Skip to contentSkip to conversation

ide: convert to qdev.

PATCH In review Gerd Hoffmann 3 participants 19 messages Sep 14, 2009 – Sep 23, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

cover ide: convert to qdev.

Hi,

Here is a patch series which starts the conversion of ide to qdev. It brings the core infrastructure and converts pci+isa ide adapters to qdev. Also some minor preparatory patches and bugfixes.

v2 changes:
* check qdev_init for failure.
* move whitespace changes to separate patch.
* drop some needless code reorderings.

cheers,
Gerd

#1 lore raw

PATCH 1/9 qdev/pci: add pci_create_noinit()

Like pci_create_simple() but doesn't call qdev_init(), so one can set properties before initializing the device.

---
 hw/pci.c |   11 ++++++++---
 hw/pci.h |    1 +
 2 files changed, 9 insertions(+), 3 deletions(-)
hw/pci.c +8 -3
index c12b0be..64d70ed 100644
@@ -923,15 +923,20 @@ void pci_qdev_register_many(PCIDeviceInfo *info)
     }
 }
 
-PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name)
 {
     DeviceState *dev;
 
     dev = qdev_create(&bus->qbus, name);
     qdev_prop_set_uint32(dev, "addr", devfn);
-    qdev_init(dev);
+    return DO_UPCAST(PCIDevice, qdev, dev);
+}
 
-    return (PCIDevice *)dev;
+PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+{
+    PCIDevice *dev = pci_create_noinit(bus, devfn, name);
+    qdev_init(&dev->qdev);
+    return dev;
 }
 
 static int pci_find_space(PCIDevice *pdev, uint8_t size)
hw/pci.h +1 -0
index 6196b6a..e7bf33a 100644
@@ -328,6 +328,7 @@ void pci_qdev_register(PCIDeviceInfo *info);
 void pci_qdev_register_many(PCIDeviceInfo *info);
 
 PCIDevice *pci_create(const char *name, const char *devaddr);
+PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name);
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
 
 /* lsi53c895a.c */
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/9 support media=cdrom for if=none

In reply to Gerd Hoffmann
---
 vl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
vl.c +1 -1
index 0e61333..eb01da7 100644
@@ -2176,6 +2176,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
     case IF_IDE:
     case IF_SCSI:
     case IF_XEN:
+    case IF_NONE:
         switch(media) {
 	case MEDIA_DISK:
             if (cyls != 0) {
@@ -2196,7 +2197,6 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
         break;
     case IF_PFLASH:
     case IF_MTD:
-    case IF_NONE:
         break;
     case IF_VIRTIO:
         /* add virtio block device */
Signature · 1 line
1.6.2.5
#3 lore raw

PATCH 3/9 split away drive init from ide_init2()

In reply to Gerd Hoffmann

This allows the ide bus being initialized without drives attached and the drives being attached and initialization later on as separate step.

---
 hw/ide/core.c     |   71 +++++++++++++++++++++++++++++------------------------
 hw/ide/internal.h |    1 +
 2 files changed, 40 insertions(+), 32 deletions(-)
hw/ide/core.c +39 -32
index 5f6e2cb..0b6de6c 100644
@@ -2518,51 +2518,58 @@ void ide_reset(IDEState *s)
     s->media_changed = 0;
 }
 
+void ide_init_drive(IDEState *s, DriveInfo *dinfo)
+{
+    int cylinders, heads, secs;
+    uint64_t nb_sectors;
+
+    if (dinfo && dinfo->bdrv) {
+        s->bs = dinfo->bdrv;
+        bdrv_get_geometry(s->bs, &nb_sectors);
+        bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
+        s->cylinders = cylinders;
+        s->heads = heads;
+        s->sectors = secs;
+        s->nb_sectors = nb_sectors;
+        /* The SMART values should be preserved across power cycles
+           but they aren't.  */
+        s->smart_enabled = 1;
+        s->smart_autosave = 1;
+        s->smart_errors = 0;
+        s->smart_selftest_count = 0;
+        if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
+            s->is_cdrom = 1;
+            bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
+        }
+        strncpy(s->drive_serial_str, drive_get_serial(s->bs),
+                sizeof(s->drive_serial_str));
+    }
+    if (strlen(s->drive_serial_str) == 0)
+        snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
+                 "QM%05d", s->drive_serial);
+    ide_reset(s);
+}
+
 void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
                qemu_irq irq)
 {
     IDEState *s;
     static int drive_serial = 1;
-    int i, cylinders, heads, secs;
-    uint64_t nb_sectors;
+    int i;
 
     for(i = 0; i < 2; i++) {
         s = bus->ifs + i;
         s->bus = bus;
         s->unit = i;
-        if (i == 0 && hd0)
-            s->bs = hd0->bdrv;
-        if (i == 1 && hd1)
-            s->bs = hd1->bdrv;
-        s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4);
-        if (s->bs) {
-            bdrv_get_geometry(s->bs, &nb_sectors);
-            bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
-            s->cylinders = cylinders;
-            s->heads = heads;
-            s->sectors = secs;
-            s->nb_sectors = nb_sectors;
-	    /* The SMART values should be preserved across power cycles
-	       but they aren't.  */
-	    s->smart_enabled = 1;
-	    s->smart_autosave = 1;
-	    s->smart_errors = 0;
-	    s->smart_selftest_count = 0;
-	    s->smart_selftest_data = qemu_blockalign(s->bs, 512);
-            if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
-                s->is_cdrom = 1;
-		bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
-            }
-        }
         s->drive_serial = drive_serial++;
-        strncpy(s->drive_serial_str, drive_get_serial(s->bs),
-                sizeof(s->drive_serial_str));
-        if (strlen(s->drive_serial_str) == 0)
-            snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
-                    "QM%05d", s->drive_serial);
+        s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4);
+        s->smart_selftest_data = qemu_blockalign(s->bs, 512);
         s->sector_write_timer = qemu_new_timer(vm_clock,
                                                ide_sector_write_timer_cb, s);
-        ide_reset(s);
+        if (i == 0)
+            ide_init_drive(s, hd0);
+        if (i == 1)
+            ide_init_drive(s, hd1);
     }
     bus->irq = irq;
 }
hw/ide/internal.h +1 -0
index b9a7c72..62aef1c 100644
@@ -527,6 +527,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
+void ide_init_drive(IDEState *s, DriveInfo *dinfo);
 void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
                qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
Signature · 1 line
1.6.2.5
#4 lore raw

PATCH 4/9 ide/qdev: add ide bus.

In reply to Gerd Hoffmann
---
 hw/ide/internal.h |   24 ++++++++++-
 hw/ide/qdev.c     |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+), 1 deletions(-)
 create mode 100644 hw/ide/qdev.c
hw/ide/internal.h +23 -1
index 62aef1c..9df759d 100644
@@ -15,6 +15,8 @@
 #define USE_DMA_CDROM
 
 typedef struct IDEBus IDEBus;
+typedef struct IDEDevice IDEDevice;
+typedef struct IDEDeviceInfo IDEDeviceInfo;
 typedef struct IDEState IDEState;
 typedef struct BMDMAState BMDMAState;
 
@@ -440,6 +442,8 @@ struct IDEState {
 
 struct IDEBus {
     BusState qbus;
+    IDEDevice *master;
+    IDEDevice *slave;
     BMDMAState *bmdma;
     IDEState ifs[2];
     uint8_t unit;
@@ -447,6 +451,20 @@ struct IDEBus {
     qemu_irq irq;
 };
 
+struct IDEDevice {
+    DeviceState qdev;
+    uint32_t unit;
+    DriveInfo *dinfo;
+};
+
+typedef int (*ide_qdev_initfn)(IDEDevice *dev);
+struct IDEDeviceInfo {
+    DeviceInfo qdev;
+    ide_qdev_initfn init;
+    uint32_t unit;
+    DriveInfo *drive;
+};
+
 #define BM_STATUS_DMAING 0x01
 #define BM_STATUS_ERROR  0x02
 #define BM_STATUS_INT    0x04
@@ -500,7 +518,7 @@ static inline void ide_set_irq(IDEBus *bus)
     }
 }
 
-/* ide.c */
+/* hw/ide/core.c */
 void ide_save(QEMUFile* f, IDEState *s);
 void ide_load(QEMUFile* f, IDEState *s, int version_id);
 void idebus_save(QEMUFile* f, IDEBus *bus);
@@ -532,4 +550,8 @@ void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
                qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
 
+/* hw/ide/qdev.c */
+IDEBus *ide_bus_new(DeviceState *dev);
+IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
+
 #endif /* HW_IDE_INTERNAL_H */
hw/ide/qdev.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#5 lore raw

PATCH 5/9 ide/pci: fix indention

In reply to Gerd Hoffmann
---
 hw/ide/pci.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/ide/pci.c +6 -6
index 607472b..e3b43a0 100644
@@ -404,15 +404,15 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
     }
 
     pci_register_bar((PCIDevice *)d, 0, 0x8,
-                           PCI_ADDRESS_SPACE_IO, ide_map);
+                     PCI_ADDRESS_SPACE_IO, ide_map);
     pci_register_bar((PCIDevice *)d, 1, 0x4,
-                           PCI_ADDRESS_SPACE_IO, ide_map);
+                     PCI_ADDRESS_SPACE_IO, ide_map);
     pci_register_bar((PCIDevice *)d, 2, 0x8,
-                           PCI_ADDRESS_SPACE_IO, ide_map);
+                     PCI_ADDRESS_SPACE_IO, ide_map);
     pci_register_bar((PCIDevice *)d, 3, 0x4,
-                           PCI_ADDRESS_SPACE_IO, ide_map);
+                     PCI_ADDRESS_SPACE_IO, ide_map);
     pci_register_bar((PCIDevice *)d, 4, 0x10,
-                           PCI_ADDRESS_SPACE_IO, bmdma_map);
+                     PCI_ADDRESS_SPACE_IO, bmdma_map);
 
     pci_conf[0x3d] = 0x01; // interrupt on pin 1
 
@@ -466,7 +466,7 @@ void pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
     piix3_reset(d);
 
     pci_register_bar((PCIDevice *)d, 4, 0x10,
-                           PCI_ADDRESS_SPACE_IO, bmdma_map);
+                     PCI_ADDRESS_SPACE_IO, bmdma_map);
 
     ide_init2(&d->bus[0], hd_table[0], hd_table[1], isa_reserve_irq(14));
     ide_init2(&d->bus[1], hd_table[2], hd_table[3], isa_reserve_irq(15));
Signature · 1 line
1.6.2.5
#6 lore raw

PATCH 6/9 ide/pci: convert to qdev.

In reply to Gerd Hoffmann

With this patch applied ide drives (when attached to a pci adapter) can be created via -device, like this:

-drive if=none,id=mydisk,file=/path/to/disk.img
-device ide-drive,drive=mydisk,bus=ide.0,unit=0

Note that creating a master on ide1 doesn't work that way. That is a side effect of qemu creating a cdrom automagically even if you don't ask for it.

---
 Makefile.target |   10 ++-
 hw/ide/pci.c    |  186 ++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 123 insertions(+), 73 deletions(-)
Makefile.target +6 -4
index 6314e0e..7e841c1 100644
@@ -194,7 +194,8 @@ obj-y += e1000.o
 obj-y += wdt_i6300esb.o
 
 # Hardware support
-obj-i386-y = ide/core.o ide/isa.o ide/pci.o pckbd.o $(sound-obj-y) dma.o isa-bus.o
+obj-i386-y = ide/core.o ide/qdev.o ide/isa.o ide/pci.o
+obj-i386-y += pckbd.o $(sound-obj-y) dma.o isa-bus.o
 obj-i386-y += vga.o vga-pci.o vga-isa.o
 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
@@ -203,7 +204,7 @@ 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 = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
 obj-ppc-y += vga.o vga-pci.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
@@ -226,7 +227,7 @@ obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
 obj-mips-y += mips_timer.o mips_int.o dma.o vga.o serial.o i8254.o i8259.o rc4030.o
 obj-mips-y += vga-pci.o vga-isa.o vga-isa-mm.o
 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 += ide/core.o ide/qdev.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 ne2000-isa.o
@@ -258,7 +259,8 @@ obj-cris-y += etraxfs_ser.o
 obj-cris-y += pflash_cfi02.o
 
 ifeq ($(TARGET_ARCH), sparc64)
-obj-sparc-y = sun4u.o ide/core.o ide/pci.o isa-bus.o pckbd.o apb_pci.o
+obj-sparc-y = sun4u.o isa-bus.o pckbd.o apb_pci.o
+obj-sparc-y += ide/core.o ide/qdev.o ide/pci.o
 obj-sparc-y += vga.o vga-pci.o
 obj-sparc-y += fdc.o mc146818rtc.o serial.o
 obj-sparc-y += cirrus_vga.o parallel.o
hw/ide/pci.c +117 -69

285 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#7 lore raw

PATCH 7/9 ide/isa: convert to qdev.

In reply to Gerd Hoffmann
---
 hw/ide.h      |    4 +-
 hw/ide/isa.c  |   61 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 hw/mips_r4k.c |    2 +-
 hw/pc.c       |    3 +-
 hw/ppc_prep.c |    2 +-
 5 files changed, 58 insertions(+), 14 deletions(-)
hw/ide.h +2 -2
index e0a508b..0e7d540 100644
@@ -4,8 +4,8 @@
 #include "qdev.h"
 
 /* ide-isa.c */
-void isa_ide_init(int iobase, int iobase2, qemu_irq irq,
-                  DriveInfo *hd0, DriveInfo *hd1);
+int isa_ide_init(int iobase, int iobase2, int isairq,
+                 DriveInfo *hd0, DriveInfo *hd1);
 
 /* ide-pci.c */
 void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
hw/ide/isa.c +53 -8

81 lines not on this page · raw message

hw/mips_r4k.c +1 -1
index d801417..fcc7fed 100644
@@ -274,7 +274,7 @@ void mips_r4k_init (ram_addr_t ram_size,
     }
 
     for(i = 0; i < MAX_IDE_BUS; i++)
-        isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
+        isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
                      hd[MAX_IDE_DEVS * i],
 		     hd[MAX_IDE_DEVS * i + 1]);
 
hw/pc.c +1 -2
index bb78f0b..58de372 100644
@@ -1366,8 +1366,7 @@ static void pc_init1(ram_addr_t ram_size,
         pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
     } else {
         for(i = 0; i < MAX_IDE_BUS; i++) {
-            isa_ide_init(ide_iobase[i], ide_iobase2[i],
-                         isa_reserve_irq(ide_irq[i]),
+            isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
 	                 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
         }
     }
hw/ppc_prep.c +1 -1
index 1930146..6001c86 100644
@@ -707,7 +707,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
     }
 
     for(i = 0; i < MAX_IDE_BUS; i++) {
-        isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
+        isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
                      hd[2 * i],
 		     hd[2 * i + 1]);
     }
Signature · 1 line
1.6.2.5
#8 lore raw

Re: [Qemu-devel] [PATCH 7/9] ide/isa: convert to qdev.

Quoted 1 line · Gerd Hoffmann

Breaks PPC:
gdb ./qemu-system-ppc
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
(gdb) r
[Thread debugging using libthread_db enabled]
[New Thread 0x7f63eee2e700 (LWP 8998)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f63eee2e700 (LWP 8998)] 0x000000000042cdc3 in ide_reset (s=0xec2048) at /src/qemu/hw/ide/core.c:2510
2510 bus->unit = s->unit;
(gdb) bt
#0 0x000000000042cdc3 in ide_reset (s=0xec2048)

    at /src/qemu/hw/ide/core.c:2510
#1  0x00000000004327d4 in pmac_ide_reset (opaque=<value optimized out>)
    at /src/qemu/hw/ide/macio.c:330
#2  0x0000000000432899 in pmac_ide_init (hd_table=<value optimized out>,
    irq=0xf5b268, dbdma=0xf597e0, channel=0x16, dma_irq=0xf5b160)
    at /src/qemu/hw/ide/macio.c:353
#3  0x000000000044ab09 in ppc_heathrow_init (ram_size=0x8000000,
    boot_device=<value optimized out>, kernel_filename=0x0,
    kernel_cmdline=0x5e9d0b "", initrd_filename=0x0,
    cpu_model=<value optimized out>) at /src/qemu/hw/ppc_oldworld.c:337
#4  0x000000000040ca15 in main (argc=0x1, argv=0x7ffff6f5b1f8,
    envp=<value optimized out>) at /src/qemu/vl.c:5742
#9 lore raw

Re: [Qemu-devel] [PATCH 7/9] ide/isa: convert to qdev.

Quoted 2 lines · Blue Swirl
Quoted 1 line · Gerd Hoffmann

Stupid me, it was 4/8 which broke it! Sorry.

#10 lore raw

Re: [Qemu-devel] [PATCH 7/9] ide/isa: convert to qdev.

Quoted 5 lines · Blue Swirl
Quoted 2 lines · Blue Swirl
Quoted 1 line · Gerd Hoffmann

Stupid me, it was 4/8 which broke it! Sorry.

Not reproducable. Can you double-check?

thanks,
Gerd

#11 lore raw

Re: [Qemu-devel] [PATCH 7/9] ide/isa: convert to qdev.

Quoted 10 lines · Gerd Hoffmann
Quoted 7 lines · Blue Swirl
Quoted 3 lines · Blue Swirl
Quoted 1 line · Gerd Hoffmann

Stupid me, it was 4/8 which broke it! Sorry.

Not reproducable.  Can you double-check?

Strange, I can't reproduce it anymore.

#12 lore raw

PATCH 8/9 isa: refine irq reservations

In reply to Gerd Hoffmann

There are a few cases where IRQ sharing on the ISA bus is used and possible. In general only devices of the same kind can do that. A few use cases:

* serial lines 1+3 share irq 4
* serial lines 2+4 share irq 3
* parallel ports share irq 7
* ppc/prep: ide ports share irq 13

This patch refines the irq reservation mechanism for the isa bus to handle those cases. It keeps track of the driver which owns the IRQ in question and allows irq sharing for devices handled by the same driver.

---
 hw/isa-bus.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
hw/isa-bus.c +13 -3
index 4ecc0f8..1d2ca90 100644
@@ -26,6 +26,7 @@ struct ISABus {
     BusState qbus;
     qemu_irq *irqs;
     uint32_t assigned;
+    DeviceInfo *irq_owner[16];
 };
 static ISABus *isabus;
 
@@ -71,7 +72,9 @@ qemu_irq isa_reserve_irq(int isairq)
         exit(1);
     }
     if (isabus->assigned & (1 << isairq)) {
-        fprintf(stderr, "isa irq %d already assigned\n", isairq);
+        DeviceInfo *owner = isabus->irq_owner[isairq];
+        fprintf(stderr, "isa irq %d already assigned (%s)\n",
+                isairq, owner ? owner->name : "unknown");
         exit(1);
     }
     isabus->assigned |= (1 << isairq);
@@ -82,10 +85,17 @@ void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
 {
     assert(dev->nirqs < ARRAY_SIZE(dev->isairq));
     if (isabus->assigned & (1 << isairq)) {
-        fprintf(stderr, "isa irq %d already assigned\n", isairq);
-        exit(1);
+        DeviceInfo *owner = isabus->irq_owner[isairq];
+        if (owner == dev->qdev.info) {
+            /* irq sharing is ok in case the same driver handles both */;
+        } else {
+            fprintf(stderr, "isa irq %d already assigned (%s)\n",
+                    isairq, owner ? owner->name : "unknown");
+            exit(1);
+        }
     }
     isabus->assigned |= (1 << isairq);
+    isabus->irq_owner[isairq] = dev->qdev.info;
     dev->isairq[dev->nirqs] = isairq;
     *p = isabus->irqs[isairq];
     dev->nirqs++;
Signature · 1 line
1.6.2.5
#13 lore raw

Re: [Qemu-devel] [PATCH 8/9] isa: refine irq reservations

Quoted 8 lines · Gerd Hoffmann

There are a few cases where IRQ sharing on the ISA bus is used and possible.  In general only devices of the same kind can do that. A few use cases:

 * serial lines 1+3 share irq 4
 * serial lines 2+4 share irq 3
 * parallel ports share irq 7
 * ppc/prep: ide ports share irq 13

There is another ppc/prep case where RTC and m48t59 share irq 8. The attached patch converts m48t59 to ISA and makes this more visible.

Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge triggered and so IRQ sharing was a bit unreliable (but not completely broken) also on real HW?

From e575502cf20d735618a96346e6d9854edaf92fa8 Mon Sep 17 00:00:00 2001
From: Blue Swirl <[email protected]>
Date: Mon, 14 Sep 2009 16:51:17 +0000
Subject: [PATCH] PPC: use ISA version of m48t59 for PREP machine

---
 hw/ppc_prep.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/ppc_prep.c +1 -1
index 743dad2..0ed07ce 100644
@@ -751,7 +751,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
         usb_ohci_init_pci(pci_bus, -1);
     }
 
-    m48t59 = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
+    m48t59 = m48t59_init_isa(0x0074, NVRAM_SIZE, 59);
     if (m48t59 == NULL)
         return;
     sysctrl->nvram = m48t59;
Signature · 1 line
1.5.6.5
#14 lore raw

Re: [Qemu-devel] [PATCH 8/9] isa: refine irq reservations

Quoted 10 lines · Blue Swirl
Quoted 8 lines · Gerd Hoffmann

There are a few cases where IRQ sharing on the ISA bus is used and possible.  In general only devices of the same kind can do that. A few use cases:

 * serial lines 1+3 share irq 4
 * serial lines 2+4 share irq 3
 * parallel ports share irq 7
 * ppc/prep: ide ports share irq 13

Quoted 6 lines

There is another ppc/prep case where RTC and m48t59 share irq 8. The attached patch converts m48t59 to ISA and makes this more visible.

Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge triggered and so IRQ sharing was a bit unreliable (but not completely broken) also on real HW?

If I remember correctly (and that's a considerable if), sufficiently well-behaved hardware with sufficiently smart drivers could share IRQs.

#15 lore raw

Re: [Qemu-devel] [PATCH 8/9] isa: refine irq reservations

In reply to Blue Swirl
Quoted 5 lines · Blue Swirl
Quoted 4 lines · Gerd Hoffmann

There are a few cases where IRQ sharing on the ISA bus is used and possible. In general only devices of the same kind can do that. A few use cases:

Quoted 7 lines
Quoted 4 lines

* serial lines 1+3 share irq 4
* serial lines 2+4 share irq 3
* parallel ports share irq 7
* ppc/prep: ide ports share irq 13

There is another ppc/prep case where RTC and m48t59 share irq 8. The attached patch converts m48t59 to ISA and makes this more visible.

Hmm, ok. So scratch this and maybe use a 'sharing the irq is is fine with me' flag instead?

Quoted 3 lines

Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge triggered and so IRQ sharing was a bit unreliable (but not completely broken) also on real HW?

Well, the fundamental problem is that (1) the drivers must be prepared to handle that and (b) the hardware must be designed sanely. There are cases where it works fine (see the list above). It isn't true in general though. You can't configure two random devices (say sb16 + ne2k) to share the same irq and expect everything to work fine.

cheers,
Gerd

#16 lore raw

Re: [Qemu-devel] [PATCH 8/9] isa: refine irq reservations

Quoted 23 lines · Gerd Hoffmann
Quoted 7 lines · Blue Swirl
Quoted 5 lines · Gerd Hoffmann

There are a few cases where IRQ sharing on the ISA bus is used and possible.  In general only devices of the same kind can do that. A few use cases:

Quoted 7 lines
Quoted 4 lines

 * serial lines 1+3 share irq 4
 * serial lines 2+4 share irq 3
 * parallel ports share irq 7
 * ppc/prep: ide ports share irq 13

There is another ppc/prep case where RTC and m48t59 share irq 8. The attached patch converts m48t59 to ISA and makes this more visible.

Hmm, ok.  So scratch this and maybe use a 'sharing the irq is is fine with me' flag instead?

Quoted 3 lines

Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge triggered and so IRQ sharing was a bit unreliable (but not completely broken) also on real HW?

Quoted 5 lines

Well, the fundamental problem is that (1) the drivers must be prepared to handle that and (b) the hardware must be designed sanely.  There are cases where it works fine (see the list above).  It isn't true in general though. You can't configure two random devices (say sb16 + ne2k) to share the same irq and expect everything to work fine.

I wonder if the PREP machine is emulated correctly. I couldn't find docs about PREP NVRAM or RTC.

#17 lore raw

PATCH 9/9 unbreak ppc/prep

In reply to Gerd Hoffmann

Changes:
* added isa bus, hooked up to the system bus. Not sure this is correct, but 'info pci' lists lists no pci-isa bridge in the machine ...).
* switches the default cpu to one which actually works.

---
 hw/ppc_prep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
hw/ppc_prep.c +4 -1
index 6001c86..5392072 100644
@@ -572,7 +572,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
 
     /* init CPUs */
     if (cpu_model == NULL)
-        cpu_model = "default";
+        cpu_model = "602";
     for (i = 0; i < smp_cpus; i++) {
         env = cpu_init(cpu_model);
         if (!env) {
@@ -670,6 +670,9 @@ static void ppc_prep_init (ram_addr_t ram_size,
     }
     i8259 = i8259_init(first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
     pci_bus = pci_prep_init(i8259);
+    /* Hmm, prep has no pci-isa bridge ??? */
+    isa_bus_new(NULL);
+    isa_bus_irqs(i8259);
     //    pci_bus = i440fx_init();
     /* Register 8 MB of ISA IO space (needed for non-contiguous map) */
     PPC_io_memory = cpu_register_io_memory(PPC_prep_io_read,
Signature · 1 line
1.6.2.5
#18 lore raw
In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann

Hi,

Here is a patch series which starts the conversion of ide to qdev. It brings the core infrastructure and converts pci+isa ide adapters to qdev. Also some minor preparatory patches and bugfixes.

Quoted 7 lines

v2 changes:
* check qdev_init for failure.
* move whitespace changes to separate patch.
* drop some needless code reorderings.

cheers,
Gerd

Looks good to me. I'd still like to see the relationship between struct IDEBus members master, slave and ifs[] documented, but that's detail. ISA interrupt sharing may need further refinement later on.