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