interrupts.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <asm/processor.h>
  12. #include <watchdog.h>
  13. #ifdef CONFIG_STATUS_LED
  14. #include <status_led.h>
  15. #endif
  16. #ifdef CONFIG_SHOW_ACTIVITY
  17. void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity")));
  18. void __board_show_activity (ulong dummy)
  19. {
  20. return;
  21. }
  22. #endif /* CONFIG_SHOW_ACTIVITY */
  23. #ifndef CONFIG_SYS_WATCHDOG_FREQ
  24. #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
  25. #endif
  26. extern int interrupt_init_cpu (unsigned *);
  27. extern void timer_interrupt_cpu (struct pt_regs *);
  28. static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  29. static __inline__ unsigned long get_msr (void)
  30. {
  31. unsigned long msr;
  32. asm volatile ("mfmsr %0":"=r" (msr):);
  33. return msr;
  34. }
  35. static __inline__ void set_msr (unsigned long msr)
  36. {
  37. asm volatile ("mtmsr %0"::"r" (msr));
  38. }
  39. static __inline__ unsigned long get_dec (void)
  40. {
  41. unsigned long val;
  42. asm volatile ("mfdec %0":"=r" (val):);
  43. return val;
  44. }
  45. static __inline__ void set_dec (unsigned long val)
  46. {
  47. if (val)
  48. asm volatile ("mtdec %0"::"r" (val));
  49. }
  50. void enable_interrupts (void)
  51. {
  52. set_msr (get_msr () | MSR_EE);
  53. }
  54. /* returns flag if MSR_EE was set before */
  55. int disable_interrupts (void)
  56. {
  57. ulong msr = get_msr ();
  58. set_msr (msr & ~MSR_EE);
  59. return ((msr & MSR_EE) != 0);
  60. }
  61. int interrupt_init (void)
  62. {
  63. int ret;
  64. /* call cpu specific function from $(CPU)/interrupts.c */
  65. ret = interrupt_init_cpu (&decrementer_count);
  66. if (ret)
  67. return ret;
  68. set_dec (decrementer_count);
  69. set_msr (get_msr () | MSR_EE);
  70. return (0);
  71. }
  72. static volatile ulong timestamp = 0;
  73. void timer_interrupt (struct pt_regs *regs)
  74. {
  75. /* call cpu specific function from $(CPU)/interrupts.c */
  76. timer_interrupt_cpu (regs);
  77. /* Restore Decrementer Count */
  78. set_dec (decrementer_count);
  79. timestamp++;
  80. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  81. if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
  82. WATCHDOG_RESET ();
  83. #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
  84. #ifdef CONFIG_STATUS_LED
  85. status_led_tick (timestamp);
  86. #endif /* CONFIG_STATUS_LED */
  87. #ifdef CONFIG_SHOW_ACTIVITY
  88. board_show_activity (timestamp);
  89. #endif /* CONFIG_SHOW_ACTIVITY */
  90. }
  91. ulong get_timer (ulong base)
  92. {
  93. return (timestamp - base);
  94. }