blob: 5a1252753dbb8b9d866a27a244aa8ed48da3b17d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Intel IO-APIC support for multi-Pentium hosts.
3 *
4 * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar, Hajnalka Szabo
5 *
6 * Many thanks to Stig Venaas for trying out countless experimental
7 * patches and reporting/debugging problems patiently!
8 *
9 * (c) 1999, Multiple IO-APIC support, developed by
10 * Ken-ichi Yaku <yaku@css1.kbnes.nec.co.jp> and
11 * Hidemi Kishimoto <kisimoto@css1.kbnes.nec.co.jp>,
12 * further tested and cleaned up by Zach Brown <zab@redhat.com>
13 * and Ingo Molnar <mingo@redhat.com>
14 *
15 * Fixes
16 * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
17 * thanks to Eric Gilmore
18 * and Rolf G. Tews
19 * for testing these extensively
20 * Paul Diefenbaugh : Added full ACPI support
21 */
22
23#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/interrupt.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/smp_lock.h>
29#include <linux/mc146818rtc.h>
30#include <linux/compiler.h>
31#include <linux/acpi.h>
Alexey Dobriyan129f6942005-06-23 00:08:33 -070032#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/sysdev.h>
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -070034#include <linux/pci.h>
Eric W. Biederman3b7d1922006-10-04 02:16:59 -070035#include <linux/msi.h>
Ashok Raj54d5d422005-09-06 15:16:15 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/io.h>
38#include <asm/smp.h>
39#include <asm/desc.h>
40#include <asm/timer.h>
Ingo Molnar306e4402005-06-30 02:58:55 -070041#include <asm/i8259.h>
Don Zickus3e4ff112006-06-26 13:57:01 +020042#include <asm/nmi.h>
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -070043#include <asm/msidef.h>
Eric W. Biederman8b955b02006-10-04 02:16:55 -070044#include <asm/hypertransport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46#include <mach_apic.h>
Andi Kleen874c4fe2006-09-26 10:52:26 +020047#include <mach_apicdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#include "io_ports.h"
50
51int (*ioapic_renumber_irq)(int ioapic, int irq);
52atomic_t irq_mis_count;
53
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -080054/* Where if anywhere is the i8259 connect in external int mode */
55static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static DEFINE_SPINLOCK(ioapic_lock);
Jan Beulich0a1ad602006-06-26 13:56:43 +020058static DEFINE_SPINLOCK(vector_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Andi Kleenf9262c12006-03-08 17:57:25 -080060int timer_over_8254 __initdata = 1;
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
63 * Is the SiS APIC rmw bug present ?
64 * -1 = don't know, 0 = no, 1 = yes
65 */
66int sis_apic_bug = -1;
67
68/*
69 * # of IRQ routing registers
70 */
71int nr_ioapic_registers[MAX_IO_APICS];
72
Rusty Russell1a3f2392006-09-26 10:52:32 +020073static int disable_timer_pin_1 __initdata;
Chuck Ebbert66759a02005-09-12 18:49:25 +020074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
76 * Rough estimation of how many shared IRQs there are, can
77 * be changed anytime.
78 */
79#define MAX_PLUS_SHARED_IRQS NR_IRQS
80#define PIN_MAP_SIZE (MAX_PLUS_SHARED_IRQS + NR_IRQS)
81
82/*
83 * This is performance-critical, we want to do it O(1)
84 *
85 * the indexing order of this array favors 1:1 mappings
86 * between pins and IRQs.
87 */
88
89static struct irq_pin_list {
90 int apic, pin, next;
91} irq_2_pin[PIN_MAP_SIZE];
92
Andi Kleencf4c6a22006-09-26 10:52:30 +020093union entry_union {
94 struct { u32 w1, w2; };
95 struct IO_APIC_route_entry entry;
96};
97
98static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
99{
100 union entry_union eu;
101 unsigned long flags;
102 spin_lock_irqsave(&ioapic_lock, flags);
103 eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
104 eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
105 spin_unlock_irqrestore(&ioapic_lock, flags);
106 return eu.entry;
107}
108
109static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
110{
111 unsigned long flags;
112 union entry_union eu;
113 eu.entry = e;
114 spin_lock_irqsave(&ioapic_lock, flags);
115 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
116 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
117 spin_unlock_irqrestore(&ioapic_lock, flags);
118}
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120/*
121 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
122 * shared ISA-space IRQs, so we have to support them. We are super
123 * fast in the common case, and fast for shared ISA-space IRQs.
124 */
125static void add_pin_to_irq(unsigned int irq, int apic, int pin)
126{
127 static int first_free_entry = NR_IRQS;
128 struct irq_pin_list *entry = irq_2_pin + irq;
129
130 while (entry->next)
131 entry = irq_2_pin + entry->next;
132
133 if (entry->pin != -1) {
134 entry->next = first_free_entry;
135 entry = irq_2_pin + entry->next;
136 if (++first_free_entry >= PIN_MAP_SIZE)
137 panic("io_apic.c: whoops");
138 }
139 entry->apic = apic;
140 entry->pin = pin;
141}
142
143/*
144 * Reroute an IRQ to a different pin.
145 */
146static void __init replace_pin_at_irq(unsigned int irq,
147 int oldapic, int oldpin,
148 int newapic, int newpin)
149{
150 struct irq_pin_list *entry = irq_2_pin + irq;
151
152 while (1) {
153 if (entry->apic == oldapic && entry->pin == oldpin) {
154 entry->apic = newapic;
155 entry->pin = newpin;
156 }
157 if (!entry->next)
158 break;
159 entry = irq_2_pin + entry->next;
160 }
161}
162
163static void __modify_IO_APIC_irq (unsigned int irq, unsigned long enable, unsigned long disable)
164{
165 struct irq_pin_list *entry = irq_2_pin + irq;
166 unsigned int pin, reg;
167
168 for (;;) {
169 pin = entry->pin;
170 if (pin == -1)
171 break;
172 reg = io_apic_read(entry->apic, 0x10 + pin*2);
173 reg &= ~disable;
174 reg |= enable;
175 io_apic_modify(entry->apic, 0x10 + pin*2, reg);
176 if (!entry->next)
177 break;
178 entry = irq_2_pin + entry->next;
179 }
180}
181
182/* mask = 1 */
183static void __mask_IO_APIC_irq (unsigned int irq)
184{
185 __modify_IO_APIC_irq(irq, 0x00010000, 0);
186}
187
188/* mask = 0 */
189static void __unmask_IO_APIC_irq (unsigned int irq)
190{
191 __modify_IO_APIC_irq(irq, 0, 0x00010000);
192}
193
194/* mask = 1, trigger = 0 */
195static void __mask_and_edge_IO_APIC_irq (unsigned int irq)
196{
197 __modify_IO_APIC_irq(irq, 0x00010000, 0x00008000);
198}
199
200/* mask = 0, trigger = 1 */
201static void __unmask_and_level_IO_APIC_irq (unsigned int irq)
202{
203 __modify_IO_APIC_irq(irq, 0x00008000, 0x00010000);
204}
205
206static void mask_IO_APIC_irq (unsigned int irq)
207{
208 unsigned long flags;
209
210 spin_lock_irqsave(&ioapic_lock, flags);
211 __mask_IO_APIC_irq(irq);
212 spin_unlock_irqrestore(&ioapic_lock, flags);
213}
214
215static void unmask_IO_APIC_irq (unsigned int irq)
216{
217 unsigned long flags;
218
219 spin_lock_irqsave(&ioapic_lock, flags);
220 __unmask_IO_APIC_irq(irq);
221 spin_unlock_irqrestore(&ioapic_lock, flags);
222}
223
224static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
225{
226 struct IO_APIC_route_entry entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* Check delivery_mode to be sure we're not clearing an SMI pin */
Andi Kleencf4c6a22006-09-26 10:52:30 +0200229 entry = ioapic_read_entry(apic, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (entry.delivery_mode == dest_SMI)
231 return;
232
233 /*
234 * Disable it in the IO-APIC irq-routing table:
235 */
236 memset(&entry, 0, sizeof(entry));
237 entry.mask = 1;
Andi Kleencf4c6a22006-09-26 10:52:30 +0200238 ioapic_write_entry(apic, pin, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
240
241static void clear_IO_APIC (void)
242{
243 int apic, pin;
244
245 for (apic = 0; apic < nr_ioapics; apic++)
246 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
247 clear_IO_APIC_pin(apic, pin);
248}
249
Ashok Raj54d5d422005-09-06 15:16:15 -0700250#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t cpumask)
252{
253 unsigned long flags;
254 int pin;
255 struct irq_pin_list *entry = irq_2_pin + irq;
256 unsigned int apicid_value;
Ashok Raj54d5d422005-09-06 15:16:15 -0700257 cpumask_t tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Ashok Raj54d5d422005-09-06 15:16:15 -0700259 cpus_and(tmp, cpumask, cpu_online_map);
260 if (cpus_empty(tmp))
261 tmp = TARGET_CPUS;
262
263 cpus_and(cpumask, tmp, CPU_MASK_ALL);
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 apicid_value = cpu_mask_to_apicid(cpumask);
266 /* Prepare to do the io_apic_write */
267 apicid_value = apicid_value << 24;
268 spin_lock_irqsave(&ioapic_lock, flags);
269 for (;;) {
270 pin = entry->pin;
271 if (pin == -1)
272 break;
273 io_apic_write(entry->apic, 0x10 + 1 + pin*2, apicid_value);
274 if (!entry->next)
275 break;
276 entry = irq_2_pin + entry->next;
277 }
Eric W. Biedermanace80ab2006-10-04 02:16:47 -0700278 set_native_irq_info(irq, cpumask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 spin_unlock_irqrestore(&ioapic_lock, flags);
280}
281
282#if defined(CONFIG_IRQBALANCE)
283# include <asm/processor.h> /* kernel_thread() */
284# include <linux/kernel_stat.h> /* kstat */
285# include <linux/slab.h> /* kmalloc() */
286# include <linux/timer.h> /* time_after() */
287
Zhang Yanmin1b61b912006-06-23 02:04:22 -0700288#ifdef CONFIG_BALANCED_IRQ_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289# define TDprintk(x...) do { printk("<%ld:%s:%d>: ", jiffies, __FILE__, __LINE__); printk(x); } while (0)
290# define Dprintk(x...) do { TDprintk(x); } while (0)
291# else
292# define TDprintk(x...)
293# define Dprintk(x...)
294# endif
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#define IRQBALANCE_CHECK_ARCH -999
Zhang Yanmin1b61b912006-06-23 02:04:22 -0700297#define MAX_BALANCED_IRQ_INTERVAL (5*HZ)
298#define MIN_BALANCED_IRQ_INTERVAL (HZ/2)
299#define BALANCED_IRQ_MORE_DELTA (HZ/10)
300#define BALANCED_IRQ_LESS_DELTA (HZ)
301
302static int irqbalance_disabled __read_mostly = IRQBALANCE_CHECK_ARCH;
303static int physical_balance __read_mostly;
304static long balanced_irq_interval __read_mostly = MAX_BALANCED_IRQ_INTERVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306static struct irq_cpu_info {
307 unsigned long * last_irq;
308 unsigned long * irq_delta;
309 unsigned long irq;
310} irq_cpu_data[NR_CPUS];
311
312#define CPU_IRQ(cpu) (irq_cpu_data[cpu].irq)
313#define LAST_CPU_IRQ(cpu,irq) (irq_cpu_data[cpu].last_irq[irq])
314#define IRQ_DELTA(cpu,irq) (irq_cpu_data[cpu].irq_delta[irq])
315
316#define IDLE_ENOUGH(cpu,now) \
317 (idle_cpu(cpu) && ((now) - per_cpu(irq_stat, (cpu)).idle_timestamp > 1))
318
319#define IRQ_ALLOWED(cpu, allowed_mask) cpu_isset(cpu, allowed_mask)
320
321#define CPU_TO_PACKAGEINDEX(i) (first_cpu(cpu_sibling_map[i]))
322
Zhang Yanmin1b61b912006-06-23 02:04:22 -0700323static cpumask_t balance_irq_affinity[NR_IRQS] = {
324 [0 ... NR_IRQS-1] = CPU_MASK_ALL
325};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Zhang Yanmin1b61b912006-06-23 02:04:22 -0700327void set_balance_irq_affinity(unsigned int irq, cpumask_t mask)
328{
329 balance_irq_affinity[irq] = mask;
330}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332static unsigned long move(int curr_cpu, cpumask_t allowed_mask,
333 unsigned long now, int direction)
334{
335 int search_idle = 1;
336 int cpu = curr_cpu;
337
338 goto inside;
339
340 do {
341 if (unlikely(cpu == curr_cpu))
342 search_idle = 0;
343inside:
344 if (direction == 1) {
345 cpu++;
346 if (cpu >= NR_CPUS)
347 cpu = 0;
348 } else {
349 cpu--;
350 if (cpu == -1)
351 cpu = NR_CPUS-1;
352 }
353 } while (!cpu_online(cpu) || !IRQ_ALLOWED(cpu,allowed_mask) ||
354 (search_idle && !IDLE_ENOUGH(cpu,now)));
355
356 return cpu;
357}
358
359static inline void balance_irq(int cpu, int irq)
360{
361 unsigned long now = jiffies;
362 cpumask_t allowed_mask;
363 unsigned int new_cpu;
364
365 if (irqbalance_disabled)
366 return;
367
Zhang Yanmin1b61b912006-06-23 02:04:22 -0700368 cpus_and(allowed_mask, cpu_online_map, balance_irq_affinity[irq]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 new_cpu = move(cpu, allowed_mask, now, 1);
370 if (cpu != new_cpu) {
Ashok Raj54d5d422005-09-06 15:16:15 -0700371 set_pending_irq(irq, cpumask_of_cpu(new_cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
373}
374
375static inline void rotate_irqs_among_cpus(unsigned long useful_load_threshold)
376{
377 int i, j;
378 Dprintk("Rotating IRQs among CPUs.\n");
Andrew Morton394e3902006-03-23 03:01:05 -0800379 for_each_online_cpu(i) {
380 for (j = 0; j < NR_IRQS; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (!irq_desc[j].action)
382 continue;
383 /* Is it a significant load ? */
384 if (IRQ_DELTA(CPU_TO_PACKAGEINDEX(i),j) <
385 useful_load_threshold)
386 continue;
387 balance_irq(i, j);
388 }
389 }
390 balanced_irq_interval = max((long)MIN_BALANCED_IRQ_INTERVAL,
391 balanced_irq_interval - BALANCED_IRQ_LESS_DELTA);
392 return;
393}
394
395static void do_irq_balance(void)
396{
397 int i, j;
398 unsigned long max_cpu_irq = 0, min_cpu_irq = (~0);
399 unsigned long move_this_load = 0;
400 int max_loaded = 0, min_loaded = 0;
401 int load;
402 unsigned long useful_load_threshold = balanced_irq_interval + 10;
403 int selected_irq;
404 int tmp_loaded, first_attempt = 1;
405 unsigned long tmp_cpu_irq;
406 unsigned long imbalance = 0;
407 cpumask_t allowed_mask, target_cpu_mask, tmp;
408
KAMEZAWA Hiroyukic89125992006-03-28 01:56:39 -0800409 for_each_possible_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 int package_index;
411 CPU_IRQ(i) = 0;
412 if (!cpu_online(i))
413 continue;
414 package_index = CPU_TO_PACKAGEINDEX(i);
415 for (j = 0; j < NR_IRQS; j++) {
416 unsigned long value_now, delta;
417 /* Is this an active IRQ? */
418 if (!irq_desc[j].action)
419 continue;
420 if ( package_index == i )
421 IRQ_DELTA(package_index,j) = 0;
422 /* Determine the total count per processor per IRQ */
423 value_now = (unsigned long) kstat_cpu(i).irqs[j];
424
425 /* Determine the activity per processor per IRQ */
426 delta = value_now - LAST_CPU_IRQ(i,j);
427
428 /* Update last_cpu_irq[][] for the next time */
429 LAST_CPU_IRQ(i,j) = value_now;
430
431 /* Ignore IRQs whose rate is less than the clock */
432 if (delta < useful_load_threshold)
433 continue;
434 /* update the load for the processor or package total */
435 IRQ_DELTA(package_index,j) += delta;
436
437 /* Keep track of the higher numbered sibling as well */
438 if (i != package_index)
439 CPU_IRQ(i) += delta;
440 /*
441 * We have sibling A and sibling B in the package
442 *
443 * cpu_irq[A] = load for cpu A + load for cpu B
444 * cpu_irq[B] = load for cpu B
445 */
446 CPU_IRQ(package_index) += delta;
447 }
448 }
449 /* Find the least loaded processor package */
Andrew Morton394e3902006-03-23 03:01:05 -0800450 for_each_online_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 if (i != CPU_TO_PACKAGEINDEX(i))
452 continue;
453 if (min_cpu_irq > CPU_IRQ(i)) {
454 min_cpu_irq = CPU_IRQ(i);
455 min_loaded = i;
456 }
457 }
458 max_cpu_irq = ULONG_MAX;
459
460tryanothercpu:
461 /* Look for heaviest loaded processor.
462 * We may come back to get the next heaviest loaded processor.
463 * Skip processors with trivial loads.
464 */
465 tmp_cpu_irq = 0;
466 tmp_loaded = -1;
Andrew Morton394e3902006-03-23 03:01:05 -0800467 for_each_online_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (i != CPU_TO_PACKAGEINDEX(i))
469 continue;
470 if (max_cpu_irq <= CPU_IRQ(i))
471 continue;
472 if (tmp_cpu_irq < CPU_IRQ(i)) {
473 tmp_cpu_irq = CPU_IRQ(i);
474 tmp_loaded = i;
475 }
476 }
477
478 if (tmp_loaded == -1) {
479 /* In the case of small number of heavy interrupt sources,
480 * loading some of the cpus too much. We use Ingo's original
481 * approach to rotate them around.
482 */
483 if (!first_attempt && imbalance >= useful_load_threshold) {
484 rotate_irqs_among_cpus(useful_load_threshold);
485 return;
486 }
487 goto not_worth_the_effort;
488 }
489
490 first_attempt = 0; /* heaviest search */
491 max_cpu_irq = tmp_cpu_irq; /* load */
492 max_loaded = tmp_loaded; /* processor */
493 imbalance = (max_cpu_irq - min_cpu_irq) / 2;
494
495 Dprintk("max_loaded cpu = %d\n", max_loaded);
496 Dprintk("min_loaded cpu = %d\n", min_loaded);
497 Dprintk("max_cpu_irq load = %ld\n", max_cpu_irq);
498 Dprintk("min_cpu_irq load = %ld\n", min_cpu_irq);
499 Dprintk("load imbalance = %lu\n", imbalance);
500
501 /* if imbalance is less than approx 10% of max load, then
502 * observe diminishing returns action. - quit
503 */
504 if (imbalance < (max_cpu_irq >> 3)) {
505 Dprintk("Imbalance too trivial\n");
506 goto not_worth_the_effort;
507 }
508
509tryanotherirq:
510 /* if we select an IRQ to move that can't go where we want, then
511 * see if there is another one to try.
512 */
513 move_this_load = 0;
514 selected_irq = -1;
515 for (j = 0; j < NR_IRQS; j++) {
516 /* Is this an active IRQ? */
517 if (!irq_desc[j].action)
518 continue;
519 if (imbalance <= IRQ_DELTA(max_loaded,j))
520 continue;
521 /* Try to find the IRQ that is closest to the imbalance
522 * without going over.
523 */
524 if (move_this_load < IRQ_DELTA(max_loaded,j)) {
525 move_this_load = IRQ_DELTA(max_loaded,j);
526 selected_irq = j;
527 }
528 }
529 if (selected_irq == -1) {
530 goto tryanothercpu;
531 }
532
533 imbalance = move_this_load;
534
535 /* For physical_balance case, we accumlated both load
536 * values in the one of the siblings cpu_irq[],
537 * to use the same code for physical and logical processors
538 * as much as possible.
539 *
540 * NOTE: the cpu_irq[] array holds the sum of the load for
541 * sibling A and sibling B in the slot for the lowest numbered
542 * sibling (A), _AND_ the load for sibling B in the slot for
543 * the higher numbered sibling.
544 *
545 * We seek the least loaded sibling by making the comparison
546 * (A+B)/2 vs B
547 */
548 load = CPU_IRQ(min_loaded) >> 1;
549 for_each_cpu_mask(j, cpu_sibling_map[min_loaded]) {
550 if (load > CPU_IRQ(j)) {
551 /* This won't change cpu_sibling_map[min_loaded] */
552 load = CPU_IRQ(j);
553 min_loaded = j;
554 }
555 }
556
Zhang Yanmin1b61b912006-06-23 02:04:22 -0700557 cpus_and(allowed_mask,
558 cpu_online_map,
559 balance_irq_affinity[selected_irq]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 target_cpu_mask = cpumask_of_cpu(min_loaded);
561 cpus_and(tmp, target_cpu_mask, allowed_mask);
562
563 if (!cpus_empty(tmp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 Dprintk("irq = %d moved to cpu = %d\n",
566 selected_irq, min_loaded);
567 /* mark for change destination */
Ashok Raj54d5d422005-09-06 15:16:15 -0700568 set_pending_irq(selected_irq, cpumask_of_cpu(min_loaded));
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /* Since we made a change, come back sooner to
571 * check for more variation.
572 */
573 balanced_irq_interval = max((long)MIN_BALANCED_IRQ_INTERVAL,
574 balanced_irq_interval - BALANCED_IRQ_LESS_DELTA);
575 return;
576 }
577 goto tryanotherirq;
578
579not_worth_the_effort:
580 /*
581 * if we did not find an IRQ to move, then adjust the time interval
582 * upward
583 */
584 balanced_irq_interval = min((long)MAX_BALANCED_IRQ_INTERVAL,
585 balanced_irq_interval + BALANCED_IRQ_MORE_DELTA);
586 Dprintk("IRQ worth rotating not found\n");
587 return;
588}
589
590static int balanced_irq(void *unused)
591{
592 int i;
593 unsigned long prev_balance_time = jiffies;
594 long time_remaining = balanced_irq_interval;
595
596 daemonize("kirqd");
597
598 /* push everything to CPU 0 to give us a starting point. */
599 for (i = 0 ; i < NR_IRQS ; i++) {
Ingo Molnarcd916d32006-06-29 02:24:42 -0700600 irq_desc[i].pending_mask = cpumask_of_cpu(0);
Ashok Raj54d5d422005-09-06 15:16:15 -0700601 set_pending_irq(i, cpumask_of_cpu(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
603
604 for ( ; ; ) {
Nishanth Aravamudan52e6e632005-09-10 00:27:26 -0700605 time_remaining = schedule_timeout_interruptible(time_remaining);
Christoph Lameter3e1d1d22005-06-24 23:13:50 -0700606 try_to_freeze();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 if (time_after(jiffies,
608 prev_balance_time+balanced_irq_interval)) {
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700609 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 do_irq_balance();
611 prev_balance_time = jiffies;
612 time_remaining = balanced_irq_interval;
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700613 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615 }
616 return 0;
617}
618
619static int __init balanced_irq_init(void)
620{
621 int i;
622 struct cpuinfo_x86 *c;
623 cpumask_t tmp;
624
625 cpus_shift_right(tmp, cpu_online_map, 2);
626 c = &boot_cpu_data;
627 /* When not overwritten by the command line ask subarchitecture. */
628 if (irqbalance_disabled == IRQBALANCE_CHECK_ARCH)
629 irqbalance_disabled = NO_BALANCE_IRQ;
630 if (irqbalance_disabled)
631 return 0;
632
633 /* disable irqbalance completely if there is only one processor online */
634 if (num_online_cpus() < 2) {
635 irqbalance_disabled = 1;
636 return 0;
637 }
638 /*
639 * Enable physical balance only if more than 1 physical processor
640 * is present
641 */
642 if (smp_num_siblings > 1 && !cpus_empty(tmp))
643 physical_balance = 1;
644
Andrew Morton394e3902006-03-23 03:01:05 -0800645 for_each_online_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 irq_cpu_data[i].irq_delta = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
647 irq_cpu_data[i].last_irq = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
648 if (irq_cpu_data[i].irq_delta == NULL || irq_cpu_data[i].last_irq == NULL) {
649 printk(KERN_ERR "balanced_irq_init: out of memory");
650 goto failed;
651 }
652 memset(irq_cpu_data[i].irq_delta,0,sizeof(unsigned long) * NR_IRQS);
653 memset(irq_cpu_data[i].last_irq,0,sizeof(unsigned long) * NR_IRQS);
654 }
655
656 printk(KERN_INFO "Starting balanced_irq\n");
657 if (kernel_thread(balanced_irq, NULL, CLONE_KERNEL) >= 0)
658 return 0;
659 else
660 printk(KERN_ERR "balanced_irq_init: failed to spawn balanced_irq");
661failed:
KAMEZAWA Hiroyukic89125992006-03-28 01:56:39 -0800662 for_each_possible_cpu(i) {
Jesper Juhl4ae66732005-06-25 14:58:48 -0700663 kfree(irq_cpu_data[i].irq_delta);
Andrew Morton394e3902006-03-23 03:01:05 -0800664 irq_cpu_data[i].irq_delta = NULL;
Jesper Juhl4ae66732005-06-25 14:58:48 -0700665 kfree(irq_cpu_data[i].last_irq);
Andrew Morton394e3902006-03-23 03:01:05 -0800666 irq_cpu_data[i].last_irq = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
668 return 0;
669}
670
671int __init irqbalance_disable(char *str)
672{
673 irqbalance_disabled = 1;
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800674 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675}
676
677__setup("noirqbalance", irqbalance_disable);
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679late_initcall(balanced_irq_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#endif /* CONFIG_IRQBALANCE */
Ashok Raj54d5d422005-09-06 15:16:15 -0700681#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683#ifndef CONFIG_SMP
684void fastcall send_IPI_self(int vector)
685{
686 unsigned int cfg;
687
688 /*
689 * Wait for idle.
690 */
691 apic_wait_icr_idle();
692 cfg = APIC_DM_FIXED | APIC_DEST_SELF | vector | APIC_DEST_LOGICAL;
693 /*
694 * Send the IPI. The write to APIC_ICR fires this off.
695 */
696 apic_write_around(APIC_ICR, cfg);
697}
698#endif /* !CONFIG_SMP */
699
700
701/*
702 * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
703 * specific CPU-side IRQs.
704 */
705
706#define MAX_PIRQS 8
707static int pirq_entries [MAX_PIRQS];
708static int pirqs_enabled;
709int skip_ioapic_setup;
710
711static int __init ioapic_setup(char *str)
712{
713 skip_ioapic_setup = 1;
714 return 1;
715}
716
717__setup("noapic", ioapic_setup);
718
719static int __init ioapic_pirq_setup(char *str)
720{
721 int i, max;
722 int ints[MAX_PIRQS+1];
723
724 get_options(str, ARRAY_SIZE(ints), ints);
725
726 for (i = 0; i < MAX_PIRQS; i++)
727 pirq_entries[i] = -1;
728
729 pirqs_enabled = 1;
730 apic_printk(APIC_VERBOSE, KERN_INFO
731 "PIRQ redirection, working around broken MP-BIOS.\n");
732 max = MAX_PIRQS;
733 if (ints[0] < MAX_PIRQS)
734 max = ints[0];
735
736 for (i = 0; i < max; i++) {
737 apic_printk(APIC_VERBOSE, KERN_DEBUG
738 "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
739 /*
740 * PIRQs are mapped upside down, usually.
741 */
742 pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
743 }
744 return 1;
745}
746
747__setup("pirq=", ioapic_pirq_setup);
748
749/*
750 * Find the IRQ entry number of a certain pin.
751 */
752static int find_irq_entry(int apic, int pin, int type)
753{
754 int i;
755
756 for (i = 0; i < mp_irq_entries; i++)
757 if (mp_irqs[i].mpc_irqtype == type &&
758 (mp_irqs[i].mpc_dstapic == mp_ioapics[apic].mpc_apicid ||
759 mp_irqs[i].mpc_dstapic == MP_APIC_ALL) &&
760 mp_irqs[i].mpc_dstirq == pin)
761 return i;
762
763 return -1;
764}
765
766/*
767 * Find the pin to which IRQ[irq] (ISA) is connected
768 */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -0800769static int __init find_isa_irq_pin(int irq, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
771 int i;
772
773 for (i = 0; i < mp_irq_entries; i++) {
774 int lbus = mp_irqs[i].mpc_srcbus;
775
776 if ((mp_bus_id_to_type[lbus] == MP_BUS_ISA ||
777 mp_bus_id_to_type[lbus] == MP_BUS_EISA ||
778 mp_bus_id_to_type[lbus] == MP_BUS_MCA ||
779 mp_bus_id_to_type[lbus] == MP_BUS_NEC98
780 ) &&
781 (mp_irqs[i].mpc_irqtype == type) &&
782 (mp_irqs[i].mpc_srcbusirq == irq))
783
784 return mp_irqs[i].mpc_dstirq;
785 }
786 return -1;
787}
788
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -0800789static int __init find_isa_irq_apic(int irq, int type)
790{
791 int i;
792
793 for (i = 0; i < mp_irq_entries; i++) {
794 int lbus = mp_irqs[i].mpc_srcbus;
795
796 if ((mp_bus_id_to_type[lbus] == MP_BUS_ISA ||
797 mp_bus_id_to_type[lbus] == MP_BUS_EISA ||
798 mp_bus_id_to_type[lbus] == MP_BUS_MCA ||
799 mp_bus_id_to_type[lbus] == MP_BUS_NEC98
800 ) &&
801 (mp_irqs[i].mpc_irqtype == type) &&
802 (mp_irqs[i].mpc_srcbusirq == irq))
803 break;
804 }
805 if (i < mp_irq_entries) {
806 int apic;
807 for(apic = 0; apic < nr_ioapics; apic++) {
808 if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic)
809 return apic;
810 }
811 }
812
813 return -1;
814}
815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816/*
817 * Find a specific PCI IRQ entry.
818 * Not an __init, possibly needed by modules
819 */
820static int pin_2_irq(int idx, int apic, int pin);
821
822int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
823{
824 int apic, i, best_guess = -1;
825
826 apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, "
827 "slot:%d, pin:%d.\n", bus, slot, pin);
828 if (mp_bus_id_to_pci_bus[bus] == -1) {
829 printk(KERN_WARNING "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
830 return -1;
831 }
832 for (i = 0; i < mp_irq_entries; i++) {
833 int lbus = mp_irqs[i].mpc_srcbus;
834
835 for (apic = 0; apic < nr_ioapics; apic++)
836 if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic ||
837 mp_irqs[i].mpc_dstapic == MP_APIC_ALL)
838 break;
839
840 if ((mp_bus_id_to_type[lbus] == MP_BUS_PCI) &&
841 !mp_irqs[i].mpc_irqtype &&
842 (bus == lbus) &&
843 (slot == ((mp_irqs[i].mpc_srcbusirq >> 2) & 0x1f))) {
844 int irq = pin_2_irq(i,apic,mp_irqs[i].mpc_dstirq);
845
846 if (!(apic || IO_APIC_IRQ(irq)))
847 continue;
848
849 if (pin == (mp_irqs[i].mpc_srcbusirq & 3))
850 return irq;
851 /*
852 * Use the first all-but-pin matching entry as a
853 * best-guess fuzzy result for broken mptables.
854 */
855 if (best_guess < 0)
856 best_guess = irq;
857 }
858 }
859 return best_guess;
860}
Alexey Dobriyan129f6942005-06-23 00:08:33 -0700861EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863/*
864 * This function currently is only a helper for the i386 smp boot process where
865 * we need to reprogram the ioredtbls to cater for the cpus which have come online
866 * so mask in all cases should simply be TARGET_CPUS
867 */
Ashok Raj54d5d422005-09-06 15:16:15 -0700868#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869void __init setup_ioapic_dest(void)
870{
871 int pin, ioapic, irq, irq_entry;
872
873 if (skip_ioapic_setup == 1)
874 return;
875
876 for (ioapic = 0; ioapic < nr_ioapics; ioapic++) {
877 for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
878 irq_entry = find_irq_entry(ioapic, pin, mp_INT);
879 if (irq_entry == -1)
880 continue;
881 irq = pin_2_irq(irq_entry, ioapic, pin);
882 set_ioapic_affinity_irq(irq, TARGET_CPUS);
883 }
884
885 }
886}
Ashok Raj54d5d422005-09-06 15:16:15 -0700887#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889/*
890 * EISA Edge/Level control register, ELCR
891 */
892static int EISA_ELCR(unsigned int irq)
893{
894 if (irq < 16) {
895 unsigned int port = 0x4d0 + (irq >> 3);
896 return (inb(port) >> (irq & 7)) & 1;
897 }
898 apic_printk(APIC_VERBOSE, KERN_INFO
899 "Broken MPtable reports ISA irq %d\n", irq);
900 return 0;
901}
902
903/* EISA interrupts are always polarity zero and can be edge or level
904 * trigger depending on the ELCR value. If an interrupt is listed as
905 * EISA conforming in the MP table, that means its trigger type must
906 * be read in from the ELCR */
907
908#define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].mpc_srcbusirq))
909#define default_EISA_polarity(idx) (0)
910
911/* ISA interrupts are always polarity zero edge triggered,
912 * when listed as conforming in the MP table. */
913
914#define default_ISA_trigger(idx) (0)
915#define default_ISA_polarity(idx) (0)
916
917/* PCI interrupts are always polarity one level triggered,
918 * when listed as conforming in the MP table. */
919
920#define default_PCI_trigger(idx) (1)
921#define default_PCI_polarity(idx) (1)
922
923/* MCA interrupts are always polarity zero level triggered,
924 * when listed as conforming in the MP table. */
925
926#define default_MCA_trigger(idx) (1)
927#define default_MCA_polarity(idx) (0)
928
929/* NEC98 interrupts are always polarity zero edge triggered,
930 * when listed as conforming in the MP table. */
931
932#define default_NEC98_trigger(idx) (0)
933#define default_NEC98_polarity(idx) (0)
934
935static int __init MPBIOS_polarity(int idx)
936{
937 int bus = mp_irqs[idx].mpc_srcbus;
938 int polarity;
939
940 /*
941 * Determine IRQ line polarity (high active or low active):
942 */
943 switch (mp_irqs[idx].mpc_irqflag & 3)
944 {
945 case 0: /* conforms, ie. bus-type dependent polarity */
946 {
947 switch (mp_bus_id_to_type[bus])
948 {
949 case MP_BUS_ISA: /* ISA pin */
950 {
951 polarity = default_ISA_polarity(idx);
952 break;
953 }
954 case MP_BUS_EISA: /* EISA pin */
955 {
956 polarity = default_EISA_polarity(idx);
957 break;
958 }
959 case MP_BUS_PCI: /* PCI pin */
960 {
961 polarity = default_PCI_polarity(idx);
962 break;
963 }
964 case MP_BUS_MCA: /* MCA pin */
965 {
966 polarity = default_MCA_polarity(idx);
967 break;
968 }
969 case MP_BUS_NEC98: /* NEC 98 pin */
970 {
971 polarity = default_NEC98_polarity(idx);
972 break;
973 }
974 default:
975 {
976 printk(KERN_WARNING "broken BIOS!!\n");
977 polarity = 1;
978 break;
979 }
980 }
981 break;
982 }
983 case 1: /* high active */
984 {
985 polarity = 0;
986 break;
987 }
988 case 2: /* reserved */
989 {
990 printk(KERN_WARNING "broken BIOS!!\n");
991 polarity = 1;
992 break;
993 }
994 case 3: /* low active */
995 {
996 polarity = 1;
997 break;
998 }
999 default: /* invalid */
1000 {
1001 printk(KERN_WARNING "broken BIOS!!\n");
1002 polarity = 1;
1003 break;
1004 }
1005 }
1006 return polarity;
1007}
1008
1009static int MPBIOS_trigger(int idx)
1010{
1011 int bus = mp_irqs[idx].mpc_srcbus;
1012 int trigger;
1013
1014 /*
1015 * Determine IRQ trigger mode (edge or level sensitive):
1016 */
1017 switch ((mp_irqs[idx].mpc_irqflag>>2) & 3)
1018 {
1019 case 0: /* conforms, ie. bus-type dependent */
1020 {
1021 switch (mp_bus_id_to_type[bus])
1022 {
1023 case MP_BUS_ISA: /* ISA pin */
1024 {
1025 trigger = default_ISA_trigger(idx);
1026 break;
1027 }
1028 case MP_BUS_EISA: /* EISA pin */
1029 {
1030 trigger = default_EISA_trigger(idx);
1031 break;
1032 }
1033 case MP_BUS_PCI: /* PCI pin */
1034 {
1035 trigger = default_PCI_trigger(idx);
1036 break;
1037 }
1038 case MP_BUS_MCA: /* MCA pin */
1039 {
1040 trigger = default_MCA_trigger(idx);
1041 break;
1042 }
1043 case MP_BUS_NEC98: /* NEC 98 pin */
1044 {
1045 trigger = default_NEC98_trigger(idx);
1046 break;
1047 }
1048 default:
1049 {
1050 printk(KERN_WARNING "broken BIOS!!\n");
1051 trigger = 1;
1052 break;
1053 }
1054 }
1055 break;
1056 }
1057 case 1: /* edge */
1058 {
1059 trigger = 0;
1060 break;
1061 }
1062 case 2: /* reserved */
1063 {
1064 printk(KERN_WARNING "broken BIOS!!\n");
1065 trigger = 1;
1066 break;
1067 }
1068 case 3: /* level */
1069 {
1070 trigger = 1;
1071 break;
1072 }
1073 default: /* invalid */
1074 {
1075 printk(KERN_WARNING "broken BIOS!!\n");
1076 trigger = 0;
1077 break;
1078 }
1079 }
1080 return trigger;
1081}
1082
1083static inline int irq_polarity(int idx)
1084{
1085 return MPBIOS_polarity(idx);
1086}
1087
1088static inline int irq_trigger(int idx)
1089{
1090 return MPBIOS_trigger(idx);
1091}
1092
1093static int pin_2_irq(int idx, int apic, int pin)
1094{
1095 int irq, i;
1096 int bus = mp_irqs[idx].mpc_srcbus;
1097
1098 /*
1099 * Debugging check, we are in big trouble if this message pops up!
1100 */
1101 if (mp_irqs[idx].mpc_dstirq != pin)
1102 printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
1103
1104 switch (mp_bus_id_to_type[bus])
1105 {
1106 case MP_BUS_ISA: /* ISA pin */
1107 case MP_BUS_EISA:
1108 case MP_BUS_MCA:
1109 case MP_BUS_NEC98:
1110 {
1111 irq = mp_irqs[idx].mpc_srcbusirq;
1112 break;
1113 }
1114 case MP_BUS_PCI: /* PCI pin */
1115 {
1116 /*
1117 * PCI IRQs are mapped in order
1118 */
1119 i = irq = 0;
1120 while (i < apic)
1121 irq += nr_ioapic_registers[i++];
1122 irq += pin;
1123
1124 /*
1125 * For MPS mode, so far only needed by ES7000 platform
1126 */
1127 if (ioapic_renumber_irq)
1128 irq = ioapic_renumber_irq(apic, irq);
1129
1130 break;
1131 }
1132 default:
1133 {
1134 printk(KERN_ERR "unknown bus type %d.\n",bus);
1135 irq = 0;
1136 break;
1137 }
1138 }
1139
1140 /*
1141 * PCI IRQ command line redirection. Yes, limits are hardcoded.
1142 */
1143 if ((pin >= 16) && (pin <= 23)) {
1144 if (pirq_entries[pin-16] != -1) {
1145 if (!pirq_entries[pin-16]) {
1146 apic_printk(APIC_VERBOSE, KERN_DEBUG
1147 "disabling PIRQ%d\n", pin-16);
1148 } else {
1149 irq = pirq_entries[pin-16];
1150 apic_printk(APIC_VERBOSE, KERN_DEBUG
1151 "using PIRQ%d -> IRQ %d\n",
1152 pin-16, irq);
1153 }
1154 }
1155 }
1156 return irq;
1157}
1158
1159static inline int IO_APIC_irq_trigger(int irq)
1160{
1161 int apic, idx, pin;
1162
1163 for (apic = 0; apic < nr_ioapics; apic++) {
1164 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1165 idx = find_irq_entry(apic,pin,mp_INT);
1166 if ((idx != -1) && (irq == pin_2_irq(idx,apic,pin)))
1167 return irq_trigger(idx);
1168 }
1169 }
1170 /*
1171 * nonexistent IRQs are edge default
1172 */
1173 return 0;
1174}
1175
1176/* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */
Ravikiran G Thirumalai6c231b72005-09-06 15:17:45 -07001177u8 irq_vector[NR_IRQ_VECTORS] __read_mostly = { FIRST_DEVICE_VECTOR , 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001179static int __assign_irq_vector(int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
1181 static int current_vector = FIRST_DEVICE_VECTOR, offset = 0;
Jan Beulich0a1ad602006-06-26 13:56:43 +02001182 int vector;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001184 BUG_ON((unsigned)irq >= NR_IRQ_VECTORS);
Jan Beulich0a1ad602006-06-26 13:56:43 +02001185
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001186 if (IO_APIC_VECTOR(irq) > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 return IO_APIC_VECTOR(irq);
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 current_vector += 8;
1190 if (current_vector == SYSCALL_VECTOR)
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001191 current_vector += 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
1193 if (current_vector >= FIRST_SYSTEM_VECTOR) {
1194 offset++;
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001195 if (!(offset % 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 return -ENOSPC;
1197 current_vector = FIRST_DEVICE_VECTOR + offset;
1198 }
1199
Jan Beulich0a1ad602006-06-26 13:56:43 +02001200 vector = current_vector;
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001201 IO_APIC_VECTOR(irq) = vector;
Jan Beulich0a1ad602006-06-26 13:56:43 +02001202
1203 return vector;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204}
1205
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001206static int assign_irq_vector(int irq)
1207{
1208 unsigned long flags;
1209 int vector;
1210
1211 spin_lock_irqsave(&vector_lock, flags);
1212 vector = __assign_irq_vector(irq);
1213 spin_unlock_irqrestore(&vector_lock, flags);
1214
1215 return vector;
1216}
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001217static struct irq_chip ioapic_chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219#define IOAPIC_AUTO -1
1220#define IOAPIC_EDGE 0
1221#define IOAPIC_LEVEL 1
1222
Ingo Molnard1bef4e2006-06-29 02:24:36 -07001223static void ioapic_register_intr(int irq, int vector, unsigned long trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
Jan Beulich6ebcc002006-06-26 13:56:46 +02001225 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1226 trigger == IOAPIC_LEVEL)
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001227 set_irq_chip_and_handler(irq, &ioapic_chip,
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001228 handle_fasteoi_irq);
Jan Beulich6ebcc002006-06-26 13:56:46 +02001229 else
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001230 set_irq_chip_and_handler(irq, &ioapic_chip,
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001231 handle_edge_irq);
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001232 set_intr_gate(vector, interrupt[irq]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
1235static void __init setup_IO_APIC_irqs(void)
1236{
1237 struct IO_APIC_route_entry entry;
1238 int apic, pin, idx, irq, first_notcon = 1, vector;
1239 unsigned long flags;
1240
1241 apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
1242
1243 for (apic = 0; apic < nr_ioapics; apic++) {
1244 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1245
1246 /*
1247 * add it to the IO-APIC irq-routing table:
1248 */
1249 memset(&entry,0,sizeof(entry));
1250
1251 entry.delivery_mode = INT_DELIVERY_MODE;
1252 entry.dest_mode = INT_DEST_MODE;
1253 entry.mask = 0; /* enable IRQ */
1254 entry.dest.logical.logical_dest =
1255 cpu_mask_to_apicid(TARGET_CPUS);
1256
1257 idx = find_irq_entry(apic,pin,mp_INT);
1258 if (idx == -1) {
1259 if (first_notcon) {
1260 apic_printk(APIC_VERBOSE, KERN_DEBUG
1261 " IO-APIC (apicid-pin) %d-%d",
1262 mp_ioapics[apic].mpc_apicid,
1263 pin);
1264 first_notcon = 0;
1265 } else
1266 apic_printk(APIC_VERBOSE, ", %d-%d",
1267 mp_ioapics[apic].mpc_apicid, pin);
1268 continue;
1269 }
1270
1271 entry.trigger = irq_trigger(idx);
1272 entry.polarity = irq_polarity(idx);
1273
1274 if (irq_trigger(idx)) {
1275 entry.trigger = 1;
1276 entry.mask = 1;
1277 }
1278
1279 irq = pin_2_irq(idx, apic, pin);
1280 /*
1281 * skip adding the timer int on secondary nodes, which causes
1282 * a small but painful rift in the time-space continuum
1283 */
1284 if (multi_timer_check(apic, irq))
1285 continue;
1286 else
1287 add_pin_to_irq(irq, apic, pin);
1288
1289 if (!apic && !IO_APIC_IRQ(irq))
1290 continue;
1291
1292 if (IO_APIC_IRQ(irq)) {
1293 vector = assign_irq_vector(irq);
1294 entry.vector = vector;
1295 ioapic_register_intr(irq, vector, IOAPIC_AUTO);
1296
1297 if (!apic && (irq < 16))
1298 disable_8259A_irq(irq);
1299 }
Andi Kleencf4c6a22006-09-26 10:52:30 +02001300 ioapic_write_entry(apic, pin, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 spin_lock_irqsave(&ioapic_lock, flags);
Ashok Raj54d5d422005-09-06 15:16:15 -07001302 set_native_irq_info(irq, TARGET_CPUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 spin_unlock_irqrestore(&ioapic_lock, flags);
1304 }
1305 }
1306
1307 if (!first_notcon)
1308 apic_printk(APIC_VERBOSE, " not connected.\n");
1309}
1310
1311/*
1312 * Set up the 8259A-master output pin:
1313 */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001314static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, int vector)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
1316 struct IO_APIC_route_entry entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 memset(&entry,0,sizeof(entry));
1319
1320 disable_8259A_irq(0);
1321
1322 /* mask LVT0 */
1323 apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
1324
1325 /*
1326 * We use logical delivery to get the timer IRQ
1327 * to the first CPU.
1328 */
1329 entry.dest_mode = INT_DEST_MODE;
1330 entry.mask = 0; /* unmask IRQ now */
1331 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
1332 entry.delivery_mode = INT_DELIVERY_MODE;
1333 entry.polarity = 0;
1334 entry.trigger = 0;
1335 entry.vector = vector;
1336
1337 /*
1338 * The timer IRQ doesn't have to know that behind the
1339 * scene we have a 8259A-master in AEOI mode ...
1340 */
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001341 irq_desc[0].chip = &ioapic_chip;
1342 set_irq_handler(0, handle_edge_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 /*
1345 * Add it to the IO-APIC irq-routing table:
1346 */
Andi Kleencf4c6a22006-09-26 10:52:30 +02001347 ioapic_write_entry(apic, pin, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349 enable_8259A_irq(0);
1350}
1351
1352static inline void UNEXPECTED_IO_APIC(void)
1353{
1354}
1355
1356void __init print_IO_APIC(void)
1357{
1358 int apic, i;
1359 union IO_APIC_reg_00 reg_00;
1360 union IO_APIC_reg_01 reg_01;
1361 union IO_APIC_reg_02 reg_02;
1362 union IO_APIC_reg_03 reg_03;
1363 unsigned long flags;
1364
1365 if (apic_verbosity == APIC_QUIET)
1366 return;
1367
1368 printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
1369 for (i = 0; i < nr_ioapics; i++)
1370 printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
1371 mp_ioapics[i].mpc_apicid, nr_ioapic_registers[i]);
1372
1373 /*
1374 * We are a bit conservative about what we expect. We have to
1375 * know about every hardware change ASAP.
1376 */
1377 printk(KERN_INFO "testing the IO APIC.......................\n");
1378
1379 for (apic = 0; apic < nr_ioapics; apic++) {
1380
1381 spin_lock_irqsave(&ioapic_lock, flags);
1382 reg_00.raw = io_apic_read(apic, 0);
1383 reg_01.raw = io_apic_read(apic, 1);
1384 if (reg_01.bits.version >= 0x10)
1385 reg_02.raw = io_apic_read(apic, 2);
1386 if (reg_01.bits.version >= 0x20)
1387 reg_03.raw = io_apic_read(apic, 3);
1388 spin_unlock_irqrestore(&ioapic_lock, flags);
1389
1390 printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mpc_apicid);
1391 printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
1392 printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
1393 printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
1394 printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
1395 if (reg_00.bits.ID >= get_physical_broadcast())
1396 UNEXPECTED_IO_APIC();
1397 if (reg_00.bits.__reserved_1 || reg_00.bits.__reserved_2)
1398 UNEXPECTED_IO_APIC();
1399
1400 printk(KERN_DEBUG ".... register #01: %08X\n", reg_01.raw);
1401 printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
1402 if ( (reg_01.bits.entries != 0x0f) && /* older (Neptune) boards */
1403 (reg_01.bits.entries != 0x17) && /* typical ISA+PCI boards */
1404 (reg_01.bits.entries != 0x1b) && /* Compaq Proliant boards */
1405 (reg_01.bits.entries != 0x1f) && /* dual Xeon boards */
1406 (reg_01.bits.entries != 0x22) && /* bigger Xeon boards */
1407 (reg_01.bits.entries != 0x2E) &&
1408 (reg_01.bits.entries != 0x3F)
1409 )
1410 UNEXPECTED_IO_APIC();
1411
1412 printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
1413 printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
1414 if ( (reg_01.bits.version != 0x01) && /* 82489DX IO-APICs */
1415 (reg_01.bits.version != 0x10) && /* oldest IO-APICs */
1416 (reg_01.bits.version != 0x11) && /* Pentium/Pro IO-APICs */
1417 (reg_01.bits.version != 0x13) && /* Xeon IO-APICs */
1418 (reg_01.bits.version != 0x20) /* Intel P64H (82806 AA) */
1419 )
1420 UNEXPECTED_IO_APIC();
1421 if (reg_01.bits.__reserved_1 || reg_01.bits.__reserved_2)
1422 UNEXPECTED_IO_APIC();
1423
1424 /*
1425 * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
1426 * but the value of reg_02 is read as the previous read register
1427 * value, so ignore it if reg_02 == reg_01.
1428 */
1429 if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
1430 printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
1431 printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
1432 if (reg_02.bits.__reserved_1 || reg_02.bits.__reserved_2)
1433 UNEXPECTED_IO_APIC();
1434 }
1435
1436 /*
1437 * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
1438 * or reg_03, but the value of reg_0[23] is read as the previous read
1439 * register value, so ignore it if reg_03 == reg_0[12].
1440 */
1441 if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
1442 reg_03.raw != reg_01.raw) {
1443 printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
1444 printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
1445 if (reg_03.bits.__reserved_1)
1446 UNEXPECTED_IO_APIC();
1447 }
1448
1449 printk(KERN_DEBUG ".... IRQ redirection table:\n");
1450
1451 printk(KERN_DEBUG " NR Log Phy Mask Trig IRR Pol"
1452 " Stat Dest Deli Vect: \n");
1453
1454 for (i = 0; i <= reg_01.bits.entries; i++) {
1455 struct IO_APIC_route_entry entry;
1456
Andi Kleencf4c6a22006-09-26 10:52:30 +02001457 entry = ioapic_read_entry(apic, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
1459 printk(KERN_DEBUG " %02x %03X %02X ",
1460 i,
1461 entry.dest.logical.logical_dest,
1462 entry.dest.physical.physical_dest
1463 );
1464
1465 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
1466 entry.mask,
1467 entry.trigger,
1468 entry.irr,
1469 entry.polarity,
1470 entry.delivery_status,
1471 entry.dest_mode,
1472 entry.delivery_mode,
1473 entry.vector
1474 );
1475 }
1476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 printk(KERN_DEBUG "IRQ to pin mappings:\n");
1478 for (i = 0; i < NR_IRQS; i++) {
1479 struct irq_pin_list *entry = irq_2_pin + i;
1480 if (entry->pin < 0)
1481 continue;
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001482 printk(KERN_DEBUG "IRQ%d ", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 for (;;) {
1484 printk("-> %d:%d", entry->apic, entry->pin);
1485 if (!entry->next)
1486 break;
1487 entry = irq_2_pin + entry->next;
1488 }
1489 printk("\n");
1490 }
1491
1492 printk(KERN_INFO ".................................... done.\n");
1493
1494 return;
1495}
1496
1497#if 0
1498
1499static void print_APIC_bitfield (int base)
1500{
1501 unsigned int v;
1502 int i, j;
1503
1504 if (apic_verbosity == APIC_QUIET)
1505 return;
1506
1507 printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG);
1508 for (i = 0; i < 8; i++) {
1509 v = apic_read(base + i*0x10);
1510 for (j = 0; j < 32; j++) {
1511 if (v & (1<<j))
1512 printk("1");
1513 else
1514 printk("0");
1515 }
1516 printk("\n");
1517 }
1518}
1519
1520void /*__init*/ print_local_APIC(void * dummy)
1521{
1522 unsigned int v, ver, maxlvt;
1523
1524 if (apic_verbosity == APIC_QUIET)
1525 return;
1526
1527 printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
1528 smp_processor_id(), hard_smp_processor_id());
1529 v = apic_read(APIC_ID);
1530 printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, GET_APIC_ID(v));
1531 v = apic_read(APIC_LVR);
1532 printk(KERN_INFO "... APIC VERSION: %08x\n", v);
1533 ver = GET_APIC_VERSION(v);
1534 maxlvt = get_maxlvt();
1535
1536 v = apic_read(APIC_TASKPRI);
1537 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
1538
1539 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1540 v = apic_read(APIC_ARBPRI);
1541 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
1542 v & APIC_ARBPRI_MASK);
1543 v = apic_read(APIC_PROCPRI);
1544 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
1545 }
1546
1547 v = apic_read(APIC_EOI);
1548 printk(KERN_DEBUG "... APIC EOI: %08x\n", v);
1549 v = apic_read(APIC_RRR);
1550 printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
1551 v = apic_read(APIC_LDR);
1552 printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
1553 v = apic_read(APIC_DFR);
1554 printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
1555 v = apic_read(APIC_SPIV);
1556 printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
1557
1558 printk(KERN_DEBUG "... APIC ISR field:\n");
1559 print_APIC_bitfield(APIC_ISR);
1560 printk(KERN_DEBUG "... APIC TMR field:\n");
1561 print_APIC_bitfield(APIC_TMR);
1562 printk(KERN_DEBUG "... APIC IRR field:\n");
1563 print_APIC_bitfield(APIC_IRR);
1564
1565 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1566 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
1567 apic_write(APIC_ESR, 0);
1568 v = apic_read(APIC_ESR);
1569 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
1570 }
1571
1572 v = apic_read(APIC_ICR);
1573 printk(KERN_DEBUG "... APIC ICR: %08x\n", v);
1574 v = apic_read(APIC_ICR2);
1575 printk(KERN_DEBUG "... APIC ICR2: %08x\n", v);
1576
1577 v = apic_read(APIC_LVTT);
1578 printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
1579
1580 if (maxlvt > 3) { /* PC is LVT#4. */
1581 v = apic_read(APIC_LVTPC);
1582 printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
1583 }
1584 v = apic_read(APIC_LVT0);
1585 printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
1586 v = apic_read(APIC_LVT1);
1587 printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
1588
1589 if (maxlvt > 2) { /* ERR is LVT#3. */
1590 v = apic_read(APIC_LVTERR);
1591 printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
1592 }
1593
1594 v = apic_read(APIC_TMICT);
1595 printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
1596 v = apic_read(APIC_TMCCT);
1597 printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
1598 v = apic_read(APIC_TDCR);
1599 printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
1600 printk("\n");
1601}
1602
1603void print_all_local_APICs (void)
1604{
1605 on_each_cpu(print_local_APIC, NULL, 1, 1);
1606}
1607
1608void /*__init*/ print_PIC(void)
1609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 unsigned int v;
1611 unsigned long flags;
1612
1613 if (apic_verbosity == APIC_QUIET)
1614 return;
1615
1616 printk(KERN_DEBUG "\nprinting PIC contents\n");
1617
1618 spin_lock_irqsave(&i8259A_lock, flags);
1619
1620 v = inb(0xa1) << 8 | inb(0x21);
1621 printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
1622
1623 v = inb(0xa0) << 8 | inb(0x20);
1624 printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
1625
1626 outb(0x0b,0xa0);
1627 outb(0x0b,0x20);
1628 v = inb(0xa0) << 8 | inb(0x20);
1629 outb(0x0a,0xa0);
1630 outb(0x0a,0x20);
1631
1632 spin_unlock_irqrestore(&i8259A_lock, flags);
1633
1634 printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
1635
1636 v = inb(0x4d1) << 8 | inb(0x4d0);
1637 printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
1638}
1639
1640#endif /* 0 */
1641
1642static void __init enable_IO_APIC(void)
1643{
1644 union IO_APIC_reg_01 reg_01;
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001645 int i8259_apic, i8259_pin;
1646 int i, apic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 unsigned long flags;
1648
1649 for (i = 0; i < PIN_MAP_SIZE; i++) {
1650 irq_2_pin[i].pin = -1;
1651 irq_2_pin[i].next = 0;
1652 }
1653 if (!pirqs_enabled)
1654 for (i = 0; i < MAX_PIRQS; i++)
1655 pirq_entries[i] = -1;
1656
1657 /*
1658 * The number of IO-APIC IRQ registers (== #pins):
1659 */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001660 for (apic = 0; apic < nr_ioapics; apic++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 spin_lock_irqsave(&ioapic_lock, flags);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001662 reg_01.raw = io_apic_read(apic, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 spin_unlock_irqrestore(&ioapic_lock, flags);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001664 nr_ioapic_registers[apic] = reg_01.bits.entries+1;
1665 }
1666 for(apic = 0; apic < nr_ioapics; apic++) {
1667 int pin;
1668 /* See if any of the pins is in ExtINT mode */
Eric W. Biederman1008fdd2006-01-11 22:46:06 +01001669 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001670 struct IO_APIC_route_entry entry;
Andi Kleencf4c6a22006-09-26 10:52:30 +02001671 entry = ioapic_read_entry(apic, pin);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001672
1673
1674 /* If the interrupt line is enabled and in ExtInt mode
1675 * I have found the pin where the i8259 is connected.
1676 */
1677 if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
1678 ioapic_i8259.apic = apic;
1679 ioapic_i8259.pin = pin;
1680 goto found_i8259;
1681 }
1682 }
1683 }
1684 found_i8259:
1685 /* Look to see what if the MP table has reported the ExtINT */
1686 /* If we could not find the appropriate pin by looking at the ioapic
1687 * the i8259 probably is not connected the ioapic but give the
1688 * mptable a chance anyway.
1689 */
1690 i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
1691 i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
1692 /* Trust the MP table if nothing is setup in the hardware */
1693 if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
1694 printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
1695 ioapic_i8259.pin = i8259_pin;
1696 ioapic_i8259.apic = i8259_apic;
1697 }
1698 /* Complain if the MP table and the hardware disagree */
1699 if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
1700 (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
1701 {
1702 printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
1704
1705 /*
1706 * Do not trust the IO-APIC being empty at bootup
1707 */
1708 clear_IO_APIC();
1709}
1710
1711/*
1712 * Not an __init, needed by the reboot code
1713 */
1714void disable_IO_APIC(void)
1715{
1716 /*
1717 * Clear the IO-APIC before rebooting:
1718 */
1719 clear_IO_APIC();
1720
Eric W. Biederman650927e2005-06-25 14:57:44 -07001721 /*
Karsten Wiese0b968d22005-09-09 12:59:04 +02001722 * If the i8259 is routed through an IOAPIC
Eric W. Biederman650927e2005-06-25 14:57:44 -07001723 * Put that IOAPIC in virtual wire mode
Karsten Wiese0b968d22005-09-09 12:59:04 +02001724 * so legacy interrupts can be delivered.
Eric W. Biederman650927e2005-06-25 14:57:44 -07001725 */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001726 if (ioapic_i8259.pin != -1) {
Eric W. Biederman650927e2005-06-25 14:57:44 -07001727 struct IO_APIC_route_entry entry;
Eric W. Biederman650927e2005-06-25 14:57:44 -07001728
1729 memset(&entry, 0, sizeof(entry));
1730 entry.mask = 0; /* Enabled */
1731 entry.trigger = 0; /* Edge */
1732 entry.irr = 0;
1733 entry.polarity = 0; /* High */
1734 entry.delivery_status = 0;
1735 entry.dest_mode = 0; /* Physical */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001736 entry.delivery_mode = dest_ExtINT; /* ExtInt */
Eric W. Biederman650927e2005-06-25 14:57:44 -07001737 entry.vector = 0;
Vivek Goyal76865c32006-01-06 00:12:19 -08001738 entry.dest.physical.physical_dest =
1739 GET_APIC_ID(apic_read(APIC_ID));
Eric W. Biederman650927e2005-06-25 14:57:44 -07001740
1741 /*
1742 * Add it to the IO-APIC irq-routing table:
1743 */
Andi Kleencf4c6a22006-09-26 10:52:30 +02001744 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
Eric W. Biederman650927e2005-06-25 14:57:44 -07001745 }
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001746 disconnect_bsp_APIC(ioapic_i8259.pin != -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
1748
1749/*
1750 * function to set the IO-APIC physical IDs based on the
1751 * values stored in the MPC table.
1752 *
1753 * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
1754 */
1755
1756#ifndef CONFIG_X86_NUMAQ
1757static void __init setup_ioapic_ids_from_mpc(void)
1758{
1759 union IO_APIC_reg_00 reg_00;
1760 physid_mask_t phys_id_present_map;
1761 int apic;
1762 int i;
1763 unsigned char old_id;
1764 unsigned long flags;
1765
1766 /*
Natalie Protasevichca05fea2005-06-23 00:08:22 -07001767 * Don't check I/O APIC IDs for xAPIC systems. They have
1768 * no meaning without the serial APIC bus.
1769 */
Shaohua Li7c5c1e42006-03-23 02:59:53 -08001770 if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
1771 || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
Natalie Protasevichca05fea2005-06-23 00:08:22 -07001772 return;
1773 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 * This is broken; anything with a real cpu count has to
1775 * circumvent this idiocy regardless.
1776 */
1777 phys_id_present_map = ioapic_phys_id_map(phys_cpu_present_map);
1778
1779 /*
1780 * Set the IOAPIC ID to the value stored in the MPC table.
1781 */
1782 for (apic = 0; apic < nr_ioapics; apic++) {
1783
1784 /* Read the register 0 value */
1785 spin_lock_irqsave(&ioapic_lock, flags);
1786 reg_00.raw = io_apic_read(apic, 0);
1787 spin_unlock_irqrestore(&ioapic_lock, flags);
1788
1789 old_id = mp_ioapics[apic].mpc_apicid;
1790
1791 if (mp_ioapics[apic].mpc_apicid >= get_physical_broadcast()) {
1792 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
1793 apic, mp_ioapics[apic].mpc_apicid);
1794 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
1795 reg_00.bits.ID);
1796 mp_ioapics[apic].mpc_apicid = reg_00.bits.ID;
1797 }
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 /*
1800 * Sanity check, is the ID really free? Every APIC in a
1801 * system must have a unique ID or we get lots of nice
1802 * 'stuck on smp_invalidate_needed IPI wait' messages.
1803 */
1804 if (check_apicid_used(phys_id_present_map,
1805 mp_ioapics[apic].mpc_apicid)) {
1806 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
1807 apic, mp_ioapics[apic].mpc_apicid);
1808 for (i = 0; i < get_physical_broadcast(); i++)
1809 if (!physid_isset(i, phys_id_present_map))
1810 break;
1811 if (i >= get_physical_broadcast())
1812 panic("Max APIC ID exceeded!\n");
1813 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
1814 i);
1815 physid_set(i, phys_id_present_map);
1816 mp_ioapics[apic].mpc_apicid = i;
1817 } else {
1818 physid_mask_t tmp;
1819 tmp = apicid_to_cpu_present(mp_ioapics[apic].mpc_apicid);
1820 apic_printk(APIC_VERBOSE, "Setting %d in the "
1821 "phys_id_present_map\n",
1822 mp_ioapics[apic].mpc_apicid);
1823 physids_or(phys_id_present_map, phys_id_present_map, tmp);
1824 }
1825
1826
1827 /*
1828 * We need to adjust the IRQ routing table
1829 * if the ID changed.
1830 */
1831 if (old_id != mp_ioapics[apic].mpc_apicid)
1832 for (i = 0; i < mp_irq_entries; i++)
1833 if (mp_irqs[i].mpc_dstapic == old_id)
1834 mp_irqs[i].mpc_dstapic
1835 = mp_ioapics[apic].mpc_apicid;
1836
1837 /*
1838 * Read the right value from the MPC table and
1839 * write it into the ID register.
1840 */
1841 apic_printk(APIC_VERBOSE, KERN_INFO
1842 "...changing IO-APIC physical APIC ID to %d ...",
1843 mp_ioapics[apic].mpc_apicid);
1844
1845 reg_00.bits.ID = mp_ioapics[apic].mpc_apicid;
1846 spin_lock_irqsave(&ioapic_lock, flags);
1847 io_apic_write(apic, 0, reg_00.raw);
1848 spin_unlock_irqrestore(&ioapic_lock, flags);
1849
1850 /*
1851 * Sanity check
1852 */
1853 spin_lock_irqsave(&ioapic_lock, flags);
1854 reg_00.raw = io_apic_read(apic, 0);
1855 spin_unlock_irqrestore(&ioapic_lock, flags);
1856 if (reg_00.bits.ID != mp_ioapics[apic].mpc_apicid)
1857 printk("could not set ID!\n");
1858 else
1859 apic_printk(APIC_VERBOSE, " ok.\n");
1860 }
1861}
1862#else
1863static void __init setup_ioapic_ids_from_mpc(void) { }
1864#endif
1865
1866/*
1867 * There is a nasty bug in some older SMP boards, their mptable lies
1868 * about the timer IRQ. We do the following to work around the situation:
1869 *
1870 * - timer IRQ defaults to IO-APIC IRQ
1871 * - if this function detects that timer IRQs are defunct, then we fall
1872 * back to ISA timer IRQs
1873 */
1874static int __init timer_irq_works(void)
1875{
1876 unsigned long t1 = jiffies;
1877
1878 local_irq_enable();
1879 /* Let ten ticks pass... */
1880 mdelay((10 * 1000) / HZ);
1881
1882 /*
1883 * Expect a few ticks at least, to be sure some possible
1884 * glue logic does not lock up after one or two first
1885 * ticks in a non-ExtINT mode. Also the local APIC
1886 * might have cached one ExtINT interrupt. Finally, at
1887 * least one tick may be lost due to delays.
1888 */
1889 if (jiffies - t1 > 4)
1890 return 1;
1891
1892 return 0;
1893}
1894
1895/*
1896 * In the SMP+IOAPIC case it might happen that there are an unspecified
1897 * number of pending IRQ events unhandled. These cases are very rare,
1898 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
1899 * better to do it this way as thus we do not have to be aware of
1900 * 'pending' interrupts in the IRQ path, except at this point.
1901 */
1902/*
1903 * Edge triggered needs to resend any interrupt
1904 * that was delayed but this is now handled in the device
1905 * independent code.
1906 */
1907
1908/*
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001909 * Startup quirk:
1910 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 * Starting up a edge-triggered IO-APIC interrupt is
1912 * nasty - we need to make sure that we get the edge.
1913 * If it is already asserted for some reason, we need
1914 * return 1 to indicate that is was pending.
1915 *
1916 * This is not complete - we should be able to fake
1917 * an edge even if it isn't on the 8259A...
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001918 *
1919 * (We do this for level-triggered IRQs too - it cannot hurt.)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 */
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001921static unsigned int startup_ioapic_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922{
1923 int was_pending = 0;
1924 unsigned long flags;
1925
1926 spin_lock_irqsave(&ioapic_lock, flags);
1927 if (irq < 16) {
1928 disable_8259A_irq(irq);
1929 if (i8259A_irq_pending(irq))
1930 was_pending = 1;
1931 }
1932 __unmask_IO_APIC_irq(irq);
1933 spin_unlock_irqrestore(&ioapic_lock, flags);
1934
1935 return was_pending;
1936}
1937
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001938static void ack_ioapic_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939{
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001940 move_native_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 ack_APIC_irq();
1942}
1943
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001944static void ack_ioapic_quirk_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945{
1946 unsigned long v;
1947 int i;
1948
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001949 move_native_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950/*
1951 * It appears there is an erratum which affects at least version 0x11
1952 * of I/O APIC (that's the 82093AA and cores integrated into various
1953 * chipsets). Under certain conditions a level-triggered interrupt is
1954 * erroneously delivered as edge-triggered one but the respective IRR
1955 * bit gets set nevertheless. As a result the I/O unit expects an EOI
1956 * message but it will never arrive and further interrupts are blocked
1957 * from the source. The exact reason is so far unknown, but the
1958 * phenomenon was observed when two consecutive interrupt requests
1959 * from a given source get delivered to the same CPU and the source is
1960 * temporarily disabled in between.
1961 *
1962 * A workaround is to simulate an EOI message manually. We achieve it
1963 * by setting the trigger mode to edge and then to level when the edge
1964 * trigger mode gets detected in the TMR of a local APIC for a
1965 * level-triggered interrupt. We mask the source for the time of the
1966 * operation to prevent an edge-triggered interrupt escaping meanwhile.
1967 * The idea is from Manfred Spraul. --macro
1968 */
1969 i = IO_APIC_VECTOR(irq);
1970
1971 v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
1972
1973 ack_APIC_irq();
1974
1975 if (!(v & (1 << (i & 0x1f)))) {
1976 atomic_inc(&irq_mis_count);
1977 spin_lock(&ioapic_lock);
1978 __mask_and_edge_IO_APIC_irq(irq);
1979 __unmask_and_level_IO_APIC_irq(irq);
1980 spin_unlock(&ioapic_lock);
1981 }
1982}
1983
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001984static int ioapic_retrigger_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985{
Ingo Molnarc0ad90a2006-06-29 02:24:44 -07001986 send_IPI_self(IO_APIC_VECTOR(irq));
1987
1988 return 1;
1989}
1990
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001991static struct irq_chip ioapic_chip __read_mostly = {
1992 .name = "IO-APIC",
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001993 .startup = startup_ioapic_irq,
1994 .mask = mask_IO_APIC_irq,
1995 .unmask = unmask_IO_APIC_irq,
1996 .ack = ack_ioapic_irq,
1997 .eoi = ack_ioapic_quirk_irq,
Ashok Raj54d5d422005-09-06 15:16:15 -07001998#ifdef CONFIG_SMP
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001999 .set_affinity = set_ioapic_affinity_irq,
Ashok Raj54d5d422005-09-06 15:16:15 -07002000#endif
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07002001 .retrigger = ioapic_retrigger_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002};
2003
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
2005static inline void init_IO_APIC_traps(void)
2006{
2007 int irq;
2008
2009 /*
2010 * NOTE! The local APIC isn't very good at handling
2011 * multiple interrupts at the same interrupt level.
2012 * As the interrupt level is determined by taking the
2013 * vector number and shifting that right by 4, we
2014 * want to spread these out a bit so that they don't
2015 * all fall in the same interrupt level.
2016 *
2017 * Also, we've got to be careful not to trash gate
2018 * 0x80, because int 0x80 is hm, kind of importantish. ;)
2019 */
2020 for (irq = 0; irq < NR_IRQS ; irq++) {
2021 int tmp = irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 if (IO_APIC_IRQ(tmp) && !IO_APIC_VECTOR(tmp)) {
2023 /*
2024 * Hmm.. We don't have an entry for this,
2025 * so default to an old-fashioned 8259
2026 * interrupt if we can..
2027 */
2028 if (irq < 16)
2029 make_8259A_irq(irq);
2030 else
2031 /* Strange. Oh, well.. */
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002032 irq_desc[irq].chip = &no_irq_chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 }
2034 }
2035}
2036
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002037/*
2038 * The local APIC irq-chip implementation:
2039 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002041static void ack_apic(unsigned int irq)
2042{
2043 ack_APIC_irq();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044}
2045
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002046static void mask_lapic_irq (unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047{
2048 unsigned long v;
2049
2050 v = apic_read(APIC_LVT0);
2051 apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
2052}
2053
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002054static void unmask_lapic_irq (unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002056 unsigned long v;
2057
2058 v = apic_read(APIC_LVT0);
2059 apic_write_around(APIC_LVT0, v & ~APIC_LVT_MASKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002062static struct irq_chip lapic_chip __read_mostly = {
2063 .name = "local-APIC-edge",
2064 .mask = mask_lapic_irq,
2065 .unmask = unmask_lapic_irq,
2066 .eoi = ack_apic,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067};
2068
2069static void setup_nmi (void)
2070{
2071 /*
2072 * Dirty trick to enable the NMI watchdog ...
2073 * We put the 8259A master into AEOI mode and
2074 * unmask on all local APICs LVT0 as NMI.
2075 *
2076 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
2077 * is from Maciej W. Rozycki - so we do not have to EOI from
2078 * the NMI handler or the timer interrupt.
2079 */
2080 apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
2081
2082 on_each_cpu(enable_NMI_through_LVT0, NULL, 1, 1);
2083
2084 apic_printk(APIC_VERBOSE, " done.\n");
2085}
2086
2087/*
2088 * This looks a bit hackish but it's about the only one way of sending
2089 * a few INTA cycles to 8259As and any associated glue logic. ICR does
2090 * not support the ExtINT mode, unfortunately. We need to send these
2091 * cycles as some i82489DX-based boards have glue logic that keeps the
2092 * 8259A interrupt line asserted until INTA. --macro
2093 */
2094static inline void unlock_ExtINT_logic(void)
2095{
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002096 int apic, pin, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct IO_APIC_route_entry entry0, entry1;
2098 unsigned char save_control, save_freq_select;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002100 pin = find_isa_irq_pin(8, mp_INT);
2101 apic = find_isa_irq_apic(8, mp_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 if (pin == -1)
2103 return;
2104
Andi Kleencf4c6a22006-09-26 10:52:30 +02002105 entry0 = ioapic_read_entry(apic, pin);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002106 clear_IO_APIC_pin(apic, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 memset(&entry1, 0, sizeof(entry1));
2109
2110 entry1.dest_mode = 0; /* physical delivery */
2111 entry1.mask = 0; /* unmask IRQ now */
2112 entry1.dest.physical.physical_dest = hard_smp_processor_id();
2113 entry1.delivery_mode = dest_ExtINT;
2114 entry1.polarity = entry0.polarity;
2115 entry1.trigger = 0;
2116 entry1.vector = 0;
2117
Andi Kleencf4c6a22006-09-26 10:52:30 +02002118 ioapic_write_entry(apic, pin, entry1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
2120 save_control = CMOS_READ(RTC_CONTROL);
2121 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
2122 CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
2123 RTC_FREQ_SELECT);
2124 CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
2125
2126 i = 100;
2127 while (i-- > 0) {
2128 mdelay(10);
2129 if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
2130 i -= 10;
2131 }
2132
2133 CMOS_WRITE(save_control, RTC_CONTROL);
2134 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002135 clear_IO_APIC_pin(apic, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Andi Kleencf4c6a22006-09-26 10:52:30 +02002137 ioapic_write_entry(apic, pin, entry0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138}
2139
Kimball Murraye0c1e9b2006-05-08 15:17:16 +02002140int timer_uses_ioapic_pin_0;
2141
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142/*
2143 * This code may look a bit paranoid, but it's supposed to cooperate with
2144 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
2145 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
2146 * fanatically on his truly buggy board.
2147 */
2148static inline void check_timer(void)
2149{
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002150 int apic1, pin1, apic2, pin2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 int vector;
2152
2153 /*
2154 * get/set the timer IRQ vector:
2155 */
2156 disable_8259A_irq(0);
2157 vector = assign_irq_vector(0);
2158 set_intr_gate(vector, interrupt[0]);
2159
2160 /*
2161 * Subtle, code in do_timer_interrupt() expects an AEOI
2162 * mode for the 8259A whenever interrupts are routed
2163 * through I/O APICs. Also IRQ0 has to be enabled in
2164 * the 8259A which implies the virtual wire has to be
2165 * disabled in the local APIC.
2166 */
2167 apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
2168 init_8259A(1);
2169 timer_ack = 1;
Andi Kleenf9262c12006-03-08 17:57:25 -08002170 if (timer_over_8254 > 0)
2171 enable_8259A_irq(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002173 pin1 = find_isa_irq_pin(0, mp_INT);
2174 apic1 = find_isa_irq_apic(0, mp_INT);
2175 pin2 = ioapic_i8259.pin;
2176 apic2 = ioapic_i8259.apic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
Kimball Murraye0c1e9b2006-05-08 15:17:16 +02002178 if (pin1 == 0)
2179 timer_uses_ioapic_pin_0 = 1;
2180
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002181 printk(KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n",
2182 vector, apic1, pin1, apic2, pin2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
2184 if (pin1 != -1) {
2185 /*
2186 * Ok, does IRQ0 through the IOAPIC work?
2187 */
2188 unmask_IO_APIC_irq(0);
2189 if (timer_irq_works()) {
2190 if (nmi_watchdog == NMI_IO_APIC) {
2191 disable_8259A_irq(0);
2192 setup_nmi();
2193 enable_8259A_irq(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 }
Chuck Ebbert66759a02005-09-12 18:49:25 +02002195 if (disable_timer_pin_1 > 0)
2196 clear_IO_APIC_pin(0, pin1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 return;
2198 }
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002199 clear_IO_APIC_pin(apic1, pin1);
2200 printk(KERN_ERR "..MP-BIOS bug: 8254 timer not connected to "
2201 "IO-APIC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
2203
2204 printk(KERN_INFO "...trying to set up timer (IRQ0) through the 8259A ... ");
2205 if (pin2 != -1) {
2206 printk("\n..... (found pin %d) ...", pin2);
2207 /*
2208 * legacy devices should be connected to IO APIC #0
2209 */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002210 setup_ExtINT_IRQ0_pin(apic2, pin2, vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 if (timer_irq_works()) {
2212 printk("works.\n");
2213 if (pin1 != -1)
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002214 replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 else
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002216 add_pin_to_irq(0, apic2, pin2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 if (nmi_watchdog == NMI_IO_APIC) {
2218 setup_nmi();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 }
2220 return;
2221 }
2222 /*
2223 * Cleanup, just in case ...
2224 */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002225 clear_IO_APIC_pin(apic2, pin2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 }
2227 printk(" failed.\n");
2228
2229 if (nmi_watchdog == NMI_IO_APIC) {
2230 printk(KERN_WARNING "timer doesn't work through the IO-APIC - disabling NMI Watchdog!\n");
2231 nmi_watchdog = 0;
2232 }
2233
2234 printk(KERN_INFO "...trying to set up timer as Virtual Wire IRQ...");
2235
2236 disable_8259A_irq(0);
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002237 set_irq_chip_and_handler(0, &lapic_chip, handle_fasteoi_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 apic_write_around(APIC_LVT0, APIC_DM_FIXED | vector); /* Fixed mode */
2239 enable_8259A_irq(0);
2240
2241 if (timer_irq_works()) {
2242 printk(" works.\n");
2243 return;
2244 }
2245 apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);
2246 printk(" failed.\n");
2247
2248 printk(KERN_INFO "...trying to set up timer as ExtINT IRQ...");
2249
2250 timer_ack = 0;
2251 init_8259A(0);
2252 make_8259A_irq(0);
2253 apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
2254
2255 unlock_ExtINT_logic();
2256
2257 if (timer_irq_works()) {
2258 printk(" works.\n");
2259 return;
2260 }
2261 printk(" failed :(.\n");
2262 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
2263 "report. Then try booting with the 'noapic' option");
2264}
2265
2266/*
2267 *
2268 * IRQ's that are handled by the PIC in the MPS IOAPIC case.
2269 * - IRQ2 is the cascade IRQ, and cannot be a io-apic IRQ.
2270 * Linux doesn't really care, as it's not actually used
2271 * for any interrupt handling anyway.
2272 */
2273#define PIC_IRQS (1 << PIC_CASCADE_IR)
2274
2275void __init setup_IO_APIC(void)
2276{
2277 enable_IO_APIC();
2278
2279 if (acpi_ioapic)
2280 io_apic_irqs = ~0; /* all IRQs go through IOAPIC */
2281 else
2282 io_apic_irqs = ~PIC_IRQS;
2283
2284 printk("ENABLING IO-APIC IRQs\n");
2285
2286 /*
2287 * Set up IO-APIC IRQ routing.
2288 */
2289 if (!acpi_ioapic)
2290 setup_ioapic_ids_from_mpc();
2291 sync_Arb_IDs();
2292 setup_IO_APIC_irqs();
2293 init_IO_APIC_traps();
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08002294 check_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 if (!acpi_ioapic)
2296 print_IO_APIC();
2297}
2298
Andi Kleenf9262c12006-03-08 17:57:25 -08002299static int __init setup_disable_8254_timer(char *s)
2300{
2301 timer_over_8254 = -1;
2302 return 1;
2303}
2304static int __init setup_enable_8254_timer(char *s)
2305{
2306 timer_over_8254 = 2;
2307 return 1;
2308}
2309
2310__setup("disable_8254_timer", setup_disable_8254_timer);
2311__setup("enable_8254_timer", setup_enable_8254_timer);
2312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313/*
2314 * Called after all the initialization is done. If we didnt find any
2315 * APIC bugs then we can allow the modify fast path
2316 */
2317
2318static int __init io_apic_bug_finalize(void)
2319{
2320 if(sis_apic_bug == -1)
2321 sis_apic_bug = 0;
2322 return 0;
2323}
2324
2325late_initcall(io_apic_bug_finalize);
2326
2327struct sysfs_ioapic_data {
2328 struct sys_device dev;
2329 struct IO_APIC_route_entry entry[0];
2330};
2331static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
2332
Pavel Machek438510f2005-04-16 15:25:24 -07002333static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
2335 struct IO_APIC_route_entry *entry;
2336 struct sysfs_ioapic_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 int i;
2338
2339 data = container_of(dev, struct sysfs_ioapic_data, dev);
2340 entry = data->entry;
Andi Kleencf4c6a22006-09-26 10:52:30 +02002341 for (i = 0; i < nr_ioapic_registers[dev->id]; i ++)
2342 entry[i] = ioapic_read_entry(dev->id, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
2344 return 0;
2345}
2346
2347static int ioapic_resume(struct sys_device *dev)
2348{
2349 struct IO_APIC_route_entry *entry;
2350 struct sysfs_ioapic_data *data;
2351 unsigned long flags;
2352 union IO_APIC_reg_00 reg_00;
2353 int i;
2354
2355 data = container_of(dev, struct sysfs_ioapic_data, dev);
2356 entry = data->entry;
2357
2358 spin_lock_irqsave(&ioapic_lock, flags);
2359 reg_00.raw = io_apic_read(dev->id, 0);
2360 if (reg_00.bits.ID != mp_ioapics[dev->id].mpc_apicid) {
2361 reg_00.bits.ID = mp_ioapics[dev->id].mpc_apicid;
2362 io_apic_write(dev->id, 0, reg_00.raw);
2363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 spin_unlock_irqrestore(&ioapic_lock, flags);
Andi Kleencf4c6a22006-09-26 10:52:30 +02002365 for (i = 0; i < nr_ioapic_registers[dev->id]; i ++)
2366 ioapic_write_entry(dev->id, i, entry[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
2368 return 0;
2369}
2370
2371static struct sysdev_class ioapic_sysdev_class = {
2372 set_kset_name("ioapic"),
2373 .suspend = ioapic_suspend,
2374 .resume = ioapic_resume,
2375};
2376
2377static int __init ioapic_init_sysfs(void)
2378{
2379 struct sys_device * dev;
2380 int i, size, error = 0;
2381
2382 error = sysdev_class_register(&ioapic_sysdev_class);
2383 if (error)
2384 return error;
2385
2386 for (i = 0; i < nr_ioapics; i++ ) {
2387 size = sizeof(struct sys_device) + nr_ioapic_registers[i]
2388 * sizeof(struct IO_APIC_route_entry);
2389 mp_ioapic_data[i] = kmalloc(size, GFP_KERNEL);
2390 if (!mp_ioapic_data[i]) {
2391 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
2392 continue;
2393 }
2394 memset(mp_ioapic_data[i], 0, size);
2395 dev = &mp_ioapic_data[i]->dev;
2396 dev->id = i;
2397 dev->cls = &ioapic_sysdev_class;
2398 error = sysdev_register(dev);
2399 if (error) {
2400 kfree(mp_ioapic_data[i]);
2401 mp_ioapic_data[i] = NULL;
2402 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
2403 continue;
2404 }
2405 }
2406
2407 return 0;
2408}
2409
2410device_initcall(ioapic_init_sysfs);
2411
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002412#ifdef CONFIG_PCI_MSI
2413/*
2414 * Dynamic irq allocate and deallocation for MSI
2415 */
2416int create_irq(void)
2417{
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07002418 /* Allocate an unused irq */
2419 int irq, new, vector;
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002420 unsigned long flags;
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002421
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07002422 irq = -ENOSPC;
2423 spin_lock_irqsave(&vector_lock, flags);
2424 for (new = (NR_IRQS - 1); new >= 0; new--) {
2425 if (platform_legacy_irq(new))
2426 continue;
2427 if (irq_vector[new] != 0)
2428 continue;
2429 vector = __assign_irq_vector(new);
2430 if (likely(vector > 0))
2431 irq = new;
2432 break;
2433 }
2434 spin_unlock_irqrestore(&vector_lock, flags);
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002435
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07002436 if (irq >= 0) {
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002437 set_intr_gate(vector, interrupt[irq]);
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002438 dynamic_irq_init(irq);
2439 }
2440 return irq;
2441}
2442
2443void destroy_irq(unsigned int irq)
2444{
2445 unsigned long flags;
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002446
2447 dynamic_irq_cleanup(irq);
2448
2449 spin_lock_irqsave(&vector_lock, flags);
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07002450 irq_vector[irq] = 0;
2451 spin_unlock_irqrestore(&vector_lock, flags);
2452}
2453#endif /* CONFIG_PCI_MSI */
2454
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07002455/*
2456 * MSI mesage composition
2457 */
2458#ifdef CONFIG_PCI_MSI
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07002459static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg)
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07002460{
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07002461 int vector;
2462 unsigned dest;
2463
2464 vector = assign_irq_vector(irq);
2465 if (vector >= 0) {
2466 dest = cpu_mask_to_apicid(TARGET_CPUS);
2467
2468 msg->address_hi = MSI_ADDR_BASE_HI;
2469 msg->address_lo =
2470 MSI_ADDR_BASE_LO |
2471 ((INT_DEST_MODE == 0) ?
2472 MSI_ADDR_DEST_MODE_PHYSICAL:
2473 MSI_ADDR_DEST_MODE_LOGICAL) |
2474 ((INT_DELIVERY_MODE != dest_LowestPrio) ?
2475 MSI_ADDR_REDIRECTION_CPU:
2476 MSI_ADDR_REDIRECTION_LOWPRI) |
2477 MSI_ADDR_DEST_ID(dest);
2478
2479 msg->data =
2480 MSI_DATA_TRIGGER_EDGE |
2481 MSI_DATA_LEVEL_ASSERT |
2482 ((INT_DELIVERY_MODE != dest_LowestPrio) ?
2483 MSI_DATA_DELIVERY_FIXED:
2484 MSI_DATA_DELIVERY_LOWPRI) |
2485 MSI_DATA_VECTOR(vector);
2486 }
2487 return vector;
2488}
2489
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07002490#ifdef CONFIG_SMP
2491static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask)
2492{
2493 struct msi_msg msg;
2494 unsigned int dest;
2495 cpumask_t tmp;
2496 int vector;
2497
2498 cpus_and(tmp, mask, cpu_online_map);
2499 if (cpus_empty(tmp))
2500 tmp = TARGET_CPUS;
2501
2502 vector = assign_irq_vector(irq);
2503 if (vector < 0)
2504 return;
2505
2506 dest = cpu_mask_to_apicid(mask);
2507
2508 read_msi_msg(irq, &msg);
2509
2510 msg.data &= ~MSI_DATA_VECTOR_MASK;
2511 msg.data |= MSI_DATA_VECTOR(vector);
2512 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
2513 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
2514
2515 write_msi_msg(irq, &msg);
2516 set_native_irq_info(irq, mask);
2517}
2518#endif /* CONFIG_SMP */
2519
2520/*
2521 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
2522 * which implement the MSI or MSI-X Capability Structure.
2523 */
2524static struct irq_chip msi_chip = {
2525 .name = "PCI-MSI",
2526 .unmask = unmask_msi_irq,
2527 .mask = mask_msi_irq,
2528 .ack = ack_ioapic_irq,
2529#ifdef CONFIG_SMP
2530 .set_affinity = set_msi_irq_affinity,
2531#endif
2532 .retrigger = ioapic_retrigger_irq,
2533};
2534
2535int arch_setup_msi_irq(unsigned int irq, struct pci_dev *dev)
2536{
2537 struct msi_msg msg;
2538 int ret;
2539 ret = msi_compose_msg(dev, irq, &msg);
2540 if (ret < 0)
2541 return ret;
2542
2543 write_msi_msg(irq, &msg);
2544
2545 set_irq_chip_and_handler(irq, &msi_chip, handle_edge_irq);
2546
2547 return 0;
2548}
2549
2550void arch_teardown_msi_irq(unsigned int irq)
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07002551{
2552 return;
2553}
2554
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07002555#endif /* CONFIG_PCI_MSI */
2556
Eric W. Biederman8b955b02006-10-04 02:16:55 -07002557/*
2558 * Hypertransport interrupt support
2559 */
2560#ifdef CONFIG_HT_IRQ
2561
2562#ifdef CONFIG_SMP
2563
2564static void target_ht_irq(unsigned int irq, unsigned int dest)
2565{
2566 u32 low, high;
2567 low = read_ht_irq_low(irq);
2568 high = read_ht_irq_high(irq);
2569
2570 low &= ~(HT_IRQ_LOW_DEST_ID_MASK);
2571 high &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
2572
2573 low |= HT_IRQ_LOW_DEST_ID(dest);
2574 high |= HT_IRQ_HIGH_DEST_ID(dest);
2575
2576 write_ht_irq_low(irq, low);
2577 write_ht_irq_high(irq, high);
2578}
2579
2580static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask)
2581{
2582 unsigned int dest;
2583 cpumask_t tmp;
2584
2585 cpus_and(tmp, mask, cpu_online_map);
2586 if (cpus_empty(tmp))
2587 tmp = TARGET_CPUS;
2588
2589 cpus_and(mask, tmp, CPU_MASK_ALL);
2590
2591 dest = cpu_mask_to_apicid(mask);
2592
2593 target_ht_irq(irq, dest);
2594 set_native_irq_info(irq, mask);
2595}
2596#endif
2597
2598static struct hw_interrupt_type ht_irq_chip = {
2599 .name = "PCI-HT",
2600 .mask = mask_ht_irq,
2601 .unmask = unmask_ht_irq,
2602 .ack = ack_ioapic_irq,
2603#ifdef CONFIG_SMP
2604 .set_affinity = set_ht_irq_affinity,
2605#endif
2606 .retrigger = ioapic_retrigger_irq,
2607};
2608
2609int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
2610{
2611 int vector;
2612
2613 vector = assign_irq_vector(irq);
2614 if (vector >= 0) {
2615 u32 low, high;
2616 unsigned dest;
2617 cpumask_t tmp;
2618
2619 cpus_clear(tmp);
2620 cpu_set(vector >> 8, tmp);
2621 dest = cpu_mask_to_apicid(tmp);
2622
2623 high = HT_IRQ_HIGH_DEST_ID(dest);
2624
2625 low = HT_IRQ_LOW_BASE |
2626 HT_IRQ_LOW_DEST_ID(dest) |
2627 HT_IRQ_LOW_VECTOR(vector) |
2628 ((INT_DEST_MODE == 0) ?
2629 HT_IRQ_LOW_DM_PHYSICAL :
2630 HT_IRQ_LOW_DM_LOGICAL) |
2631 HT_IRQ_LOW_RQEOI_EDGE |
2632 ((INT_DELIVERY_MODE != dest_LowestPrio) ?
2633 HT_IRQ_LOW_MT_FIXED :
2634 HT_IRQ_LOW_MT_ARBITRATED) |
2635 HT_IRQ_LOW_IRQ_MASKED;
2636
2637 write_ht_irq_low(irq, low);
2638 write_ht_irq_high(irq, high);
2639
2640 set_irq_chip_and_handler(irq, &ht_irq_chip, handle_edge_irq);
2641 }
2642 return vector;
2643}
2644#endif /* CONFIG_HT_IRQ */
2645
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646/* --------------------------------------------------------------------------
2647 ACPI-based IOAPIC Configuration
2648 -------------------------------------------------------------------------- */
2649
Len Brown888ba6c2005-08-24 12:07:20 -04002650#ifdef CONFIG_ACPI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
2652int __init io_apic_get_unique_id (int ioapic, int apic_id)
2653{
2654 union IO_APIC_reg_00 reg_00;
2655 static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
2656 physid_mask_t tmp;
2657 unsigned long flags;
2658 int i = 0;
2659
2660 /*
2661 * The P4 platform supports up to 256 APIC IDs on two separate APIC
2662 * buses (one for LAPICs, one for IOAPICs), where predecessors only
2663 * supports up to 16 on one shared APIC bus.
2664 *
2665 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
2666 * advantage of new APIC bus architecture.
2667 */
2668
2669 if (physids_empty(apic_id_map))
2670 apic_id_map = ioapic_phys_id_map(phys_cpu_present_map);
2671
2672 spin_lock_irqsave(&ioapic_lock, flags);
2673 reg_00.raw = io_apic_read(ioapic, 0);
2674 spin_unlock_irqrestore(&ioapic_lock, flags);
2675
2676 if (apic_id >= get_physical_broadcast()) {
2677 printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
2678 "%d\n", ioapic, apic_id, reg_00.bits.ID);
2679 apic_id = reg_00.bits.ID;
2680 }
2681
2682 /*
2683 * Every APIC in a system must have a unique ID or we get lots of nice
2684 * 'stuck on smp_invalidate_needed IPI wait' messages.
2685 */
2686 if (check_apicid_used(apic_id_map, apic_id)) {
2687
2688 for (i = 0; i < get_physical_broadcast(); i++) {
2689 if (!check_apicid_used(apic_id_map, i))
2690 break;
2691 }
2692
2693 if (i == get_physical_broadcast())
2694 panic("Max apic_id exceeded!\n");
2695
2696 printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
2697 "trying %d\n", ioapic, apic_id, i);
2698
2699 apic_id = i;
2700 }
2701
2702 tmp = apicid_to_cpu_present(apic_id);
2703 physids_or(apic_id_map, apic_id_map, tmp);
2704
2705 if (reg_00.bits.ID != apic_id) {
2706 reg_00.bits.ID = apic_id;
2707
2708 spin_lock_irqsave(&ioapic_lock, flags);
2709 io_apic_write(ioapic, 0, reg_00.raw);
2710 reg_00.raw = io_apic_read(ioapic, 0);
2711 spin_unlock_irqrestore(&ioapic_lock, flags);
2712
2713 /* Sanity check */
Andreas Deresch6070f9e2006-02-26 04:18:34 +01002714 if (reg_00.bits.ID != apic_id) {
2715 printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
2716 return -1;
2717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 }
2719
2720 apic_printk(APIC_VERBOSE, KERN_INFO
2721 "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
2722
2723 return apic_id;
2724}
2725
2726
2727int __init io_apic_get_version (int ioapic)
2728{
2729 union IO_APIC_reg_01 reg_01;
2730 unsigned long flags;
2731
2732 spin_lock_irqsave(&ioapic_lock, flags);
2733 reg_01.raw = io_apic_read(ioapic, 1);
2734 spin_unlock_irqrestore(&ioapic_lock, flags);
2735
2736 return reg_01.bits.version;
2737}
2738
2739
2740int __init io_apic_get_redir_entries (int ioapic)
2741{
2742 union IO_APIC_reg_01 reg_01;
2743 unsigned long flags;
2744
2745 spin_lock_irqsave(&ioapic_lock, flags);
2746 reg_01.raw = io_apic_read(ioapic, 1);
2747 spin_unlock_irqrestore(&ioapic_lock, flags);
2748
2749 return reg_01.bits.entries;
2750}
2751
2752
2753int io_apic_set_pci_routing (int ioapic, int pin, int irq, int edge_level, int active_high_low)
2754{
2755 struct IO_APIC_route_entry entry;
2756 unsigned long flags;
2757
2758 if (!IO_APIC_IRQ(irq)) {
2759 printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
2760 ioapic);
2761 return -EINVAL;
2762 }
2763
2764 /*
2765 * Generate a PCI IRQ routing entry and program the IOAPIC accordingly.
2766 * Note that we mask (disable) IRQs now -- these get enabled when the
2767 * corresponding device driver registers for this IRQ.
2768 */
2769
2770 memset(&entry,0,sizeof(entry));
2771
2772 entry.delivery_mode = INT_DELIVERY_MODE;
2773 entry.dest_mode = INT_DEST_MODE;
2774 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
2775 entry.trigger = edge_level;
2776 entry.polarity = active_high_low;
2777 entry.mask = 1;
2778
2779 /*
2780 * IRQs < 16 are already in the irq_2_pin[] map
2781 */
2782 if (irq >= 16)
2783 add_pin_to_irq(irq, ioapic, pin);
2784
2785 entry.vector = assign_irq_vector(irq);
2786
2787 apic_printk(APIC_DEBUG, KERN_DEBUG "IOAPIC[%d]: Set PCI routing entry "
2788 "(%d-%d -> 0x%x -> IRQ %d Mode:%i Active:%i)\n", ioapic,
2789 mp_ioapics[ioapic].mpc_apicid, pin, entry.vector, irq,
2790 edge_level, active_high_low);
2791
2792 ioapic_register_intr(irq, entry.vector, edge_level);
2793
2794 if (!ioapic && (irq < 16))
2795 disable_8259A_irq(irq);
2796
Andi Kleencf4c6a22006-09-26 10:52:30 +02002797 ioapic_write_entry(ioapic, pin, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 spin_lock_irqsave(&ioapic_lock, flags);
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07002799 set_native_irq_info(irq, TARGET_CPUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 spin_unlock_irqrestore(&ioapic_lock, flags);
2801
2802 return 0;
2803}
2804
Len Brown888ba6c2005-08-24 12:07:20 -04002805#endif /* CONFIG_ACPI */
Rusty Russell1a3f2392006-09-26 10:52:32 +02002806
2807static int __init parse_disable_timer_pin_1(char *arg)
2808{
2809 disable_timer_pin_1 = 1;
2810 return 0;
2811}
2812early_param("disable_timer_pin_1", parse_disable_timer_pin_1);
2813
2814static int __init parse_enable_timer_pin_1(char *arg)
2815{
2816 disable_timer_pin_1 = -1;
2817 return 0;
2818}
2819early_param("enable_timer_pin_1", parse_enable_timer_pin_1);
2820
2821static int __init parse_noapic(char *arg)
2822{
2823 /* disable IO-APIC */
2824 disable_ioapic_setup();
2825 return 0;
2826}
2827early_param("noapic", parse_noapic);