From nobody Mon Feb 9 23:11:09 2026 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=1733267807; cv=none; d=zohomail.com; s=zohoarc; b=N9WEW/GPapsSOv3HuWHhHy9YD0MjjbK5Y5aDics3LwUKs3fBCFEdCI0YAfrmJvmJ/INGW9IJXY68kEI1M5Hv8aVUl9mB9tZhue12d7bYtQynsEwIHzgg2O5i1+yThK5EaQS3VGYrmilNXNCePiHQ0gaFt2Bc2oci44ulSSaurDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267807; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lXViAFlbF0a27TZCJ/bkE40evUkFiMFffaowOt3YXOA=; b=LE5QN1jdKfT6APtIbRcueUVKA3KTyV39biUlUptSgPHgLLlrsX1aAaoYHC8oXqLE+Rg5DI5e3J0QoEGIjBiKuxEltZcMoUdvtU/q+YXIm7RMgLuCg23mOIhq0C3T/ki9zLbVC6I/I+UsABaaywGY2WPOR3PedwH2HKgFFyFNIr4= 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 1733267807649454.9441650552063; Tue, 3 Dec 2024 15:16:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6W-0001Gc-Kg; Tue, 03 Dec 2024 18:14:52 -0500 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 1tIc6V-0001Fv-ON for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:51 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6S-0001I5-RK for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:51 -0500 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7256dc42176so3048289b3a.3 for ; Tue, 03 Dec 2024 15:14:47 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267687; x=1733872487; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lXViAFlbF0a27TZCJ/bkE40evUkFiMFffaowOt3YXOA=; b=gEnHvg/0yOz90+1NOCXFDOnhHr8EiCS36/DLKNaRm5MFKUJ9OCwqkzs3xjME2vBhym CcCmHutSj7mD4RENPL+Jh/rWT7CAcjcXwRX5jjYQX4mvbLj28cCl7Nl6TkSLIeat1L2a G4PSy2Jsgk0GfvOcRhJqteJRElalN2kbe0JbLw67bngoGF2pf2TlwPgffeGLtc/nifJg vCIJRI793Bt4BZx67jAa6dbD/WeQmFPjb31R0mranu2cehomfof02RWMhCX+22piIzi5 AbLqxwEp4a7YFOjg7MszltGMfuc2lEbn3bFu9WHtP1uMWs4Oi+APo9yMWp0zxY843AOI z/Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267687; x=1733872487; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lXViAFlbF0a27TZCJ/bkE40evUkFiMFffaowOt3YXOA=; b=OwHNUk9bYq32nc2aX4tUkK+SWn27ciMWSYEwuG7elKfCu21MLVkWO7PhLfqVxWC3wE L/DG1e4+wpO5nn/AXsFIHx3yxUxgjrUcVczv3LQWetPZLX5EWPtJmSTmb7aDt5k5i8N3 9Iy7NqDmZofpI4lzZq5BTz3JJLCI/nLGRm9IA4HUXZUjOfkQiY4lbqL+w2E+kWsjiN7/ GnC5czICZmfbqiHyPOPMPBtPG93a6mP44OhKvOqu+FkQSK6Z9Ks1V1YHVfNBu5eAJB+M pKJmYdDWxHaZ3qzO1b6WHHP4OKf/PCI7WnUO0tV6fzNcr59tFfDq8OMswcoZTN0lN/NA hUAg== X-Forwarded-Encrypted: i=1; AJvYcCXq62WkQCo7G4iwSqn72aO3vStCS5rTJdspKSEICYh7TW1RAK4GsTDVAyY/B6mkPuiL//JT39gDa3VL@nongnu.org X-Gm-Message-State: AOJu0YzruOjWW61NJGWsNcYvGOVUgTgKDqoZZgjiu+lCzaxdbJFyTD0J nG2WIUCadtRDQLGOjOx8vpyqUPOz3b0Fwh/G1CqqdE/zTfMZwaxd7cW/K31EM5Q= X-Gm-Gg: ASbGncsFAbDMu/4bKwZMo9WTtAX1mU/ePwGSB61Kvk1mKCEuZC3daQyhej0JFkxEKIE 47turpFYyZ6Cwe1M454zB29kpjlRpJaDIJ8WjfD18DKX49ZAYGQ8f08i7KkeahX59DY4revDUE2 CckV5tkctcUP0jSYzjDXr3P33FbBvec2NLGP3ch4jdxcvEvClgrkbYL0jtupCBxOqHrTXdqGS5h BDcr5PvwTz9KibaZ/3VzWYZns0377V4HqRzSVPvgzlSFq+lIc6t9L3Mz1KLvCk= X-Google-Smtp-Source: AGHT+IHZX6xOmv6RESxSzfIKssM/VKGrdDopGu0PXBGyXwOCheTKh3QGQk4V83wimymBNC0tW+TjFw== X-Received: by 2002:a05:6a00:92a3:b0:71e:79a9:ec47 with SMTP id d2e1a72fcca58-7257fa5708fmr5365792b3a.6.1733267686769; Tue, 03 Dec 2024 15:14:46 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:39 -0800 Subject: [PATCH v4 01/11] target/riscv: Add properties for Indirect CSR Access extension MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-1-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com, Kaiwen Xue X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::42e; envelope-from=atishp@rivosinc.com; helo=mail-pf1-x42e.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267809634116600 From: Kaiwen Xue This adds the properties for sxcsrind. Definitions of new registers and implementations will come with future patches. Signed-off-by: Kaiwen Xue Reviewed-by: Daniel Henrique Barboza Signed-off-by: Atish Patra Acked-by: Alistair Francis --- target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f219f0c3b527..963f1f3af9ae 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -185,12 +185,14 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), + ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind), ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), + ISA_EXT_DATA_ENTRY(sscsrind, PRIV_VERSION_1_12_0, ext_sscsrind), ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12), ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 59d6fc445d18..8b974255f6fb 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -79,6 +79,8 @@ struct RISCVCPUConfig { bool ext_smstateen; bool ext_sstc; bool ext_smcntrpmf; + bool ext_smcsrind; + bool ext_sscsrind; bool ext_svadu; bool ext_svinval; bool ext_svnapot; --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267891; cv=none; d=zohomail.com; s=zohoarc; b=PNliK9xrVQtcfPBUSjcV+Ba4Yucfr4/xqYeE57CPjEBkFRxVMPyPYOHcf4TuP+ZpxD5DeLTW2jpUgfVxiKw8YcUs2gFwmV3+iF2/Vha1LTVgnRsBYX59p+iIrObY9QdJ47msZMRJA37SJQ4rUh3vUaHVhfV9fVMlqMc2GD9i50k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267891; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wnE0CmP8NTo4c9Y80T+D12LCLdMtfc2JUgxsXFE/v+o=; b=TtTN+pdYgNwkP6Vd//viZ7N4+JJhyMcyYdFqNgy9bU2rABdeMRDQJJnFaiSwNZRIAgqxZ2nQEaq2XYyrjwU+P5ZaLWK0IgOW193pBfKsSZZKUaeSB2dWAn8LQXI3k119a5Hphq+ddVjnKKY1+fzn0/TR99AJWMcikedsl9qLU9E= 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 173326789136162.12854507811198; Tue, 3 Dec 2024 15:18:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6Z-0001IL-4U; Tue, 03 Dec 2024 18:14:55 -0500 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 1tIc6W-0001GD-AF for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:52 -0500 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6T-0001IK-8T for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:51 -0500 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-724d23df764so5362717b3a.1 for ; Tue, 03 Dec 2024 15:14:48 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267688; x=1733872488; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wnE0CmP8NTo4c9Y80T+D12LCLdMtfc2JUgxsXFE/v+o=; b=uEHWXBxaa+f7zXpJz/8OK4luOnoP6K9NZq7q6gnChqmAHMmWn+kUjULr2/s48IiMdI pTLJrSWq9kDYKyldK68/7JSoauD5ZYIS8XNMViAJK0QRFqzQHMwudVXGbbQ1UMAZbAsz hsIvYZ07SRiapUxg58iKBke1k4pcMRs7PZFAPhVfUwg21/GDKC8r+/Uhlze9jUlZGS+O ZliPNr2tI+Li5c8cnxXWuBI7LGOIi0vGIhHwXcvjFOplsNa+vK6qJH6Pa6lgy5wygZ6Q 4Mivkoze1KKB0fok/lH8CabjEw/5NqyMO5V3Y/nCvxAZ96KWAUd1X7wzmCEfC+2THRVQ dFrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267688; x=1733872488; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wnE0CmP8NTo4c9Y80T+D12LCLdMtfc2JUgxsXFE/v+o=; b=FawvAQEEVIUWN58xqgvysJ9gFS0L1MLR796l6A/IdlIL4b2rbIkhvG7CYrBOgnRCF+ n/WWbwBfchWUjG8voRCQXr+kPw4+a9RfmG3+o047KVKueYfCv74dgJVQjd5jHJzUq5zA U5PweCKYUeJBY8jPhusGfUdNLalPACitjoda/eVAR/CbW8ldw2iGZUlMHrz45iDWWtlu +otGSjFBDOXCTjodlgKx+MB27naaNbCQSltXp+EwvUgYh1CQvWQkOQUY3O9KNWSqTYTz 4dew+4Y397BzI1A6SqDpDnV95XMFONLDPiblpyUGoj0XnoCE55UBy2pWbsJzy7Lqr69+ aYnA== X-Forwarded-Encrypted: i=1; AJvYcCUdqVGPdrXwq03yS5dCFBjNI/C8u3NzAuU6SHCx6ykahKu5XJvtPtq/kb2X8Y5DSX+IgY6IQKD1wO1M@nongnu.org X-Gm-Message-State: AOJu0YzjWzJZicEcjUStfawzUKAPkXrhAIFY15SWe82I0BunhQzw3XMc l11UCTXBU12qjE/5yfSGZVlBcOMnBLvSWm7q+no1DtMBYm8xieFwvnBcPzLeLOQ= X-Gm-Gg: ASbGncs/DBbid+v/jz49GDw7yWSyc/kzj1FnzGCrF/+G9GcJSHmBdlMz5F3wcIV1e1O XBmCLpGVhwi4i22D0QRUjD7tA79IYCdgmdiGGN9HjttraWtspwqp6+K0d6AQDX8J49huM6XEb5a 2i1GV1dw3dPgkWvpSTqike6ipe29+LNrq788MeKirF/qARm0q07VHkmWNzyPKZmTkTUZx3iskuC P1YYuPlJhhMBMJ9QWFUHUdl2QXUMBbSzkkOI4hLjlr2EmvI7iRyP7UwmAVxiv0= X-Google-Smtp-Source: AGHT+IFfFe9wwTLurayiKPPFuIml+pnARUR4kEcvabXwOOing9vio2xzrU7HqkYbxERf8HqAtGAK5g== X-Received: by 2002:a17:902:e743:b0:215:4a4e:9286 with SMTP id d9443c01a7336-215bd0e66b0mr64747065ad.26.1733267687830; Tue, 03 Dec 2024 15:14:47 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:40 -0800 Subject: [PATCH v4 02/11] target/riscv: Decouple AIA processing from xiselect and xireg MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-2-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com, Kaiwen Xue X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::42b; envelope-from=atishp@rivosinc.com; helo=mail-pf1-x42b.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267892122116600 From: Kaiwen Xue Since xiselect and xireg also will be of use in sxcsrind, AIA should have its own separated interface when those CSRs are accessed. Signed-off-by: Kaiwen Xue Reviewed-by: Alistair Francis Signed-off-by: Atish Patra --- target/riscv/csr.c | 165 ++++++++++++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 139 insertions(+), 26 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 9846770820f4..52e0139fc99c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -29,6 +29,7 @@ #include "sysemu/cpu-timers.h" #include "qemu/guest-random.h" #include "qapi/error.h" +#include =20 /* CSR function table public API */ void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops) @@ -305,6 +306,15 @@ static RISCVException aia_any32(CPURISCVState *env, in= t csrno) return any32(env, csrno); } =20 +static RISCVException csrind_or_aia_any(CPURISCVState *env, int csrno) +{ + if (!riscv_cpu_cfg(env)->ext_smaia && !riscv_cpu_cfg(env)->ext_smcsrin= d) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return any(env, csrno); +} + static RISCVException smode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS)) { @@ -341,6 +351,30 @@ static RISCVException aia_smode32(CPURISCVState *env, = int csrno) return smode32(env, csrno); } =20 +static bool csrind_extensions_present(CPURISCVState *env) +{ + return riscv_cpu_cfg(env)->ext_smcsrind || riscv_cpu_cfg(env)->ext_ssc= srind; +} + +static bool aia_extensions_present(CPURISCVState *env) +{ + return riscv_cpu_cfg(env)->ext_smaia || riscv_cpu_cfg(env)->ext_ssaia; +} + +static bool csrind_or_aia_extensions_present(CPURISCVState *env) +{ + return csrind_extensions_present(env) || aia_extensions_present(env); +} + +static RISCVException csrind_or_aia_smode(CPURISCVState *env, int csrno) +{ + if (!csrind_or_aia_extensions_present(env)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return smode(env, csrno); +} + static RISCVException hmode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVH)) { @@ -360,6 +394,15 @@ static RISCVException hmode32(CPURISCVState *env, int = csrno) =20 } =20 +static RISCVException csrind_or_aia_hmode(CPURISCVState *env, int csrno) +{ + if (!csrind_or_aia_extensions_present(env)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return hmode(env, csrno); +} + static RISCVException umode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVU)) { @@ -1966,6 +2009,22 @@ static int aia_xlate_vs_csrno(CPURISCVState *env, in= t csrno) }; } =20 +static int csrind_xlate_vs_csrno(CPURISCVState *env, int csrno) +{ + if (!env->virt_enabled) { + return csrno; + } + + switch (csrno) { + case CSR_SISELECT: + return CSR_VSISELECT; + case CSR_SIREG: + return CSR_VSIREG; + default: + return csrno; + }; +} + static RISCVException rmw_xiselect(CPURISCVState *env, int csrno, target_ulong *val, target_ulong new_val, target_ulong wr_mask) @@ -1973,7 +2032,7 @@ static RISCVException rmw_xiselect(CPURISCVState *env= , int csrno, target_ulong *iselect; =20 /* Translate CSR number for VS-mode */ - csrno =3D aia_xlate_vs_csrno(env, csrno); + csrno =3D csrind_xlate_vs_csrno(env, csrno); =20 /* Find the iselect CSR based on CSR number */ switch (csrno) { @@ -2002,6 +2061,12 @@ static RISCVException rmw_xiselect(CPURISCVState *en= v, int csrno, return RISCV_EXCP_NONE; } =20 +static bool xiselect_aia_range(target_ulong isel) +{ + return (ISELECT_IPRIO0 <=3D isel && isel <=3D ISELECT_IPRIO15) || + (ISELECT_IMSIC_FIRST <=3D isel && isel <=3D ISELECT_IMSIC_LAST); +} + static int rmw_iprio(target_ulong xlen, target_ulong iselect, uint8_t *iprio, target_ulong *val, target_ulong new_val, @@ -2047,45 +2112,44 @@ static int rmw_iprio(target_ulong xlen, return 0; } =20 -static RISCVException rmw_xireg(CPURISCVState *env, int csrno, - target_ulong *val, target_ulong new_val, - target_ulong wr_mask) +static RISCVException rmw_xireg_aia(CPURISCVState *env, int csrno, + target_ulong isel, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) { - bool virt, isel_reserved; - uint8_t *iprio; + bool virt =3D false, isel_reserved =3D false; int ret =3D -EINVAL; - target_ulong priv, isel, vgein; - - /* Translate CSR number for VS-mode */ - csrno =3D aia_xlate_vs_csrno(env, csrno); + uint8_t *iprio; + target_ulong priv, vgein; =20 - /* Decode register details from CSR number */ - virt =3D false; - isel_reserved =3D false; + /* VS-mode CSR number passed in has already been translated */ switch (csrno) { case CSR_MIREG: + if (!riscv_cpu_cfg(env)->ext_smaia) { + goto done; + } iprio =3D env->miprio; - isel =3D env->miselect; priv =3D PRV_M; break; case CSR_SIREG: - if (env->priv =3D=3D PRV_S && env->mvien & MIP_SEIP && + if (!riscv_cpu_cfg(env)->ext_ssaia || + (env->priv =3D=3D PRV_S && env->mvien & MIP_SEIP && env->siselect >=3D ISELECT_IMSIC_EIDELIVERY && - env->siselect <=3D ISELECT_IMSIC_EIE63) { + env->siselect <=3D ISELECT_IMSIC_EIE63)) { goto done; } iprio =3D env->siprio; - isel =3D env->siselect; priv =3D PRV_S; break; case CSR_VSIREG: + if (!riscv_cpu_cfg(env)->ext_ssaia) { + goto done; + } iprio =3D env->hviprio; - isel =3D env->vsiselect; priv =3D PRV_S; virt =3D true; break; default: - goto done; + goto done; }; =20 /* Find the selected guest interrupt file */ @@ -2116,10 +2180,54 @@ static RISCVException rmw_xireg(CPURISCVState *env,= int csrno, } =20 done: + /* + * If AIA is not enabled, illegal instruction exception is always + * returned regardless of whether we are in VS-mode or not + */ if (ret) { return (env->virt_enabled && virt && !isel_reserved) ? RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; } + + return RISCV_EXCP_NONE; +} + +static RISCVException rmw_xireg(CPURISCVState *env, int csrno, + target_ulong *val, target_ulong new_val, + target_ulong wr_mask) +{ + bool virt =3D false; + int ret =3D -EINVAL; + target_ulong isel; + + /* Translate CSR number for VS-mode */ + csrno =3D csrind_xlate_vs_csrno(env, csrno); + + /* Decode register details from CSR number */ + switch (csrno) { + case CSR_MIREG: + isel =3D env->miselect; + break; + case CSR_SIREG: + isel =3D env->siselect; + break; + case CSR_VSIREG: + isel =3D env->vsiselect; + virt =3D true; + break; + default: + goto done; + }; + + if (xiselect_aia_range(isel)) { + return rmw_xireg_aia(env, csrno, isel, val, new_val, wr_mask); + } + +done: + if (ret) { + return (env->virt_enabled && virt) ? + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; + } return RISCV_EXCP_NONE; } =20 @@ -5065,8 +5173,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MIP] =3D { "mip", any, NULL, NULL, rmw_mip }, =20 /* Machine-Level Window to Indirectly Accessed Registers (AIA) */ - [CSR_MISELECT] =3D { "miselect", aia_any, NULL, NULL, rmw_xiselec= t }, - [CSR_MIREG] =3D { "mireg", aia_any, NULL, NULL, rmw_xireg }, + [CSR_MISELECT] =3D { "miselect", csrind_or_aia_any, NULL, NULL, + rmw_xiselect }, + [CSR_MIREG] =3D { "mireg", csrind_or_aia_any, NULL, NULL, + rmw_xireg }, =20 /* Machine-Level Interrupts (AIA) */ [CSR_MTOPEI] =3D { "mtopei", aia_any, NULL, NULL, rmw_xtopei }, @@ -5184,8 +5294,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_SATP] =3D { "satp", satp, read_satp, write_satp }, =20 /* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */ - [CSR_SISELECT] =3D { "siselect", aia_smode, NULL, NULL, rmw_xisele= ct }, - [CSR_SIREG] =3D { "sireg", aia_smode, NULL, NULL, rmw_xireg = }, + [CSR_SISELECT] =3D { "siselect", csrind_or_aia_smode, NULL, NULL, + rmw_xiselect = }, + [CSR_SIREG] =3D { "sireg", csrind_or_aia_smode, NULL, NULL, + rmw_xireg = }, =20 /* Supervisor-Level Interrupts (AIA) */ [CSR_STOPEI] =3D { "stopei", aia_smode, NULL, NULL, rmw_xtopei= }, @@ -5264,9 +5376,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { /* * VS-Level Window to Indirectly Accessed Registers (H-extension with = AIA) */ - [CSR_VSISELECT] =3D { "vsiselect", aia_hmode, NULL, NULL, - rmw_xiselect = }, - [CSR_VSIREG] =3D { "vsireg", aia_hmode, NULL, NULL, rmw_xire= g }, + [CSR_VSISELECT] =3D { "vsiselect", csrind_or_aia_hmode, NULL, NULL, + rmw_xiselect = }, + [CSR_VSIREG] =3D { "vsireg", csrind_or_aia_hmode, NULL, NULL, + rmw_xireg = }, =20 /* VS-Level Interrupts (H-extension with AIA) */ [CSR_VSTOPEI] =3D { "vstopei", aia_hmode, NULL, NULL, rmw_xtop= ei }, --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267787; cv=none; d=zohomail.com; s=zohoarc; b=QKMI+E1aOtrbBkeVLn6gluW5JX1eVmE9egBXIiFBJ9GIlijQXcyJU9A9KQd+Hi/YYRrgOGsgHfqVL7yyJk/YTFXBWI0HA6lFHzXhyrlsgjrNpnYYcewITJbwqGl2j72GobnbX0mnjHNz2G/Zn3EtDV7hC6MnWuooBYrixLApz5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267787; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jgqE8QX3K8RGYv92OKL7ZgQ+ZbdwwR+hFk0G3kGMbpQ=; b=Pn/ouyREhqdrNnGOWAq403x5b6ZCcsLZYtrtSjt9JmYlxyOTWmc2emftqH17G2fO20m8Krz/9ALcLz/L4l2DXCERu+2lS+nhiA3mdQg57TdFKGf5zM5D0QY+by0yKpNXn4zPZrW6HEYkOdGIIOm3zZMlVxtBUpYljjok9Lx/SNE= 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 1733267787329568.8490233942548; Tue, 3 Dec 2024 15:16:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6Y-0001IE-Nz; Tue, 03 Dec 2024 18:14:54 -0500 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 1tIc6W-0001GF-Ak for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:52 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6U-0001Ie-7v for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:52 -0500 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-7fcc00285a9so3041952a12.2 for ; Tue, 03 Dec 2024 15:14:49 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267689; x=1733872489; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jgqE8QX3K8RGYv92OKL7ZgQ+ZbdwwR+hFk0G3kGMbpQ=; b=mZz18di7V0L8u8x9yicA2jJGRSDx+N07WwPQHHt3E34S/5fiZojwFvuzBtV2yOlTCG C5hJq24DQGSAprDisWY25OGuj7sonNHXdhdxIECjIAZ9FIoBthbbXdvAr5JgECp6AywY rrp5i84i00nGxVPK4U+3VBAs8KoLHBmhX3rxDE/1SXvnQg/3NjOp2j8AfmoUi0cLOJGe GSTJsmL/tr27Dzf8DnAO9oKupSFji+GQWu0Mu7fmj9Tc/0FwN7b+D1obtw/ugu9I7gT3 G34gmBxrHS9YclIrl9As8gYngMxtZFmdytqpFy6LeLpHdGUuN5anHvGM8Tl3LNcWy0HL Ncbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267689; x=1733872489; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jgqE8QX3K8RGYv92OKL7ZgQ+ZbdwwR+hFk0G3kGMbpQ=; b=RjIB7gR+feZLAth79o4cNDCeZron1EPXLHi2LA+Z0FWoAfDkkxjEVh4f0E1GIQsrds ye9tfQgorw43omuCEwhxXFJ0QcvsmWO5B81f54SUvNhbP+bs32dyTO97z5wiyZxVKN+a HoAZLibVlEEz/cBEQcH74IM3VfAjWdGbvo7WirZFY+JWkBMZp6WQu8UxC+N5Na3C9tum m8Vn8pA4Aoh6la0CeP1/UKNG97Vs75oFW5XDcDxVoaMKWlU/cABds8/yqCvQxasJRGVc YAi1AIxLkxY4dRMScyR8rCBcl48RP93r7YDNpsRGdd5JQppzzJwmS3b59ml4ARdA7NwL SHdQ== X-Forwarded-Encrypted: i=1; AJvYcCX5OkL6yPzI2GgOFufUn52c9ISToHizprRyJi6kpgAgmce+to561PHoG6diDw2M2eKc61n1n4zWyoSI@nongnu.org X-Gm-Message-State: AOJu0YxH8AQdJaSCZ766Jbp/idYtX44WJDnxshC6IcwA+1qfa9728w4g I2FCUtMaHSzrFWqPv7QMEE9LEjcdqshhiN3ncTHYOXA4nKbEnQ7GpCkKOcq+e4Y= X-Gm-Gg: ASbGncs4D1/Db5niDgcYXTVMB0Qj46UpxAWeMVtDSypqKqqHJfQfmmCNdk8uNaTDX1J Ey7IVGc6Cya8f5WgMf3JMMz+QENbqdSsnORMjK1XR/2KriIX/I8KrWhK8fB4ueD8GXYDM0fIIcm Y1vB3FT2ofARUNYlOeW6D7M3o9POEatToloLGuQHuZqT7inpJRvVmQSDs0uks3kT2zB5VKihxXz FXY9JYMhFGM9XjvHFkhIyY1i9NO1q724b+osjDB0ADXfzsLUFMS9KbVKkHfP88= X-Google-Smtp-Source: AGHT+IFWBjis/dBtbj3s0JEYepKf6+Zs9uSKO3+lV/qr4sKvdjSB9fPEtm0OIE1BN98ZaZfQv1tBwQ== X-Received: by 2002:a05:6a21:3282:b0:1db:eead:c588 with SMTP id adf61e73a8af0-1e1653f3ca0mr6665023637.29.1733267688905; Tue, 03 Dec 2024 15:14:48 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:41 -0800 Subject: [PATCH v4 03/11] target/riscv: Enable S*stateen bits for AIA MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-3-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::52a; envelope-from=atishp@rivosinc.com; helo=mail-pg1-x52a.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 autolearn=ham autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267789888116600 As per the ratified AIA spec v1.0, three stateen bits control AIA CSR access. Bit 60 controls the indirect CSRs Bit 59 controls the most AIA CSR state Bit 58 controls the IMSIC state such as stopei and vstopei Enable the corresponding bits in [m|h]stateen and enable corresponding checks in the CSR accessor functions. Reviewed-by: Alistair Francis Signed-off-by: Atish Patra --- target/riscv/csr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 52e0139fc99c..c91a26a52ef6 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -335,19 +335,42 @@ static RISCVException smode32(CPURISCVState *env, int= csrno) =20 static RISCVException aia_smode(CPURISCVState *env, int csrno) { + int ret; + if (!riscv_cpu_cfg(env)->ext_ssaia) { return RISCV_EXCP_ILLEGAL_INST; } =20 + if (csrno =3D=3D CSR_STOPEI) { + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_IMSIC); + } else { + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_AIA); + } + + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + return smode(env, csrno); } =20 static RISCVException aia_smode32(CPURISCVState *env, int csrno) { + int ret; + if (!riscv_cpu_cfg(env)->ext_ssaia) { return RISCV_EXCP_ILLEGAL_INST; } =20 + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_AIA); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + return smode32(env, csrno); } =20 @@ -586,15 +609,38 @@ static RISCVException pointer_masking(CPURISCVState *= env, int csrno) =20 static RISCVException aia_hmode(CPURISCVState *env, int csrno) { + int ret; + if (!riscv_cpu_cfg(env)->ext_ssaia) { return RISCV_EXCP_ILLEGAL_INST; } =20 - return hmode(env, csrno); + if (csrno =3D=3D CSR_VSTOPEI) { + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_IMSIC); + } else { + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_AIA); + } + + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + + return hmode(env, csrno); } =20 static RISCVException aia_hmode32(CPURISCVState *env, int csrno) { + int ret; + + if (!riscv_cpu_cfg(env)->ext_ssaia) { + return RISCV_EXCP_ILLEGAL_INST; + } + + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_AIA); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + if (!riscv_cpu_cfg(env)->ext_ssaia) { return RISCV_EXCP_ILLEGAL_INST; } @@ -2030,6 +2076,12 @@ static RISCVException rmw_xiselect(CPURISCVState *en= v, int csrno, target_ulong wr_mask) { target_ulong *iselect; + int ret; + + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } =20 /* Translate CSR number for VS-mode */ csrno =3D csrind_xlate_vs_csrno(env, csrno); @@ -2200,6 +2252,11 @@ static RISCVException rmw_xireg(CPURISCVState *env, = int csrno, int ret =3D -EINVAL; target_ulong isel; =20 + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + /* Translate CSR number for VS-mode */ csrno =3D csrind_xlate_vs_csrno(env, csrno); =20 @@ -2678,6 +2735,19 @@ static RISCVException write_mstateen0(CPURISCVState = *env, int csrno, wr_mask |=3D SMSTATEEN0_P1P13; } =20 + if (riscv_cpu_cfg(env)->ext_smaia) { + wr_mask |=3D SMSTATEEN0_SVSLCT; + } + + /* + * As per the AIA specification, SMSTATEEN0_IMSIC is valid only if IMS= IC is + * implemented. However, that information is with MachineState and we = can't + * figure that out in csr.c. Just enable if Smaia is available. + */ + if (riscv_cpu_cfg(env)->ext_smaia) { + wr_mask |=3D (SMSTATEEN0_AIA | SMSTATEEN0_IMSIC); + } + return write_mstateen(env, csrno, wr_mask, new_val); } =20 @@ -2758,6 +2828,19 @@ static RISCVException write_hstateen0(CPURISCVState = *env, int csrno, wr_mask |=3D SMSTATEEN0_FCSR; } =20 + if (riscv_cpu_cfg(env)->ext_ssaia) { + wr_mask |=3D SMSTATEEN0_SVSLCT; + } + + /* + * As per the AIA specification, SMSTATEEN0_IMSIC is valid only if IMS= IC is + * implemented. However, that information is with MachineState and we = can't + * figure that out in csr.c. Just enable if Ssaia is available. + */ + if (riscv_cpu_cfg(env)->ext_ssaia) { + wr_mask |=3D (SMSTATEEN0_AIA | SMSTATEEN0_IMSIC); + } + return write_hstateen(env, csrno, wr_mask, new_val); } =20 --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267887; cv=none; d=zohomail.com; s=zohoarc; b=Atms6kXvuSpJl8sqXUnV5OOvEnags5aqkKCu1pkoIAtMRayITxIjv2wB+ZSRXpz98Rt1xXzPGi5CgBfSXdFfYYHKCLvbjfYHhfk0Pd5nt12RP7sRI6v/+bOKJJkICkdlqj0C6yLnQs68YFSnhhUdJTf0f+EOgahnuGlJ0T0it9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267887; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6ddN6SdqQg7ukvbQ2Vu2DeDWsVWqNeVtoQ+eBROZ4d8=; b=VnwkUcOONaEZkn55kNHAOeaYmTwIcZRKY5082vJrhKpkZ9kI3KH7tiliFVFqFb9CBfSdWe4t6/r2+oqNB83+ChZzIz7Zari8B4MSRcGBrrtrT6BunBBVi2O4xFZKpmHPPwL4ikn1ZoEJ/a4ZZPt/BS9m+tQa3JS+LJZXke6xfVI= 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 1733267887639790.6305171513153; Tue, 3 Dec 2024 15:18:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6a-0001Iv-N1; Tue, 03 Dec 2024 18:14:56 -0500 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 1tIc6X-0001HV-Uw for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:53 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6V-0001Ix-IZ for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:53 -0500 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-7fbce800ee5so6129201a12.2 for ; Tue, 03 Dec 2024 15:14:51 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267690; x=1733872490; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6ddN6SdqQg7ukvbQ2Vu2DeDWsVWqNeVtoQ+eBROZ4d8=; b=dSDqv9SUWdS9+pwtnL5uo2C+x3ptz5ab71dRBwuyKQSr/2uyWVF+1MW56Q4oDmSEGd EC0RjH5OhoB8jrh5CexyvOwCBERc+t8/mgj4ZKajyE7AO1GE9Crx/Xw9PQWgUorIZaWd NhVxioHoWGHYj4Kb9ZSMD7Lmud/NxndIW4xk7KKNnHc8T5bxJy2VqfG0mzPxxu+9pSPw kPZrgCegbXJr9dE4SDUxA+KE6zFTiT3H4dCDnuDrYNdLKisZa3iYxoevjUYjIvr92HJl W2RC540QEbd9WvqvBtHuAeuAaqXcPc1UaeqvbNvPuH/t7b5KeHRijb/FUxpGmyKbACo3 9d1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267690; x=1733872490; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ddN6SdqQg7ukvbQ2Vu2DeDWsVWqNeVtoQ+eBROZ4d8=; b=vikPMYtEInwKs8n2Gt+6v8YrtclGF+qp/A45m1SzdP6EpIglNixYP67vnDVVUEJVMS YicRBjXO43EZCSJ5WBO9mdEGqhiUTO0NR1xpl6CJ3aSmO63U6c4zqbGgU4NrRNLtK+yK p7JUvjrivNANPMTrL27FTqdehGpjl7vjsscoQOjyirwRYHrnc9gU+8Uoi+DGAJdHVqI1 AR/zEBWqMFhLq7bKoZwI9kghZBvrA6aTxylY9LVi4MIdtSBJeOTYaXq3JhpXfdmCAI0O daeabs9Cbrcce37zNYXHQ0tlSSK1B2YQGRODcTYQlxR/nH4VdSd1Ce3uW6Gqg1QnVOKk 82Yg== X-Forwarded-Encrypted: i=1; AJvYcCVbhH+iwVZP5UBl9d9fnBW2lErgZQt1Gx8AFmIes2GOZX5d3rUPG66JW3tHrFYFuCEsD1LxRAbvqa2I@nongnu.org X-Gm-Message-State: AOJu0YyS/9/hOvZpgxuvMx21EpdjfPAL0PI8HazrEJJ4ggnnLk23SA/U ZU1DYr0rjVzbjZ8WYSE/IAFOGVQYaBY7a03qi/B0BeKOWiYkkrlh8prt7W0KIbk= X-Gm-Gg: ASbGncse+Bi/rGuzzjb98xW6Y1XMirClOvAc7xfV5VESjzOOpJQK7Argd7VnZxWbpxp lHPICByTo/DyV2tQxp1wlejhpg5DNbqs1JMgyzsBEr5Pu+ASpRabA+Eoy43WF6fngst1pMON3Ob jp3KTELz+JaFvDptCEESKaTFAgd8yS0fJbictFbOhl3SanO7bCAwz46qyiMqK92cP9OcAxcCqCD KYxGr9Ote1jnHRs9eoeVreurxddL1i3OMZjLzWE9MfSalt1BLlp0hDvMlQkr+I= X-Google-Smtp-Source: AGHT+IGmpC9YKh768Zc+vF/NJox8kvweiKFmbp8YFDEMu71MoKjqLxkEDRDflub0ivuDZPkpmkyyVg== X-Received: by 2002:a05:6a20:244f:b0:1d6:fb3e:78cf with SMTP id adf61e73a8af0-1e165410fbdmr5848197637.41.1733267690067; Tue, 03 Dec 2024 15:14:50 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:42 -0800 Subject: [PATCH v4 04/11] target/riscv: Support generic CSR indirect access MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-4-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com, Kaiwen Xue X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::536; envelope-from=atishp@rivosinc.com; helo=mail-pg1-x536.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267888193116600 From: Kaiwen Xue This adds the indirect access registers required by sscsrind/smcsrind and the operations on them. Note that xiselect and xireg are used for both AIA and sxcsrind, and the behavior of accessing them depends on whether each extension is enabled and the value stored in xiselect. Co-developed-by: Atish Patra Signed-off-by: Atish Patra Signed-off-by: Kaiwen Xue Acked-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza --- target/riscv/cpu_bits.h | 28 +++++++++- target/riscv/csr.c | 144 ++++++++++++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 166 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 385a2c67c24b..e13c5420a251 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -173,6 +173,13 @@ #define CSR_MISELECT 0x350 #define CSR_MIREG 0x351 =20 +/* Machine Indirect Register Alias */ +#define CSR_MIREG2 0x352 +#define CSR_MIREG3 0x353 +#define CSR_MIREG4 0x355 +#define CSR_MIREG5 0x356 +#define CSR_MIREG6 0x357 + /* Machine-Level Interrupts (AIA) */ #define CSR_MTOPEI 0x35c #define CSR_MTOPI 0xfb0 @@ -222,6 +229,13 @@ #define CSR_SISELECT 0x150 #define CSR_SIREG 0x151 =20 +/* Supervisor Indirect Register Alias */ +#define CSR_SIREG2 0x152 +#define CSR_SIREG3 0x153 +#define CSR_SIREG4 0x155 +#define CSR_SIREG5 0x156 +#define CSR_SIREG6 0x157 + /* Supervisor-Level Interrupts (AIA) */ #define CSR_STOPEI 0x15c #define CSR_STOPI 0xdb0 @@ -288,6 +302,13 @@ #define CSR_VSISELECT 0x250 #define CSR_VSIREG 0x251 =20 +/* Virtual Supervisor Indirect Alias */ +#define CSR_VSIREG2 0x252 +#define CSR_VSIREG3 0x253 +#define CSR_VSIREG4 0x255 +#define CSR_VSIREG5 0x256 +#define CSR_VSIREG6 0x257 + /* VS-Level Interrupts (H-extension with AIA) */ #define CSR_VSTOPEI 0x25c #define CSR_VSTOPI 0xeb0 @@ -863,10 +884,13 @@ typedef enum RISCVException { #define ISELECT_IMSIC_EIE63 0xff #define ISELECT_IMSIC_FIRST ISELECT_IMSIC_EIDELIVERY #define ISELECT_IMSIC_LAST ISELECT_IMSIC_EIE63 -#define ISELECT_MASK 0x1ff +#define ISELECT_MASK_AIA 0x1ff + +/* MISELECT, SISELECT, and VSISELECT bits (AIA) */ +#define ISELECT_MASK_SXCSRIND 0xfff =20 /* Dummy [M|S|VS]ISELECT value for emulating [M|S|VS]TOPEI CSRs */ -#define ISELECT_IMSIC_TOPEI (ISELECT_MASK + 1) +#define ISELECT_IMSIC_TOPEI (ISELECT_MASK_AIA + 1) =20 /* IMSIC bits (AIA) */ #define IMSIC_TOPEI_IID_SHIFT 16 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index c91a26a52ef6..424e9dbbd4ff 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -306,6 +306,15 @@ static RISCVException aia_any32(CPURISCVState *env, in= t csrno) return any32(env, csrno); } =20 +static RISCVException csrind_any(CPURISCVState *env, int csrno) +{ + if (!riscv_cpu_cfg(env)->ext_smcsrind) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; +} + static RISCVException csrind_or_aia_any(CPURISCVState *env, int csrno) { if (!riscv_cpu_cfg(env)->ext_smaia && !riscv_cpu_cfg(env)->ext_smcsrin= d) { @@ -389,6 +398,15 @@ static bool csrind_or_aia_extensions_present(CPURISCVS= tate *env) return csrind_extensions_present(env) || aia_extensions_present(env); } =20 +static RISCVException csrind_smode(CPURISCVState *env, int csrno) +{ + if (!csrind_extensions_present(env)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return smode(env, csrno); +} + static RISCVException csrind_or_aia_smode(CPURISCVState *env, int csrno) { if (!csrind_or_aia_extensions_present(env)) { @@ -417,6 +435,15 @@ static RISCVException hmode32(CPURISCVState *env, int = csrno) =20 } =20 +static RISCVException csrind_hmode(CPURISCVState *env, int csrno) +{ + if (!csrind_extensions_present(env)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return hmode(env, csrno); +} + static RISCVException csrind_or_aia_hmode(CPURISCVState *env, int csrno) { if (!csrind_or_aia_extensions_present(env)) { @@ -2065,7 +2092,12 @@ static int csrind_xlate_vs_csrno(CPURISCVState *env,= int csrno) case CSR_SISELECT: return CSR_VSISELECT; case CSR_SIREG: - return CSR_VSIREG; + case CSR_SIREG2: + case CSR_SIREG3: + case CSR_SIREG4: + case CSR_SIREG5: + case CSR_SIREG6: + return CSR_VSIREG + (csrno - CSR_SIREG); default: return csrno; }; @@ -2105,7 +2137,12 @@ static RISCVException rmw_xiselect(CPURISCVState *en= v, int csrno, *val =3D *iselect; } =20 - wr_mask &=3D ISELECT_MASK; + if (riscv_cpu_cfg(env)->ext_smcsrind || riscv_cpu_cfg(env)->ext_sscsri= nd) { + wr_mask &=3D ISELECT_MASK_SXCSRIND; + } else { + wr_mask &=3D ISELECT_MASK_AIA; + } + if (wr_mask) { *iselect =3D (*iselect & ~wr_mask) | (new_val & wr_mask); } @@ -2244,6 +2281,56 @@ done: return RISCV_EXCP_NONE; } =20 +/* + * rmw_xireg_csrind: Perform indirect access to xireg and xireg2-xireg6 + * + * Perform indirect access to xireg and xireg2-xireg6. + * This is a generic interface for all xireg CSRs. Apart from AIA, all oth= er + * extension using csrind should be implemented here. + */ +static int rmw_xireg_csrind(CPURISCVState *env, int csrno, + target_ulong isel, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + return -EINVAL; +} + +static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + bool virt =3D false; + int ret =3D -EINVAL; + target_ulong isel; + + ret =3D smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } + + /* Translate CSR number for VS-mode */ + csrno =3D csrind_xlate_vs_csrno(env, csrno); + + if (CSR_MIREG <=3D csrno && csrno <=3D CSR_MIREG6 && + csrno !=3D CSR_MIREG4 - 1) { + isel =3D env->miselect; + } else if (CSR_SIREG <=3D csrno && csrno <=3D CSR_SIREG6 && + csrno !=3D CSR_SIREG4 - 1) { + isel =3D env->siselect; + } else if (CSR_VSIREG <=3D csrno && csrno <=3D CSR_VSIREG6 && + csrno !=3D CSR_VSIREG4 - 1) { + isel =3D env->vsiselect; + virt =3D true; + } else { + goto done; + } + + return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask); + +done: + return (env->virt_enabled && virt) ? + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; +} + static RISCVException rmw_xireg(CPURISCVState *env, int csrno, target_ulong *val, target_ulong new_val, target_ulong wr_mask) @@ -2276,8 +2363,21 @@ static RISCVException rmw_xireg(CPURISCVState *env, = int csrno, goto done; }; =20 + /* + * Use the xiselect range to determine actual op on xireg. + * + * Since we only checked the existence of AIA or Indirect Access in the + * predicate, we should check the existence of the exact extension when + * we get to a specific range and return illegal instruction exception= even + * in VS-mode. + */ if (xiselect_aia_range(isel)) { return rmw_xireg_aia(env, csrno, isel, val, new_val, wr_mask); + } else if (riscv_cpu_cfg(env)->ext_smcsrind || + riscv_cpu_cfg(env)->ext_sscsrind) { + return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask); + } else { + return RISCV_EXCP_ILLEGAL_INST; } =20 done: @@ -2735,7 +2835,7 @@ static RISCVException write_mstateen0(CPURISCVState *= env, int csrno, wr_mask |=3D SMSTATEEN0_P1P13; } =20 - if (riscv_cpu_cfg(env)->ext_smaia) { + if (riscv_cpu_cfg(env)->ext_smaia || riscv_cpu_cfg(env)->ext_smcsrind)= { wr_mask |=3D SMSTATEEN0_SVSLCT; } =20 @@ -2828,7 +2928,7 @@ static RISCVException write_hstateen0(CPURISCVState *= env, int csrno, wr_mask |=3D SMSTATEEN0_FCSR; } =20 - if (riscv_cpu_cfg(env)->ext_ssaia) { + if (riscv_cpu_cfg(env)->ext_ssaia || riscv_cpu_cfg(env)->ext_sscsrind)= { wr_mask |=3D SMSTATEEN0_SVSLCT; } =20 @@ -5261,6 +5361,18 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MIREG] =3D { "mireg", csrind_or_aia_any, NULL, NULL, rmw_xireg }, =20 + /* Machine Indirect Register Alias */ + [CSR_MIREG2] =3D { "mireg2", csrind_any, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MIREG3] =3D { "mireg3", csrind_any, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MIREG4] =3D { "mireg4", csrind_any, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MIREG5] =3D { "mireg5", csrind_any, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MIREG6] =3D { "mireg6", csrind_any, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + /* Machine-Level Interrupts (AIA) */ [CSR_MTOPEI] =3D { "mtopei", aia_any, NULL, NULL, rmw_xtopei }, [CSR_MTOPI] =3D { "mtopi", aia_any, read_mtopi }, @@ -5382,6 +5494,18 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_SIREG] =3D { "sireg", csrind_or_aia_smode, NULL, NULL, rmw_xireg = }, =20 + /* Supervisor Indirect Register Alias */ + [CSR_SIREG2] =3D { "sireg2", csrind_smode, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_SIREG3] =3D { "sireg3", csrind_smode, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_SIREG4] =3D { "sireg4", csrind_smode, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_SIREG5] =3D { "sireg5", csrind_smode, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_SIREG6] =3D { "sireg6", csrind_smode, NULL, NULL, rmw_xiregi, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + /* Supervisor-Level Interrupts (AIA) */ [CSR_STOPEI] =3D { "stopei", aia_smode, NULL, NULL, rmw_xtopei= }, [CSR_STOPI] =3D { "stopi", aia_smode, read_stopi }, @@ -5464,6 +5588,18 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_VSIREG] =3D { "vsireg", csrind_or_aia_hmode, NULL, NULL, rmw_xireg = }, =20 + /* Virtual Supervisor Indirect Alias */ + [CSR_VSIREG2] =3D { "vsireg2", csrind_hmode, NULL, NULL, rmw_xireg= i, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_VSIREG3] =3D { "vsireg3", csrind_hmode, NULL, NULL, rmw_xireg= i, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_VSIREG4] =3D { "vsireg4", csrind_hmode, NULL, NULL, rmw_xireg= i, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_VSIREG5] =3D { "vsireg5", csrind_hmode, NULL, NULL, rmw_xireg= i, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_VSIREG6] =3D { "vsireg6", csrind_hmode, NULL, NULL, rmw_xireg= i, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + /* VS-Level Interrupts (H-extension with AIA) */ [CSR_VSTOPEI] =3D { "vstopei", aia_hmode, NULL, NULL, rmw_xtop= ei }, [CSR_VSTOPI] =3D { "vstopi", aia_hmode, read_vstopi }, --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267787; cv=none; d=zohomail.com; s=zohoarc; b=fIFvN+UYVOahNwHK4dvkJJGAV9Ej2s3eHZJdaFwflCHbNrEYCtGlbodXygE10BQZoQq9aYdupQBA+jF8XbedpYkqmGPdO6dD/8T0ziQCkOTd9igSLuyGvaQvxUgUSoOyFwfC71IjU8cO2F3HdUUeUD3aMirT3owihe4c3PBn0Qo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267787; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FyiLgrScJsMZeBZ1bSE7OPq3hdaSp5RGPvZtqSAwd9A=; b=QxFN7exFXfFquUeQ18j6S0c1sFTwtParcYNLu7vxxOt4JtgXOG4uu8cG1aDk4pwQ+ULJMc6dYE0oS8OxtuPsDF3HVzb/gaDX4rxHEbsF/fbMjJmiQ2FGp290gPf4WbYC893Ibue/IbxHdUosKkgFYD2KPVi5H6+hvwbSed06APk= 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 1733267787228448.1326863774118; Tue, 3 Dec 2024 15:16:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6b-0001Jo-QR; Tue, 03 Dec 2024 18:14:57 -0500 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 1tIc6Y-0001I4-F1 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:54 -0500 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6W-0001JG-Eu for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:54 -0500 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7ea8de14848so4283395a12.2 for ; Tue, 03 Dec 2024 15:14:52 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267691; x=1733872491; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FyiLgrScJsMZeBZ1bSE7OPq3hdaSp5RGPvZtqSAwd9A=; b=TJFXyVpAwEA+AURxZsP+8/xl+l541T+2tvSxpzBFBn90WCPOUcPeg5XS58e7h+16XC K03kPQmWuV2G5hVUUI4YFGvq6LYtx2Pzecf8s1ZP7EzYYFDSN0WHl7NNy3X1vtkqGn6t +xFPu3Qe5IFxVj+I6+Ko4iRu2RE8NmtYCz8DSkxSp196mfxsXWjhMJ+PUauw7iLZAIYN ZXj/8JCftE0MrgrdCvnmYz81AY1EYt2OB6UtgShxosfKWyy3GTkL3tw47z6omP/qNaT2 KZ+vT+u11Bi/mYTGR/PTaqMKrdA6teucvO4yEaHJPta5U6viZrS0w6L1EIY4y3LHVAer NTsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267691; x=1733872491; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FyiLgrScJsMZeBZ1bSE7OPq3hdaSp5RGPvZtqSAwd9A=; b=gvV+RYDQuiupBvA517w6YBvi5AkxyAaP7OBNEH9mRk+U+yQV/CzrbzFdpvV4DT5NOY kVd12eWKeWxrmGROmkrHHKLrcG1LgmwGM+qSjO/ZL2MdIVEH6JvwwZjUNTyExB3h0UbZ OmbJk2THo9ITG+LliUvxSjFppziK1TyKKkJRB6BzWWyYbVyrUTiXhIAWZxEmbALofUCc o9nJVuJO5v7IJbvahKnygzfIIPpUfk/1MNDp/yM/nYdOjBlEeGW9br1l1U34kIiSbMwI +BYlhqH/tNM6uEoOQZuH3C3qlgY8NN8U0/lDwNZ96rzsndveIX11RzTYmWfm2YrYHbYd b+Bg== X-Forwarded-Encrypted: i=1; AJvYcCWO0MnzU2RpKww9iEuAFOeHITeQIAKDooAGdkYWiRCE8ow0iMzUleC7xMBcHHo9vpwLZA2QjU1Td93k@nongnu.org X-Gm-Message-State: AOJu0Yxw7BanH5T+F2GmVfpp8NIZwkaKL/6snkGe0jmbehtYQUM8W2be YXkz/3ftAjycEnqhijJS8xMdLyqY5yFNzBLiQ/w08VGNBXLo+eIZ941YXdizot8= X-Gm-Gg: ASbGncs6sLeycZC1Lu+mQE50krytYWFUyHN48Wei30qSU0AC4OUlStinDbBopHjFDEx 5+nidxyXsBfNm5hTmR5OYdYzyxLLjRhsHDAtrGm6zN+1nIu98ThSIaQ62OyOp8BISGmVZxlxC8m mbhLMQwOKsx3mzQetv54ERZpKjBFzeYWNPwifcs+6J5ZQ6RBBZCFcc1wR3xqE+AJWDDn0kM85Ef pskuHTNUzJTCc3/2/plXmDyZw8Xa5LUe6CwzjXA2knJ63HdZP3eImtW5ONC14c= X-Google-Smtp-Source: AGHT+IEfbIvb8FoeZ5Y1G7BRUQ1hMVBquV2hB0NHd2V183vF8K7nU3w+h4tC7Zmj43pxEPqnrokZ8g== X-Received: by 2002:a05:6a20:748f:b0:1db:d932:ddcc with SMTP id adf61e73a8af0-1e1653c4a75mr6491682637.19.1733267691121; Tue, 03 Dec 2024 15:14:51 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:43 -0800 Subject: [PATCH v4 05/11] target/riscv: Add properties for counter delegation ISA extensions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-5-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::530; envelope-from=atishp@rivosinc.com; helo=mail-pg1-x530.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267789841116600 This adds the properties for counter delegation ISA extensions (Smcdeleg/Ssccfg). Definitions of new registers and and implementation will come in the next set of patches. Reviewed-by: Daniel Henrique Barboza Signed-off-by: Atish Patra Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 963f1f3af9ae..82edd28e2e1d 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -184,11 +184,13 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), + ISA_EXT_DATA_ENTRY(smcdeleg, PRIV_VERSION_1_13_0, ext_smcdeleg), ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind), ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), + ISA_EXT_DATA_ENTRY(ssccfg, PRIV_VERSION_1_13_0, ext_ssccfg), ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 8b974255f6fb..ae2b019703fe 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -78,6 +78,8 @@ struct RISCVCPUConfig { bool ext_ztso; bool ext_smstateen; bool ext_sstc; + bool ext_smcdeleg; + bool ext_ssccfg; bool ext_smcntrpmf; bool ext_smcsrind; bool ext_sscsrind; --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267836; cv=none; d=zohomail.com; s=zohoarc; b=L+mUV7c3s+B8zypFUnBSYMXp2QwQCHnkU836h4GHLceLFFBPqhT/i+B/A3cFah7v78XvB4E5s8BL/NS+kKJVmIW+OzRBhguqcLyKcnvKhqhtjbMltxOxgLvENvpU1c6TwEKZ7/up5aEpLTt8e63v9l5eH2OsyIlbIUQRzM5J2v0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LMnKYE8WPdvKl7s3HVfAdc/3hWY0P2i17ofoTw5jOGw=; b=Zcjspk1CJf6E15QYlXdmQevI5cE0Ot8tDGT7CveOHd/JMIINxzjPsB5NIa50iLT7aSAcJAJBrnGQzRHAox+aHOwnYpcQIQlOg/jX8hfrejLzy2OXsAYZhvWj9iIvmvqtfpn/kJDVIWqFHKHm1GkcalHoZLeRil9N9+XOil7x7lM= 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 1733267836144829.5774114496678; Tue, 3 Dec 2024 15:17:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6d-0001Lj-GA; Tue, 03 Dec 2024 18:14:59 -0500 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 1tIc6Z-0001IP-Eo for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:56 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6X-0001Jv-M4 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:55 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-215b0582aaeso16568785ad.3 for ; Tue, 03 Dec 2024 15:14:53 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267692; x=1733872492; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LMnKYE8WPdvKl7s3HVfAdc/3hWY0P2i17ofoTw5jOGw=; b=N6nvTfJm4dkJQHfcWF2jlj6wT/l7YnNWXbx+02kjm42lVIjR9Bde2oywvuYu58z+om P1+ks3K2v3gyI0rtvhY1gb1OftrEbTIOHDnE0c/FxJFeJLkwbRMfFJSi3si4Q7aM7EzX YIFoxycE/1aDlhMBN8GvDatJ7JMS4iTlz3HtykekVMrylslO1Rzz7BF+Kfwk0rSkR9nm B7Io24uteT52ovXvWTqtRM3pm2Krf9h0uCdtDJW1ES2MWm8Bgumhu0WCu6oEKy1i26hZ tPHM1H/2JTYLpDZXOqT9wUDInZ7sVv8fRLymCbHH621K1k2yHSNU6Qz1BR9v3VSjoWIV Pukw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267692; x=1733872492; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LMnKYE8WPdvKl7s3HVfAdc/3hWY0P2i17ofoTw5jOGw=; b=Ip28u+0njedD2hbzgobaSuBUJIzdclUAw0pz3PYREn/0YH8ApqNe6noQJd5WSCisSl Ew1H8xnwBWgaJJMpFbaKRzm1fDMU+vx03EVmCxPMfkVjd4N1OGFeioLKY3zodpY7/4xR A8lZcdp7+szFIQ+grCjP0kNNIdRxFgM76jpH9E06waKNrqWNXCEpXYO10jhFUGJRsJLN df+pH9/jaA97y7fSiDCPwkPKJbIMcpQg0T+DaOWlBnSZUCdKAu9V7OCIwbZArIByZDXk /Xj6yqg4aHnsEHKRqbJNnGrZnLsdhvbq8NHc4ET9/GBf1WuNfiiAAHfcbpCDHnM8P5Rw S70w== X-Forwarded-Encrypted: i=1; AJvYcCX69dbdG8vJDBtq/VfmF6aBUB5Xt4zRl8fI5HqZhCLpKO+oVo95drIpBdcZTFbIIZRGpqIdWNBNdw4w@nongnu.org X-Gm-Message-State: AOJu0Yx3R4Fadc29o3PACZ4j7rV6nsQqD1T6Xq8r+BYUmOv5N0Sn1VjN 8KfV07f5Lfh4g4aMYaEZfAb1OfwCsWYlYPARKI7ugNowgqdginGqb61nFuYxyEU= X-Gm-Gg: ASbGncvrbD2bHpNC8IDHcpHMpq1v5sK+EzHuwtDXvXmQawGp2GccjBiDlWq+tynRKMN +MgNHITHqEkzfxEuBAp1TFn8tBs+JRmOCATZgWzXfuK0k35qsVtt14nDv1m0/zeO5BflbVGicsU XXO444hfHo6FzpJlNF95ttmFByl1ggLv/yo1uQa8xAeDiMfgM8uDTvhKvsqabwz/txI/bTakTZi tH6q9Inur2wpXjV8GMFPeZzrD1fYiZh59nvdUII+X4zalNXqotv7TfCxNomDn0= X-Google-Smtp-Source: AGHT+IFTgjURCicqPJ47SCN5f1t5Kdxv4N9lllPghpOB6pd05/fucO0zpFKBOtq9qx0M2KK7LA/tYQ== X-Received: by 2002:a17:903:32ce:b0:215:7742:73d6 with SMTP id d9443c01a7336-215bd0c4b00mr48972105ad.20.1733267692201; Tue, 03 Dec 2024 15:14:52 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:44 -0800 Subject: [PATCH v4 06/11] target/riscv: Add counter delegation definitions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-6-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com, Kaiwen Xue X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::62f; envelope-from=atishp@rivosinc.com; helo=mail-pl1-x62f.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 autolearn=ham autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267837789116600 From: Kaiwen Xue This adds definitions for counter delegation, including the new scountinhibit register and the mstateen.CD bit. Signed-off-by: Kaiwen Xue Reviewed-by: Alistair Francis Signed-off-by: Atish Patra --- target/riscv/cpu.h | 1 + target/riscv/cpu_bits.h | 8 +++++++- target/riscv/machine.c | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 284b11282197..903268626374 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -385,6 +385,7 @@ struct CPUArchState { uint32_t scounteren; uint32_t mcounteren; =20 + uint32_t scountinhibit; uint32_t mcountinhibit; =20 /* PMU cycle & instret privilege mode filtering */ diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index e13c5420a251..4ac065ac5e5a 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -210,6 +210,9 @@ #define CSR_SSTATEEN2 0x10E #define CSR_SSTATEEN3 0x10F =20 +/* Supervisor Counter Delegation */ +#define CSR_SCOUNTINHIBIT 0x120 + /* Supervisor Trap Handling */ #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 @@ -791,6 +794,7 @@ typedef enum RISCVException { #define MENVCFG_CBIE (3UL << 4) #define MENVCFG_CBCFE BIT(6) #define MENVCFG_CBZE BIT(7) +#define MENVCFG_CDE (1ULL << 60) #define MENVCFG_ADUE (1ULL << 61) #define MENVCFG_PBMTE (1ULL << 62) #define MENVCFG_STCE (1ULL << 63) @@ -886,7 +890,9 @@ typedef enum RISCVException { #define ISELECT_IMSIC_LAST ISELECT_IMSIC_EIE63 #define ISELECT_MASK_AIA 0x1ff =20 -/* MISELECT, SISELECT, and VSISELECT bits (AIA) */ +/* [M|S|VS]SELCT value for Indirect CSR Access Extension */ +#define ISELECT_CD_FIRST 0x40 +#define ISELECT_CD_LAST 0x5f #define ISELECT_MASK_SXCSRIND 0xfff =20 /* Dummy [M|S|VS]ISELECT value for emulating [M|S|VS]TOPEI CSRs */ diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 99f0af507717..e1bdc31c7c53 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -434,6 +434,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINTTL(env.siselect, RISCVCPU), VMSTATE_UINT32(env.scounteren, RISCVCPU), VMSTATE_UINT32(env.mcounteren, RISCVCPU), + VMSTATE_UINT32(env.scountinhibit, RISCVCPU), VMSTATE_UINT32(env.mcountinhibit, RISCVCPU), VMSTATE_STRUCT_ARRAY(env.pmu_ctrs, RISCVCPU, RV_MAX_MHPMCOUNTERS, = 0, vmstate_pmu_ctr_state, PMUCTRState), --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267790; cv=none; d=zohomail.com; s=zohoarc; b=UDP35Dij+XNU2Rla6BXBtvyUgREarrauzDmIlcy4dLsHc0p+45z3lhVdhsMLV0/fw/EpLR4Q7HBCK9+ziXewVpCxNEjLSTg0G0Hox9hIwr0LcC1tsBrt6PayJ4ctXU9OwLrSs4kjCMpPXXe6AZO7MWzZE4lMX7FxVDH4JpstuJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267790; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LdFNd6tBzEDXZhXA50p/zVov//j7cpToaodVCiWJBjM=; b=AuvjjJkpVRHB2KiZn+nwVMg6KGGZPdBFHmwY4LjPBZJzdoTHozjjS76esOlSP4Vvh2PhxGgviJt8x+laluxUZgZBpe64WmduM7B0XSJjYqK4iaLkhgQA+mkF1UmBSRBnl8rXJYAtOJEW/XtAqRurV+9J58fKLQAcZZaUIS2bviA= 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 173326779081959.252308527625814; Tue, 3 Dec 2024 15:16:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6f-0001NC-0B; Tue, 03 Dec 2024 18:15:01 -0500 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 1tIc6a-0001Iz-Oq for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:56 -0500 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6Z-0001KO-2d for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:56 -0500 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7253bc4d25eso251940b3a.0 for ; Tue, 03 Dec 2024 15:14:54 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267693; x=1733872493; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LdFNd6tBzEDXZhXA50p/zVov//j7cpToaodVCiWJBjM=; b=boTPZ/n+V+wzJC2ma9+vfISsqGUDI3VJOvnsfL7Zt3bIz1AbEufsyLA4pNVMU9d7UP V8H44/7k9/0S8V96Ix3RQp6/AUc99ysk2qhBl+bQmU3vKs0yN+DMF6JWb2wZbeSWthUv JWNFdJ4CCyeJ8rOeFYh3YXmy+c6tOzc2D2JxfQIBGncWtW4Wvs3/fcrMp/3Ox8qkfScI HdQXtEnWhlX7ki/s1joo3dSTkt2KKW1GkHr+FavZUfJRvohT/addsF9GyPFyWubFD2Ez Dnd5fo7RciGW2sA6h8XTAoasakkmoXGjmsxRccVBQ43Gxf3WUlTPzCLkkz9iNO3UmMov vgEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267693; x=1733872493; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LdFNd6tBzEDXZhXA50p/zVov//j7cpToaodVCiWJBjM=; b=haJmgbK4mkIxkeqfdLKbq8Qn9Y1PkWSj/JdhjKW9wwVgfdGRPsiYYWkRB3TgNYkuaY 86UyADllvQegWEsTNk1ug1csnTN1hZPdeClmmTdh/b4hP62nrgyeNoNR5ghs5EQojFTx 2/yMkfhGqULMGKJ9ApNUhXUXbaAxMTDet0+xGDCSFzuUBzPdQItH2FRwGsFNwX0Fg58Q IwjMYmlrVdafu+Pju+bGDJGtynnqcD0PQeTE+ZEC/O4W1kH4gWSf2FRR1hwLbZ7hEAYu k728CiAeBhacFM843X4bLnJRCreEUm7CWcFmqw8roRejrPeJdU7RvHdsJbxEnLDQcRgA HZKQ== X-Forwarded-Encrypted: i=1; AJvYcCWFK25jroTeTKVlnXOtb+PzJDFUJrrBLTo9n1E6jQ/Tql8gAg+qbmKxpQxt+UBblxVsecgjtGegbxWf@nongnu.org X-Gm-Message-State: AOJu0YzvIJqHVAQbwXJZRVI6RDLuFrNhLNNTQQr/v6VfGwy23U6HWSLf 1rqoSRxJ5i9DL3BNBXXKPXrOAd5T/KytuDVeMS9nP1bpJ6xiBTcdvX81x6vgU9o= X-Gm-Gg: ASbGncsoe/nDmy4Vp1NDVZJBHfOZ2d4AoMmatYnJCEmFW9qPrmWFoI/IyGgt2AIO6Dp ZLyMk1m/GlKSvSD3TI0oX7L30sOOFTO82jY7qKG4HtOBo7/AEInl4nDrKiHPAX3dH4NaBLmkVES iMH9fEeWkLnYNnqGmyaN6oOTvH4ondeiXMfoLySZOI4ZcdCnlbokeBcwbtsGN0A9q4ssU6xGd3g kfrrNbQZhk6/W37SvePKqSvyt2AUxnoFrMjjF64AbCs7xQfoAnJmCI5COA0FmA= X-Google-Smtp-Source: AGHT+IHWFzPbwlRhVNYMoWlMbaUjvPXySpHxbh7pbKjgJTNcr4HOVgux2X9xxXjmEBOSG9lQwGGeOQ== X-Received: by 2002:a05:6a00:4651:b0:725:37a4:8827 with SMTP id d2e1a72fcca58-7257f8dbeedmr7575973b3a.3.1733267693484; Tue, 03 Dec 2024 15:14:53 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:45 -0800 Subject: [PATCH v4 07/11] target/riscv: Add select value range check for counter delegation MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-7-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com, Kaiwen Xue X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::435; envelope-from=atishp@rivosinc.com; helo=mail-pf1-x435.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 autolearn=ham autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267791549116600 From: Kaiwen Xue This adds checks in ops performed on xireg and xireg2-xireg6 so that the counter delegation function will receive a valid xiselect value with the proper extensions enabled. Co-developed-by: Atish Patra Signed-off-by: Kaiwen Xue Reviewed-by: Alistair Francis Signed-off-by: Atish Patra --- target/riscv/csr.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 424e9dbbd4ff..0985dbdca76d 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2156,6 +2156,11 @@ static bool xiselect_aia_range(target_ulong isel) (ISELECT_IMSIC_FIRST <=3D isel && isel <=3D ISELECT_IMSIC_LAST); } =20 +static bool xiselect_cd_range(target_ulong isel) +{ + return (ISELECT_CD_FIRST <=3D isel && isel <=3D ISELECT_CD_LAST); +} + static int rmw_iprio(target_ulong xlen, target_ulong iselect, uint8_t *iprio, target_ulong *val, target_ulong new_val, @@ -2281,6 +2286,17 @@ done: return RISCV_EXCP_NONE; } =20 +static int rmw_xireg_cd(CPURISCVState *env, int csrno, + target_ulong isel, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + if (!riscv_cpu_cfg(env)->ext_smcdeleg) { + return RISCV_EXCP_ILLEGAL_INST; + } + /* TODO: Implement the functionality later */ + return RISCV_EXCP_NONE; +} + /* * rmw_xireg_csrind: Perform indirect access to xireg and xireg2-xireg6 * @@ -2292,7 +2308,25 @@ static int rmw_xireg_csrind(CPURISCVState *env, int = csrno, target_ulong isel, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { - return -EINVAL; + int ret =3D -EINVAL; + bool virt =3D csrno =3D=3D CSR_VSIREG ? true : false; + + if (xiselect_cd_range(isel)) { + ret =3D rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask); + } else { + /* + * As per the specification, access to unimplented region is undef= ined + * but recommendation is to raise illegal instruction exception. + */ + return RISCV_EXCP_ILLEGAL_INST; + } + + if (ret) { + return (env->virt_enabled && virt) ? + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; } =20 static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val, --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267791; cv=none; d=zohomail.com; s=zohoarc; b=hw3wMaW3OxFiT82k0i187wMMl42K3YHIW8w7wTHM1XhPHj8Ku69+CsAUnaXyiF0RoyTEHKxTOsLaHdUEEr/Be06c8B/e9N2PkYAaGvCZ5li+58KhSq7b2Mzsp1B80dBaHsQB4Mg+WE4UOf5Hkk7Z9dHck1ypVF2YcN1QXuBg1ZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267791; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XRhB3NOg6WFytSRkGTDAssg6WaUaHQdukH6It54foGQ=; b=X/kBsPxf2OBqPcDr/w1RoiPPW64JSVBfr80UKbd1RRdnGmgf3BuE5wkuapY7ojU6Dnx9P/FhLy+iD3WiXSLze79nuNe/e9E00B9ru190J/Mp1dOQLfodiK2WZnNK++Ho9gEeMvv9CDxbGXrKf+mo2SOpNKiLKaJ/xA+w30rj2oc= 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 1733267791235401.8944882868226; Tue, 3 Dec 2024 15:16:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6h-0001PZ-Hk; Tue, 03 Dec 2024 18:15:03 -0500 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 1tIc6c-0001Kz-IC for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:58 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6a-0001Kp-3h for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:58 -0500 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-724e14b90cfso6138394b3a.2 for ; Tue, 03 Dec 2024 15:14:55 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267694; x=1733872494; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=XRhB3NOg6WFytSRkGTDAssg6WaUaHQdukH6It54foGQ=; b=jXmUofXEdVR9ZrQINggmdUTZJq2UuDBK0VmwSgAo1BA7E5zn7M1meuT2XxyN0O+ZNr slwYUbUNPEeUVc6H+3I7IKDFMZNrByIjkUnQCjzIbw+/9IpjA3eNXVj/j9/g1UM0+qFD 2/4b/mb1x28Z8pdjXrD3q+qEBu1n+aE8nUlWq4EkCpXSsXL2RK9V+8O/cnN1Qa5YL+4l qeSvjcagcMrDV/qdlRoNXoi3k3A5t8vuFDZgvwnhrjRJ7RizRHZFOoU4rXnbOI/NmF5o AQGG4NbGPMjlErO1vIZT0KAT9RK+sca6VtugZDQWgux7xkOtcNagMnf0pxpdALO+NI4M 8XUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267694; x=1733872494; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XRhB3NOg6WFytSRkGTDAssg6WaUaHQdukH6It54foGQ=; b=OtzHsXZZaoHTMQBpb1519esvqHe+DXiJU2kS7iMsLmr6aO+6qyU0Qi0ufI27WTvgKL 0rGbLDOjGecYDGqjxUSQPIHPKvMFegUDHbUijLRTOI8MnurG0DtpJEb7VHJEwvKSkwgz 6vyZFkcZGypF7iyJWQvvDQBfWeVqbrxi1mgcSPre9d7LVBngWdp+A8OA1+jXkc/kwqAQ oHl0VvxEMf+/XSdto4FQTnrOExa+TUsjBauXbbFghm4Cl3CuhzLCKrDB9eztWCsZgnQM DZKvnGVdaGzq4TxW2y5mSPprwUecmZdyNlF4KDNxLFUjHCnA+cN519BUMkcNIDC9uRmm 2dqw== X-Forwarded-Encrypted: i=1; AJvYcCWWUwpLtemzw+1GPSQXiUrDxR/MLup485cHkYiO3+3LLziCKEJJ5cpDNd7J2ZI7PI3Yf3V/YmvhEfnF@nongnu.org X-Gm-Message-State: AOJu0Yz9mJjAyJ72yefsQ6uTmO8fJpdasp7QMKvbaot/wS/S42Iqo0LB 8JLPuEJZOBV1hH8SKLp+n9G6jhDeAtIOUl54o+ojv/R/mQqjt3e3nwtuhinTs8M= X-Gm-Gg: ASbGncsTJLwdrf8w/Y1CfJ4loHoUtkgbeLRkwpMn36WuZ0E6xvakSvY/dZ4NE9no4O9 89Va84LBXwkYnobYFhZPvRv1pLK4PVYplH5BM+yaMdvEcytjueICPLsIObAdbIZ8mt1fY/Aa2rZ TOvlmD2qwbkuDY74aG9A+5JXTNqaR8+nzl9Gd1o7/U1bt510cV888jCK1oaGbH0UQFB+SZ3QsZf pwZxDqh1JeQw5Z2IZ8G49C77TOgsOLpKtJQg2tHC1FkI1voyO3NpkjSa1RN24A= X-Google-Smtp-Source: AGHT+IEQ72ZChzEml7gPJrIzVb5lQs+Libj5HRyer8Pi1ZIc9aasy24IKJiw3gNq+V3tAYmOqRNRow== X-Received: by 2002:a05:6a00:3c8a:b0:71e:1722:d02c with SMTP id d2e1a72fcca58-7257fa3a16cmr6074854b3a.3.1733267694566; Tue, 03 Dec 2024 15:14:54 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:46 -0800 Subject: [PATCH v4 08/11] target/riscv: Add counter delegation/configuration support MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-8-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com, Kaiwen Xue X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::436; envelope-from=atishp@rivosinc.com; helo=mail-pf1-x436.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 autolearn=ham autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267793725116600 From: Kaiwen Xue The Smcdeleg/Ssccfg adds the support for counter delegation via S*indcsr and Ssccfg. It also adds a new shadow CSR scountinhibit and menvcfg enable bit (CDE) to enable this extension and scountovf virtualization. Signed-off-by: Kaiwen Xue Co-developed-by: Atish Patra Signed-off-by: Atish Patra Acked-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza --- target/riscv/csr.c | 304 +++++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 292 insertions(+), 12 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 0985dbdca76d..a77b6ed4c9f3 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -383,6 +383,21 @@ static RISCVException aia_smode32(CPURISCVState *env, = int csrno) return smode32(env, csrno); } =20 +static RISCVException scountinhibit_pred(CPURISCVState *env, int csrno) +{ + RISCVCPU *cpu =3D env_archcpu(env); + + if (!cpu->cfg.ext_ssccfg || !cpu->cfg.ext_smcdeleg) { + return RISCV_EXCP_ILLEGAL_INST; + } + + if (env->virt_enabled) { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + + return smode(env, csrno); +} + static bool csrind_extensions_present(CPURISCVState *env) { return riscv_cpu_cfg(env)->ext_smcsrind || riscv_cpu_cfg(env)->ext_ssc= srind; @@ -1220,10 +1235,9 @@ done: return result; } =20 -static RISCVException write_mhpmcounter(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException riscv_pmu_write_ctr(CPURISCVState *env, target_ulong= val, + uint32_t ctr_idx) { - int ctr_idx =3D csrno - CSR_MCYCLE; PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; uint64_t mhpmctr_val =3D val; =20 @@ -1248,10 +1262,9 @@ static RISCVException write_mhpmcounter(CPURISCVStat= e *env, int csrno, return RISCV_EXCP_NONE; } =20 -static RISCVException write_mhpmcounterh(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException riscv_pmu_write_ctrh(CPURISCVState *env, target_ulon= g val, + uint32_t ctr_idx) { - int ctr_idx =3D csrno - CSR_MCYCLEH; PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; uint64_t mhpmctr_val =3D counter->mhpmcounter_val; uint64_t mhpmctrh_val =3D val; @@ -1273,6 +1286,20 @@ static RISCVException write_mhpmcounterh(CPURISCVSta= te *env, int csrno, return RISCV_EXCP_NONE; } =20 +static int write_mhpmcounter(CPURISCVState *env, int csrno, target_ulong v= al) +{ + int ctr_idx =3D csrno - CSR_MCYCLE; + + return riscv_pmu_write_ctr(env, val, ctr_idx); +} + +static int write_mhpmcounterh(CPURISCVState *env, int csrno, target_ulong = val) +{ + int ctr_idx =3D csrno - CSR_MCYCLEH; + + return riscv_pmu_write_ctrh(env, val, ctr_idx); +} + RISCVException riscv_pmu_read_ctr(CPURISCVState *env, target_ulong *val, bool upper_half, uint32_t ctr_idx) { @@ -1338,6 +1365,167 @@ static RISCVException read_hpmcounterh(CPURISCVStat= e *env, int csrno, return riscv_pmu_read_ctr(env, val, true, ctr_index); } =20 +static int rmw_cd_mhpmcounter(CPURISCVState *env, int ctr_idx, + target_ulong *val, target_ulong new_val, + target_ulong wr_mask) +{ + if (wr_mask !=3D 0 && wr_mask !=3D -1) { + return -EINVAL; + } + + if (!wr_mask && val) { + riscv_pmu_read_ctr(env, val, false, ctr_idx); + } else if (wr_mask) { + riscv_pmu_write_ctr(env, new_val, ctr_idx); + } else { + return -EINVAL; + } + + return 0; +} + +static int rmw_cd_mhpmcounterh(CPURISCVState *env, int ctr_idx, + target_ulong *val, target_ulong new_val, + target_ulong wr_mask) +{ + if (wr_mask !=3D 0 && wr_mask !=3D -1) { + return -EINVAL; + } + + if (!wr_mask && val) { + riscv_pmu_read_ctr(env, val, true, ctr_idx); + } else if (wr_mask) { + riscv_pmu_write_ctrh(env, new_val, ctr_idx); + } else { + return -EINVAL; + } + + return 0; +} + +static int rmw_cd_mhpmevent(CPURISCVState *env, int evt_index, + target_ulong *val, target_ulong new_val, + target_ulong wr_mask) +{ + uint64_t mhpmevt_val =3D new_val; + + if (wr_mask !=3D 0 && wr_mask !=3D -1) { + return -EINVAL; + } + + if (!wr_mask && val) { + *val =3D env->mhpmevent_val[evt_index]; + if (riscv_cpu_cfg(env)->ext_sscofpmf) { + *val &=3D ~MHPMEVENT_BIT_MINH; + } + } else if (wr_mask) { + wr_mask &=3D ~MHPMEVENT_BIT_MINH; + mhpmevt_val =3D (new_val & wr_mask) | + (env->mhpmevent_val[evt_index] & ~wr_mask); + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + mhpmevt_val =3D mhpmevt_val | + ((uint64_t)env->mhpmeventh_val[evt_index] << 32); + } + env->mhpmevent_val[evt_index] =3D mhpmevt_val; + riscv_pmu_update_event_map(env, mhpmevt_val, evt_index); + } else { + return -EINVAL; + } + + return 0; +} + +static int rmw_cd_mhpmeventh(CPURISCVState *env, int evt_index, + target_ulong *val, target_ulong new_val, + target_ulong wr_mask) +{ + uint64_t mhpmevth_val; + uint64_t mhpmevt_val =3D env->mhpmevent_val[evt_index]; + + if (wr_mask !=3D 0 && wr_mask !=3D -1) { + return -EINVAL; + } + + if (!wr_mask && val) { + *val =3D env->mhpmeventh_val[evt_index]; + if (riscv_cpu_cfg(env)->ext_sscofpmf) { + *val &=3D ~MHPMEVENTH_BIT_MINH; + } + } else if (wr_mask) { + wr_mask &=3D ~MHPMEVENTH_BIT_MINH; + env->mhpmeventh_val[evt_index] =3D + (new_val & wr_mask) | (env->mhpmeventh_val[evt_index] & ~wr_ma= sk); + mhpmevth_val =3D env->mhpmeventh_val[evt_index]; + mhpmevt_val =3D mhpmevt_val | (mhpmevth_val << 32); + riscv_pmu_update_event_map(env, mhpmevt_val, evt_index); + } else { + return -EINVAL; + } + + return 0; +} + +static int rmw_cd_ctr_cfg(CPURISCVState *env, int cfg_index, target_ulong = *val, + target_ulong new_val, target_ulong wr_mask) +{ + switch (cfg_index) { + case 0: /* CYCLECFG */ + if (wr_mask) { + wr_mask &=3D ~MCYCLECFG_BIT_MINH; + env->mcyclecfg =3D (new_val & wr_mask) | (env->mcyclecfg & ~wr= _mask); + } else { + *val =3D env->mcyclecfg &=3D ~MHPMEVENTH_BIT_MINH; + } + break; + case 2: /* INSTRETCFG */ + if (wr_mask) { + wr_mask &=3D ~MINSTRETCFG_BIT_MINH; + env->minstretcfg =3D (new_val & wr_mask) | + (env->minstretcfg & ~wr_mask); + } else { + *val =3D env->minstretcfg &=3D ~MHPMEVENTH_BIT_MINH; + } + break; + default: + return -EINVAL; + } + return 0; +} + +static int rmw_cd_ctr_cfgh(CPURISCVState *env, int cfg_index, target_ulong= *val, + target_ulong new_val, target_ulong wr_mask) +{ + + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + switch (cfg_index) { + case 0: /* CYCLECFGH */ + if (wr_mask) { + wr_mask &=3D ~MCYCLECFGH_BIT_MINH; + env->mcyclecfgh =3D (new_val & wr_mask) | + (env->mcyclecfgh & ~wr_mask); + } else { + *val =3D env->mcyclecfgh; + } + break; + case 2: /* INSTRETCFGH */ + if (wr_mask) { + wr_mask &=3D ~MINSTRETCFGH_BIT_MINH; + env->minstretcfgh =3D (new_val & wr_mask) | + (env->minstretcfgh & ~wr_mask); + } else { + *val =3D env->minstretcfgh; + } + break; + default: + return -EINVAL; + } + return 0; +} + + static RISCVException read_scountovf(CPURISCVState *env, int csrno, target_ulong *val) { @@ -1347,6 +1535,14 @@ static RISCVException read_scountovf(CPURISCVState *= env, int csrno, target_ulong *mhpm_evt_val; uint64_t of_bit_mask; =20 + /* Virtualize scountovf for counter delegation */ + if (riscv_cpu_cfg(env)->ext_sscofpmf && + riscv_cpu_cfg(env)->ext_ssccfg && + get_field(env->menvcfg, MENVCFG_CDE) && + env->virt_enabled) { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { mhpm_evt_val =3D env->mhpmeventh_val; of_bit_mask =3D MHPMEVENTH_BIT_OF; @@ -2290,11 +2486,72 @@ static int rmw_xireg_cd(CPURISCVState *env, int csr= no, target_ulong isel, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { - if (!riscv_cpu_cfg(env)->ext_smcdeleg) { - return RISCV_EXCP_ILLEGAL_INST; + int ret =3D -EINVAL; + int ctr_index =3D isel - ISELECT_CD_FIRST; + int isel_hpm_start =3D ISELECT_CD_FIRST + 3; + + if (!riscv_cpu_cfg(env)->ext_smcdeleg || !riscv_cpu_cfg(env)->ext_sscc= fg) { + ret =3D RISCV_EXCP_ILLEGAL_INST; + goto done; } - /* TODO: Implement the functionality later */ - return RISCV_EXCP_NONE; + + /* Invalid siselect value for reserved */ + if (ctr_index =3D=3D 1) { + goto done; + } + + /* sireg4 and sireg5 provides access RV32 only CSRs */ + if (((csrno =3D=3D CSR_SIREG5) || (csrno =3D=3D CSR_SIREG4)) && + (riscv_cpu_mxl(env) !=3D MXL_RV32)) { + ret =3D RISCV_EXCP_ILLEGAL_INST; + goto done; + } + + /* Check Sscofpmf dependancy */ + if (!riscv_cpu_cfg(env)->ext_sscofpmf && csrno =3D=3D CSR_SIREG5 && + (isel_hpm_start <=3D isel && isel <=3D ISELECT_CD_LAST)) { + goto done; + } + + /* Check smcntrpmf dependancy */ + if (!riscv_cpu_cfg(env)->ext_smcntrpmf && + (csrno =3D=3D CSR_SIREG2 || csrno =3D=3D CSR_SIREG5) && + (ISELECT_CD_FIRST <=3D isel && isel < isel_hpm_start)) { + goto done; + } + + if (!get_field(env->mcounteren, BIT(ctr_index)) || + !get_field(env->menvcfg, MENVCFG_CDE)) { + goto done; + } + + switch (csrno) { + case CSR_SIREG: + ret =3D rmw_cd_mhpmcounter(env, ctr_index, val, new_val, wr_mask); + break; + case CSR_SIREG4: + ret =3D rmw_cd_mhpmcounterh(env, ctr_index, val, new_val, wr_mask); + break; + case CSR_SIREG2: + if (ctr_index <=3D 2) { + ret =3D rmw_cd_ctr_cfg(env, ctr_index, val, new_val, wr_mask); + } else { + ret =3D rmw_cd_mhpmevent(env, ctr_index, val, new_val, wr_mask= ); + } + break; + case CSR_SIREG5: + if (ctr_index <=3D 2) { + ret =3D rmw_cd_ctr_cfgh(env, ctr_index, val, new_val, wr_mask); + } else { + ret =3D rmw_cd_mhpmeventh(env, ctr_index, val, new_val, wr_mas= k); + } + break; + default: + goto done; + } + +done: + return ret; } =20 /* @@ -2573,6 +2830,21 @@ static RISCVException write_mcountinhibit(CPURISCVSt= ate *env, int csrno, return RISCV_EXCP_NONE; } =20 +static RISCVException read_scountinhibit(CPURISCVState *env, int csrno, + target_ulong *val) +{ + /* S-mode can only access the bits delegated by M-mode */ + *val =3D env->mcountinhibit & env->mcounteren; + return RISCV_EXCP_NONE; +} + +static RISCVException write_scountinhibit(CPURISCVState *env, int csrno, + target_ulong val) +{ + write_mcountinhibit(env, csrno, val & env->mcounteren); + return RISCV_EXCP_NONE; +} + static RISCVException read_mcounteren(CPURISCVState *env, int csrno, target_ulong *val) { @@ -2675,11 +2947,13 @@ static RISCVException write_menvcfg(CPURISCVState *= env, int csrno, target_ulong val) { const RISCVCPUConfig *cfg =3D riscv_cpu_cfg(env); - uint64_t mask =3D MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE | MENVCF= G_CBZE; + uint64_t mask =3D MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE | + MENVCFG_CBZE | MENVCFG_CDE; =20 if (riscv_cpu_mxl(env) =3D=3D MXL_RV64) { mask |=3D (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | (cfg->ext_sstc ? MENVCFG_STCE : 0) | + (cfg->ext_smcdeleg ? MENVCFG_CDE : 0) | (cfg->ext_svadu ? MENVCFG_ADUE : 0); =20 if (env_archcpu(env)->cfg.ext_zicfilp) { @@ -2708,7 +2982,8 @@ static RISCVException write_menvcfgh(CPURISCVState *e= nv, int csrno, const RISCVCPUConfig *cfg =3D riscv_cpu_cfg(env); uint64_t mask =3D (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | (cfg->ext_sstc ? MENVCFG_STCE : 0) | - (cfg->ext_svadu ? MENVCFG_ADUE : 0); + (cfg->ext_svadu ? MENVCFG_ADUE : 0) | + (cfg->ext_smcdeleg ? MENVCFG_CDE : 0); uint64_t valh =3D (uint64_t)val << 32; =20 env->menvcfg =3D (env->menvcfg & ~mask) | (valh & mask); @@ -5493,6 +5768,11 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { write_sstateen_1_3, .min_priv_ver =3D PRIV_VERSION_1_12_0 }, =20 + /* Supervisor Counter Delegation */ + [CSR_SCOUNTINHIBIT] =3D {"scountinhibit", scountinhibit_pred, + read_scountinhibit, write_scountinhibit, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + /* Supervisor Trap Setup */ [CSR_SSTATUS] =3D { "sstatus", smode, read_sstatus, write_sst= atus, NULL, read_sstatus_i128 = }, --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267880; cv=none; d=zohomail.com; s=zohoarc; b=Tt6eYXzrgjxi2DczdomhenX5zl00QmsorNF2JhN68NW1iIQIVioYIEqNIduNNxlso1L9QxM7FkhEdB/gv36FEeBtMR+MixodHgefYYZUz17iRl4+ZyWyL9JwScXpoYxFJgE4mI8zIqjqw9dle7kr09tkQEm/Hl14P6qPQxoBcIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267880; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vTwUWeOBYxedW2UpgZEtaCjLh9J+yVkl+/fWLaqQqm4=; b=AbutWxN5LDQte0pIcT7KErdAXVr0p2QGWV499cRq92RMG6w8pOd/vRhMHxNFkCYm7dTLq9dgAXbBVDs6tAjkIstpV+neAAjrLDmK9jDJ2OlXtwGxuszL/q2iM+b2G4NnFZbOFS713gfyI7Ok9gh76oK1H81ovdJkOAHlbQINFtg= 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 1733267880507883.3035380314282; Tue, 3 Dec 2024 15:18:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6l-0001Qj-0s; Tue, 03 Dec 2024 18:15:07 -0500 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 1tIc6h-0001PA-3O for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:15:03 -0500 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6b-0001LE-3k for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:15:02 -0500 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-7253bc4d25eso251967b3a.0 for ; Tue, 03 Dec 2024 15:14:56 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267695; x=1733872495; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vTwUWeOBYxedW2UpgZEtaCjLh9J+yVkl+/fWLaqQqm4=; b=YEIZ8g6o7hlLJY1RT7mD4mBsQ6dqoRz3SfgJeOwI64KC0M/87bfg1PWAcQh8MTKc/1 00GChh9XQ9pauZiCRq6JLlnVsy/j82n/6Znql9UystFh5nHeHHA/nTwXLQ6orwFTsfp4 VVuJ1iOYjZVm5NfSPvDBfcGhv+XSzrd3fVKQGzdLPpwyUp1SQghvNXhfG1jKZrxSnPm+ 0u1Jbim07m9lGMZzb5+5ewRXMwztlHKwQyaBk6VSUbKU1M2YEdlmp5OzdmAPUHGfAiKU TUsNNtgFNGQKPQsuTEDpLBDTxPUrJNA9qzu4U90l4DZUod6nUL/KSCJZrpZRWssZl6Eh m9xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267695; x=1733872495; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vTwUWeOBYxedW2UpgZEtaCjLh9J+yVkl+/fWLaqQqm4=; b=waFDo8J+3P8qECNQf1kKRWNvASHX+dofOZPt0KYAKe97TiHmGj967uTEZxLVfI7l8U zl/7wTe51lrijq/nk9XuVxpBvH1fCKQMAQv7yf5ticCN1v8F92pcewoTU8DvdG3tsNLR LqtCpndEU3+up9vMHbf3FvjQQWy8Jd9VFKEU2lIRjq6n4lJrKBzmvESJprLHRV/cmnml BBDz5IovohOCz0ASeEIfl21N+ItWuw450uECPGKFsnM/s3yNkPO8mCxiYKgBq3sLyzqA MTOC1LnLoBFvH2ZOnei3vVprB0VNHYvePER8X4KYKUHcOeFO9g3b1kild8nZovY3eHCF zIGA== X-Forwarded-Encrypted: i=1; AJvYcCXFoD8HQ5MxmRTdKalTOxf8jEzOmkzLoBZ3MWXu/sLsIjQfKsgHCH1dcAX3Uh3Id8H5dMuBsrSXpxxr@nongnu.org X-Gm-Message-State: AOJu0Yzvlz+vjEDtK9Uq+1w3j8xXdSQMFud8J7S5z7A2MsqbhXDVrgjM jdMfAs0DiLP1kr0+qrrPY1X4xtNmFbtS63ybVjJUc7V4NiPWiaFDu+rhHR1CO7o= X-Gm-Gg: ASbGncvkbHEM9Dw7+d7+93R1jj9HGTlibrQJHd/X6DIQg1lhyDV71nqh4gUn9CXxXGu A6vRbcRUH0VtwUXRlZqgS2KTutfK1cyJn+BafcTV+wFfu5dAx611ksYXFYkaUfh1EPEB6gkvljt LvTZX+xJAu8wwv9lNUlCXehYAOp7UBy5wuGoALUIT1OkQkNStNjq8n2Bwx8Zy2ZNg/GVVcILlrd Ia5P638jFjI+UHNzUjYnLO4VxnTQsaz+dM5zNSIIkm3EEZoPljBcT/IrfO6KKY= X-Google-Smtp-Source: AGHT+IFqH267BHlWINP68ATaiF7zZgT9wTLIZATLPYoP4ZkDZ7Ifuz3OKfBWha89aJ0denh+vPQk0g== X-Received: by 2002:a05:6a00:4651:b0:725:37a4:8827 with SMTP id d2e1a72fcca58-7257f8dbeedmr7576172b3a.3.1733267695593; Tue, 03 Dec 2024 15:14:55 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:47 -0800 Subject: [PATCH v4 09/11] target/riscv: Invoke pmu init after feature enable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-9-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::42a; envelope-from=atishp@rivosinc.com; helo=mail-pf1-x42a.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267881926116600 The dependant ISA features are enabled at the end of cpu_realize in finalize_features. Thus, PMU init should be invoked after that only. Move the init invocation to riscv_tcg_cpu_finalize_features. Reviewed-by: Alistair Francis Signed-off-by: Atish Patra --- target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index c62c2216961b..2b57aa4d1704 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -934,6 +934,20 @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Er= ror **errp) error_propagate(errp, local_err); return; } +#ifndef CONFIG_USER_ONLY + if (cpu->cfg.pmu_mask) { + riscv_pmu_init(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + + if (cpu->cfg.ext_sscofpmf) { + cpu->pmu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + riscv_pmu_timer_cb, cpu); + } + } +#endif } =20 void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) @@ -981,7 +995,6 @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error *= *errp) =20 #ifndef CONFIG_USER_ONLY CPURISCVState *env =3D &cpu->env; - Error *local_err =3D NULL; =20 tcg_cflags_set(CPU(cs), CF_PCREL); =20 @@ -989,19 +1002,6 @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error= **errp) riscv_timer_init(cpu); } =20 - if (cpu->cfg.pmu_mask) { - riscv_pmu_init(cpu, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); - return false; - } - - if (cpu->cfg.ext_sscofpmf) { - cpu->pmu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, - riscv_pmu_timer_cb, cpu); - } - } - /* 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; --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267860; cv=none; d=zohomail.com; s=zohoarc; b=hlNWhmf5N/QouChepUJBiLJD5+V0wclugLNMos0592VGN7JsBW2lByp5Vo1vmAWRXah54LVeLAHf3Z8VeFaXEqnT77olsQZ87Nfif3P7Oaqp6pW6+eK8NbYa6SbIowgzPS4p4gZ+n/Fky6UWaAep6Fpj9x8UpMRvHSY/w7hT33g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267860; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pG0aQnUQA7YEFMoz0E4tJtn6hJqy67liJfeq3q7vHeU=; b=T2o1E0QjYoMkMeMOhtoRBc4WtULxiImWfPqlMolrY6tEzDHNonwFvtfxhV8QEish8QvbbICcwIATJMySa5dr8/v6VhAEEU5GhSuyfTptnyNxC18i2PFZs6dghbpZlfBiKb8ZxJsnSfmx3gOapGlhKIQy03PobYTu5xKmDjh0xG8= 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 1733267860007142.56859702354348; Tue, 3 Dec 2024 15:17:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6g-0001OI-8F; Tue, 03 Dec 2024 18:15:02 -0500 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 1tIc6d-0001M8-Rh for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:59 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6c-0001La-1L for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:14:59 -0500 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-2ee8aa26415so2971242a91.1 for ; Tue, 03 Dec 2024 15:14:57 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267696; x=1733872496; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pG0aQnUQA7YEFMoz0E4tJtn6hJqy67liJfeq3q7vHeU=; b=Nzmj3DrlNIkCzdF5AoL2oVlt1XhtzaOoPhC8wUysmU2xPE9Tn61vz5yWKRNO1xSZVr ZI1z9I/dgIY3GhtTQiqxBR4mmledrB5ZI0lOG7UkVm/J5SC4Ewaz2za762vnY6QF0FSw wcGXxY2z981457oGCMl+cwDLc+3ZnhuQuS5rFviC9ZJFG6j6vwD46qljpDonxITtA6CN KJh2dU57v4pwF+VB6SV/aFlBRVF8sQo3HPDG/iWxajvxB+lHS2STK9ZbShm1bBrE/SZV QOkw9w2mtYgtQOSiy20l3P6wFsheysNuI3Ae70L7ps2lkbkj55ruD/W/AlyUIat2QQb3 BZfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267696; x=1733872496; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pG0aQnUQA7YEFMoz0E4tJtn6hJqy67liJfeq3q7vHeU=; b=jsHqdr+Ndo1A6mjjHdp0NlBL9U2hPzYy+YV0Tdy3Ow9pLk8T1CTlOOrC8YrN2IgQAY Vb/oBj47FaALIZuqzS1awpJrjzOrlBxu2nsxnGsRvvR3ySmD/4psMT+MZWZ7fM7VM1Hz aCc11ozZlGU4Vcwzvd6TNzn5NBaMkW13I44pOaRnNaMoo6MjlRsjjaFej3lKOlFwEkYI mTSL1xH5g5xI8SK2adPWO5twVPjAs6M62nHnTnr+AQfv+EfGXegO7FjYDZ8Wi3w8UB1U eDxtNrJwuFJP4DA8HmhXx35hYekC8gvII1+WmCDVeFpDHONxhyl2b1FOb4YZxoJ3IWBb Rwzw== X-Forwarded-Encrypted: i=1; AJvYcCWreti4sOBuW1YrtY06oFbumohRJ4saNo/YHJynnEfDvYIWHewy+YjEWcA6YCOyyuvD8z2C0a4XQ4d/@nongnu.org X-Gm-Message-State: AOJu0YzD5OzMEVDlYlM9A1C9VvAphlIdHtgekUCdCd2e5fyBjDmvUjAP K52xL/wWRAbwfKfBr05hVNAJSMJZSpRhTg/9WFcAc3quuhUkNToD9ObJY6b+rQE= X-Gm-Gg: ASbGnctWKf8t1BXe06XHNf/FjpOE16+lQgoBIdMq6LoBNHYv9waxG+KjT6/KXOL6sjy n76j7g1U2ylsfYcqs0bVW6gqZ9jQRz8ol0ZUnffsOKA90PUAWk4Mbbx7iuGn6oO4EQxTf8bbMfg 0Ud/gAfwyhn4XGWQoN++TSPQuDlD2dy16zitEdtT/8BMi/+ykjsVhI7N3jfhry3iz5zGwe9+lm6 QLShpzK53FRTn1F9rZkX2rg1Pgt+z3sIt02GUYubEJrxIbZTeVQldvA2p4zi3w= X-Google-Smtp-Source: AGHT+IHooGOQbGWgbWmWYOflIkzZDuYu5vVnLDYDzFLGw/Lj56bLWHFPasBSFqPOJ8VMCuDQDTKG4Q== X-Received: by 2002:a17:90b:3803:b0:2ee:edae:75e with SMTP id 98e67ed59e1d1-2ef011eb672mr5312459a91.13.1733267696547; Tue, 03 Dec 2024 15:14:56 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:48 -0800 Subject: [PATCH v4 10/11] target/riscv: Add implied rule for counter delegation extensions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-10-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::102f; envelope-from=atishp@rivosinc.com; helo=mail-pj1-x102f.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267861934116600 The counter delegation/configuration extensions depend on the following extensions. 1. Smcdeleg - To enable counter delegation from M to S 2. S[m|s]csrind - To enable indirect access CSRs Add an implied rule so that these extensions are enabled by default if the sscfg extension is enabled. Reviewed-by: Daniel Henrique Barboza Signed-off-by: Atish Patra --- target/riscv/cpu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 82edd28e2e1d..410ca2e3a666 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -2642,6 +2642,16 @@ static RISCVCPUImpliedExtsRule ZVKSG_IMPLIED =3D { }, }; =20 +static RISCVCPUImpliedExtsRule SSCFG_IMPLIED =3D { + .ext =3D CPU_CFG_OFFSET(ext_ssccfg), + .implied_multi_exts =3D { + CPU_CFG_OFFSET(ext_smcsrind), CPU_CFG_OFFSET(ext_sscsrind), + CPU_CFG_OFFSET(ext_smcdeleg), + + RISCV_IMPLIED_EXTS_RULE_END + }, +}; + RISCVCPUImpliedExtsRule *riscv_misa_ext_implied_rules[] =3D { &RVA_IMPLIED, &RVD_IMPLIED, &RVF_IMPLIED, &RVM_IMPLIED, &RVV_IMPLIED, NULL @@ -2659,7 +2669,7 @@ RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rule= s[] =3D { &ZVE64X_IMPLIED, &ZVFBFMIN_IMPLIED, &ZVFBFWMA_IMPLIED, &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVKN_IMPLIED, &ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED, - &ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, + &ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, &SSCFG_IMPLIED, NULL }; =20 --=20 2.34.1 From nobody Mon Feb 9 23:11:09 2026 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=1733267859; cv=none; d=zohomail.com; s=zohoarc; b=RiRhrA3uRhs4JeH93YWpFoN5VYyJ0DjGr9GMoH18UjqLWJRgVvjt0qS0lz7NQOADQ7H3RvniWJZ5cGiXbdYwLJZjor9mGqsSlwjl5lkfmZ7bfxI1k7ie9tw2TgexSxr1b0zSvt+46i1TUZ2PT17aEHIC3oCzrXCslWmQp5aYD8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733267859; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aWl6RCkJhXh66y8GBilR1MgWBHw1j2MblGEre7+EdBQ=; b=F9iudDz+TutRQqMP+9OObX372U8KHqLZAl7YCVnY17ui6s83RAq0xa1NUyFgTCfqaVBOIeleh8sO1UZFISoreqgW+uP+5lgGW/WYbQyxIM8KmPe3e04BtH1MQUAuzzRrvJv+mZR0PpaPhQ34MV3wOwex4PPymkpuhEYKyxUUqAg= 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 1733267859989861.3617987077281; Tue, 3 Dec 2024 15:17:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIc6i-0001Ps-P7; Tue, 03 Dec 2024 18:15:04 -0500 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 1tIc6e-0001NK-OX for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:15:00 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIc6c-0001Lj-Vl for qemu-devel@nongnu.org; Tue, 03 Dec 2024 18:15:00 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-215b4681c94so16277555ad.0 for ; Tue, 03 Dec 2024 15:14:58 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254180f78asm11032133b3a.133.2024.12.03.15.14.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 15:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733267697; x=1733872497; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=aWl6RCkJhXh66y8GBilR1MgWBHw1j2MblGEre7+EdBQ=; b=rZXRf9yTIGJv7MsL7UnDql1EpyogBiXda0/XEp4g++OTjt4/PZ2sBo4UQaacmGFs5h rtKbWq5VRM0VMh0d77AHQax8ZL4RHdyWvoWicluHR1+yIuGiSpDUVbNyC94wGwjb79nS Y4Q6dIayOk18EL7Wx4+YGW5g1xGmDf9QucLjLaDsl2xI7mr/UeQHLeoQ3+J9ejhZ5Ut4 9cK8NAW6THBF8n1f3ySycorgyFxCiBUml7BNqnnV+w2wbm4M/M6+lAcN5tqiGrTtiTR/ CEzIdnfGr6Q9Pibi6WYbFDQH7jQIpLN/zthvwexGHZ8Iq8/hvNcgji4uF1rHObhkR4mc KG9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733267697; x=1733872497; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aWl6RCkJhXh66y8GBilR1MgWBHw1j2MblGEre7+EdBQ=; b=UzJnNUn1djAC2K/VytHdN5qgMiHxZCy15pogkfrhWmyIqDeUwhDQADA6Dy6V1frmyp 7H9tdXQKoqrOKOavm9xiFpQS3EDtNVUn6AU1Ntc5iuEqeZAVBTx0HixSSsi0SmDF7DXD gC037167pJlvSvg6TRBO9CiRGg12y6M5hmheggTR9LQtwjc9WalziexOD5qs+5KY8d5O zuGXtvn7Z4RMOzj3goQCORAxzfu9Xei0UvSfWACGecDCM73BZvkLFWl6B9ep6WDq94P7 RTOoiE0tBu/7MYVGE3nm+wq7vsIppQ/9lAbwDrmZ4I+et81y5IiMuwbP5uP8+UUi9P5e UOsg== X-Forwarded-Encrypted: i=1; AJvYcCXsK1HD+4shaMj7D02YlgrO3FMOWTISMq89CwxPV+R0zf6z6xoZ7qEqgn+x+d5UOdpgg2pRVOd/HllJ@nongnu.org X-Gm-Message-State: AOJu0YzsWhYu5nVo4+dA3F3aP2EM58p7WxzB6JA7QMWMSVMPA31oUC04 2kpVQhfsVq53OLLjO44IHLZwKzGib4QutAVZV/55wXhXf8uYifuE4ZHm/1ofL30vS0ad3Gb9zyu 1 X-Gm-Gg: ASbGnctZ6Ge53eI8+ElLNzD+dZdYb9piz2oQQOuhu5L8Fn86lHd7VuP4QTm8KcS+t70 FzSONNWZkkLmWK6zB//RuigNB2UQwCJ5UD7g/pCSrgWAMZV9DjqgOmL3hkB+olo+DLudXXpkZwe vbYkVxML75NY0ls0HlO+hkm2msoMLa79jA4zCOR7EHamw2+5w+WsFpD/Xc1yqWlc4nyd+h4zTLi IqJGmuVOnRGAGnAOmWv45UfhJKADLAIKz2DjCC+cbW5XJJRnsgcqwz9JkBPUvk= X-Google-Smtp-Source: AGHT+IGTgPAVT7ZhRnEGuCbEfWRO+19H7I4Dju+xp5TRPG7zndoFEGt0TX6P4HuWJZr2dXM6aitAKg== X-Received: by 2002:a17:903:2290:b0:215:b473:1dc9 with SMTP id d9443c01a7336-215bd161a26mr55142985ad.46.1733267697532; Tue, 03 Dec 2024 15:14:57 -0800 (PST) From: Atish Patra Date: Tue, 03 Dec 2024 15:14:49 -0800 Subject: [PATCH v4 11/11] target/riscv: Add configuration for S[m|s]csrind, Smcdeleg/Ssccfg MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241203-counter_delegation-v4-11-c12a89baed86@rivosinc.com> References: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> In-Reply-To: <20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: kaiwenxue1@gmail.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com X-Mailer: b4 0.15-dev-13183 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=2607:f8b0:4864:20::629; envelope-from=atishp@rivosinc.com; helo=mail-pl1-x629.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733267861932116600 Add configuration options so that they can be enabled/disabld from qemu commandline. Acked-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza Signed-off-by: Atish Patra --- target/riscv/cpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 410ca2e3a666..2a4f285a974f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1477,6 +1477,10 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { /* Defaults for standard extensions */ MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), MULTI_EXT_CFG_BOOL("smcntrpmf", ext_smcntrpmf, false), + MULTI_EXT_CFG_BOOL("smcsrind", ext_smcsrind, false), + MULTI_EXT_CFG_BOOL("smcdeleg", ext_smcdeleg, false), + MULTI_EXT_CFG_BOOL("sscsrind", ext_sscsrind, false), + MULTI_EXT_CFG_BOOL("ssccfg", ext_ssccfg, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), MULTI_EXT_CFG_BOOL("zicfilp", ext_zicfilp, false), MULTI_EXT_CFG_BOOL("zicfiss", ext_zicfiss, false), --=20 2.34.1