All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 07/24] convert pci bridge to qdev
Date: Fri, 25 Sep 2009 21:42:32 +0200	[thread overview]
Message-ID: <1253907769-1067-8-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1253907769-1067-1-git-send-email-kraxel@redhat.com>

Also switch secondary pci busses to inplace allocation.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci.c |   66 +++++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index ad508a5..608792a 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -142,18 +142,16 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,
     return bus;
 }
 
-static PCIBus *pci_register_secondary_bus(PCIDevice *dev,
-                                          pci_map_irq_fn map_irq,
-                                          const char *name)
+static void pci_register_secondary_bus(PCIBus *bus,
+                                       PCIDevice *dev,
+                                       pci_map_irq_fn map_irq,
+                                       const char *name)
 {
-    PCIBus *bus;
-
-    bus = FROM_QBUS(PCIBus, qbus_create(&pci_bus_info, &dev->qdev, name));
+    qbus_create_inplace(&bus->qbus, &pci_bus_info, &dev->qdev, name);
     bus->map_irq = map_irq;
     bus->parent_dev = dev;
     bus->next = dev->bus->next;
     dev->bus->next = bus;
-    return bus;
 }
 
 int pci_bus_num(PCIBus *s)
@@ -858,7 +856,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
 
 typedef struct {
     PCIDevice dev;
-    PCIBus *bus;
+    PCIBus bus;
+    uint32_t vid;
+    uint32_t did;
 } PCIBridge;
 
 static void pci_bridge_write_config(PCIDevice *d,
@@ -867,7 +867,7 @@ static void pci_bridge_write_config(PCIDevice *d,
     PCIBridge *s = (PCIBridge *)d;
 
     pci_default_write_config(d, address, val, len);
-    s->bus->bus_num = d->config[PCI_SECONDARY_BUS];
+    s->bus.bus_num = d->config[PCI_SECONDARY_BUS];
 }
 
 PCIBus *pci_find_bus(int bus_num)
@@ -890,15 +890,12 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function)
     return bus->devices[PCI_DEVFN(slot, function)];
 }
 
-PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
-                        pci_map_irq_fn map_irq, const char *name)
+static int pci_bridge_initfn(PCIDevice *dev)
 {
-    PCIBridge *s;
-    s = (PCIBridge *)pci_register_device(bus, name, sizeof(PCIBridge),
-                                         devfn, NULL, pci_bridge_write_config);
+    PCIBridge *s = DO_UPCAST(PCIBridge, dev, dev);
 
-    pci_config_set_vendor_id(s->dev.config, vid);
-    pci_config_set_device_id(s->dev.config, did);
+    pci_config_set_vendor_id(s->dev.config, s->vid);
+    pci_config_set_device_id(s->dev.config, s->did);
 
     s->dev.config[0x04] = 0x06; // command = bus master, pci mem
     s->dev.config[0x05] = 0x00;
@@ -911,9 +908,23 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
     s->dev.config[PCI_HEADER_TYPE] =
         PCI_HEADER_TYPE_MULTI_FUNCTION | PCI_HEADER_TYPE_BRIDGE; // header_type
     s->dev.config[0x1E] = 0xa0; // secondary status
+    return 0;
+}
 
-    s->bus = pci_register_secondary_bus(&s->dev, map_irq, name);
-    return s->bus;
+PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
+                        pci_map_irq_fn map_irq, const char *name)
+{
+    PCIDevice *dev;
+    PCIBridge *s;
+
+    dev = pci_create_noinit(bus, devfn, "pci-bridge");
+    qdev_prop_set_uint32(&dev->qdev, "vendorid", vid);
+    qdev_prop_set_uint32(&dev->qdev, "deviceid", did);
+    qdev_init(&dev->qdev);
+
+    s = DO_UPCAST(PCIBridge, dev, dev);
+    pci_register_secondary_bus(&s->bus, &s->dev, map_irq, name);
+    return &s->bus;
 }
 
 static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
@@ -1074,3 +1085,22 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
                        r->addr, r->addr + r->size - 1);
     }
 }
+
+static PCIDeviceInfo bridge_info = {
+    .qdev.name    = "pci-bridge",
+    .qdev.size    = sizeof(PCIBridge),
+    .init         = pci_bridge_initfn,
+    .config_write = pci_bridge_write_config,
+    .qdev.props   = (Property[]) {
+        DEFINE_PROP_HEX32("vendorid", PCIBridge, vid, 0),
+        DEFINE_PROP_HEX32("deviceid", PCIBridge, did, 0),
+        DEFINE_PROP_END_OF_LIST(),
+    }
+};
+
+static void pci_register_devices(void)
+{
+    pci_qdev_register(&bridge_info);
+}
+
+device_init(pci_register_devices)
-- 
1.6.2.5

  parent reply	other threads:[~2009-09-25 19:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-25 19:42 [Qemu-devel] [PATCH 00/24] qdev: bus management updates Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 01/24] unbreak usb pass-through on linux Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 02/24] allow qdev busses allocations be inplace Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 03/24] switch scsi bus to inplace allocation Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 04/24] switch usb " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 05/24] switch ide " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 06/24] inplace allocation for pci, split irq init Gerd Hoffmann
2009-09-25 19:42 ` Gerd Hoffmann [this message]
2009-09-25 19:42 ` [Qemu-devel] [PATCH 08/24] piix_pci: kill PIIX3IrqState Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 09/24] qdev: device free fixups Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 10/24] Add exit callback to DeviceInfo Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 11/24] Implement scsi device destruction Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 12/24] pci: use qdev for " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 13/24] pci: move unregister from PCIDevice to PCIDeviceInfo Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 14/24] usb: hook unplug into qdev, cleanups + fixes Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 15/24] switch qemu-config to qemu_error Gerd Hoffmann
2009-09-28 20:40   ` Markus Armbruster
2009-09-29  8:57     ` Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 16/24] qdev hotplug: infrastructure and monitor commands Gerd Hoffmann
2009-09-28 20:32   ` Markus Armbruster
2009-09-29  9:08     ` Gerd Hoffmann
2009-09-29 12:25       ` Markus Armbruster
2009-09-29 13:23         ` Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 17/24] usb: hotplug windup Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 18/24] scsi: " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 19/24] pci: " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 20/24] pci: windup acpi-based hotplug Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 21/24] drive cleanup fixes Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 22/24] refactor drive_hot_add Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 23/24] allow if=none for drive_add Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 24/24] store a pointer to QemuOpts in DeviceState, release it when zapping a device Gerd Hoffmann
2009-09-25 20:57 ` [Qemu-devel] [PATCH 00/24] qdev: bus management updates Anthony Liguori
2009-09-28 20:40 ` Markus Armbruster

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=1253907769-1067-8-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.