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