armv8: Support loading 32-bit OS in AArch32 execution state
Subsystems (2)
v2 cover armv8: Support loading 32-bit OS in AArch32 execution state
This series is to support loading a 32-bit OS, the execution state will change from AArch64 to AArch32 when jumping to kernel. The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
Spin-table method is used for secondary cores to load 32-bit OS. The architecture information will be got through checking FIT image and saved in the os_arch element of spin-table, then the secondary cores will check os_arch and jump to 32-bit OS or 64-bit OS automatically.
Changes in v2:
- armv8_switch_to_el2_aarch32() is removed. armv8_switch_to_el2_m is used to switch to AArch64 EL2 or AArch32 Hyp.
- armv8_switch_to_el1_aarch32() is removed. armv8_switch_to_el1_m is used to switch to AArch64 EL1 or AArch32 SVC.
----------------------------------------------------------------
Alison Wang (2):
armv8: Support loading 32-bit OS in AArch32 execution state
armv8: fsl-layerscape: SMP support for loading 32-bit OS
arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S | 35 +++++++++++++++++++++++++++++++---- arch/arm/cpu/armv8/fsl-layerscape/mp.c | 10 ++++++++++ arch/arm/cpu/armv8/transition.S | 8 ++++---- arch/arm/include/asm/arch-fsl-layerscape/mp.h | 6 ++++++ arch/arm/include/asm/macro.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- arch/arm/include/asm/system.h | 25 +++++++++++++++++++++++-- arch/arm/lib/bootm.c | 31 +++++++++++++++++++++++++++---- common/image-fit.c | 12 +++++++++++- 8 files changed, 185 insertions(+), 22 deletions(-)
PATCH v2 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
To support loading a 32-bit OS, the execution state will change from AArch64 to AArch32 when jumping to kernel.
The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
---
Changes in v2:
- armv8_switch_to_el2_aarch32() is removed. armv8_switch_to_el2_m is used to switch to AArch64 EL2 or AArch32 Hyp.
- armv8_switch_to_el1_aarch32() is removed. armv8_switch_to_el1_m is used to switch to AArch64 EL1 or AArch32 SVC.
arch/arm/cpu/armv8/transition.S | 8 ++--- arch/arm/include/asm/macro.h | 80 +++++++++++++++++++++++++++++++++++++---- arch/arm/include/asm/system.h | 25 +++++++++++-- arch/arm/lib/bootm.c | 26 +++++++++++--- common/image-fit.c | 12 ++++++- 5 files changed, 133 insertions(+), 18 deletions(-)
arch/arm/cpu/armv8/transition.S +4 -4
@@ -11,13 +11,13 @@ #include <asm/macro.h> ENTRY(armv8_switch_to_el2) - switch_el x0, 1f, 0f, 0f + switch_el x4, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el2) ENTRY(armv8_switch_to_el1) - switch_el x0, 0f, 1f, 0f + switch_el x4, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el1)
arch/arm/include/asm/macro.h +73 -7
128 lines not on this page · raw message
arch/arm/include/asm/system.h +23 -2
@@ -17,6 +17,9 @@#define CR_WXN (1 << 19)/* Write Permision Imply XN */ #define CR_EE (1 << 25)/* Exception (Big) Endian */ +#define ES_TO_AARCH64 1 +#define ES_TO_AARCH32 0 +#ifndef __ASSEMBLY__u64 get_page_table_size (void );
@@ -100,8 +103,26 @@ void __asm_invalidate_icache_all(void);int __asm_flush_l3_cache (void );void __asm_switch_ttbr (u64 new_ttbr); -void armv8_switch_to_el2 (void ); -void armv8_switch_to_el1 (void ); +/* +* Switch from EL3 to EL2 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el2 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag); +/* +* Switch from EL2 to EL1 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el1 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag);void gic_init (void );void gic_send_sgi (unsigned long sgino);void wait_for_wakeup (void );
arch/arm/lib/bootm.c +22 -4
@@ -193,9 +193,9 @@ static void do_nonsec_virt_switch(void) {smp_kick_all_cpus ();dcache_disable ();/* flush cache before swtiching to EL2 */ -armv8_switch_to_el2 (); +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 );#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 -armv8_switch_to_el1 (); +armv8_switch_to_el1 (0 ,0 ,0 ,ES_TO_AARCH64 );#endif }#endif
@@ -286,8 +286,26 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)announce_and_cleanup (fake);if (!fake) { -do_nonsec_virt_switch (); -kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); +if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && + (images->os.arch ==IH_ARCH_ARM )) { +smp_kick_all_cpus (); +dcache_disable (); +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 ); +armv8_switch_to_el1 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#else +armv8_switch_to_el2 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#endif + }else { +do_nonsec_virt_switch (); +kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); + } }#else unsigned long machid = gd->bd->bi_arch_number;
common/image-fit.c +11 -1
@@ -1163,7 +1163,8 @@ int fit_image_check_arch(const void *fit, int noffset, uint8_t arch)if (fit_image_get_arch (fit, noffset, &image_arch))return 0 ;return (arch == image_arch) || - (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ); + (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ) || + (arch ==IH_ARCH_ARM64 && image_arch ==IH_ARCH_ARM ); }/**
@@ -1586,6 +1587,9 @@ int fit_image_load(bootm_headers_t *images, ulong addr,int type_ok, os_ok;ulong load, data, len;uint8_t os; +#ifndef USE_HOSTCC +uint8_t os_arch; +#endif const char *prop_name;int ret;
@@ -1669,6 +1673,12 @@ int fit_image_load(bootm_headers_t *images, ulong addr, return -ENOEXEC; }#endif + +#ifndef USE_HOSTCC +fit_image_get_arch (fit, noffset, &os_arch); + images->os.arch = os_arch; +#endif +if (image_type ==IH_TYPE_FLATDT && !fit_image_check_comp (fit, noffset,IH_COMP_NONE )) {puts ("FDT image is compressed" );
Signature · 1 line
2.1.0.27.g96db324
PATCH v2 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
Quoted 60 lines · Alison Wang
To support loading a 32-bit OS, the execution state will change from AArch64 to AArch32 when jumping to kernel.
The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
Signed-off-by Ebony Zhu <[email protected]>Signed-off-by Alison Wang <[email protected]>Signed-off-by Chenhui Zhao <[email protected]>---
Changes in v2:
-armv8_switch_to_el2_aarch32()is removed.armv8_switch_to_el2_mis used to switch to AArch64 EL2 or AArch32 Hyp.
-armv8_switch_to_el1_aarch32()is removed.armv8_switch_to_el1_mis used to switch to AArch64 EL1 or AArch32 SVC.arch/arm/cpu/armv8/transition.S | 8 ++--- arch/arm/include/asm/macro.h | 80 +++++++++++++++++++++++++++++++++++++---- arch/arm/include/asm/system.h | 25 +++++++++++-- arch/arm/lib/bootm.c | 26 +++++++++++--- common/image-fit.c | 12 ++++++- 5 files changed, 133 insertions(+), 18 deletions(-)arch/arm/cpu/armv8/transition.S +4
-4@@ -11,13 +11,13 @@ #include <asm/macro.h> ENTRY(armv8_switch_to_el2) - switch_el x0, 1f, 0f, 0f + switch_el x4, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el2) ENTRY(armv8_switch_to_el1) - switch_el x0, 0f, 1f, 0f + switch_el x4, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el1)arch/arm/include/asm/macro.h +3
-0@@ -8,6 +8,9 @@#ifndef __ASM_ARM_MACRO_H__#define __ASM_ARM_MACRO_H__ + +#include <asm/system.h> +#ifdef __ASSEMBLY__/*
arch/arm/include/asm/macro.h lr .req x30 · line 141
Quoted 7 lines
arch/arm/include/asm/macro.h +1
-3@@ -135,9 +138,20 @@ lr .req x30#endif .endm -.macro armv8_switch_to_el2_m, xreg1 -/* 64bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | Non-secure EL0/EL1 */ - mov \xreg1, #0x5b1 +.macro armv8_switch_to_el2_m, xreg1, xreg2, xreg3, xreg4, xreg5, xreg6, xreg7
These arguments should probably get documented :). Also xreg4 doesn't seem to actually be a scratch register, but a real parameter. So please name it accordingly.
arch/arm/include/asm/macro.h lr .req x30 · line 154
Quoted 13 lines
arch/arm/include/asm/macro.h +13
-0+ mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + + /* + * If the next lower exception level is AArch64, 64bit EL2 | HCE | SMD | + * RES1 (Bits[5:4]) | Non-secure EL0/EL1. If the next lower exception + * level is AArch32, 32bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | + * Non-secure EL0/EL1. + */ + mov \xreg1, #0x1b1 + lsl \xreg2, \xreg4, #10 + orr \xreg1, \xreg1, \xreg2
Is there any way you can make this obvious from the code? Basically we would want something like
mov \xreg1, #(SCR_EL3_EL2_AA64 | SCR_EL3_HCE | SCR_EL3_SMD ...)
I'm sure there are creative ways to achieve this even with the high bits set. Maybe ldr = works?
Quoted 8 lines
arch/arm/include/asm/macro.h +0
-1msr scr_el3, \xreg1 msr cptr_el3, xzr /* Disable coprocessor traps to EL3 */ mov \xreg1, #0x33ff@@ -156,18 +170,46 @@ lr .req x30 movk \xreg1, #0x30C5, lsl #16 msr sctlr_el2, \xreg1 -/* Return to the EL2_SP2 mode from EL3 */
arch/arm/include/asm/macro.h lr .req x30 · line 182
Quoted 10 lines
arch/arm/include/asm/macro.h +6
-0mov \xreg1, sp msr sp_el2, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el3 msr vbar_el2, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL2 or AArch32 Hypervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2f
Just b.ne should be enough, no?
arch/arm/include/asm/macro.h lr .req x30 · line 186
Quoted 4 lines
arch/arm/include/asm/macro.h +3
-0+ +1: +/* Return to the EL2_SP2 mode from EL3 */ mov \xreg1, #0x3c9
Magic values again :). Please convert them to constants getting ORed.
Quoted 31 lines
arch/arm/include/asm/macro.h +21
-1msr spsr_el3, \xreg1 /* EL2_SP2 | D | A | I | F */ msr elr_el3, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to AArch32 Hypervisor mode */ + mov \xreg1, #0x1da + msr spsr_el3, \xreg1 /* Hyp | D | A | I | F */ + msr elr_el3, \xreg5 + + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endm -.macro armv8_switch_to_el1_m, xreg1, xreg2 +.macro armv8_switch_to_el1_m, xreg1, xreg2, xreg3, xreg4, xreg5, xreg6, xreg7 + mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + /* Initialize Generic Timers */ mrs \xreg1, cnthctl_el2 orr \xreg1, \xreg1, #0x3 /* Enable EL1 access to timers */
arch/arm/include/asm/macro.h lr .req x30 · line 233
Quoted 5 lines
arch/arm/include/asm/macro.h +1
-1@@ -188,7 +230,7 @@ lr .req x30 msr cpacr_el1, \xreg1 /* Enable FP/SIMD at EL1 */ /* Initialize HCR_EL2 */ - mov \xreg1, #(1 << 31) /* 64bit EL1 */ + lsl \xreg1, \xreg4, #31
This deserves a comment. Imagine you read this code again in 5 years. Would you still understand what's going on?
Quoted 92 lines
arch/arm/include/asm/macro.h +25
-1orr \xreg1, \xreg1, #(1 << 29) /* Disable HVC */ msr hcr_el2, \xreg1@@ -203,15 +245,39 @@ lr .req x30 movk \xreg1, #0x30d0, lsl #16 msr sctlr_el1, \xreg1 - /* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, sp msr sp_el1, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el2 msr vbar_el1, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL1 or AArch32 Supervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2f + +1: +/* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, #0x3c5 msr spsr_el2, \xreg1 /* EL1_SP1 | D | A | I | F */ msr elr_el2, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to the Supervisor mode from EL2 */ + mov \xreg1, #0x1d3 + msr spsr_el2, \xreg1 /* Supervisor | D | A | I | F */ + msr elr_el2, \xreg5 + + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endm #if defined(CONFIG_GICV3)arch/arm/include/asm/system.h +23
-2@@ -17,6 +17,9 @@#define CR_WXN (1 << 19)/* Write Permision Imply XN */ #define CR_EE (1 << 25)/* Exception (Big) Endian */ +#define ES_TO_AARCH64 1 +#define ES_TO_AARCH32 0 +#ifndef __ASSEMBLY__u64 get_page_table_size (void );@@ -100,8 +103,26 @@ void __asm_invalidate_icache_all(void);int __asm_flush_l3_cache (void );void __asm_switch_ttbr (u64 new_ttbr); -void armv8_switch_to_el2 (void ); -void armv8_switch_to_el1 (void ); +/* +* Switch from EL3 to EL2 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el2 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag); +/* +* Switch from EL2 to EL1 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el1 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag);void gic_init (void );void gic_send_sgi (unsigned long sgino);void wait_for_wakeup (void );arch/arm/lib/bootm.c +0
-0
arch/arm/lib/bootm.c static void do_nonsec_virt_switch(void) · line 196
Quoted 5 lines
arch/arm/lib/bootm.c +1
-1@@ -193,9 +193,9 @@ static void do_nonsec_virt_switch(void) {smp_kick_all_cpus ();dcache_disable ();/* flush cache before swtiching to EL2 */ -armv8_switch_to_el2 (); +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 );
Just rename the existing function to armv8_switch_to_el2_adv() or so and provide armv8_switch_to_el2() as static inline function that simply invokes armv8_switch_to_el2_adv(0, 0, 0, ES_TO_AARCH64);
Quoted 7 lines
arch/arm/lib/bootm.c +1
-1#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 -armv8_switch_to_el1 (); +armv8_switch_to_el1 (0 ,0 ,0 ,ES_TO_AARCH64 ); #endif }#endif
arch/arm/lib/bootm.c static void boot_jump_linux(bootm_headers_t *images, int flag) · line 292
Quoted 9 lines
arch/arm/lib/bootm.c +4
-2@@ -286,8 +286,26 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)announce_and_cleanup (fake);if (!fake) { -do_nonsec_virt_switch (); -kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); +if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && + (images->os.arch ==IH_ARCH_ARM )) { +smp_kick_all_cpus (); +dcache_disable ();
This open codes part of do_nonsec_virt_switch().
Could we just clean up all of that mess a bit more maybe? How about you call
do_nonsec_virt_switch(ES_EL2 | ES_AARCH32, entry, images->ft_addr) or do_nonsec_virt_switch(ES_EL1 | ES_AARCH64, entry, images->ft_addr)
Then the if() would only need to set ES_AARCH32/64 in a variable and everything else goes along the same code.
Quoted 24 lines
arch/arm/lib/bootm.c +16
-0+#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 ); +armv8_switch_to_el1 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#else +armv8_switch_to_el2 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#endif + }else { +do_nonsec_virt_switch (); +kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); + } }#else unsigned long machid = gd->bd->bi_arch_number;common/image-fit.c +0
-0
common/image-fit.c int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) · line 1167
Quoted 6 lines
common/image-fit.c +2
-1@@ -1163,7 +1163,8 @@ int fit_image_check_arch(const void *fit, int noffset, uint8_t arch)if (fit_image_get_arch (fit, noffset, &image_arch))return 0 ;return (arch == image_arch) || - (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ); + (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ) || + (arch ==IH_ARCH_ARM64 && image_arch ==IH_ARCH_ARM );
This should be a Kconfig option. ThunderX doesn't support AArch32 execution.
Quoted 26 lines
common/image-fit.c +9
-0}/** @@ -1586,6 +1587,9 @@ int fit_image_load(bootm_headers_t *images, ulong addr,int type_ok, os_ok;ulong load, data, len;uint8_t os; +#ifndef USE_HOSTCC +uint8_t os_arch; +#endif const char *prop_name;int ret;@@ -1669,6 +1673,12 @@ int fit_image_load(bootm_headers_t *images, ulong addr, return -ENOEXEC; }#endif + +#ifndef USE_HOSTCC +fit_image_get_arch (fit, noffset, &os_arch); + images->os.arch = os_arch; +#endif +if (image_type ==IH_TYPE_FLATDT && !fit_image_check_comp (fit, noffset,IH_COMP_NONE )) {puts ("FDT image is compressed" );
PATCH v2 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
Quoted 70 lines · Alison Wang
Quoted 6 lines
To support loading a 32-bit OS, the execution state will change from AArch64 to AArch32 when jumping to kernel.
The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
Quoted 6 lines
Signed-off-by Ebony Zhu <[email protected]>Signed-off-by Alison Wang <[email protected]>Signed-off-by Chenhui Zhao <[email protected]>---
Changes in v2:
-armv8_switch_to_el2_aarch32()is removed.armv8_switch_to_el2_misused
Quoted 2 lines
to switch to AArch64 EL2 or AArch32 Hyp.
-armv8_switch_to_el1_aarch32()is removed.armv8_switch_to_el1_misused
Quoted 4 lines
to switch to AArch64 EL1 or AArch32 SVC.
arch/arm/cpu/armv8/transition.S | 8 ++--- arch/arm/include/asm/macro.h | 80+++++++++++++++++++++++++++++++++++++----
Quoted 42 lines
arch/arm/include/asm/system.h | 25 +++++++++++-- arch/arm/lib/bootm.c | 26 +++++++++++--- common/image-fit.c | 12 ++++++- 5 files changed, 133 insertions(+), 18 deletions(-)(quoted diff) +0
-0
b/arch/arm/cpu/armv8/transition.Sindex 253a39b..9fa3b59 100644arch/arm/cpu/armv8/transition.S +4
-4@@ -11,13 +11,13 @@ #include <asm/macro.h> ENTRY(armv8_switch_to_el2) - switch_el x0, 1f, 0f, 0f + switch_el x4, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el2) ENTRY(armv8_switch_to_el1) - switch_el x0, 0f, 1f, 0f + switch_el x4, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el1)(quoted diff) +0
-0
b/arch/arm/include/asm/macro.hindex 9bb0efa..56d77f6 100644arch/arm/include/asm/macro.h +3
-0@@ -8,6 +8,9 @@#ifndef __ASM_ARM_MACRO_H__#define __ASM_ARM_MACRO_H__ + +#include <asm/system.h> +#ifdef __ASSEMBLY__/* arch/arm/include/asm/macro.h lr .req x30 · line 139
Quoted 5 lines
arch/arm/include/asm/macro.h +0
-2@@ -135,9 +138,20 @@ lr .req x30#endif .endm -.macro armv8_switch_to_el2_m, xreg1 -/* 64bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | Non-secure EL0/EL1 */
Quoted 7 lines
arch/arm/include/asm/macro.h lr .req x30 · line 142
Quoted 3 lines
arch/arm/include/asm/macro.h +2
-1- mov \xreg1, #0x5b1 +.macro armv8_switch_to_el2_m, xreg1, xreg2, xreg3, xreg4, xreg5, +xreg6, xreg7These arguments should probably get documented :). Also xreg4 doesn't seem to actually be a scratch register, but a real parameter. So please name it accordingly.
[Alison Wang] Ok, I will add the descriptions for these arguments. Not only xreg4, xreg1, xreg2 and xreg3 are real parameters too. I will rename them in the next version.
Quoted 20 lines
arch/arm/include/asm/macro.h lr .req x30
Quoted 7 lines
arch/arm/include/asm/macro.h +6
-0+ mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + +/* +* If the next lower exception level is AArch64, 64bit EL2 | HCE | SMD |
arch/arm/include/asm/macro.h lr .req x30 · line 149
Quoted 1 line
arch/arm/include/asm/macro.h +1
-0+* RES1 (Bits[5:4]) | Non-secure EL0/EL1. If the next lower exception
arch/arm/include/asm/macro.h lr .req x30 · line 154
Quoted 6 lines
arch/arm/include/asm/macro.h +6
-0+* level is AArch32, 32bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | +* Non-secure EL0/EL1. +*/ + mov \xreg1, #0x1b1 + lsl \xreg2, \xreg4, #10 + orr \xreg1, \xreg1, \xreg2Is there any way you can make this obvious from the code? Basically we would want something like
Quoted 4 lines
mov \xreg1, #(SCR_EL3_EL2_AA64 |
SCR_EL3_HCE|SCR_EL3_SMD...)I'm sure there are creative ways to achieve this even with the high bits set. Maybe ldr = works?
[Alison Wang] Yes, I will change them and make them obvious.
Quoted 9 lines
arch/arm/include/asm/macro.h lr .req x30 · line 157
Quoted 3 lines
arch/arm/include/asm/macro.h +0
-0msr scr_el3, \xreg1 msr cptr_el3, xzr /* Disable coprocessor traps to EL3*/
Quoted 5 lines
arch/arm/include/asm/macro.h +0
-0mov \xreg1, #0x33ff@@ -156,18 +170,46 @@ lr .req x30 movk \xreg1, #0x30C5, lsl #16 msr sctlr_el2, \xreg1
Quoted 13 lines
arch/arm/include/asm/macro.h lr .req x30 · line 182
Quoted 11 lines
arch/arm/include/asm/macro.h +6
-1-/* Return to the EL2_SP2 mode from EL3 */ mov \xreg1, sp msr sp_el2, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el3 msr vbar_el2, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL2 or AArch32 Hypervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2fJust b.ne should be enough, no?
[Alison Wang] Yes, you are right.
Quoted 7 lines
arch/arm/include/asm/macro.h lr .req x30 · line 186
Quoted 5 lines
arch/arm/include/asm/macro.h +3
-0+ +1: +/* Return to the EL2_SP2 mode from EL3 */ mov \xreg1, #0x3c9Magic values again :). Please convert them to constants getting ORed.
[Alison Wang] Ok, I will change the original magic values too.
Quoted 35 lines
Quoted 14 lines
arch/arm/include/asm/macro.h +11
-0msr spsr_el3, \xreg1 /* EL2_SP2 | D | A | I | F */ msr elr_el3, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to AArch32 Hypervisor mode */ + mov \xreg1, #0x1da + msr spsr_el3, \xreg1 /* Hyp | D | A | I | F */ + msr elr_el3, \xreg5arch/arm/include/asm/macro.h lr .req x30
Quoted 10 lines
arch/arm/include/asm/macro.h +6
-1+ + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endm -.macro armv8_switch_to_el1_m, xreg1, xreg2 +.macro armv8_switch_to_el1_m, xreg1, xreg2, xreg3, xreg4, xreg5,xreg6, xreg7
Quoted 10 lines
arch/arm/include/asm/macro.h +4
-0+ mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + /* Initialize Generic Timers */ mrs \xreg1, cnthctl_el2 orr \xreg1, \xreg1, #0x3 /* Enable EL1 access to timers */@@ -188,7 +230,7 @@ lr .req x30 msr cpacr_el1, \xreg1 /* Enable FP/SIMD at EL1 */
Quoted 6 lines
arch/arm/include/asm/macro.h lr .req x30 · line 233
Quoted 3 lines
arch/arm/include/asm/macro.h +1
-1/* Initialize HCR_EL2 */ - mov \xreg1, #(1 << 31) /* 64bit EL1 */ + lsl \xreg1, \xreg4, #31This deserves a comment. Imagine you read this code again in 5 years. Would you still understand what's going on?
[Alison Wang] Ok, I will add a comment.
Quoted 94 lines
Quoted 94 lines
arch/arm/include/asm/macro.h +25
-1orr \xreg1, \xreg1, #(1 << 29) /* Disable HVC */ msr hcr_el2, \xreg1@@ -203,15 +245,39 @@ lr .req x30 movk \xreg1, #0x30d0, lsl #16 msr sctlr_el1, \xreg1 - /* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, sp msr sp_el1, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el2 msr vbar_el1, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL1 or AArch32 Supervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2f + +1: +/* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, #0x3c5 msr spsr_el2, \xreg1 /* EL1_SP1 | D | A | I | F */ msr elr_el2, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to the Supervisor mode from EL2 */ + mov \xreg1, #0x1d3 + msr spsr_el2, \xreg1 /* Supervisor | D | A | I | F */ + msr elr_el2, \xreg5 + + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endm #if defined(CONFIG_GICV3)(quoted diff) +0
-0
b/arch/arm/include/asm/system.hindex 9ae890a..fcfe3ae 100644arch/arm/include/asm/system.h +23
-2@@ -17,6 +17,9 @@#define CR_WXN (1 << 19)/* Write Permision Imply XN */ #define CR_EE (1 << 25)/* Exception (Big) Endian */ +#define ES_TO_AARCH64 1 +#define ES_TO_AARCH32 0 +#ifndef __ASSEMBLY__u64 get_page_table_size (void );@@ -100,8 +103,26 @@ void __asm_invalidate_icache_all(void);int __asm_flush_l3_cache (void );void __asm_switch_ttbr (u64 new_ttbr); -void armv8_switch_to_el2 (void ); -void armv8_switch_to_el1 (void ); +/* +* Switch from EL3 to EL2 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el2 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag); +/* +* Switch from EL2 to EL1 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el1 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag);void gic_init (void );void gic_send_sgi (unsigned long sgino);void wait_for_wakeup (void );arch/arm/lib/bootm.c index renamed from arch/arm/lib/bootm.c +0
-00838d89..f6f685a 100644
arch/arm/lib/bootm.c +0
-0@@ -193,9 +193,9 @@ static void do_nonsec_virt_switch(void) {
Quoted 8 lines
arch/arm/lib/bootm.c static void do_nonsec_virt_switch(void) · line 196
Quoted 4 lines
arch/arm/lib/bootm.c +1
-1smp_kick_all_cpus ();dcache_disable ();/* flush cache before swtiching to EL2 */ -armv8_switch_to_el2 (); +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 );Just rename the existing function to
armv8_switch_to_el2_adv()or so and providearmv8_switch_to_el2()as static inline function that simply invokesarmv8_switch_to_el2_adv(0, 0, 0, ES_TO_AARCH64);
[Alison Wang] I didn't know why you suggest to do so. Please explain it. Thanks.
Quoted 21 lines
arch/arm/lib/bootm.c static void boot_jump_linux(bootm_headers_t
Quoted 8 lines
arch/arm/lib/bootm.c +1
-1#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 -armv8_switch_to_el1 (); +armv8_switch_to_el1 (0 ,0 ,0 ,ES_TO_AARCH64 ); #endif }#endif @@ -286,8 +286,26 @@ static void boot_jump_linux(bootm_headers_t*images, int flag)
arch/arm/lib/bootm.c static void boot_jump_linux(bootm_headers_t *images, int flag) · line 292
Quoted 9 lines
arch/arm/lib/bootm.c +4
-2announce_and_cleanup (fake);if (!fake) { -do_nonsec_virt_switch (); -kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); +if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && + (images->os.arch ==IH_ARCH_ARM )) { +smp_kick_all_cpus (); +dcache_disable ();This open codes part of
do_nonsec_virt_switch().
Quoted 8 lines
Could we just clean up all of that mess a bit more maybe? How about you call
do_nonsec_virt_switch(ES_EL2 | ES_AARCH32, entry, images->ft_addr)ordo_nonsec_virt_switch(ES_EL1 | ES_AARCH64, entry, images->ft_addr)Then the
if()would only need to set ES_AARCH32/64 in a variable and everything else goes along the same code.
[Alison Wang] It sounds fine. I will try to do it in the next version.
Quoted 26 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int
Quoted 25 lines
arch/arm/lib/bootm.c +16
-0+#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 ); +armv8_switch_to_el1 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#else +armv8_switch_to_el2 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#endif + }else { +do_nonsec_virt_switch (); +kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); + } }#else unsigned long machid = gd->bd->bi_arch_number; diff --git
a/common/image-fit.cb/common/image-fit.cindex 25f8a11..2986469 100644common/image-fit.c +0
-0@@ -1163,7 +1163,8 @@ int fit_image_check_arch(const void *fit, intnoffset,
uint8_tarch)
Quoted 9 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) · line 1167
Quoted 6 lines
common/image-fit.c +2
-1if (fit_image_get_arch (fit, noffset, &image_arch))return 0 ;return (arch == image_arch) || - (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ); + (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ) || + (arch ==IH_ARCH_ARM64 && image_arch ==IH_ARCH_ARM );This should be a
Kconfigoption. ThunderX doesn't support AArch32 execution.
[Alison Wang] I can't understand your meaning. Can you clarify it?
Quoted 17 lines
common/image-fit.c int fit_image_load(bootm_headers_t *images,
Quoted 5 lines
common/image-fit.c +0
-0}/** @@ -1586,6 +1587,9 @@ int fit_image_load(bootm_headers_t *images,ulong addr,
common/image-fit.c int fit_image_load(bootm_headers_t *images,
Quoted 10 lines
common/image-fit.c +3
-0int type_ok, os_ok;ulong load, data, len;uint8_t os; +#ifndef USE_HOSTCC +uint8_t os_arch; +#endif const char *prop_name;int ret;@@ -1669,6 +1673,12 @@ int fit_image_load(bootm_headers_t *images,ulong addr,
Quoted 12 lines
common/image-fit.c int fit_image_load(bootm_headers_t *images, ulong addr, · line 1684
Quoted 12 lines
common/image-fit.c +6
-0return -ENOEXEC; }#endif + +#ifndef USE_HOSTCC +fit_image_get_arch (fit, noffset, &os_arch); + images->os.arch = os_arch; +#endif +if (image_type ==IH_TYPE_FLATDT && !fit_image_check_comp (fit, noffset,IH_COMP_NONE )) {puts ("FDT image is compressed" );
Thanks a lot for your review.
Best Regards,
Alison Wang
PATCH v2 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
Quoted 280 lines · Huan Wang
Quoted 70 lines · Alison Wang
Quoted 6 lines
To support loading a 32-bit OS, the execution state will change from AArch64 to AArch32 when jumping to kernel.
The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
Quoted 6 lines
Signed-off-by Ebony Zhu <[email protected]>Signed-off-by Alison Wang <[email protected]>Signed-off-by Chenhui Zhao <[email protected]>---
Changes in v2:
-armv8_switch_to_el2_aarch32()is removed.armv8_switch_to_el2_misused
Quoted 2 lines
to switch to AArch64 EL2 or AArch32 Hyp.
-armv8_switch_to_el1_aarch32()is removed.armv8_switch_to_el1_misused
Quoted 4 lines
to switch to AArch64 EL1 or AArch32 SVC.
arch/arm/cpu/armv8/transition.S | 8 ++--- arch/arm/include/asm/macro.h | 80+++++++++++++++++++++++++++++++++++++----
Quoted 42 lines
arch/arm/include/asm/system.h | 25 +++++++++++-- arch/arm/lib/bootm.c | 26 +++++++++++--- common/image-fit.c | 12 ++++++- 5 files changed, 133 insertions(+), 18 deletions(-)(quoted diff) +0
-0
b/arch/arm/cpu/armv8/transition.Sindex 253a39b..9fa3b59 100644arch/arm/cpu/armv8/transition.S +4
-4@@ -11,13 +11,13 @@ #include <asm/macro.h> ENTRY(armv8_switch_to_el2) - switch_el x0, 1f, 0f, 0f + switch_el x4, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el2) ENTRY(armv8_switch_to_el1) - switch_el x0, 0f, 1f, 0f + switch_el x4, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el1)(quoted diff) +0
-0
b/arch/arm/include/asm/macro.hindex 9bb0efa..56d77f6 100644arch/arm/include/asm/macro.h +3
-0@@ -8,6 +8,9 @@#ifndef __ASM_ARM_MACRO_H__#define __ASM_ARM_MACRO_H__ + +#include <asm/system.h> +#ifdef __ASSEMBLY__/* arch/arm/include/asm/macro.h lr .req x30 · line 139
Quoted 5 lines
arch/arm/include/asm/macro.h +0
-2@@ -135,9 +138,20 @@ lr .req x30#endif .endm -.macro armv8_switch_to_el2_m, xreg1 -/* 64bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | Non-secure EL0/EL1 */
Quoted 7 lines
arch/arm/include/asm/macro.h lr .req x30 · line 142
Quoted 3 lines
arch/arm/include/asm/macro.h +2
-1- mov \xreg1, #0x5b1 +.macro armv8_switch_to_el2_m, xreg1, xreg2, xreg3, xreg4, xreg5, +xreg6, xreg7These arguments should probably get documented :). Also xreg4 doesn't seem to actually be a scratch register, but a real parameter. So please name it accordingly.
[Alison Wang] Ok, I will add the descriptions for these arguments. Not only xreg4, xreg1, xreg2 and xreg3 are real parameters too. I will rename them in the next version.
Quoted 20 lines
arch/arm/include/asm/macro.h lr .req x30
Quoted 7 lines
arch/arm/include/asm/macro.h +6
-0+ mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + +/* +* If the next lower exception level is AArch64, 64bit EL2 | HCE | SMD |
arch/arm/include/asm/macro.h lr .req x30 · line 149
Quoted 1 line
arch/arm/include/asm/macro.h +1
-0+* RES1 (Bits[5:4]) | Non-secure EL0/EL1. If the next lower exception
arch/arm/include/asm/macro.h lr .req x30 · line 154
Quoted 6 lines
arch/arm/include/asm/macro.h +6
-0+* level is AArch32, 32bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | +* Non-secure EL0/EL1. +*/ + mov \xreg1, #0x1b1 + lsl \xreg2, \xreg4, #10 + orr \xreg1, \xreg1, \xreg2Is there any way you can make this obvious from the code? Basically we would want something like
Quoted 4 lines
mov \xreg1, #(SCR_EL3_EL2_AA64 |
SCR_EL3_HCE|SCR_EL3_SMD...)I'm sure there are creative ways to achieve this even with the high bits set. Maybe ldr = works?
[Alison Wang] Yes, I will change them and make them obvious.
Quoted 9 lines
arch/arm/include/asm/macro.h lr .req x30 · line 157
Quoted 3 lines
arch/arm/include/asm/macro.h +0
-0msr scr_el3, \xreg1 msr cptr_el3, xzr /* Disable coprocessor traps to EL3*/
Quoted 5 lines
arch/arm/include/asm/macro.h +0
-0mov \xreg1, #0x33ff@@ -156,18 +170,46 @@ lr .req x30 movk \xreg1, #0x30C5, lsl #16 msr sctlr_el2, \xreg1Quoted 13 lines
arch/arm/include/asm/macro.h lr .req x30 · line 182
Quoted 11 lines
arch/arm/include/asm/macro.h +6
-1-/* Return to the EL2_SP2 mode from EL3 */ mov \xreg1, sp msr sp_el2, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el3 msr vbar_el2, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL2 or AArch32 Hypervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2fJust b.ne should be enough, no?
[Alison Wang] Yes, you are right.
Quoted 7 lines
arch/arm/include/asm/macro.h lr .req x30 · line 186
Quoted 5 lines
arch/arm/include/asm/macro.h +3
-0+ +1: +/* Return to the EL2_SP2 mode from EL3 */ mov \xreg1, #0x3c9Magic values again :). Please convert them to constants getting ORed.
[Alison Wang] Ok, I will change the original magic values too.
Quoted 35 lines
Quoted 14 lines
arch/arm/include/asm/macro.h +11
-0msr spsr_el3, \xreg1 /* EL2_SP2 | D | A | I | F */ msr elr_el3, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to AArch32 Hypervisor mode */ + mov \xreg1, #0x1da + msr spsr_el3, \xreg1 /* Hyp | D | A | I | F */ + msr elr_el3, \xreg5arch/arm/include/asm/macro.h lr .req x30
Quoted 10 lines
arch/arm/include/asm/macro.h +6
-1+ + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endm -.macro armv8_switch_to_el1_m, xreg1, xreg2 +.macro armv8_switch_to_el1_m, xreg1, xreg2, xreg3, xreg4, xreg5,xreg6, xreg7
Quoted 10 lines
arch/arm/include/asm/macro.h +4
-0+ mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + /* Initialize Generic Timers */ mrs \xreg1, cnthctl_el2 orr \xreg1, \xreg1, #0x3 /* Enable EL1 access to timers */@@ -188,7 +230,7 @@ lr .req x30 msr cpacr_el1, \xreg1 /* Enable FP/SIMD at EL1 */Quoted 6 lines
arch/arm/include/asm/macro.h lr .req x30 · line 233
Quoted 3 lines
arch/arm/include/asm/macro.h +1
-1/* Initialize HCR_EL2 */ - mov \xreg1, #(1 << 31) /* 64bit EL1 */ + lsl \xreg1, \xreg4, #31This deserves a comment. Imagine you read this code again in 5 years. Would you still understand what's going on?
[Alison Wang] Ok, I will add a comment.
Quoted 94 lines
Quoted 94 lines
arch/arm/include/asm/macro.h +25
-1orr \xreg1, \xreg1, #(1 << 29) /* Disable HVC */ msr hcr_el2, \xreg1@@ -203,15 +245,39 @@ lr .req x30 movk \xreg1, #0x30d0, lsl #16 msr sctlr_el1, \xreg1 - /* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, sp msr sp_el1, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el2 msr vbar_el1, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL1 or AArch32 Supervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2f + +1: +/* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, #0x3c5 msr spsr_el2, \xreg1 /* EL1_SP1 | D | A | I | F */ msr elr_el2, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to the Supervisor mode from EL2 */ + mov \xreg1, #0x1d3 + msr spsr_el2, \xreg1 /* Supervisor | D | A | I | F */ + msr elr_el2, \xreg5 + + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endm #if defined(CONFIG_GICV3)(quoted diff) +0
-0
b/arch/arm/include/asm/system.hindex 9ae890a..fcfe3ae 100644arch/arm/include/asm/system.h +23
-2@@ -17,6 +17,9 @@#define CR_WXN (1 << 19)/* Write Permision Imply XN */ #define CR_EE (1 << 25)/* Exception (Big) Endian */ +#define ES_TO_AARCH64 1 +#define ES_TO_AARCH32 0 +#ifndef __ASSEMBLY__u64 get_page_table_size (void );@@ -100,8 +103,26 @@ void __asm_invalidate_icache_all(void);int __asm_flush_l3_cache (void );void __asm_switch_ttbr (u64 new_ttbr); -void armv8_switch_to_el2 (void ); -void armv8_switch_to_el1 (void ); +/* +* Switch from EL3 to EL2 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el2 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag); +/* +* Switch from EL2 to EL1 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32 +*/ +void armv8_switch_to_el1 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag);void gic_init (void );void gic_send_sgi (unsigned long sgino);void wait_for_wakeup (void );arch/arm/lib/bootm.c index renamed from arch/arm/lib/bootm.c +0
-00838d89..f6f685a 100644
arch/arm/lib/bootm.c +0
-0@@ -193,9 +193,9 @@ static void do_nonsec_virt_switch(void) {Quoted 8 lines
arch/arm/lib/bootm.c static void do_nonsec_virt_switch(void) · line 196
Quoted 4 lines
arch/arm/lib/bootm.c +1
-1smp_kick_all_cpus ();dcache_disable ();/* flush cache before swtiching to EL2 */ -armv8_switch_to_el2 (); +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 );Just rename the existing function to
armv8_switch_to_el2_adv()or so and providearmv8_switch_to_el2()as static inline function that simply invokesarmv8_switch_to_el2_adv(0, 0, 0, ES_TO_AARCH64);
Quoted 2 lines
[Alison Wang] I didn't know why you suggest to do so. Please explain it. Thanks.
I guess with my suggestion below this wouldn't make much sense anymore, so it's fine the way it is.
Quoted 65 lines
Quoted 21 lines
arch/arm/lib/bootm.c static void boot_jump_linux(bootm_headers_t
Quoted 8 lines
arch/arm/lib/bootm.c +1
-1#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 -armv8_switch_to_el1 (); +armv8_switch_to_el1 (0 ,0 ,0 ,ES_TO_AARCH64 ); #endif }#endif @@ -286,8 +286,26 @@ static void boot_jump_linux(bootm_headers_t*images, int flag)
arch/arm/lib/bootm.c static void boot_jump_linux(bootm_headers_t *images, int flag) · line 292
Quoted 9 lines
arch/arm/lib/bootm.c +4
-2announce_and_cleanup (fake);if (!fake) { -do_nonsec_virt_switch (); -kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); +if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && + (images->os.arch ==IH_ARCH_ARM )) { +smp_kick_all_cpus (); +dcache_disable ();This open codes part of
do_nonsec_virt_switch().Quoted 8 lines
Could we just clean up all of that mess a bit more maybe? How about you call
do_nonsec_virt_switch(ES_EL2 | ES_AARCH32, entry, images->ft_addr)ordo_nonsec_virt_switch(ES_EL1 | ES_AARCH64, entry, images->ft_addr)Then the
if()would only need to set ES_AARCH32/64 in a variable and everything else goes along the same code.[Alison Wang] It sounds fine. I will try to do it in the next version.
Quoted 26 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int
Quoted 25 lines
arch/arm/lib/bootm.c +16
-0+#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 ); +armv8_switch_to_el1 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#else +armv8_switch_to_el2 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#endif + }else { +do_nonsec_virt_switch (); +kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); + } }#else unsigned long machid = gd->bd->bi_arch_number; diff --git
a/common/image-fit.cb/common/image-fit.cindex 25f8a11..2986469 100644common/image-fit.c +0
-0@@ -1163,7 +1163,8 @@ int fit_image_check_arch(const void *fit, intnoffset,
uint8_tarch)Quoted 9 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) · line 1167
Quoted 6 lines
common/image-fit.c +2
-1if (fit_image_get_arch (fit, noffset, &image_arch))return 0 ;return (arch == image_arch) || - (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ); + (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ) || + (arch ==IH_ARCH_ARM64 && image_arch ==IH_ARCH_ARM );This should be a
Kconfigoption. ThunderX doesn't support AArch32 execution.
Quoted 1 line
[Alison Wang] I can't understand your meaning. Can you clarify it?
U-Boot supports the ThunderX SoC which uses Cavium's own ARMv8 core implementation. That core does not support running AArch32 code.
Alex
PATCH v2 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
Quoted 287 lines · Huan Wang
Quoted 100 lines
Quoted 70 lines · Alison Wang
Quoted 6 lines
To support loading a 32-bit OS, the execution state will change from AArch64 to AArch32 when jumping to kernel.
The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
Quoted 6 lines
Signed-off-by Ebony Zhu <[email protected]>Signed-off-by Alison Wang <[email protected]>Signed-off-by Chenhui Zhao <[email protected]>---
Changes in v2:
-armv8_switch_to_el2_aarch32()is removed.armv8_switch_to_el2_misused
Quoted 2 lines
to switch to AArch64 EL2 or AArch32 Hyp.
-armv8_switch_to_el1_aarch32()is removed.armv8_switch_to_el1_misused
Quoted 4 lines
to switch to AArch64 EL1 or AArch32 SVC.
arch/arm/cpu/armv8/transition.S | 8 ++--- arch/arm/include/asm/macro.h | 80+++++++++++++++++++++++++++++++++++++----
Quoted 42 lines
arch/arm/include/asm/system.h | 25 +++++++++++-- arch/arm/lib/bootm.c | 26 +++++++++++--- common/image-fit.c | 12 ++++++- 5 files changed, 133 insertions(+), 18 deletions(-)(quoted diff) +0
-0
b/arch/arm/cpu/armv8/transition.Sindex 253a39b..9fa3b59 100644arch/arm/cpu/armv8/transition.S +4
-4@@ -11,13 +11,13 @@ #include <asm/macro.h> ENTRY(armv8_switch_to_el2) - switch_el x0, 1f, 0f, 0f + switch_el x4, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el2) ENTRY(armv8_switch_to_el1) - switch_el x0, 0f, 1f, 0f + switch_el x4, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(armv8_switch_to_el1)(quoted diff) +0
-0
b/arch/arm/include/asm/macro.hindex 9bb0efa..56d77f6 100644arch/arm/include/asm/macro.h +3
-0@@ -8,6 +8,9 @@#ifndef __ASM_ARM_MACRO_H__#define __ASM_ARM_MACRO_H__ + +#include <asm/system.h> +#ifdef __ASSEMBLY__/* arch/arm/include/asm/macro.h lr .req x30 · line 139
Quoted 5 lines
arch/arm/include/asm/macro.h +0
-2@@ -135,9 +138,20 @@ lr .req x30#endif .endm -.macro armv8_switch_to_el2_m, xreg1 -/* 64bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | Non-secure EL0/EL1 */
Quoted 7 lines
arch/arm/include/asm/macro.h lr .req x30 · line 142
Quoted 3 lines
arch/arm/include/asm/macro.h +2
-1- mov \xreg1, #0x5b1 +.macro armv8_switch_to_el2_m, xreg1, xreg2, xreg3, xreg4, xreg5, +xreg6, xreg7These arguments should probably get documented :). Also xreg4 doesn't seem to actually be a scratch register, but a real parameter. So please name it accordingly.
[Alison Wang] Ok, I will add the descriptions for these arguments. Not only xreg4, xreg1, xreg2 and xreg3 are real parameters too. I will rename them in the next version.
Quoted 20 lines
arch/arm/include/asm/macro.h lr .req x30
Quoted 7 lines
arch/arm/include/asm/macro.h +6
-0+ mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + +/* +* If the next lower exception level is AArch64, 64bit EL2 | HCE | SMD |
arch/arm/include/asm/macro.h lr .req x30 · line 149
Quoted 1 line
arch/arm/include/asm/macro.h +1
-0+* RES1 (Bits[5:4]) | Non-secure EL0/EL1. If the next lower exception
arch/arm/include/asm/macro.h lr .req x30 · line 154
Quoted 6 lines
arch/arm/include/asm/macro.h +6
-0+* level is AArch32, 32bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | +* Non-secure EL0/EL1. +*/ + mov \xreg1, #0x1b1 + lsl \xreg2, \xreg4, #10 + orr \xreg1, \xreg1, \xreg2Is there any way you can make this obvious from the code? Basically we would want something like
Quoted 8 lines
Quoted 4 lines
mov \xreg1, #(SCR_EL3_EL2_AA64 |
SCR_EL3_HCE|SCR_EL3_SMD...)I'm sure there are creative ways to achieve this even with the high bits set. Maybe ldr = works?
[Alison Wang] Yes, I will change them and make them obvious.
Quoted 3 lines
Quoted 3 lines
arch/arm/include/asm/macro.h +0
-0msr scr_el3, \xreg1 msr cptr_el3, xzr /* Disable coprocessor trapsto EL3
Quoted 53 lines
Quoted 6 lines
*/
Quoted 5 lines
arch/arm/include/asm/macro.h +0
-0mov \xreg1, #0x33ff@@ -156,18 +170,46 @@ lr .req x30 movk \xreg1, #0x30C5, lsl #16 msr sctlr_el2, \xreg1Quoted 13 lines
arch/arm/include/asm/macro.h lr .req x30 · line 182
Quoted 11 lines
arch/arm/include/asm/macro.h +6
-1-/* Return to the EL2_SP2 mode from EL3 */ mov \xreg1, sp msr sp_el2, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el3 msr vbar_el2, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL2 or AArch32 Hypervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2fJust b.ne should be enough, no?
[Alison Wang] Yes, you are right.
Quoted 7 lines
arch/arm/include/asm/macro.h lr .req x30 · line 186
Quoted 5 lines
arch/arm/include/asm/macro.h +3
-0+ +1: +/* Return to the EL2_SP2 mode from EL3 */ mov \xreg1, #0x3c9Magic values again :). Please convert them to constants getting ORed.
[Alison Wang] Ok, I will change the original magic values too.
Quoted 25 lines
Quoted 14 lines
arch/arm/include/asm/macro.h +11
-0msr spsr_el3, \xreg1 /* EL2_SP2 | D | A | I | F */ msr elr_el3, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to AArch32 Hypervisor mode */ + mov \xreg1, #0x1da + msr spsr_el3, \xreg1 /* Hyp | D | A | I | F */ + msr elr_el3, \xreg5arch/arm/include/asm/macro.h lr .req x30
Quoted 10 lines
arch/arm/include/asm/macro.h +6
-1+ + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endm -.macro armv8_switch_to_el1_m, xreg1, xreg2 +.macro armv8_switch_to_el1_m, xreg1, xreg2, xreg3, xreg4, xreg5,xreg6, xreg7
Quoted 7 lines
Quoted 7 lines
arch/arm/include/asm/macro.h lr .req x30
Quoted 7 lines
arch/arm/include/asm/macro.h +4
-0+ mov \xreg5, \xreg1 + mov \xreg6, \xreg2 + mov \xreg7, \xreg3 + /* Initialize Generic Timers */ mrs \xreg1, cnthctl_el2 orr \xreg1, \xreg1, #0x3 /* Enable EL1 access totimers */
Quoted 54 lines
Quoted 9 lines
arch/arm/include/asm/macro.h lr .req x30 · line 233
Quoted 6 lines
arch/arm/include/asm/macro.h +1
-1@@ -188,7 +230,7 @@ lr .req x30 msr cpacr_el1, \xreg1 /* Enable FP/SIMD at EL1 */ /* Initialize HCR_EL2 */ - mov \xreg1, #(1 << 31) /* 64bit EL1 */ + lsl \xreg1, \xreg4, #31This deserves a comment. Imagine you read this code again in 5 years. Would you still understand what's going on?
[Alison Wang] Ok, I will add a comment.
Quoted 44 lines
Quoted 44 lines
arch/arm/include/asm/macro.h +25
-1orr \xreg1, \xreg1, #(1 << 29) /* Disable HVC */ msr hcr_el2, \xreg1@@ -203,15 +245,39 @@ lr .req x30 movk \xreg1, #0x30d0, lsl #16 msr sctlr_el1, \xreg1 - /* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, sp msr sp_el1, \xreg1 /* Migrate SP */ mrs \xreg1, vbar_el2 msr vbar_el1, \xreg1 /* Migrate VBAR */ + + /* Check switch to AArch64 EL1 or AArch32 Supervisor mode */ + ldr \xreg1, =ES_TO_AARCH64 + cmp \xreg4, \xreg1 + b.eq 1f + b.ne 2f + +1: +/* Return to the EL1_SP1 mode from EL2 */ mov \xreg1, #0x3c5 msr spsr_el2, \xreg1 /* EL1_SP1 | D | A | I | F */ msr elr_el2, lr + + mov \xreg1, \xreg5 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 + eret + +2: +/* Return to the Supervisor mode from EL2 */ + mov \xreg1, #0x1d3 + msr spsr_el2, \xreg1 /* Supervisor | D | A | I | F */ + msr elr_el2, \xreg5 + + mov \xreg1, #0 + mov \xreg2, \xreg6 + mov \xreg3, \xreg7 eret + .endmQuoted 7 lines
Quoted 7 lines
arch/arm/include/asm/system.h line 17
Quoted 7 lines
arch/arm/include/asm/macro.h +0
-0#if defined(CONFIG_GICV3 )(quoted diff) +0
-0
b/arch/arm/include/asm/system.hindex 9ae890a..fcfe3ae 100644arch/arm/include/asm/system.h +0
-0@@ -17,6 +17,9 @@#define CR_WXN (1 << 19)/* Write Permision Imply XN */Quoted 1 line
Quoted 1 line
arch/arm/include/asm/system.h line 18
Quoted 1 line
arch/arm/include/asm/system.h +0
-0#define CR_EE (1 << 25)/* Exception (Big) Endian */Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
arch/arm/include/asm/system.h +3
-0+#define ES_TO_AARCH64 1 +#define ES_TO_AARCH32 0 +#ifndef __ASSEMBLY__u64 get_page_table_size (void );@@ -100,8 +103,26 @@ void __asm_invalidate_icache_all(void);int __asm_flush_l3_cache (void );void __asm_switch_ttbr (u64 new_ttbr);Quoted 9 lines
Quoted 9 lines
arch/arm/include/asm/system.h void __asm_invalidate_icache_all(void);
Quoted 9 lines
arch/arm/include/asm/system.h +7
-2-void armv8_switch_to_el2 (void ); -void armv8_switch_to_el1 (void ); +/* +* Switch from EL3 to EL2 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or
ES_TO_AARCH32Quoted 10 lines
Quoted 10 lines
arch/arm/include/asm/system.h void __asm_invalidate_icache_all(void);
Quoted 10 lines
arch/arm/include/asm/system.h +10
-0+*/ +void armv8_switch_to_el2 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag); +/* +* Switch from EL2 to EL1 for ARMv8 +* +* @entry_point: kernel entry point +* @mach_nr: machine nr +* @fdt_addr: fdt address +* @es_flag: execution state flag, ES_TO_AARCH64 or
ES_TO_AARCH32Quoted 20 lines
Quoted 20 lines
Quoted 11 lines
arch/arm/include/asm/system.h +3
-0+*/ +void armv8_switch_to_el1 (u64 entry_point,u64 mach_nr,u64 fdt_addr, +u64 es_flag);void gic_init (void );void gic_send_sgi (unsigned long sgino);void wait_for_wakeup (void );arch/arm/lib/bootm.c index renamed from arch/arm/lib/bootm.c +0
-00838d89..f6f685a 100644
arch/arm/lib/bootm.c static void do_nonsec_virt_switch(void) · line 196
Quoted 5 lines
arch/arm/lib/bootm.c +1
-1@@ -193,9 +193,9 @@ static void do_nonsec_virt_switch(void) {smp_kick_all_cpus ();dcache_disable ();/* flush cache before swtiching to EL2 */ -armv8_switch_to_el2 (); +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 );Just rename the existing function to
armv8_switch_to_el2_adv()or so and providearmv8_switch_to_el2()as static inline function that simply invokesarmv8_switch_to_el2_adv(0, 0, 0, ES_TO_AARCH64);
Quoted 6 lines
Quoted 1 line
[Alison Wang] I didn't know why you suggest to do so. Please explain
it.
Quoted 1 line
Thanks.
I guess with my suggestion below this wouldn't make much sense anymore, so it's fine the way it is.
[Alison Wang] ok.
Quoted 66 lines
Quoted 66 lines
Quoted 22 lines
arch/arm/lib/bootm.c static void boot_jump_linux(bootm_headers_t
Quoted 9 lines
arch/arm/lib/bootm.c +1
-1#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 -armv8_switch_to_el1 (); +armv8_switch_to_el1 (0 ,0 ,0 ,ES_TO_AARCH64 ); #endif }#endif @@ -286,8 +286,26 @@ static void boot_jump_linux(bootm_headers_t*images, int flag)
arch/arm/lib/bootm.c static void boot_jump_linux(bootm_headers_t *images, int flag) · line 292
Quoted 9 lines
arch/arm/lib/bootm.c +4
-2announce_and_cleanup (fake);if (!fake) { -do_nonsec_virt_switch (); -kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); +if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && + (images->os.arch ==IH_ARCH_ARM )) { +smp_kick_all_cpus (); +dcache_disable ();This open codes part of
do_nonsec_virt_switch().Quoted 8 lines
Could we just clean up all of that mess a bit more maybe? How about you call
do_nonsec_virt_switch(ES_EL2 | ES_AARCH32, entry, images->ft_addr)ordo_nonsec_virt_switch(ES_EL1 | ES_AARCH64, entry, images->ft_addr)Then the
if()would only need to set ES_AARCH32/64 in a variable and everything else goes along the same code.[Alison Wang] It sounds fine. I will try to do it in the next version.
Quoted 35 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int
Quoted 25 lines
arch/arm/lib/bootm.c +16
-0+#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +armv8_switch_to_el2 (0 ,0 ,0 ,ES_TO_AARCH64 ); +armv8_switch_to_el1 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#else +armv8_switch_to_el2 ((u64 )images->ep, + (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, +ES_TO_AARCH32 ); +#endif + }else { +do_nonsec_virt_switch (); +kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); + } }#else unsigned long machid = gd->bd->bi_arch_number; diff --git
a/common/image-fit.cb/common/image-fit.cindex 25f8a11..2986469 100644common/image-fit.c +0
-0@@ -1163,7 +1163,8 @@ int fit_image_check_arch(const void *fit, intnoffset,
uint8_tarch)common/image-fit.c int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) · line 1167
Quoted 6 lines
common/image-fit.c +2
-1if (fit_image_get_arch (fit, noffset, &image_arch))return 0 ;return (arch == image_arch) || - (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ); + (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ) || + (arch ==IH_ARCH_ARM64 && image_arch ==IH_ARCH_ARM );This should be a
Kconfigoption. ThunderX doesn't support AArch32 execution.
Quoted 5 lines
Quoted 1 line
[Alison Wang] I can't understand your meaning. Can you clarify it?
U-Boot supports the ThunderX SoC which uses Cavium's own ARMv8 core implementation. That core does not support running AArch32 code.
[Alison Wang] Oh, I think your concern is that this function will not detect FIT image is wrong when loading 32-bit kernel on ThunderX, right?
Then what is your suggestion to fix this issue?
Best Regards,
Alison Wang
PATCH v2 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
Quoted 12 lines · Huan Wang
Quoted 12 lines · Huan Wang
Quoted 11 lines
Quoted 11 lines · Alison Wang
Quoted 10 lines
To support loading a 32-bit OS, the execution state will change from AArch64 to AArch32 when jumping to kernel.
The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
Signed-off-by Ebony Zhu <[email protected]>Signed-off-by Alison Wang <[email protected]>Signed-off-by Chenhui Zhao <[email protected]>---
[...]
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 4 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int
Quoted 3 lines
common/image-fit.c +0
-0@@ -1163,7 +1163,8 @@ int fit_image_check_arch(const void *fit, intnoffset,
uint8_tarch)Quoted 9 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) · line 1167
Quoted 6 lines
common/image-fit.c +2
-1if (fit_image_get_arch (fit, noffset, &image_arch))return 0 ;return (arch == image_arch) || - (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ); + (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ) || + (arch ==IH_ARCH_ARM64 && image_arch ==IH_ARCH_ARM );This should be a
Kconfigoption. ThunderX doesn't support AArch32 execution.[Alison Wang] I can't understand your meaning. Can you clarify it?
Quoted 7 lines
Quoted 3 lines
U-Boot supports the ThunderX SoC which uses Cavium's own ARMv8 core implementation. That core does not support running AArch32 code.
[Alison Wang] Oh, I think your concern is that this function will not detect FIT image is wrong when loading 32-bit kernel on ThunderX, right?
Then what is your suggestion to fix this issue?
My suggestion is to introduce a new Kconfig option that says "this arm64 system can execute aarch32 code" which is set as default y. CONFIG_THUNDERX would then set it to n if that's possible - or you'd just set it to n in the thunderx defconfig.
Alex
PATCH v2 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
Quoted 39 lines · Huan Wang
Quoted 13 lines
Quoted 13 lines · Huan Wang
Quoted 12 lines
Quoted 12 lines · Alison Wang
Quoted 11 lines
To support loading a 32-bit OS, the execution state will change from
AArch64 to AArch32 when jumping to kernel.The architecture information will be got through checking FIT image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
Signed-off-by Ebony Zhu <[email protected]>Signed-off-by Alison Wang <[email protected]>Signed-off-by Chenhui Zhao <[email protected]>---
[...]
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
common/image-fit.c +0
-0@@ -1163,7 +1163,8 @@ int fit_image_check_arch(const void *fit,int
noffset,
uint8_tarch)common/image-fit.c
Quoted 5 lines
if (
fit_image_get_arch(fit, noffset, &image_arch))
return 0;
return (arch ==image_arch) ||common/image-fit.c +1
-1- (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 ); + (arch ==IH_ARCH_I386 && image_arch ==IH_ARCH_X86_64 )||
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
common/image-fit.c int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) · line 1167
Quoted 1 line
common/image-fit.c +1
-0+ (arch ==IH_ARCH_ARM64 && image_arch ==IH_ARCH_ARM );This should be a
Kconfigoption. ThunderX doesn't support AArch32 execution.[Alison Wang] I can't understand your meaning. Can you clarify it?
U-Boot supports the ThunderX SoC which uses Cavium's own ARMv8 core implementation. That core does not support running AArch32 code.
[Alison Wang] Oh, I think your concern is that this function will not detect FIT image is wrong when loading 32-bit kernel on ThunderX,
Quoted 8 lines
right?
Quoted 2 lines
Then what is your suggestion to fix this issue?
My suggestion is to introduce a new
Kconfigoption that says "this arm64 system can execute aarch32 code" which is set as default y.CONFIG_THUNDERXwould then set it to n if that's possible - or you'd just set it to n in the thunderx defconfig.
[Alison Wang] Good idea. I will do it in the next version. Thanks.
Best Regards,
Alison Wang
PATCH v2 2/2 armv8: fsl-layerscape: SMP support for loading 32-bit OS
In reply to Alison WangSpin-table method is used for secondary cores to load 32-bit OS. The architecture information will be got through checking FIT image and saved in the os_arch element of spin-table, then the secondary cores will check os_arch and jump to 32-bit OS or 64-bit OS automatically.
---
Changes in v2:
- Support to call armv8_switch_to_el2_m and armv8_switch_to_el1_m.
arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S | 35 ++++++++++++++++++++++++--- arch/arm/cpu/armv8/fsl-layerscape/mp.c | 10 ++++++++ arch/arm/include/asm/arch-fsl-layerscape/mp.h | 6 +++++ arch/arm/lib/bootm.c | 5 ++++ 4 files changed, 52 insertions(+), 4 deletions(-)
arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S +31 -4
@@ -13,6 +13,8 @@ #ifdef CONFIG_MP #include <asm/arch/mp.h> #endif +#include <asm/u-boot.h> +#include <asm/system.h> ENTRY(lowlevel_init) mov x29, lr /* Save LR */
@@ -320,6 +322,12 @@ ENTRY(secondary_boot_func) gic_wait_for_interrupt_m x0, w1 #endif + ldr x5, [x11, #24] + ldr x6, =IH_ARCH_DEFAULT + cmp x6, x5 + b.ne slave_cpu + + ldr x3, =ES_TO_AARCH64 bl secondary_switch_to_el2 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 bl secondary_switch_to_el1
@@ -337,19 +345,38 @@ slave_cpu: tbz x1, #25, cpu_is_le rev x0, x0 /* BE to LE conversion */ cpu_is_le: + + ldr x5, [x11, #24] + ldr x6, =IH_ARCH_DEFAULT + cmp x6, x5 + b.eq 1f + +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + ldr x3, =ES_TO_AARCH64 + bl secondary_switch_to_el2 + ldr x0, [x11] + ldr x3, =ES_TO_AARCH32 + bl secondary_switch_to_el1 +#else + ldr x0, [x11] + ldr x3, =ES_TO_AARCH32 + bl secondary_switch_to_el2 +#endif + +1: br x0 /* branch to the given address */ ENDPROC(secondary_boot_func) ENTRY(secondary_switch_to_el2) - switch_el x0, 1f, 0f, 0f + switch_el x4, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(secondary_switch_to_el2) ENTRY(secondary_switch_to_el1) - switch_el x0, 0f, 1f, 0f + switch_el x4, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x0, x1, x2, x3, x4, x5, x6 ENDPROC(secondary_switch_to_el1) /* Ensure that the literals used by the secondary boot code are
arch/arm/cpu/armv8/fsl-layerscape/mp.c +10 -0
@@ -22,6 +22,16 @@ phys_addr_t determine_mp_bootpg(void)return (phys_addr_t)&secondary_boot_code; } +void update_os_arch_secondary_cores (uint8_t os_arch) +{ +u64 *table =get_spin_tbl_addr (); +int i; + +for (i =1 ; i <CONFIG_MAX_CPUS ; i++) + table[i *WORDS_PER_SPIN_TABLE_ENTRY + +SPIN_TABLE_ELEM_OS_ARCH_IDX ] = os_arch; +} +int fsl_layerscape_wake_seconday_cores (void ) {struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR );
arch/arm/include/asm/arch-fsl-layerscape/mp.h +6 -0
@@ -13,6 +13,7 @@* uint64_t entry_addr; * uint64_t status; * uint64_t lpid; +* uint64_t os_arch; * }; * we pad this struct to 64 bytes so each entry is in its own cacheline * the actual spin table is an array of these structures
@@ -20,6 +21,7 @@#define SPIN_TABLE_ELEM_ENTRY_ADDR_IDX 0#define SPIN_TABLE_ELEM_STATUS_IDX 1#define SPIN_TABLE_ELEM_LPID_IDX 2 +#define SPIN_TABLE_ELEM_OS_ARCH_IDX 3#define WORDS_PER_SPIN_TABLE_ENTRY 8/* pad to 64 bytes */ #define SPIN_TABLE_ELEM_SIZE 64
@@ -35,4 +37,8 @@ phys_addr_t determine_mp_bootpg(void);void secondary_boot_func (void );int is_core_online (u64 cpu_id);#endif + +#define IH_ARCH_ARM 2/* ARM */ +#define IH_ARCH_ARM64 22/* ARM64 */ +#endif /* _FSL_LAYERSCAPE_MP_H */
arch/arm/lib/bootm.c +5 -0
@@ -268,6 +268,10 @@ bool armv7_boot_nonsec(void) }#endif +__weak void update_os_arch_secondary_cores (uint8_t os_arch) +{ +} +/* Subcommand: GO */ static void boot_jump_linux (bootm_headers_t *images,int flag) {
@@ -286,6 +290,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)announce_and_cleanup (fake);if (!fake) { +update_os_arch_secondary_cores (images->os.arch);if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && (images->os.arch ==IH_ARCH_ARM )) {smp_kick_all_cpus ();
Signature · 1 line
2.1.0.27.g96db324