From patchwork Thu May 16 15:50:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2578691 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 5A683DFB7B for ; Thu, 16 May 2013 15:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752207Ab3EPPvd (ORCPT ); Thu, 16 May 2013 11:51:33 -0400 Received: from mail-da0-f49.google.com ([209.85.210.49]:49197 "EHLO mail-da0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754704Ab3EPPvb (ORCPT ); Thu, 16 May 2013 11:51:31 -0400 Received: by mail-da0-f49.google.com with SMTP id p5so1749084dak.36 for ; Thu, 16 May 2013 08:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=98GdKdlB72/cEI+1AqjJeQSgIGSKih0DzyNSnELztWo=; b=XJH39Pcw9YN3f4WqDss0J0Jx7Wkm8JJq6meitABspO/ZjxzeBnfBlF7t1jn0ta+s4K 5B+V6Ss/pJLR8mAZ2eI9IzE5gJtG1JH8LE1JBzFYHadkx2oKOwjfz70+6ImSMQCOI5J8 PfU8x2r7S241EQ2vJpDqDZOy8FBDrN4D1lpfFQv593J06zN/YhzucEyYsIRLJnym2JzL rwuXxQ+y2TBep4fxO/VhyihGcZpMrHDF/V7N5nkKd3Hwj9P8l/ww31whSt6DXGsf56UZ l7xVe+SprhQ+cuggG/ls2cf1VulRjqtpkheV5rY3CmOgoWsp8QIq/DpKRIVmtb9tRnpd xm7w== X-Received: by 10.68.40.200 with SMTP id z8mr42849725pbk.210.1368719490915; Thu, 16 May 2013 08:51:30 -0700 (PDT) Received: from localhost.localdomain ([120.196.98.100]) by mx.google.com with ESMTPSA id ea15sm8026701pad.16.2013.05.16.08.51.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 May 2013 08:51:29 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Yinghai Lu Cc: Jiang Liu , "Rafael J . Wysocki" , Greg Kroah-Hartman , Gu Zheng , Toshi Kani , Myron Stowe , Yijing Wang , Jiang Liu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2, part3 04/11] PCI: introduce helper function pci_stop_and_remove_device() Date: Thu, 16 May 2013 23:50:52 +0800 Message-Id: <1368719459-24800-5-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1368719459-24800-1-git-send-email-jiang.liu@huawei.com> References: <1368719459-24800-1-git-send-email-jiang.liu@huawei.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Introduce a helper function pci_stop_and_remove_device(), which removes a PCI device in a safe way by locking parent and all affected descendant PCI buses. Signed-off-by: Jiang Liu Cc: Yinghai Lu Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/remove.c | 19 +++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 20 insertions(+) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 2f01f72..8e9b272 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "pci.h" static void pci_stop_bus_device(struct pci_dev *dev); @@ -148,6 +149,24 @@ void pci_stop_and_remove_bus_device(struct pci_dev *dev) } EXPORT_SYMBOL(pci_stop_and_remove_bus_device); +void pci_stop_and_remove_device(struct pci_dev *pdev) +{ + int ret; + struct pci_bus *bus = pdev->bus; + + do { + ret = pci_bus_lock_timeout(bus, PCI_BUS_STATE_STOPPING - 1, + true, HZ / 10); + if (ret == 0) { + pci_stop_and_remove_bus_device(pdev); + pci_bus_unlock(bus, true); + break; + } + } while (pci_bus_get_state(bus) <= PCI_BUS_STATE_STARTED && + pci_dev_get_state(pdev) <= PCI_DEV_STATE_STARTED); +} +EXPORT_SYMBOL(pci_stop_and_remove_device); + void pci_stop_root_bus(struct pci_bus *bus) { BUG_ON(!pci_bus_is_locked(bus)); diff --git a/include/linux/pci.h b/include/linux/pci.h index d3f61f8..45d4aea 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -817,6 +817,7 @@ struct pci_dev *pci_dev_get(struct pci_dev *dev); void pci_dev_put(struct pci_dev *dev); void pci_remove_bus(struct pci_bus *b); void pci_stop_and_remove_bus_device(struct pci_dev *dev); +void pci_stop_and_remove_device(struct pci_dev *dev); void pci_stop_root_bus(struct pci_bus *bus); void pci_remove_root_bus(struct pci_bus *bus); void pci_setup_cardbus(struct pci_bus *bus);