13 #include <linux/pci.h>
17 #include <linux/bitmap.h>
19 #include <linux/slab.h>
26 #define PREFIX "PCI: "
29 static bool pci_mmcfg_running_state;
30 static bool pci_mmcfg_arch_init_failed;
43 static __init void free_all_mmcfg(
void)
49 pci_mmconfig_remove(cfg);
57 list_for_each_entry_rcu(cfg, &pci_mmcfg_list,
list) {
58 if (cfg->
segment > new->segment ||
59 (cfg->
segment == new->segment &&
61 list_add_tail_rcu(&new->list, &cfg->
list);
65 list_add_tail_rcu(&new->list, &pci_mmcfg_list);
84 new->start_bus =
start;
92 "PCI MMCONFIG %04x [bus %02x-%02x]", segment, start, end);
93 res->
name =
new->name;
103 new = pci_mmconfig_alloc(segment, start, end, addr);
106 list_add_sorted(
new);
110 "MMCONFIG for domain %04x [bus %02x-%02x] at %pR "
112 segment, start, end, &new->res, (
unsigned long)addr);
130 static const char __init *pci_mmcfg_e7520(
void)
136 if (win == 0x0000 || win == 0xf000)
139 if (pci_mmconfig_add(0, 0, 255, win << 16) ==
NULL)
142 return "Intel Corporation E7520 Memory Controller Hub";
145 static const char __init *pci_mmcfg_intel_945(
void)
156 switch ((pciexbar >> 1) & 3) {
176 if ((pciexbar & mask) & 0x0fffffffU)
180 if ((pciexbar & mask) >= 0xf0000000U)
183 if (pci_mmconfig_add(0, 0, (len >> 20) - 1, pciexbar & mask) ==
NULL)
186 return "Intel Corporation 945G/GZ/P/PL Express Memory Controller Hub";
189 static const char __init *pci_mmcfg_amd_fam10h(
void)
194 unsigned segnbits = 0, busnbits,
end_bus;
200 if (rdmsr_safe(address, &low, &high))
224 segnbits = busnbits - 8;
228 end_bus = (1 << busnbits) - 1;
229 for (i = 0; i < (1 << segnbits); i++)
230 if (pci_mmconfig_add(i, 0, end_bus,
231 base + (1<<28) *
i) ==
NULL) {
236 return "AMD Family 10h NB";
240 static const char __init *pci_mmcfg_nvidia_mcp55(
void)
243 int mcp55_mmconf_found = 0;
245 static const u32 extcfg_regnum = 0x90;
246 static const u32 extcfg_regsize = 4;
247 static const u32 extcfg_enable_mask = 1<<31;
248 static const u32 extcfg_start_mask = 0xff<<16;
249 static const int extcfg_start_shift = 16;
250 static const u32 extcfg_size_mask = 0x3<<28;
251 static const int extcfg_size_shift = 28;
252 static const int extcfg_sizebus[] = {0x100, 0x80, 0x40, 0x20};
253 static const u32 extcfg_base_mask[] = {0x7ff8, 0x7ffc, 0x7ffe, 0x7fff};
254 static const int extcfg_base_lshift = 25;
259 if (!
acpi_disabled || !list_empty(&pci_mmcfg_list) || mcp55_checked)
262 mcp55_checked =
true;
263 for (bus = 0; bus < 256; bus++) {
271 device = (l >> 16) & 0xffff;
277 extcfg_regsize, &extcfg);
279 if (!(extcfg & extcfg_enable_mask))
282 size_index = (extcfg & extcfg_size_mask) >> extcfg_size_shift;
283 base = extcfg & extcfg_base_mask[size_index];
285 base <<= extcfg_base_lshift;
286 start = (extcfg & extcfg_start_mask) >> extcfg_start_shift;
287 end = start + extcfg_sizebus[size_index] - 1;
288 if (pci_mmconfig_add(0, start, end, base) ==
NULL)
290 mcp55_mmconf_found++;
293 if (!mcp55_mmconf_found)
296 return "nVidia MCP55";
313 0x1200, pci_mmcfg_amd_fam10h },
315 0x1200, pci_mmcfg_amd_fam10h },
317 0x0369, pci_mmcfg_nvidia_mcp55 },
320 static void __init pci_mmcfg_check_end_bus_number(
void)
330 if (cfg->
list.next == &pci_mmcfg_list)
339 static int __init pci_mmcfg_check_hostbridge(
void)
352 for (i = 0; i <
ARRAY_SIZE(pci_mmcfg_probes); i++) {
353 bus = pci_mmcfg_probes[
i].bus;
354 devfn = pci_mmcfg_probes[
i].devfn;
357 device = (l >> 16) & 0xffff;
360 if (pci_mmcfg_probes[i].vendor == vendor &&
361 pci_mmcfg_probes[i].device == device)
362 name = pci_mmcfg_probes[
i].probe();
369 pci_mmcfg_check_end_bus_number();
371 return !list_empty(&pci_mmcfg_list);
399 (address.address_length <= 0) ||
403 if ((mcfg_res->
start >= address.minimum) &&
404 (mcfg_res->
end < (address.minimum + address.address_length))) {
417 check_mcfg_resource, context);
425 static int __devinit is_acpi_reserved(
u64 start,
u64 end,
unsigned not_used)
430 mcfg_res.
end = end - 1;
439 return mcfg_res.
flags;
446 struct device *
dev,
int with_e820)
448 u64 addr = cfg->
res.start;
452 char *
method = with_e820 ?
"E820" :
"ACPI motherboard resources";
456 if (size < (16
UL<<20))
460 if (size < (16
UL<<20) && size != old_size)
464 dev_info(dev,
"MMCONFIG at %pR reserved in %s\n",
470 if (old_size != size) {
474 cfg->
res.end = cfg->
res.start +
477 "PCI MMCONFIG %04x [bus %02x-%02x]",
483 "at %pR (base %#lx) (size reduced!)\n",
487 "MMCONFIG for %04x [bus%02x-%02x] "
488 "at %pR (base %#lx) (size reduced!)\n",
496 static int __ref pci_mmcfg_check_reserved(
struct device *
dev,
500 if (is_mmconf_reserved(is_acpi_reserved, cfg, dev, 0))
505 "MMCONFIG at %pR not reserved in "
506 "ACPI motherboard resources\n",
510 "MMCONFIG at %pR not reserved in "
511 "ACPI motherboard resources\n",
521 if (pci_mmcfg_running_state)
532 static void __init pci_mmcfg_reject_broken(
int early)
537 if (pci_mmcfg_check_reserved(
NULL, cfg, early) == 0) {
557 if (mcfg->
header.revision >= 1) {
563 pr_err(
PREFIX "MCFG region for %04x [bus %02x-%02x] at %#llx "
595 for (i = 0; i <
entries; i++) {
597 if (acpi_mcfg_check_entry(mcfg, cfg)) {
613 static void __init __pci_mmcfg_init(
int early)
615 pci_mmcfg_reject_broken(early);
616 if (list_empty(&pci_mmcfg_list))
633 pci_mmcfg_arch_init_failed =
true;
637 static int __initdata known_bridge;
642 if (pci_mmcfg_check_hostbridge())
666 static int __init pci_mmcfg_late_insert_resources(
void)
670 pci_mmcfg_running_state =
true;
682 if (!cfg->res.parent)
704 if (!(
pci_probe & PCI_PROBE_MMCONF) || pci_mmcfg_arch_init_failed)
716 "domain %04x [bus %02x-%02x] "
717 "only partially covers this bridge\n",
729 cfg = pci_mmconfig_alloc(seg, start, end, addr);
731 dev_warn(dev,
"fail to add MMCONFIG (out of memory)\n");
733 }
else if (!pci_mmcfg_check_reserved(dev, cfg, 0)) {
738 if (pci_mmcfg_running_state)
744 "MMCONFIG %pR conflicts with "
748 dev_warn(dev,
"fail to map MMCONFIG %pR.\n",
751 list_add_sorted(cfg);
752 dev_info(dev,
"MMCONFIG at %pR (base %#lx)\n",
753 &cfg->
res, (
unsigned long)addr);
779 list_del_rcu(&cfg->
list);