summaryrefslogtreecommitdiffstats
path: root/drivers/clocksource/efi.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2017-02-15 20:34:10 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-02-24 08:21:33 +0100
commit5596f405ff03cd5de12ad592a6d696e112fed0c1 (patch)
tree815c9bfaff0e54e0179553bf2bfc5b91747335b8 /drivers/clocksource/efi.c
parent40c5c3f8fcf8913c630329f45eead1fd5ec7fcbb (diff)
downloadbarebox-5596f405ff03cd5de12ad592a6d696e112fed0c1.tar.gz
barebox-5596f405ff03cd5de12ad592a6d696e112fed0c1.tar.xz
efi: move clocksource out of arch
as efi is not an arch but a boot mode from where barebox is started Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/clocksource/efi.c')
-rw-r--r--drivers/clocksource/efi.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
new file mode 100644
index 0000000000..c92c35b112
--- /dev/null
+++ b/drivers/clocksource/efi.c
@@ -0,0 +1,58 @@
+#include <common.h>
+#include <efi.h>
+#include <mach/efi.h>
+#include <clock.h>
+
+#ifdef __x86_64__
+uint64_t ticks_read(void)
+{
+ uint64_t a, d;
+
+ __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
+
+ return (d << 32) | a;
+}
+#else
+uint64_t ticks_read(void)
+{
+ uint64_t val;
+
+ __asm__ volatile ("rdtsc" : "=A" (val));
+
+ return val;
+}
+#endif
+
+static uint64_t freq;
+
+/* count TSC ticks during a millisecond delay */
+static uint64_t ticks_freq(void)
+{
+ uint64_t ticks_start, ticks_end;
+
+ ticks_start = ticks_read();
+ BS->stall(1000);
+ ticks_end = ticks_read();
+
+ return (ticks_end - ticks_start) * 1000;
+}
+
+static uint64_t efi_clocksource_read(void)
+{
+ return 1000 * 1000 * ticks_read() / freq;
+}
+
+static struct clocksource cs = {
+ .read = efi_clocksource_read,
+ .mask = CLOCKSOURCE_MASK(64),
+ .shift = 0,
+};
+
+int efi_clocksource_init(void)
+{
+ cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
+
+ freq = ticks_freq();
+
+ return init_clock(&cs);
+}