blob: fd34a4a32193c361d669fb890b45b82a7e381777 [file] [log] [blame]
Masahiro Yamada5894ca02014-10-03 19:21:06 +09001/*
Masahiro Yamada9fc5f9d2015-05-29 17:30:03 +09002 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada5894ca02014-10-03 19:21:06 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <config.h>
8#include <linux/linkage.h>
Masahiro Yamada105a9e72015-02-27 02:27:06 +09009#include <linux/sizes.h>
Masahiro Yamada5894ca02014-10-03 19:21:06 +090010#include <asm/system.h>
Masahiro Yamadaa86ac952015-02-27 02:26:44 +090011#include <mach/led.h>
12#include <mach/arm-mpcore.h>
13#include <mach/sbc-regs.h>
Masahiro Yamada105a9e72015-02-27 02:27:06 +090014#include <mach/ssc-regs.h>
Masahiro Yamada5894ca02014-10-03 19:21:06 +090015
16ENTRY(lowlevel_init)
17 mov r8, lr @ persevere link reg across call
18
19 /*
20 * The UniPhier Boot ROM loads SPL code to the L2 cache.
21 * But CPUs can only do instruction fetch now because start.S has
22 * cleared C and M bits.
23 * First we need to turn on MMU and Dcache again to get back
24 * data access to L2.
25 */
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +090026 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
27 orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache
Masahiro Yamada5894ca02014-10-03 19:21:06 +090028 mcr p15, 0, r0, c1, c0, 0
29
Masahiro Yamadab4ad44b2015-01-06 14:28:16 +090030#ifdef CONFIG_DEBUG_LL
31 bl setup_lowlevel_debug
32#endif
33
Masahiro Yamada5894ca02014-10-03 19:21:06 +090034 /*
35 * Now we are using the page table embedded in the Boot ROM.
36 * It is not handy since it is not a straight mapped table for sLD3.
37 * What we need to do next is to switch over to the page table in SPL.
38 */
39 ldr r3, =init_page_table @ page table must be 16KB aligned
40
41 /* Disable MMU and Dcache before switching Page Table */
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +090042 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
Masahiro Yamada5894ca02014-10-03 19:21:06 +090043 bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache
44 mcr p15, 0, r0, c1, c0, 0
45
46 bl enable_mmu
47
48#ifdef CONFIG_UNIPHIER_SMP
Masahiro Yamada62118b72015-03-23 00:07:31 +090049secondary_startup:
50 /*
51 * Entry point for secondary CPUs
52 *
53 * The Boot ROM has already enabled MMU for the secondary CPUs as well
54 * as for the primary one. The MMU table embedded in the Boot ROM
55 * prohibits the DRAM access, so it is impossible to bring the
56 * secondary CPUs into DRAM directly. They must jump here into SPL,
57 * which is run on L2 cache.
58 *
59 * Boot Sequence
60 * [primary CPU] [secondary CPUs]
61 * start from Boot ROM start from Boot ROM
62 * jump to SPL sleep in Boot ROM
63 * kick secondaries ---(sev)---> jump to SPL
64 * jump to U-Boot main sleep in SPL
65 * jump to Linux
66 * kick secondaries ---(sev)---> jump to Linux
67 */
Masahiro Yamada5894ca02014-10-03 19:21:06 +090068
69 /* branch by CPU ID */
70 mrc p15, 0, r0, c0, c0, 5 @ MPIDR (Multiprocessor Affinity Register)
71 and r0, r0, #0x3
72 cmp r0, #0x0
73 beq primary_cpu
Masahiro Yamada62118b72015-03-23 00:07:31 +090074 /* only for secondary CPUs */
75 ldr r1, =ROM_BOOT_ROMRSV2 @ The last data access to L2 cache
76 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
77 orr r0, r0, #CR_I @ Enable ICache
78 bic r0, r0, #(CR_C | CR_M) @ MMU and Dcache must be disabled
79 mcr p15, 0, r0, c1, c0, 0 @ before jumping to Linux
Masahiro Yamada5894ca02014-10-03 19:21:06 +090080 mov r0, #0
81 str r0, [r1]
Masahiro Yamada62118b72015-03-23 00:07:31 +090082 b 1f
83 /*
84 * L2 cache is shared among all the CPUs and it might be disabled by
85 * the primary one. Before that, the following 5 lines must be cached
86 * on the Icaches of the secondary CPUs.
87 */
880: wfe @ kicked by Linux
891: ldr r0, [r1]
Masahiro Yamada5894ca02014-10-03 19:21:06 +090090 cmp r0, #0
Masahiro Yamada62118b72015-03-23 00:07:31 +090091 bxne r0 @ r0: Linux entry for secondary CPUs
92 b 0b
Masahiro Yamada5894ca02014-10-03 19:21:06 +090093primary_cpu:
94 ldr r1, =ROM_BOOT_ROMRSV2
Masahiro Yamada62118b72015-03-23 00:07:31 +090095 ldr r0, =secondary_startup
Masahiro Yamada5894ca02014-10-03 19:21:06 +090096 str r0, [r1]
97 ldr r0, [r1] @ make sure str is complete before sev
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +090098 sev @ kick the secondary CPU
Masahiro Yamada5894ca02014-10-03 19:21:06 +090099#endif
100
101 bl setup_init_ram @ RAM area for temporary stack pointer
102
103 mov lr, r8 @ restore link
104 mov pc, lr @ back to my caller
105ENDPROC(lowlevel_init)
106
107ENTRY(enable_mmu)
108 mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register)
109 bic r0, r0, #0x37
110 orr r0, r0, #0x20 @ disable TTBR1
111 mcr p15, 0, r0, c2, c0, 2
112
113 orr r0, r3, #0x8 @ Outer Cacheability for table walks: WBWA
114 mcr p15, 0, r0, c2, c0, 0 @ TTBR0
115
116 mov r0, #0
117 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
118
119 mov r0, #-1 @ manager for all domains (No permission check)
120 mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register)
121
122 dsb
123 isb
124 /*
125 * MMU on:
126 * TLBs was already invalidated in "../start.S"
127 * So, we don't need to invalidate it here.
128 */
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +0900129 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900130 orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable
131 mcr p15, 0, r0, c1, c0, 0
132
133 mov pc, lr
134ENDPROC(enable_mmu)
135
Masahiro Yamada105a9e72015-02-27 02:27:06 +0900136/*
137 * For PH1-Pro4 or older SoCs, the size of WAY is 32KB.
138 * It is large enough for tmp RAM.
139 */
140#define BOOT_RAM_SIZE (SZ_32K)
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900141#define BOOT_WAY_BITS (0x00000100) /* way 8 */
142
143ENTRY(setup_init_ram)
144 /*
145 * Touch to zero for the boot way
146 */
1470:
148 /*
149 * set SSCOQM, SSCOQAD, SSCOQSZ, SSCOQWN in this order
150 */
151 ldr r0, = 0x00408006 @ touch to zero with address range
152 ldr r1, = SSCOQM
153 str r0, [r1]
Masahiro Yamadace3a6392015-03-23 00:07:26 +0900154 ldr r0, = (CONFIG_SPL_STACK - BOOT_RAM_SIZE) @ base address
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900155 ldr r1, = SSCOQAD
156 str r0, [r1]
157 ldr r0, = BOOT_RAM_SIZE
158 ldr r1, = SSCOQSZ
159 str r0, [r1]
160 ldr r0, = BOOT_WAY_BITS
161 ldr r1, = SSCOQWN
162 str r0, [r1]
163 ldr r1, = SSCOPPQSEF
164 ldr r0, [r1]
165 cmp r0, #0 @ check if the command is successfully set
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +0900166 bne 0b @ try again if an error occurs
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900167
168 ldr r1, = SSCOLPQS
1691:
170 ldr r0, [r1]
171 cmp r0, #0x4
172 bne 1b @ wait until the operation is completed
173 str r0, [r1] @ clear the complete notification flag
174
175 mov pc, lr
176ENDPROC(setup_init_ram)