irq.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Low-Level PCI Support for PC -- Routing of Interrupts
  4. *
  5. * (c) 1999--2000 Martin Mares <mj@ucw.cz>
  6. */
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/pci.h>
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/dmi.h>
  13. #include <linux/io.h>
  14. #include <linux/smp.h>
  15. #include <asm/io_apic.h>
  16. #include <linux/irq.h>
  17. #include <linux/acpi.h>
  18. #include <asm/pci_x86.h>
  19. #define PIRQ_SIGNATURE (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))
  20. #define PIRQ_VERSION 0x0100
  21. static int broken_hp_bios_irq9;
  22. static int acer_tm360_irqrouting;
  23. static struct irq_routing_table *pirq_table;
  24. static int pirq_enable_irq(struct pci_dev *dev);
  25. static void pirq_disable_irq(struct pci_dev *dev);
  26. /*
  27. * Never use: 0, 1, 2 (timer, keyboard, and cascade)
  28. * Avoid using: 13, 14 and 15 (FP error and IDE).
  29. * Penalize: 3, 4, 6, 7, 12 (known ISA uses: serial, floppy, parallel and mouse)
  30. */
  31. unsigned int pcibios_irq_mask = 0xfff8;
  32. static int pirq_penalty[16] = {
  33. 1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000,
  34. 0, 0, 0, 0, 1000, 100000, 100000, 100000
  35. };
  36. struct irq_router {
  37. char *name;
  38. u16 vendor, device;
  39. int (*get)(struct pci_dev *router, struct pci_dev *dev, int pirq);
  40. int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq,
  41. int new);
  42. };
  43. struct irq_router_handler {
  44. u16 vendor;
  45. int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
  46. };
  47. int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
  48. void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
  49. /*
  50. * Check passed address for the PCI IRQ Routing Table signature
  51. * and perform checksum verification.
  52. */
  53. static inline struct irq_routing_table *pirq_check_routing_table(u8 *addr)
  54. {
  55. struct irq_routing_table *rt;
  56. int i;
  57. u8 sum;
  58. rt = (struct irq_routing_table *) addr;
  59. if (rt->signature != PIRQ_SIGNATURE ||
  60. rt->version != PIRQ_VERSION ||
  61. rt->size % 16 ||
  62. rt->size < sizeof(struct irq_routing_table))
  63. return NULL;
  64. sum = 0;
  65. for (i = 0; i < rt->size; i++)
  66. sum += addr[i];
  67. if (!sum) {
  68. DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%p\n",
  69. rt);
  70. return rt;
  71. }
  72. return NULL;
  73. }
  74. /*
  75. * Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table.
  76. */
  77. static struct irq_routing_table * __init pirq_find_routing_table(void)
  78. {
  79. u8 *addr;
  80. struct irq_routing_table *rt;
  81. if (pirq_table_addr) {
  82. rt = pirq_check_routing_table((u8 *) __va(pirq_table_addr));
  83. if (rt)
  84. return rt;
  85. printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n");
  86. }
  87. for (addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) {
  88. rt = pirq_check_routing_table(addr);
  89. if (rt)
  90. return rt;
  91. }
  92. return NULL;
  93. }
  94. /*
  95. * If we have a IRQ routing table, use it to search for peer host
  96. * bridges. It's a gross hack, but since there are no other known
  97. * ways how to get a list of buses, we have to go this way.
  98. */
  99. static void __init pirq_peer_trick(void)
  100. {
  101. struct irq_routing_table *rt = pirq_table;
  102. u8 busmap[256];
  103. int i;
  104. struct irq_info *e;
  105. memset(busmap, 0, sizeof(busmap));
  106. for (i = 0; i < (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); i++) {
  107. e = &rt->slots[i];
  108. #ifdef DEBUG
  109. {
  110. int j;
  111. DBG(KERN_DEBUG "%02x:%02x slot=%02x", e->bus, e->devfn/8, e->slot);
  112. for (j = 0; j < 4; j++)
  113. DBG(" %d:%02x/%04x", j, e->irq[j].link, e->irq[j].bitmap);
  114. DBG("\n");
  115. }
  116. #endif
  117. busmap[e->bus] = 1;
  118. }
  119. for (i = 1; i < 256; i++) {
  120. if (!busmap[i] || pci_find_bus(0, i))
  121. continue;
  122. pcibios_scan_root(i);
  123. }
  124. pcibios_last_bus = -1;
  125. }
  126. /*
  127. * Code for querying and setting of IRQ routes on various interrupt routers.
  128. * PIC Edge/Level Control Registers (ELCR) 0x4d0 & 0x4d1.
  129. */
  130. void elcr_set_level_irq(unsigned int irq)
  131. {
  132. unsigned char mask = 1 << (irq & 7);
  133. unsigned int port = 0x4d0 + (irq >> 3);
  134. unsigned char val;
  135. static u16 elcr_irq_mask;
  136. if (irq >= 16 || (1 << irq) & elcr_irq_mask)
  137. return;
  138. elcr_irq_mask |= (1 << irq);
  139. printk(KERN_DEBUG "PCI: setting IRQ %u as level-triggered\n", irq);
  140. val = inb(port);
  141. if (!(val & mask)) {
  142. DBG(KERN_DEBUG " -> edge");
  143. outb(val | mask, port);
  144. }
  145. }
  146. /*
  147. * Common IRQ routing practice: nibbles in config space,
  148. * offset by some magic constant.
  149. */
  150. static unsigned int read_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr)
  151. {
  152. u8 x;
  153. unsigned reg = offset + (nr >> 1);
  154. pci_read_config_byte(router, reg, &x);
  155. return (nr & 1) ? (x >> 4) : (x & 0xf);
  156. }
  157. static void write_config_nybble(struct pci_dev *router, unsigned offset,
  158. unsigned nr, unsigned int val)
  159. {
  160. u8 x;
  161. unsigned reg = offset + (nr >> 1);
  162. pci_read_config_byte(router, reg, &x);
  163. x = (nr & 1) ? ((x & 0x0f) | (val << 4)) : ((x & 0xf0) | val);
  164. pci_write_config_byte(router, reg, x);
  165. }
  166. /*
  167. * ALI pirq entries are damn ugly, and completely undocumented.
  168. * This has been figured out from pirq tables, and it's not a pretty
  169. * picture.
  170. */
  171. static int pirq_ali_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  172. {
  173. static const unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };
  174. WARN_ON_ONCE(pirq > 16);
  175. return irqmap[read_config_nybble(router, 0x48, pirq-1)];
  176. }
  177. static int pirq_ali_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  178. {
  179. static const unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };
  180. unsigned int val = irqmap[irq];
  181. WARN_ON_ONCE(pirq > 16);
  182. if (val) {
  183. write_config_nybble(router, 0x48, pirq-1, val);
  184. return 1;
  185. }
  186. return 0;
  187. }
  188. /*
  189. * The Intel PIIX4 pirq rules are fairly simple: "pirq" is
  190. * just a pointer to the config space.
  191. */
  192. static int pirq_piix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  193. {
  194. u8 x;
  195. pci_read_config_byte(router, pirq, &x);
  196. return (x < 16) ? x : 0;
  197. }
  198. static int pirq_piix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  199. {
  200. pci_write_config_byte(router, pirq, irq);
  201. return 1;
  202. }
  203. /*
  204. * The VIA pirq rules are nibble-based, like ALI,
  205. * but without the ugly irq number munging.
  206. * However, PIRQD is in the upper instead of lower 4 bits.
  207. */
  208. static int pirq_via_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  209. {
  210. return read_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq);
  211. }
  212. static int pirq_via_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  213. {
  214. write_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq, irq);
  215. return 1;
  216. }
  217. /*
  218. * The VIA pirq rules are nibble-based, like ALI,
  219. * but without the ugly irq number munging.
  220. * However, for 82C586, nibble map is different .
  221. */
  222. static int pirq_via586_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  223. {
  224. static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
  225. WARN_ON_ONCE(pirq > 5);
  226. return read_config_nybble(router, 0x55, pirqmap[pirq-1]);
  227. }
  228. static int pirq_via586_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  229. {
  230. static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
  231. WARN_ON_ONCE(pirq > 5);
  232. write_config_nybble(router, 0x55, pirqmap[pirq-1], irq);
  233. return 1;
  234. }
  235. /*
  236. * ITE 8330G pirq rules are nibble-based
  237. * FIXME: pirqmap may be { 1, 0, 3, 2 },
  238. * 2+3 are both mapped to irq 9 on my system
  239. */
  240. static int pirq_ite_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  241. {
  242. static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
  243. WARN_ON_ONCE(pirq > 4);
  244. return read_config_nybble(router, 0x43, pirqmap[pirq-1]);
  245. }
  246. static int pirq_ite_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  247. {
  248. static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
  249. WARN_ON_ONCE(pirq > 4);
  250. write_config_nybble(router, 0x43, pirqmap[pirq-1], irq);
  251. return 1;
  252. }
  253. /*
  254. * OPTI: high four bits are nibble pointer..
  255. * I wonder what the low bits do?
  256. */
  257. static int pirq_opti_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  258. {
  259. return read_config_nybble(router, 0xb8, pirq >> 4);
  260. }
  261. static int pirq_opti_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  262. {
  263. write_config_nybble(router, 0xb8, pirq >> 4, irq);
  264. return 1;
  265. }
  266. /*
  267. * Cyrix: nibble offset 0x5C
  268. * 0x5C bits 7:4 is INTB bits 3:0 is INTA
  269. * 0x5D bits 7:4 is INTD bits 3:0 is INTC
  270. */
  271. static int pirq_cyrix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  272. {
  273. return read_config_nybble(router, 0x5C, (pirq-1)^1);
  274. }
  275. static int pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  276. {
  277. write_config_nybble(router, 0x5C, (pirq-1)^1, irq);
  278. return 1;
  279. }
  280. /*
  281. * PIRQ routing for SiS 85C503 router used in several SiS chipsets.
  282. * We have to deal with the following issues here:
  283. * - vendors have different ideas about the meaning of link values
  284. * - some onboard devices (integrated in the chipset) have special
  285. * links and are thus routed differently (i.e. not via PCI INTA-INTD)
  286. * - different revision of the router have a different layout for
  287. * the routing registers, particularly for the onchip devices
  288. *
  289. * For all routing registers the common thing is we have one byte
  290. * per routeable link which is defined as:
  291. * bit 7 IRQ mapping enabled (0) or disabled (1)
  292. * bits [6:4] reserved (sometimes used for onchip devices)
  293. * bits [3:0] IRQ to map to
  294. * allowed: 3-7, 9-12, 14-15
  295. * reserved: 0, 1, 2, 8, 13
  296. *
  297. * The config-space registers located at 0x41/0x42/0x43/0x44 are
  298. * always used to route the normal PCI INT A/B/C/D respectively.
  299. * Apparently there are systems implementing PCI routing table using
  300. * link values 0x01-0x04 and others using 0x41-0x44 for PCI INTA..D.
  301. * We try our best to handle both link mappings.
  302. *
  303. * Currently (2003-05-21) it appears most SiS chipsets follow the
  304. * definition of routing registers from the SiS-5595 southbridge.
  305. * According to the SiS 5595 datasheets the revision id's of the
  306. * router (ISA-bridge) should be 0x01 or 0xb0.
  307. *
  308. * Furthermore we've also seen lspci dumps with revision 0x00 and 0xb1.
  309. * Looks like these are used in a number of SiS 5xx/6xx/7xx chipsets.
  310. * They seem to work with the current routing code. However there is
  311. * some concern because of the two USB-OHCI HCs (original SiS 5595
  312. * had only one). YMMV.
  313. *
  314. * Onchip routing for router rev-id 0x01/0xb0 and probably 0x00/0xb1:
  315. *
  316. * 0x61: IDEIRQ:
  317. * bits [6:5] must be written 01
  318. * bit 4 channel-select primary (0), secondary (1)
  319. *
  320. * 0x62: USBIRQ:
  321. * bit 6 OHCI function disabled (0), enabled (1)
  322. *
  323. * 0x6a: ACPI/SCI IRQ: bits 4-6 reserved
  324. *
  325. * 0x7e: Data Acq. Module IRQ - bits 4-6 reserved
  326. *
  327. * We support USBIRQ (in addition to INTA-INTD) and keep the
  328. * IDE, ACPI and DAQ routing untouched as set by the BIOS.
  329. *
  330. * Currently the only reported exception is the new SiS 65x chipset
  331. * which includes the SiS 69x southbridge. Here we have the 85C503
  332. * router revision 0x04 and there are changes in the register layout
  333. * mostly related to the different USB HCs with USB 2.0 support.
  334. *
  335. * Onchip routing for router rev-id 0x04 (try-and-error observation)
  336. *
  337. * 0x60/0x61/0x62/0x63: 1xEHCI and 3xOHCI (companion) USB-HCs
  338. * bit 6-4 are probably unused, not like 5595
  339. */
  340. #define PIRQ_SIS_IRQ_MASK 0x0f
  341. #define PIRQ_SIS_IRQ_DISABLE 0x80
  342. #define PIRQ_SIS_USB_ENABLE 0x40
  343. static int pirq_sis_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  344. {
  345. u8 x;
  346. int reg;
  347. reg = pirq;
  348. if (reg >= 0x01 && reg <= 0x04)
  349. reg += 0x40;
  350. pci_read_config_byte(router, reg, &x);
  351. return (x & PIRQ_SIS_IRQ_DISABLE) ? 0 : (x & PIRQ_SIS_IRQ_MASK);
  352. }
  353. static int pirq_sis_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  354. {
  355. u8 x;
  356. int reg;
  357. reg = pirq;
  358. if (reg >= 0x01 && reg <= 0x04)
  359. reg += 0x40;
  360. pci_read_config_byte(router, reg, &x);
  361. x &= ~(PIRQ_SIS_IRQ_MASK | PIRQ_SIS_IRQ_DISABLE);
  362. x |= irq ? irq: PIRQ_SIS_IRQ_DISABLE;
  363. pci_write_config_byte(router, reg, x);
  364. return 1;
  365. }
  366. /*
  367. * VLSI: nibble offset 0x74 - educated guess due to routing table and
  368. * config space of VLSI 82C534 PCI-bridge/router (1004:0102)
  369. * Tested on HP OmniBook 800 covering PIRQ 1, 2, 4, 8 for onboard
  370. * devices, PIRQ 3 for non-pci(!) soundchip and (untested) PIRQ 6
  371. * for the busbridge to the docking station.
  372. */
  373. static int pirq_vlsi_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  374. {
  375. WARN_ON_ONCE(pirq >= 9);
  376. if (pirq > 8) {
  377. dev_info(&dev->dev, "VLSI router PIRQ escape (%d)\n", pirq);
  378. return 0;
  379. }
  380. return read_config_nybble(router, 0x74, pirq-1);
  381. }
  382. static int pirq_vlsi_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  383. {
  384. WARN_ON_ONCE(pirq >= 9);
  385. if (pirq > 8) {
  386. dev_info(&dev->dev, "VLSI router PIRQ escape (%d)\n", pirq);
  387. return 0;
  388. }
  389. write_config_nybble(router, 0x74, pirq-1, irq);
  390. return 1;
  391. }
  392. /*
  393. * ServerWorks: PCI interrupts mapped to system IRQ lines through Index
  394. * and Redirect I/O registers (0x0c00 and 0x0c01). The Index register
  395. * format is (PCIIRQ## | 0x10), e.g.: PCIIRQ10=0x1a. The Redirect
  396. * register is a straight binary coding of desired PIC IRQ (low nibble).
  397. *
  398. * The 'link' value in the PIRQ table is already in the correct format
  399. * for the Index register. There are some special index values:
  400. * 0x00 for ACPI (SCI), 0x01 for USB, 0x02 for IDE0, 0x04 for IDE1,
  401. * and 0x03 for SMBus.
  402. */
  403. static int pirq_serverworks_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  404. {
  405. outb(pirq, 0xc00);
  406. return inb(0xc01) & 0xf;
  407. }
  408. static int pirq_serverworks_set(struct pci_dev *router, struct pci_dev *dev,
  409. int pirq, int irq)
  410. {
  411. outb(pirq, 0xc00);
  412. outb(irq, 0xc01);
  413. return 1;
  414. }
  415. /* Support for AMD756 PCI IRQ Routing
  416. * Jhon H. Caicedo <jhcaiced@osso.org.co>
  417. * Jun/21/2001 0.2.0 Release, fixed to use "nybble" functions... (jhcaiced)
  418. * Jun/19/2001 Alpha Release 0.1.0 (jhcaiced)
  419. * The AMD756 pirq rules are nibble-based
  420. * offset 0x56 0-3 PIRQA 4-7 PIRQB
  421. * offset 0x57 0-3 PIRQC 4-7 PIRQD
  422. */
  423. static int pirq_amd756_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  424. {
  425. u8 irq;
  426. irq = 0;
  427. if (pirq <= 4)
  428. irq = read_config_nybble(router, 0x56, pirq - 1);
  429. dev_info(&dev->dev,
  430. "AMD756: dev [%04x:%04x], router PIRQ %d get IRQ %d\n",
  431. dev->vendor, dev->device, pirq, irq);
  432. return irq;
  433. }
  434. static int pirq_amd756_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  435. {
  436. dev_info(&dev->dev,
  437. "AMD756: dev [%04x:%04x], router PIRQ %d set IRQ %d\n",
  438. dev->vendor, dev->device, pirq, irq);
  439. if (pirq <= 4)
  440. write_config_nybble(router, 0x56, pirq - 1, irq);
  441. return 1;
  442. }
  443. /*
  444. * PicoPower PT86C523
  445. */
  446. static int pirq_pico_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  447. {
  448. outb(0x10 + ((pirq - 1) >> 1), 0x24);
  449. return ((pirq - 1) & 1) ? (inb(0x26) >> 4) : (inb(0x26) & 0xf);
  450. }
  451. static int pirq_pico_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
  452. int irq)
  453. {
  454. unsigned int x;
  455. outb(0x10 + ((pirq - 1) >> 1), 0x24);
  456. x = inb(0x26);
  457. x = ((pirq - 1) & 1) ? ((x & 0x0f) | (irq << 4)) : ((x & 0xf0) | (irq));
  458. outb(x, 0x26);
  459. return 1;
  460. }
  461. #ifdef CONFIG_PCI_BIOS
  462. static int pirq_bios_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  463. {
  464. struct pci_dev *bridge;
  465. int pin = pci_get_interrupt_pin(dev, &bridge);
  466. return pcibios_set_irq_routing(bridge, pin - 1, irq);
  467. }
  468. #endif
  469. static __init int intel_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  470. {
  471. static struct pci_device_id __initdata pirq_440gx[] = {
  472. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
  473. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
  474. { },
  475. };
  476. /* 440GX has a proprietary PIRQ router -- don't use it */
  477. if (pci_dev_present(pirq_440gx))
  478. return 0;
  479. switch (device) {
  480. case PCI_DEVICE_ID_INTEL_82371FB_0:
  481. case PCI_DEVICE_ID_INTEL_82371SB_0:
  482. case PCI_DEVICE_ID_INTEL_82371AB_0:
  483. case PCI_DEVICE_ID_INTEL_82371MX:
  484. case PCI_DEVICE_ID_INTEL_82443MX_0:
  485. case PCI_DEVICE_ID_INTEL_82801AA_0:
  486. case PCI_DEVICE_ID_INTEL_82801AB_0:
  487. case PCI_DEVICE_ID_INTEL_82801BA_0:
  488. case PCI_DEVICE_ID_INTEL_82801BA_10:
  489. case PCI_DEVICE_ID_INTEL_82801CA_0:
  490. case PCI_DEVICE_ID_INTEL_82801CA_12:
  491. case PCI_DEVICE_ID_INTEL_82801DB_0:
  492. case PCI_DEVICE_ID_INTEL_82801E_0:
  493. case PCI_DEVICE_ID_INTEL_82801EB_0:
  494. case PCI_DEVICE_ID_INTEL_ESB_1:
  495. case PCI_DEVICE_ID_INTEL_ICH6_0:
  496. case PCI_DEVICE_ID_INTEL_ICH6_1:
  497. case PCI_DEVICE_ID_INTEL_ICH7_0:
  498. case PCI_DEVICE_ID_INTEL_ICH7_1:
  499. case PCI_DEVICE_ID_INTEL_ICH7_30:
  500. case PCI_DEVICE_ID_INTEL_ICH7_31:
  501. case PCI_DEVICE_ID_INTEL_TGP_LPC:
  502. case PCI_DEVICE_ID_INTEL_ESB2_0:
  503. case PCI_DEVICE_ID_INTEL_ICH8_0:
  504. case PCI_DEVICE_ID_INTEL_ICH8_1:
  505. case PCI_DEVICE_ID_INTEL_ICH8_2:
  506. case PCI_DEVICE_ID_INTEL_ICH8_3:
  507. case PCI_DEVICE_ID_INTEL_ICH8_4:
  508. case PCI_DEVICE_ID_INTEL_ICH9_0:
  509. case PCI_DEVICE_ID_INTEL_ICH9_1:
  510. case PCI_DEVICE_ID_INTEL_ICH9_2:
  511. case PCI_DEVICE_ID_INTEL_ICH9_3:
  512. case PCI_DEVICE_ID_INTEL_ICH9_4:
  513. case PCI_DEVICE_ID_INTEL_ICH9_5:
  514. case PCI_DEVICE_ID_INTEL_EP80579_0:
  515. case PCI_DEVICE_ID_INTEL_ICH10_0:
  516. case PCI_DEVICE_ID_INTEL_ICH10_1:
  517. case PCI_DEVICE_ID_INTEL_ICH10_2:
  518. case PCI_DEVICE_ID_INTEL_ICH10_3:
  519. case PCI_DEVICE_ID_INTEL_PATSBURG_LPC_0:
  520. case PCI_DEVICE_ID_INTEL_PATSBURG_LPC_1:
  521. r->name = "PIIX/ICH";
  522. r->get = pirq_piix_get;
  523. r->set = pirq_piix_set;
  524. return 1;
  525. }
  526. if ((device >= PCI_DEVICE_ID_INTEL_5_3400_SERIES_LPC_MIN &&
  527. device <= PCI_DEVICE_ID_INTEL_5_3400_SERIES_LPC_MAX)
  528. || (device >= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MIN &&
  529. device <= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MAX)
  530. || (device >= PCI_DEVICE_ID_INTEL_DH89XXCC_LPC_MIN &&
  531. device <= PCI_DEVICE_ID_INTEL_DH89XXCC_LPC_MAX)
  532. || (device >= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MIN &&
  533. device <= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MAX)) {
  534. r->name = "PIIX/ICH";
  535. r->get = pirq_piix_get;
  536. r->set = pirq_piix_set;
  537. return 1;
  538. }
  539. return 0;
  540. }
  541. static __init int via_router_probe(struct irq_router *r,
  542. struct pci_dev *router, u16 device)
  543. {
  544. /* FIXME: We should move some of the quirk fixup stuff here */
  545. /*
  546. * workarounds for some buggy BIOSes
  547. */
  548. if (device == PCI_DEVICE_ID_VIA_82C586_0) {
  549. switch (router->device) {
  550. case PCI_DEVICE_ID_VIA_82C686:
  551. /*
  552. * Asus k7m bios wrongly reports 82C686A
  553. * as 586-compatible
  554. */
  555. device = PCI_DEVICE_ID_VIA_82C686;
  556. break;
  557. case PCI_DEVICE_ID_VIA_8235:
  558. /**
  559. * Asus a7v-x bios wrongly reports 8235
  560. * as 586-compatible
  561. */
  562. device = PCI_DEVICE_ID_VIA_8235;
  563. break;
  564. case PCI_DEVICE_ID_VIA_8237:
  565. /**
  566. * Asus a7v600 bios wrongly reports 8237
  567. * as 586-compatible
  568. */
  569. device = PCI_DEVICE_ID_VIA_8237;
  570. break;
  571. }
  572. }
  573. switch (device) {
  574. case PCI_DEVICE_ID_VIA_82C586_0:
  575. r->name = "VIA";
  576. r->get = pirq_via586_get;
  577. r->set = pirq_via586_set;
  578. return 1;
  579. case PCI_DEVICE_ID_VIA_82C596:
  580. case PCI_DEVICE_ID_VIA_82C686:
  581. case PCI_DEVICE_ID_VIA_8231:
  582. case PCI_DEVICE_ID_VIA_8233A:
  583. case PCI_DEVICE_ID_VIA_8235:
  584. case PCI_DEVICE_ID_VIA_8237:
  585. /* FIXME: add new ones for 8233/5 */
  586. r->name = "VIA";
  587. r->get = pirq_via_get;
  588. r->set = pirq_via_set;
  589. return 1;
  590. }
  591. return 0;
  592. }
  593. static __init int vlsi_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  594. {
  595. switch (device) {
  596. case PCI_DEVICE_ID_VLSI_82C534:
  597. r->name = "VLSI 82C534";
  598. r->get = pirq_vlsi_get;
  599. r->set = pirq_vlsi_set;
  600. return 1;
  601. }
  602. return 0;
  603. }
  604. static __init int serverworks_router_probe(struct irq_router *r,
  605. struct pci_dev *router, u16 device)
  606. {
  607. switch (device) {
  608. case PCI_DEVICE_ID_SERVERWORKS_OSB4:
  609. case PCI_DEVICE_ID_SERVERWORKS_CSB5:
  610. r->name = "ServerWorks";
  611. r->get = pirq_serverworks_get;
  612. r->set = pirq_serverworks_set;
  613. return 1;
  614. }
  615. return 0;
  616. }
  617. static __init int sis_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  618. {
  619. if (device != PCI_DEVICE_ID_SI_503)
  620. return 0;
  621. r->name = "SIS";
  622. r->get = pirq_sis_get;
  623. r->set = pirq_sis_set;
  624. return 1;
  625. }
  626. static __init int cyrix_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  627. {
  628. switch (device) {
  629. case PCI_DEVICE_ID_CYRIX_5520:
  630. r->name = "NatSemi";
  631. r->get = pirq_cyrix_get;
  632. r->set = pirq_cyrix_set;
  633. return 1;
  634. }
  635. return 0;
  636. }
  637. static __init int opti_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  638. {
  639. switch (device) {
  640. case PCI_DEVICE_ID_OPTI_82C700:
  641. r->name = "OPTI";
  642. r->get = pirq_opti_get;
  643. r->set = pirq_opti_set;
  644. return 1;
  645. }
  646. return 0;
  647. }
  648. static __init int ite_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  649. {
  650. switch (device) {
  651. case PCI_DEVICE_ID_ITE_IT8330G_0:
  652. r->name = "ITE";
  653. r->get = pirq_ite_get;
  654. r->set = pirq_ite_set;
  655. return 1;
  656. }
  657. return 0;
  658. }
  659. static __init int ali_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  660. {
  661. switch (device) {
  662. case PCI_DEVICE_ID_AL_M1533:
  663. case PCI_DEVICE_ID_AL_M1563:
  664. r->name = "ALI";
  665. r->get = pirq_ali_get;
  666. r->set = pirq_ali_set;
  667. return 1;
  668. }
  669. return 0;
  670. }
  671. static __init int amd_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  672. {
  673. switch (device) {
  674. case PCI_DEVICE_ID_AMD_VIPER_740B:
  675. r->name = "AMD756";
  676. break;
  677. case PCI_DEVICE_ID_AMD_VIPER_7413:
  678. r->name = "AMD766";
  679. break;
  680. case PCI_DEVICE_ID_AMD_VIPER_7443:
  681. r->name = "AMD768";
  682. break;
  683. default:
  684. return 0;
  685. }
  686. r->get = pirq_amd756_get;
  687. r->set = pirq_amd756_set;
  688. return 1;
  689. }
  690. static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  691. {
  692. switch (device) {
  693. case PCI_DEVICE_ID_PICOPOWER_PT86C523:
  694. r->name = "PicoPower PT86C523";
  695. r->get = pirq_pico_get;
  696. r->set = pirq_pico_set;
  697. return 1;
  698. case PCI_DEVICE_ID_PICOPOWER_PT86C523BBP:
  699. r->name = "PicoPower PT86C523 rev. BB+";
  700. r->get = pirq_pico_get;
  701. r->set = pirq_pico_set;
  702. return 1;
  703. }
  704. return 0;
  705. }
  706. static __initdata struct irq_router_handler pirq_routers[] = {
  707. { PCI_VENDOR_ID_INTEL, intel_router_probe },
  708. { PCI_VENDOR_ID_AL, ali_router_probe },
  709. { PCI_VENDOR_ID_ITE, ite_router_probe },
  710. { PCI_VENDOR_ID_VIA, via_router_probe },
  711. { PCI_VENDOR_ID_OPTI, opti_router_probe },
  712. { PCI_VENDOR_ID_SI, sis_router_probe },
  713. { PCI_VENDOR_ID_CYRIX, cyrix_router_probe },
  714. { PCI_VENDOR_ID_VLSI, vlsi_router_probe },
  715. { PCI_VENDOR_ID_SERVERWORKS, serverworks_router_probe },
  716. { PCI_VENDOR_ID_AMD, amd_router_probe },
  717. { PCI_VENDOR_ID_PICOPOWER, pico_router_probe },
  718. /* Someone with docs needs to add the ATI Radeon IGP */
  719. { 0, NULL }
  720. };
  721. static struct irq_router pirq_router;
  722. static struct pci_dev *pirq_router_dev;
  723. /*
  724. * FIXME: should we have an option to say "generic for
  725. * chipset" ?
  726. */
  727. static void __init pirq_find_router(struct irq_router *r)
  728. {
  729. struct irq_routing_table *rt = pirq_table;
  730. struct irq_router_handler *h;
  731. #ifdef CONFIG_PCI_BIOS
  732. if (!rt->signature) {
  733. printk(KERN_INFO "PCI: Using BIOS for IRQ routing\n");
  734. r->set = pirq_bios_set;
  735. r->name = "BIOS";
  736. return;
  737. }
  738. #endif
  739. /* Default unless a driver reloads it */
  740. r->name = "default";
  741. r->get = NULL;
  742. r->set = NULL;
  743. DBG(KERN_DEBUG "PCI: Attempting to find IRQ router for [%04x:%04x]\n",
  744. rt->rtr_vendor, rt->rtr_device);
  745. pirq_router_dev = pci_get_domain_bus_and_slot(0, rt->rtr_bus,
  746. rt->rtr_devfn);
  747. if (!pirq_router_dev) {
  748. DBG(KERN_DEBUG "PCI: Interrupt router not found at "
  749. "%02x:%02x\n", rt->rtr_bus, rt->rtr_devfn);
  750. return;
  751. }
  752. for (h = pirq_routers; h->vendor; h++) {
  753. /* First look for a router match */
  754. if (rt->rtr_vendor == h->vendor &&
  755. h->probe(r, pirq_router_dev, rt->rtr_device))
  756. break;
  757. /* Fall back to a device match */
  758. if (pirq_router_dev->vendor == h->vendor &&
  759. h->probe(r, pirq_router_dev, pirq_router_dev->device))
  760. break;
  761. }
  762. dev_info(&pirq_router_dev->dev, "%s IRQ router [%04x:%04x]\n",
  763. pirq_router.name,
  764. pirq_router_dev->vendor, pirq_router_dev->device);
  765. /* The device remains referenced for the kernel lifetime */
  766. }
  767. static struct irq_info *pirq_get_info(struct pci_dev *dev)
  768. {
  769. struct irq_routing_table *rt = pirq_table;
  770. int entries = (rt->size - sizeof(struct irq_routing_table)) /
  771. sizeof(struct irq_info);
  772. struct irq_info *info;
  773. for (info = rt->slots; entries--; info++)
  774. if (info->bus == dev->bus->number &&
  775. PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn))
  776. return info;
  777. return NULL;
  778. }
  779. static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
  780. {
  781. u8 pin;
  782. struct irq_info *info;
  783. int i, pirq, newirq;
  784. int irq = 0;
  785. u32 mask;
  786. struct irq_router *r = &pirq_router;
  787. struct pci_dev *dev2 = NULL;
  788. char *msg = NULL;
  789. /* Find IRQ pin */
  790. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  791. if (!pin) {
  792. dev_dbg(&dev->dev, "no interrupt pin\n");
  793. return 0;
  794. }
  795. if (io_apic_assign_pci_irqs)
  796. return 0;
  797. /* Find IRQ routing entry */
  798. if (!pirq_table)
  799. return 0;
  800. info = pirq_get_info(dev);
  801. if (!info) {
  802. dev_dbg(&dev->dev, "PCI INT %c not found in routing table\n",
  803. 'A' + pin - 1);
  804. return 0;
  805. }
  806. pirq = info->irq[pin - 1].link;
  807. mask = info->irq[pin - 1].bitmap;
  808. if (!pirq) {
  809. dev_dbg(&dev->dev, "PCI INT %c not routed\n", 'A' + pin - 1);
  810. return 0;
  811. }
  812. dev_dbg(&dev->dev, "PCI INT %c -> PIRQ %02x, mask %04x, excl %04x",
  813. 'A' + pin - 1, pirq, mask, pirq_table->exclusive_irqs);
  814. mask &= pcibios_irq_mask;
  815. /* Work around broken HP Pavilion Notebooks which assign USB to
  816. IRQ 9 even though it is actually wired to IRQ 11 */
  817. if (broken_hp_bios_irq9 && pirq == 0x59 && dev->irq == 9) {
  818. dev->irq = 11;
  819. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
  820. r->set(pirq_router_dev, dev, pirq, 11);
  821. }
  822. /* same for Acer Travelmate 360, but with CB and irq 11 -> 10 */
  823. if (acer_tm360_irqrouting && dev->irq == 11 &&
  824. dev->vendor == PCI_VENDOR_ID_O2) {
  825. pirq = 0x68;
  826. mask = 0x400;
  827. dev->irq = r->get(pirq_router_dev, dev, pirq);
  828. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  829. }
  830. /*
  831. * Find the best IRQ to assign: use the one
  832. * reported by the device if possible.
  833. */
  834. newirq = dev->irq;
  835. if (newirq && !((1 << newirq) & mask)) {
  836. if (pci_probe & PCI_USE_PIRQ_MASK)
  837. newirq = 0;
  838. else
  839. dev_warn(&dev->dev, "IRQ %d doesn't match PIRQ mask "
  840. "%#x; try pci=usepirqmask\n", newirq, mask);
  841. }
  842. if (!newirq && assign) {
  843. for (i = 0; i < 16; i++) {
  844. if (!(mask & (1 << i)))
  845. continue;
  846. if (pirq_penalty[i] < pirq_penalty[newirq] &&
  847. can_request_irq(i, IRQF_SHARED))
  848. newirq = i;
  849. }
  850. }
  851. dev_dbg(&dev->dev, "PCI INT %c -> newirq %d", 'A' + pin - 1, newirq);
  852. /* Check if it is hardcoded */
  853. if ((pirq & 0xf0) == 0xf0) {
  854. irq = pirq & 0xf;
  855. msg = "hardcoded";
  856. } else if (r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
  857. ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask))) {
  858. msg = "found";
  859. elcr_set_level_irq(irq);
  860. } else if (newirq && r->set &&
  861. (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) {
  862. if (r->set(pirq_router_dev, dev, pirq, newirq)) {
  863. elcr_set_level_irq(newirq);
  864. msg = "assigned";
  865. irq = newirq;
  866. }
  867. }
  868. if (!irq) {
  869. if (newirq && mask == (1 << newirq)) {
  870. msg = "guessed";
  871. irq = newirq;
  872. } else {
  873. dev_dbg(&dev->dev, "can't route interrupt\n");
  874. return 0;
  875. }
  876. }
  877. dev_info(&dev->dev, "%s PCI INT %c -> IRQ %d\n", msg, 'A' + pin - 1, irq);
  878. /* Update IRQ for all devices with the same pirq value */
  879. for_each_pci_dev(dev2) {
  880. pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin);
  881. if (!pin)
  882. continue;
  883. info = pirq_get_info(dev2);
  884. if (!info)
  885. continue;
  886. if (info->irq[pin - 1].link == pirq) {
  887. /*
  888. * We refuse to override the dev->irq
  889. * information. Give a warning!
  890. */
  891. if (dev2->irq && dev2->irq != irq && \
  892. (!(pci_probe & PCI_USE_PIRQ_MASK) || \
  893. ((1 << dev2->irq) & mask))) {
  894. #ifndef CONFIG_PCI_MSI
  895. dev_info(&dev2->dev, "IRQ routing conflict: "
  896. "have IRQ %d, want IRQ %d\n",
  897. dev2->irq, irq);
  898. #endif
  899. continue;
  900. }
  901. dev2->irq = irq;
  902. pirq_penalty[irq]++;
  903. if (dev != dev2)
  904. dev_info(&dev->dev, "sharing IRQ %d with %s\n",
  905. irq, pci_name(dev2));
  906. }
  907. }
  908. return 1;
  909. }
  910. void __init pcibios_fixup_irqs(void)
  911. {
  912. struct pci_dev *dev = NULL;
  913. u8 pin;
  914. DBG(KERN_DEBUG "PCI: IRQ fixup\n");
  915. for_each_pci_dev(dev) {
  916. /*
  917. * If the BIOS has set an out of range IRQ number, just
  918. * ignore it. Also keep track of which IRQ's are
  919. * already in use.
  920. */
  921. if (dev->irq >= 16) {
  922. dev_dbg(&dev->dev, "ignoring bogus IRQ %d\n", dev->irq);
  923. dev->irq = 0;
  924. }
  925. /*
  926. * If the IRQ is already assigned to a PCI device,
  927. * ignore its ISA use penalty
  928. */
  929. if (pirq_penalty[dev->irq] >= 100 &&
  930. pirq_penalty[dev->irq] < 100000)
  931. pirq_penalty[dev->irq] = 0;
  932. pirq_penalty[dev->irq]++;
  933. }
  934. if (io_apic_assign_pci_irqs)
  935. return;
  936. dev = NULL;
  937. for_each_pci_dev(dev) {
  938. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  939. if (!pin)
  940. continue;
  941. /*
  942. * Still no IRQ? Try to lookup one...
  943. */
  944. if (!dev->irq)
  945. pcibios_lookup_irq(dev, 0);
  946. }
  947. }
  948. /*
  949. * Work around broken HP Pavilion Notebooks which assign USB to
  950. * IRQ 9 even though it is actually wired to IRQ 11
  951. */
  952. static int __init fix_broken_hp_bios_irq9(const struct dmi_system_id *d)
  953. {
  954. if (!broken_hp_bios_irq9) {
  955. broken_hp_bios_irq9 = 1;
  956. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  957. d->ident);
  958. }
  959. return 0;
  960. }
  961. /*
  962. * Work around broken Acer TravelMate 360 Notebooks which assign
  963. * Cardbus to IRQ 11 even though it is actually wired to IRQ 10
  964. */
  965. static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
  966. {
  967. if (!acer_tm360_irqrouting) {
  968. acer_tm360_irqrouting = 1;
  969. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  970. d->ident);
  971. }
  972. return 0;
  973. }
  974. static const struct dmi_system_id pciirq_dmi_table[] __initconst = {
  975. {
  976. .callback = fix_broken_hp_bios_irq9,
  977. .ident = "HP Pavilion N5400 Series Laptop",
  978. .matches = {
  979. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  980. DMI_MATCH(DMI_BIOS_VERSION, "GE.M1.03"),
  981. DMI_MATCH(DMI_PRODUCT_VERSION,
  982. "HP Pavilion Notebook Model GE"),
  983. DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
  984. },
  985. },
  986. {
  987. .callback = fix_acer_tm360_irqrouting,
  988. .ident = "Acer TravelMate 36x Laptop",
  989. .matches = {
  990. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  991. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  992. },
  993. },
  994. { }
  995. };
  996. void __init pcibios_irq_init(void)
  997. {
  998. struct irq_routing_table *rtable = NULL;
  999. DBG(KERN_DEBUG "PCI: IRQ init\n");
  1000. if (raw_pci_ops == NULL)
  1001. return;
  1002. dmi_check_system(pciirq_dmi_table);
  1003. pirq_table = pirq_find_routing_table();
  1004. #ifdef CONFIG_PCI_BIOS
  1005. if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) {
  1006. pirq_table = pcibios_get_irq_routing_table();
  1007. rtable = pirq_table;
  1008. }
  1009. #endif
  1010. if (pirq_table) {
  1011. pirq_peer_trick();
  1012. pirq_find_router(&pirq_router);
  1013. if (pirq_table->exclusive_irqs) {
  1014. int i;
  1015. for (i = 0; i < 16; i++)
  1016. if (!(pirq_table->exclusive_irqs & (1 << i)))
  1017. pirq_penalty[i] += 100;
  1018. }
  1019. /*
  1020. * If we're using the I/O APIC, avoid using the PCI IRQ
  1021. * routing table
  1022. */
  1023. if (io_apic_assign_pci_irqs) {
  1024. kfree(rtable);
  1025. pirq_table = NULL;
  1026. }
  1027. }
  1028. x86_init.pci.fixup_irqs();
  1029. if (io_apic_assign_pci_irqs && pci_routeirq) {
  1030. struct pci_dev *dev = NULL;
  1031. /*
  1032. * PCI IRQ routing is set up by pci_enable_device(), but we
  1033. * also do it here in case there are still broken drivers that
  1034. * don't use pci_enable_device().
  1035. */
  1036. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  1037. for_each_pci_dev(dev)
  1038. pirq_enable_irq(dev);
  1039. }
  1040. }
  1041. static void pirq_penalize_isa_irq(int irq, int active)
  1042. {
  1043. /*
  1044. * If any ISAPnP device reports an IRQ in its list of possible
  1045. * IRQ's, we try to avoid assigning it to PCI devices.
  1046. */
  1047. if (irq < 16) {
  1048. if (active)
  1049. pirq_penalty[irq] += 1000;
  1050. else
  1051. pirq_penalty[irq] += 100;
  1052. }
  1053. }
  1054. void pcibios_penalize_isa_irq(int irq, int active)
  1055. {
  1056. #ifdef CONFIG_ACPI
  1057. if (!acpi_noirq)
  1058. acpi_penalize_isa_irq(irq, active);
  1059. else
  1060. #endif
  1061. pirq_penalize_isa_irq(irq, active);
  1062. }
  1063. static int pirq_enable_irq(struct pci_dev *dev)
  1064. {
  1065. u8 pin = 0;
  1066. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  1067. if (pin && !pcibios_lookup_irq(dev, 1)) {
  1068. char *msg = "";
  1069. if (!io_apic_assign_pci_irqs && dev->irq)
  1070. return 0;
  1071. if (io_apic_assign_pci_irqs) {
  1072. #ifdef CONFIG_X86_IO_APIC
  1073. struct pci_dev *temp_dev;
  1074. int irq;
  1075. if (dev->irq_managed && dev->irq > 0)
  1076. return 0;
  1077. irq = IO_APIC_get_PCI_irq_vector(dev->bus->number,
  1078. PCI_SLOT(dev->devfn), pin - 1);
  1079. /*
  1080. * Busses behind bridges are typically not listed in the MP-table.
  1081. * In this case we have to look up the IRQ based on the parent bus,
  1082. * parent slot, and pin number. The SMP code detects such bridged
  1083. * busses itself so we should get into this branch reliably.
  1084. */
  1085. temp_dev = dev;
  1086. while (irq < 0 && dev->bus->parent) { /* go back to the bridge */
  1087. struct pci_dev *bridge = dev->bus->self;
  1088. pin = pci_swizzle_interrupt_pin(dev, pin);
  1089. irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number,
  1090. PCI_SLOT(bridge->devfn),
  1091. pin - 1);
  1092. if (irq >= 0)
  1093. dev_warn(&dev->dev, "using bridge %s "
  1094. "INT %c to get IRQ %d\n",
  1095. pci_name(bridge), 'A' + pin - 1,
  1096. irq);
  1097. dev = bridge;
  1098. }
  1099. dev = temp_dev;
  1100. if (irq >= 0) {
  1101. dev->irq_managed = 1;
  1102. dev->irq = irq;
  1103. dev_info(&dev->dev, "PCI->APIC IRQ transform: "
  1104. "INT %c -> IRQ %d\n", 'A' + pin - 1, irq);
  1105. return 0;
  1106. } else
  1107. msg = "; probably buggy MP table";
  1108. #endif
  1109. } else if (pci_probe & PCI_BIOS_IRQ_SCAN)
  1110. msg = "";
  1111. else
  1112. msg = "; please try using pci=biosirq";
  1113. /*
  1114. * With IDE legacy devices the IRQ lookup failure is not
  1115. * a problem..
  1116. */
  1117. if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
  1118. !(dev->class & 0x5))
  1119. return 0;
  1120. dev_warn(&dev->dev, "can't find IRQ for PCI INT %c%s\n",
  1121. 'A' + pin - 1, msg);
  1122. }
  1123. return 0;
  1124. }
  1125. bool mp_should_keep_irq(struct device *dev)
  1126. {
  1127. if (dev->power.is_prepared)
  1128. return true;
  1129. #ifdef CONFIG_PM
  1130. if (dev->power.runtime_status == RPM_SUSPENDING)
  1131. return true;
  1132. #endif
  1133. return false;
  1134. }
  1135. static void pirq_disable_irq(struct pci_dev *dev)
  1136. {
  1137. if (io_apic_assign_pci_irqs && !mp_should_keep_irq(&dev->dev) &&
  1138. dev->irq_managed && dev->irq) {
  1139. mp_unmap_irq(dev->irq);
  1140. dev->irq = 0;
  1141. dev->irq_managed = 0;
  1142. }
  1143. }