[Skiboot] [RFC PATCH 3/3] astbmc/pnor: Use mbox-flash for flash accesses

Cyril Bur cyril.bur at au1.ibm.com
Thu Jan 12 16:26:19 AEDT 2017


If the BMC is MBOX protocol aware, request flash reads/writes over the
MBOX regs. This inits the blocklevel for pnor access with mbox-flash.

[This patch need a bit allocated in the scratch data register!]

Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 hw/ast-bmc/ast-io.c     |  9 +++++++++
 include/ast.h           |  1 +
 platforms/astbmc/pnor.c | 48 +++++++++++++++++++++++++++++++-----------------
 3 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/hw/ast-bmc/ast-io.c b/hw/ast-bmc/ast-io.c
index 41234fbb..84fcb84b 100644
--- a/hw/ast-bmc/ast-io.c
+++ b/hw/ast-bmc/ast-io.c
@@ -96,6 +96,7 @@
 
 #define BMC_SIO_SCR29 0x29
 #define BMC_SIO_SCR29_MEMBOOT 0x10
+#define BMC_SIO_SCR29_MBOX_FLASH (1 << 2) /* TODO: Actually get a free bit!!! */
 
 enum {
 	BMC_SIO_DEV_NONE	= -1,
@@ -388,6 +389,14 @@ void ast_io_init(void)
 	ast_setup_sio_irq_polarity();
 }
 
+bool ast_is_mbox_pnor(void)
+{
+	uint8_t boot_flags;
+
+	boot_flags = bmc_sio_inb(BMC_SIO_SCR29);
+	return boot_flags & BMC_SIO_SCR29_MBOX_FLASH;
+}
+
 bool ast_is_ahb_lpc_pnor(void)
 {
 	uint8_t boot_version;
diff --git a/include/ast.h b/include/ast.h
index 43c5989f..40225e9a 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -74,6 +74,7 @@ int ast_copy_from_ahb(void *dst, uint32_t reg, uint32_t len);
 
 void ast_io_init(void);
 bool ast_is_ahb_lpc_pnor(void);
+bool ast_is_mbox_pnor(void);
 
 /* UART configuration */
 
diff --git a/platforms/astbmc/pnor.c b/platforms/astbmc/pnor.c
index de4cafaf..e663055c 100644
--- a/platforms/astbmc/pnor.c
+++ b/platforms/astbmc/pnor.c
@@ -18,6 +18,7 @@
 #include <device.h>
 #include <console.h>
 #include <opal.h>
+#include <libflash/mbox-flash.h>
 #include <libflash/libflash.h>
 #include <libflash/libffs.h>
 #include <libflash/blocklevel.h>
@@ -27,26 +28,35 @@
 
 int pnor_init(void)
 {
-	struct spi_flash_ctrl *pnor_ctrl;
+	struct spi_flash_ctrl *pnor_ctrl = NULL;
 	struct blocklevel_device *bl = NULL;
 	int rc;
+	bool do_mbox;
 
-	/* Open controller and flash. If the LPC->AHB doesn't point to
-	 * the PNOR flash base we assume we're booting from BMC system
-	 * memory (or some other place setup by the BMC to support LPC
-	 * FW reads & writes). */
-	if (ast_is_ahb_lpc_pnor())
-		rc = ast_sf_open(AST_SF_TYPE_PNOR, &pnor_ctrl);
-	else {
-		printf("PLAT: Memboot detected\n");
-		rc = ast_sf_open(AST_SF_TYPE_MEM, &pnor_ctrl);
-	}
-	if (rc) {
-		prerror("PLAT: Failed to open PNOR flash controller\n");
-		goto fail;
+	do_mbox = ast_is_mbox_pnor();
+	if (do_mbox) {
+		rc = mbox_flash_init(&bl);
+	} else {
+		/* Open controller and flash. If the LPC->AHB doesn't point to
+		 * the PNOR flash base we assume we're booting from BMC system
+		 * memory (or some other place setup by the BMC to support LPC
+		 * FW reads & writes).
+		 */
+
+		if (ast_is_ahb_lpc_pnor())
+			rc = ast_sf_open(AST_SF_TYPE_PNOR, &pnor_ctrl);
+		else {
+			printf("PLAT: Memboot detected\n");
+			rc = ast_sf_open(AST_SF_TYPE_MEM, &pnor_ctrl);
+		}
+		if (rc) {
+			prerror("PLAT: Failed to open PNOR flash controller\n");
+			goto fail;
+		}
+
+		rc = flash_init(pnor_ctrl, &bl, NULL);
 	}
 
-	rc = flash_init(pnor_ctrl, &bl, NULL);
 	if (rc) {
 		prerror("PLAT: Failed to open init PNOR driver\n");
 		goto fail;
@@ -57,8 +67,12 @@ int pnor_init(void)
 		return 0;
 
  fail:
-	if (bl)
-		flash_exit(bl);
+	if (bl) {
+		if (do_mbox)
+			mbox_flash_exit(bl);
+		else
+			flash_exit(bl);
+	}
 	if (pnor_ctrl)
 		ast_sf_close(pnor_ctrl);
 
-- 
2.11.0



More information about the Skiboot mailing list