interrupts.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2003
  6. * Gleb Natapov <gnatapov@mrv.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/processor.h>
  28. #include <watchdog.h>
  29. #ifdef CONFIG_STATUS_LED
  30. #include <status_led.h>
  31. #endif
  32. #ifdef CONFIG_SHOW_ACTIVITY
  33. void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity")));
  34. void __board_show_activity (ulong dummy)
  35. {
  36. return;
  37. }
  38. #endif /* CONFIG_SHOW_ACTIVITY */
  39. #ifndef CONFIG_SYS_WATCHDOG_FREQ
  40. #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
  41. #endif
  42. extern int interrupt_init_cpu (unsigned *);
  43. extern void timer_interrupt_cpu (struct pt_regs *);
  44. static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  45. static __inline__ unsigned long get_msr (void)
  46. {
  47. unsigned long msr;
  48. asm volatile ("mfmsr %0":"=r" (msr):);
  49. return msr;
  50. }
  51. static __inline__ void set_msr (unsigned long msr)
  52. {
  53. asm volatile ("mtmsr %0"::"r" (msr));
  54. }
  55. static __inline__ unsigned long get_dec (void)
  56. {
  57. unsigned long val;
  58. asm volatile ("mfdec %0":"=r" (val):);
  59. return val;
  60. }
  61. static __inline__ void set_dec (unsigned long val)
  62. {
  63. if (val)
  64. asm volatile ("mtdec %0"::"r" (val));
  65. }
  66. void enable_interrupts (void)
  67. {
  68. set_msr (get_msr () | MSR_EE);
  69. }
  70. /* returns flag if MSR_EE was set before */
  71. int disable_interrupts (void)
  72. {
  73. ulong msr = get_msr ();
  74. set_msr (msr & ~MSR_EE);
  75. return ((msr & MSR_EE) != 0);
  76. }
  77. int interrupt_init (void)
  78. {
  79. int ret;
  80. /* call cpu specific function from $(CPU)/interrupts.c */
  81. ret = interrupt_init_cpu (&decrementer_count);
  82. if (ret)
  83. return ret;
  84. set_dec (decrementer_count);
  85. set_msr (get_msr () | MSR_EE);
  86. return (0);
  87. }
  88. static volatile ulong timestamp = 0;
  89. void timer_interrupt (struct pt_regs *regs)
  90. {
  91. /* call cpu specific function from $(CPU)/interrupts.c */
  92. timer_interrupt_cpu (regs);
  93. /* Restore Decrementer Count */
  94. set_dec (decrementer_count);
  95. timestamp++;
  96. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  97. if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
  98. WATCHDOG_RESET ();
  99. #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
  100. #ifdef CONFIG_STATUS_LED
  101. status_led_tick (timestamp);
  102. #endif /* CONFIG_STATUS_LED */
  103. #ifdef CONFIG_SHOW_ACTIVITY
  104. board_show_activity (timestamp);
  105. #endif /* CONFIG_SHOW_ACTIVITY */
  106. }
  107. void reset_timer (void)
  108. {
  109. timestamp = 0;
  110. }
  111. ulong get_timer (ulong base)
  112. {
  113. return (timestamp - base);
  114. }
  115. void set_timer (ulong t)
  116. {
  117. timestamp = t;
  118. }