Skip to contentSkip to conversation

qdev isa patches.

PATCH Superseded Gerd Hoffmann 3 participants 20 messages Sep 9, 2009 – Sep 11, 2009 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover qdev isa patches.

Hi,

Here is a batch of patches for the isa bus and isa bus devices. qdev support for the isa bus is reworked a bit, following up the default value discussion with Markus. A few devices are converted to qdev. Some bugs (like -M isapc segfaulting) are fixed along the way.

As usual the individual patches have more verbose descriptions.

cheers,
Gerd

#1 lore raw

PATCH 1/12 isapc: Fix irq routing

Only send irqs to ioapic in case we have one.
Fixes qemu segfault.

---
 hw/pc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/pc.c +2 -1
index 6292001..9af0cdb 100644
@@ -100,7 +100,8 @@ static void isa_irq_handler(void *opaque, int n, int level)
     if (n < 16) {
         qemu_set_irq(isa->i8259[n], level);
     }
-    qemu_set_irq(isa->ioapic[n], level);
+    if (isa->ioapic)
+        qemu_set_irq(isa->ioapic[n], level);
 };
 
 static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/12 isapc: pick a more sane default cpu for such old hardware.

In reply to Gerd Hoffmann
---
 hw/pc.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/pc.c +2 -0
index 9af0cdb..872cb3a 100644
@@ -1450,6 +1450,8 @@ static void pc_init_isa(ram_addr_t ram_size,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
+    if (cpu_model == NULL)
+        cpu_model = "486";
     pc_init1(ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 0);
Signature · 1 line
1.6.2.5
#3 lore raw

PATCH 3/12 qdev: drop iobase properties from isa bus

In reply to Gerd Hoffmann

Lot of ISA devices work at fixed addresses, so having iobase as bus property doesn't make much sense. Devices which can have different iobases will get a device property.

Also simply hard-code stuff which can't be configured anyway.

---
 hw/fdc.c        |   17 +++++++++--------
 hw/fdc.h        |    4 +---
 hw/isa-bus.c    |   10 +---------
 hw/isa.h        |    4 +---
 hw/mips_malta.c |    4 ++--
 hw/pc.c         |    4 ++--
 hw/pckbd.c      |    8 ++++----
 hw/ppc_prep.c   |    2 +-
 hw/sun4u.c      |    4 ++--
 9 files changed, 23 insertions(+), 34 deletions(-)
hw/fdc.c +9 -8
index db57710..d761e62 100644
@@ -1871,14 +1871,14 @@ static void fdctrl_connect_drives(fdctrl_t *fdctrl, BlockDriverState **fds)
     }
 }
 
-fdctrl_t *fdctrl_init_isa(int isairq, int dma_chann,
-                          uint32_t io_base,
-                          BlockDriverState **fds)
+fdctrl_t *fdctrl_init_isa(BlockDriverState **fds)
 {
     fdctrl_t *fdctrl;
     ISADevice *dev;
+    int isairq = 6;
+    int dma_chann = 2;
 
-    dev = isa_create_simple("isa-fdc", io_base, 0, isairq, -1);
+    dev = isa_create_simple("isa-fdc", isairq, -1);
     fdctrl = &(DO_UPCAST(fdctrl_isabus_t, busdev, dev)->state);
 
     fdctrl->dma_chann = dma_chann;
@@ -1968,14 +1968,15 @@ static int isabus_fdc_init1(ISADevice *dev)
 {
     fdctrl_isabus_t *isa = DO_UPCAST(fdctrl_isabus_t, busdev, dev);
     fdctrl_t *fdctrl = &isa->state;
+    int iobase = 0x3f0;
 
-    register_ioport_read(isa->busdev.iobase[0] + 0x01, 5, 1,
+    register_ioport_read(iobase + 0x01, 5, 1,
                          &fdctrl_read_port, fdctrl);
-    register_ioport_read(isa->busdev.iobase[0] + 0x07, 1, 1,
+    register_ioport_read(iobase + 0x07, 1, 1,
                          &fdctrl_read_port, fdctrl);
-    register_ioport_write(isa->busdev.iobase[0] + 0x01, 5, 1,
+    register_ioport_write(iobase + 0x01, 5, 1,
                           &fdctrl_write_port, fdctrl);
-    register_ioport_write(isa->busdev.iobase[0] + 0x07, 1, 1,
+    register_ioport_write(iobase + 0x07, 1, 1,
                           &fdctrl_write_port, fdctrl);
     isa_init_irq(&isa->busdev, &fdctrl->irq);
 
hw/fdc.h +1 -3
index 04d64ea..1b81ec1 100644
@@ -3,9 +3,7 @@
 
 typedef struct fdctrl_t fdctrl_t;
 
-fdctrl_t *fdctrl_init_isa(int isairq, int dma_chann,
-                          uint32_t io_base,
-                          BlockDriverState **fds);
+fdctrl_t *fdctrl_init_isa(BlockDriverState **fds);
 fdctrl_t *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
                              target_phys_addr_t mmio_base,
                              BlockDriverState **fds);
hw/isa-bus.c +1 -9
index 2843b51..fde066a 100644
@@ -35,11 +35,6 @@ static struct BusInfo isa_bus_info = {
     .name      = "ISA",
     .size      = sizeof(ISABus),
     .print_dev = isabus_dev_print,
-    .props     = (Property[]) {
-        DEFINE_PROP_HEX32("iobase",  ISADevice, iobase[0], -1),
-        DEFINE_PROP_HEX32("iobase2", ISADevice, iobase[1], -1),
-        DEFINE_PROP_END_OF_LIST(),
-    }
 };
 
 ISABus *isa_bus_new(DeviceState *dev)
@@ -122,8 +117,7 @@ void isa_qdev_register(ISADeviceInfo *info)
     qdev_register(&info->qdev);
 }
 
-ISADevice *isa_create_simple(const char *name, uint32_t iobase, uint32_t iobase2,
-                             uint32_t irq, uint32 irq2)
+ISADevice *isa_create_simple(const char *name, uint32_t irq, uint32 irq2)
 {
     DeviceState *dev;
     ISADevice *isa;
@@ -134,8 +128,6 @@ ISADevice *isa_create_simple(const char *name, uint32_t iobase, uint32_t iobase2
     }
     dev = qdev_create(&isabus->qbus, name);
     isa = DO_UPCAST(ISADevice, qdev, dev);
-    isa->iobase[0] = iobase;
-    isa->iobase[1] = iobase2;
     qdev_init(dev);
     if (irq != -1) {
         isa_connect_irq(isa, 0, irq);
hw/isa.h +1 -3
index d98acd5..24c5c66 100644
@@ -12,7 +12,6 @@ typedef struct ISADeviceInfo ISADeviceInfo;
 
 struct ISADevice {
     DeviceState qdev;
-    uint32_t iobase[2];
     uint32_t isairq[2];
     qemu_irq *irqs[2];
     int nirqs;
@@ -30,8 +29,7 @@ void isa_connect_irq(ISADevice *dev, int devirq, int isairq);
 qemu_irq isa_reserve_irq(int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p);
 void isa_qdev_register(ISADeviceInfo *info);
-ISADevice *isa_create_simple(const char *name, uint32_t iobase, uint32_t iobase2,
-                             uint32_t irq, uint32_t irq2);
+ISADevice *isa_create_simple(const char *name, uint32_t irq, uint32_t irq2);
 
 extern target_phys_addr_t isa_mem_base;
 
hw/mips_malta.c +2 -2
index bb6364b..3222e16 100644
@@ -921,7 +921,7 @@ void mips_malta_init (ram_addr_t ram_size,
     DMA_init(0);
 
     /* Super I/O */
-    isa_dev = isa_create_simple("i8042", 0x60, 0x64, 1, 12);
+    isa_dev = isa_create_simple("i8042", 1, 12);
  
     rtc_state = rtc_init(0x70, isa_reserve_irq(8), 2000);
     serial_init(0x3f8, isa_reserve_irq(4), 115200, serial_hds[0]);
@@ -932,7 +932,7 @@ void mips_malta_init (ram_addr_t ram_size,
         dinfo = drive_get(IF_FLOPPY, 0, i);
         fd[i] = dinfo ? dinfo->bdrv : NULL;
     }
-    floppy_controller = fdctrl_init_isa(6, 2, 0x3f0, fd);
+    floppy_controller = fdctrl_init_isa(fd);
 
     /* Sound card */
 #ifdef HAS_AUDIO
hw/pc.c +2 -2
index 872cb3a..0219961 100644
@@ -1373,7 +1373,7 @@ static void pc_init1(ram_addr_t ram_size,
         }
     }
 
-    isa_dev = isa_create_simple("i8042", 0x60, 0x64, 1, 12);
+    isa_dev = isa_create_simple("i8042", 1, 12);
     DMA_init(0);
 #ifdef HAS_AUDIO
     audio_init(pci_enabled ? pci_bus : NULL, isa_irq);
@@ -1383,7 +1383,7 @@ static void pc_init1(ram_addr_t ram_size,
         dinfo = drive_get(IF_FLOPPY, 0, i);
         fd[i] = dinfo ? dinfo->bdrv : NULL;
     }
-    floppy_controller = fdctrl_init_isa(6, 2, 0x3f0, fd);
+    floppy_controller = fdctrl_init_isa(fd);
 
     cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd);
 
hw/pckbd.c +4 -4
index 3f83320..b4b65a6 100644
@@ -455,10 +455,10 @@ static int i8042_initfn(ISADevice *dev)
 
     kbd_reset(s);
     register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
-    register_ioport_read(dev->iobase[0], 1, 1, kbd_read_data, s);
-    register_ioport_write(dev->iobase[0], 1, 1, kbd_write_data, s);
-    register_ioport_read(dev->iobase[1], 1, 1, kbd_read_status, s);
-    register_ioport_write(dev->iobase[1], 1, 1, kbd_write_command, s);
+    register_ioport_read(0x60, 1, 1, kbd_read_data, s);
+    register_ioport_write(0x60, 1, 1, kbd_write_data, s);
+    register_ioport_read(0x64, 1, 1, kbd_read_status, s);
+    register_ioport_write(0x64, 1, 1, kbd_write_command, s);
 
     s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
     s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
hw/ppc_prep.c +1 -1
index c081d58..3fbfc8b 100644
@@ -719,7 +719,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
         dinfo = drive_get(IF_FLOPPY, 0, i);
         fd[i] = dinfo ? dinfo->bdrv : NULL;
     }
-    fdctrl_init_isa(6, 2, 0x3f0, fd);
+    fdctrl_init_isa(fd);
 
     /* Register speaker port */
     register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL);
hw/sun4u.c +2 -2
index 03855d3..b71df1f 100644
@@ -617,12 +617,12 @@ static void sun4uv_init(ram_addr_t RAM_size,
 
     pci_cmd646_ide_init(pci_bus, hd, 1);
 
-    isa_create_simple("i8042", 0x60, 0x64, 1, 12);
+    isa_create_simple("i8042", 1, 12);
     for(i = 0; i < MAX_FD; i++) {
         dinfo = drive_get(IF_FLOPPY, 0, i);
         fd[i] = dinfo ? dinfo->bdrv : NULL;
     }
-    fdctrl_init_isa(6, 2, 0x3f0, fd);
+    fdctrl_init_isa(fd);
     /* FIXME: wire up interrupts.  */
     nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59);
 
Signature · 1 line
1.6.2.5
#4 lore raw

PATCH 4/12 qdev: simplify isa irq assignments

In reply to Gerd Hoffmann

isa-bus owns the isa irqs now, so it can hand them out directly. There is no need for the separate isa_connect_irqs step, drop it.

Also hard-code isa interrupts which can't be configured anyway.

---
 hw/fdc.c        |    6 +++---
 hw/isa-bus.c    |   38 +++++++++++---------------------------
 hw/isa.h        |    6 ++----
 hw/mips_malta.c |    2 +-
 hw/pc.c         |    2 +-
 hw/pckbd.c      |    4 ++--
 hw/sun4u.c      |    2 +-
 7 files changed, 21 insertions(+), 39 deletions(-)
hw/fdc.c +3 -3
index d761e62..47b1c9d 100644
@@ -1875,10 +1875,9 @@ fdctrl_t *fdctrl_init_isa(BlockDriverState **fds)
 {
     fdctrl_t *fdctrl;
     ISADevice *dev;
-    int isairq = 6;
     int dma_chann = 2;
 
-    dev = isa_create_simple("isa-fdc", isairq, -1);
+    dev = isa_create_simple("isa-fdc");
     fdctrl = &(DO_UPCAST(fdctrl_isabus_t, busdev, dev)->state);
 
     fdctrl->dma_chann = dma_chann;
@@ -1969,6 +1968,7 @@ static int isabus_fdc_init1(ISADevice *dev)
     fdctrl_isabus_t *isa = DO_UPCAST(fdctrl_isabus_t, busdev, dev);
     fdctrl_t *fdctrl = &isa->state;
     int iobase = 0x3f0;
+    int isairq = 6;
 
     register_ioport_read(iobase + 0x01, 5, 1,
                          &fdctrl_read_port, fdctrl);
@@ -1978,7 +1978,7 @@ static int isabus_fdc_init1(ISADevice *dev)
                           &fdctrl_write_port, fdctrl);
     register_ioport_write(iobase + 0x07, 1, 1,
                           &fdctrl_write_port, fdctrl);
-    isa_init_irq(&isa->busdev, &fdctrl->irq);
+    isa_init_irq(&isa->busdev, &fdctrl->irq, isairq);
 
     return fdctrl_init_common(fdctrl);
 }
hw/isa-bus.c +11 -27
index fde066a..bfd0fff 100644
@@ -57,20 +57,6 @@ void isa_bus_irqs(qemu_irq *irqs)
     isabus->irqs = irqs;
 }
 
-void isa_connect_irq(ISADevice *dev, int devnr, int isairq)
-{
-    assert(devnr >= 0 && devnr < dev->nirqs);
-    if (isabus->assigned & (1 << isairq)) {
-        fprintf(stderr, "isa irq %d already assigned\n", isairq);
-        exit(1);
-    }
-    if (dev->irqs[devnr]) {
-        isabus->assigned |= (1 << isairq);
-        dev->isairq[devnr] = isairq;
-        *dev->irqs[devnr] = isabus->irqs[isairq];
-    }
-}
-
 /*
  * isa_reserve_irq() reserves the ISA irq and returns the corresponding
  * qemu_irq entry for the i8259.
@@ -92,10 +78,16 @@ qemu_irq isa_reserve_irq(int isairq)
     return isabus->irqs[isairq];
 }
 
-void isa_init_irq(ISADevice *dev, qemu_irq *p)
+void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
 {
-    assert(dev->nirqs < ARRAY_SIZE(dev->irqs));
-    dev->irqs[dev->nirqs] = p;
+    assert(dev->nirqs < ARRAY_SIZE(dev->isairq));
+    if (isabus->assigned & (1 << isairq)) {
+        fprintf(stderr, "isa irq %d already assigned\n", isairq);
+        exit(1);
+    }
+    isabus->assigned |= (1 << isairq);
+    dev->isairq[dev->nirqs] = isairq;
+    *p = isabus->irqs[isairq];
     dev->nirqs++;
 }
 
@@ -117,25 +109,17 @@ void isa_qdev_register(ISADeviceInfo *info)
     qdev_register(&info->qdev);
 }
 
-ISADevice *isa_create_simple(const char *name, uint32_t irq, uint32 irq2)
+ISADevice *isa_create_simple(const char *name)
 {
     DeviceState *dev;
-    ISADevice *isa;
 
     if (!isabus) {
         fprintf(stderr, "Tried to create isa device %s with no isa bus present.\n", name);
         return NULL;
     }
     dev = qdev_create(&isabus->qbus, name);
-    isa = DO_UPCAST(ISADevice, qdev, dev);
     qdev_init(dev);
-    if (irq != -1) {
-        isa_connect_irq(isa, 0, irq);
-    }
-    if (irq2 != -1) {
-        isa_connect_irq(isa, 1, irq2);
-    }
-    return isa;
+    return DO_UPCAST(ISADevice, qdev, dev);
 }
 
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
hw/isa.h +2 -4
index 24c5c66..4582ff9 100644
@@ -13,7 +13,6 @@ typedef struct ISADeviceInfo ISADeviceInfo;
 struct ISADevice {
     DeviceState qdev;
     uint32_t isairq[2];
-    qemu_irq *irqs[2];
     int nirqs;
 };
 
@@ -25,11 +24,10 @@ struct ISADeviceInfo {
 
 ISABus *isa_bus_new(DeviceState *dev);
 void isa_bus_irqs(qemu_irq *irqs);
-void isa_connect_irq(ISADevice *dev, int devirq, int isairq);
 qemu_irq isa_reserve_irq(int isairq);
-void isa_init_irq(ISADevice *dev, qemu_irq *p);
+void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
 void isa_qdev_register(ISADeviceInfo *info);
-ISADevice *isa_create_simple(const char *name, uint32_t irq, uint32_t irq2);
+ISADevice *isa_create_simple(const char *name);
 
 extern target_phys_addr_t isa_mem_base;
 
hw/mips_malta.c +1 -1
index 3222e16..32c7102 100644
@@ -921,7 +921,7 @@ void mips_malta_init (ram_addr_t ram_size,
     DMA_init(0);
 
     /* Super I/O */
-    isa_dev = isa_create_simple("i8042", 1, 12);
+    isa_dev = isa_create_simple("i8042");
  
     rtc_state = rtc_init(0x70, isa_reserve_irq(8), 2000);
     serial_init(0x3f8, isa_reserve_irq(4), 115200, serial_hds[0]);
hw/pc.c +1 -1
index 0219961..e1ffaa4 100644
@@ -1373,7 +1373,7 @@ static void pc_init1(ram_addr_t ram_size,
         }
     }
 
-    isa_dev = isa_create_simple("i8042", 1, 12);
+    isa_dev = isa_create_simple("i8042");
     DMA_init(0);
 #ifdef HAS_AUDIO
     audio_init(pci_enabled ? pci_bus : NULL, isa_irq);
hw/pckbd.c +2 -2
index b4b65a6..5acf4a6 100644
@@ -450,8 +450,8 @@ static int i8042_initfn(ISADevice *dev)
 {
     KBDState *s = &(DO_UPCAST(ISAKBDState, dev, dev)->kbd);
 
-    isa_init_irq(dev, &s->irq_kbd);
-    isa_init_irq(dev, &s->irq_mouse);
+    isa_init_irq(dev, &s->irq_kbd, 1);
+    isa_init_irq(dev, &s->irq_mouse, 12);
 
     kbd_reset(s);
     register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
hw/sun4u.c +1 -1
index b71df1f..ffda4cd 100644
@@ -617,7 +617,7 @@ static void sun4uv_init(ram_addr_t RAM_size,
 
     pci_cmd646_ide_init(pci_bus, hd, 1);
 
-    isa_create_simple("i8042", 1, 12);
+    isa_create_simple("i8042");
     for(i = 0; i < MAX_FD; i++) {
         dinfo = drive_get(IF_FLOPPY, 0, i);
         fd[i] = dinfo ? dinfo->bdrv : NULL;
Signature · 1 line
1.6.2.5
#5 lore raw

PATCH 5/12 qdev: tag isabus-bridge as no-user

In reply to Gerd Hoffmann

isabus-bridge isn't supposed to be added via -device ...

---
 hw/isa-bus.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/isa-bus.c +1 -0
index bfd0fff..3cc17b2 100644
@@ -145,6 +145,7 @@ static SysBusDeviceInfo isabus_bridge_info = {
     .init = isabus_bridge_init,
     .qdev.name  = "isabus-bridge",
     .qdev.size  = sizeof(SysBusDevice),
+    .qdev.no_user = 1,
 };
 
 static void isabus_register_devices(void)
Signature · 1 line
1.6.2.5
#6 lore raw

PATCH 6/12 qdev: add isa_create() function

In reply to Gerd Hoffmann

Like isa_create_simple, but doesn't call qdev_init, so one can set properties after creating and before initializing the device.

---
 hw/isa-bus.c |   15 +++++++++++++--
 hw/isa.h     |    1 +
 2 files changed, 14 insertions(+), 2 deletions(-)
hw/isa-bus.c +13 -2
index 3cc17b2..4ecc0f8 100644
@@ -109,7 +109,7 @@ void isa_qdev_register(ISADeviceInfo *info)
     qdev_register(&info->qdev);
 }
 
-ISADevice *isa_create_simple(const char *name)
+ISADevice *isa_create(const char *name)
 {
     DeviceState *dev;
 
@@ -118,10 +118,21 @@ ISADevice *isa_create_simple(const char *name)
         return NULL;
     }
     dev = qdev_create(&isabus->qbus, name);
-    qdev_init(dev);
     return DO_UPCAST(ISADevice, qdev, dev);
 }
 
+ISADevice *isa_create_simple(const char *name)
+{
+    ISADevice *dev;
+
+    dev = isa_create(name);
+    if (qdev_init(&dev->qdev) != 0) {
+        qdev_free(&dev->qdev);
+        return NULL;
+    }
+    return dev;
+}
+
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     ISADevice *d = DO_UPCAST(ISADevice, qdev, dev);
hw/isa.h +1 -0
index 4582ff9..655ad62 100644
@@ -27,6 +27,7 @@ void isa_bus_irqs(qemu_irq *irqs);
 qemu_irq isa_reserve_irq(int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
 void isa_qdev_register(ISADeviceInfo *info);
+ISADevice *isa_create(const char *name);
 ISADevice *isa_create_simple(const char *name);
 
 extern target_phys_addr_t isa_mem_base;
Signature · 1 line
1.6.2.5
#7 lore raw

PATCH 7/12 qdev/isa: convert soundblaster

In reply to Gerd Hoffmann
---
 hw/sb16.c |   63 +++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 39 insertions(+), 24 deletions(-)
hw/sb16.c +39 -24
index ac41a13..4105579 100644
@@ -25,6 +25,7 @@
 #include "audiodev.h"
 #include "audio/audio.h"
 #include "isa.h"
+#include "qdev.h"
 #include "qemu-timer.h"
 
 #define dolog(...) AUD_log ("sb16", __VA_ARGS__)
@@ -45,23 +46,15 @@
 
 static const char e3[] = "COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.";
 
-static struct {
-    int ver_lo;
-    int ver_hi;
-    int irq;
-    int dma;
-    int hdma;
-    int port;
-} conf = {5, 4, 5, 1, 5, 0x220};
-
 typedef struct SB16State {
+    ISADevice dev;
     QEMUSoundCard card;
     qemu_irq pic;
-    int irq;
-    int dma;
-    int hdma;
-    int port;
-    int ver;
+    uint32_t irq;
+    uint32_t dma;
+    uint32_t hdma;
+    uint32_t port;
+    uint32_t ver;
 
     int in_index;
     int out_data_len;
@@ -1398,22 +1391,17 @@ static int SB_load (QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-int SB16_init (qemu_irq *pic)
+static int sb16_initfn (ISADevice *dev)
 {
-    SB16State *s;
-    int i;
     static const uint8_t dsp_write_ports[] = {0x6, 0xc};
     static const uint8_t dsp_read_ports[] = {0x6, 0xa, 0xc, 0xd, 0xe, 0xf};
+    SB16State *s;
+    int i;
 
-    s = qemu_mallocz (sizeof (*s));
+    s = DO_UPCAST (SB16State, dev, dev);
 
     s->cmd = -1;
-    s->pic = isa_reserve_irq (conf.irq);
-    s->irq = conf.irq;
-    s->dma = conf.dma;
-    s->hdma = conf.hdma;
-    s->port = conf.port;
-    s->ver = conf.ver_lo | (conf.ver_hi << 8);
+    isa_init_irq (dev, &s->pic, s->irq);
 
     s->mixer_regs[0x80] = magic_of_irq (s->irq);
     s->mixer_regs[0x81] = (1 << s->dma) | (1 << s->hdma);
@@ -1449,3 +1437,30 @@ int SB16_init (qemu_irq *pic)
     AUD_register_card ("sb16", &s->card);
     return 0;
 }
+
+int SB16_init (qemu_irq *pic)
+{
+    isa_create_simple("sb16");
+    return 0;
+}
+
+static ISADeviceInfo sb16_info = {
+    .qdev.name     = "sb16",
+    .qdev.desc     = "Creative Sound Blaster 16",
+    .qdev.size     = sizeof (SB16State),
+    .init          = sb16_initfn,
+    .qdev.props    = (Property[]) {
+        DEFINE_PROP_HEX32  ("version", SB16State, ver,  0x0405), /* 4.5 */
+        DEFINE_PROP_HEX32  ("iobase",  SB16State, port, 0x220),
+        DEFINE_PROP_UINT32 ("irq",     SB16State, irq,  5),
+        DEFINE_PROP_UINT32 ("dma",     SB16State, dma,  1),
+        DEFINE_PROP_UINT32 ("dma16",   SB16State, hdma, 5),
+        DEFINE_PROP_END_OF_LIST (),
+    },
+};
+
+static void sb16_register(void)
+{
+    isa_qdev_register(&sb16_info);
+}
+device_init(sb16_register)
Signature · 1 line
1.6.2.5
#8 lore raw

PATCH 8/12 qdev/isa: convert cs4231a sound card

In reply to Gerd Hoffmann
---
 hw/cs4231a.c |   46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)
hw/cs4231a.c +33 -13
index 46c71eb..91ee2aa 100644
@@ -25,6 +25,7 @@
 #include "audiodev.h"
 #include "audio/audio.h"
 #include "isa.h"
+#include "qdev.h"
 #include "qemu-timer.h"
 
 /*
@@ -40,11 +41,8 @@
 /* #define DEBUG_XLAW */
 
 static struct {
-    int irq;
-    int dma;
-    int port;
     int aci_counter;
-} conf = {9, 3, 0x534, 1};
+} conf = {1};
 
 #ifdef DEBUG
 #define dolog(...) AUD_log ("cs4231a", __VA_ARGS__)
@@ -59,12 +57,14 @@ static struct {
 #define CS_DREGS 32
 
 typedef struct CSState {
+    ISADevice dev;
     QEMUSoundCard card;
     qemu_irq pic;
     uint32_t regs[CS_REGS];
     uint8_t dregs[CS_DREGS];
-    int dma;
-    int port;
+    uint32_t irq;
+    uint32_t dma;
+    uint32_t port;
     int shift;
     int dma_running;
     int audio_free;
@@ -635,16 +635,12 @@ static int cs_load (QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-int cs4231a_init (qemu_irq *pic)
+static int cs4231a_initfn (ISADevice *dev)
 {
+    CSState *s = DO_UPCAST (CSState, dev, dev);
     int i;
-    CSState *s;
-
-    s = qemu_mallocz (sizeof (*s));
 
-    s->pic = isa_reserve_irq (conf.irq);
-    s->dma = conf.dma;
-    s->port = conf.port;
+    isa_init_irq (dev, &s->pic, s->irq);
 
     for (i = 0; i < 4; i++) {
         register_ioport_write (s->port + i, 1, 1, cs_write, s);
@@ -660,3 +656,27 @@ int cs4231a_init (qemu_irq *pic)
     AUD_register_card ("cs4231a", &s->card);
     return 0;
 }
+
+int cs4231a_init (qemu_irq *pic)
+{
+    isa_create_simple("cs4231a");
+    return 0;
+}
+
+static ISADeviceInfo cs4231a_info = {
+    .qdev.name     = "cs4231a",
+    .qdev.size     = sizeof (CSState),
+    .init          = cs4231a_initfn,
+    .qdev.props    = (Property[]) {
+        DEFINE_PROP_HEX32  ("iobase",  CSState, port, 0x534),
+        DEFINE_PROP_UINT32 ("irq",     CSState, irq,  9),
+        DEFINE_PROP_UINT32 ("dma",     CSState, dma,  3),
+        DEFINE_PROP_END_OF_LIST (),
+    },
+};
+
+static void cs4231a_register(void)
+{
+    isa_qdev_register(&cs4231a_info);
+}
+device_init(cs4231a_register)
Signature · 1 line
1.6.2.5
#9 lore raw

PATCH 9/12 qdev/isa: convert gravis ultrasound

In reply to Gerd Hoffmann
---
 hw/gus.c    |   75 ++++++++++++++++++++++++++++++++++++++--------------------
 hw/gusemu.h |    4 +-
 2 files changed, 51 insertions(+), 28 deletions(-)
hw/gus.c +49 -26
index 5e73c5a..b41095e 100644
@@ -54,16 +54,18 @@ static struct {
 } conf = {0x240, 7, 3, 44100};
 
 typedef struct GUSState {
+    ISADevice dev;
     GUSEmuState emu;
     QEMUSoundCard card;
-    int freq;
+    uint32_t freq;
+    uint32_t port;
     int pos, left, shift, irqs;
     GUSsample *mixbuf;
     uint8_t himem[1024 * 1024 + 32 + 4096];
     int samples;
     SWVoiceOut *voice;
     int64_t last_ticks;
-    qemu_irq *pic;
+    qemu_irq pic;
 } GUSState;
 
 IO_READ_PROTO (gus_readb)
@@ -168,8 +170,8 @@ reset:
 int GUS_irqrequest (GUSEmuState *emu, int hwirq, int n)
 {
     GUSState *s = emu->opaque;
-    /* qemu_irq_lower (s->pic[hwirq]); */
-    qemu_irq_raise (s->pic[hwirq]);
+    /* qemu_irq_lower (s->pic); */
+    qemu_irq_raise (s->pic);
     s->irqs += n;
     ldebug ("irqrequest %d %d %d\n", hwirq, n, s->irqs);
     return n;
@@ -179,7 +181,7 @@ void GUS_irqclear (GUSEmuState *emu, int hwirq)
 {
     GUSState *s = emu->opaque;
     ldebug ("irqclear %d %d\n", hwirq, s->irqs);
-    qemu_irq_lower (s->pic[hwirq]);
+    qemu_irq_lower (s->pic);
     s->irqs -= 1;
 #ifdef IRQ_STORM
     if (s->irqs > 0) {
@@ -250,16 +252,14 @@ static int GUS_load (QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-int GUS_init (qemu_irq *pic)
+static int gus_initfn (ISADevice *dev)
 {
-    GUSState *s;
+    GUSState *s = DO_UPCAST(GUSState, dev, dev);
     struct audsettings as;
 
-    s = qemu_mallocz (sizeof (*s));
-
     AUD_register_card ("gus", &s->card);
 
-    as.freq = conf.freq;
+    as.freq = s->freq;
     as.nchannels = 2;
     as.fmt = AUD_FMT_S16;
     as.endianness = GUS_ENDIANNESS;
@@ -283,34 +283,57 @@ int GUS_init (qemu_irq *pic)
     s->samples = AUD_get_buffer_size_out (s->voice) >> s->shift;
     s->mixbuf = qemu_mallocz (s->samples << s->shift);
 
-    register_ioport_write (conf.port, 1, 1, gus_writeb, s);
-    register_ioport_write (conf.port, 1, 2, gus_writew, s);
+    register_ioport_write (s->port, 1, 1, gus_writeb, s);
+    register_ioport_write (s->port, 1, 2, gus_writew, s);
 
-    register_ioport_read ((conf.port + 0x100) & 0xf00, 1, 1, gus_readb, s);
-    register_ioport_read ((conf.port + 0x100) & 0xf00, 1, 2, gus_readw, s);
+    register_ioport_read ((s->port + 0x100) & 0xf00, 1, 1, gus_readb, s);
+    register_ioport_read ((s->port + 0x100) & 0xf00, 1, 2, gus_readw, s);
 
-    register_ioport_write (conf.port + 6, 10, 1, gus_writeb, s);
-    register_ioport_write (conf.port + 6, 10, 2, gus_writew, s);
-    register_ioport_read (conf.port + 6, 10, 1, gus_readb, s);
-    register_ioport_read (conf.port + 6, 10, 2, gus_readw, s);
+    register_ioport_write (s->port + 6, 10, 1, gus_writeb, s);
+    register_ioport_write (s->port + 6, 10, 2, gus_writew, s);
+    register_ioport_read (s->port + 6, 10, 1, gus_readb, s);
+    register_ioport_read (s->port + 6, 10, 2, gus_readw, s);
 
 
-    register_ioport_write (conf.port + 0x100, 8, 1, gus_writeb, s);
-    register_ioport_write (conf.port + 0x100, 8, 2, gus_writew, s);
-    register_ioport_read (conf.port + 0x100, 8, 1, gus_readb, s);
-    register_ioport_read (conf.port + 0x100, 8, 2, gus_readw, s);
+    register_ioport_write (s->port + 0x100, 8, 1, gus_writeb, s);
+    register_ioport_write (s->port + 0x100, 8, 2, gus_writew, s);
+    register_ioport_read (s->port + 0x100, 8, 1, gus_readb, s);
+    register_ioport_read (s->port + 0x100, 8, 2, gus_readw, s);
 
     DMA_register_channel (conf.dma, GUS_read_DMA, s);
-    s->emu.gusirq = conf.irq;
-    s->emu.gusdma = conf.dma;
     s->emu.himemaddr = s->himem;
     s->emu.gusdatapos = s->emu.himemaddr + 1024 * 1024 + 32;
     s->emu.opaque = s;
-    s->freq = conf.freq;
-    s->pic = pic;
+    isa_init_irq(dev, &s->pic, s->emu.gusirq);
 
     AUD_set_active_out (s->voice, 1);
 
     register_savevm ("gus", 0, 2, GUS_save, GUS_load, s);
     return 0;
 }
+
+int GUS_init (qemu_irq *pic)
+{
+    isa_create_simple("gus");
+    return 0;
+}
+
+static ISADeviceInfo gus_info = {
+    .qdev.name     = "gus",
+    .qdev.desc     = "Creative Sound Blaster 16",
+    .qdev.size     = sizeof (GUSState),
+    .init          = gus_initfn,
+    .qdev.props    = (Property[]) {
+        DEFINE_PROP_UINT32 ("freq",    GUSState, freq,        44100),
+        DEFINE_PROP_HEX32  ("iobase",  GUSState, port,        0x240),
+        DEFINE_PROP_UINT32 ("irq",     GUSState, emu.gusirq,  7),
+        DEFINE_PROP_UINT32 ("dma",     GUSState, emu.gusdma,  3),
+        DEFINE_PROP_END_OF_LIST (),
+    },
+};
+
+static void gus_register(void)
+{
+    isa_qdev_register(&gus_info);
+}
+device_init(gus_register)
hw/gusemu.h +2 -2
index a64300a..5093767 100644
@@ -46,8 +46,8 @@ typedef struct _GUSEmuState
 {
  GUSbyte *himemaddr; /* 1024*1024 bytes used for storing uploaded samples (+32 additional bytes for read padding) */
  GUSbyte *gusdatapos; /* (gusdataend-gusdata) bytes used for storing emulated GF1/mixer register states (32*32+4 bytes in initial GUSemu32 version) */
- int gusirq;
- int gusdma;
+ uint32_t gusirq;
+ uint32_t gusdma;
  unsigned int timer1fraction;
  unsigned int timer2fraction;
  void *opaque;
Signature · 1 line
1.6.2.5
#10 lore raw

PATCH 10/12 qdev/isa: convert ne2000

In reply to Gerd Hoffmann

Also split the isa bits into a separate source file, so we don't drag in a dependency for isa-bus.o for machines which want ne2k_pci only.

---
 Makefile.target |    5 +-
 hw/mips_r4k.c   |    2 +-
 hw/ne2000-isa.c |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/ne2000.c     |  106 +++++++++-------------------------------------------
 hw/ne2000.h     |   40 ++++++++++++++++++++
 hw/pc.c         |    2 +-
 hw/pc.h         |    2 +-
 hw/ppc_prep.c   |    2 +-
 8 files changed, 177 insertions(+), 93 deletions(-)
 create mode 100644 hw/ne2000-isa.c
 create mode 100644 hw/ne2000.h
Makefile.target +3 -2
index 67bd4d7..2c03877 100644
@@ -188,13 +188,14 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
+obj-i386-y += ne2000-isa.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/isa.o ide/pci.o ide/macio.o
 obj-ppc-y += vga.o $(sound-obj-y) dma.o isa-bus.o openpic.o
 # PREP target
 obj-ppc-y += pckbd.o serial.o i8259.o i8254.o fdc.o mc146818rtc.o
-obj-ppc-y += prep_pci.o ppc_prep.o
+obj-ppc-y += prep_pci.o ppc_prep.o ne2000-isa.o
 # Mac shared devices
 obj-ppc-y += macio.o cuda.o adb.o mac_nvram.o mac_dbdma.o
 # OldWorld PowerMac
@@ -215,7 +216,7 @@ obj-mips-y += g364fb.o jazz_led.o dp8393x.o
 obj-mips-y += ide/core.o ide/isa.o ide/pci.o
 obj-mips-y += gt64xxx.o pckbd.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
 obj-mips-y += piix4.o parallel.o cirrus_vga.o isa-bus.o pcspk.o $(sound-obj-y)
-obj-mips-y += mipsnet.o
+obj-mips-y += mipsnet.o ne2000-isa.o
 obj-mips-y += pflash_cfi01.o
 obj-mips-y += vmware_vga.o
 
hw/mips_r4k.c +1 -1
index da5ca31..aacb256 100644
@@ -260,7 +260,7 @@ void mips_r4k_init (ram_addr_t ram_size,
     isa_vga_init();
 
     if (nd_table[0].vlan)
-        isa_ne2000_init(0x300, i8259[9], &nd_table[0]);
+        isa_ne2000_init(0x300, 9, &nd_table[0]);
 
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
hw/ne2000-isa.c new file +111 -0

111 lines not on this page · raw message

hw/ne2000.c +19 -87

187 lines not on this page · raw message

hw/ne2000.h new file +40 -0
new file mode 100644
index 0000000..92a2ddb
@@ -0,0 +1,40 @@
+#define NE2000_PMEM_SIZE    (32*1024)
+#define NE2000_PMEM_START   (16*1024)
+#define NE2000_PMEM_END     (NE2000_PMEM_SIZE+NE2000_PMEM_START)
+#define NE2000_MEM_SIZE     NE2000_PMEM_END
+
+typedef struct NE2000State {
+    uint8_t cmd;
+    uint32_t start;
+    uint32_t stop;
+    uint8_t boundary;
+    uint8_t tsr;
+    uint8_t tpsr;
+    uint16_t tcnt;
+    uint16_t rcnt;
+    uint32_t rsar;
+    uint8_t rsr;
+    uint8_t rxcr;
+    uint8_t isr;
+    uint8_t dcfg;
+    uint8_t imr;
+    uint8_t phys[6]; /* mac address */
+    uint8_t curpag;
+    uint8_t mult[8]; /* multicast mask array */
+    qemu_irq irq;
+    VLANClientState *vc;
+    uint8_t macaddr[6];
+    uint8_t mem[NE2000_MEM_SIZE];
+} NE2000State;
+
+void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val);
+uint32_t ne2000_ioport_read(void *opaque, uint32_t addr);
+void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val);
+uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr);
+void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val);
+uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr);
+void ne2000_save(QEMUFile* f, void* opaque);
+int ne2000_load(QEMUFile* f, void* opaque, int version_id);
+void ne2000_reset(NE2000State *s);
+int ne2000_can_receive(VLANClientState *vc);
+ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_);
hw/pc.c +1 -1
index e1ffaa4..9497f71 100644
@@ -1052,7 +1052,7 @@ static void pc_init_ne2k_isa(NICInfo *nd)
     if (nb_ne2k == NE2000_NB_MAX)
         return;
     isa_ne2000_init(ne2000_io[nb_ne2k],
-                    isa_reserve_irq(ne2000_irq[nb_ne2k]), nd);
+                    ne2000_irq[nb_ne2k], nd);
     nb_ne2k++;
 }
 
hw/pc.h +1 -1
index ec5735b..d80d3a5 100644
@@ -148,7 +148,7 @@ void isa_cirrus_vga_init(void);
 
 /* ne2000.c */
 
-void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd);
+void isa_ne2000_init(int base, int irq, NICInfo *nd);
 
 int cpu_is_bsp(CPUState *env);
 #endif
hw/ppc_prep.c +1 -1
index 3fbfc8b..994c965 100644
@@ -691,7 +691,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
 	    nd_table[i].model = "ne2k_isa";
         }
         if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
-            isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
+            isa_ne2000_init(ne2000_io[i], ne2000_irq[i], &nd_table[i]);
         } else {
             pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
         }
Signature · 1 line
1.6.2.5
#11 lore raw

Re: [Qemu-devel] [PATCH 10/12] qdev/isa: convert ne2000

Quoted 4 lines · Gerd Hoffmann

Also split the isa bits into a separate source file, so we don't drag in a dependency for isa-bus.o for machines which want ne2k_pci only.

Review would be easier if the split was a separate commit that doesn't change code. No need to respin.

#12 lore raw

Re: [Qemu-devel] [PATCH 10/12] qdev/isa: convert ne2000

In reply to Gerd Hoffmann
Quoted 4 lines · Gerd Hoffmann

Also split the isa bits into a separate source file, so we don't drag in a dependency for isa-bus.o for machines which want ne2k_pci only.

Closer examination led to a few questions...

Quoted 125 lines
---
 Makefile.target |    5 +-
 hw/mips_r4k.c   |    2 +-
 hw/ne2000-isa.c |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/ne2000.c     |  106 +++++++++-------------------------------------------
 hw/ne2000.h     |   40 ++++++++++++++++++++
 hw/pc.c         |    2 +-
 hw/pc.h         |    2 +-
 hw/ppc_prep.c   |    2 +-
 8 files changed, 177 insertions(+), 93 deletions(-)
 create mode 100644 hw/ne2000-isa.c
 create mode 100644 hw/ne2000.h
Makefile.target +3 -2
index 67bd4d7..2c03877 100644
@@ -188,13 +188,14 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
+obj-i386-y += ne2000-isa.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/isa.o ide/pci.o ide/macio.o
 obj-ppc-y += vga.o $(sound-obj-y) dma.o isa-bus.o openpic.o
 # PREP target
 obj-ppc-y += pckbd.o serial.o i8259.o i8254.o fdc.o mc146818rtc.o
-obj-ppc-y += prep_pci.o ppc_prep.o
+obj-ppc-y += prep_pci.o ppc_prep.o ne2000-isa.o
 # Mac shared devices
 obj-ppc-y += macio.o cuda.o adb.o mac_nvram.o mac_dbdma.o
 # OldWorld PowerMac
@@ -215,7 +216,7 @@ obj-mips-y += g364fb.o jazz_led.o dp8393x.o
 obj-mips-y += ide/core.o ide/isa.o ide/pci.o
 obj-mips-y += gt64xxx.o pckbd.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
 obj-mips-y += piix4.o parallel.o cirrus_vga.o isa-bus.o pcspk.o $(sound-obj-y)
-obj-mips-y += mipsnet.o
+obj-mips-y += mipsnet.o ne2000-isa.o
 obj-mips-y += pflash_cfi01.o
 obj-mips-y += vmware_vga.o
 
hw/mips_r4k.c +1 -1
index da5ca31..aacb256 100644
@@ -260,7 +260,7 @@ void mips_r4k_init (ram_addr_t ram_size,
     isa_vga_init();
 
     if (nd_table[0].vlan)
-        isa_ne2000_init(0x300, i8259[9], &nd_table[0]);
+        isa_ne2000_init(0x300, 9, &nd_table[0]);
 
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
hw/ne2000-isa.c new file +64 -0
new file mode 100644
index 0000000..3120035
@@ -0,0 +1,111 @@
+/*
+ * QEMU NE2000 emulation -- isa bus windup
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "hw.h"
+#include "pc.h"
+#include "isa.h"
+#include "qdev.h"
+#include "net.h"
+#include "ne2000.h"
+
+typedef struct ISANE2000State {
+    ISADevice dev;
+    uint32_t iobase;
+    uint32_t isairq;
+    NE2000State ne2000;
+} ISANE2000State;
+
+static void isa_ne2000_cleanup(VLANClientState *vc)
+{
+    NE2000State *s = vc->opaque;
+    ISANE2000State *isa = container_of(s, ISANE2000State, ne2000);
+
+    unregister_savevm("ne2000", s);
+
+    isa_unassign_ioport(isa->iobase, 16);
+    isa_unassign_ioport(isa->iobase + 0x10, 2);
+    isa_unassign_ioport(isa->iobase + 0x1f, 1);
+
+    qemu_free(s);
+}
+
+static int isa_ne2000_initfn(ISADevice *dev)
+{
+    ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
+    NE2000State *s = &isa->ne2000;
+
+    register_ioport_write(isa->iobase, 16, 1, ne2000_ioport_write, s);
+    register_ioport_read(isa->iobase, 16, 1, ne2000_ioport_read, s);
+
+    register_ioport_write(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_write, s);
+    register_ioport_read(isa->iobase + 0x10, 1, 1, ne2000_asic_ioport_read, s);
+    register_ioport_write(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_write, s);
+    register_ioport_read(isa->iobase + 0x10, 2, 2, ne2000_asic_ioport_read, s);
+

hw/ne2000-isa.c line 74

Quoted 10 lines
hw/ne2000-isa.c new file +10 -0
+    register_ioport_write(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_write, s);
+    register_ioport_read(isa->iobase + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
+
+    isa_init_irq(dev, &s->irq, isa->isairq);
+
+    register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
+    return 0;
+}
+
+void isa_ne2000_init(int base, int irq, NICInfo *nd)

Nitpick: in qdev parlance, this function is a create_simple, not an init.

hw/ne2000-isa.c line 85

Quoted 11 lines
hw/ne2000-isa.c new file +11 -0
+{
+    ISADevice *dev;
+    NE2000State *s;
+
+    qemu_check_nic_model(nd, "ne2k_isa");
+
+    dev = isa_create("ne2k_isa");
+    qdev_prop_set_uint32(&dev->qdev, "iobase", base);
+    qdev_prop_set_uint32(&dev->qdev, "irq",    irq);
+    qdev_init(&dev->qdev);
+

Shouldn't the rest be in isa_ne2000_initfn()? Think of -device, which doesn't go through this function...

hw/ne2000-isa.c line 91

Quoted 6 lines
hw/ne2000-isa.c new file +6 -0
+    s = &DO_UPCAST(ISANE2000State, dev, dev)->ne2000;
+    memcpy(s->macaddr, nd->macaddr, 6);
+    ne2000_reset(s); /* needs macaddr */
+    s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
+                                          ne2000_can_receive, ne2000_receive,
+                                          NULL, isa_ne2000_cleanup, s);

Shouldn't this use qdev_get_vlan_client(), like the other qdevified NICs?

Quoted 68 lines
hw/ne2000-isa.c new file +20 -0
+    qemu_format_nic_info_str(s->vc, s->macaddr);
+}
+
+static ISADeviceInfo ne2000_isa_info = {
+    .qdev.name  = "ne2k_isa",
+    .qdev.size  = sizeof(ISANE2000State),
+    .init       = isa_ne2000_initfn,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
+        DEFINE_PROP_UINT32("irq",   ISANE2000State, isairq, 9),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void ne2000_isa_register_devices(void)
+{
+    isa_qdev_register(&ne2000_isa_info);
+}
+
+device_init(ne2000_isa_register_devices)
hw/ne2000.c +1 -30
index bdfc9ed..cde64be 100644
@@ -25,6 +25,7 @@
 #include "pci.h"
 #include "pc.h"
 #include "net.h"
+#include "ne2000.h"
 
 /* debug NE2000 card */
 //#define DEBUG_NE2000
@@ -116,42 +117,19 @@
 #define ENTSR_CDH 0x40	/* The collision detect "heartbeat" signal was lost. */
 #define ENTSR_OWC 0x80  /* There was an out-of-window collision. */
 
-#define NE2000_PMEM_SIZE    (32*1024)
-#define NE2000_PMEM_START   (16*1024)
-#define NE2000_PMEM_END     (NE2000_PMEM_SIZE+NE2000_PMEM_START)
-#define NE2000_MEM_SIZE     NE2000_PMEM_END
-
-typedef struct NE2000State {
-    uint8_t cmd;
-    uint32_t start;
-    uint32_t stop;
-    uint8_t boundary;
-    uint8_t tsr;
-    uint8_t tpsr;
-    uint16_t tcnt;
-    uint16_t rcnt;
-    uint32_t rsar;
-    uint8_t rsr;
-    uint8_t rxcr;
-    uint8_t isr;
-    uint8_t dcfg;
-    uint8_t imr;
-    uint8_t phys[6]; /* mac address */
-    uint8_t curpag;
-    uint8_t mult[8]; /* multicast mask array */
-    qemu_irq irq;
-    int isa_io_base;
-    VLANClientState *vc;
-    uint8_t macaddr[6];
-    uint8_t mem[NE2000_MEM_SIZE];
-} NE2000State;
-
 typedef struct PCINE2000State {
     PCIDevice dev;

hw/ne2000.c line 130

Quoted 10 lines
hw/ne2000.c +6 -1
     NE2000State ne2000;
 } PCINE2000State;
 
-static void ne2000_reset(NE2000State *s)
+typedef struct ISANE2000State {
+    ISADevice dev;
+    uint32_t iobase;
+    uint32_t isairq;
+    NE2000State ne2000;
+} ISANE2000State;

ISANE2000State doesn't belong here, and isn't used as far as I can see.

Quoted 5 lines
hw/ne2000.c +2 -0
+
+void ne2000_reset(NE2000State *s)
 {
     int i;
 

[...]

#13 lore raw

Re: [Qemu-devel] [PATCH 10/12] qdev/isa: convert ne2000

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+void isa_ne2000_init(int base, int irq, NICInfo *nd)

Nitpick: in qdev parlance, this function is a create_simple, not an init.

Long-term I want zap that anyway ...

Quoted 6 lines
Quoted 6 lines
hw/ne2000-isa.c new file +6 -0
+{
+    ISADevice *dev;
+    NE2000State *s;
+
+    qemu_check_nic_model(nd, "ne2k_isa");
+
Quoted 8 lines

hw/ne2000-isa.c line 85

Quoted 5 lines
hw/ne2000-isa.c new file +5 -0
+    dev = isa_create("ne2k_isa");
+    qdev_prop_set_uint32(&dev->qdev, "iobase", base);
+    qdev_prop_set_uint32(&dev->qdev, "irq",    irq);
+    qdev_init(&dev->qdev);
+

Shouldn't the rest be in isa_ne2000_initfn()? Think of -device, which doesn't go through this function...

It should. Need to figure a way to handle that nicely though, see below.

Right now you can't create a single nic via -device because they are not yet completely qdev-ified. ne2k_isa is no exception here ;)

Quoted 9 lines

hw/ne2000-isa.c line 91

Quoted 6 lines
hw/ne2000-isa.c new file +6 -0
+    s =&DO_UPCAST(ISANE2000State, dev, dev)->ne2000;
+    memcpy(s->macaddr, nd->macaddr, 6);
+    ne2000_reset(s); /* needs macaddr */
+    s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
+                                          ne2000_can_receive, ne2000_receive,
+                                          NULL, isa_ne2000_cleanup, s);

Shouldn't this use qdev_get_vlan_client(), like the other qdevified NICs?

Have a close look at this vlan stuff is on my todo list. Right now it is a big hack. DeviceState->nd must go away, likewise qdev_get_vlan_client() and qdev_get_macaddr(). Instead do something sane using properties.

Quoted 8 lines

hw/ne2000-isa.c line 36

Quoted 6 lines
hw/ne2000-isa.c new file +6 -0
+typedef struct ISANE2000State {
+    ISADevice dev;
+    uint32_t iobase;
+    uint32_t isairq;
+    NE2000State ne2000;
+} ISANE2000State;

ISANE2000State doesn't belong here, and isn't used as far as I can see.

Indeed.

cheers,
Gerd

#14 lore raw

PATCH 11/12 qdev/isa: finish pckbd conversion

In reply to Gerd Hoffmann

drop old init path and switch remaining users to
isa_create_simple().

---
 hw/mips_r4k.c |    4 +++-
 hw/pckbd.c    |   22 ----------------------
 hw/ppc_prep.c |    2 +-
 3 files changed, 4 insertions(+), 24 deletions(-)
hw/mips_r4k.c +3 -1
index aacb256..ae265a0 100644
@@ -241,6 +241,8 @@ void mips_r4k_init (ram_addr_t ram_size,
 
     /* The PIC is attached to the MIPS CPU INT0 pin */
     i8259 = i8259_init(env->irq[2]);
+    isa_bus_new(NULL);
+    isa_bus_irqs(i8259);
 
     rtc_state = rtc_init(0x70, i8259[8], 2000);
 
@@ -276,7 +278,7 @@ void mips_r4k_init (ram_addr_t ram_size,
                      hd[MAX_IDE_DEVS * i],
 		     hd[MAX_IDE_DEVS * i + 1]);
 
-    i8042_init(i8259[1], i8259[12], 0x60);
+    isa_create_simple("i8042");
 }
 
 static QEMUMachine mips_machine = {
hw/pckbd.c +0 -22
index 5acf4a6..3d573c2 100644
@@ -362,28 +362,6 @@ static int kbd_load(QEMUFile* f, void* opaque, int version_id)
     return 0;
 }
 
-void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base)
-{
-    KBDState *s = &kbd_state;
-
-    s->irq_kbd = kbd_irq;
-    s->irq_mouse = mouse_irq;
-
-    kbd_reset(s);
-    register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
-    register_ioport_read(io_base, 1, 1, kbd_read_data, s);
-    register_ioport_write(io_base, 1, 1, kbd_write_data, s);
-    register_ioport_read(io_base + 4, 1, 1, kbd_read_status, s);
-    register_ioport_write(io_base + 4, 1, 1, kbd_write_command, s);
-
-    s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
-    s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
-#ifdef TARGET_I386
-    vmmouse_init(s->mouse);
-#endif
-    qemu_register_reset(kbd_reset, s);
-}
-
 /* Memory mapped interface */
 static uint32_t kbd_mm_readb (void *opaque, target_phys_addr_t addr)
 {
hw/ppc_prep.c +1 -1
index 994c965..0bab6d7 100644
@@ -711,7 +711,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
                      hd[2 * i],
 		     hd[2 * i + 1]);
     }
-    i8042_init(i8259[1], i8259[12], 0x60);
+    isa_create_simple("i8042");
     DMA_init(1);
     //    SB16_init();
 
Signature · 1 line
1.6.2.5
#15 lore raw

PATCH 12/12 qdev/isa: convert real time clock

In reply to Gerd Hoffmann
---
 hw/mc146818rtc.c |   41 +++++++++++++++++++++++++++++++----------
 hw/mips_jazz.c   |    2 +-
 hw/mips_malta.c  |    2 +-
 hw/mips_r4k.c    |    2 +-
 hw/pc.c          |    2 +-
 hw/pc.h          |    3 +--
 hw/ppc_prep.c    |    2 +-
 7 files changed, 37 insertions(+), 17 deletions(-)
hw/mc146818rtc.c +32 -11
index 5c8676e..2741139 100644
@@ -63,10 +63,11 @@
 #define REG_C_AF   0x20
 
 struct RTCState {
+    ISADevice dev;
     uint8_t cmos_data[128];
     uint8_t cmos_index;
     struct tm current_tm;
-    int base_year;
+    uint32_t base_year;
     qemu_irq irq;
     qemu_irq sqw_irq;
     int it_shift;
@@ -588,20 +589,19 @@ static void rtc_reset(void *opaque)
 #endif
 }
 
-RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
+static int rtc_initfn(ISADevice *dev)
 {
-    RTCState *s;
+    RTCState *s = DO_UPCAST(RTCState, dev, dev);
+    int base = 0x70;
+    int isairq = 8;
 
-    s = qemu_mallocz(sizeof(RTCState));
+    isa_init_irq(dev, &s->irq, isairq);
 
-    s->irq = irq;
-    s->sqw_irq = sqw_irq;
     s->cmos_data[RTC_REG_A] = 0x26;
     s->cmos_data[RTC_REG_B] = 0x02;
     s->cmos_data[RTC_REG_C] = 0x00;
     s->cmos_data[RTC_REG_D] = 0x80;
 
-    s->base_year = base_year;
     rtc_set_date_from_host(s);
 
     s->periodic_timer = qemu_new_timer(vm_clock,
@@ -627,14 +627,35 @@ RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
         register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
 #endif
     qemu_register_reset(rtc_reset, s);
-
-    return s;
+    return 0;
 }
 
-RTCState *rtc_init(int base, qemu_irq irq, int base_year)
+RTCState *rtc_init(int base_year)
+{
+    ISADevice *dev;
+
+    dev = isa_create("mc146818rtc");
+    qdev_prop_set_uint32(&dev->qdev, "base_year", base_year);
+    qdev_init(&dev->qdev);
+    return DO_UPCAST(RTCState, dev, dev);
+}
+
+static ISADeviceInfo mc146818rtc_info = {
+    .qdev.name     = "mc146818rtc",
+    .qdev.size     = sizeof(RTCState),
+    .qdev.no_user  = 1,
+    .init          = rtc_initfn,
+    .qdev.props    = (Property[]) {
+        DEFINE_PROP_UINT32("base_year", RTCState, base_year, 1980),
+        DEFINE_PROP_END_OF_LIST(),
+    }
+};
+
+static void mc146818rtc_register(void)
 {
-    return rtc_init_sqw(base, irq, NULL, base_year);
+    isa_qdev_register(&mc146818rtc_info);
 }
+device_init(mc146818rtc_register)
 
 /* Memory mapped interface */
 static uint32_t cmos_mm_readb (void *opaque, target_phys_addr_t addr)
hw/mips_jazz.c +1 -1
index 1cbd947..d62a584 100644
@@ -241,7 +241,7 @@ void mips_jazz_init (ram_addr_t ram_size,
     fdctrl_init_sysbus(rc4030[1], 0, 0x80003000, fds);
 
     /* Real time clock */
-    rtc_init(0x70, i8259[8], 1980);
+    rtc_init(1980);
     s_rtc = cpu_register_io_memory(rtc_read, rtc_write, env);
     cpu_register_physical_memory(0x80004000, 0x00001000, s_rtc);
 
hw/mips_malta.c +1 -1
index 32c7102..25e32bf 100644
@@ -923,7 +923,7 @@ void mips_malta_init (ram_addr_t ram_size,
     /* Super I/O */
     isa_dev = isa_create_simple("i8042");
  
-    rtc_state = rtc_init(0x70, isa_reserve_irq(8), 2000);
+    rtc_state = rtc_init(2000);
     serial_init(0x3f8, isa_reserve_irq(4), 115200, serial_hds[0]);
     serial_init(0x2f8, isa_reserve_irq(3), 115200, serial_hds[1]);
     if (parallel_hds[0])
hw/mips_r4k.c +1 -1
index ae265a0..d801417 100644
@@ -244,7 +244,7 @@ void mips_r4k_init (ram_addr_t ram_size,
     isa_bus_new(NULL);
     isa_bus_irqs(i8259);
 
-    rtc_state = rtc_init(0x70, i8259[8], 2000);
+    rtc_state = rtc_init(2000);
 
     /* Register 64 KB of ISA IO space at 0x14000000 */
     isa_mmio_init(0x14000000, 0x00010000);
hw/pc.c +1 -1
index 9497f71..d96d756 100644
@@ -1313,7 +1313,7 @@ static void pc_init1(ram_addr_t ram_size,
         }
     }
 
-    rtc_state = rtc_init(0x70, isa_reserve_irq(8), 2000);
+    rtc_state = rtc_init(2000);
 
     qemu_register_boot_set(pc_boot_set, rtc_state);
 
hw/pc.h +1 -2
index d80d3a5..c9cdd4a 100644
@@ -81,8 +81,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
 
 typedef struct RTCState RTCState;
 
-RTCState *rtc_init(int base, qemu_irq irq, int base_year);
-RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year);
+RTCState *rtc_init(int base_year);
 RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
                       int base_year);
 void rtc_set_memory(RTCState *s, int addr, int val);
hw/ppc_prep.c +1 -1
index 0bab6d7..2b39f4d 100644
@@ -680,7 +680,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
     pci_vga_init(pci_bus, 0, 0);
     //    openpic = openpic_init(0x00000000, 0xF0000000, 1);
     //    pit = pit_init(0x40, i8259[0]);
-    rtc_init(0x70, i8259[8], 2000);
+    rtc_init(2000);
 
     serial_init(0x3f8, i8259[4], 115200, serial_hds[0]);
     nb_nics1 = nb_nics;
Signature · 1 line
1.6.2.5
#16 lore raw

[Qemu-devel] Re: [PATCH 12/12] qdev/isa: convert real time clock

hw/mc146818rtc.c line 70

Quoted 12 lines
hw/mc146818rtc.c +2 -1
@@ -63,10 +63,11 @@
  #define REG_C_AF   0x20
 
  struct RTCState {
+    ISADevice dev;
      uint8_t cmos_data[128];
      uint8_t cmos_index;
      struct tm current_tm;
-    int base_year;
+    uint32_t base_year;

Self-NACK. This sign change breaks some math and makes my VMs time-travel to 2005 ...

cheers,
Gerd

#17 lore raw

[Qemu-devel] Re: [PATCH 12/12] qdev/isa: convert real time clock

Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
hw/mc146818rtc.c +0 -0
@@ -63,10 +63,11 @@
  #define REG_C_AF   0x20
 
Quoted 11 lines

hw/mc146818rtc.c line 70

Quoted 7 lines
hw/mc146818rtc.c +2 -1
  struct RTCState {
+    ISADevice dev;
      uint8_t cmos_data[128];
      uint8_t cmos_index;
      struct tm current_tm;
-    int base_year;
+    uint32_t base_year;

Self-NACK. This sign change breaks some math and makes my VMs time-travel to 2005 ...

I thought you retracted this patch, but now I find it in master. Is there fix in the queue?

To err is human, and the more patches are committed, the more errors can happen. Still, my impression is that the current rate could be lower. Gerd, maybe you should have CC'ed Anthony for the NACK.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#18 lore raw

[Qemu-devel] Re: [PATCH 12/12] qdev/isa: convert real time clock

Quoted 17 lines · Jan Kiszka
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
hw/mc146818rtc.c +0 -0
@@ -63,10 +63,11 @@
  #define REG_C_AF   0x20
 
Quoted 10 lines

hw/mc146818rtc.c line 70

Quoted 7 lines
hw/mc146818rtc.c +2 -1
  struct RTCState {
+    ISADevice dev;
      uint8_t cmos_data[128];
      uint8_t cmos_index;
      struct tm current_tm;
-    int base_year;
+    uint32_t base_year;

Self-NACK. This sign change breaks some math and makes my VMs time-travel to 2005 ...

Quoted 7 lines

I thought you retracted this patch, but now I find it in master. Is there fix in the queue?

To err is human, and the more patches are committed, the more errors can happen. Still, my impression is that the current rate could be lower. Gerd, maybe you should have CC'ed Anthony for the NACK.

Err, sorry, wrong alarm, v2 got merged.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#19 lore raw
In reply to Gerd Hoffmann
Quoted 11 lines · Gerd Hoffmann

Hi,

Here is a batch of patches for the isa bus and isa bus devices. qdev support for the isa bus is reworked a bit, following up the default value discussion with Markus. A few devices are converted to qdev. Some bugs (like -M isapc segfaulting) are fixed along the way.

As usual the individual patches have more verbose descriptions.

cheers,
Gerd

The whole series looks good to me, except for "[PATCH 10/12] qdev/isa:
convert ne2000"; see my comments there.

After "[PATCH 03/12] qdev: drop iobase properties from isa bus", ISA I/O bases are no longer visible in info qdev. I think that's okay.