]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/8254TimerDxe/Timer.h
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / 8254TimerDxe / Timer.h
CommitLineData
1a3ffdff
HW
1/** @file\r
2 Private data structures\r
3\r
4Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6**/\r
7\r
8#ifndef _TIMER_H_\r
9#define _TIMER_H_\r
10\r
11#include <PiDxe.h>\r
12\r
13#include <Protocol/Cpu.h>\r
14#include <Protocol/Legacy8259.h>\r
15#include <Protocol/Timer.h>\r
16\r
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Library/BaseLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/IoLib.h>\r
21\r
22//\r
23// The PCAT 8253/8254 has an input clock at 1.193182 MHz and Timer 0 is\r
24// initialized as a 16 bit free running counter that generates an interrupt(IRQ0)\r
25// each time the counter rolls over.\r
26//\r
27// 65536 counts\r
28// ---------------- * 1,000,000 uS/S = 54925.4 uS = 549254 * 100 ns\r
29// 1,193,182 Hz\r
30//\r
31\r
32//\r
33// The maximum tick duration for 8254 timer\r
34//\r
ac0a286f 35#define MAX_TIMER_TICK_DURATION 549254\r
1a3ffdff
HW
36//\r
37// The default timer tick duration is set to 10 ms = 100000 100 ns units\r
38//\r
ac0a286f
MK
39#define DEFAULT_TIMER_TICK_DURATION 100000\r
40#define TIMER_CONTROL_PORT 0x43\r
41#define TIMER0_COUNT_PORT 0x40\r
1a3ffdff
HW
42\r
43//\r
44// Function Prototypes\r
45//\r
ac0a286f 46\r
1a3ffdff
HW
47/**\r
48 Initialize the Timer Architectural Protocol driver\r
49\r
50 @param ImageHandle ImageHandle of the loaded driver\r
51 @param SystemTable Pointer to the System Table\r
52\r
53 @retval EFI_SUCCESS Timer Architectural Protocol created\r
54 @retval EFI_OUT_OF_RESOURCES Not enough resources available to initialize driver.\r
55 @retval EFI_DEVICE_ERROR A device error occurred attempting to initialize the driver.\r
56\r
57**/\r
58EFI_STATUS\r
59EFIAPI\r
60TimerDriverInitialize (\r
61 IN EFI_HANDLE ImageHandle,\r
62 IN EFI_SYSTEM_TABLE *SystemTable\r
63 )\r
64;\r
65\r
66/**\r
67\r
68 This function adjusts the period of timer interrupts to the value specified\r
69 by TimerPeriod. If the timer period is updated, then the selected timer\r
70 period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If\r
71 the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.\r
72 If an error occurs while attempting to update the timer period, then the\r
73 timer hardware will be put back in its state prior to this call, and\r
74 EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt\r
75 is disabled. This is not the same as disabling the CPU's interrupts.\r
76 Instead, it must either turn off the timer hardware, or it must adjust the\r
77 interrupt controller so that a CPU interrupt is not generated when the timer\r
78 interrupt fires.\r
79\r
80\r
81 @param This The EFI_TIMER_ARCH_PROTOCOL instance.\r
82 @param NotifyFunction The rate to program the timer interrupt in 100 nS units. If\r
83 the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
84 returned. If the timer is programmable, then the timer period\r
85 will be rounded up to the nearest timer period that is supported\r
86 by the timer hardware. If TimerPeriod is set to 0, then the\r
87 timer interrupts will be disabled.\r
88\r
89 @retval EFI_SUCCESS The timer period was changed.\r
90 @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.\r
91 @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.\r
92\r
93**/\r
94EFI_STATUS\r
95EFIAPI\r
96TimerDriverRegisterHandler (\r
97 IN EFI_TIMER_ARCH_PROTOCOL *This,\r
98 IN EFI_TIMER_NOTIFY NotifyFunction\r
99 )\r
100;\r
101\r
102/**\r
103\r
104 This function adjusts the period of timer interrupts to the value specified\r
105 by TimerPeriod. If the timer period is updated, then the selected timer\r
106 period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If\r
107 the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.\r
108 If an error occurs while attempting to update the timer period, then the\r
109 timer hardware will be put back in its state prior to this call, and\r
110 EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt\r
111 is disabled. This is not the same as disabling the CPU's interrupts.\r
112 Instead, it must either turn off the timer hardware, or it must adjust the\r
113 interrupt controller so that a CPU interrupt is not generated when the timer\r
114 interrupt fires.\r
115\r
116\r
117 @param This The EFI_TIMER_ARCH_PROTOCOL instance.\r
118 @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If\r
119 the timer hardware is not programmable, then EFI_UNSUPPORTED is\r
120 returned. If the timer is programmable, then the timer period\r
121 will be rounded up to the nearest timer period that is supported\r
122 by the timer hardware. If TimerPeriod is set to 0, then the\r
123 timer interrupts will be disabled.\r
124\r
125 @retval EFI_SUCCESS The timer period was changed.\r
126 @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.\r
127 @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.\r
128\r
129**/\r
130EFI_STATUS\r
131EFIAPI\r
132TimerDriverSetTimerPeriod (\r
133 IN EFI_TIMER_ARCH_PROTOCOL *This,\r
134 IN UINT64 TimerPeriod\r
135 )\r
136;\r
137\r
138/**\r
139\r
140 This function retrieves the period of timer interrupts in 100 ns units,\r
141 returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod\r
142 is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is\r
143 returned, then the timer is currently disabled.\r
144\r
145\r
146 @param This The EFI_TIMER_ARCH_PROTOCOL instance.\r
147 @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If\r
148 0 is returned, then the timer is currently disabled.\r
149\r
150 @retval EFI_SUCCESS The timer period was returned in TimerPeriod.\r
151 @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r
152\r
153**/\r
154EFI_STATUS\r
155EFIAPI\r
156TimerDriverGetTimerPeriod (\r
ac0a286f
MK
157 IN EFI_TIMER_ARCH_PROTOCOL *This,\r
158 OUT UINT64 *TimerPeriod\r
1a3ffdff
HW
159 )\r
160;\r
161\r
162/**\r
163\r
164 This function generates a soft timer interrupt. If the platform does not support soft\r
165 timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.\r
166 If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()\r
167 service, then a soft timer interrupt will be generated. If the timer interrupt is\r
168 enabled when this service is called, then the registered handler will be invoked. The\r
169 registered handler should not be able to distinguish a hardware-generated timer\r
170 interrupt from a software-generated timer interrupt.\r
171\r
172\r
173 @param This The EFI_TIMER_ARCH_PROTOCOL instance.\r
174\r
175 @retval EFI_SUCCESS The soft timer interrupt was generated.\r
176 @retval EFI_UNSUPPORTED The platform does not support the generation of soft timer interrupts.\r
177\r
178**/\r
179EFI_STATUS\r
180EFIAPI\r
181TimerDriverGenerateSoftInterrupt (\r
182 IN EFI_TIMER_ARCH_PROTOCOL *This\r
183 )\r
184;\r
185\r
186#endif\r