interrupts.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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));
  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 status indicator.
  198. */
  199. set_dcr(uic_base + UIC_SR, (0x80000000 >> vec));
  200. }
  201. /*
  202. * Shift msr to next position and increment vector
  203. */
  204. msr_shift <<= 1;
  205. vec++;
  206. }
  207. }
  208. #if (UIC_MAX > 1) && !defined(CONFIG_440GX)
  209. static void uic_cascade_interrupt(void *para)
  210. {
  211. external_interrupt(para);
  212. }
  213. #endif
  214. #if defined(CONFIG_440)
  215. #if defined(CONFIG_440GX)
  216. /* 440GX uses base uic register */
  217. #define UIC_BMSR uicb0msr
  218. #define UIC_BSR uicb0sr
  219. #else
  220. #define UIC_BMSR uic0msr
  221. #define UIC_BSR uic0sr
  222. #endif
  223. #else /* CONFIG_440 */
  224. #define UIC_BMSR uicmsr
  225. #define UIC_BSR uicsr
  226. #endif /* CONFIG_440 */
  227. /*
  228. * Handle external interrupts
  229. */
  230. void external_interrupt(struct pt_regs *regs)
  231. {
  232. u32 uic_msr;
  233. /*
  234. * Read masked interrupt status register to determine interrupt source
  235. */
  236. uic_msr = mfdcr(UIC_BMSR);
  237. #if (UIC_MAX > 1)
  238. if ((UICB0_UIC1CI & uic_msr) || (UICB0_UIC1NCI & uic_msr))
  239. uic_interrupt(UIC1_DCR_BASE, 32);
  240. #endif
  241. #if (UIC_MAX > 2)
  242. if ((UICB0_UIC2CI & uic_msr) || (UICB0_UIC2NCI & uic_msr))
  243. uic_interrupt(UIC2_DCR_BASE, 64);
  244. #endif
  245. #if (UIC_MAX > 3)
  246. if ((UICB0_UIC3CI & uic_msr) || (UICB0_UIC3NCI & uic_msr))
  247. uic_interrupt(UIC3_DCR_BASE, 96);
  248. #endif
  249. #if defined(CONFIG_440)
  250. #if !defined(CONFIG_440GX)
  251. if (uic_msr & ~(UICB0_ALL))
  252. uic_interrupt(UIC0_DCR_BASE, 0);
  253. #else
  254. if ((UICB0_UIC0CI & uic_msr) || (UICB0_UIC0NCI & uic_msr))
  255. uic_interrupt(UIC0_DCR_BASE, 0);
  256. #endif
  257. #else /* CONFIG_440 */
  258. uic_interrupt(UIC0_DCR_BASE, 0);
  259. #endif /* CONFIG_440 */
  260. mtdcr(UIC_BSR, uic_msr);
  261. return;
  262. }
  263. /*
  264. * Install and free a interrupt handler.
  265. */
  266. void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg)
  267. {
  268. int i;
  269. /*
  270. * Print warning when replacing with a different irq vector
  271. */
  272. if ((irq_vecs[vec].handler != NULL) && (irq_vecs[vec].handler != handler)) {
  273. printf("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
  274. vec, (uint) handler, (uint) irq_vecs[vec].handler);
  275. }
  276. irq_vecs[vec].handler = handler;
  277. irq_vecs[vec].arg = arg;
  278. i = vec & 0x1f;
  279. if ((vec >= 0) && (vec < 32))
  280. mtdcr(uicer, mfdcr(uicer) | (0x80000000 >> i));
  281. #if (UIC_MAX > 1)
  282. else if ((vec >= 32) && (vec < 64))
  283. mtdcr(uic1er, mfdcr(uic1er) | (0x80000000 >> i));
  284. #endif
  285. #if (UIC_MAX > 2)
  286. else if ((vec >= 64) && (vec < 96))
  287. mtdcr(uic2er, mfdcr(uic2er) | (0x80000000 >> i));
  288. #endif
  289. #if (UIC_MAX > 3)
  290. else if (vec >= 96)
  291. mtdcr(uic3er, mfdcr(uic3er) | (0x80000000 >> i));
  292. #endif
  293. debug("Install interrupt for vector %d ==> %p\n", vec, handler);
  294. }
  295. void irq_free_handler (int vec)
  296. {
  297. int i;
  298. debug("Free interrupt for vector %d ==> %p\n",
  299. vec, irq_vecs[vec].handler);
  300. i = vec & 0x1f;
  301. if ((vec >= 0) && (vec < 32))
  302. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> i));
  303. #if (UIC_MAX > 1)
  304. else if ((vec >= 32) && (vec < 64))
  305. mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> i));
  306. #endif
  307. #if (UIC_MAX > 2)
  308. else if ((vec >= 64) && (vec < 96))
  309. mtdcr(uic2er, mfdcr(uic2er) & ~(0x80000000 >> i));
  310. #endif
  311. #if (UIC_MAX > 3)
  312. else if (vec >= 96)
  313. mtdcr(uic3er, mfdcr(uic3er) & ~(0x80000000 >> i));
  314. #endif
  315. irq_vecs[vec].handler = NULL;
  316. irq_vecs[vec].arg = NULL;
  317. }
  318. void timer_interrupt_cpu (struct pt_regs *regs)
  319. {
  320. /* nothing to do here */
  321. return;
  322. }
  323. #if defined(CONFIG_CMD_IRQ)
  324. int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  325. {
  326. int vec;
  327. printf ("Interrupt-Information:\n");
  328. printf ("Nr Routine Arg Count\n");
  329. for (vec = 0; vec < (UIC_MAX * 32); vec++) {
  330. if (irq_vecs[vec].handler != NULL) {
  331. printf ("%02d %08lx %08lx %d\n",
  332. vec,
  333. (ulong)irq_vecs[vec].handler,
  334. (ulong)irq_vecs[vec].arg,
  335. irq_vecs[vec].count);
  336. }
  337. }
  338. return 0;
  339. }
  340. #endif