ACPI based root bridge hot-add
Subsystems (4)
cover ACPI based root bridge hot-add
Here is a series of patches to support ACPI hot-add of a root bridge hierarchy. The added hierarchy may contain other p2p bridges and end/leaf I/O devices too. The root bridge itself is assumed to have been assigned resource ranges, but the p2p bridges and end devices are not required to be initialized by firmware. Most of the code changes are to make the existing code flows suitable for such a hierarchy of bridges & devices.
This code supports hot-add on ia64 only for now.It does not yet support I/O APIC hot-add, which is needed to make this fully functional. The patches are against 2.6.11-mm4 (plus the patch needed for ia64 to boot). I've tested to make sure this does not break end/leaf device hotplug on the hotplug capable ia64 box I have.
Thanks,
Rajesh
PATCH 1/12 ACPI based root bridge hot-add
When you hot-plug a (root) bridge hierarchy, it may have p2p bridges and devices attached to it that have not been configured by firmware. In this case, we need to configure the devices before starting them. This patch separates device start from device scan so that we can introduce the configuration step in the middle.
I kept the existing semantics for pci_scan_bus() since there are a huge number of callers to that function.
Also, I have no way of testing the changes I made to the parisc files, so this needs review by those folks. Sorry for the massive cross-post, this touches files in many different places.
---
linux-2.6.11-mm4-iohp-rshah1/arch/i386/pci/common.c | 2 - linux-2.6.11-mm4-iohp-rshah1/arch/i386/pci/legacy.c | 2 + linux-2.6.11-mm4-iohp-rshah1/arch/i386/pci/numa.c | 2 + linux-2.6.11-mm4-iohp-rshah1/arch/ia64/pci/pci.c | 2 - linux-2.6.11-mm4-iohp-rshah1/drivers/acpi/pci_bind.c | 16 +++++++++++- linux-2.6.11-mm4-iohp-rshah1/drivers/acpi/pci_root.c | 24 +++++++++++++++++- linux-2.6.11-mm4-iohp-rshah1/drivers/parisc/dino.c | 1 linux-2.6.11-mm4-iohp-rshah1/drivers/parisc/lba_pci.c | 2 + linux-2.6.11-mm4-iohp-rshah1/drivers/pci/probe.c | 2 - linux-2.6.11-mm4-iohp-rshah1/include/linux/pci.h | 8 ++++-- 10 files changed, 53 insertions(+), 8 deletions(-)
arch/i386/pci/common.c renamed from arch/i386/pci/common.c~pci_serparate_device_add +1 -1
@@ -133,7 +133,7 @@ struct pci_bus * __devinit pcibios_scan_printk ("PCI: Probing PCI hardware (bus %02x)\n" , busnum); -return pci_scan_bus (busnum, &pci_root_ops,NULL ); +return pci_scan_bus_parented (NULL , busnum, &pci_root_ops,NULL ); }extern u8 pci_cache_line_size;
arch/i386/pci/legacy.c renamed from arch/i386/pci/legacy.c~pci_serparate_device_add +2 -0
@@ -45,6 +45,8 @@ static int __init pci_legacy_init(void)printk ("PCI: Probing PCI hardware\n" ); pci_root_bus =pcibios_scan_root (0 ); +if (pci_root_bus) +pci_bus_add_devices (pci_root_bus);pcibios_fixup_peer_bridges ();
arch/i386/pci/numa.c renamed from arch/i386/pci/numa.c~pci_serparate_device_add +2 -0
@@ -115,6 +115,8 @@ static int __init pci_numa_init(void)return 0 ; pci_root_bus =pcibios_scan_root (0 ); +if (pci_root_bus) +pci_bus_add_devices (pci_root_bus);if (num_online_nodes () >1 )for_each_online_node (quad) {if (quad =0 )
arch/ia64/pci/pci.c renamed from arch/ia64/pci/pci.c~pci_serparate_device_add +1 -1
@@ -330,7 +330,7 @@ pci_acpi_scan_root(struct acpi_device *dacpi_walk_resources (device->handle,METHOD_NAME__CRS , add_window, &info); - pbus =pci_scan_bus (bus, &pci_root_ops, controller); + pbus =pci_scan_bus_parented (NULL , bus, &pci_root_ops, controller);if (pbus)pcibios_setup_root_windows (pbus, controller);
drivers/acpi/pci_bind.c renamed from drivers/acpi/pci_bind.c~pci_serparate_device_add +15 -1
@@ -129,6 +129,8 @@ acpi_pci_bind (char *pathname =NULL ;struct acpi_buffer buffer = {0 ,NULL };acpi_handle handle =NULL ; +struct pci_dev *dev; +struct pci_bus *bus;ACPI_FUNCTION_TRACE ("acpi_pci_bind" );
@@ -193,8 +195,20 @@ acpi_pci_bind (* Locate matching device in PCI namespace. If it doesn't exist * this typically means that the device isn't currently inserted * (e.g. docking station, port replicator, etc.). +* We cannot simply search the global pci device list, since +* PCI devices are added to the global pci list when the root +* bridge start ops are run, which may not have happened yet. */ - data->dev =pci_find_slot (data->id.bus,PCI_DEVFN (data->id.device, data->id.function)); + bus =pci_find_bus (data->id.segment, data->id.bus); +if (bus) { +list_for_each_entry (dev, &bus->devices, bus_list) { +if (dev->devfn =PCI_DEVFN (data->id.device, + data->id.function)) { + data->dev = dev; +break ; + } + } + }if (!data->dev) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
drivers/acpi/pci_root.c renamed from drivers/acpi/pci_root.c~pci_serparate_device_add +23 -1
@@ -46,6 +46,7 @@ ACPI_MODULE_NAME ("pci_root")static int acpi_pci_root_add (struct acpi_device *device);static int acpi_pci_root_remove (struct acpi_device *device,int type); +static int acpi_pci_root_start (struct acpi_device *device);static struct acpi_driver acpi_pci_root_driver = { .name =ACPI_PCI_ROOT_DRIVER_NAME ,
@@ -54,6 +55,7 @@ static struct acpi_driver acpi_pci_root_ .ops = { .add = acpi_pci_root_add, .remove = acpi_pci_root_remove, + .start = acpi_pci_root_start, }, };
@@ -169,6 +171,7 @@ acpi_pci_root_add (if (!root)return_VALUE (-ENOMEM );memset (root,0 ,sizeof (struct acpi_pci_root )); +INIT_LIST_HEAD (&root->node); root->handle = device->handle;strcpy (acpi_device_name (device),ACPI_PCI_ROOT_DEVICE_NAME );
@@ -298,12 +301,31 @@ acpi_pci_root_add ( root->id.bus); end: -if (result) +if (result) { +if (!list_empty (&root->node)) +list_del (&root->node);kfree (root); + }return_VALUE (result); } +static int +acpi_pci_root_start ( +struct acpi_device *device) +{ +struct acpi_pci_root *root; + +ACPI_FUNCTION_TRACE ("acpi_pci_root_start" ); + +list_for_each_entry (root, &acpi_pci_roots, node) { +if (root->handle = device->handle) { +pci_bus_add_devices (root->bus); +return_VALUE (0 ); + } + } +return_VALUE (-ENODEV ); +}static int acpi_pci_root_remove (
drivers/parisc/dino.c renamed from drivers/parisc/dino.c~pci_serparate_device_add +1 -0
@@ -993,6 +993,7 @@ dino_driver_callback(struct parisc_devic bus =pci_scan_bus_parented (&dev->dev, dino_current_bus, &dino_cfg_ops,NULL );if (bus) { +pci_bus_add_devices (bus);/* This code *depends* on scanning being single threaded * if it isn't, this global bus number count will fail */
drivers/parisc/lba_pci.c renamed from drivers/parisc/lba_pci.c~pci_serparate_device_add +2 -0
@@ -1570,6 +1570,8 @@ lba_driver_probe(struct parisc_device *d lba_bus = lba_dev->hba.hba_bus pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start, cfg_ops,NULL ); +if (lba_bus) +pci_bus_add_devices (lba_bus);/* This is in lieu of calling pci_assign_unassigned_resources() */ if (is_pdc_pat ()) {
drivers/pci/probe.c renamed from drivers/pci/probe.c~pci_serparate_device_add +0 -2
@@ -916,8 +916,6 @@ struct pci_bus * __devinit pci_scan_bus_ b->subordinate =pci_scan_child_bus (b); -pci_bus_add_devices (b); -return b; sys_create_link_err:
include/linux/pci.h renamed from include/linux/pci.h~pci_serparate_device_add +6 -2
@@ -732,16 +732,20 @@ void pcibios_update_irq(struct pci_dev */* Generic PCI functions used internally */ extern struct pci_bus *pci_find_bus (int domain,int busnr); +void pci_bus_add_devices (struct pci_bus *bus);struct pci_bus *pci_scan_bus_parented (struct device *parent,int bus,struct pci_ops *ops,void *sysdata);static inline struct pci_bus *pci_scan_bus (int bus,struct pci_ops *ops,void *sysdata) { -return pci_scan_bus_parented (NULL , bus, ops, sysdata); +struct pci_bus *root_bus; + root_bus =pci_scan_bus_parented (NULL , bus, ops, sysdata); +if (root_bus) +pci_bus_add_devices (root_bus); +return root_bus; }int pci_scan_slot (struct pci_bus *bus,int devfn);struct pci_dev *pci_scan_single_device (struct pci_bus *bus,int devfn);unsigned int pci_scan_child_bus (struct pci_bus *bus);void pci_bus_add_device (struct pci_dev *dev); -void pci_bus_add_devices (struct pci_bus *bus);void pci_name_device (struct pci_dev *dev);char *pci_class_name (u32 class);void pci_read_bridge_bases (struct pci_bus *child);
_
PATCH 2/12 Fix pci_enable_device() for p2p bridges
In reply to Rajesh ShahWhen checking if a PCI to PCI bridge should be enabled to decode memory and/or IO resources, we need to look at all device resources not just the first 6. This is needed to allow PCI bridges to pass down memory and IO accesses to child devices even when the bridge itself does not consume resources in its PCI BARs.
---
linux-2.6.11-mm4-iohp-rshah1/arch/ia64/pci/pci.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
arch/ia64/pci/pci.c renamed from arch/ia64/pci/pci.c~fix-ia64-pcibios_enable_resources +7 -3
@@ -436,18 +436,24 @@ pcibios_enable_resources (struct pci_devu16 cmd, old_cmd;int idx;struct resource *r; +unsigned long type_mask =IORESOURCE_IO |IORESOURCE_MEM ;if (!dev)return -EINVAL ;pci_read_config_word (dev,PCI_COMMAND , &cmd); old_cmd = cmd; -for (idx=0 ; idx<6 ; idx++) { +for (idx=0 ; idx<PCI_NUM_RESOURCES ; idx++) {/* Only set up the desired resources. */ if (!(mask & (1 << idx)))continue ; r = &dev->resource[idx]; +if (!(r->flags & type_mask)) +continue ; +if ((idx ==PCI_ROM_RESOURCE ) && + (!(r->flags &IORESOURCE_ROM_ENABLE ))) +continue ;if (!r->start && r->end) { printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n",
@@ -459,8 +465,6 @@ pcibios_enable_resources (struct pci_devif (r->flags &IORESOURCE_MEM ) cmd |=PCI_COMMAND_MEMORY ; } -if (dev->resource[PCI_ROM_RESOURCE ].start) - cmd |=PCI_COMMAND_MEMORY ;if (cmd != old_cmd) {printk ("PCI: Enabling device %s (%04x -> %04x)\n" ,pci_name (dev), old_cmd, cmd);pci_write_config_word (dev,PCI_COMMAND , cmd);
_
PATCH 3/12 Make pcibios_fixup_bus() hot-plug safe
In reply to Rajesh ShahPCI scan code calls the arch specific pcibios_fixup_bus() each time it scans a new bridge. For root bridge hot-plug, the bridge and it's attached devices may not have been configured properly yet, so it's not safe to claim those resources at this time.
This code goes away when we clean up the way pci resources are claimed (in pci_enable_device()), so this is only a stopgap fix.
---
linux-2.6.11-mm4-iohp-rshah1/arch/ia64/pci/pci.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletion(-)
arch/ia64/pci/pci.c renamed from arch/ia64/pci/pci.c~ia64-pcibios_fixup_bus-hotplug-safe +21 -1
@@ -391,6 +391,25 @@ void pcibios_bus_to_resource(struct pci_ res->end = region->end + offset; } +static int __devinit is_valid_resource (struct pci_dev *dev,int idx) +{ +unsigned int i, type_mask =IORESOURCE_IO |IORESOURCE_MEM ; +struct resource *devr = &dev->resource[idx]; + +if (!dev->bus) +return 0 ; +for (i=0 ; i<PCI_BUS_NUM_RESOURCES ; i++) { +struct resource *busr = dev->bus->resource[i]; + +if (!busr || ((busr->flags ^ devr->flags) & type_mask)) +continue ; +if ((devr->start) && (devr->start >= busr->start) && + (devr->end <= busr->end)) +return 1 ; + } +return 0 ; +} +static void __devinit pcibios_fixup_device_resources (struct pci_dev *dev) {struct pci_bus_region region;
@@ -404,7 +423,8 @@ static void __devinit pcibios_fixup_devi region.start = dev->resource[i].start; region.end = dev->resource[i].end;pcibios_bus_to_resource (dev, &dev->resource[i], ®ion); -pci_claim_resource (dev, i); +if ((is_valid_resource (dev, i))) +pci_claim_resource (dev, i); } }
_
PATCH 4/12 Prevent duplicate bus numbers when scanning PCI bridge
In reply to Rajesh ShahWhen hot-plugging a root bridge, as we try to assign bus numbers we may find that the hotplugged hieratchy has more PCI to PCI bridges (i.e. bus requirements) than available. Make sure we don't step over an existing bus when that happens.
---
linux-2.6.11-mm4-iohp-rshah1/drivers/pci/probe.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/pci/probe.c renamed from drivers/pci/probe.c~prevent_duplicate_busnr +10 -2
@@ -417,7 +417,7 @@ int __devinit pci_scan_bridge(struct pci {struct pci_bus *child;int is_cardbus = (dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ); -u32 buses; +u32 buses, i;u16 bctl;pci_read_config_dword (dev,PCI_PRIMARY_BUS , &buses);
@@ -476,6 +476,10 @@ int __devinit pci_scan_bridge(struct pci/* Clear errors */ pci_write_config_word (dev,PCI_STATUS ,0xffff ); +/* Prevent assigning a bus number that already exists. +* This can happen when a bridge is hot-plugged */ +if (pci_find_bus (pci_domain_nr (bus), max+1 )) +return max; child =pci_alloc_child_bus (bus, dev, ++max); buses = (buses &0xff000000 ) | ((unsigned int )(child->primary) <<0 )
@@ -507,7 +511,11 @@ int __devinit pci_scan_bridge(struct pci* as cards with a PCI-to-PCI bridge can be * inserted later. */ - max +=CARDBUS_RESERVE_BUSNR ; +for (i=0 ; i<CARDBUS_RESERVE_BUSNR ; i++) +if (pci_find_bus (pci_domain_nr (bus), + max+i+1 )) +break ; + max += i; }/* * Set the subordinate bus number to its real value.
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
PATCH 5/12 Take the PCI lock when modifying pci bus or device lists
In reply to Rajesh ShahWith root bridge and pci bridge hot-plug, new buses and devices can be added or removed at run time. Protect the pci bus and device lists with the pci lock when doing so.
---
linux-2.6.11-mm4-iohp-rshah1/drivers/pci/probe.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletion(-)
drivers/pci/probe.c renamed from drivers/pci/probe.c~lock-pci-root-bus-add +11 -1
@@ -8,6 +8,7 @@#include <linux/slab.h> #include <linux/module.h> #include <linux/cpumask.h> +#include "pci.h" #undef DEBUG
@@ -380,8 +381,11 @@ struct pci_bus * __devinit pci_add_new_bstruct pci_bus *child; child =pci_alloc_child_bus (parent, dev, busnr); -if (child) +if (child) { +spin_lock (&pci_bus_lock);list_add_tail (&child->node, &parent->children); +spin_unlock (&pci_bus_lock); + }return child; }
@@ -771,7 +775,9 @@ pci_scan_single_device(struct pci_bus *b* and the bus list for fixup functions, etc. */ INIT_LIST_HEAD (&dev->global_list); +spin_lock (&pci_bus_lock);list_add_tail (&dev->bus_list, &bus->devices); +spin_unlock (&pci_bus_lock);return dev; }
@@ -891,7 +897,9 @@ struct pci_bus * __devinit pci_scan_bus_DBG ("PCI: Bus %04x:%02x already known\n" ,pci_domain_nr (b), bus); goto err_out; } +spin_lock (&pci_bus_lock);list_add_tail (&b->node, &pci_root_buses); +spin_unlock (&pci_bus_lock);memset (dev,0 ,sizeof (*dev)); dev->parent = parent;
@@ -933,7 +941,9 @@ class_dev_create_file_err: class_dev_reg_err:device_unregister (dev); dev_reg_err: +spin_lock (&pci_bus_lock);list_del (&b->node); +spin_unlock (&pci_bus_lock); err_out:kfree (dev);kfree (b);
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
PATCH 6/12 Link newly created pci child bus to its parent on creation
In reply to Rajesh ShahWhen a pci child bus is created, add it to the parent's children list immediately rather than waiting till pci_bus_add_devices(). For hot-plug bridges/devices, pci_bus_add_devices() may be called much later, after they have been properly configured. In the meantime, this allows us to use the normal pci bus search functions for the hot-plug bridges/buses.
---
linux-2.6.11-mm4-iohp-rshah1/drivers/pci/bus.c | 11 +++++++---- linux-2.6.11-mm4-iohp-rshah1/drivers/pci/probe.c | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/pci/probe.c renamed from drivers/pci/probe.c~pci_link_child_bus +2 -2
@@ -457,7 +457,7 @@ int __devinit pci_scan_bridge(struct pcireturn max; } - child =pci_alloc_child_bus (bus, dev, busnr); + child =pci_add_new_bus (bus, dev, busnr);if (!child)return max; child->primary = buses &0xFF ;
@@ -484,7 +484,7 @@ int __devinit pci_scan_bridge(struct pci* This can happen when a bridge is hot-plugged */ if (pci_find_bus (pci_domain_nr (bus), max+1 ))return max; - child =pci_alloc_child_bus (bus, dev, ++max); + child =pci_add_new_bus (bus, dev, ++max); buses = (buses &0xff000000 ) | ((unsigned int )(child->primary) <<0 ) | ((unsigned int )(child->secondary) <<8 )
drivers/pci/bus.c renamed from drivers/pci/bus.c~pci_link_child_bus +7 -4
@@ -121,10 +121,13 @@ void __devinit pci_bus_add_devices(struc* If there is an unattached subordinate bus, attach * it and then scan for unattached PCI devices. */ -if (dev->subordinate &&list_empty (&dev->subordinate->node)) { -spin_lock (&pci_bus_lock); -list_add_tail (&dev->subordinate->node, &dev->bus->children); -spin_unlock (&pci_bus_lock); +if (dev->subordinate) { +if (list_empty (&dev->subordinate->node)) { +spin_lock (&pci_bus_lock); +list_add_tail (&dev->subordinate->node, + &dev->bus->children); +spin_unlock (&pci_bus_lock); + }pci_bus_add_devices (dev->subordinate);sysfs_create_link (&dev->subordinate->class_dev.kobj, &dev->dev.kobj,"bridge" );
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
A message that is not in the archive (sent off-list or not yet received): 20050318140922.F1145-39QZ/XbsZ5/mO6KZMuUCQVaTQe2KTcn/@public.gmane.org
Re: [patch 06/12] Link newly created pci child bus to its parent on creation
SGksCgpPbiBGcmlkYXkgMTggTWFyY2ggMjAwNSAxNzowOSwgUmFqZXNoIFNoYWggd3JvdGU6Cj4g K6CgoKCgoKCgoKCgoKCgoGlmIChkZXYtPnN1Ym9yZGluYXRlKSB7Cj4gK6CgoKCgoKCgoKCgoKCg oCCgIKAgoCBpZiAobGlzdF9lbXB0eSgmZGV2LT5zdWJvcmRpbmF0ZS0+bm9kZSkpIHsKPiAroKCg oKCgoKCgoKCgoKCgoKCgoKCgoKAgoCCgIKAgc3Bpbl9sb2NrKCZwY2lfYnVzX2xvY2spOwo+ICug oKCgoKCgoKCgoKCgoKCgoKCgoKCgoCCgIKAgoCBsaXN0X2FkZF90YWlsKCZkZXYtPnN1Ym9yZGlu YXRlLT5ub2RlLAo+ICugoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKAgoCCg IKAgJmRldi0+YnVzLT5jaGlsZHJlbik7Cj4gK6CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgIKAgoCCg IHNwaW5fdW5sb2NrKCZwY2lfYnVzX2xvY2spOwo+ICugoKCgoKCgoKCgoKCgoKAgoCCgIKAgfQoK U2hvdWxkJ250IHNwaW5fbG9jay91bmxvY2sgYmUgYXJvdW5kIGVudGlyZSAiaWYiIHN0YXRlbWVu dD8gbGlzdF9lbXB0eQpjb3VsZCBiZWNvbWUgZmFsc2UgYWZ0ZXIgaXQgd2FzIGNoZWNrbGVkIGJ1 dCBiZWZvcmUgc3BpbmxvY2sgd2FzIGFjcXVpcmVkLgoKLS0gCkRtaXRyeQo=
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
A message that is not in the archive (sent off-list or not yet received): 200503182300.12924.dtor_core-yWtbtysYrB+LZ21kGMrzwg@public.gmane.org
Re: [patch 06/12] Link newly created pci child bus to its parent on creation
T24gRnJpZGF5IDE4IE1hcmNoIDIwMDUgMjM6MDAsIERtaXRyeSBUb3Jva2hvdiB3cm90ZToKPiBI aSwKPiAKPiBPbiBGcmlkYXkgMTggTWFyY2ggMjAwNSAxNzowOSwgUmFqZXNoIFNoYWggd3JvdGU6 Cj4gPiAroKCgoKCgoKCgoKCgoKCgaWYgKGRldi0+c3Vib3JkaW5hdGUpIHsKPiA+ICugoKCgoKCg oKCgoKCgoKAgoCCgIKAgaWYgKGxpc3RfZW1wdHkoJmRldi0+c3Vib3JkaW5hdGUtPm5vZGUpKSB7 Cj4gPiAroKCgoKCgoKCgoKCgoKCgoKCgoKCgoKAgoCCgIKAgc3Bpbl9sb2NrKCZwY2lfYnVzX2xv Y2spOwo+ID4gK6CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgIKAgoCCgIGxpc3RfYWRkX3RhaWwoJmRl di0+c3Vib3JkaW5hdGUtPm5vZGUsCj4gPiAroKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCg oKCgoKCgoKCgIKAgoCCgICZkZXYtPmJ1cy0+Y2hpbGRyZW4pOwo+ID4gK6CgoKCgoKCgoKCgoKCg oKCgoKCgoKCgIKAgoCCgIHNwaW5fdW5sb2NrKCZwY2lfYnVzX2xvY2spOwo+ID4gK6CgoKCgoKCg oKCgoKCgoCCgIKAgoCB9Cj4gCj4gU2hvdWxkJ250IHNwaW5fbG9jay91bmxvY2sgYmUgYXJvdW5k IGVudGlyZSAiaWYiIHN0YXRlbWVudD8gbGlzdF9lbXB0eQo+IGNvdWxkIGJlY29tZSBmYWxzZSBh ZnRlciBpdCB3YXMgY2hlY2tsZWQgYnV0IGJlZm9yZSBzcGlubG9jayB3YXMgYWNxdWlyZWQuCgpT Y3JhdGNoIHRoYXQsIEkgbWlzcmVhZCB0aGUgY29kZSwgc29ycnkuCgotLSAKRG1pdHJ5Cg==
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
PATCH 7/12 Make the PCI remove routines safe for failed hot-plug
In reply to Rajesh ShahWhen a root bridge hierarchy is hot-plugged, resource requirements for the new devices may be greater than what the root bridge is decoding. In this case, we want to remove devices that did not get needed resources. These devices have been scanned into bus specific lists but not yet added to the global device list. Make sure the pci remove functions can handle this case.
---
linux-2.6.11-mm4-iohp-rshah1/drivers/pci/remove.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
drivers/pci/remove.c renamed from drivers/pci/remove.c~pci-remove-device-hotplug-safe +9 -5
@@ -26,17 +26,21 @@ static void pci_free_resources(struct pcstatic void pci_destroy_dev (struct pci_dev *dev) { -pci_proc_detach_device (dev); -pci_remove_sysfs_dev_files (dev); -device_unregister (&dev->dev); +if (!list_empty (&dev->global_list)) { +pci_proc_detach_device (dev); +pci_remove_sysfs_dev_files (dev); +device_unregister (&dev->dev); +spin_lock (&pci_bus_lock); +list_del (&dev->global_list); + dev->global_list.next = dev->global_list.prev =NULL ; +spin_unlock (&pci_bus_lock); + }/* Remove the device from the device lists, and prevent any further * list accesses from this device */ spin_lock (&pci_bus_lock);list_del (&dev->bus_list); -list_del (&dev->global_list); dev->bus_list.next = dev->bus_list.prev =NULL ; - dev->global_list.next = dev->global_list.prev =NULL ;spin_unlock (&pci_bus_lock);pci_free_resources (dev);
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
Re: [patch 07/12] Make the PCI remove routines safe for failed hot-plug
Quoted 20 lines · Rajesh Shah
diff -puN
drivers/pci/remove.c~pci-remove-device-hotplug-safedrivers/pci/remove.cdrivers/pci/remove.c renamed from drivers/pci/remove.c~pci-remove-device-hotplug-safe +9
-3@@ -26,17 +26,21 @@ static void pci_free_resources(struct pcstatic void pci_destroy_dev (struct pci_dev *dev) { -pci_proc_detach_device (dev); -pci_remove_sysfs_dev_files (dev); -device_unregister (&dev->dev); +if (!list_empty (&dev->global_list)) { +pci_proc_detach_device (dev); +pci_remove_sysfs_dev_files (dev); +device_unregister (&dev->dev); +spin_lock (&pci_bus_lock); +list_del (&dev->global_list); + dev->global_list.next = dev->global_list.prev =NULL ; +spin_unlock (&pci_bus_lock); + }
drivers/pci/remove.c static void pci_free_resources(struct pc · line 46
Quoted 10 lines
drivers/pci/remove.c renamed from drivers/pci/remove.c~pci-remove-device-hotplug-safe +0
-2/* Remove the device from the device lists, and prevent any further * list accesses from this device */ spin_lock (&pci_bus_lock);list_del (&dev->bus_list); -list_del (&dev->global_list); dev->bus_list.next = dev->bus_list.prev =NULL ; - dev->global_list.next = dev->global_list.prev =NULL ;spin_unlock (&pci_bus_lock);pci_free_resources (dev);
I did have a comment about this code at first glance, but in reviewing it again, nevermind, it looks fine...
thanks,
greg k-h
PATCH 8/12 Remove hot-plugged devices that could not be allocated resources
In reply to Rajesh ShahWhen hot-plugging an I/O hierarchy that contains many bridges and leaf devices, it's possible that there are not enough resources to start all the device present. If we fail to assign a resource, clear the corresponding value in the pci_dev structure, so other code can take corrective action.
---
linux-2.6.11-mm4-iohp-rshah1/drivers/pci/setup-bus.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c renamed from drivers/pci/setup-bus.c~discard_no_resource_devs +4 -1
@@ -72,7 +72,10 @@ pbus_assign_resources_sorted(struct pci_for (list = head.next; list;) { res = list->res; idx = res - &list->dev->resource[0 ]; -pci_assign_resource (list->dev, idx); +if (pci_assign_resource (list->dev, idx)) { + res->start =0 ; + res->flags =0 ; + } tmp = list; list = list->next;kfree (tmp);
_
PATCH 9/12 Read bridge resources when fixing up the bus
In reply to Rajesh ShahRead bridge io/mem/pfmem ranges when fixing up the bus so that bus resources are tracked. This is required to properly support pci end device and bridge hotplug.
---
linux-2.6.11-mm4-iohp-rshah1/arch/ia64/pci/pci.c | 4 ++++ 1 files changed, 4 insertions(+)
arch/ia64/pci/pci.c renamed from arch/ia64/pci/pci.c~ia64-read_bridge_bases +4 -0
@@ -436,6 +436,10 @@ pcibios_fixup_bus (struct pci_bus *b) {struct pci_dev *dev; +if (b->self) { +pci_read_bridge_bases (b); +pcibios_fixup_device_resources (b->self); + }list_for_each_entry (dev, &b->devices, bus_list)pcibios_fixup_device_resources (dev);
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
PATCH 10/12 Allow ACPI .add and .start operations to be done independently
In reply to Rajesh ShahCreate new interfaces to recursively add an acpi namespace object to the acpi device list, and recursively start the namespace object. This is needed for ACPI based hotplug of a root bridge hierarchy where the add operation must be performed first and the start operation must be performed separately after the hot-plugged devices have been properly configured.
---
linux-2.6.11-mm4-iohp-rshah1/drivers/acpi/container.c | 2 linux-2.6.11-mm4-iohp-rshah1/drivers/acpi/processor_core.c | 2 linux-2.6.11-mm4-iohp-rshah1/drivers/acpi/scan.c | 126 ++++++++++--- linux-2.6.11-mm4-iohp-rshah1/include/acpi/acpi_bus.h | 17 + 4 files changed, 119 insertions(+), 28 deletions(-)
drivers/acpi/scan.c renamed from drivers/acpi/scan.c~acpi_separate_device_start +101 -25
@@ -553,20 +553,29 @@ acpi_bus_driver_init (* upon possible configuration and currently allocated resources. */ +ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"Driver successfully bound to device\n" )); +return_VALUE (0 ); +} + +int +acpi_start_single_object ( +struct acpi_device *device) +{ +int result =0 ; +struct acpi_driver *driver; + +ACPI_FUNCTION_TRACE ("acpi_start_single_object" ); + +if (!(driver = device->driver)) +return_VALUE (0 ); +if (driver->ops.start) { result = driver->ops.start (device);if (result && driver->ops.remove) driver->ops.remove (device,ACPI_BUS_REMOVAL_NORMAL ); -return_VALUE (result); - } - -ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"Driver successfully bound to device\n" )); - -if (driver->ops.scan) { - driver->ops.scan (device); } -return_VALUE (0 ); +return_VALUE (result); }static int acpi_driver_attach (struct acpi_driver * drv)
@@ -586,6 +595,7 @@ static int acpi_driver_attach(struct acpif (!acpi_bus_match (dev, drv)) {if (!acpi_bus_driver_init (dev, drv)) { +acpi_start_single_object (dev);atomic_inc (&drv->references); count++; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
@@ -1009,8 +1019,8 @@ acpi_bus_remove ( } -int -acpi_bus_add ( +static int +acpi_add_single_object ( struct acpi_device **child, struct acpi_device *parent, acpi_handle handle,
@@ -1019,7 +1029,7 @@ acpi_bus_add (int result =0 ;struct acpi_device *device =NULL ; -ACPI_FUNCTION_TRACE ("acpi_bus_add" ); +ACPI_FUNCTION_TRACE ("acpi_add_single_object" );if (!child)return_VALUE (-EINVAL );
@@ -1140,7 +1150,7 @@ acpi_bus_add (* * TBD: Assumes LDM provides driver hot-plug capability. */ -acpi_bus_find_driver (device); + result =acpi_bus_find_driver (device); end:if (!result)
@@ -1153,10 +1163,10 @@ end:return_VALUE (result); } -EXPORT_SYMBOL (acpi_bus_add); -int acpi_bus_scan (struct acpi_device *start) +static int acpi_bus_scan (struct acpi_device *start, +struct acpi_bus_ops *ops) {acpi_status status =AE_OK ;struct acpi_device *parent =NULL ;
@@ -1229,9 +1239,20 @@ int acpi_bus_scan (struct acpi_device *scontinue ; } - status =acpi_bus_add (&child, parent, chandle, type); -if (ACPI_FAILURE (status)) -continue ; +if (ops->acpi_op_add) + status =acpi_add_single_object (&child, parent, + chandle, type); +else + status =acpi_bus_get_device (chandle, &child); + +if (ACPI_FAILURE (status)) +continue ; + +if (ops->acpi_op_start) { + status =acpi_start_single_object (child); +if (ACPI_FAILURE (status)) +continue ; + }/* * If the device is present, enabled, and functioning then
@@ -1257,8 +1278,50 @@ int acpi_bus_scan (struct acpi_device *sreturn_VALUE (0 ); } -EXPORT_SYMBOL (acpi_bus_scan); +int +acpi_bus_add ( +struct acpi_device **child, +struct acpi_device *parent, +acpi_handle handle, +int type) +{ +int result; +struct acpi_bus_ops ops; + +ACPI_FUNCTION_TRACE ("acpi_bus_add" ); + + result =acpi_add_single_object (child, parent, handle, type); +if (!result) { +memset (&ops,0 ,sizeof (ops)); + ops.acpi_op_add =1 ; + result =acpi_bus_scan (*child, &ops); + } +return_VALUE (result); +} +EXPORT_SYMBOL (acpi_bus_add); + +int +acpi_bus_start ( +struct acpi_device *device) +{ +int result; +struct acpi_bus_ops ops; + +ACPI_FUNCTION_TRACE ("acpi_bus_start" ); + +if (!device) +return_VALUE (-EINVAL ); + + result =acpi_start_single_object (device); +if (!result) { +memset (&ops,0 ,sizeof (ops)); + ops.acpi_op_start =1 ; + result =acpi_bus_scan (device, &ops); + } +return_VALUE (result); +} +EXPORT_SYMBOL (acpi_bus_start); static int acpi_bus_trim(struct acpi_device *start,
@@ -1331,13 +1394,19 @@ acpi_bus_scan_fixed (/* * Enumerate all fixed-feature devices. */ -if (acpi_fadt.pwr_button ==0 ) - result =acpi_bus_add (&device, acpi_root, +if (acpi_fadt.pwr_button ==0 ) { + result =acpi_add_single_object (&device, acpi_root,NULL ,ACPI_BUS_TYPE_POWER_BUTTON ); +if (!result) + result =acpi_start_single_object (device); + } -if (acpi_fadt.sleep_button ==0 ) - result =acpi_bus_add (&device, acpi_root, +if (acpi_fadt.sleep_button ==0 ) { + result =acpi_add_single_object (&device, acpi_root,NULL ,ACPI_BUS_TYPE_SLEEP_BUTTON ); +if (!result) + result =acpi_start_single_object (device); + }return_VALUE (result); }
@@ -1346,6 +1415,7 @@ acpi_bus_scan_fixed (static int __init acpi_scan_init (void ) {int result; +struct acpi_bus_ops ops;ACPI_FUNCTION_TRACE ("acpi_scan_init" );
@@ -1357,17 +1427,23 @@ static int __init acpi_scan_init(void)/* * Create the root device in the bus's device tree */ - result =acpi_bus_add (&acpi_root,NULL ,ACPI_ROOT_OBJECT , + result =acpi_add_single_object (&acpi_root,NULL ,ACPI_ROOT_OBJECT ,ACPI_BUS_TYPE_SYSTEM );if (result) goto Done; + result =acpi_start_single_object (acpi_root); +/* * Enumerate devices in the ACPI namespace. */ result =acpi_bus_scan_fixed (acpi_root); -if (!result) - result =acpi_bus_scan (acpi_root); +if (!result) { +memset (&ops,0 ,sizeof (ops)); + ops.acpi_op_add =1 ; + ops.acpi_op_start =1 ; + result =acpi_bus_scan (acpi_root, &ops); + }if (result)acpi_device_unregister (acpi_root,ACPI_BUS_REMOVAL_NORMAL );
include/acpi/acpi_bus.h renamed from include/acpi/acpi_bus.h~acpi_separate_device_start +16 -1
@@ -108,6 +108,21 @@ typedef int (*acpi_op_unbind) (struct actypedef int (*acpi_op_match ) (struct acpi_device *device,struct acpi_driver *driver); +struct acpi_bus_ops { +u32 acpi_op_add:1 ; +u32 acpi_op_remove:1 ; +u32 acpi_op_lock:1 ; +u32 acpi_op_start:1 ; +u32 acpi_op_stop:1 ; +u32 acpi_op_suspend:1 ; +u32 acpi_op_resume:1 ; +u32 acpi_op_scan:1 ; +u32 acpi_op_bind:1 ; +u32 acpi_op_unbind:1 ; +u32 acpi_op_match:1 ; +u32 reserved:21 ; +}; +struct acpi_device_ops {acpi_op_add add;acpi_op_remove remove;
@@ -327,9 +342,9 @@ int acpi_bus_generate_event (struct acpiint acpi_bus_receive_event (struct acpi_bus_event *event);int acpi_bus_register_driver (struct acpi_driver *driver);int acpi_bus_unregister_driver (struct acpi_driver *driver); -int acpi_bus_scan (struct acpi_device *start);int acpi_bus_add (struct acpi_device **child,struct acpi_device *parent,acpi_handle handle,int type); +int acpi_bus_start (struct acpi_device *device);int acpi_match_ids (struct acpi_device *device,char *ids);
drivers/acpi/container.c renamed from drivers/acpi/container.c~acpi_separate_device_start +1 -1
@@ -153,7 +153,7 @@ container_device_add(struct acpi_devicereturn_VALUE (-ENODEV ); } - result =acpi_bus_scan (*device); + result =acpi_bus_start (*device);return_VALUE (result); }
drivers/acpi/processor_core.c renamed from drivers/acpi/processor_core.c~acpi_separate_device_start +1 -1
@@ -723,7 +723,7 @@ int acpi_processor_device_add(return_VALUE (-ENODEV ); } -acpi_bus_scan (*device); +acpi_bus_start (*device); pr =acpi_driver_data (*device);if (!pr)
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
PATCH 11/12 Export the interface to get PCI id for an ACPI handle
In reply to Rajesh ShahExport an acpi interface to get PCI domain/bus/devfn information from the corresponding namespace handle. Used by acpiphp code to transpate the device handle of the hot-plugged root bridge to the corresponding pci location information.
---
linux-2.6.11-mm4-iohp-rshah1/drivers/acpi/pci_bind.c | 11 +++++------ linux-2.6.11-mm4-iohp-rshah1/include/acpi/acpi_drivers.h | 1 + 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/acpi/pci_bind.c renamed from drivers/acpi/pci_bind.c~acpi-get-pci-id +5 -6
@@ -61,15 +61,14 @@ acpi_pci_data_handler (/** -* acpi_os_get_pci_id +* acpi_get_pci_id * ------------------ * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem) * to resolve PCI information for ACPI-PCI devices defined in the namespace. * This typically occurs when resolving PCI operation region information. */ -#ifdef ACPI_FUTURE_USAGE acpi_status -acpi_os_get_pci_id ( +acpi_get_pci_id (acpi_handle handle,struct acpi_pci_id *id) {
@@ -78,7 +77,7 @@ acpi_os_get_pci_id (struct acpi_device *device =NULL ;struct acpi_pci_data *data =NULL ; -ACPI_FUNCTION_TRACE ("acpi_os_get_pci_id" ); +ACPI_FUNCTION_TRACE ("acpi_get_pci_id" );if (!id)return_ACPI_STATUS (AE_BAD_PARAMETER );
@@ -92,7 +91,7 @@ acpi_os_get_pci_id ( } status =acpi_get_data (handle, acpi_pci_data_handler, (void **) &data); -if (ACPI_FAILURE (status) || !data || !data->dev) { +if (ACPI_FAILURE (status) || !data) {ACPI_DEBUG_PRINT ((ACPI_DB_ERROR ,"Invalid ACPI-PCI context for device %s\n" ,acpi_device_bid (device)));
@@ -115,7 +114,7 @@ acpi_os_get_pci_id (return_ACPI_STATUS (AE_OK ); } -#endif /* ACPI_FUTURE_USAGE */ +EXPORT_SYMBOL (acpi_get_pci_id);int
include/acpi/acpi_drivers.h renamed from include/acpi/acpi_drivers.h~acpi-get-pci-id +1 -0
@@ -68,6 +68,7 @@ void acpi_pci_irq_del_prt (int segment,struct pci_bus ; +acpi_status acpi_get_pci_id (acpi_handle handle,struct acpi_pci_id *id);int acpi_pci_bind (struct acpi_device *device);int acpi_pci_unbind (struct acpi_device *device);int acpi_pci_bind_root (struct acpi_device *device,struct acpi_pci_id *id,struct pci_bus *bus);
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
PATCH 12/12 ACPI based root bridge hot-add
In reply to Rajesh Shahacpiphp changes to support acpi based root bridge hot-add. This patch applies on top of the acpiphp re-write patch by Matthew Wilcox at:
http://marc.theaimsgroup.com/?l=linux-ia64&m=110616116714938&w=2
---
linux-2.6.11-mm4-iohp-rshah1/drivers/pci/hotplug/acpiphp_glue.c | 211 +++++++++- 1 files changed, 202 insertions(+), 9 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c renamed from drivers/pci/hotplug/acpiphp_glue.c~acpiphp_h2p_add +202 -9
@@ -6,6 +6,8 @@* Copyright (C) 2002,2003 NEC Corporation * Copyright (C) 2003-2005 Matthew Wilcox ([email protected]) * Copyright (C) 2003-2005 Hewlett Packard +* Copyright (C) 2005 Rajesh Shah ([email protected]) +* Copyright (C) 2005 Intel Corporation * * All rights reserved. *
@@ -304,13 +306,15 @@ static void init_bridge_misc(struct acpi register_slot, bridge, NULL);/* install notify handler */ - status =acpi_install_notify_handler (bridge->handle, +if (bridge->type !=BRIDGE_TYPE_HOST ) { + status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event_bridge, bridge); -if (ACPI_FAILURE (status)) { -err ("failed to register interrupt notify handler\n" ); +if (ACPI_FAILURE (status)) { +err ("failed to register interrupt notify handler\n" ); + } }list_add (&bridge->list, &bridge_list);
@@ -802,6 +806,143 @@ static int acpiphp_check_bridge(struct areturn retval; } +static void program_hpp (struct pci_dev *dev,struct acpiphp_bridge *bridge) +{ +u16 pci_cmd, pci_bctl; +struct pci_dev *cdev; + +/* Program hpp values for this device */ +if (!(dev->hdr_type ==PCI_HEADER_TYPE_NORMAL || + (dev->hdr_type ==PCI_HEADER_TYPE_BRIDGE && + (dev->class >>8 ) ==PCI_CLASS_BRIDGE_PCI ))) +return ; +pci_write_config_byte (dev,PCI_CACHE_LINE_SIZE , + bridge->hpp.cache_line_size); +pci_write_config_byte (dev,PCI_LATENCY_TIMER , + bridge->hpp.latency_timer); +pci_read_config_word (dev,PCI_COMMAND , &pci_cmd); +if (bridge->hpp.enable_SERR) + pci_cmd |=PCI_COMMAND_SERR ; +else + pci_cmd &= ~PCI_COMMAND_SERR ; +if (bridge->hpp.enable_PERR) + pci_cmd |=PCI_COMMAND_PARITY ; +else + pci_cmd &= ~PCI_COMMAND_PARITY ; +pci_write_config_word (dev,PCI_COMMAND , pci_cmd); + +/* Program bridge control value and child devices */ +if ((dev->class >>8 ) ==PCI_CLASS_BRIDGE_PCI ) { +pci_write_config_byte (dev,PCI_SEC_LATENCY_TIMER , + bridge->hpp.latency_timer); +pci_read_config_word (dev,PCI_BRIDGE_CONTROL , &pci_bctl); +if (bridge->hpp.enable_SERR) + pci_bctl |=PCI_BRIDGE_CTL_SERR ; +else + pci_bctl &= ~PCI_BRIDGE_CTL_SERR ; +if (bridge->hpp.enable_PERR) + pci_bctl |=PCI_BRIDGE_CTL_PARITY ; +else + pci_bctl &= ~PCI_BRIDGE_CTL_PARITY ; +pci_write_config_word (dev,PCI_BRIDGE_CONTROL , pci_bctl); +if (dev->subordinate) { +list_for_each_entry (cdev, &dev->subordinate->devices, + bus_list) +program_hpp (cdev, bridge); + } + } +} + +static void acpiphp_set_hpp_values (acpi_handle handle,struct pci_bus *bus) +{ +struct acpiphp_bridge bridge; +struct pci_dev *dev; + +memset (&bridge,0 ,sizeof (bridge)); + bridge.handle = handle; +decode_hpp (&bridge); +list_for_each_entry (dev, &bus->devices, bus_list) +program_hpp (dev, &bridge); + +} + +/* +* Remove devices for which we could not assign resources, call +* arch specific code to fix-up the bus +*/ +static void acpiphp_sanitize_bus (struct pci_bus *bus) +{ +struct pci_dev *dev; +int i; +unsigned long type_mask =IORESOURCE_IO |IORESOURCE_MEM ; + +list_for_each_entry (dev, &bus->devices, bus_list) { +for (i=0 ; i<PCI_BRIDGE_RESOURCES ; i++) { +struct resource *res = &dev->resource[i]; +if ((res->flags & type_mask) && !res->start && + res->end) { +/* Could not assign a required resources +* for this device, remove it */ +pci_remove_bus_device (dev); +break ; + } + } + } +} + +/* Program resources in newly inserted bridge */ +static int acpiphp_configure_bridge (acpi_handle handle) +{ +struct acpi_pci_id pci_id; +struct pci_bus *bus; + +if (ACPI_FAILURE (acpi_get_pci_id (handle, &pci_id))) { +err ("cannot get PCI domain and bus number for bridge\n" ); +return -EINVAL ; + } + bus =pci_find_bus (pci_id.segment, pci_id.bus); +if (!bus) { +err ("cannot find bus %d:%d\n" , + pci_id.segment, pci_id.bus); +return -EINVAL ; + } + +pci_bus_size_bridges (bus); +pci_bus_assign_resources (bus); +acpiphp_sanitize_bus (bus); +acpiphp_set_hpp_values (handle, bus); +pci_enable_bridges (bus); +return 0 ; +} + +static void handle_bridge_insertion (acpi_handle handle,u32 type) +{ +struct acpi_device *device, *pdevice; +acpi_handle phandle; + +if ((type !=ACPI_NOTIFY_BUS_CHECK ) && + (type !=ACPI_NOTIFY_DEVICE_CHECK )) { +err ("unexpected notification type %d\n" , type); +return ; + } + +acpi_get_parent (handle, &phandle); +if (acpi_bus_get_device (phandle, &pdevice)) { +dbg ("no parent device, assuming NULL\n" ); + pdevice =NULL ; + } +if (acpi_bus_add (&device, pdevice, handle,ACPI_BUS_TYPE_DEVICE )) { +err ("cannot add bridge to acpi list\n" ); +return ; + } +if (!acpiphp_configure_bridge (handle) && + !acpi_bus_start (device)) +add_bridge (handle); +else +err ("cannot configure and start bridge\n" ); + +} +/* * ACPI event handlers */
@@ -822,8 +963,19 @@ static void handle_hotplug_event_bridge(char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname), .pointer = objname }; +struct acpi_device *device; - bridge = (struct acpiphp_bridge *)context; +if (acpi_bus_get_device (handle, &device)) { +/* This bridge must have just been physically inserted */ +handle_bridge_insertion (handle, type); +return ; + } + + bridge =acpiphp_handle_to_bridge (handle); +if (!bridge) { +err ("cannot get bridge info\n" ); +return ; + }acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer);
@@ -923,6 +1075,47 @@ static void handle_hotplug_event_func(ac } } +static int is_root_bridge (acpi_handle handle) +{ +acpi_status status; +struct acpi_device_info *info; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +int i; + + status =acpi_get_object_info (handle, &buffer); +if (ACPI_SUCCESS (status)) { + info = buffer.pointer; +if ((info->valid &ACPI_VALID_HID ) && + !strcmp (PCI_ROOT_HID_STRING , + info->hardware_id.value)) { +acpi_os_free (buffer.pointer); +return 1 ; + } +if (info->valid &ACPI_VALID_CID ) { +for (i=0 ; i < info->compatibility_id.count; i++) { +if (!strcmp (PCI_ROOT_HID_STRING , + info->compatibility_id.id[i].value)) { +acpi_os_free (buffer.pointer); +return 1 ; + } + } + } + } +return 0 ; +} + +static acpi_status +find_root_bridges (acpi_handle handle,u32 lvl,void *context,void **rv) +{ +int *count = (int *)context; + +if (is_root_bridge (handle)) { +acpi_install_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_bridge,NULL ); + (*count)++; + } +return AE_OK ; +}static struct acpi_pci_driver acpi_pci_hp_driver = { .add = add_bridge,
@@ -935,15 +1128,15 @@ static struct acpi_pci_driver acpi_pci_h*/ int __init acpiphp_glue_init (void ) { -int num; - -if (list_empty (&pci_root_buses)) -return -1 ; +int num =0 ; - num =acpi_pci_register_driver (&acpi_pci_hp_driver); +acpi_walk_namespace (ACPI_TYPE_DEVICE ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX , find_root_bridges, &num,NULL );if (num <=0 )return -1 ; +else +acpi_pci_register_driver (&acpi_pci_hp_driver);return 0 ; }
_
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
Quoted 8 lines · Rajesh Shah
Here is a series of patches to support ACPI hot-add of a root bridge hierarchy. The added hierarchy may contain other p2p bridges and end/leaf I/O devices too. The root bridge itself is assumed to have been assigned resource ranges, but the p2p bridges and end devices are not required to be initialized by firmware. Most of the code changes are to make the existing code flows suitable for such a hierarchy of bridges & devices.
Quoted 5 lines
This code supports hot-add on ia64 only for now.It does not yet support I/O APIC hot-add, which is needed to make this fully functional. The patches are against 2.6.11-mm4 (plus the patch needed for ia64 to boot). I've tested to make sure this does not break end/leaf device hotplug on the hotplug capable ia64 box I have.
This all looks very good, nice job. I only had one minor comment on the patches, which I'll reply to directly.
But I did have a few questions:
- This series relys on Mathew's rewrite of the acpiphp driver. Is that acceptable? Is that patch necessary for your work? And if so, can you include it in the whole series?
- Does this break the i386 acpiphp functionality?
- Have you tested other pci hotplug systems with this patch series? Like pci express hotplug, standard pci hotplug, cardbus, etc?
- Are you wanting the acpi specific patches to go into the tree through the acpi developers? How about the ia64 specific patches?
- Have the acpi developers agreed with your acpi patches?
thanks,
greg k-h
Quoted 8 lines · Greg KH
This all looks very good, nice job. I only had one minor comment on the patches, which I'll reply to directly.
But I did have a few questions:
- This series relys on Mathew's rewrite of the acpiphp driver. Is that acceptable? Is that patch necessary for your work? And if so, can you include it in the whole series?
The last patch (12) in the series is the only one that depends on Matthew's acpiphp rewrite. I do have a really old version of my patch that worked with the original acpiphp code base but this version is cleaner. I could probably resurrect my old patch if you want, but I'd rather prefer to work on and fix any other objections you or others may have with Matthew's re-write, since that's the better overall approach.
Quoted 1 line
- Does this break the i386 acpiphp functionality?
Dely Sy had tested hotplug with an earlier version of my patches (with minor differences from the current series) on i386 and it worked fine. She probably hasn't tested the latest one. Dely, could you check that please? The i386 hotplug capable box I have doesn't seem to have the right firmware, so I haven't been able to test hotplug on that (I'm working on fixing that). Of course, I tested my patches on i386 (ACPI as well as non-ACPI) and x86_64 machines to make sure I didn't break boot on those.
Quoted 3 lines
- Have you tested other pci hotplug systems with this patch series? Like pci express hotplug, standard pci hotplug, cardbus, etc?
No, because I the one system I have access to isn't doing any hot-plug. I'm working on fixing that but was also hoping to hear from others who surely have access to more machines than I do.
Quoted 3 lines
- Are you wanting the acpi specific patches to go into the tree through the acpi developers? How about the ia64 specific patches?
I honestly don't know what the best approach is here - what do you recommend? I did receive an email from Andrew indicating he wants to pick these up for the next mm. Perhaps the best thing is to let Andrew include the whole series after I've addressed all feedback and you, Tony, Len etc. all agree these are OK to go in.
Quoted 2 lines
- Have the acpi developers agreed with your acpi patches?
This is the first time I sent the patches to the acpi list, so I do need to give them a few days to weigh in.
Rajesh
Quoted 9 lines · Rajesh Shah
Quoted 3 lines
- Are you wanting the acpi specific patches to go into the tree through the acpi developers? How about the ia64 specific patches?
I honestly don't know what the best approach is here - what do you recommend? I did receive an email from Andrew indicating he wants to pick these up for the next mm. Perhaps the best thing is to let Andrew include the whole series after I've addressed all feedback and you, Tony, Len etc. all agree these are OK to go in.
That sounds like a fine plan to me.
thanks,
greg k-h
Quoted 6 lines · Greg KH
Quoted 1 line · Rajesh Shah
Quoted 1 line
- Are you wanting the acpi specific patches to go into the
tree
Quoted 3 lines
Quoted 2 lines
through the acpi developers? How about the ia64 specific patches?
Quoted 7 lines
Quoted 5 lines
I honestly don't know what the best approach is here - what do you recommend? I did receive an email from Andrew indicating he wants to pick these up for the next mm. Perhaps the best thing is to let Andrew include the whole series after I've addressed all feedback and you, Tony, Len etc. all agree these are OK to go in.
That sounds like a fine plan to me.
Me too.
And I don't see any issues with the ACPI specific changes.
cheers,
-Len
Quoted 7 lines · Rajesh Shah
Here is a series of patches to support ACPI hot-add of a root bridge hierarchy. The added hierarchy may contain other p2p bridges and end/leaf I/O devices too. The root bridge itself is assumed to have been assigned resource ranges, but the p2p bridges and end devices are not required to be initialized by firmware. Most of the code changes are to make the existing code flows suitable for such a hierarchy of bridges & devices.
Quoted 8 lines
This code supports hot-add on ia64 only for now.It does not yet support I/O APIC hot-add, which is needed to make this fully functional. The patches are against 2.6.11-mm4 (plus the patch needed for ia64 to boot). I've tested to make sure this does not break end/leaf device hotplug on the hotplug capable ia64 box I have.
Thanks,
Rajesh
Does this mean that when it will be ported for i386, I will be able to really use my Docking Station ?
Does it rescan the DSDT to find new additions to ACPI devices ?
I have an IBM docking station with a PCI bus inside and some other devices, and when I hot plug my IBM ThinkPad T41 in it, it does not recognize those devices. Only if I boot in dock they are usable. And the DSDT is different if I boot in dock or not.
So I wander if this patch would help me to hot plug my T41 in the dock and all devices will be recognized. (when the patch will be for i386 too)
Thx,
Paul
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
Quoted 3 lines · Paul Ionescu
Does this mean that when it will be ported for i386, I will be able to really use my Docking Station ?
No. The current patches only trigger when a _root_ bridge is hot-added, not a PCI to PCI bridge (which is what the docking station is). The code to support p2p bridge hotplug will benefit from these patches but more code is needed to support that.
Quoted 2 lines
Does it rescan the DSDT to find new additions to ACPI devices ?
It scans the ACPI namespace under the root bridge that was added. Any pci devices underneath are scanned and added, but there isn't any code to look for non-PCI devices there.
Rajesh
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click