interrupts.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2002 (440 port)
  6. * Scott McNutt, Artesyn Communication Producs, smcnutt@artsyncp.com
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <watchdog.h>
  28. #include <command.h>
  29. #include <asm/processor.h>
  30. #include <ppc4xx.h>
  31. #include <ppc_asm.tmpl>
  32. #include <commproc.h>
  33. #include "vecnum.h"
  34. /****************************************************************************/
  35. /*
  36. * CPM interrupt vector functions.
  37. */
  38. struct irq_action {
  39. interrupt_handler_t *handler;
  40. void *arg;
  41. int count;
  42. };
  43. static struct irq_action irq_vecs[32];
  44. #if defined(CONFIG_440)
  45. static struct irq_action irq_vecs1[32]; /* For UIC1 */
  46. void uic1_interrupt( void * parms); /* UIC1 handler */
  47. #endif
  48. /****************************************************************************/
  49. #if defined(CONFIG_440)
  50. /* SPRN changed in 440 */
  51. static __inline__ void set_evpr(unsigned long val)
  52. {
  53. asm volatile("mtspr 0x03f,%0" : : "r" (val));
  54. }
  55. #else /* !defined(CONFIG_440) */
  56. static __inline__ void set_pit(unsigned long val)
  57. {
  58. asm volatile("mtpit %0" : : "r" (val));
  59. }
  60. static __inline__ void set_tcr(unsigned long val)
  61. {
  62. asm volatile("mttcr %0" : : "r" (val));
  63. }
  64. static __inline__ void set_evpr(unsigned long val)
  65. {
  66. asm volatile("mtevpr %0" : : "r" (val));
  67. }
  68. #endif /* defined(CONFIG_440 */
  69. /****************************************************************************/
  70. int interrupt_init_cpu (unsigned *decrementer_count)
  71. {
  72. DECLARE_GLOBAL_DATA_PTR;
  73. int vec;
  74. unsigned long val;
  75. /* decrementer is automatically reloaded */
  76. *decrementer_count = 0;
  77. /*
  78. * Mark all irqs as free
  79. */
  80. for (vec=0; vec<32; vec++) {
  81. irq_vecs[vec].handler = NULL;
  82. irq_vecs[vec].arg = NULL;
  83. irq_vecs[vec].count = 0;
  84. #if defined(CONFIG_440)
  85. irq_vecs1[vec].handler = NULL;
  86. irq_vecs1[vec].arg = NULL;
  87. irq_vecs1[vec].count = 0;
  88. #endif
  89. }
  90. #ifdef CONFIG_4xx
  91. /*
  92. * Init PIT
  93. */
  94. #if defined(CONFIG_440)
  95. val = mfspr( tcr );
  96. val &= (~0x04400000); /* clear DIS & ARE */
  97. mtspr( tcr, val );
  98. mtspr( dec, 0 ); /* Prevent exception after TSR clear*/
  99. mtspr( decar, 0 ); /* clear reload */
  100. mtspr( tsr, 0x08000000 ); /* clear DEC status */
  101. val = gd->bd->bi_intfreq/100; /* 10 msec */
  102. mtspr( decar, val ); /* Set auto-reload value */
  103. mtspr( dec, val ); /* Set inital val */
  104. #else
  105. set_pit(gd->bd->bi_intfreq / 1000);
  106. #endif
  107. #endif /* CONFIG_4xx */
  108. #ifdef CONFIG_ADCIOP
  109. /*
  110. * Init PIT
  111. */
  112. set_pit(66000);
  113. #endif
  114. /*
  115. * Enable PIT
  116. */
  117. val = mfspr(tcr);
  118. val |= 0x04400000;
  119. mtspr(tcr, val);
  120. /*
  121. * Set EVPR to 0
  122. */
  123. set_evpr(0x00000000);
  124. #if defined(CONFIG_440)
  125. /* Install the UIC1 handlers */
  126. irq_install_handler(VECNUM_UIC1NC, uic1_interrupt, 0);
  127. irq_install_handler(VECNUM_UIC1C, uic1_interrupt, 0);
  128. #endif
  129. return (0);
  130. }
  131. /****************************************************************************/
  132. /*
  133. * Handle external interrupts
  134. */
  135. void external_interrupt(struct pt_regs *regs)
  136. {
  137. ulong uic_msr;
  138. ulong msr_shift;
  139. int vec;
  140. /*
  141. * Read masked interrupt status register to determine interrupt source
  142. */
  143. uic_msr = mfdcr(uicmsr);
  144. msr_shift = uic_msr;
  145. vec = 0;
  146. while (msr_shift != 0) {
  147. if (msr_shift & 0x80000000) {
  148. /*
  149. * Increment irq counter (for debug purpose only)
  150. */
  151. irq_vecs[vec].count++;
  152. if (irq_vecs[vec].handler != NULL) {
  153. /* call isr */
  154. (*irq_vecs[vec].handler)(irq_vecs[vec].arg);
  155. } else {
  156. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> vec));
  157. printf ("Masking bogus interrupt vector 0x%x\n", vec);
  158. }
  159. /*
  160. * After servicing the interrupt, we have to remove the status indicator.
  161. */
  162. mtdcr(uicsr, (0x80000000 >> vec));
  163. }
  164. /*
  165. * Shift msr to next position and increment vector
  166. */
  167. msr_shift <<= 1;
  168. vec++;
  169. }
  170. }
  171. #if defined(CONFIG_440)
  172. /* Handler for UIC1 interrupt */
  173. void uic1_interrupt( void * parms)
  174. {
  175. ulong uic1_msr;
  176. ulong msr_shift;
  177. int vec;
  178. /*
  179. * Read masked interrupt status register to determine interrupt source
  180. */
  181. uic1_msr = mfdcr(uic1msr);
  182. msr_shift = uic1_msr;
  183. vec = 0;
  184. while (msr_shift != 0) {
  185. if (msr_shift & 0x80000000) {
  186. /*
  187. * Increment irq counter (for debug purpose only)
  188. */
  189. irq_vecs1[vec].count++;
  190. if (irq_vecs1[vec].handler != NULL) {
  191. /* call isr */
  192. (*irq_vecs1[vec].handler)(irq_vecs1[vec].arg);
  193. } else {
  194. mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> vec));
  195. printf ("Masking bogus interrupt vector (uic1) 0x%x\n", vec);
  196. }
  197. /*
  198. * After servicing the interrupt, we have to remove the status indicator.
  199. */
  200. mtdcr(uic1sr, (0x80000000 >> vec));
  201. }
  202. /*
  203. * Shift msr to next position and increment vector
  204. */
  205. msr_shift <<= 1;
  206. vec++;
  207. }
  208. }
  209. #endif /* defined(CONFIG_440) */
  210. /****************************************************************************/
  211. /*
  212. * Install and free a interrupt handler.
  213. */
  214. void
  215. irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
  216. {
  217. struct irq_action *irqa = irq_vecs;
  218. int i = vec;
  219. #if defined(CONFIG_440)
  220. if (vec > 31) {
  221. i = vec - 32;
  222. irqa = irq_vecs1;
  223. }
  224. #endif
  225. if (irqa[i].handler != NULL) {
  226. printf ("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
  227. vec, (uint)handler, (uint)irqa[i].handler);
  228. }
  229. irqa[i].handler = handler;
  230. irqa[i].arg = arg;
  231. #if defined(CONFIG_440)
  232. if( vec > 31 )
  233. mtdcr(uic1er, mfdcr(uic1er) | (0x80000000 >> i));
  234. else
  235. #endif
  236. mtdcr(uicer, mfdcr(uicer) | (0x80000000 >> i));
  237. #if 0
  238. printf ("Install interrupt for vector %d ==> %p\n", vec, handler);
  239. #endif
  240. }
  241. void
  242. irq_free_handler(int vec)
  243. {
  244. struct irq_action *irqa = irq_vecs;
  245. int i = vec;
  246. #if defined(CONFIG_440)
  247. if (vec > 31) {
  248. irqa = irq_vecs1;
  249. i = vec - 32;
  250. }
  251. #endif
  252. #if 0
  253. printf ("Free interrupt for vector %d ==> %p\n",
  254. vec, irq_vecs[vec].handler);
  255. #endif
  256. #if defined(CONFIG_440)
  257. if (vec > 31)
  258. mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> i));
  259. else
  260. #endif
  261. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> i));
  262. irqa[i].handler = NULL;
  263. irqa[i].arg = NULL;
  264. }
  265. /****************************************************************************/
  266. void timer_interrupt_cpu (struct pt_regs *regs)
  267. {
  268. /* nothing to do here */
  269. return;
  270. }
  271. /****************************************************************************/
  272. #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
  273. /*******************************************************************************
  274. *
  275. * irqinfo - print information about PCI devices
  276. *
  277. */
  278. int
  279. do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  280. {
  281. int vec;
  282. printf ("\nInterrupt-Information:\n");
  283. #if defined(CONFIG_440)
  284. printf ("\nUIC 0\n");
  285. #endif
  286. printf ("Nr Routine Arg Count\n");
  287. for (vec=0; vec<32; vec++) {
  288. if (irq_vecs[vec].handler != NULL) {
  289. printf ("%02d %08lx %08lx %d\n",
  290. vec,
  291. (ulong)irq_vecs[vec].handler,
  292. (ulong)irq_vecs[vec].arg,
  293. irq_vecs[vec].count);
  294. }
  295. }
  296. #if defined(CONFIG_440)
  297. printf ("\nUIC 1\n");
  298. printf ("Nr Routine Arg Count\n");
  299. for (vec=0; vec<32; vec++)
  300. {
  301. if (irq_vecs1[vec].handler != NULL)
  302. printf ("%02d %08lx %08lx %d\n",
  303. vec+31, (ulong)irq_vecs1[vec].handler,
  304. (ulong)irq_vecs1[vec].arg, irq_vecs1[vec].count);
  305. }
  306. printf("\n");
  307. #endif
  308. return 0;
  309. }
  310. #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */