interrupts.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <irq_func.h>
  11. #include <asm/processor.h>
  12. #include <watchdog.h>
  13. #ifdef CONFIG_LED_STATUS
  14. #include <status_led.h>
  15. #endif
  16. #include <asm/ptrace.h>
  17. #ifndef CONFIG_MPC83XX_TIMER
  18. #ifndef CONFIG_SYS_WATCHDOG_FREQ
  19. #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
  20. #endif
  21. static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  22. static __inline__ unsigned long get_dec (void)
  23. {
  24. unsigned long val;
  25. asm volatile ("mfdec %0":"=r" (val):);
  26. return val;
  27. }
  28. static __inline__ void set_dec (unsigned long val)
  29. {
  30. if (val)
  31. asm volatile ("mtdec %0"::"r" (val));
  32. }
  33. #endif /* !CONFIG_MPC83XX_TIMER */
  34. void enable_interrupts(void)
  35. {
  36. set_msr (get_msr () | MSR_EE);
  37. }
  38. /* returns flag if MSR_EE was set before */
  39. int disable_interrupts(void)
  40. {
  41. ulong msr = get_msr ();
  42. set_msr (msr & ~MSR_EE);
  43. return ((msr & MSR_EE) != 0);
  44. }
  45. #ifndef CONFIG_MPC83XX_TIMER
  46. int interrupt_init(void)
  47. {
  48. /* call cpu specific function from $(CPU)/interrupts.c */
  49. interrupt_init_cpu (&decrementer_count);
  50. set_dec (decrementer_count);
  51. set_msr (get_msr () | MSR_EE);
  52. return (0);
  53. }
  54. static volatile ulong timestamp = 0;
  55. void timer_interrupt(struct pt_regs *regs)
  56. {
  57. /* call cpu specific function from $(CPU)/interrupts.c */
  58. timer_interrupt_cpu (regs);
  59. /* Restore Decrementer Count */
  60. set_dec (decrementer_count);
  61. timestamp++;
  62. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  63. if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
  64. WATCHDOG_RESET ();
  65. #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
  66. #ifdef CONFIG_LED_STATUS
  67. status_led_tick(timestamp);
  68. #endif /* CONFIG_LED_STATUS */
  69. }
  70. ulong get_timer (ulong base)
  71. {
  72. return (timestamp - base);
  73. }
  74. #endif /* !CONFIG_MPC83XX_TIMER */