interrupt.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. #include "cbe_regs.h"
  34. struct iic {
  35. struct cbe_iic_thread_regs __iomem *regs;
  36. u8 target_id;
  37. };
  38. static DEFINE_PER_CPU(struct iic, iic);
  39. void iic_local_enable(void)
  40. {
  41. struct iic *iic = &__get_cpu_var(iic);
  42. u64 tmp;
  43. /*
  44. * There seems to be a bug that is present in DD2.x CPUs
  45. * and still only partially fixed in DD3.1.
  46. * This bug causes a value written to the priority register
  47. * not to make it there, resulting in a system hang unless we
  48. * write it again.
  49. * Masking with 0xf0 is done because the Cell BE does not
  50. * implement the lower four bits of the interrupt priority,
  51. * they always read back as zeroes, although future CPUs
  52. * might implement different bits.
  53. */
  54. do {
  55. out_be64(&iic->regs->prio, 0xff);
  56. tmp = in_be64(&iic->regs->prio);
  57. } while ((tmp & 0xf0) != 0xf0);
  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 cbe_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.class != 2)
  105. break;
  106. irq = IIC_EXT_OFFSET
  107. + spider_get_irq(node)
  108. + node * IIC_NODE_STRIDE;
  109. break;
  110. case 0x01 ... 0x04:
  111. case 0x07 ... 0x0a:
  112. /*
  113. * These units are connected to the SPEs
  114. */
  115. if (pending.class > 2)
  116. break;
  117. irq = IIC_SPE_OFFSET
  118. + pending.class * IIC_CLASS_STRIDE
  119. + node * IIC_NODE_STRIDE
  120. + unit;
  121. break;
  122. }
  123. if (irq == -1)
  124. printk(KERN_WARNING "Unexpected interrupt class %02x, "
  125. "source %02x, prio %02x, cpu %02x\n", pending.class,
  126. pending.source, pending.prio, smp_processor_id());
  127. return irq;
  128. }
  129. /* Get an IRQ number from the pending state register of the IIC */
  130. int iic_get_irq(struct pt_regs *regs)
  131. {
  132. struct iic *iic;
  133. int irq;
  134. struct cbe_iic_pending_bits pending;
  135. iic = &__get_cpu_var(iic);
  136. *(unsigned long *) &pending =
  137. in_be64((unsigned long __iomem *) &iic->regs->pending_destr);
  138. irq = -1;
  139. if (pending.flags & CBE_IIC_IRQ_VALID) {
  140. if (pending.flags & CBE_IIC_IRQ_IPI) {
  141. irq = IIC_IPI_OFFSET + (pending.prio >> 4);
  142. /*
  143. if (irq > 0x80)
  144. printk(KERN_WARNING "Unexpected IPI prio %02x"
  145. "on CPU %02x\n", pending.prio,
  146. smp_processor_id());
  147. */
  148. } else {
  149. irq = iic_external_get_irq(pending);
  150. }
  151. }
  152. return irq;
  153. }
  154. /* hardcoded part to be compatible with older firmware */
  155. static int setup_iic_hardcoded(void)
  156. {
  157. struct device_node *np;
  158. int nodeid, cpu;
  159. unsigned long regs;
  160. struct iic *iic;
  161. for_each_possible_cpu(cpu) {
  162. iic = &per_cpu(iic, cpu);
  163. nodeid = cpu/2;
  164. for (np = of_find_node_by_type(NULL, "cpu");
  165. np;
  166. np = of_find_node_by_type(np, "cpu")) {
  167. if (nodeid == *(int *)get_property(np, "node-id", NULL))
  168. break;
  169. }
  170. if (!np) {
  171. printk(KERN_WARNING "IIC: CPU %d not found\n", cpu);
  172. iic->regs = NULL;
  173. iic->target_id = 0xff;
  174. return -ENODEV;
  175. }
  176. regs = *(long *)get_property(np, "iic", NULL);
  177. /* hack until we have decided on the devtree info */
  178. regs += 0x400;
  179. if (cpu & 1)
  180. regs += 0x20;
  181. printk(KERN_INFO "IIC for CPU %d at %lx\n", cpu, regs);
  182. iic->regs = ioremap(regs, sizeof(struct cbe_iic_thread_regs));
  183. iic->target_id = (nodeid << 4) + ((cpu & 1) ? 0xf : 0xe);
  184. }
  185. return 0;
  186. }
  187. static int setup_iic(void)
  188. {
  189. struct device_node *dn;
  190. unsigned long *regs;
  191. char *compatible;
  192. unsigned *np, found = 0;
  193. struct iic *iic = NULL;
  194. for (dn = NULL; (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
  195. compatible = (char *)get_property(dn, "compatible", NULL);
  196. if (!compatible) {
  197. printk(KERN_WARNING "no compatible property found !\n");
  198. continue;
  199. }
  200. if (strstr(compatible, "IBM,CBEA-Internal-Interrupt-Controller"))
  201. regs = (unsigned long *)get_property(dn,"reg", NULL);
  202. else
  203. continue;
  204. if (!regs)
  205. printk(KERN_WARNING "IIC: no reg property\n");
  206. np = (unsigned int *)get_property(dn, "ibm,interrupt-server-ranges", NULL);
  207. if (!np) {
  208. printk(KERN_WARNING "IIC: CPU association not found\n");
  209. iic->regs = NULL;
  210. iic->target_id = 0xff;
  211. return -ENODEV;
  212. }
  213. iic = &per_cpu(iic, np[0]);
  214. iic->regs = ioremap(regs[0], sizeof(struct cbe_iic_thread_regs));
  215. iic->target_id = ((np[0] & 2) << 3) + ((np[0] & 1) ? 0xf : 0xe);
  216. printk("IIC for CPU %d at %lx mapped to %p\n", np[0], regs[0], iic->regs);
  217. iic = &per_cpu(iic, np[1]);
  218. iic->regs = ioremap(regs[2], sizeof(struct cbe_iic_thread_regs));
  219. iic->target_id = ((np[1] & 2) << 3) + ((np[1] & 1) ? 0xf : 0xe);
  220. printk("IIC for CPU %d at %lx mapped to %p\n", np[1], regs[2], iic->regs);
  221. found++;
  222. }
  223. if (found)
  224. return 0;
  225. else
  226. return -ENODEV;
  227. }
  228. #ifdef CONFIG_SMP
  229. /* Use the highest interrupt priorities for IPI */
  230. static inline int iic_ipi_to_irq(int ipi)
  231. {
  232. return IIC_IPI_OFFSET + IIC_NUM_IPIS - 1 - ipi;
  233. }
  234. static inline int iic_irq_to_ipi(int irq)
  235. {
  236. return IIC_NUM_IPIS - 1 - (irq - IIC_IPI_OFFSET);
  237. }
  238. void iic_setup_cpu(void)
  239. {
  240. out_be64(&__get_cpu_var(iic).regs->prio, 0xff);
  241. }
  242. void iic_cause_IPI(int cpu, int mesg)
  243. {
  244. out_be64(&per_cpu(iic, cpu).regs->generate, (IIC_NUM_IPIS - 1 - mesg) << 4);
  245. }
  246. u8 iic_get_target_id(int cpu)
  247. {
  248. return per_cpu(iic, cpu).target_id;
  249. }
  250. EXPORT_SYMBOL_GPL(iic_get_target_id);
  251. static irqreturn_t iic_ipi_action(int irq, void *dev_id, struct pt_regs *regs)
  252. {
  253. smp_message_recv(iic_irq_to_ipi(irq), regs);
  254. return IRQ_HANDLED;
  255. }
  256. static void iic_request_ipi(int ipi, const char *name)
  257. {
  258. int irq;
  259. irq = iic_ipi_to_irq(ipi);
  260. /* IPIs are marked SA_INTERRUPT as they must run with irqs
  261. * disabled */
  262. get_irq_desc(irq)->chip = &iic_pic;
  263. get_irq_desc(irq)->status |= IRQ_PER_CPU;
  264. request_irq(irq, iic_ipi_action, SA_INTERRUPT, name, NULL);
  265. }
  266. void iic_request_IPIs(void)
  267. {
  268. iic_request_ipi(PPC_MSG_CALL_FUNCTION, "IPI-call");
  269. iic_request_ipi(PPC_MSG_RESCHEDULE, "IPI-resched");
  270. #ifdef CONFIG_DEBUGGER
  271. iic_request_ipi(PPC_MSG_DEBUGGER_BREAK, "IPI-debug");
  272. #endif /* CONFIG_DEBUGGER */
  273. }
  274. #endif /* CONFIG_SMP */
  275. static void iic_setup_spe_handlers(void)
  276. {
  277. int be, isrc;
  278. /* Assume two threads per BE are present */
  279. for (be=0; be < num_present_cpus() / 2; be++) {
  280. for (isrc = 0; isrc < IIC_CLASS_STRIDE * 3; isrc++) {
  281. int irq = IIC_NODE_STRIDE * be + IIC_SPE_OFFSET + isrc;
  282. get_irq_desc(irq)->chip = &iic_pic;
  283. }
  284. }
  285. }
  286. void iic_init_IRQ(void)
  287. {
  288. int cpu, irq_offset;
  289. struct iic *iic;
  290. if (setup_iic() < 0)
  291. setup_iic_hardcoded();
  292. irq_offset = 0;
  293. for_each_possible_cpu(cpu) {
  294. iic = &per_cpu(iic, cpu);
  295. if (iic->regs)
  296. out_be64(&iic->regs->prio, 0xff);
  297. }
  298. iic_setup_spe_handlers();
  299. }