interrupts.c 7.1 KB

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