1 /******************************************************************************
3 * Copyright (C) 2014 - 2015 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
81 .set rvbar_base, 0xFD5C0040
86 /* this initializes the various processor modes */
121 #if 0 //dont put other a53 cpus in wfi
125 and x0, x0, #0xFF //Mask off to leave Aff0
126 cbz x0, OKToRun //If core 0, run the primary init code
133 /*Set vector table base address*/
137 /* Set reset vector address */
143 /* calculate the rvbar base address for particular CPU core */
147 /* store vector base address to RVBAR */
150 /*Define stack pointer for current exception level*/
155 /* Disable trapping of CPTR_EL3 accesses or use of Adv.SIMD/FPU*/
156 mov x0, #0 // Clear all trap bits
160 /* Configure SCR_EL3 */
161 mov w1, #0 //; Initial value of register is unknown
162 orr w1, w1, #(1 << 11) //; Set ST bit (Secure EL1 can access CNTPS_TVAL_EL1, CNTPS_CTL_EL1 & CNTPS_CVAL_EL1)
163 orr w1, w1, #(1 << 10) //; Set RW bit (EL1 is AArch64, as this is the Secure world)
164 orr w1, w1, #(1 << 3) //; Set EA bit (SError routed to EL3)
165 orr w1, w1, #(1 << 2) //; Set FIQ bit (FIQs routed to EL3)
166 orr w1, w1, #(1 << 1) //; Set IRQ bit (IRQs routed to EL3)
169 /*Enable ECC protection*/
170 mrs x0, S3_1_C11_C0_2 // register L2CTLR_EL1
172 msr S3_1_C11_C0_2, x0
174 /*configure cpu auxiliary control register EL1 */
175 ldr x0,=0x80CA000 // L1 Data prefetch control - 5, Enable device split throttle, 2 independent data prefetch streams
176 msr S3_1_C15_C2_0, x0 //CPUACTLR_EL1
179 /*Enable hardware coherency between cores*/
180 mrs x0, S3_1_c15_c2_1 //Read EL1 CPU Extended Control Register
181 orr x0, x0, #(1 << 6) //Set the SMPEN bit
182 msr S3_1_c15_c2_1, x0 //Write EL1 CPU Extended Control Register
186 ic IALLU //; Invalidate I cache to PoU
187 bl invalidate_dcaches
191 ldr x1, =L0Table //; Get address of level 0 for TTBR0_EL1
192 msr TTBR0_EL3, x1 //; Set TTBR0_EL3 (NOTE: There is no TTBR1 at EL1)
195 /**********************************************
196 * Set up memory attributes
198 * 0 = b01000100 = Normal, Inner/Outer Non-Cacheable
199 * 1 = b11111111 = Normal, Inner/Outer WB/WA/RA
200 * 2 = b00000000 = Device-nGnRnE
201 * 3 = b00000100 = Device-nGnRE
202 * 4 = b10111011 = Normal, Inner/Outer WT/WA/RA
203 **********************************************/
204 ldr x1, =0x000000BB0400FF44
207 /**********************************************
209 * Physical Address Size PS = 010 -> 40bits 1TB
210 * Granual Size TG0 = 00 -> 4KB
211 * size offset of the memory region T0SZ = 24 -> (region size 2^(64-24) = 2^40)
212 ***************************************************/
217 /* Enable SError Exception for asynchronous abort */
222 /* Configure SCTLR_EL3 */
223 mov x1, #0 //Most of the SCTLR_EL3 bits are unknown at reset
224 orr x1, x1, #(1 << 12) //Enable I cache
225 orr x1, x1, #(1 << 3) //Enable SP alignment check
226 orr x1, x1, #(1 << 2) //Enable caches
227 orr x1, x1, #(1 << 0) //Enable MMU
232 bl _startup //jump to start
240 mrs x0, CLIDR_EL1 //; x0 = CLIDR
241 ubfx w2, w0, #24, #3 //; w2 = CLIDR.LoC
242 cmp w2, #0 //; LoC is 0?
243 b.eq invalidateCaches_end //; No cleaning required and enable MMU
244 mov w1, #0 //; w1 = level iterator
246 invalidateCaches_flush_level:
247 add w3, w1, w1, lsl #1 //; w3 = w1 * 3 (right-shift for cache type)
248 lsr w3, w0, w3 //; w3 = w0 >> w3
249 ubfx w3, w3, #0, #3 //; w3 = cache type of this level
250 cmp w3, #2 //; No cache at this level?
251 b.lt invalidateCaches_next_level
254 msr CSSELR_EL1, x4 //; Select current cache level in CSSELR
255 isb //; ISB required to reflect new CSIDR
256 mrs x4, CCSIDR_EL1 //; w4 = CSIDR
259 add w3, w3, #2 //; w3 = log2(line size)
260 ubfx w5, w4, #13, #15
261 ubfx w4, w4, #3, #10 //; w4 = Way number
262 clz w6, w4 //; w6 = 32 - log2(number of ways)
264 invalidateCaches_flush_set:
265 mov w8, w4 //; w8 = Way number
266 invalidateCaches_flush_way:
267 lsl w7, w1, #1 //; Fill level field
269 orr w7, w7, w9 //; Fill index field
271 orr w7, w7, w9 //; Fill way field
272 dc CISW, x7 //; Invalidate by set/way to point of coherency
273 subs w8, w8, #1 //; Decrement way
274 b.ge invalidateCaches_flush_way
275 subs w5, w5, #1 //; Descrement set
276 b.ge invalidateCaches_flush_set
278 invalidateCaches_next_level:
279 add w1, w1, #1 //; Next level
281 b.gt invalidateCaches_flush_level
283 invalidateCaches_end: