Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* $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> | |
b5a37e96 | 24 | #include <linux/bootmem.h> |
1da177e4 LT |
25 | |
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> | |
2e457ef6 | 31 | #include <asm/io.h> |
1da177e4 LT |
32 | #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> | |
63b61452 | 42 | #include <asm/auxio.h> |
92704a1c | 43 | #include <asm/head.h> |
1da177e4 LT |
44 | |
45 | #ifdef CONFIG_SMP | |
46 | static 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 | ||
62 | struct 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 | */ | |
71 | struct irq_work_struct { | |
72 | unsigned int irq_worklists[16]; | |
73 | }; | |
74 | struct irq_work_struct __irq_work[NR_CPUS]; | |
75 | #define irq_work(__cpu, __pil) &(__irq_work[(__cpu)].irq_worklists[(__pil)]) | |
76 | ||
088dd1f8 | 77 | static struct irqaction *irq_action[NR_IRQS+1]; |
1da177e4 LT |
78 | |
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 | */ | |
84 | static DEFINE_SPINLOCK(irq_action_lock); | |
85 | ||
86 | static 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 | ||
103 | int 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 | } | |
135 | out_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. */ | |
142 | void 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 | ||
d82ace7d | 154 | if (tlb_type == hypervisor) { |
4bf447d6 | 155 | unsigned int ino = __irq_ino(irq); |
10951ee6 DM |
156 | int cpu = hard_smp_processor_id(); |
157 | ||
4bf447d6 DM |
158 | sun4v_intr_settarget(ino, cpu); |
159 | sun4v_intr_setenabled(ino, HV_INTR_ENABLED); | |
d82ace7d DM |
160 | } else { |
161 | if (tlb_type == cheetah || tlb_type == cheetah_plus) { | |
162 | unsigned long ver; | |
163 | ||
164 | __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. */ | |
1da177e4 LT |
183 | __asm__ __volatile__("ldxa [%%g0] %1, %0" |
184 | : "=r" (tid) | |
d82ace7d DM |
185 | : "i" (ASI_UPA_CONFIG)); |
186 | tid = ((tid & UPA_CONFIG_MID) << 9); | |
187 | tid &= IMAP_TID_UPA; | |
1da177e4 | 188 | } else { |
d82ace7d DM |
189 | tid = (starfire_translate(imap, |
190 | smp_processor_id()) << 26); | |
191 | tid &= IMAP_TID_UPA; | |
1da177e4 | 192 | } |
1da177e4 | 193 | |
d82ace7d DM |
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 | } | |
1da177e4 LT |
205 | |
206 | preempt_enable(); | |
207 | } | |
208 | ||
209 | /* This now gets passed true ino's as well. */ | |
210 | void 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) { | |
10951ee6 | 217 | if (tlb_type == hypervisor) { |
4bf447d6 DM |
218 | unsigned int ino = __irq_ino(irq); |
219 | ||
220 | sun4v_intr_setenabled(ino, HV_INTR_DISABLED); | |
10951ee6 DM |
221 | } else { |
222 | u32 tmp; | |
1da177e4 | 223 | |
10951ee6 DM |
224 | /* 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 | } | |
1da177e4 LT |
233 | } |
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 | */ | |
088dd1f8 | 240 | static struct irq_desc pil0_dummy_desc; |
1da177e4 | 241 | static struct ino_bucket pil0_dummy_bucket = { |
088dd1f8 | 242 | .irq_info = &pil0_dummy_desc, |
1da177e4 LT |
243 | }; |
244 | ||
088dd1f8 DM |
245 | static 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 | ||
1da177e4 LT |
256 | unsigned 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 | ||
10951ee6 DM |
270 | BUG_ON(tlb_type == hypervisor); |
271 | ||
1da177e4 LT |
272 | /* 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 | ||
1da177e4 | 286 | bucket = &ivector_table[ino]; |
088dd1f8 DM |
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"); | |
1da177e4 LT |
302 | prom_halt(); |
303 | } | |
088dd1f8 DM |
304 | memset(bucket->irq_info, 0, sizeof(struct irq_desc)); |
305 | ||
306 | /* Ok, looks good, set it up. Don't touch the irq_chain or | |
307 | * the pending flag. | |
308 | */ | |
1da177e4 LT |
309 | bucket->imap = imap; |
310 | bucket->iclr = iclr; | |
311 | bucket->pil = pil; | |
312 | bucket->flags = 0; | |
313 | ||
088dd1f8 | 314 | out: |
1da177e4 LT |
315 | return __irq(bucket); |
316 | } | |
317 | ||
e3999574 DM |
318 | unsigned 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 | ||
87bdc367 DM |
325 | printk(KERN_INFO "sun4v_irq: Mapping (%x:%x) --> sysino[%lx]\n", |
326 | devhandle, devino, sysino); | |
e3999574 DM |
327 | |
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 | ||
1da177e4 LT |
350 | static 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 | ||
088dd1f8 DM |
364 | static 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 | ||
380 | static 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 | ||
389 | static 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 | ||
1da177e4 LT |
410 | int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), |
411 | unsigned long irqflags, const char *name, void *dev_id) | |
412 | { | |
088dd1f8 | 413 | struct irqaction *action; |
1da177e4 LT |
414 | struct ino_bucket *bucket = __bucket(irq); |
415 | unsigned long flags; | |
416 | int pending = 0; | |
417 | ||
088dd1f8 | 418 | if (unlikely(!handler)) |
1da177e4 | 419 | return -EINVAL; |
088dd1f8 DM |
420 | |
421 | if (unlikely(!bucket->irq_info)) | |
422 | return -ENODEV; | |
1da177e4 LT |
423 | |
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 | ||
088dd1f8 DM |
440 | if (check_irq_sharing(bucket->pil, irqflags)) { |
441 | spin_unlock_irqrestore(&irq_action_lock, flags); | |
442 | return -EBUSY; | |
1da177e4 LT |
443 | } |
444 | ||
088dd1f8 | 445 | action = get_action_slot(bucket); |
1da177e4 LT |
446 | if (!action) { |
447 | spin_unlock_irqrestore(&irq_action_lock, flags); | |
448 | return -ENOMEM; | |
449 | } | |
450 | ||
088dd1f8 DM |
451 | bucket->flags |= IBF_ACTIVE; |
452 | pending = 0; | |
453 | if (bucket != &pil0_dummy_bucket) { | |
1da177e4 LT |
454 | 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 | ||
088dd1f8 | 467 | append_irq_action(bucket->pil, action); |
1da177e4 LT |
468 | |
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 | } | |
088dd1f8 | 476 | |
1da177e4 | 477 | spin_unlock_irqrestore(&irq_action_lock, flags); |
088dd1f8 DM |
478 | |
479 | if (bucket != &pil0_dummy_bucket) | |
1da177e4 LT |
480 | register_irq_proc(__irq_ino(irq)); |
481 | ||
482 | #ifdef CONFIG_SMP | |
483 | distribute_irqs(); | |
484 | #endif | |
485 | return 0; | |
1da177e4 LT |
486 | } |
487 | ||
488 | EXPORT_SYMBOL(request_irq); | |
489 | ||
088dd1f8 | 490 | static struct irqaction *unlink_irq_action(unsigned int irq, void *dev_id) |
1da177e4 | 491 | { |
088dd1f8 DM |
492 | struct ino_bucket *bucket = __bucket(irq); |
493 | struct irqaction *action, **pp; | |
1da177e4 | 494 | |
088dd1f8 DM |
495 | pp = irq_action + bucket->pil; |
496 | action = *pp; | |
497 | if (unlikely(!action)) | |
498 | return NULL; | |
1da177e4 | 499 | |
088dd1f8 | 500 | if (unlikely(!action->handler)) { |
1da177e4 | 501 | printk("Freeing free IRQ %d\n", bucket->pil); |
088dd1f8 | 502 | return NULL; |
1da177e4 LT |
503 | } |
504 | ||
088dd1f8 DM |
505 | while (action && action->dev_id != dev_id) { |
506 | pp = &action->next; | |
507 | action = *pp; | |
1da177e4 LT |
508 | } |
509 | ||
088dd1f8 DM |
510 | if (likely(action)) |
511 | *pp = action->next; | |
512 | ||
513 | return action; | |
514 | } | |
515 | ||
516 | void free_irq(unsigned int irq, void *dev_id) | |
517 | { | |
518 | struct irqaction *action; | |
519 | struct ino_bucket *bucket; | |
520 | unsigned long flags; | |
521 | ||
522 | spin_lock_irqsave(&irq_action_lock, flags); | |
523 | ||
524 | action = unlink_irq_action(irq, dev_id); | |
1da177e4 LT |
525 | |
526 | spin_unlock_irqrestore(&irq_action_lock, flags); | |
527 | ||
088dd1f8 DM |
528 | if (unlikely(!action)) |
529 | return; | |
530 | ||
1da177e4 LT |
531 | synchronize_irq(irq); |
532 | ||
533 | spin_lock_irqsave(&irq_action_lock, flags); | |
534 | ||
088dd1f8 | 535 | bucket = __bucket(irq); |
1da177e4 | 536 | if (bucket != &pil0_dummy_bucket) { |
088dd1f8 | 537 | struct irq_desc *desc = bucket->irq_info; |
1da177e4 | 538 | unsigned long imap = bucket->imap; |
088dd1f8 | 539 | int ent, i; |
1da177e4 | 540 | |
088dd1f8 DM |
541 | for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) { |
542 | struct irqaction *p = &desc->action[i]; | |
543 | ||
544 | if (p == action) { | |
545 | desc->action_active_mask &= ~(1 << i); | |
546 | break; | |
1da177e4 | 547 | } |
1da177e4 LT |
548 | } |
549 | ||
088dd1f8 DM |
550 | if (!desc->action_active_mask) { |
551 | /* This unique interrupt source is now inactive. */ | |
552 | bucket->flags &= ~IBF_ACTIVE; | |
1da177e4 | 553 | |
088dd1f8 DM |
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 | } | |
1da177e4 | 564 | |
088dd1f8 DM |
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 | } | |
1da177e4 LT |
571 | } |
572 | ||
1da177e4 LT |
573 | spin_unlock_irqrestore(&irq_action_lock, flags); |
574 | } | |
575 | ||
576 | EXPORT_SYMBOL(free_irq); | |
577 | ||
578 | #ifdef CONFIG_SMP | |
579 | void 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 | ||
088dd1f8 | 611 | static void process_bucket(int irq, struct ino_bucket *bp, struct pt_regs *regs) |
1da177e4 | 612 | { |
088dd1f8 DM |
613 | struct irq_desc *desc = bp->irq_info; |
614 | unsigned char flags = bp->flags; | |
615 | u32 action_mask, i; | |
616 | int random; | |
1da177e4 | 617 | |
088dd1f8 | 618 | bp->flags |= IBF_INPROGRESS; |
1da177e4 | 619 | |
088dd1f8 DM |
620 | if (unlikely(!(flags & IBF_ACTIVE))) { |
621 | bp->pending = 1; | |
1da177e4 | 622 | goto out; |
1da177e4 LT |
623 | } |
624 | ||
088dd1f8 DM |
625 | if (desc->pre_handler) |
626 | desc->pre_handler(bp, | |
627 | desc->pre_handler_arg1, | |
628 | desc->pre_handler_arg2); | |
1da177e4 | 629 | |
088dd1f8 DM |
630 | 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); | |
1da177e4 | 635 | |
088dd1f8 DM |
636 | if (!(action_mask & mask)) |
637 | continue; | |
1da177e4 | 638 | |
088dd1f8 | 639 | action_mask &= ~mask; |
1da177e4 | 640 | |
088dd1f8 DM |
641 | 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) { | |
10951ee6 | 648 | if (tlb_type == hypervisor) { |
4bf447d6 | 649 | unsigned int ino = __irq_ino(bp); |
10951ee6 | 650 | |
4bf447d6 | 651 | sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE); |
10951ee6 DM |
652 | } 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 | } | |
088dd1f8 | 658 | } |
1da177e4 | 659 | out: |
088dd1f8 | 660 | bp->flags &= ~IBF_INPROGRESS; |
1da177e4 LT |
661 | } |
662 | ||
1da177e4 LT |
663 | void handler_irq(int irq, struct pt_regs *regs) |
664 | { | |
088dd1f8 | 665 | struct ino_bucket *bp; |
1da177e4 LT |
666 | 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 | |
1da177e4 LT |
683 | 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 | |
088dd1f8 DM |
697 | while (bp) { |
698 | struct ino_bucket *nbp = __bucket(bp->irq_chain); | |
1da177e4 | 699 | |
1da177e4 | 700 | bp->irq_chain = 0; |
088dd1f8 DM |
701 | process_bucket(irq, bp, regs); |
702 | bp = nbp; | |
1da177e4 LT |
703 | } |
704 | irq_exit(); | |
705 | } | |
706 | ||
707 | #ifdef CONFIG_BLK_DEV_FD | |
63b61452 | 708 | extern irqreturn_t floppy_interrupt(int, void *, struct pt_regs *);; |
1da177e4 | 709 | |
63b61452 DM |
710 | /* XXX No easy way to include asm/floppy.h XXX */ |
711 | extern unsigned char *pdma_vaddr; | |
712 | extern unsigned long pdma_size; | |
713 | extern volatile int doing_pdma; | |
714 | extern unsigned long fdc_status; | |
1da177e4 | 715 | |
63b61452 | 716 | irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie, struct pt_regs *regs) |
1da177e4 | 717 | { |
63b61452 DM |
718 | 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; | |
723 | ||
724 | 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++; | |
1da177e4 | 742 | |
63b61452 DM |
743 | /* write */ |
744 | writeb(data, stat + 1); | |
745 | } | |
746 | size--; | |
747 | } | |
1da177e4 | 748 | |
63b61452 DM |
749 | pdma_vaddr = vaddr; |
750 | pdma_size = size; | |
1da177e4 | 751 | |
63b61452 DM |
752 | /* Send Terminal Count pulse to floppy controller. */ |
753 | val = readb(auxio_register); | |
754 | val |= AUXIO_AUX1_FTCNT; | |
755 | writeb(val, auxio_register); | |
94bbc176 | 756 | val &= ~AUXIO_AUX1_FTCNT; |
63b61452 | 757 | writeb(val, auxio_register); |
1da177e4 | 758 | |
63b61452 | 759 | doing_pdma = 0; |
1da177e4 | 760 | } |
1da177e4 | 761 | |
63b61452 DM |
762 | main_interrupt: |
763 | return floppy_interrupt(irq, dev_cookie, regs); | |
1da177e4 | 764 | } |
63b61452 DM |
765 | EXPORT_SYMBOL(sparc_floppy_irq); |
766 | #endif | |
1da177e4 LT |
767 | |
768 | /* We really don't need these at all on the Sparc. We only have | |
769 | * stubs here because they are exported to modules. | |
770 | */ | |
771 | unsigned long probe_irq_on(void) | |
772 | { | |
773 | return 0; | |
774 | } | |
775 | ||
776 | EXPORT_SYMBOL(probe_irq_on); | |
777 | ||
778 | int probe_irq_off(unsigned long mask) | |
779 | { | |
780 | return 0; | |
781 | } | |
782 | ||
783 | EXPORT_SYMBOL(probe_irq_off); | |
784 | ||
785 | #ifdef CONFIG_SMP | |
786 | static 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; | |
1da177e4 LT |
790 | |
791 | while (!cpu_online(goal_cpu)) { | |
792 | if (++goal_cpu >= NR_CPUS) | |
793 | goal_cpu = 0; | |
794 | } | |
795 | ||
10951ee6 | 796 | if (tlb_type == hypervisor) { |
4bf447d6 | 797 | unsigned int ino = __irq_ino(bucket); |
10951ee6 | 798 | |
4bf447d6 DM |
799 | sun4v_intr_settarget(ino, goal_cpu); |
800 | sun4v_intr_setenabled(ino, HV_INTR_ENABLED); | |
1da177e4 | 801 | } else { |
10951ee6 DM |
802 | 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); | |
1da177e4 | 815 | } |
1da177e4 | 816 | |
cee2824f | 817 | do { |
1da177e4 LT |
818 | if (++goal_cpu >= NR_CPUS) |
819 | goal_cpu = 0; | |
cee2824f | 820 | } while (!cpu_online(goal_cpu)); |
1da177e4 LT |
821 | |
822 | return goal_cpu; | |
823 | } | |
824 | ||
825 | /* Called from request_irq. */ | |
826 | static 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]; | |
088dd1f8 DM |
840 | |
841 | if (level == 12) | |
842 | continue; | |
843 | ||
1da177e4 LT |
844 | 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 | ||
cdd5186f DM |
853 | struct sun5_timer { |
854 | u64 count0; | |
855 | u64 limit0; | |
856 | u64 count1; | |
857 | u64 limit1; | |
858 | }; | |
1da177e4 | 859 | |
cdd5186f | 860 | static struct sun5_timer *prom_timers; |
1da177e4 LT |
861 | static u64 prom_limit0, prom_limit1; |
862 | ||
863 | static 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 | ||
889 | static 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 | ||
1da177e4 LT |
916 | void init_irqwork_curcpu(void) |
917 | { | |
1da177e4 LT |
918 | int cpu = hard_smp_processor_id(); |
919 | ||
56fb4df6 | 920 | memset(__irq_work + cpu, 0, sizeof(struct irq_work_struct)); |
1da177e4 LT |
921 | } |
922 | ||
b5a37e96 | 923 | static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type) |
ac29c11d | 924 | { |
164c220f DM |
925 | 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"); | |
ac29c11d DM |
929 | |
930 | func = HV_FAST_CPU_QCONF; | |
931 | arg0 = type; | |
b5a37e96 | 932 | arg1 = paddr; |
ac29c11d DM |
933 | 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 | ||
b5a37e96 | 941 | if (arg0 != HV_EOK) { |
ac29c11d DM |
942 | prom_printf("SUN4V: cpu_qconf(%lu) failed with error %lu\n", |
943 | type, func); | |
944 | prom_halt(); | |
945 | } | |
946 | } | |
947 | ||
b5a37e96 | 948 | static void __cpuinit sun4v_register_mondo_queues(int this_cpu) |
5b0c0572 | 949 | { |
b5a37e96 DM |
950 | 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 | ||
958 | static 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 | ||
975 | static 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); | |
5b0c0572 DM |
983 | |
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 | ||
b5a37e96 | 992 | static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem) |
1d2f1f90 DM |
993 | { |
994 | #ifdef CONFIG_SMP | |
b5a37e96 | 995 | void *page; |
1d2f1f90 DM |
996 | |
997 | BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64)); | |
998 | ||
b5a37e96 DM |
999 | if (use_bootmem) |
1000 | page = alloc_bootmem_low_pages(PAGE_SIZE); | |
1001 | else | |
1002 | page = (void *) get_zeroed_page(GFP_ATOMIC); | |
1003 | ||
1d2f1f90 DM |
1004 | 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 | ||
b5a37e96 DM |
1014 | /* Allocate and register the mondo and error queues for this cpu. */ |
1015 | void __cpuinit sun4v_init_mondo_queues(int use_bootmem) | |
ac29c11d DM |
1016 | { |
1017 | int cpu = hard_smp_processor_id(); | |
1018 | struct trap_per_cpu *tb = &trap_block[cpu]; | |
1019 | ||
b5a37e96 DM |
1020 | 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); | |
1d2f1f90 | 1026 | |
b5a37e96 | 1027 | init_cpu_send_mondo_info(tb, use_bootmem); |
1d2f1f90 | 1028 | |
b5a37e96 | 1029 | sun4v_register_mondo_queues(cpu); |
ac29c11d DM |
1030 | } |
1031 | ||
1da177e4 LT |
1032 | /* Only invoked on boot processor. */ |
1033 | void __init init_IRQ(void) | |
1034 | { | |
1035 | map_prom_timers(); | |
1036 | kill_prom_timer(); | |
1037 | memset(&ivector_table[0], 0, sizeof(ivector_table)); | |
1038 | ||
ac29c11d | 1039 | if (tlb_type == hypervisor) |
b5a37e96 | 1040 | sun4v_init_mondo_queues(1); |
ac29c11d | 1041 | |
1da177e4 LT |
1042 | /* 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 | ||
1061 | static struct proc_dir_entry * root_irq_dir; | |
1062 | static struct proc_dir_entry * irq_dir [NUM_IVECS]; | |
1063 | ||
1064 | #ifdef CONFIG_SMP | |
1065 | ||
1066 | static 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; | |
12cf649f ED |
1070 | struct irq_desc *desc = bp->irq_info; |
1071 | struct irqaction *ap = desc->action; | |
1da177e4 LT |
1072 | 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 | ||
1086 | static inline void set_intr_affinity(int irq, cpumask_t hw_aff) | |
1087 | { | |
1088 | struct ino_bucket *bp = ivector_table + irq; | |
12cf649f ED |
1089 | struct irq_desc *desc = bp->irq_info; |
1090 | struct irqaction *ap = desc->action; | |
1da177e4 LT |
1091 | |
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 | */ | |
12cf649f | 1095 | put_smpaff_in_irqaction(ap, hw_aff); |
1da177e4 LT |
1096 | |
1097 | /* Migration is simply done by the next cpu to service this | |
1098 | * interrupt. | |
1099 | */ | |
1100 | } | |
1101 | ||
1102 | static 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 | ||
1128 | static 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 | ||
1159 | void init_irq_proc (void) | |
1160 | { | |
1161 | /* create /proc/irq */ | |
1162 | root_irq_dir = proc_mkdir("irq", NULL); | |
1163 | } | |
1164 |