mmconfig-shared.c 16 KB

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