]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/arm64/kernel/head.S
arm64: Kconfig: Fix help text about AArch32 support with 64K pages
[mirror_ubuntu-artful-kernel.git] / arch / arm64 / kernel / head.S
CommitLineData
9703d9d7
CM
1/*
2 * Low-level CPU initialisation
3 * Based on arch/arm/kernel/head.S
4 *
5 * Copyright (C) 1994-2002 Russell King
6 * Copyright (C) 2003-2012 ARM Ltd.
7 * Authors: Catalin Marinas <catalin.marinas@arm.com>
8 * Will Deacon <will.deacon@arm.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include <linux/linkage.h>
24#include <linux/init.h>
021f6537 25#include <linux/irqchip/arm-gic-v3.h>
9703d9d7
CM
26
27#include <asm/assembler.h>
28#include <asm/ptrace.h>
29#include <asm/asm-offsets.h>
c218bca7 30#include <asm/cache.h>
0359b0e2 31#include <asm/cputype.h>
87d1587b 32#include <asm/kernel-pgtable.h>
9703d9d7
CM
33#include <asm/memory.h>
34#include <asm/thread_info.h>
35#include <asm/pgtable-hwdef.h>
36#include <asm/pgtable.h>
37#include <asm/page.h>
f35a9205 38#include <asm/virt.h>
9703d9d7 39
6f4d57fa 40#define __PHYS_OFFSET (KERNEL_START - TEXT_OFFSET)
9703d9d7 41
4190312b
AB
42#if (TEXT_OFFSET & 0xfff) != 0
43#error TEXT_OFFSET must be at least 4KB aligned
44#elif (PAGE_OFFSET & 0x1fffff) != 0
da57a369 45#error PAGE_OFFSET must be at least 2MB aligned
4190312b 46#elif TEXT_OFFSET > 0x1fffff
da57a369 47#error TEXT_OFFSET must be less than 2MB
9703d9d7
CM
48#endif
49
6f4d57fa 50#define KERNEL_START _text
9703d9d7
CM
51#define KERNEL_END _end
52
9703d9d7
CM
53/*
54 * Kernel startup entry point.
55 * ---------------------------
56 *
57 * The requirements are:
58 * MMU = off, D-cache = off, I-cache = on or off,
59 * x0 = physical address to the FDT blob.
60 *
61 * This code is mostly position independent so you call this at
62 * __pa(PAGE_OFFSET + TEXT_OFFSET).
63 *
64 * Note that the callee-saved registers are used for storing variables
65 * that are useful before the MMU is enabled. The allocations are described
66 * in the entry routines.
67 */
68 __HEAD
69
70 /*
71 * DO NOT MODIFY. Image header expected by Linux boot-loaders.
72 */
3c7f2550
MS
73#ifdef CONFIG_EFI
74efi_head:
75 /*
76 * This add instruction has no meaningful effect except that
77 * its opcode forms the magic "MZ" signature required by UEFI.
78 */
79 add x13, x18, #0x16
80 b stext
81#else
9703d9d7
CM
82 b stext // branch to kernel start, magic
83 .long 0 // reserved
3c7f2550 84#endif
a2c1d73b
MR
85 .quad _kernel_offset_le // Image load offset from start of RAM, little-endian
86 .quad _kernel_size_le // Effective size of kernel image, little-endian
87 .quad _kernel_flags_le // Informative flags, little-endian
4370eec0
RF
88 .quad 0 // reserved
89 .quad 0 // reserved
90 .quad 0 // reserved
91 .byte 0x41 // Magic number, "ARM\x64"
92 .byte 0x52
93 .byte 0x4d
94 .byte 0x64
3c7f2550
MS
95#ifdef CONFIG_EFI
96 .long pe_header - efi_head // Offset to the PE header.
97#else
4370eec0 98 .word 0 // reserved
3c7f2550
MS
99#endif
100
101#ifdef CONFIG_EFI
e8f3010f
AB
102 .globl __efistub_stext_offset
103 .set __efistub_stext_offset, stext - efi_head
3c7f2550
MS
104 .align 3
105pe_header:
106 .ascii "PE"
107 .short 0
108coff_header:
109 .short 0xaa64 // AArch64
110 .short 2 // nr_sections
111 .long 0 // TimeDateStamp
112 .long 0 // PointerToSymbolTable
113 .long 1 // NumberOfSymbols
114 .short section_table - optional_header // SizeOfOptionalHeader
115 .short 0x206 // Characteristics.
116 // IMAGE_FILE_DEBUG_STRIPPED |
117 // IMAGE_FILE_EXECUTABLE_IMAGE |
118 // IMAGE_FILE_LINE_NUMS_STRIPPED
119optional_header:
120 .short 0x20b // PE32+ format
121 .byte 0x02 // MajorLinkerVersion
122 .byte 0x14 // MinorLinkerVersion
c16173fa 123 .long _end - stext // SizeOfCode
3c7f2550
MS
124 .long 0 // SizeOfInitializedData
125 .long 0 // SizeOfUninitializedData
e8f3010f
AB
126 .long __efistub_entry - efi_head // AddressOfEntryPoint
127 .long __efistub_stext_offset // BaseOfCode
3c7f2550
MS
128
129extra_header_fields:
130 .quad 0 // ImageBase
ea6bc80d 131 .long 0x1000 // SectionAlignment
a352ea3e 132 .long PECOFF_FILE_ALIGNMENT // FileAlignment
3c7f2550
MS
133 .short 0 // MajorOperatingSystemVersion
134 .short 0 // MinorOperatingSystemVersion
135 .short 0 // MajorImageVersion
136 .short 0 // MinorImageVersion
137 .short 0 // MajorSubsystemVersion
138 .short 0 // MinorSubsystemVersion
139 .long 0 // Win32VersionValue
140
c16173fa 141 .long _end - efi_head // SizeOfImage
3c7f2550
MS
142
143 // Everything before the kernel image is considered part of the header
e8f3010f 144 .long __efistub_stext_offset // SizeOfHeaders
3c7f2550
MS
145 .long 0 // CheckSum
146 .short 0xa // Subsystem (EFI application)
147 .short 0 // DllCharacteristics
148 .quad 0 // SizeOfStackReserve
149 .quad 0 // SizeOfStackCommit
150 .quad 0 // SizeOfHeapReserve
151 .quad 0 // SizeOfHeapCommit
152 .long 0 // LoaderFlags
153 .long 0x6 // NumberOfRvaAndSizes
154
155 .quad 0 // ExportTable
156 .quad 0 // ImportTable
157 .quad 0 // ResourceTable
158 .quad 0 // ExceptionTable
159 .quad 0 // CertificationTable
160 .quad 0 // BaseRelocationTable
161
162 // Section table
163section_table:
164
165 /*
166 * The EFI application loader requires a relocation section
167 * because EFI applications must be relocatable. This is a
168 * dummy section as far as we are concerned.
169 */
170 .ascii ".reloc"
171 .byte 0
172 .byte 0 // end of 0 padding of section name
173 .long 0
174 .long 0
175 .long 0 // SizeOfRawData
176 .long 0 // PointerToRawData
177 .long 0 // PointerToRelocations
178 .long 0 // PointerToLineNumbers
179 .short 0 // NumberOfRelocations
180 .short 0 // NumberOfLineNumbers
181 .long 0x42100040 // Characteristics (section flags)
182
183
184 .ascii ".text"
185 .byte 0
186 .byte 0
187 .byte 0 // end of 0 padding of section name
c16173fa 188 .long _end - stext // VirtualSize
e8f3010f 189 .long __efistub_stext_offset // VirtualAddress
3c7f2550 190 .long _edata - stext // SizeOfRawData
e8f3010f 191 .long __efistub_stext_offset // PointerToRawData
3c7f2550
MS
192
193 .long 0 // PointerToRelocations (0 for executables)
194 .long 0 // PointerToLineNumbers (0 for executables)
195 .short 0 // NumberOfRelocations (0 for executables)
196 .short 0 // NumberOfLineNumbers (0 for executables)
197 .long 0xe0500020 // Characteristics (section flags)
ea6bc80d
AB
198
199 /*
200 * EFI will load stext onwards at the 4k section alignment
201 * described in the PE/COFF header. To ensure that instruction
202 * sequences using an adrp and a :lo12: immediate will function
203 * correctly at this alignment, we must ensure that stext is
204 * placed at a 4k boundary in the Image to begin with.
205 */
206 .align 12
3c7f2550 207#endif
9703d9d7
CM
208
209ENTRY(stext)
da9c177d 210 bl preserve_boot_args
828e9834 211 bl el2_setup // Drop to EL1, w20=cpu_boot_mode
6f4d57fa 212 adrp x24, __PHYS_OFFSET
828e9834 213 bl set_cpu_boot_mode_flag
9703d9d7
CM
214 bl __create_page_tables // x25=TTBR0, x26=TTBR1
215 /*
a591ede4
MZ
216 * The following calls CPU setup code, see arch/arm64/mm/proc.S for
217 * details.
9703d9d7
CM
218 * On return, the CPU will be ready for the MMU to be turned on and
219 * the TCR will have been set.
220 */
a871d354 221 ldr x27, =__mmap_switched // address to jump to after
9703d9d7 222 // MMU has been enabled
8b0a9575 223 adr_l lr, __enable_mmu // return (PIC) address
a591ede4 224 b __cpu_setup // initialise processor
9703d9d7
CM
225ENDPROC(stext)
226
da9c177d
AB
227/*
228 * Preserve the arguments passed by the bootloader in x0 .. x3
229 */
230preserve_boot_args:
231 mov x21, x0 // x21=FDT
232
233 adr_l x0, boot_args // record the contents of
234 stp x21, x1, [x0] // x0 .. x3 at kernel entry
235 stp x2, x3, [x0, #16]
236
237 dmb sy // needed before dc ivac with
238 // MMU off
239
240 add x1, x0, #0x20 // 4 x 8 bytes
241 b __inval_cache_range // tail call
242ENDPROC(preserve_boot_args)
243
034edabe
LA
244/*
245 * Macro to create a table entry to the next page.
246 *
247 * tbl: page table address
248 * virt: virtual address
249 * shift: #imm page table shift
250 * ptrs: #imm pointers per table page
251 *
252 * Preserves: virt
253 * Corrupts: tmp1, tmp2
254 * Returns: tbl -> next level table page address
255 */
256 .macro create_table_entry, tbl, virt, shift, ptrs, tmp1, tmp2
257 lsr \tmp1, \virt, #\shift
258 and \tmp1, \tmp1, #\ptrs - 1 // table index
259 add \tmp2, \tbl, #PAGE_SIZE
260 orr \tmp2, \tmp2, #PMD_TYPE_TABLE // address of next table and entry type
261 str \tmp2, [\tbl, \tmp1, lsl #3]
262 add \tbl, \tbl, #PAGE_SIZE // next level table page
263 .endm
264
265/*
266 * Macro to populate the PGD (and possibily PUD) for the corresponding
267 * block entry in the next level (tbl) for the given virtual address.
268 *
269 * Preserves: tbl, next, virt
270 * Corrupts: tmp1, tmp2
271 */
272 .macro create_pgd_entry, tbl, virt, tmp1, tmp2
273 create_table_entry \tbl, \virt, PGDIR_SHIFT, PTRS_PER_PGD, \tmp1, \tmp2
6a3fd402
SP
274#if SWAPPER_PGTABLE_LEVELS > 3
275 create_table_entry \tbl, \virt, PUD_SHIFT, PTRS_PER_PUD, \tmp1, \tmp2
276#endif
277#if SWAPPER_PGTABLE_LEVELS > 2
87d1587b 278 create_table_entry \tbl, \virt, SWAPPER_TABLE_SHIFT, PTRS_PER_PTE, \tmp1, \tmp2
034edabe
LA
279#endif
280 .endm
281
282/*
283 * Macro to populate block entries in the page table for the start..end
284 * virtual range (inclusive).
285 *
286 * Preserves: tbl, flags
287 * Corrupts: phys, start, end, pstate
288 */
289 .macro create_block_map, tbl, flags, phys, start, end
87d1587b
SP
290 lsr \phys, \phys, #SWAPPER_BLOCK_SHIFT
291 lsr \start, \start, #SWAPPER_BLOCK_SHIFT
034edabe 292 and \start, \start, #PTRS_PER_PTE - 1 // table index
87d1587b
SP
293 orr \phys, \flags, \phys, lsl #SWAPPER_BLOCK_SHIFT // table entry
294 lsr \end, \end, #SWAPPER_BLOCK_SHIFT
034edabe
LA
295 and \end, \end, #PTRS_PER_PTE - 1 // table end index
2969999: str \phys, [\tbl, \start, lsl #3] // store the entry
297 add \start, \start, #1 // next entry
87d1587b 298 add \phys, \phys, #SWAPPER_BLOCK_SIZE // next block
034edabe
LA
299 cmp \start, \end
300 b.ls 9999b
301 .endm
302
303/*
304 * Setup the initial page tables. We only setup the barest amount which is
305 * required to get the kernel running. The following sections are required:
306 * - identity mapping to enable the MMU (low address, TTBR0)
307 * - first few MB of the kernel linear mapping to jump to once the MMU has
61bd93ce 308 * been enabled
034edabe
LA
309 */
310__create_page_tables:
6f4d57fa
AB
311 adrp x25, idmap_pg_dir
312 adrp x26, swapper_pg_dir
034edabe
LA
313 mov x27, lr
314
315 /*
316 * Invalidate the idmap and swapper page tables to avoid potential
317 * dirty cache lines being evicted.
318 */
319 mov x0, x25
320 add x1, x26, #SWAPPER_DIR_SIZE
321 bl __inval_cache_range
322
323 /*
324 * Clear the idmap and swapper page tables.
325 */
326 mov x0, x25
327 add x6, x26, #SWAPPER_DIR_SIZE
3281: stp xzr, xzr, [x0], #16
329 stp xzr, xzr, [x0], #16
330 stp xzr, xzr, [x0], #16
331 stp xzr, xzr, [x0], #16
332 cmp x0, x6
333 b.lo 1b
334
87d1587b 335 ldr x7, =SWAPPER_MM_MMUFLAGS
034edabe
LA
336
337 /*
338 * Create the identity mapping.
339 */
340 mov x0, x25 // idmap_pg_dir
5dfe9d7d 341 adrp x3, __idmap_text_start // __pa(__idmap_text_start)
dd006da2
AB
342
343#ifndef CONFIG_ARM64_VA_BITS_48
344#define EXTRA_SHIFT (PGDIR_SHIFT + PAGE_SHIFT - 3)
345#define EXTRA_PTRS (1 << (48 - EXTRA_SHIFT))
346
347 /*
348 * If VA_BITS < 48, it may be too small to allow for an ID mapping to be
349 * created that covers system RAM if that is located sufficiently high
350 * in the physical address space. So for the ID map, use an extended
351 * virtual range in that case, by configuring an additional translation
352 * level.
353 * First, we have to verify our assumption that the current value of
354 * VA_BITS was chosen such that all translation levels are fully
355 * utilised, and that lowering T0SZ will always result in an additional
356 * translation level to be configured.
357 */
358#if VA_BITS != EXTRA_SHIFT
359#error "Mismatch between VA_BITS and page size/number of translation levels"
360#endif
361
362 /*
363 * Calculate the maximum allowed value for TCR_EL1.T0SZ so that the
5dfe9d7d 364 * entire ID map region can be mapped. As T0SZ == (64 - #bits used),
dd006da2 365 * this number conveniently equals the number of leading zeroes in
5dfe9d7d 366 * the physical address of __idmap_text_end.
dd006da2 367 */
5dfe9d7d 368 adrp x5, __idmap_text_end
dd006da2
AB
369 clz x5, x5
370 cmp x5, TCR_T0SZ(VA_BITS) // default T0SZ small enough?
371 b.ge 1f // .. then skip additional level
372
0c20856c
MR
373 adr_l x6, idmap_t0sz
374 str x5, [x6]
375 dmb sy
376 dc ivac, x6 // Invalidate potentially stale cache line
dd006da2
AB
377
378 create_table_entry x0, x3, EXTRA_SHIFT, EXTRA_PTRS, x5, x6
3791:
380#endif
381
034edabe 382 create_pgd_entry x0, x3, x5, x6
5dfe9d7d
AB
383 mov x5, x3 // __pa(__idmap_text_start)
384 adr_l x6, __idmap_text_end // __pa(__idmap_text_end)
034edabe
LA
385 create_block_map x0, x7, x3, x5, x6
386
387 /*
388 * Map the kernel image (starting with PHYS_OFFSET).
389 */
390 mov x0, x26 // swapper_pg_dir
391 mov x5, #PAGE_OFFSET
392 create_pgd_entry x0, x5, x3, x6
6f4d57fa 393 ldr x6, =KERNEL_END // __va(KERNEL_END)
034edabe
LA
394 mov x3, x24 // phys offset
395 create_block_map x0, x7, x3, x5, x6
396
034edabe
LA
397 /*
398 * Since the page tables have been populated with non-cacheable
399 * accesses (MMU disabled), invalidate the idmap and swapper page
400 * tables again to remove any speculatively loaded cache lines.
401 */
402 mov x0, x25
403 add x1, x26, #SWAPPER_DIR_SIZE
91d57155 404 dmb sy
034edabe
LA
405 bl __inval_cache_range
406
407 mov lr, x27
408 ret
409ENDPROC(__create_page_tables)
410 .ltorg
411
034edabe 412/*
a871d354 413 * The following fragment of code is executed with the MMU enabled.
034edabe 414 */
a871d354 415 .set initial_sp, init_thread_union + THREAD_START_SP
034edabe 416__mmap_switched:
a871d354
AB
417 adr_l x6, __bss_start
418 adr_l x7, __bss_stop
034edabe 419
034edabe
LA
4201: cmp x6, x7
421 b.hs 2f
422 str xzr, [x6], #8 // Clear BSS
423 b 1b
4242:
a871d354
AB
425 adr_l sp, initial_sp, x4
426 str_l x21, __fdt_pointer, x5 // Save FDT pointer
427 str_l x24, memstart_addr, x6 // Save PHYS_OFFSET
034edabe 428 mov x29, #0
39d114dd
AR
429#ifdef CONFIG_KASAN
430 bl kasan_early_init
431#endif
034edabe
LA
432 b start_kernel
433ENDPROC(__mmap_switched)
434
435/*
436 * end early head section, begin head code that is also used for
437 * hotplug and needs to have the same protections as the text region
438 */
439 .section ".text","ax"
9703d9d7
CM
440/*
441 * If we're fortunate enough to boot at EL2, ensure that the world is
442 * sane before dropping to EL1.
828e9834
ML
443 *
444 * Returns either BOOT_CPU_MODE_EL1 or BOOT_CPU_MODE_EL2 in x20 if
445 * booted in EL1 or EL2 respectively.
9703d9d7
CM
446 */
447ENTRY(el2_setup)
448 mrs x0, CurrentEL
974c8e45 449 cmp x0, #CurrentEL_EL2
9cf71728
ML
450 b.ne 1f
451 mrs x0, sctlr_el2
452CPU_BE( orr x0, x0, #(1 << 25) ) // Set the EE bit for EL2
453CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2
454 msr sctlr_el2, x0
455 b 2f
4561: mrs x0, sctlr_el1
457CPU_BE( orr x0, x0, #(3 << 24) ) // Set the EE and E0E bits for EL1
458CPU_LE( bic x0, x0, #(3 << 24) ) // Clear the EE and E0E bits for EL1
459 msr sctlr_el1, x0
828e9834 460 mov w20, #BOOT_CPU_MODE_EL1 // This cpu booted in EL1
9cf71728 461 isb
9703d9d7
CM
462 ret
463
464 /* Hyp configuration. */
9cf71728 4652: mov x0, #(1 << 31) // 64-bit EL1
9703d9d7
CM
466 msr hcr_el2, x0
467
468 /* Generic timers. */
469 mrs x0, cnthctl_el2
470 orr x0, x0, #3 // Enable EL1 physical timers
471 msr cnthctl_el2, x0
1f75ff0a 472 msr cntvoff_el2, xzr // Clear virtual offset
9703d9d7 473
021f6537
MZ
474#ifdef CONFIG_ARM_GIC_V3
475 /* GICv3 system register access */
476 mrs x0, id_aa64pfr0_el1
477 ubfx x0, x0, #24, #4
478 cmp x0, #1
479 b.ne 3f
480
72c58395 481 mrs_s x0, ICC_SRE_EL2
021f6537
MZ
482 orr x0, x0, #ICC_SRE_EL2_SRE // Set ICC_SRE_EL2.SRE==1
483 orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1
72c58395 484 msr_s ICC_SRE_EL2, x0
021f6537 485 isb // Make sure SRE is now set
72c58395 486 msr_s ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults
021f6537
MZ
487
4883:
489#endif
490
9703d9d7
CM
491 /* Populate ID registers. */
492 mrs x0, midr_el1
493 mrs x1, mpidr_el1
494 msr vpidr_el2, x0
495 msr vmpidr_el2, x1
496
497 /* sctlr_el1 */
498 mov x0, #0x0800 // Set/clear RES{1,0} bits
9cf71728
ML
499CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems
500CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems
9703d9d7
CM
501 msr sctlr_el1, x0
502
503 /* Coprocessor traps. */
504 mov x0, #0x33ff
505 msr cptr_el2, x0 // Disable copro. traps to EL2
506
507#ifdef CONFIG_COMPAT
508 msr hstr_el2, xzr // Disable CP15 traps to EL2
509#endif
510
d10bcd47
WD
511 /* EL2 debug */
512 mrs x0, pmcr_el0 // Disable debug access traps
513 ubfx x0, x0, #11, #5 // to EL2 and allow access to
514 msr mdcr_el2, x0 // all PMU counters from EL1
515
7dbfbe5b
MZ
516 /* Stage-2 translation */
517 msr vttbr_el2, xzr
518
712c6ff4 519 /* Hypervisor stub */
ac2dec5f
LA
520 adrp x0, __hyp_stub_vectors
521 add x0, x0, #:lo12:__hyp_stub_vectors
712c6ff4
MZ
522 msr vbar_el2, x0
523
9703d9d7
CM
524 /* spsr */
525 mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
526 PSR_MODE_EL1h)
527 msr spsr_el2, x0
528 msr elr_el2, lr
828e9834 529 mov w20, #BOOT_CPU_MODE_EL2 // This CPU booted in EL2
9703d9d7
CM
530 eret
531ENDPROC(el2_setup)
532
828e9834
ML
533/*
534 * Sets the __boot_cpu_mode flag depending on the CPU boot mode passed
535 * in x20. See arch/arm64/include/asm/virt.h for more info.
536 */
537ENTRY(set_cpu_boot_mode_flag)
6f4d57fa 538 adr_l x1, __boot_cpu_mode
828e9834
ML
539 cmp w20, #BOOT_CPU_MODE_EL2
540 b.ne 1f
541 add x1, x1, #4
d0488597
WD
5421: str w20, [x1] // This CPU has booted in EL1
543 dmb sy
544 dc ivac, x1 // Invalidate potentially stale cache line
828e9834
ML
545 ret
546ENDPROC(set_cpu_boot_mode_flag)
547
f35a9205
MZ
548/*
549 * We need to find out the CPU boot mode long after boot, so we need to
550 * store it in a writable variable.
551 *
552 * This is not in .bss, because we set it sufficiently early that the boot-time
553 * zeroing of .bss would clobber it.
554 */
c218bca7 555 .pushsection .data..cacheline_aligned
c218bca7 556 .align L1_CACHE_SHIFT
947bb758 557ENTRY(__boot_cpu_mode)
f35a9205 558 .long BOOT_CPU_MODE_EL2
424a3838 559 .long BOOT_CPU_MODE_EL1
f35a9205
MZ
560 .popsection
561
9703d9d7
CM
562 /*
563 * This provides a "holding pen" for platforms to hold all secondary
564 * cores are held until we're ready for them to initialise.
565 */
566ENTRY(secondary_holding_pen)
828e9834 567 bl el2_setup // Drop to EL1, w20=cpu_boot_mode
828e9834 568 bl set_cpu_boot_mode_flag
9703d9d7 569 mrs x0, mpidr_el1
0359b0e2
JM
570 ldr x1, =MPIDR_HWID_BITMASK
571 and x0, x0, x1
b1c98297 572 adr_l x3, secondary_holding_pen_release
9703d9d7
CM
573pen: ldr x4, [x3]
574 cmp x4, x0
575 b.eq secondary_startup
576 wfe
577 b pen
578ENDPROC(secondary_holding_pen)
652af899
MR
579
580 /*
581 * Secondary entry point that jumps straight into the kernel. Only to
582 * be used where CPUs are brought online dynamically by the kernel.
583 */
584ENTRY(secondary_entry)
652af899 585 bl el2_setup // Drop to EL1
85cc00ea 586 bl set_cpu_boot_mode_flag
652af899
MR
587 b secondary_startup
588ENDPROC(secondary_entry)
9703d9d7
CM
589
590ENTRY(secondary_startup)
591 /*
592 * Common entry point for secondary CPUs.
593 */
6f4d57fa
AB
594 adrp x25, idmap_pg_dir
595 adrp x26, swapper_pg_dir
a591ede4 596 bl __cpu_setup // initialise processor
9703d9d7
CM
597
598 ldr x21, =secondary_data
599 ldr x27, =__secondary_switched // address to jump to after enabling the MMU
600 b __enable_mmu
601ENDPROC(secondary_startup)
602
603ENTRY(__secondary_switched)
604 ldr x0, [x21] // get secondary_data.stack
605 mov sp, x0
606 mov x29, #0
607 b secondary_start_kernel
608ENDPROC(__secondary_switched)
9703d9d7
CM
609
610/*
8b0a9575 611 * Enable the MMU.
9703d9d7 612 *
8b0a9575
AB
613 * x0 = SCTLR_EL1 value for turning on the MMU.
614 * x27 = *virtual* address to jump to upon completion
615 *
616 * other registers depend on the function called upon completion
9703d9d7 617 */
5dfe9d7d 618 .section ".idmap.text", "ax"
9703d9d7
CM
619__enable_mmu:
620 ldr x5, =vectors
621 msr vbar_el1, x5
622 msr ttbr0_el1, x25 // load TTBR0
623 msr ttbr1_el1, x26 // load TTBR1
624 isb
9703d9d7
CM
625 msr sctlr_el1, x0
626 isb
8ec41987
WD
627 /*
628 * Invalidate the local I-cache so that any instructions fetched
629 * speculatively from the PoC are discarded, since they may have
630 * been dynamically patched at the PoU.
631 */
632 ic iallu
633 dsb nsh
634 isb
9703d9d7 635 br x27
8b0a9575 636ENDPROC(__enable_mmu)