qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, agraf@suse.de,
	"Andreas Färber" <afaerber@suse.de>,
	armbru@redhat.com
Subject: [Qemu-devel] [RFC ppc-next v3 05/10] macio: Split MacIO in two
Date: Mon, 14 Jan 2013 00:54:59 +0100	[thread overview]
Message-ID: <1358121304-21345-6-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1358121304-21345-1-git-send-email-afaerber@suse.de>

Let the machines create two different types. This prepares to move
knowledge about sub-devices from the machines into the devices.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/macio.c            |   97 +++++++++++++++++++++++++++++++++++--------------
 hw/ppc/mac.h          |   10 +++--
 hw/ppc/mac_newworld.c |    4 +-
 hw/ppc/mac_oldworld.c |    4 +-
 4 Dateien geändert, 82 Zeilen hinzugefügt(+), 33 Zeilen entfernt(-)

diff --git a/hw/macio.c b/hw/macio.c
index 8b4b48d..0e6fc8d 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -36,7 +36,6 @@ typedef struct MacIOState
     PCIDevice parent;
     /*< public >*/
 
-    int is_oldworld;
     MemoryRegion bar;
     MemoryRegion *pic_mem;
     MemoryRegion *dbdma_mem;
@@ -52,15 +51,6 @@ static void macio_bar_setup(MacIOState *macio_state)
     int i;
     MemoryRegion *bar = &macio_state->bar;
 
-    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);
     }
@@ -80,7 +70,7 @@ static void macio_bar_setup(MacIOState *macio_state)
         macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000);
 }
 
-static int macio_initfn(PCIDevice *d)
+static int macio_common_initfn(PCIDevice *d)
 {
     MacIOState *s = MACIO(d);
 
@@ -92,6 +82,38 @@ static int macio_initfn(PCIDevice *d)
     return 0;
 }
 
+static int macio_oldworld_initfn(PCIDevice *d)
+{
+    MacIOState *s = MACIO(d);
+    int ret = macio_common_initfn(d);
+    if (ret < 0) {
+        return ret;
+    }
+
+    if (s->pic_mem) {
+        /* Heathrow PIC */
+        memory_region_add_subregion(&s->bar, 0x00000, s->pic_mem);
+    }
+
+    return 0;
+}
+
+static int macio_newworld_initfn(PCIDevice *d)
+{
+    MacIOState *s = MACIO(d);
+    int ret = macio_common_initfn(d);
+    if (ret < 0) {
+        return ret;
+    }
+
+    if (s->pic_mem) {
+        /* OpenPIC */
+        memory_region_add_subregion(&s->bar, 0x40000, s->pic_mem);
+    }
+
+    return 0;
+}
+
 static void macio_instance_init(Object *obj)
 {
     MacIOState *s = MACIO(obj);
@@ -99,44 +121,69 @@ static void macio_instance_init(Object *obj)
     memory_region_init(&s->bar, "macio", 0x80000);
 }
 
+static void macio_oldworld_class_init(ObjectClass *oc, void *data)
+{
+    PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
+
+    pdc->init = macio_oldworld_initfn;
+    pdc->device_id = PCI_DEVICE_ID_APPLE_343S1201;
+}
+
+static void macio_newworld_class_init(ObjectClass *oc, void *data)
+{
+    PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
+
+    pdc->init = macio_newworld_initfn;
+    pdc->device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL;
+}
+
 static void macio_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = macio_initfn;
     k->vendor_id = PCI_VENDOR_ID_APPLE;
     k->class_id = PCI_CLASS_OTHERS << 8;
 }
 
+static const TypeInfo macio_oldworld_type_info = {
+    .name          = TYPE_OLDWORLD_MACIO,
+    .parent        = TYPE_MACIO,
+    .class_init    = macio_oldworld_class_init,
+};
+
+static const TypeInfo macio_newworld_type_info = {
+    .name          = TYPE_NEWWORLD_MACIO,
+    .parent        = TYPE_MACIO,
+    .class_init    = macio_newworld_class_init,
+};
+
 static const TypeInfo macio_type_info = {
     .name          = TYPE_MACIO,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(MacIOState),
     .instance_init = macio_instance_init,
+    .abstract      = true,
     .class_init    = macio_class_init,
 };
 
 static void macio_register_types(void)
 {
     type_register_static(&macio_type_info);
+    type_register_static(&macio_oldworld_type_info);
+    type_register_static(&macio_newworld_type_info);
 }
 
 type_init(macio_register_types)
 
-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(PCIDevice *d,
+                MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
+                MemoryRegion *cuda_mem, void *nvram,
+                int nb_ide, MemoryRegion **ide_mem,
+                MemoryRegion *escc_mem)
 {
-    PCIDevice *d;
-    MacIOState *macio_state;
+    MacIOState *macio_state = MACIO(d);
     int i;
 
-    d = pci_create(bus, -1, TYPE_MACIO);
-
-    macio_state = MACIO(d);
-    macio_state->is_oldworld = is_oldworld;
     macio_state->pic_mem = pic_mem;
     macio_state->dbdma_mem = dbdma_mem;
     macio_state->cuda_mem = cuda_mem;
@@ -147,12 +194,8 @@ void macio_init (PCIBus *bus, int device_id, int is_oldworld,
     macio_state->nb_ide = nb_ide;
     for (i = 0; i < nb_ide; i++)
         macio_state->ide_mem[i] = ide_mem[i];
-    for (; i < 4; i++)
-        macio_state->ide_mem[i] = NULL;
     /* Note: this code is strongly inspirated from the corresponding code
        in PearPC */
 
-    pci_config_set_device_id(d->config, device_id);
-
     qdev_init_nofail(DEVICE(d));
 }
diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index 89c7d66..864a610 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -45,10 +45,12 @@
 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);
+#define TYPE_OLDWORLD_MACIO "macio-oldworld"
+#define TYPE_NEWWORLD_MACIO "macio-newworld"
+void macio_init(PCIDevice *dev,
+                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/mac_newworld.c b/hw/ppc/mac_newworld.c
index adf111c..d1329dc 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -147,6 +147,7 @@ static void ppc_core99_init(QEMUMachineInitArgs *args)
     hwaddr kernel_base, initrd_base, cmdline_base = 0;
     long kernel_size, initrd_size;
     PCIBus *pci_bus;
+    PCIDevice *macio;
     MacIONVRAMState *nvr;
     int bios_size;
     MemoryRegion *pic_mem, *dbdma_mem, *cuda_mem, *escc_mem;
@@ -374,7 +375,8 @@ static void ppc_core99_init(QEMUMachineInitArgs *args)
     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 = pci_create(pci_bus, -1, TYPE_NEWWORLD_MACIO);
+    macio_init(macio, pic_mem,
                dbdma_mem, cuda_mem, NULL, 3, ide_mem, escc_bar);
 
     if (usb_enabled(machine_arch == ARCH_MAC99_U3)) {
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 0d9f65b..74b3878 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -90,6 +90,7 @@ static void ppc_heathrow_init(QEMUMachineInitArgs *args)
     uint32_t kernel_base, initrd_base, cmdline_base = 0;
     int32_t kernel_size, initrd_size;
     PCIBus *pci_bus;
+    PCIDevice *macio;
     MacIONVRAMState *nvr;
     int bios_size;
     MemoryRegion *pic_mem, *dbdma_mem, *cuda_mem;
@@ -283,7 +284,8 @@ static void ppc_heathrow_init(QEMUMachineInitArgs *args)
     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 = pci_create(pci_bus, -1, TYPE_OLDWORLD_MACIO);
+    macio_init(macio, pic_mem,
                dbdma_mem, cuda_mem, nvr, 2, ide_mem, escc_bar);
 
     if (usb_enabled(false)) {
-- 
1.7.10.4

  parent reply	other threads:[~2013-01-13 23:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-13 23:54 [Qemu-devel] [RFC ppc-next v3 00/10] target-ppc: MacIO QOM'ification Andreas Färber
2013-01-13 23:54 ` [Qemu-devel] [PATCH 01/10] qom: Make object_resolve_path_component() path argument const Andreas Färber
2013-01-14 12:19   ` Markus Armbruster
2013-01-14 16:52     ` Andreas Färber
2013-01-14 17:27       ` Markus Armbruster
2013-01-14 19:01       ` [Qemu-devel] Go along with glib's basic type typedef silliness? (was: [PATCH 01/10] qom: Make object_resolve_path_component() path argument const) Markus Armbruster
2013-01-17 20:26         ` Blue Swirl
2013-01-18 15:36           ` [Qemu-devel] Go along with glib's basic type typedef silliness? Markus Armbruster
2013-01-19  9:13             ` Blue Swirl
2013-01-13 23:54 ` [Qemu-devel] [RFC ppc-next v3 02/10] ppc: Move Mac machines to hw/ppc/ Andreas Färber
2013-01-13 23:54 ` [Qemu-devel] [RFC ppc-next v3 03/10] macio: QOM'ify some more Andreas Färber
2013-01-13 23:54 ` [Qemu-devel] [RFC ppc-next v3 04/10] macio: Delay qdev init until all fields are initialized Andreas Färber
2013-01-13 23:54 ` Andreas Färber [this message]
2013-01-13 23:55 ` [Qemu-devel] [RFC ppc-next v3 06/10] mac_nvram: Clean up public API Andreas Färber
2013-01-13 23:55 ` [Qemu-devel] [RFC ppc-next v3 07/10] mac_nvram: Mark as Big Endian Andreas Färber
2013-01-13 23:55 ` [Qemu-devel] [RFC ppc-next v3 08/10] mac_nvram: QOM'ify MacIO NVRAM Andreas Färber
2013-01-14 12:34   ` Markus Armbruster
2013-01-14 16:22     ` Andreas Färber
2013-01-14 17:30       ` Markus Armbruster
2013-01-13 23:55 ` [Qemu-devel] [RFC ppc-next v3 09/10] ide/macio: QOM'ify MacIO IDE Andreas Färber
2013-01-13 23:55 ` [Qemu-devel] [RFC ppc-next v3 10/10] cuda: QOM'ify CUDA Andreas Färber
2013-01-14 12:47 ` [Qemu-devel] [RFC ppc-next v3 00/10] target-ppc: MacIO QOM'ification Markus Armbruster
2013-01-14 21:56 ` [Qemu-devel] [Qemu-ppc] " Mark Cave-Ayland
2013-01-18 16:36   ` Andreas Färber

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=1358121304-21345-6-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /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).