All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
@ 2019-02-18 12:56 Markus Armbruster
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02 Markus Armbruster
                   ` (20 more replies)
  0 siblings, 21 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

Alex Bennée posted this patch to address an XXX comment in
pflash_cfi01_realize() the other day:

Subject: [PATCH v2] hw/block: report when pflash backing file isn't aligned
Message-Id: <20190215122808.22301-1-alex.bennee@linaro.org>
https://lists.nongnu.org/archive/html/qemu-devel/2019-02/msg04166.html

Review led me to look into its callers.  Most of them are pleasantly
boring: they create flash memory of some fixed size at some fixed
address.  A few are more creative, and some of the creative ones look
quite broken to me.  Fix them, and clean up some along the way.

Markus Armbruster (10):
  pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  pflash: Macro PFLASH_BUG() is used just once, expand
  hw: Use CFI_PFLASH0{1,2} and TYPE_CFI_PFLASH0{1,2}
  sam460ex: Don't size flash memory to match backing image
  ppc405_boards: Don't size flash memory to match backing image
  r2d: Flash memory creation is confused about size, mark FIXME
  mips_malta: Clean up definition of flash memory size somewhat
  pflash: Clean up after commit 368a354f02b part 1
  pflash: Clean up after commit 368a354f02b part 2
  hw/arm hw/xtensa: De-duplicate pflash creation code some

 hw/arm/collie.c                          |   9 +-
 hw/arm/digic_boards.c                    |   3 +-
 hw/arm/gumstix.c                         |   8 +-
 hw/arm/mainstone.c                       |   4 +-
 hw/arm/musicpal.c                        |   8 +-
 hw/arm/omap_sx1.c                        |   8 +-
 hw/arm/versatilepb.c                     |   3 +-
 hw/arm/vexpress.c                        |  30 ++----
 hw/arm/virt.c                            |  27 ++---
 hw/arm/xilinx_zynq.c                     |   5 +-
 hw/arm/z2.c                              |   5 +-
 hw/block/pflash_cfi01.c                  | 120 ++++++++++++-----------
 hw/block/pflash_cfi02.c                  |  69 ++++++-------
 hw/i386/pc_sysfw.c                       |  10 +-
 hw/lm32/lm32_boards.c                    |   8 +-
 hw/lm32/milkymist.c                      |   4 +-
 hw/microblaze/petalogix_ml605_mmu.c      |   5 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c |   4 +-
 hw/mips/mips_malta.c                     |  15 ++-
 hw/mips/mips_r4k.c                       |   4 +-
 hw/ppc/ppc405_boards.c                   |  59 ++++-------
 hw/ppc/sam460ex.c                        |  23 ++---
 hw/ppc/virtex_ml507.c                    |   4 +-
 hw/sh4/r2d.c                             |  11 ++-
 hw/xtensa/xtfpga.c                       |  26 +++--
 include/hw/block/flash.h                 |  65 +++++++-----
 26 files changed, 258 insertions(+), 279 deletions(-)

-- 
2.17.2

^ permalink raw reply	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-18 16:40   ` Laszlo Ersek
                     ` (2 more replies)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand Markus Armbruster
                   ` (19 subsequent siblings)
  20 siblings, 3 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

flash.h's incomplete struct pflash_t is completed both in
pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
incompatible.  This can hide type errors, such as passing a pflash_t
created with pflash_cfi02_register() to pflash_cfi01_get_memory().

Furthermore, POSIX reserves typedef names ending with _t.

Rename the two structs to PFlashCFI01 and PFlashCFI02.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/arm/vexpress.c        |  8 ++--
 hw/block/pflash_cfi01.c  | 87 +++++++++++++++++++++-------------------
 hw/block/pflash_cfi02.c  | 67 ++++++++++++++++---------------
 hw/i386/pc_sysfw.c       |  2 +-
 hw/mips/mips_malta.c     |  2 +-
 hw/xtensa/xtfpga.c       | 10 ++---
 include/hw/block/flash.h | 53 ++++++++++++++----------
 7 files changed, 122 insertions(+), 107 deletions(-)

diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index c02d18ee61..ed46d2e730 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -512,8 +512,8 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
 /* Open code a private version of pflash registration since we
  * need to set non-default device width for VExpress platform.
  */
-static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
-                                          DriveInfo *di)
+static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
+                                             DriveInfo *di)
 {
     DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
 
@@ -536,7 +536,7 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
     qdev_init_nofail(dev);
 
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
-    return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
+    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
 }
 
 static void vexpress_common_init(MachineState *machine)
@@ -548,7 +548,7 @@ static void vexpress_common_init(MachineState *machine)
     qemu_irq pic[64];
     uint32_t sys_id;
     DriveInfo *dinfo;
-    pflash_t *pflash0;
+    PFlashCFI01 *pflash0;
     I2CBus *i2c;
     ram_addr_t vram_size, sram_size;
     MemoryRegion *sysmem = get_system_memory();
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index bffb4c40e7..9efa7aa9af 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -65,12 +65,13 @@ do {                                                        \
 #define DPRINTF(fmt, ...) do { } while (0)
 #endif
 
-#define CFI_PFLASH01(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01)
+#define CFI_PFLASH01(obj) \
+    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
 
 #define PFLASH_BE          0
 #define PFLASH_SECURE      1
 
-struct pflash_t {
+struct PFlashCFI01 {
     /*< private >*/
     SysBusDevice parent_obj;
     /*< public >*/
@@ -109,17 +110,17 @@ static const VMStateDescription vmstate_pflash = {
     .minimum_version_id = 1,
     .post_load = pflash_post_load,
     .fields = (VMStateField[]) {
-        VMSTATE_UINT8(wcycle, pflash_t),
-        VMSTATE_UINT8(cmd, pflash_t),
-        VMSTATE_UINT8(status, pflash_t),
-        VMSTATE_UINT64(counter, pflash_t),
+        VMSTATE_UINT8(wcycle, PFlashCFI01),
+        VMSTATE_UINT8(cmd, PFlashCFI01),
+        VMSTATE_UINT8(status, PFlashCFI01),
+        VMSTATE_UINT64(counter, PFlashCFI01),
         VMSTATE_END_OF_LIST()
     }
 };
 
 static void pflash_timer (void *opaque)
 {
-    pflash_t *pfl = opaque;
+    PFlashCFI01 *pfl = opaque;
 
     trace_pflash_timer_expired(pfl->cmd);
     /* Reset flash */
@@ -133,7 +134,7 @@ static void pflash_timer (void *opaque)
  * If this code is called we know we have a device_width set for
  * this flash.
  */
-static uint32_t pflash_cfi_query(pflash_t *pfl, hwaddr offset)
+static uint32_t pflash_cfi_query(PFlashCFI01 *pfl, hwaddr offset)
 {
     int i;
     uint32_t resp = 0;
@@ -193,7 +194,7 @@ static uint32_t pflash_cfi_query(pflash_t *pfl, hwaddr offset)
 
 
 /* Perform a device id query based on the bank width of the flash. */
-static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)
+static uint32_t pflash_devid_query(PFlashCFI01 *pfl, hwaddr offset)
 {
     int i;
     uint32_t resp;
@@ -241,7 +242,7 @@ static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)
     return resp;
 }
 
-static uint32_t pflash_data_read(pflash_t *pfl, hwaddr offset,
+static uint32_t pflash_data_read(PFlashCFI01 *pfl, hwaddr offset,
                                  int width, int be)
 {
     uint8_t *p;
@@ -284,7 +285,7 @@ static uint32_t pflash_data_read(pflash_t *pfl, hwaddr offset,
     return ret;
 }
 
-static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,
                              int width, int be)
 {
     hwaddr boff;
@@ -398,7 +399,7 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
 }
 
 /* update flash content on disk */
-static void pflash_update(pflash_t *pfl, int offset,
+static void pflash_update(PFlashCFI01 *pfl, int offset,
                           int size)
 {
     int offset_end;
@@ -412,7 +413,7 @@ static void pflash_update(pflash_t *pfl, int offset,
     }
 }
 
-static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
+static inline void pflash_data_write(PFlashCFI01 *pfl, hwaddr offset,
                                      uint32_t value, int width, int be)
 {
     uint8_t *p = pfl->storage;
@@ -448,7 +449,7 @@ static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
 
 }
 
-static void pflash_write(pflash_t *pfl, hwaddr offset,
+static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
                          uint32_t value, int width, int be)
 {
     uint8_t *p;
@@ -654,7 +655,7 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,
 static MemTxResult pflash_mem_read_with_attrs(void *opaque, hwaddr addr, uint64_t *value,
                                               unsigned len, MemTxAttrs attrs)
 {
-    pflash_t *pfl = opaque;
+    PFlashCFI01 *pfl = opaque;
     bool be = !!(pfl->features & (1 << PFLASH_BE));
 
     if ((pfl->features & (1 << PFLASH_SECURE)) && !attrs.secure) {
@@ -668,7 +669,7 @@ static MemTxResult pflash_mem_read_with_attrs(void *opaque, hwaddr addr, uint64_
 static MemTxResult pflash_mem_write_with_attrs(void *opaque, hwaddr addr, uint64_t value,
                                                unsigned len, MemTxAttrs attrs)
 {
-    pflash_t *pfl = opaque;
+    PFlashCFI01 *pfl = opaque;
     bool be = !!(pfl->features & (1 << PFLASH_BE));
 
     if ((pfl->features & (1 << PFLASH_SECURE)) && !attrs.secure) {
@@ -687,7 +688,7 @@ static const MemoryRegionOps pflash_cfi01_ops = {
 
 static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
 {
-    pflash_t *pfl = CFI_PFLASH01(dev);
+    PFlashCFI01 *pfl = CFI_PFLASH01(dev);
     uint64_t total_len;
     int ret;
     uint64_t blocks_per_device, sector_len_per_device, device_len;
@@ -864,14 +865,14 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
 }
 
 static Property pflash_cfi01_properties[] = {
-    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
+    DEFINE_PROP_DRIVE("drive", PFlashCFI01, blk),
     /* num-blocks is the number of blocks actually visible to the guest,
      * ie the total size of the device divided by the sector length.
      * If we're emulating flash devices wired in parallel the actual
      * number of blocks per indvidual device will differ.
      */
-    DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
-    DEFINE_PROP_UINT64("sector-length", struct pflash_t, sector_len, 0),
+    DEFINE_PROP_UINT32("num-blocks", PFlashCFI01, nb_blocs, 0),
+    DEFINE_PROP_UINT64("sector-length", PFlashCFI01, sector_len, 0),
     /* width here is the overall width of this QEMU device in bytes.
      * The QEMU device may be emulating a number of flash devices
      * wired up in parallel; the width of each individual flash
@@ -888,17 +889,17 @@ static Property pflash_cfi01_properties[] = {
      * 16 bit devices making up a 32 bit wide QEMU device. This
      * is deprecated for new uses of this device.
      */
-    DEFINE_PROP_UINT8("width", struct pflash_t, bank_width, 0),
-    DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0),
-    DEFINE_PROP_UINT8("max-device-width", struct pflash_t, max_device_width, 0),
-    DEFINE_PROP_BIT("big-endian", struct pflash_t, features, PFLASH_BE, 0),
-    DEFINE_PROP_BIT("secure", struct pflash_t, features, PFLASH_SECURE, 0),
-    DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0),
-    DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
-    DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
-    DEFINE_PROP_UINT16("id3", struct pflash_t, ident3, 0),
-    DEFINE_PROP_STRING("name", struct pflash_t, name),
-    DEFINE_PROP_BOOL("old-multiple-chip-handling", struct pflash_t,
+    DEFINE_PROP_UINT8("width", PFlashCFI01, bank_width, 0),
+    DEFINE_PROP_UINT8("device-width", PFlashCFI01, device_width, 0),
+    DEFINE_PROP_UINT8("max-device-width", PFlashCFI01, max_device_width, 0),
+    DEFINE_PROP_BIT("big-endian", PFlashCFI01, features, PFLASH_BE, 0),
+    DEFINE_PROP_BIT("secure", PFlashCFI01, features, PFLASH_SECURE, 0),
+    DEFINE_PROP_UINT16("id0", PFlashCFI01, ident0, 0),
+    DEFINE_PROP_UINT16("id1", PFlashCFI01, ident1, 0),
+    DEFINE_PROP_UINT16("id2", PFlashCFI01, ident2, 0),
+    DEFINE_PROP_UINT16("id3", PFlashCFI01, ident3, 0),
+    DEFINE_PROP_STRING("name", PFlashCFI01, name),
+    DEFINE_PROP_BOOL("old-multiple-chip-handling", PFlashCFI01,
                      old_multiple_chip_handling, false),
     DEFINE_PROP_END_OF_LIST(),
 };
@@ -917,7 +918,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data)
 static const TypeInfo pflash_cfi01_info = {
     .name           = TYPE_CFI_PFLASH01,
     .parent         = TYPE_SYS_BUS_DEVICE,
-    .instance_size  = sizeof(struct pflash_t),
+    .instance_size  = sizeof(PFlashCFI01),
     .class_init     = pflash_cfi01_class_init,
 };
 
@@ -928,13 +929,15 @@ static void pflash_cfi01_register_types(void)
 
 type_init(pflash_cfi01_register_types)
 
-pflash_t *pflash_cfi01_register(hwaddr base,
-                                DeviceState *qdev, const char *name,
-                                hwaddr size,
-                                BlockBackend *blk,
-                                uint32_t sector_len, int nb_blocs,
-                                int bank_width, uint16_t id0, uint16_t id1,
-                                uint16_t id2, uint16_t id3, int be)
+PFlashCFI01 *pflash_cfi01_register(hwaddr base,
+                                   DeviceState *qdev, const char *name,
+                                   hwaddr size,
+                                   BlockBackend *blk,
+                                   uint32_t sector_len, int nb_blocs,
+                                   int bank_width,
+                                   uint16_t id0, uint16_t id1,
+                                   uint16_t id2, uint16_t id3,
+                                   int be)
 {
     DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
 
@@ -956,14 +959,14 @@ pflash_t *pflash_cfi01_register(hwaddr base,
     return CFI_PFLASH01(dev);
 }
 
-MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl)
+MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl)
 {
     return &fl->mem;
 }
 
 static void postload_update_cb(void *opaque, int running, RunState state)
 {
-    pflash_t *pfl = opaque;
+    PFlashCFI01 *pfl = opaque;
 
     /* This is called after bdrv_invalidate_cache_all.  */
     qemu_del_vm_change_state_handler(pfl->vmstate);
@@ -975,7 +978,7 @@ static void postload_update_cb(void *opaque, int running, RunState state)
 
 static int pflash_post_load(void *opaque, int version_id)
 {
-    pflash_t *pfl = opaque;
+    PFlashCFI01 *pfl = opaque;
 
     if (!pfl->ro) {
         pfl->vmstate = qemu_add_vm_change_state_handler(postload_update_cb,
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 0f8b7b8c7b..424cc106d6 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -57,9 +57,10 @@ do {                                                       \
 
 #define PFLASH_LAZY_ROMD_THRESHOLD 42
 
-#define CFI_PFLASH02(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH02)
+#define CFI_PFLASH02(obj) \
+    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
 
-struct pflash_t {
+struct PFlashCFI02 {
     /*< private >*/
     SysBusDevice parent_obj;
     /*< public >*/
@@ -101,7 +102,7 @@ struct pflash_t {
 /*
  * Set up replicated mappings of the same region.
  */
-static void pflash_setup_mappings(pflash_t *pfl)
+static void pflash_setup_mappings(PFlashCFI02 *pfl)
 {
     unsigned i;
     hwaddr size = memory_region_size(&pfl->orig_mem);
@@ -115,7 +116,7 @@ static void pflash_setup_mappings(pflash_t *pfl)
     }
 }
 
-static void pflash_register_memory(pflash_t *pfl, int rom_mode)
+static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode)
 {
     memory_region_rom_device_set_romd(&pfl->orig_mem, rom_mode);
     pfl->rom_mode = rom_mode;
@@ -123,7 +124,7 @@ static void pflash_register_memory(pflash_t *pfl, int rom_mode)
 
 static void pflash_timer (void *opaque)
 {
-    pflash_t *pfl = opaque;
+    PFlashCFI02 *pfl = opaque;
 
     trace_pflash_timer_expired(pfl->cmd);
     /* Reset flash */
@@ -137,7 +138,7 @@ static void pflash_timer (void *opaque)
     pfl->cmd = 0;
 }
 
-static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,
                              int width, int be)
 {
     hwaddr boff;
@@ -246,7 +247,7 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
 }
 
 /* update flash content on disk */
-static void pflash_update(pflash_t *pfl, int offset,
+static void pflash_update(PFlashCFI02 *pfl, int offset,
                           int size)
 {
     int offset_end;
@@ -260,7 +261,7 @@ static void pflash_update(pflash_t *pfl, int offset,
     }
 }
 
-static void pflash_write (pflash_t *pfl, hwaddr offset,
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,
                           uint32_t value, int width, int be)
 {
     hwaddr boff;
@@ -533,7 +534,7 @@ static const MemoryRegionOps pflash_cfi02_ops_le = {
 
 static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
 {
-    pflash_t *pfl = CFI_PFLASH02(dev);
+    PFlashCFI02 *pfl = CFI_PFLASH02(dev);
     uint32_t chip_len;
     int ret;
     Error *local_err = NULL;
@@ -679,19 +680,19 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
 }
 
 static Property pflash_cfi02_properties[] = {
-    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
-    DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
-    DEFINE_PROP_UINT32("sector-length", struct pflash_t, sector_len, 0),
-    DEFINE_PROP_UINT8("width", struct pflash_t, width, 0),
-    DEFINE_PROP_UINT8("mappings", struct pflash_t, mappings, 0),
-    DEFINE_PROP_UINT8("big-endian", struct pflash_t, be, 0),
-    DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0),
-    DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
-    DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
-    DEFINE_PROP_UINT16("id3", struct pflash_t, ident3, 0),
-    DEFINE_PROP_UINT16("unlock-addr0", struct pflash_t, unlock_addr0, 0),
-    DEFINE_PROP_UINT16("unlock-addr1", struct pflash_t, unlock_addr1, 0),
-    DEFINE_PROP_STRING("name", struct pflash_t, name),
+    DEFINE_PROP_DRIVE("drive", PFlashCFI02, blk),
+    DEFINE_PROP_UINT32("num-blocks", PFlashCFI02, nb_blocs, 0),
+    DEFINE_PROP_UINT32("sector-length", PFlashCFI02, sector_len, 0),
+    DEFINE_PROP_UINT8("width", PFlashCFI02, width, 0),
+    DEFINE_PROP_UINT8("mappings", PFlashCFI02, mappings, 0),
+    DEFINE_PROP_UINT8("big-endian", PFlashCFI02, be, 0),
+    DEFINE_PROP_UINT16("id0", PFlashCFI02, ident0, 0),
+    DEFINE_PROP_UINT16("id1", PFlashCFI02, ident1, 0),
+    DEFINE_PROP_UINT16("id2", PFlashCFI02, ident2, 0),
+    DEFINE_PROP_UINT16("id3", PFlashCFI02, ident3, 0),
+    DEFINE_PROP_UINT16("unlock-addr0", PFlashCFI02, unlock_addr0, 0),
+    DEFINE_PROP_UINT16("unlock-addr1", PFlashCFI02, unlock_addr1, 0),
+    DEFINE_PROP_STRING("name", PFlashCFI02, name),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -707,7 +708,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data)
 static const TypeInfo pflash_cfi02_info = {
     .name           = TYPE_CFI_PFLASH02,
     .parent         = TYPE_SYS_BUS_DEVICE,
-    .instance_size  = sizeof(struct pflash_t),
+    .instance_size  = sizeof(PFlashCFI02),
     .class_init     = pflash_cfi02_class_init,
 };
 
@@ -718,15 +719,17 @@ static void pflash_cfi02_register_types(void)
 
 type_init(pflash_cfi02_register_types)
 
-pflash_t *pflash_cfi02_register(hwaddr base,
-                                DeviceState *qdev, const char *name,
-                                hwaddr size,
-                                BlockBackend *blk, uint32_t sector_len,
-                                int nb_blocs, int nb_mappings, int width,
-                                uint16_t id0, uint16_t id1,
-                                uint16_t id2, uint16_t id3,
-                                uint16_t unlock_addr0, uint16_t unlock_addr1,
-                                int be)
+PFlashCFI02 *pflash_cfi02_register(hwaddr base,
+                                   DeviceState *qdev, const char *name,
+                                   hwaddr size,
+                                   BlockBackend *blk,
+                                   uint32_t sector_len, int nb_blocs,
+                                   int nb_mappings, int width,
+                                   uint16_t id0, uint16_t id1,
+                                   uint16_t id2, uint16_t id3,
+                                   uint16_t unlock_addr0,
+                                   uint16_t unlock_addr1,
+                                   int be)
 {
     DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH02);
 
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index 091e22dd60..67e55342f6 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -111,7 +111,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
     char *fatal_errmsg = NULL;
     hwaddr phys_addr = 0x100000000ULL;
     int sector_bits, sector_size;
-    pflash_t *system_flash;
+    PFlashCFI01 *system_flash;
     MemoryRegion *flash_mem;
     char name[64];
     void *flash_ptr;
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 74667766c2..fff5ed19bd 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -1189,7 +1189,7 @@ void mips_malta_init(MachineState *machine)
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
     char *filename;
-    pflash_t *fl;
+    PFlashCFI01 *fl;
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *ram_high = g_new(MemoryRegion, 1);
     MemoryRegion *ram_low_preio = g_new(MemoryRegion, 1);
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index ab3e52b415..3d59a7a356 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -162,9 +162,9 @@ static void xtfpga_net_init(MemoryRegion *address_space,
     memory_region_add_subregion(address_space, buffers, ram);
 }
 
-static pflash_t *xtfpga_flash_init(MemoryRegion *address_space,
-                                   const XtfpgaBoardDesc *board,
-                                   DriveInfo *dinfo, int be)
+static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
+                                      const XtfpgaBoardDesc *board,
+                                      DriveInfo *dinfo, int be)
 {
     SysBusDevice *s;
     DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
@@ -181,7 +181,7 @@ static pflash_t *xtfpga_flash_init(MemoryRegion *address_space,
     s = SYS_BUS_DEVICE(dev);
     memory_region_add_subregion(address_space, board->flash->base,
                                 sysbus_mmio_get_region(s, 0));
-    return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
+    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
 }
 
 static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
@@ -229,7 +229,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
     XtensaMxPic *mx_pic = NULL;
     qemu_irq *extints;
     DriveInfo *dinfo;
-    pflash_t *flash = NULL;
+    PFlashCFI01 *flash = NULL;
     QemuOpts *machine_opts = qemu_get_machine_opts();
     const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
     const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 67c3aa329e..51d8f60c65 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -5,32 +5,41 @@
 
 #include "exec/memory.h"
 
-#define TYPE_CFI_PFLASH01 "cfi.pflash01"
-#define TYPE_CFI_PFLASH02 "cfi.pflash02"
-
-typedef struct pflash_t pflash_t;
-
 /* pflash_cfi01.c */
-pflash_t *pflash_cfi01_register(hwaddr base,
-                                DeviceState *qdev, const char *name,
-                                hwaddr size,
-                                BlockBackend *blk,
-                                uint32_t sector_len, int nb_blocs, int width,
-                                uint16_t id0, uint16_t id1,
-                                uint16_t id2, uint16_t id3, int be);
+
+#define TYPE_CFI_PFLASH01 "cfi.pflash01"
+
+typedef struct PFlashCFI01 PFlashCFI01;
+
+PFlashCFI01 *pflash_cfi01_register(hwaddr base,
+                                   DeviceState *qdev, const char *name,
+                                   hwaddr size,
+                                   BlockBackend *blk,
+                                   uint32_t sector_len, int nb_blocs,
+                                   int width,
+                                   uint16_t id0, uint16_t id1,
+                                   uint16_t id2, uint16_t id3,
+                                   int be);
+MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
 
 /* pflash_cfi02.c */
-pflash_t *pflash_cfi02_register(hwaddr base,
-                                DeviceState *qdev, const char *name,
-                                hwaddr size,
-                                BlockBackend *blk, uint32_t sector_len,
-                                int nb_blocs, int nb_mappings, int width,
-                                uint16_t id0, uint16_t id1,
-                                uint16_t id2, uint16_t id3,
-                                uint16_t unlock_addr0, uint16_t unlock_addr1,
-                                int be);
 
-MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl);
+#define TYPE_CFI_PFLASH02 "cfi.pflash02"
+
+typedef struct PFlashCFI02 PFlashCFI02;
+
+PFlashCFI02 *pflash_cfi02_register(hwaddr base,
+                                   DeviceState *qdev, const char *name,
+                                   hwaddr size,
+                                   BlockBackend *blk,
+                                   uint32_t sector_len, int nb_blocs,
+                                   int nb_mappings,
+                                   int width,
+                                   uint16_t id0, uint16_t id1,
+                                   uint16_t id2, uint16_t id3,
+                                   uint16_t unlock_addr0,
+                                   uint16_t unlock_addr1,
+                                   int be);
 
 /* nand.c */
 DeviceState *nand_init(BlockBackend *blk, int manf_id, int chip_id);
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02 Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-18 16:43   ` Laszlo Ersek
  2019-02-19 12:40   ` Philippe Mathieu-Daudé
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2} Markus Armbruster
                   ` (18 subsequent siblings)
  20 siblings, 2 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
BUG", which sounds like a warning, then calls exit(1), followed by
unreachable goto reset_flash.  All this commit does is expanding the
macro, so the smell becomes more poignant, and the macro can be
deleted.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/block/pflash_cfi01.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 9efa7aa9af..f73c30a3ee 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -49,12 +49,6 @@
 #include "sysemu/sysemu.h"
 #include "trace.h"
 
-#define PFLASH_BUG(fmt, ...) \
-do { \
-    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
-    exit(1); \
-} while(0)
-
 /* #define PFLASH_DEBUG */
 #ifdef PFLASH_DEBUG
 #define DPRINTF(fmt, ...)                                   \
@@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
                 pfl->status |= 0x80;
             } else {
                 DPRINTF("%s: unknown command for \"write block\"\n", __func__);
-                PFLASH_BUG("Write block confirm");
-                goto reset_flash;
+                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
+                exit(1);
             }
             break;
         default:
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02 Markus Armbruster
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-18 16:45   ` Laszlo Ersek
                     ` (2 more replies)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image Markus Armbruster
                   ` (17 subsequent siblings)
  20 siblings, 3 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

We have two open-coded copies of macro CFI_PFLASH01().  Move the macro
to the header, so we can ditch the copies.  Move CFI_PFLASH02() to the
header for symmetry.

We define macros TYPE_CFI_PFLASH01 and TYPE_CFI_PFLASH02 for type name
strings, then mostly use the strings.  If the macros are worth
defining, they are worth using.  Replace the strings by the macros.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/arm/vexpress.c        | 4 ++--
 hw/arm/virt.c            | 3 ++-
 hw/block/pflash_cfi01.c  | 3 ---
 hw/block/pflash_cfi02.c  | 3 ---
 hw/xtensa/xtfpga.c       | 4 ++--
 include/hw/block/flash.h | 4 ++++
 6 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index ed46d2e730..00913f2655 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -515,7 +515,7 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
 static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
                                              DriveInfo *di)
 {
-    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
+    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
 
     if (di) {
         qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
@@ -536,7 +536,7 @@ static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
     qdev_init_nofail(dev);
 
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
-    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
+    return CFI_PFLASH01(dev);
 }
 
 static void vexpress_common_init(MachineState *machine)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 99c2b6e60d..b7d53b2b87 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -34,6 +34,7 @@
 #include "hw/arm/arm.h"
 #include "hw/arm/primecell.h"
 #include "hw/arm/virt.h"
+#include "hw/block/flash.h"
 #include "hw/vfio/vfio-calxeda-xgmac.h"
 #include "hw/vfio/vfio-amd-xgbe.h"
 #include "hw/display/ramfb.h"
@@ -874,7 +875,7 @@ static void create_one_flash(const char *name, hwaddr flashbase,
      * parameters as the flash devices on the Versatile Express board.
      */
     DriveInfo *dinfo = drive_get_next(IF_PFLASH);
-    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
+    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     const uint64_t sectorlength = 256 * 1024;
 
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index f73c30a3ee..43dbb7db26 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -59,9 +59,6 @@ do {                                                        \
 #define DPRINTF(fmt, ...) do { } while (0)
 #endif
 
-#define CFI_PFLASH01(obj) \
-    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
-
 #define PFLASH_BE          0
 #define PFLASH_SECURE      1
 
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 424cc106d6..e9c76d6cfb 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -57,9 +57,6 @@ do {                                                       \
 
 #define PFLASH_LAZY_ROMD_THRESHOLD 42
 
-#define CFI_PFLASH02(obj) \
-    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
-
 struct PFlashCFI02 {
     /*< private >*/
     SysBusDevice parent_obj;
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index 3d59a7a356..a726d5632a 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -167,7 +167,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
                                       DriveInfo *dinfo, int be)
 {
     SysBusDevice *s;
-    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
+    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
 
     qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
                         &error_abort);
@@ -181,7 +181,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
     s = SYS_BUS_DEVICE(dev);
     memory_region_add_subregion(address_space, board->flash->base,
                                 sysbus_mmio_get_region(s, 0));
-    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
+    return CFI_PFLASH01(dev);
 }
 
 static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 51d8f60c65..1078dc7238 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -8,6 +8,8 @@
 /* pflash_cfi01.c */
 
 #define TYPE_CFI_PFLASH01 "cfi.pflash01"
+#define CFI_PFLASH01(obj) \
+    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
 
 typedef struct PFlashCFI01 PFlashCFI01;
 
@@ -25,6 +27,8 @@ MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
 /* pflash_cfi02.c */
 
 #define TYPE_CFI_PFLASH02 "cfi.pflash02"
+#define CFI_PFLASH02(obj) \
+    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
 
 typedef struct PFlashCFI02 PFlashCFI02;
 
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (2 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2} Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-18 16:36   ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 05/10] ppc405_boards: " Markus Armbruster
                   ` (16 subsequent siblings)
  20 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc, BALATON Zoltan

Machine "sam460ex" maps its flash memory at address 0xFFF00000.  When
no image is supplied, its size is 1MiB (0x100000).  Else, it's the
size of the image rounded up to the next multiple of 64KiB.

The rounding is actually useless: pflash_cfi01_realize() fails with
"failed to read the initial flash content" unless it's a no-op.

I have no idea what happens when the pflash's size exceeds 1MiB.
Useful outcomes seem unlikely.

I guess memory at the end of the address space remains unmapped when
it's smaller than 1MiB.  Again, useful outcomes seem unlikely.

Set the flash memory size to 1MiB regardless of image size, to match
the physical hardware.

Cc: BALATON Zoltan <balaton@eik.bme.hu>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ppc/sam460ex.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
index 75250d49e4..ca8d7ab9c6 100644
--- a/hw/ppc/sam460ex.c
+++ b/hw/ppc/sam460ex.c
@@ -92,31 +92,24 @@ struct boot_info {
 static int sam460ex_load_uboot(void)
 {
     DriveInfo *dinfo;
-    BlockBackend *blk = NULL;
-    hwaddr base = FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32);
-    long bios_size = FLASH_SIZE;
-    int fl_sectors;
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    if (dinfo) {
-        blk = blk_by_legacy_dinfo(dinfo);
-        bios_size = blk_getlength(blk);
-    }
-    fl_sectors = (bios_size + 65535) >> 16;
-
-    if (!pflash_cfi01_register(base, NULL, "sam460ex.flash", bios_size,
-                               blk, 64 * KiB, fl_sectors,
+    if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
+                               NULL, "sam460ex.flash", FLASH_SIZE,
+                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
+                               65536, FLASH_SIZE / 65536,
                                1, 0x89, 0x18, 0x0000, 0x0, 1)) {
         error_report("Error registering flash memory");
         /* XXX: return an error instead? */
         exit(1);
     }
 
-    if (!blk) {
+    if (!dinfo) {
         /*error_report("No flash image given with the 'pflash' parameter,"
                 " using default u-boot image");*/
-        base = UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32);
-        rom_add_file_fixed(UBOOT_FILENAME, base, -1);
+        rom_add_file_fixed(UBOOT_FILENAME,
+                           UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
+                           -1);
     }
 
     return 0;
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (3 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-19  3:55   ` David Gibson
                     ` (2 more replies)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME Markus Armbruster
                   ` (15 subsequent siblings)
  20 siblings, 3 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc, David Gibson

Machine "ref405ep" maps its flash memory at address 2^32 - image size.
Image size is rounded up to the next multiple of 64KiB.  Useless,
because pflash_cfi02_realize() fails with "failed to read the initial
flash content" unless the rounding is a no-op.

If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
other stuff.  No idea how that would play out, but a useful outcomes
seem unlikely.

Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
regardless of image size, to match the physical hardware.

Machine "taihu" maps its boot flash memory similarly.  The code even
has a comment /* XXX: should check that size is 2MB */, followed by
disabled code to adjust the size to 2MiB regardless of image size.

Its code to map its application flash memory looks the same, except
there the XXX comment asks for 32MiB, and the code to adjust the size
isn't disabled.  Note that pflash_cfi02_realize() fails with "failed
to read the initial flash content" for images smaller than 32MiB.

Map the boot flash memory at fixed address 0xFFE00000 with size 2MiB,
to match the physical hardware.  Delete dead code from application
flash mapping, and simplify some.

Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ppc/ppc405_boards.c | 53 +++++++++++++-----------------------------
 1 file changed, 16 insertions(+), 37 deletions(-)

diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index f47b15f10e..728154aebb 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -158,7 +158,7 @@ static void ref405ep_init(MachineState *machine)
     target_ulong kernel_base, initrd_base;
     long kernel_size, initrd_size;
     int linux_boot;
-    int fl_idx, fl_sectors, len;
+    int len;
     DriveInfo *dinfo;
     MemoryRegion *sysmem = get_system_memory();
 
@@ -185,26 +185,19 @@ static void ref405ep_init(MachineState *machine)
 #ifdef DEBUG_BOARD_INIT
     printf("%s: register BIOS\n", __func__);
 #endif
-    fl_idx = 0;
 #ifdef USE_FLASH_BIOS
-    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
+    dinfo = drive_get(IF_PFLASH, 0, 0);
     if (dinfo) {
-        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
-
-        bios_size = blk_getlength(blk);
-        fl_sectors = (bios_size + 65535) >> 16;
 #ifdef DEBUG_BOARD_INIT
-        printf("Register parallel flash %d size %lx"
-               " at addr %lx '%s' %d\n",
-               fl_idx, bios_size, -bios_size,
-               blk_name(blk), fl_sectors);
+        printf("Register parallel flash\n");
 #endif
-        pflash_cfi02_register((uint32_t)(-bios_size),
+        bios_size = 0x80000;
+        pflash_cfi02_register(0xFFF80000,
                               NULL, "ef405ep.bios", bios_size,
-                              blk, 65536, fl_sectors, 1,
+                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
+                              65536, bios_size / 65536, 1,
                               2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
-        fl_idx++;
     } else
 #endif
     {
@@ -455,7 +448,7 @@ static void taihu_405ep_init(MachineState *machine)
     target_ulong kernel_base, initrd_base;
     long kernel_size, initrd_size;
     int linux_boot;
-    int fl_idx, fl_sectors;
+    int fl_idx;
     DriveInfo *dinfo;
 
     /* RAM is soldered to the board so the size cannot be changed */
@@ -486,21 +479,14 @@ static void taihu_405ep_init(MachineState *machine)
 #if defined(USE_FLASH_BIOS)
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
     if (dinfo) {
-        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
-
-        bios_size = blk_getlength(blk);
-        /* XXX: should check that size is 2MB */
-        //        bios_size = 2 * 1024 * 1024;
-        fl_sectors = (bios_size + 65535) >> 16;
 #ifdef DEBUG_BOARD_INIT
-        printf("Register parallel flash %d size %lx"
-               " at addr %lx '%s' %d\n",
-               fl_idx, bios_size, -bios_size,
-               blk_name(blk), fl_sectors);
+        printf("Register boot flash\n");
 #endif
-        pflash_cfi02_register((uint32_t)(-bios_size),
+        bios_size = 2 * MiB;
+        pflash_cfi02_register(0xFFE00000,
                               NULL, "taihu_405ep.bios", bios_size,
-                              blk, 65536, fl_sectors, 1,
+                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
+                              65536, bios_size / 65536, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
         fl_idx++;
@@ -536,20 +522,13 @@ static void taihu_405ep_init(MachineState *machine)
     /* Register Linux flash */
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
     if (dinfo) {
-        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
-
-        bios_size = blk_getlength(blk);
-        /* XXX: should check that size is 32MB */
         bios_size = 32 * MiB;
-        fl_sectors = (bios_size + 65535) >> 16;
 #ifdef DEBUG_BOARD_INIT
-        printf("Register parallel flash %d size %lx"
-               " at addr " TARGET_FMT_lx " '%s'\n",
-               fl_idx, bios_size, (target_ulong)0xfc000000,
-               blk_name(blk));
+        printf("Register application flash\n"
 #endif
         pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
-                              blk, 65536, fl_sectors, 1,
+                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
+                              65536, bios_size / 65536, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
         fl_idx++;
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (4 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 05/10] ppc405_boards: " Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-19 14:03   ` Peter Maydell
  2019-02-19 16:02   ` Philippe Mathieu-Daudé
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat Markus Armbruster
                   ` (14 subsequent siblings)
  20 siblings, 2 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc, Magnus Damm

pflash_cfi02_register() takes a size in bytes, a block size in bytes
and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
number of blocks.  The latter happens to win.  I tried to find
documentation on the physcial hardware, no luck.

For now, adjust the byte size passed to match the actual size created,
and add a FIXME comment.

Cc: Magnus Damm <magnus.damm@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/sh4/r2d.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index dcdb3728cb..ed18d1f351 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -290,7 +290,14 @@ static void r2d_init(MachineState *machine)
 
     /* onboard flash memory */
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
+    /*
+     * FIXME The code is confused about the size of the flash.  It
+     * used to pass FLASH_SIZE bytes, in FLASH_SIZE >> 16 blocks of
+     * 16KiB each, which does not compute, but creates one of
+     * FLASH_SIZE / 4 bytes anyway.  The current code does so too, but
+     * whether it's the right size is anybody's guess.
+     */
+    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE / 4,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           16 * KiB, FLASH_SIZE >> 16,
                           1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (5 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-19 13:02   ` Philippe Mathieu-Daudé
  2019-02-21 15:27   ` Alex Bennée
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1 Markus Armbruster
                   ` (13 subsequent siblings)
  20 siblings, 2 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc,
	Aurelien Jarno, Aleksandar Rikalo

pflash_cfi01_register() takes a size in bytes, a block size in bytes
and a number of blocks.  mips_malta_init() passes BIOS_SIZE, 65536,
FLASH_SIZE >> 16.  Actually consistent only because BIOS_SIZE (defined
in include/hw/mips/bios.h as (4 * MiB)) matches FLASH_SIZE (defined
locally as 0x400000).  Confusing all the same.

Pass FLASH_SIZE instead of BIOS_SIZE.

There are more uses of BIOS_SIZE, but I don't sufficiently understand
them to attempt cleanup.

Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Aleksandar Rikalo <arikalo@wavecomp.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/mips/mips_malta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index fff5ed19bd..65cdda4881 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -1269,12 +1269,12 @@ void mips_malta_init(MachineState *machine)
     if (dinfo) {
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
                "addr %08llx '%s' %x\n",
-               fl_idx, bios_size, FLASH_ADDRESS,
+               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
                blk_name(dinfo->bdrv), fl_sectors);
     }
 #endif
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
-                               BIOS_SIZE,
+                               FLASH_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                65536, fl_sectors,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (6 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-18 16:50   ` Laszlo Ersek
                     ` (2 more replies)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2 Markus Armbruster
                   ` (12 subsequent siblings)
  20 siblings, 3 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

QOMification left parameter @qdev unused in pflash_cfi01_register()
and pflash_cfi02_register().  All callers pass NULL.  Remove.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/arm/collie.c                          | 4 ++--
 hw/arm/digic_boards.c                    | 2 +-
 hw/arm/gumstix.c                         | 4 ++--
 hw/arm/mainstone.c                       | 2 +-
 hw/arm/musicpal.c                        | 4 ++--
 hw/arm/omap_sx1.c                        | 4 ++--
 hw/arm/versatilepb.c                     | 2 +-
 hw/arm/xilinx_zynq.c                     | 2 +-
 hw/arm/z2.c                              | 3 +--
 hw/block/pflash_cfi01.c                  | 2 +-
 hw/block/pflash_cfi02.c                  | 2 +-
 hw/i386/pc_sysfw.c                       | 2 +-
 hw/lm32/lm32_boards.c                    | 4 ++--
 hw/lm32/milkymist.c                      | 2 +-
 hw/microblaze/petalogix_ml605_mmu.c      | 3 +--
 hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
 hw/mips/mips_malta.c                     | 2 +-
 hw/mips/mips_r4k.c                       | 2 +-
 hw/ppc/ppc405_boards.c                   | 6 +++---
 hw/ppc/sam460ex.c                        | 2 +-
 hw/ppc/virtex_ml507.c                    | 2 +-
 hw/sh4/r2d.c                             | 2 +-
 include/hw/block/flash.h                 | 4 ++--
 23 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/hw/arm/collie.c b/hw/arm/collie.c
index 48b732c176..cbc4400f8e 100644
--- a/hw/arm/collie.c
+++ b/hw/arm/collie.c
@@ -36,12 +36,12 @@ static void collie_init(MachineState *machine)
     s = sa1110_init(sysmem, collie_binfo.ram_size, machine->cpu_type);
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi01_register(SA_CS0, NULL, "collie.fl1", 0x02000000,
+    pflash_cfi01_register(SA_CS0, "collie.fl1", 0x02000000,
                     dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                     (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
     dinfo = drive_get(IF_PFLASH, 0, 1);
-    pflash_cfi01_register(SA_CS1, NULL, "collie.fl2", 0x02000000,
+    pflash_cfi01_register(SA_CS1, "collie.fl2", 0x02000000,
                     dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                     (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
diff --git a/hw/arm/digic_boards.c b/hw/arm/digic_boards.c
index 9f11dcd11f..15a00a1be3 100644
--- a/hw/arm/digic_boards.c
+++ b/hw/arm/digic_boards.c
@@ -129,7 +129,7 @@ static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
 #define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
 #define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
 
-    pflash_cfi02_register(addr, NULL, "pflash", FLASH_K8P3215UQB_SIZE,
+    pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE,
                           NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
                           FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE,
                           DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c
index 56cb763c4e..304dbeab2f 100644
--- a/hw/arm/gumstix.c
+++ b/hw/arm/gumstix.c
@@ -72,7 +72,7 @@ static void connex_init(MachineState *machine)
 #else
     be = 0;
 #endif
-    if (!pflash_cfi01_register(0x00000000, NULL, "connext.rom", connex_rom,
+    if (!pflash_cfi01_register(0x00000000, "connext.rom", connex_rom,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                sector_len, connex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
@@ -109,7 +109,7 @@ static void verdex_init(MachineState *machine)
 #else
     be = 0;
 #endif
-    if (!pflash_cfi01_register(0x00000000, NULL, "verdex.rom", verdex_rom,
+    if (!pflash_cfi01_register(0x00000000, "verdex.rom", verdex_rom,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                sector_len, verdex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
index 0beb5c426b..2a1c1072db 100644
--- a/hw/arm/mainstone.c
+++ b/hw/arm/mainstone.c
@@ -148,7 +148,7 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
             exit(1);
         }
 
-        if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
+        if (!pflash_cfi01_register(mainstone_flash_base[i],
                                    i ? "mainstone.flash1" : "mainstone.flash0",
                                    MAINSTONE_FLASH,
                                    blk_by_legacy_dinfo(dinfo),
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index d22532a11c..ecca0e6f64 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -1636,14 +1636,14 @@ static void musicpal_init(MachineState *machine)
          * image is smaller than 32 MB.
          */
 #ifdef TARGET_WORDS_BIGENDIAN
-        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                               "musicpal.flash", flash_size,
                               blk, 0x10000, (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 1);
 #else
-        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                               "musicpal.flash", flash_size,
                               blk, 0x10000, (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
index 84550f0236..b1128777cf 100644
--- a/hw/arm/omap_sx1.c
+++ b/hw/arm/omap_sx1.c
@@ -152,7 +152,7 @@ static void sx1_init(MachineState *machine, const int version)
 #endif
 
     if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
-        if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
+        if (!pflash_cfi01_register(OMAP_CS0_BASE,
                                    "omap_sx1.flash0-1", flash_size,
                                    blk_by_legacy_dinfo(dinfo),
                                    sector_size, flash_size / sector_size,
@@ -176,7 +176,7 @@ static void sx1_init(MachineState *machine, const int version)
         memory_region_add_subregion(address_space,
                                 OMAP_CS1_BASE + flash1_size, &cs[1]);
 
-        if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
+        if (!pflash_cfi01_register(OMAP_CS1_BASE,
                                    "omap_sx1.flash1-1", flash1_size,
                                    blk_by_legacy_dinfo(dinfo),
                                    sector_size, flash1_size / sector_size,
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index 22b09a1e61..82c5277462 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -365,7 +365,7 @@ static void versatile_init(MachineState *machine, int board_id)
     /* 0x34000000 NOR Flash */
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, NULL, "versatile.flash",
+    if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, "versatile.flash",
                           VERSATILE_FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           VERSATILE_FLASH_SECT_SIZE,
diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
index 57497b0c4d..1fa4a77728 100644
--- a/hw/arm/xilinx_zynq.c
+++ b/hw/arm/xilinx_zynq.c
@@ -205,7 +205,7 @@ static void zynq_init(MachineState *machine)
     DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0);
 
     /* AMD */
-    pflash_cfi02_register(0xe2000000, NULL, "zynq.pflash", FLASH_SIZE,
+    pflash_cfi02_register(0xe2000000, "zynq.pflash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           FLASH_SECTOR_SIZE,
                           FLASH_SIZE/FLASH_SECTOR_SIZE, 1,
diff --git a/hw/arm/z2.c b/hw/arm/z2.c
index 697a822f1e..54e6caee9f 100644
--- a/hw/arm/z2.c
+++ b/hw/arm/z2.c
@@ -324,8 +324,7 @@ static void z2_init(MachineState *machine)
         exit(1);
     }
 
-    if (!pflash_cfi01_register(Z2_FLASH_BASE,
-                               NULL, "z2.flash0", Z2_FLASH_SIZE,
+    if (!pflash_cfi01_register(Z2_FLASH_BASE, "z2.flash0", Z2_FLASH_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                sector_len, Z2_FLASH_SIZE / sector_len,
                                4, 0, 0, 0, 0, be)) {
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 43dbb7db26..f2a4b16a34 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -921,7 +921,7 @@ static void pflash_cfi01_register_types(void)
 type_init(pflash_cfi01_register_types)
 
 PFlashCFI01 *pflash_cfi01_register(hwaddr base,
-                                   DeviceState *qdev, const char *name,
+                                   const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
                                    uint32_t sector_len, int nb_blocs,
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index e9c76d6cfb..73491aafe6 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -717,7 +717,7 @@ static void pflash_cfi02_register_types(void)
 type_init(pflash_cfi02_register_types)
 
 PFlashCFI02 *pflash_cfi02_register(hwaddr base,
-                                   DeviceState *qdev, const char *name,
+                                   const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
                                    uint32_t sector_len, int nb_blocs,
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index 67e55342f6..9a5be54a85 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -160,7 +160,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
 
         /* pflash_cfi01_register() creates a deep copy of the name */
         snprintf(name, sizeof name, "system.flash%d", unit);
-        system_flash = pflash_cfi01_register(phys_addr, NULL /* qdev */, name,
+        system_flash = pflash_cfi01_register(phys_addr, name,
                                              size, blk, sector_size,
                                              size >> sector_bits,
                                              1      /* width */,
diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index 05157f8eab..f726355309 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -114,7 +114,7 @@ static void lm32_evr_init(MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
-    pflash_cfi02_register(flash_base, NULL, "lm32_evr.flash", flash_size,
+    pflash_cfi02_register(flash_base, "lm32_evr.flash", flash_size,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           flash_sector_size, flash_size / flash_sector_size,
                           1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
@@ -207,7 +207,7 @@ static void lm32_uclinux_init(MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
-    pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
+    pflash_cfi02_register(flash_base, "lm32_uclinux.flash", flash_size,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           flash_sector_size, flash_size / flash_sector_size,
                           1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index b080cf1ca9..ece7e3b699 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -121,7 +121,7 @@ milkymist_init(MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Numonyx JS28F256J3F105 */
-    pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
+    pflash_cfi01_register(flash_base, "milkymist.flash", flash_size,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           flash_sector_size, flash_size / flash_sector_size,
                           2, 0x00, 0x89, 0x00, 0x1d, 1);
diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c
index c730878d25..74bcc14cda 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -107,8 +107,7 @@ petalogix_ml605_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* 5th parameter 2 means bank-width
      * 10th paremeter 0 means little-endian */
-    pflash_cfi01_register(FLASH_BASEADDR,
-                          NULL, "petalogix_ml605.flash", FLASH_SIZE,
+    pflash_cfi01_register(FLASH_BASEADDR, "petalogix_ml605.flash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           64 * KiB, FLASH_SIZE >> 16,
                           2, 0x89, 0x18, 0x0000, 0x0, 0);
diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c
index b9f0b0d06e..a07b7f8edf 100644
--- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
+++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
@@ -88,7 +88,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(FLASH_BASEADDR,
-                          NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE,
+                          "petalogix_s3adsp1800.flash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           64 * KiB, FLASH_SIZE >> 16,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 65cdda4881..76b81b7402 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -1273,7 +1273,7 @@ void mips_malta_init(MachineState *machine)
                blk_name(dinfo->bdrv), fl_sectors);
     }
 #endif
-    fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
+    fl = pflash_cfi01_register(FLASH_ADDRESS, "mips_malta.bios",
                                FLASH_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                65536, fl_sectors,
diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index a015a6d14e..0b9df466e7 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -235,7 +235,7 @@ void mips_r4k_init(MachineState *machine)
         load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
     } else if ((dinfo = drive_get(IF_PFLASH, 0, 0)) != NULL) {
         uint32_t mips_rom = 0x00400000;
-        if (!pflash_cfi01_register(0x1fc00000, NULL, "mips_r4k.bios", mips_rom,
+        if (!pflash_cfi01_register(0x1fc00000, "mips_r4k.bios", mips_rom,
                                    blk_by_legacy_dinfo(dinfo),
                                    sector_len, mips_rom / sector_len,
                                    4, 0, 0, 0, 0, be)) {
diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index 728154aebb..a54627903d 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -193,7 +193,7 @@ static void ref405ep_init(MachineState *machine)
 #endif
         bios_size = 0x80000;
         pflash_cfi02_register(0xFFF80000,
-                              NULL, "ef405ep.bios", bios_size,
+                              "ef405ep.bios", bios_size,
                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                               65536, bios_size / 65536, 1,
                               2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
@@ -484,7 +484,7 @@ static void taihu_405ep_init(MachineState *machine)
 #endif
         bios_size = 2 * MiB;
         pflash_cfi02_register(0xFFE00000,
-                              NULL, "taihu_405ep.bios", bios_size,
+                              "taihu_405ep.bios", bios_size,
                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                               65536, bios_size / 65536, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
@@ -526,7 +526,7 @@ static void taihu_405ep_init(MachineState *machine)
 #ifdef DEBUG_BOARD_INIT
         printf("Register application flash\n"
 #endif
-        pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
+        pflash_cfi02_register(0xfc000000, "taihu_405ep.flash", bios_size,
                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                               65536, bios_size / 65536, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
index ca8d7ab9c6..a989a8c439 100644
--- a/hw/ppc/sam460ex.c
+++ b/hw/ppc/sam460ex.c
@@ -95,7 +95,7 @@ static int sam460ex_load_uboot(void)
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
-                               NULL, "sam460ex.flash", FLASH_SIZE,
+                               "sam460ex.flash", FLASH_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                65536, FLASH_SIZE / 65536,
                                1, 0x89, 0x18, 0x0000, 0x0, 1)) {
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index 5a711cb3d9..d2085a839c 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -227,7 +227,7 @@ static void virtex_init(MachineState *machine)
     memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi01_register(PFLASH_BASEADDR, NULL, "virtex.flash", FLASH_SIZE,
+    pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           64 * KiB, FLASH_SIZE >> 16,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index ed18d1f351..abd3b67c28 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -297,7 +297,7 @@ static void r2d_init(MachineState *machine)
      * FLASH_SIZE / 4 bytes anyway.  The current code does so too, but
      * whether it's the right size is anybody's guess.
      */
-    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE / 4,
+    pflash_cfi02_register(0x0, "r2d.flash", FLASH_SIZE / 4,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           16 * KiB, FLASH_SIZE >> 16,
                           1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 1078dc7238..464a72f11b 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -14,7 +14,7 @@
 typedef struct PFlashCFI01 PFlashCFI01;
 
 PFlashCFI01 *pflash_cfi01_register(hwaddr base,
-                                   DeviceState *qdev, const char *name,
+                                   const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
                                    uint32_t sector_len, int nb_blocs,
@@ -33,7 +33,7 @@ MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
 typedef struct PFlashCFI02 PFlashCFI02;
 
 PFlashCFI02 *pflash_cfi02_register(hwaddr base,
-                                   DeviceState *qdev, const char *name,
+                                   const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
                                    uint32_t sector_len, int nb_blocs,
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (7 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1 Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-18 17:01   ` Laszlo Ersek
  2019-02-21 16:51   ` Alex Bennée
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some Markus Armbruster
                   ` (11 subsequent siblings)
  20 siblings, 2 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

QOMification left parameter @size unused in pflash_cfi01_register()
and pflash_cfi02_register().  register().  Obviously, @size should
match @sector_len and @nb_blocs, i.e. size == sector_len * nb_blocs.
All callers satisfy this.

Remove @nb_blocs and compute it from @size and @sector_len.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/arm/collie.c                          | 5 +++--
 hw/arm/digic_boards.c                    | 1 -
 hw/arm/gumstix.c                         | 4 ++--
 hw/arm/mainstone.c                       | 2 +-
 hw/arm/musicpal.c                        | 4 ++--
 hw/arm/omap_sx1.c                        | 4 ++--
 hw/arm/versatilepb.c                     | 1 -
 hw/arm/xilinx_zynq.c                     | 3 +--
 hw/arm/z2.c                              | 2 +-
 hw/block/pflash_cfi01.c                  | 5 +++--
 hw/block/pflash_cfi02.c                  | 5 +++--
 hw/i386/pc_sysfw.c                       | 6 +-----
 hw/lm32/lm32_boards.c                    | 4 ++--
 hw/lm32/milkymist.c                      | 2 +-
 hw/microblaze/petalogix_ml605_mmu.c      | 2 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
 hw/mips/mips_malta.c                     | 7 +++----
 hw/mips/mips_r4k.c                       | 2 +-
 hw/ppc/ppc405_boards.c                   | 6 +++---
 hw/ppc/sam460ex.c                        | 2 +-
 hw/ppc/virtex_ml507.c                    | 2 +-
 hw/sh4/r2d.c                             | 2 +-
 include/hw/block/flash.h                 | 4 ++--
 23 files changed, 36 insertions(+), 41 deletions(-)

diff --git a/hw/arm/collie.c b/hw/arm/collie.c
index cbc4400f8e..7c9c0615f0 100644
--- a/hw/arm/collie.c
+++ b/hw/arm/collie.c
@@ -9,6 +9,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "hw/boards.h"
@@ -38,12 +39,12 @@ static void collie_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(SA_CS0, "collie.fl1", 0x02000000,
                     dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                    (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
+                    64 * KiB, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
     dinfo = drive_get(IF_PFLASH, 0, 1);
     pflash_cfi01_register(SA_CS1, "collie.fl2", 0x02000000,
                     dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                    (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
+                    64 * KiB, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
     sysbus_create_simple("scoop", 0x40800000, NULL);
 
diff --git a/hw/arm/digic_boards.c b/hw/arm/digic_boards.c
index 15a00a1be3..304e4d1a29 100644
--- a/hw/arm/digic_boards.c
+++ b/hw/arm/digic_boards.c
@@ -131,7 +131,6 @@ static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
 
     pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE,
                           NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
-                          FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE,
                           DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
                           4,
                           0x00EC, 0x007E, 0x0003, 0x0001,
diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c
index 304dbeab2f..2e526218f4 100644
--- a/hw/arm/gumstix.c
+++ b/hw/arm/gumstix.c
@@ -74,7 +74,7 @@ static void connex_init(MachineState *machine)
 #endif
     if (!pflash_cfi01_register(0x00000000, "connext.rom", connex_rom,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                               sector_len, connex_rom / sector_len,
+                               sector_len,
                                2, 0, 0, 0, 0, be)) {
         error_report("Error registering flash memory");
         exit(1);
@@ -111,7 +111,7 @@ static void verdex_init(MachineState *machine)
 #endif
     if (!pflash_cfi01_register(0x00000000, "verdex.rom", verdex_rom,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                               sector_len, verdex_rom / sector_len,
+                               sector_len,
                                2, 0, 0, 0, 0, be)) {
         error_report("Error registering flash memory");
         exit(1);
diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
index 2a1c1072db..6e15ba9663 100644
--- a/hw/arm/mainstone.c
+++ b/hw/arm/mainstone.c
@@ -152,7 +152,7 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
                                    i ? "mainstone.flash1" : "mainstone.flash0",
                                    MAINSTONE_FLASH,
                                    blk_by_legacy_dinfo(dinfo),
-                                   sector_len, MAINSTONE_FLASH / sector_len,
+                                   sector_len,
                                    4, 0, 0, 0, 0, be)) {
             error_report("Error registering flash memory");
             exit(1);
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index ecca0e6f64..fb3f5146f3 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -1638,14 +1638,14 @@ static void musicpal_init(MachineState *machine)
 #ifdef TARGET_WORDS_BIGENDIAN
         pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                               "musicpal.flash", flash_size,
-                              blk, 0x10000, (flash_size + 0xffff) >> 16,
+                              blk, 0x10000,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 1);
 #else
         pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                               "musicpal.flash", flash_size,
-                              blk, 0x10000, (flash_size + 0xffff) >> 16,
+                              blk, 0x10000,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 0);
diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
index b1128777cf..b269a5e1c2 100644
--- a/hw/arm/omap_sx1.c
+++ b/hw/arm/omap_sx1.c
@@ -155,7 +155,7 @@ static void sx1_init(MachineState *machine, const int version)
         if (!pflash_cfi01_register(OMAP_CS0_BASE,
                                    "omap_sx1.flash0-1", flash_size,
                                    blk_by_legacy_dinfo(dinfo),
-                                   sector_size, flash_size / sector_size,
+                                   sector_size,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                            fl_idx);
@@ -179,7 +179,7 @@ static void sx1_init(MachineState *machine, const int version)
         if (!pflash_cfi01_register(OMAP_CS1_BASE,
                                    "omap_sx1.flash1-1", flash1_size,
                                    blk_by_legacy_dinfo(dinfo),
-                                   sector_size, flash1_size / sector_size,
+                                   sector_size,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                            fl_idx);
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index 82c5277462..d67181810a 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -369,7 +369,6 @@ static void versatile_init(MachineState *machine, int board_id)
                           VERSATILE_FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                           VERSATILE_FLASH_SECT_SIZE,
-                          VERSATILE_FLASH_SIZE / VERSATILE_FLASH_SECT_SIZE,
                           4, 0x0089, 0x0018, 0x0000, 0x0, 0)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
     }
diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
index 1fa4a77728..f36cfcfd4a 100644
--- a/hw/arm/xilinx_zynq.c
+++ b/hw/arm/xilinx_zynq.c
@@ -207,8 +207,7 @@ static void zynq_init(MachineState *machine)
     /* AMD */
     pflash_cfi02_register(0xe2000000, "zynq.pflash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          FLASH_SECTOR_SIZE,
-                          FLASH_SIZE/FLASH_SECTOR_SIZE, 1,
+                          FLASH_SECTOR_SIZE, 1,
                           1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa,
                               0);
 
diff --git a/hw/arm/z2.c b/hw/arm/z2.c
index 54e6caee9f..fb073ec2f5 100644
--- a/hw/arm/z2.c
+++ b/hw/arm/z2.c
@@ -326,7 +326,7 @@ static void z2_init(MachineState *machine)
 
     if (!pflash_cfi01_register(Z2_FLASH_BASE, "z2.flash0", Z2_FLASH_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                               sector_len, Z2_FLASH_SIZE / sector_len,
+                               sector_len,
                                4, 0, 0, 0, 0, be)) {
         error_report("Error registering flash memory");
         exit(1);
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index f2a4b16a34..2e161f937f 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -924,7 +924,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
                                    const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
-                                   uint32_t sector_len, int nb_blocs,
+                                   uint32_t sector_len,
                                    int bank_width,
                                    uint16_t id0, uint16_t id1,
                                    uint16_t id2, uint16_t id3,
@@ -935,7 +935,8 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
     if (blk) {
         qdev_prop_set_drive(dev, "drive", blk, &error_abort);
     }
-    qdev_prop_set_uint32(dev, "num-blocks", nb_blocs);
+    assert(size % sector_len == 0);
+    qdev_prop_set_uint32(dev, "num-blocks", size / sector_len);
     qdev_prop_set_uint64(dev, "sector-length", sector_len);
     qdev_prop_set_uint8(dev, "width", bank_width);
     qdev_prop_set_bit(dev, "big-endian", !!be);
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 73491aafe6..414b5ab074 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -720,7 +720,7 @@ PFlashCFI02 *pflash_cfi02_register(hwaddr base,
                                    const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
-                                   uint32_t sector_len, int nb_blocs,
+                                   uint32_t sector_len,
                                    int nb_mappings, int width,
                                    uint16_t id0, uint16_t id1,
                                    uint16_t id2, uint16_t id3,
@@ -733,7 +733,8 @@ PFlashCFI02 *pflash_cfi02_register(hwaddr base,
     if (blk) {
         qdev_prop_set_drive(dev, "drive", blk, &error_abort);
     }
-    qdev_prop_set_uint32(dev, "num-blocks", nb_blocs);
+    assert(size % sector_len == 0);
+    qdev_prop_set_uint32(dev, "num-blocks", size / sector_len);
     qdev_prop_set_uint32(dev, "sector-length", sector_len);
     qdev_prop_set_uint8(dev, "width", width);
     qdev_prop_set_uint8(dev, "mappings", nb_mappings);
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index 9a5be54a85..34727c5b1f 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -110,16 +110,13 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
     int64_t size;
     char *fatal_errmsg = NULL;
     hwaddr phys_addr = 0x100000000ULL;
-    int sector_bits, sector_size;
+    uint32_t sector_size = 4096;
     PFlashCFI01 *system_flash;
     MemoryRegion *flash_mem;
     char name[64];
     void *flash_ptr;
     int ret, flash_size;
 
-    sector_bits = 12;
-    sector_size = 1 << sector_bits;
-
     for (unit = 0;
          (unit < FLASH_MAP_UNIT_MAX &&
           (pflash_drv = drive_get(IF_PFLASH, 0, unit)) != NULL);
@@ -162,7 +159,6 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
         snprintf(name, sizeof name, "system.flash%d", unit);
         system_flash = pflash_cfi01_register(phys_addr, name,
                                              size, blk, sector_size,
-                                             size >> sector_bits,
                                              1      /* width */,
                                              0x0000 /* id0 */,
                                              0x0000 /* id1 */,
diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index f726355309..09f411ed07 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -116,7 +116,7 @@ static void lm32_evr_init(MachineState *machine)
     /* Spansion S29NS128P */
     pflash_cfi02_register(flash_base, "lm32_evr.flash", flash_size,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          flash_sector_size, flash_size / flash_sector_size,
+                          flash_sector_size,
                           1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
 
     /* create irq lines */
@@ -209,7 +209,7 @@ static void lm32_uclinux_init(MachineState *machine)
     /* Spansion S29NS128P */
     pflash_cfi02_register(flash_base, "lm32_uclinux.flash", flash_size,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          flash_sector_size, flash_size / flash_sector_size,
+                          flash_sector_size,
                           1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
 
     /* create irq lines */
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index ece7e3b699..46b0f51fdf 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -123,7 +123,7 @@ milkymist_init(MachineState *machine)
     /* Numonyx JS28F256J3F105 */
     pflash_cfi01_register(flash_base, "milkymist.flash", flash_size,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          flash_sector_size, flash_size / flash_sector_size,
+                          flash_sector_size,
                           2, 0x00, 0x89, 0x00, 0x1d, 1);
 
     /* create irq lines */
diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c
index 74bcc14cda..46904d2012 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -109,7 +109,7 @@ petalogix_ml605_init(MachineState *machine)
      * 10th paremeter 0 means little-endian */
     pflash_cfi01_register(FLASH_BASEADDR, "petalogix_ml605.flash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          64 * KiB, FLASH_SIZE >> 16,
+                          64 * KiB,
                           2, 0x89, 0x18, 0x0000, 0x0, 0);
 
 
diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c
index a07b7f8edf..027c31fdcc 100644
--- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
+++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
@@ -90,7 +90,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
     pflash_cfi01_register(FLASH_BASEADDR,
                           "petalogix_s3adsp1800.flash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          64 * KiB, FLASH_SIZE >> 16,
+                          64 * KiB,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
 
     dev = qdev_create(NULL, "xlnx.xps-intc");
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 76b81b7402..e5be4367b6 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -1208,7 +1208,6 @@ void mips_malta_init(MachineState *machine)
     DriveInfo *dinfo;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     int fl_idx = 0;
-    int fl_sectors = bios_size >> 16;
     int be;
 
     DeviceState *dev = qdev_create(NULL, TYPE_MIPS_MALTA);
@@ -1268,15 +1267,15 @@ void mips_malta_init(MachineState *machine)
 #ifdef DEBUG_BOARD_INIT
     if (dinfo) {
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
-               "addr %08llx '%s' %x\n",
+               "addr %08llx '%s'\n",
                fl_idx, FLASH_SIZE, FLASH_ADDRESS,
-               blk_name(dinfo->bdrv), fl_sectors);
+               blk_name(dinfo->bdrv));
     }
 #endif
     fl = pflash_cfi01_register(FLASH_ADDRESS, "mips_malta.bios",
                                FLASH_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                               65536, fl_sectors,
+                               65536,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
     bios = pflash_cfi01_get_memory(fl);
     fl_idx++;
diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index 0b9df466e7..acfd59c17a 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -237,7 +237,7 @@ void mips_r4k_init(MachineState *machine)
         uint32_t mips_rom = 0x00400000;
         if (!pflash_cfi01_register(0x1fc00000, "mips_r4k.bios", mips_rom,
                                    blk_by_legacy_dinfo(dinfo),
-                                   sector_len, mips_rom / sector_len,
+                                   sector_len,
                                    4, 0, 0, 0, 0, be)) {
             fprintf(stderr, "qemu: Error registering flash memory.\n");
         }
diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index a54627903d..7b96840498 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -195,7 +195,7 @@ static void ref405ep_init(MachineState *machine)
         pflash_cfi02_register(0xFFF80000,
                               "ef405ep.bios", bios_size,
                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                              65536, bios_size / 65536, 1,
+                              65536, 1,
                               2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
     } else
@@ -486,7 +486,7 @@ static void taihu_405ep_init(MachineState *machine)
         pflash_cfi02_register(0xFFE00000,
                               "taihu_405ep.bios", bios_size,
                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                              65536, bios_size / 65536, 1,
+                              65536, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
         fl_idx++;
@@ -528,7 +528,7 @@ static void taihu_405ep_init(MachineState *machine)
 #endif
         pflash_cfi02_register(0xfc000000, "taihu_405ep.flash", bios_size,
                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                              65536, bios_size / 65536, 1,
+                              65536, 1,
                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                               1);
         fl_idx++;
diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
index a989a8c439..a5dae67c26 100644
--- a/hw/ppc/sam460ex.c
+++ b/hw/ppc/sam460ex.c
@@ -97,7 +97,7 @@ static int sam460ex_load_uboot(void)
     if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
                                "sam460ex.flash", FLASH_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                               65536, FLASH_SIZE / 65536,
+                               65536,
                                1, 0x89, 0x18, 0x0000, 0x0, 1)) {
         error_report("Error registering flash memory");
         /* XXX: return an error instead? */
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index d2085a839c..4f86c22968 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -229,7 +229,7 @@ static void virtex_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          64 * KiB, FLASH_SIZE >> 16,
+                          64 * KiB,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
 
     cpu_irq = (qemu_irq *) &env->irq_inputs[PPC40x_INPUT_INT];
diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index abd3b67c28..5e6953537c 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -299,7 +299,7 @@ static void r2d_init(MachineState *machine)
      */
     pflash_cfi02_register(0x0, "r2d.flash", FLASH_SIZE / 4,
                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                          16 * KiB, FLASH_SIZE >> 16,
+                          16 * KiB,
                           1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
                           0x555, 0x2aa, 0);
 
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 464a72f11b..24b13eb525 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -17,7 +17,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
                                    const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
-                                   uint32_t sector_len, int nb_blocs,
+                                   uint32_t sector_len,
                                    int width,
                                    uint16_t id0, uint16_t id1,
                                    uint16_t id2, uint16_t id3,
@@ -36,7 +36,7 @@ PFlashCFI02 *pflash_cfi02_register(hwaddr base,
                                    const char *name,
                                    hwaddr size,
                                    BlockBackend *blk,
-                                   uint32_t sector_len, int nb_blocs,
+                                   uint32_t sector_len,
                                    int nb_mappings,
                                    int width,
                                    uint16_t id0, uint16_t id1,
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (8 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2 Markus Armbruster
@ 2019-02-18 12:56 ` Markus Armbruster
  2019-02-18 17:12   ` Laszlo Ersek
                     ` (2 more replies)
  2019-02-18 13:31 ` [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups no-reply
                   ` (10 subsequent siblings)
  20 siblings, 3 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 12:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

pflash_cfi01_register() creates a TYPE_CFI_PFLASH01 device, sets
properties, realizes, and wires up.

We have three modified copies of it, because their users need to set
additional properties, or have the wiring done differently.

Factor out their common part into pflash_cfi01_create().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/arm/vexpress.c        | 22 +++++-----------------
 hw/arm/virt.c            | 26 +++++++++-----------------
 hw/block/pflash_cfi01.c  | 39 +++++++++++++++++++++++++++------------
 hw/xtensa/xtfpga.c       | 18 +++++++-----------
 include/hw/block/flash.h |  8 ++++++++
 5 files changed, 56 insertions(+), 57 deletions(-)

diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index 00913f2655..b23c63ed24 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -515,26 +515,14 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
 static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
                                              DriveInfo *di)
 {
-    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
+    DeviceState *dev;
 
-    if (di) {
-        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
-                            &error_abort);
-    }
-
-    qdev_prop_set_uint32(dev, "num-blocks",
-                         VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE);
-    qdev_prop_set_uint64(dev, "sector-length", VEXPRESS_FLASH_SECT_SIZE);
-    qdev_prop_set_uint8(dev, "width", 4);
+    dev = DEVICE(pflash_cfi01_create(name, VEXPRESS_FLASH_SIZE,
+                                     di ? blk_by_legacy_dinfo(di) : NULL,
+                                     VEXPRESS_FLASH_SECT_SIZE,
+                                     4, 0x89, 0x18, 0x00, 0x00, false));
     qdev_prop_set_uint8(dev, "device-width", 2);
-    qdev_prop_set_bit(dev, "big-endian", false);
-    qdev_prop_set_uint16(dev, "id0", 0x89);
-    qdev_prop_set_uint16(dev, "id1", 0x18);
-    qdev_prop_set_uint16(dev, "id2", 0x00);
-    qdev_prop_set_uint16(dev, "id3", 0x00);
-    qdev_prop_set_string(dev, "name", name);
     qdev_init_nofail(dev);
-
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
     return CFI_PFLASH01(dev);
 }
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index b7d53b2b87..7787918483 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -48,6 +48,7 @@
 #include "exec/address-spaces.h"
 #include "qemu/bitops.h"
 #include "qemu/error-report.h"
+#include "qemu/units.h"
 #include "hw/pci-host/gpex.h"
 #include "hw/arm/sysbus-fdt.h"
 #include "hw/platform-bus.h"
@@ -875,29 +876,20 @@ static void create_one_flash(const char *name, hwaddr flashbase,
      * parameters as the flash devices on the Versatile Express board.
      */
     DriveInfo *dinfo = drive_get_next(IF_PFLASH);
-    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
-    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
-    const uint64_t sectorlength = 256 * 1024;
+    DeviceState *dev;
+    SysBusDevice *sbd;
 
-    if (dinfo) {
-        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
-                            &error_abort);
-    }
+    dev = DEVICE(pflash_cfi01_create(name, flashsize,
+                                     dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
+                                     256 * KiB,
+                                     4, 0x89, 0x18, 0x00, 0x00, false));
 
-    qdev_prop_set_uint32(dev, "num-blocks", flashsize / sectorlength);
-    qdev_prop_set_uint64(dev, "sector-length", sectorlength);
-    qdev_prop_set_uint8(dev, "width", 4);
     qdev_prop_set_uint8(dev, "device-width", 2);
-    qdev_prop_set_bit(dev, "big-endian", false);
-    qdev_prop_set_uint16(dev, "id0", 0x89);
-    qdev_prop_set_uint16(dev, "id1", 0x18);
-    qdev_prop_set_uint16(dev, "id2", 0x00);
-    qdev_prop_set_uint16(dev, "id3", 0x00);
-    qdev_prop_set_string(dev, "name", name);
     qdev_init_nofail(dev);
 
+    sbd = SYS_BUS_DEVICE(dev);
     memory_region_add_subregion(sysmem, flashbase,
-                                sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
+                                sysbus_mmio_get_region(sbd, 0));
 
     if (file) {
         char *fn;
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 2e161f937f..00c2efd0d7 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -920,15 +920,14 @@ static void pflash_cfi01_register_types(void)
 
 type_init(pflash_cfi01_register_types)
 
-PFlashCFI01 *pflash_cfi01_register(hwaddr base,
-                                   const char *name,
-                                   hwaddr size,
-                                   BlockBackend *blk,
-                                   uint32_t sector_len,
-                                   int bank_width,
-                                   uint16_t id0, uint16_t id1,
-                                   uint16_t id2, uint16_t id3,
-                                   int be)
+PFlashCFI01 *pflash_cfi01_create(const char *name,
+                                 hwaddr size,
+                                 BlockBackend *blk,
+                                 uint32_t sector_len,
+                                 int bank_width,
+                                 uint16_t id0, uint16_t id1,
+                                 uint16_t id2, uint16_t id3,
+                                 int be)
 {
     DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
 
@@ -945,12 +944,28 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
     qdev_prop_set_uint16(dev, "id2", id2);
     qdev_prop_set_uint16(dev, "id3", id3);
     qdev_prop_set_string(dev, "name", name);
-    qdev_init_nofail(dev);
-
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
     return CFI_PFLASH01(dev);
 }
 
+PFlashCFI01 *pflash_cfi01_register(hwaddr base,
+                                   const char *name,
+                                   hwaddr size,
+                                   BlockBackend *blk,
+                                   uint32_t sector_len,
+                                   int bank_width,
+                                   uint16_t id0, uint16_t id1,
+                                   uint16_t id2, uint16_t id3,
+                                   int be)
+{
+    PFlashCFI01 *dev = pflash_cfi01_create(name, size, blk,
+                                           sector_len, bank_width,
+                                           id0, id1, id2, id3, be);
+
+    qdev_init_nofail(DEVICE(dev));
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
+    return dev;
+}
+
 MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl)
 {
     return &fl->mem;
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index a726d5632a..0e96e73ee2 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -167,21 +167,17 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
                                       DriveInfo *dinfo, int be)
 {
     SysBusDevice *s;
-    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
+    PFlashCFI01 *dev = pflash_cfi01_create("xtfpga.io.flash",
+                                           board->flash->size,
+                                           blk_by_legacy_dinfo(dinfo),
+                                           board->flash->sector_size,
+                                           2, 0, 0, 0, 0, be);
 
-    qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
-                        &error_abort);
-    qdev_prop_set_uint32(dev, "num-blocks",
-                         board->flash->size / board->flash->sector_size);
-    qdev_prop_set_uint64(dev, "sector-length", board->flash->sector_size);
-    qdev_prop_set_uint8(dev, "width", 2);
-    qdev_prop_set_bit(dev, "big-endian", be);
-    qdev_prop_set_string(dev, "name", "xtfpga.io.flash");
-    qdev_init_nofail(dev);
+    qdev_init_nofail(DEVICE(dev));
     s = SYS_BUS_DEVICE(dev);
     memory_region_add_subregion(address_space, board->flash->base,
                                 sysbus_mmio_get_region(s, 0));
-    return CFI_PFLASH01(dev);
+    return dev;
 }
 
 static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 24b13eb525..dbb25ba382 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -13,6 +13,14 @@
 
 typedef struct PFlashCFI01 PFlashCFI01;
 
+PFlashCFI01 *pflash_cfi01_create(const char *name,
+                                 hwaddr size,
+                                 BlockBackend *blk,
+                                 uint32_t sector_len,
+                                 int width,
+                                 uint16_t id0, uint16_t id1,
+                                 uint16_t id2, uint16_t id3,
+                                 int be);
 PFlashCFI01 *pflash_cfi01_register(hwaddr base,
                                    const char *name,
                                    hwaddr size,
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (9 preceding siblings ...)
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some Markus Armbruster
@ 2019-02-18 13:31 ` no-reply
  2019-02-18 17:16 ` no-reply
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-18 13:31 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
03f9a76b8c hw/arm hw/xtensa: De-duplicate pflash creation code some
4e432c01fe pflash: Clean up after commit 368a354f02b part 2
bd61cf81c3 pflash: Clean up after commit 368a354f02b part 1
31e9871f71 mips_malta: Clean up definition of flash memory size somewhat
66c8ac0932 r2d: Flash memory creation is confused about size, mark FIXME
857cd68a50 ppc405_boards: Don't size flash memory to match backing image
170a8ce912 sam460ex: Don't size flash memory to match backing image
aa2df2f4fd hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
588d5b718c pflash: Macro PFLASH_BUG() is used just once, expand
f4339a63b6 pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit f4339a63b6dd (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#127: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#339: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#357: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 588d5b718cc4 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit aa2df2f4fd70 (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit 170a8ce912fd (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit 857cd68a500d (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 66c8ac09327b (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit 31e9871f7159 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit bd61cf81c38f (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#89: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#97: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 4e432c01fea3 (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 03f9a76b8cbd (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image Markus Armbruster
@ 2019-02-18 16:36   ` BALATON Zoltan
  2019-02-18 17:57     ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: BALATON Zoltan @ 2019-02-18 16:36 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, alex.bennee, qemu-ppc

Hello,

On Mon, 18 Feb 2019, Markus Armbruster wrote:
> Machine "sam460ex" maps its flash memory at address 0xFFF00000.  When
> no image is supplied, its size is 1MiB (0x100000).  Else, it's the
> size of the image rounded up to the next multiple of 64KiB.
>
> The rounding is actually useless: pflash_cfi01_realize() fails with
> "failed to read the initial flash content" unless it's a no-op.
>
> I have no idea what happens when the pflash's size exceeds 1MiB.
> Useful outcomes seem unlikely.
>
> I guess memory at the end of the address space remains unmapped when
> it's smaller than 1MiB.  Again, useful outcomes seem unlikely.

I'm not sure where this was coming from but it predates my changes so no 
idea either.

> Set the flash memory size to 1MiB regardless of image size, to match
> the physical hardware.

Actually the real hardware seems to have a 512 kB flash chip:
https://eu.mouser.com/datasheet/2/268/atmel_AT49BV040B-1180330.pdf
so while you're at it you could change FLASH_SIZE to match that.

> Cc: BALATON Zoltan <balaton@eik.bme.hu>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> hw/ppc/sam460ex.c | 23 ++++++++---------------
> 1 file changed, 8 insertions(+), 15 deletions(-)
>
> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
> index 75250d49e4..ca8d7ab9c6 100644
> --- a/hw/ppc/sam460ex.c
> +++ b/hw/ppc/sam460ex.c
> @@ -92,31 +92,24 @@ struct boot_info {
> static int sam460ex_load_uboot(void)
> {
>     DriveInfo *dinfo;
> -    BlockBackend *blk = NULL;
> -    hwaddr base = FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32);
> -    long bios_size = FLASH_SIZE;
> -    int fl_sectors;
>
>     dinfo = drive_get(IF_PFLASH, 0, 0);
> -    if (dinfo) {
> -        blk = blk_by_legacy_dinfo(dinfo);
> -        bios_size = blk_getlength(blk);

After this maybe the
#include "sysemu/block-backend.h"
can also be dropped from the includes?

> -    }
> -    fl_sectors = (bios_size + 65535) >> 16;
> -
> -    if (!pflash_cfi01_register(base, NULL, "sam460ex.flash", bios_size,
> -                               blk, 64 * KiB, fl_sectors,
> +    if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
> +                               NULL, "sam460ex.flash", FLASH_SIZE,
> +                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                               65536, FLASH_SIZE / 65536,

Could you keep 64 * KiB instead of 65536 here to match other places?

Regards,
BALATON Zoltan

>                                1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>         error_report("Error registering flash memory");
>         /* XXX: return an error instead? */
>         exit(1);
>     }
>
> -    if (!blk) {
> +    if (!dinfo) {
>         /*error_report("No flash image given with the 'pflash' parameter,"
>                 " using default u-boot image");*/
> -        base = UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32);
> -        rom_add_file_fixed(UBOOT_FILENAME, base, -1);
> +        rom_add_file_fixed(UBOOT_FILENAME,
> +                           UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
> +                           -1);
>     }
>
>     return 0;
>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02 Markus Armbruster
@ 2019-02-18 16:40   ` Laszlo Ersek
  2019-02-19 12:49   ` Philippe Mathieu-Daudé
  2019-02-21 15:07   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-18 16:40 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: alex.bennee, kwolf, mreitz, qemu-block, qemu-ppc

On 02/18/19 13:56, Markus Armbruster wrote:
> flash.h's incomplete struct pflash_t is completed both in
> pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
> incompatible.

O_o

> This can hide type errors, such as passing a pflash_t
> created with pflash_cfi02_register() to pflash_cfi01_get_memory().
> 
> Furthermore, POSIX reserves typedef names ending with _t.
> 
> Rename the two structs to PFlashCFI01 and PFlashCFI02.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/vexpress.c        |  8 ++--
>  hw/block/pflash_cfi01.c  | 87 +++++++++++++++++++++-------------------
>  hw/block/pflash_cfi02.c  | 67 ++++++++++++++++---------------
>  hw/i386/pc_sysfw.c       |  2 +-
>  hw/mips/mips_malta.c     |  2 +-
>  hw/xtensa/xtfpga.c       | 10 ++---
>  include/hw/block/flash.h | 53 ++++++++++++++----------
>  7 files changed, 122 insertions(+), 107 deletions(-)

I didn't check larger contexts in the modified files. I also didn't look
for typos or try to verify the patch by recreating it from scratch, and
by comparison. I read through the posted patch and it looks OK to me.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand Markus Armbruster
@ 2019-02-18 16:43   ` Laszlo Ersek
  2019-02-18 17:35     ` Markus Armbruster
  2019-02-19 12:40   ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-18 16:43 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: alex.bennee, kwolf, mreitz, qemu-block, qemu-ppc

On 02/18/19 13:56, Markus Armbruster wrote:
> PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
> BUG", which sounds like a warning, then calls exit(1), followed by
> unreachable goto reset_flash.  All this commit does is expanding the
> macro, so the smell becomes more poignant, and the macro can be
> deleted.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/block/pflash_cfi01.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 9efa7aa9af..f73c30a3ee 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -49,12 +49,6 @@
>  #include "sysemu/sysemu.h"
>  #include "trace.h"
>  
> -#define PFLASH_BUG(fmt, ...) \
> -do { \
> -    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
> -    exit(1); \
> -} while(0)
> -
>  /* #define PFLASH_DEBUG */
>  #ifdef PFLASH_DEBUG
>  #define DPRINTF(fmt, ...)                                   \
> @@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                  pfl->status |= 0x80;
>              } else {
>                  DPRINTF("%s: unknown command for \"write block\"\n", __func__);
> -                PFLASH_BUG("Write block confirm");
> -                goto reset_flash;
> +                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
> +                exit(1);
>              }
>              break;
>          default:
> 

Technically speaking, the commit message is slightly incorrect, where it
says "all this commit does is expanding the macro" -- the "goto" is
being removed as well.

I like the attention to detail in that you didn't add the missing
newline character in the expanded fprintf() ;)

With the commit message tweaked, or not:

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thakns
Laszlo

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2} Markus Armbruster
@ 2019-02-18 16:45   ` Laszlo Ersek
  2019-02-19 12:41   ` Philippe Mathieu-Daudé
  2019-02-21 15:09   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-18 16:45 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: alex.bennee, kwolf, mreitz, qemu-block, qemu-ppc

On 02/18/19 13:56, Markus Armbruster wrote:
> We have two open-coded copies of macro CFI_PFLASH01().  Move the macro
> to the header, so we can ditch the copies.  Move CFI_PFLASH02() to the
> header for symmetry.
> 
> We define macros TYPE_CFI_PFLASH01 and TYPE_CFI_PFLASH02 for type name
> strings, then mostly use the strings.  If the macros are worth
> defining, they are worth using.  Replace the strings by the macros.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/vexpress.c        | 4 ++--
>  hw/arm/virt.c            | 3 ++-
>  hw/block/pflash_cfi01.c  | 3 ---
>  hw/block/pflash_cfi02.c  | 3 ---
>  hw/xtensa/xtfpga.c       | 4 ++--
>  include/hw/block/flash.h | 4 ++++
>  6 files changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index ed46d2e730..00913f2655 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -515,7 +515,7 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>  static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>                                               DriveInfo *di)
>  {
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>  
>      if (di) {
>          qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
> @@ -536,7 +536,7 @@ static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>      qdev_init_nofail(dev);
>  
>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> -    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
> +    return CFI_PFLASH01(dev);
>  }
>  
>  static void vexpress_common_init(MachineState *machine)
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 99c2b6e60d..b7d53b2b87 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -34,6 +34,7 @@
>  #include "hw/arm/arm.h"
>  #include "hw/arm/primecell.h"
>  #include "hw/arm/virt.h"
> +#include "hw/block/flash.h"
>  #include "hw/vfio/vfio-calxeda-xgmac.h"
>  #include "hw/vfio/vfio-amd-xgbe.h"
>  #include "hw/display/ramfb.h"
> @@ -874,7 +875,7 @@ static void create_one_flash(const char *name, hwaddr flashbase,
>       * parameters as the flash devices on the Versatile Express board.
>       */
>      DriveInfo *dinfo = drive_get_next(IF_PFLASH);
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
>      const uint64_t sectorlength = 256 * 1024;
>  
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index f73c30a3ee..43dbb7db26 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -59,9 +59,6 @@ do {                                                        \
>  #define DPRINTF(fmt, ...) do { } while (0)
>  #endif
>  
> -#define CFI_PFLASH01(obj) \
> -    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
> -
>  #define PFLASH_BE          0
>  #define PFLASH_SECURE      1
>  
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 424cc106d6..e9c76d6cfb 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -57,9 +57,6 @@ do {                                                       \
>  
>  #define PFLASH_LAZY_ROMD_THRESHOLD 42
>  
> -#define CFI_PFLASH02(obj) \
> -    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
> -
>  struct PFlashCFI02 {
>      /*< private >*/
>      SysBusDevice parent_obj;
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index 3d59a7a356..a726d5632a 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -167,7 +167,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
>                                        DriveInfo *dinfo, int be)
>  {
>      SysBusDevice *s;
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>  
>      qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
>                          &error_abort);
> @@ -181,7 +181,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
>      s = SYS_BUS_DEVICE(dev);
>      memory_region_add_subregion(address_space, board->flash->base,
>                                  sysbus_mmio_get_region(s, 0));
> -    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
> +    return CFI_PFLASH01(dev);
>  }
>  
>  static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 51d8f60c65..1078dc7238 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -8,6 +8,8 @@
>  /* pflash_cfi01.c */
>  
>  #define TYPE_CFI_PFLASH01 "cfi.pflash01"
> +#define CFI_PFLASH01(obj) \
> +    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
>  
>  typedef struct PFlashCFI01 PFlashCFI01;
>  
> @@ -25,6 +27,8 @@ MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
>  /* pflash_cfi02.c */
>  
>  #define TYPE_CFI_PFLASH02 "cfi.pflash02"
> +#define CFI_PFLASH02(obj) \
> +    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
>  
>  typedef struct PFlashCFI02 PFlashCFI02;
>  
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1 Markus Armbruster
@ 2019-02-18 16:50   ` Laszlo Ersek
  2019-02-19 16:12   ` Philippe Mathieu-Daudé
  2019-02-21 15:57   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-18 16:50 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: alex.bennee, kwolf, mreitz, qemu-block, qemu-ppc

On 02/18/19 13:56, Markus Armbruster wrote:
> QOMification left parameter @qdev unused in pflash_cfi01_register()
> and pflash_cfi02_register().  All callers pass NULL.  Remove.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/collie.c                          | 4 ++--
>  hw/arm/digic_boards.c                    | 2 +-
>  hw/arm/gumstix.c                         | 4 ++--
>  hw/arm/mainstone.c                       | 2 +-
>  hw/arm/musicpal.c                        | 4 ++--
>  hw/arm/omap_sx1.c                        | 4 ++--
>  hw/arm/versatilepb.c                     | 2 +-
>  hw/arm/xilinx_zynq.c                     | 2 +-
>  hw/arm/z2.c                              | 3 +--
>  hw/block/pflash_cfi01.c                  | 2 +-
>  hw/block/pflash_cfi02.c                  | 2 +-
>  hw/i386/pc_sysfw.c                       | 2 +-
>  hw/lm32/lm32_boards.c                    | 4 ++--
>  hw/lm32/milkymist.c                      | 2 +-
>  hw/microblaze/petalogix_ml605_mmu.c      | 3 +--
>  hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
>  hw/mips/mips_malta.c                     | 2 +-
>  hw/mips/mips_r4k.c                       | 2 +-
>  hw/ppc/ppc405_boards.c                   | 6 +++---
>  hw/ppc/sam460ex.c                        | 2 +-
>  hw/ppc/virtex_ml507.c                    | 2 +-
>  hw/sh4/r2d.c                             | 2 +-
>  include/hw/block/flash.h                 | 4 ++--
>  23 files changed, 31 insertions(+), 33 deletions(-)

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2 Markus Armbruster
@ 2019-02-18 17:01   ` Laszlo Ersek
  2019-02-18 17:56     ` Laszlo Ersek
  2019-02-21 16:51   ` Alex Bennée
  1 sibling, 1 reply; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-18 17:01 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: alex.bennee, kwolf, mreitz, qemu-block, qemu-ppc

On 02/18/19 13:56, Markus Armbruster wrote:
> QOMification left parameter @size unused in pflash_cfi01_register()
> and pflash_cfi02_register().  register().  Obviously, @size should
> match @sector_len and @nb_blocs, i.e. size == sector_len * nb_blocs.
> All callers satisfy this.
> 
> Remove @nb_blocs and compute it from @size and @sector_len.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/collie.c                          | 5 +++--
>  hw/arm/digic_boards.c                    | 1 -
>  hw/arm/gumstix.c                         | 4 ++--
>  hw/arm/mainstone.c                       | 2 +-
>  hw/arm/musicpal.c                        | 4 ++--
>  hw/arm/omap_sx1.c                        | 4 ++--
>  hw/arm/versatilepb.c                     | 1 -
>  hw/arm/xilinx_zynq.c                     | 3 +--
>  hw/arm/z2.c                              | 2 +-
>  hw/block/pflash_cfi01.c                  | 5 +++--
>  hw/block/pflash_cfi02.c                  | 5 +++--
>  hw/i386/pc_sysfw.c                       | 6 +-----
>  hw/lm32/lm32_boards.c                    | 4 ++--
>  hw/lm32/milkymist.c                      | 2 +-
>  hw/microblaze/petalogix_ml605_mmu.c      | 2 +-
>  hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
>  hw/mips/mips_malta.c                     | 7 +++----
>  hw/mips/mips_r4k.c                       | 2 +-
>  hw/ppc/ppc405_boards.c                   | 6 +++---
>  hw/ppc/sam460ex.c                        | 2 +-
>  hw/ppc/virtex_ml507.c                    | 2 +-
>  hw/sh4/r2d.c                             | 2 +-
>  include/hw/block/flash.h                 | 4 ++--
>  23 files changed, 36 insertions(+), 41 deletions(-)

> @@ -1268,15 +1267,15 @@ void mips_malta_init(MachineState *machine)
>  #ifdef DEBUG_BOARD_INIT
>      if (dinfo) {
>          printf("Register parallel flash %d size " TARGET_FMT_lx " at "
> -               "addr %08llx '%s' %x\n",
> +               "addr %08llx '%s'\n",
>                 fl_idx, FLASH_SIZE, FLASH_ADDRESS,
> -               blk_name(dinfo->bdrv), fl_sectors);
> +               blk_name(dinfo->bdrv));
>      }
>  #endif

This change is somewhat observable, but I guess it's harmless.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some Markus Armbruster
@ 2019-02-18 17:12   ` Laszlo Ersek
  2019-02-19  8:43   ` Max Filippov
  2019-02-19 14:13   ` Peter Maydell
  2 siblings, 0 replies; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-18 17:12 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: alex.bennee, kwolf, mreitz, qemu-block, qemu-ppc

On 02/18/19 13:56, Markus Armbruster wrote:
> pflash_cfi01_register() creates a TYPE_CFI_PFLASH01 device, sets
> properties, realizes, and wires up.
> 
> We have three modified copies of it, because their users need to set
> additional properties, or have the wiring done differently.
> 
> Factor out their common part into pflash_cfi01_create().
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/vexpress.c        | 22 +++++-----------------
>  hw/arm/virt.c            | 26 +++++++++-----------------
>  hw/block/pflash_cfi01.c  | 39 +++++++++++++++++++++++++++------------
>  hw/xtensa/xtfpga.c       | 18 +++++++-----------
>  include/hw/block/flash.h |  8 ++++++++
>  5 files changed, 56 insertions(+), 57 deletions(-)
> 
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index 00913f2655..b23c63ed24 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -515,26 +515,14 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>  static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>                                               DriveInfo *di)
>  {
> -    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
> +    DeviceState *dev;
>  
> -    if (di) {
> -        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
> -                            &error_abort);
> -    }
> -
> -    qdev_prop_set_uint32(dev, "num-blocks",
> -                         VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE);
> -    qdev_prop_set_uint64(dev, "sector-length", VEXPRESS_FLASH_SECT_SIZE);
> -    qdev_prop_set_uint8(dev, "width", 4);
> +    dev = DEVICE(pflash_cfi01_create(name, VEXPRESS_FLASH_SIZE,
> +                                     di ? blk_by_legacy_dinfo(di) : NULL,
> +                                     VEXPRESS_FLASH_SECT_SIZE,
> +                                     4, 0x89, 0x18, 0x00, 0x00, false));
>      qdev_prop_set_uint8(dev, "device-width", 2);
> -    qdev_prop_set_bit(dev, "big-endian", false);
> -    qdev_prop_set_uint16(dev, "id0", 0x89);
> -    qdev_prop_set_uint16(dev, "id1", 0x18);
> -    qdev_prop_set_uint16(dev, "id2", 0x00);
> -    qdev_prop_set_uint16(dev, "id3", 0x00);
> -    qdev_prop_set_string(dev, "name", name);
>      qdev_init_nofail(dev);
> -
>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
>      return CFI_PFLASH01(dev);
>  }
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index b7d53b2b87..7787918483 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -48,6 +48,7 @@
>  #include "exec/address-spaces.h"
>  #include "qemu/bitops.h"
>  #include "qemu/error-report.h"
> +#include "qemu/units.h"
>  #include "hw/pci-host/gpex.h"
>  #include "hw/arm/sysbus-fdt.h"
>  #include "hw/platform-bus.h"
> @@ -875,29 +876,20 @@ static void create_one_flash(const char *name, hwaddr flashbase,
>       * parameters as the flash devices on the Versatile Express board.
>       */
>      DriveInfo *dinfo = drive_get_next(IF_PFLASH);
> -    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
> -    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
> -    const uint64_t sectorlength = 256 * 1024;
> +    DeviceState *dev;
> +    SysBusDevice *sbd;
>  
> -    if (dinfo) {
> -        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
> -                            &error_abort);
> -    }
> +    dev = DEVICE(pflash_cfi01_create(name, flashsize,
> +                                     dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                                     256 * KiB,
> +                                     4, 0x89, 0x18, 0x00, 0x00, false));
>  
> -    qdev_prop_set_uint32(dev, "num-blocks", flashsize / sectorlength);
> -    qdev_prop_set_uint64(dev, "sector-length", sectorlength);
> -    qdev_prop_set_uint8(dev, "width", 4);
>      qdev_prop_set_uint8(dev, "device-width", 2);
> -    qdev_prop_set_bit(dev, "big-endian", false);
> -    qdev_prop_set_uint16(dev, "id0", 0x89);
> -    qdev_prop_set_uint16(dev, "id1", 0x18);
> -    qdev_prop_set_uint16(dev, "id2", 0x00);
> -    qdev_prop_set_uint16(dev, "id3", 0x00);
> -    qdev_prop_set_string(dev, "name", name);
>      qdev_init_nofail(dev);
>  
> +    sbd = SYS_BUS_DEVICE(dev);
>      memory_region_add_subregion(sysmem, flashbase,
> -                                sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
> +                                sysbus_mmio_get_region(sbd, 0));
>  
>      if (file) {
>          char *fn;
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 2e161f937f..00c2efd0d7 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -920,15 +920,14 @@ static void pflash_cfi01_register_types(void)
>  
>  type_init(pflash_cfi01_register_types)
>  
> -PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> -                                   const char *name,
> -                                   hwaddr size,
> -                                   BlockBackend *blk,
> -                                   uint32_t sector_len,
> -                                   int bank_width,
> -                                   uint16_t id0, uint16_t id1,
> -                                   uint16_t id2, uint16_t id3,
> -                                   int be)
> +PFlashCFI01 *pflash_cfi01_create(const char *name,
> +                                 hwaddr size,
> +                                 BlockBackend *blk,
> +                                 uint32_t sector_len,
> +                                 int bank_width,
> +                                 uint16_t id0, uint16_t id1,
> +                                 uint16_t id2, uint16_t id3,
> +                                 int be)
>  {
>      DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>  
> @@ -945,12 +944,28 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
>      qdev_prop_set_uint16(dev, "id2", id2);
>      qdev_prop_set_uint16(dev, "id3", id3);
>      qdev_prop_set_string(dev, "name", name);
> -    qdev_init_nofail(dev);
> -
> -    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
>      return CFI_PFLASH01(dev);
>  }
>  
> +PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> +                                   const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len,
> +                                   int bank_width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   int be)
> +{
> +    PFlashCFI01 *dev = pflash_cfi01_create(name, size, blk,
> +                                           sector_len, bank_width,
> +                                           id0, id1, id2, id3, be);
> +
> +    qdev_init_nofail(DEVICE(dev));
> +    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> +    return dev;
> +}
> +
>  MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl)
>  {
>      return &fl->mem;
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index a726d5632a..0e96e73ee2 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -167,21 +167,17 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
>                                        DriveInfo *dinfo, int be)
>  {
>      SysBusDevice *s;
> -    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
> +    PFlashCFI01 *dev = pflash_cfi01_create("xtfpga.io.flash",
> +                                           board->flash->size,
> +                                           blk_by_legacy_dinfo(dinfo),
> +                                           board->flash->sector_size,
> +                                           2, 0, 0, 0, 0, be);
>  
> -    qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
> -                        &error_abort);
> -    qdev_prop_set_uint32(dev, "num-blocks",
> -                         board->flash->size / board->flash->sector_size);
> -    qdev_prop_set_uint64(dev, "sector-length", board->flash->sector_size);
> -    qdev_prop_set_uint8(dev, "width", 2);
> -    qdev_prop_set_bit(dev, "big-endian", be);
> -    qdev_prop_set_string(dev, "name", "xtfpga.io.flash");
> -    qdev_init_nofail(dev);
> +    qdev_init_nofail(DEVICE(dev));
>      s = SYS_BUS_DEVICE(dev);
>      memory_region_add_subregion(address_space, board->flash->base,
>                                  sysbus_mmio_get_region(s, 0));
> -    return CFI_PFLASH01(dev);
> +    return dev;
>  }
>  
>  static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 24b13eb525..dbb25ba382 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -13,6 +13,14 @@
>  
>  typedef struct PFlashCFI01 PFlashCFI01;
>  
> +PFlashCFI01 *pflash_cfi01_create(const char *name,
> +                                 hwaddr size,
> +                                 BlockBackend *blk,
> +                                 uint32_t sector_len,
> +                                 int width,
> +                                 uint16_t id0, uint16_t id1,
> +                                 uint16_t id2, uint16_t id3,
> +                                 int be);
>  PFlashCFI01 *pflash_cfi01_register(hwaddr base,
>                                     const char *name,
>                                     hwaddr size,
> 

Writing this patch must have been "fun"; my eyes are bleeding from
cross-referencing the new parameters with the removed properties. :/

I think the patch is correct.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (10 preceding siblings ...)
  2019-02-18 13:31 ` [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups no-reply
@ 2019-02-18 17:16 ` no-reply
  2019-02-18 17:39 ` no-reply
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-18 17:16 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190218125615.18970-1-armbru@redhat.com -> patchew/20190218125615.18970-1-armbru@redhat.com
Switched to a new branch 'test'
9a994e41a5 hw/arm hw/xtensa: De-duplicate pflash creation code some
303fbacd55 pflash: Clean up after commit 368a354f02b part 2
3f16bf66bc pflash: Clean up after commit 368a354f02b part 1
3e2ae31e84 mips_malta: Clean up definition of flash memory size somewhat
d0652958b7 r2d: Flash memory creation is confused about size, mark FIXME
f26f2e4d2d ppc405_boards: Don't size flash memory to match backing image
e5dd4a33f5 sam460ex: Don't size flash memory to match backing image
2eec664e4d hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
83da6876dd pflash: Macro PFLASH_BUG() is used just once, expand
0b9075ea6a pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit 0b9075ea6a77 (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 83da6876dd88 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 2eec664e4dcd (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit e5dd4a33f5aa (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit f26f2e4d2d3f (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit d0652958b7c8 (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit 3e2ae31e8434 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit 3f16bf66bce3 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#90: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#98: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 303fbacd5529 (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 9a994e41a577 (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-18 16:43   ` Laszlo Ersek
@ 2019-02-18 17:35     ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 17:35 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: qemu-devel, kwolf, qemu-ppc, alex.bennee, qemu-block, mreitz

Laszlo Ersek <lersek@redhat.com> writes:

> On 02/18/19 13:56, Markus Armbruster wrote:
>> PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
>> BUG", which sounds like a warning, then calls exit(1), followed by
>> unreachable goto reset_flash.  All this commit does is expanding the
>> macro, so the smell becomes more poignant, and the macro can be
>> deleted.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/block/pflash_cfi01.c | 10 ++--------
>>  1 file changed, 2 insertions(+), 8 deletions(-)
>> 
>> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
>> index 9efa7aa9af..f73c30a3ee 100644
>> --- a/hw/block/pflash_cfi01.c
>> +++ b/hw/block/pflash_cfi01.c
>> @@ -49,12 +49,6 @@
>>  #include "sysemu/sysemu.h"
>>  #include "trace.h"
>>  
>> -#define PFLASH_BUG(fmt, ...) \
>> -do { \
>> -    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
>> -    exit(1); \
>> -} while(0)
>> -
>>  /* #define PFLASH_DEBUG */
>>  #ifdef PFLASH_DEBUG
>>  #define DPRINTF(fmt, ...)                                   \
>> @@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>                  pfl->status |= 0x80;
>>              } else {
>>                  DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>> -                PFLASH_BUG("Write block confirm");
>> -                goto reset_flash;
>> +                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
>> +                exit(1);
>>              }
>>              break;
>>          default:
>> 
>
> Technically speaking, the commit message is slightly incorrect, where it
> says "all this commit does is expanding the macro" -- the "goto" is
> being removed as well.

You're right.  I'll amend the commit message.

> I like the attention to detail in that you didn't add the missing
> newline character in the expanded fprintf() ;)

I wish I could claim it was intentional preservation of a bad smell as
fair warning to future readers...

> With the commit message tweaked, or not:
>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks!

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (11 preceding siblings ...)
  2019-02-18 17:16 ` no-reply
@ 2019-02-18 17:39 ` no-reply
  2019-02-19  4:39 ` no-reply
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-18 17:39 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190218125615.18970-1-armbru@redhat.com -> patchew/20190218125615.18970-1-armbru@redhat.com
Switched to a new branch 'test'
8f917fc996 hw/arm hw/xtensa: De-duplicate pflash creation code some
f63eecee6c pflash: Clean up after commit 368a354f02b part 2
3b2230a827 pflash: Clean up after commit 368a354f02b part 1
f96fda82f8 mips_malta: Clean up definition of flash memory size somewhat
0d2c655ad8 r2d: Flash memory creation is confused about size, mark FIXME
72f3fec4c4 ppc405_boards: Don't size flash memory to match backing image
257f0ac71c sam460ex: Don't size flash memory to match backing image
ec2b9e19b1 hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
f1122cc4d9 pflash: Macro PFLASH_BUG() is used just once, expand
f1832c9809 pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit f1832c9809fd (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit f1122cc4d99f (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit ec2b9e19b179 (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit 257f0ac71c81 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit 72f3fec4c495 (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 0d2c655ad826 (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit f96fda82f805 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit 3b2230a827ee (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#90: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#98: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit f63eecee6c91 (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 8f917fc9969e (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-18 17:01   ` Laszlo Ersek
@ 2019-02-18 17:56     ` Laszlo Ersek
  2019-02-19  5:44       ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-18 17:56 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: alex.bennee, kwolf, mreitz, qemu-block, qemu-ppc

On 02/18/19 18:01, Laszlo Ersek wrote:
> On 02/18/19 13:56, Markus Armbruster wrote:
>> QOMification left parameter @size unused in pflash_cfi01_register()
>> and pflash_cfi02_register().  register().  Obviously, @size should

I meant to point out the typo above, but I got distracted mid-review. Sorry!

Thanks
Laszlo

>> match @sector_len and @nb_blocs, i.e. size == sector_len * nb_blocs.
>> All callers satisfy this.
>>
>> Remove @nb_blocs and compute it from @size and @sector_len.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/arm/collie.c                          | 5 +++--
>>  hw/arm/digic_boards.c                    | 1 -
>>  hw/arm/gumstix.c                         | 4 ++--
>>  hw/arm/mainstone.c                       | 2 +-
>>  hw/arm/musicpal.c                        | 4 ++--
>>  hw/arm/omap_sx1.c                        | 4 ++--
>>  hw/arm/versatilepb.c                     | 1 -
>>  hw/arm/xilinx_zynq.c                     | 3 +--
>>  hw/arm/z2.c                              | 2 +-
>>  hw/block/pflash_cfi01.c                  | 5 +++--
>>  hw/block/pflash_cfi02.c                  | 5 +++--
>>  hw/i386/pc_sysfw.c                       | 6 +-----
>>  hw/lm32/lm32_boards.c                    | 4 ++--
>>  hw/lm32/milkymist.c                      | 2 +-
>>  hw/microblaze/petalogix_ml605_mmu.c      | 2 +-
>>  hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
>>  hw/mips/mips_malta.c                     | 7 +++----
>>  hw/mips/mips_r4k.c                       | 2 +-
>>  hw/ppc/ppc405_boards.c                   | 6 +++---
>>  hw/ppc/sam460ex.c                        | 2 +-
>>  hw/ppc/virtex_ml507.c                    | 2 +-
>>  hw/sh4/r2d.c                             | 2 +-
>>  include/hw/block/flash.h                 | 4 ++--
>>  23 files changed, 36 insertions(+), 41 deletions(-)
> 
>> @@ -1268,15 +1267,15 @@ void mips_malta_init(MachineState *machine)
>>  #ifdef DEBUG_BOARD_INIT
>>      if (dinfo) {
>>          printf("Register parallel flash %d size " TARGET_FMT_lx " at "
>> -               "addr %08llx '%s' %x\n",
>> +               "addr %08llx '%s'\n",
>>                 fl_idx, FLASH_SIZE, FLASH_ADDRESS,
>> -               blk_name(dinfo->bdrv), fl_sectors);
>> +               blk_name(dinfo->bdrv));
>>      }
>>  #endif
> 
> This change is somewhat observable, but I guess it's harmless.
> 
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image
  2019-02-18 16:36   ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
@ 2019-02-18 17:57     ` Markus Armbruster
  2019-02-19  1:19       ` BALATON Zoltan
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-18 17:57 UTC (permalink / raw)
  To: BALATON Zoltan; +Cc: qemu-ppc, alex.bennee, qemu-devel

BALATON Zoltan <balaton@eik.bme.hu> writes:

> Hello,
>
> On Mon, 18 Feb 2019, Markus Armbruster wrote:
>> Machine "sam460ex" maps its flash memory at address 0xFFF00000.  When
>> no image is supplied, its size is 1MiB (0x100000).  Else, it's the
>> size of the image rounded up to the next multiple of 64KiB.
>>
>> The rounding is actually useless: pflash_cfi01_realize() fails with
>> "failed to read the initial flash content" unless it's a no-op.
>>
>> I have no idea what happens when the pflash's size exceeds 1MiB.
>> Useful outcomes seem unlikely.
>>
>> I guess memory at the end of the address space remains unmapped when
>> it's smaller than 1MiB.  Again, useful outcomes seem unlikely.
>
> I'm not sure where this was coming from but it predates my changes so
> no idea either.
>
>> Set the flash memory size to 1MiB regardless of image size, to match
>> the physical hardware.
>
> Actually the real hardware seems to have a 512 kB flash chip:
> https://eu.mouser.com/datasheet/2/268/atmel_AT49BV040B-1180330.pdf

Fascinating.

<http://www.sam4x0.com/sam460ex.html> confirms.

> so while you're at it you could change FLASH_SIZE to match that.

Leads to more questions, below.

>> Cc: BALATON Zoltan <balaton@eik.bme.hu>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>> hw/ppc/sam460ex.c | 23 ++++++++---------------
>> 1 file changed, 8 insertions(+), 15 deletions(-)
>>
>> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
>> index 75250d49e4..ca8d7ab9c6 100644
>> --- a/hw/ppc/sam460ex.c
>> +++ b/hw/ppc/sam460ex.c
>> @@ -92,31 +92,24 @@ struct boot_info {
>> static int sam460ex_load_uboot(void)
>> {
>>     DriveInfo *dinfo;
>> -    BlockBackend *blk = NULL;
>> -    hwaddr base = FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32);
>> -    long bios_size = FLASH_SIZE;
>> -    int fl_sectors;
>>
>>     dinfo = drive_get(IF_PFLASH, 0, 0);
>> -    if (dinfo) {
>> -        blk = blk_by_legacy_dinfo(dinfo);
>> -        bios_size = blk_getlength(blk);
>
> After this maybe the
> #include "sysemu/block-backend.h"
> can also be dropped from the includes?

I'll try.

>> -    }
>> -    fl_sectors = (bios_size + 65535) >> 16;
>> -
>> -    if (!pflash_cfi01_register(base, NULL, "sam460ex.flash", bios_size,
>> -                               blk, 64 * KiB, fl_sectors,
>> +    if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>> +                               NULL, "sam460ex.flash", FLASH_SIZE,
>> +                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>> +                               65536, FLASH_SIZE / 65536,
>
> Could you keep 64 * KiB instead of 65536 here to match other places?

Sure (editing accident).

> Regards,
> BALATON Zoltan
>
>>                                1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>>         error_report("Error registering flash memory");
>>         /* XXX: return an error instead? */
>>         exit(1);
>>     }
>>
>> -    if (!blk) {
>> +    if (!dinfo) {
>>         /*error_report("No flash image given with the 'pflash' parameter,"
>>                 " using default u-boot image");*/
>> -        base = UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32);
>> -        rom_add_file_fixed(UBOOT_FILENAME, base, -1);
>> +        rom_add_file_fixed(UBOOT_FILENAME,
>> +                           UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
>> +                           -1);
>>     }
>>
>>     return 0;

Let's have a look at the resulting function:

    static int sam460ex_load_uboot(void)
    {
        DriveInfo *dinfo;

        dinfo = drive_get(IF_PFLASH, 0, 0);
        if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
                                   "sam460ex.flash", FLASH_SIZE,
                                   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                   65536,
                                   1, 0x89, 0x18, 0x0000, 0x0, 1)) {
            error_report("Error registering flash memory");
            /* XXX: return an error instead? */
            exit(1);
        }

        if (!dinfo) {
            /*error_report("No flash image given with the 'pflash' parameter,"
                    " using default u-boot image");*/
            rom_add_file_fixed(UBOOT_FILENAME,
                               UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
                               -1);
        }

        return 0;
    }

This first creates 1MiB of flash memory mapped at the end of the 32-bit
address space (0xFFF00000..0xFFFFFFFF).

If_PFLASH unit 0 is defined, the flash memory is initialized from that
block backend.

Else, it's initialized to zero.  And then 512KiB of ROM gets mapped on
top of its second half (0xFFF80000..0xFFFFFFFF), initialized from
u-boot-sam460-20100605.bin (which we build).

This doesn't smell right.

I propose to do the following: if IF_PFLASH unit 0 is defined, create
512KiB of flash memory mapped at the end of the 32-bit address space,
else, create 512KiB of ROM there.

Okay?

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image
  2019-02-18 17:57     ` Markus Armbruster
@ 2019-02-19  1:19       ` BALATON Zoltan
  2019-02-19  5:43         ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: BALATON Zoltan @ 2019-02-19  1:19 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: alex.bennee, François Revol, qemu-ppc, qemu-devel

On Mon, 18 Feb 2019, Markus Armbruster wrote:
> BALATON Zoltan <balaton@eik.bme.hu> writes:
>> On Mon, 18 Feb 2019, Markus Armbruster wrote:
>>> Machine "sam460ex" maps its flash memory at address 0xFFF00000.  When
>>> no image is supplied, its size is 1MiB (0x100000).  Else, it's the
>>> size of the image rounded up to the next multiple of 64KiB.
>>>
>>> The rounding is actually useless: pflash_cfi01_realize() fails with
>>> "failed to read the initial flash content" unless it's a no-op.
>>>
>>> I have no idea what happens when the pflash's size exceeds 1MiB.
>>> Useful outcomes seem unlikely.
>>>
>>> I guess memory at the end of the address space remains unmapped when
>>> it's smaller than 1MiB.  Again, useful outcomes seem unlikely.
>>
>> I'm not sure where this was coming from but it predates my changes so
>> no idea either.
>>
>>> Set the flash memory size to 1MiB regardless of image size, to match
>>> the physical hardware.
>>
>> Actually the real hardware seems to have a 512 kB flash chip:
>> https://eu.mouser.com/datasheet/2/268/atmel_AT49BV040B-1180330.pdf
>
> Fascinating.
>
> <http://www.sam4x0.com/sam460ex.html> confirms.
>
>> so while you're at it you could change FLASH_SIZE to match that.
>
> Leads to more questions, below.
>
>>> Cc: BALATON Zoltan <balaton@eik.bme.hu>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> ---
>>> hw/ppc/sam460ex.c | 23 ++++++++---------------
>>> 1 file changed, 8 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
>>> index 75250d49e4..ca8d7ab9c6 100644
>>> --- a/hw/ppc/sam460ex.c
>>> +++ b/hw/ppc/sam460ex.c
>>> @@ -92,31 +92,24 @@ struct boot_info {
>>> static int sam460ex_load_uboot(void)
>>> {
>>>     DriveInfo *dinfo;
>>> -    BlockBackend *blk = NULL;
>>> -    hwaddr base = FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32);
>>> -    long bios_size = FLASH_SIZE;
>>> -    int fl_sectors;
>>>
>>>     dinfo = drive_get(IF_PFLASH, 0, 0);
>>> -    if (dinfo) {
>>> -        blk = blk_by_legacy_dinfo(dinfo);
>>> -        bios_size = blk_getlength(blk);
>>
>> After this maybe the
>> #include "sysemu/block-backend.h"
>> can also be dropped from the includes?
>
> I'll try.
>
>>> -    }
>>> -    fl_sectors = (bios_size + 65535) >> 16;
>>> -
>>> -    if (!pflash_cfi01_register(base, NULL, "sam460ex.flash", bios_size,
>>> -                               blk, 64 * KiB, fl_sectors,
>>> +    if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>> +                               NULL, "sam460ex.flash", FLASH_SIZE,
>>> +                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>>> +                               65536, FLASH_SIZE / 65536,
>>
>> Could you keep 64 * KiB instead of 65536 here to match other places?
>
> Sure (editing accident).
>
>> Regards,
>> BALATON Zoltan
>>
>>>                                1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>>>         error_report("Error registering flash memory");
>>>         /* XXX: return an error instead? */
>>>         exit(1);
>>>     }
>>>
>>> -    if (!blk) {
>>> +    if (!dinfo) {
>>>         /*error_report("No flash image given with the 'pflash' parameter,"
>>>                 " using default u-boot image");*/
>>> -        base = UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32);
>>> -        rom_add_file_fixed(UBOOT_FILENAME, base, -1);
>>> +        rom_add_file_fixed(UBOOT_FILENAME,
>>> +                           UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>> +                           -1);
>>>     }
>>>
>>>     return 0;
>
> Let's have a look at the resulting function:
>
>    static int sam460ex_load_uboot(void)
>    {
>        DriveInfo *dinfo;
>
>        dinfo = drive_get(IF_PFLASH, 0, 0);
>        if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>                                   "sam460ex.flash", FLASH_SIZE,
>                                   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,

There's still a blk_* function here which I did not notice so the 
"sysemu/block-backend.h" is probably still needed.

>                                   65536,
>                                   1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>            error_report("Error registering flash memory");
>            /* XXX: return an error instead? */
>            exit(1);
>        }
>
>        if (!dinfo) {
>            /*error_report("No flash image given with the 'pflash' parameter,"
>                    " using default u-boot image");*/
>            rom_add_file_fixed(UBOOT_FILENAME,
>                               UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
>                               -1);
>        }
>
>        return 0;
>    }
>
> This first creates 1MiB of flash memory mapped at the end of the 32-bit
> address space (0xFFF00000..0xFFFFFFFF).
>
> If_PFLASH unit 0 is defined, the flash memory is initialized from that
> block backend.
>
> Else, it's initialized to zero.  And then 512KiB of ROM gets mapped on
> top of its second half (0xFFF80000..0xFFFFFFFF), initialized from
> u-boot-sam460-20100605.bin (which we build).
>
> This doesn't smell right.

Unfortunately I don't know much about how this should work. Maybe François 
can remember where this comes from, this was already there when I started 
working on it, but I suspect maybe he's copied it from some other board in 
QEMU as well. The sam460ex was based on ppc440_bamboo but that does not 
seem to have flash ROM. Memory SPD EEPROM came from mips_malta (cleaned up 
since but it shows that that was also used as inspiration) but that's also 
not the same so maybe it was adapted for sam460ex or came from some other 
example in QEMU. This was already there in François's initial commit:

https://github.com/mmuman/qemu/commit/d10cc631645f3893d53e60cc00c618470b4de52c#diff-73d06ebbc1301aab78105d853097fa2fR42

and later was slightly modified (maybe to rebase for changes in QEMU):

https://github.com/mmuman/qemu/commit/768136b08a6b9b69e707af2c478b68a5935bb8f0#diff-73d06ebbc1301aab78105d853097fa2fL1267

The comment says these values come from U-Boot:

https://git.qemu.org/?p=u-boot-sam460ex.git;a=blob;f=include/configs/Sam460ex.h;h=71064a9601c89dd3ce381d07e0def6c9d5294d44;hb=HEAD#l123

and that indeed has flash size of 1 MB but then builds an image that's 
exactly 512 kB which should be mapped at end of 4GB because the initial 
program counter of the CPU is 0xfffffffc and board has a 512kB flash chip 
as well.

> I propose to do the following: if IF_PFLASH unit 0 is defined, create
> 512KiB of flash memory mapped at the end of the 32-bit address space,
> else, create 512KiB of ROM there.
>
> Okay?

AFAIU the above U-Boot could handle up to 1MB of ROM but board has a 512kB 
chip so probably it makes sense to use 512k here. However since this is 
not well understood (at least by me) I'm not asking you to do that and 
maybe just leave it as it is now. This can be revisited when NVRAM is 
implemented later as this may be related to that (or not) this would need 
understanding of some details I don't have yet. But if you feel confident 
enough to clean this up feel free to go ahead.

Thank you,
BALATON Zoltan

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 05/10] ppc405_boards: " Markus Armbruster
@ 2019-02-19  3:55   ` David Gibson
  2019-02-19 15:28   ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
  2019-02-21 15:20   ` [Qemu-devel] " Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: David Gibson @ 2019-02-19  3:55 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, alex.bennee, lersek, kwolf, mreitz, qemu-block, qemu-ppc

[-- Attachment #1: Type: text/plain, Size: 6449 bytes --]

On Mon, Feb 18, 2019 at 01:56:10PM +0100, Markus Armbruster wrote:
> Machine "ref405ep" maps its flash memory at address 2^32 - image size.
> Image size is rounded up to the next multiple of 64KiB.  Useless,
> because pflash_cfi02_realize() fails with "failed to read the initial
> flash content" unless the rounding is a no-op.
> 
> If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
> other stuff.  No idea how that would play out, but a useful outcomes
> seem unlikely.
> 
> Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
> regardless of image size, to match the physical hardware.
> 
> Machine "taihu" maps its boot flash memory similarly.  The code even
> has a comment /* XXX: should check that size is 2MB */, followed by
> disabled code to adjust the size to 2MiB regardless of image size.
> 
> Its code to map its application flash memory looks the same, except
> there the XXX comment asks for 32MiB, and the code to adjust the size
> isn't disabled.  Note that pflash_cfi02_realize() fails with "failed
> to read the initial flash content" for images smaller than 32MiB.
> 
> Map the boot flash memory at fixed address 0xFFE00000 with size 2MiB,
> to match the physical hardware.  Delete dead code from application
> flash mapping, and simplify some.
> 
> Cc: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  hw/ppc/ppc405_boards.c | 53 +++++++++++++-----------------------------
>  1 file changed, 16 insertions(+), 37 deletions(-)
> 
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index f47b15f10e..728154aebb 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -158,7 +158,7 @@ static void ref405ep_init(MachineState *machine)
>      target_ulong kernel_base, initrd_base;
>      long kernel_size, initrd_size;
>      int linux_boot;
> -    int fl_idx, fl_sectors, len;
> +    int len;
>      DriveInfo *dinfo;
>      MemoryRegion *sysmem = get_system_memory();
>  
> @@ -185,26 +185,19 @@ static void ref405ep_init(MachineState *machine)
>  #ifdef DEBUG_BOARD_INIT
>      printf("%s: register BIOS\n", __func__);
>  #endif
> -    fl_idx = 0;
>  #ifdef USE_FLASH_BIOS
> -    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
> +    dinfo = drive_get(IF_PFLASH, 0, 0);
>      if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        fl_sectors = (bios_size + 65535) >> 16;
>  #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr %lx '%s' %d\n",
> -               fl_idx, bios_size, -bios_size,
> -               blk_name(blk), fl_sectors);
> +        printf("Register parallel flash\n");
>  #endif
> -        pflash_cfi02_register((uint32_t)(-bios_size),
> +        bios_size = 0x80000;
> +        pflash_cfi02_register(0xFFF80000,
>                                NULL, "ef405ep.bios", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,
>                                2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
> -        fl_idx++;
>      } else
>  #endif
>      {
> @@ -455,7 +448,7 @@ static void taihu_405ep_init(MachineState *machine)
>      target_ulong kernel_base, initrd_base;
>      long kernel_size, initrd_size;
>      int linux_boot;
> -    int fl_idx, fl_sectors;
> +    int fl_idx;
>      DriveInfo *dinfo;
>  
>      /* RAM is soldered to the board so the size cannot be changed */
> @@ -486,21 +479,14 @@ static void taihu_405ep_init(MachineState *machine)
>  #if defined(USE_FLASH_BIOS)
>      dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>      if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        /* XXX: should check that size is 2MB */
> -        //        bios_size = 2 * 1024 * 1024;
> -        fl_sectors = (bios_size + 65535) >> 16;
>  #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr %lx '%s' %d\n",
> -               fl_idx, bios_size, -bios_size,
> -               blk_name(blk), fl_sectors);
> +        printf("Register boot flash\n");
>  #endif
> -        pflash_cfi02_register((uint32_t)(-bios_size),
> +        bios_size = 2 * MiB;
> +        pflash_cfi02_register(0xFFE00000,
>                                NULL, "taihu_405ep.bios", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
>          fl_idx++;
> @@ -536,20 +522,13 @@ static void taihu_405ep_init(MachineState *machine)
>      /* Register Linux flash */
>      dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>      if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        /* XXX: should check that size is 32MB */
>          bios_size = 32 * MiB;
> -        fl_sectors = (bios_size + 65535) >> 16;
>  #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr " TARGET_FMT_lx " '%s'\n",
> -               fl_idx, bios_size, (target_ulong)0xfc000000,
> -               blk_name(blk));
> +        printf("Register application flash\n"
>  #endif
>          pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
>          fl_idx++;

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (12 preceding siblings ...)
  2019-02-18 17:39 ` no-reply
@ 2019-02-19  4:39 ` no-reply
  2019-02-19  4:43 ` no-reply
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-19  4:39 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190218125615.18970-1-armbru@redhat.com -> patchew/20190218125615.18970-1-armbru@redhat.com
Switched to a new branch 'test'
7003d72a5f hw/arm hw/xtensa: De-duplicate pflash creation code some
0f5bb14893 pflash: Clean up after commit 368a354f02b part 2
0ddfc52fb8 pflash: Clean up after commit 368a354f02b part 1
a88cfc5bbf mips_malta: Clean up definition of flash memory size somewhat
06b58eb0a8 r2d: Flash memory creation is confused about size, mark FIXME
fd280c6abc ppc405_boards: Don't size flash memory to match backing image
85a5bb56ec sam460ex: Don't size flash memory to match backing image
4f66728f2f hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
368c51060a pflash: Macro PFLASH_BUG() is used just once, expand
209d90e8f1 pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit 209d90e8f163 (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 368c51060aff (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 4f66728f2f5a (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit 85a5bb56ec18 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit fd280c6abca7 (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 06b58eb0a8e9 (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit a88cfc5bbf98 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit 0ddfc52fb852 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#90: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#98: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 0f5bb148930a (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 7003d72a5f0f (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (13 preceding siblings ...)
  2019-02-19  4:39 ` no-reply
@ 2019-02-19  4:43 ` no-reply
  2019-02-19 13:06 ` no-reply
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-19  4:43 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]      patchew/20190218125615.18970-1-armbru@redhat.com -> patchew/20190218125615.18970-1-armbru@redhat.com
Submodule 'capstone' (https://git.qemu.org/git/capstone.git) registered for path 'capstone'
Submodule 'dtc' (https://git.qemu.org/git/dtc.git) registered for path 'dtc'
Submodule 'roms/QemuMacDrivers' (https://git.qemu.org/git/QemuMacDrivers.git) registered for path 'roms/QemuMacDrivers'
Submodule 'roms/SLOF' (https://git.qemu.org/git/SLOF.git) registered for path 'roms/SLOF'
Submodule 'roms/ipxe' (https://git.qemu.org/git/ipxe.git) registered for path 'roms/ipxe'
Submodule 'roms/openbios' (https://git.qemu.org/git/openbios.git) registered for path 'roms/openbios'
Submodule 'roms/openhackware' (https://git.qemu.org/git/openhackware.git) registered for path 'roms/openhackware'
Submodule 'roms/qemu-palcode' (https://git.qemu.org/git/qemu-palcode.git) registered for path 'roms/qemu-palcode'
Submodule 'roms/seabios' (https://git.qemu.org/git/seabios.git/) registered for path 'roms/seabios'
Submodule 'roms/seabios-hppa' (https://github.com/hdeller/seabios-hppa.git) registered for path 'roms/seabios-hppa'
Submodule 'roms/sgabios' (https://git.qemu.org/git/sgabios.git) registered for path 'roms/sgabios'
Submodule 'roms/skiboot' (https://git.qemu.org/git/skiboot.git) registered for path 'roms/skiboot'
Submodule 'roms/u-boot' (https://git.qemu.org/git/u-boot.git) registered for path 'roms/u-boot'
Submodule 'roms/u-boot-sam460ex' (https://git.qemu.org/git/u-boot-sam460ex.git) registered for path 'roms/u-boot-sam460ex'
Submodule 'tests/fp/berkeley-softfloat-3' (https://github.com/cota/berkeley-softfloat-3) registered for path 'tests/fp/berkeley-softfloat-3'
Submodule 'tests/fp/berkeley-testfloat-3' (https://github.com/cota/berkeley-testfloat-3) registered for path 'tests/fp/berkeley-testfloat-3'
Submodule 'ui/keycodemapdb' (https://git.qemu.org/git/keycodemapdb.git) registered for path 'ui/keycodemapdb'
Cloning into 'capstone'...
Submodule path 'capstone': checked out '22ead3e0bfdb87516656453336160e0a37b066bf'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '88f18909db731a627456f26d779445f84e449536'
Cloning into 'roms/QemuMacDrivers'...
Submodule path 'roms/QemuMacDrivers': checked out '90c488d5f4a407342247b9ea869df1c2d9c8e266'
Cloning into 'roms/SLOF'...
Submodule path 'roms/SLOF': checked out 'a5b428e1c1eae703bdd62a3f527223c291ee3fdc'
Cloning into 'roms/ipxe'...
Submodule path 'roms/ipxe': checked out 'de4565cbe76ea9f7913a01f331be3ee901bb6e17'
Cloning into 'roms/openbios'...
Submodule path 'roms/openbios': checked out '3464681b2b5983df80086a40179d324102347da3'
Cloning into 'roms/openhackware'...
Submodule path 'roms/openhackware': checked out 'c559da7c8eec5e45ef1f67978827af6f0b9546f5'
Cloning into 'roms/qemu-palcode'...
Submodule path 'roms/qemu-palcode': checked out '51c237d7e20d05100eacadee2f61abc17e6bc097'
Cloning into 'roms/seabios'...
Submodule path 'roms/seabios': checked out 'a698c8995ffb2838296ec284fe3c4ad33dfca307'
Cloning into 'roms/seabios-hppa'...
Submodule path 'roms/seabios-hppa': checked out '1ef99a01572c2581c30e16e6fe69e9ea2ef92ce0'
Cloning into 'roms/sgabios'...
Submodule path 'roms/sgabios': checked out 'cbaee52287e5f32373181cff50a00b6c4ac9015a'
Cloning into 'roms/skiboot'...
Submodule path 'roms/skiboot': checked out 'e0ee24c27a172bcf482f6f2bc905e6211c134bcc'
Cloning into 'roms/u-boot'...
Submodule path 'roms/u-boot': checked out 'd85ca029f257b53a96da6c2fb421e78a003a9943'
Cloning into 'roms/u-boot-sam460ex'...
Submodule path 'roms/u-boot-sam460ex': checked out '60b3916f33e617a815973c5a6df77055b2e3a588'
Cloning into 'tests/fp/berkeley-softfloat-3'...
Submodule path 'tests/fp/berkeley-softfloat-3': checked out 'b64af41c3276f97f0e181920400ee056b9c88037'
Cloning into 'tests/fp/berkeley-testfloat-3'...
Submodule path 'tests/fp/berkeley-testfloat-3': checked out '5a59dcec19327396a011a17fd924aed4fec416b3'
Cloning into 'ui/keycodemapdb'...
Submodule path 'ui/keycodemapdb': checked out '6b3d716e2b6472eb7189d3220552280ef3d832ce'
Switched to a new branch 'test'
7003d72 hw/arm hw/xtensa: De-duplicate pflash creation code some
0f5bb14 pflash: Clean up after commit 368a354f02b part 2
0ddfc52 pflash: Clean up after commit 368a354f02b part 1
a88cfc5 mips_malta: Clean up definition of flash memory size somewhat
06b58eb r2d: Flash memory creation is confused about size, mark FIXME
fd280c6 ppc405_boards: Don't size flash memory to match backing image
85a5bb5 sam460ex: Don't size flash memory to match backing image
4f66728 hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
368c510 pflash: Macro PFLASH_BUG() is used just once, expand
209d90e pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit 209d90e8f163 (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 368c51060aff (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 4f66728f2f5a (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit 85a5bb56ec18 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit fd280c6abca7 (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 06b58eb0a8e9 (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit a88cfc5bbf98 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit 0ddfc52fb852 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#90: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#98: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 0f5bb148930a (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 7003d72a5f0f (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image
  2019-02-19  1:19       ` BALATON Zoltan
@ 2019-02-19  5:43         ` Markus Armbruster
  2019-02-19 11:34           ` BALATON Zoltan
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19  5:43 UTC (permalink / raw)
  To: BALATON Zoltan; +Cc: qemu-ppc, François Revol, alex.bennee, qemu-devel

BALATON Zoltan <balaton@eik.bme.hu> writes:

> On Mon, 18 Feb 2019, Markus Armbruster wrote:
>> BALATON Zoltan <balaton@eik.bme.hu> writes:
>>> On Mon, 18 Feb 2019, Markus Armbruster wrote:
>>>> Machine "sam460ex" maps its flash memory at address 0xFFF00000.  When
>>>> no image is supplied, its size is 1MiB (0x100000).  Else, it's the
>>>> size of the image rounded up to the next multiple of 64KiB.
>>>>
>>>> The rounding is actually useless: pflash_cfi01_realize() fails with
>>>> "failed to read the initial flash content" unless it's a no-op.
>>>>
>>>> I have no idea what happens when the pflash's size exceeds 1MiB.
>>>> Useful outcomes seem unlikely.
>>>>
>>>> I guess memory at the end of the address space remains unmapped when
>>>> it's smaller than 1MiB.  Again, useful outcomes seem unlikely.
>>>
>>> I'm not sure where this was coming from but it predates my changes so
>>> no idea either.
>>>
>>>> Set the flash memory size to 1MiB regardless of image size, to match
>>>> the physical hardware.
>>>
>>> Actually the real hardware seems to have a 512 kB flash chip:
>>> https://eu.mouser.com/datasheet/2/268/atmel_AT49BV040B-1180330.pdf
>>
>> Fascinating.
>>
>> <http://www.sam4x0.com/sam460ex.html> confirms.
>>
>>> so while you're at it you could change FLASH_SIZE to match that.
>>
>> Leads to more questions, below.
[...]
>> Let's have a look at the resulting function:
>>
>>    static int sam460ex_load_uboot(void)
>>    {
>>        DriveInfo *dinfo;
>>
>>        dinfo = drive_get(IF_PFLASH, 0, 0);
>>        if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>                                   "sam460ex.flash", FLASH_SIZE,
>>                                   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
[...]
>>                                   65536,
>>                                   1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>>            error_report("Error registering flash memory");
>>            /* XXX: return an error instead? */
>>            exit(1);
>>        }
>>
>>        if (!dinfo) {
>>            /*error_report("No flash image given with the 'pflash' parameter,"
>>                    " using default u-boot image");*/
>>            rom_add_file_fixed(UBOOT_FILENAME,
>>                               UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>                               -1);
>>        }
>>
>>        return 0;
>>    }
>>
>> This first creates 1MiB of flash memory mapped at the end of the 32-bit
>> address space (0xFFF00000..0xFFFFFFFF).
>>
>> If_PFLASH unit 0 is defined, the flash memory is initialized from that
>> block backend.
>>
>> Else, it's initialized to zero.  And then 512KiB of ROM gets mapped on
>> top of its second half (0xFFF80000..0xFFFFFFFF), initialized from
>> u-boot-sam460-20100605.bin (which we build).
>>
>> This doesn't smell right.
>
> Unfortunately I don't know much about how this should work. Maybe
> François can remember where this comes from, this was already there
> when I started working on it, but I suspect maybe he's copied it from
> some other board in QEMU as well. The sam460ex was based on
> ppc440_bamboo but that does not seem to have flash ROM. Memory SPD
> EEPROM came from mips_malta (cleaned up since but it shows that that
> was also used as inspiration) but that's also not the same so maybe it
> was adapted for sam460ex or came from some other example in QEMU. This
> was already there in François's initial commit:
>
> https://github.com/mmuman/qemu/commit/d10cc631645f3893d53e60cc00c618470b4de52c#diff-73d06ebbc1301aab78105d853097fa2fR42
>
> and later was slightly modified (maybe to rebase for changes in QEMU):
>
> https://github.com/mmuman/qemu/commit/768136b08a6b9b69e707af2c478b68a5935bb8f0#diff-73d06ebbc1301aab78105d853097fa2fL1267
>
> The comment says these values come from U-Boot:
>
> https://git.qemu.org/?p=u-boot-sam460ex.git;a=blob;f=include/configs/Sam460ex.h;h=71064a9601c89dd3ce381d07e0def6c9d5294d44;hb=HEAD#l123
>
> and that indeed has flash size of 1 MB but then builds an image that's
> exactly 512 kB which should be mapped at end of 4GB because the
> initial program counter of the CPU is 0xfffffffc and board has a 512kB
> flash chip as well.
>
>> I propose to do the following: if IF_PFLASH unit 0 is defined, create
>> 512KiB of flash memory mapped at the end of the 32-bit address space,
>> else, create 512KiB of ROM there.
>>
>> Okay?
>
> AFAIU the above U-Boot could handle up to 1MB of ROM but board has a
> 512kB chip so probably it makes sense to use 512k here. However since
> this is not well understood (at least by me) I'm not asking you to do
> that and maybe just leave it as it is now. This can be revisited when
> NVRAM is implemented later as this may be related to that (or not)
> this would need understanding of some details I don't have yet. But if
> you feel confident enough to clean this up feel free to go ahead.

Then let's use my patch as is, plus a FIXME comment explaining the
situation.  Okay?

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-18 17:56     ` Laszlo Ersek
@ 2019-02-19  5:44       ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19  5:44 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: qemu-devel, kwolf, qemu-ppc, alex.bennee, qemu-block, mreitz

Laszlo Ersek <lersek@redhat.com> writes:

> On 02/18/19 18:01, Laszlo Ersek wrote:
>> On 02/18/19 13:56, Markus Armbruster wrote:
>>> QOMification left parameter @size unused in pflash_cfi01_register()
>>> and pflash_cfi02_register().  register().  Obviously, @size should
>
> I meant to point out the typo above, but I got distracted mid-review. Sorry!

Will fix, thanks!

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some Markus Armbruster
  2019-02-18 17:12   ` Laszlo Ersek
@ 2019-02-19  8:43   ` Max Filippov
  2019-02-19 13:01     ` Markus Armbruster
  2019-02-19 14:13   ` Peter Maydell
  2 siblings, 1 reply; 97+ messages in thread
From: Max Filippov @ 2019-02-19  8:43 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, Kevin Wolf, Qemu-block, Alex Bennée, Max Reitz,
	qemu-ppc, lersek

On Mon, Feb 18, 2019 at 5:07 AM Markus Armbruster <armbru@redhat.com> wrote:
>
> pflash_cfi01_register() creates a TYPE_CFI_PFLASH01 device, sets
> properties, realizes, and wires up.
>
> We have three modified copies of it, because their users need to set
> additional properties, or have the wiring done differently.
>
> Factor out their common part into pflash_cfi01_create().
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/vexpress.c        | 22 +++++-----------------
>  hw/arm/virt.c            | 26 +++++++++-----------------
>  hw/block/pflash_cfi01.c  | 39 +++++++++++++++++++++++++++------------
>  hw/xtensa/xtfpga.c       | 18 +++++++-----------

I was told that it's better this way when I did that initially:
  http://lists.gnu.org/archive/html/qemu-devel/2015-09/msg06927.html

Has the idea of "better" changed since then?
I'm fine with the code either way, just curious.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image
  2019-02-19  5:43         ` Markus Armbruster
@ 2019-02-19 11:34           ` BALATON Zoltan
  0 siblings, 0 replies; 97+ messages in thread
From: BALATON Zoltan @ 2019-02-19 11:34 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: alex.bennee, François Revol, qemu-ppc, qemu-devel

On Tue, 19 Feb 2019, Markus Armbruster wrote:
> BALATON Zoltan <balaton@eik.bme.hu> writes:
>> On Mon, 18 Feb 2019, Markus Armbruster wrote:
>>> BALATON Zoltan <balaton@eik.bme.hu> writes:
>>>> On Mon, 18 Feb 2019, Markus Armbruster wrote:
>>>>> Machine "sam460ex" maps its flash memory at address 0xFFF00000.  When
>>>>> no image is supplied, its size is 1MiB (0x100000).  Else, it's the
>>>>> size of the image rounded up to the next multiple of 64KiB.
>>>>>
>>>>> The rounding is actually useless: pflash_cfi01_realize() fails with
>>>>> "failed to read the initial flash content" unless it's a no-op.
>>>>>
>>>>> I have no idea what happens when the pflash's size exceeds 1MiB.
>>>>> Useful outcomes seem unlikely.
>>>>>
>>>>> I guess memory at the end of the address space remains unmapped when
>>>>> it's smaller than 1MiB.  Again, useful outcomes seem unlikely.
>>>>
>>>> I'm not sure where this was coming from but it predates my changes so
>>>> no idea either.
>>>>
>>>>> Set the flash memory size to 1MiB regardless of image size, to match
>>>>> the physical hardware.
>>>>
>>>> Actually the real hardware seems to have a 512 kB flash chip:
>>>> https://eu.mouser.com/datasheet/2/268/atmel_AT49BV040B-1180330.pdf
>>>
>>> Fascinating.
>>>
>>> <http://www.sam4x0.com/sam460ex.html> confirms.
>>>
>>>> so while you're at it you could change FLASH_SIZE to match that.
>>>
>>> Leads to more questions, below.
> [...]
>>> Let's have a look at the resulting function:
>>>
>>>    static int sam460ex_load_uboot(void)
>>>    {
>>>        DriveInfo *dinfo;
>>>
>>>        dinfo = drive_get(IF_PFLASH, 0, 0);
>>>        if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>>                                   "sam460ex.flash", FLASH_SIZE,
>>>                                   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> [...]
>>>                                   65536,
>>>                                   1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>>>            error_report("Error registering flash memory");
>>>            /* XXX: return an error instead? */
>>>            exit(1);
>>>        }
>>>
>>>        if (!dinfo) {
>>>            /*error_report("No flash image given with the 'pflash' parameter,"
>>>                    " using default u-boot image");*/
>>>            rom_add_file_fixed(UBOOT_FILENAME,
>>>                               UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>>                               -1);
>>>        }
>>>
>>>        return 0;
>>>    }
>>>
>>> This first creates 1MiB of flash memory mapped at the end of the 32-bit
>>> address space (0xFFF00000..0xFFFFFFFF).
>>>
>>> If_PFLASH unit 0 is defined, the flash memory is initialized from that
>>> block backend.
>>>
>>> Else, it's initialized to zero.  And then 512KiB of ROM gets mapped on
>>> top of its second half (0xFFF80000..0xFFFFFFFF), initialized from
>>> u-boot-sam460-20100605.bin (which we build).
>>>
>>> This doesn't smell right.
>>
>> Unfortunately I don't know much about how this should work. Maybe
>> François can remember where this comes from, this was already there
>> when I started working on it, but I suspect maybe he's copied it from
>> some other board in QEMU as well. The sam460ex was based on
>> ppc440_bamboo but that does not seem to have flash ROM. Memory SPD
>> EEPROM came from mips_malta (cleaned up since but it shows that that
>> was also used as inspiration) but that's also not the same so maybe it
>> was adapted for sam460ex or came from some other example in QEMU. This
>> was already there in François's initial commit:
>>
>> https://github.com/mmuman/qemu/commit/d10cc631645f3893d53e60cc00c618470b4de52c#diff-73d06ebbc1301aab78105d853097fa2fR42
>>
>> and later was slightly modified (maybe to rebase for changes in QEMU):
>>
>> https://github.com/mmuman/qemu/commit/768136b08a6b9b69e707af2c478b68a5935bb8f0#diff-73d06ebbc1301aab78105d853097fa2fL1267
>>
>> The comment says these values come from U-Boot:
>>
>> https://git.qemu.org/?p=u-boot-sam460ex.git;a=blob;f=include/configs/Sam460ex.h;h=71064a9601c89dd3ce381d07e0def6c9d5294d44;hb=HEAD#l123
>>
>> and that indeed has flash size of 1 MB but then builds an image that's
>> exactly 512 kB which should be mapped at end of 4GB because the
>> initial program counter of the CPU is 0xfffffffc and board has a 512kB
>> flash chip as well.
>>
>>> I propose to do the following: if IF_PFLASH unit 0 is defined, create
>>> 512KiB of flash memory mapped at the end of the 32-bit address space,
>>> else, create 512KiB of ROM there.
>>>
>>> Okay?
>>
>> AFAIU the above U-Boot could handle up to 1MB of ROM but board has a
>> 512kB chip so probably it makes sense to use 512k here. However since
>> this is not well understood (at least by me) I'm not asking you to do
>> that and maybe just leave it as it is now. This can be revisited when
>> NVRAM is implemented later as this may be related to that (or not)
>> this would need understanding of some details I don't have yet. But if
>> you feel confident enough to clean this up feel free to go ahead.
>
> Then let's use my patch as is, plus a FIXME comment explaining the
> situation.  Okay?

Yes, that would be fine.

Thank you,
BALATON Zoltan

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand Markus Armbruster
  2019-02-18 16:43   ` Laszlo Ersek
@ 2019-02-19 12:40   ` Philippe Mathieu-Daudé
  2019-02-19 13:11     ` Peter Maydell
  1 sibling, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 12:40 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: kwolf, qemu-block, alex.bennee, mreitz, qemu-ppc, lersek

On 2/18/19 1:56 PM, Markus Armbruster wrote:
> PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
> BUG", which sounds like a warning, then calls exit(1), followed by
> unreachable goto reset_flash.  All this commit does is expanding the
> macro, so the smell becomes more poignant, and the macro can be
> deleted.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/block/pflash_cfi01.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 9efa7aa9af..f73c30a3ee 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -49,12 +49,6 @@
>  #include "sysemu/sysemu.h"
>  #include "trace.h"
>  
> -#define PFLASH_BUG(fmt, ...) \
> -do { \
> -    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
> -    exit(1); \
> -} while(0)
> -
>  /* #define PFLASH_DEBUG */
>  #ifdef PFLASH_DEBUG
>  #define DPRINTF(fmt, ...)                                   \
> @@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                  pfl->status |= 0x80;
>              } else {
>                  DPRINTF("%s: unknown command for \"write block\"\n", __func__);
> -                PFLASH_BUG("Write block confirm");
> -                goto reset_flash;
> +                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
> +                exit(1);

Don't you want to use hw_error here?

      hw_error("PFLASH: Possible BUG - Write block confirm");

>              }
>              break;
>          default:
> 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2} Markus Armbruster
  2019-02-18 16:45   ` Laszlo Ersek
@ 2019-02-19 12:41   ` Philippe Mathieu-Daudé
  2019-02-21 15:09   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 12:41 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: kwolf, qemu-block, alex.bennee, mreitz, qemu-ppc, lersek

On 2/18/19 1:56 PM, Markus Armbruster wrote:
> We have two open-coded copies of macro CFI_PFLASH01().  Move the macro
> to the header, so we can ditch the copies.  Move CFI_PFLASH02() to the
> header for symmetry.
> 
> We define macros TYPE_CFI_PFLASH01 and TYPE_CFI_PFLASH02 for type name
> strings, then mostly use the strings.  If the macros are worth
> defining, they are worth using.  Replace the strings by the macros.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  hw/arm/vexpress.c        | 4 ++--
>  hw/arm/virt.c            | 3 ++-
>  hw/block/pflash_cfi01.c  | 3 ---
>  hw/block/pflash_cfi02.c  | 3 ---
>  hw/xtensa/xtfpga.c       | 4 ++--
>  include/hw/block/flash.h | 4 ++++
>  6 files changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index ed46d2e730..00913f2655 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -515,7 +515,7 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>  static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>                                               DriveInfo *di)
>  {
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>  
>      if (di) {
>          qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
> @@ -536,7 +536,7 @@ static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>      qdev_init_nofail(dev);
>  
>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> -    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
> +    return CFI_PFLASH01(dev);
>  }
>  
>  static void vexpress_common_init(MachineState *machine)
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 99c2b6e60d..b7d53b2b87 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -34,6 +34,7 @@
>  #include "hw/arm/arm.h"
>  #include "hw/arm/primecell.h"
>  #include "hw/arm/virt.h"
> +#include "hw/block/flash.h"
>  #include "hw/vfio/vfio-calxeda-xgmac.h"
>  #include "hw/vfio/vfio-amd-xgbe.h"
>  #include "hw/display/ramfb.h"
> @@ -874,7 +875,7 @@ static void create_one_flash(const char *name, hwaddr flashbase,
>       * parameters as the flash devices on the Versatile Express board.
>       */
>      DriveInfo *dinfo = drive_get_next(IF_PFLASH);
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
>      const uint64_t sectorlength = 256 * 1024;
>  
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index f73c30a3ee..43dbb7db26 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -59,9 +59,6 @@ do {                                                        \
>  #define DPRINTF(fmt, ...) do { } while (0)
>  #endif
>  
> -#define CFI_PFLASH01(obj) \
> -    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
> -
>  #define PFLASH_BE          0
>  #define PFLASH_SECURE      1
>  
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 424cc106d6..e9c76d6cfb 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -57,9 +57,6 @@ do {                                                       \
>  
>  #define PFLASH_LAZY_ROMD_THRESHOLD 42
>  
> -#define CFI_PFLASH02(obj) \
> -    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
> -
>  struct PFlashCFI02 {
>      /*< private >*/
>      SysBusDevice parent_obj;
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index 3d59a7a356..a726d5632a 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -167,7 +167,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
>                                        DriveInfo *dinfo, int be)
>  {
>      SysBusDevice *s;
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>  
>      qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
>                          &error_abort);
> @@ -181,7 +181,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
>      s = SYS_BUS_DEVICE(dev);
>      memory_region_add_subregion(address_space, board->flash->base,
>                                  sysbus_mmio_get_region(s, 0));
> -    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
> +    return CFI_PFLASH01(dev);
>  }
>  
>  static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 51d8f60c65..1078dc7238 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -8,6 +8,8 @@
>  /* pflash_cfi01.c */
>  
>  #define TYPE_CFI_PFLASH01 "cfi.pflash01"
> +#define CFI_PFLASH01(obj) \
> +    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
>  
>  typedef struct PFlashCFI01 PFlashCFI01;
>  
> @@ -25,6 +27,8 @@ MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
>  /* pflash_cfi02.c */
>  
>  #define TYPE_CFI_PFLASH02 "cfi.pflash02"
> +#define CFI_PFLASH02(obj) \
> +    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
>  
>  typedef struct PFlashCFI02 PFlashCFI02;
>  
> 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02 Markus Armbruster
  2019-02-18 16:40   ` Laszlo Ersek
@ 2019-02-19 12:49   ` Philippe Mathieu-Daudé
  2019-02-19 13:41     ` Markus Armbruster
  2019-02-21 15:07   ` Alex Bennée
  2 siblings, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 12:49 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: kwolf, qemu-block, alex.bennee, mreitz, qemu-ppc, lersek

On 2/18/19 1:56 PM, Markus Armbruster wrote:
> flash.h's incomplete struct pflash_t is completed both in
> pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
> incompatible.  This can hide type errors, such as passing a pflash_t
> created with pflash_cfi02_register() to pflash_cfi01_get_memory().
> 
> Furthermore, POSIX reserves typedef names ending with _t.
> 
> Rename the two structs to PFlashCFI01 and PFlashCFI02.

Why not ParallelFlashCFIxx?

Ideally ParallelFlashCFI would be an InterfaceInfo...

> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/vexpress.c        |  8 ++--
>  hw/block/pflash_cfi01.c  | 87 +++++++++++++++++++++-------------------
>  hw/block/pflash_cfi02.c  | 67 ++++++++++++++++---------------
>  hw/i386/pc_sysfw.c       |  2 +-
>  hw/mips/mips_malta.c     |  2 +-
>  hw/xtensa/xtfpga.c       | 10 ++---
>  include/hw/block/flash.h | 53 ++++++++++++++----------
>  7 files changed, 122 insertions(+), 107 deletions(-)
> 
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index c02d18ee61..ed46d2e730 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -512,8 +512,8 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>  /* Open code a private version of pflash registration since we
>   * need to set non-default device width for VExpress platform.
>   */
> -static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
> -                                          DriveInfo *di)
> +static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
> +                                             DriveInfo *di)
>  {
>      DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
>  
> @@ -536,7 +536,7 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
>      qdev_init_nofail(dev);
>  
>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> -    return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
> +    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
>  }
>  
>  static void vexpress_common_init(MachineState *machine)
> @@ -548,7 +548,7 @@ static void vexpress_common_init(MachineState *machine)
>      qemu_irq pic[64];
>      uint32_t sys_id;
>      DriveInfo *dinfo;
> -    pflash_t *pflash0;
> +    PFlashCFI01 *pflash0;
>      I2CBus *i2c;
>      ram_addr_t vram_size, sram_size;
>      MemoryRegion *sysmem = get_system_memory();
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index bffb4c40e7..9efa7aa9af 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -65,12 +65,13 @@ do {                                                        \
>  #define DPRINTF(fmt, ...) do { } while (0)
>  #endif
>  
> -#define CFI_PFLASH01(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01)
> +#define CFI_PFLASH01(obj) \
> +    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
>  
>  #define PFLASH_BE          0
>  #define PFLASH_SECURE      1
>  
> -struct pflash_t {
> +struct PFlashCFI01 {
>      /*< private >*/
>      SysBusDevice parent_obj;
>      /*< public >*/
> @@ -109,17 +110,17 @@ static const VMStateDescription vmstate_pflash = {
>      .minimum_version_id = 1,
>      .post_load = pflash_post_load,
>      .fields = (VMStateField[]) {
> -        VMSTATE_UINT8(wcycle, pflash_t),
> -        VMSTATE_UINT8(cmd, pflash_t),
> -        VMSTATE_UINT8(status, pflash_t),
> -        VMSTATE_UINT64(counter, pflash_t),
> +        VMSTATE_UINT8(wcycle, PFlashCFI01),
> +        VMSTATE_UINT8(cmd, PFlashCFI01),
> +        VMSTATE_UINT8(status, PFlashCFI01),
> +        VMSTATE_UINT64(counter, PFlashCFI01),
>          VMSTATE_END_OF_LIST()
>      }
>  };
>  
>  static void pflash_timer (void *opaque)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>  
>      trace_pflash_timer_expired(pfl->cmd);
>      /* Reset flash */
> @@ -133,7 +134,7 @@ static void pflash_timer (void *opaque)
>   * If this code is called we know we have a device_width set for
>   * this flash.
>   */
> -static uint32_t pflash_cfi_query(pflash_t *pfl, hwaddr offset)
> +static uint32_t pflash_cfi_query(PFlashCFI01 *pfl, hwaddr offset)
>  {
>      int i;
>      uint32_t resp = 0;
> @@ -193,7 +194,7 @@ static uint32_t pflash_cfi_query(pflash_t *pfl, hwaddr offset)
>  
>  
>  /* Perform a device id query based on the bank width of the flash. */
> -static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)
> +static uint32_t pflash_devid_query(PFlashCFI01 *pfl, hwaddr offset)
>  {
>      int i;
>      uint32_t resp;
> @@ -241,7 +242,7 @@ static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)
>      return resp;
>  }
>  
> -static uint32_t pflash_data_read(pflash_t *pfl, hwaddr offset,
> +static uint32_t pflash_data_read(PFlashCFI01 *pfl, hwaddr offset,
>                                   int width, int be)
>  {
>      uint8_t *p;
> @@ -284,7 +285,7 @@ static uint32_t pflash_data_read(pflash_t *pfl, hwaddr offset,
>      return ret;
>  }
>  
> -static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
> +static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,
>                               int width, int be)
>  {
>      hwaddr boff;
> @@ -398,7 +399,7 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
>  }
>  
>  /* update flash content on disk */
> -static void pflash_update(pflash_t *pfl, int offset,
> +static void pflash_update(PFlashCFI01 *pfl, int offset,
>                            int size)
>  {
>      int offset_end;
> @@ -412,7 +413,7 @@ static void pflash_update(pflash_t *pfl, int offset,
>      }
>  }
>  
> -static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
> +static inline void pflash_data_write(PFlashCFI01 *pfl, hwaddr offset,
>                                       uint32_t value, int width, int be)
>  {
>      uint8_t *p = pfl->storage;
> @@ -448,7 +449,7 @@ static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
>  
>  }
>  
> -static void pflash_write(pflash_t *pfl, hwaddr offset,
> +static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                           uint32_t value, int width, int be)
>  {
>      uint8_t *p;
> @@ -654,7 +655,7 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,
>  static MemTxResult pflash_mem_read_with_attrs(void *opaque, hwaddr addr, uint64_t *value,
>                                                unsigned len, MemTxAttrs attrs)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>      bool be = !!(pfl->features & (1 << PFLASH_BE));
>  
>      if ((pfl->features & (1 << PFLASH_SECURE)) && !attrs.secure) {
> @@ -668,7 +669,7 @@ static MemTxResult pflash_mem_read_with_attrs(void *opaque, hwaddr addr, uint64_
>  static MemTxResult pflash_mem_write_with_attrs(void *opaque, hwaddr addr, uint64_t value,
>                                                 unsigned len, MemTxAttrs attrs)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>      bool be = !!(pfl->features & (1 << PFLASH_BE));
>  
>      if ((pfl->features & (1 << PFLASH_SECURE)) && !attrs.secure) {
> @@ -687,7 +688,7 @@ static const MemoryRegionOps pflash_cfi01_ops = {
>  
>  static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
>  {
> -    pflash_t *pfl = CFI_PFLASH01(dev);
> +    PFlashCFI01 *pfl = CFI_PFLASH01(dev);
>      uint64_t total_len;
>      int ret;
>      uint64_t blocks_per_device, sector_len_per_device, device_len;
> @@ -864,14 +865,14 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
>  }
>  
>  static Property pflash_cfi01_properties[] = {
> -    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
> +    DEFINE_PROP_DRIVE("drive", PFlashCFI01, blk),
>      /* num-blocks is the number of blocks actually visible to the guest,
>       * ie the total size of the device divided by the sector length.
>       * If we're emulating flash devices wired in parallel the actual
>       * number of blocks per indvidual device will differ.
>       */
> -    DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
> -    DEFINE_PROP_UINT64("sector-length", struct pflash_t, sector_len, 0),
> +    DEFINE_PROP_UINT32("num-blocks", PFlashCFI01, nb_blocs, 0),
> +    DEFINE_PROP_UINT64("sector-length", PFlashCFI01, sector_len, 0),
>      /* width here is the overall width of this QEMU device in bytes.
>       * The QEMU device may be emulating a number of flash devices
>       * wired up in parallel; the width of each individual flash
> @@ -888,17 +889,17 @@ static Property pflash_cfi01_properties[] = {
>       * 16 bit devices making up a 32 bit wide QEMU device. This
>       * is deprecated for new uses of this device.
>       */
> -    DEFINE_PROP_UINT8("width", struct pflash_t, bank_width, 0),
> -    DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0),
> -    DEFINE_PROP_UINT8("max-device-width", struct pflash_t, max_device_width, 0),
> -    DEFINE_PROP_BIT("big-endian", struct pflash_t, features, PFLASH_BE, 0),
> -    DEFINE_PROP_BIT("secure", struct pflash_t, features, PFLASH_SECURE, 0),
> -    DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0),
> -    DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
> -    DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
> -    DEFINE_PROP_UINT16("id3", struct pflash_t, ident3, 0),
> -    DEFINE_PROP_STRING("name", struct pflash_t, name),
> -    DEFINE_PROP_BOOL("old-multiple-chip-handling", struct pflash_t,
> +    DEFINE_PROP_UINT8("width", PFlashCFI01, bank_width, 0),
> +    DEFINE_PROP_UINT8("device-width", PFlashCFI01, device_width, 0),
> +    DEFINE_PROP_UINT8("max-device-width", PFlashCFI01, max_device_width, 0),
> +    DEFINE_PROP_BIT("big-endian", PFlashCFI01, features, PFLASH_BE, 0),
> +    DEFINE_PROP_BIT("secure", PFlashCFI01, features, PFLASH_SECURE, 0),
> +    DEFINE_PROP_UINT16("id0", PFlashCFI01, ident0, 0),
> +    DEFINE_PROP_UINT16("id1", PFlashCFI01, ident1, 0),
> +    DEFINE_PROP_UINT16("id2", PFlashCFI01, ident2, 0),
> +    DEFINE_PROP_UINT16("id3", PFlashCFI01, ident3, 0),
> +    DEFINE_PROP_STRING("name", PFlashCFI01, name),
> +    DEFINE_PROP_BOOL("old-multiple-chip-handling", PFlashCFI01,
>                       old_multiple_chip_handling, false),
>      DEFINE_PROP_END_OF_LIST(),
>  };
> @@ -917,7 +918,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data)
>  static const TypeInfo pflash_cfi01_info = {
>      .name           = TYPE_CFI_PFLASH01,
>      .parent         = TYPE_SYS_BUS_DEVICE,
> -    .instance_size  = sizeof(struct pflash_t),
> +    .instance_size  = sizeof(PFlashCFI01),
>      .class_init     = pflash_cfi01_class_init,
>  };
>  
> @@ -928,13 +929,15 @@ static void pflash_cfi01_register_types(void)
>  
>  type_init(pflash_cfi01_register_types)
>  
> -pflash_t *pflash_cfi01_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk,
> -                                uint32_t sector_len, int nb_blocs,
> -                                int bank_width, uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3, int be)
> +PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int bank_width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   int be)
>  {
>      DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>  
> @@ -956,14 +959,14 @@ pflash_t *pflash_cfi01_register(hwaddr base,
>      return CFI_PFLASH01(dev);
>  }
>  
> -MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl)
> +MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl)
>  {
>      return &fl->mem;
>  }
>  
>  static void postload_update_cb(void *opaque, int running, RunState state)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>  
>      /* This is called after bdrv_invalidate_cache_all.  */
>      qemu_del_vm_change_state_handler(pfl->vmstate);
> @@ -975,7 +978,7 @@ static void postload_update_cb(void *opaque, int running, RunState state)
>  
>  static int pflash_post_load(void *opaque, int version_id)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>  
>      if (!pfl->ro) {
>          pfl->vmstate = qemu_add_vm_change_state_handler(postload_update_cb,
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 0f8b7b8c7b..424cc106d6 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -57,9 +57,10 @@ do {                                                       \
>  
>  #define PFLASH_LAZY_ROMD_THRESHOLD 42
>  
> -#define CFI_PFLASH02(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH02)
> +#define CFI_PFLASH02(obj) \
> +    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
>  
> -struct pflash_t {
> +struct PFlashCFI02 {
>      /*< private >*/
>      SysBusDevice parent_obj;
>      /*< public >*/
> @@ -101,7 +102,7 @@ struct pflash_t {
>  /*
>   * Set up replicated mappings of the same region.
>   */
> -static void pflash_setup_mappings(pflash_t *pfl)
> +static void pflash_setup_mappings(PFlashCFI02 *pfl)
>  {
>      unsigned i;
>      hwaddr size = memory_region_size(&pfl->orig_mem);
> @@ -115,7 +116,7 @@ static void pflash_setup_mappings(pflash_t *pfl)
>      }
>  }
>  
> -static void pflash_register_memory(pflash_t *pfl, int rom_mode)
> +static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode)
>  {
>      memory_region_rom_device_set_romd(&pfl->orig_mem, rom_mode);
>      pfl->rom_mode = rom_mode;
> @@ -123,7 +124,7 @@ static void pflash_register_memory(pflash_t *pfl, int rom_mode)
>  
>  static void pflash_timer (void *opaque)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI02 *pfl = opaque;
>  
>      trace_pflash_timer_expired(pfl->cmd);
>      /* Reset flash */
> @@ -137,7 +138,7 @@ static void pflash_timer (void *opaque)
>      pfl->cmd = 0;
>  }
>  
> -static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
> +static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,
>                               int width, int be)
>  {
>      hwaddr boff;
> @@ -246,7 +247,7 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
>  }
>  
>  /* update flash content on disk */
> -static void pflash_update(pflash_t *pfl, int offset,
> +static void pflash_update(PFlashCFI02 *pfl, int offset,
>                            int size)
>  {
>      int offset_end;
> @@ -260,7 +261,7 @@ static void pflash_update(pflash_t *pfl, int offset,
>      }
>  }
>  
> -static void pflash_write (pflash_t *pfl, hwaddr offset,
> +static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,
>                            uint32_t value, int width, int be)
>  {
>      hwaddr boff;
> @@ -533,7 +534,7 @@ static const MemoryRegionOps pflash_cfi02_ops_le = {
>  
>  static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
>  {
> -    pflash_t *pfl = CFI_PFLASH02(dev);
> +    PFlashCFI02 *pfl = CFI_PFLASH02(dev);
>      uint32_t chip_len;
>      int ret;
>      Error *local_err = NULL;
> @@ -679,19 +680,19 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
>  }
>  
>  static Property pflash_cfi02_properties[] = {
> -    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
> -    DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
> -    DEFINE_PROP_UINT32("sector-length", struct pflash_t, sector_len, 0),
> -    DEFINE_PROP_UINT8("width", struct pflash_t, width, 0),
> -    DEFINE_PROP_UINT8("mappings", struct pflash_t, mappings, 0),
> -    DEFINE_PROP_UINT8("big-endian", struct pflash_t, be, 0),
> -    DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0),
> -    DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
> -    DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
> -    DEFINE_PROP_UINT16("id3", struct pflash_t, ident3, 0),
> -    DEFINE_PROP_UINT16("unlock-addr0", struct pflash_t, unlock_addr0, 0),
> -    DEFINE_PROP_UINT16("unlock-addr1", struct pflash_t, unlock_addr1, 0),
> -    DEFINE_PROP_STRING("name", struct pflash_t, name),
> +    DEFINE_PROP_DRIVE("drive", PFlashCFI02, blk),
> +    DEFINE_PROP_UINT32("num-blocks", PFlashCFI02, nb_blocs, 0),
> +    DEFINE_PROP_UINT32("sector-length", PFlashCFI02, sector_len, 0),
> +    DEFINE_PROP_UINT8("width", PFlashCFI02, width, 0),
> +    DEFINE_PROP_UINT8("mappings", PFlashCFI02, mappings, 0),
> +    DEFINE_PROP_UINT8("big-endian", PFlashCFI02, be, 0),
> +    DEFINE_PROP_UINT16("id0", PFlashCFI02, ident0, 0),
> +    DEFINE_PROP_UINT16("id1", PFlashCFI02, ident1, 0),
> +    DEFINE_PROP_UINT16("id2", PFlashCFI02, ident2, 0),
> +    DEFINE_PROP_UINT16("id3", PFlashCFI02, ident3, 0),
> +    DEFINE_PROP_UINT16("unlock-addr0", PFlashCFI02, unlock_addr0, 0),
> +    DEFINE_PROP_UINT16("unlock-addr1", PFlashCFI02, unlock_addr1, 0),
> +    DEFINE_PROP_STRING("name", PFlashCFI02, name),
>      DEFINE_PROP_END_OF_LIST(),
>  };
>  
> @@ -707,7 +708,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data)
>  static const TypeInfo pflash_cfi02_info = {
>      .name           = TYPE_CFI_PFLASH02,
>      .parent         = TYPE_SYS_BUS_DEVICE,
> -    .instance_size  = sizeof(struct pflash_t),
> +    .instance_size  = sizeof(PFlashCFI02),
>      .class_init     = pflash_cfi02_class_init,
>  };
>  
> @@ -718,15 +719,17 @@ static void pflash_cfi02_register_types(void)
>  
>  type_init(pflash_cfi02_register_types)
>  
> -pflash_t *pflash_cfi02_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk, uint32_t sector_len,
> -                                int nb_blocs, int nb_mappings, int width,
> -                                uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3,
> -                                uint16_t unlock_addr0, uint16_t unlock_addr1,
> -                                int be)
> +PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int nb_mappings, int width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   uint16_t unlock_addr0,
> +                                   uint16_t unlock_addr1,
> +                                   int be)
>  {
>      DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH02);
>  
> diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> index 091e22dd60..67e55342f6 100644
> --- a/hw/i386/pc_sysfw.c
> +++ b/hw/i386/pc_sysfw.c
> @@ -111,7 +111,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
>      char *fatal_errmsg = NULL;
>      hwaddr phys_addr = 0x100000000ULL;
>      int sector_bits, sector_size;
> -    pflash_t *system_flash;
> +    PFlashCFI01 *system_flash;
>      MemoryRegion *flash_mem;
>      char name[64];
>      void *flash_ptr;
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index 74667766c2..fff5ed19bd 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -1189,7 +1189,7 @@ void mips_malta_init(MachineState *machine)
>      const char *kernel_cmdline = machine->kernel_cmdline;
>      const char *initrd_filename = machine->initrd_filename;
>      char *filename;
> -    pflash_t *fl;
> +    PFlashCFI01 *fl;
>      MemoryRegion *system_memory = get_system_memory();
>      MemoryRegion *ram_high = g_new(MemoryRegion, 1);
>      MemoryRegion *ram_low_preio = g_new(MemoryRegion, 1);
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index ab3e52b415..3d59a7a356 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -162,9 +162,9 @@ static void xtfpga_net_init(MemoryRegion *address_space,
>      memory_region_add_subregion(address_space, buffers, ram);
>  }
>  
> -static pflash_t *xtfpga_flash_init(MemoryRegion *address_space,
> -                                   const XtfpgaBoardDesc *board,
> -                                   DriveInfo *dinfo, int be)
> +static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
> +                                      const XtfpgaBoardDesc *board,
> +                                      DriveInfo *dinfo, int be)
>  {
>      SysBusDevice *s;
>      DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> @@ -181,7 +181,7 @@ static pflash_t *xtfpga_flash_init(MemoryRegion *address_space,
>      s = SYS_BUS_DEVICE(dev);
>      memory_region_add_subregion(address_space, board->flash->base,
>                                  sysbus_mmio_get_region(s, 0));
> -    return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
> +    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
>  }
>  
>  static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
> @@ -229,7 +229,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
>      XtensaMxPic *mx_pic = NULL;
>      qemu_irq *extints;
>      DriveInfo *dinfo;
> -    pflash_t *flash = NULL;
> +    PFlashCFI01 *flash = NULL;
>      QemuOpts *machine_opts = qemu_get_machine_opts();
>      const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
>      const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 67c3aa329e..51d8f60c65 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -5,32 +5,41 @@
>  
>  #include "exec/memory.h"
>  
> -#define TYPE_CFI_PFLASH01 "cfi.pflash01"
> -#define TYPE_CFI_PFLASH02 "cfi.pflash02"
> -
> -typedef struct pflash_t pflash_t;
> -
>  /* pflash_cfi01.c */
> -pflash_t *pflash_cfi01_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk,
> -                                uint32_t sector_len, int nb_blocs, int width,
> -                                uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3, int be);
> +
> +#define TYPE_CFI_PFLASH01 "cfi.pflash01"
> +
> +typedef struct PFlashCFI01 PFlashCFI01;
> +
> +PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   int be);
> +MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
>  
>  /* pflash_cfi02.c */
> -pflash_t *pflash_cfi02_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk, uint32_t sector_len,
> -                                int nb_blocs, int nb_mappings, int width,
> -                                uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3,
> -                                uint16_t unlock_addr0, uint16_t unlock_addr1,
> -                                int be);
>  
> -MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl);
> +#define TYPE_CFI_PFLASH02 "cfi.pflash02"
> +
> +typedef struct PFlashCFI02 PFlashCFI02;
> +
> +PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int nb_mappings,
> +                                   int width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   uint16_t unlock_addr0,
> +                                   uint16_t unlock_addr1,
> +                                   int be);
>  
>  /* nand.c */
>  DeviceState *nand_init(BlockBackend *blk, int manf_id, int chip_id);
> 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some
  2019-02-19  8:43   ` Max Filippov
@ 2019-02-19 13:01     ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 13:01 UTC (permalink / raw)
  To: Max Filippov
  Cc: Kevin Wolf, Qemu-block, lersek, qemu-devel, Max Reitz, qemu-ppc,
	Alex Bennée, Paolo Bonzini, Peter Maydell,
	Andreas Färber, Peter Crosthwaite

Max Filippov <jcmvbkbc@gmail.com> writes:

> On Mon, Feb 18, 2019 at 5:07 AM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> pflash_cfi01_register() creates a TYPE_CFI_PFLASH01 device, sets
>> properties, realizes, and wires up.
>>
>> We have three modified copies of it, because their users need to set
>> additional properties, or have the wiring done differently.
>>
>> Factor out their common part into pflash_cfi01_create().
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/arm/vexpress.c        | 22 +++++-----------------
>>  hw/arm/virt.c            | 26 +++++++++-----------------
>>  hw/block/pflash_cfi01.c  | 39 +++++++++++++++++++++++++++------------
>>  hw/xtensa/xtfpga.c       | 18 +++++++-----------
>
> I was told that it's better this way when I did that initially:
>   http://lists.gnu.org/archive/html/qemu-devel/2015-09/msg06927.html
>
> Has the idea of "better" changed since then?
> I'm fine with the code either way, just curious.

I'm not sure about our collective idea of "better".  I simply saw a
helper function duplicated with minor variations because it fails to
capture what's truly common, so I fixed that.

If we think helper functions capturing device creation and property
setting are bad, and open coding would be better. then we should get rid
of pflash_cfi01_register() and pflash_cfi02_register() everywhere, not
just avoid it in these three places.

Cc'ing the usual QOM suspects for guidance.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat Markus Armbruster
@ 2019-02-19 13:02   ` Philippe Mathieu-Daudé
  2019-02-19 13:43     ` Markus Armbruster
  2019-02-21 15:27   ` Alex Bennée
  1 sibling, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 13:02 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: kwolf, qemu-block, Aleksandar Rikalo, alex.bennee, mreitz,
	qemu-ppc, lersek, Aurelien Jarno

On 2/18/19 1:56 PM, Markus Armbruster wrote:
> pflash_cfi01_register() takes a size in bytes, a block size in bytes
> and a number of blocks.  mips_malta_init() passes BIOS_SIZE, 65536,
> FLASH_SIZE >> 16.  Actually consistent only because BIOS_SIZE (defined
> in include/hw/mips/bios.h as (4 * MiB)) matches FLASH_SIZE (defined
> locally as 0x400000).  Confusing all the same.
> 
> Pass FLASH_SIZE instead of BIOS_SIZE.

Your cleanup is correct.

> 
> There are more uses of BIOS_SIZE, but I don't sufficiently understand
> them to attempt cleanup.

BIOS_SIZE is a MIPS architecture definition, incorrectly used around.
This simply means "Top of 32bit address space - Boot Vector address".
There is nothing wrong in plugging bigger/smaller flashes around the
boot vector.
(I have a series cleaning this definition, but I'm throttling my MIPS
apports).

> 
> Cc: Aurelien Jarno <aurelien@aurel32.net>
> Cc: Aleksandar Rikalo <arikalo@wavecomp.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/mips/mips_malta.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index fff5ed19bd..65cdda4881 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -1269,12 +1269,12 @@ void mips_malta_init(MachineState *machine)
>      if (dinfo) {
>          printf("Register parallel flash %d size " TARGET_FMT_lx " at "
>                 "addr %08llx '%s' %x\n",
> -               fl_idx, bios_size, FLASH_ADDRESS,
> +               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
>                 blk_name(dinfo->bdrv), fl_sectors);
>      }
>  #endif
>      fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
> -                               BIOS_SIZE,
> +                               FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 65536, fl_sectors,
>                                 4, 0x0000, 0x0000, 0x0000, 0x0000, be);
> 

Does that mean you can remove the "hw/mips/bios.h" include now?

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (14 preceding siblings ...)
  2019-02-19  4:43 ` no-reply
@ 2019-02-19 13:06 ` no-reply
  2019-02-19 13:49 ` no-reply
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-19 13:06 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190218125615.18970-1-armbru@redhat.com -> patchew/20190218125615.18970-1-armbru@redhat.com
 t [tag update]            patchew/20190219060719.8211-1-richardw.yang@linux.intel.com -> patchew/20190219060719.8211-1-richardw.yang@linux.intel.com
 * [new tag]               patchew/20190219124257.3001-1-kraxel@redhat.com -> patchew/20190219124257.3001-1-kraxel@redhat.com
Switched to a new branch 'test'
eadbdde93b hw/arm hw/xtensa: De-duplicate pflash creation code some
66b962dbf3 pflash: Clean up after commit 368a354f02b part 2
5284500a74 pflash: Clean up after commit 368a354f02b part 1
09d2c4a708 mips_malta: Clean up definition of flash memory size somewhat
370f0b5929 r2d: Flash memory creation is confused about size, mark FIXME
a44365fece ppc405_boards: Don't size flash memory to match backing image
e6dcc28b89 sam460ex: Don't size flash memory to match backing image
b554480ef5 hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
d750905bcc pflash: Macro PFLASH_BUG() is used just once, expand
ec3e8745cd pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit ec3e8745cdd8 (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit d750905bcc59 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit b554480ef5e6 (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit e6dcc28b8994 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit a44365fece7c (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 370f0b59294b (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit 09d2c4a70817 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit 5284500a7468 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#90: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#98: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 66b962dbf392 (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit eadbdde93b39 (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-19 12:40   ` Philippe Mathieu-Daudé
@ 2019-02-19 13:11     ` Peter Maydell
  2019-02-19 13:46       ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Peter Maydell @ 2019-02-19 13:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Markus Armbruster, QEMU Developers, Kevin Wolf, Qemu-block,
	Laszlo Ersek, Max Reitz, qemu-ppc, Alex Bennée

On Tue, 19 Feb 2019 at 12:41, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> On 2/18/19 1:56 PM, Markus Armbruster wrote:
> > PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
> > BUG", which sounds like a warning, then calls exit(1), followed by
> > unreachable goto reset_flash.  All this commit does is expanding the
> > macro, so the smell becomes more poignant, and the macro can be
> > deleted.
> >
> > Signed-off-by: Markus Armbruster <armbru@redhat.com>
> > ---
> >  hw/block/pflash_cfi01.c | 10 ++--------
> >  1 file changed, 2 insertions(+), 8 deletions(-)
> >
> > diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> > index 9efa7aa9af..f73c30a3ee 100644
> > --- a/hw/block/pflash_cfi01.c
> > +++ b/hw/block/pflash_cfi01.c
> > @@ -49,12 +49,6 @@
> >  #include "sysemu/sysemu.h"
> >  #include "trace.h"
> >
> > -#define PFLASH_BUG(fmt, ...) \
> > -do { \
> > -    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
> > -    exit(1); \
> > -} while(0)
> > -
> >  /* #define PFLASH_DEBUG */
> >  #ifdef PFLASH_DEBUG
> >  #define DPRINTF(fmt, ...)                                   \
> > @@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
> >                  pfl->status |= 0x80;
> >              } else {
> >                  DPRINTF("%s: unknown command for \"write block\"\n", __func__);
> > -                PFLASH_BUG("Write block confirm");
> > -                goto reset_flash;
> > +                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
> > +                exit(1);
>
> Don't you want to use hw_error here?
>
>       hw_error("PFLASH: Possible BUG - Write block confirm");

This should just be
   qemu_log_mask(LOG_GUEST_ERROR, ...);
(replacing both the DPRINTF and the PFLASH_BUG()).

It's triggerable by a guest (if it puts the device into write-block
mode and then feeds it a bogus command byte), so it's just a guest
error, not an issue with our model of the pflash.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-19 12:49   ` Philippe Mathieu-Daudé
@ 2019-02-19 13:41     ` Markus Armbruster
  2019-02-19 14:33       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 13:41 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, kwolf, qemu-block, lersek, mreitz, qemu-ppc, alex.bennee

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>> flash.h's incomplete struct pflash_t is completed both in
>> pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
>> incompatible.  This can hide type errors, such as passing a pflash_t
>> created with pflash_cfi02_register() to pflash_cfi01_get_memory().
>> 
>> Furthermore, POSIX reserves typedef names ending with _t.
>> 
>> Rename the two structs to PFlashCFI01 and PFlashCFI02.
>
> Why not ParallelFlashCFIxx?

Feels a bit long, and we abbreviate to pflash pretty consistently.  That
said, I'm not particularly enamored with my choice of name :)

> Ideally ParallelFlashCFI would be an InterfaceInfo...

You mean TYPE_CFI_PFLASH0{1,2} should be children of an abstract parent?

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat
  2019-02-19 13:02   ` Philippe Mathieu-Daudé
@ 2019-02-19 13:43     ` Markus Armbruster
  2019-02-19 16:10       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 13:43 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, kwolf, qemu-block, Aleksandar Rikalo, lersek, mreitz,
	qemu-ppc, alex.bennee, Aurelien Jarno

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>> pflash_cfi01_register() takes a size in bytes, a block size in bytes
>> and a number of blocks.  mips_malta_init() passes BIOS_SIZE, 65536,
>> FLASH_SIZE >> 16.  Actually consistent only because BIOS_SIZE (defined
>> in include/hw/mips/bios.h as (4 * MiB)) matches FLASH_SIZE (defined
>> locally as 0x400000).  Confusing all the same.
>> 
>> Pass FLASH_SIZE instead of BIOS_SIZE.
>
> Your cleanup is correct.
>
>> 
>> There are more uses of BIOS_SIZE, but I don't sufficiently understand
>> them to attempt cleanup.
>
> BIOS_SIZE is a MIPS architecture definition, incorrectly used around.
> This simply means "Top of 32bit address space - Boot Vector address".
> There is nothing wrong in plugging bigger/smaller flashes around the
> boot vector.
> (I have a series cleaning this definition, but I'm throttling my MIPS
> apports).
>
>> 
>> Cc: Aurelien Jarno <aurelien@aurel32.net>
>> Cc: Aleksandar Rikalo <arikalo@wavecomp.com>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/mips/mips_malta.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
>> index fff5ed19bd..65cdda4881 100644
>> --- a/hw/mips/mips_malta.c
>> +++ b/hw/mips/mips_malta.c
>> @@ -1269,12 +1269,12 @@ void mips_malta_init(MachineState *machine)
>>      if (dinfo) {
>>          printf("Register parallel flash %d size " TARGET_FMT_lx " at "
>>                 "addr %08llx '%s' %x\n",
>> -               fl_idx, bios_size, FLASH_ADDRESS,
>> +               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
>>                 blk_name(dinfo->bdrv), fl_sectors);
>>      }
>>  #endif
>>      fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
>> -                               BIOS_SIZE,
>> +                               FLASH_SIZE,
>>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>>                                 65536, fl_sectors,
>>                                 4, 0x0000, 0x0000, 0x0000, 0x0000, be);
>> 
>
> Does that mean you can remove the "hw/mips/bios.h" include now?

No, since there are more uses of BIOS_SIZE in this file.  They feel
inappropriate to me, but I don't feel confident enough to attempt
cleanup.

> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Thanks!

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-19 13:11     ` Peter Maydell
@ 2019-02-19 13:46       ` Markus Armbruster
  2019-02-21  9:22         ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 13:46 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc, Laszlo Ersek

Peter Maydell <peter.maydell@linaro.org> writes:

> On Tue, 19 Feb 2019 at 12:41, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>
>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>> > PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
>> > BUG", which sounds like a warning, then calls exit(1), followed by
>> > unreachable goto reset_flash.  All this commit does is expanding the
>> > macro, so the smell becomes more poignant, and the macro can be
>> > deleted.
>> >
>> > Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> > ---
>> >  hw/block/pflash_cfi01.c | 10 ++--------
>> >  1 file changed, 2 insertions(+), 8 deletions(-)
>> >
>> > diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
>> > index 9efa7aa9af..f73c30a3ee 100644
>> > --- a/hw/block/pflash_cfi01.c
>> > +++ b/hw/block/pflash_cfi01.c
>> > @@ -49,12 +49,6 @@
>> >  #include "sysemu/sysemu.h"
>> >  #include "trace.h"
>> >
>> > -#define PFLASH_BUG(fmt, ...) \
>> > -do { \
>> > -    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
>> > -    exit(1); \
>> > -} while(0)
>> > -
>> >  /* #define PFLASH_DEBUG */
>> >  #ifdef PFLASH_DEBUG
>> >  #define DPRINTF(fmt, ...)                                   \
>> > @@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>> >                  pfl->status |= 0x80;
>> >              } else {
>> >                  DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>> > -                PFLASH_BUG("Write block confirm");
>> > -                goto reset_flash;
>> > +                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
>> > +                exit(1);
>>
>> Don't you want to use hw_error here?
>>
>>       hw_error("PFLASH: Possible BUG - Write block confirm");
>
> This should just be
>    qemu_log_mask(LOG_GUEST_ERROR, ...);
> (replacing both the DPRINTF and the PFLASH_BUG()).
>
> It's triggerable by a guest (if it puts the device into write-block
> mode and then feeds it a bogus command byte), so it's just a guest
> error, not an issue with our model of the pflash.

I can do that.  Thanks!

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (15 preceding siblings ...)
  2019-02-19 13:06 ` no-reply
@ 2019-02-19 13:49 ` no-reply
  2019-02-19 13:53 ` no-reply
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-19 13:49 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
03998181d5 hw/arm hw/xtensa: De-duplicate pflash creation code some
8900ef3eb2 pflash: Clean up after commit 368a354f02b part 2
b2a752e969 pflash: Clean up after commit 368a354f02b part 1
6161e9b2e1 mips_malta: Clean up definition of flash memory size somewhat
f63e1b95be r2d: Flash memory creation is confused about size, mark FIXME
c940613c6f ppc405_boards: Don't size flash memory to match backing image
aafbf2b0cb sam460ex: Don't size flash memory to match backing image
50c58aaaef hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
32f306be23 pflash: Macro PFLASH_BUG() is used just once, expand
ab1e43ce7b pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit ab1e43ce7b8b (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 32f306be2381 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 50c58aaaeff5 (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit aafbf2b0cbd5 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit c940613c6fd9 (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit f63e1b95beaf (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit 6161e9b2e1a1 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit b2a752e969e1 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#90: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#98: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 8900ef3eb27a (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 03998181d548 (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (16 preceding siblings ...)
  2019-02-19 13:49 ` no-reply
@ 2019-02-19 13:53 ` no-reply
  2019-02-19 16:43 ` no-reply
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-19 13:53 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]      patchew/20190218125615.18970-1-armbru@redhat.com -> patchew/20190218125615.18970-1-armbru@redhat.com
 - [tag update]      patchew/20190219114609.1582-1-berrange@redhat.com -> patchew/20190219114609.1582-1-berrange@redhat.com
 - [tag update]      patchew/20190219124257.3001-1-kraxel@redhat.com -> patchew/20190219124257.3001-1-kraxel@redhat.com
Submodule 'capstone' (https://git.qemu.org/git/capstone.git) registered for path 'capstone'
Submodule 'dtc' (https://git.qemu.org/git/dtc.git) registered for path 'dtc'
Submodule 'roms/QemuMacDrivers' (https://git.qemu.org/git/QemuMacDrivers.git) registered for path 'roms/QemuMacDrivers'
Submodule 'roms/SLOF' (https://git.qemu.org/git/SLOF.git) registered for path 'roms/SLOF'
Submodule 'roms/ipxe' (https://git.qemu.org/git/ipxe.git) registered for path 'roms/ipxe'
Submodule 'roms/openbios' (https://git.qemu.org/git/openbios.git) registered for path 'roms/openbios'
Submodule 'roms/openhackware' (https://git.qemu.org/git/openhackware.git) registered for path 'roms/openhackware'
Submodule 'roms/qemu-palcode' (https://git.qemu.org/git/qemu-palcode.git) registered for path 'roms/qemu-palcode'
Submodule 'roms/seabios' (https://git.qemu.org/git/seabios.git/) registered for path 'roms/seabios'
Submodule 'roms/seabios-hppa' (https://github.com/hdeller/seabios-hppa.git) registered for path 'roms/seabios-hppa'
Submodule 'roms/sgabios' (https://git.qemu.org/git/sgabios.git) registered for path 'roms/sgabios'
Submodule 'roms/skiboot' (https://git.qemu.org/git/skiboot.git) registered for path 'roms/skiboot'
Submodule 'roms/u-boot' (https://git.qemu.org/git/u-boot.git) registered for path 'roms/u-boot'
Submodule 'roms/u-boot-sam460ex' (https://git.qemu.org/git/u-boot-sam460ex.git) registered for path 'roms/u-boot-sam460ex'
Submodule 'tests/fp/berkeley-softfloat-3' (https://github.com/cota/berkeley-softfloat-3) registered for path 'tests/fp/berkeley-softfloat-3'
Submodule 'tests/fp/berkeley-testfloat-3' (https://github.com/cota/berkeley-testfloat-3) registered for path 'tests/fp/berkeley-testfloat-3'
Submodule 'ui/keycodemapdb' (https://git.qemu.org/git/keycodemapdb.git) registered for path 'ui/keycodemapdb'
Cloning into 'capstone'...
Submodule path 'capstone': checked out '22ead3e0bfdb87516656453336160e0a37b066bf'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '88f18909db731a627456f26d779445f84e449536'
Cloning into 'roms/QemuMacDrivers'...
Submodule path 'roms/QemuMacDrivers': checked out '90c488d5f4a407342247b9ea869df1c2d9c8e266'
Cloning into 'roms/SLOF'...
Submodule path 'roms/SLOF': checked out 'a5b428e1c1eae703bdd62a3f527223c291ee3fdc'
Cloning into 'roms/ipxe'...
Submodule path 'roms/ipxe': checked out 'de4565cbe76ea9f7913a01f331be3ee901bb6e17'
Cloning into 'roms/openbios'...
Submodule path 'roms/openbios': checked out '3464681b2b5983df80086a40179d324102347da3'
Cloning into 'roms/openhackware'...
Submodule path 'roms/openhackware': checked out 'c559da7c8eec5e45ef1f67978827af6f0b9546f5'
Cloning into 'roms/qemu-palcode'...
Submodule path 'roms/qemu-palcode': checked out '51c237d7e20d05100eacadee2f61abc17e6bc097'
Cloning into 'roms/seabios'...
Submodule path 'roms/seabios': checked out 'a698c8995ffb2838296ec284fe3c4ad33dfca307'
Cloning into 'roms/seabios-hppa'...
Submodule path 'roms/seabios-hppa': checked out '1ef99a01572c2581c30e16e6fe69e9ea2ef92ce0'
Cloning into 'roms/sgabios'...
Submodule path 'roms/sgabios': checked out 'cbaee52287e5f32373181cff50a00b6c4ac9015a'
Cloning into 'roms/skiboot'...
Submodule path 'roms/skiboot': checked out 'e0ee24c27a172bcf482f6f2bc905e6211c134bcc'
Cloning into 'roms/u-boot'...
Submodule path 'roms/u-boot': checked out 'd85ca029f257b53a96da6c2fb421e78a003a9943'
Cloning into 'roms/u-boot-sam460ex'...
Submodule path 'roms/u-boot-sam460ex': checked out '60b3916f33e617a815973c5a6df77055b2e3a588'
Cloning into 'tests/fp/berkeley-softfloat-3'...
Submodule path 'tests/fp/berkeley-softfloat-3': checked out 'b64af41c3276f97f0e181920400ee056b9c88037'
Cloning into 'tests/fp/berkeley-testfloat-3'...
Submodule path 'tests/fp/berkeley-testfloat-3': checked out '5a59dcec19327396a011a17fd924aed4fec416b3'
Cloning into 'ui/keycodemapdb'...
Submodule path 'ui/keycodemapdb': checked out '6b3d716e2b6472eb7189d3220552280ef3d832ce'
Switched to a new branch 'test'
0399818 hw/arm hw/xtensa: De-duplicate pflash creation code some
8900ef3 pflash: Clean up after commit 368a354f02b part 2
b2a752e pflash: Clean up after commit 368a354f02b part 1
6161e9b mips_malta: Clean up definition of flash memory size somewhat
f63e1b9 r2d: Flash memory creation is confused about size, mark FIXME
c940613 ppc405_boards: Don't size flash memory to match backing image
aafbf2b sam460ex: Don't size flash memory to match backing image
50c58aa hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
32f306b pflash: Macro PFLASH_BUG() is used just once, expand
ab1e43c pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit ab1e43ce7b8b (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 32f306be2381 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 50c58aaaeff5 (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit aafbf2b0cbd5 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit c940613c6fd9 (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit f63e1b95beaf (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit 6161e9b2e1a1 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit b2a752e969e1 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#90: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#98: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 8900ef3eb27a (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 03998181d548 (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME Markus Armbruster
@ 2019-02-19 14:03   ` Peter Maydell
  2019-02-19 15:45     ` Markus Armbruster
  2019-02-19 16:02   ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 97+ messages in thread
From: Peter Maydell @ 2019-02-19 14:03 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: QEMU Developers, Kevin Wolf, Qemu-block, Alex Bennée,
	Magnus Damm, Max Reitz, qemu-ppc, Laszlo Ersek

On Mon, 18 Feb 2019 at 13:07, Markus Armbruster <armbru@redhat.com> wrote:
>
> pflash_cfi02_register() takes a size in bytes, a block size in bytes
> and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
> FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
> number of blocks.  The latter happens to win.  I tried to find
> documentation on the physcial hardware, no luck.
>
> For now, adjust the byte size passed to match the actual size created,
> and add a FIXME comment.

I'm pretty sure that FLASH_SIZE here is supposed to be a
byte count of the size of the pflash. That matches what
Linux has in arch/sh/boards/mach-r2d/setup.c where it
sets up the flash_resource struct.

The r2dplus board is also I think known as RTS7751R2D. That
takes us to https://elinux.org/RTS7751R2D_Handling_Manual
(sadly the link to the "hardware manual" is broken).

No idea what the block size would be.


thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some Markus Armbruster
  2019-02-18 17:12   ` Laszlo Ersek
  2019-02-19  8:43   ` Max Filippov
@ 2019-02-19 14:13   ` Peter Maydell
  2019-02-19 15:46     ` Markus Armbruster
  2 siblings, 1 reply; 97+ messages in thread
From: Peter Maydell @ 2019-02-19 14:13 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: QEMU Developers, Kevin Wolf, Qemu-block, Alex Bennée,
	Max Reitz, qemu-ppc, Laszlo Ersek

On Mon, 18 Feb 2019 at 13:08, Markus Armbruster <armbru@redhat.com> wrote:
>
> pflash_cfi01_register() creates a TYPE_CFI_PFLASH01 device, sets
> properties, realizes, and wires up.
>
> We have three modified copies of it, because their users need to set
> additional properties, or have the wiring done differently.
>
> Factor out their common part into pflash_cfi01_create().
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/vexpress.c        | 22 +++++-----------------
>  hw/arm/virt.c            | 26 +++++++++-----------------
>  hw/block/pflash_cfi01.c  | 39 +++++++++++++++++++++++++++------------
>  hw/xtensa/xtfpga.c       | 18 +++++++-----------
>  include/hw/block/flash.h |  8 ++++++++
>  5 files changed, 56 insertions(+), 57 deletions(-)
>
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index 00913f2655..b23c63ed24 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -515,26 +515,14 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>  static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>                                               DriveInfo *di)
>  {
> -    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
> +    DeviceState *dev;
>
> -    if (di) {
> -        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
> -                            &error_abort);
> -    }
> -
> -    qdev_prop_set_uint32(dev, "num-blocks",
> -                         VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE);
> -    qdev_prop_set_uint64(dev, "sector-length", VEXPRESS_FLASH_SECT_SIZE);
> -    qdev_prop_set_uint8(dev, "width", 4);
> +    dev = DEVICE(pflash_cfi01_create(name, VEXPRESS_FLASH_SIZE,
> +                                     di ? blk_by_legacy_dinfo(di) : NULL,
> +                                     VEXPRESS_FLASH_SECT_SIZE,
> +                                     4, 0x89, 0x18, 0x00, 0x00, false));
>      qdev_prop_set_uint8(dev, "device-width", 2);
> -    qdev_prop_set_bit(dev, "big-endian", false);
> -    qdev_prop_set_uint16(dev, "id0", 0x89);
> -    qdev_prop_set_uint16(dev, "id1", 0x18);
> -    qdev_prop_set_uint16(dev, "id2", 0x00);
> -    qdev_prop_set_uint16(dev, "id3", 0x00);
> -    qdev_prop_set_string(dev, "name", name);
>      qdev_init_nofail(dev);
> -
>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
>      return CFI_PFLASH01(dev);
>  }

I prefer this code the way it stands. In particular the
"call another function but then set the 'device-width'
property here" looks dubious. But broadly speaking the
"do all the property setting directly rather than calling
a helper function" is the style choice I think we should
be aiming for. (The prevalence of the other approach is
due to a mix of (1) older code we haven't updated and
(2) property-setting being annoyingly heavyweight
syntax.)

thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-19 13:41     ` Markus Armbruster
@ 2019-02-19 14:33       ` Philippe Mathieu-Daudé
  2019-02-21  9:15         ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 14:33 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, kwolf, qemu-block, lersek, mreitz, qemu-ppc, alex.bennee

On 2/19/19 2:41 PM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> 
>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>>> flash.h's incomplete struct pflash_t is completed both in
>>> pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
>>> incompatible.  This can hide type errors, such as passing a pflash_t
>>> created with pflash_cfi02_register() to pflash_cfi01_get_memory().
>>>
>>> Furthermore, POSIX reserves typedef names ending with _t.

Worth adding in CODING_STYLE 'Naming' section :)

>>>
>>> Rename the two structs to PFlashCFI01 and PFlashCFI02.
>>
>> Why not ParallelFlashCFIxx?
> 
> Feels a bit long, and we abbreviate to pflash pretty consistently.  That
> said, I'm not particularly enamored with my choice of name :)
> 
>> Ideally ParallelFlashCFI would be an InterfaceInfo...
> 
> You mean TYPE_CFI_PFLASH0{1,2} should be children of an abstract parent?

I'd use "TYPE_PFLASH_CFI0[12]".

---

The "Common Flash memory Interface" as stated is definitively an
interface :)

QEMU models the 2 most famous industry implementations:

- vendor 0x01: Intel (and Sharp)
- vendor 0x02: AMD (and Fujistu)

---

My first refactor attempt was to have both implementations inheritate
from an abstract parent, but since the migration structures are
different, it looked easier to me to extract an InterfaceInfo.

>From here my idea was to add an NorFlash abstract parent where to share
the block devices and some of the reset:

            +-------------------+
            |                   |
            |    NOR Flash      |
            |                   |
            +-------------------+
              |    Parent     |
              |               |
              |               |
 +------------v---+       +---v------------+
 |                |       |                |
 |    PFlash01    |       |    PFlash02    |
 |                |       |                |
 +----------------+       +----------------+
     Child      |           |
                |           |
                | Implements|
            +---v-----------v---+
            |                   |
            |     CFI Flash     |
            |                   |
            +-------------------+

But since there is no consumer of the CFI InterfaceInfo, we can simply
go the way you suggested:

            +-------------------+
            |                   |
            |   CFI NOR Flash   |
            |                   |
            +-------------------+
              |    Parent     |
              |               |
 +------------v---+       +---v------------+
 |                |       |                |
 |    PFlash01    |       |    PFlash02    |
 |                |       |                |
 +----------------+       +----------------+
        Child                   Child

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 05/10] ppc405_boards: " Markus Armbruster
  2019-02-19  3:55   ` David Gibson
@ 2019-02-19 15:28   ` BALATON Zoltan
  2019-02-19 15:55     ` Markus Armbruster
  2019-02-21 15:20   ` [Qemu-devel] " Alex Bennée
  2 siblings, 1 reply; 97+ messages in thread
From: BALATON Zoltan @ 2019-02-19 15:28 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, kwolf, qemu-block, alex.bennee, mreitz, qemu-ppc,
	lersek, David Gibson

On Mon, 18 Feb 2019, Markus Armbruster wrote:
> Machine "ref405ep" maps its flash memory at address 2^32 - image size.
> Image size is rounded up to the next multiple of 64KiB.  Useless,
> because pflash_cfi02_realize() fails with "failed to read the initial
> flash content" unless the rounding is a no-op.
>
> If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
> other stuff.  No idea how that would play out, but a useful outcomes
> seem unlikely.
>
> Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
> regardless of image size, to match the physical hardware.

If PPC405 behaves the same as PPC440 and starts at 0xfffffffc then this 
won't boot. It's maybe better to keep 2^32 - image_size but assert image 
is not bigger than 512kB. But I don't know anything about these boards so 
just sharing this comment for your consideration. I'm fine with any 
decision you take.

Regards,
BALATON Zoltan

> Machine "taihu" maps its boot flash memory similarly.  The code even
> has a comment /* XXX: should check that size is 2MB */, followed by
> disabled code to adjust the size to 2MiB regardless of image size.
>
> Its code to map its application flash memory looks the same, except
> there the XXX comment asks for 32MiB, and the code to adjust the size
> isn't disabled.  Note that pflash_cfi02_realize() fails with "failed
> to read the initial flash content" for images smaller than 32MiB.
>
> Map the boot flash memory at fixed address 0xFFE00000 with size 2MiB,
> to match the physical hardware.  Delete dead code from application
> flash mapping, and simplify some.
>
> Cc: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> hw/ppc/ppc405_boards.c | 53 +++++++++++++-----------------------------
> 1 file changed, 16 insertions(+), 37 deletions(-)
>
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index f47b15f10e..728154aebb 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -158,7 +158,7 @@ static void ref405ep_init(MachineState *machine)
>     target_ulong kernel_base, initrd_base;
>     long kernel_size, initrd_size;
>     int linux_boot;
> -    int fl_idx, fl_sectors, len;
> +    int len;
>     DriveInfo *dinfo;
>     MemoryRegion *sysmem = get_system_memory();
>
> @@ -185,26 +185,19 @@ static void ref405ep_init(MachineState *machine)
> #ifdef DEBUG_BOARD_INIT
>     printf("%s: register BIOS\n", __func__);
> #endif
> -    fl_idx = 0;
> #ifdef USE_FLASH_BIOS
> -    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
> +    dinfo = drive_get(IF_PFLASH, 0, 0);
>     if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        fl_sectors = (bios_size + 65535) >> 16;
> #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr %lx '%s' %d\n",
> -               fl_idx, bios_size, -bios_size,
> -               blk_name(blk), fl_sectors);
> +        printf("Register parallel flash\n");
> #endif
> -        pflash_cfi02_register((uint32_t)(-bios_size),
> +        bios_size = 0x80000;
> +        pflash_cfi02_register(0xFFF80000,
>                               NULL, "ef405ep.bios", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,
>                               2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                               1);
> -        fl_idx++;
>     } else
> #endif
>     {
> @@ -455,7 +448,7 @@ static void taihu_405ep_init(MachineState *machine)
>     target_ulong kernel_base, initrd_base;
>     long kernel_size, initrd_size;
>     int linux_boot;
> -    int fl_idx, fl_sectors;
> +    int fl_idx;
>     DriveInfo *dinfo;
>
>     /* RAM is soldered to the board so the size cannot be changed */
> @@ -486,21 +479,14 @@ static void taihu_405ep_init(MachineState *machine)
> #if defined(USE_FLASH_BIOS)
>     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>     if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        /* XXX: should check that size is 2MB */
> -        //        bios_size = 2 * 1024 * 1024;
> -        fl_sectors = (bios_size + 65535) >> 16;
> #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr %lx '%s' %d\n",
> -               fl_idx, bios_size, -bios_size,
> -               blk_name(blk), fl_sectors);
> +        printf("Register boot flash\n");
> #endif
> -        pflash_cfi02_register((uint32_t)(-bios_size),
> +        bios_size = 2 * MiB;
> +        pflash_cfi02_register(0xFFE00000,
>                               NULL, "taihu_405ep.bios", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,
>                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                               1);
>         fl_idx++;
> @@ -536,20 +522,13 @@ static void taihu_405ep_init(MachineState *machine)
>     /* Register Linux flash */
>     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>     if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        /* XXX: should check that size is 32MB */
>         bios_size = 32 * MiB;
> -        fl_sectors = (bios_size + 65535) >> 16;
> #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr " TARGET_FMT_lx " '%s'\n",
> -               fl_idx, bios_size, (target_ulong)0xfc000000,
> -               blk_name(blk));
> +        printf("Register application flash\n"
> #endif
>         pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,
>                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                               1);
>         fl_idx++;
>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-19 14:03   ` Peter Maydell
@ 2019-02-19 15:45     ` Markus Armbruster
  2019-02-19 15:53       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 15:45 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Kevin Wolf, Qemu-block, Laszlo Ersek, Magnus Damm,
	QEMU Developers, Max Reitz, qemu-ppc, Alex Bennée

Peter Maydell <peter.maydell@linaro.org> writes:

> On Mon, 18 Feb 2019 at 13:07, Markus Armbruster <armbru@redhat.com> wrote:
>>
>> pflash_cfi02_register() takes a size in bytes, a block size in bytes
>> and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
>> FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
>> number of blocks.  The latter happens to win.  I tried to find
>> documentation on the physcial hardware, no luck.
>>
>> For now, adjust the byte size passed to match the actual size created,
>> and add a FIXME comment.
>
> I'm pretty sure that FLASH_SIZE here is supposed to be a
> byte count of the size of the pflash. That matches what
> Linux has in arch/sh/boards/mach-r2d/setup.c where it
> sets up the flash_resource struct.

Okay, that's some evidence for size 0x02000000 (32MiB).

However, we've created size (16 * KiB) * (FLASH_SIZE >> 16), i.e. 8MiB,
since at least commit 368a354f02b (v1.3.0), possibly since forever.

> The r2dplus board is also I think known as RTS7751R2D. That
> takes us to https://elinux.org/RTS7751R2D_Handling_Manual
> (sadly the link to the "hardware manual" is broken).

Quote section Flash ROM Mapping:

    Currently, MTD device mapping on Flash ROM is set as below.
    0x00000000-0x00020000 	"bootloader" 	
    0x00020000-0x00320000 	"mtdblock1" 	XIP kernel
    0x00320000-0x00520000 	"mtdblock2" 	
    0x00520000-0x01000000 	"mtdblock3" 	

Suggests a size of 0x01000000 (16MiB).  Now we have three candidates.

Pick one, any one, and I'll adjust my patch.  All I really care about is
getting argument @size consistent with arguments @sector_len and
@nb_blocs, so I can ditch @nb_blocs in PATCH 09.

> No idea what the block size would be.

As long as that's the case, inertia wins by default.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some
  2019-02-19 14:13   ` Peter Maydell
@ 2019-02-19 15:46     ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Kevin Wolf, Qemu-block, Laszlo Ersek, QEMU Developers, Max Reitz,
	qemu-ppc, Alex Bennée

Peter Maydell <peter.maydell@linaro.org> writes:

> On Mon, 18 Feb 2019 at 13:08, Markus Armbruster <armbru@redhat.com> wrote:
>>
>> pflash_cfi01_register() creates a TYPE_CFI_PFLASH01 device, sets
>> properties, realizes, and wires up.
>>
>> We have three modified copies of it, because their users need to set
>> additional properties, or have the wiring done differently.
>>
>> Factor out their common part into pflash_cfi01_create().
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/arm/vexpress.c        | 22 +++++-----------------
>>  hw/arm/virt.c            | 26 +++++++++-----------------
>>  hw/block/pflash_cfi01.c  | 39 +++++++++++++++++++++++++++------------
>>  hw/xtensa/xtfpga.c       | 18 +++++++-----------
>>  include/hw/block/flash.h |  8 ++++++++
>>  5 files changed, 56 insertions(+), 57 deletions(-)
>>
>> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
>> index 00913f2655..b23c63ed24 100644
>> --- a/hw/arm/vexpress.c
>> +++ b/hw/arm/vexpress.c
>> @@ -515,26 +515,14 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>>  static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>>                                               DriveInfo *di)
>>  {
>> -    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>> +    DeviceState *dev;
>>
>> -    if (di) {
>> -        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
>> -                            &error_abort);
>> -    }
>> -
>> -    qdev_prop_set_uint32(dev, "num-blocks",
>> -                         VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE);
>> -    qdev_prop_set_uint64(dev, "sector-length", VEXPRESS_FLASH_SECT_SIZE);
>> -    qdev_prop_set_uint8(dev, "width", 4);
>> +    dev = DEVICE(pflash_cfi01_create(name, VEXPRESS_FLASH_SIZE,
>> +                                     di ? blk_by_legacy_dinfo(di) : NULL,
>> +                                     VEXPRESS_FLASH_SECT_SIZE,
>> +                                     4, 0x89, 0x18, 0x00, 0x00, false));
>>      qdev_prop_set_uint8(dev, "device-width", 2);
>> -    qdev_prop_set_bit(dev, "big-endian", false);
>> -    qdev_prop_set_uint16(dev, "id0", 0x89);
>> -    qdev_prop_set_uint16(dev, "id1", 0x18);
>> -    qdev_prop_set_uint16(dev, "id2", 0x00);
>> -    qdev_prop_set_uint16(dev, "id3", 0x00);
>> -    qdev_prop_set_string(dev, "name", name);
>>      qdev_init_nofail(dev);
>> -
>>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
>>      return CFI_PFLASH01(dev);
>>  }
>
> I prefer this code the way it stands. In particular the
> "call another function but then set the 'device-width'
> property here" looks dubious. But broadly speaking the
> "do all the property setting directly rather than calling
> a helper function" is the style choice I think we should
> be aiming for. (The prevalence of the other approach is
> due to a mix of (1) older code we haven't updated and
> (2) property-setting being annoyingly heavyweight
> syntax.)

Okay, no problem.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-19 15:45     ` Markus Armbruster
@ 2019-02-19 15:53       ` Philippe Mathieu-Daudé
  2019-02-19 17:30         ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 15:53 UTC (permalink / raw)
  To: Markus Armbruster, Peter Maydell
  Cc: Kevin Wolf, Qemu-block, Alex Bennée, Magnus Damm,
	QEMU Developers, Max Reitz, qemu-ppc, Laszlo Ersek

On 2/19/19 4:45 PM, Markus Armbruster wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
> 
>> On Mon, 18 Feb 2019 at 13:07, Markus Armbruster <armbru@redhat.com> wrote:
>>>
>>> pflash_cfi02_register() takes a size in bytes, a block size in bytes
>>> and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
>>> FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
>>> number of blocks.  The latter happens to win.  I tried to find
>>> documentation on the physcial hardware, no luck.

"physical"

>>>
>>> For now, adjust the byte size passed to match the actual size created,
>>> and add a FIXME comment.
>>
>> I'm pretty sure that FLASH_SIZE here is supposed to be a
>> byte count of the size of the pflash. That matches what
>> Linux has in arch/sh/boards/mach-r2d/setup.c where it
>> sets up the flash_resource struct.
> 
> Okay, that's some evidence for size 0x02000000 (32MiB).
> 
> However, we've created size (16 * KiB) * (FLASH_SIZE >> 16), i.e. 8MiB,
> since at least commit 368a354f02b (v1.3.0), possibly since forever.
> 
>> The r2dplus board is also I think known as RTS7751R2D. That
>> takes us to https://elinux.org/RTS7751R2D_Handling_Manual
>> (sadly the link to the "hardware manual" is broken).
> 
> Quote section Flash ROM Mapping:
> 
>     Currently, MTD device mapping on Flash ROM is set as below.
>     0x00000000-0x00020000 	"bootloader" 	
>     0x00020000-0x00320000 	"mtdblock1" 	XIP kernel
>     0x00320000-0x00520000 	"mtdblock2" 	
>     0x00520000-0x01000000 	"mtdblock3" 	
> 
> Suggests a size of 0x01000000 (16MiB).  Now we have three candidates.
> 
> Pick one, any one, and I'll adjust my patch.  All I really care about is
> getting argument @size consistent with arguments @sector_len and
> @nb_blocs, so I can ditch @nb_blocs in PATCH 09.
> 
>> No idea what the block size would be.
> 
> As long as that's the case, inertia wins by default.

There is also a paper [*]:

  The Renesas Technology R0P751RLC001RL (R2DPLUS) board was used
  as our target device.
  This board is often used to evaluate software for CE devices.
  The specification is shown below.
    CPU: SH7751R(SH4) 240Mhz
    RAM: 64Mbyte
    Compact flash: 512Mbyte
    Flash ROM: 64Mbyte (32Mbyte available for root file system)

Let's use at least 16MB to be able to run the elinux cited kernel.

[*] https://www.kernel.org/doc/ols/2008/ols2008v2-pages-125-134.pdf

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-19 15:28   ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
@ 2019-02-19 15:55     ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 15:55 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: kwolf, qemu-block, lersek, qemu-devel, mreitz, qemu-ppc,
	alex.bennee, David Gibson

BALATON Zoltan <balaton@eik.bme.hu> writes:

> On Mon, 18 Feb 2019, Markus Armbruster wrote:
>> Machine "ref405ep" maps its flash memory at address 2^32 - image size.
>> Image size is rounded up to the next multiple of 64KiB.  Useless,
>> because pflash_cfi02_realize() fails with "failed to read the initial
>> flash content" unless the rounding is a no-op.
>>
>> If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
>> other stuff.  No idea how that would play out, but a useful outcomes
>> seem unlikely.
>>
>> Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
>> regardless of image size, to match the physical hardware.
>
> If PPC405 behaves the same as PPC440 and starts at 0xfffffffc then
> this won't boot. It's maybe better to keep 2^32 - image_size but
> assert image is not bigger than 512kB. But I don't know anything about
> these boards so just sharing this comment for your consideration. I'm
> fine with any decision you take.

If the image is smaller than 512KiB, pflash_cfi02_realize() fails with
"failed to read the initial flash content".

Alex Bennée has a patch that'll make it fail for any size mismatch, with
a much nicer error message.  I like it; silently truncating firmware
images is unlikely to be useful.

For what it's worth, my patch brings this board into line with most
other boards: create flash memory of fixed size at a fixed address,
matching the physical machine we emulate.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME Markus Armbruster
  2019-02-19 14:03   ` Peter Maydell
@ 2019-02-19 16:02   ` Philippe Mathieu-Daudé
  2019-02-19 16:21     ` Peter Maydell
  1 sibling, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 16:02 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: kwolf, qemu-block, alex.bennee, Magnus Damm, mreitz, qemu-ppc, lersek

On 2/18/19 1:56 PM, Markus Armbruster wrote:
> pflash_cfi02_register() takes a size in bytes, a block size in bytes
> and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
> FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
> number of blocks.  The latter happens to win.  I tried to find
> documentation on the physcial hardware, no luck.
> 
> For now, adjust the byte size passed to match the actual size created,
> and add a FIXME comment.
> 
> Cc: Magnus Damm <magnus.damm@gmail.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/sh4/r2d.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
> index dcdb3728cb..ed18d1f351 100644
> --- a/hw/sh4/r2d.c
> +++ b/hw/sh4/r2d.c
> @@ -290,7 +290,14 @@ static void r2d_init(MachineState *machine)
>  
>      /* onboard flash memory */
>      dinfo = drive_get(IF_PFLASH, 0, 0);
> -    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
> +    /*
> +     * FIXME The code is confused about the size of the flash.  It
> +     * used to pass FLASH_SIZE bytes, in FLASH_SIZE >> 16 blocks of
> +     * 16KiB each, which does not compute, but creates one of
> +     * FLASH_SIZE / 4 bytes anyway.  The current code does so too, but
> +     * whether it's the right size is anybody's guess.
> +     */
> +    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE / 4,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            16 * KiB, FLASH_SIZE >> 16,
>                            1, 4, 0x0000, 0x0000, 0x0000, 0x0000,

Good news: when you read (0x0000, 0x0000, 0x0000, 0x0000) pflash IDs,
that means the code uses the "Virt PFlash". IOW this is not a physical
model, since the guest obviously doesn't care about checking the flash
model.
The "VirtPFlash" only has 64KiB sectors.

I suggest we add a pflash_cfi02_create_virt(reduced args) helper to make
this obvious:

  pflash_cfi02_create_virt(paddr, name, size_bytes, mapping?).

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat
  2019-02-19 13:43     ` Markus Armbruster
@ 2019-02-19 16:10       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 16:10 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, kwolf, qemu-block, Aleksandar Rikalo, lersek, mreitz,
	qemu-ppc, alex.bennee, Aurelien Jarno

On 2/19/19 2:43 PM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> 
>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>>> pflash_cfi01_register() takes a size in bytes, a block size in bytes
>>> and a number of blocks.  mips_malta_init() passes BIOS_SIZE, 65536,
>>> FLASH_SIZE >> 16.  Actually consistent only because BIOS_SIZE (defined
>>> in include/hw/mips/bios.h as (4 * MiB)) matches FLASH_SIZE (defined
>>> locally as 0x400000).  Confusing all the same.
>>>
>>> Pass FLASH_SIZE instead of BIOS_SIZE.
>>
>> Your cleanup is correct.
>>
>>>
>>> There are more uses of BIOS_SIZE, but I don't sufficiently understand
>>> them to attempt cleanup.
>>
>> BIOS_SIZE is a MIPS architecture definition, incorrectly used around.
>> This simply means "Top of 32bit address space - Boot Vector address".
>> There is nothing wrong in plugging bigger/smaller flashes around the
>> boot vector.
>> (I have a series cleaning this definition, but I'm throttling my MIPS
>> apports).
>>
>>>
>>> Cc: Aurelien Jarno <aurelien@aurel32.net>
>>> Cc: Aleksandar Rikalo <arikalo@wavecomp.com>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> ---
>>>  hw/mips/mips_malta.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
>>> index fff5ed19bd..65cdda4881 100644
>>> --- a/hw/mips/mips_malta.c
>>> +++ b/hw/mips/mips_malta.c
>>> @@ -1269,12 +1269,12 @@ void mips_malta_init(MachineState *machine)
>>>      if (dinfo) {
>>>          printf("Register parallel flash %d size " TARGET_FMT_lx " at "
>>>                 "addr %08llx '%s' %x\n",
>>> -               fl_idx, bios_size, FLASH_ADDRESS,
>>> +               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
>>>                 blk_name(dinfo->bdrv), fl_sectors);
>>>      }
>>>  #endif
>>>      fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
>>> -                               BIOS_SIZE,
>>> +                               FLASH_SIZE,
>>>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>>>                                 65536, fl_sectors,
>>>                                 4, 0x0000, 0x0000, 0x0000, 0x0000, be);
>>>
>>
>> Does that mean you can remove the "hw/mips/bios.h" include now?
> 
> No, since there are more uses of BIOS_SIZE in this file.  They feel
> inappropriate to me, but I don't feel confident enough to attempt
> cleanup.

OK, since I already did it twice, I'll do it once your work get merged.

> 
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
> Thanks!
> 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1 Markus Armbruster
  2019-02-18 16:50   ` Laszlo Ersek
@ 2019-02-19 16:12   ` Philippe Mathieu-Daudé
  2019-02-21 15:57   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-19 16:12 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel
  Cc: kwolf, qemu-block, alex.bennee, mreitz, qemu-ppc, lersek

On 2/18/19 1:56 PM, Markus Armbruster wrote:
> QOMification left parameter @qdev unused in pflash_cfi01_register()
> and pflash_cfi02_register().  All callers pass NULL.  Remove.

Good patch to discretly include a "rename to pflash_cfi01_create()" :P

> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  hw/arm/collie.c                          | 4 ++--
>  hw/arm/digic_boards.c                    | 2 +-
>  hw/arm/gumstix.c                         | 4 ++--
>  hw/arm/mainstone.c                       | 2 +-
>  hw/arm/musicpal.c                        | 4 ++--
>  hw/arm/omap_sx1.c                        | 4 ++--
>  hw/arm/versatilepb.c                     | 2 +-
>  hw/arm/xilinx_zynq.c                     | 2 +-
>  hw/arm/z2.c                              | 3 +--
>  hw/block/pflash_cfi01.c                  | 2 +-
>  hw/block/pflash_cfi02.c                  | 2 +-
>  hw/i386/pc_sysfw.c                       | 2 +-
>  hw/lm32/lm32_boards.c                    | 4 ++--
>  hw/lm32/milkymist.c                      | 2 +-
>  hw/microblaze/petalogix_ml605_mmu.c      | 3 +--
>  hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
>  hw/mips/mips_malta.c                     | 2 +-
>  hw/mips/mips_r4k.c                       | 2 +-
>  hw/ppc/ppc405_boards.c                   | 6 +++---
>  hw/ppc/sam460ex.c                        | 2 +-
>  hw/ppc/virtex_ml507.c                    | 2 +-
>  hw/sh4/r2d.c                             | 2 +-
>  include/hw/block/flash.h                 | 4 ++--
>  23 files changed, 31 insertions(+), 33 deletions(-)
> 
> diff --git a/hw/arm/collie.c b/hw/arm/collie.c
> index 48b732c176..cbc4400f8e 100644
> --- a/hw/arm/collie.c
> +++ b/hw/arm/collie.c
> @@ -36,12 +36,12 @@ static void collie_init(MachineState *machine)
>      s = sa1110_init(sysmem, collie_binfo.ram_size, machine->cpu_type);
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
> -    pflash_cfi01_register(SA_CS0, NULL, "collie.fl1", 0x02000000,
> +    pflash_cfi01_register(SA_CS0, "collie.fl1", 0x02000000,
>                      dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                      (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
>  
>      dinfo = drive_get(IF_PFLASH, 0, 1);
> -    pflash_cfi01_register(SA_CS1, NULL, "collie.fl2", 0x02000000,
> +    pflash_cfi01_register(SA_CS1, "collie.fl2", 0x02000000,
>                      dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                      (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
>  
> diff --git a/hw/arm/digic_boards.c b/hw/arm/digic_boards.c
> index 9f11dcd11f..15a00a1be3 100644
> --- a/hw/arm/digic_boards.c
> +++ b/hw/arm/digic_boards.c
> @@ -129,7 +129,7 @@ static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
>  #define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
>  #define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
>  
> -    pflash_cfi02_register(addr, NULL, "pflash", FLASH_K8P3215UQB_SIZE,
> +    pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE,
>                            NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
>                            FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE,
>                            DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
> diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c
> index 56cb763c4e..304dbeab2f 100644
> --- a/hw/arm/gumstix.c
> +++ b/hw/arm/gumstix.c
> @@ -72,7 +72,7 @@ static void connex_init(MachineState *machine)
>  #else
>      be = 0;
>  #endif
> -    if (!pflash_cfi01_register(0x00000000, NULL, "connext.rom", connex_rom,
> +    if (!pflash_cfi01_register(0x00000000, "connext.rom", connex_rom,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 sector_len, connex_rom / sector_len,
>                                 2, 0, 0, 0, 0, be)) {
> @@ -109,7 +109,7 @@ static void verdex_init(MachineState *machine)
>  #else
>      be = 0;
>  #endif
> -    if (!pflash_cfi01_register(0x00000000, NULL, "verdex.rom", verdex_rom,
> +    if (!pflash_cfi01_register(0x00000000, "verdex.rom", verdex_rom,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 sector_len, verdex_rom / sector_len,
>                                 2, 0, 0, 0, 0, be)) {
> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
> index 0beb5c426b..2a1c1072db 100644
> --- a/hw/arm/mainstone.c
> +++ b/hw/arm/mainstone.c
> @@ -148,7 +148,7 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
>              exit(1);
>          }
>  
> -        if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
> +        if (!pflash_cfi01_register(mainstone_flash_base[i],
>                                     i ? "mainstone.flash1" : "mainstone.flash0",
>                                     MAINSTONE_FLASH,
>                                     blk_by_legacy_dinfo(dinfo),
> diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
> index d22532a11c..ecca0e6f64 100644
> --- a/hw/arm/musicpal.c
> +++ b/hw/arm/musicpal.c
> @@ -1636,14 +1636,14 @@ static void musicpal_init(MachineState *machine)
>           * image is smaller than 32 MB.
>           */
>  #ifdef TARGET_WORDS_BIGENDIAN
> -        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
> +        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
>                                "musicpal.flash", flash_size,
>                                blk, 0x10000, (flash_size + 0xffff) >> 16,
>                                MP_FLASH_SIZE_MAX / flash_size,
>                                2, 0x00BF, 0x236D, 0x0000, 0x0000,
>                                0x5555, 0x2AAA, 1);
>  #else
> -        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
> +        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
>                                "musicpal.flash", flash_size,
>                                blk, 0x10000, (flash_size + 0xffff) >> 16,
>                                MP_FLASH_SIZE_MAX / flash_size,
> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
> index 84550f0236..b1128777cf 100644
> --- a/hw/arm/omap_sx1.c
> +++ b/hw/arm/omap_sx1.c
> @@ -152,7 +152,7 @@ static void sx1_init(MachineState *machine, const int version)
>  #endif
>  
>      if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
> -        if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
> +        if (!pflash_cfi01_register(OMAP_CS0_BASE,
>                                     "omap_sx1.flash0-1", flash_size,
>                                     blk_by_legacy_dinfo(dinfo),
>                                     sector_size, flash_size / sector_size,
> @@ -176,7 +176,7 @@ static void sx1_init(MachineState *machine, const int version)
>          memory_region_add_subregion(address_space,
>                                  OMAP_CS1_BASE + flash1_size, &cs[1]);
>  
> -        if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
> +        if (!pflash_cfi01_register(OMAP_CS1_BASE,
>                                     "omap_sx1.flash1-1", flash1_size,
>                                     blk_by_legacy_dinfo(dinfo),
>                                     sector_size, flash1_size / sector_size,
> diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
> index 22b09a1e61..82c5277462 100644
> --- a/hw/arm/versatilepb.c
> +++ b/hw/arm/versatilepb.c
> @@ -365,7 +365,7 @@ static void versatile_init(MachineState *machine, int board_id)
>      /* 0x34000000 NOR Flash */
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
> -    if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, NULL, "versatile.flash",
> +    if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, "versatile.flash",
>                            VERSATILE_FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            VERSATILE_FLASH_SECT_SIZE,
> diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
> index 57497b0c4d..1fa4a77728 100644
> --- a/hw/arm/xilinx_zynq.c
> +++ b/hw/arm/xilinx_zynq.c
> @@ -205,7 +205,7 @@ static void zynq_init(MachineState *machine)
>      DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0);
>  
>      /* AMD */
> -    pflash_cfi02_register(0xe2000000, NULL, "zynq.pflash", FLASH_SIZE,
> +    pflash_cfi02_register(0xe2000000, "zynq.pflash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            FLASH_SECTOR_SIZE,
>                            FLASH_SIZE/FLASH_SECTOR_SIZE, 1,
> diff --git a/hw/arm/z2.c b/hw/arm/z2.c
> index 697a822f1e..54e6caee9f 100644
> --- a/hw/arm/z2.c
> +++ b/hw/arm/z2.c
> @@ -324,8 +324,7 @@ static void z2_init(MachineState *machine)
>          exit(1);
>      }
>  
> -    if (!pflash_cfi01_register(Z2_FLASH_BASE,
> -                               NULL, "z2.flash0", Z2_FLASH_SIZE,
> +    if (!pflash_cfi01_register(Z2_FLASH_BASE, "z2.flash0", Z2_FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 sector_len, Z2_FLASH_SIZE / sector_len,
>                                 4, 0, 0, 0, 0, be)) {
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 43dbb7db26..f2a4b16a34 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -921,7 +921,7 @@ static void pflash_cfi01_register_types(void)
>  type_init(pflash_cfi01_register_types)
>  
>  PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index e9c76d6cfb..73491aafe6 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -717,7 +717,7 @@ static void pflash_cfi02_register_types(void)
>  type_init(pflash_cfi02_register_types)
>  
>  PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,
> diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> index 67e55342f6..9a5be54a85 100644
> --- a/hw/i386/pc_sysfw.c
> +++ b/hw/i386/pc_sysfw.c
> @@ -160,7 +160,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
>  
>          /* pflash_cfi01_register() creates a deep copy of the name */
>          snprintf(name, sizeof name, "system.flash%d", unit);
> -        system_flash = pflash_cfi01_register(phys_addr, NULL /* qdev */, name,
> +        system_flash = pflash_cfi01_register(phys_addr, name,
>                                               size, blk, sector_size,
>                                               size >> sector_bits,
>                                               1      /* width */,
> diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
> index 05157f8eab..f726355309 100644
> --- a/hw/lm32/lm32_boards.c
> +++ b/hw/lm32/lm32_boards.c
> @@ -114,7 +114,7 @@ static void lm32_evr_init(MachineState *machine)
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* Spansion S29NS128P */
> -    pflash_cfi02_register(flash_base, NULL, "lm32_evr.flash", flash_size,
> +    pflash_cfi02_register(flash_base, "lm32_evr.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            flash_sector_size, flash_size / flash_sector_size,
>                            1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
> @@ -207,7 +207,7 @@ static void lm32_uclinux_init(MachineState *machine)
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* Spansion S29NS128P */
> -    pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
> +    pflash_cfi02_register(flash_base, "lm32_uclinux.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            flash_sector_size, flash_size / flash_sector_size,
>                            1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
> diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
> index b080cf1ca9..ece7e3b699 100644
> --- a/hw/lm32/milkymist.c
> +++ b/hw/lm32/milkymist.c
> @@ -121,7 +121,7 @@ milkymist_init(MachineState *machine)
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* Numonyx JS28F256J3F105 */
> -    pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
> +    pflash_cfi01_register(flash_base, "milkymist.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            flash_sector_size, flash_size / flash_sector_size,
>                            2, 0x00, 0x89, 0x00, 0x1d, 1);
> diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c
> index c730878d25..74bcc14cda 100644
> --- a/hw/microblaze/petalogix_ml605_mmu.c
> +++ b/hw/microblaze/petalogix_ml605_mmu.c
> @@ -107,8 +107,7 @@ petalogix_ml605_init(MachineState *machine)
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* 5th parameter 2 means bank-width
>       * 10th paremeter 0 means little-endian */
> -    pflash_cfi01_register(FLASH_BASEADDR,
> -                          NULL, "petalogix_ml605.flash", FLASH_SIZE,
> +    pflash_cfi01_register(FLASH_BASEADDR, "petalogix_ml605.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            64 * KiB, FLASH_SIZE >> 16,
>                            2, 0x89, 0x18, 0x0000, 0x0, 0);
> diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c
> index b9f0b0d06e..a07b7f8edf 100644
> --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
> +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
> @@ -88,7 +88,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      pflash_cfi01_register(FLASH_BASEADDR,
> -                          NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE,
> +                          "petalogix_s3adsp1800.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            64 * KiB, FLASH_SIZE >> 16,
>                            1, 0x89, 0x18, 0x0000, 0x0, 1);
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index 65cdda4881..76b81b7402 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -1273,7 +1273,7 @@ void mips_malta_init(MachineState *machine)
>                 blk_name(dinfo->bdrv), fl_sectors);
>      }
>  #endif
> -    fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
> +    fl = pflash_cfi01_register(FLASH_ADDRESS, "mips_malta.bios",
>                                 FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 65536, fl_sectors,
> diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
> index a015a6d14e..0b9df466e7 100644
> --- a/hw/mips/mips_r4k.c
> +++ b/hw/mips/mips_r4k.c
> @@ -235,7 +235,7 @@ void mips_r4k_init(MachineState *machine)
>          load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
>      } else if ((dinfo = drive_get(IF_PFLASH, 0, 0)) != NULL) {
>          uint32_t mips_rom = 0x00400000;
> -        if (!pflash_cfi01_register(0x1fc00000, NULL, "mips_r4k.bios", mips_rom,
> +        if (!pflash_cfi01_register(0x1fc00000, "mips_r4k.bios", mips_rom,
>                                     blk_by_legacy_dinfo(dinfo),
>                                     sector_len, mips_rom / sector_len,
>                                     4, 0, 0, 0, 0, be)) {
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index 728154aebb..a54627903d 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -193,7 +193,7 @@ static void ref405ep_init(MachineState *machine)
>  #endif
>          bios_size = 0x80000;
>          pflash_cfi02_register(0xFFF80000,
> -                              NULL, "ef405ep.bios", bios_size,
> +                              "ef405ep.bios", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                65536, bios_size / 65536, 1,
>                                2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
> @@ -484,7 +484,7 @@ static void taihu_405ep_init(MachineState *machine)
>  #endif
>          bios_size = 2 * MiB;
>          pflash_cfi02_register(0xFFE00000,
> -                              NULL, "taihu_405ep.bios", bios_size,
> +                              "taihu_405ep.bios", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                65536, bios_size / 65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
> @@ -526,7 +526,7 @@ static void taihu_405ep_init(MachineState *machine)
>  #ifdef DEBUG_BOARD_INIT
>          printf("Register application flash\n"
>  #endif
> -        pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
> +        pflash_cfi02_register(0xfc000000, "taihu_405ep.flash", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                65536, bios_size / 65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
> index ca8d7ab9c6..a989a8c439 100644
> --- a/hw/ppc/sam460ex.c
> +++ b/hw/ppc/sam460ex.c
> @@ -95,7 +95,7 @@ static int sam460ex_load_uboot(void)
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
> -                               NULL, "sam460ex.flash", FLASH_SIZE,
> +                               "sam460ex.flash", FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 65536, FLASH_SIZE / 65536,
>                                 1, 0x89, 0x18, 0x0000, 0x0, 1)) {
> diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> index 5a711cb3d9..d2085a839c 100644
> --- a/hw/ppc/virtex_ml507.c
> +++ b/hw/ppc/virtex_ml507.c
> @@ -227,7 +227,7 @@ static void virtex_init(MachineState *machine)
>      memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
> -    pflash_cfi01_register(PFLASH_BASEADDR, NULL, "virtex.flash", FLASH_SIZE,
> +    pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            64 * KiB, FLASH_SIZE >> 16,
>                            1, 0x89, 0x18, 0x0000, 0x0, 1);
> diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
> index ed18d1f351..abd3b67c28 100644
> --- a/hw/sh4/r2d.c
> +++ b/hw/sh4/r2d.c
> @@ -297,7 +297,7 @@ static void r2d_init(MachineState *machine)
>       * FLASH_SIZE / 4 bytes anyway.  The current code does so too, but
>       * whether it's the right size is anybody's guess.
>       */
> -    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE / 4,
> +    pflash_cfi02_register(0x0, "r2d.flash", FLASH_SIZE / 4,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            16 * KiB, FLASH_SIZE >> 16,
>                            1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 1078dc7238..464a72f11b 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -14,7 +14,7 @@
>  typedef struct PFlashCFI01 PFlashCFI01;
>  
>  PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,
> @@ -33,7 +33,7 @@ MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
>  typedef struct PFlashCFI02 PFlashCFI02;
>  
>  PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,
> 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-19 16:02   ` Philippe Mathieu-Daudé
@ 2019-02-19 16:21     ` Peter Maydell
  2019-02-19 17:53       ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Peter Maydell @ 2019-02-19 16:21 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Markus Armbruster, QEMU Developers, Kevin Wolf, Qemu-block,
	Laszlo Ersek, Magnus Damm, Max Reitz, qemu-ppc, Alex Bennée

On Tue, 19 Feb 2019 at 16:07, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> On 2/18/19 1:56 PM, Markus Armbruster wrote:
> Good news: when you read (0x0000, 0x0000, 0x0000, 0x0000) pflash IDs,
> that means the code uses the "Virt PFlash". IOW this is not a physical
> model, since the guest obviously doesn't care about checking the flash
> model.
> The "VirtPFlash" only has 64KiB sectors.
>
> I suggest we add a pflash_cfi02_create_virt(reduced args) helper to make
> this obvious:
>
>   pflash_cfi02_create_virt(paddr, name, size_bytes, mapping?).

What would this be, and when would you use it without a
/* FIXME this is not what the real hardware does */ ?

The real problem with most of these pflash creation calls
is that they're using bogus data for the flash device
(wrong IDs, wrong width, using the legacy weird implementation,
etc etc) because nobody cares much about the boards or has
real hardware to see what the hardware really is doing.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (17 preceding siblings ...)
  2019-02-19 13:53 ` no-reply
@ 2019-02-19 16:43 ` no-reply
  2019-02-27 15:26 ` no-reply
  2019-02-27 17:41 ` no-reply
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-19 16:43 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190218125615.18970-1-armbru@redhat.com -> patchew/20190218125615.18970-1-armbru@redhat.com
 t [tag update]            patchew/20190219114609.1582-1-berrange@redhat.com -> patchew/20190219114609.1582-1-berrange@redhat.com
Switched to a new branch 'test'
918b511857 hw/arm hw/xtensa: De-duplicate pflash creation code some
573a3cb6ee pflash: Clean up after commit 368a354f02b part 2
cd6c8874c9 pflash: Clean up after commit 368a354f02b part 1
47d6b05dbf mips_malta: Clean up definition of flash memory size somewhat
4d776997cb r2d: Flash memory creation is confused about size, mark FIXME
8ef649b622 ppc405_boards: Don't size flash memory to match backing image
05e5efce12 sam460ex: Don't size flash memory to match backing image
83454272f9 hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
e25489f667 pflash: Macro PFLASH_BUG() is used just once, expand
23cedcc198 pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit 23cedcc198b7 (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit e25489f66779 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 83454272f952 (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit 05e5efce1273 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit 8ef649b622cf (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 4d776997cb7d (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit 47d6b05dbf10 (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit cd6c8874c9f4 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#91: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#99: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 573a3cb6eeac (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 918b5118573b (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-19 15:53       ` Philippe Mathieu-Daudé
@ 2019-02-19 17:30         ` Markus Armbruster
  2019-03-04  4:57           ` Magnus Damm
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 17:30 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Kevin Wolf, Qemu-block, Laszlo Ersek, Magnus Damm,
	QEMU Developers, Max Reitz, qemu-ppc, Alex Bennée

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 2/19/19 4:45 PM, Markus Armbruster wrote:
>> Peter Maydell <peter.maydell@linaro.org> writes:
>> 
>>> On Mon, 18 Feb 2019 at 13:07, Markus Armbruster <armbru@redhat.com> wrote:
>>>>
>>>> pflash_cfi02_register() takes a size in bytes, a block size in bytes
>>>> and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
>>>> FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
>>>> number of blocks.  The latter happens to win.  I tried to find
>>>> documentation on the physcial hardware, no luck.
>
> "physical"

Thanks, will fix.

>>>>
>>>> For now, adjust the byte size passed to match the actual size created,
>>>> and add a FIXME comment.
>>>
>>> I'm pretty sure that FLASH_SIZE here is supposed to be a
>>> byte count of the size of the pflash. That matches what
>>> Linux has in arch/sh/boards/mach-r2d/setup.c where it
>>> sets up the flash_resource struct.
>> 
>> Okay, that's some evidence for size 0x02000000 (32MiB).
>> 
>> However, we've created size (16 * KiB) * (FLASH_SIZE >> 16), i.e. 8MiB,
>> since at least commit 368a354f02b (v1.3.0), possibly since forever.
>> 
>>> The r2dplus board is also I think known as RTS7751R2D. That
>>> takes us to https://elinux.org/RTS7751R2D_Handling_Manual
>>> (sadly the link to the "hardware manual" is broken).
>> 
>> Quote section Flash ROM Mapping:
>> 
>>     Currently, MTD device mapping on Flash ROM is set as below.
>>     0x00000000-0x00020000 	"bootloader" 	
>>     0x00020000-0x00320000 	"mtdblock1" 	XIP kernel
>>     0x00320000-0x00520000 	"mtdblock2" 	
>>     0x00520000-0x01000000 	"mtdblock3" 	
>> 
>> Suggests a size of 0x01000000 (16MiB).  Now we have three candidates.
>> 
>> Pick one, any one, and I'll adjust my patch.  All I really care about is
>> getting argument @size consistent with arguments @sector_len and
>> @nb_blocs, so I can ditch @nb_blocs in PATCH 09.
>> 
>>> No idea what the block size would be.
>> 
>> As long as that's the case, inertia wins by default.
>
> There is also a paper [*]:
>
>   The Renesas Technology R0P751RLC001RL (R2DPLUS) board was used
>   as our target device.
>   This board is often used to evaluate software for CE devices.
>   The specification is shown below.
>     CPU: SH7751R(SH4) 240Mhz
>     RAM: 64Mbyte
>     Compact flash: 512Mbyte
>     Flash ROM: 64Mbyte (32Mbyte available for root file system)

Candidate #4: 64MiB.  Bring 'em on!

>
> Let's use at least 16MB to be able to run the elinux cited kernel.
>
> [*] https://www.kernel.org/doc/ols/2008/ols2008v2-pages-125-134.pdf

That's a vote for changing the status quo (8 MiB).

Perhaps Magnus, who maintains the machine, can pick a new value for us.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-19 16:21     ` Peter Maydell
@ 2019-02-19 17:53       ` Markus Armbruster
  2019-02-19 18:11         ` Peter Maydell
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-19 17:53 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, Alex Bennée, Magnus Damm,
	QEMU Developers, qemu-ppc, Max Reitz, Laszlo Ersek

Peter Maydell <peter.maydell@linaro.org> writes:

> On Tue, 19 Feb 2019 at 16:07, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>
>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>> Good news: when you read (0x0000, 0x0000, 0x0000, 0x0000) pflash IDs,
>> that means the code uses the "Virt PFlash".

Which code?

>>                                             IOW this is not a physical
>> model, since the guest obviously doesn't care about checking the flash
>> model.
>> The "VirtPFlash" only has 64KiB sectors.
>>
>> I suggest we add a pflash_cfi02_create_virt(reduced args) helper to make
>> this obvious:
>>
>>   pflash_cfi02_create_virt(paddr, name, size_bytes, mapping?).
>
> What would this be, and when would you use it without a
> /* FIXME this is not what the real hardware does */ ?

For a purely virtual machine such as ARM virt, perhaps?

Funnily, we use IDs 0x89, 0x18, 0x00, 0x00 there.  Which first appeared
in the microblaze petalogix-s3adsp1800 machine (commit 2548de3a343, Jan
2010), then got copied to ppc virtex-ml507 (commit 2c50e26efdb, Sep
2010), microblaze petalogix-ml605 (commit 00914b7d970, Mar 2011), ppc
sam460ex (commit 4b387f9ee16, Feb 2018), arm vexpress-* in different
form (commit b8433303fbc and 0163a2dc80, Dec 2013), and finally arm virt
(commit acf82361c61, Sep 2014).  Which ones match physical hardware is
anybody's guess.

> The real problem with most of these pflash creation calls
> is that they're using bogus data for the flash device
> (wrong IDs, wrong width, using the legacy weird implementation,
> etc etc)

Even better news: when we replace the helper function by longhand, 
many of the (bogus) qdev_prop_set_FOO() become no-ops (because the
default is identically bogus), so we can sweep more of this under the
carpet!

>          because nobody cares much about the boards or has
> real hardware to see what the hardware really is doing.

Remind me, why are we shipping stuff nobody cares much about?

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-19 17:53       ` Markus Armbruster
@ 2019-02-19 18:11         ` Peter Maydell
  0 siblings, 0 replies; 97+ messages in thread
From: Peter Maydell @ 2019-02-19 18:11 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, Alex Bennée, Magnus Damm,
	QEMU Developers, qemu-ppc, Max Reitz, Laszlo Ersek

On Tue, 19 Feb 2019 at 17:53, Markus Armbruster <armbru@redhat.com> wrote:
>
> Peter Maydell <peter.maydell@linaro.org> writes:
> > What would this be, and when would you use it without a
> > /* FIXME this is not what the real hardware does */ ?
>
> For a purely virtual machine such as ARM virt, perhaps?
>
> Funnily, we use IDs 0x89, 0x18, 0x00, 0x00 there.

FWIW, this is "Manufacturer: Intel" and whatever device 0x18
is for Intel. IDs 2 and 3 are used by the pflash_cfi01 code
only if we're using the bogus backward-compatibility "act
like a bad emulation of two 16-bit devices making up a 32-bit
wide device", in which case they're the ID values for the
second of the two devices. (Or it might be that the ident
values then are "manuf-id manuf-id device-id device-id",
and with the not-bogus setup they're "manuf-id device-id
unused unused".)

I'm not sure whether the chips on any of these boards
really are Intel ones :-)

thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-19 14:33       ` Philippe Mathieu-Daudé
@ 2019-02-21  9:15         ` Markus Armbruster
  2019-02-21 16:41           ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-21  9:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Markus Armbruster, kwolf, qemu-block, alex.bennee, qemu-devel,
	mreitz, qemu-ppc, lersek

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 2/19/19 2:41 PM, Markus Armbruster wrote:
>> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>> 
>>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>>>> flash.h's incomplete struct pflash_t is completed both in
>>>> pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
>>>> incompatible.  This can hide type errors, such as passing a pflash_t
>>>> created with pflash_cfi02_register() to pflash_cfi01_get_memory().
>>>>
>>>> Furthermore, POSIX reserves typedef names ending with _t.
>
> Worth adding in CODING_STYLE 'Naming' section :)
>
>>>>
>>>> Rename the two structs to PFlashCFI01 and PFlashCFI02.
>>>
>>> Why not ParallelFlashCFIxx?
>> 
>> Feels a bit long, and we abbreviate to pflash pretty consistently.  That
>> said, I'm not particularly enamored with my choice of name :)
>> 
>>> Ideally ParallelFlashCFI would be an InterfaceInfo...
>> 
>> You mean TYPE_CFI_PFLASH0{1,2} should be children of an abstract parent?
>
> I'd use "TYPE_PFLASH_CFI0[12]".

That's a separate renaming patch.  It could go right before PATCH 03.
Worthwhile?

[...]

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-19 13:46       ` Markus Armbruster
@ 2019-02-21  9:22         ` Markus Armbruster
  2019-02-21  9:38           ` Peter Maydell
  2019-02-21 15:08           ` Alex Bennée
  0 siblings, 2 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-21  9:22 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc, Laszlo Ersek

Markus Armbruster <armbru@redhat.com> writes:

> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> On Tue, 19 Feb 2019 at 12:41, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>>
>>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>>> > PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
>>> > BUG", which sounds like a warning, then calls exit(1), followed by
>>> > unreachable goto reset_flash.  All this commit does is expanding the
>>> > macro, so the smell becomes more poignant, and the macro can be
>>> > deleted.
>>> >
>>> > Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> > ---
>>> >  hw/block/pflash_cfi01.c | 10 ++--------
>>> >  1 file changed, 2 insertions(+), 8 deletions(-)
>>> >
>>> > diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
>>> > index 9efa7aa9af..f73c30a3ee 100644
>>> > --- a/hw/block/pflash_cfi01.c
>>> > +++ b/hw/block/pflash_cfi01.c
>>> > @@ -49,12 +49,6 @@
>>> >  #include "sysemu/sysemu.h"
>>> >  #include "trace.h"
>>> >
>>> > -#define PFLASH_BUG(fmt, ...) \
>>> > -do { \
>>> > -    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
>>> > -    exit(1); \
>>> > -} while(0)
>>> > -
>>> >  /* #define PFLASH_DEBUG */
>>> >  #ifdef PFLASH_DEBUG
>>> >  #define DPRINTF(fmt, ...)                                   \
>>> > @@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>> >                  pfl->status |= 0x80;
>>> >              } else {
>>> >                  DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>>> > -                PFLASH_BUG("Write block confirm");
>>> > -                goto reset_flash;
>>> > +                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
>>> > +                exit(1);
>>>
>>> Don't you want to use hw_error here?
>>>
>>>       hw_error("PFLASH: Possible BUG - Write block confirm");
>>
>> This should just be
>>    qemu_log_mask(LOG_GUEST_ERROR, ...);
>> (replacing both the DPRINTF and the PFLASH_BUG()).
>>
>> It's triggerable by a guest (if it puts the device into write-block
>> mode and then feeds it a bogus command byte), so it's just a guest
>> error, not an issue with our model of the pflash.
>
> I can do that.  Thanks!

Double-checking... you want me to keep goto reset_flash, like this:

@@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
                 pfl->wcycle = 0;
                 pfl->status |= 0x80;
             } else {
-                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
-                PFLASH_BUG("Write block confirm");
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "unknown command for \"write block\"\n");
                 goto reset_flash;
             }
             break;

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21  9:22         ` Markus Armbruster
@ 2019-02-21  9:38           ` Peter Maydell
  2019-02-21 12:07             ` Laszlo Ersek
  2019-02-21 16:19             ` Philippe Mathieu-Daudé
  2019-02-21 15:08           ` Alex Bennée
  1 sibling, 2 replies; 97+ messages in thread
From: Peter Maydell @ 2019-02-21  9:38 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc, Laszlo Ersek

On Thu, 21 Feb 2019 at 09:22, Markus Armbruster <armbru@redhat.com> wrote:
> Double-checking... you want me to keep goto reset_flash, like this:
>
> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                  pfl->wcycle = 0;
>                  pfl->status |= 0x80;
>              } else {
> -                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
> -                PFLASH_BUG("Write block confirm");
> +                qemu_log_mask(LOG_GUEST_ERROR,
> +                              "unknown command for \"write block\"\n");
>                  goto reset_flash;
>              }
>              break;

Yes. (We seem to handle most kinds of guest errors in programming
the flash by reset_flash.)

thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21  9:38           ` Peter Maydell
@ 2019-02-21 12:07             ` Laszlo Ersek
  2019-02-21 12:38               ` Peter Maydell
  2019-02-21 16:19             ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-21 12:07 UTC (permalink / raw)
  To: Peter Maydell, Markus Armbruster
  Cc: Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc

somewhat off-topic:

On 02/21/19 10:38, Peter Maydell wrote:
> On Thu, 21 Feb 2019 at 09:22, Markus Armbruster <armbru@redhat.com> wrote:
>> Double-checking... you want me to keep goto reset_flash, like this:
>>
>> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>                  pfl->wcycle = 0;
>>                  pfl->status |= 0x80;
>>              } else {
>> -                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>> -                PFLASH_BUG("Write block confirm");
>> +                qemu_log_mask(LOG_GUEST_ERROR,
>> +                              "unknown command for \"write block\"\n");
>>                  goto reset_flash;
>>              }
>>              break;
> 
> Yes. (We seem to handle most kinds of guest errors in programming
> the flash by reset_flash.)

since we're talking "reset_flash", I'll note that there is no actual
reset handler for cfi.pflash01. I found out recently, via:

https://bugzilla.redhat.com/show_bug.cgi?id=1678713

Thanks
Laszlo

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21 12:07             ` Laszlo Ersek
@ 2019-02-21 12:38               ` Peter Maydell
  2019-02-21 12:46                 ` Laszlo Ersek
  0 siblings, 1 reply; 97+ messages in thread
From: Peter Maydell @ 2019-02-21 12:38 UTC (permalink / raw)
  To: Laszlo Ersek
  Cc: Markus Armbruster, Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc

On Thu, 21 Feb 2019 at 12:07, Laszlo Ersek <lersek@redhat.com> wrote:
> since we're talking "reset_flash", I'll note that there is no actual
> reset handler for cfi.pflash01. I found out recently, via:
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1678713

Yes; this isn't uncommon for some of the really old
device models. It should definitely have one added.

You are correct also that the timer in the pflash_cfi01
model is dead code -- it has always been so, since the
device was added in 2007. The reason it is there is that
pflash_cfi01 was created as a copy-and-hack of the
cfi02 device. In cfi02 we do use the timer, as a way
of simulating "make full-chip and sector erases take a
guest-visible amount of time rather than completing
instantaneously". cfi01 doesn't do that (and I think
may not implement anything other than block erase),
but the timer initialization code was left in rather
than being deleted as part of the copy-and-hack.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21 12:38               ` Peter Maydell
@ 2019-02-21 12:46                 ` Laszlo Ersek
  2019-02-21 16:39                   ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-21 12:46 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Markus Armbruster, Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc

On 02/21/19 13:38, Peter Maydell wrote:
> On Thu, 21 Feb 2019 at 12:07, Laszlo Ersek <lersek@redhat.com> wrote:
>> since we're talking "reset_flash", I'll note that there is no actual
>> reset handler for cfi.pflash01. I found out recently, via:
>>
>> https://bugzilla.redhat.com/show_bug.cgi?id=1678713
> 
> Yes; this isn't uncommon for some of the really old
> device models. It should definitely have one added.
> 
> You are correct also that the timer in the pflash_cfi01
> model is dead code -- it has always been so, since the
> device was added in 2007. The reason it is there is that
> pflash_cfi01 was created as a copy-and-hack of the
> cfi02 device. In cfi02 we do use the timer, as a way
> of simulating "make full-chip and sector erases take a
> guest-visible amount of time rather than completing
> instantaneously". cfi01 doesn't do that (and I think
> may not implement anything other than block erase),
> but the timer initialization code was left in rather
> than being deleted as part of the copy-and-hack.

Thank you, I've linked this back into the RHBZ.

Laszlo

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02 Markus Armbruster
  2019-02-18 16:40   ` Laszlo Ersek
  2019-02-19 12:49   ` Philippe Mathieu-Daudé
@ 2019-02-21 15:07   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 15:07 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, lersek, kwolf, mreitz, qemu-block, qemu-ppc


Markus Armbruster <armbru@redhat.com> writes:

> flash.h's incomplete struct pflash_t is completed both in
> pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
> incompatible.  This can hide type errors, such as passing a pflash_t
> created with pflash_cfi02_register() to pflash_cfi01_get_memory().
>
> Furthermore, POSIX reserves typedef names ending with _t.
>
> Rename the two structs to PFlashCFI01 and PFlashCFI02.

modulo whatever name you eventually settle on:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/vexpress.c        |  8 ++--
>  hw/block/pflash_cfi01.c  | 87 +++++++++++++++++++++-------------------
>  hw/block/pflash_cfi02.c  | 67 ++++++++++++++++---------------
>  hw/i386/pc_sysfw.c       |  2 +-
>  hw/mips/mips_malta.c     |  2 +-
>  hw/xtensa/xtfpga.c       | 10 ++---
>  include/hw/block/flash.h | 53 ++++++++++++++----------
>  7 files changed, 122 insertions(+), 107 deletions(-)
>
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index c02d18ee61..ed46d2e730 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -512,8 +512,8 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>  /* Open code a private version of pflash registration since we
>   * need to set non-default device width for VExpress platform.
>   */
> -static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
> -                                          DriveInfo *di)
> +static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
> +                                             DriveInfo *di)
>  {
>      DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
>
> @@ -536,7 +536,7 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
>      qdev_init_nofail(dev);
>
>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> -    return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
> +    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
>  }
>
>  static void vexpress_common_init(MachineState *machine)
> @@ -548,7 +548,7 @@ static void vexpress_common_init(MachineState *machine)
>      qemu_irq pic[64];
>      uint32_t sys_id;
>      DriveInfo *dinfo;
> -    pflash_t *pflash0;
> +    PFlashCFI01 *pflash0;
>      I2CBus *i2c;
>      ram_addr_t vram_size, sram_size;
>      MemoryRegion *sysmem = get_system_memory();
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index bffb4c40e7..9efa7aa9af 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -65,12 +65,13 @@ do {                                                        \
>  #define DPRINTF(fmt, ...) do { } while (0)
>  #endif
>
> -#define CFI_PFLASH01(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01)
> +#define CFI_PFLASH01(obj) \
> +    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
>
>  #define PFLASH_BE          0
>  #define PFLASH_SECURE      1
>
> -struct pflash_t {
> +struct PFlashCFI01 {
>      /*< private >*/
>      SysBusDevice parent_obj;
>      /*< public >*/
> @@ -109,17 +110,17 @@ static const VMStateDescription vmstate_pflash = {
>      .minimum_version_id = 1,
>      .post_load = pflash_post_load,
>      .fields = (VMStateField[]) {
> -        VMSTATE_UINT8(wcycle, pflash_t),
> -        VMSTATE_UINT8(cmd, pflash_t),
> -        VMSTATE_UINT8(status, pflash_t),
> -        VMSTATE_UINT64(counter, pflash_t),
> +        VMSTATE_UINT8(wcycle, PFlashCFI01),
> +        VMSTATE_UINT8(cmd, PFlashCFI01),
> +        VMSTATE_UINT8(status, PFlashCFI01),
> +        VMSTATE_UINT64(counter, PFlashCFI01),
>          VMSTATE_END_OF_LIST()
>      }
>  };
>
>  static void pflash_timer (void *opaque)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>
>      trace_pflash_timer_expired(pfl->cmd);
>      /* Reset flash */
> @@ -133,7 +134,7 @@ static void pflash_timer (void *opaque)
>   * If this code is called we know we have a device_width set for
>   * this flash.
>   */
> -static uint32_t pflash_cfi_query(pflash_t *pfl, hwaddr offset)
> +static uint32_t pflash_cfi_query(PFlashCFI01 *pfl, hwaddr offset)
>  {
>      int i;
>      uint32_t resp = 0;
> @@ -193,7 +194,7 @@ static uint32_t pflash_cfi_query(pflash_t *pfl, hwaddr offset)
>
>
>  /* Perform a device id query based on the bank width of the flash. */
> -static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)
> +static uint32_t pflash_devid_query(PFlashCFI01 *pfl, hwaddr offset)
>  {
>      int i;
>      uint32_t resp;
> @@ -241,7 +242,7 @@ static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)
>      return resp;
>  }
>
> -static uint32_t pflash_data_read(pflash_t *pfl, hwaddr offset,
> +static uint32_t pflash_data_read(PFlashCFI01 *pfl, hwaddr offset,
>                                   int width, int be)
>  {
>      uint8_t *p;
> @@ -284,7 +285,7 @@ static uint32_t pflash_data_read(pflash_t *pfl, hwaddr offset,
>      return ret;
>  }
>
> -static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
> +static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,
>                               int width, int be)
>  {
>      hwaddr boff;
> @@ -398,7 +399,7 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
>  }
>
>  /* update flash content on disk */
> -static void pflash_update(pflash_t *pfl, int offset,
> +static void pflash_update(PFlashCFI01 *pfl, int offset,
>                            int size)
>  {
>      int offset_end;
> @@ -412,7 +413,7 @@ static void pflash_update(pflash_t *pfl, int offset,
>      }
>  }
>
> -static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
> +static inline void pflash_data_write(PFlashCFI01 *pfl, hwaddr offset,
>                                       uint32_t value, int width, int be)
>  {
>      uint8_t *p = pfl->storage;
> @@ -448,7 +449,7 @@ static inline void pflash_data_write(pflash_t *pfl, hwaddr offset,
>
>  }
>
> -static void pflash_write(pflash_t *pfl, hwaddr offset,
> +static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                           uint32_t value, int width, int be)
>  {
>      uint8_t *p;
> @@ -654,7 +655,7 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,
>  static MemTxResult pflash_mem_read_with_attrs(void *opaque, hwaddr addr, uint64_t *value,
>                                                unsigned len, MemTxAttrs attrs)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>      bool be = !!(pfl->features & (1 << PFLASH_BE));
>
>      if ((pfl->features & (1 << PFLASH_SECURE)) && !attrs.secure) {
> @@ -668,7 +669,7 @@ static MemTxResult pflash_mem_read_with_attrs(void *opaque, hwaddr addr, uint64_
>  static MemTxResult pflash_mem_write_with_attrs(void *opaque, hwaddr addr, uint64_t value,
>                                                 unsigned len, MemTxAttrs attrs)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>      bool be = !!(pfl->features & (1 << PFLASH_BE));
>
>      if ((pfl->features & (1 << PFLASH_SECURE)) && !attrs.secure) {
> @@ -687,7 +688,7 @@ static const MemoryRegionOps pflash_cfi01_ops = {
>
>  static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
>  {
> -    pflash_t *pfl = CFI_PFLASH01(dev);
> +    PFlashCFI01 *pfl = CFI_PFLASH01(dev);
>      uint64_t total_len;
>      int ret;
>      uint64_t blocks_per_device, sector_len_per_device, device_len;
> @@ -864,14 +865,14 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
>  }
>
>  static Property pflash_cfi01_properties[] = {
> -    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
> +    DEFINE_PROP_DRIVE("drive", PFlashCFI01, blk),
>      /* num-blocks is the number of blocks actually visible to the guest,
>       * ie the total size of the device divided by the sector length.
>       * If we're emulating flash devices wired in parallel the actual
>       * number of blocks per indvidual device will differ.
>       */
> -    DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
> -    DEFINE_PROP_UINT64("sector-length", struct pflash_t, sector_len, 0),
> +    DEFINE_PROP_UINT32("num-blocks", PFlashCFI01, nb_blocs, 0),
> +    DEFINE_PROP_UINT64("sector-length", PFlashCFI01, sector_len, 0),
>      /* width here is the overall width of this QEMU device in bytes.
>       * The QEMU device may be emulating a number of flash devices
>       * wired up in parallel; the width of each individual flash
> @@ -888,17 +889,17 @@ static Property pflash_cfi01_properties[] = {
>       * 16 bit devices making up a 32 bit wide QEMU device. This
>       * is deprecated for new uses of this device.
>       */
> -    DEFINE_PROP_UINT8("width", struct pflash_t, bank_width, 0),
> -    DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0),
> -    DEFINE_PROP_UINT8("max-device-width", struct pflash_t, max_device_width, 0),
> -    DEFINE_PROP_BIT("big-endian", struct pflash_t, features, PFLASH_BE, 0),
> -    DEFINE_PROP_BIT("secure", struct pflash_t, features, PFLASH_SECURE, 0),
> -    DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0),
> -    DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
> -    DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
> -    DEFINE_PROP_UINT16("id3", struct pflash_t, ident3, 0),
> -    DEFINE_PROP_STRING("name", struct pflash_t, name),
> -    DEFINE_PROP_BOOL("old-multiple-chip-handling", struct pflash_t,
> +    DEFINE_PROP_UINT8("width", PFlashCFI01, bank_width, 0),
> +    DEFINE_PROP_UINT8("device-width", PFlashCFI01, device_width, 0),
> +    DEFINE_PROP_UINT8("max-device-width", PFlashCFI01, max_device_width, 0),
> +    DEFINE_PROP_BIT("big-endian", PFlashCFI01, features, PFLASH_BE, 0),
> +    DEFINE_PROP_BIT("secure", PFlashCFI01, features, PFLASH_SECURE, 0),
> +    DEFINE_PROP_UINT16("id0", PFlashCFI01, ident0, 0),
> +    DEFINE_PROP_UINT16("id1", PFlashCFI01, ident1, 0),
> +    DEFINE_PROP_UINT16("id2", PFlashCFI01, ident2, 0),
> +    DEFINE_PROP_UINT16("id3", PFlashCFI01, ident3, 0),
> +    DEFINE_PROP_STRING("name", PFlashCFI01, name),
> +    DEFINE_PROP_BOOL("old-multiple-chip-handling", PFlashCFI01,
>                       old_multiple_chip_handling, false),
>      DEFINE_PROP_END_OF_LIST(),
>  };
> @@ -917,7 +918,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data)
>  static const TypeInfo pflash_cfi01_info = {
>      .name           = TYPE_CFI_PFLASH01,
>      .parent         = TYPE_SYS_BUS_DEVICE,
> -    .instance_size  = sizeof(struct pflash_t),
> +    .instance_size  = sizeof(PFlashCFI01),
>      .class_init     = pflash_cfi01_class_init,
>  };
>
> @@ -928,13 +929,15 @@ static void pflash_cfi01_register_types(void)
>
>  type_init(pflash_cfi01_register_types)
>
> -pflash_t *pflash_cfi01_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk,
> -                                uint32_t sector_len, int nb_blocs,
> -                                int bank_width, uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3, int be)
> +PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int bank_width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   int be)
>  {
>      DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>
> @@ -956,14 +959,14 @@ pflash_t *pflash_cfi01_register(hwaddr base,
>      return CFI_PFLASH01(dev);
>  }
>
> -MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl)
> +MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl)
>  {
>      return &fl->mem;
>  }
>
>  static void postload_update_cb(void *opaque, int running, RunState state)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>
>      /* This is called after bdrv_invalidate_cache_all.  */
>      qemu_del_vm_change_state_handler(pfl->vmstate);
> @@ -975,7 +978,7 @@ static void postload_update_cb(void *opaque, int running, RunState state)
>
>  static int pflash_post_load(void *opaque, int version_id)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI01 *pfl = opaque;
>
>      if (!pfl->ro) {
>          pfl->vmstate = qemu_add_vm_change_state_handler(postload_update_cb,
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 0f8b7b8c7b..424cc106d6 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -57,9 +57,10 @@ do {                                                       \
>
>  #define PFLASH_LAZY_ROMD_THRESHOLD 42
>
> -#define CFI_PFLASH02(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH02)
> +#define CFI_PFLASH02(obj) \
> +    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
>
> -struct pflash_t {
> +struct PFlashCFI02 {
>      /*< private >*/
>      SysBusDevice parent_obj;
>      /*< public >*/
> @@ -101,7 +102,7 @@ struct pflash_t {
>  /*
>   * Set up replicated mappings of the same region.
>   */
> -static void pflash_setup_mappings(pflash_t *pfl)
> +static void pflash_setup_mappings(PFlashCFI02 *pfl)
>  {
>      unsigned i;
>      hwaddr size = memory_region_size(&pfl->orig_mem);
> @@ -115,7 +116,7 @@ static void pflash_setup_mappings(pflash_t *pfl)
>      }
>  }
>
> -static void pflash_register_memory(pflash_t *pfl, int rom_mode)
> +static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode)
>  {
>      memory_region_rom_device_set_romd(&pfl->orig_mem, rom_mode);
>      pfl->rom_mode = rom_mode;
> @@ -123,7 +124,7 @@ static void pflash_register_memory(pflash_t *pfl, int rom_mode)
>
>  static void pflash_timer (void *opaque)
>  {
> -    pflash_t *pfl = opaque;
> +    PFlashCFI02 *pfl = opaque;
>
>      trace_pflash_timer_expired(pfl->cmd);
>      /* Reset flash */
> @@ -137,7 +138,7 @@ static void pflash_timer (void *opaque)
>      pfl->cmd = 0;
>  }
>
> -static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
> +static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,
>                               int width, int be)
>  {
>      hwaddr boff;
> @@ -246,7 +247,7 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,
>  }
>
>  /* update flash content on disk */
> -static void pflash_update(pflash_t *pfl, int offset,
> +static void pflash_update(PFlashCFI02 *pfl, int offset,
>                            int size)
>  {
>      int offset_end;
> @@ -260,7 +261,7 @@ static void pflash_update(pflash_t *pfl, int offset,
>      }
>  }
>
> -static void pflash_write (pflash_t *pfl, hwaddr offset,
> +static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,
>                            uint32_t value, int width, int be)
>  {
>      hwaddr boff;
> @@ -533,7 +534,7 @@ static const MemoryRegionOps pflash_cfi02_ops_le = {
>
>  static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
>  {
> -    pflash_t *pfl = CFI_PFLASH02(dev);
> +    PFlashCFI02 *pfl = CFI_PFLASH02(dev);
>      uint32_t chip_len;
>      int ret;
>      Error *local_err = NULL;
> @@ -679,19 +680,19 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
>  }
>
>  static Property pflash_cfi02_properties[] = {
> -    DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
> -    DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
> -    DEFINE_PROP_UINT32("sector-length", struct pflash_t, sector_len, 0),
> -    DEFINE_PROP_UINT8("width", struct pflash_t, width, 0),
> -    DEFINE_PROP_UINT8("mappings", struct pflash_t, mappings, 0),
> -    DEFINE_PROP_UINT8("big-endian", struct pflash_t, be, 0),
> -    DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0),
> -    DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0),
> -    DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
> -    DEFINE_PROP_UINT16("id3", struct pflash_t, ident3, 0),
> -    DEFINE_PROP_UINT16("unlock-addr0", struct pflash_t, unlock_addr0, 0),
> -    DEFINE_PROP_UINT16("unlock-addr1", struct pflash_t, unlock_addr1, 0),
> -    DEFINE_PROP_STRING("name", struct pflash_t, name),
> +    DEFINE_PROP_DRIVE("drive", PFlashCFI02, blk),
> +    DEFINE_PROP_UINT32("num-blocks", PFlashCFI02, nb_blocs, 0),
> +    DEFINE_PROP_UINT32("sector-length", PFlashCFI02, sector_len, 0),
> +    DEFINE_PROP_UINT8("width", PFlashCFI02, width, 0),
> +    DEFINE_PROP_UINT8("mappings", PFlashCFI02, mappings, 0),
> +    DEFINE_PROP_UINT8("big-endian", PFlashCFI02, be, 0),
> +    DEFINE_PROP_UINT16("id0", PFlashCFI02, ident0, 0),
> +    DEFINE_PROP_UINT16("id1", PFlashCFI02, ident1, 0),
> +    DEFINE_PROP_UINT16("id2", PFlashCFI02, ident2, 0),
> +    DEFINE_PROP_UINT16("id3", PFlashCFI02, ident3, 0),
> +    DEFINE_PROP_UINT16("unlock-addr0", PFlashCFI02, unlock_addr0, 0),
> +    DEFINE_PROP_UINT16("unlock-addr1", PFlashCFI02, unlock_addr1, 0),
> +    DEFINE_PROP_STRING("name", PFlashCFI02, name),
>      DEFINE_PROP_END_OF_LIST(),
>  };
>
> @@ -707,7 +708,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data)
>  static const TypeInfo pflash_cfi02_info = {
>      .name           = TYPE_CFI_PFLASH02,
>      .parent         = TYPE_SYS_BUS_DEVICE,
> -    .instance_size  = sizeof(struct pflash_t),
> +    .instance_size  = sizeof(PFlashCFI02),
>      .class_init     = pflash_cfi02_class_init,
>  };
>
> @@ -718,15 +719,17 @@ static void pflash_cfi02_register_types(void)
>
>  type_init(pflash_cfi02_register_types)
>
> -pflash_t *pflash_cfi02_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk, uint32_t sector_len,
> -                                int nb_blocs, int nb_mappings, int width,
> -                                uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3,
> -                                uint16_t unlock_addr0, uint16_t unlock_addr1,
> -                                int be)
> +PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int nb_mappings, int width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   uint16_t unlock_addr0,
> +                                   uint16_t unlock_addr1,
> +                                   int be)
>  {
>      DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH02);
>
> diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> index 091e22dd60..67e55342f6 100644
> --- a/hw/i386/pc_sysfw.c
> +++ b/hw/i386/pc_sysfw.c
> @@ -111,7 +111,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
>      char *fatal_errmsg = NULL;
>      hwaddr phys_addr = 0x100000000ULL;
>      int sector_bits, sector_size;
> -    pflash_t *system_flash;
> +    PFlashCFI01 *system_flash;
>      MemoryRegion *flash_mem;
>      char name[64];
>      void *flash_ptr;
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index 74667766c2..fff5ed19bd 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -1189,7 +1189,7 @@ void mips_malta_init(MachineState *machine)
>      const char *kernel_cmdline = machine->kernel_cmdline;
>      const char *initrd_filename = machine->initrd_filename;
>      char *filename;
> -    pflash_t *fl;
> +    PFlashCFI01 *fl;
>      MemoryRegion *system_memory = get_system_memory();
>      MemoryRegion *ram_high = g_new(MemoryRegion, 1);
>      MemoryRegion *ram_low_preio = g_new(MemoryRegion, 1);
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index ab3e52b415..3d59a7a356 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -162,9 +162,9 @@ static void xtfpga_net_init(MemoryRegion *address_space,
>      memory_region_add_subregion(address_space, buffers, ram);
>  }
>
> -static pflash_t *xtfpga_flash_init(MemoryRegion *address_space,
> -                                   const XtfpgaBoardDesc *board,
> -                                   DriveInfo *dinfo, int be)
> +static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
> +                                      const XtfpgaBoardDesc *board,
> +                                      DriveInfo *dinfo, int be)
>  {
>      SysBusDevice *s;
>      DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> @@ -181,7 +181,7 @@ static pflash_t *xtfpga_flash_init(MemoryRegion *address_space,
>      s = SYS_BUS_DEVICE(dev);
>      memory_region_add_subregion(address_space, board->flash->base,
>                                  sysbus_mmio_get_region(s, 0));
> -    return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
> +    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
>  }
>
>  static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
> @@ -229,7 +229,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
>      XtensaMxPic *mx_pic = NULL;
>      qemu_irq *extints;
>      DriveInfo *dinfo;
> -    pflash_t *flash = NULL;
> +    PFlashCFI01 *flash = NULL;
>      QemuOpts *machine_opts = qemu_get_machine_opts();
>      const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
>      const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 67c3aa329e..51d8f60c65 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -5,32 +5,41 @@
>
>  #include "exec/memory.h"
>
> -#define TYPE_CFI_PFLASH01 "cfi.pflash01"
> -#define TYPE_CFI_PFLASH02 "cfi.pflash02"
> -
> -typedef struct pflash_t pflash_t;
> -
>  /* pflash_cfi01.c */
> -pflash_t *pflash_cfi01_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk,
> -                                uint32_t sector_len, int nb_blocs, int width,
> -                                uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3, int be);
> +
> +#define TYPE_CFI_PFLASH01 "cfi.pflash01"
> +
> +typedef struct PFlashCFI01 PFlashCFI01;
> +
> +PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   int be);
> +MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
>
>  /* pflash_cfi02.c */
> -pflash_t *pflash_cfi02_register(hwaddr base,
> -                                DeviceState *qdev, const char *name,
> -                                hwaddr size,
> -                                BlockBackend *blk, uint32_t sector_len,
> -                                int nb_blocs, int nb_mappings, int width,
> -                                uint16_t id0, uint16_t id1,
> -                                uint16_t id2, uint16_t id3,
> -                                uint16_t unlock_addr0, uint16_t unlock_addr1,
> -                                int be);
>
> -MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl);
> +#define TYPE_CFI_PFLASH02 "cfi.pflash02"
> +
> +typedef struct PFlashCFI02 PFlashCFI02;
> +
> +PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> +                                   DeviceState *qdev, const char *name,
> +                                   hwaddr size,
> +                                   BlockBackend *blk,
> +                                   uint32_t sector_len, int nb_blocs,
> +                                   int nb_mappings,
> +                                   int width,
> +                                   uint16_t id0, uint16_t id1,
> +                                   uint16_t id2, uint16_t id3,
> +                                   uint16_t unlock_addr0,
> +                                   uint16_t unlock_addr1,
> +                                   int be);
>
>  /* nand.c */
>  DeviceState *nand_init(BlockBackend *blk, int manf_id, int chip_id);


--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21  9:22         ` Markus Armbruster
  2019-02-21  9:38           ` Peter Maydell
@ 2019-02-21 15:08           ` Alex Bennée
  1 sibling, 0 replies; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 15:08 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Peter Maydell, Philippe Mathieu-Daudé,
	Kevin Wolf, Qemu-block, QEMU Developers, Max Reitz, qemu-ppc,
	Laszlo Ersek


Markus Armbruster <armbru@redhat.com> writes:

> Markus Armbruster <armbru@redhat.com> writes:
>
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>
>>> On Tue, 19 Feb 2019 at 12:41, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>>>
>>>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>>>> > PFLASH_BUG()'s lone use has a suspicious smell: it prints "Possible
>>>> > BUG", which sounds like a warning, then calls exit(1), followed by
>>>> > unreachable goto reset_flash.  All this commit does is expanding the
>>>> > macro, so the smell becomes more poignant, and the macro can be
>>>> > deleted.
>>>> >
>>>> > Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>> > ---
>>>> >  hw/block/pflash_cfi01.c | 10 ++--------
>>>> >  1 file changed, 2 insertions(+), 8 deletions(-)
>>>> >
>>>> > diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
>>>> > index 9efa7aa9af..f73c30a3ee 100644
>>>> > --- a/hw/block/pflash_cfi01.c
>>>> > +++ b/hw/block/pflash_cfi01.c
>>>> > @@ -49,12 +49,6 @@
>>>> >  #include "sysemu/sysemu.h"
>>>> >  #include "trace.h"
>>>> >
>>>> > -#define PFLASH_BUG(fmt, ...) \
>>>> > -do { \
>>>> > -    fprintf(stderr, "PFLASH: Possible BUG - " fmt, ## __VA_ARGS__); \
>>>> > -    exit(1); \
>>>> > -} while(0)
>>>> > -
>>>> >  /* #define PFLASH_DEBUG */
>>>> >  #ifdef PFLASH_DEBUG
>>>> >  #define DPRINTF(fmt, ...)                                   \
>>>> > @@ -624,8 +618,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>>> >                  pfl->status |= 0x80;
>>>> >              } else {
>>>> >                  DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>>>> > -                PFLASH_BUG("Write block confirm");
>>>> > -                goto reset_flash;
>>>> > +                fprintf(stderr, "PFLASH: Possible BUG - Write block confirm");
>>>> > +                exit(1);
>>>>
>>>> Don't you want to use hw_error here?
>>>>
>>>>       hw_error("PFLASH: Possible BUG - Write block confirm");
>>>
>>> This should just be
>>>    qemu_log_mask(LOG_GUEST_ERROR, ...);
>>> (replacing both the DPRINTF and the PFLASH_BUG()).
>>>
>>> It's triggerable by a guest (if it puts the device into write-block
>>> mode and then feeds it a bogus command byte), so it's just a guest
>>> error, not an issue with our model of the pflash.
>>
>> I can do that.  Thanks!
>
> Double-checking... you want me to keep goto reset_flash, like this:
>
> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                  pfl->wcycle = 0;
>                  pfl->status |= 0x80;
>              } else {
> -                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
> -                PFLASH_BUG("Write block confirm");
> +                qemu_log_mask(LOG_GUEST_ERROR,
> +                              "unknown command for \"write block\"\n");
>                  goto reset_flash;
>              }
>              break;

With this change:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2} Markus Armbruster
  2019-02-18 16:45   ` Laszlo Ersek
  2019-02-19 12:41   ` Philippe Mathieu-Daudé
@ 2019-02-21 15:09   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 15:09 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, lersek, kwolf, mreitz, qemu-block, qemu-ppc


Markus Armbruster <armbru@redhat.com> writes:

> We have two open-coded copies of macro CFI_PFLASH01().  Move the macro
> to the header, so we can ditch the copies.  Move CFI_PFLASH02() to the
> header for symmetry.
>
> We define macros TYPE_CFI_PFLASH01 and TYPE_CFI_PFLASH02 for type name
> strings, then mostly use the strings.  If the macros are worth
> defining, they are worth using.  Replace the strings by the macros.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  hw/arm/vexpress.c        | 4 ++--
>  hw/arm/virt.c            | 3 ++-
>  hw/block/pflash_cfi01.c  | 3 ---
>  hw/block/pflash_cfi02.c  | 3 ---
>  hw/xtensa/xtfpga.c       | 4 ++--
>  include/hw/block/flash.h | 4 ++++
>  6 files changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index ed46d2e730..00913f2655 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -515,7 +515,7 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
>  static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>                                               DriveInfo *di)
>  {
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>
>      if (di) {
>          qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di),
> @@ -536,7 +536,7 @@ static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name,
>      qdev_init_nofail(dev);
>
>      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> -    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
> +    return CFI_PFLASH01(dev);
>  }
>
>  static void vexpress_common_init(MachineState *machine)
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 99c2b6e60d..b7d53b2b87 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -34,6 +34,7 @@
>  #include "hw/arm/arm.h"
>  #include "hw/arm/primecell.h"
>  #include "hw/arm/virt.h"
> +#include "hw/block/flash.h"
>  #include "hw/vfio/vfio-calxeda-xgmac.h"
>  #include "hw/vfio/vfio-amd-xgbe.h"
>  #include "hw/display/ramfb.h"
> @@ -874,7 +875,7 @@ static void create_one_flash(const char *name, hwaddr flashbase,
>       * parameters as the flash devices on the Versatile Express board.
>       */
>      DriveInfo *dinfo = drive_get_next(IF_PFLASH);
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
>      const uint64_t sectorlength = 256 * 1024;
>
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index f73c30a3ee..43dbb7db26 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -59,9 +59,6 @@ do {                                                        \
>  #define DPRINTF(fmt, ...) do { } while (0)
>  #endif
>
> -#define CFI_PFLASH01(obj) \
> -    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
> -
>  #define PFLASH_BE          0
>  #define PFLASH_SECURE      1
>
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 424cc106d6..e9c76d6cfb 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -57,9 +57,6 @@ do {                                                       \
>
>  #define PFLASH_LAZY_ROMD_THRESHOLD 42
>
> -#define CFI_PFLASH02(obj) \
> -    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
> -
>  struct PFlashCFI02 {
>      /*< private >*/
>      SysBusDevice parent_obj;
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index 3d59a7a356..a726d5632a 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -167,7 +167,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
>                                        DriveInfo *dinfo, int be)
>  {
>      SysBusDevice *s;
> -    DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
> +    DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01);
>
>      qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
>                          &error_abort);
> @@ -181,7 +181,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
>      s = SYS_BUS_DEVICE(dev);
>      memory_region_add_subregion(address_space, board->flash->base,
>                                  sysbus_mmio_get_region(s, 0));
> -    return OBJECT_CHECK(PFlashCFI01, (dev), "cfi.pflash01");
> +    return CFI_PFLASH01(dev);
>  }
>
>  static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 51d8f60c65..1078dc7238 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -8,6 +8,8 @@
>  /* pflash_cfi01.c */
>
>  #define TYPE_CFI_PFLASH01 "cfi.pflash01"
> +#define CFI_PFLASH01(obj) \
> +    OBJECT_CHECK(PFlashCFI01, (obj), TYPE_CFI_PFLASH01)
>
>  typedef struct PFlashCFI01 PFlashCFI01;
>
> @@ -25,6 +27,8 @@ MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
>  /* pflash_cfi02.c */
>
>  #define TYPE_CFI_PFLASH02 "cfi.pflash02"
> +#define CFI_PFLASH02(obj) \
> +    OBJECT_CHECK(PFlashCFI02, (obj), TYPE_CFI_PFLASH02)
>
>  typedef struct PFlashCFI02 PFlashCFI02;


--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 05/10] ppc405_boards: " Markus Armbruster
  2019-02-19  3:55   ` David Gibson
  2019-02-19 15:28   ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
@ 2019-02-21 15:20   ` Alex Bennée
  2019-02-21 16:31     ` Markus Armbruster
  2 siblings, 1 reply; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 15:20 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, lersek, kwolf, mreitz, qemu-block, qemu-ppc, David Gibson


Markus Armbruster <armbru@redhat.com> writes:

> Machine "ref405ep" maps its flash memory at address 2^32 - image size.
> Image size is rounded up to the next multiple of 64KiB.  Useless,
> because pflash_cfi02_realize() fails with "failed to read the initial
> flash content" unless the rounding is a no-op.
>
> If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
> other stuff.  No idea how that would play out, but a useful outcomes
> seem unlikely.
>
> Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
> regardless of image size, to match the physical hardware.
>
> Machine "taihu" maps its boot flash memory similarly.  The code even
> has a comment /* XXX: should check that size is 2MB */, followed by
> disabled code to adjust the size to 2MiB regardless of image size.
>
> Its code to map its application flash memory looks the same, except
> there the XXX comment asks for 32MiB, and the code to adjust the size
> isn't disabled.  Note that pflash_cfi02_realize() fails with "failed
> to read the initial flash content" for images smaller than 32MiB.
>
> Map the boot flash memory at fixed address 0xFFE00000 with size 2MiB,
> to match the physical hardware.  Delete dead code from application
> flash mapping, and simplify some.
>
> Cc: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ppc/ppc405_boards.c | 53 +++++++++++++-----------------------------
>  1 file changed, 16 insertions(+), 37 deletions(-)
>
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index f47b15f10e..728154aebb 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -158,7 +158,7 @@ static void ref405ep_init(MachineState *machine)
>      target_ulong kernel_base, initrd_base;
>      long kernel_size, initrd_size;
>      int linux_boot;
> -    int fl_idx, fl_sectors, len;
> +    int len;
>      DriveInfo *dinfo;
>      MemoryRegion *sysmem = get_system_memory();
>
> @@ -185,26 +185,19 @@ static void ref405ep_init(MachineState *machine)
>  #ifdef DEBUG_BOARD_INIT
>      printf("%s: register BIOS\n", __func__);
>  #endif
> -    fl_idx = 0;
>  #ifdef USE_FLASH_BIOS
> -    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
> +    dinfo = drive_get(IF_PFLASH, 0, 0);
>      if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        fl_sectors = (bios_size + 65535) >> 16;
>  #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr %lx '%s' %d\n",
> -               fl_idx, bios_size, -bios_size,
> -               blk_name(blk), fl_sectors);
> +        printf("Register parallel flash\n");
>  #endif
> -        pflash_cfi02_register((uint32_t)(-bios_size),
> +        bios_size = 0x80000;

 bios_size = 8 * MiB?

> +        pflash_cfi02_register(0xFFF80000,
>                                NULL, "ef405ep.bios", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,

64 * KiB?

>                                2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
> -        fl_idx++;
>      } else
>  #endif
>      {
> @@ -455,7 +448,7 @@ static void taihu_405ep_init(MachineState *machine)
>      target_ulong kernel_base, initrd_base;
>      long kernel_size, initrd_size;
>      int linux_boot;
> -    int fl_idx, fl_sectors;
> +    int fl_idx;
>      DriveInfo *dinfo;
>
>      /* RAM is soldered to the board so the size cannot be changed */
> @@ -486,21 +479,14 @@ static void taihu_405ep_init(MachineState *machine)
>  #if defined(USE_FLASH_BIOS)
>      dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>      if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        /* XXX: should check that size is 2MB */
> -        //        bios_size = 2 * 1024 * 1024;
> -        fl_sectors = (bios_size + 65535) >> 16;
>  #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr %lx '%s' %d\n",
> -               fl_idx, bios_size, -bios_size,
> -               blk_name(blk), fl_sectors);
> +        printf("Register boot flash\n");
>  #endif
> -        pflash_cfi02_register((uint32_t)(-bios_size),
> +        bios_size = 2 * MiB;
> +        pflash_cfi02_register(0xFFE00000,
>                                NULL, "taihu_405ep.bios", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,

64 * KiB

>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
>          fl_idx++;
> @@ -536,20 +522,13 @@ static void taihu_405ep_init(MachineState *machine)
>      /* Register Linux flash */
>      dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>      if (dinfo) {
> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> -
> -        bios_size = blk_getlength(blk);
> -        /* XXX: should check that size is 32MB */
>          bios_size = 32 * MiB;
> -        fl_sectors = (bios_size + 65535) >> 16;
>  #ifdef DEBUG_BOARD_INIT
> -        printf("Register parallel flash %d size %lx"
> -               " at addr " TARGET_FMT_lx " '%s'\n",
> -               fl_idx, bios_size, (target_ulong)0xfc000000,
> -               blk_name(blk));
> +        printf("Register application flash\n"
>  #endif
>          pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
> -                              blk, 65536, fl_sectors, 1,
> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> +                              65536, bios_size / 65536, 1,

64 * KiB

>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
>          fl_idx++;


--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat Markus Armbruster
  2019-02-19 13:02   ` Philippe Mathieu-Daudé
@ 2019-02-21 15:27   ` Alex Bennée
  1 sibling, 0 replies; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 15:27 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, lersek, kwolf, mreitz, qemu-block, qemu-ppc,
	Aurelien Jarno, Aleksandar Rikalo


Markus Armbruster <armbru@redhat.com> writes:

> pflash_cfi01_register() takes a size in bytes, a block size in bytes
> and a number of blocks.  mips_malta_init() passes BIOS_SIZE, 65536,
> FLASH_SIZE >> 16.  Actually consistent only because BIOS_SIZE (defined
> in include/hw/mips/bios.h as (4 * MiB)) matches FLASH_SIZE (defined
> locally as 0x400000).  Confusing all the same.
>
> Pass FLASH_SIZE instead of BIOS_SIZE.
>
> There are more uses of BIOS_SIZE, but I don't sufficiently understand
> them to attempt cleanup.
>
> Cc: Aurelien Jarno <aurelien@aurel32.net>
> Cc: Aleksandar Rikalo <arikalo@wavecomp.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  hw/mips/mips_malta.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index fff5ed19bd..65cdda4881 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -1269,12 +1269,12 @@ void mips_malta_init(MachineState *machine)
>      if (dinfo) {
>          printf("Register parallel flash %d size " TARGET_FMT_lx " at "
>                 "addr %08llx '%s' %x\n",
> -               fl_idx, bios_size, FLASH_ADDRESS,
> +               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
>                 blk_name(dinfo->bdrv), fl_sectors);
>      }
>  #endif
>      fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
> -                               BIOS_SIZE,
> +                               FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 65536, fl_sectors,
>                                 4, 0x0000, 0x0000, 0x0000, 0x0000, be);


--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1 Markus Armbruster
  2019-02-18 16:50   ` Laszlo Ersek
  2019-02-19 16:12   ` Philippe Mathieu-Daudé
@ 2019-02-21 15:57   ` Alex Bennée
  2 siblings, 0 replies; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 15:57 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, lersek, kwolf, mreitz, qemu-block, qemu-ppc


Markus Armbruster <armbru@redhat.com> writes:

> QOMification left parameter @qdev unused in pflash_cfi01_register()
> and pflash_cfi02_register().  All callers pass NULL.  Remove.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  hw/arm/collie.c                          | 4 ++--
>  hw/arm/digic_boards.c                    | 2 +-
>  hw/arm/gumstix.c                         | 4 ++--
>  hw/arm/mainstone.c                       | 2 +-
>  hw/arm/musicpal.c                        | 4 ++--
>  hw/arm/omap_sx1.c                        | 4 ++--
>  hw/arm/versatilepb.c                     | 2 +-
>  hw/arm/xilinx_zynq.c                     | 2 +-
>  hw/arm/z2.c                              | 3 +--
>  hw/block/pflash_cfi01.c                  | 2 +-
>  hw/block/pflash_cfi02.c                  | 2 +-
>  hw/i386/pc_sysfw.c                       | 2 +-
>  hw/lm32/lm32_boards.c                    | 4 ++--
>  hw/lm32/milkymist.c                      | 2 +-
>  hw/microblaze/petalogix_ml605_mmu.c      | 3 +--
>  hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
>  hw/mips/mips_malta.c                     | 2 +-
>  hw/mips/mips_r4k.c                       | 2 +-
>  hw/ppc/ppc405_boards.c                   | 6 +++---
>  hw/ppc/sam460ex.c                        | 2 +-
>  hw/ppc/virtex_ml507.c                    | 2 +-
>  hw/sh4/r2d.c                             | 2 +-
>  include/hw/block/flash.h                 | 4 ++--
>  23 files changed, 31 insertions(+), 33 deletions(-)
>
> diff --git a/hw/arm/collie.c b/hw/arm/collie.c
> index 48b732c176..cbc4400f8e 100644
> --- a/hw/arm/collie.c
> +++ b/hw/arm/collie.c
> @@ -36,12 +36,12 @@ static void collie_init(MachineState *machine)
>      s = sa1110_init(sysmem, collie_binfo.ram_size, machine->cpu_type);
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
> -    pflash_cfi01_register(SA_CS0, NULL, "collie.fl1", 0x02000000,
> +    pflash_cfi01_register(SA_CS0, "collie.fl1", 0x02000000,
>                      dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                      (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
>
>      dinfo = drive_get(IF_PFLASH, 0, 1);
> -    pflash_cfi01_register(SA_CS1, NULL, "collie.fl2", 0x02000000,
> +    pflash_cfi01_register(SA_CS1, "collie.fl2", 0x02000000,
>                      dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                      (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
>
> diff --git a/hw/arm/digic_boards.c b/hw/arm/digic_boards.c
> index 9f11dcd11f..15a00a1be3 100644
> --- a/hw/arm/digic_boards.c
> +++ b/hw/arm/digic_boards.c
> @@ -129,7 +129,7 @@ static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
>  #define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
>  #define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
>
> -    pflash_cfi02_register(addr, NULL, "pflash", FLASH_K8P3215UQB_SIZE,
> +    pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE,
>                            NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
>                            FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE,
>                            DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
> diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c
> index 56cb763c4e..304dbeab2f 100644
> --- a/hw/arm/gumstix.c
> +++ b/hw/arm/gumstix.c
> @@ -72,7 +72,7 @@ static void connex_init(MachineState *machine)
>  #else
>      be = 0;
>  #endif
> -    if (!pflash_cfi01_register(0x00000000, NULL, "connext.rom", connex_rom,
> +    if (!pflash_cfi01_register(0x00000000, "connext.rom", connex_rom,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 sector_len, connex_rom / sector_len,
>                                 2, 0, 0, 0, 0, be)) {
> @@ -109,7 +109,7 @@ static void verdex_init(MachineState *machine)
>  #else
>      be = 0;
>  #endif
> -    if (!pflash_cfi01_register(0x00000000, NULL, "verdex.rom", verdex_rom,
> +    if (!pflash_cfi01_register(0x00000000, "verdex.rom", verdex_rom,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 sector_len, verdex_rom / sector_len,
>                                 2, 0, 0, 0, 0, be)) {
> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
> index 0beb5c426b..2a1c1072db 100644
> --- a/hw/arm/mainstone.c
> +++ b/hw/arm/mainstone.c
> @@ -148,7 +148,7 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
>              exit(1);
>          }
>
> -        if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
> +        if (!pflash_cfi01_register(mainstone_flash_base[i],
>                                     i ? "mainstone.flash1" : "mainstone.flash0",
>                                     MAINSTONE_FLASH,
>                                     blk_by_legacy_dinfo(dinfo),
> diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
> index d22532a11c..ecca0e6f64 100644
> --- a/hw/arm/musicpal.c
> +++ b/hw/arm/musicpal.c
> @@ -1636,14 +1636,14 @@ static void musicpal_init(MachineState *machine)
>           * image is smaller than 32 MB.
>           */
>  #ifdef TARGET_WORDS_BIGENDIAN
> -        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
> +        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
>                                "musicpal.flash", flash_size,
>                                blk, 0x10000, (flash_size + 0xffff) >> 16,
>                                MP_FLASH_SIZE_MAX / flash_size,
>                                2, 0x00BF, 0x236D, 0x0000, 0x0000,
>                                0x5555, 0x2AAA, 1);
>  #else
> -        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX, NULL,
> +        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
>                                "musicpal.flash", flash_size,
>                                blk, 0x10000, (flash_size + 0xffff) >> 16,
>                                MP_FLASH_SIZE_MAX / flash_size,
> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
> index 84550f0236..b1128777cf 100644
> --- a/hw/arm/omap_sx1.c
> +++ b/hw/arm/omap_sx1.c
> @@ -152,7 +152,7 @@ static void sx1_init(MachineState *machine, const int version)
>  #endif
>
>      if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
> -        if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
> +        if (!pflash_cfi01_register(OMAP_CS0_BASE,
>                                     "omap_sx1.flash0-1", flash_size,
>                                     blk_by_legacy_dinfo(dinfo),
>                                     sector_size, flash_size / sector_size,
> @@ -176,7 +176,7 @@ static void sx1_init(MachineState *machine, const int version)
>          memory_region_add_subregion(address_space,
>                                  OMAP_CS1_BASE + flash1_size, &cs[1]);
>
> -        if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
> +        if (!pflash_cfi01_register(OMAP_CS1_BASE,
>                                     "omap_sx1.flash1-1", flash1_size,
>                                     blk_by_legacy_dinfo(dinfo),
>                                     sector_size, flash1_size / sector_size,
> diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
> index 22b09a1e61..82c5277462 100644
> --- a/hw/arm/versatilepb.c
> +++ b/hw/arm/versatilepb.c
> @@ -365,7 +365,7 @@ static void versatile_init(MachineState *machine, int board_id)
>      /* 0x34000000 NOR Flash */
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
> -    if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, NULL, "versatile.flash",
> +    if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, "versatile.flash",
>                            VERSATILE_FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            VERSATILE_FLASH_SECT_SIZE,
> diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
> index 57497b0c4d..1fa4a77728 100644
> --- a/hw/arm/xilinx_zynq.c
> +++ b/hw/arm/xilinx_zynq.c
> @@ -205,7 +205,7 @@ static void zynq_init(MachineState *machine)
>      DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0);
>
>      /* AMD */
> -    pflash_cfi02_register(0xe2000000, NULL, "zynq.pflash", FLASH_SIZE,
> +    pflash_cfi02_register(0xe2000000, "zynq.pflash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            FLASH_SECTOR_SIZE,
>                            FLASH_SIZE/FLASH_SECTOR_SIZE, 1,
> diff --git a/hw/arm/z2.c b/hw/arm/z2.c
> index 697a822f1e..54e6caee9f 100644
> --- a/hw/arm/z2.c
> +++ b/hw/arm/z2.c
> @@ -324,8 +324,7 @@ static void z2_init(MachineState *machine)
>          exit(1);
>      }
>
> -    if (!pflash_cfi01_register(Z2_FLASH_BASE,
> -                               NULL, "z2.flash0", Z2_FLASH_SIZE,
> +    if (!pflash_cfi01_register(Z2_FLASH_BASE, "z2.flash0", Z2_FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 sector_len, Z2_FLASH_SIZE / sector_len,
>                                 4, 0, 0, 0, 0, be)) {
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 43dbb7db26..f2a4b16a34 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -921,7 +921,7 @@ static void pflash_cfi01_register_types(void)
>  type_init(pflash_cfi01_register_types)
>
>  PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index e9c76d6cfb..73491aafe6 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -717,7 +717,7 @@ static void pflash_cfi02_register_types(void)
>  type_init(pflash_cfi02_register_types)
>
>  PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,
> diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> index 67e55342f6..9a5be54a85 100644
> --- a/hw/i386/pc_sysfw.c
> +++ b/hw/i386/pc_sysfw.c
> @@ -160,7 +160,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
>
>          /* pflash_cfi01_register() creates a deep copy of the name */
>          snprintf(name, sizeof name, "system.flash%d", unit);
> -        system_flash = pflash_cfi01_register(phys_addr, NULL /* qdev */, name,
> +        system_flash = pflash_cfi01_register(phys_addr, name,
>                                               size, blk, sector_size,
>                                               size >> sector_bits,
>                                               1      /* width */,
> diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
> index 05157f8eab..f726355309 100644
> --- a/hw/lm32/lm32_boards.c
> +++ b/hw/lm32/lm32_boards.c
> @@ -114,7 +114,7 @@ static void lm32_evr_init(MachineState *machine)
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* Spansion S29NS128P */
> -    pflash_cfi02_register(flash_base, NULL, "lm32_evr.flash", flash_size,
> +    pflash_cfi02_register(flash_base, "lm32_evr.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            flash_sector_size, flash_size / flash_sector_size,
>                            1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
> @@ -207,7 +207,7 @@ static void lm32_uclinux_init(MachineState *machine)
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* Spansion S29NS128P */
> -    pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
> +    pflash_cfi02_register(flash_base, "lm32_uclinux.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            flash_sector_size, flash_size / flash_sector_size,
>                            1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
> diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
> index b080cf1ca9..ece7e3b699 100644
> --- a/hw/lm32/milkymist.c
> +++ b/hw/lm32/milkymist.c
> @@ -121,7 +121,7 @@ milkymist_init(MachineState *machine)
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* Numonyx JS28F256J3F105 */
> -    pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
> +    pflash_cfi01_register(flash_base, "milkymist.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            flash_sector_size, flash_size / flash_sector_size,
>                            2, 0x00, 0x89, 0x00, 0x1d, 1);
> diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c
> index c730878d25..74bcc14cda 100644
> --- a/hw/microblaze/petalogix_ml605_mmu.c
> +++ b/hw/microblaze/petalogix_ml605_mmu.c
> @@ -107,8 +107,7 @@ petalogix_ml605_init(MachineState *machine)
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      /* 5th parameter 2 means bank-width
>       * 10th paremeter 0 means little-endian */
> -    pflash_cfi01_register(FLASH_BASEADDR,
> -                          NULL, "petalogix_ml605.flash", FLASH_SIZE,
> +    pflash_cfi01_register(FLASH_BASEADDR, "petalogix_ml605.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            64 * KiB, FLASH_SIZE >> 16,
>                            2, 0x89, 0x18, 0x0000, 0x0, 0);
> diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c
> index b9f0b0d06e..a07b7f8edf 100644
> --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
> +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
> @@ -88,7 +88,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      pflash_cfi01_register(FLASH_BASEADDR,
> -                          NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE,
> +                          "petalogix_s3adsp1800.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            64 * KiB, FLASH_SIZE >> 16,
>                            1, 0x89, 0x18, 0x0000, 0x0, 1);
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index 65cdda4881..76b81b7402 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -1273,7 +1273,7 @@ void mips_malta_init(MachineState *machine)
>                 blk_name(dinfo->bdrv), fl_sectors);
>      }
>  #endif
> -    fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
> +    fl = pflash_cfi01_register(FLASH_ADDRESS, "mips_malta.bios",
>                                 FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 65536, fl_sectors,
> diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
> index a015a6d14e..0b9df466e7 100644
> --- a/hw/mips/mips_r4k.c
> +++ b/hw/mips/mips_r4k.c
> @@ -235,7 +235,7 @@ void mips_r4k_init(MachineState *machine)
>          load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
>      } else if ((dinfo = drive_get(IF_PFLASH, 0, 0)) != NULL) {
>          uint32_t mips_rom = 0x00400000;
> -        if (!pflash_cfi01_register(0x1fc00000, NULL, "mips_r4k.bios", mips_rom,
> +        if (!pflash_cfi01_register(0x1fc00000, "mips_r4k.bios", mips_rom,
>                                     blk_by_legacy_dinfo(dinfo),
>                                     sector_len, mips_rom / sector_len,
>                                     4, 0, 0, 0, 0, be)) {
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index 728154aebb..a54627903d 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -193,7 +193,7 @@ static void ref405ep_init(MachineState *machine)
>  #endif
>          bios_size = 0x80000;
>          pflash_cfi02_register(0xFFF80000,
> -                              NULL, "ef405ep.bios", bios_size,
> +                              "ef405ep.bios", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                65536, bios_size / 65536, 1,
>                                2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
> @@ -484,7 +484,7 @@ static void taihu_405ep_init(MachineState *machine)
>  #endif
>          bios_size = 2 * MiB;
>          pflash_cfi02_register(0xFFE00000,
> -                              NULL, "taihu_405ep.bios", bios_size,
> +                              "taihu_405ep.bios", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                65536, bios_size / 65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
> @@ -526,7 +526,7 @@ static void taihu_405ep_init(MachineState *machine)
>  #ifdef DEBUG_BOARD_INIT
>          printf("Register application flash\n"
>  #endif
> -        pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
> +        pflash_cfi02_register(0xfc000000, "taihu_405ep.flash", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                65536, bios_size / 65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
> index ca8d7ab9c6..a989a8c439 100644
> --- a/hw/ppc/sam460ex.c
> +++ b/hw/ppc/sam460ex.c
> @@ -95,7 +95,7 @@ static int sam460ex_load_uboot(void)
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
> -                               NULL, "sam460ex.flash", FLASH_SIZE,
> +                               "sam460ex.flash", FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                                 65536, FLASH_SIZE / 65536,
>                                 1, 0x89, 0x18, 0x0000, 0x0, 1)) {
> diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> index 5a711cb3d9..d2085a839c 100644
> --- a/hw/ppc/virtex_ml507.c
> +++ b/hw/ppc/virtex_ml507.c
> @@ -227,7 +227,7 @@ static void virtex_init(MachineState *machine)
>      memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
>
>      dinfo = drive_get(IF_PFLASH, 0, 0);
> -    pflash_cfi01_register(PFLASH_BASEADDR, NULL, "virtex.flash", FLASH_SIZE,
> +    pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            64 * KiB, FLASH_SIZE >> 16,
>                            1, 0x89, 0x18, 0x0000, 0x0, 1);
> diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
> index ed18d1f351..abd3b67c28 100644
> --- a/hw/sh4/r2d.c
> +++ b/hw/sh4/r2d.c
> @@ -297,7 +297,7 @@ static void r2d_init(MachineState *machine)
>       * FLASH_SIZE / 4 bytes anyway.  The current code does so too, but
>       * whether it's the right size is anybody's guess.
>       */
> -    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE / 4,
> +    pflash_cfi02_register(0x0, "r2d.flash", FLASH_SIZE / 4,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            16 * KiB, FLASH_SIZE >> 16,
>                            1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 1078dc7238..464a72f11b 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -14,7 +14,7 @@
>  typedef struct PFlashCFI01 PFlashCFI01;
>
>  PFlashCFI01 *pflash_cfi01_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,
> @@ -33,7 +33,7 @@ MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
>  typedef struct PFlashCFI02 PFlashCFI02;
>
>  PFlashCFI02 *pflash_cfi02_register(hwaddr base,
> -                                   DeviceState *qdev, const char *name,
> +                                   const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
>                                     uint32_t sector_len, int nb_blocs,


--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21  9:38           ` Peter Maydell
  2019-02-21 12:07             ` Laszlo Ersek
@ 2019-02-21 16:19             ` Philippe Mathieu-Daudé
  2019-02-21 17:03               ` Markus Armbruster
  2019-02-22  7:17               ` Markus Armbruster
  1 sibling, 2 replies; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-21 16:19 UTC (permalink / raw)
  To: Peter Maydell, Markus Armbruster, Laszlo Ersek
  Cc: Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc

On 2/21/19 10:38 AM, Peter Maydell wrote:
> On Thu, 21 Feb 2019 at 09:22, Markus Armbruster <armbru@redhat.com> wrote:
>> Double-checking... you want me to keep goto reset_flash, like this:
>>
>> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>                  pfl->wcycle = 0;
>>                  pfl->status |= 0x80;
>>              } else {
>> -                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>> -                PFLASH_BUG("Write block confirm");
>> +                qemu_log_mask(LOG_GUEST_ERROR,
>> +                              "unknown command for \"write block\"\n");
>>                  goto reset_flash;
>>              }
>>              break;
> 
> Yes. (We seem to handle most kinds of guest errors in programming
> the flash by reset_flash.)

Oh I missed the context of the patch here.

So for the case of the Multi-WRITE command (0xe8):

1/ On first write cycle we have

  - address = flash_page_address (we store it in pfl->counter)
  - data = flash_command (0xe8: enter Multi-WRITE)

2/ Second cycle:

  - address = flash_page_address
    We should check it matches flash_page_address
    of cycle 1/, but we don't.
  - data: N

    "N is the number of elements (bytes / words / double words),
    minus one, to be written to the write buffer. Expected count
    ranges are N = 00h to N = 7Fh (e.g., 1 to 128 bytes) in 8-bit
    mode, N = 00h to N = 003Fh in 16-bit mode, and N = 00h to
    N = 1Fh in 32-bit mode. Bus cycles 3 and higher are for writing
    data into the write buffer. The confirm command (D0h) is
    expected after exactly N + 1 write cycles; any other command at
    that point in the sequence will prevent the transfer of the
    buffer to the array (the write will be aborted)."

    Instead of starting to write the data in a buffer, we write it
    directly to the block backend.
    Instead of starting to write from cycle 3+, we write now in 2,
    and keep cycle count == 2 (pfl->wcycle) until all data is
    written, where we increment at 3.

3/ Cycles 3+

  - address = word index (relative to the page address)
  - data = word value

    We check for the CONFIRM command, and switch the device back
    to READ mode (setting Status), or reset the device (which is
    modelled the same way).

    Very silly: If the guest cancelled and never sent the CONFIRM
    command, the data is already written/flushed back.

So back to the previous code snippet, regardless the value, this
is neither a hw_error() nor a GUEST_ERROR. This code is simply not
correct. Eventually the proper (polite) error message should be:

    qemu_log_mask(LOG_UNIMP, "MULTI_WRITE: Abort not implemented,"
                             " the data is already written"
                             " on storage!\n"
                             "Nevertheless resetting the flash"
                             " into READ mode.\n");

Regards,

Phil.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-21 15:20   ` [Qemu-devel] " Alex Bennée
@ 2019-02-21 16:31     ` Markus Armbruster
  2019-02-21 22:18       ` David Gibson
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-21 16:31 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, qemu-block, qemu-devel, mreitz, qemu-ppc, lersek, David Gibson

Alex Bennée <alex.bennee@linaro.org> writes:

> Markus Armbruster <armbru@redhat.com> writes:
>
>> Machine "ref405ep" maps its flash memory at address 2^32 - image size.
>> Image size is rounded up to the next multiple of 64KiB.  Useless,
>> because pflash_cfi02_realize() fails with "failed to read the initial
>> flash content" unless the rounding is a no-op.
>>
>> If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
>> other stuff.  No idea how that would play out, but a useful outcomes
>> seem unlikely.
>>
>> Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
>> regardless of image size, to match the physical hardware.
>>
>> Machine "taihu" maps its boot flash memory similarly.  The code even
>> has a comment /* XXX: should check that size is 2MB */, followed by
>> disabled code to adjust the size to 2MiB regardless of image size.
>>
>> Its code to map its application flash memory looks the same, except
>> there the XXX comment asks for 32MiB, and the code to adjust the size
>> isn't disabled.  Note that pflash_cfi02_realize() fails with "failed
>> to read the initial flash content" for images smaller than 32MiB.
>>
>> Map the boot flash memory at fixed address 0xFFE00000 with size 2MiB,
>> to match the physical hardware.  Delete dead code from application
>> flash mapping, and simplify some.
>>
>> Cc: David Gibson <david@gibson.dropbear.id.au>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ppc/ppc405_boards.c | 53 +++++++++++++-----------------------------
>>  1 file changed, 16 insertions(+), 37 deletions(-)
>>
>> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
>> index f47b15f10e..728154aebb 100644
>> --- a/hw/ppc/ppc405_boards.c
>> +++ b/hw/ppc/ppc405_boards.c
>> @@ -158,7 +158,7 @@ static void ref405ep_init(MachineState *machine)
>>      target_ulong kernel_base, initrd_base;
>>      long kernel_size, initrd_size;
>>      int linux_boot;
>> -    int fl_idx, fl_sectors, len;
>> +    int len;
>>      DriveInfo *dinfo;
>>      MemoryRegion *sysmem = get_system_memory();
>>
>> @@ -185,26 +185,19 @@ static void ref405ep_init(MachineState *machine)
>>  #ifdef DEBUG_BOARD_INIT
>>      printf("%s: register BIOS\n", __func__);
>>  #endif
>> -    fl_idx = 0;
>>  #ifdef USE_FLASH_BIOS
>> -    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>> +    dinfo = drive_get(IF_PFLASH, 0, 0);
>>      if (dinfo) {
>> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
>> -
>> -        bios_size = blk_getlength(blk);
>> -        fl_sectors = (bios_size + 65535) >> 16;
>>  #ifdef DEBUG_BOARD_INIT
>> -        printf("Register parallel flash %d size %lx"
>> -               " at addr %lx '%s' %d\n",
>> -               fl_idx, bios_size, -bios_size,
>> -               blk_name(blk), fl_sectors);
>> +        printf("Register parallel flash\n");
>>  #endif
>> -        pflash_cfi02_register((uint32_t)(-bios_size),
>> +        bios_size = 0x80000;
>
>  bios_size = 8 * MiB?

The next line has base address 0xFFF80000.  I picked 0x80000 to make
0xFFF80000 + 0x80000 == 0 mod 2^32 more obvious.

If I change 0x80000 to 8 * MiB, the size is more obvious, but "at end of
32 bit address space" less so.

If I additionally change the base address back to ((uint32_t)-bios_size,
"at end of 32 bit address space" is obvious again, but the actual base
address less so.

I don't really care myself.  David, you're the maintainer, do you have a
preference?

>> +        pflash_cfi02_register(0xFFF80000,
>>                                NULL, "ef405ep.bios", bios_size,
>> -                              blk, 65536, fl_sectors, 1,
>> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>> +                              65536, bios_size / 65536, 1,
>
> 64 * KiB?

David, same question (two additional instances below).

>>                                2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>>                                1);
>> -        fl_idx++;
>>      } else
>>  #endif
>>      {
>> @@ -455,7 +448,7 @@ static void taihu_405ep_init(MachineState *machine)
>>      target_ulong kernel_base, initrd_base;
>>      long kernel_size, initrd_size;
>>      int linux_boot;
>> -    int fl_idx, fl_sectors;
>> +    int fl_idx;
>>      DriveInfo *dinfo;
>>
>>      /* RAM is soldered to the board so the size cannot be changed */
>> @@ -486,21 +479,14 @@ static void taihu_405ep_init(MachineState *machine)
>>  #if defined(USE_FLASH_BIOS)
>>      dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>>      if (dinfo) {
>> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
>> -
>> -        bios_size = blk_getlength(blk);
>> -        /* XXX: should check that size is 2MB */
>> -        //        bios_size = 2 * 1024 * 1024;
>> -        fl_sectors = (bios_size + 65535) >> 16;
>>  #ifdef DEBUG_BOARD_INIT
>> -        printf("Register parallel flash %d size %lx"
>> -               " at addr %lx '%s' %d\n",
>> -               fl_idx, bios_size, -bios_size,
>> -               blk_name(blk), fl_sectors);
>> +        printf("Register boot flash\n");
>>  #endif
>> -        pflash_cfi02_register((uint32_t)(-bios_size),
>> +        bios_size = 2 * MiB;
>> +        pflash_cfi02_register(0xFFE00000,
>>                                NULL, "taihu_405ep.bios", bios_size,
>> -                              blk, 65536, fl_sectors, 1,
>> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>> +                              65536, bios_size / 65536, 1,
>
> 64 * KiB
>
>>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>>                                1);
>>          fl_idx++;
>> @@ -536,20 +522,13 @@ static void taihu_405ep_init(MachineState *machine)
>>      /* Register Linux flash */
>>      dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>>      if (dinfo) {
>> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
>> -
>> -        bios_size = blk_getlength(blk);
>> -        /* XXX: should check that size is 32MB */
>>          bios_size = 32 * MiB;
>> -        fl_sectors = (bios_size + 65535) >> 16;
>>  #ifdef DEBUG_BOARD_INIT
>> -        printf("Register parallel flash %d size %lx"
>> -               " at addr " TARGET_FMT_lx " '%s'\n",
>> -               fl_idx, bios_size, (target_ulong)0xfc000000,
>> -               blk_name(blk));
>> +        printf("Register application flash\n"
>>  #endif
>>          pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
>> -                              blk, 65536, fl_sectors, 1,
>> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>> +                              65536, bios_size / 65536, 1,
>
> 64 * KiB
>
>>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>>                                1);
>>          fl_idx++;
>
>
> --
> Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21 12:46                 ` Laszlo Ersek
@ 2019-02-21 16:39                   ` Philippe Mathieu-Daudé
  2019-02-21 16:55                     ` Laszlo Ersek
  0 siblings, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-21 16:39 UTC (permalink / raw)
  To: Laszlo Ersek, Peter Maydell, Markus Armbruster
  Cc: Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc, Stefano Garzarella

On 2/21/19 1:46 PM, Laszlo Ersek wrote:
> On 02/21/19 13:38, Peter Maydell wrote:
>> On Thu, 21 Feb 2019 at 12:07, Laszlo Ersek <lersek@redhat.com> wrote:
>>> since we're talking "reset_flash", I'll note that there is no actual
>>> reset handler for cfi.pflash01. I found out recently, via:
>>>
>>> https://bugzilla.redhat.com/show_bug.cgi?id=1678713
>>
>> Yes; this isn't uncommon for some of the really old
>> device models. It should definitely have one added.
>>
>> You are correct also that the timer in the pflash_cfi01
>> model is dead code -- it has always been so, since the
>> device was added in 2007. The reason it is there is that
>> pflash_cfi01 was created as a copy-and-hack of the
>> cfi02 device. In cfi02 we do use the timer, as a way
>> of simulating "make full-chip and sector erases take a
>> guest-visible amount of time rather than completing
>> instantaneously". cfi01 doesn't do that (and I think
>> may not implement anything other than block erase),

This time is flash-device specific and is currently hardcoded.

The guest learn from the CFI table how long it should wait
before polling/accessing the flash, or take measures in case
of timeout.

We set these values in _realize():

    ...
    /* Typical timeout for block erase (512 ms) */
    pfl->cfi_table[0x21] = 0x09;
    /* Typical timeout for full chip erase (4096 ms) */
    pfl->cfi_table[0x22] = 0x0C;
    ...
    /* Max timeout for block erase */
    pfl->cfi_table[0x25] = 0x0A;
    /* Max timeout for chip erase */
    pfl->cfi_table[0x26] = 0x0D;

The timer is triggered in _write(), where we use other hardcoded
values (which are luckily in range with the CFI announced ones):

        /* Let's wait 5 seconds before chip erase is done */
        timer_mod(pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
                  (NANOSECONDS_PER_SECOND * 5));

        /* Let's wait 1/2 second before sector erase is done */
        timer_mod(pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
                  (NANOSECONDS_PER_SECOND / 2));

When emulating embedded devices, it is very desirable to have those
timers working, and I'd prefer we fix that on CFI01 rather than simply
removing the unused timer.

Now for the case of "Virt" machines, it is probably pointless to add
flash delay and we should remove the timer use.

>> but the timer initialization code was left in rather
>> than being deleted as part of the copy-and-hack.
> 
> Thank you, I've linked this back into the RHBZ.
> 
> Laszlo
> 

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02
  2019-02-21  9:15         ` Markus Armbruster
@ 2019-02-21 16:41           ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-02-21 16:41 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, qemu-block, alex.bennee, qemu-devel, mreitz, qemu-ppc, lersek

On 2/21/19 10:15 AM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> 
>> On 2/19/19 2:41 PM, Markus Armbruster wrote:
>>> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>>>
>>>> On 2/18/19 1:56 PM, Markus Armbruster wrote:
>>>>> flash.h's incomplete struct pflash_t is completed both in
>>>>> pflash_cfi01.c and in pflash_cfi02.c.  The complete types are
>>>>> incompatible.  This can hide type errors, such as passing a pflash_t
>>>>> created with pflash_cfi02_register() to pflash_cfi01_get_memory().
>>>>>
>>>>> Furthermore, POSIX reserves typedef names ending with _t.
>>
>> Worth adding in CODING_STYLE 'Naming' section :)
>>
>>>>>
>>>>> Rename the two structs to PFlashCFI01 and PFlashCFI02.
>>>>
>>>> Why not ParallelFlashCFIxx?
>>>
>>> Feels a bit long, and we abbreviate to pflash pretty consistently.  That
>>> said, I'm not particularly enamored with my choice of name :)
>>>
>>>> Ideally ParallelFlashCFI would be an InterfaceInfo...
>>>
>>> You mean TYPE_CFI_PFLASH0{1,2} should be children of an abstract parent?
>>
>> I'd use "TYPE_PFLASH_CFI0[12]".
> 
> That's a separate renaming patch.  It could go right before PATCH 03.
> Worthwhile?

Definitively not the more important issue with this device =)

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-18 12:56 ` [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2 Markus Armbruster
  2019-02-18 17:01   ` Laszlo Ersek
@ 2019-02-21 16:51   ` Alex Bennée
  2019-02-21 17:18     ` Markus Armbruster
  1 sibling, 1 reply; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 16:51 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, lersek, kwolf, mreitz, qemu-block, qemu-ppc


Markus Armbruster <armbru@redhat.com> writes:

> QOMification left parameter @size unused in pflash_cfi01_register()
> and pflash_cfi02_register().  register().  Obviously, @size should
> match @sector_len and @nb_blocs, i.e. size == sector_len * nb_blocs.
> All callers satisfy this.
>
> Remove @nb_blocs and compute it from @size and @sector_len.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/arm/collie.c                          | 5 +++--
>  hw/arm/digic_boards.c                    | 1 -
>  hw/arm/gumstix.c                         | 4 ++--
>  hw/arm/mainstone.c                       | 2 +-
>  hw/arm/musicpal.c                        | 4 ++--
>  hw/arm/omap_sx1.c                        | 4 ++--
>  hw/arm/versatilepb.c                     | 1 -
>  hw/arm/xilinx_zynq.c                     | 3 +--
>  hw/arm/z2.c                              | 2 +-
>  hw/block/pflash_cfi01.c                  | 5 +++--
>  hw/block/pflash_cfi02.c                  | 5 +++--
>  hw/i386/pc_sysfw.c                       | 6 +-----
>  hw/lm32/lm32_boards.c                    | 4 ++--
>  hw/lm32/milkymist.c                      | 2 +-
>  hw/microblaze/petalogix_ml605_mmu.c      | 2 +-
>  hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +-
>  hw/mips/mips_malta.c                     | 7 +++----
>  hw/mips/mips_r4k.c                       | 2 +-
>  hw/ppc/ppc405_boards.c                   | 6 +++---
>  hw/ppc/sam460ex.c                        | 2 +-
>  hw/ppc/virtex_ml507.c                    | 2 +-
>  hw/sh4/r2d.c                             | 2 +-
>  include/hw/block/flash.h                 | 4 ++--
>  23 files changed, 36 insertions(+), 41 deletions(-)
>
> diff --git a/hw/arm/collie.c b/hw/arm/collie.c
> index cbc4400f8e..7c9c0615f0 100644
> --- a/hw/arm/collie.c
> +++ b/hw/arm/collie.c
> @@ -9,6 +9,7 @@
>   * GNU GPL, version 2 or (at your option) any later version.
>   */
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "hw/hw.h"
>  #include "hw/sysbus.h"
>  #include "hw/boards.h"
> @@ -38,12 +39,12 @@ static void collie_init(MachineState *machine)
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      pflash_cfi01_register(SA_CS0, "collie.fl1", 0x02000000,
>                      dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                    (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
> +                    64 * KiB, 4, 0x00, 0x00, 0x00, 0x00, 0);
>
>      dinfo = drive_get(IF_PFLASH, 0, 1);
>      pflash_cfi01_register(SA_CS1, "collie.fl2", 0x02000000,
>                      dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                    (64 * 1024), 512, 4, 0x00, 0x00, 0x00, 0x00, 0);
> +                    64 * KiB, 4, 0x00, 0x00, 0x00, 0x00, 0);
>
>      sysbus_create_simple("scoop", 0x40800000, NULL);
>
> diff --git a/hw/arm/digic_boards.c b/hw/arm/digic_boards.c
> index 15a00a1be3..304e4d1a29 100644
> --- a/hw/arm/digic_boards.c
> +++ b/hw/arm/digic_boards.c
> @@ -131,7 +131,6 @@ static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
>
>      pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE,
>                            NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
> -                          FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE,
>                            DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
>                            4,
>                            0x00EC, 0x007E, 0x0003, 0x0001,
> diff --git a/hw/arm/gumstix.c b/hw/arm/gumstix.c
> index 304dbeab2f..2e526218f4 100644
> --- a/hw/arm/gumstix.c
> +++ b/hw/arm/gumstix.c
> @@ -74,7 +74,7 @@ static void connex_init(MachineState *machine)
>  #endif
>      if (!pflash_cfi01_register(0x00000000, "connext.rom", connex_rom,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                               sector_len, connex_rom / sector_len,
> +                               sector_len,
>                                 2, 0, 0, 0, 0, be)) {
>          error_report("Error registering flash memory");
>          exit(1);
> @@ -111,7 +111,7 @@ static void verdex_init(MachineState *machine)
>  #endif
>      if (!pflash_cfi01_register(0x00000000, "verdex.rom", verdex_rom,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                               sector_len, verdex_rom / sector_len,
> +                               sector_len,
>                                 2, 0, 0, 0, 0, be)) {
>          error_report("Error registering flash memory");
>          exit(1);
> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
> index 2a1c1072db..6e15ba9663 100644
> --- a/hw/arm/mainstone.c
> +++ b/hw/arm/mainstone.c
> @@ -152,7 +152,7 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
>                                     i ? "mainstone.flash1" : "mainstone.flash0",
>                                     MAINSTONE_FLASH,
>                                     blk_by_legacy_dinfo(dinfo),
> -                                   sector_len, MAINSTONE_FLASH / sector_len,
> +                                   sector_len,
>                                     4, 0, 0, 0, 0, be)) {
>              error_report("Error registering flash memory");
>              exit(1);
> diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
> index ecca0e6f64..fb3f5146f3 100644
> --- a/hw/arm/musicpal.c
> +++ b/hw/arm/musicpal.c
> @@ -1638,14 +1638,14 @@ static void musicpal_init(MachineState *machine)
>  #ifdef TARGET_WORDS_BIGENDIAN
>          pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
>                                "musicpal.flash", flash_size,
> -                              blk, 0x10000, (flash_size + 0xffff) >> 16,
> +                              blk, 0x10000,
>                                MP_FLASH_SIZE_MAX / flash_size,
>                                2, 0x00BF, 0x236D, 0x0000, 0x0000,
>                                0x5555, 0x2AAA, 1);
>  #else
>          pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
>                                "musicpal.flash", flash_size,
> -                              blk, 0x10000, (flash_size + 0xffff) >> 16,
> +                              blk, 0x10000,
>                                MP_FLASH_SIZE_MAX / flash_size,
>                                2, 0x00BF, 0x236D, 0x0000, 0x0000,
>                                0x5555, 0x2AAA, 0);
> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
> index b1128777cf..b269a5e1c2 100644
> --- a/hw/arm/omap_sx1.c
> +++ b/hw/arm/omap_sx1.c
> @@ -155,7 +155,7 @@ static void sx1_init(MachineState *machine, const int version)
>          if (!pflash_cfi01_register(OMAP_CS0_BASE,
>                                     "omap_sx1.flash0-1", flash_size,
>                                     blk_by_legacy_dinfo(dinfo),
> -                                   sector_size, flash_size / sector_size,
> +                                   sector_size,
>                                     4, 0, 0, 0, 0, be)) {
>              fprintf(stderr, "qemu: Error registering flash memory %d.\n",
>                             fl_idx);
> @@ -179,7 +179,7 @@ static void sx1_init(MachineState *machine, const int version)
>          if (!pflash_cfi01_register(OMAP_CS1_BASE,
>                                     "omap_sx1.flash1-1", flash1_size,
>                                     blk_by_legacy_dinfo(dinfo),
> -                                   sector_size, flash1_size / sector_size,
> +                                   sector_size,
>                                     4, 0, 0, 0, 0, be)) {
>              fprintf(stderr, "qemu: Error registering flash memory %d.\n",
>                             fl_idx);
> diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
> index 82c5277462..d67181810a 100644
> --- a/hw/arm/versatilepb.c
> +++ b/hw/arm/versatilepb.c
> @@ -369,7 +369,6 @@ static void versatile_init(MachineState *machine, int board_id)
>                            VERSATILE_FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>                            VERSATILE_FLASH_SECT_SIZE,
> -                          VERSATILE_FLASH_SIZE / VERSATILE_FLASH_SECT_SIZE,
>                            4, 0x0089, 0x0018, 0x0000, 0x0, 0)) {
>          fprintf(stderr, "qemu: Error registering flash memory.\n");
>      }
> diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
> index 1fa4a77728..f36cfcfd4a 100644
> --- a/hw/arm/xilinx_zynq.c
> +++ b/hw/arm/xilinx_zynq.c
> @@ -207,8 +207,7 @@ static void zynq_init(MachineState *machine)
>      /* AMD */
>      pflash_cfi02_register(0xe2000000, "zynq.pflash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          FLASH_SECTOR_SIZE,
> -                          FLASH_SIZE/FLASH_SECTOR_SIZE, 1,
> +                          FLASH_SECTOR_SIZE, 1,
>                            1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa,
>                                0);
>
> diff --git a/hw/arm/z2.c b/hw/arm/z2.c
> index 54e6caee9f..fb073ec2f5 100644
> --- a/hw/arm/z2.c
> +++ b/hw/arm/z2.c
> @@ -326,7 +326,7 @@ static void z2_init(MachineState *machine)
>
>      if (!pflash_cfi01_register(Z2_FLASH_BASE, "z2.flash0", Z2_FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                               sector_len, Z2_FLASH_SIZE / sector_len,
> +                               sector_len,
>                                 4, 0, 0, 0, 0, be)) {
>          error_report("Error registering flash memory");
>          exit(1);
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index f2a4b16a34..2e161f937f 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -924,7 +924,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
>                                     const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
> -                                   uint32_t sector_len, int nb_blocs,
> +                                   uint32_t sector_len,
>                                     int bank_width,
>                                     uint16_t id0, uint16_t id1,
>                                     uint16_t id2, uint16_t id3,
> @@ -935,7 +935,8 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
>      if (blk) {
>          qdev_prop_set_drive(dev, "drive", blk, &error_abort);
>      }
> -    qdev_prop_set_uint32(dev, "num-blocks", nb_blocs);
> +    assert(size % sector_len == 0);
> +    qdev_prop_set_uint32(dev, "num-blocks", size / sector_len);
>      qdev_prop_set_uint64(dev, "sector-length", sector_len);
>      qdev_prop_set_uint8(dev, "width", bank_width);
>      qdev_prop_set_bit(dev, "big-endian", !!be);
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 73491aafe6..414b5ab074 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -720,7 +720,7 @@ PFlashCFI02 *pflash_cfi02_register(hwaddr base,
>                                     const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
> -                                   uint32_t sector_len, int nb_blocs,
> +                                   uint32_t sector_len,
>                                     int nb_mappings, int width,
>                                     uint16_t id0, uint16_t id1,
>                                     uint16_t id2, uint16_t id3,
> @@ -733,7 +733,8 @@ PFlashCFI02 *pflash_cfi02_register(hwaddr base,
>      if (blk) {
>          qdev_prop_set_drive(dev, "drive", blk, &error_abort);
>      }
> -    qdev_prop_set_uint32(dev, "num-blocks", nb_blocs);
> +    assert(size % sector_len == 0);
> +    qdev_prop_set_uint32(dev, "num-blocks", size / sector_len);
>      qdev_prop_set_uint32(dev, "sector-length", sector_len);
>      qdev_prop_set_uint8(dev, "width", width);
>      qdev_prop_set_uint8(dev, "mappings", nb_mappings);
> diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> index 9a5be54a85..34727c5b1f 100644
> --- a/hw/i386/pc_sysfw.c
> +++ b/hw/i386/pc_sysfw.c
> @@ -110,16 +110,13 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
>      int64_t size;
>      char *fatal_errmsg = NULL;
>      hwaddr phys_addr = 0x100000000ULL;
> -    int sector_bits, sector_size;
> +    uint32_t sector_size = 4096;
>      PFlashCFI01 *system_flash;
>      MemoryRegion *flash_mem;
>      char name[64];
>      void *flash_ptr;
>      int ret, flash_size;
>
> -    sector_bits = 12;
> -    sector_size = 1 << sector_bits;
> -
>      for (unit = 0;
>           (unit < FLASH_MAP_UNIT_MAX &&
>            (pflash_drv = drive_get(IF_PFLASH, 0, unit)) != NULL);
> @@ -162,7 +159,6 @@ static void pc_system_flash_init(MemoryRegion *rom_memory)
>          snprintf(name, sizeof name, "system.flash%d", unit);
>          system_flash = pflash_cfi01_register(phys_addr, name,
>                                               size, blk, sector_size,
> -                                             size >> sector_bits,
>                                               1      /* width */,
>                                               0x0000 /* id0 */,
>                                               0x0000 /* id1 */,
> diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
> index f726355309..09f411ed07 100644
> --- a/hw/lm32/lm32_boards.c
> +++ b/hw/lm32/lm32_boards.c
> @@ -116,7 +116,7 @@ static void lm32_evr_init(MachineState *machine)
>      /* Spansion S29NS128P */
>      pflash_cfi02_register(flash_base, "lm32_evr.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          flash_sector_size, flash_size / flash_sector_size,
> +                          flash_sector_size,
>                            1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
>
>      /* create irq lines */
> @@ -209,7 +209,7 @@ static void lm32_uclinux_init(MachineState *machine)
>      /* Spansion S29NS128P */
>      pflash_cfi02_register(flash_base, "lm32_uclinux.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          flash_sector_size, flash_size / flash_sector_size,
> +                          flash_sector_size,
>                            1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
>
>      /* create irq lines */
> diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
> index ece7e3b699..46b0f51fdf 100644
> --- a/hw/lm32/milkymist.c
> +++ b/hw/lm32/milkymist.c
> @@ -123,7 +123,7 @@ milkymist_init(MachineState *machine)
>      /* Numonyx JS28F256J3F105 */
>      pflash_cfi01_register(flash_base, "milkymist.flash", flash_size,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          flash_sector_size, flash_size / flash_sector_size,
> +                          flash_sector_size,
>                            2, 0x00, 0x89, 0x00, 0x1d, 1);
>
>      /* create irq lines */
> diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c
> index 74bcc14cda..46904d2012 100644
> --- a/hw/microblaze/petalogix_ml605_mmu.c
> +++ b/hw/microblaze/petalogix_ml605_mmu.c
> @@ -109,7 +109,7 @@ petalogix_ml605_init(MachineState *machine)
>       * 10th paremeter 0 means little-endian */
>      pflash_cfi01_register(FLASH_BASEADDR, "petalogix_ml605.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          64 * KiB, FLASH_SIZE >> 16,
> +                          64 * KiB,
>                            2, 0x89, 0x18, 0x0000, 0x0, 0);
>
>
> diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c
> index a07b7f8edf..027c31fdcc 100644
> --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
> +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
> @@ -90,7 +90,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
>      pflash_cfi01_register(FLASH_BASEADDR,
>                            "petalogix_s3adsp1800.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          64 * KiB, FLASH_SIZE >> 16,
> +                          64 * KiB,
>                            1, 0x89, 0x18, 0x0000, 0x0, 1);
>
>      dev = qdev_create(NULL, "xlnx.xps-intc");
> diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
> index 76b81b7402..e5be4367b6 100644
> --- a/hw/mips/mips_malta.c
> +++ b/hw/mips/mips_malta.c
> @@ -1208,7 +1208,6 @@ void mips_malta_init(MachineState *machine)
>      DriveInfo *dinfo;
>      DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
>      int fl_idx = 0;
> -    int fl_sectors = bios_size >> 16;
>      int be;
>
>      DeviceState *dev = qdev_create(NULL, TYPE_MIPS_MALTA);
> @@ -1268,15 +1267,15 @@ void mips_malta_init(MachineState *machine)
>  #ifdef DEBUG_BOARD_INIT
>      if (dinfo) {
>          printf("Register parallel flash %d size " TARGET_FMT_lx " at "
> -               "addr %08llx '%s' %x\n",
> +               "addr %08llx '%s'\n",
>                 fl_idx, FLASH_SIZE, FLASH_ADDRESS,
> -               blk_name(dinfo->bdrv), fl_sectors);
> +               blk_name(dinfo->bdrv));
>      }
>  #endif
>      fl = pflash_cfi01_register(FLASH_ADDRESS, "mips_malta.bios",
>                                 FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                               65536, fl_sectors,
> +                               65536,
>                                 4, 0x0000, 0x0000, 0x0000, 0x0000, be);
>      bios = pflash_cfi01_get_memory(fl);
>      fl_idx++;
> diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
> index 0b9df466e7..acfd59c17a 100644
> --- a/hw/mips/mips_r4k.c
> +++ b/hw/mips/mips_r4k.c
> @@ -237,7 +237,7 @@ void mips_r4k_init(MachineState *machine)
>          uint32_t mips_rom = 0x00400000;
>          if (!pflash_cfi01_register(0x1fc00000, "mips_r4k.bios", mips_rom,
>                                     blk_by_legacy_dinfo(dinfo),
> -                                   sector_len, mips_rom / sector_len,
> +                                   sector_len,
>                                     4, 0, 0, 0, 0, be)) {
>              fprintf(stderr, "qemu: Error registering flash memory.\n");
>          }
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index a54627903d..7b96840498 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -195,7 +195,7 @@ static void ref405ep_init(MachineState *machine)
>          pflash_cfi02_register(0xFFF80000,
>                                "ef405ep.bios", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                              65536, bios_size / 65536, 1,
> +                              65536, 1,
>                                2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
>      } else
> @@ -486,7 +486,7 @@ static void taihu_405ep_init(MachineState *machine)
>          pflash_cfi02_register(0xFFE00000,
>                                "taihu_405ep.bios", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                              65536, bios_size / 65536, 1,
> +                              65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
>          fl_idx++;
> @@ -528,7 +528,7 @@ static void taihu_405ep_init(MachineState *machine)
>  #endif
>          pflash_cfi02_register(0xfc000000, "taihu_405ep.flash", bios_size,
>                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                              65536, bios_size / 65536, 1,
> +                              65536, 1,
>                                4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
>                                1);
>          fl_idx++;
> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
> index a989a8c439..a5dae67c26 100644
> --- a/hw/ppc/sam460ex.c
> +++ b/hw/ppc/sam460ex.c
> @@ -97,7 +97,7 @@ static int sam460ex_load_uboot(void)
>      if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>                                 "sam460ex.flash", FLASH_SIZE,
>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                               65536, FLASH_SIZE / 65536,
> +                               65536,

64 * KiB?

>                                 1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>          error_report("Error registering flash memory");
>          /* XXX: return an error instead? */
> diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> index d2085a839c..4f86c22968 100644
> --- a/hw/ppc/virtex_ml507.c
> +++ b/hw/ppc/virtex_ml507.c
> @@ -229,7 +229,7 @@ static void virtex_init(MachineState *machine)
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          64 * KiB, FLASH_SIZE >> 16,
> +                          64 * KiB,
>                            1, 0x89, 0x18, 0x0000, 0x0, 1);
>
>      cpu_irq = (qemu_irq *) &env->irq_inputs[PPC40x_INPUT_INT];
> diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
> index abd3b67c28..5e6953537c 100644
> --- a/hw/sh4/r2d.c
> +++ b/hw/sh4/r2d.c
> @@ -299,7 +299,7 @@ static void r2d_init(MachineState *machine)
>       */
>      pflash_cfi02_register(0x0, "r2d.flash", FLASH_SIZE / 4,
>                            dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                          16 * KiB, FLASH_SIZE >> 16,
> +                          16 * KiB,
>                            1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
>                            0x555, 0x2aa, 0);
>
> diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
> index 464a72f11b..24b13eb525 100644
> --- a/include/hw/block/flash.h
> +++ b/include/hw/block/flash.h
> @@ -17,7 +17,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
>                                     const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
> -                                   uint32_t sector_len, int nb_blocs,
> +                                   uint32_t sector_len,
>                                     int width,
>                                     uint16_t id0, uint16_t id1,
>                                     uint16_t id2, uint16_t id3,
> @@ -36,7 +36,7 @@ PFlashCFI02 *pflash_cfi02_register(hwaddr base,
>                                     const char *name,
>                                     hwaddr size,
>                                     BlockBackend *blk,
> -                                   uint32_t sector_len, int nb_blocs,
> +                                   uint32_t sector_len,
>                                     int nb_mappings,
>                                     int width,
>                                     uint16_t id0, uint16_t id1,

Otherwise:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21 16:39                   ` Philippe Mathieu-Daudé
@ 2019-02-21 16:55                     ` Laszlo Ersek
  0 siblings, 0 replies; 97+ messages in thread
From: Laszlo Ersek @ 2019-02-21 16:55 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Peter Maydell, Markus Armbruster
  Cc: Kevin Wolf, Qemu-block, QEMU Developers, Alex Bennée,
	Max Reitz, qemu-ppc, Stefano Garzarella

On 02/21/19 17:39, Philippe Mathieu-Daudé wrote:
> On 2/21/19 1:46 PM, Laszlo Ersek wrote:
>> On 02/21/19 13:38, Peter Maydell wrote:
>>> On Thu, 21 Feb 2019 at 12:07, Laszlo Ersek <lersek@redhat.com> wrote:
>>>> since we're talking "reset_flash", I'll note that there is no actual
>>>> reset handler for cfi.pflash01. I found out recently, via:
>>>>
>>>> https://bugzilla.redhat.com/show_bug.cgi?id=1678713
>>>
>>> Yes; this isn't uncommon for some of the really old
>>> device models. It should definitely have one added.
>>>
>>> You are correct also that the timer in the pflash_cfi01
>>> model is dead code -- it has always been so, since the
>>> device was added in 2007. The reason it is there is that
>>> pflash_cfi01 was created as a copy-and-hack of the
>>> cfi02 device. In cfi02 we do use the timer, as a way
>>> of simulating "make full-chip and sector erases take a
>>> guest-visible amount of time rather than completing
>>> instantaneously". cfi01 doesn't do that (and I think
>>> may not implement anything other than block erase),
> 
> This time is flash-device specific and is currently hardcoded.
> 
> The guest learn from the CFI table how long it should wait
> before polling/accessing the flash, or take measures in case
> of timeout.
> 
> We set these values in _realize():
> 
>     ...
>     /* Typical timeout for block erase (512 ms) */
>     pfl->cfi_table[0x21] = 0x09;
>     /* Typical timeout for full chip erase (4096 ms) */
>     pfl->cfi_table[0x22] = 0x0C;
>     ...
>     /* Max timeout for block erase */
>     pfl->cfi_table[0x25] = 0x0A;
>     /* Max timeout for chip erase */
>     pfl->cfi_table[0x26] = 0x0D;
> 
> The timer is triggered in _write(), where we use other hardcoded
> values (which are luckily in range with the CFI announced ones):
> 
>         /* Let's wait 5 seconds before chip erase is done */
>         timer_mod(pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
>                   (NANOSECONDS_PER_SECOND * 5));
> 
>         /* Let's wait 1/2 second before sector erase is done */
>         timer_mod(pfl->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
>                   (NANOSECONDS_PER_SECOND / 2));
> 
> When emulating embedded devices, it is very desirable to have those
> timers working, and I'd prefer we fix that on CFI01 rather than simply
> removing the unused timer.
> 
> Now for the case of "Virt" machines, it is probably pointless to add
> flash delay and we should remove the timer use.

If the timer logic can be completed in such a way that existent OVMF
code sees no change at all, on the machine types that it currently runs
on (that is, on *unversioned* i440fx and q35), I'm OK with the idea.

Thanks,
Laszlo

> 
>>> but the timer initialization code was left in rather
>>> than being deleted as part of the copy-and-hack.
>>
>> Thank you, I've linked this back into the RHBZ.
>>
>> Laszlo
>>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21 16:19             ` Philippe Mathieu-Daudé
@ 2019-02-21 17:03               ` Markus Armbruster
  2019-02-21 18:50                 ` Alex Bennée
  2019-02-22  7:17               ` Markus Armbruster
  1 sibling, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-21 17:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Laszlo Ersek, Kevin Wolf, Qemu-block,
	QEMU Developers, Max Reitz, qemu-ppc, Alex Bennée

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 2/21/19 10:38 AM, Peter Maydell wrote:
>> On Thu, 21 Feb 2019 at 09:22, Markus Armbruster <armbru@redhat.com> wrote:
>>> Double-checking... you want me to keep goto reset_flash, like this:
>>>
>>> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>>                  pfl->wcycle = 0;
>>>                  pfl->status |= 0x80;
>>>              } else {
>>> -                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>>> -                PFLASH_BUG("Write block confirm");
>>> +                qemu_log_mask(LOG_GUEST_ERROR,
>>> +                              "unknown command for \"write block\"\n");
>>>                  goto reset_flash;
>>>              }
>>>              break;
>> 
>> Yes. (We seem to handle most kinds of guest errors in programming
>> the flash by reset_flash.)
>
> Oh I missed the context of the patch here.
>
> So for the case of the Multi-WRITE command (0xe8):
>
> 1/ On first write cycle we have
>
>   - address = flash_page_address (we store it in pfl->counter)
>   - data = flash_command (0xe8: enter Multi-WRITE)
>
> 2/ Second cycle:
>
>   - address = flash_page_address
>     We should check it matches flash_page_address
>     of cycle 1/, but we don't.
>   - data: N
>
>     "N is the number of elements (bytes / words / double words),
>     minus one, to be written to the write buffer. Expected count
>     ranges are N = 00h to N = 7Fh (e.g., 1 to 128 bytes) in 8-bit
>     mode, N = 00h to N = 003Fh in 16-bit mode, and N = 00h to
>     N = 1Fh in 32-bit mode. Bus cycles 3 and higher are for writing
>     data into the write buffer. The confirm command (D0h) is
>     expected after exactly N + 1 write cycles; any other command at
>     that point in the sequence will prevent the transfer of the
>     buffer to the array (the write will be aborted)."
>
>     Instead of starting to write the data in a buffer, we write it
>     directly to the block backend.
>     Instead of starting to write from cycle 3+, we write now in 2,
>     and keep cycle count == 2 (pfl->wcycle) until all data is
>     written, where we increment at 3.
>
> 3/ Cycles 3+
>
>   - address = word index (relative to the page address)
>   - data = word value
>
>     We check for the CONFIRM command, and switch the device back
>     to READ mode (setting Status), or reset the device (which is
>     modelled the same way).
>
>     Very silly: If the guest cancelled and never sent the CONFIRM
>     command, the data is already written/flushed back.
>
> So back to the previous code snippet, regardless the value, this
> is neither a hw_error() nor a GUEST_ERROR. This code is simply not
> correct. Eventually the proper (polite) error message should be:
>
>     qemu_log_mask(LOG_UNIMP, "MULTI_WRITE: Abort not implemented,"
>                              " the data is already written"
>                              " on storage!\n"
>                              "Nevertheless resetting the flash"
>                              " into READ mode.\n");

Oww.

This code is a swamp.

Peter, Alex, do you agree with Phil's analysis?  If yes, I'll update my
patch once more.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-21 16:51   ` Alex Bennée
@ 2019-02-21 17:18     ` Markus Armbruster
  2019-02-21 17:36       ` BALATON Zoltan
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-02-21 17:18 UTC (permalink / raw)
  To: Alex Bennée; +Cc: kwolf, qemu-block, qemu-devel, mreitz, qemu-ppc, lersek

Alex Bennée <alex.bennee@linaro.org> writes:

> Markus Armbruster <armbru@redhat.com> writes:
>
>> QOMification left parameter @size unused in pflash_cfi01_register()
>> and pflash_cfi02_register().  register().  Obviously, @size should
>> match @sector_len and @nb_blocs, i.e. size == sector_len * nb_blocs.
>> All callers satisfy this.
>>
>> Remove @nb_blocs and compute it from @size and @sector_len.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
[...]
>> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
>> index a989a8c439..a5dae67c26 100644
>> --- a/hw/ppc/sam460ex.c
>> +++ b/hw/ppc/sam460ex.c
>> @@ -97,7 +97,7 @@ static int sam460ex_load_uboot(void)
>>      if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>                                 "sam460ex.flash", FLASH_SIZE,
>>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>> -                               65536, FLASH_SIZE / 65536,
>> +                               65536,
>
> 64 * KiB?

I generally prefer to keep big, repetitive patches as mechanical as
possible.  But if it's desired, I'll make this change.

Zoltan, David, David, you're maintainers, do you have a preference?

>>                                 1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>>          error_report("Error registering flash memory");
>>          /* XXX: return an error instead? */
[...]
>
> Otherwise:
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

Thanks!

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-21 17:18     ` Markus Armbruster
@ 2019-02-21 17:36       ` BALATON Zoltan
  2019-02-21 18:18         ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: BALATON Zoltan @ 2019-02-21 17:36 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Alex Bennée, kwolf, qemu-block, qemu-devel, mreitz,
	qemu-ppc, lersek, david

On Thu, 21 Feb 2019, Markus Armbruster wrote:
> Alex Bennée <alex.bennee@linaro.org> writes:
>
>> Markus Armbruster <armbru@redhat.com> writes:
>>
>>> QOMification left parameter @size unused in pflash_cfi01_register()
>>> and pflash_cfi02_register().  register().  Obviously, @size should
>>> match @sector_len and @nb_blocs, i.e. size == sector_len * nb_blocs.
>>> All callers satisfy this.
>>>
>>> Remove @nb_blocs and compute it from @size and @sector_len.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> ---
> [...]
>>> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
>>> index a989a8c439..a5dae67c26 100644
>>> --- a/hw/ppc/sam460ex.c
>>> +++ b/hw/ppc/sam460ex.c
>>> @@ -97,7 +97,7 @@ static int sam460ex_load_uboot(void)
>>>      if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>>                                 "sam460ex.flash", FLASH_SIZE,
>>>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>>> -                               65536, FLASH_SIZE / 65536,
>>> +                               65536,
>>
>> 64 * KiB?
>
> I generally prefer to keep big, repetitive patches as mechanical as
> possible.  But if it's desired, I'll make this change.
>
> Zoltan, David, David, you're maintainers, do you have a preference?

For the sam460ex, this is 64 * KiB now before your patches which matches 
other similar numbers in this file. I've already said I prefer to keep it 
as 64 * KiB in reply to your [PATCH 04/10] which changed it and you've 
agreed to that a few days ago. If you fix that patch (04/10) this one 
remains mechanical.

Regards,
BALATON Zoltan

>
>>>                                 1, 0x89, 0x18, 0x0000, 0x0, 1)) {
>>>          error_report("Error registering flash memory");
>>>          /* XXX: return an error instead? */
> [...]
>>
>> Otherwise:
>>
>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>
> Thanks!
>
>

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2
  2019-02-21 17:36       ` BALATON Zoltan
@ 2019-02-21 18:18         ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-21 18:18 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: kwolf, qemu-block, lersek, qemu-devel, mreitz, qemu-ppc,
	Alex Bennée, david

BALATON Zoltan <balaton@eik.bme.hu> writes:

> On Thu, 21 Feb 2019, Markus Armbruster wrote:
>> Alex Bennée <alex.bennee@linaro.org> writes:
>>
>>> Markus Armbruster <armbru@redhat.com> writes:
>>>
>>>> QOMification left parameter @size unused in pflash_cfi01_register()
>>>> and pflash_cfi02_register().  register().  Obviously, @size should
>>>> match @sector_len and @nb_blocs, i.e. size == sector_len * nb_blocs.
>>>> All callers satisfy this.
>>>>
>>>> Remove @nb_blocs and compute it from @size and @sector_len.
>>>>
>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>> ---
>> [...]
>>>> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
>>>> index a989a8c439..a5dae67c26 100644
>>>> --- a/hw/ppc/sam460ex.c
>>>> +++ b/hw/ppc/sam460ex.c
>>>> @@ -97,7 +97,7 @@ static int sam460ex_load_uboot(void)
>>>>      if (!pflash_cfi01_register(FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32),
>>>>                                 "sam460ex.flash", FLASH_SIZE,
>>>>                                 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>>>> -                               65536, FLASH_SIZE / 65536,
>>>> +                               65536,
>>>
>>> 64 * KiB?
>>
>> I generally prefer to keep big, repetitive patches as mechanical as
>> possible.  But if it's desired, I'll make this change.
>>
>> Zoltan, David, David, you're maintainers, do you have a preference?
>
> For the sam460ex, this is 64 * KiB now before your patches which
> matches other similar numbers in this file. I've already said I prefer
> to keep it as 64 * KiB in reply to your [PATCH 04/10] which changed it
> and you've agreed to that a few days ago. If you fix that patch
> (04/10) this one remains mechanical.

You're 100% right.  I failed to recall that detail from previous review
when I wrote the reply above.

Thanks!

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21 17:03               ` Markus Armbruster
@ 2019-02-21 18:50                 ` Alex Bennée
  0 siblings, 0 replies; 97+ messages in thread
From: Alex Bennée @ 2019-02-21 18:50 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Philippe Mathieu-Daudé,
	Peter Maydell, Laszlo Ersek, Kevin Wolf, Qemu-block,
	QEMU Developers, Max Reitz, qemu-ppc


Markus Armbruster <armbru@redhat.com> writes:

> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>
>> On 2/21/19 10:38 AM, Peter Maydell wrote:
>>> On Thu, 21 Feb 2019 at 09:22, Markus Armbruster <armbru@redhat.com> wrote:
>>>> Double-checking... you want me to keep goto reset_flash, like this:
>>>>
>>>> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>>>                  pfl->wcycle = 0;
>>>>                  pfl->status |= 0x80;
>>>>              } else {
>>>> -                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>>>> -                PFLASH_BUG("Write block confirm");
>>>> +                qemu_log_mask(LOG_GUEST_ERROR,
>>>> +                              "unknown command for \"write block\"\n");
>>>>                  goto reset_flash;
>>>>              }
>>>>              break;
>>>
>>> Yes. (We seem to handle most kinds of guest errors in programming
>>> the flash by reset_flash.)
>>
>> Oh I missed the context of the patch here.
>>
>> So for the case of the Multi-WRITE command (0xe8):
>>
>> 1/ On first write cycle we have
>>
>>   - address = flash_page_address (we store it in pfl->counter)
>>   - data = flash_command (0xe8: enter Multi-WRITE)
>>
>> 2/ Second cycle:
>>
>>   - address = flash_page_address
>>     We should check it matches flash_page_address
>>     of cycle 1/, but we don't.
>>   - data: N
>>
>>     "N is the number of elements (bytes / words / double words),
>>     minus one, to be written to the write buffer. Expected count
>>     ranges are N = 00h to N = 7Fh (e.g., 1 to 128 bytes) in 8-bit
>>     mode, N = 00h to N = 003Fh in 16-bit mode, and N = 00h to
>>     N = 1Fh in 32-bit mode. Bus cycles 3 and higher are for writing
>>     data into the write buffer. The confirm command (D0h) is
>>     expected after exactly N + 1 write cycles; any other command at
>>     that point in the sequence will prevent the transfer of the
>>     buffer to the array (the write will be aborted)."
>>
>>     Instead of starting to write the data in a buffer, we write it
>>     directly to the block backend.
>>     Instead of starting to write from cycle 3+, we write now in 2,
>>     and keep cycle count == 2 (pfl->wcycle) until all data is
>>     written, where we increment at 3.
>>
>> 3/ Cycles 3+
>>
>>   - address = word index (relative to the page address)
>>   - data = word value
>>
>>     We check for the CONFIRM command, and switch the device back
>>     to READ mode (setting Status), or reset the device (which is
>>     modelled the same way).
>>
>>     Very silly: If the guest cancelled and never sent the CONFIRM
>>     command, the data is already written/flushed back.
>>
>> So back to the previous code snippet, regardless the value, this
>> is neither a hw_error() nor a GUEST_ERROR. This code is simply not
>> correct. Eventually the proper (polite) error message should be:
>>
>>     qemu_log_mask(LOG_UNIMP, "MULTI_WRITE: Abort not implemented,"
>>                              " the data is already written"
>>                              " on storage!\n"
>>                              "Nevertheless resetting the flash"
>>                              " into READ mode.\n");
>
> Oww.
>
> This code is a swamp.
>
> Peter, Alex, do you agree with Phil's analysis?  If yes, I'll update my
> patch once more.

I'm happy to defer to Phil's obvious expertise here ;-)

--
Alex Bennée

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-21 16:31     ` Markus Armbruster
@ 2019-02-21 22:18       ` David Gibson
  2019-02-22  7:23         ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: David Gibson @ 2019-02-21 22:18 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Alex Bennée, kwolf, qemu-block, qemu-devel, mreitz,
	qemu-ppc, lersek

[-- Attachment #1: Type: text/plain, Size: 4555 bytes --]

On Thu, Feb 21, 2019 at 05:31:30PM +0100, Markus Armbruster wrote:
> Alex Bennée <alex.bennee@linaro.org> writes:
> 
> > Markus Armbruster <armbru@redhat.com> writes:
> >
> >> Machine "ref405ep" maps its flash memory at address 2^32 - image size.
> >> Image size is rounded up to the next multiple of 64KiB.  Useless,
> >> because pflash_cfi02_realize() fails with "failed to read the initial
> >> flash content" unless the rounding is a no-op.
> >>
> >> If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
> >> other stuff.  No idea how that would play out, but a useful outcomes
> >> seem unlikely.
> >>
> >> Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
> >> regardless of image size, to match the physical hardware.
> >>
> >> Machine "taihu" maps its boot flash memory similarly.  The code even
> >> has a comment /* XXX: should check that size is 2MB */, followed by
> >> disabled code to adjust the size to 2MiB regardless of image size.
> >>
> >> Its code to map its application flash memory looks the same, except
> >> there the XXX comment asks for 32MiB, and the code to adjust the size
> >> isn't disabled.  Note that pflash_cfi02_realize() fails with "failed
> >> to read the initial flash content" for images smaller than 32MiB.
> >>
> >> Map the boot flash memory at fixed address 0xFFE00000 with size 2MiB,
> >> to match the physical hardware.  Delete dead code from application
> >> flash mapping, and simplify some.
> >>
> >> Cc: David Gibson <david@gibson.dropbear.id.au>
> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> >> ---
> >>  hw/ppc/ppc405_boards.c | 53 +++++++++++++-----------------------------
> >>  1 file changed, 16 insertions(+), 37 deletions(-)
> >>
> >> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> >> index f47b15f10e..728154aebb 100644
> >> --- a/hw/ppc/ppc405_boards.c
> >> +++ b/hw/ppc/ppc405_boards.c
> >> @@ -158,7 +158,7 @@ static void ref405ep_init(MachineState *machine)
> >>      target_ulong kernel_base, initrd_base;
> >>      long kernel_size, initrd_size;
> >>      int linux_boot;
> >> -    int fl_idx, fl_sectors, len;
> >> +    int len;
> >>      DriveInfo *dinfo;
> >>      MemoryRegion *sysmem = get_system_memory();
> >>
> >> @@ -185,26 +185,19 @@ static void ref405ep_init(MachineState *machine)
> >>  #ifdef DEBUG_BOARD_INIT
> >>      printf("%s: register BIOS\n", __func__);
> >>  #endif
> >> -    fl_idx = 0;
> >>  #ifdef USE_FLASH_BIOS
> >> -    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
> >> +    dinfo = drive_get(IF_PFLASH, 0, 0);
> >>      if (dinfo) {
> >> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
> >> -
> >> -        bios_size = blk_getlength(blk);
> >> -        fl_sectors = (bios_size + 65535) >> 16;
> >>  #ifdef DEBUG_BOARD_INIT
> >> -        printf("Register parallel flash %d size %lx"
> >> -               " at addr %lx '%s' %d\n",
> >> -               fl_idx, bios_size, -bios_size,
> >> -               blk_name(blk), fl_sectors);
> >> +        printf("Register parallel flash\n");
> >>  #endif
> >> -        pflash_cfi02_register((uint32_t)(-bios_size),
> >> +        bios_size = 0x80000;
> >
> >  bios_size = 8 * MiB?
> 
> The next line has base address 0xFFF80000.  I picked 0x80000 to make
> 0xFFF80000 + 0x80000 == 0 mod 2^32 more obvious.
> 
> If I change 0x80000 to 8 * MiB, the size is more obvious, but "at end of
> 32 bit address space" less so.
> 
> If I additionally change the base address back to ((uint32_t)-bios_size,
> "at end of 32 bit address space" is obvious again, but the actual base
> address less so.

I have a weak preference for ((uint32_t)-bios_size), with bios_size =
8 * MiB.

> 
> I don't really care myself.  David, you're the maintainer, do you have a
> preference?
> 
> >> +        pflash_cfi02_register(0xFFF80000,
> >>                                NULL, "ef405ep.bios", bios_size,
> >> -                              blk, 65536, fl_sectors, 1,
> >> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> >> +                              65536, bios_size / 65536, 1,
> >
> > 64 * KiB?
> 
> David, same question (two additional instances below).

Here I think 64 * KiB would be nice in each of those places.  Again,
only a weak preference.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand
  2019-02-21 16:19             ` Philippe Mathieu-Daudé
  2019-02-21 17:03               ` Markus Armbruster
@ 2019-02-22  7:17               ` Markus Armbruster
  1 sibling, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-22  7:17 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Laszlo Ersek, Kevin Wolf, Qemu-block,
	QEMU Developers, Max Reitz, qemu-ppc, Alex Bennée

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 2/21/19 10:38 AM, Peter Maydell wrote:
>> On Thu, 21 Feb 2019 at 09:22, Markus Armbruster <armbru@redhat.com> wrote:
>>> Double-checking... you want me to keep goto reset_flash, like this:
>>>
>>> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>>>                  pfl->wcycle = 0;
>>>                  pfl->status |= 0x80;
>>>              } else {
>>> -                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
>>> -                PFLASH_BUG("Write block confirm");
>>> +                qemu_log_mask(LOG_GUEST_ERROR,
>>> +                              "unknown command for \"write block\"\n");
>>>                  goto reset_flash;
>>>              }
>>>              break;
>> 
>> Yes. (We seem to handle most kinds of guest errors in programming
>> the flash by reset_flash.)
>
> Oh I missed the context of the patch here.
>
> So for the case of the Multi-WRITE command (0xe8):

Since I'm a clueless idiot on pflash, I need to process your argument
real slow, so I can write a commit message that doesn't document my
cluelessness forever.

We have a little state machine, and its state is encoded in
pfl->wcycle. pfl->cmd, pfl->counter.  I'm going to show it as

    (value of pfl->wcycle, value of pfl->cmd, value of pfl->counter)

for brevity.

We start with (0, don't care, don't care).

A guest write sends us a width, an address, and a value.
pflash_mem_write_with_attrs() does permission checking, and
pflash_write() the actual work.  We enter it with @offset, @value and
@width holding the message.

    cmd = value;

    trace_pflash_write(offset, value, width, pfl->wcycle);
    if (!pfl->wcycle) {
        /* Set the device in I/O access mode */
        memory_region_rom_device_set_romd(&pfl->mem, false);
    }

@cmd is @value truncated to 8 bits.

> 1/ On first write cycle we have
>
>   - address = flash_page_address (we store it in pfl->counter)
>   - data = flash_command (0xe8: enter Multi-WRITE)

    switch (pfl->wcycle) {
    case 0:
        /* read mode */
        switch (cmd) {
        [...]
        case 0xe8: /* Write to buffer */
            DPRINTF("%s: Write to buffer\n", __func__);
            pfl->status |= 0x80; /* Ready! */
            break;
        [...]
        pfl->wcycle++;
        pfl->cmd = cmd;
        break;

Transition from (0, don't care, don't care) to (1, 0xE8, don't care).

I can't see "we store it in pfl->counter".

Note that the address (passed in @offset) is entirely ignored.

> 2/ Second cycle:
>
>   - address = flash_page_address
>     We should check it matches flash_page_address
>     of cycle 1/, but we don't.
>   - data: N
>
>     "N is the number of elements (bytes / words / double words),
>     minus one, to be written to the write buffer. Expected count
>     ranges are N = 00h to N = 7Fh (e.g., 1 to 128 bytes) in 8-bit
>     mode, N = 00h to N = 003Fh in 16-bit mode, and N = 00h to
>     N = 1Fh in 32-bit mode. Bus cycles 3 and higher are for writing
>     data into the write buffer. The confirm command (D0h) is
>     expected after exactly N + 1 write cycles; any other command at
>     that point in the sequence will prevent the transfer of the
>     buffer to the array (the write will be aborted)."
>
>     Instead of starting to write the data in a buffer, we write it
>     directly to the block backend.

    case 1:
        switch (pfl->cmd) {
        [...]
        case 0xe8:
            /* Mask writeblock size based on device width, or bank width if
             * device width not specified.
             */
            if (pfl->device_width) {
                value = extract32(value, 0, pfl->device_width * 8);
            } else {
                value = extract32(value, 0, pfl->bank_width * 8);
            }
            DPRINTF("%s: block write of %x bytes\n", __func__, value);
            pfl->counter = value;
            pfl->wcycle++;
            break;
        [...]
        }
        break;

Transition from (1, 0xE8, don't care) to (2, 0xE8, N), where N is passed
in @value.

Again, the address (passed in @offset) is ignored.

Nothing is written to the block backend, yet.

>     Instead of starting to write from cycle 3+, we write now in 2,
>     and keep cycle count == 2 (pfl->wcycle) until all data is
>     written, where we increment at 3.

    case 2:
        switch (pfl->cmd) {
        case 0xe8: /* Block write */
            if (!pfl->ro) {
                pflash_data_write(pfl, offset, value, width, be);
            } else {
                pfl->status |= 0x10; /* Programming error */
            }

Write to memory, with pflash_data_write(), but don't flush to the
backend, yet.  This is (guest-visibly!) wrong.  It's not quite "instead
of starting to write the data in a buffer, we write it directly to the
block backend."

Note that we happily accept any address and width.  I suspect we should
only accept consecutive addresses and consistent width.

            pfl->status |= 0x80;

            if (!pfl->counter) {
                hwaddr mask = pfl->writeblock_size - 1;
                mask = ~mask;

                DPRINTF("%s: block write finished\n", __func__);
                pfl->wcycle++;
                if (!pfl->ro) {
                    /* Flush the entire write buffer onto backing storage.  */
                    pflash_update(pfl, offset & mask, pfl->writeblock_size);
                } else {
                    pfl->status |= 0x10; /* Programming error */
                }
            }

If this is the multi-write's last write, flush the entire write block to
the backend *boggle*.

            pfl->counter--;
            break;
        [...]
        }
        break;

Transition from (2, 0xE8, N) to

    (2, 0xE8, N-1)          if N>0
    (3, 0xE8, don't care)   if N==0

> 3/ Cycles 3+
>
>   - address = word index (relative to the page address)
>   - data = word value
>
>     We check for the CONFIRM command, and switch the device back
>     to READ mode (setting Status), or reset the device (which is
>     modelled the same way).
>
>     Very silly: If the guest cancelled and never sent the CONFIRM
>     command, the data is already written/flushed back.

    case 3: /* Confirm mode */
        switch (pfl->cmd) {
        case 0xe8: /* Block write */
            if (cmd == 0xd0) {
                pfl->wcycle = 0;
                pfl->status |= 0x80;

On CONFIRM, transition from (3, 0xE8, don't care) back to the intial
state (0, don't care, don't care).

            } else {
                DPRINTF("%s: unknown command for \"write block\"\n", __func__);
                PFLASH_BUG("Write block confirm");
                goto reset_flash;
            }

On anything else, pea brain implodes, and we exit(1).

            break;

The fact that we let a hack job like this anywhere near "secure boot" is
either frightening or amusing, depending on one's level of cynicism
towards virtual secure boot.

> So back to the previous code snippet, regardless the value, this
> is neither a hw_error() nor a GUEST_ERROR. This code is simply not
> correct. Eventually the proper (polite) error message should be:
>
>     qemu_log_mask(LOG_UNIMP, "MULTI_WRITE: Abort not implemented,"
>                              " the data is already written"
>                              " on storage!\n"
>                              "Nevertheless resetting the flash"
>                              " into READ mode.\n");

Yup, makes sense.

Perhaps we should also LOG_UNIMP on the first write of a multi-write
already, because the guest-visible wrongness starts right there.  You
tell me.

Two things left to do for this series: FIXME comments, and a commit
message.  Before I tackle them, I'll give you a chance to correct
misunderstandings in my reasoning.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 05/10] ppc405_boards: Don't size flash memory to match backing image
  2019-02-21 22:18       ` David Gibson
@ 2019-02-22  7:23         ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-02-22  7:23 UTC (permalink / raw)
  To: David Gibson
  Cc: kwolf, qemu-block, lersek, qemu-devel, mreitz, qemu-ppc,
	Alex Bennée

David Gibson <david@gibson.dropbear.id.au> writes:

> On Thu, Feb 21, 2019 at 05:31:30PM +0100, Markus Armbruster wrote:
>> Alex Bennée <alex.bennee@linaro.org> writes:
>> 
>> > Markus Armbruster <armbru@redhat.com> writes:
>> >
>> >> Machine "ref405ep" maps its flash memory at address 2^32 - image size.
>> >> Image size is rounded up to the next multiple of 64KiB.  Useless,
>> >> because pflash_cfi02_realize() fails with "failed to read the initial
>> >> flash content" unless the rounding is a no-op.
>> >>
>> >> If the image size exceeds 0x80000 Bytes, we overlap first SRAM, then
>> >> other stuff.  No idea how that would play out, but a useful outcomes
>> >> seem unlikely.
>> >>
>> >> Map the flash memory at fixed address 0xFFF80000 with size 512KiB,
>> >> regardless of image size, to match the physical hardware.
>> >>
>> >> Machine "taihu" maps its boot flash memory similarly.  The code even
>> >> has a comment /* XXX: should check that size is 2MB */, followed by
>> >> disabled code to adjust the size to 2MiB regardless of image size.
>> >>
>> >> Its code to map its application flash memory looks the same, except
>> >> there the XXX comment asks for 32MiB, and the code to adjust the size
>> >> isn't disabled.  Note that pflash_cfi02_realize() fails with "failed
>> >> to read the initial flash content" for images smaller than 32MiB.
>> >>
>> >> Map the boot flash memory at fixed address 0xFFE00000 with size 2MiB,
>> >> to match the physical hardware.  Delete dead code from application
>> >> flash mapping, and simplify some.
>> >>
>> >> Cc: David Gibson <david@gibson.dropbear.id.au>
>> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> >> ---
>> >>  hw/ppc/ppc405_boards.c | 53 +++++++++++++-----------------------------
>> >>  1 file changed, 16 insertions(+), 37 deletions(-)
>> >>
>> >> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
>> >> index f47b15f10e..728154aebb 100644
>> >> --- a/hw/ppc/ppc405_boards.c
>> >> +++ b/hw/ppc/ppc405_boards.c
>> >> @@ -158,7 +158,7 @@ static void ref405ep_init(MachineState *machine)
>> >>      target_ulong kernel_base, initrd_base;
>> >>      long kernel_size, initrd_size;
>> >>      int linux_boot;
>> >> -    int fl_idx, fl_sectors, len;
>> >> +    int len;
>> >>      DriveInfo *dinfo;
>> >>      MemoryRegion *sysmem = get_system_memory();
>> >>
>> >> @@ -185,26 +185,19 @@ static void ref405ep_init(MachineState *machine)
>> >>  #ifdef DEBUG_BOARD_INIT
>> >>      printf("%s: register BIOS\n", __func__);
>> >>  #endif
>> >> -    fl_idx = 0;
>> >>  #ifdef USE_FLASH_BIOS
>> >> -    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
>> >> +    dinfo = drive_get(IF_PFLASH, 0, 0);
>> >>      if (dinfo) {
>> >> -        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
>> >> -
>> >> -        bios_size = blk_getlength(blk);
>> >> -        fl_sectors = (bios_size + 65535) >> 16;
>> >>  #ifdef DEBUG_BOARD_INIT
>> >> -        printf("Register parallel flash %d size %lx"
>> >> -               " at addr %lx '%s' %d\n",
>> >> -               fl_idx, bios_size, -bios_size,
>> >> -               blk_name(blk), fl_sectors);
>> >> +        printf("Register parallel flash\n");
>> >>  #endif
>> >> -        pflash_cfi02_register((uint32_t)(-bios_size),
>> >> +        bios_size = 0x80000;
>> >
>> >  bios_size = 8 * MiB?
>> 
>> The next line has base address 0xFFF80000.  I picked 0x80000 to make
>> 0xFFF80000 + 0x80000 == 0 mod 2^32 more obvious.
>> 
>> If I change 0x80000 to 8 * MiB, the size is more obvious, but "at end of
>> 32 bit address space" less so.
>> 
>> If I additionally change the base address back to ((uint32_t)-bios_size,
>> "at end of 32 bit address space" is obvious again, but the actual base
>> address less so.
>
> I have a weak preference for ((uint32_t)-bios_size), with bios_size =
> 8 * MiB.
>
>> 
>> I don't really care myself.  David, you're the maintainer, do you have a
>> preference?
>> 
>> >> +        pflash_cfi02_register(0xFFF80000,
>> >>                                NULL, "ef405ep.bios", bios_size,
>> >> -                              blk, 65536, fl_sectors, 1,
>> >> +                              dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
>> >> +                              65536, bios_size / 65536, 1,
>> >
>> > 64 * KiB?
>> 
>> David, same question (two additional instances below).
>
> Here I think 64 * KiB would be nice in each of those places.  Again,
> only a weak preference.

Your weak preference is enough to tip my scales.  Thanks!

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (18 preceding siblings ...)
  2019-02-19 16:43 ` no-reply
@ 2019-02-27 15:26 ` no-reply
  2019-02-27 17:41 ` no-reply
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-27 15:26 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190218140926.333779-1-vsementsov@virtuozzo.com -> patchew/20190218140926.333779-1-vsementsov@virtuozzo.com
Switched to a new branch 'test'
ba3f93c692 hw/arm hw/xtensa: De-duplicate pflash creation code some
f99ab9fe08 pflash: Clean up after commit 368a354f02b part 2
e98231996b pflash: Clean up after commit 368a354f02b part 1
fd218de008 mips_malta: Clean up definition of flash memory size somewhat
413850d478 r2d: Flash memory creation is confused about size, mark FIXME
d23c64b271 ppc405_boards: Don't size flash memory to match backing image
db2935d503 sam460ex: Don't size flash memory to match backing image
856425f0be hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
09fa7495d9 pflash: Macro PFLASH_BUG() is used just once, expand
83625c2e47 pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit 83625c2e4780 (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#128: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#340: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#358: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 09fa7495d9a5 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 856425f0be58 (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit db2935d50313 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit d23c64b27139 (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 413850d478aa (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit fd218de008eb (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit e98231996be7 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#92: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#100: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit f99ab9fe08d8 (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit ba3f93c692dd (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
  2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
                   ` (19 preceding siblings ...)
  2019-02-27 15:26 ` no-reply
@ 2019-02-27 17:41 ` no-reply
  20 siblings, 0 replies; 97+ messages in thread
From: no-reply @ 2019-02-27 17:41 UTC (permalink / raw)
  To: armbru
  Cc: fam, qemu-devel, kwolf, qemu-block, alex.bennee, mreitz,
	qemu-ppc, lersek

Patchew URL: https://patchew.org/QEMU/20190218125615.18970-1-armbru@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190218125615.18970-1-armbru@redhat.com
Subject: [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/20190219195928.12289-1-dgilbert@redhat.com -> patchew/20190219195928.12289-1-dgilbert@redhat.com
Switched to a new branch 'test'
97502f3196 hw/arm hw/xtensa: De-duplicate pflash creation code some
6bb2bc07ff pflash: Clean up after commit 368a354f02b part 2
9604558ee0 pflash: Clean up after commit 368a354f02b part 1
bc39e20ae1 mips_malta: Clean up definition of flash memory size somewhat
9aeddfb874 r2d: Flash memory creation is confused about size, mark FIXME
cd1fb1567e ppc405_boards: Don't size flash memory to match backing image
6a565f0a2a sam460ex: Don't size flash memory to match backing image
9cbfffefec hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2}
9f784f3f33 pflash: Macro PFLASH_BUG() is used just once, expand
1e9644bd3b pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02

=== OUTPUT BEGIN ===
1/10 Checking commit 1e9644bd3b0d (pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02)
ERROR: space prohibited between function name and open parenthesis '('
#129: FILE: hw/block/pflash_cfi01.c:288:
+static uint32_t pflash_read (PFlashCFI01 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#341: FILE: hw/block/pflash_cfi02.c:141:
+static uint32_t pflash_read (PFlashCFI02 *pfl, hwaddr offset,

ERROR: space prohibited between function name and open parenthesis '('
#359: FILE: hw/block/pflash_cfi02.c:264:
+static void pflash_write (PFlashCFI02 *pfl, hwaddr offset,

total: 3 errors, 0 warnings, 483 lines checked

Patch 1/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

2/10 Checking commit 9f784f3f3321 (pflash: Macro PFLASH_BUG() is used just once, expand)
3/10 Checking commit 9cbfffefec0b (hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2})
4/10 Checking commit 6a565f0a2aa8 (sam460ex: Don't size flash memory to match backing image)
5/10 Checking commit cd1fb1567ec3 (ppc405_boards: Don't size flash memory to match backing image)
6/10 Checking commit 9aeddfb8748e (r2d: Flash memory creation is confused about size, mark FIXME)
7/10 Checking commit bc39e20ae16c (mips_malta: Clean up definition of flash memory size somewhat)
8/10 Checking commit 9604558ee0b8 (pflash: Clean up after commit 368a354f02b part 1)
ERROR: spaces required around that '-' (ctx:VxV)
#92: FILE: hw/arm/musicpal.c:1639:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

ERROR: spaces required around that '-' (ctx:VxV)
#100: FILE: hw/arm/musicpal.c:1646:
+        pflash_cfi02_register(0x100000000ULL-MP_FLASH_SIZE_MAX,
                                             ^

total: 2 errors, 0 warnings, 248 lines checked

Patch 8/10 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

9/10 Checking commit 6bb2bc07ffb7 (pflash: Clean up after commit 368a354f02b part 2)
10/10 Checking commit 97502f319636 (hw/arm hw/xtensa: De-duplicate pflash creation code some)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190218125615.18970-1-armbru@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-02-19 17:30         ` Markus Armbruster
@ 2019-03-04  4:57           ` Magnus Damm
  2019-03-04  7:25             ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Magnus Damm @ 2019-03-04  4:57 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Philippe Mathieu-Daudé,
	Peter Maydell, Kevin Wolf, Qemu-block, Laszlo Ersek,
	QEMU Developers, Max Reitz, qemu-ppc, Alex Bennée

Hi guys,

On Wed, Feb 20, 2019 at 2:31 AM Markus Armbruster <armbru@redhat.com> wrote:
>
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>
> > On 2/19/19 4:45 PM, Markus Armbruster wrote:
> >> Peter Maydell <peter.maydell@linaro.org> writes:
> >>
> >>> On Mon, 18 Feb 2019 at 13:07, Markus Armbruster <armbru@redhat.com> wrote:
> >>>>
> >>>> pflash_cfi02_register() takes a size in bytes, a block size in bytes
> >>>> and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
> >>>> FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
> >>>> number of blocks.  The latter happens to win.  I tried to find
> >>>> documentation on the physcial hardware, no luck.
> >
> > "physical"
>
> Thanks, will fix.
>
> >>>>
> >>>> For now, adjust the byte size passed to match the actual size created,
> >>>> and add a FIXME comment.
> >>>
> >>> I'm pretty sure that FLASH_SIZE here is supposed to be a
> >>> byte count of the size of the pflash. That matches what
> >>> Linux has in arch/sh/boards/mach-r2d/setup.c where it
> >>> sets up the flash_resource struct.
> >>
> >> Okay, that's some evidence for size 0x02000000 (32MiB).
> >>
> >> However, we've created size (16 * KiB) * (FLASH_SIZE >> 16), i.e. 8MiB,
> >> since at least commit 368a354f02b (v1.3.0), possibly since forever.
> >>
> >>> The r2dplus board is also I think known as RTS7751R2D. That
> >>> takes us to https://elinux.org/RTS7751R2D_Handling_Manual
> >>> (sadly the link to the "hardware manual" is broken).
> >>
> >> Quote section Flash ROM Mapping:
> >>
> >>     Currently, MTD device mapping on Flash ROM is set as below.
> >>     0x00000000-0x00020000    "bootloader"
> >>     0x00020000-0x00320000    "mtdblock1"     XIP kernel
> >>     0x00320000-0x00520000    "mtdblock2"
> >>     0x00520000-0x01000000    "mtdblock3"
> >>
> >> Suggests a size of 0x01000000 (16MiB).  Now we have three candidates.
> >>
> >> Pick one, any one, and I'll adjust my patch.  All I really care about is
> >> getting argument @size consistent with arguments @sector_len and
> >> @nb_blocs, so I can ditch @nb_blocs in PATCH 09.
> >>
> >>> No idea what the block size would be.
> >>
> >> As long as that's the case, inertia wins by default.
> >
> > There is also a paper [*]:
> >
> >   The Renesas Technology R0P751RLC001RL (R2DPLUS) board was used
> >   as our target device.
> >   This board is often used to evaluate software for CE devices.
> >   The specification is shown below.
> >     CPU: SH7751R(SH4) 240Mhz
> >     RAM: 64Mbyte
> >     Compact flash: 512Mbyte
> >     Flash ROM: 64Mbyte (32Mbyte available for root file system)
>
> Candidate #4: 64MiB.  Bring 'em on!
>
> >
> > Let's use at least 16MB to be able to run the elinux cited kernel.
> >
> > [*] https://www.kernel.org/doc/ols/2008/ols2008v2-pages-125-134.pdf
>
> That's a vote for changing the status quo (8 MiB).
>
> Perhaps Magnus, who maintains the machine, can pick a new value for us.

According to the old board user document in Japanese (under NDA) what
is referred to as FROM (Area0) is connected via a 32-bit bus and CS0
to CN8. The docs mention s29pl127j60tfi130 but since I don't have the
board handy ATM I don't know how the chips are connected.

Hope this helps,

/ magnus

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-04  4:57           ` Magnus Damm
@ 2019-03-04  7:25             ` Markus Armbruster
  2019-03-04 11:43               ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-03-04  7:25 UTC (permalink / raw)
  To: Magnus Damm
  Cc: Kevin Wolf, Peter Maydell, Qemu-block, Laszlo Ersek,
	QEMU Developers, Max Reitz, Alex Bennée, qemu-ppc,
	Philippe Mathieu-Daudé

Magnus Damm <magnus.damm@gmail.com> writes:

> Hi guys,
>
> On Wed, Feb 20, 2019 at 2:31 AM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>>
>> > On 2/19/19 4:45 PM, Markus Armbruster wrote:
>> >> Peter Maydell <peter.maydell@linaro.org> writes:
>> >>
>> >>> On Mon, 18 Feb 2019 at 13:07, Markus Armbruster <armbru@redhat.com> wrote:
>> >>>>
>> >>>> pflash_cfi02_register() takes a size in bytes, a block size in bytes
>> >>>> and a number of blocks.  r2d_init() passes FLASH_SIZE, 16 * KiB,
>> >>>> FLASH_SIZE >> 16.  Does not compute: size doesn't match block size *
>> >>>> number of blocks.  The latter happens to win.  I tried to find
>> >>>> documentation on the physcial hardware, no luck.
>> >
>> > "physical"
>>
>> Thanks, will fix.
>>
>> >>>>
>> >>>> For now, adjust the byte size passed to match the actual size created,
>> >>>> and add a FIXME comment.
>> >>>
>> >>> I'm pretty sure that FLASH_SIZE here is supposed to be a
>> >>> byte count of the size of the pflash. That matches what
>> >>> Linux has in arch/sh/boards/mach-r2d/setup.c where it
>> >>> sets up the flash_resource struct.
>> >>
>> >> Okay, that's some evidence for size 0x02000000 (32MiB).
>> >>
>> >> However, we've created size (16 * KiB) * (FLASH_SIZE >> 16), i.e. 8MiB,
>> >> since at least commit 368a354f02b (v1.3.0), possibly since forever.
>> >>
>> >>> The r2dplus board is also I think known as RTS7751R2D. That
>> >>> takes us to https://elinux.org/RTS7751R2D_Handling_Manual
>> >>> (sadly the link to the "hardware manual" is broken).
>> >>
>> >> Quote section Flash ROM Mapping:
>> >>
>> >>     Currently, MTD device mapping on Flash ROM is set as below.
>> >>     0x00000000-0x00020000    "bootloader"
>> >>     0x00020000-0x00320000    "mtdblock1"     XIP kernel
>> >>     0x00320000-0x00520000    "mtdblock2"
>> >>     0x00520000-0x01000000    "mtdblock3"
>> >>
>> >> Suggests a size of 0x01000000 (16MiB).  Now we have three candidates.
>> >>
>> >> Pick one, any one, and I'll adjust my patch.  All I really care about is
>> >> getting argument @size consistent with arguments @sector_len and
>> >> @nb_blocs, so I can ditch @nb_blocs in PATCH 09.
>> >>
>> >>> No idea what the block size would be.
>> >>
>> >> As long as that's the case, inertia wins by default.
>> >
>> > There is also a paper [*]:
>> >
>> >   The Renesas Technology R0P751RLC001RL (R2DPLUS) board was used
>> >   as our target device.
>> >   This board is often used to evaluate software for CE devices.
>> >   The specification is shown below.
>> >     CPU: SH7751R(SH4) 240Mhz
>> >     RAM: 64Mbyte
>> >     Compact flash: 512Mbyte
>> >     Flash ROM: 64Mbyte (32Mbyte available for root file system)
>>
>> Candidate #4: 64MiB.  Bring 'em on!
>>
>> >
>> > Let's use at least 16MB to be able to run the elinux cited kernel.
>> >
>> > [*] https://www.kernel.org/doc/ols/2008/ols2008v2-pages-125-134.pdf
>>
>> That's a vote for changing the status quo (8 MiB).
>>
>> Perhaps Magnus, who maintains the machine, can pick a new value for us.
>
> According to the old board user document in Japanese (under NDA) what
> is referred to as FROM (Area0) is connected via a 32-bit bus and CS0
> to CN8. The docs mention s29pl127j60tfi130 but since I don't have the
> board handy ATM I don't know how the chips are connected.
>
> Hope this helps,

If you want me to change our emulated flash memory's size, please give
me a number.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-04  7:25             ` Markus Armbruster
@ 2019-03-04 11:43               ` Philippe Mathieu-Daudé
  2019-03-04 15:33                 ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-03-04 11:43 UTC (permalink / raw)
  To: Markus Armbruster, Magnus Damm
  Cc: Kevin Wolf, Peter Maydell, Qemu-block, Laszlo Ersek,
	QEMU Developers, Max Reitz, Alex Bennée, qemu-ppc

On 3/4/19 8:25 AM, Markus Armbruster wrote:
> Magnus Damm <magnus.damm@gmail.com> writes:
>> On Wed, Feb 20, 2019 at 2:31 AM Markus Armbruster <armbru@redhat.com> wrote:
>>> Perhaps Magnus, who maintains the machine, can pick a new value for us.
>>
>> According to the old board user document in Japanese (under NDA) what
>> is referred to as FROM (Area0) is connected via a 32-bit bus and CS0
>> to CN8. The docs mention s29pl127j60tfi130 but since I don't have the
>> board handy ATM I don't know how the chips are connected.
>>
>> Hope this helps,
> 
> If you want me to change our emulated flash memory's size, please give
> me a number.

datasheet "S29PL-J 002-00615 Rev. *E":
https://www.cypress.com/file/207091/download

The S29PL127J60TFI130 is a 128Mbit NOR pflash addressable in words of 16bit.

128Mbit = 16 MiB

At least it matches the "RTS7751R2D Handling Manual"!
https://elinux.org/RTS7751R2D_Handling_Manual#Kernel_start_from_FROM_extension_card_.28Kernel_space_XIP.29

PL127J:
- 4 Banks
  -> we don't model banks.
- sectors of 4Kw and 32Kw
  -> we don't model different sector size and only use the
     biggest available

sector_size = 32Kw = 64KiB // sector_len
(naive) sector_count = 256 // nb_blocs

ManufID:  0001h
DeviceID: 227Eh 2220h 2200h

I understand "connected via a 32-bit bus and CS0 to CN8" as the full
device wordsize is addressable, so this device

So in pflash_cfi02_register() format:

- name = "FROM (Area0)"
- size = 16 * MiB
- sector_len = 64 * KiB
- nb_blocs = 256
- nb_mappings = 1? /* Machine specific... */
- width = 2
- id0 = 0x0001
- id1 = 0x227e
- id2 = 0x2220
- id3 = 0x2200
- unlock_addr0 = 0x555,
- unlock_addr1 = 0x2aa
- be = 0 /* Arch specific... */

Which hopefully is very similar to what we currently use :)

Regards,

Phil.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-04 11:43               ` Philippe Mathieu-Daudé
@ 2019-03-04 15:33                 ` Markus Armbruster
  2019-03-05 17:21                   ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 97+ messages in thread
From: Markus Armbruster @ 2019-03-04 15:33 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Magnus Damm, Kevin Wolf, Peter Maydell, Qemu-block,
	Alex Bennée, QEMU Developers, Max Reitz, qemu-ppc,
	Laszlo Ersek

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 3/4/19 8:25 AM, Markus Armbruster wrote:
>> Magnus Damm <magnus.damm@gmail.com> writes:
>>> On Wed, Feb 20, 2019 at 2:31 AM Markus Armbruster <armbru@redhat.com> wrote:
>>>> Perhaps Magnus, who maintains the machine, can pick a new value for us.
>>>
>>> According to the old board user document in Japanese (under NDA) what
>>> is referred to as FROM (Area0) is connected via a 32-bit bus and CS0
>>> to CN8. The docs mention s29pl127j60tfi130 but since I don't have the
>>> board handy ATM I don't know how the chips are connected.
>>>
>>> Hope this helps,
>> 
>> If you want me to change our emulated flash memory's size, please give
>> me a number.
>
> datasheet "S29PL-J 002-00615 Rev. *E":
> https://www.cypress.com/file/207091/download
>
> The S29PL127J60TFI130 is a 128Mbit NOR pflash addressable in words of 16bit.
>
> 128Mbit = 16 MiB
>
> At least it matches the "RTS7751R2D Handling Manual"!
> https://elinux.org/RTS7751R2D_Handling_Manual#Kernel_start_from_FROM_extension_card_.28Kernel_space_XIP.29
>
> PL127J:
> - 4 Banks
>   -> we don't model banks.
> - sectors of 4Kw and 32Kw
>   -> we don't model different sector size and only use the
>      biggest available
>
> sector_size = 32Kw = 64KiB // sector_len
> (naive) sector_count = 256 // nb_blocs
>
> ManufID:  0001h
> DeviceID: 227Eh 2220h 2200h
>
> I understand "connected via a 32-bit bus and CS0 to CN8" as the full
> device wordsize is addressable, so this device
>
> So in pflash_cfi02_register() format:
>
> - name = "FROM (Area0)"
> - size = 16 * MiB
> - sector_len = 64 * KiB
> - nb_blocs = 256
> - nb_mappings = 1? /* Machine specific... */
> - width = 2
> - id0 = 0x0001
> - id1 = 0x227e
> - id2 = 0x2220
> - id3 = 0x2200
> - unlock_addr0 = 0x555,
> - unlock_addr1 = 0x2aa
> - be = 0 /* Arch specific... */
>
> Which hopefully is very similar to what we currently use :)

'fraid not:

    $ qemu-system-sh4 -M r2d -display none -S -monitor stdio
    QEMU 3.1.50 monitor - type 'help' for more information
    (qemu) info qtree
    [...]
      dev: cfi.pflash02, id ""
        drive = ""
        num-blocks = 512 (0x200)        <--- instead of 256
        sector-length = 16384 (0x4000)  <--- instead of 65536
        width = 4 (0x4)                 <--- instead of 2
        mappings = 1 (0x1)
        big-endian = 0 (0x0)
        id0 = 0 (0x0)                   <--- instead of 0x0001
        id1 = 0 (0x0)                   <--- instead of 0x227e
        id2 = 0 (0x0)                   <--- instead of 0x2220
        id3 = 0 (0x0)                   <--- instead of 0x2200
        unlock-addr0 = 1365 (0x555)
        unlock-addr1 = 682 (0x2aa)
        name = "r2d.flash"              <--- instead of "FROM (Area0)"
        mmio 0000000000000000/0000000000800000

Not shown: size is num-blocks * sector-length = 512 * 16384 = 8MiB
instead of 16MiB.

Which properties would you like me to change, and how?

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-04 15:33                 ` Markus Armbruster
@ 2019-03-05 17:21                   ` Philippe Mathieu-Daudé
  2019-03-05 17:25                     ` Peter Maydell
  2019-03-06 14:11                     ` Markus Armbruster
  0 siblings, 2 replies; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-03-05 17:21 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Magnus Damm, Kevin Wolf, Peter Maydell, Qemu-block,
	Alex Bennée, QEMU Developers, Max Reitz, qemu-ppc,
	Laszlo Ersek

On 3/4/19 4:33 PM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>> On 3/4/19 8:25 AM, Markus Armbruster wrote:
>>> Magnus Damm <magnus.damm@gmail.com> writes:
>>>> On Wed, Feb 20, 2019 at 2:31 AM Markus Armbruster <armbru@redhat.com> wrote:
>>>>> Perhaps Magnus, who maintains the machine, can pick a new value for us.
>>>>
>>>> According to the old board user document in Japanese (under NDA) what
>>>> is referred to as FROM (Area0) is connected via a 32-bit bus and CS0
>>>> to CN8. The docs mention s29pl127j60tfi130 but since I don't have the
>>>> board handy ATM I don't know how the chips are connected.
>>>>
>>>> Hope this helps,
>>>
>>> If you want me to change our emulated flash memory's size, please give
>>> me a number.
>>
>> datasheet "S29PL-J 002-00615 Rev. *E":
>> https://www.cypress.com/file/207091/download
>>
>> The S29PL127J60TFI130 is a 128Mbit NOR pflash addressable in words of 16bit.
>>
>> 128Mbit = 16 MiB
>>
>> At least it matches the "RTS7751R2D Handling Manual"!
>> https://elinux.org/RTS7751R2D_Handling_Manual#Kernel_start_from_FROM_extension_card_.28Kernel_space_XIP.29
>>
>> PL127J:
>> - 4 Banks
>>   -> we don't model banks.
>> - sectors of 4Kw and 32Kw
>>   -> we don't model different sector size and only use the
>>      biggest available
>>
>> sector_size = 32Kw = 64KiB // sector_len
>> (naive) sector_count = 256 // nb_blocs
>>
>> ManufID:  0001h
>> DeviceID: 227Eh 2220h 2200h
>>
>> I understand "connected via a 32-bit bus and CS0 to CN8" as the full
>> device wordsize is addressable, so this device
>>
>> So in pflash_cfi02_register() format:
>>
>> - name = "FROM (Area0)"
>> - size = 16 * MiB
>> - sector_len = 64 * KiB
>> - nb_blocs = 256
>> - nb_mappings = 1? /* Machine specific... */
>> - width = 2
>> - id0 = 0x0001
>> - id1 = 0x227e
>> - id2 = 0x2220
>> - id3 = 0x2200
>> - unlock_addr0 = 0x555,
>> - unlock_addr1 = 0x2aa
>> - be = 0 /* Arch specific... */
>>
>> Which hopefully is very similar to what we currently use :)
> 
> 'fraid not:

I was trying to be sarcastic :/

> 
>     $ qemu-system-sh4 -M r2d -display none -S -monitor stdio
>     QEMU 3.1.50 monitor - type 'help' for more information
>     (qemu) info qtree
>     [...]
>       dev: cfi.pflash02, id ""
>         drive = ""
>         num-blocks = 512 (0x200)        <--- instead of 256
>         sector-length = 16384 (0x4000)  <--- instead of 65536
>         width = 4 (0x4)                 <--- instead of 2
>         mappings = 1 (0x1)
>         big-endian = 0 (0x0)
>         id0 = 0 (0x0)                   <--- instead of 0x0001
>         id1 = 0 (0x0)                   <--- instead of 0x227e
>         id2 = 0 (0x0)                   <--- instead of 0x2220
>         id3 = 0 (0x0)                   <--- instead of 0x2200
>         unlock-addr0 = 1365 (0x555)
>         unlock-addr1 = 682 (0x2aa)
>         name = "r2d.flash"              <--- instead of "FROM (Area0)"
>         mmio 0000000000000000/0000000000800000
> 
> Not shown: size is num-blocks * sector-length = 512 * 16384 = 8MiB
> instead of 16MiB.
> 
> Which properties would you like me to change, and how?

The simpler change for correctness is to fix the FLASH_SIZE:

-#define FLASH_SIZE 0x02000000
+#define FLASH_SIZE (16 * MiB)

+   /*
+    * According to the old board user document in Japanese (under NDA) what
+    * is referred to as FROM (Area0) is connected via a 32-bit bus and CS0
+    * to CN8. The docs mention a Cypress S29PL127J60TFI130 chipsset.
+    * Per the 'S29PL-J 002-00615 Rev. *E' datasheet, it is a 128Mbit NOR
+    * parallel flash addressable in words of 16bit.
+    */
    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
                          dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                         16 * KiB, FLASH_SIZE >> 16,
+                         16 * KiB, FLASH_SIZE >> 14 /* will get removed
later */,
                          1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
                          0x555, 0x2aa, 0);

                          1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
                          0x555, 0x2aa, 0);

Now fixing the sector size:

    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
                          dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                         16 * KiB, FLASH_SIZE >> 16,
-                         1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
+                         64 * KiB, FLASH_SIZE >> 16 /* will get removed
later */,
+                         1, 4, 0x0001, 0x227e, 0x2220, 0x2200
                          0x555, 0x2aa, 0);

But I'd recommend changing/fixing the sector size during the next dev
cycle, so we have more time for testing.

Regards,

Phil.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-05 17:21                   ` Philippe Mathieu-Daudé
@ 2019-03-05 17:25                     ` Peter Maydell
  2019-03-05 21:50                       ` Philippe Mathieu-Daudé
  2019-03-06 14:11                     ` Markus Armbruster
  1 sibling, 1 reply; 97+ messages in thread
From: Peter Maydell @ 2019-03-05 17:25 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Markus Armbruster, Magnus Damm, Kevin Wolf, Qemu-block,
	Alex Bennée, QEMU Developers, Max Reitz, qemu-ppc,
	Laszlo Ersek

On Tue, 5 Mar 2019 at 17:21, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> But I'd recommend changing/fixing the sector size during the next dev
> cycle, so we have more time for testing.

Nobody in the upstream dev community is using or testing this board.
The only way we'll find out if there's a problem with changing the
sector size is to put the change in and get it into a release.
I would vote for just making the change now.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-05 17:25                     ` Peter Maydell
@ 2019-03-05 21:50                       ` Philippe Mathieu-Daudé
  2019-03-06  6:03                         ` Markus Armbruster
  0 siblings, 1 reply; 97+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-03-05 21:50 UTC (permalink / raw)
  To: Peter Maydell, Cleber Rosa
  Cc: Markus Armbruster, Magnus Damm, Kevin Wolf, Qemu-block,
	Alex Bennée, QEMU Developers, Max Reitz, qemu-ppc,
	Laszlo Ersek

On 3/5/19 6:25 PM, Peter Maydell wrote:
> On Tue, 5 Mar 2019 at 17:21, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>> But I'd recommend changing/fixing the sector size during the next dev
>> cycle, so we have more time for testing.
> 
> Nobody in the upstream dev community is using or testing this board.

Well I submitted a Avocado test last year:
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02749.html

And I rebase/run it from time to time.

> The only way we'll find out if there's a problem with changing the
> sector size is to put the change in and get it into a release.
> I would vote for just making the change now.

I'm happy with this vote, and am sure Markus will be too :)

Markus: the last field I wasn't sure about without double checking the
code is the @width one. I find it misleading, is that the size of the
data bus or the size of the flash words? Answer: this is the size of the
words in byte. NOR flash devices can not write less data than their word
boundary.

The S29PL127J60TFI130 only support 16bit words, so using @width=2 is
correct.

And the winner is.... ta-da!

    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
                          dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                         16 * KiB, FLASH_SIZE >> 16,
-                         1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
+                         64 * KiB, FLASH_SIZE >> 16 /* will get removed
later */,
+                         1, 2, 0x0001, 0x227e, 0x2220, 0x2200
                          0x555, 0x2aa, 0);

> 
> thanks
> -- PMM

Thanks for your support!

Phil.

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-05 21:50                       ` Philippe Mathieu-Daudé
@ 2019-03-06  6:03                         ` Markus Armbruster
  0 siblings, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-03-06  6:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Cleber Rosa, Kevin Wolf, Qemu-block, Laszlo Ersek,
	Magnus Damm, QEMU Developers, qemu-ppc, Max Reitz,
	Alex Bennée

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 3/5/19 6:25 PM, Peter Maydell wrote:
>> On Tue, 5 Mar 2019 at 17:21, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>> But I'd recommend changing/fixing the sector size during the next dev
>>> cycle, so we have more time for testing.
>> 
>> Nobody in the upstream dev community is using or testing this board.
>
> Well I submitted a Avocado test last year:
> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02749.html
>
> And I rebase/run it from time to time.
>
>> The only way we'll find out if there's a problem with changing the
>> sector size is to put the change in and get it into a release.
>> I would vote for just making the change now.
>
> I'm happy with this vote, and am sure Markus will be too :)
>
> Markus: the last field I wasn't sure about without double checking the
> code is the @width one. I find it misleading, is that the size of the
> data bus or the size of the flash words? Answer: this is the size of the
> words in byte. NOR flash devices can not write less data than their word
> boundary.
>
> The S29PL127J60TFI130 only support 16bit words, so using @width=2 is
> correct.
>
> And the winner is.... ta-da!
>
>     pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
>                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
> -                         16 * KiB, FLASH_SIZE >> 16,
> -                         1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
> +                         64 * KiB, FLASH_SIZE >> 16 /* will get removed
> later */,
> +                         1, 2, 0x0001, 0x227e, 0x2220, 0x2200
>                           0x555, 0x2aa, 0);

Sold!

[...]

^ permalink raw reply	[flat|nested] 97+ messages in thread

* Re: [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME
  2019-03-05 17:21                   ` Philippe Mathieu-Daudé
  2019-03-05 17:25                     ` Peter Maydell
@ 2019-03-06 14:11                     ` Markus Armbruster
  1 sibling, 0 replies; 97+ messages in thread
From: Markus Armbruster @ 2019-03-06 14:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Qemu-block, Laszlo Ersek, Magnus Damm,
	QEMU Developers, Max Reitz, qemu-ppc, Alex Bennée

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 3/4/19 4:33 PM, Markus Armbruster wrote:
>> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>>> On 3/4/19 8:25 AM, Markus Armbruster wrote:
>>>> Magnus Damm <magnus.damm@gmail.com> writes:
>>>>> On Wed, Feb 20, 2019 at 2:31 AM Markus Armbruster <armbru@redhat.com> wrote:
>>>>>> Perhaps Magnus, who maintains the machine, can pick a new value for us.
>>>>>
>>>>> According to the old board user document in Japanese (under NDA) what
>>>>> is referred to as FROM (Area0) is connected via a 32-bit bus and CS0
>>>>> to CN8. The docs mention s29pl127j60tfi130 but since I don't have the
>>>>> board handy ATM I don't know how the chips are connected.
>>>>>
>>>>> Hope this helps,
>>>>
>>>> If you want me to change our emulated flash memory's size, please give
>>>> me a number.
>>>
>>> datasheet "S29PL-J 002-00615 Rev. *E":
>>> https://www.cypress.com/file/207091/download
>>>
>>> The S29PL127J60TFI130 is a 128Mbit NOR pflash addressable in words of 16bit.
>>>
>>> 128Mbit = 16 MiB
>>>
>>> At least it matches the "RTS7751R2D Handling Manual"!
>>> https://elinux.org/RTS7751R2D_Handling_Manual#Kernel_start_from_FROM_extension_card_.28Kernel_space_XIP.29
>>>
>>> PL127J:
>>> - 4 Banks
>>>   -> we don't model banks.
>>> - sectors of 4Kw and 32Kw
>>>   -> we don't model different sector size and only use the
>>>      biggest available
>>>
>>> sector_size = 32Kw = 64KiB // sector_len
>>> (naive) sector_count = 256 // nb_blocs
>>>
>>> ManufID:  0001h
>>> DeviceID: 227Eh 2220h 2200h
>>>
>>> I understand "connected via a 32-bit bus and CS0 to CN8" as the full
>>> device wordsize is addressable, so this device
>>>
>>> So in pflash_cfi02_register() format:
>>>
>>> - name = "FROM (Area0)"
>>> - size = 16 * MiB
>>> - sector_len = 64 * KiB
>>> - nb_blocs = 256
>>> - nb_mappings = 1? /* Machine specific... */
>>> - width = 2
>>> - id0 = 0x0001
>>> - id1 = 0x227e
>>> - id2 = 0x2220
>>> - id3 = 0x2200
>>> - unlock_addr0 = 0x555,
>>> - unlock_addr1 = 0x2aa
>>> - be = 0 /* Arch specific... */
>>>
>>> Which hopefully is very similar to what we currently use :)
>> 
>> 'fraid not:
>
> I was trying to be sarcastic :/

And I fell for it, should've known better %-}

^ permalink raw reply	[flat|nested] 97+ messages in thread

end of thread, other threads:[~2019-03-06 14:11 UTC | newest]

Thread overview: 97+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-18 12:56 [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups Markus Armbruster
2019-02-18 12:56 ` [Qemu-devel] [PATCH 01/10] pflash: Rename pflash_t to PFlashCFI01, PFlashCFI02 Markus Armbruster
2019-02-18 16:40   ` Laszlo Ersek
2019-02-19 12:49   ` Philippe Mathieu-Daudé
2019-02-19 13:41     ` Markus Armbruster
2019-02-19 14:33       ` Philippe Mathieu-Daudé
2019-02-21  9:15         ` Markus Armbruster
2019-02-21 16:41           ` Philippe Mathieu-Daudé
2019-02-21 15:07   ` Alex Bennée
2019-02-18 12:56 ` [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand Markus Armbruster
2019-02-18 16:43   ` Laszlo Ersek
2019-02-18 17:35     ` Markus Armbruster
2019-02-19 12:40   ` Philippe Mathieu-Daudé
2019-02-19 13:11     ` Peter Maydell
2019-02-19 13:46       ` Markus Armbruster
2019-02-21  9:22         ` Markus Armbruster
2019-02-21  9:38           ` Peter Maydell
2019-02-21 12:07             ` Laszlo Ersek
2019-02-21 12:38               ` Peter Maydell
2019-02-21 12:46                 ` Laszlo Ersek
2019-02-21 16:39                   ` Philippe Mathieu-Daudé
2019-02-21 16:55                     ` Laszlo Ersek
2019-02-21 16:19             ` Philippe Mathieu-Daudé
2019-02-21 17:03               ` Markus Armbruster
2019-02-21 18:50                 ` Alex Bennée
2019-02-22  7:17               ` Markus Armbruster
2019-02-21 15:08           ` Alex Bennée
2019-02-18 12:56 ` [Qemu-devel] [PATCH 03/10] hw: Use CFI_PFLASH0{1, 2} and TYPE_CFI_PFLASH0{1, 2} Markus Armbruster
2019-02-18 16:45   ` Laszlo Ersek
2019-02-19 12:41   ` Philippe Mathieu-Daudé
2019-02-21 15:09   ` Alex Bennée
2019-02-18 12:56 ` [Qemu-devel] [PATCH 04/10] sam460ex: Don't size flash memory to match backing image Markus Armbruster
2019-02-18 16:36   ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
2019-02-18 17:57     ` Markus Armbruster
2019-02-19  1:19       ` BALATON Zoltan
2019-02-19  5:43         ` Markus Armbruster
2019-02-19 11:34           ` BALATON Zoltan
2019-02-18 12:56 ` [Qemu-devel] [PATCH 05/10] ppc405_boards: " Markus Armbruster
2019-02-19  3:55   ` David Gibson
2019-02-19 15:28   ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
2019-02-19 15:55     ` Markus Armbruster
2019-02-21 15:20   ` [Qemu-devel] " Alex Bennée
2019-02-21 16:31     ` Markus Armbruster
2019-02-21 22:18       ` David Gibson
2019-02-22  7:23         ` Markus Armbruster
2019-02-18 12:56 ` [Qemu-devel] [PATCH 06/10] r2d: Flash memory creation is confused about size, mark FIXME Markus Armbruster
2019-02-19 14:03   ` Peter Maydell
2019-02-19 15:45     ` Markus Armbruster
2019-02-19 15:53       ` Philippe Mathieu-Daudé
2019-02-19 17:30         ` Markus Armbruster
2019-03-04  4:57           ` Magnus Damm
2019-03-04  7:25             ` Markus Armbruster
2019-03-04 11:43               ` Philippe Mathieu-Daudé
2019-03-04 15:33                 ` Markus Armbruster
2019-03-05 17:21                   ` Philippe Mathieu-Daudé
2019-03-05 17:25                     ` Peter Maydell
2019-03-05 21:50                       ` Philippe Mathieu-Daudé
2019-03-06  6:03                         ` Markus Armbruster
2019-03-06 14:11                     ` Markus Armbruster
2019-02-19 16:02   ` Philippe Mathieu-Daudé
2019-02-19 16:21     ` Peter Maydell
2019-02-19 17:53       ` Markus Armbruster
2019-02-19 18:11         ` Peter Maydell
2019-02-18 12:56 ` [Qemu-devel] [PATCH 07/10] mips_malta: Clean up definition of flash memory size somewhat Markus Armbruster
2019-02-19 13:02   ` Philippe Mathieu-Daudé
2019-02-19 13:43     ` Markus Armbruster
2019-02-19 16:10       ` Philippe Mathieu-Daudé
2019-02-21 15:27   ` Alex Bennée
2019-02-18 12:56 ` [Qemu-devel] [PATCH 08/10] pflash: Clean up after commit 368a354f02b part 1 Markus Armbruster
2019-02-18 16:50   ` Laszlo Ersek
2019-02-19 16:12   ` Philippe Mathieu-Daudé
2019-02-21 15:57   ` Alex Bennée
2019-02-18 12:56 ` [Qemu-devel] [PATCH 09/10] pflash: Clean up after commit 368a354f02b part 2 Markus Armbruster
2019-02-18 17:01   ` Laszlo Ersek
2019-02-18 17:56     ` Laszlo Ersek
2019-02-19  5:44       ` Markus Armbruster
2019-02-21 16:51   ` Alex Bennée
2019-02-21 17:18     ` Markus Armbruster
2019-02-21 17:36       ` BALATON Zoltan
2019-02-21 18:18         ` Markus Armbruster
2019-02-18 12:56 ` [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some Markus Armbruster
2019-02-18 17:12   ` Laszlo Ersek
2019-02-19  8:43   ` Max Filippov
2019-02-19 13:01     ` Markus Armbruster
2019-02-19 14:13   ` Peter Maydell
2019-02-19 15:46     ` Markus Armbruster
2019-02-18 13:31 ` [Qemu-devel] [PATCH 00/10] pflash: Fixes and cleanups no-reply
2019-02-18 17:16 ` no-reply
2019-02-18 17:39 ` no-reply
2019-02-19  4:39 ` no-reply
2019-02-19  4:43 ` no-reply
2019-02-19 13:06 ` no-reply
2019-02-19 13:49 ` no-reply
2019-02-19 13:53 ` no-reply
2019-02-19 16:43 ` no-reply
2019-02-27 15:26 ` no-reply
2019-02-27 17:41 ` no-reply

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.