All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
@ 2011-08-10 22:28 Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 01/11] pci: add pci_address_space_io() Richard Henderson
                   ` (11 more replies)
  0 siblings, 12 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

[ Sorry about the partial duplicates, Avi.  ]

This patchset is relative to
  git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory-region

although I'm sure it could be applied on top of Avi's batch 4.

This is not complete by any means.  I'm interested in feedback
for some of the trickier points, e.g. pckbd and fdc.

The pckbd mmio interface to mips_jazz is similar to how serial and
ide/mmio are structured.  But there are way more uses of serial.


r~


Richard Henderson (11):
  pci: add pci_address_space_io()
  isa: Pass i/o address space to isa_bus_new.
  isa: add isa_register_ioport()
  pc: Re-order pc_init1 to initialize the ISA bus before ISA devices.
  cs4231a: Convert to MemoryRegion.
  i8254: Convert to MemoryRegion.
  i8259: Convert to MemoryRegion.
  pckbd: Convert to MemoryRegion.
  serial: Convert serial_isa_initfn to MemoryRegion.
  memory: Fix old_portio vs non-zero offset.
  fdc: Convert isabus_fdc_init1 to MemoryRegion.

 hw/cs4231a.c   |   38 ++++++++++++++++----------------
 hw/fdc.c       |   53 ++++++++++++++++++++++++++++-----------------
 hw/i8254.c     |   16 +++++++++++--
 hw/i8259.c     |   65 +++++++++++++++++++++++++++++++++++++++----------------
 hw/isa-bus.c   |   14 +++++++++++-
 hw/isa.h       |    7 ++++-
 hw/mips_jazz.c |   21 +++++++++++-------
 hw/mips_r4k.c  |    2 +-
 hw/pc.h        |    2 +-
 hw/pc_piix.c   |   24 +++++++++++---------
 hw/pci.c       |    5 ++++
 hw/pci.h       |    1 +
 hw/pckbd.c     |   59 +++++++++++++++++++++++++++++++-------------------
 hw/piix4.c     |    2 +-
 hw/piix_pci.c  |    2 +-
 hw/ppc_prep.c  |    2 +-
 hw/serial.c    |   15 ++++++++++--
 hw/sun4u.c     |    2 +-
 hw/vt82c686.c  |    2 +-
 memory.c       |    4 +-
 20 files changed, 218 insertions(+), 118 deletions(-)

-- 
1.7.6

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

* [Qemu-devel] [PATCH 01/11] pci: add pci_address_space_io()
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 02/11] isa: Pass i/o address space to isa_bus_new Richard Henderson
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

Returns the I/O address space.  Useful for implementing
PCI-ISA bridge devices.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/pci.c |    5 +++++
 hw/pci.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 4e495b4..4f7bb7a 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -2170,3 +2170,8 @@ MemoryRegion *pci_address_space(PCIDevice *dev)
 {
     return dev->bus->address_space_mem;
 }
+
+MemoryRegion *pci_address_space_io(PCIDevice *dev)
+{
+    return dev->bus->address_space_io;
+}
diff --git a/hw/pci.h b/hw/pci.h
index 391217e..6bdbe4c 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -221,6 +221,7 @@ void pci_default_write_config(PCIDevice *d,
 void pci_device_save(PCIDevice *s, QEMUFile *f);
 int pci_device_load(PCIDevice *s, QEMUFile *f);
 MemoryRegion *pci_address_space(PCIDevice *dev);
+MemoryRegion *pci_address_space_io(PCIDevice *dev);
 
 typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
 typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
-- 
1.7.6

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

* [Qemu-devel] [PATCH 02/11] isa: Pass i/o address space to isa_bus_new.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 01/11] pci: add pci_address_space_io() Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 03/11] isa: add isa_register_ioport() Richard Henderson
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

Not used yet, but at least we're provided with the correct region.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/isa-bus.c   |    4 +++-
 hw/isa.h       |    2 +-
 hw/mips_jazz.c |   17 ++++++++++-------
 hw/mips_r4k.c  |    2 +-
 hw/pc_piix.c   |    2 +-
 hw/piix4.c     |    2 +-
 hw/piix_pci.c  |    2 +-
 hw/ppc_prep.c  |    2 +-
 hw/sun4u.c     |    2 +-
 hw/vt82c686.c  |    2 +-
 10 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 1cb497f..d067505 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -24,6 +24,7 @@
 
 struct ISABus {
     BusState qbus;
+    MemoryRegion *address_space_io;
     qemu_irq *irqs;
 };
 static ISABus *isabus;
@@ -39,7 +40,7 @@ static struct BusInfo isa_bus_info = {
     .get_fw_dev_path = isabus_get_fw_dev_path,
 };
 
-ISABus *isa_bus_new(DeviceState *dev)
+ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io)
 {
     if (isabus) {
         fprintf(stderr, "Can't create a second ISA bus\n");
@@ -51,6 +52,7 @@ ISABus *isa_bus_new(DeviceState *dev)
     }
 
     isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
+    isabus->address_space_io = address_space_io;
     return isabus;
 }
 
diff --git a/hw/isa.h b/hw/isa.h
index f344699..390e2d4 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -25,7 +25,7 @@ struct ISADeviceInfo {
     isa_qdev_initfn init;
 };
 
-ISABus *isa_bus_new(DeviceState *dev);
+ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io);
 void isa_bus_irqs(qemu_irq *irqs);
 qemu_irq isa_get_irq(int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index f7a6579..0faba41 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -103,10 +103,11 @@ static void cpu_request_exit(void *opaque, int irq, int level)
     }
 }
 
-static
-void mips_jazz_init (MemoryRegion *address_space, ram_addr_t ram_size,
-                     const char *cpu_model,
-                     enum jazz_model_e jazz_model)
+static void mips_jazz_init(MemoryRegion *address_space,
+                           MemoryRegion *address_space_io,
+                           ram_addr_t ram_size,
+                           const char *cpu_model,
+                           enum jazz_model_e jazz_model)
 {
     char *filename;
     int bios_size, n;
@@ -182,7 +183,7 @@ void mips_jazz_init (MemoryRegion *address_space, ram_addr_t ram_size,
 
     /* ISA devices */
     i8259 = i8259_init(env->irq[4]);
-    isa_bus_new(NULL);
+    isa_bus_new(NULL, address_space_io);
     isa_bus_irqs(i8259);
     cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
     DMA_init(0, cpu_exit_irq);
@@ -289,7 +290,8 @@ void mips_magnum_init (MemoryRegion *address_space_mem,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
 {
-    mips_jazz_init(address_space_mem, ram_size, cpu_model, JAZZ_MAGNUM);
+    mips_jazz_init(address_space_mem, address_space_io,
+                   ram_size, cpu_model, JAZZ_MAGNUM);
 }
 
 static
@@ -300,7 +302,8 @@ void mips_pica61_init (MemoryRegion *address_space_mem,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
 {
-    mips_jazz_init(address_space_mem, ram_size, cpu_model, JAZZ_PICA61);
+    mips_jazz_init(address_space_mem, address_space_io,
+                   ram_size, cpu_model, JAZZ_PICA61);
 }
 
 static QEMUMachine mips_magnum_machine = {
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index 499a06e..d858807 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -260,7 +260,7 @@ void mips_r4k_init (MemoryRegion *address_space_mem,
 
     /* The PIC is attached to the MIPS CPU INT0 pin */
     i8259 = i8259_init(env->irq[2]);
-    isa_bus_new(NULL);
+    isa_bus_new(NULL, address_space_io);
     isa_bus_irqs(i8259);
 
     rtc_init(2000, NULL);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 675fad3..709a1c3 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -149,7 +149,7 @@ static void pc_init1(MemoryRegion *system_memory,
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
-        isa_bus_new(NULL);
+        isa_bus_new(NULL, system_io);
     }
     isa_bus_irqs(isa_irq);
 
diff --git a/hw/piix4.c b/hw/piix4.c
index 9590e7b..2fd1171 100644
--- a/hw/piix4.c
+++ b/hw/piix4.c
@@ -87,7 +87,7 @@ static int piix4_initfn(PCIDevice *dev)
 {
     PIIX4State *d = DO_UPCAST(PIIX4State, dev, dev);
 
-    isa_bus_new(&d->dev.qdev);
+    isa_bus_new(&d->dev.qdev, pci_address_space_io(dev));
     piix4_dev = &d->dev;
     qemu_register_reset(piix4_reset, d);
     return 0;
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index 8f6ea42..d183443 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -504,7 +504,7 @@ static int piix3_initfn(PCIDevice *dev)
 {
     PIIX3State *d = DO_UPCAST(PIIX3State, dev, dev);
 
-    isa_bus_new(&d->dev.qdev);
+    isa_bus_new(&d->dev.qdev, pci_address_space_io(dev));
     qemu_register_reset(piix3_reset, d);
     return 0;
 }
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index d8f9fb9..07de957 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -653,7 +653,7 @@ static void ppc_prep_init (MemoryRegion *address_space_mem,
     i8259 = i8259_init(first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
     pci_bus = pci_prep_init(i8259, get_system_memory(), get_system_io());
     /* Hmm, prep has no pci-isa bridge ??? */
-    isa_bus_new(NULL);
+    isa_bus_new(NULL, address_space_io);
     isa_bus_irqs(i8259);
     //    pci_bus = i440fx_init();
     /* Register 8 MB of ISA IO space (needed for non-contiguous map) */
diff --git a/hw/sun4u.c b/hw/sun4u.c
index 1150a15..b6421cb 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -544,7 +544,7 @@ pci_ebus_init1(PCIDevice *pci_dev)
 {
     EbusState *s = DO_UPCAST(EbusState, pci_dev, pci_dev);
 
-    isa_bus_new(&pci_dev->qdev);
+    isa_bus_new(&pci_dev->qdev, pci_address_space_io(pci_dev));
 
     pci_dev->config[0x04] = 0x06; // command = bus master, pci mem
     pci_dev->config[0x05] = 0x00;
diff --git a/hw/vt82c686.c b/hw/vt82c686.c
index 5c973ed..e2b179e 100644
--- a/hw/vt82c686.c
+++ b/hw/vt82c686.c
@@ -490,7 +490,7 @@ static int vt82c686b_initfn(PCIDevice *d)
     uint8_t *wmask;
     int i;
 
-    isa_bus_new(&d->qdev);
+    isa_bus_new(&d->qdev, pci_address_space_io(d));
 
     pci_conf = d->config;
     pci_config_set_prog_interface(pci_conf, 0x0);
-- 
1.7.6

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

* [Qemu-devel] [PATCH 03/11] isa: add isa_register_ioport()
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 01/11] pci: add pci_address_space_io() Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 02/11] isa: Pass i/o address space to isa_bus_new Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-11  6:18   ` Avi Kivity
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 04/11] pc: Re-order pc_init1 to initialize the ISA bus before ISA devices Richard Henderson
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

To replace isa_init_ioport and isa_init_ioport_range
as the ISA devices are converted to the memory api.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/isa-bus.c |   10 ++++++++++
 hw/isa.h     |    5 ++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index d067505..b49e6c6 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -108,6 +108,16 @@ void isa_init_ioport(ISADevice *dev, uint16_t ioport)
     isa_init_ioport_range(dev, ioport, 1);
 }
 
+void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start)
+{
+    memory_region_add_subregion(isabus->address_space_io, start, io);
+    if (dev != NULL) {
+        assert(dev->nio < ARRAY_SIZE(dev->io));
+        dev->io[dev->nio++] = io;
+        isa_init_ioport_range(dev, start, io->size);
+    }
+}
+
 static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
     ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
diff --git a/hw/isa.h b/hw/isa.h
index 390e2d4..432d17a 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -13,10 +13,12 @@ typedef struct ISADeviceInfo ISADeviceInfo;
 
 struct ISADevice {
     DeviceState qdev;
+    MemoryRegion *io[32];
     uint32_t isairq[2];
-    int nirqs;
     uint16_t ioports[32];
+    int nirqs;
     int nioports;
+    int nio;
 };
 
 typedef int (*isa_qdev_initfn)(ISADevice *dev);
@@ -29,6 +31,7 @@ ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io);
 void isa_bus_irqs(qemu_irq *irqs);
 qemu_irq isa_get_irq(int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
+void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
 void isa_init_ioport(ISADevice *dev, uint16_t ioport);
 void isa_init_ioport_range(ISADevice *dev, uint16_t start, uint16_t length);
 void isa_qdev_register(ISADeviceInfo *info);
-- 
1.7.6

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

* [Qemu-devel] [PATCH 04/11] pc: Re-order pc_init1 to initialize the ISA bus before ISA devices.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (2 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 03/11] isa: add isa_register_ioport() Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 05/11] cs4231a: Convert to MemoryRegion Richard Henderson
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

In particular, the i8259 was being initialized before the ISA bus,
leading to a crash.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/pc_piix.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 709a1c3..82718ec 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -123,17 +123,7 @@ static void pc_init1(MemoryRegion *system_memory,
                        pci_memory, &ram_memory);
     }
 
-    if (!xen_enabled()) {
-        cpu_irq = pc_allocate_cpu_irq();
-        i8259 = i8259_init(cpu_irq[0]);
-    } else {
-        i8259 = xen_interrupt_controller_init();
-    }
     isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
-    isa_irq_state->i8259 = i8259;
-    if (pci_enabled) {
-        ioapic_init(isa_irq_state);
-    }
     isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
     if (pci_enabled) {
@@ -153,6 +143,18 @@ static void pc_init1(MemoryRegion *system_memory,
     }
     isa_bus_irqs(isa_irq);
 
+    if (!xen_enabled()) {
+        cpu_irq = pc_allocate_cpu_irq();
+        i8259 = i8259_init(cpu_irq[0]);
+    } else {
+        i8259 = xen_interrupt_controller_init();
+    }
+
+    isa_irq_state->i8259 = i8259;
+    if (pci_enabled) {
+        ioapic_init(isa_irq_state);
+    }
+
     pc_register_ferr_irq(isa_get_irq(13));
 
     pc_vga_init(pci_enabled? pci_bus: NULL);
-- 
1.7.6

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

* [Qemu-devel] [PATCH 05/11] cs4231a: Convert to MemoryRegion.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (3 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 04/11] pc: Re-order pc_init1 to initialize the ISA bus before ISA devices Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-11  6:22   ` Avi Kivity
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 06/11] i8254: " Richard Henderson
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/cs4231a.c |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index 598f032..e16665e 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -59,6 +59,7 @@ static struct {
 typedef struct CSState {
     ISADevice dev;
     QEMUSoundCard card;
+    MemoryRegion ioports;
     qemu_irq pic;
     uint32_t regs[CS_REGS];
     uint8_t dregs[CS_DREGS];
@@ -74,14 +75,6 @@ typedef struct CSState {
     int16_t *tab;
 } CSState;
 
-#define IO_READ_PROTO(name)                             \
-    static uint32_t name (void *opaque, uint32_t addr)
-
-#define IO_WRITE_PROTO(name)                                            \
-    static void name (void *opaque, uint32_t addr, uint32_t val)
-
-#define GET_SADDR(addr) (addr & 3)
-
 #define MODE2 (1 << 6)
 #define MCE (1 << 6)
 #define PMCE (1 << 4)
@@ -353,12 +346,12 @@ static void cs_reset_voices (CSState *s, uint32_t val)
     }
 }
 
-IO_READ_PROTO (cs_read)
+static uint64_t cs_read(void *opaque, target_phys_addr_t addr, unsigned size)
 {
     CSState *s = opaque;
     uint32_t saddr, iaddr, ret;
 
-    saddr = GET_SADDR (addr);
+    saddr = addr;
     iaddr = ~0U;
 
     switch (saddr) {
@@ -390,12 +383,14 @@ IO_READ_PROTO (cs_read)
     return ret;
 }
 
-IO_WRITE_PROTO (cs_write)
+static void cs_write(void *opaque, target_phys_addr_t addr,
+                     uint64_t val64, unsigned size)
 {
     CSState *s = opaque;
-    uint32_t saddr, iaddr;
+    uint32_t saddr, iaddr, val;
 
-    saddr = GET_SADDR (addr);
+    saddr = addr;
+    val = val64;
 
     switch (saddr) {
     case Index_Address:
@@ -637,18 +632,23 @@ static const VMStateDescription vmstate_cs4231a = {
     }
 };
 
+static const MemoryRegionOps cs_ioport_ops = {
+    .read = cs_read,
+    .write = cs_write,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    }
+};
+
 static int cs4231a_initfn (ISADevice *dev)
 {
     CSState *s = DO_UPCAST (CSState, dev, dev);
-    int i;
 
     isa_init_irq (dev, &s->pic, s->irq);
 
-    for (i = 0; i < 4; i++) {
-        isa_init_ioport(dev, i);
-        register_ioport_write (s->port + i, 1, 1, cs_write, s);
-        register_ioport_read (s->port + i, 1, 1, cs_read, s);
-    }
+    memory_region_init_io(&s->ioports, &cs_ioport_ops, s, "cs4231a", 4);
+    isa_register_ioport(dev, &s->ioports, s->port);
 
     DMA_register_channel (s->dma, cs_dma_read, s);
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH 06/11] i8254: Convert to MemoryRegion.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (4 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 05/11] cs4231a: Convert to MemoryRegion Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 07/11] i8259: " Richard Henderson
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/i8254.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/hw/i8254.c b/hw/i8254.c
index a9ca9f6..12571ef 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -55,6 +55,7 @@ typedef struct PITChannelState {
 
 typedef struct PITState {
     ISADevice dev;
+    MemoryRegion ioports;
     uint32_t irq;
     uint32_t iobase;
     PITChannelState channels[3];
@@ -506,6 +507,16 @@ void hpet_pit_enable(void)
     pit_load_count(s, 0);
 }
 
+static const MemoryRegionPortio pit_portio[] = {
+    { 0, 4, 1, .write = pit_ioport_write },
+    { 0, 3, 1, .read = pit_ioport_read },
+    PORTIO_END_OF_LIST()
+};
+
+static const MemoryRegionOps pit_ioport_ops = {
+    .old_portio = pit_portio
+};
+
 static int pit_initfn(ISADevice *dev)
 {
     PITState *pit = DO_UPCAST(PITState, dev, dev);
@@ -516,9 +527,8 @@ static int pit_initfn(ISADevice *dev)
     s->irq_timer = qemu_new_timer_ns(vm_clock, pit_irq_timer, s);
     s->irq = isa_get_irq(pit->irq);
 
-    register_ioport_write(pit->iobase, 4, 1, pit_ioport_write, pit);
-    register_ioport_read(pit->iobase, 3, 1, pit_ioport_read, pit);
-    isa_init_ioport(dev, pit->iobase);
+    memory_region_init_io(&pit->ioports, &pit_ioport_ops, pit, "pit", 4);
+    isa_register_ioport(dev, &pit->ioports, pit->iobase);
 
     qdev_set_legacy_instance_id(&dev->qdev, pit->iobase, 2);
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH 07/11] i8259: Convert to MemoryRegion.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (5 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 06/11] i8254: " Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-28 15:25   ` Avi Kivity
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 08/11] pckbd: " Richard Henderson
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

The only non-obvious part is pic_poll_read which used
"addr1 >> 7" to detect whether one referred to either
the master or slave PIC.  Instead, test this directly.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/i8259.c |   65 ++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/hw/i8259.c b/hw/i8259.c
index 84d330d..8c4feae 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -59,6 +59,8 @@ typedef struct PicState {
     uint8_t elcr; /* PIIX edge/trigger selection*/
     uint8_t elcr_mask;
     PicState2 *pics_state;
+    MemoryRegion base_io;
+    MemoryRegion elcr_io;
 } PicState;
 
 struct PicState2 {
@@ -284,13 +286,15 @@ static void pic_reset(void *opaque)
     /* Note: ELCR is not reset */
 }
 
-static void pic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+static void pic_ioport_write(void *opaque, target_phys_addr_t addr64,
+                             uint64_t val64, unsigned size)
 {
     PicState *s = opaque;
+    uint32_t addr = addr64;
+    uint32_t val = val64;
     int priority, cmd, irq;
 
     DPRINTF("write: addr=0x%02x val=0x%02x\n", addr, val);
-    addr &= 1;
     if (addr == 0) {
         if (val & 0x10) {
             /* init */
@@ -374,19 +378,21 @@ static void pic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     }
 }
 
-static uint32_t pic_poll_read (PicState *s, uint32_t addr1)
+static uint32_t pic_poll_read(PicState *s)
 {
     int ret;
 
     ret = pic_get_irq(s);
     if (ret >= 0) {
-        if (addr1 >> 7) {
+        bool slave = (s == &isa_pic->pics[1]);
+
+        if (slave) {
             s->pics_state->pics[0].isr &= ~(1 << 2);
             s->pics_state->pics[0].irr &= ~(1 << 2);
         }
         s->irr &= ~(1 << ret);
         s->isr &= ~(1 << ret);
-        if (addr1 >> 7 || ret != 2)
+        if (slave || ret != 2)
             pic_update_irq(s->pics_state);
     } else {
         ret = 0x07;
@@ -396,16 +402,15 @@ static uint32_t pic_poll_read (PicState *s, uint32_t addr1)
     return ret;
 }
 
-static uint32_t pic_ioport_read(void *opaque, uint32_t addr1)
+static uint64_t pic_ioport_read(void *opaque, target_phys_addr_t addr1,
+                                unsigned size)
 {
     PicState *s = opaque;
-    unsigned int addr;
+    unsigned int addr = addr1;
     int ret;
 
-    addr = addr1;
-    addr &= 1;
     if (s->poll) {
-        ret = pic_poll_read(s, addr1);
+        ret = pic_poll_read(s);
         s->poll = 0;
     } else {
         if (addr == 0) {
@@ -417,7 +422,7 @@ static uint32_t pic_ioport_read(void *opaque, uint32_t addr1)
             ret = s->imr;
         }
     }
-    DPRINTF("read: addr=0x%02x val=0x%02x\n", addr1, ret);
+    DPRINTF("read: addr=0x%02x val=0x%02x\n", addr, ret);
     return ret;
 }
 
@@ -427,22 +432,24 @@ uint32_t pic_intack_read(PicState2 *s)
 {
     int ret;
 
-    ret = pic_poll_read(&s->pics[0], 0x00);
+    ret = pic_poll_read(&s->pics[0]);
     if (ret == 2)
-        ret = pic_poll_read(&s->pics[1], 0x80) + 8;
+        ret = pic_poll_read(&s->pics[1]) + 8;
     /* Prepare for ISR read */
     s->pics[0].read_reg_select = 1;
 
     return ret;
 }
 
-static void elcr_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+static void elcr_ioport_write(void *opaque, target_phys_addr_t addr,
+                              uint64_t val, unsigned size)
 {
     PicState *s = opaque;
     s->elcr = val & s->elcr_mask;
 }
 
-static uint32_t elcr_ioport_read(void *opaque, uint32_t addr1)
+static uint64_t elcr_ioport_read(void *opaque, target_phys_addr_t addr,
+                                 unsigned size)
 {
     PicState *s = opaque;
     return s->elcr;
@@ -474,15 +481,35 @@ static const VMStateDescription vmstate_pic = {
     }
 };
 
+static const MemoryRegionOps pic_base_ioport_ops = {
+    .read = pic_ioport_read,
+    .write = pic_ioport_write,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
+
+static const MemoryRegionOps pic_elcr_ioport_ops = {
+    .read = elcr_ioport_read,
+    .write = elcr_ioport_write,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
+
 /* XXX: add generic master/slave system */
 static void pic_init1(int io_addr, int elcr_addr, PicState *s)
 {
-    register_ioport_write(io_addr, 2, 1, pic_ioport_write, s);
-    register_ioport_read(io_addr, 2, 1, pic_ioport_read, s);
+    memory_region_init_io(&s->base_io, &pic_base_ioport_ops, s, "pic", 2);
+    memory_region_init_io(&s->elcr_io, &pic_elcr_ioport_ops, s, "elcr", 1);
+
+    isa_register_ioport(NULL, &s->base_io, io_addr);
     if (elcr_addr >= 0) {
-        register_ioport_write(elcr_addr, 1, 1, elcr_ioport_write, s);
-        register_ioport_read(elcr_addr, 1, 1, elcr_ioport_read, s);
+        isa_register_ioport(NULL, &s->elcr_io, elcr_addr);
     }
+
     vmstate_register(NULL, io_addr, &vmstate_pic, s);
     qemu_register_reset(pic_reset, s);
 }
-- 
1.7.6

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

* [Qemu-devel] [PATCH 08/11] pckbd: Convert to MemoryRegion.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (6 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 07/11] i8259: " Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 09/11] serial: Convert serial_isa_initfn " Richard Henderson
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

Slightly non-obvious with mips_jazz passing in the region
structure to populate.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/mips_jazz.c |    4 ++-
 hw/pc.h        |    2 +-
 hw/pckbd.c     |   59 ++++++++++++++++++++++++++++++++++---------------------
 3 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 0faba41..1abab70 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -116,6 +116,7 @@ static void mips_jazz_init(MemoryRegion *address_space,
     rc4030_dma *dmas;
     void* rc4030_opaque;
     MemoryRegion *rtc = g_new(MemoryRegion, 1);
+    MemoryRegion *i8042 = g_new(MemoryRegion, 1);
     MemoryRegion *dma_dummy = g_new(MemoryRegion, 1);
     NICInfo *nd;
     DeviceState *dev;
@@ -246,7 +247,8 @@ static void mips_jazz_init(MemoryRegion *address_space,
     memory_region_add_subregion(address_space, 0x80004000, rtc);
 
     /* Keyboard (i8042) */
-    i8042_mm_init(rc4030[6], rc4030[7], 0x80005000, 0x1000, 0x1);
+    i8042_mm_init(rc4030[6], rc4030[7], i8042, 0x1000, 0x1);
+    memory_region_add_subregion(address_space, 0x80005000, i8042);
 
     /* Serial ports */
     if (serial_hds[0]) {
diff --git a/hw/pc.h b/hw/pc.h
index dae736e..28ed210 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -118,7 +118,7 @@ void vmmouse_set_data(const uint32_t *data);
 
 void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base);
 void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
-                   target_phys_addr_t base, ram_addr_t size,
+                   MemoryRegion *region, ram_addr_t size,
                    target_phys_addr_t mask);
 void i8042_isa_mouse_fake_event(void *opaque);
 void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out);
diff --git a/hw/pckbd.c b/hw/pckbd.c
index ae65c04..947a4d7 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -400,33 +400,27 @@ static void kbd_mm_writeb (void *opaque, target_phys_addr_t addr, uint32_t value
         kbd_write_data(s, 0, value & 0xff);
 }
 
-static CPUReadMemoryFunc * const kbd_mm_read[] = {
-    &kbd_mm_readb,
-    &kbd_mm_readb,
-    &kbd_mm_readb,
-};
-
-static CPUWriteMemoryFunc * const kbd_mm_write[] = {
-    &kbd_mm_writeb,
-    &kbd_mm_writeb,
-    &kbd_mm_writeb,
+static const MemoryRegionOps i8042_mmio_ops = {
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .old_mmio = {
+        .read = { kbd_mm_readb, kbd_mm_readb, kbd_mm_readb },
+        .write = { kbd_mm_writeb, kbd_mm_writeb, kbd_mm_writeb },
+    },
 };
 
 void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
-                   target_phys_addr_t base, ram_addr_t size,
+                   MemoryRegion *region, ram_addr_t size,
                    target_phys_addr_t mask)
 {
     KBDState *s = qemu_mallocz(sizeof(KBDState));
-    int s_io_memory;
 
     s->irq_kbd = kbd_irq;
     s->irq_mouse = mouse_irq;
     s->mask = mask;
 
     vmstate_register(NULL, 0, &vmstate_kbd, s);
-    s_io_memory = cpu_register_io_memory(kbd_mm_read, kbd_mm_write, s,
-                                         DEVICE_NATIVE_ENDIAN);
-    cpu_register_physical_memory(base, size, s_io_memory);
+
+    memory_region_init_io(region, &i8042_mmio_ops, s, "i8042", size);
 
     s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
     s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
@@ -435,7 +429,8 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
 
 typedef struct ISAKBDState {
     ISADevice dev;
-    KBDState  kbd;
+    KBDState kbd;
+    MemoryRegion io[2];
 } ISAKBDState;
 
 void i8042_isa_mouse_fake_event(void *opaque)
@@ -464,19 +459,37 @@ static const VMStateDescription vmstate_kbd_isa = {
     }
 };
 
+static const MemoryRegionPortio i8042_data_portio[] = {
+    { 0, 1, 1, .read = kbd_read_data, .write = kbd_write_data },
+    PORTIO_END_OF_LIST()
+};
+
+static const MemoryRegionPortio i8042_cmd_portio[] = {
+    { 0, 1, 1, .read = kbd_read_status, .write = kbd_write_command },
+    PORTIO_END_OF_LIST()
+};
+
+static const MemoryRegionOps i8042_data_ops = {
+    .old_portio = i8042_data_portio
+};
+
+static const MemoryRegionOps i8042_cmd_ops = {
+    .old_portio = i8042_cmd_portio
+};
+
 static int i8042_initfn(ISADevice *dev)
 {
-    KBDState *s = &(DO_UPCAST(ISAKBDState, dev, dev)->kbd);
+    ISAKBDState *isa_s = DO_UPCAST(ISAKBDState, dev, dev);
+    KBDState *s = &isa_s->kbd;
 
     isa_init_irq(dev, &s->irq_kbd, 1);
     isa_init_irq(dev, &s->irq_mouse, 12);
 
-    register_ioport_read(0x60, 1, 1, kbd_read_data, s);
-    register_ioport_write(0x60, 1, 1, kbd_write_data, s);
-    isa_init_ioport(dev, 0x60);
-    register_ioport_read(0x64, 1, 1, kbd_read_status, s);
-    register_ioport_write(0x64, 1, 1, kbd_write_command, s);
-    isa_init_ioport(dev, 0x64);
+    memory_region_init_io(isa_s->io + 0, &i8042_data_ops, s, "i8042-data", 1);
+    isa_register_ioport(dev, isa_s->io + 0, 0x60);
+
+    memory_region_init_io(isa_s->io + 1, &i8042_cmd_ops, s, "i8042-cmd", 1);
+    isa_register_ioport(dev, isa_s->io + 1, 0x64);
 
     s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
     s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
-- 
1.7.6

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

* [Qemu-devel] [PATCH 09/11] serial: Convert serial_isa_initfn to MemoryRegion.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (7 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 08/11] pckbd: " Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 10/11] memory: Fix old_portio vs non-zero offset Richard Henderson
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

The serial_mm_init path is as yet unconverted.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/serial.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/hw/serial.c b/hw/serial.c
index 0ee61dd..466de21 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -157,6 +157,7 @@ struct SerialState {
 
 typedef struct ISASerialState {
     ISADevice dev;
+    MemoryRegion io;
     uint32_t index;
     uint32_t iobase;
     uint32_t isairq;
@@ -755,6 +756,15 @@ void serial_set_frequency(SerialState *s, uint32_t frequency)
 static const int isa_serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
 static const int isa_serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
 
+static const MemoryRegionPortio serial_portio[] = {
+    { 0, 8, 1, .read = serial_ioport_read, .write = serial_ioport_write },
+    PORTIO_END_OF_LIST()
+};
+
+static const MemoryRegionOps serial_io_ops = {
+    .old_portio = serial_portio
+};
+
 static int serial_isa_initfn(ISADevice *dev)
 {
     static int index;
@@ -776,9 +786,8 @@ static int serial_isa_initfn(ISADevice *dev)
     serial_init_core(s);
     qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3);
 
-    register_ioport_write(isa->iobase, 8, 1, serial_ioport_write, s);
-    register_ioport_read(isa->iobase, 8, 1, serial_ioport_read, s);
-    isa_init_ioport_range(dev, isa->iobase, 8);
+    memory_region_init_io(&isa->io, &serial_io_ops, s, "serial", 8);
+    isa_register_ioport(dev, &isa->io, isa->iobase);
     return 0;
 }
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH 10/11] memory: Fix old_portio vs non-zero offset.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (8 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 09/11] serial: Convert serial_isa_initfn " Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 11/11] fdc: Convert isabus_fdc_init1 to MemoryRegion Richard Henderson
  2011-08-11  7:48 ` [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Avi Kivity
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

The legacy functions that we're wrapping expect that offset
to be included in the register.  Indeed, they generally
expect the absolute address and then mask off the "high" bits.

The FDC is the first converted device with a non-zero offset.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 memory.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/memory.c b/memory.c
index a1f118b..2c82cd3 100644
--- a/memory.c
+++ b/memory.c
@@ -367,7 +367,7 @@ static void memory_region_iorange_read(IORange *iorange,
 
         *data = ((uint64_t)1 << (width * 8)) - 1;
         if (mrp) {
-            *data = mrp->read(mr->opaque, offset - mrp->offset);
+            *data = mrp->read(mr->opaque, offset);
         }
         return;
     }
@@ -391,7 +391,7 @@ static void memory_region_iorange_write(IORange *iorange,
         const MemoryRegionPortio *mrp = find_portio(mr, offset, width, true);
 
         if (mrp) {
-            mrp->write(mr->opaque, offset - mrp->offset, data);
+            mrp->write(mr->opaque, offset, data);
         }
         return;
     }
-- 
1.7.6

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

* [Qemu-devel] [PATCH 11/11] fdc: Convert isabus_fdc_init1 to MemoryRegion.
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (9 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 10/11] memory: Fix old_portio vs non-zero offset Richard Henderson
@ 2011-08-10 22:28 ` Richard Henderson
  2011-08-11  7:48 ` [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Avi Kivity
  11 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2011-08-10 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: avi

This requires some amount of hoop-jumping, so that we don't
inadvertently claim port 0x3f6, which is used by ISA IDE.

The sysbus initialization path is as yet unconverted.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 hw/fdc.c |   53 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index edf0360..cba973e 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -425,6 +425,7 @@ typedef struct FDCtrlSysBus {
 
 typedef struct FDCtrlISABus {
     ISADevice busdev;
+    MemoryRegion io_0, io_7;
     struct FDCtrl state;
     int32_t bootindexA;
     int32_t bootindexB;
@@ -490,16 +491,6 @@ static void fdctrl_write (void *opaque, uint32_t reg, uint32_t value)
     }
 }
 
-static uint32_t fdctrl_read_port (void *opaque, uint32_t reg)
-{
-    return fdctrl_read(opaque, reg & 7);
-}
-
-static void fdctrl_write_port (void *opaque, uint32_t reg, uint32_t value)
-{
-    fdctrl_write(opaque, reg & 7, value);
-}
-
 static uint32_t fdctrl_read_mem (void *opaque, target_phys_addr_t reg)
 {
     return fdctrl_read(opaque, (uint32_t)reg);
@@ -1891,6 +1882,34 @@ static int fdctrl_init_common(FDCtrl *fdctrl)
     return fdctrl_connect_drives(fdctrl);
 }
 
+static uint32_t fdctrl_read_port_7(void *opaque, uint32_t reg)
+{
+    return fdctrl_read(opaque, reg + 7);
+}
+
+static void fdctrl_write_port_7(void *opaque, uint32_t reg, uint32_t value)
+{
+    fdctrl_write(opaque, reg + 7, value);
+}
+
+static const MemoryRegionPortio fdc_portio_0[] = {
+    { 1, 5, 1, .read = fdctrl_read, .write = fdctrl_write },
+    PORTIO_END_OF_LIST()
+};
+
+static const MemoryRegionPortio fdc_portio_7[] = {
+    { 0, 1, 1, .read = fdctrl_read_port_7, .write = fdctrl_write_port_7 },
+    PORTIO_END_OF_LIST()
+};
+
+static const MemoryRegionOps fdc_ioport_0_ops = {
+    .old_portio = fdc_portio_0
+};
+
+static const MemoryRegionOps fdc_ioport_7_ops = {
+    .old_portio = fdc_portio_7
+};
+
 static int isabus_fdc_init1(ISADevice *dev)
 {
     FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
@@ -1900,16 +1919,10 @@ static int isabus_fdc_init1(ISADevice *dev)
     int dma_chann = 2;
     int ret;
 
-    register_ioport_read(iobase + 0x01, 5, 1,
-                         &fdctrl_read_port, fdctrl);
-    register_ioport_read(iobase + 0x07, 1, 1,
-                         &fdctrl_read_port, fdctrl);
-    register_ioport_write(iobase + 0x01, 5, 1,
-                          &fdctrl_write_port, fdctrl);
-    register_ioport_write(iobase + 0x07, 1, 1,
-                          &fdctrl_write_port, fdctrl);
-    isa_init_ioport_range(dev, iobase, 6);
-    isa_init_ioport(dev, iobase + 7);
+    memory_region_init_io(&isa->io_0, &fdc_ioport_0_ops, fdctrl, "fdc", 6);
+    memory_region_init_io(&isa->io_7, &fdc_ioport_7_ops, fdctrl, "fdc", 1);
+    isa_register_ioport(dev, &isa->io_0, iobase);
+    isa_register_ioport(dev, &isa->io_7, iobase + 7);
 
     isa_init_irq(&isa->busdev, &fdctrl->irq, isairq);
     fdctrl->dma_chann = dma_chann;
-- 
1.7.6

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

* Re: [Qemu-devel] [PATCH 03/11] isa: add isa_register_ioport()
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 03/11] isa: add isa_register_ioport() Richard Henderson
@ 2011-08-11  6:18   ` Avi Kivity
  0 siblings, 0 replies; 23+ messages in thread
From: Avi Kivity @ 2011-08-11  6:18 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 08/11/2011 01:28 AM, Richard Henderson wrote:
> To replace isa_init_ioport and isa_init_ioport_range
> as the ISA devices are converted to the memory api.
>
>
> +void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start)
> +{
> +    memory_region_add_subregion(isabus->address_space_io, start, io);
> +    if (dev != NULL) {
> +        assert(dev->nio<  ARRAY_SIZE(dev->io));
> +        dev->io[dev->nio++] = io;
> +        isa_init_ioport_range(dev, start, io->size);
> +    }
> +}

memory_region_size(io);

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

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

* Re: [Qemu-devel] [PATCH 05/11] cs4231a: Convert to MemoryRegion.
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 05/11] cs4231a: Convert to MemoryRegion Richard Henderson
@ 2011-08-11  6:22   ` Avi Kivity
  2011-08-11  6:27     ` Avi Kivity
  0 siblings, 1 reply; 23+ messages in thread
From: Avi Kivity @ 2011-08-11  6:22 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 08/11/2011 01:28 AM, Richard Henderson wrote:
>       }
>   };
>
> +static const MemoryRegionOps cs_ioport_ops = {
> +    .read = cs_read,
> +    .write = cs_write,
> +    .impl = {
> +        .min_access_size = 1,
> +        .max_access_size = 1,
> +    }
> +};

Should be .valid, not .impl.

.impl means the implementation only supports this access size; emulate 
other sizes by using a supported size (e.g. crack a 4-byte access into 4 
1-byte accesses).  .valid means what the device actually supports; if 
the guest uses another size something bus-defined happens.

> +
>   static int cs4231a_initfn (ISADevice *dev)
>   {
>       CSState *s = DO_UPCAST (CSState, dev, dev);
> -    int i;
>
>       isa_init_irq (dev,&s->pic, s->irq);
>
> -    for (i = 0; i<  4; i++) {
> -        isa_init_ioport(dev, i);
> -        register_ioport_write (s->port + i, 1, 1, cs_write, s);
> -        register_ioport_read (s->port + i, 1, 1, cs_read, s);
> -    }
> +    memory_region_init_io(&s->ioports,&cs_ioport_ops, s, "cs4231a", 4);
> +    isa_register_ioport(dev,&s->ioports, s->port);
>
>       DMA_register_channel (s->dma, cs_dma_read, s);
>


-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

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

* Re: [Qemu-devel] [PATCH 05/11] cs4231a: Convert to MemoryRegion.
  2011-08-11  6:22   ` Avi Kivity
@ 2011-08-11  6:27     ` Avi Kivity
  0 siblings, 0 replies; 23+ messages in thread
From: Avi Kivity @ 2011-08-11  6:27 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 08/11/2011 09:22 AM, Avi Kivity wrote:
> On 08/11/2011 01:28 AM, Richard Henderson wrote:
>>       }
>>   };
>>
>> +static const MemoryRegionOps cs_ioport_ops = {
>> +    .read = cs_read,
>> +    .write = cs_write,
>> +    .impl = {
>> +        .min_access_size = 1,
>> +        .max_access_size = 1,
>> +    }
>> +};
>
> Should be .valid, not .impl.
>
> .impl means the implementation only supports this access size; emulate 
> other sizes by using a supported size (e.g. crack a 4-byte access into 
> 4 1-byte accesses).  .valid means what the device actually supports; 
> if the guest uses another size something bus-defined happens.

Oh, the standard qemu implementation auto-cracks, so .impl is correct.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

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

* Re: [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
  2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
                   ` (10 preceding siblings ...)
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 11/11] fdc: Convert isabus_fdc_init1 to MemoryRegion Richard Henderson
@ 2011-08-11  7:48 ` Avi Kivity
  2011-08-11  8:05   ` Edgar E. Iglesias
  2011-08-11 14:58   ` Richard Henderson
  11 siblings, 2 replies; 23+ messages in thread
From: Avi Kivity @ 2011-08-11  7:48 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 08/11/2011 01:28 AM, Richard Henderson wrote:
> [ Sorry about the partial duplicates, Avi.  ]
>
> This patchset is relative to
>    git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory-region
>
> although I'm sure it could be applied on top of Avi's batch 4.
>
> This is not complete by any means.  I'm interested in feedback
> for some of the trickier points, e.g. pckbd and fdc.
>
> The pckbd mmio interface to mips_jazz is similar to how serial and
> ide/mmio are structured.  But there are way more uses of serial.
>

Thanks, I've queued this on my branch.

If we're going to work on this in parallel, we'd better coordinate.  
Right now I'm going though all files the contain qemu_ram_alloc 
alphabetically and converting them (now in 'O').  If anyone wants a 
letter, let me know.

Anthony, can we step up the merge rate?  There are now 70 patches in the 
queue and growing, at the current rate this will take months.

-- 
error compiling committee.c: too many arguments to function

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

* Re: [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
  2011-08-11  7:48 ` [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Avi Kivity
@ 2011-08-11  8:05   ` Edgar E. Iglesias
  2011-08-11  8:20     ` Avi Kivity
  2011-08-11 14:58   ` Richard Henderson
  1 sibling, 1 reply; 23+ messages in thread
From: Edgar E. Iglesias @ 2011-08-11  8:05 UTC (permalink / raw)
  To: Avi Kivity; +Cc: qemu-devel, Richard Henderson

On Thu, Aug 11, 2011 at 10:48:23AM +0300, Avi Kivity wrote:
> On 08/11/2011 01:28 AM, Richard Henderson wrote:
> >[ Sorry about the partial duplicates, Avi.  ]
> >
> >This patchset is relative to
> >   git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory-region
> >
> >although I'm sure it could be applied on top of Avi's batch 4.
> >
> >This is not complete by any means.  I'm interested in feedback
> >for some of the trickier points, e.g. pckbd and fdc.
> >
> >The pckbd mmio interface to mips_jazz is similar to how serial and
> >ide/mmio are structured.  But there are way more uses of serial.
> >
> 
> Thanks, I've queued this on my branch.
> 
> If we're going to work on this in parallel, we'd better coordinate.
> Right now I'm going though all files the contain qemu_ram_alloc
> alphabetically and converting them (now in 'O').  If anyone wants a
> letter, let me know.

Hi Avi,

I was planing to convert the xilinx_* and etraxfs_* parts soon.
Or have you already done any etrax* conversions?

Cheers

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

* Re: [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
  2011-08-11  8:05   ` Edgar E. Iglesias
@ 2011-08-11  8:20     ` Avi Kivity
  2011-08-11 10:24       ` Edgar E. Iglesias
  0 siblings, 1 reply; 23+ messages in thread
From: Avi Kivity @ 2011-08-11  8:20 UTC (permalink / raw)
  To: Edgar E. Iglesias; +Cc: qemu-devel, Richard Henderson

On 08/11/2011 11:05 AM, Edgar E. Iglesias wrote:
> >
> >  If we're going to work on this in parallel, we'd better coordinate.
> >  Right now I'm going though all files the contain qemu_ram_alloc
> >  alphabetically and converting them (now in 'O').  If anyone wants a
> >  letter, let me know.
>
> Hi Avi,
>
> I was planing to convert the xilinx_* and etraxfs_* parts soon.
> Or have you already done any etrax* conversions?
>

I converted etraxfs.c, which was then removed...

I haven't touched xilinx.  You can view the entire queue at

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

-- 
error compiling committee.c: too many arguments to function

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

* Re: [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
  2011-08-11  8:20     ` Avi Kivity
@ 2011-08-11 10:24       ` Edgar E. Iglesias
  2011-08-11 11:19         ` Avi Kivity
  0 siblings, 1 reply; 23+ messages in thread
From: Edgar E. Iglesias @ 2011-08-11 10:24 UTC (permalink / raw)
  To: Avi Kivity; +Cc: qemu-devel, Richard Henderson

On Thu, Aug 11, 2011 at 11:20:04AM +0300, Avi Kivity wrote:
> On 08/11/2011 11:05 AM, Edgar E. Iglesias wrote:
> >>
> >>  If we're going to work on this in parallel, we'd better coordinate.
> >>  Right now I'm going though all files the contain qemu_ram_alloc
> >>  alphabetically and converting them (now in 'O').  If anyone wants a
> >>  letter, let me know.
> >
> >Hi Avi,
> >
> >I was planing to convert the xilinx_* and etraxfs_* parts soon.
> >Or have you already done any etrax* conversions?
> >
> 
> I converted etraxfs.c, which was then removed...

I've been planing to remove that board for a while, apparantly
I did it to late. Sorry.

> 
> I haven't touched xilinx.  You can view the entire queue at
> 
>    git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory-region

OK, thanks. I'll post etrax devs soon and do xilinx devs this weekend.

Cheers

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

* Re: [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
  2011-08-11 10:24       ` Edgar E. Iglesias
@ 2011-08-11 11:19         ` Avi Kivity
  0 siblings, 0 replies; 23+ messages in thread
From: Avi Kivity @ 2011-08-11 11:19 UTC (permalink / raw)
  To: Edgar E. Iglesias; +Cc: qemu-devel, Richard Henderson

On 08/11/2011 01:24 PM, Edgar E. Iglesias wrote:
> >
> >  I converted etraxfs.c, which was then removed...
>
> I've been planing to remove that board for a while, apparantly
> I did it to late. Sorry.

No problem, especially as I didn't coordinate this with anyone.

> >
> >  I haven't touched xilinx.  You can view the entire queue at
> >
> >     git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory-region
>
> OK, thanks. I'll post etrax devs soon and do xilinx devs this weekend.
>

Great.

-- 
error compiling committee.c: too many arguments to function

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

* Re: [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
  2011-08-11  7:48 ` [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Avi Kivity
  2011-08-11  8:05   ` Edgar E. Iglesias
@ 2011-08-11 14:58   ` Richard Henderson
  2011-08-11 15:16     ` Avi Kivity
  1 sibling, 1 reply; 23+ messages in thread
From: Richard Henderson @ 2011-08-11 14:58 UTC (permalink / raw)
  To: Avi Kivity; +Cc: qemu-devel

On 08/11/2011 12:48 AM, Avi Kivity wrote:
> If we're going to work on this in parallel, we'd better coordinate.
> Right now I'm going though all files the contain qemu_ram_alloc
> alphabetically and converting them (now in 'O').  If anyone wants a
> letter, let me know.

I've been looking at files that contain isa_init_ioport.  Although
I fear all the easy ones are now done and they get more difficult
from here...


r~

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

* Re: [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA
  2011-08-11 14:58   ` Richard Henderson
@ 2011-08-11 15:16     ` Avi Kivity
  0 siblings, 0 replies; 23+ messages in thread
From: Avi Kivity @ 2011-08-11 15:16 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 08/11/2011 05:58 PM, Richard Henderson wrote:
> On 08/11/2011 12:48 AM, Avi Kivity wrote:
> >  If we're going to work on this in parallel, we'd better coordinate.
> >  Right now I'm going though all files the contain qemu_ram_alloc
> >  alphabetically and converting them (now in 'O').  If anyone wants a
> >  letter, let me know.
>
> I've been looking at files that contain isa_init_ioport.  Although
> I fear all the easy ones are now done and they get more difficult
> from here...
>

I think we need a multi-region helper:

     static const ISAIOPort list = {
          { 0x3c0, read_3c0, write_3c0 },
          ...
     };

     isa_init_ioport_list(dev, list);


-- 
error compiling committee.c: too many arguments to function

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

* Re: [Qemu-devel] [PATCH 07/11] i8259: Convert to MemoryRegion.
  2011-08-10 22:28 ` [Qemu-devel] [PATCH 07/11] i8259: " Richard Henderson
@ 2011-08-28 15:25   ` Avi Kivity
  0 siblings, 0 replies; 23+ messages in thread
From: Avi Kivity @ 2011-08-28 15:25 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 08/11/2011 01:28 AM, Richard Henderson wrote:
> The only non-obvious part is pic_poll_read which used
> "addr1>>  7" to detect whether one referred to either
> the master or slave PIC.  Instead, test this directly.

Crashes mipsel-test from qemu.org immediately:

>   /* XXX: add generic master/slave system */
>   static void pic_init1(int io_addr, int elcr_addr, PicState *s)
>   {
> -    register_ioport_write(io_addr, 2, 1, pic_ioport_write, s);
> -    register_ioport_read(io_addr, 2, 1, pic_ioport_read, s);
> +    memory_region_init_io(&s->base_io,&pic_base_ioport_ops, s, "pic", 2);
> +    memory_region_init_io(&s->elcr_io,&pic_elcr_ioport_ops, s, "elcr", 1);
> +
> +    isa_register_ioport(NULL,&s->base_io, io_addr);
>       if (elcr_addr>= 0) {
> -        register_ioport_write(elcr_addr, 1, 1, elcr_ioport_write, s);
> -        register_ioport_read(elcr_addr, 1, 1, elcr_ioport_read, s);
> +        isa_register_ioport(NULL,&s->elcr_io, elcr_addr);
>       }
> +
>       vmstate_register(NULL, io_addr,&vmstate_pic, s);
>       qemu_register_reset(pic_reset, s);
>   }


#0  0x00000000005979a9 in isa_register_ioport (dev=0x0, io=0x2c19380, 
start=32) at /build/home/tlv/akivity/qemu/hw/isa-bus.c:113
#1  0x00000000005ae200 in pic_init1 (io_addr=32, elcr_addr=1232, 
s=0x2c19360) at /build/home/tlv/akivity/qemu/hw/i8259.c:508
#2  0x00000000005ae943 in i8259_init (parent_irq=0x2c19280) at 
/build/home/tlv/akivity/qemu/hw/i8259.c:557
#3  0x00000000005a6b36 in mips_malta_init (ram_size=<optimized out>, 
boot_device=<optimized out>, kernel_filename=<optimized out>,
     kernel_cmdline=0x7fff7acf17b5 "console=ttyS0 init=/bin/sh", 
initrd_filename=0x7fff7acf17a3 "initrd.gz", cpu_model=<optimized out>)
     at /build/home/tlv/akivity/qemu/hw/mips_malta.c:913
#4  0x000000000055d2eb in main (argc=<optimized out>, argv=<optimized 
out>, envp=<optimized out>) at /build/home/tlv/akivity/qemu/vl.c:3257


-- 
error compiling committee.c: too many arguments to function

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

end of thread, other threads:[~2011-08-28 15:25 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-10 22:28 [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 01/11] pci: add pci_address_space_io() Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 02/11] isa: Pass i/o address space to isa_bus_new Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 03/11] isa: add isa_register_ioport() Richard Henderson
2011-08-11  6:18   ` Avi Kivity
2011-08-10 22:28 ` [Qemu-devel] [PATCH 04/11] pc: Re-order pc_init1 to initialize the ISA bus before ISA devices Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 05/11] cs4231a: Convert to MemoryRegion Richard Henderson
2011-08-11  6:22   ` Avi Kivity
2011-08-11  6:27     ` Avi Kivity
2011-08-10 22:28 ` [Qemu-devel] [PATCH 06/11] i8254: " Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 07/11] i8259: " Richard Henderson
2011-08-28 15:25   ` Avi Kivity
2011-08-10 22:28 ` [Qemu-devel] [PATCH 08/11] pckbd: " Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 09/11] serial: Convert serial_isa_initfn " Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 10/11] memory: Fix old_portio vs non-zero offset Richard Henderson
2011-08-10 22:28 ` [Qemu-devel] [PATCH 11/11] fdc: Convert isabus_fdc_init1 to MemoryRegion Richard Henderson
2011-08-11  7:48 ` [Qemu-devel] [PATCH 00/11] Memory API conversion for ISA Avi Kivity
2011-08-11  8:05   ` Edgar E. Iglesias
2011-08-11  8:20     ` Avi Kivity
2011-08-11 10:24       ` Edgar E. Iglesias
2011-08-11 11:19         ` Avi Kivity
2011-08-11 14:58   ` Richard Henderson
2011-08-11 15:16     ` Avi Kivity

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