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