mmconfig-shared.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * mmconfig-shared.c - Low-level direct PCI config space access via
  3. * MMCONFIG - common code between i386 and x86-64.
  4. *
  5. * This code does:
  6. * - known chipset handling
  7. * - ACPI decoding and validation
  8. *
  9. * Per-architecture code takes care of the mappings and accesses
  10. * themselves.
  11. */
  12. #include <linux/pci.h>
  13. #include <linux/init.h>
  14. #include <linux/acpi.h>
  15. #include <linux/sfi_acpi.h>
  16. #include <linux/bitmap.h>
  17. #include <linux/dmi.h>
  18. #include <linux/sort.h>
  19. #include <asm/e820.h>
  20. #include <asm/pci_x86.h>
  21. #include <asm/acpi.h>
  22. #define PREFIX "PCI: "
  23. /* Indicate if the mmcfg resources have been placed into the resource table. */
  24. static int __initdata pci_mmcfg_resources_inserted;
  25. static __init void free_all_mmcfg(void)
  26. {
  27. int i;
  28. struct pci_mmcfg_region *cfg;
  29. pci_mmcfg_arch_free();
  30. for (i = 0; i < pci_mmcfg_config_num; i++) {
  31. cfg = &pci_mmcfg_config[i];
  32. if (cfg->res.parent)
  33. release_resource(&cfg->res);
  34. }
  35. pci_mmcfg_config_num = 0;
  36. kfree(pci_mmcfg_config);
  37. pci_mmcfg_config = NULL;
  38. }
  39. static __init struct pci_mmcfg_region *pci_mmconfig_add(int segment, int start,
  40. int end, u64 addr)
  41. {
  42. struct pci_mmcfg_region *new;
  43. int new_num = pci_mmcfg_config_num + 1;
  44. int i = pci_mmcfg_config_num;
  45. int num_buses;
  46. struct resource *res;
  47. if (addr == 0)
  48. return NULL;
  49. new = kzalloc(sizeof(pci_mmcfg_config[0]) * new_num, GFP_KERNEL);
  50. if (!new)
  51. return NULL;
  52. if (pci_mmcfg_config) {
  53. memcpy(new, pci_mmcfg_config,
  54. sizeof(pci_mmcfg_config[0]) * new_num);
  55. kfree(pci_mmcfg_config);
  56. }
  57. pci_mmcfg_config = new;
  58. pci_mmcfg_config_num++;
  59. new = &pci_mmcfg_config[i];
  60. new->address = addr;
  61. new->segment = segment;
  62. new->start_bus = start;
  63. new->end_bus = end;
  64. num_buses = end - start + 1;
  65. res = &new->res;
  66. res->start = addr + PCI_MMCFG_BUS_OFFSET(start);
  67. res->end = addr + PCI_MMCFG_BUS_OFFSET(num_buses) - 1;
  68. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  69. snprintf(new->name, PCI_MMCFG_RESOURCE_NAME_LEN,
  70. "PCI MMCONFIG %04x [bus %02x-%02x]", segment, start, end);
  71. res->name = new->name;
  72. return &pci_mmcfg_config[i];
  73. }
  74. static const char __init *pci_mmcfg_e7520(void)
  75. {
  76. u32 win;
  77. raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0xce, 2, &win);
  78. win = win & 0xf000;
  79. if (win == 0x0000 || win == 0xf000)
  80. return NULL;
  81. if (pci_mmconfig_add(0, 0, 255, win << 16) == NULL)
  82. return NULL;
  83. return "Intel Corporation E7520 Memory Controller Hub";
  84. }
  85. static const char __init *pci_mmcfg_intel_945(void)
  86. {
  87. u32 pciexbar, mask = 0, len = 0;
  88. raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0x48, 4, &pciexbar);
  89. /* Enable bit */
  90. if (!(pciexbar & 1))
  91. return NULL;
  92. /* Size bits */
  93. switch ((pciexbar >> 1) & 3) {
  94. case 0:
  95. mask = 0xf0000000U;
  96. len = 0x10000000U;
  97. break;
  98. case 1:
  99. mask = 0xf8000000U;
  100. len = 0x08000000U;
  101. break;
  102. case 2:
  103. mask = 0xfc000000U;
  104. len = 0x04000000U;
  105. break;
  106. default:
  107. return NULL;
  108. }
  109. /* Errata #2, things break when not aligned on a 256Mb boundary */
  110. /* Can only happen in 64M/128M mode */
  111. if ((pciexbar & mask) & 0x0fffffffU)
  112. return NULL;
  113. /* Don't hit the APIC registers and their friends */
  114. if ((pciexbar & mask) >= 0xf0000000U)
  115. return NULL;
  116. if (pci_mmconfig_add(0, 0, (len >> 20) - 1, pciexbar & mask) == NULL)
  117. return NULL;
  118. return "Intel Corporation 945G/GZ/P/PL Express Memory Controller Hub";
  119. }
  120. static const char __init *pci_mmcfg_amd_fam10h(void)
  121. {
  122. u32 low, high, address;
  123. u64 base, msr;
  124. int i;
  125. unsigned segnbits = 0, busnbits, end_bus;
  126. if (!(pci_probe & PCI_CHECK_ENABLE_AMD_MMCONF))
  127. return NULL;
  128. address = MSR_FAM10H_MMIO_CONF_BASE;
  129. if (rdmsr_safe(address, &low, &high))
  130. return NULL;
  131. msr = high;
  132. msr <<= 32;
  133. msr |= low;
  134. /* mmconfig is not enable */
  135. if (!(msr & FAM10H_MMIO_CONF_ENABLE))
  136. return NULL;
  137. base = msr & (FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT);
  138. busnbits = (msr >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) &
  139. FAM10H_MMIO_CONF_BUSRANGE_MASK;
  140. /*
  141. * only handle bus 0 ?
  142. * need to skip it
  143. */
  144. if (!busnbits)
  145. return NULL;
  146. if (busnbits > 8) {
  147. segnbits = busnbits - 8;
  148. busnbits = 8;
  149. }
  150. end_bus = (1 << busnbits) - 1;
  151. for (i = 0; i < (1 << segnbits); i++)
  152. if (pci_mmconfig_add(i, 0, end_bus,
  153. base + (1<<28) * i) == NULL) {
  154. free_all_mmcfg();
  155. return NULL;
  156. }
  157. return "AMD Family 10h NB";
  158. }
  159. static bool __initdata mcp55_checked;
  160. static const char __init *pci_mmcfg_nvidia_mcp55(void)
  161. {
  162. int bus;
  163. int mcp55_mmconf_found = 0;
  164. static const u32 extcfg_regnum = 0x90;
  165. static const u32 extcfg_regsize = 4;
  166. static const u32 extcfg_enable_mask = 1<<31;
  167. static const u32 extcfg_start_mask = 0xff<<16;
  168. static const int extcfg_start_shift = 16;
  169. static const u32 extcfg_size_mask = 0x3<<28;
  170. static const int extcfg_size_shift = 28;
  171. static const int extcfg_sizebus[] = {0x100, 0x80, 0x40, 0x20};
  172. static const u32 extcfg_base_mask[] = {0x7ff8, 0x7ffc, 0x7ffe, 0x7fff};
  173. static const int extcfg_base_lshift = 25;
  174. /*
  175. * do check if amd fam10h already took over
  176. */
  177. if (!acpi_disabled || pci_mmcfg_config_num || mcp55_checked)
  178. return NULL;
  179. mcp55_checked = true;
  180. for (bus = 0; bus < 256; bus++) {
  181. u64 base;
  182. u32 l, extcfg;
  183. u16 vendor, device;
  184. int start, size_index, end;
  185. raw_pci_ops->read(0, bus, PCI_DEVFN(0, 0), 0, 4, &l);
  186. vendor = l & 0xffff;
  187. device = (l >> 16) & 0xffff;
  188. if (PCI_VENDOR_ID_NVIDIA != vendor || 0x0369 != device)
  189. continue;
  190. raw_pci_ops->read(0, bus, PCI_DEVFN(0, 0), extcfg_regnum,
  191. extcfg_regsize, &extcfg);
  192. if (!(extcfg & extcfg_enable_mask))
  193. continue;
  194. size_index = (extcfg & extcfg_size_mask) >> extcfg_size_shift;
  195. base = extcfg & extcfg_base_mask[size_index];
  196. /* base could > 4G */
  197. base <<= extcfg_base_lshift;
  198. start = (extcfg & extcfg_start_mask) >> extcfg_start_shift;
  199. end = start + extcfg_sizebus[size_index] - 1;
  200. if (pci_mmconfig_add(0, start, end, base) == NULL)
  201. continue;
  202. mcp55_mmconf_found++;
  203. }
  204. if (!mcp55_mmconf_found)
  205. return NULL;
  206. return "nVidia MCP55";
  207. }
  208. struct pci_mmcfg_hostbridge_probe {
  209. u32 bus;
  210. u32 devfn;
  211. u32 vendor;
  212. u32 device;
  213. const char *(*probe)(void);
  214. };
  215. static struct pci_mmcfg_hostbridge_probe pci_mmcfg_probes[] __initdata = {
  216. { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL,
  217. PCI_DEVICE_ID_INTEL_E7520_MCH, pci_mmcfg_e7520 },
  218. { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL,
  219. PCI_DEVICE_ID_INTEL_82945G_HB, pci_mmcfg_intel_945 },
  220. { 0, PCI_DEVFN(0x18, 0), PCI_VENDOR_ID_AMD,
  221. 0x1200, pci_mmcfg_amd_fam10h },
  222. { 0xff, PCI_DEVFN(0, 0), PCI_VENDOR_ID_AMD,
  223. 0x1200, pci_mmcfg_amd_fam10h },
  224. { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_NVIDIA,
  225. 0x0369, pci_mmcfg_nvidia_mcp55 },
  226. };
  227. static int __init cmp_mmcfg(const void *x1, const void *x2)
  228. {
  229. const typeof(pci_mmcfg_config[0]) *m1 = x1;
  230. const typeof(pci_mmcfg_config[0]) *m2 = x2;
  231. int start1, start2;
  232. start1 = m1->start_bus;
  233. start2 = m2->start_bus;
  234. return start1 - start2;
  235. }
  236. static void __init pci_mmcfg_check_end_bus_number(void)
  237. {
  238. int i;
  239. typeof(pci_mmcfg_config[0]) *cfg, *cfgx;
  240. /* sort them at first */
  241. sort(pci_mmcfg_config, pci_mmcfg_config_num,
  242. sizeof(pci_mmcfg_config[0]), cmp_mmcfg, NULL);
  243. /* last one*/
  244. if (pci_mmcfg_config_num > 0) {
  245. i = pci_mmcfg_config_num - 1;
  246. cfg = &pci_mmcfg_config[i];
  247. if (cfg->end_bus < cfg->start_bus)
  248. cfg->end_bus = 255;
  249. }
  250. /* don't overlap please */
  251. for (i = 0; i < pci_mmcfg_config_num - 1; i++) {
  252. cfg = &pci_mmcfg_config[i];
  253. cfgx = &pci_mmcfg_config[i+1];
  254. if (cfg->end_bus < cfg->start_bus)
  255. cfg->end_bus = 255;
  256. if (cfg->end_bus >= cfgx->start_bus)
  257. cfg->end_bus = cfgx->start_bus - 1;
  258. }
  259. }
  260. static int __init pci_mmcfg_check_hostbridge(void)
  261. {
  262. u32 l;
  263. u32 bus, devfn;
  264. u16 vendor, device;
  265. int i;
  266. const char *name;
  267. if (!raw_pci_ops)
  268. return 0;
  269. free_all_mmcfg();
  270. for (i = 0; i < ARRAY_SIZE(pci_mmcfg_probes); i++) {
  271. bus = pci_mmcfg_probes[i].bus;
  272. devfn = pci_mmcfg_probes[i].devfn;
  273. raw_pci_ops->read(0, bus, devfn, 0, 4, &l);
  274. vendor = l & 0xffff;
  275. device = (l >> 16) & 0xffff;
  276. name = NULL;
  277. if (pci_mmcfg_probes[i].vendor == vendor &&
  278. pci_mmcfg_probes[i].device == device)
  279. name = pci_mmcfg_probes[i].probe();
  280. if (name)
  281. printk(KERN_INFO "PCI: Found %s with MMCONFIG support.\n",
  282. name);
  283. }
  284. /* some end_bus_number is crazy, fix it */
  285. pci_mmcfg_check_end_bus_number();
  286. return pci_mmcfg_config_num != 0;
  287. }
  288. static void __init pci_mmcfg_insert_resources(void)
  289. {
  290. int i;
  291. struct pci_mmcfg_region *cfg;
  292. for (i = 0; i < pci_mmcfg_config_num; i++) {
  293. cfg = &pci_mmcfg_config[i];
  294. insert_resource(&iomem_resource, &cfg->res);
  295. }
  296. /* Mark that the resources have been inserted. */
  297. pci_mmcfg_resources_inserted = 1;
  298. }
  299. static acpi_status __init check_mcfg_resource(struct acpi_resource *res,
  300. void *data)
  301. {
  302. struct resource *mcfg_res = data;
  303. struct acpi_resource_address64 address;
  304. acpi_status status;
  305. if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
  306. struct acpi_resource_fixed_memory32 *fixmem32 =
  307. &res->data.fixed_memory32;
  308. if (!fixmem32)
  309. return AE_OK;
  310. if ((mcfg_res->start >= fixmem32->address) &&
  311. (mcfg_res->end < (fixmem32->address +
  312. fixmem32->address_length))) {
  313. mcfg_res->flags = 1;
  314. return AE_CTRL_TERMINATE;
  315. }
  316. }
  317. if ((res->type != ACPI_RESOURCE_TYPE_ADDRESS32) &&
  318. (res->type != ACPI_RESOURCE_TYPE_ADDRESS64))
  319. return AE_OK;
  320. status = acpi_resource_to_address64(res, &address);
  321. if (ACPI_FAILURE(status) ||
  322. (address.address_length <= 0) ||
  323. (address.resource_type != ACPI_MEMORY_RANGE))
  324. return AE_OK;
  325. if ((mcfg_res->start >= address.minimum) &&
  326. (mcfg_res->end < (address.minimum + address.address_length))) {
  327. mcfg_res->flags = 1;
  328. return AE_CTRL_TERMINATE;
  329. }
  330. return AE_OK;
  331. }
  332. static acpi_status __init find_mboard_resource(acpi_handle handle, u32 lvl,
  333. void *context, void **rv)
  334. {
  335. struct resource *mcfg_res = context;
  336. acpi_walk_resources(handle, METHOD_NAME__CRS,
  337. check_mcfg_resource, context);
  338. if (mcfg_res->flags)
  339. return AE_CTRL_TERMINATE;
  340. return AE_OK;
  341. }
  342. static int __init is_acpi_reserved(u64 start, u64 end, unsigned not_used)
  343. {
  344. struct resource mcfg_res;
  345. mcfg_res.start = start;
  346. mcfg_res.end = end - 1;
  347. mcfg_res.flags = 0;
  348. acpi_get_devices("PNP0C01", find_mboard_resource, &mcfg_res, NULL);
  349. if (!mcfg_res.flags)
  350. acpi_get_devices("PNP0C02", find_mboard_resource, &mcfg_res,
  351. NULL);
  352. return mcfg_res.flags;
  353. }
  354. typedef int (*check_reserved_t)(u64 start, u64 end, unsigned type);
  355. static int __init is_mmconf_reserved(check_reserved_t is_reserved,
  356. int i, typeof(pci_mmcfg_config[0]) *cfg, int with_e820)
  357. {
  358. u64 addr = cfg->res.start;
  359. u64 size = resource_size(&cfg->res);
  360. u64 old_size = size;
  361. int valid = 0, num_buses;
  362. while (!is_reserved(addr, addr + size, E820_RESERVED)) {
  363. size >>= 1;
  364. if (size < (16UL<<20))
  365. break;
  366. }
  367. if (size >= (16UL<<20) || size == old_size) {
  368. printk(KERN_NOTICE
  369. "PCI: MCFG area at %Lx reserved in %s\n",
  370. addr, with_e820?"E820":"ACPI motherboard resources");
  371. valid = 1;
  372. if (old_size != size) {
  373. /* update end_bus */
  374. cfg->end_bus = cfg->start_bus + ((size>>20) - 1);
  375. num_buses = cfg->end_bus - cfg->start_bus + 1;
  376. cfg->res.end = cfg->res.start +
  377. PCI_MMCFG_BUS_OFFSET(num_buses) - 1;
  378. snprintf(cfg->name, PCI_MMCFG_RESOURCE_NAME_LEN,
  379. "PCI MMCONFIG %04x [bus %02x-%02x]",
  380. cfg->segment, cfg->start_bus, cfg->end_bus);
  381. printk(KERN_NOTICE "PCI: updated MCFG configuration %d: base %lx "
  382. "segment %hu buses %u - %u\n",
  383. i, (unsigned long)cfg->address, cfg->segment,
  384. (unsigned int)cfg->start_bus,
  385. (unsigned int)cfg->end_bus);
  386. }
  387. }
  388. return valid;
  389. }
  390. static void __init pci_mmcfg_reject_broken(int early)
  391. {
  392. typeof(pci_mmcfg_config[0]) *cfg;
  393. int i;
  394. if (pci_mmcfg_config_num == 0)
  395. return;
  396. for (i = 0; i < pci_mmcfg_config_num; i++) {
  397. int valid = 0;
  398. cfg = &pci_mmcfg_config[i];
  399. printk(KERN_NOTICE "PCI: MCFG configuration %d: base %lx "
  400. "segment %hu buses %u - %u\n",
  401. i, (unsigned long)cfg->address, cfg->segment,
  402. (unsigned int)cfg->start_bus,
  403. (unsigned int)cfg->end_bus);
  404. if (!early && !acpi_disabled)
  405. valid = is_mmconf_reserved(is_acpi_reserved, i, cfg, 0);
  406. if (valid)
  407. continue;
  408. if (!early)
  409. printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %Lx is not"
  410. " reserved in ACPI motherboard resources\n",
  411. cfg->address);
  412. /* Don't try to do this check unless configuration
  413. type 1 is available. how about type 2 ?*/
  414. if (raw_pci_ops)
  415. valid = is_mmconf_reserved(e820_all_mapped, i, cfg, 1);
  416. if (!valid)
  417. goto reject;
  418. }
  419. return;
  420. reject:
  421. printk(KERN_INFO "PCI: Not using MMCONFIG.\n");
  422. free_all_mmcfg();
  423. }
  424. static int __initdata known_bridge;
  425. /* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
  426. struct pci_mmcfg_region *pci_mmcfg_config;
  427. int pci_mmcfg_config_num;
  428. static int __init acpi_mcfg_check_entry(struct acpi_table_mcfg *mcfg,
  429. struct acpi_mcfg_allocation *cfg)
  430. {
  431. int year;
  432. if (cfg->address < 0xFFFFFFFF)
  433. return 0;
  434. if (!strcmp(mcfg->header.oem_id, "SGI"))
  435. return 0;
  436. if (mcfg->header.revision >= 1) {
  437. if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) &&
  438. year >= 2010)
  439. return 0;
  440. }
  441. printk(KERN_ERR PREFIX "MCFG region for %04x:%02x-%02x at %#llx "
  442. "is above 4GB, ignored\n", cfg->pci_segment,
  443. cfg->start_bus_number, cfg->end_bus_number, cfg->address);
  444. return -EINVAL;
  445. }
  446. static int __init pci_parse_mcfg(struct acpi_table_header *header)
  447. {
  448. struct acpi_table_mcfg *mcfg;
  449. struct acpi_mcfg_allocation *cfg_table, *cfg;
  450. unsigned long i;
  451. int entries;
  452. if (!header)
  453. return -EINVAL;
  454. mcfg = (struct acpi_table_mcfg *)header;
  455. /* how many config structures do we have */
  456. free_all_mmcfg();
  457. entries = 0;
  458. i = header->length - sizeof(struct acpi_table_mcfg);
  459. while (i >= sizeof(struct acpi_mcfg_allocation)) {
  460. entries++;
  461. i -= sizeof(struct acpi_mcfg_allocation);
  462. };
  463. if (entries == 0) {
  464. printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
  465. return -ENODEV;
  466. }
  467. cfg_table = (struct acpi_mcfg_allocation *) &mcfg[1];
  468. for (i = 0; i < entries; i++) {
  469. cfg = &cfg_table[i];
  470. if (acpi_mcfg_check_entry(mcfg, cfg)) {
  471. free_all_mmcfg();
  472. return -ENODEV;
  473. }
  474. if (pci_mmconfig_add(cfg->pci_segment, cfg->start_bus_number,
  475. cfg->end_bus_number, cfg->address) == NULL) {
  476. printk(KERN_WARNING PREFIX
  477. "no memory for MCFG entries\n");
  478. free_all_mmcfg();
  479. return -ENOMEM;
  480. }
  481. }
  482. return 0;
  483. }
  484. static void __init __pci_mmcfg_init(int early)
  485. {
  486. /* MMCONFIG disabled */
  487. if ((pci_probe & PCI_PROBE_MMCONF) == 0)
  488. return;
  489. /* MMCONFIG already enabled */
  490. if (!early && !(pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF))
  491. return;
  492. /* for late to exit */
  493. if (known_bridge)
  494. return;
  495. if (early) {
  496. if (pci_mmcfg_check_hostbridge())
  497. known_bridge = 1;
  498. }
  499. if (!known_bridge)
  500. acpi_sfi_table_parse(ACPI_SIG_MCFG, pci_parse_mcfg);
  501. pci_mmcfg_reject_broken(early);
  502. if (pci_mmcfg_config_num == 0)
  503. return;
  504. if (pci_mmcfg_arch_init())
  505. pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
  506. else {
  507. /*
  508. * Signal not to attempt to insert mmcfg resources because
  509. * the architecture mmcfg setup could not initialize.
  510. */
  511. pci_mmcfg_resources_inserted = 1;
  512. }
  513. }
  514. void __init pci_mmcfg_early_init(void)
  515. {
  516. __pci_mmcfg_init(1);
  517. }
  518. void __init pci_mmcfg_late_init(void)
  519. {
  520. __pci_mmcfg_init(0);
  521. }
  522. static int __init pci_mmcfg_late_insert_resources(void)
  523. {
  524. /*
  525. * If resources are already inserted or we are not using MMCONFIG,
  526. * don't insert the resources.
  527. */
  528. if ((pci_mmcfg_resources_inserted == 1) ||
  529. (pci_probe & PCI_PROBE_MMCONF) == 0 ||
  530. (pci_mmcfg_config_num == 0))
  531. return 1;
  532. /*
  533. * Attempt to insert the mmcfg resources but not with the busy flag
  534. * marked so it won't cause request errors when __request_region is
  535. * called.
  536. */
  537. pci_mmcfg_insert_resources();
  538. return 0;
  539. }
  540. /*
  541. * Perform MMCONFIG resource insertion after PCI initialization to allow for
  542. * misprogrammed MCFG tables that state larger sizes but actually conflict
  543. * with other system resources.
  544. */
  545. late_initcall(pci_mmcfg_late_insert_resources);