blob: d93963340c3c0d958385ce4ec8aadcdfe225a174 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/pci.h>
2#include <linux/acpi.h>
3#include <linux/init.h>
Nick Pigginb33fa1f2005-10-01 02:34:42 +10004#include <linux/irq.h>
Gary Hade036fff42007-10-03 15:56:14 -07005#include <linux/dmi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09006#include <linux/slab.h>
Andi Kleen69e1a332005-09-12 18:49:24 +02007#include <asm/numa.h>
Jaswinder Singh Rajput82487712008-12-27 18:32:28 +05308#include <asm/pci_x86.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Gary Hade62f420f2007-10-03 15:56:51 -070010struct pci_root_info {
Bjorn Helgaas42887b22009-10-06 15:33:49 -060011 struct acpi_device *bridge;
Yinghai Lufe057252012-04-02 18:31:53 -070012 char name[16];
Yinghai Lu35cb05e2012-04-02 18:31:53 -070013 struct pci_sysdata sd;
Jiang Liuc0fa4072012-06-22 14:55:17 +080014#ifdef CONFIG_PCI_MMCONFIG
15 bool mcfg_added;
16 u16 segment;
17 u8 start_bus;
18 u8 end_bus;
19#endif
Gary Hade62f420f2007-10-03 15:56:51 -070020};
21
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -070022static bool pci_use_crs = true;
Bjorn Helgaas1f09b092012-10-29 17:26:54 -060023static bool pci_ignore_seg = false;
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -070024
25static int __init set_use_crs(const struct dmi_system_id *id)
26{
27 pci_use_crs = true;
28 return 0;
29}
30
Dave Jones28c3c052011-12-30 14:37:05 -050031static int __init set_nouse_crs(const struct dmi_system_id *id)
32{
33 pci_use_crs = false;
34 return 0;
35}
36
Bjorn Helgaas1f09b092012-10-29 17:26:54 -060037static 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
44static const struct dmi_system_id pci_crs_quirks[] __initconst = {
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -070045 /* 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 Helgaas24917622010-07-23 12:53:27 -060054 /* 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 Menzel29cf7a302011-08-31 17:07:10 +020063 /* 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 Nieder841137172012-02-28 11:51:10 -070074 /* 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 Nieder841137172012-02-28 11:51:10 -070082 },
83 },
Dave Jones28c3c052011-12-30 14:37:05 -050084
Dave Jonese7027812012-01-04 11:33:12 -050085 /* Now for the blacklist.. */
86
87 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
88 {
89 .callback = set_nouse_crs,
90 .ident = "Dell Studio 1557",
91 .matches = {
92 DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."),
93 DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"),
94 DMI_MATCH(DMI_BIOS_VERSION, "A09"),
95 },
96 },
Dave Jones8b6a5af2012-01-04 11:30:52 -050097 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
98 {
99 .callback = set_nouse_crs,
100 .ident = "Thinkpad SL510",
101 .matches = {
102 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
103 DMI_MATCH(DMI_BOARD_NAME, "2847DFG"),
104 DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"),
105 },
106 },
Bjorn Helgaas1f09b092012-10-29 17:26:54 -0600107
108 /* https://bugzilla.kernel.org/show_bug.cgi?id=15362 */
109 {
110 .callback = set_ignore_seg,
111 .ident = "HP xw9300",
112 .matches = {
113 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
114 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw9300 Workstation"),
115 },
116 },
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -0700117 {}
118};
119
120void __init pci_acpi_crs_quirks(void)
121{
122 int year;
123
124 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
125 pci_use_crs = false;
126
Bjorn Helgaas1f09b092012-10-29 17:26:54 -0600127 dmi_check_system(pci_crs_quirks);
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -0700128
129 /*
130 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
131 * takes precedence over anything we figured out above.
132 */
133 if (pci_probe & PCI_ROOT_NO_CRS)
134 pci_use_crs = false;
135 else if (pci_probe & PCI_USE__CRS)
136 pci_use_crs = true;
137
138 printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
139 "if necessary, use \"pci=%s\" and report a bug\n",
140 pci_use_crs ? "Using" : "Ignoring",
141 pci_use_crs ? "nocrs" : "use_crs");
142}
143
Jiang Liuc0fa4072012-06-22 14:55:17 +0800144#ifdef CONFIG_PCI_MMCONFIG
Greg Kroah-Hartmana18e3692012-12-21 14:02:53 -0800145static int check_segment(u16 seg, struct device *dev, char *estr)
Jiang Liuc0fa4072012-06-22 14:55:17 +0800146{
147 if (seg) {
148 dev_err(dev,
149 "%s can't access PCI configuration "
150 "space under this host bridge.\n",
151 estr);
152 return -EIO;
153 }
154
155 /*
156 * Failure in adding MMCFG information is not fatal,
157 * just can't access extended configuration space of
158 * devices under this host bridge.
159 */
160 dev_warn(dev,
161 "%s can't access extended PCI configuration "
162 "space under this bridge.\n",
163 estr);
164
165 return 0;
166}
167
Greg Kroah-Hartmana18e3692012-12-21 14:02:53 -0800168static int setup_mcfg_map(struct pci_root_info *info, u16 seg, u8 start,
169 u8 end, phys_addr_t addr)
Jiang Liuc0fa4072012-06-22 14:55:17 +0800170{
171 int result;
172 struct device *dev = &info->bridge->dev;
173
174 info->start_bus = start;
175 info->end_bus = end;
176 info->mcfg_added = false;
177
178 /* return success if MMCFG is not in use */
179 if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg)
180 return 0;
181
182 if (!(pci_probe & PCI_PROBE_MMCONF))
183 return check_segment(seg, dev, "MMCONFIG is disabled,");
184
185 result = pci_mmconfig_insert(dev, seg, start, end, addr);
186 if (result == 0) {
187 /* enable MMCFG if it hasn't been enabled yet */
188 if (raw_pci_ext_ops == NULL)
189 raw_pci_ext_ops = &pci_mmcfg;
190 info->mcfg_added = true;
191 } else if (result != -EEXIST)
192 return check_segment(seg, dev,
193 "fail to add MMCONFIG information,");
194
195 return 0;
196}
197
198static void teardown_mcfg_map(struct pci_root_info *info)
199{
200 if (info->mcfg_added) {
201 pci_mmconfig_delete(info->segment, info->start_bus,
202 info->end_bus);
203 info->mcfg_added = false;
204 }
205}
206#else
Greg Kroah-Hartmana18e3692012-12-21 14:02:53 -0800207static int setup_mcfg_map(struct pci_root_info *info,
Jiang Liuc0fa4072012-06-22 14:55:17 +0800208 u16 seg, u8 start, u8 end,
209 phys_addr_t addr)
210{
211 return 0;
212}
213static void teardown_mcfg_map(struct pci_root_info *info)
214{
215}
216#endif
217
Jiang Liu593669c2015-02-05 13:44:46 +0800218static void validate_resources(struct device *dev, struct list_head *crs_res,
219 unsigned long type)
Gary Hade62f420f2007-10-03 15:56:51 -0700220{
Jiang Liu593669c2015-02-05 13:44:46 +0800221 LIST_HEAD(list);
222 struct resource *res1, *res2, *root = NULL;
223 struct resource_entry *tmp, *entry, *entry2;
Gary Hade62f420f2007-10-03 15:56:51 -0700224
Jiang Liu593669c2015-02-05 13:44:46 +0800225 BUG_ON((type & (IORESOURCE_MEM | IORESOURCE_IO)) == 0);
226 root = (type & IORESOURCE_MEM) ? &iomem_resource : &ioport_resource;
Gary Hade62f420f2007-10-03 15:56:51 -0700227
Jiang Liu593669c2015-02-05 13:44:46 +0800228 list_splice_init(crs_res, &list);
229 resource_list_for_each_entry_safe(entry, tmp, &list) {
230 bool free = false;
231 resource_size_t end;
Gary Hade62f420f2007-10-03 15:56:51 -0700232
Jiang Liu593669c2015-02-05 13:44:46 +0800233 res1 = entry->res;
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600234 if (!(res1->flags & type))
Jiang Liu593669c2015-02-05 13:44:46 +0800235 goto next;
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600236
Jiang Liu593669c2015-02-05 13:44:46 +0800237 /* Exclude non-addressable range or non-addressable portion */
238 end = min(res1->end, root->end);
239 if (end <= res1->start) {
240 dev_info(dev, "host bridge window %pR (ignored, not CPU addressable)\n",
241 res1);
242 free = true;
243 goto next;
244 } else if (res1->end != end) {
245 dev_info(dev, "host bridge window %pR ([%#llx-%#llx] ignored, not CPU addressable)\n",
246 res1, (unsigned long long)end + 1,
247 (unsigned long long)res1->end);
248 res1->end = end;
249 }
250
251 resource_list_for_each_entry(entry2, crs_res) {
252 res2 = entry2->res;
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600253 if (!(res2->flags & type))
254 continue;
255
256 /*
257 * I don't like throwing away windows because then
258 * our resources no longer match the ACPI _CRS, but
259 * the kernel resource tree doesn't allow overlaps.
260 */
Wei Yang74d24b22012-04-26 15:32:55 +0800261 if (resource_overlaps(res1, res2)) {
Alexey Neyman3ad674d2013-10-09 16:16:38 -0600262 res2->start = min(res1->start, res2->start);
263 res2->end = max(res1->end, res2->end);
Jiang Liu593669c2015-02-05 13:44:46 +0800264 dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n",
Alexey Neyman3ad674d2013-10-09 16:16:38 -0600265 res2, res1);
Jiang Liu593669c2015-02-05 13:44:46 +0800266 free = true;
267 goto next;
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600268 }
269 }
Jiang Liu593669c2015-02-05 13:44:46 +0800270
271next:
272 resource_list_del(entry);
273 if (free)
274 resource_list_free_entry(entry);
275 else
276 resource_list_add_tail(entry, crs_res);
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600277 }
278}
279
Yinghai Lu9a03d282012-04-02 18:31:53 -0700280static void add_resources(struct pci_root_info *info,
Jiang Liu593669c2015-02-05 13:44:46 +0800281 struct list_head *resources,
282 struct list_head *crs_res)
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600283{
Jiang Liu593669c2015-02-05 13:44:46 +0800284 struct resource_entry *entry, *tmp;
285 struct resource *res, *conflict, *root = NULL;
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600286
Jiang Liu593669c2015-02-05 13:44:46 +0800287 validate_resources(&info->bridge->dev, crs_res, IORESOURCE_MEM);
288 validate_resources(&info->bridge->dev, crs_res, IORESOURCE_IO);
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600289
Jiang Liu593669c2015-02-05 13:44:46 +0800290 resource_list_for_each_entry_safe(entry, tmp, crs_res) {
291 res = entry->res;
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600292 if (res->flags & IORESOURCE_MEM)
293 root = &iomem_resource;
294 else if (res->flags & IORESOURCE_IO)
295 root = &ioport_resource;
296 else
Jiang Liu593669c2015-02-05 13:44:46 +0800297 BUG_ON(res);
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600298
299 conflict = insert_resource_conflict(root, res);
Jiang Liu593669c2015-02-05 13:44:46 +0800300 if (conflict) {
Bjorn Helgaas43d786e2011-07-02 10:47:12 -0600301 dev_info(&info->bridge->dev,
302 "ignoring host bridge window %pR (conflicts with %s %pR)\n",
303 res, conflict->name, conflict);
Jiang Liu593669c2015-02-05 13:44:46 +0800304 resource_list_destroy_entry(entry);
305 }
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700306 }
307
Jiang Liu593669c2015-02-05 13:44:46 +0800308 list_splice_tail(crs_res, resources);
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700309}
Jiang Liuc0fa4072012-06-22 14:55:17 +0800310
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700311static void release_pci_root_info(struct pci_host_bridge *bridge)
312{
Jiang Liu593669c2015-02-05 13:44:46 +0800313 struct resource *res;
314 struct resource_entry *entry;
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700315 struct pci_root_info *info = bridge->release_data;
316
Jiang Liu593669c2015-02-05 13:44:46 +0800317 resource_list_for_each_entry(entry, &bridge->windows) {
318 res = entry->res;
319 if (res->parent &&
320 (res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
321 release_resource(res);
322 }
323
324 teardown_mcfg_map(info);
325 kfree(info);
Yinghai Lubaa495d2012-04-02 18:31:53 -0700326}
327
Jiang Liu2c62e842015-04-30 12:41:28 +0800328/*
329 * An IO port or MMIO resource assigned to a PCI host bridge may be
330 * consumed by the host bridge itself or available to its child
331 * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
332 * to tell whether the resource is consumed by the host bridge itself,
333 * but firmware hasn't used that bit consistently, so we can't rely on it.
334 *
335 * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
336 * to be available to child bus/devices except one special case:
337 * IO port [0xCF8-0xCFF] is consumed by the host bridge itself
338 * to access PCI configuration space.
339 *
340 * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
341 */
342static bool resource_is_pcicfg_ioport(struct resource *res)
343{
344 return (res->flags & IORESOURCE_IO) &&
345 res->start == 0xCF8 && res->end == 0xCFF;
346}
347
Bjorn Helgaasda5d7272014-01-24 10:44:42 -0700348static void probe_pci_root_info(struct pci_root_info *info,
349 struct acpi_device *device,
Jiang Liu593669c2015-02-05 13:44:46 +0800350 int busnum, int domain,
351 struct list_head *list)
Gary Hade62f420f2007-10-03 15:56:51 -0700352{
Jiang Liu593669c2015-02-05 13:44:46 +0800353 int ret;
Jiang Liu63f17892015-03-04 16:47:11 +0800354 struct resource_entry *entry, *tmp;
Gary Hade62f420f2007-10-03 15:56:51 -0700355
Yinghai Lu5c1d81d2012-05-17 18:51:12 -0700356 sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
Yinghai Lubaa495d2012-04-02 18:31:53 -0700357 info->bridge = device;
Jiang Liu593669c2015-02-05 13:44:46 +0800358 ret = acpi_dev_get_resources(device, list,
359 acpi_dev_filter_resource_type_cb,
360 (void *)(IORESOURCE_IO | IORESOURCE_MEM));
361 if (ret < 0)
362 dev_warn(&device->dev,
363 "failed to parse _CRS method, error code %d\n", ret);
364 else if (ret == 0)
365 dev_dbg(&device->dev,
366 "no IO and memory resources present in _CRS\n");
367 else
Jiang Liu63f17892015-03-04 16:47:11 +0800368 resource_list_for_each_entry_safe(entry, tmp, list) {
Jiang Liu2c62e842015-04-30 12:41:28 +0800369 if ((entry->res->flags & IORESOURCE_DISABLED) ||
370 resource_is_pcicfg_ioport(entry->res))
Jiang Liu63f17892015-03-04 16:47:11 +0800371 resource_list_destroy_entry(entry);
372 else
373 entry->res->name = info->name;
374 }
Gary Hade62f420f2007-10-03 15:56:51 -0700375}
376
Greg Kroah-Hartmana18e3692012-12-21 14:02:53 -0800377struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Bjorn Helgaas57283772010-03-11 12:20:11 -0700379 struct acpi_device *device = root->device;
Bjorn Helgaas8928d5a2014-01-24 10:41:11 -0700380 struct pci_root_info *info;
Bjorn Helgaas57283772010-03-11 12:20:11 -0700381 int domain = root->segment;
382 int busnum = root->secondary.start;
Jiang Liu593669c2015-02-05 13:44:46 +0800383 struct resource_entry *res_entry;
384 LIST_HEAD(crs_res);
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600385 LIST_HEAD(resources);
Bjorn Helgaas8928d5a2014-01-24 10:41:11 -0700386 struct pci_bus *bus;
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300387 struct pci_sysdata *sd;
Yinghai Lu871d5f82008-02-19 03:20:09 -0800388 int node;
Andi Kleen69e1a332005-09-12 18:49:24 +0200389
Bjorn Helgaas1f09b092012-10-29 17:26:54 -0600390 if (pci_ignore_seg)
391 domain = 0;
392
Jeff Garzika79e4192007-10-11 16:58:30 -0400393 if (domain && !pci_domains_supported) {
Bjorn Helgaas2a6bed82009-11-04 10:32:47 -0700394 printk(KERN_WARNING "pci_bus %04x:%02x: "
395 "ignored (multiple domains not supported)\n",
396 domain, busnum);
Jeff Garzika79e4192007-10-11 16:58:30 -0400397 return NULL;
398 }
399
Bjorn Helgaasab6ffce2014-01-24 14:40:46 -0700400 node = acpi_get_node(device->handle);
Myron Stowe33673102014-05-08 11:44:20 -0500401 if (node == NUMA_NO_NODE) {
Bjorn Helgaas6616dbd2014-01-24 11:54:51 -0700402 node = x86_pci_root_bus_node(busnum);
Myron Stowe33673102014-05-08 11:44:20 -0500403 if (node != 0 && node != NUMA_NO_NODE)
404 dev_info(&device->dev, FW_BUG "no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n",
405 node);
406 }
Yinghai Lub755de82008-02-20 12:41:52 -0800407
Bjorn Helgaas8a3d01c2014-01-24 14:51:49 -0700408 if (node != NUMA_NO_NODE && !node_online(node))
409 node = NUMA_NO_NODE;
Yinghai Lu871d5f82008-02-19 03:20:09 -0800410
Jiang Liu965cd0e2014-06-09 16:19:34 +0800411 info = kzalloc_node(sizeof(*info), GFP_KERNEL, node);
Yinghai Lu35cb05e2012-04-02 18:31:53 -0700412 if (!info) {
Bjorn Helgaas2a6bed82009-11-04 10:32:47 -0700413 printk(KERN_WARNING "pci_bus %04x:%02x: "
414 "ignored (out of memory)\n", domain, busnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return NULL;
416 }
417
Yinghai Lu35cb05e2012-04-02 18:31:53 -0700418 sd = &info->sd;
Jeff Garzika79e4192007-10-11 16:58:30 -0400419 sd->domain = domain;
Yinghai Lu871d5f82008-02-19 03:20:09 -0800420 sd->node = node;
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100421 sd->companion = device;
Bjorn Helgaasaffbda82014-01-24 10:38:40 -0700422
yakui.zhao@intel.comb87e81e2008-04-15 14:34:49 -0700423 bus = pci_find_bus(domain, busnum);
424 if (bus) {
425 /*
Bjorn Helgaasaffbda82014-01-24 10:38:40 -0700426 * If the desired bus has been scanned already, replace
427 * its bus->sysdata.
yakui.zhao@intel.comb87e81e2008-04-15 14:34:49 -0700428 */
429 memcpy(bus->sysdata, sd, sizeof(*sd));
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700430 kfree(info);
Yinghai Lu626fdfe2009-06-24 20:00:12 -0700431 } else {
Yinghai Lu5c1d81d2012-05-17 18:51:12 -0700432 /* insert busn res at first */
433 pci_add_resource(&resources, &root->secondary);
Jiang Liu593669c2015-02-05 13:44:46 +0800434
Bjorn Helgaas316d86f2012-01-17 17:41:21 -0700435 /*
436 * _CRS with no apertures is normal, so only fall back to
437 * defaults or native bridge info if we're ignoring _CRS.
438 */
Jiang Liu593669c2015-02-05 13:44:46 +0800439 probe_pci_root_info(info, device, busnum, domain, &crs_res);
440 if (pci_use_crs) {
441 add_resources(info, &resources, &crs_res);
442 } else {
443 resource_list_for_each_entry(res_entry, &crs_res)
444 dev_printk(KERN_DEBUG, &device->dev,
445 "host bridge window %pR (ignored)\n",
446 res_entry->res);
447 resource_list_free(&crs_res);
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600448 x86_pci_root_bus_resources(busnum, &resources);
Yinghai Lu9a03d282012-04-02 18:31:53 -0700449 }
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700450
Jiang Liuc0fa4072012-06-22 14:55:17 +0800451 if (!setup_mcfg_map(info, domain, (u8)root->secondary.start,
452 (u8)root->secondary.end, root->mcfg_addr))
453 bus = pci_create_root_bus(NULL, busnum, &pci_root_ops,
454 sd, &resources);
455
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700456 if (bus) {
Yinghai Lu5c1d81d2012-05-17 18:51:12 -0700457 pci_scan_child_bus(bus);
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700458 pci_set_host_bridge_release(
459 to_pci_host_bridge(bus->bridge),
460 release_pci_root_info, info);
461 } else {
Jiang Liu593669c2015-02-05 13:44:46 +0800462 resource_list_free(&resources);
463 teardown_mcfg_map(info);
464 kfree(info);
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700465 }
Yinghai Lu626fdfe2009-06-24 20:00:12 -0700466 }
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300467
Jon Masonb03e7492011-07-20 15:20:54 -0500468 /* After the PCI-E bus has been walked and all devices discovered,
469 * configure any settings of the fabric that might be necessary.
470 */
471 if (bus) {
472 struct pci_bus *child;
Bjorn Helgaasa58674f2013-08-22 11:24:44 +0800473 list_for_each_entry(child, &bus->children, node)
474 pcie_bus_configure_settings(child);
Jon Masonb03e7492011-07-20 15:20:54 -0500475 }
476
Bjorn Helgaasab6ffce2014-01-24 14:40:46 -0700477 if (bus && node != NUMA_NO_NODE)
Bjorn Helgaas2b8c2ef2008-12-18 16:34:51 -0700478 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
Gary Hade62f420f2007-10-03 15:56:51 -0700479
Andi Kleen69e1a332005-09-12 18:49:24 +0200480 return bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}
482
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +0100483int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
484{
485 struct pci_sysdata *sd = bridge->bus->sysdata;
486
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100487 ACPI_COMPANION_SET(&bridge->dev, sd->companion);
Rafael J. Wysocki6c0cc952013-01-09 22:33:37 +0100488 return 0;
489}
490
Robert Richter8dd779b2008-07-02 22:50:29 +0200491int __init pci_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
493 struct pci_dev *dev = NULL;
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (acpi_noirq)
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +0200496 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
499 acpi_irq_penalty_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 pcibios_enable_irq = acpi_pci_irq_enable;
David Shaohua Li87bec662005-07-27 23:02:00 -0400501 pcibios_disable_irq = acpi_pci_irq_disable;
Thomas Gleixnerab3b3792009-08-29 17:47:33 +0200502 x86_init.pci.init_irq = x86_init_noop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 if (pci_routeirq) {
505 /*
506 * PCI IRQ routing is set up by pci_enable_device(), but we
507 * also do it here in case there are still broken drivers that
508 * don't use pci_enable_device().
509 */
510 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
Hanna Linderfb37fb92005-11-06 23:39:36 -0800511 for_each_pci_dev(dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 acpi_pci_irq_enable(dev);
Bjorn Helgaas657472e92008-02-18 09:44:13 -0700513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 return 0;
516}