qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Anthony Liguori" <aliguori@us.ibm.com>,
	"Alexander Graf" <agraf@suse.de>,
	"Laurent Vivier" <laurent@vivier.eu>,
	qemu-ppc@nongnu.org, "Avi Kivity" <avi@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Richard Henderson" <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH] macio: Convert to qdev
Date: Fri, 27 Jan 2012 00:17:02 +0100	[thread overview]
Message-ID: <1327619823-9491-1-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1327433600-7403-2-git-send-email-aliguori@us.ibm.com>

From: Anthony Liguori <aliguori@us.ibm.com>

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Split macio into two PCIDevices with declarative device ID,
macio-oldworld and macio-newworld. Drop is_oldworld state in favor
of two separate init functions and deferred creation.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Alexander Graf <agraf@suse.de>
---
 Anthony, I've extended and tested your patch, please consider using this version.
 (In that case feel free to move your Signed-off-by down.)

 Alex, please ack. We could inline macio_init() and get rid of is_oldworld but
 would have to move MacIOState into ppc_mac.h then.

 hw/macio.c        |  114 +++++++++++++++++++++++++++++++++++++---------------
 hw/ppc_mac.h      |    8 ++--
 hw/ppc_newworld.c |    2 +-
 hw/ppc_oldworld.c |    2 +-
 4 files changed, 87 insertions(+), 39 deletions(-)

diff --git a/hw/macio.c b/hw/macio.c
index cc6ae40..3fb49fb 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -27,9 +27,8 @@
 #include "pci.h"
 #include "escc.h"
 
-typedef struct macio_state_t macio_state_t;
-struct macio_state_t {
-    int is_oldworld;
+typedef struct MacIOState {
+    PCIDevice parent;
     MemoryRegion bar;
     MemoryRegion *pic_mem;
     MemoryRegion *dbdma_mem;
@@ -38,23 +37,14 @@ struct macio_state_t {
     void *nvram;
     int nb_ide;
     MemoryRegion *ide_mem[4];
-};
+} MacIOState;
 
-static void macio_bar_setup(macio_state_t *macio_state)
+static void macio_bar_setup(MacIOState *macio_state)
 {
     int i;
     MemoryRegion *bar = &macio_state->bar;
 
     memory_region_init(bar, "macio", 0x80000);
-    if (macio_state->pic_mem) {
-        if (macio_state->is_oldworld) {
-            /* Heathrow PIC */
-            memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem);
-        } else {
-            /* OpenPIC */
-            memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem);
-        }
-    }
     if (macio_state->dbdma_mem) {
         memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem);
     }
@@ -70,25 +60,82 @@ static void macio_bar_setup(macio_state_t *macio_state)
                                         macio_state->ide_mem[i]);
         }
     }
-    if (macio_state->nvram != NULL)
+    if (macio_state->nvram != NULL) {
         macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
+    }
+}
+
+static void macio_common_init(MacIOState *macio_state)
+{
+    PCIDevice *d = &macio_state->parent;
+
+    d->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt on pin 1 */
+
+    macio_bar_setup(macio_state);
+    pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
+}
+
+static int macio_oldworld_initfn(PCIDevice *d)
+{
+    MacIOState *s = DO_UPCAST(MacIOState, parent, d);
+
+    macio_common_init(s);
+
+    if (s->pic_mem != NULL) {
+        /* Heathrow PIC */
+        memory_region_add_subregion(&s->bar, 0x00000, s->pic_mem);
+    }
+    return 0;
 }
 
-void macio_init (PCIBus *bus, int device_id, int is_oldworld,
-                 MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
-                 MemoryRegion *cuda_mem, void *nvram,
-                 int nb_ide, MemoryRegion **ide_mem,
-                 MemoryRegion *escc_mem)
+static int macio_newworld_initfn(PCIDevice *d)
+{
+    MacIOState *s = DO_UPCAST(MacIOState, parent, d);
+
+    macio_common_init(s);
+
+    if (s->pic_mem != NULL) {
+        /* OpenPIC */
+        memory_region_add_subregion(&s->bar, 0x40000, s->pic_mem);
+    }
+    return 0;
+}
+
+static PCIDeviceInfo macio_oldworld_info = {
+    .qdev.name = "macio-oldworld",
+    .qdev.size = sizeof(MacIOState),
+    .qdev.no_user = 1,
+    .no_hotplug = 1,
+    .init = macio_oldworld_initfn,
+    .vendor_id = PCI_VENDOR_ID_APPLE,
+    .device_id = PCI_DEVICE_ID_APPLE_343S1201,
+    .class_id = PCI_CLASS_OTHERS << 8,
+};
+
+static PCIDeviceInfo macio_newworld_info = {
+    .qdev.name = "macio-newworld",
+    .qdev.size = sizeof(MacIOState),
+    .qdev.no_user = 1,
+    .no_hotplug = 1,
+    .init = macio_newworld_initfn,
+    .vendor_id = PCI_VENDOR_ID_APPLE,
+    .device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL,
+    .class_id = PCI_CLASS_OTHERS << 8,
+};
+
+void macio_init(PCIBus *bus, bool is_oldworld,
+                MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
+                MemoryRegion *cuda_mem, void *nvram,
+                int nb_ide, MemoryRegion **ide_mem,
+                MemoryRegion *escc_mem)
 {
     PCIDevice *d;
-    macio_state_t *macio_state;
+    MacIOState *macio_state;
     int i;
 
-    d = pci_register_device(bus, "macio",
-                            sizeof(PCIDevice) + sizeof(macio_state_t),
-                            -1, NULL, NULL);
-    macio_state = (macio_state_t *)(d + 1);
-    macio_state->is_oldworld = is_oldworld;
+    d = pci_create(bus, -1, is_oldworld ? "macio-oldworld" : "macio-newworld");
+
+    macio_state = DO_UPCAST(MacIOState, parent, d);
     macio_state->pic_mem = pic_mem;
     macio_state->dbdma_mem = dbdma_mem;
     macio_state->cuda_mem = cuda_mem;
@@ -104,12 +151,13 @@ void macio_init (PCIBus *bus, int device_id, int is_oldworld,
     /* Note: this code is strongly inspirated from the corresponding code
        in PearPC */
 
-    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
-    pci_config_set_device_id(d->config, device_id);
-    pci_config_set_class(d->config, PCI_CLASS_OTHERS << 8);
-
-    d->config[0x3d] = 0x01; // interrupt on pin 1
+    qdev_init_nofail(&d->qdev);
+}
 
-    macio_bar_setup(macio_state);
-    pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &macio_state->bar);
+static void macio_register(void)
+{
+    pci_qdev_register(&macio_oldworld_info);
+    pci_qdev_register(&macio_newworld_info);
 }
+
+device_init(macio_register)
diff --git a/hw/ppc_mac.h b/hw/ppc_mac.h
index af75e45..c165096 100644
--- a/hw/ppc_mac.h
+++ b/hw/ppc_mac.h
@@ -45,10 +45,10 @@
 void cuda_init (MemoryRegion **cuda_mem, qemu_irq irq);
 
 /* MacIO */
-void macio_init (PCIBus *bus, int device_id, int is_oldworld,
-                 MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
-                 MemoryRegion *cuda_mem, void *nvram,
-                 int nb_ide, MemoryRegion **ide_mem, MemoryRegion *escc_mem);
+void macio_init(PCIBus *bus, bool is_oldworld,
+                MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
+                MemoryRegion *cuda_mem, void *nvram,
+                int nb_ide, MemoryRegion **ide_mem, MemoryRegion *escc_mem);
 
 /* Heathrow PIC */
 qemu_irq *heathrow_pic_init(MemoryRegion **pmem,
diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c
index a746c9c..83c09fa 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -348,7 +348,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
     adb_kbd_init(&adb_bus);
     adb_mouse_init(&adb_bus);
 
-    macio_init(pci_bus, PCI_DEVICE_ID_APPLE_UNI_N_KEYL, 0, pic_mem,
+    macio_init(pci_bus, false, pic_mem,
                dbdma_mem, cuda_mem, NULL, 3, ide_mem, escc_bar);
 
     if (usb_enabled) {
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index 9295a34..7a74b61 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -274,7 +274,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
     nvr = macio_nvram_init(0x2000, 4);
     pmac_format_nvram_partition(nvr, 0x2000);
 
-    macio_init(pci_bus, PCI_DEVICE_ID_APPLE_343S1201, 1, pic_mem,
+    macio_init(pci_bus, true, pic_mem,
                dbdma_mem, cuda_mem, nvr, 2, ide_mem, escc_bar);
 
     if (usb_enabled) {
-- 
1.7.7

  reply	other threads:[~2012-01-26 23:19 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-24 19:32 [Qemu-devel] [PATCH v3 0/28] qom: add QEMU Object Model type hierarchy to qdev Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 01/28] macio: convert " Anthony Liguori
2012-01-26 23:17   ` Andreas Färber [this message]
2012-03-06 22:56     ` [Qemu-devel] [PATCH] macio: Convert " Alexander Graf
2012-01-24 19:32 ` [Qemu-devel] [PATCH 02/28] openpic: remove dead code to make a PCI device version Anthony Liguori
2012-01-26 23:57   ` Andreas Färber
2012-01-24 19:32 ` [Qemu-devel] [PATCH 03/28] pci: call reset unconditionally Anthony Liguori
2012-01-25 12:42   ` Michael S. Tsirkin
2012-01-25 13:28     ` Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2) Anthony Liguori
2012-01-25 21:30   ` Andreas Färber
2012-01-25 21:37     ` Anthony Liguori
2012-01-26  7:43       ` Paolo Bonzini
2012-01-27 15:05       ` Andreas Färber
2012-01-27 15:42         ` Anthony Liguori
2012-01-27 15:43           ` Andreas Färber
2012-01-24 19:32 ` [Qemu-devel] [PATCH 05/28] qdev: integrate with QEMU Object Model (v2) Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 06/28] qdev: move qdev->info to class Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 07/28] qdev: don't access name through info Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 08/28] qdev: use a wrapper to access reset and promote reset to a class method Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 09/28] qdev: add a interface to register subclasses Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 10/28] qdev: add class_init to DeviceInfo Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 11/28] qdev: prepare source tree for code conversion Anthony Liguori
2012-01-26 17:35   ` [Qemu-devel] [PATCH 1/3] es1370: Drop dead code Andreas Färber
2012-01-26 17:35     ` [Qemu-devel] [PATCH 2/3] marvell_88w8618_audio: Use DEFINE_PROP_* macros Andreas Färber
2012-01-26 17:35     ` [Qemu-devel] [PATCH 3/3] qdev: prepare source tree for code conversion Andreas Färber
2012-01-24 19:33 ` [Qemu-devel] [PATCH 12/28] isa: pic: convert to QEMU Object Model Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 13/28] usb: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 14/28] ccid: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 15/28] ssi: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 16/28] i2c: rename i2c_slave -> I2CSlave Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 17/28] i2c: smbus: convert to QEMU Object Model Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 18/28] hda-codec: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 19/28] ide: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 20/28] scsi: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 21/28] spapr: convert to QEMU Object Model (v2) Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 22/28] virtio-serial: convert to QEMU Object Model Anthony Liguori
2012-01-24 19:59   ` Amit Shah
2012-01-24 20:13     ` Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 23/28] unin_pci: Clean up qdev names Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 24/28] unin_pci: Drop duplicate busdev Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 25/28] unin_pci: Drop unused reset handler Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 26/28] pci: convert to QEMU Object Model Anthony Liguori
2012-01-25 12:41   ` Michael S. Tsirkin
2012-01-25 13:34     ` Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: " Anthony Liguori
2012-01-24 20:01   ` Jan Kiszka
2012-01-24 20:21     ` Anthony Liguori
2012-01-24 21:01       ` Jan Kiszka
2012-01-24 21:11         ` Anthony Liguori
2012-01-24 21:31           ` Jan Kiszka
2012-01-24 21:53             ` Anthony Liguori
2012-01-24 22:06               ` Jan Kiszka
2012-01-24 23:03                 ` Anthony Liguori
2012-01-25  8:33                   ` Andreas Färber
2012-01-25 12:09                     ` Avi Kivity
2012-01-25 13:02                     ` Paul Brook
2012-01-25 14:25                     ` Anthony Liguori
2012-01-25  8:37                   ` Jan Kiszka
2012-01-25 10:15                     ` Paolo Bonzini
2012-01-25 10:27                       ` Jan Kiszka
2012-01-25 11:15                         ` Paolo Bonzini
2012-01-25 14:00                     ` Anthony Liguori
2012-01-25 14:23                       ` Jan Kiszka
2012-01-25 14:40                         ` Anthony Liguori
2012-01-25 15:18                           ` Andreas Färber
2012-01-25 15:34                           ` Eric Blake
2012-01-24 19:33 ` [Qemu-devel] [PATCH 28/28] virtio-s390: " Anthony Liguori
2012-01-24 23:13 ` [Qemu-devel] [PATCH v3 0/28] qom: add QEMU Object Model type hierarchy to qdev Peter Maydell
2012-01-24 23:16   ` Anthony Liguori
2012-01-25 18:31 ` Blue Swirl
2012-01-25 19:43   ` Anthony Liguori
2012-01-25 20:09     ` Blue Swirl
2012-01-27 17:34 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327619823-9491-1-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).