iPXE
Macros | Functions | Variables
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) More...
 
#define ACPI_TIMER_MASK   0x00ffffffUL
 ACPI timer mask. More...
 

Functions

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

Variables

static unsigned int pm_tmr
 Power management timer register address. More...
 

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.

◆ 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.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __timer()

struct timer acpi_timer __timer ( TIMER_PREFERRED  )

ACPI timer.

◆ acpi_currticks()

static 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 TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
#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
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define ACPI_TIMER_MASK
ACPI timer mask.
Definition: acpi_timer.c:48
unsigned int uint32_t
Definition: stdint.h:12
uint32_t inl(volatile uint32_t *io_addr)
Read 32-bit dword from I/O-mapped device.

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

◆ acpi_udelay()

static 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 }
#define ACPI_TIMER_HZ
ACPI timer frequency (fixed 3.579545MHz)
Definition: acpi_timer.c:40
uint32_t start
Starting offset.
Definition: netvsc.h:12
static unsigned int pm_tmr
Power management timer register address.
Definition: acpi_timer.c:51
#define ACPI_TIMER_MASK
ACPI timer mask.
Definition: acpi_timer.c:48
unsigned int uint32_t
Definition: stdint.h:12
uint32_t inl(volatile uint32_t *io_addr)
Read 32-bit dword from I/O-mapped device.

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

◆ acpi_timer_probe()

static 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  struct acpi_fadt fadtab;
106  userptr_t fadt;
107  unsigned int pm_tmr_blk;
108 
109  /* Locate FADT */
110  fadt = acpi_table ( FADT_SIGNATURE, 0 );
111  if ( ! fadt ) {
112  DBGC ( &acpi_timer, "ACPI could not find FADT\n" );
113  return -ENOENT;
114  }
115 
116  /* Read FADT */
117  copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) );
118  pm_tmr_blk = le32_to_cpu ( fadtab.pm_tmr_blk );
119  if ( ! pm_tmr_blk ) {
120  DBGC ( &acpi_timer, "ACPI has no timer\n" );
121  return -ENOENT;
122  }
123 
124  /* Record power management timer register address */
125  pm_tmr = ( pm_tmr_blk + ACPI_PM_TMR );
126 
127  return 0;
128 }
#define le32_to_cpu(value)
Definition: byteswap.h:113
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
#define DBGC(...)
Definition: compiler.h:505
userptr_t acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition: acpi.c:98
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define ACPI_PM_TMR
ACPI PM Timer Register (within PM_TMR_BLK)
Definition: acpi.h:269
uint32_t pm_tmr_blk
PM Timer Control Register Block.
Definition: acpi.h:260
Fixed ACPI Description Table (FADT)
Definition: acpi.h:244
static unsigned int pm_tmr
Power management timer register address.
Definition: acpi_timer.c:51
#define FADT_SIGNATURE
Fixed ACPI Description Table (FADT) signature.
Definition: acpi.h:241
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References ACPI_PM_TMR, acpi_table(), copy_from_user(), 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().