]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/Timer.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Include / Protocol / Timer.h
1 /** @file
2 Timer Architectural Protocol as defined in PI Specification VOLUME 2 DXE
3
4 This code is used to provide the timer tick for the DXE core.
5
6 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #ifndef __ARCH_PROTOCOL_TIMER_H__
12 #define __ARCH_PROTOCOL_TIMER_H__
13
14 ///
15 /// Global ID for the Timer Architectural Protocol
16 ///
17 #define EFI_TIMER_ARCH_PROTOCOL_GUID \
18 { 0x26baccb3, 0x6f42, 0x11d4, {0xbc, 0xe7, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }
19
20 ///
21 /// Declare forward reference for the Timer Architectural Protocol
22 ///
23 typedef struct _EFI_TIMER_ARCH_PROTOCOL EFI_TIMER_ARCH_PROTOCOL;
24
25 /**
26 This function of this type is called when a timer interrupt fires. This
27 function executes at TPL_HIGH_LEVEL. The DXE Core will register a function
28 of this type to be called for the timer interrupt, so it can know how much
29 time has passed. This information is used to signal timer based events.
30
31 @param Time Time since the last timer interrupt in 100 ns units. This will
32 typically be TimerPeriod, but if a timer interrupt is missed, and the
33 EFI_TIMER_ARCH_PROTOCOL driver can detect missed interrupts, then Time
34 will contain the actual amount of time since the last interrupt.
35
36 None.
37
38 **/
39 typedef
40 VOID
41 (EFIAPI *EFI_TIMER_NOTIFY)(
42 IN UINT64 Time
43 );
44
45 /**
46 This function registers the handler NotifyFunction so it is called every time
47 the timer interrupt fires. It also passes the amount of time since the last
48 handler call to the NotifyFunction. If NotifyFunction is NULL, then the
49 handler is unregistered. If the handler is registered, then EFI_SUCCESS is
50 returned. If the CPU does not support registering a timer interrupt handler,
51 then EFI_UNSUPPORTED is returned. If an attempt is made to register a handler
52 when a handler is already registered, then EFI_ALREADY_STARTED is returned.
53 If an attempt is made to unregister a handler when a handler is not registered,
54 then EFI_INVALID_PARAMETER is returned. If an error occurs attempting to
55 register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR
56 is returned.
57
58 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
59 @param NotifyFunction The function to call when a timer interrupt fires. This
60 function executes at TPL_HIGH_LEVEL. The DXE Core will
61 register a handler for the timer interrupt, so it can know
62 how much time has passed. This information is used to
63 signal timer based events. NULL will unregister the handler.
64
65 @retval EFI_SUCCESS The timer handler was registered.
66 @retval EFI_UNSUPPORTED The platform does not support timer interrupts.
67 @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a handler is already
68 registered.
69 @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not
70 previously registered.
71 @retval EFI_DEVICE_ERROR The timer handler could not be registered.
72
73 **/
74 typedef
75 EFI_STATUS
76 (EFIAPI *EFI_TIMER_REGISTER_HANDLER)(
77 IN EFI_TIMER_ARCH_PROTOCOL *This,
78 IN EFI_TIMER_NOTIFY NotifyFunction
79 );
80
81 /**
82 This function adjusts the period of timer interrupts to the value specified
83 by TimerPeriod. If the timer period is updated, then the selected timer
84 period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
85 the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
86 If an error occurs while attempting to update the timer period, then the
87 timer hardware will be put back in its state prior to this call, and
88 EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
89 is disabled. This is not the same as disabling the CPU's interrupts.
90 Instead, it must either turn off the timer hardware, or it must adjust the
91 interrupt controller so that a CPU interrupt is not generated when the timer
92 interrupt fires.
93
94 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
95 @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If
96 the timer hardware is not programmable, then EFI_UNSUPPORTED is
97 returned. If the timer is programmable, then the timer period
98 will be rounded up to the nearest timer period that is supported
99 by the timer hardware. If TimerPeriod is set to 0, then the
100 timer interrupts will be disabled.
101
102 @retval EFI_SUCCESS The timer period was changed.
103 @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.
104 @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
105
106 **/
107 typedef
108 EFI_STATUS
109 (EFIAPI *EFI_TIMER_SET_TIMER_PERIOD)(
110 IN EFI_TIMER_ARCH_PROTOCOL *This,
111 IN UINT64 TimerPeriod
112 );
113
114 /**
115 This function retrieves the period of timer interrupts in 100 ns units,
116 returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod
117 is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is
118 returned, then the timer is currently disabled.
119
120 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
121 @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If
122 0 is returned, then the timer is currently disabled.
123
124 @retval EFI_SUCCESS The timer period was returned in TimerPeriod.
125 @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
126
127 **/
128 typedef
129 EFI_STATUS
130 (EFIAPI *EFI_TIMER_GET_TIMER_PERIOD)(
131 IN EFI_TIMER_ARCH_PROTOCOL *This,
132 OUT UINT64 *TimerPeriod
133 );
134
135 /**
136 This function generates a soft timer interrupt. If the platform does not support soft
137 timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.
138 If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()
139 service, then a soft timer interrupt will be generated. If the timer interrupt is
140 enabled when this service is called, then the registered handler will be invoked. The
141 registered handler should not be able to distinguish a hardware-generated timer
142 interrupt from a software-generated timer interrupt.
143
144 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
145
146 @retval EFI_SUCCESS The soft timer interrupt was generated.
147 @retval EFI_UNSUPPORTED The platform does not support the generation of soft timer interrupts.
148
149 **/
150 typedef
151 EFI_STATUS
152 (EFIAPI *EFI_TIMER_GENERATE_SOFT_INTERRUPT)(
153 IN EFI_TIMER_ARCH_PROTOCOL *This
154 );
155
156
157 ///
158 /// This protocol provides the services to initialize a periodic timer
159 /// interrupt, and to register a handler that is called each time the timer
160 /// interrupt fires. It may also provide a service to adjust the rate of the
161 /// periodic timer interrupt. When a timer interrupt occurs, the handler is
162 /// passed the amount of time that has passed since the previous timer
163 /// interrupt.
164 ///
165 struct _EFI_TIMER_ARCH_PROTOCOL {
166 EFI_TIMER_REGISTER_HANDLER RegisterHandler;
167 EFI_TIMER_SET_TIMER_PERIOD SetTimerPeriod;
168 EFI_TIMER_GET_TIMER_PERIOD GetTimerPeriod;
169 EFI_TIMER_GENERATE_SOFT_INTERRUPT GenerateSoftInterrupt;
170 };
171
172 extern EFI_GUID gEfiTimerArchProtocolGuid;
173
174 #endif