interrupts.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_LED_STATUS
  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. static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  27. static __inline__ unsigned long get_dec (void)
  28. {
  29. unsigned long val;
  30. asm volatile ("mfdec %0":"=r" (val):);
  31. return val;
  32. }
  33. static __inline__ void set_dec (unsigned long val)
  34. {
  35. if (val)
  36. asm volatile ("mtdec %0"::"r" (val));
  37. }
  38. void enable_interrupts (void)
  39. {
  40. set_msr (get_msr () | MSR_EE);
  41. }
  42. /* returns flag if MSR_EE was set before */
  43. int disable_interrupts (void)
  44. {
  45. ulong msr = get_msr ();
  46. set_msr (msr & ~MSR_EE);
  47. return ((msr & MSR_EE) != 0);
  48. }
  49. int interrupt_init (void)
  50. {
  51. int ret;
  52. /* call cpu specific function from $(CPU)/interrupts.c */
  53. ret = interrupt_init_cpu (&decrementer_count);
  54. if (ret)
  55. return ret;
  56. set_dec (decrementer_count);
  57. set_msr (get_msr () | MSR_EE);
  58. return (0);
  59. }
  60. static volatile ulong timestamp = 0;
  61. void timer_interrupt (struct pt_regs *regs)
  62. {
  63. /* call cpu specific function from $(CPU)/interrupts.c */
  64. timer_interrupt_cpu (regs);
  65. /* Restore Decrementer Count */
  66. set_dec (decrementer_count);
  67. timestamp++;
  68. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  69. if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
  70. WATCHDOG_RESET ();
  71. #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
  72. #ifdef CONFIG_LED_STATUS
  73. status_led_tick (timestamp);
  74. #endif /* CONFIG_LED_STATUS */
  75. #ifdef CONFIG_SHOW_ACTIVITY
  76. board_show_activity (timestamp);
  77. #endif /* CONFIG_SHOW_ACTIVITY */
  78. }
  79. ulong get_timer (ulong base)
  80. {
  81. return (timestamp - base);
  82. }