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