Xen Test Framework
hpet.c
Go to the documentation of this file.
1 
7 #include <xtf/lib.h>
8 
9 #include <xen/errno.h>
10 
11 #include <arch/hpet.h>
12 
13 unsigned int hpet_nr_timers;
14 
15 union hpet_timer {
17  struct {
18  uint8_t :1;
19  bool level :1;
20  bool enabled :1;
21  bool periodic :1;
22  uint8_t :4;
23  bool mode_32bit :1;
25  uint32_t :18;
26  };
27 };
28 
29 int hpet_init(void)
30 {
32 
33  /* Bare MMIO? */
34  if ( id == ~0ull )
35  return -ENODEV;
36 
37  uint32_t period = id >> 32;
38 
39  /* Sanity check main counter tick period. */
40  if ( period == 0 || period > HPET_ID_MAX_PERIOD )
41  return -ENODEV;
42 
43  /* Get number of timers. */
45 
46  return 0;
47 }
48 
49 void hpet_init_timer(unsigned int nr, unsigned int irq, uint64_t ticks,
50  bool level, bool periodic, bool mode32bit)
51 {
52  uint64_t cfg;
53  union hpet_timer tm = {};
54 
55  tm.level = level;
56  tm.enabled = true;
57  tm.periodic = periodic;
58  tm.mode_32bit = mode32bit;
59  tm.irq = irq;
60 
61  /*
62  * Disable interrupts and reset main counter.
63  *
64  * Note that this is a testing HPET implementation and ATM we only expect
65  * a single timer to be tested simultaneously.
66  */
67  cfg = hpet_read64(HPET_CFG);
70 
71  /* Configure timer and setup comparator. */
72  hpet_write32(HPET_Tn_CFG(nr), tm.raw);
73  hpet_write64(HPET_Tn_CMP(nr), ticks);
74 
75  /* Enable main counter. */
77 }
78 
79 /*
80  * Local variables:
81  * mode: C
82  * c-file-style: "BSD"
83  * c-basic-offset: 4
84  * tab-width: 4
85  * indent-tabs-mode: nil
86  * End:
87  */
int hpet_init(void)
Discover and initialise the HPET.
Definition: hpet.c:29
unsigned int hpet_nr_timers
Definition: hpet.c:13
#define HPET_COUNTER
Definition: hpet.h:23
def cfg
Definition: mkcfg.py:42
#define HPET_CFG
Definition: hpet.h:20
bool enabled
Definition: hpet.c:20
bool level
Definition: hpet.c:19
static void hpet_write32(unsigned int reg, uint32_t val)
Definition: hpet.h:49
uint32_t raw
Definition: hpet.c:16
#define MASK_EXTR(v, m)
Definition: numbers.h:40
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
#define HPET_ID_NUMBER_MASK
Definition: hpet.h:18
#define HPET_Tn_CFG(n)
Definition: hpet.h:25
#define HPET_ID_MAX_PERIOD
Definition: hpet.h:17
static void hpet_write64(unsigned int reg, uint64_t val)
Definition: hpet.h:54
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
#define HPET_ID
Definition: hpet.h:16
bool mode_32bit
Definition: hpet.c:23
x86 HPET register definitions and utility functions.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
bool periodic
Definition: hpet.c:21
#define ENODEV
Definition: errno.h:32
#define HPET_CFG_ENABLE
Definition: hpet.h:21
#define HPET_Tn_CMP(n)
Definition: hpet.h:27
uint8_t irq
Definition: hpet.c:24
__UINT8_TYPE__ uint8_t
Definition: stdint.h:14
static uint64_t hpet_read64(unsigned int reg)
Definition: hpet.h:44