interrupts.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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. unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  36. /****************************************************************************/
  37. /*
  38. * CPM interrupt vector functions.
  39. */
  40. struct irq_action {
  41. interrupt_handler_t *handler;
  42. void *arg;
  43. int count;
  44. };
  45. static struct irq_action irq_vecs[32];
  46. #if defined(CONFIG_440)
  47. static struct irq_action irq_vecs1[32]; /* For UIC1 */
  48. void uic1_interrupt( void * parms); /* UIC1 handler */
  49. #endif
  50. /****************************************************************************/
  51. static __inline__ unsigned long get_msr(void)
  52. {
  53. unsigned long msr;
  54. asm volatile("mfmsr %0" : "=r" (msr) :);
  55. return msr;
  56. }
  57. static __inline__ void set_msr(unsigned long msr)
  58. {
  59. asm volatile("mtmsr %0" : : "r" (msr));
  60. }
  61. #if defined(CONFIG_440)
  62. /* SPRN changed in 440 */
  63. static __inline__ void set_evpr(unsigned long val)
  64. {
  65. asm volatile("mtspr 0x03f,%0" : : "r" (val));
  66. }
  67. #else /* !defined(CONFIG_440) */
  68. static __inline__ unsigned long get_dec(void)
  69. {
  70. unsigned long val;
  71. asm volatile("mfdec %0" : "=r" (val) :);
  72. return val;
  73. }
  74. static __inline__ void set_dec(unsigned long val)
  75. {
  76. asm volatile("mtdec %0" : : "r" (val));
  77. }
  78. static __inline__ void set_pit(unsigned long val)
  79. {
  80. asm volatile("mtpit %0" : : "r" (val));
  81. }
  82. static __inline__ void set_tcr(unsigned long val)
  83. {
  84. asm volatile("mttcr %0" : : "r" (val));
  85. }
  86. static __inline__ void set_evpr(unsigned long val)
  87. {
  88. asm volatile("mtevpr %0" : : "r" (val));
  89. }
  90. #endif /* defined(CONFIG_440 */
  91. void enable_interrupts (void)
  92. {
  93. set_msr (get_msr() | MSR_EE);
  94. }
  95. /* returns flag if MSR_EE was set before */
  96. int disable_interrupts (void)
  97. {
  98. ulong msr = get_msr();
  99. set_msr (msr & ~MSR_EE);
  100. return ((msr & MSR_EE) != 0);
  101. }
  102. /****************************************************************************/
  103. int interrupt_init(void)
  104. {
  105. DECLARE_GLOBAL_DATA_PTR;
  106. int vec;
  107. unsigned long val;
  108. /*
  109. * Mark all irqs as free
  110. */
  111. for (vec=0; vec<32; vec++) {
  112. irq_vecs[vec].handler = NULL;
  113. irq_vecs[vec].arg = NULL;
  114. irq_vecs[vec].count = 0;
  115. #if defined(CONFIG_440)
  116. irq_vecs1[vec].handler = NULL;
  117. irq_vecs1[vec].arg = NULL;
  118. irq_vecs1[vec].count = 0;
  119. #endif
  120. }
  121. #ifdef CONFIG_4xx
  122. /*
  123. * Init PIT
  124. */
  125. #if defined(CONFIG_440)
  126. val = mfspr( tcr );
  127. val &= (~0x04400000); /* clear DIS & ARE */
  128. mtspr( tcr, val );
  129. mtspr( dec, 0 ); /* Prevent exception after TSR clear*/
  130. mtspr( decar, 0 ); /* clear reload */
  131. mtspr( tsr, 0x08000000 ); /* clear DEC status */
  132. val = gd->bd->bi_intfreq/100; /* 10 msec */
  133. mtspr( decar, val ); /* Set auto-reload value */
  134. mtspr( dec, val ); /* Set inital val */
  135. #else
  136. set_pit(gd->bd->bi_intfreq / 1000);
  137. #endif
  138. #endif /* CONFIG_4xx */
  139. #ifdef CONFIG_ADCIOP
  140. /*
  141. * Init PIT
  142. */
  143. set_pit(66000);
  144. #endif
  145. /*
  146. * Enable PIT
  147. */
  148. val = mfspr(tcr);
  149. val |= 0x04400000;
  150. mtspr(tcr, val);
  151. /*
  152. * Set EVPR to 0
  153. */
  154. set_evpr(0x00000000);
  155. #if defined(CONFIG_440)
  156. /* Install the UIC1 handlers */
  157. irq_install_handler(VECNUM_UIC1NC, uic1_interrupt, 0);
  158. irq_install_handler(VECNUM_UIC1C, uic1_interrupt, 0);
  159. #endif
  160. /*
  161. * Enable external interrupts (including PIT)
  162. */
  163. set_msr (get_msr() | MSR_EE);
  164. return (0);
  165. }
  166. /****************************************************************************/
  167. /*
  168. * Handle external interrupts
  169. */
  170. void external_interrupt(struct pt_regs *regs)
  171. {
  172. ulong uic_msr;
  173. ulong msr_shift;
  174. int vec;
  175. /*
  176. * Read masked interrupt status register to determine interrupt source
  177. */
  178. uic_msr = mfdcr(uicmsr);
  179. msr_shift = uic_msr;
  180. vec = 0;
  181. while (msr_shift != 0) {
  182. if (msr_shift & 0x80000000) {
  183. /*
  184. * Increment irq counter (for debug purpose only)
  185. */
  186. irq_vecs[vec].count++;
  187. if (irq_vecs[vec].handler != NULL) {
  188. /* call isr */
  189. (*irq_vecs[vec].handler)(irq_vecs[vec].arg);
  190. } else {
  191. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> vec));
  192. printf ("Masking bogus interrupt vector 0x%x\n", vec);
  193. }
  194. /*
  195. * After servicing the interrupt, we have to remove the status indicator.
  196. */
  197. mtdcr(uicsr, (0x80000000 >> vec));
  198. }
  199. /*
  200. * Shift msr to next position and increment vector
  201. */
  202. msr_shift <<= 1;
  203. vec++;
  204. }
  205. }
  206. #if defined(CONFIG_440)
  207. /* Handler for UIC1 interrupt */
  208. void uic1_interrupt( void * parms)
  209. {
  210. ulong uic1_msr;
  211. ulong msr_shift;
  212. int vec;
  213. /*
  214. * Read masked interrupt status register to determine interrupt source
  215. */
  216. uic1_msr = mfdcr(uic1msr);
  217. msr_shift = uic1_msr;
  218. vec = 0;
  219. while (msr_shift != 0) {
  220. if (msr_shift & 0x80000000) {
  221. /*
  222. * Increment irq counter (for debug purpose only)
  223. */
  224. irq_vecs1[vec].count++;
  225. if (irq_vecs1[vec].handler != NULL) {
  226. /* call isr */
  227. (*irq_vecs1[vec].handler)(irq_vecs1[vec].arg);
  228. } else {
  229. mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> vec));
  230. printf ("Masking bogus interrupt vector (uic1) 0x%x\n", vec);
  231. }
  232. /*
  233. * After servicing the interrupt, we have to remove the status indicator.
  234. */
  235. mtdcr(uic1sr, (0x80000000 >> vec));
  236. }
  237. /*
  238. * Shift msr to next position and increment vector
  239. */
  240. msr_shift <<= 1;
  241. vec++;
  242. }
  243. }
  244. #endif /* defined(CONFIG_440) */
  245. /****************************************************************************/
  246. /*
  247. * Install and free a interrupt handler.
  248. */
  249. void
  250. irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
  251. {
  252. struct irq_action *irqa = irq_vecs;
  253. int i = vec;
  254. #if defined(CONFIG_440)
  255. if (vec > 31) {
  256. i = vec - 32;
  257. irqa = irq_vecs1;
  258. }
  259. #endif
  260. if (irqa[i].handler != NULL) {
  261. printf ("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
  262. vec, (uint)handler, (uint)irqa[i].handler);
  263. }
  264. irqa[i].handler = handler;
  265. irqa[i].arg = arg;
  266. #if defined(CONFIG_440)
  267. if( vec > 31 )
  268. mtdcr(uic1er, mfdcr(uic1er) | (0x80000000 >> i));
  269. else
  270. #endif
  271. mtdcr(uicer, mfdcr(uicer) | (0x80000000 >> i));
  272. #if 0
  273. printf ("Install interrupt for vector %d ==> %p\n", vec, handler);
  274. #endif
  275. }
  276. void
  277. irq_free_handler(int vec)
  278. {
  279. struct irq_action *irqa = irq_vecs;
  280. int i = vec;
  281. #if defined(CONFIG_440)
  282. if (vec > 31) {
  283. irqa = irq_vecs1;
  284. i = vec - 32;
  285. }
  286. #endif
  287. #if 0
  288. printf ("Free interrupt for vector %d ==> %p\n",
  289. vec, irq_vecs[vec].handler);
  290. #endif
  291. #if defined(CONFIG_440)
  292. if (vec > 31)
  293. mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> i));
  294. else
  295. #endif
  296. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> i));
  297. irqa[i].handler = NULL;
  298. irqa[i].arg = NULL;
  299. }
  300. /****************************************************************************/
  301. volatile ulong timestamp = 0;
  302. /*
  303. * timer_interrupt - gets called when the decrementer overflows,
  304. * with interrupts disabled.
  305. * Trivial implementation - no need to be really accurate.
  306. */
  307. void timer_interrupt(struct pt_regs *regs)
  308. {
  309. #if 0
  310. printf ("*** Timer Interrupt *** ");
  311. #endif
  312. timestamp++;
  313. #if defined(CONFIG_WATCHDOG)
  314. if ((timestamp % 1000) == 0)
  315. reset_4xx_watchdog();
  316. #endif /* CONFIG_WATCHDOG */
  317. }
  318. /****************************************************************************/
  319. void reset_timer (void)
  320. {
  321. timestamp = 0;
  322. }
  323. ulong get_timer (ulong base)
  324. {
  325. return (timestamp - base);
  326. }
  327. void set_timer (ulong t)
  328. {
  329. timestamp = t;
  330. }
  331. /****************************************************************************/
  332. #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
  333. /*******************************************************************************
  334. *
  335. * irqinfo - print information about PCI devices
  336. *
  337. */
  338. int
  339. do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  340. {
  341. int vec;
  342. printf ("\nInterrupt-Information:\n");
  343. #if defined(CONFIG_440)
  344. printf ("\nUIC 0\n");
  345. #endif
  346. printf ("Nr Routine Arg Count\n");
  347. for (vec=0; vec<32; vec++) {
  348. if (irq_vecs[vec].handler != NULL) {
  349. printf ("%02d %08lx %08lx %d\n",
  350. vec,
  351. (ulong)irq_vecs[vec].handler,
  352. (ulong)irq_vecs[vec].arg,
  353. irq_vecs[vec].count);
  354. }
  355. }
  356. #if defined(CONFIG_440)
  357. printf ("\nUIC 1\n");
  358. printf ("Nr Routine Arg Count\n");
  359. for (vec=0; vec<32; vec++)
  360. {
  361. if (irq_vecs1[vec].handler != NULL)
  362. printf ("%02d %08lx %08lx %d\n",
  363. vec+31, (ulong)irq_vecs1[vec].handler,
  364. (ulong)irq_vecs1[vec].arg, irq_vecs1[vec].count);
  365. }
  366. printf("\n");
  367. #endif
  368. return 0;
  369. }
  370. #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */