mmconfig-shared.c 16 KB

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