--- /dev/null
+/**
+ * @file arch/x86/hpet.c
+ *
+ * Basic x86 HPET driver.
+ */
+
+#include <xtf/lib.h>
+
+#include <xen/errno.h>
+
+#include <arch/hpet.h>
+
+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:
+ */
--- /dev/null
+/**
+ * @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 <xtf/numbers.h>
+#include <xtf/types.h>
+
+#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:
+ */
# 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
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();