pci_irq.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. * pci_irq.c - ACPI PCI Interrupt Routing ($Revision: 11 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. * Copyright (C) 2002 Dominik Brodowski <devel@brodo.de>
  7. * (c) Copyright 2008 Hewlett-Packard Development Company, L.P.
  8. * Bjorn Helgaas <bjorn.helgaas@hp.com>
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or (at
  15. * your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  25. *
  26. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. */
  28. #include <linux/dmi.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/types.h>
  33. #include <linux/proc_fs.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/pm.h>
  36. #include <linux/pci.h>
  37. #include <linux/acpi.h>
  38. #include <acpi/acpi_bus.h>
  39. #include <acpi/acpi_drivers.h>
  40. #define _COMPONENT ACPI_PCI_COMPONENT
  41. ACPI_MODULE_NAME("pci_irq");
  42. struct acpi_prt_entry {
  43. struct list_head list;
  44. struct acpi_pci_id id;
  45. u8 pin;
  46. acpi_handle link;
  47. u32 index; /* GSI, or link _CRS index */
  48. };
  49. static LIST_HEAD(acpi_prt_list);
  50. static DEFINE_SPINLOCK(acpi_prt_lock);
  51. static inline char pin_name(int pin)
  52. {
  53. return 'A' + pin - 1;
  54. }
  55. /* --------------------------------------------------------------------------
  56. PCI IRQ Routing Table (PRT) Support
  57. -------------------------------------------------------------------------- */
  58. static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev,
  59. int pin)
  60. {
  61. struct acpi_prt_entry *entry;
  62. int segment = pci_domain_nr(dev->bus);
  63. int bus = dev->bus->number;
  64. int device = PCI_SLOT(dev->devfn);
  65. spin_lock(&acpi_prt_lock);
  66. list_for_each_entry(entry, &acpi_prt_list, list) {
  67. if ((segment == entry->id.segment)
  68. && (bus == entry->id.bus)
  69. && (device == entry->id.device)
  70. && (pin == entry->pin)) {
  71. spin_unlock(&acpi_prt_lock);
  72. return entry;
  73. }
  74. }
  75. spin_unlock(&acpi_prt_lock);
  76. return NULL;
  77. }
  78. /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
  79. static const struct dmi_system_id medion_md9580[] = {
  80. {
  81. .ident = "Medion MD9580-F laptop",
  82. .matches = {
  83. DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
  84. DMI_MATCH(DMI_PRODUCT_NAME, "A555"),
  85. },
  86. },
  87. { }
  88. };
  89. /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
  90. static const struct dmi_system_id dell_optiplex[] = {
  91. {
  92. .ident = "Dell Optiplex GX1",
  93. .matches = {
  94. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
  95. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"),
  96. },
  97. },
  98. { }
  99. };
  100. /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
  101. static const struct dmi_system_id hp_t5710[] = {
  102. {
  103. .ident = "HP t5710",
  104. .matches = {
  105. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  106. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"),
  107. DMI_MATCH(DMI_BOARD_NAME, "098Ch"),
  108. },
  109. },
  110. { }
  111. };
  112. struct prt_quirk {
  113. const struct dmi_system_id *system;
  114. unsigned int segment;
  115. unsigned int bus;
  116. unsigned int device;
  117. unsigned char pin;
  118. const char *source; /* according to BIOS */
  119. const char *actual_source;
  120. };
  121. #define PCI_INTX_PIN(c) (c - 'A' + 1)
  122. /*
  123. * These systems have incorrect _PRT entries. The BIOS claims the PCI
  124. * interrupt at the listed segment/bus/device/pin is connected to the first
  125. * link device, but it is actually connected to the second.
  126. */
  127. static const struct prt_quirk prt_quirks[] = {
  128. { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'),
  129. "\\_SB_.PCI0.ISA_.LNKA",
  130. "\\_SB_.PCI0.ISA_.LNKB"},
  131. { dell_optiplex, 0, 0, 0xd, PCI_INTX_PIN('A'),
  132. "\\_SB_.LNKB",
  133. "\\_SB_.LNKA"},
  134. { hp_t5710, 0, 0, 1, PCI_INTX_PIN('A'),
  135. "\\_SB_.PCI0.LNK1",
  136. "\\_SB_.PCI0.LNK3"},
  137. };
  138. static void do_prt_fixups(struct acpi_prt_entry *entry,
  139. struct acpi_pci_routing_table *prt)
  140. {
  141. int i;
  142. const struct prt_quirk *quirk;
  143. for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
  144. quirk = &prt_quirks[i];
  145. /* All current quirks involve link devices, not GSIs */
  146. if (!prt->source)
  147. continue;
  148. if (dmi_check_system(quirk->system) &&
  149. entry->id.segment == quirk->segment &&
  150. entry->id.bus == quirk->bus &&
  151. entry->id.device == quirk->device &&
  152. entry->pin == quirk->pin &&
  153. !strcmp(prt->source, quirk->source) &&
  154. strlen(prt->source) >= strlen(quirk->actual_source)) {
  155. printk(KERN_WARNING PREFIX "firmware reports "
  156. "%04x:%02x:%02x PCI INT %c connected to %s; "
  157. "changing to %s\n",
  158. entry->id.segment, entry->id.bus,
  159. entry->id.device, pin_name(entry->pin),
  160. prt->source, quirk->actual_source);
  161. strcpy(prt->source, quirk->actual_source);
  162. }
  163. }
  164. }
  165. static int acpi_pci_irq_add_entry(acpi_handle handle, struct pci_bus *bus,
  166. struct acpi_pci_routing_table *prt)
  167. {
  168. struct acpi_prt_entry *entry;
  169. entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
  170. if (!entry)
  171. return -ENOMEM;
  172. /*
  173. * Note that the _PRT uses 0=INTA, 1=INTB, etc, while PCI uses
  174. * 1=INTA, 2=INTB. We use the PCI encoding throughout, so convert
  175. * it here.
  176. */
  177. entry->id.segment = pci_domain_nr(bus);
  178. entry->id.bus = bus->number;
  179. entry->id.device = (prt->address >> 16) & 0xFFFF;
  180. entry->pin = prt->pin + 1;
  181. do_prt_fixups(entry, prt);
  182. entry->index = prt->source_index;
  183. /*
  184. * Type 1: Dynamic
  185. * ---------------
  186. * The 'source' field specifies the PCI interrupt link device used to
  187. * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
  188. * indicates which resource descriptor in the resource template (of
  189. * the link device) this interrupt is allocated from.
  190. *
  191. * NOTE: Don't query the Link Device for IRQ information at this time
  192. * because Link Device enumeration may not have occurred yet
  193. * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
  194. * namespace).
  195. */
  196. if (prt->source[0])
  197. acpi_get_handle(handle, prt->source, &entry->link);
  198. /*
  199. * Type 2: Static
  200. * --------------
  201. * The 'source' field is NULL, and the 'source_index' field specifies
  202. * the IRQ value, which is hardwired to specific interrupt inputs on
  203. * the interrupt controller.
  204. */
  205. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
  206. " %04x:%02x:%02x[%c] -> %s[%d]\n",
  207. entry->id.segment, entry->id.bus,
  208. entry->id.device, pin_name(entry->pin),
  209. prt->source, entry->index));
  210. spin_lock(&acpi_prt_lock);
  211. list_add_tail(&entry->list, &acpi_prt_list);
  212. spin_unlock(&acpi_prt_lock);
  213. return 0;
  214. }
  215. int acpi_pci_irq_add_prt(acpi_handle handle, struct pci_bus *bus)
  216. {
  217. acpi_status status;
  218. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  219. struct acpi_pci_routing_table *entry;
  220. /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */
  221. status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  222. if (ACPI_FAILURE(status))
  223. return -ENODEV;
  224. printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
  225. (char *) buffer.pointer);
  226. kfree(buffer.pointer);
  227. buffer.length = ACPI_ALLOCATE_BUFFER;
  228. buffer.pointer = NULL;
  229. status = acpi_get_irq_routing_table(handle, &buffer);
  230. if (ACPI_FAILURE(status)) {
  231. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
  232. acpi_format_exception(status)));
  233. kfree(buffer.pointer);
  234. return -ENODEV;
  235. }
  236. entry = buffer.pointer;
  237. while (entry && (entry->length > 0)) {
  238. acpi_pci_irq_add_entry(handle, bus, entry);
  239. entry = (struct acpi_pci_routing_table *)
  240. ((unsigned long)entry + entry->length);
  241. }
  242. kfree(buffer.pointer);
  243. return 0;
  244. }
  245. void acpi_pci_irq_del_prt(struct pci_bus *bus)
  246. {
  247. struct acpi_prt_entry *entry, *tmp;
  248. printk(KERN_DEBUG
  249. "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
  250. pci_domain_nr(bus), bus->number);
  251. spin_lock(&acpi_prt_lock);
  252. list_for_each_entry_safe(entry, tmp, &acpi_prt_list, list) {
  253. if (pci_domain_nr(bus) == entry->id.segment
  254. && bus->number == entry->id.bus) {
  255. list_del(&entry->list);
  256. kfree(entry);
  257. }
  258. }
  259. spin_unlock(&acpi_prt_lock);
  260. }
  261. /* --------------------------------------------------------------------------
  262. PCI Interrupt Routing Support
  263. -------------------------------------------------------------------------- */
  264. static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
  265. {
  266. struct acpi_prt_entry *entry;
  267. struct pci_dev *bridge;
  268. u8 bridge_pin, orig_pin = pin;
  269. entry = acpi_pci_irq_find_prt_entry(dev, pin);
  270. if (entry) {
  271. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %s[%c] _PRT entry\n",
  272. pci_name(dev), pin_name(pin)));
  273. return entry;
  274. }
  275. /*
  276. * Attempt to derive an IRQ for this device from a parent bridge's
  277. * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
  278. */
  279. bridge = dev->bus->self;
  280. while (bridge) {
  281. pin = pci_swizzle_interrupt_pin(dev, pin);
  282. if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
  283. /* PC card has the same IRQ as its cardbridge */
  284. bridge_pin = bridge->pin;
  285. if (!bridge_pin) {
  286. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  287. "No interrupt pin configured for device %s\n",
  288. pci_name(bridge)));
  289. return NULL;
  290. }
  291. pin = bridge_pin;
  292. }
  293. entry = acpi_pci_irq_find_prt_entry(bridge, pin);
  294. if (entry) {
  295. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  296. "Derived GSI for %s INT %c from %s\n",
  297. pci_name(dev), pin_name(orig_pin),
  298. pci_name(bridge)));
  299. return entry;
  300. }
  301. dev = bridge;
  302. bridge = dev->bus->self;
  303. }
  304. dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n",
  305. pin_name(orig_pin));
  306. return NULL;
  307. }
  308. int acpi_pci_irq_enable(struct pci_dev *dev)
  309. {
  310. struct acpi_prt_entry *entry;
  311. int gsi;
  312. u8 pin;
  313. int triggering = ACPI_LEVEL_SENSITIVE;
  314. int polarity = ACPI_ACTIVE_LOW;
  315. char *link = NULL;
  316. char link_desc[16];
  317. int rc;
  318. pin = dev->pin;
  319. if (!pin) {
  320. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  321. "No interrupt pin configured for device %s\n",
  322. pci_name(dev)));
  323. return 0;
  324. }
  325. entry = acpi_pci_irq_lookup(dev, pin);
  326. if (!entry) {
  327. /*
  328. * IDE legacy mode controller IRQs are magic. Why do compat
  329. * extensions always make such a nasty mess.
  330. */
  331. if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
  332. (dev->class & 0x05) == 0)
  333. return 0;
  334. }
  335. if (entry) {
  336. if (entry->link)
  337. gsi = acpi_pci_link_allocate_irq(entry->link,
  338. entry->index,
  339. &triggering, &polarity,
  340. &link);
  341. else
  342. gsi = entry->index;
  343. } else
  344. gsi = -1;
  345. /*
  346. * No IRQ known to the ACPI subsystem - maybe the BIOS /
  347. * driver reported one, then use it. Exit in any case.
  348. */
  349. if (gsi < 0) {
  350. dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin));
  351. /* Interrupt Line values above 0xF are forbidden */
  352. if (dev->irq > 0 && (dev->irq <= 0xF)) {
  353. printk(" - using IRQ %d\n", dev->irq);
  354. acpi_register_gsi(&dev->dev, dev->irq,
  355. ACPI_LEVEL_SENSITIVE,
  356. ACPI_ACTIVE_LOW);
  357. return 0;
  358. } else {
  359. printk("\n");
  360. return 0;
  361. }
  362. }
  363. rc = acpi_register_gsi(&dev->dev, gsi, triggering, polarity);
  364. if (rc < 0) {
  365. dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n",
  366. pin_name(pin));
  367. return rc;
  368. }
  369. dev->irq = rc;
  370. if (link)
  371. snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link);
  372. else
  373. link_desc[0] = '\0';
  374. dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n",
  375. pin_name(pin), link_desc, gsi,
  376. (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
  377. (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
  378. return 0;
  379. }
  380. /* FIXME: implement x86/x86_64 version */
  381. void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
  382. {
  383. }
  384. void acpi_pci_irq_disable(struct pci_dev *dev)
  385. {
  386. struct acpi_prt_entry *entry;
  387. int gsi;
  388. u8 pin;
  389. pin = dev->pin;
  390. if (!pin)
  391. return;
  392. entry = acpi_pci_irq_lookup(dev, pin);
  393. if (!entry)
  394. return;
  395. if (entry->link)
  396. gsi = acpi_pci_link_free_irq(entry->link);
  397. else
  398. gsi = entry->index;
  399. /*
  400. * TBD: It might be worth clearing dev->irq by magic constant
  401. * (e.g. PCI_UNDEFINED_IRQ).
  402. */
  403. dev_info(&dev->dev, "PCI INT %c disabled\n", pin_name(pin));
  404. acpi_unregister_gsi(gsi);
  405. }