From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578948; cv=none; d=zohomail.com; s=zohoarc; b=ItCYhErq9F9/6nqv185JjDYK7cUo7KOJvglTHqD44rTZ2VWXrXmbRgVd0dOTB+N9oBctqnTdpcUA0l1UAyf5XdAWD2f+6y8PKecO4vXYbsfsPsKAq5ec6cB8eTWTNsAh3talmonX6RC81KSp9+2D9PfncoGiWwOjo1wPFJQI4H8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578948; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=a+Zgm0io6LeoIsyl5JLjVBfyHJJ+8SzMmZMEhejfwZM=; b=FziHt5Dy52nBbIPoPGkysEpNu5bVGDDitqVpZyAG1qYsH9WmVpFhB0m6dGAKb71wxE/Nmzu/c6zmWNaUdHeCrMuoqdwVr+Y9Yrpg8idbY3hZrxlLlPPSXVcO1bM3HtaUUhkIR9gHtmIlQKM5IiFZ5SsKHN6jSJP2nnv10RFLWFg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578948179605.0283298060718; Fri, 10 Apr 2020 21:22:28 -0700 (PDT) Received: from localhost ([::1]:48642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7f0-0001hv-0m for importer@patchew.org; Sat, 11 Apr 2020 00:22:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47199) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7Ze-0000N2-Od for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZT-0006M7-VL for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:53 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3739 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZT-0006L7-L6; Sat, 11 Apr 2020 00:16:43 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 74309DF672F0D1670750; Sat, 11 Apr 2020 12:16:40 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:33 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 1/9] linux-header: Update linux/kvm.h Date: Sat, 11 Apr 2020 12:14:19 +0800 Message-ID: <20200411041427.14828-2-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update linux/kvm.h to commit b9a6e4cd9 on https://github.com/kvm-riscv/linu= x. Only use this header file, so do not update all linux headers. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- linux-headers/linux/kvm.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 265099100e..7cfc111af5 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -236,6 +236,7 @@ struct kvm_hyperv_exit { #define KVM_EXIT_IOAPIC_EOI 26 #define KVM_EXIT_HYPERV 27 #define KVM_EXIT_ARM_NISV 28 +#define KVM_EXIT_RISCV_SBI 28 =20 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -400,6 +401,13 @@ struct kvm_run { __u64 esr_iss; __u64 fault_ipa; } arm_nisv; + /* KVM_EXIT_RISCV_SBI */ + struct { + unsigned long extension_id; + unsigned long function_id; + unsigned long args[6]; + unsigned long ret[2]; + } riscv_sbi; /* Fix the size of the union. */ char padding[256]; }; --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578665; cv=none; d=zohomail.com; s=zohoarc; b=TW8XDmSjtAmebQXNBCWUreBKfKc94N+6x1nT9avA3SdfDk1B2/NefQ+mj/eYWj+dCzbJvLp/igcXUxom5LiqBIxoUR/cjzOTYFYZ594fPGPej6GxOk64diQHQ8H2zA+Yi9tC6XCYXAqZAtrJZ9ncJrEk3B4N1VgyrzJthhN5wFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578665; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6hLy0KWbnCkWnptXqxMUGfTAv2s0ZwRn5Xi59VDc2FE=; b=k+qovDmlANeIzSXd7lu+agSaTt0OgM89moI3wU/7pfzbz4RHHNcvCb/5S+MYgtIp6Zp+85UeT1ZZ+aVZ/UJWZ96mo/Z7++FGWN85k69vkjFHteZujvTEu6NNDCe1/Q4kKZwfQzvBbWK/VMu7mcRh2BX97kWt36Nm52H3F1k91so= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578665364991.5340164885034; Fri, 10 Apr 2020 21:17:45 -0700 (PDT) Received: from localhost ([::1]:48546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7aS-0001p8-4x for importer@patchew.org; Sat, 11 Apr 2020 00:17:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47051) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7ZV-0000BO-Iv for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZU-0006MP-2T for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:45 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3740 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZT-0006L8-Nh; Sat, 11 Apr 2020 00:16:44 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6E36319CAD27E4DABFCC; Sat, 11 Apr 2020 12:16:40 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:33 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 2/9] target/riscv: Add target/riscv/kvm.c to place the public kvm interface Date: Sat, 11 Apr 2020 12:14:20 +0800 Message-ID: <20200411041427.14828-3-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add target/riscv/kvm.c to place kvm_arch_* function needed by kvm/kvm-all.c. Meanwhile, add kvm support in configure file. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin Reviewed-by: Alistair Francis --- configure | 1 + target/riscv/Makefile.objs | 1 + target/riscv/kvm.c | 128 +++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 target/riscv/kvm.c diff --git a/configure b/configure index 233c671aaa..7114a1c64d 100755 --- a/configure +++ b/configure @@ -200,6 +200,7 @@ supported_kvm_target() { x86_64:i386 | x86_64:x86_64 | x86_64:x32 | \ mips:mips | mipsel:mips | \ ppc:ppc | ppc64:ppc | ppc:ppc64 | ppc64:ppc64 | ppc64:ppc64le | \ + riscv32:riscv32 | riscv64:riscv64 | \ s390x:s390x) return 0 ;; diff --git a/target/riscv/Makefile.objs b/target/riscv/Makefile.objs index ff651f69f6..7ea8f4c3da 100644 --- a/target/riscv/Makefile.objs +++ b/target/riscv/Makefile.objs @@ -1,5 +1,6 @@ obj-y +=3D translate.o op_helper.o cpu_helper.o cpu.o csr.o fpu_helper.o g= dbstub.o obj-$(CONFIG_SOFTMMU) +=3D pmp.o +obj-$(CONFIG_KVM) +=3D kvm.o =20 ifeq ($(CONFIG_SOFTMMU),y) obj-y +=3D monitor.o diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c new file mode 100644 index 0000000000..8c386d9acf --- /dev/null +++ b/target/riscv/kvm.c @@ -0,0 +1,128 @@ +/* + * RISC-V implementation of KVM hooks + * + * Copyright (c) 2020 Huawei Technologies Co., Ltd + * + * 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 or later, 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 f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include + +#include + +#include "qemu-common.h" +#include "qemu/timer.h" +#include "qemu/error-report.h" +#include "qemu/main-loop.h" +#include "sysemu/sysemu.h" +#include "sysemu/kvm.h" +#include "sysemu/kvm_int.h" +#include "cpu.h" +#include "trace.h" +#include "hw/pci/pci.h" +#include "exec/memattrs.h" +#include "exec/address-spaces.h" +#include "hw/boards.h" +#include "hw/irq.h" +#include "qemu/log.h" +#include "hw/loader.h" + +const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { + KVM_CAP_LAST_INFO +}; + +int kvm_arch_get_registers(CPUState *cs) +{ + return 0; +} + +int kvm_arch_put_registers(CPUState *cs, int level) +{ + return 0; +} + +int kvm_arch_release_virq_post(int virq) +{ + return 0; +} + +int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, + uint64_t address, uint32_t data, PCIDevice *d= ev) +{ + return 0; +} + +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + +unsigned long kvm_arch_vcpu_id(CPUState *cpu) +{ + return cpu->cpu_index; +} + +void kvm_arch_init_irq_routing(KVMState *s) +{ +} + +int kvm_arch_init_vcpu(CPUState *cs) +{ + return 0; +} + +int kvm_arch_msi_data_to_gsi(uint32_t data) +{ + abort(); +} + +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, + int vector, PCIDevice *dev) +{ + return 0; +} + +int kvm_arch_init(MachineState *ms, KVMState *s) +{ + return 0; +} + +int kvm_arch_irqchip_create(KVMState *s) +{ + return 0; +} + +int kvm_arch_process_async_events(CPUState *cs) +{ + return 0; +} + +void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run) +{ +} + +MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) +{ + return MEMTXATTRS_UNSPECIFIED; +} + +bool kvm_arch_stop_on_emulation_error(CPUState *cs) +{ + return true; +} + +int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) +{ + return 0; +} --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578669; cv=none; d=zohomail.com; s=zohoarc; b=FVhwN48EjEK5qbu6a6cQluKtA0LX2mjzw5nQU0Lt8YTaY4uywQw7plSBhQS9MbZAiSRX5Me+2n/k5aPne1iRNvgP9ItcnNpr0fr0t2gv54UjIsP7Dru6QNFPWDHBxdPyA/zXdsvRNI+YiKMEJqSERAnmBpBey1/+Up43RQS2Zp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578669; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mJIH2bnq2jrMCWsxO2yiB6MhAzwyDV+/muluREKB3gc=; b=d1BBosoHjhXKmiOy4I0i7oAnI6SsCXWcvRS2DWLu4o7bUFkIkt3cmPSw+2xxBQZZEZjrm0Xh6yyttjFb6+NuUE4U7OA5Rs+bSNR2/PU9WrhR5G3ZcYVxbYQzoj+tPR+nUJgjhYbxG2elXf1QqMVa/bbrA7RvBzCZiAbtNxt9ePI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578669946852.2987412422001; Fri, 10 Apr 2020 21:17:49 -0700 (PDT) Received: from localhost ([::1]:48550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7aW-00023o-H2 for importer@patchew.org; Sat, 11 Apr 2020 00:17:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47218) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7Zf-0000Pg-51 for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZU-0006ME-0a for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:54 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3741 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZT-0006L6-MO; Sat, 11 Apr 2020 00:16:43 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 684BDB5DED9E6ACACEC5; Sat, 11 Apr 2020 12:16:40 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:34 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 3/9] target/riscv: Implement function kvm_arch_init_vcpu Date: Sat, 11 Apr 2020 12:14:21 +0800 Message-ID: <20200411041427.14828-4-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Get isa info from kvm while kvm init. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- target/riscv/kvm.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 8c386d9acf..3e8f8e7185 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -38,6 +38,18 @@ #include "qemu/log.h" #include "hw/loader.h" =20 +static __u64 kvm_riscv_reg_id(__u64 type, __u64 idx) +{ + __u64 id =3D KVM_REG_RISCV | type | idx; + +#if defined(TARGET_RISCV32) + id |=3D KVM_REG_SIZE_U32; +#elif defined(TARGET_RISCV64) + id |=3D KVM_REG_SIZE_U64; +#endif + return id; +} + const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { KVM_CAP_LAST_INFO }; @@ -79,7 +91,19 @@ void kvm_arch_init_irq_routing(KVMState *s) =20 int kvm_arch_init_vcpu(CPUState *cs) { - return 0; + int ret =3D 0; + uint64_t isa; + RISCVCPU *cpu =3D RISCV_CPU(cs); + __u64 id; + + id =3D kvm_riscv_reg_id(KVM_REG_RISCV_CONFIG, KVM_REG_RISCV_CONFIG_REG= (isa)); + ret =3D kvm_get_one_reg(cs, id, &isa); + if (ret) { + return ret; + } + cpu->env.misa =3D isa; + + return ret; } =20 int kvm_arch_msi_data_to_gsi(uint32_t data) --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578668; cv=none; d=zohomail.com; s=zohoarc; b=nfWGjmu7/N1EMzTDbeln6e0L1Qr2EZUvXAdoQW8bleo15Pwyrt70Ml2fqsc97C4LPydvpEsceqkaXp4pWOUch/89bJ5gwiY01lrVZud2IbZt/x1VH1+hTKZci77/G590asLkKUzbTMa0Ch3WL+CFAx+CiK6EytuhoiDiSNu9eaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578668; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=a6Hkfd447qrSBgoCmVOKCxWubihSyFE+ViNH+TCc0ho=; b=SbHOf+hYNdK9KT0NsOE1yQ7u0FTAdwAEEmnq/vODx1BmbQGbPyd5i2MJSaE3lceJgwOAkoL8uHzha30m2zwiiKNURbQ/z0bWIoEFhy2krbrHKfzzS4AN73PRNl5CBJd2/yhfLuZ259OfBm0hkj0+E89raOnucY1kjPn28ypPga4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578668989933.764952061628; Fri, 10 Apr 2020 21:17:48 -0700 (PDT) Received: from localhost ([::1]:48548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7aV-0001zi-Mt for importer@patchew.org; Sat, 11 Apr 2020 00:17:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47118) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7Za-0000Gf-1X for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZY-0006Ux-Lz for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:49 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43836 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZY-0006OX-B4; Sat, 11 Apr 2020 00:16:48 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 84503B4FB1451654E9CC; Sat, 11 Apr 2020 12:16:45 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:35 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 4/9] target/riscv: Implement kvm_arch_get_registers Date: Sat, 11 Apr 2020 12:14:22 +0800 Message-ID: <20200411041427.14828-5-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Get GPR CSR and FP registers from kvm by KVM_GET_ONE_REG ioctl. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- target/riscv/kvm.c | 144 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 3e8f8e7185..8d5069b9e9 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -50,13 +50,155 @@ static __u64 kvm_riscv_reg_id(__u64 type, __u64 idx) return id; } =20 +#define RISCV_CORE_REG(name) kvm_riscv_reg_id(KVM_REG_RISCV_CORE, \ + KVM_REG_RISCV_CORE_REG(name)) + +#define RISCV_CSR_REG(name) kvm_riscv_reg_id(KVM_REG_RISCV_CSR, \ + KVM_REG_RISCV_CSR_REG(name)) + +#define RISCV_FP_F_REG(idx) kvm_riscv_reg_id(KVM_REG_RISCV_FP_F, idx) + +#define RISCV_FP_D_REG(idx) kvm_riscv_reg_id(KVM_REG_RISCV_FP_D, idx) + +static int kvm_riscv_get_regs_core(CPUState *cs) +{ + int ret =3D 0; + int i; + uint64_t reg; + CPURISCVState *env =3D &RISCV_CPU(cs)->env; + + ret =3D kvm_get_one_reg(cs, RISCV_CORE_REG(regs.pc), ®); + if (ret) { + return ret; + } + env->pc =3D reg; + + for (i =3D 1; i < 32; i++) { + __u64 id =3D kvm_riscv_reg_id(KVM_REG_RISCV_CORE, i); + ret =3D kvm_get_one_reg(cs, id, ®); + if (ret) { + return ret; + } + env->gpr[i] =3D reg; + } + + return ret; +} + +static int kvm_riscv_get_regs_csr(CPUState *cs) +{ + int ret =3D 0; + uint64_t reg; + CPURISCVState *env =3D &RISCV_CPU(cs)->env; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(sstatus), ®); + if (ret) { + return ret; + } + env->mstatus =3D reg; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(sie), ®); + if (ret) { + return ret; + } + env->mie =3D reg; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(stvec), ®); + if (ret) { + return ret; + } + env->stvec =3D reg; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(sscratch), ®); + if (ret) { + return ret; + } + env->sscratch =3D reg; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(sepc), ®); + if (ret) { + return ret; + } + env->sepc =3D reg; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(scause), ®); + if (ret) { + return ret; + } + env->scause =3D reg; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(sip), ®); + if (ret) { + return ret; + } + env->mip =3D reg; + + ret =3D kvm_get_one_reg(cs, RISCV_CSR_REG(sstatus), ®); + if (ret) { + return ret; + } + env->satp =3D reg; + + return ret; +} + +static int kvm_riscv_get_regs_fp(CPUState *cs) +{ + int ret =3D 0; + int i; + CPURISCVState *env =3D &RISCV_CPU(cs)->env; + + if (riscv_has_ext(env, RVD)) { + uint64_t reg; + for (i =3D 0; i < 32; i++) { + ret =3D kvm_get_one_reg(cs, RISCV_FP_D_REG(i), ®); + if (ret) { + return ret; + } + env->fpr[i] =3D reg; + } + return ret; + } + + if (riscv_has_ext(env, RVF)) { + uint32_t reg; + for (i =3D 0; i < 32; i++) { + ret =3D kvm_get_one_reg(cs, RISCV_FP_F_REG(i), ®); + if (ret) { + return ret; + } + env->fpr[i] =3D reg; + } + return ret; + } + + return ret; +} + const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { KVM_CAP_LAST_INFO }; =20 int kvm_arch_get_registers(CPUState *cs) { - return 0; + int ret =3D 0; + + ret =3D kvm_riscv_get_regs_core(cs); + if (ret) { + return ret; + } + + ret =3D kvm_riscv_get_regs_csr(cs); + if (ret) { + return ret; + } + + ret =3D kvm_riscv_get_regs_fp(cs); + if (ret) { + return ret; + } + + return ret; } =20 int kvm_arch_put_registers(CPUState *cs, int level) --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578737; cv=none; d=zohomail.com; s=zohoarc; b=E4cmkrhsZ11oAMjIDCMqzQM9GSRKdTBH+fwUJYZ24Tw+6nNCE07OZe+bQDSMm6YCjzEhAnXV+UKNc+QWxg3mIXiPfKEjJWNo5x+0y8eCUpYRbEDtsNJrmVniWbwpfID5qxBGlCG3IoNEoFX20jVELNjBQvqO+xT3atqd0E/FNMw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578737; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ixVALvqzbO7DYwmyQSwNzLr4DZILWBXUEEe6f7ntUJI=; b=M/zfgpOoZZRjsPn1Jzudw0iVYUUCJMMSsh+n+9X8VPzMRexsbW6NyNvBwGDfuazjIA73bnT2V3dg/yl4wtKPpJ2BO3g830QP8jAQ48Et270AN+sqXIOeF4yUEOpQfR16wcd9l7oTwh1fNTTNVJQSTq8pEiQuTjVrMkB33M9QWLk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578737161229.36048313145795; Fri, 10 Apr 2020 21:18:57 -0700 (PDT) Received: from localhost ([::1]:48582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7bZ-0004mG-V2 for importer@patchew.org; Sat, 11 Apr 2020 00:18:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47112) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7ZZ-0000GN-Se for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZY-0006Um-HE for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:49 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43780 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZY-0006ON-5X; Sat, 11 Apr 2020 00:16:48 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 785A0AB817DB17D5CBE4; Sat, 11 Apr 2020 12:16:45 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:36 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 5/9] target/riscv: Implement kvm_arch_put_registers Date: Sat, 11 Apr 2020 12:14:23 +0800 Message-ID: <20200411041427.14828-6-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Put GPR CSR and FP registers to kvm by KVM_SET_ONE_REG ioctl Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- target/riscv/kvm.c | 136 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 8d5069b9e9..6dffda36bb 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -85,6 +85,31 @@ static int kvm_riscv_get_regs_core(CPUState *cs) return ret; } =20 +static int kvm_riscv_put_regs_core(CPUState *cs) +{ + int ret =3D 0; + int i; + uint64_t reg; + CPURISCVState *env =3D &RISCV_CPU(cs)->env; + + reg =3D env->pc; + ret =3D kvm_set_one_reg(cs, RISCV_CORE_REG(regs.pc), ®); + if (ret) { + return ret; + } + + for (i =3D 1; i < 32; i++) { + __u64 id =3D kvm_riscv_reg_id(KVM_REG_RISCV_CORE, i); + reg =3D env->gpr[i]; + ret =3D kvm_set_one_reg(cs, id, ®); + if (ret) { + return ret; + } + } + + return ret; +} + static int kvm_riscv_get_regs_csr(CPUState *cs) { int ret =3D 0; @@ -142,6 +167,64 @@ static int kvm_riscv_get_regs_csr(CPUState *cs) return ret; } =20 +static int kvm_riscv_put_regs_csr(CPUState *cs) +{ + int ret =3D 0; + uint64_t reg; + CPURISCVState *env =3D &RISCV_CPU(cs)->env; + + reg =3D env->mstatus; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(sstatus), ®); + if (ret) { + return ret; + } + + reg =3D env->mie; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(sie), ®); + if (ret) { + return ret; + } + + reg =3D env->stvec; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(stvec), ®); + if (ret) { + return ret; + } + + reg =3D env->sscratch; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(sscratch), ®); + if (ret) { + return ret; + } + + reg =3D env->sepc; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(sepc), ®); + if (ret) { + return ret; + } + + reg =3D env->scause; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(scause), ®); + if (ret) { + return ret; + } + + reg =3D env->mip; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(sip), ®); + if (ret) { + return ret; + } + + reg =3D env->satp; + ret =3D kvm_set_one_reg(cs, RISCV_CSR_REG(sstatus), ®); + if (ret) { + return ret; + } + + return ret; +} + + static int kvm_riscv_get_regs_fp(CPUState *cs) { int ret =3D 0; @@ -175,6 +258,40 @@ static int kvm_riscv_get_regs_fp(CPUState *cs) return ret; } =20 +static int kvm_riscv_put_regs_fp(CPUState *cs) +{ + int ret =3D 0; + int i; + CPURISCVState *env =3D &RISCV_CPU(cs)->env; + + if (riscv_has_ext(env, RVD)) { + uint64_t reg; + for (i =3D 0; i < 32; i++) { + reg =3D env->fpr[i]; + ret =3D kvm_set_one_reg(cs, RISCV_FP_D_REG(i), ®); + if (ret) { + return ret; + } + } + return ret; + } + + if (riscv_has_ext(env, RVF)) { + uint32_t reg; + for (i =3D 0; i < 32; i++) { + reg =3D env->fpr[i]; + ret =3D kvm_set_one_reg(cs, RISCV_FP_F_REG(i), ®); + if (ret) { + return ret; + } + } + return ret; + } + + return ret; +} + + const KVMCapabilityInfo kvm_arch_required_capabilities[] =3D { KVM_CAP_LAST_INFO }; @@ -203,7 +320,24 @@ int kvm_arch_get_registers(CPUState *cs) =20 int kvm_arch_put_registers(CPUState *cs, int level) { - return 0; + int ret =3D 0; + + ret =3D kvm_riscv_put_regs_core(cs); + if (ret) { + return ret; + } + + ret =3D kvm_riscv_put_regs_csr(cs); + if (ret) { + return ret; + } + + ret =3D kvm_riscv_put_regs_fp(cs); + if (ret) { + return ret; + } + + return ret; } =20 int kvm_arch_release_virq_post(int virq) --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578864; cv=none; d=zohomail.com; s=zohoarc; b=OhyYYmM/75dqKe0QYmJCflwtudvYsLgXkXKkVHArnCpTTVKG+JX02fV9BFgXcZqSwx30iIZcS714EzjxuCwCyzvg7FHbRNAXljX/nCE2s7M0aSF/o5pyRrYkOVZAtnbFO9vPbfTYuJ3VpflPe9yx9HGekoz5sZE0ewxxXOrAD3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578864; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X9qHlozBhczTd4Iah3CqgaWyaxszJQIALF+s78tZL7w=; b=dcESSfpYY6ub3+ZPqO9DS5oztkJn0/2mRDKXd95ZiTNE7G/30KuPCoRomPdzculbuXC5OhW8u+tRNWebbXjNhxI9/sknHD3D8XnmpmDHLvF5gt3sdcvaM/H6u1adf8X6aNWcEVKUzba+UkTo9BBacV344/tF0h/H86UtB5jcib0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578864068978.7637296567204; Fri, 10 Apr 2020 21:21:04 -0700 (PDT) Received: from localhost ([::1]:48622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7de-0008Vp-To for importer@patchew.org; Sat, 11 Apr 2020 00:21:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47101) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7ZZ-0000FW-E7 for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZX-0006Rw-V2 for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:49 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3743 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZX-0006OQ-KU; Sat, 11 Apr 2020 00:16:47 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id AB30B18C808FAF5A511A; Sat, 11 Apr 2020 12:16:45 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:36 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 6/9] target/riscv: Support start kernel directly by KVM Date: Sat, 11 Apr 2020 12:14:24 +0800 Message-ID: <20200411041427.14828-7-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Get kernel and fdt start address in virt.c, and pass them to KVM when cpu reset. In addition, add kvm_riscv.h to place riscv specific interface. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- hw/riscv/virt.c | 16 +++++++++++++--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 3 +++ target/riscv/kvm.c | 14 ++++++++++++++ target/riscv/kvm_riscv.h | 24 ++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 target/riscv/kvm_riscv.h diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 85ec9e22aa..d72eb782e4 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -42,6 +42,7 @@ #include "exec/address-spaces.h" #include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" +#include "sysemu/kvm.h" =20 #include =20 @@ -480,6 +481,9 @@ static void riscv_virt_board_init(MachineState *machine) target_ulong start_addr =3D memmap[VIRT_DRAM].base; int i; unsigned int smp_cpus =3D machine->smp.cpus; + uint64_t kernel_entry =3D 0; + hwaddr start_fdt; + CPUState *cs; =20 /* Initialize SOC */ object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc= ), @@ -510,8 +514,7 @@ static void riscv_virt_board_init(MachineState *machine) memmap[VIRT_DRAM].base); =20 if (machine->kernel_filename) { - uint64_t kernel_entry =3D riscv_load_kernel(machine->kernel_filena= me, - NULL); + kernel_entry =3D riscv_load_kernel(machine->kernel_filename, NULL); =20 if (machine->initrd_filename) { hwaddr start; @@ -564,10 +567,17 @@ static void riscv_virt_board_init(MachineState *machi= ne) exit(1); } qemu_fdt_dumpdtb(s->fdt, fdt_totalsize(s->fdt)); + start_fdt =3D memmap[VIRT_MROM].base + sizeof(reset_vec); rom_add_blob_fixed_as("mrom.fdt", s->fdt, fdt_totalsize(s->fdt), - memmap[VIRT_MROM].base + sizeof(reset_vec), + start_fdt, &address_space_memory); =20 + for (cs =3D first_cpu; cs; cs =3D CPU_NEXT(cs)) { + RISCVCPU *riscv_cpu =3D RISCV_CPU(cs); + riscv_cpu->env.loader_start =3D kernel_entry; + riscv_cpu->env.fdt_start =3D start_fdt; + } + /* create PLIC hart topology configuration string */ plic_hart_config_len =3D (strlen(VIRT_PLIC_HART_CONFIG) + 1) * smp_cpu= s; plic_hart_config =3D g_malloc0(plic_hart_config_len); diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4e578239d3..6a6af13ab9 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -28,6 +28,7 @@ #include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "fpu/softfloat-helpers.h" +#include "kvm_riscv.h" =20 /* RISC-V CPU definitions */ =20 @@ -347,6 +348,9 @@ static void riscv_cpu_reset(DeviceState *dev) cs->exception_index =3D EXCP_NONE; env->load_res =3D -1; set_default_nan_mode(1, &env->fp_status); +#ifdef CONFIG_KVM + kvm_riscv_reset_vcpu(cpu); +#endif } =20 static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7d21addbab..dcff112c5f 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -213,6 +213,9 @@ struct CPURISCVState { =20 /* Fields from here on are preserved across CPU reset. */ QEMUTimer *timer; /* Internal timer */ + + hwaddr loader_start; + hwaddr fdt_start; }; =20 #define RISCV_CPU_CLASS(klass) \ diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 6dffda36bb..b9aec66b69 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -37,6 +37,7 @@ #include "hw/irq.h" #include "qemu/log.h" #include "hw/loader.h" +#include "kvm_riscv.h" =20 static __u64 kvm_riscv_reg_id(__u64 type, __u64 idx) { @@ -426,3 +427,16 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run = *run) { return 0; } + +void kvm_riscv_reset_vcpu(RISCVCPU *cpu) +{ + CPURISCVState *env =3D &cpu->env; + + if (!kvm_enabled()) { + return; + } + env->pc =3D cpu->env.loader_start; + env->gpr[10] =3D kvm_arch_vcpu_id(CPU(cpu)); /* a0 */ + env->gpr[11] =3D cpu->env.fdt_start; /* a1 */ +} + diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h new file mode 100644 index 0000000000..f38c82bf59 --- /dev/null +++ b/target/riscv/kvm_riscv.h @@ -0,0 +1,24 @@ +/* + * QEMU KVM support -- RISC-V specific functions. + * + * Copyright (c) 2020 Huawei Technologies Co., Ltd + * + * 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 or later, 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 f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#ifndef QEMU_KVM_RISCV_H +#define QEMU_KVM_RISCV_H + +void kvm_riscv_reset_vcpu(RISCVCPU *cpu); + +#endif --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578800; cv=none; d=zohomail.com; s=zohoarc; b=D3b/MiO1hpbFtwI40j8NfosBUmvTMwfkZGBu25kWa/DIFP+XiQ9Kln5suWqvaLT1q6lCe/1B+Y+CSo6ahZFZaHm68s8xg7vLvID9c8VD5lWwzgcHWY8YyoalfrUfLmPtDgDT+n6Impmy9nTxpgppcKFoZMVRsATxfJ+od5twnKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578800; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VpEnWU3/YCobi2vdfwbsLfsKyOkSiMzAutS6Xmadsf8=; b=CYObnpJjjhKVUAcmI7V2Uhf82ejHPbosJzxCiTgvu1qlTZLMrI803tkVPC11lZhv+UYiTN8HJLEq94W5Q8/J6oKHiSZZcp77DtcmczosIbEzqoVJyEayXxYVq8+bh/4v9W8bVk222UDzsxPHi62Zjq6cTe7Gk8jENds78wtrJpk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578800348610.0771815885677; Fri, 10 Apr 2020 21:20:00 -0700 (PDT) Received: from localhost ([::1]:48596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7cd-0006Oh-6h for importer@patchew.org; Sat, 11 Apr 2020 00:19:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47144) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7Zb-0000Iu-Fh for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7Za-0006X8-Fh for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:51 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43860 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZZ-0006Pd-3W; Sat, 11 Apr 2020 00:16:50 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8FF71AD7F755C0AA5FD1; Sat, 11 Apr 2020 12:16:45 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:37 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 7/9] hw/riscv: PLIC update external interrupt by KVM when kvm enabled Date: Sat, 11 Apr 2020 12:14:25 +0800 Message-ID: <20200411041427.14828-8-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Only support supervisor external interrupt currently. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- hw/riscv/sifive_plic.c | 31 ++++++++++++++++++++++--------- target/riscv/kvm.c | 19 +++++++++++++++++++ target/riscv/kvm_riscv.h | 1 + 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/hw/riscv/sifive_plic.c b/hw/riscv/sifive_plic.c index c1e04cbb98..ff5c18ed20 100644 --- a/hw/riscv/sifive_plic.c +++ b/hw/riscv/sifive_plic.c @@ -29,6 +29,8 @@ #include "target/riscv/cpu.h" #include "sysemu/sysemu.h" #include "hw/riscv/sifive_plic.h" +#include "sysemu/kvm.h" +#include "kvm_riscv.h" =20 #define RISCV_DEBUG_PLIC 0 =20 @@ -145,15 +147,26 @@ static void sifive_plic_update(SiFivePLICState *plic) continue; } int level =3D sifive_plic_irqs_pending(plic, addrid); - switch (mode) { - case PLICMode_M: - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(le= vel)); - break; - case PLICMode_S: - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_SEIP, BOOL_TO_MASK(le= vel)); - break; - default: - break; + if (kvm_enabled()) { + if (mode =3D=3D PLICMode_M) { + continue; + } +#ifdef CONFIG_KVM + kvm_riscv_set_irq(RISCV_CPU(cpu), IRQ_S_EXT, level); +#endif + } else { + switch (mode) { + case PLICMode_M: + riscv_cpu_update_mip(RISCV_CPU(cpu), + MIP_MEIP, BOOL_TO_MASK(level)); + break; + case PLICMode_S: + riscv_cpu_update_mip(RISCV_CPU(cpu), + MIP_SEIP, BOOL_TO_MASK(level)); + break; + default: + break; + } } } =20 diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index b9aec66b69..0f429fd802 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -440,3 +440,22 @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu) env->gpr[11] =3D cpu->env.fdt_start; /* a1 */ } =20 +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level) +{ + int ret; + unsigned virq =3D level ? KVM_INTERRUPT_SET : KVM_INTERRUPT_UNSET; + + if (irq !=3D IRQ_S_EXT) { + return; + } + + if (!kvm_enabled()) { + return; + } + + ret =3D kvm_vcpu_ioctl(CPU(cpu), KVM_INTERRUPT, &virq); + if (ret < 0) { + perror("Set irq failed"); + abort(); + } +} diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h index f38c82bf59..ed281bdce0 100644 --- a/target/riscv/kvm_riscv.h +++ b/target/riscv/kvm_riscv.h @@ -20,5 +20,6 @@ #define QEMU_KVM_RISCV_H =20 void kvm_riscv_reset_vcpu(RISCVCPU *cpu); +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); =20 #endif --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578828; cv=none; d=zohomail.com; s=zohoarc; b=NPXdjn9y3na/OaffNAk6UwM9m3pLiFaA4korGEFxL2Jy7D38tXqazc2pwFanVUg9LWek/O4Yu2i7bJOkgMtBDWFb3ajG2dVWQ76spEgHWCTVPE7srKP8KsLvRubXkYokZs7zAeeyqHeqXlLxlFTDNwx90UcoaJ7nzoyT7EOCkvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578828; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o5vXH5YrW96z23kLe0BITE2qS6gGsR8NMu6JEd2ML1A=; b=i8D0BYGnQQW9+1guzHFiGFg1biMXncPSDVommUXljJXlY1kKcmlgmY+ZKHV8X2jinrjrWyVw0SyyTcIHGNk1LoBpOh8CafytGWEv6zOuIWZi6UsixWjUMtYxbytUkyXcuIAyYZ7HlHa/wMeHZb63FcywjrWtuOET8bL2pHWif2M= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586578828774584.5631399916239; Fri, 10 Apr 2020 21:20:28 -0700 (PDT) Received: from localhost ([::1]:48598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7d5-00078u-JB for importer@patchew.org; Sat, 11 Apr 2020 00:20:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47139) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7Zb-0000IG-B8 for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZY-0006VL-Qi for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:50 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43850 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZY-0006Oj-En; Sat, 11 Apr 2020 00:16:48 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 89F88E4D640B17DDB427; Sat, 11 Apr 2020 12:16:45 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:38 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 8/9] target/riscv: Handler KVM_EXIT_RISCV_SBI exit Date: Sat, 11 Apr 2020 12:14:26 +0800 Message-ID: <20200411041427.14828-9-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use char-fe handler console sbi call, which implement early console io while apply 'earlycon=3Dsbi' into kernel parameters. The common SBI interface sbi_ecall_interface.h is introduced from https://github.com/riscv/opensbi/blob/master/include/sbi/sbi_ecall_interfac= e.h. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- target/riscv/kvm.c | 42 ++++++++++++++++- target/riscv/sbi_ecall_interface.h | 72 ++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 target/riscv/sbi_ecall_interface.h diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index 0f429fd802..ff6ea7816e 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -38,6 +38,8 @@ #include "qemu/log.h" #include "hw/loader.h" #include "kvm_riscv.h" +#include "sbi_ecall_interface.h" +#include "chardev/char-fe.h" =20 static __u64 kvm_riscv_reg_id(__u64 type, __u64 idx) { @@ -423,9 +425,47 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) return true; } =20 +static int kvm_riscv_handle_sbi(struct kvm_run *run) +{ + int ret =3D 0; + unsigned char ch; + switch (run->riscv_sbi.extension_id) { + case SBI_EXT_0_1_CONSOLE_PUTCHAR: + ch =3D run->riscv_sbi.args[0]; + qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch)); + break; + case SBI_EXT_0_1_CONSOLE_GETCHAR: + ret =3D qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch)); + if (ret =3D=3D sizeof(ch)) { + run->riscv_sbi.args[0] =3D ch; + } else { + run->riscv_sbi.args[0] =3D -1; + } + break; + default: + qemu_log_mask(LOG_UNIMP, + "%s: un-handled SBI EXIT, specific reasons is %lu\n", + __func__, run->riscv_sbi.extension_id); + ret =3D -1; + break; + } + return ret; +} + int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) { - return 0; + int ret =3D 0; + switch (run->exit_reason) { + case KVM_EXIT_RISCV_SBI: + ret =3D kvm_riscv_handle_sbi(run); + break; + default: + qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", + __func__, run->exit_reason); + ret =3D -1; + break; + } + return ret; } =20 void kvm_riscv_reset_vcpu(RISCVCPU *cpu) diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_in= terface.h new file mode 100644 index 0000000000..225dcd42b1 --- /dev/null +++ b/target/riscv/sbi_ecall_interface.h @@ -0,0 +1,72 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + */ + +#ifndef __SBI_ECALL_INTERFACE_H__ +#define __SBI_ECALL_INTERFACE_H__ + +/* clang-format off */ + +/* SBI Extension IDs */ +#define SBI_EXT_0_1_SET_TIMER 0x0 +#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 +#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 +#define SBI_EXT_0_1_CLEAR_IPI 0x3 +#define SBI_EXT_0_1_SEND_IPI 0x4 +#define SBI_EXT_0_1_REMOTE_FENCE_I 0x5 +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA 0x6 +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID 0x7 +#define SBI_EXT_0_1_SHUTDOWN 0x8 +#define SBI_EXT_BASE 0x10 +#define SBI_EXT_TIME 0x54494D45 +#define SBI_EXT_IPI 0x735049 +#define SBI_EXT_RFENCE 0x52464E43 +#define SBI_EXT_HSM 0x48534D + +/* SBI function IDs for BASE extension*/ +#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 +#define SBI_EXT_BASE_GET_IMP_ID 0x1 +#define SBI_EXT_BASE_GET_IMP_VERSION 0x2 +#define SBI_EXT_BASE_PROBE_EXT 0x3 +#define SBI_EXT_BASE_GET_MVENDORID 0x4 +#define SBI_EXT_BASE_GET_MARCHID 0x5 +#define SBI_EXT_BASE_GET_MIMPID 0x6 + +/* SBI function IDs for TIME extension*/ +#define SBI_EXT_TIME_SET_TIMER 0x0 + +/* SBI function IDs for IPI extension*/ +#define SBI_EXT_IPI_SEND_IPI 0x0 + +/* SBI function IDs for RFENCE extension*/ +#define SBI_EXT_RFENCE_REMOTE_FENCE_I 0x0 +#define SBI_EXT_RFENCE_REMOTE_SFENCE_VMA 0x1 +#define SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID 0x2 +#define SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA 0x3 +#define SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID 0x4 +#define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA 0x5 +#define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID 0x6 + +/* SBI function IDs for HSM extension */ +#define SBI_EXT_HSM_HART_START 0x0 +#define SBI_EXT_HSM_HART_STOP 0x1 +#define SBI_EXT_HSM_HART_GET_STATUS 0x2 + +#define SBI_HSM_HART_STATUS_STARTED 0x0 +#define SBI_HSM_HART_STATUS_STOPPED 0x1 +#define SBI_HSM_HART_STATUS_START_PENDING 0x2 +#define SBI_HSM_HART_STATUS_STOP_PENDING 0x3 + +#define SBI_SPEC_VERSION_MAJOR_OFFSET 24 +#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f +#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff +#define SBI_EXT_VENDOR_START 0x09000000 +#define SBI_EXT_VENDOR_END 0x09FFFFFF +/* clang-format on */ + +#endif --=20 2.19.1 From nobody Mon Feb 9 15:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1586578733; cv=none; d=zohomail.com; s=zohoarc; b=JkWApZIjKL/NTVoioCTPBwTZJ5zjLKH71NyE+h+/35cFfqG/o8vnvwAznNz20qicoNo0COBIZUwndcv0a4HLQ+Zuzho/efGiSH547Ndnb4J7mw/4+jgU96QtfkI4muHpq/Nmm9L3cMSviNvXAvpa6qUI00Cv2H8K1KAkUjBFmxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586578733; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y6mN4EK+/UJUtIMhKfvMCOAI8q+po/AQ7oNo/O7qm0Q=; b=DSiBJwF/UGuPNqMmz0X2Wos1Czge+BEQ00D4IDJmnkRFU9Bcf358IUTBPJAp7wD2Szj9RAqWXWD/klqE+jZnoJv6M/iMF1sHeLb9HXpWjz3NVrOvw8WdfqsrpgdFhqgVMyFKLcmPiN0rxbqt8zcpwRh3A810Q/wBViLqyne6EiI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15865787333841017.1358159224013; Fri, 10 Apr 2020 21:18:53 -0700 (PDT) Received: from localhost ([::1]:48580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7bX-0004iR-66 for importer@patchew.org; Sat, 11 Apr 2020 00:18:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47115) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jN7ZZ-0000GT-Tv for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jN7ZY-0006VR-Qs for qemu-devel@nongnu.org; Sat, 11 Apr 2020 00:16:49 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43826 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jN7ZY-0006OO-FO; Sat, 11 Apr 2020 00:16:48 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7F044A2A2B3C4F1BD898; Sat, 11 Apr 2020 12:16:45 +0800 (CST) Received: from huawei.com (10.173.222.107) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 11 Apr 2020 12:16:39 +0800 From: Yifei Jiang To: , Subject: [PATCH RFC v2 9/9] target/riscv: add host cpu type Date: Sat, 11 Apr 2020 12:14:27 +0800 Message-ID: <20200411041427.14828-10-jiangyifei@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com> References: <20200411041427.14828-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.222.107] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com, sagark@eecs.berkeley.edu, yinyipeng1@huawei.com, kbastian@mail.uni-paderborn.de, anup.patel@wdc.com, Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org, palmer@dabbelt.com, Yifei Jiang , dengkai1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, host cpu is inherited simply. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- target/riscv/cpu.c | 6 ++++++ target/riscv/cpu.h | 1 + 2 files changed, 7 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 6a6af13ab9..e5b42c3a54 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -203,6 +203,10 @@ static void rv64imacu_nommu_cpu_init(Object *obj) set_feature(env, RISCV_FEATURE_PMP); } =20 +static void riscv_host_cpu_init(Object *obj) +{ +} + #endif =20 static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) @@ -615,6 +619,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { DEFINE_CPU(TYPE_RISCV_CPU_BASE32, riscv_base32_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rv32imacu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32gcsu_priv1_10_0_cpu_in= it), + DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init), /* Depreacted */ DEFINE_CPU(TYPE_RISCV_CPU_RV32IMACU_NOMMU, rv32imacu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_RV32GCSU_V1_09_1, rv32gcsu_priv1_09_1_cpu_in= it), @@ -623,6 +628,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { DEFINE_CPU(TYPE_RISCV_CPU_BASE64, riscv_base64_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64imacu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64gcsu_priv1_10_0_cpu_in= it), + DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init), /* Deprecated */ DEFINE_CPU(TYPE_RISCV_CPU_RV64IMACU_NOMMU, rv64imacu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_RV64GCSU_V1_09_1, rv64gcsu_priv1_09_1_cpu_in= it), diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index dcff112c5f..4901fd8061 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -39,6 +39,7 @@ #define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51") #define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34") #define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54") +#define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host") /* Deprecated */ #define TYPE_RISCV_CPU_RV32IMACU_NOMMU RISCV_CPU_TYPE_NAME("rv32imacu-nom= mu") #define TYPE_RISCV_CPU_RV32GCSU_V1_09_1 RISCV_CPU_TYPE_NAME("rv32gcsu-v1.9= .1") --=20 2.19.1