]> xenbits.xensource.com Git - xtf.git/commitdiff
Introduce some basic HPET infrastructure
authorRoger Pau Monne <roger.pau@citrix.com>
Fri, 30 Mar 2018 12:39:42 +0000 (13:39 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 13 Apr 2018 16:14:29 +0000 (17:14 +0100)
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/hpet.c [new file with mode: 0644]
arch/x86/include/arch/hpet.h [new file with mode: 0644]
arch/x86/include/arch/xtf.h
build/files.mk
tests/selftest/main.c

diff --git a/arch/x86/hpet.c b/arch/x86/hpet.c
new file mode 100644 (file)
index 0000000..906f780
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * @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:
+ */
diff --git a/arch/x86/include/arch/hpet.h b/arch/x86/include/arch/hpet.h
new file mode 100644 (file)
index 0000000..1cd5d12
--- /dev/null
@@ -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 <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:
+ */
index 2956e1a7f4d0b747491f9bedb7e9ef049f051c7f..deaed1707ab0ae2d1b5cb20c437f39661ab6d45f 100644 (file)
@@ -4,6 +4,7 @@
 #include <arch/apic.h>
 #include <arch/cpuid.h>
 #include <arch/exinfo.h>
+#include <arch/hpet.h>
 #include <arch/idt.h>
 #include <arch/lib.h>
 #include <arch/mm.h>
index 46b42d6bc086456cc11b6d3bed2274e201c2e47e..3000239487bc589d8b22122e16ade51409f56bc2 100644 (file)
@@ -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
 
index f9bf4f4ada93c23ddfcf839872a323bda891161a..51196b4916fcc8404fda47949edd48676b8f6154 100644 (file)
@@ -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();