From: Jiang Liu <liuj97@gmail.com>
To: "Rafael J . Wysocki" <rjw@sisk.pl>, Bjorn Helgaas <bhelgaas@google.com>
Cc: Jiang Liu <jiang.liu@huawei.com>, Yinghai Lu <yinghai@kernel.org>,
Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
Yijing Wang <wangyijing@huawei.com>, Jiang Liu <liuj97@gmail.com>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
Toshi Kani <toshi.kani@hp.com>,
Myron Stowe <myron.stowe@redhat.com>
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 [thread overview]
Message-ID: <1358525267-14268-4-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1358525267-14268-1-git-send-email-jiang.liu@huawei.com>
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 <jiang.liu@huawei.com>
---
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 <linux/errno.h>
#include <linux/ioport.h>
#include <linux/proc_fs.h>
+#include <linux/notifier.h>
#include <linux/init.h>
#include <linux/slab.h>
#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);
--
1.7.9.5
next prev parent reply other threads:[~2013-01-18 16:07 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-18 16:07 [RFC PATCH v5 0/8] introduce PCI bus notifier chain to get rid of the ACPI PCI subdriver interfaces Jiang Liu
2013-01-18 16:07 ` [RFC PATCH v5 1/8] PCI: make PCI device create/destroy logic symmetric Jiang Liu
2013-01-20 23:35 ` Rafael J. Wysocki
2013-01-18 16:07 ` [RFC PATCH v5 2/8] PCI: split registration of PCI bus devices into two stages Jiang Liu
2013-01-18 16:07 ` Jiang Liu [this message]
2013-01-20 23:54 ` [RFC PATCH v5 3/8] PCI: add a blocking notifier chain for PCI bus addition/removal Rafael J. Wysocki
2013-01-21 16:18 ` Jiang Liu
2013-01-21 22:46 ` Rafael J. Wysocki
2013-01-18 16:07 ` [RFC PATCH v5 4/8] ACPI, PCI: avoid building pci_slot as module Jiang Liu
2013-01-21 0:01 ` Rafael J. Wysocki
2013-01-28 21:09 ` Bjorn Helgaas
2013-01-28 21:29 ` Yinghai Lu
2013-01-28 21:52 ` Bjorn Helgaas
2013-01-28 22:00 ` Yinghai Lu
2013-01-28 22:14 ` Bjorn Helgaas
2013-01-28 22:58 ` Yinghai Lu
2013-01-29 2:07 ` Jiang Liu
2013-01-29 2:21 ` Yinghai Lu
2013-01-29 2:45 ` Jiang Liu
2013-01-29 2:50 ` Bjorn Helgaas
2013-01-29 4:36 ` Matthew Garrett
2013-01-29 4:36 ` Matthew Garrett
2013-01-29 1:00 ` Rafael J. Wysocki
2013-02-03 20:18 ` Rafael J. Wysocki
2013-02-03 20:58 ` Bjorn Helgaas
2013-02-03 22:47 ` Myron Stowe
2013-02-03 23:38 ` Rafael J. Wysocki
2013-01-18 16:07 ` [RFC PATCH v5 5/8] PCI, ACPI: hook PCI bus notifications to create/destroy PCI slots Jiang Liu
2013-01-21 0:05 ` Rafael J. Wysocki
2013-01-18 16:07 ` [RFC PATCH v5 6/8] pci_slot: replace printk(KERN_xxx) with pr_xxx() Jiang Liu
2013-01-18 16:07 ` [RFC PATCH v5 7/8] PCI/PCIe: add "pci=nopciehp" to disable PCIe native hotplug Jiang Liu
2013-01-18 17:35 ` Bjorn Helgaas
2013-01-18 17:50 ` Yinghai Lu
2013-01-18 22:08 ` Rafael J. Wysocki
2013-01-22 16:19 ` Jiang Liu
2013-01-18 22:01 ` Rafael J. Wysocki
2013-01-19 1:56 ` Yijing Wang
2013-01-19 14:51 ` Greg Kroah-Hartman
2013-01-18 16:07 ` [RFC PATCH v5 8/8] PCI/PCIe: only claim PME from firmware when CONFIG_PCIE_PME is enabled Jiang Liu
2013-01-20 23:43 ` Rafael J. Wysocki
2013-01-21 17:06 ` Jiang Liu
2013-01-28 20:56 ` [RFC PATCH v5 0/8] introduce PCI bus notifier chain to get rid of the ACPI PCI subdriver interfaces Bjorn Helgaas
2013-01-29 0:34 ` Rafael J. Wysocki
2013-01-29 2:04 ` Jiang Liu
2013-02-01 16:13 ` Jiang Liu
2013-02-01 22:52 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1358525267-14268-4-git-send-email-jiang.liu@huawei.com \
--to=liuj97@gmail.com \
--cc=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jiang.liu@huawei.com \
--cc=kaneshige.kenji@jp.fujitsu.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=myron.stowe@redhat.com \
--cc=rjw@sisk.pl \
--cc=toshi.kani@hp.com \
--cc=wangyijing@huawei.com \
--cc=yinghai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).