From: Antonios Motakis <
antonios...@huawei.com>
This is a straight port of the inmate demos from AArch32 to AArch64.
These can now be loaded as cells onto a Foundation ARMv8 model.
Code reuse can possible be increased here as well.
inmates/Makefile | 1 +
inmates/demos/arm64/Makefile | 20 +++++++
inmates/demos/arm64/gic-demo.c | 58 +++++++++++++++++++
inmates/demos/arm64/uart-demo.c | 40 +++++++++++++
inmates/lib/arm64/Makefile | 19 +++++++
inmates/lib/arm64/Makefile.lib | 46 +++++++++++++++
inmates/lib/arm64/gic-v2.c | 39 +++++++++++++
inmates/lib/arm64/gic.c | 43 ++++++++++++++
inmates/lib/arm64/header.S | 66 ++++++++++++++++++++++
inmates/lib/arm64/include/inmates/gic.h | 25 ++++++++
inmates/lib/arm64/include/inmates/inmate.h | 54 ++++++++++++++++++
.../arm64/include/mach-amd-seattle/mach/gic_v2.h | 14 +++++
.../arm64/include/mach-amd-seattle/mach/timer.h | 13 +++++
.../lib/arm64/include/mach-amd-seattle/mach/uart.h | 13 +++++
.../arm64/include/mach-foundation-v8/mach/gic_v2.h | 14 +++++
.../arm64/include/mach-foundation-v8/mach/timer.h | 13 +++++
.../arm64/include/mach-foundation-v8/mach/uart.h | 13 +++++
inmates/lib/arm64/inmate.lds | 40 +++++++++++++
inmates/lib/arm64/printk.c | 55 ++++++++++++++++++
inmates/lib/arm64/timer.c | 55 ++++++++++++++++++
inmates/lib/arm64/uart-pl011.c | 23 ++++++++
21 files changed, 664 insertions(+)
create mode 100644 inmates/demos/arm64/gic-demo.c
create mode 100644 inmates/demos/arm64/uart-demo.c
create mode 100644 inmates/lib/arm64/Makefile.lib
create mode 100644 inmates/lib/arm64/gic-v2.c
create mode 100644 inmates/lib/arm64/gic.c
create mode 100644 inmates/lib/arm64/header.S
create mode 100644 inmates/lib/arm64/include/inmates/gic.h
create mode 100644 inmates/lib/arm64/include/inmates/inmate.h
create mode 100644 inmates/lib/arm64/include/mach-amd-seattle/mach/gic_v2.h
create mode 100644 inmates/lib/arm64/include/mach-amd-seattle/mach/timer.h
create mode 100644 inmates/lib/arm64/include/mach-amd-seattle/mach/uart.h
create mode 100644 inmates/lib/arm64/include/mach-foundation-v8/mach/gic_v2.h
create mode 100644 inmates/lib/arm64/include/mach-foundation-v8/mach/timer.h
create mode 100644 inmates/lib/arm64/include/mach-foundation-v8/mach/uart.h
create mode 100644 inmates/lib/arm64/inmate.lds
create mode 100644 inmates/lib/arm64/printk.c
create mode 100644 inmates/lib/arm64/timer.c
create mode 100644 inmates/lib/arm64/uart-pl011.c
diff --git a/inmates/Makefile b/inmates/Makefile
index 0d4ea5d..904be0a 100644
--- a/inmates/Makefile
+++ b/inmates/Makefile
@@ -15,6 +15,7 @@ export INMATES_LIB
INCLUDES := -I$(INMATES_LIB) \
-I$(src)/../hypervisor/arch/$(SRCARCH)/include \
+ -I$(src)/../hypervisor/arch/arm/include \
-I$(src)/../hypervisor/include
LINUXINCLUDE :=
diff --git a/inmates/demos/arm64/Makefile b/inmates/demos/arm64/Makefile
index e69de29..f61667a 100644
--- a/inmates/demos/arm64/Makefile
+++ b/inmates/demos/arm64/Makefile
@@ -0,0 +1,20 @@
+#
+# Jailhouse AArch64 support
+#
+# Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+#
+# Authors:
+# Antonios Motakis <
antonios...@huawei.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+include $(INMATES_LIB)/Makefile.lib
+
+INMATES := gic-demo.bin uart-demo.bin
+
+gic-demo-y := gic-demo.o
+uart-demo-y := uart-demo.o
+
+$(eval $(call DECLARE_TARGETS,$(INMATES)))
diff --git a/inmates/demos/arm64/gic-demo.c b/inmates/demos/arm64/gic-demo.c
new file mode 100644
index 0000000..61b432e
--- /dev/null
+++ b/inmates/demos/arm64/gic-demo.c
@@ -0,0 +1,58 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <asm/gic_common.h>
+#include <inmates/inmate.h>
+#include <mach/timer.h>
+
+#define BEATS_PER_SEC 10
+
+static u64 ticks_per_beat;
+static volatile u64 expected_ticks;
+
+static void handle_IRQ(unsigned int irqn)
+{
+ static u64 min_delta = ~0ULL, max_delta = 0;
+ u64 delta;
+
+ if (irqn != TIMER_IRQ)
+ return;
+
+ delta = timer_get_ticks() - expected_ticks;
+ if (delta < min_delta)
+ min_delta = delta;
+ if (delta > max_delta)
+ max_delta = delta;
+
+ printk("Timer fired, jitter: %6ld ns, min: %6ld ns, max: %6ld ns\n",
+ (long)timer_ticks_to_ns(delta),
+ (long)timer_ticks_to_ns(min_delta),
+ (long)timer_ticks_to_ns(max_delta));
+
+ expected_ticks = timer_get_ticks() + ticks_per_beat;
+ timer_start(ticks_per_beat);
+}
+
+void inmate_main(void)
+{
+ printk("Initializing the GIC...\n");
+ gic_setup(handle_IRQ);
+ gic_enable_irq(TIMER_IRQ);
+
+ printk("Initializing the timer...\n");
+ ticks_per_beat = timer_get_frequency() / BEATS_PER_SEC;
+ expected_ticks = timer_get_ticks() + ticks_per_beat;
+ timer_start(ticks_per_beat);
+
+ while (1)
+ asm volatile("wfi" : : : "memory");
+}
diff --git a/inmates/demos/arm64/uart-demo.c b/inmates/demos/arm64/uart-demo.c
new file mode 100644
index 0000000..3e030d4
--- /dev/null
+++ b/inmates/demos/arm64/uart-demo.c
@@ -0,0 +1,40 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <inmates/inmate.h>
+
+/*
+ * To ease the debugging, we can send a spurious hypercall, which should return
+ * -ENOSYS, but appear in the hypervisor stats for this cell.
+ */
+static void heartbeat(void)
+{
+ asm volatile (
+ "mov x0, %0\n"
+ "hvc #0\n"
+ : : "r" (0xbea7) : "x0");
+}
+
+void inmate_main(void)
+{
+ unsigned int i = 0, j;
+ /*
+ * The cell config can set up a mapping to access UARTx instead of UART0
+ */
+ while(++i) {
+ for (j = 0; j < 100000000; j++);
+ printk("Hello %d from cell!\n", i);
+ heartbeat();
+ }
+
+ /* lr should be 0, so a return will go back to the reset vector */
+}
diff --git a/inmates/lib/arm64/Makefile b/inmates/lib/arm64/Makefile
index e69de29..2859134 100644
--- a/inmates/lib/arm64/Makefile
+++ b/inmates/lib/arm64/Makefile
@@ -0,0 +1,19 @@
+#
+# Jailhouse, a Linux-based partitioning hypervisor
+#
+# Copyright (c) Siemens AG, 2015
+#
+# Authors:
+# Jan Kiszka <
jan.k...@siemens.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+include $(INMATES_LIB)/Makefile.lib
+
+always := lib.a
+
+lib-y := header.o gic.o printk.o timer.o
+lib-$(CONFIG_ARM_GIC) += gic-v2.o
+lib-$(CONFIG_SERIAL_AMBA_PL011) += uart-pl011.o
diff --git a/inmates/lib/arm64/Makefile.lib b/inmates/lib/arm64/Makefile.lib
new file mode 100644
index 0000000..0196c51
--- /dev/null
+++ b/inmates/lib/arm64/Makefile.lib
@@ -0,0 +1,46 @@
+#
+# Jailhouse, a Linux-based partitioning hypervisor
+#
+# Copyright (c) ARM Limited, 2014
+# Copyright (c) Siemens AG, 2014
+#
+# Authors:
+# Jean-Philippe Brucker <
jean-phili...@arm.com>
+# Jan Kiszka <
jan.k...@siemens.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+-include $(obj)/../../../hypervisor/include/generated/
config.mk
+
+KBUILD_AFLAGS := $(filter-out -include asm/unified.h,$(KBUILD_AFLAGS))
+
+KBUILD_CFLAGS += -I$(INMATES_LIB)/include
+KBUILD_AFLAGS += -I$(INMATES_LIB)/include
+
+define DECLARE_TARGETS =
+ _TARGETS = $(1)
+ always := $$(_TARGETS)
+ # $(NAME-y) NAME-linked.o NAME.bin
+ targets += $$(foreach t,$$(_TARGETS:.bin=-y),$$($$t)) \
+ $$(_TARGETS:.bin=-linked.o) $$(_TARGETS)
+endef
+
+mach-$(CONFIG_MACH_FOUNDATION_V8) := foundation-v8
+mach-$(CONFIG_MACH_AMD_SEATTLE) := amd-seattle
+
+MACHINE := mach-$(mach-y)
+KBUILD_CFLAGS += -I$(INMATES_LIB)/include/$(MACHINE)
+KBUILD_AFLAGS += -I$(INMATES_LIB)/include/$(MACHINE)
+
+# prevent deleting intermediate files which would cause rebuilds
+.SECONDARY: $(addprefix $(obj)/,$(targets))
+
+.SECONDEXPANSION:
+$(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y)) \
+ $(INMATES_LIB)/lib.a
+ $(call if_changed,ld)
+
+$(obj)/%.bin: $(obj)/%-linked.o
+ $(call if_changed,objcopy)
diff --git a/inmates/lib/arm64/gic-v2.c b/inmates/lib/arm64/gic-v2.c
new file mode 100644
index 0000000..f14a742
--- /dev/null
+++ b/inmates/lib/arm64/gic-v2.c
@@ -0,0 +1,39 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <asm/gic_common.h>
+#include <asm/gic_v2.h>
+#include <inmates/gic.h>
+#include <inmates/inmate.h>
+#include <mach/gic_v2.h>
+
+void gic_enable(unsigned int irqn)
+{
+ mmio_write32(GICD_BASE + GICD_ISENABLER, 1 << irqn);
+}
+
+int gic_init(void)
+{
+ mmio_write32(GICC_BASE + GICC_CTLR, GICC_CTLR_GRPEN1);
+ mmio_write32(GICC_BASE + GICC_PMR, GICC_PMR_DEFAULT);
+
+ return 0;
+}
+
+void gic_write_eoi(u32 irqn)
+{
+ mmio_write32(GICC_BASE + GICC_EOIR, irqn);
+}
+
+u32 gic_read_ack(void)
+{
+ return mmio_read32(GICC_BASE + GICC_IAR);
+}
diff --git a/inmates/lib/arm64/gic.c b/inmates/lib/arm64/gic.c
new file mode 100644
index 0000000..dd7a790
--- /dev/null
+++ b/inmates/lib/arm64/gic.c
@@ -0,0 +1,43 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <inmates/inmate.h>
+#include <inmates/gic.h>
+
+static irq_handler_t irq_handler = (irq_handler_t)NULL;
+
+/* Replaces the weak reference in header.S */
+void vector_irq(void)
+{
+ u32 irqn;
+
+ do {
+ irqn = gic_read_ack();
+
+ if (irq_handler)
+ irq_handler(irqn);
+
+ gic_write_eoi(irqn);
+
+ } while (irqn != 0x3ff);
+}
+
+void gic_setup(irq_handler_t handler)
+{
+ gic_init();
+ irq_handler = handler;
+}
+
+void gic_enable_irq(unsigned int irq)
+{
+ gic_enable(irq);
+}
diff --git a/inmates/lib/arm64/header.S b/inmates/lib/arm64/header.S
new file mode 100644
index 0000000..fe7bae7
--- /dev/null
+++ b/inmates/lib/arm64/header.S
@@ -0,0 +1,66 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+.macro ventry label
+ .align 7
+ b \label
+.endm
+
+ .section ".boot", "ax"
+ .globl __reset_entry
+__reset_entry:
+ ldr x0, =vectors
+ msr vbar_el1, x0
+
+ ldr x0, =stack_top
+ mov sp, x0
+
+ mov x0, #(3 << 20)
+ msr cpacr_el1, x0
+
+ msr daif, xzr
+
+ isb
+
+ b inmate_main
+
+handle_irq:
+ bl vector_irq
+ eret
+
+.weak vector_irq
+ b .
+
+ .globl vectors
+ .align 11
+vectors:
+ ventry .
+ ventry .
+ ventry .
+ ventry .
+
+ ventry .
+ ventry handle_irq
+ ventry .
+ ventry .
+
+ ventry .
+ ventry handle_irq
+ ventry .
+ ventry .
+
+ ventry .
+ ventry .
+ ventry .
+ ventry .
+
+ .ltorg
diff --git a/inmates/lib/arm64/include/inmates/gic.h b/inmates/lib/arm64/include/inmates/gic.h
new file mode 100644
index 0000000..4e5eabd
--- /dev/null
+++ b/inmates/lib/arm64/include/inmates/gic.h
@@ -0,0 +1,25 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _JAILHOUSE_INMATES_GIC_H
+#define _JAILHOUSE_INMATES_GIC_H
+
+#include <jailhouse/types.h>
+
+#ifndef __ASSEMBLY__
+
+int gic_init(void);
+void gic_enable(unsigned int irqn);
+void gic_write_eoi(u32 irqn);
+u32 gic_read_ack(void);
+
+#endif /* !__ASSEMBLY__ */
+#endif
diff --git a/inmates/lib/arm64/include/inmates/inmate.h b/inmates/lib/arm64/include/inmates/inmate.h
new file mode 100644
index 0000000..9ad962c
--- /dev/null
+++ b/inmates/lib/arm64/include/inmates/inmate.h
@@ -0,0 +1,54 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _JAILHOUSE_INMATES_INMATE_H
+#define _JAILHOUSE_INMATES_INMATE_H
+
+#ifndef __ASSEMBLY__
+typedef signed char s8;
+typedef unsigned char u8;
+
+typedef signed short s16;
+typedef unsigned short u16;
+
+typedef signed int s32;
+typedef unsigned int u32;
+
+typedef signed long long s64;
+typedef unsigned long long u64;
+
+static inline void *memset(void *addr, int val, unsigned long size)
+{
+ char *s = addr;
+ unsigned int i;
+ for (i = 0; i < size; i++)
+ *s++ = val;
+
+ return addr;
+}
+
+extern unsigned long printk_uart_base;
+void printk(const char *fmt, ...);
+void inmate_main(void);
+
+void __attribute__((used)) vector_irq(void);
+
+typedef void (*irq_handler_t)(unsigned int);
+void gic_setup(irq_handler_t handler);
+void gic_enable_irq(unsigned int irq);
+
+unsigned long timer_get_frequency(void);
+u64 timer_get_ticks(void);
+u64 timer_ticks_to_ns(u64 ticks);
+void timer_start(u64 timeout);
+
+#endif /* !__ASSEMBLY__ */
+#endif
diff --git a/inmates/lib/arm64/include/mach-amd-seattle/mach/gic_v2.h b/inmates/lib/arm64/include/mach-amd-seattle/mach/gic_v2.h
new file mode 100644
index 0000000..b357a21
--- /dev/null
+++ b/inmates/lib/arm64/include/mach-amd-seattle/mach/gic_v2.h
@@ -0,0 +1,14 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#define GICD_BASE ((void *)0xe1110000)
+#define GICC_BASE ((void *)0xe112f000)
diff --git a/inmates/lib/arm64/include/mach-amd-seattle/mach/timer.h b/inmates/lib/arm64/include/mach-amd-seattle/mach/timer.h
new file mode 100644
index 0000000..696b5cb
--- /dev/null
+++ b/inmates/lib/arm64/include/mach-amd-seattle/mach/timer.h
@@ -0,0 +1,13 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#define TIMER_IRQ 27
diff --git a/inmates/lib/arm64/include/mach-amd-seattle/mach/uart.h b/inmates/lib/arm64/include/mach-amd-seattle/mach/uart.h
new file mode 100644
index 0000000..512b6cb
--- /dev/null
+++ b/inmates/lib/arm64/include/mach-amd-seattle/mach/uart.h
@@ -0,0 +1,13 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#define UART_BASE ((void *)0xe1010000)
diff --git a/inmates/lib/arm64/include/mach-foundation-v8/mach/gic_v2.h b/inmates/lib/arm64/include/mach-foundation-v8/mach/gic_v2.h
new file mode 100644
index 0000000..bd3ec88
--- /dev/null
+++ b/inmates/lib/arm64/include/mach-foundation-v8/mach/gic_v2.h
@@ -0,0 +1,14 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#define GICD_BASE ((void *)0x2c001000)
+#define GICC_BASE ((void *)0x2c002000)
diff --git a/inmates/lib/arm64/include/mach-foundation-v8/mach/timer.h b/inmates/lib/arm64/include/mach-foundation-v8/mach/timer.h
new file mode 100644
index 0000000..696b5cb
--- /dev/null
+++ b/inmates/lib/arm64/include/mach-foundation-v8/mach/timer.h
@@ -0,0 +1,13 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#define TIMER_IRQ 27
diff --git a/inmates/lib/arm64/include/mach-foundation-v8/mach/uart.h b/inmates/lib/arm64/include/mach-foundation-v8/mach/uart.h
new file mode 100644
index 0000000..5ac3f87
--- /dev/null
+++ b/inmates/lib/arm64/include/mach-foundation-v8/mach/uart.h
@@ -0,0 +1,13 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#define UART_BASE ((void *)0x1c090000)
diff --git a/inmates/lib/arm64/inmate.lds b/inmates/lib/arm64/inmate.lds
new file mode 100644
index 0000000..e484bdc
--- /dev/null
+++ b/inmates/lib/arm64/inmate.lds
@@ -0,0 +1,40 @@
+/*
+ * Jailhouse AArch64 support
+ *
+ * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ *
+ * Authors:
+ * Antonios Motakis <
antonios...@huawei.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+SECTIONS {
+ . = 0;
+ .boot : { *(.boot) }
+
+ . = ALIGN(4096);
+ . = . + 0x1000;
+ stack_top = .;
+ bss_start = .;
+ .bss : {
+ *(.bss)
+ *(COMMON)
+ }
+
+ . = ALIGN(4);
+ .text : {
+ *(.text)
+ }
+
+ .rodata : {
+ *(.rodata)
+ }
+
+ .data : {
+ *(.data)
+ }
+}
+
+ENTRY(__reset_entry)
diff --git a/inmates/lib/arm64/printk.c b/inmates/lib/arm64/printk.c
new file mode 100644
index 0000000..0bc6e0a
--- /dev/null
+++ b/inmates/lib/arm64/printk.c
@@ -0,0 +1,55 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/types.h>
+#include <asm/debug.h>
+#include <stdarg.h>
+#include <inmates/inmate.h>
+
+static struct uart_chip chip;
+
+static void console_write(const char *msg)
+{
+ char c = 0;
+
+ while (1) {
+ if (c == '\n')
+ c = '\r';
+ else
+ c = *msg++;
+ if (!c)
+ break;
+
+ chip.wait(&chip);
+ chip.write(&chip, c);
+ chip.busy(&chip);
+ }
+}
+
+#include "../../../hypervisor/printk-core.c"
+
+void printk(const char *fmt, ...)
+{
+ static bool inited = false;
+ va_list ap;
+
+ if (!inited) {
+ uart_chip_init(&chip);
+ inited = true;
+ }
+
+ va_start(ap, fmt);
+
+ __vprintk(fmt, ap);
+
+ va_end(ap);
+}
diff --git a/inmates/lib/arm64/timer.c b/inmates/lib/arm64/timer.c
new file mode 100644
index 0000000..79f50ef
--- /dev/null
+++ b/inmates/lib/arm64/timer.c
@@ -0,0 +1,55 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ * Copyright (c) Siemens AG, 2015
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ * Jan Kiszka <
jan.k...@siemens.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <asm/sysregs.h>
+#include <inmates/inmate.h>
+
+unsigned long timer_get_frequency(void)
+{
+ unsigned long freq;
+
+ arm_read_sysreg(CNTFRQ_EL0, freq);
+ return freq;
+}
+
+u64 timer_get_ticks(void)
+{
+ u64 pct64;
+
+ arm_read_sysreg(CNTPCT_EL0, pct64);
+ return pct64;
+}
+
+static unsigned long emul_division(u64 val, u64 div)
+{
+ unsigned long cnt = 0;
+
+ while (val > div) {
+ val -= div;
+ cnt++;
+ }
+ return cnt;
+}
+
+u64 timer_ticks_to_ns(u64 ticks)
+{
+ return emul_division(ticks * 1000,
+ timer_get_frequency() / 1000 / 1000);
+}
+
+void timer_start(u64 timeout)
+{
+ arm_write_sysreg(CNTV_TVAL_EL0, timeout);
+ arm_write_sysreg(CNTV_CTL_EL0, 1);
+}
diff --git a/inmates/lib/arm64/uart-pl011.c b/inmates/lib/arm64/uart-pl011.c
new file mode 100644
index 0000000..8f07d78
--- /dev/null
+++ b/inmates/lib/arm64/uart-pl011.c
@@ -0,0 +1,23 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ *
+ * Authors:
+ * Jean-Philippe Brucker <
jean-phili...@arm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <asm/uart_pl011.h>
+#include <mach/uart.h>
+
+void uart_chip_init(struct uart_chip *chip)
+{
+ chip->virt_base = UART_BASE;
+ chip->fifo_enabled = true;
+ chip->wait = uart_wait;
+ chip->write = uart_write;
+ chip->busy = uart_busy;
+ uart_init(chip);
+}
--
2.4.3.368.g7974889