powerpc/powernv: Fix endian issues in memory error handling code
PATCH 1/1 powerpc/powernv: Fix endian issues in memory error handling code
struct OpalMemoryErrorData is passed to us from firmware, so we have to byteswap it.
---
Having enums in a firmware interface concerns me, but that cleanup can be in a subsequent patch.
Mahesh, could you give this a test to see if it works?
arch/powerpc/include/asm/opal.h +5 -5
@@ -482,7 +482,7 @@ enum OpalMemErr_DynErrType {struct OpalMemoryErrorData {enum OpalMemErr_Version version:8 ;/* 0x00 */ enum OpalMemErrType type:8 ;/* 0x01 */ -uint16_t flags;/* 0x02 */ +__be16 flags;/* 0x02 */ uint8_t reserved_1[4 ];/* 0x04 */ union {
@@ -490,15 +490,15 @@ struct OpalMemoryErrorData {struct {enum OpalMemErr_ResilErrType resil_err_type:8 ;uint8_t reserved_1[7 ]; -uint64_t physical_address_start; -uint64_t physical_address_end; +__be64 physical_address_start; +__be64 physical_address_end; } resilience;/* Dynamic memory deallocation error info */ struct {enum OpalMemErr_DynErrType dyn_err_type:8 ;uint8_t reserved_1[7 ]; -uint64_t physical_address_start; -uint64_t physical_address_end; +__be64 physical_address_start; +__be64 physical_address_end; } dyn_dealloc; } u; };
arch/powerpc/platforms/powernv/opal-memory-errors.c +4 -4
@@ -47,12 +47,12 @@ static void handle_memory_error_event(st __func__, merr_evt->type);switch (merr_evt->type) {case OPAL_MEM_ERR_TYPE_RESILIENCE : - paddr_start = merr_evt->u.resilience.physical_address_start; - paddr_end = merr_evt->u.resilience.physical_address_end; + paddr_start =be64_to_cpu (merr_evt->u.resilience.physical_address_start); + paddr_end =be64_to_cpu (merr_evt->u.resilience.physical_address_end);break ;case OPAL_MEM_ERR_TYPE_DYN_DALLOC : - paddr_start = merr_evt->u.dyn_dealloc.physical_address_start; - paddr_end = merr_evt->u.dyn_dealloc.physical_address_end; + paddr_start =be64_to_cpu (merr_evt->u.dyn_dealloc.physical_address_start); + paddr_end =be64_to_cpu (merr_evt->u.dyn_dealloc.physical_address_end);break ;default :return ;
Quoted 4 lines · Anton Blanchard
struct OpalMemoryErrorData is passed to us from firmware, so we have to byteswap it.
Signed-off-by Anton Blanchard <[email protected]>
Quoted 62 lines
---
Having enums in a firmware interface concerns me, but that cleanup can be in a subsequent patch.
Mahesh, could you give this a test to see if it works?
Index:
b/arch/powerpc/include/asm/opal.h
===================================================================arch/powerpc/include/asm/opal.h +5
-5@@ -482,7 +482,7 @@ enum OpalMemErr_DynErrType {struct OpalMemoryErrorData {enum OpalMemErr_Version version:8 ;/* 0x00 */ enum OpalMemErrType type:8 ;/* 0x01 */ -uint16_t flags;/* 0x02 */ +__be16 flags;/* 0x02 */ uint8_t reserved_1[4 ];/* 0x04 */ union {@@ -490,15 +490,15 @@ struct OpalMemoryErrorData {struct {enum OpalMemErr_ResilErrType resil_err_type:8 ;uint8_t reserved_1[7 ]; -uint64_t physical_address_start; -uint64_t physical_address_end; +__be64 physical_address_start; +__be64 physical_address_end; } resilience;/* Dynamic memory deallocation error info */ struct {enum OpalMemErr_DynErrType dyn_err_type:8 ;uint8_t reserved_1[7 ]; -uint64_t physical_address_start; -uint64_t physical_address_end; +__be64 physical_address_start; +__be64 physical_address_end; } dyn_dealloc; } u; };Index:
b/arch/powerpc/platforms/powernv/opal-memory-errors.c
===================================================================arch/powerpc/platforms/powernv/opal-memory-errors.c +4
-4@@ -47,12 +47,12 @@ static void handle_memory_error_event(st __func__, merr_evt->type);switch (merr_evt->type) {case OPAL_MEM_ERR_TYPE_RESILIENCE : - paddr_start = merr_evt->u.resilience.physical_address_start; - paddr_end = merr_evt->u.resilience.physical_address_end; + paddr_start =be64_to_cpu (merr_evt->u.resilience.physical_address_start); + paddr_end =be64_to_cpu (merr_evt->u.resilience.physical_address_end);break ;case OPAL_MEM_ERR_TYPE_DYN_DALLOC : - paddr_start = merr_evt->u.dyn_dealloc.physical_address_start; - paddr_end = merr_evt->u.dyn_dealloc.physical_address_end; + paddr_start =be64_to_cpu (merr_evt->u.dyn_dealloc.physical_address_start); + paddr_end =be64_to_cpu (merr_evt->u.dyn_dealloc.physical_address_end);break ;default :return ;
Signature · 1 line
Mahesh J Salgaonkar