Patchwork [7/9] ide/isa: convert to qdev.

login
register
mail settings
Submitter Gerd Hoffmann
Date Sept. 14, 2009, 3:49 p.m.
Message ID <1252943364-32705-8-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/33591/
State Superseded
Headers show

Comments

Gerd Hoffmann - Sept. 14, 2009, 3:49 p.m.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 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(-)
Blue Swirl - Sept. 14, 2009, 5:23 p.m.
On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
>

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
Blue Swirl - Sept. 14, 2009, 5:46 p.m.
On Mon, Sep 14, 2009 at 8:23 PM, Blue Swirl <blauwirbel@gmail.com> wrote:
> On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
>>

Stupid me, it was 4/8 which broke it! Sorry.
Gerd Hoffmann - Sept. 15, 2009, 9:33 a.m.
On 09/14/09 19:46, Blue Swirl wrote:
> On Mon, Sep 14, 2009 at 8:23 PM, Blue Swirl<blauwirbel@gmail.com>  wrote:
>> On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>>>
>
> Stupid me, it was 4/8 which broke it! Sorry.

Not reproducable.  Can you double-check?

thanks,
   Gerd
Blue Swirl - Sept. 15, 2009, 8:10 p.m.
On Tue, Sep 15, 2009 at 12:33 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> On 09/14/09 19:46, Blue Swirl wrote:
>>
>> On Mon, Sep 14, 2009 at 8:23 PM, Blue Swirl<blauwirbel@gmail.com>  wrote:
>>>
>>> On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>>>>
>>
>> Stupid me, it was 4/8 which broke it! Sorry.
>
> Not reproducable.  Can you double-check?

Strange, I can't reproduce it anymore.

Patch

diff --git a/hw/ide.h b/hw/ide.h
index e0a508b..0e7d540 100644
--- a/hw/ide.h
+++ b/hw/ide.h
@@ -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,
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index ec2d6fb..d2fe0c0 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -24,6 +24,7 @@ 
  */
 #include <hw/hw.h>
 #include <hw/pc.h>
+#include <hw/isa.h>
 #include "block.h"
 #include "block_int.h"
 #include "sysemu.h"
@@ -35,7 +36,12 @@ 
 /* ISA IDE definitions */
 
 typedef struct ISAIDEState {
-    IDEBus *bus;
+    ISADevice dev;
+    IDEBus    *bus;
+    uint32_t  iobase;
+    uint32_t  iobase2;
+    uint32_t  isairq;
+    qemu_irq  irq;
 } ISAIDEState;
 
 static void isa_ide_save(QEMUFile* f, void *opaque)
@@ -57,15 +63,54 @@  static int isa_ide_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
-void isa_ide_init(int iobase, int iobase2, qemu_irq irq,
-                  DriveInfo *hd0, DriveInfo *hd1)
+static int isa_ide_initfn(ISADevice *dev)
 {
+    ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
+
+    s->bus = ide_bus_new(&s->dev.qdev);
+    ide_init_ioport(s->bus, s->iobase, s->iobase2);
+    isa_init_irq(dev, &s->irq, s->isairq);
+    ide_init2(s->bus, NULL, NULL, s->irq);
+    register_savevm("isa-ide", 0, 3, isa_ide_save, isa_ide_load, s);
+    return 0;
+};
+
+int isa_ide_init(int iobase, int iobase2, int isairq,
+                 DriveInfo *hd0, DriveInfo *hd1)
+{
+    ISADevice *dev;
     ISAIDEState *s;
 
-    s = qemu_mallocz(sizeof(*s));
-    s->bus = qemu_mallocz(sizeof(IDEBus));
+    dev = isa_create("isa-ide");
+    qdev_prop_set_uint32(&dev->qdev, "iobase",  iobase);
+    qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2);
+    qdev_prop_set_uint32(&dev->qdev, "irq",     isairq);
+    if (qdev_init(&dev->qdev) != 0)
+        return -1;
 
-    ide_init2(s->bus, hd0, hd1, irq);
-    ide_init_ioport(s->bus, iobase, iobase2);
-    register_savevm("isa-ide", 0, 3, isa_ide_save, isa_ide_load, s);
+    s = DO_UPCAST(ISAIDEState, dev, dev);
+    if (hd0)
+        ide_create_drive(s->bus, 0, hd0);
+    if (hd1)
+        ide_create_drive(s->bus, 1, hd1);
+    return 0;
+}
+
+static ISADeviceInfo isa_ide_info = {
+    .qdev.name  = "isa-ide",
+    .qdev.size  = sizeof(ISAIDEState),
+    .init       = isa_ide_initfn,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_HEX32("iobase",  ISAIDEState, iobase,  0x1f0),
+        DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6),
+        DEFINE_PROP_UINT32("irq",    ISAIDEState, isairq,  14),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void isa_ide_register_devices(void)
+{
+    isa_qdev_register(&isa_ide_info);
 }
+
+device_init(isa_ide_register_devices)
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index d801417..fcc7fed 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -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]);
 
diff --git a/hw/pc.c b/hw/pc.c
index bb78f0b..58de372 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -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]);
         }
     }
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 1930146..6001c86 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -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]);
     }