From: Yu Zhao Subject: [RFC PATCH 3/3] PCI: support Secondary Bus Reset Date: Tue, 7 Apr 2009 09:33:31 +0800 Message-ID: <1239068011-15164-3-git-send-email-yu.zhao@intel.com> References: <1239068011-15164-1-git-send-email-yu.zhao@intel.com> Cc: kvm@vger.kernel.org, matthew@wil.cx, Yu Zhao To: linux-pci@vger.kernel.org Return-path: Received: from mga09.intel.com ([134.134.136.24]:61176 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753639AbZDGBcY (ORCPT ); Mon, 6 Apr 2009 21:32:24 -0400 In-Reply-To: <1239068011-15164-1-git-send-email-yu.zhao@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: PCI-to-PCI Bridge 1.2 specifies that the Secondary Bus Reset bit can force the assertion of RST# on the secondary interface, which can be used to reset all devices including subordinates under this bus. This can be used to reset a function if this function is the only device under this bus. Signed-off-by: Yu Zhao --- drivers/pci/pci.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e459a0b..a77c33a 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2115,6 +2115,33 @@ static int pci_pm_flr(struct pci_dev *dev, int probe) return 0; } +static int pci_secondary_bus_reset(struct pci_dev *dev, int probe) +{ + u16 ctrl; + struct pci_dev *pdev; + + if (dev->subordinate) + return -ENOTTY; + + list_for_each_entry(pdev, &dev->bus->devices, bus_list) + if (pdev != dev) + return -ENOTTY; + + if (probe) + return 0; + + pci_read_config_word(dev->bus->self, PCI_BRIDGE_CONTROL, &ctrl); + ctrl |= PCI_BRIDGE_CTL_BUS_RESET; + pci_write_config_word(dev->bus->self, PCI_BRIDGE_CONTROL, ctrl); + msleep(100); + + ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET; + pci_write_config_word(dev->bus->self, PCI_BRIDGE_CONTROL, ctrl); + msleep(100); + + return 0; +} + static int pci_dev_reset(struct pci_dev *dev, int probe) { int rc; @@ -2136,6 +2163,10 @@ static int pci_dev_reset(struct pci_dev *dev, int probe) goto done; rc = pci_pm_flr(dev, probe); + if (rc != -ENOTTY) + goto done; + + rc = pci_secondary_bus_reset(dev, probe); done: up(&dev->dev.sem); -- 1.5.6.4