PCI: make pci_bus a struct device

This moves the pci_bus class device to be a real struct device and at
the same time, place it in the device tree in the correct location.

Note, the old "bridge" symlink is now gone, but this was a non-standard
link and no userspace program used it. If you need to determine the
device that the bus is on, follow the standard device symlink, or walk
up the device tree.


Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

+46 -53
+13 -4
drivers/pci/bus.c
··· 108 void pci_bus_add_devices(struct pci_bus *bus) 109 { 110 struct pci_dev *dev; 111 int retval; 112 113 list_for_each_entry(dev, &bus->devices, bus_list) { ··· 139 up_write(&pci_bus_sem); 140 } 141 pci_bus_add_devices(dev->subordinate); 142 - retval = sysfs_create_link(&dev->subordinate->class_dev.kobj, 143 - &dev->dev.kobj, "bridge"); 144 if (retval) 145 - dev_err(&dev->dev, "Error creating sysfs " 146 - "bridge symlink, continuing...\n"); 147 } 148 } 149 }
··· 108 void pci_bus_add_devices(struct pci_bus *bus) 109 { 110 struct pci_dev *dev; 111 + struct pci_bus *child_bus; 112 int retval; 113 114 list_for_each_entry(dev, &bus->devices, bus_list) { ··· 138 up_write(&pci_bus_sem); 139 } 140 pci_bus_add_devices(dev->subordinate); 141 + 142 + /* register the bus with sysfs as the parent is now 143 + * properly registered. */ 144 + child_bus = dev->subordinate; 145 + child_bus->dev.parent = child_bus->bridge; 146 + retval = device_register(&child_bus->dev); 147 + if (!retval) 148 + retval = device_create_file(&child_bus->dev, 149 + &dev_attr_cpuaffinity); 150 if (retval) 151 + dev_err(&dev->dev, "Error registering pci_bus" 152 + " device bridge symlink," 153 + " continuing...\n"); 154 } 155 } 156 }
+3 -3
drivers/pci/pci-sysfs.c
··· 359 char *buf, loff_t off, size_t count) 360 { 361 struct pci_bus *bus = to_pci_bus(container_of(kobj, 362 - struct class_device, 363 kobj)); 364 365 /* Only support 1, 2 or 4 byte accesses */ ··· 384 char *buf, loff_t off, size_t count) 385 { 386 struct pci_bus *bus = to_pci_bus(container_of(kobj, 387 - struct class_device, 388 kobj)); 389 /* Only support 1, 2 or 4 byte accesses */ 390 if (count != 1 && count != 2 && count != 4) ··· 408 struct vm_area_struct *vma) 409 { 410 struct pci_bus *bus = to_pci_bus(container_of(kobj, 411 - struct class_device, 412 kobj)); 413 414 return pci_mmap_legacy_page_range(bus, vma);
··· 359 char *buf, loff_t off, size_t count) 360 { 361 struct pci_bus *bus = to_pci_bus(container_of(kobj, 362 + struct device, 363 kobj)); 364 365 /* Only support 1, 2 or 4 byte accesses */ ··· 384 char *buf, loff_t off, size_t count) 385 { 386 struct pci_bus *bus = to_pci_bus(container_of(kobj, 387 + struct device, 388 kobj)); 389 /* Only support 1, 2 or 4 byte accesses */ 390 if (count != 1 && count != 2 && count != 4) ··· 408 struct vm_area_struct *vma) 409 { 410 struct pci_bus *bus = to_pci_bus(container_of(kobj, 411 + struct device, 412 kobj)); 413 414 return pci_mmap_legacy_page_range(bus, vma);
+1 -1
drivers/pci/pci.h
··· 64 } 65 extern int pcie_mch_quirk; 66 extern struct device_attribute pci_dev_attrs[]; 67 - extern struct class_device_attribute class_device_attr_cpuaffinity; 68 69 /** 70 * pci_match_one_device - Tell if a PCI device structure has a matching
··· 64 } 65 extern int pcie_mch_quirk; 66 extern struct device_attribute pci_dev_attrs[]; 67 + extern struct device_attribute dev_attr_cpuaffinity; 68 69 /** 70 * pci_match_one_device - Tell if a PCI device structure has a matching
+25 -39
drivers/pci/probe.c
··· 54 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; 55 b->legacy_io->read = pci_read_legacy_io; 56 b->legacy_io->write = pci_write_legacy_io; 57 - class_device_create_bin_file(&b->class_dev, b->legacy_io); 58 59 /* Allocated above after the legacy_io struct */ 60 b->legacy_mem = b->legacy_io + 1; ··· 62 b->legacy_mem->size = 1024*1024; 63 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; 64 b->legacy_mem->mmap = pci_mmap_legacy_mem; 65 - class_device_create_bin_file(&b->class_dev, b->legacy_mem); 66 } 67 } 68 69 void pci_remove_legacy_files(struct pci_bus *b) 70 { 71 if (b->legacy_io) { 72 - class_device_remove_bin_file(&b->class_dev, b->legacy_io); 73 - class_device_remove_bin_file(&b->class_dev, b->legacy_mem); 74 kfree(b->legacy_io); /* both are allocated here */ 75 } 76 } ··· 82 /* 83 * PCI Bus Class Devices 84 */ 85 - static ssize_t pci_bus_show_cpuaffinity(struct class_device *class_dev, 86 char *buf) 87 { 88 int ret; 89 cpumask_t cpumask; 90 91 - cpumask = pcibus_to_cpumask(to_pci_bus(class_dev)); 92 ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask); 93 if (ret < PAGE_SIZE) 94 buf[ret++] = '\n'; 95 return ret; 96 } 97 - CLASS_DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL); 98 99 /* 100 * PCI Bus Class 101 */ 102 - static void release_pcibus_dev(struct class_device *class_dev) 103 { 104 - struct pci_bus *pci_bus = to_pci_bus(class_dev); 105 106 if (pci_bus->bridge) 107 put_device(pci_bus->bridge); ··· 111 112 static struct class pcibus_class = { 113 .name = "pci_bus", 114 - .release = &release_pcibus_dev, 115 }; 116 117 static int __init pcibus_class_init(void) ··· 394 { 395 struct pci_bus *child; 396 int i; 397 - int retval; 398 399 /* 400 * Allocate a new bus, and inherit stuff from the parent.. ··· 409 child->bus_flags = parent->bus_flags; 410 child->bridge = get_device(&bridge->dev); 411 412 - child->class_dev.class = &pcibus_class; 413 - sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr); 414 - retval = class_device_register(&child->class_dev); 415 - if (retval) 416 - goto error_register; 417 - retval = class_device_create_file(&child->class_dev, 418 - &class_device_attr_cpuaffinity); 419 - if (retval) 420 - goto error_file_create; 421 422 /* 423 * Set up the primary, secondary and subordinate ··· 432 bridge->subordinate = child; 433 434 return child; 435 - 436 - error_file_create: 437 - class_device_unregister(&child->class_dev); 438 - error_register: 439 - kfree(child); 440 - return NULL; 441 } 442 443 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr) ··· 1098 goto dev_reg_err; 1099 b->bridge = get_device(dev); 1100 1101 - b->class_dev.class = &pcibus_class; 1102 - sprintf(b->class_dev.class_id, "%04x:%02x", pci_domain_nr(b), bus); 1103 - error = class_device_register(&b->class_dev); 1104 if (error) 1105 goto class_dev_reg_err; 1106 - error = class_device_create_file(&b->class_dev, &class_device_attr_cpuaffinity); 1107 if (error) 1108 - goto class_dev_create_file_err; 1109 1110 /* Create legacy_io and legacy_mem files for this bus */ 1111 pci_create_legacy_files(b); 1112 - 1113 - error = sysfs_create_link(&b->class_dev.kobj, &b->bridge->kobj, "bridge"); 1114 - if (error) 1115 - goto sys_create_link_err; 1116 1117 b->number = b->secondary = bus; 1118 b->resource[0] = &ioport_resource; ··· 1117 1118 return b; 1119 1120 - sys_create_link_err: 1121 - class_device_remove_file(&b->class_dev, &class_device_attr_cpuaffinity); 1122 - class_dev_create_file_err: 1123 - class_device_unregister(&b->class_dev); 1124 class_dev_reg_err: 1125 device_unregister(dev); 1126 dev_reg_err:
··· 54 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; 55 b->legacy_io->read = pci_read_legacy_io; 56 b->legacy_io->write = pci_write_legacy_io; 57 + device_create_bin_file(&b->dev, b->legacy_io); 58 59 /* Allocated above after the legacy_io struct */ 60 b->legacy_mem = b->legacy_io + 1; ··· 62 b->legacy_mem->size = 1024*1024; 63 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; 64 b->legacy_mem->mmap = pci_mmap_legacy_mem; 65 + device_create_bin_file(&b->dev, b->legacy_mem); 66 } 67 } 68 69 void pci_remove_legacy_files(struct pci_bus *b) 70 { 71 if (b->legacy_io) { 72 + device_remove_bin_file(&b->dev, b->legacy_io); 73 + device_remove_bin_file(&b->dev, b->legacy_mem); 74 kfree(b->legacy_io); /* both are allocated here */ 75 } 76 } ··· 82 /* 83 * PCI Bus Class Devices 84 */ 85 + static ssize_t pci_bus_show_cpuaffinity(struct device *dev, 86 + struct device_attribute *attr, 87 char *buf) 88 { 89 int ret; 90 cpumask_t cpumask; 91 92 + cpumask = pcibus_to_cpumask(to_pci_bus(dev)); 93 ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask); 94 if (ret < PAGE_SIZE) 95 buf[ret++] = '\n'; 96 return ret; 97 } 98 + DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL); 99 100 /* 101 * PCI Bus Class 102 */ 103 + static void release_pcibus_dev(struct device *dev) 104 { 105 + struct pci_bus *pci_bus = to_pci_bus(dev); 106 107 if (pci_bus->bridge) 108 put_device(pci_bus->bridge); ··· 110 111 static struct class pcibus_class = { 112 .name = "pci_bus", 113 + .dev_release = &release_pcibus_dev, 114 }; 115 116 static int __init pcibus_class_init(void) ··· 393 { 394 struct pci_bus *child; 395 int i; 396 397 /* 398 * Allocate a new bus, and inherit stuff from the parent.. ··· 409 child->bus_flags = parent->bus_flags; 410 child->bridge = get_device(&bridge->dev); 411 412 + /* initialize some portions of the bus device, but don't register it 413 + * now as the parent is not properly set up yet. This device will get 414 + * registered later in pci_bus_add_devices() 415 + */ 416 + child->dev.class = &pcibus_class; 417 + sprintf(child->dev.bus_id, "%04x:%02x", pci_domain_nr(child), busnr); 418 419 /* 420 * Set up the primary, secondary and subordinate ··· 435 bridge->subordinate = child; 436 437 return child; 438 } 439 440 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr) ··· 1107 goto dev_reg_err; 1108 b->bridge = get_device(dev); 1109 1110 + b->dev.class = &pcibus_class; 1111 + b->dev.parent = b->bridge; 1112 + sprintf(b->dev.bus_id, "%04x:%02x", pci_domain_nr(b), bus); 1113 + error = device_register(&b->dev); 1114 if (error) 1115 goto class_dev_reg_err; 1116 + error = device_create_file(&b->dev, &dev_attr_cpuaffinity); 1117 if (error) 1118 + goto dev_create_file_err; 1119 1120 /* Create legacy_io and legacy_mem files for this bus */ 1121 pci_create_legacy_files(b); 1122 1123 b->number = b->secondary = bus; 1124 b->resource[0] = &ioport_resource; ··· 1129 1130 return b; 1131 1132 + dev_create_file_err: 1133 + device_unregister(&b->dev); 1134 class_dev_reg_err: 1135 device_unregister(dev); 1136 dev_reg_err:
+2 -4
drivers/pci/remove.c
··· 78 list_del(&pci_bus->node); 79 up_write(&pci_bus_sem); 80 pci_remove_legacy_files(pci_bus); 81 - class_device_remove_file(&pci_bus->class_dev, 82 - &class_device_attr_cpuaffinity); 83 - sysfs_remove_link(&pci_bus->class_dev.kobj, "bridge"); 84 - class_device_unregister(&pci_bus->class_dev); 85 } 86 EXPORT_SYMBOL(pci_remove_bus); 87
··· 78 list_del(&pci_bus->node); 79 up_write(&pci_bus_sem); 80 pci_remove_legacy_files(pci_bus); 81 + device_remove_file(&pci_bus->dev, &dev_attr_cpuaffinity); 82 + device_unregister(&pci_bus->dev); 83 } 84 EXPORT_SYMBOL(pci_remove_bus); 85
+2 -2
include/linux/pci.h
··· 278 unsigned short bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */ 279 pci_bus_flags_t bus_flags; /* Inherited by child busses */ 280 struct device *bridge; 281 - struct class_device class_dev; 282 struct bin_attribute *legacy_io; /* legacy I/O for this bus */ 283 struct bin_attribute *legacy_mem; /* legacy mem */ 284 }; 285 286 #define pci_bus_b(n) list_entry(n, struct pci_bus, node) 287 - #define to_pci_bus(n) container_of(n, struct pci_bus, class_dev) 288 289 /* 290 * Error values that may be returned by PCI functions.
··· 278 unsigned short bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */ 279 pci_bus_flags_t bus_flags; /* Inherited by child busses */ 280 struct device *bridge; 281 + struct device dev; 282 struct bin_attribute *legacy_io; /* legacy I/O for this bus */ 283 struct bin_attribute *legacy_mem; /* legacy mem */ 284 }; 285 286 #define pci_bus_b(n) list_entry(n, struct pci_bus, node) 287 + #define to_pci_bus(n) container_of(n, struct pci_bus, dev) 288 289 /* 290 * Error values that may be returned by PCI functions.