2 Private data structures
4 Copyright (c) 2005 - 2012, 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
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.
19 #include <Protocol/Cpu.h>
20 #include <Protocol/Legacy8259.h>
21 #include <Protocol/Timer.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/BaseLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/IoLib.h>
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.
34 // ---------------- * 1,000,000 uS/S = 54925.4 uS = 549254 * 100 ns
39 // The maximum tick duration for 8254 timer
41 #define MAX_TIMER_TICK_DURATION 549254
43 // The default timer tick duration is set to 10 ms = 100000 100 ns units
45 #define DEFAULT_TIMER_TICK_DURATION 100000
46 #define TIMER_CONTROL_PORT 0x43
47 #define TIMER0_COUNT_PORT 0x40
50 // Function Prototypes
53 Initialize the Timer Architectural Protocol driver
55 @param ImageHandle ImageHandle of the loaded driver
56 @param SystemTable Pointer to the System Table
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 occured attempting to initialize the driver.
65 TimerDriverInitialize (
66 IN EFI_HANDLE ImageHandle
,
67 IN EFI_SYSTEM_TABLE
*SystemTable
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
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.
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.
101 TimerDriverRegisterHandler (
102 IN EFI_TIMER_ARCH_PROTOCOL
*This
,
103 IN EFI_TIMER_NOTIFY NotifyFunction
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
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.
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.
137 TimerDriverSetTimerPeriod (
138 IN EFI_TIMER_ARCH_PROTOCOL
*This
,
139 IN UINT64 TimerPeriod
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.
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.
155 @retval EFI_SUCCESS The timer period was returned in TimerPeriod.
156 @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
161 TimerDriverGetTimerPeriod (
162 IN EFI_TIMER_ARCH_PROTOCOL
*This
,
163 OUT UINT64
*TimerPeriod
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.
178 @param This The EFI_TIMER_ARCH_PROTOCOL instance.
180 @retval EFI_SUCCESS The soft timer interrupt was generated.
181 @retval EFI_UNSUPPORTEDT The platform does not support the generation of soft timer interrupts.
186 TimerDriverGenerateSoftInterrupt (
187 IN EFI_TIMER_ARCH_PROTOCOL
*This