Skip to contentSkip to conversation

Memory API conversions, batch 5

PATCH Superseded Avi Kivity 2 participants 38 messages Aug 24, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

cover Memory API conversions, batch 5

This is a collection of random conversions to devices to the new memory API. Some qemu interfaces are also update, for example machine creation and sysbus.

Please review. If all is fine, I will post a [PULL] request for the batch (in git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory/batch).

Avi Kivity (24):
arm_sysctl: convert to memory API
stellaris_enet: convert to memory API
sysbus: add helpers to add and delete memory regions to the system
bus
pci_host: convert conf index and data ports to memory API
ReadWriteHandler: remove
QEMUMachine: pass address space to machine init function
an5206: convert to memory API
armv7m: convert to memory API
axis_dev88: convert to memory API (RAM only)
sysbus: add sysbus_add_memory_overlap()
integratorcp: convert to memory API (RAM/flash only)
leon3: convert to memory API
cirrus: wrap memory update in a transaction
piix_pci: wrap memory update in a transaction Makefile.hw: allow hw/ files to include glib headers pflash_cfi01/pflash_cfi02: convert to memory API
dummy_m68k: convert to memory API
g364fb: convert to memory API
lm32_boards: convert to memory API
mainstone: convert to memory API
mcf5208: convert to memory API
milkymist-minimac2: convert to memory API
milkymist-softusb: convert to memory API
milkymist: convert to memory API

 Makefile.hw                   |    1 +
 Makefile.target               |    1 -
 hw/an5206.c                   |   16 +++++--
 hw/arm-misc.h                 |    5 ++-
 hw/arm_sysctl.c               |    1 +
 hw/armv7m.c                   |   24 ++++++----
 hw/axis_dev88.c               |   20 +++++----
 hw/boards.h                   |    5 ++-
 hw/cirrus_vga.c               |    2 +
 hw/collie.c                   |   21 ++++++---
 hw/dec_pci.c                  |   13 +++---
 hw/dummy_m68k.c               |   10 +++-
 hw/flash.h                    |   16 +++++--
 hw/g364fb.c                   |   61 +++++++++++++++------------
 hw/grackle_pci.c              |   13 +++---
 hw/gumstix.c                  |   37 ++++++++++------
 hw/integratorcp.c             |   32 ++++++++++----
 hw/leon3.c                    |   20 ++++++---
 hw/lm32_boards.c              |   35 +++++++++------
 hw/mainstone.c                |   37 +++++++++------
 hw/mcf5208.c                  |   75 +++++++++++++++------------------
 hw/milkymist-minimac2.c       |   43 +++++++++---------
 hw/milkymist-softusb.c        |   48 ++++++++++----------
 hw/milkymist.c                |   20 +++++---
 hw/mips.h                     |    4 +-
 hw/mips_fulong2e.c            |    4 +-
 hw/mips_jazz.c                |   11 +++-
 hw/mips_malta.c               |   48 ++++++++++++---------
 hw/mips_mipssim.c             |    4 +-
 hw/mips_r4k.c                 |   23 ++++++----
 hw/musicpal.c                 |   20 ++++++---
 hw/nseries.c                  |   18 ++++++--
 hw/omap_sx1.c                 |   30 ++++++++-----
 hw/palm.c                     |    4 +-
 hw/pc_piix.c                  |   31 +++++++++-----
 hw/pci_host.c                 |   86 ++++++++++++++++---------------------
 hw/pci_host.h                 |   16 +++----
 hw/petalogix_ml605_mmu.c      |   12 +++--
 hw/petalogix_s3adsp1800_mmu.c |   13 ++++--
 hw/pflash_cfi01.c             |   67 ++++++++++-------------------
 hw/pflash_cfi02.c             |   95 ++++++++++++++++++++---------------------
 hw/piix_pci.c                 |   13 +++++-
 hw/ppc405_boards.c            |   69 +++++++++++++++++-------------
 hw/ppc440_bamboo.c            |    4 +-
 hw/ppc4xx_pci.c               |   10 +++--
 hw/ppc_newworld.c             |    4 +-
 hw/ppc_oldworld.c             |    4 +-
 hw/ppc_prep.c                 |    4 +-
 hw/ppce500_mpc8544ds.c        |    4 +-
 hw/ppce500_pci.c              |   21 ++++-----
 hw/prep_pci.c                 |   12 ++++-
 hw/r2d.c                      |   12 ++++-
 hw/realview.c                 |   33 ++++++++++----
 hw/s390-virtio.c              |    4 +-
 hw/shix.c                     |    4 +-
 hw/spitz.c                    |   32 ++++++++++----
 hw/stellaris.c                |   21 ++++++---
 hw/stellaris_enet.c           |   29 +++++-------
 hw/sun4m.c                    |   48 +++++++++++++++-----
 hw/sun4u.c                    |   12 ++++-
 hw/syborg.c                   |    4 +-
 hw/sysbus.c                   |   28 ++++++++++++
 hw/sysbus.h                   |    8 +++
 hw/tosa.c                     |    4 +-
 hw/unin_pci.c                 |   82 ++++++++++++++++++------------------
 hw/versatilepb.c              |   19 ++++++--
 hw/vexpress.c                 |    4 +-
 hw/virtex_ml507.c             |   12 +++--
 hw/xen_machine_pv.c           |    4 +-
 hw/z2.c                       |   20 +++++---
 rwhandler.c                   |   87 -------------------------------------
 rwhandler.h                   |   27 ------------
 vl.c                          |    3 +-
 73 files changed, 924 insertions(+), 760 deletions(-)
 delete mode 100644 rwhandler.c
 delete mode 100644 rwhandler.h
Signature · 1 line
1.7.5.3
author
#1 lore raw

PATCH 1/24 arm_sysctl: convert to memory API

---
 hw/arm_sysctl.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/arm_sysctl.c +1 -0
index 17cf6f7..5b845a2 100644
@@ -19,6 +19,7 @@ typedef struct {
     SysBusDevice busdev;
     MemoryRegion iomem;
     qemu_irq pl110_mux_ctrl;
+    MemoryRegion iomem;
 
     uint32_t sys_id;
     uint32_t leds;
Signature · 1 line
1.7.5.3
#2 lore raw

Re: [Qemu-devel] [PATCH 01/24] arm_sysctl: convert to memory API

Quoted 10 lines · Avi Kivity

---
 hw/arm_sysctl.c |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
hw/arm_sysctl.c +0 -0
index 17cf6f7..5b845a2 100644

hw/arm_sysctl.c typedef struct { · line 25

Quoted 7 lines
hw/arm_sysctl.c +1 -0
@@ -19,6 +19,7 @@ typedef struct {
     SysBusDevice busdev;
     MemoryRegion iomem;
     qemu_irq pl110_mux_ctrl;
+    MemoryRegion iomem;
 
     uint32_t sys_id;
     uint32_t leds;

Er, looks like you forgot to squish Richard's compile fix patch?

-- PMM

author
#3 lore raw

Re: [Qemu-devel] [PATCH 01/24] arm_sysctl: convert to memory API

Quoted 16 lines · Peter Maydell
Quoted 15 lines · Avi Kivity

---

   hw/arm_sysctl.c |    1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/hw/arm_sysctl.c b/hw/arm_sysctl.c
index 17cf6f7..5b845a2 100644
--- a/hw/arm_sysctl.c
+++ b/hw/arm_sysctl.c

 @@ -19,6 +19,7 @@ typedef struct {
      SysBusDevice busdev;
      MemoryRegion iomem;
      qemu_irq pl110_mux_ctrl;

+ MemoryRegion iomem;

Quoted 5 lines
Quoted 2 lines
      uint32_t sys_id;
      uint32_t leds;

Er, looks like you forgot to squish Richard's compile fix patch?

Not applied yet; will fix.

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

PATCH 2/24 stellaris_enet: convert to memory API

In reply to Avi Kivity
---
 hw/stellaris_enet.c |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)
hw/stellaris_enet.c +12 -17
index f9bd3da..d5613ff 100644
@@ -69,7 +69,7 @@ typedef struct {
     NICState *nic;
     NICConf conf;
     qemu_irq irq;
-    int mmio_index;
+    MemoryRegion mmio;
 } stellaris_enet_state;
 
 static void stellaris_enet_update(stellaris_enet_state *s)
@@ -130,7 +130,8 @@ static int stellaris_enet_can_receive(VLANClientState *nc)
     return (s->np < 31);
 }
 
-static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset)
+static uint64_t stellaris_enet_read(void *opaque, target_phys_addr_t offset,
+                                    unsigned size)
 {
     stellaris_enet_state *s = (stellaris_enet_state *)opaque;
     uint32_t val;
@@ -198,7 +199,7 @@ static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset)
 }
 
 static void stellaris_enet_write(void *opaque, target_phys_addr_t offset,
-                        uint32_t value)
+                                 uint64_t value, unsigned size)
 {
     stellaris_enet_state *s = (stellaris_enet_state *)opaque;
 
@@ -303,17 +304,12 @@ static void stellaris_enet_write(void *opaque, target_phys_addr_t offset,
     }
 }
 
-static CPUReadMemoryFunc * const stellaris_enet_readfn[] = {
-   stellaris_enet_read,
-   stellaris_enet_read,
-   stellaris_enet_read
+static const MemoryRegionOps stellaris_enet_ops = {
+    .read = stellaris_enet_read,
+    .write = stellaris_enet_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static CPUWriteMemoryFunc * const stellaris_enet_writefn[] = {
-   stellaris_enet_write,
-   stellaris_enet_write,
-   stellaris_enet_write
-};
 static void stellaris_enet_reset(stellaris_enet_state *s)
 {
     s->mdv = 0x80;
@@ -391,7 +387,7 @@ static void stellaris_enet_cleanup(VLANClientState *nc)
 
     unregister_savevm(&s->busdev.qdev, "stellaris_enet", s);
 
-    cpu_unregister_io_memory(s->mmio_index);
+    memory_region_destroy(&s->mmio);
 
     g_free(s);
 }
@@ -408,10 +404,9 @@ static int stellaris_enet_init(SysBusDevice *dev)
 {
     stellaris_enet_state *s = FROM_SYSBUS(stellaris_enet_state, dev);
 
-    s->mmio_index = cpu_register_io_memory(stellaris_enet_readfn,
-                                           stellaris_enet_writefn, s,
-                                           DEVICE_NATIVE_ENDIAN);
-    sysbus_init_mmio(dev, 0x1000, s->mmio_index);
+    memory_region_init_io(&s->mmio, &stellaris_enet_ops, s, "stellaris_enet",
+                          0x1000);
+    sysbus_init_mmio_region(dev, &s->mmio);
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
Signature · 1 line
1.7.5.3
author
#5 lore raw

PATCH 3/24 sysbus: add helpers to add and delete memory regions to the system bus

In reply to Avi Kivity
---
 hw/sysbus.c |   22 ++++++++++++++++++++++
 hw/sysbus.h |    6 ++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
hw/sysbus.c +22 -0
index f39768b..f5f0ed2 100644
@@ -256,3 +256,25 @@ static char *sysbus_get_fw_dev_path(DeviceState *dev)
 
     return strdup(path);
 }
+
+void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
+                       MemoryRegion *mem)
+{
+    memory_region_add_subregion(get_system_memory(), addr, mem);
+}
+
+void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem)
+{
+    memory_region_del_subregion(get_system_memory(), mem);
+}
+
+void sysbus_add_io(SysBusDevice *dev, target_phys_addr_t addr,
+                       MemoryRegion *mem)
+{
+    memory_region_add_subregion(get_system_io(), addr, mem);
+}
+
+void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem)
+{
+    memory_region_del_subregion(get_system_io(), mem);
+}
hw/sysbus.h +6 -0
index b87c6c5..e4d56cf 100644
@@ -57,6 +57,12 @@ void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
 
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
 void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
+void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
+                       MemoryRegion *mem);
+void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
+void sysbus_add_io(SysBusDevice *dev, target_phys_addr_t addr,
+                   MemoryRegion *mem);
+void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
 
 /* Legacy helper function for creating devices.  */
 DeviceState *sysbus_create_varargs(const char *name,
Signature · 1 line
1.7.5.3
author
#6 lore raw

PATCH 4/24 pci_host: convert conf index and data ports to memory API

In reply to Avi Kivity
---
 hw/dec_pci.c     |   13 ++++----
 hw/grackle_pci.c |   13 ++++----
 hw/pci_host.c    |   86 ++++++++++++++++++++++++------------------------------
 hw/pci_host.h    |   16 ++++------
 hw/piix_pci.c    |   11 +++++-
 hw/ppc4xx_pci.c  |   10 ++++--
 hw/ppce500_pci.c |   21 ++++++-------
 hw/prep_pci.c    |   12 +++++--
 hw/unin_pci.c    |   82 +++++++++++++++++++++++++-------------------------
 9 files changed, 131 insertions(+), 133 deletions(-)
hw/dec_pci.c +6 -7
index a35f382..1aec066 100644
@@ -80,16 +80,15 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
 static int pci_dec_21154_init_device(SysBusDevice *dev)
 {
     DECState *s;
-    int pci_mem_config, pci_mem_data;
 
     s = FROM_SYSBUS(DECState, dev);
 
-    pci_mem_config = pci_host_conf_register_mmio(&s->host_state,
-                                                 DEVICE_LITTLE_ENDIAN);
-    pci_mem_data = pci_host_data_register_mmio(&s->host_state,
-                                               DEVICE_LITTLE_ENDIAN);
-    sysbus_init_mmio(dev, 0x1000, pci_mem_config);
-    sysbus_init_mmio(dev, 0x1000, pci_mem_data);
+    memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops,
+                          &s->host_state, "pci-conf-idx", 0x1000);
+    memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops,
+                          &s->host_state, "pci-data-idx", 0x1000);
+    sysbus_init_mmio_region(dev, &s->host_state.conf_mem);
+    sysbus_init_mmio_region(dev, &s->host_state.data_mem);
     return 0;
 }
 
hw/grackle_pci.c +6 -7
index 9a823e1..9d3ff7d 100644
@@ -92,16 +92,15 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic,
 static int pci_grackle_init_device(SysBusDevice *dev)
 {
     GrackleState *s;
-    int pci_mem_config, pci_mem_data;
 
     s = FROM_SYSBUS(GrackleState, dev);
 
-    pci_mem_config = pci_host_conf_register_mmio(&s->host_state,
-                                                 DEVICE_LITTLE_ENDIAN);
-    pci_mem_data = pci_host_data_register_mmio(&s->host_state,
-                                               DEVICE_LITTLE_ENDIAN);
-    sysbus_init_mmio(dev, 0x1000, pci_mem_config);
-    sysbus_init_mmio(dev, 0x1000, pci_mem_data);
+    memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops,
+                          &s->host_state, "pci-conf-idx", 0x1000);
+    memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops,
+                          &s->host_state, "pci-data-idx", 0x1000);
+    sysbus_init_mmio_region(dev, &s->host_state.conf_mem);
+    sysbus_init_mmio_region(dev, &s->host_state.data_mem);
 
     qemu_register_reset(pci_grackle_reset, &s->host_state);
     return 0;
hw/pci_host.c +38 -48

120 lines not on this page · raw message

hw/pci_host.h +6 -10
index 7f55114..0211086 100644
@@ -29,12 +29,11 @@
 #define PCI_HOST_H
 
 #include "sysbus.h"
-#include "rwhandler.h"
 
 struct PCIHostState {
     SysBusDevice busdev;
-    ReadWriteHandler conf_handler;
-    ReadWriteHandler data_handler;
+    MemoryRegion conf_mem;
+    MemoryRegion data_mem;
     MemoryRegion *address_space;
     uint32_t config_reg;
     PCIBus *bus;
@@ -49,12 +48,9 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr,
 void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len);
 uint32_t pci_data_read(PCIBus *s, uint32_t addr, int len);
 
-/* for mmio */
-int pci_host_conf_register_mmio(PCIHostState *s, int endian);
-int pci_host_data_register_mmio(PCIHostState *s, int endian);
-
-/* for ioio */
-void pci_host_conf_register_ioport(pio_addr_t ioport, PCIHostState *s);
-void pci_host_data_register_ioport(pio_addr_t ioport, PCIHostState *s);
+extern const MemoryRegionOps pci_host_conf_le_ops;
+extern const MemoryRegionOps pci_host_conf_be_ops;
+extern const MemoryRegionOps pci_host_data_le_ops;
+extern const MemoryRegionOps pci_host_data_be_ops;
 
 #endif /* PCI_HOST_H */
hw/piix_pci.c +9 -2
index c563c6e..f892994 100644
@@ -235,9 +235,16 @@ static int i440fx_pcihost_initfn(SysBusDevice *dev)
 {
     I440FXState *s = FROM_SYSBUS(I440FXState, dev);
 
-    pci_host_conf_register_ioport(0xcf8, s);
+    memory_region_init_io(&s->conf_mem, &pci_host_conf_le_ops, s,
+                          "pci-conf-idx", 4);
+    sysbus_add_io(dev, 0xcf8, &s->conf_mem);
+    sysbus_init_ioports(&s->busdev, 0xcf8, 4);
+
+    memory_region_init_io(&s->data_mem, &pci_host_data_le_ops, s,
+                          "pci-conf-data", 4);
+    sysbus_add_io(dev, 0xcfc, &s->data_mem);
+    sysbus_init_ioports(&s->busdev, 0xcfc, 4);
 
-    pci_host_data_register_ioport(0xcfc, s);
     return 0;
 }
 
hw/ppc4xx_pci.c +6 -4
index 52e2663..339b38e 100644
@@ -368,10 +368,12 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],
     cpu_register_physical_memory(config_space + PCIC0_CFGADDR, 4, index);
 
     /* CFGDATA */
-    index = pci_host_data_register_mmio(&controller->pci_state, 1);
-    if (index < 0)
-        goto free;
-    cpu_register_physical_memory(config_space + PCIC0_CFGDATA, 4, index);
+    memory_region_init_io(&controller->pci_state.data_mem,
+                          &pci_host_data_be_ops,
+                          &controller->pci_state, "pci-conf-data", 4);
+    memory_region_add_subregion(get_system_memory(),
+                                config_space + PCIC0_CFGDATA,
+                                &controller->pci_state.data_mem);
 
     /* Internal registers */
     index = cpu_register_io_memory(pci_reg_read, pci_reg_write, controller,
hw/ppce500_pci.c +10 -11
index 4390aeb..2db365d 100644
@@ -79,8 +79,6 @@ struct PPCE500PCIState {
     uint32_t gasket_time;
     qemu_irq irq[4];
     /* mmio maps */
-    int cfgaddr;
-    int cfgdata;
     int reg;
 };
 
@@ -268,18 +266,18 @@ static void e500_pci_map(SysBusDevice *dev, target_phys_addr_t base)
     PCIHostState *h = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
     PPCE500PCIState *s = DO_UPCAST(PPCE500PCIState, pci_state, h);
 
-    cpu_register_physical_memory(base + PCIE500_CFGADDR, 4, s->cfgaddr);
-    cpu_register_physical_memory(base + PCIE500_CFGDATA, 4, s->cfgdata);
+    sysbus_add_memory(dev, base + PCIE500_CFGADDR, &h->conf_mem);
+    sysbus_add_memory(dev, base + PCIE500_CFGDATA, &h->data_mem);
     cpu_register_physical_memory(base + PCIE500_REG_BASE, PCIE500_REG_SIZE,
                                  s->reg);
 }
 
 static void e500_pci_unmap(SysBusDevice *dev, target_phys_addr_t base)
 {
-    cpu_register_physical_memory(base + PCIE500_CFGADDR, 4,
-                                 IO_MEM_UNASSIGNED);
-    cpu_register_physical_memory(base + PCIE500_CFGDATA, 4,
-                                 IO_MEM_UNASSIGNED);
+    PCIHostState *h = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
+
+    sysbus_del_memory(dev, &h->conf_mem);
+    sysbus_del_memory(dev, &h->data_mem);
     cpu_register_physical_memory(base + PCIE500_REG_BASE, PCIE500_REG_SIZE,
                                  IO_MEM_UNASSIGNED);
 }
@@ -309,9 +307,10 @@ static int e500_pcihost_initfn(SysBusDevice *dev)
 
     pci_create_simple(b, 0, "e500-host-bridge");
 
-    s->cfgaddr = pci_host_conf_register_mmio(&s->pci_state, DEVICE_BIG_ENDIAN);
-    s->cfgdata = pci_host_data_register_mmio(&s->pci_state,
-                                             DEVICE_LITTLE_ENDIAN);
+    memory_region_init_io(&h->conf_mem, &pci_host_conf_be_ops, h,
+                          "pci-conf-idx", 4);
+    memory_region_init_io(&h->data_mem, &pci_host_data_le_ops, h,
+                          "pci-conf-data", 4);
     s->reg = cpu_register_io_memory(e500_pci_reg_read, e500_pci_reg_write, s,
                                     DEVICE_BIG_ENDIAN);
     sysbus_init_mmio_cb2(dev, e500_pci_map, e500_pci_unmap);
hw/prep_pci.c +9 -3
index c36232a..55e4e25 100644
@@ -125,9 +125,15 @@ PCIBus *pci_prep_init(qemu_irq *pic,
                               address_space_io,
                               0, 4);
 
-    pci_host_conf_register_ioport(0xcf8, s);
-
-    pci_host_data_register_ioport(0xcfc, s);
+    memory_region_init_io(&s->conf_mem, &pci_host_conf_be_ops, s,
+                          "pci-conf-idx", 1);
+    memory_region_add_subregion(address_space_io, 0xcf8, &s->conf_mem);
+    sysbus_init_ioports(&s->busdev, 0xcf8, 1);
+
+    memory_region_init_io(&s->conf_mem, &pci_host_data_be_ops, s,
+                          "pci-conf-data", 1);
+    memory_region_add_subregion(address_space_io, 0xcfc, &s->data_mem);
+    sysbus_init_ioports(&s->busdev, 0xcfc, 1);
 
     PPC_io_memory = cpu_register_io_memory(PPC_PCIIO_read,
                                            PPC_PCIIO_write, s,
hw/unin_pci.c +41 -41

149 lines not on this page · raw message

Signature · 1 line
1.7.5.3
author
#7 lore raw

PATCH 5/24 ReadWriteHandler: remove

In reply to Avi Kivity

No longer used.

---
 Makefile.target |    1 -
 rwhandler.c     |   87 -------------------------------------------------------
 rwhandler.h     |   27 -----------------
 3 files changed, 0 insertions(+), 115 deletions(-)
 delete mode 100644 rwhandler.c
 delete mode 100644 rwhandler.h
Makefile.target +0 -1
index e280bf6..c9957ae 100644
@@ -195,7 +195,6 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o virt
 obj-y += vhost_net.o
 obj-$(CONFIG_VHOST_NET) += vhost.o
 obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
-obj-y += rwhandler.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
 obj-y += memory.o
rwhandler.c deleted +0 -87

87 lines not on this page · raw message

rwhandler.h deleted +0 -27
deleted file mode 100644
index b2a5790..0000000
@@ -1,27 +0,0 @@
-#ifndef READ_WRITE_HANDLER_H
-#define READ_WRITE_HANDLER_H
-
-#include "qemu-common.h"
-#include "ioport.h"
-
-typedef struct ReadWriteHandler ReadWriteHandler;
-
-/* len is guaranteed to be one of 1, 2 or 4, addr is guaranteed to fit in an
- * appropriate type (io/memory/etc). They do not need to be range checked. */
-typedef void WriteHandlerFunc(ReadWriteHandler *, pcibus_t addr,
-                              uint32_t value, int len);
-typedef uint32_t ReadHandlerFunc(ReadWriteHandler *, pcibus_t addr, int len);
-
-struct ReadWriteHandler {
-    WriteHandlerFunc *write;
-    ReadHandlerFunc *read;
-};
-
-/* Helpers for when we want to use a single routine with length. */
-/* CPU memory handler: both read and write must be present. */
-int cpu_register_io_memory_simple(ReadWriteHandler *, int endian);
-/* io port handler: can supply only read or write handlers. */
-int register_ioport_simple(ReadWriteHandler *,
-                           pio_addr_t start, int length, int size);
-
-#endif
Signature · 1 line
1.7.5.3
author
#8 lore raw

PATCH 6/24 QEMUMachine: pass address space to machine init function

In reply to Avi Kivity

Avoids get_system_memory() everywhere.

---
 hw/an5206.c                   |    4 ++-
 hw/axis_dev88.c               |    4 ++-
 hw/boards.h                   |    5 +++-
 hw/collie.c                   |    4 ++-
 hw/dummy_m68k.c               |    4 ++-
 hw/gumstix.c                  |    8 +++++-
 hw/integratorcp.c             |    4 ++-
 hw/leon3.c                    |    4 ++-
 hw/lm32_boards.c              |    8 +++++-
 hw/mainstone.c                |    4 ++-
 hw/mcf5208.c                  |    4 ++-
 hw/milkymist.c                |    5 +++-
 hw/mips_fulong2e.c            |    4 ++-
 hw/mips_jazz.c                |    8 +++++-
 hw/mips_malta.c               |    4 ++-
 hw/mips_mipssim.c             |    4 ++-
 hw/mips_r4k.c                 |    4 ++-
 hw/musicpal.c                 |    4 ++-
 hw/nseries.c                  |   18 +++++++++++----
 hw/omap_sx1.c                 |    8 +++++-
 hw/palm.c                     |    4 ++-
 hw/pc_piix.c                  |   31 +++++++++++++++++---------
 hw/petalogix_ml605_mmu.c      |    4 ++-
 hw/petalogix_s3adsp1800_mmu.c |    4 ++-
 hw/ppc405_boards.c            |    8 +++++-
 hw/ppc440_bamboo.c            |    4 ++-
 hw/ppc_newworld.c             |    4 ++-
 hw/ppc_oldworld.c             |    4 ++-
 hw/ppc_prep.c                 |    4 ++-
 hw/ppce500_mpc8544ds.c        |    4 ++-
 hw/r2d.c                      |    4 ++-
 hw/realview.c                 |   33 ++++++++++++++++++++-------
 hw/s390-virtio.c              |    4 ++-
 hw/shix.c                     |    4 ++-
 hw/spitz.c                    |   32 +++++++++++++++++++-------
 hw/stellaris.c                |   18 +++++++++++----
 hw/sun4m.c                    |   48 ++++++++++++++++++++++++++++++----------
 hw/sun4u.c                    |   12 +++++++--
 hw/syborg.c                   |    4 ++-
 hw/tosa.c                     |    4 ++-
 hw/versatilepb.c              |   19 ++++++++++++----
 hw/vexpress.c                 |    4 ++-
 hw/virtex_ml507.c             |    4 ++-
 hw/xen_machine_pv.c           |    4 ++-
 hw/z2.c                       |    4 ++-
 vl.c                          |    3 +-
 46 files changed, 282 insertions(+), 102 deletions(-)
hw/an5206.c +3 -1
index 04ca420..e34de39 100644
@@ -28,7 +28,9 @@ void irq_info(Monitor *mon)
 
 /* Board init.  */
 
-static void an5206_init(ram_addr_t ram_size,
+static void an5206_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
hw/axis_dev88.c +3 -1
index 06200e2..cfc89c2 100644
@@ -244,7 +244,9 @@ static CPUWriteMemoryFunc * const gpio_write[] = {
 static struct cris_load_info li;
 
 static
-void axisdev88_init (ram_addr_t ram_size,
+void axisdev88_init (MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
hw/boards.h +4 -1
index 716fd7b..5c12ce7 100644
@@ -4,8 +4,11 @@
 #define HW_BOARDS_H
 
 #include "qdev.h"
+#include "memory.h"
 
-typedef void QEMUMachineInitFunc(ram_addr_t ram_size,
+typedef void QEMUMachineInitFunc(MemoryRegion *address_space_mem,
+                                 MemoryRegion *address_space_io,
+                                 ram_addr_t ram_size,
                                  const char *boot_device,
                                  const char *kernel_filename,
                                  const char *kernel_cmdline,
hw/collie.c +3 -1
index 156404d..9b724aa 100644
@@ -19,7 +19,9 @@ static struct arm_boot_info collie_binfo = {
     .ram_size = 0x20000000,
 };
 
-static void collie_init(ram_addr_t ram_size,
+static void collie_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
hw/dummy_m68k.c +3 -1
index eed9e38..2de69ad 100644
@@ -15,7 +15,9 @@
 
 /* Board init.  */
 
-static void dummy_m68k_init(ram_addr_t ram_size,
+static void dummy_m68k_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
hw/gumstix.c +6 -2
index 853f7e1..ccdd834 100644
@@ -41,7 +41,9 @@
 
 static const int sector_len = 128 * 1024;
 
-static void connex_init(ram_addr_t ram_size,
+static void connex_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
@@ -80,7 +82,9 @@ static void connex_init(ram_addr_t ram_size,
                     qdev_get_gpio_in(cpu->gpio, 36));
 }
 
-static void verdex_init(ram_addr_t ram_size,
+static void verdex_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
hw/integratorcp.c +3 -1
index 2814108..3d4b339 100644
@@ -450,7 +450,9 @@ static struct arm_boot_info integrator_binfo = {
     .board_id = 0x113,
 };
 
-static void integratorcp_init(ram_addr_t ram_size,
+static void integratorcp_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
hw/leon3.c +3 -1
index a62a941..efe6c7c 100644
@@ -92,7 +92,9 @@ static void leon3_set_pil_in(void *opaque, uint32_t pil_in)
     }
 }
 
-static void leon3_generic_hw_init(ram_addr_t  ram_size,
+static void leon3_generic_hw_init(MemoryRegion *address_space_mem,
+                                  MemoryRegion *address_space_io,
+                                  ram_addr_t  ram_size,
                                   const char *boot_device,
                                   const char *kernel_filename,
                                   const char *kernel_cmdline,
hw/lm32_boards.c +6 -2
index d18aad7..fced5d1 100644
@@ -68,7 +68,9 @@ static void main_cpu_reset(void *opaque)
     env->deba = reset_info->flash_base;
 }
 
-static void lm32_evr_init(ram_addr_t ram_size_not_used,
+static void lm32_evr_init(MemoryRegion *address_space_mem,
+                          MemoryRegion *address_space_io,
+                          ram_addr_t ram_size_not_used,
                           const char *boot_device,
                           const char *kernel_filename,
                           const char *kernel_cmdline,
@@ -156,7 +158,9 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,
     qemu_register_reset(main_cpu_reset, reset_info);
 }
 
-static void lm32_uclinux_init(ram_addr_t ram_size_not_used,
+static void lm32_uclinux_init(MemoryRegion *address_space_mem,
+                          MemoryRegion *address_space_io,
+                          ram_addr_t ram_size_not_used,
                           const char *boot_device,
                           const char *kernel_filename,
                           const char *kernel_cmdline,
hw/mainstone.c +3 -1
index 4792f0e..227f6f8 100644
@@ -165,7 +165,9 @@ static void mainstone_common_init(ram_addr_t ram_size,
     arm_load_kernel(cpu->env, &mainstone_binfo);
 }
 
-static void mainstone_init(ram_addr_t ram_size,
+static void mainstone_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
hw/mcf5208.c +3 -1
index 8fe507f..f4d4fbd 100644
@@ -197,7 +197,9 @@ static void mcf5208_sys_init(qemu_irq *pic)
     }
 }
 
-static void mcf5208evb_init(ram_addr_t ram_size,
+static void mcf5208evb_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
hw/milkymist.c +4 -1
index 93288c8..e599917 100644
@@ -29,6 +29,7 @@
 #include "blockdev.h"
 #include "milkymist-hw.h"
 #include "lm32.h"
+#include "memory.h"
 
 #define BIOS_FILENAME    "mmone-bios.bin"
 #define BIOS_OFFSET      0x00860000
@@ -72,7 +73,9 @@ static void main_cpu_reset(void *opaque)
 }
 
 static void
-milkymist_init(ram_addr_t ram_size_not_used,
+milkymist_init(MemoryRegion *address_space_mem,
+                          MemoryRegion *address_space_io,
+                          ram_addr_t ram_size_not_used,
                           const char *boot_device,
                           const char *kernel_filename,
                           const char *kernel_cmdline,
hw/mips_fulong2e.c +3 -1
index ec8c88e..8cd25ed 100644
@@ -251,7 +251,9 @@ static void cpu_request_exit(void *opaque, int irq, int level)
     }
 }
 
-static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
+static void mips_fulong2e_init(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size, const char *boot_device,
                         const char *kernel_filename, const char *kernel_cmdline,
                         const char *initrd_filename, const char *cpu_model)
 {
hw/mips_jazz.c +6 -2
index 84ce061..d6fb82a 100644
@@ -281,7 +281,9 @@ void mips_jazz_init (ram_addr_t ram_size,
 }
 
 static
-void mips_magnum_init (ram_addr_t ram_size,
+void mips_magnum_init (MemoryRegion *address_space_mem,
+                       MemoryRegion *address_space_io,
+                       ram_addr_t ram_size,
                        const char *boot_device,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
@@ -290,7 +292,9 @@ void mips_magnum_init (ram_addr_t ram_size,
 }
 
 static
-void mips_pica61_init (ram_addr_t ram_size,
+void mips_pica61_init (MemoryRegion *address_space_mem,
+                       MemoryRegion *address_space_io,
+                       ram_addr_t ram_size,
                        const char *boot_device,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
hw/mips_malta.c +3 -1
index 86a8ba0..ceb6254 100644
@@ -755,7 +755,9 @@ static void cpu_request_exit(void *opaque, int irq, int level)
 }
 
 static
-void mips_malta_init (ram_addr_t ram_size,
+void mips_malta_init (MemoryRegion *address_space_mem,
+                      MemoryRegion *address_space_io,
+                      ram_addr_t ram_size,
                       const char *boot_device,
                       const char *kernel_filename, const char *kernel_cmdline,
                       const char *initrd_filename, const char *cpu_model)
hw/mips_mipssim.c +3 -1
index 0d46cc4..67e115b 100644
@@ -113,7 +113,9 @@ static void main_cpu_reset(void *opaque)
 }
 
 static void
-mips_mipssim_init (ram_addr_t ram_size,
+mips_mipssim_init (MemoryRegion *address_space_mem,
+                   MemoryRegion *address_space_io,
+                   ram_addr_t ram_size,
                    const char *boot_device,
                    const char *kernel_filename, const char *kernel_cmdline,
                    const char *initrd_filename, const char *cpu_model)
hw/mips_r4k.c +3 -1
index 9d90568..7a07bcd 100644
@@ -156,7 +156,9 @@ static void main_cpu_reset(void *opaque)
 
 static const int sector_len = 32 * 1024;
 static
-void mips_r4k_init (ram_addr_t ram_size,
+void mips_r4k_init (MemoryRegion *address_space_mem,
+                    MemoryRegion *address_space_io,
+                    ram_addr_t ram_size,
                     const char *boot_device,
                     const char *kernel_filename, const char *kernel_cmdline,
                     const char *initrd_filename, const char *cpu_model)
hw/musicpal.c +3 -1
index 63dd391..becd579 100644
@@ -1483,7 +1483,9 @@ static struct arm_boot_info musicpal_binfo = {
     .board_id = 0x20e,
 };
 
-static void musicpal_init(ram_addr_t ram_size,
+static void musicpal_init(MemoryRegion *address_space_mem,
+               MemoryRegion *address_space_io,
+               ram_addr_t ram_size,
                const char *boot_device,
                const char *kernel_filename, const char *kernel_cmdline,
                const char *initrd_filename, const char *cpu_model)
hw/nseries.c +13 -5
index f7aae7a..ec695ec 100644
@@ -1266,7 +1266,9 @@ static int n810_atag_setup(const struct arm_boot_info *info, void *p)
     return n8x0_atag_setup(p, 810);
 }
 
-static void n8x0_init(ram_addr_t ram_size, const char *boot_device,
+static void n8x0_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size, const char *boot_device,
                 const char *kernel_filename,
                 const char *kernel_cmdline, const char *initrd_filename,
                 const char *cpu_model, struct arm_boot_info *binfo, int model)
@@ -1378,22 +1380,28 @@ static struct arm_boot_info n810_binfo = {
     .atag_board = n810_atag_setup,
 };
 
-static void n800_init(ram_addr_t ram_size,
+static void n800_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
-    return n8x0_init(ram_size, boot_device,
+    return n8x0_init(address_space_mem, address_space_io,
+                    ram_size, boot_device,
                     kernel_filename, kernel_cmdline, initrd_filename,
                     cpu_model, &n800_binfo, 800);
 }
 
-static void n810_init(ram_addr_t ram_size,
+static void n810_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
-    return n8x0_init(ram_size, boot_device,
+    return n8x0_init(address_space_mem, address_space_io,
+                    ram_size, boot_device,
                     kernel_filename, kernel_cmdline, initrd_filename,
                     cpu_model, &n810_binfo, 810);
 }
hw/omap_sx1.c +6 -2
index a7b687b..e1cceec 100644
@@ -214,7 +214,9 @@ static void sx1_init(ram_addr_t ram_size,
     //~ qemu_console_resize(ds, 640, 480);
 }
 
-static void sx1_init_v1(ram_addr_t ram_size,
+static void sx1_init_v1(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
@@ -223,7 +225,9 @@ static void sx1_init_v1(ram_addr_t ram_size,
                 kernel_cmdline, initrd_filename, cpu_model, 1);
 }
 
-static void sx1_init_v2(ram_addr_t ram_size,
+static void sx1_init_v2(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
hw/palm.c +3 -1
index 4c67e75..7714a93 100644
@@ -193,7 +193,9 @@ static struct arm_boot_info palmte_binfo = {
     .board_id = 0x331,
 };
 
-static void palmte_init(ram_addr_t ram_size,
+static void palmte_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
hw/pc_piix.c +20 -11
index 75d96d9..f7f7865 100644
@@ -222,35 +222,41 @@ static void pc_init1(MemoryRegion *system_memory,
     }
 }
 
-static void pc_init_pci(ram_addr_t ram_size,
+static void pc_init_pci(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size,
                         const char *boot_device,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
-    pc_init1(get_system_memory(),
-             get_system_io(),
+    pc_init1(address_space_mem,
+             address_space_io,
              ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 1, 1);
 }
 
-static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
+static void pc_init_pci_no_kvmclock(MemoryRegion *address_space_mem,
+                                    MemoryRegion *address_space_io,
+                                    ram_addr_t ram_size,
                                     const char *boot_device,
                                     const char *kernel_filename,
                                     const char *kernel_cmdline,
                                     const char *initrd_filename,
                                     const char *cpu_model)
 {
-    pc_init1(get_system_memory(),
-             get_system_io(),
+    pc_init1(address_space_mem,
+             address_space_io,
              ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 1, 0);
 }
 
-static void pc_init_isa(ram_addr_t ram_size,
+static void pc_init_isa(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size,
                         const char *boot_device,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
@@ -259,15 +265,17 @@ static void pc_init_isa(ram_addr_t ram_size,
 {
     if (cpu_model == NULL)
         cpu_model = "486";
-    pc_init1(get_system_memory(),
-             get_system_io(),
+    pc_init1(address_space_mem,
+             address_space_io,
              ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0, 1);
 }
 
 #ifdef CONFIG_XEN
-static void pc_xen_hvm_init(ram_addr_t ram_size,
+static void pc_xen_hvm_init(MemoryRegion *address_space_mem,
+                            MemoryRegion *address_space_io,
+                            ram_addr_t ram_size,
                             const char *boot_device,
                             const char *kernel_filename,
                             const char *kernel_cmdline,
@@ -277,7 +285,8 @@ static void pc_xen_hvm_init(ram_addr_t ram_size,
     if (xen_hvm_init() != 0) {
         hw_error("xen hardware virtual machine initialisation failed");
     }
-    pc_init_pci_no_kvmclock(ram_size, boot_device,
+    pc_init_pci_no_kvmclock(address_space_mem, address_space_io,
+                            ram_size, boot_device,
                             kernel_filename, kernel_cmdline,
                             initrd_filename, cpu_model);
     xen_vcpu_init();
hw/petalogix_ml605_mmu.c +3 -1
index e3a66e5..b0758ea 100644
@@ -134,7 +134,9 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
 #define AXIDMA_BASEADDR 0x84600000
 
 static void
-petalogix_ml605_init(ram_addr_t ram_size,
+petalogix_ml605_init(MemoryRegion *address_space_mem,
+                          MemoryRegion *address_space_io,
+                          ram_addr_t ram_size,
                           const char *boot_device,
                           const char *kernel_filename,
                           const char *kernel_cmdline,
hw/petalogix_s3adsp1800_mmu.c +3 -1
index 589e8ca..b5d9f8a 100644
@@ -111,7 +111,9 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
 }
 
 static void
-petalogix_s3adsp1800_init(ram_addr_t ram_size,
+petalogix_s3adsp1800_init(MemoryRegion *address_space_mem,
+                          MemoryRegion *address_space_io,
+                          ram_addr_t ram_size,
                           const char *boot_device,
                           const char *kernel_filename,
                           const char *kernel_cmdline,
hw/ppc405_boards.c +6 -2
index dec165e..90eb98e 100644
@@ -170,7 +170,9 @@ static void ref405ep_fpga_init (uint32_t base)
     qemu_register_reset(&ref405ep_fpga_reset, fpga);
 }
 
-static void ref405ep_init (ram_addr_t ram_size,
+static void ref405ep_init (MemoryRegion *address_space_mem,
+                           MemoryRegion *address_space_io,
+                           ram_addr_t ram_size,
                            const char *boot_device,
                            const char *kernel_filename,
                            const char *kernel_cmdline,
@@ -498,7 +500,9 @@ static void taihu_cpld_init (uint32_t base)
     qemu_register_reset(&taihu_cpld_reset, cpld);
 }
 
-static void taihu_405ep_init(ram_addr_t ram_size,
+static void taihu_405ep_init(MemoryRegion *address_space_mem,
+                             MemoryRegion *address_space_io,
+                             ram_addr_t ram_size,
                              const char *boot_device,
                              const char *kernel_filename,
                              const char *kernel_cmdline,
hw/ppc440_bamboo.c +3 -1
index 1addb68..d43f8ba 100644
@@ -88,7 +88,9 @@ out:
     return ret;
 }
 
-static void bamboo_init(ram_addr_t ram_size,
+static void bamboo_init(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size,
                         const char *boot_device,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
hw/ppc_newworld.c +3 -1
index 4727e07..68b719b 100644
@@ -127,7 +127,9 @@ static target_phys_addr_t round_page(target_phys_addr_t addr)
 }
 
 /* PowerPC Mac99 hardware initialisation */
-static void ppc_core99_init (ram_addr_t ram_size,
+static void ppc_core99_init (MemoryRegion *address_space_mem,
+                             MemoryRegion *address_space_io,
+                             ram_addr_t ram_size,
                              const char *boot_device,
                              const char *kernel_filename,
                              const char *kernel_cmdline,
hw/ppc_oldworld.c +3 -1
index 0071fc9..b471257 100644
@@ -65,7 +65,9 @@ static target_phys_addr_t round_page(target_phys_addr_t addr)
     return (addr + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
 }
 
-static void ppc_heathrow_init (ram_addr_t ram_size,
+static void ppc_heathrow_init (MemoryRegion *address_space_mem,
+                               MemoryRegion *address_space_io,
+                               ram_addr_t ram_size,
                                const char *boot_device,
                                const char *kernel_filename,
                                const char *kernel_cmdline,
hw/ppc_prep.c +3 -1
index 515de42..1d9de45 100644
@@ -527,7 +527,9 @@ static void cpu_request_exit(void *opaque, int irq, int level)
 }
 
 /* PowerPC PREP hardware initialisation */
-static void ppc_prep_init (ram_addr_t ram_size,
+static void ppc_prep_init (MemoryRegion *address_space_mem,
+                           MemoryRegion *address_space_io,
+                           ram_addr_t ram_size,
                            const char *boot_device,
                            const char *kernel_filename,
                            const char *kernel_cmdline,
hw/ppce500_mpc8544ds.c +3 -1
index 1274a3e..37efb83 100644
@@ -218,7 +218,9 @@ static void mpc8544ds_cpu_reset(void *opaque)
     mmubooke_create_initial_mapping(env, 0, 0);
 }
 
-static void mpc8544ds_init(ram_addr_t ram_size,
+static void mpc8544ds_init(MemoryRegion *address_space_mem,
+                         MemoryRegion *address_space_io,
+                         ram_addr_t ram_size,
                          const char *boot_device,
                          const char *kernel_filename,
                          const char *kernel_cmdline,
hw/r2d.c +3 -1
index 96a7ff8..923fd4e 100644
@@ -223,7 +223,9 @@ static struct __attribute__((__packed__))
     char kernel_cmdline[256];
 } boot_params;
 
-static void r2d_init(ram_addr_t ram_size,
+static void r2d_init(MemoryRegion *address_space_mem,
+              MemoryRegion *address_space_io,
+              ram_addr_t ram_size,
               const char *boot_device,
 	      const char *kernel_filename, const char *kernel_cmdline,
 	      const char *initrd_filename, const char *cpu_model)
hw/realview.c +24 -9
index 549bb15..9b30331 100644
@@ -18,6 +18,7 @@
 #include "boards.h"
 #include "bitbang_i2c.h"
 #include "blockdev.h"
+#include "memory.h"
 
 #define SMP_BOOT_ADDR 0xe0000000
 
@@ -118,7 +119,9 @@ static const int realview_board_id[] = {
     0x76d
 };
 
-static void realview_init(ram_addr_t ram_size,
+static void realview_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model,
@@ -378,7 +381,9 @@ static void realview_init(ram_addr_t ram_size,
     arm_load_kernel(first_cpu, &realview_binfo);
 }
 
-static void realview_eb_init(ram_addr_t ram_size,
+static void realview_eb_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
@@ -386,11 +391,14 @@ static void realview_eb_init(ram_addr_t ram_size,
     if (!cpu_model) {
         cpu_model = "arm926";
     }
-    realview_init(ram_size, boot_device, kernel_filename, kernel_cmdline,
+    realview_init(address_space_mem, address_space_io,
+                  ram_size, boot_device, kernel_filename, kernel_cmdline,
                   initrd_filename, cpu_model, BOARD_EB);
 }
 
-static void realview_eb_mpcore_init(ram_addr_t ram_size,
+static void realview_eb_mpcore_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
@@ -398,11 +406,14 @@ static void realview_eb_mpcore_init(ram_addr_t ram_size,
     if (!cpu_model) {
         cpu_model = "arm11mpcore";
     }
-    realview_init(ram_size, boot_device, kernel_filename, kernel_cmdline,
+    realview_init(address_space_mem, address_space_io,
+                  ram_size, boot_device, kernel_filename, kernel_cmdline,
                   initrd_filename, cpu_model, BOARD_EB_MPCORE);
 }
 
-static void realview_pb_a8_init(ram_addr_t ram_size,
+static void realview_pb_a8_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
@@ -410,11 +421,14 @@ static void realview_pb_a8_init(ram_addr_t ram_size,
     if (!cpu_model) {
         cpu_model = "cortex-a8";
     }
-    realview_init(ram_size, boot_device, kernel_filename, kernel_cmdline,
+    realview_init(address_space_mem, address_space_io,
+                  ram_size, boot_device, kernel_filename, kernel_cmdline,
                   initrd_filename, cpu_model, BOARD_PB_A8);
 }
 
-static void realview_pbx_a9_init(ram_addr_t ram_size,
+static void realview_pbx_a9_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
@@ -422,7 +436,8 @@ static void realview_pbx_a9_init(ram_addr_t ram_size,
     if (!cpu_model) {
         cpu_model = "cortex-a9";
     }
-    realview_init(ram_size, boot_device, kernel_filename, kernel_cmdline,
+    realview_init(address_space_mem, address_space_io,
+                  ram_size, boot_device, kernel_filename, kernel_cmdline,
                   initrd_filename, cpu_model, BOARD_PBX_A9);
 }
 
hw/s390-virtio.c +3 -1
index acbf026..78a77c0 100644
@@ -131,7 +131,9 @@ int s390_virtio_hypercall(CPUState *env, uint64_t mem, uint64_t hypercall)
 }
 
 /* PC hardware initialisation */
-static void s390_init(ram_addr_t my_ram_size,
+static void s390_init(MemoryRegion *address_space_mem,
+                      MemoryRegion *address_space_io,
+                      ram_addr_t my_ram_size,
                       const char *boot_device,
                       const char *kernel_filename,
                       const char *kernel_cmdline,
hw/shix.c +3 -1
index 638bf16..0209f6a 100644
@@ -47,7 +47,9 @@ void pic_info(Monitor *mon)
     /* XXXXX */
 }
 
-static void shix_init(ram_addr_t ram_size,
+static void shix_init(MemoryRegion *address_space_mem,
+               MemoryRegion *address_space_io,
+               ram_addr_t ram_size,
                const char *boot_device,
 	       const char *kernel_filename, const char *kernel_cmdline,
 	       const char *initrd_filename, const char *cpu_model)
hw/spitz.c +23 -9
index c05b5f7..cac4669 100644
@@ -893,7 +893,9 @@ static struct arm_boot_info spitz_binfo = {
     .ram_size = 0x04000000,
 };
 
-static void spitz_common_init(ram_addr_t ram_size,
+static void spitz_common_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *kernel_filename,
                 const char *kernel_cmdline, const char *initrd_filename,
                 const char *cpu_model, enum spitz_model_e model, int arm_id)
@@ -946,39 +948,51 @@ static void spitz_common_init(ram_addr_t ram_size,
     sl_bootparam_write(SL_PXA_PARAM_BASE);
 }
 
-static void spitz_init(ram_addr_t ram_size,
+static void spitz_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
-    spitz_common_init(ram_size, kernel_filename,
+    spitz_common_init(address_space_mem, address_space_io,
+                ram_size, kernel_filename,
                 kernel_cmdline, initrd_filename, cpu_model, spitz, 0x2c9);
 }
 
-static void borzoi_init(ram_addr_t ram_size,
+static void borzoi_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
-    spitz_common_init(ram_size, kernel_filename,
+    spitz_common_init(address_space_mem, address_space_io,
+                ram_size, kernel_filename,
                 kernel_cmdline, initrd_filename, cpu_model, borzoi, 0x33f);
 }
 
-static void akita_init(ram_addr_t ram_size,
+static void akita_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
-    spitz_common_init(ram_size, kernel_filename,
+    spitz_common_init(address_space_mem, address_space_io,
+                ram_size, kernel_filename,
                 kernel_cmdline, initrd_filename, cpu_model, akita, 0x2e8);
 }
 
-static void terrier_init(ram_addr_t ram_size,
+static void terrier_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
-    spitz_common_init(ram_size, kernel_filename,
+    spitz_common_init(address_space_mem, address_space_io,
+                ram_size, kernel_filename,
                 kernel_cmdline, initrd_filename, cpu_model, terrier, 0x33f);
 }
 
hw/stellaris.c +13 -5
index 9b0db7f..f47b06e 100644
@@ -1250,7 +1250,9 @@ static stellaris_board_info stellaris_boards[] = {
   }
 };
 
-static void stellaris_init(const char *kernel_filename, const char *cpu_model,
+static void stellaris_init(MemoryRegion *address_space_mem,
+                           MemoryRegion *address_space_io,
+                           const char *kernel_filename, const char *cpu_model,
                            stellaris_board_info *board)
 {
     static const int uart_irq[] = {5, 6, 33, 34};
@@ -1377,20 +1379,26 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
 }
 
 /* FIXME: Figure out how to generate these from stellaris_boards.  */
-static void lm3s811evb_init(ram_addr_t ram_size,
+static void lm3s811evb_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
-    stellaris_init(kernel_filename, cpu_model, &stellaris_boards[0]);
+    stellaris_init(address_space_mem, address_space_io,
+                   kernel_filename, cpu_model, &stellaris_boards[0]);
 }
 
-static void lm3s6965evb_init(ram_addr_t ram_size,
+static void lm3s6965evb_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
-    stellaris_init(kernel_filename, cpu_model, &stellaris_boards[1]);
+    stellaris_init(address_space_mem, address_space_io,
+                   kernel_filename, cpu_model, &stellaris_boards[1]);
 }
 
 static QEMUMachine lm3s811evb_machine = {
hw/sun4m.c +36 -12

120 lines not on this page · raw message

hw/sun4u.c +9 -3
index 1b60e4e..1595015 100644
@@ -867,7 +867,9 @@ static const struct hwdef hwdefs[] = {
 };
 
 /* Sun4u hardware initialisation */
-static void sun4u_init(ram_addr_t RAM_size,
+static void sun4u_init(MemoryRegion *address_space_mem,
+                       MemoryRegion *address_space_io,
+                       ram_addr_t RAM_size,
                        const char *boot_devices,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
@@ -877,7 +879,9 @@ static void sun4u_init(ram_addr_t RAM_size,
 }
 
 /* Sun4v hardware initialisation */
-static void sun4v_init(ram_addr_t RAM_size,
+static void sun4v_init(MemoryRegion *address_space_mem,
+                       MemoryRegion *address_space_io,
+                       ram_addr_t RAM_size,
                        const char *boot_devices,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
@@ -887,7 +891,9 @@ static void sun4v_init(ram_addr_t RAM_size,
 }
 
 /* Niagara hardware initialisation */
-static void niagara_init(ram_addr_t RAM_size,
+static void niagara_init(MemoryRegion *address_space_mem,
+                         MemoryRegion *address_space_io,
+                         ram_addr_t RAM_size,
                          const char *boot_devices,
                          const char *kernel_filename, const char *kernel_cmdline,
                          const char *initrd_filename, const char *cpu_model)
hw/syborg.c +3 -1
index bc200e4..4bdb3c0 100644
@@ -29,7 +29,9 @@
 
 static struct arm_boot_info syborg_binfo;
 
-static void syborg_init(ram_addr_t ram_size,
+static void syborg_init(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size,
                         const char *boot_device,
                         const char *kernel_filename, const char *kernel_cmdline,
                         const char *initrd_filename, const char *cpu_model)
hw/tosa.c +3 -1
index a7967a2..cce828f 100644
@@ -205,7 +205,9 @@ static struct arm_boot_info tosa_binfo = {
     .ram_size = 0x04000000,
 };
 
-static void tosa_init(ram_addr_t ram_size,
+static void tosa_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
hw/versatilepb.c +14 -5
index 49f8f5f..aaab42c 100644
@@ -17,6 +17,7 @@
 #include "usb-ohci.h"
 #include "boards.h"
 #include "blockdev.h"
+#include "memory.h"
 
 /* Primary interrupt controller.  */
 
@@ -169,7 +170,9 @@ static int vpb_sic_init(SysBusDevice *dev)
 
 static struct arm_boot_info versatile_binfo;
 
-static void versatile_init(ram_addr_t ram_size,
+static void versatile_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model,
@@ -309,23 +312,29 @@ static void versatile_init(ram_addr_t ram_size,
     arm_load_kernel(env, &versatile_binfo);
 }
 
-static void vpb_init(ram_addr_t ram_size,
+static void vpb_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
-    versatile_init(ram_size,
+    versatile_init(address_space_mem, address_space_io,
+                   ram_size,
                    boot_device,
                    kernel_filename, kernel_cmdline,
                    initrd_filename, cpu_model, 0x183);
 }
 
-static void vab_init(ram_addr_t ram_size,
+static void vab_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
-    versatile_init(ram_size,
+    versatile_init(address_space_mem, address_space_io,
+                   ram_size,
                    boot_device,
                    kernel_filename, kernel_cmdline,
                    initrd_filename, cpu_model, 0x25e);
hw/vexpress.c +3 -1
index c9766dd..3aa9e8a 100644
@@ -34,7 +34,9 @@ static struct arm_boot_info vexpress_binfo = {
     .smp_loader_start = SMP_BOOT_ADDR,
 };
 
-static void vexpress_a9_init(ram_addr_t ram_size,
+static void vexpress_a9_init(MemoryRegion *address_space_mem,
+                     MemoryRegion *address_space_io,
+                     ram_addr_t ram_size,
                      const char *boot_device,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
hw/virtex_ml507.c +3 -1
index 333050c..4503851 100644
@@ -185,7 +185,9 @@ static int xilinx_load_device_tree(target_phys_addr_t addr,
     return fdt_size;
 }
 
-static void virtex_init(ram_addr_t ram_size,
+static void virtex_init(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size,
                         const char *boot_device,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
hw/xen_machine_pv.c +3 -1
index 7985d11..e2d0b85 100644
@@ -29,7 +29,9 @@
 #include "xen_domainbuild.h"
 #include "blockdev.h"
 
-static void xen_init_pv(ram_addr_t ram_size,
+static void xen_init_pv(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size,
 			const char *boot_device,
 			const char *kernel_filename,
 			const char *kernel_cmdline,
hw/z2.c +3 -1
index f93a1bf..f1db41b 100644
@@ -272,7 +272,9 @@ static I2CSlaveInfo aer915_info = {
     .send = aer915_send
 };
 
-static void z2_init(ram_addr_t ram_size,
+static void z2_init(MemoryRegion *address_space_mem,
+                MemoryRegion *address_space_io,
+                ram_addr_t ram_size,
                 const char *boot_device,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
vl.c +2 -1
index 5f1a177..5cdb083 100644
@@ -148,6 +148,7 @@ int main(int argc, char **argv)
 #ifdef CONFIG_VIRTFS
 #include "fsdev/qemu-fsdev.h"
 #endif
+#include "exec-memory.h"
 
 #include "disas.h"
 
@@ -3244,7 +3245,7 @@ int main(int argc, char **argv, char **envp)
     }
     qemu_add_globals();
 
-    machine->init(ram_size, boot_devices,
+    machine->init(get_system_memory(), get_system_io(), ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
     cpu_synchronize_all_post_init();
Signature · 1 line
1.7.5.3
#9 lore raw

Re: [Qemu-devel] [PATCH 06/24] QEMUMachine: pass address space to machine init function

Quoted 5 lines · Avi Kivity

Avoids get_system_memory() everywhere.

-    machine->init(ram_size, boot_devices,
+    machine->init(get_system_memory(), get_system_io(), ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);

I think this is conceptually wrong. The system memory/IO address spaces are not configurable properties of the machine model (in the way that the other arguments to machine->init() are), they're purely an internal implementation detail of it. (In fact for many of the machines we support there isn't even any such thing as the system IO space...)

-- PMM

author
#10 lore raw

Re: [Qemu-devel] [PATCH 06/24] QEMUMachine: pass address space to machine init function

Quoted 7 lines · Peter Maydell
Quoted 5 lines · Avi Kivity

Avoids get_system_memory() everywhere.

- machine->init(ram_size, boot_devices,
+ machine->init(get_system_memory(), get_system_io(), ram_size, boot_devices,

                    kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
Quoted 5 lines

I think this is conceptually wrong. The system memory/IO address spaces are not configurable properties of the machine model (in the way that the other arguments to machine->init() are), they're purely an internal implementation detail of it. (In fact for many of the machines we support there isn't even any such thing as the system IO space...)

I agree with all you say, but does it make the patch incorrect? The purpose here is to allow removal of get_system_memory() from the general code base.

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

Re: [Qemu-devel] [PATCH 06/24] QEMUMachine: pass address space to machine init function

Quoted 11 lines · Avi Kivity
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Avi Kivity

 Avoids get_system_memory() everywhere.

 -    machine->init(ram_size, boot_devices,
 +    machine->init(get_system_memory(), get_system_io(), ram_size, boot_devices,
                    kernel_filename, kernel_cmdline, initrd_filename, cpu_model);

Quoted 7 lines
Quoted 5 lines

I think this is conceptually wrong. The system memory/IO address spaces are not configurable properties of the machine model (in the way that the other arguments to machine->init() are), they're purely an internal implementation detail of it. (In fact for many of the machines we support there isn't even any such thing as the system IO space...)

I agree with all you say, but does it make the patch incorrect?

My assertion is that patches which are conceptually wrong are also incorrect :-)

Quoted 2 lines

The purpose here is to allow removal of get_system_memory() from the general code base.

The right way to remove get_system_memory() from the general code base is to actually model things correctly, for instance by having machine models create a container memory region into which they insert the memory regions for all the devices which currently use sysbus_mmio_map to map themselves, and then pass the container memory region to the "master" end of the bus, ie the CPU.

-- PMM

author
#12 lore raw

Re: [Qemu-devel] [PATCH 06/24] QEMUMachine: pass address space to machine init function

Quoted 10 lines · Peter Maydell
Quoted 2 lines

The purpose here is to allow removal of get_system_memory() from the general code base.

The right way to remove get_system_memory() from the general code base is to actually model things correctly, for instance by having machine models create a container memory region into which they insert the memory regions for all the devices which currently use sysbus_mmio_map to map themselves, and then pass the container memory region to the "master" end of the bus, ie the CPU.

I think you're right. This also allows eventual removal of system_io on anything non-x86.

So a replacement would look like:

(before)

-static void pc_init_isa(ram_addr_t ram_size,
+static void pc_init_isa(MemoryRegion *address_space_mem,
+ MemoryRegion *address_space_io,
+ ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
@@ -259,15 +265,17 @@ static void pc_init_isa(ram_addr_t ram_size,

 {
     if (cpu_model == NULL)
         cpu_model = "486";

- pc_init1(get_system_memory(),
- get_system_io(),
+ pc_init1(address_space_mem,
+ address_space_io,

              ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0, 1);

}

(after)
@@ -259,15 +265,17 @@ static void pc_init_isa(ram_addr_t ram_size,
{
+ MemoryRegion *address_space_mem, *address_space_io;
+

+    setup_system_memory(&address_space_mem,&address_space_io);
     if (cpu_model == NULL)
         cpu_model = "486";

- pc_init1(get_system_memory(),
- get_system_io(),
+ pc_init1(address_space_mem,
+ address_space_io,

              ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0, 1);

}

Later on, we'd refine the setup_system_memory() calls, for example not to create the io space on non-x86.

A possible complication is whether anything currently uses system_memory before ->init is called. Anyone know?

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

Re: [Qemu-devel] [PATCH 06/24] QEMUMachine: pass address space to machine init function

Quoted 58 lines · Avi Kivity
Quoted 10 lines · Peter Maydell
Quoted 2 lines

The purpose here is to allow removal of get_system_memory() from the general code base.

The right way to remove get_system_memory() from the general code base is to actually model things correctly, for instance by having machine models create a container memory region into which they insert the memory regions for all the devices which currently use sysbus_mmio_map to map themselves, and then pass the container memory region to the "master" end of the bus, ie the CPU.

I think you're right. This also allows eventual removal of system_io on anything non-x86.

So a replacement would look like:

(before)

hw/pc_piix.c +10 -5
-static void pc_init_isa(ram_addr_t ram_size,
+static void pc_init_isa(MemoryRegion *address_space_mem,
+                        MemoryRegion *address_space_io,
+                        ram_addr_t ram_size,
                         const char *boot_device,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
@@ -259,15 +265,17 @@ static void pc_init_isa(ram_addr_t ram_size,
 {
     if (cpu_model == NULL)
         cpu_model = "486";
-    pc_init1(get_system_memory(),
-             get_system_io(),
+    pc_init1(address_space_mem,
+             address_space_io,
              ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0, 1);
 }
 
 (after)
@@ -259,15 +265,17 @@ static void pc_init_isa(ram_addr_t ram_size,
 {
+    MemoryRegion *address_space_mem, *address_space_io;
+
+    setup_system_memory(&address_space_mem,&address_space_io);
     if (cpu_model == NULL)
         cpu_model = "486";
-    pc_init1(get_system_memory(),
-             get_system_io(),
+    pc_init1(address_space_mem,
+             address_space_io,
              ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0, 1);
 }
 
 

Later on, we'd refine the setup_system_memory() calls, for example not to create the io space on non-x86.

Quoted 2 lines

A possible complication is whether anything currently uses system_memory before ->init is called. Anyone know?

Okay, it looks like I can just drop the patch and call get_system_memory() in the various _init functions. This avoids the complication. We can tidy up get_system_memory() later.

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

PATCH 7/24 an5206: convert to memory API

In reply to Avi Kivity
---
 hw/an5206.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
hw/an5206.c +8 -4
index e34de39..9a91984 100644
@@ -6,6 +6,8 @@
  * This code is licensed under the GPL
  */
 
+#include <glib.h>
+
 #include "hw.h"
 #include "pc.h"
 #include "mcf.h"
@@ -39,6 +41,8 @@ static void an5206_init(MemoryRegion *address_space_mem,
     int kernel_size;
     uint64_t elf_entry;
     target_phys_addr_t entry;
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
+    MemoryRegion *sram = g_new(MemoryRegion, 1);
 
     if (!cpu_model)
         cpu_model = "m5206";
@@ -54,12 +58,12 @@ static void an5206_init(MemoryRegion *address_space_mem,
     env->rambar0 = AN5206_RAMBAR_ADDR | 1;
 
     /* DRAM at address zero */
-    cpu_register_physical_memory(0, ram_size,
-        qemu_ram_alloc(NULL, "an5206.ram", ram_size) | IO_MEM_RAM);
+    memory_region_init_ram(ram, NULL, "an5206.ram", ram_size);
+    memory_region_add_subregion(address_space_mem, 0, ram);
 
     /* Internal SRAM.  */
-    cpu_register_physical_memory(AN5206_RAMBAR_ADDR, 512,
-        qemu_ram_alloc(NULL, "an5206.sram", 512) | IO_MEM_RAM);
+    memory_region_init_ram(sram, NULL, "an5206.sram", 512);
+    memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
 
     mcf5206_init(AN5206_MBAR_ADDR, env);
 
Signature · 1 line
1.7.5.3
author
#15 lore raw

PATCH 8/24 armv7m: convert to memory API

In reply to Avi Kivity
---
 hw/arm-misc.h  |    5 ++++-
 hw/armv7m.c    |   24 ++++++++++++++----------
 hw/stellaris.c |    3 ++-
 3 files changed, 20 insertions(+), 12 deletions(-)
hw/arm-misc.h +4 -1
index f8a7472..af403a1 100644
@@ -11,13 +11,16 @@
 #ifndef ARM_MISC_H
 #define ARM_MISC_H 1
 
+#include "memory.h"
+
 /* The CPU is also modeled as an interrupt controller.  */
 #define ARM_PIC_CPU_IRQ 0
 #define ARM_PIC_CPU_FIQ 1
 qemu_irq *arm_pic_init_cpu(CPUState *env);
 
 /* armv7m.c */
-qemu_irq *armv7m_init(int flash_size, int sram_size,
+qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
+                      int flash_size, int sram_size,
                       const char *kernel_filename, const char *cpu_model);
 
 /* arm_boot.c */
hw/armv7m.c +14 -10
index a932f16..db535fd 100644
@@ -7,6 +7,8 @@
  * This code is licensed under the GPL.
  */
 
+#include <glib.h>
+
 #include "sysbus.h"
 #include "arm-misc.h"
 #include "loader.h"
@@ -156,7 +158,8 @@ static void armv7m_reset(void *opaque)
    flash_size and sram_size are in kb.
    Returns the NVIC array.  */
 
-qemu_irq *armv7m_init(int flash_size, int sram_size,
+qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
+                      int flash_size, int sram_size,
                       const char *kernel_filename, const char *cpu_model)
 {
     CPUState *env;
@@ -169,6 +172,9 @@ qemu_irq *armv7m_init(int flash_size, int sram_size,
     uint64_t lowaddr;
     int i;
     int big_endian;
+    MemoryRegion *sram = g_new(MemoryRegion, 1);
+    MemoryRegion *flash = g_new(MemoryRegion, 1);
+    MemoryRegion *hack = g_new(MemoryRegion, 1);
 
     flash_size *= 1024;
     sram_size *= 1024;
@@ -194,12 +200,11 @@ qemu_irq *armv7m_init(int flash_size, int sram_size,
 #endif
 
     /* Flash programming is done via the SCU, so pretend it is ROM.  */
-    cpu_register_physical_memory(0, flash_size,
-                                 qemu_ram_alloc(NULL, "armv7m.flash",
-                                                flash_size) | IO_MEM_ROM);
-    cpu_register_physical_memory(0x20000000, sram_size,
-                                 qemu_ram_alloc(NULL, "armv7m.sram",
-                                                sram_size) | IO_MEM_RAM);
+    memory_region_init_ram(flash, NULL, "armv7m.flash", flash_size);
+    memory_region_set_readonly(flash, true);
+    memory_region_add_subregion(address_space_mem, 0, flash);
+    memory_region_init_ram(sram, NULL, "armv7m.sram", sram_size);
+    memory_region_add_subregion(address_space_mem, 0x20000000, sram);
     armv7m_bitband_init();
 
     nvic = qdev_create(NULL, "armv7m_nvic");
@@ -232,9 +237,8 @@ qemu_irq *armv7m_init(int flash_size, int sram_size,
     /* Hack to map an additional page of ram at the top of the address
        space.  This stops qemu complaining about executing code outside RAM
        when returning from an exception.  */
-    cpu_register_physical_memory(0xfffff000, 0x1000,
-                                 qemu_ram_alloc(NULL, "armv7m.hack", 
-                                                0x1000) | IO_MEM_RAM);
+    memory_region_init_ram(hack, NULL, "armv7m.hack", 0x1000);
+    memory_region_add_subregion(address_space_mem, 0xfffff000, hack);
 
     qemu_register_reset(armv7m_reset, env);
     return pic;
hw/stellaris.c +2 -1
index f47b06e..d354008 100644
@@ -1276,7 +1276,8 @@ static void stellaris_init(MemoryRegion *address_space_mem,
 
     flash_size = ((board->dc0 & 0xffff) + 1) << 1;
     sram_size = (board->dc0 >> 18) + 1;
-    pic = armv7m_init(flash_size, sram_size, kernel_filename, cpu_model);
+    pic = armv7m_init(address_space_mem,
+                      flash_size, sram_size, kernel_filename, cpu_model);
 
     if (board->dc1 & (1 << 16)) {
         dev = sysbus_create_varargs("stellaris-adc", 0x40038000,
Signature · 1 line
1.7.5.3
author
#16 lore raw

PATCH 9/24 axis_dev88: convert to memory API (RAM only)

In reply to Avi Kivity
---
 hw/axis_dev88.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
hw/axis_dev88.c +8 -8
index cfc89c2..04a3d5b 100644
@@ -22,6 +22,8 @@
  * THE SOFTWARE.
  */
 
+#include <glib.h>
+
 #include "sysbus.h"
 #include "net.h"
 #include "flash.h"
@@ -261,8 +263,8 @@ void axisdev88_init (MemoryRegion *address_space_mem,
     int i;
     int nand_regs;
     int gpio_regs;
-    ram_addr_t phys_ram;
-    ram_addr_t phys_intmem;
+    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
+    MemoryRegion *phys_intmem = g_new(MemoryRegion, 1);
 
     /* init CPUs */
     if (cpu_model == NULL) {
@@ -271,15 +273,13 @@ void axisdev88_init (MemoryRegion *address_space_mem,
     env = cpu_init(cpu_model);
 
     /* allocate RAM */
-    phys_ram = qemu_ram_alloc(NULL, "axisdev88.ram", ram_size);
-    cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);
+    memory_region_init_ram(phys_ram, NULL, "axisdev88.ram", ram_size);
+    memory_region_add_subregion(address_space_mem, 0x40000000, phys_ram);
 
     /* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the 
        internal memory.  */
-    phys_intmem = qemu_ram_alloc(NULL, "axisdev88.chipram", INTMEM_SIZE);
-    cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
-                                 phys_intmem | IO_MEM_RAM);
-
+    memory_region_init_ram(phys_intmem, NULL, "axisdev88.chipram", INTMEM_SIZE);
+    memory_region_add_subregion(address_space_mem, 0x38000000, phys_intmem);
 
       /* Attach a NAND flash to CS1.  */
     nand = drive_get(IF_MTD, 0, 0);
Signature · 1 line
1.7.5.3
author
#17 lore raw

PATCH 10/24 sysbus: add sysbus_add_memory_overlap()

In reply to Avi Kivity
---
 hw/sysbus.c |    6 ++++++
 hw/sysbus.h |    2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)
hw/sysbus.c +6 -0
index f5f0ed2..4efb91a 100644
@@ -263,6 +263,12 @@ void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
     memory_region_add_subregion(get_system_memory(), addr, mem);
 }
 
+void sysbus_add_memory_overlap(SysBusDevice *dev, target_phys_addr_t addr,
+                               MemoryRegion *mem, unsigned priority)
+{
+    memory_region_add_subregion(get_system_memory(), addr, mem);
+}
+
 void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem)
 {
     memory_region_del_subregion(get_system_memory(), mem);
hw/sysbus.h +2 -0
index e4d56cf..b3e1f99 100644
@@ -59,6 +59,8 @@ void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
 void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
 void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
                        MemoryRegion *mem);
+void sysbus_add_memory_overlap(SysBusDevice *dev, target_phys_addr_t addr,
+                               MemoryRegion *mem, unsigned priority);
 void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
 void sysbus_add_io(SysBusDevice *dev, target_phys_addr_t addr,
                    MemoryRegion *mem);
Signature · 1 line
1.7.5.3
author
#18 lore raw

PATCH 11/24 integratorcp: convert to memory API (RAM/flash only)

In reply to Avi Kivity
---
 hw/integratorcp.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
hw/integratorcp.c +20 -8
index 3d4b339..720cc02 100644
@@ -7,6 +7,8 @@
  * This code is licensed under the GPL
  */
 
+#include <glib.h>
+
 #include "sysbus.h"
 #include "primecell.h"
 #include "devices.h"
@@ -17,7 +19,8 @@
 typedef struct {
     SysBusDevice busdev;
     uint32_t memsz;
-    uint32_t flash_offset;
+    MemoryRegion flash;
+    bool flash_mapped;
     uint32_t cm_osc;
     uint32_t cm_ctrl;
     uint32_t cm_lock;
@@ -108,9 +111,15 @@ static uint32_t integratorcm_read(void *opaque, target_phys_addr_t offset)
 static void integratorcm_do_remap(integratorcm_state *s, int flash)
 {
     if (flash) {
-        cpu_register_physical_memory(0, 0x100000, IO_MEM_RAM);
+        if (s->flash_mapped) {
+            sysbus_del_memory(&s->busdev, &s->flash);
+            s->flash_mapped = false;
+        }
     } else {
-        cpu_register_physical_memory(0, 0x100000, s->flash_offset | IO_MEM_RAM);
+        if (!s->flash_mapped) {
+            sysbus_add_memory_overlap(&s->busdev, 0, &s->flash, 1);
+            s->flash_mapped = true;
+        }
     }
     //??? tlb_flush (cpu_single_env, 1);
 }
@@ -252,7 +261,8 @@ static int integratorcm_init(SysBusDevice *dev)
     }
     memcpy(integrator_spd + 73, "QEMU-MEMORY", 11);
     s->cm_init = 0x00000112;
-    s->flash_offset = qemu_ram_alloc(NULL, "integrator.flash", 0x100000);
+    memory_region_init_ram(&s->flash, NULL, "integrator.flash", 0x100000);
+    s->flash_mapped = false;
 
     iomemtype = cpu_register_io_memory(integratorcm_readfn,
                                        integratorcm_writefn, s,
@@ -458,7 +468,8 @@ static void integratorcp_init(MemoryRegion *address_space_mem,
                      const char *initrd_filename, const char *cpu_model)
 {
     CPUState *env;
-    ram_addr_t ram_offset;
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
+    MemoryRegion *ram_alias = g_new(MemoryRegion, 1);
     qemu_irq pic[32];
     qemu_irq *cpu_pic;
     DeviceState *dev;
@@ -471,13 +482,14 @@ static void integratorcp_init(MemoryRegion *address_space_mem,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
-    ram_offset = qemu_ram_alloc(NULL, "integrator.ram", ram_size);
+    memory_region_init_ram(ram, NULL, "integrator.ram", ram_size);
     /* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash.  */
     /* ??? RAM should repeat to fill physical memory space.  */
     /* SDRAM at address zero*/
-    cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);
+    memory_region_add_subregion(address_space_mem, 0, ram);
     /* And again at address 0x80000000 */
-    cpu_register_physical_memory(0x80000000, ram_size, ram_offset | IO_MEM_RAM);
+    memory_region_init_alias(ram_alias, "ram.alias", ram, 0, ram_size);
+    memory_region_add_subregion(address_space_mem, 0x80000000, ram_alias);
 
     dev = qdev_create(NULL, "integrator_core");
     qdev_prop_set_uint32(dev, "memsz", ram_size >> 20);
Signature · 1 line
1.7.5.3
#19 lore raw

Re: [Qemu-devel] [PATCH 11/24] integratorcp: convert to memory API (RAM/flash only)

Quoted 6 lines · Avi Kivity
hw/integratorcp.c +1 -1
@@ -108,9 +111,15 @@ static uint32_t integratorcm_read(void *opaque, target_phys_addr_t offset)
  static void integratorcm_do_remap(integratorcm_state *s, int flash)
  {
     if (flash) {
-        cpu_register_physical_memory(0, 0x100000, IO_MEM_RAM);
+        if (s->flash_mapped) {

hw/integratorcp.c static uint32_t integratorcm_read(void *opaque, target_phys_addr_t offset) · line 123

Quoted 10 lines
hw/integratorcp.c +7 -1
+            sysbus_del_memory(&s->busdev, &s->flash);
+            s->flash_mapped = false;
+        }
     } else {
-        cpu_register_physical_memory(0, 0x100000, s->flash_offset | IO_MEM_RAM);
+        if (!s->flash_mapped) {
+            sysbus_add_memory_overlap(&s->busdev, 0, &s->flash, 1);
+            s->flash_mapped = true;
+        }
     }

This is introducing a new field in the device state which is actually just tracking s->cm_init bit 2. At least it would be, except that in integratorcm_set_ctrl this line:

    s->cm_init = (s->cm_init & ~ 5) | (value ^ 5);

appears to be using ^ when it meant & ...

This isn't a nak -- I'm happy for this to get committed and I'll fix things up later, since the device doesn't have a VMStateDescription that would be broken by the extra state field. (Or if I get round to it before the series gets committed I'll send you a fix to squash into this patch.)

-- PMM

author
#20 lore raw

Re: [Qemu-devel] [PATCH 11/24] integratorcp: convert to memory API (RAM/flash only)

Quoted 21 lines · Peter Maydell
Quoted 16 lines · Avi Kivity

@@ -108,9 +111,15 @@ static uint32_t integratorcm_read(void *opaque, target_phys_addr_t offset)
static void integratorcm_do_remap(integratorcm_state *s, int flash)

   {
      if (flash) {
 -        cpu_register_physical_memory(0, 0x100000, IO_MEM_RAM);
 +        if (s->flash_mapped) {
 +            sysbus_del_memory(&s->busdev,&s->flash);
 +            s->flash_mapped = false;
 +        }
      } else {
 -        cpu_register_physical_memory(0, 0x100000, s->flash_offset | IO_MEM_RAM);
 +        if (!s->flash_mapped) {
 +            sysbus_add_memory_overlap(&s->busdev, 0,&s->flash, 1);
 +            s->flash_mapped = true;
 +        }
      }

This is introducing a new field in the device state which is actually just tracking s->cm_init bit 2. At least it would be, except that in integratorcm_set_ctrl this line:

Quoted 7 lines
     s->cm_init = (s->cm_init&  ~ 5) | (value ^ 5);

appears to be using ^ when it meant& ...

This isn't a nak -- I'm happy for this to get committed and I'll fix things up later, since the device doesn't have a VMStateDescription that would be broken by the extra state field.

Even with vmstate, nothing would break since the field would be recovered on restore.

Quoted 3 lines

(Or if I get round to
it before the series gets committed I'll send you a fix to squash into this patch.)

That would be best. Please post the &/^ fixup separately (if needed) since it isn't strictly related to the conversion.

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

PATCH 12/24 leon3: convert to memory API

In reply to Avi Kivity
---
 hw/leon3.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
hw/leon3.c +10 -6
index efe6c7c..5c3780d 100644
@@ -21,6 +21,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
+#include <glib.h>
+
 #include "hw.h"
 #include "qemu-timer.h"
 #include "qemu-char.h"
@@ -102,7 +105,8 @@ static void leon3_generic_hw_init(MemoryRegion *address_space_mem,
                                   const char *cpu_model)
 {
     CPUState   *env;
-    ram_addr_t  ram_offset, prom_offset;
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
+    MemoryRegion *prom = g_new(MemoryRegion, 1);
     int         ret;
     char       *filename;
     qemu_irq   *cpu_irqs = NULL;
@@ -141,14 +145,14 @@ static void leon3_generic_hw_init(MemoryRegion *address_space_mem,
         exit(1);
     }
 
-    ram_offset = qemu_ram_alloc(NULL, "leon3.ram", ram_size);
-    cpu_register_physical_memory(0x40000000, ram_size, ram_offset | IO_MEM_RAM);
+    memory_region_init_ram(ram, NULL, "leon3.ram", ram_size);
+    memory_region_add_subregion(address_space_mem, 0x40000000, ram);
 
     /* Allocate BIOS */
     prom_size = 8 * 1024 * 1024; /* 8Mb */
-    prom_offset = qemu_ram_alloc(NULL, "Leon3.bios", prom_size);
-    cpu_register_physical_memory(0x00000000, prom_size,
-                                 prom_offset | IO_MEM_ROM);
+    memory_region_init_ram(prom, NULL, "Leon3.bios", prom_size);
+    memory_region_set_readonly(prom, true);
+    memory_region_add_subregion(address_space_mem, 0x00000000, prom);
 
     /* Load boot prom */
     if (bios_name == NULL) {
Signature · 1 line
1.7.5.3
author
#22 lore raw

PATCH 13/24 cirrus: wrap memory update in a transaction

In reply to Avi Kivity

This prevents spurious unmapping and remapping of the vga windows, which reduces performance.

---
 hw/cirrus_vga.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/cirrus_vga.c +2 -0
index 4d0ef0d..ec7ea82 100644
@@ -2424,6 +2424,7 @@ static void cirrus_update_memory_access(CirrusVGAState *s)
 {
     unsigned mode;
 
+    memory_region_transaction_begin();
     if ((s->vga.sr[0x17] & 0x44) == 0x44) {
         goto generic_io;
     } else if (s->cirrus_srcptr != s->cirrus_srcptr_end) {
@@ -2443,6 +2444,7 @@ static void cirrus_update_memory_access(CirrusVGAState *s)
             unmap_linear_vram(s);
         }
     }
+    memory_region_transaction_commit();
 }
 
 
Signature · 1 line
1.7.5.3
author
#23 lore raw

PATCH 14/24 piix_pci: wrap memory update in a transaction

In reply to Avi Kivity

The code will remap all PAMs, even if just one is updated, resulting in reduced performance. Wrap in a transaction to detect that those other PAMs have not changed.

---
 hw/piix_pci.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/piix_pci.c +2 -0
index f892994..8f6ea42 100644
@@ -142,6 +142,7 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)
     int i, r;
     uint32_t smram;
 
+    memory_region_transaction_begin();
     update_pam(d, 0xf0000, 0x100000, (d->dev.config[I440FX_PAM] >> 4) & 3,
                &d->pam_regions[0]);
     for(i = 0; i < 12; i++) {
@@ -162,6 +163,7 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)
             d->smram_enabled = false;
         }
     }
+    memory_region_transaction_commit();
 }
 
 static void i440fx_set_smm(int val, void *arg)
Signature · 1 line
1.7.5.3
author
#24 lore raw

PATCH 15/24 Makefile.hw: allow hw/ files to include glib headers

In reply to Avi Kivity
---
 Makefile.hw |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Makefile.hw +1 -0
index 659e441..63eb7e4 100644
@@ -10,6 +10,7 @@ include $(SRC_PATH)/rules.mak
 $(call set-vpath, $(SRC_PATH):$(SRC_PATH)/hw)
 
 QEMU_CFLAGS+=-I..
+QEMU_CFLAGS += $(GLIB_CFLAGS)
 
 include $(SRC_PATH)/Makefile.objs
 
Signature · 1 line
1.7.5.3
author
#25 lore raw

PATCH 16/24 pflash_cfi01/pflash_cfi02: convert to memory API

In reply to Avi Kivity

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

---
 hw/collie.c                   |   17 ++++---
 hw/flash.h                    |   16 +++++--
 hw/gumstix.c                  |   29 +++++++-----
 hw/lm32_boards.c              |   15 ++++---
 hw/mainstone.c                |   21 +++++----
 hw/milkymist.c                |    8 ++-
 hw/mips_malta.c               |   44 ++++++++++---------
 hw/mips_r4k.c                 |   19 +++++---
 hw/musicpal.c                 |   16 ++++---
 hw/omap_sx1.c                 |   22 ++++++----
 hw/petalogix_ml605_mmu.c      |    8 ++-
 hw/petalogix_s3adsp1800_mmu.c |    9 +++-
 hw/pflash_cfi01.c             |   67 ++++++++++-------------------
 hw/pflash_cfi02.c             |   95 ++++++++++++++++++++---------------------
 hw/ppc405_boards.c            |   61 ++++++++++++++------------
 hw/r2d.c                      |    8 +++-
 hw/virtex_ml507.c             |    8 ++-
 hw/z2.c                       |   16 ++++---
 18 files changed, 256 insertions(+), 223 deletions(-)
hw/collie.c +10 -7
index 9b724aa..6f30d24 100644
@@ -5,6 +5,7 @@
  *
  * This code is licensed under GNU GPL v2.
  */
+#include <glib.h>
 #include "hw.h"
 #include "sysbus.h"
 #include "boards.h"
@@ -28,7 +29,7 @@ static void collie_init(MemoryRegion *address_space_mem,
 {
     StrongARMState *s;
     DriveInfo *dinfo;
-    ram_addr_t phys_flash;
+    MemoryRegion *phys_flash = g_new(MemoryRegion, 2);
 
     if (!cpu_model) {
         cpu_model = "sa1110";
@@ -36,17 +37,19 @@ static void collie_init(MemoryRegion *address_space_mem,
 
     s = sa1110_init(collie_binfo.ram_size, cpu_model);
 
-    phys_flash = qemu_ram_alloc(NULL, "collie.fl1", 0x02000000);
+    memory_region_init_rom_device(&phys_flash[0], &pflash_cfi01_ops_le,
+                                  NULL, "collie.fl1", 0x02000000);
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi01_register(SA_CS0, phys_flash,
+    pflash_cfi01_register(SA_CS0, &phys_flash[0],
                     dinfo ? dinfo->bdrv : NULL, (64 * 1024),
-                    512, 4, 0x00, 0x00, 0x00, 0x00, 0);
+                    512, 4, 0x00, 0x00, 0x00, 0x00);
 
-    phys_flash = qemu_ram_alloc(NULL, "collie.fl2", 0x02000000);
+    memory_region_init_rom_device(&phys_flash[1], &pflash_cfi01_ops_le,
+                                  NULL, "collie.fl2", 0x02000000);
     dinfo = drive_get(IF_PFLASH, 0, 1);
-    pflash_cfi01_register(SA_CS1, phys_flash,
+    pflash_cfi01_register(SA_CS1, &phys_flash[1],
                     dinfo ? dinfo->bdrv : NULL, (64 * 1024),
-                    512, 4, 0x00, 0x00, 0x00, 0x00, 0);
+                    512, 4, 0x00, 0x00, 0x00, 0x00);
 
     sysbus_create_simple("scoop", 0x40800000, NULL);
 
hw/flash.h +11 -5
index 140ae39..7fb012b 100644
@@ -1,21 +1,27 @@
+#include "memory.h"
+
 /* NOR flash devices */
 typedef struct pflash_t pflash_t;
 
 /* pflash_cfi01.c */
-pflash_t *pflash_cfi01_register(target_phys_addr_t base, ram_addr_t off,
+extern const MemoryRegionOps pflash_cfi01_ops_be;
+extern const MemoryRegionOps pflash_cfi01_ops_le;
+extern const MemoryRegionOps pflash_cfi02_ops_be;
+extern const MemoryRegionOps pflash_cfi02_ops_le;
+
+pflash_t *pflash_cfi01_register(target_phys_addr_t base, MemoryRegion *mem,
                                 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);
+                                uint16_t id2, uint16_t id3);
 
 /* 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, MemoryRegion *mem,
                                 BlockDriverState *bs, 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);
+                                uint16_t unlock_addr0, uint16_t unlock_addr1);
 
 /* nand.c */
 DeviceState *nand_init(BlockDriverState *bdrv, int manf_id, int chip_id);
hw/gumstix.c +17 -12
index ccdd834..620bdd7 100644
@@ -31,6 +31,7 @@
  * # qemu-system-arm -M verdex -pflash flash -monitor null -nographic -m 289
  */
 
+#include <glib.h>
 #include "hw.h"
 #include "pxa.h"
 #include "net.h"
@@ -50,7 +51,8 @@ static void connex_init(MemoryRegion *address_space_mem,
 {
     PXA2xxState *cpu;
     DriveInfo *dinfo;
-    int be;
+    const MemoryRegionOps *flash_ops;
+    MemoryRegion *flash = g_new(MemoryRegion, 1);
 
     uint32_t connex_rom = 0x01000000;
     uint32_t connex_ram = 0x04000000;
@@ -65,14 +67,15 @@ static void connex_init(MemoryRegion *address_space_mem,
     }
 
 #ifdef TARGET_WORDS_BIGENDIAN
-    be = 1;
+    flash_ops = &pflash_cfi01_ops_be;
 #else
-    be = 0;
+    flash_ops = &pflash_cfi01_ops_le;
 #endif
-    if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(NULL, "connext.rom",
-                                                          connex_rom),
+    memory_region_init_rom_device(flash, flash_ops,
+                                  NULL, "connext.rom", connex_rom);
+    if (!pflash_cfi01_register(0x00000000, flash,
                                dinfo->bdrv, sector_len, connex_rom / sector_len,
-                               2, 0, 0, 0, 0, be)) {
+                               2, 0, 0, 0, 0)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
         exit(1);
     }
@@ -91,7 +94,8 @@ static void verdex_init(MemoryRegion *address_space_mem,
 {
     PXA2xxState *cpu;
     DriveInfo *dinfo;
-    int be;
+    MemoryRegion *flash = g_new(MemoryRegion, 1);
+    const MemoryRegionOps *flash_ops;
 
     uint32_t verdex_rom = 0x02000000;
     uint32_t verdex_ram = 0x10000000;
@@ -106,14 +110,15 @@ static void verdex_init(MemoryRegion *address_space_mem,
     }
 
 #ifdef TARGET_WORDS_BIGENDIAN
-    be = 1;
+    flash_ops = &pflash_cfi01_ops_be;
 #else
-    be = 0;
+    flash_ops = &pflash_cfi01_ops_le;
 #endif
-    if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(NULL, "verdex.rom",
-                                                          verdex_rom),
+    memory_region_init_rom_device(flash, flash_ops,
+                                  NULL, "verdex.rom", verdex_rom);
+    if (!pflash_cfi01_register(0x00000000, flash,
                                dinfo->bdrv, sector_len, verdex_rom / sector_len,
-                               2, 0, 0, 0, 0, be)) {
+                               2, 0, 0, 0, 0)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
         exit(1);
     }
hw/lm32_boards.c +9 -6
index fced5d1..3c6b5af 100644
@@ -17,6 +17,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <glib.h>
 #include "sysbus.h"
 #include "hw.h"
 #include "net.h"
@@ -79,7 +80,7 @@ static void lm32_evr_init(MemoryRegion *address_space_mem,
     CPUState *env;
     DriveInfo *dinfo;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
+    MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq *cpu_irq, irq[32];
     ResetInfo *reset_info;
     int i;
@@ -110,13 +111,14 @@ static void lm32_evr_init(MemoryRegion *address_space_mem,
     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);
+    memory_region_init_rom_device(phys_flash, &pflash_cfi02_ops_be,
+                                  NULL, "lm32_evr.flash", flash_size);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
     pflash_cfi02_register(flash_base, phys_flash,
                           dinfo ? dinfo->bdrv : NULL, flash_sector_size,
                           flash_size / flash_sector_size, 1, 2,
-                          0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
+                          0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa);
 
     /* create irq lines */
     cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
@@ -169,7 +171,7 @@ static void lm32_uclinux_init(MemoryRegion *address_space_mem,
     CPUState *env;
     DriveInfo *dinfo;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
+    MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq *cpu_irq, irq[32];
     HWSetup *hw;
     ResetInfo *reset_info;
@@ -207,13 +209,14 @@ static void lm32_uclinux_init(MemoryRegion *address_space_mem,
     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);
+    memory_region_init_rom_device(phys_flash, &pflash_cfi01_ops_be,
+                                  NULL, "lm32_uclinux.flash", flash_size);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Spansion S29NS128P */
     pflash_cfi02_register(flash_base, phys_flash,
                           dinfo ? dinfo->bdrv : NULL, flash_sector_size,
                           flash_size / flash_sector_size, 1, 2,
-                          0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
+                          0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa);
 
     /* create irq lines */
     cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
hw/mainstone.c +12 -9
index 227f6f8..cb62abb 100644
@@ -8,6 +8,7 @@
  *
  * This code is licensed under the GNU GPL v2.
  */
+#include <glib.h>
 #include "hw.h"
 #include "pxa.h"
 #include "arm-misc.h"
@@ -101,7 +102,8 @@ static void mainstone_common_init(ram_addr_t ram_size,
     DeviceState *mst_irq;
     DriveInfo *dinfo;
     int i;
-    int be;
+    MemoryRegion *flashes = g_new(MemoryRegion, 2);
+    const MemoryRegionOps *flash_ops;
 
     if (!cpu_model)
         cpu_model = "pxa270-c5";
@@ -113,9 +115,9 @@ static void mainstone_common_init(ram_addr_t ram_size,
                                    MAINSTONE_ROM) | IO_MEM_ROM);
 
 #ifdef TARGET_WORDS_BIGENDIAN
-    be = 1;
+    flash_ops = &pflash_cfi01_ops_be;
 #else
-    be = 0;
+    flash_ops = &pflash_cfi01_ops_le;
 #endif
     /* There are two 32MiB flash devices on the board */
     for (i = 0; i < 2; i ++) {
@@ -126,13 +128,14 @@ static void mainstone_common_init(ram_addr_t ram_size,
             exit(1);
         }
 
+        memory_region_init_rom_device(&flashes[i], flash_ops,
+                                      NULL, (i ? "mainstone.flash1"
+                                               : "mainstone.flash0"),
+                                      MAINSTONE_FLASH);
         if (!pflash_cfi01_register(mainstone_flash_base[i],
-                                   qemu_ram_alloc(NULL, i ? "mainstone.flash1" :
-                                                  "mainstone.flash0",
-                                                  MAINSTONE_FLASH),
-                                   dinfo->bdrv, sector_len,
-                                   MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0,
-                                   be)) {
+                                   &flashes[i], dinfo->bdrv, sector_len,
+                                   MAINSTONE_FLASH / sector_len, 4, 0, 0, 0,
+                                   0)) {
             fprintf(stderr, "qemu: Error registering flash memory.\n");
             exit(1);
         }
hw/milkymist.c +5 -3
index e599917..74994a7 100644
@@ -17,6 +17,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <glib.h>
 #include "sysbus.h"
 #include "hw.h"
 #include "net.h"
@@ -85,7 +86,7 @@ milkymist_init(MemoryRegion *address_space_mem,
     int kernel_size;
     DriveInfo *dinfo;
     ram_addr_t phys_sdram;
-    ram_addr_t phys_flash;
+    MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq irq[32], *cpu_irq;
     int i;
     char *bios_filename;
@@ -116,13 +117,14 @@ milkymist_init(MemoryRegion *address_space_mem,
     cpu_register_physical_memory(sdram_base, sdram_size,
             phys_sdram | IO_MEM_RAM);
 
-    phys_flash = qemu_ram_alloc(NULL, "milkymist.flash", flash_size);
+    memory_region_init_rom_device(phys_flash, &pflash_cfi01_ops_be,
+                                  NULL, "milkymist.flash", flash_size);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     /* Numonyx JS28F256J3F105 */
     pflash_cfi01_register(flash_base, phys_flash,
                           dinfo ? dinfo->bdrv : NULL, flash_sector_size,
                           flash_size / flash_sector_size, 2,
-                          0x00, 0x89, 0x00, 0x1d, 1);
+                          0x00, 0x89, 0x00, 0x1d);
 
     /* create irq lines */
     cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
hw/mips_malta.c +24 -20

101 lines not on this page · raw message

hw/mips_r4k.c +11 -8
index 7a07bcd..8eec51d 100644
@@ -7,6 +7,7 @@
  * All peripherial devices are attached to this "bus" with
  * the standard PC ISA addresses.
 */
+#include <glib.h>
 #include "hw.h"
 #include "mips.h"
 #include "mips_cpudevs.h"
@@ -165,7 +166,7 @@ void mips_r4k_init (MemoryRegion *address_space_mem,
 {
     char *filename;
     ram_addr_t ram_offset;
-    ram_addr_t bios_offset;
+    MemoryRegion *bios = g_new(MemoryRegion, 1);
     int bios_size;
     CPUState *env;
     ResetData *reset_info;
@@ -229,18 +230,20 @@ void mips_r4k_init (MemoryRegion *address_space_mem,
     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);
-
+        memory_region_init_ram(bios, NULL, "mips_r4k.bios", BIOS_SIZE);
+        memory_region_set_readonly(bios, true);
+        memory_region_add_subregion(address_space_mem, 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,
+        memory_region_init_rom_device(bios,
+                                      (be ? &pflash_cfi01_ops_be
+                                          : &pflash_cfi01_ops_le),
+                                      NULL, "mips_r4k.bios", mips_rom);
+        if (!pflash_cfi01_register(0x1fc00000, bios,
                                    dinfo->bdrv, sector_len,
                                    mips_rom / sector_len,
-                                   4, 0, 0, 0, 0, be)) {
+                                   4, 0, 0, 0, 0)) {
             fprintf(stderr, "qemu: Error registering flash memory.\n");
 	}
     }
hw/musicpal.c +10 -6
index becd579..fd697bd 100644
@@ -6,6 +6,7 @@
  * This code is licensed under the GNU GPL v2.
  */
 
+#include <glib.h>
 #include "sysbus.h"
 #include "arm-misc.h"
 #include "devices.h"
@@ -1504,6 +1505,7 @@ static void musicpal_init(MemoryRegion *address_space_mem,
     unsigned long flash_size;
     DriveInfo *dinfo;
     ram_addr_t sram_off;
+    MemoryRegion *flash = g_new(MemoryRegion, 1);
 
     if (!cpu_model) {
         cpu_model = "arm926";
@@ -1567,21 +1569,23 @@ static void musicpal_init(MemoryRegion *address_space_mem,
          * 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),
+        memory_region_init_rom_device(flash, &pflash_cfi02_ops_be,
+                                      NULL, "musicpal.flash", flash_size);
+        pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, flash,
                               dinfo->bdrv, 0x10000,
                               (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
-                              0x5555, 0x2AAA, 1);
+                              0x5555, 0x2AAA);
 #else
-        pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(NULL,
-                              "musicpal.flash", flash_size),
+        memory_region_init_rom_device(flash, &pflash_cfi02_ops_le,
+                                      NULL, "musicpal.flash", flash_size);
+        pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, flash,
                               dinfo->bdrv, 0x10000,
                               (flash_size + 0xffff) >> 16,
                               MP_FLASH_SIZE_MAX / flash_size,
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
-                              0x5555, 0x2AAA, 0);
+                              0x5555, 0x2AAA);
 #endif
 
     }
hw/omap_sx1.c +13 -9
index e1cceec..35f5b79 100644
@@ -25,6 +25,7 @@
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
+#include <glib.h>
 #include "hw.h"
 #include "console.h"
 #include "omap.h"
@@ -129,7 +130,8 @@ static void sx1_init(ram_addr_t ram_size,
     DriveInfo *dinfo;
     int fl_idx;
     uint32_t flash_size = flash0_size;
-    int be;
+    const MemoryRegionOps *flash_ops;
+    MemoryRegion *flash = g_new(MemoryRegion, 2);
 
     if (version == 2) {
         flash_size = flash2_size;
@@ -155,17 +157,18 @@ static void sx1_init(ram_addr_t ram_size,
 
     fl_idx = 0;
 #ifdef TARGET_WORDS_BIGENDIAN
-    be = 1;
+    flash_ops = &pflash_cfi01_ops_be;
 #else
-    be = 0;
+    flash_ops = &pflash_cfi01_ops_le;
 #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),
+        memory_region_init_rom_device(&flash[0], flash_ops,
+                                      NULL, "omap_sx1.flash0-1", flash_size);
+        if (!pflash_cfi01_register(OMAP_CS0_BASE, &flash[0],
                                    dinfo->bdrv, sector_size,
                                    flash_size / sector_size,
-                                   4, 0, 0, 0, 0, be)) {
+                                   4, 0, 0, 0, 0)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                            fl_idx);
         }
@@ -182,11 +185,12 @@ 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),
+        memory_region_init_rom_device(&flash[1], flash_ops,
+                                      NULL, "omap_sx1.flash1-1", flash1_size);
+        if (!pflash_cfi01_register(OMAP_CS1_BASE, &flash[1],
                                    dinfo->bdrv, sector_size,
                                    flash1_size / sector_size,
-                                   4, 0, 0, 0, 0, be)) {
+                                   4, 0, 0, 0, 0)) {
             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
                            fl_idx);
         }
hw/petalogix_ml605_mmu.c +5 -3
index b0758ea..c76d229 100644
@@ -25,6 +25,7 @@
  * THE SOFTWARE.
  */
 
+#include <glib.h>
 #include "sysbus.h"
 #include "hw.h"
 #include "net.h"
@@ -150,7 +151,7 @@ petalogix_ml605_init(MemoryRegion *address_space_mem,
     target_phys_addr_t ddr_base = MEMORY_BASEADDR;
     ram_addr_t phys_lmb_bram;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
+    MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq irq[32], *cpu_irq;
 
     /* init CPUs */
@@ -170,14 +171,15 @@ petalogix_ml605_init(MemoryRegion *address_space_mem,
     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);
+    memory_region_init_rom_device(phys_flash, &pflash_cfi01_ops_le,
+                                  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,
                           dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                           FLASH_SIZE >> 16,
-                          2, 0x89, 0x18, 0x0000, 0x0, 0);
+                          2, 0x89, 0x18, 0x0000, 0x0);
 
 
     cpu_irq = microblaze_pic_init_cpu(env);
hw/petalogix_s3adsp1800_mmu.c +6 -3
index b5d9f8a..aa29e57 100644
@@ -23,6 +23,7 @@
  * THE SOFTWARE.
  */
 
+#include <glib.h>
 #include "sysbus.h"
 #include "hw.h"
 #include "net.h"
@@ -127,7 +128,7 @@ petalogix_s3adsp1800_init(MemoryRegion *address_space_mem,
     target_phys_addr_t ddr_base = 0x90000000;
     ram_addr_t phys_lmb_bram;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
+    MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq irq[32], *cpu_irq;
 
     /* init CPUs */
@@ -148,12 +149,14 @@ petalogix_s3adsp1800_init(MemoryRegion *address_space_mem,
     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);
+    memory_region_init_rom_device(phys_flash, &pflash_cfi01_ops_be,
+                                  NULL, "petalogix_s3adsp1800.flash",
+                                  FLASH_SIZE);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(0xa0000000, phys_flash,
                           dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                           FLASH_SIZE >> 16,
-                          1, 0x89, 0x18, 0x0000, 0x0, 1);
+                          1, 0x89, 0x18, 0x0000, 0x0);
 
     cpu_irq = microblaze_pic_init_cpu(env);
     dev = xilinx_intc_create(0x81800000, cpu_irq[0], 2);
hw/pflash_cfi01.c +23 -44

126 lines not on this page · raw message

hw/pflash_cfi02.c +47 -48

154 lines not on this page · raw message

hw/ppc405_boards.c +33 -28

141 lines not on this page · raw message

hw/r2d.c +6 -2
index 923fd4e..5bd5633 100644
@@ -23,6 +23,7 @@
  * THE SOFTWARE.
  */
 
+#include <glib.h>
 #include "sysbus.h"
 #include "hw.h"
 #include "sh.h"
@@ -237,6 +238,7 @@ static void r2d_init(MemoryRegion *address_space_mem,
     qemu_irq *irq;
     DriveInfo *dinfo;
     int i;
+    MemoryRegion *flash = g_new(MemoryRegion, 1);
 
     if (!cpu_model)
         cpu_model = "SH7751R";
@@ -269,11 +271,13 @@ static void r2d_init(MemoryRegion *address_space_mem,
 
     /* onboard flash memory */
     dinfo = drive_get(IF_PFLASH, 0, 0);
-    pflash_cfi02_register(0x0, qemu_ram_alloc(NULL, "r2d.flash", FLASH_SIZE),
+    memory_region_init_rom_device(flash, &pflash_cfi02_ops_le,
+                                  NULL, "r2d.flash", FLASH_SIZE);
+    pflash_cfi02_register(0x0, flash,
                           dinfo ? dinfo->bdrv : NULL, (16 * 1024),
                           FLASH_SIZE >> 16,
                           1, 4, 0x0000, 0x0000, 0x0000, 0x0000,
-                          0x555, 0x2aa, 0);
+                          0x555, 0x2aa);
 
     /* NIC: rtl8139 on-board, and 2 slots. */
     for (i = 0; i < nb_nics; i++)
hw/virtex_ml507.c +5 -3
index 4503851..35982ff 100644
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include <glib.h>
 #include "sysbus.h"
 #include "hw.h"
 #include "pc.h"
@@ -198,7 +199,7 @@ static void virtex_init(MemoryRegion *address_space_mem,
     target_phys_addr_t ram_base = 0;
     DriveInfo *dinfo;
     ram_addr_t phys_ram;
-    ram_addr_t phys_flash;
+    MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq irq[32], *cpu_irq;
     clk_setup_t clk_setup[7];
     int kernel_size;
@@ -217,12 +218,13 @@ static void virtex_init(MemoryRegion *address_space_mem,
     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);
+    memory_region_init_rom_device(phys_flash, &pflash_cfi01_ops_be,
+                                  NULL, "virtex.flash", FLASH_SIZE);
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(0xfc000000, phys_flash,
                           dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                           FLASH_SIZE >> 16,
-                          1, 0x89, 0x18, 0x0000, 0x0, 1);
+                          1, 0x89, 0x18, 0x0000, 0x0);
 
     cpu_irq = (qemu_irq *) &env->irq_inputs[PPC40x_INPUT_INT];
     dev = xilinx_intc_create(0x81800000, cpu_irq[0], 0);
hw/z2.c +9 -7
index f1db41b..a6a4761 100644
@@ -8,6 +8,7 @@
  * This code is licensed under the GNU GPL v2.
  */
 
+#include <glib.h>
 #include "hw.h"
 #include "pxa.h"
 #include "arm-misc.h"
@@ -282,10 +283,11 @@ static void z2_init(MemoryRegion *address_space_mem,
     uint32_t sector_len = 0x10000;
     PXA2xxState *cpu;
     DriveInfo *dinfo;
-    int be;
+    const MemoryRegionOps *flash_ops;
     void *z2_lcd;
     i2c_bus *bus;
     DeviceState *wm;
+    MemoryRegion *flash = g_new(MemoryRegion, 1);
 
     if (!cpu_model) {
         cpu_model = "pxa270-c5";
@@ -295,9 +297,9 @@ static void z2_init(MemoryRegion *address_space_mem,
     cpu = pxa270_init(z2_binfo.ram_size, cpu_model);
 
 #ifdef TARGET_WORDS_BIGENDIAN
-    be = 1;
+    flash_ops = &pflash_cfi01_ops_be;
 #else
-    be = 0;
+    flash_ops = &pflash_cfi01_ops_le;
 #endif
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if (!dinfo) {
@@ -306,11 +308,11 @@ static void z2_init(MemoryRegion *address_space_mem,
         exit(1);
     }
 
-    if (!pflash_cfi01_register(Z2_FLASH_BASE,
-                               qemu_ram_alloc(NULL, "z2.flash0", Z2_FLASH_SIZE),
+    memory_region_init_rom_device(flash, flash_ops,
+                                  NULL, "z2.flash0", Z2_FLASH_SIZE);
+    if (!pflash_cfi01_register(Z2_FLASH_BASE, flash,
                                dinfo->bdrv, sector_len,
-                               Z2_FLASH_SIZE / sector_len, 4, 0, 0, 0, 0,
-                               be)) {
+                               Z2_FLASH_SIZE / sector_len, 4, 0, 0, 0, 0)) {
         fprintf(stderr, "qemu: Error registering flash memory.\n");
         exit(1);
     }
Signature · 1 line
1.7.5.3
author
#26 lore raw

PATCH 17/24 dummy_m68k: convert to memory API

In reply to Avi Kivity
---
 hw/dummy_m68k.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/dummy_m68k.c +4 -2
index 2de69ad..609d04c 100644
@@ -6,6 +6,7 @@
  * This code is licensed under the GPL
  */
 
+#include <glib.h>
 #include "hw.h"
 #include "boards.h"
 #include "loader.h"
@@ -23,6 +24,7 @@ static void dummy_m68k_init(MemoryRegion *address_space_mem,
                      const char *initrd_filename, const char *cpu_model)
 {
     CPUState *env;
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
     int kernel_size;
     uint64_t elf_entry;
     target_phys_addr_t entry;
@@ -39,8 +41,8 @@ static void dummy_m68k_init(MemoryRegion *address_space_mem,
     env->vbr = 0;
 
     /* RAM at address zero */
-    cpu_register_physical_memory(0, ram_size,
-        qemu_ram_alloc(NULL, "dummy_m68k.ram", ram_size) | IO_MEM_RAM);
+    memory_region_init_ram(ram, NULL, "dummy_m68k.ram", ram_size);
+    memory_region_add_subregion(address_space_mem, 0, ram);
 
     /* Load kernel.  */
     if (kernel_filename) {
Signature · 1 line
1.7.5.3
author
#27 lore raw

PATCH 18/24 g364fb: convert to memory API

In reply to Avi Kivity
---
 hw/g364fb.c    |   61 +++++++++++++++++++++++++++++++------------------------
 hw/mips.h      |    4 ++-
 hw/mips_jazz.c |    3 +-
 3 files changed, 39 insertions(+), 29 deletions(-)
hw/g364fb.c +34 -27
index b3020c5..d081bb4 100644
@@ -17,6 +17,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <glib.h>
 #include "hw.h"
 #include "mips.h"
 #include "console.h"
@@ -36,7 +37,7 @@ do { fprintf(stderr, "g364 ERROR: " fmt , ## __VA_ARGS__);} while (0)
 typedef struct G364State {
     /* hardware */
     uint8_t *vram;
-    ram_addr_t vram_offset;
+    MemoryRegion vram_region;
     int vram_size;
     qemu_irq irq;
     /* registers */
@@ -68,16 +69,17 @@ typedef struct G364State {
 #define CTLA_FORCE_BLANK 0x00000400
 #define CTLA_NO_CURSOR   0x00800000
 
-static inline int check_dirty(ram_addr_t page)
+static inline int check_dirty(G364State *s, ram_addr_t page)
 {
-    return cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG);
+    return memory_region_get_dirty(&s->vram_region, page, DIRTY_MEMORY_VGA);
 }
 
 static inline void reset_dirty(G364State *s,
                                ram_addr_t page_min, ram_addr_t page_max)
 {
-    cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE - 1,
-                                    VGA_DIRTY_FLAG);
+    memory_region_reset_dirty(&s->vram_region, page_min,
+                              page_max + TARGET_PAGE_SIZE - 1,
+                              DIRTY_MEMORY_VGA);
 }
 
 static void g364fb_draw_graphic8(G364State *s)
@@ -114,7 +116,7 @@ static void g364fb_draw_graphic8(G364State *s)
             return;
     }
 
-    page = s->vram_offset;
+    page = 0;
     page_min = (ram_addr_t)-1;
     page_max = 0;
 
@@ -135,7 +137,7 @@ static void g364fb_draw_graphic8(G364State *s)
     /* XXX: out of range in vram? */
     data_display = dd = ds_get_data(s->ds);
     while (y < s->height) {
-        if (check_dirty(page)) {
+        if (check_dirty(s, page)) {
             if (y < ymin)
                 ymin = ymax = y;
             if (page_min == (ram_addr_t)-1)
@@ -275,7 +277,7 @@ static inline void g364fb_invalidate_display(void *opaque)
 
     s->blanked = 0;
     for (i = 0; i < s->vram_size; i += TARGET_PAGE_SIZE) {
-        cpu_physical_memory_set_dirty(s->vram_offset + i);
+        memory_region_set_dirty(&s->vram_region, i);
     }
 }
 
@@ -411,7 +413,7 @@ static void g364_invalidate_cursor_position(G364State *s)
     end = (ymax + 1) * ds_get_linesize(s->ds);
 
     for (i = start; i < end; i += TARGET_PAGE_SIZE) {
-        cpu_physical_memory_set_dirty(s->vram_offset + i);
+        memory_region_set_dirty(&s->vram_region, i);
     }
 }
 
@@ -522,16 +524,20 @@ static void g364fb_ctrl_writeb(void *opaque, target_phys_addr_t addr, uint32_t v
     g364fb_ctrl_writel(opaque, addr & ~0x3, val);
 }
 
-static CPUReadMemoryFunc * const g364fb_ctrl_read[3] = {
-    g364fb_ctrl_readb,
-    g364fb_ctrl_readw,
-    g364fb_ctrl_readl,
-};
-
-static CPUWriteMemoryFunc * const g364fb_ctrl_write[3] = {
-    g364fb_ctrl_writeb,
-    g364fb_ctrl_writew,
-    g364fb_ctrl_writel,
+static const MemoryRegionOps g364fb_ctrl_ops = {
+    .old_mmio = {
+        .read = {
+            g364fb_ctrl_readb,
+            g364fb_ctrl_readw,
+            g364fb_ctrl_readl,
+        },
+        .write = {
+            g364fb_ctrl_writeb,
+            g364fb_ctrl_writew,
+            g364fb_ctrl_writel,
+        },
+    },
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static int g364fb_load(QEMUFile *f, void *opaque, int version_id)
@@ -583,18 +589,19 @@ static void g364fb_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->height);
 }
 
-int g364fb_mm_init(target_phys_addr_t vram_base,
+int g364fb_mm_init(MemoryRegion *system_memory,
+                   target_phys_addr_t vram_base,
                    target_phys_addr_t ctrl_base, int it_shift,
                    qemu_irq irq)
 {
     G364State *s;
-    int io_ctrl;
+    MemoryRegion *io_ctrl = g_new(MemoryRegion, 1);
 
     s = g_malloc0(sizeof(G364State));
 
     s->vram_size = 8 * 1024 * 1024;
-    s->vram_offset = qemu_ram_alloc(NULL, "g364fb.vram", s->vram_size);
-    s->vram = qemu_get_ram_ptr(s->vram_offset);
+    memory_region_init_ram(&s->vram_region, NULL, "g364fb.vram", s->vram_size);
+    s->vram = memory_region_get_ram_ptr(&s->vram_region);
     s->irq = irq;
 
     qemu_register_reset(g364fb_reset, s);
@@ -605,11 +612,11 @@ int g364fb_mm_init(target_phys_addr_t vram_base,
                                  g364fb_invalidate_display,
                                  g364fb_screen_dump, NULL, s);
 
-    cpu_register_physical_memory(vram_base, s->vram_size, s->vram_offset);
+    memory_region_add_subregion(system_memory, vram_base, &s->vram_region);
 
-    io_ctrl = cpu_register_io_memory(g364fb_ctrl_read, g364fb_ctrl_write, s,
-                                     DEVICE_NATIVE_ENDIAN);
-    cpu_register_physical_memory(ctrl_base, 0x200000, io_ctrl);
+    memory_region_init_io(io_ctrl, &g364fb_ctrl_ops, s,
+                          "g364fb-ctrl", 0x200000);
+    memory_region_add_subregion(system_memory, ctrl_base, io_ctrl);
 
     return 0;
 }
hw/mips.h +3 -1
index cae5f4c..97d7b9e 100644
@@ -2,6 +2,8 @@
 #define HW_MIPS_H
 /* Definitions for mips board emulation.  */
 
+#include "memory.h"
+
 /* gt64xxx.c */
 PCIBus *gt64120_register(qemu_irq *pic);
 
@@ -9,7 +11,7 @@ PCIBus *gt64120_register(qemu_irq *pic);
 PCIBus *bonito_init(qemu_irq *pic);
 
 /* g364fb.c */
-int g364fb_mm_init(target_phys_addr_t vram_base,
+int g364fb_mm_init(MemoryRegion *system_memory, target_phys_addr_t vram_base,
                    target_phys_addr_t ctrl_base, int it_shift,
                    qemu_irq irq);
 
hw/mips_jazz.c +2 -1
index d6fb82a..9ee4208 100644
@@ -195,7 +195,8 @@ void mips_jazz_init (ram_addr_t ram_size,
     /* Video card */
     switch (jazz_model) {
     case JAZZ_MAGNUM:
-        g364fb_mm_init(0x40000000, 0x60000000, 0, rc4030[3]);
+        g364fb_mm_init(get_system_memory(), 0x40000000, 0x60000000, 0,
+                       rc4030[3]);
         break;
     case JAZZ_PICA61:
         isa_vga_mm_init(0x40000000, 0x60000000, 0, get_system_memory());
Signature · 1 line
1.7.5.3
author
#28 lore raw

PATCH 19/24 lm32_boards: convert to memory API

In reply to Avi Kivity
---
 hw/lm32_boards.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/lm32_boards.c +6 -6
index 3c6b5af..0a9ad59 100644
@@ -79,7 +79,7 @@ static void lm32_evr_init(MemoryRegion *address_space_mem,
 {
     CPUState *env;
     DriveInfo *dinfo;
-    ram_addr_t phys_ram;
+    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
     MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq *cpu_irq, irq[32];
     ResetInfo *reset_info;
@@ -108,8 +108,8 @@ static void lm32_evr_init(MemoryRegion *address_space_mem,
 
     reset_info->flash_base = flash_base;
 
-    phys_ram = qemu_ram_alloc(NULL, "lm32_evr.sdram", ram_size);
-    cpu_register_physical_memory(ram_base, ram_size, phys_ram | IO_MEM_RAM);
+    memory_region_init_ram(phys_ram, NULL, "lm32_evr.sdram", ram_size);
+    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
 
     memory_region_init_rom_device(phys_flash, &pflash_cfi02_ops_be,
                                   NULL, "lm32_evr.flash", flash_size);
@@ -170,7 +170,7 @@ static void lm32_uclinux_init(MemoryRegion *address_space_mem,
 {
     CPUState *env;
     DriveInfo *dinfo;
-    ram_addr_t phys_ram;
+    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
     MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq *cpu_irq, irq[32];
     HWSetup *hw;
@@ -206,8 +206,8 @@ static void lm32_uclinux_init(MemoryRegion *address_space_mem,
 
     reset_info->flash_base = flash_base;
 
-    phys_ram = qemu_ram_alloc(NULL, "lm32_uclinux.sdram", ram_size);
-    cpu_register_physical_memory(ram_base, ram_size, phys_ram | IO_MEM_RAM);
+    memory_region_init_ram(phys_ram, NULL, "lm32_uclinux.sdram", ram_size);
+    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
 
     memory_region_init_rom_device(phys_flash, &pflash_cfi01_ops_be,
                                   NULL, "lm32_uclinux.flash", flash_size);
Signature · 1 line
1.7.5.3
author
#29 lore raw

PATCH 20/24 mainstone: convert to memory API

In reply to Avi Kivity
---
 hw/mainstone.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
hw/mainstone.c +7 -5
index cb62abb..ae7a542 100644
@@ -91,7 +91,8 @@ static struct arm_boot_info mainstone_binfo = {
     .ram_size = 0x04000000,
 };
 
-static void mainstone_common_init(ram_addr_t ram_size,
+static void mainstone_common_init(MemoryRegion *address_space_mem,
+                ram_addr_t ram_size,
                 const char *kernel_filename,
                 const char *kernel_cmdline, const char *initrd_filename,
                 const char *cpu_model, enum mainstone_model_e model, int arm_id)
@@ -102,6 +103,7 @@ static void mainstone_common_init(ram_addr_t ram_size,
     DeviceState *mst_irq;
     DriveInfo *dinfo;
     int i;
+    MemoryRegion *rom = g_new(MemoryRegion, 1);
     MemoryRegion *flashes = g_new(MemoryRegion, 2);
     const MemoryRegionOps *flash_ops;
 
@@ -110,9 +112,9 @@ static void mainstone_common_init(ram_addr_t ram_size,
 
     /* Setup CPU & memory */
     cpu = pxa270_init(mainstone_binfo.ram_size, cpu_model);
-    cpu_register_physical_memory(0, MAINSTONE_ROM,
-                    qemu_ram_alloc(NULL, "mainstone.rom",
-                                   MAINSTONE_ROM) | IO_MEM_ROM);
+    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM);
+    memory_region_set_readonly(rom, true);
+    memory_region_add_subregion(address_space_mem, 0, rom);
 
 #ifdef TARGET_WORDS_BIGENDIAN
     flash_ops = &pflash_cfi01_ops_be;
@@ -175,7 +177,7 @@ static void mainstone_init(MemoryRegion *address_space_mem,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
-    mainstone_common_init(ram_size, kernel_filename,
+    mainstone_common_init(address_space_mem, ram_size, kernel_filename,
                 kernel_cmdline, initrd_filename, cpu_model, mainstone, 0x196);
 }
 
Signature · 1 line
1.7.5.3
author
#30 lore raw

PATCH 21/24 mcf5208: convert to memory API

In reply to Avi Kivity
---
 hw/mcf5208.c |   71 +++++++++++++++++++++++++--------------------------------
 1 files changed, 31 insertions(+), 40 deletions(-)
hw/mcf5208.c +31 -40
index f4d4fbd..73c6961 100644
@@ -5,6 +5,7 @@
  *
  * This code is licensed under the GPL
  */
+#include <glib.h>
 #include "hw.h"
 #include "mcf.h"
 #include "qemu-timer.h"
@@ -27,6 +28,7 @@
 #define PCSR_PRE_MASK   0x0f00
 
 typedef struct {
+    MemoryRegion iomem;
     qemu_irq irq;
     ptimer_state *timer;
     uint16_t pcsr;
@@ -43,7 +45,7 @@ static void m5208_timer_update(m5208_timer_state *s)
 }
 
 static void m5208_timer_write(void *opaque, target_phys_addr_t offset,
-                              uint32_t value)
+                              uint64_t value, unsigned size)
 {
     m5208_timer_state *s = (m5208_timer_state *)opaque;
     int prescale;
@@ -104,7 +106,8 @@ static void m5208_timer_trigger(void *opaque)
     m5208_timer_update(s);
 }
 
-static uint32_t m5208_timer_read(void *opaque, target_phys_addr_t addr)
+static uint64_t m5208_timer_read(void *opaque, target_phys_addr_t addr,
+                                 unsigned size)
 {
     m5208_timer_state *s = (m5208_timer_state *)opaque;
     switch (addr) {
@@ -120,19 +123,14 @@ static uint32_t m5208_timer_read(void *opaque, target_phys_addr_t addr)
     }
 }
 
-static CPUReadMemoryFunc * const m5208_timer_readfn[] = {
-   m5208_timer_read,
-   m5208_timer_read,
-   m5208_timer_read
+static const MemoryRegionOps m5208_timer_ops = {
+    .read = m5208_timer_read,
+    .write = m5208_timer_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static CPUWriteMemoryFunc * const m5208_timer_writefn[] = {
-   m5208_timer_write,
-   m5208_timer_write,
-   m5208_timer_write
-};
-
-static uint32_t m5208_sys_read(void *opaque, target_phys_addr_t addr)
+static uint64_t m5208_sys_read(void *opaque, target_phys_addr_t addr,
+                               unsigned size)
 {
     switch (addr) {
     case 0x110: /* SDCS0 */
@@ -154,45 +152,36 @@ static uint32_t m5208_sys_read(void *opaque, target_phys_addr_t addr)
 }
 
 static void m5208_sys_write(void *opaque, target_phys_addr_t addr,
-                            uint32_t value)
+                            uint64_t value, unsigned size)
 {
     hw_error("m5208_sys_write: Bad offset 0x%x\n", (int)addr);
 }
 
-static CPUReadMemoryFunc * const m5208_sys_readfn[] = {
-   m5208_sys_read,
-   m5208_sys_read,
-   m5208_sys_read
-};
-
-static CPUWriteMemoryFunc * const m5208_sys_writefn[] = {
-   m5208_sys_write,
-   m5208_sys_write,
-   m5208_sys_write
+static const MemoryRegionOps m5208_sys_ops = {
+    .read = m5208_sys_read,
+    .write = m5208_sys_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void mcf5208_sys_init(qemu_irq *pic)
+static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic)
 {
-    int iomemtype;
+    MemoryRegion *iomem = g_new(MemoryRegion, 1);
     m5208_timer_state *s;
     QEMUBH *bh;
     int i;
 
-    iomemtype = cpu_register_io_memory(m5208_sys_readfn,
-                                       m5208_sys_writefn, NULL,
-                                       DEVICE_NATIVE_ENDIAN);
     /* SDRAMC.  */
-    cpu_register_physical_memory(0xfc0a8000, 0x00004000, iomemtype);
+    memory_region_init_io(iomem, &m5208_sys_ops, NULL, "m5208-sys", 0x00004000);
+    memory_region_add_subregion(address_space, 0xfc0a8000, iomem);
     /* Timers.  */
     for (i = 0; i < 2; i++) {
         s = (m5208_timer_state *)g_malloc0(sizeof(m5208_timer_state));
         bh = qemu_bh_new(m5208_timer_trigger, s);
         s->timer = ptimer_init(bh);
-        iomemtype = cpu_register_io_memory(m5208_timer_readfn,
-                                           m5208_timer_writefn, s,
-                                           DEVICE_NATIVE_ENDIAN);
-        cpu_register_physical_memory(0xfc080000 + 0x4000 * i, 0x00004000,
-                                     iomemtype);
+        memory_region_init_io(&s->iomem, &m5208_timer_ops, s,
+                              "m5208-timer", 0x00004000);
+        memory_region_add_subregion(address_space, 0xfc080000 + 0x4000 * i,
+                                    &s->iomem);
         s->irq = pic[4 + i];
     }
 }
@@ -209,6 +198,8 @@ static void mcf5208evb_init(MemoryRegion *address_space_mem,
     uint64_t elf_entry;
     target_phys_addr_t entry;
     qemu_irq *pic;
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
+    MemoryRegion *sram = g_new(MemoryRegion, 1);
 
     if (!cpu_model)
         cpu_model = "m5208";
@@ -223,12 +214,12 @@ static void mcf5208evb_init(MemoryRegion *address_space_mem,
     /* TODO: Configure BARs.  */
 
     /* DRAM at 0x40000000 */
-    cpu_register_physical_memory(0x40000000, ram_size,
-        qemu_ram_alloc(NULL, "mcf5208.ram", ram_size) | IO_MEM_RAM);
+    memory_region_init_ram(ram, NULL, "mcf5208.ram", ram_size);
+    memory_region_add_subregion(address_space_mem, 0x40000000, ram);
 
     /* Internal SRAM.  */
-    cpu_register_physical_memory(0x80000000, 16384,
-        qemu_ram_alloc(NULL, "mcf5208.sram", 16384) | IO_MEM_RAM);
+    memory_region_init_ram(sram, NULL, "mcf5208.sram", 16384);
+    memory_region_add_subregion(address_space_mem, 0x80000000, sram);
 
     /* Internal peripherals.  */
     pic = mcf_intc_init(0xfc048000, env);
@@ -237,7 +228,7 @@ static void mcf5208evb_init(MemoryRegion *address_space_mem,
     mcf_uart_mm_init(0xfc064000, pic[27], serial_hds[1]);
     mcf_uart_mm_init(0xfc068000, pic[28], serial_hds[2]);
 
-    mcf5208_sys_init(pic);
+    mcf5208_sys_init(address_space_mem, pic);
 
     if (nb_nics > 1) {
         fprintf(stderr, "Too many NICs\n");
Signature · 1 line
1.7.5.3
#31 lore raw

Re: [Qemu-devel] [PATCH 21/24] mcf5208: convert to memory API

hw/mcf5208.c line 11

Quoted 12 lines · Avi Kivity
hw/mcf5208.c +1 -0
index f4d4fbd..73c6961 100644
@@ -5,6 +5,7 @@
  *
  * This code is licensed under the GPL
  */
+#include <glib.h>
  #include "hw.h"
  #include "mcf.h"
  #include "qemu-timer.h"

You shouldn't need to include glib.h here, I think? hw.h includes qemu-common.h which includes glib.h.

-- PMM

author
#32 lore raw

Re: [Qemu-devel] [PATCH 21/24] mcf5208: convert to memory API

Quoted 14 lines · Peter Maydell
Quoted 9 lines · Avi Kivity

diff --git a/hw/mcf5208.c b/hw/mcf5208.c
index f4d4fbd..73c6961 100644
--- a/hw/mcf5208.c
+++ b/hw/mcf5208.c
@@ -5,6 +5,7 @@
*
* This code is licensed under the GPL
*/
+#include<glib.h>

Quoted 3 lines
   #include "hw.h"
   #include "mcf.h"
   #include "qemu-timer.h"
Quoted 3 lines

You shouldn't need to include glib.h here, I think? hw.h includes qemu-common.h which includes glib.h.

My preference is not to depend on indirect includes; but I can remove this include if it's disliked by many.

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

Re: [Qemu-devel] [PATCH 21/24] mcf5208: convert to memory API

Quoted 16 lines · Avi Kivity
Quoted 15 lines · Peter Maydell
Quoted 12 lines · Avi Kivity

 diff --git a/hw/mcf5208.c b/hw/mcf5208.c
 index f4d4fbd..73c6961 100644
 --- a/hw/mcf5208.c
 +++ b/hw/mcf5208.c
 @@ -5,6 +5,7 @@
   *
   * This code is licensed under the GPL
   */
 +#include<glib.h>
   #include "hw.h"
   #include "mcf.h"
   #include "qemu-timer.h"

Quoted 7 lines
Quoted 4 lines

You shouldn't need to include glib.h here, I think? hw.h includes qemu-common.h
which includes glib.h.

My preference is not to depend on indirect includes; but I can remove this include if it's disliked by many.

qemu-common.h says
/* we put basic includes here to avoid repeating them in device drivers */

so direct includes of system headers in hw/ files is going against current practice. I don't feel strongly either way on the question of direct vs indirect, but we should be consistent, and the choice we've made is "rely on qemu-common.h".

-- PMM

author
#34 lore raw

Re: [Qemu-devel] [PATCH 21/24] mcf5208: convert to memory API

Quoted 25 lines · Peter Maydell
Quoted 16 lines · Avi Kivity
Quoted 15 lines · Peter Maydell
Quoted 12 lines · Avi Kivity
   diff --git a/hw/mcf5208.c b/hw/mcf5208.c
   index f4d4fbd..73c6961 100644
   --- a/hw/mcf5208.c
   +++ b/hw/mcf5208.c
   @@ -5,6 +5,7 @@
     *
     * This code is licensed under the GPL
     */
   +#include<glib.h>
     #include "hw.h"
     #include "mcf.h"
     #include "qemu-timer.h"
Quoted 7 lines
Quoted 4 lines

You shouldn't need to include glib.h here, I think? hw.h includes qemu-common.h
which includes glib.h.

My preference is not to depend on indirect includes; but I can remove this include if it's disliked by many.

Quoted 8 lines

qemu-common.h says
/* we put basic includes here to avoid repeating them in device drivers */

so direct includes of system headers in hw/ files is going against current practice. I don't feel strongly either way on the question of direct vs indirect, but we should be consistent, and the choice we've made is "rely on qemu-common.h".

Okay, I'll drop the include (here and elsewhere).

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

PATCH 22/24 milkymist-minimac2: convert to memory API

In reply to Avi Kivity
---
 hw/milkymist-minimac2.c |   43 +++++++++++++++++++++----------------------
 1 files changed, 21 insertions(+), 22 deletions(-)
hw/milkymist-minimac2.c +21 -22
index cd36026..fb48e37 100644
@@ -97,6 +97,8 @@ struct MilkymistMinimac2State {
     NICConf conf;
     char *phy_model;
     target_phys_addr_t buffers_base;
+    MemoryRegion buffers;
+    MemoryRegion regs_region;
 
     qemu_irq rx_irq;
     qemu_irq tx_irq;
@@ -320,8 +322,8 @@ static ssize_t minimac2_rx(VLANClientState *nc, const uint8_t *buf, size_t size)
     return size;
 }
 
-static uint32_t
-minimac2_read(void *opaque, target_phys_addr_t addr)
+static uint64_t
+minimac2_read(void *opaque, target_phys_addr_t addr, unsigned size)
 {
     MilkymistMinimac2State *s = opaque;
     uint32_t r = 0;
@@ -350,7 +352,8 @@ minimac2_read(void *opaque, target_phys_addr_t addr)
 }
 
 static void
-minimac2_write(void *opaque, target_phys_addr_t addr, uint32_t value)
+minimac2_write(void *opaque, target_phys_addr_t addr, uint64_t value,
+               unsigned size)
 {
     MilkymistMinimac2State *s = opaque;
 
@@ -395,16 +398,14 @@ minimac2_write(void *opaque, target_phys_addr_t addr, uint32_t value)
     }
 }
 
-static CPUReadMemoryFunc * const minimac2_read_fn[] = {
-    NULL,
-    NULL,
-    &minimac2_read,
-};
-
-static CPUWriteMemoryFunc * const minimac2_write_fn[] = {
-    NULL,
-    NULL,
-    &minimac2_write,
+static const MemoryRegionOps minimac2_ops = {
+    .read = minimac2_read,
+    .write = minimac2_write,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static int minimac2_can_rx(VLANClientState *nc)
@@ -457,25 +458,23 @@ static NetClientInfo net_milkymist_minimac2_info = {
 static int milkymist_minimac2_init(SysBusDevice *dev)
 {
     MilkymistMinimac2State *s = FROM_SYSBUS(typeof(*s), dev);
-    int regs;
-    ram_addr_t buffers;
     size_t buffers_size = TARGET_PAGE_ALIGN(3 * MINIMAC2_BUFFER_SIZE);
 
     sysbus_init_irq(dev, &s->rx_irq);
     sysbus_init_irq(dev, &s->tx_irq);
 
-    regs = cpu_register_io_memory(minimac2_read_fn, minimac2_write_fn, s,
-            DEVICE_NATIVE_ENDIAN);
-    sysbus_init_mmio(dev, R_MAX * 4, regs);
+    memory_region_init_io(&s->regs_region, &minimac2_ops, s,
+                          "minimac2-mmio", R_MAX * 4);
+    sysbus_init_mmio_region(dev, &s->regs_region);
 
     /* register buffers memory */
-    buffers = qemu_ram_alloc(NULL, "milkymist_minimac2.buffers", buffers_size);
-    s->rx0_buf = qemu_get_ram_ptr(buffers);
+    memory_region_init_ram(&s->buffers, NULL, "milkymist_minimac2.buffers",
+                           buffers_size);
+    s->rx0_buf = memory_region_get_ram_ptr(&s->buffers);
     s->rx1_buf = s->rx0_buf + MINIMAC2_BUFFER_SIZE;
     s->tx_buf = s->rx1_buf + MINIMAC2_BUFFER_SIZE;
 
-    cpu_register_physical_memory(s->buffers_base, buffers_size,
-            buffers | IO_MEM_RAM);
+    sysbus_add_memory(dev, s->buffers_base, &s->buffers);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(&net_milkymist_minimac2_info, &s->conf,
Signature · 1 line
1.7.5.3
author
#36 lore raw

PATCH 23/24 milkymist-softusb: convert to memory API

In reply to Avi Kivity
---
 hw/milkymist-softusb.c |   48 ++++++++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 24 deletions(-)
hw/milkymist-softusb.c +24 -24
index fe4eedb..ef4d9ee 100644
@@ -49,6 +49,9 @@ struct MilkymistSoftUsbState {
     HIDState hid_kbd;
     HIDState hid_mouse;
 
+    MemoryRegion regs_region;
+    MemoryRegion pmem;
+    MemoryRegion dmem;
     qemu_irq irq;
 
     /* device properties */
@@ -68,7 +71,8 @@ struct MilkymistSoftUsbState {
 };
 typedef struct MilkymistSoftUsbState MilkymistSoftUsbState;
 
-static uint32_t softusb_read(void *opaque, target_phys_addr_t addr)
+static uint64_t softusb_read(void *opaque, target_phys_addr_t addr,
+                             unsigned size)
 {
     MilkymistSoftUsbState *s = opaque;
     uint32_t r = 0;
@@ -91,7 +95,8 @@ static uint32_t softusb_read(void *opaque, target_phys_addr_t addr)
 }
 
 static void
-softusb_write(void *opaque, target_phys_addr_t addr, uint32_t value)
+softusb_write(void *opaque, target_phys_addr_t addr, uint64_t value,
+              unsigned size)
 {
     MilkymistSoftUsbState *s = opaque;
 
@@ -110,16 +115,14 @@ softusb_write(void *opaque, target_phys_addr_t addr, uint32_t value)
     }
 }
 
-static CPUReadMemoryFunc * const softusb_read_fn[] = {
-    NULL,
-    NULL,
-    &softusb_read,
-};
-
-static CPUWriteMemoryFunc * const softusb_write_fn[] = {
-    NULL,
-    NULL,
-    &softusb_write,
+static const MemoryRegionOps softusb_mmio_ops = {
+    .read = softusb_read,
+    .write = softusb_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
 };
 
 static inline void softusb_read_dmem(MilkymistSoftUsbState *s,
@@ -256,23 +259,20 @@ static void milkymist_softusb_reset(DeviceState *d)
 static int milkymist_softusb_init(SysBusDevice *dev)
 {
     MilkymistSoftUsbState *s = FROM_SYSBUS(typeof(*s), dev);
-    int softusb_regs;
-    ram_addr_t pmem_ram;
-    ram_addr_t dmem_ram;
 
     sysbus_init_irq(dev, &s->irq);
 
-    softusb_regs = cpu_register_io_memory(softusb_read_fn, softusb_write_fn, s,
-            DEVICE_NATIVE_ENDIAN);
-    sysbus_init_mmio(dev, R_MAX * 4, softusb_regs);
+    memory_region_init_io(&s->regs_region, &softusb_mmio_ops, s,
+                          "milkymist-softusb", R_MAX * 4);
+    sysbus_init_mmio_region(dev, &s->regs_region);
 
     /* register pmem and dmem */
-    pmem_ram = qemu_ram_alloc(NULL, "milkymist_softusb.pmem", s->pmem_size);
-    cpu_register_physical_memory(s->pmem_base, s->pmem_size,
-            pmem_ram | IO_MEM_RAM);
-    dmem_ram = qemu_ram_alloc(NULL, "milkymist_softusb.dmem", s->dmem_size);
-    cpu_register_physical_memory(s->dmem_base, s->dmem_size,
-            dmem_ram | IO_MEM_RAM);
+    memory_region_init_ram(&s->pmem, NULL, "milkymist_softusb.pmem",
+                           s->pmem_size);
+    sysbus_add_memory(dev, s->pmem_base, &s->pmem);
+    memory_region_init_ram(&s->dmem, NULL, "milkymist_softusb.dmem",
+                           s->dmem_size);
+    sysbus_add_memory(dev, s->dmem_base, &s->dmem);
 
     hid_init(&s->hid_kbd, HID_KEYBOARD, softusb_kbd_hid_datain);
     hid_init(&s->hid_mouse, HID_MOUSE, softusb_mouse_hid_datain);
Signature · 1 line
1.7.5.3
author
#37 lore raw

PATCH 24/24 milkymist: convert to memory API

In reply to Avi Kivity
---
 hw/milkymist.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
hw/milkymist.c +3 -4
index 74994a7..09de681 100644
@@ -85,7 +85,7 @@ milkymist_init(MemoryRegion *address_space_mem,
     CPUState *env;
     int kernel_size;
     DriveInfo *dinfo;
-    ram_addr_t phys_sdram;
+    MemoryRegion *phys_sdram = g_new(MemoryRegion, 1);
     MemoryRegion *phys_flash = g_new(MemoryRegion, 1);
     qemu_irq irq[32], *cpu_irq;
     int i;
@@ -113,9 +113,8 @@ milkymist_init(MemoryRegion *address_space_mem,
 
     cpu_lm32_set_phys_msb_ignore(env, 1);
 
-    phys_sdram = qemu_ram_alloc(NULL, "milkymist.sdram", sdram_size);
-    cpu_register_physical_memory(sdram_base, sdram_size,
-            phys_sdram | IO_MEM_RAM);
+    memory_region_init_ram(phys_sdram, NULL, "milkymist.sdram", sdram_size);
+    memory_region_add_subregion(address_space_mem, sdram_base, phys_sdram);
 
     memory_region_init_rom_device(phys_flash, &pflash_cfi01_ops_be,
                                   NULL, "milkymist.flash", flash_size);
Signature · 1 line
1.7.5.3