1 /******************************************************************************
3 * Copyright (C) 2014 - 2018 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 * @addtogroup a53_64_boot_code Cortex A53 64bit Processor Boot Code
40 * The boot code performs minimum configuration which is required for an
41 * application. Cortex-A53 starts by checking current exception level. If the
42 * current exception level is EL3 and BSP is built for EL3, it will do
43 * initialization required for application execution at EL3. Below is a
44 * sequence illustrating what all configuration is performed before control
45 * reaches to main function for EL3 execution.
47 * 1. Program vector table base for exception handling
48 * 2. Set reset vector table base address
49 * 3. Program stack pointer for EL3
50 * 4. Routing of interrupts to EL3
51 * 5. Enable ECC protection
52 * 6. Program generic counter frequency
53 * 7. Invalidate instruction cache, data cache and TLBs
54 * 8. Configure MMU registers and program base address of translation table
55 * 9. Transfer control to _start which clears BSS sections and runs global
56 * constructor before jumping to main application
58 * If the current exception level is EL1 and BSP is also built for EL1_NONSECURE
59 * it will perform initialization required for application execution at EL1
60 * non-secure. For all other combination, the execution will go into infinite
61 * loop. Below is a sequence illustrating what all configuration is performed
62 * before control reaches to main function for EL1 execution.
64 * 1. Program vector table base for exception handling
65 * 2. Program stack pointer for EL1
66 * 3. Invalidate instruction cache, data cache and TLBs
67 * 4. Configure MMU registers and program base address of translation table
68 * 5. Transfer control to _start which clears BSS sections and runs global
69 * constructor before jumping to main application
72 * MODIFICATION HISTORY:
74 * Ver Who Date Changes
75 * ----- ------- -------- ---------------------------------------------------
76 * 5.00 pkp 05/21/14 Initial version
77 * 6.00 pkp 07/25/16 Program the counter frequency
78 * 6.02 pkp 01/22/17 Added support for EL1 non-secure
79 * 6.02 pkp 01/24/17 Clearing status of FPUStatus variable to ensure it
80 * holds correct value.
81 * 6.3 mus 04/20/17 CPU Cache protection bit in the L2CTLR_EL1 will be in
82 * set state on reset. So, setting that bit through boot
83 * code is redundant, hence removed the code which sets
84 * CPU cache protection bit.
85 * 6.4 mus 08/11/17 Implemented ARM erratum 855873.It fixes
87 * 6.6 mus 01/19/18 Added isb after writing to the cpacr_el1/cptr_el3,
88 * to ensure floating-point unit is disabled, before
89 * any subsequent instruction.
92 ******************************************************************************/
94 #include "xparameters.h"
95 #include "bspconfig.h"
96 #include "xil_errata.h"
108 .global _vector_table
110 .set EL3_stack, __el3_stack
111 .set EL2_stack, __el2_stack
112 .set EL1_stack, __el1_stack
113 .set EL0_stack, __el0_stack
115 .set TT_S1_FAULT, 0x0
116 .set TT_S1_TABLE, 0x3
118 .set L0Table, MMUTableL0
119 .set L1Table, MMUTableL1
120 .set L2Table, MMUTableL2
121 .set vector_base, _vector_table
122 .set rvbar_base, 0xFD5C0040
124 .set counterfreq, XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
131 /* this initializes the various processor modes */
166 #if 0 //dont put other a53 cpus in wfi
170 and x0, x0, #0xFF //Mask off to leave Aff0
171 cbz x0, OKToRun //If core 0, run the primary init code
185 b error // go to error if current exception level is neither EL3 nor EL1
188 /*Set vector table base address*/
192 /* Set reset vector address */
198 /* calculate the rvbar base address for particular CPU core */
202 /* store vector base address to RVBAR */
205 /*Define stack pointer for current exception level*/
209 /* Enable Trapping of SIMD/FPU register for standalone BSP */
212 orr x0, x0, #(0x1 << 10)
218 * Clear FPUStatus variable to make sure that it contains current
219 * status of FPU i.e. disabled. In case of a warm restart execution
220 * when bss sections are not cleared, it may contain previously updated
221 * value which does not hold true now.
227 /* Configure SCR_EL3 */
228 mov w1, #0 //; Initial value of register is unknown
229 orr w1, w1, #(1 << 11) //; Set ST bit (Secure EL1 can access CNTPS_TVAL_EL1, CNTPS_CTL_EL1 & CNTPS_CVAL_EL1)
230 orr w1, w1, #(1 << 10) //; Set RW bit (EL1 is AArch64, as this is the Secure world)
231 orr w1, w1, #(1 << 3) //; Set EA bit (SError routed to EL3)
232 orr w1, w1, #(1 << 2) //; Set FIQ bit (FIQs routed to EL3)
233 orr w1, w1, #(1 << 1) //; Set IRQ bit (IRQs routed to EL3)
236 /*configure cpu auxiliary control register EL1 */
237 ldr x0,=0x80CA000 // L1 Data prefetch control - 5, Enable device split throttle, 2 independent data prefetch streams
238 #if CONFIG_ARM_ERRATA_855873
240 * Set ENDCCASCI bit in CPUACTLR_EL1 register, to execute data
241 * cache clean operations as data cache clean and invalidate
244 orr x0, x0, #(1 << 44) //; Set ENDCCASCI bit
246 msr S3_1_C15_C2_0, x0 //CPUACTLR_EL1
248 /* program the counter frequency */
252 /*Enable hardware coherency between cores*/
253 mrs x0, S3_1_c15_c2_1 //Read EL1 CPU Extended Control Register
254 orr x0, x0, #(1 << 6) //Set the SMPEN bit
255 msr S3_1_c15_c2_1, x0 //Write EL1 CPU Extended Control Register
259 ic IALLU //; Invalidate I cache to PoU
260 bl invalidate_dcaches
264 ldr x1, =L0Table //; Get address of level 0 for TTBR0_EL3
265 msr TTBR0_EL3, x1 //; Set TTBR0_EL3
267 /**********************************************
268 * Set up memory attributes
270 * 0 = b01000100 = Normal, Inner/Outer Non-Cacheable
271 * 1 = b11111111 = Normal, Inner/Outer WB/WA/RA
272 * 2 = b00000000 = Device-nGnRnE
273 * 3 = b00000100 = Device-nGnRE
274 * 4 = b10111011 = Normal, Inner/Outer WT/WA/RA
275 **********************************************/
276 ldr x1, =0x000000BB0400FF44
279 /**********************************************
281 * Physical Address Size PS = 010 -> 40bits 1TB
282 * Granual Size TG0 = 00 -> 4KB
283 * size offset of the memory region T0SZ = 24 -> (region size 2^(64-24) = 2^40)
284 ***************************************************/
289 /* Enable SError Exception for asynchronous abort */
294 /* Configure SCTLR_EL3 */
295 mov x1, #0 //Most of the SCTLR_EL3 bits are unknown at reset
296 orr x1, x1, #(1 << 12) //Enable I cache
297 orr x1, x1, #(1 << 3) //Enable SP alignment check
298 orr x1, x1, #(1 << 2) //Enable caches
299 orr x1, x1, #(1 << 0) //Enable MMU
304 b _startup //jump to start
306 b error // present exception level and selected exception level mismatch
310 .if (EL1_NONSECURE == 1)
311 /*Set vector table base address*/
316 bic x0, x0, #(0x3 << 0x20)
321 * Clear FPUStatus variable to make sure that it contains current
322 * status of FPU i.e. disabled. In case of a warm restart execution
323 * when bss sections are not cleared, it may contain previously updated
324 * value which does not hold true now.
330 /*Define stack pointer for current exception level*/
334 /* Disable MMU first */
341 ic IALLU //; Invalidate I cache to PoU
342 bl invalidate_dcaches
346 ldr x1, =L0Table //; Get address of level 0 for TTBR0_EL1
347 msr TTBR0_EL1, x1 //; Set TTBR0_EL1
349 /**********************************************
350 * Set up memory attributes
352 * 0 = b01000100 = Normal, Inner/Outer Non-Cacheable
353 * 1 = b11111111 = Normal, Inner/Outer WB/WA/RA
354 * 2 = b00000000 = Device-nGnRnE
355 * 3 = b00000100 = Device-nGnRE
356 * 4 = b10111011 = Normal, Inner/Outer WT/WA/RA
357 **********************************************/
358 ldr x1, =0x000000BB0400FF44
361 /**********************************************
363 * Physical Address Size PS = 010 -> 40bits 1TB
364 * Granual Size TG0 = 00 -> 4KB
365 * size offset of the memory region T0SZ = 24 -> (region size 2^(64-24) = 2^40)
366 ***************************************************/
370 /* Enable SError Exception for asynchronous abort */
377 orr x1, x1, #(1 << 18) // ; Set WFE non trapping
378 orr x1, x1, #(1 << 17) // ; Set WFI non trapping
379 orr x1, x1, #(1 << 5) // ; Set CP15 barrier enabled
380 orr x1, x1, #(1 << 12) // ; Set I bit
381 orr x1, x1, #(1 << 2) // ; Set C bit
382 orr x1, x1, #(1 << 0) // ; Set M bit
386 bl _startup //jump to start
388 b error // present exception level and selected exception level mismatch
397 mrs x0, CLIDR_EL1 //; x0 = CLIDR
398 ubfx w2, w0, #24, #3 //; w2 = CLIDR.LoC
399 cmp w2, #0 //; LoC is 0?
400 b.eq invalidateCaches_end //; No cleaning required and enable MMU
401 mov w1, #0 //; w1 = level iterator
403 invalidateCaches_flush_level:
404 add w3, w1, w1, lsl #1 //; w3 = w1 * 3 (right-shift for cache type)
405 lsr w3, w0, w3 //; w3 = w0 >> w3
406 ubfx w3, w3, #0, #3 //; w3 = cache type of this level
407 cmp w3, #2 //; No cache at this level?
408 b.lt invalidateCaches_next_level
411 msr CSSELR_EL1, x4 //; Select current cache level in CSSELR
412 isb //; ISB required to reflect new CSIDR
413 mrs x4, CCSIDR_EL1 //; w4 = CSIDR
416 add w3, w3, #2 //; w3 = log2(line size)
417 ubfx w5, w4, #13, #15
418 ubfx w4, w4, #3, #10 //; w4 = Way number
419 clz w6, w4 //; w6 = 32 - log2(number of ways)
421 invalidateCaches_flush_set:
422 mov w8, w4 //; w8 = Way number
423 invalidateCaches_flush_way:
424 lsl w7, w1, #1 //; Fill level field
426 orr w7, w7, w9 //; Fill index field
428 orr w7, w7, w9 //; Fill way field
429 dc CISW, x7 //; Invalidate by set/way to point of coherency
430 subs w8, w8, #1 //; Decrement way
431 b.ge invalidateCaches_flush_way
432 subs w5, w5, #1 //; Descrement set
433 b.ge invalidateCaches_flush_set
435 invalidateCaches_next_level:
436 add w1, w1, #1 //; Next level
438 b.gt invalidateCaches_flush_level
440 invalidateCaches_end:
445 * @} End of "addtogroup a53_64_boot_code".