2 Private data structures
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2019, Citrix Systems, Inc.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Protocol/Cpu.h>
16 #include <Protocol/Timer.h>
18 #include <Register/LocalApic.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/BaseLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/LocalApicLib.h>
24 #include <Library/PcdLib.h>
26 // The default timer tick duration is set to 10 ms = 100000 100 ns units
28 #define DEFAULT_TIMER_TICK_DURATION 100000
31 // The Timer Vector use for interrupt
33 #define LOCAL_APIC_TIMER_VECTOR 32
36 // Function Prototypes
39 Initialize the Timer Architectural Protocol driver
41 @param ImageHandle ImageHandle of the loaded driver
42 @param SystemTable Pointer to the System Table
44 @retval EFI_SUCCESS Timer Architectural Protocol created
45 @retval EFI_OUT_OF_RESOURCES Not enough resources available to initialize driver.
46 @retval EFI_DEVICE_ERROR A device error occurred attempting to initialize the driver.
51 TimerDriverInitialize (
52 IN EFI_HANDLE ImageHandle
,
53 IN EFI_SYSTEM_TABLE
*SystemTable
59 This function adjusts the period of timer interrupts to the value specified
60 by TimerPeriod. If the timer period is updated, then the selected timer
61 period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
62 the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
63 If an error occurs while attempting to update the timer period, then the
64 timer hardware will be put back in its state prior to this call, and
65 EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
66 is disabled. This is not the same as disabling the CPU's interrupts.
67 Instead, it must either turn off the timer hardware, or it must adjust the
68 interrupt controller so that a CPU interrupt is not generated when the timer
72 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
73 @param NotifyFunction The rate to program the timer interrupt in 100 nS units. If
74 the timer hardware is not programmable, then EFI_UNSUPPORTED is
75 returned. If the timer is programmable, then the timer period
76 will be rounded up to the nearest timer period that is supported
77 by the timer hardware. If TimerPeriod is set to 0, then the
78 timer interrupts will be disabled.
80 @retval EFI_SUCCESS The timer period was changed.
81 @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.
82 @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
87 TimerDriverRegisterHandler (
88 IN EFI_TIMER_ARCH_PROTOCOL
*This
,
89 IN EFI_TIMER_NOTIFY NotifyFunction
95 This function adjusts the period of timer interrupts to the value specified
96 by TimerPeriod. If the timer period is updated, then the selected timer
97 period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
98 the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
99 If an error occurs while attempting to update the timer period, then the
100 timer hardware will be put back in its state prior to this call, and
101 EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
102 is disabled. This is not the same as disabling the CPU's interrupts.
103 Instead, it must either turn off the timer hardware, or it must adjust the
104 interrupt controller so that a CPU interrupt is not generated when the timer
108 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
109 @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If
110 the timer hardware is not programmable, then EFI_UNSUPPORTED is
111 returned. If the timer is programmable, then the timer period
112 will be rounded up to the nearest timer period that is supported
113 by the timer hardware. If TimerPeriod is set to 0, then the
114 timer interrupts will be disabled.
116 @retval EFI_SUCCESS The timer period was changed.
117 @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.
118 @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
123 TimerDriverSetTimerPeriod (
124 IN EFI_TIMER_ARCH_PROTOCOL
*This
,
125 IN UINT64 TimerPeriod
131 This function retrieves the period of timer interrupts in 100 ns units,
132 returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod
133 is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is
134 returned, then the timer is currently disabled.
137 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
138 @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If
139 0 is returned, then the timer is currently disabled.
141 @retval EFI_SUCCESS The timer period was returned in TimerPeriod.
142 @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
147 TimerDriverGetTimerPeriod (
148 IN EFI_TIMER_ARCH_PROTOCOL
*This
,
149 OUT UINT64
*TimerPeriod
155 This function generates a soft timer interrupt. If the platform does not support soft
156 timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.
157 If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()
158 service, then a soft timer interrupt will be generated. If the timer interrupt is
159 enabled when this service is called, then the registered handler will be invoked. The
160 registered handler should not be able to distinguish a hardware-generated timer
161 interrupt from a software-generated timer interrupt.
164 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
166 @retval EFI_SUCCESS The soft timer interrupt was generated.
167 @retval EFI_UNSUPPORTED The platform does not support the generation of soft timer interrupts.
172 TimerDriverGenerateSoftInterrupt (
173 IN EFI_TIMER_ARCH_PROTOCOL
*This