4 * Copyright (C) Linaro.
5 * Copyright (C) Huawei Futurewei Technologies.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kexec.h>
13 #include <linux/linkage.h>
15 #include <asm/assembler.h>
16 #include <asm/kexec.h>
18 #include <asm/sysreg.h>
21 * arm64_relocate_new_kernel - Put a 2nd stage image in place and boot it.
23 * The memory that the old kernel occupies may be overwritten when coping the
24 * new image to its final location. To assure that the
25 * arm64_relocate_new_kernel routine which does that copy is not overwritten,
26 * all code and data needed by arm64_relocate_new_kernel must be between the
27 * symbols arm64_relocate_new_kernel and arm64_relocate_new_kernel_end. The
28 * machine_kexec() routine will copy arm64_relocate_new_kernel to the kexec
29 * control_code_page, a special page which has been set up to be preserved
30 * during the copy operation.
32 ENTRY(arm64_relocate_new_kernel)
34 /* Setup the list loop variables. */
35 mov x18, x2 /* x18 = dtb address */
36 mov x17, x1 /* x17 = kimage_start */
37 mov x16, x0 /* x16 = kimage_head */
38 raw_dcache_line_size x15, x0 /* x15 = dcache line size */
39 mov x14, xzr /* x14 = entry ptr */
40 mov x13, xzr /* x13 = copy dest */
42 /* Clear the sctlr_el2 flags. */
44 cmp x0, #CurrentEL_EL2
47 ldr x1, =SCTLR_ELx_FLAGS
49 pre_disable_mmu_workaround
54 /* Check if the new image needs relocation. */
55 tbnz x16, IND_DONE_BIT, .Ldone
58 and x12, x16, PAGE_MASK /* x12 = addr */
60 /* Test the entry flags. */
62 tbz x16, IND_SOURCE_BIT, .Ltest_indirection
64 /* Invalidate dest page to PoC. */
66 add x20, x0, #PAGE_SIZE
77 copy_page x20, x21, x0, x1, x2, x3, x4, x5, x6, x7
79 /* dest += PAGE_SIZE */
80 add x13, x13, PAGE_SIZE
84 tbz x16, IND_INDIRECTION_BIT, .Ltest_destination
91 tbz x16, IND_DESTINATION_BIT, .Lnext
100 /* while (!(entry & DONE)) */
101 tbz x16, IND_DONE_BIT, .Lloop
104 /* wait for writes from copy_page to finish */
110 /* Start new image. */
117 ENDPROC(arm64_relocate_new_kernel)
121 .align 3 /* To keep the 64-bit values below naturally aligned. */
124 .org KEXEC_CONTROL_PAGE_SIZE
127 * arm64_relocate_new_kernel_size - Number of bytes to copy to the
130 .globl arm64_relocate_new_kernel_size
131 arm64_relocate_new_kernel_size:
132 .quad .Lcopy_end - arm64_relocate_new_kernel