Xen Test Framework
Loading...
Searching...
No Matches
arch
x86
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
{
16
uint32_t
raw
;
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;
24
uint8_t
irq
:5;
25
uint32_t
:18;
26
};
27
};
28
29
int
hpet_init
(
void
)
30
{
31
uint64_t
id
=
hpet_read64
(
HPET_ID
);
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. */
44
hpet_nr_timers
=
MASK_EXTR
(
id
,
HPET_ID_NUMBER_MASK
) + 1;
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
);
68
hpet_write64
(
HPET_CFG
, cfg & ~
HPET_CFG_ENABLE
);
69
hpet_write64
(
HPET_COUNTER
, 0);
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. */
76
hpet_write64
(
HPET_CFG
, cfg |
HPET_CFG_ENABLE
);
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
*/
errno.h
ENODEV
#define ENODEV
Definition
errno.h:32
hpet_init_timer
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
hpet_init
int hpet_init(void)
Discover and initialise the HPET.
Definition
hpet.c:29
hpet_nr_timers
unsigned int hpet_nr_timers
Definition
hpet.c:13
hpet.h
x86 HPET register definitions and utility functions.
HPET_ID_NUMBER_MASK
#define HPET_ID_NUMBER_MASK
Definition
hpet.h:18
HPET_Tn_CFG
#define HPET_Tn_CFG(n)
Definition
hpet.h:25
hpet_write64
static void hpet_write64(unsigned int reg, uint64_t val)
Definition
hpet.h:54
HPET_ID_MAX_PERIOD
#define HPET_ID_MAX_PERIOD
Definition
hpet.h:17
hpet_write32
static void hpet_write32(unsigned int reg, uint32_t val)
Definition
hpet.h:49
HPET_Tn_CMP
#define HPET_Tn_CMP(n)
Definition
hpet.h:27
HPET_COUNTER
#define HPET_COUNTER
Definition
hpet.h:23
HPET_CFG_ENABLE
#define HPET_CFG_ENABLE
Definition
hpet.h:21
HPET_ID
#define HPET_ID
Definition
hpet.h:16
hpet_read64
static uint64_t hpet_read64(unsigned int reg)
Definition
hpet.h:44
HPET_CFG
#define HPET_CFG
Definition
hpet.h:20
lib.h
MASK_EXTR
#define MASK_EXTR(v, m)
Definition
numbers.h:40
uint32_t
__UINT32_TYPE__ uint32_t
Definition
stdint.h:16
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
uint8_t
__UINT8_TYPE__ uint8_t
Definition
stdint.h:14
hpet_timer
Definition
hpet.c:15
hpet_timer::mode_32bit
bool mode_32bit
Definition
hpet.c:23
hpet_timer::periodic
bool periodic
Definition
hpet.c:21
hpet_timer::raw
uint32_t raw
Definition
hpet.c:16
hpet_timer::enabled
bool enabled
Definition
hpet.c:20
hpet_timer::level
bool level
Definition
hpet.c:19
hpet_timer::irq
uint8_t irq
Definition
hpet.c:24
Generated by
1.9.8