From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlv4F-0003oA-RA for qemu-devel@nongnu.org; Tue, 13 Oct 2015 04:36:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zlv4D-0005iH-SD for qemu-devel@nongnu.org; Tue, 13 Oct 2015 04:36:19 -0400 Received: from [59.151.112.132] (port=25161 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlv4D-0005dX-GE for qemu-devel@nongnu.org; Tue, 13 Oct 2015 04:36:17 -0400 From: Cao jin Date: Tue, 13 Oct 2015 16:41:34 +0800 Message-ID: <1444725695-27517-2-git-send-email-caoj.fnst@cn.fujitsu.com> In-Reply-To: <1444725695-27517-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1444725695-27517-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v3 1/2] enable multi-function hot-add List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, alex.williamson@redhat.com, izumi.taku@jp.fujitsu.com, mst@redhat.com Just ensure the function 0 added last, then driver will got the notification to scan all the function in the slot. Signed-off-by: Cao jin --- hw/pci/pci.c | 10 ++++++++++ hw/pci/pcie.c | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index ccea628..15b53d9 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -847,6 +847,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, PCIConfigWriteFunc *config_write = pc->config_write; Error *local_err = NULL; AddressSpace *dma_as; + DeviceState *dev = DEVICE(pci_dev); if (devfn < 0) { for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices); @@ -864,6 +865,15 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, PCI_SLOT(devfn), PCI_FUNC(devfn), name, bus->devices[devfn]->name); return NULL; + } else if (dev->hotplugged && + bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]) { + error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s," + " new func %s cannot be exposed to guest.", + PCI_SLOT(devfn), + bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name, + name); + + return NULL; } pci_dev->bus = bus; diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 6e28985..89bf61b 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -249,16 +249,16 @@ void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, return; } - /* TODO: multifunction hot-plug. - * Right now, only a device of function = 0 is allowed to be - * hot plugged/unplugged. + /* To enable multifunction hot-plug, we just ensure the function + * 0 added last. Until function 0 added, we set the sltsta and + * inform OS via event notification. */ - assert(PCI_FUNC(pci_dev->devfn) == 0); - - pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA, - PCI_EXP_SLTSTA_PDS); - pcie_cap_slot_event(PCI_DEVICE(hotplug_dev), - PCI_EXP_HP_EV_PDC | PCI_EXP_HP_EV_ABP); + if (PCI_FUNC(pci_dev->devfn) == 0) { + pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA, + PCI_EXP_SLTSTA_PDS); + pcie_cap_slot_event(PCI_DEVICE(hotplug_dev), + PCI_EXP_HP_EV_PDC | PCI_EXP_HP_EV_ABP); + } } void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev, -- 2.1.0