irq.c 33 KB

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