Skip to contentSkip to conversation

pflash_cfi01/pflash_cfi02: convert to memory API

PATCH In review Avi Kivity 2 participants 16 messages Aug 28, 2011 – Aug 29, 2011

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 pflash_cfi01/pflash_cfi02: convert to memory API

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

---

This is a rework of the pflash conversion to the memory API. It has changed significantly - the change in allocation described above - so please review carefully.

The mips_malta change also changes behavious - previously on of the two aliases was mapped as rom/device while the other was mapped as plain rom. Now both aliases are mapped as rom/device. I'm guessing that this is the right behaviour, and the old behaviour was just an implementation limitation, but if someone can check, that would be even better. That file has the most sensitive changes so please review it extra carefully.

 hw/collie.c                   |    7 +--
 hw/flash.h                    |   11 ++++-
 hw/gumstix.c                  |    6 +--
 hw/lm32_boards.c              |    8 +---
 hw/mainstone.c                |    7 +--
 hw/milkymist.c                |    4 +-
 hw/mips_malta.c               |   44 +++++++++++++------
 hw/mips_r4k.c                 |   13 +++---
 hw/musicpal.c                 |    8 ++--
 hw/omap_sx1.c                 |    8 ++--
 hw/petalogix_ml605_mmu.c      |    5 +-
 hw/petalogix_s3adsp1800_mmu.c |    5 +-
 hw/pflash_cfi01.c             |   73 ++++++++++++-------------------
 hw/pflash_cfi02.c             |   95 +++++++++++++++++++++--------------------
 hw/ppc405_boards.c            |   49 ++++++++++++---------
 hw/r2d.c                      |    2 +-
 hw/virtex_ml507.c             |    4 +-
 hw/z2.c                       |    2 +-
 18 files changed, 174 insertions(+), 177 deletions(-)
hw/collie.c +2 -5
index 156404d..a10cc1b 100644
@@ -26,7 +26,6 @@ static void collie_init(ram_addr_t ram_size,
 {
     StrongARMState *s;
     DriveInfo *dinfo;
-    ram_addr_t phys_flash;
 
     if (!cpu_model) {
         cpu_model = "sa1110";
@@ -34,15 +33,13 @@ static void collie_init(ram_addr_t ram_size,
 
     s = sa1110_init(collie_binfo.ram_size, cpu_model);
 
-    phys_flash = qemu_ram_alloc(NULL, "collie.fl1", 0x02000000);
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi01_register(SA_CS0, phys_flash,
+    pflash_cfi01_register(SA_CS0, NULL, "collie.fl1", 0x02000000,
                     dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                     512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
-    phys_flash = qemu_ram_alloc(NULL, "collie.fl2", 0x02000000);
     dinfo = drive_get(IF_PFLASH, 0, 1);
-    pflash_cfi01_register(SA_CS1, phys_flash,
+    pflash_cfi01_register(SA_CS1, NULL, "collie.fl2", 0x02000000,
                     dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                     512, 4, 0x00, 0x00, 0x00, 0x00, 0);
 
hw/flash.h +9 -2
index 140ae39..f92f58a 100644
@@ -1,15 +1,22 @@
 /* NOR flash devices */
+
+#include "memory.h"
+
 typedef struct pflash_t pflash_t;
 
 /* pflash_cfi01.c */
-pflash_t *pflash_cfi01_register(target_phys_addr_t base, ram_addr_t off,
+pflash_t *pflash_cfi01_register(target_phys_addr_t base,
+                                DeviceState *qdev, const char *name,
+                                target_phys_addr_t size,
                                 BlockDriverState *bs,
                                 uint32_t sector_len, int nb_blocs, int width,
                                 uint16_t id0, uint16_t id1,
                                 uint16_t id2, uint16_t id3, int be);
 
 /* pflash_cfi02.c */
-pflash_t *pflash_cfi02_register(target_phys_addr_t base, ram_addr_t off,
+pflash_t *pflash_cfi02_register(target_phys_addr_t base,
+                                DeviceState *qdev, const char *name,
+                                target_phys_addr_t size,
                                 BlockDriverState *bs, uint32_t sector_len,
                                 int nb_blocs, int nb_mappings, int width,
                                 uint16_t id0, uint16_t id1,
hw/gumstix.c +2 -4
index 853f7e1..b8b76f4 100644
@@ -67,8 +67,7 @@ static void connex_init(ram_addr_t ram_size,
 #else
     be = 0;
 #endif
-    if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(NULL, "connext.rom",
-                                                          connex_rom),
+    if (!pflash_cfi01_register(0x00000000, NULL, "connext.rom", connex_rom,
                                dinfo->bdrv, sector_len, connex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
@@ -106,8 +105,7 @@ static void verdex_init(ram_addr_t ram_size,
 #else
     be = 0;
 #endif
-    if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(NULL, "verdex.rom",
-                                                          verdex_rom),
+    if (!pflash_cfi01_register(0x00000000, NULL, "verdex.rom", verdex_rom,
                                dinfo->bdrv, sector_len, verdex_rom / sector_len,
                                2, 0, 0, 0, 0, be)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
hw/lm32_boards.c +2 -6
index d18aad7..e4acac1 100644
@@ -77,7 +77,6 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,
     CPUState *env;
     DriveInfo *dinfo;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
     qemu_irq *cpu_irq, irq[32];
     ResetInfo *reset_info;
     int i;
@@ -108,10 +107,9 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,
     phys_ram = qemu_ram_alloc(NULL, "lm32_evr.sdram", ram_size);
     cpu_register_physical_memory(ram_base, ram_size, phys_ram | IO_MEM_RAM);
 
-    phys_flash = qemu_ram_alloc(NULL, "lm32_evr.flash", flash_size);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
-    pflash_cfi02_register(flash_base, phys_flash,
+    pflash_cfi02_register(flash_base, NULL, "lm32_evr.flash", flash_size,
                           dinfo ? dinfo->bdrv : NULL, flash_sector_size,
                           flash_size / flash_sector_size, 1, 2,
                           0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
@@ -165,7 +163,6 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used,
     CPUState *env;
     DriveInfo *dinfo;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
     qemu_irq *cpu_irq, irq[32];
     HWSetup *hw;
     ResetInfo *reset_info;
@@ -203,10 +200,9 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used,
     phys_ram = qemu_ram_alloc(NULL, "lm32_uclinux.sdram", ram_size);
     cpu_register_physical_memory(ram_base, ram_size, phys_ram | IO_MEM_RAM);
 
-    phys_flash = qemu_ram_alloc(NULL, "lm32_uclinux.flash", flash_size);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
-    pflash_cfi02_register(flash_base, phys_flash,
+    pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
                           dinfo ? dinfo->bdrv : NULL, flash_sector_size,
                           flash_size / flash_sector_size, 1, 2,
                           0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
hw/mainstone.c +3 -4
index 4792f0e..c0524d7 100644
@@ -126,10 +126,9 @@ static void mainstone_common_init(ram_addr_t ram_size,
             exit(1);
         }
 
-        if (!pflash_cfi01_register(mainstone_flash_base[i],
-                                   qemu_ram_alloc(NULL, i ? "mainstone.flash1" :
-                                                  "mainstone.flash0",
-                                                  MAINSTONE_FLASH),
+        if (!pflash_cfi01_register(mainstone_flash_base[i], NULL,
+                                   i ? "mainstone.flash1" : "mainstone.flash0",
+                                   MAINSTONE_FLASH,
                                    dinfo->bdrv, sector_len,
                                    MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0,
                                    be)) {
hw/milkymist.c +1 -3
index 93288c8..a44b80c 100644
@@ -82,7 +82,6 @@ milkymist_init(ram_addr_t ram_size_not_used,
     int kernel_size;
     DriveInfo *dinfo;
     ram_addr_t phys_sdram;
-    ram_addr_t phys_flash;
     qemu_irq irq[32], *cpu_irq;
     int i;
     char *bios_filename;
@@ -113,10 +112,9 @@ milkymist_init(ram_addr_t ram_size_not_used,
     cpu_register_physical_memory(sdram_base, sdram_size,
             phys_sdram | IO_MEM_RAM);
 
-    phys_flash = qemu_ram_alloc(NULL, "milkymist.flash", flash_size);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Numonyx JS28F256J3F105 */
-    pflash_cfi01_register(flash_base, phys_flash,
+    pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
                           dinfo ? dinfo->bdrv : NULL, flash_sector_size,
                           flash_size / flash_sector_size, 2,
                           0x00, 0x89, 0x00, 0x1d, 1);
hw/mips_malta.c +30 -14

97 lines not on this page · raw message

hw/mips_r4k.c +7 -6
index 9d90568..5d002c5 100644
@@ -23,6 +23,7 @@
 #include "elf.h"
 #include "mc146818rtc.h"
 #include "blockdev.h"
+#include "exec-memory.h"
 
 #define MAX_IDE_BUS 2
 
@@ -163,7 +164,7 @@ void mips_r4k_init (ram_addr_t ram_size,
 {
     char *filename;
     ram_addr_t ram_offset;
-    ram_addr_t bios_offset;
+    MemoryRegion *bios;
     int bios_size;
     CPUState *env;
     ResetData *reset_info;
@@ -227,15 +228,15 @@ void mips_r4k_init (ram_addr_t ram_size,
     be = 0;
 #endif
     if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) {
-        bios_offset = qemu_ram_alloc(NULL, "mips_r4k.bios", BIOS_SIZE);
-	cpu_register_physical_memory(0x1fc00000, BIOS_SIZE,
-                                     bios_offset | IO_MEM_ROM);
+        bios = g_new(MemoryRegion, 1);
+        memory_region_init_ram(bios, NULL, "mips_r4k.bios", BIOS_SIZE);
+        memory_region_set_readonly(bios, true);
+        memory_region_add_subregion(get_system_memory(), 0x1fc00000, bios);
 
         load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
     } else if ((dinfo = drive_get(IF_PFLASH, 0, 0)) != NULL) {
         uint32_t mips_rom = 0x00400000;
-        bios_offset = qemu_ram_alloc(NULL, "mips_r4k.bios", mips_rom);
-        if (!pflash_cfi01_register(0x1fc00000, bios_offset,
+        if (!pflash_cfi01_register(0x1fc00000, NULL, "mips_r4k.bios", mips_rom,
                                    dinfo->bdrv, sector_len,
                                    mips_rom / sector_len,
                                    4, 0, 0, 0, 0, be)) {
hw/musicpal.c +4 -4
index 63dd391..ade5a91 100644
@@ -1565,16 +1565,16 @@ static void musicpal_init(ram_addr_t ram_size,
          * image is smaller than 32 MB.
          */
 #ifdef TARGET_WORDS_BIGENDIAN
-        pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(NULL,
-                              "musicpal.flash", flash_size),
+        pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, NULL,
+                              "musicpal.flash", flash_size,
                               dinfo->bdrv, 0x10000,
                               (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 1);
 #else
-        pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(NULL,
-                              "musicpal.flash", flash_size),
+        pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, NULL,
+                              "musicpal.flash", flash_size,
                               dinfo->bdrv, 0x10000,
                               (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
hw/omap_sx1.c +4 -4
index a7b687b..15cfbb5 100644
@@ -161,8 +161,8 @@ static void sx1_init(ram_addr_t ram_size,
 #endif
 
     if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
-        if (!pflash_cfi01_register(OMAP_CS0_BASE, qemu_ram_alloc(NULL,
-                                   "omap_sx1.flash0-1", flash_size),
+        if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
+                                   "omap_sx1.flash0-1", flash_size,
                                    dinfo->bdrv, sector_size,
                                    flash_size / sector_size,
                                    4, 0, 0, 0, 0, be)) {
@@ -182,8 +182,8 @@ static void sx1_init(ram_addr_t ram_size,
         cpu_register_physical_memory(OMAP_CS1_BASE + flash1_size,
                         OMAP_CS1_SIZE - flash1_size, io);
 
-        if (!pflash_cfi01_register(OMAP_CS1_BASE, qemu_ram_alloc(NULL,
-                                   "omap_sx1.flash1-1", flash1_size),
+        if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
+                                   "omap_sx1.flash1-1", flash1_size,
                                    dinfo->bdrv, sector_size,
                                    flash1_size / sector_size,
                                    4, 0, 0, 0, 0, be)) {
hw/petalogix_ml605_mmu.c +2 -3
index e3ca310..38db521 100644
@@ -149,7 +149,6 @@ petalogix_ml605_init(ram_addr_t ram_size,
     target_phys_addr_t ddr_base = MEMORY_BASEADDR;
     ram_addr_t phys_lmb_bram;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
     qemu_irq irq[32], *cpu_irq;
 
     /* init CPUs */
@@ -169,11 +168,11 @@ petalogix_ml605_init(ram_addr_t ram_size,
     phys_ram = qemu_ram_alloc(NULL, "petalogix_ml605.ram", ram_size);
     cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM);
 
-    phys_flash = qemu_ram_alloc(NULL, "petalogix_ml605.flash", FLASH_SIZE);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* 5th parameter 2 means bank-width
      * 10th paremeter 0 means little-endian */
-    pflash_cfi01_register(FLASH_BASEADDR, phys_flash,
+    pflash_cfi01_register(FLASH_BASEADDR,
+                          NULL, "petalogix_ml605.flash", FLASH_SIZE,
                           dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                           FLASH_SIZE >> 16,
                           2, 0x89, 0x18, 0x0000, 0x0, 0);
hw/petalogix_s3adsp1800_mmu.c +2 -3
index a43fb4c..66fb96d 100644
@@ -127,7 +127,6 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size,
     target_phys_addr_t ddr_base = 0x90000000;
     ram_addr_t phys_lmb_bram;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
     qemu_irq irq[32], *cpu_irq;
 
     /* init CPUs */
@@ -148,9 +147,9 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size,
     phys_ram = qemu_ram_alloc(NULL, "petalogix_s3adsp1800.ram", ram_size);
     cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM);
 
-    phys_flash = qemu_ram_alloc(NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE);
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi01_register(0xa0000000, phys_flash,
+    pflash_cfi01_register(0xa0000000,
+                          NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE,
                           dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                           FLASH_SIZE >> 16,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
hw/pflash_cfi01.c +28 -45

132 lines not on this page · raw message

hw/pflash_cfi02.c +48 -47

146 lines not on this page · raw message

hw/ppc405_boards.c +27 -22

126 lines not on this page · raw message

hw/r2d.c +1 -1
index 96a7ff8..ed0c586 100644
@@ -267,7 +267,7 @@ static void r2d_init(ram_addr_t ram_size,
 
     /* onboard flash memory */
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi02_register(0x0, qemu_ram_alloc(NULL, "r2d.flash", FLASH_SIZE),
+    pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
                           dinfo ? dinfo->bdrv : NULL, (16 * 1024),
                           FLASH_SIZE >> 16,
                           1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
hw/virtex_ml507.c +1 -3
index 333050c..7459b0b 100644
@@ -196,7 +196,6 @@ static void virtex_init(ram_addr_t ram_size,
     target_phys_addr_t ram_base = 0;
     DriveInfo *dinfo;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
     qemu_irq irq[32], *cpu_irq;
     clk_setup_t clk_setup[7];
     int kernel_size;
@@ -215,9 +214,8 @@ static void virtex_init(ram_addr_t ram_size,
     phys_ram = qemu_ram_alloc(NULL, "ram", ram_size);
     cpu_register_physical_memory(ram_base, ram_size, phys_ram | IO_MEM_RAM);
 
-    phys_flash = qemu_ram_alloc(NULL, "virtex.flash", FLASH_SIZE);
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi01_register(0xfc000000, phys_flash,
+    pflash_cfi01_register(0xfc000000, NULL, "virtex.flash", FLASH_SIZE,
                           dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                           FLASH_SIZE >> 16,
                           1, 0x89, 0x18, 0x0000, 0x0, 1);
hw/z2.c +1 -1
index f93a1bf..b6ae608 100644
@@ -305,7 +305,7 @@ static void z2_init(ram_addr_t ram_size,
     }
 
     if (!pflash_cfi01_register(Z2_FLASH_BASE,
-                               qemu_ram_alloc(NULL, "z2.flash0", Z2_FLASH_SIZE),
+                               NULL, "z2.flash0", Z2_FLASH_SIZE,
                                dinfo->bdrv, sector_len,
                                Z2_FLASH_SIZE / sector_len, 4, 0, 0, 0, 0,
                                be)) {
Signature · 1 line
1.7.6.1
#1 lore raw
Quoted 14 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

---

This is a rework of the pflash conversion to the memory API. It has changed significantly - the change in allocation described above - so please review carefully.

Quoted 6 lines

The mips_malta change also changes behavious - previously on of the two aliases was mapped as rom/device while the other was mapped as plain rom. Now both aliases are mapped as rom/device. I'm guessing that this is the right behaviour, and the old behaviour was just an implementation limitation, but if someone can check, that would be even better. That file has the most sensitive changes so please review it extra carefully.

Regarding the flash mapping, your description matches my understanding of it. There is a difference between the 0x1fc and the 0x1e0 mappings though, in that reading from 0x1fc00010 does not map to the flash but instead gets decoded into a read from a revision register. To read from the flash at 0x10, you need to go via the 0x1e0 mapping.

That was never modelled by QEMU, instead the malta board writes into the backing ram of the flash area, see:
/* Board ID = 0x420 (Malta Board with CoreLV)
XXX: theoretically 0x1e000010 should map to flash and 0x1fc00010 should map to the board ID. */
stl_p(memory_region_get_ram_ptr(bios) + 0x10, 0x00000420);

I assume this will continue to work even after your changes but it would be good to test it. I can check it.

A problem, with my compiler I see this:
qemu/hw/mips_malta.c: In function ‘mips_malta_init’:
qemu/hw/mips_malta.c:860:37: error: ‘bios’ may be used uninitialized in this function [-Werror=uninitialized]

Cheers

#2 lore raw

On Sun, Aug 28, 2011 at 8:14 PM, Edgar E. Iglesias <[email protected]

Quoted 43 lines

wrote:

Quoted 11 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

---

This is a rework of the pflash conversion to the memory API. It has

changed

Quoted 1 line

significantly - the change in allocation described above - so please

review

Quoted 6 lines

carefully.

The mips_malta change also changes behavious - previously on of the two aliases was mapped as rom/device while the other was mapped as plain rom. Now both aliases are mapped as rom/device. I'm guessing that this is the right behaviour, and the old behaviour was just an implementation

limitation,

Quoted 1 line

but if someone can check, that would be even better. That file has the

most

Quoted 1 line

sensitive changes so please review it extra carefully.

Regarding the flash mapping, your description matches my understanding of it.
There is a difference between the 0x1fc and the 0x1e0 mappings though, in that
reading from 0x1fc00010 does not map to the flash but instead gets decoded into a read from a revision register. To read from the flash at 0x10, you need to go via the 0x1e0 mapping.

That was never modelled by QEMU, instead the malta board writes into the backing ram of the flash area, see:
/* Board ID = 0x420 (Malta Board with CoreLV)
XXX: theoretically 0x1e000010 should map to flash and 0x1fc00010 should map to the board ID. */
stl_p(memory_region_get_ram_ptr(bios) + 0x10, 0x00000420);

Quoted 3 lines

I assume this will continue to work even after your changes but it would be good to test it. I can check it.

The 0x10 hack still works as expected.

Cheers

author
#3 lore raw
In reply to Edgar E. Iglesias
Quoted 28 lines · Edgar E. Iglesias
Quoted 14 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

---

This is a rework of the pflash conversion to the memory API. It has changed significantly - the change in allocation described above - so please review carefully.

Quoted 6 lines

The mips_malta change also changes behavious - previously on of the two aliases was mapped as rom/device while the other was mapped as plain rom. Now both aliases are mapped as rom/device. I'm guessing that this is the right behaviour, and the old behaviour was just an implementation limitation, but if someone can check, that would be even better. That file has the most sensitive changes so please review it extra carefully.

Regarding the flash mapping, your description matches my understanding of it. There is a difference between the 0x1fc and the 0x1e0 mappings though, in that reading from 0x1fc00010 does not map to the flash but instead gets decoded into a read from a revision register. To read from the flash at 0x10, you need to go via the 0x1e0 mapping.

Quoted 6 lines

That was never modelled by QEMU, instead the malta board writes into the backing ram of the flash area, see:
/* Board ID = 0x420 (Malta Board with CoreLV)
XXX: theoretically 0x1e000010 should map to flash and 0x1fc00010 should map to the board ID. */
stl_p(memory_region_get_ram_ptr(bios) + 0x10, 0x00000420);

This can be modelled correctly, using a container and a new region for 0x10-0x14. I'll live that as an exercise to the interested writer.

Quoted 7 lines

I assume this will continue to work even after your changes but it would be good to test it. I can check it.

A problem, with my compiler I see this:
qemu/hw/mips_malta.c: In function ‘mips_malta_init’:
qemu/hw/mips_malta.c:860:37: error: ‘bios’ may be used uninitialized in this function [-Werror=uninitialized]

Thanks, I have a fix for this and will post an updated patch once the other issues are resolved.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#4 lore raw
In reply to Avi Kivity
Quoted 6 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

Hi Avi,

Something is going wrong with the flash devices. It can be reproduced
with the microblaze image on the wiki, you'll see the kernel complain
with:
pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0) of-flash a0000000.flash: do_map_probe() failed

When it should be saying:
a0000000.flash: Found 1 x8 devices at 0x0 in 8-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000 Intel/Sharp Extended Query Table at 0x0031

Cheers

author
#5 lore raw
Quoted 16 lines · Edgar E. Iglesias
Quoted 6 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

Hi Avi,

Something is going wrong with the flash devices. It can be reproduced
with the microblaze image on the wiki, you'll see the kernel complain
with:
pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0) of-flash a0000000.flash: do_map_probe() failed

Quoted 5 lines

When it should be saying:
a0000000.flash: Found 1 x8 devices at 0x0 in 8-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000 Intel/Sharp Extended Query Table at 0x0031

I get exactly the same behaviour with upstream - 9f94778. With what version does it work correctly?

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#6 lore raw
Quoted 17 lines · Avi Kivity
Quoted 16 lines · Edgar E. Iglesias
Quoted 6 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

Hi Avi,

Something is going wrong with the flash devices. It can be reproduced
with the microblaze image on the wiki, you'll see the kernel complain
with:
pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0) of-flash a0000000.flash: do_map_probe() failed

Quoted 8 lines
Quoted 5 lines

When it should be saying:
a0000000.flash: Found 1 x8 devices at 0x0 in 8-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000 Intel/Sharp Extended Query Table at 0x0031

I get exactly the same behaviour with upstream - 9f94778. With what version does it work correctly?

Im on a slightly patched tree, will try clean upstream versions. Maybe the flashes never worked with that board in upstream... :/

Cheers

#7 lore raw
In reply to Avi Kivity
Quoted 17 lines · Avi Kivity
Quoted 16 lines · Edgar E. Iglesias
Quoted 6 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

Hi Avi,

Something is going wrong with the flash devices. It can be reproduced
with the microblaze image on the wiki, you'll see the kernel complain
with:
pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0) of-flash a0000000.flash: do_map_probe() failed

Quoted 8 lines
Quoted 5 lines

When it should be saying:
a0000000.flash: Found 1 x8 devices at 0x0 in 8-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000 Intel/Sharp Extended Query Table at 0x0031

I get exactly the same behaviour with upstream - 9f94778. With what version does it work correctly?

With:
commit 9f94778c1603420e48d779a495e84eb82945cc75

Author: Artyom Tarasenko <[email protected]>
Date:   Mon Jul 25 19:22:38 2011 +0200

Fix disabling interrupts in sun4u

clear interrupt request if the interrupt priority < CPU pil clear hardware interrupt request if interrupts are disabled

[[email protected]: added a comment about magic 2]

It works, with some qemu complaints about non uinmplemented sequences, but the flashes are found.

pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0)

[    0.596261] a0000000.flash: Found 1 x8 devices at 0x0 in 8-bit bank
[    0.597003]  Intel/Sharp Extended Query Table at 0x0031

pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0)

With GDB I see pflash_read, beeing called.

With, the latest patches applied:

commit f38f0030afddba4c9df42bdb25ce123c41aafeb6

Author: Avi Kivity <[email protected]>
Date:   Sun Aug 28 18:43:36 2011 +0300

pflash_cfi01/pflash_cfi02: convert to memory API

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

commit 6f997f56903060383ddc7672c33fc3d40dfd9cb9
Merge: 9f94778 75f5941
Author: Edgar E. Iglesias <[email protected]>
Date: Sun Aug 28 19:29:16 2011 +0200

Merge branch 'memory/core' of git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm

I see the following:
pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0)

[    0.605584] of-flash a0000000.flash: do_map_probe() failed

The flash is never found.

And, pflash_read is never called.

The set_readable doesnt seem to bite..

Hope this helps..

Cheers

#8 lore raw
In reply to Avi Kivity
Quoted 45 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

---

hw/pflash_cfi01.c +3 -4
index 90e1301..b597304 100644
@@ -40,6 +40,7 @@
 #include "flash.h"
 #include "block.h"
 #include "qemu-timer.h"
+#include "exec-memory.h"
 
 #define PFLASH_BUG(fmt, ...) \
 do { \
@@ -74,8 +75,7 @@ struct pflash_t {
     target_phys_addr_t counter;
     unsigned int writeblock_size;
     QEMUTimer *timer;
-    ram_addr_t off;
-    int fl_mem;
+    MemoryRegion mem;
     void *storage;
 };
 
@@ -89,8 +89,7 @@ static void pflash_timer (void *opaque)
     if (pfl->bypass) {
         pfl->wcycle = 2;
     } else {
-        cpu_register_physical_memory(pfl->base, pfl->total_len,
-                        pfl->off | IO_MEM_ROMD | pfl->fl_mem);
+        memory_region_rom_device_set_readable(&pfl->mem, true);
         pfl->wcycle = 0;
     }
     pfl->cmd = 0;

hw/pflash_cfi01.c static void pflash_write(pflash_t *pfl, target_phys_addr_t offset, · line 266

Quoted 6 lines
hw/pflash_cfi01.c +1 -1
@@ -263,7 +262,7 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,
 
     if (!pfl->wcycle) {
         /* Set the device in I/O access mode */
-        cpu_register_physical_memory(pfl->base, pfl->total_len, pfl->fl_mem);
+        memory_region_rom_device_set_readable(&pfl->mem, false);
     }

I get the impression that this one is not biting. Reads are not reaching the IO callbacks at times when they should..

Cheers

author
#9 lore raw
Quoted 47 lines · Edgar E. Iglesias
Quoted 46 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

---

diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c index 90e1301..b597304 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/pflash_cfi01.c
@@ -40,6 +40,7 @@
#include "flash.h"
#include "block.h"
#include "qemu-timer.h"
+#include "exec-memory.h"

#define PFLASH_BUG(fmt, ...) \
do { \

 @@ -74,8 +75,7 @@ struct pflash_t {
      target_phys_addr_t counter;
      unsigned int writeblock_size;
      QEMUTimer *timer;
 -    ram_addr_t off;
 -    int fl_mem;
 +    MemoryRegion mem;
      void *storage;

};

@@ -89,8 +89,7 @@ static void pflash_timer (void *opaque)

      if (pfl->bypass) {
          pfl->wcycle = 2;
      } else {
 -        cpu_register_physical_memory(pfl->base, pfl->total_len,
 -                        pfl->off | IO_MEM_ROMD | pfl->fl_mem);
 +        memory_region_rom_device_set_readable(&pfl->mem, true);
          pfl->wcycle = 0;
      }
      pfl->cmd = 0;

@@ -263,7 +262,7 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,

Quoted 9 lines
Quoted 5 lines
      if (!pfl->wcycle) {
          /* Set the device in I/O access mode */
 -        cpu_register_physical_memory(pfl->base, pfl->total_len, pfl->fl_mem);
 +        memory_region_rom_device_set_readable(&pfl->mem, false);
      }

I get the impression that this one is not biting. Reads are not reaching the IO callbacks at times when they should..

It does bite, as I saw with gdb. You can even see that from the qemu error - it complains about unimplemented command 0xf0, that comes from pflash_write() later on.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#10 lore raw
Quoted 54 lines · Avi Kivity
Quoted 53 lines · Edgar E. Iglesias
Quoted 51 lines · Avi Kivity

cfi02 is annoying in that is ignores some address bits; we probably want explicit support in the memory API for that.

In order to get the correct opaque into the MemoryRegion object, the allocation scheme is changed so that the flash emulation code allocates memory, instead of the caller. This clears a FIXME in the flash code.

---

diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c index 90e1301..b597304 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/pflash_cfi01.c
@@ -40,6 +40,7 @@
#include "flash.h"
#include "block.h"
#include "qemu-timer.h"
+#include "exec-memory.h"

#define PFLASH_BUG(fmt, ...) \
do { \

 @@ -74,8 +75,7 @@ struct pflash_t {
      target_phys_addr_t counter;
      unsigned int writeblock_size;
      QEMUTimer *timer;
 -    ram_addr_t off;
 -    int fl_mem;
 +    MemoryRegion mem;
      void *storage;

};

@@ -89,8 +89,7 @@ static void pflash_timer (void *opaque)

      if (pfl->bypass) {
          pfl->wcycle = 2;
      } else {
 -        cpu_register_physical_memory(pfl->base, pfl->total_len,
 -                        pfl->off | IO_MEM_ROMD | pfl->fl_mem);
 +        memory_region_rom_device_set_readable(&pfl->mem, true);
          pfl->wcycle = 0;
      }
      pfl->cmd = 0;

@@ -263,7 +262,7 @@ static void pflash_write(pflash_t *pfl, target_phys_addr_t offset,

      if (!pfl->wcycle) {
          /* Set the device in I/O access mode */
 -        cpu_register_physical_memory(pfl->base, pfl->total_len, pfl->fl_mem);
 +        memory_region_rom_device_set_readable(&pfl->mem, false);
      }
Quoted 7 lines
Quoted 3 lines

I get the impression that this one is not biting. Reads are not reaching the IO callbacks at times when they should..

It does bite, as I saw with gdb. You can even see that from the qemu error - it complains about unimplemented command 0xf0, that comes from pflash_write() later on.

I wasn't clear enough maybe, the code in question is running, but the set_readble is not having any effect AFAICT. The reads, that should come through via IO callbacks when switching mode are not getting through. Do you ever see pflash_read beeing called?

Cheers

author
#11 lore raw
Quoted 10 lines · Edgar E. Iglesias
Quoted 4 lines

It does bite, as I saw with gdb. You can even see that from the qemu error - it complains about unimplemented command 0xf0, that comes from pflash_write() later on.

I wasn't clear enough maybe, the code in question is running, but the set_readble is not having any effect AFAICT. The reads, that should come through via IO callbacks when switching mode are not getting through. Do you ever see pflash_read beeing called?

Thanks for the clarification. I don't, and there is now a fix on

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git

Please check it out.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#12 lore raw
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Edgar E. Iglesias
Quoted 4 lines

It does bite, as I saw with gdb. You can even see that from the qemu error - it complains about unimplemented command 0xf0, that comes from pflash_write() later on.

I wasn't clear enough maybe, the code in question is running, but the set_readble is not having any effect AFAICT. The reads, that should come through via IO callbacks when switching mode are not getting through. Do you ever see pflash_read beeing called?

Quoted 5 lines

Thanks for the clarification. I don't, and there is now a fix on

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git

Please check it out.

Great, have to run now, but I'll try it out later today.

Cheers

author
#13 lore raw
In reply to Avi Kivity
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Edgar E. Iglesias
Quoted 4 lines

It does bite, as I saw with gdb. You can even see that from the qemu error - it complains about unimplemented command 0xf0, that comes from pflash_write() later on.

I wasn't clear enough maybe, the code in question is running, but the set_readble is not having any effect AFAICT. The reads, that should come through via IO callbacks when switching mode are not getting through. Do you ever see pflash_read beeing called?

Quoted 4 lines

Thanks for the clarification. I don't, and there is now a fix on

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git

Forgot the branch:

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git fix-pflash

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#14 lore raw
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Edgar E. Iglesias
Quoted 4 lines

It does bite, as I saw with gdb. You can even see that from the qemu error - it complains about unimplemented command 0xf0, that comes from pflash_write() later on.

I wasn't clear enough maybe, the code in question is running, but the set_readble is not having any effect AFAICT. The reads, that should come through via IO callbacks when switching mode are not getting through. Do you ever see pflash_read beeing called?

Quoted 8 lines
Quoted 4 lines

Thanks for the clarification. I don't, and there is now a fix on

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git

Forgot the branch:

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git fix-pflash

That works

Thanks

author
#15 lore raw
Quoted 8 lines · Edgar E. Iglesias
Quoted 4 lines

Forgot the branch:

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git fix-pflash

That works

Thanks for all the testing and help. I'll post the fixes for merging soon.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.