irq.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  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. dev_info(&dev->dev, "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. dev_info(&dev->dev, "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. dev_info(&dev->dev,
  432. "AMD756: dev [%04x:%04x], router PIRQ %d get IRQ %d\n",
  433. dev->vendor, dev->device, pirq, irq);
  434. return irq;
  435. }
  436. static int pirq_amd756_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  437. {
  438. dev_info(&dev->dev,
  439. "AMD756: dev [%04x:%04x], router PIRQ %d set IRQ %d\n",
  440. dev->vendor, dev->device, pirq, irq);
  441. if (pirq <= 4)
  442. write_config_nybble(router, 0x56, pirq - 1, irq);
  443. return 1;
  444. }
  445. /*
  446. * PicoPower PT86C523
  447. */
  448. static int pirq_pico_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  449. {
  450. outb(0x10 + ((pirq - 1) >> 1), 0x24);
  451. return ((pirq - 1) & 1) ? (inb(0x26) >> 4) : (inb(0x26) & 0xf);
  452. }
  453. static int pirq_pico_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
  454. int irq)
  455. {
  456. unsigned int x;
  457. outb(0x10 + ((pirq - 1) >> 1), 0x24);
  458. x = inb(0x26);
  459. x = ((pirq - 1) & 1) ? ((x & 0x0f) | (irq << 4)) : ((x & 0xf0) | (irq));
  460. outb(x, 0x26);
  461. return 1;
  462. }
  463. #ifdef CONFIG_PCI_BIOS
  464. static int pirq_bios_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  465. {
  466. struct pci_dev *bridge;
  467. int pin = pci_get_interrupt_pin(dev, &bridge);
  468. return pcibios_set_irq_routing(bridge, pin, irq);
  469. }
  470. #endif
  471. static __init int intel_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  472. {
  473. static struct pci_device_id __initdata pirq_440gx[] = {
  474. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
  475. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
  476. { },
  477. };
  478. /* 440GX has a proprietary PIRQ router -- don't use it */
  479. if (pci_dev_present(pirq_440gx))
  480. return 0;
  481. switch (device) {
  482. case PCI_DEVICE_ID_INTEL_82371FB_0:
  483. case PCI_DEVICE_ID_INTEL_82371SB_0:
  484. case PCI_DEVICE_ID_INTEL_82371AB_0:
  485. case PCI_DEVICE_ID_INTEL_82371MX:
  486. case PCI_DEVICE_ID_INTEL_82443MX_0:
  487. case PCI_DEVICE_ID_INTEL_82801AA_0:
  488. case PCI_DEVICE_ID_INTEL_82801AB_0:
  489. case PCI_DEVICE_ID_INTEL_82801BA_0:
  490. case PCI_DEVICE_ID_INTEL_82801BA_10:
  491. case PCI_DEVICE_ID_INTEL_82801CA_0:
  492. case PCI_DEVICE_ID_INTEL_82801CA_12:
  493. case PCI_DEVICE_ID_INTEL_82801DB_0:
  494. case PCI_DEVICE_ID_INTEL_82801E_0:
  495. case PCI_DEVICE_ID_INTEL_82801EB_0:
  496. case PCI_DEVICE_ID_INTEL_ESB_1:
  497. case PCI_DEVICE_ID_INTEL_ICH6_0:
  498. case PCI_DEVICE_ID_INTEL_ICH6_1:
  499. case PCI_DEVICE_ID_INTEL_ICH7_0:
  500. case PCI_DEVICE_ID_INTEL_ICH7_1:
  501. case PCI_DEVICE_ID_INTEL_ICH7_30:
  502. case PCI_DEVICE_ID_INTEL_ICH7_31:
  503. case PCI_DEVICE_ID_INTEL_ESB2_0:
  504. case PCI_DEVICE_ID_INTEL_ICH8_0:
  505. case PCI_DEVICE_ID_INTEL_ICH8_1:
  506. case PCI_DEVICE_ID_INTEL_ICH8_2:
  507. case PCI_DEVICE_ID_INTEL_ICH8_3:
  508. case PCI_DEVICE_ID_INTEL_ICH8_4:
  509. case PCI_DEVICE_ID_INTEL_ICH9_0:
  510. case PCI_DEVICE_ID_INTEL_ICH9_1:
  511. case PCI_DEVICE_ID_INTEL_ICH9_2:
  512. case PCI_DEVICE_ID_INTEL_ICH9_3:
  513. case PCI_DEVICE_ID_INTEL_ICH9_4:
  514. case PCI_DEVICE_ID_INTEL_ICH9_5:
  515. case PCI_DEVICE_ID_INTEL_TOLAPAI_0:
  516. case PCI_DEVICE_ID_INTEL_ICH10_0:
  517. case PCI_DEVICE_ID_INTEL_ICH10_1:
  518. case PCI_DEVICE_ID_INTEL_ICH10_2:
  519. case PCI_DEVICE_ID_INTEL_ICH10_3:
  520. r->name = "PIIX/ICH";
  521. r->get = pirq_piix_get;
  522. r->set = pirq_piix_set;
  523. return 1;
  524. }
  525. if ((device >= PCI_DEVICE_ID_INTEL_PCH_LPC_MIN) &&
  526. (device <= PCI_DEVICE_ID_INTEL_PCH_LPC_MAX)) {
  527. r->name = "PIIX/ICH";
  528. r->get = pirq_piix_get;
  529. r->set = pirq_piix_set;
  530. return 1;
  531. }
  532. return 0;
  533. }
  534. static __init int via_router_probe(struct irq_router *r,
  535. struct pci_dev *router, u16 device)
  536. {
  537. /* FIXME: We should move some of the quirk fixup stuff here */
  538. /*
  539. * workarounds for some buggy BIOSes
  540. */
  541. if (device == PCI_DEVICE_ID_VIA_82C586_0) {
  542. switch (router->device) {
  543. case PCI_DEVICE_ID_VIA_82C686:
  544. /*
  545. * Asus k7m bios wrongly reports 82C686A
  546. * as 586-compatible
  547. */
  548. device = PCI_DEVICE_ID_VIA_82C686;
  549. break;
  550. case PCI_DEVICE_ID_VIA_8235:
  551. /**
  552. * Asus a7v-x bios wrongly reports 8235
  553. * as 586-compatible
  554. */
  555. device = PCI_DEVICE_ID_VIA_8235;
  556. break;
  557. case PCI_DEVICE_ID_VIA_8237:
  558. /**
  559. * Asus a7v600 bios wrongly reports 8237
  560. * as 586-compatible
  561. */
  562. device = PCI_DEVICE_ID_VIA_8237;
  563. break;
  564. }
  565. }
  566. switch (device) {
  567. case PCI_DEVICE_ID_VIA_82C586_0:
  568. r->name = "VIA";
  569. r->get = pirq_via586_get;
  570. r->set = pirq_via586_set;
  571. return 1;
  572. case PCI_DEVICE_ID_VIA_82C596:
  573. case PCI_DEVICE_ID_VIA_82C686:
  574. case PCI_DEVICE_ID_VIA_8231:
  575. case PCI_DEVICE_ID_VIA_8233A:
  576. case PCI_DEVICE_ID_VIA_8235:
  577. case PCI_DEVICE_ID_VIA_8237:
  578. /* FIXME: add new ones for 8233/5 */
  579. r->name = "VIA";
  580. r->get = pirq_via_get;
  581. r->set = pirq_via_set;
  582. return 1;
  583. }
  584. return 0;
  585. }
  586. static __init int vlsi_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  587. {
  588. switch (device) {
  589. case PCI_DEVICE_ID_VLSI_82C534:
  590. r->name = "VLSI 82C534";
  591. r->get = pirq_vlsi_get;
  592. r->set = pirq_vlsi_set;
  593. return 1;
  594. }
  595. return 0;
  596. }
  597. static __init int serverworks_router_probe(struct irq_router *r,
  598. struct pci_dev *router, u16 device)
  599. {
  600. switch (device) {
  601. case PCI_DEVICE_ID_SERVERWORKS_OSB4:
  602. case PCI_DEVICE_ID_SERVERWORKS_CSB5:
  603. r->name = "ServerWorks";
  604. r->get = pirq_serverworks_get;
  605. r->set = pirq_serverworks_set;
  606. return 1;
  607. }
  608. return 0;
  609. }
  610. static __init int sis_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  611. {
  612. if (device != PCI_DEVICE_ID_SI_503)
  613. return 0;
  614. r->name = "SIS";
  615. r->get = pirq_sis_get;
  616. r->set = pirq_sis_set;
  617. return 1;
  618. }
  619. static __init int cyrix_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  620. {
  621. switch (device) {
  622. case PCI_DEVICE_ID_CYRIX_5520:
  623. r->name = "NatSemi";
  624. r->get = pirq_cyrix_get;
  625. r->set = pirq_cyrix_set;
  626. return 1;
  627. }
  628. return 0;
  629. }
  630. static __init int opti_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  631. {
  632. switch (device) {
  633. case PCI_DEVICE_ID_OPTI_82C700:
  634. r->name = "OPTI";
  635. r->get = pirq_opti_get;
  636. r->set = pirq_opti_set;
  637. return 1;
  638. }
  639. return 0;
  640. }
  641. static __init int ite_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  642. {
  643. switch (device) {
  644. case PCI_DEVICE_ID_ITE_IT8330G_0:
  645. r->name = "ITE";
  646. r->get = pirq_ite_get;
  647. r->set = pirq_ite_set;
  648. return 1;
  649. }
  650. return 0;
  651. }
  652. static __init int ali_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  653. {
  654. switch (device) {
  655. case PCI_DEVICE_ID_AL_M1533:
  656. case PCI_DEVICE_ID_AL_M1563:
  657. r->name = "ALI";
  658. r->get = pirq_ali_get;
  659. r->set = pirq_ali_set;
  660. return 1;
  661. }
  662. return 0;
  663. }
  664. static __init int amd_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  665. {
  666. switch (device) {
  667. case PCI_DEVICE_ID_AMD_VIPER_740B:
  668. r->name = "AMD756";
  669. break;
  670. case PCI_DEVICE_ID_AMD_VIPER_7413:
  671. r->name = "AMD766";
  672. break;
  673. case PCI_DEVICE_ID_AMD_VIPER_7443:
  674. r->name = "AMD768";
  675. break;
  676. default:
  677. return 0;
  678. }
  679. r->get = pirq_amd756_get;
  680. r->set = pirq_amd756_set;
  681. return 1;
  682. }
  683. static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  684. {
  685. switch (device) {
  686. case PCI_DEVICE_ID_PICOPOWER_PT86C523:
  687. r->name = "PicoPower PT86C523";
  688. r->get = pirq_pico_get;
  689. r->set = pirq_pico_set;
  690. return 1;
  691. case PCI_DEVICE_ID_PICOPOWER_PT86C523BBP:
  692. r->name = "PicoPower PT86C523 rev. BB+";
  693. r->get = pirq_pico_get;
  694. r->set = pirq_pico_set;
  695. return 1;
  696. }
  697. return 0;
  698. }
  699. static __initdata struct irq_router_handler pirq_routers[] = {
  700. { PCI_VENDOR_ID_INTEL, intel_router_probe },
  701. { PCI_VENDOR_ID_AL, ali_router_probe },
  702. { PCI_VENDOR_ID_ITE, ite_router_probe },
  703. { PCI_VENDOR_ID_VIA, via_router_probe },
  704. { PCI_VENDOR_ID_OPTI, opti_router_probe },
  705. { PCI_VENDOR_ID_SI, sis_router_probe },
  706. { PCI_VENDOR_ID_CYRIX, cyrix_router_probe },
  707. { PCI_VENDOR_ID_VLSI, vlsi_router_probe },
  708. { PCI_VENDOR_ID_SERVERWORKS, serverworks_router_probe },
  709. { PCI_VENDOR_ID_AMD, amd_router_probe },
  710. { PCI_VENDOR_ID_PICOPOWER, pico_router_probe },
  711. /* Someone with docs needs to add the ATI Radeon IGP */
  712. { 0, NULL }
  713. };
  714. static struct irq_router pirq_router;
  715. static struct pci_dev *pirq_router_dev;
  716. /*
  717. * FIXME: should we have an option to say "generic for
  718. * chipset" ?
  719. */
  720. static void __init pirq_find_router(struct irq_router *r)
  721. {
  722. struct irq_routing_table *rt = pirq_table;
  723. struct irq_router_handler *h;
  724. #ifdef CONFIG_PCI_BIOS
  725. if (!rt->signature) {
  726. printk(KERN_INFO "PCI: Using BIOS for IRQ routing\n");
  727. r->set = pirq_bios_set;
  728. r->name = "BIOS";
  729. return;
  730. }
  731. #endif
  732. /* Default unless a driver reloads it */
  733. r->name = "default";
  734. r->get = NULL;
  735. r->set = NULL;
  736. DBG(KERN_DEBUG "PCI: Attempting to find IRQ router for [%04x:%04x]\n",
  737. rt->rtr_vendor, rt->rtr_device);
  738. pirq_router_dev = pci_get_bus_and_slot(rt->rtr_bus, rt->rtr_devfn);
  739. if (!pirq_router_dev) {
  740. DBG(KERN_DEBUG "PCI: Interrupt router not found at "
  741. "%02x:%02x\n", rt->rtr_bus, rt->rtr_devfn);
  742. return;
  743. }
  744. for (h = pirq_routers; h->vendor; h++) {
  745. /* First look for a router match */
  746. if (rt->rtr_vendor == h->vendor &&
  747. h->probe(r, pirq_router_dev, rt->rtr_device))
  748. break;
  749. /* Fall back to a device match */
  750. if (pirq_router_dev->vendor == h->vendor &&
  751. h->probe(r, pirq_router_dev, pirq_router_dev->device))
  752. break;
  753. }
  754. dev_info(&pirq_router_dev->dev, "%s IRQ router [%04x:%04x]\n",
  755. pirq_router.name,
  756. pirq_router_dev->vendor, pirq_router_dev->device);
  757. /* The device remains referenced for the kernel lifetime */
  758. }
  759. static struct irq_info *pirq_get_info(struct pci_dev *dev)
  760. {
  761. struct irq_routing_table *rt = pirq_table;
  762. int entries = (rt->size - sizeof(struct irq_routing_table)) /
  763. sizeof(struct irq_info);
  764. struct irq_info *info;
  765. for (info = rt->slots; entries--; info++)
  766. if (info->bus == dev->bus->number &&
  767. PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn))
  768. return info;
  769. return NULL;
  770. }
  771. static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
  772. {
  773. u8 pin;
  774. struct irq_info *info;
  775. int i, pirq, newirq;
  776. int irq = 0;
  777. u32 mask;
  778. struct irq_router *r = &pirq_router;
  779. struct pci_dev *dev2 = NULL;
  780. char *msg = NULL;
  781. /* Find IRQ pin */
  782. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  783. if (!pin) {
  784. dev_dbg(&dev->dev, "no interrupt pin\n");
  785. return 0;
  786. }
  787. pin = pin - 1;
  788. /* Find IRQ routing entry */
  789. if (!pirq_table)
  790. return 0;
  791. info = pirq_get_info(dev);
  792. if (!info) {
  793. dev_dbg(&dev->dev, "PCI INT %c not found in routing table\n",
  794. 'A' + pin);
  795. return 0;
  796. }
  797. pirq = info->irq[pin].link;
  798. mask = info->irq[pin].bitmap;
  799. if (!pirq) {
  800. dev_dbg(&dev->dev, "PCI INT %c not routed\n", 'A' + pin);
  801. return 0;
  802. }
  803. dev_dbg(&dev->dev, "PCI INT %c -> PIRQ %02x, mask %04x, excl %04x",
  804. 'A' + pin, pirq, mask, pirq_table->exclusive_irqs);
  805. mask &= pcibios_irq_mask;
  806. /* Work around broken HP Pavilion Notebooks which assign USB to
  807. IRQ 9 even though it is actually wired to IRQ 11 */
  808. if (broken_hp_bios_irq9 && pirq == 0x59 && dev->irq == 9) {
  809. dev->irq = 11;
  810. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
  811. r->set(pirq_router_dev, dev, pirq, 11);
  812. }
  813. /* same for Acer Travelmate 360, but with CB and irq 11 -> 10 */
  814. if (acer_tm360_irqrouting && dev->irq == 11 &&
  815. dev->vendor == PCI_VENDOR_ID_O2) {
  816. pirq = 0x68;
  817. mask = 0x400;
  818. dev->irq = r->get(pirq_router_dev, dev, pirq);
  819. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  820. }
  821. /*
  822. * Find the best IRQ to assign: use the one
  823. * reported by the device if possible.
  824. */
  825. newirq = dev->irq;
  826. if (newirq && !((1 << newirq) & mask)) {
  827. if (pci_probe & PCI_USE_PIRQ_MASK)
  828. newirq = 0;
  829. else
  830. dev_warn(&dev->dev, "IRQ %d doesn't match PIRQ mask "
  831. "%#x; try pci=usepirqmask\n", newirq, mask);
  832. }
  833. if (!newirq && assign) {
  834. for (i = 0; i < 16; i++) {
  835. if (!(mask & (1 << i)))
  836. continue;
  837. if (pirq_penalty[i] < pirq_penalty[newirq] &&
  838. can_request_irq(i, IRQF_SHARED))
  839. newirq = i;
  840. }
  841. }
  842. dev_dbg(&dev->dev, "PCI INT %c -> newirq %d", 'A' + pin, newirq);
  843. /* Check if it is hardcoded */
  844. if ((pirq & 0xf0) == 0xf0) {
  845. irq = pirq & 0xf;
  846. msg = "hardcoded";
  847. } else if (r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
  848. ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask))) {
  849. msg = "found";
  850. eisa_set_level_irq(irq);
  851. } else if (newirq && r->set &&
  852. (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) {
  853. if (r->set(pirq_router_dev, dev, pirq, newirq)) {
  854. eisa_set_level_irq(newirq);
  855. msg = "assigned";
  856. irq = newirq;
  857. }
  858. }
  859. if (!irq) {
  860. if (newirq && mask == (1 << newirq)) {
  861. msg = "guessed";
  862. irq = newirq;
  863. } else {
  864. dev_dbg(&dev->dev, "can't route interrupt\n");
  865. return 0;
  866. }
  867. }
  868. dev_info(&dev->dev, "%s PCI INT %c -> IRQ %d\n", msg, 'A' + pin, irq);
  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. dev_info(&dev2->dev, "IRQ routing conflict: "
  888. "have IRQ %d, want IRQ %d\n",
  889. dev2->irq, irq);
  890. #endif
  891. continue;
  892. }
  893. dev2->irq = irq;
  894. pirq_penalty[irq]++;
  895. if (dev != dev2)
  896. dev_info(&dev->dev, "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. dev_dbg(&dev->dev, "ignoring bogus IRQ %d\n", dev->irq);
  915. dev->irq = 0;
  916. }
  917. /*
  918. * If the IRQ is already assigned to a PCI device,
  919. * ignore its ISA use penalty
  920. */
  921. if (pirq_penalty[dev->irq] >= 100 &&
  922. pirq_penalty[dev->irq] < 100000)
  923. pirq_penalty[dev->irq] = 0;
  924. pirq_penalty[dev->irq]++;
  925. }
  926. dev = NULL;
  927. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  928. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  929. #ifdef CONFIG_X86_IO_APIC
  930. /*
  931. * Recalculate IRQ numbers if we use the I/O APIC.
  932. */
  933. if (io_apic_assign_pci_irqs) {
  934. int irq;
  935. if (!pin)
  936. continue;
  937. /*
  938. * interrupt pins are numbered starting from 1
  939. */
  940. pin--;
  941. irq = IO_APIC_get_PCI_irq_vector(dev->bus->number,
  942. PCI_SLOT(dev->devfn), pin);
  943. /*
  944. * Busses behind bridges are typically not listed in the
  945. * MP-table. In this case we have to look up the IRQ
  946. * based on the parent bus, parent slot, and pin number.
  947. * The SMP code detects such bridged busses itself so we
  948. * should get into this branch reliably.
  949. */
  950. if (irq < 0 && dev->bus->parent) {
  951. /* go back to the bridge */
  952. struct pci_dev *bridge = dev->bus->self;
  953. int bus;
  954. pin = (pin + PCI_SLOT(dev->devfn)) % 4;
  955. bus = bridge->bus->number;
  956. irq = IO_APIC_get_PCI_irq_vector(bus,
  957. PCI_SLOT(bridge->devfn), pin);
  958. if (irq >= 0)
  959. dev_warn(&dev->dev,
  960. "using bridge %s INT %c to "
  961. "get IRQ %d\n",
  962. pci_name(bridge),
  963. 'A' + pin, irq);
  964. }
  965. if (irq >= 0) {
  966. dev_info(&dev->dev,
  967. "PCI->APIC IRQ transform: INT %c "
  968. "-> IRQ %d\n",
  969. 'A' + pin, irq);
  970. dev->irq = irq;
  971. }
  972. }
  973. #endif
  974. /*
  975. * Still no IRQ? Try to lookup one...
  976. */
  977. if (pin && !dev->irq)
  978. pcibios_lookup_irq(dev, 0);
  979. }
  980. }
  981. /*
  982. * Work around broken HP Pavilion Notebooks which assign USB to
  983. * IRQ 9 even though it is actually wired to IRQ 11
  984. */
  985. static int __init fix_broken_hp_bios_irq9(const struct dmi_system_id *d)
  986. {
  987. if (!broken_hp_bios_irq9) {
  988. broken_hp_bios_irq9 = 1;
  989. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  990. d->ident);
  991. }
  992. return 0;
  993. }
  994. /*
  995. * Work around broken Acer TravelMate 360 Notebooks which assign
  996. * Cardbus to IRQ 11 even though it is actually wired to IRQ 10
  997. */
  998. static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
  999. {
  1000. if (!acer_tm360_irqrouting) {
  1001. acer_tm360_irqrouting = 1;
  1002. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  1003. d->ident);
  1004. }
  1005. return 0;
  1006. }
  1007. static struct dmi_system_id __initdata pciirq_dmi_table[] = {
  1008. {
  1009. .callback = fix_broken_hp_bios_irq9,
  1010. .ident = "HP Pavilion N5400 Series Laptop",
  1011. .matches = {
  1012. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1013. DMI_MATCH(DMI_BIOS_VERSION, "GE.M1.03"),
  1014. DMI_MATCH(DMI_PRODUCT_VERSION,
  1015. "HP Pavilion Notebook Model GE"),
  1016. DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
  1017. },
  1018. },
  1019. {
  1020. .callback = fix_acer_tm360_irqrouting,
  1021. .ident = "Acer TravelMate 36x Laptop",
  1022. .matches = {
  1023. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1024. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  1025. },
  1026. },
  1027. { }
  1028. };
  1029. int __init pcibios_irq_init(void)
  1030. {
  1031. DBG(KERN_DEBUG "PCI: IRQ init\n");
  1032. if (pcibios_enable_irq || raw_pci_ops == NULL)
  1033. return 0;
  1034. dmi_check_system(pciirq_dmi_table);
  1035. pirq_table = pirq_find_routing_table();
  1036. #ifdef CONFIG_PCI_BIOS
  1037. if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN))
  1038. pirq_table = pcibios_get_irq_routing_table();
  1039. #endif
  1040. if (pirq_table) {
  1041. pirq_peer_trick();
  1042. pirq_find_router(&pirq_router);
  1043. if (pirq_table->exclusive_irqs) {
  1044. int i;
  1045. for (i = 0; i < 16; i++)
  1046. if (!(pirq_table->exclusive_irqs & (1 << i)))
  1047. pirq_penalty[i] += 100;
  1048. }
  1049. /*
  1050. * If we're using the I/O APIC, avoid using the PCI IRQ
  1051. * routing table
  1052. */
  1053. if (io_apic_assign_pci_irqs)
  1054. pirq_table = NULL;
  1055. }
  1056. pcibios_enable_irq = pirq_enable_irq;
  1057. pcibios_fixup_irqs();
  1058. return 0;
  1059. }
  1060. static void pirq_penalize_isa_irq(int irq, int active)
  1061. {
  1062. /*
  1063. * If any ISAPnP device reports an IRQ in its list of possible
  1064. * IRQ's, we try to avoid assigning it to PCI devices.
  1065. */
  1066. if (irq < 16) {
  1067. if (active)
  1068. pirq_penalty[irq] += 1000;
  1069. else
  1070. pirq_penalty[irq] += 100;
  1071. }
  1072. }
  1073. void pcibios_penalize_isa_irq(int irq, int active)
  1074. {
  1075. #ifdef CONFIG_ACPI
  1076. if (!acpi_noirq)
  1077. acpi_penalize_isa_irq(irq, active);
  1078. else
  1079. #endif
  1080. pirq_penalize_isa_irq(irq, active);
  1081. }
  1082. static int pirq_enable_irq(struct pci_dev *dev)
  1083. {
  1084. u8 pin;
  1085. struct pci_dev *temp_dev;
  1086. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  1087. if (pin && !pcibios_lookup_irq(dev, 1) && !dev->irq) {
  1088. char *msg = "";
  1089. pin--; /* interrupt pins are numbered starting from 1 */
  1090. if (io_apic_assign_pci_irqs) {
  1091. int irq;
  1092. irq = IO_APIC_get_PCI_irq_vector(dev->bus->number, PCI_SLOT(dev->devfn), pin);
  1093. /*
  1094. * Busses behind bridges are typically not listed in the MP-table.
  1095. * In this case we have to look up the IRQ based on the parent bus,
  1096. * parent slot, and pin number. The SMP code detects such bridged
  1097. * busses itself so we should get into this branch reliably.
  1098. */
  1099. temp_dev = dev;
  1100. while (irq < 0 && dev->bus->parent) { /* go back to the bridge */
  1101. struct pci_dev *bridge = dev->bus->self;
  1102. pin = (pin + PCI_SLOT(dev->devfn)) % 4;
  1103. irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number,
  1104. PCI_SLOT(bridge->devfn), pin);
  1105. if (irq >= 0)
  1106. dev_warn(&dev->dev, "using bridge %s "
  1107. "INT %c to get IRQ %d\n",
  1108. pci_name(bridge), 'A' + pin,
  1109. irq);
  1110. dev = bridge;
  1111. }
  1112. dev = temp_dev;
  1113. if (irq >= 0) {
  1114. dev_info(&dev->dev, "PCI->APIC IRQ transform: "
  1115. "INT %c -> IRQ %d\n", 'A' + pin, irq);
  1116. dev->irq = irq;
  1117. return 0;
  1118. } else
  1119. msg = "; probably buggy MP table";
  1120. } else if (pci_probe & PCI_BIOS_IRQ_SCAN)
  1121. msg = "";
  1122. else
  1123. msg = "; please try using pci=biosirq";
  1124. /*
  1125. * With IDE legacy devices the IRQ lookup failure is not
  1126. * a problem..
  1127. */
  1128. if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
  1129. !(dev->class & 0x5))
  1130. return 0;
  1131. dev_warn(&dev->dev, "can't find IRQ for PCI INT %c%s\n",
  1132. 'A' + pin, msg);
  1133. }
  1134. return 0;
  1135. }