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