diff mbox series

[2/4] hw/ast-sfc: Use lpc fw space copy functions

Message ID 20201027001612.148724-2-oohall@gmail.com
State Under Review
Headers show
Series [1/4] hw/lpc: add helpers to copy in/out of fw space | expand

Checks

Context Check Description
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (233ade2f6ffdfa406100276784eb447d062fe8e7)

Commit Message

Oliver O'Halloran Oct. 27, 2020, 12:16 a.m. UTC
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hw/ast-bmc/ast-sf-ctrl.c | 58 +++++-----------------------------------
 1 file changed, 6 insertions(+), 52 deletions(-)

Comments

Vasant Hegde Oct. 29, 2020, 4:18 p.m. UTC | #1
On 10/27/20 5:46 AM, Oliver O'Halloran wrote:
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>


Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>

-Vasant
diff mbox series

Patch

diff --git a/hw/ast-bmc/ast-sf-ctrl.c b/hw/ast-bmc/ast-sf-ctrl.c
index 03cc44318e71..fc43040f574d 100644
--- a/hw/ast-bmc/ast-sf-ctrl.c
+++ b/hw/ast-bmc/ast-sf-ctrl.c
@@ -71,30 +71,9 @@  static int ast_copy_to_ahb(uint32_t reg, const void *src, uint32_t len)
 
 	/* SPI flash, use LPC->AHB bridge */
 	if ((reg >> 28) == (PNOR_AHB_ADDR >> 28)) {
-		uint32_t chunk, off = reg - PNOR_AHB_ADDR + pnor_lpc_offset;
-		int64_t rc;
-
-		while(len) {
-			/* Chose access size */
-			if (len > 3 && !(off & 3)) {
-				rc = lpc_write(OPAL_LPC_FW, off,
-					       *(uint32_t *)src, 4);
-				chunk = 4;
-			} else {
-				rc = lpc_write(OPAL_LPC_FW, off,
-					       *(uint8_t *)src, 1);
-				chunk = 1;
-			}
-			if (rc) {
-				prerror("AST_IO: lpc_write.sb failure %lld"
-					" to FW 0x%08x\n", rc, off);
-				return rc;
-			}
-			len -= chunk;
-			off += chunk;
-			src += chunk;
-		}
-		return 0;
+		uint32_t off = reg - PNOR_AHB_ADDR + pnor_lpc_offset;
+
+		return lpc_fw_write(off, src, len);
 	}
 
 	/* Otherwise we don't do byte access (... yet)  */
@@ -110,34 +89,9 @@  static int ast_copy_from_ahb(void *dst, uint32_t reg, uint32_t len)
 
 	/* SPI flash, use LPC->AHB bridge */
 	if ((reg >> 28) == (PNOR_AHB_ADDR >> 28)) {
-		uint32_t chunk, off = reg - PNOR_AHB_ADDR + pnor_lpc_offset;
-		int64_t rc;
-
-		while(len) {
-			uint32_t dat;
-
-			/* Chose access size */
-			if (len > 3 && !(off & 3)) {
-				rc = lpc_read(OPAL_LPC_FW, off, &dat, 4);
-				if (!rc)
-					*(uint32_t *)dst = dat;
-				chunk = 4;
-			} else {
-				rc = lpc_read(OPAL_LPC_FW, off, &dat, 1);
-				if (!rc)
-					*(uint8_t *)dst = dat;
-				chunk = 1;
-			}
-			if (rc) {
-				prerror("AST_IO: lpc_read.sb failure %lld"
-					" to FW 0x%08x\n", rc, off);
-				return rc;
-			}
-			len -= chunk;
-			off += chunk;
-			dst += chunk;
-		}
-		return 0;
+		uint32_t off = reg - PNOR_AHB_ADDR + pnor_lpc_offset;
+
+		return lpc_fw_read(off, dst, len);
 	}
 	/* Otherwise we don't do byte access (... yet)  */
 	prerror("AST_IO: Attempted read bytes access to %08x\n", reg);