interrupt.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Cell Internal Interrupt Controller
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  5. *
  6. * Author: Arnd Bergmann <arndb@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/config.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/module.h>
  26. #include <linux/percpu.h>
  27. #include <linux/types.h>
  28. #include <asm/io.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/prom.h>
  31. #include <asm/ptrace.h>
  32. #include "interrupt.h"
  33. struct iic_pending_bits {
  34. u32 data;
  35. u8 flags;
  36. u8 class;
  37. u8 source;
  38. u8 prio;
  39. };
  40. enum iic_pending_flags {
  41. IIC_VALID = 0x80,
  42. IIC_IPI = 0x40,
  43. };
  44. struct iic_regs {
  45. struct iic_pending_bits pending;
  46. struct iic_pending_bits pending_destr;
  47. u64 generate;
  48. u64 prio;
  49. };
  50. struct iic {
  51. struct iic_regs __iomem *regs;
  52. u8 target_id;
  53. };
  54. static DEFINE_PER_CPU(struct iic, iic);
  55. void iic_local_enable(void)
  56. {
  57. out_be64(&__get_cpu_var(iic).regs->prio, 0xff);
  58. }
  59. void iic_local_disable(void)
  60. {
  61. out_be64(&__get_cpu_var(iic).regs->prio, 0x0);
  62. }
  63. static unsigned int iic_startup(unsigned int irq)
  64. {
  65. return 0;
  66. }
  67. static void iic_enable(unsigned int irq)
  68. {
  69. iic_local_enable();
  70. }
  71. static void iic_disable(unsigned int irq)
  72. {
  73. }
  74. static void iic_end(unsigned int irq)
  75. {
  76. iic_local_enable();
  77. }
  78. static struct hw_interrupt_type iic_pic = {
  79. .typename = " CELL-IIC ",
  80. .startup = iic_startup,
  81. .enable = iic_enable,
  82. .disable = iic_disable,
  83. .end = iic_end,
  84. };
  85. static int iic_external_get_irq(struct iic_pending_bits pending)
  86. {
  87. int irq;
  88. unsigned char node, unit;
  89. node = pending.source >> 4;
  90. unit = pending.source & 0xf;
  91. irq = -1;
  92. /*
  93. * This mapping is specific to the Cell Broadband
  94. * Engine. We might need to get the numbers
  95. * from the device tree to support future CPUs.
  96. */
  97. switch (unit) {
  98. case 0x00:
  99. case 0x0b:
  100. /*
  101. * One of these units can be connected
  102. * to an external interrupt controller.
  103. */
  104. if (pending.prio > 0x3f ||
  105. pending.class != 2)
  106. break;
  107. irq = IIC_EXT_OFFSET
  108. + spider_get_irq(pending.prio + node * IIC_NODE_STRIDE)
  109. + node * IIC_NODE_STRIDE;
  110. break;
  111. case 0x01 ... 0x04:
  112. case 0x07 ... 0x0a:
  113. /*
  114. * These units are connected to the SPEs
  115. */
  116. if (pending.class > 2)
  117. break;
  118. irq = IIC_SPE_OFFSET
  119. + pending.class * IIC_CLASS_STRIDE
  120. + node * IIC_NODE_STRIDE
  121. + unit;
  122. break;
  123. }
  124. if (irq == -1)
  125. printk(KERN_WARNING "Unexpected interrupt class %02x, "
  126. "source %02x, prio %02x, cpu %02x\n", pending.class,
  127. pending.source, pending.prio, smp_processor_id());
  128. return irq;
  129. }
  130. /* Get an IRQ number from the pending state register of the IIC */
  131. int iic_get_irq(struct pt_regs *regs)
  132. {
  133. struct iic *iic;
  134. int irq;
  135. struct iic_pending_bits pending;
  136. iic = &__get_cpu_var(iic);
  137. *(unsigned long *) &pending =
  138. in_be64((unsigned long __iomem *) &iic->regs->pending_destr);
  139. irq = -1;
  140. if (pending.flags & IIC_VALID) {
  141. if (pending.flags & IIC_IPI) {
  142. irq = IIC_IPI_OFFSET + (pending.prio >> 4);
  143. /*
  144. if (irq > 0x80)
  145. printk(KERN_WARNING "Unexpected IPI prio %02x"
  146. "on CPU %02x\n", pending.prio,
  147. smp_processor_id());
  148. */
  149. } else {
  150. irq = iic_external_get_irq(pending);
  151. }
  152. }
  153. return irq;
  154. }
  155. static int setup_iic(int cpu, struct iic *iic)
  156. {
  157. struct device_node *np;
  158. int nodeid = cpu / 2;
  159. unsigned long regs;
  160. for (np = of_find_node_by_type(NULL, "cpu");
  161. np;
  162. np = of_find_node_by_type(np, "cpu")) {
  163. if (nodeid == *(int *)get_property(np, "node-id", NULL))
  164. break;
  165. }
  166. if (!np) {
  167. printk(KERN_WARNING "IIC: CPU %d not found\n", cpu);
  168. iic->regs = NULL;
  169. iic->target_id = 0xff;
  170. return -ENODEV;
  171. }
  172. regs = *(long *)get_property(np, "iic", NULL);
  173. /* hack until we have decided on the devtree info */
  174. regs += 0x400;
  175. if (cpu & 1)
  176. regs += 0x20;
  177. printk(KERN_DEBUG "IIC for CPU %d at %lx\n", cpu, regs);
  178. iic->regs = __ioremap(regs, sizeof(struct iic_regs),
  179. _PAGE_NO_CACHE);
  180. iic->target_id = (nodeid << 4) + ((cpu & 1) ? 0xf : 0xe);
  181. return 0;
  182. }
  183. #ifdef CONFIG_SMP
  184. /* Use the highest interrupt priorities for IPI */
  185. static inline int iic_ipi_to_irq(int ipi)
  186. {
  187. return IIC_IPI_OFFSET + IIC_NUM_IPIS - 1 - ipi;
  188. }
  189. static inline int iic_irq_to_ipi(int irq)
  190. {
  191. return IIC_NUM_IPIS - 1 - (irq - IIC_IPI_OFFSET);
  192. }
  193. void iic_setup_cpu(void)
  194. {
  195. out_be64(&__get_cpu_var(iic).regs->prio, 0xff);
  196. }
  197. void iic_cause_IPI(int cpu, int mesg)
  198. {
  199. out_be64(&per_cpu(iic, cpu).regs->generate, (IIC_NUM_IPIS - 1 - mesg) << 4);
  200. }
  201. u8 iic_get_target_id(int cpu)
  202. {
  203. return per_cpu(iic, cpu).target_id;
  204. }
  205. EXPORT_SYMBOL_GPL(iic_get_target_id);
  206. static irqreturn_t iic_ipi_action(int irq, void *dev_id, struct pt_regs *regs)
  207. {
  208. smp_message_recv(iic_irq_to_ipi(irq), regs);
  209. return IRQ_HANDLED;
  210. }
  211. static void iic_request_ipi(int ipi, const char *name)
  212. {
  213. int irq;
  214. irq = iic_ipi_to_irq(ipi);
  215. /* IPIs are marked SA_INTERRUPT as they must run with irqs
  216. * disabled */
  217. get_irq_desc(irq)->handler = &iic_pic;
  218. get_irq_desc(irq)->status |= IRQ_PER_CPU;
  219. request_irq(irq, iic_ipi_action, SA_INTERRUPT, name, NULL);
  220. }
  221. void iic_request_IPIs(void)
  222. {
  223. iic_request_ipi(PPC_MSG_CALL_FUNCTION, "IPI-call");
  224. iic_request_ipi(PPC_MSG_RESCHEDULE, "IPI-resched");
  225. #ifdef CONFIG_DEBUGGER
  226. iic_request_ipi(PPC_MSG_DEBUGGER_BREAK, "IPI-debug");
  227. #endif /* CONFIG_DEBUGGER */
  228. }
  229. #endif /* CONFIG_SMP */
  230. static void iic_setup_spe_handlers(void)
  231. {
  232. int be, isrc;
  233. /* Assume two threads per BE are present */
  234. for (be=0; be < num_present_cpus() / 2; be++) {
  235. for (isrc = 0; isrc < IIC_CLASS_STRIDE * 3; isrc++) {
  236. int irq = IIC_NODE_STRIDE * be + IIC_SPE_OFFSET + isrc;
  237. get_irq_desc(irq)->handler = &iic_pic;
  238. }
  239. }
  240. }
  241. void iic_init_IRQ(void)
  242. {
  243. int cpu, irq_offset;
  244. struct iic *iic;
  245. irq_offset = 0;
  246. for_each_cpu(cpu) {
  247. iic = &per_cpu(iic, cpu);
  248. setup_iic(cpu, iic);
  249. if (iic->regs)
  250. out_be64(&iic->regs->prio, 0xff);
  251. }
  252. iic_setup_spe_handlers();
  253. }