2 * arch/ppc/kernel/open_pic.c -- OpenPIC Interrupt Handling
4 * Copyright (C) 1997 Geert Uytterhoeven
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
11 #include <linux/config.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/sysdev.h>
18 #include <linux/errno.h>
19 #include <asm/ptrace.h>
20 #include <asm/signal.h>
23 #include <asm/sections.h>
24 #include <asm/open_pic.h>
25 #include <asm/i8259.h>
27 #include "open_pic_defs.h"
29 #if defined(CONFIG_PRPMC800) || defined(CONFIG_85xx)
30 #define OPENPIC_BIG_ENDIAN
33 void __iomem *OpenPIC_Addr;
34 static volatile struct OpenPIC __iomem *OpenPIC = NULL;
37 * We define OpenPIC_InitSenses table thusly:
38 * bit 0x1: sense, 0 for edge and 1 for level.
39 * bit 0x2: polarity, 0 for negative, 1 for positive.
41 u_int OpenPIC_NumInitSenses __initdata = 0;
42 u_char *OpenPIC_InitSenses __initdata = NULL;
43 extern int use_of_interrupt_tree;
45 static u_int NumProcessors;
46 static u_int NumSources;
47 static int open_pic_irq_offset;
48 static volatile OpenPIC_Source __iomem *ISR[NR_IRQS];
49 static int openpic_cascade_irq = -1;
50 static int (*openpic_cascade_fn)(struct pt_regs *);
52 /* Global Operations */
53 static void openpic_disable_8259_pass_through(void);
54 static void openpic_set_spurious(u_int vector);
57 /* Interprocessor Interrupts */
58 static void openpic_initipi(u_int ipi, u_int pri, u_int vector);
59 static irqreturn_t openpic_ipi_action(int cpl, void *dev_id, struct pt_regs *);
62 /* Timer Interrupts */
63 static void openpic_inittimer(u_int timer, u_int pri, u_int vector);
64 static void openpic_maptimer(u_int timer, cpumask_t cpumask);
66 /* Interrupt Sources */
67 static void openpic_enable_irq(u_int irq);
68 static void openpic_disable_irq(u_int irq);
69 static void openpic_initirq(u_int irq, u_int pri, u_int vector, int polarity,
71 static void openpic_mapirq(u_int irq, cpumask_t cpumask, cpumask_t keepmask);
74 * These functions are not used but the code is kept here
75 * for completeness and future reference.
78 static void openpic_enable_8259_pass_through(void);
79 static u_int openpic_get_spurious(void);
80 static void openpic_set_sense(u_int irq, int sense);
84 * Description of the openpic for the higher-level irq code
86 static void openpic_end_irq(unsigned int irq_nr);
87 static void openpic_ack_irq(unsigned int irq_nr);
88 static void openpic_set_affinity(unsigned int irq_nr, cpumask_t cpumask);
90 struct hw_interrupt_type open_pic = {
91 .typename = " OpenPIC ",
92 .enable = openpic_enable_irq,
93 .disable = openpic_disable_irq,
94 .ack = openpic_ack_irq,
95 .end = openpic_end_irq,
96 .set_affinity = openpic_set_affinity,
100 static void openpic_end_ipi(unsigned int irq_nr);
101 static void openpic_ack_ipi(unsigned int irq_nr);
102 static void openpic_enable_ipi(unsigned int irq_nr);
103 static void openpic_disable_ipi(unsigned int irq_nr);
105 struct hw_interrupt_type open_pic_ipi = {
106 .typename = " OpenPIC ",
107 .enable = openpic_enable_ipi,
108 .disable = openpic_disable_ipi,
109 .ack = openpic_ack_ipi,
110 .end = openpic_end_ipi,
112 #endif /* CONFIG_SMP */
115 * Accesses to the current processor's openpic registers
118 #define THIS_CPU Processor[cpu]
119 #define DECL_THIS_CPU int cpu = smp_hw_index[smp_processor_id()]
120 #define CHECK_THIS_CPU check_arg_cpu(cpu)
122 #define THIS_CPU Processor[0]
123 #define DECL_THIS_CPU
124 #define CHECK_THIS_CPU
125 #endif /* CONFIG_SMP */
128 #define check_arg_ipi(ipi) \
129 if (ipi < 0 || ipi >= OPENPIC_NUM_IPI) \
130 printk("open_pic.c:%d: invalid ipi %d\n", __LINE__, ipi);
131 #define check_arg_timer(timer) \
132 if (timer < 0 || timer >= OPENPIC_NUM_TIMERS) \
133 printk("open_pic.c:%d: invalid timer %d\n", __LINE__, timer);
134 #define check_arg_vec(vec) \
135 if (vec < 0 || vec >= OPENPIC_NUM_VECTORS) \
136 printk("open_pic.c:%d: invalid vector %d\n", __LINE__, vec);
137 #define check_arg_pri(pri) \
138 if (pri < 0 || pri >= OPENPIC_NUM_PRI) \
139 printk("open_pic.c:%d: invalid priority %d\n", __LINE__, pri);
141 * Print out a backtrace if it's out of range, since if it's larger than NR_IRQ's
142 * data has probably been corrupted and we're going to panic or deadlock later
145 #define check_arg_irq(irq) \
146 if (irq < open_pic_irq_offset || irq >= NumSources+open_pic_irq_offset \
147 || ISR[irq - open_pic_irq_offset] == 0) { \
148 printk("open_pic.c:%d: invalid irq %d\n", __LINE__, irq); \
150 #define check_arg_cpu(cpu) \
151 if (cpu < 0 || cpu >= NumProcessors){ \
152 printk("open_pic.c:%d: invalid cpu %d\n", __LINE__, cpu); \
155 #define check_arg_ipi(ipi) do {} while (0)
156 #define check_arg_timer(timer) do {} while (0)
157 #define check_arg_vec(vec) do {} while (0)
158 #define check_arg_pri(pri) do {} while (0)
159 #define check_arg_irq(irq) do {} while (0)
160 #define check_arg_cpu(cpu) do {} while (0)
163 u_int openpic_read(volatile u_int __iomem *addr)
167 #ifdef OPENPIC_BIG_ENDIAN
175 static inline void openpic_write(volatile u_int __iomem *addr, u_int val)
177 #ifdef OPENPIC_BIG_ENDIAN
184 static inline u_int openpic_readfield(volatile u_int __iomem *addr, u_int mask)
186 u_int val = openpic_read(addr);
190 inline void openpic_writefield(volatile u_int __iomem *addr, u_int mask,
193 u_int val = openpic_read(addr);
194 openpic_write(addr, (val & ~mask) | (field & mask));
197 static inline void openpic_clearfield(volatile u_int __iomem *addr, u_int mask)
199 openpic_writefield(addr, mask, 0);
202 static inline void openpic_setfield(volatile u_int __iomem *addr, u_int mask)
204 openpic_writefield(addr, mask, mask);
207 static void openpic_safe_writefield(volatile u_int __iomem *addr, u_int mask,
210 openpic_setfield(addr, OPENPIC_MASK);
211 while (openpic_read(addr) & OPENPIC_ACTIVITY);
212 openpic_writefield(addr, mask | OPENPIC_MASK, field | OPENPIC_MASK);
216 /* yes this is right ... bug, feature, you decide! -- tgall */
217 u_int openpic_read_IPI(volatile u_int __iomem * addr)
220 #if defined(OPENPIC_BIG_ENDIAN) || defined(CONFIG_POWER3)
228 /* because of the power3 be / le above, this is needed */
229 inline void openpic_writefield_IPI(volatile u_int __iomem * addr, u_int mask, u_int field)
231 u_int val = openpic_read_IPI(addr);
232 openpic_write(addr, (val & ~mask) | (field & mask));
235 static inline void openpic_clearfield_IPI(volatile u_int __iomem *addr, u_int mask)
237 openpic_writefield_IPI(addr, mask, 0);
240 static inline void openpic_setfield_IPI(volatile u_int __iomem *addr, u_int mask)
242 openpic_writefield_IPI(addr, mask, mask);
245 static void openpic_safe_writefield_IPI(volatile u_int __iomem *addr, u_int mask, u_int field)
247 openpic_setfield_IPI(addr, OPENPIC_MASK);
249 /* wait until it's not in use */
250 /* BenH: Is this code really enough ? I would rather check the result
251 * and eventually retry ...
253 while(openpic_read_IPI(addr) & OPENPIC_ACTIVITY);
255 openpic_writefield_IPI(addr, mask | OPENPIC_MASK, field | OPENPIC_MASK);
257 #endif /* CONFIG_SMP */
259 #ifdef CONFIG_EPIC_SERIAL_MODE
260 /* On platforms that may use EPIC serial mode, the default is enabled. */
261 int epic_serial_mode = 1;
263 static void __init openpic_eicr_set_clk(u_int clkval)
265 openpic_writefield(&OpenPIC->Global.Global_Configuration1,
266 OPENPIC_EICR_S_CLK_MASK, (clkval << 28));
269 static void __init openpic_enable_sie(void)
271 openpic_setfield(&OpenPIC->Global.Global_Configuration1,
276 #if defined(CONFIG_EPIC_SERIAL_MODE)
277 static void openpic_reset(void)
279 openpic_setfield(&OpenPIC->Global.Global_Configuration0,
280 OPENPIC_CONFIG_RESET);
281 while (openpic_readfield(&OpenPIC->Global.Global_Configuration0,
282 OPENPIC_CONFIG_RESET))
287 void __init openpic_set_sources(int first_irq, int num_irqs, void __iomem *first_ISR)
289 volatile OpenPIC_Source __iomem *src = first_ISR;
292 last_irq = first_irq + num_irqs;
293 if (last_irq > NumSources)
294 NumSources = last_irq;
296 src = &((struct OpenPIC __iomem *)OpenPIC_Addr)->Source[first_irq];
297 for (i = first_irq; i < last_irq; ++i, ++src)
302 * The `offset' parameter defines where the interrupts handled by the
303 * OpenPIC start in the space of interrupt numbers that the kernel knows
304 * about. In other words, the OpenPIC's IRQ0 is numbered `offset' in the
305 * kernel's interrupt numbering scheme.
306 * We assume there is only one OpenPIC.
308 void __init openpic_init(int offset)
315 printk("No OpenPIC found !\n");
318 OpenPIC = (volatile struct OpenPIC __iomem *)OpenPIC_Addr;
320 #ifdef CONFIG_EPIC_SERIAL_MODE
321 /* Have to start from ground zero.
326 if (ppc_md.progress) ppc_md.progress("openpic: enter", 0x122);
328 t = openpic_read(&OpenPIC->Global.Feature_Reporting0);
329 switch (t & OPENPIC_FEATURE_VERSION_MASK) {
343 NumProcessors = ((t & OPENPIC_FEATURE_LAST_PROCESSOR_MASK) >>
344 OPENPIC_FEATURE_LAST_PROCESSOR_SHIFT) + 1;
346 openpic_set_sources(0,
347 ((t & OPENPIC_FEATURE_LAST_SOURCE_MASK) >>
348 OPENPIC_FEATURE_LAST_SOURCE_SHIFT) + 1,
350 printk("OpenPIC Version %s (%d CPUs and %d IRQ sources) at %p\n",
351 version, NumProcessors, NumSources, OpenPIC);
352 timerfreq = openpic_read(&OpenPIC->Global.Timer_Frequency);
354 printk("OpenPIC timer frequency is %d.%06d MHz\n",
355 timerfreq / 1000000, timerfreq % 1000000);
357 open_pic_irq_offset = offset;
359 /* Initialize timer interrupts */
360 if ( ppc_md.progress ) ppc_md.progress("openpic: timer",0x3ba);
361 for (i = 0; i < OPENPIC_NUM_TIMERS; i++) {
362 /* Disabled, Priority 0 */
363 openpic_inittimer(i, 0, OPENPIC_VEC_TIMER+i+offset);
365 openpic_maptimer(i, CPU_MASK_NONE);
369 /* Initialize IPI interrupts */
370 if ( ppc_md.progress ) ppc_md.progress("openpic: ipi",0x3bb);
371 for (i = 0; i < OPENPIC_NUM_IPI; i++) {
372 /* Disabled, increased priorities 10..13 */
373 openpic_initipi(i, OPENPIC_PRIORITY_IPI_BASE+i,
374 OPENPIC_VEC_IPI+i+offset);
375 /* IPIs are per-CPU */
376 irq_desc[OPENPIC_VEC_IPI+i+offset].status |= IRQ_PER_CPU;
377 irq_desc[OPENPIC_VEC_IPI+i+offset].handler = &open_pic_ipi;
381 /* Initialize external interrupts */
382 if (ppc_md.progress) ppc_md.progress("openpic: external",0x3bc);
384 openpic_set_priority(0xf);
386 /* Init all external sources, including possibly the cascade. */
387 for (i = 0; i < NumSources; i++) {
393 /* the bootloader may have left it enabled (bad !) */
394 openpic_disable_irq(i+offset);
396 sense = (i < OpenPIC_NumInitSenses)? OpenPIC_InitSenses[i]: \
397 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE);
399 if (sense & IRQ_SENSE_MASK)
400 irq_desc[i+offset].status = IRQ_LEVEL;
402 /* Enabled, Default priority */
403 openpic_initirq(i, OPENPIC_PRIORITY_DEFAULT, i+offset,
404 (sense & IRQ_POLARITY_MASK),
405 (sense & IRQ_SENSE_MASK));
407 openpic_mapirq(i, CPU_MASK_CPU0, CPU_MASK_NONE);
410 /* Init descriptors */
411 for (i = offset; i < NumSources + offset; i++)
412 irq_desc[i].handler = &open_pic;
414 /* Initialize the spurious interrupt */
415 if (ppc_md.progress) ppc_md.progress("openpic: spurious",0x3bd);
416 openpic_set_spurious(OPENPIC_VEC_SPURIOUS);
417 openpic_disable_8259_pass_through();
418 #ifdef CONFIG_EPIC_SERIAL_MODE
419 if (epic_serial_mode) {
420 openpic_eicr_set_clk(7); /* Slowest value until we know better */
421 openpic_enable_sie();
424 openpic_set_priority(0);
426 if (ppc_md.progress) ppc_md.progress("openpic: exit",0x222);
430 static void openpic_enable_8259_pass_through(void)
432 openpic_clearfield(&OpenPIC->Global.Global_Configuration0,
433 OPENPIC_CONFIG_8259_PASSTHROUGH_DISABLE);
437 static void openpic_disable_8259_pass_through(void)
439 openpic_setfield(&OpenPIC->Global.Global_Configuration0,
440 OPENPIC_CONFIG_8259_PASSTHROUGH_DISABLE);
444 * Find out the current interrupt
446 u_int openpic_irq(void)
452 vec = openpic_readfield(&OpenPIC->THIS_CPU.Interrupt_Acknowledge,
453 OPENPIC_VECTOR_MASK);
457 void openpic_eoi(void)
462 openpic_write(&OpenPIC->THIS_CPU.EOI, 0);
463 /* Handle PCI write posting */
464 (void)openpic_read(&OpenPIC->THIS_CPU.EOI);
467 u_int openpic_get_priority(void)
472 return openpic_readfield(&OpenPIC->THIS_CPU.Current_Task_Priority,
473 OPENPIC_CURRENT_TASK_PRIORITY_MASK);
476 void openpic_set_priority(u_int pri)
482 openpic_writefield(&OpenPIC->THIS_CPU.Current_Task_Priority,
483 OPENPIC_CURRENT_TASK_PRIORITY_MASK, pri);
487 * Get/set the spurious vector
490 static u_int openpic_get_spurious(void)
492 return openpic_readfield(&OpenPIC->Global.Spurious_Vector,
493 OPENPIC_VECTOR_MASK);
497 static void openpic_set_spurious(u_int vec)
500 openpic_writefield(&OpenPIC->Global.Spurious_Vector, OPENPIC_VECTOR_MASK,
506 * Convert a cpu mask from logical to physical cpu numbers.
508 static inline cpumask_t physmask(cpumask_t cpumask)
511 cpumask_t mask = CPU_MASK_NONE;
513 cpus_and(cpumask, cpu_online_map, cpumask);
515 for (i = 0; i < NR_CPUS; i++)
516 if (cpu_isset(i, cpumask))
517 cpu_set(smp_hw_index[i], mask);
522 #define physmask(cpumask) (cpumask)
525 void openpic_reset_processor_phys(u_int mask)
527 openpic_write(&OpenPIC->Global.Processor_Initialization, mask);
530 #if defined(CONFIG_SMP) || defined(CONFIG_PM)
531 static DEFINE_SPINLOCK(openpic_setup_lock);
536 * Initialize an interprocessor interrupt (and disable it)
538 * ipi: OpenPIC interprocessor interrupt number
539 * pri: interrupt source priority
540 * vec: the vector it will produce
542 static void __init openpic_initipi(u_int ipi, u_int pri, u_int vec)
547 openpic_safe_writefield_IPI(&OpenPIC->Global.IPI_Vector_Priority(ipi),
548 OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK,
549 (pri << OPENPIC_PRIORITY_SHIFT) | vec);
553 * Send an IPI to one or more CPUs
555 * Externally called, however, it takes an IPI number (0...OPENPIC_NUM_IPI)
556 * and not a system-wide interrupt number
558 void openpic_cause_IPI(u_int ipi, cpumask_t cpumask)
564 openpic_write(&OpenPIC->THIS_CPU.IPI_Dispatch(ipi),
565 cpus_addr(physmask(cpumask))[0]);
568 void openpic_request_IPIs(void)
573 * Make sure this matches what is defined in smp.c for
574 * smp_message_{pass|recv}() or what shows up in
575 * /proc/interrupts will be wrong!!! --Troy */
580 /* IPIs are marked SA_INTERRUPT as they must run with irqs disabled */
581 request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset,
582 openpic_ipi_action, SA_INTERRUPT,
583 "IPI0 (call function)", NULL);
584 request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset+1,
585 openpic_ipi_action, SA_INTERRUPT,
586 "IPI1 (reschedule)", NULL);
587 request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset+2,
588 openpic_ipi_action, SA_INTERRUPT,
589 "IPI2 (invalidate tlb)", NULL);
590 request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset+3,
591 openpic_ipi_action, SA_INTERRUPT,
592 "IPI3 (xmon break)", NULL);
594 for ( i = 0; i < OPENPIC_NUM_IPI ; i++ )
595 openpic_enable_ipi(OPENPIC_VEC_IPI+open_pic_irq_offset+i);
599 * Do per-cpu setup for SMP systems.
601 * Get IPI's working and start taking interrupts.
605 void __devinit do_openpic_setup_cpu(void)
607 #ifdef CONFIG_IRQ_ALL_CPUS
609 cpumask_t msk = CPU_MASK_NONE;
611 spin_lock(&openpic_setup_lock);
613 #ifdef CONFIG_IRQ_ALL_CPUS
614 cpu_set(smp_hw_index[smp_processor_id()], msk);
616 /* let the openpic know we want intrs. default affinity
617 * is 0xffffffff until changed via /proc
618 * That's how it's done on x86. If we want it differently, then
619 * we should make sure we also change the default values of irq_affinity
622 for (i = 0; i < NumSources; i++)
623 openpic_mapirq(i, msk, CPU_MASK_ALL);
624 #endif /* CONFIG_IRQ_ALL_CPUS */
625 openpic_set_priority(0);
627 spin_unlock(&openpic_setup_lock);
629 #endif /* CONFIG_SMP */
632 * Initialize a timer interrupt (and disable it)
634 * timer: OpenPIC timer number
635 * pri: interrupt source priority
636 * vec: the vector it will produce
638 static void __init openpic_inittimer(u_int timer, u_int pri, u_int vec)
640 check_arg_timer(timer);
643 openpic_safe_writefield(&OpenPIC->Global.Timer[timer].Vector_Priority,
644 OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK,
645 (pri << OPENPIC_PRIORITY_SHIFT) | vec);
649 * Map a timer interrupt to one or more CPUs
651 static void __init openpic_maptimer(u_int timer, cpumask_t cpumask)
653 cpumask_t phys = physmask(cpumask);
654 check_arg_timer(timer);
655 openpic_write(&OpenPIC->Global.Timer[timer].Destination,
660 * Change the priority of an interrupt
663 openpic_set_irq_priority(u_int irq, u_int pri)
666 openpic_safe_writefield(&ISR[irq - open_pic_irq_offset]->Vector_Priority,
667 OPENPIC_PRIORITY_MASK,
668 pri << OPENPIC_PRIORITY_SHIFT);
672 * Initalize the interrupt source which will generate an NMI.
673 * This raises the interrupt's priority from 8 to 9.
675 * irq: The logical IRQ which generates an NMI.
678 openpic_init_nmi_irq(u_int irq)
681 openpic_set_irq_priority(irq, OPENPIC_PRIORITY_NMI);
686 * All functions below take an offset'ed irq argument
691 * Hookup a cascade to the OpenPIC.
694 static struct irqaction openpic_cascade_irqaction = {
695 .handler = no_action,
696 .flags = SA_INTERRUPT,
697 .mask = CPU_MASK_NONE,
701 openpic_hookup_cascade(u_int irq, char *name,
702 int (*cascade_fn)(struct pt_regs *))
704 openpic_cascade_irq = irq;
705 openpic_cascade_fn = cascade_fn;
707 if (setup_irq(irq, &openpic_cascade_irqaction))
708 printk("Unable to get OpenPIC IRQ %d for cascade\n",
709 irq - open_pic_irq_offset);
713 * Enable/disable an external interrupt source
715 * Externally called, irq is an offseted system-wide interrupt number
717 static void openpic_enable_irq(u_int irq)
719 volatile u_int __iomem *vpp;
722 vpp = &ISR[irq - open_pic_irq_offset]->Vector_Priority;
723 openpic_clearfield(vpp, OPENPIC_MASK);
724 /* make sure mask gets to controller before we return to user */
726 mb(); /* sync is probably useless here */
727 } while (openpic_readfield(vpp, OPENPIC_MASK));
730 static void openpic_disable_irq(u_int irq)
732 volatile u_int __iomem *vpp;
736 vpp = &ISR[irq - open_pic_irq_offset]->Vector_Priority;
737 openpic_setfield(vpp, OPENPIC_MASK);
738 /* make sure mask gets to controller before we return to user */
740 mb(); /* sync is probably useless here */
741 vp = openpic_readfield(vpp, OPENPIC_MASK | OPENPIC_ACTIVITY);
742 } while((vp & OPENPIC_ACTIVITY) && !(vp & OPENPIC_MASK));
747 * Enable/disable an IPI interrupt source
749 * Externally called, irq is an offseted system-wide interrupt number
751 void openpic_enable_ipi(u_int irq)
753 irq -= (OPENPIC_VEC_IPI+open_pic_irq_offset);
755 openpic_clearfield_IPI(&OpenPIC->Global.IPI_Vector_Priority(irq), OPENPIC_MASK);
759 void openpic_disable_ipi(u_int irq)
761 irq -= (OPENPIC_VEC_IPI+open_pic_irq_offset);
763 openpic_setfield_IPI(&OpenPIC->Global.IPI_Vector_Priority(irq), OPENPIC_MASK);
768 * Initialize an interrupt source (and disable it!)
770 * irq: OpenPIC interrupt number
771 * pri: interrupt source priority
772 * vec: the vector it will produce
773 * pol: polarity (1 for positive, 0 for negative)
774 * sense: 1 for level, 0 for edge
777 openpic_initirq(u_int irq, u_int pri, u_int vec, int pol, int sense)
779 openpic_safe_writefield(&ISR[irq]->Vector_Priority,
780 OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK |
781 OPENPIC_SENSE_MASK | OPENPIC_POLARITY_MASK,
782 (pri << OPENPIC_PRIORITY_SHIFT) | vec |
783 (pol ? OPENPIC_POLARITY_POSITIVE :
784 OPENPIC_POLARITY_NEGATIVE) |
785 (sense ? OPENPIC_SENSE_LEVEL : OPENPIC_SENSE_EDGE));
789 * Map an interrupt source to one or more CPUs
791 static void openpic_mapirq(u_int irq, cpumask_t physmask, cpumask_t keepmask)
795 if (!cpus_empty(keepmask)) {
796 cpumask_t irqdest = { .bits[0] = openpic_read(&ISR[irq]->Destination) };
797 cpus_and(irqdest, irqdest, keepmask);
798 cpus_or(physmask, physmask, irqdest);
800 openpic_write(&ISR[irq]->Destination, cpus_addr(physmask)[0]);
805 * Set the sense for an interrupt source (and disable it!)
807 * sense: 1 for level, 0 for edge
809 static void openpic_set_sense(u_int irq, int sense)
812 openpic_safe_writefield(&ISR[irq]->Vector_Priority,
814 (sense ? OPENPIC_SENSE_LEVEL : 0));
818 /* No spinlocks, should not be necessary with the OpenPIC
819 * (1 register = 1 interrupt and we have the desc lock).
821 static void openpic_ack_irq(unsigned int irq_nr)
823 #ifdef __SLOW_VERSION__
824 openpic_disable_irq(irq_nr);
827 if ((irq_desc[irq_nr].status & IRQ_LEVEL) == 0)
832 static void openpic_end_irq(unsigned int irq_nr)
834 #ifdef __SLOW_VERSION__
835 if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))
836 && irq_desc[irq_nr].action)
837 openpic_enable_irq(irq_nr);
839 if ((irq_desc[irq_nr].status & IRQ_LEVEL) != 0)
844 static void openpic_set_affinity(unsigned int irq_nr, cpumask_t cpumask)
846 openpic_mapirq(irq_nr - open_pic_irq_offset, physmask(cpumask), CPU_MASK_NONE);
850 static void openpic_ack_ipi(unsigned int irq_nr)
855 static void openpic_end_ipi(unsigned int irq_nr)
859 static irqreturn_t openpic_ipi_action(int cpl, void *dev_id, struct pt_regs *regs)
861 smp_message_recv(cpl-OPENPIC_VEC_IPI-open_pic_irq_offset, regs);
865 #endif /* CONFIG_SMP */
868 openpic_get_irq(struct pt_regs *regs)
870 int irq = openpic_irq();
873 * Check for the cascade interrupt and call the cascaded
874 * interrupt controller function (usually i8259_irq) if so.
875 * This should move to irq.c eventually. -- paulus
877 if (irq == openpic_cascade_irq && openpic_cascade_fn != NULL) {
878 int cirq = openpic_cascade_fn(regs);
880 /* Allow for the cascade being shared with other devices */
885 } else if (irq == OPENPIC_VEC_SPURIOUS)
892 smp_openpic_message_pass(int target, int msg, unsigned long data, int wait)
894 cpumask_t mask = CPU_MASK_ALL;
895 /* make sure we're sending something that translates to an IPI */
897 printk("SMP %d: smp_message_pass: unknown msg %d\n",
898 smp_processor_id(), msg);
903 openpic_cause_IPI(msg, mask);
905 case MSG_ALL_BUT_SELF:
906 cpu_clear(smp_processor_id(), mask);
907 openpic_cause_IPI(msg, mask);
910 openpic_cause_IPI(msg, cpumask_of_cpu(target));
914 #endif /* CONFIG_SMP */
919 * We implement the IRQ controller as a sysdev and put it
920 * to sleep at powerdown stage (the callback is named suspend,
921 * but it's old semantics, for the Device Model, it's really
922 * powerdown). The possible problem is that another sysdev that
923 * happens to be suspend after this one will have interrupts off,
924 * that may be an issue... For now, this isn't an issue on pmac
928 static u32 save_ipi_vp[OPENPIC_NUM_IPI];
929 static u32 save_irq_src_vp[OPENPIC_MAX_SOURCES];
930 static u32 save_irq_src_dest[OPENPIC_MAX_SOURCES];
931 static u32 save_cpu_task_pri[OPENPIC_MAX_PROCESSORS];
932 static int openpic_suspend_count;
934 static void openpic_cached_enable_irq(u_int irq)
937 save_irq_src_vp[irq - open_pic_irq_offset] &= ~OPENPIC_MASK;
940 static void openpic_cached_disable_irq(u_int irq)
943 save_irq_src_vp[irq - open_pic_irq_offset] |= OPENPIC_MASK;
946 /* WARNING: Can be called directly by the cpufreq code with NULL parameter,
947 * we need something better to deal with that... Maybe switch to S1 for
950 int openpic_suspend(struct sys_device *sysdev, pm_message_t state)
955 spin_lock_irqsave(&openpic_setup_lock, flags);
957 if (openpic_suspend_count++ > 0) {
958 spin_unlock_irqrestore(&openpic_setup_lock, flags);
962 openpic_set_priority(0xf);
964 open_pic.enable = openpic_cached_enable_irq;
965 open_pic.disable = openpic_cached_disable_irq;
967 for (i=0; i<NumProcessors; i++) {
968 save_cpu_task_pri[i] = openpic_read(&OpenPIC->Processor[i].Current_Task_Priority);
969 openpic_writefield(&OpenPIC->Processor[i].Current_Task_Priority,
970 OPENPIC_CURRENT_TASK_PRIORITY_MASK, 0xf);
973 for (i=0; i<OPENPIC_NUM_IPI; i++)
974 save_ipi_vp[i] = openpic_read(&OpenPIC->Global.IPI_Vector_Priority(i));
975 for (i=0; i<NumSources; i++) {
978 save_irq_src_vp[i] = openpic_read(&ISR[i]->Vector_Priority) & ~OPENPIC_ACTIVITY;
979 save_irq_src_dest[i] = openpic_read(&ISR[i]->Destination);
982 spin_unlock_irqrestore(&openpic_setup_lock, flags);
987 /* WARNING: Can be called directly by the cpufreq code with NULL parameter,
988 * we need something better to deal with that... Maybe switch to S1 for
991 int openpic_resume(struct sys_device *sysdev)
995 u32 vppmask = OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK |
996 OPENPIC_SENSE_MASK | OPENPIC_POLARITY_MASK |
999 spin_lock_irqsave(&openpic_setup_lock, flags);
1001 if ((--openpic_suspend_count) > 0) {
1002 spin_unlock_irqrestore(&openpic_setup_lock, flags);
1006 /* OpenPIC sometimes seem to need some time to be fully back up... */
1008 openpic_set_spurious(OPENPIC_VEC_SPURIOUS);
1009 } while(openpic_readfield(&OpenPIC->Global.Spurious_Vector, OPENPIC_VECTOR_MASK)
1010 != OPENPIC_VEC_SPURIOUS);
1012 openpic_disable_8259_pass_through();
1014 for (i=0; i<OPENPIC_NUM_IPI; i++)
1015 openpic_write(&OpenPIC->Global.IPI_Vector_Priority(i),
1017 for (i=0; i<NumSources; i++) {
1020 openpic_write(&ISR[i]->Destination, save_irq_src_dest[i]);
1021 openpic_write(&ISR[i]->Vector_Priority, save_irq_src_vp[i]);
1022 /* make sure mask gets to controller before we return to user */
1024 openpic_write(&ISR[i]->Vector_Priority, save_irq_src_vp[i]);
1025 } while (openpic_readfield(&ISR[i]->Vector_Priority, vppmask)
1026 != (save_irq_src_vp[i] & vppmask));
1028 for (i=0; i<NumProcessors; i++)
1029 openpic_write(&OpenPIC->Processor[i].Current_Task_Priority,
1030 save_cpu_task_pri[i]);
1032 open_pic.enable = openpic_enable_irq;
1033 open_pic.disable = openpic_disable_irq;
1035 openpic_set_priority(0);
1037 spin_unlock_irqrestore(&openpic_setup_lock, flags);
1042 #endif /* CONFIG_PM */
1044 static struct sysdev_class openpic_sysclass = {
1045 set_kset_name("openpic"),
1048 static struct sys_device device_openpic = {
1050 .cls = &openpic_sysclass,
1053 static struct sysdev_driver driver_openpic = {
1055 .suspend = &openpic_suspend,
1056 .resume = &openpic_resume,
1057 #endif /* CONFIG_PM */
1060 static int __init init_openpic_sysfs(void)
1066 printk(KERN_DEBUG "Registering openpic with sysfs...\n");
1067 rc = sysdev_class_register(&openpic_sysclass);
1069 printk(KERN_ERR "Failed registering openpic sys class\n");
1072 rc = sysdev_register(&device_openpic);
1074 printk(KERN_ERR "Failed registering openpic sys device\n");
1077 rc = sysdev_driver_register(&openpic_sysclass, &driver_openpic);
1079 printk(KERN_ERR "Failed registering openpic sys driver\n");
1085 subsys_initcall(init_openpic_sysfs);