]>
Commit | Line | Data |
---|---|---|
18c97f53 | 1 | /** @file\r |
2 | Private data structures\r | |
eb16e240 | 3 | \r |
76cd9a03 | 4 | Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r |
18c97f53 | 5 | This program and the accompanying materials \r |
eb16e240 | 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 | |
18c97f53 | 12 | **/\r |
eb16e240 | 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 | |
eb16e240 | 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 | |
2952f72d | 26 | #include <Library/IoLib.h>\r |
eb16e240 | 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 | |
76cd9a03 | 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 | |
2952f72d | 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 | |
eb16e240 | 46 | #define TIMER_CONTROL_PORT 0x43\r |
47 | #define TIMER0_COUNT_PORT 0x40\r | |
48 | \r | |
49 | //\r | |
50 | // Function Prototypes\r | |
51 | //\r | |
18c97f53 | 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 | |
eb16e240 | 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 | |
eb16e240 | 69 | ;\r |
70 | \r | |
18c97f53 | 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 | |
24115e44 | 87 | @param NotifyFunction The rate to program the timer interrupt in 100 nS units. If\r |
18c97f53 | 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 | |
eb16e240 | 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 | |
eb16e240 | 105 | ;\r |
106 | \r | |
18c97f53 | 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 | |
eb16e240 | 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 | |
18c97f53 | 141 | ;\r |
eb16e240 | 142 | \r |
18c97f53 | 143 | /**\r |
eb16e240 | 144 | \r |
18c97f53 | 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 | |
eb16e240 | 149 | \r |
eb16e240 | 150 | \r |
18c97f53 | 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 | |
eb16e240 | 154 | \r |
18c97f53 | 155 | @retval EFI_SUCCESS The timer period was returned in TimerPeriod.\r |
156 | @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.\r | |
eb16e240 | 157 | \r |
18c97f53 | 158 | **/\r |
eb16e240 | 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 | |
18c97f53 | 165 | ;\r |
eb16e240 | 166 | \r |
18c97f53 | 167 | /**\r |
eb16e240 | 168 | \r |
18c97f53 | 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 | |
eb16e240 | 176 | \r |
eb16e240 | 177 | \r |
18c97f53 | 178 | @param This The EFI_TIMER_ARCH_PROTOCOL instance.\r |
eb16e240 | 179 | \r |
18c97f53 | 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 | |
eb16e240 | 182 | \r |
18c97f53 | 183 | **/\r |
eb16e240 | 184 | EFI_STATUS\r |
185 | EFIAPI\r | |
186 | TimerDriverGenerateSoftInterrupt (\r | |
187 | IN EFI_TIMER_ARCH_PROTOCOL *This\r | |
188 | )\r | |
eb16e240 | 189 | ;\r |
190 | \r | |
191 | #endif\r |