acpi.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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=15362 */
  110. {
  111. .callback = set_ignore_seg,
  112. .ident = "HP xw9300",
  113. .matches = {
  114. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  115. DMI_MATCH(DMI_PRODUCT_NAME, "HP xw9300 Workstation"),
  116. },
  117. },
  118. {}
  119. };
  120. void __init pci_acpi_crs_quirks(void)
  121. {
  122. int year;
  123. if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008) {
  124. if (iomem_resource.end <= 0xffffffff)
  125. pci_use_crs = false;
  126. }
  127. dmi_check_system(pci_crs_quirks);
  128. /*
  129. * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
  130. * takes precedence over anything we figured out above.
  131. */
  132. if (pci_probe & PCI_ROOT_NO_CRS)
  133. pci_use_crs = false;
  134. else if (pci_probe & PCI_USE__CRS)
  135. pci_use_crs = true;
  136. printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
  137. "if necessary, use \"pci=%s\" and report a bug\n",
  138. pci_use_crs ? "Using" : "Ignoring",
  139. pci_use_crs ? "nocrs" : "use_crs");
  140. }
  141. #ifdef CONFIG_PCI_MMCONFIG
  142. static int check_segment(u16 seg, struct device *dev, char *estr)
  143. {
  144. if (seg) {
  145. dev_err(dev,
  146. "%s can't access PCI configuration "
  147. "space under this host bridge.\n",
  148. estr);
  149. return -EIO;
  150. }
  151. /*
  152. * Failure in adding MMCFG information is not fatal,
  153. * just can't access extended configuration space of
  154. * devices under this host bridge.
  155. */
  156. dev_warn(dev,
  157. "%s can't access extended PCI configuration "
  158. "space under this bridge.\n",
  159. estr);
  160. return 0;
  161. }
  162. static int setup_mcfg_map(struct acpi_pci_root_info *ci)
  163. {
  164. int result, seg;
  165. struct pci_root_info *info;
  166. struct acpi_pci_root *root = ci->root;
  167. struct device *dev = &ci->bridge->dev;
  168. info = container_of(ci, struct pci_root_info, common);
  169. info->start_bus = (u8)root->secondary.start;
  170. info->end_bus = (u8)root->secondary.end;
  171. info->mcfg_added = false;
  172. seg = info->sd.domain;
  173. /* return success if MMCFG is not in use */
  174. if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg)
  175. return 0;
  176. if (!(pci_probe & PCI_PROBE_MMCONF))
  177. return check_segment(seg, dev, "MMCONFIG is disabled,");
  178. result = pci_mmconfig_insert(dev, seg, info->start_bus, info->end_bus,
  179. root->mcfg_addr);
  180. if (result == 0) {
  181. /* enable MMCFG if it hasn't been enabled yet */
  182. if (raw_pci_ext_ops == NULL)
  183. raw_pci_ext_ops = &pci_mmcfg;
  184. info->mcfg_added = true;
  185. } else if (result != -EEXIST)
  186. return check_segment(seg, dev,
  187. "fail to add MMCONFIG information,");
  188. return 0;
  189. }
  190. static void teardown_mcfg_map(struct acpi_pci_root_info *ci)
  191. {
  192. struct pci_root_info *info;
  193. info = container_of(ci, struct pci_root_info, common);
  194. if (info->mcfg_added) {
  195. pci_mmconfig_delete(info->sd.domain,
  196. info->start_bus, info->end_bus);
  197. info->mcfg_added = false;
  198. }
  199. }
  200. #else
  201. static int setup_mcfg_map(struct acpi_pci_root_info *ci)
  202. {
  203. return 0;
  204. }
  205. static void teardown_mcfg_map(struct acpi_pci_root_info *ci)
  206. {
  207. }
  208. #endif
  209. static int pci_acpi_root_get_node(struct acpi_pci_root *root)
  210. {
  211. int busnum = root->secondary.start;
  212. struct acpi_device *device = root->device;
  213. int node = acpi_get_node(device->handle);
  214. if (node == NUMA_NO_NODE) {
  215. node = x86_pci_root_bus_node(busnum);
  216. if (node != 0 && node != NUMA_NO_NODE)
  217. dev_info(&device->dev, FW_BUG "no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n",
  218. node);
  219. }
  220. if (node != NUMA_NO_NODE && !node_online(node))
  221. node = NUMA_NO_NODE;
  222. return node;
  223. }
  224. static int pci_acpi_root_init_info(struct acpi_pci_root_info *ci)
  225. {
  226. return setup_mcfg_map(ci);
  227. }
  228. static void pci_acpi_root_release_info(struct acpi_pci_root_info *ci)
  229. {
  230. teardown_mcfg_map(ci);
  231. kfree(container_of(ci, struct pci_root_info, common));
  232. }
  233. /*
  234. * An IO port or MMIO resource assigned to a PCI host bridge may be
  235. * consumed by the host bridge itself or available to its child
  236. * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
  237. * to tell whether the resource is consumed by the host bridge itself,
  238. * but firmware hasn't used that bit consistently, so we can't rely on it.
  239. *
  240. * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
  241. * to be available to child bus/devices except one special case:
  242. * IO port [0xCF8-0xCFF] is consumed by the host bridge itself
  243. * to access PCI configuration space.
  244. *
  245. * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
  246. */
  247. static bool resource_is_pcicfg_ioport(struct resource *res)
  248. {
  249. return (res->flags & IORESOURCE_IO) &&
  250. res->start == 0xCF8 && res->end == 0xCFF;
  251. }
  252. static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
  253. {
  254. struct acpi_device *device = ci->bridge;
  255. int busnum = ci->root->secondary.start;
  256. struct resource_entry *entry, *tmp;
  257. int status;
  258. status = acpi_pci_probe_root_resources(ci);
  259. if (pci_use_crs) {
  260. resource_list_for_each_entry_safe(entry, tmp, &ci->resources)
  261. if (resource_is_pcicfg_ioport(entry->res))
  262. resource_list_destroy_entry(entry);
  263. return status;
  264. }
  265. resource_list_for_each_entry_safe(entry, tmp, &ci->resources) {
  266. dev_printk(KERN_DEBUG, &device->dev,
  267. "host bridge window %pR (ignored)\n", entry->res);
  268. resource_list_destroy_entry(entry);
  269. }
  270. x86_pci_root_bus_resources(busnum, &ci->resources);
  271. return 0;
  272. }
  273. static struct acpi_pci_root_ops acpi_pci_root_ops = {
  274. .pci_ops = &pci_root_ops,
  275. .init_info = pci_acpi_root_init_info,
  276. .release_info = pci_acpi_root_release_info,
  277. .prepare_resources = pci_acpi_root_prepare_resources,
  278. };
  279. struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
  280. {
  281. int domain = root->segment;
  282. int busnum = root->secondary.start;
  283. int node = pci_acpi_root_get_node(root);
  284. struct pci_bus *bus;
  285. if (pci_ignore_seg)
  286. root->segment = domain = 0;
  287. if (domain && !pci_domains_supported) {
  288. printk(KERN_WARNING "pci_bus %04x:%02x: "
  289. "ignored (multiple domains not supported)\n",
  290. domain, busnum);
  291. return NULL;
  292. }
  293. bus = pci_find_bus(domain, busnum);
  294. if (bus) {
  295. /*
  296. * If the desired bus has been scanned already, replace
  297. * its bus->sysdata.
  298. */
  299. struct pci_sysdata sd = {
  300. .domain = domain,
  301. .node = node,
  302. .companion = root->device
  303. };
  304. memcpy(bus->sysdata, &sd, sizeof(sd));
  305. } else {
  306. struct pci_root_info *info;
  307. info = kzalloc_node(sizeof(*info), GFP_KERNEL, node);
  308. if (!info)
  309. dev_err(&root->device->dev,
  310. "pci_bus %04x:%02x: ignored (out of memory)\n",
  311. domain, busnum);
  312. else {
  313. info->sd.domain = domain;
  314. info->sd.node = node;
  315. info->sd.companion = root->device;
  316. bus = acpi_pci_root_create(root, &acpi_pci_root_ops,
  317. &info->common, &info->sd);
  318. }
  319. }
  320. /* After the PCI-E bus has been walked and all devices discovered,
  321. * configure any settings of the fabric that might be necessary.
  322. */
  323. if (bus) {
  324. struct pci_bus *child;
  325. list_for_each_entry(child, &bus->children, node)
  326. pcie_bus_configure_settings(child);
  327. }
  328. return bus;
  329. }
  330. int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
  331. {
  332. /*
  333. * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL
  334. * here, pci_create_root_bus() has been called by someone else and
  335. * sysdata is likely to be different from what we expect. Let it go in
  336. * that case.
  337. */
  338. if (!bridge->dev.parent) {
  339. struct pci_sysdata *sd = bridge->bus->sysdata;
  340. ACPI_COMPANION_SET(&bridge->dev, sd->companion);
  341. }
  342. return 0;
  343. }
  344. int __init pci_acpi_init(void)
  345. {
  346. struct pci_dev *dev = NULL;
  347. if (acpi_noirq)
  348. return -ENODEV;
  349. printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
  350. acpi_irq_penalty_init();
  351. pcibios_enable_irq = acpi_pci_irq_enable;
  352. pcibios_disable_irq = acpi_pci_irq_disable;
  353. x86_init.pci.init_irq = x86_init_noop;
  354. if (pci_routeirq) {
  355. /*
  356. * PCI IRQ routing is set up by pci_enable_device(), but we
  357. * also do it here in case there are still broken drivers that
  358. * don't use pci_enable_device().
  359. */
  360. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  361. for_each_pci_dev(dev)
  362. acpi_pci_irq_enable(dev);
  363. }
  364. return 0;
  365. }