pci_irq.c 12 KB

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