1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Early initialization code for aarch64 (a.k.a. armv8) */
5 #include <soc/addressmap.h>
14 * According to the reference manual the first instruction is fetched from
15 * offset 0x100, but at offset 0 a branch instruction is always placed.
16 * Support two entry points for now.
17 * To save memory put the cavium specific init code between those to entry
21 fmov d30, x0 /* Save X0 in FPR for use later */
23 * The BDK stores X1 for later use, but it turns out that we don't need
24 * this "feature". The idea is to hide the devicetree somewhere in
25 * flash, that only the ROM will find it and point to it using X1.
27 adr x1, _start /* x1 = _start location based on PC */
28 fmov d29, x1 /* Save PC in FPR for use later */
30 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
31 /* Change the core to big endian mode for EL3 */
33 mov x1, 1<<25 /* Set SCTLR_EL3[ee]=1 */
36 #define ENDIAN_CONVERT64(reg) rev reg, reg
37 #define ENDIAN_CONVERT32(reg) rev reg, reg
38 #define ENDIAN_CONVERT16(reg) rev16 reg, reg
39 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
40 /* Nothing needed, default is little endian */
41 #define ENDIAN_CONVERT64(reg)
42 #define ENDIAN_CONVERT32(reg)
43 #define ENDIAN_CONVERT16(reg)
45 #error Unknown endianness
48 mov x0, (LMC0_PF_BAR0 >> 32)
50 mov x1, (LMC0_PF_BAR0 & 0xffffffff)
53 /* Test if DRAM PLL is running */
54 ldr x1, [x0, LMC0_DDR_PLL_CTL0]
64 /* Check that we're running on the node we're linked for */
66 ubfx x0, x0, 16, 8 /* Bits 23:16 are the physical node ID */
73 /* Get code position */
75 mov x0, BOOTROM_OFFSET
81 * Check if IROM has loaded the code to BOOTROM_OFFSET.
82 * In case the offset is wrong, try to relocate.
83 * Ideally the following code is never executed.
84 * FIXME: Add region overlap check.
90 /* Get bootblock length */
98 ldp q0, q1, [x1], 32 /* Load 32 bytes */
99 subs w2, w2, 32 /* Subtract 32 from length, setting flags */
100 stp q0, q1, [x0], 32 /* Store 32 bytes */
101 b.gt copy_code /* Repeat if length is still positive */
104 /* Load the actual location we're suppose to be at */
105 adr x0, after_relocate /* Relative address */
106 adr x1, _start /* Relative address */
107 sub x0, x0, x1 /* This only works if _start is suppose to be zero */
108 mov x1, BOOTROM_OFFSET
110 br x0 /* Branch to relocated code */
112 ic ialluis /* Clear the icache now that all code is correct */
115 /* Allow unaligned memory access as long as MMU is disabled */
116 mrs x22, s3_0_c11_c0_4
117 orr x22, x22, # (1 << 37) /* Set DCVA47 */
118 msr s3_0_c11_c0_4, x22
122 /* Real entry point */
130 ubfx x0, x0, 4, 12 /* Bits 15:4 are the part number */
134 thunder1_cache_setup:
136 * Setup L2 cache to allow secure access to all of the address space
137 * thunder1 compatibility list:
142 #define REGIONX_START 0x1000
143 #define REGIONX_END 0x1008
144 #define REGIONX_ATTR 0x1010
145 mov x0, L2C_PF_BAR0 >> 32
147 mov x1, (L2C_PF_BAR0 & 0xffffffff)
149 str xzr, [x0, REGIONX_START] /* Start of zero */
150 mov x1, 0x3fffff00000 /* End of max address */
152 str x1, [x0, REGIONX_END]
153 mov x1, 2 /* Secure only access */
155 str x1, [x0, REGIONX_ATTR]
156 /* Update way partition to allow core 0 to write to L2 */
157 #define L2C_WPAR_PP0_OFFSET 0x40000
158 mov x1, L2C_WPAR_PP0_OFFSET
160 ldr xzr, [x0, x1] /* Read back to make sure done */
164 #undef L2C_WPAR_PP0_OFFSET
167 * At this point the whole CAR is readable and writeable, but if
168 * we touch to many cache-lines our code might get flushed out.
169 * We have to lock all cache-lines that are to be used as RAM, which are
170 * the ones marked as SRAM in memlayout.
172 mrs x0, CTR_EL0 /* Get cache-line size */
173 /* [19:16] - Indicates (Log2(number of words in cache line) */
175 mov x1, 4 /* Bytes in a word (32-bit) */
176 lsl x0, x1, x0 /* Number of Bytes in x0 */
179 mvn x1, x1 /* Place mask in x1 */
182 and x3, x3, x1 /* Align addresses with cache-lines */
186 and x4, x4, x1 /* Align addresses with cache-lines */
187 sub x2, x4, x3 /* Store sram length in x2 */
190 sys #0, c11, c1, #4, x3
191 add x3, x3, x0 /* Increment address by cache-line bytes */
192 subs w2, w2, w0 /* Subtract cache-line bytes from length */
193 b.gt lock_cache_lines /* Repeat if length is still positive */
196 * The locked region isn't considered dirty by L2. Do read/write of
197 * each cache line to force each to be dirty. This is needed across the
198 * whole line to make sure the L2 dirty bits are all up to date.
199 * NOTE: If we'd relocate we could memset the whole memory !
202 and x3, x3, x1 /* Align addresses with cache-lines */
206 and x4, x4, x1 /* Align addresses with cache-lines */
207 sub x2, x4, x3 /* Store sram length in x2 */
213 ldp q0, q1, [x3], 32 /* Load 32 bytes */
214 subs w2, w2, 32 /* Subtract 32 from length, setting flags */
215 stp q0, q1, [x4], 32 /* Store 32 bytes */
216 b.gt dirty_cache_line /* Repeat if length is still positive */
221 * As the memory controller isn't running, but we access the DRAM's
222 * address space, some interrupt flags had been set.
223 * Tidy up our mess now on (valid for CN81XX only).
225 mov x0, (L2C_TAD0_INT_W1C >> 32)
227 mov x1, (L2C_TAD0_INT_W1C & 0xffffffff)
231 orr x1, x1, 0x1c00 /* Clear WRDISLMC, RDDISLMC, RDNXM */
244 fmov x0, d30 /* The original X0, info from previous image */
245 fmov x1, d29 /* The original PC we were loaded at */