#include <limits.h>
#include <assert.h>
#include <unistd.h>
#include <gpxe/timer.h>
#include <gpxe/efi/efi.h>
#include <gpxe/efi/Protocol/Cpu.h>
Go to the source code of this file.
Defines | |
| #define | EFI_TIMER0_SHIFT 12 |
| Scale factor to apply to CPU timer 0. | |
| #define | EFI_CALIBRATE_DELAY_MS 1 |
| Calibration time. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| EFI_REQUIRE_PROTOCOL (EFI_CPU_ARCH_PROTOCOL,&cpu_arch) | |
| static void | efi_udelay (unsigned long usecs) |
| Delay for a fixed number of microseconds. | |
| static unsigned long | efi_currticks (void) |
| Get current system time in ticks. | |
| static unsigned long | efi_ticks_per_sec (void) |
| Get number of ticks per second. | |
| PROVIDE_TIMER (efi, udelay, efi_udelay) | |
| PROVIDE_TIMER (efi, currticks, efi_currticks) | |
| PROVIDE_TIMER (efi, ticks_per_sec, efi_ticks_per_sec) | |
Variables | |
| static EFI_CPU_ARCH_PROTOCOL * | cpu_arch |
| CPU protocol. | |
Definition in file efi_timer.c.
| #define EFI_TIMER0_SHIFT 12 |
Scale factor to apply to CPU timer 0.
The timer is scaled down in order to ensure that reasonable values for "number of ticks" don't exceed the size of an unsigned long.
Definition at line 39 of file efi_timer.c.
Referenced by efi_currticks().
| #define EFI_CALIBRATE_DELAY_MS 1 |
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| EFI_REQUIRE_PROTOCOL | ( | EFI_CPU_ARCH_PROTOCOL | , | |
| & | cpu_arch | |||
| ) |
| static void efi_udelay | ( | unsigned long | usecs | ) | [static] |
Delay for a fixed number of microseconds.
| usecs | Number of microseconds for which to delay |
Definition at line 53 of file efi_timer.c.
References _EFI_SYSTEM_TABLE::BootServices, DBG, efi_strerror(), efi_systab, and EFI_BOOT_SERVICES::Stall.
00053 { 00054 EFI_BOOT_SERVICES *bs = efi_systab->BootServices; 00055 EFI_STATUS efirc; 00056 00057 if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) { 00058 DBG ( "EFI could not delay for %ldus: %s\n", 00059 usecs, efi_strerror ( efirc ) ); 00060 /* Probably screwed */ 00061 } 00062 }
| static unsigned long efi_currticks | ( | void | ) | [static] |
Get current system time in ticks.
| ticks | Current time, in ticks |
Definition at line 69 of file efi_timer.c.
References DBG, efi_strerror(), EFI_TIMER0_SHIFT, _EFI_CPU_ARCH_PROTOCOL::GetTimerValue, NULL, and time().
00069 { 00070 UINT64 time; 00071 EFI_STATUS efirc; 00072 00073 /* Read CPU timer 0 (TSC) */ 00074 if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time, 00075 NULL ) ) != 0 ) { 00076 DBG ( "EFI could not read CPU timer: %s\n", 00077 efi_strerror ( efirc ) ); 00078 /* Probably screwed */ 00079 return -1UL; 00080 } 00081 00082 return ( time >> EFI_TIMER0_SHIFT ); 00083 }
| static unsigned long efi_ticks_per_sec | ( | void | ) | [static] |
Get number of ticks per second.
| ticks_per_sec | Number of ticks per second |
Definition at line 90 of file efi_timer.c.
References currticks(), DBG, EFI_CALIBRATE_DELAY_MS, mdelay(), and ticks_per_sec().
00090 { 00091 static unsigned long ticks_per_sec = 0; 00092 00093 /* Calibrate timer, if necessary. EFI does nominally provide 00094 * the timer speed via the (optional) TimerPeriod parameter to 00095 * the GetTimerValue() call, but it gets the speed slightly 00096 * wrong. By up to three orders of magnitude. Not helpful. 00097 */ 00098 if ( ! ticks_per_sec ) { 00099 unsigned long start; 00100 unsigned long elapsed; 00101 00102 DBG ( "Calibrating EFI timer with a %d ms delay\n", 00103 EFI_CALIBRATE_DELAY_MS ); 00104 start = currticks(); 00105 mdelay ( EFI_CALIBRATE_DELAY_MS ); 00106 elapsed = ( currticks() - start ); 00107 ticks_per_sec = ( elapsed * ( 1000 / EFI_CALIBRATE_DELAY_MS )); 00108 DBG ( "EFI CPU timer calibrated at %ld ticks in %d ms (%ld " 00109 "ticks/sec)\n", elapsed, EFI_CALIBRATE_DELAY_MS, 00110 ticks_per_sec ); 00111 } 00112 00113 return ticks_per_sec; 00114 }
| PROVIDE_TIMER | ( | efi | , | |
| udelay | , | |||
| efi_udelay | ||||
| ) |
| PROVIDE_TIMER | ( | efi | , | |
| currticks | , | |||
| efi_currticks | ||||
| ) |
| PROVIDE_TIMER | ( | efi | , | |
| ticks_per_sec | , | |||
| efi_ticks_per_sec | ||||
| ) |
EFI_CPU_ARCH_PROTOCOL* cpu_arch [static] |
1.5.7.1