armv8: Support loading 32-bit OS in AArch32 execution state
Subsystems (3)
v6 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 v6:
- Modified armv8_switch_to_el1(). It will always jump to ep when switching to AArch64 or AArch32 modes.
- Make other platforms compatible with the new armv8_switch_to_el2() and armv8_switch_to_el1().
Changes in v5:
- Modified armv8_switch_to_el2(). It will always jump to ep when switching to AArch64 or AArch32 modes.
- Make secondary_switch_to_el2() always jump to ep when switching to AArch64 or AArch32 modes.
Changes in v4:
- Correct config ARM64_SUPPORT_AARCH32.
- Omit arch and ftaddr arguments.
- Rename "xreg5" to "tmp".
- Use xxx_RES1 to combine all RES1 fields in xxx register.
- Use an immediate cmp directly.
- Use #ifdef for CONFIG_ARM64_SUPPORT_AARCH32.
Changes in v3:
- Comments the functions and the arguments.
- Rename the real parameters.
- Use the macros instead of the magic values.
- Remove the redundant codes.
- Clean up all of the mess in boot_jump_linux().
- Add CONFIG_ARM64_SUPPORT_AARCH32 to detect for some ARM64 system doesn't support AArch32 state.
- Adjust the arguments for armv8_switch_to_el2_m and armv8_switch_to_el1_m.
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.
- Support to call armv8_switch_to_el2_m and armv8_switch_to_el1_m.
----------------------------------------------------------------
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/Kconfig | 6 ++ arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S | 61 ++++++++++++--- arch/arm/cpu/armv8/fsl-layerscape/mp.c | 10 +++ arch/arm/cpu/armv8/start.S | 8 ++ arch/arm/cpu/armv8/transition.S | 8 +- arch/arm/include/asm/arch-fsl-layerscape/mp.h | 6 ++ arch/arm/include/asm/macro.h | 176 +++++++++++++++++++++++++++++++++----------- arch/arm/include/asm/system.h | 119 +++++++++++++++++++++++++++++- arch/arm/lib/bootm.c | 45 +++++++++-- arch/arm/mach-rmobile/lowlevel_init_gen3.S | 9 ++- common/image-fit.c | 19 ++++- 11 files changed, 401 insertions(+), 66 deletions(-)
PATCH v6 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 v6:
- Modified armv8_switch_to_el1(). It will always jump to ep when switching to AArch64 or AArch32 modes.
- Make other platforms compatible with the new armv8_switch_to_el2() and armv8_switch_to_el1().
Changes in v5:
- Modified armv8_switch_to_el2(). It will always jump to ep when switching to AArch64 or AArch32 modes.
Changes in v4:
- Correct config ARM64_SUPPORT_AARCH32.
- Omit arch and ftaddr arguments.
- Rename "xreg5" to "tmp".
- Use xxx_RES1 to combine all RES1 fields in xxx register.
- Use an immediate cmp directly.
- Use #ifdef for CONFIG_ARM64_SUPPORT_AARCH32.
Changes in v3:
- Comments the functions and the arguments.
- Rename the real parameters.
- Use the macros instead of the magic values.
- Remove the redundant codes.
- Clean up all of the mess in boot_jump_linux().
- Add CONFIG_ARM64_SUPPORT_AARCH32 to detect for some ARM64 system doesn't support AArch32 state.
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/Kconfig | 6 + arch/arm/cpu/armv8/start.S | 8 ++ arch/arm/cpu/armv8/transition.S | 8 +- arch/arm/include/asm/macro.h | 176 ++++++++++++++++++++++------- arch/arm/include/asm/system.h | 119 ++++++++++++++++++- arch/arm/lib/bootm.c | 39 ++++++- arch/arm/mach-rmobile/lowlevel_init_gen3.S | 9 +- common/image-fit.c | 19 +++- 8 files changed, 328 insertions(+), 56 deletions(-)
arch/arm/Kconfig +6 -0
@@ -126,6 +126,12 @@ config ENABLE_ARM_SOC_BOOT0_HOOK ARM_SOC_BOOT0_HOOK which contains the required assembler preprocessor code. +config ARM64_SUPPORT_AARCH32 + bool "ARM64 system support AArch32 execution state" + default y if ARM64 && !TARGET_THUNDERX_88XX + help + This ARM64 system supports AArch32 execution state. + choice prompt "Target select" default TARGET_HIKEY
arch/arm/cpu/armv8/start.S +8 -0
@@ -251,9 +251,17 @@ WEAK(lowlevel_init) /* * All slaves will enter EL2 and optionally EL1. */ + adr x3, lowlevel_in_el2 + ldr x4, =ES_TO_AARCH64 bl armv8_switch_to_el2 + +lowlevel_in_el2: #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + adr x3, lowlevel_in_el1 + ldr x4, =ES_TO_AARCH64 bl armv8_switch_to_el1 + +lowlevel_in_el1: #endif #endif /* CONFIG_ARMV8_MULTIENTRY */
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 x5, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x3, x4, x5 ENDPROC(armv8_switch_to_el2) ENTRY(armv8_switch_to_el1) - switch_el x0, 0f, 1f, 0f + switch_el x5, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x3, x4, x5 ENDPROC(armv8_switch_to_el1)
arch/arm/include/asm/macro.h +133 -43
215 lines not on this page · raw message
arch/arm/include/asm/system.h +117 -2
131 lines not on this page · raw message
arch/arm/lib/bootm.c +34 -5
@@ -193,10 +193,6 @@ static void do_nonsec_virt_switch(void) {smp_kick_all_cpus ();dcache_disable ();/* flush cache before swtiching to EL2 */ -armv8_switch_to_el2 (); -#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 -armv8_switch_to_el1 (); -#endif }#endif
@@ -273,6 +269,24 @@ bool armv7_boot_nonsec(void) }#endif +#ifdef CONFIG_ARM64 +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +static void switch_to_el1 (void ) +{ +if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && + (images.os.arch ==IH_ARCH_ARM )) +armv8_switch_to_el1 (0 , (u64 )gd->bd->bi_arch_number, + (u64 )images.ft_addr, + (u64 )images.ep, +ES_TO_AARCH32 ); +else +armv8_switch_to_el1 ((u64 )images.ft_addr,0 ,0 , + images.ep, +ES_TO_AARCH64 ); +} +#endif +#endif +/* Subcommand: GO */ static void boot_jump_linux (bootm_headers_t *images,int flag) {
@@ -292,7 +306,22 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)if (!fake) {do_nonsec_virt_switch (); -kernel_entry (images->ft_addr,NULL ,NULL ,NULL ); + +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +armv8_switch_to_el2 ((u64 )images->ft_addr,0 ,0 , + (u64 )switch_to_el1,ES_TO_AARCH64 ); +#else +if ((IH_ARCH_DEFAULT ==IH_ARCH_ARM64 ) && + (images->os.arch ==IH_ARCH_ARM )) +armv8_switch_to_el2 (0 , (u64 )gd->bd->bi_arch_number, + (u64 )images->ft_addr, + (u64 )images->ep, +ES_TO_AARCH32 ); +else +armv8_switch_to_el2 ((u64 )images->ft_addr,0 ,0 , + images->ep, +ES_TO_AARCH64 ); +#endif }#else unsigned long machid = gd->bd->bi_arch_number;
arch/arm/mach-rmobile/lowlevel_init_gen3.S +8 -1
@@ -61,11 +61,18 @@ ENTRY(lowlevel_init) /* * All slaves will enter EL2 and optionally EL1. */ + adr x3, lowlevel_in_el2 + ldr x4, =ES_TO_AARCH64 bl armv8_switch_to_el2 + +lowlevel_in_el2: #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + adr x3, lowlevel_in_el1 + ldr x4, =ES_TO_AARCH64 bl armv8_switch_to_el1 -#endif +lowlevel_in_el1: +#endif #endif /* CONFIG_ARMV8_MULTIENTRY */ bl s_init
common/image-fit.c +18 -1
@@ -27,6 +27,7 @@ DECLARE_GLOBAL_DATA_PTR;#include <u-boot/md5.h> #include <u-boot/sha1.h> #include <u-boot/sha256.h> +#include <generated/autoconf.h> /*****************************************************************************/ /* New uImage format routines */
@@ -1161,11 +1162,18 @@ int fit_image_check_os(const void *fit, int noffset, uint8_t os)int fit_image_check_arch (const void *fit,int noffset,uint8_t arch) {uint8_t image_arch; +int aarch32_support =0 ; + +#ifdef CONFIG_ARM64_SUPPORT_AARCH32 + aarch32_support =1 ; +#endif 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 && + aarch32_support); }/**
@@ -1617,6 +1625,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;
@@ -1700,6 +1711,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 v6 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 v6:
- Make secondary_switch_to_el1() always jump to ep when switching to AArch64 or AArch32 modes.
Changes in v5:
- Make secondary_switch_to_el2() always jump to ep when switching to AArch64 or AArch32 modes.
Changes in v4:
- Omit arch and ftaddr arguments.
Changes in v3:
- Adjust the arguments for armv8_switch_to_el2_m and armv8_switch_to_el1_m.
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 | 61 ++++++++++++++++++++++----- arch/arm/cpu/armv8/fsl-layerscape/mp.c | 10 +++++ arch/arm/include/asm/arch-fsl-layerscape/mp.h | 6 +++ arch/arm/lib/bootm.c | 6 +++ 4 files changed, 73 insertions(+), 10 deletions(-)
arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S +51 -10
@@ -13,6 +13,7 @@ #ifdef CONFIG_MP #include <asm/arch/mp.h> #endif +#include <asm/u-boot.h> ENTRY(lowlevel_init) mov x29, lr /* Save LR */
@@ -324,11 +325,6 @@ ENTRY(secondary_boot_func) gic_wait_for_interrupt_m x0, w1 #endif - bl secondary_switch_to_el2 -#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 - bl secondary_switch_to_el1 -#endif - slave_cpu: wfe ldr x0, [x11]
@@ -341,19 +337,64 @@ slave_cpu: tbz x1, #25, cpu_is_le rev x0, x0 /* BE to LE conversion */ cpu_is_le: - br x0 /* branch to the given address */ + ldr x5, [x11, #24] + ldr x6, =IH_ARCH_DEFAULT + cmp x6, x5 + b.eq 1f + +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + adr x3, secondary_switch_to_el1 + ldr x4, =ES_TO_AARCH64 +#else + ldr x3, [x11] + ldr x4, =ES_TO_AARCH32 +#endif + bl secondary_switch_to_el2 + +1: +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + adr x3, secondary_switch_to_el1 +#else + ldr x3, [x11] +#endif + ldr x4, =ES_TO_AARCH64 + bl secondary_switch_to_el2 + ENDPROC(secondary_boot_func) ENTRY(secondary_switch_to_el2) - switch_el x0, 1f, 0f, 0f + switch_el x5, 1f, 0f, 0f 0: ret -1: armv8_switch_to_el2_m x0 +1: armv8_switch_to_el2_m x3, x4, x5 ENDPROC(secondary_switch_to_el2) ENTRY(secondary_switch_to_el1) - switch_el x0, 0f, 1f, 0f + mrs x0, mpidr_el1 + ubfm x1, x0, #8, #15 + ubfm x2, x0, #0, #1 + orr x10, x2, x1, lsl #2 /* x10 has LPID */ + + lsl x1, x10, #6 + ldr x0, =__spin_table + /* physical address of this cpus spin table element */ + add x11, x1, x0 + + ldr x3, [x11] + + ldr x5, [x11, #24] + ldr x6, =IH_ARCH_DEFAULT + cmp x6, x5 + b.eq 2f + + ldr x4, =ES_TO_AARCH32 + bl switch_to_el1 + +2: ldr x4, =ES_TO_AARCH64 + +switch_to_el1: + switch_el x5, 0f, 1f, 0f 0: ret -1: armv8_switch_to_el1_m x0, x1 +1: armv8_switch_to_el1_m x3, x4, x5 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 +6 -0
@@ -270,6 +270,10 @@ bool armv7_boot_nonsec(void)#endif #ifdef CONFIG_ARM64 +__weak void update_os_arch_secondary_cores(uint8_t os_arch) +{ +} + #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 static void switch_to_el1(void) {
@@ -307,6 +311,8 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)if (!fake) {do_nonsec_virt_switch (); +update_os_arch_secondary_cores (images->os.arch); +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 armv8_switch_to_el2 ((u64 )images->ft_addr,0 ,0 , (u64 )switch_to_el1,ES_TO_AARCH64 );
Signature · 1 line
2.1.0.27.g96db324
PATCH v6 1/2 armv8: Support loading 32-bit OS in AArch32 execution state
In reply to Alison WangQuoted 9 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]>
I still have a hard time wrapping my head around how this will look like with PSCI support, but it's certainly a step into the right direction.
Alex
PATCH v6 2/2 armv8: fsl-layerscape: SMP support for loading 32-bit OS
In reply to Alison WangQuoted 7 lines · Alison Wang
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_archelement of spin-table, then the secondary cores will checkos_archand jump to 32-bit OS or 64-bit OS automatically.Signed-off-by Alison Wang <[email protected]>Signed-off-by Chenhui Zhao <[email protected]>
No complains from my side, but this dives heavily into FSL specific code. Also, I mention PSCI once more here ;).
Alex
v6 cover armv8: Support loading 32-bit OS in AArch32 execution state
In reply to Alison WangQuoted 42 lines · Alison Wang
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_archelement of spin-table, then the secondary cores will checkos_archand jump to 32-bit OS or 64-bit OS automatically.---------------------------------------
Changes in v6:
- Modifiedarmv8_switch_to_el1(). It will always jump to ep when switching to AArch64 or AArch32 modes.
- Make other platforms compatible with the newarmv8_switch_to_el2()andarmv8_switch_to_el1().Changes in v5:
- Modifiedarmv8_switch_to_el2(). It will always jump to ep when switching to AArch64 or AArch32 modes.
- Makesecondary_switch_to_el2()always jump to ep when switching to AArch64 or AArch32 modes.Changes in v4:
- Correct configARM64_SUPPORT_AARCH32.
- Omit arch and ftaddr arguments.
- Rename "xreg5" to "tmp".
- Usexxx_RES1to combine all RES1 fields in xxx register.
- Use an immediate cmp directly.
- Use #ifdef forCONFIG_ARM64_SUPPORT_AARCH32.Changes in v3:
- Comments the functions and the arguments.
- Rename the real parameters.
- Use the macros instead of the magic values.
- Remove the redundant codes.
- Clean up all of the mess inboot_jump_linux().
- AddCONFIG_ARM64_SUPPORT_AARCH32to detect for some ARM64 system doesn't support AArch32 state.
- Adjust the arguments forarmv8_switch_to_el2_mandarmv8_switch_to_el1_m.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.
- Support to callarmv8_switch_to_el2_mandarmv8_switch_to_el1_m.
Quoted 4 lines
----------------------------------------------------------------
Alison Wang (2):
armv8: Support loading 32-bit OS in AArch32 execution state
armv8: fsl-layerscape: SMP support for loading 32-bit OS
Alison,
The change overall is OK, but the way you split the patches is not. If you apply the first patch and then compile, you will see all our armv8 platforms are broken. You changed the definition of macro armv8_switch_to_el2_m in the first patch, but you change the call in the second patch.
York