irq_ia64.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/ia64/kernel/irq.c
  3.  *
  4.  * Copyright (C) 1998-2001 Hewlett-Packard Co
  5.  * Stephane Eranian <eranian@hpl.hp.com>
  6.  * David Mosberger-Tang <davidm@hpl.hp.com>
  7.  *
  8.  *  6/10/99: Updated to bring in sync with x86 version to facilitate
  9.  *      support for SMP and different interrupt controllers.
  10.  *
  11.  * 09/15/00 Goutham Rao <goutham.rao@intel.com> Implemented pci_irq_to_vector
  12.  *                      PCI to vector allocation routine.
  13.  */
  14. #include <linux/config.h>
  15. #include <linux/sched.h>
  16. #include <linux/errno.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ioport.h>
  20. #include <linux/kernel_stat.h>
  21. #include <linux/slab.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/random.h> /* for rand_initialize_irq() */
  24. #include <linux/signal.h>
  25. #include <linux/smp.h>
  26. #include <linux/smp_lock.h>
  27. #include <linux/threads.h>
  28. #include <asm/bitops.h>
  29. #include <asm/delay.h>
  30. #include <asm/io.h>
  31. #include <asm/hw_irq.h>
  32. #include <asm/machvec.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/system.h>
  35. #ifdef CONFIG_PERFMON
  36. # include <asm/perfmon.h>
  37. #endif
  38. #define IRQ_DEBUG 0
  39. /* default base addr of IPI table */
  40. unsigned long ipi_base_addr = (__IA64_UNCACHED_OFFSET | IA64_IPI_DEFAULT_BASE_ADDR);
  41. /*
  42.  * Legacy IRQ to IA-64 vector translation table.
  43.  */
  44. __u8 isa_irq_to_vector_map[16] = {
  45. /* 8259 IRQ translation, first 16 entries */
  46. 0x2f, 0x20, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29,
  47. 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21
  48. };
  49. int
  50. ia64_alloc_vector (void)
  51. {
  52. static int next_vector = IA64_FIRST_DEVICE_VECTOR;
  53. if (next_vector > IA64_LAST_DEVICE_VECTOR)
  54. /* XXX could look for sharable vectors instead of panic'ing... */
  55. panic("%s: out of interrupt vectors!", __FUNCTION__);
  56. return next_vector++;
  57. }
  58. extern unsigned int do_IRQ(unsigned long irq, struct pt_regs *regs);
  59. /*
  60.  * That's where the IVT branches when we get an external
  61.  * interrupt. This branches to the correct hardware IRQ handler via
  62.  * function ptr.
  63.  */
  64. void
  65. ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
  66. {
  67. unsigned long saved_tpr;
  68. #ifdef CONFIG_SMP
  69. # define IS_RESCHEDULE(vec) (vec == IA64_IPI_RESCHEDULE)
  70. #else
  71. # define IS_RESCHEDULE(vec) (0)
  72. #endif
  73. #if IRQ_DEBUG
  74. {
  75. unsigned long bsp, sp;
  76. /*
  77.  * Note: if the interrupt happened while executing in
  78.  * the context switch routine (ia64_switch_to), we may
  79.  * get a spurious stack overflow here.  This is
  80.  * because the register and the memory stack are not
  81.  * switched atomically.
  82.  */
  83. asm ("mov %0=ar.bsp" : "=r"(bsp));
  84. asm ("mov %0=sp" : "=r"(sp));
  85. if ((sp - bsp) < 1024) {
  86. static unsigned char count;
  87. static long last_time;
  88. if (jiffies - last_time > 5*HZ)
  89. count = 0;
  90. if (++count < 5) {
  91. last_time = jiffies;
  92. printk("ia64_handle_irq: DANGER: less than "
  93.        "1KB of free stack space!!n"
  94.        "(bsp=0x%lx, sp=%lx)n", bsp, sp);
  95. }
  96. }
  97. }
  98. #endif /* IRQ_DEBUG */
  99. /*
  100.  * Always set TPR to limit maximum interrupt nesting depth to
  101.  * 16 (without this, it would be ~240, which could easily lead
  102.  * to kernel stack overflows).
  103.  */
  104. saved_tpr = ia64_get_tpr();
  105. ia64_srlz_d();
  106. while (vector != IA64_SPURIOUS_INT_VECTOR) {
  107. if (!IS_RESCHEDULE(vector)) {
  108. ia64_set_tpr(vector);
  109. ia64_srlz_d();
  110. do_IRQ(local_vector_to_irq(vector), regs);
  111. /*
  112.  * Disable interrupts and send EOI:
  113.  */
  114. local_irq_disable();
  115. ia64_set_tpr(saved_tpr);
  116. }
  117. ia64_eoi();
  118. vector = ia64_get_ivr();
  119. }
  120. /*
  121.  * This must be done *after* the ia64_eoi().  For example, the keyboard softirq
  122.  * handler needs to be able to wait for further keyboard interrupts, which can't
  123.  * come through until ia64_eoi() has been done.
  124.  */
  125. if (local_softirq_pending())
  126. do_softirq();
  127. }
  128. #ifdef CONFIG_SMP
  129. extern void handle_IPI (int irq, void *dev_id, struct pt_regs *regs);
  130. static struct irqaction ipi_irqaction = {
  131. handler: handle_IPI,
  132. flags: SA_INTERRUPT,
  133. name: "IPI"
  134. };
  135. #endif
  136. void
  137. register_percpu_irq (ia64_vector vec, struct irqaction *action)
  138. {
  139. irq_desc_t *desc;
  140. unsigned int irq;
  141. for (irq = 0; irq < NR_IRQS; ++irq)
  142. if (irq_to_vector(irq) == vec) {
  143. desc = irq_desc(irq);
  144. desc->status |= IRQ_PER_CPU;
  145. desc->handler = &irq_type_ia64_lsapic;
  146. if (action)
  147. setup_irq(irq, action);
  148. }
  149. }
  150. void __init
  151. init_IRQ (void)
  152. {
  153. register_percpu_irq(IA64_SPURIOUS_INT_VECTOR, NULL);
  154. #ifdef CONFIG_SMP
  155. register_percpu_irq(IA64_IPI_VECTOR, &ipi_irqaction);
  156. #endif
  157. #ifdef CONFIG_PERFMON
  158. perfmon_init_percpu();
  159. #endif
  160. platform_irq_init();
  161. }
  162. void
  163. ia64_send_ipi (int cpu, int vector, int delivery_mode, int redirect)
  164. {
  165. unsigned long ipi_addr;
  166. unsigned long ipi_data;
  167. unsigned long phys_cpu_id;
  168. #ifdef CONFIG_SMP
  169. phys_cpu_id = cpu_physical_id(cpu);
  170. #else
  171. phys_cpu_id = (ia64_get_lid() >> 16) & 0xffff;
  172. #endif
  173. /*
  174.  * cpu number is in 8bit ID and 8bit EID
  175.  */
  176. ipi_data = (delivery_mode << 8) | (vector & 0xff);
  177. ipi_addr = ipi_base_addr | (phys_cpu_id << 4) | ((redirect & 1)  << 3);
  178. writeq(ipi_data, ipi_addr);
  179. }