armv8: Fix get_sctlr() return type
PATCH v2 1/2 armv8: Fix get_sctlr() return type
SCTLR_EL2 is a 64-bit register [1]. Return its value as long (64 bit) instead of int (32 bit) in get_sctlr() to make sure it's not trimmed.
---
Changes in v2:
- None (this patch was introduced in v2)
arch/arm/cpu/armv8/cache_v8.c | 2 +- arch/arm/include/asm/system.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +1 -1
@@ -825,7 +825,7 @@ void dcache_enable(void)void dcache_disable (void ) { -uint32_t sctlr; +unsigned long sctlr; sctlr =get_sctlr ();
arch/arm/include/asm/system.h +1 -1
@@ -171,7 +171,7 @@ static inline unsigned int current_el(void)return 3 & (el >>2 ); } -static inline unsigned int get_sctlr (void ) +static inline unsigned long get_sctlr (void ) {unsigned int el;unsigned long val;
Signature · 1 line
2.39.5
PATCH v2 2/2 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.
---
Changes in v2:
- None
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 22 lines · Sam Protsenko
SCTLR_EL2is a 64-bit register [1]. Return its value as long (64 bit) instead of int (32 bit) inget_sctlr()to make sure it's not trimmed.Fixes 0ae7653128c8 ("arm64: core support")Suggested-by Heinrich Schuchardt <[email protected]>Signed-off-by Sam Protsenko <[email protected]>---
Changes in v2:
- None (this patch was introduced in v2)arch/arm/cpu/armv8/cache_v8.c | 2 +- arch/arm/include/asm/system.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/arm/cpu/armv8/cache_v8.c +0
-0
arch/arm/cpu/armv8/cache_v8.c void dcache_enable(void) · line 828
Quoted 5 lines
arch/arm/cpu/armv8/cache_v8.c +1
-1@@ -825,7 +825,7 @@ void dcache_enable(void)void dcache_disable (void ) { -uint32_t sctlr; +unsigned long sctlr;
Although that's correct since it's a 64bit platform, isn't it better to define it as u64 to be sure we'll have at least 64 bits?
Thanks
/Ilias
Quoted 19 lines
arch/arm/cpu/armv8/cache_v8.c +0
-0sctlr =get_sctlr ();arch/arm/include/asm/system.h +1
-2@@ -171,7 +171,7 @@ static inline unsigned int current_el(void)return 3 & (el >>2 ); } -static inline unsigned int get_sctlr (void ) +static inline unsigned long get_sctlr (void ) {unsigned int el;unsigned long val; --2.39.5
Quoted 25 lines · Ilias Apalodimas
Quoted 23 lines · Sam Protsenko
SCTLR_EL2is a 64-bit register [1]. Return its value as long (64 bit) instead of int (32 bit) inget_sctlr()to make sure it's not trimmed.Fixes 0ae7653128c8 ("arm64: core support")Suggested-by Heinrich Schuchardt <[email protected]>Signed-off-by Sam Protsenko <[email protected]>---
Changes in v2:
- None (this patch was introduced in v2)arch/arm/cpu/armv8/cache_v8.c | 2 +- arch/arm/include/asm/system.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/arm/cpu/armv8/cache_v8.c +0
-0@@ -825,7 +825,7 @@ void dcache_enable(void)
Quoted 8 lines
arch/arm/cpu/armv8/cache_v8.c void dcache_enable(void) · line 828
Quoted 4 lines
arch/arm/cpu/armv8/cache_v8.c +1
-1void dcache_disable (void ) { -uint32_t sctlr; +unsigned long sctlr;Although that's correct since it's a 64bit platform, isn't it better to define it as u64 to be sure we'll have at least 64 bits?
Thanks for reviewing this! I considered making it uint64_t while reworking this bit. This 'sctlr' variable is assigned to get_sctlr() return value, and then passed to set_sctlr() as a parameter, both of which are 'unsigned long'. So I made 'sctlr' unsigned long too, just to match the signatures of mentioned functions. As for get_sctlr(), I just followed the style already existed inside and around that function. As you said, both u64 and unsigned long are 64-bit long types on ARMv8, and that's definitely ARMv8 specific file, so I guess that should be fine? In any case, if you have a strong opinion about this, please let me know and I'll rework it; both u64 and unsigned long look ok to me in this context.
Quoted 21 lines
Thanks
/IliasQuoted 19 lines
arch/arm/cpu/armv8/cache_v8.c +0
-0sctlr =get_sctlr ();arch/arm/include/asm/system.h +1
-2@@ -171,7 +171,7 @@ static inline unsigned int current_el(void)return 3 & (el >>2 ); } -static inline unsigned int get_sctlr (void ) +static inline unsigned long get_sctlr (void ) {unsigned int el;unsigned long val; --2.39.5
Ilias Apalodimas
Reviewed-byQuoted 37 lines · Sam Protsenko
Quoted 25 lines · Ilias Apalodimas
Quoted 23 lines · Sam Protsenko
SCTLR_EL2is a 64-bit register [1]. Return its value as long (64 bit) instead of int (32 bit) inget_sctlr()to make sure it's not trimmed.Fixes 0ae7653128c8 ("arm64: core support")Suggested-by Heinrich Schuchardt <[email protected]>Signed-off-by Sam Protsenko <[email protected]>---
Changes in v2:
- None (this patch was introduced in v2)arch/arm/cpu/armv8/cache_v8.c | 2 +- arch/arm/include/asm/system.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/arm/cpu/armv8/cache_v8.c +0
-0@@ -825,7 +825,7 @@ void dcache_enable(void)Quoted 8 lines
arch/arm/cpu/armv8/cache_v8.c void dcache_enable(void) · line 828
Quoted 4 lines
arch/arm/cpu/armv8/cache_v8.c +1
-1void dcache_disable (void ) { -uint32_t sctlr; +unsigned long sctlr;Although that's correct since it's a 64bit platform, isn't it better to define it as u64 to be sure we'll have at least 64 bits?
Quoted 11 lines
Thanks for reviewing this! I considered making it
uint64_twhile reworking this bit. This 'sctlr' variable is assigned toget_sctlr()return value, and then passed toset_sctlr()as a parameter, both of which are 'unsigned long'. So I made 'sctlr' unsigned long too, just to match the signatures of mentioned functions. As forget_sctlr(), I just followed the style already existed inside and around that function. As you said, both u64 and unsigned long are 64-bit long types on ARMv8, and that's definitely ARMv8 specific file, so I guess that should be fine? In any case, if you have a strong opinion about this, please let me know and I'll rework it; both u64 and unsigned long look ok to me in this context.
Yea perhaps I am nitpicking too much
Quoted 22 lines
Quoted 22 lines
Thanks
/IliasQuoted 19 lines
arch/arm/cpu/armv8/cache_v8.c +0
-0sctlr =get_sctlr ();arch/arm/include/asm/system.h +1
-2@@ -171,7 +171,7 @@ static inline unsigned int current_el(void)return 3 & (el >>2 ); } -static inline unsigned int get_sctlr (void ) +static inline unsigned long get_sctlr (void ) {unsigned int el;unsigned long val; --2.39.5
Quoted 6 lines · Sam Protsenko
SCTLR_EL2is a 64-bit register [1]. Return its value as long (64 bit) instead of int (32 bit) inget_sctlr()to make sure it's not trimmed.
Applied to u-boot/next, thanks!
Signature · 1 line
Tom