diff options
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r-- | drivers/pci/probe.c | 372 |
1 files changed, 235 insertions, 137 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 14e0ea1ff38b..ef5377438a1e 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -1,3 +1,4 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
1 | /* | 2 | /* |
2 | * probe.c - PCI detection and setup code | 3 | * probe.c - PCI detection and setup code |
3 | */ | 4 | */ |
@@ -69,8 +70,8 @@ static int find_anything(struct device *dev, void *data) | |||
69 | } | 70 | } |
70 | 71 | ||
71 | /* | 72 | /* |
72 | * Some device drivers need know if pci is initiated. | 73 | * Some device drivers need know if PCI is initiated. |
73 | * Basically, we think pci is not initiated when there | 74 | * Basically, we think PCI is not initiated when there |
74 | * is no device to be found on the pci_bus_type. | 75 | * is no device to be found on the pci_bus_type. |
75 | */ | 76 | */ |
76 | int no_pci_devices(void) | 77 | int no_pci_devices(void) |
@@ -116,12 +117,16 @@ static u64 pci_size(u64 base, u64 maxbase, u64 mask) | |||
116 | if (!size) | 117 | if (!size) |
117 | return 0; | 118 | return 0; |
118 | 119 | ||
119 | /* Get the lowest of them to find the decode size, and | 120 | /* |
120 | from that the extent. */ | 121 | * Get the lowest of them to find the decode size, and from that |
122 | * the extent. | ||
123 | */ | ||
121 | size = (size & ~(size-1)) - 1; | 124 | size = (size & ~(size-1)) - 1; |
122 | 125 | ||
123 | /* base == maxbase can be valid only if the BAR has | 126 | /* |
124 | already been programmed with all 1s. */ | 127 | * base == maxbase can be valid only if the BAR has already been |
128 | * programmed with all 1s. | ||
129 | */ | ||
125 | if (base == maxbase && ((base | size) & mask) != mask) | 130 | if (base == maxbase && ((base | size) & mask) != mask) |
126 | return 0; | 131 | return 0; |
127 | 132 | ||
@@ -164,7 +169,7 @@ static inline unsigned long decode_bar(struct pci_dev *dev, u32 bar) | |||
164 | #define PCI_COMMAND_DECODE_ENABLE (PCI_COMMAND_MEMORY | PCI_COMMAND_IO) | 169 | #define PCI_COMMAND_DECODE_ENABLE (PCI_COMMAND_MEMORY | PCI_COMMAND_IO) |
165 | 170 | ||
166 | /** | 171 | /** |
167 | * pci_read_base - read a PCI BAR | 172 | * pci_read_base - Read a PCI BAR |
168 | * @dev: the PCI device | 173 | * @dev: the PCI device |
169 | * @type: type of the BAR | 174 | * @type: type of the BAR |
170 | * @res: resource buffer to be filled in | 175 | * @res: resource buffer to be filled in |
@@ -253,7 +258,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
253 | 258 | ||
254 | sz64 = pci_size(l64, sz64, mask64); | 259 | sz64 = pci_size(l64, sz64, mask64); |
255 | if (!sz64) { | 260 | if (!sz64) { |
256 | dev_info(&dev->dev, FW_BUG "reg 0x%x: invalid BAR (can't size)\n", | 261 | pci_info(dev, FW_BUG "reg 0x%x: invalid BAR (can't size)\n", |
257 | pos); | 262 | pos); |
258 | goto fail; | 263 | goto fail; |
259 | } | 264 | } |
@@ -264,7 +269,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
264 | res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; | 269 | res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; |
265 | res->start = 0; | 270 | res->start = 0; |
266 | res->end = 0; | 271 | res->end = 0; |
267 | dev_err(&dev->dev, "reg 0x%x: can't handle BAR larger than 4GB (size %#010llx)\n", | 272 | pci_err(dev, "reg 0x%x: can't handle BAR larger than 4GB (size %#010llx)\n", |
268 | pos, (unsigned long long)sz64); | 273 | pos, (unsigned long long)sz64); |
269 | goto out; | 274 | goto out; |
270 | } | 275 | } |
@@ -274,7 +279,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
274 | res->flags |= IORESOURCE_UNSET; | 279 | res->flags |= IORESOURCE_UNSET; |
275 | res->start = 0; | 280 | res->start = 0; |
276 | res->end = sz64; | 281 | res->end = sz64; |
277 | dev_info(&dev->dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n", | 282 | pci_info(dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n", |
278 | pos, (unsigned long long)l64); | 283 | pos, (unsigned long long)l64); |
279 | goto out; | 284 | goto out; |
280 | } | 285 | } |
@@ -301,7 +306,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
301 | res->flags |= IORESOURCE_UNSET; | 306 | res->flags |= IORESOURCE_UNSET; |
302 | res->start = 0; | 307 | res->start = 0; |
303 | res->end = region.end - region.start; | 308 | res->end = region.end - region.start; |
304 | dev_info(&dev->dev, "reg 0x%x: initial BAR value %#010llx invalid\n", | 309 | pci_info(dev, "reg 0x%x: initial BAR value %#010llx invalid\n", |
305 | pos, (unsigned long long)region.start); | 310 | pos, (unsigned long long)region.start); |
306 | } | 311 | } |
307 | 312 | ||
@@ -312,7 +317,7 @@ fail: | |||
312 | res->flags = 0; | 317 | res->flags = 0; |
313 | out: | 318 | out: |
314 | if (res->flags) | 319 | if (res->flags) |
315 | dev_printk(KERN_DEBUG, &dev->dev, "reg 0x%x: %pR\n", pos, res); | 320 | pci_printk(KERN_DEBUG, dev, "reg 0x%x: %pR\n", pos, res); |
316 | 321 | ||
317 | return (res->flags & IORESOURCE_MEM_64) ? 1 : 0; | 322 | return (res->flags & IORESOURCE_MEM_64) ? 1 : 0; |
318 | } | 323 | } |
@@ -375,7 +380,7 @@ static void pci_read_bridge_io(struct pci_bus *child) | |||
375 | region.start = base; | 380 | region.start = base; |
376 | region.end = limit + io_granularity - 1; | 381 | region.end = limit + io_granularity - 1; |
377 | pcibios_bus_to_resource(dev->bus, res, ®ion); | 382 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
378 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); | 383 | pci_printk(KERN_DEBUG, dev, " bridge window %pR\n", res); |
379 | } | 384 | } |
380 | } | 385 | } |
381 | 386 | ||
@@ -397,7 +402,7 @@ static void pci_read_bridge_mmio(struct pci_bus *child) | |||
397 | region.start = base; | 402 | region.start = base; |
398 | region.end = limit + 0xfffff; | 403 | region.end = limit + 0xfffff; |
399 | pcibios_bus_to_resource(dev->bus, res, ®ion); | 404 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
400 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); | 405 | pci_printk(KERN_DEBUG, dev, " bridge window %pR\n", res); |
401 | } | 406 | } |
402 | } | 407 | } |
403 | 408 | ||
@@ -437,7 +442,7 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child) | |||
437 | limit = (pci_bus_addr_t) limit64; | 442 | limit = (pci_bus_addr_t) limit64; |
438 | 443 | ||
439 | if (base != base64) { | 444 | if (base != base64) { |
440 | dev_err(&dev->dev, "can't handle bridge window above 4GB (bus address %#010llx)\n", | 445 | pci_err(dev, "can't handle bridge window above 4GB (bus address %#010llx)\n", |
441 | (unsigned long long) base64); | 446 | (unsigned long long) base64); |
442 | return; | 447 | return; |
443 | } | 448 | } |
@@ -450,7 +455,7 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child) | |||
450 | region.start = base; | 455 | region.start = base; |
451 | region.end = limit + 0xfffff; | 456 | region.end = limit + 0xfffff; |
452 | pcibios_bus_to_resource(dev->bus, res, ®ion); | 457 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
453 | dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); | 458 | pci_printk(KERN_DEBUG, dev, " bridge window %pR\n", res); |
454 | } | 459 | } |
455 | } | 460 | } |
456 | 461 | ||
@@ -463,7 +468,7 @@ void pci_read_bridge_bases(struct pci_bus *child) | |||
463 | if (pci_is_root_bus(child)) /* It's a host bus, nothing to read */ | 468 | if (pci_is_root_bus(child)) /* It's a host bus, nothing to read */ |
464 | return; | 469 | return; |
465 | 470 | ||
466 | dev_info(&dev->dev, "PCI bridge to %pR%s\n", | 471 | pci_info(dev, "PCI bridge to %pR%s\n", |
467 | &child->busn_res, | 472 | &child->busn_res, |
468 | dev->transparent ? " (subtractive decode)" : ""); | 473 | dev->transparent ? " (subtractive decode)" : ""); |
469 | 474 | ||
@@ -480,7 +485,7 @@ void pci_read_bridge_bases(struct pci_bus *child) | |||
480 | if (res && res->flags) { | 485 | if (res && res->flags) { |
481 | pci_bus_add_resource(child, res, | 486 | pci_bus_add_resource(child, res, |
482 | PCI_SUBTRACTIVE_DECODE); | 487 | PCI_SUBTRACTIVE_DECODE); |
483 | dev_printk(KERN_DEBUG, &dev->dev, | 488 | pci_printk(KERN_DEBUG, dev, |
484 | " bridge window %pR (subtractive decode)\n", | 489 | " bridge window %pR (subtractive decode)\n", |
485 | res); | 490 | res); |
486 | } | 491 | } |
@@ -764,7 +769,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) | |||
764 | 769 | ||
765 | bridge->bus = bus; | 770 | bridge->bus = bus; |
766 | 771 | ||
767 | /* temporarily move resources off the list */ | 772 | /* Temporarily move resources off the list */ |
768 | list_splice_init(&bridge->windows, &resources); | 773 | list_splice_init(&bridge->windows, &resources); |
769 | bus->sysdata = bridge->sysdata; | 774 | bus->sysdata = bridge->sysdata; |
770 | bus->msi = bridge->msi; | 775 | bus->msi = bridge->msi; |
@@ -776,7 +781,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) | |||
776 | 781 | ||
777 | b = pci_find_bus(pci_domain_nr(bus), bridge->busnr); | 782 | b = pci_find_bus(pci_domain_nr(bus), bridge->busnr); |
778 | if (b) { | 783 | if (b) { |
779 | /* If we already got to this bus through a different bridge, ignore it */ | 784 | /* Ignore it if we already got here via a different bridge */ |
780 | dev_dbg(&b->dev, "bus already known\n"); | 785 | dev_dbg(&b->dev, "bus already known\n"); |
781 | err = -EEXIST; | 786 | err = -EEXIST; |
782 | goto free; | 787 | goto free; |
@@ -869,9 +874,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent, | |||
869 | int i; | 874 | int i; |
870 | int ret; | 875 | int ret; |
871 | 876 | ||
872 | /* | 877 | /* Allocate a new bus and inherit stuff from the parent */ |
873 | * Allocate a new bus, and inherit stuff from the parent.. | ||
874 | */ | ||
875 | child = pci_alloc_bus(parent); | 878 | child = pci_alloc_bus(parent); |
876 | if (!child) | 879 | if (!child) |
877 | return NULL; | 880 | return NULL; |
@@ -882,16 +885,14 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent, | |||
882 | child->sysdata = parent->sysdata; | 885 | child->sysdata = parent->sysdata; |
883 | child->bus_flags = parent->bus_flags; | 886 | child->bus_flags = parent->bus_flags; |
884 | 887 | ||
885 | /* initialize some portions of the bus device, but don't register it | 888 | /* |
886 | * now as the parent is not properly set up yet. | 889 | * Initialize some portions of the bus device, but don't register |
890 | * it now as the parent is not properly set up yet. | ||
887 | */ | 891 | */ |
888 | child->dev.class = &pcibus_class; | 892 | child->dev.class = &pcibus_class; |
889 | dev_set_name(&child->dev, "%04x:%02x", pci_domain_nr(child), busnr); | 893 | dev_set_name(&child->dev, "%04x:%02x", pci_domain_nr(child), busnr); |
890 | 894 | ||
891 | /* | 895 | /* Set up the primary, secondary and subordinate bus numbers */ |
892 | * Set up the primary, secondary and subordinate | ||
893 | * bus numbers. | ||
894 | */ | ||
895 | child->number = child->busn_res.start = busnr; | 896 | child->number = child->busn_res.start = busnr; |
896 | child->primary = parent->busn_res.start; | 897 | child->primary = parent->busn_res.start; |
897 | child->busn_res.end = 0xff; | 898 | child->busn_res.end = 0xff; |
@@ -907,7 +908,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent, | |||
907 | pci_set_bus_of_node(child); | 908 | pci_set_bus_of_node(child); |
908 | pci_set_bus_speed(child); | 909 | pci_set_bus_speed(child); |
909 | 910 | ||
910 | /* Set up default resource pointers and names.. */ | 911 | /* Set up default resource pointers and names */ |
911 | for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { | 912 | for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { |
912 | child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i]; | 913 | child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i]; |
913 | child->resource[i]->name = child->name; | 914 | child->resource[i]->name = child->name; |
@@ -1005,11 +1006,11 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1005 | secondary = (buses >> 8) & 0xFF; | 1006 | secondary = (buses >> 8) & 0xFF; |
1006 | subordinate = (buses >> 16) & 0xFF; | 1007 | subordinate = (buses >> 16) & 0xFF; |
1007 | 1008 | ||
1008 | dev_dbg(&dev->dev, "scanning [bus %02x-%02x] behind bridge, pass %d\n", | 1009 | pci_dbg(dev, "scanning [bus %02x-%02x] behind bridge, pass %d\n", |
1009 | secondary, subordinate, pass); | 1010 | secondary, subordinate, pass); |
1010 | 1011 | ||
1011 | if (!primary && (primary != bus->number) && secondary && subordinate) { | 1012 | if (!primary && (primary != bus->number) && secondary && subordinate) { |
1012 | dev_warn(&dev->dev, "Primary bus is hard wired to 0\n"); | 1013 | pci_warn(dev, "Primary bus is hard wired to 0\n"); |
1013 | primary = bus->number; | 1014 | primary = bus->number; |
1014 | } | 1015 | } |
1015 | 1016 | ||
@@ -1017,13 +1018,15 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1017 | if (!pass && | 1018 | if (!pass && |
1018 | (primary != bus->number || secondary <= bus->number || | 1019 | (primary != bus->number || secondary <= bus->number || |
1019 | secondary > subordinate)) { | 1020 | secondary > subordinate)) { |
1020 | dev_info(&dev->dev, "bridge configuration invalid ([bus %02x-%02x]), reconfiguring\n", | 1021 | pci_info(dev, "bridge configuration invalid ([bus %02x-%02x]), reconfiguring\n", |
1021 | secondary, subordinate); | 1022 | secondary, subordinate); |
1022 | broken = 1; | 1023 | broken = 1; |
1023 | } | 1024 | } |
1024 | 1025 | ||
1025 | /* Disable MasterAbortMode during probing to avoid reporting | 1026 | /* |
1026 | of bus errors (in some architectures) */ | 1027 | * Disable Master-Abort Mode during probing to avoid reporting of |
1028 | * bus errors in some architectures. | ||
1029 | */ | ||
1027 | pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &bctl); | 1030 | pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &bctl); |
1028 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, | 1031 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, |
1029 | bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); | 1032 | bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); |
@@ -1033,18 +1036,19 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1033 | if ((secondary || subordinate) && !pcibios_assign_all_busses() && | 1036 | if ((secondary || subordinate) && !pcibios_assign_all_busses() && |
1034 | !is_cardbus && !broken) { | 1037 | !is_cardbus && !broken) { |
1035 | unsigned int cmax; | 1038 | unsigned int cmax; |
1039 | |||
1036 | /* | 1040 | /* |
1037 | * Bus already configured by firmware, process it in the first | 1041 | * Bus already configured by firmware, process it in the |
1038 | * pass and just note the configuration. | 1042 | * first pass and just note the configuration. |
1039 | */ | 1043 | */ |
1040 | if (pass) | 1044 | if (pass) |
1041 | goto out; | 1045 | goto out; |
1042 | 1046 | ||
1043 | /* | 1047 | /* |
1044 | * The bus might already exist for two reasons: Either we are | 1048 | * The bus might already exist for two reasons: Either we |
1045 | * rescanning the bus or the bus is reachable through more than | 1049 | * are rescanning the bus or the bus is reachable through |
1046 | * one bridge. The second case can happen with the i450NX | 1050 | * more than one bridge. The second case can happen with |
1047 | * chipset. | 1051 | * the i450NX chipset. |
1048 | */ | 1052 | */ |
1049 | child = pci_find_bus(pci_domain_nr(bus), secondary); | 1053 | child = pci_find_bus(pci_domain_nr(bus), secondary); |
1050 | if (!child) { | 1054 | if (!child) { |
@@ -1058,24 +1062,29 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1058 | 1062 | ||
1059 | cmax = pci_scan_child_bus(child); | 1063 | cmax = pci_scan_child_bus(child); |
1060 | if (cmax > subordinate) | 1064 | if (cmax > subordinate) |
1061 | dev_warn(&dev->dev, "bridge has subordinate %02x but max busn %02x\n", | 1065 | pci_warn(dev, "bridge has subordinate %02x but max busn %02x\n", |
1062 | subordinate, cmax); | 1066 | subordinate, cmax); |
1063 | /* subordinate should equal child->busn_res.end */ | 1067 | |
1068 | /* Subordinate should equal child->busn_res.end */ | ||
1064 | if (subordinate > max) | 1069 | if (subordinate > max) |
1065 | max = subordinate; | 1070 | max = subordinate; |
1066 | } else { | 1071 | } else { |
1072 | |||
1067 | /* | 1073 | /* |
1068 | * We need to assign a number to this bus which we always | 1074 | * We need to assign a number to this bus which we always |
1069 | * do in the second pass. | 1075 | * do in the second pass. |
1070 | */ | 1076 | */ |
1071 | if (!pass) { | 1077 | if (!pass) { |
1072 | if (pcibios_assign_all_busses() || broken || is_cardbus) | 1078 | if (pcibios_assign_all_busses() || broken || is_cardbus) |
1073 | /* Temporarily disable forwarding of the | 1079 | |
1074 | configuration cycles on all bridges in | 1080 | /* |
1075 | this bus segment to avoid possible | 1081 | * Temporarily disable forwarding of the |
1076 | conflicts in the second pass between two | 1082 | * configuration cycles on all bridges in |
1077 | bridges programmed with overlapping | 1083 | * this bus segment to avoid possible |
1078 | bus ranges. */ | 1084 | * conflicts in the second pass between two |
1085 | * bridges programmed with overlapping bus | ||
1086 | * ranges. | ||
1087 | */ | ||
1079 | pci_write_config_dword(dev, PCI_PRIMARY_BUS, | 1088 | pci_write_config_dword(dev, PCI_PRIMARY_BUS, |
1080 | buses & ~0xffffff); | 1089 | buses & ~0xffffff); |
1081 | goto out; | 1090 | goto out; |
@@ -1084,9 +1093,11 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1084 | /* Clear errors */ | 1093 | /* Clear errors */ |
1085 | pci_write_config_word(dev, PCI_STATUS, 0xffff); | 1094 | pci_write_config_word(dev, PCI_STATUS, 0xffff); |
1086 | 1095 | ||
1087 | /* Prevent assigning a bus number that already exists. | 1096 | /* |
1088 | * This can happen when a bridge is hot-plugged, so in | 1097 | * Prevent assigning a bus number that already exists. |
1089 | * this case we only re-scan this bus. */ | 1098 | * This can happen when a bridge is hot-plugged, so in this |
1099 | * case we only re-scan this bus. | ||
1100 | */ | ||
1090 | child = pci_find_bus(pci_domain_nr(bus), max+1); | 1101 | child = pci_find_bus(pci_domain_nr(bus), max+1); |
1091 | if (!child) { | 1102 | if (!child) { |
1092 | child = pci_add_new_bus(bus, dev, max+1); | 1103 | child = pci_add_new_bus(bus, dev, max+1); |
@@ -1113,19 +1124,18 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1113 | buses |= CARDBUS_LATENCY_TIMER << 24; | 1124 | buses |= CARDBUS_LATENCY_TIMER << 24; |
1114 | } | 1125 | } |
1115 | 1126 | ||
1116 | /* | 1127 | /* We need to blast all three values with a single write */ |
1117 | * We need to blast all three values with a single write. | ||
1118 | */ | ||
1119 | pci_write_config_dword(dev, PCI_PRIMARY_BUS, buses); | 1128 | pci_write_config_dword(dev, PCI_PRIMARY_BUS, buses); |
1120 | 1129 | ||
1121 | if (!is_cardbus) { | 1130 | if (!is_cardbus) { |
1122 | child->bridge_ctl = bctl; | 1131 | child->bridge_ctl = bctl; |
1123 | max = pci_scan_child_bus_extend(child, available_buses); | 1132 | max = pci_scan_child_bus_extend(child, available_buses); |
1124 | } else { | 1133 | } else { |
1134 | |||
1125 | /* | 1135 | /* |
1126 | * For CardBus bridges, we leave 4 bus numbers | 1136 | * For CardBus bridges, we leave 4 bus numbers as |
1127 | * as cards with a PCI-to-PCI bridge can be | 1137 | * cards with a PCI-to-PCI bridge can be inserted |
1128 | * inserted later. | 1138 | * later. |
1129 | */ | 1139 | */ |
1130 | for (i = 0; i < CARDBUS_RESERVE_BUSNR; i++) { | 1140 | for (i = 0; i < CARDBUS_RESERVE_BUSNR; i++) { |
1131 | struct pci_bus *parent = bus; | 1141 | struct pci_bus *parent = bus; |
@@ -1141,10 +1151,11 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1141 | parent = parent->parent; | 1151 | parent = parent->parent; |
1142 | } | 1152 | } |
1143 | if (j) { | 1153 | if (j) { |
1154 | |||
1144 | /* | 1155 | /* |
1145 | * Often, there are two cardbus bridges | 1156 | * Often, there are two CardBus |
1146 | * -- try to leave one valid bus number | 1157 | * bridges -- try to leave one |
1147 | * for each one. | 1158 | * valid bus number for each one. |
1148 | */ | 1159 | */ |
1149 | i /= 2; | 1160 | i /= 2; |
1150 | break; | 1161 | break; |
@@ -1152,9 +1163,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, | |||
1152 | } | 1163 | } |
1153 | max += i; | 1164 | max += i; |
1154 | } | 1165 | } |
1155 | /* | 1166 | |
1156 | * Set the subordinate bus number to its real value. | 1167 | /* Set subordinate bus number to its real value */ |
1157 | */ | ||
1158 | pci_bus_update_busn_res_end(child, max); | 1168 | pci_bus_update_busn_res_end(child, max); |
1159 | pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max); | 1169 | pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max); |
1160 | } | 1170 | } |
@@ -1295,7 +1305,7 @@ static void set_pcie_thunderbolt(struct pci_dev *dev) | |||
1295 | } | 1305 | } |
1296 | 1306 | ||
1297 | /** | 1307 | /** |
1298 | * pci_ext_cfg_is_aliased - is ext config space just an alias of std config? | 1308 | * pci_ext_cfg_is_aliased - Is ext config space just an alias of std config? |
1299 | * @dev: PCI device | 1309 | * @dev: PCI device |
1300 | * | 1310 | * |
1301 | * PCI Express to PCI/PCI-X Bridge Specification, rev 1.0, 4.1.4 says that | 1311 | * PCI Express to PCI/PCI-X Bridge Specification, rev 1.0, 4.1.4 says that |
@@ -1332,7 +1342,7 @@ static bool pci_ext_cfg_is_aliased(struct pci_dev *dev) | |||
1332 | } | 1342 | } |
1333 | 1343 | ||
1334 | /** | 1344 | /** |
1335 | * pci_cfg_space_size - get the configuration space size of the PCI device. | 1345 | * pci_cfg_space_size - Get the configuration space size of the PCI device |
1336 | * @dev: PCI device | 1346 | * @dev: PCI device |
1337 | * | 1347 | * |
1338 | * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices | 1348 | * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices |
@@ -1398,7 +1408,7 @@ static void pci_msi_setup_pci_dev(struct pci_dev *dev) | |||
1398 | } | 1408 | } |
1399 | 1409 | ||
1400 | /** | 1410 | /** |
1401 | * pci_intx_mask_broken - test PCI_COMMAND_INTX_DISABLE writability | 1411 | * pci_intx_mask_broken - Test PCI_COMMAND_INTX_DISABLE writability |
1402 | * @dev: PCI device | 1412 | * @dev: PCI device |
1403 | * | 1413 | * |
1404 | * Test whether PCI_COMMAND_INTX_DISABLE is writable for @dev. Check this | 1414 | * Test whether PCI_COMMAND_INTX_DISABLE is writable for @dev. Check this |
@@ -1426,11 +1436,11 @@ static int pci_intx_mask_broken(struct pci_dev *dev) | |||
1426 | } | 1436 | } |
1427 | 1437 | ||
1428 | /** | 1438 | /** |
1429 | * pci_setup_device - fill in class and map information of a device | 1439 | * pci_setup_device - Fill in class and map information of a device |
1430 | * @dev: the device structure to fill | 1440 | * @dev: the device structure to fill |
1431 | * | 1441 | * |
1432 | * Initialize the device structure with information about the device's | 1442 | * Initialize the device structure with information about the device's |
1433 | * vendor,class,memory and IO-space addresses,IRQ lines etc. | 1443 | * vendor,class,memory and IO-space addresses, IRQ lines etc. |
1434 | * Called at initialisation of the PCI subsystem and by CardBus services. | 1444 | * Called at initialisation of the PCI subsystem and by CardBus services. |
1435 | * Returns 0 on success and negative if unknown type of device (not normal, | 1445 | * Returns 0 on success and negative if unknown type of device (not normal, |
1436 | * bridge or CardBus). | 1446 | * bridge or CardBus). |
@@ -1456,8 +1466,11 @@ int pci_setup_device(struct pci_dev *dev) | |||
1456 | set_pcie_port_type(dev); | 1466 | set_pcie_port_type(dev); |
1457 | 1467 | ||
1458 | pci_dev_assign_slot(dev); | 1468 | pci_dev_assign_slot(dev); |
1459 | /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer) | 1469 | |
1460 | set this higher, assuming the system even supports it. */ | 1470 | /* |
1471 | * Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer) | ||
1472 | * set this higher, assuming the system even supports it. | ||
1473 | */ | ||
1461 | dev->dma_mask = 0xffffffff; | 1474 | dev->dma_mask = 0xffffffff; |
1462 | 1475 | ||
1463 | dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), | 1476 | dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), |
@@ -1468,13 +1481,13 @@ int pci_setup_device(struct pci_dev *dev) | |||
1468 | dev->revision = class & 0xff; | 1481 | dev->revision = class & 0xff; |
1469 | dev->class = class >> 8; /* upper 3 bytes */ | 1482 | dev->class = class >> 8; /* upper 3 bytes */ |
1470 | 1483 | ||
1471 | dev_printk(KERN_DEBUG, &dev->dev, "[%04x:%04x] type %02x class %#08x\n", | 1484 | pci_printk(KERN_DEBUG, dev, "[%04x:%04x] type %02x class %#08x\n", |
1472 | dev->vendor, dev->device, dev->hdr_type, dev->class); | 1485 | dev->vendor, dev->device, dev->hdr_type, dev->class); |
1473 | 1486 | ||
1474 | /* need to have dev->class ready */ | 1487 | /* Need to have dev->class ready */ |
1475 | dev->cfg_size = pci_cfg_space_size(dev); | 1488 | dev->cfg_size = pci_cfg_space_size(dev); |
1476 | 1489 | ||
1477 | /* need to have dev->cfg_size ready */ | 1490 | /* Need to have dev->cfg_size ready */ |
1478 | set_pcie_thunderbolt(dev); | 1491 | set_pcie_thunderbolt(dev); |
1479 | 1492 | ||
1480 | /* "Unknown power state" */ | 1493 | /* "Unknown power state" */ |
@@ -1482,13 +1495,14 @@ int pci_setup_device(struct pci_dev *dev) | |||
1482 | 1495 | ||
1483 | /* Early fixups, before probing the BARs */ | 1496 | /* Early fixups, before probing the BARs */ |
1484 | pci_fixup_device(pci_fixup_early, dev); | 1497 | pci_fixup_device(pci_fixup_early, dev); |
1485 | /* device class may be changed after fixup */ | 1498 | |
1499 | /* Device class may be changed after fixup */ | ||
1486 | class = dev->class >> 8; | 1500 | class = dev->class >> 8; |
1487 | 1501 | ||
1488 | if (dev->non_compliant_bars) { | 1502 | if (dev->non_compliant_bars) { |
1489 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | 1503 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
1490 | if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { | 1504 | if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { |
1491 | dev_info(&dev->dev, "device has non-compliant BARs; disabling IO/MEM decoding\n"); | 1505 | pci_info(dev, "device has non-compliant BARs; disabling IO/MEM decoding\n"); |
1492 | cmd &= ~PCI_COMMAND_IO; | 1506 | cmd &= ~PCI_COMMAND_IO; |
1493 | cmd &= ~PCI_COMMAND_MEMORY; | 1507 | cmd &= ~PCI_COMMAND_MEMORY; |
1494 | pci_write_config_word(dev, PCI_COMMAND, cmd); | 1508 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
@@ -1521,14 +1535,14 @@ int pci_setup_device(struct pci_dev *dev) | |||
1521 | res = &dev->resource[0]; | 1535 | res = &dev->resource[0]; |
1522 | res->flags = LEGACY_IO_RESOURCE; | 1536 | res->flags = LEGACY_IO_RESOURCE; |
1523 | pcibios_bus_to_resource(dev->bus, res, ®ion); | 1537 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1524 | dev_info(&dev->dev, "legacy IDE quirk: reg 0x10: %pR\n", | 1538 | pci_info(dev, "legacy IDE quirk: reg 0x10: %pR\n", |
1525 | res); | 1539 | res); |
1526 | region.start = 0x3F6; | 1540 | region.start = 0x3F6; |
1527 | region.end = 0x3F6; | 1541 | region.end = 0x3F6; |
1528 | res = &dev->resource[1]; | 1542 | res = &dev->resource[1]; |
1529 | res->flags = LEGACY_IO_RESOURCE; | 1543 | res->flags = LEGACY_IO_RESOURCE; |
1530 | pcibios_bus_to_resource(dev->bus, res, ®ion); | 1544 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1531 | dev_info(&dev->dev, "legacy IDE quirk: reg 0x14: %pR\n", | 1545 | pci_info(dev, "legacy IDE quirk: reg 0x14: %pR\n", |
1532 | res); | 1546 | res); |
1533 | } | 1547 | } |
1534 | if ((progif & 4) == 0) { | 1548 | if ((progif & 4) == 0) { |
@@ -1537,14 +1551,14 @@ int pci_setup_device(struct pci_dev *dev) | |||
1537 | res = &dev->resource[2]; | 1551 | res = &dev->resource[2]; |
1538 | res->flags = LEGACY_IO_RESOURCE; | 1552 | res->flags = LEGACY_IO_RESOURCE; |
1539 | pcibios_bus_to_resource(dev->bus, res, ®ion); | 1553 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1540 | dev_info(&dev->dev, "legacy IDE quirk: reg 0x18: %pR\n", | 1554 | pci_info(dev, "legacy IDE quirk: reg 0x18: %pR\n", |
1541 | res); | 1555 | res); |
1542 | region.start = 0x376; | 1556 | region.start = 0x376; |
1543 | region.end = 0x376; | 1557 | region.end = 0x376; |
1544 | res = &dev->resource[3]; | 1558 | res = &dev->resource[3]; |
1545 | res->flags = LEGACY_IO_RESOURCE; | 1559 | res->flags = LEGACY_IO_RESOURCE; |
1546 | pcibios_bus_to_resource(dev->bus, res, ®ion); | 1560 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
1547 | dev_info(&dev->dev, "legacy IDE quirk: reg 0x1c: %pR\n", | 1561 | pci_info(dev, "legacy IDE quirk: reg 0x1c: %pR\n", |
1548 | res); | 1562 | res); |
1549 | } | 1563 | } |
1550 | } | 1564 | } |
@@ -1553,9 +1567,12 @@ int pci_setup_device(struct pci_dev *dev) | |||
1553 | case PCI_HEADER_TYPE_BRIDGE: /* bridge header */ | 1567 | case PCI_HEADER_TYPE_BRIDGE: /* bridge header */ |
1554 | if (class != PCI_CLASS_BRIDGE_PCI) | 1568 | if (class != PCI_CLASS_BRIDGE_PCI) |
1555 | goto bad; | 1569 | goto bad; |
1556 | /* The PCI-to-PCI bridge spec requires that subtractive | 1570 | |
1557 | decoding (i.e. transparent) bridge must have programming | 1571 | /* |
1558 | interface code of 0x01. */ | 1572 | * The PCI-to-PCI bridge spec requires that subtractive |
1573 | * decoding (i.e. transparent) bridge must have programming | ||
1574 | * interface code of 0x01. | ||
1575 | */ | ||
1559 | pci_read_irq(dev); | 1576 | pci_read_irq(dev); |
1560 | dev->transparent = ((dev->class & 0xff) == 1); | 1577 | dev->transparent = ((dev->class & 0xff) == 1); |
1561 | pci_read_bases(dev, 2, PCI_ROM_ADDRESS1); | 1578 | pci_read_bases(dev, 2, PCI_ROM_ADDRESS1); |
@@ -1577,12 +1594,12 @@ int pci_setup_device(struct pci_dev *dev) | |||
1577 | break; | 1594 | break; |
1578 | 1595 | ||
1579 | default: /* unknown header */ | 1596 | default: /* unknown header */ |
1580 | dev_err(&dev->dev, "unknown header type %02x, ignoring device\n", | 1597 | pci_err(dev, "unknown header type %02x, ignoring device\n", |
1581 | dev->hdr_type); | 1598 | dev->hdr_type); |
1582 | return -EIO; | 1599 | return -EIO; |
1583 | 1600 | ||
1584 | bad: | 1601 | bad: |
1585 | dev_err(&dev->dev, "ignoring class %#08x (doesn't match header type %02x)\n", | 1602 | pci_err(dev, "ignoring class %#08x (doesn't match header type %02x)\n", |
1586 | dev->class, dev->hdr_type); | 1603 | dev->class, dev->hdr_type); |
1587 | dev->class = PCI_CLASS_NOT_DEFINED << 8; | 1604 | dev->class = PCI_CLASS_NOT_DEFINED << 8; |
1588 | } | 1605 | } |
@@ -1606,7 +1623,7 @@ static void pci_configure_mps(struct pci_dev *dev) | |||
1606 | return; | 1623 | return; |
1607 | 1624 | ||
1608 | if (pcie_bus_config == PCIE_BUS_TUNE_OFF) { | 1625 | if (pcie_bus_config == PCIE_BUS_TUNE_OFF) { |
1609 | dev_warn(&dev->dev, "Max Payload Size %d, but upstream %s set to %d; if necessary, use \"pci=pcie_bus_safe\" and report a bug\n", | 1626 | pci_warn(dev, "Max Payload Size %d, but upstream %s set to %d; if necessary, use \"pci=pcie_bus_safe\" and report a bug\n", |
1610 | mps, pci_name(bridge), p_mps); | 1627 | mps, pci_name(bridge), p_mps); |
1611 | return; | 1628 | return; |
1612 | } | 1629 | } |
@@ -1620,12 +1637,12 @@ static void pci_configure_mps(struct pci_dev *dev) | |||
1620 | 1637 | ||
1621 | rc = pcie_set_mps(dev, p_mps); | 1638 | rc = pcie_set_mps(dev, p_mps); |
1622 | if (rc) { | 1639 | if (rc) { |
1623 | dev_warn(&dev->dev, "can't set Max Payload Size to %d; if necessary, use \"pci=pcie_bus_safe\" and report a bug\n", | 1640 | pci_warn(dev, "can't set Max Payload Size to %d; if necessary, use \"pci=pcie_bus_safe\" and report a bug\n", |
1624 | p_mps); | 1641 | p_mps); |
1625 | return; | 1642 | return; |
1626 | } | 1643 | } |
1627 | 1644 | ||
1628 | dev_info(&dev->dev, "Max Payload Size set to %d (was %d, max %d)\n", | 1645 | pci_info(dev, "Max Payload Size set to %d (was %d, max %d)\n", |
1629 | p_mps, mps, 128 << dev->pcie_mpss); | 1646 | p_mps, mps, 128 << dev->pcie_mpss); |
1630 | } | 1647 | } |
1631 | 1648 | ||
@@ -1645,8 +1662,7 @@ static void program_hpp_type0(struct pci_dev *dev, struct hpp_type0 *hpp) | |||
1645 | hpp = &pci_default_type0; | 1662 | hpp = &pci_default_type0; |
1646 | 1663 | ||
1647 | if (hpp->revision > 1) { | 1664 | if (hpp->revision > 1) { |
1648 | dev_warn(&dev->dev, | 1665 | pci_warn(dev, "PCI settings rev %d not supported; using defaults\n", |
1649 | "PCI settings rev %d not supported; using defaults\n", | ||
1650 | hpp->revision); | 1666 | hpp->revision); |
1651 | hpp = &pci_default_type0; | 1667 | hpp = &pci_default_type0; |
1652 | } | 1668 | } |
@@ -1684,7 +1700,7 @@ static void program_hpp_type1(struct pci_dev *dev, struct hpp_type1 *hpp) | |||
1684 | if (!pos) | 1700 | if (!pos) |
1685 | return; | 1701 | return; |
1686 | 1702 | ||
1687 | dev_warn(&dev->dev, "PCI-X settings not supported\n"); | 1703 | pci_warn(dev, "PCI-X settings not supported\n"); |
1688 | } | 1704 | } |
1689 | 1705 | ||
1690 | static bool pcie_root_rcb_set(struct pci_dev *dev) | 1706 | static bool pcie_root_rcb_set(struct pci_dev *dev) |
@@ -1714,7 +1730,7 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) | |||
1714 | return; | 1730 | return; |
1715 | 1731 | ||
1716 | if (hpp->revision > 1) { | 1732 | if (hpp->revision > 1) { |
1717 | dev_warn(&dev->dev, "PCIe settings rev %d not supported\n", | 1733 | pci_warn(dev, "PCIe settings rev %d not supported\n", |
1718 | hpp->revision); | 1734 | hpp->revision); |
1719 | return; | 1735 | return; |
1720 | } | 1736 | } |
@@ -1772,6 +1788,7 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) | |||
1772 | /* Initialize Advanced Error Capabilities and Control Register */ | 1788 | /* Initialize Advanced Error Capabilities and Control Register */ |
1773 | pci_read_config_dword(dev, pos + PCI_ERR_CAP, ®32); | 1789 | pci_read_config_dword(dev, pos + PCI_ERR_CAP, ®32); |
1774 | reg32 = (reg32 & hpp->adv_err_cap_and) | hpp->adv_err_cap_or; | 1790 | reg32 = (reg32 & hpp->adv_err_cap_and) | hpp->adv_err_cap_or; |
1791 | |||
1775 | /* Don't enable ECRC generation or checking if unsupported */ | 1792 | /* Don't enable ECRC generation or checking if unsupported */ |
1776 | if (!(reg32 & PCI_ERR_CAP_ECRC_GENC)) | 1793 | if (!(reg32 & PCI_ERR_CAP_ECRC_GENC)) |
1777 | reg32 &= ~PCI_ERR_CAP_ECRC_GENE; | 1794 | reg32 &= ~PCI_ERR_CAP_ECRC_GENE; |
@@ -1818,7 +1835,7 @@ int pci_configure_extended_tags(struct pci_dev *dev, void *ign) | |||
1818 | */ | 1835 | */ |
1819 | if (host->no_ext_tags) { | 1836 | if (host->no_ext_tags) { |
1820 | if (ctl & PCI_EXP_DEVCTL_EXT_TAG) { | 1837 | if (ctl & PCI_EXP_DEVCTL_EXT_TAG) { |
1821 | dev_info(&dev->dev, "disabling Extended Tags\n"); | 1838 | pci_info(dev, "disabling Extended Tags\n"); |
1822 | pcie_capability_clear_word(dev, PCI_EXP_DEVCTL, | 1839 | pcie_capability_clear_word(dev, PCI_EXP_DEVCTL, |
1823 | PCI_EXP_DEVCTL_EXT_TAG); | 1840 | PCI_EXP_DEVCTL_EXT_TAG); |
1824 | } | 1841 | } |
@@ -1826,7 +1843,7 @@ int pci_configure_extended_tags(struct pci_dev *dev, void *ign) | |||
1826 | } | 1843 | } |
1827 | 1844 | ||
1828 | if (!(ctl & PCI_EXP_DEVCTL_EXT_TAG)) { | 1845 | if (!(ctl & PCI_EXP_DEVCTL_EXT_TAG)) { |
1829 | dev_info(&dev->dev, "enabling Extended Tags\n"); | 1846 | pci_info(dev, "enabling Extended Tags\n"); |
1830 | pcie_capability_set_word(dev, PCI_EXP_DEVCTL, | 1847 | pcie_capability_set_word(dev, PCI_EXP_DEVCTL, |
1831 | PCI_EXP_DEVCTL_EXT_TAG); | 1848 | PCI_EXP_DEVCTL_EXT_TAG); |
1832 | } | 1849 | } |
@@ -1871,10 +1888,42 @@ static void pci_configure_relaxed_ordering(struct pci_dev *dev) | |||
1871 | if (root->dev_flags & PCI_DEV_FLAGS_NO_RELAXED_ORDERING) { | 1888 | if (root->dev_flags & PCI_DEV_FLAGS_NO_RELAXED_ORDERING) { |
1872 | pcie_capability_clear_word(dev, PCI_EXP_DEVCTL, | 1889 | pcie_capability_clear_word(dev, PCI_EXP_DEVCTL, |
1873 | PCI_EXP_DEVCTL_RELAX_EN); | 1890 | PCI_EXP_DEVCTL_RELAX_EN); |
1874 | dev_info(&dev->dev, "Disable Relaxed Ordering because the Root Port didn't support it\n"); | 1891 | pci_info(dev, "Relaxed Ordering disabled because the Root Port didn't support it\n"); |
1875 | } | 1892 | } |
1876 | } | 1893 | } |
1877 | 1894 | ||
1895 | static void pci_configure_ltr(struct pci_dev *dev) | ||
1896 | { | ||
1897 | #ifdef CONFIG_PCIEASPM | ||
1898 | u32 cap; | ||
1899 | struct pci_dev *bridge; | ||
1900 | |||
1901 | if (!pci_is_pcie(dev)) | ||
1902 | return; | ||
1903 | |||
1904 | pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); | ||
1905 | if (!(cap & PCI_EXP_DEVCAP2_LTR)) | ||
1906 | return; | ||
1907 | |||
1908 | /* | ||
1909 | * Software must not enable LTR in an Endpoint unless the Root | ||
1910 | * Complex and all intermediate Switches indicate support for LTR. | ||
1911 | * PCIe r3.1, sec 6.18. | ||
1912 | */ | ||
1913 | if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) | ||
1914 | dev->ltr_path = 1; | ||
1915 | else { | ||
1916 | bridge = pci_upstream_bridge(dev); | ||
1917 | if (bridge && bridge->ltr_path) | ||
1918 | dev->ltr_path = 1; | ||
1919 | } | ||
1920 | |||
1921 | if (dev->ltr_path) | ||
1922 | pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, | ||
1923 | PCI_EXP_DEVCTL2_LTR_EN); | ||
1924 | #endif | ||
1925 | } | ||
1926 | |||
1878 | static void pci_configure_device(struct pci_dev *dev) | 1927 | static void pci_configure_device(struct pci_dev *dev) |
1879 | { | 1928 | { |
1880 | struct hotplug_params hpp; | 1929 | struct hotplug_params hpp; |
@@ -1883,6 +1932,7 @@ static void pci_configure_device(struct pci_dev *dev) | |||
1883 | pci_configure_mps(dev); | 1932 | pci_configure_mps(dev); |
1884 | pci_configure_extended_tags(dev, NULL); | 1933 | pci_configure_extended_tags(dev, NULL); |
1885 | pci_configure_relaxed_ordering(dev); | 1934 | pci_configure_relaxed_ordering(dev); |
1935 | pci_configure_ltr(dev); | ||
1886 | 1936 | ||
1887 | memset(&hpp, 0, sizeof(hpp)); | 1937 | memset(&hpp, 0, sizeof(hpp)); |
1888 | ret = pci_get_hp_params(dev, &hpp); | 1938 | ret = pci_get_hp_params(dev, &hpp); |
@@ -1902,10 +1952,11 @@ static void pci_release_capabilities(struct pci_dev *dev) | |||
1902 | } | 1952 | } |
1903 | 1953 | ||
1904 | /** | 1954 | /** |
1905 | * pci_release_dev - free a pci device structure when all users of it are finished. | 1955 | * pci_release_dev - Free a PCI device structure when all users of it are |
1956 | * finished | ||
1906 | * @dev: device that's been disconnected | 1957 | * @dev: device that's been disconnected |
1907 | * | 1958 | * |
1908 | * Will be called only by the device core when all users of this pci device are | 1959 | * Will be called only by the device core when all users of this PCI device are |
1909 | * done. | 1960 | * done. |
1910 | */ | 1961 | */ |
1911 | static void pci_release_dev(struct device *dev) | 1962 | static void pci_release_dev(struct device *dev) |
@@ -1993,7 +2044,7 @@ bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, | |||
1993 | if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, l)) | 2044 | if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, l)) |
1994 | return false; | 2045 | return false; |
1995 | 2046 | ||
1996 | /* some broken boards return 0 or ~0 if a slot is empty: */ | 2047 | /* Some broken boards return 0 or ~0 if a slot is empty: */ |
1997 | if (*l == 0xffffffff || *l == 0x00000000 || | 2048 | if (*l == 0xffffffff || *l == 0x00000000 || |
1998 | *l == 0x0000ffff || *l == 0xffff0000) | 2049 | *l == 0x0000ffff || *l == 0xffff0000) |
1999 | return false; | 2050 | return false; |
@@ -2006,8 +2057,8 @@ bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, | |||
2006 | EXPORT_SYMBOL(pci_bus_read_dev_vendor_id); | 2057 | EXPORT_SYMBOL(pci_bus_read_dev_vendor_id); |
2007 | 2058 | ||
2008 | /* | 2059 | /* |
2009 | * Read the config data for a PCI device, sanity-check it | 2060 | * Read the config data for a PCI device, sanity-check it, |
2010 | * and fill in the dev structure... | 2061 | * and fill in the dev structure. |
2011 | */ | 2062 | */ |
2012 | static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) | 2063 | static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) |
2013 | { | 2064 | { |
@@ -2073,7 +2124,7 @@ static void pci_init_capabilities(struct pci_dev *dev) | |||
2073 | } | 2124 | } |
2074 | 2125 | ||
2075 | /* | 2126 | /* |
2076 | * This is the equivalent of pci_host_bridge_msi_domain that acts on | 2127 | * This is the equivalent of pci_host_bridge_msi_domain() that acts on |
2077 | * devices. Firmware interfaces that can select the MSI domain on a | 2128 | * devices. Firmware interfaces that can select the MSI domain on a |
2078 | * per-device basis should be called from here. | 2129 | * per-device basis should be called from here. |
2079 | */ | 2130 | */ |
@@ -2082,7 +2133,7 @@ static struct irq_domain *pci_dev_msi_domain(struct pci_dev *dev) | |||
2082 | struct irq_domain *d; | 2133 | struct irq_domain *d; |
2083 | 2134 | ||
2084 | /* | 2135 | /* |
2085 | * If a domain has been set through the pcibios_add_device | 2136 | * If a domain has been set through the pcibios_add_device() |
2086 | * callback, then this is the one (platform code knows best). | 2137 | * callback, then this is the one (platform code knows best). |
2087 | */ | 2138 | */ |
2088 | d = dev_get_msi_domain(&dev->dev); | 2139 | d = dev_get_msi_domain(&dev->dev); |
@@ -2136,10 +2187,10 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) | |||
2136 | /* Fix up broken headers */ | 2187 | /* Fix up broken headers */ |
2137 | pci_fixup_device(pci_fixup_header, dev); | 2188 | pci_fixup_device(pci_fixup_header, dev); |
2138 | 2189 | ||
2139 | /* moved out from quirk header fixup code */ | 2190 | /* Moved out from quirk header fixup code */ |
2140 | pci_reassigndev_resource_alignment(dev); | 2191 | pci_reassigndev_resource_alignment(dev); |
2141 | 2192 | ||
2142 | /* Clear the state_saved flag. */ | 2193 | /* Clear the state_saved flag */ |
2143 | dev->state_saved = false; | 2194 | dev->state_saved = false; |
2144 | 2195 | ||
2145 | /* Initialize various capabilities */ | 2196 | /* Initialize various capabilities */ |
@@ -2156,7 +2207,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) | |||
2156 | ret = pcibios_add_device(dev); | 2207 | ret = pcibios_add_device(dev); |
2157 | WARN_ON(ret < 0); | 2208 | WARN_ON(ret < 0); |
2158 | 2209 | ||
2159 | /* Setup MSI irq domain */ | 2210 | /* Set up MSI IRQ domain */ |
2160 | pci_set_msi_domain(dev); | 2211 | pci_set_msi_domain(dev); |
2161 | 2212 | ||
2162 | /* Notifier could use PCI capabilities */ | 2213 | /* Notifier could use PCI capabilities */ |
@@ -2215,29 +2266,34 @@ static unsigned next_fn(struct pci_bus *bus, struct pci_dev *dev, unsigned fn) | |||
2215 | 2266 | ||
2216 | static int only_one_child(struct pci_bus *bus) | 2267 | static int only_one_child(struct pci_bus *bus) |
2217 | { | 2268 | { |
2218 | struct pci_dev *parent = bus->self; | 2269 | struct pci_dev *bridge = bus->self; |
2219 | 2270 | ||
2220 | if (!parent || !pci_is_pcie(parent)) | 2271 | /* |
2272 | * Systems with unusual topologies set PCI_SCAN_ALL_PCIE_DEVS so | ||
2273 | * we scan for all possible devices, not just Device 0. | ||
2274 | */ | ||
2275 | if (pci_has_flag(PCI_SCAN_ALL_PCIE_DEVS)) | ||
2221 | return 0; | 2276 | return 0; |
2222 | if (pci_pcie_type(parent) == PCI_EXP_TYPE_ROOT_PORT) | ||
2223 | return 1; | ||
2224 | 2277 | ||
2225 | /* | 2278 | /* |
2226 | * PCIe downstream ports are bridges that normally lead to only a | 2279 | * A PCIe Downstream Port normally leads to a Link with only Device |
2227 | * device 0, but if PCI_SCAN_ALL_PCIE_DEVS is set, scan all | 2280 | * 0 on it (PCIe spec r3.1, sec 7.3.1). As an optimization, scan |
2228 | * possible devices, not just device 0. See PCIe spec r3.0, | 2281 | * only for Device 0 in that situation. |
2229 | * sec 7.3.1. | 2282 | * |
2283 | * Checking has_secondary_link is a hack to identify Downstream | ||
2284 | * Ports because sometimes Switches are configured such that the | ||
2285 | * PCIe Port Type labels are backwards. | ||
2230 | */ | 2286 | */ |
2231 | if (parent->has_secondary_link && | 2287 | if (bridge && pci_is_pcie(bridge) && bridge->has_secondary_link) |
2232 | !pci_has_flag(PCI_SCAN_ALL_PCIE_DEVS)) | ||
2233 | return 1; | 2288 | return 1; |
2289 | |||
2234 | return 0; | 2290 | return 0; |
2235 | } | 2291 | } |
2236 | 2292 | ||
2237 | /** | 2293 | /** |
2238 | * pci_scan_slot - scan a PCI slot on a bus for devices. | 2294 | * pci_scan_slot - Scan a PCI slot on a bus for devices |
2239 | * @bus: PCI bus to scan | 2295 | * @bus: PCI bus to scan |
2240 | * @devfn: slot number to scan (must have zero function.) | 2296 | * @devfn: slot number to scan (must have zero function) |
2241 | * | 2297 | * |
2242 | * Scan a PCI slot on the specified PCI bus for devices, adding | 2298 | * Scan a PCI slot on the specified PCI bus for devices, adding |
2243 | * discovered devices to the @bus->devices list. New devices | 2299 | * discovered devices to the @bus->devices list. New devices |
@@ -2268,7 +2324,7 @@ int pci_scan_slot(struct pci_bus *bus, int devfn) | |||
2268 | } | 2324 | } |
2269 | } | 2325 | } |
2270 | 2326 | ||
2271 | /* only one slot has pcie device */ | 2327 | /* Only one slot has PCIe device */ |
2272 | if (bus->self && nr) | 2328 | if (bus->self && nr) |
2273 | pcie_aspm_init_link_state(bus->self); | 2329 | pcie_aspm_init_link_state(bus->self); |
2274 | 2330 | ||
@@ -2317,7 +2373,9 @@ static void pcie_write_mps(struct pci_dev *dev, int mps) | |||
2317 | 2373 | ||
2318 | if (pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT && | 2374 | if (pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT && |
2319 | dev->bus->self) | 2375 | dev->bus->self) |
2320 | /* For "Performance", the assumption is made that | 2376 | |
2377 | /* | ||
2378 | * For "Performance", the assumption is made that | ||
2321 | * downstream communication will never be larger than | 2379 | * downstream communication will never be larger than |
2322 | * the MRRS. So, the MPS only needs to be configured | 2380 | * the MRRS. So, the MPS only needs to be configured |
2323 | * for the upstream communication. This being the case, | 2381 | * for the upstream communication. This being the case, |
@@ -2334,27 +2392,30 @@ static void pcie_write_mps(struct pci_dev *dev, int mps) | |||
2334 | 2392 | ||
2335 | rc = pcie_set_mps(dev, mps); | 2393 | rc = pcie_set_mps(dev, mps); |
2336 | if (rc) | 2394 | if (rc) |
2337 | dev_err(&dev->dev, "Failed attempting to set the MPS\n"); | 2395 | pci_err(dev, "Failed attempting to set the MPS\n"); |
2338 | } | 2396 | } |
2339 | 2397 | ||
2340 | static void pcie_write_mrrs(struct pci_dev *dev) | 2398 | static void pcie_write_mrrs(struct pci_dev *dev) |
2341 | { | 2399 | { |
2342 | int rc, mrrs; | 2400 | int rc, mrrs; |
2343 | 2401 | ||
2344 | /* In the "safe" case, do not configure the MRRS. There appear to be | 2402 | /* |
2403 | * In the "safe" case, do not configure the MRRS. There appear to be | ||
2345 | * issues with setting MRRS to 0 on a number of devices. | 2404 | * issues with setting MRRS to 0 on a number of devices. |
2346 | */ | 2405 | */ |
2347 | if (pcie_bus_config != PCIE_BUS_PERFORMANCE) | 2406 | if (pcie_bus_config != PCIE_BUS_PERFORMANCE) |
2348 | return; | 2407 | return; |
2349 | 2408 | ||
2350 | /* For Max performance, the MRRS must be set to the largest supported | 2409 | /* |
2410 | * For max performance, the MRRS must be set to the largest supported | ||
2351 | * value. However, it cannot be configured larger than the MPS the | 2411 | * value. However, it cannot be configured larger than the MPS the |
2352 | * device or the bus can support. This should already be properly | 2412 | * device or the bus can support. This should already be properly |
2353 | * configured by a prior call to pcie_write_mps. | 2413 | * configured by a prior call to pcie_write_mps(). |
2354 | */ | 2414 | */ |
2355 | mrrs = pcie_get_mps(dev); | 2415 | mrrs = pcie_get_mps(dev); |
2356 | 2416 | ||
2357 | /* MRRS is a R/W register. Invalid values can be written, but a | 2417 | /* |
2418 | * MRRS is a R/W register. Invalid values can be written, but a | ||
2358 | * subsequent read will verify if the value is acceptable or not. | 2419 | * subsequent read will verify if the value is acceptable or not. |
2359 | * If the MRRS value provided is not acceptable (e.g., too large), | 2420 | * If the MRRS value provided is not acceptable (e.g., too large), |
2360 | * shrink the value until it is acceptable to the HW. | 2421 | * shrink the value until it is acceptable to the HW. |
@@ -2364,12 +2425,12 @@ static void pcie_write_mrrs(struct pci_dev *dev) | |||
2364 | if (!rc) | 2425 | if (!rc) |
2365 | break; | 2426 | break; |
2366 | 2427 | ||
2367 | dev_warn(&dev->dev, "Failed attempting to set the MRRS\n"); | 2428 | pci_warn(dev, "Failed attempting to set the MRRS\n"); |
2368 | mrrs /= 2; | 2429 | mrrs /= 2; |
2369 | } | 2430 | } |
2370 | 2431 | ||
2371 | if (mrrs < 128) | 2432 | if (mrrs < 128) |
2372 | dev_err(&dev->dev, "MRRS was unable to be configured with a safe value. If problems are experienced, try running with pci=pcie_bus_safe\n"); | 2433 | pci_err(dev, "MRRS was unable to be configured with a safe value. If problems are experienced, try running with pci=pcie_bus_safe\n"); |
2373 | } | 2434 | } |
2374 | 2435 | ||
2375 | static int pcie_bus_configure_set(struct pci_dev *dev, void *data) | 2436 | static int pcie_bus_configure_set(struct pci_dev *dev, void *data) |
@@ -2389,14 +2450,15 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data) | |||
2389 | pcie_write_mps(dev, mps); | 2450 | pcie_write_mps(dev, mps); |
2390 | pcie_write_mrrs(dev); | 2451 | pcie_write_mrrs(dev); |
2391 | 2452 | ||
2392 | dev_info(&dev->dev, "Max Payload Size set to %4d/%4d (was %4d), Max Read Rq %4d\n", | 2453 | pci_info(dev, "Max Payload Size set to %4d/%4d (was %4d), Max Read Rq %4d\n", |
2393 | pcie_get_mps(dev), 128 << dev->pcie_mpss, | 2454 | pcie_get_mps(dev), 128 << dev->pcie_mpss, |
2394 | orig_mps, pcie_get_readrq(dev)); | 2455 | orig_mps, pcie_get_readrq(dev)); |
2395 | 2456 | ||
2396 | return 0; | 2457 | return 0; |
2397 | } | 2458 | } |
2398 | 2459 | ||
2399 | /* pcie_bus_configure_settings requires that pci_walk_bus work in a top-down, | 2460 | /* |
2461 | * pcie_bus_configure_settings() requires that pci_walk_bus work in a top-down, | ||
2400 | * parents then children fashion. If this changes, then this code will not | 2462 | * parents then children fashion. If this changes, then this code will not |
2401 | * work as designed. | 2463 | * work as designed. |
2402 | */ | 2464 | */ |
@@ -2410,7 +2472,8 @@ void pcie_bus_configure_settings(struct pci_bus *bus) | |||
2410 | if (!pci_is_pcie(bus->self)) | 2472 | if (!pci_is_pcie(bus->self)) |
2411 | return; | 2473 | return; |
2412 | 2474 | ||
2413 | /* FIXME - Peer to peer DMA is possible, though the endpoint would need | 2475 | /* |
2476 | * FIXME - Peer to peer DMA is possible, though the endpoint would need | ||
2414 | * to be aware of the MPS of the destination. To work around this, | 2477 | * to be aware of the MPS of the destination. To work around this, |
2415 | * simply force the MPS of the entire system to the smallest possible. | 2478 | * simply force the MPS of the entire system to the smallest possible. |
2416 | */ | 2479 | */ |
@@ -2464,7 +2527,7 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, | |||
2464 | for (devfn = 0; devfn < 0x100; devfn += 8) | 2527 | for (devfn = 0; devfn < 0x100; devfn += 8) |
2465 | pci_scan_slot(bus, devfn); | 2528 | pci_scan_slot(bus, devfn); |
2466 | 2529 | ||
2467 | /* Reserve buses for SR-IOV capability. */ | 2530 | /* Reserve buses for SR-IOV capability */ |
2468 | used_buses = pci_iov_bus_range(bus); | 2531 | used_buses = pci_iov_bus_range(bus); |
2469 | max += used_buses; | 2532 | max += used_buses; |
2470 | 2533 | ||
@@ -2506,6 +2569,7 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, | |||
2506 | unsigned int buses = 0; | 2569 | unsigned int buses = 0; |
2507 | 2570 | ||
2508 | if (!hotplug_bridges && normal_bridges == 1) { | 2571 | if (!hotplug_bridges && normal_bridges == 1) { |
2572 | |||
2509 | /* | 2573 | /* |
2510 | * There is only one bridge on the bus (upstream | 2574 | * There is only one bridge on the bus (upstream |
2511 | * port) so it gets all available buses which it | 2575 | * port) so it gets all available buses which it |
@@ -2514,6 +2578,7 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, | |||
2514 | */ | 2578 | */ |
2515 | buses = available_buses; | 2579 | buses = available_buses; |
2516 | } else if (dev->is_hotplug_bridge) { | 2580 | } else if (dev->is_hotplug_bridge) { |
2581 | |||
2517 | /* | 2582 | /* |
2518 | * Distribute the extra buses between hotplug | 2583 | * Distribute the extra buses between hotplug |
2519 | * bridges if any. | 2584 | * bridges if any. |
@@ -2572,8 +2637,8 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) | |||
2572 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); | 2637 | EXPORT_SYMBOL_GPL(pci_scan_child_bus); |
2573 | 2638 | ||
2574 | /** | 2639 | /** |
2575 | * pcibios_root_bridge_prepare - Platform-specific host bridge setup. | 2640 | * pcibios_root_bridge_prepare - Platform-specific host bridge setup |
2576 | * @bridge: Host bridge to set up. | 2641 | * @bridge: Host bridge to set up |
2577 | * | 2642 | * |
2578 | * Default empty implementation. Replace with an architecture-specific setup | 2643 | * Default empty implementation. Replace with an architecture-specific setup |
2579 | * routine, if necessary. | 2644 | * routine, if necessary. |
@@ -2620,6 +2685,39 @@ err_out: | |||
2620 | } | 2685 | } |
2621 | EXPORT_SYMBOL_GPL(pci_create_root_bus); | 2686 | EXPORT_SYMBOL_GPL(pci_create_root_bus); |
2622 | 2687 | ||
2688 | int pci_host_probe(struct pci_host_bridge *bridge) | ||
2689 | { | ||
2690 | struct pci_bus *bus, *child; | ||
2691 | int ret; | ||
2692 | |||
2693 | ret = pci_scan_root_bus_bridge(bridge); | ||
2694 | if (ret < 0) { | ||
2695 | dev_err(bridge->dev.parent, "Scanning root bridge failed"); | ||
2696 | return ret; | ||
2697 | } | ||
2698 | |||
2699 | bus = bridge->bus; | ||
2700 | |||
2701 | /* | ||
2702 | * We insert PCI resources into the iomem_resource and | ||
2703 | * ioport_resource trees in either pci_bus_claim_resources() | ||
2704 | * or pci_bus_assign_resources(). | ||
2705 | */ | ||
2706 | if (pci_has_flag(PCI_PROBE_ONLY)) { | ||
2707 | pci_bus_claim_resources(bus); | ||
2708 | } else { | ||
2709 | pci_bus_size_bridges(bus); | ||
2710 | pci_bus_assign_resources(bus); | ||
2711 | |||
2712 | list_for_each_entry(child, &bus->children, node) | ||
2713 | pcie_bus_configure_settings(child); | ||
2714 | } | ||
2715 | |||
2716 | pci_bus_add_devices(bus); | ||
2717 | return 0; | ||
2718 | } | ||
2719 | EXPORT_SYMBOL_GPL(pci_host_probe); | ||
2720 | |||
2623 | int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int bus_max) | 2721 | int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int bus_max) |
2624 | { | 2722 | { |
2625 | struct resource *res = &b->busn_res; | 2723 | struct resource *res = &b->busn_res; |
@@ -2776,7 +2874,7 @@ struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, | |||
2776 | EXPORT_SYMBOL(pci_scan_bus); | 2874 | EXPORT_SYMBOL(pci_scan_bus); |
2777 | 2875 | ||
2778 | /** | 2876 | /** |
2779 | * pci_rescan_bus_bridge_resize - scan a PCI bus for devices. | 2877 | * pci_rescan_bus_bridge_resize - Scan a PCI bus for devices |
2780 | * @bridge: PCI bridge for the bus to scan | 2878 | * @bridge: PCI bridge for the bus to scan |
2781 | * | 2879 | * |
2782 | * Scan a PCI bus and child buses for new devices, add them, | 2880 | * Scan a PCI bus and child buses for new devices, add them, |
@@ -2801,11 +2899,11 @@ unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge) | |||
2801 | } | 2899 | } |
2802 | 2900 | ||
2803 | /** | 2901 | /** |
2804 | * pci_rescan_bus - scan a PCI bus for devices. | 2902 | * pci_rescan_bus - Scan a PCI bus for devices |
2805 | * @bus: PCI bus to scan | 2903 | * @bus: PCI bus to scan |
2806 | * | 2904 | * |
2807 | * Scan a PCI bus and child buses for new devices, adds them, | 2905 | * Scan a PCI bus and child buses for new devices, add them, |
2808 | * and enables them. | 2906 | * and enable them. |
2809 | * | 2907 | * |
2810 | * Returns the max number of subordinate bus discovered. | 2908 | * Returns the max number of subordinate bus discovered. |
2811 | */ | 2909 | */ |
@@ -2874,7 +2972,7 @@ int pci_hp_add_bridge(struct pci_dev *dev) | |||
2874 | break; | 2972 | break; |
2875 | } | 2973 | } |
2876 | if (busnr-- > end) { | 2974 | if (busnr-- > end) { |
2877 | dev_err(&dev->dev, "No bus number available for hot-added bridge\n"); | 2975 | pci_err(dev, "No bus number available for hot-added bridge\n"); |
2878 | return -1; | 2976 | return -1; |
2879 | } | 2977 | } |
2880 | 2978 | ||