1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2fb9aa6f1SThomas Gleixner /*
3fb9aa6f1SThomas Gleixner * Low-Level PCI Support for PC -- Routing of Interrupts
4fb9aa6f1SThomas Gleixner *
5fb9aa6f1SThomas Gleixner * (c) 1999--2000 Martin Mares <mj@ucw.cz>
6fb9aa6f1SThomas Gleixner */
7fb9aa6f1SThomas Gleixner
8fb9aa6f1SThomas Gleixner #include <linux/types.h>
9fb9aa6f1SThomas Gleixner #include <linux/kernel.h>
10fb9aa6f1SThomas Gleixner #include <linux/pci.h>
11fb9aa6f1SThomas Gleixner #include <linux/init.h>
12fb9aa6f1SThomas Gleixner #include <linux/interrupt.h>
13fb9aa6f1SThomas Gleixner #include <linux/dmi.h>
147058b061SPaolo Ciarrocchi #include <linux/io.h>
157058b061SPaolo Ciarrocchi #include <linux/smp.h>
161ce849c7SMaciej W. Rozycki #include <linux/spinlock.h>
17fb9aa6f1SThomas Gleixner #include <asm/io_apic.h>
18fb9aa6f1SThomas Gleixner #include <linux/irq.h>
19fb9aa6f1SThomas Gleixner #include <linux/acpi.h>
201ce849c7SMaciej W. Rozycki
21d2531661SMaciej W. Rozycki #include <asm/i8259.h>
221ce849c7SMaciej W. Rozycki #include <asm/pc-conf-reg.h>
2382487711SJaswinder Singh Rajput #include <asm/pci_x86.h>
24fb9aa6f1SThomas Gleixner
25fb9aa6f1SThomas Gleixner #define PIRQ_SIGNATURE (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))
26fb9aa6f1SThomas Gleixner #define PIRQ_VERSION 0x0100
27fb9aa6f1SThomas Gleixner
28b584db0cSMaciej W. Rozycki #define IRT_SIGNATURE (('$' << 0) + ('I' << 8) + ('R' << 16) + ('T' << 24))
29b584db0cSMaciej W. Rozycki
30fb9aa6f1SThomas Gleixner static int broken_hp_bios_irq9;
31fb9aa6f1SThomas Gleixner static int acer_tm360_irqrouting;
32fb9aa6f1SThomas Gleixner
33fb9aa6f1SThomas Gleixner static struct irq_routing_table *pirq_table;
34fb9aa6f1SThomas Gleixner
35fb9aa6f1SThomas Gleixner static int pirq_enable_irq(struct pci_dev *dev);
36c03b3b07SJiang Liu static void pirq_disable_irq(struct pci_dev *dev);
37fb9aa6f1SThomas Gleixner
38fb9aa6f1SThomas Gleixner /*
39fb9aa6f1SThomas Gleixner * Never use: 0, 1, 2 (timer, keyboard, and cascade)
40fb9aa6f1SThomas Gleixner * Avoid using: 13, 14 and 15 (FP error and IDE).
41fb9aa6f1SThomas Gleixner * Penalize: 3, 4, 6, 7, 12 (known ISA uses: serial, floppy, parallel and mouse)
42fb9aa6f1SThomas Gleixner */
43fb9aa6f1SThomas Gleixner unsigned int pcibios_irq_mask = 0xfff8;
44fb9aa6f1SThomas Gleixner
45fb9aa6f1SThomas Gleixner static int pirq_penalty[16] = {
46fb9aa6f1SThomas Gleixner 1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000,
47fb9aa6f1SThomas Gleixner 0, 0, 0, 0, 1000, 100000, 100000, 100000
48fb9aa6f1SThomas Gleixner };
49fb9aa6f1SThomas Gleixner
50fb9aa6f1SThomas Gleixner struct irq_router {
51fb9aa6f1SThomas Gleixner char *name;
52fb9aa6f1SThomas Gleixner u16 vendor, device;
53fb9aa6f1SThomas Gleixner int (*get)(struct pci_dev *router, struct pci_dev *dev, int pirq);
54273c1127SMiklos Vajna int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq,
55273c1127SMiklos Vajna int new);
561ce849c7SMaciej W. Rozycki int (*lvl)(struct pci_dev *router, struct pci_dev *dev, int pirq,
571ce849c7SMaciej W. Rozycki int irq);
58fb9aa6f1SThomas Gleixner };
59fb9aa6f1SThomas Gleixner
60fb9aa6f1SThomas Gleixner struct irq_router_handler {
61fb9aa6f1SThomas Gleixner u16 vendor;
62fb9aa6f1SThomas Gleixner int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
63fb9aa6f1SThomas Gleixner };
64fb9aa6f1SThomas Gleixner
65ab3b3793SThomas Gleixner int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
66c03b3b07SJiang Liu void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
67fb9aa6f1SThomas Gleixner
68fb9aa6f1SThomas Gleixner /*
69fb9aa6f1SThomas Gleixner * Check passed address for the PCI IRQ Routing Table signature
70fb9aa6f1SThomas Gleixner * and perform checksum verification.
71fb9aa6f1SThomas Gleixner */
72fb9aa6f1SThomas Gleixner
pirq_check_routing_table(u8 * addr,u8 * limit)735d64089aSMaciej W. Rozycki static inline struct irq_routing_table *pirq_check_routing_table(u8 *addr,
745d64089aSMaciej W. Rozycki u8 *limit)
75fb9aa6f1SThomas Gleixner {
76fb9aa6f1SThomas Gleixner struct irq_routing_table *rt;
77fb9aa6f1SThomas Gleixner int i;
78fb9aa6f1SThomas Gleixner u8 sum;
79fb9aa6f1SThomas Gleixner
80fb9aa6f1SThomas Gleixner rt = (struct irq_routing_table *)addr;
81fb9aa6f1SThomas Gleixner if (rt->signature != PIRQ_SIGNATURE ||
82fb9aa6f1SThomas Gleixner rt->version != PIRQ_VERSION ||
83fb9aa6f1SThomas Gleixner rt->size % 16 ||
845d64089aSMaciej W. Rozycki rt->size < sizeof(struct irq_routing_table) ||
855d64089aSMaciej W. Rozycki (limit && rt->size > limit - addr))
86fb9aa6f1SThomas Gleixner return NULL;
87fb9aa6f1SThomas Gleixner sum = 0;
88fb9aa6f1SThomas Gleixner for (i = 0; i < rt->size; i++)
89fb9aa6f1SThomas Gleixner sum += addr[i];
90fb9aa6f1SThomas Gleixner if (!sum) {
91613fa6e2SMaciej W. Rozycki DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%lx\n",
92613fa6e2SMaciej W. Rozycki __pa(rt));
93fb9aa6f1SThomas Gleixner return rt;
94fb9aa6f1SThomas Gleixner }
95fb9aa6f1SThomas Gleixner return NULL;
96fb9aa6f1SThomas Gleixner }
97fb9aa6f1SThomas Gleixner
98b584db0cSMaciej W. Rozycki /*
99b584db0cSMaciej W. Rozycki * Handle the $IRT PCI IRQ Routing Table format used by AMI for its BCP
100b584db0cSMaciej W. Rozycki * (BIOS Configuration Program) external tool meant for tweaking BIOS
101b584db0cSMaciej W. Rozycki * structures without the need to rebuild it from sources. The $IRT
102b584db0cSMaciej W. Rozycki * format has been invented by AMI before Microsoft has come up with its
103b584db0cSMaciej W. Rozycki * $PIR format and a $IRT table is therefore there in some systems that
104b584db0cSMaciej W. Rozycki * lack a $PIR table.
105b584db0cSMaciej W. Rozycki *
106b584db0cSMaciej W. Rozycki * It uses the same PCI BIOS 2.1 format for interrupt routing entries
107b584db0cSMaciej W. Rozycki * themselves but has a different simpler header prepended instead,
108b584db0cSMaciej W. Rozycki * occupying 8 bytes, where a `$IRT' signature is followed by one byte
109b584db0cSMaciej W. Rozycki * specifying the total number of interrupt routing entries allocated in
110b584db0cSMaciej W. Rozycki * the table, then one byte specifying the actual number of entries used
111b584db0cSMaciej W. Rozycki * (which the BCP tool can take advantage of when modifying the table),
112b584db0cSMaciej W. Rozycki * and finally a 16-bit word giving the IRQs devoted exclusively to PCI.
113b584db0cSMaciej W. Rozycki * Unlike with the $PIR table there is no alignment guarantee.
114b584db0cSMaciej W. Rozycki *
115b584db0cSMaciej W. Rozycki * Given the similarity of the two formats the $IRT one is trivial to
116b584db0cSMaciej W. Rozycki * convert to the $PIR one, which we do here, except that obviously we
117b584db0cSMaciej W. Rozycki * have no information as to the router device to use, but we can handle
118b584db0cSMaciej W. Rozycki * it by matching PCI device IDs actually seen on the bus against ones
119b584db0cSMaciej W. Rozycki * that our individual routers recognise.
120b584db0cSMaciej W. Rozycki *
121b584db0cSMaciej W. Rozycki * Reportedly there is another $IRT table format where a 16-bit word
122b584db0cSMaciej W. Rozycki * follows the header instead that points to interrupt routing entries
123b584db0cSMaciej W. Rozycki * in a $PIR table provided elsewhere. In that case this code will not
124b584db0cSMaciej W. Rozycki * be reached though as the $PIR table will have been chosen instead.
125b584db0cSMaciej W. Rozycki */
pirq_convert_irt_table(u8 * addr,u8 * limit)126b584db0cSMaciej W. Rozycki static inline struct irq_routing_table *pirq_convert_irt_table(u8 *addr,
127b584db0cSMaciej W. Rozycki u8 *limit)
128b584db0cSMaciej W. Rozycki {
129b584db0cSMaciej W. Rozycki struct irt_routing_table *ir;
130b584db0cSMaciej W. Rozycki struct irq_routing_table *rt;
131b584db0cSMaciej W. Rozycki u16 size;
132b584db0cSMaciej W. Rozycki u8 sum;
133b584db0cSMaciej W. Rozycki int i;
134fb9aa6f1SThomas Gleixner
135b584db0cSMaciej W. Rozycki ir = (struct irt_routing_table *)addr;
136b584db0cSMaciej W. Rozycki if (ir->signature != IRT_SIGNATURE || !ir->used || ir->size < ir->used)
137b584db0cSMaciej W. Rozycki return NULL;
138b584db0cSMaciej W. Rozycki
139*c00f94adSChristophe JAILLET size = struct_size(ir, slots, ir->used);
140b584db0cSMaciej W. Rozycki if (size > limit - addr)
141b584db0cSMaciej W. Rozycki return NULL;
142b584db0cSMaciej W. Rozycki
143b584db0cSMaciej W. Rozycki DBG(KERN_DEBUG "PCI: $IRT Interrupt Routing Table found at 0x%lx\n",
144b584db0cSMaciej W. Rozycki __pa(ir));
145b584db0cSMaciej W. Rozycki
146*c00f94adSChristophe JAILLET size = struct_size(rt, slots, ir->used);
147b584db0cSMaciej W. Rozycki rt = kzalloc(size, GFP_KERNEL);
148b584db0cSMaciej W. Rozycki if (!rt)
149b584db0cSMaciej W. Rozycki return NULL;
150b584db0cSMaciej W. Rozycki
151b584db0cSMaciej W. Rozycki rt->signature = PIRQ_SIGNATURE;
152b584db0cSMaciej W. Rozycki rt->version = PIRQ_VERSION;
153b584db0cSMaciej W. Rozycki rt->size = size;
154b584db0cSMaciej W. Rozycki rt->exclusive_irqs = ir->exclusive_irqs;
155b584db0cSMaciej W. Rozycki for (i = 0; i < ir->used; i++)
156b584db0cSMaciej W. Rozycki rt->slots[i] = ir->slots[i];
157b584db0cSMaciej W. Rozycki
158b584db0cSMaciej W. Rozycki addr = (u8 *)rt;
159b584db0cSMaciej W. Rozycki sum = 0;
160b584db0cSMaciej W. Rozycki for (i = 0; i < size; i++)
161b584db0cSMaciej W. Rozycki sum += addr[i];
162b584db0cSMaciej W. Rozycki rt->checksum = -sum;
163b584db0cSMaciej W. Rozycki
164b584db0cSMaciej W. Rozycki return rt;
165b584db0cSMaciej W. Rozycki }
166fb9aa6f1SThomas Gleixner
167fb9aa6f1SThomas Gleixner /*
168fb9aa6f1SThomas Gleixner * Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table.
169fb9aa6f1SThomas Gleixner */
170fb9aa6f1SThomas Gleixner
pirq_find_routing_table(void)171fb9aa6f1SThomas Gleixner static struct irq_routing_table * __init pirq_find_routing_table(void)
172fb9aa6f1SThomas Gleixner {
1735d64089aSMaciej W. Rozycki u8 * const bios_start = (u8 *)__va(0xf0000);
1745d64089aSMaciej W. Rozycki u8 * const bios_end = (u8 *)__va(0x100000);
175fb9aa6f1SThomas Gleixner u8 *addr;
176fb9aa6f1SThomas Gleixner struct irq_routing_table *rt;
177fb9aa6f1SThomas Gleixner
178fb9aa6f1SThomas Gleixner if (pirq_table_addr) {
1795d64089aSMaciej W. Rozycki rt = pirq_check_routing_table((u8 *)__va(pirq_table_addr),
1805d64089aSMaciej W. Rozycki NULL);
181fb9aa6f1SThomas Gleixner if (rt)
182fb9aa6f1SThomas Gleixner return rt;
183fb9aa6f1SThomas Gleixner printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n");
184fb9aa6f1SThomas Gleixner }
1855d64089aSMaciej W. Rozycki for (addr = bios_start;
1865d64089aSMaciej W. Rozycki addr < bios_end - sizeof(struct irq_routing_table);
1875d64089aSMaciej W. Rozycki addr += 16) {
1885d64089aSMaciej W. Rozycki rt = pirq_check_routing_table(addr, bios_end);
189fb9aa6f1SThomas Gleixner if (rt)
190fb9aa6f1SThomas Gleixner return rt;
191fb9aa6f1SThomas Gleixner }
192b584db0cSMaciej W. Rozycki for (addr = bios_start;
193b584db0cSMaciej W. Rozycki addr < bios_end - sizeof(struct irt_routing_table);
194b584db0cSMaciej W. Rozycki addr++) {
195b584db0cSMaciej W. Rozycki rt = pirq_convert_irt_table(addr, bios_end);
196b584db0cSMaciej W. Rozycki if (rt)
197b584db0cSMaciej W. Rozycki return rt;
198b584db0cSMaciej W. Rozycki }
199fb9aa6f1SThomas Gleixner return NULL;
200fb9aa6f1SThomas Gleixner }
201fb9aa6f1SThomas Gleixner
202fb9aa6f1SThomas Gleixner /*
203fb9aa6f1SThomas Gleixner * If we have a IRQ routing table, use it to search for peer host
204fb9aa6f1SThomas Gleixner * bridges. It's a gross hack, but since there are no other known
205fb9aa6f1SThomas Gleixner * ways how to get a list of buses, we have to go this way.
206fb9aa6f1SThomas Gleixner */
207fb9aa6f1SThomas Gleixner
pirq_peer_trick(void)208fb9aa6f1SThomas Gleixner static void __init pirq_peer_trick(void)
209fb9aa6f1SThomas Gleixner {
210fb9aa6f1SThomas Gleixner struct irq_routing_table *rt = pirq_table;
211fb9aa6f1SThomas Gleixner u8 busmap[256];
212fb9aa6f1SThomas Gleixner int i;
213fb9aa6f1SThomas Gleixner struct irq_info *e;
214fb9aa6f1SThomas Gleixner
215fb9aa6f1SThomas Gleixner memset(busmap, 0, sizeof(busmap));
216fb9aa6f1SThomas Gleixner for (i = 0; i < (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); i++) {
217fb9aa6f1SThomas Gleixner e = &rt->slots[i];
218fb9aa6f1SThomas Gleixner #ifdef DEBUG
219fb9aa6f1SThomas Gleixner {
220fb9aa6f1SThomas Gleixner int j;
221dc0e6408SMaciej W. Rozycki DBG(KERN_DEBUG "%02x:%02x.%x slot=%02x",
222dc0e6408SMaciej W. Rozycki e->bus, e->devfn / 8, e->devfn % 8, e->slot);
223fb9aa6f1SThomas Gleixner for (j = 0; j < 4; j++)
224fb9aa6f1SThomas Gleixner DBG(" %d:%02x/%04x", j, e->irq[j].link, e->irq[j].bitmap);
225fb9aa6f1SThomas Gleixner DBG("\n");
226fb9aa6f1SThomas Gleixner }
227fb9aa6f1SThomas Gleixner #endif
228fb9aa6f1SThomas Gleixner busmap[e->bus] = 1;
229fb9aa6f1SThomas Gleixner }
230fb9aa6f1SThomas Gleixner for (i = 1; i < 256; i++) {
231fb9aa6f1SThomas Gleixner if (!busmap[i] || pci_find_bus(0, i))
232fb9aa6f1SThomas Gleixner continue;
23349886cf4SBjorn Helgaas pcibios_scan_root(i);
234fb9aa6f1SThomas Gleixner }
235fb9aa6f1SThomas Gleixner pcibios_last_bus = -1;
236fb9aa6f1SThomas Gleixner }
237fb9aa6f1SThomas Gleixner
238fb9aa6f1SThomas Gleixner /*
239fb9aa6f1SThomas Gleixner * Code for querying and setting of IRQ routes on various interrupt routers.
240ea6cd250SPaul Gortmaker * PIC Edge/Level Control Registers (ELCR) 0x4d0 & 0x4d1.
241fb9aa6f1SThomas Gleixner */
242fb9aa6f1SThomas Gleixner
elcr_set_level_irq(unsigned int irq)243ea6cd250SPaul Gortmaker void elcr_set_level_irq(unsigned int irq)
244fb9aa6f1SThomas Gleixner {
245fb9aa6f1SThomas Gleixner unsigned char mask = 1 << (irq & 7);
246d2531661SMaciej W. Rozycki unsigned int port = PIC_ELCR1 + (irq >> 3);
247fb9aa6f1SThomas Gleixner unsigned char val;
248ea6cd250SPaul Gortmaker static u16 elcr_irq_mask;
249fb9aa6f1SThomas Gleixner
250ea6cd250SPaul Gortmaker if (irq >= 16 || (1 << irq) & elcr_irq_mask)
251fb9aa6f1SThomas Gleixner return;
252fb9aa6f1SThomas Gleixner
253ea6cd250SPaul Gortmaker elcr_irq_mask |= (1 << irq);
254fb9aa6f1SThomas Gleixner printk(KERN_DEBUG "PCI: setting IRQ %u as level-triggered\n", irq);
255fb9aa6f1SThomas Gleixner val = inb(port);
256fb9aa6f1SThomas Gleixner if (!(val & mask)) {
257fb9aa6f1SThomas Gleixner DBG(KERN_DEBUG " -> edge");
258fb9aa6f1SThomas Gleixner outb(val | mask, port);
259fb9aa6f1SThomas Gleixner }
260fb9aa6f1SThomas Gleixner }
261fb9aa6f1SThomas Gleixner
262fb9aa6f1SThomas Gleixner /*
2631ce849c7SMaciej W. Rozycki * PIRQ routing for the M1487 ISA Bus Controller (IBC) ASIC used
2641ce849c7SMaciej W. Rozycki * with the ALi FinALi 486 chipset. The IBC is not decoded in the
2651ce849c7SMaciej W. Rozycki * PCI configuration space, so we identify it by the accompanying
2661ce849c7SMaciej W. Rozycki * M1489 Cache-Memory PCI Controller (CMP) ASIC.
2671ce849c7SMaciej W. Rozycki *
2681ce849c7SMaciej W. Rozycki * There are four 4-bit mappings provided, spread across two PCI
2691ce849c7SMaciej W. Rozycki * INTx Routing Table Mapping Registers, available in the port I/O
2701ce849c7SMaciej W. Rozycki * space accessible indirectly via the index/data register pair at
2711ce849c7SMaciej W. Rozycki * 0x22/0x23, located at indices 0x42 and 0x43 for the INT1/INT2
2721ce849c7SMaciej W. Rozycki * and INT3/INT4 lines respectively. The INT1/INT3 and INT2/INT4
2731ce849c7SMaciej W. Rozycki * lines are mapped in the low and the high 4-bit nibble of the
2741ce849c7SMaciej W. Rozycki * corresponding register as follows:
2751ce849c7SMaciej W. Rozycki *
2761ce849c7SMaciej W. Rozycki * 0000 : Disabled
2771ce849c7SMaciej W. Rozycki * 0001 : IRQ9
2781ce849c7SMaciej W. Rozycki * 0010 : IRQ3
2791ce849c7SMaciej W. Rozycki * 0011 : IRQ10
2801ce849c7SMaciej W. Rozycki * 0100 : IRQ4
2811ce849c7SMaciej W. Rozycki * 0101 : IRQ5
2821ce849c7SMaciej W. Rozycki * 0110 : IRQ7
2831ce849c7SMaciej W. Rozycki * 0111 : IRQ6
2841ce849c7SMaciej W. Rozycki * 1000 : Reserved
2851ce849c7SMaciej W. Rozycki * 1001 : IRQ11
2861ce849c7SMaciej W. Rozycki * 1010 : Reserved
2871ce849c7SMaciej W. Rozycki * 1011 : IRQ12
2881ce849c7SMaciej W. Rozycki * 1100 : Reserved
2891ce849c7SMaciej W. Rozycki * 1101 : IRQ14
2901ce849c7SMaciej W. Rozycki * 1110 : Reserved
2911ce849c7SMaciej W. Rozycki * 1111 : IRQ15
2921ce849c7SMaciej W. Rozycki *
2931ce849c7SMaciej W. Rozycki * In addition to the usual ELCR register pair there is a separate
2941ce849c7SMaciej W. Rozycki * PCI INTx Sensitivity Register at index 0x44 in the same port I/O
2951ce849c7SMaciej W. Rozycki * space, whose bits 3:0 select the trigger mode for INT[4:1] lines
2961ce849c7SMaciej W. Rozycki * respectively. Any bit set to 1 causes interrupts coming on the
2971ce849c7SMaciej W. Rozycki * corresponding line to be passed to ISA as edge-triggered and
2981ce849c7SMaciej W. Rozycki * otherwise they are passed as level-triggered. Manufacturer's
2991ce849c7SMaciej W. Rozycki * documentation says this register has to be set consistently with
3001ce849c7SMaciej W. Rozycki * the relevant ELCR register.
3011ce849c7SMaciej W. Rozycki *
3021ce849c7SMaciej W. Rozycki * Accesses to the port I/O space concerned here need to be unlocked
3031ce849c7SMaciej W. Rozycki * by writing the value of 0xc5 to the Lock Register at index 0x03
3041ce849c7SMaciej W. Rozycki * beforehand. Any other value written to said register prevents
3051ce849c7SMaciej W. Rozycki * further accesses from reaching the register file, except for the
3061ce849c7SMaciej W. Rozycki * Lock Register being written with 0xc5 again.
3071ce849c7SMaciej W. Rozycki *
3081ce849c7SMaciej W. Rozycki * References:
3091ce849c7SMaciej W. Rozycki *
3101ce849c7SMaciej W. Rozycki * "M1489/M1487: 486 PCI Chip Set", Version 1.2, Acer Laboratories
3111ce849c7SMaciej W. Rozycki * Inc., July 1997
3121ce849c7SMaciej W. Rozycki */
3131ce849c7SMaciej W. Rozycki
3141ce849c7SMaciej W. Rozycki #define PC_CONF_FINALI_LOCK 0x03u
3151ce849c7SMaciej W. Rozycki #define PC_CONF_FINALI_PCI_INTX_RT1 0x42u
3161ce849c7SMaciej W. Rozycki #define PC_CONF_FINALI_PCI_INTX_RT2 0x43u
3171ce849c7SMaciej W. Rozycki #define PC_CONF_FINALI_PCI_INTX_SENS 0x44u
3181ce849c7SMaciej W. Rozycki
3191ce849c7SMaciej W. Rozycki #define PC_CONF_FINALI_LOCK_KEY 0xc5u
3201ce849c7SMaciej W. Rozycki
read_pc_conf_nybble(u8 base,u8 index)3211ce849c7SMaciej W. Rozycki static u8 read_pc_conf_nybble(u8 base, u8 index)
3221ce849c7SMaciej W. Rozycki {
3231ce849c7SMaciej W. Rozycki u8 reg = base + (index >> 1);
3241ce849c7SMaciej W. Rozycki u8 x;
3251ce849c7SMaciej W. Rozycki
3261ce849c7SMaciej W. Rozycki x = pc_conf_get(reg);
3271ce849c7SMaciej W. Rozycki return index & 1 ? x >> 4 : x & 0xf;
3281ce849c7SMaciej W. Rozycki }
3291ce849c7SMaciej W. Rozycki
write_pc_conf_nybble(u8 base,u8 index,u8 val)3301ce849c7SMaciej W. Rozycki static void write_pc_conf_nybble(u8 base, u8 index, u8 val)
3311ce849c7SMaciej W. Rozycki {
3321ce849c7SMaciej W. Rozycki u8 reg = base + (index >> 1);
3331ce849c7SMaciej W. Rozycki u8 x;
3341ce849c7SMaciej W. Rozycki
3351ce849c7SMaciej W. Rozycki x = pc_conf_get(reg);
3361ce849c7SMaciej W. Rozycki x = index & 1 ? (x & 0x0f) | (val << 4) : (x & 0xf0) | val;
3371ce849c7SMaciej W. Rozycki pc_conf_set(reg, x);
3381ce849c7SMaciej W. Rozycki }
3391ce849c7SMaciej W. Rozycki
3404969e223SMaciej W. Rozycki /*
3414969e223SMaciej W. Rozycki * FinALi pirq rules are as follows:
3424969e223SMaciej W. Rozycki *
3434969e223SMaciej W. Rozycki * - bit 0 selects between INTx Routing Table Mapping Registers,
3444969e223SMaciej W. Rozycki *
3454969e223SMaciej W. Rozycki * - bit 3 selects the nibble within the INTx Routing Table Mapping Register,
3464969e223SMaciej W. Rozycki *
3474969e223SMaciej W. Rozycki * - bits 7:4 map to bits 3:0 of the PCI INTx Sensitivity Register.
3484969e223SMaciej W. Rozycki */
pirq_finali_get(struct pci_dev * router,struct pci_dev * dev,int pirq)3491ce849c7SMaciej W. Rozycki static int pirq_finali_get(struct pci_dev *router, struct pci_dev *dev,
3501ce849c7SMaciej W. Rozycki int pirq)
3511ce849c7SMaciej W. Rozycki {
3521ce849c7SMaciej W. Rozycki static const u8 irqmap[16] = {
3531ce849c7SMaciej W. Rozycki 0, 9, 3, 10, 4, 5, 7, 6, 0, 11, 0, 12, 0, 14, 0, 15
3541ce849c7SMaciej W. Rozycki };
3551ce849c7SMaciej W. Rozycki unsigned long flags;
3564969e223SMaciej W. Rozycki u8 index;
3571ce849c7SMaciej W. Rozycki u8 x;
3581ce849c7SMaciej W. Rozycki
3594969e223SMaciej W. Rozycki index = (pirq & 1) << 1 | (pirq & 8) >> 3;
3601ce849c7SMaciej W. Rozycki raw_spin_lock_irqsave(&pc_conf_lock, flags);
3611ce849c7SMaciej W. Rozycki pc_conf_set(PC_CONF_FINALI_LOCK, PC_CONF_FINALI_LOCK_KEY);
3624969e223SMaciej W. Rozycki x = irqmap[read_pc_conf_nybble(PC_CONF_FINALI_PCI_INTX_RT1, index)];
3631ce849c7SMaciej W. Rozycki pc_conf_set(PC_CONF_FINALI_LOCK, 0);
3641ce849c7SMaciej W. Rozycki raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
3651ce849c7SMaciej W. Rozycki return x;
3661ce849c7SMaciej W. Rozycki }
3671ce849c7SMaciej W. Rozycki
pirq_finali_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)3681ce849c7SMaciej W. Rozycki static int pirq_finali_set(struct pci_dev *router, struct pci_dev *dev,
3691ce849c7SMaciej W. Rozycki int pirq, int irq)
3701ce849c7SMaciej W. Rozycki {
3711ce849c7SMaciej W. Rozycki static const u8 irqmap[16] = {
3721ce849c7SMaciej W. Rozycki 0, 0, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15
3731ce849c7SMaciej W. Rozycki };
3741ce849c7SMaciej W. Rozycki u8 val = irqmap[irq];
3751ce849c7SMaciej W. Rozycki unsigned long flags;
3764969e223SMaciej W. Rozycki u8 index;
3771ce849c7SMaciej W. Rozycki
3781ce849c7SMaciej W. Rozycki if (!val)
3791ce849c7SMaciej W. Rozycki return 0;
3801ce849c7SMaciej W. Rozycki
3814969e223SMaciej W. Rozycki index = (pirq & 1) << 1 | (pirq & 8) >> 3;
3821ce849c7SMaciej W. Rozycki raw_spin_lock_irqsave(&pc_conf_lock, flags);
3831ce849c7SMaciej W. Rozycki pc_conf_set(PC_CONF_FINALI_LOCK, PC_CONF_FINALI_LOCK_KEY);
3844969e223SMaciej W. Rozycki write_pc_conf_nybble(PC_CONF_FINALI_PCI_INTX_RT1, index, val);
3851ce849c7SMaciej W. Rozycki pc_conf_set(PC_CONF_FINALI_LOCK, 0);
3861ce849c7SMaciej W. Rozycki raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
3871ce849c7SMaciej W. Rozycki return 1;
3881ce849c7SMaciej W. Rozycki }
3891ce849c7SMaciej W. Rozycki
pirq_finali_lvl(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)3901ce849c7SMaciej W. Rozycki static int pirq_finali_lvl(struct pci_dev *router, struct pci_dev *dev,
3911ce849c7SMaciej W. Rozycki int pirq, int irq)
3921ce849c7SMaciej W. Rozycki {
3934969e223SMaciej W. Rozycki u8 mask = ~((pirq & 0xf0u) >> 4);
3941ce849c7SMaciej W. Rozycki unsigned long flags;
3951ce849c7SMaciej W. Rozycki u8 trig;
3961ce849c7SMaciej W. Rozycki
3971ce849c7SMaciej W. Rozycki elcr_set_level_irq(irq);
3981ce849c7SMaciej W. Rozycki raw_spin_lock_irqsave(&pc_conf_lock, flags);
3991ce849c7SMaciej W. Rozycki pc_conf_set(PC_CONF_FINALI_LOCK, PC_CONF_FINALI_LOCK_KEY);
4001ce849c7SMaciej W. Rozycki trig = pc_conf_get(PC_CONF_FINALI_PCI_INTX_SENS);
4011ce849c7SMaciej W. Rozycki trig &= mask;
4021ce849c7SMaciej W. Rozycki pc_conf_set(PC_CONF_FINALI_PCI_INTX_SENS, trig);
4031ce849c7SMaciej W. Rozycki pc_conf_set(PC_CONF_FINALI_LOCK, 0);
4041ce849c7SMaciej W. Rozycki raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
4051ce849c7SMaciej W. Rozycki return 1;
4061ce849c7SMaciej W. Rozycki }
4071ce849c7SMaciej W. Rozycki
4081ce849c7SMaciej W. Rozycki /*
40927b46d76SSimon Arlott * Common IRQ routing practice: nibbles in config space,
410fb9aa6f1SThomas Gleixner * offset by some magic constant.
411fb9aa6f1SThomas Gleixner */
read_config_nybble(struct pci_dev * router,unsigned offset,unsigned nr)412fb9aa6f1SThomas Gleixner static unsigned int read_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr)
413fb9aa6f1SThomas Gleixner {
414fb9aa6f1SThomas Gleixner u8 x;
415fb9aa6f1SThomas Gleixner unsigned reg = offset + (nr >> 1);
416fb9aa6f1SThomas Gleixner
417fb9aa6f1SThomas Gleixner pci_read_config_byte(router, reg, &x);
418fb9aa6f1SThomas Gleixner return (nr & 1) ? (x >> 4) : (x & 0xf);
419fb9aa6f1SThomas Gleixner }
420fb9aa6f1SThomas Gleixner
write_config_nybble(struct pci_dev * router,unsigned offset,unsigned nr,unsigned int val)421273c1127SMiklos Vajna static void write_config_nybble(struct pci_dev *router, unsigned offset,
422273c1127SMiklos Vajna unsigned nr, unsigned int val)
423fb9aa6f1SThomas Gleixner {
424fb9aa6f1SThomas Gleixner u8 x;
425fb9aa6f1SThomas Gleixner unsigned reg = offset + (nr >> 1);
426fb9aa6f1SThomas Gleixner
427fb9aa6f1SThomas Gleixner pci_read_config_byte(router, reg, &x);
428fb9aa6f1SThomas Gleixner x = (nr & 1) ? ((x & 0x0f) | (val << 4)) : ((x & 0xf0) | val);
429fb9aa6f1SThomas Gleixner pci_write_config_byte(router, reg, x);
430fb9aa6f1SThomas Gleixner }
431fb9aa6f1SThomas Gleixner
432fb9aa6f1SThomas Gleixner /*
433fb9aa6f1SThomas Gleixner * ALI pirq entries are damn ugly, and completely undocumented.
434fb9aa6f1SThomas Gleixner * This has been figured out from pirq tables, and it's not a pretty
435fb9aa6f1SThomas Gleixner * picture.
436fb9aa6f1SThomas Gleixner */
pirq_ali_get(struct pci_dev * router,struct pci_dev * dev,int pirq)437fb9aa6f1SThomas Gleixner static int pirq_ali_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
438fb9aa6f1SThomas Gleixner {
439fb9aa6f1SThomas Gleixner static const unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };
440fb9aa6f1SThomas Gleixner
441223ac2f4SBjörn Steinbrink WARN_ON_ONCE(pirq > 16);
442fb9aa6f1SThomas Gleixner return irqmap[read_config_nybble(router, 0x48, pirq-1)];
443fb9aa6f1SThomas Gleixner }
444fb9aa6f1SThomas Gleixner
pirq_ali_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)445fb9aa6f1SThomas Gleixner static int pirq_ali_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
446fb9aa6f1SThomas Gleixner {
447fb9aa6f1SThomas Gleixner static const unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };
448fb9aa6f1SThomas Gleixner unsigned int val = irqmap[irq];
449fb9aa6f1SThomas Gleixner
450223ac2f4SBjörn Steinbrink WARN_ON_ONCE(pirq > 16);
451fb9aa6f1SThomas Gleixner if (val) {
452fb9aa6f1SThomas Gleixner write_config_nybble(router, 0x48, pirq-1, val);
453fb9aa6f1SThomas Gleixner return 1;
454fb9aa6f1SThomas Gleixner }
455fb9aa6f1SThomas Gleixner return 0;
456fb9aa6f1SThomas Gleixner }
457fb9aa6f1SThomas Gleixner
458fb9aa6f1SThomas Gleixner /*
4596b79164fSMaciej W. Rozycki * PIRQ routing for the 82374EB/82374SB EISA System Component (ESC)
4606b79164fSMaciej W. Rozycki * ASIC used with the Intel 82420 and 82430 PCIsets. The ESC is not
4616b79164fSMaciej W. Rozycki * decoded in the PCI configuration space, so we identify it by the
4626b79164fSMaciej W. Rozycki * accompanying 82375EB/82375SB PCI-EISA Bridge (PCEB) ASIC.
4636b79164fSMaciej W. Rozycki *
4646b79164fSMaciej W. Rozycki * There are four PIRQ Route Control registers, available in the
4656b79164fSMaciej W. Rozycki * port I/O space accessible indirectly via the index/data register
4666b79164fSMaciej W. Rozycki * pair at 0x22/0x23, located at indices 0x60/0x61/0x62/0x63 for the
4676b79164fSMaciej W. Rozycki * PIRQ0/1/2/3# lines respectively. The semantics is the same as
4686b79164fSMaciej W. Rozycki * with the PIIX router.
4696b79164fSMaciej W. Rozycki *
4706b79164fSMaciej W. Rozycki * Accesses to the port I/O space concerned here need to be unlocked
4716b79164fSMaciej W. Rozycki * by writing the value of 0x0f to the ESC ID Register at index 0x02
4726b79164fSMaciej W. Rozycki * beforehand. Any other value written to said register prevents
4736b79164fSMaciej W. Rozycki * further accesses from reaching the register file, except for the
4746b79164fSMaciej W. Rozycki * ESC ID Register being written with 0x0f again.
4756b79164fSMaciej W. Rozycki *
4766b79164fSMaciej W. Rozycki * References:
4776b79164fSMaciej W. Rozycki *
4786b79164fSMaciej W. Rozycki * "82374EB/82374SB EISA System Component (ESC)", Intel Corporation,
4796b79164fSMaciej W. Rozycki * Order Number: 290476-004, March 1996
4806b79164fSMaciej W. Rozycki *
4816b79164fSMaciej W. Rozycki * "82375EB/82375SB PCI-EISA Bridge (PCEB)", Intel Corporation, Order
4826b79164fSMaciej W. Rozycki * Number: 290477-004, March 1996
4836b79164fSMaciej W. Rozycki */
4846b79164fSMaciej W. Rozycki
4856b79164fSMaciej W. Rozycki #define PC_CONF_I82374_ESC_ID 0x02u
4866b79164fSMaciej W. Rozycki #define PC_CONF_I82374_PIRQ_ROUTE_CONTROL 0x60u
4876b79164fSMaciej W. Rozycki
4886b79164fSMaciej W. Rozycki #define PC_CONF_I82374_ESC_ID_KEY 0x0fu
4896b79164fSMaciej W. Rozycki
pirq_esc_get(struct pci_dev * router,struct pci_dev * dev,int pirq)4906b79164fSMaciej W. Rozycki static int pirq_esc_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
4916b79164fSMaciej W. Rozycki {
4926b79164fSMaciej W. Rozycki unsigned long flags;
4936b79164fSMaciej W. Rozycki int reg;
4946b79164fSMaciej W. Rozycki u8 x;
4956b79164fSMaciej W. Rozycki
4966b79164fSMaciej W. Rozycki reg = pirq;
4976b79164fSMaciej W. Rozycki if (reg >= 1 && reg <= 4)
4986b79164fSMaciej W. Rozycki reg += PC_CONF_I82374_PIRQ_ROUTE_CONTROL - 1;
4996b79164fSMaciej W. Rozycki
5006b79164fSMaciej W. Rozycki raw_spin_lock_irqsave(&pc_conf_lock, flags);
5016b79164fSMaciej W. Rozycki pc_conf_set(PC_CONF_I82374_ESC_ID, PC_CONF_I82374_ESC_ID_KEY);
5026b79164fSMaciej W. Rozycki x = pc_conf_get(reg);
5036b79164fSMaciej W. Rozycki pc_conf_set(PC_CONF_I82374_ESC_ID, 0);
5046b79164fSMaciej W. Rozycki raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
5056b79164fSMaciej W. Rozycki return (x < 16) ? x : 0;
5066b79164fSMaciej W. Rozycki }
5076b79164fSMaciej W. Rozycki
pirq_esc_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)5086b79164fSMaciej W. Rozycki static int pirq_esc_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
5096b79164fSMaciej W. Rozycki int irq)
5106b79164fSMaciej W. Rozycki {
5116b79164fSMaciej W. Rozycki unsigned long flags;
5126b79164fSMaciej W. Rozycki int reg;
5136b79164fSMaciej W. Rozycki
5146b79164fSMaciej W. Rozycki reg = pirq;
5156b79164fSMaciej W. Rozycki if (reg >= 1 && reg <= 4)
5166b79164fSMaciej W. Rozycki reg += PC_CONF_I82374_PIRQ_ROUTE_CONTROL - 1;
5176b79164fSMaciej W. Rozycki
5186b79164fSMaciej W. Rozycki raw_spin_lock_irqsave(&pc_conf_lock, flags);
5196b79164fSMaciej W. Rozycki pc_conf_set(PC_CONF_I82374_ESC_ID, PC_CONF_I82374_ESC_ID_KEY);
5206b79164fSMaciej W. Rozycki pc_conf_set(reg, irq);
5216b79164fSMaciej W. Rozycki pc_conf_set(PC_CONF_I82374_ESC_ID, 0);
5226b79164fSMaciej W. Rozycki raw_spin_unlock_irqrestore(&pc_conf_lock, flags);
5236b79164fSMaciej W. Rozycki return 1;
5246b79164fSMaciej W. Rozycki }
5256b79164fSMaciej W. Rozycki
5266b79164fSMaciej W. Rozycki /*
527fb9aa6f1SThomas Gleixner * The Intel PIIX4 pirq rules are fairly simple: "pirq" is
528fb9aa6f1SThomas Gleixner * just a pointer to the config space.
529fb9aa6f1SThomas Gleixner */
pirq_piix_get(struct pci_dev * router,struct pci_dev * dev,int pirq)530fb9aa6f1SThomas Gleixner static int pirq_piix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
531fb9aa6f1SThomas Gleixner {
532fb9aa6f1SThomas Gleixner u8 x;
533fb9aa6f1SThomas Gleixner
534fb9aa6f1SThomas Gleixner pci_read_config_byte(router, pirq, &x);
535fb9aa6f1SThomas Gleixner return (x < 16) ? x : 0;
536fb9aa6f1SThomas Gleixner }
537fb9aa6f1SThomas Gleixner
pirq_piix_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)538fb9aa6f1SThomas Gleixner static int pirq_piix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
539fb9aa6f1SThomas Gleixner {
540fb9aa6f1SThomas Gleixner pci_write_config_byte(router, pirq, irq);
541fb9aa6f1SThomas Gleixner return 1;
542fb9aa6f1SThomas Gleixner }
543fb9aa6f1SThomas Gleixner
544fb9aa6f1SThomas Gleixner /*
5450e8c6f56SMaciej W. Rozycki * PIRQ routing for the 82426EX ISA Bridge (IB) ASIC used with the
5460e8c6f56SMaciej W. Rozycki * Intel 82420EX PCIset.
5470e8c6f56SMaciej W. Rozycki *
5480e8c6f56SMaciej W. Rozycki * There are only two PIRQ Route Control registers, available in the
5490e8c6f56SMaciej W. Rozycki * combined 82425EX/82426EX PCI configuration space, at 0x66 and 0x67
5500e8c6f56SMaciej W. Rozycki * for the PIRQ0# and PIRQ1# lines respectively. The semantics is
5510e8c6f56SMaciej W. Rozycki * the same as with the PIIX router.
5520e8c6f56SMaciej W. Rozycki *
5530e8c6f56SMaciej W. Rozycki * References:
5540e8c6f56SMaciej W. Rozycki *
5550e8c6f56SMaciej W. Rozycki * "82420EX PCIset Data Sheet, 82425EX PCI System Controller (PSC)
5560e8c6f56SMaciej W. Rozycki * and 82426EX ISA Bridge (IB)", Intel Corporation, Order Number:
5570e8c6f56SMaciej W. Rozycki * 290488-004, December 1995
5580e8c6f56SMaciej W. Rozycki */
5590e8c6f56SMaciej W. Rozycki
5600e8c6f56SMaciej W. Rozycki #define PCI_I82426EX_PIRQ_ROUTE_CONTROL 0x66u
5610e8c6f56SMaciej W. Rozycki
pirq_ib_get(struct pci_dev * router,struct pci_dev * dev,int pirq)5620e8c6f56SMaciej W. Rozycki static int pirq_ib_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
5630e8c6f56SMaciej W. Rozycki {
5640e8c6f56SMaciej W. Rozycki int reg;
5650e8c6f56SMaciej W. Rozycki u8 x;
5660e8c6f56SMaciej W. Rozycki
5670e8c6f56SMaciej W. Rozycki reg = pirq;
5680e8c6f56SMaciej W. Rozycki if (reg >= 1 && reg <= 2)
5690e8c6f56SMaciej W. Rozycki reg += PCI_I82426EX_PIRQ_ROUTE_CONTROL - 1;
5700e8c6f56SMaciej W. Rozycki
5710e8c6f56SMaciej W. Rozycki pci_read_config_byte(router, reg, &x);
5720e8c6f56SMaciej W. Rozycki return (x < 16) ? x : 0;
5730e8c6f56SMaciej W. Rozycki }
5740e8c6f56SMaciej W. Rozycki
pirq_ib_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)5750e8c6f56SMaciej W. Rozycki static int pirq_ib_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
5760e8c6f56SMaciej W. Rozycki int irq)
5770e8c6f56SMaciej W. Rozycki {
5780e8c6f56SMaciej W. Rozycki int reg;
5790e8c6f56SMaciej W. Rozycki
5800e8c6f56SMaciej W. Rozycki reg = pirq;
5810e8c6f56SMaciej W. Rozycki if (reg >= 1 && reg <= 2)
5820e8c6f56SMaciej W. Rozycki reg += PCI_I82426EX_PIRQ_ROUTE_CONTROL - 1;
5830e8c6f56SMaciej W. Rozycki
5840e8c6f56SMaciej W. Rozycki pci_write_config_byte(router, reg, irq);
5850e8c6f56SMaciej W. Rozycki return 1;
5860e8c6f56SMaciej W. Rozycki }
5870e8c6f56SMaciej W. Rozycki
5880e8c6f56SMaciej W. Rozycki /*
589fb9aa6f1SThomas Gleixner * The VIA pirq rules are nibble-based, like ALI,
590fb9aa6f1SThomas Gleixner * but without the ugly irq number munging.
591fb9aa6f1SThomas Gleixner * However, PIRQD is in the upper instead of lower 4 bits.
592fb9aa6f1SThomas Gleixner */
pirq_via_get(struct pci_dev * router,struct pci_dev * dev,int pirq)593fb9aa6f1SThomas Gleixner static int pirq_via_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
594fb9aa6f1SThomas Gleixner {
595fb9aa6f1SThomas Gleixner return read_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq);
596fb9aa6f1SThomas Gleixner }
597fb9aa6f1SThomas Gleixner
pirq_via_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)598fb9aa6f1SThomas Gleixner static int pirq_via_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
599fb9aa6f1SThomas Gleixner {
600fb9aa6f1SThomas Gleixner write_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq, irq);
601fb9aa6f1SThomas Gleixner return 1;
602fb9aa6f1SThomas Gleixner }
603fb9aa6f1SThomas Gleixner
604fb9aa6f1SThomas Gleixner /*
605fb9aa6f1SThomas Gleixner * The VIA pirq rules are nibble-based, like ALI,
606fb9aa6f1SThomas Gleixner * but without the ugly irq number munging.
607fb9aa6f1SThomas Gleixner * However, for 82C586, nibble map is different .
608fb9aa6f1SThomas Gleixner */
pirq_via586_get(struct pci_dev * router,struct pci_dev * dev,int pirq)609fb9aa6f1SThomas Gleixner static int pirq_via586_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
610fb9aa6f1SThomas Gleixner {
611fb9aa6f1SThomas Gleixner static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
6127d409d60SIngo Molnar
613223ac2f4SBjörn Steinbrink WARN_ON_ONCE(pirq > 5);
614fb9aa6f1SThomas Gleixner return read_config_nybble(router, 0x55, pirqmap[pirq-1]);
615fb9aa6f1SThomas Gleixner }
616fb9aa6f1SThomas Gleixner
pirq_via586_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)617fb9aa6f1SThomas Gleixner static int pirq_via586_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
618fb9aa6f1SThomas Gleixner {
619fb9aa6f1SThomas Gleixner static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
6207d409d60SIngo Molnar
621223ac2f4SBjörn Steinbrink WARN_ON_ONCE(pirq > 5);
622fb9aa6f1SThomas Gleixner write_config_nybble(router, 0x55, pirqmap[pirq-1], irq);
623fb9aa6f1SThomas Gleixner return 1;
624fb9aa6f1SThomas Gleixner }
625fb9aa6f1SThomas Gleixner
626fb9aa6f1SThomas Gleixner /*
627fb9aa6f1SThomas Gleixner * ITE 8330G pirq rules are nibble-based
628fb9aa6f1SThomas Gleixner * FIXME: pirqmap may be { 1, 0, 3, 2 },
629fb9aa6f1SThomas Gleixner * 2+3 are both mapped to irq 9 on my system
630fb9aa6f1SThomas Gleixner */
pirq_ite_get(struct pci_dev * router,struct pci_dev * dev,int pirq)631fb9aa6f1SThomas Gleixner static int pirq_ite_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
632fb9aa6f1SThomas Gleixner {
633fb9aa6f1SThomas Gleixner static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
6347d409d60SIngo Molnar
635223ac2f4SBjörn Steinbrink WARN_ON_ONCE(pirq > 4);
636fb9aa6f1SThomas Gleixner return read_config_nybble(router, 0x43, pirqmap[pirq-1]);
637fb9aa6f1SThomas Gleixner }
638fb9aa6f1SThomas Gleixner
pirq_ite_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)639fb9aa6f1SThomas Gleixner static int pirq_ite_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
640fb9aa6f1SThomas Gleixner {
641fb9aa6f1SThomas Gleixner static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
6427d409d60SIngo Molnar
643223ac2f4SBjörn Steinbrink WARN_ON_ONCE(pirq > 4);
644fb9aa6f1SThomas Gleixner write_config_nybble(router, 0x43, pirqmap[pirq-1], irq);
645fb9aa6f1SThomas Gleixner return 1;
646fb9aa6f1SThomas Gleixner }
647fb9aa6f1SThomas Gleixner
648fb9aa6f1SThomas Gleixner /*
649fb9aa6f1SThomas Gleixner * OPTI: high four bits are nibble pointer..
650fb9aa6f1SThomas Gleixner * I wonder what the low bits do?
651fb9aa6f1SThomas Gleixner */
pirq_opti_get(struct pci_dev * router,struct pci_dev * dev,int pirq)652fb9aa6f1SThomas Gleixner static int pirq_opti_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
653fb9aa6f1SThomas Gleixner {
654fb9aa6f1SThomas Gleixner return read_config_nybble(router, 0xb8, pirq >> 4);
655fb9aa6f1SThomas Gleixner }
656fb9aa6f1SThomas Gleixner
pirq_opti_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)657fb9aa6f1SThomas Gleixner static int pirq_opti_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
658fb9aa6f1SThomas Gleixner {
659fb9aa6f1SThomas Gleixner write_config_nybble(router, 0xb8, pirq >> 4, irq);
660fb9aa6f1SThomas Gleixner return 1;
661fb9aa6f1SThomas Gleixner }
662fb9aa6f1SThomas Gleixner
663fb9aa6f1SThomas Gleixner /*
664fb9aa6f1SThomas Gleixner * Cyrix: nibble offset 0x5C
665fb9aa6f1SThomas Gleixner * 0x5C bits 7:4 is INTB bits 3:0 is INTA
666fb9aa6f1SThomas Gleixner * 0x5D bits 7:4 is INTD bits 3:0 is INTC
667fb9aa6f1SThomas Gleixner */
pirq_cyrix_get(struct pci_dev * router,struct pci_dev * dev,int pirq)668fb9aa6f1SThomas Gleixner static int pirq_cyrix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
669fb9aa6f1SThomas Gleixner {
670fb9aa6f1SThomas Gleixner return read_config_nybble(router, 0x5C, (pirq-1)^1);
671fb9aa6f1SThomas Gleixner }
672fb9aa6f1SThomas Gleixner
pirq_cyrix_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)673fb9aa6f1SThomas Gleixner static int pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
674fb9aa6f1SThomas Gleixner {
675fb9aa6f1SThomas Gleixner write_config_nybble(router, 0x5C, (pirq-1)^1, irq);
676fb9aa6f1SThomas Gleixner return 1;
677fb9aa6f1SThomas Gleixner }
678fb9aa6f1SThomas Gleixner
679fe62bc23SMaciej W. Rozycki
680fe62bc23SMaciej W. Rozycki /*
681fe62bc23SMaciej W. Rozycki * PIRQ routing for the SiS85C497 AT Bus Controller & Megacell (ATM)
682fe62bc23SMaciej W. Rozycki * ISA bridge used with the SiS 85C496/497 486 Green PC VESA/ISA/PCI
683fe62bc23SMaciej W. Rozycki * Chipset.
684fe62bc23SMaciej W. Rozycki *
685fe62bc23SMaciej W. Rozycki * There are four PCI INTx#-to-IRQ Link registers provided in the
686fe62bc23SMaciej W. Rozycki * SiS85C497 part of the peculiar combined 85C496/497 configuration
687fe62bc23SMaciej W. Rozycki * space decoded by the SiS85C496 PCI & CPU Memory Controller (PCM)
688fe62bc23SMaciej W. Rozycki * host bridge, at 0xc0/0xc1/0xc2/0xc3 respectively for the PCI INT
689fe62bc23SMaciej W. Rozycki * A/B/C/D lines. Bit 7 enables the respective link if set and bits
690fe62bc23SMaciej W. Rozycki * 3:0 select the 8259A IRQ line as follows:
691fe62bc23SMaciej W. Rozycki *
692fe62bc23SMaciej W. Rozycki * 0000 : Reserved
693fe62bc23SMaciej W. Rozycki * 0001 : Reserved
694fe62bc23SMaciej W. Rozycki * 0010 : Reserved
695fe62bc23SMaciej W. Rozycki * 0011 : IRQ3
696fe62bc23SMaciej W. Rozycki * 0100 : IRQ4
697fe62bc23SMaciej W. Rozycki * 0101 : IRQ5
698fe62bc23SMaciej W. Rozycki * 0110 : IRQ6
699fe62bc23SMaciej W. Rozycki * 0111 : IRQ7
700fe62bc23SMaciej W. Rozycki * 1000 : Reserved
701fe62bc23SMaciej W. Rozycki * 1001 : IRQ9
702fe62bc23SMaciej W. Rozycki * 1010 : IRQ10
703fe62bc23SMaciej W. Rozycki * 1011 : IRQ11
704fe62bc23SMaciej W. Rozycki * 1100 : IRQ12
705fe62bc23SMaciej W. Rozycki * 1101 : Reserved
706fe62bc23SMaciej W. Rozycki * 1110 : IRQ14
707fe62bc23SMaciej W. Rozycki * 1111 : IRQ15
708fe62bc23SMaciej W. Rozycki *
709fe62bc23SMaciej W. Rozycki * We avoid using a reserved value for disabled links, hence the
710fe62bc23SMaciej W. Rozycki * choice of IRQ15 for that case.
711fe62bc23SMaciej W. Rozycki *
712fe62bc23SMaciej W. Rozycki * References:
713fe62bc23SMaciej W. Rozycki *
714fe62bc23SMaciej W. Rozycki * "486 Green PC VESA/ISA/PCI Chipset, SiS 85C496/497", Rev 3.0,
715fe62bc23SMaciej W. Rozycki * Silicon Integrated Systems Corp., July 1995
716fe62bc23SMaciej W. Rozycki */
717fe62bc23SMaciej W. Rozycki
718fe62bc23SMaciej W. Rozycki #define PCI_SIS497_INTA_TO_IRQ_LINK 0xc0u
719fe62bc23SMaciej W. Rozycki
720fe62bc23SMaciej W. Rozycki #define PIRQ_SIS497_IRQ_MASK 0x0fu
721fe62bc23SMaciej W. Rozycki #define PIRQ_SIS497_IRQ_ENABLE 0x80u
722fe62bc23SMaciej W. Rozycki
pirq_sis497_get(struct pci_dev * router,struct pci_dev * dev,int pirq)723fe62bc23SMaciej W. Rozycki static int pirq_sis497_get(struct pci_dev *router, struct pci_dev *dev,
724fe62bc23SMaciej W. Rozycki int pirq)
725fe62bc23SMaciej W. Rozycki {
726fe62bc23SMaciej W. Rozycki int reg;
727fe62bc23SMaciej W. Rozycki u8 x;
728fe62bc23SMaciej W. Rozycki
729fe62bc23SMaciej W. Rozycki reg = pirq;
730fe62bc23SMaciej W. Rozycki if (reg >= 1 && reg <= 4)
731fe62bc23SMaciej W. Rozycki reg += PCI_SIS497_INTA_TO_IRQ_LINK - 1;
732fe62bc23SMaciej W. Rozycki
733fe62bc23SMaciej W. Rozycki pci_read_config_byte(router, reg, &x);
734fe62bc23SMaciej W. Rozycki return (x & PIRQ_SIS497_IRQ_ENABLE) ? (x & PIRQ_SIS497_IRQ_MASK) : 0;
735fe62bc23SMaciej W. Rozycki }
736fe62bc23SMaciej W. Rozycki
pirq_sis497_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)737fe62bc23SMaciej W. Rozycki static int pirq_sis497_set(struct pci_dev *router, struct pci_dev *dev,
738fe62bc23SMaciej W. Rozycki int pirq, int irq)
739fe62bc23SMaciej W. Rozycki {
740fe62bc23SMaciej W. Rozycki int reg;
741fe62bc23SMaciej W. Rozycki u8 x;
742fe62bc23SMaciej W. Rozycki
743fe62bc23SMaciej W. Rozycki reg = pirq;
744fe62bc23SMaciej W. Rozycki if (reg >= 1 && reg <= 4)
745fe62bc23SMaciej W. Rozycki reg += PCI_SIS497_INTA_TO_IRQ_LINK - 1;
746fe62bc23SMaciej W. Rozycki
747fe62bc23SMaciej W. Rozycki pci_read_config_byte(router, reg, &x);
748fe62bc23SMaciej W. Rozycki x &= ~(PIRQ_SIS497_IRQ_MASK | PIRQ_SIS497_IRQ_ENABLE);
749fe62bc23SMaciej W. Rozycki x |= irq ? (PIRQ_SIS497_IRQ_ENABLE | irq) : PIRQ_SIS497_IRQ_MASK;
750fe62bc23SMaciej W. Rozycki pci_write_config_byte(router, reg, x);
751fe62bc23SMaciej W. Rozycki return 1;
752fe62bc23SMaciej W. Rozycki }
753fe62bc23SMaciej W. Rozycki
754fb9aa6f1SThomas Gleixner /*
755fb9aa6f1SThomas Gleixner * PIRQ routing for SiS 85C503 router used in several SiS chipsets.
756fb9aa6f1SThomas Gleixner * We have to deal with the following issues here:
757fb9aa6f1SThomas Gleixner * - vendors have different ideas about the meaning of link values
758fb9aa6f1SThomas Gleixner * - some onboard devices (integrated in the chipset) have special
759fb9aa6f1SThomas Gleixner * links and are thus routed differently (i.e. not via PCI INTA-INTD)
760fb9aa6f1SThomas Gleixner * - different revision of the router have a different layout for
761fb9aa6f1SThomas Gleixner * the routing registers, particularly for the onchip devices
762fb9aa6f1SThomas Gleixner *
763fb9aa6f1SThomas Gleixner * For all routing registers the common thing is we have one byte
764fb9aa6f1SThomas Gleixner * per routeable link which is defined as:
765fb9aa6f1SThomas Gleixner * bit 7 IRQ mapping enabled (0) or disabled (1)
766fb9aa6f1SThomas Gleixner * bits [6:4] reserved (sometimes used for onchip devices)
767fb9aa6f1SThomas Gleixner * bits [3:0] IRQ to map to
768fb9aa6f1SThomas Gleixner * allowed: 3-7, 9-12, 14-15
769fb9aa6f1SThomas Gleixner * reserved: 0, 1, 2, 8, 13
770fb9aa6f1SThomas Gleixner *
771fb9aa6f1SThomas Gleixner * The config-space registers located at 0x41/0x42/0x43/0x44 are
772fb9aa6f1SThomas Gleixner * always used to route the normal PCI INT A/B/C/D respectively.
773fb9aa6f1SThomas Gleixner * Apparently there are systems implementing PCI routing table using
774fb9aa6f1SThomas Gleixner * link values 0x01-0x04 and others using 0x41-0x44 for PCI INTA..D.
775fb9aa6f1SThomas Gleixner * We try our best to handle both link mappings.
776fb9aa6f1SThomas Gleixner *
777fb9aa6f1SThomas Gleixner * Currently (2003-05-21) it appears most SiS chipsets follow the
778fb9aa6f1SThomas Gleixner * definition of routing registers from the SiS-5595 southbridge.
779fb9aa6f1SThomas Gleixner * According to the SiS 5595 datasheets the revision id's of the
780fb9aa6f1SThomas Gleixner * router (ISA-bridge) should be 0x01 or 0xb0.
781fb9aa6f1SThomas Gleixner *
782fb9aa6f1SThomas Gleixner * Furthermore we've also seen lspci dumps with revision 0x00 and 0xb1.
783fb9aa6f1SThomas Gleixner * Looks like these are used in a number of SiS 5xx/6xx/7xx chipsets.
784fb9aa6f1SThomas Gleixner * They seem to work with the current routing code. However there is
785fb9aa6f1SThomas Gleixner * some concern because of the two USB-OHCI HCs (original SiS 5595
786fb9aa6f1SThomas Gleixner * had only one). YMMV.
787fb9aa6f1SThomas Gleixner *
788fb9aa6f1SThomas Gleixner * Onchip routing for router rev-id 0x01/0xb0 and probably 0x00/0xb1:
789fb9aa6f1SThomas Gleixner *
790fb9aa6f1SThomas Gleixner * 0x61: IDEIRQ:
791fb9aa6f1SThomas Gleixner * bits [6:5] must be written 01
792fb9aa6f1SThomas Gleixner * bit 4 channel-select primary (0), secondary (1)
793fb9aa6f1SThomas Gleixner *
794fb9aa6f1SThomas Gleixner * 0x62: USBIRQ:
795fb9aa6f1SThomas Gleixner * bit 6 OHCI function disabled (0), enabled (1)
796fb9aa6f1SThomas Gleixner *
797fb9aa6f1SThomas Gleixner * 0x6a: ACPI/SCI IRQ: bits 4-6 reserved
798fb9aa6f1SThomas Gleixner *
799fb9aa6f1SThomas Gleixner * 0x7e: Data Acq. Module IRQ - bits 4-6 reserved
800fb9aa6f1SThomas Gleixner *
801fb9aa6f1SThomas Gleixner * We support USBIRQ (in addition to INTA-INTD) and keep the
802fb9aa6f1SThomas Gleixner * IDE, ACPI and DAQ routing untouched as set by the BIOS.
803fb9aa6f1SThomas Gleixner *
804fb9aa6f1SThomas Gleixner * Currently the only reported exception is the new SiS 65x chipset
805fb9aa6f1SThomas Gleixner * which includes the SiS 69x southbridge. Here we have the 85C503
806fb9aa6f1SThomas Gleixner * router revision 0x04 and there are changes in the register layout
807fb9aa6f1SThomas Gleixner * mostly related to the different USB HCs with USB 2.0 support.
808fb9aa6f1SThomas Gleixner *
809fb9aa6f1SThomas Gleixner * Onchip routing for router rev-id 0x04 (try-and-error observation)
810fb9aa6f1SThomas Gleixner *
811fb9aa6f1SThomas Gleixner * 0x60/0x61/0x62/0x63: 1xEHCI and 3xOHCI (companion) USB-HCs
812fb9aa6f1SThomas Gleixner * bit 6-4 are probably unused, not like 5595
813fb9aa6f1SThomas Gleixner */
814fb9aa6f1SThomas Gleixner
8155a0e5fa9SMaciej W. Rozycki #define PIRQ_SIS503_IRQ_MASK 0x0f
8165a0e5fa9SMaciej W. Rozycki #define PIRQ_SIS503_IRQ_DISABLE 0x80
8175a0e5fa9SMaciej W. Rozycki #define PIRQ_SIS503_USB_ENABLE 0x40
818fb9aa6f1SThomas Gleixner
pirq_sis503_get(struct pci_dev * router,struct pci_dev * dev,int pirq)8195a0e5fa9SMaciej W. Rozycki static int pirq_sis503_get(struct pci_dev *router, struct pci_dev *dev,
8205a0e5fa9SMaciej W. Rozycki int pirq)
821fb9aa6f1SThomas Gleixner {
822fb9aa6f1SThomas Gleixner u8 x;
823fb9aa6f1SThomas Gleixner int reg;
824fb9aa6f1SThomas Gleixner
825fb9aa6f1SThomas Gleixner reg = pirq;
826fb9aa6f1SThomas Gleixner if (reg >= 0x01 && reg <= 0x04)
827fb9aa6f1SThomas Gleixner reg += 0x40;
828fb9aa6f1SThomas Gleixner pci_read_config_byte(router, reg, &x);
8295a0e5fa9SMaciej W. Rozycki return (x & PIRQ_SIS503_IRQ_DISABLE) ? 0 : (x & PIRQ_SIS503_IRQ_MASK);
830fb9aa6f1SThomas Gleixner }
831fb9aa6f1SThomas Gleixner
pirq_sis503_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)8325a0e5fa9SMaciej W. Rozycki static int pirq_sis503_set(struct pci_dev *router, struct pci_dev *dev,
8335a0e5fa9SMaciej W. Rozycki int pirq, int irq)
834fb9aa6f1SThomas Gleixner {
835fb9aa6f1SThomas Gleixner u8 x;
836fb9aa6f1SThomas Gleixner int reg;
837fb9aa6f1SThomas Gleixner
838fb9aa6f1SThomas Gleixner reg = pirq;
839fb9aa6f1SThomas Gleixner if (reg >= 0x01 && reg <= 0x04)
840fb9aa6f1SThomas Gleixner reg += 0x40;
841fb9aa6f1SThomas Gleixner pci_read_config_byte(router, reg, &x);
8425a0e5fa9SMaciej W. Rozycki x &= ~(PIRQ_SIS503_IRQ_MASK | PIRQ_SIS503_IRQ_DISABLE);
8435a0e5fa9SMaciej W. Rozycki x |= irq ? irq : PIRQ_SIS503_IRQ_DISABLE;
844fb9aa6f1SThomas Gleixner pci_write_config_byte(router, reg, x);
845fb9aa6f1SThomas Gleixner return 1;
846fb9aa6f1SThomas Gleixner }
847fb9aa6f1SThomas Gleixner
848fb9aa6f1SThomas Gleixner
849fb9aa6f1SThomas Gleixner /*
850fb9aa6f1SThomas Gleixner * VLSI: nibble offset 0x74 - educated guess due to routing table and
851fb9aa6f1SThomas Gleixner * config space of VLSI 82C534 PCI-bridge/router (1004:0102)
852fb9aa6f1SThomas Gleixner * Tested on HP OmniBook 800 covering PIRQ 1, 2, 4, 8 for onboard
853fb9aa6f1SThomas Gleixner * devices, PIRQ 3 for non-pci(!) soundchip and (untested) PIRQ 6
854fb9aa6f1SThomas Gleixner * for the busbridge to the docking station.
855fb9aa6f1SThomas Gleixner */
856fb9aa6f1SThomas Gleixner
pirq_vlsi_get(struct pci_dev * router,struct pci_dev * dev,int pirq)857fb9aa6f1SThomas Gleixner static int pirq_vlsi_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
858fb9aa6f1SThomas Gleixner {
8597d409d60SIngo Molnar WARN_ON_ONCE(pirq >= 9);
860fb9aa6f1SThomas Gleixner if (pirq > 8) {
86112c0b20fSBjorn Helgaas dev_info(&dev->dev, "VLSI router PIRQ escape (%d)\n", pirq);
862fb9aa6f1SThomas Gleixner return 0;
863fb9aa6f1SThomas Gleixner }
864fb9aa6f1SThomas Gleixner return read_config_nybble(router, 0x74, pirq-1);
865fb9aa6f1SThomas Gleixner }
866fb9aa6f1SThomas Gleixner
pirq_vlsi_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)867fb9aa6f1SThomas Gleixner static int pirq_vlsi_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
868fb9aa6f1SThomas Gleixner {
8697d409d60SIngo Molnar WARN_ON_ONCE(pirq >= 9);
870fb9aa6f1SThomas Gleixner if (pirq > 8) {
87112c0b20fSBjorn Helgaas dev_info(&dev->dev, "VLSI router PIRQ escape (%d)\n", pirq);
872fb9aa6f1SThomas Gleixner return 0;
873fb9aa6f1SThomas Gleixner }
874fb9aa6f1SThomas Gleixner write_config_nybble(router, 0x74, pirq-1, irq);
875fb9aa6f1SThomas Gleixner return 1;
876fb9aa6f1SThomas Gleixner }
877fb9aa6f1SThomas Gleixner
878fb9aa6f1SThomas Gleixner /*
879fb9aa6f1SThomas Gleixner * ServerWorks: PCI interrupts mapped to system IRQ lines through Index
880fb9aa6f1SThomas Gleixner * and Redirect I/O registers (0x0c00 and 0x0c01). The Index register
881fb9aa6f1SThomas Gleixner * format is (PCIIRQ## | 0x10), e.g.: PCIIRQ10=0x1a. The Redirect
882fb9aa6f1SThomas Gleixner * register is a straight binary coding of desired PIC IRQ (low nibble).
883fb9aa6f1SThomas Gleixner *
884fb9aa6f1SThomas Gleixner * The 'link' value in the PIRQ table is already in the correct format
885fb9aa6f1SThomas Gleixner * for the Index register. There are some special index values:
886fb9aa6f1SThomas Gleixner * 0x00 for ACPI (SCI), 0x01 for USB, 0x02 for IDE0, 0x04 for IDE1,
887fb9aa6f1SThomas Gleixner * and 0x03 for SMBus.
888fb9aa6f1SThomas Gleixner */
pirq_serverworks_get(struct pci_dev * router,struct pci_dev * dev,int pirq)889fb9aa6f1SThomas Gleixner static int pirq_serverworks_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
890fb9aa6f1SThomas Gleixner {
891c11b68bcSAlan Cox outb(pirq, 0xc00);
892fb9aa6f1SThomas Gleixner return inb(0xc01) & 0xf;
893fb9aa6f1SThomas Gleixner }
894fb9aa6f1SThomas Gleixner
pirq_serverworks_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)895273c1127SMiklos Vajna static int pirq_serverworks_set(struct pci_dev *router, struct pci_dev *dev,
896273c1127SMiklos Vajna int pirq, int irq)
897fb9aa6f1SThomas Gleixner {
898c11b68bcSAlan Cox outb(pirq, 0xc00);
899c11b68bcSAlan Cox outb(irq, 0xc01);
900fb9aa6f1SThomas Gleixner return 1;
901fb9aa6f1SThomas Gleixner }
902fb9aa6f1SThomas Gleixner
903fb9aa6f1SThomas Gleixner /* Support for AMD756 PCI IRQ Routing
904fb9aa6f1SThomas Gleixner * Jhon H. Caicedo <jhcaiced@osso.org.co>
905fb9aa6f1SThomas Gleixner * Jun/21/2001 0.2.0 Release, fixed to use "nybble" functions... (jhcaiced)
906fb9aa6f1SThomas Gleixner * Jun/19/2001 Alpha Release 0.1.0 (jhcaiced)
907fb9aa6f1SThomas Gleixner * The AMD756 pirq rules are nibble-based
908fb9aa6f1SThomas Gleixner * offset 0x56 0-3 PIRQA 4-7 PIRQB
909fb9aa6f1SThomas Gleixner * offset 0x57 0-3 PIRQC 4-7 PIRQD
910fb9aa6f1SThomas Gleixner */
pirq_amd756_get(struct pci_dev * router,struct pci_dev * dev,int pirq)911fb9aa6f1SThomas Gleixner static int pirq_amd756_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
912fb9aa6f1SThomas Gleixner {
913fb9aa6f1SThomas Gleixner u8 irq;
914fb9aa6f1SThomas Gleixner irq = 0;
915fb9aa6f1SThomas Gleixner if (pirq <= 4)
916fb9aa6f1SThomas Gleixner irq = read_config_nybble(router, 0x56, pirq - 1);
91712c0b20fSBjorn Helgaas dev_info(&dev->dev,
918d768cb69SBjorn Helgaas "AMD756: dev [%04x:%04x], router PIRQ %d get IRQ %d\n",
919fb9aa6f1SThomas Gleixner dev->vendor, dev->device, pirq, irq);
920fb9aa6f1SThomas Gleixner return irq;
921fb9aa6f1SThomas Gleixner }
922fb9aa6f1SThomas Gleixner
pirq_amd756_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)923fb9aa6f1SThomas Gleixner static int pirq_amd756_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
924fb9aa6f1SThomas Gleixner {
92512c0b20fSBjorn Helgaas dev_info(&dev->dev,
926d768cb69SBjorn Helgaas "AMD756: dev [%04x:%04x], router PIRQ %d set IRQ %d\n",
927fb9aa6f1SThomas Gleixner dev->vendor, dev->device, pirq, irq);
928fb9aa6f1SThomas Gleixner if (pirq <= 4)
929fb9aa6f1SThomas Gleixner write_config_nybble(router, 0x56, pirq - 1, irq);
930fb9aa6f1SThomas Gleixner return 1;
931fb9aa6f1SThomas Gleixner }
932fb9aa6f1SThomas Gleixner
933b205f6b2SThomas Backlund /*
934b205f6b2SThomas Backlund * PicoPower PT86C523
935b205f6b2SThomas Backlund */
pirq_pico_get(struct pci_dev * router,struct pci_dev * dev,int pirq)936b205f6b2SThomas Backlund static int pirq_pico_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
937b205f6b2SThomas Backlund {
938b205f6b2SThomas Backlund outb(0x10 + ((pirq - 1) >> 1), 0x24);
939b205f6b2SThomas Backlund return ((pirq - 1) & 1) ? (inb(0x26) >> 4) : (inb(0x26) & 0xf);
940b205f6b2SThomas Backlund }
941b205f6b2SThomas Backlund
pirq_pico_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)942b205f6b2SThomas Backlund static int pirq_pico_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
943b205f6b2SThomas Backlund int irq)
944b205f6b2SThomas Backlund {
945b205f6b2SThomas Backlund unsigned int x;
946b205f6b2SThomas Backlund outb(0x10 + ((pirq - 1) >> 1), 0x24);
947b205f6b2SThomas Backlund x = inb(0x26);
948b205f6b2SThomas Backlund x = ((pirq - 1) & 1) ? ((x & 0x0f) | (irq << 4)) : ((x & 0xf0) | (irq));
949b205f6b2SThomas Backlund outb(x, 0x26);
950b205f6b2SThomas Backlund return 1;
951b205f6b2SThomas Backlund }
952b205f6b2SThomas Backlund
953fb9aa6f1SThomas Gleixner #ifdef CONFIG_PCI_BIOS
954fb9aa6f1SThomas Gleixner
pirq_bios_set(struct pci_dev * router,struct pci_dev * dev,int pirq,int irq)955fb9aa6f1SThomas Gleixner static int pirq_bios_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
956fb9aa6f1SThomas Gleixner {
957fb9aa6f1SThomas Gleixner struct pci_dev *bridge;
958fb9aa6f1SThomas Gleixner int pin = pci_get_interrupt_pin(dev, &bridge);
959878f2e50SBjorn Helgaas return pcibios_set_irq_routing(bridge, pin - 1, irq);
960fb9aa6f1SThomas Gleixner }
961fb9aa6f1SThomas Gleixner
962fb9aa6f1SThomas Gleixner #endif
963fb9aa6f1SThomas Gleixner
intel_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)964fb9aa6f1SThomas Gleixner static __init int intel_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
965fb9aa6f1SThomas Gleixner {
966fb9aa6f1SThomas Gleixner static struct pci_device_id __initdata pirq_440gx[] = {
967fb9aa6f1SThomas Gleixner { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
968fb9aa6f1SThomas Gleixner { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
969fb9aa6f1SThomas Gleixner { },
970fb9aa6f1SThomas Gleixner };
971fb9aa6f1SThomas Gleixner
972fb9aa6f1SThomas Gleixner /* 440GX has a proprietary PIRQ router -- don't use it */
973fb9aa6f1SThomas Gleixner if (pci_dev_present(pirq_440gx))
974fb9aa6f1SThomas Gleixner return 0;
975fb9aa6f1SThomas Gleixner
9767058b061SPaolo Ciarrocchi switch (device) {
9776b79164fSMaciej W. Rozycki case PCI_DEVICE_ID_INTEL_82375:
9786b79164fSMaciej W. Rozycki r->name = "PCEB/ESC";
9796b79164fSMaciej W. Rozycki r->get = pirq_esc_get;
9806b79164fSMaciej W. Rozycki r->set = pirq_esc_set;
9816b79164fSMaciej W. Rozycki return 1;
982fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82371FB_0:
983fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82371SB_0:
984fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82371AB_0:
985fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82371MX:
986fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82443MX_0:
987fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801AA_0:
988fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801AB_0:
989fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801BA_0:
990fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801BA_10:
991fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801CA_0:
992fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801CA_12:
993fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801DB_0:
994fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801E_0:
995fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_82801EB_0:
996fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ESB_1:
997fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH6_0:
998fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH6_1:
999fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH7_0:
1000fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH7_1:
1001fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH7_30:
1002fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH7_31:
100357064d21SSeth Heasley case PCI_DEVICE_ID_INTEL_TGP_LPC:
1004fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ESB2_0:
1005fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH8_0:
1006fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH8_1:
1007fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH8_2:
1008fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH8_3:
1009fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH8_4:
1010fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH9_0:
1011fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH9_1:
1012fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH9_2:
1013fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH9_3:
1014fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH9_4:
1015fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_INTEL_ICH9_5:
1016cb04e95bSSeth Heasley case PCI_DEVICE_ID_INTEL_EP80579_0:
1017cc09c5bcSJason Gaston case PCI_DEVICE_ID_INTEL_ICH10_0:
1018cc09c5bcSJason Gaston case PCI_DEVICE_ID_INTEL_ICH10_1:
1019cc09c5bcSJason Gaston case PCI_DEVICE_ID_INTEL_ICH10_2:
1020cc09c5bcSJason Gaston case PCI_DEVICE_ID_INTEL_ICH10_3:
10219b444b36SSeth Heasley case PCI_DEVICE_ID_INTEL_PATSBURG_LPC_0:
10229b444b36SSeth Heasley case PCI_DEVICE_ID_INTEL_PATSBURG_LPC_1:
1023fb9aa6f1SThomas Gleixner r->name = "PIIX/ICH";
1024fb9aa6f1SThomas Gleixner r->get = pirq_piix_get;
1025fb9aa6f1SThomas Gleixner r->set = pirq_piix_set;
1026fb9aa6f1SThomas Gleixner return 1;
10270e8c6f56SMaciej W. Rozycki case PCI_DEVICE_ID_INTEL_82425:
10280e8c6f56SMaciej W. Rozycki r->name = "PSC/IB";
10290e8c6f56SMaciej W. Rozycki r->get = pirq_ib_get;
10300e8c6f56SMaciej W. Rozycki r->set = pirq_ib_set;
10310e8c6f56SMaciej W. Rozycki return 1;
1032fb9aa6f1SThomas Gleixner }
103337a84ec6SSeth Heasley
1034c13ff2ffSSeth Heasley if ((device >= PCI_DEVICE_ID_INTEL_5_3400_SERIES_LPC_MIN &&
1035c13ff2ffSSeth Heasley device <= PCI_DEVICE_ID_INTEL_5_3400_SERIES_LPC_MAX)
1036c13ff2ffSSeth Heasley || (device >= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MIN &&
1037c13ff2ffSSeth Heasley device <= PCI_DEVICE_ID_INTEL_COUGARPOINT_LPC_MAX)
1038c13ff2ffSSeth Heasley || (device >= PCI_DEVICE_ID_INTEL_DH89XXCC_LPC_MIN &&
1039c0a86a9bSSeth Heasley device <= PCI_DEVICE_ID_INTEL_DH89XXCC_LPC_MAX)
1040c0a86a9bSSeth Heasley || (device >= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MIN &&
1041c0a86a9bSSeth Heasley device <= PCI_DEVICE_ID_INTEL_PANTHERPOINT_LPC_MAX)) {
104237a84ec6SSeth Heasley r->name = "PIIX/ICH";
104337a84ec6SSeth Heasley r->get = pirq_piix_get;
104437a84ec6SSeth Heasley r->set = pirq_piix_set;
104537a84ec6SSeth Heasley return 1;
104637a84ec6SSeth Heasley }
104737a84ec6SSeth Heasley
1048fb9aa6f1SThomas Gleixner return 0;
1049fb9aa6f1SThomas Gleixner }
1050fb9aa6f1SThomas Gleixner
via_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1051fb9aa6f1SThomas Gleixner static __init int via_router_probe(struct irq_router *r,
1052fb9aa6f1SThomas Gleixner struct pci_dev *router, u16 device)
1053fb9aa6f1SThomas Gleixner {
1054fb9aa6f1SThomas Gleixner /* FIXME: We should move some of the quirk fixup stuff here */
1055fb9aa6f1SThomas Gleixner
1056fb9aa6f1SThomas Gleixner /*
1057fb9aa6f1SThomas Gleixner * workarounds for some buggy BIOSes
1058fb9aa6f1SThomas Gleixner */
1059fb9aa6f1SThomas Gleixner if (device == PCI_DEVICE_ID_VIA_82C586_0) {
1060fb9aa6f1SThomas Gleixner switch (router->device) {
1061fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_82C686:
1062fb9aa6f1SThomas Gleixner /*
1063fb9aa6f1SThomas Gleixner * Asus k7m bios wrongly reports 82C686A
1064fb9aa6f1SThomas Gleixner * as 586-compatible
1065fb9aa6f1SThomas Gleixner */
1066fb9aa6f1SThomas Gleixner device = PCI_DEVICE_ID_VIA_82C686;
1067fb9aa6f1SThomas Gleixner break;
1068fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_8235:
1069fb9aa6f1SThomas Gleixner /**
1070fb9aa6f1SThomas Gleixner * Asus a7v-x bios wrongly reports 8235
1071fb9aa6f1SThomas Gleixner * as 586-compatible
1072fb9aa6f1SThomas Gleixner */
1073fb9aa6f1SThomas Gleixner device = PCI_DEVICE_ID_VIA_8235;
1074fb9aa6f1SThomas Gleixner break;
10759f67fd5dSBertram Felgenhauer case PCI_DEVICE_ID_VIA_8237:
10769f67fd5dSBertram Felgenhauer /**
10779f67fd5dSBertram Felgenhauer * Asus a7v600 bios wrongly reports 8237
10789f67fd5dSBertram Felgenhauer * as 586-compatible
10799f67fd5dSBertram Felgenhauer */
10809f67fd5dSBertram Felgenhauer device = PCI_DEVICE_ID_VIA_8237;
10819f67fd5dSBertram Felgenhauer break;
1082fb9aa6f1SThomas Gleixner }
1083fb9aa6f1SThomas Gleixner }
1084fb9aa6f1SThomas Gleixner
1085fb9aa6f1SThomas Gleixner switch (device) {
1086fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_82C586_0:
1087fb9aa6f1SThomas Gleixner r->name = "VIA";
1088fb9aa6f1SThomas Gleixner r->get = pirq_via586_get;
1089fb9aa6f1SThomas Gleixner r->set = pirq_via586_set;
1090fb9aa6f1SThomas Gleixner return 1;
1091fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_82C596:
1092fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_82C686:
1093fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_8231:
1094fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_8233A:
1095fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_8235:
1096fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VIA_8237:
1097fb9aa6f1SThomas Gleixner /* FIXME: add new ones for 8233/5 */
1098fb9aa6f1SThomas Gleixner r->name = "VIA";
1099fb9aa6f1SThomas Gleixner r->get = pirq_via_get;
1100fb9aa6f1SThomas Gleixner r->set = pirq_via_set;
1101fb9aa6f1SThomas Gleixner return 1;
1102fb9aa6f1SThomas Gleixner }
1103fb9aa6f1SThomas Gleixner return 0;
1104fb9aa6f1SThomas Gleixner }
1105fb9aa6f1SThomas Gleixner
vlsi_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1106fb9aa6f1SThomas Gleixner static __init int vlsi_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1107fb9aa6f1SThomas Gleixner {
11087058b061SPaolo Ciarrocchi switch (device) {
1109fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_VLSI_82C534:
1110fb9aa6f1SThomas Gleixner r->name = "VLSI 82C534";
1111fb9aa6f1SThomas Gleixner r->get = pirq_vlsi_get;
1112fb9aa6f1SThomas Gleixner r->set = pirq_vlsi_set;
1113fb9aa6f1SThomas Gleixner return 1;
1114fb9aa6f1SThomas Gleixner }
1115fb9aa6f1SThomas Gleixner return 0;
1116fb9aa6f1SThomas Gleixner }
1117fb9aa6f1SThomas Gleixner
1118fb9aa6f1SThomas Gleixner
serverworks_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1119273c1127SMiklos Vajna static __init int serverworks_router_probe(struct irq_router *r,
1120273c1127SMiklos Vajna struct pci_dev *router, u16 device)
1121fb9aa6f1SThomas Gleixner {
11227058b061SPaolo Ciarrocchi switch (device) {
1123fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_SERVERWORKS_OSB4:
1124fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_SERVERWORKS_CSB5:
1125fb9aa6f1SThomas Gleixner r->name = "ServerWorks";
1126fb9aa6f1SThomas Gleixner r->get = pirq_serverworks_get;
1127fb9aa6f1SThomas Gleixner r->set = pirq_serverworks_set;
1128fb9aa6f1SThomas Gleixner return 1;
1129fb9aa6f1SThomas Gleixner }
1130fb9aa6f1SThomas Gleixner return 0;
1131fb9aa6f1SThomas Gleixner }
1132fb9aa6f1SThomas Gleixner
sis_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1133fb9aa6f1SThomas Gleixner static __init int sis_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1134fb9aa6f1SThomas Gleixner {
11355a0e5fa9SMaciej W. Rozycki switch (device) {
1136fe62bc23SMaciej W. Rozycki case PCI_DEVICE_ID_SI_496:
1137fe62bc23SMaciej W. Rozycki r->name = "SiS85C497";
1138fe62bc23SMaciej W. Rozycki r->get = pirq_sis497_get;
1139fe62bc23SMaciej W. Rozycki r->set = pirq_sis497_set;
1140fe62bc23SMaciej W. Rozycki return 1;
11415a0e5fa9SMaciej W. Rozycki case PCI_DEVICE_ID_SI_503:
11425a0e5fa9SMaciej W. Rozycki r->name = "SiS85C503";
11435a0e5fa9SMaciej W. Rozycki r->get = pirq_sis503_get;
11445a0e5fa9SMaciej W. Rozycki r->set = pirq_sis503_set;
1145fb9aa6f1SThomas Gleixner return 1;
1146fb9aa6f1SThomas Gleixner }
11475a0e5fa9SMaciej W. Rozycki return 0;
11485a0e5fa9SMaciej W. Rozycki }
1149fb9aa6f1SThomas Gleixner
cyrix_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1150fb9aa6f1SThomas Gleixner static __init int cyrix_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1151fb9aa6f1SThomas Gleixner {
11527058b061SPaolo Ciarrocchi switch (device) {
1153fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_CYRIX_5520:
1154fb9aa6f1SThomas Gleixner r->name = "NatSemi";
1155fb9aa6f1SThomas Gleixner r->get = pirq_cyrix_get;
1156fb9aa6f1SThomas Gleixner r->set = pirq_cyrix_set;
1157fb9aa6f1SThomas Gleixner return 1;
1158fb9aa6f1SThomas Gleixner }
1159fb9aa6f1SThomas Gleixner return 0;
1160fb9aa6f1SThomas Gleixner }
1161fb9aa6f1SThomas Gleixner
opti_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1162fb9aa6f1SThomas Gleixner static __init int opti_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1163fb9aa6f1SThomas Gleixner {
11647058b061SPaolo Ciarrocchi switch (device) {
1165fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_OPTI_82C700:
1166fb9aa6f1SThomas Gleixner r->name = "OPTI";
1167fb9aa6f1SThomas Gleixner r->get = pirq_opti_get;
1168fb9aa6f1SThomas Gleixner r->set = pirq_opti_set;
1169fb9aa6f1SThomas Gleixner return 1;
1170fb9aa6f1SThomas Gleixner }
1171fb9aa6f1SThomas Gleixner return 0;
1172fb9aa6f1SThomas Gleixner }
1173fb9aa6f1SThomas Gleixner
ite_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1174fb9aa6f1SThomas Gleixner static __init int ite_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1175fb9aa6f1SThomas Gleixner {
11767058b061SPaolo Ciarrocchi switch (device) {
1177fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_ITE_IT8330G_0:
1178fb9aa6f1SThomas Gleixner r->name = "ITE";
1179fb9aa6f1SThomas Gleixner r->get = pirq_ite_get;
1180fb9aa6f1SThomas Gleixner r->set = pirq_ite_set;
1181fb9aa6f1SThomas Gleixner return 1;
1182fb9aa6f1SThomas Gleixner }
1183fb9aa6f1SThomas Gleixner return 0;
1184fb9aa6f1SThomas Gleixner }
1185fb9aa6f1SThomas Gleixner
ali_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1186fb9aa6f1SThomas Gleixner static __init int ali_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1187fb9aa6f1SThomas Gleixner {
11887058b061SPaolo Ciarrocchi switch (device) {
11891ce849c7SMaciej W. Rozycki case PCI_DEVICE_ID_AL_M1489:
11901ce849c7SMaciej W. Rozycki r->name = "FinALi";
11911ce849c7SMaciej W. Rozycki r->get = pirq_finali_get;
11921ce849c7SMaciej W. Rozycki r->set = pirq_finali_set;
11931ce849c7SMaciej W. Rozycki r->lvl = pirq_finali_lvl;
11941ce849c7SMaciej W. Rozycki return 1;
1195fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_AL_M1533:
1196fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_AL_M1563:
1197fb9aa6f1SThomas Gleixner r->name = "ALI";
1198fb9aa6f1SThomas Gleixner r->get = pirq_ali_get;
1199fb9aa6f1SThomas Gleixner r->set = pirq_ali_set;
1200fb9aa6f1SThomas Gleixner return 1;
1201fb9aa6f1SThomas Gleixner }
1202fb9aa6f1SThomas Gleixner return 0;
1203fb9aa6f1SThomas Gleixner }
1204fb9aa6f1SThomas Gleixner
amd_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1205fb9aa6f1SThomas Gleixner static __init int amd_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1206fb9aa6f1SThomas Gleixner {
12077058b061SPaolo Ciarrocchi switch (device) {
1208fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_AMD_VIPER_740B:
1209fb9aa6f1SThomas Gleixner r->name = "AMD756";
1210fb9aa6f1SThomas Gleixner break;
1211fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_AMD_VIPER_7413:
1212fb9aa6f1SThomas Gleixner r->name = "AMD766";
1213fb9aa6f1SThomas Gleixner break;
1214fb9aa6f1SThomas Gleixner case PCI_DEVICE_ID_AMD_VIPER_7443:
1215fb9aa6f1SThomas Gleixner r->name = "AMD768";
1216fb9aa6f1SThomas Gleixner break;
1217fb9aa6f1SThomas Gleixner default:
1218fb9aa6f1SThomas Gleixner return 0;
1219fb9aa6f1SThomas Gleixner }
1220fb9aa6f1SThomas Gleixner r->get = pirq_amd756_get;
1221fb9aa6f1SThomas Gleixner r->set = pirq_amd756_set;
1222fb9aa6f1SThomas Gleixner return 1;
1223fb9aa6f1SThomas Gleixner }
1224fb9aa6f1SThomas Gleixner
pico_router_probe(struct irq_router * r,struct pci_dev * router,u16 device)1225b205f6b2SThomas Backlund static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
1226b205f6b2SThomas Backlund {
1227b205f6b2SThomas Backlund switch (device) {
1228b205f6b2SThomas Backlund case PCI_DEVICE_ID_PICOPOWER_PT86C523:
1229b205f6b2SThomas Backlund r->name = "PicoPower PT86C523";
1230b205f6b2SThomas Backlund r->get = pirq_pico_get;
1231b205f6b2SThomas Backlund r->set = pirq_pico_set;
1232b205f6b2SThomas Backlund return 1;
1233b205f6b2SThomas Backlund
1234b205f6b2SThomas Backlund case PCI_DEVICE_ID_PICOPOWER_PT86C523BBP:
1235b205f6b2SThomas Backlund r->name = "PicoPower PT86C523 rev. BB+";
1236b205f6b2SThomas Backlund r->get = pirq_pico_get;
1237b205f6b2SThomas Backlund r->set = pirq_pico_set;
1238b205f6b2SThomas Backlund return 1;
1239b205f6b2SThomas Backlund }
1240b205f6b2SThomas Backlund return 0;
1241b205f6b2SThomas Backlund }
1242b205f6b2SThomas Backlund
1243fb9aa6f1SThomas Gleixner static __initdata struct irq_router_handler pirq_routers[] = {
1244fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_INTEL, intel_router_probe },
1245fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_AL, ali_router_probe },
1246fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_ITE, ite_router_probe },
1247fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_VIA, via_router_probe },
1248fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_OPTI, opti_router_probe },
1249fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_SI, sis_router_probe },
1250fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_CYRIX, cyrix_router_probe },
1251fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_VLSI, vlsi_router_probe },
1252fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_SERVERWORKS, serverworks_router_probe },
1253fb9aa6f1SThomas Gleixner { PCI_VENDOR_ID_AMD, amd_router_probe },
1254b205f6b2SThomas Backlund { PCI_VENDOR_ID_PICOPOWER, pico_router_probe },
1255fb9aa6f1SThomas Gleixner /* Someone with docs needs to add the ATI Radeon IGP */
1256fb9aa6f1SThomas Gleixner { 0, NULL }
1257fb9aa6f1SThomas Gleixner };
1258fb9aa6f1SThomas Gleixner static struct irq_router pirq_router;
1259fb9aa6f1SThomas Gleixner static struct pci_dev *pirq_router_dev;
1260fb9aa6f1SThomas Gleixner
1261fb9aa6f1SThomas Gleixner
1262fb9aa6f1SThomas Gleixner /*
1263fb9aa6f1SThomas Gleixner * FIXME: should we have an option to say "generic for
1264fb9aa6f1SThomas Gleixner * chipset" ?
1265fb9aa6f1SThomas Gleixner */
1266fb9aa6f1SThomas Gleixner
pirq_try_router(struct irq_router * r,struct irq_routing_table * rt,struct pci_dev * dev)1267ac7cd5e1SMaciej W. Rozycki static bool __init pirq_try_router(struct irq_router *r,
1268ac7cd5e1SMaciej W. Rozycki struct irq_routing_table *rt,
1269ac7cd5e1SMaciej W. Rozycki struct pci_dev *dev)
1270ac7cd5e1SMaciej W. Rozycki {
1271ac7cd5e1SMaciej W. Rozycki struct irq_router_handler *h;
1272ac7cd5e1SMaciej W. Rozycki
1273ac7cd5e1SMaciej W. Rozycki DBG(KERN_DEBUG "PCI: Trying IRQ router for [%04x:%04x]\n",
1274ac7cd5e1SMaciej W. Rozycki dev->vendor, dev->device);
1275ac7cd5e1SMaciej W. Rozycki
1276ac7cd5e1SMaciej W. Rozycki for (h = pirq_routers; h->vendor; h++) {
1277ac7cd5e1SMaciej W. Rozycki /* First look for a router match */
1278ac7cd5e1SMaciej W. Rozycki if (rt->rtr_vendor == h->vendor &&
1279ac7cd5e1SMaciej W. Rozycki h->probe(r, dev, rt->rtr_device))
1280ac7cd5e1SMaciej W. Rozycki return true;
1281ac7cd5e1SMaciej W. Rozycki /* Fall back to a device match */
1282ac7cd5e1SMaciej W. Rozycki if (dev->vendor == h->vendor &&
1283ac7cd5e1SMaciej W. Rozycki h->probe(r, dev, dev->device))
1284ac7cd5e1SMaciej W. Rozycki return true;
1285ac7cd5e1SMaciej W. Rozycki }
1286ac7cd5e1SMaciej W. Rozycki return false;
1287ac7cd5e1SMaciej W. Rozycki }
1288ac7cd5e1SMaciej W. Rozycki
pirq_find_router(struct irq_router * r)1289fb9aa6f1SThomas Gleixner static void __init pirq_find_router(struct irq_router *r)
1290fb9aa6f1SThomas Gleixner {
1291fb9aa6f1SThomas Gleixner struct irq_routing_table *rt = pirq_table;
1292ac7cd5e1SMaciej W. Rozycki struct pci_dev *dev;
1293fb9aa6f1SThomas Gleixner
1294fb9aa6f1SThomas Gleixner #ifdef CONFIG_PCI_BIOS
1295fb9aa6f1SThomas Gleixner if (!rt->signature) {
1296fb9aa6f1SThomas Gleixner printk(KERN_INFO "PCI: Using BIOS for IRQ routing\n");
1297fb9aa6f1SThomas Gleixner r->set = pirq_bios_set;
1298fb9aa6f1SThomas Gleixner r->name = "BIOS";
1299fb9aa6f1SThomas Gleixner return;
1300fb9aa6f1SThomas Gleixner }
1301fb9aa6f1SThomas Gleixner #endif
1302fb9aa6f1SThomas Gleixner
1303fb9aa6f1SThomas Gleixner /* Default unless a driver reloads it */
1304fb9aa6f1SThomas Gleixner r->name = "default";
1305fb9aa6f1SThomas Gleixner r->get = NULL;
1306fb9aa6f1SThomas Gleixner r->set = NULL;
1307fb9aa6f1SThomas Gleixner
1308d768cb69SBjorn Helgaas DBG(KERN_DEBUG "PCI: Attempting to find IRQ router for [%04x:%04x]\n",
1309fb9aa6f1SThomas Gleixner rt->rtr_vendor, rt->rtr_device);
1310fb9aa6f1SThomas Gleixner
1311ac7cd5e1SMaciej W. Rozycki /* Use any vendor:device provided by the routing table or try all. */
1312ac7cd5e1SMaciej W. Rozycki if (rt->rtr_vendor) {
1313ac7cd5e1SMaciej W. Rozycki dev = pci_get_domain_bus_and_slot(0, rt->rtr_bus,
1314d4b31503SSinan Kaya rt->rtr_devfn);
1315ac7cd5e1SMaciej W. Rozycki if (dev && pirq_try_router(r, rt, dev))
1316ac7cd5e1SMaciej W. Rozycki pirq_router_dev = dev;
1317ac7cd5e1SMaciej W. Rozycki } else {
1318ac7cd5e1SMaciej W. Rozycki dev = NULL;
1319ac7cd5e1SMaciej W. Rozycki for_each_pci_dev(dev) {
1320ac7cd5e1SMaciej W. Rozycki if (pirq_try_router(r, rt, dev)) {
1321ac7cd5e1SMaciej W. Rozycki pirq_router_dev = dev;
1322ac7cd5e1SMaciej W. Rozycki break;
1323ac7cd5e1SMaciej W. Rozycki }
1324ac7cd5e1SMaciej W. Rozycki }
1325fb9aa6f1SThomas Gleixner }
1326fb9aa6f1SThomas Gleixner
1327ac7cd5e1SMaciej W. Rozycki if (pirq_router_dev)
1328d768cb69SBjorn Helgaas dev_info(&pirq_router_dev->dev, "%s IRQ router [%04x:%04x]\n",
1329fb9aa6f1SThomas Gleixner pirq_router.name,
133012c0b20fSBjorn Helgaas pirq_router_dev->vendor, pirq_router_dev->device);
1331ac7cd5e1SMaciej W. Rozycki else
1332ac7cd5e1SMaciej W. Rozycki DBG(KERN_DEBUG "PCI: Interrupt router not found at "
1333ac7cd5e1SMaciej W. Rozycki "%02x:%02x\n", rt->rtr_bus, rt->rtr_devfn);
1334fb9aa6f1SThomas Gleixner
1335fb9aa6f1SThomas Gleixner /* The device remains referenced for the kernel lifetime */
1336fb9aa6f1SThomas Gleixner }
1337fb9aa6f1SThomas Gleixner
133831324502SMaciej W. Rozycki /*
133931324502SMaciej W. Rozycki * We're supposed to match on the PCI device only and not the function,
134031324502SMaciej W. Rozycki * but some BIOSes build their tables with the PCI function included
134131324502SMaciej W. Rozycki * for motherboard devices, so if a complete match is found, then give
134231324502SMaciej W. Rozycki * it precedence over a slot match.
134331324502SMaciej W. Rozycki */
pirq_get_dev_info(struct pci_dev * dev)1344d88a8b1cSMaciej W. Rozycki static struct irq_info *pirq_get_dev_info(struct pci_dev *dev)
1345fb9aa6f1SThomas Gleixner {
1346fb9aa6f1SThomas Gleixner struct irq_routing_table *rt = pirq_table;
1347273c1127SMiklos Vajna int entries = (rt->size - sizeof(struct irq_routing_table)) /
1348273c1127SMiklos Vajna sizeof(struct irq_info);
134931324502SMaciej W. Rozycki struct irq_info *slotinfo = NULL;
1350fb9aa6f1SThomas Gleixner struct irq_info *info;
1351fb9aa6f1SThomas Gleixner
1352fb9aa6f1SThomas Gleixner for (info = rt->slots; entries--; info++)
135331324502SMaciej W. Rozycki if (info->bus == dev->bus->number) {
135431324502SMaciej W. Rozycki if (info->devfn == dev->devfn)
1355fb9aa6f1SThomas Gleixner return info;
135631324502SMaciej W. Rozycki if (!slotinfo &&
135731324502SMaciej W. Rozycki PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn))
135831324502SMaciej W. Rozycki slotinfo = info;
135931324502SMaciej W. Rozycki }
136031324502SMaciej W. Rozycki return slotinfo;
1361fb9aa6f1SThomas Gleixner }
1362fb9aa6f1SThomas Gleixner
1363d88a8b1cSMaciej W. Rozycki /*
1364d88a8b1cSMaciej W. Rozycki * Buses behind bridges are typically not listed in the PIRQ routing table.
1365d88a8b1cSMaciej W. Rozycki * Do the usual dance then and walk the tree of bridges up adjusting the
1366d88a8b1cSMaciej W. Rozycki * pin number accordingly on the way until the originating root bus device
1367d88a8b1cSMaciej W. Rozycki * has been reached and then use its routing information.
1368d88a8b1cSMaciej W. Rozycki */
pirq_get_info(struct pci_dev * dev,u8 * pin)1369d88a8b1cSMaciej W. Rozycki static struct irq_info *pirq_get_info(struct pci_dev *dev, u8 *pin)
1370d88a8b1cSMaciej W. Rozycki {
1371d88a8b1cSMaciej W. Rozycki struct pci_dev *temp_dev = dev;
1372d88a8b1cSMaciej W. Rozycki struct irq_info *info;
1373d88a8b1cSMaciej W. Rozycki u8 temp_pin = *pin;
1374d88a8b1cSMaciej W. Rozycki u8 dpin = temp_pin;
1375d88a8b1cSMaciej W. Rozycki
1376d88a8b1cSMaciej W. Rozycki info = pirq_get_dev_info(dev);
1377d88a8b1cSMaciej W. Rozycki while (!info && temp_dev->bus->parent) {
1378d88a8b1cSMaciej W. Rozycki struct pci_dev *bridge = temp_dev->bus->self;
1379d88a8b1cSMaciej W. Rozycki
1380d88a8b1cSMaciej W. Rozycki temp_pin = pci_swizzle_interrupt_pin(temp_dev, temp_pin);
1381d88a8b1cSMaciej W. Rozycki info = pirq_get_dev_info(bridge);
1382d88a8b1cSMaciej W. Rozycki if (info)
1383d88a8b1cSMaciej W. Rozycki dev_warn(&dev->dev,
1384d88a8b1cSMaciej W. Rozycki "using bridge %s INT %c to get INT %c\n",
1385d88a8b1cSMaciej W. Rozycki pci_name(bridge),
1386d88a8b1cSMaciej W. Rozycki 'A' + temp_pin - 1, 'A' + dpin - 1);
1387d88a8b1cSMaciej W. Rozycki
1388d88a8b1cSMaciej W. Rozycki temp_dev = bridge;
1389d88a8b1cSMaciej W. Rozycki }
1390d88a8b1cSMaciej W. Rozycki *pin = temp_pin;
1391d88a8b1cSMaciej W. Rozycki return info;
1392d88a8b1cSMaciej W. Rozycki }
1393d88a8b1cSMaciej W. Rozycki
pcibios_lookup_irq(struct pci_dev * dev,int assign)1394fb9aa6f1SThomas Gleixner static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
1395fb9aa6f1SThomas Gleixner {
1396fb9aa6f1SThomas Gleixner struct irq_info *info;
1397fb9aa6f1SThomas Gleixner int i, pirq, newirq;
1398d88a8b1cSMaciej W. Rozycki u8 dpin, pin;
1399fb9aa6f1SThomas Gleixner int irq = 0;
1400fb9aa6f1SThomas Gleixner u32 mask;
1401fb9aa6f1SThomas Gleixner struct irq_router *r = &pirq_router;
1402fb9aa6f1SThomas Gleixner struct pci_dev *dev2 = NULL;
1403fb9aa6f1SThomas Gleixner char *msg = NULL;
1404fb9aa6f1SThomas Gleixner
1405fb9aa6f1SThomas Gleixner /* Find IRQ pin */
1406d88a8b1cSMaciej W. Rozycki pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &dpin);
1407d88a8b1cSMaciej W. Rozycki if (!dpin) {
140812c0b20fSBjorn Helgaas dev_dbg(&dev->dev, "no interrupt pin\n");
1409fb9aa6f1SThomas Gleixner return 0;
1410fb9aa6f1SThomas Gleixner }
1411fb9aa6f1SThomas Gleixner
1412b9c61b70SYinghai Lu if (io_apic_assign_pci_irqs)
1413b9c61b70SYinghai Lu return 0;
1414b9c61b70SYinghai Lu
1415fb9aa6f1SThomas Gleixner /* Find IRQ routing entry */
1416fb9aa6f1SThomas Gleixner
1417fb9aa6f1SThomas Gleixner if (!pirq_table)
1418fb9aa6f1SThomas Gleixner return 0;
1419fb9aa6f1SThomas Gleixner
1420d88a8b1cSMaciej W. Rozycki pin = dpin;
1421d88a8b1cSMaciej W. Rozycki info = pirq_get_info(dev, &pin);
1422fb9aa6f1SThomas Gleixner if (!info) {
142312c0b20fSBjorn Helgaas dev_dbg(&dev->dev, "PCI INT %c not found in routing table\n",
1424d88a8b1cSMaciej W. Rozycki 'A' + dpin - 1);
1425fb9aa6f1SThomas Gleixner return 0;
1426fb9aa6f1SThomas Gleixner }
1427f672c392SBjorn Helgaas pirq = info->irq[pin - 1].link;
1428f672c392SBjorn Helgaas mask = info->irq[pin - 1].bitmap;
1429fb9aa6f1SThomas Gleixner if (!pirq) {
1430d88a8b1cSMaciej W. Rozycki dev_dbg(&dev->dev, "PCI INT %c not routed\n", 'A' + dpin - 1);
1431fb9aa6f1SThomas Gleixner return 0;
1432fb9aa6f1SThomas Gleixner }
143312c0b20fSBjorn Helgaas dev_dbg(&dev->dev, "PCI INT %c -> PIRQ %02x, mask %04x, excl %04x",
1434d88a8b1cSMaciej W. Rozycki 'A' + dpin - 1, pirq, mask, pirq_table->exclusive_irqs);
1435fb9aa6f1SThomas Gleixner mask &= pcibios_irq_mask;
1436fb9aa6f1SThomas Gleixner
1437fb9aa6f1SThomas Gleixner /* Work around broken HP Pavilion Notebooks which assign USB to
1438fb9aa6f1SThomas Gleixner IRQ 9 even though it is actually wired to IRQ 11 */
1439fb9aa6f1SThomas Gleixner
1440fb9aa6f1SThomas Gleixner if (broken_hp_bios_irq9 && pirq == 0x59 && dev->irq == 9) {
1441fb9aa6f1SThomas Gleixner dev->irq = 11;
1442fb9aa6f1SThomas Gleixner pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
1443fb9aa6f1SThomas Gleixner r->set(pirq_router_dev, dev, pirq, 11);
1444fb9aa6f1SThomas Gleixner }
1445fb9aa6f1SThomas Gleixner
1446fb9aa6f1SThomas Gleixner /* same for Acer Travelmate 360, but with CB and irq 11 -> 10 */
1447273c1127SMiklos Vajna if (acer_tm360_irqrouting && dev->irq == 11 &&
1448273c1127SMiklos Vajna dev->vendor == PCI_VENDOR_ID_O2) {
1449fb9aa6f1SThomas Gleixner pirq = 0x68;
1450fb9aa6f1SThomas Gleixner mask = 0x400;
1451fb9aa6f1SThomas Gleixner dev->irq = r->get(pirq_router_dev, dev, pirq);
1452fb9aa6f1SThomas Gleixner pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
1453fb9aa6f1SThomas Gleixner }
1454fb9aa6f1SThomas Gleixner
1455fb9aa6f1SThomas Gleixner /*
1456fb9aa6f1SThomas Gleixner * Find the best IRQ to assign: use the one
1457fb9aa6f1SThomas Gleixner * reported by the device if possible.
1458fb9aa6f1SThomas Gleixner */
1459fb9aa6f1SThomas Gleixner newirq = dev->irq;
1460fb9aa6f1SThomas Gleixner if (newirq && !((1 << newirq) & mask)) {
14617058b061SPaolo Ciarrocchi if (pci_probe & PCI_USE_PIRQ_MASK)
14627058b061SPaolo Ciarrocchi newirq = 0;
14637058b061SPaolo Ciarrocchi else
146412c0b20fSBjorn Helgaas dev_warn(&dev->dev, "IRQ %d doesn't match PIRQ mask "
146512c0b20fSBjorn Helgaas "%#x; try pci=usepirqmask\n", newirq, mask);
1466fb9aa6f1SThomas Gleixner }
1467fb9aa6f1SThomas Gleixner if (!newirq && assign) {
1468fb9aa6f1SThomas Gleixner for (i = 0; i < 16; i++) {
1469fb9aa6f1SThomas Gleixner if (!(mask & (1 << i)))
1470fb9aa6f1SThomas Gleixner continue;
1471273c1127SMiklos Vajna if (pirq_penalty[i] < pirq_penalty[newirq] &&
1472273c1127SMiklos Vajna can_request_irq(i, IRQF_SHARED))
1473fb9aa6f1SThomas Gleixner newirq = i;
1474fb9aa6f1SThomas Gleixner }
1475fb9aa6f1SThomas Gleixner }
1476d88a8b1cSMaciej W. Rozycki dev_dbg(&dev->dev, "PCI INT %c -> newirq %d", 'A' + dpin - 1, newirq);
1477fb9aa6f1SThomas Gleixner
1478fb9aa6f1SThomas Gleixner /* Check if it is hardcoded */
1479fb9aa6f1SThomas Gleixner if ((pirq & 0xf0) == 0xf0) {
1480fb9aa6f1SThomas Gleixner irq = pirq & 0xf;
148112c0b20fSBjorn Helgaas msg = "hardcoded";
1482fb9aa6f1SThomas Gleixner } else if (r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
1483fb9aa6f1SThomas Gleixner ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask))) {
148412c0b20fSBjorn Helgaas msg = "found";
14851ce849c7SMaciej W. Rozycki if (r->lvl)
14861ce849c7SMaciej W. Rozycki r->lvl(pirq_router_dev, dev, pirq, irq);
14871ce849c7SMaciej W. Rozycki else
1488ea6cd250SPaul Gortmaker elcr_set_level_irq(irq);
1489273c1127SMiklos Vajna } else if (newirq && r->set &&
1490273c1127SMiklos Vajna (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) {
1491fb9aa6f1SThomas Gleixner if (r->set(pirq_router_dev, dev, pirq, newirq)) {
14921ce849c7SMaciej W. Rozycki if (r->lvl)
14931ce849c7SMaciej W. Rozycki r->lvl(pirq_router_dev, dev, pirq, newirq);
14941ce849c7SMaciej W. Rozycki else
1495ea6cd250SPaul Gortmaker elcr_set_level_irq(newirq);
149612c0b20fSBjorn Helgaas msg = "assigned";
1497fb9aa6f1SThomas Gleixner irq = newirq;
1498fb9aa6f1SThomas Gleixner }
1499fb9aa6f1SThomas Gleixner }
1500fb9aa6f1SThomas Gleixner
1501fb9aa6f1SThomas Gleixner if (!irq) {
1502fb9aa6f1SThomas Gleixner if (newirq && mask == (1 << newirq)) {
150312c0b20fSBjorn Helgaas msg = "guessed";
1504fb9aa6f1SThomas Gleixner irq = newirq;
150512c0b20fSBjorn Helgaas } else {
150612c0b20fSBjorn Helgaas dev_dbg(&dev->dev, "can't route interrupt\n");
1507fb9aa6f1SThomas Gleixner return 0;
1508fb9aa6f1SThomas Gleixner }
150912c0b20fSBjorn Helgaas }
1510d88a8b1cSMaciej W. Rozycki dev_info(&dev->dev, "%s PCI INT %c -> IRQ %d\n",
1511d88a8b1cSMaciej W. Rozycki msg, 'A' + dpin - 1, irq);
1512fb9aa6f1SThomas Gleixner
1513fb9aa6f1SThomas Gleixner /* Update IRQ for all devices with the same pirq value */
15141f7979acSKulikov Vasiliy for_each_pci_dev(dev2) {
1515d88a8b1cSMaciej W. Rozycki pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &dpin);
1516d88a8b1cSMaciej W. Rozycki if (!dpin)
1517fb9aa6f1SThomas Gleixner continue;
1518f672c392SBjorn Helgaas
1519d88a8b1cSMaciej W. Rozycki pin = dpin;
1520d88a8b1cSMaciej W. Rozycki info = pirq_get_info(dev2, &pin);
1521fb9aa6f1SThomas Gleixner if (!info)
1522fb9aa6f1SThomas Gleixner continue;
1523f672c392SBjorn Helgaas if (info->irq[pin - 1].link == pirq) {
1524273c1127SMiklos Vajna /*
1525273c1127SMiklos Vajna * We refuse to override the dev->irq
1526273c1127SMiklos Vajna * information. Give a warning!
1527273c1127SMiklos Vajna */
1528fb9aa6f1SThomas Gleixner if (dev2->irq && dev2->irq != irq && \
1529fb9aa6f1SThomas Gleixner (!(pci_probe & PCI_USE_PIRQ_MASK) || \
1530fb9aa6f1SThomas Gleixner ((1 << dev2->irq) & mask))) {
1531fb9aa6f1SThomas Gleixner #ifndef CONFIG_PCI_MSI
153212c0b20fSBjorn Helgaas dev_info(&dev2->dev, "IRQ routing conflict: "
153312c0b20fSBjorn Helgaas "have IRQ %d, want IRQ %d\n",
153412c0b20fSBjorn Helgaas dev2->irq, irq);
1535fb9aa6f1SThomas Gleixner #endif
1536fb9aa6f1SThomas Gleixner continue;
1537fb9aa6f1SThomas Gleixner }
1538fb9aa6f1SThomas Gleixner dev2->irq = irq;
1539fb9aa6f1SThomas Gleixner pirq_penalty[irq]++;
1540fb9aa6f1SThomas Gleixner if (dev != dev2)
154112c0b20fSBjorn Helgaas dev_info(&dev->dev, "sharing IRQ %d with %s\n",
1542273c1127SMiklos Vajna irq, pci_name(dev2));
1543fb9aa6f1SThomas Gleixner }
1544fb9aa6f1SThomas Gleixner }
1545fb9aa6f1SThomas Gleixner return 1;
1546fb9aa6f1SThomas Gleixner }
1547fb9aa6f1SThomas Gleixner
pcibios_fixup_irqs(void)15489325a28cSThomas Gleixner void __init pcibios_fixup_irqs(void)
1549fb9aa6f1SThomas Gleixner {
1550fb9aa6f1SThomas Gleixner struct pci_dev *dev = NULL;
1551fb9aa6f1SThomas Gleixner u8 pin;
1552fb9aa6f1SThomas Gleixner
1553fb9aa6f1SThomas Gleixner DBG(KERN_DEBUG "PCI: IRQ fixup\n");
15541f7979acSKulikov Vasiliy for_each_pci_dev(dev) {
1555fb9aa6f1SThomas Gleixner /*
1556273c1127SMiklos Vajna * If the BIOS has set an out of range IRQ number, just
1557273c1127SMiklos Vajna * ignore it. Also keep track of which IRQ's are
1558273c1127SMiklos Vajna * already in use.
1559fb9aa6f1SThomas Gleixner */
1560fb9aa6f1SThomas Gleixner if (dev->irq >= 16) {
156112c0b20fSBjorn Helgaas dev_dbg(&dev->dev, "ignoring bogus IRQ %d\n", dev->irq);
1562fb9aa6f1SThomas Gleixner dev->irq = 0;
1563fb9aa6f1SThomas Gleixner }
1564273c1127SMiklos Vajna /*
1565273c1127SMiklos Vajna * If the IRQ is already assigned to a PCI device,
1566273c1127SMiklos Vajna * ignore its ISA use penalty
1567273c1127SMiklos Vajna */
1568273c1127SMiklos Vajna if (pirq_penalty[dev->irq] >= 100 &&
1569273c1127SMiklos Vajna pirq_penalty[dev->irq] < 100000)
1570fb9aa6f1SThomas Gleixner pirq_penalty[dev->irq] = 0;
1571fb9aa6f1SThomas Gleixner pirq_penalty[dev->irq]++;
1572fb9aa6f1SThomas Gleixner }
1573fb9aa6f1SThomas Gleixner
1574b9c61b70SYinghai Lu if (io_apic_assign_pci_irqs)
1575b9c61b70SYinghai Lu return;
1576b9c61b70SYinghai Lu
1577fb9aa6f1SThomas Gleixner dev = NULL;
15781f7979acSKulikov Vasiliy for_each_pci_dev(dev) {
1579fb9aa6f1SThomas Gleixner pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
158012b955ffSBjorn Helgaas if (!pin)
158112b955ffSBjorn Helgaas continue;
158212b955ffSBjorn Helgaas
1583fb9aa6f1SThomas Gleixner /*
1584fb9aa6f1SThomas Gleixner * Still no IRQ? Try to lookup one...
1585fb9aa6f1SThomas Gleixner */
158612b955ffSBjorn Helgaas if (!dev->irq)
1587fb9aa6f1SThomas Gleixner pcibios_lookup_irq(dev, 0);
1588fb9aa6f1SThomas Gleixner }
1589fb9aa6f1SThomas Gleixner }
1590fb9aa6f1SThomas Gleixner
1591fb9aa6f1SThomas Gleixner /*
1592fb9aa6f1SThomas Gleixner * Work around broken HP Pavilion Notebooks which assign USB to
1593fb9aa6f1SThomas Gleixner * IRQ 9 even though it is actually wired to IRQ 11
1594fb9aa6f1SThomas Gleixner */
fix_broken_hp_bios_irq9(const struct dmi_system_id * d)159519ad7ae4SLinus Torvalds static int __init fix_broken_hp_bios_irq9(const struct dmi_system_id *d)
1596fb9aa6f1SThomas Gleixner {
1597fb9aa6f1SThomas Gleixner if (!broken_hp_bios_irq9) {
1598fb9aa6f1SThomas Gleixner broken_hp_bios_irq9 = 1;
1599273c1127SMiklos Vajna printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
1600273c1127SMiklos Vajna d->ident);
1601fb9aa6f1SThomas Gleixner }
1602fb9aa6f1SThomas Gleixner return 0;
1603fb9aa6f1SThomas Gleixner }
1604fb9aa6f1SThomas Gleixner
1605fb9aa6f1SThomas Gleixner /*
1606fb9aa6f1SThomas Gleixner * Work around broken Acer TravelMate 360 Notebooks which assign
1607fb9aa6f1SThomas Gleixner * Cardbus to IRQ 11 even though it is actually wired to IRQ 10
1608fb9aa6f1SThomas Gleixner */
fix_acer_tm360_irqrouting(const struct dmi_system_id * d)160919ad7ae4SLinus Torvalds static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
1610fb9aa6f1SThomas Gleixner {
1611fb9aa6f1SThomas Gleixner if (!acer_tm360_irqrouting) {
1612fb9aa6f1SThomas Gleixner acer_tm360_irqrouting = 1;
1613273c1127SMiklos Vajna printk(KERN_INFO "%s detected - fixing broken IRQ routing\n",
1614273c1127SMiklos Vajna d->ident);
1615fb9aa6f1SThomas Gleixner }
1616fb9aa6f1SThomas Gleixner return 0;
1617fb9aa6f1SThomas Gleixner }
1618fb9aa6f1SThomas Gleixner
16196faadbbbSChristoph Hellwig static const struct dmi_system_id pciirq_dmi_table[] __initconst = {
1620fb9aa6f1SThomas Gleixner {
1621fb9aa6f1SThomas Gleixner .callback = fix_broken_hp_bios_irq9,
1622fb9aa6f1SThomas Gleixner .ident = "HP Pavilion N5400 Series Laptop",
1623fb9aa6f1SThomas Gleixner .matches = {
1624fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
1625fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_BIOS_VERSION, "GE.M1.03"),
1626273c1127SMiklos Vajna DMI_MATCH(DMI_PRODUCT_VERSION,
1627273c1127SMiklos Vajna "HP Pavilion Notebook Model GE"),
1628fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
1629fb9aa6f1SThomas Gleixner },
1630fb9aa6f1SThomas Gleixner },
1631fb9aa6f1SThomas Gleixner {
1632fb9aa6f1SThomas Gleixner .callback = fix_acer_tm360_irqrouting,
1633fb9aa6f1SThomas Gleixner .ident = "Acer TravelMate 36x Laptop",
1634fb9aa6f1SThomas Gleixner .matches = {
1635fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1636fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
1637fb9aa6f1SThomas Gleixner },
1638fb9aa6f1SThomas Gleixner },
1639fb9aa6f1SThomas Gleixner { }
1640fb9aa6f1SThomas Gleixner };
1641fb9aa6f1SThomas Gleixner
pcibios_irq_init(void)1642ab3b3793SThomas Gleixner void __init pcibios_irq_init(void)
1643fb9aa6f1SThomas Gleixner {
1644ea094d53SWenwen Wang struct irq_routing_table *rtable = NULL;
1645ea094d53SWenwen Wang
1646fb9aa6f1SThomas Gleixner DBG(KERN_DEBUG "PCI: IRQ init\n");
1647fb9aa6f1SThomas Gleixner
1648ab3b3793SThomas Gleixner if (raw_pci_ops == NULL)
1649ab3b3793SThomas Gleixner return;
1650fb9aa6f1SThomas Gleixner
1651fb9aa6f1SThomas Gleixner dmi_check_system(pciirq_dmi_table);
1652fb9aa6f1SThomas Gleixner
1653fb9aa6f1SThomas Gleixner pirq_table = pirq_find_routing_table();
1654fb9aa6f1SThomas Gleixner
1655fb9aa6f1SThomas Gleixner #ifdef CONFIG_PCI_BIOS
1656ea094d53SWenwen Wang if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) {
1657fb9aa6f1SThomas Gleixner pirq_table = pcibios_get_irq_routing_table();
1658ea094d53SWenwen Wang rtable = pirq_table;
1659ea094d53SWenwen Wang }
1660fb9aa6f1SThomas Gleixner #endif
1661fb9aa6f1SThomas Gleixner if (pirq_table) {
1662fb9aa6f1SThomas Gleixner pirq_peer_trick();
1663fb9aa6f1SThomas Gleixner pirq_find_router(&pirq_router);
1664fb9aa6f1SThomas Gleixner if (pirq_table->exclusive_irqs) {
1665fb9aa6f1SThomas Gleixner int i;
1666fb9aa6f1SThomas Gleixner for (i = 0; i < 16; i++)
1667fb9aa6f1SThomas Gleixner if (!(pirq_table->exclusive_irqs & (1 << i)))
1668fb9aa6f1SThomas Gleixner pirq_penalty[i] += 100;
1669fb9aa6f1SThomas Gleixner }
1670273c1127SMiklos Vajna /*
1671273c1127SMiklos Vajna * If we're using the I/O APIC, avoid using the PCI IRQ
1672273c1127SMiklos Vajna * routing table
1673273c1127SMiklos Vajna */
1674ea094d53SWenwen Wang if (io_apic_assign_pci_irqs) {
1675ea094d53SWenwen Wang kfree(rtable);
1676fb9aa6f1SThomas Gleixner pirq_table = NULL;
1677fb9aa6f1SThomas Gleixner }
1678ea094d53SWenwen Wang }
1679fb9aa6f1SThomas Gleixner
16809325a28cSThomas Gleixner x86_init.pci.fixup_irqs();
1681b9c61b70SYinghai Lu
1682b9c61b70SYinghai Lu if (io_apic_assign_pci_irqs && pci_routeirq) {
1683b9c61b70SYinghai Lu struct pci_dev *dev = NULL;
1684b9c61b70SYinghai Lu /*
1685b9c61b70SYinghai Lu * PCI IRQ routing is set up by pci_enable_device(), but we
1686b9c61b70SYinghai Lu * also do it here in case there are still broken drivers that
1687b9c61b70SYinghai Lu * don't use pci_enable_device().
1688b9c61b70SYinghai Lu */
1689b9c61b70SYinghai Lu printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
1690b9c61b70SYinghai Lu for_each_pci_dev(dev)
1691b9c61b70SYinghai Lu pirq_enable_irq(dev);
1692b9c61b70SYinghai Lu }
1693fb9aa6f1SThomas Gleixner }
1694fb9aa6f1SThomas Gleixner
pirq_penalize_isa_irq(int irq,int active)1695fb9aa6f1SThomas Gleixner static void pirq_penalize_isa_irq(int irq, int active)
1696fb9aa6f1SThomas Gleixner {
1697fb9aa6f1SThomas Gleixner /*
1698fb9aa6f1SThomas Gleixner * If any ISAPnP device reports an IRQ in its list of possible
1699fb9aa6f1SThomas Gleixner * IRQ's, we try to avoid assigning it to PCI devices.
1700fb9aa6f1SThomas Gleixner */
1701fb9aa6f1SThomas Gleixner if (irq < 16) {
1702fb9aa6f1SThomas Gleixner if (active)
1703fb9aa6f1SThomas Gleixner pirq_penalty[irq] += 1000;
1704fb9aa6f1SThomas Gleixner else
1705fb9aa6f1SThomas Gleixner pirq_penalty[irq] += 100;
1706fb9aa6f1SThomas Gleixner }
1707fb9aa6f1SThomas Gleixner }
1708fb9aa6f1SThomas Gleixner
pcibios_penalize_isa_irq(int irq,int active)1709fb9aa6f1SThomas Gleixner void pcibios_penalize_isa_irq(int irq, int active)
1710fb9aa6f1SThomas Gleixner {
1711fb9aa6f1SThomas Gleixner #ifdef CONFIG_ACPI
1712fb9aa6f1SThomas Gleixner if (!acpi_noirq)
1713fb9aa6f1SThomas Gleixner acpi_penalize_isa_irq(irq, active);
1714fb9aa6f1SThomas Gleixner else
1715fb9aa6f1SThomas Gleixner #endif
1716fb9aa6f1SThomas Gleixner pirq_penalize_isa_irq(irq, active);
1717fb9aa6f1SThomas Gleixner }
1718fb9aa6f1SThomas Gleixner
pirq_enable_irq(struct pci_dev * dev)1719fb9aa6f1SThomas Gleixner static int pirq_enable_irq(struct pci_dev *dev)
1720fb9aa6f1SThomas Gleixner {
1721c03b3b07SJiang Liu u8 pin = 0;
1722fb9aa6f1SThomas Gleixner
1723fb9aa6f1SThomas Gleixner pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
1724b9c61b70SYinghai Lu if (pin && !pcibios_lookup_irq(dev, 1)) {
1725fb9aa6f1SThomas Gleixner char *msg = "";
1726fb9aa6f1SThomas Gleixner
1727b9c61b70SYinghai Lu if (!io_apic_assign_pci_irqs && dev->irq)
1728b9c61b70SYinghai Lu return 0;
1729b9c61b70SYinghai Lu
1730fb9aa6f1SThomas Gleixner if (io_apic_assign_pci_irqs) {
1731b9c61b70SYinghai Lu #ifdef CONFIG_X86_IO_APIC
1732b9c61b70SYinghai Lu struct pci_dev *temp_dev;
1733fb9aa6f1SThomas Gleixner int irq;
1734fb9aa6f1SThomas Gleixner
173567b4eab9SBjorn Helgaas if (dev->irq_managed && dev->irq > 0)
1736cffe0a2bSJiang Liu return 0;
1737fb9aa6f1SThomas Gleixner
1738e20c06fdSYinghai Lu irq = IO_APIC_get_PCI_irq_vector(dev->bus->number,
173925d0d35eSJiang Liu PCI_SLOT(dev->devfn), pin - 1);
1740fb9aa6f1SThomas Gleixner /*
1741fb9aa6f1SThomas Gleixner * Busses behind bridges are typically not listed in the MP-table.
1742fb9aa6f1SThomas Gleixner * In this case we have to look up the IRQ based on the parent bus,
1743fb9aa6f1SThomas Gleixner * parent slot, and pin number. The SMP code detects such bridged
1744fb9aa6f1SThomas Gleixner * busses itself so we should get into this branch reliably.
1745fb9aa6f1SThomas Gleixner */
1746fb9aa6f1SThomas Gleixner temp_dev = dev;
1747fb9aa6f1SThomas Gleixner while (irq < 0 && dev->bus->parent) { /* go back to the bridge */
1748fb9aa6f1SThomas Gleixner struct pci_dev *bridge = dev->bus->self;
1749fb9aa6f1SThomas Gleixner
1750b1c86792SBjorn Helgaas pin = pci_swizzle_interrupt_pin(dev, pin);
1751fb9aa6f1SThomas Gleixner irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number,
1752e20c06fdSYinghai Lu PCI_SLOT(bridge->devfn),
175325d0d35eSJiang Liu pin - 1);
1754fb9aa6f1SThomas Gleixner if (irq >= 0)
175512c0b20fSBjorn Helgaas dev_warn(&dev->dev, "using bridge %s "
175612c0b20fSBjorn Helgaas "INT %c to get IRQ %d\n",
1757f672c392SBjorn Helgaas pci_name(bridge), 'A' + pin - 1,
175812c0b20fSBjorn Helgaas irq);
1759fb9aa6f1SThomas Gleixner dev = bridge;
1760fb9aa6f1SThomas Gleixner }
1761fb9aa6f1SThomas Gleixner dev = temp_dev;
1762fb9aa6f1SThomas Gleixner if (irq >= 0) {
176367b4eab9SBjorn Helgaas dev->irq_managed = 1;
176467b4eab9SBjorn Helgaas dev->irq = irq;
176512c0b20fSBjorn Helgaas dev_info(&dev->dev, "PCI->APIC IRQ transform: "
1766f672c392SBjorn Helgaas "INT %c -> IRQ %d\n", 'A' + pin - 1, irq);
1767fb9aa6f1SThomas Gleixner return 0;
1768fb9aa6f1SThomas Gleixner } else
176912c0b20fSBjorn Helgaas msg = "; probably buggy MP table";
1770b9c61b70SYinghai Lu #endif
1771fb9aa6f1SThomas Gleixner } else if (pci_probe & PCI_BIOS_IRQ_SCAN)
1772fb9aa6f1SThomas Gleixner msg = "";
1773fb9aa6f1SThomas Gleixner else
177412c0b20fSBjorn Helgaas msg = "; please try using pci=biosirq";
1775fb9aa6f1SThomas Gleixner
1776273c1127SMiklos Vajna /*
1777273c1127SMiklos Vajna * With IDE legacy devices the IRQ lookup failure is not
1778273c1127SMiklos Vajna * a problem..
1779273c1127SMiklos Vajna */
1780273c1127SMiklos Vajna if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
1781273c1127SMiklos Vajna !(dev->class & 0x5))
1782fb9aa6f1SThomas Gleixner return 0;
1783fb9aa6f1SThomas Gleixner
178412c0b20fSBjorn Helgaas dev_warn(&dev->dev, "can't find IRQ for PCI INT %c%s\n",
1785f672c392SBjorn Helgaas 'A' + pin - 1, msg);
1786fb9aa6f1SThomas Gleixner }
1787fb9aa6f1SThomas Gleixner return 0;
1788fb9aa6f1SThomas Gleixner }
1789c03b3b07SJiang Liu
mp_should_keep_irq(struct device * dev)17906c777e87SBjorn Helgaas bool mp_should_keep_irq(struct device *dev)
17916c777e87SBjorn Helgaas {
17926c777e87SBjorn Helgaas if (dev->power.is_prepared)
17936c777e87SBjorn Helgaas return true;
17946c777e87SBjorn Helgaas #ifdef CONFIG_PM
17956c777e87SBjorn Helgaas if (dev->power.runtime_status == RPM_SUSPENDING)
17966c777e87SBjorn Helgaas return true;
17976c777e87SBjorn Helgaas #endif
17986c777e87SBjorn Helgaas
17996c777e87SBjorn Helgaas return false;
18006c777e87SBjorn Helgaas }
18016c777e87SBjorn Helgaas
pirq_disable_irq(struct pci_dev * dev)1802c03b3b07SJiang Liu static void pirq_disable_irq(struct pci_dev *dev)
1803c03b3b07SJiang Liu {
18046c777e87SBjorn Helgaas if (io_apic_assign_pci_irqs && !mp_should_keep_irq(&dev->dev) &&
18056c777e87SBjorn Helgaas dev->irq_managed && dev->irq) {
1806c03b3b07SJiang Liu mp_unmap_irq(dev->irq);
180767b4eab9SBjorn Helgaas dev->irq = 0;
180867b4eab9SBjorn Helgaas dev->irq_managed = 0;
1809c03b3b07SJiang Liu }
1810c03b3b07SJiang Liu }
1811