interrupts.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000-2002
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2003
  7. * Gleb Natapov <gnatapov@mrv.com>
  8. */
  9. #include <common.h>
  10. #include <asm/processor.h>
  11. #include <watchdog.h>
  12. #ifdef CONFIG_LED_STATUS
  13. #include <status_led.h>
  14. #endif
  15. #ifdef CONFIG_SHOW_ACTIVITY
  16. void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity")));
  17. void __board_show_activity (ulong dummy)
  18. {
  19. return;
  20. }
  21. #endif /* CONFIG_SHOW_ACTIVITY */
  22. #ifndef CONFIG_SYS_WATCHDOG_FREQ
  23. #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
  24. #endif
  25. static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  26. static __inline__ unsigned long get_dec (void)
  27. {
  28. unsigned long val;
  29. asm volatile ("mfdec %0":"=r" (val):);
  30. return val;
  31. }
  32. static __inline__ void set_dec (unsigned long val)
  33. {
  34. if (val)
  35. asm volatile ("mtdec %0"::"r" (val));
  36. }
  37. void enable_interrupts (void)
  38. {
  39. set_msr (get_msr () | MSR_EE);
  40. }
  41. /* returns flag if MSR_EE was set before */
  42. int disable_interrupts (void)
  43. {
  44. ulong msr = get_msr ();
  45. set_msr (msr & ~MSR_EE);
  46. return ((msr & MSR_EE) != 0);
  47. }
  48. int interrupt_init (void)
  49. {
  50. /* call cpu specific function from $(CPU)/interrupts.c */
  51. interrupt_init_cpu (&decrementer_count);
  52. set_dec (decrementer_count);
  53. set_msr (get_msr () | MSR_EE);
  54. return (0);
  55. }
  56. static volatile ulong timestamp = 0;
  57. void timer_interrupt (struct pt_regs *regs)
  58. {
  59. /* call cpu specific function from $(CPU)/interrupts.c */
  60. timer_interrupt_cpu (regs);
  61. /* Restore Decrementer Count */
  62. set_dec (decrementer_count);
  63. timestamp++;
  64. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  65. if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
  66. WATCHDOG_RESET ();
  67. #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
  68. #ifdef CONFIG_LED_STATUS
  69. status_led_tick (timestamp);
  70. #endif /* CONFIG_LED_STATUS */
  71. #ifdef CONFIG_SHOW_ACTIVITY
  72. board_show_activity (timestamp);
  73. #endif /* CONFIG_SHOW_ACTIVITY */
  74. }
  75. ulong get_timer (ulong base)
  76. {
  77. return (timestamp - base);
  78. }