1 /* $Id: irq.c,v 1.114 2002/01/11 08:45:38 davem Exp $
2 * irq.c: UltraSparc IRQ handling/init/registry.
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/sched.h>
12 #include <linux/ptrace.h>
13 #include <linux/errno.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/signal.h>
17 #include <linux/interrupt.h>
18 #include <linux/slab.h>
19 #include <linux/random.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/proc_fs.h>
23 #include <linux/seq_file.h>
25 #include <asm/ptrace.h>
26 #include <asm/processor.h>
27 #include <asm/atomic.h>
28 #include <asm/system.h>
31 #include <asm/iommu.h>
33 #include <asm/oplib.h>
34 #include <asm/timer.h>
36 #include <asm/starfire.h>
37 #include <asm/uaccess.h>
38 #include <asm/cache.h>
39 #include <asm/cpudata.h>
40 #include <asm/auxio.h>
43 static void distribute_irqs(void);
46 /* UPA nodes send interrupt packet to UltraSparc with first data reg
47 * value low 5 (7 on Starfire) bits holding the IRQ identifier being
48 * delivered. We must translate this into a non-vector IRQ so we can
49 * set the softint on this cpu.
51 * To make processing these packets efficient and race free we use
52 * an array of irq buckets below. The interrupt vector handler in
53 * entry.S feeds incoming packets into per-cpu pil-indexed lists.
54 * The IVEC handler does not need to act atomically, the PIL dispatch
55 * code uses CAS to get an atomic snapshot of the list and clear it
59 struct ino_bucket ivector_table
[NUM_IVECS
] __attribute__ ((aligned (SMP_CACHE_BYTES
)));
61 /* This has to be in the main kernel image, it cannot be
62 * turned into per-cpu data. The reason is that the main
63 * kernel image is locked into the TLB and this structure
64 * is accessed from the vectored interrupt trap handler. If
65 * access to this structure takes a TLB miss it could cause
66 * the 5-level sparc v9 trap stack to overflow.
68 struct irq_work_struct
{
69 unsigned int irq_worklists
[16];
71 struct irq_work_struct __irq_work
[NR_CPUS
];
72 #define irq_work(__cpu, __pil) &(__irq_work[(__cpu)].irq_worklists[(__pil)])
74 static struct irqaction
*irq_action
[NR_IRQS
+1];
76 /* This only synchronizes entities which modify IRQ handler
77 * state and some selected user-level spots that want to
78 * read things in the table. IRQ handler processing orders
79 * its' accesses such that no locking is needed.
81 static DEFINE_SPINLOCK(irq_action_lock
);
83 static void register_irq_proc (unsigned int irq
);
86 * Upper 2b of irqaction->flags holds the ino.
87 * irqaction->mask holds the smp affinity information.
89 #define put_ino_in_irqaction(action, irq) \
90 action->flags &= 0xffffffffffffUL; \
91 if (__bucket(irq) == &pil0_dummy_bucket) \
92 action->flags |= 0xdeadUL << 48; \
94 action->flags |= __irq_ino(irq) << 48;
95 #define get_ino_in_irqaction(action) (action->flags >> 48)
97 #define put_smpaff_in_irqaction(action, smpaff) (action)->mask = (smpaff)
98 #define get_smpaff_in_irqaction(action) ((action)->mask)
100 int show_interrupts(struct seq_file
*p
, void *v
)
103 int i
= *(loff_t
*) v
;
104 struct irqaction
*action
;
109 spin_lock_irqsave(&irq_action_lock
, flags
);
111 if (!(action
= *(i
+ irq_action
)))
113 seq_printf(p
, "%3d: ", i
);
115 seq_printf(p
, "%10u ", kstat_irqs(i
));
117 for (j
= 0; j
< NR_CPUS
; j
++) {
120 seq_printf(p
, "%10u ",
121 kstat_cpu(j
).irqs
[i
]);
124 seq_printf(p
, " %s:%lx", action
->name
,
125 get_ino_in_irqaction(action
));
126 for (action
= action
->next
; action
; action
= action
->next
) {
127 seq_printf(p
, ", %s:%lx", action
->name
,
128 get_ino_in_irqaction(action
));
133 spin_unlock_irqrestore(&irq_action_lock
, flags
);
138 /* Now these are always passed a true fully specified sun4u INO. */
139 void enable_irq(unsigned int irq
)
141 struct ino_bucket
*bucket
= __bucket(irq
);
151 if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
154 __asm__ ("rdpr %%ver, %0" : "=r" (ver
));
155 if ((ver
>> 32) == 0x003e0016) {
156 /* We set it to our JBUS ID. */
157 __asm__
__volatile__("ldxa [%%g0] %1, %0"
159 : "i" (ASI_JBUS_CONFIG
));
160 tid
= ((tid
& (0x1fUL
<<17)) << 9);
161 tid
&= IMAP_TID_JBUS
;
163 /* We set it to our Safari AID. */
164 __asm__
__volatile__("ldxa [%%g0] %1, %0"
166 : "i" (ASI_SAFARI_CONFIG
));
167 tid
= ((tid
& (0x3ffUL
<<17)) << 9);
168 tid
&= IMAP_AID_SAFARI
;
170 } else if (this_is_starfire
== 0) {
171 /* We set it to our UPA MID. */
172 __asm__
__volatile__("ldxa [%%g0] %1, %0"
174 : "i" (ASI_UPA_CONFIG
));
175 tid
= ((tid
& UPA_CONFIG_MID
) << 9);
178 tid
= (starfire_translate(imap
, smp_processor_id()) << 26);
182 /* NOTE NOTE NOTE, IGN and INO are read-only, IGN is a product
183 * of this SYSIO's preconfigured IGN in the SYSIO Control
184 * Register, the hardware just mirrors that value here.
185 * However for Graphics and UPA Slave devices the full
186 * IMAP_INR field can be set by the programmer here.
188 * Things like FFB can now be handled via the new IRQ mechanism.
190 upa_writel(tid
| IMAP_VALID
, imap
);
195 /* This now gets passed true ino's as well. */
196 void disable_irq(unsigned int irq
)
198 struct ino_bucket
*bucket
= __bucket(irq
);
205 /* NOTE: We do not want to futz with the IRQ clear registers
206 * and move the state to IDLE, the SCSI code does call
207 * disable_irq() to assure atomicity in the queue cmd
208 * SCSI adapter driver code. Thus we'd lose interrupts.
210 tmp
= upa_readl(imap
);
212 upa_writel(tmp
, imap
);
216 /* The timer is the one "weird" interrupt which is generated by
217 * the CPU %tick register and not by some normal vectored interrupt
218 * source. To handle this special case, we use this dummy INO bucket.
220 static struct irq_desc pil0_dummy_desc
;
221 static struct ino_bucket pil0_dummy_bucket
= {
222 .irq_info
= &pil0_dummy_desc
,
225 static void build_irq_error(const char *msg
, unsigned int ino
, int pil
, int inofixup
,
226 unsigned long iclr
, unsigned long imap
,
227 struct ino_bucket
*bucket
)
229 prom_printf("IRQ: INO %04x (%d:%016lx:%016lx) --> "
230 "(%d:%d:%016lx:%016lx), halting...\n",
231 ino
, bucket
->pil
, bucket
->iclr
, bucket
->imap
,
232 pil
, inofixup
, iclr
, imap
);
236 unsigned int build_irq(int pil
, int inofixup
, unsigned long iclr
, unsigned long imap
)
238 struct ino_bucket
*bucket
;
242 if (iclr
!= 0UL || imap
!= 0UL) {
243 prom_printf("Invalid dummy bucket for PIL0 (%lx:%lx)\n",
247 return __irq(&pil0_dummy_bucket
);
250 /* RULE: Both must be specified in all other cases. */
251 if (iclr
== 0UL || imap
== 0UL) {
252 prom_printf("Invalid build_irq %d %d %016lx %016lx\n",
253 pil
, inofixup
, iclr
, imap
);
257 ino
= (upa_readl(imap
) & (IMAP_IGN
| IMAP_INO
)) + inofixup
;
258 if (ino
> NUM_IVECS
) {
259 prom_printf("Invalid INO %04x (%d:%d:%016lx:%016lx)\n",
260 ino
, pil
, inofixup
, iclr
, imap
);
264 bucket
= &ivector_table
[ino
];
265 if (bucket
->flags
& IBF_ACTIVE
)
266 build_irq_error("IRQ: Trying to build active INO bucket.\n",
267 ino
, pil
, inofixup
, iclr
, imap
, bucket
);
269 if (bucket
->irq_info
) {
270 if (bucket
->imap
!= imap
|| bucket
->iclr
!= iclr
)
271 build_irq_error("IRQ: Trying to reinit INO bucket.\n",
272 ino
, pil
, inofixup
, iclr
, imap
, bucket
);
277 bucket
->irq_info
= kmalloc(sizeof(struct irq_desc
), GFP_ATOMIC
);
278 if (!bucket
->irq_info
) {
279 prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n");
282 memset(bucket
->irq_info
, 0, sizeof(struct irq_desc
));
284 /* Ok, looks good, set it up. Don't touch the irq_chain or
293 return __irq(bucket
);
296 static void atomic_bucket_insert(struct ino_bucket
*bucket
)
298 unsigned long pstate
;
301 __asm__
__volatile__("rdpr %%pstate, %0" : "=r" (pstate
));
302 __asm__
__volatile__("wrpr %0, %1, %%pstate"
303 : : "r" (pstate
), "i" (PSTATE_IE
));
304 ent
= irq_work(smp_processor_id(), bucket
->pil
);
305 bucket
->irq_chain
= *ent
;
306 *ent
= __irq(bucket
);
307 __asm__
__volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate
));
310 static int check_irq_sharing(int pil
, unsigned long irqflags
)
312 struct irqaction
*action
, *tmp
;
314 action
= *(irq_action
+ pil
);
316 if ((action
->flags
& SA_SHIRQ
) && (irqflags
& SA_SHIRQ
)) {
317 for (tmp
= action
; tmp
->next
; tmp
= tmp
->next
)
326 static void append_irq_action(int pil
, struct irqaction
*action
)
328 struct irqaction
**pp
= irq_action
+ pil
;
335 static struct irqaction
*get_action_slot(struct ino_bucket
*bucket
)
337 struct irq_desc
*desc
= bucket
->irq_info
;
341 if (bucket
->flags
& IBF_PCI
)
342 max_irq
= MAX_IRQ_DESC_ACTION
;
343 for (i
= 0; i
< max_irq
; i
++) {
344 struct irqaction
*p
= &desc
->action
[i
];
347 if (desc
->action_active_mask
& mask
)
350 desc
->action_active_mask
|= mask
;
356 int request_irq(unsigned int irq
, irqreturn_t (*handler
)(int, void *, struct pt_regs
*),
357 unsigned long irqflags
, const char *name
, void *dev_id
)
359 struct irqaction
*action
;
360 struct ino_bucket
*bucket
= __bucket(irq
);
364 if (unlikely(!handler
))
367 if (unlikely(!bucket
->irq_info
))
370 if ((bucket
!= &pil0_dummy_bucket
) && (irqflags
& SA_SAMPLE_RANDOM
)) {
372 * This function might sleep, we want to call it first,
373 * outside of the atomic block. In SA_STATIC_ALLOC case,
374 * random driver's kmalloc will fail, but it is safe.
375 * If already initialized, random driver will not reinit.
376 * Yes, this might clear the entropy pool if the wrong
377 * driver is attempted to be loaded, without actually
378 * installing a new handler, but is this really a problem,
379 * only the sysadmin is able to do this.
381 rand_initialize_irq(irq
);
384 spin_lock_irqsave(&irq_action_lock
, flags
);
386 if (check_irq_sharing(bucket
->pil
, irqflags
)) {
387 spin_unlock_irqrestore(&irq_action_lock
, flags
);
391 action
= get_action_slot(bucket
);
393 spin_unlock_irqrestore(&irq_action_lock
, flags
);
397 bucket
->flags
|= IBF_ACTIVE
;
399 if (bucket
!= &pil0_dummy_bucket
) {
400 pending
= bucket
->pending
;
405 action
->handler
= handler
;
406 action
->flags
= irqflags
;
409 action
->dev_id
= dev_id
;
410 put_ino_in_irqaction(action
, irq
);
411 put_smpaff_in_irqaction(action
, CPU_MASK_NONE
);
413 append_irq_action(bucket
->pil
, action
);
417 /* We ate the IVEC already, this makes sure it does not get lost. */
419 atomic_bucket_insert(bucket
);
420 set_softint(1 << bucket
->pil
);
423 spin_unlock_irqrestore(&irq_action_lock
, flags
);
425 if (bucket
!= &pil0_dummy_bucket
)
426 register_irq_proc(__irq_ino(irq
));
434 EXPORT_SYMBOL(request_irq
);
436 static struct irqaction
*unlink_irq_action(unsigned int irq
, void *dev_id
)
438 struct ino_bucket
*bucket
= __bucket(irq
);
439 struct irqaction
*action
, **pp
;
441 pp
= irq_action
+ bucket
->pil
;
443 if (unlikely(!action
))
446 if (unlikely(!action
->handler
)) {
447 printk("Freeing free IRQ %d\n", bucket
->pil
);
451 while (action
&& action
->dev_id
!= dev_id
) {
462 void free_irq(unsigned int irq
, void *dev_id
)
464 struct irqaction
*action
;
465 struct ino_bucket
*bucket
;
468 spin_lock_irqsave(&irq_action_lock
, flags
);
470 action
= unlink_irq_action(irq
, dev_id
);
472 spin_unlock_irqrestore(&irq_action_lock
, flags
);
474 if (unlikely(!action
))
477 synchronize_irq(irq
);
479 spin_lock_irqsave(&irq_action_lock
, flags
);
481 bucket
= __bucket(irq
);
482 if (bucket
!= &pil0_dummy_bucket
) {
483 struct irq_desc
*desc
= bucket
->irq_info
;
484 unsigned long imap
= bucket
->imap
;
487 for (i
= 0; i
< MAX_IRQ_DESC_ACTION
; i
++) {
488 struct irqaction
*p
= &desc
->action
[i
];
491 desc
->action_active_mask
&= ~(1 << i
);
496 if (!desc
->action_active_mask
) {
497 /* This unique interrupt source is now inactive. */
498 bucket
->flags
&= ~IBF_ACTIVE
;
500 /* See if any other buckets share this bucket's IMAP
501 * and are still active.
503 for (ent
= 0; ent
< NUM_IVECS
; ent
++) {
504 struct ino_bucket
*bp
= &ivector_table
[ent
];
507 (bp
->flags
& IBF_ACTIVE
) != 0)
511 /* Only disable when no other sub-irq levels of
512 * the same IMAP are active.
514 if (ent
== NUM_IVECS
)
519 spin_unlock_irqrestore(&irq_action_lock
, flags
);
522 EXPORT_SYMBOL(free_irq
);
525 void synchronize_irq(unsigned int irq
)
527 struct ino_bucket
*bucket
= __bucket(irq
);
530 /* The following is how I wish I could implement this.
531 * Unfortunately the ICLR registers are read-only, you can
532 * only write ICLR_foo values to them. To get the current
533 * IRQ status you would need to get at the IRQ diag registers
534 * in the PCI/SBUS controller and the layout of those vary
535 * from one controller to the next, sigh... -DaveM
537 unsigned long iclr
= bucket
->iclr
;
540 u32 tmp
= upa_readl(iclr
);
542 if (tmp
== ICLR_TRANSMIT
||
543 tmp
== ICLR_PENDING
) {
550 /* So we have to do this with a INPROGRESS bit just like x86. */
551 while (bucket
->flags
& IBF_INPROGRESS
)
555 #endif /* CONFIG_SMP */
557 static void process_bucket(int irq
, struct ino_bucket
*bp
, struct pt_regs
*regs
)
559 struct irq_desc
*desc
= bp
->irq_info
;
560 unsigned char flags
= bp
->flags
;
564 bp
->flags
|= IBF_INPROGRESS
;
566 if (unlikely(!(flags
& IBF_ACTIVE
))) {
571 if (desc
->pre_handler
)
572 desc
->pre_handler(bp
,
573 desc
->pre_handler_arg1
,
574 desc
->pre_handler_arg2
);
576 action_mask
= desc
->action_active_mask
;
578 for (i
= 0; i
< MAX_IRQ_DESC_ACTION
; i
++) {
579 struct irqaction
*p
= &desc
->action
[i
];
582 if (!(action_mask
& mask
))
585 action_mask
&= ~mask
;
587 if (p
->handler(__irq(bp
), p
->dev_id
, regs
) == IRQ_HANDLED
)
594 upa_writel(ICLR_IDLE
, bp
->iclr
);
595 /* Test and add entropy */
596 if (random
& SA_SAMPLE_RANDOM
)
597 add_interrupt_randomness(irq
);
600 bp
->flags
&= ~IBF_INPROGRESS
;
603 void handler_irq(int irq
, struct pt_regs
*regs
)
605 struct ino_bucket
*bp
;
606 int cpu
= smp_processor_id();
610 * Check for TICK_INT on level 14 softint.
613 unsigned long clr_mask
= 1 << irq
;
614 unsigned long tick_mask
= tick_ops
->softint_mask
;
616 if ((irq
== 14) && (get_softint() & tick_mask
)) {
618 clr_mask
= tick_mask
;
620 clear_softint(clr_mask
);
623 clear_softint(1 << irq
);
627 kstat_this_cpu
.irqs
[irq
]++;
632 __bucket(xchg32(irq_work(cpu
, irq
), 0)) :
635 bp
= __bucket(xchg32(irq_work(cpu
, irq
), 0));
638 struct ino_bucket
*nbp
= __bucket(bp
->irq_chain
);
641 process_bucket(irq
, bp
, regs
);
647 #ifdef CONFIG_BLK_DEV_FD
648 extern irqreturn_t
floppy_interrupt(int, void *, struct pt_regs
*);;
650 /* XXX No easy way to include asm/floppy.h XXX */
651 extern unsigned char *pdma_vaddr
;
652 extern unsigned long pdma_size
;
653 extern volatile int doing_pdma
;
654 extern unsigned long fdc_status
;
656 irqreturn_t
sparc_floppy_irq(int irq
, void *dev_cookie
, struct pt_regs
*regs
)
658 if (likely(doing_pdma
)) {
659 void __iomem
*stat
= (void __iomem
*) fdc_status
;
660 unsigned char *vaddr
= pdma_vaddr
;
661 unsigned long size
= pdma_size
;
666 if (unlikely(!(val
& 0x80))) {
671 if (unlikely(!(val
& 0x20))) {
679 *vaddr
++ = readb(stat
+ 1);
681 unsigned char data
= *vaddr
++;
684 writeb(data
, stat
+ 1);
692 /* Send Terminal Count pulse to floppy controller. */
693 val
= readb(auxio_register
);
694 val
|= AUXIO_AUX1_FTCNT
;
695 writeb(val
, auxio_register
);
696 val
&= AUXIO_AUX1_FTCNT
;
697 writeb(val
, auxio_register
);
703 return floppy_interrupt(irq
, dev_cookie
, regs
);
705 EXPORT_SYMBOL(sparc_floppy_irq
);
708 /* We really don't need these at all on the Sparc. We only have
709 * stubs here because they are exported to modules.
711 unsigned long probe_irq_on(void)
716 EXPORT_SYMBOL(probe_irq_on
);
718 int probe_irq_off(unsigned long mask
)
723 EXPORT_SYMBOL(probe_irq_off
);
726 static int retarget_one_irq(struct irqaction
*p
, int goal_cpu
)
728 struct ino_bucket
*bucket
= get_ino_in_irqaction(p
) + ivector_table
;
729 unsigned long imap
= bucket
->imap
;
732 while (!cpu_online(goal_cpu
)) {
733 if (++goal_cpu
>= NR_CPUS
)
737 if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
738 tid
= goal_cpu
<< 26;
739 tid
&= IMAP_AID_SAFARI
;
740 } else if (this_is_starfire
== 0) {
741 tid
= goal_cpu
<< 26;
744 tid
= (starfire_translate(imap
, goal_cpu
) << 26);
747 upa_writel(tid
| IMAP_VALID
, imap
);
750 if (++goal_cpu
>= NR_CPUS
)
752 } while (!cpu_online(goal_cpu
));
757 /* Called from request_irq. */
758 static void distribute_irqs(void)
763 spin_lock_irqsave(&irq_action_lock
, flags
);
767 * Skip the timer at [0], and very rare error/power intrs at [15].
768 * Also level [12], it causes problems on Ex000 systems.
770 for (level
= 1; level
< NR_IRQS
; level
++) {
771 struct irqaction
*p
= irq_action
[level
];
777 cpu
= retarget_one_irq(p
, cpu
);
781 spin_unlock_irqrestore(&irq_action_lock
, flags
);
792 static struct sun5_timer
*prom_timers
;
793 static u64 prom_limit0
, prom_limit1
;
795 static void map_prom_timers(void)
797 unsigned int addr
[3];
800 /* PROM timer node hangs out in the top level of device siblings... */
801 tnode
= prom_finddevice("/counter-timer");
803 /* Assume if node is not present, PROM uses different tick mechanism
804 * which we should not care about.
806 if (tnode
== 0 || tnode
== -1) {
807 prom_timers
= (struct sun5_timer
*) 0;
811 /* If PROM is really using this, it must be mapped by him. */
812 err
= prom_getproperty(tnode
, "address", (char *)addr
, sizeof(addr
));
814 prom_printf("PROM does not have timer mapped, trying to continue.\n");
815 prom_timers
= (struct sun5_timer
*) 0;
818 prom_timers
= (struct sun5_timer
*) ((unsigned long)addr
[0]);
821 static void kill_prom_timer(void)
826 /* Save them away for later. */
827 prom_limit0
= prom_timers
->limit0
;
828 prom_limit1
= prom_timers
->limit1
;
830 /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
831 * We turn both off here just to be paranoid.
833 prom_timers
->limit0
= 0;
834 prom_timers
->limit1
= 0;
836 /* Wheee, eat the interrupt packet too... */
837 __asm__
__volatile__(
839 " ldxa [%%g0] %0, %%g1\n"
840 " ldxa [%%g2] %1, %%g1\n"
841 " stxa %%g0, [%%g0] %0\n"
844 : "i" (ASI_INTR_RECEIVE
), "i" (ASI_INTR_R
)
848 void init_irqwork_curcpu(void)
850 register struct irq_work_struct
*workp
asm("o2");
851 register unsigned long tmp
asm("o3");
852 int cpu
= hard_smp_processor_id();
854 memset(__irq_work
+ cpu
, 0, sizeof(*workp
));
856 /* Make sure we are called with PSTATE_IE disabled. */
857 __asm__
__volatile__("rdpr %%pstate, %0\n\t"
859 if (tmp
& PSTATE_IE
) {
860 prom_printf("BUG: init_irqwork_curcpu() called with "
861 "PSTATE_IE enabled, bailing.\n");
862 __asm__
__volatile__("mov %%i7, %0\n\t"
864 prom_printf("BUG: Called from %lx\n", tmp
);
868 /* Set interrupt globals. */
869 workp
= &__irq_work
[cpu
];
870 __asm__
__volatile__(
871 "rdpr %%pstate, %0\n\t"
872 "wrpr %0, %1, %%pstate\n\t"
874 "wrpr %0, 0x0, %%pstate\n\t"
876 : "i" (PSTATE_IG
), "r" (workp
));
879 /* Only invoked on boot processor. */
880 void __init
init_IRQ(void)
884 memset(&ivector_table
[0], 0, sizeof(ivector_table
));
886 /* We need to clear any IRQ's pending in the soft interrupt
887 * registers, a spurious one could be left around from the
888 * PROM timer which we just disabled.
890 clear_softint(get_softint());
892 /* Now that ivector table is initialized, it is safe
893 * to receive IRQ vector traps. We will normally take
894 * one or two right now, in case some device PROM used
895 * to boot us wants to speak to us. We just ignore them.
897 __asm__
__volatile__("rdpr %%pstate, %%g1\n\t"
898 "or %%g1, %0, %%g1\n\t"
899 "wrpr %%g1, 0x0, %%pstate"
905 static struct proc_dir_entry
* root_irq_dir
;
906 static struct proc_dir_entry
* irq_dir
[NUM_IVECS
];
910 static int irq_affinity_read_proc (char *page
, char **start
, off_t off
,
911 int count
, int *eof
, void *data
)
913 struct ino_bucket
*bp
= ivector_table
+ (long)data
;
914 struct irq_desc
*desc
= bp
->irq_info
;
915 struct irqaction
*ap
= desc
->action
;
919 mask
= get_smpaff_in_irqaction(ap
);
920 if (cpus_empty(mask
))
921 mask
= cpu_online_map
;
923 len
= cpumask_scnprintf(page
, count
, mask
);
926 len
+= sprintf(page
+ len
, "\n");
930 static inline void set_intr_affinity(int irq
, cpumask_t hw_aff
)
932 struct ino_bucket
*bp
= ivector_table
+ irq
;
933 struct irq_desc
*desc
= bp
->irq_info
;
934 struct irqaction
*ap
= desc
->action
;
936 /* Users specify affinity in terms of hw cpu ids.
937 * As soon as we do this, handler_irq() might see and take action.
939 put_smpaff_in_irqaction(ap
, hw_aff
);
941 /* Migration is simply done by the next cpu to service this
946 static int irq_affinity_write_proc (struct file
*file
, const char __user
*buffer
,
947 unsigned long count
, void *data
)
949 int irq
= (long) data
, full_count
= count
, err
;
952 err
= cpumask_parse(buffer
, count
, new_value
);
955 * Do not allow disabling IRQs completely - it's a too easy
956 * way to make the system unusable accidentally :-) At least
957 * one online CPU still has to be targeted.
959 cpus_and(new_value
, new_value
, cpu_online_map
);
960 if (cpus_empty(new_value
))
963 set_intr_affinity(irq
, new_value
);
970 #define MAX_NAMELEN 10
972 static void register_irq_proc (unsigned int irq
)
974 char name
[MAX_NAMELEN
];
976 if (!root_irq_dir
|| irq_dir
[irq
])
979 memset(name
, 0, MAX_NAMELEN
);
980 sprintf(name
, "%x", irq
);
982 /* create /proc/irq/1234 */
983 irq_dir
[irq
] = proc_mkdir(name
, root_irq_dir
);
986 /* XXX SMP affinity not supported on starfire yet. */
987 if (this_is_starfire
== 0) {
988 struct proc_dir_entry
*entry
;
990 /* create /proc/irq/1234/smp_affinity */
991 entry
= create_proc_entry("smp_affinity", 0600, irq_dir
[irq
]);
995 entry
->data
= (void *)(long)irq
;
996 entry
->read_proc
= irq_affinity_read_proc
;
997 entry
->write_proc
= irq_affinity_write_proc
;
1003 void init_irq_proc (void)
1005 /* create /proc/irq */
1006 root_irq_dir
= proc_mkdir("irq", NULL
);