interrupts.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * (C) Copyright 2008
  3. * Texas Instruments
  4. *
  5. * Richard Woodruff <r-woodruff2@ti.com>
  6. * Syed Moahmmed Khasim <khasim@ti.com>
  7. *
  8. * (C) Copyright 2002
  9. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  10. * Marius Groeger <mgroeger@sysgo.de>
  11. * Alex Zuepke <azu@sysgo.de>
  12. *
  13. * (C) Copyright 2002
  14. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  15. *
  16. * See file CREDITS for list of people who contributed to this
  17. * project.
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  32. * MA 02111-1307 USA
  33. */
  34. #include <common.h>
  35. #include <asm/io.h>
  36. #include <asm/proc-armv/ptrace.h>
  37. #ifdef CONFIG_USE_IRQ
  38. /* enable IRQ interrupts */
  39. void enable_interrupts(void)
  40. {
  41. unsigned long temp;
  42. __asm__ __volatile__("mrs %0, cpsr\n"
  43. "bic %0, %0, #0x80\n" "msr cpsr_c, %0":"=r"(temp)
  44. ::"memory");
  45. }
  46. /*
  47. * disable IRQ/FIQ interrupts
  48. * returns true if interrupts had been enabled before we disabled them
  49. */
  50. int disable_interrupts(void)
  51. {
  52. unsigned long old, temp;
  53. __asm__ __volatile__("mrs %0, cpsr\n"
  54. "orr %1, %0, #0xc0\n"
  55. "msr cpsr_c, %1":"=r"(old), "=r"(temp)
  56. ::"memory");
  57. return (old & 0x80) == 0;
  58. }
  59. #else
  60. void enable_interrupts(void)
  61. {
  62. return;
  63. }
  64. int disable_interrupts(void)
  65. {
  66. return 0;
  67. }
  68. #endif
  69. void bad_mode(void)
  70. {
  71. panic("Resetting CPU ...\n");
  72. reset_cpu(0);
  73. }
  74. void show_regs(struct pt_regs *regs)
  75. {
  76. unsigned long flags;
  77. const char *processor_modes[] = {
  78. "USER_26", "FIQ_26", "IRQ_26", "SVC_26",
  79. "UK4_26", "UK5_26", "UK6_26", "UK7_26",
  80. "UK8_26", "UK9_26", "UK10_26", "UK11_26",
  81. "UK12_26", "UK13_26", "UK14_26", "UK15_26",
  82. "USER_32", "FIQ_32", "IRQ_32", "SVC_32",
  83. "UK4_32", "UK5_32", "UK6_32", "ABT_32",
  84. "UK8_32", "UK9_32", "UK10_32", "UND_32",
  85. "UK12_32", "UK13_32", "UK14_32", "SYS_32",
  86. };
  87. flags = condition_codes(regs);
  88. printf("pc : [<%08lx>] lr : [<%08lx>]\n"
  89. "sp : %08lx ip : %08lx fp : %08lx\n",
  90. instruction_pointer(regs),
  91. regs->ARM_lr, regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
  92. printf("r10: %08lx r9 : %08lx r8 : %08lx\n",
  93. regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
  94. printf("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
  95. regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
  96. printf("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
  97. regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
  98. printf("Flags: %c%c%c%c",
  99. flags & CC_N_BIT ? 'N' : 'n',
  100. flags & CC_Z_BIT ? 'Z' : 'z',
  101. flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
  102. printf(" IRQs %s FIQs %s Mode %s%s\n",
  103. interrupts_enabled(regs) ? "on" : "off",
  104. fast_interrupts_enabled(regs) ? "on" : "off",
  105. processor_modes[processor_mode(regs)],
  106. thumb_mode(regs) ? " (T)" : "");
  107. }
  108. void do_undefined_instruction(struct pt_regs *pt_regs)
  109. {
  110. printf("undefined instruction\n");
  111. show_regs(pt_regs);
  112. bad_mode();
  113. }
  114. void do_software_interrupt(struct pt_regs *pt_regs)
  115. {
  116. printf("software interrupt\n");
  117. show_regs(pt_regs);
  118. bad_mode();
  119. }
  120. void do_prefetch_abort(struct pt_regs *pt_regs)
  121. {
  122. printf("prefetch abort\n");
  123. show_regs(pt_regs);
  124. bad_mode();
  125. }
  126. void do_data_abort(struct pt_regs *pt_regs)
  127. {
  128. printf("data abort\n");
  129. show_regs(pt_regs);
  130. bad_mode();
  131. }
  132. void do_not_used(struct pt_regs *pt_regs)
  133. {
  134. printf("not used\n");
  135. show_regs(pt_regs);
  136. bad_mode();
  137. }
  138. void do_fiq(struct pt_regs *pt_regs)
  139. {
  140. printf("fast interrupt request\n");
  141. show_regs(pt_regs);
  142. bad_mode();
  143. }
  144. void do_irq(struct pt_regs *pt_regs)
  145. {
  146. printf("interrupt request\n");
  147. show_regs(pt_regs);
  148. bad_mode();
  149. }
  150. static ulong timestamp;
  151. static ulong lastinc;
  152. static gptimer_t *timer_base = (gptimer_t *)CONFIG_SYS_TIMERBASE;
  153. /*
  154. * Nothing really to do with interrupts, just starts up a counter.
  155. * We run the counter with 13MHz, divided by 8, resulting in timer
  156. * frequency of 1.625MHz. With 32bit counter register, counter
  157. * overflows in ~44min
  158. */
  159. /* 13MHz / 8 = 1.625MHz */
  160. #define TIMER_CLOCK (V_SCLK / (2 << CONFIG_SYS_PTV))
  161. #define TIMER_LOAD_VAL 0xffffffff
  162. int interrupt_init(void)
  163. {
  164. /* start the counter ticking up, reload value on overflow */
  165. writel(TIMER_LOAD_VAL, &timer_base->tldr);
  166. /* enable timer */
  167. writel((CONFIG_SYS_PTV << 2) | TCLR_PRE | TCLR_AR | TCLR_ST,
  168. &timer_base->tclr);
  169. reset_timer_masked(); /* init the timestamp and lastinc value */
  170. return 0;
  171. }
  172. /*
  173. * timer without interrupts
  174. */
  175. void reset_timer(void)
  176. {
  177. reset_timer_masked();
  178. }
  179. ulong get_timer(ulong base)
  180. {
  181. return get_timer_masked() - base;
  182. }
  183. void set_timer(ulong t)
  184. {
  185. timestamp = t;
  186. }
  187. /* delay x useconds */
  188. void udelay(unsigned long usec)
  189. {
  190. long tmo = usec * (TIMER_CLOCK / 1000) / 1000;
  191. unsigned long now, last = readl(&timer_base->tcrr);
  192. while (tmo > 0) {
  193. now = readl(&timer_base->tcrr);
  194. if (last > now) /* count up timer overflow */
  195. tmo -= TIMER_LOAD_VAL - last + now;
  196. else
  197. tmo -= now - last;
  198. last = now;
  199. }
  200. }
  201. void reset_timer_masked(void)
  202. {
  203. /* reset time, capture current incrementer value time */
  204. lastinc = readl(&timer_base->tcrr) / (TIMER_CLOCK / CONFIG_SYS_HZ);
  205. timestamp = 0; /* start "advancing" time stamp from 0 */
  206. }
  207. ulong get_timer_masked(void)
  208. {
  209. /* current tick value */
  210. ulong now = readl(&timer_base->tcrr) / (TIMER_CLOCK / CONFIG_SYS_HZ);
  211. if (now >= lastinc) /* normal mode (non roll) */
  212. /* move stamp fordward with absoulte diff ticks */
  213. timestamp += (now - lastinc);
  214. else /* we have rollover of incrementer */
  215. timestamp += ((TIMER_LOAD_VAL / (TIMER_CLOCK / CONFIG_SYS_HZ))
  216. - lastinc) + now;
  217. lastinc = now;
  218. return timestamp;
  219. }
  220. /*
  221. * This function is derived from PowerPC code (read timebase as long long).
  222. * On ARM it just returns the timer value.
  223. */
  224. unsigned long long get_ticks(void)
  225. {
  226. return get_timer(0);
  227. }
  228. /*
  229. * This function is derived from PowerPC code (timebase clock frequency).
  230. * On ARM it returns the number of timer ticks per second.
  231. */
  232. ulong get_tbclk(void)
  233. {
  234. return CONFIG_SYS_HZ;
  235. }