acpi.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. #include <linux/pci.h>
  2. #include <linux/acpi.h>
  3. #include <linux/init.h>
  4. #include <linux/irq.h>
  5. #include <linux/dmi.h>
  6. #include <linux/slab.h>
  7. #include <linux/pci-acpi.h>
  8. #include <asm/numa.h>
  9. #include <asm/pci_x86.h>
  10. struct pci_root_info {
  11. struct acpi_pci_root_info common;
  12. struct pci_sysdata sd;
  13. #ifdef CONFIG_PCI_MMCONFIG
  14. bool mcfg_added;
  15. u8 start_bus;
  16. u8 end_bus;
  17. #endif
  18. };
  19. static bool pci_use_crs = true;
  20. static bool pci_ignore_seg = false;
  21. static int __init set_use_crs(const struct dmi_system_id *id)
  22. {
  23. pci_use_crs = true;
  24. return 0;
  25. }
  26. static int __init set_nouse_crs(const struct dmi_system_id *id)
  27. {
  28. pci_use_crs = false;
  29. return 0;
  30. }
  31. static int __init set_ignore_seg(const struct dmi_system_id *id)
  32. {
  33. printk(KERN_INFO "PCI: %s detected: ignoring ACPI _SEG\n", id->ident);
  34. pci_ignore_seg = true;
  35. return 0;
  36. }
  37. static const struct dmi_system_id pci_crs_quirks[] __initconst = {
  38. /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
  39. {
  40. .callback = set_use_crs,
  41. .ident = "IBM System x3800",
  42. .matches = {
  43. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  44. DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
  45. },
  46. },
  47. /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
  48. /* 2006 AMD HT/VIA system with two host bridges */
  49. {
  50. .callback = set_use_crs,
  51. .ident = "ASRock ALiveSATA2-GLAN",
  52. .matches = {
  53. DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"),
  54. },
  55. },
  56. /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */
  57. /* 2006 AMD HT/VIA system with two host bridges */
  58. {
  59. .callback = set_use_crs,
  60. .ident = "ASUS M2V-MX SE",
  61. .matches = {
  62. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  63. DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"),
  64. DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
  65. },
  66. },
  67. /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */
  68. {
  69. .callback = set_use_crs,
  70. .ident = "MSI MS-7253",
  71. .matches = {
  72. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  73. DMI_MATCH(DMI_BOARD_NAME, "MS-7253"),
  74. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
  75. },
  76. },
  77. /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/931368 */
  78. /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1033299 */
  79. {
  80. .callback = set_use_crs,
  81. .ident = "Foxconn K8M890-8237A",
  82. .matches = {
  83. DMI_MATCH(DMI_BOARD_VENDOR, "Foxconn"),
  84. DMI_MATCH(DMI_BOARD_NAME, "K8M890-8237A"),
  85. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
  86. },
  87. },
  88. /* Now for the blacklist.. */
  89. /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
  90. {
  91. .callback = set_nouse_crs,
  92. .ident = "Dell Studio 1557",
  93. .matches = {
  94. DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."),
  95. DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"),
  96. DMI_MATCH(DMI_BIOS_VERSION, "A09"),
  97. },
  98. },
  99. /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
  100. {
  101. .callback = set_nouse_crs,
  102. .ident = "Thinkpad SL510",
  103. .matches = {
  104. DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
  105. DMI_MATCH(DMI_BOARD_NAME, "2847DFG"),
  106. DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"),
  107. },
  108. },
  109. /* https://bugzilla.kernel.org/show_bug.cgi?id=42606 */
  110. {
  111. .callback = set_nouse_crs,
  112. .ident = "Supermicro X8DTH",
  113. .matches = {
  114. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  115. DMI_MATCH(DMI_PRODUCT_NAME, "X8DTH-i/6/iF/6F"),
  116. DMI_MATCH(DMI_BIOS_VERSION, "2.0a"),
  117. },
  118. },
  119. /* https://bugzilla.kernel.org/show_bug.cgi?id=15362 */
  120. {
  121. .callback = set_ignore_seg,
  122. .ident = "HP xw9300",
  123. .matches = {
  124. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  125. DMI_MATCH(DMI_PRODUCT_NAME, "HP xw9300 Workstation"),
  126. },
  127. },
  128. {}
  129. };
  130. void __init pci_acpi_crs_quirks(void)
  131. {
  132. int year;
  133. if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008) {
  134. if (iomem_resource.end <= 0xffffffff)
  135. pci_use_crs = false;
  136. }
  137. dmi_check_system(pci_crs_quirks);
  138. /*
  139. * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
  140. * takes precedence over anything we figured out above.
  141. */
  142. if (pci_probe & PCI_ROOT_NO_CRS)
  143. pci_use_crs = false;
  144. else if (pci_probe & PCI_USE__CRS)
  145. pci_use_crs = true;
  146. printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
  147. "if necessary, use \"pci=%s\" and report a bug\n",
  148. pci_use_crs ? "Using" : "Ignoring",
  149. pci_use_crs ? "nocrs" : "use_crs");
  150. }
  151. #ifdef CONFIG_PCI_MMCONFIG
  152. static int check_segment(u16 seg, struct device *dev, char *estr)
  153. {
  154. if (seg) {
  155. dev_err(dev,
  156. "%s can't access PCI configuration "
  157. "space under this host bridge.\n",
  158. estr);
  159. return -EIO;
  160. }
  161. /*
  162. * Failure in adding MMCFG information is not fatal,
  163. * just can't access extended configuration space of
  164. * devices under this host bridge.
  165. */
  166. dev_warn(dev,
  167. "%s can't access extended PCI configuration "
  168. "space under this bridge.\n",
  169. estr);
  170. return 0;
  171. }
  172. static int setup_mcfg_map(struct acpi_pci_root_info *ci)
  173. {
  174. int result, seg;
  175. struct pci_root_info *info;
  176. struct acpi_pci_root *root = ci->root;
  177. struct device *dev = &ci->bridge->dev;
  178. info = container_of(ci, struct pci_root_info, common);
  179. info->start_bus = (u8)root->secondary.start;
  180. info->end_bus = (u8)root->secondary.end;
  181. info->mcfg_added = false;
  182. seg = info->sd.domain;
  183. /* return success if MMCFG is not in use */
  184. if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg)
  185. return 0;
  186. if (!(pci_probe & PCI_PROBE_MMCONF))
  187. return check_segment(seg, dev, "MMCONFIG is disabled,");
  188. result = pci_mmconfig_insert(dev, seg, info->start_bus, info->end_bus,
  189. root->mcfg_addr);
  190. if (result == 0) {
  191. /* enable MMCFG if it hasn't been enabled yet */
  192. if (raw_pci_ext_ops == NULL)
  193. raw_pci_ext_ops = &pci_mmcfg;
  194. info->mcfg_added = true;
  195. } else if (result != -EEXIST)
  196. return check_segment(seg, dev,
  197. "fail to add MMCONFIG information,");
  198. return 0;
  199. }
  200. static void teardown_mcfg_map(struct acpi_pci_root_info *ci)
  201. {
  202. struct pci_root_info *info;
  203. info = container_of(ci, struct pci_root_info, common);
  204. if (info->mcfg_added) {
  205. pci_mmconfig_delete(info->sd.domain,
  206. info->start_bus, info->end_bus);
  207. info->mcfg_added = false;
  208. }
  209. }
  210. #else
  211. static int setup_mcfg_map(struct acpi_pci_root_info *ci)
  212. {
  213. return 0;
  214. }
  215. static void teardown_mcfg_map(struct acpi_pci_root_info *ci)
  216. {
  217. }
  218. #endif
  219. static int pci_acpi_root_get_node(struct acpi_pci_root *root)
  220. {
  221. int busnum = root->secondary.start;
  222. struct acpi_device *device = root->device;
  223. int node = acpi_get_node(device->handle);
  224. if (node == NUMA_NO_NODE) {
  225. node = x86_pci_root_bus_node(busnum);
  226. if (node != 0 && node != NUMA_NO_NODE)
  227. dev_info(&device->dev, FW_BUG "no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n",
  228. node);
  229. }
  230. if (node != NUMA_NO_NODE && !node_online(node))
  231. node = NUMA_NO_NODE;
  232. return node;
  233. }
  234. static int pci_acpi_root_init_info(struct acpi_pci_root_info *ci)
  235. {
  236. return setup_mcfg_map(ci);
  237. }
  238. static void pci_acpi_root_release_info(struct acpi_pci_root_info *ci)
  239. {
  240. teardown_mcfg_map(ci);
  241. kfree(container_of(ci, struct pci_root_info, common));
  242. }
  243. /*
  244. * An IO port or MMIO resource assigned to a PCI host bridge may be
  245. * consumed by the host bridge itself or available to its child
  246. * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
  247. * to tell whether the resource is consumed by the host bridge itself,
  248. * but firmware hasn't used that bit consistently, so we can't rely on it.
  249. *
  250. * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
  251. * to be available to child bus/devices except one special case:
  252. * IO port [0xCF8-0xCFF] is consumed by the host bridge itself
  253. * to access PCI configuration space.
  254. *
  255. * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
  256. */
  257. static bool resource_is_pcicfg_ioport(struct resource *res)
  258. {
  259. return (res->flags & IORESOURCE_IO) &&
  260. res->start == 0xCF8 && res->end == 0xCFF;
  261. }
  262. static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
  263. {
  264. struct acpi_device *device = ci->bridge;
  265. int busnum = ci->root->secondary.start;
  266. struct resource_entry *entry, *tmp;
  267. int status;
  268. status = acpi_pci_probe_root_resources(ci);
  269. if (pci_use_crs) {
  270. resource_list_for_each_entry_safe(entry, tmp, &ci->resources)
  271. if (resource_is_pcicfg_ioport(entry->res))
  272. resource_list_destroy_entry(entry);
  273. return status;
  274. }
  275. resource_list_for_each_entry_safe(entry, tmp, &ci->resources) {
  276. dev_printk(KERN_DEBUG, &device->dev,
  277. "host bridge window %pR (ignored)\n", entry->res);
  278. resource_list_destroy_entry(entry);
  279. }
  280. x86_pci_root_bus_resources(busnum, &ci->resources);
  281. return 0;
  282. }
  283. static struct acpi_pci_root_ops acpi_pci_root_ops = {
  284. .pci_ops = &pci_root_ops,
  285. .init_info = pci_acpi_root_init_info,
  286. .release_info = pci_acpi_root_release_info,
  287. .prepare_resources = pci_acpi_root_prepare_resources,
  288. };
  289. struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
  290. {
  291. int domain = root->segment;
  292. int busnum = root->secondary.start;
  293. int node = pci_acpi_root_get_node(root);
  294. struct pci_bus *bus;
  295. if (pci_ignore_seg)
  296. root->segment = domain = 0;
  297. if (domain && !pci_domains_supported) {
  298. printk(KERN_WARNING "pci_bus %04x:%02x: "
  299. "ignored (multiple domains not supported)\n",
  300. domain, busnum);
  301. return NULL;
  302. }
  303. bus = pci_find_bus(domain, busnum);
  304. if (bus) {
  305. /*
  306. * If the desired bus has been scanned already, replace
  307. * its bus->sysdata.
  308. */
  309. struct pci_sysdata sd = {
  310. .domain = domain,
  311. .node = node,
  312. .companion = root->device
  313. };
  314. memcpy(bus->sysdata, &sd, sizeof(sd));
  315. } else {
  316. struct pci_root_info *info;
  317. info = kzalloc_node(sizeof(*info), GFP_KERNEL, node);
  318. if (!info)
  319. dev_err(&root->device->dev,
  320. "pci_bus %04x:%02x: ignored (out of memory)\n",
  321. domain, busnum);
  322. else {
  323. info->sd.domain = domain;
  324. info->sd.node = node;
  325. info->sd.companion = root->device;
  326. bus = acpi_pci_root_create(root, &acpi_pci_root_ops,
  327. &info->common, &info->sd);
  328. }
  329. }
  330. /* After the PCI-E bus has been walked and all devices discovered,
  331. * configure any settings of the fabric that might be necessary.
  332. */
  333. if (bus) {
  334. struct pci_bus *child;
  335. list_for_each_entry(child, &bus->children, node)
  336. pcie_bus_configure_settings(child);
  337. }
  338. return bus;
  339. }
  340. int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
  341. {
  342. /*
  343. * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL
  344. * here, pci_create_root_bus() has been called by someone else and
  345. * sysdata is likely to be different from what we expect. Let it go in
  346. * that case.
  347. */
  348. if (!bridge->dev.parent) {
  349. struct pci_sysdata *sd = bridge->bus->sysdata;
  350. ACPI_COMPANION_SET(&bridge->dev, sd->companion);
  351. }
  352. return 0;
  353. }
  354. int __init pci_acpi_init(void)
  355. {
  356. struct pci_dev *dev = NULL;
  357. if (acpi_noirq)
  358. return -ENODEV;
  359. printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
  360. acpi_irq_penalty_init();
  361. pcibios_enable_irq = acpi_pci_irq_enable;
  362. pcibios_disable_irq = acpi_pci_irq_disable;
  363. x86_init.pci.init_irq = x86_init_noop;
  364. if (pci_routeirq) {
  365. /*
  366. * PCI IRQ routing is set up by pci_enable_device(), but we
  367. * also do it here in case there are still broken drivers that
  368. * don't use pci_enable_device().
  369. */
  370. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  371. for_each_pci_dev(dev)
  372. acpi_pci_irq_enable(dev);
  373. }
  374. return 0;
  375. }