Skip to contentSkip to conversation

Basic early_printk and smoke test implementation

PATCH Superseded Oleksii Kurochko 6 participants 26 messages Jan 9, 2023 – Jan 10, 2023 RISC-V

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v2 cover Basic early_printk and smoke test implementation

The patch series introduces the following:
- the minimal set of headers and changes inside them.
- SBI (RISC-V Supervisor Binary Interface) things necessary for basic early_printk implementation.
- things needed to set up the stack.
- early_printk() function to print only strings.
- RISC-V smoke test which checks if "Hello from C env" message is present in serial.tmp

---
Changes in V2:
- update commit patches commit messages according to the mailing list comments
- Remove unneeded types in <asm/types.h>
- Introduce definition of STACK_SIZE
- order the files alphabetically in Makefile
- Add license to early_printk.c
- Add RISCV_32 dependecy to config EARLY_PRINTK in Kconfig.debug
- Move dockerfile changes to separate config and sent them as separate patch to mailing list.
- Update test.yaml to wire up smoke test
---

Oleksii Kurochko (8):
xen/riscv: introduce dummy asm/init.h
xen/riscv: introduce asm/types.h header file xen/riscv: introduce stack stuff
xen/riscv: introduce sbi call to putchar to console xen/include: include <asm/types.h> in <xen/early_printk.h> xen/riscv: introduce early_printk basic stuff xen/riscv: print hello message from C env
automation: add RISC-V smoke test

 automation/gitlab-ci/test.yaml            | 20 +++++++++++
 automation/scripts/qemu-smoke-riscv64.sh  | 20 +++++++++++
 xen/arch/riscv/Kconfig.debug              |  7 ++++
 xen/arch/riscv/Makefile                   |  3 ++
 xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++
 xen/arch/riscv/include/asm/config.h       |  2 ++
 xen/arch/riscv/include/asm/early_printk.h | 12 +++++++
 xen/arch/riscv/include/asm/init.h         | 12 +++++++
 xen/arch/riscv/include/asm/sbi.h          | 34 ++++++++++++++++++
 xen/arch/riscv/include/asm/types.h        | 22 ++++++++++++
 xen/arch/riscv/riscv64/head.S             |  6 +++-
 xen/arch/riscv/sbi.c                      | 44 +++++++++++++++++++++++
 xen/arch/riscv/setup.c                    | 18 ++++++++++
 xen/include/xen/early_printk.h            |  2 ++
 14 files changed, 234 insertions(+), 1 deletion(-)
 create mode 100755 automation/scripts/qemu-smoke-riscv64.sh
 create mode 100644 xen/arch/riscv/early_printk.c
 create mode 100644 xen/arch/riscv/include/asm/early_printk.h
 create mode 100644 xen/arch/riscv/include/asm/init.h
 create mode 100644 xen/arch/riscv/include/asm/sbi.h
 create mode 100644 xen/arch/riscv/include/asm/types.h
 create mode 100644 xen/arch/riscv/sbi.c
 create mode 100644 xen/arch/riscv/setup.c
Signature · 1 line
2.38.1
#1 lore raw

PATCH v2 1/8 xen/riscv: introduce dummy asm/init.h

The following patches require <xen/init.h> which includes <asm/init.h>

---
Changes in V2:
- Add explanation comment to the comment message

---
 xen/arch/riscv/include/asm/init.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 xen/arch/riscv/include/asm/init.h
xen/arch/riscv/include/asm/init.h new file +12 -0
new file mode 100644
index 0000000000..237ec25e4e
@@ -0,0 +1,12 @@
+#ifndef _XEN_ASM_INIT_H
+#define _XEN_ASM_INIT_H
+
+#endif /* _XEN_ASM_INIT_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.38.1
#2 lore raw

PATCH v2 2/8 xen/riscv: introduce asm/types.h header file

In reply to Oleksii Kurochko

---
Changes in V2:
- Remove unneeded now types from <asm/types.h>

---
 xen/arch/riscv/include/asm/types.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 xen/arch/riscv/include/asm/types.h
xen/arch/riscv/include/asm/types.h new file +22 -0
new file mode 100644
index 0000000000..fbe352ef20
@@ -0,0 +1,22 @@
+#ifndef __RISCV_TYPES_H__
+#define __RISCV_TYPES_H__
+
+#ifndef __ASSEMBLY__
+
+#if defined(__SIZE_TYPE__)
+typedef __SIZE_TYPE__ size_t;
+#else
+typedef unsigned long size_t;
+#endif
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __RISCV_TYPES_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.38.1
#3 lore raw

PATCH v2 3/8 xen/riscv: introduce stack stuff

In reply to Oleksii Kurochko

The patch introduces and sets up a stack in order to go to C environment

---
Changes in V2:
- introduce STACK_SIZE define.
- use consistent padding between instruction mnemonic and operand(s)

---
 xen/arch/riscv/Makefile             | 1 +
 xen/arch/riscv/include/asm/config.h | 2 ++
 xen/arch/riscv/riscv64/head.S       | 8 +++++++-
 xen/arch/riscv/setup.c              | 6 ++++++
 4 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/riscv/setup.c
xen/arch/riscv/Makefile +1 -0
index 248f2cbb3e..5a67a3f493 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += setup.o
 
 $(TARGET): $(TARGET)-syms
 	$(OBJCOPY) -O binary -S $< $@
xen/arch/riscv/include/asm/config.h +2 -0
index 0370f865f3..bdd2237f01 100644
@@ -43,6 +43,8 @@
 
 #define SMP_CACHE_BYTES (1 << 6)
 
+#define STACK_SIZE (PAGE_SIZE)
+
 #endif /* __RISCV_CONFIG_H__ */
 /*
  * Local variables:
xen/arch/riscv/riscv64/head.S +7 -1
index 990edb70a0..c1f33a1934 100644
@@ -1,4 +1,10 @@
         .section .text.header, "ax", %progbits
 
 ENTRY(start)
-        j  start
+        la      sp, cpu0_boot_stack
+        li      t0, STACK_SIZE
+        add     sp, sp, t0
+
+_start_hang:
+        wfi
+        j       _start_hang
xen/arch/riscv/setup.c new file +6 -0
new file mode 100644
index 0000000000..41ef4912bd
@@ -0,0 +1,6 @@
+#include <xen/init.h>
+#include <xen/compile.h>
+
+/* Xen stack for bringing up the first CPU. */
+unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
+    __aligned(STACK_SIZE);
Signature · 1 line
2.38.1
#7 lore raw

PATCH v2 4/8 xen/riscv: introduce sbi call to putchar to console

In reply to Oleksii Kurochko

The patch introduce sbi_putchar() SBI call which is necessary to implement initial early_printk

---
Changes in V2:
- add an explanatory comment about sbi_console_putchar() function.
- order the files alphabetically in Makefile

---
 xen/arch/riscv/Makefile          |  1 +
 xen/arch/riscv/include/asm/sbi.h | 34 ++++++++++++++++++++++++
 xen/arch/riscv/sbi.c             | 44 ++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 xen/arch/riscv/include/asm/sbi.h
 create mode 100644 xen/arch/riscv/sbi.c
xen/arch/riscv/Makefile +1 -0
index 5a67a3f493..fd916e1004 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += sbi.o
 obj-y += setup.o
 
 $(TARGET): $(TARGET)-syms
xen/arch/riscv/include/asm/sbi.h new file +34 -0
new file mode 100644
index 0000000000..34b53f8eaf
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021 Vates SAS.
+ *
+ * Taken from xvisor, modified by Bobby Eshleman ([email protected]).
+ *
+ * Taken/modified from Xvisor project with the following copyright:
+ *
+ * Copyright (c) 2019 Western Digital Corporation or its affiliates.
+ */
+
+#ifndef __CPU_SBI_H__
+#define __CPU_SBI_H__
+
+#define SBI_EXT_0_1_CONSOLE_PUTCHAR		0x1
+
+struct sbiret {
+    long error;
+    long value;
+};
+
+struct sbiret sbi_ecall(unsigned long ext, unsigned long fid, unsigned long arg0,
+        unsigned long arg1, unsigned long arg2,
+        unsigned long arg3, unsigned long arg4,
+        unsigned long arg5);
+
+/**
+ * Writes given character to the console device.
+ *
+ * @param ch The data to be written to the console.
+ */
+void sbi_console_putchar(int ch);
+
+#endif // __CPU_SBI_H__
xen/arch/riscv/sbi.c new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.38.1
#14 lore raw

PATCH v2 5/8 xen/include: include <asm/types.h> in <xen/early_printk.h>

In reply to Oleksii Kurochko

<asm/types.h> should be included because second argument of early_puts has type 'size_t' which is defined in <asm/types.h>

---
Changes in V2:
- add Acked-by: Julien Grall <[email protected]>

---
 xen/include/xen/early_printk.h | 2 ++
 1 file changed, 2 insertions(+)
xen/include/xen/early_printk.h +2 -0
index 0f76c3a74f..abb34687da 100644
@@ -4,6 +4,8 @@
 #ifndef __XEN_EARLY_PRINTK_H__
 #define __XEN_EARLY_PRINTK_H__
 
+#include <asm/types.h>
+
 #ifdef CONFIG_EARLY_PRINTK
 void early_puts(const char *s, size_t nr);
 #else
Signature · 1 line
2.38.1
#15 lore raw

PATCH v2 6/8 xen/riscv: introduce early_printk basic stuff

In reply to Oleksii Kurochko

The patch introduces a basic stuff of early_printk functionality which will be enough to print 'hello from C environment". early_printk() function was changed in comparison with original as common isn't being built now so there is no vscnprintf.

Because printk() relies on a serial driver (like the ns16550 driver) and drivers require working virtual memory (ioremap()) there is not print functionality early in Xen boot.

This commit adds early printk implementation built on the putc SBI call.

As sbi_console_putchar() is being already planned for deprecation it is used temporary now and will be removed or reworked after real uart will be ready.

---
Changes in V2:
- add license to early_printk.c
- add signed-off-by Bobby
- add RISCV_32 to Kconfig.debug to EARLY_PRINTK config
- update commit message
- order the files alphabetically in Makefile

---
 xen/arch/riscv/Kconfig.debug              |  7 +++++
 xen/arch/riscv/Makefile                   |  1 +
 xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++++++++
 xen/arch/riscv/include/asm/early_printk.h | 12 +++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 xen/arch/riscv/early_printk.c
 create mode 100644 xen/arch/riscv/include/asm/early_printk.h
xen/arch/riscv/Kconfig.debug +7 -0
index e69de29bb2..6ba0bd1e5a 100644
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk config"
+    default DEBUG
+    depends on RISCV_64 || RISCV_32
+    help
+
+      Enables early printk debug messages
xen/arch/riscv/Makefile +1 -0
index fd916e1004..1a4f1a6015 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
 obj-$(CONFIG_RISCV_64) += riscv64/
 obj-y += sbi.o
 obj-y += setup.o
xen/arch/riscv/early_printk.c new file +33 -0
new file mode 100644
index 0000000000..88da5169ed
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <[email protected]>
+ */
+#include <asm/sbi.h>
+#include <asm/early_printk.h>
+
+/*
+ * TODO: 
+ *   sbi_console_putchar is already planned for deprication
+ *   so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+    while ( nr-- > 0 )
+    {
+        if (*s == '\n')
+            sbi_console_putchar('\r');
+        sbi_console_putchar(*s);
+        s++;
+    }
+}
+
+void early_printk(const char *str)
+{
+    while (*str)
+    {
+        early_puts(str, 1);
+        str++;
+    }
+}
xen/arch/riscv/include/asm/early_printk.h new file +12 -0
new file mode 100644
index 0000000000..05106e160d
@@ -0,0 +1,12 @@
+#ifndef __EARLY_PRINTK_H__
+#define __EARLY_PRINTK_H__
+
+#include <xen/early_printk.h>
+
+#ifdef CONFIG_EARLY_PRINTK
+void early_printk(const char *str);
+#else
+static inline void early_printk(const char *s) {};
+#endif
+
+#endif /* __EARLY_PRINTK_H__ */
Signature · 1 line
2.38.1
#21 lore raw

PATCH v2 7/8 xen/riscv: print hello message from C env

In reply to Oleksii Kurochko
---
 xen/arch/riscv/riscv64/head.S |  4 +---
 xen/arch/riscv/setup.c        | 12 ++++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)
xen/arch/riscv/riscv64/head.S +1 -3
index c1f33a1934..d444dd8aad 100644
@@ -5,6 +5,4 @@ ENTRY(start)
         li      t0, STACK_SIZE
         add     sp, sp, t0
 
-_start_hang:
-        wfi
-        j       _start_hang
+        tail    start_xen
xen/arch/riscv/setup.c +12 -0
index 41ef4912bd..586060c7e5 100644
@@ -1,6 +1,18 @@
 #include <xen/init.h>
 #include <xen/compile.h>
 
+#include <asm/early_printk.h>
+
 /* Xen stack for bringing up the first CPU. */
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
+
+void __init noreturn start_xen(void)
+{
+    early_printk("Hello from C env\n");
+
+    for ( ;; )
+        asm volatile ("wfi");
+
+    unreachable();
+}
Signature · 1 line
2.38.1
#23 lore raw

PATCH v2 8/8 automation: add RISC-V smoke test

In reply to Oleksii Kurochko

Add check if there is a message 'Hello from C env' presents in log file to be sure that stack is set and C part of early printk is working.

---
Changes in V2:
- Move changes in the dockerfile to separate patch and send it to mailing list separately:
[PATCH] automation: add qemu-system-riscv to riscv64.dockerfile
- Update test.yaml to wire up smoke test

---
 automation/gitlab-ci/test.yaml           | 20 ++++++++++++++++++++
 automation/scripts/qemu-smoke-riscv64.sh | 20 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100755 automation/scripts/qemu-smoke-riscv64.sh
automation/gitlab-ci/test.yaml +20 -0
index afd80adfe1..64f47a0ab9 100644
@@ -54,6 +54,19 @@
   tags:
     - x86_64
 
+.qemu-riscv64:
+  extends: .test-jobs-common
+  variables:
+    CONTAINER: archlinux:riscv64
+    LOGFILE: qemu-smoke-riscv64.log
+  artifacts:
+    paths:
+      - smoke.serial
+      - '*.log'
+    when: always
+  tags:
+    - x86_64
+
 .yocto-test:
   extends: .test-jobs-common
   script:
@@ -234,6 +247,13 @@ qemu-smoke-x86-64-clang-pvh:
   needs:
     - debian-unstable-clang-debug
 
+qemu-smoke-riscv64-gcc:
+  extends: .qemu-riscv64
+  script:
+    - ./automation/scripts/qemu-smoke-riscv64.sh 2>&1 | tee ${LOGFILE}
+  needs:
+    - riscv64-cross-gcc
+
 # Yocto test jobs
 yocto-qemuarm64:
   extends: .yocto-test-arm64
automation/scripts/qemu-smoke-riscv64.sh new file +20 -0
new file mode 100755
index 0000000000..e0f06360bc
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+set -ex
+
+# Run the test
+rm -f smoke.serial
+set +e
+
+timeout -k 1 2 \
+qemu-system-riscv64 \
+    -M virt \
+    -smp 1 \
+    -nographic \
+    -m 2g \
+    -kernel binaries/xen \
+    |& tee smoke.serial
+
+set -e
+(grep -q "Hello from C env" smoke.serial) || exit 1
+exit 0
Signature · 1 line
2.38.1
#8 lore raw

Re: [PATCH v2 4/8] xen/riscv: introduce sbi call to putchar to console

In reply to Oleksii Kurochko
Quoted 6 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/sbi.h new file +3 -0
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021 Vates SAS.

xen/arch/riscv/include/asm/sbi.h line 13

Quoted 10 lines
xen/arch/riscv/include/asm/sbi.h new file +10 -0
+ *
+ * Taken from xvisor, modified by Bobby Eshleman ([email protected]).
+ *
+ * Taken/modified from Xvisor project with the following copyright:
+ *
+ * Copyright (c) 2019 Western Digital Corporation or its affiliates.
+ */
+
+#ifndef __CPU_SBI_H__
+#define __CPU_SBI_H__

Didn't you mean to change this?

xen/arch/riscv/include/asm/sbi.h line 25

Quoted 11 lines
xen/arch/riscv/include/asm/sbi.h new file +11 -0
+#define SBI_EXT_0_1_CONSOLE_PUTCHAR		0x1
+
+struct sbiret {
+    long error;
+    long value;
+};
+
+struct sbiret sbi_ecall(unsigned long ext, unsigned long fid, unsigned long arg0,
+        unsigned long arg1, unsigned long arg2,
+        unsigned long arg3, unsigned long arg4,
+        unsigned long arg5);

Please get indentation right here as well as for the definition. Possible forms are

struct sbiret sbi_ecall(unsigned long ext, unsigned long fid,
unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);

or

struct sbiret sbi_ecall(unsigned long ext, unsigned long fid,
unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);

Jan

#10 lore raw

Re: [PATCH v2 4/8] xen/riscv: introduce sbi call to putchar to console

In reply to Oleksii Kurochko

Hi,

Quoted 32 lines · Oleksii Kurochko

The patch introduce sbi_putchar() SBI call which is necessary to implement initial early_printk

---
Changes in V2:
- add an explanatory comment about sbi_console_putchar() function.
- order the files alphabetically in Makefile

---
  xen/arch/riscv/Makefile          |  1 +
  xen/arch/riscv/include/asm/sbi.h | 34 ++++++++++++++++++++++++
  xen/arch/riscv/sbi.c             | 44 ++++++++++++++++++++++++++++++++
  3 files changed, 79 insertions(+)

create mode 100644 xen/arch/riscv/include/asm/sbi.h create mode 100644 xen/arch/riscv/sbi.c

xen/arch/riscv/Makefile +1 -0
index 5a67a3f493..fd916e1004 100644
@@ -1,4 +1,5 @@
  obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += sbi.o
  obj-y += setup.o
 
  $(TARGET): $(TARGET)-syms
xen/arch/riscv/include/asm/sbi.h new file +0 -0
new file mode 100644
index 0000000000..34b53f8eaf

xen/arch/riscv/include/asm/sbi.h line 5

Quoted 5 lines
xen/arch/riscv/include/asm/sbi.h new file +5 -0
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021 Vates SAS.
+ *
+ * Taken from xvisor, modified by Bobby Eshleman ([email protected]).

Hmmm... I missed this one in v1. Is this mostly code from Bobby? If so, please update the commit message accordingly.

FAOD, this comment applies for any future code you take from anyone. I will try to remember to mention it but please take pro-active action to check/mention where the code is coming from.

Cheers,

Signature · 1 line
Julien Grall
#16 lore raw

Re: [PATCH v2 6/8] xen/riscv: introduce early_printk basic stuff

In reply to Oleksii Kurochko

Hi,

Quoted 9 lines · Oleksii Kurochko

The patch introduces a basic stuff of early_printk functionality which will be enough to print 'hello from C environment". early_printk() function was changed in comparison with original as common isn't being built now so there is no vscnprintf.

Because printk() relies on a serial driver (like the ns16550 driver) and drivers require working virtual memory (ioremap()) there is not print functionality early in Xen boot.

Quoted 7 lines

This commit adds early printk implementation built on the putc SBI call.

As sbi_console_putchar() is being already planned for deprecation it is used temporary now and will be removed or reworked after real uart will be ready.

From the previous discussion, I was under the impression you agreed that the code was mainly written by Bobby. And indeed you put him as the first signed-off.

So you want to also add a From tag right at the top of the patch so when we commit it, the author tag will be Bobby.

Quoted 46 lines

---
Changes in V2:
- add license to early_printk.c
- add signed-off-by Bobby
- add RISCV_32 to Kconfig.debug to EARLY_PRINTK config
- update commit message
- order the files alphabetically in Makefile

---
  xen/arch/riscv/Kconfig.debug              |  7 +++++
  xen/arch/riscv/Makefile                   |  1 +
  xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++++++++
  xen/arch/riscv/include/asm/early_printk.h | 12 +++++++++
  4 files changed, 53 insertions(+)

create mode 100644 xen/arch/riscv/early_printk.c create mode 100644 xen/arch/riscv/include/asm/early_printk.h

xen/arch/riscv/Kconfig.debug +7 -0
index e69de29bb2..6ba0bd1e5a 100644
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk config"
+    default DEBUG
+    depends on RISCV_64 || RISCV_32
+    help
+
+      Enables early printk debug messages
xen/arch/riscv/Makefile +1 -0
index fd916e1004..1a4f1a6015 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  obj-$(CONFIG_RISCV_64) += riscv64/
  obj-y += sbi.o
  obj-y += setup.o
xen/arch/riscv/early_printk.c new file +2 -0
new file mode 100644
index 0000000000..88da5169ed
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*

xen/arch/riscv/early_printk.c line 12

Quoted 10 lines
xen/arch/riscv/early_printk.c new file +10 -0
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <[email protected]>
+ */
+#include <asm/sbi.h>
+#include <asm/early_printk.h>
+
+/*
+ * TODO:
+ *   sbi_console_putchar is already planned for deprication

s/deprication/deprecation/

Quoted 29 lines
xen/arch/riscv/early_printk.c new file +21 -0
+ *   so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+    while ( nr-- > 0 )
+    {
+        if (*s == '\n')
+            sbi_console_putchar('\r');
+        sbi_console_putchar(*s);
+        s++;
+    }
+}
+
+void early_printk(const char *str)
+{
+    while (*str)
+    {
+        early_puts(str, 1);
+        str++;
+    }
+}
xen/arch/riscv/include/asm/early_printk.h new file +2 -0
new file mode 100644
index 0000000000..05106e160d
@@ -0,0 +1,12 @@
+#ifndef __EARLY_PRINTK_H__
+#define __EARLY_PRINTK_H__

xen/arch/riscv/include/asm/early_printk.h line 12

Quoted 10 lines
xen/arch/riscv/include/asm/early_printk.h new file +10 -0
+
+#include <xen/early_printk.h>
+
+#ifdef CONFIG_EARLY_PRINTK
+void early_printk(const char *str);
+#else
+static inline void early_printk(const char *s) {};
+#endif
+
+#endif /* __EARLY_PRINTK_H__ */

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v2 3/8] xen/riscv: introduce stack stuff

In reply to Oleksii Kurochko

Hi,

Quoted 3 lines · Oleksii Kurochko

The patch introduces and sets up a stack in order to go to C environment

It looks like the comments from Andrew were missed.

Quoted 57 lines

---
Changes in V2:
- introduce STACK_SIZE define.
- use consistent padding between instruction mnemonic and operand(s)

---
  xen/arch/riscv/Makefile             | 1 +
  xen/arch/riscv/include/asm/config.h | 2 ++
  xen/arch/riscv/riscv64/head.S       | 8 +++++++-
  xen/arch/riscv/setup.c              | 6 ++++++
  4 files changed, 16 insertions(+), 1 deletion(-)

create mode 100644 xen/arch/riscv/setup.c

xen/arch/riscv/Makefile +1 -0
index 248f2cbb3e..5a67a3f493 100644
@@ -1,4 +1,5 @@
  obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += setup.o
 
  $(TARGET): $(TARGET)-syms
  	$(OBJCOPY) -O binary -S $< $@
xen/arch/riscv/include/asm/config.h +2 -0
index 0370f865f3..bdd2237f01 100644
@@ -43,6 +43,8 @@
 
  #define SMP_CACHE_BYTES (1 << 6)
 
+#define STACK_SIZE (PAGE_SIZE)
+
  #endif /* __RISCV_CONFIG_H__ */
  /*
   * Local variables:
xen/arch/riscv/riscv64/head.S +7 -1
index 990edb70a0..c1f33a1934 100644
@@ -1,4 +1,10 @@
          .section .text.header, "ax", %progbits
 
  ENTRY(start)
-        j  start
+        la      sp, cpu0_boot_stack
+        li      t0, STACK_SIZE
+        add     sp, sp, t0
+
+_start_hang:
+        wfi
+        j       _start_hang
xen/arch/riscv/setup.c new file +0 -0
new file mode 100644
index 0000000000..41ef4912bd

xen/arch/riscv/setup.c line 2

Quoted 2 lines
xen/arch/riscv/setup.c new file +2 -0
@@ -0,0 +1,6 @@
+#include <xen/init.h>
+#include <xen/compile.h>

Why do you need to include <xen/compile.h>?

In any case, please order the include alphabetically. I haven't look at the rest of the series. But please go through the series and check that generic comments (like this one) are addressed everywhere.

Cheers,

Signature · 1 line
Julien Grall
#6 lore raw

Re: [PATCH v2 3/8] xen/riscv: introduce stack stuff

In reply to Oleksii Kurochko

xen/arch/riscv/include/asm/config.h line 46

Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +1 -0
@@ -43,6 +43,8 @@
 
 #define SMP_CACHE_BYTES (1 << 6)
 
+#define STACK_SIZE (PAGE_SIZE)

Btw, nit: No need for parentheses here.

Jan

#17 lore raw

Re: [PATCH v2 6/8] xen/riscv: introduce early_printk basic stuff

In reply to Oleksii Kurochko

xen/arch/riscv/Kconfig.debug line 2

Quoted 5 lines · Oleksii Kurochko
xen/arch/riscv/Kconfig.debug +2 -0
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk config"

Nit: Stray "config" in the prompt text.

Jan

#18 lore raw

Re: [PATCH v2 6/8] xen/riscv: introduce early_printk basic stuff

In reply to Oleksii Kurochko
Quoted 10 lines · Oleksii Kurochko

The patch introduces a basic stuff of early_printk functionality which will be enough to print 'hello from C environment". early_printk() function was changed in comparison with original as common isn't being built now so there is no vscnprintf.

Because printk() relies on a serial driver (like the ns16550 driver) and drivers require working virtual memory (ioremap()) there is not print functionality early in Xen boot.

Quoted 5 lines

This commit adds early printk implementation built on the putc SBI call.

As sbi_console_putchar() is being already planned for deprecation it is used temporary now and will be removed or reworked after real uart will be ready.

There was a discussion to add a new SBI putchar replacement. It doesn't seem to be completed yet, but there might be an SBI replacement for this in the future as well.

Alistair

Quoted 101 lines

---
Changes in V2:
- add license to early_printk.c
- add signed-off-by Bobby
- add RISCV_32 to Kconfig.debug to EARLY_PRINTK config
- update commit message
- order the files alphabetically in Makefile

---
 xen/arch/riscv/Kconfig.debug              |  7 +++++
 xen/arch/riscv/Makefile                   |  1 +
 xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++++++++
 xen/arch/riscv/include/asm/early_printk.h | 12 +++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 xen/arch/riscv/early_printk.c
 create mode 100644 xen/arch/riscv/include/asm/early_printk.h
xen/arch/riscv/Kconfig.debug +7 -0
index e69de29bb2..6ba0bd1e5a 100644
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk config"
+    default DEBUG
+    depends on RISCV_64 || RISCV_32
+    help
+
+      Enables early printk debug messages
xen/arch/riscv/Makefile +1 -0
index fd916e1004..1a4f1a6015 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
 obj-$(CONFIG_RISCV_64) += riscv64/
 obj-y += sbi.o
 obj-y += setup.o
xen/arch/riscv/early_printk.c new file +33 -0
new file mode 100644
index 0000000000..88da5169ed
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <[email protected]>
+ */
+#include <asm/sbi.h>
+#include <asm/early_printk.h>
+
+/*
+ * TODO:
+ *   sbi_console_putchar is already planned for deprication
+ *   so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+    while ( nr-- > 0 )
+    {
+        if (*s == '\n')
+            sbi_console_putchar('\r');
+        sbi_console_putchar(*s);
+        s++;
+    }
+}
+
+void early_printk(const char *str)
+{
+    while (*str)
+    {
+        early_puts(str, 1);
+        str++;
+    }
+}
xen/arch/riscv/include/asm/early_printk.h new file +12 -1
new file mode 100644
index 0000000000..05106e160d
@@ -0,0 +1,12 @@
+#ifndef __EARLY_PRINTK_H__
+#define __EARLY_PRINTK_H__
+
+#include <xen/early_printk.h>
+
+#ifdef CONFIG_EARLY_PRINTK
+void early_printk(const char *str);
+#else
+static inline void early_printk(const char *s) {};
+#endif
+
+#endif /* __EARLY_PRINTK_H__ */
--

2.38.1

Reviewed-by on v2 7/8
#22 lore raw

Re: [PATCH v2 7/8] xen/riscv: print hello message from C env

In reply to Oleksii Kurochko
Quoted 2 lines · Oleksii Kurochko

Alistair

Quoted 44 lines
---
 xen/arch/riscv/riscv64/head.S |  4 +---
 xen/arch/riscv/setup.c        | 12 ++++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)
xen/arch/riscv/riscv64/head.S +1 -3
index c1f33a1934..d444dd8aad 100644
@@ -5,6 +5,4 @@ ENTRY(start)
         li      t0, STACK_SIZE
         add     sp, sp, t0
 
-_start_hang:
-        wfi
-        j       _start_hang
+        tail    start_xen
xen/arch/riscv/setup.c +12 -1
index 41ef4912bd..586060c7e5 100644
@@ -1,6 +1,18 @@
 #include <xen/init.h>
 #include <xen/compile.h>
 
+#include <asm/early_printk.h>
+
 /* Xen stack for bringing up the first CPU. */
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
+
+void __init noreturn start_xen(void)
+{
+    early_printk("Hello from C env\n");
+
+    for ( ;; )
+        asm volatile ("wfi");
+
+    unreachable();
+}
--

2.38.1

Acked-by on v2 8/8
#24 lore raw

Re: [PATCH v2 8/8] automation: add RISC-V smoke test

In reply to Oleksii Kurochko
Quoted 22 lines · Oleksii Kurochko

Add check if there is a message 'Hello from C env' presents in log file to be sure that stack is set and C part of early printk is working.

---
Changes in V2:
- Move changes in the dockerfile to separate patch and send it to mailing list separately:
[PATCH] automation: add qemu-system-riscv to riscv64.dockerfile
- Update test.yaml to wire up smoke test

---
 automation/gitlab-ci/test.yaml           | 20 ++++++++++++++++++++
 automation/scripts/qemu-smoke-riscv64.sh | 20 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100755 automation/scripts/qemu-smoke-riscv64.sh
automation/gitlab-ci/test.yaml +0 -0
index afd80adfe1..64f47a0ab9 100644

automation/gitlab-ci/test.yaml line 60

Quoted 7 lines
automation/gitlab-ci/test.yaml +4 -0
@@ -54,6 +54,19 @@
   tags:
     - x86_64
 
+.qemu-riscv64:
+  extends: .test-jobs-common
+  variables:
+    CONTAINER: archlinux:riscv64

I realize that it is committed now, but following the arm32 convention the name of the arch container (currently archlinux:riscv64) would be:

CONTAINER: archlinux:current-riscv64

I know this is not related to this patch, but I am taking the opportunity to mention it now in case we get an opportunity to fix it in the future for consistency.

Quoted 13 lines
automation/gitlab-ci/test.yaml +9 -0
+    LOGFILE: qemu-smoke-riscv64.log
+  artifacts:
+    paths:
+      - smoke.serial
+      - '*.log'
+    when: always
+  tags:
+    - x86_64
+
 .yocto-test:
   extends: .test-jobs-common
   script:

automation/gitlab-ci/test.yaml qemu-smoke-x86-64-clang-pvh: · line 255

Quoted 9 lines
automation/gitlab-ci/test.yaml +6 -0
@@ -234,6 +247,13 @@ qemu-smoke-x86-64-clang-pvh:
   needs:
     - debian-unstable-clang-debug
 
+qemu-smoke-riscv64-gcc:
+  extends: .qemu-riscv64
+  script:
+    - ./automation/scripts/qemu-smoke-riscv64.sh 2>&1 | tee ${LOGFILE}
+  needs:
+    - riscv64-cross-gcc

Similarly here the "needs" dependency should be called arch-current-gcc-riscv for consistency with arm32.

Basically we already have a crossbuild and crosstest environment up and running in gitlab-ci and it is the one for arm32. You can just base all the naming convention on that.

I realize that riscv64-cross-gcc is also already exported by build.yaml, but I am mentioning it in case we get an opportunity to fix it in the future.

Nonetheless this patch on its own is OK so

Quoted 32 lines
automation/gitlab-ci/test.yaml +0 -0
 # Yocto test jobs
 yocto-qemuarm64:
   extends: .yocto-test-arm64
automation/scripts/qemu-smoke-riscv64.sh new file +20 -0
new file mode 100755
index 0000000000..e0f06360bc
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+set -ex
+
+# Run the test
+rm -f smoke.serial
+set +e
+
+timeout -k 1 2 \
+qemu-system-riscv64 \
+    -M virt \
+    -smp 1 \
+    -nographic \
+    -m 2g \
+    -kernel binaries/xen \
+    |& tee smoke.serial
+
+set -e
+(grep -q "Hello from C env" smoke.serial) || exit 1
+exit 0
Signature · 1 line
2.38.1
#19 lore raw

Re: [PATCH v2 6/8] xen/riscv: introduce early_printk basic stuff

In reply to Alistair Francis
Quoted 18 lines · Alistair Francis
Quoted 10 lines · Oleksii Kurochko

The patch introduces a basic stuff of early_printk functionality which will be enough to print 'hello from C environment". early_printk() function was changed in comparison with original as common isn't being built now so there is no vscnprintf.

Because printk() relies on a serial driver (like the ns16550 driver) and drivers require working virtual memory (ioremap()) there is not print functionality early in Xen boot.

Quoted 5 lines

This commit adds early printk implementation built on the putc SBI call.

As sbi_console_putchar() is being already planned for deprecation it is used temporary now and will be removed or reworked after real uart will be ready.

Quoted 6 lines

There was a discussion to add a new SBI putchar replacement. It doesn't seem to be completed yet, but there might be an SBI replacement for this in the future as well.

Alistair

Are you referring to the Debug Console Extension (EID #0x4442434E "DBCN")”?

https://lists.riscv.org/g/tech-prs/topic/96051183#84

Best,
Bobby

Quoted 104 lines

Review

Quoted 41 lines

---
Changes in V2:
- add license to early_printk.c
- add signed-off-by Bobby
- add RISCV_32 to Kconfig.debug to EARLY_PRINTK config
- update commit message
- order the files alphabetically in Makefile

---
 xen/arch/riscv/Kconfig.debug              |  7 +++++
 xen/arch/riscv/Makefile                   |  1 +
 xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++++++++
 xen/arch/riscv/include/asm/early_printk.h | 12 +++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 xen/arch/riscv/early_printk.c
 create mode 100644 xen/arch/riscv/include/asm/early_printk.h
xen/arch/riscv/Kconfig.debug +7 -0
index e69de29bb2..6ba0bd1e5a 100644
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk config"
+    default DEBUG
+    depends on RISCV_64 || RISCV_32
+    help
+
+      Enables early printk debug messages
xen/arch/riscv/Makefile +1 -0
index fd916e1004..1a4f1a6015 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
 obj-$(CONFIG_RISCV_64) += riscv64/
 obj-y += sbi.o
 obj-y += setup.o
(quoted diff) +0 -0

b/xen/arch/riscv/early_printk.c

Review

Quoted 39 lines

new file mode 100644
index 0000000000..88da5169ed

xen/arch/riscv/early_printk.c new file +33 -0
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <[email protected]>
+ */
+#include <asm/sbi.h>
+#include <asm/early_printk.h>
+
+/*
+ * TODO:
+ *   sbi_console_putchar is already planned for deprication
+ *   so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+    while ( nr-- > 0 )
+    {
+        if (*s == '\n')
+            sbi_console_putchar('\r');
+        sbi_console_putchar(*s);
+        s++;
+    }
+}
+
+void early_printk(const char *str)
+{
+    while (*str)
+    {
+        early_puts(str, 1);
+        str++;
+    }
+}
(quoted diff) +0 -0

b/xen/arch/riscv/include/asm/early_printk.h

Quoted 21 lines

new file mode 100644
index 0000000000..05106e160d

xen/arch/riscv/include/asm/early_printk.h new file +12 -1
@@ -0,0 +1,12 @@
+#ifndef __EARLY_PRINTK_H__
+#define __EARLY_PRINTK_H__
+
+#include <xen/early_printk.h>
+
+#ifdef CONFIG_EARLY_PRINTK
+void early_printk(const char *str);
+#else
+static inline void early_printk(const char *s) {};
+#endif
+
+#endif /* __EARLY_PRINTK_H__ */
--

2.38.1

author
#25 lore raw

Re: [PATCH v2 8/8] automation: add RISC-V smoke test

In reply to Stefano Stabellini
Quoted 80 lines · Stefano Stabellini
Quoted 25 lines · Oleksii Kurochko

Add check if there is a message 'Hello from C env' presents in log file to be sure that stack is set and C part of early printk is working.

---
Changes in V2:
    - Move changes in the dockerfile to separate patch and  send it to
      mailing list separately:
        [PATCH] automation: add qemu-system-riscv to riscv64.dockerfile
    - Update test.yaml to wire up smoke test
---
 automation/gitlab-ci/test.yaml           | 20 ++++++++++++++++++++ automation/scripts/qemu-smoke-riscv64.sh | 20 ++++++++++++++++++++

 2 files changed, 40 insertions(+)

 create mode 100755 automation/scripts/qemu-smoke-riscv64.sh

automation/gitlab- renamed from automation/gitlab-ci/test.yaml +0 -0

ci/test.yaml
index afd80adfe1..64f47a0ab9 100644

automation/gitlab-ci/test.yaml +0 -0
@@ -54,6 +54,19 @@
Quoted 7 lines

   tags:
     - x86_64

+.qemu-riscv64:
+  extends: .test-jobs-common
+  variables:
+    CONTAINER: archlinux:riscv64

I realize that it is committed now, but following the arm32 convention
the name of the arch container (currently archlinux:riscv64) would be:

CONTAINER: archlinux:current-riscv64

I know this is not related to this patch, but I am taking the opportunity to mention it now in case we get an opportunity to fix it in
the future for consistency.

Quoted 15 lines

+    LOGFILE: qemu-smoke-riscv64.log
+  artifacts:
+    paths:
+      - smoke.serial
+      - '*.log'
+    when: always
+  tags:
+    - x86_64
+
 .yocto-test:
   extends: .test-jobs-common
   script:

automation/gitlab-ci/test.yaml +0 -0
@@ -234,6 +247,13 @@ qemu-smoke-x86-64-clang-pvh:

   needs:
     - debian-unstable-clang-debug

Quoted 8 lines


+qemu-smoke-riscv64-gcc:
+  extends: .qemu-riscv64
+  script:
+    - ./automation/scripts/qemu-smoke-riscv64.sh 2>&1 | tee ${LOGFILE}
+  needs:
+    - riscv64-cross-gcc

Similarly here the "needs" dependency should be called arch-current-gcc-riscv for consistency with arm32.

Basically we already have a crossbuild and crosstest environment up and
running in gitlab-ci and it is the one for arm32. You can just base all
the naming convention on that.

Quoted 9 lines

I realize that riscv64-cross-gcc is also already exported by build.yaml,
but I am mentioning it in case we get an opportunity to fix it in the future.

Nonetheless this patch on its own is OK so

Thanks for the comments.

I think it will be nice to fix that from the start so I will do a separete patch out of this patch series (when it will be merged) which will fix all this names related to RISCV.

Quoted 26 lines
Quoted 26 lines

 # Yocto test jobs
 yocto-qemuarm64:
   extends: .yocto-test-arm64

automation/scripts/qemu-smoke-riscv64.sh new file +15 -0
new file mode 100755
index 0000000000..e0f06360bc
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+set -ex
+
+# Run the test
+rm -f smoke.serial
+set +e
+
+timeout -k 1 2 \
+qemu-system-riscv64 \
+    -M virt \
+    -smp 1 \
+    -nographic \
+    -m 2g \
+    -kernel binaries/xen \
Quoted 8 lines
Quoted 8 lines
automation/scripts/qemu-smoke-riscv64.sh new file +5 -0
+    |& tee smoke.serial
+
+set -e
+(grep -q "Hello from C env" smoke.serial) || exit 1
+exit 0
Signature · 1 line
2.38.1

~Oleksii

author
#9 lore raw

Re: [PATCH v2 4/8] xen/riscv: introduce sbi call to putchar to console

In reply to Jan Beulich
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/sbi.h new file +5 -0
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021 Vates SAS.
+ *
+ * Taken from xvisor, modified by Bobby Eshleman

([email protected]).
+ *
+ * Taken/modified from Xvisor project with the following copyright:
+ *

Quoted 8 lines

xen/arch/riscv/include/asm/sbi.h line 13

Quoted 6 lines

+ * Copyright (c) 2019 Western Digital Corporation or its affiliates.
+ */

xen/arch/riscv/include/asm/sbi.h new file +3 -0
+
+#ifndef __CPU_SBI_H__
+#define __CPU_SBI_H__

Didn't you mean to change this?

Thanks.

My fault. Missed that. I will double check that and take into account in new patch series.

Quoted 15 lines
Quoted 9 lines
xen/arch/riscv/include/asm/sbi.h new file +8 -0
+#define SBI_EXT_0_1_CONSOLE_PUTCHAR            0x1
+
+struct sbiret {
+    long error;
+    long value;
+};
+
+struct sbiret sbi_ecall(unsigned long ext, unsigned long fid,
Quoted 4 lines

unsigned long arg0,
+        unsigned long arg1, unsigned long arg2,
+        unsigned long arg3, unsigned long arg4,
+        unsigned long arg5);

Please get indentation right here as well as for the definition.

Thanks for clarification.

Quoted 16 lines

Possible
forms are

struct sbiret sbi_ecall(unsigned long ext, unsigned long fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);

or

struct sbiret sbi_ecall(unsigned long ext, unsigned long fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);

Jan

author
#11 lore raw

Re: [PATCH v2 4/8] xen/riscv: introduce sbi call to putchar to console

In reply to Julien Grall

Hi,

Quoted 48 lines · Julien Grall

Hi,

Quoted 40 lines · Oleksii Kurochko

The patch introduce sbi_putchar() SBI call which is necessary to implement initial early_printk

---
Changes in V2:
     - add an explanatory comment about sbi_console_putchar() function.
     - order the files alphabetically in Makefile
---
  xen/arch/riscv/Makefile          |  1 + xen/arch/riscv/include/asm/sbi.h | 34 ++++++++++++++++++++++++ xen/arch/riscv/sbi.c             | 44
++++++++++++++++++++++++++++++++

  3 files changed, 79 insertions(+)

  create mode 100644 xen/arch/riscv/include/asm/sbi.h create mode 100644 xen/arch/riscv/sbi.c

xen/arch/riscv/Makefile +0 -0
index 5a67a3f493..fd916e1004 100644
@@ -1,4 +1,5 @@

  obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += sbi.o
  obj-y += setup.o

  $(TARGET): $(TARGET)-syms

xen/arch/riscv/include/asm/sbi.h new file +5 -0
new file mode 100644
index 0000000000..34b53f8eaf
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021 Vates SAS.
+ *
+ * Taken from xvisor, modified by Bobby Eshleman
Quoted 1 line

([email protected]).

Hmmm... I missed this one in v1. Is this mostly code from Bobby? If so,
please update the commit message accordingly.

Quoted 6 lines

FAOD, this comment applies for any future code you take from anyone. I
will try to remember to mention it but please take pro-active action to
check/mention where the code is coming from.

Sure, I will try to be more attentive next time.

Probably it is out of scope a little bit but could you please share with me a link or clarify in which cases I have to add Copytrigt(c) or should I add a new comment with "Modfied by Oleksii ... ", or it is not necessary at all? Maybe have I to put some other information related to copyrigts?

Thanks in advance.

Quoted 2 lines

Cheers,

~Oleksii

author
#5 lore raw

Re: [PATCH v2 3/8] xen/riscv: introduce stack stuff

In reply to Julien Grall
Quoted 10 lines · Julien Grall

Hi,

Quoted 4 lines · Oleksii Kurochko

The patch introduces and sets up a stack in order to go to C environment

It looks like the comments from Andrew were missed.

I will double check which one.
Thanks.

Quoted 56 lines
Quoted 56 lines

---
Changes in V2:
     - introduce STACK_SIZE define.
     - use consistent padding between instruction mnemonic and operand(s)
---
  xen/arch/riscv/Makefile             | 1 + xen/arch/riscv/include/asm/config.h | 2 ++ xen/arch/riscv/riscv64/head.S       | 8 +++++++- xen/arch/riscv/setup.c              | 6 ++++++

  4 files changed, 16 insertions(+), 1 deletion(-)

  create mode 100644 xen/arch/riscv/setup.c

xen/arch/riscv/Makefile +0 -0
index 248f2cbb3e..5a67a3f493 100644
@@ -1,4 +1,5 @@

  obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += setup.o

  $(TARGET): $(TARGET)-syms
        $(OBJCOPY) -O binary -S $< $@

xen/arch/riscv/include/asm/config.h +0 -0
index 0370f865f3..bdd2237f01 100644
@@ -43,6 +43,8 @@


  #define SMP_CACHE_BYTES (1 << 6)

xen/arch/riscv/include/asm/config.h +2 -0
+#define STACK_SIZE (PAGE_SIZE)
+

  #endif /* __RISCV_CONFIG_H__ */
  /*
   * Local variables:

xen/arch/riscv/riscv64/head.S +0 -0
index 990edb70a0..c1f33a1934 100644
@@ -1,4 +1,10 @@

          .section .text.header, "ax", %progbits

  ENTRY(start)
-        j  start
+        la      sp, cpu0_boot_stack
+        li      t0, STACK_SIZE
+        add     sp, sp, t0

xen/arch/riscv/riscv64/head.S +4 -0
+
+_start_hang:
+        wfi
+        j       _start_hang
xen/arch/riscv/setup.c new file +0 -0
new file mode 100644
Quoted 9 lines

xen/arch/riscv/setup.c line 2

Quoted 6 lines

index 0000000000..41ef4912bd

xen/arch/riscv/setup.c new file +2 -0
@@ -0,0 +1,6 @@
+#include <xen/init.h>
+#include <xen/compile.h>

Why do you need to include <xen/compile.h>?

It is needed to use __aligned define which looks better then __attribute__((__aligned__(SOMETHING)))

Quoted 2 lines

In any case, please order the include alphabetically. I haven't look at

Thanks. I didn't now that headers should be in alphabetic order too.

Quoted 6 lines

the rest of the series. But please go through the series and check that
generic comments (like this one) are addressed everywhere.

Cheers,

~Oleksii

#20 lore raw

Re: [PATCH v2 6/8] xen/riscv: introduce early_printk basic stuff

In reply to Bobby Eshleman
Quoted 27 lines · Bobby Eshleman
Quoted 23 lines · Alistair Francis
Quoted 10 lines · Oleksii Kurochko

The patch introduces a basic stuff of early_printk functionality which will be enough to print 'hello from C environment". early_printk() function was changed in comparison with original as common isn't being built now so there is no vscnprintf.

Because printk() relies on a serial driver (like the ns16550 driver) and drivers require working virtual memory (ioremap()) there is not print functionality early in Xen boot.

Quoted 5 lines

This commit adds early printk implementation built on the putc SBI call.

As sbi_console_putchar() is being already planned for deprecation it is used temporary now and will be removed or reworked after real uart will be ready.

There was a discussion to add a new SBI putchar replacement. It doesn't seem to be completed yet, but there might be an SBI replacement for this in the future as well.

Quoted 6 lines
Quoted 1 line

Alistair

Are you referring to the Debug Console Extension (EID #0x4442434E "DBCN")”?

https://lists.riscv.org/g/tech-prs/topic/96051183#84

That's the one!

Alistair

Quoted 106 lines

Best,
Bobby

Quoted 102 lines
Quoted 102 lines

---
Changes in V2:
- add license to early_printk.c
- add signed-off-by Bobby
- add RISCV_32 to Kconfig.debug to EARLY_PRINTK config
- update commit message
- order the files alphabetically in Makefile

---
 xen/arch/riscv/Kconfig.debug              |  7 +++++
 xen/arch/riscv/Makefile                   |  1 +
 xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++++++++
 xen/arch/riscv/include/asm/early_printk.h | 12 +++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 xen/arch/riscv/early_printk.c
 create mode 100644 xen/arch/riscv/include/asm/early_printk.h
xen/arch/riscv/Kconfig.debug +7 -0
index e69de29bb2..6ba0bd1e5a 100644
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk config"
+    default DEBUG
+    depends on RISCV_64 || RISCV_32
+    help
+
+      Enables early printk debug messages
xen/arch/riscv/Makefile +1 -0
index fd916e1004..1a4f1a6015 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
 obj-$(CONFIG_RISCV_64) += riscv64/
 obj-y += sbi.o
 obj-y += setup.o
xen/arch/riscv/early_printk.c new file +33 -0
new file mode 100644
index 0000000000..88da5169ed
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <[email protected]>
+ */
+#include <asm/sbi.h>
+#include <asm/early_printk.h>
+
+/*
+ * TODO:
+ *   sbi_console_putchar is already planned for deprication
+ *   so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+    while ( nr-- > 0 )
+    {
+        if (*s == '\n')
+            sbi_console_putchar('\r');
+        sbi_console_putchar(*s);
+        s++;
+    }
+}
+
+void early_printk(const char *str)
+{
+    while (*str)
+    {
+        early_puts(str, 1);
+        str++;
+    }
+}
xen/arch/riscv/include/asm/early_printk.h new file +12 -1
new file mode 100644
index 0000000000..05106e160d
@@ -0,0 +1,12 @@
+#ifndef __EARLY_PRINTK_H__
+#define __EARLY_PRINTK_H__
+
+#include <xen/early_printk.h>
+
+#ifdef CONFIG_EARLY_PRINTK
+void early_printk(const char *str);
+#else
+static inline void early_printk(const char *s) {};
+#endif
+
+#endif /* __EARLY_PRINTK_H__ */
--

2.38.1

#12 lore raw

Re: [PATCH v2 4/8] xen/riscv: introduce sbi call to putchar to console

In reply to Oleksii
Quoted 1 line · Oleksii

Hi,

Hi Oleksii,

Quoted 55 lines · Julien Grall
Quoted 48 lines

Hi,

Quoted 40 lines · Oleksii Kurochko

The patch introduce sbi_putchar() SBI call which is necessary to implement initial early_printk

---
Changes in V2:
     - add an explanatory comment about sbi_console_putchar()
function.
     - order the files alphabetically in Makefile

---
   xen/arch/riscv/Makefile          |  1 +
   xen/arch/riscv/include/asm/sbi.h | 34 ++++++++++++++++++++++++
   xen/arch/riscv/sbi.c             | 44
++++++++++++++++++++++++++++++++
   3 files changed, 79 insertions(+)

  create mode 100644 xen/arch/riscv/include/asm/sbi.h create mode 100644 xen/arch/riscv/sbi.c

xen/arch/riscv/Makefile +1 -0
index 5a67a3f493..fd916e1004 100644
@@ -1,4 +1,5 @@
   obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += sbi.o
   obj-y += setup.o
 
   $(TARGET): $(TARGET)-syms
xen/arch/riscv/include/asm/sbi.h new file +5 -0
new file mode 100644
index 0000000000..34b53f8eaf
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021 Vates SAS.
+ *
+ * Taken from xvisor, modified by Bobby Eshleman
Quoted 1 line

([email protected]).

Hmmm... I missed this one in v1. Is this mostly code from Bobby? If so,
please update the commit message accordingly.

Quoted 6 lines

FAOD, this comment applies for any future code you take from anyone. I
will try to remember to mention it but please take pro-active action to
check/mention where the code is coming from.

Quoted 7 lines

Sure, I will try to be more attentive next time.

Probably it is out of scope a little bit but could you please share with me a link or clarify in which cases I have to add Copytrigt(c) or should I add a new comment with "Modfied by Oleksii ... ", or it is not necessary at all? Maybe have I to put some other information related to copyrigts?

From my experience, in Xen, we tend to use the signed-off-by rather in-file copyright. So I don't exactly know what would be the rule.

Maybe George can help here?

Cheers,

Signature · 1 line
Julien Grall
#13 lore raw

Re: [PATCH v2 4/8] xen/riscv: introduce sbi call to putchar to console

(+ George)

Quoted 76 lines · Julien Grall
Quoted 1 line · Oleksii

Hi,

Hi Oleksii,

Quoted 54 lines · Julien Grall
Quoted 47 lines

Hi,

Quoted 39 lines · Oleksii Kurochko

The patch introduce sbi_putchar() SBI call which is necessary to implement initial early_printk

---
Changes in V2:
      - add an explanatory comment about sbi_console_putchar() function.
      - order the files alphabetically in Makefile
---
   xen/arch/riscv/Makefile          |  1 + xen/arch/riscv/include/asm/sbi.h | 34 ++++++++++++++++++++++++ xen/arch/riscv/sbi.c             | 44
++++++++++++++++++++++++++++++++

   3 files changed, 79 insertions(+)

   create mode 100644 xen/arch/riscv/include/asm/sbi.h create mode 100644 xen/arch/riscv/sbi.c

xen/arch/riscv/Makefile +0 -0
index 5a67a3f493..fd916e1004 100644
@@ -1,4 +1,5 @@

   obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += sbi.o
   obj-y += setup.o
   $(TARGET): $(TARGET)-syms

xen/arch/riscv/include/asm/sbi.h new file +5 -0
new file mode 100644
index 0000000000..34b53f8eaf
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021 Vates SAS.
+ *
+ * Taken from xvisor, modified by Bobby Eshleman
Quoted 1 line

([email protected]).

Hmmm... I missed this one in v1. Is this mostly code from Bobby? If so,
please update the commit message accordingly.

Quoted 6 lines

FAOD, this comment applies for any future code you take from anyone. I
will try to remember to mention it but please take pro-active action to
check/mention where the code is coming from.

Quoted 7 lines

Sure, I will try to be more attentive next time.

Probably it is out of scope a little bit but could you please share with me a link or clarify in which cases I have to add Copytrigt(c) or should I add a new comment with "Modfied by Oleksii ... ", or it is not necessary at all? Maybe have I to put some other information related to copyrigts?

From my experience, in Xen, we tend to use the signed-off-by rather
in-file copyright. So I don't exactly know what would be the rule.

Maybe George can help here?

Cheers,

Signature · 1 line
Julien Grall