]> git.proxmox.com Git - mirror_edk2.git/blob - PcAtChipsetPkg/8254TimerDxe/Timer.h
8254TimerDxe: DuetPkg => PcAtChipsetPkg
[mirror_edk2.git] / PcAtChipsetPkg / 8254TimerDxe / Timer.h
1 /*++
2
3 Copyright (c) 2005 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 Timer.h
16
17 Abstract:
18
19 Private data structures
20
21 --*/
22
23 #ifndef _TIMER_H_
24 #define _TIMER_H_
25
26 #include <PiDxe.h>
27
28 #include <Protocol/Cpu.h>
29 #include <Protocol/Legacy8259.h>
30 #include <Protocol/Timer.h>
31
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/BaseLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/IoLib.h>
36
37 //
38 // The PCAT 8253/8254 has an input clock at 1.193182 MHz and Timer 0 is
39 // initialized as a 16 bit free running counter that generates an interrupt(IRQ0)
40 // each time the counter rolls over.
41 //
42 // 65536 counts
43 // ---------------- * 1,000,000 uS/S = 54925.4 uS = 549254 * 100 ns
44 // 1,193,182 Hz
45 //
46 // The default timer tick duration is set to 10 ms = 100000 100 ns units
47 //
48 #define DEFAULT_TIMER_TICK_DURATION 100000
49 #define TIMER_CONTROL_PORT 0x43
50 #define TIMER0_COUNT_PORT 0x40
51
52 //
53 // Function Prototypes
54 //
55 EFI_STATUS
56 EFIAPI
57 TimerDriverInitialize (
58 IN EFI_HANDLE ImageHandle,
59 IN EFI_SYSTEM_TABLE *SystemTable
60 )
61 /*++
62
63 Routine Description:
64
65 Initialize the Timer Architectural Protocol driver
66
67 Arguments:
68
69 ImageHandle - ImageHandle of the loaded driver
70
71 SystemTable - Pointer to the System Table
72
73 Returns:
74
75 EFI_SUCCESS - Timer Architectural Protocol created
76
77 EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.
78
79 EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.
80
81 --*/
82 ;
83
84 EFI_STATUS
85 EFIAPI
86 TimerDriverRegisterHandler (
87 IN EFI_TIMER_ARCH_PROTOCOL *This,
88 IN EFI_TIMER_NOTIFY NotifyFunction
89 )
90 /*++
91
92 Routine Description:
93
94 This function registers the handler NotifyFunction so it is called every time
95 the timer interrupt fires. It also passes the amount of time since the last
96 handler call to the NotifyFunction. If NotifyFunction is NULL, then the
97 handler is unregistered. If the handler is registered, then EFI_SUCCESS is
98 returned. If the CPU does not support registering a timer interrupt handler,
99 then EFI_UNSUPPORTED is returned. If an attempt is made to register a handler
100 when a handler is already registered, then EFI_ALREADY_STARTED is returned.
101 If an attempt is made to unregister a handler when a handler is not registered,
102 then EFI_INVALID_PARAMETER is returned. If an error occurs attempting to
103 register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR
104 is returned.
105
106 Arguments:
107
108 This - The EFI_TIMER_ARCH_PROTOCOL instance.
109
110 NotifyFunction - The function to call when a timer interrupt fires. This
111 function executes at TPL_HIGH_LEVEL. The DXE Core will
112 register a handler for the timer interrupt, so it can know
113 how much time has passed. This information is used to
114 signal timer based events. NULL will unregister the handler.
115
116 Returns:
117
118 EFI_SUCCESS - The timer handler was registered.
119
120 EFI_UNSUPPORTED - The platform does not support timer interrupts.
121
122 EFI_ALREADY_STARTED - NotifyFunction is not NULL, and a handler is already
123 registered.
124
125 EFI_INVALID_PARAMETER - NotifyFunction is NULL, and a handler was not
126 previously registered.
127
128 EFI_DEVICE_ERROR - The timer handler could not be registered.
129
130 --*/
131 ;
132
133 EFI_STATUS
134 EFIAPI
135 TimerDriverSetTimerPeriod (
136 IN EFI_TIMER_ARCH_PROTOCOL *This,
137 IN UINT64 TimerPeriod
138 )
139 /*++
140
141 Routine Description:
142
143 This function adjusts the period of timer interrupts to the value specified
144 by TimerPeriod. If the timer period is updated, then the selected timer
145 period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
146 the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
147 If an error occurs while attempting to update the timer period, then the
148 timer hardware will be put back in its state prior to this call, and
149 EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
150 is disabled. This is not the same as disabling the CPU's interrupts.
151 Instead, it must either turn off the timer hardware, or it must adjust the
152 interrupt controller so that a CPU interrupt is not generated when the timer
153 interrupt fires.
154
155 Arguments:
156
157 This - The EFI_TIMER_ARCH_PROTOCOL instance.
158
159 TimerPeriod - The rate to program the timer interrupt in 100 nS units. If
160 the timer hardware is not programmable, then EFI_UNSUPPORTED is
161 returned. If the timer is programmable, then the timer period
162 will be rounded up to the nearest timer period that is supported
163 by the timer hardware. If TimerPeriod is set to 0, then the
164 timer interrupts will be disabled.
165
166 Returns:
167
168 EFI_SUCCESS - The timer period was changed.
169
170 EFI_UNSUPPORTED - The platform cannot change the period of the timer interrupt.
171
172 EFI_DEVICE_ERROR - The timer period could not be changed due to a device error.
173
174 --*/
175 ;
176
177 EFI_STATUS
178 EFIAPI
179 TimerDriverGetTimerPeriod (
180 IN EFI_TIMER_ARCH_PROTOCOL *This,
181 OUT UINT64 *TimerPeriod
182 )
183 /*++
184
185 Routine Description:
186
187 This function retrieves the period of timer interrupts in 100 ns units,
188 returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod
189 is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is
190 returned, then the timer is currently disabled.
191
192 Arguments:
193
194 This - The EFI_TIMER_ARCH_PROTOCOL instance.
195
196 TimerPeriod - A pointer to the timer period to retrieve in 100 ns units. If
197 0 is returned, then the timer is currently disabled.
198
199 Returns:
200
201 EFI_SUCCESS - The timer period was returned in TimerPeriod.
202
203 EFI_INVALID_PARAMETER - TimerPeriod is NULL.
204
205 --*/
206 ;
207
208 EFI_STATUS
209 EFIAPI
210 TimerDriverGenerateSoftInterrupt (
211 IN EFI_TIMER_ARCH_PROTOCOL *This
212 )
213 /*++
214
215 Routine Description:
216
217 This function generates a soft timer interrupt. If the platform does not support soft
218 timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.
219 If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()
220 service, then a soft timer interrupt will be generated. If the timer interrupt is
221 enabled when this service is called, then the registered handler will be invoked. The
222 registered handler should not be able to distinguish a hardware-generated timer
223 interrupt from a software-generated timer interrupt.
224
225 Arguments:
226
227 This - The EFI_TIMER_ARCH_PROTOCOL instance.
228
229 Returns:
230
231 EFI_SUCCESS - The soft timer interrupt was generated.
232
233 EFI_UNSUPPORTEDT - The platform does not support the generation of soft timer interrupts.
234
235 --*/
236 ;
237
238 #endif