From nobody Sat May 18 10:07:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1684418951; cv=none; d=zohomail.com; s=zohoarc; b=PrJZKlmbiB2H+cAUT0Lokwb+HLeZM0fvyHZpD+C4AkyRfecB0WJXGkmfkpE3HrnSpZibNSRo7UvEqF/MJa0lDpJW2Ikafwb2lrmLRCtQUnNORX1n+tFfi7eIw5nzPOAszF8MyyrFJ5EZbKUh8c73WKkkSzd9m8v3iy88+y/YxZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684418951; h=Content-Transfer-Encoding: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=6hpOmi46xQ4MApQ9wmEcpNEs40K4g7mIrpG+eIQXr1g=; b=LwA/yKtvGr+5btYOruPiLpcYnrl4TOvaFeQWAGCYTcTIlotiJfUtmSfnh6hVHu4qVg8xe1fZvSnaX38xFOsqaoZyrt4FfG98h96wk81D0KG0WEDKVtonfGOkrex8hHNFxcKFgl0ZdGJdsRJWn5EvNoWhwX2n8zyGkxx9BUE/+Ik= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1684418951012479.17789191624195; Thu, 18 May 2023 07:09:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzdlM-0006MJ-Uo; Thu, 18 May 2023 09:33:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzbyl-0000CH-Hz for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:32 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzbyi-0002Vp-6F for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:29 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f41dceb9caso7770945e9.0 for ; Thu, 18 May 2023 04:39:26 -0700 (PDT) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id p6-20020a1c7406000000b003f4272c2d10sm5083982wmc.1.2023.05.18.04.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 04:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1684409966; x=1687001966; 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=6hpOmi46xQ4MApQ9wmEcpNEs40K4g7mIrpG+eIQXr1g=; b=Rwg+E2ykP7uQWb/9mJPWOcSnAYMgi1gsk4b2TIYaWJ/NheB3iMvSh5YCyLEKY8UBJQ W8AEjI/vml6Xra0CA5zbOgbpAF1roXPqLT5MjcK92LRfRXF+q8S+LWDEacHISPSirzZZ 3Kj/iNzrez55coWskp9nb2AEpLmlH03sGPVhVbvGl+1rAX+SrWsKOVN9bAEw6mqMd4nr IIIt8lAk3rhL4ATAUB5hpx7XYpHDUtXnQkfPs7I2WTeypZmv7tHS6HNEJoOZvkkaRzpZ g2d06W+iHW9gqE9/M386yASzdmbN+spoc4kK90gdMrhwHEOreSBcdRN/QzAdXPzlIsbj ZOsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684409966; x=1687001966; 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=6hpOmi46xQ4MApQ9wmEcpNEs40K4g7mIrpG+eIQXr1g=; b=kFTjc4ge+5mj8wIcmUGE90fJGWOq6v7Ln+NuO+RzKFokjZafj8B2rIcPK2T1QHxo4y UpxVCr2Hl5gX3IzCxzmgbbr7cnMyPuuYQd9EmN17cHKXmRB2/VwlDBUG0Xw1YTAZya2a PNJwOP8gKTSFuyZ3b3rgVR2K1FJ8WefDNuYLvDOjHg7GsL17z2bKS6BDXtjRERopkrO7 fvfu4A2FCvBoyFT+SEk0S2/zEiAS2eDdhlCMN95KMvsU2csvQYiosYncOsUmF+AvvzC7 BBj4EgbjDBDV8FUqCacJluML/gahdEY35cI1FlbQKCIoBDMGIAT/1Gt7mttQ6xxC094x C7yg== X-Gm-Message-State: AC+VfDw8TlJd9XNv9AoNdGeUkLKZte4ej0l7GFWsfJoGmXWQvQmarIfB 9omkehiCv/rKsQXFK3jNw8kZHQ== X-Google-Smtp-Source: ACHHUZ5TkVQDU4xp/HZ2GzRywz/ATw8maVSaQ42HdPmih5pHFXHR0DH3eQbyJKP/bpE0E7WNKlxiKQ== X-Received: by 2002:a05:600c:35d1:b0:3f4:255e:e375 with SMTP id r17-20020a05600c35d100b003f4255ee375mr1288480wmq.9.1684409965879; Thu, 18 May 2023 04:39:25 -0700 (PDT) From: Rajnesh Kanwal To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, atishp@rivosinc.com, apatel@ventanamicro.com, Rajnesh Kanwal Subject: [PATCH 1/6] target/riscv: Without H-mode mask all HS mode inturrupts in mie. Date: Thu, 18 May 2023 12:38:33 +0100 Message-Id: <20230518113838.130084-2-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518113838.130084-1-rkanwal@rivosinc.com> References: <20230518113838.130084-1-rkanwal@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=rkanwal@rivosinc.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 18 May 2023 09:33:46 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1684418951621100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Rajnesh Kanwal --- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 4451bd1263..041f0b3e2e 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1522,7 +1522,7 @@ static RISCVException rmw_mie64(CPURISCVState *env, i= nt csrno, env->mie =3D (env->mie & ~mask) | (new_val & mask); =20 if (!riscv_has_ext(env, RVH)) { - env->mie &=3D ~((uint64_t)MIP_SGEIP); + env->mie &=3D ~((uint64_t)HS_MODE_INTERRUPTS); } =20 return RISCV_EXCP_NONE; --=20 2.25.1 From nobody Sat May 18 10:07:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1684417072; cv=none; d=zohomail.com; s=zohoarc; b=hUn4DzeqtvjB0+/a5hbl6MAvPJFvyhpWHAn1NlHYY+XU62UH2uIxFM1qMxuW5qBaZXWrnyDSNL24MbmDppmIVZm7Ddv10KpIl7J3gpMMc8fYsBYIHgII7SdjUgM9SaVsozXJG/0SiSyu7FPGbGywAYrrsfJknwDxgnp9ePZ9iEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684417072; h=Content-Transfer-Encoding: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=7RMufLVcnImVuRlhef+rldQbtlOp58Wd3G7oPLW1EL4=; b=ddC2UhcVaPInCtNN1DWJcCObCBApvoUy1jJFzH8Ra42H2hSaL29WOuhPxOgq30LsVwv4OtPuxzlg6+iTyGqmKkEAbtMf2XT4DOz7FSyFTZ2sB3p5h7P+aHuunpEM8uSCWGrh6LNX5afPRZ0L4VB0l2SXxxlRbPz4/XHsk/dpyDs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1684417072818919.7859134486615; Thu, 18 May 2023 06:37:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzdlL-0006Iz-NO; Thu, 18 May 2023 09:33:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzbyl-0000CF-GU for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:32 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzbyi-0002WC-EJ for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:30 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f435658d23so18693145e9.3 for ; Thu, 18 May 2023 04:39:28 -0700 (PDT) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id p6-20020a1c7406000000b003f4272c2d10sm5083982wmc.1.2023.05.18.04.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 04:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1684409967; x=1687001967; 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=7RMufLVcnImVuRlhef+rldQbtlOp58Wd3G7oPLW1EL4=; b=5FL+3CKXVELaXh/rt3PAA479sqtRGHpLQpOnkpGhygXawXKQ0LaN5tY7n8dU7CGJ2p c4PtKSc6vsC7zhalBqeKnwmr+CLHN4SKZ7EyZZToRBJP7ktDhhKbotuh043kIDbFglsY QgblbO6w6I8URschJpgpiAUxJP2Qknnh4l0+ksDc/ovyhSggS8Vksgzjx9X4ZhFNykcW /Y7nov8SNGCiiUQ2xDc7LQjCT8aFW0X7FnJ86eDstBQZTvV9enT1RHWv4AdedRj4hFg8 fqb2QJ7j7vulgWGhEV1e6rdYO4iMo203BV2E7LKUMw+QyWYcwxr6feKPDq7kYzHxsHq+ nY+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684409967; x=1687001967; 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=7RMufLVcnImVuRlhef+rldQbtlOp58Wd3G7oPLW1EL4=; b=U8K+w8vyvgYS8SWKD4+1v2xJ8aXakaD308hdD/2JHXMGPoXlGtBZ61gJ6bmzK4w+xB ldVIHlBxWZRAIbgiLtwEE7OEJbzMgDiU19TKgiOkXZTfL1ft9aksjDgFG89CWlqxWv5+ J3uTM4ZO1OxRL76ItbGIsudu43UmJUiHIbpj9PZoYKXllggmNgLQvsQywriupvXx8mE5 VVS6Wr6756GXS55+17rMX9X3YjyGxqXe6YzFi/Pz+l7vgVC8Xba94ppGeroaqKQ1Tzrw +uxf28QPjIHLOs3cexZjrWUahHb0mE8wL8D9XDj3dxatsQ81r8nH6v1kcqPgCCGUQSCp qp2A== X-Gm-Message-State: AC+VfDw2gfi7+TOHTjcAgktm77h+LBYAGLzTE5ewo5MROR9T7ITvG5fq baaEN5zQVNq1c3nxbV/AvypWyA== X-Google-Smtp-Source: ACHHUZ4h8FFljrzvKlb7zxoLglalw8mUA5mOXANmxjHo03HUKOdrUWOH+yQO74RgeV/fmMLQv6jBNw== X-Received: by 2002:a05:600c:ad3:b0:3f5:e7f:5328 with SMTP id c19-20020a05600c0ad300b003f50e7f5328mr1506863wmr.3.1684409966976; Thu, 18 May 2023 04:39:26 -0700 (PDT) From: Rajnesh Kanwal To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, atishp@rivosinc.com, apatel@ventanamicro.com, Rajnesh Kanwal Subject: [PATCH 2/6] target/riscv: Check for async flag in case of RISCV_EXCP_SEMIHOST. Date: Thu, 18 May 2023 12:38:34 +0100 Message-Id: <20230518113838.130084-3-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518113838.130084-1-rkanwal@rivosinc.com> References: <20230518113838.130084-1-rkanwal@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=rkanwal@rivosinc.com; helo=mail-wm1-x332.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 18 May 2023 09:33:46 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1684417074082100001 Content-Type: text/plain; charset="utf-8" RISCV_EXCP_SEMIHOST is set to 0x10, which can also be a local interrupt as well. This change adds a check for async flag before invoking semihosting logic. Signed-off-by: Rajnesh Kanwal --- target/riscv/cpu_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 57d04385f1..c78a2a9514 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1602,7 +1602,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) target_ulong htval =3D 0; target_ulong mtval2 =3D 0; =20 - if (cause =3D=3D RISCV_EXCP_SEMIHOST) { + if (!async && cause =3D=3D RISCV_EXCP_SEMIHOST) { do_common_semihosting(cs); env->pc +=3D 4; return; --=20 2.25.1 From nobody Sat May 18 10:07:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1684417290; cv=none; d=zohomail.com; s=zohoarc; b=CLnNIZKMPesrPJC/SGzNCbpHGySqKrwhKnq3wcqwfHy83H8WM0Nd0sdzz5nS23RIsndNJlZ5rDw/cjzHkeUY7oZKS7xj9q7tdiunea5By4c6AkBoLkSnGqq1733rF9+mugJS/xUaRqe77ib3DEhVFo9cW8yp7zoVqGgDBrQa85k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684417290; h=Content-Transfer-Encoding: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=erus5ABQqsHoSUUKbAryAoIx/sTkHxYWibzmmckFzwE=; b=BPrKrZtdMzrAxrs2n2ZTkXN4rwEg5r0epbN2ZePyMpuH9Z3T41s5aU+Iohi7744KQmzsNyp1iDEizy8p5dfdPeVu+SHmFaNTA5mO/QkcEWjT9lJZzZWR6ej2TDwXuvKmgKvpO1+x7Z46r8uSBFEinprowSh/Zf+YOhEGmgqXIgU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1684417289928716.5307113163834; Thu, 18 May 2023 06:41:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzdlN-0006Mv-VT; Thu, 18 May 2023 09:33:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzbyn-0000Dr-64 for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:33 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzbyl-0002WQ-8G for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:32 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f41dceb9d4so18553435e9.1 for ; Thu, 18 May 2023 04:39:28 -0700 (PDT) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id p6-20020a1c7406000000b003f4272c2d10sm5083982wmc.1.2023.05.18.04.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 04:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1684409968; x=1687001968; 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=erus5ABQqsHoSUUKbAryAoIx/sTkHxYWibzmmckFzwE=; b=mSRulgNf0cd9JOthDyGfjdAeHHAoIjbFh2Rsj8Xn/TDHx2YRjFV+Egeb01e4VV6qa4 W/dS3IpZOAyHoGKlzzgNOBOq8172P2kAjpf44ZgAz3CfQPrSwgwP0BdntQJz1SHYxc9T n+rKJt23LcJF16eaj7Cw6nOYUkA0dnQRRtetvM2LzrtNXucr8dzMOoJBffxpi9GoCtFm 6QE2YFBbNx1EF3Aet1Zn2dRdIDAd/QwCjpjWpCAmgHmtUABT6AC45fjWxAoez+3d/5Md 4XZiDp4+elS8Rx9/C9n5YzDDIEqrHnXBmVZFrMeIlWnGjALTcc/D7B9IvSZzu3nkpKrq FUsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684409968; x=1687001968; 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=erus5ABQqsHoSUUKbAryAoIx/sTkHxYWibzmmckFzwE=; b=UISOWqsoiYHm7+wg4VEepDMJg2xCWHfwT/uMcVVzFLeuDYmHnfOGys9scx6U8Bcwlf eYbtCjpcBGfosqSrifI3lI33/QX6iAi19Z8oXa3cLvJvejVgPE8aceiUkMl58fMmYyKB qmWlKjkQUlty0wX4qzoGLjJWXhhUrGUomakd1CRzy91TqM2MwGzBJ2pP65SCBpdQqVNF E8+3GsDJQFl4QiGAAvumDVATQwCP6jmsM9pN2mGUxMOg6Ll0LOP8ogXD/ofAsoKB1D3T JyQFHjwC7PHjDNcXSkBLNrIqZoylohTHcIs6oJj+QNPVm+oMg3VbuUDRZ6gkfF3DvL4w SMFg== X-Gm-Message-State: AC+VfDyfpdZuTHspn8cFH0k+8bGdtorhBPq62tvHd/IsUO7aS9SU46Y/ WSPm1rIHdEyeQM2yZ9TuLfEdcg== X-Google-Smtp-Source: ACHHUZ4atxuAbltrSLDsTYOD9/2fTVgWHl3al5HIrAHTyeGpLF45j9capZUhn/3JK4vl4k/lNG5ZuQ== X-Received: by 2002:a1c:ed01:0:b0:3f4:f012:5cae with SMTP id l1-20020a1ced01000000b003f4f0125caemr1372957wmh.20.1684409967917; Thu, 18 May 2023 04:39:27 -0700 (PDT) From: Rajnesh Kanwal To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, atishp@rivosinc.com, apatel@ventanamicro.com, Rajnesh Kanwal Subject: [PATCH 3/6] target/riscv: Set VS* bits to one in mideleg when H-Ext is enabled Date: Thu, 18 May 2023 12:38:35 +0100 Message-Id: <20230518113838.130084-4-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518113838.130084-1-rkanwal@rivosinc.com> References: <20230518113838.130084-1-rkanwal@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=rkanwal@rivosinc.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 18 May 2023 09:33:46 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1684417292302100002 Content-Type: text/plain; charset="utf-8" With H-Ext supported, VS bits are all hardwired to one in MIDELEG denoting always delegated interrupts. This is being done in rmw_mideleg but given mideleg is used in other places when routing interrupts this change initializes it in riscv_cpu_realize to be on the safe side. Signed-off-by: Rajnesh Kanwal --- target/riscv/cpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index db0875fb43..90460cfe64 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1288,6 +1288,11 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 + /* With H-Ext VSSIP, VSTIP, VSEIP and SGEIP are hardwired to one. */ + if (riscv_has_ext(env, RVH)) { + env->mideleg =3D MIP_VSSIP | MIP_VSTIP | MIP_VSEIP | MIP_SGEIP; + } + riscv_cpu_register_gdb_regs_for_features(cs); =20 qemu_init_vcpu(cs); --=20 2.25.1 From nobody Sat May 18 10:07:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1684417189; cv=none; d=zohomail.com; s=zohoarc; b=mrzuZD9I4XO4FKCqHKjrE8N36AE9A5eSMDNZv2ML4z2VAPtQ4A4VOTN7RJFQ1aTlhUaxlj61oYLCBIL7lwYKbEe2E09twGNoMIljHN8E89Evh7da+R/ELlsPphYrTQPsjke3C/0+5sxHqN2FQbFx+uxf1QhIfuiJtHt+ZCLlHrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684417189; h=Content-Transfer-Encoding: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=n2S4ErOgaYneqPGjObFFVVohgOMNaPVx36RIW3tMfIo=; b=IwEowyEY9oOcD42RaVrL6cz+88RfOd2Ltx1RcxQYnjqw9OYWscJQJCgVME8+bZ30HQyH8iFsg8dVsschHKY+gzPsIYnS06V/UbD1vNEsyBG1RMvCIHxR5CDyE31RLro+4FKrNoOztR0SY3vTfFWt90y5aEGqbWS0gIkHvHwiJ5o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1684417189868357.3886791340125; Thu, 18 May 2023 06:39:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzdlN-0006Mo-K2; Thu, 18 May 2023 09:33:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzbyo-0000El-Dk for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:34 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzbyl-0002Wq-9X for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:34 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f49bf0223cso18663045e9.1 for ; Thu, 18 May 2023 04:39:30 -0700 (PDT) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id p6-20020a1c7406000000b003f4272c2d10sm5083982wmc.1.2023.05.18.04.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 04:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1684409969; x=1687001969; 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=n2S4ErOgaYneqPGjObFFVVohgOMNaPVx36RIW3tMfIo=; b=PMCKD+FQ3iRO0DYvSpyglrPCRkRd9JX3p22rpm+Q4eYmn6arfMvXeHaXGOBHmK8Kob mshIwvosIVhDZOOevrs8771G2AjMzSr5q9EuqdWVskgmmz6gEcp1MAbuV4U/WprvJJvH Il5P/ung5znCPPhpdjQBPvgNF75hwCLKFxGKVrKVi8wSCPgNN44oFWhN/cxo1IlZa6de hDFgamIxAvEBcrzzh6oJc74jeIF2tvGXhwZC2rKK5FEVhKSQ8DwERq/DYfvb5cmMDX3n iWFdfM4jd184cEzNurdMjAKEjkzc/WO6CG2CWFPPtVV4OJUrX3ytFbUnEQfWX+U18adS dEvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684409969; x=1687001969; 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=n2S4ErOgaYneqPGjObFFVVohgOMNaPVx36RIW3tMfIo=; b=LRqWRyJPUnc0CqdlTOMxOnSTiv9KmIBUl70Ak6EbHFNxxlm3xSKeRUwCOBzUV4nxU3 KC/dbKAlzqI4e6cps+4BgwMYiFbpj/+JBGwq9t6WCy/hLOiYfk87HbuPhIC3hP9dasBd sksWnlQclQfX8GjryZ7Kj892OT17vAOHBui4XNrwntAqhQT9Tw0+gG05k3FmSq4sLbBA AxXqx6OtHphHX5u1dVfRmTWNQz1gdBl+cBaTrWSPDn6Bbzv8r8kzxMkREvmwdVeDL6VN QEqiOQ+teVMCMEtr/+ZZeLFXpMlLh6nQtFNVKoDTPdoznnNgfL/TgisTtQPSE+KQsgyb Y7Tg== X-Gm-Message-State: AC+VfDxTzKhXMWVaWtJrNDPASCOYKFACDQLoiAg0VaTS9xGV4K7BvgeQ Jcq1Zq0CuO1Cp17BFDjIY4UxIA== X-Google-Smtp-Source: ACHHUZ5oStCtXfde0F+jSfpbR373w84M7AUF5XlC3tO3zu1Kvkwrioph0GXu9lc4oPwbZs3YCB7LkA== X-Received: by 2002:a05:600c:210e:b0:3f4:2737:a016 with SMTP id u14-20020a05600c210e00b003f42737a016mr1348684wml.29.1684409969215; Thu, 18 May 2023 04:39:29 -0700 (PDT) From: Rajnesh Kanwal To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, atishp@rivosinc.com, apatel@ventanamicro.com, Rajnesh Kanwal Subject: [PATCH 4/6] target/riscv: Split interrupt logic from riscv_cpu_update_mip. Date: Thu, 18 May 2023 12:38:36 +0100 Message-Id: <20230518113838.130084-5-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518113838.130084-1-rkanwal@rivosinc.com> References: <20230518113838.130084-1-rkanwal@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=rkanwal@rivosinc.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 18 May 2023 09:33:46 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1684417191714100003 Content-Type: text/plain; charset="utf-8" This is to allow virtual interrupts to be inserted into S and VS modes. Given virtual interrupts will be maintained in separate mvip and hvip CSRs, riscv_cpu_update_mip will no longer be in the path and interrupts need to be triggered for these cases from rmw_hvip64 and rmw_mvip64 functions. Signed-off-by: Rajnesh Kanwal --- target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index de7e43126a..de55bfb775 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -562,6 +562,7 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env); int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts); uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask, uint64_t value); +void riscv_cpu_interrupt(CPURISCVState *env); #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value = */ void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void *), void *arg); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index c78a2a9514..035437e0fb 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -609,11 +609,10 @@ int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_= t interrupts) } } =20 -uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask, - uint64_t value) +void riscv_cpu_interrupt(CPURISCVState *env) { + uint64_t gein, vsgein =3D 0, vstip =3D 0; CPUState *cs =3D env_cpu(env); - uint64_t gein, vsgein =3D 0, vstip =3D 0, old =3D env->mip; =20 if (env->virt_enabled) { gein =3D get_field(env->hstatus, HSTATUS_VGEIN); @@ -624,13 +623,25 @@ uint64_t riscv_cpu_update_mip(CPURISCVState *env, uin= t64_t mask, =20 QEMU_IOTHREAD_LOCK_GUARD(); =20 - env->mip =3D (env->mip & ~mask) | (value & mask); - if (env->mip | vsgein | vstip) { cpu_interrupt(cs, CPU_INTERRUPT_HARD); } else { cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); } +} + +uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask, uint64_t = value) +{ + uint64_t old =3D env->mip; + + /* No need to update mip for VSTIP */ + mask =3D ((mask =3D=3D MIP_VSTIP) && env->vstime_irq) ? 0 : mask; + + QEMU_IOTHREAD_LOCK_GUARD(); + + env->mip =3D (env->mip & ~mask) | (value & mask); + + riscv_cpu_interrupt(env); =20 return old; } --=20 2.25.1 From nobody Sat May 18 10:07:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1684417115; cv=none; d=zohomail.com; s=zohoarc; b=hDFksjWiFFD04FB5YCpEdqLxO3AocLU8OI8Ihl3MOmVTwRX1HwwKoXNJI7L8nGO3JV9j14R+XX0yvy+YegCHKMeqpSq2zm4HTNSNU3afs3L/hlTRYV7G1s56nmXJYc33dbAIBDEEI2Y7e4ifxOlJvoG3Zp+pIvEjzzXMWsZesEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684417115; h=Content-Transfer-Encoding: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=XrCVqwX7mW/VC1Gp5Sh7JCu+ALDhVLo30mip54py/BQ=; b=j14mWSxnv8GY4j9PMptHu2MCi8Ep4BPoOzs5H7iTYpbOj3einPoX0GuajO6IEudGR54f7j/0vwAIj7MkNUgEEfr9+M1bCaXsPCNboFR0+X/mYYDGfThuMKzsTsO+Zic662YO34GI+yrs5hkW2ZyGP9fST3uSJ9qrfuGQWdek1Oc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1684417115901591.5744936153661; Thu, 18 May 2023 06:38:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzdlO-0006Mw-Ax; Thu, 18 May 2023 09:33:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzbyq-0000Fw-1Q for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:36 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzbyl-0002X8-Ov for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:35 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f475366514so13437795e9.2 for ; Thu, 18 May 2023 04:39:31 -0700 (PDT) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id p6-20020a1c7406000000b003f4272c2d10sm5083982wmc.1.2023.05.18.04.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 04:39:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1684409970; x=1687001970; 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=XrCVqwX7mW/VC1Gp5Sh7JCu+ALDhVLo30mip54py/BQ=; b=QboZXNYj1U05ge95+ZbSwWyrhcjLdL0QLCD4q46L2PocKXUvvkiySqGgrTPCodEzMU vq6Mb5OSK906Mt/8yagtZjAwowbBJyhPMWx4dWnUIQxyWyDL/3ox1iWNJ8McdYGQ/+7b 9yRPtgu3tnnQa7Cdvl+RGLqo/XgzgGa5cRf9yAEqqrHD4mdEfYp3zVdncWE1ypb6BAnb 95ZUdgPYo0RGLHj1ykT4eYNFUjcZjacNhkX4HOFU6+fLtno62Dgny81CjiIEECxU1zEQ 7+30IMAo0o+4V8q4XrHqvy0GQOL51gMYi/1BGXgY/HkSCvPBY86ytBVYYhWvujP675x+ NhsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684409970; x=1687001970; 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=XrCVqwX7mW/VC1Gp5Sh7JCu+ALDhVLo30mip54py/BQ=; b=YyKFOAVcrS9o6afukPH/Gn3v+GkOmwxOF3a12zmztWEIiTTlvYqQFOhYADYQglMjHM iY21SRa19pWfnJLpoIPu8mAxUhrX72rO6SxZQ1la88+JeYdRIgED/O/iGWCYqFaOSu66 F17vQ+tGIyt4KOyWoLq8JSPn/jWiLsiakv6N4EnJoqpvIY3Mj9D4RktcRdpFNKCowckt 8dtOO5HMdciTqe9DVZnbFy6MZm83mNZCznBUn52UYWGUS+1ELsVDNQbivWuy0DlmmAfS 6f90n8XuztmE/+8b86s2WqpLPNeNpUS7Q0/nEmXKvAcvrxJm11UQkQfWacCl8TC8Bt79 r2YA== X-Gm-Message-State: AC+VfDzZEXA40ahSyeENF8VjxQAbMhPIJrItJireJEBoZVFz3d0ItBIs H1eoNvQWpUX/kc3IPQz1OvD4Tw== X-Google-Smtp-Source: ACHHUZ49bRFv42npaLS3pU22/YvhRLgk7Tia/+LJUmBrsDSOh34XyhQ3u49qINYW1gRJgukhBL2yYg== X-Received: by 2002:a7b:c847:0:b0:3f5:42e:7229 with SMTP id c7-20020a7bc847000000b003f5042e7229mr1018556wml.41.1684409970403; Thu, 18 May 2023 04:39:30 -0700 (PDT) From: Rajnesh Kanwal To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, atishp@rivosinc.com, apatel@ventanamicro.com, Rajnesh Kanwal Subject: [PATCH 5/6] target/riscv: Add M-mode virtual interrupt and IRQ filtering support. Date: Thu, 18 May 2023 12:38:37 +0100 Message-Id: <20230518113838.130084-6-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518113838.130084-1-rkanwal@rivosinc.com> References: <20230518113838.130084-1-rkanwal@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=rkanwal@rivosinc.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 18 May 2023 09:33:46 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1684417117016100003 Content-Type: text/plain; charset="utf-8" This change adds support for inserting virtual interrupts from M-mode into S-mode using mvien and mvip csrs. IRQ filtering is a use case of this change, i-e M-mode can stop delegating an interrupt to S-mode and instead enable it in MIE and receive those interrupts in M-mode and then selectively inject the interrupt using mvien and mvip. Also, the spec doesn't mandate the interrupt to be actually supported in hardware. Which allows M-mode to assert virtual interrupts to S-mode that have no connection to any real interrupt events. This is defined as part of the AIA specification [0], "5.3 Interrupt filtering and virtual interrupts for supervisor level". [0]: https://github.com/riscv/riscv-aia/releases/download/1.0-RC4/riscv-int= errupts-1.0-RC4.pdf Signed-off-by: Rajnesh Kanwal --- target/riscv/cpu.c | 3 +- target/riscv/cpu.h | 8 ++ target/riscv/cpu_bits.h | 6 + target/riscv/cpu_helper.c | 26 +++- target/riscv/csr.c | 279 ++++++++++++++++++++++++++++++++++---- target/riscv/machine.c | 3 + 6 files changed, 289 insertions(+), 36 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 90460cfe64..9557194a21 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -712,7 +712,8 @@ static bool riscv_cpu_has_work(CPUState *cs) * Definition of the WFI instruction requires it to ignore the privile= ge * mode and delegation registers, but respect individual enables */ - return riscv_cpu_all_pending(env) !=3D 0; + return riscv_cpu_all_pending(env) !=3D 0 || + riscv_cpu_sirq_pending(env) !=3D RISCV_EXCP_NONE; #else return true; #endif diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index de55bfb775..07cf656471 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -190,6 +190,12 @@ struct CPUArchState { uint64_t mie; uint64_t mideleg; =20 + /* + * When mideleg[i]=3D0 and mvien[i]=3D1, sie[i] is no more + * alias of mie[i] and needs to be maintained separatly. + */ + uint64_t sie; + target_ulong satp; /* since: priv-1.10.0 */ target_ulong stval; target_ulong medeleg; @@ -210,6 +216,8 @@ struct CPUArchState { /* AIA CSRs */ target_ulong miselect; target_ulong siselect; + uint64_t mvien; + uint64_t mvip; =20 /* Hypervisor CSRs */ target_ulong hstatus; diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 59f0ffd9e1..0d32d2a5a7 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -735,6 +735,12 @@ typedef enum RISCVException { #define MIE_SSIE (1 << IRQ_S_SOFT) #define MIE_USIE (1 << IRQ_U_SOFT) =20 +/* Machine constants */ +#define M_MODE_INTERRUPTS ((uint64_t)(MIP_MSIP | MIP_MTIP | MIP_MEIP)) +#define S_MODE_INTERRUPTS ((uint64_t)(MIP_SSIP | MIP_STIP | MIP_SEIP)) +#define VS_MODE_INTERRUPTS ((uint64_t)(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)) +#define HS_MODE_INTERRUPTS ((uint64_t)(MIP_SGEIP | VS_MODE_INTERRUPTS)) + /* General PointerMasking CSR bits */ #define PM_ENABLE 0x00000001ULL #define PM_CURRENT 0x00000002ULL diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 035437e0fb..681b4ae811 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -365,6 +365,10 @@ static int riscv_cpu_pending_to_irq(CPURISCVState *env, return best_irq; } =20 +/* + * Doesn't report interrupts inserted using mvip from M-mode firmware. Tho= se + * are returned in riscv_cpu_sirq_pending(). + */ uint64_t riscv_cpu_all_pending(CPURISCVState *env) { uint32_t gein =3D get_field(env->hstatus, HSTATUS_VGEIN); @@ -387,9 +391,10 @@ int riscv_cpu_sirq_pending(CPURISCVState *env) { uint64_t irqs =3D riscv_cpu_all_pending(env) & env->mideleg & ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + uint64_t irqs_f =3D env->mvip & env->mvien & ~env->mideleg & env->sie; =20 return riscv_cpu_pending_to_irq(env, IRQ_S_EXT, IPRIO_DEFAULT_S, - irqs, env->siprio); + irqs | irqs_f, env->siprio); } =20 int riscv_cpu_vsirq_pending(CPURISCVState *env) @@ -403,8 +408,8 @@ int riscv_cpu_vsirq_pending(CPURISCVState *env) =20 static int riscv_cpu_local_irq_pending(CPURISCVState *env) { + uint64_t irqs, pending, mie, hsie, vsie, irqs_f; int virq; - uint64_t irqs, pending, mie, hsie, vsie; =20 /* Determine interrupt enable state of all privilege modes */ if (env->virt_enabled) { @@ -430,8 +435,11 @@ static int riscv_cpu_local_irq_pending(CPURISCVState *= env) irqs, env->miprio); } =20 + /* Check for virtual S-mode interrupts. */ + irqs_f =3D env->mvip & (env->mvien & ~env->mideleg) & env->sie; + /* Check HS-mode interrupts */ - irqs =3D pending & env->mideleg & ~env->hideleg & -hsie; + irqs =3D ((pending & env->mideleg & ~env->hideleg) | irqs_f) & -hsie; if (irqs) { return riscv_cpu_pending_to_irq(env, IRQ_S_EXT, IPRIO_DEFAULT_S, irqs, env->siprio); @@ -611,19 +619,21 @@ int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_= t interrupts) =20 void riscv_cpu_interrupt(CPURISCVState *env) { - uint64_t gein, vsgein =3D 0, vstip =3D 0; + uint64_t gein, vsgein =3D 0, vstip =3D 0, irqf =3D 0; CPUState *cs =3D env_cpu(env); =20 if (env->virt_enabled) { gein =3D get_field(env->hstatus, HSTATUS_VGEIN); vsgein =3D (env->hgeip & (1ULL << gein)) ? MIP_VSEIP : 0; + } else { + irqf =3D env->mvien & env->mvip & env->sie; } =20 vstip =3D env->vstime_irq ? MIP_VSTIP : 0; =20 QEMU_IOTHREAD_LOCK_GUARD(); =20 - if (env->mip | vsgein | vstip) { + if (env->mip | vsgein | vstip | irqf) { cpu_interrupt(cs, CPU_INTERRUPT_HARD); } else { cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); @@ -1608,6 +1618,8 @@ void riscv_cpu_do_interrupt(CPUState *cs) bool async =3D !!(cs->exception_index & RISCV_EXCP_INT_FLAG); target_ulong cause =3D cs->exception_index & RISCV_EXCP_INT_MASK; uint64_t deleg =3D async ? env->mideleg : env->medeleg; + bool s_injected =3D env->mvip & (1 << cause) & env->mvien && + !(env->mip & (1 << cause)); target_ulong tval =3D 0; target_ulong tinst =3D 0; target_ulong htval =3D 0; @@ -1698,8 +1710,8 @@ void riscv_cpu_do_interrupt(CPUState *cs) __func__, env->mhartid, async, cause, env->pc, tval, riscv_cpu_get_trap_name(cause, async)); =20 - if (env->priv <=3D PRV_S && - cause < TARGET_LONG_BITS && ((deleg >> cause) & 1)) { + if (env->priv <=3D PRV_S && cause < 64 && + (((deleg >> cause) & 1) || s_injected)) { /* handle the trap in S-mode */ if (riscv_has_ext(env, RVH)) { uint64_t hdeleg =3D async ? env->hideleg : env->hedeleg; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 041f0b3e2e..c1ca065a81 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1113,21 +1113,16 @@ static RISCVException write_stimecmph(CPURISCVState= *env, int csrno, return RISCV_EXCP_NONE; } =20 -/* Machine constants */ - -#define M_MODE_INTERRUPTS ((uint64_t)(MIP_MSIP | MIP_MTIP | MIP_MEIP)) -#define S_MODE_INTERRUPTS ((uint64_t)(MIP_SSIP | MIP_STIP | MIP_SEIP | \ - MIP_LCOFIP)) -#define VS_MODE_INTERRUPTS ((uint64_t)(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)) -#define HS_MODE_INTERRUPTS ((uint64_t)(MIP_SGEIP | VS_MODE_INTERRUPTS)) - #define VSTOPI_NUM_SRCS 5 =20 -static const uint64_t delegable_ints =3D S_MODE_INTERRUPTS | - VS_MODE_INTERRUPTS; -static const uint64_t vs_delegable_ints =3D VS_MODE_INTERRUPTS; +#define LOCAL_INTERRUPTS (~0x1FFF) + +static const uint64_t delegable_ints =3D + S_MODE_INTERRUPTS | VS_MODE_INTERRUPTS | MIP_LCOFIP; +static const uint64_t vs_delegable_ints =3D + (VS_MODE_INTERRUPTS | LOCAL_INTERRUPTS) & ~MIP_LCOFIP; static const uint64_t all_ints =3D M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | - HS_MODE_INTERRUPTS; + HS_MODE_INTERRUPTS | LOCAL_INTERRUPTS; #define DELEGABLE_EXCPS ((1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | \ (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | \ (1ULL << (RISCV_EXCP_ILLEGAL_INST)) | \ @@ -1158,12 +1153,30 @@ static const target_ulong vs_delegable_excps =3D DE= LEGABLE_EXCPS & static const target_ulong sstatus_v1_10_mask =3D SSTATUS_SIE | SSTATUS_SPI= E | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS; -static const target_ulong sip_writable_mask =3D SIP_SSIP | MIP_USIP | MIP_= UEIP | - SIP_LCOFIP; + +/* + * Spec allows for bits 13:63 to be either read-only or writable. + * So far we have interrupt LCOFIP in that region which is writable. + * + * Also, spec allows to inject virtual interrupts in this region even + * without any hardware interrupts for that interrupt number. + * + * For now interrupt in 13:63 region are all kept writable. 13 being + * LCOFIP and 14:63 being virtual only. Change this in future if we + * introduce more interrupts that are not writable. + */ + +/* Bit STIP can be an alias of mip.STIP that's why it's writable in mvip. = */ +static const target_ulong mvip_writable_mask =3D MIP_SSIP | MIP_STIP | MIP= _SEIP | + LOCAL_INTERRUPTS; +static const target_ulong mvien_writable_mask =3D MIP_SSIP | MIP_SEIP | + LOCAL_INTERRUPTS; + +static const target_ulong sip_writable_mask =3D SIP_SSIP | LOCAL_INTERRUPT= S; static const target_ulong hip_writable_mask =3D MIP_VSSIP; static const target_ulong hvip_writable_mask =3D MIP_VSSIP | MIP_VSTIP | - MIP_VSEIP; -static const target_ulong vsip_writable_mask =3D MIP_VSSIP; + MIP_VSEIP | LOCAL_INTERRUPTS; +static const target_ulong vsip_writable_mask =3D MIP_VSSIP | LOCAL_INTERRU= PTS; =20 const bool valid_vm_1_10_32[16] =3D { [VM_1_10_MBARE] =3D true, @@ -1559,6 +1572,52 @@ static RISCVException rmw_mieh(CPURISCVState *env, i= nt csrno, return ret; } =20 +static RISCVException rmw_mvien64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + uint64_t mask =3D wr_mask & mvien_writable_mask; + + if (ret_val) { + *ret_val =3D env->mvien; + } + + env->mvien =3D (env->mvien & ~mask) | (new_val & mask); + + return RISCV_EXCP_NONE; +} + +static RISCVException rmw_mvien(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mvien64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_mvienh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mvien64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + static int read_mtopi(CPURISCVState *env, int csrno, target_ulong *val) { int irq; @@ -1699,6 +1758,11 @@ static int rmw_xireg(CPURISCVState *env, int csrno, = target_ulong *val, priv =3D PRV_M; break; case CSR_SIREG: + if (env->priv =3D=3D PRV_S && env->mvien & MIP_SEIP && + env->siselect >=3D ISELECT_IMSIC_EIDELIVERY && + env->siselect <=3D ISELECT_IMSIC_EIE63) { + goto done; + } iprio =3D env->siprio; isel =3D env->siselect; priv =3D PRV_S; @@ -1763,6 +1827,9 @@ static int rmw_xtopei(CPURISCVState *env, int csrno, = target_ulong *val, priv =3D PRV_M; break; case CSR_STOPEI: + if (env->mvien & MIP_SEIP && env->priv =3D=3D PRV_S) { + goto done; + } priv =3D PRV_S; break; case CSR_VSTOPEI: @@ -2336,6 +2403,143 @@ static RISCVException rmw_miph(CPURISCVState *env, = int csrno, return ret; } =20 +/* + * The function is written for two use-cases: + * 1- To access mvip csr as is for m-mode access. + * 2- To access sip as a combination of mip and mvip for s-mode. + * + * Both report bits 1, 5, 9 and 13:63 but with the exception of + * STIP being read-only zero in case of mvip when sstc extension + * is present. + * Also, sip needs to be read-only zero when both mideleg[i] and + * mvien[i] are zero but mvip needs to be an alias of mip. + */ +static RISCVException rmw_mvip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + RISCVCPU *cpu =3D env_archcpu(env); + target_ulong ret_mip =3D 0; + RISCVException ret; + uint64_t old_mvip; + + /* + * mideleg[i] mvien[i] + * 0 0 No delegation. mvip[i] is alias of mip[i]. + * 0 1 mvip[i] becomes source of interrupt, mip bypas= sed. + * 1 X mip[i] is source of interrupt and mvip[i] alia= ses + * mip[i]. + * + * So alias condition would be for bits: + * ((S_MODE_INTERRUPTS | LOCAL_INTERRUPTS) & (mideleg | ~mvien)) | + * (!sstc & MIP_STIP) + * + * Non-alias condition will be for bits: + * (S_MODE_INTERRUPTS | LOCAL_INTERRUPTS) & (~mideleg & mvien) + * + * alias_mask denotes the bits that come from mip nalias_mask denotes= bits + * that come from hvip. + */ + uint64_t alias_mask =3D ((S_MODE_INTERRUPTS | LOCAL_INTERRUPTS) & + (env->mideleg | ~env->mvien)) | MIP_STIP; + uint64_t nalias_mask =3D (S_MODE_INTERRUPTS | LOCAL_INTERRUPTS) & + (~env->mideleg & env->mvien); + uint64_t wr_mask_mvip; + uint64_t wr_mask_mip; + + /* + * mideleg[i] mvien[i] + * 0 0 sip[i] read-only zero. + * 0 1 sip[i] alias of mvip[i]. + * 1 X sip[i] alias of mip[i]. + * + * Both alias and non-alias mask remain same for sip except for bits + * which are zero in both mideleg and mvien. + */ + if (csrno =3D=3D CSR_SIP) { + /* Remove bits that are zero in both mideleg and mvien. */ + alias_mask &=3D (env->mideleg | env->mvien); + nalias_mask &=3D (env->mideleg | env->mvien); + } + + /* + * If sstc is present, mvip.STIP is not an alias of mip.STIP so clear + * that our in mip returned value. + */ + if (cpu->cfg.ext_sstc && (env->priv =3D=3D PRV_M) && + get_field(env->menvcfg, MENVCFG_STCE)) { + alias_mask &=3D ~MIP_STIP; + } + + wr_mask_mip =3D wr_mask & alias_mask & mvip_writable_mask; + wr_mask_mvip =3D wr_mask & nalias_mask & mvip_writable_mask; + + /* + * For bits set in alias_mask, mvip needs to be alias of mip, so forwa= rd + * this to rmw_mip. + */ + ret =3D rmw_mip(env, CSR_MIP, &ret_mip, new_val, wr_mask_mip); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + + old_mvip =3D env->mvip; + + /* + * Write to mvip. Update only non-alias bits. Alias bits were updated + * in mip in rmw_mip above. + */ + if (wr_mask_mvip) { + env->mvip =3D (env->mvip & ~wr_mask_mvip) | (new_val & wr_mask_mvi= p); + + /* + * Given mvip is separate source from mip, we need to trigger inte= rrupt + * from here separately. Normally this happen from riscv_cpu_updat= e_mip. + */ + riscv_cpu_interrupt(env); + } + + if (ret_val) { + ret_mip &=3D alias_mask; + old_mvip &=3D nalias_mask; + + *ret_val =3D old_mvip | ret_mip; + } + + return RISCV_EXCP_NONE; +} + +static RISCVException rmw_mvip(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mvip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_mviph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_mvip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + /* Supervisor Trap Setup */ static RISCVException read_sstatus_i128(CPURISCVState *env, int csrno, Int128 *val) @@ -2430,20 +2634,37 @@ static RISCVException rmw_sie64(CPURISCVState *env,= int csrno, uint64_t *ret_val, uint64_t new_val, uint64_t wr_mask) { + uint64_t nalias_mask =3D (S_MODE_INTERRUPTS | LOCAL_INTERRUPTS) & + (~env->mideleg & env->mvien); + uint64_t alias_mask =3D (S_MODE_INTERRUPTS | LOCAL_INTERRUPTS) & env->= mideleg; + uint64_t sie_mask =3D wr_mask & nalias_mask; RISCVException ret; - uint64_t mask =3D env->mideleg & S_MODE_INTERRUPTS; =20 + /* + * mideleg[i] mvien[i] + * 0 0 sie[i] read-only zero. + * 0 1 sie[i] is a separate writable bit. + * 1 X sie[i] alias of mie[i]. + * + * Both alias and non-alias mask remain same for sip except for bits + * which are zero in both mideleg and mvien. + */ if (env->virt_enabled) { if (env->hvictl & HVICTL_VTI) { return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } ret =3D rmw_vsie64(env, CSR_VSIE, ret_val, new_val, wr_mask); + if (ret_val) { + *ret_val &=3D alias_mask; + } } else { - ret =3D rmw_mie64(env, csrno, ret_val, new_val, wr_mask & mask); - } + ret =3D rmw_mie64(env, csrno, ret_val, new_val, wr_mask & alias_ma= sk); + if (ret_val) { + *ret_val &=3D alias_mask; + *ret_val |=3D env->sie & nalias_mask; + } =20 - if (ret_val) { - *ret_val &=3D mask; + env->sie =3D (env->sie & ~sie_mask) | (new_val & sie_mask); } =20 return ret; @@ -2641,7 +2862,7 @@ static RISCVException rmw_sip64(CPURISCVState *env, i= nt csrno, uint64_t new_val, uint64_t wr_mask) { RISCVException ret; - uint64_t mask =3D env->mideleg & sip_writable_mask; + uint64_t mask =3D (env->mideleg | env->mvien) & sip_writable_mask; =20 if (env->virt_enabled) { if (env->hvictl & HVICTL_VTI) { @@ -2649,11 +2870,12 @@ static RISCVException rmw_sip64(CPURISCVState *env,= int csrno, } ret =3D rmw_vsip64(env, CSR_VSIP, ret_val, new_val, wr_mask); } else { - ret =3D rmw_mip64(env, csrno, ret_val, new_val, wr_mask & mask); + ret =3D rmw_mvip64(env, csrno, ret_val, new_val, wr_mask & mask); } =20 if (ret_val) { - *ret_val &=3D env->mideleg & S_MODE_INTERRUPTS; + *ret_val &=3D (env->mideleg | env->mvien) & + (S_MODE_INTERRUPTS | LOCAL_INTERRUPTS); } =20 return ret; @@ -2818,6 +3040,7 @@ static int read_vstopi(CPURISCVState *env, int csrno,= target_ulong *val) =20 *val =3D (iid & TOPI_IID_MASK) << TOPI_IID_SHIFT; *val |=3D iprio; + return RISCV_EXCP_NONE; } =20 @@ -4123,14 +4346,14 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MTOPI] =3D { "mtopi", aia_any, read_mtopi }, =20 /* Virtual Interrupts for Supervisor Level (AIA) */ - [CSR_MVIEN] =3D { "mvien", aia_any, read_zero, write_ignore }, - [CSR_MVIP] =3D { "mvip", aia_any, read_zero, write_ignore }, + [CSR_MVIEN] =3D { "mvien", aia_any, NULL, NULL, rmw_mvien }, + [CSR_MVIP] =3D { "mvip", aia_any, NULL, NULL, rmw_mvip }, =20 /* Machine-Level High-Half CSRs (AIA) */ [CSR_MIDELEGH] =3D { "midelegh", aia_any32, NULL, NULL, rmw_midelegh }, [CSR_MIEH] =3D { "mieh", aia_any32, NULL, NULL, rmw_mieh }, - [CSR_MVIENH] =3D { "mvienh", aia_any32, read_zero, write_ignore }, - [CSR_MVIPH] =3D { "mviph", aia_any32, read_zero, write_ignore }, + [CSR_MVIENH] =3D { "mvienh", aia_any32, NULL, NULL, rmw_mvienh }, + [CSR_MVIPH] =3D { "mviph", aia_any32, NULL, NULL, rmw_mviph }, [CSR_MIPH] =3D { "miph", aia_any32, NULL, NULL, rmw_miph }, =20 /* Execution environment configuration */ diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 3ce2970785..dd7bdbb691 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -377,6 +377,9 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINT64(env.mip, RISCVCPU), VMSTATE_UINT64(env.miclaim, RISCVCPU), VMSTATE_UINT64(env.mie, RISCVCPU), + VMSTATE_UINT64(env.mvien, RISCVCPU), + VMSTATE_UINT64(env.mvip, RISCVCPU), + VMSTATE_UINT64(env.sie, RISCVCPU), VMSTATE_UINT64(env.mideleg, RISCVCPU), VMSTATE_UINTTL(env.satp, RISCVCPU), VMSTATE_UINTTL(env.stval, RISCVCPU), --=20 2.25.1 From nobody Sat May 18 10:07:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1684419067; cv=none; d=zohomail.com; s=zohoarc; b=gu/JLCQyEVSQzYqRmhSFpByYEgy9pqbS2Tji+muCpoQiBXt+naL76nh2BveA9lbxmyKOTRI5PBINedLx/7SwJuUlGmzwlcfr2CjhUYw+gqLcJEsqEdaomIE4zxv1ePvVV3uFc4Ly5nNEBbpAqeJkl5srGE4u3gUA7rD16N0PSHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684419067; h=Content-Transfer-Encoding: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=+eOz27V0lI0dX2ZuXz8KIfQYa/IppOOHJuB9W329sPI=; b=k3HXbxBhamn7+wZ5EJx3C/7MCy+5cujRn9S8IaTsr/p3P/jwXI7qZkuZWI07LjIqpuNL8aOQojzs6E1JC7Qmh5f+OhUuYTT2zeA12otsnwn083yR0H7WLYdvb+6l/wJvY+uWsnDnhw70SBoVmRHjoSUWgixrYZMG7SRaseD3Qk0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1684419067901447.5914968697099; Thu, 18 May 2023 07:11:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzdlM-0006Lo-JN; Thu, 18 May 2023 09:33:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzbyp-0000Fc-MZ for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:35 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzbym-0002Xg-Qn for qemu-devel@nongnu.org; Thu, 18 May 2023 07:39:35 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f41d087b3bso19468795e9.0 for ; Thu, 18 May 2023 04:39:32 -0700 (PDT) Received: from localhost.localdomain (cpc98982-watf12-2-0-cust57.15-2.cable.virginm.net. [82.26.13.58]) by smtp.gmail.com with ESMTPSA id p6-20020a1c7406000000b003f4272c2d10sm5083982wmc.1.2023.05.18.04.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 04:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1684409971; x=1687001971; 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=+eOz27V0lI0dX2ZuXz8KIfQYa/IppOOHJuB9W329sPI=; b=lMNqOU6zGV4tndIicGV3eQuyX02QHa5XXzYsBhW5l8ft76TBjWi542QZBi34ToRzWz a7W083eALazlwErB2WgdEfhNgIAjE76PuwZr/BAsf3PysqONi+89vVeePm/mZR0W5gtE GpCS2qKL5AUKb/R8kazrmNlntPsDvwBTZHd8lUKnvA8d2gQFe2oYgEu0qsEZl8qupxaC DFdrocRvd154vFJqtJRrVWk64MnIXAh59Ag4tutYyojVJ0HnQnIfy29er6l4vRD/pygb HxaRakVaSC/ABIlAs1neu+eMKgLPaHGxeHrMAfFIs/KGKVwRiUMOwPTQydqqH4AowKGI YhFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684409971; x=1687001971; 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=+eOz27V0lI0dX2ZuXz8KIfQYa/IppOOHJuB9W329sPI=; b=UC1Sc0BI+2IGWNAH1I6GQ6ZEZTuLDy7ecReoQTMk3wP+0B6NIcDLaX9LrmdvZewFfr Sp9lPqn0qrCvrXOk3qu74L07qUpeISuwTDWd8fVFMfq9Lfchl3Og+5LZh4DNS2F5Nqcm d2LeonXQDw1I7/CuyVkVvNndky0GYfFu8mN9HTTcQXY2Xthy12MroxSlgToX4wgydJ/P 9RtXN3QEYEaDQT6WzLpB+Rbr8JZUrtnQ35aZEuiHV8fnX6RinUlroBbymYhNB4dC+fre 9Ye8dUdnYJ5nrCo5vQ8pUrwULuXi3imIYdDlobBZ2V206ZpSpwjztDO5M2DFcwT0Hy/T kQDw== X-Gm-Message-State: AC+VfDwbhqqzD6mzMoGFS9S7FmJlysOi59MBjPAdvu7CmJe4BlyQNPJz fyfZK9R6r9y9d/udmiowqbtDAw== X-Google-Smtp-Source: ACHHUZ6199r23dDQdHE2EedKFP59sZaG8oxNrOnvdPnqJDBQET9LrUHNPce8xQfuTsEMGtyepfXenA== X-Received: by 2002:a1c:7910:0:b0:3f4:27ff:7d54 with SMTP id l16-20020a1c7910000000b003f427ff7d54mr1348036wme.3.1684409971518; Thu, 18 May 2023 04:39:31 -0700 (PDT) From: Rajnesh Kanwal To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liweiwei@iscas.ac.cn, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, atishp@rivosinc.com, apatel@ventanamicro.com, Rajnesh Kanwal Subject: [PATCH 6/6] target/riscv: Add HS-mode virtual interrupt and IRQ filtering support. Date: Thu, 18 May 2023 12:38:38 +0100 Message-Id: <20230518113838.130084-7-rkanwal@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518113838.130084-1-rkanwal@rivosinc.com> References: <20230518113838.130084-1-rkanwal@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=rkanwal@rivosinc.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 18 May 2023 09:33:46 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1684419069517100003 Content-Type: text/plain; charset="utf-8" This change adds support for inserting virtual interrupts from HS-mode into VS-mode using hvien and hvip csrs. This also allows for IRQ filtering from HS-mode. Also, the spec doesn't mandate the interrupt to be actually supported in hardware. Which allows HS-mode to assert virtual interrupts to VS-mode that have no connection to any real interrupt events. This is defined as part of the AIA specification [0], "6.3.2 Virtual interrupts for VS level". [0]: https://github.com/riscv/riscv-aia/releases/download/1.0-RC4/riscv-int= errupts-1.0-RC4.pdf Signed-off-by: Rajnesh Kanwal --- target/riscv/cpu.c | 3 +- target/riscv/cpu.h | 14 +++ target/riscv/cpu_helper.c | 48 +++++++--- target/riscv/csr.c | 196 ++++++++++++++++++++++++++++++++++---- target/riscv/machine.c | 3 + 5 files changed, 234 insertions(+), 30 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 9557194a21..c2b05d4c37 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -713,7 +713,8 @@ static bool riscv_cpu_has_work(CPUState *cs) * mode and delegation registers, but respect individual enables */ return riscv_cpu_all_pending(env) !=3D 0 || - riscv_cpu_sirq_pending(env) !=3D RISCV_EXCP_NONE; + riscv_cpu_sirq_pending(env) !=3D RISCV_EXCP_NONE || + riscv_cpu_vsirq_pending(env) !=3D RISCV_EXCP_NONE; #else return true; #endif diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 07cf656471..3e10eee38f 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -196,6 +196,12 @@ struct CPUArchState { */ uint64_t sie; =20 + /* + * When hideleg[i]=3D0 and hvien[i]=3D1, vsie[i] is no more + * alias of sie[i] (mie[i]) and needs to be maintained separatly. + */ + uint64_t vsie; + target_ulong satp; /* since: priv-1.10.0 */ target_ulong stval; target_ulong medeleg; @@ -230,6 +236,14 @@ struct CPUArchState { target_ulong hgeie; target_ulong hgeip; uint64_t htimedelta; + uint64_t hvien; + + /* + * Bits VSSIP, VSTIP and VSEIP in hvip are maintained in mip. Other bi= ts + * from 0:12 are reserved. Bits 13:63 are not aliased and must be sepa= rately + * maintain in hvip. + */ + uint64_t hvip; =20 /* Hypervisor controlled virtual interrupt priorities */ target_ulong hvictl; diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 681b4ae811..80bdd4cf5a 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -366,8 +366,9 @@ static int riscv_cpu_pending_to_irq(CPURISCVState *env, } =20 /* - * Doesn't report interrupts inserted using mvip from M-mode firmware. Tho= se - * are returned in riscv_cpu_sirq_pending(). + * Doesn't report interrupts inserted using mvip from M-mode firmware or + * using hvip bits 13:63 from HS-mode. Those are returned in + * riscv_cpu_sirq_pending() and riscv_cpu_vsirq_pending(). */ uint64_t riscv_cpu_all_pending(CPURISCVState *env) { @@ -399,16 +400,23 @@ int riscv_cpu_sirq_pending(CPURISCVState *env) =20 int riscv_cpu_vsirq_pending(CPURISCVState *env) { - uint64_t irqs =3D riscv_cpu_all_pending(env) & env->mideleg & - (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + uint64_t irqs =3D riscv_cpu_all_pending(env) & env->mideleg & env->hid= eleg; + uint64_t irqs_f_vs =3D env->hvip & env->hvien & ~env->hideleg & env->v= sie; + uint64_t vsbits; + + /* Bring VS-level bits to correct position */ + vsbits =3D irqs & VS_MODE_INTERRUPTS; + irqs &=3D ~VS_MODE_INTERRUPTS; + irqs |=3D vsbits >> 1; =20 return riscv_cpu_pending_to_irq(env, IRQ_S_EXT, IPRIO_DEFAULT_S, - irqs >> 1, env->hviprio); + (irqs | irqs_f_vs), env->hviprio); } =20 static int riscv_cpu_local_irq_pending(CPURISCVState *env) { - uint64_t irqs, pending, mie, hsie, vsie, irqs_f; + uint64_t irqs, pending, mie, hsie, vsie, irqs_f, irqs_f_vs; + uint64_t vsbits, irq_delegated; int virq; =20 /* Determine interrupt enable state of all privilege modes */ @@ -445,12 +453,26 @@ static int riscv_cpu_local_irq_pending(CPURISCVState = *env) irqs, env->siprio); } =20 + /* Check for virtual VS-mode interrupts. */ + irqs_f_vs =3D env->hvip & env->hvien & ~env->hideleg & env->vsie; + /* Check VS-mode interrupts */ - irqs =3D pending & env->mideleg & env->hideleg & -vsie; + irq_delegated =3D pending & env->mideleg & env->hideleg; + + /* Bring VS-level bits to correct position */ + vsbits =3D irq_delegated & VS_MODE_INTERRUPTS; + irq_delegated &=3D ~VS_MODE_INTERRUPTS; + irq_delegated |=3D vsbits >> 1; + + irqs =3D (irq_delegated | irqs_f_vs) & -vsie; if (irqs) { virq =3D riscv_cpu_pending_to_irq(env, IRQ_S_EXT, IPRIO_DEFAULT_S, - irqs >> 1, env->hviprio); - return (virq <=3D 0) ? virq : virq + 1; + irqs, env->hviprio); + if (virq <=3D 0 || (virq > 12 && virq <=3D 63)) { + return virq; + } else { + return virq + 1; + } } =20 /* Indicate no pending interrupt */ @@ -625,6 +647,7 @@ void riscv_cpu_interrupt(CPURISCVState *env) if (env->virt_enabled) { gein =3D get_field(env->hstatus, HSTATUS_VGEIN); vsgein =3D (env->hgeip & (1ULL << gein)) ? MIP_VSEIP : 0; + irqf =3D env->hvien & env->hvip & env->vsie; } else { irqf =3D env->mvien & env->mvip & env->sie; } @@ -1620,6 +1643,8 @@ void riscv_cpu_do_interrupt(CPUState *cs) uint64_t deleg =3D async ? env->mideleg : env->medeleg; bool s_injected =3D env->mvip & (1 << cause) & env->mvien && !(env->mip & (1 << cause)); + bool vs_injected =3D env->hvip & (1 << cause) & env->hvien && + !(env->mip & (1 << cause)); target_ulong tval =3D 0; target_ulong tinst =3D 0; target_ulong htval =3D 0; @@ -1711,12 +1736,13 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_get_trap_name(cause, async)); =20 if (env->priv <=3D PRV_S && cause < 64 && - (((deleg >> cause) & 1) || s_injected)) { + (((deleg >> cause) & 1) || s_injected || vs_injected)) { /* handle the trap in S-mode */ if (riscv_has_ext(env, RVH)) { uint64_t hdeleg =3D async ? env->hideleg : env->hedeleg; =20 - if (env->virt_enabled && ((hdeleg >> cause) & 1)) { + if (env->virt_enabled && + (((hdeleg >> cause) & 1) || vs_injected)) { /* Trap to VS mode */ /* * See if we need to adjust cause. Yes if its VS mode inte= rrupt diff --git a/target/riscv/csr.c b/target/riscv/csr.c index c1ca065a81..1929d5fa7b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -30,6 +30,11 @@ #include "qemu/guest-random.h" #include "qapi/error.h" =20 + +static RISCVException rmw_hvip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask); + /* CSR function table public API */ void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops) { @@ -1176,6 +1181,8 @@ static const target_ulong sip_writable_mask =3D SIP_S= SIP | LOCAL_INTERRUPTS; static const target_ulong hip_writable_mask =3D MIP_VSSIP; static const target_ulong hvip_writable_mask =3D MIP_VSSIP | MIP_VSTIP | MIP_VSEIP | LOCAL_INTERRUPTS; +static const target_ulong hvien_writable_mask =3D LOCAL_INTERRUPTS; + static const target_ulong vsip_writable_mask =3D MIP_VSSIP | LOCAL_INTERRU= PTS; =20 const bool valid_vm_1_10_32[16] =3D { @@ -2584,16 +2591,36 @@ static RISCVException rmw_vsie64(CPURISCVState *env= , int csrno, uint64_t *ret_val, uint64_t new_val, uint64_t wr_mask) { + uint64_t alias_mask =3D (LOCAL_INTERRUPTS | VS_MODE_INTERRUPTS) & + env->hideleg; + uint64_t nalias_mask =3D LOCAL_INTERRUPTS & (~env->hideleg & env->hvie= n); + uint64_t rval, rval_vs, vsbits; + uint64_t wr_mask_vsie; + uint64_t wr_mask_mie; RISCVException ret; - uint64_t rval, mask =3D env->hideleg & VS_MODE_INTERRUPTS; =20 /* Bring VS-level bits to correct position */ - new_val =3D (new_val & (VS_MODE_INTERRUPTS >> 1)) << 1; - wr_mask =3D (wr_mask & (VS_MODE_INTERRUPTS >> 1)) << 1; + vsbits =3D new_val & (VS_MODE_INTERRUPTS >> 1); + new_val &=3D ~(VS_MODE_INTERRUPTS >> 1); + new_val |=3D vsbits << 1; + + vsbits =3D wr_mask & (VS_MODE_INTERRUPTS >> 1); + wr_mask &=3D ~(VS_MODE_INTERRUPTS >> 1); + wr_mask |=3D vsbits << 1; + + wr_mask_mie =3D wr_mask & alias_mask; + wr_mask_vsie =3D wr_mask & nalias_mask; + + ret =3D rmw_mie64(env, csrno, &rval, new_val, wr_mask_mie); + + rval_vs =3D env->vsie & nalias_mask; + env->vsie =3D (env->vsie & ~wr_mask_vsie) | (new_val & wr_mask_vsie); =20 - ret =3D rmw_mie64(env, csrno, &rval, new_val, wr_mask & mask); if (ret_val) { - *ret_val =3D (rval & mask) >> 1; + rval &=3D alias_mask; + vsbits =3D rval & VS_MODE_INTERRUPTS; + rval &=3D ~VS_MODE_INTERRUPTS; + *ret_val =3D rval | (vsbits >> 1) | rval_vs; } =20 return ret; @@ -2812,15 +2839,26 @@ static RISCVException rmw_vsip64(CPURISCVState *env= , int csrno, { RISCVException ret; uint64_t rval, mask =3D env->hideleg & VS_MODE_INTERRUPTS; + uint64_t vsbits; =20 - /* Bring VS-level bits to correct position */ - new_val =3D (new_val & (VS_MODE_INTERRUPTS >> 1)) << 1; - wr_mask =3D (wr_mask & (VS_MODE_INTERRUPTS >> 1)) << 1; + /* Add virtualized bits into vsip mask. */ + mask |=3D env->hvien & ~env->hideleg; =20 - ret =3D rmw_mip64(env, csrno, &rval, new_val, - wr_mask & mask & vsip_writable_mask); + /* Bring VS-level bits to correct position */ + vsbits =3D new_val & (VS_MODE_INTERRUPTS >> 1); + new_val &=3D ~(VS_MODE_INTERRUPTS >> 1); + new_val |=3D vsbits << 1; + vsbits =3D wr_mask & (VS_MODE_INTERRUPTS >> 1); + wr_mask &=3D ~(VS_MODE_INTERRUPTS >> 1); + wr_mask |=3D vsbits << 1; + + ret =3D rmw_hvip64(env, csrno, &rval, new_val, + wr_mask & mask & vsip_writable_mask); if (ret_val) { - *ret_val =3D (rval & mask) >> 1; + rval &=3D mask; + vsbits =3D rval & VS_MODE_INTERRUPTS; + rval &=3D ~VS_MODE_INTERRUPTS; + *ret_val =3D rval | (vsbits >> 1); } =20 return ret; @@ -3112,6 +3150,52 @@ static RISCVException write_hedeleg(CPURISCVState *e= nv, int csrno, return RISCV_EXCP_NONE; } =20 +static RISCVException rmw_hvien64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + uint64_t mask =3D wr_mask & hvien_writable_mask; + + if (ret_val) { + *ret_val =3D env->hvien; + } + + env->hvien =3D (env->hvien & ~mask) | (new_val & mask); + + return RISCV_EXCP_NONE; +} + +static RISCVException rmw_hvien(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_hvien64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val =3D rval; + } + + return ret; +} + +static RISCVException rmw_hvienh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_m= ask) +{ + uint64_t rval; + RISCVException ret; + + ret =3D rmw_hvien64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val =3D rval >> 32; + } + + return ret; +} + static RISCVException rmw_hideleg64(CPURISCVState *env, int csrno, uint64_t *ret_val, uint64_t new_val, uint64_t wr_mask) @@ -3157,16 +3241,94 @@ static RISCVException rmw_hidelegh(CPURISCVState *e= nv, int csrno, return ret; } =20 +/* + * The function is written for two use-cases: + * 1- To access hvip csr as is for HS-mode access. + * 2- To access vsip as a combination of hvip, and mip for vs-mode. + * + * Both report bits 2, 6, 10 and 13:63. + * vsip needs to be read-only zero when both hideleg[i] and + * hvien[i] are zero. + */ static RISCVException rmw_hvip64(CPURISCVState *env, int csrno, uint64_t *ret_val, uint64_t new_val, uint64_t wr_mask) { RISCVException ret; + uint64_t old_hvip; + uint64_t ret_mip; + + /* + * For bits 10, 6 and 2, vsip[i] is an alias of hip[i]. These bits are + * present in hip, hvip and mip. Where mip[i] is alias of hip[i] and h= vip[i] + * is OR'ed in hip[i] to inject virtual interrupts from hypervisor. Th= ese + * bits are actually being maintained in mip so we read them from ther= e. + * This way we have a single source of truth and allows for easier + * implementation. + * + * For bits 13:63 we have: + * + * hideleg[i] hvien[i] + * 0 0 No delegation. vsip[i] readonly zero. + * 0 1 vsip[i] is alias of hvip[i], sip bypassed. + * 1 X vsip[i] is alias of sip[i], hvip bypassed. + * + * alias_mask denotes the bits that come from sip (mip here given we + * maintain all bits there). nalias_mask denotes bits that come from + * hvip. + */ + uint64_t alias_mask =3D (env->hideleg | ~env->hvien) | VS_MODE_INTERRU= PTS; + uint64_t nalias_mask =3D (~env->hideleg & env->hvien); + uint64_t wr_mask_hvip; + uint64_t wr_mask_mip; + + /* + * Both alias and non-alias mask remain same for vsip except: + * 1- For VS* bits if they are zero in hideleg. + * 2- For 13:63 bits if they are zero in both hideleg and hvien. + */ + if (csrno =3D=3D CSR_VSIP) { + /* zero-out VS* bits that are not delegated to VS mode. */ + alias_mask &=3D (env->hideleg | ~VS_MODE_INTERRUPTS); + + /* + * zero-out 13:63 bits that are zero in both hideleg and hvien. + * nalias_mask mask can not contain any VS* bits so only second + * condition applies on it. + */ + nalias_mask &=3D (env->hideleg | env->hvien); + alias_mask &=3D (env->hideleg | env->hvien); + } + + wr_mask_hvip =3D wr_mask & nalias_mask & hvip_writable_mask; + wr_mask_mip =3D wr_mask & alias_mask & hvip_writable_mask; + + /* Aliased bits, bits 10, 6, 2 need to come from mip. */ + ret =3D rmw_mip64(env, csrno, &ret_mip, new_val, wr_mask_mip); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + + old_hvip =3D env->hvip; + + if (wr_mask_hvip) { + env->hvip =3D (env->hvip & ~wr_mask_hvip) | (new_val & wr_mask_hvi= p); + + /* + * Given hvip is separate source from mip, we need to trigger inte= rrupt + * from here separately. Normally this happen from riscv_cpu_updat= e_mip. + */ + riscv_cpu_interrupt(env); + } =20 - ret =3D rmw_mip64(env, csrno, ret_val, new_val, - wr_mask & hvip_writable_mask); if (ret_val) { - *ret_val &=3D VS_MODE_INTERRUPTS; + /* Only take VS* bits from mip. */ + ret_mip &=3D alias_mask; + + /* Take in non-delegated 13:63 bits from hvip. */ + old_hvip &=3D nalias_mask; + + *ret_val =3D ret_mip | old_hvip; } =20 return ret; @@ -4527,14 +4689,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, =20 /* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) = */ - [CSR_HVIEN] =3D { "hvien", aia_hmode, read_zero, write_ign= ore }, + [CSR_HVIEN] =3D { "hvien", aia_hmode, NULL, NULL, rmw_hvie= n }, [CSR_HVICTL] =3D { "hvictl", aia_hmode, read_hvictl, write_hvictl = }, [CSR_HVIPRIO1] =3D { "hviprio1", aia_hmode, read_hviprio1, write_hviprio1 = }, [CSR_HVIPRIO2] =3D { "hviprio2", aia_hmode, read_hviprio2, write_hviprio2 = }, - /* * VS-Level Window to Indirectly Accessed Registers (H-extension with = AIA) */ @@ -4549,8 +4710,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] =3D { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh = }, - [CSR_HVIENH] =3D { "hvienh", aia_hmode32, read_zero, - write_ignore = }, + [CSR_HVIENH] =3D { "hvienh", aia_hmode32, NULL, NULL, rmw_hv= ienh }, [CSR_HVIPH] =3D { "hviph", aia_hmode32, NULL, NULL, rmw_hv= iph }, [CSR_HVIPRIO1H] =3D { "hviprio1h", aia_hmode32, read_hviprio1h, write_hviprio1h = }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index dd7bdbb691..3fff230a1c 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -92,6 +92,8 @@ static const VMStateDescription vmstate_hyper =3D { VMSTATE_UINTTL(env.hgatp, RISCVCPU), VMSTATE_UINTTL(env.hgeie, RISCVCPU), VMSTATE_UINTTL(env.hgeip, RISCVCPU), + VMSTATE_UINT64(env.hvien, RISCVCPU), + VMSTATE_UINT64(env.hvip, RISCVCPU), VMSTATE_UINT64(env.htimedelta, RISCVCPU), VMSTATE_UINT64(env.vstimecmp, RISCVCPU), =20 @@ -106,6 +108,7 @@ static const VMStateDescription vmstate_hyper =3D { VMSTATE_UINTTL(env.vstval, RISCVCPU), VMSTATE_UINTTL(env.vsatp, RISCVCPU), VMSTATE_UINTTL(env.vsiselect, RISCVCPU), + VMSTATE_UINT64(env.vsie, RISCVCPU), =20 VMSTATE_UINTTL(env.mtval2, RISCVCPU), VMSTATE_UINTTL(env.mtinst, RISCVCPU), --=20 2.25.1