iPXE
acpi_timer.c File Reference

ACPI power management timer. More...

#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/io.h>
#include <ipxe/acpi.h>

Go to the source code of this file.

Macros

#define ACPI_TIMER_HZ   3579545
 ACPI timer frequency (fixed 3.579545MHz)
#define ACPI_TIMER_MASK   0x00ffffffUL
 ACPI timer mask.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
struct timer acpi_timer __timer (TIMER_PREFERRED)
 ACPI timer.
static unsigned long acpi_currticks (void)
 Get current system time in ticks.
static void acpi_udelay (unsigned long usecs)
 Delay for a fixed number of microseconds.
static int acpi_timer_probe (void)
 Probe ACPI power management timer.

Variables

static unsigned int pm_tmr
 Power management timer register address.

Detailed Description

ACPI power management timer.

Definition in file acpi_timer.c.

Macro Definition Documentation

◆ ACPI_TIMER_HZ

#define ACPI_TIMER_HZ   3579545

ACPI timer frequency (fixed 3.579545MHz)

Definition at line 40 of file acpi_timer.c.

Referenced by acpi_currticks(), and acpi_udelay().

◆ ACPI_TIMER_MASK

#define ACPI_TIMER_MASK   0x00ffffffUL

ACPI timer mask.

Timers may be implemented as either 24-bit or 32-bit counters. We simplify the code by pessimistically assuming that the timer has only 24 bits.

Definition at line 48 of file acpi_timer.c.

Referenced by acpi_currticks(), and acpi_udelay().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ __timer()

struct timer acpi_timer __timer ( TIMER_PREFERRED )

ACPI timer.

References __timer, and TIMER_PREFERRED.

◆ acpi_currticks()

unsigned long acpi_currticks ( void )
static

Get current system time in ticks.

Return values
ticksCurrent time, in ticks

Definition at line 60 of file acpi_timer.c.

60 {
61 static unsigned long offset;
62 static uint32_t prev;
63 uint32_t now;
64
65 /* Read timer and account for wraparound */
66 now = ( inl ( pm_tmr ) & ACPI_TIMER_MASK );
67 if ( now < prev ) {
68 offset += ( ( ACPI_TIMER_MASK + 1 ) /
70 }
71 prev = now;
72
73 /* Convert to timer ticks */
74 return ( offset + ( now / ( ACPI_TIMER_HZ / TICKS_PER_SEC ) ) );
75}
#define ACPI_TIMER_MASK
ACPI timer mask.
Definition acpi_timer.c:48
#define ACPI_TIMER_HZ
ACPI timer frequency (fixed 3.579545MHz)
Definition acpi_timer.c:40
static unsigned int pm_tmr
Power management timer register address.
Definition acpi_timer.c:51
unsigned int uint32_t
Definition stdint.h:12
uint16_t offset
Offset to command line.
Definition bzimage.h:3
#define inl(io_addr)
Definition io.h:301
#define TICKS_PER_SEC
Number of ticks per second.
Definition timer.h:16

References ACPI_TIMER_HZ, ACPI_TIMER_MASK, inl, offset, pm_tmr, and TICKS_PER_SEC.

◆ acpi_udelay()

void acpi_udelay ( unsigned long usecs)
static

Delay for a fixed number of microseconds.

Parameters
usecsNumber of microseconds for which to delay

Definition at line 82 of file acpi_timer.c.

82 {
84 uint32_t elapsed;
85 uint32_t threshold;
86
87 /* Delay until a suitable number of ticks have elapsed. We do
88 * not need to allow for multiple wraparound, since the
89 * wraparound period for a 24-bit timer at 3.579545MHz is
90 * around 4700000us.
91 */
92 start = inl ( pm_tmr );
93 threshold = ( ( usecs * ACPI_TIMER_HZ ) / 1000000 );
94 do {
95 elapsed = ( ( inl ( pm_tmr ) - start ) & ACPI_TIMER_MASK );
96 } while ( elapsed < threshold );
97}
uint32_t start
Starting offset.
Definition netvsc.h:1

References ACPI_TIMER_HZ, ACPI_TIMER_MASK, inl, pm_tmr, and start.

◆ acpi_timer_probe()

int acpi_timer_probe ( void )
static

Probe ACPI power management timer.

Return values
rcReturn status code

Definition at line 104 of file acpi_timer.c.

104 {
105 const struct acpi_fadt *fadt;
106 unsigned int pm_tmr_blk;
107
108 /* Locate FADT */
109 fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ),
110 struct acpi_fadt, acpi );
111 if ( ! fadt ) {
112 DBGC ( &acpi_timer, "ACPI could not find FADT\n" );
113 return -ENOENT;
114 }
115
116 /* Read FADT */
118 if ( ! pm_tmr_blk ) {
119 DBGC ( &acpi_timer, "ACPI has no timer\n" );
120 return -ENOENT;
121 }
122
123 /* Record power management timer register address */
125
126 return 0;
127}
const struct acpi_header * acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition acpi.c:93
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition efi_block.c:67
#define DBGC(...)
Definition compiler.h:505
#define ENOENT
No such file or directory.
Definition errno.h:515
#define le32_to_cpu(value)
Definition byteswap.h:114
#define ACPI_PM_TMR
ACPI PM Timer Register (within PM_TMR_BLK)
Definition acpi.h:286
#define FADT_SIGNATURE
Fixed ACPI Description Table (FADT) signature.
Definition acpi.h:258
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
Fixed ACPI Description Table (FADT)
Definition acpi.h:261
uint32_t pm_tmr_blk
PM Timer Control Register Block.
Definition acpi.h:277

References acpi, ACPI_PM_TMR, acpi_table(), container_of, DBGC, ENOENT, FADT_SIGNATURE, le32_to_cpu, pm_tmr, and acpi_fadt::pm_tmr_blk.

Variable Documentation

◆ pm_tmr

unsigned int pm_tmr
static

Power management timer register address.

Definition at line 51 of file acpi_timer.c.

Referenced by acpi_currticks(), acpi_timer_probe(), and acpi_udelay().