PCI, ACPI: pci root bus hotplug support - part5
Subsystems (3)
cover PCI, ACPI: pci root bus hotplug support - part5
This part is to make sure ioapic and dmar handling sequence.
aka need to start driver for ioapic and dmar before regular pci device drivers. and need to stop dmar and ioapic driver after pci device drivers.
user acpi_pci_driver to start and stop ioapic and dmar driver.
could get from
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-root-bus-hotplug-part5
Jiang Liu (3):
ACPI, PCI: Use normal list for struct acpi_pci_driver ACPI, PCI: Notify acpi_pci_drivers when hot-plugging PCI root bridges ACPI, PCI: Protect global lists in drivers/acpi/pci_root.c
Yinghai Lu (4):
ACPI, PCI: Stop pci devices before acpi_pci_driver remove calling
PCI: Set dev_node early for pci_dev
PCI, x86: Move pci_enable_bridges() down
ACPI, PCI: Skip extra pci_enable_bridges for non hot-add root
drivers/acpi/pci_root.c | 121 +++++++++++++++++++++++++++----------------- drivers/acpi/pci_root_hp.c | 1 + drivers/pci/probe.c | 2 + drivers/pci/setup-bus.c | 2 - include/acpi/acpi_bus.h | 1 + include/linux/acpi.h | 2 +- 6 files changed, 79 insertions(+), 50 deletions(-)
Signature · 1 line
1.7.7
PATCH 1/7 ACPI, PCI: Use normal list for struct acpi_pci_driver
From: Jiang Liu <[email protected]>
Use normal list for struct acpi_pci_driver to simplify code.
--- drivers/acpi/pci_root.c | 16 +++------------- include/linux/acpi.h | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-)
drivers/acpi/pci_root.c +3 -13
@@ -72,8 +72,8 @@ static struct acpi_driver acpi_pci_root_driver = { };static LIST_HEAD (acpi_pci_roots); +static LIST_HEAD (acpi_pci_drivers); -static struct acpi_pci_driver *sub_driver;static DEFINE_MUTEX (osc_lock);int acpi_pci_register_driver (struct acpi_pci_driver *driver)
@@ -81,10 +81,7 @@ int acpi_pci_register_driver(struct acpi_pci_driver *driver)int n =0 ;struct acpi_pci_root *root; -struct acpi_pci_driver **pptr = &sub_driver; -while (*pptr) - pptr = &(*pptr)->next; - *pptr = driver; +list_add_tail (&driver->node, &acpi_pci_drivers);if (!driver->add)return 0 ;
@@ -103,14 +100,7 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver) {struct acpi_pci_root *root; -struct acpi_pci_driver **pptr = &sub_driver; -while (*pptr) { -if (*pptr == driver) -break ; - pptr = &(*pptr)->next; - } -BUG_ON (!*pptr); - *pptr = (*pptr)->next; +list_del (&driver->node);if (!driver->remove)return ;
include/linux/acpi.h +1 -1
@@ -138,7 +138,7 @@ void acpi_penalize_isa_irq(int irq, int active);void acpi_pci_irq_disable (struct pci_dev *dev);struct acpi_pci_driver { -struct acpi_pci_driver *next; +struct list_head node;int (*add)(acpi_handle handle);void (*remove)(acpi_handle handle); };
Signature · 1 line
1.7.7
PATCH 2/7 ACPI, PCI: Notify acpi_pci_drivers when hot-plugging PCI root bridges
In reply to Yinghai LuFrom: Jiang Liu <[email protected]>
When hot-plugging PCI root bridge, acpi_pci_drivers' add()/remove() methods should be invoked to notify registered drivers.
-v2: Move add calling to acpi_pci_root_start by Yinghai
--- drivers/acpi/pci_root.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/acpi/pci_root.c +11 -0
@@ -626,14 +626,25 @@ end:static int acpi_pci_root_start (struct acpi_device *device) {struct acpi_pci_root *root =acpi_driver_data (device); +struct acpi_pci_driver *driver; + +list_for_each_entry (driver, &acpi_pci_drivers, node) +if (driver->add) + driver->add (device->handle);pci_bus_add_devices (root->bus); +return 0 ; }static int acpi_pci_root_remove (struct acpi_device *device,int type) {struct acpi_pci_root *root =acpi_driver_data (device); +struct acpi_pci_driver *driver; + +list_for_each_entry (driver, &acpi_pci_drivers, node) +if (driver->remove) + driver->remove (root->device->handle);/* that root bus could be removed already */ if (!pci_find_bus (root->segment, root->secondary.start)) {
Signature · 1 line
1.7.7
PATCH 3/7 ACPI, PCI: Protect global lists in drivers/acpi/pci_root.c
In reply to Yinghai LuFrom: Jiang Liu <[email protected]>
There are two global lists inf file drivers/acpi/pci_root.c. One is for registered acpi_pci_drivers, the other is for enumerated ACPI PCI root bridge objects. These two global lists may change dynamically when registering/deregistering acpi_pci_drivers or adding/removing ACPI PCI root bridge objects. So protect them by mutex lock and RCU list.
--- drivers/acpi/pci_root.c | 87 ++++++++++++++++++++++++++++------------------ 1 files changed, 53 insertions(+), 34 deletions(-)
drivers/acpi/pci_root.c +53 -34
@@ -27,7 +27,8 @@#include <linux/module.h> #include <linux/init.h> #include <linux/types.h> -#include <linux/spinlock.h> +#include <linux/mutex.h> +#include <linux/rculist.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/pci.h>
@@ -71,6 +72,8 @@ static struct acpi_driver acpi_pci_root_driver = { }, }; +/* Lock to protect both acpi_pci_roots and acpi_pci_drivers lists */ +static DEFINE_MUTEX (acpi_pci_root_lock);static LIST_HEAD (acpi_pci_roots);static LIST_HEAD (acpi_pci_drivers);
@@ -81,47 +84,48 @@ int acpi_pci_register_driver(struct acpi_pci_driver *driver)int n =0 ;struct acpi_pci_root *root; +mutex_lock (&acpi_pci_root_lock);list_add_tail (&driver->node, &acpi_pci_drivers); - -if (!driver->add) -return 0 ; - -list_for_each_entry (root, &acpi_pci_roots, node) { - driver->add (root->device->handle); - n++; - } +if (driver->add) +list_for_each_entry_rcu (root, &acpi_pci_roots, node) { + driver->add (root->device->handle); + n++; + } +mutex_unlock (&acpi_pci_root_lock);return n; } -EXPORT_SYMBOL (acpi_pci_register_driver);void acpi_pci_unregister_driver (struct acpi_pci_driver *driver) {struct acpi_pci_root *root; +mutex_lock (&acpi_pci_root_lock);list_del (&driver->node); - -if (!driver->remove) -return ; - -list_for_each_entry (root, &acpi_pci_roots, node) - driver->remove (root->device->handle); +if (driver->remove) +list_for_each_entry_rcu (root, &acpi_pci_roots, node) + driver->remove (root->device->handle); +mutex_unlock (&acpi_pci_root_lock); } -EXPORT_SYMBOL (acpi_pci_unregister_driver);acpi_handle acpi_get_pci_rootbridge_handle (unsigned int seg,unsigned int bus) {struct acpi_pci_root *root; +struct acpi_handle *handle =NULL ; -list_for_each_entry (root, &acpi_pci_roots, node) +rcu_read_lock (); +list_for_each_entry_rcu (root, &acpi_pci_roots, node)if ((root->segment == (u16 ) seg) && - (root->secondary.start == (u16 ) bus)) -return root->device->handle; -return NULL ; -} + (root->secondary.start == (u16 ) bus)) { + handle = root->device->handle; +break ; + } +rcu_read_unlock (); +return handle; +}EXPORT_SYMBOL_GPL (acpi_get_pci_rootbridge_handle);/**
@@ -268,10 +272,15 @@ struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle) {struct acpi_pci_root *root; -list_for_each_entry (root, &acpi_pci_roots, node) { -if (root->device->handle == handle) +rcu_read_lock (); +list_for_each_entry_rcu (root, &acpi_pci_roots, node) { +if (root->device->handle == handle) { +rcu_read_unlock ();return root; + } } +rcu_read_unlock (); +return NULL ; }EXPORT_SYMBOL_GPL (acpi_pci_find_root);
@@ -459,7 +468,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)if (ACPI_FAILURE (status) && status !=AE_NOT_FOUND ) { printk(KERN_ERR PREFIX "can't evaluate _SEG\n"); result = -ENODEV ; - goto end; + goto out_free; }/* Check _CRS first, then _BBN. If no _BBN, default to zero. */
@@ -484,7 +493,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)else { printk(KERN_ERR PREFIX "can't evaluate _BBN\n"); result = -ENODEV ; - goto end; + goto out_free; } }
@@ -508,8 +517,8 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)* TBD: Need PCI interface for enumeration/configuration of roots. */ -/* TBD: Locking */ -list_add_tail (&root->node, &acpi_pci_roots); +mutex_lock (&acpi_pci_root_lock); +list_add_tail_rcu (&root->node, &acpi_pci_roots); printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n", acpi_device_name(device), acpi_device_bid(device),
@@ -528,7 +537,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)"Bus %04x:%02x not present in PCI namespace\n" , root->segment, (unsigned int)root->secondary.start); result = -ENODEV ; - goto end; + goto out_del_root; }/*
@@ -538,7 +547,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)*/ result =acpi_pci_bind_root (device);if (result) - goto end; + goto out_del_root;/* * PCI Routing Table
@@ -614,11 +623,15 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)if (device->wakeup.flags.run_wake)device_set_run_wake (root->bus->bridge, true); +mutex_unlock (&acpi_pci_root_lock); +return 0 ; -end: -if (!list_empty (&root->node)) -list_del (&root->node); +out_del_root: +list_del_rcu (&root->node); +mutex_unlock (&acpi_pci_root_lock); +synchronize_rcu (); +out_free:kfree (root);return result; }
@@ -628,11 +641,13 @@ static int acpi_pci_root_start(struct acpi_device *device)struct acpi_pci_root *root =acpi_driver_data (device);struct acpi_pci_driver *driver; +mutex_lock (&acpi_pci_root_lock);list_for_each_entry (driver, &acpi_pci_drivers, node)if (driver->add) driver->add (device->handle);pci_bus_add_devices (root->bus); +mutex_unlock (&acpi_pci_root_lock);return 0 ; }
@@ -642,6 +657,8 @@ static int acpi_pci_root_remove(struct acpi_device *device, int type)struct acpi_pci_root *root =acpi_driver_data (device);struct acpi_pci_driver *driver; +mutex_lock (&acpi_pci_root_lock); +list_for_each_entry (driver, &acpi_pci_drivers, node)if (driver->remove) driver->remove (root->device->handle);
@@ -661,7 +678,9 @@ static int acpi_pci_root_remove(struct acpi_device *device, int type)pci_stop_and_remove_bus (root->bus); out: -list_del (&root->node); +list_del_rcu (&root->node); +mutex_unlock (&acpi_pci_root_lock); +synchronize_rcu ();kfree (root);return 0 ;
Signature · 1 line
1.7.7
PATCH 4/7 ACPI, PCI: Stop pci devices before acpi_pci_driver remove calling
In reply to Yinghai LuDuring stop pci drivers, it still need to access ioapic and iommu. So need to make sure those drivers need to be stop at first.
Also change the acpi_pci_drivers remove calling sequence to reverse.
--- drivers/acpi/pci_root.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/acpi/pci_root.c +7 -4
@@ -659,10 +659,6 @@ static int acpi_pci_root_remove(struct acpi_device *device, int type)mutex_lock (&acpi_pci_root_lock); -list_for_each_entry (driver, &acpi_pci_drivers, node) -if (driver->remove) - driver->remove (root->device->handle); -/* that root bus could be removed already */ if (!pci_find_bus (root->segment, root->secondary.start)) { dev_printk(KERN_DEBUG, &device->dev,
@@ -670,6 +666,13 @@ static int acpi_pci_root_remove(struct acpi_device *device, int type) goto out; } +/* stop normal pci drivers before we stop ioapic and dmar etc */ +pci_stop_bus_devices (root->bus); + +list_for_each_entry_reverse (driver, &acpi_pci_drivers, node) +if (driver->remove) + driver->remove (root->device->handle); +device_set_run_wake (root->bus->bridge, false);pci_acpi_remove_bus_pm_notifier (device);
Signature · 1 line
1.7.7
PATCH 5/7 PCI: Set dev_node early for pci_dev
In reply to Yinghai Luotherwise irq_desc for pci bridge with hot-added ioapic can not be on local node.
--- drivers/pci/probe.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/pci/probe.c +1 -0
@@ -1293,6 +1293,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) dev->dev.release = pci_release_dev;pci_dev_get (dev); +set_dev_node (&dev->dev,pcibus_to_node (bus)); dev->dev.dma_mask = &dev->dma_mask; dev->dev.dma_parms = &dev->dma_parms; dev->dev.coherent_dma_mask =0xffffffffull ;
Signature · 1 line
1.7.7
PATCH 6/7 PCI, x86: Move pci_enable_bridges() down
In reply to Yinghai LuAfter we get hot-added ioapic registered.
pci_enable_bridges will try to enable ioapic irq for pci bridge.
So need to move it down.
Or We can move out pcibios_enable_irq() out of pci_enable_device() and call pcibios_enable_irq in pci_bus_add_devices ? also will need to move ...
pcibios_resource_survey_bus(root->bus);
pci_assign_unassigned_bus_resources(root->bus);to the start add ....
--- drivers/acpi/pci_root.c | 3 +++ drivers/pci/probe.c | 1 + drivers/pci/setup-bus.c | 2 -- 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/pci_root.c +3 -0
@@ -646,6 +646,9 @@ static int acpi_pci_root_start(struct acpi_device *device)if (driver->add) driver->add (device->handle); +/* need to after hot-added ioapic is registered */ +pci_enable_bridges (root->bus); +pci_bus_add_devices (root->bus);mutex_unlock (&acpi_pci_root_lock);
drivers/pci/probe.c +1 -0
@@ -1909,6 +1909,7 @@ unsigned int __ref pci_rescan_bus(struct pci_bus *bus) max =pci_scan_child_bus (bus);pci_assign_unassigned_bus_resources (bus); +pci_enable_bridges (bus);pci_bus_add_devices (bus);return max;
drivers/pci/setup-bus.c +0 -2
@@ -1527,6 +1527,4 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)up_read (&pci_bus_sem);__pci_bus_assign_resources (bus, &add_list,NULL );BUG_ON (!list_empty (&add_list)); - -pci_enable_bridges (bus); }
Signature · 1 line
1.7.7
PATCH 7/7 ACPI, PCI: Skip extra pci_enable_bridges for non hot-add root
In reply to Yinghai LuPre-installed will be handled later, need to skip the one only for hot-added roots.
Otherwise will get anonying failing message about can not reserve, irq ...
--- drivers/acpi/pci_root.c | 3 ++- drivers/acpi/pci_root_hp.c | 1 + include/acpi/acpi_bus.h | 1 + 3 files changed, 4 insertions(+), 1 deletions(-)
drivers/acpi/pci_root.c +2 -1
@@ -647,7 +647,8 @@ static int acpi_pci_root_start(struct acpi_device *device) driver->add (device->handle);/* need to after hot-added ioapic is registered */ -pci_enable_bridges (root->bus); +if (root->hot_added) +pci_enable_bridges (root->bus);pci_bus_add_devices (root->bus);mutex_unlock (&acpi_pci_root_lock);
drivers/acpi/pci_root_hp.c +1 -0
@@ -86,6 +86,7 @@ static void acpi_root_configure_bridge(acpi_handle handle)pcibios_resource_survey_bus (root->bus);pci_assign_unassigned_bus_resources (root->bus); + root->hot_added = true; }static void handle_root_bridge_insertion (acpi_handle handle)
include/acpi/acpi_bus.h +1 -0
@@ -406,6 +406,7 @@ struct acpi_pci_root {u32 osc_support_set;/* _OSC state of support bits */ u32 osc_control_set;/* _OSC state of control bits */ +bool hot_added;phys_addr_t mcfg_addr; };
Signature · 1 line
1.7.7