Skip to contentSkip to conversation

xen: beginning support for RISC-V

RFC PATCH In review Bobby Eshleman 7 participants 49 messages Jan 22, 2020 – Jun 30, 2020 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover xen: beginning support for RISC-V

Hey everybody,

This is an RFC patchset for the very beginnings of adding RISC-V support to Xen. This RFC is really just to start a dialogue about supporting RISC-V and align with the Xen project and community before going further. For that reason, it is very rough and very incomplete.

My name is Bobby Eshleman, I'm a software engineer at
Star Lab / Wind River on the ARM team, mostly having worked in the Linux kernel. I've also been involved a good amount with Xen on ARM here, mostly dealing with tooling, deployment, and testing. A lot of this patchset is heavily inspired by the Xen/ARM source code (particularly the early setup up code).

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

Because the ARM and RISC-V use cases will likely bear resemblance, the RISC-V port should probably respect the design considerations that have been laid out and respected by Xen on ARM for dom0less, safety certification, etc... My inclination has been to initially target or prioritize dom0less (without excluding dom0full) and use the ARM dom0less implementation as a model to follow. I'd love feedback on this point and on how the Xen project might envision a RISC-V implementation.

This patchset has _some_ code for future support for 32-bit, but currently my focus is on 64-bit.

Again, this is a very, very rough and totally incomplete patchset. My goal here is just to gauge community interest, begin discussing what Xen on RISC-V may look like, receive feedback, and see if I'm heading in the right direction.

My big questions are:
Does the Xen project have interest in RISC-V? What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Alistair Francis (20):
HACK: OE Build changes
HACK: Makefile: Don't build Xen tools
riscv: makefiles and Kconfig
riscv: Add riscv to tools/libxc header files
riscv: Add asm-offsets.c
riscv: Add delay.c
riscv: Add domain.c
riscv: Add domctl.c
riscv: Add guestcopy.c
riscv: Add time.c
riscv: Add smp.c
riscv: Add shutdown.c
riscv: Add traps.c
riscv: Add irq.c
riscv: Add vm_event.c
riscv: Add p2m.c
riscv: Add the lib directory
riscv: Add smpboot.c
riscv: Add percpu.c
riscv: Add sysctl.c

Bobby Eshleman (3):
riscv: header files
riscv: early setup code
riscv: Add iommu.c

 Makefile                                 |  13 +-
 config/StdGNU.mk                         |  12 +-
 config/riscv64.mk                        |   7 +
 tools/configure                          |  32 +-
 tools/firmware/Makefile                  |  12 +-
 tools/libxc/include/xenctrl.h            |   7 +
 tools/libxc/xc_core.h                    |   2 +
 tools/libxc/xc_core_riscv.h              |  57 ++
 xen/Makefile                             |   2 +-
 xen/Rules.mk                             |   2 +-
 xen/arch/Kconfig                         |   1 +
 xen/arch/riscv/Kconfig                   |  36 +
 xen/arch/riscv/Makefile                  |  62 ++
 xen/arch/riscv/Rules.mk                  |  55 ++
 xen/arch/riscv/asm-offsets.c             |  38 +
 xen/arch/riscv/configs/riscv32_defconfig |   0
 xen/arch/riscv/configs/riscv64_defconfig |   0
 xen/arch/riscv/delay.c                   | 114 +++
 xen/arch/riscv/domain.c                  | 273 +++++++
 xen/arch/riscv/domctl.c                  |  53 ++
 xen/arch/riscv/guestcopy.c               | 158 ++++
 xen/arch/riscv/head.S                    | 180 +++++
 xen/arch/riscv/irq.c                     | 107 +++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++
 xen/arch/riscv/mm.c                      | 925 +++++++++++++++++++++++
 xen/arch/riscv/p2m.c                     | 261 +++++++
 xen/arch/riscv/percpu.c                  |  84 ++
 xen/arch/riscv/platforms/Kconfig         |  31 +
 xen/arch/riscv/setup.c                   | 122 +++
 xen/arch/riscv/shutdown.c                |  24 +
 xen/arch/riscv/smp.c                     |  41 +
 xen/arch/riscv/smpboot.c                 | 114 +++
 xen/arch/riscv/sysctl.c                  |  31 +
 xen/arch/riscv/time.c                    |  74 ++
 xen/arch/riscv/traps.c                   |  56 ++
 xen/arch/riscv/vm_event.c                |  42 +
 xen/arch/riscv/xen.lds.S                 | 262 +++++++
 xen/drivers/passthrough/Makefile         |   1 +
 xen/drivers/passthrough/riscv/Makefile   |   1 +
 xen/drivers/passthrough/riscv/iommu.c    |  74 ++
 xen/include/asm-riscv/altp2m.h           |  39 +
 xen/include/asm-riscv/asm.h              |  76 ++
 xen/include/asm-riscv/atomic.h           | 249 ++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++
 xen/include/asm-riscv/bug.h              |  59 ++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 +
 xen/include/asm-riscv/cmpxchg.h          | 382 ++++++++++
 xen/include/asm-riscv/config.h           | 203 +++++
 xen/include/asm-riscv/csr.h              | 117 +++
 xen/include/asm-riscv/current.h          |  50 ++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  28 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 +
 xen/include/asm-riscv/domain.h           |  85 +++
 xen/include/asm-riscv/event.h            |  42 +
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  56 ++
 xen/include/asm-riscv/grant_table.h      |  93 +++
 xen/include/asm-riscv/guest_access.h     | 164 ++++
 xen/include/asm-riscv/guest_atomics.h    |  62 ++
 xen/include/asm-riscv/hardirq.h          |  27 +
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +
 xen/include/asm-riscv/io.h               | 283 +++++++
 xen/include/asm-riscv/iocap.h            |  16 +
 xen/include/asm-riscv/iommu.h            |  49 ++
 xen/include/asm-riscv/irq.h              |  58 ++
 xen/include/asm-riscv/mem_access.h       |  35 +
 xen/include/asm-riscv/mm.h               | 308 ++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++
 xen/include/asm-riscv/nospec.h           |  25 +
 xen/include/asm-riscv/numa.h             |  41 +
 xen/include/asm-riscv/p2m.h              | 410 ++++++++++
 xen/include/asm-riscv/page.h             | 327 ++++++++
 xen/include/asm-riscv/paging.h           |  16 +
 xen/include/asm-riscv/pci.h              |  31 +
 xen/include/asm-riscv/percpu.h           |  34 +
 xen/include/asm-riscv/pgtable-bits.h     |  53 ++
 xen/include/asm-riscv/processor.h        |  60 ++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  42 +
 xen/include/asm-riscv/riscv_encoding.h   | 682 +++++++++++++++++
 xen/include/asm-riscv/setup.h            |  16 +
 xen/include/asm-riscv/smp.h              |  50 ++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  13 +
 xen/include/asm-riscv/string.h           |  28 +
 xen/include/asm-riscv/sysregs.h          |  14 +
 xen/include/asm-riscv/system.h           |  96 +++
 xen/include/asm-riscv/time.h             |  60 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  73 ++
 xen/include/asm-riscv/vm_event.h         |  61 ++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 181 +++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 103 files changed, 9064 insertions(+), 42 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 tools/libxc/xc_core_riscv.h
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/asm-offsets.c
 create mode 100644 xen/arch/riscv/configs/riscv32_defconfig
 create mode 100644 xen/arch/riscv/configs/riscv64_defconfig
 create mode 100644 xen/arch/riscv/delay.c
 create mode 100644 xen/arch/riscv/domain.c
 create mode 100644 xen/arch/riscv/domctl.c
 create mode 100644 xen/arch/riscv/guestcopy.c
 create mode 100644 xen/arch/riscv/head.S
 create mode 100644 xen/arch/riscv/irq.c
 create mode 100644 xen/arch/riscv/lib/Makefile
 create mode 100644 xen/arch/riscv/lib/find_next_bit.c
 create mode 100644 xen/arch/riscv/mm.c
 create mode 100644 xen/arch/riscv/p2m.c
 create mode 100644 xen/arch/riscv/percpu.c
 create mode 100644 xen/arch/riscv/platforms/Kconfig
 create mode 100644 xen/arch/riscv/setup.c
 create mode 100644 xen/arch/riscv/shutdown.c
 create mode 100644 xen/arch/riscv/smp.c
 create mode 100644 xen/arch/riscv/smpboot.c
 create mode 100644 xen/arch/riscv/sysctl.c
 create mode 100644 xen/arch/riscv/time.c
 create mode 100644 xen/arch/riscv/traps.c
 create mode 100644 xen/arch/riscv/vm_event.c
 create mode 100644 xen/arch/riscv/xen.lds.S
 create mode 100644 xen/drivers/passthrough/riscv/Makefile
 create mode 100644 xen/drivers/passthrough/riscv/iommu.c
 create mode 100644 xen/include/asm-riscv/altp2m.h
 create mode 100644 xen/include/asm-riscv/asm.h
 create mode 100644 xen/include/asm-riscv/atomic.h
 create mode 100644 xen/include/asm-riscv/bitops.h
 create mode 100644 xen/include/asm-riscv/bug.h
 create mode 100644 xen/include/asm-riscv/byteorder.h
 create mode 100644 xen/include/asm-riscv/cache.h
 create mode 100644 xen/include/asm-riscv/cmpxchg.h
 create mode 100644 xen/include/asm-riscv/config.h
 create mode 100644 xen/include/asm-riscv/csr.h
 create mode 100644 xen/include/asm-riscv/current.h
 create mode 100644 xen/include/asm-riscv/debugger.h
 create mode 100644 xen/include/asm-riscv/delay.h
 create mode 100644 xen/include/asm-riscv/desc.h
 create mode 100644 xen/include/asm-riscv/device.h
 create mode 100644 xen/include/asm-riscv/div64.h
 create mode 100644 xen/include/asm-riscv/domain.h
 create mode 100644 xen/include/asm-riscv/event.h
 create mode 100644 xen/include/asm-riscv/fence.h
 create mode 100644 xen/include/asm-riscv/flushtlb.h
 create mode 100644 xen/include/asm-riscv/grant_table.h
 create mode 100644 xen/include/asm-riscv/guest_access.h
 create mode 100644 xen/include/asm-riscv/guest_atomics.h
 create mode 100644 xen/include/asm-riscv/hardirq.h
 create mode 100644 xen/include/asm-riscv/hypercall.h
 create mode 100644 xen/include/asm-riscv/init.h
 create mode 100644 xen/include/asm-riscv/io.h
 create mode 100644 xen/include/asm-riscv/iocap.h
 create mode 100644 xen/include/asm-riscv/iommu.h
 create mode 100644 xen/include/asm-riscv/irq.h
 create mode 100644 xen/include/asm-riscv/mem_access.h
 create mode 100644 xen/include/asm-riscv/mm.h
 create mode 100644 xen/include/asm-riscv/monitor.h
 create mode 100644 xen/include/asm-riscv/nospec.h
 create mode 100644 xen/include/asm-riscv/numa.h
 create mode 100644 xen/include/asm-riscv/p2m.h
 create mode 100644 xen/include/asm-riscv/page.h
 create mode 100644 xen/include/asm-riscv/paging.h
 create mode 100644 xen/include/asm-riscv/pci.h
 create mode 100644 xen/include/asm-riscv/percpu.h
 create mode 100644 xen/include/asm-riscv/pgtable-bits.h
 create mode 100644 xen/include/asm-riscv/processor.h
 create mode 100644 xen/include/asm-riscv/random.h
 create mode 100644 xen/include/asm-riscv/regs.h
 create mode 100644 xen/include/asm-riscv/riscv_encoding.h
 create mode 100644 xen/include/asm-riscv/setup.h
 create mode 100644 xen/include/asm-riscv/smp.h
 create mode 100644 xen/include/asm-riscv/softirq.h
 create mode 100644 xen/include/asm-riscv/spinlock.h
 create mode 100644 xen/include/asm-riscv/string.h
 create mode 100644 xen/include/asm-riscv/sysregs.h
 create mode 100644 xen/include/asm-riscv/system.h
 create mode 100644 xen/include/asm-riscv/time.h
 create mode 100644 xen/include/asm-riscv/trace.h
 create mode 100644 xen/include/asm-riscv/types.h
 create mode 100644 xen/include/asm-riscv/vm_event.h
 create mode 100644 xen/include/asm-riscv/xenoprof.h
 create mode 100644 xen/include/public/arch-riscv.h
 create mode 100644 xen/include/public/arch-riscv/hvm/save.h
Signature · 45 lines
2.25.0

The source code can be found on github:
	https://github.com/beshleman/xen/tree/port-to-risc-v

The patchset only targets the QEMU virt board and it is tested on
Alistair Francis's patchset for QEMU with RISC-V hypervisor extensions
v0.5, found here:
	https://github.com/alistair23/qemu/tree/mainline/alistair/riscv-hyp-ext-v0.5.next

QEMU is built with:
	git clone --single-branch --branch mainline/alistair/riscv-hyp-ext-v0.5.next \
		https://github.com/alistair23/qemu.git
        cd qemu
        mkdir build && cd build
        ../configure --target-list=riscv64-softmmu
	make -j$(nproc) && make install

The bootloader used is the standard OpenSBI, built with the command:
	CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM=qemu/virt FW_PAYLOAD_PATH=../xen/xen/xen make

Xen/RISC-V is built with:
	XEN_TARGET_ARCH=riscv64 CROSS_COMPILE=riscv64-unknown-linux-gnu- make build

Xen may be ran with the following command:
	qemu-system-riscv64 -cpu rv64,x-h=true -M virt -m 512M -display none \
		-serial stdio -kernel \
		opensbi/build/platform/qemu/virt/firmware/fw_payload.elf

Also, shoutout to Alistair Francis (from Western Digital) for getting
the ball rolling and doing a ton of the groundwork with
Makefile/Kconfig, a ton of the RISC-V specific header files, and also
the QEMU RISC-V H extension support, and Dan Robertson (a colleague of
mine at Star Lab) for help in forward porting a number of patches that
were out-of-sync with upstream.


Thanks,
Bobby Eshleman


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

RFC PATCH 1/23 HACK: OE Build changes

From: Alistair Francis <[email protected]>

---
 config/StdGNU.mk        | 12 ++++++------
 tools/configure         | 32 ++++++++++++++++----------------
 tools/firmware/Makefile | 12 ++++++------
 3 files changed, 28 insertions(+), 28 deletions(-)
config/StdGNU.mk +6 -6
index 039274ea61..a5bbde1e02 100644
@@ -1,15 +1,15 @@
 AS         = $(CROSS_COMPILE)as
-LD         = $(CROSS_COMPILE)ld
+LD         ?= $(CROSS_COMPILE)ld
 ifeq ($(clang),y)
-CC         = $(CROSS_COMPILE)clang
-CXX        = $(CROSS_COMPILE)clang++
+CC         ?= $(CROSS_COMPILE)clang
+CXX        ?= $(CROSS_COMPILE)clang++
 LD_LTO     = $(CROSS_COMPILE)llvm-ld
 else
-CC         = $(CROSS_COMPILE)gcc
-CXX        = $(CROSS_COMPILE)g++
+CC         ?= $(CROSS_COMPILE)gcc
+CXX        ?= $(CROSS_COMPILE)g++
 LD_LTO     = $(CROSS_COMPILE)ld
 endif
-CPP        = $(CC) -E
+CPP        ?= $(CC) -E
 AR         = $(CROSS_COMPILE)ar
 RANLIB     = $(CROSS_COMPILE)ranlib
 NM         = $(CROSS_COMPILE)nm
tools/configure +16 -16
index 977a8837c3..59946c1524 100755
@@ -9257,12 +9257,12 @@ if test -n "$SYSTEMD_CFLAGS"; then
     pkg_cv_SYSTEMD_CFLAGS="$SYSTEMD_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd-daemon\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd-daemon") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libsystemd") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_CFLAGS=`$PKG_CONFIG --cflags "libsystemd-daemon" 2>/dev/null`
+  pkg_cv_SYSTEMD_CFLAGS=`$PKG_CONFIG --cflags "libsystemd" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -9274,12 +9274,12 @@ if test -n "$SYSTEMD_LIBS"; then
     pkg_cv_SYSTEMD_LIBS="$SYSTEMD_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd-daemon\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd-daemon") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libsystemd") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_LIBS=`$PKG_CONFIG --libs "libsystemd-daemon" 2>/dev/null`
+  pkg_cv_SYSTEMD_LIBS=`$PKG_CONFIG --libs "libsystemd" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -9300,9 +9300,9 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libsystemd-daemon" 2>&1`
+	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libsystemd" 2>&1`
         else
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libsystemd-daemon" 2>&1`
+	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libsystemd" 2>&1`
         fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$SYSTEMD_PKG_ERRORS" >&5
@@ -9483,12 +9483,12 @@ if test -n "$SYSTEMD_CFLAGS"; then
     pkg_cv_SYSTEMD_CFLAGS="$SYSTEMD_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd-daemon\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd-daemon") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libsystemd") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_CFLAGS=`$PKG_CONFIG --cflags "libsystemd-daemon" 2>/dev/null`
+  pkg_cv_SYSTEMD_CFLAGS=`$PKG_CONFIG --cflags "libsystemd" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -9500,12 +9500,12 @@ if test -n "$SYSTEMD_LIBS"; then
     pkg_cv_SYSTEMD_LIBS="$SYSTEMD_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd-daemon\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd-daemon") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libsystemd") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_LIBS=`$PKG_CONFIG --libs "libsystemd-daemon" 2>/dev/null`
+  pkg_cv_SYSTEMD_LIBS=`$PKG_CONFIG --libs "libsystemd" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
@@ -9526,9 +9526,9 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libsystemd-daemon" 2>&1`
+	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libsystemd" 2>&1`
         else
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libsystemd-daemon" 2>&1`
+	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libsystemd" 2>&1`
         fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$SYSTEMD_PKG_ERRORS" >&5
tools/firmware/Makefile +6 -6
index 809a5fd025..87cbe7e091 100644
@@ -20,13 +20,13 @@ SEABIOSLD ?= $(LD)
 SEABIOS_EXTRAVERSION ?= "-Xen"
 
 ovmf-dir:
-	GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) ovmf-dir
+	GIT="$(GIT)" $(XEN_ROOT)/scripts/git-checkout.sh $(OVMF_UPSTREAM_URL) $(OVMF_UPSTREAM_REVISION) ovmf-dir
 	cp ovmf-makefile ovmf-dir/Makefile;
 
 seabios-dir:
-	GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh $(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) seabios-dir
+	GIT="$(GIT)" $(XEN_ROOT)/scripts/git-checkout.sh $(SEABIOS_UPSTREAM_URL) $(SEABIOS_UPSTREAM_REVISION) seabios-dir
 	cp seabios-config seabios-dir/.config;
-	$(MAKE) -C seabios-dir olddefconfig CC=$(SEABIOSCC) LD=$(SEABIOSLD)
+	$(MAKE) -C seabios-dir olddefconfig CC="$(SEABIOSCC)" LD="$(SEABIOSLD)"
 	rm -f seabios-dir/.version
 	echo '$(SEABIOS_UPSTREAM_REVISION)' > seabios-dir/.version
 
@@ -41,7 +41,7 @@ ifeq ($(CONFIG_ROMBIOS),y)
 	false ; \
 	fi
 endif
-	$(MAKE) CC=$(CC) PYTHON=$(PYTHON) subdirs-$@
+	$(MAKE) CC="$(CC)" PYTHON="$(PYTHON)" subdirs-$@
 
 .PHONY: install
 install: all
@@ -119,7 +119,7 @@ seabios-dir-force-update: seabios-dir
 
 subdir-clean-seabios-dir:
 	set -e; if test -d seabios-dir/.; then \
-		$(MAKE) -C seabios-dir CC=$(SEABIOSCC) LD=$(SEABIOSLD) clean; \
+		$(MAKE) -C seabios-dir CC="$(SEABIOSCC)" LD="$(SEABIOSLD)" clean; \
 	fi
 
 subtree-force-update:
@@ -135,4 +135,4 @@ subtree-force-update-all:
 	$(MAKE) ovmf-dir-force-update
 
 subdir-all-seabios-dir: seabios-dir
-	$(MAKE) -C $< CC=$(SEABIOSCC) LD=$(SEABIOSLD) PYTHON=$(PYTHON) EXTRAVERSION=$(SEABIOS_EXTRAVERSION) all;
+	$(MAKE) -C $< CC="$(SEABIOSCC)" LD="$(SEABIOSLD)" PYTHON="$(PYTHON)" EXTRAVERSION="$(SEABIOS_EXTRAVERSION)" all;
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

RFC PATCH 2/23 HACK: Makefile: Don't build Xen tools

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 Makefile | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
Makefile +1 -12
index 512d6b73c8..7936f3a368 100644
@@ -7,7 +7,7 @@
 all: dist
 
 -include config/Toplevel.mk
-SUBSYSTEMS?=xen tools stubdom docs
+SUBSYSTEMS=xen stubdom docs
 TARGS_DIST=$(patsubst %, dist-%, $(SUBSYSTEMS))
 TARGS_INSTALL=$(patsubst %, install-%, $(SUBSYSTEMS))
 TARGS_UNINSTALL=$(patsubst %, uninstall-%, $(SUBSYSTEMS))
@@ -20,12 +20,6 @@ include Config.mk
 
 .PHONY: mini-os-dir
 mini-os-dir:
-	if [ ! -d $(XEN_ROOT)/extras/mini-os ]; then \
-		GIT=$(GIT) $(XEN_ROOT)/scripts/git-checkout.sh \
-			$(MINIOS_UPSTREAM_URL) \
-			$(MINIOS_UPSTREAM_REVISION) \
-			$(XEN_ROOT)/extras/mini-os ; \
-	fi
 
 .PHONY: mini-os-dir-force-update
 mini-os-dir-force-update: mini-os-dir
@@ -131,14 +125,9 @@ install-xen:
 
 .PHONY: install-tools
 install-tools: install-tools-public-headers
-	$(MAKE) -C tools install
 
 .PHONY: install-stubdom
 install-stubdom: mini-os-dir install-tools
-	$(MAKE) -C stubdom install
-ifeq (x86_64,$(XEN_TARGET_ARCH))
-	XEN_TARGET_ARCH=x86_32 $(MAKE) -C stubdom install-grub
-endif
 
 .PHONY: tools/firmware/seabios-dir-force-update
 tools/firmware/seabios-dir-force-update:
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

RFC PATCH 3/23 riscv: makefiles and Kconfig

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 config/riscv64.mk                        |   7 +
 xen/Makefile                             |   2 +-
 xen/Rules.mk                             |   2 +-
 xen/arch/Kconfig                         |   1 +
 xen/arch/riscv/Kconfig                   |  36 ++++
 xen/arch/riscv/Makefile                  |  62 ++++++
 xen/arch/riscv/Rules.mk                  |  55 +++++
 xen/arch/riscv/configs/riscv32_defconfig |   0
 xen/arch/riscv/configs/riscv64_defconfig |   0
 xen/arch/riscv/platforms/Kconfig         |  31 +++
 xen/arch/riscv/xen.lds.S                 | 262 +++++++++++++++++++++++
 xen/drivers/passthrough/Makefile         |   1 +
 xen/drivers/passthrough/riscv/Makefile   |   1 +
 13 files changed, 458 insertions(+), 2 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/configs/riscv32_defconfig
 create mode 100644 xen/arch/riscv/configs/riscv64_defconfig
 create mode 100644 xen/arch/riscv/platforms/Kconfig
 create mode 100644 xen/arch/riscv/xen.lds.S
 create mode 100644 xen/drivers/passthrough/riscv/Makefile
config/riscv64.mk new file +7 -0
new file mode 100644
index 0000000000..0ec97838f9
@@ -0,0 +1,7 @@
+CONFIG_RISCV := y
+CONFIG_RISCV_64 := y
+CONFIG_RISCV_$(XEN_OS) := y
+
+CONFIG_XEN_INSTALL_SUFFIX :=
+
+CFLAGS +=
xen/Makefile +1 -1
index f36a5bc6c0..0c47899127 100644
@@ -27,7 +27,7 @@ MAKEFLAGS += -rR
 EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
 
 ARCH=$(XEN_TARGET_ARCH)
-SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' -e s'/riscv\(32\|64\)/riscv/g')
 
 # Don't break if the build process wasn't called from the top level
 # we need XEN_TARGET_ARCH to generate the proper config
xen/Rules.mk +1 -1
index 5aba841b0a..1556266679 100644
@@ -29,7 +29,7 @@ endif
 # Set ARCH/SUBARCH appropriately.
 override TARGET_SUBARCH  := $(XEN_TARGET_ARCH)
 override TARGET_ARCH     := $(shell echo $(XEN_TARGET_ARCH) | \
-                              sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+                              sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' -e s'/riscv\(32\|64\)/riscv/g')
 
 TARGET := $(BASEDIR)/xen
 
xen/arch/Kconfig +1 -0
index 1954d1c5c1..985c023ca6 100644
@@ -7,5 +7,6 @@ config NR_CPUS
 	default "4" if ARM && QEMU
 	default "4" if ARM && MPSOC
 	default "128" if ARM
+	default "4" if RISCV
 	---help---
 	  Specifies the maximum number of physical CPUs which Xen will support.
xen/arch/riscv/Kconfig new file +36 -0
new file mode 100644
index 0000000000..8bea40af60
@@ -0,0 +1,36 @@
+config 64BIT
+	bool
+	default ARCH != "riscv32"
+	help
+	  Say yes to build a 64-bit Xen
+	  Say no to build a 32-bit Xen
+
+config RISCV_32
+	def_bool y
+	depends on !64BIT
+
+config RISCV_64
+	def_bool y
+	depends on 64BIT
+
+config RISCV
+	def_bool y
+	select HAS_PDX
+	select HAS_PASSTHROUGH
+
+config ARCH_DEFCONFIG
+	string
+	default "arch/riscv/configs/arm32_defconfig" if RISCV_32
+	default "arch/riscv/configs/arm64_defconfig" if RISCV_64
+
+menu "Architecture Features"
+
+source "arch/Kconfig"
+
+endmenu
+
+source "arch/riscv/platforms/Kconfig"
+
+source "common/Kconfig"
+
+source "drivers/Kconfig"
xen/arch/riscv/Makefile new file +62 -0

63 lines not on this page · raw message

xen/arch/riscv/Rules.mk new file +55 -0

55 lines not on this page · raw message

xen/arch/riscv/configs/riscv32_defconfig new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/configs/riscv64_defconfig new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/platforms/Kconfig new file +31 -0
new file mode 100644
index 0000000000..6959ec35a2
@@ -0,0 +1,31 @@
+choice
+	prompt "Platform Support"
+	default ALL_PLAT
+	---help---
+	Choose which hardware platform to enable in Xen.
+
+	If unsure, choose ALL_PLAT.
+
+config ALL_PLAT
+	bool "All Platforms"
+	---help---
+	Enable support for all available hardware platforms. It doesn't
+	automatically select any of the related drivers.
+
+config QEMU
+	bool "QEMU RISC-V virt machine support"
+	depends on RISCV
+	select HAS_NS16550
+	---help---
+	Enable all the required drivers for QEMU RISC-V virt emulated
+	machine.
+
+endchoice
+
+config ALL64_PLAT
+	bool
+	default (ALL_PLAT && RISCV_64)
+
+config ALL32_PLAT
+	bool
+	default (ALL_PLAT && RISCV_32)
xen/arch/riscv/xen.lds.S new file +262 -0

262 lines not on this page · raw message

xen/drivers/passthrough/Makefile +1 -0
index d50ab188c8..3c8ef68418 100644
@@ -2,6 +2,7 @@ subdir-$(CONFIG_X86) += vtd
 subdir-$(CONFIG_X86) += amd
 subdir-$(CONFIG_X86) += x86
 subdir-$(CONFIG_ARM) += arm
+subdir-$(CONFIG_RISCV) += riscv
 
 obj-y += iommu.o
 obj-$(CONFIG_HAS_PCI) += pci.o
xen/drivers/passthrough/riscv/Makefile new file +1 -0
new file mode 100644
index 0000000000..0484b796b0
@@ -0,0 +1 @@
+obj-y += iommu.o
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

RFC PATCH 4/23 riscv: header files

In reply to Bobby Eshleman

This patch adds all of the header files.

The address spaces defined in config.h are somewhat modeled after ARM64 but due to the smaller address width for RISC-V SV39 the address spaces there is definitely a difference. My choices here were pretty arbitrary and I'd some feedback on them.

---
 xen/include/asm-riscv/altp2m.h           |  39 ++
 xen/include/asm-riscv/asm.h              |  76 +++
 xen/include/asm-riscv/atomic.h           | 249 +++++++++
 xen/include/asm-riscv/bitops.h           | 331 +++++++++++
 xen/include/asm-riscv/bug.h              |  59 ++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 +
 xen/include/asm-riscv/cmpxchg.h          | 382 +++++++++++++
 xen/include/asm-riscv/config.h           | 203 +++++++
 xen/include/asm-riscv/csr.h              | 117 ++++
 xen/include/asm-riscv/current.h          |  50 ++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  28 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 +
 xen/include/asm-riscv/domain.h           |  85 +++
 xen/include/asm-riscv/event.h            |  42 ++
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  56 ++
 xen/include/asm-riscv/grant_table.h      |  93 ++++
 xen/include/asm-riscv/guest_access.h     | 164 ++++++
 xen/include/asm-riscv/guest_atomics.h    |  62 +++
 xen/include/asm-riscv/hardirq.h          |  27 +
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 ++
 xen/include/asm-riscv/io.h               | 283 ++++++++++
 xen/include/asm-riscv/iocap.h            |  16 +
 xen/include/asm-riscv/iommu.h            |  49 ++
 xen/include/asm-riscv/irq.h              |  58 ++
 xen/include/asm-riscv/mem_access.h       |  35 ++
 xen/include/asm-riscv/mm.h               | 308 ++++++++++
 xen/include/asm-riscv/monitor.h          |  65 +++
 xen/include/asm-riscv/nospec.h           |  25 +
 xen/include/asm-riscv/numa.h             |  41 ++
 xen/include/asm-riscv/p2m.h              | 410 ++++++++++++++
 xen/include/asm-riscv/page.h             | 327 +++++++++++
 xen/include/asm-riscv/paging.h           |  16 +
 xen/include/asm-riscv/pci.h              |  31 ++
 xen/include/asm-riscv/percpu.h           |  34 ++
 xen/include/asm-riscv/pgtable-bits.h     |  53 ++
 xen/include/asm-riscv/processor.h        |  60 ++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  42 ++
 xen/include/asm-riscv/riscv_encoding.h   | 682 +++++++++++++++++++++++
 xen/include/asm-riscv/setup.h            |  16 +
 xen/include/asm-riscv/smp.h              |  50 ++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  13 +
 xen/include/asm-riscv/string.h           |  28 +
 xen/include/asm-riscv/sysregs.h          |  14 +
 xen/include/asm-riscv/system.h           |  96 ++++
 xen/include/asm-riscv/time.h             |  60 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  73 +++
 xen/include/asm-riscv/vm_event.h         |  61 ++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 181 ++++++
 xen/include/public/arch-riscv/hvm/save.h |  39 ++
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 62 files changed, 5455 insertions(+)
 create mode 100644 xen/include/asm-riscv/altp2m.h
 create mode 100644 xen/include/asm-riscv/asm.h
 create mode 100644 xen/include/asm-riscv/atomic.h
 create mode 100644 xen/include/asm-riscv/bitops.h
 create mode 100644 xen/include/asm-riscv/bug.h
 create mode 100644 xen/include/asm-riscv/byteorder.h
 create mode 100644 xen/include/asm-riscv/cache.h
 create mode 100644 xen/include/asm-riscv/cmpxchg.h
 create mode 100644 xen/include/asm-riscv/config.h
 create mode 100644 xen/include/asm-riscv/csr.h
 create mode 100644 xen/include/asm-riscv/current.h
 create mode 100644 xen/include/asm-riscv/debugger.h
 create mode 100644 xen/include/asm-riscv/delay.h
 create mode 100644 xen/include/asm-riscv/desc.h
 create mode 100644 xen/include/asm-riscv/device.h
 create mode 100644 xen/include/asm-riscv/div64.h
 create mode 100644 xen/include/asm-riscv/domain.h
 create mode 100644 xen/include/asm-riscv/event.h
 create mode 100644 xen/include/asm-riscv/fence.h
 create mode 100644 xen/include/asm-riscv/flushtlb.h
 create mode 100644 xen/include/asm-riscv/grant_table.h
 create mode 100644 xen/include/asm-riscv/guest_access.h
 create mode 100644 xen/include/asm-riscv/guest_atomics.h
 create mode 100644 xen/include/asm-riscv/hardirq.h
 create mode 100644 xen/include/asm-riscv/hypercall.h
 create mode 100644 xen/include/asm-riscv/init.h
 create mode 100644 xen/include/asm-riscv/io.h
 create mode 100644 xen/include/asm-riscv/iocap.h
 create mode 100644 xen/include/asm-riscv/iommu.h
 create mode 100644 xen/include/asm-riscv/irq.h
 create mode 100644 xen/include/asm-riscv/mem_access.h
 create mode 100644 xen/include/asm-riscv/mm.h
 create mode 100644 xen/include/asm-riscv/monitor.h
 create mode 100644 xen/include/asm-riscv/nospec.h
 create mode 100644 xen/include/asm-riscv/numa.h
 create mode 100644 xen/include/asm-riscv/p2m.h
 create mode 100644 xen/include/asm-riscv/page.h
 create mode 100644 xen/include/asm-riscv/paging.h
 create mode 100644 xen/include/asm-riscv/pci.h
 create mode 100644 xen/include/asm-riscv/percpu.h
 create mode 100644 xen/include/asm-riscv/pgtable-bits.h
 create mode 100644 xen/include/asm-riscv/processor.h
 create mode 100644 xen/include/asm-riscv/random.h
 create mode 100644 xen/include/asm-riscv/regs.h
 create mode 100644 xen/include/asm-riscv/riscv_encoding.h
 create mode 100644 xen/include/asm-riscv/setup.h
 create mode 100644 xen/include/asm-riscv/smp.h
 create mode 100644 xen/include/asm-riscv/softirq.h
 create mode 100644 xen/include/asm-riscv/spinlock.h
 create mode 100644 xen/include/asm-riscv/string.h
 create mode 100644 xen/include/asm-riscv/sysregs.h
 create mode 100644 xen/include/asm-riscv/system.h
 create mode 100644 xen/include/asm-riscv/time.h
 create mode 100644 xen/include/asm-riscv/trace.h
 create mode 100644 xen/include/asm-riscv/types.h
 create mode 100644 xen/include/asm-riscv/vm_event.h
 create mode 100644 xen/include/asm-riscv/xenoprof.h
 create mode 100644 xen/include/public/arch-riscv.h
 create mode 100644 xen/include/public/arch-riscv/hvm/save.h
xen/include/asm-riscv/altp2m.h new file +39 -0
new file mode 100644
index 0000000000..8554495f94
@@ -0,0 +1,39 @@
+/*
+ * Alternate p2m
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_RISCV_ALTP2M_H
+#define __ASM_RISCV_ALTP2M_H
+
+#include <xen/sched.h>
+
+/* Alternate p2m on/off per domain */
+static inline bool altp2m_active(const struct domain *d)
+{
+    /* Not implemented on RISCV. */
+    return false;
+}
+
+/* Alternate p2m VCPU */
+static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
+{
+    /* Not implemented on RISCV, should not be reached. */
+    BUG();
+    return 0;
+}
+
+#endif /* __ASM_RISCV_ALTP2M_H */
xen/include/asm-riscv/asm.h new file +76 -0

76 lines not on this page · raw message

xen/include/asm-riscv/atomic.h new file +249 -0

249 lines not on this page · raw message

xen/include/asm-riscv/bitops.h new file +331 -0

331 lines not on this page · raw message

xen/include/asm-riscv/bug.h new file +59 -0

59 lines not on this page · raw message

xen/include/asm-riscv/byteorder.h new file +16 -0
new file mode 100644
index 0000000000..320a03c88f
@@ -0,0 +1,16 @@
+#ifndef __ASM_RISCV_BYTEORDER_H__
+#define __ASM_RISCV_BYTEORDER_H__
+
+#define __BYTEORDER_HAS_U64__
+
+#include <xen/byteorder/little_endian.h>
+
+#endif /* __ASM_RISCV_BYTEORDER_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/cache.h new file +24 -0
new file mode 100644
index 0000000000..1fdc702828
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2017 Chen Liqin <[email protected]>
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT		6
+
+#define L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
+
+#define __read_mostly __section(".data.read_mostly")
+
+#endif /* _ASM_RISCV_CACHE_H */
xen/include/asm-riscv/cmpxchg.h new file +382 -0

382 lines not on this page · raw message

xen/include/asm-riscv/config.h new file +203 -0

203 lines not on this page · raw message

xen/include/asm-riscv/csr.h new file +117 -0

117 lines not on this page · raw message

xen/include/asm-riscv/current.h new file +50 -0

50 lines not on this page · raw message

xen/include/asm-riscv/debugger.h new file +15 -0
new file mode 100644
index 0000000000..af4fc8a838
@@ -0,0 +1,15 @@
+#ifndef __RISCV_DEBUGGER_H__
+#define __RISCV_DEBUGGER_H__
+
+#define debugger_trap_fatal(v, r) (0)
+#define debugger_trap_immediate() ((void) 0)
+
+#endif /* __RISCV_DEBUGGER_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/delay.h new file +28 -0
new file mode 100644
index 0000000000..cbb0c9eb96
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2009 Chen Liqin <[email protected]>
+ * Copyright (C) 2016 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_DELAY_H
+#define _ASM_RISCV_DELAY_H
+
+extern unsigned long riscv_timebase;
+
+#define udelay udelay
+extern void udelay(unsigned long usecs);
+
+#define ndelay ndelay
+extern void ndelay(unsigned long nsecs);
+
+extern void __delay(unsigned long cycles);
+
+#endif /* _ASM_RISCV_DELAY_H */
xen/include/asm-riscv/desc.h new file +12 -0
new file mode 100644
index 0000000000..a4d02d5eef
@@ -0,0 +1,12 @@
+#ifndef __ARCH_DESC_H
+#define __ARCH_DESC_H
+
+#endif /* __ARCH_DESC_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/device.h new file +15 -0
new file mode 100644
index 0000000000..e38d2a9712
@@ -0,0 +1,15 @@
+#ifndef __ASM_RISCV_DEVICE_H
+#define __ASM_RISCV_DEVICE_H
+
+typedef struct device device_t;
+
+#endif /* __ASM_RISCV_DEVICE_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/div64.h new file +23 -0
new file mode 100644
index 0000000000..0a88dd30ad
@@ -0,0 +1,23 @@
+#ifndef __ASM_RISCV_DIV64
+#define __ASM_RISCV_DIV64
+
+#include <asm/system.h>
+#include <xen/types.h>
+
+# define do_div(n,base) ({                                      \
+        uint32_t __base = (base);                               \
+        uint32_t __rem;                                         \
+        __rem = ((uint64_t)(n)) % __base;                       \
+        (n) = ((uint64_t)(n)) / __base;                         \
+        __rem;                                                  \
+ })
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/domain.h new file +85 -0

85 lines not on this page · raw message

xen/include/asm-riscv/event.h new file +42 -0

42 lines not on this page · raw message

xen/include/asm-riscv/fence.h new file +12 -0
new file mode 100644
index 0000000000..2b443a3a48
@@ -0,0 +1,12 @@
+#ifndef _ASM_RISCV_FENCE_H
+#define _ASM_RISCV_FENCE_H
+
+#ifdef CONFIG_SMP
+#define RISCV_ACQUIRE_BARRIER		"\tfence r , rw\n"
+#define RISCV_RELEASE_BARRIER		"\tfence rw,  w\n"
+#else
+#define RISCV_ACQUIRE_BARRIER
+#define RISCV_RELEASE_BARRIER
+#endif
+
+#endif	/* _ASM_RISCV_FENCE_H */
xen/include/asm-riscv/flushtlb.h new file +56 -0

56 lines not on this page · raw message

xen/include/asm-riscv/grant_table.h new file +93 -0

93 lines not on this page · raw message

xen/include/asm-riscv/guest_access.h new file +164 -0

164 lines not on this page · raw message

xen/include/asm-riscv/guest_atomics.h new file +62 -0

62 lines not on this page · raw message

xen/include/asm-riscv/hardirq.h new file +27 -0
new file mode 100644
index 0000000000..67b6a673db
@@ -0,0 +1,27 @@
+#ifndef __ASM_HARDIRQ_H
+#define __ASM_HARDIRQ_H
+
+#include <xen/cache.h>
+#include <xen/smp.h>
+
+typedef struct {
+        unsigned long __softirq_pending;
+        unsigned int __local_irq_count;
+} __cacheline_aligned irq_cpustat_t;
+
+#include <xen/irq_cpustat.h>    /* Standard mappings for irq_cpustat_t above */
+
+#define in_irq() (local_irq_count(smp_processor_id()) != 0)
+
+#define irq_enter()     (local_irq_count(smp_processor_id())++)
+#define irq_exit()      (local_irq_count(smp_processor_id())--)
+
+#endif /* __ASM_HARDIRQ_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/hypercall.h new file +12 -0
new file mode 100644
index 0000000000..8af474b5e2
@@ -0,0 +1,12 @@
+#ifndef __ASM_RISCV_HYPERCALL_H__
+#define __ASM_RISCV_HYPERCALL_H__
+
+#endif /* __ASM_RISCV_HYPERCALL_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/init.h new file +42 -0

42 lines not on this page · raw message

xen/include/asm-riscv/io.h new file +283 -0

283 lines not on this page · raw message

xen/include/asm-riscv/iocap.h new file +16 -0
new file mode 100644
index 0000000000..712f34528e
@@ -0,0 +1,16 @@
+#ifndef __RISCV_IOCAP_H__
+#define __RISCV_IOCAP_H__
+
+#define cache_flush_permitted(d)                        \
+    (!rangeset_is_empty((d)->iomem_caps))
+
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/iommu.h new file +49 -0

49 lines not on this page · raw message

xen/include/asm-riscv/irq.h new file +58 -0

58 lines not on this page · raw message

xen/include/asm-riscv/mem_access.h new file +35 -0
new file mode 100644
index 0000000000..aa7decb629
@@ -0,0 +1,35 @@
+/******************************************************************************
+ *
+ * Copyright 2019 (C) Alistair Francis <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _ASM_RISCV_MEM_ACCESS_H
+#define _ASM_RISCV_MEM_ACCESS_H
+
+#include <xen/errno.h>
+/* vm_event and mem_access are supported on any ARM guest */
+static inline bool p2m_mem_access_sanity_check(struct domain *d)
+{
+    return true;
+}
+
+#endif /* _ASM_RISCV_MEM_ACCESS_H */
xen/include/asm-riscv/mm.h new file +308 -0

308 lines not on this page · raw message

xen/include/asm-riscv/monitor.h new file +65 -0

17 lines not on this page · raw message

xen/include/asm-riscv/nospec.h new file +25 -0
new file mode 100644
index 0000000000..55087fa831

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/numa.h new file +41 -0

41 lines not on this page · raw message

xen/include/asm-riscv/p2m.h new file +410 -0

410 lines not on this page · raw message

xen/include/asm-riscv/page.h new file +327 -0

327 lines not on this page · raw message

xen/include/asm-riscv/paging.h new file +16 -0
new file mode 100644
index 0000000000..6d1a000246

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/pci.h new file +31 -0
new file mode 100644
index 0000000000..0ccf335e34

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/percpu.h new file +34 -0
new file mode 100644
index 0000000000..9bf4ffcae3

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/pgtable-bits.h new file +53 -0

53 lines not on this page · raw message

xen/include/asm-riscv/processor.h new file +60 -0

60 lines not on this page · raw message

xen/include/asm-riscv/random.h new file +9 -0
new file mode 100644
index 0000000000..b4acee276b

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/regs.h new file +42 -0

42 lines not on this page · raw message

xen/include/asm-riscv/riscv_encoding.h new file +682 -0

682 lines not on this page · raw message

xen/include/asm-riscv/setup.h new file +16 -0
new file mode 100644
index 0000000000..8c9d8066d5

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/smp.h new file +50 -0

50 lines not on this page · raw message

xen/include/asm-riscv/softirq.h new file +16 -0
new file mode 100644
index 0000000000..976e0ebd70

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/spinlock.h new file +13 -0
new file mode 100644
index 0000000000..2f47b4d9ad

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/string.h new file +28 -0
new file mode 100644
index 0000000000..733e9e00d3

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/sysregs.h new file +14 -0
new file mode 100644
index 0000000000..0f7f5c644b

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/system.h new file +96 -0

96 lines not on this page · raw message

xen/include/asm-riscv/time.h new file +60 -0

60 lines not on this page · raw message

xen/include/asm-riscv/trace.h new file +12 -0
new file mode 100644
index 0000000000..e06def61f6

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/types.h new file +73 -0

73 lines not on this page · raw message

xen/include/asm-riscv/vm_event.h new file +61 -0

61 lines not on this page · raw message

xen/include/asm-riscv/xenoprof.h new file +12 -0
new file mode 100644
index 0000000000..3db6ce3ab2

Lines of this file are not shown. View the raw message.

xen/include/public/arch-riscv.h new file +181 -0

181 lines not on this page · raw message

xen/include/public/arch-riscv/hvm/save.h new file +39 -0
new file mode 100644
index 0000000000..fa010f0315

Lines of this file are not shown. View the raw message.

xen/include/public/hvm/save.h +2 -0
index f72e3a9bc4..d7505f279c 100644

Lines of this file are not shown. View the raw message.

xen/include/public/pmu.h +2 -0
index 0e1312cfe5..ac73586a3b 100644

Lines of this file are not shown. View the raw message.

xen/include/public/xen.h +2 -0
index d2198dffad..6e439991dc 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Part of the diff is not shown here. View the raw message.

#5 lore raw

RFC PATCH 5/23 riscv: early setup code

In reply to Bobby Eshleman

This patch initializes virtual memory for Xen and initializes UART. Just the bare bones to start seeing output. Many shortcuts exist and many TODO's remain.

Most of this patch is modeled after Xen ARM64 and Xvisor. Many values are hardcoded for the QEMU virt board, with TODO's left for pulling those values from the DTB.

---
 xen/arch/riscv/head.S  | 180 ++++++++
 xen/arch/riscv/mm.c    | 925 +++++++++++++++++++++++++++++++++++++++++
 xen/arch/riscv/setup.c | 122 ++++++
 3 files changed, 1227 insertions(+)
 create mode 100644 xen/arch/riscv/head.S
 create mode 100644 xen/arch/riscv/mm.c
 create mode 100644 xen/arch/riscv/setup.c
xen/arch/riscv/head.S new file +180 -0
new file mode 100644
index 0000000000..0712df4a3e
@@ -0,0 +1,180 @@
+#include <asm/asm.h>
+#include <asm/asm-offsets.h>
+#include <asm/init.h>
+#include <asm/csr.h>
+#include <asm/config.h>
+
+.global _start
+
+ENTRY(start)
+	.section .entry, "ax", %progbits
+_start:
+	/* Mask all interrupts */
+	csrw CSR_SIE, zero
+
+	/*
+	 * Disable FPU to detect illegal usage of
+	 * floating point in kernel space
+	 */
+	li t0, SSTATUS_FS
+	csrc CSR_SSTATUS, t0
+
+	/* Save HART ID and DTB base */
+	la	a6, _bootcpu_reg0
+	REG_S	a0, (a6)
+	la	a6, _bootcpu_reg1
+	REG_S	a1, (a6)
+
+	/* Save load addresses
+	 * a2 -> load start
+	 * a3 -> load end
+	 * a4 -> execution start
+	 * a5 -> execution end
+	 */
+	la	a2, _start
+	la	a6, __exec_start
+	REG_L	a4, (a6)
+	la	a6, __exec_end
+	REG_L	a5, (a6)
+	sub	a6, a5, a4
+	add	a3, a2, a6
+	la	a6, _load_start
+	REG_S	a2, (a6)
+	la	a6, _load_end
+	REG_S	a3, (a6)
+	la	a6, _end
+	REG_S	a3, (a6)
+
+	/* Zero-out bss section */
+	la	a6, __bss_start
+	REG_L	a0, (a6)
+	sub	a0, a0, a4
+	add	a0, a0, a2
+	la	a6, __bss_end
+	REG_L	a1, (a6)
+	sub	a1, a1, a4
+	add	a1, a1, a2
+_bss_zero:
+	REG_S	zero, (a0)
+	add	a0, a0, __SIZEOF_POINTER__
+	blt	a0, a1, _bss_zero
+
+	/* Setup temporary stack */
+	la	a6, __hvc_stack_end
+	REG_L	a0, (a6)
+	sub	a0, a0, a4
+	add	sp, a0, a2
+
+        /* Setup hang for IRQ vector w/ virtual address */
+	la	a6, __debug_irq_vector
+        REG_L   a4, (a6)
+	csrw	CSR_STVEC, a4
+
+	/* Setup initial page table */
+	la	a6, _load_start
+	REG_L	a0, (a6)
+	la	a6, _load_end
+	REG_L	a1, (a6)
+	la	a6, __exec_start
+	REG_L	a2, (a6)
+	la	a6, __exec_end
+	REG_L	a3, (a6)
+	call	_setup_initial_pagetables
+
+	j	_start_secondary_nopen
+
+	.align	3
+_start_lottery:
+	RISCV_PTR	0
+	.align	3
+__start_secondary_pen_release:
+	RISCV_PTR	start_secondary_pen_release
+
+	/*
+	 * Note: From this point primary CPU startup is same as secondary CPU
+	 */
+_start_secondary_nopen:
+	/* Set trap vector to spin forever to help debug */
+	//la	a6, _start_hang
+	//csrw	CSR_STVEC, a6
+
+	/* Jump to final execution address */
+	la	a6, __cpu_init
+	REG_L	a0, (a6)
+	jalr	a0
+
+_start_hang:
+	wfi
+	j	_start_hang
+
+	.align 3
+__phys_offset:
+	RISCV_PTR phys_offset
+__pgtbl_root:
+	RISCV_PTR xen_second_pagetable
+__exec_start:
+	RISCV_PTR _code_start
+__exec_end:
+	RISCV_PTR _code_end
+__bss_start:
+	RISCV_PTR _bss_start
+__bss_end:
+	RISCV_PTR _bss_end
+__debug_irq_vector:
+	RISCV_PTR _start_hang
+__cpu_init:
+	RISCV_PTR _cpu_init
+
+	/*
+	 * Boot register 0 passed by bootloader
+	 */
+	.globl _bootcpu_reg0
+_bootcpu_reg0:
+	RISCV_PTR 0x0
+
+	/*
+	 * Boot register 1 passed by bootloader
+	 */
+	.globl _boot_reg1
+_bootcpu_reg1:
+	RISCV_PTR 0x0
+
+	/*
+	 * Load start address storage
+	 */
+	.globl _load_start
+_load_start:
+	RISCV_PTR 0x0
+
+	/*
+	 * Load end address storage
+	 */
+	.globl _load_end
+_load_end:
+	RISCV_PTR 0x0
+
+        .globl _end
+_end:
+	RISCV_PTR 0x0
+
+	/*
+	 * Exception stacks.
+	 */
+__hvc_stack_end:
+	RISCV_PTR _hvc_stack_end
+
+	.align 3
+	.globl _cpu_init
+_cpu_init:
+        /* Set stack pointer to virtual address at end of the Xen executable */
+	la	a6, __exec_end
+        REG_L   sp, (a6)
+
+
+	/* Jump to C code */
+	call	start_xen
+
+	/* Hang !!! */
+	j	_start_hang
+
+	ret
xen/arch/riscv/mm.c new file +925 -0

925 lines not on this page · raw message

xen/arch/riscv/setup.c new file +122 -0

122 lines not on this page · raw message

Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

RFC PATCH 6/23 riscv: Add riscv to tools/libxc header files

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 tools/libxc/include/xenctrl.h |  7 +++++
 tools/libxc/xc_core.h         |  2 ++
 tools/libxc/xc_core_riscv.h   | 57 +++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 tools/libxc/xc_core_riscv.h
tools/libxc/include/xenctrl.h +7 -0
index 75f191ae3a..4cbe35bb2b 100644
@@ -83,6 +83,13 @@
 #define xen_mb()   asm volatile ("dmb sy" : : : "memory")
 #define xen_rmb()  asm volatile ("dmb sy" : : : "memory")
 #define xen_wmb()  asm volatile ("dmb sy" : : : "memory")
+#elif defined(__riscv)
+#define RISCV_FENCE(p, s) \
+  __asm__ __volatile__ ("fence " #p "," #s : : : "memory")
+
+#define xen_mb()  RISCV_FENCE(rw,rw)
+#define xen_rmb() RISCV_FENCE(r,r)
+#define xen_wmb() RISCV_FENCE(w,w)
 #else
 #error "Define barriers"
 #endif
tools/libxc/xc_core.h +2 -0
index ed7ed53ca5..7baba3e4bd 100644
@@ -155,6 +155,8 @@ int xc_core_arch_get_scratch_gpfn(xc_interface *xch, uint32_t domid,
 # include "xc_core_x86.h"
 #elif defined (__arm__) || defined(__aarch64__)
 # include "xc_core_arm.h"
+#elif defined(__riscv)
+# include "xc_core_riscv.h"
 #else
 # error "unsupported architecture"
 #endif
tools/libxc/xc_core_riscv.h new file +57 -0

57 lines not on this page · raw message

Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

RFC PATCH 7/23 riscv: Add asm-offsets.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/asm-offsets.c | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 xen/arch/riscv/asm-offsets.c
xen/arch/riscv/asm-offsets.c new file +38 -0
new file mode 100644
index 0000000000..4c53f8af84
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#define COMPILE_OFFSETS
+
+#include <xen/types.h>
+#include <xen/sched.h>
+#include <xen/bitops.h>
+#include <public/xen.h>
+#include <asm/processor.h>
+#include <asm/init.h>
+#include <asm/current.h>
+
+#define DEFINE(_sym, _val)                                                 \
+    asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
+                  : : "i" (_val) )
+#define BLANK()                                                            \
+    asm volatile ( "\n.ascii\"==><==\"" : : )
+#define OFFSET(_sym, _str, _mem)                                           \
+    DEFINE(_sym, offsetof(_str, _mem));
+
+void asm_offsets(void)
+{
+
+   BLANK();
+   OFFSET(INITINFO_stack, struct init_info, stack);
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#8 lore raw

RFC PATCH 8/23 riscv: Add delay.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/delay.c | 114 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)
 create mode 100644 xen/arch/riscv/delay.c
xen/arch/riscv/delay.c new file +114 -0
new file mode 100644
index 0000000000..fe8e7b0575
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <asm/io.h>
+#include <asm/system.h>
+#include <asm/processor.h>
+#include <asm/time.h>
+
+/*
+ * This is copies from arch/arm/include/asm/delay.h
+ *
+ * Loop (or tick) based delay:
+ *
+ * loops = loops_per_jiffy * jiffies_per_sec * delay_us / us_per_sec
+ *
+ * where:
+ *
+ * jiffies_per_sec = HZ
+ * us_per_sec = 1000000
+ *
+ * Therefore the constant part is HZ / 1000000 which is a small
+ * fractional number. To make this usable with integer math, we
+ * scale up this constant by 2^31, perform the actual multiplication,
+ * and scale the result back down by 2^31 with a simple shift:
+ *
+ * loops = (loops_per_jiffy * delay_us * UDELAY_MULT) >> 31
+ *
+ * where:
+ *
+ * UDELAY_MULT = 2^31 * HZ / 1000000
+ *             = (2^31 / 1000000) * HZ
+ *             = 2147.483648 * HZ
+ *             = 2147 * HZ + 483648 * HZ / 1000000
+ *
+ * 31 is the biggest scale shift value that won't overflow 32 bits for
+ * delay_us * UDELAY_MULT assuming HZ <= 1000 and delay_us <= 2000.
+ */
+#define HZ	1000
+#define MAX_UDELAY_US	2000
+#define MAX_UDELAY_HZ	1000
+#define UDELAY_MULT	(2147UL * HZ + 483648UL * HZ / 1000000UL)
+#define UDELAY_SHIFT	31
+
+#if HZ > MAX_UDELAY_HZ
+#error "HZ > MAX_UDELAY_HZ"
+#endif
+
+unsigned long riscv_timebase = 1000000;
+
+/*
+ * RISC-V supports both UDELAY and NDELAY.  This is largely the same as above,
+ * but with different constants.  I added 10 bits to the shift to get this, but
+ * the result is that I need a 64-bit multiply, which is slow on 32-bit
+ * platforms.
+ *
+ * NDELAY_MULT = 2^41 * HZ / 1000000000
+ *             = (2^41 / 1000000000) * HZ
+ *             = 2199.02325555 * HZ
+ *             = 2199 * HZ + 23255550 * HZ / 1000000000
+ *
+ * The maximum here is to avoid 64-bit overflow, but it isn't checked as it
+ * won't happen.
+ */
+#define MAX_NDELAY_NS   (1ULL << 42)
+#define MAX_NDELAY_HZ	MAX_UDELAY_HZ
+#define NDELAY_MULT	((unsigned long long)(2199ULL * HZ + 23255550ULL * HZ / 1000000000ULL))
+#define NDELAY_SHIFT	41
+
+#if HZ > MAX_NDELAY_HZ
+#error "HZ > MAX_NDELAY_HZ"
+#endif
+
+void __delay(unsigned long cycles)
+{
+	u64 t0 = get_cycles();
+
+	while ((unsigned long)(get_cycles() - t0) < cycles)
+		cpu_relax();
+}
+EXPORT_SYMBOL(__delay);
+
+void udelay(unsigned long usecs)
+{
+	unsigned long ucycles = usecs * riscv_timebase * UDELAY_MULT / HZ;
+
+	if (unlikely(usecs > MAX_UDELAY_US)) {
+		__delay((u64)usecs * riscv_timebase / 1000000ULL);
+		return;
+	}
+
+	__delay(ucycles >> UDELAY_SHIFT);
+}
+EXPORT_SYMBOL(udelay);
+
+void ndelay(unsigned long nsecs)
+{
+	/*
+	 * This doesn't bother checking for overflow, as it won't happen (it's
+	 * an hour) of delay.
+	 */
+	unsigned long long ncycles = nsecs * riscv_timebase * NDELAY_MULT / HZ;
+	__delay(ncycles >> NDELAY_SHIFT);
+}
+EXPORT_SYMBOL(ndelay);
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

RFC PATCH 9/23 riscv: Add domain.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/domain.c | 273 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 273 insertions(+)
 create mode 100644 xen/arch/riscv/domain.c
xen/arch/riscv/domain.c new file +273 -0
new file mode 100644
index 0000000000..206366abf7
@@ -0,0 +1,273 @@
+/******************************************************************************
+ *
+ * Copyright 2019 (C) Alistair Francis <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include <xen/bitops.h>
+#include <xen/errno.h>
+#include <xen/grant_table.h>
+#include <xen/hypercall.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/livepatch.h>
+#include <xen/sched.h>
+#include <xen/softirq.h>
+#include <xen/wait.h>
+
+DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
+
+static void do_idle(void)
+{
+    unsigned int cpu = smp_processor_id();
+
+    sched_tick_suspend();
+    /* sched_tick_suspend() can raise TIMER_SOFTIRQ. Process it now. */
+    process_pending_softirqs();
+
+    local_irq_disable();
+    if ( cpu_is_haltable(cpu) )
+    {
+        wait_for_interrupt();
+    }
+    local_irq_enable();
+
+    sched_tick_resume();
+}
+
+void idle_loop(void)
+{
+    unsigned int cpu = smp_processor_id();
+
+    for ( ; ; )
+    {
+        if ( cpu_is_offline(cpu) )
+            stop_cpu();
+
+        /* Are we here for running vcpu context tasklets, or for idling? */
+        if ( unlikely(tasklet_work_to_do(cpu)) )
+            do_tasklet();
+        /*
+         * Test softirqs twice --- first to see if should even try scrubbing
+         * and then, after it is done, whether softirqs became pending
+         * while we were scrubbing.
+         */
+        else if ( !softirq_pending(cpu) && !scrub_free_pages() &&
+                  !softirq_pending(cpu) )
+            do_idle();
+
+        do_softirq();
+        /*
+         * We MUST be last (or before dsb, wfi). Otherwise after we get the
+         * softirq we would execute dsb,wfi (and sleep) and not patch.
+         */
+        check_for_livepatch_work();
+    }
+}
+
+
+void context_switch(struct vcpu *prev, struct vcpu *next)
+{
+    ASSERT(local_irq_is_enabled());
+    ASSERT(prev != next);
+    ASSERT(!vcpu_cpu_dirty(next));
+
+    local_irq_disable();
+
+    /* TODO */
+
+    set_current(next);
+}
+
+void continue_running(struct vcpu *same)
+{
+    /* Nothing to do */
+}
+
+void sync_local_execstate(void)
+{
+    /* Nothing to do -- no lazy switching */
+}
+
+void sync_vcpu_execstate(struct vcpu *v)
+{
+    /* Nothing to do -- no lazy switching */
+}
+
+unsigned long hypercall_create_continuation(
+    unsigned int op, const char *format, ...)
+{
+	/* TODO */
+
+	return 0;
+}
+
+void startup_cpu_idle_loop(void)
+{
+    struct vcpu *v = current;
+
+    ASSERT(is_idle_vcpu(v));
+
+    reset_stack_and_jump(idle_loop);
+}
+
+struct domain *alloc_domain_struct(void)
+{
+    struct domain *d;
+    BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
+    d = alloc_xenheap_pages(0, 0);
+    if ( d == NULL )
+        return NULL;
+
+    clear_page(d);
+    return d;
+}
+
+void free_domain_struct(struct domain *d)
+{
+    free_xenheap_page(d);
+}
+
+void dump_pageframe_info(struct domain *d)
+{
+
+}
+
+int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
+{
+    /* TODO */
+
+    return 0;
+}
+
+
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)
+{
+    /* TODO */
+
+    return 0;
+}
+
+void arch_domain_destroy(struct domain *d)
+{
+}
+
+void arch_domain_shutdown(struct domain *d)
+{
+}
+
+void arch_domain_pause(struct domain *d)
+{
+}
+
+void arch_domain_unpause(struct domain *d)
+{
+}
+
+int arch_domain_soft_reset(struct domain *d)
+{
+    return -ENOSYS;
+}
+
+void arch_domain_creation_finished(struct domain *d)
+{
+    /* TODO */
+}
+
+int domain_relinquish_resources(struct domain *d)
+{
+    /* TODO */
+
+    return 0;
+}
+
+void arch_dump_domain_info(struct domain *d)
+{
+    p2m_dump_info(d);
+}
+
+long arch_do_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    return -ENOSYS;
+}
+
+void arch_dump_vcpu_info(struct vcpu *v)
+{
+    /* TODO */
+}
+
+int arch_set_info_guest(
+    struct vcpu *v, vcpu_guest_context_u c)
+{
+    /* TODO */
+
+    return 0;
+}
+
+#define MAX_PAGES_PER_VCPU  2
+
+struct vcpu *alloc_vcpu_struct(const struct domain *d)
+{
+    struct vcpu *v;
+
+    BUILD_BUG_ON(sizeof(*v) > MAX_PAGES_PER_VCPU * PAGE_SIZE);
+    v = alloc_xenheap_pages(get_order_from_bytes(sizeof(*v)), 0);
+    if ( v != NULL )
+    {
+        unsigned int i;
+
+        for ( i = 0; i < DIV_ROUND_UP(sizeof(*v), PAGE_SIZE); i++ )
+            clear_page((void *)v + i * PAGE_SIZE);
+    }
+
+    return v;
+}
+
+void free_vcpu_struct(struct vcpu *v)
+{
+    free_xenheap_pages(v, get_order_from_bytes(sizeof(*v)));
+}
+
+int arch_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    return default_initialise_vcpu(v, arg);
+}
+
+int arch_vcpu_reset(struct vcpu *v)
+{
+    /* TODO */
+    return 0;
+}
+
+int arch_vcpu_create(struct vcpu *v)
+{
+    int rc = 0;
+
+    /* TODO */
+
+    return rc;
+}
+
+void arch_vcpu_destroy(struct vcpu *v)
+{
+    /* TODO */
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#10 lore raw

RFC PATCH 10/23 riscv: Add domctl.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/domctl.c | 53 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 xen/arch/riscv/domctl.c
xen/arch/riscv/domctl.c new file +53 -0
new file mode 100644
index 0000000000..4bbd4e740d
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * Arch-specific domctl.c
+ *
+ * Copyright (c) 2012, Citrix Systems
+ */
+
+#include <xen/errno.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/iocap.h>
+#include <xen/lib.h>
+#include <xen/mm.h>
+#include <xen/sched.h>
+#include <xen/types.h>
+#include <xsm/xsm.h>
+#include <public/domctl.h>
+
+void arch_get_domain_info(const struct domain *d,
+                          struct xen_domctl_getdomaininfo *info)
+{
+    info->flags |= XEN_DOMINF_hap;
+}
+
+long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
+                    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
+{
+    /* TODO */
+
+    switch ( domctl->cmd ) {
+    case XEN_DOMCTL_cacheflush:
+    case XEN_DOMCTL_bind_pt_irq:
+    case XEN_DOMCTL_unbind_pt_irq:
+    case XEN_DOMCTL_disable_migrate:
+    case XEN_DOMCTL_vuart_op:
+    default:
+        return 0;
+    }
+}
+
+void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
+{
+    /* TODO */
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

RFC PATCH 11/23 riscv: Add guestcopy.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/guestcopy.c | 158 +++++++++++++++++++++++++++++++++++++
 1 file changed, 158 insertions(+)
 create mode 100644 xen/arch/riscv/guestcopy.c
xen/arch/riscv/guestcopy.c new file +158 -0
new file mode 100644
index 0000000000..c2f7700eab
@@ -0,0 +1,158 @@
+#include <xen/lib.h>
+#include <xen/domain_page.h>
+#include <xen/mm.h>
+#include <xen/sched.h>
+#include <asm/current.h>
+#include <asm/guest_access.h>
+
+#define COPY_flush_dcache   (1U << 0)
+#define COPY_from_guest     (0U << 1)
+#define COPY_to_guest       (1U << 1)
+#define COPY_ipa            (0U << 2)
+#define COPY_linear         (1U << 2)
+
+typedef union
+{
+    struct
+    {
+        struct vcpu *v;
+    } gva;
+
+    struct
+    {
+        struct domain *d;
+    } gpa;
+} copy_info_t;
+
+#define GVA_INFO(vcpu) ((copy_info_t) { .gva = { vcpu } })
+#define GPA_INFO(domain) ((copy_info_t) { .gpa = { domain } })
+
+static struct page_info *translate_get_page(copy_info_t info, uint64_t addr,
+                                            bool linear, bool write)
+{
+    p2m_type_t p2mt;
+    struct page_info *page;
+
+    page = get_page_from_gfn(info.gpa.d, paddr_to_pfn(addr), &p2mt, P2M_ALLOC);
+
+    if ( !page )
+        return NULL;
+
+    if ( !p2m_is_ram(p2mt) )
+    {
+        put_page(page);
+        return NULL;
+    }
+
+    return page;
+}
+
+static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
+                                copy_info_t info, unsigned int flags)
+{
+    /* XXX needs to handle faults */
+    unsigned offset = addr & ~PAGE_MASK;
+
+    BUILD_BUG_ON((sizeof(addr)) < sizeof(vaddr_t));
+    BUILD_BUG_ON((sizeof(addr)) < sizeof(paddr_t));
+
+    while ( len )
+    {
+        void *p;
+        unsigned size = min(len, (unsigned)PAGE_SIZE - offset);
+        struct page_info *page;
+
+        page = translate_get_page(info, addr, flags & COPY_linear,
+                                  flags & COPY_to_guest);
+        if ( page == NULL )
+            return len;
+
+        p = __map_domain_page(page);
+        p += offset;
+        if ( flags & COPY_to_guest )
+        {
+            /*
+             * buf will be NULL when the caller request to zero the
+             * guest memory.
+             */
+            if ( buf )
+                memcpy(p, buf, size);
+            else
+                memset(p, 0, size);
+        }
+        else
+            memcpy(buf, p, size);
+
+        if ( flags & COPY_flush_dcache )
+            clean_dcache_va_range(p, size);
+
+        unmap_domain_page(p - offset);
+        put_page(page);
+        len -= size;
+        buf += size;
+        addr += size;
+        /*
+         * After the first iteration, guest virtual address is correctly
+         * aligned to PAGE_SIZE.
+         */
+        offset = 0;
+    }
+
+    return 0;
+}
+
+unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len)
+{
+    return copy_guest((void *)from, (vaddr_t)to, len,
+                      GVA_INFO(current), COPY_to_guest | COPY_linear);
+}
+
+unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from,
+                                             unsigned len)
+{
+    return copy_guest((void *)from, (vaddr_t)to, len, GVA_INFO(current),
+                      COPY_to_guest | COPY_flush_dcache | COPY_linear);
+}
+
+unsigned long raw_clear_guest(void *to, unsigned len)
+{
+    return copy_guest(NULL, (vaddr_t)to, len, GVA_INFO(current),
+                      COPY_to_guest | COPY_linear);
+}
+
+unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len)
+{
+    return copy_guest(to, (vaddr_t)from, len, GVA_INFO(current),
+                      COPY_from_guest | COPY_linear);
+}
+
+unsigned long copy_to_guest_phys_flush_dcache(struct domain *d,
+                                              paddr_t gpa,
+                                              void *buf,
+                                              unsigned int len)
+{
+    return copy_guest(buf, gpa, len, GPA_INFO(d),
+                      COPY_to_guest | COPY_ipa | COPY_flush_dcache);
+}
+
+int access_guest_memory_by_ipa(struct domain *d, paddr_t gpa, void *buf,
+                               uint32_t size, bool is_write)
+{
+    unsigned long left;
+    int flags = COPY_ipa;
+
+    flags |= is_write ? COPY_to_guest : COPY_from_guest;
+
+    left = copy_guest(buf, gpa, size, GPA_INFO(d), flags);
+
+    return (!left) ? 0 : -EINVAL;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#12 lore raw

RFC PATCH 12/23 riscv: Add time.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/time.c | 74 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 xen/arch/riscv/time.c
xen/arch/riscv/time.c new file +74 -0
new file mode 100644
index 0000000000..5358a22bd7
@@ -0,0 +1,74 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/console.h>
+#include <xen/init.h>
+#include <xen/irq.h>
+#include <xen/lib.h>
+#include <xen/mm.h>
+#include <xen/softirq.h>
+#include <xen/sched.h>
+#include <xen/time.h>
+#include <xen/sched.h>
+#include <xen/event.h>
+#include <xen/cpu.h>
+#include <xen/notifier.h>
+#include <asm/system.h>
+#include <asm/time.h>
+
+unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz. */
+
+uint64_t __read_mostly boot_count;
+
+s_time_t ticks_to_ns(uint64_t ticks)
+{
+    return muldiv64(ticks, SECONDS(1), 1000 * cpu_khz);
+}
+
+void __init preinit_xen_time(void)
+{
+    if ( !cpu_khz )
+        cpu_khz = 1000;
+
+    boot_count = get_cycles();
+}
+
+s_time_t get_s_time(void)
+{
+    uint64_t ticks = get_cycles() - boot_count;
+    return ticks_to_ns(ticks);
+}
+
+
+/* VCPU PV timers. */
+void send_timer_event(struct vcpu *v)
+{
+    send_guest_vcpu_virq(v, VIRQ_TIMER);
+}
+
+/* VCPU PV clock. */
+void update_vcpu_system_time(struct vcpu *v)
+{
+    /* XXX update shared_info->wc_* */
+}
+
+void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds)
+{
+    d->time_offset_seconds = time_offset_seconds;
+}
+
+int reprogram_timer(s_time_t timeout)
+{
+    /* TODO */
+
+    return 0;
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

RFC PATCH 13/23 riscv: Add smp.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/smp.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 xen/arch/riscv/smp.c
xen/arch/riscv/smp.c new file +41 -0
new file mode 100644
index 0000000000..735da22cd2
@@ -0,0 +1,41 @@
+#include <xen/mm.h>
+#include <xen/smp.h>
+#include <asm/system.h>
+#include <asm/smp.h>
+#include <asm/page.h>
+#include <asm/flushtlb.h>
+
+volatile unsigned long start_secondary_pen_release = HARTID_INVALID;
+
+void flush_tlb_mask(const cpumask_t *mask)
+{
+    flush_all_guests_tlb();
+}
+
+void smp_send_event_check_mask(const cpumask_t *mask)
+{
+    /* TODO */
+}
+
+void smp_send_call_function_mask(const cpumask_t *mask)
+{
+    cpumask_t target_mask;
+
+    cpumask_andnot(&target_mask, mask, cpumask_of(smp_processor_id()));
+
+    if ( cpumask_test_cpu(smp_processor_id(), mask) )
+    {
+        local_irq_disable();
+        smp_call_function_interrupt();
+        local_irq_enable();
+    }
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#14 lore raw

RFC PATCH 14/23 riscv: Add shutdown.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/shutdown.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 xen/arch/riscv/shutdown.c
xen/arch/riscv/shutdown.c new file +24 -0
new file mode 100644
index 0000000000..90ade9a555
@@ -0,0 +1,24 @@
+#include <xen/console.h>
+#include <xen/cpu.h>
+#include <xen/delay.h>
+#include <xen/lib.h>
+#include <xen/smp.h>
+
+void machine_halt(void)
+{
+    /* TODO */
+}
+
+void machine_restart(unsigned int delay_millisecs)
+{
+    /* TODO */
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#15 lore raw

RFC PATCH 15/23 riscv: Add traps.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/traps.c | 56 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 xen/arch/riscv/traps.c
xen/arch/riscv/traps.c new file +56 -0
new file mode 100644
index 0000000000..d0147a527f
@@ -0,0 +1,56 @@
+/*
+ * RISC-V Trap handlers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/domain_page.h>
+#include <xen/errno.h>
+#include <xen/hypercall.h>
+#include <xen/init.h>
+#include <xen/iocap.h>
+#include <xen/irq.h>
+#include <xen/lib.h>
+#include <xen/livepatch.h>
+#include <xen/mem_access.h>
+#include <xen/mm.h>
+#include <xen/perfc.h>
+#include <xen/smp.h>
+#include <xen/softirq.h>
+#include <xen/string.h>
+#include <xen/symbols.h>
+#include <xen/version.h>
+#include <xen/virtual_region.h>
+
+#include <public/sched.h>
+#include <public/xen.h>
+
+void show_stack(const struct cpu_user_regs *regs)
+{
+    /* TODO */
+}
+
+void show_execution_state(const struct cpu_user_regs *regs)
+{
+    /* TODO */
+}
+
+void vcpu_show_execution_state(struct vcpu *v)
+{
+    /* TODO */
+}
+
+enum mc_disposition arch_do_multicall_call(struct mc_state *state)
+{
+    /* TODO */
+
+    return mc_continue;
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#16 lore raw

RFC PATCH 16/23 riscv: Add irq.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/irq.c | 107 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)
 create mode 100644 xen/arch/riscv/irq.c
xen/arch/riscv/irq.c new file +107 -0
new file mode 100644
index 0000000000..d1b0b578de
@@ -0,0 +1,107 @@
+/*
+ * RISC-V Interrupt support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/lib.h>
+#include <xen/spinlock.h>
+#include <xen/irq.h>
+#include <xen/init.h>
+#include <xen/errno.h>
+#include <xen/sched.h>
+
+const unsigned int nr_irqs = NR_IRQS;
+
+static void ack_none(struct irq_desc *irq)
+{
+    printk("unexpected IRQ trap at irq %02x\n", irq->irq);
+}
+
+static void end_none(struct irq_desc *irq)
+{
+    /* TODO */
+}
+
+hw_irq_controller no_irq_type = {
+    .typename = "none",
+    .startup = irq_startup_none,
+    .shutdown = irq_shutdown_none,
+    .enable = irq_enable_none,
+    .disable = irq_disable_none,
+    .ack = ack_none,
+    .end = end_none
+};
+
+static irq_desc_t irq_desc[NR_IRQS];
+static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);
+
+int arch_init_one_irq_desc(struct irq_desc *desc)
+{
+    return 0;
+}
+
+struct pirq *alloc_pirq_struct(struct domain *d)
+{
+	/* TODO */
+
+    return NULL;
+}
+
+irq_desc_t *__irq_to_desc(int irq)
+{
+    if ( irq < NR_LOCAL_IRQS )
+        return &this_cpu(local_irq_desc)[irq];
+
+    return &irq_desc[irq-NR_LOCAL_IRQS];
+}
+
+int pirq_guest_bind(struct vcpu *v, struct pirq *pirq, int will_share)
+{
+    BUG();
+}
+
+void pirq_guest_unbind(struct domain *d, struct pirq *pirq)
+{
+    BUG();
+}
+
+void pirq_set_affinity(struct domain *d, int pirq, const cpumask_t *mask)
+{
+    BUG();
+}
+
+void smp_send_state_dump(unsigned int cpu)
+{
+    /* TODO */
+}
+
+void arch_move_irqs(struct vcpu *v)
+{
+    /* TODO */
+}
+
+int setup_irq(unsigned int irq, unsigned int irqflags, struct irqaction *new)
+{
+    int rc = 0;
+    unsigned long flags;
+    struct irq_desc *desc;
+
+    desc = irq_to_desc(irq);
+
+    spin_lock_irqsave(&desc->lock, flags);
+
+    /* TODO */
+
+    spin_unlock_irqrestore(&desc->lock, flags);
+
+    return rc;
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#17 lore raw

RFC PATCH 17/23 riscv: Add vm_event.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/vm_event.c | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 xen/arch/riscv/vm_event.c
xen/arch/riscv/vm_event.c new file +42 -0
new file mode 100644
index 0000000000..b0d3b9ccbd
@@ -0,0 +1,42 @@
+/*
+ * Architecture-specific vm_event handling routines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/sched.h>
+#include <asm/vm_event.h>
+
+void vm_event_fill_regs(vm_event_request_t *req)
+{
+    /* TODO */
+}
+
+void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp)
+{
+    /* TODO */
+}
+
+void vm_event_monitor_next_interrupt(struct vcpu *v)
+{
+    /* Not supported on ARM. */
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#18 lore raw

RFC PATCH 18/23 riscv: Add p2m.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/p2m.c | 261 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 261 insertions(+)
 create mode 100644 xen/arch/riscv/p2m.c
xen/arch/riscv/p2m.c new file +261 -0
new file mode 100644
index 0000000000..38d92d8cc1
@@ -0,0 +1,261 @@
+#include <xen/cpu.h>
+#include <xen/domain_page.h>
+#include <xen/iocap.h>
+#include <xen/lib.h>
+#include <xen/sched.h>
+#include <xen/softirq.h>
+#include <asm/event.h>
+#include <asm/flushtlb.h>
+#include <asm/page.h>
+
+
+#define INVALID_VMID 0 /* VMID 0 is reserved */
+
+/* Unlock the flush and do a P2M TLB flush if necessary */
+void p2m_write_unlock(struct p2m_domain *p2m)
+{
+    /* TODO */
+
+    write_unlock(&p2m->lock);
+}
+
+void p2m_dump_info(struct domain *d)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+    p2m_read_lock(p2m);
+    printk("p2m mappings for domain %d (vmid %d):\n",
+           d->domain_id, p2m->vmid);
+    BUG_ON(p2m->stats.mappings[0] || p2m->stats.shattered[0]);
+    printk("  1G mappings: %ld (shattered %ld)\n",
+           p2m->stats.mappings[1], p2m->stats.shattered[1]);
+    printk("  2M mappings: %ld (shattered %ld)\n",
+           p2m->stats.mappings[2], p2m->stats.shattered[2]);
+    printk("  4K mappings: %ld\n", p2m->stats.mappings[3]);
+    p2m_read_unlock(p2m);
+}
+
+void memory_type_changed(struct domain *d)
+{
+}
+
+void dump_p2m_lookup(struct domain *d, paddr_t addr)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+    printk("dom%d IPA 0x%"PRIpaddr"\n", d->domain_id, addr);
+
+    printk("P2M @ %p mfn:%#"PRI_mfn"\n",
+           p2m->root, mfn_x(page_to_mfn(p2m->root)));
+}
+
+/*
+ * p2m_save_state and p2m_restore_state work in pair to workaround
+ * ARM64_WORKAROUND_AT_SPECULATE. p2m_save_state will set-up VTTBR to
+ * point to the empty page-tables to stop allocating TLB entries.
+ */
+void p2m_save_state(struct vcpu *p)
+{
+    /* TODO */
+}
+
+void p2m_restore_state(struct vcpu *n)
+{
+    /* TODO */
+}
+
+mfn_t gfn_to_mfn(struct domain *d, gfn_t gfn)
+{
+    return p2m_lookup(d, gfn, NULL);
+}
+
+/*
+ * Force a synchronous P2M TLB flush.
+ *
+ * Must be called with the p2m lock held.
+ */
+static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m)
+{
+    /* TODO */
+}
+
+int p2m_set_entry(struct p2m_domain *p2m,
+                  gfn_t sgfn,
+                  unsigned long nr,
+                  mfn_t smfn,
+                  p2m_type_t t,
+                  p2m_access_t a)
+{
+    int rc = 0;
+
+    /* TODO */
+
+    return rc;
+}
+
+mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t)
+{
+    mfn_t mfn;
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+    p2m_read_lock(p2m);
+    mfn = p2m_get_entry(p2m, gfn, t, NULL, NULL, NULL);
+    p2m_read_unlock(p2m);
+
+    return mfn;
+}
+
+mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn,
+                    p2m_type_t *t, p2m_access_t *a,
+                    unsigned int *page_order,
+                    bool *valid)
+{
+    /* TODO */
+
+    mfn_t mfn;
+
+    p2m_read_lock(p2m);
+    mfn = p2m_get_entry(p2m, gfn, t, NULL, NULL, NULL);
+    p2m_read_unlock(p2m);
+
+    return mfn;
+}
+
+static inline int p2m_insert_mapping(struct domain *d,
+                                     gfn_t start_gfn,
+                                     unsigned long nr,
+                                     mfn_t mfn,
+                                     p2m_type_t t)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int rc;
+
+    p2m_write_lock(p2m);
+    rc = p2m_set_entry(p2m, start_gfn, nr, mfn, t, p2m->default_access);
+    p2m_write_unlock(p2m);
+
+    return rc;
+}
+
+static inline int p2m_remove_mapping(struct domain *d,
+                                     gfn_t start_gfn,
+                                     unsigned long nr,
+                                     mfn_t mfn)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int rc;
+
+    p2m_write_lock(p2m);
+    rc = p2m_set_entry(p2m, start_gfn, nr, INVALID_MFN,
+                       p2m_invalid, p2m_access_rwx);
+    p2m_write_unlock(p2m);
+
+    return rc;
+}
+
+void p2m_tlb_flush_sync(struct p2m_domain *p2m)
+{
+    if ( p2m->need_flush )
+        p2m_force_tlb_flush_sync(p2m);
+}
+
+int map_regions_p2mt(struct domain *d,
+                     gfn_t gfn,
+                     unsigned long nr,
+                     mfn_t mfn,
+                     p2m_type_t p2mt)
+{
+    return p2m_insert_mapping(d, gfn, nr, mfn, p2mt);
+}
+
+int unmap_regions_p2mt(struct domain *d,
+                       gfn_t gfn,
+                       unsigned long nr,
+                       mfn_t mfn)
+{
+    return p2m_remove_mapping(d, gfn, nr, mfn);
+}
+
+int map_mmio_regions(struct domain *d,
+                     gfn_t start_gfn,
+                     unsigned long nr,
+                     mfn_t mfn)
+{
+    return p2m_insert_mapping(d, start_gfn, nr, mfn, p2m_mmio_direct_dev);
+}
+
+int unmap_mmio_regions(struct domain *d,
+                       gfn_t start_gfn,
+                       unsigned long nr,
+                       mfn_t mfn)
+{
+    return p2m_remove_mapping(d, start_gfn, nr, mfn);
+}
+
+int map_dev_mmio_region(struct domain *d,
+                        gfn_t gfn,
+                        unsigned long nr,
+                        mfn_t mfn)
+{
+    /* TODO */
+
+    return 0;
+}
+
+int guest_physmap_add_entry(struct domain *d,
+                            gfn_t gfn,
+                            mfn_t mfn,
+                            unsigned long page_order,
+                            p2m_type_t t)
+{
+    return p2m_insert_mapping(d, gfn, (1 << page_order), mfn, t);
+}
+
+int guest_physmap_remove_page(struct domain *d, gfn_t gfn, mfn_t mfn,
+                              unsigned int page_order)
+{
+    return p2m_remove_mapping(d, gfn, (1 << page_order), mfn);
+}
+
+struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn,
+                                        p2m_type_t *t)
+{
+    struct page_info *page;
+    p2m_type_t p2mt;
+    mfn_t mfn = p2m_lookup(d, gfn, &p2mt);
+
+    if ( t )
+        *t = p2mt;
+
+    if ( !p2m_is_any_ram(p2mt) )
+        return NULL;
+
+    if ( !mfn_valid(mfn) )
+        return NULL;
+
+    page = mfn_to_page(mfn);
+
+    /*
+     * get_page won't work on foreign mapping because the page doesn't
+     * belong to the current domain.
+     */
+    if ( p2m_is_foreign(p2mt) )
+    {
+        struct domain *fdom = page_get_owner_and_reference(page);
+        ASSERT(fdom != NULL);
+        ASSERT(fdom != d);
+        return page;
+    }
+
+    return get_page(page, d) ? page : NULL;
+}
+
+void vcpu_mark_events_pending(struct vcpu *v)
+{
+    /* TODO */
+}
+
+void vcpu_update_evtchn_irq(struct vcpu *v)
+{
+    /* TODO */
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#19 lore raw

RFC PATCH 19/23 riscv: Add the lib directory

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

Add the lib directory with find_next_bit support.

This was taken from Linux

---
 xen/arch/riscv/lib/Makefile        |   1 +
 xen/arch/riscv/lib/find_next_bit.c | 284 +++++++++++++++++++++++++++++
 2 files changed, 285 insertions(+)
 create mode 100644 xen/arch/riscv/lib/Makefile
 create mode 100644 xen/arch/riscv/lib/find_next_bit.c
xen/arch/riscv/lib/Makefile new file +1 -0
new file mode 100644
index 0000000000..6fae6a1f10
@@ -0,0 +1 @@
+obj-y += find_next_bit.o
xen/arch/riscv/lib/find_next_bit.c new file +284 -0

284 lines not on this page · raw message

Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#20 lore raw

Re: [RFC XEN PATCH 19/23] riscv: Add the lib directory

Quoted 5 lines · Bobby Eshleman

From: Alistair Francis <[email protected]>

Add the lib directory with find_next_bit support.

This was taken from Linux

As was Arm64's - the two definitely would want folding.

Jan

#21 lore raw

Re: [RFC XEN PATCH 19/23] riscv: Add the lib directory

Quoted 9 lines · Jan Beulich
Quoted 5 lines · Bobby Eshleman

From: Alistair Francis <[email protected]>

Add the lib directory with find_next_bit support.

This was taken from Linux

As was Arm64's - the two definitely would want folding.

Indeed. I'm finding a good more overlap with arch/arm as I move forward, so expect to see a good degree of folding between the two in v2.

#22 lore raw

RFC PATCH 20/23 riscv: Add smpboot.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/smpboot.c | 114 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)
 create mode 100644 xen/arch/riscv/smpboot.c
xen/arch/riscv/smpboot.c new file +114 -0
new file mode 100644
index 0000000000..f125179a3e
@@ -0,0 +1,114 @@
+/*
+ * Dummy smpboot support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/cpu.h>
+#include <xen/cpumask.h>
+#include <xen/delay.h>
+#include <xen/domain_page.h>
+#include <public/domctl.h>
+#include <xen/errno.h>
+#include <xen/init.h>
+#include <xen/mm.h>
+#include <xen/sched.h>
+#include <xen/smp.h>
+#include <xen/softirq.h>
+#include <xen/timer.h>
+#include <xen/warning.h>
+#include <xen/irq.h>
+#include <xen/console.h>
+
+cpumask_t cpu_online_map;
+cpumask_t cpu_present_map;
+cpumask_t cpu_possible_map;
+
+/* Fake one node for now. See also include/asm-arm/numa.h */
+nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
+
+/* Boot cpu data */
+struct init_info init_data =
+{
+};
+
+/* Shared state for coordinating CPU teardown */
+static bool cpu_is_dead;
+
+/* ID of the PCPU we're running on */
+DEFINE_PER_CPU(unsigned int, cpu_id);
+/* XXX these seem awfully x86ish... */
+/* representing HT siblings of each logical CPU */
+DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_mask);
+/* representing HT and core siblings of each logical CPU */
+DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask);
+
+/*
+ * By default non-boot CPUs not identical to the boot CPU will be
+ * parked.
+ */
+static bool __read_mostly opt_hmp_unsafe = false;
+boolean_param("hmp-unsafe", opt_hmp_unsafe);
+
+int __cpu_up(unsigned int cpu)
+{
+    printk("Bringing up CPU%d\n", cpu);
+
+    console_start_sync(); /* Secondary may use early_printk */
+
+    /* TODO */
+
+    return 0;
+}
+
+/* Shut down the current CPU */
+void __cpu_disable(void)
+{
+    unsigned int cpu = get_processor_id();
+
+    /* TODO */
+
+    /* It's now safe to remove this processor from the online map */
+    cpumask_clear_cpu(cpu, &cpu_online_map);
+
+    smp_mb();
+
+    /* Return to caller; eventually the IPI mechanism will unwind and the 
+     * scheduler will drop to the idle loop, which will call stop_cpu(). */
+}
+
+void __cpu_die(unsigned int cpu)
+{
+    unsigned int i = 0;
+
+    while ( !cpu_is_dead )
+    {
+        mdelay(100);
+        cpu_relax();
+        process_pending_softirqs();
+        if ( (++i % 10) == 0 )
+            printk(KERN_ERR "CPU %u still not dead...\n", cpu);
+        smp_mb();
+    }
+    cpu_is_dead = false;
+    smp_mb();
+}
+
+void stop_cpu(void)
+{
+    local_irq_disable();
+    cpu_is_dead = true;
+
+    /* TODO */
+
+    while ( 1 )
+        wait_for_interrupt();
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#23 lore raw

RFC PATCH 21/23 riscv: Add percpu.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/percpu.c | 84 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 xen/arch/riscv/percpu.c
xen/arch/riscv/percpu.c new file +84 -0
new file mode 100644
index 0000000000..25442c48fe
@@ -0,0 +1,84 @@
+#include <xen/percpu.h>
+#include <xen/cpu.h>
+#include <xen/init.h>
+#include <xen/mm.h>
+#include <xen/rcupdate.h>
+
+unsigned long __per_cpu_offset[NR_CPUS];
+#define INVALID_PERCPU_AREA (-(long)__per_cpu_start)
+#define PERCPU_ORDER (get_order_from_bytes(__per_cpu_data_end-__per_cpu_start))
+
+void __init percpu_init_areas(void)
+{
+    unsigned int cpu;
+    for ( cpu = 1; cpu < NR_CPUS; cpu++ )
+        __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
+}
+
+static int init_percpu_area(unsigned int cpu)
+{
+    char *p;
+    if ( __per_cpu_offset[cpu] != INVALID_PERCPU_AREA )
+        return -EBUSY;
+    if ( (p = alloc_xenheap_pages(PERCPU_ORDER, 0)) == NULL )
+        return -ENOMEM;
+    memset(p, 0, __per_cpu_data_end - __per_cpu_start);
+    __per_cpu_offset[cpu] = p - __per_cpu_start;
+    return 0;
+}
+
+struct free_info {
+    unsigned int cpu;
+    struct rcu_head rcu;
+};
+static DEFINE_PER_CPU(struct free_info, free_info);
+
+static void _free_percpu_area(struct rcu_head *head)
+{
+    struct free_info *info = container_of(head, struct free_info, rcu);
+    unsigned int cpu = info->cpu;
+    char *p = __per_cpu_start + __per_cpu_offset[cpu];
+    free_xenheap_pages(p, PERCPU_ORDER);
+    __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
+}
+
+static void free_percpu_area(unsigned int cpu)
+{
+    struct free_info *info = &per_cpu(free_info, cpu);
+    info->cpu = cpu;
+    call_rcu(&info->rcu, _free_percpu_area);
+}
+
+static int cpu_percpu_callback(
+    struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+    unsigned int cpu = (unsigned long)hcpu;
+    int rc = 0;
+
+    switch ( action )
+    {
+    case CPU_UP_PREPARE:
+        rc = init_percpu_area(cpu);
+        break;
+    case CPU_UP_CANCELED:
+    case CPU_DEAD:
+        free_percpu_area(cpu);
+        break;
+    default:
+        break;
+    }
+
+    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+}
+
+static struct notifier_block cpu_percpu_nfb = {
+    .notifier_call = cpu_percpu_callback,
+    .priority = 100 /* highest priority */
+};
+
+static int __init percpu_presmp_init(void)
+{
+    register_cpu_notifier(&cpu_percpu_nfb);
+    return 0;
+}
+presmp_initcall(percpu_presmp_init);
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#24 lore raw

RFC PATCH 22/23 riscv: Add sysctl.c

In reply to Bobby Eshleman

From: Alistair Francis <[email protected]>

---
 xen/arch/riscv/sysctl.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 xen/arch/riscv/sysctl.c
xen/arch/riscv/sysctl.c new file +31 -0
new file mode 100644
index 0000000000..fbfdb44eff
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * Arch-specific sysctl.c
+ *
+ * System management operations. For use by node control stack.
+ *
+ * Copyright (c) 2012, Citrix Systems
+ */
+
+#include <xen/types.h>
+#include <xen/lib.h>
+#include <xen/errno.h>
+#include <xen/hypercall.h>
+#include <public/sysctl.h>
+
+void arch_do_physinfo(struct xen_sysctl_physinfo *pi) { }
+
+long arch_do_sysctl(struct xen_sysctl *sysctl,
+                    XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
+{
+    return -ENOSYS;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#25 lore raw

Re: [RFC XEN PATCH 22/23] riscv: Add sysctl.c

Quoted 13 lines · Bobby Eshleman
xen/arch/riscv/sysctl.c new file +10 -0
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * Arch-specific sysctl.c
+ *
+ * System management operations. For use by node control stack.
+ *
+ * Copyright (c) 2012, Citrix Systems
+ */
+
+#include <xen/types.h>
+#include <xen/lib.h>

xen/arch/riscv/sysctl.c line 20

Quoted 10 lines
xen/arch/riscv/sysctl.c new file +10 -0
+#include <xen/errno.h>
+#include <xen/hypercall.h>
+#include <public/sysctl.h>
+
+void arch_do_physinfo(struct xen_sysctl_physinfo *pi) { }
+
+long arch_do_sysctl(struct xen_sysctl *sysctl,
+                    XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
+{
+    return -ENOSYS;

At the example of this (there may be more in this series) - -EOPNOTSUPP please. Only top level hypercall handlers ought to produce -ENOSYS, for major hypercall numbers with no handler.

Jan

#26 lore raw

Re: [RFC XEN PATCH 22/23] riscv: Add sysctl.c

Quoted 20 lines · Jan Beulich
Quoted 19 lines · Bobby Eshleman
xen/arch/riscv/sysctl.c new file +16 -0
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * Arch-specific sysctl.c
+ *
+ * System management operations. For use by node control stack.
+ *
+ * Copyright (c) 2012, Citrix Systems
+ */
+
+#include <xen/types.h>
+#include <xen/lib.h>
+#include <xen/errno.h>
+#include <xen/hypercall.h>
+#include <public/sysctl.h>
+
+void arch_do_physinfo(struct xen_sysctl_physinfo *pi) { }
+
Quoted 9 lines

xen/arch/riscv/sysctl.c line 20

Quoted 4 lines
xen/arch/riscv/sysctl.c new file +4 -0
+long arch_do_sysctl(struct xen_sysctl *sysctl,
+                    XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
+{
+    return -ENOSYS;

At the example of this (there may be more in this series) - -EOPNOTSUPP please. Only top level hypercall handlers ought to produce -ENOSYS, for major hypercall numbers with no handler.

Got it, will do. Thanks!

#27 lore raw

RFC PATCH 23/23 riscv: Add iommu.c

In reply to Bobby Eshleman
---
 xen/drivers/passthrough/riscv/iommu.c | 74 +++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 xen/drivers/passthrough/riscv/iommu.c
xen/drivers/passthrough/riscv/iommu.c new file +74 -0
new file mode 100644
index 0000000000..81db4958b2
@@ -0,0 +1,74 @@
+/*
+ * IOMMU framework for RISC-V
+ *
+ * Based off passthrough/arm/iommu.c
+ *
+ * Bobby Eshleman <bobbyeshleman@gmail>
+ * Copyright (c) 2019
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/iommu.h>
+
+static const struct iommu_ops *iommu_ops;
+
+const struct iommu_ops *iommu_get_ops(void)
+{
+    return iommu_ops;
+}
+
+void __init iommu_set_ops(const struct iommu_ops *ops)
+{
+    BUG_ON(ops == NULL);
+
+    if ( iommu_ops && iommu_ops != ops )
+    {
+        printk("WARNING: Cannot set IOMMU ops, already set to a different value\n");
+        return;
+    }
+
+    iommu_ops = ops;
+}
+
+int __init iommu_hardware_setup(void)
+{
+    /* TODO */
+    return 0;
+}
+
+void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d)
+{
+    /* TODO */
+    return;
+}
+
+int arch_iommu_domain_init(struct domain *d)
+{
+    /* TODO */
+    return 0;
+}
+
+void arch_iommu_domain_destroy(struct domain *d)
+{
+    /* TODO */
+}
+
+int arch_iommu_populate_page_table(struct domain *d)
+{
+    /* TODO */
+    return -ENOSYS;
+}
+
+void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
+{
+    /* TODO */
+}
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#28 lore raw
In reply to Bobby Eshleman
Quoted 36 lines · Bobby Eshleman

Hey everybody,

This is an RFC patchset for the very beginnings of adding RISC-V support to Xen. This RFC is really just to start a dialogue about supporting RISC-V and align with the Xen project and community before going further. For that reason, it is very rough and very incomplete.

My name is Bobby Eshleman, I'm a software engineer at
Star Lab / Wind River on the ARM team, mostly having worked in the Linux kernel. I've also been involved a good amount with Xen on ARM here, mostly dealing with tooling, deployment, and testing. A lot of this patchset is heavily inspired by the Xen/ARM source code (particularly the early setup up code).

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

Because the ARM and RISC-V use cases will likely bear resemblance, the RISC-V port should probably respect the design considerations that have been laid out and respected by Xen on ARM for dom0less, safety certification, etc... My inclination has been to initially target or prioritize dom0less (without excluding dom0full) and use the ARM dom0less implementation as a model to follow. I'd love feedback on this point and on how the Xen project might envision a RISC-V implementation.

This patchset has _some_ code for future support for 32-bit, but currently my focus is on 64-bit.

Quoted 7 lines

Again, this is a very, very rough and totally incomplete patchset. My goal here is just to gauge community interest, begin discussing what Xen on RISC-V may look like, receive feedback, and see if I'm heading in the right direction.

My big questions are:
Does the Xen project have interest in RISC-V?

There is very large downstream interest in RISC-V.  So a definite yes.

Quoted 5 lines

What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Both RISC-V and Power9 are frequently requested things, and both suffer from the fact that, while we as a community would like them, the upstream intersection of "people who know Xen" and "people who know enough arch $X to do an initial port" is 0.

This series clearly demonstrates a change in the status quo, and I think a lot of people will be happy.

To get RISC-V to being fully supported, we will ultimately need to get hardware into the CI system, and an easy way for developers to test changes.  Do you have any thoughts on production RISC-V hardware (ideally server form factor) for the CI system, and/or dev boards which might be available fairly cheaply?

How much time do you have to put towards the port?  Is this something in your free time, or something you are doing as part of work?  Ultimately, we are going to need to increase the level of RISC-V knowledge in the community to maintain things in the future.

Other than that, very RFC series are entirely fine.  A good first step would be simply to get the build working, and get some kind of cross-compile build in CI, to make sure that we don't clobber the RISC-V build with common or other-arch changes.

I hope this helps.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#29 lore raw
Quoted 76 lines · Andrew Cooper
Quoted 36 lines · Bobby Eshleman

Hey everybody,

This is an RFC patchset for the very beginnings of adding RISC-V support to Xen. This RFC is really just to start a dialogue about supporting RISC-V and align with the Xen project and community before going further. For that reason, it is very rough and very incomplete.

My name is Bobby Eshleman, I'm a software engineer at
Star Lab / Wind River on the ARM team, mostly having worked in the Linux kernel. I've also been involved a good amount with Xen on ARM here, mostly dealing with tooling, deployment, and testing. A lot of this patchset is heavily inspired by the Xen/ARM source code (particularly the early setup up code).

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

Because the ARM and RISC-V use cases will likely bear resemblance, the RISC-V port should probably respect the design considerations that have been laid out and respected by Xen on ARM for dom0less, safety certification, etc... My inclination has been to initially target or prioritize dom0less (without excluding dom0full) and use the ARM dom0less implementation as a model to follow. I'd love feedback on this point and on how the Xen project might envision a RISC-V implementation.

This patchset has _some_ code for future support for 32-bit, but currently my focus is on 64-bit.

Quoted 7 lines

Again, this is a very, very rough and totally incomplete patchset. My goal here is just to gauge community interest, begin discussing what Xen on RISC-V may look like, receive feedback, and see if I'm heading in the right direction.

My big questions are:
Does the Xen project have interest in RISC-V?

There is very large downstream interest in RISC-V. So a definite yes.

Quoted 5 lines

What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Both RISC-V and Power9 are frequently requested things, and both suffer from the fact that, while we as a community would like them, the upstream intersection of "people who know Xen" and "people who know enough arch $X to do an initial port" is 0.

This series clearly demonstrates a change in the status quo, and I think a lot of people will be happy.

To get RISC-V to being fully supported, we will ultimately need to get hardware into the CI system, and an easy way for developers to test changes. Do you have any thoughts on production RISC-V hardware (ideally server form factor) for the CI system, and/or dev boards which might be available fairly cheaply?

How much time do you have to put towards the port? Is this something in your free time, or something you are doing as part of work? Ultimately, we are going to need to increase the level of RISC-V knowledge in the community to maintain things in the future.

Quoted 6 lines

Other than that, very RFC series are entirely fine. A good first step would be simply to get the build working, and get some kind of cross-compile build in CI, to make sure that we don't clobber the RISC-V build with common or other-arch changes.

I hope this helps.

I totally agree with what Andy says.

You should also leverage the developer summit: see https://events.linuxfoundation.org/xen-summit/program/cfp/ <https://events.linuxfoundation.org/xen-summit/program/cfp/>
CfP closes March 6th. Design sessions can be submitted afterwards

Community calls may also be a good option to deal with specific issues / questions, e.g. around compile support in the CI, etc.

Lars

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#30 lore raw
Quoted 8 lines · Lars Kurth

You should also leverage the developer summit: see https://events.linuxfoundation.org/xen-summit/program/cfp/ <https://events.linuxfoundation.org/xen-summit/program/cfp/>
CfP closes March 6th. Design sessions can be submitted afterwards

Community calls may also be a good option to deal with specific issues / questions, e.g. around compile support in the CI, etc.

Lars

That's a really good idea. I'll submit as I do think I can get there if accepted. Thanks for the tip on community calls, I did not realize Xen did those!

-Bobby

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#31 lore raw
Quoted 11 lines · Bobby Eshleman
Quoted 6 lines · Lars Kurth

You should also leverage the developer summit: see https://events.linuxfoundation.org/xen-summit/program/cfp/ <https://events.linuxfoundation.org/xen-summit/program/cfp/>
CfP closes March 6th. Design sessions can be submitted afterwards

Community calls may also be a good option to deal with specific issues / questions, e.g. around compile support in the CI, etc.

Quoted 7 lines
Quoted 2 lines

Lars

That's a really good idea. I'll submit as I do think I can get there if accepted. Thanks for the tip on community calls, I did not realize Xen did those!

-Bobby

If you add your name/email address to https://cryptpad.fr/pad/#/2/pad/edit/D9vGzihPxxAOe6RFPz0sRCf+/ <https://cryptpad.fr/pad/#/2/pad/edit/D9vGzihPxxAOe6RFPz0sRCf+/> I will CC you on the next invite They are usually the 1st Thursday of each month
Past minutes can be found at https://cryptpad.fr/drive/#/2/drive/edit/uZ1UjYxICjse+XlJrXrIwZXN/
Lars

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#32 lore raw
Quoted 4 lines · Lars Kurth

If you add your name/email address to https://cryptpad.fr/pad/#/2/pad/edit/D9vGzihPxxAOe6RFPz0sRCf+/ <https://cryptpad.fr/pad/#/2/pad/edit/D9vGzihPxxAOe6RFPz0sRCf+/> I will CC you on the next invite They are usually the 1st Thursday of each month
Past minutes can be found at https://cryptpad.fr/drive/#/2/drive/edit/uZ1UjYxICjse+XlJrXrIwZXN/
Lars

Done! Thanks.

-Bobby

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#33 lore raw
In reply to Andrew Cooper
Quoted 4 lines · Andrew Cooper
Quoted 2 lines

My big questions are:
Does the Xen project have interest in RISC-V?

There is very large downstream interest in RISC-V.  So a definite yes.

Definite Yes from me too

Quoted 11 lines
Quoted 5 lines

What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Both RISC-V and Power9 are frequently requested things, and both suffer from the fact that, while we as a community would like them, the upstream intersection of "people who know Xen" and "people who know enough arch $X to do an initial port" is 0.

Quoted 8 lines

This series clearly demonstrates a change in the status quo, and I think a lot of people will be happy.

To get RISC-V to being fully supported, we will ultimately need to get hardware into the CI system, and an easy way for developers to test changes.  Do you have any thoughts on production RISC-V hardware (ideally server form factor) for the CI system, and/or dev boards which might be available fairly cheaply?

My understanding is that virtualization development for RISC-V is done on QEMU right now (which could still be hooked into the CI system if somebody wanted to do the work I think.)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): 20200123044527.GA5583@bobbye-pc

#35 lore raw
Quoted 8 lines · Stefano Stabellini
Quoted 4 lines · Andrew Cooper
Quoted 2 lines

My big questions are:
Does the Xen project have interest in RISC-V?

There is very large downstream interest in RISC-V.  So a definite yes.

Definite Yes from me too

Both great to hear!

Quoted 21 lines
Quoted 12 lines
Quoted 6 lines

What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Both RISC-V and Power9 are frequently requested things, and both suffer from the fact that, while we as a community would like them, the upstream intersection of "people who know Xen" and "people who know enough arch $X to do an initial port" is 0.

Quoted 8 lines

This series clearly demonstrates a change in the status quo, and I think a lot of people will be happy.

To get RISC-V to being fully supported, we will ultimately need to get hardware into the CI system, and an easy way for developers to test changes.  Do you have any thoughts on production RISC-V hardware (ideally server form factor) for the CI system, and/or dev boards which might be available fairly cheaply?

Quoted 3 lines

My understanding is that virtualization development for RISC-V is done on QEMU right now (which could still be hooked into the CI system if somebody wanted to do the work I think.)

That is correct. I think the RTL and hardware folks are waiting for the spec to be finalized before committing to the effort, so everyone is just developing against QEMU for now.

I can certainly look at hooking in QEMU to the CI at some point soon. That is the OSSTest repo, correct?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#36 lore raw
In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

How much time do you have to put towards the port?  Is this something in your free time, or something you are doing as part of work?  Ultimately, we are going to need to increase the level of RISC-V knowledge in the community to maintain things in the future.

This is something in my free time, and I have about 20 hours a week to put into it.

Quoted 5 lines

Other than that, very RFC series are entirely fine.  A good first step would be simply to get the build working, and get some kind of cross-compile build in CI, to make sure that we don't clobber the RISC-V build with common or other-arch changes.

That's something I can look at, if the idea of QEMU in CI is not too horrific.

Quoted 3 lines

I hope this helps.

~Andrew

Definitely helps, thanks!

-Bobby

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#37 lore raw
Quoted 8 lines · Bobby Eshleman
Quoted 5 lines · Andrew Cooper

How much time do you have to put towards the port?  Is this something in your free time, or something you are doing as part of work?  Ultimately, we are going to need to increase the level of RISC-V knowledge in the community to maintain things in the future.

This is something in my free time, and I have about 20 hours a week to put into it.

Ok, so not full time, but hopefully enough time to help spread some knowledge.

Quoted 8 lines
Quoted 6 lines

Other than that, very RFC series are entirely fine.  A good first step would be simply to get the build working, and get some kind of cross-compile build in CI, to make sure that we don't clobber the RISC-V build with common or other-arch changes.

That's something I can look at, if the idea of QEMU in CI is not too horrific.

We have https://gitlab.com/xen-project/xen/pipelines which runs a load of containerised builds.  How easy is it to set up a containerised RISC-V cross-compiler environment?

The test step also boots Xen under Qemu software emulation to check that we don't have any boot-time screamers.  A reasonable second step might be to have start_xen() panic() at the end, and check for that in the console log, which would allow for some kind of boot testing before getting all the way to "and here is dom0 ready to run".

All configuration is in .gitlab-ci.yml and automation/.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#38 lore raw
Quoted 5 lines · Andrew Cooper

We have https://gitlab.com/xen-project/xen/pipelines which runs a load of containerised builds.  How easy is it to set up a containerised RISC-V cross-compiler environment?

It's pretty easy. I personally use a Docker container that has the bins built from source from both the RISC-V gcc toolchain and QEMU.

Quoted 8 lines

The test step also boots Xen under Qemu software emulation to check that we don't have any boot-time screamers.  A reasonable second step might be to have start_xen() panic() at the end, and check for that in the console log, which would allow for some kind of boot testing before getting all the way to "and here is dom0 ready to run".

All configuration is in .gitlab-ci.yml and automation/.

That sounds ideal and like a perfect place to start.

Thanks!
-Bobby

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#39 lore raw
In reply to Andrew Cooper
Quoted 85 lines · Andrew Cooper
Quoted 62 lines · Bobby Eshleman

Hey everybody,

This is an RFC patchset for the very beginnings of adding RISC-V support
to Xen. This RFC is really just to start a dialogue about supporting
RISC-V and align with the Xen project and community before going further. For that reason, it is very rough and very incomplete.

My name is Bobby Eshleman, I'm a software engineer at Star Lab / Wind River on the ARM team, mostly having worked in the Linux
kernel. I've also been involved a good amount with Xen on ARM here,
mostly dealing with tooling, deployment, and testing. A lot of this
patchset is heavily inspired by the Xen/ARM source code (particularly
the early setup up code).

Currently, this patchset really only sets up virtual memory for Xen and
initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the
next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been
left accordingly. It is very, very rough. Be forewarned: you are quite
likely to see some ungainly code here (despite my efforts to clean it up
before sending this patchset out). My intent with this RFC is to align
early and gauge interest, as opposed to presenting a totally complete
patchset.

Because the ARM and RISC-V use cases will likely bear resemblance, the
RISC-V port should probably respect the design considerations that have
been laid out and respected by Xen on ARM for dom0less, safety certification, etc... My inclination has been to initially target or
prioritize dom0less (without excluding dom0full) and use the ARM dom0less implementation as a model to follow. I'd love feedback on this
point and on how the Xen project might envision a RISC-V implementation.

This patchset has _some_ code for future support for 32-bit, but currently my focus is on 64-bit.

Again, this is a very, very rough and totally incomplete patchset. My
goal here is just to gauge community interest, begin discussing what Xen
on RISC-V may look like, receive feedback, and see if I'm heading in the
right direction.

Quoted 2 lines

My big questions are:
Does the Xen project have interest in RISC-V?

There is very large downstream interest in RISC-V. So a definite yes.

Quoted 5 lines

What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Both RISC-V and Power9 are frequently requested things, and both suffer
from the fact that, while we as a community would like them, the upstream intersection of "people who know Xen" and "people who know enough arch $X to do an initial port" is 0.

This series clearly demonstrates a change in the status quo, and I think
a lot of people will be happy.

Quoted 7 lines

To get RISC-V to being fully supported, we will ultimately need to get
hardware into the CI system, and an easy way for developers to test changes. Do you have any thoughts on production RISC-V hardware (ideally server form factor) for the CI system, and/or dev boards which
might be available fairly cheaply?

AFAIK this is awhile off. The Hypervisor spec is still in a draft state (expecting to be frozen this year) so right now QEMU is the only option.

Alistair

Quoted 15 lines

How much time do you have to put towards the port? Is this something in
your free time, or something you are doing as part of work? Ultimately,
we are going to need to increase the level of RISC-V knowledge in the community to maintain things in the future.

Other than that, very RFC series are entirely fine. A good first step
would be simply to get the build working, and get some kind of cross-compile build in CI, to make sure that we don't clobber the RISC-V
build with common or other-arch changes.

Quoted 3 lines

I hope this helps.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#40 lore raw
In reply to Bobby Eshleman
Quoted 10 lines · Bobby Eshleman

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

I've taken a very quick look over the series.

Normally, we require that all patches be bisectable, and this series is not because of the Makefile changes in patch 3 specifying object files which are introduced in the following 20 patches.  Of course, introducing a brand new architecture is a special case, but the suggested plan of getting a "minimal build" together will help keep the second phase of "making it boot".

To start with, I'd recommend a head.S with _start: and an infinite loop, along with whatever makefile/kconfig infrastructure is required to get a build.

Within that first phase however, there are some obvious tweaks we should make to common code.  For one, the debugger_trap() infrastructure really is x86-specific (and I haven't seen it used in a decade) so should have its ARM stubs dropped so as not to be a burden on other architectures.

There are other aspects (the atomic_t infrastructure) where x86 and ARM already have basically identical copies of the header file, and you've taken a 3rd copy.

Other areas where you can reduce the minimum build would be to put some defaults into the defconfig, such as disabling grant tables and mem access.  There are almost certainly others which will help, so have a search around menuconfig.

Disabling grant tables in particular will work around the fact that the ARM snapshot you based your port on was pre-XSA-295, and the cmpxchg loop against guest memory in gnttab_clear_flags() is reintroducing a previously-fixed security vulnerability.

Some ARM-isms you've inherited would be much better if you didn't.  In particular, I *really* hope RISC-V hasn't made the same backwards naming bug in their pagetable levels which results in {second,first,zeroth}_* et al.  In x86, we purposefully chose not to follow Intel's naming, and instead went with L1, L2, L3, and for 64bit L4.

As a couple of general points from our coding style, please avoid commented out code, and you are free to omit braces for single statement blocks.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#41 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 10 lines · Bobby Eshleman

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

Quoted 8 lines

I've taken a very quick look over the series.

Normally, we require that all patches be bisectable, and this series is not because of the Makefile changes in patch 3 specifying object files which are introduced in the following 20 patches.  Of course, introducing a brand new architecture is a special case, but the suggested plan of getting a "minimal build" together will help keep the second phase of "making it boot".

That totally makes sense.

Quoted 5 lines

To start with, I'd recommend a head.S with _start: and an infinite loop, along with whatever makefile/kconfig infrastructure is required to get a build.

Got it, sounds like a plan.

Quoted 5 lines

Within that first phase however, there are some obvious tweaks we should make to common code.  For one, the debugger_trap() infrastructure really is x86-specific (and I haven't seen it used in a decade) so should have its ARM stubs dropped so as not to be a burden on other architectures.

Quoted 8 lines

There are other aspects (the atomic_t infrastructure) where x86 and ARM already have basically identical copies of the header file, and you've taken a 3rd copy.

Other areas where you can reduce the minimum build would be to put some defaults into the defconfig, such as disabling grant tables and mem access.  There are almost certainly others which will help, so have a search around menuconfig.

Taking note of these, I can definitely do that.

Quoted 5 lines

Disabling grant tables in particular will work around the fact that the ARM snapshot you based your port on was pre-XSA-295, and the cmpxchg loop against guest memory in gnttab_clear_flags() is reintroducing a previously-fixed security vulnerability.

Duly noted, I'll fix that and look over some of those again and compare them to the newer files, as some are definitely a few version bumps behind.

Quoted 7 lines

Some ARM-isms you've inherited would be much better if you didn't.  In particular, I *really* hope RISC-V hasn't made the same backwards naming bug in their pagetable levels which results in {second,first,zeroth}_* et al.  In x86, we purposefully chose not to follow Intel's naming, and instead went with L1, L2, L3, and for 64bit L4.

The RISC-V spec does indeed describe the table level numbers in reverse
order: L2 points to L1 points to L0 (for 39bit addresses).

For SV48 48bit addresses, it's L3, L2, L1, to L0.

That said, in the spec there is no direct mention of LX for levels, and instead these are referred to by the section from the "virtual page number" that they are referred by, (ie VPN[3], VPN[2], etc...).

I definitely would not be strongly opposed to this change for a form that reads better.

Quoted 5 lines

As a couple of general points from our coding style, please avoid commented out code, and you are free to omit braces for single statement blocks.

~Andrew

Thanks again,
-Bobby

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#42 lore raw
Quoted 14 lines · Bobby Eshleman
Quoted 13 lines · Andrew Cooper
Quoted 10 lines · Bobby Eshleman

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

I've taken a very quick look over the series.

Quoted 7 lines
Quoted 6 lines

Normally, we require that all patches be bisectable, and this series is not because of the Makefile changes in patch 3 specifying object files which are introduced in the following 20 patches.  Of course, introducing a brand new architecture is a special case, but the suggested plan of getting a "minimal build" together will help keep the second phase of "making it boot".

That totally makes sense.

I see I trailed off in the middle of that final sentence, but it seems I did get my point across.

Quoted 9 lines
Quoted 9 lines

Within that first phase however, there are some obvious tweaks we should make to common code.  For one, the debugger_trap() infrastructure really is x86-specific (and I haven't seen it used in a decade) so should have its ARM stubs dropped so as not to be a burden on other architectures.

There are other aspects (the atomic_t infrastructure) where x86 and ARM already have basically identical copies of the header file, and you've taken a 3rd copy.

Quoted 5 lines
Quoted 4 lines

Other areas where you can reduce the minimum build would be to put some defaults into the defconfig, such as disabling grant tables and mem access.  There are almost certainly others which will help, so have a search around menuconfig.

Taking note of these, I can definitely do that.

To fore-warn you, there probably will be more things like this which become apparent on further review.

While I don't expect you to do all the cleanup (some will almost certainly be quicker for others to do), I would like to take the opportunity to do the obvious bits of cleanup, given the rare opportunity of seeing the minimum viable set of things to make a new arch compile.

Quoted 8 lines
Quoted 5 lines

Some ARM-isms you've inherited would be much better if you didn't.  In particular, I *really* hope RISC-V hasn't made the same backwards naming bug in their pagetable levels which results in {second,first,zeroth}_* et al.  In x86, we purposefully chose not to follow Intel's naming, and instead went with L1, L2, L3, and for 64bit L4.

The RISC-V spec does indeed describe the table level numbers in reverse
order: L2 points to L1 points to L0 (for 39bit addresses).

Quoted 8 lines

For SV48 48bit addresses, it's L3, L2, L1, to L0.

That said, in the spec there is no direct mention of LX for levels, and instead these are referred to by the section from the "virtual page number" that they are referred by, (ie VPN[3], VPN[2], etc...).

I definitely would not be strongly opposed to this change for a form that reads better.

This looks to be the same as what we've chosen to do in x86, give or take a fencepost.

I'd recommend using L{3..0} for similarity with the spec (you surely don't want an off-by-one difference between code in Xen and the spec). Whatever you end up choosing, put a description at the top of mm.h (or wherever appropriate) which briefly introduces the terminology in Xen, and cross references any differences with the spec.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#43 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 6 lines · Bobby Eshleman
Quoted 4 lines · Andrew Cooper

Other areas where you can reduce the minimum build would be to put some defaults into the defconfig, such as disabling grant tables and mem access.  There are almost certainly others which will help, so have a search around menuconfig.

Taking note of these, I can definitely do that.

Quoted 8 lines

To fore-warn you, there probably will be more things like this which become apparent on further review.

While I don't expect you to do all the cleanup (some will almost certainly be quicker for others to do), I would like to take the opportunity to do the obvious bits of cleanup, given the rare opportunity of seeing the minimum viable set of things to make a new arch compile.

This sounds very reasonable.

Quoted 8 lines

This looks to be the same as what we've chosen to do in x86, give or take a fencepost.

I'd recommend using L{3..0} for similarity with the spec (you surely don't want an off-by-one difference between code in Xen and the spec). Whatever you end up choosing, put a description at the top of mm.h (or wherever appropriate) which briefly introduces the terminology in Xen, and cross references any differences with the spec.

Roger that.

Thanks again for the feedback.

-Bobby

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#44 lore raw
In reply to Bobby Eshleman

Any updates? I am looking forward to this :-)

Quoted 312 lines · Bobby Eshleman

Hey everybody,

This is an RFC patchset for the very beginnings of adding RISC-V support to Xen. This RFC is really just to start a dialogue about supporting RISC-V and align with the Xen project and community before going further. For that reason, it is very rough and very incomplete.

My name is Bobby Eshleman, I'm a software engineer at
Star Lab / Wind River on the ARM team, mostly having worked in the Linux kernel. I've also been involved a good amount with Xen on ARM here, mostly dealing with tooling, deployment, and testing. A lot of this patchset is heavily inspired by the Xen/ARM source code (particularly the early setup up code).

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

Because the ARM and RISC-V use cases will likely bear resemblance, the RISC-V port should probably respect the design considerations that have been laid out and respected by Xen on ARM for dom0less, safety certification, etc... My inclination has been to initially target or prioritize dom0less (without excluding dom0full) and use the ARM dom0less implementation as a model to follow. I'd love feedback on this point and on how the Xen project might envision a RISC-V implementation.

This patchset has _some_ code for future support for 32-bit, but currently my focus is on 64-bit.

Again, this is a very, very rough and totally incomplete patchset. My goal here is just to gauge community interest, begin discussing what Xen on RISC-V may look like, receive feedback, and see if I'm heading in the right direction.

My big questions are:
Does the Xen project have interest in RISC-V? What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Alistair Francis (20):
HACK: OE Build changes
HACK: Makefile: Don't build Xen tools
riscv: makefiles and Kconfig
riscv: Add riscv to tools/libxc header files
riscv: Add asm-offsets.c
riscv: Add delay.c
riscv: Add domain.c
riscv: Add domctl.c
riscv: Add guestcopy.c
riscv: Add time.c
riscv: Add smp.c
riscv: Add shutdown.c
riscv: Add traps.c
riscv: Add irq.c
riscv: Add vm_event.c
riscv: Add p2m.c
riscv: Add the lib directory
riscv: Add smpboot.c
riscv: Add percpu.c
riscv: Add sysctl.c

Bobby Eshleman (3):
riscv: header files
riscv: early setup code
riscv: Add iommu.c

 Makefile                                 |  13 +-
 config/StdGNU.mk                         |  12 +-
 config/riscv64.mk                        |   7 +
 tools/configure                          |  32 +-
 tools/firmware/Makefile                  |  12 +-
 tools/libxc/include/xenctrl.h            |   7 +
 tools/libxc/xc_core.h                    |   2 +
 tools/libxc/xc_core_riscv.h              |  57 ++
 xen/Makefile                             |   2 +-
 xen/Rules.mk                             |   2 +-
 xen/arch/Kconfig                         |   1 +
 xen/arch/riscv/Kconfig                   |  36 +
 xen/arch/riscv/Makefile                  |  62 ++
 xen/arch/riscv/Rules.mk                  |  55 ++
 xen/arch/riscv/asm-offsets.c             |  38 +
 xen/arch/riscv/configs/riscv32_defconfig |   0
 xen/arch/riscv/configs/riscv64_defconfig |   0
 xen/arch/riscv/delay.c                   | 114 +++
 xen/arch/riscv/domain.c                  | 273 +++++++
 xen/arch/riscv/domctl.c                  |  53 ++
 xen/arch/riscv/guestcopy.c               | 158 ++++
 xen/arch/riscv/head.S                    | 180 +++++
 xen/arch/riscv/irq.c                     | 107 +++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++
 xen/arch/riscv/mm.c                      | 925 +++++++++++++++++++++++
 xen/arch/riscv/p2m.c                     | 261 +++++++
 xen/arch/riscv/percpu.c                  |  84 ++
 xen/arch/riscv/platforms/Kconfig         |  31 +
 xen/arch/riscv/setup.c                   | 122 +++
 xen/arch/riscv/shutdown.c                |  24 +
 xen/arch/riscv/smp.c                     |  41 +
 xen/arch/riscv/smpboot.c                 | 114 +++
 xen/arch/riscv/sysctl.c                  |  31 +
 xen/arch/riscv/time.c                    |  74 ++
 xen/arch/riscv/traps.c                   |  56 ++
 xen/arch/riscv/vm_event.c                |  42 +
 xen/arch/riscv/xen.lds.S                 | 262 +++++++
 xen/drivers/passthrough/Makefile         |   1 +
 xen/drivers/passthrough/riscv/Makefile   |   1 +
 xen/drivers/passthrough/riscv/iommu.c    |  74 ++
 xen/include/asm-riscv/altp2m.h           |  39 +
 xen/include/asm-riscv/asm.h              |  76 ++
 xen/include/asm-riscv/atomic.h           | 249 ++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++
 xen/include/asm-riscv/bug.h              |  59 ++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 +
 xen/include/asm-riscv/cmpxchg.h          | 382 ++++++++++
 xen/include/asm-riscv/config.h           | 203 +++++
 xen/include/asm-riscv/csr.h              | 117 +++
 xen/include/asm-riscv/current.h          |  50 ++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  28 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 +
 xen/include/asm-riscv/domain.h           |  85 +++
 xen/include/asm-riscv/event.h            |  42 +
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  56 ++
 xen/include/asm-riscv/grant_table.h      |  93 +++
 xen/include/asm-riscv/guest_access.h     | 164 ++++
 xen/include/asm-riscv/guest_atomics.h    |  62 ++
 xen/include/asm-riscv/hardirq.h          |  27 +
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +
 xen/include/asm-riscv/io.h               | 283 +++++++
 xen/include/asm-riscv/iocap.h            |  16 +
 xen/include/asm-riscv/iommu.h            |  49 ++
 xen/include/asm-riscv/irq.h              |  58 ++
 xen/include/asm-riscv/mem_access.h       |  35 +
 xen/include/asm-riscv/mm.h               | 308 ++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++
 xen/include/asm-riscv/nospec.h           |  25 +
 xen/include/asm-riscv/numa.h             |  41 +
 xen/include/asm-riscv/p2m.h              | 410 ++++++++++
 xen/include/asm-riscv/page.h             | 327 ++++++++
 xen/include/asm-riscv/paging.h           |  16 +
 xen/include/asm-riscv/pci.h              |  31 +
 xen/include/asm-riscv/percpu.h           |  34 +
 xen/include/asm-riscv/pgtable-bits.h     |  53 ++
 xen/include/asm-riscv/processor.h        |  60 ++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  42 +
 xen/include/asm-riscv/riscv_encoding.h   | 682 +++++++++++++++++
 xen/include/asm-riscv/setup.h            |  16 +
 xen/include/asm-riscv/smp.h              |  50 ++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  13 +
 xen/include/asm-riscv/string.h           |  28 +
 xen/include/asm-riscv/sysregs.h          |  14 +
 xen/include/asm-riscv/system.h           |  96 +++
 xen/include/asm-riscv/time.h             |  60 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  73 ++
 xen/include/asm-riscv/vm_event.h         |  61 ++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 181 +++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 103 files changed, 9064 insertions(+), 42 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 tools/libxc/xc_core_riscv.h
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/asm-offsets.c
 create mode 100644 xen/arch/riscv/configs/riscv32_defconfig
 create mode 100644 xen/arch/riscv/configs/riscv64_defconfig
 create mode 100644 xen/arch/riscv/delay.c
 create mode 100644 xen/arch/riscv/domain.c
 create mode 100644 xen/arch/riscv/domctl.c
 create mode 100644 xen/arch/riscv/guestcopy.c
 create mode 100644 xen/arch/riscv/head.S
 create mode 100644 xen/arch/riscv/irq.c
 create mode 100644 xen/arch/riscv/lib/Makefile
 create mode 100644 xen/arch/riscv/lib/find_next_bit.c
 create mode 100644 xen/arch/riscv/mm.c
 create mode 100644 xen/arch/riscv/p2m.c
 create mode 100644 xen/arch/riscv/percpu.c
 create mode 100644 xen/arch/riscv/platforms/Kconfig
 create mode 100644 xen/arch/riscv/setup.c
 create mode 100644 xen/arch/riscv/shutdown.c
 create mode 100644 xen/arch/riscv/smp.c
 create mode 100644 xen/arch/riscv/smpboot.c
 create mode 100644 xen/arch/riscv/sysctl.c
 create mode 100644 xen/arch/riscv/time.c
 create mode 100644 xen/arch/riscv/traps.c
 create mode 100644 xen/arch/riscv/vm_event.c
 create mode 100644 xen/arch/riscv/xen.lds.S
 create mode 100644 xen/drivers/passthrough/riscv/Makefile
 create mode 100644 xen/drivers/passthrough/riscv/iommu.c
 create mode 100644 xen/include/asm-riscv/altp2m.h
 create mode 100644 xen/include/asm-riscv/asm.h
 create mode 100644 xen/include/asm-riscv/atomic.h
 create mode 100644 xen/include/asm-riscv/bitops.h
 create mode 100644 xen/include/asm-riscv/bug.h
 create mode 100644 xen/include/asm-riscv/byteorder.h
 create mode 100644 xen/include/asm-riscv/cache.h
 create mode 100644 xen/include/asm-riscv/cmpxchg.h
 create mode 100644 xen/include/asm-riscv/config.h
 create mode 100644 xen/include/asm-riscv/csr.h
 create mode 100644 xen/include/asm-riscv/current.h
 create mode 100644 xen/include/asm-riscv/debugger.h
 create mode 100644 xen/include/asm-riscv/delay.h
 create mode 100644 xen/include/asm-riscv/desc.h
 create mode 100644 xen/include/asm-riscv/device.h
 create mode 100644 xen/include/asm-riscv/div64.h
 create mode 100644 xen/include/asm-riscv/domain.h
 create mode 100644 xen/include/asm-riscv/event.h
 create mode 100644 xen/include/asm-riscv/fence.h
 create mode 100644 xen/include/asm-riscv/flushtlb.h
 create mode 100644 xen/include/asm-riscv/grant_table.h
 create mode 100644 xen/include/asm-riscv/guest_access.h
 create mode 100644 xen/include/asm-riscv/guest_atomics.h
 create mode 100644 xen/include/asm-riscv/hardirq.h
 create mode 100644 xen/include/asm-riscv/hypercall.h
 create mode 100644 xen/include/asm-riscv/init.h
 create mode 100644 xen/include/asm-riscv/io.h
 create mode 100644 xen/include/asm-riscv/iocap.h
 create mode 100644 xen/include/asm-riscv/iommu.h
 create mode 100644 xen/include/asm-riscv/irq.h
 create mode 100644 xen/include/asm-riscv/mem_access.h
 create mode 100644 xen/include/asm-riscv/mm.h
 create mode 100644 xen/include/asm-riscv/monitor.h
 create mode 100644 xen/include/asm-riscv/nospec.h
 create mode 100644 xen/include/asm-riscv/numa.h
 create mode 100644 xen/include/asm-riscv/p2m.h
 create mode 100644 xen/include/asm-riscv/page.h
 create mode 100644 xen/include/asm-riscv/paging.h
 create mode 100644 xen/include/asm-riscv/pci.h
 create mode 100644 xen/include/asm-riscv/percpu.h
 create mode 100644 xen/include/asm-riscv/pgtable-bits.h
 create mode 100644 xen/include/asm-riscv/processor.h
 create mode 100644 xen/include/asm-riscv/random.h
 create mode 100644 xen/include/asm-riscv/regs.h
 create mode 100644 xen/include/asm-riscv/riscv_encoding.h
 create mode 100644 xen/include/asm-riscv/setup.h
 create mode 100644 xen/include/asm-riscv/smp.h
 create mode 100644 xen/include/asm-riscv/softirq.h
 create mode 100644 xen/include/asm-riscv/spinlock.h
 create mode 100644 xen/include/asm-riscv/string.h
 create mode 100644 xen/include/asm-riscv/sysregs.h
 create mode 100644 xen/include/asm-riscv/system.h
 create mode 100644 xen/include/asm-riscv/time.h
 create mode 100644 xen/include/asm-riscv/trace.h
 create mode 100644 xen/include/asm-riscv/types.h
 create mode 100644 xen/include/asm-riscv/vm_event.h
 create mode 100644 xen/include/asm-riscv/xenoprof.h
 create mode 100644 xen/include/public/arch-riscv.h
 create mode 100644 xen/include/public/arch-riscv/hvm/save.h
Signature · 39 lines
2.25.0

The source code can be found on github:
	https://github.com/beshleman/xen/tree/port-to-risc-v

The patchset only targets the QEMU virt board and it is tested on
Alistair Francis's patchset for QEMU with RISC-V hypervisor extensions
v0.5, found here:
	https://github.com/alistair23/qemu/tree/mainline/alistair/riscv-hyp-ext-v0.5.next

QEMU is built with:
	git clone --single-branch --branch mainline/alistair/riscv-hyp-ext-v0.5.next \
		https://github.com/alistair23/qemu.git
        cd qemu
        mkdir build && cd build
        ../configure --target-list=riscv64-softmmu
	make -j$(nproc) && make install

The bootloader used is the standard OpenSBI, built with the command:
	CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM=qemu/virt FW_PAYLOAD_PATH=../xen/xen/xen make

Xen/RISC-V is built with:
	XEN_TARGET_ARCH=riscv64 CROSS_COMPILE=riscv64-unknown-linux-gnu- make build

Xen may be ran with the following command:
	qemu-system-riscv64 -cpu rv64,x-h=true -M virt -m 512M -display none \
		-serial stdio -kernel \
		opensbi/build/platform/qemu/virt/firmware/fw_payload.elf

Also, shoutout to Alistair Francis (from Western Digital) for getting
the ball rolling and doing a ton of the groundwork with
Makefile/Kconfig, a ton of the RISC-V specific header files, and also
the QEMU RISC-V H extension support, and Dan Robertson (a colleague of
mine at Star Lab) for help in forward porting a number of patches that
were out-of-sync with upstream.


Thanks,
Bobby Eshleman
#45 lore raw
Quoted 2 lines · Stefano Stabellini

Any updates? I am looking forward to this :-)

At the risk of flooding the list with +1s -- I'm also very much looking forward to it!

Thanks,
Roman.

Quoted 316 lines · Bobby Eshleman
Quoted 312 lines

Hey everybody,

This is an RFC patchset for the very beginnings of adding RISC-V support to Xen. This RFC is really just to start a dialogue about supporting RISC-V and align with the Xen project and community before going further. For that reason, it is very rough and very incomplete.

My name is Bobby Eshleman, I'm a software engineer at
Star Lab / Wind River on the ARM team, mostly having worked in the Linux kernel. I've also been involved a good amount with Xen on ARM here, mostly dealing with tooling, deployment, and testing. A lot of this patchset is heavily inspired by the Xen/ARM source code (particularly the early setup up code).

Currently, this patchset really only sets up virtual memory for Xen and initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been left accordingly. It is very, very rough. Be forewarned: you are quite likely to see some ungainly code here (despite my efforts to clean it up before sending this patchset out). My intent with this RFC is to align early and gauge interest, as opposed to presenting a totally complete patchset.

Because the ARM and RISC-V use cases will likely bear resemblance, the RISC-V port should probably respect the design considerations that have been laid out and respected by Xen on ARM for dom0less, safety certification, etc... My inclination has been to initially target or prioritize dom0less (without excluding dom0full) and use the ARM dom0less implementation as a model to follow. I'd love feedback on this point and on how the Xen project might envision a RISC-V implementation.

This patchset has _some_ code for future support for 32-bit, but currently my focus is on 64-bit.

Again, this is a very, very rough and totally incomplete patchset. My goal here is just to gauge community interest, begin discussing what Xen on RISC-V may look like, receive feedback, and see if I'm heading in the right direction.

My big questions are:
Does the Xen project have interest in RISC-V? What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Alistair Francis (20):
HACK: OE Build changes
HACK: Makefile: Don't build Xen tools
riscv: makefiles and Kconfig
riscv: Add riscv to tools/libxc header files
riscv: Add asm-offsets.c
riscv: Add delay.c
riscv: Add domain.c
riscv: Add domctl.c
riscv: Add guestcopy.c
riscv: Add time.c
riscv: Add smp.c
riscv: Add shutdown.c
riscv: Add traps.c
riscv: Add irq.c
riscv: Add vm_event.c
riscv: Add p2m.c
riscv: Add the lib directory
riscv: Add smpboot.c
riscv: Add percpu.c
riscv: Add sysctl.c

Bobby Eshleman (3):
riscv: header files
riscv: early setup code
riscv: Add iommu.c

 Makefile                                 |  13 +-
 config/StdGNU.mk                         |  12 +-
 config/riscv64.mk                        |   7 +
 tools/configure                          |  32 +-
 tools/firmware/Makefile                  |  12 +-
 tools/libxc/include/xenctrl.h            |   7 +
 tools/libxc/xc_core.h                    |   2 +
 tools/libxc/xc_core_riscv.h              |  57 ++
 xen/Makefile                             |   2 +-
 xen/Rules.mk                             |   2 +-
 xen/arch/Kconfig                         |   1 +
 xen/arch/riscv/Kconfig                   |  36 +
 xen/arch/riscv/Makefile                  |  62 ++
 xen/arch/riscv/Rules.mk                  |  55 ++
 xen/arch/riscv/asm-offsets.c             |  38 +
 xen/arch/riscv/configs/riscv32_defconfig |   0
 xen/arch/riscv/configs/riscv64_defconfig |   0
 xen/arch/riscv/delay.c                   | 114 +++
 xen/arch/riscv/domain.c                  | 273 +++++++
 xen/arch/riscv/domctl.c                  |  53 ++
 xen/arch/riscv/guestcopy.c               | 158 ++++
 xen/arch/riscv/head.S                    | 180 +++++
 xen/arch/riscv/irq.c                     | 107 +++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++
 xen/arch/riscv/mm.c                      | 925 +++++++++++++++++++++++
 xen/arch/riscv/p2m.c                     | 261 +++++++
 xen/arch/riscv/percpu.c                  |  84 ++
 xen/arch/riscv/platforms/Kconfig         |  31 +
 xen/arch/riscv/setup.c                   | 122 +++
 xen/arch/riscv/shutdown.c                |  24 +
 xen/arch/riscv/smp.c                     |  41 +
 xen/arch/riscv/smpboot.c                 | 114 +++
 xen/arch/riscv/sysctl.c                  |  31 +
 xen/arch/riscv/time.c                    |  74 ++
 xen/arch/riscv/traps.c                   |  56 ++
 xen/arch/riscv/vm_event.c                |  42 +
 xen/arch/riscv/xen.lds.S                 | 262 +++++++
 xen/drivers/passthrough/Makefile         |   1 +
 xen/drivers/passthrough/riscv/Makefile   |   1 +
 xen/drivers/passthrough/riscv/iommu.c    |  74 ++
 xen/include/asm-riscv/altp2m.h           |  39 +
 xen/include/asm-riscv/asm.h              |  76 ++
 xen/include/asm-riscv/atomic.h           | 249 ++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++
 xen/include/asm-riscv/bug.h              |  59 ++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 +
 xen/include/asm-riscv/cmpxchg.h          | 382 ++++++++++
 xen/include/asm-riscv/config.h           | 203 +++++
 xen/include/asm-riscv/csr.h              | 117 +++
 xen/include/asm-riscv/current.h          |  50 ++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  28 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 +
 xen/include/asm-riscv/domain.h           |  85 +++
 xen/include/asm-riscv/event.h            |  42 +
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  56 ++
 xen/include/asm-riscv/grant_table.h      |  93 +++
 xen/include/asm-riscv/guest_access.h     | 164 ++++
 xen/include/asm-riscv/guest_atomics.h    |  62 ++
 xen/include/asm-riscv/hardirq.h          |  27 +
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +
 xen/include/asm-riscv/io.h               | 283 +++++++
 xen/include/asm-riscv/iocap.h            |  16 +
 xen/include/asm-riscv/iommu.h            |  49 ++
 xen/include/asm-riscv/irq.h              |  58 ++
 xen/include/asm-riscv/mem_access.h       |  35 +
 xen/include/asm-riscv/mm.h               | 308 ++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++
 xen/include/asm-riscv/nospec.h           |  25 +
 xen/include/asm-riscv/numa.h             |  41 +
 xen/include/asm-riscv/p2m.h              | 410 ++++++++++
 xen/include/asm-riscv/page.h             | 327 ++++++++
 xen/include/asm-riscv/paging.h           |  16 +
 xen/include/asm-riscv/pci.h              |  31 +
 xen/include/asm-riscv/percpu.h           |  34 +
 xen/include/asm-riscv/pgtable-bits.h     |  53 ++
 xen/include/asm-riscv/processor.h        |  60 ++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  42 +
 xen/include/asm-riscv/riscv_encoding.h   | 682 +++++++++++++++++
 xen/include/asm-riscv/setup.h            |  16 +
 xen/include/asm-riscv/smp.h              |  50 ++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  13 +
 xen/include/asm-riscv/string.h           |  28 +
 xen/include/asm-riscv/sysregs.h          |  14 +
 xen/include/asm-riscv/system.h           |  96 +++
 xen/include/asm-riscv/time.h             |  60 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  73 ++
 xen/include/asm-riscv/vm_event.h         |  61 ++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 181 +++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 103 files changed, 9064 insertions(+), 42 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 tools/libxc/xc_core_riscv.h
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/asm-offsets.c
 create mode 100644 xen/arch/riscv/configs/riscv32_defconfig
 create mode 100644 xen/arch/riscv/configs/riscv64_defconfig
 create mode 100644 xen/arch/riscv/delay.c
 create mode 100644 xen/arch/riscv/domain.c
 create mode 100644 xen/arch/riscv/domctl.c
 create mode 100644 xen/arch/riscv/guestcopy.c
 create mode 100644 xen/arch/riscv/head.S
 create mode 100644 xen/arch/riscv/irq.c
 create mode 100644 xen/arch/riscv/lib/Makefile
 create mode 100644 xen/arch/riscv/lib/find_next_bit.c
 create mode 100644 xen/arch/riscv/mm.c
 create mode 100644 xen/arch/riscv/p2m.c
 create mode 100644 xen/arch/riscv/percpu.c
 create mode 100644 xen/arch/riscv/platforms/Kconfig
 create mode 100644 xen/arch/riscv/setup.c
 create mode 100644 xen/arch/riscv/shutdown.c
 create mode 100644 xen/arch/riscv/smp.c
 create mode 100644 xen/arch/riscv/smpboot.c
 create mode 100644 xen/arch/riscv/sysctl.c
 create mode 100644 xen/arch/riscv/time.c
 create mode 100644 xen/arch/riscv/traps.c
 create mode 100644 xen/arch/riscv/vm_event.c
 create mode 100644 xen/arch/riscv/xen.lds.S
 create mode 100644 xen/drivers/passthrough/riscv/Makefile
 create mode 100644 xen/drivers/passthrough/riscv/iommu.c
 create mode 100644 xen/include/asm-riscv/altp2m.h
 create mode 100644 xen/include/asm-riscv/asm.h
 create mode 100644 xen/include/asm-riscv/atomic.h
 create mode 100644 xen/include/asm-riscv/bitops.h
 create mode 100644 xen/include/asm-riscv/bug.h
 create mode 100644 xen/include/asm-riscv/byteorder.h
 create mode 100644 xen/include/asm-riscv/cache.h
 create mode 100644 xen/include/asm-riscv/cmpxchg.h
 create mode 100644 xen/include/asm-riscv/config.h
 create mode 100644 xen/include/asm-riscv/csr.h
 create mode 100644 xen/include/asm-riscv/current.h
 create mode 100644 xen/include/asm-riscv/debugger.h
 create mode 100644 xen/include/asm-riscv/delay.h
 create mode 100644 xen/include/asm-riscv/desc.h
 create mode 100644 xen/include/asm-riscv/device.h
 create mode 100644 xen/include/asm-riscv/div64.h
 create mode 100644 xen/include/asm-riscv/domain.h
 create mode 100644 xen/include/asm-riscv/event.h
 create mode 100644 xen/include/asm-riscv/fence.h
 create mode 100644 xen/include/asm-riscv/flushtlb.h
 create mode 100644 xen/include/asm-riscv/grant_table.h
 create mode 100644 xen/include/asm-riscv/guest_access.h
 create mode 100644 xen/include/asm-riscv/guest_atomics.h
 create mode 100644 xen/include/asm-riscv/hardirq.h
 create mode 100644 xen/include/asm-riscv/hypercall.h
 create mode 100644 xen/include/asm-riscv/init.h
 create mode 100644 xen/include/asm-riscv/io.h
 create mode 100644 xen/include/asm-riscv/iocap.h
 create mode 100644 xen/include/asm-riscv/iommu.h
 create mode 100644 xen/include/asm-riscv/irq.h
 create mode 100644 xen/include/asm-riscv/mem_access.h
 create mode 100644 xen/include/asm-riscv/mm.h
 create mode 100644 xen/include/asm-riscv/monitor.h
 create mode 100644 xen/include/asm-riscv/nospec.h
 create mode 100644 xen/include/asm-riscv/numa.h
 create mode 100644 xen/include/asm-riscv/p2m.h
 create mode 100644 xen/include/asm-riscv/page.h
 create mode 100644 xen/include/asm-riscv/paging.h
 create mode 100644 xen/include/asm-riscv/pci.h
 create mode 100644 xen/include/asm-riscv/percpu.h
 create mode 100644 xen/include/asm-riscv/pgtable-bits.h
 create mode 100644 xen/include/asm-riscv/processor.h
 create mode 100644 xen/include/asm-riscv/random.h
 create mode 100644 xen/include/asm-riscv/regs.h
 create mode 100644 xen/include/asm-riscv/riscv_encoding.h
 create mode 100644 xen/include/asm-riscv/setup.h
 create mode 100644 xen/include/asm-riscv/smp.h
 create mode 100644 xen/include/asm-riscv/softirq.h
 create mode 100644 xen/include/asm-riscv/spinlock.h
 create mode 100644 xen/include/asm-riscv/string.h
 create mode 100644 xen/include/asm-riscv/sysregs.h
 create mode 100644 xen/include/asm-riscv/system.h
 create mode 100644 xen/include/asm-riscv/time.h
 create mode 100644 xen/include/asm-riscv/trace.h
 create mode 100644 xen/include/asm-riscv/types.h
 create mode 100644 xen/include/asm-riscv/vm_event.h
 create mode 100644 xen/include/asm-riscv/xenoprof.h
 create mode 100644 xen/include/public/arch-riscv.h
 create mode 100644 xen/include/public/arch-riscv/hvm/save.h

--
2.25.0

The source code can be found on github:
https://github.com/beshleman/xen/tree/port-to-risc-v

The patchset only targets the QEMU virt board and it is tested on Alistair Francis's patchset for QEMU with RISC-V hypervisor extensions v0.5, found here:
https://github.com/alistair23/qemu/tree/mainline/alistair/riscv-hyp-ext-v0.5.next

QEMU is built with:

      git clone --single-branch --branch mainline/alistair/riscv-hyp-ext-v0.5.next \
              https://github.com/alistair23/qemu.git
        cd qemu
        mkdir build && cd build
        ../configure --target-list=riscv64-softmmu
      make -j$(nproc) && make install

The bootloader used is the standard OpenSBI, built with the command:
CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM=qemu/virt FW_PAYLOAD_PATH=../xen/xen/xen make

Xen/RISC-V is built with:
XEN_TARGET_ARCH=riscv64 CROSS_COMPILE=riscv64-unknown-linux-gnu- make build

Xen may be ran with the following command:

      qemu-system-riscv64 -cpu rv64,x-h=true -M virt -m 512M -display none \
              -serial stdio -kernel \
              opensbi/build/platform/qemu/virt/firmware/fw_payload.elf

Also, shoutout to Alistair Francis (from Western Digital) for getting the ball rolling and doing a ton of the groundwork with Makefile/Kconfig, a ton of the RISC-V specific header files, and also the QEMU RISC-V H extension support, and Dan Robertson (a colleague of mine at Star Lab) for help in forward porting a number of patches that were out-of-sync with upstream.

Thanks,
Bobby Eshleman

#46 lore raw
In reply to Stefano Stabellini
Quoted 1 line · Stefano Stabellini

Any updates? I am looking forward to this :-)

FYI, I would like to talk more about RISC-V Xen at the Xen Virtual summit. I'll put it forward as a BoF subject.

I haven't worked on this, although the RISC-V Hypervisor spec is progressing towards ratification.

Alistair

Quoted 349 lines · Bobby Eshleman
Quoted 346 lines

Hey everybody,

This is an RFC patchset for the very beginnings of adding RISC-V support
to Xen. This RFC is really just to start a dialogue about supporting
RISC-V and align with the Xen project and community before going further. For that reason, it is very rough and very incomplete.

My name is Bobby Eshleman, I'm a software engineer at Star Lab / Wind River on the ARM team, mostly having worked in the Linux
kernel. I've also been involved a good amount with Xen on ARM here,
mostly dealing with tooling, deployment, and testing. A lot of this
patchset is heavily inspired by the Xen/ARM source code (particularly
the early setup up code).

Currently, this patchset really only sets up virtual memory for Xen and
initializes UART to enable print output. None of RISC-V's virtualization support has been implemented yet, although that is the
next road to start going down. Many functions only contain dummy implementations. Many shortcuts have been taken and TODO's have been
left accordingly. It is very, very rough. Be forewarned: you are quite
likely to see some ungainly code here (despite my efforts to clean it up
before sending this patchset out). My intent with this RFC is to align
early and gauge interest, as opposed to presenting a totally complete
patchset.

Because the ARM and RISC-V use cases will likely bear resemblance, the
RISC-V port should probably respect the design considerations that have
been laid out and respected by Xen on ARM for dom0less, safety certification, etc... My inclination has been to initially target or
prioritize dom0less (without excluding dom0full) and use the ARM dom0less implementation as a model to follow. I'd love feedback on this
point and on how the Xen project might envision a RISC-V implementation.

This patchset has _some_ code for future support for 32-bit, but currently my focus is on 64-bit.

Again, this is a very, very rough and totally incomplete patchset. My
goal here is just to gauge community interest, begin discussing what Xen
on RISC-V may look like, receive feedback, and see if I'm heading in the
right direction.

My big questions are:
Does the Xen project have interest in RISC-V? What can be done to make the RISC-V port as upstreamable as
possible?
Any major pitfalls?

It would be great to hear all of your feedback.

Alistair Francis (20):
HACK: OE Build changes
HACK: Makefile: Don't build Xen tools
riscv: makefiles and Kconfig
riscv: Add riscv to tools/libxc header files
riscv: Add asm-offsets.c
riscv: Add delay.c
riscv: Add domain.c
riscv: Add domctl.c
riscv: Add guestcopy.c
riscv: Add time.c
riscv: Add smp.c
riscv: Add shutdown.c
riscv: Add traps.c
riscv: Add irq.c
riscv: Add vm_event.c
riscv: Add p2m.c
riscv: Add the lib directory
riscv: Add smpboot.c
riscv: Add percpu.c
riscv: Add sysctl.c

Bobby Eshleman (3):
riscv: header files
riscv: early setup code
riscv: Add iommu.c

 Makefile                                 |  13 +-
 config/StdGNU.mk                         |  12 +-
 config/riscv64.mk                        |   7 +
 tools/configure                          |  32 +-
 tools/firmware/Makefile                  |  12 +-
 tools/libxc/include/xenctrl.h            |   7 +
 tools/libxc/xc_core.h                    |   2 +
 tools/libxc/xc_core_riscv.h              |  57 ++
 xen/Makefile                             |   2 +-
 xen/Rules.mk                             |   2 +-
 xen/arch/Kconfig                         |   1 +
 xen/arch/riscv/Kconfig                   |  36 +
 xen/arch/riscv/Makefile                  |  62 ++
 xen/arch/riscv/Rules.mk                  |  55 ++
 xen/arch/riscv/asm-offsets.c             |  38 +
 xen/arch/riscv/configs/riscv32_defconfig |   0
 xen/arch/riscv/configs/riscv64_defconfig |   0
 xen/arch/riscv/delay.c                   | 114 +++
 xen/arch/riscv/domain.c                  | 273 +++++++
 xen/arch/riscv/domctl.c                  |  53 ++
 xen/arch/riscv/guestcopy.c               | 158 ++++
 xen/arch/riscv/head.S                    | 180 +++++
 xen/arch/riscv/irq.c                     | 107 +++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++
 xen/arch/riscv/mm.c                      | 925
+++++++++++++++++++++++
 xen/arch/riscv/p2m.c                     | 261 +++++++
 xen/arch/riscv/percpu.c                  |  84 ++
 xen/arch/riscv/platforms/Kconfig         |  31 +
 xen/arch/riscv/setup.c                   | 122 +++
 xen/arch/riscv/shutdown.c                |  24 +
 xen/arch/riscv/smp.c                     |  41 +
 xen/arch/riscv/smpboot.c                 | 114 +++
 xen/arch/riscv/sysctl.c                  |  31 +
 xen/arch/riscv/time.c                    |  74 ++
 xen/arch/riscv/traps.c                   |  56 ++
 xen/arch/riscv/vm_event.c                |  42 +
 xen/arch/riscv/xen.lds.S                 | 262 +++++++
 xen/drivers/passthrough/Makefile         |   1 +
 xen/drivers/passthrough/riscv/Makefile   |   1 +
 xen/drivers/passthrough/riscv/iommu.c    |  74 ++
 xen/include/asm-riscv/altp2m.h           |  39 +
 xen/include/asm-riscv/asm.h              |  76 ++
 xen/include/asm-riscv/atomic.h           | 249 ++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++
 xen/include/asm-riscv/bug.h              |  59 ++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 +
 xen/include/asm-riscv/cmpxchg.h          | 382 ++++++++++
 xen/include/asm-riscv/config.h           | 203 +++++
 xen/include/asm-riscv/csr.h              | 117 +++
 xen/include/asm-riscv/current.h          |  50 ++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  28 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 +
 xen/include/asm-riscv/domain.h           |  85 +++
 xen/include/asm-riscv/event.h            |  42 +
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  56 ++
 xen/include/asm-riscv/grant_table.h      |  93 +++
 xen/include/asm-riscv/guest_access.h     | 164 ++++
 xen/include/asm-riscv/guest_atomics.h    |  62 ++
 xen/include/asm-riscv/hardirq.h          |  27 +
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +
 xen/include/asm-riscv/io.h               | 283 +++++++
 xen/include/asm-riscv/iocap.h            |  16 +
 xen/include/asm-riscv/iommu.h            |  49 ++
 xen/include/asm-riscv/irq.h              |  58 ++
 xen/include/asm-riscv/mem_access.h       |  35 +
 xen/include/asm-riscv/mm.h               | 308 ++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++
 xen/include/asm-riscv/nospec.h           |  25 +
 xen/include/asm-riscv/numa.h             |  41 +
 xen/include/asm-riscv/p2m.h              | 410 ++++++++++
 xen/include/asm-riscv/page.h             | 327 ++++++++
 xen/include/asm-riscv/paging.h           |  16 +
 xen/include/asm-riscv/pci.h              |  31 +
 xen/include/asm-riscv/percpu.h           |  34 +
 xen/include/asm-riscv/pgtable-bits.h     |  53 ++
 xen/include/asm-riscv/processor.h        |  60 ++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  42 +
 xen/include/asm-riscv/riscv_encoding.h   | 682 +++++++++++++++++
 xen/include/asm-riscv/setup.h            |  16 +
 xen/include/asm-riscv/smp.h              |  50 ++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  13 +
 xen/include/asm-riscv/string.h           |  28 +
 xen/include/asm-riscv/sysregs.h          |  14 +
 xen/include/asm-riscv/system.h           |  96 +++
 xen/include/asm-riscv/time.h             |  60 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  73 ++
 xen/include/asm-riscv/vm_event.h         |  61 ++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 181 +++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 103 files changed, 9064 insertions(+), 42 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 tools/libxc/xc_core_riscv.h
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/asm-offsets.c
 create mode 100644 xen/arch/riscv/configs/riscv32_defconfig
 create mode 100644 xen/arch/riscv/configs/riscv64_defconfig
 create mode 100644 xen/arch/riscv/delay.c
 create mode 100644 xen/arch/riscv/domain.c
 create mode 100644 xen/arch/riscv/domctl.c
 create mode 100644 xen/arch/riscv/guestcopy.c
 create mode 100644 xen/arch/riscv/head.S
 create mode 100644 xen/arch/riscv/irq.c
 create mode 100644 xen/arch/riscv/lib/Makefile
 create mode 100644 xen/arch/riscv/lib/find_next_bit.c
 create mode 100644 xen/arch/riscv/mm.c
 create mode 100644 xen/arch/riscv/p2m.c
 create mode 100644 xen/arch/riscv/percpu.c
 create mode 100644 xen/arch/riscv/platforms/Kconfig
 create mode 100644 xen/arch/riscv/setup.c
 create mode 100644 xen/arch/riscv/shutdown.c
 create mode 100644 xen/arch/riscv/smp.c
 create mode 100644 xen/arch/riscv/smpboot.c
 create mode 100644 xen/arch/riscv/sysctl.c
 create mode 100644 xen/arch/riscv/time.c
 create mode 100644 xen/arch/riscv/traps.c
 create mode 100644 xen/arch/riscv/vm_event.c
 create mode 100644 xen/arch/riscv/xen.lds.S
 create mode 100644 xen/drivers/passthrough/riscv/Makefile
 create mode 100644 xen/drivers/passthrough/riscv/iommu.c
 create mode 100644 xen/include/asm-riscv/altp2m.h
 create mode 100644 xen/include/asm-riscv/asm.h
 create mode 100644 xen/include/asm-riscv/atomic.h
 create mode 100644 xen/include/asm-riscv/bitops.h
 create mode 100644 xen/include/asm-riscv/bug.h
 create mode 100644 xen/include/asm-riscv/byteorder.h
 create mode 100644 xen/include/asm-riscv/cache.h
 create mode 100644 xen/include/asm-riscv/cmpxchg.h
 create mode 100644 xen/include/asm-riscv/config.h
 create mode 100644 xen/include/asm-riscv/csr.h
 create mode 100644 xen/include/asm-riscv/current.h
 create mode 100644 xen/include/asm-riscv/debugger.h
 create mode 100644 xen/include/asm-riscv/delay.h
 create mode 100644 xen/include/asm-riscv/desc.h
 create mode 100644 xen/include/asm-riscv/device.h
 create mode 100644 xen/include/asm-riscv/div64.h
 create mode 100644 xen/include/asm-riscv/domain.h
 create mode 100644 xen/include/asm-riscv/event.h
 create mode 100644 xen/include/asm-riscv/fence.h
 create mode 100644 xen/include/asm-riscv/flushtlb.h
 create mode 100644 xen/include/asm-riscv/grant_table.h
 create mode 100644 xen/include/asm-riscv/guest_access.h
 create mode 100644 xen/include/asm-riscv/guest_atomics.h
 create mode 100644 xen/include/asm-riscv/hardirq.h
 create mode 100644 xen/include/asm-riscv/hypercall.h
 create mode 100644 xen/include/asm-riscv/init.h
 create mode 100644 xen/include/asm-riscv/io.h
 create mode 100644 xen/include/asm-riscv/iocap.h
 create mode 100644 xen/include/asm-riscv/iommu.h
 create mode 100644 xen/include/asm-riscv/irq.h
 create mode 100644 xen/include/asm-riscv/mem_access.h
 create mode 100644 xen/include/asm-riscv/mm.h
 create mode 100644 xen/include/asm-riscv/monitor.h
 create mode 100644 xen/include/asm-riscv/nospec.h
 create mode 100644 xen/include/asm-riscv/numa.h
 create mode 100644 xen/include/asm-riscv/p2m.h
 create mode 100644 xen/include/asm-riscv/page.h
 create mode 100644 xen/include/asm-riscv/paging.h
 create mode 100644 xen/include/asm-riscv/pci.h
 create mode 100644 xen/include/asm-riscv/percpu.h
 create mode 100644 xen/include/asm-riscv/pgtable-bits.h
 create mode 100644 xen/include/asm-riscv/processor.h
 create mode 100644 xen/include/asm-riscv/random.h
 create mode 100644 xen/include/asm-riscv/regs.h
 create mode 100644 xen/include/asm-riscv/riscv_encoding.h
 create mode 100644 xen/include/asm-riscv/setup.h
 create mode 100644 xen/include/asm-riscv/smp.h
 create mode 100644 xen/include/asm-riscv/softirq.h
 create mode 100644 xen/include/asm-riscv/spinlock.h
 create mode 100644 xen/include/asm-riscv/string.h
 create mode 100644 xen/include/asm-riscv/sysregs.h
 create mode 100644 xen/include/asm-riscv/system.h
 create mode 100644 xen/include/asm-riscv/time.h
 create mode 100644 xen/include/asm-riscv/trace.h
 create mode 100644 xen/include/asm-riscv/types.h
 create mode 100644 xen/include/asm-riscv/vm_event.h
 create mode 100644 xen/include/asm-riscv/xenoprof.h
 create mode 100644 xen/include/public/arch-riscv.h
 create mode 100644 xen/include/public/arch-riscv/hvm/save.h
Signature · 51 lines
2.25.0

The source code can be found on github:
	https://github.com/beshleman/xen/tree/port-to-risc-v

The patchset only targets the QEMU virt board and it is tested on
Alistair Francis's patchset for QEMU with RISC-V hypervisor
extensions
v0.5, found here:
	
https://github.com/alistair23/qemu/tree/mainline/alistair/riscv-hyp-ext-v0.5.next

QEMU is built with:
	git clone --single-branch --branch mainline/alistair/riscv-hyp-
ext-v0.5.next \
		https://github.com/alistair23/qemu.git
        cd qemu
        mkdir build && cd build
        ../configure --target-list=riscv64-softmmu
	make -j$(nproc) && make install

The bootloader used is the standard OpenSBI, built with the
command:
	CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM=qemu/virt
FW_PAYLOAD_PATH=../xen/xen/xen make

Xen/RISC-V is built with:
	XEN_TARGET_ARCH=riscv64 CROSS_COMPILE=riscv64-unknown-linux-
gnu- make build

Xen may be ran with the following command:
	qemu-system-riscv64 -cpu rv64,x-h=true -M virt -m 512M -display
none \
		-serial stdio -kernel \
		opensbi/build/platform/qemu/virt/firmware/fw_payload.el
f

Also, shoutout to Alistair Francis (from Western Digital) for
getting
the ball rolling and doing a ton of the groundwork with
Makefile/Kconfig, a ton of the RISC-V specific header files, and
also
the QEMU RISC-V H extension support, and Dan Robertson (a colleague
of
mine at Star Lab) for help in forward porting a number of patches
that
were out-of-sync with upstream.


Thanks,
Bobby Eshleman
#47 lore raw
Quoted 3 lines · Alistair Francis
Quoted 1 line · Stefano Stabellini

Any updates? I am looking forward to this :-)

It has been on a slow burn since I became a new dad (shortly after the RFC). I've gradually regained free time, and so I've been able to change that slow burn to a moderate burn in the last couple weeks.

Most of my progress has been around build environment improvements. I've done some work stripping it down to the bare minimum required to build a new arch and rooting the commit history from there, and some work with incorporating it into the gitlab CI, containerizing the build and QEMU run, etc...

As far as hypervisor status: I'm just about done with incorporating the boot module FDT parsing code, extracting kernel info and ram regions (taken/generalized from arch/arm), plus implementing the arch-specific pieces of domain_create().

On the verge of being able to dive into a guest kernel and see what breaks first :)

I'm expected to commit an extra day or two per week in the next month or so at Vates, so this will considerably bump up my cadence in comparison to the last few months.

Quoted 8 lines

FYI, I would like to talk more about RISC-V Xen at the Xen Virtual summit. I'll put it forward as a BoF subject.

I haven't worked on this, although the RISC-V Hypervisor spec is progressing towards ratification.

Alistair

That would be great :)

-Bobby

#48 lore raw
Quoted 19 lines · Bobby Eshleman
Quoted 3 lines · Alistair Francis
Quoted 1 line · Stefano Stabellini

Any updates? I am looking forward to this :-)

It has been on a slow burn since I became a new dad (shortly after the RFC). I've gradually regained free time, and so I've been able to change that slow burn to a moderate burn in the last couple weeks.

Most of my progress has been around build environment improvements. I've done some work stripping it down to the bare minimum required to build a new arch and rooting the commit history from there, and some work with incorporating it into the gitlab CI, containerizing the build and QEMU run, etc...

As far as hypervisor status: I'm just about done with incorporating the boot module FDT parsing code, extracting kernel info and ram regions (taken/generalized from arch/arm), plus implementing the arch-specific pieces of domain_create().

Quoted 6 lines

On the verge of being able to dive into a guest kernel and see what breaks first :)

I'm expected to commit an extra day or two per week in the next month or so at Vates, so this will considerably bump up my cadence in comparison to the last few months.

Great to hear and congratulations! I'll stay tuned. Next time I'll try to rebuild and run your series on QEMU, I might ask you for some help with the setup.

Quoted 10 lines
Quoted 8 lines

FYI, I would like to talk more about RISC-V Xen at the Xen Virtual summit. I'll put it forward as a BoF subject.

I haven't worked on this, although the RISC-V Hypervisor spec is progressing towards ratification.

Alistair

That would be great :)

Indeed!

#49 lore raw
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Bobby Eshleman
Quoted 3 lines · Alistair Francis
Quoted 1 line · Stefano Stabellini

Any updates? I am looking forward to this :-)

It has been on a slow burn since I became a new dad (shortly after the RFC). I've gradually regained free time, and so I've been able to change that slow burn to a moderate burn in the last couple weeks.

Most of my progress has been around build environment improvements. I've done some work stripping it down to the bare minimum required to build a new arch and rooting the commit history from there, and some work with incorporating it into the gitlab CI, containerizing the build and QEMU run, etc...

As far as hypervisor status: I'm just about done with incorporating the boot module FDT parsing code, extracting kernel info and ram regions (taken/generalized from arch/arm), plus implementing the arch-specific pieces of domain_create().

On the verge of being able to dive into a guest kernel and see what breaks first :)

Quoted 8 lines
Quoted 3 lines

I'm expected to commit an extra day or two per week in the next month or so at Vates, so this will considerably bump up my cadence in comparison to the last few months.

Great to hear and congratulations! I'll stay tuned. Next time I'll try to rebuild and run your series on QEMU, I might ask you for some help with the setup.

Thanks! And absolutely, feel free :)