Different architectures have different timer implementation. In
order to avoid using too many #ifdef, we want to implement
ukplat_time_* APIs for each architecture. In this case, we
move the time.c and tscclock.c to x86 sub-directory.
Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
plat/kvm/Makefile.uk | 4 +--
plat/kvm/time.c | 65 -----------------------------------
plat/kvm/x86/time.c | 45 ++++++++++++++++++++++--
plat/kvm/{ => x86}/tscclock.c | 0
4 files changed, 44 insertions(+), 70 deletions(-)
delete mode 100644 plat/kvm/time.c
rename plat/kvm/{ => x86}/tscclock.c (100%)
diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk
index 7015ed6..54463e3 100644
--- a/plat/kvm/Makefile.uk
+++ b/plat/kvm/Makefile.uk
@@ -37,7 +37,8 @@ LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) +=
$(LIBKVMPLAT_BASE)/x86/setup.c
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/console.c
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/lcpu.c
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/intctrl.c
-LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/tscclock.c
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/tscclock.c
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/time.c
ifeq ($(findstring y,$(CONFIG_KVM_KERNEL_VGA_CONSOLE)
$(CONFIG_KVM_DEBUG_VGA_CONSOLE)),y)
LIBKVMPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/vga_console.c
endif
@@ -61,7 +62,6 @@ endif
LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/shutdown.c
LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/memory.c
LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/irq.c
-LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/time.c
LIBKVMPLAT_SRCS-y += $(LIBKVMPLAT_BASE)/io.c
LIBKVMPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
LIBKVMPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/memory.c|common
diff --git a/plat/kvm/time.c b/plat/kvm/time.c
deleted file mode 100644
index 1fb48bf..0000000
--- a/plat/kvm/time.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* SPDX-License-Identifier: ISC */
-/*
- * Authors: Dan Williams
- * Martin Lucina
- * Ricardo Koller
- * Costin Lupu <costin.lupu@xxxxxxxxx>
- *
- * Copyright (c) 2015-2017 IBM
- * Copyright (c) 2016-2017 Docker, Inc.
- * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation
- *
- * Permission to use, copy, modify, and/or distribute this software
- * for any purpose with or without fee is hereby granted, provided
- * that the above copyright notice and this permission notice appear
- * in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-/* Taken from solo5 time.c */
-
-#include <stdlib.h>
-#include <uk/plat/time.h>
-#include <uk/plat/irq.h>
-#include <kvm/tscclock.h>
-#include <uk/assert.h>
-
-
-/* return ns since time_init() */
-__nsec ukplat_monotonic_clock(void)
-{
- return tscclock_monotonic();
-}
-
-/* return wall time in nsecs */
-__nsec ukplat_clock_wall(void)
-{
- return tscclock_monotonic() + tscclock_epochoffset();
-}
-
-static int timer_handler(void *arg __unused)
-{
- /* Yes, we handled the irq. */
- return 1;
-}
-
-/* must be called before interrupts are enabled */
-void ukplat_time_init(void)
-{
- int rc;
-
- rc = ukplat_irq_register(0, timer_handler, NULL);
- if (rc < 0)
- UK_CRASH("Failed to register timer interrupt handler\n");
-
- rc = tscclock_init();
- if (rc < 0)
- UK_CRASH("Failed to initialize TSCCLOCK\n");
-}
diff --git a/plat/kvm/x86/time.c b/plat/kvm/x86/time.c
index 8a95ab5..3d8a842 100644
--- a/plat/kvm/x86/time.c
+++ b/plat/kvm/x86/time.c
@@ -1,8 +1,16 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
- * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ * Authors: Dan Williams
+ * Martin Lucina
+ * Ricardo Koller
+ * Costin Lupu <costin.lupu@xxxxxxxxx>
+ * Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
+ * Wei Chen <wei.chen@xxxxxxx>
*
- * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ * Copyright (c) 2015-2017 IBM
+ * Copyright (c) 2016-2017 Docker, Inc.
+ * Copyright (c) 2017-2018, NEC Europe Ltd., NEC Corporation
+ * Copyright (c) 2018, Arm Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,11 +40,42 @@
* THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
*/
+#include <stdlib.h>
#include <uk/plat/time.h>
+#include <uk/plat/irq.h>
+#include <kvm/tscclock.h>
+#include <uk/assert.h>
+/* return ns since time_init() */
+__nsec ukplat_monotonic_clock(void)
+{
+ return tscclock_monotonic();
+}
+
+/* return wall time in nsecs */
+__nsec ukplat_clock_wall(void)
+{
+ return tscclock_monotonic() + tscclock_epochoffset();
+}
+
+static int timer_handler(void *arg __unused)
+{
+ /* Yes, we handled the irq. */
+ return 1;
+}
+
+/* must be called before interrupts are enabled */
void ukplat_time_init(void)
{
- /* TODO */
+ int rc;
+
+ rc = ukplat_irq_register(0, timer_handler, NULL);
+ if (rc < 0)
+ UK_CRASH("Failed to register timer interrupt handler\n");
+
+ rc = tscclock_init();
+ if (rc < 0)
+ UK_CRASH("Failed to initialize TSCCLOCK\n");
}
void ukplat_time_fini(void)
diff --git a/plat/kvm/tscclock.c b/plat/kvm/x86/tscclock.c
similarity index 100%
rename from plat/kvm/tscclock.c
rename to plat/kvm/x86/tscclock.c