]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/8254TimerDxe/Timer.h
Add 8254 module and fix the hob operation for R9 library.
[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
29#include <Protocol/CpuIo.h>\r
30#include <Protocol/Legacy8259.h>\r
31#include <Protocol/Timer.h>\r
32\r
33#include <Library/UefiBootServicesTableLib.h>\r
34#include <Library/BaseLib.h>\r
35#include <Library/DebugLib.h>\r
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
46#define DEFAULT_TIMER_TICK_DURATION 549254\r
47#define TIMER_CONTROL_PORT 0x43\r
48#define TIMER0_COUNT_PORT 0x40\r
49\r
50//\r
51// Function Prototypes\r
52//\r
53EFI_STATUS\r
54EFIAPI\r
55TimerDriverInitialize (\r
56 IN EFI_HANDLE ImageHandle,\r
57 IN EFI_SYSTEM_TABLE *SystemTable\r
58 )\r
59/*++\r
60\r
61Routine Description:\r
62\r
63 Initialize the Timer Architectural Protocol driver\r
64\r
65Arguments:\r
66\r
67 ImageHandle - ImageHandle of the loaded driver\r
68\r
69 SystemTable - Pointer to the System Table\r
70\r
71Returns:\r
72\r
73 EFI_SUCCESS - Timer Architectural Protocol created\r
74\r
75 EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.\r
76 \r
77 EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.\r
78\r
79--*/\r
80;\r
81\r
82EFI_STATUS\r
83EFIAPI\r
84TimerDriverRegisterHandler (\r
85 IN EFI_TIMER_ARCH_PROTOCOL *This,\r
86 IN EFI_TIMER_NOTIFY NotifyFunction\r
87 )\r
88/*++\r
89\r
90Routine Description:\r
91\r
92 This function registers the handler NotifyFunction so it is called every time \r
93 the timer interrupt fires. It also passes the amount of time since the last \r
94 handler call to the NotifyFunction. If NotifyFunction is NULL, then the \r
95 handler is unregistered. If the handler is registered, then EFI_SUCCESS is \r
96 returned. If the CPU does not support registering a timer interrupt handler, \r
97 then EFI_UNSUPPORTED is returned. If an attempt is made to register a handler \r
98 when a handler is already registered, then EFI_ALREADY_STARTED is returned. \r
99 If an attempt is made to unregister a handler when a handler is not registered, \r
100 then EFI_INVALID_PARAMETER is returned. If an error occurs attempting to \r
101 register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR \r
102 is returned.\r
103\r
104Arguments:\r
105\r
106 This - The EFI_TIMER_ARCH_PROTOCOL instance.\r
107\r
108 NotifyFunction - The function to call when a timer interrupt fires. This \r
109 function executes at TPL_HIGH_LEVEL. The DXE Core will \r
110 register a handler for the timer interrupt, so it can know \r
111 how much time has passed. This information is used to \r
112 signal timer based events. NULL will unregister the handler.\r
113\r
114Returns: \r
115\r
116 EFI_SUCCESS - The timer handler was registered.\r
117\r
118 EFI_UNSUPPORTED - The platform does not support timer interrupts.\r
119\r
120 EFI_ALREADY_STARTED - NotifyFunction is not NULL, and a handler is already \r
121 registered.\r
122\r
123 EFI_INVALID_PARAMETER - NotifyFunction is NULL, and a handler was not \r
124 previously registered.\r
125\r
126 EFI_DEVICE_ERROR - The timer handler could not be registered.\r
127\r
128--*/\r
129;\r
130\r
131EFI_STATUS\r
132EFIAPI\r
133TimerDriverSetTimerPeriod (\r
134 IN EFI_TIMER_ARCH_PROTOCOL *This,\r
135 IN UINT64 TimerPeriod\r
136 )\r
137/*++\r
138\r
139Routine Description:\r
140\r
141 This function adjusts the period of timer interrupts to the value specified \r
142 by TimerPeriod. If the timer period is updated, then the selected timer \r
143 period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If \r
144 the timer hardware is not programmable, then EFI_UNSUPPORTED is returned. \r
145 If an error occurs while attempting to update the timer period, then the \r
146 timer hardware will be put back in its state prior to this call, and \r
147 EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt \r
148 is disabled. This is not the same as disabling the CPU's interrupts. \r
149 Instead, it must either turn off the timer hardware, or it must adjust the \r
150 interrupt controller so that a CPU interrupt is not generated when the timer \r
151 interrupt fires. \r
152\r
153Arguments:\r
154\r
155 This - The EFI_TIMER_ARCH_PROTOCOL instance.\r
156\r
157 TimerPeriod - The rate to program the timer interrupt in 100 nS units. If \r
158 the timer hardware is not programmable, then EFI_UNSUPPORTED is \r
159 returned. If the timer is programmable, then the timer period \r
160 will be rounded up to the nearest timer period that is supported \r
161 by the timer hardware. If TimerPeriod is set to 0, then the \r
162 timer interrupts will be disabled.\r
163\r
164Returns: \r
165\r
166 EFI_SUCCESS - The timer period was changed.\r
167\r
168 EFI_UNSUPPORTED - The platform cannot change the period of the timer interrupt.\r
169\r
170 EFI_DEVICE_ERROR - The timer period could not be changed due to a device error.\r
171\r
172--*/\r
173;\r
174\r
175EFI_STATUS\r
176EFIAPI\r
177TimerDriverGetTimerPeriod (\r
178 IN EFI_TIMER_ARCH_PROTOCOL *This,\r
179 OUT UINT64 *TimerPeriod\r
180 )\r
181/*++\r
182\r
183Routine Description:\r
184\r
185 This function retrieves the period of timer interrupts in 100 ns units, \r
186 returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod \r
187 is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is \r
188 returned, then the timer is currently disabled.\r
189\r
190Arguments:\r
191\r
192 This - The EFI_TIMER_ARCH_PROTOCOL instance.\r
193\r
194 TimerPeriod - A pointer to the timer period to retrieve in 100 ns units. If \r
195 0 is returned, then the timer is currently disabled.\r
196\r
197Returns: \r
198\r
199 EFI_SUCCESS - The timer period was returned in TimerPeriod.\r
200\r
201 EFI_INVALID_PARAMETER - TimerPeriod is NULL.\r
202\r
203--*/\r
204;\r
205\r
206EFI_STATUS\r
207EFIAPI\r
208TimerDriverGenerateSoftInterrupt (\r
209 IN EFI_TIMER_ARCH_PROTOCOL *This\r
210 )\r
211/*++\r
212\r
213Routine Description:\r
214\r
215 This function generates a soft timer interrupt. If the platform does not support soft \r
216 timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned. \r
217 If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler() \r
218 service, then a soft timer interrupt will be generated. If the timer interrupt is \r
219 enabled when this service is called, then the registered handler will be invoked. The \r
220 registered handler should not be able to distinguish a hardware-generated timer \r
221 interrupt from a software-generated timer interrupt.\r
222\r
223Arguments:\r
224\r
225 This - The EFI_TIMER_ARCH_PROTOCOL instance.\r
226\r
227Returns: \r
228\r
229 EFI_SUCCESS - The soft timer interrupt was generated.\r
230\r
231 EFI_UNSUPPORTEDT - The platform does not support the generation of soft timer interrupts.\r
232\r
233--*/\r
234;\r
235\r
236#endif\r