[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 1/5] plat/common: arm: separate arm and arm64 and add `cpu.h` to arm



In order to add support for arm on xen the following is done:
- Separate directories for arm and arm64 sources under plat/common
- Add `cpu.h` to the arm platform with
declerations of `halt`, `reset` and `system_off`.
- Add implementations for those functions in
plat/common/arm/arm/cpu_native.c

Signed-off-by: Dafna Hirschfeld <dafna3@xxxxxxxxx>
---
 plat/common/arm/arm/cpu_native.c         | 62 +++++++++++++++++
 plat/common/arm/arm/time.c               | 85 ++++++++++++++++++++++++
 plat/common/arm/{ => arm64}/cache64.S    |  0
 plat/common/arm/{ => arm64}/cpu_native.c |  0
 plat/common/arm/{ => arm64}/pl011.c      |  0
 plat/common/arm/{ => arm64}/psci_arm64.S |  0
 plat/common/arm/{ => arm64}/time.c       |  0
 plat/common/arm/{ => arm64}/traps.c      |  0
 plat/common/include/arm/arm/cpu.h        | 39 +++++++++++
 plat/common/include/arm/cpu.h            |  2 +
 plat/common/include/cpu.h                |  6 +-
 plat/kvm/Makefile.uk                     | 12 ++--
 plat/xen/Makefile.uk                     |  5 ++
 13 files changed, 202 insertions(+), 9 deletions(-)
 create mode 100644 plat/common/arm/arm/cpu_native.c
 create mode 100644 plat/common/arm/arm/time.c
 rename plat/common/arm/{ => arm64}/cache64.S (100%)
 rename plat/common/arm/{ => arm64}/cpu_native.c (100%)
 rename plat/common/arm/{ => arm64}/pl011.c (100%)
 rename plat/common/arm/{ => arm64}/psci_arm64.S (100%)
 rename plat/common/arm/{ => arm64}/time.c (100%)
 rename plat/common/arm/{ => arm64}/traps.c (100%)
 create mode 100644 plat/common/include/arm/arm/cpu.h

diff --git a/plat/common/arm/arm/cpu_native.c b/plat/common/arm/arm/cpu_native.c
new file mode 100644
index 0000000..46f99b5
--- /dev/null
+++ b/plat/common/arm/arm/cpu_native.c
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Wei Chen <wei.chen@xxxxxxx>
+ *
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#include <cpu.h>
+//#include <irq.h>
+#include <uk/assert.h>
+//#include <arm/cpu_defs.h>
+#include <xen-arm/os.h>
+/*
+ * Halts the CPU until the next external interrupt is fired. For Arm,
+ * we can use WFI to implement this feature.
+ */
+void halt(void)
+{
+       __asm__ __volatile__("wfi");
+}
+
+/* Systems support PSCI >= 0.2 can do system reset from PSCI */
+void reset(void)
+{
+       //TODO
+       uk_pr_crit("Couldn't reset system, HALT!\n");
+       __CPU_HALT();
+}
+
+/* Systems support PSCI >= 0.2 can do system off from PSCI */
+void system_off(void)
+{
+       //TODO
+       uk_pr_crit("Couldn't shutdown system, HALT!\n");
+       __CPU_HALT();
+}
diff --git a/plat/common/arm/arm/time.c b/plat/common/arm/arm/time.c
new file mode 100644
index 0000000..0ce9eb5
--- /dev/null
+++ b/plat/common/arm/arm/time.c
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Wei Chen <Wei.Chen@xxxxxxx>
+ *
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#include <stdlib.h>
+#include <libfdt.h>
+#include <uk/assert.h>
+#include <uk/plat/time.h>
+#include <uk/plat/irq.h>
+#include <uk/bitops.h>
+#include <cpu.h>
+
+static uint64_t boot_ticks;
+static uint32_t counter_freq;
+extern void *_libkvmplat_dtb;
+
+/*
+ * Shift factor for counter scaling multiplier; referred to as S in the
+ * following comments.
+ */
+static uint8_t counter_shift;
+
+/* Multiplier for converting counter ticks to nsecs. (0.S) fixed point. */
+static uint32_t ns_per_tick;
+
+/* How many nanoseconds per second */
+#define NSEC_PER_SEC ukarch_time_sec_to_nsec(1)
+
+static inline uint64_t ticks_to_ns(uint64_t ticks)
+{
+       return (ns_per_tick * ticks) >> counter_shift;
+}
+
+
+unsigned long sched_have_pending_events;
+
+void time_block_until(__snsec until)
+{
+       while ((__snsec) ukplat_monotonic_clock() < until) {
+               /*
+                * TODO:
+                * As we haven't support interrupt on Arm, so we just
+                * use busy polling for now.
+                */
+               if (__uk_test_and_clear_bit(0, &sched_have_pending_events))
+                       break;
+       }
+}
+
+static int timer_handler(void *arg __unused)
+{
+       /* Yes, we handled the irq. */
+       return 1;
+}
+
+
diff --git a/plat/common/arm/cache64.S b/plat/common/arm/arm64/cache64.S
similarity index 100%
rename from plat/common/arm/cache64.S
rename to plat/common/arm/arm64/cache64.S
diff --git a/plat/common/arm/cpu_native.c b/plat/common/arm/arm64/cpu_native.c
similarity index 100%
rename from plat/common/arm/cpu_native.c
rename to plat/common/arm/arm64/cpu_native.c
diff --git a/plat/common/arm/pl011.c b/plat/common/arm/arm64/pl011.c
similarity index 100%
rename from plat/common/arm/pl011.c
rename to plat/common/arm/arm64/pl011.c
diff --git a/plat/common/arm/psci_arm64.S b/plat/common/arm/arm64/psci_arm64.S
similarity index 100%
rename from plat/common/arm/psci_arm64.S
rename to plat/common/arm/arm64/psci_arm64.S
diff --git a/plat/common/arm/time.c b/plat/common/arm/arm64/time.c
similarity index 100%
rename from plat/common/arm/time.c
rename to plat/common/arm/arm64/time.c
diff --git a/plat/common/arm/traps.c b/plat/common/arm/arm64/traps.c
similarity index 100%
rename from plat/common/arm/traps.c
rename to plat/common/arm/arm64/traps.c
diff --git a/plat/common/include/arm/arm/cpu.h 
b/plat/common/include/arm/arm/cpu.h
new file mode 100644
index 0000000..fd846a5
--- /dev/null
+++ b/plat/common/include/arm/arm/cpu.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Wei Chen <wei.chen@xxxxxxx>
+ *
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+
+/* CPU native APIs */
+void halt(void);
+void reset(void);
+void system_off(void);
diff --git a/plat/common/include/arm/cpu.h b/plat/common/include/arm/cpu.h
index 1c06721..479c7a9 100644
--- a/plat/common/include/arm/cpu.h
+++ b/plat/common/include/arm/cpu.h
@@ -37,6 +37,8 @@
 
 #if defined(__ARM_64__)
 #include <arm/arm64/cpu.h>
+#elif defined(__ARM_32__)
+#include <arm/arm/cpu.h>
 #else
 #error "Add cpu.h for current architecture."
 #endif
diff --git a/plat/common/include/cpu.h b/plat/common/include/cpu.h
index ca2e15e..5b9cbc7 100644
--- a/plat/common/include/cpu.h
+++ b/plat/common/include/cpu.h
@@ -38,7 +38,7 @@
 #include <uk/arch/lcpu.h>
 #if defined(__X86_64__)
 #include <x86/cpu.h>
-#elif defined(__ARM_64__)
+#elif defined(__ARM_64__) || defined(__ARM_32__)
 #include <arm/cpu.h>
 #else
 #error "Add cpu.h for current architecture."
@@ -47,8 +47,8 @@
 #define __CPU_HALT()           \
 ({                             \
        local_irq_disable();    \
-               for (;;)        \
-                       halt(); \
+       for (;;)                \
+               halt();         \
 })
 
 #endif /* __PLAT_CMN_CPU_H__ */
diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk
index 1f9c5dc..7191828 100644
--- a/plat/kvm/Makefile.uk
+++ b/plat/kvm/Makefile.uk
@@ -52,13 +52,13 @@ endif
 ##
 ifeq ($(CONFIG_ARCH_ARM_64),y)
 ifeq ($(findstring y,$(CONFIG_KVM_KERNEL_SERIAL_CONSOLE) 
$(CONFIG_KVM_DEBUG_SERIAL_CONSOLE)),y)
-LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/pl011.c|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/arm64/pl011.c|common
 endif
-LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/cpu_native.c|common
-LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/cache64.S|common
-LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/psci_arm64.S|common
-LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/time.c|common
-LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/traps.c|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/arm64/cpu_native.c|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/arm64/cache64.S|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/arm64/psci_arm64.S|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/arm64/time.c|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/arm64/traps.c|common
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/entry64.S
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/exceptions.S
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/pagetable.S
diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index 5d777b2..033ae51 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -31,6 +31,11 @@ LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/io.c
 LIBXENPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
 LIBXENPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/memory.c|common
 
+ifneq (,$(filter arm,$(CONFIG_UK_ARCH)))
+LIBXENPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/arm/arm/cpu_native.c
+LIBXENPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/arm/arm/time.c
+endif
+
 ifneq (,$(filter x86_32 x86_64,$(CONFIG_UK_ARCH)))
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += 
$(UK_PLAT_COMMON_BASE)/x86/trace.c|common
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += 
$(UK_PLAT_COMMON_BASE)/x86/traps.c|common
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.