[Skiboot] [PATCH 4/4] libflash/mbox: Use lpc fw space copy functions

Oliver O'Halloran oohall at gmail.com
Tue Oct 27 11:16:12 AEDT 2020


Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 libflash/mbox-flash.c | 67 ++-----------------------------------------
 1 file changed, 2 insertions(+), 65 deletions(-)

diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c
index 6da77d7fc9a0..f2f808cb432e 100644
--- a/libflash/mbox-flash.c
+++ b/libflash/mbox-flash.c
@@ -147,79 +147,16 @@ static int lpc_window_read(struct mbox_flash_data *mbox_flash, uint32_t pos,
 			   void *buf, uint32_t len)
 {
 	uint32_t off = mbox_flash->read.lpc_addr + (pos - mbox_flash->read.cur_pos);
-	int rc;
-
-	prlog(PR_TRACE, "Reading at 0x%08x for 0x%08x offset: 0x%08x\n",
-			pos, len, off);
-
-	while(len) {
-		uint32_t chunk;
-		uint32_t dat;
-
-		/* XXX: make this read until it's aligned */
-		if (len > 3 && !(off & 3)) {
-			rc = lpc_read(OPAL_LPC_FW, off, &dat, 4);
-			if (!rc) {
-				/*
-				 * lpc_read swaps to CPU endian but it's not
-				 * really a 32-bit value, so convert back.
-				 */
-				*(__be32 *)buf = cpu_to_be32(dat);
-			}
-			chunk = 4;
-		} else {
-			rc = lpc_read(OPAL_LPC_FW, off, &dat, 1);
-			if (!rc)
-				*(uint8_t *)buf = dat;
-			chunk = 1;
-		}
-		if (rc) {
-			prlog(PR_ERR, "lpc_read failure %d to FW 0x%08x\n", rc, off);
-			return rc;
-		}
-		len -= chunk;
-		off += chunk;
-		buf += chunk;
-	}
 
-	return 0;
+	return lpc_fw_read(off, buf, len);
 }
 
 static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos,
 			    const void *buf, uint32_t len)
 {
 	uint32_t off = mbox_flash->write.lpc_addr + (pos - mbox_flash->write.cur_pos);
-	int rc;
-
-
-	prlog(PR_TRACE, "Writing at 0x%08x for 0x%08x offset: 0x%08x\n",
-			pos, len, off);
 
-	while(len) {
-		uint32_t chunk;
-
-		if (len > 3 && !(off & 3)) {
-			/* endian swap: see lpc_window_write */
-			uint32_t dat = be32_to_cpu(*(__be32 *)buf);
-
-			rc = lpc_write(OPAL_LPC_FW, off, dat, 4);
-			chunk = 4;
-		} else {
-			uint8_t dat = *(uint8_t *)buf;
-
-			rc = lpc_write(OPAL_LPC_FW, off, dat, 1);
-			chunk = 1;
-		}
-		if (rc) {
-			prlog(PR_ERR, "lpc_write failure %d to FW 0x%08x\n", rc, off);
-			return rc;
-		}
-		len -= chunk;
-		off += chunk;
-		buf += chunk;
-	}
-
-	return 0;
+	return lpc_fw_write(off, buf,  len);
 }
 
 static uint64_t mbox_flash_mask(struct mbox_flash_data *mbox_flash)
-- 
2.26.2



More information about the Skiboot mailing list