irq.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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 <asm/pci_x86.h>
  19. #define PIRQ_SIGNATURE (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))
  20. #define PIRQ_VERSION 0x0100
  21. static int broken_hp_bios_irq9;
  22. static int acer_tm360_irqrouting;
  23. static struct irq_routing_table *pirq_table;
  24. static int pirq_enable_irq(struct pci_dev *dev);
  25. /*
  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 - 1, 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_TGP_LPC:
  504. case PCI_DEVICE_ID_INTEL_ESB2_0:
  505. case PCI_DEVICE_ID_INTEL_ICH8_0:
  506. case PCI_DEVICE_ID_INTEL_ICH8_1:
  507. case PCI_DEVICE_ID_INTEL_ICH8_2:
  508. case PCI_DEVICE_ID_INTEL_ICH8_3:
  509. case PCI_DEVICE_ID_INTEL_ICH8_4:
  510. case PCI_DEVICE_ID_INTEL_ICH9_0:
  511. case PCI_DEVICE_ID_INTEL_ICH9_1:
  512. case PCI_DEVICE_ID_INTEL_ICH9_2:
  513. case PCI_DEVICE_ID_INTEL_ICH9_3:
  514. case PCI_DEVICE_ID_INTEL_ICH9_4:
  515. case PCI_DEVICE_ID_INTEL_ICH9_5:
  516. case PCI_DEVICE_ID_INTEL_TOLAPAI_0:
  517. case PCI_DEVICE_ID_INTEL_ICH10_0:
  518. case PCI_DEVICE_ID_INTEL_ICH10_1:
  519. case PCI_DEVICE_ID_INTEL_ICH10_2:
  520. case PCI_DEVICE_ID_INTEL_ICH10_3:
  521. r->name = "PIIX/ICH";
  522. r->get = pirq_piix_get;
  523. r->set = pirq_piix_set;
  524. return 1;
  525. }
  526. if ((device >= PCI_DEVICE_ID_INTEL_PCH_LPC_MIN) &&
  527. (device <= PCI_DEVICE_ID_INTEL_PCH_LPC_MAX)) {
  528. r->name = "PIIX/ICH";
  529. r->get = pirq_piix_get;
  530. r->set = pirq_piix_set;
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. static __init int via_router_probe(struct irq_router *r,
  536. struct pci_dev *router, u16 device)
  537. {
  538. /* FIXME: We should move some of the quirk fixup stuff here */
  539. /*
  540. * workarounds for some buggy BIOSes
  541. */
  542. if (device == PCI_DEVICE_ID_VIA_82C586_0) {
  543. switch (router->device) {
  544. case PCI_DEVICE_ID_VIA_82C686:
  545. /*
  546. * Asus k7m bios wrongly reports 82C686A
  547. * as 586-compatible
  548. */
  549. device = PCI_DEVICE_ID_VIA_82C686;
  550. break;
  551. case PCI_DEVICE_ID_VIA_8235:
  552. /**
  553. * Asus a7v-x bios wrongly reports 8235
  554. * as 586-compatible
  555. */
  556. device = PCI_DEVICE_ID_VIA_8235;
  557. break;
  558. case PCI_DEVICE_ID_VIA_8237:
  559. /**
  560. * Asus a7v600 bios wrongly reports 8237
  561. * as 586-compatible
  562. */
  563. device = PCI_DEVICE_ID_VIA_8237;
  564. break;
  565. }
  566. }
  567. switch (device) {
  568. case PCI_DEVICE_ID_VIA_82C586_0:
  569. r->name = "VIA";
  570. r->get = pirq_via586_get;
  571. r->set = pirq_via586_set;
  572. return 1;
  573. case PCI_DEVICE_ID_VIA_82C596:
  574. case PCI_DEVICE_ID_VIA_82C686:
  575. case PCI_DEVICE_ID_VIA_8231:
  576. case PCI_DEVICE_ID_VIA_8233A:
  577. case PCI_DEVICE_ID_VIA_8235:
  578. case PCI_DEVICE_ID_VIA_8237:
  579. /* FIXME: add new ones for 8233/5 */
  580. r->name = "VIA";
  581. r->get = pirq_via_get;
  582. r->set = pirq_via_set;
  583. return 1;
  584. }
  585. return 0;
  586. }
  587. static __init int vlsi_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  588. {
  589. switch (device) {
  590. case PCI_DEVICE_ID_VLSI_82C534:
  591. r->name = "VLSI 82C534";
  592. r->get = pirq_vlsi_get;
  593. r->set = pirq_vlsi_set;
  594. return 1;
  595. }
  596. return 0;
  597. }
  598. static __init int serverworks_router_probe(struct irq_router *r,
  599. struct pci_dev *router, u16 device)
  600. {
  601. switch (device) {
  602. case PCI_DEVICE_ID_SERVERWORKS_OSB4:
  603. case PCI_DEVICE_ID_SERVERWORKS_CSB5:
  604. r->name = "ServerWorks";
  605. r->get = pirq_serverworks_get;
  606. r->set = pirq_serverworks_set;
  607. return 1;
  608. }
  609. return 0;
  610. }
  611. static __init int sis_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  612. {
  613. if (device != PCI_DEVICE_ID_SI_503)
  614. return 0;
  615. r->name = "SIS";
  616. r->get = pirq_sis_get;
  617. r->set = pirq_sis_set;
  618. return 1;
  619. }
  620. static __init int cyrix_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  621. {
  622. switch (device) {
  623. case PCI_DEVICE_ID_CYRIX_5520:
  624. r->name = "NatSemi";
  625. r->get = pirq_cyrix_get;
  626. r->set = pirq_cyrix_set;
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. static __init int opti_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  632. {
  633. switch (device) {
  634. case PCI_DEVICE_ID_OPTI_82C700:
  635. r->name = "OPTI";
  636. r->get = pirq_opti_get;
  637. r->set = pirq_opti_set;
  638. return 1;
  639. }
  640. return 0;
  641. }
  642. static __init int ite_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  643. {
  644. switch (device) {
  645. case PCI_DEVICE_ID_ITE_IT8330G_0:
  646. r->name = "ITE";
  647. r->get = pirq_ite_get;
  648. r->set = pirq_ite_set;
  649. return 1;
  650. }
  651. return 0;
  652. }
  653. static __init int ali_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  654. {
  655. switch (device) {
  656. case PCI_DEVICE_ID_AL_M1533:
  657. case PCI_DEVICE_ID_AL_M1563:
  658. r->name = "ALI";
  659. r->get = pirq_ali_get;
  660. r->set = pirq_ali_set;
  661. return 1;
  662. }
  663. return 0;
  664. }
  665. static __init int amd_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  666. {
  667. switch (device) {
  668. case PCI_DEVICE_ID_AMD_VIPER_740B:
  669. r->name = "AMD756";
  670. break;
  671. case PCI_DEVICE_ID_AMD_VIPER_7413:
  672. r->name = "AMD766";
  673. break;
  674. case PCI_DEVICE_ID_AMD_VIPER_7443:
  675. r->name = "AMD768";
  676. break;
  677. default:
  678. return 0;
  679. }
  680. r->get = pirq_amd756_get;
  681. r->set = pirq_amd756_set;
  682. return 1;
  683. }
  684. static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  685. {
  686. switch (device) {
  687. case PCI_DEVICE_ID_PICOPOWER_PT86C523:
  688. r->name = "PicoPower PT86C523";
  689. r->get = pirq_pico_get;
  690. r->set = pirq_pico_set;
  691. return 1;
  692. case PCI_DEVICE_ID_PICOPOWER_PT86C523BBP:
  693. r->name = "PicoPower PT86C523 rev. BB+";
  694. r->get = pirq_pico_get;
  695. r->set = pirq_pico_set;
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. static __initdata struct irq_router_handler pirq_routers[] = {
  701. { PCI_VENDOR_ID_INTEL, intel_router_probe },
  702. { PCI_VENDOR_ID_AL, ali_router_probe },
  703. { PCI_VENDOR_ID_ITE, ite_router_probe },
  704. { PCI_VENDOR_ID_VIA, via_router_probe },
  705. { PCI_VENDOR_ID_OPTI, opti_router_probe },
  706. { PCI_VENDOR_ID_SI, sis_router_probe },
  707. { PCI_VENDOR_ID_CYRIX, cyrix_router_probe },
  708. { PCI_VENDOR_ID_VLSI, vlsi_router_probe },
  709. { PCI_VENDOR_ID_SERVERWORKS, serverworks_router_probe },
  710. { PCI_VENDOR_ID_AMD, amd_router_probe },
  711. { PCI_VENDOR_ID_PICOPOWER, pico_router_probe },
  712. /* Someone with docs needs to add the ATI Radeon IGP */
  713. { 0, NULL }
  714. };
  715. static struct irq_router pirq_router;
  716. static struct pci_dev *pirq_router_dev;
  717. /*
  718. * FIXME: should we have an option to say "generic for
  719. * chipset" ?
  720. */
  721. static void __init pirq_find_router(struct irq_router *r)
  722. {
  723. struct irq_routing_table *rt = pirq_table;
  724. struct irq_router_handler *h;
  725. #ifdef CONFIG_PCI_BIOS
  726. if (!rt->signature) {
  727. printk(KERN_INFO "PCI: Using BIOS for IRQ routing\n");
  728. r->set = pirq_bios_set;
  729. r->name = "BIOS";
  730. return;
  731. }
  732. #endif
  733. /* Default unless a driver reloads it */
  734. r->name = "default";
  735. r->get = NULL;
  736. r->set = NULL;
  737. DBG(KERN_DEBUG "PCI: Attempting to find IRQ router for [%04x:%04x]\n",
  738. rt->rtr_vendor, rt->rtr_device);
  739. pirq_router_dev = pci_get_bus_and_slot(rt->rtr_bus, rt->rtr_devfn);
  740. if (!pirq_router_dev) {
  741. DBG(KERN_DEBUG "PCI: Interrupt router not found at "
  742. "%02x:%02x\n", rt->rtr_bus, rt->rtr_devfn);
  743. return;
  744. }
  745. for (h = pirq_routers; h->vendor; h++) {
  746. /* First look for a router match */
  747. if (rt->rtr_vendor == h->vendor &&
  748. h->probe(r, pirq_router_dev, rt->rtr_device))
  749. break;
  750. /* Fall back to a device match */
  751. if (pirq_router_dev->vendor == h->vendor &&
  752. h->probe(r, pirq_router_dev, pirq_router_dev->device))
  753. break;
  754. }
  755. dev_info(&pirq_router_dev->dev, "%s IRQ router [%04x:%04x]\n",
  756. pirq_router.name,
  757. pirq_router_dev->vendor, pirq_router_dev->device);
  758. /* The device remains referenced for the kernel lifetime */
  759. }
  760. static struct irq_info *pirq_get_info(struct pci_dev *dev)
  761. {
  762. struct irq_routing_table *rt = pirq_table;
  763. int entries = (rt->size - sizeof(struct irq_routing_table)) /
  764. sizeof(struct irq_info);
  765. struct irq_info *info;
  766. for (info = rt->slots; entries--; info++)
  767. if (info->bus == dev->bus->number &&
  768. PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn))
  769. return info;
  770. return NULL;
  771. }
  772. static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
  773. {
  774. u8 pin;
  775. struct irq_info *info;
  776. int i, pirq, newirq;
  777. int irq = 0;
  778. u32 mask;
  779. struct irq_router *r = &pirq_router;
  780. struct pci_dev *dev2 = NULL;
  781. char *msg = NULL;
  782. /* Find IRQ pin */
  783. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  784. if (!pin) {
  785. dev_dbg(&dev->dev, "no interrupt pin\n");
  786. return 0;
  787. }
  788. if (io_apic_assign_pci_irqs)
  789. return 0;
  790. /* Find IRQ routing entry */
  791. if (!pirq_table)
  792. return 0;
  793. info = pirq_get_info(dev);
  794. if (!info) {
  795. dev_dbg(&dev->dev, "PCI INT %c not found in routing table\n",
  796. 'A' + pin - 1);
  797. return 0;
  798. }
  799. pirq = info->irq[pin - 1].link;
  800. mask = info->irq[pin - 1].bitmap;
  801. if (!pirq) {
  802. dev_dbg(&dev->dev, "PCI INT %c not routed\n", 'A' + pin - 1);
  803. return 0;
  804. }
  805. dev_dbg(&dev->dev, "PCI INT %c -> PIRQ %02x, mask %04x, excl %04x",
  806. 'A' + pin - 1, pirq, mask, pirq_table->exclusive_irqs);
  807. mask &= pcibios_irq_mask;
  808. /* Work around broken HP Pavilion Notebooks which assign USB to
  809. IRQ 9 even though it is actually wired to IRQ 11 */
  810. if (broken_hp_bios_irq9 && pirq == 0x59 && dev->irq == 9) {
  811. dev->irq = 11;
  812. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
  813. r->set(pirq_router_dev, dev, pirq, 11);
  814. }
  815. /* same for Acer Travelmate 360, but with CB and irq 11 -> 10 */
  816. if (acer_tm360_irqrouting && dev->irq == 11 &&
  817. dev->vendor == PCI_VENDOR_ID_O2) {
  818. pirq = 0x68;
  819. mask = 0x400;
  820. dev->irq = r->get(pirq_router_dev, dev, pirq);
  821. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  822. }
  823. /*
  824. * Find the best IRQ to assign: use the one
  825. * reported by the device if possible.
  826. */
  827. newirq = dev->irq;
  828. if (newirq && !((1 << newirq) & mask)) {
  829. if (pci_probe & PCI_USE_PIRQ_MASK)
  830. newirq = 0;
  831. else
  832. dev_warn(&dev->dev, "IRQ %d doesn't match PIRQ mask "
  833. "%#x; try pci=usepirqmask\n", newirq, mask);
  834. }
  835. if (!newirq && assign) {
  836. for (i = 0; i < 16; i++) {
  837. if (!(mask & (1 << i)))
  838. continue;
  839. if (pirq_penalty[i] < pirq_penalty[newirq] &&
  840. can_request_irq(i, IRQF_SHARED))
  841. newirq = i;
  842. }
  843. }
  844. dev_dbg(&dev->dev, "PCI INT %c -> newirq %d", 'A' + pin - 1, newirq);
  845. /* Check if it is hardcoded */
  846. if ((pirq & 0xf0) == 0xf0) {
  847. irq = pirq & 0xf;
  848. msg = "hardcoded";
  849. } else if (r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
  850. ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask))) {
  851. msg = "found";
  852. eisa_set_level_irq(irq);
  853. } else if (newirq && r->set &&
  854. (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) {
  855. if (r->set(pirq_router_dev, dev, pirq, newirq)) {
  856. eisa_set_level_irq(newirq);
  857. msg = "assigned";
  858. irq = newirq;
  859. }
  860. }
  861. if (!irq) {
  862. if (newirq && mask == (1 << newirq)) {
  863. msg = "guessed";
  864. irq = newirq;
  865. } else {
  866. dev_dbg(&dev->dev, "can't route interrupt\n");
  867. return 0;
  868. }
  869. }
  870. dev_info(&dev->dev, "%s PCI INT %c -> IRQ %d\n", msg, 'A' + pin - 1, irq);
  871. /* Update IRQ for all devices with the same pirq value */
  872. while ((dev2 = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev2)) != NULL) {
  873. pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin);
  874. if (!pin)
  875. continue;
  876. info = pirq_get_info(dev2);
  877. if (!info)
  878. continue;
  879. if (info->irq[pin - 1].link == pirq) {
  880. /*
  881. * We refuse to override the dev->irq
  882. * information. Give a warning!
  883. */
  884. if (dev2->irq && dev2->irq != irq && \
  885. (!(pci_probe & PCI_USE_PIRQ_MASK) || \
  886. ((1 << dev2->irq) & mask))) {
  887. #ifndef CONFIG_PCI_MSI
  888. dev_info(&dev2->dev, "IRQ routing conflict: "
  889. "have IRQ %d, want IRQ %d\n",
  890. dev2->irq, irq);
  891. #endif
  892. continue;
  893. }
  894. dev2->irq = irq;
  895. pirq_penalty[irq]++;
  896. if (dev != dev2)
  897. dev_info(&dev->dev, "sharing IRQ %d with %s\n",
  898. irq, pci_name(dev2));
  899. }
  900. }
  901. return 1;
  902. }
  903. static void __init pcibios_fixup_irqs(void)
  904. {
  905. struct pci_dev *dev = NULL;
  906. u8 pin;
  907. DBG(KERN_DEBUG "PCI: IRQ fixup\n");
  908. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  909. /*
  910. * If the BIOS has set an out of range IRQ number, just
  911. * ignore it. Also keep track of which IRQ's are
  912. * already in use.
  913. */
  914. if (dev->irq >= 16) {
  915. dev_dbg(&dev->dev, "ignoring bogus IRQ %d\n", 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. if (io_apic_assign_pci_irqs)
  928. return;
  929. dev = NULL;
  930. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  931. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  932. if (!pin)
  933. continue;
  934. /*
  935. * Still no IRQ? Try to lookup one...
  936. */
  937. if (!dev->irq)
  938. pcibios_lookup_irq(dev, 0);
  939. }
  940. }
  941. /*
  942. * Work around broken HP Pavilion Notebooks which assign USB to
  943. * IRQ 9 even though it is actually wired to IRQ 11
  944. */
  945. static int __init fix_broken_hp_bios_irq9(const struct dmi_system_id *d)
  946. {
  947. if (!broken_hp_bios_irq9) {
  948. broken_hp_bios_irq9 = 1;
  949. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  950. d->ident);
  951. }
  952. return 0;
  953. }
  954. /*
  955. * Work around broken Acer TravelMate 360 Notebooks which assign
  956. * Cardbus to IRQ 11 even though it is actually wired to IRQ 10
  957. */
  958. static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
  959. {
  960. if (!acer_tm360_irqrouting) {
  961. acer_tm360_irqrouting = 1;
  962. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  963. d->ident);
  964. }
  965. return 0;
  966. }
  967. static struct dmi_system_id __initdata pciirq_dmi_table[] = {
  968. {
  969. .callback = fix_broken_hp_bios_irq9,
  970. .ident = "HP Pavilion N5400 Series Laptop",
  971. .matches = {
  972. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  973. DMI_MATCH(DMI_BIOS_VERSION, "GE.M1.03"),
  974. DMI_MATCH(DMI_PRODUCT_VERSION,
  975. "HP Pavilion Notebook Model GE"),
  976. DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
  977. },
  978. },
  979. {
  980. .callback = fix_acer_tm360_irqrouting,
  981. .ident = "Acer TravelMate 36x Laptop",
  982. .matches = {
  983. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  984. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  985. },
  986. },
  987. { }
  988. };
  989. int __init pcibios_irq_init(void)
  990. {
  991. DBG(KERN_DEBUG "PCI: IRQ init\n");
  992. if (pcibios_enable_irq || raw_pci_ops == NULL)
  993. return 0;
  994. dmi_check_system(pciirq_dmi_table);
  995. pirq_table = pirq_find_routing_table();
  996. #ifdef CONFIG_PCI_BIOS
  997. if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN))
  998. pirq_table = pcibios_get_irq_routing_table();
  999. #endif
  1000. if (pirq_table) {
  1001. pirq_peer_trick();
  1002. pirq_find_router(&pirq_router);
  1003. if (pirq_table->exclusive_irqs) {
  1004. int i;
  1005. for (i = 0; i < 16; i++)
  1006. if (!(pirq_table->exclusive_irqs & (1 << i)))
  1007. pirq_penalty[i] += 100;
  1008. }
  1009. /*
  1010. * If we're using the I/O APIC, avoid using the PCI IRQ
  1011. * routing table
  1012. */
  1013. if (io_apic_assign_pci_irqs)
  1014. pirq_table = NULL;
  1015. }
  1016. pcibios_enable_irq = pirq_enable_irq;
  1017. pcibios_fixup_irqs();
  1018. if (io_apic_assign_pci_irqs && pci_routeirq) {
  1019. struct pci_dev *dev = NULL;
  1020. /*
  1021. * PCI IRQ routing is set up by pci_enable_device(), but we
  1022. * also do it here in case there are still broken drivers that
  1023. * don't use pci_enable_device().
  1024. */
  1025. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  1026. for_each_pci_dev(dev)
  1027. pirq_enable_irq(dev);
  1028. }
  1029. return 0;
  1030. }
  1031. static void pirq_penalize_isa_irq(int irq, int active)
  1032. {
  1033. /*
  1034. * If any ISAPnP device reports an IRQ in its list of possible
  1035. * IRQ's, we try to avoid assigning it to PCI devices.
  1036. */
  1037. if (irq < 16) {
  1038. if (active)
  1039. pirq_penalty[irq] += 1000;
  1040. else
  1041. pirq_penalty[irq] += 100;
  1042. }
  1043. }
  1044. void pcibios_penalize_isa_irq(int irq, int active)
  1045. {
  1046. #ifdef CONFIG_ACPI
  1047. if (!acpi_noirq)
  1048. acpi_penalize_isa_irq(irq, active);
  1049. else
  1050. #endif
  1051. pirq_penalize_isa_irq(irq, active);
  1052. }
  1053. static int pirq_enable_irq(struct pci_dev *dev)
  1054. {
  1055. u8 pin;
  1056. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  1057. if (pin && !pcibios_lookup_irq(dev, 1)) {
  1058. char *msg = "";
  1059. if (!io_apic_assign_pci_irqs && dev->irq)
  1060. return 0;
  1061. if (io_apic_assign_pci_irqs) {
  1062. #ifdef CONFIG_X86_IO_APIC
  1063. struct pci_dev *temp_dev;
  1064. int irq;
  1065. struct io_apic_irq_attr irq_attr;
  1066. irq = IO_APIC_get_PCI_irq_vector(dev->bus->number,
  1067. PCI_SLOT(dev->devfn),
  1068. pin - 1, &irq_attr);
  1069. /*
  1070. * Busses behind bridges are typically not listed in the MP-table.
  1071. * In this case we have to look up the IRQ based on the parent bus,
  1072. * parent slot, and pin number. The SMP code detects such bridged
  1073. * busses itself so we should get into this branch reliably.
  1074. */
  1075. temp_dev = dev;
  1076. while (irq < 0 && dev->bus->parent) { /* go back to the bridge */
  1077. struct pci_dev *bridge = dev->bus->self;
  1078. pin = pci_swizzle_interrupt_pin(dev, pin);
  1079. irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number,
  1080. PCI_SLOT(bridge->devfn),
  1081. pin - 1, &irq_attr);
  1082. if (irq >= 0)
  1083. dev_warn(&dev->dev, "using bridge %s "
  1084. "INT %c to get IRQ %d\n",
  1085. pci_name(bridge), 'A' + pin - 1,
  1086. irq);
  1087. dev = bridge;
  1088. }
  1089. dev = temp_dev;
  1090. if (irq >= 0) {
  1091. io_apic_set_pci_routing(&dev->dev, irq,
  1092. &irq_attr);
  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. }