mmconfig-shared.c 16 KB

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