Timer.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /** @file
  2. Private data structures
  3. Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef TIMER_H_
  7. #define TIMER_H_
  8. #include <Protocol/Timer.h>
  9. #define DEFAULT_TIMER_TICK_DURATION 100000 //10ms = 100000 100 ns units
  10. #define SR_IP7 (1 << 15)
  11. //
  12. // Function Prototypes
  13. //
  14. extern UINT32 EFIAPI CpuGetCompare(VOID);
  15. extern VOID EFIAPI CpuSetCompare(IN UINT32 val);
  16. extern VOID EFIAPI CpuSetIP(IN UINT32 val);
  17. extern VOID EFIAPI ClearC0Cause(IN UINT32 val);
  18. extern VOID EFIAPI ClearC0Status(IN UINT32 val);
  19. /**
  20. Initialize the Timer Architectural Protocol driver
  21. @param ImageHandle ImageHandle of the loaded driver
  22. @param SystemTable Pointer to the System Table
  23. @retval EFI_SUCCESS Timer Architectural Protocol created
  24. @retval EFI_OUT_OF_RESOURCES Not enough resources available to initialize driver.
  25. @retval EFI_DEVICE_ERROR A device error occurred attempting to initialize the driver.
  26. **/
  27. EFI_STATUS
  28. EFIAPI
  29. TimerDriverInitialize (
  30. IN EFI_HANDLE ImageHandle,
  31. IN EFI_SYSTEM_TABLE *SystemTable
  32. );
  33. /**
  34. This function adjusts the period of timer interrupts to the value specified
  35. by TimerPeriod. If the timer period is updated, then the selected timer
  36. period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
  37. the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
  38. If an error occurs while attempting to update the timer period, then the
  39. timer hardware will be put back in its state prior to this call, and
  40. EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
  41. is disabled. This is not the same as disabling the CPU's interrupts.
  42. Instead, it must either turn off the timer hardware, or it must adjust the
  43. interrupt controller so that a CPU interrupt is not generated when the timer
  44. interrupt fires.
  45. @param This The EFI_TIMER_ARCH_PROTOCOL instance.
  46. @param NotifyFunction The rate to program the timer interrupt in 100 nS units. If
  47. the timer hardware is not programmable, then EFI_UNSUPPORTED is
  48. returned. If the timer is programmable, then the timer period
  49. will be rounded up to the nearest timer period that is supported
  50. by the timer hardware. If TimerPeriod is set to 0, then the
  51. timer interrupts will be disabled.
  52. @retval EFI_SUCCESS The timer period was changed.
  53. @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.
  54. @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
  55. **/
  56. EFI_STATUS
  57. EFIAPI
  58. TimerDriverRegisterHandler (
  59. IN EFI_TIMER_ARCH_PROTOCOL *This,
  60. IN EFI_TIMER_NOTIFY NotifyFunction
  61. );
  62. /**
  63. This function adjusts the period of timer interrupts to the value specified
  64. by TimerPeriod. If the timer period is updated, then the selected timer
  65. period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
  66. the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
  67. If an error occurs while attempting to update the timer period, then the
  68. timer hardware will be put back in its state prior to this call, and
  69. EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
  70. is disabled. This is not the same as disabling the CPU's interrupts.
  71. Instead, it must either turn off the timer hardware, or it must adjust the
  72. interrupt controller so that a CPU interrupt is not generated when the timer
  73. interrupt fires.
  74. @param This The EFI_TIMER_ARCH_PROTOCOL instance.
  75. @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If
  76. the timer hardware is not programmable, then EFI_UNSUPPORTED is
  77. returned. If the timer is programmable, then the timer period
  78. will be rounded up to the nearest timer period that is supported
  79. by the timer hardware. If TimerPeriod is set to 0, then the
  80. timer interrupts will be disabled.
  81. @retval EFI_SUCCESS The timer period was changed.
  82. @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.
  83. @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
  84. **/
  85. EFI_STATUS
  86. EFIAPI
  87. TimerDriverSetTimerPeriod (
  88. IN EFI_TIMER_ARCH_PROTOCOL *This,
  89. IN UINT64 TimerPeriod
  90. );
  91. /**
  92. This function retrieves the period of timer interrupts in 100 ns units,
  93. returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod
  94. is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is
  95. returned, then the timer is currently disabled.
  96. @param This The EFI_TIMER_ARCH_PROTOCOL instance.
  97. @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If
  98. 0 is returned, then the timer is currently disabled.
  99. @retval EFI_SUCCESS The timer period was returned in TimerPeriod.
  100. @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
  101. **/
  102. EFI_STATUS
  103. EFIAPI
  104. TimerDriverGetTimerPeriod (
  105. IN EFI_TIMER_ARCH_PROTOCOL *This,
  106. OUT UINT64 *TimerPeriod
  107. );
  108. /**
  109. This function generates a soft timer interrupt. If the platform does not support soft
  110. timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.
  111. If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()
  112. service, then a soft timer interrupt will be generated. If the timer interrupt is
  113. enabled when this service is called, then the registered handler will be invoked. The
  114. registered handler should not be able to distinguish a hardware-generated timer
  115. interrupt from a software-generated timer interrupt.
  116. @param This The EFI_TIMER_ARCH_PROTOCOL instance.
  117. @retval EFI_SUCCESS The soft timer interrupt was generated.
  118. @retval EFI_UNSUPPORTED The platform does not support the generation of soft timer interrupts.
  119. **/
  120. EFI_STATUS
  121. EFIAPI
  122. TimerDriverGenerateSoftInterrupt (
  123. IN EFI_TIMER_ARCH_PROTOCOL *This
  124. );
  125. /**
  126. Write Csr TMCFG register.
  127. @param A0 The value used to write to the TMCFG register
  128. @retval none
  129. **/
  130. extern
  131. VOID
  132. LoongarchWriteqTmcfg (
  133. IN UINT64 Val
  134. );
  135. /**
  136. Write Csr TINTCLR register.
  137. @param A0 The value used to write to the TINTCLR register
  138. @retval none
  139. **/
  140. extern
  141. VOID
  142. LoongarchWriteqTintclr (
  143. IN UINT64 Val
  144. );
  145. #endif // TIMER_H_