added some suse-specific patches to the kernel.
[linux-flexiantxendom0-3.2.10.git] / arch / ia64 / kernel / iosapic.c
1 /*
2  * I/O SAPIC support.
3  *
4  * Copyright (C) 1999 Intel Corp.
5  * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
6  * Copyright (C) 2000-2002 J.I. Lee <jung-ik.lee@intel.com>
7  * Copyright (C) 1999-2000, 2002-2003 Hewlett-Packard Co.
8  *      David Mosberger-Tang <davidm@hpl.hp.com>
9  * Copyright (C) 1999 VA Linux Systems
10  * Copyright (C) 1999,2000 Walt Drummond <drummond@valinux.com>
11  *
12  * 00/04/19     D. Mosberger    Rewritten to mirror more closely the x86 I/O APIC code.
13  *                              In particular, we now have separate handlers for edge
14  *                              and level triggered interrupts.
15  * 00/10/27     Asit Mallick, Goutham Rao <goutham.rao@intel.com> IRQ vector allocation
16  *                              PCI to vector mapping, shared PCI interrupts.
17  * 00/10/27     D. Mosberger    Document things a bit more to make them more understandable.
18  *                              Clean up much of the old IOSAPIC cruft.
19  * 01/07/27     J.I. Lee        PCI irq routing, Platform/Legacy interrupts and fixes for
20  *                              ACPI S5(SoftOff) support.
21  * 02/01/23     J.I. Lee        iosapic pgm fixes for PCI irq routing from _PRT
22  * 02/01/07     E. Focht        <efocht@ess.nec.de> Redirectable interrupt vectors in
23  *                              iosapic_set_affinity(), initializations for
24  *                              /proc/irq/#/smp_affinity
25  * 02/04/02     P. Diefenbaugh  Cleaned up ACPI PCI IRQ routing.
26  * 02/04/18     J.I. Lee        bug fix in iosapic_init_pci_irq
27  * 02/04/30     J.I. Lee        bug fix in find_iosapic to fix ACPI PCI IRQ to IOSAPIC mapping
28  *                              error
29  * 02/07/29     T. Kochi        Allocate interrupt vectors dynamically
30  * 02/08/04     T. Kochi        Cleaned up terminology (irq, global system interrupt, vector, etc.)
31  * 02/09/20     D. Mosberger    Simplified by taking advantage of ACPI's pci_irq code.
32  * 03/02/19     B. Helgaas      Make pcat_compat system-wide, not per-IOSAPIC.
33  *                              Remove iosapic_address & gsi_base from external interfaces.
34  *                              Rationalize __init/__devinit attributes.
35  */
36 /*
37  * Here is what the interrupt logic between a PCI device and the kernel looks like:
38  *
39  * (1) A PCI device raises one of the four interrupt pins (INTA, INTB, INTC, INTD).  The
40  *     device is uniquely identified by its bus--, and slot-number (the function
41  *     number does not matter here because all functions share the same interrupt
42  *     lines).
43  *
44  * (2) The motherboard routes the interrupt line to a pin on a IOSAPIC controller.
45  *     Multiple interrupt lines may have to share the same IOSAPIC pin (if they're level
46  *     triggered and use the same polarity).  Each interrupt line has a unique Global
47  *     System Interrupt (GSI) number which can be calculated as the sum of the controller's
48  *     base GSI number and the IOSAPIC pin number to which the line connects.
49  *
50  * (3) The IOSAPIC uses an internal routing table entries (RTEs) to map the IOSAPIC pin
51  *     into the IA-64 interrupt vector.  This interrupt vector is then sent to the CPU.
52  *
53  * (4) The kernel recognizes an interrupt as an IRQ.  The IRQ interface is used as
54  *     architecture-independent interrupt handling mechanism in Linux.  As an
55  *     IRQ is a number, we have to have IA-64 interrupt vector number <-> IRQ number
56  *     mapping.  On smaller systems, we use one-to-one mapping between IA-64 vector and
57  *     IRQ.  A platform can implement platform_irq_to_vector(irq) and
58  *     platform_local_vector_to_irq(vector) APIs to differentiate the mapping.
59  *     Please see also include/asm-ia64/hw_irq.h for those APIs.
60  *
61  * To sum up, there are three levels of mappings involved:
62  *
63  *      PCI pin -> global system interrupt (GSI) -> IA-64 vector <-> IRQ
64  *
65  * Note: The term "IRQ" is loosely used everywhere in Linux kernel to describe interrupts.
66  * Now we use "IRQ" only for Linux IRQ's.  ISA IRQ (isa_irq) is the only exception in this
67  * source code.
68  */
69 #include <linux/config.h>
70
71 #include <linux/acpi.h>
72 #include <linux/init.h>
73 #include <linux/irq.h>
74 #include <linux/kernel.h>
75 #include <linux/list.h>
76 #include <linux/pci.h>
77 #include <linux/smp.h>
78 #include <linux/smp_lock.h>
79 #include <linux/string.h>
80
81 #include <asm/delay.h>
82 #include <asm/hw_irq.h>
83 #include <asm/io.h>
84 #include <asm/iosapic.h>
85 #include <asm/machvec.h>
86 #include <asm/processor.h>
87 #include <asm/ptrace.h>
88 #include <asm/system.h>
89
90
91 #undef DEBUG_INTERRUPT_ROUTING
92 #undef OVERRIDE_DEBUG
93
94 #ifdef DEBUG_INTERRUPT_ROUTING
95 #define DBG(fmt...)     printk(fmt)
96 #else
97 #define DBG(fmt...)
98 #endif
99
100 static spinlock_t iosapic_lock = SPIN_LOCK_UNLOCKED;
101
102 /* These tables map IA-64 vectors to the IOSAPIC pin that generates this vector. */
103
104 static struct iosapic_intr_info {
105         char            *addr;          /* base address of IOSAPIC */
106         unsigned int    gsi_base;       /* first GSI assigned to this IOSAPIC */
107         char            rte_index;      /* IOSAPIC RTE index (-1 => not an IOSAPIC interrupt) */
108         unsigned char   dmode   : 3;    /* delivery mode (see iosapic.h) */
109         unsigned char   polarity: 1;    /* interrupt polarity (see iosapic.h) */
110         unsigned char   trigger : 1;    /* trigger mode (see iosapic.h) */
111 } iosapic_intr_info[IA64_NUM_VECTORS];
112
113 static struct iosapic {
114         char            *addr;          /* base address of IOSAPIC */
115         unsigned int    gsi_base;       /* first GSI assigned to this IOSAPIC */
116         unsigned short  num_rte;        /* number of RTE in this IOSAPIC */
117 } iosapic_lists[256];
118
119 static int num_iosapic;
120
121 static unsigned char pcat_compat __initdata;    /* 8259 compatibility flag */
122
123
124 /*
125  * Find an IOSAPIC associated with a GSI
126  */
127 static inline int
128 find_iosapic (unsigned int gsi)
129 {
130         int i;
131
132         for (i = 0; i < num_iosapic; i++) {
133                 if ((unsigned) (gsi - iosapic_lists[i].gsi_base) < iosapic_lists[i].num_rte)
134                         return i;
135         }
136
137         return -1;
138 }
139
140 static inline int
141 _gsi_to_vector (unsigned int gsi)
142 {
143         struct iosapic_intr_info *info;
144
145         for (info = iosapic_intr_info; info < iosapic_intr_info + IA64_NUM_VECTORS; ++info)
146                 if (info->gsi_base + info->rte_index == gsi)
147                         return info - iosapic_intr_info;
148         return -1;
149 }
150
151 /*
152  * Translate GSI number to the corresponding IA-64 interrupt vector.  If no
153  * entry exists, return -1.
154  */
155 inline int
156 gsi_to_vector (unsigned int gsi)
157 {
158         return _gsi_to_vector(gsi);
159 }
160
161 int
162 gsi_to_irq (unsigned int gsi)
163 {
164         /*
165          * XXX fix me: this assumes an identity mapping vetween IA-64 vector and Linux irq
166          * numbers...
167          */
168         return _gsi_to_vector(gsi);
169 }
170
171 static void
172 set_rte (unsigned int vector, unsigned int dest)
173 {
174         unsigned long pol, trigger, dmode;
175         u32 low32, high32;
176         char *addr;
177         int rte_index;
178         char redir;
179
180         DBG(KERN_DEBUG"IOSAPIC: routing vector %d to 0x%x\n", vector, dest);
181
182         rte_index = iosapic_intr_info[vector].rte_index;
183         if (rte_index < 0)
184                 return;         /* not an IOSAPIC interrupt */
185
186         addr    = iosapic_intr_info[vector].addr;
187         pol     = iosapic_intr_info[vector].polarity;
188         trigger = iosapic_intr_info[vector].trigger;
189         dmode   = iosapic_intr_info[vector].dmode;
190
191         redir = (dmode == IOSAPIC_LOWEST_PRIORITY) ? 1 : 0;
192 #ifdef CONFIG_SMP
193         {
194                 unsigned int irq;
195
196                 for (irq = 0; irq < NR_IRQS; ++irq)
197                         if (irq_to_vector(irq) == vector) {
198                                 set_irq_affinity_info(irq, (int)(dest & 0xffff), redir);
199                                 break;
200                         }
201         }
202 #endif
203
204         low32 = ((pol << IOSAPIC_POLARITY_SHIFT) |
205                  (trigger << IOSAPIC_TRIGGER_SHIFT) |
206                  (dmode << IOSAPIC_DELIVERY_SHIFT) |
207                  vector);
208
209         /* dest contains both id and eid */
210         high32 = (dest << IOSAPIC_DEST_SHIFT);
211
212         writel(IOSAPIC_RTE_HIGH(rte_index), addr + IOSAPIC_REG_SELECT);
213         writel(high32, addr + IOSAPIC_WINDOW);
214         writel(IOSAPIC_RTE_LOW(rte_index), addr + IOSAPIC_REG_SELECT);
215         writel(low32, addr + IOSAPIC_WINDOW);
216 }
217
218 static void
219 nop (unsigned int vector)
220 {
221         /* do nothing... */
222 }
223
224 static void
225 mask_irq (unsigned int irq)
226 {
227         unsigned long flags;
228         char *addr;
229         u32 low32;
230         int rte_index;
231         ia64_vector vec = irq_to_vector(irq);
232
233         addr = iosapic_intr_info[vec].addr;
234         rte_index = iosapic_intr_info[vec].rte_index;
235
236         if (rte_index < 0)
237                 return;                 /* not an IOSAPIC interrupt! */
238
239         spin_lock_irqsave(&iosapic_lock, flags);
240         {
241                 writel(IOSAPIC_RTE_LOW(rte_index), addr + IOSAPIC_REG_SELECT);
242                 low32 = readl(addr + IOSAPIC_WINDOW);
243
244                 low32 |= (1 << IOSAPIC_MASK_SHIFT);    /* set only the mask bit */
245                 writel(low32, addr + IOSAPIC_WINDOW);
246         }
247         spin_unlock_irqrestore(&iosapic_lock, flags);
248 }
249
250 static void
251 unmask_irq (unsigned int irq)
252 {
253         unsigned long flags;
254         char *addr;
255         u32 low32;
256         int rte_index;
257         ia64_vector vec = irq_to_vector(irq);
258
259         addr = iosapic_intr_info[vec].addr;
260         rte_index = iosapic_intr_info[vec].rte_index;
261         if (rte_index < 0)
262                 return;                 /* not an IOSAPIC interrupt! */
263
264         spin_lock_irqsave(&iosapic_lock, flags);
265         {
266                 writel(IOSAPIC_RTE_LOW(rte_index), addr + IOSAPIC_REG_SELECT);
267                 low32 = readl(addr + IOSAPIC_WINDOW);
268
269                 low32 &= ~(1 << IOSAPIC_MASK_SHIFT);    /* clear only the mask bit */
270                 writel(low32, addr + IOSAPIC_WINDOW);
271         }
272         spin_unlock_irqrestore(&iosapic_lock, flags);
273 }
274
275
276 static void
277 iosapic_set_affinity (unsigned int irq, unsigned long mask)
278 {
279 #ifdef CONFIG_SMP
280         unsigned long flags;
281         u32 high32, low32;
282         int dest, rte_index;
283         char *addr;
284         int redir = (irq & IA64_IRQ_REDIRECTED) ? 1 : 0;
285         ia64_vector vec;
286
287         irq &= (~IA64_IRQ_REDIRECTED);
288         vec = irq_to_vector(irq);
289
290         mask &= cpu_online_map;
291
292         if (!mask || vec >= IA64_NUM_VECTORS)
293                 return;
294
295         dest = cpu_physical_id(ffz(~mask));
296
297         rte_index = iosapic_intr_info[vec].rte_index;
298         addr = iosapic_intr_info[vec].addr;
299
300         if (rte_index < 0)
301                 return;                 /* not an IOSAPIC interrupt */
302
303         set_irq_affinity_info(irq, dest, redir);
304
305         /* dest contains both id and eid */
306         high32 = dest << IOSAPIC_DEST_SHIFT;
307
308         spin_lock_irqsave(&iosapic_lock, flags);
309         {
310                 /* get current delivery mode by reading the low32 */
311                 writel(IOSAPIC_RTE_LOW(rte_index), addr + IOSAPIC_REG_SELECT);
312                 low32 = readl(addr + IOSAPIC_WINDOW);
313
314                 low32 &= ~(7 << IOSAPIC_DELIVERY_SHIFT);
315                 if (redir)
316                         /* change delivery mode to lowest priority */
317                         low32 |= (IOSAPIC_LOWEST_PRIORITY << IOSAPIC_DELIVERY_SHIFT);
318                 else
319                         /* change delivery mode to fixed */
320                         low32 |= (IOSAPIC_FIXED << IOSAPIC_DELIVERY_SHIFT);
321
322                 writel(IOSAPIC_RTE_HIGH(rte_index), addr + IOSAPIC_REG_SELECT);
323                 writel(high32, addr + IOSAPIC_WINDOW);
324                 writel(IOSAPIC_RTE_LOW(rte_index), addr + IOSAPIC_REG_SELECT);
325                 writel(low32, addr + IOSAPIC_WINDOW);
326         }
327         spin_unlock_irqrestore(&iosapic_lock, flags);
328 #endif
329 }
330
331 /*
332  * Handlers for level-triggered interrupts.
333  */
334
335 static unsigned int
336 iosapic_startup_level_irq (unsigned int irq)
337 {
338         unmask_irq(irq);
339         return 0;
340 }
341
342 static void
343 iosapic_end_level_irq (unsigned int irq)
344 {
345         ia64_vector vec = irq_to_vector(irq);
346
347         writel(vec, iosapic_intr_info[vec].addr + IOSAPIC_EOI);
348 }
349
350 #define iosapic_shutdown_level_irq      mask_irq
351 #define iosapic_enable_level_irq        unmask_irq
352 #define iosapic_disable_level_irq       mask_irq
353 #define iosapic_ack_level_irq           nop
354
355 struct hw_interrupt_type irq_type_iosapic_level = {
356         .typename =     "IO-SAPIC-level",
357         .startup =      iosapic_startup_level_irq,
358         .shutdown =     iosapic_shutdown_level_irq,
359         .enable =       iosapic_enable_level_irq,
360         .disable =      iosapic_disable_level_irq,
361         .ack =          iosapic_ack_level_irq,
362         .end =          iosapic_end_level_irq,
363         .set_affinity = iosapic_set_affinity
364 };
365
366 /*
367  * Handlers for edge-triggered interrupts.
368  */
369
370 static unsigned int
371 iosapic_startup_edge_irq (unsigned int irq)
372 {
373         unmask_irq(irq);
374         /*
375          * IOSAPIC simply drops interrupts pended while the
376          * corresponding pin was masked, so we can't know if an
377          * interrupt is pending already.  Let's hope not...
378          */
379         return 0;
380 }
381
382 static void
383 iosapic_ack_edge_irq (unsigned int irq)
384 {
385         irq_desc_t *idesc = irq_desc(irq);
386         /*
387          * Once we have recorded IRQ_PENDING already, we can mask the
388          * interrupt for real. This prevents IRQ storms from unhandled
389          * devices.
390          */
391         if ((idesc->status & (IRQ_PENDING|IRQ_DISABLED)) == (IRQ_PENDING|IRQ_DISABLED))
392                 mask_irq(irq);
393 }
394
395 #define iosapic_enable_edge_irq         unmask_irq
396 #define iosapic_disable_edge_irq        nop
397 #define iosapic_end_edge_irq            nop
398
399 struct hw_interrupt_type irq_type_iosapic_edge = {
400         .typename =     "IO-SAPIC-edge",
401         .startup =      iosapic_startup_edge_irq,
402         .shutdown =     iosapic_disable_edge_irq,
403         .enable =       iosapic_enable_edge_irq,
404         .disable =      iosapic_disable_edge_irq,
405         .ack =          iosapic_ack_edge_irq,
406         .end =          iosapic_end_edge_irq,
407         .set_affinity = iosapic_set_affinity
408 };
409
410 unsigned int
411 iosapic_version (char *addr)
412 {
413         /*
414          * IOSAPIC Version Register return 32 bit structure like:
415          * {
416          *      unsigned int version   : 8;
417          *      unsigned int reserved1 : 8;
418          *      unsigned int max_redir : 8;
419          *      unsigned int reserved2 : 8;
420          * }
421          */
422         writel(IOSAPIC_VERSION, addr + IOSAPIC_REG_SELECT);
423         return readl(IOSAPIC_WINDOW + addr);
424 }
425
426 /*
427  * if the given vector is already owned by other,
428  *  assign a new vector for the other and make the vector available
429  */
430 static void __init
431 iosapic_reassign_vector (int vector)
432 {
433         int new_vector;
434
435         if (iosapic_intr_info[vector].rte_index >= 0 || iosapic_intr_info[vector].addr
436             || iosapic_intr_info[vector].gsi_base || iosapic_intr_info[vector].dmode
437             || iosapic_intr_info[vector].polarity || iosapic_intr_info[vector].trigger)
438         {
439                 new_vector = ia64_alloc_vector();
440                 printk(KERN_INFO "Reassigning vector %d to %d\n", vector, new_vector);
441                 memcpy(&iosapic_intr_info[new_vector], &iosapic_intr_info[vector],
442                        sizeof(struct iosapic_intr_info));
443                 memset(&iosapic_intr_info[vector], 0, sizeof(struct iosapic_intr_info));
444                 iosapic_intr_info[vector].rte_index = -1;
445         }
446 }
447
448 static void
449 register_intr (unsigned int gsi, int vector, unsigned char delivery,
450                unsigned long polarity, unsigned long trigger)
451 {
452         irq_desc_t *idesc;
453         struct hw_interrupt_type *irq_type;
454         int rte_index;
455         int index;
456         unsigned long gsi_base;
457         char *iosapic_address;
458
459         index = find_iosapic(gsi);
460         if (index < 0) {
461                 printk(KERN_WARNING "%s: No IOSAPIC for GSI 0x%x\n", __FUNCTION__, gsi);
462                 return;
463         }
464
465         iosapic_address = iosapic_lists[index].addr;
466         gsi_base = iosapic_lists[index].gsi_base;
467
468         rte_index = gsi - gsi_base;
469         iosapic_intr_info[vector].rte_index = rte_index;
470         iosapic_intr_info[vector].polarity = polarity;
471         iosapic_intr_info[vector].dmode    = delivery;
472         iosapic_intr_info[vector].addr     = iosapic_address;
473         iosapic_intr_info[vector].gsi_base = gsi_base;
474         iosapic_intr_info[vector].trigger  = trigger;
475
476         if (trigger == IOSAPIC_EDGE)
477                 irq_type = &irq_type_iosapic_edge;
478         else
479                 irq_type = &irq_type_iosapic_level;
480
481         idesc = irq_desc(vector);
482         if (idesc->handler != irq_type) {
483                 if (idesc->handler != &no_irq_type)
484                         printk(KERN_WARNING "%s: changing vector %d from %s to %s\n",
485                                __FUNCTION__, vector, idesc->handler->typename, irq_type->typename);
486                 idesc->handler = irq_type;
487         }
488 }
489
490 /*
491  * ACPI can describe IOSAPIC interrupts via static tables and namespace
492  * methods.  This provides an interface to register those interrupts and
493  * program the IOSAPIC RTE.
494  */
495 int
496 iosapic_register_intr (unsigned int gsi,
497                        unsigned long polarity, unsigned long trigger)
498 {
499         int vector;
500         unsigned int dest = (ia64_get_lid() >> 16) & 0xffff;
501
502         vector = gsi_to_vector(gsi);
503         if (vector < 0)
504                 vector = ia64_alloc_vector();
505
506         register_intr(gsi, vector, IOSAPIC_LOWEST_PRIORITY,
507                       polarity, trigger);
508
509         printk(KERN_INFO "GSI 0x%x(%s,%s) -> CPU 0x%04x vector %d\n",
510                gsi, (polarity == IOSAPIC_POL_HIGH ? "high" : "low"),
511                (trigger == IOSAPIC_EDGE ? "edge" : "level"), dest, vector);
512
513         /* program the IOSAPIC routing table */
514         set_rte(vector, dest);
515         return vector;
516 }
517
518 /*
519  * ACPI calls this when it finds an entry for a platform interrupt.
520  * Note that the irq_base and IOSAPIC address must be set in iosapic_init().
521  */
522 int __init
523 iosapic_register_platform_intr (u32 int_type, unsigned int gsi,
524                                 int iosapic_vector, u16 eid, u16 id,
525                                 unsigned long polarity, unsigned long trigger)
526 {
527         unsigned char delivery;
528         int vector;
529         unsigned int dest = ((id << 8) | eid) & 0xffff;
530
531         switch (int_type) {
532               case ACPI_INTERRUPT_PMI:
533                 vector = iosapic_vector;
534                 /*
535                  * since PMI vector is alloc'd by FW(ACPI) not by kernel,
536                  * we need to make sure the vector is available
537                  */
538                 iosapic_reassign_vector(vector);
539                 delivery = IOSAPIC_PMI;
540                 break;
541               case ACPI_INTERRUPT_INIT:
542                 vector = ia64_alloc_vector();
543                 delivery = IOSAPIC_INIT;
544                 break;
545               case ACPI_INTERRUPT_CPEI:
546                 vector = IA64_PCE_VECTOR;
547                 delivery = IOSAPIC_LOWEST_PRIORITY;
548                 break;
549               default:
550                 printk(KERN_ERR "iosapic_register_platform_irq(): invalid int type\n");
551                 return -1;
552         }
553
554         register_intr(gsi, vector, delivery, polarity,
555                       trigger);
556
557         printk(KERN_INFO "PLATFORM int 0x%x: GSI 0x%x(%s,%s) -> CPU 0x%04x vector %d\n",
558                int_type, gsi, (polarity == IOSAPIC_POL_HIGH ? "high" : "low"),
559                (trigger == IOSAPIC_EDGE ? "edge" : "level"), dest, vector);
560
561         /* program the IOSAPIC routing table */
562         set_rte(vector, dest);
563         return vector;
564 }
565
566
567 /*
568  * ACPI calls this when it finds an entry for a legacy ISA IRQ override.
569  * Note that the gsi_base and IOSAPIC address must be set in iosapic_init().
570  */
571 void __init
572 iosapic_override_isa_irq (unsigned int isa_irq, unsigned int gsi,
573                           unsigned long polarity,
574                           unsigned long trigger)
575 {
576         int vector;
577         unsigned int dest = (ia64_get_lid() >> 16) & 0xffff;
578
579         vector = isa_irq_to_vector(isa_irq);
580
581         register_intr(gsi, vector, IOSAPIC_LOWEST_PRIORITY, polarity, trigger);
582
583         DBG("ISA: IRQ %u -> GSI 0x%x (%s,%s) -> CPU 0x%04x vector %d\n",
584             isa_irq, gsi,
585             polarity == IOSAPIC_POL_HIGH ? "high" : "low", trigger == IOSAPIC_EDGE ? "edge" : "level",
586             dest, vector);
587
588         /* program the IOSAPIC routing table */
589         set_rte(vector, dest);
590 }
591
592 void __init
593 iosapic_system_init (int system_pcat_compat)
594 {
595         int vector;
596
597         for (vector = 0; vector < IA64_NUM_VECTORS; ++vector)
598                 iosapic_intr_info[vector].rte_index = -1;       /* mark as unused */
599
600         pcat_compat = system_pcat_compat;
601         if (pcat_compat) {
602                 /*
603                  * Disable the compatibility mode interrupts (8259 style), needs IN/OUT support
604                  * enabled.
605                  */
606                 printk(KERN_INFO "%s: Disabling PC-AT compatible 8259 interrupts\n", __FUNCTION__);
607                 outb(0xff, 0xA1);
608                 outb(0xff, 0x21);
609         }
610 }
611
612 void __init
613 iosapic_init (unsigned long phys_addr, unsigned int gsi_base)
614 {
615         int num_rte;
616         unsigned int isa_irq, ver;
617         char *addr;
618
619         addr = ioremap(phys_addr, 0);
620         ver = iosapic_version(addr);
621
622         /*
623          * The MAX_REDIR register holds the highest input pin
624          * number (starting from 0).
625          * We add 1 so that we can use it for number of pins (= RTEs)
626          */
627         num_rte = ((ver >> 16) & 0xff) + 1;
628
629         iosapic_lists[num_iosapic].addr = addr;
630         iosapic_lists[num_iosapic].gsi_base = gsi_base;
631         iosapic_lists[num_iosapic].num_rte = num_rte;
632         num_iosapic++;
633
634         printk(KERN_INFO "  IOSAPIC v%x.%x, address 0x%lx, GSIs 0x%x-0x%x\n",
635                (ver & 0xf0) >> 4, (ver & 0x0f), phys_addr, gsi_base, gsi_base + num_rte - 1);
636
637         if ((gsi_base == 0) && pcat_compat) {
638
639                 /*
640                  * Map the legacy ISA devices into the IOSAPIC data.  Some of these may
641                  * get reprogrammed later on with data from the ACPI Interrupt Source
642                  * Override table.
643                  */
644                 for (isa_irq = 0; isa_irq < 16; ++isa_irq)
645                         iosapic_override_isa_irq(isa_irq, isa_irq, IOSAPIC_POL_HIGH, IOSAPIC_EDGE);
646         }
647 }
648
649 static void __init
650 fixup_vector (int vector, unsigned int gsi, const char *pci_id)
651 {
652         struct hw_interrupt_type *irq_type = &irq_type_iosapic_level;
653         irq_desc_t *idesc;
654         unsigned int dest;
655
656         idesc = irq_desc(vector);
657         if (idesc->handler != irq_type) {
658                 if (idesc->handler != &no_irq_type)
659                         printk(KERN_INFO "IOSAPIC: changing vector %d from %s to %s\n",
660                                vector, idesc->handler->typename, irq_type->typename);
661                 idesc->handler = irq_type;
662         }
663 #ifdef CONFIG_SMP
664         /*
665          * For platforms that do not support interrupt redirect via the XTP interface, we
666          * can round-robin the PCI device interrupts to the processors
667          */
668         if (!(smp_int_redirect & SMP_IRQ_REDIRECTION)) {
669                 static int cpu_index = -1;
670
671                 do
672                         if (++cpu_index >= NR_CPUS)
673                                 cpu_index = 0;
674                 while (!cpu_online(cpu_index));
675
676                 dest = cpu_physical_id(cpu_index) & 0xffff;
677         } else {
678                 /*
679                  * Direct the interrupt vector to the current cpu, platform redirection
680                  * will distribute them.
681                  */
682                 dest = (ia64_get_lid() >> 16) & 0xffff;
683         }
684 #else
685         /* direct the interrupt vector to the running cpu id */
686         dest = (ia64_get_lid() >> 16) & 0xffff;
687 #endif
688         set_rte(vector, dest);
689
690         printk(KERN_INFO "IOSAPIC: %s -> GSI 0x%x -> CPU 0x%04x vector %d\n",
691                pci_id, gsi, dest, vector);
692 }
693
694 void __init
695 iosapic_parse_prt (void)
696 {
697         struct acpi_prt_entry *entry;
698         struct list_head *node;
699         unsigned int gsi;
700         int vector;
701         char pci_id[16];
702
703         list_for_each(node, &acpi_prt.entries) {
704                 entry = list_entry(node, struct acpi_prt_entry, node);
705
706                 /* We're only interested in static (non-link) entries.  */
707                 if (entry->link.handle)
708                         continue;
709
710                 gsi = entry->link.index;
711
712                 vector = gsi_to_vector(gsi);
713                 if (vector < 0) {
714                         /* allocate a vector for this interrupt line */
715                         if (pcat_compat && (gsi < 16))
716                                 vector = isa_irq_to_vector(gsi);
717                         else
718                                 /* new GSI; allocate a vector for it */
719                                 vector = ia64_alloc_vector();
720
721                         register_intr(gsi, vector, IOSAPIC_LOWEST_PRIORITY, IOSAPIC_POL_LOW, IOSAPIC_LEVEL);
722                 }
723                 snprintf(pci_id, sizeof(pci_id), "%02x:%02x:%02x[%c]",
724                          entry->id.segment, entry->id.bus, entry->id.device, 'A' + entry->pin);
725
726                 fixup_vector(vector, gsi, pci_id);
727         }
728 }