PCI probing for cardbus
Could people please test these patches and let me know of any problems. They work for me. There should be no user-visible changes in behaviour from this set, apart from drivers/hotplug breaking again. These are all against base 2.5.63, and will follow in separate mails.
pci-1.diff
- Separate out bus resource allocator (pci_bus_alloc_resource)
- Provide pci_enable_bridges to setup command register for all pci bridges
pci-2.diff
- Eliminate the stack allocation of a struct pci_dev, and make pci_scan_slot() take a bus and a devfn argument.
- Add "dev->multifunction" to indicate whether this is a multifunction device.
- Run header fixups before inserting the new pci device into any device lists or announcing it to the drivers.
- Convert some more stuff to use the list_for_each* macro(s).
No real behavioural change yet.
pci-3.diff
This is the first patch which we start breaking things.
The pci_find* functions search using the following lists:
bus->children (for subordinate buses)
pci_root_buses (for all root buses)
pci_devices (for devices) This leaves one list which we can add devices to without any drivers finding the new devices before we've finished with them. (Jeff - some drivers do go scanning the bus_list, notably de4x5.c:srom_search.)
- initialise bus->node list head.
- pci_scan_slot will scan the specified slot, and add the discovered devices to the bus->devices list only. These devices will not appear on the global device list, and do not show in sysfs, procfs. pci_scan_slot returns the number of functions found. If you want to find the devices, you have to scan bus->devices and look for devices where list_empty(&dev->global_list) is true.
- new function "pci_bus_add_devices" adds newly discovered devices to the global device lists, and handles the sysfs and procfs stuff, making the devices available to drivers. All our buses which have an empty list head are treated as "new" (since they are not attached to the parent buses list of children) and are also added. Currently, no buses will be in this state when this function is called.
- new function "pci_scan_child_bus" scans a complete bus, building a list of devices on bus->devices only, performing bus fixups via pcibios_fixup_bus() and scanning behind bridges. It does make devices externally visible.
- pci_do_scan_bus retains its original behaviour - ie, it scans and makes devices available immediately.
pci-4.diff
- Convert setup-bus.c resource allocation to scan bus->devices rather than bus->children. As noted previously, newly discovered child buses will not be on the parents list of children buses, so when we're trying to assign resources, we need to scan the bus for devices with subordinate buses rather than using the list of children buses.
pci-5.diff
Now we tackle pci_add_new_bus and pci_scan_bridge. The hotplug code currently uses this, but I'd like it to die off; pci_scan_bridge() should be used to scan behind bridges. This may mean hotplug needs some changes to pci_scan_bridge - if so, we need to find out what changes are required and fix it.
pci_alloc_child_bus() does what pci_add_new_bus() did, except it doesn't attach the new bus to the parents list of child buses. The only way this bus can be reached from the parent bus is by scanning the parents devices list, and locating a device with a non-NULL subordinate bus. The only code which should be doing this is the PCI code.
Since the new bus will have an empty list head for bus->node, we can detect unattached buses prety easily. (see pci-3.diff. maybe we want a pci_bus_unattached() to make it more readable?)
pci_scan_bridge() changes slightly - we use our new pci_scan_child_bus() function from pci-3.diff, which doesn't attach devices to the global tree. This means callers of pci_scan_child_bus() and pci_scan_bridge() (ie, hotplug) will need to call pci_bus_add_devices().
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html
Re: [CFT] PCI probing for cardbus (1/5)
drivers/pci/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for the PCI bus specific drivers. # -obj-y += access.o probe.o pci.o pool.o quirks.o \ +obj-y += access.o bus.o probe.o pci.o pool.o quirks.o \ names.o pci-driver.o search.o hotplug.o \ pci-sysfs.o obj-$(CONFIG_PM) += power.o
drivers/pci/bus.c +81 -0
81 lines not on this page · raw message
drivers/pci/setup-res.c +26 -63
110 lines not on this page · raw message
include/linux/pci.h +10 -0
@@ -641,6 +641,16 @@int pci_request_region (struct pci_dev *,int ,char *);void pci_release_region (struct pci_dev *,int ); +/* drivers/pci/bus.c */ + +int pci_bus_alloc_resource (struct pci_bus *bus,struct resource *res, +unsigned long size,unsigned long align, +unsigned long min,unsigned int type_mask, +void (*alignf)(void *,struct resource *, +unsigned long ,unsigned long ), +void *alignf_data); +void pci_enable_bridges (struct pci_bus *bus); +/* New-style probing supporting hot-pluggable devices */ int pci_register_driver (struct pci_driver *);void pci_unregister_driver (struct pci_driver *);
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html
Re: [CFT] PCI probing for cardbus (2/5)
In reply to Russell Kingdrivers/hotplug/acpiphp_glue.c +2 -10
@@ -879,7 +879,7 @@static int enable_device (struct acpiphp_slot *slot) {u8 bus; -struct pci_dev dev0, *dev; +struct pci_dev *dev;struct pci_bus *child;struct list_head *l;struct acpiphp_func *func;
@@ -902,16 +902,8 @@if (retval) goto err_exit; -memset (&dev0,0 ,sizeof (struct pci_dev )); - - dev0.bus = slot->bridge->pci_bus; - dev0.devfn =PCI_DEVFN (slot->device,0 ); - dev0.sysdata = dev0.bus->sysdata; - dev0.dev.parent = dev0.bus->dev; - dev0.dev.bus = &pci_bus_type; -/* returned `dev' is the *first function* only! */ - dev =pci_scan_slot (&dev0); + dev =pci_scan_slot (slot->bridge->pci_bus,PCI_DEVFN (slot->device,0 ));if (!dev) {err ("No new device found\n" );
drivers/hotplug/cpci_hotplug_pci.c +1 -7
@@ -601,19 +601,13 @@/* Still NULL? Well then scan for it! */ if (slot->dev ==NULL ) { -struct pci_dev dev0; -dbg ("pci_dev still null" ); -memset (&dev0,0 ,sizeof (struct pci_dev )); - dev0.bus = slot->bus; - dev0.devfn = slot->devfn; - dev0.sysdata = slot->bus->self->sysdata;/* * This will generate pci_dev structures for all functions, but * we will only call this case when lookup fails. */ - slot->dev =pci_scan_slot (&dev0); + slot->dev =pci_scan_slot (slot->bus, slot->devfn);if (slot->dev ==NULL ) {err ("Could not find PCI device for slot %02x" , slot->number);return 0 ;
drivers/hotplug/cpqphp_pci.c +2 -7
@@ -250,7 +250,6 @@int cpqhp_configure_device (struct controller * ctrl,struct pci_func * func) {unsigned char bus; -struct pci_dev dev0;struct pci_bus *child;struct pci_dev * temp;int rc =0 ;
@@ -260,20 +259,16 @@memset (&wrapped_dev,0 ,sizeof (struct pci_dev_wrapped ));memset (&wrapped_bus,0 ,sizeof (struct pci_bus_wrapped )); -memset (&dev0,0 ,sizeof (struct pci_dev )); -if (func->pci_dev ==NULL ) func->pci_dev =pci_find_slot (func->bus, (func->device <<3 ) | (func->function &0x7 ));//Still NULL ? Well then scan for it ! if (func->pci_dev ==NULL ) {dbg ("INFO: pci_dev still null\n" ); - dev0.bus = ctrl->pci_dev->bus; - dev0.devfn = (func->device <<3 ) + (func->function &0x7 ); - dev0.sysdata = ctrl->pci_dev->sysdata;//this will generate pci_dev structures for all functions, but we will only call this case when lookup fails - func->pci_dev =pci_scan_slot (&dev0); + func->pci_dev =pci_scan_slot (ctrl->pci_dev->bus, + (func->device <<3 ) + (func->function &0x7 ));if (func->pci_dev ==NULL ) {dbg ("ERROR: pci_dev still null\n" );return 0 ;
drivers/hotplug/ibmphp_core.c +4 -7
@@ -1035,7 +1035,6 @@static int ibm_configure_device (struct pci_func *func) {unsigned char bus; -struct pci_dev dev0;struct pci_bus *child;struct pci_dev *temp;int rc =0 ;
@@ -1046,7 +1045,6 @@memset (&wrapped_dev,0 ,sizeof (struct pci_dev_wrapped ));memset (&wrapped_bus,0 ,sizeof (struct pci_bus_wrapped )); -memset (&dev0,0 ,sizeof (struct pci_dev ));if (!(bus_structure_fixup (func->busno))) flag =1 ;
@@ -1054,13 +1052,12 @@ func->dev =pci_find_slot (func->busno, (func->device <<3 ) | (func->function &0x7 ));if (func->dev ==NULL ) { - dev0.bus =ibmphp_find_bus (func->busno); -if (!dev0.bus) +struct pci_bus *bus =ibmphp_find_bus (func->busno); +if (!bus)return 0 ; - dev0.devfn = ((func->device <<3 ) + (func->function &0x7 )); - dev0.sysdata = dev0.bus->sysdata; - func->dev =pci_scan_slot (&dev0); + func->dev =pci_scan_slot (bus, + (func->device <<3 ) + (func->function &0x7 ));if (func->dev ==NULL ) {err ("ERROR... : pci_dev still NULL \n" );
drivers/pci/probe.c +43 -44
152 lines not on this page · raw message
include/linux/pci.h +2 -1
@@ -413,6 +413,7 @@/* These fields are used by common fixups */ unsigned int transparent:1; /* Transparent PCI bridge */ + unsigned int multifunction:1;/* Part of multi-function device */ };#define pci_dev_g (n) list_entry(n, struct pci_dev, global_list)
@@ -548,7 +549,7 @@ {return pci_alloc_primary_bus_parented (NULL , bus); } -struct pci_dev *pci_scan_slot (struct pci_dev *temp); +struct pci_dev *pci_scan_slot (struct pci_bus *bus,int devfn);int pci_proc_attach_device (struct pci_dev *dev);int pci_proc_detach_device (struct pci_dev *dev);int pci_proc_attach_bus (struct pci_bus *bus);
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html
Re: [CFT] PCI probing for cardbus (3/5)
In reply to Russell Kingdrivers/pci/bus.c +46 -0
@@ -12,6 +12,10 @@#include <linux/pci.h> #include <linux/errno.h> #include <linux/ioport.h> +#include <linux/proc_fs.h> +#include <linux/init.h> + +#include "pci.h" /** * pci_bus_alloc_resource - allocate a resource from a parent bus
@@ -64,6 +68,47 @@return ret; } +/** +* pci_bus_add_devices - insert newly discovered PCI devices +* @bus: bus to check for new devices +* +* Add newly discovered PCI devices (which are on the bus->devices +* list) to the global PCI device list, add the sysfs and procfs +* entries. Where a bridge is found, add the discovered bus to +* the parents list of child buses, and recurse. +* +* Call hotplug for each new devices. +*/ +void __devinit pci_bus_add_devices (struct pci_bus *bus) +{ +struct pci_dev *dev; + +list_for_each_entry (dev, &bus->devices, bus_list) { +/* +* Skip already-present devices (which are on the +* global device list.) +*/ +if (!list_empty (&dev->global_list)) +continue ; + +device_register (&dev->dev); +list_add_tail (&dev->global_list, &pci_devices); +#ifdef CONFIG_PROC_FS +pci_proc_attach_device (dev); +#endif +pci_create_sysfs_dev_files (dev); + +/* +* If there is an unattached subordinate bus, attach +* it and then scan for unattached PCI devices. +*/ +if (dev->subordinate &&list_empty (&dev->subordinate->node)) { +list_add_tail (&dev->subordinate->node, &dev->bus->children); +pci_bus_add_devices (dev->subordinate); + } + } +} +void pci_enable_bridges (struct pci_bus *bus) {struct pci_dev *dev;
@@ -78,4 +123,5 @@ }EXPORT_SYMBOL (pci_bus_alloc_resource); +EXPORT_SYMBOL (pci_bus_add_devices);EXPORT_SYMBOL (pci_enable_bridges);
drivers/pci/probe.c +35 -17
96 lines not on this page · raw message
include/linux/pci.h +2 -1
@@ -549,7 +549,8 @@ {return pci_alloc_primary_bus_parented (NULL , bus); } -struct pci_dev *pci_scan_slot (struct pci_bus *bus,int devfn); +int pci_scan_slot (struct pci_bus *bus,int devfn); +void pci_bus_add_devices (struct pci_bus *bus);int pci_proc_attach_device (struct pci_dev *dev);int pci_proc_detach_device (struct pci_dev *dev);int pci_proc_attach_bus (struct pci_bus *bus);
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html
Re: [CFT] PCI probing for cardbus (4/5)
In reply to Russell Kingdrivers/pci/setup-bus.c +1 -0
@@ -350,6 +350,7 @@ {struct pci_bus *b;int found_vga =pbus_assign_resources_sorted (bus); +struct pci_dev *dev;if (found_vga) {/* Propagate presence of the VGA to upstream bridges */
@@ -357,9 +358,12 @@
b->resource[0]->flags |= IORESOURCE_BUS_HAS_VGA;
}
}
- list_for_each_entry(b, &bus->children, node) {
- pci_bus_assign_resources(b);
- pci_setup_bridge(b);
+ list_for_each_entry(dev, &bus->devices, bus_list) {
+ b = dev->subordinate;
+ if (b) {
+ pci_bus_assign_resources(b);
+ pci_setup_bridge(b);
+ }
}
}
EXPORT_SYMBOL(pci_bus_assign_resources);
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html
Re: [CFT] PCI probing for cardbus (5/5)
In reply to Russell Kingdrivers/pci/probe.c +50 -25
@@ -228,41 +228,57 @@return b; } -struct pci_bus *__devinit pci_add_new_bus (struct pci_bus *parent,struct pci_dev *dev,int busnr) +static struct pci_bus *__devinit +pci_alloc_child_bus (struct pci_bus *parent,struct pci_dev *bridge,int busnr) {struct pci_bus *child; -int i;/* * Allocate a new bus, and inherit stuff from the parent.. */ child =pci_alloc_bus (); -list_add_tail (&child->node, &parent->children); - child->self = dev; - dev->subordinate = child; - child->parent = parent; - child->ops = parent->ops; - child->sysdata = parent->sysdata; - child->dev = &dev->dev; +if (child) { +int i; -/* -* Set up the primary, secondary and subordinate -* bus numbers. -*/ - child->number = child->secondary = busnr; - child->primary = parent->secondary; - child->subordinate =0xff ; - -/* Set up default resource pointers and names.. */ -for (i =0 ; i <4 ; i++) { - child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES +i]; - child->resource[i]->name = child->name; + child->self = bridge; + child->parent = parent; + child->ops = parent->ops; + child->sysdata = parent->sysdata; + child->dev = &bridge->dev; + +/* +* Set up the primary, secondary and subordinate +* bus numbers. +*/ + child->number = child->secondary = busnr; + child->primary = parent->secondary; + child->subordinate =0xff ; + +/* Set up default resource pointers and names.. */ +for (i =0 ; i <4 ; i++) { + child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES +i]; + child->resource[i]->name = child->name; + } + + bridge->subordinate = child; }return child; } +struct pci_bus *__devinit pci_add_new_bus (struct pci_bus *parent,struct pci_dev *dev,int busnr) +{ +struct pci_bus *child; + + child =pci_alloc_child_bus (parent, dev, busnr); +if (child) +list_add_tail (&child->node, &parent->children); +return child; +} + +static unsigned int __devinit pci_scan_child_bus (struct pci_bus *bus); +/* * If it's a bridge, configure it and scan the bus behind it. * For CardBus bridges, we don't scan behind as the devices will
@@ -289,12 +305,12 @@*/ if (pass)return max; - child =pci_add_new_bus (bus, dev,0 ); + child =pci_alloc_child_bus (bus, dev,0 ); child->primary = buses &0xFF ; child->secondary = (buses >>8 ) &0xFF ; child->subordinate = (buses >>16 ) &0xFF ; child->number = child->secondary; - cmax =pci_do_scan_bus (child); + cmax =pci_scan_child_bus (child);if (cmax > max) max = cmax; }else {/*
@@ -307,18 +323,27 @@/* Clear errors */ pci_write_config_word (dev,PCI_STATUS ,0xffff ); - child =pci_add_new_bus (bus, dev, ++max); + child =pci_alloc_child_bus (bus, dev, ++max); buses = (buses &0xff000000 ) | ((unsigned int )(child->primary) <<0 ) | ((unsigned int )(child->secondary) <<8 ) | ((unsigned int )(child->subordinate) <<16 ); + +/* +* yenta.c forces a secondary latency timer of 176. +* Copy that behaviour here. +*/ +if (is_cardbus) + buses = (buses &0x00ffffff ) | (176 <<24 ); +/* * We need to blast all three values with a single write. */ pci_write_config_dword (dev,PCI_PRIMARY_BUS , buses); +if (!is_cardbus) {/* Now we can scan all subordinate buses... */ - max =pci_do_scan_bus (child); + max =pci_scan_child_bus (child); }else {/* * For CardBus bridges, we leave 4 bus numbers
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html