irq.c 30 KB

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