irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. * Derived (i.e. mostly copied) from arch/i386/kernel/irq.c:
  5. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  6. */
  7. #include "linux/config.h"
  8. #include "linux/kernel.h"
  9. #include "linux/module.h"
  10. #include "linux/smp.h"
  11. #include "linux/kernel_stat.h"
  12. #include "linux/interrupt.h"
  13. #include "linux/random.h"
  14. #include "linux/slab.h"
  15. #include "linux/file.h"
  16. #include "linux/proc_fs.h"
  17. #include "linux/init.h"
  18. #include "linux/seq_file.h"
  19. #include "linux/profile.h"
  20. #include "linux/hardirq.h"
  21. #include "asm/irq.h"
  22. #include "asm/hw_irq.h"
  23. #include "asm/atomic.h"
  24. #include "asm/signal.h"
  25. #include "asm/system.h"
  26. #include "asm/errno.h"
  27. #include "asm/uaccess.h"
  28. #include "user_util.h"
  29. #include "kern_util.h"
  30. #include "irq_user.h"
  31. #include "irq_kern.h"
  32. #include "os.h"
  33. /*
  34. * Generic, controller-independent functions:
  35. */
  36. int show_interrupts(struct seq_file *p, void *v)
  37. {
  38. int i = *(loff_t *) v, j;
  39. struct irqaction * action;
  40. unsigned long flags;
  41. if (i == 0) {
  42. seq_printf(p, " ");
  43. for_each_online_cpu(j)
  44. seq_printf(p, "CPU%d ",j);
  45. seq_putc(p, '\n');
  46. }
  47. if (i < NR_IRQS) {
  48. spin_lock_irqsave(&irq_desc[i].lock, flags);
  49. action = irq_desc[i].action;
  50. if (!action)
  51. goto skip;
  52. seq_printf(p, "%3d: ",i);
  53. #ifndef CONFIG_SMP
  54. seq_printf(p, "%10u ", kstat_irqs(i));
  55. #else
  56. for_each_online_cpu(j)
  57. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  58. #endif
  59. seq_printf(p, " %14s", irq_desc[i].handler->typename);
  60. seq_printf(p, " %s", action->name);
  61. for (action=action->next; action; action = action->next)
  62. seq_printf(p, ", %s", action->name);
  63. seq_putc(p, '\n');
  64. skip:
  65. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  66. } else if (i == NR_IRQS) {
  67. seq_putc(p, '\n');
  68. }
  69. return 0;
  70. }
  71. /*
  72. * do_IRQ handles all normal device IRQ's (the special
  73. * SMP cross-CPU interrupts have their own specific
  74. * handlers).
  75. */
  76. unsigned int do_IRQ(int irq, union uml_pt_regs *regs)
  77. {
  78. irq_enter();
  79. __do_IRQ(irq, (struct pt_regs *) regs);
  80. irq_exit();
  81. return 1;
  82. }
  83. int um_request_irq(unsigned int irq, int fd, int type,
  84. irqreturn_t (*handler)(int, void *, struct pt_regs *),
  85. unsigned long irqflags, const char * devname,
  86. void *dev_id)
  87. {
  88. int err;
  89. err = request_irq(irq, handler, irqflags, devname, dev_id);
  90. if(err)
  91. return(err);
  92. if(fd != -1)
  93. err = activate_fd(irq, fd, type, dev_id);
  94. return(err);
  95. }
  96. EXPORT_SYMBOL(um_request_irq);
  97. EXPORT_SYMBOL(reactivate_fd);
  98. static DEFINE_SPINLOCK(irq_spinlock);
  99. unsigned long irq_lock(void)
  100. {
  101. unsigned long flags;
  102. spin_lock_irqsave(&irq_spinlock, flags);
  103. return(flags);
  104. }
  105. void irq_unlock(unsigned long flags)
  106. {
  107. spin_unlock_irqrestore(&irq_spinlock, flags);
  108. }
  109. /* hw_interrupt_type must define (startup || enable) &&
  110. * (shutdown || disable) && end */
  111. static void dummy(unsigned int irq)
  112. {
  113. }
  114. /* This is used for everything else than the timer. */
  115. static struct hw_interrupt_type normal_irq_type = {
  116. .typename = "SIGIO",
  117. .release = free_irq_by_irq_and_dev,
  118. .disable = dummy,
  119. .enable = dummy,
  120. .ack = dummy,
  121. .end = dummy
  122. };
  123. static struct hw_interrupt_type SIGVTALRM_irq_type = {
  124. .typename = "SIGVTALRM",
  125. .release = free_irq_by_irq_and_dev,
  126. .shutdown = dummy, /* never called */
  127. .disable = dummy,
  128. .enable = dummy,
  129. .ack = dummy,
  130. .end = dummy
  131. };
  132. void __init init_IRQ(void)
  133. {
  134. int i;
  135. irq_desc[TIMER_IRQ].status = IRQ_DISABLED;
  136. irq_desc[TIMER_IRQ].action = NULL;
  137. irq_desc[TIMER_IRQ].depth = 1;
  138. irq_desc[TIMER_IRQ].handler = &SIGVTALRM_irq_type;
  139. enable_irq(TIMER_IRQ);
  140. for(i=1;i<NR_IRQS;i++){
  141. irq_desc[i].status = IRQ_DISABLED;
  142. irq_desc[i].action = NULL;
  143. irq_desc[i].depth = 1;
  144. irq_desc[i].handler = &normal_irq_type;
  145. enable_irq(i);
  146. }
  147. }
  148. int init_aio_irq(int irq, char *name, irqreturn_t (*handler)(int, void *,
  149. struct pt_regs *))
  150. {
  151. int fds[2], err;
  152. err = os_pipe(fds, 1, 1);
  153. if(err){
  154. printk("init_aio_irq - os_pipe failed, err = %d\n", -err);
  155. goto out;
  156. }
  157. err = um_request_irq(irq, fds[0], IRQ_READ, handler,
  158. SA_INTERRUPT | SA_SAMPLE_RANDOM, name,
  159. (void *) (long) fds[0]);
  160. if(err){
  161. printk("init_aio_irq - : um_request_irq failed, err = %d\n",
  162. err);
  163. goto out_close;
  164. }
  165. err = fds[1];
  166. goto out;
  167. out_close:
  168. os_close_file(fds[0]);
  169. os_close_file(fds[1]);
  170. out:
  171. return(err);
  172. }