blob: c57b1708ae8cfa9be9251576a494ed6af6d635ba [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: irq.c,v 1.114 2002/01/11 08:45:38 davem Exp $
2 * irq.c: UltraSparc IRQ handling/init/registry.
3 *
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)
7 */
8
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>
16#include <linux/mm.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>
David S. Millerb5a37e92006-02-11 23:07:13 -080024#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/ptrace.h>
27#include <asm/processor.h>
28#include <asm/atomic.h>
29#include <asm/system.h>
30#include <asm/irq.h>
Sven Hartge2e457ef2005-10-08 21:12:04 -070031#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/sbus.h>
33#include <asm/iommu.h>
34#include <asm/upa.h>
35#include <asm/oplib.h>
36#include <asm/timer.h>
37#include <asm/smp.h>
38#include <asm/starfire.h>
39#include <asm/uaccess.h>
40#include <asm/cache.h>
41#include <asm/cpudata.h>
David S. Miller63b61452005-06-27 17:04:45 -070042#include <asm/auxio.h>
David S. Miller92704a12006-02-26 23:27:19 -080043#include <asm/head.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#ifdef CONFIG_SMP
46static void distribute_irqs(void);
47#endif
48
49/* UPA nodes send interrupt packet to UltraSparc with first data reg
50 * value low 5 (7 on Starfire) bits holding the IRQ identifier being
51 * delivered. We must translate this into a non-vector IRQ so we can
52 * set the softint on this cpu.
53 *
54 * To make processing these packets efficient and race free we use
55 * an array of irq buckets below. The interrupt vector handler in
56 * entry.S feeds incoming packets into per-cpu pil-indexed lists.
57 * The IVEC handler does not need to act atomically, the PIL dispatch
58 * code uses CAS to get an atomic snapshot of the list and clear it
59 * at the same time.
60 */
61
62struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES)));
63
64/* This has to be in the main kernel image, it cannot be
65 * turned into per-cpu data. The reason is that the main
66 * kernel image is locked into the TLB and this structure
67 * is accessed from the vectored interrupt trap handler. If
68 * access to this structure takes a TLB miss it could cause
69 * the 5-level sparc v9 trap stack to overflow.
70 */
71struct irq_work_struct {
72 unsigned int irq_worklists[16];
73};
74struct irq_work_struct __irq_work[NR_CPUS];
75#define irq_work(__cpu, __pil) &(__irq_work[(__cpu)].irq_worklists[(__pil)])
76
David S. Miller088dd1f2005-07-04 13:24:38 -070077static struct irqaction *irq_action[NR_IRQS+1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/* This only synchronizes entities which modify IRQ handler
80 * state and some selected user-level spots that want to
81 * read things in the table. IRQ handler processing orders
82 * its' accesses such that no locking is needed.
83 */
84static DEFINE_SPINLOCK(irq_action_lock);
85
86static void register_irq_proc (unsigned int irq);
87
88/*
89 * Upper 2b of irqaction->flags holds the ino.
90 * irqaction->mask holds the smp affinity information.
91 */
92#define put_ino_in_irqaction(action, irq) \
93 action->flags &= 0xffffffffffffUL; \
94 if (__bucket(irq) == &pil0_dummy_bucket) \
95 action->flags |= 0xdeadUL << 48; \
96 else \
97 action->flags |= __irq_ino(irq) << 48;
98#define get_ino_in_irqaction(action) (action->flags >> 48)
99
100#define put_smpaff_in_irqaction(action, smpaff) (action)->mask = (smpaff)
101#define get_smpaff_in_irqaction(action) ((action)->mask)
102
103int show_interrupts(struct seq_file *p, void *v)
104{
105 unsigned long flags;
106 int i = *(loff_t *) v;
107 struct irqaction *action;
108#ifdef CONFIG_SMP
109 int j;
110#endif
111
112 spin_lock_irqsave(&irq_action_lock, flags);
113 if (i <= NR_IRQS) {
114 if (!(action = *(i + irq_action)))
115 goto out_unlock;
116 seq_printf(p, "%3d: ", i);
117#ifndef CONFIG_SMP
118 seq_printf(p, "%10u ", kstat_irqs(i));
119#else
120 for (j = 0; j < NR_CPUS; j++) {
121 if (!cpu_online(j))
122 continue;
123 seq_printf(p, "%10u ",
124 kstat_cpu(j).irqs[i]);
125 }
126#endif
127 seq_printf(p, " %s:%lx", action->name,
128 get_ino_in_irqaction(action));
129 for (action = action->next; action; action = action->next) {
130 seq_printf(p, ", %s:%lx", action->name,
131 get_ino_in_irqaction(action));
132 }
133 seq_putc(p, '\n');
134 }
135out_unlock:
136 spin_unlock_irqrestore(&irq_action_lock, flags);
137
138 return 0;
139}
140
141/* Now these are always passed a true fully specified sun4u INO. */
142void enable_irq(unsigned int irq)
143{
144 struct ino_bucket *bucket = __bucket(irq);
145 unsigned long imap;
146 unsigned long tid;
147
148 imap = bucket->imap;
149 if (imap == 0UL)
150 return;
151
152 preempt_disable();
153
David S. Millerd82ace72006-02-09 02:52:44 -0800154 if (tlb_type == hypervisor) {
David S. Miller4bf447d2006-02-13 22:37:32 -0800155 unsigned int ino = __irq_ino(irq);
David S. Miller10951ee2006-02-13 18:22:57 -0800156 int cpu = hard_smp_processor_id();
157
David S. Miller4bf447d2006-02-13 22:37:32 -0800158 sun4v_intr_settarget(ino, cpu);
159 sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 } else {
David S. Millerd82ace72006-02-09 02:52:44 -0800161 if (tlb_type == cheetah || tlb_type == cheetah_plus) {
162 unsigned long ver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
David S. Millerd82ace72006-02-09 02:52:44 -0800164 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
165 if ((ver >> 32) == __JALAPENO_ID ||
166 (ver >> 32) == __SERRANO_ID) {
167 /* We set it to our JBUS ID. */
168 __asm__ __volatile__("ldxa [%%g0] %1, %0"
169 : "=r" (tid)
170 : "i" (ASI_JBUS_CONFIG));
171 tid = ((tid & (0x1fUL<<17)) << 9);
172 tid &= IMAP_TID_JBUS;
173 } else {
174 /* We set it to our Safari AID. */
175 __asm__ __volatile__("ldxa [%%g0] %1, %0"
176 : "=r" (tid)
177 : "i"(ASI_SAFARI_CONFIG));
178 tid = ((tid & (0x3ffUL<<17)) << 9);
179 tid &= IMAP_AID_SAFARI;
180 }
181 } else if (this_is_starfire == 0) {
182 /* We set it to our UPA MID. */
183 __asm__ __volatile__("ldxa [%%g0] %1, %0"
184 : "=r" (tid)
185 : "i" (ASI_UPA_CONFIG));
186 tid = ((tid & UPA_CONFIG_MID) << 9);
187 tid &= IMAP_TID_UPA;
188 } else {
189 tid = (starfire_translate(imap,
190 smp_processor_id()) << 26);
191 tid &= IMAP_TID_UPA;
192 }
193
194 /* NOTE NOTE NOTE, IGN and INO are read-only, IGN is a product
195 * of this SYSIO's preconfigured IGN in the SYSIO Control
196 * Register, the hardware just mirrors that value here.
197 * However for Graphics and UPA Slave devices the full
198 * IMAP_INR field can be set by the programmer here.
199 *
200 * Things like FFB can now be handled via the new IRQ
201 * mechanism.
202 */
203 upa_writel(tid | IMAP_VALID, imap);
204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 preempt_enable();
207}
208
209/* This now gets passed true ino's as well. */
210void disable_irq(unsigned int irq)
211{
212 struct ino_bucket *bucket = __bucket(irq);
213 unsigned long imap;
214
215 imap = bucket->imap;
216 if (imap != 0UL) {
David S. Miller10951ee2006-02-13 18:22:57 -0800217 if (tlb_type == hypervisor) {
David S. Miller4bf447d2006-02-13 22:37:32 -0800218 unsigned int ino = __irq_ino(irq);
219
220 sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
David S. Miller10951ee2006-02-13 18:22:57 -0800221 } else {
222 u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
David S. Miller10951ee2006-02-13 18:22:57 -0800224 /* NOTE: We do not want to futz with the IRQ clear registers
225 * and move the state to IDLE, the SCSI code does call
226 * disable_irq() to assure atomicity in the queue cmd
227 * SCSI adapter driver code. Thus we'd lose interrupts.
228 */
229 tmp = upa_readl(imap);
230 tmp &= ~IMAP_VALID;
231 upa_writel(tmp, imap);
232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 }
234}
235
236/* The timer is the one "weird" interrupt which is generated by
237 * the CPU %tick register and not by some normal vectored interrupt
238 * source. To handle this special case, we use this dummy INO bucket.
239 */
David S. Miller088dd1f2005-07-04 13:24:38 -0700240static struct irq_desc pil0_dummy_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static struct ino_bucket pil0_dummy_bucket = {
David S. Miller088dd1f2005-07-04 13:24:38 -0700242 .irq_info = &pil0_dummy_desc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243};
244
David S. Miller088dd1f2005-07-04 13:24:38 -0700245static void build_irq_error(const char *msg, unsigned int ino, int pil, int inofixup,
246 unsigned long iclr, unsigned long imap,
247 struct ino_bucket *bucket)
248{
249 prom_printf("IRQ: INO %04x (%d:%016lx:%016lx) --> "
250 "(%d:%d:%016lx:%016lx), halting...\n",
251 ino, bucket->pil, bucket->iclr, bucket->imap,
252 pil, inofixup, iclr, imap);
253 prom_halt();
254}
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256unsigned int build_irq(int pil, int inofixup, unsigned long iclr, unsigned long imap)
257{
258 struct ino_bucket *bucket;
259 int ino;
260
261 if (pil == 0) {
262 if (iclr != 0UL || imap != 0UL) {
263 prom_printf("Invalid dummy bucket for PIL0 (%lx:%lx)\n",
264 iclr, imap);
265 prom_halt();
266 }
267 return __irq(&pil0_dummy_bucket);
268 }
269
David S. Miller10951ee2006-02-13 18:22:57 -0800270 BUG_ON(tlb_type == hypervisor);
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 /* RULE: Both must be specified in all other cases. */
273 if (iclr == 0UL || imap == 0UL) {
274 prom_printf("Invalid build_irq %d %d %016lx %016lx\n",
275 pil, inofixup, iclr, imap);
276 prom_halt();
277 }
278
279 ino = (upa_readl(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
280 if (ino > NUM_IVECS) {
281 prom_printf("Invalid INO %04x (%d:%d:%016lx:%016lx)\n",
282 ino, pil, inofixup, iclr, imap);
283 prom_halt();
284 }
285
David S. Miller088dd1f2005-07-04 13:24:38 -0700286 bucket = &ivector_table[ino];
287 if (bucket->flags & IBF_ACTIVE)
288 build_irq_error("IRQ: Trying to build active INO bucket.\n",
289 ino, pil, inofixup, iclr, imap, bucket);
290
291 if (bucket->irq_info) {
292 if (bucket->imap != imap || bucket->iclr != iclr)
293 build_irq_error("IRQ: Trying to reinit INO bucket.\n",
294 ino, pil, inofixup, iclr, imap, bucket);
295
296 goto out;
297 }
298
299 bucket->irq_info = kmalloc(sizeof(struct irq_desc), GFP_ATOMIC);
300 if (!bucket->irq_info) {
301 prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n");
302 prom_halt();
303 }
304 memset(bucket->irq_info, 0, sizeof(struct irq_desc));
305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /* Ok, looks good, set it up. Don't touch the irq_chain or
307 * the pending flag.
308 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 bucket->imap = imap;
310 bucket->iclr = iclr;
311 bucket->pil = pil;
312 bucket->flags = 0;
313
David S. Miller088dd1f2005-07-04 13:24:38 -0700314out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 return __irq(bucket);
316}
317
David S. Millere3999572006-02-13 18:16:10 -0800318unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino, int pil, unsigned char flags)
319{
320 struct ino_bucket *bucket;
321 unsigned long sysino;
322
323 sysino = sun4v_devino_to_sysino(devhandle, devino);
324
David S. Miller87bdc362006-02-13 21:36:30 -0800325 printk(KERN_INFO "sun4v_irq: Mapping (%x:%x) --> sysino[%lx]\n",
326 devhandle, devino, sysino);
David S. Millere3999572006-02-13 18:16:10 -0800327
328 bucket = &ivector_table[sysino];
329
330 /* Catch accidental accesses to these things. IMAP/ICLR handling
331 * is done by hypervisor calls on sun4v platforms, not by direct
332 * register accesses.
333 */
334 bucket->imap = ~0UL;
335 bucket->iclr = ~0UL;
336
337 bucket->pil = pil;
338 bucket->flags = flags;
339
340 bucket->irq_info = kmalloc(sizeof(struct irq_desc), GFP_ATOMIC);
341 if (!bucket->irq_info) {
342 prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n");
343 prom_halt();
344 }
345 memset(bucket->irq_info, 0, sizeof(struct irq_desc));
346
347 return __irq(bucket);
348}
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350static void atomic_bucket_insert(struct ino_bucket *bucket)
351{
352 unsigned long pstate;
353 unsigned int *ent;
354
355 __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
356 __asm__ __volatile__("wrpr %0, %1, %%pstate"
357 : : "r" (pstate), "i" (PSTATE_IE));
358 ent = irq_work(smp_processor_id(), bucket->pil);
359 bucket->irq_chain = *ent;
360 *ent = __irq(bucket);
361 __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
362}
363
David S. Miller088dd1f2005-07-04 13:24:38 -0700364static int check_irq_sharing(int pil, unsigned long irqflags)
365{
366 struct irqaction *action, *tmp;
367
368 action = *(irq_action + pil);
369 if (action) {
370 if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) {
371 for (tmp = action; tmp->next; tmp = tmp->next)
372 ;
373 } else {
374 return -EBUSY;
375 }
376 }
377 return 0;
378}
379
380static void append_irq_action(int pil, struct irqaction *action)
381{
382 struct irqaction **pp = irq_action + pil;
383
384 while (*pp)
385 pp = &((*pp)->next);
386 *pp = action;
387}
388
389static struct irqaction *get_action_slot(struct ino_bucket *bucket)
390{
391 struct irq_desc *desc = bucket->irq_info;
392 int max_irq, i;
393
394 max_irq = 1;
395 if (bucket->flags & IBF_PCI)
396 max_irq = MAX_IRQ_DESC_ACTION;
397 for (i = 0; i < max_irq; i++) {
398 struct irqaction *p = &desc->action[i];
399 u32 mask = (1 << i);
400
401 if (desc->action_active_mask & mask)
402 continue;
403
404 desc->action_active_mask |= mask;
405 return p;
406 }
407 return NULL;
408}
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *),
411 unsigned long irqflags, const char *name, void *dev_id)
412{
David S. Miller088dd1f2005-07-04 13:24:38 -0700413 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 struct ino_bucket *bucket = __bucket(irq);
415 unsigned long flags;
416 int pending = 0;
417
David S. Miller088dd1f2005-07-04 13:24:38 -0700418 if (unlikely(!handler))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 return -EINVAL;
David S. Miller088dd1f2005-07-04 13:24:38 -0700420
421 if (unlikely(!bucket->irq_info))
422 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 if ((bucket != &pil0_dummy_bucket) && (irqflags & SA_SAMPLE_RANDOM)) {
425 /*
426 * This function might sleep, we want to call it first,
427 * outside of the atomic block. In SA_STATIC_ALLOC case,
428 * random driver's kmalloc will fail, but it is safe.
429 * If already initialized, random driver will not reinit.
430 * Yes, this might clear the entropy pool if the wrong
431 * driver is attempted to be loaded, without actually
432 * installing a new handler, but is this really a problem,
433 * only the sysadmin is able to do this.
434 */
435 rand_initialize_irq(irq);
436 }
437
438 spin_lock_irqsave(&irq_action_lock, flags);
439
David S. Miller088dd1f2005-07-04 13:24:38 -0700440 if (check_irq_sharing(bucket->pil, irqflags)) {
441 spin_unlock_irqrestore(&irq_action_lock, flags);
442 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444
David S. Miller088dd1f2005-07-04 13:24:38 -0700445 action = get_action_slot(bucket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 if (!action) {
447 spin_unlock_irqrestore(&irq_action_lock, flags);
448 return -ENOMEM;
449 }
450
David S. Miller088dd1f2005-07-04 13:24:38 -0700451 bucket->flags |= IBF_ACTIVE;
452 pending = 0;
453 if (bucket != &pil0_dummy_bucket) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 pending = bucket->pending;
455 if (pending)
456 bucket->pending = 0;
457 }
458
459 action->handler = handler;
460 action->flags = irqflags;
461 action->name = name;
462 action->next = NULL;
463 action->dev_id = dev_id;
464 put_ino_in_irqaction(action, irq);
465 put_smpaff_in_irqaction(action, CPU_MASK_NONE);
466
David S. Miller088dd1f2005-07-04 13:24:38 -0700467 append_irq_action(bucket->pil, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 enable_irq(irq);
470
471 /* We ate the IVEC already, this makes sure it does not get lost. */
472 if (pending) {
473 atomic_bucket_insert(bucket);
474 set_softint(1 << bucket->pil);
475 }
David S. Miller088dd1f2005-07-04 13:24:38 -0700476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 spin_unlock_irqrestore(&irq_action_lock, flags);
David S. Miller088dd1f2005-07-04 13:24:38 -0700478
479 if (bucket != &pil0_dummy_bucket)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 register_irq_proc(__irq_ino(irq));
481
482#ifdef CONFIG_SMP
483 distribute_irqs();
484#endif
485 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
488EXPORT_SYMBOL(request_irq);
489
David S. Miller088dd1f2005-07-04 13:24:38 -0700490static struct irqaction *unlink_irq_action(unsigned int irq, void *dev_id)
491{
492 struct ino_bucket *bucket = __bucket(irq);
493 struct irqaction *action, **pp;
494
495 pp = irq_action + bucket->pil;
496 action = *pp;
497 if (unlikely(!action))
498 return NULL;
499
500 if (unlikely(!action->handler)) {
501 printk("Freeing free IRQ %d\n", bucket->pil);
502 return NULL;
503 }
504
505 while (action && action->dev_id != dev_id) {
506 pp = &action->next;
507 action = *pp;
508 }
509
510 if (likely(action))
511 *pp = action->next;
512
513 return action;
514}
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516void free_irq(unsigned int irq, void *dev_id)
517{
518 struct irqaction *action;
David S. Miller088dd1f2005-07-04 13:24:38 -0700519 struct ino_bucket *bucket;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 spin_lock_irqsave(&irq_action_lock, flags);
523
David S. Miller088dd1f2005-07-04 13:24:38 -0700524 action = unlink_irq_action(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 spin_unlock_irqrestore(&irq_action_lock, flags);
527
David S. Miller088dd1f2005-07-04 13:24:38 -0700528 if (unlikely(!action))
529 return;
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 synchronize_irq(irq);
532
533 spin_lock_irqsave(&irq_action_lock, flags);
534
David S. Miller088dd1f2005-07-04 13:24:38 -0700535 bucket = __bucket(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (bucket != &pil0_dummy_bucket) {
David S. Miller088dd1f2005-07-04 13:24:38 -0700537 struct irq_desc *desc = bucket->irq_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 unsigned long imap = bucket->imap;
David S. Miller088dd1f2005-07-04 13:24:38 -0700539 int ent, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
David S. Miller088dd1f2005-07-04 13:24:38 -0700541 for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) {
542 struct irqaction *p = &desc->action[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
David S. Miller088dd1f2005-07-04 13:24:38 -0700544 if (p == action) {
545 desc->action_active_mask &= ~(1 << i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 break;
David S. Miller088dd1f2005-07-04 13:24:38 -0700547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549
David S. Miller088dd1f2005-07-04 13:24:38 -0700550 if (!desc->action_active_mask) {
551 /* This unique interrupt source is now inactive. */
552 bucket->flags &= ~IBF_ACTIVE;
553
554 /* See if any other buckets share this bucket's IMAP
555 * and are still active.
556 */
557 for (ent = 0; ent < NUM_IVECS; ent++) {
558 struct ino_bucket *bp = &ivector_table[ent];
559 if (bp != bucket &&
560 bp->imap == imap &&
561 (bp->flags & IBF_ACTIVE) != 0)
562 break;
563 }
564
565 /* Only disable when no other sub-irq levels of
566 * the same IMAP are active.
567 */
568 if (ent == NUM_IVECS)
569 disable_irq(irq);
570 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 spin_unlock_irqrestore(&irq_action_lock, flags);
574}
575
576EXPORT_SYMBOL(free_irq);
577
578#ifdef CONFIG_SMP
579void synchronize_irq(unsigned int irq)
580{
581 struct ino_bucket *bucket = __bucket(irq);
582
583#if 0
584 /* The following is how I wish I could implement this.
585 * Unfortunately the ICLR registers are read-only, you can
586 * only write ICLR_foo values to them. To get the current
587 * IRQ status you would need to get at the IRQ diag registers
588 * in the PCI/SBUS controller and the layout of those vary
589 * from one controller to the next, sigh... -DaveM
590 */
591 unsigned long iclr = bucket->iclr;
592
593 while (1) {
594 u32 tmp = upa_readl(iclr);
595
596 if (tmp == ICLR_TRANSMIT ||
597 tmp == ICLR_PENDING) {
598 cpu_relax();
599 continue;
600 }
601 break;
602 }
603#else
604 /* So we have to do this with a INPROGRESS bit just like x86. */
605 while (bucket->flags & IBF_INPROGRESS)
606 cpu_relax();
607#endif
608}
609#endif /* CONFIG_SMP */
610
David S. Miller088dd1f2005-07-04 13:24:38 -0700611static void process_bucket(int irq, struct ino_bucket *bp, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
David S. Miller088dd1f2005-07-04 13:24:38 -0700613 struct irq_desc *desc = bp->irq_info;
614 unsigned char flags = bp->flags;
615 u32 action_mask, i;
616 int random;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
David S. Miller088dd1f2005-07-04 13:24:38 -0700618 bp->flags |= IBF_INPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
David S. Miller088dd1f2005-07-04 13:24:38 -0700620 if (unlikely(!(flags & IBF_ACTIVE))) {
621 bp->pending = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
624
David S. Miller088dd1f2005-07-04 13:24:38 -0700625 if (desc->pre_handler)
626 desc->pre_handler(bp,
627 desc->pre_handler_arg1,
628 desc->pre_handler_arg2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
David S. Miller088dd1f2005-07-04 13:24:38 -0700630 action_mask = desc->action_active_mask;
631 random = 0;
632 for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) {
633 struct irqaction *p = &desc->action[i];
634 u32 mask = (1 << i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
David S. Miller088dd1f2005-07-04 13:24:38 -0700636 if (!(action_mask & mask))
637 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
David S. Miller088dd1f2005-07-04 13:24:38 -0700639 action_mask &= ~mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
David S. Miller088dd1f2005-07-04 13:24:38 -0700641 if (p->handler(__irq(bp), p->dev_id, regs) == IRQ_HANDLED)
642 random |= p->flags;
643
644 if (!action_mask)
645 break;
646 }
647 if (bp->pil != 0) {
David S. Miller10951ee2006-02-13 18:22:57 -0800648 if (tlb_type == hypervisor) {
David S. Miller4bf447d2006-02-13 22:37:32 -0800649 unsigned int ino = __irq_ino(bp);
David S. Miller10951ee2006-02-13 18:22:57 -0800650
David S. Miller4bf447d2006-02-13 22:37:32 -0800651 sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
David S. Miller10951ee2006-02-13 18:22:57 -0800652 } else {
653 upa_writel(ICLR_IDLE, bp->iclr);
654 /* Test and add entropy */
655 if (random & SA_SAMPLE_RANDOM)
656 add_interrupt_randomness(irq);
657 }
David S. Miller088dd1f2005-07-04 13:24:38 -0700658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659out:
David S. Miller088dd1f2005-07-04 13:24:38 -0700660 bp->flags &= ~IBF_INPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663void handler_irq(int irq, struct pt_regs *regs)
664{
David S. Miller088dd1f2005-07-04 13:24:38 -0700665 struct ino_bucket *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 int cpu = smp_processor_id();
667
668#ifndef CONFIG_SMP
669 /*
670 * Check for TICK_INT on level 14 softint.
671 */
672 {
673 unsigned long clr_mask = 1 << irq;
674 unsigned long tick_mask = tick_ops->softint_mask;
675
676 if ((irq == 14) && (get_softint() & tick_mask)) {
677 irq = 0;
678 clr_mask = tick_mask;
679 }
680 clear_softint(clr_mask);
681 }
682#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 clear_softint(1 << irq);
684#endif
685
686 irq_enter();
687 kstat_this_cpu.irqs[irq]++;
688
689 /* Sliiiick... */
690#ifndef CONFIG_SMP
691 bp = ((irq != 0) ?
692 __bucket(xchg32(irq_work(cpu, irq), 0)) :
693 &pil0_dummy_bucket);
694#else
695 bp = __bucket(xchg32(irq_work(cpu, irq), 0));
696#endif
David S. Miller088dd1f2005-07-04 13:24:38 -0700697 while (bp) {
698 struct ino_bucket *nbp = __bucket(bp->irq_chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 bp->irq_chain = 0;
David S. Miller088dd1f2005-07-04 13:24:38 -0700701 process_bucket(irq, bp, regs);
702 bp = nbp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704 irq_exit();
705}
706
707#ifdef CONFIG_BLK_DEV_FD
David S. Miller63b61452005-06-27 17:04:45 -0700708extern irqreturn_t floppy_interrupt(int, void *, struct pt_regs *);;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
David S. Miller63b61452005-06-27 17:04:45 -0700710/* XXX No easy way to include asm/floppy.h XXX */
711extern unsigned char *pdma_vaddr;
712extern unsigned long pdma_size;
713extern volatile int doing_pdma;
714extern unsigned long fdc_status;
715
716irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
David S. Miller63b61452005-06-27 17:04:45 -0700718 if (likely(doing_pdma)) {
719 void __iomem *stat = (void __iomem *) fdc_status;
720 unsigned char *vaddr = pdma_vaddr;
721 unsigned long size = pdma_size;
722 u8 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
David S. Miller63b61452005-06-27 17:04:45 -0700724 while (size) {
725 val = readb(stat);
726 if (unlikely(!(val & 0x80))) {
727 pdma_vaddr = vaddr;
728 pdma_size = size;
729 return IRQ_HANDLED;
730 }
731 if (unlikely(!(val & 0x20))) {
732 pdma_vaddr = vaddr;
733 pdma_size = size;
734 doing_pdma = 0;
735 goto main_interrupt;
736 }
737 if (val & 0x40) {
738 /* read */
739 *vaddr++ = readb(stat + 1);
740 } else {
741 unsigned char data = *vaddr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
David S. Miller63b61452005-06-27 17:04:45 -0700743 /* write */
744 writeb(data, stat + 1);
745 }
746 size--;
747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
David S. Miller63b61452005-06-27 17:04:45 -0700749 pdma_vaddr = vaddr;
750 pdma_size = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
David S. Miller63b61452005-06-27 17:04:45 -0700752 /* Send Terminal Count pulse to floppy controller. */
753 val = readb(auxio_register);
754 val |= AUXIO_AUX1_FTCNT;
755 writeb(val, auxio_register);
Bernhard R Link94bbc172006-03-10 01:23:13 -0800756 val &= ~AUXIO_AUX1_FTCNT;
David S. Miller63b61452005-06-27 17:04:45 -0700757 writeb(val, auxio_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
David S. Miller63b61452005-06-27 17:04:45 -0700759 doing_pdma = 0;
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
David S. Miller63b61452005-06-27 17:04:45 -0700762main_interrupt:
763 return floppy_interrupt(irq, dev_cookie, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
David S. Miller63b61452005-06-27 17:04:45 -0700765EXPORT_SYMBOL(sparc_floppy_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766#endif
767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768/* We really don't need these at all on the Sparc. We only have
769 * stubs here because they are exported to modules.
770 */
771unsigned long probe_irq_on(void)
772{
773 return 0;
774}
775
776EXPORT_SYMBOL(probe_irq_on);
777
778int probe_irq_off(unsigned long mask)
779{
780 return 0;
781}
782
783EXPORT_SYMBOL(probe_irq_off);
784
785#ifdef CONFIG_SMP
786static int retarget_one_irq(struct irqaction *p, int goal_cpu)
787{
788 struct ino_bucket *bucket = get_ino_in_irqaction(p) + ivector_table;
789 unsigned long imap = bucket->imap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 while (!cpu_online(goal_cpu)) {
792 if (++goal_cpu >= NR_CPUS)
793 goal_cpu = 0;
794 }
795
David S. Miller10951ee2006-02-13 18:22:57 -0800796 if (tlb_type == hypervisor) {
David S. Miller4bf447d2006-02-13 22:37:32 -0800797 unsigned int ino = __irq_ino(bucket);
David S. Miller10951ee2006-02-13 18:22:57 -0800798
David S. Miller4bf447d2006-02-13 22:37:32 -0800799 sun4v_intr_settarget(ino, goal_cpu);
800 sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 } else {
David S. Miller10951ee2006-02-13 18:22:57 -0800802 unsigned int tid;
803
804 if (tlb_type == cheetah || tlb_type == cheetah_plus) {
805 tid = goal_cpu << 26;
806 tid &= IMAP_AID_SAFARI;
807 } else if (this_is_starfire == 0) {
808 tid = goal_cpu << 26;
809 tid &= IMAP_TID_UPA;
810 } else {
811 tid = (starfire_translate(imap, goal_cpu) << 26);
812 tid &= IMAP_TID_UPA;
813 }
814 upa_writel(tid | IMAP_VALID, imap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
David S. Millercee28242005-05-03 22:04:36 -0700817 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (++goal_cpu >= NR_CPUS)
819 goal_cpu = 0;
David S. Millercee28242005-05-03 22:04:36 -0700820 } while (!cpu_online(goal_cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 return goal_cpu;
823}
824
825/* Called from request_irq. */
826static void distribute_irqs(void)
827{
828 unsigned long flags;
829 int cpu, level;
830
831 spin_lock_irqsave(&irq_action_lock, flags);
832 cpu = 0;
833
834 /*
835 * Skip the timer at [0], and very rare error/power intrs at [15].
836 * Also level [12], it causes problems on Ex000 systems.
837 */
838 for (level = 1; level < NR_IRQS; level++) {
839 struct irqaction *p = irq_action[level];
David S. Miller088dd1f2005-07-04 13:24:38 -0700840
841 if (level == 12)
842 continue;
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 while(p) {
845 cpu = retarget_one_irq(p, cpu);
846 p = p->next;
847 }
848 }
849 spin_unlock_irqrestore(&irq_action_lock, flags);
850}
851#endif
852
David S. Millercdd51862005-07-24 19:36:13 -0700853struct sun5_timer {
854 u64 count0;
855 u64 limit0;
856 u64 count1;
857 u64 limit1;
858};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
David S. Millercdd51862005-07-24 19:36:13 -0700860static struct sun5_timer *prom_timers;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861static u64 prom_limit0, prom_limit1;
862
863static void map_prom_timers(void)
864{
865 unsigned int addr[3];
866 int tnode, err;
867
868 /* PROM timer node hangs out in the top level of device siblings... */
869 tnode = prom_finddevice("/counter-timer");
870
871 /* Assume if node is not present, PROM uses different tick mechanism
872 * which we should not care about.
873 */
874 if (tnode == 0 || tnode == -1) {
875 prom_timers = (struct sun5_timer *) 0;
876 return;
877 }
878
879 /* If PROM is really using this, it must be mapped by him. */
880 err = prom_getproperty(tnode, "address", (char *)addr, sizeof(addr));
881 if (err == -1) {
882 prom_printf("PROM does not have timer mapped, trying to continue.\n");
883 prom_timers = (struct sun5_timer *) 0;
884 return;
885 }
886 prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
887}
888
889static void kill_prom_timer(void)
890{
891 if (!prom_timers)
892 return;
893
894 /* Save them away for later. */
895 prom_limit0 = prom_timers->limit0;
896 prom_limit1 = prom_timers->limit1;
897
898 /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
899 * We turn both off here just to be paranoid.
900 */
901 prom_timers->limit0 = 0;
902 prom_timers->limit1 = 0;
903
904 /* Wheee, eat the interrupt packet too... */
905 __asm__ __volatile__(
906" mov 0x40, %%g2\n"
907" ldxa [%%g0] %0, %%g1\n"
908" ldxa [%%g2] %1, %%g1\n"
909" stxa %%g0, [%%g0] %0\n"
910" membar #Sync\n"
911 : /* no outputs */
912 : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
913 : "g1", "g2");
914}
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916void init_irqwork_curcpu(void)
917{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 int cpu = hard_smp_processor_id();
919
David S. Miller56fb4df2006-02-26 23:24:22 -0800920 memset(__irq_work + cpu, 0, sizeof(struct irq_work_struct));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921}
922
David S. Millerb5a37e92006-02-11 23:07:13 -0800923static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type)
David S. Millerac29c112006-02-08 00:08:23 -0800924{
David S. Miller164c2202006-02-09 22:57:21 -0800925 register unsigned long func __asm__("%o5");
926 register unsigned long arg0 __asm__("%o0");
927 register unsigned long arg1 __asm__("%o1");
928 register unsigned long arg2 __asm__("%o2");
David S. Millerac29c112006-02-08 00:08:23 -0800929
930 func = HV_FAST_CPU_QCONF;
931 arg0 = type;
David S. Millerb5a37e92006-02-11 23:07:13 -0800932 arg1 = paddr;
David S. Millerac29c112006-02-08 00:08:23 -0800933 arg2 = 128; /* XXX Implied by Niagara queue offsets. XXX */
934 __asm__ __volatile__("ta %8"
935 : "=&r" (func), "=&r" (arg0),
936 "=&r" (arg1), "=&r" (arg2)
937 : "0" (func), "1" (arg0),
938 "2" (arg1), "3" (arg2),
939 "i" (HV_FAST_TRAP));
940
David S. Millerb5a37e92006-02-11 23:07:13 -0800941 if (arg0 != HV_EOK) {
David S. Millerac29c112006-02-08 00:08:23 -0800942 prom_printf("SUN4V: cpu_qconf(%lu) failed with error %lu\n",
943 type, func);
944 prom_halt();
945 }
946}
947
David S. Millerb5a37e92006-02-11 23:07:13 -0800948static void __cpuinit sun4v_register_mondo_queues(int this_cpu)
David S. Miller5b0c0572006-02-08 02:53:50 -0800949{
David S. Millerb5a37e92006-02-11 23:07:13 -0800950 struct trap_per_cpu *tb = &trap_block[this_cpu];
951
952 register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO);
953 register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO);
954 register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR);
955 register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR);
956}
957
958static void __cpuinit alloc_one_mondo(unsigned long *pa_ptr, int use_bootmem)
959{
960 void *page;
961
962 if (use_bootmem)
963 page = alloc_bootmem_low_pages(PAGE_SIZE);
964 else
965 page = (void *) get_zeroed_page(GFP_ATOMIC);
966
967 if (!page) {
968 prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
969 prom_halt();
970 }
971
972 *pa_ptr = __pa(page);
973}
974
975static void __cpuinit alloc_one_kbuf(unsigned long *pa_ptr, int use_bootmem)
976{
977 void *page;
978
979 if (use_bootmem)
980 page = alloc_bootmem_low_pages(PAGE_SIZE);
981 else
982 page = (void *) get_zeroed_page(GFP_ATOMIC);
David S. Miller5b0c0572006-02-08 02:53:50 -0800983
984 if (!page) {
985 prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
986 prom_halt();
987 }
988
989 *pa_ptr = __pa(page);
990}
991
David S. Millerb5a37e92006-02-11 23:07:13 -0800992static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem)
David S. Miller1d2f1f92006-02-08 16:41:20 -0800993{
994#ifdef CONFIG_SMP
David S. Millerb5a37e92006-02-11 23:07:13 -0800995 void *page;
David S. Miller1d2f1f92006-02-08 16:41:20 -0800996
997 BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
998
David S. Millerb5a37e92006-02-11 23:07:13 -0800999 if (use_bootmem)
1000 page = alloc_bootmem_low_pages(PAGE_SIZE);
1001 else
1002 page = (void *) get_zeroed_page(GFP_ATOMIC);
1003
David S. Miller1d2f1f92006-02-08 16:41:20 -08001004 if (!page) {
1005 prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
1006 prom_halt();
1007 }
1008
1009 tb->cpu_mondo_block_pa = __pa(page);
1010 tb->cpu_list_pa = __pa(page + 64);
1011#endif
1012}
1013
David S. Millerb5a37e92006-02-11 23:07:13 -08001014/* Allocate and register the mondo and error queues for this cpu. */
1015void __cpuinit sun4v_init_mondo_queues(int use_bootmem)
David S. Millerac29c112006-02-08 00:08:23 -08001016{
1017 int cpu = hard_smp_processor_id();
1018 struct trap_per_cpu *tb = &trap_block[cpu];
1019
David S. Millerb5a37e92006-02-11 23:07:13 -08001020 alloc_one_mondo(&tb->cpu_mondo_pa, use_bootmem);
1021 alloc_one_mondo(&tb->dev_mondo_pa, use_bootmem);
1022 alloc_one_mondo(&tb->resum_mondo_pa, use_bootmem);
1023 alloc_one_kbuf(&tb->resum_kernel_buf_pa, use_bootmem);
1024 alloc_one_mondo(&tb->nonresum_mondo_pa, use_bootmem);
1025 alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, use_bootmem);
David S. Miller1d2f1f92006-02-08 16:41:20 -08001026
David S. Millerb5a37e92006-02-11 23:07:13 -08001027 init_cpu_send_mondo_info(tb, use_bootmem);
David S. Miller1d2f1f92006-02-08 16:41:20 -08001028
David S. Millerb5a37e92006-02-11 23:07:13 -08001029 sun4v_register_mondo_queues(cpu);
David S. Millerac29c112006-02-08 00:08:23 -08001030}
1031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032/* Only invoked on boot processor. */
1033void __init init_IRQ(void)
1034{
1035 map_prom_timers();
1036 kill_prom_timer();
1037 memset(&ivector_table[0], 0, sizeof(ivector_table));
1038
David S. Millerac29c112006-02-08 00:08:23 -08001039 if (tlb_type == hypervisor)
David S. Millerb5a37e92006-02-11 23:07:13 -08001040 sun4v_init_mondo_queues(1);
David S. Millerac29c112006-02-08 00:08:23 -08001041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 /* We need to clear any IRQ's pending in the soft interrupt
1043 * registers, a spurious one could be left around from the
1044 * PROM timer which we just disabled.
1045 */
1046 clear_softint(get_softint());
1047
1048 /* Now that ivector table is initialized, it is safe
1049 * to receive IRQ vector traps. We will normally take
1050 * one or two right now, in case some device PROM used
1051 * to boot us wants to speak to us. We just ignore them.
1052 */
1053 __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
1054 "or %%g1, %0, %%g1\n\t"
1055 "wrpr %%g1, 0x0, %%pstate"
1056 : /* No outputs */
1057 : "i" (PSTATE_IE)
1058 : "g1");
1059}
1060
1061static struct proc_dir_entry * root_irq_dir;
1062static struct proc_dir_entry * irq_dir [NUM_IVECS];
1063
1064#ifdef CONFIG_SMP
1065
1066static int irq_affinity_read_proc (char *page, char **start, off_t off,
1067 int count, int *eof, void *data)
1068{
1069 struct ino_bucket *bp = ivector_table + (long)data;
Eddie C. Dost12cf6492005-07-06 15:40:21 -07001070 struct irq_desc *desc = bp->irq_info;
1071 struct irqaction *ap = desc->action;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 cpumask_t mask;
1073 int len;
1074
1075 mask = get_smpaff_in_irqaction(ap);
1076 if (cpus_empty(mask))
1077 mask = cpu_online_map;
1078
1079 len = cpumask_scnprintf(page, count, mask);
1080 if (count - len < 2)
1081 return -EINVAL;
1082 len += sprintf(page + len, "\n");
1083 return len;
1084}
1085
1086static inline void set_intr_affinity(int irq, cpumask_t hw_aff)
1087{
1088 struct ino_bucket *bp = ivector_table + irq;
Eddie C. Dost12cf6492005-07-06 15:40:21 -07001089 struct irq_desc *desc = bp->irq_info;
1090 struct irqaction *ap = desc->action;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 /* Users specify affinity in terms of hw cpu ids.
1093 * As soon as we do this, handler_irq() might see and take action.
1094 */
Eddie C. Dost12cf6492005-07-06 15:40:21 -07001095 put_smpaff_in_irqaction(ap, hw_aff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 /* Migration is simply done by the next cpu to service this
1098 * interrupt.
1099 */
1100}
1101
1102static int irq_affinity_write_proc (struct file *file, const char __user *buffer,
1103 unsigned long count, void *data)
1104{
1105 int irq = (long) data, full_count = count, err;
1106 cpumask_t new_value;
1107
1108 err = cpumask_parse(buffer, count, new_value);
1109
1110 /*
1111 * Do not allow disabling IRQs completely - it's a too easy
1112 * way to make the system unusable accidentally :-) At least
1113 * one online CPU still has to be targeted.
1114 */
1115 cpus_and(new_value, new_value, cpu_online_map);
1116 if (cpus_empty(new_value))
1117 return -EINVAL;
1118
1119 set_intr_affinity(irq, new_value);
1120
1121 return full_count;
1122}
1123
1124#endif
1125
1126#define MAX_NAMELEN 10
1127
1128static void register_irq_proc (unsigned int irq)
1129{
1130 char name [MAX_NAMELEN];
1131
1132 if (!root_irq_dir || irq_dir[irq])
1133 return;
1134
1135 memset(name, 0, MAX_NAMELEN);
1136 sprintf(name, "%x", irq);
1137
1138 /* create /proc/irq/1234 */
1139 irq_dir[irq] = proc_mkdir(name, root_irq_dir);
1140
1141#ifdef CONFIG_SMP
1142 /* XXX SMP affinity not supported on starfire yet. */
1143 if (this_is_starfire == 0) {
1144 struct proc_dir_entry *entry;
1145
1146 /* create /proc/irq/1234/smp_affinity */
1147 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
1148
1149 if (entry) {
1150 entry->nlink = 1;
1151 entry->data = (void *)(long)irq;
1152 entry->read_proc = irq_affinity_read_proc;
1153 entry->write_proc = irq_affinity_write_proc;
1154 }
1155 }
1156#endif
1157}
1158
1159void init_irq_proc (void)
1160{
1161 /* create /proc/irq */
1162 root_irq_dir = proc_mkdir("irq", NULL);
1163}
1164