Patchwork [21/34] lsi53c895a: convert to pci_bar_map

login
register
mail settings
Submitter Blue Swirl
Date July 22, 2010, 10 p.m.
Message ID <AANLkTinIfIIsmJUuUHf9EMbsX1bUlDSItd9UQGVwk0c_@mail.gmail.com>
Download mbox | patch
Permalink /patch/59697/
State New
Headers show

Comments

Blue Swirl - July 22, 2010, 10 p.m.
Use pci_bar_map() and post_map_func instead of a mapping function.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/lsi53c895a.c |   47 ++++++++++++++++++++---------------------------
 1 files changed, 20 insertions(+), 27 deletions(-)

 {
@@ -2026,17 +2011,19 @@ static void lsi_ram_mapfunc(PCIDevice
*pci_dev, int region_num,

     DPRINTF("Mapping ram at %08"FMT_PCIBUS"\n", addr);
     s->script_ram_base = addr;
-    cpu_register_physical_memory(addr + 0, 0x2000, s->ram_io_addr);
 }

-static void lsi_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
-                             pcibus_t addr, pcibus_t size, int type)
-{
-    LSIState *s = DO_UPCAST(LSIState, dev, pci_dev);
+static IOPortWriteFunc * const lsi_io_writes[] = {
+    lsi_io_writeb,
+    lsi_io_writew,
+    lsi_io_writel,
+};

-    DPRINTF("Mapping registers at %08"FMT_PCIBUS"\n", addr);
-    cpu_register_physical_memory(addr + 0, 0x400, s->mmio_io_addr);
-}
+static IOPortReadFunc * const lsi_io_reads[] = {
+    lsi_io_readb,
+    lsi_io_readw,
+    lsi_io_readl,
+};

 static void lsi_scsi_reset(DeviceState *dev)
 {
@@ -2153,6 +2140,7 @@ static int lsi_scsi_init(PCIDevice *dev)
 {
     LSIState *s = DO_UPCAST(LSIState, dev, dev);
     uint8_t *pci_conf;
+    int io_index;

     pci_conf = s->dev.config;

@@ -2177,12 +2165,17 @@ static int lsi_scsi_init(PCIDevice *dev)
                                             lsi_ram_writefn, s);

     /* TODO: use dev and get rid of cast below */
-    pci_register_bar((struct PCIDevice *)s, 0, 256,
-                     PCI_BASE_ADDRESS_SPACE_IO, lsi_io_mapfunc, NULL);
+    pci_register_bar((struct PCIDevice *)s, 0, 256, PCI_BASE_ADDRESS_SPACE_IO,
+                     NULL, NULL);
+    io_index = cpu_register_io(lsi_io_reads, lsi_io_writes, 256, s);
+    pci_bar_map((struct PCIDevice *)s, 0, 0, 0, 256, io_index);
+
     pci_register_bar((struct PCIDevice *)s, 1, 0x400,
-                     PCI_BASE_ADDRESS_SPACE_MEMORY, lsi_mmio_mapfunc, NULL);
+                     PCI_BASE_ADDRESS_SPACE_MEMORY, NULL, NULL);
+    pci_bar_map((struct PCIDevice *)s, 1, 0, 0, 0x400, s->mmio_io_addr);
     pci_register_bar((struct PCIDevice *)s, 2, 0x2000,
-                     PCI_BASE_ADDRESS_SPACE_MEMORY, lsi_ram_mapfunc, NULL);
+                     PCI_BASE_ADDRESS_SPACE_MEMORY, NULL, lsi_ram_mapfunc);
+    pci_bar_map((struct PCIDevice *)s, 2, 0, 0, 0x2000, s->ram_io_addr);
     QTAILQ_INIT(&s->queue);

     scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, lsi_command_complete);

Patch

diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index a9cbcef..ed52db0 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -2004,21 +2004,6 @@  static void lsi_io_writel(void *opaque,
uint32_t addr, uint32_t val)
     lsi_reg_writeb(s, addr + 3, (val >> 24) & 0xff);
 }

-static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num,
-                           pcibus_t addr, pcibus_t size, int type)
-{
-    LSIState *s = DO_UPCAST(LSIState, dev, pci_dev);
-
-    DPRINTF("Mapping IO at %08"FMT_PCIBUS"\n", addr);
-
-    register_ioport_write(addr, 256, 1, lsi_io_writeb, s);
-    register_ioport_read(addr, 256, 1, lsi_io_readb, s);
-    register_ioport_write(addr, 256, 2, lsi_io_writew, s);
-    register_ioport_read(addr, 256, 2, lsi_io_readw, s);
-    register_ioport_write(addr, 256, 4, lsi_io_writel, s);
-    register_ioport_read(addr, 256, 4, lsi_io_readl, s);
-}
-
 static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num,
                             pcibus_t addr, pcibus_t size, int type)