interrupts.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Alex Zuepke <azu@sysgo.de>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <clps7111.h>
  30. #include <asm/proc-armv/ptrace.h>
  31. #include <asm/hardware.h>
  32. extern void reset_cpu(ulong addr);
  33. #ifndef CONFIG_NETARM
  34. /* we always count down the max. */
  35. #define TIMER_LOAD_VAL 0xffff
  36. /* macro to read the 16 bit timer */
  37. #define READ_TIMER (IO_TC1D & 0xffff)
  38. #else
  39. #define IRQEN (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_INTR_ENABLE))
  40. #define TM2CTRL (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_CONTROL))
  41. #define TM2STAT (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_STATUS))
  42. #define TIMER_LOAD_VAL NETARM_GEN_TSTAT_CTC_MASK
  43. #define READ_TIMER (TM2STAT & NETARM_GEN_TSTAT_CTC_MASK)
  44. #endif
  45. #ifdef CONFIG_USE_IRQ
  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. #else
  73. void enable_interrupts (void)
  74. {
  75. return;
  76. }
  77. int disable_interrupts (void)
  78. {
  79. return 0;
  80. }
  81. #endif
  82. void bad_mode (void)
  83. {
  84. panic ("Resetting CPU ...\n");
  85. reset_cpu (0);
  86. }
  87. void show_regs (struct pt_regs *regs)
  88. {
  89. unsigned long flags;
  90. const char *processor_modes[] =
  91. { "USER_26", "FIQ_26", "IRQ_26", "SVC_26", "UK4_26", "UK5_26",
  92. "UK6_26", "UK7_26",
  93. "UK8_26", "UK9_26", "UK10_26", "UK11_26", "UK12_26", "UK13_26",
  94. "UK14_26", "UK15_26",
  95. "USER_32", "FIQ_32", "IRQ_32", "SVC_32", "UK4_32", "UK5_32",
  96. "UK6_32", "ABT_32",
  97. "UK8_32", "UK9_32", "UK10_32", "UND_32", "UK12_32", "UK13_32",
  98. "UK14_32", "SYS_32"
  99. };
  100. flags = condition_codes (regs);
  101. printf ("pc : [<%08lx>] lr : [<%08lx>]\n"
  102. "sp : %08lx ip : %08lx fp : %08lx\n",
  103. instruction_pointer (regs),
  104. regs->ARM_lr, regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
  105. printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
  106. regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
  107. printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
  108. regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
  109. printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
  110. regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
  111. printf ("Flags: %c%c%c%c",
  112. flags & CC_N_BIT ? 'N' : 'n',
  113. flags & CC_Z_BIT ? 'Z' : 'z',
  114. flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
  115. printf (" IRQs %s FIQs %s Mode %s%s\n",
  116. interrupts_enabled (regs) ? "on" : "off",
  117. fast_interrupts_enabled (regs) ? "on" : "off",
  118. processor_modes[processor_mode (regs)],
  119. thumb_mode (regs) ? " (T)" : "");
  120. }
  121. void do_undefined_instruction (struct pt_regs *pt_regs)
  122. {
  123. printf ("undefined instruction\n");
  124. show_regs (pt_regs);
  125. bad_mode ();
  126. }
  127. void do_software_interrupt (struct pt_regs *pt_regs)
  128. {
  129. printf ("software interrupt\n");
  130. show_regs (pt_regs);
  131. bad_mode ();
  132. }
  133. void do_prefetch_abort (struct pt_regs *pt_regs)
  134. {
  135. printf ("prefetch abort\n");
  136. show_regs (pt_regs);
  137. bad_mode ();
  138. }
  139. void do_data_abort (struct pt_regs *pt_regs)
  140. {
  141. printf ("data abort\n");
  142. show_regs (pt_regs);
  143. bad_mode ();
  144. }
  145. void do_not_used (struct pt_regs *pt_regs)
  146. {
  147. printf ("not used\n");
  148. show_regs (pt_regs);
  149. bad_mode ();
  150. }
  151. void do_fiq (struct pt_regs *pt_regs)
  152. {
  153. printf ("fast interrupt request\n");
  154. show_regs (pt_regs);
  155. bad_mode ();
  156. }
  157. void do_irq (struct pt_regs *pt_regs)
  158. {
  159. printf ("interrupt request\n");
  160. show_regs (pt_regs);
  161. bad_mode ();
  162. }
  163. static ulong timestamp;
  164. static ulong lastdec;
  165. int interrupt_init (void)
  166. {
  167. #if defined(CONFIG_NETARM)
  168. /* disable all interrupts */
  169. IRQEN = 0;
  170. /* operate timer 2 in non-prescale mode */
  171. TM2CTRL = ( NETARM_GEN_TIMER_SET_HZ(CFG_HZ) |
  172. NETARM_GEN_TCTL_ENABLE |
  173. NETARM_GEN_TCTL_INIT_COUNT(TIMER_LOAD_VAL));
  174. /* set timer 2 counter */
  175. lastdec = TIMER_LOAD_VAL;
  176. #elif defined(CONFIG_IMPA7) || defined(CONFIG_EP7312)
  177. /* disable all interrupts */
  178. IO_INTMR1 = 0;
  179. /* operate timer 1 in prescale mode */
  180. IO_SYSCON1 |= SYSCON1_TC1M;
  181. /* select 2kHz clock source for timer 1 */
  182. IO_SYSCON1 &= ~SYSCON1_TC1S;
  183. /* set timer 1 counter */
  184. lastdec = IO_TC1D = TIMER_LOAD_VAL;
  185. #elif defined(CONFIG_S3C4510B)
  186. /* Nothing to do, interrupts not supported */
  187. lastdec = 0;
  188. #else
  189. #error No interrupt_init() defined for this CPU type
  190. #endif
  191. timestamp = 0;
  192. return (0);
  193. }
  194. /*
  195. * timer without interrupts
  196. */
  197. #if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM)
  198. void reset_timer (void)
  199. {
  200. reset_timer_masked ();
  201. }
  202. ulong get_timer (ulong base)
  203. {
  204. return get_timer_masked () - base;
  205. }
  206. void set_timer (ulong t)
  207. {
  208. timestamp = t;
  209. }
  210. void udelay (unsigned long usec)
  211. {
  212. ulong tmo;
  213. tmo = usec / 1000;
  214. tmo *= CFG_HZ;
  215. tmo /= 1000;
  216. tmo += get_timer (0);
  217. while (get_timer_masked () < tmo)
  218. /*NOP*/;
  219. }
  220. void reset_timer_masked (void)
  221. {
  222. /* reset time */
  223. lastdec = READ_TIMER;
  224. timestamp = 0;
  225. }
  226. ulong get_timer_masked (void)
  227. {
  228. ulong now = READ_TIMER;
  229. if (lastdec >= now) {
  230. /* normal mode */
  231. timestamp += lastdec - now;
  232. } else {
  233. /* we have an overflow ... */
  234. timestamp += lastdec + TIMER_LOAD_VAL - now;
  235. }
  236. lastdec = now;
  237. return timestamp;
  238. }
  239. void udelay_masked (unsigned long usec)
  240. {
  241. ulong tmo;
  242. tmo = usec / 1000;
  243. tmo *= CFG_HZ;
  244. tmo /= 1000;
  245. reset_timer_masked ();
  246. while (get_timer_masked () < tmo)
  247. /*NOP*/;
  248. }
  249. #elif defined(CONFIG_S3C4510B)
  250. #define TMR_OFFSET (0x1000)
  251. void udelay (unsigned long usec)
  252. {
  253. u32 rDATA;
  254. rDATA = t_data_us(usec);
  255. /* Stop timer 0 */
  256. CLR_REG( REG_TMOD, TM0_RUN);
  257. /* Configure for toggle mode */
  258. SET_REG( REG_TMOD, TM0_TOGGLE);
  259. /* Load Timer data register with count down value plus offset */
  260. PUT_REG( REG_TDATA0, rDATA + TMR_OFFSET);
  261. /* Clear timer counter register */
  262. PUT_REG( REG_TCNT0, 0x0);
  263. /* Start timer -- count down timer */
  264. SET_REG( REG_TMOD, TM0_RUN);
  265. /* spin during count down */
  266. while ( GET_REG( REG_TCNT0) > TMR_OFFSET);
  267. /* Stop timer */
  268. CLR_REG( REG_TMOD, TM0_RUN);
  269. }
  270. ulong get_timer (ulong base)
  271. {
  272. return (0xFFFFFFFF - GET_REG( REG_TCNT1)) - base;
  273. }
  274. #else
  275. #error Timer routines not defined for this CPU type
  276. #endif