add PCI bus registration support [2/9]
RFC PATCH 1/1 add PCI bus registration support [2/9]
This patch adds pci_add_bus() for PCI bus registration. It also moves pci_remove_bus() from remove.c to bus/bus.c for consistency.
drivers/pci/bus/bus.c +60 -1
@@ -9,6 +9,7 @@#include <linux/module.h> #include "bus.h" +#include "../pci.h" #undef DEBUG
@@ -50,7 +51,7 @@*/ /** -* pci_alloc_bus - allocates a "pci_bus" structure +* pci_alloc_bus - allocates a "pci_bus" structure */ struct pci_bus *pci_alloc_bus (void ) {
@@ -67,3 +68,61 @@ }EXPORT_SYMBOL (pci_alloc_bus); + +/** +* pci_add_bus - registers a bus with the pci bus class +* @bus: the bus +* +* Setup class data, register with the driver core, proc, etc... +*/ +int pci_add_bus (struct pci_bus *bus) +{ +int ret; + + bus->class_dev.class = &pcibus_class; +sprintf (bus->class_dev.class_id,"%04x:%02x" ,pci_domain_nr (bus), + bus->primary); + + ret =class_device_register (&bus->class_dev); +if (ret) +return ret; + +class_device_create_file (&bus->class_dev, + &class_device_attr_cpuaffinity); +if (bus->self) +sysfs_create_link (&bus->class_dev.kobj, + &bus->self->dev.kobj,"bridge" ); + +spin_lock (&pci_bus_lock); +list_add_tail (&bus->node, &bus->parent->children); +spin_unlock (&pci_bus_lock); + +pci_proc_attach_bus (bus); + +return 0 ; +} + +EXPORT_SYMBOL (pci_add_bus); + +/** +* pci_remove_bus - unregisters a bus with the pci bus class +* @bus: the bus +* +* Remove the bus from bus lists, remove proc/sysfs files, and unregister +* from the driver core. +*/ +void pci_remove_bus (struct pci_bus *pci_bus) +{ +pci_proc_detach_bus (pci_bus); + +spin_lock (&pci_bus_lock); +list_del (&pci_bus->node); +spin_unlock (&pci_bus_lock); +pci_remove_legacy_files (pci_bus); +class_device_remove_file (&pci_bus->class_dev, + &class_device_attr_cpuaffinity); +sysfs_remove_link (&pci_bus->class_dev.kobj,"bridge" ); +class_device_unregister (&pci_bus->class_dev); +} + +EXPORT_SYMBOL (pci_remove_bus);
drivers/pci/remove.c +0 -14
@@ -57,20 +57,6 @@ }EXPORT_SYMBOL (pci_remove_device_safe); -void pci_remove_bus (struct pci_bus *pci_bus) -{ -pci_proc_detach_bus (pci_bus); - -spin_lock (&pci_bus_lock); -list_del (&pci_bus->node); -spin_unlock (&pci_bus_lock); -pci_remove_legacy_files (pci_bus); -class_device_remove_file (&pci_bus->class_dev, - &class_device_attr_cpuaffinity); -sysfs_remove_link (&pci_bus->class_dev.kobj,"bridge" ); -class_device_unregister (&pci_bus->class_dev); -} -EXPORT_SYMBOL (pci_remove_bus);/** * pci_remove_bus_device - remove a PCI device and any children
include/linux/pci.h +2 -1
@@ -734,6 +734,8 @@/* Generic PCI functions used internally */ extern struct pci_bus *pci_alloc_bus (void ); +extern int pci_add_bus (struct pci_bus *bus); +extern void pci_remove_bus (struct pci_bus *bus);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);
@@ -756,7 +758,6 @@int pci_get_interrupt_pin (struct pci_dev *dev,struct pci_dev **bridge);extern struct pci_dev *pci_dev_get (struct pci_dev *dev);extern void pci_dev_put (struct pci_dev *dev); -extern void pci_remove_bus (struct pci_bus *b);extern void pci_remove_bus_device (struct pci_dev *dev);/* Generic PCI functions exported to card drivers */
Quoted 1 line · Adam Belay
+EXPORT_SYMBOL(pci_add_bus);
This doens't need to be exported, right? No module uses it. But if they do, I suggest EXPORT_SYMBOL_GPL() instead, is that ok?
thanks,
greg k-h
Quoted 9 lines · Greg KH
Quoted 1 line · Adam Belay
+EXPORT_SYMBOL(pci_add_bus);
This doens't need to be exported, right? No module uses it. But if they do, I suggest
EXPORT_SYMBOL_GPL()instead, is that ok?thanks,
greg k-h
Yes, no module currently uses it, but now that "pci_driver" is supported, any PCI bridge driver could potentially be made into a module. In theory, this could even include the PCI<->PCI bridge driver. I also wanted to export this as a module so that it would be easier to add new drivers for more unusual bridge hardware. EXPORT_SYMBOL_GPL() would be fine.
Thanks,
Adam