From patchwork Thu Sep 10 12:12:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cao jin X-Patchwork-Id: 516258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1E67214028F for ; Thu, 10 Sep 2015 22:40:46 +1000 (AEST) Received: from localhost ([::1]:49095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Za19e-0004Nc-TI for incoming@patchwork.ozlabs.org; Thu, 10 Sep 2015 08:40:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Za0eA-0003iJ-QH for qemu-devel@nongnu.org; Thu, 10 Sep 2015 08:08:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Za0e4-0003cp-SB for qemu-devel@nongnu.org; Thu, 10 Sep 2015 08:08:10 -0400 Received: from [59.151.112.132] (port=56259 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Za0e4-0003WQ-GR for qemu-devel@nongnu.org; Thu, 10 Sep 2015 08:08:04 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100567467" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Sep 2015 20:10:54 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8AC7jlc005399; Thu, 10 Sep 2015 20:07:45 +0800 Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.65) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 10 Sep 2015 20:07:58 +0800 From: Cao jin To: Date: Thu, 10 Sep 2015 20:12:23 +0800 Message-ID: <1441887143-26756-3-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1441887143-26756-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1441887143-26756-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.65] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 X-Mailman-Approved-At: Thu, 10 Sep 2015 08:38:46 -0400 Cc: pbonzini@redhat.com, alex.williamson@redhat.com Subject: [Qemu-devel] [PATCH 2/2] PCI-e device multi-function hot-add support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In case user regret when hot-add multi-function, we should roll back, device_del the function added but still not worked. Signed-off-by: Cao jin --- hw/pci/pcie.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 61ebefd..b83a244 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -265,10 +265,33 @@ void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, } } +static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) +{ + object_unparent(OBJECT(dev)); +} + void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { uint8_t *exp_cap; + PCIDevice *pci_dev = PCI_DEVICE(dev); + PCIBus *bus = pci_dev->bus; + + /* handle the condition: user want to hot-add multi function, but regret + * before finish it, and want to delete the added but not worked function. + */ + if (PCI_FUNC(pci_dev->devfn) > 0 && + bus->devices[PCI_DEVFN(0,0)] == NULL) { + pci_for_each_device(bus, pci_bus_num(bus), + pcie_unplug_device, NULL); + + pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, + PCI_EXP_SLTSTA_PDS); + pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA, + PCI_EXP_SLTSTA_PDC); + + return; + } pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp); @@ -382,11 +405,6 @@ void pcie_cap_slot_reset(PCIDevice *dev) hotplug_event_update_event_status(dev); } -static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) -{ - object_unparent(OBJECT(dev)); -} - void pcie_cap_slot_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len) {