interrupt.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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.prio > 0x3f ||
  105. pending.class != 2)
  106. break;
  107. irq = IIC_EXT_OFFSET
  108. + spider_get_irq(node)
  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 cbe_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 & CBE_IIC_IRQ_VALID) {
  141. if (pending.flags & CBE_IIC_IRQ_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. /* hardcoded part to be compatible with older firmware */
  156. static int setup_iic_hardcoded(void)
  157. {
  158. struct device_node *np;
  159. int nodeid, cpu;
  160. unsigned long regs;
  161. struct iic *iic;
  162. for_each_cpu(cpu) {
  163. iic = &per_cpu(iic, cpu);
  164. nodeid = cpu/2;
  165. for (np = of_find_node_by_type(NULL, "cpu");
  166. np;
  167. np = of_find_node_by_type(np, "cpu")) {
  168. if (nodeid == *(int *)get_property(np, "node-id", NULL))
  169. break;
  170. }
  171. if (!np) {
  172. printk(KERN_WARNING "IIC: CPU %d not found\n", cpu);
  173. iic->regs = NULL;
  174. iic->target_id = 0xff;
  175. return -ENODEV;
  176. }
  177. regs = *(long *)get_property(np, "iic", NULL);
  178. /* hack until we have decided on the devtree info */
  179. regs += 0x400;
  180. if (cpu & 1)
  181. regs += 0x20;
  182. printk(KERN_INFO "IIC for CPU %d at %lx\n", cpu, regs);
  183. iic->regs = ioremap(regs, sizeof(struct cbe_iic_thread_regs));
  184. iic->target_id = (nodeid << 4) + ((cpu & 1) ? 0xf : 0xe);
  185. }
  186. return 0;
  187. }
  188. static int setup_iic(void)
  189. {
  190. struct device_node *dn;
  191. unsigned long *regs;
  192. char *compatible;
  193. unsigned *np, found = 0;
  194. struct iic *iic = NULL;
  195. for (dn = NULL; (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
  196. compatible = (char *)get_property(dn, "compatible", NULL);
  197. if (!compatible) {
  198. printk(KERN_WARNING "no compatible property found !\n");
  199. continue;
  200. }
  201. if (strstr(compatible, "IBM,CBEA-Internal-Interrupt-Controller"))
  202. regs = (unsigned long *)get_property(dn,"reg", NULL);
  203. else
  204. continue;
  205. if (!regs)
  206. printk(KERN_WARNING "IIC: no reg property\n");
  207. np = (unsigned int *)get_property(dn, "ibm,interrupt-server-ranges", NULL);
  208. if (!np) {
  209. printk(KERN_WARNING "IIC: CPU association not found\n");
  210. iic->regs = NULL;
  211. iic->target_id = 0xff;
  212. return -ENODEV;
  213. }
  214. iic = &per_cpu(iic, np[0]);
  215. iic->regs = ioremap(regs[0], sizeof(struct cbe_iic_thread_regs));
  216. iic->target_id = ((np[0] & 2) << 3) + ((np[0] & 1) ? 0xf : 0xe);
  217. printk("IIC for CPU %d at %lx mapped to %p\n", np[0], regs[0], iic->regs);
  218. iic = &per_cpu(iic, np[1]);
  219. iic->regs = ioremap(regs[2], sizeof(struct cbe_iic_thread_regs));
  220. iic->target_id = ((np[1] & 2) << 3) + ((np[1] & 1) ? 0xf : 0xe);
  221. printk("IIC for CPU %d at %lx mapped to %p\n", np[1], regs[2], iic->regs);
  222. found++;
  223. }
  224. if (found)
  225. return 0;
  226. else
  227. return -ENODEV;
  228. }
  229. #ifdef CONFIG_SMP
  230. /* Use the highest interrupt priorities for IPI */
  231. static inline int iic_ipi_to_irq(int ipi)
  232. {
  233. return IIC_IPI_OFFSET + IIC_NUM_IPIS - 1 - ipi;
  234. }
  235. static inline int iic_irq_to_ipi(int irq)
  236. {
  237. return IIC_NUM_IPIS - 1 - (irq - IIC_IPI_OFFSET);
  238. }
  239. void iic_setup_cpu(void)
  240. {
  241. out_be64(&__get_cpu_var(iic).regs->prio, 0xff);
  242. }
  243. void iic_cause_IPI(int cpu, int mesg)
  244. {
  245. out_be64(&per_cpu(iic, cpu).regs->generate, (IIC_NUM_IPIS - 1 - mesg) << 4);
  246. }
  247. u8 iic_get_target_id(int cpu)
  248. {
  249. return per_cpu(iic, cpu).target_id;
  250. }
  251. EXPORT_SYMBOL_GPL(iic_get_target_id);
  252. static irqreturn_t iic_ipi_action(int irq, void *dev_id, struct pt_regs *regs)
  253. {
  254. smp_message_recv(iic_irq_to_ipi(irq), regs);
  255. return IRQ_HANDLED;
  256. }
  257. static void iic_request_ipi(int ipi, const char *name)
  258. {
  259. int irq;
  260. irq = iic_ipi_to_irq(ipi);
  261. /* IPIs are marked SA_INTERRUPT as they must run with irqs
  262. * disabled */
  263. get_irq_desc(irq)->handler = &iic_pic;
  264. get_irq_desc(irq)->status |= IRQ_PER_CPU;
  265. request_irq(irq, iic_ipi_action, SA_INTERRUPT, name, NULL);
  266. }
  267. void iic_request_IPIs(void)
  268. {
  269. iic_request_ipi(PPC_MSG_CALL_FUNCTION, "IPI-call");
  270. iic_request_ipi(PPC_MSG_RESCHEDULE, "IPI-resched");
  271. #ifdef CONFIG_DEBUGGER
  272. iic_request_ipi(PPC_MSG_DEBUGGER_BREAK, "IPI-debug");
  273. #endif /* CONFIG_DEBUGGER */
  274. }
  275. #endif /* CONFIG_SMP */
  276. static void iic_setup_spe_handlers(void)
  277. {
  278. int be, isrc;
  279. /* Assume two threads per BE are present */
  280. for (be=0; be < num_present_cpus() / 2; be++) {
  281. for (isrc = 0; isrc < IIC_CLASS_STRIDE * 3; isrc++) {
  282. int irq = IIC_NODE_STRIDE * be + IIC_SPE_OFFSET + isrc;
  283. get_irq_desc(irq)->handler = &iic_pic;
  284. }
  285. }
  286. }
  287. void iic_init_IRQ(void)
  288. {
  289. int cpu, irq_offset;
  290. struct iic *iic;
  291. if (setup_iic() < 0)
  292. setup_iic_hardcoded();
  293. irq_offset = 0;
  294. for_each_possible_cpu(cpu) {
  295. iic = &per_cpu(iic, cpu);
  296. if (iic->regs)
  297. out_be64(&iic->regs->prio, 0xff);
  298. }
  299. iic_setup_spe_handlers();
  300. }