irq.c 33 KB

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