From: Jan Kiszka <[email protected]>

This allows to build Jailhouse for RISC-V, using QEMU as a first target.
The assembly entry routine can be called and returns a funky error for
now. All the rest are stubs.

Signed-off-by: Jan Kiszka <[email protected]>
[ralf: rebase to next, add stubs for missing routines]
Signed-off-by: Ralf Ramsauer <[email protected]>
---
 configs/riscv/qemu-riscv64.c                  | 65 ++++++++++++++++
 driver/main.c                                 |  2 +
 hypervisor/arch/riscv/Kbuild                  | 17 ++++
 hypervisor/arch/riscv/Makefile                | 13 ++++
 hypervisor/arch/riscv/asm-defines.c           | 19 +++++
 hypervisor/arch/riscv/control.c               | 78 +++++++++++++++++++
 hypervisor/arch/riscv/dbg-write.c             | 17 ++++
 hypervisor/arch/riscv/entry.S                 | 17 ++++
 hypervisor/arch/riscv/include/asm/bitops.h    | 37 +++++++++
 hypervisor/arch/riscv/include/asm/cell.h      | 24 ++++++
 hypervisor/arch/riscv/include/asm/control.h   |  0
 hypervisor/arch/riscv/include/asm/ivshmem.h   | 14 ++++
 .../arch/riscv/include/asm/jailhouse_header.h | 14 ++++
 hypervisor/arch/riscv/include/asm/mmio.h      |  0
 hypervisor/arch/riscv/include/asm/paging.h    | 54 +++++++++++++
 .../arch/riscv/include/asm/paging_modes.h     |  0
 hypervisor/arch/riscv/include/asm/percpu.h    | 23 ++++++
 hypervisor/arch/riscv/include/asm/processor.h | 33 ++++++++
 hypervisor/arch/riscv/include/asm/sections.h  | 14 ++++
 hypervisor/arch/riscv/include/asm/spinlock.h  | 27 +++++++
 hypervisor/arch/riscv/include/asm/types.h     | 14 ++++
 hypervisor/arch/riscv/ivshmem.c               | 29 +++++++
 hypervisor/arch/riscv/lib.c                   | 19 +++++
 hypervisor/arch/riscv/paging.c                | 23 ++++++
 hypervisor/arch/riscv/pci.c                   | 49 ++++++++++++
 hypervisor/arch/riscv/setup.c                 | 32 ++++++++
 include/arch/riscv/asm/jailhouse_hypercall.h  | 68 ++++++++++++++++
 inmates/demos/riscv/Makefile                  |  0
 inmates/lib/riscv/Makefile                    |  0
 inmates/tests/riscv/Makefile                  |  0
 inmates/tools/riscv/Makefile                  |  0
 scripts/include.mk                            |  3 +
 32 files changed, 705 insertions(+)
 create mode 100644 configs/riscv/qemu-riscv64.c
 create mode 100644 hypervisor/arch/riscv/Kbuild
 create mode 100644 hypervisor/arch/riscv/Makefile
 create mode 100644 hypervisor/arch/riscv/asm-defines.c
 create mode 100644 hypervisor/arch/riscv/control.c
 create mode 100644 hypervisor/arch/riscv/dbg-write.c
 create mode 100644 hypervisor/arch/riscv/entry.S
 create mode 100644 hypervisor/arch/riscv/include/asm/bitops.h
 create mode 100644 hypervisor/arch/riscv/include/asm/cell.h
 create mode 100644 hypervisor/arch/riscv/include/asm/control.h
 create mode 100644 hypervisor/arch/riscv/include/asm/ivshmem.h
 create mode 100644 hypervisor/arch/riscv/include/asm/jailhouse_header.h
 create mode 100644 hypervisor/arch/riscv/include/asm/mmio.h
 create mode 100644 hypervisor/arch/riscv/include/asm/paging.h
 create mode 100644 hypervisor/arch/riscv/include/asm/paging_modes.h
 create mode 100644 hypervisor/arch/riscv/include/asm/percpu.h
 create mode 100644 hypervisor/arch/riscv/include/asm/processor.h
 create mode 100644 hypervisor/arch/riscv/include/asm/sections.h
 create mode 100644 hypervisor/arch/riscv/include/asm/spinlock.h
 create mode 100644 hypervisor/arch/riscv/include/asm/types.h
 create mode 100644 hypervisor/arch/riscv/ivshmem.c
 create mode 100644 hypervisor/arch/riscv/lib.c
 create mode 100644 hypervisor/arch/riscv/paging.c
 create mode 100644 hypervisor/arch/riscv/pci.c
 create mode 100644 hypervisor/arch/riscv/setup.c
 create mode 100644 include/arch/riscv/asm/jailhouse_hypercall.h
 create mode 100644 inmates/demos/riscv/Makefile
 create mode 100644 inmates/lib/riscv/Makefile
 create mode 100644 inmates/tests/riscv/Makefile
 create mode 100644 inmates/tools/riscv/Makefile

diff --git a/configs/riscv/qemu-riscv64.c b/configs/riscv/qemu-riscv64.c
new file mode 100644
index 00000000..3c68ad71
--- /dev/null
+++ b/configs/riscv/qemu-riscv64.c
@@ -0,0 +1,65 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Configuration for QEMU riscv64 virtual target, 1G RAM, 4 cores
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * NOTE: Add "mem=768M" to the kernel command line.
+ */
+
+#include <jailhouse/types.h>
+#include <jailhouse/cell-config.h>
+
+struct {
+       struct jailhouse_system header;
+       struct jailhouse_cpu cpus[4];
+       struct jailhouse_memory mem_regions[1];
+} __attribute__((packed)) config = {
+       .header = {
+               .signature = JAILHOUSE_SYSTEM_SIGNATURE,
+               .revision = JAILHOUSE_CONFIG_REVISION,
+               .flags = JAILHOUSE_SYS_VIRTUAL_DEBUG_CONSOLE,
+               .hypervisor_memory = {
+                       .phys_start = 0xbfc00000,
+                       .size =       0x00400000,
+               },
+               .root_cell = {
+                       .name = "qemu-riscv64",
+
+                       .num_cpus = ARRAY_SIZE(config.cpus),
+                       .num_memory_regions = ARRAY_SIZE(config.mem_regions),
+               },
+       },
+
+       .cpus = {
+               {
+                       .phys_id = 0,
+               },
+               {
+                       .phys_id = 1,
+               },
+               {
+                       .phys_id = 2,
+               },
+               {
+                       .phys_id = 3,
+               },
+       },
+
+       .mem_regions = {
+               /* RAM */ {
+                       .phys_start = 0x80000000,
+                       .virt_start = 0x80000000,
+                       .size = 0x3fa10000,
+                       .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE |
+                               JAILHOUSE_MEM_EXECUTE,
+               },
+       }
+};
diff --git a/driver/main.c b/driver/main.c
index d0e7f980..d13afeb6 100644
--- a/driver/main.c
+++ b/driver/main.c
@@ -162,6 +162,8 @@ static u64 get_physical_cpu_id(void)
        return read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
 #elif defined(CONFIG_X86)
        return read_apic_id();
+#elif defined(CONFIG_RISCV)
+       return cpuid_to_hartid_map(smp_processor_id());
 #else
 #      error Unsupported architecture
 #endif
diff --git a/hypervisor/arch/riscv/Kbuild b/hypervisor/arch/riscv/Kbuild
new file mode 100644
index 00000000..dd114a6c
--- /dev/null
+++ b/hypervisor/arch/riscv/Kbuild
@@ -0,0 +1,17 @@
+#
+# Jailhouse, a Linux-based partitioning hypervisor
+#
+# Copyright (c) Siemens AG, 2020
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+-include $(GEN_CONFIG_MK)
+
+always-y := lib.a
+
+lib-y := entry.o setup.o dbg-write.o control.o ivshmem.o paging.o pci.o lib.o
diff --git a/hypervisor/arch/riscv/Makefile b/hypervisor/arch/riscv/Makefile
new file mode 100644
index 00000000..c41bed7a
--- /dev/null
+++ b/hypervisor/arch/riscv/Makefile
@@ -0,0 +1,13 @@
+#
+# Jailhouse, a Linux-based partitioning hypervisor
+#
+# Copyright (c) Siemens AG, 2020
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+KBUILD_CFLAGS += -mcmodel=medany
diff --git a/hypervisor/arch/riscv/asm-defines.c 
b/hypervisor/arch/riscv/asm-defines.c
new file mode 100644
index 00000000..17c2f256
--- /dev/null
+++ b/hypervisor/arch/riscv/asm-defines.c
@@ -0,0 +1,19 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/gen-defines.h>
+
+void common(void);
+
+void common(void)
+{
+}
diff --git a/hypervisor/arch/riscv/control.c b/hypervisor/arch/riscv/control.c
new file mode 100644
index 00000000..ab0bb449
--- /dev/null
+++ b/hypervisor/arch/riscv/control.c
@@ -0,0 +1,78 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/control.h>
+
+int arch_cell_create(struct cell *cell)
+{
+       return -ENOSYS;
+}
+
+int arch_map_memory_region(struct cell *cell,
+                          const struct jailhouse_memory *mem)
+{
+       return -ENOSYS;
+}
+
+int arch_unmap_memory_region(struct cell *cell,
+                            const struct jailhouse_memory *mem)
+{
+       return -ENOSYS;
+}
+
+void arch_check_events(void)
+{
+}
+
+void arch_flush_cell_vcpu_caches(struct cell *cell)
+{
+}
+
+void arch_cell_destroy(struct cell *cell)
+{
+}
+
+void arch_cell_reset(struct cell *cell)
+{
+}
+
+void arch_prepare_shutdown(void)
+{
+}
+
+void __attribute__((noreturn)) arch_panic_stop(void)
+{
+       while (1);
+}
+
+void arch_panic_park(void)
+{
+}
+
+void arch_reset_cpu(unsigned int const cpu_id)
+{
+}
+
+void arch_park_cpu(unsigned int cpu_id)
+{
+}
+
+void arch_send_event(struct public_per_cpu *target_data)
+{
+}
+
+// Likely misplaced
+#include <jailhouse/processor.h>
+unsigned int cpu_by_phys_processor_id(u64 phys_id)
+{
+       return -1;
+}
diff --git a/hypervisor/arch/riscv/dbg-write.c 
b/hypervisor/arch/riscv/dbg-write.c
new file mode 100644
index 00000000..6bd75887
--- /dev/null
+++ b/hypervisor/arch/riscv/dbg-write.c
@@ -0,0 +1,17 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/printk.h>
+
+void arch_dbg_write_init(void)
+{
+}
diff --git a/hypervisor/arch/riscv/entry.S b/hypervisor/arch/riscv/entry.S
new file mode 100644
index 00000000..def55516
--- /dev/null
+++ b/hypervisor/arch/riscv/entry.S
@@ -0,0 +1,17 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+       .text
+       .globl arch_entry
+arch_entry:
+       li      a0,-55
+       ret
diff --git a/hypervisor/arch/riscv/include/asm/bitops.h 
b/hypervisor/arch/riscv/include/asm/bitops.h
new file mode 100644
index 00000000..4b7e31b1
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/bitops.h
@@ -0,0 +1,37 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef _JAILHOUSE_ASM_BITOPS_H
+#define _JAILHOUSE_ASM_BITOPS_H
+
+static inline __attribute__((always_inline)) int
+test_bit(unsigned int nr, const volatile unsigned long *addr)
+{
+       return 0;
+}
+
+static inline int atomic_test_and_set_bit(int nr, volatile unsigned long *addr)
+{
+       return 0;
+}
+
+static inline unsigned long ffzl(unsigned long word)
+{
+       return 0;
+}
+
+static inline unsigned long ffsl(unsigned long word)
+{
+       return 0;
+}
+
+#endif /* !_JAILHOUSE_ASM_BITOPS_H */
diff --git a/hypervisor/arch/riscv/include/asm/cell.h 
b/hypervisor/arch/riscv/include/asm/cell.h
new file mode 100644
index 00000000..63ba43ce
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/cell.h
@@ -0,0 +1,24 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef _JAILHOUSE_ASM_CELL_H
+#define _JAILHOUSE_ASM_CELL_H
+
+#include <jailhouse/types.h>
+
+// this shouldn't be here
+#include <jailhouse/cell-config.h>
+
+struct arch_cell {
+};
+
+#endif /* !_JAILHOUSE_ASM_CELL_H */
diff --git a/hypervisor/arch/riscv/include/asm/control.h 
b/hypervisor/arch/riscv/include/asm/control.h
new file mode 100644
index 00000000..e69de29b
diff --git a/hypervisor/arch/riscv/include/asm/ivshmem.h 
b/hypervisor/arch/riscv/include/asm/ivshmem.h
new file mode 100644
index 00000000..03251590
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/ivshmem.h
@@ -0,0 +1,14 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+struct arch_ivshmem_irq_cache {
+};
diff --git a/hypervisor/arch/riscv/include/asm/jailhouse_header.h 
b/hypervisor/arch/riscv/include/asm/jailhouse_header.h
new file mode 100644
index 00000000..a0c22083
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/jailhouse_header.h
@@ -0,0 +1,14 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (C) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#define JAILHOUSE_BASE                 __JH_CONST_UL(0xffffffdfff000000)
+#define JAILHOUSE_BORROW_ROOT_PT       1
diff --git a/hypervisor/arch/riscv/include/asm/mmio.h 
b/hypervisor/arch/riscv/include/asm/mmio.h
new file mode 100644
index 00000000..e69de29b
diff --git a/hypervisor/arch/riscv/include/asm/paging.h 
b/hypervisor/arch/riscv/include/asm/paging.h
new file mode 100644
index 00000000..866f9a3f
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/paging.h
@@ -0,0 +1,54 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef _JAILHOUSE_ASM_PAGING_H
+#define _JAILHOUSE_ASM_PAGING_H
+
+#include <jailhouse/types.h>
+
+#define PAGE_SHIFT             12
+
+#define MAX_PAGE_TABLE_LEVELS  3
+
+#define PAGE_FLAG_FRAMEBUFFER  0
+#define PAGE_FLAG_DEVICE       0
+
+#define PAGE_DEFAULT_FLAGS     0
+#define PAGE_READONLY_FLAGS    0
+#define PAGE_PRESENT_FLAGS     0
+#define PAGE_NONPRESENT_FLAGS  0
+
+#define INVALID_PHYS_ADDR      (~0UL)
+
+#define TEMPORARY_MAPPING_BASE 0x0000008000000000UL
+#define NUM_TEMPORARY_PAGES    16
+
+#define REMAP_BASE             0xffffff8000000000UL
+#define NUM_REMAP_BITMAP_PAGES 4
+
+#define CELL_ROOT_PT_PAGES     1
+
+#ifndef __ASSEMBLY__
+
+typedef u64 *pt_entry_t;
+
+static inline void arch_paging_flush_page_tlbs(unsigned long page_addr)
+{
+}
+
+static inline void arch_paging_flush_cpu_caches(void *addr, long size)
+{
+}
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* !_JAILHOUSE_ASM_PAGING_H */
diff --git a/hypervisor/arch/riscv/include/asm/paging_modes.h 
b/hypervisor/arch/riscv/include/asm/paging_modes.h
new file mode 100644
index 00000000..e69de29b
diff --git a/hypervisor/arch/riscv/include/asm/percpu.h 
b/hypervisor/arch/riscv/include/asm/percpu.h
new file mode 100644
index 00000000..fce6c052
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/percpu.h
@@ -0,0 +1,23 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+// this shouldn't be here
+#include <asm/processor.h>
+
+#define STACK_SIZE                     PAGE_SIZE
+
+#define ARCH_PUBLIC_PERCPU_FIELDS                                      \
+       spinlock_t control_lock;                                        \
+       ;
+
+#define ARCH_PERCPU_FIELDS                                             \
+       ;
diff --git a/hypervisor/arch/riscv/include/asm/processor.h 
b/hypervisor/arch/riscv/include/asm/processor.h
new file mode 100644
index 00000000..8d4b1c60
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/processor.h
@@ -0,0 +1,33 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef _JAILHOUSE_ASM_PROCESSOR_H
+#define _JAILHOUSE_ASM_PROCESSOR_H
+
+#include <jailhouse/types.h>
+
+union registers {
+};
+
+static inline void cpu_relax(void)
+{
+}
+
+static inline void memory_barrier(void)
+{
+}
+
+static inline void memory_load_barrier(void)
+{
+}
+
+#endif /* !_JAILHOUSE_ASM_PROCESSOR_H */
diff --git a/hypervisor/arch/riscv/include/asm/sections.h 
b/hypervisor/arch/riscv/include/asm/sections.h
new file mode 100644
index 00000000..d13a46bd
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/sections.h
@@ -0,0 +1,14 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+/* no special sections */
+#define ARCH_SECTIONS
diff --git a/hypervisor/arch/riscv/include/asm/spinlock.h 
b/hypervisor/arch/riscv/include/asm/spinlock.h
new file mode 100644
index 00000000..a5e707d7
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/spinlock.h
@@ -0,0 +1,27 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef _JAILHOUSE_ASM_SPINLOCK_H
+#define _JAILHOUSE_ASM_SPINLOCK_H
+
+typedef struct {
+} spinlock_t;
+
+static inline void spin_lock(spinlock_t *lock)
+{
+}
+
+static inline void spin_unlock(spinlock_t *lock)
+{
+}
+
+#endif /* !_JAILHOUSE_ASM_SPINLOCK_H */
diff --git a/hypervisor/arch/riscv/include/asm/types.h 
b/hypervisor/arch/riscv/include/asm/types.h
new file mode 100644
index 00000000..b133cf4c
--- /dev/null
+++ b/hypervisor/arch/riscv/include/asm/types.h
@@ -0,0 +1,14 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Konrad Schwarz <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#define MAX_CPUS       __riscv_xlen
+#define BITS_PER_LONG  64
diff --git a/hypervisor/arch/riscv/ivshmem.c b/hypervisor/arch/riscv/ivshmem.c
new file mode 100644
index 00000000..e5dd7973
--- /dev/null
+++ b/hypervisor/arch/riscv/ivshmem.c
@@ -0,0 +1,29 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/entry.h>
+#include <jailhouse/ivshmem.h>
+
+void arch_ivshmem_trigger_interrupt(struct ivshmem_endpoint *ive,
+                                   unsigned int vector)
+{
+}
+
+int arch_ivshmem_update_msix(struct ivshmem_endpoint *ive, unsigned int vector,
+                            bool enabled)
+{
+       return -ENOSYS;
+}
+
+void arch_ivshmem_update_intx(struct ivshmem_endpoint *ive, bool enabled)
+{
+}
diff --git a/hypervisor/arch/riscv/lib.c b/hypervisor/arch/riscv/lib.c
new file mode 100644
index 00000000..5fe45bc7
--- /dev/null
+++ b/hypervisor/arch/riscv/lib.c
@@ -0,0 +1,19 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/processor.h>
+
+// Check if it be moved elsewhere
+unsigned long phys_processor_id(void)
+{
+       return 0;
+}
diff --git a/hypervisor/arch/riscv/paging.c b/hypervisor/arch/riscv/paging.c
new file mode 100644
index 00000000..294ea958
--- /dev/null
+++ b/hypervisor/arch/riscv/paging.c
@@ -0,0 +1,23 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/paging.h>
+
+void arch_paging_init(void)
+{
+}
+
+// Might be misplaced
+unsigned long arch_paging_gphys2phys(unsigned long gphys, unsigned long flags)
+{
+       return 0;
+}
diff --git a/hypervisor/arch/riscv/pci.c b/hypervisor/arch/riscv/pci.c
new file mode 100644
index 00000000..067a7651
--- /dev/null
+++ b/hypervisor/arch/riscv/pci.c
@@ -0,0 +1,49 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/entry.h>
+#include <jailhouse/pci.h>
+
+u32 arch_pci_read_config(u16 bdf, u16 address, unsigned int size)
+{
+       return 0;
+}
+
+void arch_pci_write_config(u16 bdf, u16 address, u32 value, unsigned int size)
+{
+}
+
+int arch_pci_add_physical_device(struct cell *cell, struct pci_device *device)
+{
+       return -ENOSYS;
+}
+
+void arch_pci_remove_physical_device(struct pci_device *device)
+{
+}
+
+void arch_pci_set_suppress_msi(struct pci_device *device,
+                              const struct jailhouse_pci_capability *cap,
+                              bool suppress)
+{
+}
+
+int arch_pci_update_msi(struct pci_device *device,
+                       const struct jailhouse_pci_capability *cap)
+{
+       return -ENOSYS;
+}
+
+int arch_pci_update_msix_vector(struct pci_device *device, unsigned int index)
+{
+       return -ENOSYS;
+}
diff --git a/hypervisor/arch/riscv/setup.c b/hypervisor/arch/riscv/setup.c
new file mode 100644
index 00000000..53cdce80
--- /dev/null
+++ b/hypervisor/arch/riscv/setup.c
@@ -0,0 +1,32 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/entry.h>
+
+int arch_init_early(void)
+{
+       return -ENOSYS;
+}
+
+int arch_cpu_init(struct per_cpu *cpu_data)
+{
+       return -ENOSYS;
+}
+
+void __attribute__((noreturn)) arch_cpu_activate_vmm(void)
+{
+       while (1);
+}
+
+void arch_cpu_restore(unsigned int cpu_id, int return_code)
+{
+}
diff --git a/include/arch/riscv/asm/jailhouse_hypercall.h 
b/include/arch/riscv/asm/jailhouse_hypercall.h
new file mode 100644
index 00000000..7d54047c
--- /dev/null
+++ b/include/arch/riscv/asm/jailhouse_hypercall.h
@@ -0,0 +1,68 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Alternatively, you can use or redistribute this file under the following
+ * BSD license:
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#define JAILHOUSE_NUM_CPU_STATS                        
JAILHOUSE_GENERIC_CPU_STATS
+
+#ifndef __ASSEMBLY__
+
+static inline __u32 jailhouse_call(__u32 num)
+{
+       return -ENOSYS;
+}
+
+static inline __u32 jailhouse_call_arg1(__u32 num, __u32 arg1)
+{
+       return -ENOSYS;
+}
+
+static inline __u32 jailhouse_call_arg2(__u32 num, __u32 arg1, __u32 arg2)
+{
+       return -ENOSYS;
+}
+
+struct jailhouse_comm_region {
+        COMM_REGION_GENERIC_HEADER;
+} __attribute__((packed));
+
+static inline void
+jailhouse_send_msg_to_cell(struct jailhouse_comm_region *comm_region,
+                          __u32 msg)
+{
+}
+
+#endif /* !__ASSEMBLY__ */
diff --git a/inmates/demos/riscv/Makefile b/inmates/demos/riscv/Makefile
new file mode 100644
index 00000000..e69de29b
diff --git a/inmates/lib/riscv/Makefile b/inmates/lib/riscv/Makefile
new file mode 100644
index 00000000..e69de29b
diff --git a/inmates/tests/riscv/Makefile b/inmates/tests/riscv/Makefile
new file mode 100644
index 00000000..e69de29b
diff --git a/inmates/tools/riscv/Makefile b/inmates/tools/riscv/Makefile
new file mode 100644
index 00000000..e69de29b
diff --git a/scripts/include.mk b/scripts/include.mk
index d0139d8e..35855e7d 100644
--- a/scripts/include.mk
+++ b/scripts/include.mk
@@ -67,3 +67,6 @@ endif
 ifeq ($(ARCH),aarch64)
 override ARCH = arm64
 endif
+ifeq ($(ARCH),riscv64)
+override ARCH = riscv
+endif
-- 
2.36.1

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20220627131329.3659-21-ralf.ramsauer%40oth-regensburg.de.

Reply via email to