interrupts.c 15 KB

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