Xen Test Framework
hpet.h
Go to the documentation of this file.
1 
9 #ifndef XTF_X86_HPET_H
10 #define XTF_X86_HPET_H
11 
12 #include <xtf/numbers.h>
13 #include <xtf/macro_magic.h>
14 #include <xtf/types.h>
15 
16 #define HPET_ID 0x0
17 #define HPET_ID_MAX_PERIOD 0x05f5e100
18 #define HPET_ID_NUMBER_MASK 0x1f00
19 
20 #define HPET_CFG 0x010
21 #define HPET_CFG_ENABLE 0x001
22 
23 #define HPET_COUNTER 0x0f0
24 
25 #define HPET_Tn_CFG(n) (0x100 + (n) * 0x20)
26 
27 #define HPET_Tn_CMP(n) (0x108 + (n) * 0x20)
28 
29 #define HPET_DEFAULT_BASE 0xfed00000
30 
31 /* Number of available HPET timers. */
32 extern unsigned int hpet_nr_timers;
33 
37 int hpet_init(void);
38 
39 static inline uint32_t hpet_read32(unsigned int reg)
40 {
41  return *(volatile uint32_t *)(_p(HPET_DEFAULT_BASE) + reg);
42 }
43 
44 static inline uint64_t hpet_read64(unsigned int reg)
45 {
46  return *(volatile uint64_t *)(_p(HPET_DEFAULT_BASE) + reg);
47 }
48 
49 static inline void hpet_write32(unsigned int reg, uint32_t val)
50 {
51  *(volatile uint32_t *)(_p(HPET_DEFAULT_BASE) + reg) = val;
52 }
53 
54 static inline void hpet_write64(unsigned int reg, uint64_t val)
55 {
56  *(volatile uint64_t *)(_p(HPET_DEFAULT_BASE) + reg) = val;
57 }
58 
62 static inline uint64_t hpet_read_counter(void)
63 {
64  if ( IS_DEFINED(CONFIG_64BIT) )
65  return hpet_read64(HPET_COUNTER);
66  else
67  {
68  uint32_t lo, hi;
69 
70  do {
71  hi = hpet_read32(HPET_COUNTER + 4);
73  } while ( hi != hpet_read32(HPET_COUNTER + 4) );
74 
75  return ((uint64_t)hi << 32) | lo;
76  }
77 }
78 
82 void hpet_init_timer(unsigned int nr, unsigned int irq, uint64_t ticks,
83  bool level, bool periodic, bool mode32bit);
84 
85 #endif /* !XTF_X86_HPET_H */
86 
87 /*
88  * Local variables:
89  * mode: C
90  * c-file-style: "BSD"
91  * c-basic-offset: 4
92  * tab-width: 4
93  * indent-tabs-mode: nil
94  * End:
95  */
Common declarations for all tests.
Varadic macro helpers - Here be many dragons.
#define IS_DEFINED(x)
Evalute whether the CONFIG_ token x is defined.
Definition: macro_magic.h:67
#define HPET_COUNTER
Definition: hpet.h:23
void hpet_init_timer(unsigned int nr, unsigned int irq, uint64_t ticks, bool level, bool periodic, bool mode32bit)
Setup and enable a specific HPET timer.
Definition: hpet.c:49
static void hpet_write32(unsigned int reg, uint32_t val)
Definition: hpet.h:49
Primatives for number manipulation.
int hpet_init(void)
Discover and initialise the HPET.
Definition: hpet.c:29
unsigned int hpet_nr_timers
Definition: hpet.c:13
static void hpet_write64(unsigned int reg, uint64_t val)
Definition: hpet.h:54
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
static uint32_t hpet_read32(unsigned int reg)
Definition: hpet.h:39
#define _p(v)
Express an abitrary integer v as void *.
Definition: numbers.h:48
static uint64_t hpet_read_counter(void)
Fetch the HPET main counter register.
Definition: hpet.h:62
#define HPET_DEFAULT_BASE
Definition: hpet.h:29
static uint64_t hpet_read64(unsigned int reg)
Definition: hpet.h:44