irq.c 33 KB

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