irq.c 4.3 KB

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