interrupts.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. * (C) Copyright 2003 (440GX port)
  9. * Travis B. Sawyer, Sandburst Corporation, tsawyer@sandburst.com
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <watchdog.h>
  31. #include <command.h>
  32. #include <asm/processor.h>
  33. #include <ppc4xx.h>
  34. #include <ppc_asm.tmpl>
  35. #include <commproc.h>
  36. #include <asm/ppc4xx-intvec.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. /*
  39. * Define the number of UIC's
  40. */
  41. #if defined(CONFIG_440SPE) || \
  42. defined(CONFIG_460EX) || defined(CONFIG_460GT)
  43. #define UIC_MAX 4
  44. #elif defined(CONFIG_440GX) || \
  45. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  46. defined(CONFIG_405EX)
  47. #define UIC_MAX 3
  48. #elif defined(CONFIG_440GP) || defined(CONFIG_440SP) || \
  49. defined(CONFIG_440EP) || defined(CONFIG_440GR)
  50. #define UIC_MAX 2
  51. #else
  52. #define UIC_MAX 1
  53. #endif
  54. /*
  55. * CPM interrupt vector functions.
  56. */
  57. struct irq_action {
  58. interrupt_handler_t *handler;
  59. void *arg;
  60. int count;
  61. };
  62. static struct irq_action irq_vecs[UIC_MAX * 32];
  63. u32 get_dcr(u16);
  64. void set_dcr(u16, u32);
  65. #if (UIC_MAX > 1) && !defined(CONFIG_440GX)
  66. static void uic_cascade_interrupt(void *para);
  67. #endif
  68. #if defined(CONFIG_440)
  69. /* SPRN changed in 440 */
  70. static __inline__ void set_evpr(unsigned long val)
  71. {
  72. asm volatile("mtspr 0x03f,%0" : : "r" (val));
  73. }
  74. #else /* !defined(CONFIG_440) */
  75. static __inline__ void set_pit(unsigned long val)
  76. {
  77. asm volatile("mtpit %0" : : "r" (val));
  78. }
  79. static __inline__ void set_tcr(unsigned long val)
  80. {
  81. asm volatile("mttcr %0" : : "r" (val));
  82. }
  83. static __inline__ void set_evpr(unsigned long val)
  84. {
  85. asm volatile("mtevpr %0" : : "r" (val));
  86. }
  87. #endif /* defined(CONFIG_440 */
  88. int interrupt_init_cpu (unsigned *decrementer_count)
  89. {
  90. int vec;
  91. unsigned long val;
  92. /* decrementer is automatically reloaded */
  93. *decrementer_count = 0;
  94. /*
  95. * Mark all irqs as free
  96. */
  97. for (vec = 0; vec < (UIC_MAX * 32); vec++) {
  98. irq_vecs[vec].handler = NULL;
  99. irq_vecs[vec].arg = NULL;
  100. irq_vecs[vec].count = 0;
  101. }
  102. #ifdef CONFIG_4xx
  103. /*
  104. * Init PIT
  105. */
  106. #if defined(CONFIG_440)
  107. val = mfspr( tcr );
  108. val &= (~0x04400000); /* clear DIS & ARE */
  109. mtspr( tcr, val );
  110. mtspr( dec, 0 ); /* Prevent exception after TSR clear*/
  111. mtspr( decar, 0 ); /* clear reload */
  112. mtspr( tsr, 0x08000000 ); /* clear DEC status */
  113. val = gd->bd->bi_intfreq/1000; /* 1 msec */
  114. mtspr( decar, val ); /* Set auto-reload value */
  115. mtspr( dec, val ); /* Set inital val */
  116. #else
  117. set_pit(gd->bd->bi_intfreq / 1000);
  118. #endif
  119. #endif /* CONFIG_4xx */
  120. #ifdef CONFIG_ADCIOP
  121. /*
  122. * Init PIT
  123. */
  124. set_pit(66000);
  125. #endif
  126. /*
  127. * Enable PIT
  128. */
  129. val = mfspr(tcr);
  130. val |= 0x04400000;
  131. mtspr(tcr, val);
  132. /*
  133. * Set EVPR to 0
  134. */
  135. set_evpr(0x00000000);
  136. #if !defined(CONFIG_440GX)
  137. #if (UIC_MAX > 1)
  138. /* Install the UIC1 handlers */
  139. irq_install_handler(VECNUM_UIC1NC, uic_cascade_interrupt, 0);
  140. irq_install_handler(VECNUM_UIC1C, uic_cascade_interrupt, 0);
  141. #endif
  142. #if (UIC_MAX > 2)
  143. irq_install_handler(VECNUM_UIC2NC, uic_cascade_interrupt, 0);
  144. irq_install_handler(VECNUM_UIC2C, uic_cascade_interrupt, 0);
  145. #endif
  146. #if (UIC_MAX > 3)
  147. irq_install_handler(VECNUM_UIC3NC, uic_cascade_interrupt, 0);
  148. irq_install_handler(VECNUM_UIC3C, uic_cascade_interrupt, 0);
  149. #endif
  150. #else /* !defined(CONFIG_440GX) */
  151. /* Take the GX out of compatibility mode
  152. * Travis Sawyer, 9 Mar 2004
  153. * NOTE: 440gx user manual inconsistency here
  154. * Compatibility mode and Ethernet Clock select are not
  155. * correct in the manual
  156. */
  157. mfsdr(sdr_mfr, val);
  158. val &= ~0x10000000;
  159. mtsdr(sdr_mfr,val);
  160. /* Enable UIC interrupts via UIC Base Enable Register */
  161. mtdcr(uicb0sr, UICB0_ALL);
  162. mtdcr(uicb0er, 0x54000000);
  163. /* None are critical */
  164. mtdcr(uicb0cr, 0);
  165. #endif /* !defined(CONFIG_440GX) */
  166. return (0);
  167. }
  168. /* Handler for UIC interrupt */
  169. static void uic_interrupt(u32 uic_base, int vec_base)
  170. {
  171. u32 uic_msr;
  172. u32 msr_shift;
  173. int vec;
  174. /*
  175. * Read masked interrupt status register to determine interrupt source
  176. */
  177. uic_msr = get_dcr(uic_base + UIC_MSR);
  178. msr_shift = uic_msr;
  179. vec = vec_base;
  180. while (msr_shift != 0) {
  181. if (msr_shift & 0x80000000) {
  182. /*
  183. * Increment irq counter (for debug purpose only)
  184. */
  185. irq_vecs[vec].count++;
  186. if (irq_vecs[vec].handler != NULL) {
  187. /* call isr */
  188. (*irq_vecs[vec].handler)(irq_vecs[vec].arg);
  189. } else {
  190. set_dcr(uic_base + UIC_ER,
  191. get_dcr(uic_base + UIC_ER) &
  192. ~(0x80000000 >> (vec & 0x1f)));
  193. printf("Masking bogus interrupt vector %d"
  194. " (UIC_BASE=0x%x)\n", vec, uic_base);
  195. }
  196. /*
  197. * After servicing the interrupt, we have to remove the
  198. * status indicator
  199. */
  200. set_dcr(uic_base + UIC_SR, (0x80000000 >> (vec & 0x1f)));
  201. }
  202. /*
  203. * Shift msr to next position and increment vector
  204. */
  205. msr_shift <<= 1;
  206. vec++;
  207. }
  208. }
  209. #if (UIC_MAX > 1) && !defined(CONFIG_440GX)
  210. static void uic_cascade_interrupt(void *para)
  211. {
  212. external_interrupt(para);
  213. }
  214. #endif
  215. #if defined(CONFIG_440)
  216. #if defined(CONFIG_440GX)
  217. /* 440GX uses base uic register */
  218. #define UIC_BMSR uicb0msr
  219. #define UIC_BSR uicb0sr
  220. #else
  221. #define UIC_BMSR uic0msr
  222. #define UIC_BSR uic0sr
  223. #endif
  224. #else /* CONFIG_440 */
  225. #define UIC_BMSR uicmsr
  226. #define UIC_BSR uicsr
  227. #endif /* CONFIG_440 */
  228. /*
  229. * Handle external interrupts
  230. */
  231. void external_interrupt(struct pt_regs *regs)
  232. {
  233. u32 uic_msr;
  234. /*
  235. * Read masked interrupt status register to determine interrupt source
  236. */
  237. uic_msr = mfdcr(UIC_BMSR);
  238. #if (UIC_MAX > 1)
  239. if ((UICB0_UIC1CI & uic_msr) || (UICB0_UIC1NCI & uic_msr))
  240. uic_interrupt(UIC1_DCR_BASE, 32);
  241. #endif
  242. #if (UIC_MAX > 2)
  243. if ((UICB0_UIC2CI & uic_msr) || (UICB0_UIC2NCI & uic_msr))
  244. uic_interrupt(UIC2_DCR_BASE, 64);
  245. #endif
  246. #if (UIC_MAX > 3)
  247. if ((UICB0_UIC3CI & uic_msr) || (UICB0_UIC3NCI & uic_msr))
  248. uic_interrupt(UIC3_DCR_BASE, 96);
  249. #endif
  250. #if defined(CONFIG_440)
  251. #if !defined(CONFIG_440GX)
  252. if (uic_msr & ~(UICB0_ALL))
  253. uic_interrupt(UIC0_DCR_BASE, 0);
  254. #else
  255. if ((UICB0_UIC0CI & uic_msr) || (UICB0_UIC0NCI & uic_msr))
  256. uic_interrupt(UIC0_DCR_BASE, 0);
  257. #endif
  258. #else /* CONFIG_440 */
  259. uic_interrupt(UIC0_DCR_BASE, 0);
  260. #endif /* CONFIG_440 */
  261. mtdcr(UIC_BSR, uic_msr);
  262. return;
  263. }
  264. /*
  265. * Install and free a interrupt handler.
  266. */
  267. void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg)
  268. {
  269. int i;
  270. /*
  271. * Print warning when replacing with a different irq vector
  272. */
  273. if ((irq_vecs[vec].handler != NULL) && (irq_vecs[vec].handler != handler)) {
  274. printf("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
  275. vec, (uint) handler, (uint) irq_vecs[vec].handler);
  276. }
  277. irq_vecs[vec].handler = handler;
  278. irq_vecs[vec].arg = arg;
  279. i = vec & 0x1f;
  280. if ((vec >= 0) && (vec < 32))
  281. mtdcr(uicer, mfdcr(uicer) | (0x80000000 >> i));
  282. #if (UIC_MAX > 1)
  283. else if ((vec >= 32) && (vec < 64))
  284. mtdcr(uic1er, mfdcr(uic1er) | (0x80000000 >> i));
  285. #endif
  286. #if (UIC_MAX > 2)
  287. else if ((vec >= 64) && (vec < 96))
  288. mtdcr(uic2er, mfdcr(uic2er) | (0x80000000 >> i));
  289. #endif
  290. #if (UIC_MAX > 3)
  291. else if (vec >= 96)
  292. mtdcr(uic3er, mfdcr(uic3er) | (0x80000000 >> i));
  293. #endif
  294. debug("Install interrupt for vector %d ==> %p\n", vec, handler);
  295. }
  296. void irq_free_handler (int vec)
  297. {
  298. int i;
  299. debug("Free interrupt for vector %d ==> %p\n",
  300. vec, irq_vecs[vec].handler);
  301. i = vec & 0x1f;
  302. if ((vec >= 0) && (vec < 32))
  303. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> i));
  304. #if (UIC_MAX > 1)
  305. else if ((vec >= 32) && (vec < 64))
  306. mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> i));
  307. #endif
  308. #if (UIC_MAX > 2)
  309. else if ((vec >= 64) && (vec < 96))
  310. mtdcr(uic2er, mfdcr(uic2er) & ~(0x80000000 >> i));
  311. #endif
  312. #if (UIC_MAX > 3)
  313. else if (vec >= 96)
  314. mtdcr(uic3er, mfdcr(uic3er) & ~(0x80000000 >> i));
  315. #endif
  316. irq_vecs[vec].handler = NULL;
  317. irq_vecs[vec].arg = NULL;
  318. }
  319. void timer_interrupt_cpu (struct pt_regs *regs)
  320. {
  321. /* nothing to do here */
  322. return;
  323. }
  324. #if defined(CONFIG_CMD_IRQ)
  325. int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  326. {
  327. int vec;
  328. printf ("Interrupt-Information:\n");
  329. printf ("Nr Routine Arg Count\n");
  330. for (vec = 0; vec < (UIC_MAX * 32); vec++) {
  331. if (irq_vecs[vec].handler != NULL) {
  332. printf ("%02d %08lx %08lx %d\n",
  333. vec,
  334. (ulong)irq_vecs[vec].handler,
  335. (ulong)irq_vecs[vec].arg,
  336. irq_vecs[vec].count);
  337. }
  338. }
  339. return 0;
  340. }
  341. #endif