aboutsummaryrefslogtreecommitdiffstats
path: root/arch/v850
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2005-11-15 03:09:18 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-15 11:59:20 -0500
commit0c53508980a95b84c296c4336a831776cc22cf58 (patch)
tree66f908cb6cbdeb2bbc34fd3a3ab08090ecc3d9a2 /arch/v850
parentf4eeb0a20f017fd8bc849cc50469c2e2e6a0c05c (diff)
[PATCH] v850: use generic hardirq code
Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Miles Bader <miles@gnu.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/v850')
-rw-r--r--arch/v850/Kconfig8
-rw-r--r--arch/v850/kernel/irq.c636
2 files changed, 13 insertions, 631 deletions
diff --git a/arch/v850/Kconfig b/arch/v850/Kconfig
index 89c053b6c2c4..310865903234 100644
--- a/arch/v850/Kconfig
+++ b/arch/v850/Kconfig
@@ -23,6 +23,14 @@ config GENERIC_CALIBRATE_DELAY
23 bool 23 bool
24 default y 24 default y
25 25
26config GENERIC_HARDIRQS
27 bool
28 default y
29
30config GENERIC_IRQ_PROBE
31 bool
32 default y
33
26# Turn off some random 386 crap that can affect device config 34# Turn off some random 386 crap that can affect device config
27config ISA 35config ISA
28 bool 36 bool
diff --git a/arch/v850/kernel/irq.c b/arch/v850/kernel/irq.c
index 534eb8ab97a7..7a151c26f82e 100644
--- a/arch/v850/kernel/irq.c
+++ b/arch/v850/kernel/irq.c
@@ -27,55 +27,15 @@
27#include <asm/system.h> 27#include <asm/system.h>
28 28
29/* 29/*
30 * Controller mappings for all interrupt sources: 30 * 'what should we do if we get a hw irq event on an illegal vector'.
31 * each architecture has to answer this themselves, it doesn't deserve
32 * a generic callback i think.
31 */ 33 */
32irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = { 34void ack_bad_irq(unsigned int irq)
33 [0 ... NR_IRQS-1] = {
34 .handler = &no_irq_type,
35 .lock = SPIN_LOCK_UNLOCKED
36 }
37};
38
39/*
40 * Special irq handlers.
41 */
42
43irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
44{
45 return IRQ_NONE;
46}
47
48/*
49 * Generic no controller code
50 */
51
52static void enable_none(unsigned int irq) { }
53static unsigned int startup_none(unsigned int irq) { return 0; }
54static void disable_none(unsigned int irq) { }
55static void ack_none(unsigned int irq)
56{ 35{
57 /*
58 * 'what should we do if we get a hw irq event on an illegal vector'.
59 * each architecture has to answer this themselves, it doesn't deserve
60 * a generic callback i think.
61 */
62 printk("received IRQ %d with unknown interrupt type\n", irq); 36 printk("received IRQ %d with unknown interrupt type\n", irq);
63} 37}
64 38
65/* startup is the same as "enable", shutdown is same as "disable" */
66#define shutdown_none disable_none
67#define end_none enable_none
68
69struct hw_interrupt_type no_irq_type = {
70 .typename = "none",
71 .startup = startup_none,
72 .shutdown = shutdown_none,
73 .enable = enable_none,
74 .disable = disable_none,
75 .ack = ack_none,
76 .end = end_none
77};
78
79volatile unsigned long irq_err_count, spurious_count; 39volatile unsigned long irq_err_count, spurious_count;
80 40
81/* 41/*
@@ -136,596 +96,16 @@ int show_interrupts(struct seq_file *p, void *v)
136 return 0; 96 return 0;
137} 97}
138 98
139/*
140 * This should really return information about whether
141 * we should do bottom half handling etc. Right now we
142 * end up _always_ checking the bottom half, which is a
143 * waste of time and is not what some drivers would
144 * prefer.
145 */
146int handle_IRQ_event(unsigned int irq, struct pt_regs * regs, struct irqaction * action)
147{
148 int status = 1; /* Force the "do bottom halves" bit */
149 int ret;
150
151 if (!(action->flags & SA_INTERRUPT))
152 local_irq_enable();
153
154 do {
155 ret = action->handler(irq, action->dev_id, regs);
156 if (ret == IRQ_HANDLED)
157 status |= action->flags;
158 action = action->next;
159 } while (action);
160 if (status & SA_SAMPLE_RANDOM)
161 add_interrupt_randomness(irq);
162 local_irq_disable();
163
164 return status;
165}
166
167/*
168 * Generic enable/disable code: this just calls
169 * down into the PIC-specific version for the actual
170 * hardware disable after having gotten the irq
171 * controller lock.
172 */
173
174/**
175 * disable_irq_nosync - disable an irq without waiting
176 * @irq: Interrupt to disable
177 *
178 * Disable the selected interrupt line. Disables of an interrupt
179 * stack. Unlike disable_irq(), this function does not ensure existing
180 * instances of the IRQ handler have completed before returning.
181 *
182 * This function may be called from IRQ context.
183 */
184
185void inline disable_irq_nosync(unsigned int irq)
186{
187 irq_desc_t *desc = irq_desc + irq;
188 unsigned long flags;
189
190 spin_lock_irqsave(&desc->lock, flags);
191 if (!desc->depth++) {
192 desc->status |= IRQ_DISABLED;
193 desc->handler->disable(irq);
194 }
195 spin_unlock_irqrestore(&desc->lock, flags);
196}
197
198/**
199 * disable_irq - disable an irq and wait for completion
200 * @irq: Interrupt to disable
201 *
202 * Disable the selected interrupt line. Disables of an interrupt
203 * stack. That is for two disables you need two enables. This
204 * function waits for any pending IRQ handlers for this interrupt
205 * to complete before returning. If you use this function while
206 * holding a resource the IRQ handler may need you will deadlock.
207 *
208 * This function may be called - with care - from IRQ context.
209 */
210
211void disable_irq(unsigned int irq)
212{
213 disable_irq_nosync(irq);
214 synchronize_irq(irq);
215}
216
217/**
218 * enable_irq - enable interrupt handling on an irq
219 * @irq: Interrupt to enable
220 *
221 * Re-enables the processing of interrupts on this IRQ line
222 * providing no disable_irq calls are now in effect.
223 *
224 * This function may be called from IRQ context.
225 */
226
227void enable_irq(unsigned int irq)
228{
229 irq_desc_t *desc = irq_desc + irq;
230 unsigned long flags;
231
232 spin_lock_irqsave(&desc->lock, flags);
233 switch (desc->depth) {
234 case 1: {
235 unsigned int status = desc->status & ~IRQ_DISABLED;
236 desc->status = status;
237 if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
238 desc->status = status | IRQ_REPLAY;
239 hw_resend_irq(desc->handler,irq);
240 }
241 desc->handler->enable(irq);
242 /* fall-through */
243 }
244 default:
245 desc->depth--;
246 break;
247 case 0:
248 printk("enable_irq(%u) unbalanced from %p\n", irq,
249 __builtin_return_address(0));
250 }
251 spin_unlock_irqrestore(&desc->lock, flags);
252}
253
254/* Handle interrupt IRQ. REGS are the registers at the time of ther 99/* Handle interrupt IRQ. REGS are the registers at the time of ther
255 interrupt. */ 100 interrupt. */
256unsigned int handle_irq (int irq, struct pt_regs *regs) 101unsigned int handle_irq (int irq, struct pt_regs *regs)
257{ 102{
258 /*
259 * We ack quickly, we don't want the irq controller
260 * thinking we're snobs just because some other CPU has
261 * disabled global interrupts (we have already done the
262 * INT_ACK cycles, it's too late to try to pretend to the
263 * controller that we aren't taking the interrupt).
264 *
265 * 0 return value means that this irq is already being
266 * handled by some other CPU. (or is disabled)
267 */
268 int cpu = smp_processor_id();
269 irq_desc_t *desc = irq_desc + irq;
270 struct irqaction * action;
271 unsigned int status;
272
273 irq_enter(); 103 irq_enter();
274 kstat_cpu(cpu).irqs[irq]++; 104 __do_IRQ(irq, regs);
275 spin_lock(&desc->lock);
276 desc->handler->ack(irq);
277 /*
278 REPLAY is when Linux resends an IRQ that was dropped earlier
279 WAITING is used by probe to mark irqs that are being tested
280 */
281 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
282 status |= IRQ_PENDING; /* we _want_ to handle it */
283
284 /*
285 * If the IRQ is disabled for whatever reason, we cannot
286 * use the action we have.
287 */
288 action = NULL;
289 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
290 action = desc->action;
291 status &= ~IRQ_PENDING; /* we commit to handling */
292 status |= IRQ_INPROGRESS; /* we are handling it */
293 }
294 desc->status = status;
295
296 /*
297 * If there is no IRQ handler or it was disabled, exit early.
298 Since we set PENDING, if another processor is handling
299 a different instance of this same irq, the other processor
300 will take care of it.
301 */
302 if (unlikely(!action))
303 goto out;
304
305 /*
306 * Edge triggered interrupts need to remember
307 * pending events.
308 * This applies to any hw interrupts that allow a second
309 * instance of the same irq to arrive while we are in handle_irq
310 * or in the handler. But the code here only handles the _second_
311 * instance of the irq, not the third or fourth. So it is mostly
312 * useful for irq hardware that does not mask cleanly in an
313 * SMP environment.
314 */
315 for (;;) {
316 spin_unlock(&desc->lock);
317 handle_IRQ_event(irq, regs, action);
318 spin_lock(&desc->lock);
319
320 if (likely(!(desc->status & IRQ_PENDING)))
321 break;
322 desc->status &= ~IRQ_PENDING;
323 }
324 desc->status &= ~IRQ_INPROGRESS;
325
326out:
327 /*
328 * The ->end() handler has to deal with interrupts which got
329 * disabled while the handler was running.
330 */
331 desc->handler->end(irq);
332 spin_unlock(&desc->lock);
333
334 irq_exit(); 105 irq_exit();
335
336 return 1; 106 return 1;
337} 107}
338 108
339/**
340 * request_irq - allocate an interrupt line
341 * @irq: Interrupt line to allocate
342 * @handler: Function to be called when the IRQ occurs
343 * @irqflags: Interrupt type flags
344 * @devname: An ascii name for the claiming device
345 * @dev_id: A cookie passed back to the handler function
346 *
347 * This call allocates interrupt resources and enables the
348 * interrupt line and IRQ handling. From the point this
349 * call is made your handler function may be invoked. Since
350 * your handler function must clear any interrupt the board
351 * raises, you must take care both to initialise your hardware
352 * and to set up the interrupt handler in the right order.
353 *
354 * Dev_id must be globally unique. Normally the address of the
355 * device data structure is used as the cookie. Since the handler
356 * receives this value it makes sense to use it.
357 *
358 * If your interrupt is shared you must pass a non NULL dev_id
359 * as this is required when freeing the interrupt.
360 *
361 * Flags:
362 *
363 * SA_SHIRQ Interrupt is shared
364 *
365 * SA_INTERRUPT Disable local interrupts while processing
366 *
367 * SA_SAMPLE_RANDOM The interrupt can be used for entropy
368 *
369 */
370
371int request_irq(unsigned int irq,
372 irqreturn_t (*handler)(int, void *, struct pt_regs *),
373 unsigned long irqflags,
374 const char * devname,
375 void *dev_id)
376{
377 int retval;
378 struct irqaction * action;
379
380#if 1
381 /*
382 * Sanity-check: shared interrupts should REALLY pass in
383 * a real dev-ID, otherwise we'll have trouble later trying
384 * to figure out which interrupt is which (messes up the
385 * interrupt freeing logic etc).
386 */
387 if (irqflags & SA_SHIRQ) {
388 if (!dev_id)
389 printk("Bad boy: %s (at 0x%x) called us without a dev_id!\n", devname, (&irq)[-1]);
390 }
391#endif
392
393 if (irq >= NR_IRQS)
394 return -EINVAL;
395 if (!handler)
396 return -EINVAL;
397
398 action = (struct irqaction *)
399 kmalloc(sizeof(struct irqaction), GFP_KERNEL);
400 if (!action)
401 return -ENOMEM;
402
403 action->handler = handler;
404 action->flags = irqflags;
405 cpus_clear(action->mask);
406 action->name = devname;
407 action->next = NULL;
408 action->dev_id = dev_id;
409
410 retval = setup_irq(irq, action);
411 if (retval)
412 kfree(action);
413 return retval;
414}
415
416EXPORT_SYMBOL(request_irq);
417
418/**
419 * free_irq - free an interrupt
420 * @irq: Interrupt line to free
421 * @dev_id: Device identity to free
422 *
423 * Remove an interrupt handler. The handler is removed and if the
424 * interrupt line is no longer in use by any driver it is disabled.
425 * On a shared IRQ the caller must ensure the interrupt is disabled
426 * on the card it drives before calling this function. The function
427 * does not return until any executing interrupts for this IRQ
428 * have completed.
429 *
430 * This function may be called from interrupt context.
431 *
432 * Bugs: Attempting to free an irq in a handler for the same irq hangs
433 * the machine.
434 */
435
436void free_irq(unsigned int irq, void *dev_id)
437{
438 irq_desc_t *desc;
439 struct irqaction **p;
440 unsigned long flags;
441
442 if (irq >= NR_IRQS)
443 return;
444
445 desc = irq_desc + irq;
446 spin_lock_irqsave(&desc->lock,flags);
447 p = &desc->action;
448 for (;;) {
449 struct irqaction * action = *p;
450 if (action) {
451 struct irqaction **pp = p;
452 p = &action->next;
453 if (action->dev_id != dev_id)
454 continue;
455
456 /* Found it - now remove it from the list of entries */
457 *pp = action->next;
458 if (!desc->action) {
459 desc->status |= IRQ_DISABLED;
460 desc->handler->shutdown(irq);
461 }
462 spin_unlock_irqrestore(&desc->lock,flags);
463
464 synchronize_irq(irq);
465 kfree(action);
466 return;
467 }
468 printk("Trying to free free IRQ%d\n",irq);
469 spin_unlock_irqrestore(&desc->lock,flags);
470 return;
471 }
472}
473
474EXPORT_SYMBOL(free_irq);
475
476/*
477 * IRQ autodetection code..
478 *
479 * This depends on the fact that any interrupt that
480 * comes in on to an unassigned handler will get stuck
481 * with "IRQ_WAITING" cleared and the interrupt
482 * disabled.
483 */
484
485static DECLARE_MUTEX(probe_sem);
486
487/**
488 * probe_irq_on - begin an interrupt autodetect
489 *
490 * Commence probing for an interrupt. The interrupts are scanned
491 * and a mask of potential interrupt lines is returned.
492 *
493 */
494
495unsigned long probe_irq_on(void)
496{
497 unsigned int i;
498 irq_desc_t *desc;
499 unsigned long val;
500 unsigned long delay;
501
502 down(&probe_sem);
503 /*
504 * something may have generated an irq long ago and we want to
505 * flush such a longstanding irq before considering it as spurious.
506 */
507 for (i = NR_IRQS-1; i > 0; i--) {
508 desc = irq_desc + i;
509
510 spin_lock_irq(&desc->lock);
511 if (!irq_desc[i].action)
512 irq_desc[i].handler->startup(i);
513 spin_unlock_irq(&desc->lock);
514 }
515
516 /* Wait for longstanding interrupts to trigger. */
517 for (delay = jiffies + HZ/50; time_after(delay, jiffies); )
518 /* about 20ms delay */ barrier();
519
520 /*
521 * enable any unassigned irqs
522 * (we must startup again here because if a longstanding irq
523 * happened in the previous stage, it may have masked itself)
524 */
525 for (i = NR_IRQS-1; i > 0; i--) {
526 desc = irq_desc + i;
527
528 spin_lock_irq(&desc->lock);
529 if (!desc->action) {
530 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
531 if (desc->handler->startup(i))
532 desc->status |= IRQ_PENDING;
533 }
534 spin_unlock_irq(&desc->lock);
535 }
536
537 /*
538 * Wait for spurious interrupts to trigger
539 */
540 for (delay = jiffies + HZ/10; time_after(delay, jiffies); )
541 /* about 100ms delay */ barrier();
542
543 /*
544 * Now filter out any obviously spurious interrupts
545 */
546 val = 0;
547 for (i = 0; i < NR_IRQS; i++) {
548 irq_desc_t *desc = irq_desc + i;
549 unsigned int status;
550
551 spin_lock_irq(&desc->lock);
552 status = desc->status;
553
554 if (status & IRQ_AUTODETECT) {
555 /* It triggered already - consider it spurious. */
556 if (!(status & IRQ_WAITING)) {
557 desc->status = status & ~IRQ_AUTODETECT;
558 desc->handler->shutdown(i);
559 } else
560 if (i < 32)
561 val |= 1 << i;
562 }
563 spin_unlock_irq(&desc->lock);
564 }
565
566 return val;
567}
568
569EXPORT_SYMBOL(probe_irq_on);
570
571/*
572 * Return a mask of triggered interrupts (this
573 * can handle only legacy ISA interrupts).
574 */
575
576/**
577 * probe_irq_mask - scan a bitmap of interrupt lines
578 * @val: mask of interrupts to consider
579 *
580 * Scan the ISA bus interrupt lines and return a bitmap of
581 * active interrupts. The interrupt probe logic state is then
582 * returned to its previous value.
583 *
584 * Note: we need to scan all the irq's even though we will
585 * only return ISA irq numbers - just so that we reset them
586 * all to a known state.
587 */
588unsigned int probe_irq_mask(unsigned long val)
589{
590 int i;
591 unsigned int mask;
592
593 mask = 0;
594 for (i = 0; i < NR_IRQS; i++) {
595 irq_desc_t *desc = irq_desc + i;
596 unsigned int status;
597
598 spin_lock_irq(&desc->lock);
599 status = desc->status;
600
601 if (status & IRQ_AUTODETECT) {
602 if (i < 16 && !(status & IRQ_WAITING))
603 mask |= 1 << i;
604
605 desc->status = status & ~IRQ_AUTODETECT;
606 desc->handler->shutdown(i);
607 }
608 spin_unlock_irq(&desc->lock);
609 }
610 up(&probe_sem);
611
612 return mask & val;
613}
614
615/*
616 * Return the one interrupt that triggered (this can
617 * handle any interrupt source).
618 */
619
620/**
621 * probe_irq_off - end an interrupt autodetect
622 * @val: mask of potential interrupts (unused)
623 *
624 * Scans the unused interrupt lines and returns the line which
625 * appears to have triggered the interrupt. If no interrupt was
626 * found then zero is returned. If more than one interrupt is
627 * found then minus the first candidate is returned to indicate
628 * their is doubt.
629 *
630 * The interrupt probe logic state is returned to its previous
631 * value.
632 *
633 * BUGS: When used in a module (which arguably shouldnt happen)
634 * nothing prevents two IRQ probe callers from overlapping. The
635 * results of this are non-optimal.
636 */
637
638int probe_irq_off(unsigned long val)
639{
640 int i, irq_found, nr_irqs;
641
642 nr_irqs = 0;
643 irq_found = 0;
644 for (i = 0; i < NR_IRQS; i++) {
645 irq_desc_t *desc = irq_desc + i;
646 unsigned int status;
647
648 spin_lock_irq(&desc->lock);
649 status = desc->status;
650
651 if (status & IRQ_AUTODETECT) {
652 if (!(status & IRQ_WAITING)) {
653 if (!nr_irqs)
654 irq_found = i;
655 nr_irqs++;
656 }
657 desc->status = status & ~IRQ_AUTODETECT;
658 desc->handler->shutdown(i);
659 }
660 spin_unlock_irq(&desc->lock);
661 }
662 up(&probe_sem);
663
664 if (nr_irqs > 1)
665 irq_found = -irq_found;
666 return irq_found;
667}
668
669EXPORT_SYMBOL(probe_irq_off);
670
671/* this was setup_x86_irq but it seems pretty generic */
672int setup_irq(unsigned int irq, struct irqaction * new)
673{
674 int shared = 0;
675 unsigned long flags;
676 struct irqaction *old, **p;
677 irq_desc_t *desc = irq_desc + irq;
678
679 /*
680 * Some drivers like serial.c use request_irq() heavily,
681 * so we have to be careful not to interfere with a
682 * running system.
683 */
684 if (new->flags & SA_SAMPLE_RANDOM) {
685 /*
686 * This function might sleep, we want to call it first,
687 * outside of the atomic block.
688 * Yes, this might clear the entropy pool if the wrong
689 * driver is attempted to be loaded, without actually
690 * installing a new handler, but is this really a problem,
691 * only the sysadmin is able to do this.
692 */
693 rand_initialize_irq(irq);
694 }
695
696 /*
697 * The following block of code has to be executed atomically
698 */
699 spin_lock_irqsave(&desc->lock,flags);
700 p = &desc->action;
701 if ((old = *p) != NULL) {
702 /* Can't share interrupts unless both agree to */
703 if (!(old->flags & new->flags & SA_SHIRQ)) {
704 spin_unlock_irqrestore(&desc->lock,flags);
705 return -EBUSY;
706 }
707
708 /* add new interrupt at end of irq queue */
709 do {
710 p = &old->next;
711 old = *p;
712 } while (old);
713 shared = 1;
714 }
715
716 *p = new;
717
718 if (!shared) {
719 desc->depth = 0;
720 desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
721 desc->handler->startup(irq);
722 }
723 spin_unlock_irqrestore(&desc->lock,flags);
724
725 /* register_irq_proc(irq); */
726 return 0;
727}
728
729/* Initialize irq handling for IRQs. 109/* Initialize irq handling for IRQs.
730 BASE_IRQ, BASE_IRQ+INTERVAL, ..., BASE_IRQ+NUM*INTERVAL 110 BASE_IRQ, BASE_IRQ+INTERVAL, ..., BASE_IRQ+NUM*INTERVAL
731 to IRQ_TYPE. An IRQ_TYPE of 0 means to use a generic interrupt type. */ 111 to IRQ_TYPE. An IRQ_TYPE of 0 means to use a generic interrupt type. */
@@ -741,9 +121,3 @@ init_irq_handlers (int base_irq, int num, int interval,
741 base_irq += interval; 121 base_irq += interval;
742 } 122 }
743} 123}
744
745#if defined(CONFIG_PROC_FS) && defined(CONFIG_SYSCTL)
746void init_irq_proc(void)
747{
748}
749#endif /* CONFIG_PROC_FS && CONFIG_SYSCTL */