[Skiboot] [PATCH 8/8] flash: AST BMC endian fixes

Nicholas Piggin npiggin at gmail.com
Sun Oct 3 12:22:10 AEDT 2021


Fix endian for the 4-byte LPC copy similarly to other flash drivers.
This allows flash to be detected on POWER8 AST BMC systems with a LE
skiboot.

Fix incorrect comments in those other drivers while we're here.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 hw/ast-bmc/ast-sf-ctrl.c | 14 +++++++++++---
 libflash/ipmi-hiomap.c   |  2 +-
 libflash/mbox-flash.c    |  2 +-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/hw/ast-bmc/ast-sf-ctrl.c b/hw/ast-bmc/ast-sf-ctrl.c
index 03cc44318..c3a32134e 100644
--- a/hw/ast-bmc/ast-sf-ctrl.c
+++ b/hw/ast-bmc/ast-sf-ctrl.c
@@ -77,8 +77,11 @@ static int ast_copy_to_ahb(uint32_t reg, const void *src, uint32_t len)
 		while(len) {
 			/* Chose access size */
 			if (len > 3 && !(off & 3)) {
+				/* endian swap: see ast_copy_from_ahb */
+				uint32_t dat = be32_to_cpu(*(__be32 *)src);
+
 				rc = lpc_write(OPAL_LPC_FW, off,
-					       *(uint32_t *)src, 4);
+					       dat, 4);
 				chunk = 4;
 			} else {
 				rc = lpc_write(OPAL_LPC_FW, off,
@@ -119,8 +122,13 @@ static int ast_copy_from_ahb(void *dst, uint32_t reg, uint32_t len)
 			/* Chose access size */
 			if (len > 3 && !(off & 3)) {
 				rc = lpc_read(OPAL_LPC_FW, off, &dat, 4);
-				if (!rc)
-					*(uint32_t *)dst = dat;
+				if (!rc) {
+					/*
+					 * lpc_read swaps to CPU endian but it's not
+					 * really a 32-bit value, so convert back.
+					 */
+					*(__be32 *)dst = cpu_to_be32(dat);
+				}
 				chunk = 4;
 			} else {
 				rc = lpc_read(OPAL_LPC_FW, off, &dat, 1);
diff --git a/libflash/ipmi-hiomap.c b/libflash/ipmi-hiomap.c
index c889d6316..29355d666 100644
--- a/libflash/ipmi-hiomap.c
+++ b/libflash/ipmi-hiomap.c
@@ -620,7 +620,7 @@ static int lpc_window_write(struct ipmi_hiomap *ctx, uint32_t pos,
 		uint32_t chunk;
 
 		if (len > 3 && !(off & 3)) {
-			/* endian swap: see lpc_window_write */
+			/* endian swap: see lpc_window_read */
 			uint32_t dat = be32_to_cpu(*(__be32 *)buf);
 
 			rc = lpc_write(OPAL_LPC_FW, off, dat, 4);
diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c
index 6da77d7fc..4c20f15f2 100644
--- a/libflash/mbox-flash.c
+++ b/libflash/mbox-flash.c
@@ -199,7 +199,7 @@ static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos,
 		uint32_t chunk;
 
 		if (len > 3 && !(off & 3)) {
-			/* endian swap: see lpc_window_write */
+			/* endian swap: see lpc_window_read */
 			uint32_t dat = be32_to_cpu(*(__be32 *)buf);
 
 			rc = lpc_write(OPAL_LPC_FW, off, dat, 4);
-- 
2.23.0



More information about the Skiboot mailing list