From patchwork Fri Sep 25 19:42:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 34297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 50927B7B93 for ; Sat, 26 Sep 2009 06:13:56 +1000 (EST) Received: from localhost ([127.0.0.1]:58665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrHAv-00034G-AG for incoming@patchwork.ozlabs.org; Fri, 25 Sep 2009 16:13:53 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MrGhJ-0006XR-8P for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MrGhD-0006Rg-8Q for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:15 -0400 Received: from [199.232.76.173] (port=56055 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrGhB-0006RC-Kg for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55214) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MrGhB-0004es-3f for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:09 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8PJh8rH027808 for ; Fri, 25 Sep 2009 15:43:08 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-108.ams2.redhat.com [10.36.8.108]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n8PJguZU004602; Fri, 25 Sep 2009 15:43:06 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id A92A8700F7; Fri, 25 Sep 2009 21:42:50 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 25 Sep 2009 21:42:44 +0200 Message-Id: <1253907769-1067-20-git-send-email-kraxel@redhat.com> In-Reply-To: <1253907769-1067-1-git-send-email-kraxel@redhat.com> References: <1253907769-1067-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 19/24] pci: hotplug windup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Create qdev infrastructure for pci hotplug. PCI bus implementations must register a handler for hotplug. Creating a new PCI device will automagically hot-plug it in case the PCI bus in question supports this. Signed-off-by: Gerd Hoffmann --- hw/pci.c | 25 +++++++++++++++++++++++-- hw/pci.h | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 3221a6c..03ad90f 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -41,6 +41,7 @@ struct PCIBus { int devfn_min; pci_set_irq_fn set_irq; pci_map_irq_fn map_irq; + pci_hotplug_fn hotplug; uint32_t config_reg; /* XXX: suppress */ void *irq_opaque; PCIDevice *devices[256]; @@ -132,6 +133,12 @@ void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, bus->irq_count = qemu_mallocz(nirq * sizeof(bus->irq_count[0])); } +void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug) +{ + bus->qbus.allow_hotplug = 1; + bus->hotplug = hotplug; +} + PCIBus *pci_register_bus(DeviceState *parent, const char *name, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, void *irq_opaque, int devfn_min, int nirq) @@ -935,19 +942,33 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base) PCIDevice *pci_dev = (PCIDevice *)qdev; PCIDeviceInfo *info = container_of(base, PCIDeviceInfo, qdev); PCIBus *bus; - int devfn; + int devfn, rc; bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev)); devfn = pci_dev->devfn; pci_dev = do_pci_register_device(pci_dev, bus, base->name, devfn, info->config_read, info->config_write); assert(pci_dev); - return info->init(pci_dev); + rc = info->init(pci_dev); + if (rc != 0) + return rc; + if (qdev->hotplugged) + bus->hotplug(pci_dev, 1); + return 0; +} + +static int pci_unplug_device(DeviceState *qdev) +{ + PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev); + + dev->bus->hotplug(dev, 0); + return 0; } void pci_qdev_register(PCIDeviceInfo *info) { info->qdev.init = pci_qdev_init; + info->qdev.unplug = pci_unplug_device; info->qdev.exit = pci_unregister_device; info->qdev.bus_info = &pci_bus_info; qdev_register(&info->qdev); diff --git a/hw/pci.h b/hw/pci.h index 5e781d8..c678353 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -246,11 +246,13 @@ int pci_device_load(PCIDevice *s, QEMUFile *f); typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level); typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num); +typedef int (*pci_hotplug_fn)(PCIDevice *pci_dev, int state); void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, int devfn_min); PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min); void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, void *irq_opaque, int nirq); +void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug); PCIBus *pci_register_bus(DeviceState *parent, const char *name, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, void *irq_opaque, int devfn_min, int nirq);