Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/pci.h> |
| 2 | #include <linux/acpi.h> |
| 3 | #include <linux/init.h> |
Nick Piggin | b33fa1f | 2005-10-01 02:34:42 +1000 | [diff] [blame] | 4 | #include <linux/irq.h> |
Gary Hade | 036fff4 | 2007-10-03 15:56:14 -0700 | [diff] [blame] | 5 | #include <linux/dmi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 6 | #include <linux/slab.h> |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 7 | #include <asm/numa.h> |
Jaswinder Singh Rajput | 8248771 | 2008-12-27 18:32:28 +0530 | [diff] [blame] | 8 | #include <asm/pci_x86.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 10 | struct pci_root_info { |
Bjorn Helgaas | 42887b2 | 2009-10-06 15:33:49 -0600 | [diff] [blame] | 11 | struct acpi_device *bridge; |
Yinghai Lu | fe05725 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 12 | char name[16]; |
Yinghai Lu | 35cb05e | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 13 | struct pci_sysdata sd; |
Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 14 | #ifdef CONFIG_PCI_MMCONFIG |
| 15 | bool mcfg_added; |
| 16 | u16 segment; |
| 17 | u8 start_bus; |
| 18 | u8 end_bus; |
| 19 | #endif |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 22 | static bool pci_use_crs = true; |
Bjorn Helgaas | 1f09b09 | 2012-10-29 17:26:54 -0600 | [diff] [blame] | 23 | static bool pci_ignore_seg = false; |
Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 24 | |
| 25 | static int __init set_use_crs(const struct dmi_system_id *id) |
| 26 | { |
| 27 | pci_use_crs = true; |
| 28 | return 0; |
| 29 | } |
| 30 | |
Dave Jones | 28c3c05 | 2011-12-30 14:37:05 -0500 | [diff] [blame] | 31 | static int __init set_nouse_crs(const struct dmi_system_id *id) |
| 32 | { |
| 33 | pci_use_crs = false; |
| 34 | return 0; |
| 35 | } |
| 36 | |
Bjorn Helgaas | 1f09b09 | 2012-10-29 17:26:54 -0600 | [diff] [blame] | 37 | static int __init set_ignore_seg(const struct dmi_system_id *id) |
| 38 | { |
| 39 | printk(KERN_INFO "PCI: %s detected: ignoring ACPI _SEG\n", id->ident); |
| 40 | pci_ignore_seg = true; |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static const struct dmi_system_id pci_crs_quirks[] __initconst = { |
Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 45 | /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */ |
| 46 | { |
| 47 | .callback = set_use_crs, |
| 48 | .ident = "IBM System x3800", |
| 49 | .matches = { |
| 50 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 51 | DMI_MATCH(DMI_PRODUCT_NAME, "x3800"), |
| 52 | }, |
| 53 | }, |
Bjorn Helgaas | 2491762 | 2010-07-23 12:53:27 -0600 | [diff] [blame] | 54 | /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */ |
| 55 | /* 2006 AMD HT/VIA system with two host bridges */ |
| 56 | { |
| 57 | .callback = set_use_crs, |
| 58 | .ident = "ASRock ALiveSATA2-GLAN", |
| 59 | .matches = { |
| 60 | DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"), |
| 61 | }, |
| 62 | }, |
Paul Menzel | 29cf7a30 | 2011-08-31 17:07:10 +0200 | [diff] [blame] | 63 | /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */ |
| 64 | /* 2006 AMD HT/VIA system with two host bridges */ |
| 65 | { |
| 66 | .callback = set_use_crs, |
| 67 | .ident = "ASUS M2V-MX SE", |
| 68 | .matches = { |
| 69 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), |
| 70 | DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"), |
| 71 | DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."), |
| 72 | }, |
| 73 | }, |
Jonathan Nieder | 84113717 | 2012-02-28 11:51:10 -0700 | [diff] [blame] | 74 | /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */ |
| 75 | { |
| 76 | .callback = set_use_crs, |
| 77 | .ident = "MSI MS-7253", |
| 78 | .matches = { |
| 79 | DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"), |
| 80 | DMI_MATCH(DMI_BOARD_NAME, "MS-7253"), |
| 81 | DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"), |
Jonathan Nieder | 84113717 | 2012-02-28 11:51:10 -0700 | [diff] [blame] | 82 | }, |
| 83 | }, |
Bjorn Helgaas | 1dace01 | 2015-06-09 18:54:07 -0500 | [diff] [blame] | 84 | /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/931368 */ |
| 85 | /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1033299 */ |
| 86 | { |
| 87 | .callback = set_use_crs, |
| 88 | .ident = "Foxconn K8M890-8237A", |
| 89 | .matches = { |
| 90 | DMI_MATCH(DMI_BOARD_VENDOR, "Foxconn"), |
| 91 | DMI_MATCH(DMI_BOARD_NAME, "K8M890-8237A"), |
| 92 | DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"), |
| 93 | }, |
| 94 | }, |
Dave Jones | 28c3c05 | 2011-12-30 14:37:05 -0500 | [diff] [blame] | 95 | |
Dave Jones | e702781 | 2012-01-04 11:33:12 -0500 | [diff] [blame] | 96 | /* Now for the blacklist.. */ |
| 97 | |
| 98 | /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */ |
| 99 | { |
| 100 | .callback = set_nouse_crs, |
| 101 | .ident = "Dell Studio 1557", |
| 102 | .matches = { |
| 103 | DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."), |
| 104 | DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"), |
| 105 | DMI_MATCH(DMI_BIOS_VERSION, "A09"), |
| 106 | }, |
| 107 | }, |
Dave Jones | 8b6a5af | 2012-01-04 11:30:52 -0500 | [diff] [blame] | 108 | /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */ |
| 109 | { |
| 110 | .callback = set_nouse_crs, |
| 111 | .ident = "Thinkpad SL510", |
| 112 | .matches = { |
| 113 | DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), |
| 114 | DMI_MATCH(DMI_BOARD_NAME, "2847DFG"), |
| 115 | DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"), |
| 116 | }, |
| 117 | }, |
Bjorn Helgaas | 1f09b09 | 2012-10-29 17:26:54 -0600 | [diff] [blame] | 118 | |
| 119 | /* https://bugzilla.kernel.org/show_bug.cgi?id=15362 */ |
| 120 | { |
| 121 | .callback = set_ignore_seg, |
| 122 | .ident = "HP xw9300", |
| 123 | .matches = { |
| 124 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 125 | DMI_MATCH(DMI_PRODUCT_NAME, "HP xw9300 Workstation"), |
| 126 | }, |
| 127 | }, |
Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 128 | {} |
| 129 | }; |
| 130 | |
| 131 | void __init pci_acpi_crs_quirks(void) |
| 132 | { |
| 133 | int year; |
| 134 | |
Bjorn Helgaas | 3d9fecf | 2015-06-09 17:31:38 -0500 | [diff] [blame] | 135 | if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008) { |
| 136 | if (iomem_resource.end <= 0xffffffff) |
| 137 | pci_use_crs = false; |
| 138 | } |
Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 139 | |
Bjorn Helgaas | 1f09b09 | 2012-10-29 17:26:54 -0600 | [diff] [blame] | 140 | dmi_check_system(pci_crs_quirks); |
Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that |
| 144 | * takes precedence over anything we figured out above. |
| 145 | */ |
| 146 | if (pci_probe & PCI_ROOT_NO_CRS) |
| 147 | pci_use_crs = false; |
| 148 | else if (pci_probe & PCI_USE__CRS) |
| 149 | pci_use_crs = true; |
| 150 | |
| 151 | printk(KERN_INFO "PCI: %s host bridge windows from ACPI; " |
| 152 | "if necessary, use \"pci=%s\" and report a bug\n", |
| 153 | pci_use_crs ? "Using" : "Ignoring", |
| 154 | pci_use_crs ? "nocrs" : "use_crs"); |
| 155 | } |
| 156 | |
Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 157 | #ifdef CONFIG_PCI_MMCONFIG |
Greg Kroah-Hartman | a18e369 | 2012-12-21 14:02:53 -0800 | [diff] [blame] | 158 | static int check_segment(u16 seg, struct device *dev, char *estr) |
Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 159 | { |
| 160 | if (seg) { |
| 161 | dev_err(dev, |
| 162 | "%s can't access PCI configuration " |
| 163 | "space under this host bridge.\n", |
| 164 | estr); |
| 165 | return -EIO; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Failure in adding MMCFG information is not fatal, |
| 170 | * just can't access extended configuration space of |
| 171 | * devices under this host bridge. |
| 172 | */ |
| 173 | dev_warn(dev, |
| 174 | "%s can't access extended PCI configuration " |
| 175 | "space under this bridge.\n", |
| 176 | estr); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Greg Kroah-Hartman | a18e369 | 2012-12-21 14:02:53 -0800 | [diff] [blame] | 181 | static int setup_mcfg_map(struct pci_root_info *info, u16 seg, u8 start, |
| 182 | u8 end, phys_addr_t addr) |
Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 183 | { |
| 184 | int result; |
| 185 | struct device *dev = &info->bridge->dev; |
| 186 | |
| 187 | info->start_bus = start; |
| 188 | info->end_bus = end; |
| 189 | info->mcfg_added = false; |
| 190 | |
| 191 | /* return success if MMCFG is not in use */ |
| 192 | if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg) |
| 193 | return 0; |
| 194 | |
| 195 | if (!(pci_probe & PCI_PROBE_MMCONF)) |
| 196 | return check_segment(seg, dev, "MMCONFIG is disabled,"); |
| 197 | |
| 198 | result = pci_mmconfig_insert(dev, seg, start, end, addr); |
| 199 | if (result == 0) { |
| 200 | /* enable MMCFG if it hasn't been enabled yet */ |
| 201 | if (raw_pci_ext_ops == NULL) |
| 202 | raw_pci_ext_ops = &pci_mmcfg; |
| 203 | info->mcfg_added = true; |
| 204 | } else if (result != -EEXIST) |
| 205 | return check_segment(seg, dev, |
| 206 | "fail to add MMCONFIG information,"); |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static void teardown_mcfg_map(struct pci_root_info *info) |
| 212 | { |
| 213 | if (info->mcfg_added) { |
| 214 | pci_mmconfig_delete(info->segment, info->start_bus, |
| 215 | info->end_bus); |
| 216 | info->mcfg_added = false; |
| 217 | } |
| 218 | } |
| 219 | #else |
Greg Kroah-Hartman | a18e369 | 2012-12-21 14:02:53 -0800 | [diff] [blame] | 220 | static int setup_mcfg_map(struct pci_root_info *info, |
Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 221 | u16 seg, u8 start, u8 end, |
| 222 | phys_addr_t addr) |
| 223 | { |
| 224 | return 0; |
| 225 | } |
| 226 | static void teardown_mcfg_map(struct pci_root_info *info) |
| 227 | { |
| 228 | } |
| 229 | #endif |
| 230 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 231 | static void validate_resources(struct device *dev, struct list_head *crs_res, |
| 232 | unsigned long type) |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 233 | { |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 234 | LIST_HEAD(list); |
| 235 | struct resource *res1, *res2, *root = NULL; |
| 236 | struct resource_entry *tmp, *entry, *entry2; |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 237 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 238 | BUG_ON((type & (IORESOURCE_MEM | IORESOURCE_IO)) == 0); |
| 239 | root = (type & IORESOURCE_MEM) ? &iomem_resource : &ioport_resource; |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 240 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 241 | list_splice_init(crs_res, &list); |
| 242 | resource_list_for_each_entry_safe(entry, tmp, &list) { |
| 243 | bool free = false; |
| 244 | resource_size_t end; |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 245 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 246 | res1 = entry->res; |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 247 | if (!(res1->flags & type)) |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 248 | goto next; |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 249 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 250 | /* Exclude non-addressable range or non-addressable portion */ |
| 251 | end = min(res1->end, root->end); |
| 252 | if (end <= res1->start) { |
| 253 | dev_info(dev, "host bridge window %pR (ignored, not CPU addressable)\n", |
| 254 | res1); |
| 255 | free = true; |
| 256 | goto next; |
| 257 | } else if (res1->end != end) { |
| 258 | dev_info(dev, "host bridge window %pR ([%#llx-%#llx] ignored, not CPU addressable)\n", |
| 259 | res1, (unsigned long long)end + 1, |
| 260 | (unsigned long long)res1->end); |
| 261 | res1->end = end; |
| 262 | } |
| 263 | |
| 264 | resource_list_for_each_entry(entry2, crs_res) { |
| 265 | res2 = entry2->res; |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 266 | if (!(res2->flags & type)) |
| 267 | continue; |
| 268 | |
| 269 | /* |
| 270 | * I don't like throwing away windows because then |
| 271 | * our resources no longer match the ACPI _CRS, but |
| 272 | * the kernel resource tree doesn't allow overlaps. |
| 273 | */ |
Wei Yang | 74d24b2 | 2012-04-26 15:32:55 +0800 | [diff] [blame] | 274 | if (resource_overlaps(res1, res2)) { |
Alexey Neyman | 3ad674d | 2013-10-09 16:16:38 -0600 | [diff] [blame] | 275 | res2->start = min(res1->start, res2->start); |
| 276 | res2->end = max(res1->end, res2->end); |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 277 | dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n", |
Alexey Neyman | 3ad674d | 2013-10-09 16:16:38 -0600 | [diff] [blame] | 278 | res2, res1); |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 279 | free = true; |
| 280 | goto next; |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 281 | } |
| 282 | } |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 283 | |
| 284 | next: |
| 285 | resource_list_del(entry); |
| 286 | if (free) |
| 287 | resource_list_free_entry(entry); |
| 288 | else |
| 289 | resource_list_add_tail(entry, crs_res); |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 293 | static void add_resources(struct pci_root_info *info, |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 294 | struct list_head *resources, |
| 295 | struct list_head *crs_res) |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 296 | { |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 297 | struct resource_entry *entry, *tmp; |
| 298 | struct resource *res, *conflict, *root = NULL; |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 299 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 300 | validate_resources(&info->bridge->dev, crs_res, IORESOURCE_MEM); |
| 301 | validate_resources(&info->bridge->dev, crs_res, IORESOURCE_IO); |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 302 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 303 | resource_list_for_each_entry_safe(entry, tmp, crs_res) { |
| 304 | res = entry->res; |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 305 | if (res->flags & IORESOURCE_MEM) |
| 306 | root = &iomem_resource; |
| 307 | else if (res->flags & IORESOURCE_IO) |
| 308 | root = &ioport_resource; |
| 309 | else |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 310 | BUG_ON(res); |
Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 311 | |
| 312 | conflict = insert_resource_conflict(root, res); |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 313 | if (conflict) { |
Bjorn Helgaas | 43d786e | 2011-07-02 10:47:12 -0600 | [diff] [blame] | 314 | dev_info(&info->bridge->dev, |
| 315 | "ignoring host bridge window %pR (conflicts with %s %pR)\n", |
| 316 | res, conflict->name, conflict); |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 317 | resource_list_destroy_entry(entry); |
| 318 | } |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 321 | list_splice_tail(crs_res, resources); |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 322 | } |
Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 323 | |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 324 | static void release_pci_root_info(struct pci_host_bridge *bridge) |
| 325 | { |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 326 | struct resource *res; |
| 327 | struct resource_entry *entry; |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 328 | struct pci_root_info *info = bridge->release_data; |
| 329 | |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 330 | resource_list_for_each_entry(entry, &bridge->windows) { |
| 331 | res = entry->res; |
| 332 | if (res->parent && |
| 333 | (res->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 334 | release_resource(res); |
| 335 | } |
| 336 | |
| 337 | teardown_mcfg_map(info); |
| 338 | kfree(info); |
Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Jiang Liu | 2c62e84 | 2015-04-30 12:41:28 +0800 | [diff] [blame] | 341 | /* |
| 342 | * An IO port or MMIO resource assigned to a PCI host bridge may be |
| 343 | * consumed by the host bridge itself or available to its child |
| 344 | * bus/devices. The ACPI specification defines a bit (Producer/Consumer) |
| 345 | * to tell whether the resource is consumed by the host bridge itself, |
| 346 | * but firmware hasn't used that bit consistently, so we can't rely on it. |
| 347 | * |
| 348 | * On x86 and IA64 platforms, all IO port and MMIO resources are assumed |
| 349 | * to be available to child bus/devices except one special case: |
| 350 | * IO port [0xCF8-0xCFF] is consumed by the host bridge itself |
| 351 | * to access PCI configuration space. |
| 352 | * |
| 353 | * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF]. |
| 354 | */ |
| 355 | static bool resource_is_pcicfg_ioport(struct resource *res) |
| 356 | { |
| 357 | return (res->flags & IORESOURCE_IO) && |
| 358 | res->start == 0xCF8 && res->end == 0xCFF; |
| 359 | } |
| 360 | |
Bjorn Helgaas | da5d727 | 2014-01-24 10:44:42 -0700 | [diff] [blame] | 361 | static void probe_pci_root_info(struct pci_root_info *info, |
| 362 | struct acpi_device *device, |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 363 | int busnum, int domain, |
| 364 | struct list_head *list) |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 365 | { |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 366 | int ret; |
Jiang Liu | 63f1789 | 2015-03-04 16:47:11 +0800 | [diff] [blame] | 367 | struct resource_entry *entry, *tmp; |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 368 | |
Yinghai Lu | 5c1d81d | 2012-05-17 18:51:12 -0700 | [diff] [blame] | 369 | sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum); |
Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 370 | info->bridge = device; |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 371 | ret = acpi_dev_get_resources(device, list, |
| 372 | acpi_dev_filter_resource_type_cb, |
| 373 | (void *)(IORESOURCE_IO | IORESOURCE_MEM)); |
| 374 | if (ret < 0) |
| 375 | dev_warn(&device->dev, |
| 376 | "failed to parse _CRS method, error code %d\n", ret); |
| 377 | else if (ret == 0) |
| 378 | dev_dbg(&device->dev, |
| 379 | "no IO and memory resources present in _CRS\n"); |
| 380 | else |
Jiang Liu | 63f1789 | 2015-03-04 16:47:11 +0800 | [diff] [blame] | 381 | resource_list_for_each_entry_safe(entry, tmp, list) { |
Jiang Liu | 2c62e84 | 2015-04-30 12:41:28 +0800 | [diff] [blame] | 382 | if ((entry->res->flags & IORESOURCE_DISABLED) || |
| 383 | resource_is_pcicfg_ioport(entry->res)) |
Jiang Liu | 63f1789 | 2015-03-04 16:47:11 +0800 | [diff] [blame] | 384 | resource_list_destroy_entry(entry); |
| 385 | else |
| 386 | entry->res->name = info->name; |
| 387 | } |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Greg Kroah-Hartman | a18e369 | 2012-12-21 14:02:53 -0800 | [diff] [blame] | 390 | struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
Bjorn Helgaas | 5728377 | 2010-03-11 12:20:11 -0700 | [diff] [blame] | 392 | struct acpi_device *device = root->device; |
Bjorn Helgaas | 8928d5a | 2014-01-24 10:41:11 -0700 | [diff] [blame] | 393 | struct pci_root_info *info; |
Bjorn Helgaas | 5728377 | 2010-03-11 12:20:11 -0700 | [diff] [blame] | 394 | int domain = root->segment; |
| 395 | int busnum = root->secondary.start; |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 396 | struct resource_entry *res_entry; |
| 397 | LIST_HEAD(crs_res); |
Bjorn Helgaas | 2cd6975 | 2011-10-28 16:28:14 -0600 | [diff] [blame] | 398 | LIST_HEAD(resources); |
Bjorn Helgaas | 8928d5a | 2014-01-24 10:41:11 -0700 | [diff] [blame] | 399 | struct pci_bus *bus; |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 400 | struct pci_sysdata *sd; |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 401 | int node; |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 402 | |
Bjorn Helgaas | 1f09b09 | 2012-10-29 17:26:54 -0600 | [diff] [blame] | 403 | if (pci_ignore_seg) |
| 404 | domain = 0; |
| 405 | |
Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 406 | if (domain && !pci_domains_supported) { |
Bjorn Helgaas | 2a6bed8 | 2009-11-04 10:32:47 -0700 | [diff] [blame] | 407 | printk(KERN_WARNING "pci_bus %04x:%02x: " |
| 408 | "ignored (multiple domains not supported)\n", |
| 409 | domain, busnum); |
Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 410 | return NULL; |
| 411 | } |
| 412 | |
Bjorn Helgaas | ab6ffce | 2014-01-24 14:40:46 -0700 | [diff] [blame] | 413 | node = acpi_get_node(device->handle); |
Myron Stowe | 3367310 | 2014-05-08 11:44:20 -0500 | [diff] [blame] | 414 | if (node == NUMA_NO_NODE) { |
Bjorn Helgaas | 6616dbd | 2014-01-24 11:54:51 -0700 | [diff] [blame] | 415 | node = x86_pci_root_bus_node(busnum); |
Myron Stowe | 3367310 | 2014-05-08 11:44:20 -0500 | [diff] [blame] | 416 | if (node != 0 && node != NUMA_NO_NODE) |
| 417 | dev_info(&device->dev, FW_BUG "no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n", |
| 418 | node); |
| 419 | } |
Yinghai Lu | b755de8 | 2008-02-20 12:41:52 -0800 | [diff] [blame] | 420 | |
Bjorn Helgaas | 8a3d01c | 2014-01-24 14:51:49 -0700 | [diff] [blame] | 421 | if (node != NUMA_NO_NODE && !node_online(node)) |
| 422 | node = NUMA_NO_NODE; |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 423 | |
Jiang Liu | 965cd0e | 2014-06-09 16:19:34 +0800 | [diff] [blame] | 424 | info = kzalloc_node(sizeof(*info), GFP_KERNEL, node); |
Yinghai Lu | 35cb05e | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 425 | if (!info) { |
Bjorn Helgaas | 2a6bed8 | 2009-11-04 10:32:47 -0700 | [diff] [blame] | 426 | printk(KERN_WARNING "pci_bus %04x:%02x: " |
| 427 | "ignored (out of memory)\n", domain, busnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return NULL; |
| 429 | } |
| 430 | |
Yinghai Lu | 35cb05e | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 431 | sd = &info->sd; |
Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 432 | sd->domain = domain; |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 433 | sd->node = node; |
Rafael J. Wysocki | 7b19981 | 2013-11-11 22:41:56 +0100 | [diff] [blame] | 434 | sd->companion = device; |
Bjorn Helgaas | affbda8 | 2014-01-24 10:38:40 -0700 | [diff] [blame] | 435 | |
yakui.zhao@intel.com | b87e81e | 2008-04-15 14:34:49 -0700 | [diff] [blame] | 436 | bus = pci_find_bus(domain, busnum); |
| 437 | if (bus) { |
| 438 | /* |
Bjorn Helgaas | affbda8 | 2014-01-24 10:38:40 -0700 | [diff] [blame] | 439 | * If the desired bus has been scanned already, replace |
| 440 | * its bus->sysdata. |
yakui.zhao@intel.com | b87e81e | 2008-04-15 14:34:49 -0700 | [diff] [blame] | 441 | */ |
| 442 | memcpy(bus->sysdata, sd, sizeof(*sd)); |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 443 | kfree(info); |
Yinghai Lu | 626fdfe | 2009-06-24 20:00:12 -0700 | [diff] [blame] | 444 | } else { |
Yinghai Lu | 5c1d81d | 2012-05-17 18:51:12 -0700 | [diff] [blame] | 445 | /* insert busn res at first */ |
| 446 | pci_add_resource(&resources, &root->secondary); |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 447 | |
Bjorn Helgaas | 316d86f | 2012-01-17 17:41:21 -0700 | [diff] [blame] | 448 | /* |
| 449 | * _CRS with no apertures is normal, so only fall back to |
| 450 | * defaults or native bridge info if we're ignoring _CRS. |
| 451 | */ |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 452 | probe_pci_root_info(info, device, busnum, domain, &crs_res); |
| 453 | if (pci_use_crs) { |
| 454 | add_resources(info, &resources, &crs_res); |
| 455 | } else { |
| 456 | resource_list_for_each_entry(res_entry, &crs_res) |
| 457 | dev_printk(KERN_DEBUG, &device->dev, |
| 458 | "host bridge window %pR (ignored)\n", |
| 459 | res_entry->res); |
| 460 | resource_list_free(&crs_res); |
Bjorn Helgaas | 2cd6975 | 2011-10-28 16:28:14 -0600 | [diff] [blame] | 461 | x86_pci_root_bus_resources(busnum, &resources); |
Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 462 | } |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 463 | |
Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 464 | if (!setup_mcfg_map(info, domain, (u8)root->secondary.start, |
| 465 | (u8)root->secondary.end, root->mcfg_addr)) |
| 466 | bus = pci_create_root_bus(NULL, busnum, &pci_root_ops, |
| 467 | sd, &resources); |
| 468 | |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 469 | if (bus) { |
Yinghai Lu | 5c1d81d | 2012-05-17 18:51:12 -0700 | [diff] [blame] | 470 | pci_scan_child_bus(bus); |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 471 | pci_set_host_bridge_release( |
| 472 | to_pci_host_bridge(bus->bridge), |
| 473 | release_pci_root_info, info); |
| 474 | } else { |
Jiang Liu | 593669c | 2015-02-05 13:44:46 +0800 | [diff] [blame] | 475 | resource_list_free(&resources); |
| 476 | teardown_mcfg_map(info); |
| 477 | kfree(info); |
Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 478 | } |
Yinghai Lu | 626fdfe | 2009-06-24 20:00:12 -0700 | [diff] [blame] | 479 | } |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 480 | |
Jon Mason | b03e749 | 2011-07-20 15:20:54 -0500 | [diff] [blame] | 481 | /* After the PCI-E bus has been walked and all devices discovered, |
| 482 | * configure any settings of the fabric that might be necessary. |
| 483 | */ |
| 484 | if (bus) { |
| 485 | struct pci_bus *child; |
Bjorn Helgaas | a58674f | 2013-08-22 11:24:44 +0800 | [diff] [blame] | 486 | list_for_each_entry(child, &bus->children, node) |
| 487 | pcie_bus_configure_settings(child); |
Jon Mason | b03e749 | 2011-07-20 15:20:54 -0500 | [diff] [blame] | 488 | } |
| 489 | |
Bjorn Helgaas | ab6ffce | 2014-01-24 14:40:46 -0700 | [diff] [blame] | 490 | if (bus && node != NUMA_NO_NODE) |
Bjorn Helgaas | 2b8c2ef | 2008-12-18 16:34:51 -0700 | [diff] [blame] | 491 | dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node); |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 492 | |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 493 | return bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Rafael J. Wysocki | 6c0cc95 | 2013-01-09 22:33:37 +0100 | [diff] [blame] | 496 | int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) |
| 497 | { |
Rafael J. Wysocki | dc4fdaf | 2015-05-28 01:39:53 +0200 | [diff] [blame] | 498 | /* |
| 499 | * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL |
| 500 | * here, pci_create_root_bus() has been called by someone else and |
| 501 | * sysdata is likely to be different from what we expect. Let it go in |
| 502 | * that case. |
| 503 | */ |
| 504 | if (!bridge->dev.parent) { |
| 505 | struct pci_sysdata *sd = bridge->bus->sysdata; |
| 506 | ACPI_COMPANION_SET(&bridge->dev, sd->companion); |
| 507 | } |
Rafael J. Wysocki | 6c0cc95 | 2013-01-09 22:33:37 +0100 | [diff] [blame] | 508 | return 0; |
| 509 | } |
| 510 | |
Robert Richter | 8dd779b | 2008-07-02 22:50:29 +0200 | [diff] [blame] | 511 | int __init pci_acpi_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { |
| 513 | struct pci_dev *dev = NULL; |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | if (acpi_noirq) |
Thomas Gleixner | b72d0db | 2009-08-29 16:24:51 +0200 | [diff] [blame] | 516 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n"); |
| 519 | acpi_irq_penalty_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | pcibios_enable_irq = acpi_pci_irq_enable; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 521 | pcibios_disable_irq = acpi_pci_irq_disable; |
Thomas Gleixner | ab3b379 | 2009-08-29 17:47:33 +0200 | [diff] [blame] | 522 | x86_init.pci.init_irq = x86_init_noop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
| 524 | if (pci_routeirq) { |
| 525 | /* |
| 526 | * PCI IRQ routing is set up by pci_enable_device(), but we |
| 527 | * also do it here in case there are still broken drivers that |
| 528 | * don't use pci_enable_device(). |
| 529 | */ |
| 530 | printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n"); |
Hanna Linder | fb37fb9 | 2005-11-06 23:39:36 -0800 | [diff] [blame] | 531 | for_each_pci_dev(dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | acpi_pci_irq_enable(dev); |
Bjorn Helgaas | 657472e | 2008-02-18 09:44:13 -0700 | [diff] [blame] | 533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return 0; |
| 536 | } |