From: Roger Pau Monne Date: Fri, 30 Mar 2018 12:39:42 +0000 (+0100) Subject: Introduce some basic HPET infrastructure X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=30804bee41755adbce3ba44333b6601371251983;p=people%2Fandrewcoop%2Fxen-test-framework.git Introduce some basic HPET infrastructure Signed-off-by: Roger Pau Monné Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/hpet.c b/arch/x86/hpet.c new file mode 100644 index 0000000..906f780 --- /dev/null +++ b/arch/x86/hpet.c @@ -0,0 +1,38 @@ +/** + * @file arch/x86/hpet.c + * + * Basic x86 HPET driver. + */ + +#include + +#include + +#include + +int hpet_init(void) +{ + uint64_t id = hpet_read64(HPET_ID); + + /* Bare MMIO? */ + if ( id == ~0ull ) + return -ENODEV; + + uint32_t period = id >> 32; + + /* Sanity check main counter tick period. */ + if ( period == 0 || period > HPET_ID_MAX_PERIOD ) + return -ENODEV; + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/arch/x86/include/arch/hpet.h b/arch/x86/include/arch/hpet.h new file mode 100644 index 0000000..1cd5d12 --- /dev/null +++ b/arch/x86/include/arch/hpet.h @@ -0,0 +1,55 @@ +/** + * @file arch/x86/include/arch/hpet.h + * + * %x86 HPET register definitions and utility functions. + * + * NB: assume the HPET is at it's default address. + */ + +#ifndef XTF_X86_HPET_H +#define XTF_X86_HPET_H + +#include +#include + +#define HPET_ID 0x0 +#define HPET_ID_MAX_PERIOD 0x05f5e100 + +#define HPET_DEFAULT_BASE 0xfed00000 + +/** + * Discover and initialise the HPET. May fail if there is no HPET. + */ +int hpet_init(void); + +static inline uint32_t hpet_read32(unsigned int reg) +{ + return *(volatile uint32_t *)(_p(HPET_DEFAULT_BASE) + reg); +} + +static inline uint64_t hpet_read64(unsigned int reg) +{ + return *(volatile uint64_t *)(_p(HPET_DEFAULT_BASE) + reg); +} + +static inline void hpet_write32(unsigned int reg, uint32_t val) +{ + *(volatile uint32_t *)(_p(HPET_DEFAULT_BASE) + reg) = val; +} + +static inline void hpet_write64(unsigned int reg, uint64_t val) +{ + *(volatile uint64_t *)(_p(HPET_DEFAULT_BASE) + reg) = val; +} + +#endif /* !XTF_X86_HPET_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/arch/x86/include/arch/xtf.h b/arch/x86/include/arch/xtf.h index 2956e1a..deaed17 100644 --- a/arch/x86/include/arch/xtf.h +++ b/arch/x86/include/arch/xtf.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/build/files.mk b/build/files.mk index 46b42d6..3000239 100644 --- a/build/files.mk +++ b/build/files.mk @@ -29,6 +29,7 @@ obj-perenv += $(ROOT)/arch/x86/traps.o # HVM specific objects obj-hvm += $(ROOT)/arch/x86/apic.o +obj-hvm += $(ROOT)/arch/x86/hpet.o obj-hvm += $(ROOT)/arch/x86/hvm/pagetables.o obj-hvm += $(ROOT)/arch/x86/hvm/traps.o diff --git a/tests/selftest/main.c b/tests/selftest/main.c index f9bf4f4..51196b4 100644 --- a/tests/selftest/main.c +++ b/tests/selftest/main.c @@ -322,6 +322,10 @@ static void test_driver_init(void) xtf_failure("Fail: apic_init(X2APIC) returned %d\n", rc); } } + + rc = hpet_init(); + if ( rc && rc != -ENODEV ) + xtf_failure("Fail: hpet_init() returned %d\n", rc); } rc = xenstore_init();