interrupts.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. extern void board_show_activity (ulong);
  34. #endif /* CONFIG_SHOW_ACTIVITY */
  35. #ifndef CFG_WATCHDOG_FREQ
  36. #define CFG_WATCHDOG_FREQ (CFG_HZ / 2)
  37. #endif
  38. extern int interrupt_init_cpu (unsigned *);
  39. extern void timer_interrupt_cpu (struct pt_regs *);
  40. static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  41. static __inline__ unsigned long get_msr (void)
  42. {
  43. unsigned long msr;
  44. asm volatile ("mfmsr %0":"=r" (msr):);
  45. return msr;
  46. }
  47. static __inline__ void set_msr (unsigned long msr)
  48. {
  49. asm volatile ("mtmsr %0"::"r" (msr));
  50. }
  51. static __inline__ unsigned long get_dec (void)
  52. {
  53. unsigned long val;
  54. asm volatile ("mfdec %0":"=r" (val):);
  55. return val;
  56. }
  57. static __inline__ void set_dec (unsigned long val)
  58. {
  59. if (val)
  60. asm volatile ("mtdec %0"::"r" (val));
  61. }
  62. void enable_interrupts (void)
  63. {
  64. set_msr (get_msr () | MSR_EE);
  65. }
  66. /* returns flag if MSR_EE was set before */
  67. int disable_interrupts (void)
  68. {
  69. ulong msr = get_msr ();
  70. set_msr (msr & ~MSR_EE);
  71. return ((msr & MSR_EE) != 0);
  72. }
  73. int interrupt_init (void)
  74. {
  75. int ret;
  76. /* call cpu specific function from $(CPU)/interrupts.c */
  77. ret = interrupt_init_cpu (&decrementer_count);
  78. if (ret)
  79. return ret;
  80. set_dec (decrementer_count);
  81. set_msr (get_msr () | MSR_EE);
  82. return (0);
  83. }
  84. static volatile ulong timestamp = 0;
  85. void timer_interrupt (struct pt_regs *regs)
  86. {
  87. /* call cpu specific function from $(CPU)/interrupts.c */
  88. timer_interrupt_cpu (regs);
  89. /* Restore Decrementer Count */
  90. set_dec (decrementer_count);
  91. timestamp++;
  92. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  93. if ((timestamp % (CFG_WATCHDOG_FREQ)) == 0)
  94. WATCHDOG_RESET ();
  95. #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
  96. #ifdef CONFIG_STATUS_LED
  97. status_led_tick (timestamp);
  98. #endif /* CONFIG_STATUS_LED */
  99. #ifdef CONFIG_SHOW_ACTIVITY
  100. board_show_activity (timestamp);
  101. #endif /* CONFIG_SHOW_ACTIVITY */
  102. }
  103. void reset_timer (void)
  104. {
  105. timestamp = 0;
  106. }
  107. ulong get_timer (ulong base)
  108. {
  109. return (timestamp - base);
  110. }
  111. void set_timer (ulong t)
  112. {
  113. timestamp = t;
  114. }