From patchwork Fri Apr 3 07:41:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuji Shimada X-Patchwork-Id: 16044 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n337fu3l026994 for ; Fri, 3 Apr 2009 07:41:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751079AbZDCHl4 (ORCPT ); Fri, 3 Apr 2009 03:41:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751653AbZDCHl4 (ORCPT ); Fri, 3 Apr 2009 03:41:56 -0400 Received: from TYO202.gate.nec.co.jp ([202.32.8.206]:34621 "EHLO tyo202.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751079AbZDCHl4 (ORCPT ); Fri, 3 Apr 2009 03:41:56 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.195]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id n337fn5a003953; Fri, 3 Apr 2009 16:41:49 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id n337fn900971; Fri, 3 Apr 2009 16:41:49 +0900 (JST) Received: from mail03.kamome.nec.co.jp (mail03.kamome.nec.co.jp [10.25.43.7]) by mailsv4.nec.co.jp (8.13.8/8.13.4) with ESMTP id n337fm2P018443; Fri, 3 Apr 2009 16:41:48 +0900 (JST) Received: from kaishu.jp.nec.com ([10.26.220.5] [10.26.220.5]) by mail03.kamome.nec.co.jp with ESMTP id BT-MMP-331424; Fri, 3 Apr 2009 16:41:47 +0900 Received: from [10.58.40.47] ([10.58.40.47] [10.58.40.47]) by mail.jp.nec.com with ESMTP; Fri, 3 Apr 2009 16:41:46 +0900 Date: Fri, 03 Apr 2009 16:41:46 +0900 From: Yuji Shimada To: Alex Chiang , jbarnes@virtuousgeek.org, linux-pci@vger.kernel.org Subject: [PATCH v3] Setup disabled bridges even if buses are added. In-Reply-To: <20090403023229.GN7173@ldl.fc.hp.com> References: <20090403111102.0975.27C06F64@necst.nec.co.jp> <20090403023229.GN7173@ldl.fc.hp.com> Message-Id: <20090403164009.0987.27C06F64@necst.nec.co.jp> MIME-Version: 1.0 X-Mailer: Becky! ver. 2.50 [ja] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Thank you for your review. This patch setups disabled bridges even if buses have already been added. pci_assign_unassigned_resources is called after buses are added. pci_assign_unassigned_resources calls pci_bus_assign_resources. pci_bus_assign_resources calls pci_setup_bridge to configure BARs of bridges. Currently pci_setup_bridge returns immediately if the bus have already been added. So pci_assign_unassigned_resources can't configure BARs of bridge. The patch fixes the issue. On logical hot-add, we need to prevent the kernel from re-initializing bridges that have already been initialized. To achieve this, pci_setup_bridge returns immediately if the bridge have already been enabled. We don't need to check whether the specified bus is a root bus or not. pci_setup_bridge is not called on a root bus, because a root bus does not have a bridge. The patch adds a new helper function, pci_is_enabled. I made the function name similar to pci_is_managed. The codes which use enable_cnt directly are changed to use pci_is_enabled. Thanks, Acked-by: Alex Chiang --- Yuji Shimada Signed-off-by: Yuji Shimada -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 68f91a2..97a8194 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -184,7 +184,7 @@ void pci_enable_bridges(struct pci_bus *bus) list_for_each_entry(dev, &bus->devices, bus_list) { if (dev->subordinate) { - if (atomic_read(&dev->enable_cnt) == 0) { + if (!pci_is_enabled(dev)) { retval = pci_enable_device(dev); pci_set_master(dev); } diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index e9a8706..cd8e682 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -148,7 +148,7 @@ static ssize_t is_enabled_store(struct device *dev, return -EPERM; if (!val) { - if (atomic_read(&pdev->enable_cnt) != 0) + if (pci_is_enabled(pdev)) pci_disable_device(pdev); else result = -EIO; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 59569b8..5080a5d 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -812,7 +812,7 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) */ int pci_reenable_device(struct pci_dev *dev) { - if (atomic_read(&dev->enable_cnt)) + if (pci_is_enabled(dev)) return do_pci_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1); return 0; } @@ -1010,7 +1010,7 @@ static void do_pci_disable_device(struct pci_dev *dev) */ void pci_disable_enabled_device(struct pci_dev *dev) { - if (atomic_read(&dev->enable_cnt)) + if (pci_is_enabled(dev)) do_pci_disable_device(dev); } diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 334285a..8d9da9d 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -144,7 +144,7 @@ static void pci_setup_bridge(struct pci_bus *bus) struct pci_bus_region region; u32 l, bu, lu, io_upper16; - if (!pci_is_root_bus(bus) && bus->is_added) + if (pci_is_enabled(bridge)) return; dev_info(&bridge->dev, "PCI bridge, secondary bus %04x:%02x\n", diff --git a/include/linux/pci.h b/include/linux/pci.h index 6fb335b..1873182 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -674,6 +674,11 @@ int __must_check pci_reenable_device(struct pci_dev *); int __must_check pcim_enable_device(struct pci_dev *pdev); void pcim_pin_device(struct pci_dev *pdev); +static inline int pci_is_enabled(struct pci_dev *pdev) +{ + return (atomic_read(&pdev->enable_cnt) > 0); +} + static inline int pci_is_managed(struct pci_dev *pdev) { return pdev->is_managed;