From patchwork Fri Jan 27 11:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13118436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40B3AC54EAA for ; Fri, 27 Jan 2023 11:39:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.485492.752766 (Exim 4.92) (envelope-from ) id 1pLN4u-0001nj-S5; Fri, 27 Jan 2023 11:39:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 485492.752766; Fri, 27 Jan 2023 11:39:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLN4u-0001nO-NV; Fri, 27 Jan 2023 11:39:32 +0000 Received: by outflank-mailman (input) for mailman id 485492; Fri, 27 Jan 2023 11:39:30 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLN4s-0001VA-EN for xen-devel@lists.xenproject.org; Fri, 27 Jan 2023 11:39:30 +0000 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [2a00:1450:4864:20::332]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 418b6290-9e37-11ed-b8d1-410ff93cb8f0; Fri, 27 Jan 2023 12:39:28 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id l8so3239842wms.3 for ; Fri, 27 Jan 2023 03:39:28 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-240-53.w90-112.abo.wanadoo.fr. [90.112.199.53]) by smtp.gmail.com with ESMTPSA id x10-20020a05600c420a00b003c6b70a4d69sm3919529wmh.42.2023.01.27.03.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 03:39:26 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 418b6290-9e37-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kD9WTDzKXvdc7hcj/tM3aNt9EYeu8WRQj4/RhYxhaQs=; b=fiuBhFv3Q1w6K1BLC1mZXHcPqytGRc5HF9W2Jov993P3ucMGjedlzzFnQzwpkgmY6B JoloqYCghreioF3HjMMSOOs/PomMn3N3IcHFswthvzvhqM00nFeKzGlOe/HQrO/E1I2p 7tQG04+5e/5AHAZ3mHmduuuYs8fpJqZ8F6xlD+S5zIyZ7lqrIVwTlccFcmS56FZKCxoS 7/eAKN5P9XOkHhkfjv4b893bRwZshkQtg9JSEHmFje4bJK9nrOKS8v3q0L7pfoEOK/f1 CqnuvXtdNV6xJ+uXriY+Jt14AFoM1ggcbe0DLz7LATbGRGLFvimdYu5wEcs7SOmpDm5a T9FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kD9WTDzKXvdc7hcj/tM3aNt9EYeu8WRQj4/RhYxhaQs=; b=LqOLUtUeoFWMmcTiDz6jwcu3G/2/8iShR7VJKs0F1fTV/qoJ9wa0xE8vXMqRv4PyrZ shOeiX3cpEIbSWvv7Wge/hfwjW4hyVMznkCTZ0IxWlOdc7Truvh3p/nG2BTrVntgm4FO mi7Ysv9T6mnmbNMsmo1xlcpGDSxlRE0ypvDQ7c3Vztf+O6bvrnwRboMYHPw2gOiVqzyp Yc58m2J3zW04rNxCWrC11qr21TEIhfjJwul8ow7EBX3vrOXXy0SN0BqlX+J26mJ4VSbB ptdt5aHztzlKTp1phuWjfY1W2j4mV9jy0nYtD/eqGy+xDcDxBkgp0/8MV1zEgisGsD4M HMGg== X-Gm-Message-State: AO0yUKXMnu6l1jG+LgRIDpDOB8UY5iNR7FOO2zIkBI+j/DT41j+u5MzQ vl5q+Rn4AXv6IukWCUdPpHhkI/t7CRg= X-Google-Smtp-Source: AK7set/d68ZSvlXnJnOPBgabJIFxl+Gzsa1TZe8Nq5jnlvFxiIE9QQ6jIjoMC6/yY5gu/q6/f5B0ig== X-Received: by 2002:a05:600c:19c8:b0:3dc:353c:8b44 with SMTP id u8-20020a05600c19c800b003dc353c8b44mr2106455wmq.5.1674819567139; Fri, 27 Jan 2023 03:39:27 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Julien Grall , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Bob Eshleman , Alistair Francis , Connor Davis , Bobby Eshleman Subject: [PATCH v7 1/2] xen/riscv: introduce early_printk basic stuff Date: Fri, 27 Jan 2023 13:39:14 +0200 Message-Id: <06c2c36bd68b2534c757dc4087476e855253680a.1674819203.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 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. The patch introduces the basic stuff of early_printk functionality which will be enough to print 'hello from C environment". Originally early_printk.{c,h} was introduced by Bobby Eshleman (https://github.com/glg-rv/xen/commit/a3c9916bbdff7ad6030055bbee7e53d1aab71384) but some functionality was changed: early_printk() function was changed in comparison with the original as common isn't being built now so there is no vscnprintf. This commit adds early printk implementation built on the putc SBI call. As sbi_console_putchar() is already being planned for deprecation it is used temporarily now and will be removed or reworked after real uart will be ready. Signed-off-by: Bobby Eshleman Signed-off-by: Oleksii Kurochko Reviewed-by: Bobby Eshleman --- Changes in V7: - Nothing was changed --- Changes in V6: - Remove __riscv_cmodel_medany check from early_printk.c --- Changes in V5: - Code style fixes - Change an error message of #error in case of __riscv_cmodel_medany isn't defined --- Changes in V4: - Remove "depends on RISCV*" from Kconfig.debug as it is located in arch specific folder so by default RISCV configs should be ebabled. - Add "ifdef __riscv_cmodel_medany" to be sure that PC-relative addressing is used as early_*() functions can be called from head.S with MMU-off and before relocation (if it would be needed at all for RISC-V) - fix code style --- Changes in V3: - reorder headers in alphabetical order - merge changes related to start_xen() function from "[PATCH v2 7/8] xen/riscv: print hello message from C env" to this patch - remove unneeded parentheses in definition of STACK_SIZE --- Changes in V2: - introduce STACK_SIZE define. - use consistent padding between instruction mnemonic and operand(s) --- xen/arch/riscv/Kconfig.debug | 5 ++++ xen/arch/riscv/Makefile | 1 + xen/arch/riscv/early_printk.c | 33 +++++++++++++++++++++++ xen/arch/riscv/include/asm/early_printk.h | 12 +++++++++ xen/arch/riscv/setup.c | 4 +++ 5 files changed, 55 insertions(+) create mode 100644 xen/arch/riscv/early_printk.c create mode 100644 xen/arch/riscv/include/asm/early_printk.h diff --git a/xen/arch/riscv/Kconfig.debug b/xen/arch/riscv/Kconfig.debug index e69de29bb2..608c9ff832 100644 --- a/xen/arch/riscv/Kconfig.debug +++ b/xen/arch/riscv/Kconfig.debug @@ -0,0 +1,5 @@ +config EARLY_PRINTK + bool "Enable early printk" + default DEBUG + help + Enables early printk debug messages diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile index fd916e1004..1a4f1a6015 100644 --- a/xen/arch/riscv/Makefile +++ b/xen/arch/riscv/Makefile @@ -1,3 +1,4 @@ +obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_RISCV_64) += riscv64/ obj-y += sbi.o obj-y += setup.o diff --git a/xen/arch/riscv/early_printk.c b/xen/arch/riscv/early_printk.c new file mode 100644 index 0000000000..b66a11f1bc --- /dev/null +++ b/xen/arch/riscv/early_printk.c @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * RISC-V early printk using SBI + * + * Copyright (C) 2021 Bobby Eshleman + */ +#include +#include + +/* + * TODO: + * sbi_console_putchar is already planned for deprecation + * 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++; + } +} diff --git a/xen/arch/riscv/include/asm/early_printk.h b/xen/arch/riscv/include/asm/early_printk.h new file mode 100644 index 0000000000..05106e160d --- /dev/null +++ b/xen/arch/riscv/include/asm/early_printk.h @@ -0,0 +1,12 @@ +#ifndef __EARLY_PRINTK_H__ +#define __EARLY_PRINTK_H__ + +#include + +#ifdef CONFIG_EARLY_PRINTK +void early_printk(const char *str); +#else +static inline void early_printk(const char *s) {}; +#endif + +#endif /* __EARLY_PRINTK_H__ */ diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 13e24e2fe1..d09ffe1454 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -1,12 +1,16 @@ #include #include +#include + /* 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"); From patchwork Fri Jan 27 11:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13118437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 09614C61DA4 for ; Fri, 27 Jan 2023 11:39:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.485491.752761 (Exim 4.92) (envelope-from ) id 1pLN4u-0001kp-Hz; Fri, 27 Jan 2023 11:39:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 485491.752761; Fri, 27 Jan 2023 11:39:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLN4u-0001ki-FE; Fri, 27 Jan 2023 11:39:32 +0000 Received: by outflank-mailman (input) for mailman id 485491; Fri, 27 Jan 2023 11:39:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLN4r-0001Uz-5Y for xen-devel@lists.xenproject.org; Fri, 27 Jan 2023 11:39:29 +0000 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [2a00:1450:4864:20::329]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 41f36b44-9e37-11ed-a5d9-ddcf98b90cbd; Fri, 27 Jan 2023 12:39:28 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id q10-20020a1cf30a000000b003db0edfdb74so5329050wmq.1 for ; Fri, 27 Jan 2023 03:39:28 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-240-53.w90-112.abo.wanadoo.fr. [90.112.199.53]) by smtp.gmail.com with ESMTPSA id x10-20020a05600c420a00b003c6b70a4d69sm3919529wmh.42.2023.01.27.03.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 03:39:27 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 41f36b44-9e37-11ed-a5d9-ddcf98b90cbd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Uv27LIdYCOpQaEPTODxpqyn21y70RSmO8lj9poeyTD0=; b=Vdcw6Z3aVdiU3Sn0P/j/aSOsJ9zToHiDE2D9yOE3xe4E/80BGnJkcnR1iPVVpbFhBR XQ5GjH9sixS+9yUDeOJpSMRnNlYIE1tJq3JAGBVOr52DU2ViwVlZzeE65dPa6wiO0/V6 HragHpODHCvSJfO9+xHA/DqsLlpnvYPshDVYmy3T2XuHURPSCNROp0FHvUuxhPZJGHk8 4KC172vuszXLlC//m5UjMMPUue53kyYE+mOKmeqN7MCAU9A/ea2/VxApHF1GURxcfIIT BMYJ/l+LbO2GM9yGSFVGcKf21cGgC8ZdEKsWqgg/ySBzyCEbe3GqprxrBMZNY1/TQA65 1tlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uv27LIdYCOpQaEPTODxpqyn21y70RSmO8lj9poeyTD0=; b=CfVPS/5Xe8+14XH6vv6N5XnY6AqDVZHBSSA/94sWDEnB1JuhVDyAWtW52mOvDa50gD ufKghsZf//XvEZA53vNQZG7SD3iMZswfzG6lLnai7usLsa89IwLP5GGmqsR/o6o2Olb6 NvMGOliXS8lfFQPFDASUa/o/xS8srObt5Vnvd5KeVGJhhBQS4nMWBg7y9doUTAKRWNue cO0oEM1Ja7zYrc/e9otygxvwkXZmJs+1oPZ4QFjyioWOfABqjNsEb0jzw4/l6CG/G19F FX5zq9ucqS7V17YYv5zy5sg/CKCHaqsB003JFgfNLeOsOAdJvQs5i1hFyMURoVyNI7Kt z1pA== X-Gm-Message-State: AO0yUKWndmJhhuIL6YMlCJgtYkwAV55OLETjxtgVUOJwkYmyNxF1QPVc ErfT8BaPXfnSY+byHzIK71S8vgTfLSw= X-Google-Smtp-Source: AK7set9HjLKVcPhRNaIz/MVicozKNYe4geIJ1zxFzuF28gioPDQALBXCWh1g5BsZxvff99m08PHbVg== X-Received: by 2002:a05:600c:3501:b0:3dc:19d1:3c1f with SMTP id h1-20020a05600c350100b003dc19d13c1fmr10629718wmq.30.1674819568009; Fri, 27 Jan 2023 03:39:28 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Julien Grall , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Doug Goldstein , Alistair Francis Subject: [PATCH v7 2/2] automation: add RISC-V smoke test Date: Fri, 27 Jan 2023 13:39:15 +0200 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 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. Signed-off-by: Oleksii Kurochko Acked-by: Stefano Stabellini Reviewed-by: Alistair Francis --- Changes in V7: - Fix dependecy for qemu-smoke-riscv64-gcc job --- Changes in V6: - Rename container name in test.yaml for .qemu-riscv64. --- Changes in V5: - Nothing changed --- Changes in V4: - Nothing changed --- Changes in V3: - Nothing changed - All mentioned comments by Stefano in Xen mailing list will be fixed as a separate patch out of this patch series. --- 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 diff --git a/automation/gitlab-ci/test.yaml b/automation/gitlab-ci/test.yaml index afd80adfe1..4dbe1b8af7 100644 --- a/automation/gitlab-ci/test.yaml +++ b/automation/gitlab-ci/test.yaml @@ -54,6 +54,19 @@ tags: - x86_64 +.qemu-riscv64: + extends: .test-jobs-common + variables: + CONTAINER: archlinux:current-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: + - .gcc-riscv64-cross-build + # Yocto test jobs yocto-qemuarm64: extends: .yocto-test-arm64 diff --git a/automation/scripts/qemu-smoke-riscv64.sh b/automation/scripts/qemu-smoke-riscv64.sh new file mode 100755 index 0000000000..e0f06360bc --- /dev/null +++ b/automation/scripts/qemu-smoke-riscv64.sh @@ -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