From patchwork Sun Sep 2 21:54:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 1397881 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 6B14A3FC71 for ; Sun, 2 Sep 2012 21:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756044Ab2IBVyf (ORCPT ); Sun, 2 Sep 2012 17:54:35 -0400 Received: from acsinet15.oracle.com ([141.146.126.227]:20005 "EHLO acsinet15.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755557Ab2IBVye (ORCPT ); Sun, 2 Sep 2012 17:54:34 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q82LsOrc005766 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 2 Sep 2012 21:54:25 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q82LsN8w029521 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 2 Sep 2012 21:54:24 GMT Received: from abhmt111.oracle.com (abhmt111.oracle.com [141.146.116.63]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q82LsNVc029925; Sun, 2 Sep 2012 16:54:23 -0500 Received: from linux-siqj.site (/75.55.221.75) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 02 Sep 2012 14:54:23 -0700 From: Yinghai Lu To: Bjorn Helgaas , Taku Izumi , Jiang Liu , x86 Cc: Andrew Morton , Linus Torvalds , Greg Kroah-Hartman , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Yinghai Lu Subject: [PATCH part4 03/11] PCI: Add pci_stop_and_remove_bus() Date: Sun, 2 Sep 2012 14:54:13 -0700 Message-Id: <1346622861-30865-4-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1346622861-30865-1-git-send-email-yinghai@kernel.org> References: <1346622861-30865-1-git-send-email-yinghai@kernel.org> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org It supports both pci root bus and pci bus under pci bridge. -v2: clear pci_bridge's subordinate. Signed-off-by: Yinghai Lu --- drivers/pci/remove.c | 32 ++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index b9f553b..94407d4 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -136,3 +136,35 @@ void pci_stop_and_remove_behind_bridge(struct pci_dev *dev) if (dev->subordinate) pci_remove_bus_devices(dev->subordinate); } + +static void pci_stop_host_bridge(struct pci_host_bridge *bridge) +{ + device_unregister(&bridge->dev); +} +/* + * it will support pci root bus too, in that case we need + * stop and remove host bridge + */ +void pci_stop_and_remove_bus(struct pci_bus *bus) +{ + struct pci_host_bridge *host_bridge = NULL; + struct pci_dev *pci_bridge = NULL; + + pci_stop_bus_devices(bus); + + if (pci_is_root_bus(bus)) { + host_bridge = to_pci_host_bridge(bus->bridge); + pci_stop_host_bridge(host_bridge); + } else + pci_bridge = bus->self; + + pci_remove_bus_devices(bus); + + pci_remove_bus(bus); + + if (host_bridge) + host_bridge->bus = NULL; + + if (pci_bridge) + pci_bridge->subordinate = NULL; +} diff --git a/include/linux/pci.h b/include/linux/pci.h index 4446448..8b2c722 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -738,6 +738,7 @@ extern void pci_remove_bus(struct pci_bus *b); extern void pci_stop_and_remove_bus_device(struct pci_dev *dev); void pci_stop_bus_devices(struct pci_bus *bus); void pci_stop_and_remove_behind_bridge(struct pci_dev *dev); +void pci_stop_and_remove_bus(struct pci_bus *bus); void pci_setup_cardbus(struct pci_bus *bus); extern void pci_sort_breadthfirst(void); #define dev_is_pci(d) ((d)->bus == &pci_bus_type)