2 #include <linux/acpi.h>
3 #include <linux/init.h>
6 #include <linux/slab.h>
8 #include <asm/pci_x86.h>
10 struct pci_root_info
{
11 struct acpi_device
*bridge
;
13 struct pci_sysdata sd
;
14 #ifdef CONFIG_PCI_MMCONFIG
22 static bool pci_use_crs
= true;
23 static bool pci_ignore_seg
= false;
25 static int __init
set_use_crs(const struct dmi_system_id
*id
)
31 static int __init
set_nouse_crs(const struct dmi_system_id
*id
)
37 static int __init
set_ignore_seg(const struct dmi_system_id
*id
)
39 printk(KERN_INFO
"PCI: %s detected: ignoring ACPI _SEG\n", id
->ident
);
40 pci_ignore_seg
= true;
44 static const struct dmi_system_id pci_crs_quirks
[] __initconst
= {
45 /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
47 .callback
= set_use_crs
,
48 .ident
= "IBM System x3800",
50 DMI_MATCH(DMI_SYS_VENDOR
, "IBM"),
51 DMI_MATCH(DMI_PRODUCT_NAME
, "x3800"),
54 /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
55 /* 2006 AMD HT/VIA system with two host bridges */
57 .callback
= set_use_crs
,
58 .ident
= "ASRock ALiveSATA2-GLAN",
60 DMI_MATCH(DMI_PRODUCT_NAME
, "ALiveSATA2-GLAN"),
63 /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */
64 /* 2006 AMD HT/VIA system with two host bridges */
66 .callback
= set_use_crs
,
67 .ident
= "ASUS M2V-MX SE",
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."),
74 /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */
76 .callback
= set_use_crs
,
77 .ident
= "MSI MS-7253",
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"),
85 /* Now for the blacklist.. */
87 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
89 .callback
= set_nouse_crs
,
90 .ident
= "Dell Studio 1557",
92 DMI_MATCH(DMI_BOARD_VENDOR
, "Dell Inc."),
93 DMI_MATCH(DMI_PRODUCT_NAME
, "Studio 1557"),
94 DMI_MATCH(DMI_BIOS_VERSION
, "A09"),
97 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
99 .callback
= set_nouse_crs
,
100 .ident
= "Thinkpad SL510",
102 DMI_MATCH(DMI_BOARD_VENDOR
, "LENOVO"),
103 DMI_MATCH(DMI_BOARD_NAME
, "2847DFG"),
104 DMI_MATCH(DMI_BIOS_VERSION
, "6JET85WW (1.43 )"),
108 /* https://bugzilla.kernel.org/show_bug.cgi?id=15362 */
110 .callback
= set_ignore_seg
,
111 .ident
= "HP xw9300",
113 DMI_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
114 DMI_MATCH(DMI_PRODUCT_NAME
, "HP xw9300 Workstation"),
120 void __init
pci_acpi_crs_quirks(void)
124 if (dmi_get_date(DMI_BIOS_DATE
, &year
, NULL
, NULL
) && year
< 2008)
127 dmi_check_system(pci_crs_quirks
);
130 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
131 * takes precedence over anything we figured out above.
133 if (pci_probe
& PCI_ROOT_NO_CRS
)
135 else if (pci_probe
& PCI_USE__CRS
)
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");
144 #ifdef CONFIG_PCI_MMCONFIG
145 static int check_segment(u16 seg
, struct device
*dev
, char *estr
)
149 "%s can't access PCI configuration "
150 "space under this host bridge.\n",
156 * Failure in adding MMCFG information is not fatal,
157 * just can't access extended configuration space of
158 * devices under this host bridge.
161 "%s can't access extended PCI configuration "
162 "space under this bridge.\n",
168 static int setup_mcfg_map(struct pci_root_info
*info
, u16 seg
, u8 start
,
169 u8 end
, phys_addr_t addr
)
172 struct device
*dev
= &info
->bridge
->dev
;
174 info
->start_bus
= start
;
176 info
->mcfg_added
= false;
178 /* return success if MMCFG is not in use */
179 if (raw_pci_ext_ops
&& raw_pci_ext_ops
!= &pci_mmcfg
)
182 if (!(pci_probe
& PCI_PROBE_MMCONF
))
183 return check_segment(seg
, dev
, "MMCONFIG is disabled,");
185 result
= pci_mmconfig_insert(dev
, seg
, start
, end
, addr
);
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,");
198 static void teardown_mcfg_map(struct pci_root_info
*info
)
200 if (info
->mcfg_added
) {
201 pci_mmconfig_delete(info
->segment
, info
->start_bus
,
203 info
->mcfg_added
= false;
207 static int setup_mcfg_map(struct pci_root_info
*info
,
208 u16 seg
, u8 start
, u8 end
,
213 static void teardown_mcfg_map(struct pci_root_info
*info
)
218 static void validate_resources(struct device
*dev
, struct list_head
*crs_res
,
222 struct resource
*res1
, *res2
, *root
= NULL
;
223 struct resource_entry
*tmp
, *entry
, *entry2
;
225 BUG_ON((type
& (IORESOURCE_MEM
| IORESOURCE_IO
)) == 0);
226 root
= (type
& IORESOURCE_MEM
) ? &iomem_resource
: &ioport_resource
;
228 list_splice_init(crs_res
, &list
);
229 resource_list_for_each_entry_safe(entry
, tmp
, &list
) {
234 if (!(res1
->flags
& type
))
237 /* 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",
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
);
251 resource_list_for_each_entry(entry2
, crs_res
) {
253 if (!(res2
->flags
& type
))
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.
261 if (resource_overlaps(res1
, res2
)) {
262 res2
->start
= min(res1
->start
, res2
->start
);
263 res2
->end
= max(res1
->end
, res2
->end
);
264 dev_info(dev
, "host bridge window expanded to %pR; %pR ignored\n",
272 resource_list_del(entry
);
274 resource_list_free_entry(entry
);
276 resource_list_add_tail(entry
, crs_res
);
280 static void add_resources(struct pci_root_info
*info
,
281 struct list_head
*resources
,
282 struct list_head
*crs_res
)
284 struct resource_entry
*entry
, *tmp
;
285 struct resource
*res
, *conflict
, *root
= NULL
;
287 validate_resources(&info
->bridge
->dev
, crs_res
, IORESOURCE_MEM
);
288 validate_resources(&info
->bridge
->dev
, crs_res
, IORESOURCE_IO
);
290 resource_list_for_each_entry_safe(entry
, tmp
, crs_res
) {
292 if (res
->flags
& IORESOURCE_MEM
)
293 root
= &iomem_resource
;
294 else if (res
->flags
& IORESOURCE_IO
)
295 root
= &ioport_resource
;
299 conflict
= insert_resource_conflict(root
, res
);
301 dev_info(&info
->bridge
->dev
,
302 "ignoring host bridge window %pR (conflicts with %s %pR)\n",
303 res
, conflict
->name
, conflict
);
304 resource_list_destroy_entry(entry
);
308 list_splice_tail(crs_res
, resources
);
311 static void release_pci_root_info(struct pci_host_bridge
*bridge
)
313 struct resource
*res
;
314 struct resource_entry
*entry
;
315 struct pci_root_info
*info
= bridge
->release_data
;
317 resource_list_for_each_entry(entry
, &bridge
->windows
) {
320 (res
->flags
& (IORESOURCE_MEM
| IORESOURCE_IO
)))
321 release_resource(res
);
324 teardown_mcfg_map(info
);
328 static void probe_pci_root_info(struct pci_root_info
*info
,
329 struct acpi_device
*device
,
330 int busnum
, int domain
,
331 struct list_head
*list
)
334 struct resource_entry
*entry
;
336 sprintf(info
->name
, "PCI Bus %04x:%02x", domain
, busnum
);
337 info
->bridge
= device
;
338 ret
= acpi_dev_get_resources(device
, list
,
339 acpi_dev_filter_resource_type_cb
,
340 (void *)(IORESOURCE_IO
| IORESOURCE_MEM
));
342 dev_warn(&device
->dev
,
343 "failed to parse _CRS method, error code %d\n", ret
);
345 dev_dbg(&device
->dev
,
346 "no IO and memory resources present in _CRS\n");
348 resource_list_for_each_entry(entry
, list
)
349 entry
->res
->name
= info
->name
;
352 struct pci_bus
*pci_acpi_scan_root(struct acpi_pci_root
*root
)
354 struct acpi_device
*device
= root
->device
;
355 struct pci_root_info
*info
;
356 int domain
= root
->segment
;
357 int busnum
= root
->secondary
.start
;
358 struct resource_entry
*res_entry
;
360 LIST_HEAD(resources
);
362 struct pci_sysdata
*sd
;
368 if (domain
&& !pci_domains_supported
) {
369 printk(KERN_WARNING
"pci_bus %04x:%02x: "
370 "ignored (multiple domains not supported)\n",
375 node
= acpi_get_node(device
->handle
);
376 if (node
== NUMA_NO_NODE
) {
377 node
= x86_pci_root_bus_node(busnum
);
378 if (node
!= 0 && node
!= NUMA_NO_NODE
)
379 dev_info(&device
->dev
, FW_BUG
"no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n",
383 if (node
!= NUMA_NO_NODE
&& !node_online(node
))
386 info
= kzalloc_node(sizeof(*info
), GFP_KERNEL
, node
);
388 printk(KERN_WARNING
"pci_bus %04x:%02x: "
389 "ignored (out of memory)\n", domain
, busnum
);
396 sd
->companion
= device
;
398 bus
= pci_find_bus(domain
, busnum
);
401 * If the desired bus has been scanned already, replace
404 memcpy(bus
->sysdata
, sd
, sizeof(*sd
));
407 /* insert busn res at first */
408 pci_add_resource(&resources
, &root
->secondary
);
411 * _CRS with no apertures is normal, so only fall back to
412 * defaults or native bridge info if we're ignoring _CRS.
414 probe_pci_root_info(info
, device
, busnum
, domain
, &crs_res
);
416 add_resources(info
, &resources
, &crs_res
);
418 resource_list_for_each_entry(res_entry
, &crs_res
)
419 dev_printk(KERN_DEBUG
, &device
->dev
,
420 "host bridge window %pR (ignored)\n",
422 resource_list_free(&crs_res
);
423 x86_pci_root_bus_resources(busnum
, &resources
);
426 if (!setup_mcfg_map(info
, domain
, (u8
)root
->secondary
.start
,
427 (u8
)root
->secondary
.end
, root
->mcfg_addr
))
428 bus
= pci_create_root_bus(NULL
, busnum
, &pci_root_ops
,
432 pci_scan_child_bus(bus
);
433 pci_set_host_bridge_release(
434 to_pci_host_bridge(bus
->bridge
),
435 release_pci_root_info
, info
);
437 resource_list_free(&resources
);
438 teardown_mcfg_map(info
);
443 /* After the PCI-E bus has been walked and all devices discovered,
444 * configure any settings of the fabric that might be necessary.
447 struct pci_bus
*child
;
448 list_for_each_entry(child
, &bus
->children
, node
)
449 pcie_bus_configure_settings(child
);
452 if (bus
&& node
!= NUMA_NO_NODE
)
453 dev_printk(KERN_DEBUG
, &bus
->dev
, "on NUMA node %d\n", node
);
458 int pcibios_root_bridge_prepare(struct pci_host_bridge
*bridge
)
460 struct pci_sysdata
*sd
= bridge
->bus
->sysdata
;
462 ACPI_COMPANION_SET(&bridge
->dev
, sd
->companion
);
466 int __init
pci_acpi_init(void)
468 struct pci_dev
*dev
= NULL
;
473 printk(KERN_INFO
"PCI: Using ACPI for IRQ routing\n");
474 acpi_irq_penalty_init();
475 pcibios_enable_irq
= acpi_pci_irq_enable
;
476 pcibios_disable_irq
= acpi_pci_irq_disable
;
477 x86_init
.pci
.init_irq
= x86_init_noop
;
481 * PCI IRQ routing is set up by pci_enable_device(), but we
482 * also do it here in case there are still broken drivers that
483 * don't use pci_enable_device().
485 printk(KERN_INFO
"PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
486 for_each_pci_dev(dev
)
487 acpi_pci_irq_enable(dev
);