irq.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Low-Level PCI Support for PC -- Routing of Interrupts
  4. *
  5. * (c) 1999--2000 Martin Mares <[email protected]>
  6. */
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/pci.h>
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/dmi.h>
  13. #include <linux/io.h>
  14. #include <linux/smp.h>
  15. #include <linux/spinlock.h>
  16. #include <asm/io_apic.h>
  17. #include <linux/irq.h>
  18. #include <linux/acpi.h>
  19. #include <asm/i8259.h>
  20. #include <asm/pc-conf-reg.h>
  21. #include <asm/pci_x86.h>
  22. #define PIRQ_SIGNATURE (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))
  23. #define PIRQ_VERSION 0x0100
  24. #define IRT_SIGNATURE (('$' << 0) + ('I' << 8) + ('R' << 16) + ('T' << 24))
  25. static int broken_hp_bios_irq9;
  26. static int acer_tm360_irqrouting;
  27. static struct irq_routing_table *pirq_table;
  28. static int pirq_enable_irq(struct pci_dev *dev);
  29. static void pirq_disable_irq(struct pci_dev *dev);
  30. /*
  31. * Never use: 0, 1, 2 (timer, keyboard, and cascade)
  32. * Avoid using: 13, 14 and 15 (FP error and IDE).
  33. * Penalize: 3, 4, 6, 7, 12 (known ISA uses: serial, floppy, parallel and mouse)
  34. */
  35. unsigned int pcibios_irq_mask = 0xfff8;
  36. static int pirq_penalty[16] = {
  37. 1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000,
  38. 0, 0, 0, 0, 1000, 100000, 100000, 100000
  39. };
  40. struct irq_router {
  41. char *name;
  42. u16 vendor, device;
  43. int (*get)(struct pci_dev *router, struct pci_dev *dev, int pirq);
  44. int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq,
  45. int new);
  46. int (*lvl)(struct pci_dev *router, struct pci_dev *dev, int pirq,
  47. int irq);
  48. };
  49. struct irq_router_handler {
  50. u16 vendor;
  51. int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
  52. };
  53. int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
  54. void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
  55. /*
  56. * Check passed address for the PCI IRQ Routing Table signature
  57. * and perform checksum verification.
  58. */
  59. static inline struct irq_routing_table *pirq_check_routing_table(u8 *addr,
  60. u8 *limit)
  61. {
  62. struct irq_routing_table *rt;
  63. int i;
  64. u8 sum;
  65. rt = (struct irq_routing_table *)addr;
  66. if (rt->signature != PIRQ_SIGNATURE ||
  67. rt->version != PIRQ_VERSION ||
  68. rt->size % 16 ||
  69. rt->size < sizeof(struct irq_routing_table) ||
  70. (limit && rt->size > limit - addr))
  71. return NULL;
  72. sum = 0;
  73. for (i = 0; i < rt->size; i++)
  74. sum += addr[i];
  75. if (!sum) {
  76. DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%lx\n",
  77. __pa(rt));
  78. return rt;
  79. }
  80. return NULL;
  81. }
  82. /*
  83. * Handle the $IRT PCI IRQ Routing Table format used by AMI for its BCP
  84. * (BIOS Configuration Program) external tool meant for tweaking BIOS
  85. * structures without the need to rebuild it from sources. The $IRT
  86. * format has been invented by AMI before Microsoft has come up with its
  87. * $PIR format and a $IRT table is therefore there in some systems that
  88. * lack a $PIR table.
  89. *
  90. * It uses the same PCI BIOS 2.1 format for interrupt routing entries
  91. * themselves but has a different simpler header prepended instead,
  92. * occupying 8 bytes, where a `$IRT' signature is followed by one byte
  93. * specifying the total number of interrupt routing entries allocated in
  94. * the table, then one byte specifying the actual number of entries used
  95. * (which the BCP tool can take advantage of when modifying the table),
  96. * and finally a 16-bit word giving the IRQs devoted exclusively to PCI.
  97. * Unlike with the $PIR table there is no alignment guarantee.
  98. *
  99. * Given the similarity of the two formats the $IRT one is trivial to
  100. * convert to the $PIR one, which we do here, except that obviously we
  101. * have no information as to the router device to use, but we can handle
  102. * it by matching PCI device IDs actually seen on the bus against ones
  103. * that our individual routers recognise.
  104. *
  105. * Reportedly there is another $IRT table format where a 16-bit word
  106. * follows the header instead that points to interrupt routing entries
  107. * in a $PIR table provided elsewhere. In that case this code will not
  108. * be reached though as the $PIR table will have been chosen instead.
  109. */
  110. static inline struct irq_routing_table *pirq_convert_irt_table(u8 *addr,
  111. u8 *limit)
  112. {
  113. struct irt_routing_table *ir;
  114. struct irq_routing_table *rt;
  115. u16 size;
  116. u8 sum;
  117. int i;
  118. ir = (struct irt_routing_table *)addr;
  119. if (ir->signature != IRT_SIGNATURE || !ir->used || ir->size < ir->used)
  120. return NULL;
  121. size = sizeof(*ir) + ir->used * sizeof(ir->slots[0]);
  122. if (size > limit - addr)
  123. return NULL;
  124. DBG(KERN_DEBUG "PCI: $IRT Interrupt Routing Table found at 0x%lx\n",
  125. __pa(ir));
  126. size = sizeof(*rt) + ir->used * sizeof(rt->slots[0]);
  127. rt = kzalloc(size, GFP_KERNEL);
  128. if (!rt)
  129. return NULL;
  130. rt->signature = PIRQ_SIGNATURE;
  131. rt->version = PIRQ_VERSION;
  132. rt->size = size;
  133. rt->exclusive_irqs = ir->exclusive_irqs;
  134. for (i = 0; i < ir->used; i++)
  135. rt->slots[i] = ir->slots[i];
  136. addr = (u8 *)rt;
  137. sum = 0;
  138. for (i = 0; i < size; i++)
  139. sum += addr[i];
  140. rt->checksum = -sum;
  141. return rt;
  142. }
  143. /*
  144. * Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table.
  145. */
  146. static struct irq_routing_table * __init pirq_find_routing_table(void)
  147. {
  148. u8 * const bios_start = (u8 *)__va(0xf0000);
  149. u8 * const bios_end = (u8 *)__va(0x100000);
  150. u8 *addr;
  151. struct irq_routing_table *rt;
  152. if (pirq_table_addr) {
  153. rt = pirq_check_routing_table((u8 *)__va(pirq_table_addr),
  154. NULL);
  155. if (rt)
  156. return rt;
  157. printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n");
  158. }
  159. for (addr = bios_start;
  160. addr < bios_end - sizeof(struct irq_routing_table);
  161. addr += 16) {
  162. rt = pirq_check_routing_table(addr, bios_end);
  163. if (rt)
  164. return rt;
  165. }
  166. for (addr = bios_start;
  167. addr < bios_end - sizeof(struct irt_routing_table);
  168. addr++) {
  169. rt = pirq_convert_irt_table(addr, bios_end);
  170. if (rt)
  171. return rt;
  172. }
  173. return NULL;
  174. }
  175. /*
  176. * If we have a IRQ routing table, use it to search for peer host
  177. * bridges. It's a gross hack, but since there are no other known
  178. * ways how to get a list of buses, we have to go this way.
  179. */
  180. static void __init pirq_peer_trick(void)
  181. {
  182. struct irq_routing_table *rt = pirq_table;
  183. u8 busmap[256];
  184. int i;
  185. struct irq_info *e;
  186. memset(busmap, 0, sizeof(busmap));
  187. for (i = 0; i < (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); i++) {
  188. e = &rt->slots[i];
  189. #ifdef DEBUG
  190. {
  191. int j;
  192. DBG(KERN_DEBUG "%02x:%02x.%x slot=%02x",
  193. e->bus, e->devfn / 8, e->devfn % 8, e->slot);
  194. for (j = 0; j < 4; j++)
  195. DBG(" %d:%02x/%04x", j, e->irq[j].link, e->irq[j].bitmap);
  196. DBG("\n");
  197. }
  198. #endif
  199. busmap[e->bus] = 1;
  200. }
  201. for (i = 1; i < 256; i++) {
  202. if (!busmap[i] || pci_find_bus(0, i))
  203. continue;
  204. pcibios_scan_root(i);
  205. }
  206. pcibios_last_bus = -1;
  207. }
  208. /*
  209. * Code for querying and setting of IRQ routes on various interrupt routers.
  210. * PIC Edge/Level Control Registers (ELCR) 0x4d0 & 0x4d1.
  211. */
  212. void elcr_set_level_irq(unsigned int irq)
  213. {
  214. unsigned char mask = 1 << (irq & 7);
  215. unsigned int port = PIC_ELCR1 + (irq >> 3);
  216. unsigned char val;
  217. static u16 elcr_irq_mask;
  218. if (irq >= 16 || (1 << irq) & elcr_irq_mask)
  219. return;
  220. elcr_irq_mask |= (1 << irq);
  221. printk(KERN_DEBUG "PCI: setting IRQ %u as level-triggered\n", irq);
  222. val = inb(port);
  223. if (!(val & mask)) {
  224. DBG(KERN_DEBUG " -> edge");
  225. outb(val | mask, port);
  226. }
  227. }
  228. /*
  229. * PIRQ routing for the M1487 ISA Bus Controller (IBC) ASIC used
  230. * with the ALi FinALi 486 chipset. The IBC is not decoded in the
  231. * PCI configuration space, so we identify it by the accompanying
  232. * M1489 Cache-Memory PCI Controller (CMP) ASIC.
  233. *
  234. * There are four 4-bit mappings provided, spread across two PCI
  235. * INTx Routing Table Mapping Registers, available in the port I/O
  236. * space accessible indirectly via the index/data register pair at
  237. * 0x22/0x23, located at indices 0x42 and 0x43 for the INT1/INT2
  238. * and INT3/INT4 lines respectively. The INT1/INT3 and INT2/INT4
  239. * lines are mapped in the low and the high 4-bit nibble of the
  240. * corresponding register as follows:
  241. *
  242. * 0000 : Disabled
  243. * 0001 : IRQ9
  244. * 0010 : IRQ3
  245. * 0011 : IRQ10
  246. * 0100 : IRQ4
  247. * 0101 : IRQ5
  248. * 0110 : IRQ7
  249. * 0111 : IRQ6
  250. * 1000 : Reserved
  251. * 1001 : IRQ11
  252. * 1010 : Reserved
  253. * 1011 : IRQ12
  254. * 1100 : Reserved
  255. * 1101 : IRQ14
  256. * 1110 : Reserved
  257. * 1111 : IRQ15
  258. *
  259. * In addition to the usual ELCR register pair there is a separate
  260. * PCI INTx Sensitivity Register at index 0x44 in the same port I/O
  261. * space, whose bits 3:0 select the trigger mode for INT[4:1] lines
  262. * respectively. Any bit set to 1 causes interrupts coming on the
  263. * corresponding line to be passed to ISA as edge-triggered and
  264. * otherwise they are passed as level-triggered. Manufacturer's
  265. * documentation says this register has to be set consistently with
  266. * the relevant ELCR register.
  267. *
  268. * Accesses to the port I/O space concerned here need to be unlocked
  269. * by writing the value of 0xc5 to the Lock Register at index 0x03
  270. * beforehand. Any other value written to said register prevents
  271. * further accesses from reaching the register file, except for the
  272. * Lock Register being written with 0xc5 again.
  273. *
  274. * References:
  275. *
  276. * "M1489/M1487: 486 PCI Chip Set", Version 1.2, Acer Laboratories
  277. * Inc., July 1997
  278. */
  279. #define PC_CONF_FINALI_LOCK 0x03u
  280. #define PC_CONF_FINALI_PCI_INTX_RT1 0x42u
  281. #define PC_CONF_FINALI_PCI_INTX_RT2 0x43u
  282. #define PC_CONF_FINALI_PCI_INTX_SENS 0x44u
  283. #define PC_CONF_FINALI_LOCK_KEY 0xc5u
  284. static u8 read_pc_conf_nybble(u8 base, u8 index)
  285. {
  286. u8 reg = base + (index >> 1);
  287. u8 x;
  288. x = pc_conf_get(reg);
  289. return index & 1 ? x >> 4 : x & 0xf;
  290. }
  291. static void write_pc_conf_nybble(u8 base, u8 index, u8 val)
  292. {
  293. u8 reg = base + (index >> 1);
  294. u8 x;
  295. x = pc_conf_get(reg);
  296. x = index & 1 ? (x & 0x0f) | (val << 4) : (x & 0xf0) | val;
  297. pc_conf_set(reg, x);
  298. }
  299. /*
  300. * FinALi pirq rules are as follows:
  301. *
  302. * - bit 0 selects between INTx Routing Table Mapping Registers,
  303. *
  304. * - bit 3 selects the nibble within the INTx Routing Table Mapping Register,
  305. *
  306. * - bits 7:4 map to bits 3:0 of the PCI INTx Sensitivity Register.
  307. */
  308. static int pirq_finali_get(struct pci_dev *router, struct pci_dev *dev,
  309. int pirq)
  310. {
  311. static const u8 irqmap[16] = {
  312. 0, 9, 3, 10, 4, 5, 7, 6, 0, 11, 0, 12, 0, 14, 0, 15
  313. };
  314. unsigned long flags;
  315. u8 index;
  316. u8 x;
  317. index = (pirq & 1) << 1 | (pirq & 8) >> 3;
  318. raw_spin_lock_irqsave(&pc_conf_lock, flags);
  319. pc_conf_set(PC_CONF_FINALI_LOCK, PC_CONF_FINALI_LOCK_KEY);
  320. x = irqmap[read_pc_conf_nybble(PC_CONF_FINALI_PCI_INTX_RT1, index)];
  321. pc_conf_set(PC_CONF_FINALI_LOCK, 0);
  322. raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
  323. return x;
  324. }
  325. static int pirq_finali_set(struct pci_dev *router, struct pci_dev *dev,
  326. int pirq, int irq)
  327. {
  328. static const u8 irqmap[16] = {
  329. 0, 0, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15
  330. };
  331. u8 val = irqmap[irq];
  332. unsigned long flags;
  333. u8 index;
  334. if (!val)
  335. return 0;
  336. index = (pirq & 1) << 1 | (pirq & 8) >> 3;
  337. raw_spin_lock_irqsave(&pc_conf_lock, flags);
  338. pc_conf_set(PC_CONF_FINALI_LOCK, PC_CONF_FINALI_LOCK_KEY);
  339. write_pc_conf_nybble(PC_CONF_FINALI_PCI_INTX_RT1, index, val);
  340. pc_conf_set(PC_CONF_FINALI_LOCK, 0);
  341. raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
  342. return 1;
  343. }
  344. static int pirq_finali_lvl(struct pci_dev *router, struct pci_dev *dev,
  345. int pirq, int irq)
  346. {
  347. u8 mask = ~((pirq & 0xf0u) >> 4);
  348. unsigned long flags;
  349. u8 trig;
  350. elcr_set_level_irq(irq);
  351. raw_spin_lock_irqsave(&pc_conf_lock, flags);
  352. pc_conf_set(PC_CONF_FINALI_LOCK, PC_CONF_FINALI_LOCK_KEY);
  353. trig = pc_conf_get(PC_CONF_FINALI_PCI_INTX_SENS);
  354. trig &= mask;
  355. pc_conf_set(PC_CONF_FINALI_PCI_INTX_SENS, trig);
  356. pc_conf_set(PC_CONF_FINALI_LOCK, 0);
  357. raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
  358. return 1;
  359. }
  360. /*
  361. * Common IRQ routing practice: nibbles in config space,
  362. * offset by some magic constant.
  363. */
  364. static unsigned int read_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr)
  365. {
  366. u8 x;
  367. unsigned reg = offset + (nr >> 1);
  368. pci_read_config_byte(router, reg, &x);
  369. return (nr & 1) ? (x >> 4) : (x & 0xf);
  370. }
  371. static void write_config_nybble(struct pci_dev *router, unsigned offset,
  372. unsigned nr, unsigned int val)
  373. {
  374. u8 x;
  375. unsigned reg = offset + (nr >> 1);
  376. pci_read_config_byte(router, reg, &x);
  377. x = (nr & 1) ? ((x & 0x0f) | (val << 4)) : ((x & 0xf0) | val);
  378. pci_write_config_byte(router, reg, x);
  379. }
  380. /*
  381. * ALI pirq entries are damn ugly, and completely undocumented.
  382. * This has been figured out from pirq tables, and it's not a pretty
  383. * picture.
  384. */
  385. static int pirq_ali_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  386. {
  387. static const unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };
  388. WARN_ON_ONCE(pirq > 16);
  389. return irqmap[read_config_nybble(router, 0x48, pirq-1)];
  390. }
  391. static int pirq_ali_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  392. {
  393. static const unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };
  394. unsigned int val = irqmap[irq];
  395. WARN_ON_ONCE(pirq > 16);
  396. if (val) {
  397. write_config_nybble(router, 0x48, pirq-1, val);
  398. return 1;
  399. }
  400. return 0;
  401. }
  402. /*
  403. * PIRQ routing for the 82374EB/82374SB EISA System Component (ESC)
  404. * ASIC used with the Intel 82420 and 82430 PCIsets. The ESC is not
  405. * decoded in the PCI configuration space, so we identify it by the
  406. * accompanying 82375EB/82375SB PCI-EISA Bridge (PCEB) ASIC.
  407. *
  408. * There are four PIRQ Route Control registers, available in the
  409. * port I/O space accessible indirectly via the index/data register
  410. * pair at 0x22/0x23, located at indices 0x60/0x61/0x62/0x63 for the
  411. * PIRQ0/1/2/3# lines respectively. The semantics is the same as
  412. * with the PIIX router.
  413. *
  414. * Accesses to the port I/O space concerned here need to be unlocked
  415. * by writing the value of 0x0f to the ESC ID Register at index 0x02
  416. * beforehand. Any other value written to said register prevents
  417. * further accesses from reaching the register file, except for the
  418. * ESC ID Register being written with 0x0f again.
  419. *
  420. * References:
  421. *
  422. * "82374EB/82374SB EISA System Component (ESC)", Intel Corporation,
  423. * Order Number: 290476-004, March 1996
  424. *
  425. * "82375EB/82375SB PCI-EISA Bridge (PCEB)", Intel Corporation, Order
  426. * Number: 290477-004, March 1996
  427. */
  428. #define PC_CONF_I82374_ESC_ID 0x02u
  429. #define PC_CONF_I82374_PIRQ_ROUTE_CONTROL 0x60u
  430. #define PC_CONF_I82374_ESC_ID_KEY 0x0fu
  431. static int pirq_esc_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  432. {
  433. unsigned long flags;
  434. int reg;
  435. u8 x;
  436. reg = pirq;
  437. if (reg >= 1 && reg <= 4)
  438. reg += PC_CONF_I82374_PIRQ_ROUTE_CONTROL - 1;
  439. raw_spin_lock_irqsave(&pc_conf_lock, flags);
  440. pc_conf_set(PC_CONF_I82374_ESC_ID, PC_CONF_I82374_ESC_ID_KEY);
  441. x = pc_conf_get(reg);
  442. pc_conf_set(PC_CONF_I82374_ESC_ID, 0);
  443. raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
  444. return (x < 16) ? x : 0;
  445. }
  446. static int pirq_esc_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
  447. int irq)
  448. {
  449. unsigned long flags;
  450. int reg;
  451. reg = pirq;
  452. if (reg >= 1 && reg <= 4)
  453. reg += PC_CONF_I82374_PIRQ_ROUTE_CONTROL - 1;
  454. raw_spin_lock_irqsave(&pc_conf_lock, flags);
  455. pc_conf_set(PC_CONF_I82374_ESC_ID, PC_CONF_I82374_ESC_ID_KEY);
  456. pc_conf_set(reg, irq);
  457. pc_conf_set(PC_CONF_I82374_ESC_ID, 0);
  458. raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
  459. return 1;
  460. }
  461. /*
  462. * The Intel PIIX4 pirq rules are fairly simple: "pirq" is
  463. * just a pointer to the config space.
  464. */
  465. static int pirq_piix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  466. {
  467. u8 x;
  468. pci_read_config_byte(router, pirq, &x);
  469. return (x < 16) ? x : 0;
  470. }
  471. static int pirq_piix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  472. {
  473. pci_write_config_byte(router, pirq, irq);
  474. return 1;
  475. }
  476. /*
  477. * PIRQ routing for the 82426EX ISA Bridge (IB) ASIC used with the
  478. * Intel 82420EX PCIset.
  479. *
  480. * There are only two PIRQ Route Control registers, available in the
  481. * combined 82425EX/82426EX PCI configuration space, at 0x66 and 0x67
  482. * for the PIRQ0# and PIRQ1# lines respectively. The semantics is
  483. * the same as with the PIIX router.
  484. *
  485. * References:
  486. *
  487. * "82420EX PCIset Data Sheet, 82425EX PCI System Controller (PSC)
  488. * and 82426EX ISA Bridge (IB)", Intel Corporation, Order Number:
  489. * 290488-004, December 1995
  490. */
  491. #define PCI_I82426EX_PIRQ_ROUTE_CONTROL 0x66u
  492. static int pirq_ib_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  493. {
  494. int reg;
  495. u8 x;
  496. reg = pirq;
  497. if (reg >= 1 && reg <= 2)
  498. reg += PCI_I82426EX_PIRQ_ROUTE_CONTROL - 1;
  499. pci_read_config_byte(router, reg, &x);
  500. return (x < 16) ? x : 0;
  501. }
  502. static int pirq_ib_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
  503. int irq)
  504. {
  505. int reg;
  506. reg = pirq;
  507. if (reg >= 1 && reg <= 2)
  508. reg += PCI_I82426EX_PIRQ_ROUTE_CONTROL - 1;
  509. pci_write_config_byte(router, reg, irq);
  510. return 1;
  511. }
  512. /*
  513. * The VIA pirq rules are nibble-based, like ALI,
  514. * but without the ugly irq number munging.
  515. * However, PIRQD is in the upper instead of lower 4 bits.
  516. */
  517. static int pirq_via_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  518. {
  519. return read_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq);
  520. }
  521. static int pirq_via_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  522. {
  523. write_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq, irq);
  524. return 1;
  525. }
  526. /*
  527. * The VIA pirq rules are nibble-based, like ALI,
  528. * but without the ugly irq number munging.
  529. * However, for 82C586, nibble map is different .
  530. */
  531. static int pirq_via586_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  532. {
  533. static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
  534. WARN_ON_ONCE(pirq > 5);
  535. return read_config_nybble(router, 0x55, pirqmap[pirq-1]);
  536. }
  537. static int pirq_via586_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  538. {
  539. static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
  540. WARN_ON_ONCE(pirq > 5);
  541. write_config_nybble(router, 0x55, pirqmap[pirq-1], irq);
  542. return 1;
  543. }
  544. /*
  545. * ITE 8330G pirq rules are nibble-based
  546. * FIXME: pirqmap may be { 1, 0, 3, 2 },
  547. * 2+3 are both mapped to irq 9 on my system
  548. */
  549. static int pirq_ite_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  550. {
  551. static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
  552. WARN_ON_ONCE(pirq > 4);
  553. return read_config_nybble(router, 0x43, pirqmap[pirq-1]);
  554. }
  555. static int pirq_ite_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  556. {
  557. static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
  558. WARN_ON_ONCE(pirq > 4);
  559. write_config_nybble(router, 0x43, pirqmap[pirq-1], irq);
  560. return 1;
  561. }
  562. /*
  563. * OPTI: high four bits are nibble pointer..
  564. * I wonder what the low bits do?
  565. */
  566. static int pirq_opti_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  567. {
  568. return read_config_nybble(router, 0xb8, pirq >> 4);
  569. }
  570. static int pirq_opti_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  571. {
  572. write_config_nybble(router, 0xb8, pirq >> 4, irq);
  573. return 1;
  574. }
  575. /*
  576. * Cyrix: nibble offset 0x5C
  577. * 0x5C bits 7:4 is INTB bits 3:0 is INTA
  578. * 0x5D bits 7:4 is INTD bits 3:0 is INTC
  579. */
  580. static int pirq_cyrix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  581. {
  582. return read_config_nybble(router, 0x5C, (pirq-1)^1);
  583. }
  584. static int pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  585. {
  586. write_config_nybble(router, 0x5C, (pirq-1)^1, irq);
  587. return 1;
  588. }
  589. /*
  590. * PIRQ routing for the SiS85C497 AT Bus Controller & Megacell (ATM)
  591. * ISA bridge used with the SiS 85C496/497 486 Green PC VESA/ISA/PCI
  592. * Chipset.
  593. *
  594. * There are four PCI INTx#-to-IRQ Link registers provided in the
  595. * SiS85C497 part of the peculiar combined 85C496/497 configuration
  596. * space decoded by the SiS85C496 PCI & CPU Memory Controller (PCM)
  597. * host bridge, at 0xc0/0xc1/0xc2/0xc3 respectively for the PCI INT
  598. * A/B/C/D lines. Bit 7 enables the respective link if set and bits
  599. * 3:0 select the 8259A IRQ line as follows:
  600. *
  601. * 0000 : Reserved
  602. * 0001 : Reserved
  603. * 0010 : Reserved
  604. * 0011 : IRQ3
  605. * 0100 : IRQ4
  606. * 0101 : IRQ5
  607. * 0110 : IRQ6
  608. * 0111 : IRQ7
  609. * 1000 : Reserved
  610. * 1001 : IRQ9
  611. * 1010 : IRQ10
  612. * 1011 : IRQ11
  613. * 1100 : IRQ12
  614. * 1101 : Reserved
  615. * 1110 : IRQ14
  616. * 1111 : IRQ15
  617. *
  618. * We avoid using a reserved value for disabled links, hence the
  619. * choice of IRQ15 for that case.
  620. *
  621. * References:
  622. *
  623. * "486 Green PC VESA/ISA/PCI Chipset, SiS 85C496/497", Rev 3.0,
  624. * Silicon Integrated Systems Corp., July 1995
  625. */
  626. #define PCI_SIS497_INTA_TO_IRQ_LINK 0xc0u
  627. #define PIRQ_SIS497_IRQ_MASK 0x0fu
  628. #define PIRQ_SIS497_IRQ_ENABLE 0x80u
  629. static int pirq_sis497_get(struct pci_dev *router, struct pci_dev *dev,
  630. int pirq)
  631. {
  632. int reg;
  633. u8 x;
  634. reg = pirq;
  635. if (reg >= 1 && reg <= 4)
  636. reg += PCI_SIS497_INTA_TO_IRQ_LINK - 1;
  637. pci_read_config_byte(router, reg, &x);
  638. return (x & PIRQ_SIS497_IRQ_ENABLE) ? (x & PIRQ_SIS497_IRQ_MASK) : 0;
  639. }
  640. static int pirq_sis497_set(struct pci_dev *router, struct pci_dev *dev,
  641. int pirq, int irq)
  642. {
  643. int reg;
  644. u8 x;
  645. reg = pirq;
  646. if (reg >= 1 && reg <= 4)
  647. reg += PCI_SIS497_INTA_TO_IRQ_LINK - 1;
  648. pci_read_config_byte(router, reg, &x);
  649. x &= ~(PIRQ_SIS497_IRQ_MASK | PIRQ_SIS497_IRQ_ENABLE);
  650. x |= irq ? (PIRQ_SIS497_IRQ_ENABLE | irq) : PIRQ_SIS497_IRQ_MASK;
  651. pci_write_config_byte(router, reg, x);
  652. return 1;
  653. }
  654. /*
  655. * PIRQ routing for SiS 85C503 router used in several SiS chipsets.
  656. * We have to deal with the following issues here:
  657. * - vendors have different ideas about the meaning of link values
  658. * - some onboard devices (integrated in the chipset) have special
  659. * links and are thus routed differently (i.e. not via PCI INTA-INTD)
  660. * - different revision of the router have a different layout for
  661. * the routing registers, particularly for the onchip devices
  662. *
  663. * For all routing registers the common thing is we have one byte
  664. * per routeable link which is defined as:
  665. * bit 7 IRQ mapping enabled (0) or disabled (1)
  666. * bits [6:4] reserved (sometimes used for onchip devices)
  667. * bits [3:0] IRQ to map to
  668. * allowed: 3-7, 9-12, 14-15
  669. * reserved: 0, 1, 2, 8, 13
  670. *
  671. * The config-space registers located at 0x41/0x42/0x43/0x44 are
  672. * always used to route the normal PCI INT A/B/C/D respectively.
  673. * Apparently there are systems implementing PCI routing table using
  674. * link values 0x01-0x04 and others using 0x41-0x44 for PCI INTA..D.
  675. * We try our best to handle both link mappings.
  676. *
  677. * Currently (2003-05-21) it appears most SiS chipsets follow the
  678. * definition of routing registers from the SiS-5595 southbridge.
  679. * According to the SiS 5595 datasheets the revision id's of the
  680. * router (ISA-bridge) should be 0x01 or 0xb0.
  681. *
  682. * Furthermore we've also seen lspci dumps with revision 0x00 and 0xb1.
  683. * Looks like these are used in a number of SiS 5xx/6xx/7xx chipsets.
  684. * They seem to work with the current routing code. However there is
  685. * some concern because of the two USB-OHCI HCs (original SiS 5595
  686. * had only one). YMMV.
  687. *
  688. * Onchip routing for router rev-id 0x01/0xb0 and probably 0x00/0xb1:
  689. *
  690. * 0x61: IDEIRQ:
  691. * bits [6:5] must be written 01
  692. * bit 4 channel-select primary (0), secondary (1)
  693. *
  694. * 0x62: USBIRQ:
  695. * bit 6 OHCI function disabled (0), enabled (1)
  696. *
  697. * 0x6a: ACPI/SCI IRQ: bits 4-6 reserved
  698. *
  699. * 0x7e: Data Acq. Module IRQ - bits 4-6 reserved
  700. *
  701. * We support USBIRQ (in addition to INTA-INTD) and keep the
  702. * IDE, ACPI and DAQ routing untouched as set by the BIOS.
  703. *
  704. * Currently the only reported exception is the new SiS 65x chipset
  705. * which includes the SiS 69x southbridge. Here we have the 85C503
  706. * router revision 0x04 and there are changes in the register layout
  707. * mostly related to the different USB HCs with USB 2.0 support.
  708. *
  709. * Onchip routing for router rev-id 0x04 (try-and-error observation)
  710. *
  711. * 0x60/0x61/0x62/0x63: 1xEHCI and 3xOHCI (companion) USB-HCs
  712. * bit 6-4 are probably unused, not like 5595
  713. */
  714. #define PIRQ_SIS503_IRQ_MASK 0x0f
  715. #define PIRQ_SIS503_IRQ_DISABLE 0x80
  716. #define PIRQ_SIS503_USB_ENABLE 0x40
  717. static int pirq_sis503_get(struct pci_dev *router, struct pci_dev *dev,
  718. int pirq)
  719. {
  720. u8 x;
  721. int reg;
  722. reg = pirq;
  723. if (reg >= 0x01 && reg <= 0x04)
  724. reg += 0x40;
  725. pci_read_config_byte(router, reg, &x);
  726. return (x & PIRQ_SIS503_IRQ_DISABLE) ? 0 : (x & PIRQ_SIS503_IRQ_MASK);
  727. }
  728. static int pirq_sis503_set(struct pci_dev *router, struct pci_dev *dev,
  729. int pirq, int irq)
  730. {
  731. u8 x;
  732. int reg;
  733. reg = pirq;
  734. if (reg >= 0x01 && reg <= 0x04)
  735. reg += 0x40;
  736. pci_read_config_byte(router, reg, &x);
  737. x &= ~(PIRQ_SIS503_IRQ_MASK | PIRQ_SIS503_IRQ_DISABLE);
  738. x |= irq ? irq : PIRQ_SIS503_IRQ_DISABLE;
  739. pci_write_config_byte(router, reg, x);
  740. return 1;
  741. }
  742. /*
  743. * VLSI: nibble offset 0x74 - educated guess due to routing table and
  744. * config space of VLSI 82C534 PCI-bridge/router (1004:0102)
  745. * Tested on HP OmniBook 800 covering PIRQ 1, 2, 4, 8 for onboard
  746. * devices, PIRQ 3 for non-pci(!) soundchip and (untested) PIRQ 6
  747. * for the busbridge to the docking station.
  748. */
  749. static int pirq_vlsi_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  750. {
  751. WARN_ON_ONCE(pirq >= 9);
  752. if (pirq > 8) {
  753. dev_info(&dev->dev, "VLSI router PIRQ escape (%d)\n", pirq);
  754. return 0;
  755. }
  756. return read_config_nybble(router, 0x74, pirq-1);
  757. }
  758. static int pirq_vlsi_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  759. {
  760. WARN_ON_ONCE(pirq >= 9);
  761. if (pirq > 8) {
  762. dev_info(&dev->dev, "VLSI router PIRQ escape (%d)\n", pirq);
  763. return 0;
  764. }
  765. write_config_nybble(router, 0x74, pirq-1, irq);
  766. return 1;
  767. }
  768. /*
  769. * ServerWorks: PCI interrupts mapped to system IRQ lines through Index
  770. * and Redirect I/O registers (0x0c00 and 0x0c01). The Index register
  771. * format is (PCIIRQ## | 0x10), e.g.: PCIIRQ10=0x1a. The Redirect
  772. * register is a straight binary coding of desired PIC IRQ (low nibble).
  773. *
  774. * The 'link' value in the PIRQ table is already in the correct format
  775. * for the Index register. There are some special index values:
  776. * 0x00 for ACPI (SCI), 0x01 for USB, 0x02 for IDE0, 0x04 for IDE1,
  777. * and 0x03 for SMBus.
  778. */
  779. static int pirq_serverworks_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  780. {
  781. outb(pirq, 0xc00);
  782. return inb(0xc01) & 0xf;
  783. }
  784. static int pirq_serverworks_set(struct pci_dev *router, struct pci_dev *dev,
  785. int pirq, int irq)
  786. {
  787. outb(pirq, 0xc00);
  788. outb(irq, 0xc01);
  789. return 1;
  790. }
  791. /* Support for AMD756 PCI IRQ Routing
  792. * Jhon H. Caicedo <[email protected]>
  793. * Jun/21/2001 0.2.0 Release, fixed to use "nybble" functions... (jhcaiced)
  794. * Jun/19/2001 Alpha Release 0.1.0 (jhcaiced)
  795. * The AMD756 pirq rules are nibble-based
  796. * offset 0x56 0-3 PIRQA 4-7 PIRQB
  797. * offset 0x57 0-3 PIRQC 4-7 PIRQD
  798. */
  799. static int pirq_amd756_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  800. {
  801. u8 irq;
  802. irq = 0;
  803. if (pirq <= 4)
  804. irq = read_config_nybble(router, 0x56, pirq - 1);
  805. dev_info(&dev->dev,
  806. "AMD756: dev [%04x:%04x], router PIRQ %d get IRQ %d\n",
  807. dev->vendor, dev->device, pirq, irq);
  808. return irq;
  809. }
  810. static int pirq_amd756_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  811. {
  812. dev_info(&dev->dev,
  813. "AMD756: dev [%04x:%04x], router PIRQ %d set IRQ %d\n",
  814. dev->vendor, dev->device, pirq, irq);
  815. if (pirq <= 4)
  816. write_config_nybble(router, 0x56, pirq - 1, irq);
  817. return 1;
  818. }
  819. /*
  820. * PicoPower PT86C523
  821. */
  822. static int pirq_pico_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
  823. {
  824. outb(0x10 + ((pirq - 1) >> 1), 0x24);
  825. return ((pirq - 1) & 1) ? (inb(0x26) >> 4) : (inb(0x26) & 0xf);
  826. }
  827. static int pirq_pico_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
  828. int irq)
  829. {
  830. unsigned int x;
  831. outb(0x10 + ((pirq - 1) >> 1), 0x24);
  832. x = inb(0x26);
  833. x = ((pirq - 1) & 1) ? ((x & 0x0f) | (irq << 4)) : ((x & 0xf0) | (irq));
  834. outb(x, 0x26);
  835. return 1;
  836. }
  837. #ifdef CONFIG_PCI_BIOS
  838. static int pirq_bios_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
  839. {
  840. struct pci_dev *bridge;
  841. int pin = pci_get_interrupt_pin(dev, &bridge);
  842. return pcibios_set_irq_routing(bridge, pin - 1, irq);
  843. }
  844. #endif
  845. static __init int intel_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  846. {
  847. static struct pci_device_id __initdata pirq_440gx[] = {
  848. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
  849. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
  850. { },
  851. };
  852. /* 440GX has a proprietary PIRQ router -- don't use it */
  853. if (pci_dev_present(pirq_440gx))
  854. return 0;
  855. switch (device) {
  856. case PCI_DEVICE_ID_INTEL_82375:
  857. r->name = "PCEB/ESC";
  858. r->get = pirq_esc_get;
  859. r->set = pirq_esc_set;
  860. return 1;
  861. case PCI_DEVICE_ID_INTEL_82371FB_0:
  862. case PCI_DEVICE_ID_INTEL_82371SB_0:
  863. case PCI_DEVICE_ID_INTEL_82371AB_0:
  864. case PCI_DEVICE_ID_INTEL_82371MX:
  865. case PCI_DEVICE_ID_INTEL_82443MX_0:
  866. case PCI_DEVICE_ID_INTEL_82801AA_0:
  867. case PCI_DEVICE_ID_INTEL_82801AB_0:
  868. case PCI_DEVICE_ID_INTEL_82801BA_0:
  869. case PCI_DEVICE_ID_INTEL_82801BA_10:
  870. case PCI_DEVICE_ID_INTEL_82801CA_0:
  871. case PCI_DEVICE_ID_INTEL_82801CA_12:
  872. case PCI_DEVICE_ID_INTEL_82801DB_0:
  873. case PCI_DEVICE_ID_INTEL_82801E_0:
  874. case PCI_DEVICE_ID_INTEL_82801EB_0:
  875. case PCI_DEVICE_ID_INTEL_ESB_1:
  876. case PCI_DEVICE_ID_INTEL_ICH6_0:
  877. case PCI_DEVICE_ID_INTEL_ICH6_1:
  878. case PCI_DEVICE_ID_INTEL_ICH7_0:
  879. case PCI_DEVICE_ID_INTEL_ICH7_1:
  880. case PCI_DEVICE_ID_INTEL_ICH7_30:
  881. case PCI_DEVICE_ID_INTEL_ICH7_31:
  882. case PCI_DEVICE_ID_INTEL_TGP_LPC:
  883. case PCI_DEVICE_ID_INTEL_ESB2_0:
  884. case PCI_DEVICE_ID_INTEL_ICH8_0:
  885. case PCI_DEVICE_ID_INTEL_ICH8_1:
  886. case PCI_DEVICE_ID_INTEL_ICH8_2:
  887. case PCI_DEVICE_ID_INTEL_ICH8_3:
  888. case PCI_DEVICE_ID_INTEL_ICH8_4:
  889. case PCI_DEVICE_ID_INTEL_ICH9_0:
  890. case PCI_DEVICE_ID_INTEL_ICH9_1:
  891. case PCI_DEVICE_ID_INTEL_ICH9_2:
  892. case PCI_DEVICE_ID_INTEL_ICH9_3:
  893. case PCI_DEVICE_ID_INTEL_ICH9_4:
  894. case PCI_DEVICE_ID_INTEL_ICH9_5:
  895. case PCI_DEVICE_ID_INTEL_EP80579_0:
  896. case PCI_DEVICE_ID_INTEL_ICH10_0:
  897. case PCI_DEVICE_ID_INTEL_ICH10_1:
  898. case PCI_DEVICE_ID_INTEL_ICH10_2:
  899. case PCI_DEVICE_ID_INTEL_ICH10_3:
  900. case PCI_DEVICE_ID_INTEL_PATSBURG_LPC_0:
  901. case PCI_DEVICE_ID_INTEL_PATSBURG_LPC_1:
  902. r->name = "PIIX/ICH";
  903. r->get = pirq_piix_get;
  904. r->set = pirq_piix_set;
  905. return 1;
  906. case PCI_DEVICE_ID_INTEL_82425:
  907. r->name = "PSC/IB";
  908. r->get = pirq_ib_get;
  909. r->set = pirq_ib_set;
  910. return 1;
  911. }
  912. if ((device >= PCI_DEVICE_ID_INTEL_5_3400_SERIES_LPC_MIN &&
  913. device <= PCI_DEVICE_ID_INTEL_5_3400_SERIES_LPC_MAX)
  914. || (device >= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MIN &&
  915. device <= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MAX)
  916. || (device >= PCI_DEVICE_ID_INTEL_DH89XXCC_LPC_MIN &&
  917. device <= PCI_DEVICE_ID_INTEL_DH89XXCC_LPC_MAX)
  918. || (device >= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MIN &&
  919. device <= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MAX)) {
  920. r->name = "PIIX/ICH";
  921. r->get = pirq_piix_get;
  922. r->set = pirq_piix_set;
  923. return 1;
  924. }
  925. return 0;
  926. }
  927. static __init int via_router_probe(struct irq_router *r,
  928. struct pci_dev *router, u16 device)
  929. {
  930. /* FIXME: We should move some of the quirk fixup stuff here */
  931. /*
  932. * workarounds for some buggy BIOSes
  933. */
  934. if (device == PCI_DEVICE_ID_VIA_82C586_0) {
  935. switch (router->device) {
  936. case PCI_DEVICE_ID_VIA_82C686:
  937. /*
  938. * Asus k7m bios wrongly reports 82C686A
  939. * as 586-compatible
  940. */
  941. device = PCI_DEVICE_ID_VIA_82C686;
  942. break;
  943. case PCI_DEVICE_ID_VIA_8235:
  944. /**
  945. * Asus a7v-x bios wrongly reports 8235
  946. * as 586-compatible
  947. */
  948. device = PCI_DEVICE_ID_VIA_8235;
  949. break;
  950. case PCI_DEVICE_ID_VIA_8237:
  951. /**
  952. * Asus a7v600 bios wrongly reports 8237
  953. * as 586-compatible
  954. */
  955. device = PCI_DEVICE_ID_VIA_8237;
  956. break;
  957. }
  958. }
  959. switch (device) {
  960. case PCI_DEVICE_ID_VIA_82C586_0:
  961. r->name = "VIA";
  962. r->get = pirq_via586_get;
  963. r->set = pirq_via586_set;
  964. return 1;
  965. case PCI_DEVICE_ID_VIA_82C596:
  966. case PCI_DEVICE_ID_VIA_82C686:
  967. case PCI_DEVICE_ID_VIA_8231:
  968. case PCI_DEVICE_ID_VIA_8233A:
  969. case PCI_DEVICE_ID_VIA_8235:
  970. case PCI_DEVICE_ID_VIA_8237:
  971. /* FIXME: add new ones for 8233/5 */
  972. r->name = "VIA";
  973. r->get = pirq_via_get;
  974. r->set = pirq_via_set;
  975. return 1;
  976. }
  977. return 0;
  978. }
  979. static __init int vlsi_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  980. {
  981. switch (device) {
  982. case PCI_DEVICE_ID_VLSI_82C534:
  983. r->name = "VLSI 82C534";
  984. r->get = pirq_vlsi_get;
  985. r->set = pirq_vlsi_set;
  986. return 1;
  987. }
  988. return 0;
  989. }
  990. static __init int serverworks_router_probe(struct irq_router *r,
  991. struct pci_dev *router, u16 device)
  992. {
  993. switch (device) {
  994. case PCI_DEVICE_ID_SERVERWORKS_OSB4:
  995. case PCI_DEVICE_ID_SERVERWORKS_CSB5:
  996. r->name = "ServerWorks";
  997. r->get = pirq_serverworks_get;
  998. r->set = pirq_serverworks_set;
  999. return 1;
  1000. }
  1001. return 0;
  1002. }
  1003. static __init int sis_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  1004. {
  1005. switch (device) {
  1006. case PCI_DEVICE_ID_SI_496:
  1007. r->name = "SiS85C497";
  1008. r->get = pirq_sis497_get;
  1009. r->set = pirq_sis497_set;
  1010. return 1;
  1011. case PCI_DEVICE_ID_SI_503:
  1012. r->name = "SiS85C503";
  1013. r->get = pirq_sis503_get;
  1014. r->set = pirq_sis503_set;
  1015. return 1;
  1016. }
  1017. return 0;
  1018. }
  1019. static __init int cyrix_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  1020. {
  1021. switch (device) {
  1022. case PCI_DEVICE_ID_CYRIX_5520:
  1023. r->name = "NatSemi";
  1024. r->get = pirq_cyrix_get;
  1025. r->set = pirq_cyrix_set;
  1026. return 1;
  1027. }
  1028. return 0;
  1029. }
  1030. static __init int opti_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  1031. {
  1032. switch (device) {
  1033. case PCI_DEVICE_ID_OPTI_82C700:
  1034. r->name = "OPTI";
  1035. r->get = pirq_opti_get;
  1036. r->set = pirq_opti_set;
  1037. return 1;
  1038. }
  1039. return 0;
  1040. }
  1041. static __init int ite_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  1042. {
  1043. switch (device) {
  1044. case PCI_DEVICE_ID_ITE_IT8330G_0:
  1045. r->name = "ITE";
  1046. r->get = pirq_ite_get;
  1047. r->set = pirq_ite_set;
  1048. return 1;
  1049. }
  1050. return 0;
  1051. }
  1052. static __init int ali_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  1053. {
  1054. switch (device) {
  1055. case PCI_DEVICE_ID_AL_M1489:
  1056. r->name = "FinALi";
  1057. r->get = pirq_finali_get;
  1058. r->set = pirq_finali_set;
  1059. r->lvl = pirq_finali_lvl;
  1060. return 1;
  1061. case PCI_DEVICE_ID_AL_M1533:
  1062. case PCI_DEVICE_ID_AL_M1563:
  1063. r->name = "ALI";
  1064. r->get = pirq_ali_get;
  1065. r->set = pirq_ali_set;
  1066. return 1;
  1067. }
  1068. return 0;
  1069. }
  1070. static __init int amd_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  1071. {
  1072. switch (device) {
  1073. case PCI_DEVICE_ID_AMD_VIPER_740B:
  1074. r->name = "AMD756";
  1075. break;
  1076. case PCI_DEVICE_ID_AMD_VIPER_7413:
  1077. r->name = "AMD766";
  1078. break;
  1079. case PCI_DEVICE_ID_AMD_VIPER_7443:
  1080. r->name = "AMD768";
  1081. break;
  1082. default:
  1083. return 0;
  1084. }
  1085. r->get = pirq_amd756_get;
  1086. r->set = pirq_amd756_set;
  1087. return 1;
  1088. }
  1089. static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
  1090. {
  1091. switch (device) {
  1092. case PCI_DEVICE_ID_PICOPOWER_PT86C523:
  1093. r->name = "PicoPower PT86C523";
  1094. r->get = pirq_pico_get;
  1095. r->set = pirq_pico_set;
  1096. return 1;
  1097. case PCI_DEVICE_ID_PICOPOWER_PT86C523BBP:
  1098. r->name = "PicoPower PT86C523 rev. BB+";
  1099. r->get = pirq_pico_get;
  1100. r->set = pirq_pico_set;
  1101. return 1;
  1102. }
  1103. return 0;
  1104. }
  1105. static __initdata struct irq_router_handler pirq_routers[] = {
  1106. { PCI_VENDOR_ID_INTEL, intel_router_probe },
  1107. { PCI_VENDOR_ID_AL, ali_router_probe },
  1108. { PCI_VENDOR_ID_ITE, ite_router_probe },
  1109. { PCI_VENDOR_ID_VIA, via_router_probe },
  1110. { PCI_VENDOR_ID_OPTI, opti_router_probe },
  1111. { PCI_VENDOR_ID_SI, sis_router_probe },
  1112. { PCI_VENDOR_ID_CYRIX, cyrix_router_probe },
  1113. { PCI_VENDOR_ID_VLSI, vlsi_router_probe },
  1114. { PCI_VENDOR_ID_SERVERWORKS, serverworks_router_probe },
  1115. { PCI_VENDOR_ID_AMD, amd_router_probe },
  1116. { PCI_VENDOR_ID_PICOPOWER, pico_router_probe },
  1117. /* Someone with docs needs to add the ATI Radeon IGP */
  1118. { 0, NULL }
  1119. };
  1120. static struct irq_router pirq_router;
  1121. static struct pci_dev *pirq_router_dev;
  1122. /*
  1123. * FIXME: should we have an option to say "generic for
  1124. * chipset" ?
  1125. */
  1126. static bool __init pirq_try_router(struct irq_router *r,
  1127. struct irq_routing_table *rt,
  1128. struct pci_dev *dev)
  1129. {
  1130. struct irq_router_handler *h;
  1131. DBG(KERN_DEBUG "PCI: Trying IRQ router for [%04x:%04x]\n",
  1132. dev->vendor, dev->device);
  1133. for (h = pirq_routers; h->vendor; h++) {
  1134. /* First look for a router match */
  1135. if (rt->rtr_vendor == h->vendor &&
  1136. h->probe(r, dev, rt->rtr_device))
  1137. return true;
  1138. /* Fall back to a device match */
  1139. if (dev->vendor == h->vendor &&
  1140. h->probe(r, dev, dev->device))
  1141. return true;
  1142. }
  1143. return false;
  1144. }
  1145. static void __init pirq_find_router(struct irq_router *r)
  1146. {
  1147. struct irq_routing_table *rt = pirq_table;
  1148. struct pci_dev *dev;
  1149. #ifdef CONFIG_PCI_BIOS
  1150. if (!rt->signature) {
  1151. printk(KERN_INFO "PCI: Using BIOS for IRQ routing\n");
  1152. r->set = pirq_bios_set;
  1153. r->name = "BIOS";
  1154. return;
  1155. }
  1156. #endif
  1157. /* Default unless a driver reloads it */
  1158. r->name = "default";
  1159. r->get = NULL;
  1160. r->set = NULL;
  1161. DBG(KERN_DEBUG "PCI: Attempting to find IRQ router for [%04x:%04x]\n",
  1162. rt->rtr_vendor, rt->rtr_device);
  1163. /* Use any vendor:device provided by the routing table or try all. */
  1164. if (rt->rtr_vendor) {
  1165. dev = pci_get_domain_bus_and_slot(0, rt->rtr_bus,
  1166. rt->rtr_devfn);
  1167. if (dev && pirq_try_router(r, rt, dev))
  1168. pirq_router_dev = dev;
  1169. } else {
  1170. dev = NULL;
  1171. for_each_pci_dev(dev) {
  1172. if (pirq_try_router(r, rt, dev)) {
  1173. pirq_router_dev = dev;
  1174. break;
  1175. }
  1176. }
  1177. }
  1178. if (pirq_router_dev)
  1179. dev_info(&pirq_router_dev->dev, "%s IRQ router [%04x:%04x]\n",
  1180. pirq_router.name,
  1181. pirq_router_dev->vendor, pirq_router_dev->device);
  1182. else
  1183. DBG(KERN_DEBUG "PCI: Interrupt router not found at "
  1184. "%02x:%02x\n", rt->rtr_bus, rt->rtr_devfn);
  1185. /* The device remains referenced for the kernel lifetime */
  1186. }
  1187. /*
  1188. * We're supposed to match on the PCI device only and not the function,
  1189. * but some BIOSes build their tables with the PCI function included
  1190. * for motherboard devices, so if a complete match is found, then give
  1191. * it precedence over a slot match.
  1192. */
  1193. static struct irq_info *pirq_get_dev_info(struct pci_dev *dev)
  1194. {
  1195. struct irq_routing_table *rt = pirq_table;
  1196. int entries = (rt->size - sizeof(struct irq_routing_table)) /
  1197. sizeof(struct irq_info);
  1198. struct irq_info *slotinfo = NULL;
  1199. struct irq_info *info;
  1200. for (info = rt->slots; entries--; info++)
  1201. if (info->bus == dev->bus->number) {
  1202. if (info->devfn == dev->devfn)
  1203. return info;
  1204. if (!slotinfo &&
  1205. PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn))
  1206. slotinfo = info;
  1207. }
  1208. return slotinfo;
  1209. }
  1210. /*
  1211. * Buses behind bridges are typically not listed in the PIRQ routing table.
  1212. * Do the usual dance then and walk the tree of bridges up adjusting the
  1213. * pin number accordingly on the way until the originating root bus device
  1214. * has been reached and then use its routing information.
  1215. */
  1216. static struct irq_info *pirq_get_info(struct pci_dev *dev, u8 *pin)
  1217. {
  1218. struct pci_dev *temp_dev = dev;
  1219. struct irq_info *info;
  1220. u8 temp_pin = *pin;
  1221. u8 dpin = temp_pin;
  1222. info = pirq_get_dev_info(dev);
  1223. while (!info && temp_dev->bus->parent) {
  1224. struct pci_dev *bridge = temp_dev->bus->self;
  1225. temp_pin = pci_swizzle_interrupt_pin(temp_dev, temp_pin);
  1226. info = pirq_get_dev_info(bridge);
  1227. if (info)
  1228. dev_warn(&dev->dev,
  1229. "using bridge %s INT %c to get INT %c\n",
  1230. pci_name(bridge),
  1231. 'A' + temp_pin - 1, 'A' + dpin - 1);
  1232. temp_dev = bridge;
  1233. }
  1234. *pin = temp_pin;
  1235. return info;
  1236. }
  1237. static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
  1238. {
  1239. struct irq_info *info;
  1240. int i, pirq, newirq;
  1241. u8 dpin, pin;
  1242. int irq = 0;
  1243. u32 mask;
  1244. struct irq_router *r = &pirq_router;
  1245. struct pci_dev *dev2 = NULL;
  1246. char *msg = NULL;
  1247. /* Find IRQ pin */
  1248. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &dpin);
  1249. if (!dpin) {
  1250. dev_dbg(&dev->dev, "no interrupt pin\n");
  1251. return 0;
  1252. }
  1253. if (io_apic_assign_pci_irqs)
  1254. return 0;
  1255. /* Find IRQ routing entry */
  1256. if (!pirq_table)
  1257. return 0;
  1258. pin = dpin;
  1259. info = pirq_get_info(dev, &pin);
  1260. if (!info) {
  1261. dev_dbg(&dev->dev, "PCI INT %c not found in routing table\n",
  1262. 'A' + dpin - 1);
  1263. return 0;
  1264. }
  1265. pirq = info->irq[pin - 1].link;
  1266. mask = info->irq[pin - 1].bitmap;
  1267. if (!pirq) {
  1268. dev_dbg(&dev->dev, "PCI INT %c not routed\n", 'A' + dpin - 1);
  1269. return 0;
  1270. }
  1271. dev_dbg(&dev->dev, "PCI INT %c -> PIRQ %02x, mask %04x, excl %04x",
  1272. 'A' + dpin - 1, pirq, mask, pirq_table->exclusive_irqs);
  1273. mask &= pcibios_irq_mask;
  1274. /* Work around broken HP Pavilion Notebooks which assign USB to
  1275. IRQ 9 even though it is actually wired to IRQ 11 */
  1276. if (broken_hp_bios_irq9 && pirq == 0x59 && dev->irq == 9) {
  1277. dev->irq = 11;
  1278. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
  1279. r->set(pirq_router_dev, dev, pirq, 11);
  1280. }
  1281. /* same for Acer Travelmate 360, but with CB and irq 11 -> 10 */
  1282. if (acer_tm360_irqrouting && dev->irq == 11 &&
  1283. dev->vendor == PCI_VENDOR_ID_O2) {
  1284. pirq = 0x68;
  1285. mask = 0x400;
  1286. dev->irq = r->get(pirq_router_dev, dev, pirq);
  1287. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  1288. }
  1289. /*
  1290. * Find the best IRQ to assign: use the one
  1291. * reported by the device if possible.
  1292. */
  1293. newirq = dev->irq;
  1294. if (newirq && !((1 << newirq) & mask)) {
  1295. if (pci_probe & PCI_USE_PIRQ_MASK)
  1296. newirq = 0;
  1297. else
  1298. dev_warn(&dev->dev, "IRQ %d doesn't match PIRQ mask "
  1299. "%#x; try pci=usepirqmask\n", newirq, mask);
  1300. }
  1301. if (!newirq && assign) {
  1302. for (i = 0; i < 16; i++) {
  1303. if (!(mask & (1 << i)))
  1304. continue;
  1305. if (pirq_penalty[i] < pirq_penalty[newirq] &&
  1306. can_request_irq(i, IRQF_SHARED))
  1307. newirq = i;
  1308. }
  1309. }
  1310. dev_dbg(&dev->dev, "PCI INT %c -> newirq %d", 'A' + dpin - 1, newirq);
  1311. /* Check if it is hardcoded */
  1312. if ((pirq & 0xf0) == 0xf0) {
  1313. irq = pirq & 0xf;
  1314. msg = "hardcoded";
  1315. } else if (r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
  1316. ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask))) {
  1317. msg = "found";
  1318. if (r->lvl)
  1319. r->lvl(pirq_router_dev, dev, pirq, irq);
  1320. else
  1321. elcr_set_level_irq(irq);
  1322. } else if (newirq && r->set &&
  1323. (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) {
  1324. if (r->set(pirq_router_dev, dev, pirq, newirq)) {
  1325. if (r->lvl)
  1326. r->lvl(pirq_router_dev, dev, pirq, newirq);
  1327. else
  1328. elcr_set_level_irq(newirq);
  1329. msg = "assigned";
  1330. irq = newirq;
  1331. }
  1332. }
  1333. if (!irq) {
  1334. if (newirq && mask == (1 << newirq)) {
  1335. msg = "guessed";
  1336. irq = newirq;
  1337. } else {
  1338. dev_dbg(&dev->dev, "can't route interrupt\n");
  1339. return 0;
  1340. }
  1341. }
  1342. dev_info(&dev->dev, "%s PCI INT %c -> IRQ %d\n",
  1343. msg, 'A' + dpin - 1, irq);
  1344. /* Update IRQ for all devices with the same pirq value */
  1345. for_each_pci_dev(dev2) {
  1346. pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &dpin);
  1347. if (!dpin)
  1348. continue;
  1349. pin = dpin;
  1350. info = pirq_get_info(dev2, &pin);
  1351. if (!info)
  1352. continue;
  1353. if (info->irq[pin - 1].link == pirq) {
  1354. /*
  1355. * We refuse to override the dev->irq
  1356. * information. Give a warning!
  1357. */
  1358. if (dev2->irq && dev2->irq != irq && \
  1359. (!(pci_probe & PCI_USE_PIRQ_MASK) || \
  1360. ((1 << dev2->irq) & mask))) {
  1361. #ifndef CONFIG_PCI_MSI
  1362. dev_info(&dev2->dev, "IRQ routing conflict: "
  1363. "have IRQ %d, want IRQ %d\n",
  1364. dev2->irq, irq);
  1365. #endif
  1366. continue;
  1367. }
  1368. dev2->irq = irq;
  1369. pirq_penalty[irq]++;
  1370. if (dev != dev2)
  1371. dev_info(&dev->dev, "sharing IRQ %d with %s\n",
  1372. irq, pci_name(dev2));
  1373. }
  1374. }
  1375. return 1;
  1376. }
  1377. void __init pcibios_fixup_irqs(void)
  1378. {
  1379. struct pci_dev *dev = NULL;
  1380. u8 pin;
  1381. DBG(KERN_DEBUG "PCI: IRQ fixup\n");
  1382. for_each_pci_dev(dev) {
  1383. /*
  1384. * If the BIOS has set an out of range IRQ number, just
  1385. * ignore it. Also keep track of which IRQ's are
  1386. * already in use.
  1387. */
  1388. if (dev->irq >= 16) {
  1389. dev_dbg(&dev->dev, "ignoring bogus IRQ %d\n", dev->irq);
  1390. dev->irq = 0;
  1391. }
  1392. /*
  1393. * If the IRQ is already assigned to a PCI device,
  1394. * ignore its ISA use penalty
  1395. */
  1396. if (pirq_penalty[dev->irq] >= 100 &&
  1397. pirq_penalty[dev->irq] < 100000)
  1398. pirq_penalty[dev->irq] = 0;
  1399. pirq_penalty[dev->irq]++;
  1400. }
  1401. if (io_apic_assign_pci_irqs)
  1402. return;
  1403. dev = NULL;
  1404. for_each_pci_dev(dev) {
  1405. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  1406. if (!pin)
  1407. continue;
  1408. /*
  1409. * Still no IRQ? Try to lookup one...
  1410. */
  1411. if (!dev->irq)
  1412. pcibios_lookup_irq(dev, 0);
  1413. }
  1414. }
  1415. /*
  1416. * Work around broken HP Pavilion Notebooks which assign USB to
  1417. * IRQ 9 even though it is actually wired to IRQ 11
  1418. */
  1419. static int __init fix_broken_hp_bios_irq9(const struct dmi_system_id *d)
  1420. {
  1421. if (!broken_hp_bios_irq9) {
  1422. broken_hp_bios_irq9 = 1;
  1423. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  1424. d->ident);
  1425. }
  1426. return 0;
  1427. }
  1428. /*
  1429. * Work around broken Acer TravelMate 360 Notebooks which assign
  1430. * Cardbus to IRQ 11 even though it is actually wired to IRQ 10
  1431. */
  1432. static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
  1433. {
  1434. if (!acer_tm360_irqrouting) {
  1435. acer_tm360_irqrouting = 1;
  1436. printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
  1437. d->ident);
  1438. }
  1439. return 0;
  1440. }
  1441. static const struct dmi_system_id pciirq_dmi_table[] __initconst = {
  1442. {
  1443. .callback = fix_broken_hp_bios_irq9,
  1444. .ident = "HP Pavilion N5400 Series Laptop",
  1445. .matches = {
  1446. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1447. DMI_MATCH(DMI_BIOS_VERSION, "GE.M1.03"),
  1448. DMI_MATCH(DMI_PRODUCT_VERSION,
  1449. "HP Pavilion Notebook Model GE"),
  1450. DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
  1451. },
  1452. },
  1453. {
  1454. .callback = fix_acer_tm360_irqrouting,
  1455. .ident = "Acer TravelMate 36x Laptop",
  1456. .matches = {
  1457. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1458. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  1459. },
  1460. },
  1461. { }
  1462. };
  1463. void __init pcibios_irq_init(void)
  1464. {
  1465. struct irq_routing_table *rtable = NULL;
  1466. DBG(KERN_DEBUG "PCI: IRQ init\n");
  1467. if (raw_pci_ops == NULL)
  1468. return;
  1469. dmi_check_system(pciirq_dmi_table);
  1470. pirq_table = pirq_find_routing_table();
  1471. #ifdef CONFIG_PCI_BIOS
  1472. if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) {
  1473. pirq_table = pcibios_get_irq_routing_table();
  1474. rtable = pirq_table;
  1475. }
  1476. #endif
  1477. if (pirq_table) {
  1478. pirq_peer_trick();
  1479. pirq_find_router(&pirq_router);
  1480. if (pirq_table->exclusive_irqs) {
  1481. int i;
  1482. for (i = 0; i < 16; i++)
  1483. if (!(pirq_table->exclusive_irqs & (1 << i)))
  1484. pirq_penalty[i] += 100;
  1485. }
  1486. /*
  1487. * If we're using the I/O APIC, avoid using the PCI IRQ
  1488. * routing table
  1489. */
  1490. if (io_apic_assign_pci_irqs) {
  1491. kfree(rtable);
  1492. pirq_table = NULL;
  1493. }
  1494. }
  1495. x86_init.pci.fixup_irqs();
  1496. if (io_apic_assign_pci_irqs && pci_routeirq) {
  1497. struct pci_dev *dev = NULL;
  1498. /*
  1499. * PCI IRQ routing is set up by pci_enable_device(), but we
  1500. * also do it here in case there are still broken drivers that
  1501. * don't use pci_enable_device().
  1502. */
  1503. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  1504. for_each_pci_dev(dev)
  1505. pirq_enable_irq(dev);
  1506. }
  1507. }
  1508. static void pirq_penalize_isa_irq(int irq, int active)
  1509. {
  1510. /*
  1511. * If any ISAPnP device reports an IRQ in its list of possible
  1512. * IRQ's, we try to avoid assigning it to PCI devices.
  1513. */
  1514. if (irq < 16) {
  1515. if (active)
  1516. pirq_penalty[irq] += 1000;
  1517. else
  1518. pirq_penalty[irq] += 100;
  1519. }
  1520. }
  1521. void pcibios_penalize_isa_irq(int irq, int active)
  1522. {
  1523. #ifdef CONFIG_ACPI
  1524. if (!acpi_noirq)
  1525. acpi_penalize_isa_irq(irq, active);
  1526. else
  1527. #endif
  1528. pirq_penalize_isa_irq(irq, active);
  1529. }
  1530. static int pirq_enable_irq(struct pci_dev *dev)
  1531. {
  1532. u8 pin = 0;
  1533. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  1534. if (pin && !pcibios_lookup_irq(dev, 1)) {
  1535. char *msg = "";
  1536. if (!io_apic_assign_pci_irqs && dev->irq)
  1537. return 0;
  1538. if (io_apic_assign_pci_irqs) {
  1539. #ifdef CONFIG_X86_IO_APIC
  1540. struct pci_dev *temp_dev;
  1541. int irq;
  1542. if (dev->irq_managed && dev->irq > 0)
  1543. return 0;
  1544. irq = IO_APIC_get_PCI_irq_vector(dev->bus->number,
  1545. PCI_SLOT(dev->devfn), pin - 1);
  1546. /*
  1547. * Busses behind bridges are typically not listed in the MP-table.
  1548. * In this case we have to look up the IRQ based on the parent bus,
  1549. * parent slot, and pin number. The SMP code detects such bridged
  1550. * busses itself so we should get into this branch reliably.
  1551. */
  1552. temp_dev = dev;
  1553. while (irq < 0 && dev->bus->parent) { /* go back to the bridge */
  1554. struct pci_dev *bridge = dev->bus->self;
  1555. pin = pci_swizzle_interrupt_pin(dev, pin);
  1556. irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number,
  1557. PCI_SLOT(bridge->devfn),
  1558. pin - 1);
  1559. if (irq >= 0)
  1560. dev_warn(&dev->dev, "using bridge %s "
  1561. "INT %c to get IRQ %d\n",
  1562. pci_name(bridge), 'A' + pin - 1,
  1563. irq);
  1564. dev = bridge;
  1565. }
  1566. dev = temp_dev;
  1567. if (irq >= 0) {
  1568. dev->irq_managed = 1;
  1569. dev->irq = irq;
  1570. dev_info(&dev->dev, "PCI->APIC IRQ transform: "
  1571. "INT %c -> IRQ %d\n", 'A' + pin - 1, irq);
  1572. return 0;
  1573. } else
  1574. msg = "; probably buggy MP table";
  1575. #endif
  1576. } else if (pci_probe & PCI_BIOS_IRQ_SCAN)
  1577. msg = "";
  1578. else
  1579. msg = "; please try using pci=biosirq";
  1580. /*
  1581. * With IDE legacy devices the IRQ lookup failure is not
  1582. * a problem..
  1583. */
  1584. if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
  1585. !(dev->class & 0x5))
  1586. return 0;
  1587. dev_warn(&dev->dev, "can't find IRQ for PCI INT %c%s\n",
  1588. 'A' + pin - 1, msg);
  1589. }
  1590. return 0;
  1591. }
  1592. bool mp_should_keep_irq(struct device *dev)
  1593. {
  1594. if (dev->power.is_prepared)
  1595. return true;
  1596. #ifdef CONFIG_PM
  1597. if (dev->power.runtime_status == RPM_SUSPENDING)
  1598. return true;
  1599. #endif
  1600. return false;
  1601. }
  1602. static void pirq_disable_irq(struct pci_dev *dev)
  1603. {
  1604. if (io_apic_assign_pci_irqs && !mp_should_keep_irq(&dev->dev) &&
  1605. dev->irq_managed && dev->irq) {
  1606. mp_unmap_irq(dev->irq);
  1607. dev->irq = 0;
  1608. dev->irq_managed = 0;
  1609. }
  1610. }