irq.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * linux/arch/ia64/kernel/irq.c
  3. *
  4. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  5. *
  6. * This file contains the code used by various IRQ handling routines:
  7. * asking for different IRQ's should be done through these routines
  8. * instead of just grabbing them. Thus setups with different IRQ numbers
  9. * shouldn't result in any weird surprises, and installing new handlers
  10. * should be easier.
  11. *
  12. * Copyright (C) Ashok Raj<ashok.raj@intel.com>, Intel Corporation 2004
  13. *
  14. * 4/14/2004: Added code to handle cpu migration and do safe irq
  15. * migration without lossing interrupts for iosapic
  16. * architecture.
  17. */
  18. #include <asm/delay.h>
  19. #include <asm/uaccess.h>
  20. #include <linux/module.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/kernel_stat.h>
  24. /*
  25. * 'what should we do if we get a hw irq event on an illegal vector'.
  26. * each architecture has to answer this themselves.
  27. */
  28. void ack_bad_irq(unsigned int irq)
  29. {
  30. printk(KERN_ERR "Unexpected irq vector 0x%x on CPU %u!\n", irq, smp_processor_id());
  31. }
  32. #ifdef CONFIG_IA64_GENERIC
  33. unsigned int __ia64_local_vector_to_irq (ia64_vector vec)
  34. {
  35. return (unsigned int) vec;
  36. }
  37. #endif
  38. /*
  39. * Interrupt statistics:
  40. */
  41. atomic_t irq_err_count;
  42. /*
  43. * /proc/interrupts printing:
  44. */
  45. int show_interrupts(struct seq_file *p, void *v)
  46. {
  47. int i = *(loff_t *) v, j;
  48. struct irqaction * action;
  49. unsigned long flags;
  50. if (i == 0) {
  51. seq_printf(p, " ");
  52. for (j=0; j<NR_CPUS; j++)
  53. if (cpu_online(j))
  54. seq_printf(p, "CPU%d ",j);
  55. seq_putc(p, '\n');
  56. }
  57. if (i < NR_IRQS) {
  58. spin_lock_irqsave(&irq_desc[i].lock, flags);
  59. action = irq_desc[i].action;
  60. if (!action)
  61. goto skip;
  62. seq_printf(p, "%3d: ",i);
  63. #ifndef CONFIG_SMP
  64. seq_printf(p, "%10u ", kstat_irqs(i));
  65. #else
  66. for (j = 0; j < NR_CPUS; j++)
  67. if (cpu_online(j))
  68. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  69. #endif
  70. seq_printf(p, " %14s", irq_desc[i].handler->typename);
  71. seq_printf(p, " %s", action->name);
  72. for (action=action->next; action; action = action->next)
  73. seq_printf(p, ", %s", action->name);
  74. seq_putc(p, '\n');
  75. skip:
  76. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  77. } else if (i == NR_IRQS)
  78. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  79. return 0;
  80. }
  81. #ifdef CONFIG_SMP
  82. static char irq_redir [NR_IRQS]; // = { [0 ... NR_IRQS-1] = 1 };
  83. void set_irq_affinity_info (unsigned int irq, int hwid, int redir)
  84. {
  85. cpumask_t mask = CPU_MASK_NONE;
  86. cpu_set(cpu_logical_id(hwid), mask);
  87. if (irq < NR_IRQS) {
  88. irq_affinity[irq] = mask;
  89. set_irq_info(irq, mask);
  90. irq_redir[irq] = (char) (redir & 0xff);
  91. }
  92. }
  93. #endif /* CONFIG_SMP */
  94. #ifdef CONFIG_HOTPLUG_CPU
  95. unsigned int vectors_in_migration[NR_IRQS];
  96. /*
  97. * Since cpu_online_map is already updated, we just need to check for
  98. * affinity that has zeros
  99. */
  100. static void migrate_irqs(void)
  101. {
  102. cpumask_t mask;
  103. irq_desc_t *desc;
  104. int irq, new_cpu;
  105. for (irq=0; irq < NR_IRQS; irq++) {
  106. desc = irq_descp(irq);
  107. /*
  108. * No handling for now.
  109. * TBD: Implement a disable function so we can now
  110. * tell CPU not to respond to these local intr sources.
  111. * such as ITV,CPEI,MCA etc.
  112. */
  113. if (desc->status == IRQ_PER_CPU)
  114. continue;
  115. cpus_and(mask, irq_affinity[irq], cpu_online_map);
  116. if (any_online_cpu(mask) == NR_CPUS) {
  117. /*
  118. * Save it for phase 2 processing
  119. */
  120. vectors_in_migration[irq] = irq;
  121. new_cpu = any_online_cpu(cpu_online_map);
  122. mask = cpumask_of_cpu(new_cpu);
  123. /*
  124. * Al three are essential, currently WARN_ON.. maybe panic?
  125. */
  126. if (desc->handler && desc->handler->disable &&
  127. desc->handler->enable && desc->handler->set_affinity) {
  128. desc->handler->disable(irq);
  129. desc->handler->set_affinity(irq, mask);
  130. desc->handler->enable(irq);
  131. } else {
  132. WARN_ON((!(desc->handler) || !(desc->handler->disable) ||
  133. !(desc->handler->enable) ||
  134. !(desc->handler->set_affinity)));
  135. }
  136. }
  137. }
  138. }
  139. void fixup_irqs(void)
  140. {
  141. unsigned int irq;
  142. extern void ia64_process_pending_intr(void);
  143. ia64_set_itv(1<<16);
  144. /*
  145. * Phase 1: Locate irq's bound to this cpu and
  146. * relocate them for cpu removal.
  147. */
  148. migrate_irqs();
  149. /*
  150. * Phase 2: Perform interrupt processing for all entries reported in
  151. * local APIC.
  152. */
  153. ia64_process_pending_intr();
  154. /*
  155. * Phase 3: Now handle any interrupts not captured in local APIC.
  156. * This is to account for cases that device interrupted during the time the
  157. * rte was being disabled and re-programmed.
  158. */
  159. for (irq=0; irq < NR_IRQS; irq++) {
  160. if (vectors_in_migration[irq]) {
  161. vectors_in_migration[irq]=0;
  162. __do_IRQ(irq, NULL);
  163. }
  164. }
  165. /*
  166. * Now let processor die. We do irq disable and max_xtp() to
  167. * ensure there is no more interrupts routed to this processor.
  168. * But the local timer interrupt can have 1 pending which we
  169. * take care in timer_interrupt().
  170. */
  171. max_xtp();
  172. local_irq_disable();
  173. }
  174. #endif