Timer.h 6.5 KB

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