diff options
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r-- | drivers/pci/probe.c | 176 |
1 files changed, 102 insertions, 74 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 38e403dddf6e..04796c056d12 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -16,7 +16,7 @@ | |||
16 | #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ | 16 | #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ |
17 | #define CARDBUS_RESERVE_BUSNR 3 | 17 | #define CARDBUS_RESERVE_BUSNR 3 |
18 | 18 | ||
19 | struct resource busn_resource = { | 19 | static struct resource busn_resource = { |
20 | .name = "PCI busn", | 20 | .name = "PCI busn", |
21 | .start = 0, | 21 | .start = 0, |
22 | .end = 255, | 22 | .end = 255, |
@@ -269,8 +269,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
269 | region.end = l + sz; | 269 | region.end = l + sz; |
270 | } | 270 | } |
271 | 271 | ||
272 | pcibios_bus_to_resource(dev, res, ®ion); | 272 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
273 | pcibios_resource_to_bus(dev, &inverted_region, res); | 273 | pcibios_resource_to_bus(dev->bus, &inverted_region, res); |
274 | 274 | ||
275 | /* | 275 | /* |
276 | * If "A" is a BAR value (a bus address), "bus_to_resource(A)" is | 276 | * If "A" is a BAR value (a bus address), "bus_to_resource(A)" is |
@@ -364,7 +364,7 @@ static void pci_read_bridge_io(struct pci_bus *child) | |||
364 | res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; | 364 | res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; |
365 | region.start = base; | 365 | region.start = base; |
366 | region.end = limit + io_granularity - 1; | 366 | region.end = limit + io_granularity - 1; |
367 | pcibios_bus_to_resource(dev, res, ®ion); | 367 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
368 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); | 368 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); |
369 | } | 369 | } |
370 | } | 370 | } |
@@ -386,7 +386,7 @@ static void pci_read_bridge_mmio(struct pci_bus *child) | |||
386 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; | 386 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; |
387 | region.start = base; | 387 | region.start = base; |
388 | region.end = limit + 0xfffff; | 388 | region.end = limit + 0xfffff; |
389 | pcibios_bus_to_resource(dev, res, ®ion); | 389 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
390 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); | 390 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); |
391 | } | 391 | } |
392 | } | 392 | } |
@@ -436,7 +436,7 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child) | |||
436 | res->flags |= IORESOURCE_MEM_64; | 436 | res->flags |= IORESOURCE_MEM_64; |
437 | region.start = base; | 437 | region.start = base; |
438 | region.end = limit + 0xfffff; | 438 | region.end = limit + 0xfffff; |
439 | pcibios_bus_to_resource(dev, res, ®ion); | 439 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
440 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); | 440 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); |
441 | } | 441 | } |
442 | } | 442 | } |
@@ -518,7 +518,7 @@ static struct pci_host_bridge *pci_alloc_host_bridge(struct pci_bus *b) | |||
518 | return bridge; | 518 | return bridge; |
519 | } | 519 | } |
520 | 520 | ||
521 | const unsigned char pcix_bus_speed[] = { | 521 | static const unsigned char pcix_bus_speed[] = { |
522 | PCI_SPEED_UNKNOWN, /* 0 */ | 522 | PCI_SPEED_UNKNOWN, /* 0 */ |
523 | PCI_SPEED_66MHz_PCIX, /* 1 */ | 523 | PCI_SPEED_66MHz_PCIX, /* 1 */ |
524 | PCI_SPEED_100MHz_PCIX, /* 2 */ | 524 | PCI_SPEED_100MHz_PCIX, /* 2 */ |
@@ -999,6 +999,60 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev) | |||
999 | pdev->is_hotplug_bridge = 1; | 999 | pdev->is_hotplug_bridge = 1; |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | |||
1003 | /** | ||
1004 | * pci_cfg_space_size - get the configuration space size of the PCI device. | ||
1005 | * @dev: PCI device | ||
1006 | * | ||
1007 | * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices | ||
1008 | * have 4096 bytes. Even if the device is capable, that doesn't mean we can | ||
1009 | * access it. Maybe we don't have a way to generate extended config space | ||
1010 | * accesses, or the device is behind a reverse Express bridge. So we try | ||
1011 | * reading the dword at 0x100 which must either be 0 or a valid extended | ||
1012 | * capability header. | ||
1013 | */ | ||
1014 | static int pci_cfg_space_size_ext(struct pci_dev *dev) | ||
1015 | { | ||
1016 | u32 status; | ||
1017 | int pos = PCI_CFG_SPACE_SIZE; | ||
1018 | |||
1019 | if (pci_read_config_dword(dev, pos, &status) != PCIBIOS_SUCCESSFUL) | ||
1020 | goto fail; | ||
1021 | if (status == 0xffffffff) | ||
1022 | goto fail; | ||
1023 | |||
1024 | return PCI_CFG_SPACE_EXP_SIZE; | ||
1025 | |||
1026 | fail: | ||
1027 | return PCI_CFG_SPACE_SIZE; | ||
1028 | } | ||
1029 | |||
1030 | int pci_cfg_space_size(struct pci_dev *dev) | ||
1031 | { | ||
1032 | int pos; | ||
1033 | u32 status; | ||
1034 | u16 class; | ||
1035 | |||
1036 | class = dev->class >> 8; | ||
1037 | if (class == PCI_CLASS_BRIDGE_HOST) | ||
1038 | return pci_cfg_space_size_ext(dev); | ||
1039 | |||
1040 | if (!pci_is_pcie(dev)) { | ||
1041 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); | ||
1042 | if (!pos) | ||
1043 | goto fail; | ||
1044 | |||
1045 | pci_read_config_dword(dev, pos + PCI_X_STATUS, &status); | ||
1046 | if (!(status & (PCI_X_STATUS_266MHZ | PCI_X_STATUS_533MHZ))) | ||
1047 | goto fail; | ||
1048 | } | ||
1049 | |||
1050 | return pci_cfg_space_size_ext(dev); | ||
1051 | |||
1052 | fail: | ||
1053 | return PCI_CFG_SPACE_SIZE; | ||
1054 | } | ||
1055 | |||
1002 | #define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED) | 1056 | #define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED) |
1003 | 1057 | ||
1004 | /** | 1058 | /** |
@@ -1084,24 +1138,24 @@ int pci_setup_device(struct pci_dev *dev) | |||
1084 | region.end = 0x1F7; | 1138 | region.end = 0x1F7; |
1085 | res = &dev->resource[0]; | 1139 | res = &dev->resource[0]; |
1086 | res->flags = LEGACY_IO_RESOURCE; | 1140 | res->flags = LEGACY_IO_RESOURCE; |
1087 | pcibios_bus_to_resource(dev, res, ®ion); | 1141 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1088 | region.start = 0x3F6; | 1142 | region.start = 0x3F6; |
1089 | region.end = 0x3F6; | 1143 | region.end = 0x3F6; |
1090 | res = &dev->resource[1]; | 1144 | res = &dev->resource[1]; |
1091 | res->flags = LEGACY_IO_RESOURCE; | 1145 | res->flags = LEGACY_IO_RESOURCE; |
1092 | pcibios_bus_to_resource(dev, res, ®ion); | 1146 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1093 | } | 1147 | } |
1094 | if ((progif & 4) == 0) { | 1148 | if ((progif & 4) == 0) { |
1095 | region.start = 0x170; | 1149 | region.start = 0x170; |
1096 | region.end = 0x177; | 1150 | region.end = 0x177; |
1097 | res = &dev->resource[2]; | 1151 | res = &dev->resource[2]; |
1098 | res->flags = LEGACY_IO_RESOURCE; | 1152 | res->flags = LEGACY_IO_RESOURCE; |
1099 | pcibios_bus_to_resource(dev, res, ®ion); | 1153 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1100 | region.start = 0x376; | 1154 | region.start = 0x376; |
1101 | region.end = 0x376; | 1155 | region.end = 0x376; |
1102 | res = &dev->resource[3]; | 1156 | res = &dev->resource[3]; |
1103 | res->flags = LEGACY_IO_RESOURCE; | 1157 | res->flags = LEGACY_IO_RESOURCE; |
1104 | pcibios_bus_to_resource(dev, res, ®ion); | 1158 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1105 | } | 1159 | } |
1106 | } | 1160 | } |
1107 | break; | 1161 | break; |
@@ -1154,6 +1208,18 @@ static void pci_release_capabilities(struct pci_dev *dev) | |||
1154 | pci_free_cap_save_buffers(dev); | 1208 | pci_free_cap_save_buffers(dev); |
1155 | } | 1209 | } |
1156 | 1210 | ||
1211 | static void pci_free_resources(struct pci_dev *dev) | ||
1212 | { | ||
1213 | int i; | ||
1214 | |||
1215 | pci_cleanup_rom(dev); | ||
1216 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { | ||
1217 | struct resource *res = dev->resource + i; | ||
1218 | if (res->parent) | ||
1219 | release_resource(res); | ||
1220 | } | ||
1221 | } | ||
1222 | |||
1157 | /** | 1223 | /** |
1158 | * pci_release_dev - free a pci device structure when all users of it are finished. | 1224 | * pci_release_dev - free a pci device structure when all users of it are finished. |
1159 | * @dev: device that's been disconnected | 1225 | * @dev: device that's been disconnected |
@@ -1163,9 +1229,14 @@ static void pci_release_capabilities(struct pci_dev *dev) | |||
1163 | */ | 1229 | */ |
1164 | static void pci_release_dev(struct device *dev) | 1230 | static void pci_release_dev(struct device *dev) |
1165 | { | 1231 | { |
1166 | struct pci_dev *pci_dev; | 1232 | struct pci_dev *pci_dev = to_pci_dev(dev); |
1233 | |||
1234 | down_write(&pci_bus_sem); | ||
1235 | list_del(&pci_dev->bus_list); | ||
1236 | up_write(&pci_bus_sem); | ||
1237 | |||
1238 | pci_free_resources(pci_dev); | ||
1167 | 1239 | ||
1168 | pci_dev = to_pci_dev(dev); | ||
1169 | pci_release_capabilities(pci_dev); | 1240 | pci_release_capabilities(pci_dev); |
1170 | pci_release_of_node(pci_dev); | 1241 | pci_release_of_node(pci_dev); |
1171 | pcibios_release_device(pci_dev); | 1242 | pcibios_release_device(pci_dev); |
@@ -1173,59 +1244,6 @@ static void pci_release_dev(struct device *dev) | |||
1173 | kfree(pci_dev); | 1244 | kfree(pci_dev); |
1174 | } | 1245 | } |
1175 | 1246 | ||
1176 | /** | ||
1177 | * pci_cfg_space_size - get the configuration space size of the PCI device. | ||
1178 | * @dev: PCI device | ||
1179 | * | ||
1180 | * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices | ||
1181 | * have 4096 bytes. Even if the device is capable, that doesn't mean we can | ||
1182 | * access it. Maybe we don't have a way to generate extended config space | ||
1183 | * accesses, or the device is behind a reverse Express bridge. So we try | ||
1184 | * reading the dword at 0x100 which must either be 0 or a valid extended | ||
1185 | * capability header. | ||
1186 | */ | ||
1187 | int pci_cfg_space_size_ext(struct pci_dev *dev) | ||
1188 | { | ||
1189 | u32 status; | ||
1190 | int pos = PCI_CFG_SPACE_SIZE; | ||
1191 | |||
1192 | if (pci_read_config_dword(dev, pos, &status) != PCIBIOS_SUCCESSFUL) | ||
1193 | goto fail; | ||
1194 | if (status == 0xffffffff) | ||
1195 | goto fail; | ||
1196 | |||
1197 | return PCI_CFG_SPACE_EXP_SIZE; | ||
1198 | |||
1199 | fail: | ||
1200 | return PCI_CFG_SPACE_SIZE; | ||
1201 | } | ||
1202 | |||
1203 | int pci_cfg_space_size(struct pci_dev *dev) | ||
1204 | { | ||
1205 | int pos; | ||
1206 | u32 status; | ||
1207 | u16 class; | ||
1208 | |||
1209 | class = dev->class >> 8; | ||
1210 | if (class == PCI_CLASS_BRIDGE_HOST) | ||
1211 | return pci_cfg_space_size_ext(dev); | ||
1212 | |||
1213 | if (!pci_is_pcie(dev)) { | ||
1214 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); | ||
1215 | if (!pos) | ||
1216 | goto fail; | ||
1217 | |||
1218 | pci_read_config_dword(dev, pos + PCI_X_STATUS, &status); | ||
1219 | if (!(status & (PCI_X_STATUS_266MHZ | PCI_X_STATUS_533MHZ))) | ||
1220 | goto fail; | ||
1221 | } | ||
1222 | |||
1223 | return pci_cfg_space_size_ext(dev); | ||
1224 | |||
1225 | fail: | ||
1226 | return PCI_CFG_SPACE_SIZE; | ||
1227 | } | ||
1228 | |||
1229 | struct pci_dev *pci_alloc_dev(struct pci_bus *bus) | 1247 | struct pci_dev *pci_alloc_dev(struct pci_bus *bus) |
1230 | { | 1248 | { |
1231 | struct pci_dev *dev; | 1249 | struct pci_dev *dev; |
@@ -1242,12 +1260,6 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus) | |||
1242 | } | 1260 | } |
1243 | EXPORT_SYMBOL(pci_alloc_dev); | 1261 | EXPORT_SYMBOL(pci_alloc_dev); |
1244 | 1262 | ||
1245 | struct pci_dev *alloc_pci_dev(void) | ||
1246 | { | ||
1247 | return pci_alloc_dev(NULL); | ||
1248 | } | ||
1249 | EXPORT_SYMBOL(alloc_pci_dev); | ||
1250 | |||
1251 | bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, | 1263 | bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, |
1252 | int crs_timeout) | 1264 | int crs_timeout) |
1253 | { | 1265 | { |
@@ -1381,8 +1393,6 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) | |||
1381 | dev->match_driver = false; | 1393 | dev->match_driver = false; |
1382 | ret = device_add(&dev->dev); | 1394 | ret = device_add(&dev->dev); |
1383 | WARN_ON(ret < 0); | 1395 | WARN_ON(ret < 0); |
1384 | |||
1385 | pci_proc_attach_device(dev); | ||
1386 | } | 1396 | } |
1387 | 1397 | ||
1388 | struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn) | 1398 | struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn) |
@@ -2014,6 +2024,24 @@ EXPORT_SYMBOL(pci_scan_slot); | |||
2014 | EXPORT_SYMBOL(pci_scan_bridge); | 2024 | EXPORT_SYMBOL(pci_scan_bridge); |
2015 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); | 2025 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); |
2016 | 2026 | ||
2027 | /* | ||
2028 | * pci_rescan_bus(), pci_rescan_bus_bridge_resize() and PCI device removal | ||
2029 | * routines should always be executed under this mutex. | ||
2030 | */ | ||
2031 | static DEFINE_MUTEX(pci_rescan_remove_lock); | ||
2032 | |||
2033 | void pci_lock_rescan_remove(void) | ||
2034 | { | ||
2035 | mutex_lock(&pci_rescan_remove_lock); | ||
2036 | } | ||
2037 | EXPORT_SYMBOL_GPL(pci_lock_rescan_remove); | ||
2038 | |||
2039 | void pci_unlock_rescan_remove(void) | ||
2040 | { | ||
2041 | mutex_unlock(&pci_rescan_remove_lock); | ||
2042 | } | ||
2043 | EXPORT_SYMBOL_GPL(pci_unlock_rescan_remove); | ||
2044 | |||
2017 | static int __init pci_sort_bf_cmp(const struct device *d_a, const struct device *d_b) | 2045 | static int __init pci_sort_bf_cmp(const struct device *d_a, const struct device *d_b) |
2018 | { | 2046 | { |
2019 | const struct pci_dev *a = to_pci_dev(d_a); | 2047 | const struct pci_dev *a = to_pci_dev(d_a); |