diff options
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r-- | drivers/pci/probe.c | 80 |
1 files changed, 34 insertions, 46 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 5fd585293e79..8b505bd925aa 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/slab.h> | 9 | #include <linux/slab.h> |
10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
11 | #include <linux/cpumask.h> | 11 | #include <linux/cpumask.h> |
12 | #include <linux/aspm.h> | ||
12 | #include "pci.h" | 13 | #include "pci.h" |
13 | 14 | ||
14 | #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ | 15 | #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ |
@@ -53,7 +54,7 @@ static void pci_create_legacy_files(struct pci_bus *b) | |||
53 | b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; | 54 | b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; |
54 | b->legacy_io->read = pci_read_legacy_io; | 55 | b->legacy_io->read = pci_read_legacy_io; |
55 | b->legacy_io->write = pci_write_legacy_io; | 56 | b->legacy_io->write = pci_write_legacy_io; |
56 | class_device_create_bin_file(&b->class_dev, b->legacy_io); | 57 | device_create_bin_file(&b->dev, b->legacy_io); |
57 | 58 | ||
58 | /* Allocated above after the legacy_io struct */ | 59 | /* Allocated above after the legacy_io struct */ |
59 | b->legacy_mem = b->legacy_io + 1; | 60 | b->legacy_mem = b->legacy_io + 1; |
@@ -61,15 +62,15 @@ static void pci_create_legacy_files(struct pci_bus *b) | |||
61 | b->legacy_mem->size = 1024*1024; | 62 | b->legacy_mem->size = 1024*1024; |
62 | b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; | 63 | b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; |
63 | b->legacy_mem->mmap = pci_mmap_legacy_mem; | 64 | b->legacy_mem->mmap = pci_mmap_legacy_mem; |
64 | class_device_create_bin_file(&b->class_dev, b->legacy_mem); | 65 | device_create_bin_file(&b->dev, b->legacy_mem); |
65 | } | 66 | } |
66 | } | 67 | } |
67 | 68 | ||
68 | void pci_remove_legacy_files(struct pci_bus *b) | 69 | void pci_remove_legacy_files(struct pci_bus *b) |
69 | { | 70 | { |
70 | if (b->legacy_io) { | 71 | if (b->legacy_io) { |
71 | class_device_remove_bin_file(&b->class_dev, b->legacy_io); | 72 | device_remove_bin_file(&b->dev, b->legacy_io); |
72 | class_device_remove_bin_file(&b->class_dev, b->legacy_mem); | 73 | device_remove_bin_file(&b->dev, b->legacy_mem); |
73 | kfree(b->legacy_io); /* both are allocated here */ | 74 | kfree(b->legacy_io); /* both are allocated here */ |
74 | } | 75 | } |
75 | } | 76 | } |
@@ -81,26 +82,27 @@ void pci_remove_legacy_files(struct pci_bus *bus) { return; } | |||
81 | /* | 82 | /* |
82 | * PCI Bus Class Devices | 83 | * PCI Bus Class Devices |
83 | */ | 84 | */ |
84 | 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, | ||
85 | char *buf) | 87 | char *buf) |
86 | { | 88 | { |
87 | int ret; | 89 | int ret; |
88 | cpumask_t cpumask; | 90 | cpumask_t cpumask; |
89 | 91 | ||
90 | cpumask = pcibus_to_cpumask(to_pci_bus(class_dev)); | 92 | cpumask = pcibus_to_cpumask(to_pci_bus(dev)); |
91 | ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask); | 93 | ret = cpumask_scnprintf(buf, PAGE_SIZE, cpumask); |
92 | if (ret < PAGE_SIZE) | 94 | if (ret < PAGE_SIZE) |
93 | buf[ret++] = '\n'; | 95 | buf[ret++] = '\n'; |
94 | return ret; | 96 | return ret; |
95 | } | 97 | } |
96 | CLASS_DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL); | 98 | DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpuaffinity, NULL); |
97 | 99 | ||
98 | /* | 100 | /* |
99 | * PCI Bus Class | 101 | * PCI Bus Class |
100 | */ | 102 | */ |
101 | static void release_pcibus_dev(struct class_device *class_dev) | 103 | static void release_pcibus_dev(struct device *dev) |
102 | { | 104 | { |
103 | struct pci_bus *pci_bus = to_pci_bus(class_dev); | 105 | struct pci_bus *pci_bus = to_pci_bus(dev); |
104 | 106 | ||
105 | if (pci_bus->bridge) | 107 | if (pci_bus->bridge) |
106 | put_device(pci_bus->bridge); | 108 | put_device(pci_bus->bridge); |
@@ -109,7 +111,7 @@ static void release_pcibus_dev(struct class_device *class_dev) | |||
109 | 111 | ||
110 | static struct class pcibus_class = { | 112 | static struct class pcibus_class = { |
111 | .name = "pci_bus", | 113 | .name = "pci_bus", |
112 | .release = &release_pcibus_dev, | 114 | .dev_release = &release_pcibus_dev, |
113 | }; | 115 | }; |
114 | 116 | ||
115 | static int __init pcibus_class_init(void) | 117 | static int __init pcibus_class_init(void) |
@@ -392,7 +394,6 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr) | |||
392 | { | 394 | { |
393 | struct pci_bus *child; | 395 | struct pci_bus *child; |
394 | int i; | 396 | int i; |
395 | int retval; | ||
396 | 397 | ||
397 | /* | 398 | /* |
398 | * Allocate a new bus, and inherit stuff from the parent.. | 399 | * Allocate a new bus, and inherit stuff from the parent.. |
@@ -408,15 +409,12 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr) | |||
408 | child->bus_flags = parent->bus_flags; | 409 | child->bus_flags = parent->bus_flags; |
409 | child->bridge = get_device(&bridge->dev); | 410 | child->bridge = get_device(&bridge->dev); |
410 | 411 | ||
411 | child->class_dev.class = &pcibus_class; | 412 | /* initialize some portions of the bus device, but don't register it |
412 | sprintf(child->class_dev.class_id, "%04x:%02x", pci_domain_nr(child), busnr); | 413 | * now as the parent is not properly set up yet. This device will get |
413 | retval = class_device_register(&child->class_dev); | 414 | * registered later in pci_bus_add_devices() |
414 | if (retval) | 415 | */ |
415 | goto error_register; | 416 | child->dev.class = &pcibus_class; |
416 | retval = class_device_create_file(&child->class_dev, | 417 | sprintf(child->dev.bus_id, "%04x:%02x", pci_domain_nr(child), busnr); |
417 | &class_device_attr_cpuaffinity); | ||
418 | if (retval) | ||
419 | goto error_file_create; | ||
420 | 418 | ||
421 | /* | 419 | /* |
422 | * Set up the primary, secondary and subordinate | 420 | * Set up the primary, secondary and subordinate |
@@ -434,12 +432,6 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr) | |||
434 | bridge->subordinate = child; | 432 | bridge->subordinate = child; |
435 | 433 | ||
436 | return child; | 434 | return child; |
437 | |||
438 | error_file_create: | ||
439 | class_device_unregister(&child->class_dev); | ||
440 | error_register: | ||
441 | kfree(child); | ||
442 | return NULL; | ||
443 | } | 435 | } |
444 | 436 | ||
445 | struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr) | 437 | struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr) |
@@ -471,8 +463,6 @@ static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max) | |||
471 | } | 463 | } |
472 | } | 464 | } |
473 | 465 | ||
474 | unsigned int pci_scan_child_bus(struct pci_bus *bus); | ||
475 | |||
476 | /* | 466 | /* |
477 | * If it's a bridge, configure it and scan the bus behind it. | 467 | * If it's a bridge, configure it and scan the bus behind it. |
478 | * For CardBus bridges, we don't scan behind as the devices will | 468 | * For CardBus bridges, we don't scan behind as the devices will |
@@ -641,13 +631,13 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass | |||
641 | (child->number > bus->subordinate) || | 631 | (child->number > bus->subordinate) || |
642 | (child->number < bus->number) || | 632 | (child->number < bus->number) || |
643 | (child->subordinate < bus->number)) { | 633 | (child->subordinate < bus->number)) { |
644 | pr_debug("PCI: Bus #%02x (-#%02x) is %s" | 634 | pr_debug("PCI: Bus #%02x (-#%02x) is %s " |
645 | "hidden behind%s bridge #%02x (-#%02x)\n", | 635 | "hidden behind%s bridge #%02x (-#%02x)\n", |
646 | child->number, child->subordinate, | 636 | child->number, child->subordinate, |
647 | (bus->number > child->subordinate && | 637 | (bus->number > child->subordinate && |
648 | bus->subordinate < child->number) ? | 638 | bus->subordinate < child->number) ? |
649 | "wholly " : " partially", | 639 | "wholly" : "partially", |
650 | bus->self->transparent ? " transparent" : " ", | 640 | bus->self->transparent ? " transparent" : "", |
651 | bus->number, bus->subordinate); | 641 | bus->number, bus->subordinate); |
652 | } | 642 | } |
653 | bus = bus->parent; | 643 | bus = bus->parent; |
@@ -971,6 +961,7 @@ struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn) | |||
971 | 961 | ||
972 | return dev; | 962 | return dev; |
973 | } | 963 | } |
964 | EXPORT_SYMBOL(pci_scan_single_device); | ||
974 | 965 | ||
975 | /** | 966 | /** |
976 | * pci_scan_slot - scan a PCI slot on a bus for devices. | 967 | * pci_scan_slot - scan a PCI slot on a bus for devices. |
@@ -1011,6 +1002,10 @@ int pci_scan_slot(struct pci_bus *bus, int devfn) | |||
1011 | break; | 1002 | break; |
1012 | } | 1003 | } |
1013 | } | 1004 | } |
1005 | |||
1006 | if (bus->self) | ||
1007 | pcie_aspm_init_link_state(bus->self); | ||
1008 | |||
1014 | return nr; | 1009 | return nr; |
1015 | } | 1010 | } |
1016 | 1011 | ||
@@ -1103,32 +1098,27 @@ struct pci_bus * pci_create_bus(struct device *parent, | |||
1103 | goto dev_reg_err; | 1098 | goto dev_reg_err; |
1104 | b->bridge = get_device(dev); | 1099 | b->bridge = get_device(dev); |
1105 | 1100 | ||
1106 | b->class_dev.class = &pcibus_class; | 1101 | b->dev.class = &pcibus_class; |
1107 | sprintf(b->class_dev.class_id, "%04x:%02x", pci_domain_nr(b), bus); | 1102 | b->dev.parent = b->bridge; |
1108 | error = class_device_register(&b->class_dev); | 1103 | sprintf(b->dev.bus_id, "%04x:%02x", pci_domain_nr(b), bus); |
1104 | error = device_register(&b->dev); | ||
1109 | if (error) | 1105 | if (error) |
1110 | goto class_dev_reg_err; | 1106 | goto class_dev_reg_err; |
1111 | error = class_device_create_file(&b->class_dev, &class_device_attr_cpuaffinity); | 1107 | error = device_create_file(&b->dev, &dev_attr_cpuaffinity); |
1112 | if (error) | 1108 | if (error) |
1113 | goto class_dev_create_file_err; | 1109 | goto dev_create_file_err; |
1114 | 1110 | ||
1115 | /* Create legacy_io and legacy_mem files for this bus */ | 1111 | /* Create legacy_io and legacy_mem files for this bus */ |
1116 | pci_create_legacy_files(b); | 1112 | pci_create_legacy_files(b); |
1117 | 1113 | ||
1118 | error = sysfs_create_link(&b->class_dev.kobj, &b->bridge->kobj, "bridge"); | ||
1119 | if (error) | ||
1120 | goto sys_create_link_err; | ||
1121 | |||
1122 | b->number = b->secondary = bus; | 1114 | b->number = b->secondary = bus; |
1123 | b->resource[0] = &ioport_resource; | 1115 | b->resource[0] = &ioport_resource; |
1124 | b->resource[1] = &iomem_resource; | 1116 | b->resource[1] = &iomem_resource; |
1125 | 1117 | ||
1126 | return b; | 1118 | return b; |
1127 | 1119 | ||
1128 | sys_create_link_err: | 1120 | dev_create_file_err: |
1129 | class_device_remove_file(&b->class_dev, &class_device_attr_cpuaffinity); | 1121 | device_unregister(&b->dev); |
1130 | class_dev_create_file_err: | ||
1131 | class_device_unregister(&b->class_dev); | ||
1132 | class_dev_reg_err: | 1122 | class_dev_reg_err: |
1133 | device_unregister(dev); | 1123 | device_unregister(dev); |
1134 | dev_reg_err: | 1124 | dev_reg_err: |
@@ -1140,7 +1130,6 @@ err_out: | |||
1140 | kfree(b); | 1130 | kfree(b); |
1141 | return NULL; | 1131 | return NULL; |
1142 | } | 1132 | } |
1143 | EXPORT_SYMBOL_GPL(pci_create_bus); | ||
1144 | 1133 | ||
1145 | struct pci_bus *pci_scan_bus_parented(struct device *parent, | 1134 | struct pci_bus *pci_scan_bus_parented(struct device *parent, |
1146 | int bus, struct pci_ops *ops, void *sysdata) | 1135 | int bus, struct pci_ops *ops, void *sysdata) |
@@ -1159,7 +1148,6 @@ EXPORT_SYMBOL(pci_add_new_bus); | |||
1159 | EXPORT_SYMBOL(pci_do_scan_bus); | 1148 | EXPORT_SYMBOL(pci_do_scan_bus); |
1160 | EXPORT_SYMBOL(pci_scan_slot); | 1149 | EXPORT_SYMBOL(pci_scan_slot); |
1161 | EXPORT_SYMBOL(pci_scan_bridge); | 1150 | EXPORT_SYMBOL(pci_scan_bridge); |
1162 | EXPORT_SYMBOL(pci_scan_single_device); | ||
1163 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); | 1151 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); |
1164 | #endif | 1152 | #endif |
1165 | 1153 | ||