[PATCH qemu 04/12] m25p80: add a get storage routine

Cédric Le Goater clg at kaod.org
Mon May 30 07:19:57 AEST 2016


Some SPI controllers, the Aspeed AST2400 for instance, have a mode in
which accessing the flash content is no different than doing an
MMIO. The controller generates all the necessary commands to load (or
store) data in memory.

To emulate such a behavior, we need to map the underlying storage of
the m25p80 flash model to a memory region. This is what this patch
proposes by adding a m25p80_get_storage() routine which can later be
used to handle IOs in a memory region.

It is sufficient to support read only accesses. Handling write
accesses would demand more changes to the m25p80 flash model.

Signed-off-by: Cédric Le Goater <clg at kaod.org>
---
 hw/block/m25p80.c        | 9 +++++++++
 include/hw/block/flash.h | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 906b71257ecf..c4aee22eae88 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -27,6 +27,7 @@
 #include "sysemu/blockdev.h"
 #include "hw/ssi/ssi.h"
 #include "qemu/bitops.h"
+#include "hw/block/flash.h"
 
 #ifndef M25P80_ERR_DEBUG
 #define M25P80_ERR_DEBUG 0
@@ -1003,3 +1004,11 @@ static void m25p80_register_types(void)
 }
 
 type_init(m25p80_register_types)
+
+uint8_t *m25p80_get_storage(DeviceState *dev, uint32_t *size)
+{
+    Flash *s = M25P80(dev);
+
+    *size = s->size;
+    return s->storage;
+}
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 50ccbbcf1352..845c4c9ac28f 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -61,4 +61,6 @@ uint8_t ecc_digest(ECCState *s, uint8_t sample);
 void ecc_reset(ECCState *s);
 extern VMStateDescription vmstate_ecc_state;
 
+extern uint8_t *m25p80_get_storage(DeviceState *dev, uint32_t *size);
+
 #endif
-- 
2.1.4



More information about the openbmc mailing list