armv8: cpu: Implement allow_unaligned()
PATCH 1/1 armv8: cpu: Implement allow_unaligned()
Usually ARMv8 platforms allow unaligned access for Normal memory. But some chips might not allow it by default, having SCTLR.A bit set to 1 before U-Boot execution. One such example is Exynos850 SoC. As allow_unaligned() is not implemented for ARMv8 at the moment, its __weak implementation is used, which does nothing. That might lead to unaligned access abort, for example when running EFI selftest. Fix that by implementing allow_unaligned() for ARMv8.
The issue was found when running EFI selftest on E850-96 board (Exynos850 based):
=> bootefi selftest $fdtcontroladdr
...
Executing 'HII database protocols'
"Synchronous Abort" handler, esr 0x96000021, far 0xbaac0991
...
resetting ...Unaligned abort happens in u16_strnlen(), which is called from efi_hii_sibt_string_ucs2_block_next():
u16_strlen(blk->string_text)
where 'blk' type is struct efi_hii_sibt_string_ucs2_block. Because this struct is packed, doing "->string_text" makes 'blk' address incremented by 1 byte, which makes it unaligned. Although allow_unaligned() was called in efi_init_early() before EFI selftest execution, it wasn't implemented for ARMv8 CPUs, so data abort happened.
--- arch/arm/cpu/armv8/cpu.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/cpu/armv8/cpu.c +5 -0
@@ -94,3 +94,8 @@ void armv8_setup_psci(void)secure_ram_addr (psci_arch_init)(); }#endif + +void allow_unaligned (void ) +{ +set_sctlr (get_sctlr () & ~CR_A ); +}
Signature · 1 line
2.39.5
Quoted 40 lines · Sam Protsenko
Usually ARMv8 platforms allow unaligned access for Normal memory. But some chips might not allow it by default, having SCTLR.A bit set to 1 before U-Boot execution. One such example is Exynos850 SoC. As
allow_unaligned()is not implemented for ARMv8 at the moment, its__weakimplementation is used, which does nothing. That might lead to unaligned access abort, for example when running EFI selftest. Fix that by implementingallow_unaligned()for ARMv8.The issue was found when running EFI selftest on E850-96 board (Exynos850 based):
=> bootefi selftest $fdtcontroladdr ... Executing 'HII database protocols' "Synchronous Abort" handler, esr 0x96000021, far 0xbaac0991 ... resetting ...Unaligned abort happens in
u16_strnlen(), which is called fromefi_hii_sibt_string_ucs2_block_next():u16_strlen(blk->string_text)where 'blk' type is struct
efi_hii_sibt_string_ucs2_block. Because this struct is packed, doing "->string_text" makes 'blk' address incremented by 1 byte, which makes it unaligned. Althoughallow_unaligned()was called inefi_init_early()before EFI selftest execution, it wasn't implemented for ARMv8 CPUs, so data abort happened.Signed-off-by Sam Protsenko <[email protected]>--- arch/arm/cpu/armv8/cpu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm/cpu/armv8/cpu.c +0
-0
arch/arm/cpu/armv8/cpu.c void armv8_setup_psci(void) · line 100
Quoted 7 lines
arch/arm/cpu/armv8/cpu.c +4
-0@@ -94,3 +94,8 @@ void armv8_setup_psci(void)secure_ram_addr (psci_arch_init)(); }#endif + +void allow_unaligned (void ) +{ +set_sctlr (get_sctlr () & ~CR_A );
Looking at the ARM documentation SCTLR_EL2 is a 64bit register.
But get_sctlr() is defined as
arch/arm/include/asm/system.h:174:
static inline unsigned int get_sctlr(void)
Your code might not work as expected. Should we adjust the definition of get_sctlr() to return a long value?
Best regards
Heinrich
Quoted 1 line
arch/arm/cpu/armv8/cpu.c +1
-0+}
Quoted 1 line · Heinrich Schuchardt
[snip]
Quoted 8 lines
arch/arm/cpu/armv8/cpu.c void armv8_setup_psci(void) · line 100
Quoted 3 lines
arch/arm/cpu/armv8/cpu.c +3
-0+void allow_unaligned (void ) +{ +set_sctlr (get_sctlr () & ~CR_A );Looking at the ARM documentation
SCTLR_EL2is a 64bit register.
Quoted 8 lines
But
get_sctlr()is defined as
arch/arm/include/asm/system.h:174:
static inline unsigned intget_sctlr(void)Your code might not work as expected. Should we adjust the definition of
get_sctlr()to return a long value?
Hi Heinrich,
Good catch! I totally overlooked it. And it's already used in a similar way in a couple of different places. I'll handle that in my v2 soon.
Thanks!
Quoted 6 lines
Best regards
Heinrich
Quoted 1 line
+}