interrupts.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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 "vecnum.h"
  37. /****************************************************************************/
  38. /*
  39. * CPM interrupt vector functions.
  40. */
  41. struct irq_action {
  42. interrupt_handler_t *handler;
  43. void *arg;
  44. int count;
  45. };
  46. static struct irq_action irq_vecs[32];
  47. #if defined(CONFIG_440)
  48. static struct irq_action irq_vecs1[32]; /* For UIC1 */
  49. void uic1_interrupt( void * parms); /* UIC1 handler */
  50. #if defined(CONFIG_440_GX)
  51. static struct irq_action irq_vecs2[32]; /* For UIC2 */
  52. void uic0_interrupt( void * parms); /* UIC0 handler */
  53. void uic2_interrupt( void * parms); /* UIC2 handler */
  54. #endif /* CONFIG_440_GX */
  55. #endif /* CONFIG_440 */
  56. /****************************************************************************/
  57. #if defined(CONFIG_440)
  58. /* SPRN changed in 440 */
  59. static __inline__ void set_evpr(unsigned long val)
  60. {
  61. asm volatile("mtspr 0x03f,%0" : : "r" (val));
  62. }
  63. #else /* !defined(CONFIG_440) */
  64. static __inline__ void set_pit(unsigned long val)
  65. {
  66. asm volatile("mtpit %0" : : "r" (val));
  67. }
  68. static __inline__ void set_tcr(unsigned long val)
  69. {
  70. asm volatile("mttcr %0" : : "r" (val));
  71. }
  72. static __inline__ void set_evpr(unsigned long val)
  73. {
  74. asm volatile("mtevpr %0" : : "r" (val));
  75. }
  76. #endif /* defined(CONFIG_440 */
  77. /****************************************************************************/
  78. int interrupt_init_cpu (unsigned *decrementer_count)
  79. {
  80. DECLARE_GLOBAL_DATA_PTR;
  81. int vec;
  82. unsigned long val;
  83. /* decrementer is automatically reloaded */
  84. *decrementer_count = 0;
  85. /*
  86. * Mark all irqs as free
  87. */
  88. for (vec=0; vec<32; vec++) {
  89. irq_vecs[vec].handler = NULL;
  90. irq_vecs[vec].arg = NULL;
  91. irq_vecs[vec].count = 0;
  92. #if defined(CONFIG_440)
  93. irq_vecs1[vec].handler = NULL;
  94. irq_vecs1[vec].arg = NULL;
  95. irq_vecs1[vec].count = 0;
  96. #if defined(CONFIG_440_GX)
  97. irq_vecs2[vec].handler = NULL;
  98. irq_vecs2[vec].arg = NULL;
  99. irq_vecs2[vec].count = 0;
  100. #endif /* CONFIG_440_GX */
  101. #endif
  102. }
  103. #ifdef CONFIG_4xx
  104. /*
  105. * Init PIT
  106. */
  107. #if defined(CONFIG_440)
  108. val = mfspr( tcr );
  109. val &= (~0x04400000); /* clear DIS & ARE */
  110. mtspr( tcr, val );
  111. mtspr( dec, 0 ); /* Prevent exception after TSR clear*/
  112. mtspr( decar, 0 ); /* clear reload */
  113. mtspr( tsr, 0x08000000 ); /* clear DEC status */
  114. val = gd->bd->bi_intfreq/100; /* 10 msec */
  115. mtspr( decar, val ); /* Set auto-reload value */
  116. mtspr( dec, val ); /* Set inital val */
  117. #else
  118. set_pit(gd->bd->bi_intfreq / 1000);
  119. #endif
  120. #endif /* CONFIG_4xx */
  121. #ifdef CONFIG_ADCIOP
  122. /*
  123. * Init PIT
  124. */
  125. set_pit(66000);
  126. #endif
  127. /*
  128. * Enable PIT
  129. */
  130. val = mfspr(tcr);
  131. val |= 0x04400000;
  132. mtspr(tcr, val);
  133. /*
  134. * Set EVPR to 0
  135. */
  136. set_evpr(0x00000000);
  137. #if defined(CONFIG_440)
  138. #if !defined(CONFIG_440_GX)
  139. /* Install the UIC1 handlers */
  140. irq_install_handler(VECNUM_UIC1NC, uic1_interrupt, 0);
  141. irq_install_handler(VECNUM_UIC1C, uic1_interrupt, 0);
  142. #endif
  143. #endif
  144. #if defined(CONFIG_440_GX)
  145. /* Take the GX out of compatibility mode
  146. * Travis Sawyer, 9 Mar 2004
  147. * NOTE: 440gx user manual inconsistency here
  148. * Compatibility mode and Ethernet Clock select are not
  149. * correct in the manual
  150. */
  151. mfsdr(sdr_mfr, val);
  152. val &= ~0x10000000;
  153. mtsdr(sdr_mfr,val);
  154. /* Enable UIC interrupts via UIC Base Enable Register */
  155. mtdcr(uicb0sr, UICB0_ALL);
  156. mtdcr(uicb0er, 0x54000000);
  157. /* None are critical */
  158. mtdcr(uicb0cr, 0);
  159. #endif
  160. return (0);
  161. }
  162. /****************************************************************************/
  163. /*
  164. * Handle external interrupts
  165. */
  166. #if defined(CONFIG_440_GX)
  167. void external_interrupt(struct pt_regs *regs)
  168. {
  169. ulong uic_msr;
  170. /*
  171. * Read masked interrupt status register to determine interrupt source
  172. */
  173. /* 440 GX uses base uic register */
  174. uic_msr = mfdcr(uicb0msr);
  175. if ( (UICB0_UIC0CI & uic_msr) || (UICB0_UIC0NCI & uic_msr) )
  176. uic0_interrupt(0);
  177. if ( (UICB0_UIC1CI & uic_msr) || (UICB0_UIC1NCI & uic_msr) )
  178. uic1_interrupt(0);
  179. if ( (UICB0_UIC2CI & uic_msr) || (UICB0_UIC2NCI & uic_msr) )
  180. uic2_interrupt(0);
  181. mtdcr(uicb0sr, uic_msr);
  182. return;
  183. } /* external_interrupt CONFIG_440_GX */
  184. #else
  185. void external_interrupt(struct pt_regs *regs)
  186. {
  187. ulong uic_msr;
  188. ulong msr_shift;
  189. int vec;
  190. /*
  191. * Read masked interrupt status register to determine interrupt source
  192. */
  193. uic_msr = mfdcr(uicmsr);
  194. msr_shift = uic_msr;
  195. vec = 0;
  196. while (msr_shift != 0) {
  197. if (msr_shift & 0x80000000) {
  198. /*
  199. * Increment irq counter (for debug purpose only)
  200. */
  201. irq_vecs[vec].count++;
  202. if (irq_vecs[vec].handler != NULL) {
  203. /* call isr */
  204. (*irq_vecs[vec].handler)(irq_vecs[vec].arg);
  205. } else {
  206. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> vec));
  207. printf ("Masking bogus interrupt vector 0x%x\n", vec);
  208. }
  209. /*
  210. * After servicing the interrupt, we have to remove the status indicator.
  211. */
  212. mtdcr(uicsr, (0x80000000 >> vec));
  213. }
  214. /*
  215. * Shift msr to next position and increment vector
  216. */
  217. msr_shift <<= 1;
  218. vec++;
  219. }
  220. }
  221. #endif
  222. #if defined(CONFIG_440_GX)
  223. /* Handler for UIC0 interrupt */
  224. void uic0_interrupt( void * parms)
  225. {
  226. ulong uic_msr;
  227. ulong msr_shift;
  228. int vec;
  229. /*
  230. * Read masked interrupt status register to determine interrupt source
  231. */
  232. uic_msr = mfdcr(uicmsr);
  233. msr_shift = uic_msr;
  234. vec = 0;
  235. while (msr_shift != 0) {
  236. if (msr_shift & 0x80000000) {
  237. /*
  238. * Increment irq counter (for debug purpose only)
  239. */
  240. irq_vecs[vec].count++;
  241. if (irq_vecs[vec].handler != NULL) {
  242. /* call isr */
  243. (*irq_vecs[vec].handler)(irq_vecs[vec].arg);
  244. } else {
  245. mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> vec));
  246. printf ("Masking bogus interrupt vector (uic0) 0x%x\n", vec);
  247. }
  248. /*
  249. * After servicing the interrupt, we have to remove the status indicator.
  250. */
  251. mtdcr(uicsr, (0x80000000 >> vec));
  252. }
  253. /*
  254. * Shift msr to next position and increment vector
  255. */
  256. msr_shift <<= 1;
  257. vec++;
  258. }
  259. }
  260. #endif /* CONFIG_440_GX */
  261. #if defined(CONFIG_440)
  262. /* Handler for UIC1 interrupt */
  263. void uic1_interrupt( void * parms)
  264. {
  265. ulong uic1_msr;
  266. ulong msr_shift;
  267. int vec;
  268. /*
  269. * Read masked interrupt status register to determine interrupt source
  270. */
  271. uic1_msr = mfdcr(uic1msr);
  272. msr_shift = uic1_msr;
  273. vec = 0;
  274. while (msr_shift != 0) {
  275. if (msr_shift & 0x80000000) {
  276. /*
  277. * Increment irq counter (for debug purpose only)
  278. */
  279. irq_vecs1[vec].count++;
  280. if (irq_vecs1[vec].handler != NULL) {
  281. /* call isr */
  282. (*irq_vecs1[vec].handler)(irq_vecs1[vec].arg);
  283. } else {
  284. mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> vec));
  285. printf ("Masking bogus interrupt vector (uic1) 0x%x\n", vec);
  286. }
  287. /*
  288. * After servicing the interrupt, we have to remove the status indicator.
  289. */
  290. mtdcr(uic1sr, (0x80000000 >> vec));
  291. }
  292. /*
  293. * Shift msr to next position and increment vector
  294. */
  295. msr_shift <<= 1;
  296. vec++;
  297. }
  298. }
  299. #endif /* defined(CONFIG_440) */
  300. #if defined(CONFIG_440_GX)
  301. /* Handler for UIC1 interrupt */
  302. void uic2_interrupt( void * parms)
  303. {
  304. ulong uic2_msr;
  305. ulong msr_shift;
  306. int vec;
  307. /*
  308. * Read masked interrupt status register to determine interrupt source
  309. */
  310. uic2_msr = mfdcr(uic2msr);
  311. msr_shift = uic2_msr;
  312. vec = 0;
  313. while (msr_shift != 0) {
  314. if (msr_shift & 0x80000000) {
  315. /*
  316. * Increment irq counter (for debug purpose only)
  317. */
  318. irq_vecs2[vec].count++;
  319. if (irq_vecs2[vec].handler != NULL) {
  320. /* call isr */
  321. (*irq_vecs2[vec].handler)(irq_vecs2[vec].arg);
  322. } else {
  323. mtdcr(uic2er, mfdcr(uic2er) & ~(0x80000000 >> vec));
  324. printf ("Masking bogus interrupt vector (uic1) 0x%x\n", vec);
  325. }
  326. /*
  327. * After servicing the interrupt, we have to remove the status indicator.
  328. */
  329. mtdcr(uic2sr, (0x80000000 >> vec));
  330. }
  331. /*
  332. * Shift msr to next position and increment vector
  333. */
  334. msr_shift <<= 1;
  335. vec++;
  336. }
  337. }
  338. #endif /* defined(CONFIG_440_GX) */
  339. /****************************************************************************/
  340. /*
  341. * Install and free a interrupt handler.
  342. */
  343. void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
  344. {
  345. struct irq_action *irqa = irq_vecs;
  346. int i = vec;
  347. #if defined(CONFIG_440)
  348. #if defined(CONFIG_440_GX)
  349. if ((vec > 31) && (vec < 64)) {
  350. i = vec - 32;
  351. irqa = irq_vecs1;
  352. } else if (vec > 63) {
  353. i = vec - 64;
  354. irqa = irq_vecs2;
  355. }
  356. #else /* CONFIG_440_GX */
  357. if (vec > 31) {
  358. i = vec - 32;
  359. irqa = irq_vecs1;
  360. }
  361. #endif /* CONFIG_440_GX */
  362. #endif /* CONFIG_440 */
  363. if (irqa[i].handler != NULL) {
  364. printf ("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
  365. vec, (uint) handler, (uint) irqa[i].handler);
  366. }
  367. irqa[i].handler = handler;
  368. irqa[i].arg = arg;
  369. #if defined(CONFIG_440)
  370. #if defined(CONFIG_440_GX)
  371. if ((vec > 31) && (vec < 64))
  372. mtdcr (uic1er, mfdcr (uic1er) | (0x80000000 >> i));
  373. else if (vec > 63)
  374. mtdcr (uic2er, mfdcr (uic2er) | (0x80000000 >> i));
  375. else
  376. #endif /* CONFIG_440_GX */
  377. if (vec > 31)
  378. mtdcr (uic1er, mfdcr (uic1er) | (0x80000000 >> i));
  379. else
  380. #endif
  381. mtdcr (uicer, mfdcr (uicer) | (0x80000000 >> i));
  382. #if 0
  383. printf ("Install interrupt for vector %d ==> %p\n", vec, handler);
  384. #endif
  385. }
  386. void irq_free_handler (int vec)
  387. {
  388. struct irq_action *irqa = irq_vecs;
  389. int i = vec;
  390. #if defined(CONFIG_440)
  391. #if defined(CONFIG_440_GX)
  392. if ((vec > 31) && (vec < 64)) {
  393. irqa = irq_vecs1;
  394. i = vec - 32;
  395. } else if (vec > 63) {
  396. irqa = irq_vecs2;
  397. i = vec - 64;
  398. }
  399. #endif /* CONFIG_440_GX */
  400. if (vec > 31) {
  401. irqa = irq_vecs1;
  402. i = vec - 32;
  403. }
  404. #endif
  405. #if 0
  406. printf ("Free interrupt for vector %d ==> %p\n",
  407. vec, irq_vecs[vec].handler);
  408. #endif
  409. #if defined(CONFIG_440)
  410. #if defined(CONFIG_440_GX)
  411. if ((vec > 31) && (vec < 64))
  412. mtdcr (uic1er, mfdcr (uic1er) & ~(0x80000000 >> i));
  413. else if (vec > 63)
  414. mtdcr (uic2er, mfdcr (uic2er) & ~(0x80000000 >> i));
  415. else
  416. #endif /* CONFIG_440_GX */
  417. if (vec > 31)
  418. mtdcr (uic1er, mfdcr (uic1er) & ~(0x80000000 >> i));
  419. else
  420. #endif
  421. mtdcr (uicer, mfdcr (uicer) & ~(0x80000000 >> i));
  422. irqa[i].handler = NULL;
  423. irqa[i].arg = NULL;
  424. }
  425. /****************************************************************************/
  426. void timer_interrupt_cpu (struct pt_regs *regs)
  427. {
  428. /* nothing to do here */
  429. return;
  430. }
  431. /****************************************************************************/
  432. #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
  433. /*******************************************************************************
  434. *
  435. * irqinfo - print information about PCI devices
  436. *
  437. */
  438. int
  439. do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  440. {
  441. int vec;
  442. printf ("\nInterrupt-Information:\n");
  443. #if defined(CONFIG_440)
  444. printf ("\nUIC 0\n");
  445. #endif
  446. printf ("Nr Routine Arg Count\n");
  447. for (vec=0; vec<32; vec++) {
  448. if (irq_vecs[vec].handler != NULL) {
  449. printf ("%02d %08lx %08lx %d\n",
  450. vec,
  451. (ulong)irq_vecs[vec].handler,
  452. (ulong)irq_vecs[vec].arg,
  453. irq_vecs[vec].count);
  454. }
  455. }
  456. #if defined(CONFIG_440)
  457. printf ("\nUIC 1\n");
  458. printf ("Nr Routine Arg Count\n");
  459. for (vec=0; vec<32; vec++) {
  460. if (irq_vecs1[vec].handler != NULL)
  461. printf ("%02d %08lx %08lx %d\n",
  462. vec+31, (ulong)irq_vecs1[vec].handler,
  463. (ulong)irq_vecs1[vec].arg, irq_vecs1[vec].count);
  464. }
  465. printf("\n");
  466. #endif
  467. #if defined(CONFIG_440_GX)
  468. printf ("\nUIC 2\n");
  469. printf ("Nr Routine Arg Count\n");
  470. for (vec=0; vec<32; vec++) {
  471. if (irq_vecs2[vec].handler != NULL)
  472. printf ("%02d %08lx %08lx %d\n",
  473. vec+63, (ulong)irq_vecs2[vec].handler,
  474. (ulong)irq_vecs2[vec].arg, irq_vecs2[vec].count);
  475. }
  476. printf("\n");
  477. #endif
  478. return 0;
  479. }
  480. #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */