irq.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * Code to handle x86 style IRQs plus some generic interrupt stuff.
  3. *
  4. * Copyright (C) 1992 Linus Torvalds
  5. * Copyright (C) 1994, 1995, 1996, 1997, 1998 Ralf Baechle
  6. * Copyright (C) 1999 SuSE GmbH (Philipp Rumpf, prumpf@tux.org)
  7. * Copyright (C) 1999-2000 Grant Grundler
  8. * Copyright (c) 2005 Matthew Wilcox
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <linux/bitops.h>
  25. #include <linux/config.h>
  26. #include <linux/errno.h>
  27. #include <linux/init.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/kernel_stat.h>
  30. #include <linux/seq_file.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/types.h>
  33. #undef PARISC_IRQ_CR16_COUNTS
  34. extern irqreturn_t timer_interrupt(int, void *, struct pt_regs *);
  35. extern irqreturn_t ipi_interrupt(int, void *, struct pt_regs *);
  36. #define EIEM_MASK(irq) (1UL<<(CPU_IRQ_MAX - irq))
  37. /* Bits in EIEM correlate with cpu_irq_action[].
  38. ** Numbered *Big Endian*! (ie bit 0 is MSB)
  39. */
  40. static volatile unsigned long cpu_eiem = 0;
  41. static void cpu_set_eiem(void *info)
  42. {
  43. set_eiem((unsigned long) info);
  44. }
  45. static inline void cpu_disable_irq(unsigned int irq)
  46. {
  47. unsigned long eirr_bit = EIEM_MASK(irq);
  48. cpu_eiem &= ~eirr_bit;
  49. on_each_cpu(cpu_set_eiem, (void *) cpu_eiem, 1, 1);
  50. }
  51. static void cpu_enable_irq(unsigned int irq)
  52. {
  53. unsigned long eirr_bit = EIEM_MASK(irq);
  54. mtctl(eirr_bit, 23); /* clear EIRR bit before unmasking */
  55. cpu_eiem |= eirr_bit;
  56. on_each_cpu(cpu_set_eiem, (void *) cpu_eiem, 1, 1);
  57. }
  58. static unsigned int cpu_startup_irq(unsigned int irq)
  59. {
  60. cpu_enable_irq(irq);
  61. return 0;
  62. }
  63. void no_ack_irq(unsigned int irq) { }
  64. void no_end_irq(unsigned int irq) { }
  65. static struct hw_interrupt_type cpu_interrupt_type = {
  66. .typename = "CPU",
  67. .startup = cpu_startup_irq,
  68. .shutdown = cpu_disable_irq,
  69. .enable = cpu_enable_irq,
  70. .disable = cpu_disable_irq,
  71. .ack = no_ack_irq,
  72. .end = no_end_irq,
  73. // .set_affinity = cpu_set_affinity_irq,
  74. };
  75. int show_interrupts(struct seq_file *p, void *v)
  76. {
  77. int i = *(loff_t *) v, j;
  78. unsigned long flags;
  79. if (i == 0) {
  80. seq_puts(p, " ");
  81. for_each_online_cpu(j)
  82. seq_printf(p, " CPU%d", j);
  83. #ifdef PARISC_IRQ_CR16_COUNTS
  84. seq_printf(p, " [min/avg/max] (CPU cycle counts)");
  85. #endif
  86. seq_putc(p, '\n');
  87. }
  88. if (i < NR_IRQS) {
  89. struct irqaction *action;
  90. spin_lock_irqsave(&irq_desc[i].lock, flags);
  91. action = irq_desc[i].action;
  92. if (!action)
  93. goto skip;
  94. seq_printf(p, "%3d: ", i);
  95. #ifdef CONFIG_SMP
  96. for_each_online_cpu(j)
  97. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  98. #else
  99. seq_printf(p, "%10u ", kstat_irqs(i));
  100. #endif
  101. seq_printf(p, " %14s", irq_desc[i].handler->typename);
  102. #ifndef PARISC_IRQ_CR16_COUNTS
  103. seq_printf(p, " %s", action->name);
  104. while ((action = action->next))
  105. seq_printf(p, ", %s", action->name);
  106. #else
  107. for ( ;action; action = action->next) {
  108. unsigned int k, avg, min, max;
  109. min = max = action->cr16_hist[0];
  110. for (avg = k = 0; k < PARISC_CR16_HIST_SIZE; k++) {
  111. int hist = action->cr16_hist[k];
  112. if (hist) {
  113. avg += hist;
  114. } else
  115. break;
  116. if (hist > max) max = hist;
  117. if (hist < min) min = hist;
  118. }
  119. avg /= k;
  120. seq_printf(p, " %s[%d/%d/%d]", action->name,
  121. min,avg,max);
  122. }
  123. #endif
  124. seq_putc(p, '\n');
  125. skip:
  126. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  127. }
  128. return 0;
  129. }
  130. /*
  131. ** The following form a "set": Virtual IRQ, Transaction Address, Trans Data.
  132. ** Respectively, these map to IRQ region+EIRR, Processor HPA, EIRR bit.
  133. **
  134. ** To use txn_XXX() interfaces, get a Virtual IRQ first.
  135. ** Then use that to get the Transaction address and data.
  136. */
  137. int cpu_claim_irq(unsigned int irq, struct hw_interrupt_type *type, void *data)
  138. {
  139. if (irq_desc[irq].action)
  140. return -EBUSY;
  141. if (irq_desc[irq].handler != &cpu_interrupt_type)
  142. return -EBUSY;
  143. if (type) {
  144. irq_desc[irq].handler = type;
  145. irq_desc[irq].handler_data = data;
  146. cpu_interrupt_type.enable(irq);
  147. }
  148. return 0;
  149. }
  150. int txn_claim_irq(int irq)
  151. {
  152. return cpu_claim_irq(irq, NULL, NULL) ? -1 : irq;
  153. }
  154. /*
  155. * The bits_wide parameter accommodates the limitations of the HW/SW which
  156. * use these bits:
  157. * Legacy PA I/O (GSC/NIO): 5 bits (architected EIM register)
  158. * V-class (EPIC): 6 bits
  159. * N/L/A-class (iosapic): 8 bits
  160. * PCI 2.2 MSI: 16 bits
  161. * Some PCI devices: 32 bits (Symbios SCSI/ATM/HyperFabric)
  162. *
  163. * On the service provider side:
  164. * o PA 1.1 (and PA2.0 narrow mode) 5-bits (width of EIR register)
  165. * o PA 2.0 wide mode 6-bits (per processor)
  166. * o IA64 8-bits (0-256 total)
  167. *
  168. * So a Legacy PA I/O device on a PA 2.0 box can't use all the bits supported
  169. * by the processor...and the N/L-class I/O subsystem supports more bits than
  170. * PA2.0 has. The first case is the problem.
  171. */
  172. int txn_alloc_irq(unsigned int bits_wide)
  173. {
  174. int irq;
  175. /* never return irq 0 cause that's the interval timer */
  176. for (irq = CPU_IRQ_BASE + 1; irq <= CPU_IRQ_MAX; irq++) {
  177. if (cpu_claim_irq(irq, NULL, NULL) < 0)
  178. continue;
  179. if ((irq - CPU_IRQ_BASE) >= (1 << bits_wide))
  180. continue;
  181. return irq;
  182. }
  183. /* unlikely, but be prepared */
  184. return -1;
  185. }
  186. unsigned long txn_alloc_addr(unsigned int virt_irq)
  187. {
  188. static int next_cpu = -1;
  189. next_cpu++; /* assign to "next" CPU we want this bugger on */
  190. /* validate entry */
  191. while ((next_cpu < NR_CPUS) && (!cpu_data[next_cpu].txn_addr ||
  192. !cpu_online(next_cpu)))
  193. next_cpu++;
  194. if (next_cpu >= NR_CPUS)
  195. next_cpu = 0; /* nothing else, assign monarch */
  196. return cpu_data[next_cpu].txn_addr;
  197. }
  198. unsigned int txn_alloc_data(unsigned int virt_irq)
  199. {
  200. return virt_irq - CPU_IRQ_BASE;
  201. }
  202. /* ONLY called from entry.S:intr_extint() */
  203. void do_cpu_irq_mask(struct pt_regs *regs)
  204. {
  205. unsigned long eirr_val;
  206. irq_enter();
  207. /*
  208. * Only allow interrupt processing to be interrupted by the
  209. * timer tick
  210. */
  211. set_eiem(EIEM_MASK(TIMER_IRQ));
  212. /* 1) only process IRQs that are enabled/unmasked (cpu_eiem)
  213. * 2) We loop here on EIRR contents in order to avoid
  214. * nested interrupts or having to take another interrupt
  215. * when we could have just handled it right away.
  216. */
  217. for (;;) {
  218. unsigned long bit = (1UL << (BITS_PER_LONG - 1));
  219. unsigned int irq;
  220. eirr_val = mfctl(23) & cpu_eiem;
  221. if (!eirr_val)
  222. break;
  223. if (eirr_val & EIEM_MASK(TIMER_IRQ))
  224. set_eiem(0);
  225. mtctl(eirr_val, 23); /* reset bits we are going to process */
  226. /* Work our way from MSb to LSb...same order we alloc EIRs */
  227. for (irq = TIMER_IRQ; eirr_val && bit; bit>>=1, irq++) {
  228. if (!(bit & eirr_val))
  229. continue;
  230. /* clear bit in mask - can exit loop sooner */
  231. eirr_val &= ~bit;
  232. __do_IRQ(irq, regs);
  233. }
  234. }
  235. set_eiem(cpu_eiem);
  236. irq_exit();
  237. }
  238. static struct irqaction timer_action = {
  239. .handler = timer_interrupt,
  240. .name = "timer",
  241. };
  242. #ifdef CONFIG_SMP
  243. static struct irqaction ipi_action = {
  244. .handler = ipi_interrupt,
  245. .name = "IPI",
  246. };
  247. #endif
  248. static void claim_cpu_irqs(void)
  249. {
  250. int i;
  251. for (i = CPU_IRQ_BASE; i <= CPU_IRQ_MAX; i++) {
  252. irq_desc[i].handler = &cpu_interrupt_type;
  253. }
  254. irq_desc[TIMER_IRQ].action = &timer_action;
  255. irq_desc[TIMER_IRQ].status |= IRQ_PER_CPU;
  256. #ifdef CONFIG_SMP
  257. irq_desc[IPI_IRQ].action = &ipi_action;
  258. irq_desc[IPI_IRQ].status = IRQ_PER_CPU;
  259. #endif
  260. }
  261. void __init init_IRQ(void)
  262. {
  263. local_irq_disable(); /* PARANOID - should already be disabled */
  264. mtctl(~0UL, 23); /* EIRR : clear all pending external intr */
  265. claim_cpu_irqs();
  266. #ifdef CONFIG_SMP
  267. if (!cpu_eiem)
  268. cpu_eiem = EIEM_MASK(IPI_IRQ) | EIEM_MASK(TIMER_IRQ);
  269. #else
  270. cpu_eiem = EIEM_MASK(TIMER_IRQ);
  271. #endif
  272. set_eiem(cpu_eiem); /* EIEM : enable all external intr */
  273. }
  274. void hw_resend_irq(struct hw_interrupt_type *type, unsigned int irq)
  275. {
  276. /* XXX: Needs to be written. We managed without it so far, but
  277. * we really ought to write it.
  278. */
  279. }
  280. void ack_bad_irq(unsigned int irq)
  281. {
  282. printk("unexpected IRQ %d\n", irq);
  283. }