blob: 9cecffc72e633ac8ef632f5a3a08ad112cd0b975 [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];
Gary Hade62f420f2007-10-03 15:56:51 -070013 unsigned int res_num;
14 struct resource *res;
Mike Yoknisb4873932012-11-07 15:52:20 -070015 resource_size_t *res_offset;
Yinghai Lu35cb05e2012-04-02 18:31:53 -070016 struct pci_sysdata sd;
Jiang Liuc0fa4072012-06-22 14:55:17 +080017#ifdef CONFIG_PCI_MMCONFIG
18 bool mcfg_added;
19 u16 segment;
20 u8 start_bus;
21 u8 end_bus;
22#endif
Gary Hade62f420f2007-10-03 15:56:51 -070023};
24
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -070025static bool pci_use_crs = true;
26
27static int __init set_use_crs(const struct dmi_system_id *id)
28{
29 pci_use_crs = true;
30 return 0;
31}
32
Dave Jones28c3c052011-12-30 14:37:05 -050033static int __init set_nouse_crs(const struct dmi_system_id *id)
34{
35 pci_use_crs = false;
36 return 0;
37}
38
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -070039static const struct dmi_system_id pci_use_crs_table[] __initconst = {
40 /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
41 {
42 .callback = set_use_crs,
43 .ident = "IBM System x3800",
44 .matches = {
45 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
46 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
47 },
48 },
Bjorn Helgaas24917622010-07-23 12:53:27 -060049 /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
50 /* 2006 AMD HT/VIA system with two host bridges */
51 {
52 .callback = set_use_crs,
53 .ident = "ASRock ALiveSATA2-GLAN",
54 .matches = {
55 DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"),
56 },
57 },
Paul Menzel29cf7a302011-08-31 17:07:10 +020058 /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */
59 /* 2006 AMD HT/VIA system with two host bridges */
60 {
61 .callback = set_use_crs,
62 .ident = "ASUS M2V-MX SE",
63 .matches = {
64 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
65 DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"),
66 DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
67 },
68 },
Jonathan Nieder841137172012-02-28 11:51:10 -070069 /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */
70 {
71 .callback = set_use_crs,
72 .ident = "MSI MS-7253",
73 .matches = {
74 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
75 DMI_MATCH(DMI_BOARD_NAME, "MS-7253"),
76 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
Jonathan Nieder841137172012-02-28 11:51:10 -070077 },
78 },
Dave Jones28c3c052011-12-30 14:37:05 -050079
Dave Jonese7027812012-01-04 11:33:12 -050080 /* Now for the blacklist.. */
81
82 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
83 {
84 .callback = set_nouse_crs,
85 .ident = "Dell Studio 1557",
86 .matches = {
87 DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."),
88 DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"),
89 DMI_MATCH(DMI_BIOS_VERSION, "A09"),
90 },
91 },
Dave Jones8b6a5af2012-01-04 11:30:52 -050092 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
93 {
94 .callback = set_nouse_crs,
95 .ident = "Thinkpad SL510",
96 .matches = {
97 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
98 DMI_MATCH(DMI_BOARD_NAME, "2847DFG"),
99 DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"),
100 },
101 },
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -0700102 {}
103};
104
105void __init pci_acpi_crs_quirks(void)
106{
107 int year;
108
109 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
110 pci_use_crs = false;
111
112 dmi_check_system(pci_use_crs_table);
113
114 /*
115 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
116 * takes precedence over anything we figured out above.
117 */
118 if (pci_probe & PCI_ROOT_NO_CRS)
119 pci_use_crs = false;
120 else if (pci_probe & PCI_USE__CRS)
121 pci_use_crs = true;
122
123 printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
124 "if necessary, use \"pci=%s\" and report a bug\n",
125 pci_use_crs ? "Using" : "Ignoring",
126 pci_use_crs ? "nocrs" : "use_crs");
127}
128
Jiang Liuc0fa4072012-06-22 14:55:17 +0800129#ifdef CONFIG_PCI_MMCONFIG
130static int __devinit check_segment(u16 seg, struct device *dev, char *estr)
131{
132 if (seg) {
133 dev_err(dev,
134 "%s can't access PCI configuration "
135 "space under this host bridge.\n",
136 estr);
137 return -EIO;
138 }
139
140 /*
141 * Failure in adding MMCFG information is not fatal,
142 * just can't access extended configuration space of
143 * devices under this host bridge.
144 */
145 dev_warn(dev,
146 "%s can't access extended PCI configuration "
147 "space under this bridge.\n",
148 estr);
149
150 return 0;
151}
152
153static int __devinit setup_mcfg_map(struct pci_root_info *info,
154 u16 seg, u8 start, u8 end,
155 phys_addr_t addr)
156{
157 int result;
158 struct device *dev = &info->bridge->dev;
159
160 info->start_bus = start;
161 info->end_bus = end;
162 info->mcfg_added = false;
163
164 /* return success if MMCFG is not in use */
165 if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg)
166 return 0;
167
168 if (!(pci_probe & PCI_PROBE_MMCONF))
169 return check_segment(seg, dev, "MMCONFIG is disabled,");
170
171 result = pci_mmconfig_insert(dev, seg, start, end, addr);
172 if (result == 0) {
173 /* enable MMCFG if it hasn't been enabled yet */
174 if (raw_pci_ext_ops == NULL)
175 raw_pci_ext_ops = &pci_mmcfg;
176 info->mcfg_added = true;
177 } else if (result != -EEXIST)
178 return check_segment(seg, dev,
179 "fail to add MMCONFIG information,");
180
181 return 0;
182}
183
184static void teardown_mcfg_map(struct pci_root_info *info)
185{
186 if (info->mcfg_added) {
187 pci_mmconfig_delete(info->segment, info->start_bus,
188 info->end_bus);
189 info->mcfg_added = false;
190 }
191}
192#else
193static int __devinit setup_mcfg_map(struct pci_root_info *info,
194 u16 seg, u8 start, u8 end,
195 phys_addr_t addr)
196{
197 return 0;
198}
199static void teardown_mcfg_map(struct pci_root_info *info)
200{
201}
202#endif
203
Gary Hade62f420f2007-10-03 15:56:51 -0700204static acpi_status
205resource_to_addr(struct acpi_resource *resource,
206 struct acpi_resource_address64 *addr)
207{
208 acpi_status status;
Bjorn Helgaas66528fd2010-04-20 13:52:41 -0600209 struct acpi_resource_memory24 *memory24;
210 struct acpi_resource_memory32 *memory32;
211 struct acpi_resource_fixed_memory32 *fixed_memory32;
Gary Hade62f420f2007-10-03 15:56:51 -0700212
Bjorn Helgaas66528fd2010-04-20 13:52:41 -0600213 memset(addr, 0, sizeof(*addr));
214 switch (resource->type) {
215 case ACPI_RESOURCE_TYPE_MEMORY24:
216 memory24 = &resource->data.memory24;
217 addr->resource_type = ACPI_MEMORY_RANGE;
218 addr->minimum = memory24->minimum;
219 addr->address_length = memory24->address_length;
220 addr->maximum = addr->minimum + addr->address_length - 1;
Gary Hade62f420f2007-10-03 15:56:51 -0700221 return AE_OK;
Bjorn Helgaas66528fd2010-04-20 13:52:41 -0600222 case ACPI_RESOURCE_TYPE_MEMORY32:
223 memory32 = &resource->data.memory32;
224 addr->resource_type = ACPI_MEMORY_RANGE;
225 addr->minimum = memory32->minimum;
226 addr->address_length = memory32->address_length;
227 addr->maximum = addr->minimum + addr->address_length - 1;
228 return AE_OK;
229 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
230 fixed_memory32 = &resource->data.fixed_memory32;
231 addr->resource_type = ACPI_MEMORY_RANGE;
232 addr->minimum = fixed_memory32->address;
233 addr->address_length = fixed_memory32->address_length;
234 addr->maximum = addr->minimum + addr->address_length - 1;
235 return AE_OK;
236 case ACPI_RESOURCE_TYPE_ADDRESS16:
237 case ACPI_RESOURCE_TYPE_ADDRESS32:
238 case ACPI_RESOURCE_TYPE_ADDRESS64:
239 status = acpi_resource_to_address64(resource, addr);
240 if (ACPI_SUCCESS(status) &&
241 (addr->resource_type == ACPI_MEMORY_RANGE ||
242 addr->resource_type == ACPI_IO_RANGE) &&
243 addr->address_length > 0) {
244 return AE_OK;
245 }
246 break;
Gary Hade62f420f2007-10-03 15:56:51 -0700247 }
248 return AE_ERROR;
249}
250
251static acpi_status
252count_resource(struct acpi_resource *acpi_res, void *data)
253{
254 struct pci_root_info *info = data;
255 struct acpi_resource_address64 addr;
256 acpi_status status;
257
258 status = resource_to_addr(acpi_res, &addr);
259 if (ACPI_SUCCESS(status))
260 info->res_num++;
261 return AE_OK;
262}
263
264static acpi_status
265setup_resource(struct acpi_resource *acpi_res, void *data)
266{
267 struct pci_root_info *info = data;
268 struct resource *res;
269 struct acpi_resource_address64 addr;
270 acpi_status status;
271 unsigned long flags;
Gary Hadeae5cd862011-11-14 15:42:16 -0800272 u64 start, orig_end, end;
Yinghai Lu2cdb3f12009-06-24 19:01:19 -0700273
Gary Hade62f420f2007-10-03 15:56:51 -0700274 status = resource_to_addr(acpi_res, &addr);
275 if (!ACPI_SUCCESS(status))
276 return AE_OK;
277
278 if (addr.resource_type == ACPI_MEMORY_RANGE) {
Gary Hade62f420f2007-10-03 15:56:51 -0700279 flags = IORESOURCE_MEM;
280 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
281 flags |= IORESOURCE_PREFETCH;
282 } else if (addr.resource_type == ACPI_IO_RANGE) {
Gary Hade62f420f2007-10-03 15:56:51 -0700283 flags = IORESOURCE_IO;
284 } else
285 return AE_OK;
286
Yinghai Lu2cdb3f12009-06-24 19:01:19 -0700287 start = addr.minimum + addr.translation_offset;
Gary Hadeae5cd862011-11-14 15:42:16 -0800288 orig_end = end = addr.maximum + addr.translation_offset;
289
290 /* Exclude non-addressable range or non-addressable portion of range */
291 end = min(end, (u64)iomem_resource.end);
292 if (end <= start) {
293 dev_info(&info->bridge->dev,
294 "host bridge window [%#llx-%#llx] "
295 "(ignored, not CPU addressable)\n", start, orig_end);
296 return AE_OK;
297 } else if (orig_end != end) {
298 dev_info(&info->bridge->dev,
299 "host bridge window [%#llx-%#llx] "
300 "([%#llx-%#llx] ignored, not CPU addressable)\n",
301 start, orig_end, end + 1, orig_end);
302 }
Gary Hadef9cde5f2009-05-27 12:41:44 -0700303
Yinghai Lu2cdb3f12009-06-24 19:01:19 -0700304 res = &info->res[info->res_num];
305 res->name = info->name;
306 res->flags = flags;
307 res->start = start;
308 res->end = end;
Mike Yoknisb4873932012-11-07 15:52:20 -0700309 info->res_offset[info->res_num] = addr.translation_offset;
Yinghai Lu2cdb3f12009-06-24 19:01:19 -0700310
Bjorn Helgaas7bc5e3f2010-02-23 10:24:41 -0700311 if (!pci_use_crs) {
Bjorn Helgaasf1db6fd2009-11-04 10:39:13 -0700312 dev_printk(KERN_DEBUG, &info->bridge->dev,
313 "host bridge window %pR (ignored)\n", res);
314 return AE_OK;
315 }
316
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600317 info->res_num++;
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600318
Gary Hade62f420f2007-10-03 15:56:51 -0700319 return AE_OK;
320}
321
Márton Németh6e33a852011-05-14 19:27:33 +0200322static void coalesce_windows(struct pci_root_info *info, unsigned long type)
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600323{
324 int i, j;
325 struct resource *res1, *res2;
326
327 for (i = 0; i < info->res_num; i++) {
328 res1 = &info->res[i];
329 if (!(res1->flags & type))
330 continue;
331
332 for (j = i + 1; j < info->res_num; j++) {
333 res2 = &info->res[j];
334 if (!(res2->flags & type))
335 continue;
336
337 /*
338 * I don't like throwing away windows because then
339 * our resources no longer match the ACPI _CRS, but
340 * the kernel resource tree doesn't allow overlaps.
341 */
Wei Yang74d24b22012-04-26 15:32:55 +0800342 if (resource_overlaps(res1, res2)) {
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600343 res1->start = min(res1->start, res2->start);
344 res1->end = max(res1->end, res2->end);
345 dev_info(&info->bridge->dev,
346 "host bridge window expanded to %pR; %pR ignored\n",
347 res1, res2);
348 res2->flags = 0;
349 }
350 }
351 }
352}
353
Yinghai Lu9a03d282012-04-02 18:31:53 -0700354static void add_resources(struct pci_root_info *info,
355 struct list_head *resources)
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600356{
357 int i;
358 struct resource *res, *root, *conflict;
359
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600360 coalesce_windows(info, IORESOURCE_MEM);
361 coalesce_windows(info, IORESOURCE_IO);
362
363 for (i = 0; i < info->res_num; i++) {
364 res = &info->res[i];
365
366 if (res->flags & IORESOURCE_MEM)
367 root = &iomem_resource;
368 else if (res->flags & IORESOURCE_IO)
369 root = &ioport_resource;
370 else
371 continue;
372
373 conflict = insert_resource_conflict(root, res);
374 if (conflict)
Bjorn Helgaas43d786e2011-07-02 10:47:12 -0600375 dev_info(&info->bridge->dev,
376 "ignoring host bridge window %pR (conflicts with %s %pR)\n",
377 res, conflict->name, conflict);
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600378 else
Mike Yoknisb4873932012-11-07 15:52:20 -0700379 pci_add_resource_offset(resources, res,
380 info->res_offset[i]);
Bjorn Helgaas4723d0f2010-09-22 11:09:19 -0600381 }
382}
383
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700384static void free_pci_root_info_res(struct pci_root_info *info)
Yinghai Lubaa495d2012-04-02 18:31:53 -0700385{
Yinghai Lubaa495d2012-04-02 18:31:53 -0700386 kfree(info->res);
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700387 info->res = NULL;
Mike Yoknisb4873932012-11-07 15:52:20 -0700388 kfree(info->res_offset);
389 info->res_offset = NULL;
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700390 info->res_num = 0;
391}
392
393static void __release_pci_root_info(struct pci_root_info *info)
394{
395 int i;
396 struct resource *res;
397
398 for (i = 0; i < info->res_num; i++) {
399 res = &info->res[i];
400
401 if (!res->parent)
402 continue;
403
404 if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
405 continue;
406
407 release_resource(res);
408 }
409
410 free_pci_root_info_res(info);
411
Jiang Liuc0fa4072012-06-22 14:55:17 +0800412 teardown_mcfg_map(info);
413
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700414 kfree(info);
415}
Jiang Liuc0fa4072012-06-22 14:55:17 +0800416
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700417static void release_pci_root_info(struct pci_host_bridge *bridge)
418{
419 struct pci_root_info *info = bridge->release_data;
420
421 __release_pci_root_info(info);
Yinghai Lubaa495d2012-04-02 18:31:53 -0700422}
423
Gary Hade62f420f2007-10-03 15:56:51 -0700424static void
Yinghai Lu9a03d282012-04-02 18:31:53 -0700425probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device,
426 int busnum, int domain)
Gary Hade62f420f2007-10-03 15:56:51 -0700427{
Gary Hade62f420f2007-10-03 15:56:51 -0700428 size_t size;
429
Yinghai Lu5c1d81d2012-05-17 18:51:12 -0700430 sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
Yinghai Lubaa495d2012-04-02 18:31:53 -0700431 info->bridge = device;
Yinghai Lu5c1d81d2012-05-17 18:51:12 -0700432
Yinghai Lubaa495d2012-04-02 18:31:53 -0700433 info->res_num = 0;
Gary Hade62f420f2007-10-03 15:56:51 -0700434 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
Yinghai Lubaa495d2012-04-02 18:31:53 -0700435 info);
436 if (!info->res_num)
Gary Hade62f420f2007-10-03 15:56:51 -0700437 return;
438
Yinghai Lubaa495d2012-04-02 18:31:53 -0700439 size = sizeof(*info->res) * info->res_num;
Yinghai Lu4cd8daf2012-09-19 10:49:00 -0700440 info->res = kzalloc(size, GFP_KERNEL);
Mike Yoknisb4873932012-11-07 15:52:20 -0700441 if (!info->res) {
442 info->res_num = 0;
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600443 return;
Mike Yoknisb4873932012-11-07 15:52:20 -0700444 }
445
446 size = sizeof(*info->res_offset) * info->res_num;
447 info->res_num = 0;
448 info->res_offset = kzalloc(size, GFP_KERNEL);
449 if (!info->res_offset) {
450 kfree(info->res);
451 info->res = NULL;
452 return;
453 }
Gary Hade62f420f2007-10-03 15:56:51 -0700454
Gary Hade62f420f2007-10-03 15:56:51 -0700455 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
Yinghai Lubaa495d2012-04-02 18:31:53 -0700456 info);
Gary Hade62f420f2007-10-03 15:56:51 -0700457}
458
Bjorn Helgaas57283772010-03-11 12:20:11 -0700459struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
Bjorn Helgaas57283772010-03-11 12:20:11 -0700461 struct acpi_device *device = root->device;
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700462 struct pci_root_info *info = NULL;
Bjorn Helgaas57283772010-03-11 12:20:11 -0700463 int domain = root->segment;
464 int busnum = root->secondary.start;
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600465 LIST_HEAD(resources);
Jiang Liuc0fa4072012-06-22 14:55:17 +0800466 struct pci_bus *bus = NULL;
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300467 struct pci_sysdata *sd;
Yinghai Lu871d5f82008-02-19 03:20:09 -0800468 int node;
469#ifdef CONFIG_ACPI_NUMA
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300470 int pxm;
Yinghai Lu871d5f82008-02-19 03:20:09 -0800471#endif
Andi Kleen69e1a332005-09-12 18:49:24 +0200472
Jeff Garzika79e4192007-10-11 16:58:30 -0400473 if (domain && !pci_domains_supported) {
Bjorn Helgaas2a6bed82009-11-04 10:32:47 -0700474 printk(KERN_WARNING "pci_bus %04x:%02x: "
475 "ignored (multiple domains not supported)\n",
476 domain, busnum);
Jeff Garzika79e4192007-10-11 16:58:30 -0400477 return NULL;
478 }
479
Yinghai Lu871d5f82008-02-19 03:20:09 -0800480 node = -1;
481#ifdef CONFIG_ACPI_NUMA
482 pxm = acpi_get_pxm(device->handle);
483 if (pxm >= 0)
484 node = pxm_to_node(pxm);
485 if (node != -1)
486 set_mp_bus_to_node(busnum, node);
487 else
Yinghai Lu871d5f82008-02-19 03:20:09 -0800488#endif
Yinghai Lu871d5f82008-02-19 03:20:09 -0800489 node = get_mp_bus_to_node(busnum);
Yinghai Lub755de82008-02-20 12:41:52 -0800490
491 if (node != -1 && !node_online(node))
492 node = -1;
Yinghai Lu871d5f82008-02-19 03:20:09 -0800493
Yinghai Lu35cb05e2012-04-02 18:31:53 -0700494 info = kzalloc(sizeof(*info), GFP_KERNEL);
495 if (!info) {
Bjorn Helgaas2a6bed82009-11-04 10:32:47 -0700496 printk(KERN_WARNING "pci_bus %04x:%02x: "
497 "ignored (out of memory)\n", domain, busnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 return NULL;
499 }
500
Yinghai Lu35cb05e2012-04-02 18:31:53 -0700501 sd = &info->sd;
Jeff Garzika79e4192007-10-11 16:58:30 -0400502 sd->domain = domain;
Yinghai Lu871d5f82008-02-19 03:20:09 -0800503 sd->node = node;
yakui.zhao@intel.comb87e81e2008-04-15 14:34:49 -0700504 /*
505 * Maybe the desired pci bus has been already scanned. In such case
506 * it is unnecessary to scan the pci bus with the given domain,busnum.
507 */
508 bus = pci_find_bus(domain, busnum);
509 if (bus) {
510 /*
511 * If the desired bus exits, the content of bus->sysdata will
512 * be replaced by sd.
513 */
514 memcpy(bus->sysdata, sd, sizeof(*sd));
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700515 kfree(info);
Yinghai Lu626fdfe2009-06-24 20:00:12 -0700516 } else {
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700517 probe_pci_root_info(info, device, busnum, domain);
Bjorn Helgaas316d86f2012-01-17 17:41:21 -0700518
Yinghai Lu5c1d81d2012-05-17 18:51:12 -0700519 /* insert busn res at first */
520 pci_add_resource(&resources, &root->secondary);
Bjorn Helgaas316d86f2012-01-17 17:41:21 -0700521 /*
522 * _CRS with no apertures is normal, so only fall back to
523 * defaults or native bridge info if we're ignoring _CRS.
524 */
Yinghai Lu9a03d282012-04-02 18:31:53 -0700525 if (pci_use_crs)
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700526 add_resources(info, &resources);
Yinghai Lu9a03d282012-04-02 18:31:53 -0700527 else {
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700528 free_pci_root_info_res(info);
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600529 x86_pci_root_bus_resources(busnum, &resources);
Yinghai Lu9a03d282012-04-02 18:31:53 -0700530 }
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700531
Jiang Liuc0fa4072012-06-22 14:55:17 +0800532 if (!setup_mcfg_map(info, domain, (u8)root->secondary.start,
533 (u8)root->secondary.end, root->mcfg_addr))
534 bus = pci_create_root_bus(NULL, busnum, &pci_root_ops,
535 sd, &resources);
536
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700537 if (bus) {
Yinghai Lu5c1d81d2012-05-17 18:51:12 -0700538 pci_scan_child_bus(bus);
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700539 pci_set_host_bridge_release(
540 to_pci_host_bridge(bus->bridge),
541 release_pci_root_info, info);
542 } else {
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600543 pci_free_resource_list(&resources);
Yinghai Lufd3b0c12012-04-02 18:31:53 -0700544 __release_pci_root_info(info);
545 }
Yinghai Lu626fdfe2009-06-24 20:00:12 -0700546 }
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300547
Jon Masonb03e7492011-07-20 15:20:54 -0500548 /* After the PCI-E bus has been walked and all devices discovered,
549 * configure any settings of the fabric that might be necessary.
550 */
551 if (bus) {
552 struct pci_bus *child;
Shyam Iyer5307f6d2011-09-08 16:41:17 -0500553 list_for_each_entry(child, &bus->children, node) {
554 struct pci_dev *self = child->self;
555 if (!self)
556 continue;
557
558 pcie_bus_configure_settings(child, self->pcie_mpss);
559 }
Jon Masonb03e7492011-07-20 15:20:54 -0500560 }
561
Yinghai Ludbb61522008-04-19 01:30:16 -0700562 if (bus && node != -1) {
Andi Kleen69e1a332005-09-12 18:49:24 +0200563#ifdef CONFIG_ACPI_NUMA
Yinghai Ludbb61522008-04-19 01:30:16 -0700564 if (pxm >= 0)
Bjorn Helgaas2b8c2ef2008-12-18 16:34:51 -0700565 dev_printk(KERN_DEBUG, &bus->dev,
566 "on NUMA node %d (pxm %d)\n", node, pxm);
Yinghai Ludbb61522008-04-19 01:30:16 -0700567#else
Bjorn Helgaas2b8c2ef2008-12-18 16:34:51 -0700568 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
Andi Kleen69e1a332005-09-12 18:49:24 +0200569#endif
Yinghai Ludbb61522008-04-19 01:30:16 -0700570 }
Gary Hade62f420f2007-10-03 15:56:51 -0700571
Andi Kleen69e1a332005-09-12 18:49:24 +0200572 return bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
Robert Richter8dd779b2008-07-02 22:50:29 +0200575int __init pci_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 struct pci_dev *dev = NULL;
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if (acpi_noirq)
Thomas Gleixnerb72d0db2009-08-29 16:24:51 +0200580 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
583 acpi_irq_penalty_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 pcibios_enable_irq = acpi_pci_irq_enable;
David Shaohua Li87bec662005-07-27 23:02:00 -0400585 pcibios_disable_irq = acpi_pci_irq_disable;
Thomas Gleixnerab3b3792009-08-29 17:47:33 +0200586 x86_init.pci.init_irq = x86_init_noop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 if (pci_routeirq) {
589 /*
590 * PCI IRQ routing is set up by pci_enable_device(), but we
591 * also do it here in case there are still broken drivers that
592 * don't use pci_enable_device().
593 */
594 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
Hanna Linderfb37fb92005-11-06 23:39:36 -0800595 for_each_pci_dev(dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 acpi_pci_irq_enable(dev);
Bjorn Helgaas657472e2008-02-18 09:44:13 -0700597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return 0;
600}