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>
42 static void distribute_irqs(void);
45 /* UPA nodes send interrupt packet to UltraSparc with first data reg
46 * value low 5 (7 on Starfire) bits holding the IRQ identifier being
47 * delivered. We must translate this into a non-vector IRQ so we can
48 * set the softint on this cpu.
50 * To make processing these packets efficient and race free we use
51 * an array of irq buckets below. The interrupt vector handler in
52 * entry.S feeds incoming packets into per-cpu pil-indexed lists.
53 * The IVEC handler does not need to act atomically, the PIL dispatch
54 * code uses CAS to get an atomic snapshot of the list and clear it
58 struct ino_bucket ivector_table
[NUM_IVECS
] __attribute__ ((aligned (SMP_CACHE_BYTES
)));
60 /* This has to be in the main kernel image, it cannot be
61 * turned into per-cpu data. The reason is that the main
62 * kernel image is locked into the TLB and this structure
63 * is accessed from the vectored interrupt trap handler. If
64 * access to this structure takes a TLB miss it could cause
65 * the 5-level sparc v9 trap stack to overflow.
67 struct irq_work_struct
{
68 unsigned int irq_worklists
[16];
70 struct irq_work_struct __irq_work
[NR_CPUS
];
71 #define irq_work(__cpu, __pil) &(__irq_work[(__cpu)].irq_worklists[(__pil)])
74 /* This is a table of physical addresses used to deal with IBF_DMA_SYNC.
75 * It is used for PCI only to synchronize DMA transfers with IRQ delivery
76 * for devices behind busses other than APB on Sabre systems.
78 * Currently these physical addresses are just config space accesses
79 * to the command register for that device.
81 unsigned long pci_dma_wsync
;
82 unsigned long dma_sync_reg_table
[256];
83 unsigned char dma_sync_reg_table_entry
= 0;
86 /* This is based upon code in the 32-bit Sparc kernel written mostly by
87 * David Redman (djhr@tadpole.co.uk).
89 #define MAX_STATIC_ALLOC 4
90 static struct irqaction static_irqaction
[MAX_STATIC_ALLOC
];
91 static int static_irq_count
;
93 /* This is exported so that fast IRQ handlers can get at it... -DaveM */
94 struct irqaction
*irq_action
[NR_IRQS
+1] = {
95 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
96 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
99 /* This only synchronizes entities which modify IRQ handler
100 * state and some selected user-level spots that want to
101 * read things in the table. IRQ handler processing orders
102 * its' accesses such that no locking is needed.
104 static DEFINE_SPINLOCK(irq_action_lock
);
106 static void register_irq_proc (unsigned int irq
);
109 * Upper 2b of irqaction->flags holds the ino.
110 * irqaction->mask holds the smp affinity information.
112 #define put_ino_in_irqaction(action, irq) \
113 action->flags &= 0xffffffffffffUL; \
114 if (__bucket(irq) == &pil0_dummy_bucket) \
115 action->flags |= 0xdeadUL << 48; \
117 action->flags |= __irq_ino(irq) << 48;
118 #define get_ino_in_irqaction(action) (action->flags >> 48)
120 #define put_smpaff_in_irqaction(action, smpaff) (action)->mask = (smpaff)
121 #define get_smpaff_in_irqaction(action) ((action)->mask)
123 int show_interrupts(struct seq_file
*p
, void *v
)
126 int i
= *(loff_t
*) v
;
127 struct irqaction
*action
;
132 spin_lock_irqsave(&irq_action_lock
, flags
);
134 if (!(action
= *(i
+ irq_action
)))
136 seq_printf(p
, "%3d: ", i
);
138 seq_printf(p
, "%10u ", kstat_irqs(i
));
140 for (j
= 0; j
< NR_CPUS
; j
++) {
143 seq_printf(p
, "%10u ",
144 kstat_cpu(j
).irqs
[i
]);
147 seq_printf(p
, " %s:%lx", action
->name
,
148 get_ino_in_irqaction(action
));
149 for (action
= action
->next
; action
; action
= action
->next
) {
150 seq_printf(p
, ", %s:%lx", action
->name
,
151 get_ino_in_irqaction(action
));
156 spin_unlock_irqrestore(&irq_action_lock
, flags
);
161 /* Now these are always passed a true fully specified sun4u INO. */
162 void enable_irq(unsigned int irq
)
164 struct ino_bucket
*bucket
= __bucket(irq
);
174 if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
177 __asm__ ("rdpr %%ver, %0" : "=r" (ver
));
178 if ((ver
>> 32) == 0x003e0016) {
179 /* We set it to our JBUS ID. */
180 __asm__
__volatile__("ldxa [%%g0] %1, %0"
182 : "i" (ASI_JBUS_CONFIG
));
183 tid
= ((tid
& (0x1fUL
<<17)) << 9);
184 tid
&= IMAP_TID_JBUS
;
186 /* We set it to our Safari AID. */
187 __asm__
__volatile__("ldxa [%%g0] %1, %0"
189 : "i" (ASI_SAFARI_CONFIG
));
190 tid
= ((tid
& (0x3ffUL
<<17)) << 9);
191 tid
&= IMAP_AID_SAFARI
;
193 } else if (this_is_starfire
== 0) {
194 /* We set it to our UPA MID. */
195 __asm__
__volatile__("ldxa [%%g0] %1, %0"
197 : "i" (ASI_UPA_CONFIG
));
198 tid
= ((tid
& UPA_CONFIG_MID
) << 9);
201 tid
= (starfire_translate(imap
, smp_processor_id()) << 26);
205 /* NOTE NOTE NOTE, IGN and INO are read-only, IGN is a product
206 * of this SYSIO's preconfigured IGN in the SYSIO Control
207 * Register, the hardware just mirrors that value here.
208 * However for Graphics and UPA Slave devices the full
209 * IMAP_INR field can be set by the programmer here.
211 * Things like FFB can now be handled via the new IRQ mechanism.
213 upa_writel(tid
| IMAP_VALID
, imap
);
218 /* This now gets passed true ino's as well. */
219 void disable_irq(unsigned int irq
)
221 struct ino_bucket
*bucket
= __bucket(irq
);
228 /* NOTE: We do not want to futz with the IRQ clear registers
229 * and move the state to IDLE, the SCSI code does call
230 * disable_irq() to assure atomicity in the queue cmd
231 * SCSI adapter driver code. Thus we'd lose interrupts.
233 tmp
= upa_readl(imap
);
235 upa_writel(tmp
, imap
);
239 /* The timer is the one "weird" interrupt which is generated by
240 * the CPU %tick register and not by some normal vectored interrupt
241 * source. To handle this special case, we use this dummy INO bucket.
243 static struct ino_bucket pil0_dummy_bucket
= {
254 unsigned int build_irq(int pil
, int inofixup
, unsigned long iclr
, unsigned long imap
)
256 struct ino_bucket
*bucket
;
260 if (iclr
!= 0UL || imap
!= 0UL) {
261 prom_printf("Invalid dummy bucket for PIL0 (%lx:%lx)\n",
265 return __irq(&pil0_dummy_bucket
);
268 /* RULE: Both must be specified in all other cases. */
269 if (iclr
== 0UL || imap
== 0UL) {
270 prom_printf("Invalid build_irq %d %d %016lx %016lx\n",
271 pil
, inofixup
, iclr
, imap
);
275 ino
= (upa_readl(imap
) & (IMAP_IGN
| IMAP_INO
)) + inofixup
;
276 if (ino
> NUM_IVECS
) {
277 prom_printf("Invalid INO %04x (%d:%d:%016lx:%016lx)\n",
278 ino
, pil
, inofixup
, iclr
, imap
);
282 /* Ok, looks good, set it up. Don't touch the irq_chain or
285 bucket
= &ivector_table
[ino
];
286 if ((bucket
->flags
& IBF_ACTIVE
) ||
287 (bucket
->irq_info
!= NULL
)) {
288 /* This is a gross fatal error if it happens here. */
289 prom_printf("IRQ: Trying to reinit INO bucket, fatal error.\n");
290 prom_printf("IRQ: Request INO %04x (%d:%d:%016lx:%016lx)\n",
291 ino
, pil
, inofixup
, iclr
, imap
);
292 prom_printf("IRQ: Existing (%d:%016lx:%016lx)\n",
293 bucket
->pil
, bucket
->iclr
, bucket
->imap
);
294 prom_printf("IRQ: Cannot continue, halting...\n");
302 bucket
->irq_info
= NULL
;
304 return __irq(bucket
);
307 static void atomic_bucket_insert(struct ino_bucket
*bucket
)
309 unsigned long pstate
;
312 __asm__
__volatile__("rdpr %%pstate, %0" : "=r" (pstate
));
313 __asm__
__volatile__("wrpr %0, %1, %%pstate"
314 : : "r" (pstate
), "i" (PSTATE_IE
));
315 ent
= irq_work(smp_processor_id(), bucket
->pil
);
316 bucket
->irq_chain
= *ent
;
317 *ent
= __irq(bucket
);
318 __asm__
__volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate
));
321 int request_irq(unsigned int irq
, irqreturn_t (*handler
)(int, void *, struct pt_regs
*),
322 unsigned long irqflags
, const char *name
, void *dev_id
)
324 struct irqaction
*action
, *tmp
= NULL
;
325 struct ino_bucket
*bucket
= __bucket(irq
);
329 if ((bucket
!= &pil0_dummy_bucket
) &&
330 (bucket
< &ivector_table
[0] ||
331 bucket
>= &ivector_table
[NUM_IVECS
])) {
332 unsigned int *caller
;
334 __asm__
__volatile__("mov %%i7, %0" : "=r" (caller
));
335 printk(KERN_CRIT
"request_irq: Old style IRQ registry attempt "
336 "from %p, irq %08x.\n", caller
, irq
);
342 if ((bucket
!= &pil0_dummy_bucket
) && (irqflags
& SA_SAMPLE_RANDOM
)) {
344 * This function might sleep, we want to call it first,
345 * outside of the atomic block. In SA_STATIC_ALLOC case,
346 * random driver's kmalloc will fail, but it is safe.
347 * If already initialized, random driver will not reinit.
348 * Yes, this might clear the entropy pool if the wrong
349 * driver is attempted to be loaded, without actually
350 * installing a new handler, but is this really a problem,
351 * only the sysadmin is able to do this.
353 rand_initialize_irq(irq
);
356 spin_lock_irqsave(&irq_action_lock
, flags
);
358 action
= *(bucket
->pil
+ irq_action
);
360 if ((action
->flags
& SA_SHIRQ
) && (irqflags
& SA_SHIRQ
))
361 for (tmp
= action
; tmp
->next
; tmp
= tmp
->next
)
364 spin_unlock_irqrestore(&irq_action_lock
, flags
);
367 action
= NULL
; /* Or else! */
370 /* If this is flagged as statically allocated then we use our
371 * private struct which is never freed.
373 if (irqflags
& SA_STATIC_ALLOC
) {
374 if (static_irq_count
< MAX_STATIC_ALLOC
)
375 action
= &static_irqaction
[static_irq_count
++];
377 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed "
378 "using kmalloc\n", irq
, name
);
381 action
= (struct irqaction
*)kmalloc(sizeof(struct irqaction
),
385 spin_unlock_irqrestore(&irq_action_lock
, flags
);
389 if (bucket
== &pil0_dummy_bucket
) {
390 bucket
->irq_info
= action
;
391 bucket
->flags
|= IBF_ACTIVE
;
393 if ((bucket
->flags
& IBF_ACTIVE
) != 0) {
394 void *orig
= bucket
->irq_info
;
395 void **vector
= NULL
;
397 if ((bucket
->flags
& IBF_PCI
) == 0) {
398 printk("IRQ: Trying to share non-PCI bucket.\n");
401 if ((bucket
->flags
& IBF_MULTI
) == 0) {
402 vector
= kmalloc(sizeof(void *) * 4, GFP_ATOMIC
);
404 goto free_and_enomem
;
406 /* We might have slept. */
407 if ((bucket
->flags
& IBF_MULTI
) != 0) {
411 vector
= (void **)bucket
->irq_info
;
412 for(ent
= 0; ent
< 4; ent
++) {
413 if (vector
[ent
] == NULL
) {
414 vector
[ent
] = action
;
425 bucket
->irq_info
= vector
;
426 bucket
->flags
|= IBF_MULTI
;
431 vector
= (void **)orig
;
432 for (ent
= 0; ent
< 4; ent
++) {
433 if (vector
[ent
] == NULL
) {
434 vector
[ent
] = action
;
442 bucket
->irq_info
= action
;
443 bucket
->flags
|= IBF_ACTIVE
;
445 pending
= bucket
->pending
;
450 action
->handler
= handler
;
451 action
->flags
= irqflags
;
454 action
->dev_id
= dev_id
;
455 put_ino_in_irqaction(action
, irq
);
456 put_smpaff_in_irqaction(action
, CPU_MASK_NONE
);
461 *(bucket
->pil
+ irq_action
) = action
;
465 /* We ate the IVEC already, this makes sure it does not get lost. */
467 atomic_bucket_insert(bucket
);
468 set_softint(1 << bucket
->pil
);
470 spin_unlock_irqrestore(&irq_action_lock
, flags
);
471 if ((bucket
!= &pil0_dummy_bucket
) && (!(irqflags
& SA_STATIC_ALLOC
)))
472 register_irq_proc(__irq_ino(irq
));
481 spin_unlock_irqrestore(&irq_action_lock
, flags
);
486 spin_unlock_irqrestore(&irq_action_lock
, flags
);
490 EXPORT_SYMBOL(request_irq
);
492 void free_irq(unsigned int irq
, void *dev_id
)
494 struct irqaction
*action
;
495 struct irqaction
*tmp
= NULL
;
497 struct ino_bucket
*bucket
= __bucket(irq
), *bp
;
499 if ((bucket
!= &pil0_dummy_bucket
) &&
500 (bucket
< &ivector_table
[0] ||
501 bucket
>= &ivector_table
[NUM_IVECS
])) {
502 unsigned int *caller
;
504 __asm__
__volatile__("mov %%i7, %0" : "=r" (caller
));
505 printk(KERN_CRIT
"free_irq: Old style IRQ removal attempt "
506 "from %p, irq %08x.\n", caller
, irq
);
510 spin_lock_irqsave(&irq_action_lock
, flags
);
512 action
= *(bucket
->pil
+ irq_action
);
513 if (!action
->handler
) {
514 printk("Freeing free IRQ %d\n", bucket
->pil
);
518 for ( ; action
; action
= action
->next
) {
519 if (action
->dev_id
== dev_id
)
524 printk("Trying to free free shared IRQ %d\n", bucket
->pil
);
525 spin_unlock_irqrestore(&irq_action_lock
, flags
);
528 } else if (action
->flags
& SA_SHIRQ
) {
529 printk("Trying to free shared IRQ %d with NULL device ID\n", bucket
->pil
);
530 spin_unlock_irqrestore(&irq_action_lock
, flags
);
534 if (action
->flags
& SA_STATIC_ALLOC
) {
535 printk("Attempt to free statically allocated IRQ %d (%s)\n",
536 bucket
->pil
, action
->name
);
537 spin_unlock_irqrestore(&irq_action_lock
, flags
);
542 tmp
->next
= action
->next
;
544 *(bucket
->pil
+ irq_action
) = action
->next
;
546 spin_unlock_irqrestore(&irq_action_lock
, flags
);
548 synchronize_irq(irq
);
550 spin_lock_irqsave(&irq_action_lock
, flags
);
552 if (bucket
!= &pil0_dummy_bucket
) {
553 unsigned long imap
= bucket
->imap
;
554 void **vector
, *orig
;
557 orig
= bucket
->irq_info
;
558 vector
= (void **)orig
;
560 if ((bucket
->flags
& IBF_MULTI
) != 0) {
563 for (ent
= 0; ent
< 4; ent
++) {
564 if (vector
[ent
] == action
)
566 else if (vector
[ent
] != NULL
) {
567 orphan
= vector
[ent
];
572 /* Only free when no other shared irq
577 /* Convert back to non-shared bucket. */
578 bucket
->irq_info
= orphan
;
579 bucket
->flags
&= ~(IBF_MULTI
);
585 bucket
->irq_info
= NULL
;
588 /* This unique interrupt source is now inactive. */
589 bucket
->flags
&= ~IBF_ACTIVE
;
591 /* See if any other buckets share this bucket's IMAP
592 * and are still active.
594 for (ent
= 0; ent
< NUM_IVECS
; ent
++) {
595 bp
= &ivector_table
[ent
];
598 (bp
->flags
& IBF_ACTIVE
) != 0)
602 /* Only disable when no other sub-irq levels of
603 * the same IMAP are active.
605 if (ent
== NUM_IVECS
)
611 spin_unlock_irqrestore(&irq_action_lock
, flags
);
614 EXPORT_SYMBOL(free_irq
);
617 void synchronize_irq(unsigned int irq
)
619 struct ino_bucket
*bucket
= __bucket(irq
);
622 /* The following is how I wish I could implement this.
623 * Unfortunately the ICLR registers are read-only, you can
624 * only write ICLR_foo values to them. To get the current
625 * IRQ status you would need to get at the IRQ diag registers
626 * in the PCI/SBUS controller and the layout of those vary
627 * from one controller to the next, sigh... -DaveM
629 unsigned long iclr
= bucket
->iclr
;
632 u32 tmp
= upa_readl(iclr
);
634 if (tmp
== ICLR_TRANSMIT
||
635 tmp
== ICLR_PENDING
) {
642 /* So we have to do this with a INPROGRESS bit just like x86. */
643 while (bucket
->flags
& IBF_INPROGRESS
)
647 #endif /* CONFIG_SMP */
649 void catch_disabled_ivec(struct pt_regs
*regs
)
651 int cpu
= smp_processor_id();
652 struct ino_bucket
*bucket
= __bucket(*irq_work(cpu
, 0));
654 /* We can actually see this on Ultra/PCI PCI cards, which are bridges
655 * to other devices. Here a single IMAP enabled potentially multiple
656 * unique interrupt sources (which each do have a unique ICLR register.
658 * So what we do is just register that the IVEC arrived, when registered
659 * for real the request_irq() code will check the bit and signal
660 * a local CPU interrupt for it.
663 printk("IVEC: Spurious interrupt vector (%x) received at (%016lx)\n",
664 bucket
- &ivector_table
[0], regs
->tpc
);
666 *irq_work(cpu
, 0) = 0;
671 #define FORWARD_VOLUME 12
675 static inline void redirect_intr(int cpu
, struct ino_bucket
*bp
)
677 /* Ok, here is what is going on:
678 * 1) Retargeting IRQs on Starfire is very
679 * expensive so just forget about it on them.
680 * 2) Moving around very high priority interrupts
682 * 3) If the current cpu is idle, interrupts are
683 * useful work, so keep them here. But do not
684 * pass to our neighbour if he is not very idle.
685 * 4) If sysadmin explicitly asks for directed intrs,
688 struct irqaction
*ap
= bp
->irq_info
;
690 unsigned int buddy
, ticks
;
692 cpu_mask
= get_smpaff_in_irqaction(ap
);
693 cpus_and(cpu_mask
, cpu_mask
, cpu_online_map
);
694 if (cpus_empty(cpu_mask
))
695 cpu_mask
= cpu_online_map
;
697 if (this_is_starfire
!= 0 ||
698 bp
->pil
>= 10 || current
->pid
== 0)
701 /* 'cpu' is the MID (ie. UPAID), calculate the MID
705 if (buddy
>= NR_CPUS
)
709 while (!cpu_isset(buddy
, cpu_mask
)) {
710 if (++buddy
>= NR_CPUS
)
712 if (++ticks
> NR_CPUS
) {
713 put_smpaff_in_irqaction(ap
, CPU_MASK_NONE
);
721 /* Voo-doo programming. */
722 if (cpu_data(buddy
).idle_volume
< FORWARD_VOLUME
)
725 /* This just so happens to be correct on Cheetah
730 /* Push it to our buddy. */
731 upa_writel(buddy
| IMAP_VALID
, bp
->imap
);
739 void handler_irq(int irq
, struct pt_regs
*regs
)
741 struct ino_bucket
*bp
, *nbp
;
742 int cpu
= smp_processor_id();
746 * Check for TICK_INT on level 14 softint.
749 unsigned long clr_mask
= 1 << irq
;
750 unsigned long tick_mask
= tick_ops
->softint_mask
;
752 if ((irq
== 14) && (get_softint() & tick_mask
)) {
754 clr_mask
= tick_mask
;
756 clear_softint(clr_mask
);
759 int should_forward
= 0;
761 clear_softint(1 << irq
);
765 kstat_this_cpu
.irqs
[irq
]++;
770 __bucket(xchg32(irq_work(cpu
, irq
), 0)) :
773 bp
= __bucket(xchg32(irq_work(cpu
, irq
), 0));
775 for ( ; bp
!= NULL
; bp
= nbp
) {
776 unsigned char flags
= bp
->flags
;
777 unsigned char random
= 0;
779 nbp
= __bucket(bp
->irq_chain
);
782 bp
->flags
|= IBF_INPROGRESS
;
784 if ((flags
& IBF_ACTIVE
) != 0) {
786 if ((flags
& IBF_DMA_SYNC
) != 0) {
787 upa_readl(dma_sync_reg_table
[bp
->synctab_ent
]);
788 upa_readq(pci_dma_wsync
);
791 if ((flags
& IBF_MULTI
) == 0) {
792 struct irqaction
*ap
= bp
->irq_info
;
795 ret
= ap
->handler(__irq(bp
), ap
->dev_id
, regs
);
796 if (ret
== IRQ_HANDLED
)
799 void **vector
= (void **)bp
->irq_info
;
801 for (ent
= 0; ent
< 4; ent
++) {
802 struct irqaction
*ap
= vector
[ent
];
806 ret
= ap
->handler(__irq(bp
),
809 if (ret
== IRQ_HANDLED
)
814 /* Only the dummy bucket lacks IMAP/ICLR. */
817 if (should_forward
) {
818 redirect_intr(cpu
, bp
);
822 upa_writel(ICLR_IDLE
, bp
->iclr
);
824 /* Test and add entropy */
825 if (random
& SA_SAMPLE_RANDOM
)
826 add_interrupt_randomness(irq
);
831 bp
->flags
&= ~IBF_INPROGRESS
;
836 #ifdef CONFIG_BLK_DEV_FD
837 extern void floppy_interrupt(int irq
, void *dev_cookie
, struct pt_regs
*regs
);
839 void sparc_floppy_irq(int irq
, void *dev_cookie
, struct pt_regs
*regs
)
841 struct irqaction
*action
= *(irq
+ irq_action
);
842 struct ino_bucket
*bucket
;
843 int cpu
= smp_processor_id();
846 kstat_this_cpu
.irqs
[irq
]++;
848 *(irq_work(cpu
, irq
)) = 0;
849 bucket
= get_ino_in_irqaction(action
) + ivector_table
;
851 bucket
->flags
|= IBF_INPROGRESS
;
853 floppy_interrupt(irq
, dev_cookie
, regs
);
854 upa_writel(ICLR_IDLE
, bucket
->iclr
);
856 bucket
->flags
&= ~IBF_INPROGRESS
;
862 /* The following assumes that the branch lies before the place we
863 * are branching to. This is the case for a trap vector...
864 * You have been warned.
866 #define SPARC_BRANCH(dest_addr, inst_addr) \
867 (0x10800000 | ((((dest_addr)-(inst_addr))>>2)&0x3fffff))
869 #define SPARC_NOP (0x01000000)
871 static void install_fast_irq(unsigned int cpu_irq
,
872 irqreturn_t (*handler
)(int, void *, struct pt_regs
*))
874 extern unsigned long sparc64_ttable_tl0
;
875 unsigned long ttent
= (unsigned long) &sparc64_ttable_tl0
;
879 ttent
+= (cpu_irq
- 1) << 5;
880 insns
= (unsigned int *) ttent
;
881 insns
[0] = SPARC_BRANCH(((unsigned long) handler
),
882 ((unsigned long)&insns
[0]));
883 insns
[1] = SPARC_NOP
;
884 __asm__
__volatile__("membar #StoreStore; flush %0" : : "r" (ttent
));
887 int request_fast_irq(unsigned int irq
,
888 irqreturn_t (*handler
)(int, void *, struct pt_regs
*),
889 unsigned long irqflags
, const char *name
, void *dev_id
)
891 struct irqaction
*action
;
892 struct ino_bucket
*bucket
= __bucket(irq
);
895 /* No pil0 dummy buckets allowed here. */
896 if (bucket
< &ivector_table
[0] ||
897 bucket
>= &ivector_table
[NUM_IVECS
]) {
898 unsigned int *caller
;
900 __asm__
__volatile__("mov %%i7, %0" : "=r" (caller
));
901 printk(KERN_CRIT
"request_fast_irq: Old style IRQ registry attempt "
902 "from %p, irq %08x.\n", caller
, irq
);
909 if ((bucket
->pil
== 0) || (bucket
->pil
== 14)) {
910 printk("request_fast_irq: Trying to register shared IRQ 0 or 14.\n");
914 spin_lock_irqsave(&irq_action_lock
, flags
);
916 action
= *(bucket
->pil
+ irq_action
);
918 if (action
->flags
& SA_SHIRQ
)
919 panic("Trying to register fast irq when already shared.\n");
920 if (irqflags
& SA_SHIRQ
)
921 panic("Trying to register fast irq as shared.\n");
922 printk("request_fast_irq: Trying to register yet already owned.\n");
923 spin_unlock_irqrestore(&irq_action_lock
, flags
);
928 * We do not check for SA_SAMPLE_RANDOM in this path. Neither do we
929 * support smp intr affinity in this path.
931 if (irqflags
& SA_STATIC_ALLOC
) {
932 if (static_irq_count
< MAX_STATIC_ALLOC
)
933 action
= &static_irqaction
[static_irq_count
++];
935 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed "
936 "using kmalloc\n", bucket
->pil
, name
);
939 action
= (struct irqaction
*)kmalloc(sizeof(struct irqaction
),
942 spin_unlock_irqrestore(&irq_action_lock
, flags
);
945 install_fast_irq(bucket
->pil
, handler
);
947 bucket
->irq_info
= action
;
948 bucket
->flags
|= IBF_ACTIVE
;
950 action
->handler
= handler
;
951 action
->flags
= irqflags
;
952 action
->dev_id
= NULL
;
955 put_ino_in_irqaction(action
, irq
);
956 put_smpaff_in_irqaction(action
, CPU_MASK_NONE
);
958 *(bucket
->pil
+ irq_action
) = action
;
961 spin_unlock_irqrestore(&irq_action_lock
, flags
);
969 /* We really don't need these at all on the Sparc. We only have
970 * stubs here because they are exported to modules.
972 unsigned long probe_irq_on(void)
977 EXPORT_SYMBOL(probe_irq_on
);
979 int probe_irq_off(unsigned long mask
)
984 EXPORT_SYMBOL(probe_irq_off
);
987 static int retarget_one_irq(struct irqaction
*p
, int goal_cpu
)
989 struct ino_bucket
*bucket
= get_ino_in_irqaction(p
) + ivector_table
;
990 unsigned long imap
= bucket
->imap
;
993 while (!cpu_online(goal_cpu
)) {
994 if (++goal_cpu
>= NR_CPUS
)
998 if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
) {
999 tid
= goal_cpu
<< 26;
1000 tid
&= IMAP_AID_SAFARI
;
1001 } else if (this_is_starfire
== 0) {
1002 tid
= goal_cpu
<< 26;
1003 tid
&= IMAP_TID_UPA
;
1005 tid
= (starfire_translate(imap
, goal_cpu
) << 26);
1006 tid
&= IMAP_TID_UPA
;
1008 upa_writel(tid
| IMAP_VALID
, imap
);
1011 if (++goal_cpu
>= NR_CPUS
)
1013 } while (!cpu_online(goal_cpu
));
1018 /* Called from request_irq. */
1019 static void distribute_irqs(void)
1021 unsigned long flags
;
1024 spin_lock_irqsave(&irq_action_lock
, flags
);
1028 * Skip the timer at [0], and very rare error/power intrs at [15].
1029 * Also level [12], it causes problems on Ex000 systems.
1031 for (level
= 1; level
< NR_IRQS
; level
++) {
1032 struct irqaction
*p
= irq_action
[level
];
1033 if (level
== 12) continue;
1035 cpu
= retarget_one_irq(p
, cpu
);
1039 spin_unlock_irqrestore(&irq_action_lock
, flags
);
1044 struct sun5_timer
*prom_timers
;
1045 static u64 prom_limit0
, prom_limit1
;
1047 static void map_prom_timers(void)
1049 unsigned int addr
[3];
1052 /* PROM timer node hangs out in the top level of device siblings... */
1053 tnode
= prom_finddevice("/counter-timer");
1055 /* Assume if node is not present, PROM uses different tick mechanism
1056 * which we should not care about.
1058 if (tnode
== 0 || tnode
== -1) {
1059 prom_timers
= (struct sun5_timer
*) 0;
1063 /* If PROM is really using this, it must be mapped by him. */
1064 err
= prom_getproperty(tnode
, "address", (char *)addr
, sizeof(addr
));
1066 prom_printf("PROM does not have timer mapped, trying to continue.\n");
1067 prom_timers
= (struct sun5_timer
*) 0;
1070 prom_timers
= (struct sun5_timer
*) ((unsigned long)addr
[0]);
1073 static void kill_prom_timer(void)
1078 /* Save them away for later. */
1079 prom_limit0
= prom_timers
->limit0
;
1080 prom_limit1
= prom_timers
->limit1
;
1082 /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
1083 * We turn both off here just to be paranoid.
1085 prom_timers
->limit0
= 0;
1086 prom_timers
->limit1
= 0;
1088 /* Wheee, eat the interrupt packet too... */
1089 __asm__
__volatile__(
1091 " ldxa [%%g0] %0, %%g1\n"
1092 " ldxa [%%g2] %1, %%g1\n"
1093 " stxa %%g0, [%%g0] %0\n"
1096 : "i" (ASI_INTR_RECEIVE
), "i" (ASI_INTR_R
)
1100 void enable_prom_timer(void)
1105 /* Set it to whatever was there before. */
1106 prom_timers
->limit1
= prom_limit1
;
1107 prom_timers
->count1
= 0;
1108 prom_timers
->limit0
= prom_limit0
;
1109 prom_timers
->count0
= 0;
1112 void init_irqwork_curcpu(void)
1114 register struct irq_work_struct
*workp
asm("o2");
1115 register unsigned long tmp
asm("o3");
1116 int cpu
= hard_smp_processor_id();
1118 memset(__irq_work
+ cpu
, 0, sizeof(*workp
));
1120 /* Make sure we are called with PSTATE_IE disabled. */
1121 __asm__
__volatile__("rdpr %%pstate, %0\n\t"
1123 if (tmp
& PSTATE_IE
) {
1124 prom_printf("BUG: init_irqwork_curcpu() called with "
1125 "PSTATE_IE enabled, bailing.\n");
1126 __asm__
__volatile__("mov %%i7, %0\n\t"
1128 prom_printf("BUG: Called from %lx\n", tmp
);
1132 /* Set interrupt globals. */
1133 workp
= &__irq_work
[cpu
];
1134 __asm__
__volatile__(
1135 "rdpr %%pstate, %0\n\t"
1136 "wrpr %0, %1, %%pstate\n\t"
1138 "wrpr %0, 0x0, %%pstate\n\t"
1140 : "i" (PSTATE_IG
), "r" (workp
));
1143 /* Only invoked on boot processor. */
1144 void __init
init_IRQ(void)
1148 memset(&ivector_table
[0], 0, sizeof(ivector_table
));
1150 /* We need to clear any IRQ's pending in the soft interrupt
1151 * registers, a spurious one could be left around from the
1152 * PROM timer which we just disabled.
1154 clear_softint(get_softint());
1156 /* Now that ivector table is initialized, it is safe
1157 * to receive IRQ vector traps. We will normally take
1158 * one or two right now, in case some device PROM used
1159 * to boot us wants to speak to us. We just ignore them.
1161 __asm__
__volatile__("rdpr %%pstate, %%g1\n\t"
1162 "or %%g1, %0, %%g1\n\t"
1163 "wrpr %%g1, 0x0, %%pstate"
1169 static struct proc_dir_entry
* root_irq_dir
;
1170 static struct proc_dir_entry
* irq_dir
[NUM_IVECS
];
1174 static int irq_affinity_read_proc (char *page
, char **start
, off_t off
,
1175 int count
, int *eof
, void *data
)
1177 struct ino_bucket
*bp
= ivector_table
+ (long)data
;
1178 struct irqaction
*ap
= bp
->irq_info
;
1182 mask
= get_smpaff_in_irqaction(ap
);
1183 if (cpus_empty(mask
))
1184 mask
= cpu_online_map
;
1186 len
= cpumask_scnprintf(page
, count
, mask
);
1187 if (count
- len
< 2)
1189 len
+= sprintf(page
+ len
, "\n");
1193 static inline void set_intr_affinity(int irq
, cpumask_t hw_aff
)
1195 struct ino_bucket
*bp
= ivector_table
+ irq
;
1197 /* Users specify affinity in terms of hw cpu ids.
1198 * As soon as we do this, handler_irq() might see and take action.
1200 put_smpaff_in_irqaction((struct irqaction
*)bp
->irq_info
, hw_aff
);
1202 /* Migration is simply done by the next cpu to service this
1207 static int irq_affinity_write_proc (struct file
*file
, const char __user
*buffer
,
1208 unsigned long count
, void *data
)
1210 int irq
= (long) data
, full_count
= count
, err
;
1211 cpumask_t new_value
;
1213 err
= cpumask_parse(buffer
, count
, new_value
);
1216 * Do not allow disabling IRQs completely - it's a too easy
1217 * way to make the system unusable accidentally :-) At least
1218 * one online CPU still has to be targeted.
1220 cpus_and(new_value
, new_value
, cpu_online_map
);
1221 if (cpus_empty(new_value
))
1224 set_intr_affinity(irq
, new_value
);
1231 #define MAX_NAMELEN 10
1233 static void register_irq_proc (unsigned int irq
)
1235 char name
[MAX_NAMELEN
];
1237 if (!root_irq_dir
|| irq_dir
[irq
])
1240 memset(name
, 0, MAX_NAMELEN
);
1241 sprintf(name
, "%x", irq
);
1243 /* create /proc/irq/1234 */
1244 irq_dir
[irq
] = proc_mkdir(name
, root_irq_dir
);
1247 /* XXX SMP affinity not supported on starfire yet. */
1248 if (this_is_starfire
== 0) {
1249 struct proc_dir_entry
*entry
;
1251 /* create /proc/irq/1234/smp_affinity */
1252 entry
= create_proc_entry("smp_affinity", 0600, irq_dir
[irq
]);
1256 entry
->data
= (void *)(long)irq
;
1257 entry
->read_proc
= irq_affinity_read_proc
;
1258 entry
->write_proc
= irq_affinity_write_proc
;
1264 void init_irq_proc (void)
1266 /* create /proc/irq */
1267 root_irq_dir
= proc_mkdir("irq", NULL
);