LocalApicTimerDxe.h 6.5 KB

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