split PCI probing code [1/9]
RFC PATCH 1/1 split PCI probing code [1/9]
This patch divides the PCI probing code into three smaller files:
config.c - PCI configuration space parsingprobe.c - PCI bus detection routinesbus.c - the PCI bus class driver core
These files are placed in the new directory "drivers/pci/bus". It will be used for functions related to the PCI bus class driver and PCI device detection in general.
drivers/pci/Makefile +3 -3
@@ -2,9 +2,9 @@ # Makefile for the PCI bus specific drivers. # -obj-y += access.o bus.o probe.o remove.o pci.o quirks.o \ - names.o pci-driver.o search.o pci-sysfs.o \ - rom.o +obj-y += access.o bus.o remove.o pci.o quirks.o names.o \ + pci-driver.o search.o pci-sysfs.o rom.o bus/ + obj-$(CONFIG_PROC_FS) += proc.o ifndef CONFIG_SPARC64
drivers/pci/bus/Makefile +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the PCI device detection +# + +obj-y := bus.o config.o probe.o
drivers/pci/bus/bus.c +69 -0
69 lines not on this page · raw message
drivers/pci/bus/bus.h +5 -0
@@ -0,0 +1,5 @@ +/* +* bus.h - functions internal to PCI device detection +*/ + +extern struct class pcibus_class;
drivers/pci/bus/config.c +466 -0
466 lines not on this page · raw message
drivers/pci/bus/probe.c +480 -0
480 lines not on this page · raw message
drivers/pci/probe.c +0 -971
971 lines not on this page · raw message
include/linux/pci.h +1 -0
@@ -733,6 +733,7 @@/* Generic PCI functions used internally */ +extern struct pci_bus *pci_alloc_bus (void );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);
Adam Belay <[email protected]> :
[...]
Some nits + a suspect error branch. It seems nice otherwise.
Quoted 2 lines
drivers/pci/bus/bus.c +0
-0
[...]
drivers/pci/bus/bus.c line 61
Quoted 7 lines
drivers/pci/bus/bus.c +7
-0+struct pci_bus *pci_alloc_bus (void ) +{ +struct pci_bus *b; + + b =kmalloc (sizeof (*b),GFP_KERNEL ); +if (b) { +memset (b,0 ,sizeof (*b));
mm/slab.c provides kcalloc.
[...]
Quoted 2 lines
drivers/pci/bus/config.c +0
-0
[...]
drivers/pci/bus/config.c line 75
Quoted 7 lines
drivers/pci/bus/config.c +7
-0+static void pci_read_bases (struct pci_dev *dev,unsigned int howmany,int rom) +{ +unsigned int pos, reg, next; +u32 l, sz; +struct resource *res; + +for (pos=0 ; pos<howmany; pos = next) {
for (pos = 0; pos < howmany; pos = next) {[...]
Quoted 3 lines
drivers/pci/bus/config.c +3
-0+static struct pci_dev *__devinit +pci_scan_device (struct pci_bus *bus,int devfn) +{
[...]
drivers/pci/bus/config.c line 407
Quoted 5 lines
drivers/pci/bus/config.c +5
-0+ dev =kmalloc (sizeof (struct pci_dev ),GFP_KERNEL ); +if (!dev) +return NULL ; + +memset (dev,0 ,sizeof (struct pci_dev ));
kcalloc
[...]
drivers/pci/bus/config.c line 421
Quoted 3 lines
drivers/pci/bus/config.c +3
-0+/* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer) +set this higher, assuming the system even supports it. */ + dev->dma_mask =0xffffffff ;
DMA_32BIT_MASK
drivers/pci/bus/config.c line 433
Quoted 12 lines
drivers/pci/bus/config.c +12
-0+if (pci_setup_device (dev) <0 ) { +kfree (dev); +return NULL ; + } +device_initialize (&dev->dev); + dev->dev.release = pci_release_dev; +pci_dev_get (dev); + +pci_name_device (dev); + + dev->dev.dma_mask = &dev->dma_mask; + dev->dev.coherent_dma_mask =0xffffffffull ;
DMA_32BIT_MASK
[...]
drivers/pci/bus/config.c line 447
Quoted 10 lines
drivers/pci/bus/config.c +10
-0+struct pci_dev *__devinit +pci_scan_single_device (struct pci_bus *bus,int devfn) +{ +struct pci_dev *dev; + + dev =pci_scan_device (bus, devfn); +pci_scan_msi_device (dev); + +if (!dev) +return NULL ;
Why not do the test immediately ?
[...]
Quoted 2 lines
drivers/pci/bus/probe.c +0
-0
[...]
Quoted 1 line
+int
__devinitpci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass)
[...]
drivers/pci/bus/probe.c line 238
Quoted 4 lines
drivers/pci/bus/probe.c +4
-0+ +/* 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 ))
if (pci_find_bus(pci_domain_nr(bus), max + 1))
[...]
drivers/pci/bus/probe.c line 277
Quoted 6 lines
drivers/pci/bus/probe.c +6
-0+/* +* For CardBus bridges, we leave 4 bus numbers +* as cards with a PCI-to-PCI bridge can be +* inserted later. +*/ +for (i=0 ; i<CARDBUS_RESERVE_BUSNR ; i++)
for (i = 0; i < CARDBUS_RESERVE_BUSNR; i++)
[...]
Quoted 14 lines
drivers/pci/bus/probe.c +14
-0+int __devinit pci_scan_slot (struct pci_bus *bus,int devfn) +{ +int func, nr =0 ; +int scan_all_fns; + + scan_all_fns =pcibios_scan_all_fns (bus, devfn); + +for (func =0 ; func <8 ; func++, devfn++) { +struct pci_dev *dev; + + dev =pci_scan_single_device (bus, devfn); +if (dev) { + nr++; +
drivers/pci/bus/probe.c line 330
Quoted 10 lines
drivers/pci/bus/probe.c +10
-0+/* +* If this is a single function device, +* don't scan past the first function. +*/ +if (!dev->multifunction) { +if (func >0 ) { + dev->multifunction =1 ; + }else { +break ; + }
if (func == 0)
break;
dev->multifunction = 1;[...]
Quoted 2 lines
drivers/pci/bus/probe.c +2
-0+unsigned int __devinit pci_scan_child_bus (struct pci_bus *bus) +{
[...]
drivers/pci/bus/probe.c line 357
Quoted 2 lines
drivers/pci/bus/probe.c +2
-0+pcibios_fixup_bus (bus); +for (pass=0 ; pass <2 ; pass++)
for (pass = 0; pass < 2; pass++)
[...]
Quoted 5 lines
drivers/pci/bus/probe.c +5
-0+struct pci_bus *__devinit pci_scan_bus_parented (struct device *parent,int bus,struct pci_ops *ops,void *sysdata) +{ +int error; +struct pci_bus *b; +struct device *dev;
drivers/pci/bus/probe.c line 409
Quoted 10 lines
drivers/pci/bus/probe.c +10
-0+ + b =pci_alloc_bus (); +if (!b) +return NULL ; + + dev =kmalloc (sizeof (*dev),GFP_KERNEL ); +if (!dev){ +kfree (b); +return NULL ; + }
The code below uses goto. Why not here ?
Quoted 4 lines
drivers/pci/bus/probe.c +4
-0+ + b->sysdata = sysdata; + b->ops = ops; +
drivers/pci/bus/probe.c line 423
Quoted 10 lines
drivers/pci/bus/probe.c +10
-0+if (pci_find_bus (pci_domain_nr (b), bus)) { +/* If we already got to this bus through a different bridge, ignore it */ +pr_debug ("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));
kcalloc
drivers/pci/bus/probe.c line 429
Quoted 6 lines
drivers/pci/bus/probe.c +6
-0+ dev->parent = parent; + dev->release = pci_release_bus_bridge_dev; +sprintf (dev->bus_id,"pci%04x:%02x" ,pci_domain_nr (b), bus); + error =device_register (dev); +if (error) + goto dev_reg_err;
If you make this goto and the others 'err_WHAT_SHOULD_BE_DONE_some_number', one can verify the error branch without going forth and back.
drivers/pci/bus/probe.c line 436
Quoted 7 lines
drivers/pci/bus/probe.c +7
-0+ b->bridge =get_device (dev); + + b->class_dev.class = &pcibus_class; +sprintf (b->class_dev.class_id,"%04x:%02x" ,pci_domain_nr (b), bus); + error =class_device_register (&b->class_dev); +if (error) + goto class_dev_reg_err;
Should not "get_device" above be balanced ?
drivers/pci/bus/probe.c line 446
Quoted 10 lines
drivers/pci/bus/probe.c +10
-0+ error =class_device_create_file (&b->class_dev, &class_device_attr_cpuaffinity); +if (error) + goto class_dev_create_file_err; + +/* Create legacy_io and legacy_mem files for this bus */ +pci_create_legacy_files (b); + + error =sysfs_create_link (&b->class_dev.kobj, &b->bridge->kobj,"bridge" ); +if (error) + goto sys_create_link_err;
Add "pci_remove_legacy_files" on the error branch ?
Quoted 15 lines
drivers/pci/bus/probe.c +15
-0+ + b->number = b->secondary = bus; + b->resource[0 ] = &ioport_resource; + b->resource[1 ] = &iomem_resource; + + b->subordinate =pci_scan_child_bus (b); + +return b; + +sys_create_link_err: +class_device_remove_file (&b->class_dev, &class_device_attr_cpuaffinity); +class_dev_create_file_err: +class_device_unregister (&b->class_dev); +class_dev_reg_err: +device_unregister (dev);
drivers/pci/bus/probe.c line 471
Quoted 10 lines
drivers/pci/bus/probe.c +10
-0+dev_reg_err: +spin_lock (&pci_bus_lock); +list_del (&b->node); +spin_unlock (&pci_bus_lock); +err_out: +kfree (dev); +kfree (b); +return NULL ; +} +
--
Ueimor
Quoted 4 lines · Francois Romieu
Adam Belay <[email protected]> :
[...]Some nits + a suspect error branch. It seems nice otherwise.
If I'm correct, this patch only moves the code into different files, it doesn't change any of it, so your comments apply to the current code today, not Adam's changes :)
Quoted 12 lines
Quoted 2 lines
drivers/pci/bus/bus.c +0
-0[...]
drivers/pci/bus/bus.c line 61
Quoted 7 lines
drivers/pci/bus/bus.c +7
-0+struct pci_bus *pci_alloc_bus (void ) +{ +struct pci_bus *b; + + b =kmalloc (sizeof (*b),GFP_KERNEL ); +if (b) { +memset (b,0 ,sizeof (*b));
mm/slab.cprovides kcalloc.
Ick, I hate that function call, this is nicer :)
thanks,
greg k-h
Quoted 9 lines · Greg KH
Quoted 4 lines · Francois Romieu
Adam Belay <[email protected]> :
[...]Some nits + a suspect error branch. It seems nice otherwise.
If I'm correct, this patch only moves the code into different files, it doesn't change any of it, so your comments apply to the current code today, not Adam's changes :)
Correct. I've been trying to make my changes incremental. Nonetheless, I do appreciate the comments. I'll try to apply these fixes to my current tree.
Thanks,
Adam
Greg KH <[email protected]> :
Quoted 9 lines · Francois Romieu
Quoted 4 lines
Adam Belay <[email protected]> :
[...]Some nits + a suspect error branch. It seems nice otherwise.
If I'm correct, this patch only moves the code into different files, it doesn't change any of it, so your comments apply to the current code today, not Adam's changes :)
The summary of the serie advertised cleaner code (TM). I wish I could clean the clothes simply by moving them around.
[...]
Quoted 3 lines
Quoted 1 line
mm/slab.cprovides kcalloc.Ick, I hate that function call, this is nicer :)
No problem. I just want to be sure that janitors have noticed it. O:o)
--
Ueimor
I like it. I'm a little hung up on the fact that actual device probing happens in config.c rather than probe.c (if I'm correct). Regardless, this patch set cleans things up nicely.
John