interrupts.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. return 0;
  120. }
  121. /****************************************************************************/
  122. /*
  123. * Handle external interrupts
  124. */
  125. void external_interrupt (struct pt_regs *regs)
  126. {
  127. int irq, unmask = 1;
  128. irq = m8260_get_irq (regs);
  129. m8260_mask_and_ack (irq);
  130. enable_interrupts ();
  131. if (irq_handlers[irq].handler != NULL)
  132. (*irq_handlers[irq].handler) (irq_handlers[irq].arg);
  133. else {
  134. printf ("\nBogus External Interrupt IRQ %d\n", irq);
  135. /*
  136. * turn off the bogus interrupt, otherwise it
  137. * might repeat forever
  138. */
  139. unmask = 0;
  140. }
  141. if (unmask)
  142. m8260_unmask_irq (irq);
  143. }
  144. /****************************************************************************/
  145. /*
  146. * Install and free an interrupt handler.
  147. */
  148. void
  149. irq_install_handler (int irq, interrupt_handler_t * handler, void *arg)
  150. {
  151. if (irq < 0 || irq >= NR_IRQS) {
  152. printf ("irq_install_handler: bad irq number %d\n", irq);
  153. return;
  154. }
  155. if (irq_handlers[irq].handler != NULL)
  156. printf ("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  157. (ulong) handler, (ulong) irq_handlers[irq].handler);
  158. irq_handlers[irq].handler = handler;
  159. irq_handlers[irq].arg = arg;
  160. m8260_unmask_irq (irq);
  161. }
  162. void irq_free_handler (int irq)
  163. {
  164. if (irq < 0 || irq >= NR_IRQS) {
  165. printf ("irq_free_handler: bad irq number %d\n", irq);
  166. return;
  167. }
  168. m8260_mask_irq (irq);
  169. irq_handlers[irq].handler = NULL;
  170. irq_handlers[irq].arg = NULL;
  171. }
  172. /****************************************************************************/
  173. void timer_interrupt_cpu (struct pt_regs *regs)
  174. {
  175. /* nothing to do here */
  176. return;
  177. }
  178. /****************************************************************************/
  179. #if defined(CONFIG_CMD_IRQ)
  180. /* ripped this out of ppc4xx/interrupts.c */
  181. /*******************************************************************************
  182. *
  183. * irqinfo - print information about PCI devices
  184. *
  185. */
  186. void
  187. do_irqinfo (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[])
  188. {
  189. int irq, re_enable;
  190. re_enable = disable_interrupts ();
  191. puts ("\nInterrupt-Information:\n"
  192. "Nr Routine Arg Count\n");
  193. for (irq = 0; irq < 32; irq++)
  194. if (irq_handlers[irq].handler != NULL)
  195. printf ("%02d %08lx %08lx %ld\n", irq,
  196. (ulong) irq_handlers[irq].handler,
  197. (ulong) irq_handlers[irq].arg,
  198. irq_handlers[irq].count);
  199. if (re_enable)
  200. enable_interrupts ();
  201. }
  202. #endif