From patchwork Fri Jan 18 16:07:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2003791 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 8CAC7DF280 for ; Fri, 18 Jan 2013 16:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754976Ab3ARQIQ (ORCPT ); Fri, 18 Jan 2013 11:08:16 -0500 Received: from mail-pb0-f43.google.com ([209.85.160.43]:62034 "EHLO mail-pb0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754412Ab3ARQIN (ORCPT ); Fri, 18 Jan 2013 11:08:13 -0500 Received: by mail-pb0-f43.google.com with SMTP id jt11so747592pbb.2 for ; Fri, 18 Jan 2013 08:08:12 -0800 (PST) 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=y4mBmj9wRjSK9QDXGYYc0JbNmeZTZ+gmMJWhFsngbnU=; b=yRdeqCwKtgbhz4Qh1pcqMwkXmWcfX/CB26G70gvWj5CocAehrGA9E7IvsCLHp1Aw5p Y11jcn2PvR3c4Swa82Us+755C9QPbe7SJz7u38oHW1Da6kDEhEVDmB2mVN64nz+aZfLx rnMyVnAE0GcPdkPp7jPnbuCBg21uFJ49YrZksyFXwCW+NzLYRwus4OV7IQ/Uz6U8dCv9 0F8cOUoeTy9P96cjE6UsOLiUn9gaaPe3IE+gbtShAMBbhPHL4RwBoOYOFl8xrIThKwRu WurUQg9ojdQTlQoXWdYI++NAfQYRpR5muCA9HDXDbqOEG9SIc5K0EaPlMreIadSKqIvt jSnQ== X-Received: by 10.68.137.234 with SMTP id ql10mr25339966pbb.158.1358525292916; Fri, 18 Jan 2013 08:08:12 -0800 (PST) Received: from localhost.localdomain ([120.197.109.98]) by mx.google.com with ESMTPS id ux4sm3320742pbc.25.2013.01.18.08.08.08 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jan 2013 08:08:12 -0800 (PST) From: Jiang Liu To: "Rafael J . Wysocki" , Bjorn Helgaas Cc: Jiang Liu , Yinghai Lu , Kenji Kaneshige , Yijing Wang , Jiang Liu , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Greg Kroah-Hartman , ACPI Devel Maling List , Toshi Kani , Myron Stowe Subject: [RFC PATCH v5 3/8] PCI: add a blocking notifier chain for PCI bus addition/removal Date: Sat, 19 Jan 2013 00:07:41 +0800 Message-Id: <1358525267-14268-4-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1358525267-14268-1-git-send-email-jiang.liu@huawei.com> References: <1358525267-14268-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 When adding/removing a PCI bus, some other components want to be notified so they could update their states. For example, the pci_slot driver needs to create/destroy PCI slots attaching to the PCI bus. So introduce a dedicate blocking notifier chain for PCI bus addition/removal events. It could be extended to support PCI device addition/removal events in the future when needed. Signed-off-by: Jiang Liu --- drivers/pci/bus.c | 24 ++++++++++++++++++++++++ drivers/pci/pci.h | 1 + drivers/pci/probe.c | 2 ++ drivers/pci/remove.c | 1 + include/linux/pci.h | 12 ++++++++++++ 5 files changed, 40 insertions(+) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 4c843cd..8bbd3f2 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -13,11 +13,33 @@ #include #include #include +#include #include #include #include "pci.h" +static BLOCKING_NOTIFIER_HEAD(pci_bus_notifier_chain); + +int pci_bus_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&pci_bus_notifier_chain, nb); +} + +int pci_bus_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&pci_bus_notifier_chain, nb); +} + +void pci_bus_call_notifier(struct pci_bus *bus, unsigned long code) +{ + int ret; + + ret = blocking_notifier_call_chain(&pci_bus_notifier_chain, + code, bus); + WARN_ON(ret != NOTIFY_DONE && ret != NOTIFY_OK); +} + void pci_add_resource_offset(struct list_head *resources, struct resource *res, resource_size_t offset) { @@ -197,6 +219,8 @@ int pci_bus_add_child(struct pci_bus *bus) if (retval) return retval; + pci_bus_call_notifier(bus, PCI_NOTIFY_POST_BUS_ADD); + bus->is_added = 1; /* Create legacy_io and legacy_mem files for this bus */ diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 7414094..988e4b4 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -208,6 +208,7 @@ extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, extern int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type); extern int pci_bus_add_child(struct pci_bus *bus); +extern void pci_bus_call_notifier(struct pci_bus *bus, unsigned long code); extern void pci_enable_ari(struct pci_dev *dev); /** * pci_ari_enabled - query ARI forwarding status diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index adb77c6..7db6528 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1679,6 +1679,8 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, if (error) goto class_dev_reg_err; + pci_bus_call_notifier(b, PCI_NOTIFY_POST_BUS_ADD); + /* Create legacy_io and legacy_mem files for this bus */ pci_create_legacy_files(b); diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 0d03026..2d8fbc8 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -50,6 +50,7 @@ void pci_remove_bus(struct pci_bus *bus) up_write(&pci_bus_sem); if (bus->is_added) { pci_remove_legacy_files(bus); + pci_bus_call_notifier(bus, PCI_NOTIFY_PRE_BUS_DEL); device_del(&bus->dev); } put_device(&bus->dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index ee21795..12e5447 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1033,6 +1033,18 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass); +/* + * All notifiers below get called with the target struct pci_bus *bus as + * an argument. + * Note: all PCI bus notifier must return success. Currently there's no + * error handling if any notifier returns error code. + */ +#define PCI_NOTIFY_POST_BUS_ADD 0x00000001 /* PCI bus has been added */ +#define PCI_NOTIFY_PRE_BUS_DEL 0x00000002 /* PCI bus will be deleted */ + +int pci_bus_register_notifier(struct notifier_block *nb); +int pci_bus_unregister_notifier(struct notifier_block *nb); + void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), void *userdata); int pci_cfg_space_size_ext(struct pci_dev *dev);