1 /******************************************************************************
3 * Copyright (C) 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
36 * This file contains the initial startup code for the Cortex A53 processor
37 * Currently the processor starts at EL3 and boot code, startup and main
38 * code will run on secure EL3.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ------- -------- ---------------------------------------------------
46 * 5.00 pkp 5/21/14 Initial version
52 ******************************************************************************/
54 #include "xparameters.h"
69 .set EL3_stack, __el3_stack
70 .set EL2_stack, __el2_stack
71 .set EL1_stack, __el1_stack
72 .set EL0_stack, __el0_stack
77 .set L0Table, MMUTableL0
78 .set L1Table, MMUTableL1
79 .set L2Table, MMUTableL2
80 .set vector_base, _vector_table
85 /* this initializes the various processor modes */
120 #if 0 //dont put other a53 cpus in wfi
124 and x0, x0, #0xFF //Mask off to leave Aff0
125 cbz x0, OKToRun //If core 0, run the primary init code
132 /*Set vector table base addresses. */
138 /*Define stack pointer for current exception level*/
142 /* Disable trapping of CPTR_EL3 accesses or use of Adv.SIMD/FPU*/
143 mov x0, #0 // Clear all trap bits
147 /* Configure SCR_EL3 */
148 mov w1, #0 //; Initial value of register is unknown
149 orr w1, w1, #(1 << 11) //; Set ST bit (Secure EL1 can access CNTPS_TVAL_EL1, CNTPS_CTL_EL1 & CNTPS_CVAL_EL1)
150 orr w1, w1, #(1 << 10) //; Set RW bit (EL1 is AArch64, as this is the Secure world)
151 orr w1, w1, #(1 << 3) //; Set EA bit (SError routed to EL3)
152 orr w1, w1, #(1 << 2) //; Set FIQ bit (FIQs routed to EL3)
153 orr w1, w1, #(1 << 1) //; Set IRQ bit (IRQs routed to EL3)
156 /*Enable ECC protection*/
157 mrs x0, S3_1_C11_C0_2 // register L2CTLR_EL1
159 msr S3_1_C11_C0_2, x0
161 /*configure cpu auxiliary control register EL1 */
162 ldr x0,=0x80CA000 // L1 Data prefetch control - 5, Enable device split throttle, 2 independent data prefetch streams
163 msr S3_1_C15_C2_0, x0 //CPUACTLR_EL1
166 /*Enable hardware coherency between cores*/
167 mrs x0, S3_1_c15_c2_1 //Read EL1 CPU Extended Control Register
168 orr x0, x0, #(1 << 6) //Set the SMPEN bit
169 msr S3_1_c15_c2_1, x0 //Write EL1 CPU Extended Control Register
173 ic IALLU //; Invalidate I cache to PoU
174 bl invalidate_dcaches
178 ldr x1, =L0Table //; Get address of level 0 for TTBR0_EL1
179 msr TTBR0_EL3, x1 //; Set TTBR0_EL3 (NOTE: There is no TTBR1 at EL1)
182 /**********************************************
183 * Set up memory attributes
185 * 0 = b01000100 = Normal, Inner/Outer Non-Cacheable
186 * 1 = b11111111 = Normal, Inner/Outer WB/WA/RA
187 * 2 = b00000000 = Device-nGnRnE
188 **********************************************/
189 ldr x1, =0x000000000000FF44
192 /**********************************************
194 * Physical Address Size PS = 010 -> 40bits 1TB
195 * Granual Size TG0 = 00 -> 4KB
196 * size offset of the memory region T0SZ = 24 -> (region size 2^(64-24) = 2^40)
197 ***************************************************/
202 /* Configure SCTLR_EL3 */
203 mov x1, #0 //Most of the SCTLR_EL3 bits are unknown at reset
204 orr x1, x1, #(1 << 12) //Enable I cache
205 orr x1, x1, #(1 << 3) //Enable SP alignment check
206 orr x1, x1, #(1 << 2) //Enable caches
207 orr x1, x1, #(1 << 0) //Enable MMU
212 bl _startup //jump to start
220 mrs x0, CLIDR_EL1 //; x0 = CLIDR
221 ubfx w2, w0, #24, #3 //; w2 = CLIDR.LoC
222 cmp w2, #0 //; LoC is 0?
223 b.eq invalidateCaches_end //; No cleaning required and enable MMU
224 mov w1, #0 //; w1 = level iterator
226 invalidateCaches_flush_level:
227 add w3, w1, w1, lsl #1 //; w3 = w1 * 3 (right-shift for cache type)
228 lsr w3, w0, w3 //; w3 = w0 >> w3
229 ubfx w3, w3, #0, #3 //; w3 = cache type of this level
230 cmp w3, #2 //; No cache at this level?
231 b.lt invalidateCaches_next_level
234 msr CSSELR_EL1, x4 //; Select current cache level in CSSELR
235 isb //; ISB required to reflect new CSIDR
236 mrs x4, CCSIDR_EL1 //; w4 = CSIDR
239 add w3, w3, #2 //; w3 = log2(line size)
240 ubfx w5, w4, #13, #15
241 ubfx w4, w4, #3, #10 //; w4 = Way number
242 clz w6, w4 //; w6 = 32 - log2(number of ways)
244 invalidateCaches_flush_set:
245 mov w8, w4 //; w8 = Way number
246 invalidateCaches_flush_way:
247 lsl w7, w1, #1 //; Fill level field
249 orr w7, w7, w9 //; Fill index field
251 orr w7, w7, w9 //; Fill way field
252 dc CISW, x7 //; Invalidate by set/way to point of coherency
253 subs w8, w8, #1 //; Decrement way
254 b.ge invalidateCaches_flush_way
255 subs w5, w5, #1 //; Descrement set
256 b.ge invalidateCaches_flush_set
258 invalidateCaches_next_level:
259 add w1, w1, #1 //; Next level
261 b.gt invalidateCaches_flush_level
263 invalidateCaches_end: