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