interrupts.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * (C) Copyright 2006
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * (C) Copyright 2002
  6. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. * Marius Groeger <mgroeger@sysgo.de>
  8. *
  9. * (C) Copyright 2002
  10. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  11. * Alex Zuepke <azu@sysgo.de>
  12. *
  13. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. #include <common.h>
  32. #include <asm/arch/ixp425.h>
  33. #ifdef CONFIG_USE_IRQ
  34. /*
  35. * When interrupts are enabled, use timer 2 for time/delay generation...
  36. */
  37. #define FREQ 66666666
  38. #define CLOCK_TICK_RATE (((FREQ / CFG_HZ & ~IXP425_OST_RELOAD_MASK) + 1) * CFG_HZ)
  39. #define LATCH ((CLOCK_TICK_RATE + CFG_HZ/2) / CFG_HZ) /* For divider */
  40. struct _irq_handler {
  41. void *m_data;
  42. void (*m_func)( void *data);
  43. };
  44. static struct _irq_handler IRQ_HANDLER[N_IRQS];
  45. static volatile ulong timestamp;
  46. /* enable IRQ/FIQ interrupts */
  47. void enable_interrupts(void)
  48. {
  49. unsigned long temp;
  50. __asm__ __volatile__("mrs %0, cpsr\n"
  51. "bic %0, %0, #0x80\n"
  52. "msr cpsr_c, %0"
  53. : "=r" (temp)
  54. :
  55. : "memory");
  56. }
  57. /*
  58. * disable IRQ/FIQ interrupts
  59. * returns true if interrupts had been enabled before we disabled them
  60. */
  61. int disable_interrupts(void)
  62. {
  63. unsigned long old,temp;
  64. __asm__ __volatile__("mrs %0, cpsr\n"
  65. "orr %1, %0, #0x80\n"
  66. "msr cpsr_c, %1"
  67. : "=r" (old), "=r" (temp)
  68. :
  69. : "memory");
  70. return (old & 0x80) == 0;
  71. }
  72. static void default_isr(void *data)
  73. {
  74. printf("default_isr(): called for IRQ %d, Interrupt Status=%x PR=%x\n",
  75. (int)data, *IXP425_ICIP, *IXP425_ICIH);
  76. }
  77. static int next_irq(void)
  78. {
  79. return (((*IXP425_ICIH & 0x000000fc) >> 2) - 1);
  80. }
  81. static void timer_isr(void *data)
  82. {
  83. unsigned int *pTime = (unsigned int *)data;
  84. (*pTime)++;
  85. /*
  86. * Reset IRQ source
  87. */
  88. *IXP425_OSST = IXP425_OSST_TIMER_2_PEND;
  89. }
  90. ulong get_timer (ulong base)
  91. {
  92. return timestamp - base;
  93. }
  94. void reset_timer (void)
  95. {
  96. timestamp = 0;
  97. }
  98. #else /* #ifdef CONFIG_USE_IRQ */
  99. void enable_interrupts (void)
  100. {
  101. return;
  102. }
  103. int disable_interrupts (void)
  104. {
  105. return 0;
  106. }
  107. #endif /* #ifdef CONFIG_USE_IRQ */
  108. void bad_mode (void)
  109. {
  110. panic ("Resetting CPU ...\n");
  111. reset_cpu (0);
  112. }
  113. void show_regs (struct pt_regs *regs)
  114. {
  115. unsigned long flags;
  116. const char *processor_modes[] = {
  117. "USER_26", "FIQ_26", "IRQ_26", "SVC_26",
  118. "UK4_26", "UK5_26", "UK6_26", "UK7_26",
  119. "UK8_26", "UK9_26", "UK10_26", "UK11_26",
  120. "UK12_26", "UK13_26", "UK14_26", "UK15_26",
  121. "USER_32", "FIQ_32", "IRQ_32", "SVC_32",
  122. "UK4_32", "UK5_32", "UK6_32", "ABT_32",
  123. "UK8_32", "UK9_32", "UK10_32", "UND_32",
  124. "UK12_32", "UK13_32", "UK14_32", "SYS_32"
  125. };
  126. flags = condition_codes (regs);
  127. printf ("pc : [<%08lx>] lr : [<%08lx>]\n"
  128. "sp : %08lx ip : %08lx fp : %08lx\n",
  129. instruction_pointer (regs),
  130. regs->ARM_lr, regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
  131. printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
  132. regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
  133. printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
  134. regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
  135. printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
  136. regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
  137. printf ("Flags: %c%c%c%c",
  138. flags & CC_N_BIT ? 'N' : 'n',
  139. flags & CC_Z_BIT ? 'Z' : 'z',
  140. flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
  141. printf (" IRQs %s FIQs %s Mode %s%s\n",
  142. interrupts_enabled (regs) ? "on" : "off",
  143. fast_interrupts_enabled (regs) ? "on" : "off",
  144. processor_modes[processor_mode (regs)],
  145. thumb_mode (regs) ? " (T)" : "");
  146. }
  147. void do_undefined_instruction (struct pt_regs *pt_regs)
  148. {
  149. printf ("undefined instruction\n");
  150. show_regs (pt_regs);
  151. bad_mode ();
  152. }
  153. void do_software_interrupt (struct pt_regs *pt_regs)
  154. {
  155. printf ("software interrupt\n");
  156. show_regs (pt_regs);
  157. bad_mode ();
  158. }
  159. void do_prefetch_abort (struct pt_regs *pt_regs)
  160. {
  161. printf ("prefetch abort\n");
  162. show_regs (pt_regs);
  163. bad_mode ();
  164. }
  165. void do_data_abort (struct pt_regs *pt_regs)
  166. {
  167. printf ("data abort\n");
  168. show_regs (pt_regs);
  169. bad_mode ();
  170. }
  171. void do_not_used (struct pt_regs *pt_regs)
  172. {
  173. printf ("not used\n");
  174. show_regs (pt_regs);
  175. bad_mode ();
  176. }
  177. void do_fiq (struct pt_regs *pt_regs)
  178. {
  179. printf ("fast interrupt request\n");
  180. show_regs (pt_regs);
  181. printf("IRQ=%08lx FIQ=%08lx\n", *IXP425_ICIH, *IXP425_ICFH);
  182. }
  183. void do_irq (struct pt_regs *pt_regs)
  184. {
  185. #ifdef CONFIG_USE_IRQ
  186. int irq = next_irq();
  187. IRQ_HANDLER[irq].m_func(IRQ_HANDLER[irq].m_data);
  188. #else
  189. printf ("interrupt request\n");
  190. show_regs (pt_regs);
  191. bad_mode ();
  192. #endif
  193. }
  194. int interrupt_init (void)
  195. {
  196. #ifdef CONFIG_USE_IRQ
  197. int i;
  198. /* install default interrupt handlers */
  199. for (i = 0; i < N_IRQS; i++) {
  200. IRQ_HANDLER[i].m_data = (void *)i;
  201. IRQ_HANDLER[i].m_func = default_isr;
  202. }
  203. /* install interrupt handler for timer */
  204. IRQ_HANDLER[IXP425_TIMER_2_IRQ].m_data = (void *)&timestamp;
  205. IRQ_HANDLER[IXP425_TIMER_2_IRQ].m_func = timer_isr;
  206. /* setup the Timer counter value */
  207. *IXP425_OSRT2 = (LATCH & ~IXP425_OST_RELOAD_MASK) | IXP425_OST_ENABLE;
  208. /* configure interrupts for IRQ mode */
  209. *IXP425_ICLR = 0x00000000;
  210. /* enable timer irq */
  211. *IXP425_ICMR = (1 << IXP425_TIMER_2_IRQ);
  212. #endif
  213. return (0);
  214. }