interrupt.c 8.1 KB

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