]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/arm64/kernel/head.S
arm64: Calculate size for idmap_pg_dir at compile time
[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
274#if SWAPPER_PGTABLE_LEVELS == 3
87d1587b 275 create_table_entry \tbl, \virt, SWAPPER_TABLE_SHIFT, PTRS_PER_PTE, \tmp1, \tmp2
034edabe
LA
276#endif
277 .endm
278
279/*
280 * Macro to populate block entries in the page table for the start..end
281 * virtual range (inclusive).
282 *
283 * Preserves: tbl, flags
284 * Corrupts: phys, start, end, pstate
285 */
286 .macro create_block_map, tbl, flags, phys, start, end
87d1587b
SP
287 lsr \phys, \phys, #SWAPPER_BLOCK_SHIFT
288 lsr \start, \start, #SWAPPER_BLOCK_SHIFT
034edabe 289 and \start, \start, #PTRS_PER_PTE - 1 // table index
87d1587b
SP
290 orr \phys, \flags, \phys, lsl #SWAPPER_BLOCK_SHIFT // table entry
291 lsr \end, \end, #SWAPPER_BLOCK_SHIFT
034edabe
LA
292 and \end, \end, #PTRS_PER_PTE - 1 // table end index
2939999: str \phys, [\tbl, \start, lsl #3] // store the entry
294 add \start, \start, #1 // next entry
87d1587b 295 add \phys, \phys, #SWAPPER_BLOCK_SIZE // next block
034edabe
LA
296 cmp \start, \end
297 b.ls 9999b
298 .endm
299
300/*
301 * Setup the initial page tables. We only setup the barest amount which is
302 * required to get the kernel running. The following sections are required:
303 * - identity mapping to enable the MMU (low address, TTBR0)
304 * - first few MB of the kernel linear mapping to jump to once the MMU has
61bd93ce 305 * been enabled
034edabe
LA
306 */
307__create_page_tables:
6f4d57fa
AB
308 adrp x25, idmap_pg_dir
309 adrp x26, swapper_pg_dir
034edabe
LA
310 mov x27, lr
311
312 /*
313 * Invalidate the idmap and swapper page tables to avoid potential
314 * dirty cache lines being evicted.
315 */
316 mov x0, x25
317 add x1, x26, #SWAPPER_DIR_SIZE
318 bl __inval_cache_range
319
320 /*
321 * Clear the idmap and swapper page tables.
322 */
323 mov x0, x25
324 add x6, x26, #SWAPPER_DIR_SIZE
3251: stp xzr, xzr, [x0], #16
326 stp xzr, xzr, [x0], #16
327 stp xzr, xzr, [x0], #16
328 stp xzr, xzr, [x0], #16
329 cmp x0, x6
330 b.lo 1b
331
87d1587b 332 ldr x7, =SWAPPER_MM_MMUFLAGS
034edabe
LA
333
334 /*
335 * Create the identity mapping.
336 */
337 mov x0, x25 // idmap_pg_dir
5dfe9d7d 338 adrp x3, __idmap_text_start // __pa(__idmap_text_start)
dd006da2
AB
339
340#ifndef CONFIG_ARM64_VA_BITS_48
341#define EXTRA_SHIFT (PGDIR_SHIFT + PAGE_SHIFT - 3)
342#define EXTRA_PTRS (1 << (48 - EXTRA_SHIFT))
343
344 /*
345 * If VA_BITS < 48, it may be too small to allow for an ID mapping to be
346 * created that covers system RAM if that is located sufficiently high
347 * in the physical address space. So for the ID map, use an extended
348 * virtual range in that case, by configuring an additional translation
349 * level.
350 * First, we have to verify our assumption that the current value of
351 * VA_BITS was chosen such that all translation levels are fully
352 * utilised, and that lowering T0SZ will always result in an additional
353 * translation level to be configured.
354 */
355#if VA_BITS != EXTRA_SHIFT
356#error "Mismatch between VA_BITS and page size/number of translation levels"
357#endif
358
359 /*
360 * Calculate the maximum allowed value for TCR_EL1.T0SZ so that the
5dfe9d7d 361 * entire ID map region can be mapped. As T0SZ == (64 - #bits used),
dd006da2 362 * this number conveniently equals the number of leading zeroes in
5dfe9d7d 363 * the physical address of __idmap_text_end.
dd006da2 364 */
5dfe9d7d 365 adrp x5, __idmap_text_end
dd006da2
AB
366 clz x5, x5
367 cmp x5, TCR_T0SZ(VA_BITS) // default T0SZ small enough?
368 b.ge 1f // .. then skip additional level
369
0c20856c
MR
370 adr_l x6, idmap_t0sz
371 str x5, [x6]
372 dmb sy
373 dc ivac, x6 // Invalidate potentially stale cache line
dd006da2
AB
374
375 create_table_entry x0, x3, EXTRA_SHIFT, EXTRA_PTRS, x5, x6
3761:
377#endif
378
034edabe 379 create_pgd_entry x0, x3, x5, x6
5dfe9d7d
AB
380 mov x5, x3 // __pa(__idmap_text_start)
381 adr_l x6, __idmap_text_end // __pa(__idmap_text_end)
034edabe
LA
382 create_block_map x0, x7, x3, x5, x6
383
384 /*
385 * Map the kernel image (starting with PHYS_OFFSET).
386 */
387 mov x0, x26 // swapper_pg_dir
388 mov x5, #PAGE_OFFSET
389 create_pgd_entry x0, x5, x3, x6
6f4d57fa 390 ldr x6, =KERNEL_END // __va(KERNEL_END)
034edabe
LA
391 mov x3, x24 // phys offset
392 create_block_map x0, x7, x3, x5, x6
393
034edabe
LA
394 /*
395 * Since the page tables have been populated with non-cacheable
396 * accesses (MMU disabled), invalidate the idmap and swapper page
397 * tables again to remove any speculatively loaded cache lines.
398 */
399 mov x0, x25
400 add x1, x26, #SWAPPER_DIR_SIZE
91d57155 401 dmb sy
034edabe
LA
402 bl __inval_cache_range
403
404 mov lr, x27
405 ret
406ENDPROC(__create_page_tables)
407 .ltorg
408
034edabe 409/*
a871d354 410 * The following fragment of code is executed with the MMU enabled.
034edabe 411 */
a871d354 412 .set initial_sp, init_thread_union + THREAD_START_SP
034edabe 413__mmap_switched:
a871d354
AB
414 adr_l x6, __bss_start
415 adr_l x7, __bss_stop
034edabe 416
034edabe
LA
4171: cmp x6, x7
418 b.hs 2f
419 str xzr, [x6], #8 // Clear BSS
420 b 1b
4212:
a871d354
AB
422 adr_l sp, initial_sp, x4
423 str_l x21, __fdt_pointer, x5 // Save FDT pointer
424 str_l x24, memstart_addr, x6 // Save PHYS_OFFSET
034edabe 425 mov x29, #0
39d114dd
AR
426#ifdef CONFIG_KASAN
427 bl kasan_early_init
428#endif
034edabe
LA
429 b start_kernel
430ENDPROC(__mmap_switched)
431
432/*
433 * end early head section, begin head code that is also used for
434 * hotplug and needs to have the same protections as the text region
435 */
436 .section ".text","ax"
9703d9d7
CM
437/*
438 * If we're fortunate enough to boot at EL2, ensure that the world is
439 * sane before dropping to EL1.
828e9834
ML
440 *
441 * Returns either BOOT_CPU_MODE_EL1 or BOOT_CPU_MODE_EL2 in x20 if
442 * booted in EL1 or EL2 respectively.
9703d9d7
CM
443 */
444ENTRY(el2_setup)
445 mrs x0, CurrentEL
974c8e45 446 cmp x0, #CurrentEL_EL2
9cf71728
ML
447 b.ne 1f
448 mrs x0, sctlr_el2
449CPU_BE( orr x0, x0, #(1 << 25) ) // Set the EE bit for EL2
450CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2
451 msr sctlr_el2, x0
452 b 2f
4531: mrs x0, sctlr_el1
454CPU_BE( orr x0, x0, #(3 << 24) ) // Set the EE and E0E bits for EL1
455CPU_LE( bic x0, x0, #(3 << 24) ) // Clear the EE and E0E bits for EL1
456 msr sctlr_el1, x0
828e9834 457 mov w20, #BOOT_CPU_MODE_EL1 // This cpu booted in EL1
9cf71728 458 isb
9703d9d7
CM
459 ret
460
461 /* Hyp configuration. */
9cf71728 4622: mov x0, #(1 << 31) // 64-bit EL1
9703d9d7
CM
463 msr hcr_el2, x0
464
465 /* Generic timers. */
466 mrs x0, cnthctl_el2
467 orr x0, x0, #3 // Enable EL1 physical timers
468 msr cnthctl_el2, x0
1f75ff0a 469 msr cntvoff_el2, xzr // Clear virtual offset
9703d9d7 470
021f6537
MZ
471#ifdef CONFIG_ARM_GIC_V3
472 /* GICv3 system register access */
473 mrs x0, id_aa64pfr0_el1
474 ubfx x0, x0, #24, #4
475 cmp x0, #1
476 b.ne 3f
477
72c58395 478 mrs_s x0, ICC_SRE_EL2
021f6537
MZ
479 orr x0, x0, #ICC_SRE_EL2_SRE // Set ICC_SRE_EL2.SRE==1
480 orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1
72c58395 481 msr_s ICC_SRE_EL2, x0
021f6537 482 isb // Make sure SRE is now set
72c58395 483 msr_s ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults
021f6537
MZ
484
4853:
486#endif
487
9703d9d7
CM
488 /* Populate ID registers. */
489 mrs x0, midr_el1
490 mrs x1, mpidr_el1
491 msr vpidr_el2, x0
492 msr vmpidr_el2, x1
493
494 /* sctlr_el1 */
495 mov x0, #0x0800 // Set/clear RES{1,0} bits
9cf71728
ML
496CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems
497CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems
9703d9d7
CM
498 msr sctlr_el1, x0
499
500 /* Coprocessor traps. */
501 mov x0, #0x33ff
502 msr cptr_el2, x0 // Disable copro. traps to EL2
503
504#ifdef CONFIG_COMPAT
505 msr hstr_el2, xzr // Disable CP15 traps to EL2
506#endif
507
d10bcd47
WD
508 /* EL2 debug */
509 mrs x0, pmcr_el0 // Disable debug access traps
510 ubfx x0, x0, #11, #5 // to EL2 and allow access to
511 msr mdcr_el2, x0 // all PMU counters from EL1
512
7dbfbe5b
MZ
513 /* Stage-2 translation */
514 msr vttbr_el2, xzr
515
712c6ff4 516 /* Hypervisor stub */
ac2dec5f
LA
517 adrp x0, __hyp_stub_vectors
518 add x0, x0, #:lo12:__hyp_stub_vectors
712c6ff4
MZ
519 msr vbar_el2, x0
520
9703d9d7
CM
521 /* spsr */
522 mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
523 PSR_MODE_EL1h)
524 msr spsr_el2, x0
525 msr elr_el2, lr
828e9834 526 mov w20, #BOOT_CPU_MODE_EL2 // This CPU booted in EL2
9703d9d7
CM
527 eret
528ENDPROC(el2_setup)
529
828e9834
ML
530/*
531 * Sets the __boot_cpu_mode flag depending on the CPU boot mode passed
532 * in x20. See arch/arm64/include/asm/virt.h for more info.
533 */
534ENTRY(set_cpu_boot_mode_flag)
6f4d57fa 535 adr_l x1, __boot_cpu_mode
828e9834
ML
536 cmp w20, #BOOT_CPU_MODE_EL2
537 b.ne 1f
538 add x1, x1, #4
d0488597
WD
5391: str w20, [x1] // This CPU has booted in EL1
540 dmb sy
541 dc ivac, x1 // Invalidate potentially stale cache line
828e9834
ML
542 ret
543ENDPROC(set_cpu_boot_mode_flag)
544
f35a9205
MZ
545/*
546 * We need to find out the CPU boot mode long after boot, so we need to
547 * store it in a writable variable.
548 *
549 * This is not in .bss, because we set it sufficiently early that the boot-time
550 * zeroing of .bss would clobber it.
551 */
c218bca7 552 .pushsection .data..cacheline_aligned
c218bca7 553 .align L1_CACHE_SHIFT
947bb758 554ENTRY(__boot_cpu_mode)
f35a9205 555 .long BOOT_CPU_MODE_EL2
424a3838 556 .long BOOT_CPU_MODE_EL1
f35a9205
MZ
557 .popsection
558
9703d9d7
CM
559 /*
560 * This provides a "holding pen" for platforms to hold all secondary
561 * cores are held until we're ready for them to initialise.
562 */
563ENTRY(secondary_holding_pen)
828e9834 564 bl el2_setup // Drop to EL1, w20=cpu_boot_mode
828e9834 565 bl set_cpu_boot_mode_flag
9703d9d7 566 mrs x0, mpidr_el1
0359b0e2
JM
567 ldr x1, =MPIDR_HWID_BITMASK
568 and x0, x0, x1
b1c98297 569 adr_l x3, secondary_holding_pen_release
9703d9d7
CM
570pen: ldr x4, [x3]
571 cmp x4, x0
572 b.eq secondary_startup
573 wfe
574 b pen
575ENDPROC(secondary_holding_pen)
652af899
MR
576
577 /*
578 * Secondary entry point that jumps straight into the kernel. Only to
579 * be used where CPUs are brought online dynamically by the kernel.
580 */
581ENTRY(secondary_entry)
652af899 582 bl el2_setup // Drop to EL1
85cc00ea 583 bl set_cpu_boot_mode_flag
652af899
MR
584 b secondary_startup
585ENDPROC(secondary_entry)
9703d9d7
CM
586
587ENTRY(secondary_startup)
588 /*
589 * Common entry point for secondary CPUs.
590 */
6f4d57fa
AB
591 adrp x25, idmap_pg_dir
592 adrp x26, swapper_pg_dir
a591ede4 593 bl __cpu_setup // initialise processor
9703d9d7
CM
594
595 ldr x21, =secondary_data
596 ldr x27, =__secondary_switched // address to jump to after enabling the MMU
597 b __enable_mmu
598ENDPROC(secondary_startup)
599
600ENTRY(__secondary_switched)
601 ldr x0, [x21] // get secondary_data.stack
602 mov sp, x0
603 mov x29, #0
604 b secondary_start_kernel
605ENDPROC(__secondary_switched)
9703d9d7
CM
606
607/*
8b0a9575 608 * Enable the MMU.
9703d9d7 609 *
8b0a9575
AB
610 * x0 = SCTLR_EL1 value for turning on the MMU.
611 * x27 = *virtual* address to jump to upon completion
612 *
613 * other registers depend on the function called upon completion
9703d9d7 614 */
5dfe9d7d 615 .section ".idmap.text", "ax"
9703d9d7
CM
616__enable_mmu:
617 ldr x5, =vectors
618 msr vbar_el1, x5
619 msr ttbr0_el1, x25 // load TTBR0
620 msr ttbr1_el1, x26 // load TTBR1
621 isb
9703d9d7
CM
622 msr sctlr_el1, x0
623 isb
8ec41987
WD
624 /*
625 * Invalidate the local I-cache so that any instructions fetched
626 * speculatively from the PoC are discarded, since they may have
627 * been dynamically patched at the PoU.
628 */
629 ic iallu
630 dsb nsh
631 isb
9703d9d7 632 br x27
8b0a9575 633ENDPROC(__enable_mmu)