interrupts.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. *
  7. * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 22-Oct-00
  8. */
  9. #include <common.h>
  10. #include <command.h>
  11. #include <mpc8260.h>
  12. #include <mpc8260_irq.h>
  13. #include <asm/processor.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. /****************************************************************************/
  16. struct irq_action {
  17. interrupt_handler_t *handler;
  18. void *arg;
  19. ulong count;
  20. };
  21. static struct irq_action irq_handlers[NR_IRQS];
  22. static ulong ppc_cached_irq_mask[NR_MASK_WORDS];
  23. /****************************************************************************/
  24. /* this section was ripped out of arch/powerpc/kernel/ppc8260_pic.c in the */
  25. /* Linux/PPC 2.4.x source. There was no copyright notice in that file. */
  26. /* The 8260 internal interrupt controller. It is usually
  27. * the only interrupt controller.
  28. * There are two 32-bit registers (high/low) for up to 64
  29. * possible interrupts.
  30. *
  31. * Now, the fun starts.....Interrupt Numbers DO NOT MAP
  32. * in a simple arithmetic fashion to mask or pending registers.
  33. * That is, interrupt 4 does not map to bit position 4.
  34. * We create two tables, indexed by vector number, to indicate
  35. * which register to use and which bit in the register to use.
  36. */
  37. static u_char irq_to_siureg[] = {
  38. 1, 1, 1, 1, 1, 1, 1, 1,
  39. 1, 1, 1, 1, 1, 1, 1, 1,
  40. 0, 0, 0, 0, 0, 0, 0, 0,
  41. 0, 0, 0, 0, 0, 0, 0, 0,
  42. 1, 1, 1, 1, 1, 1, 1, 1,
  43. 1, 1, 1, 1, 1, 1, 1, 1,
  44. 0, 0, 0, 0, 0, 0, 0, 0,
  45. 0, 0, 0, 0, 0, 0, 0, 0
  46. };
  47. static u_char irq_to_siubit[] = {
  48. 31, 16, 17, 18, 19, 20, 21, 22,
  49. 23, 24, 25, 26, 27, 28, 29, 30,
  50. 29, 30, 16, 17, 18, 19, 20, 21,
  51. 22, 23, 24, 25, 26, 27, 28, 31,
  52. 0, 1, 2, 3, 4, 5, 6, 7,
  53. 8, 9, 10, 11, 12, 13, 14, 15,
  54. 15, 14, 13, 12, 11, 10, 9, 8,
  55. 7, 6, 5, 4, 3, 2, 1, 0
  56. };
  57. static void m8260_mask_irq (unsigned int irq_nr)
  58. {
  59. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  60. int bit, word;
  61. volatile uint *simr;
  62. bit = irq_to_siubit[irq_nr];
  63. word = irq_to_siureg[irq_nr];
  64. simr = &(immr->im_intctl.ic_simrh);
  65. ppc_cached_irq_mask[word] &= ~(1 << (31 - bit));
  66. simr[word] = ppc_cached_irq_mask[word];
  67. }
  68. static void m8260_unmask_irq (unsigned int irq_nr)
  69. {
  70. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  71. int bit, word;
  72. volatile uint *simr;
  73. bit = irq_to_siubit[irq_nr];
  74. word = irq_to_siureg[irq_nr];
  75. simr = &(immr->im_intctl.ic_simrh);
  76. ppc_cached_irq_mask[word] |= (1 << (31 - bit));
  77. simr[word] = ppc_cached_irq_mask[word];
  78. }
  79. static void m8260_mask_and_ack (unsigned int irq_nr)
  80. {
  81. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  82. int bit, word;
  83. volatile uint *simr, *sipnr;
  84. bit = irq_to_siubit[irq_nr];
  85. word = irq_to_siureg[irq_nr];
  86. simr = &(immr->im_intctl.ic_simrh);
  87. sipnr = &(immr->im_intctl.ic_sipnrh);
  88. ppc_cached_irq_mask[word] &= ~(1 << (31 - bit));
  89. simr[word] = ppc_cached_irq_mask[word];
  90. sipnr[word] = 1 << (31 - bit);
  91. }
  92. static int m8260_get_irq (struct pt_regs *regs)
  93. {
  94. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  95. int irq;
  96. unsigned long bits;
  97. /* For MPC8260, read the SIVEC register and shift the bits down
  98. * to get the irq number. */
  99. bits = immr->im_intctl.ic_sivec;
  100. irq = bits >> 26;
  101. return irq;
  102. }
  103. /* end of code ripped out of arch/powerpc/kernel/ppc8260_pic.c */
  104. /****************************************************************************/
  105. int interrupt_init_cpu (unsigned *decrementer_count)
  106. {
  107. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  108. *decrementer_count = (gd->bus_clk / 4) / CONFIG_SYS_HZ;
  109. /* Initialize the default interrupt mapping priorities */
  110. immr->im_intctl.ic_sicr = 0;
  111. immr->im_intctl.ic_siprr = 0x05309770;
  112. immr->im_intctl.ic_scprrh = 0x05309770;
  113. immr->im_intctl.ic_scprrl = 0x05309770;
  114. /* disable all interrupts and clear all pending bits */
  115. immr->im_intctl.ic_simrh = ppc_cached_irq_mask[0] = 0;
  116. immr->im_intctl.ic_simrl = ppc_cached_irq_mask[1] = 0;
  117. immr->im_intctl.ic_sipnrh = 0xffffffff;
  118. immr->im_intctl.ic_sipnrl = 0xffffffff;
  119. #ifdef CONFIG_HYMOD
  120. /*
  121. * ensure all external interrupt sources default to trigger on
  122. * high-to-low transition (i.e. edge triggered active low)
  123. */
  124. immr->im_intctl.ic_siexr = -1;
  125. #endif
  126. return (0);
  127. }
  128. /****************************************************************************/
  129. /*
  130. * Handle external interrupts
  131. */
  132. void external_interrupt (struct pt_regs *regs)
  133. {
  134. int irq, unmask = 1;
  135. irq = m8260_get_irq (regs);
  136. m8260_mask_and_ack (irq);
  137. enable_interrupts ();
  138. if (irq_handlers[irq].handler != NULL)
  139. (*irq_handlers[irq].handler) (irq_handlers[irq].arg);
  140. else {
  141. printf ("\nBogus External Interrupt IRQ %d\n", irq);
  142. /*
  143. * turn off the bogus interrupt, otherwise it
  144. * might repeat forever
  145. */
  146. unmask = 0;
  147. }
  148. if (unmask)
  149. m8260_unmask_irq (irq);
  150. }
  151. /****************************************************************************/
  152. /*
  153. * Install and free an interrupt handler.
  154. */
  155. void
  156. irq_install_handler (int irq, interrupt_handler_t * handler, void *arg)
  157. {
  158. if (irq < 0 || irq >= NR_IRQS) {
  159. printf ("irq_install_handler: bad irq number %d\n", irq);
  160. return;
  161. }
  162. if (irq_handlers[irq].handler != NULL)
  163. printf ("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  164. (ulong) handler, (ulong) irq_handlers[irq].handler);
  165. irq_handlers[irq].handler = handler;
  166. irq_handlers[irq].arg = arg;
  167. m8260_unmask_irq (irq);
  168. }
  169. void irq_free_handler (int irq)
  170. {
  171. if (irq < 0 || irq >= NR_IRQS) {
  172. printf ("irq_free_handler: bad irq number %d\n", irq);
  173. return;
  174. }
  175. m8260_mask_irq (irq);
  176. irq_handlers[irq].handler = NULL;
  177. irq_handlers[irq].arg = NULL;
  178. }
  179. /****************************************************************************/
  180. void timer_interrupt_cpu (struct pt_regs *regs)
  181. {
  182. /* nothing to do here */
  183. return;
  184. }
  185. /****************************************************************************/
  186. #if defined(CONFIG_CMD_IRQ)
  187. /* ripped this out of ppc4xx/interrupts.c */
  188. /*******************************************************************************
  189. *
  190. * irqinfo - print information about PCI devices
  191. *
  192. */
  193. void
  194. do_irqinfo (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[])
  195. {
  196. int irq, re_enable;
  197. re_enable = disable_interrupts ();
  198. puts ("\nInterrupt-Information:\n"
  199. "Nr Routine Arg Count\n");
  200. for (irq = 0; irq < 32; irq++)
  201. if (irq_handlers[irq].handler != NULL)
  202. printf ("%02d %08lx %08lx %ld\n", irq,
  203. (ulong) irq_handlers[irq].handler,
  204. (ulong) irq_handlers[irq].arg,
  205. irq_handlers[irq].count);
  206. if (re_enable)
  207. enable_interrupts ();
  208. }
  209. #endif