Skip to contentSkip to conversation

ast2400: SMC controllers

PATCH Superseded Cédric Le Goater 3 participants 14 messages Jun 27, 2016 – Jun 28, 2016

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover ast2400: SMC controllers

Hello,

The following adds support for the AST2400 SMC controllers. The device model does not implement all the HW features, linear addressing mode is underway, but it should be complete enough for the OpenBMC distro.

Code is based on Andrew's SCU model (v3) :

    https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg07042.html

Flash images can be grabbed here for testing :

https://openpower.xyz/job/openbmc-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/palmetto/flash-palmetto
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/palmetto.pnor

Changes Since v3:
- fixed sabrelite_init() to use drive_get_next()
- fixed typos
- fixed multiple error handling when setting properties
- fixed error logging
- added extra register definitions
- constantified a couple of routine arguments
- sorted out what was need for migration
- reworked the structures handling the IOs on the flash modules
- moved mapping in SOC initialization

Changes Since v2:

- switched to a realize ops
- moved the initialization of the flash modules under the palmetto platform
- changed mkstemp() path prefix

Changes Since v1:

- included Paolo's fix adding a "drive" property to the flash device model
- fixed drive definition in the test command line

Cédric Le Goater (4):
ast2400: add SMC controllers (FMC and SPI)
ast2400: add SPI flash slaves
ast2400: create SPI flash slaves
tests: add a m25p80 test

Paolo Bonzini (1):
m25p80: qdev-ify drive property

 hw/arm/ast2400.c                    |  39 ++-
 hw/arm/palmetto-bmc.c               |  31 +++
 hw/arm/sabrelite.c                  |  18 +-
 hw/arm/xilinx_zynq.c                |   8 +-
 hw/arm/xlnx-ep108.c                 |   9 +-
 hw/block/m25p80.c                   |  10 +-
 hw/microblaze/petalogix_ml605_mmu.c |   9 +-
 hw/ssi/Makefile.objs                |   1 +
 hw/ssi/aspeed_smc.c                 | 470 ++++++++++++++++++++++++++++++++++++
 include/hw/arm/ast2400.h            |   3 +
 include/hw/ssi/aspeed_smc.h         | 100 ++++++++
 tests/Makefile.include              |   2 +
 tests/m25p80-test.c                 | 242 +++++++++++++++++++
 13 files changed, 924 insertions(+), 18 deletions(-)
 create mode 100644 hw/ssi/aspeed_smc.c
 create mode 100644 include/hw/ssi/aspeed_smc.h
 create mode 100644 tests/m25p80-test.c
Signature · 1 line
2.1.4
#1 lore raw

PATCH v4 1/5 m25p80: qdev-ify drive property

From: Paolo Bonzini <[email protected]>

This allows specifying the property via -drive if=none and creating the flash device with -device.

[clg: added an extra fix for sabrelite_init()
keeping the test on flash_dev did not seem necessary. ]

---
 hw/arm/sabrelite.c                  | 18 ++++++++++++------
 hw/arm/xilinx_zynq.c                |  8 +++++++-
 hw/arm/xlnx-ep108.c                 |  9 ++++++++-
 hw/block/m25p80.c                   | 10 ++--------
 hw/microblaze/petalogix_ml605_mmu.c |  9 ++++++++-
 5 files changed, 37 insertions(+), 17 deletions(-)
hw/arm/sabrelite.c +12 -6
index 776c51e39869..4e7ac8cc4f4b 100644
@@ -86,13 +86,19 @@ static void sabrelite_init(MachineState *machine)
             spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev), "spi");
             if (spi_bus) {
                 DeviceState *flash_dev;
-
-                flash_dev = ssi_create_slave(spi_bus, "sst25vf016b");
-                if (flash_dev) {
-                    qemu_irq cs_line = qdev_get_gpio_in_named(flash_dev,
-                                                              SSI_GPIO_CS, 0);
-                    sysbus_connect_irq(SYS_BUS_DEVICE(spi_dev), 1, cs_line);
+                qemu_irq cs_line;
+                DriveInfo *dinfo = drive_get_next(IF_MTD);
+
+                flash_dev = ssi_create_slave_no_init(spi_bus, "sst25vf016b");
+                if (dinfo) {
+                    qdev_prop_set_drive(flash_dev, "drive",
+                                        blk_by_legacy_dinfo(dinfo),
+                                        &error_fatal);
                 }
+                qdev_init_nofail(flash_dev);
+
+                cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
+                sysbus_connect_irq(SYS_BUS_DEVICE(spi_dev), 1, cs_line);
             }
         }
     }
hw/arm/xilinx_zynq.c +7 -1
index aefebcfa6d8f..b0cabe2e4a67 100644
@@ -138,7 +138,13 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
         spi = (SSIBus *)qdev_get_child_bus(dev, bus_name);
 
         for (j = 0; j < num_ss; ++j) {
-            flash_dev = ssi_create_slave(spi, "n25q128");
+            DriveInfo *dinfo = drive_get_next(IF_MTD);
+            flash_dev = ssi_create_slave_no_init(spi, "n25q128");
+            if (dinfo) {
+                qdev_prop_set_drive(flash_dev, "drive",
+                                    blk_by_legacy_dinfo(dinfo), &error_fatal);
+            }
+            qdev_init_nofail(flash_dev);
 
             cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
             sysbus_connect_irq(busdev, i * num_ss + j + 1, cs_line);
hw/arm/xlnx-ep108.c +8 -1
index 34b464171266..4ec590a25db5 100644
@@ -88,12 +88,19 @@ static void xlnx_ep108_init(MachineState *machine)
         SSIBus *spi_bus;
         DeviceState *flash_dev;
         qemu_irq cs_line;
+        DriveInfo *dinfo = drive_get_next(IF_MTD);
         gchar *bus_name = g_strdup_printf("spi%d", i);
 
         spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(&s->soc), bus_name);
         g_free(bus_name);
 
-        flash_dev = ssi_create_slave(spi_bus, "sst25wf080");
+        flash_dev = ssi_create_slave_no_init(spi_bus, "sst25wf080");
+        if (dinfo) {
+            qdev_prop_set_drive(flash_dev, "drive", blk_by_legacy_dinfo(dinfo),
+                                &error_fatal);
+        }
+        qdev_init_nofail(flash_dev);
+
         cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
 
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->soc.spi[i]), 1, cs_line);
hw/block/m25p80.c +2 -8
index e6f6e23fb71d..7d1c34a1a2d1 100644
@@ -881,7 +881,6 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
 
 static void m25p80_realize(SSISlave *ss, Error **errp)
 {
-    DriveInfo *dinfo;
     Flash *s = M25P80(ss);
     M25P80Class *mc = M25P80_GET_CLASS(s);
 
@@ -890,14 +889,8 @@ static void m25p80_realize(SSISlave *ss, Error **errp)
     s->size = s->pi->sector_size * s->pi->n_sectors;
     s->dirty_page = -1;
 
-    /* FIXME use a qdev drive property instead of drive_get_next() */
-    dinfo = drive_get_next(IF_MTD);
-
-    if (dinfo) {
+    if (s->blk) {
         DB_PRINT_L(0, "Binding to IF_MTD drive\n");
-        s->blk = blk_by_legacy_dinfo(dinfo);
-        blk_attach_dev_nofail(s->blk, s);
-
         s->storage = blk_blockalign(s->blk, s->size);
 
         if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) {
@@ -925,6 +918,7 @@ static void m25p80_pre_save(void *opaque)
 
 static Property m25p80_properties[] = {
     DEFINE_PROP_UINT32("nonvolatile-cfg", Flash, nonvolatile_cfg, 0x8FFF),
+    DEFINE_PROP_DRIVE("drive", Flash, blk),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/microblaze/petalogix_ml605_mmu.c +8 -1
index 07527b677b37..4968bdbb2821 100644
@@ -191,9 +191,16 @@ petalogix_ml605_init(MachineState *machine)
         spi = (SSIBus *)qdev_get_child_bus(dev, "spi");
 
         for (i = 0; i < NUM_SPI_FLASHES; i++) {
+            DriveInfo *dinfo = drive_get_next(IF_MTD);
             qemu_irq cs_line;
 
-            dev = ssi_create_slave(spi, "n25q128");
+            dev = ssi_create_slave_no_init(spi, "n25q128");
+            if (dinfo) {
+                qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
+                                    &error_fatal);
+            }
+            qdev_init_nofail(dev);
+
             cs_line = qdev_get_gpio_in_named(dev, SSI_GPIO_CS, 0);
             sysbus_connect_irq(busdev, i+1, cs_line);
         }
Signature · 1 line
2.1.4
#2 lore raw

PATCH v4 2/5 ast2400: add SMC controllers (FMC and SPI)

In reply to Cédric Le Goater

The Aspeed AST2400 soc includes a static memory controller for the BMC which supports NOR, NAND and SPI flash memory modules. This controller has two modes : the SMC for the legacy interface which supports only one module and the FMC for the new interface which supports up to five modules. The AST2400 also includes a SPI only controller used for the host firmware, commonly called BIOS on Intel. It can be used in three mode : a SPI master, SPI slave and SPI pass-through

Below is the initial framework for the SMC controller (FMC mode only) and the SPI controller: the sysbus object, MMIO for registers configuration and controls. Each controller has a SPI bus and a configurable number of CS lines for SPI flash slaves.

The differences between the controllers are small, so they are abstracted using indirections on the register numbers.

Only SPI flash modules are supported.

---
Changes since v3:

- Fixed typos on CTRL
- Fixed multiple error handling when setting properties in ast2400_realize()
- Added error messages when max_slaves is exceeded
- Added definitions for R_INTR_CTRL register bits
- Added definitions for R_DMA_* registers
- Constantified a couple of routine arguments
- Sorted out what was need for migration (registers only a priori)

Changes since v2:

- Switched to a realize ops to be able to handle errors.

 hw/arm/ast2400.c            |  34 ++++-
 hw/ssi/Makefile.objs        |   1 +
 hw/ssi/aspeed_smc.c         | 326 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/ast2400.h    |   3 +
 include/hw/ssi/aspeed_smc.h |  79 +++++++++++
 5 files changed, 442 insertions(+), 1 deletion(-)
 create mode 100644 hw/ssi/aspeed_smc.c
 create mode 100644 include/hw/ssi/aspeed_smc.h
hw/arm/ast2400.c +33 -1
index b14a82fcdef1..b16ba2d0c516 100644
@@ -23,6 +23,9 @@
 #define AST2400_UART_5_BASE      0x00184000
 #define AST2400_IOMEM_SIZE       0x00200000
 #define AST2400_IOMEM_BASE       0x1E600000
+#define AST2400_SMC_BASE         AST2400_IOMEM_BASE /* Legacy SMC */
+#define AST2400_FMC_BASE         0X1E620000
+#define AST2400_SPI_BASE         0X1E630000
 #define AST2400_VIC_BASE         0x1E6C0000
 #define AST2400_SCU_BASE         0x1E6E2000
 #define AST2400_TIMER_BASE       0x1E782000
@@ -85,13 +88,21 @@ static void ast2400_init(Object *obj)
                               "hw-strap1", &error_abort);
     object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu),
                               "hw-strap2", &error_abort);
+
+    object_initialize(&s->smc, sizeof(s->smc), "aspeed.smc.fmc");
+    object_property_add_child(obj, "smc", OBJECT(&s->smc), NULL);
+    qdev_set_parent_bus(DEVICE(&s->smc), sysbus_get_default());
+
+    object_initialize(&s->spi, sizeof(s->spi), "aspeed.smc.spi");
+    object_property_add_child(obj, "spi", OBJECT(&s->spi), NULL);
+    qdev_set_parent_bus(DEVICE(&s->spi), sysbus_get_default());
 }
 
 static void ast2400_realize(DeviceState *dev, Error **errp)
 {
     int i;
     AST2400State *s = AST2400(dev);
-    Error *err = NULL;
+    Error *err = NULL, *local_err = NULL;
 
     /* IO space */
     memory_region_init_io(&s->iomem, NULL, &ast2400_io_ops, NULL,
@@ -147,6 +158,27 @@ static void ast2400_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, AST2400_I2C_BASE);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0,
                        qdev_get_gpio_in(DEVICE(&s->vic), 12));
+
+    /* SMC */
+    object_property_set_int(OBJECT(&s->smc), 1, "num-cs", &err);
+    object_property_set_bool(OBJECT(&s->smc), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->smc), 0, AST2400_FMC_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->smc), 0,
+                       qdev_get_gpio_in(DEVICE(&s->vic), 19));
+
+    /* SPI */
+    object_property_set_int(OBJECT(&s->spi), 1, "num-cs", &err);
+    object_property_set_bool(OBJECT(&s->spi), true, "realized", &local_err);
+    error_propagate(&err, local_err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi), 0, AST2400_SPI_BASE);
 }
 
 static void ast2400_class_init(ObjectClass *oc, void *data)
hw/ssi/Makefile.objs +1 -0
index fcbb79ef0185..c79a8dcd86a9 100644
@@ -2,6 +2,7 @@ common-obj-$(CONFIG_PL022) += pl022.o
 common-obj-$(CONFIG_SSI) += ssi.o
 common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o
 common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o
+common-obj-$(CONFIG_ASPEED_SOC) += aspeed_smc.o
 
 obj-$(CONFIG_OMAP) += omap_spi.o
 obj-$(CONFIG_IMX) += imx_spi.o
hw/ssi/aspeed_smc.c new file +326 -0

326 lines not on this page · raw message

include/hw/arm/ast2400.h +3 -0
index f1a64fd3893d..7833bc716cd8 100644
@@ -17,6 +17,7 @@
 #include "hw/misc/aspeed_scu.h"
 #include "hw/timer/aspeed_timer.h"
 #include "hw/i2c/aspeed_i2c.h"
+#include "hw/ssi/aspeed_smc.h"
 
 typedef struct AST2400State {
     /*< private >*/
@@ -29,6 +30,8 @@ typedef struct AST2400State {
     AspeedTimerCtrlState timerctrl;
     AspeedI2CState i2c;
     AspeedSCUState scu;
+    AspeedSMCState smc;
+    AspeedSMCState spi;
 } AST2400State;
 
 #define TYPE_AST2400 "ast2400"
include/hw/ssi/aspeed_smc.h new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
2.1.4
#3 lore raw

PATCH v4 3/5 ast2400: add SPI flash slaves

In reply to Cédric Le Goater

Each controller on the ast2400 has a memory range on which it maps its flash module slaves. Each slave is assigned a memory segment for its mapping that can be changed at bootime with the Segment Address Register. This is not supported in the current implementation so we are using the defaults provided by the specs.

Each SPI flash slave can then be accessed in two modes: Command and User. When in User mode, accesses to the memory segment of the slaves are translated in SPI transfers. When in Command mode, the HW generates the SPI commands automatically and the memory segment is accessed as if doing a MMIO. Other SPI controllers call that mode linear addressing mode.

For this purpose, we are adding below each crontoller an array of structs gathering for each SPI flash module, a segment rank, a MemoryRegion to handle the memory accesses and the associated SPI slave device, which should be a m25p80.

Only the User mode is supported for now but we are preparing ground for the Command mode. The framework is sufficient to support Linux.

---

Changes since v3:

- Fixed error logging
- Constantified a couple of routine arguments
- Sorted out what was need for migration (nothing apriori, but flash module object will need some care)
- Reworked the structures handling the IOs on the flash modules :
. Replaced the SysBusDevice object with a simple struct . Added a global memory region for the flash memory address space . Added sub regions for each segment
. Moved mapping in SOC initialization
- Rephrased commit log

 hw/arm/ast2400.c            |   5 ++
 hw/ssi/aspeed_smc.c         | 150 +++++++++++++++++++++++++++++++++++++++++++-
 include/hw/ssi/aspeed_smc.h |  21 +++++++
 3 files changed, 173 insertions(+), 3 deletions(-)
hw/arm/ast2400.c +5 -0
index b16ba2d0c516..9c30b45f87a9 100644
@@ -31,6 +31,9 @@
 #define AST2400_TIMER_BASE       0x1E782000
 #define AST2400_I2C_BASE         0x1E78A000
 
+#define AST2400_FMC_FLASH_BASE   0x20000000
+#define AST2400_SPI_FLASH_BASE   0x30000000
+
 #define AST2400_A0_SILICON_REV   0x02000303
 
 static const int uart_irqs[] = { 9, 32, 33, 34, 10 };
@@ -167,6 +170,7 @@ static void ast2400_realize(DeviceState *dev, Error **errp)
         return;
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->smc), 0, AST2400_FMC_BASE);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->smc), 1, AST2400_FMC_FLASH_BASE);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->smc), 0,
                        qdev_get_gpio_in(DEVICE(&s->vic), 19));
 
@@ -179,6 +183,7 @@ static void ast2400_realize(DeviceState *dev, Error **errp)
         return;
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi), 0, AST2400_SPI_BASE);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi), 1, AST2400_SPI_FLASH_BASE);
 }
 
 static void ast2400_class_init(ObjectClass *oc, void *data)
hw/ssi/aspeed_smc.c +147 -3

172 lines not on this page · raw message

include/hw/ssi/aspeed_smc.h +21 -0
index c4a4960cd880..def3b4507e75 100644
@@ -27,6 +27,12 @@
 
 #include "hw/ssi/ssi.h"
 
+typedef struct AspeedSegments {
+    hwaddr addr;
+    uint32_t size;
+} AspeedSegments;
+
+struct AspeedSMCState;
 typedef struct AspeedSMCController {
     const char *name;
     uint8_t r_conf;
@@ -35,8 +41,20 @@ typedef struct AspeedSMCController {
     uint8_t r_timings;
     uint8_t conf_enable_w0;
     uint8_t max_slaves;
+    const AspeedSegments *segments;
+    uint32_t mapping_window_size;
 } AspeedSMCController;
 
+typedef struct AspeedSMCFlash {
+    const struct AspeedSMCState *controller;
+
+    uint8_t id;
+    uint32_t size;
+
+    MemoryRegion mmio;
+    DeviceState *flash;
+} AspeedSMCFlash;
+
 #define TYPE_ASPEED_SMC "aspeed.smc"
 #define ASPEED_SMC(obj) OBJECT_CHECK(AspeedSMCState, (obj), TYPE_ASPEED_SMC)
 #define ASPEED_SMC_CLASS(klass) \
@@ -57,6 +75,7 @@ typedef struct AspeedSMCState {
     const AspeedSMCController *ctrl;
 
     MemoryRegion mmio;
+    MemoryRegion mmio_flash;
 
     qemu_irq irq;
     int irqline;
@@ -74,6 +93,8 @@ typedef struct AspeedSMCState {
     uint8_t r_ctrl0;
     uint8_t r_timings;
     uint8_t conf_enable_w0;
+
+    AspeedSMCFlash *flashes;
 } AspeedSMCState;
 
 #endif /* ASPEED_SMC_H */
Signature · 1 line
2.1.4
#4 lore raw

PATCH v4 4/5 ast2400: create SPI flash slaves

In reply to Cédric Le Goater

A set of SPI flash slaves is attached under the flash controllers of the palmetto platform. "n25q256a" flash modules are used for the BMC and "mx25l25635e" for the host. These types are common in the OpenPower ecosystem.

---

Changes since v3 :

- moved memory mapping to platform initialization

Changes since v2 :

- moved the initialization of the flash modules under the palmetto platform

 hw/arm/palmetto-bmc.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
hw/arm/palmetto-bmc.c +31 -0
index b8eed21348d8..54e29a865d88 100644
@@ -18,6 +18,8 @@
 #include "hw/arm/ast2400.h"
 #include "hw/boards.h"
 #include "qemu/log.h"
+#include "sysemu/block-backend.h"
+#include "sysemu/blockdev.h"
 
 static struct arm_boot_info palmetto_bmc_binfo = {
     .loader_start = AST2400_SDRAM_BASE,
@@ -30,6 +32,32 @@ typedef struct PalmettoBMCState {
     MemoryRegion ram;
 } PalmettoBMCState;
 
+static void palmetto_bmc_init_flashes(AspeedSMCState *s, const char *flashtype,
+                                      Error **errp)
+{
+    int i ;
+
+    for (i = 0; i < s->num_cs; ++i) {
+        AspeedSMCFlash *fl = &s->flashes[i];
+        DriveInfo *dinfo = drive_get_next(IF_MTD);
+        qemu_irq cs_line;
+
+        /*
+         * FIXME: check that we are not using a flash module exceeding
+         * the controller segment size
+         */
+        fl->flash = ssi_create_slave_no_init(s->spi, flashtype);
+        if (dinfo) {
+            qdev_prop_set_drive(fl->flash, "drive", blk_by_legacy_dinfo(dinfo),
+                                errp);
+        }
+        qdev_init_nofail(fl->flash);
+
+        cs_line = qdev_get_gpio_in_named(fl->flash, SSI_GPIO_CS, 0);
+        sysbus_connect_irq(SYS_BUS_DEVICE(s), i + 1, cs_line);
+    }
+}
+
 static void palmetto_bmc_init(MachineState *machine)
 {
     PalmettoBMCState *bmc;
@@ -49,6 +77,9 @@ static void palmetto_bmc_init(MachineState *machine)
     object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
                              &error_abort);
 
+    palmetto_bmc_init_flashes(&bmc->soc.smc, "n25q256a", &error_abort);
+    palmetto_bmc_init_flashes(&bmc->soc.spi, "mx25l25635e", &error_abort);
+
     palmetto_bmc_binfo.kernel_filename = machine->kernel_filename;
     palmetto_bmc_binfo.initrd_filename = machine->initrd_filename;
     palmetto_bmc_binfo.kernel_cmdline = machine->kernel_cmdline;
Signature · 1 line
2.1.4
#5 lore raw

PATCH v4 5/5 tests: add a m25p80 test

In reply to Cédric Le Goater

This test uses the palmetto platform and the AST2400 SPI controller to test the m25p80 flash module device model. The flash model is defined by the platform (n25q256a) and it would be nice to find way to control it, using a property probably.

---

Peter,

This is failing miserably on a ppc64/be host ... The addresses reaching the flash memory region are in the wrong endian. Should I be using qtest_big_endian() ?

Changes since v2:

- changed mkstemp() path prefix

Changes since v1:

- fixed guest args to use -drive and not -mtdblock

 tests/Makefile.include |   2 +
 tests/m25p80-test.c    | 242 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 244 insertions(+)
 create mode 100644 tests/m25p80-test.c
tests/Makefile.include +2 -0
index fd2dba49a741..c64bc2097e44 100644
@@ -252,6 +252,7 @@ gcov-files-sparc-y += hw/timer/m48t59.c
 gcov-files-sparc64-y += hw/timer/m48t59.c
 check-qtest-arm-y = tests/tmp105-test$(EXESUF)
 check-qtest-arm-y = tests/ds1338-test$(EXESUF)
+check-qtest-arm-y = tests/m25p80-test$(EXESUF)
 gcov-files-arm-y += hw/misc/tmp105.c
 check-qtest-arm-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
@@ -568,6 +569,7 @@ tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \
 tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y)
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
 tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y)
+tests/m25p80-test$(EXESUF): tests/m25p80-test.o
 tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
 tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y)
 tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y)
tests/m25p80-test.c new file +242 -0

242 lines not on this page · raw message

Signature · 1 line
2.1.4
#6 lore raw

Re: [Qemu-arm] [PATCH v4 5/5] tests: add a m25p80 test

Quoted 7 lines · Cédric Le Goater

This test uses the palmetto platform and the AST2400 SPI controller to test the m25p80 flash module device model. The flash model is defined by the platform (n25q256a) and it would be nice to find way to control it, using a property probably.

Quoted 7 lines

---

Peter,

This is failing miserably on a ppc64/be host ... The addresses reaching the flash memory region are in the wrong endian. Should I be using qtest_big_endian() ?

Here is a possible solution tested on a fedora23/ppc64.

Thanks,

C.

From: Cédric Le Goater <[email protected]>
Subject: [PATCH] tests: fix m25p80 test to run on a big endian host
Date: Mon, 27 Jun 2016 23:31:36 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When running on a big endian host, the data read from or written to the flash module memory mapping also needs byte-swapping.

---
 tests/m25p80-test.c |   20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
tests/m25p80-test.c +15 -5
Index: qemu-ast2400-mainline.git/tests/m25p80-test.c
===================================================================
@@ -58,6 +58,16 @@ enum {
 
 #define PAGE_SIZE           256
 
+static inline uint32_t to_flash(uint32_t data)
+{
+    return bswap32(data);
+}
+
+static inline uint32_t from_flash(uint32_t data)
+{
+    return bswap32(data);
+}
+
 static void spi_conf(uint32_t value)
 {
     uint32_t conf = readl(AST2400_FMC_BASE + R_CONF);
@@ -109,11 +119,11 @@ static void read_page(uint32_t addr, uin
 
     writeb(AST2400_FLASH_BASE, EN_4BYTE_ADDR);
     writeb(AST2400_FLASH_BASE, READ);
-    writel(AST2400_FLASH_BASE, cpu_to_be32(addr));
+    writel(AST2400_FLASH_BASE, to_flash(addr));
 
     /* Continuous read are supported */
     for (i = 0; i < PAGE_SIZE / 4; i++) {
-        page[i] = be32_to_cpu(readl(AST2400_FLASH_BASE));
+        page[i] = from_flash(readl(AST2400_FLASH_BASE));
     }
     spi_ctrl_stop_user();
 }
@@ -130,7 +140,7 @@ static void test_erase_sector(void)
     writeb(AST2400_FLASH_BASE, WREN);
     writeb(AST2400_FLASH_BASE, EN_4BYTE_ADDR);
     writeb(AST2400_FLASH_BASE, ERASE_SECTOR);
-    writel(AST2400_FLASH_BASE, cpu_to_be32(some_page_addr));
+    writel(AST2400_FLASH_BASE, to_flash(some_page_addr));
     spi_ctrl_stop_user();
 
     /* Previous page should be full of zeroes as backend is not
@@ -186,11 +196,11 @@ static void test_write_page(void)
     spi_ctrl_start_user();
     writeb(AST2400_FLASH_BASE, EN_4BYTE_ADDR);
     writeb(AST2400_FLASH_BASE, PP);
-    writel(AST2400_FLASH_BASE, cpu_to_be32(my_page_addr));
+    writel(AST2400_FLASH_BASE, to_flash(my_page_addr));
 
     /* Fill the page with its own addresses */
     for (i = 0; i < PAGE_SIZE / 4; i++) {
-        writel(AST2400_FLASH_BASE, cpu_to_be32(my_page_addr + i * 4));
+        writel(AST2400_FLASH_BASE, to_flash(my_page_addr + i * 4));
     }
     spi_ctrl_stop_user();
 
#7 lore raw

Re: [Qemu-arm] [PATCH v4 5/5] tests: add a m25p80 test

In reply to Cédric Le Goater
Quoted 2 lines · Cédric Le Goater

check-qtest-arm-y = tests/ds1338-test$(EXESUF)
+check-qtest-arm-y = tests/m25p80-test$(EXESUF)

This should be a "+=".

Paolo

Quoted 2 lines

gcov-files-arm-y += hw/misc/tmp105.c check-qtest-arm-y += tests/virtio-blk-test$(EXESUF)

#8 lore raw

Re: [Qemu-devel] [PATCH v4 5/5] tests: add a m25p80 test

Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Cédric Le Goater

check-qtest-arm-y = tests/ds1338-test$(EXESUF)
+check-qtest-arm-y = tests/m25p80-test$(EXESUF)

This should be a "+=".

OK. I will fix the above line also then :

	check-qtest-arm-y = tests/tmp105-test$(EXESUF)
	check-qtest-arm-y = tests/ds1338-test$(EXESUF)

Thanks,

C.

Quoted 5 lines

Paolo

Quoted 2 lines

gcov-files-arm-y += hw/misc/tmp105.c check-qtest-arm-y += tests/virtio-blk-test$(EXESUF)

#9 lore raw

Re: [Qemu-devel] [PATCH v4 5/5] tests: add a m25p80 test

Quoted 7 lines · Cédric Le Goater
Quoted 6 lines · Paolo Bonzini
Quoted 2 lines · Cédric Le Goater

check-qtest-arm-y = tests/ds1338-test$(EXESUF)
+check-qtest-arm-y = tests/m25p80-test$(EXESUF)

Quoted 6 lines
Quoted 1 line

This should be a "+=".

OK. I will fix the above line also then :

        check-qtest-arm-y = tests/tmp105-test$(EXESUF)
        check-qtest-arm-y = tests/ds1338-test$(EXESUF)

That's fixed in master.

thanks
-- PMM

#10 lore raw

Re: [Qemu-arm] [PATCH v4 5/5] tests: add a m25p80 test

Quoted 8 lines · Peter Maydell
Quoted 7 lines · Cédric Le Goater
Quoted 6 lines · Paolo Bonzini
Quoted 2 lines · Cédric Le Goater

check-qtest-arm-y = tests/ds1338-test$(EXESUF)
+check-qtest-arm-y = tests/m25p80-test$(EXESUF)

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

This should be a "+=".

OK. I will fix the above line also then :

        check-qtest-arm-y = tests/tmp105-test$(EXESUF)
        check-qtest-arm-y = tests/ds1338-test$(EXESUF)

That's fixed in master.

OK. The patchset needs a rebase now that Marcin's patches are in.

Thanks,

C.

#11 lore raw

Re: [Qemu-arm] [PATCH v4 5/5] tests: add a m25p80 test

----- Original Message -----

Quoted 19 lines

From: "Cédric Le Goater" <[email protected]>
To: "Peter Maydell" <[email protected]>
Cc: "Paolo Bonzini" <[email protected]>, "Peter Crosthwaite" <[email protected]>, "Kevin Wolf" <[email protected]>, "Andrew Jeffery" <[email protected]>, "QEMU Developers" <[email protected]>, "Markus Armbruster" <[email protected]>, "qemu-arm" <[email protected]>
Sent: Tuesday, June 28, 2016 10:40:15 AM
Subject: Re: [PATCH v4 5/5] tests: add a m25p80 test

Quoted 10 lines · Peter Maydell
Quoted 9 lines · Cédric Le Goater
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Cédric Le Goater

check-qtest-arm-y = tests/ds1338-test$(EXESUF)
+check-qtest-arm-y = tests/m25p80-test$(EXESUF)

This should be a "+=".

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

OK. I will fix the above line also then :

        check-qtest-arm-y = tests/tmp105-test$(EXESUF)
        check-qtest-arm-y = tests/ds1338-test$(EXESUF)

That's fixed in master.

OK. The patchset needs a rebase now that Marcin's patches are in.

Please include my patches too, since otherwise the test is broken.

Thanks,

Paolo

#12 lore raw

Re: [Qemu-arm] [PATCH v4 5/5] tests: add a m25p80 test

In reply to Cédric Le Goater
Quoted 1 line · Cédric Le Goater

+ args = g_strdup_printf("-M 256 -machine palmetto-bmc "

Also you want "-m 256". This is not failing because the "256" machine type is overwritten by "palmetto-bmc".

Paolo

Quoted 4 lines
tests/m25p80-test.c new file +4 -0
+                           "-drive file=%s,format=raw,if=mtd",
+                           tmp_path);
+    qtest_start(args);
+
#13 lore raw

Re: [Qemu-arm] [PATCH v4 5/5] tests: add a m25p80 test

Quoted 7 lines · Paolo Bonzini
Quoted 1 line · Cédric Le Goater

+ args = g_strdup_printf("-M 256 -machine palmetto-bmc "

Also you want "-m 256". This is not failing because the "256" machine type is overwritten by "palmetto-bmc".

I should have seen these earlier ...

Thanks,

C.

Quoted 6 lines

Paolo

Quoted 4 lines
tests/m25p80-test.c new file +4 -0
+                           "-drive file=%s,format=raw,if=mtd",
+                           tmp_path);
+    qtest_start(args);
+