irq.c 30 KB

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