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