From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119666; cv=none; d=zohomail.com; s=zohoarc; b=Vfp+jGbfsJX7bwkOje3puqfAj+g8J8Dw0cukVnQLEhmhUMnHlAwQy2FebL8aZBpKS59vDzoMgITdT+goA7ciVxfkVe+8EArYc/PCCC1OiELzdWtAyP2PKNcko7/Sv42esV1MVL8+YKpnWW/Qc+p/vJovAWQWqIeySzhhHaolW0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119666; h=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=98jPE8Nm5XmnYTmie79vaM5ax8offv0h+SJp0+g/oio=; b=ib6vMMw3c+V0CQkCLB8BCss7C9phd7taMRcwv9RNS4p1f/C7M3/c528TBzv/zlwBxJ/HN1Z/d+2Cin9eldTK6MD3FW014IyPMv7N54m0JXARBfPjoVDqs1s0d8uu8WZvSKjuixU7hW43M1EPUaJCZ4u+Ozw5Rdcoghsj2+VF8vw= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119666622449.62747899069666; Wed, 11 Sep 2024 22:41:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPC-0008CY-2F; Thu, 12 Sep 2024 01:30:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socP9-00087O-6q for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:07 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socP7-0002xx-I3 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:06 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7191df6b5f5so395603b3a.0 for ; Wed, 11 Sep 2024 22:30:05 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119003; x=1726723803; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=98jPE8Nm5XmnYTmie79vaM5ax8offv0h+SJp0+g/oio=; b=Afxv0VCtUYpmGXE+E3xiFi4twTPhNAMzS/Dd4zPkG518f6FGPYPoMz75hS2RwbiUXU AbinH5gBzwMyHs7bZ9NNyN6oC7Yhcby1JJ18/BTDVkf/iBOE6YhpJXGk3Y7Bvk6uS1s6 eWJx3C6tN6vX2B5RD+1pJITYt4uMyiXei9vJS9tWZFU+Ff0dljdA7GAea+Tx+hBZuMvo Caf+tF4aPrI6kKw+gMY7WREpfdNsVI5sB3lNQmE+Td3DyI5hJrV2Zk1ET4ZsbYjvkHxy MiiqAWtWtzJZRzyX/6KTlsiX9h7fMzdkHsHOzMAtYdRV2HlWipxVVylzLOI0f3vOloch V5mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119003; x=1726723803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=98jPE8Nm5XmnYTmie79vaM5ax8offv0h+SJp0+g/oio=; b=SIiqhGzesIHAYDLQ6KJDiv1EUpgNGxOkMWWkjXkmYPQ1MN6WYROIwPaNE5nIwF/+7P np70AFgmy45YN8XBKMLfkRP0ayYeyByIWsnplcjftSc46JXjL6dWkcbB6+faZXbhE3Rf QXIwzOlTKGpgAgtHjEHYn0JUHswVgrINjpixl+h3m4Bhd2Z7d2ezPrRu86qfkXDCF5WY 0EJ45l+/tUV3eg6w3irrj9My1MlfLOYlMJaP6xD3PHUgdTaR1pEt9nbwRBjyEw3e1toA QJor2ieJ1+r5EJCOJKisxfgSlDs28SBfmQvyeKoc61DHV0irlmM0Tt/I6oQcAcGZg2x2 mI5A== X-Gm-Message-State: AOJu0Yw0l7+eRclvHqKXrobKt4wFYsXJrTPjQCtR6GXOiOtIIW/Uo2ct swfjxKQA0viEpGoWGUTNIf6htD1Qd7MsmvrpSwM/HTGrRd6vEDM0ItWRKQ== X-Google-Smtp-Source: AGHT+IHFJpVoqRTRqJDN/lRzeXEUecBDgoyLc/B9teFup1hMsYS91/uIyJP48qIzncqFu24UBz+plg== X-Received: by 2002:a05:6a00:2d17:b0:714:2d05:60df with SMTP id d2e1a72fcca58-71926091d24mr2537578b3a.15.1726119003315; Wed, 11 Sep 2024 22:30:03 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Jason Chien , Frank Chang , Alistair Francis Subject: [PULL 01/47] target/riscv: Add a property to set vl to ceil(AVL/2) Date: Thu, 12 Sep 2024 15:29:06 +1000 Message-ID: <20240912052953.2552501-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119667416116600 Content-Type: text/plain; charset="utf-8" From: Jason Chien RVV spec allows implementations to set vl with values within [ceil(AVL/2),VLMAX] when VLMAX < AVL < 2*VLMAX. This commit adds a property "rvv_vl_half_avl" to enable setting vl =3D ceil(AVL/2). This behavior helps identify compiler issues and bugs. Signed-off-by: Jason Chien Reviewed-by: Frank Chang Message-ID: <20240722175004.23666-1-jason.chien@sifive.com> Signed-off-by: Alistair Francis --- target/riscv/cpu_cfg.h | 1 + target/riscv/cpu.c | 1 + target/riscv/vector_helper.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 8b272fb826..96fe26d4ea 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -127,6 +127,7 @@ struct RISCVCPUConfig { bool ext_smepmp; bool rvv_ta_all_1s; bool rvv_ma_all_1s; + bool rvv_vl_half_avl; =20 uint32_t mvendorid; uint64_t marchid; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index a90808a3ba..8f21171ffa 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -2687,6 +2687,7 @@ static Property riscv_cpu_properties[] =3D { =20 DEFINE_PROP_BOOL("rvv_ta_all_1s", RISCVCPU, cfg.rvv_ta_all_1s, false), DEFINE_PROP_BOOL("rvv_ma_all_1s", RISCVCPU, cfg.rvv_ma_all_1s, false), + DEFINE_PROP_BOOL("rvv_vl_half_avl", RISCVCPU, cfg.rvv_vl_half_avl, fal= se), =20 /* * write_misa() is marked as experimental for now so mark diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 10a52ceb5b..072bd444b1 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -75,6 +75,8 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ul= ong s1, vlmax =3D vext_get_vlmax(cpu->cfg.vlenb, vsew, lmul); if (s1 <=3D vlmax) { vl =3D s1; + } else if (s1 < 2 * vlmax && cpu->cfg.rvv_vl_half_avl) { + vl =3D (s1 + 1) >> 1; } else { vl =3D vlmax; } --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119049; cv=none; d=zohomail.com; s=zohoarc; b=Nx5ZSzDcksISNgU/utl0RIqkpL/u0E7oTjQoHD0x9j04HqeeHRoHnTge4Fi/aBZmkQDJWqNbfw0b4Hdy6QY19j8UAlh2CTK7N0uegZlBBH1h4znOEd9t8N9Dg797rSP7+URQv+FiLD5QYL5Cv5EKUX4w6HeQABN1uO6CxIBcN5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119049; h=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=qKFK7bfzo9lztBPhZCSDP1XR7U4NGQvb7cgLHvUq4Qk=; b=dqUmPf45XRAFTuEvbkWbH6g6Zln3iNmESKBTVgyIbWozjFNSHd5e17npFSlFTSR4M3DlIuIOEtLhfhkwQtLH6U5WiRaWCC3fRn2NfJacVLk8j6tWGtHE2sP8Ze+Rf0O6SEAVYOH1FUje57kL2T4tsBBxeAO4a+qQk9IzZN9Z0jc= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119049731577.5808650159665; Wed, 11 Sep 2024 22:30:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPF-0008KR-6w; Thu, 12 Sep 2024 01:30:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPC-0008DW-56 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:10 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPA-0002yG-F3 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:09 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7cf5e179b68so426685a12.1 for ; Wed, 11 Sep 2024 22:30:08 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119007; x=1726723807; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qKFK7bfzo9lztBPhZCSDP1XR7U4NGQvb7cgLHvUq4Qk=; b=BljB+s7k+nxPgTKRuIuf1WhPdQROXb5sJD/7n6vZ5KRPM02Jq2DLM4MM1jNpQusaLo /uIgukx996c1RgFPdeD2EuP7Rg40VnevBgeQntMfUQaojr7+W4df2OPSpMeG7erx8/V6 hF+s6KVpkI1R8UffSYgMU8RQ1jpNa5Pj2tAyoK1lQuWljkPRA3E+UO7N+tA9csnfAN2t hDGizk+dIjHH2EKl1gU3BH/AMyxd+u4eqNdGirOMzMftKVz92TBDYAfU3NHxsDRMTpew +p044O1DIaGEHN4N9iwKSUiNLGVr41vW0vO5vqPPoQApw3ZM7SdtqiekJ1Dr/NHU6nbR zkPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119007; x=1726723807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qKFK7bfzo9lztBPhZCSDP1XR7U4NGQvb7cgLHvUq4Qk=; b=TT30/bWmzU6DD3KhPcxpEboH2Wamef+F1nuT4ilSrsUdih7fzCl7eAUvtCUL6ST27C PCDshkqQ1M/Cs5WkSHFdtLytFhOn7d3roZTxoJ0wCcvdo5rxkphymcTSk1KjPGVttqLY kLrkoJlQXahmBCh6lyZs5jX2RqXY/PaC//nwE25WlV8Lfil8V7+0KGl+uRNwi1bNXthw qDg+X1cB51nvHV4K9WIWf2yihc0psR6IxJQhyHwPxUBBs4Rh5Baz830rPfu46iPBu9dB nw7pYrt0Soyv+M7m0/4eZOUDwxfpIqdkMpvzZnpoMQHdicaJEZZY9G85kLdJFwIlyj1Q azGA== X-Gm-Message-State: AOJu0Yy9ehXRaviX0eSf85RSl1aGGYWYbwvLsacSBlSyRaAGEtIqiSPD efEt0j3y3XOcBn9KA4f3zWQ99sG9uHulCdlAhVs5BBU1hYvzFjcDSzPgtQ== X-Google-Smtp-Source: AGHT+IFIojT6DO00nECHxhJaDgiZMy5EGf9SBLIQjAxWI0X9jVG7o8oA3/I/pqGPGMYdyEcQXCvntQ== X-Received: by 2002:a05:6a21:6e41:b0:1cf:3338:a475 with SMTP id adf61e73a8af0-1cf755c7824mr2727457637.9.1726119006381; Wed, 11 Sep 2024 22:30:06 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Haibo Xu , Sunil V L , Alistair Francis Subject: [PULL 02/47] tests/acpi: Add empty ACPI SRAT data file for RISC-V Date: Thu, 12 Sep 2024 15:29:07 +1000 Message-ID: <20240912052953.2552501-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=alistair23@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119050241116600 Content-Type: text/plain; charset="utf-8" From: Haibo Xu As per process documented (steps 1-3) in bios-tables-test.c, add empty AML data file for RISC-V ACPI SRAT table and add the entry in bios-tables-test-allowed-diff.h. Signed-off-by: Haibo Xu Reviewed-by: Sunil V L Acked-by: Alistair Francis Message-ID: <0e30216273f2f59916bc651350578d8e8bc3a75f.1723172696.git.haibo1= .xu@intel.com> Signed-off-by: Alistair Francis --- tests/qtest/bios-tables-test-allowed-diff.h | 1 + tests/data/acpi/riscv64/virt/SRAT.numamem | 0 2 files changed, 1 insertion(+) create mode 100644 tests/data/acpi/riscv64/virt/SRAT.numamem diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios= -tables-test-allowed-diff.h index dfb8523c8b..a3e01d2eb7 100644 --- a/tests/qtest/bios-tables-test-allowed-diff.h +++ b/tests/qtest/bios-tables-test-allowed-diff.h @@ -1 +1,2 @@ /* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/riscv64/virt/SRAT.numamem", diff --git a/tests/data/acpi/riscv64/virt/SRAT.numamem b/tests/data/acpi/ri= scv64/virt/SRAT.numamem new file mode 100644 index 0000000000..e69de29bb2 --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119050; cv=none; d=zohomail.com; s=zohoarc; b=SG1UOZzbPdLih0Jd/ZEr2usqfIuwv0bns0+0CourloU5dlQacGqyfKMZmBaXeZ7/DWHZzOAOALMg86MiaWzgjWSS/VKlM5cfpDeb2+isGvG7D+Em/rUi1SAQY9Xh9X6NJEz2dee3g8lRDa1XJzRbrIinbnXrfk2JLa0sW6yEF88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119050; h=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=t3uTPve2mzx49hu7WEVCseBvT4eXpfBEBSsLLj942CY=; b=Fefg/fqwzOLI0yOvvAeg2r/2rdLObGYP4ITy6cTrSQRlZl5IMXWcw+l3T9s26wcRXAbmQTHHn+cQcwLbMAcq/2SBpnEnQLmzsZ+majQAdtjFqk3CBbgO2pvmV43X3UqiwVywIlqdKV/hTC7A8ZQw2VsRkxN4w0RzCS/pWIykJZc= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119050093707.3223106227948; Wed, 11 Sep 2024 22:30:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPJ-00009X-Uj; Thu, 12 Sep 2024 01:30:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPF-0008O6-7K for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:13 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPD-0002yT-Fv for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:12 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7191ee537cbso411545b3a.2 for ; Wed, 11 Sep 2024 22:30:10 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119009; x=1726723809; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t3uTPve2mzx49hu7WEVCseBvT4eXpfBEBSsLLj942CY=; b=N0lHiWRD4cS2I2MqNFbN/tORLZR2ert36LGNcgp0xKA8yCTQ+nV/rRtw8cwBqV8B0k G6CXXrazWxdte+Lx2h2NxcbW8+1UZOEbaH5PRIFEVDPHMRTQVnQYvfUR/Z+HtSw7tur3 A9jwi1sCZMs3HIVzvaijyC38H4EyOMumDFJAb6NoxhySZJ1Fl8oCwRMIAn0vnb04qdsq dr1Yzb/xdavsuFeNLpfy8aFlYQrjV0YjF7HljMI3JrtmxjGokEnGQAs/zg7oXxcGFApE LSqfZ3A8ruFDOGF1nBTtloVzuL5LV8GXl1zGujp4ZlQZtrLwrfNjcvTOhtYuqoTKALyO R44g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119009; x=1726723809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t3uTPve2mzx49hu7WEVCseBvT4eXpfBEBSsLLj942CY=; b=N4tPnmJPilJxAU6PMAHz9Y3Hm5PrYJ06YH2sbPVjzxtwxN31i1gOZklhDnLCvwpexP YRBN1NGXuwkuuM+jUQgjgFQztsctbyfjje7N1qRoVxLVu3RbC1n5QA7ICZl2A9ykqQ/X YQSxuwtzCB398R3GNQkoWo6+EcVA7PUzKaZiMYZEzRS8I2WNpYcVbHaOG70AT04my//u 8K/d02jaDrGDNYcL6RxVOU2e+R+EY9T3qOPFvKcumLBVn4u/u+RooiDoiZO/uL8ijmDH 2om79SPkw/fMDnM34vR2fZI3XXFIdXod8WI1BrJATZnLfNjhqw4Wq1n1CG6eeIBgmDYX XT7w== X-Gm-Message-State: AOJu0YxoZOIYHi3KAtLqJ/+uTtG8+jpyrelMKJ16cQMRLtfZtg+nJuzV D903lV1wMl9XANdhG6EfeXi9Tn5qdxTFI1q3MgXZdvFpv11twfS5Uh1hgg== X-Google-Smtp-Source: AGHT+IFSEXK0TaAqemG7p92dP4KUTpd36cQy0n8IznMbjBuO6nM2e02WWrWyFMgKWgPdboH8rbropA== X-Received: by 2002:a05:6a00:812:b0:70d:1b48:e362 with SMTP id d2e1a72fcca58-719262065e5mr2379405b3a.26.1726119009550; Wed, 11 Sep 2024 22:30:09 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Haibo Xu , Sunil V L , Alistair Francis Subject: [PULL 03/47] tests/qtest/bios-tables-test.c: Enable numamem testing for RISC-V Date: Thu, 12 Sep 2024 15:29:08 +1000 Message-ID: <20240912052953.2552501-4-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=alistair23@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119052033116600 Content-Type: text/plain; charset="utf-8" From: Haibo Xu Add ACPI SRAT table test case for RISC-V when NUMA was enabled. Signed-off-by: Haibo Xu Reviewed-by: Sunil V L Acked-by: Alistair Francis Message-ID: Signed-off-by: Alistair Francis --- tests/qtest/bios-tables-test.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index 36e5c0adde..e79f3a03df 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -1706,6 +1706,32 @@ static void test_acpi_microvm_ioapic2_tcg(void) free_test_data(&data); } =20 +static void test_acpi_riscv64_virt_tcg_numamem(void) +{ + test_data data =3D { + .machine =3D "virt", + .arch =3D "riscv64", + .tcg_only =3D true, + .uefi_fl1 =3D "pc-bios/edk2-riscv-code.fd", + .uefi_fl2 =3D "pc-bios/edk2-riscv-vars.fd", + .cd =3D "tests/data/uefi-boot-images/bios-tables-test.riscv64.iso.= qcow2", + .ram_start =3D 0x80000000ULL, + .scan_len =3D 128ULL * 1024 * 1024, + }; + + data.variant =3D ".numamem"; + /* + * RHCT will have ISA string encoded. To reduce the effort + * of updating expected AML file for any new default ISA extension, + * use the profile rva22s64. + */ + test_acpi_one(" -cpu rva22s64" + " -object memory-backend-ram,id=3Dram0,size=3D128M" + " -numa node,memdev=3Dram0", + &data); + free_test_data(&data); +} + static void test_acpi_aarch64_virt_tcg_numamem(void) { test_data data =3D { @@ -2466,6 +2492,8 @@ int main(int argc, char *argv[]) } else if (strcmp(arch, "riscv64") =3D=3D 0) { if (has_tcg && qtest_has_device("virtio-blk-pci")) { qtest_add_func("acpi/virt", test_acpi_riscv64_virt_tcg); + qtest_add_func("acpi/virt/numamem", + test_acpi_riscv64_virt_tcg_numamem); } } ret =3D g_test_run(); --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119171; cv=none; d=zohomail.com; s=zohoarc; b=QcAqer6k61rIZnguXIxjNgWUJ7qHcCrhh+tgRcBEgHBXn2oKhe/Ti2u2b3UP5jSsfD0lunioKA4R4RPqyWx/H5ABZuAUrHJJzMu6IKsEo+hp7mVrf6r7T1MMPhJdCvaLvTRmarina4pJYvWrgmWFeCIPw6qd1QEf52Vf+tN62DA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119171; h=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=v4PEFDsxpFWW8kLI+VribdFRqFddzL93mbYGJkbVr8k=; b=iDR0fj5UbHSQfUhJDS9ZABmBYXG0hgIspOgeiQK8HZK8JLG7lrnRy9dpGQSUbnkGvn9Duo24Wz7fMTeZhIYJnuwOGg3xg1bGNm2WaGsrM24Z1mXXT4OexgiK2i1J2tziIGcG0+7ykLQIZ2EGD24fnyQ+nejA+F/5dyXGtg92JdU= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119171140837.6132221073225; Wed, 11 Sep 2024 22:32:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPO-0000OM-L7; Thu, 12 Sep 2024 01:30:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPI-00006f-VP for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:17 -0400 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 1socPG-0002yu-MA for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:16 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7179069d029so371580b3a.2 for ; Wed, 11 Sep 2024 22:30:13 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119012; x=1726723812; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v4PEFDsxpFWW8kLI+VribdFRqFddzL93mbYGJkbVr8k=; b=JQRbgHwLmR0fDpJaBcdOMNmcVRlkyfyz4gVRqJ7+3B2ipVQRHrl2Z3HyEkAUrJhC/z q3DiV00DeEDpz/dVe3ElKcv4Y1fTsfqyj+UsSiMXFmw08jJaDd9Nk8ti4Cyoj9FrkY/2 1E74xVTtQRD91wzs62Z4RtYwZn2Yirju6pqhhaiKjXGgjTdUARORLrD9uSXES2S9GwY2 1JljZbrZMbr09lJu4ypRKSXSsko0/XctkIGu1dnk2ttMMQEFAW6Y0RkbeH3cjgptaae9 t+EhWC9RE1eRJytpq67yvSpt7WHqJKh1F3sqB63zQfZStxjnMQvNYk/g9g8gHg98yVqB YJFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119012; x=1726723812; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v4PEFDsxpFWW8kLI+VribdFRqFddzL93mbYGJkbVr8k=; b=TL7YsRJdMkMG3IPaRkBiVin1B0BA9OU+wA9XrIupcIZzWLzcBRdhiqR1AgKMeZGX0W xoSsH1TMaN7ncseAR52mDK3l1r3DHt+H8mla5wJTdePJkOCT1PrOlIcGjdsh+mW1/YlP fmzbG9MGV0mIiaODeFoPd3S+RiNVBuVJ1kSCPYoG9eacnWLZkh+0lg+lJe1gWAYRre2N LMGpSPAz/1GYtuVB0kLg5kxK4IfFcbu1rbJdb2yHkTzLDhhxsslz2Iq30CfWLvsCHV2g asdrNgzVPZIfeBSpsN7o4RxXH1MSz1WHu6Thx4LMPNc5gM4FZe5jJ4WB2vJAzyv0GXBs 1Jyw== X-Gm-Message-State: AOJu0YxdiRGuqEfs1FPn+C/SL4VWxrZRP8+o0ZaZ6ZUV4QJgRzH6+1Bl JU49zyhum+SaF4RWQtI8FdfU3gVQjrYGos7GWtstopEabd8tvnLH/SRKpA== X-Google-Smtp-Source: AGHT+IHKmeMejQanCM8WgDJNCvfYuc55K30yq64yaCKbXtrxVCOjfWNYr3790hkO1lWo7stY1b6FNg== X-Received: by 2002:a05:6a00:198d:b0:70d:2583:7227 with SMTP id d2e1a72fcca58-7192605871fmr2939725b3a.6.1726119012475; Wed, 11 Sep 2024 22:30:12 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Haibo Xu , Sunil V L , Alistair Francis Subject: [PULL 04/47] tests/acpi: Add expected ACPI SRAT AML file for RISC-V Date: Thu, 12 Sep 2024 15:29:09 +1000 Message-ID: <20240912052953.2552501-5-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119172446116600 Content-Type: text/plain; charset="utf-8" From: Haibo Xu As per the step 5 in the process documented in bios-tables-test.c, generate the expected ACPI SRAT AML data file for RISC-V using the rebuild-expected-aml.sh script and update the bios-tables-test-allowed-diff.h. This is a new file being added for the first time. Hence, iASL diff output is not added. Signed-off-by: Haibo Xu Reviewed-by: Sunil V L Acked-by: Alistair Francis Message-ID: Signed-off-by: Alistair Francis --- tests/qtest/bios-tables-test-allowed-diff.h | 1 - tests/data/acpi/riscv64/virt/SRAT.numamem | Bin 0 -> 108 bytes 2 files changed, 1 deletion(-) diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios= -tables-test-allowed-diff.h index a3e01d2eb7..dfb8523c8b 100644 --- a/tests/qtest/bios-tables-test-allowed-diff.h +++ b/tests/qtest/bios-tables-test-allowed-diff.h @@ -1,2 +1 @@ /* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/riscv64/virt/SRAT.numamem", diff --git a/tests/data/acpi/riscv64/virt/SRAT.numamem b/tests/data/acpi/ri= scv64/virt/SRAT.numamem index e69de29bb2..2b6467364b 100644 Binary files a/tests/data/acpi/riscv64/virt/SRAT.numamem and b/tests/data/a= cpi/riscv64/virt/SRAT.numamem differ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119257; cv=none; d=zohomail.com; s=zohoarc; b=a44eGIaWiAhLBN2BTfny+T1/Qe1T0mmh7Pok9GT9rk3+CvWn+02wsQza6Z2ukXqb4qthd4q30DbwmsXQwXxlWLlnd06mpjCOz2yXVvsV+qVyiMS4NTLO2IndoEPDyBw8FH3mVBMdj1CNm9nliH4zNyrY47SwLhtnotpSCt1CpGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119257; h=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=FihobyF5TVd7Cmn/sPRvZcTI6XyLQLapMPzEBDPYEuQ=; b=I8+u776CHiSvsM+yoqR+NCS5A3z+T2XF6EWUsVAbm1wyLX/3FvnGIa6XzBpp+lStXRJkMSTeCqNd9dW5mAamLU0pz8zA4lysCf/dOS+BqrXhWh/LMx8321YidvEzyXwcJ+2U9f9UonlFFWQSJ3DUX3AF94Km4JCl+p0a2RkGdKw= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119257783333.92480525456324; Wed, 11 Sep 2024 22:34:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPQ-0000T0-46; Thu, 12 Sep 2024 01:30:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPL-0000Ek-7R for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:22 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPJ-0002zD-Ag for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:18 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-718e6299191so291785b3a.2 for ; Wed, 11 Sep 2024 22:30:16 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119016; x=1726723816; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FihobyF5TVd7Cmn/sPRvZcTI6XyLQLapMPzEBDPYEuQ=; b=gbkb4WA5Tie7WYood07Ei0ARROrLnkLRjvzA5rXrT5MykUGqkBunWDszk2Vtrs8mEU GqRAja34EoEUG/rr9+uAGyd1pAKyrogLQAqHT7ZZ+sBkdQHoqiYP37XMJE7C10IO8gUk y6kKb8deRuPPdC8IX+qP6OjrX4e2onW9ab2bdGIr2KBs8FzPmDJpMO61L3xMgvh6vcr0 aG30LFKuGHdNDSksvNpTZdpAksBH4pY3Q4nrXk8To6FOrbCFRosMu0yhnI5u9Qj784T1 NtwEPxYpBjfX31yEPyags2XLHQguJi4ZL8jZWOJz8xYDjBwdgsVi1O8Bqc8etMK5pJ62 bg0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119016; x=1726723816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FihobyF5TVd7Cmn/sPRvZcTI6XyLQLapMPzEBDPYEuQ=; b=uPBfB7opgibaEwGMEagaQsVMPsPOBnFhSFIi28WGrV66279vKH1RlkE5RcjYfhDEZL uPAg6fNQg1vI56eocxRUx3hmsQpsLW2bip5wmXmXwKFXapfFWbBjrCMFacG1BjgSJNJU Mlx6id7w/EPsuT8K463PRmCaZCI7OrDeBPle6MoSGIS3sRoYObUYJp7HBaqzZgNdb9cO 4IOL1pAZCG9lLBFfLP6NirnKaZzUsw/t2nwGFkz0ziGPkvuCzX+UlQwUcGqlHu72JXxs xOMiiOaYXgm/QC/LhvqdCMe8bulrj6iXd3rUV6YwIYNCWAYgVUGmuBgu8zDfQzrstolI IJdw== X-Gm-Message-State: AOJu0YxVdrNgg8iYHkMCAf7oZJ3NuidQdCoslTkAm3h2JIGuoVsEm9Dq QDXTG+7Pbe+IxevubnSSLpGEYREOEzidHmSzQBcH7Iv4CcDZmQ1uo8G4Nw== X-Google-Smtp-Source: AGHT+IFsd3yQPAcWdB7imJ9tUE7I7V3j+NW/8K/QfFRqs+t9/iYFG/pvhVR+AHy9YaBaLSDnI6IKPg== X-Received: by 2002:a05:6a00:1952:b0:714:3acb:9d4b with SMTP id d2e1a72fcca58-719261cb457mr2327387b3a.18.1726119015390; Wed, 11 Sep 2024 22:30:15 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 05/47] target/riscv/tcg/tcg-cpu.c: consider MISA bit choice in implied rule Date: Thu, 12 Sep 2024 15:29:10 +1000 Message-ID: <20240912052953.2552501-6-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=alistair23@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119258809116600 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza Gitlab issue [1] reports a misleading error when trying to run a 'rv64' cpu with 'zfinx' and without 'f': $ ./build/qemu-system-riscv64 -nographic -M virt -cpu rv64,zfinx=3Dtrue,f= =3Dfalse qemu-system-riscv64: Zfinx cannot be supported together with F extension The user explicitly disabled F and the error message mentions a conflict with Zfinx and F. The problem isn't the error reporting, but the logic used when applying the implied ZFA rule that enables RVF unconditionally, without honoring user choice (i.e. keep F disabled). Change cpu_enable_implied_rule() to check if the user deliberately disabled a MISA bit. In this case we shouldn't either re-enable the bit nor apply any implied rules related to it. After this change the error message now shows: $ ./build/qemu-system-riscv64 -nographic -M virt -cpu rv64,zfinx=3Dtrue,f= =3Dfalse qemu-system-riscv64: Zfa extension requires F extension Disabling 'zfa': $ ./build/qemu-system-riscv64 -nographic -M virt -cpu rv64,zfinx=3Dtrue,f= =3Dfalse,zfa=3Dfalse qemu-system-riscv64: D extension requires F extension And finally after disabling 'd': $ ./build/qemu-system-riscv64 -nographic -M virt -cpu rv64,zfinx=3Dtrue,f= =3Dfalse,zfa=3Dfalse,d=3Dfalse (OpenSBI boots ...) [1] https://gitlab.com/qemu-project/qemu/-/issues/2486 Cc: Frank Chang Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2486 Fixes: 047da861f9 ("target/riscv: Introduce extension implied rule helpers") Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Message-ID: <20240824173338.316666-1-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/tcg/tcg-cpu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index b8814ab753..dea8ab7a43 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -778,11 +778,18 @@ static void cpu_enable_implied_rule(RISCVCPU *cpu, if (!enabled) { /* Enable the implied MISAs. */ if (rule->implied_misa_exts) { - riscv_cpu_set_misa_ext(env, - env->misa_ext | rule->implied_misa_exts= ); - for (i =3D 0; misa_bits[i] !=3D 0; i++) { if (rule->implied_misa_exts & misa_bits[i]) { + /* + * If the user disabled the misa_bit do not re-enable = it + * and do not apply any implied rules related to it. + */ + if (cpu_misa_ext_is_user_set(misa_bits[i]) && + !(env->misa_ext & misa_bits[i])) { + continue; + } + + riscv_cpu_set_misa_ext(env, env->misa_ext | misa_bits[= i]); ir =3D g_hash_table_lookup(misa_ext_implied_rules, GUINT_TO_POINTER(misa_bits[i]= )); =20 --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119062; cv=none; d=zohomail.com; s=zohoarc; b=K3Kpb+IJCm2GsN8Erwed5vq/10HK4UbxCgmZT1Pgz+gmX2j02wt//qPHBBKRH5mjLTlzhlti5ygnO+oQrumO9u/6QrlivWIgrOI/tcfUrJM7SQ5Rb8o1dVBT9fC42KozLsUKZpvb7UCK8uVdHYfqXdVIh4jTJNf0TWdF0KRV8EQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119062; h=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=nEqcrjvASUkXL9sGfBA1/Ox7MJPQ1GfLBPBXbleYroY=; b=NQZaVQzocwvroWfgiKrtv4bRF6EzOZK/uFRBmUX3pibaHzDiujxu2X3JbN2OPiC/4JWzT/EForVfC5PBYV9U70g5lqZt+6tVOuzBNPtdW1Lo4Z720whe9+h8GH6NAL8H/kBv8RCqQmbMwXFibmxsSejyiYQdN4Nvsprc6jfcZBo= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119062948954.5601797953893; Wed, 11 Sep 2024 22:31:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPR-0000VR-2P; Thu, 12 Sep 2024 01:30:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPO-0000PI-UI for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:22 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPM-0002za-QQ for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:22 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-7d4fbe62bf5so422666a12.0 for ; Wed, 11 Sep 2024 22:30:20 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119019; x=1726723819; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nEqcrjvASUkXL9sGfBA1/Ox7MJPQ1GfLBPBXbleYroY=; b=O/X9HS44ngc0554KfFV/w5QodR31pKanRatBhKhEq20f7FEjQ2/NG9UQPNEbspge8g 6r7ZuwK6zyf7edv4m8ATflpJLhb2ywZx/rn3fwzceIdrwIEQPdoZ7n20KSFY9APJiCF3 PQ+OsvR4OY8eaSnlU/StP5vRf+ToGMFw0mccMwJibogHkrUFfoxp4RFsBJXT6tIVYwOT /f7ub8ZsDNzI2eAeblbom/3cHvVg/hu2xw590Cd1n64TpYVTuS7MFWLxsKUqeoBK8aFR 3zwe/gLRdwdG727z35iowz+8UlXqf90PD3zxZXywSw4ailZwChwwjKOjwNx62D9xbQD4 ah+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119019; x=1726723819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nEqcrjvASUkXL9sGfBA1/Ox7MJPQ1GfLBPBXbleYroY=; b=X89HwoldmkT4VELPJD+ngi1J77x5ViMm2KK9jQ78aI70S74UNR5QFjXsgvLm2VMCFy TzVrv/zujGZFy060CFIE00w+a0SjykxjN8aY3qmQovPhUBcxcJPYdyOYBroCK6nlDNA+ xqfEeN1VyODntYbzxneKdp7QW9CCdpEvblG2/ElbpVmOLNNxFyC1cm/qSIcIW7KoiPS8 DDpDuM3J7Mjqi6D2/gXMDh3R6CQc/1fTyqk73+Q7JxUA6/jX+PRCExBUlIBHgPli/zTU yEFLasytMro0N9qC7rFNAG+xWHPVu0CsXZ3R9BOHD8Jng4jGCXtQYDStWvEq1hgDdQ3y p6jw== X-Gm-Message-State: AOJu0Yz9guz5M2vUBQpUA2TeKtATUxlnN4xCDSdIW2LEBtdFzlCXB/Ns ovYp0Te1Q/EpssR9a0pCdzhNl/KmxTVYyoc9wNrRTeV7wt2qsoMgTEnlTw== X-Google-Smtp-Source: AGHT+IGRPKx+qBHm3vsMn4jtwC5gZkT3VqRqiW3oCN+c6LTe2XLKYjgK0GXly0VbxS8YyX20O5nRpA== X-Received: by 2002:a05:6a20:2d09:b0:1cf:6d68:5654 with SMTP id adf61e73a8af0-1cf75f10dd0mr2078779637.25.1726119018657; Wed, 11 Sep 2024 22:30:18 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Vladimir Isaev , Alistair Francis , Daniel Henrique Barboza Subject: [PULL 06/47] target/riscv: fix za64rs enabling Date: Thu, 12 Sep 2024 15:29:11 +1000 Message-ID: <20240912052953.2552501-7-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=alistair23@gmail.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119064076116600 Content-Type: text/plain; charset="utf-8" From: Vladimir Isaev za64rs requires priv 1.12 when enabled by priv 1.11. This fixes annoying warning: warning: disabling za64rs extension for hart 0x00000000 because privilege s= pec version does not match on priv 1.11 CPUs. Fixes: 68c9e54beae8 ("target/riscv: do not enable all named features by def= ault") Signed-off-by: Vladimir Isaev Reviewed-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza Message-ID: <20240823063431.17474-1-vladimir.isaev@syntacore.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 8f21171ffa..f93bf9c221 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -115,7 +115,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zihpm, PRIV_VERSION_1_12_0, ext_zihpm), ISA_EXT_DATA_ENTRY(zimop, PRIV_VERSION_1_13_0, ext_zimop), ISA_EXT_DATA_ENTRY(zmmul, PRIV_VERSION_1_12_0, ext_zmmul), - ISA_EXT_DATA_ENTRY(za64rs, PRIV_VERSION_1_12_0, has_priv_1_11), + ISA_EXT_DATA_ENTRY(za64rs, PRIV_VERSION_1_12_0, has_priv_1_12), ISA_EXT_DATA_ENTRY(zaamo, PRIV_VERSION_1_12_0, ext_zaamo), ISA_EXT_DATA_ENTRY(zabha, PRIV_VERSION_1_13_0, ext_zabha), ISA_EXT_DATA_ENTRY(zacas, PRIV_VERSION_1_12_0, ext_zacas), --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119245; cv=none; d=zohomail.com; s=zohoarc; b=RBdBJ5ZtAqVEJRSVFVyxgodnY9UIBBBS9js3MEklMiJhwv7N3JwZwOS3fFDyTfuLQwfoNGD8Wjbi34yXq5AIUvUV9PUO2CPzvdtFFAxbg8LAsvj7n0jxZ8lHE8sJrDx8/sHx+StRij/laU5f7xgxtjO5OD471IOwi9YnGmAn98Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119245; h=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=xl2u8VSlAsDXatryQRsLfhflFKGJFdFrYq4cRLhSKls=; b=YPfKUnCpDC5gcE+FK38lLu+eyA0KgZxUZx7qmefOrRKJtjpP4w8FUY12IPBNGkLLI/xpdA2sygEFkqYMwj9bhtbZ4NtMOj2PR1Iue7s+XIMLiLIsZluE/xEsqk8pr9k/AQUT3d653WK2iSYrgNyJe9fjJ9ZF1SCeOpaRmNK6rhw= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119245186454.2241595281971; Wed, 11 Sep 2024 22:34:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPU-0000gx-4I; Thu, 12 Sep 2024 01:30:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPR-0000XO-Bn for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:25 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPP-0002zl-Hh for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:25 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-718d606726cso313550b3a.3 for ; Wed, 11 Sep 2024 22:30:23 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119022; x=1726723822; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xl2u8VSlAsDXatryQRsLfhflFKGJFdFrYq4cRLhSKls=; b=GciZP3ue3ve8iLqrOTH8D1bA0YFTY/H+C35eTMMtCJrYj7v0r2Izih/2D9/Yikmw16 vRopy2LOZqQ49/gR5Io57TuFzCeP6vmm1DlN1qqf671Q+k75GKQWzxJ/PquSU92Ow9D6 lUDkfCRmtpDysnrtIltnkGfA/cWec+Xuz6qpuuawtMdmr9hBZD8vXZp8bBlsoJXryuU8 zm2yM8d3xLS4ijOLT0eMSa/CbOEFz6HUuQ+NHTOPC1MlwnfFJIESbtKQUaGOqtzlZNkj lS0665NAid4mZstxnVnHyJFxO2AJvuk4BALYiLfr/gDQdTi25N2rA5ojSIByaT0WlXHu w5rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119022; x=1726723822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xl2u8VSlAsDXatryQRsLfhflFKGJFdFrYq4cRLhSKls=; b=ZbAEdmMZQ6sApbCoawbGr9bXRBZ3FaWSBUhTBu9IkE0lFW2/DFVev8NwrnIb+UTCUi kdSh08Hhqwhv5CPQXxw3nVr7ryahlfCbva/EgZObGrTusZWNTuJxTpg4FtqEh0cSRN5P gWqbCIGM+hSSavoFWLMK5Y5dzuiAFtmS2rA9dqNMhLra7LCoR9zqBhC5slS50eEzWTfa VzdviJEu4/MiuP8TZXFUIlKL/eBulMuzIMfBivvh/xQ7wDR38yIxfBYklT619ep4TtEQ amEpSROkylqKcm5DWzv+mH6gNrOj/V3mTnQSn9eID28xuokjFr6HnPMi5unj8/TYx8Jh +3KQ== X-Gm-Message-State: AOJu0YzVAMSzXgkMFjtOPKtgn2FCLk3jrgQB+HJWPfuo36lHXDbunwf8 v7dgKmGDQNg5Rj2uG7lwA6mv8T3eYl7VwbSdZX95mEMAvsFaUWwfZdqGow== X-Google-Smtp-Source: AGHT+IFO2Kb3C6kauazbiL2J/6MLPd4fk7ySnx++j35LzCP4/rGP+jzuuR1/CJY6/cVwxp9ju3DHfA== X-Received: by 2002:a05:6a21:3305:b0:1cf:3996:744e with SMTP id adf61e73a8af0-1cf761e559cmr2048548637.39.1726119021323; Wed, 11 Sep 2024 22:30:21 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Alistair Francis , Daniel Henrique Barboza Subject: [PULL 07/47] target: riscv: Enable Bit Manip for OpenTitan Ibex CPU Date: Thu, 12 Sep 2024 15:29:12 +1000 Message-ID: <20240912052953.2552501-8-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119246757116600 Content-Type: text/plain; charset="utf-8" From: Alistair Francis The OpenTitan Ibex CPU now supports the the Zba, Zbb, Zbc and Zbs bit-manipulation sub-extensions ratified in v.1.0.0 of the RISC-V Bit- Manipulation ISA Extension, so let's enable them in QEMU as well. 1: https://github.com/lowRISC/opentitan/pull/9748 Signed-off-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza Message-ID: <20240823003231.3522113-1-alistair.francis@wdc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f93bf9c221..fc3f75e826 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -701,6 +701,11 @@ static void rv32_ibex_cpu_init(Object *obj) cpu->cfg.ext_zicsr =3D true; cpu->cfg.pmp =3D true; cpu->cfg.ext_smepmp =3D true; + + cpu->cfg.ext_zba =3D true; + cpu->cfg.ext_zbb =3D true; + cpu->cfg.ext_zbc =3D true; + cpu->cfg.ext_zbs =3D true; } =20 static void rv32_imafcu_nommu_cpu_init(Object *obj) --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119134; cv=none; d=zohomail.com; s=zohoarc; b=NrtG/k9ExGeZ0GDQJkZxJWvDX2uXG2luB2wMEXJNbCobv8hheYAja0aGRJpV9JtT6dxSi/UZb4wU3mI9+1xb+pYXW2MCqRwLvBZC0ubpSaA3dzwgxQbgCtTuey0wXBC7QrtAPogqi14+WDOmfp81gQIuxwxbYmnJmWnhBxIb+D4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119134; h=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=WQnac83Zqcp2GhG5unJHuaV5QZRaiVQQMbeeoAzBig4=; b=OlmuArsKChuuF8wgSE/xPMN8I2y+6h+3Ftq92Tlh/mV6EQfc6zZ18ByN8SulwDgl1Ahks0U6+q2Rj2vfGXRR8PKRkuN4vULqad0fG/0uJSrxn9aLSRldWXpq/Mo1ZeNVZNLU47sMsxvolZ9IiqM1qi6GKLV9sRnSdjSIGQDeXlk= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119134032796.2188101573594; Wed, 11 Sep 2024 22:32:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPZ-0000xk-Px; Thu, 12 Sep 2024 01:30:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPU-0000hk-72 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:28 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPS-000300-JZ for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:27 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-7db1f13b14aso547643a12.1 for ; Wed, 11 Sep 2024 22:30:26 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119025; x=1726723825; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WQnac83Zqcp2GhG5unJHuaV5QZRaiVQQMbeeoAzBig4=; b=DBK8EvsGJnADp79LD5dc9lZrc+krUqJFgVx+AtdCjQJztC3VccJ9hqmGKJAkQjELIX S42jJV3s9ipyxcvkz3ZtEaxE4LeJ6sh39M6Jec+b3xSKCXwQxM4Kv441488Hulm6s1rM ZGUopzwV3jYGAedgG1YveucLz9vAwy3p065zdURbOfTsqdv1Fs8UIweKjI6KaWVXCn+L iZXY0n/xAakFesKZCuj56egCot1N73kn7BvYShCw1oauxs7/azlWfSywfe3+iK8mtLyS ZvDiowRtVPKIajytVDQUi8iFdzIJomNwnNXu4SBjz+EnTajixlbUUpA03NBTZvkNDKpf I3yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119025; x=1726723825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WQnac83Zqcp2GhG5unJHuaV5QZRaiVQQMbeeoAzBig4=; b=L/nKHWreqFWkRof9E4C1mE5Ml56cOqie+k/ZWqBc5V7R8qv8hYi6HKukbkqyhbTNQb x3lSi3Ud7bjHrDd/B1uiOZqFHQiFMCwMTL422w2ZqAPE8ci3weHO7K1U0O1aVwCqs8DR /7tgzmSzBL2veTrO7f3tmJ/8NZChmW7xHJ9+qJWYq0x+MFO3Xa8Nak8BEtPvev/DMbrP clwzzPVVJaVUYGo4Cnys+8Nz4Q+7/prNkobfQFt5owei9bNLUSN/apaj4OV5VPhoWwmn 8I7ahPaPnaKcZW9TZWLmAC4gKokyLF13r8z1Cm0Dcf7S+mpCvrT98nUXlumGkIbP72r7 47Fg== X-Gm-Message-State: AOJu0Ywh3D/hmu1muHGaCQ+B9X+UBk4A2w5xdt9w1bzw5RvQ5bV4unj6 sUsImMgxGdpZcqOjJsUKclnD8o/sPMgJ+I/1WulQ22yprRuhBXg8X8bu+w== X-Google-Smtp-Source: AGHT+IGF4P8QUwHTPeY1tI2ZnWRstojX2l8j2ecq3mx/qDIU07LFjioXOdjTgKVh1dFjKtBVj8boxA== X-Received: by 2002:a05:6a21:4581:b0:1cf:4458:8b27 with SMTP id adf61e73a8af0-1cf764afde6mr2387755637.46.1726119024894; Wed, 11 Sep 2024 22:30:24 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Andrew Jones , Daniel Henrique Barboza , Alistair Francis Subject: [PULL 08/47] target/riscv/kvm: Fix the group bit setting of AIA Date: Thu, 12 Sep 2024 15:29:13 +1000 Message-ID: <20240912052953.2552501-9-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=alistair23@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119134361116600 Content-Type: text/plain; charset="utf-8" From: Andrew Jones Just as the hart bit setting of the AIA should be calculated as ceil(log2(max_hart_id + 1)) the group bit setting should be calculated as ceil(log2(max_group_id + 1)). The hart bits are implemented by passing max_hart_id to find_last_bit() and adding one to the result. Do the same for the group bit setting. Signed-off-by: Andrew Jones Reviewed-by: Daniel Henrique Barboza Message-ID: <20240821075040.498945-2-ajones@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/kvm/kvm-cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c index f6e3156b8d..341af901c5 100644 --- a/target/riscv/kvm/kvm-cpu.c +++ b/target/riscv/kvm/kvm-cpu.c @@ -1695,6 +1695,7 @@ void kvm_riscv_aia_create(MachineState *machine, uint= 64_t group_shift, uint64_t max_hart_per_socket =3D 0; uint64_t socket, base_hart, hart_count, socket_imsic_base, imsic_addr; uint64_t socket_bits, hart_bits, guest_bits; + uint64_t max_group_id; =20 aia_fd =3D kvm_create_device(kvm_state, KVM_DEV_TYPE_RISCV_AIA, false); =20 @@ -1742,7 +1743,8 @@ void kvm_riscv_aia_create(MachineState *machine, uint= 64_t group_shift, =20 =20 if (socket_count > 1) { - socket_bits =3D find_last_bit(&socket_count, BITS_PER_LONG) + 1; + max_group_id =3D socket_count - 1; + socket_bits =3D find_last_bit(&max_group_id, BITS_PER_LONG) + 1; ret =3D kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS, &socket_bits, true, NULL); --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119607; cv=none; d=zohomail.com; s=zohoarc; b=eS7dBGYihdZluIwDaV5rPPAEGmo0zGOuJbeTV9m8NiPs0RyQW0z7an2VfJxJWVULFmq5wcSakPbdyt2SkV55heB9iQHacQdc1thMTaq+MI1VnrtKgE5IgckZCz9g3X+97X6kEW/NH5QWlJxVbJ8NRKcO7n36RZe+6ZvjO+8TQ6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119607; h=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=9EfpUjlJoapmNabWHYxOeHBJ2rWzJCTO2iJ5K7dyJK0=; b=eICidarYztFJpmB6nzo9FvOr14pMu4FQBs4brbdPDAwChVWi6v5oFl78viNvy6hy/By2Sk3X45bJuzzPPKruVehA2p6Z/eC8XMMsAlF23GMgSFau7o16SKtx8nibVtzxIgKwUZXMAoyDr1jWDTafSD+GcvhhQxvpSogUZKHi0I8= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119607552513.8197937131329; Wed, 11 Sep 2024 22:40:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPf-0001BN-Sx; Thu, 12 Sep 2024 01:30:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPW-0000rk-VI for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:31 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPV-00030E-CM for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:30 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7d50e865b7aso552730a12.0 for ; Wed, 11 Sep 2024 22:30:28 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119027; x=1726723827; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9EfpUjlJoapmNabWHYxOeHBJ2rWzJCTO2iJ5K7dyJK0=; b=FfwRmmwWmzk3ThrglottA0+tDXlniKQ3N0lwAXppamdlED/wuY2rCDx1/2swuFkiJg C9TuXLjD2IBC64AcSEkC4AIFVwqEyfPjyPLvtFflqAGjYpZIcPmid3elBTC8vA0/PDEy 5qpz4o3gMvEkSqxgLyqsrzj6hcUSkZx8QkL9l4dqEfNaB8fhyckWVl6bnVIHV7eWfTTD WGQZLs2yHCt1/TslGUZtSvmGJHVCcNxb+PBuSlikPY1mBrtuNALRuAT1WUV/14IutcUV BOYFDH18RPMkMr0ToADcNrhwRzOuUi+OZB+IG5G52F71jng/KEUac2ZBsZLZI8OFlqoM kfRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119027; x=1726723827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9EfpUjlJoapmNabWHYxOeHBJ2rWzJCTO2iJ5K7dyJK0=; b=Yi0ypLQUcXB96k1ZLa7IM0aVXKjUU1sSptik5FmiGWw+bScFo7rRhTcRLnZaSrBuf6 PzTHrONAQE5MgPhAJvunNZhkGhyyOaKf2dzYHEri/gG8fwu6OjvbWw1KDmvo70zFZBJD xxwc9GmstytYIus5/wYq5kkhF3H/8lvneaRZKMAg5jllBNY1hptQxdwbwE8NZQB0vaky lwSqtFCwHVVM17hr8QAhWjX3tM7QiSntiod1lgSXsHDvZkCEmrivLvltC3X6UNV0xv1a 8QJ6cyoWNPoYltcoT6uNQ6MN+rmMhpBb9JGd0c2GRJvC/NZ2SI4BTNIAalcX9knX83ey j0SQ== X-Gm-Message-State: AOJu0Yy867aokBr/xQwLJ3nlXkPigcaKTLOwWQIyedMMooBisI8Kko+0 dJb4/QC/Y51iAdiv0J/2L2NCNMI88Web6rX1tdnmPX611bdc+0J0TrovoA== X-Google-Smtp-Source: AGHT+IEOxXXdYaUc+ZCD6Jq811wkYqmu8Rf8jbRARxhIxaGj3q5CuxKdihHUyzOH9ZjNKnZ+qnrEZg== X-Received: by 2002:a05:6a21:58d:b0:1cf:5370:3b0 with SMTP id adf61e73a8af0-1cf75f00300mr2655576637.12.1726119027526; Wed, 11 Sep 2024 22:30:27 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Andrew Jones , Alistair Francis Subject: [PULL 09/47] target/riscv: Stop timer with infinite timecmp Date: Thu, 12 Sep 2024 15:29:14 +1000 Message-ID: <20240912052953.2552501-10-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=alistair23@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119609093116600 Content-Type: text/plain; charset="utf-8" From: Andrew Jones While the spec doesn't state it, setting timecmp to UINT64_MAX is another way to stop a timer, as it's considered setting the next timer event to occur at infinity. And, even if the time CSR does eventually reach UINT64_MAX, the very next tick will bring it back to zero, once again less than timecmp. For this reason riscv_timer_write_timecmp() special cases UINT64_MAX. However, if a previously set timecmp has not yet expired, then setting timecmp to UINT64_MAX to disable / stop it would not work, as the special case left the previous QEMU timer active, which would then still deliver an interrupt at that previous timecmp time. Ensure the stopped timer will not still deliver an interrupt by also deleting the QEMU timer in the UINT64_MAX special case. Fixes: ae0edf2188b3 ("target/riscv: No need to re-start QEMU timer when tim= ecmp =3D=3D UINT64_MAX") Signed-off-by: Andrew Jones Reviewed-by: Alistair Francis Message-ID: <20240829084002.1805006-2-ajones@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/time_helper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/time_helper.c b/target/riscv/time_helper.c index 8d245bed3a..bc0d9a0c4c 100644 --- a/target/riscv/time_helper.c +++ b/target/riscv/time_helper.c @@ -92,6 +92,7 @@ void riscv_timer_write_timecmp(CPURISCVState *env, QEMUTi= mer *timer, * equals UINT64_MAX. */ if (timecmp =3D=3D UINT64_MAX) { + timer_del(timer); return; } =20 --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119255; cv=none; d=zohomail.com; s=zohoarc; b=W0CoqSX8Re9nbIBOog4v2Mq4P9e0S4RIhpiJ2iees1VkYFrt1TJvcT0Mg9uwUy/79qEG4PJmIuiBhrDpbx746sLSENk4MmHezZXp0ltNGtRC10noEe26xORo2Pba2ymji8XTF2yJAaOFzgISEgVW2LMd60CLjIrf2R8luLYa99c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119255; h=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=P23SXrWlF898SusDBmeH7ZJkQYTtyW1PAq+jVBP+6cU=; b=ZbcMSBgqiVdQB/cZ0xhRo18rNuTRM6NzkJcsea4IEL/8tntXWA08bJXGQZWV6mM61irxmikYHfUDVBOjWc2ZPTA8CZSc18O9H48qjqgaqca21a2UoApETRMF4UH73TuTkoVfY/qN1A2eUNyHoXhadfQJSRr1jxHITlo0sQ/acwg= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119255779602.4807050907523; Wed, 11 Sep 2024 22:34:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPk-0001KD-7l; Thu, 12 Sep 2024 01:30:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPZ-00011y-QC for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:39 -0400 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 1socPY-00030O-6k for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:33 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7179069d029so371785b3a.2 for ; Wed, 11 Sep 2024 22:30:31 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119030; x=1726723830; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P23SXrWlF898SusDBmeH7ZJkQYTtyW1PAq+jVBP+6cU=; b=eTORKXZk21wK6wRkSLaAOlDvr5BfeTazNDclnTZqY11rZHFRiFwJQqMqY9LaUqDd7F DOoL9h0siMmX0o6Z/2mn/WEzljHrbV0sVhW32i7A+KTD3gvOb/RkAMYT6D8MLrD77dm2 5mPTvdCEWTFqK/s950F32WGm0myJupf077RODLGrKfaqJMxOVpMBbMxbjwg8Bham+3av 0n9lpeebYkIpgSOIy+66Gs6v5YOaZ4SmPIK/zRyKkFezn95yVB7LOnKVT16b4NSTT2Nt m23ZK3wxGitPknca49s6IFsmZGADbd+LZjbbhNPD2m/1lNyBnqJXHqcUY+LBGUbadJAV 2nog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119030; x=1726723830; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P23SXrWlF898SusDBmeH7ZJkQYTtyW1PAq+jVBP+6cU=; b=idV4QntpfqabiC+fHzWm4QU3h+P4fJF9pp17v53RlEFdVVt32z+SAOfiWJcHpAs2VU hh73T+aWdv4NOpnyif658P1WbmfnjvKAI4XV3/lh+VlCgT5AbH3NxzWZWRwy8EpB7AKd z1nTnEoc6ajnT/hMEIgmJF/t+u/zp4/4++SIgD4l9b08ZcR/7WvVRAsttpmLxKtkcg3F YMrU7e0gp0vjXHMd/xfs6i2aWHPnCgnZeHtxrdpyd1Owm2EWqr1JqSDCIGV37CwZFqfP 8vjsml8Jdd6TJHI5JRDXyMCumewTzHzsBKceJh2PYIwEkdOlQ0yzLPDSzbm9IE0l8Iv0 BYYg== X-Gm-Message-State: AOJu0Yw+TZJf0g1QlKleg2PzWX1Uf3IKoHRUD5U5lJCbV3K579hvgoC0 5gUJASrCYDMGbmGQWe+k7Jkq91MSYlfz5Z0B/nJoy/oGWgtFli19QfzM6Q== X-Google-Smtp-Source: AGHT+IGDY4FooubpsitL5EW+9MbOGfJNpy7zsaFPrmseVDMARQIzNHh6yr2KF7737B0peJmncRvDbg== X-Received: by 2002:a05:6a00:2381:b0:70d:2ac8:c838 with SMTP id d2e1a72fcca58-7192605877cmr2747316b3a.4.1726119030446; Wed, 11 Sep 2024 22:30:30 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Maria Klauchek , Daniel Henrique Barboza , Alistair Francis Subject: [PULL 10/47] target/riscv/cpu.c: Add 'fcsr' register to QEMU log as a part of F extension Date: Thu, 12 Sep 2024 15:29:15 +1000 Message-ID: <20240912052953.2552501-11-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=alistair23@gmail.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119256792116600 Content-Type: text/plain; charset="utf-8" From: Maria Klauchek FCSR is a part of F extension. Print it to log if FPU option is enabled. Signed-off-by: Maria Klauchek Reviewed-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Message-ID: <20240902103433.18424-1-m.klauchek@syntacore.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index fc3f75e826..d215681905 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -844,6 +844,12 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f= , int flags) } } if (flags & CPU_DUMP_FPU) { + target_ulong val =3D 0; + RISCVException res =3D riscv_csrrw_debug(env, CSR_FCSR, &val, 0, 0= ); + if (res =3D=3D RISCV_EXCP_NONE) { + qemu_fprintf(f, " %-8s " TARGET_FMT_lx "\n", + csr_ops[CSR_FCSR].name, val); + } for (i =3D 0; i < 32; i++) { qemu_fprintf(f, " %-8s %016" PRIx64, riscv_fpr_regnames[i], env->fpr[i]); --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119317; cv=none; d=zohomail.com; s=zohoarc; b=O+hwpAidYsA6YWb/BSGpPH8WPoT9hIlfgoZ+RSH/PiA26RgvViMBCwdlO6F2kYwD7gP3/VNrNiGepIQjrvHBA8eMQ2Vm79TvCejXxoew7FUXUH+HhVs1vW0nkwcQ+KrRgB3BVRtL1mu2OenwOjWm4IH1fx8S2ghsLA8aUWhdKdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119317; 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=w6UpgoFiKeN8rhCeeJc9Ofq22Ni9JUy4zXN5XGaW1OM=; b=V/8Makmf9H4fuTN4sevxnvC4vDligm1ofZd5lrh4OKrGcTftF37uNk2xqXODFzl9Wng6zu0jYMiw/HkUWUr2guO05FmRnixOG32QB6lGmaefCCZ87m9smgxssyKqCn8eEXQ9oALV3FSnuwF3ANUTVSVdZWj6QwE4hXlOBMO+VSQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172611931753642.120958488671704; Wed, 11 Sep 2024 22:35:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPh-0001I6-No; Thu, 12 Sep 2024 01:30:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPd-0001Am-Af for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:39 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPa-00030Z-Lx for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:36 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-71798661a52so407263b3a.0 for ; Wed, 11 Sep 2024 22:30:34 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119033; x=1726723833; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w6UpgoFiKeN8rhCeeJc9Ofq22Ni9JUy4zXN5XGaW1OM=; b=F4BzFmiKqWDxhZUDUpV+i2b6FvkRWR+vRXkkXIsgejbOUadY81zBTs6ZldK0nTwisK CQj5piW4oihjwrNfULGzPWfWqO4oInNJDzQvV5+KtUWIgIrbTmPNwcz7dulSMtOLRwcu aRXurMtbUZP/Nr6oF9vm0dfFK49DgDVLfintyj5vLocOQaalY7/L9xcVZnviqDPLekwh iw+F5pdC/OFXCnDXGIe55j6ROxCVlBtP40kkErlK6TEHUEI1zV9mx6Q0BvHtGE9xt+aj Ml5J6pQeasU0Q0Rqh4LoDpJWR2bb7nPlrZkxhbor6r/O1YwSByYLPPIwC4wmmChLy6CW iFnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119033; x=1726723833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w6UpgoFiKeN8rhCeeJc9Ofq22Ni9JUy4zXN5XGaW1OM=; b=TWCSDTuBzoj2kl5jji7eAx/j4NUSzEfxIf31gAistJCZR03yMhXDsp4og/Dn87tWDj dAiJqGY3thCgkA6SxFngQiNF26A3gyyF0VRyAlthPEgrj6eRJ27CcH16Mz+FQst4J0jf Msu4kM8qRmX6z9rtzNqrXBClPahKa/FrvKMGyi00XVNZ0vXW8CtZ7YdJ2madGpPjWkHJ fcRYZnsgnLDLLLtfwhaUMkaGpwXkipUufUjjvhGKa5wd6+Y8FtQs0bOX+inJiOEU/Nke nDbcO9mPGAm7FyegWA2gunmt6gkyGG6hK/yah80qUUvUwAqb2hLh6WiIn4XGf15Typuq Iqow== X-Gm-Message-State: AOJu0Yxx+Dm583DY0JgIStWSvyOlCvUywmWeDIUZkTd32DA42Xvmoplr shpYcluF83UEJsUZPuxbQGhXULmWS81UAsFC2YNeoVzocsDfUtEL1m0fyg== X-Google-Smtp-Source: AGHT+IG+nsL9jDo7QpCt5svL9WkhA3cNcUrR3X2kL4n5NQ4w9dSQva4SR3emVNUpcaFYdGE6A1wAfw== X-Received: by 2002:a05:6a00:8805:b0:717:9340:a9d0 with SMTP id d2e1a72fcca58-71907eb816bmr11989839b3a.6.1726119033132; Wed, 11 Sep 2024 22:30:33 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, =?UTF-8?q?Milan=20P=2E=20Stani=C4=87?= , Alistair Francis Subject: [PULL 11/47] util/util/cpuinfo-riscv.c: fix riscv64 build on musl libc Date: Thu, 12 Sep 2024 15:29:16 +1000 Message-ID: <20240912052953.2552501-12-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=alistair23@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119319019116600 From: Milan P. Stani=C4=87 build fails on musl libc (alpine linux) with this error: ../util/cpuinfo-riscv.c: In function 'cpuinfo_init': ../util/cpuinfo-riscv.c:63:21: error: '__NR_riscv_hwprobe' undeclared (firs= t use in this function); did you mean 'riscv_hwprobe'? 63 | if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) =3D= =3D 0 | ^~~~~~~~~~~~~~~~~~ | riscv_hwprobe ../util/cpuinfo-riscv.c:63:21: note: each undeclared identifier is reported= only once for each function it appears in ninja: subcommand failed add '#include "asm/unistd.h"' to util/cpuinfo-riscv.c fixes build Signed-off-by: Milan P. Stani=C4=87 Reviewed-by: Alistair Francis Message-ID: <20240905150702.2484-1-mps@arvanta.net> Signed-off-by: Alistair Francis --- util/cpuinfo-riscv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/cpuinfo-riscv.c b/util/cpuinfo-riscv.c index 497ce12680..8cacc67645 100644 --- a/util/cpuinfo-riscv.c +++ b/util/cpuinfo-riscv.c @@ -9,6 +9,7 @@ #ifdef CONFIG_ASM_HWPROBE_H #include #include +#include #endif =20 unsigned cpuinfo; --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119708; cv=none; d=zohomail.com; s=zohoarc; b=SlhSgzvOVl8cYt5DCyp5A7/CdJ5yfL5BSQ23aO5f+7o7WDHQymiufsT5ZcEiVRWq38msVXltkYSXYj9P8MN7G2pW9kPjCIdEIkmJ4oqkaxRLJhvqmI6KlTtowroxAhG6NNOYjVNJK1pXsQAqTuexkF/06WGLSrkQC7lRd8Oz8sQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119708; h=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=wQLh5favEwPC3T5JVQV5e7WmeMzusKhuamksZ0+89Yw=; b=KOP0OR5UAhnKzYduJrLqMUdBspqa9iFTMG75ZNWGqAn/QUKKiXGaDxnEc0nVLJnEsfSnLH+6m7wYfH7P5vgRax6unt9rj98hPoIgquFuqXjAOQD86R89e7Gti8vRqvF2Oy0DLQLATqUOryv/1gy4b9t9eq8giZ+GojRxkEubIlA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119708316867.6325058113348; Wed, 11 Sep 2024 22:41:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPn-0001Zp-BF; Thu, 12 Sep 2024 01:30:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPh-0001Iz-TX for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:41 -0400 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 1socPd-00030n-VS for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:39 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so540805a12.2 for ; Wed, 11 Sep 2024 22:30:37 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119036; x=1726723836; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wQLh5favEwPC3T5JVQV5e7WmeMzusKhuamksZ0+89Yw=; b=ELnY/SiWY4mDP3e5v58iwVw5P/xV9xMwCy/lVT0FguNJk99xswxzmd1BK2FGL7P0f4 ObKPtbPC8O/y87bx+bX8JT1NKdGQIJjrRWqLxvCvmiqALrmc3VLDPpJzWGmh1J75eYBt //AwHuybbPajPF1254ExTaFBemgO4AUPF6pKvUngtB9jtJkd6b6aEBoRgjSg/l7ujuxh CQGgsRMQsh7D8PPVZF9PveZo516JmuysglO4E/1IAUD3KoSocd1Mpm466fjgGsce3f/y aByIzig9kuVxqTITSS/z16QIpjZcsSa5/E9a6/aG9DB5jwo7cfEVFCtxaRcB/WnlYdga 3RoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119036; x=1726723836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wQLh5favEwPC3T5JVQV5e7WmeMzusKhuamksZ0+89Yw=; b=bCcoVPQVP0+UVllnf88yeQLSm/8bJXNY2cHqKU/u7iHTyRPG0OUbVvGPG8Pime5p3a +xAnuv2b/XaNAbhhGM4PDHfEYf/FI2VCHh1on/w1tIOA3zd2ORHuZipQ8PJPc7w9avpb ECxwZDmLumGBeM+NcWOuYaP0YQHNs65S4IbCVme/ArH++N7jtt7YVtjBvXtcPiQM01CI 5dBinK/ZXQcpS4Pt9GX7JzS6ksIOav2FNAy6+k6vwgLar7YIFz4NHiJke9mtGgdxQl3t 25Y+OnQCGxjF50rjkJ14wDpcJTwc98XnAeYs+uF2l8OS7gk5JmwUX6WkwDMxq6581W/C Cvjw== X-Gm-Message-State: AOJu0YzwH85ha+Ls7PeNwl+OzdPnhih3MCiwU22sssmRk2Sc7gwnf/MX uUI4dQEdrYF1adm68EyGVrhSjbkAqlAb+p5Vrdpz9e3guXpDw5W6R9yFsQ== X-Google-Smtp-Source: AGHT+IHkdPninia+JpeDUTA0AB+bTY2tK2QTJswS4S2pThfaKSTVVAKti3adEheJ+5g/6Ld9AkQS9w== X-Received: by 2002:a05:6a20:e609:b0:1cf:2ad4:3083 with SMTP id adf61e73a8af0-1cf75f2a5cfmr2599793637.23.1726119035861; Wed, 11 Sep 2024 22:30:35 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Alvin Chang , Alistair Francis Subject: [PULL 12/47] target/riscv: Preliminary textra trigger CSR writting support Date: Thu, 12 Sep 2024 15:29:17 +1000 Message-ID: <20240912052953.2552501-13-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=alistair23@gmail.com; helo=mail-pg1-x530.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119709867116600 Content-Type: text/plain; charset="utf-8" From: Alvin Chang This commit allows program to write textra trigger CSR for type 2, 3, 6 triggers. In this preliminary patch, the textra.MHVALUE and the textra.MHSELECT fields are allowed to be configured. Other fields, such as textra.SBYTEMASK, textra.SVALUE, and textra.SSELECT, are hardwired to zero for now. For textra.MHSELECT field, the only legal values are 0 (ignore) and 4 (mcontext). Writing 1~3 into textra.MHSELECT will be changed to 0, and writing 5~7 into textra.MHSELECT will be changed to 4. This behavior is aligned to RISC-V SPIKE simulator. Signed-off-by: Alvin Chang Reviewed-by: Alistair Francis Message-ID: <20240826024657.262553-2-alvinga@andestech.com> Signed-off-by: Alistair Francis --- target/riscv/cpu_bits.h | 10 ++++++ target/riscv/debug.c | 69 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 32b068f18a..7e3f629356 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -947,6 +947,16 @@ typedef enum RISCVException { #define JVT_BASE (~0x3F) =20 /* Debug Sdtrig CSR masks */ +#define TEXTRA32_MHVALUE 0xFC000000 +#define TEXTRA32_MHSELECT 0x03800000 +#define TEXTRA32_SBYTEMASK 0x000C0000 +#define TEXTRA32_SVALUE 0x0003FFFC +#define TEXTRA32_SSELECT 0x00000003 +#define TEXTRA64_MHVALUE 0xFFF8000000000000ULL +#define TEXTRA64_MHSELECT 0x0007000000000000ULL +#define TEXTRA64_SBYTEMASK 0x000000F000000000ULL +#define TEXTRA64_SVALUE 0x00000003FFFFFFFCULL +#define TEXTRA64_SSELECT 0x0000000000000003ULL #define MCONTEXT32 0x0000003F #define MCONTEXT64 0x0000000000001FFFULL #define MCONTEXT32_HCONTEXT 0x0000007F diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 0b5099ff9a..d6b4a06144 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -217,6 +217,66 @@ static inline void warn_always_zero_bit(target_ulong v= al, target_ulong mask, } } =20 +static target_ulong textra_validate(CPURISCVState *env, target_ulong tdata= 3) +{ + target_ulong mhvalue, mhselect; + target_ulong mhselect_new; + target_ulong textra; + const uint32_t mhselect_no_rvh[8] =3D { 0, 0, 0, 0, 4, 4, 4, 4 }; + + switch (riscv_cpu_mxl(env)) { + case MXL_RV32: + mhvalue =3D get_field(tdata3, TEXTRA32_MHVALUE); + mhselect =3D get_field(tdata3, TEXTRA32_MHSELECT); + /* Validate unimplemented (always zero) bits */ + warn_always_zero_bit(tdata3, (target_ulong)TEXTRA32_SBYTEMASK, + "sbytemask"); + warn_always_zero_bit(tdata3, (target_ulong)TEXTRA32_SVALUE, + "svalue"); + warn_always_zero_bit(tdata3, (target_ulong)TEXTRA32_SSELECT, + "sselect"); + break; + case MXL_RV64: + case MXL_RV128: + mhvalue =3D get_field(tdata3, TEXTRA64_MHVALUE); + mhselect =3D get_field(tdata3, TEXTRA64_MHSELECT); + /* Validate unimplemented (always zero) bits */ + warn_always_zero_bit(tdata3, (target_ulong)TEXTRA64_SBYTEMASK, + "sbytemask"); + warn_always_zero_bit(tdata3, (target_ulong)TEXTRA64_SVALUE, + "svalue"); + warn_always_zero_bit(tdata3, (target_ulong)TEXTRA64_SSELECT, + "sselect"); + break; + default: + g_assert_not_reached(); + } + + /* Validate mhselect. */ + mhselect_new =3D mhselect_no_rvh[mhselect]; + if (mhselect !=3D mhselect_new) { + qemu_log_mask(LOG_UNIMP, "mhselect only supports 0 or 4 for now\n"= ); + } + + /* Write legal values into textra */ + textra =3D 0; + switch (riscv_cpu_mxl(env)) { + case MXL_RV32: + textra =3D set_field(textra, TEXTRA32_MHVALUE, mhvalue); + textra =3D set_field(textra, TEXTRA32_MHSELECT, mhselect_new); + break; + case MXL_RV64: + case MXL_RV128: + textra =3D set_field(textra, TEXTRA64_MHVALUE, mhvalue); + textra =3D set_field(textra, TEXTRA64_MHSELECT, mhselect_new); + break; + default: + g_assert_not_reached(); + } + + return textra; +} + static void do_trigger_action(CPURISCVState *env, target_ulong trigger_ind= ex) { trigger_action_t action =3D get_trigger_action(env, trigger_index); @@ -441,8 +501,7 @@ static void type2_reg_write(CPURISCVState *env, target_= ulong index, } break; case TDATA3: - qemu_log_mask(LOG_UNIMP, - "tdata3 is not supported for type 2 trigger\n"); + env->tdata3[index] =3D textra_validate(env, val); break; default: g_assert_not_reached(); @@ -558,8 +617,7 @@ static void type6_reg_write(CPURISCVState *env, target_= ulong index, } break; case TDATA3: - qemu_log_mask(LOG_UNIMP, - "tdata3 is not supported for type 6 trigger\n"); + env->tdata3[index] =3D textra_validate(env, val); break; default: g_assert_not_reached(); @@ -741,8 +799,7 @@ static void itrigger_reg_write(CPURISCVState *env, targ= et_ulong index, "tdata2 is not supported for icount trigger\n"); break; case TDATA3: - qemu_log_mask(LOG_UNIMP, - "tdata3 is not supported for icount trigger\n"); + env->tdata3[index] =3D textra_validate(env, val); break; default: g_assert_not_reached(); --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119941; cv=none; d=zohomail.com; s=zohoarc; b=GhKibLM2U/XH+sAsCycESAhRi54nJn2EHMrVT8zTvSI/UJIhnNp3ILPx/kUL4sZ/WE+Lhrc1PkVvax3P5VGPKgy1UJxABFfab8R9mOQRK0QcF3yGyiZPSn9LfkayAfoL4t5Ym9S+yT1GoprMHPsSxDKHWoCYat1qKGPONSguzkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119941; h=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=zHM5wBkancr1aI05BSHOUm9WH4dpuz+OJwBW2j963mI=; b=TF8PtYhYnPRe4QrzHokm4RGGsn9MHiCbCaOYUL6SHSkJdD1t/mdpP7dXht5AKhOdpSKbezYuB9X7zRCZfxjXST86LW/ZUkQT4C6ec+BL3qnN0MF1TBzhaTMgBB0af7RGtEX4Aa22zGGzkLZWrzrqPQKKUp47fdkNo0yaOiHl0iQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119941041151.32571545085534; Wed, 11 Sep 2024 22:45:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPn-0001Xy-3t; Thu, 12 Sep 2024 01:30:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPk-0001Sl-GP for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:44 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPh-000318-Lx for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:43 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-7191f58054aso453216b3a.0 for ; Wed, 11 Sep 2024 22:30:40 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119039; x=1726723839; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zHM5wBkancr1aI05BSHOUm9WH4dpuz+OJwBW2j963mI=; b=bGmJaXm9nWhEicHHHxj0y9ijo4YN30xFWsqcSZqwmSRnOZR9PMPwHwlbNEYtBQtxqL nYqdeduSViJAAU44g7ri4sZPal2BKMc0zCC2BpHPTQ/1UFg3PYmMynyB9lAkeQgouSuE B/eonpTaL8ufsFQaSHUtDgIGif1Z2RrM6nTGYaKAKtIayiUFXOhdat276RIADhlqQjfU qAq6D6wY3MDNhUThcT5OONMqRkF1114U4WSZKxarjVaX0Ro3rmdVYTvJHGX4TWhIXRNY on0H4nqLeqSBo2ukWDMOxjM6eyhubCD9ZTfWbaTdxQJb75ExCs6lWq8qUB6pvEdVrKFh eNBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119039; x=1726723839; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zHM5wBkancr1aI05BSHOUm9WH4dpuz+OJwBW2j963mI=; b=IjOk3aKARmS/WztK3DXzS/cttgdQ8YaJWR9ULKFE+a47lOi6UEr8gDpmkme4lgfKfX 6D7ftYWKd9S66Cz+HIz44WRPCUX9vsyg3mB8TKiXW40wUg/xi7gBzsmwMyG3SwoND0vB C1sKu6TL8G+VirdOgEzJ/eEaoOHIFJQLuNoa8yGdOuQeTYpdJn6tdNrHTw32zofcLOmh E2VKC91sXptTCO9IX/FlThZdI1qstmrvkOHTk/9hmNsOwnvGr1Mr2Ni1zYIWBI5W5SDo HRtNRAzwXdtTXP8j6YanVcdXiB9yPtgneE2zNyar4Mo0k/6CtdxLbN9mWer1o12pb8FK K27Q== X-Gm-Message-State: AOJu0YyH5S1vI/DbxgVP2g4aZDOFdPzowbVgMvvOR0YlPQTCSiYROURg 14z0NTZ6OLSeJLT9TGJGJ1W/YhBAY9IO5XRY3fH3tWQJ15sSODJM4PO91g== X-Google-Smtp-Source: AGHT+IGkLYVT8qJLWOIwC1qSAqKHGHKgG4ANp0Nc+IwPKd+3UE7xq8yP9juXsYkUJkTqPZQXLIicEg== X-Received: by 2002:a05:6a21:6e41:b0:1c3:fc87:374e with SMTP id adf61e73a8af0-1cf764c255bmr2035722637.41.1726119038645; Wed, 11 Sep 2024 22:30:38 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Alvin Chang , Alistair Francis Subject: [PULL 13/47] target/riscv: Add textra matching condition for the triggers Date: Thu, 12 Sep 2024 15:29:18 +1000 Message-ID: <20240912052953.2552501-14-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119942525116600 Content-Type: text/plain; charset="utf-8" From: Alvin Chang According to RISC-V Debug specification, the optional textra32 and textra64 trigger CSRs can be used to configure additional matching conditions for the triggers. For example, if the textra.MHSELECT field is set to 4 (mcontext), this trigger will only match or fire if the low bits of mcontext/hcontext equal textra.MHVALUE field. This commit adds the aforementioned matching condition as common trigger matching conditions. Currently, the only legal values of textra.MHSELECT are 0 (ignore) and 4 (mcontext). When textra.MHSELECT is 0, we pass the checking. When textra.MHSELECT is 4, we compare textra.MHVALUE with mcontext CSR. The remaining fields, such as textra.SBYTEMASK, textra.SVALUE, and textra.SSELECT, are hardwired to zero for now. Thus, we skip checking them here. Signed-off-by: Alvin Chang Reviewed-by: Alistair Francis Message-ID: <20240826024657.262553-3-alvinga@andestech.com> Signed-off-by: Alistair Francis --- target/riscv/debug.h | 3 +++ target/riscv/debug.c | 45 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/target/riscv/debug.h b/target/riscv/debug.h index c347863578..f76b8f944a 100644 --- a/target/riscv/debug.h +++ b/target/riscv/debug.h @@ -131,6 +131,9 @@ enum { #define ITRIGGER_VU BIT(25) #define ITRIGGER_VS BIT(26) =20 +#define MHSELECT_IGNORE 0 +#define MHSELECT_MCONTEXT 4 + bool tdata_available(CPURISCVState *env, int tdata_index); =20 target_ulong tselect_csr_read(CPURISCVState *env); diff --git a/target/riscv/debug.c b/target/riscv/debug.c index d6b4a06144..c79b51af30 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -364,11 +364,54 @@ static bool trigger_priv_match(CPURISCVState *env, tr= igger_type_t type, return false; } =20 +static bool trigger_textra_match(CPURISCVState *env, trigger_type_t type, + int trigger_index) +{ + target_ulong textra =3D env->tdata3[trigger_index]; + target_ulong mhvalue, mhselect; + + if (type < TRIGGER_TYPE_AD_MATCH || type > TRIGGER_TYPE_AD_MATCH6) { + /* textra checking is only applicable when type is 2, 3, 4, 5, or = 6 */ + return true; + } + + switch (riscv_cpu_mxl(env)) { + case MXL_RV32: + mhvalue =3D get_field(textra, TEXTRA32_MHVALUE); + mhselect =3D get_field(textra, TEXTRA32_MHSELECT); + break; + case MXL_RV64: + case MXL_RV128: + mhvalue =3D get_field(textra, TEXTRA64_MHVALUE); + mhselect =3D get_field(textra, TEXTRA64_MHSELECT); + break; + default: + g_assert_not_reached(); + } + + /* Check mhvalue and mhselect. */ + switch (mhselect) { + case MHSELECT_IGNORE: + break; + case MHSELECT_MCONTEXT: + /* Match if the low bits of mcontext/hcontext equal mhvalue. */ + if (mhvalue !=3D env->mcontext) { + return false; + } + break; + default: + break; + } + + return true; +} + /* Common matching conditions for all types of the triggers. */ static bool trigger_common_match(CPURISCVState *env, trigger_type_t type, int trigger_index) { - return trigger_priv_match(env, type, trigger_index); + return trigger_priv_match(env, type, trigger_index) && + trigger_textra_match(env, type, trigger_index); } =20 /* type 2 trigger */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119735; cv=none; d=zohomail.com; s=zohoarc; b=F7bCHVowMowseYt80tmh7pmma3OGcyTtZHv9qw3tO3DUD/hzX9SeLRmYlyeDwkZ9G4mrYIQFQNFz/lf04oi61DJJqBEXsBSnKS3lIfilJBjFsrNrh4SrxpBHbnB3g6kPtp6MdIoR543R28NQ1Z7qdMcgZyakSNfDy6ve/8h3pgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119735; h=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=afEpHTThU9gcnAC+v8AUAUMqHz1ovSP2re97I4R4gXU=; b=nbb55ZFhfVl9jS+xZ/QpJBw2iBXpJ6pSCqC3vfRl0AZGtC4bhYi4QoOwOD1lpJc7bCOkPwWYo6KMWy3LpHhKGErgHTqJjXlBmZG3+WBdH+EdsBcNLTnwrvrt1rKT38l0NrkV9DC+W86N/pkQQKlHqhRma6/I34RbjIRSpxJlZtQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119735657892.4848772605864; Wed, 11 Sep 2024 22:42:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPp-0001mm-IN; Thu, 12 Sep 2024 01:30:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPn-0001c9-6p for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:47 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPk-00031P-8j for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:46 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-206aee4073cso6393075ad.1 for ; Wed, 11 Sep 2024 22:30:43 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119042; x=1726723842; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=afEpHTThU9gcnAC+v8AUAUMqHz1ovSP2re97I4R4gXU=; b=KgglOKSIg2MmI2waqSM3mGr8nm36QuJndYnw1ySGxAPdzDSjnVf6/QzbjO1PbgXPNN Wbvl+xuHqEanhpAqhAqVldByOid6dvDK7VORw7fuNSRRLPr37jI9/Egy+LsZjgOHp+Am IJNLZjqsamyWLi1cqmqS9ZxIiyRi+cT1KrUQXowiRS/lZy80Cv/1mz07or6uUb20M8vK AjBYD+AoKvrD943OU+SRnHS3aDJBg9+qlyrfdO+9V3Rugfa56XITi1pBHxKK4LwvH/55 biqNrs/L68a0p3S6cha5NVjsDyTca7Be+Ds0kgVhkEk/C0mJiBt7ggOgAkOp+j2cjdT+ 9Vpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119042; x=1726723842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=afEpHTThU9gcnAC+v8AUAUMqHz1ovSP2re97I4R4gXU=; b=Ytmknq8YvC/EQF6dIIyljbh9CTmzv5kftb6s3hL0+mP8hzoMHUAsZKEP8ueb9xKbjH +OtOooglyMXnmK3MScwJLyu9M34yAopDYptUzbcu40h5Ytb72+KZE9+uqAmRPEma1ShA zlr908+j7dwBr5s6pJw5/B4O/+wvhkqiCll3YKh5ePPl88qJCkOsYicNo2YZyWJRJKIA JCbbwjoRMlf1C3jd4HQwzH8Qoco4KmyuNuINZGMFZo3OYeZM7aR3zLdja9gu7sVFbgT3 qmWG4QlphtiINCp+jp74bBH+2x6Eqich9EDO8atOyF1z9RRxPBrRv+IxRLyxWQxG3D+E JSig== X-Gm-Message-State: AOJu0Yy/PsxK/nZFTxxmp/3c/JrESgkaSogGvKPxjAQjQnfqUGInPmMn aRSJnDkoqA2NIs7oZEMfv5YXjCh3MrC42G5DFvR+XvX9NdPo2a2mOv1/DQ== X-Google-Smtp-Source: AGHT+IFLkyOPvfMxjuwvzIVQiGo14LpK/PsBzTt6ydSwAGkRuQrl6vuJ2lPB1avNUzCiZ++8QivwFA== X-Received: by 2002:a05:6a21:3a41:b0:1cf:5aba:eac4 with SMTP id adf61e73a8af0-1cf76493e8emr2272974637.41.1726119042105; Wed, 11 Sep 2024 22:30:42 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Frank Chang , Jason Chien , Alistair Francis , Daniel Henrique Barboza Subject: [PULL 14/47] exec/memtxattr: add process identifier to the transaction attributes Date: Thu, 12 Sep 2024 15:29:19 +1000 Message-ID: <20240912052953.2552501-15-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=alistair23@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119737962116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach Extend memory transaction attributes with process identifier to allow per-request address translation logic to use requester_id / process_id to identify memory mapping (e.g. enabling IOMMU w/ PASID translations). Signed-off-by: Tomasz Jeznach Reviewed-by: Frank Chang Reviewed-by: Jason Chien Reviewed-by: Alistair Francis Signed-off-by: Daniel Henrique Barboza Message-ID: <20240903201633.93182-2-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- include/exec/memattrs.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index 14cdd8d582..e27c18f3dc 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -52,6 +52,11 @@ typedef struct MemTxAttrs { unsigned int memory:1; /* Requester ID (for MSI for example) */ unsigned int requester_id:16; + + /* + * PID (PCI PASID) support: Limited to 8 bits process identifier. + */ + unsigned int pid:8; } MemTxAttrs; =20 /* Bus masters which don't specify any attributes will get this, --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119649; cv=none; d=zohomail.com; s=zohoarc; b=ZylO0Vu93BXA6ZDZ33i4/xzS5bPv8j+H7n0owuICJPi+MaFsjLSj8rAZ0mb9Cgp2pTx3CajxeMwXt4yhIMGng2SxRe9sqaFDI2/kolK121oFuqQXBLEgS2Lj5N+dC9Z1PjUQkbcaW2n5RcYfvGQufhR10HmjPMz6BYd7dvImYA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119649; 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=ybFbHFlG9EAgbyzyh2VZOYLseAu6WmHgRvomZ8hfETQ=; b=KEM30Gfm1h2t0BwRCoWNppAAzD2GdUW4WKVU54NHISv5agWtw+ZFx7nMSjkW7LA5bdugdZoMU9Pp1qJ1i3xmNLVg9aDhnpLYK4swE09WE12U63pCIlibCsIuJRixiGz8zjBukotGHnweWfCp9hr2ggi0q2RN6QhoTIUliXKvCyU= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119649910606.1331689737879; Wed, 11 Sep 2024 22:40:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPw-0002Eb-8l; Thu, 12 Sep 2024 01:30:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPr-0001vQ-JU for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:52 -0400 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 1socPo-00031p-0H for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:50 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-718da0821cbso415473b3a.0 for ; Wed, 11 Sep 2024 22:30:47 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119046; x=1726723846; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ybFbHFlG9EAgbyzyh2VZOYLseAu6WmHgRvomZ8hfETQ=; b=EAnXZlC4HeVPPU7e9z91lxB2rsY/SJ+m4iWqMAFWX29zY5MH+cBwZ5eiSu4zJzPhZz Rj/lx+0UcJjjvaummDY9DKrMtvP/fgtJgCaaUazdMf2/udG69bOuMhGcok7zV9NSDbyb 1VL5vO5uk4mpryGZOcH8yKDeHD+15gYsTnr+nEXINrkluHV0HvHEClCQNsK3rSzUzepU NVwMOiWRGCcKiKQBmSumEwCvnfY++tkhFFVUGlmzHztOyKz3z1awY7c0WYEv0ovhItSY V9ePDdbCFrxLQR4wIrrtyyLFPU0vmEJ7CiOQCm1WXV8CzJ2891nWXZQUxeSGFqr3kwTu wBXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119046; x=1726723846; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ybFbHFlG9EAgbyzyh2VZOYLseAu6WmHgRvomZ8hfETQ=; b=asEx6rzB9ZHARayB1F9rryi7WiAxmTE43GY7Bu/3jYRTSdABiEhIP4/Fu6niCqDaFz tY7CXO0MfuM4NIo32eYXKE6b7JGVaasa8XWbSJU7tG6VopXDWXuU732y9fIoScwMQFZ3 l+zyJHXE+QI8Uc0hSkIpgFUlbD0Z4AEbqwq+STpUhgd24UFLWpMOcAZdw6k5LulrQOa0 evWyseNm60KpfGU4jQXUvCFlReiXo4Zv+SSKRDufoKhTOY8yx+FtnN0C9ZcM+Lmey6zI tpXVGWA1ctv3Z13Q8NbpJ8YIbGhx4RrYf6xeWaQGMQDf+PEEyb8XLalLw2WAvPveMk82 fPqQ== X-Gm-Message-State: AOJu0Yxya1EwiORjFbEMvPJ3DTghcxHFR9sXWOxntGErcqOvc0iTKBJH BDt24By7E+tOozjDVNbZr7srVD2aGT1SSXcZcNMZvu4IMH9xbv3+My3Tzg== X-Google-Smtp-Source: AGHT+IGnN31jj3PDKdYaB9pws/W7Siam1J9sLDCDtougIWk/MDVQQFnpqS059wSdQKTd9MRgp2Fu7g== X-Received: by 2002:a05:6a21:2d89:b0:1cf:4596:d486 with SMTP id adf61e73a8af0-1cf762438b7mr1899495637.47.1726119045613; Wed, 11 Sep 2024 22:30:45 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Jason Chien , Alistair Francis Subject: [PULL 15/47] hw/riscv: add riscv-iommu-bits.h Date: Thu, 12 Sep 2024 15:29:20 +1000 Message-ID: <20240912052953.2552501-16-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UPPERCASE_50_75=0.008 autolearn=no 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 @gmail.com) X-ZM-MESSAGEID: 1726119651476116600 From: Tomasz Jeznach This header will be used by the RISC-V IOMMU emulation to be added in the next patch. Due to its size it's being sent in separate for an easier review. One thing to notice is that this header can be replaced by the future Linux RISC-V IOMMU driver header, which would become a linux-header we would import instead of keeping our own. The Linux implementation isn't upstream yet so for now we'll have to manage riscv-iommu-bits.h. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Reviewed-by: Jason Chien Reviewed-by: Alistair Francis Message-ID: <20240903201633.93182-3-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/riscv-iommu-bits.h | 345 ++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 hw/riscv/riscv-iommu-bits.h diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h new file mode 100644 index 0000000000..c46d7d18ab --- /dev/null +++ b/hw/riscv/riscv-iommu-bits.h @@ -0,0 +1,345 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright =C2=A9 2022-2023 Rivos Inc. + * Copyright =C2=A9 2023 FORTH-ICS/CARV + * Copyright =C2=A9 2023 RISC-V IOMMU Task Group + * + * RISC-V IOMMU - Register Layout and Data Structures. + * + * Based on the IOMMU spec version 1.0, 3/2023 + * https://github.com/riscv-non-isa/riscv-iommu + */ + +#ifndef HW_RISCV_IOMMU_BITS_H +#define HW_RISCV_IOMMU_BITS_H + +#define RISCV_IOMMU_SPEC_DOT_VER 0x010 + +#ifndef GENMASK_ULL +#define GENMASK_ULL(h, l) (((~0ULL) >> (63 - (h) + (l))) << (l)) +#endif + +/* + * struct riscv_iommu_fq_record - Fault/Event Queue Record + * See section 3.2 for more info. + */ +struct riscv_iommu_fq_record { + uint64_t hdr; + uint64_t _reserved; + uint64_t iotval; + uint64_t iotval2; +}; +/* Header fields */ +#define RISCV_IOMMU_FQ_HDR_CAUSE GENMASK_ULL(11, 0) +#define RISCV_IOMMU_FQ_HDR_PID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_FQ_HDR_PV BIT_ULL(32) +#define RISCV_IOMMU_FQ_HDR_TTYPE GENMASK_ULL(39, 34) +#define RISCV_IOMMU_FQ_HDR_DID GENMASK_ULL(63, 40) + +/* + * struct riscv_iommu_pq_record - PCIe Page Request record + * For more infos on the PCIe Page Request queue see chapter 3.3. + */ +struct riscv_iommu_pq_record { + uint64_t hdr; + uint64_t payload; +}; +/* Header fields */ +#define RISCV_IOMMU_PREQ_HDR_PID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_PREQ_HDR_PV BIT_ULL(32) +#define RISCV_IOMMU_PREQ_HDR_PRIV BIT_ULL(33) +#define RISCV_IOMMU_PREQ_HDR_EXEC BIT_ULL(34) +#define RISCV_IOMMU_PREQ_HDR_DID GENMASK_ULL(63, 40) +/* Payload fields */ +#define RISCV_IOMMU_PREQ_PAYLOAD_M GENMASK_ULL(2, 0) + +/* Common field positions */ +#define RISCV_IOMMU_PPN_FIELD GENMASK_ULL(53, 10) +#define RISCV_IOMMU_QUEUE_LOGSZ_FIELD GENMASK_ULL(4, 0) +#define RISCV_IOMMU_QUEUE_INDEX_FIELD GENMASK_ULL(31, 0) +#define RISCV_IOMMU_QUEUE_ENABLE BIT(0) +#define RISCV_IOMMU_QUEUE_INTR_ENABLE BIT(1) +#define RISCV_IOMMU_QUEUE_MEM_FAULT BIT(8) +#define RISCV_IOMMU_QUEUE_OVERFLOW BIT(9) +#define RISCV_IOMMU_QUEUE_ACTIVE BIT(16) +#define RISCV_IOMMU_QUEUE_BUSY BIT(17) +#define RISCV_IOMMU_ATP_PPN_FIELD GENMASK_ULL(43, 0) +#define RISCV_IOMMU_ATP_MODE_FIELD GENMASK_ULL(63, 60) + +/* 5.3 IOMMU Capabilities (64bits) */ +#define RISCV_IOMMU_REG_CAP 0x0000 +#define RISCV_IOMMU_CAP_VERSION GENMASK_ULL(7, 0) +#define RISCV_IOMMU_CAP_MSI_FLAT BIT_ULL(22) +#define RISCV_IOMMU_CAP_MSI_MRIF BIT_ULL(23) +#define RISCV_IOMMU_CAP_T2GPA BIT_ULL(26) +#define RISCV_IOMMU_CAP_IGS GENMASK_ULL(29, 28) +#define RISCV_IOMMU_CAP_PAS GENMASK_ULL(37, 32) +#define RISCV_IOMMU_CAP_PD8 BIT_ULL(38) +#define RISCV_IOMMU_CAP_PD17 BIT_ULL(39) +#define RISCV_IOMMU_CAP_PD20 BIT_ULL(40) + +/* 5.4 Features control register (32bits) */ +#define RISCV_IOMMU_REG_FCTL 0x0008 +#define RISCV_IOMMU_FCTL_WSI BIT(1) + +/* 5.5 Device-directory-table pointer (64bits) */ +#define RISCV_IOMMU_REG_DDTP 0x0010 +#define RISCV_IOMMU_DDTP_MODE GENMASK_ULL(3, 0) +#define RISCV_IOMMU_DDTP_BUSY BIT_ULL(4) +#define RISCV_IOMMU_DDTP_PPN RISCV_IOMMU_PPN_FIELD + +enum riscv_iommu_ddtp_modes { + RISCV_IOMMU_DDTP_MODE_OFF =3D 0, + RISCV_IOMMU_DDTP_MODE_BARE =3D 1, + RISCV_IOMMU_DDTP_MODE_1LVL =3D 2, + RISCV_IOMMU_DDTP_MODE_2LVL =3D 3, + RISCV_IOMMU_DDTP_MODE_3LVL =3D 4, + RISCV_IOMMU_DDTP_MODE_MAX =3D 4 +}; + +/* 5.6 Command Queue Base (64bits) */ +#define RISCV_IOMMU_REG_CQB 0x0018 +#define RISCV_IOMMU_CQB_LOG2SZ RISCV_IOMMU_QUEUE_LOGSZ_FIELD +#define RISCV_IOMMU_CQB_PPN RISCV_IOMMU_PPN_FIELD + +/* 5.7 Command Queue head (32bits) */ +#define RISCV_IOMMU_REG_CQH 0x0020 + +/* 5.8 Command Queue tail (32bits) */ +#define RISCV_IOMMU_REG_CQT 0x0024 + +/* 5.9 Fault Queue Base (64bits) */ +#define RISCV_IOMMU_REG_FQB 0x0028 +#define RISCV_IOMMU_FQB_LOG2SZ RISCV_IOMMU_QUEUE_LOGSZ_FIELD +#define RISCV_IOMMU_FQB_PPN RISCV_IOMMU_PPN_FIELD + +/* 5.10 Fault Queue Head (32bits) */ +#define RISCV_IOMMU_REG_FQH 0x0030 + +/* 5.11 Fault Queue tail (32bits) */ +#define RISCV_IOMMU_REG_FQT 0x0034 + +/* 5.12 Page Request Queue base (64bits) */ +#define RISCV_IOMMU_REG_PQB 0x0038 +#define RISCV_IOMMU_PQB_LOG2SZ RISCV_IOMMU_QUEUE_LOGSZ_FIELD +#define RISCV_IOMMU_PQB_PPN RISCV_IOMMU_PPN_FIELD + +/* 5.13 Page Request Queue head (32bits) */ +#define RISCV_IOMMU_REG_PQH 0x0040 + +/* 5.14 Page Request Queue tail (32bits) */ +#define RISCV_IOMMU_REG_PQT 0x0044 + +/* 5.15 Command Queue CSR (32bits) */ +#define RISCV_IOMMU_REG_CQCSR 0x0048 +#define RISCV_IOMMU_CQCSR_CQEN RISCV_IOMMU_QUEUE_ENABLE +#define RISCV_IOMMU_CQCSR_CIE RISCV_IOMMU_QUEUE_INTR_ENABLE +#define RISCV_IOMMU_CQCSR_CQMF RISCV_IOMMU_QUEUE_MEM_FAULT +#define RISCV_IOMMU_CQCSR_CMD_TO BIT(9) +#define RISCV_IOMMU_CQCSR_CMD_ILL BIT(10) +#define RISCV_IOMMU_CQCSR_FENCE_W_IP BIT(11) +#define RISCV_IOMMU_CQCSR_CQON RISCV_IOMMU_QUEUE_ACTIVE +#define RISCV_IOMMU_CQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY + +/* 5.16 Fault Queue CSR (32bits) */ +#define RISCV_IOMMU_REG_FQCSR 0x004C +#define RISCV_IOMMU_FQCSR_FQEN RISCV_IOMMU_QUEUE_ENABLE +#define RISCV_IOMMU_FQCSR_FIE RISCV_IOMMU_QUEUE_INTR_ENABLE +#define RISCV_IOMMU_FQCSR_FQMF RISCV_IOMMU_QUEUE_MEM_FAULT +#define RISCV_IOMMU_FQCSR_FQOF RISCV_IOMMU_QUEUE_OVERFLOW +#define RISCV_IOMMU_FQCSR_FQON RISCV_IOMMU_QUEUE_ACTIVE +#define RISCV_IOMMU_FQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY + +/* 5.17 Page Request Queue CSR (32bits) */ +#define RISCV_IOMMU_REG_PQCSR 0x0050 +#define RISCV_IOMMU_PQCSR_PQEN RISCV_IOMMU_QUEUE_ENABLE +#define RISCV_IOMMU_PQCSR_PIE RISCV_IOMMU_QUEUE_INTR_ENABLE +#define RISCV_IOMMU_PQCSR_PQMF RISCV_IOMMU_QUEUE_MEM_FAULT +#define RISCV_IOMMU_PQCSR_PQOF RISCV_IOMMU_QUEUE_OVERFLOW +#define RISCV_IOMMU_PQCSR_PQON RISCV_IOMMU_QUEUE_ACTIVE +#define RISCV_IOMMU_PQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY + +/* 5.18 Interrupt Pending Status (32bits) */ +#define RISCV_IOMMU_REG_IPSR 0x0054 +#define RISCV_IOMMU_IPSR_CIP BIT(0) +#define RISCV_IOMMU_IPSR_FIP BIT(1) +#define RISCV_IOMMU_IPSR_PIP BIT(3) + +enum { + RISCV_IOMMU_INTR_CQ, + RISCV_IOMMU_INTR_FQ, + RISCV_IOMMU_INTR_PM, + RISCV_IOMMU_INTR_PQ, + RISCV_IOMMU_INTR_COUNT +}; + +/* 5.27 Interrupt cause to vector (64bits) */ +#define RISCV_IOMMU_REG_ICVEC 0x02F8 + +/* 5.28 MSI Configuration table (32 * 64bits) */ +#define RISCV_IOMMU_REG_MSI_CONFIG 0x0300 + +#define RISCV_IOMMU_REG_SIZE 0x1000 + +#define RISCV_IOMMU_DDTE_VALID BIT_ULL(0) +#define RISCV_IOMMU_DDTE_PPN RISCV_IOMMU_PPN_FIELD + +/* Struct riscv_iommu_dc - Device Context - section 2.1 */ +struct riscv_iommu_dc { + uint64_t tc; + uint64_t iohgatp; + uint64_t ta; + uint64_t fsc; + uint64_t msiptp; + uint64_t msi_addr_mask; + uint64_t msi_addr_pattern; + uint64_t _reserved; +}; + +/* Translation control fields */ +#define RISCV_IOMMU_DC_TC_V BIT_ULL(0) +#define RISCV_IOMMU_DC_TC_EN_PRI BIT_ULL(2) +#define RISCV_IOMMU_DC_TC_T2GPA BIT_ULL(3) +#define RISCV_IOMMU_DC_TC_DTF BIT_ULL(4) +#define RISCV_IOMMU_DC_TC_PDTV BIT_ULL(5) +#define RISCV_IOMMU_DC_TC_PRPR BIT_ULL(6) +#define RISCV_IOMMU_DC_TC_DPE BIT_ULL(9) +#define RISCV_IOMMU_DC_TC_SBE BIT_ULL(10) +#define RISCV_IOMMU_DC_TC_SXL BIT_ULL(11) + +/* Second-stage (aka G-stage) context fields */ +#define RISCV_IOMMU_DC_IOHGATP_PPN RISCV_IOMMU_ATP_PPN_FIELD +#define RISCV_IOMMU_DC_IOHGATP_GSCID GENMASK_ULL(59, 44) +#define RISCV_IOMMU_DC_IOHGATP_MODE RISCV_IOMMU_ATP_MODE_FIELD + +enum riscv_iommu_dc_iohgatp_modes { + RISCV_IOMMU_DC_IOHGATP_MODE_BARE =3D 0, + RISCV_IOMMU_DC_IOHGATP_MODE_SV32X4 =3D 8, + RISCV_IOMMU_DC_IOHGATP_MODE_SV39X4 =3D 8, + RISCV_IOMMU_DC_IOHGATP_MODE_SV48X4 =3D 9, + RISCV_IOMMU_DC_IOHGATP_MODE_SV57X4 =3D 10 +}; + +/* Translation attributes fields */ +#define RISCV_IOMMU_DC_TA_PSCID GENMASK_ULL(31, 12) + +/* First-stage context fields */ +#define RISCV_IOMMU_DC_FSC_PPN RISCV_IOMMU_ATP_PPN_FIELD +#define RISCV_IOMMU_DC_FSC_MODE RISCV_IOMMU_ATP_MODE_FIELD + +/* Generic I/O MMU command structure - check section 3.1 */ +struct riscv_iommu_command { + uint64_t dword0; + uint64_t dword1; +}; + +#define RISCV_IOMMU_CMD_OPCODE GENMASK_ULL(6, 0) +#define RISCV_IOMMU_CMD_FUNC GENMASK_ULL(9, 7) + +#define RISCV_IOMMU_CMD_IOTINVAL_OPCODE 1 +#define RISCV_IOMMU_CMD_IOTINVAL_FUNC_VMA 0 +#define RISCV_IOMMU_CMD_IOTINVAL_FUNC_GVMA 1 +#define RISCV_IOMMU_CMD_IOTINVAL_AV BIT_ULL(10) +#define RISCV_IOMMU_CMD_IOTINVAL_PSCID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_CMD_IOTINVAL_PSCV BIT_ULL(32) +#define RISCV_IOMMU_CMD_IOTINVAL_GV BIT_ULL(33) +#define RISCV_IOMMU_CMD_IOTINVAL_GSCID GENMASK_ULL(59, 44) + +#define RISCV_IOMMU_CMD_IOFENCE_OPCODE 2 +#define RISCV_IOMMU_CMD_IOFENCE_FUNC_C 0 +#define RISCV_IOMMU_CMD_IOFENCE_AV BIT_ULL(10) +#define RISCV_IOMMU_CMD_IOFENCE_DATA GENMASK_ULL(63, 32) + +#define RISCV_IOMMU_CMD_IODIR_OPCODE 3 +#define RISCV_IOMMU_CMD_IODIR_FUNC_INVAL_DDT 0 +#define RISCV_IOMMU_CMD_IODIR_FUNC_INVAL_PDT 1 +#define RISCV_IOMMU_CMD_IODIR_PID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_CMD_IODIR_DV BIT_ULL(33) +#define RISCV_IOMMU_CMD_IODIR_DID GENMASK_ULL(63, 40) + +enum riscv_iommu_dc_fsc_atp_modes { + RISCV_IOMMU_DC_FSC_MODE_BARE =3D 0, + RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV32 =3D 8, + RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV39 =3D 8, + RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV48 =3D 9, + RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV57 =3D 10, + RISCV_IOMMU_DC_FSC_PDTP_MODE_PD8 =3D 1, + RISCV_IOMMU_DC_FSC_PDTP_MODE_PD17 =3D 2, + RISCV_IOMMU_DC_FSC_PDTP_MODE_PD20 =3D 3 +}; + +enum riscv_iommu_fq_causes { + RISCV_IOMMU_FQ_CAUSE_INST_FAULT =3D 1, + RISCV_IOMMU_FQ_CAUSE_RD_ADDR_MISALIGNED =3D 4, + RISCV_IOMMU_FQ_CAUSE_RD_FAULT =3D 5, + RISCV_IOMMU_FQ_CAUSE_WR_ADDR_MISALIGNED =3D 6, + RISCV_IOMMU_FQ_CAUSE_WR_FAULT =3D 7, + RISCV_IOMMU_FQ_CAUSE_INST_FAULT_S =3D 12, + RISCV_IOMMU_FQ_CAUSE_RD_FAULT_S =3D 13, + RISCV_IOMMU_FQ_CAUSE_WR_FAULT_S =3D 15, + RISCV_IOMMU_FQ_CAUSE_INST_FAULT_VS =3D 20, + RISCV_IOMMU_FQ_CAUSE_RD_FAULT_VS =3D 21, + RISCV_IOMMU_FQ_CAUSE_WR_FAULT_VS =3D 23, + RISCV_IOMMU_FQ_CAUSE_DMA_DISABLED =3D 256, + RISCV_IOMMU_FQ_CAUSE_DDT_LOAD_FAULT =3D 257, + RISCV_IOMMU_FQ_CAUSE_DDT_INVALID =3D 258, + RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED =3D 259, + RISCV_IOMMU_FQ_CAUSE_TTYPE_BLOCKED =3D 260, + RISCV_IOMMU_FQ_CAUSE_MSI_LOAD_FAULT =3D 261, + RISCV_IOMMU_FQ_CAUSE_MSI_INVALID =3D 262, + RISCV_IOMMU_FQ_CAUSE_MSI_MISCONFIGURED =3D 263, + RISCV_IOMMU_FQ_CAUSE_MRIF_FAULT =3D 264, + RISCV_IOMMU_FQ_CAUSE_PDT_LOAD_FAULT =3D 265, + RISCV_IOMMU_FQ_CAUSE_PDT_INVALID =3D 266, + RISCV_IOMMU_FQ_CAUSE_PDT_MISCONFIGURED =3D 267, + RISCV_IOMMU_FQ_CAUSE_DDT_CORRUPTED =3D 268, + RISCV_IOMMU_FQ_CAUSE_PDT_CORRUPTED =3D 269, + RISCV_IOMMU_FQ_CAUSE_MSI_PT_CORRUPTED =3D 270, + RISCV_IOMMU_FQ_CAUSE_MRIF_CORRUIPTED =3D 271, + RISCV_IOMMU_FQ_CAUSE_INTERNAL_DP_ERROR =3D 272, + RISCV_IOMMU_FQ_CAUSE_MSI_WR_FAULT =3D 273, + RISCV_IOMMU_FQ_CAUSE_PT_CORRUPTED =3D 274 +}; + +/* MSI page table pointer */ +#define RISCV_IOMMU_DC_MSIPTP_PPN RISCV_IOMMU_ATP_PPN_FIELD +#define RISCV_IOMMU_DC_MSIPTP_MODE RISCV_IOMMU_ATP_MODE_FIELD +#define RISCV_IOMMU_DC_MSIPTP_MODE_OFF 0 +#define RISCV_IOMMU_DC_MSIPTP_MODE_FLAT 1 + +/* Translation attributes fields */ +#define RISCV_IOMMU_PC_TA_V BIT_ULL(0) + +/* First stage context fields */ +#define RISCV_IOMMU_PC_FSC_PPN GENMASK_ULL(43, 0) + +enum riscv_iommu_fq_ttypes { + RISCV_IOMMU_FQ_TTYPE_NONE =3D 0, + RISCV_IOMMU_FQ_TTYPE_UADDR_INST_FETCH =3D 1, + RISCV_IOMMU_FQ_TTYPE_UADDR_RD =3D 2, + RISCV_IOMMU_FQ_TTYPE_UADDR_WR =3D 3, + RISCV_IOMMU_FQ_TTYPE_TADDR_INST_FETCH =3D 5, + RISCV_IOMMU_FQ_TTYPE_TADDR_RD =3D 6, + RISCV_IOMMU_FQ_TTYPE_TADDR_WR =3D 7, + RISCV_IOMMU_FW_TTYPE_PCIE_MSG_REQ =3D 8, +}; + +/* Fields on pte */ +#define RISCV_IOMMU_MSI_PTE_V BIT_ULL(0) +#define RISCV_IOMMU_MSI_PTE_M GENMASK_ULL(2, 1) + +#define RISCV_IOMMU_MSI_PTE_M_MRIF 1 +#define RISCV_IOMMU_MSI_PTE_M_BASIC 3 + +/* When M =3D=3D 1 (MRIF mode) */ +#define RISCV_IOMMU_MSI_PTE_MRIF_ADDR GENMASK_ULL(53, 7) +/* When M =3D=3D 3 (basic mode) */ +#define RISCV_IOMMU_MSI_PTE_PPN RISCV_IOMMU_PPN_FIELD +#define RISCV_IOMMU_MSI_PTE_C BIT_ULL(63) + +/* Fields on mrif_info */ +#define RISCV_IOMMU_MSI_MRIF_NID GENMASK_ULL(9, 0) +#define RISCV_IOMMU_MSI_MRIF_NPPN RISCV_IOMMU_PPN_FIELD +#define RISCV_IOMMU_MSI_MRIF_NID_MSB BIT_ULL(60) + +#endif /* _RISCV_IOMMU_BITS_H_ */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119173; cv=none; d=zohomail.com; s=zohoarc; b=m70J5572WEdeZJc1KV33GAEcXL68q0NTRSxXfjcBgWbUrCckuWfDoq7494EzRlyAB0X4G/dM/Aow9LVqIh6ur8vDZC+iFSSfTVOr2xlVAjXxsQPI1q5z5NTY4kN6Sb2bDBmjuCd6MUiG6Fmdfwa9AonNRGpsuVGM6QN61AZybuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119173; h=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=skItlq9UBsMMY0oCH1VuQgFcMNparoCFi/zxR9Rp2lw=; b=h3vRF1/AlkxVO+7TBcAo30K0gThilLUoS+z0j9AURSvRozk/7WVAQDOU3xd0VejGfjc742W/eYc+z4ySVgPgi4Z/yFi7N2/mIxl0she+IJkclnrA/DgZncv6ZMau+eCEmceitA6f92Th4UpeG7mqHUOuqGwkN/O5QtfWfwuJZmE= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172611917310560.54796777130127; Wed, 11 Sep 2024 22:32:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socPz-0002RZ-9K; Thu, 12 Sep 2024 01:30:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPx-0002Is-1k for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:57 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPr-00032v-SC for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:56 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-718e3c98b5aso352322b3a.0 for ; Wed, 11 Sep 2024 22:30:51 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119050; x=1726723850; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=skItlq9UBsMMY0oCH1VuQgFcMNparoCFi/zxR9Rp2lw=; b=PCgdkj1S2WRV/9TcgVIApSDNsIAGXIwPIgFKhPKI44YicGZBM+LmCWaBOL1A3Rbi+G HxaHvJo0mwhM26i5713AEcUF/hFUN0l7tYUj0LBzyROiSbXXxtbrSX0gc0fDqTalLfPs yly5S/tB6+KIPqBoP4+whz/ImSisTfiNtRRoCb2ON8dOwEzeL/FyLMyKrGf1twOH7SGQ kDVwjnWKlF//OZpVPxJtZO3FCAujgxCCLqLfj3QfFBVNQe5x9sUyAkvENoTeKggspQ9l sCgSlGKsuPLcRHEB2VfBpksKWM7PGaLTV+8Nwkvaxv4w0V1yMGsLtDPQsCSQYnU3Q3NF 1Fmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119050; x=1726723850; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=skItlq9UBsMMY0oCH1VuQgFcMNparoCFi/zxR9Rp2lw=; b=SAJOUI+WcPWDUGD5LTsG3D1Of3R8bx+kKQRq68WWxLUwjm5eeHNGGHqY8ntBFwCWLC XWj5IsWSLuyUi2y8ktV0VXqY/besf7owNcPs9SpYzdVsJ7PTUzt7Zb0X6lK2XEtW01sr rkfxoTT4Z2WDb5GCTA3lXVwKfOv+b//G0OluohwP3oown7HoFHlHsm/Yq/yvbjZ+3MFw q+59ki9pvTyTVhHo3S4MCWlz/P04XyZTeEwglQQWdT2rQaTagXf6/LoZCCEYUzgvdyw6 nOVkOlbhmmPUycnNE5EY1a0X6bK6IOycrZOhaAjBIL+hQVBaNEjKrVC3b+nOfSj1i4Uq ZGlQ== X-Gm-Message-State: AOJu0YzxslzGjTNnWUxLMRk8sEScYsYGlTJa2R4ydZRgcrKGIAOErzwT 73ONdU15wsjJ7yOO62FTzCaefj0C29Kf7OGTcE5k4s32j+P1aUuAn5s/xQ== X-Google-Smtp-Source: AGHT+IFPjrQJ3Sv4U0zEIf5/hqh+qWdTaSVQa7WNa5VzUCAkjMfH1PCP6+8Prgket0gY/sUuf6k73g== X-Received: by 2002:a05:6a00:10c5:b0:706:3329:5533 with SMTP id d2e1a72fcca58-719261ee946mr2750857b3a.24.1726119049322; Wed, 11 Sep 2024 22:30:49 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Sebastien Boeuf , Daniel Henrique Barboza , Alistair Francis Subject: [PULL 16/47] hw/riscv: add RISC-V IOMMU base emulation Date: Thu, 12 Sep 2024 15:29:21 +1000 Message-ID: <20240912052953.2552501-17-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=alistair23@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119174637116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach The RISC-V IOMMU specification is now ratified as-per the RISC-V international process. The latest frozen specifcation can be found at: https://github.com/riscv-non-isa/riscv-iommu/releases/download/v1.0/riscv-i= ommu.pdf Add the foundation of the device emulation for RISC-V IOMMU. It includes support for s-stage (sv32, sv39, sv48, sv57 caps) and g-stage (sv32x4, sv39x4, sv48x4, sv57x4 caps). Other capabilities like ATS and DBG support will be added incrementally in the next patches. Co-developed-by: Sebastien Boeuf Signed-off-by: Sebastien Boeuf Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis Message-ID: <20240903201633.93182-4-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- meson.build | 1 + hw/riscv/riscv-iommu-bits.h | 18 + hw/riscv/riscv-iommu.h | 145 +++ hw/riscv/trace.h | 1 + include/hw/riscv/iommu.h | 36 + hw/riscv/riscv-iommu.c | 2050 +++++++++++++++++++++++++++++++++++ hw/riscv/Kconfig | 4 + hw/riscv/meson.build | 1 + hw/riscv/trace-events | 14 + 9 files changed, 2270 insertions(+) create mode 100644 hw/riscv/riscv-iommu.h create mode 100644 hw/riscv/trace.h create mode 100644 include/hw/riscv/iommu.h create mode 100644 hw/riscv/riscv-iommu.c create mode 100644 hw/riscv/trace-events diff --git a/meson.build b/meson.build index b89b713e79..a90855f59a 100644 --- a/meson.build +++ b/meson.build @@ -3425,6 +3425,7 @@ if have_system 'hw/pci-host', 'hw/ppc', 'hw/rtc', + 'hw/riscv', 'hw/s390x', 'hw/scsi', 'hw/sd', diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h index c46d7d18ab..b1c477f5c3 100644 --- a/hw/riscv/riscv-iommu-bits.h +++ b/hw/riscv/riscv-iommu-bits.h @@ -69,6 +69,14 @@ struct riscv_iommu_pq_record { /* 5.3 IOMMU Capabilities (64bits) */ #define RISCV_IOMMU_REG_CAP 0x0000 #define RISCV_IOMMU_CAP_VERSION GENMASK_ULL(7, 0) +#define RISCV_IOMMU_CAP_SV32 BIT_ULL(8) +#define RISCV_IOMMU_CAP_SV39 BIT_ULL(9) +#define RISCV_IOMMU_CAP_SV48 BIT_ULL(10) +#define RISCV_IOMMU_CAP_SV57 BIT_ULL(11) +#define RISCV_IOMMU_CAP_SV32X4 BIT_ULL(16) +#define RISCV_IOMMU_CAP_SV39X4 BIT_ULL(17) +#define RISCV_IOMMU_CAP_SV48X4 BIT_ULL(18) +#define RISCV_IOMMU_CAP_SV57X4 BIT_ULL(19) #define RISCV_IOMMU_CAP_MSI_FLAT BIT_ULL(22) #define RISCV_IOMMU_CAP_MSI_MRIF BIT_ULL(23) #define RISCV_IOMMU_CAP_T2GPA BIT_ULL(26) @@ -80,7 +88,9 @@ struct riscv_iommu_pq_record { =20 /* 5.4 Features control register (32bits) */ #define RISCV_IOMMU_REG_FCTL 0x0008 +#define RISCV_IOMMU_FCTL_BE BIT(0) #define RISCV_IOMMU_FCTL_WSI BIT(1) +#define RISCV_IOMMU_FCTL_GXL BIT(2) =20 /* 5.5 Device-directory-table pointer (64bits) */ #define RISCV_IOMMU_REG_DDTP 0x0010 @@ -175,6 +185,10 @@ enum { =20 /* 5.27 Interrupt cause to vector (64bits) */ #define RISCV_IOMMU_REG_ICVEC 0x02F8 +#define RISCV_IOMMU_ICVEC_CIV GENMASK_ULL(3, 0) +#define RISCV_IOMMU_ICVEC_FIV GENMASK_ULL(7, 4) +#define RISCV_IOMMU_ICVEC_PMIV GENMASK_ULL(11, 8) +#define RISCV_IOMMU_ICVEC_PIV GENMASK_ULL(15, 12) =20 /* 5.28 MSI Configuration table (32 * 64bits) */ #define RISCV_IOMMU_REG_MSI_CONFIG 0x0300 @@ -203,6 +217,8 @@ struct riscv_iommu_dc { #define RISCV_IOMMU_DC_TC_DTF BIT_ULL(4) #define RISCV_IOMMU_DC_TC_PDTV BIT_ULL(5) #define RISCV_IOMMU_DC_TC_PRPR BIT_ULL(6) +#define RISCV_IOMMU_DC_TC_GADE BIT_ULL(7) +#define RISCV_IOMMU_DC_TC_SADE BIT_ULL(8) #define RISCV_IOMMU_DC_TC_DPE BIT_ULL(9) #define RISCV_IOMMU_DC_TC_SBE BIT_ULL(10) #define RISCV_IOMMU_DC_TC_SXL BIT_ULL(11) @@ -309,9 +325,11 @@ enum riscv_iommu_fq_causes { =20 /* Translation attributes fields */ #define RISCV_IOMMU_PC_TA_V BIT_ULL(0) +#define RISCV_IOMMU_PC_TA_RESERVED GENMASK_ULL(63, 32) =20 /* First stage context fields */ #define RISCV_IOMMU_PC_FSC_PPN GENMASK_ULL(43, 0) +#define RISCV_IOMMU_PC_FSC_RESERVED GENMASK_ULL(59, 44) =20 enum riscv_iommu_fq_ttypes { RISCV_IOMMU_FQ_TTYPE_NONE =3D 0, diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h new file mode 100644 index 0000000000..95b4ce8d50 --- /dev/null +++ b/hw/riscv/riscv-iommu.h @@ -0,0 +1,145 @@ +/* + * QEMU emulation of an RISC-V IOMMU + * + * Copyright (C) 2022-2023 Rivos Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef HW_RISCV_IOMMU_STATE_H +#define HW_RISCV_IOMMU_STATE_H + +#include "qemu/osdep.h" +#include "qom/object.h" + +#include "hw/riscv/iommu.h" + +struct RISCVIOMMUState { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + uint32_t version; /* Reported interface version number */ + uint32_t pid_bits; /* process identifier width */ + uint32_t bus; /* PCI bus mapping for non-root endpoints */ + + uint64_t cap; /* IOMMU supported capabilities */ + uint64_t fctl; /* IOMMU enabled features */ + uint64_t icvec_avail_vectors; /* Available interrupt vectors in ICVEC= */ + + bool enable_off; /* Enable out-of-reset OFF mode (DMA disabled) */ + bool enable_msi; /* Enable MSI remapping */ + bool enable_s_stage; /* Enable S/VS-Stage translation */ + bool enable_g_stage; /* Enable G-Stage translation */ + + /* IOMMU Internal State */ + uint64_t ddtp; /* Validated Device Directory Tree Root Pointer = */ + + dma_addr_t cq_addr; /* Command queue base physical address */ + dma_addr_t fq_addr; /* Fault/event queue base physical address */ + dma_addr_t pq_addr; /* Page request queue base physical address */ + + uint32_t cq_mask; /* Command queue index bit mask */ + uint32_t fq_mask; /* Fault/event queue index bit mask */ + uint32_t pq_mask; /* Page request queue index bit mask */ + + /* interrupt notifier */ + void (*notify)(RISCVIOMMUState *iommu, unsigned vector); + + /* IOMMU State Machine */ + QemuThread core_proc; /* Background processing thread */ + QemuMutex core_lock; /* Global IOMMU lock, used for cache/regs update= s */ + QemuCond core_cond; /* Background processing wake up signal */ + unsigned core_exec; /* Processing thread execution actions */ + + /* IOMMU target address space */ + AddressSpace *target_as; + MemoryRegion *target_mr; + + /* MSI / MRIF access trap */ + AddressSpace trap_as; + MemoryRegion trap_mr; + + GHashTable *ctx_cache; /* Device translation Context Cache */ + QemuMutex ctx_lock; /* Device translation Cache update lock */ + + /* MMIO Hardware Interface */ + MemoryRegion regs_mr; + QemuSpin regs_lock; + uint8_t *regs_rw; /* register state (user write) */ + uint8_t *regs_wc; /* write-1-to-clear mask */ + uint8_t *regs_ro; /* read-only mask */ + + QLIST_ENTRY(RISCVIOMMUState) iommus; + QLIST_HEAD(, RISCVIOMMUSpace) spaces; +}; + +void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, + Error **errp); + +/* private helpers */ + +/* Register helper functions */ +static inline uint32_t riscv_iommu_reg_mod32(RISCVIOMMUState *s, + unsigned idx, uint32_t set, uint32_t clr) +{ + uint32_t val; + qemu_spin_lock(&s->regs_lock); + val =3D ldl_le_p(s->regs_rw + idx); + stl_le_p(s->regs_rw + idx, (val & ~clr) | set); + qemu_spin_unlock(&s->regs_lock); + return val; +} + +static inline void riscv_iommu_reg_set32(RISCVIOMMUState *s, + unsigned idx, uint32_t set) +{ + qemu_spin_lock(&s->regs_lock); + stl_le_p(s->regs_rw + idx, set); + qemu_spin_unlock(&s->regs_lock); +} + +static inline uint32_t riscv_iommu_reg_get32(RISCVIOMMUState *s, + unsigned idx) +{ + return ldl_le_p(s->regs_rw + idx); +} + +static inline uint64_t riscv_iommu_reg_mod64(RISCVIOMMUState *s, + unsigned idx, uint64_t set, uint64_t clr) +{ + uint64_t val; + qemu_spin_lock(&s->regs_lock); + val =3D ldq_le_p(s->regs_rw + idx); + stq_le_p(s->regs_rw + idx, (val & ~clr) | set); + qemu_spin_unlock(&s->regs_lock); + return val; +} + +static inline void riscv_iommu_reg_set64(RISCVIOMMUState *s, + unsigned idx, uint64_t set) +{ + qemu_spin_lock(&s->regs_lock); + stq_le_p(s->regs_rw + idx, set); + qemu_spin_unlock(&s->regs_lock); +} + +static inline uint64_t riscv_iommu_reg_get64(RISCVIOMMUState *s, + unsigned idx) +{ + return ldq_le_p(s->regs_rw + idx); +} + + + +#endif diff --git a/hw/riscv/trace.h b/hw/riscv/trace.h new file mode 100644 index 0000000000..8c0e3ca1f3 --- /dev/null +++ b/hw/riscv/trace.h @@ -0,0 +1 @@ +#include "trace/trace-hw_riscv.h" diff --git a/include/hw/riscv/iommu.h b/include/hw/riscv/iommu.h new file mode 100644 index 0000000000..070ee69973 --- /dev/null +++ b/include/hw/riscv/iommu.h @@ -0,0 +1,36 @@ +/* + * QEMU emulation of an RISC-V IOMMU + * + * Copyright (C) 2022-2023 Rivos Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef HW_RISCV_IOMMU_H +#define HW_RISCV_IOMMU_H + +#include "qemu/osdep.h" +#include "qom/object.h" + +#define TYPE_RISCV_IOMMU "riscv-iommu" +OBJECT_DECLARE_SIMPLE_TYPE(RISCVIOMMUState, RISCV_IOMMU) +typedef struct RISCVIOMMUState RISCVIOMMUState; + +#define TYPE_RISCV_IOMMU_MEMORY_REGION "riscv-iommu-mr" +typedef struct RISCVIOMMUSpace RISCVIOMMUSpace; + +#define TYPE_RISCV_IOMMU_PCI "riscv-iommu-pci" +OBJECT_DECLARE_SIMPLE_TYPE(RISCVIOMMUStatePci, RISCV_IOMMU_PCI) +typedef struct RISCVIOMMUStatePci RISCVIOMMUStatePci; + +#endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c new file mode 100644 index 0000000000..061a5efe19 --- /dev/null +++ b/hw/riscv/riscv-iommu.c @@ -0,0 +1,2050 @@ +/* + * QEMU emulation of an RISC-V IOMMU + * + * Copyright (C) 2021-2023, Rivos Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci_device.h" +#include "hw/qdev-properties.h" +#include "hw/riscv/riscv_hart.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/timer.h" + +#include "cpu_bits.h" +#include "riscv-iommu.h" +#include "riscv-iommu-bits.h" +#include "trace.h" + +#define LIMIT_CACHE_CTX (1U << 7) +#define LIMIT_CACHE_IOT (1U << 20) + +/* Physical page number coversions */ +#define PPN_PHYS(ppn) ((ppn) << TARGET_PAGE_BITS) +#define PPN_DOWN(phy) ((phy) >> TARGET_PAGE_BITS) + +typedef struct RISCVIOMMUContext RISCVIOMMUContext; +typedef struct RISCVIOMMUEntry RISCVIOMMUEntry; + +/* Device assigned I/O address space */ +struct RISCVIOMMUSpace { + IOMMUMemoryRegion iova_mr; /* IOVA memory region for attached device = */ + AddressSpace iova_as; /* IOVA address space for attached device = */ + RISCVIOMMUState *iommu; /* Managing IOMMU device state */ + uint32_t devid; /* Requester identifier, AKA device_id */ + bool notifier; /* IOMMU unmap notifier enabled */ + QLIST_ENTRY(RISCVIOMMUSpace) list; +}; + +/* Device translation context state. */ +struct RISCVIOMMUContext { + uint64_t devid:24; /* Requester Id, AKA device_id */ + uint64_t process_id:20; /* Process ID. PASID for PCIe */ + uint64_t __rfu:20; /* reserved */ + uint64_t tc; /* Translation Control */ + uint64_t ta; /* Translation Attributes */ + uint64_t satp; /* S-Stage address translation and protect= ion */ + uint64_t gatp; /* G-Stage address translation and protect= ion */ + uint64_t msi_addr_mask; /* MSI filtering - address mask */ + uint64_t msi_addr_pattern; /* MSI filtering - address pattern */ + uint64_t msiptp; /* MSI redirection page table pointer */ +}; + +/* IOMMU index for transactions without process_id specified. */ +#define RISCV_IOMMU_NOPROCID 0 + +static uint8_t riscv_iommu_get_icvec_vector(uint32_t icvec, uint32_t vec_t= ype) +{ + switch (vec_type) { + case RISCV_IOMMU_INTR_CQ: + return icvec & RISCV_IOMMU_ICVEC_CIV; + case RISCV_IOMMU_INTR_FQ: + return icvec & RISCV_IOMMU_ICVEC_FIV >> 4; + case RISCV_IOMMU_INTR_PM: + return icvec & RISCV_IOMMU_ICVEC_PMIV >> 8; + case RISCV_IOMMU_INTR_PQ: + return icvec & RISCV_IOMMU_ICVEC_PIV >> 12; + default: + g_assert_not_reached(); + } +} + +static void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type) +{ + const uint32_t fctl =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FCTL); + uint32_t ipsr, icvec, vector; + + if (fctl & RISCV_IOMMU_FCTL_WSI || !s->notify) { + return; + } + + icvec =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_ICVEC); + ipsr =3D riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IPSR, (1 << vec_type= ), 0); + + if (!(ipsr & (1 << vec_type))) { + vector =3D riscv_iommu_get_icvec_vector(icvec, vec_type); + s->notify(s, vector); + trace_riscv_iommu_notify_int_vector(vec_type, vector); + } +} + +static void riscv_iommu_fault(RISCVIOMMUState *s, + struct riscv_iommu_fq_record *ev) +{ + uint32_t ctrl =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FQCSR); + uint32_t head =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FQH) & s->f= q_mask; + uint32_t tail =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FQT) & s->f= q_mask; + uint32_t next =3D (tail + 1) & s->fq_mask; + uint32_t devid =3D get_field(ev->hdr, RISCV_IOMMU_FQ_HDR_DID); + + trace_riscv_iommu_flt(s->parent_obj.id, PCI_BUS_NUM(devid), PCI_SLOT(d= evid), + PCI_FUNC(devid), ev->hdr, ev->iotval); + + if (!(ctrl & RISCV_IOMMU_FQCSR_FQON) || + !!(ctrl & (RISCV_IOMMU_FQCSR_FQOF | RISCV_IOMMU_FQCSR_FQMF))) { + return; + } + + if (head =3D=3D next) { + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_FQCSR, + RISCV_IOMMU_FQCSR_FQOF, 0); + } else { + dma_addr_t addr =3D s->fq_addr + tail * sizeof(*ev); + if (dma_memory_write(s->target_as, addr, ev, sizeof(*ev), + MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_FQCSR, + RISCV_IOMMU_FQCSR_FQMF, 0); + } else { + riscv_iommu_reg_set32(s, RISCV_IOMMU_REG_FQT, next); + } + } + + if (ctrl & RISCV_IOMMU_FQCSR_FIE) { + riscv_iommu_notify(s, RISCV_IOMMU_INTR_FQ); + } +} + +static void riscv_iommu_pri(RISCVIOMMUState *s, + struct riscv_iommu_pq_record *pr) +{ + uint32_t ctrl =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_PQCSR); + uint32_t head =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_PQH) & s->p= q_mask; + uint32_t tail =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_PQT) & s->p= q_mask; + uint32_t next =3D (tail + 1) & s->pq_mask; + uint32_t devid =3D get_field(pr->hdr, RISCV_IOMMU_PREQ_HDR_DID); + + trace_riscv_iommu_pri(s->parent_obj.id, PCI_BUS_NUM(devid), PCI_SLOT(d= evid), + PCI_FUNC(devid), pr->payload); + + if (!(ctrl & RISCV_IOMMU_PQCSR_PQON) || + !!(ctrl & (RISCV_IOMMU_PQCSR_PQOF | RISCV_IOMMU_PQCSR_PQMF))) { + return; + } + + if (head =3D=3D next) { + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_PQCSR, + RISCV_IOMMU_PQCSR_PQOF, 0); + } else { + dma_addr_t addr =3D s->pq_addr + tail * sizeof(*pr); + if (dma_memory_write(s->target_as, addr, pr, sizeof(*pr), + MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_PQCSR, + RISCV_IOMMU_PQCSR_PQMF, 0); + } else { + riscv_iommu_reg_set32(s, RISCV_IOMMU_REG_PQT, next); + } + } + + if (ctrl & RISCV_IOMMU_PQCSR_PIE) { + riscv_iommu_notify(s, RISCV_IOMMU_INTR_PQ); + } +} + +/* Portable implementation of pext_u64, bit-mask extraction. */ +static uint64_t _pext_u64(uint64_t val, uint64_t ext) +{ + uint64_t ret =3D 0; + uint64_t rot =3D 1; + + while (ext) { + if (ext & 1) { + if (val & 1) { + ret |=3D rot; + } + rot <<=3D 1; + } + val >>=3D 1; + ext >>=3D 1; + } + + return ret; +} + +/* Check if GPA matches MSI/MRIF pattern. */ +static bool riscv_iommu_msi_check(RISCVIOMMUState *s, RISCVIOMMUContext *c= tx, + dma_addr_t gpa) +{ + if (!s->enable_msi) { + return false; + } + + if (get_field(ctx->msiptp, RISCV_IOMMU_DC_MSIPTP_MODE) !=3D + RISCV_IOMMU_DC_MSIPTP_MODE_FLAT) { + return false; /* Invalid MSI/MRIF mode */ + } + + if ((PPN_DOWN(gpa) ^ ctx->msi_addr_pattern) & ~ctx->msi_addr_mask) { + return false; /* GPA not in MSI range defined by AIA IMSIC rules. = */ + } + + return true; +} + +/* + * RISCV IOMMU Address Translation Lookup - Page Table Walk + * + * Note: Code is based on get_physical_address() from target/riscv/cpu_hel= per.c + * Both implementation can be merged into single helper function in future. + * Keeping them separate for now, as error reporting and flow specifics are + * sufficiently different for separate implementation. + * + * @s : IOMMU Device State + * @ctx : Translation context for device id and process address space= id. + * @iotlb : translation data: physical address and access mode. + * @return : success or fault cause code. + */ +static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ct= x, + IOMMUTLBEntry *iotlb) +{ + dma_addr_t addr, base; + uint64_t satp, gatp, pte; + bool en_s, en_g; + struct { + unsigned char step; + unsigned char levels; + unsigned char ptidxbits; + unsigned char ptesize; + } sc[2]; + /* Translation stage phase */ + enum { + S_STAGE =3D 0, + G_STAGE =3D 1, + } pass; + + satp =3D get_field(ctx->satp, RISCV_IOMMU_ATP_MODE_FIELD); + gatp =3D get_field(ctx->gatp, RISCV_IOMMU_ATP_MODE_FIELD); + + en_s =3D satp !=3D RISCV_IOMMU_DC_FSC_MODE_BARE; + en_g =3D gatp !=3D RISCV_IOMMU_DC_IOHGATP_MODE_BARE; + + /* + * Early check for MSI address match when IOVA =3D=3D GPA. This check + * is required to ensure MSI translation is applied in case + * first-stage translation is set to BARE mode. In this case IOVA + * provided is a valid GPA. Running translation through page walk + * second stage translation will incorrectly try to translate GPA + * to host physical page, likely hitting IOPF. + */ + if ((iotlb->perm & IOMMU_WO) && + riscv_iommu_msi_check(s, ctx, iotlb->iova)) { + iotlb->target_as =3D &s->trap_as; + iotlb->translated_addr =3D iotlb->iova; + iotlb->addr_mask =3D ~TARGET_PAGE_MASK; + return 0; + } + + /* Exit early for pass-through mode. */ + if (!(en_s || en_g)) { + iotlb->translated_addr =3D iotlb->iova; + iotlb->addr_mask =3D ~TARGET_PAGE_MASK; + /* Allow R/W in pass-through mode */ + iotlb->perm =3D IOMMU_RW; + return 0; + } + + /* S/G translation parameters. */ + for (pass =3D 0; pass < 2; pass++) { + uint32_t sv_mode; + + sc[pass].step =3D 0; + if (pass ? (s->fctl & RISCV_IOMMU_FCTL_GXL) : + (ctx->tc & RISCV_IOMMU_DC_TC_SXL)) { + /* 32bit mode for GXL/SXL =3D=3D 1 */ + switch (pass ? gatp : satp) { + case RISCV_IOMMU_DC_IOHGATP_MODE_BARE: + sc[pass].levels =3D 0; + sc[pass].ptidxbits =3D 0; + sc[pass].ptesize =3D 0; + break; + case RISCV_IOMMU_DC_IOHGATP_MODE_SV32X4: + sv_mode =3D pass ? RISCV_IOMMU_CAP_SV32X4 : RISCV_IOMMU_CA= P_SV32; + if (!(s->cap & sv_mode)) { + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + sc[pass].levels =3D 2; + sc[pass].ptidxbits =3D 10; + sc[pass].ptesize =3D 4; + break; + default: + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + } else { + /* 64bit mode for GXL/SXL =3D=3D 0 */ + switch (pass ? gatp : satp) { + case RISCV_IOMMU_DC_IOHGATP_MODE_BARE: + sc[pass].levels =3D 0; + sc[pass].ptidxbits =3D 0; + sc[pass].ptesize =3D 0; + break; + case RISCV_IOMMU_DC_IOHGATP_MODE_SV39X4: + sv_mode =3D pass ? RISCV_IOMMU_CAP_SV39X4 : RISCV_IOMMU_CA= P_SV39; + if (!(s->cap & sv_mode)) { + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + sc[pass].levels =3D 3; + sc[pass].ptidxbits =3D 9; + sc[pass].ptesize =3D 8; + break; + case RISCV_IOMMU_DC_IOHGATP_MODE_SV48X4: + sv_mode =3D pass ? RISCV_IOMMU_CAP_SV48X4 : RISCV_IOMMU_CA= P_SV48; + if (!(s->cap & sv_mode)) { + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + sc[pass].levels =3D 4; + sc[pass].ptidxbits =3D 9; + sc[pass].ptesize =3D 8; + break; + case RISCV_IOMMU_DC_IOHGATP_MODE_SV57X4: + sv_mode =3D pass ? RISCV_IOMMU_CAP_SV57X4 : RISCV_IOMMU_CA= P_SV57; + if (!(s->cap & sv_mode)) { + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + sc[pass].levels =3D 5; + sc[pass].ptidxbits =3D 9; + sc[pass].ptesize =3D 8; + break; + default: + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + } + }; + + /* S/G stages translation tables root pointers */ + gatp =3D PPN_PHYS(get_field(ctx->gatp, RISCV_IOMMU_ATP_PPN_FIELD)); + satp =3D PPN_PHYS(get_field(ctx->satp, RISCV_IOMMU_ATP_PPN_FIELD)); + addr =3D (en_s && en_g) ? satp : iotlb->iova; + base =3D en_g ? gatp : satp; + pass =3D en_g ? G_STAGE : S_STAGE; + + do { + const unsigned widened =3D (pass && !sc[pass].step) ? 2 : 0; + const unsigned va_bits =3D widened + sc[pass].ptidxbits; + const unsigned va_skip =3D TARGET_PAGE_BITS + sc[pass].ptidxbits * + (sc[pass].levels - 1 - sc[pass].step); + const unsigned idx =3D (addr >> va_skip) & ((1 << va_bits) - 1); + const dma_addr_t pte_addr =3D base + idx * sc[pass].ptesize; + const bool ade =3D + ctx->tc & (pass ? RISCV_IOMMU_DC_TC_GADE : RISCV_IOMMU_DC_TC_S= ADE); + + /* Address range check before first level lookup */ + if (!sc[pass].step) { + const uint64_t va_mask =3D (1ULL << (va_skip + va_bits)) - 1; + if ((addr & va_mask) !=3D addr) { + return RISCV_IOMMU_FQ_CAUSE_DMA_DISABLED; + } + } + + /* Read page table entry */ + if (dma_memory_read(s->target_as, pte_addr, &pte, + sc[pass].ptesize, MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + return (iotlb->perm & IOMMU_WO) ? RISCV_IOMMU_FQ_CAUSE_WR_FAULT + : RISCV_IOMMU_FQ_CAUSE_RD_FAUL= T; + } + + if (sc[pass].ptesize =3D=3D 4) { + pte =3D (uint64_t) le32_to_cpu(*((uint32_t *)&pte)); + } else { + pte =3D le64_to_cpu(pte); + } + + sc[pass].step++; + hwaddr ppn =3D pte >> PTE_PPN_SHIFT; + + if (!(pte & PTE_V)) { + break; /* Invalid PTE */ + } else if (!(pte & (PTE_R | PTE_W | PTE_X))) { + base =3D PPN_PHYS(ppn); /* Inner PTE, continue walking */ + } else if ((pte & (PTE_R | PTE_W | PTE_X)) =3D=3D PTE_W) { + break; /* Reserved leaf PTE flags: PTE_W */ + } else if ((pte & (PTE_R | PTE_W | PTE_X)) =3D=3D (PTE_W | PTE_X))= { + break; /* Reserved leaf PTE flags: PTE_W + PTE_= X */ + } else if (ppn & ((1ULL << (va_skip - TARGET_PAGE_BITS)) - 1)) { + break; /* Misaligned PPN */ + } else if ((iotlb->perm & IOMMU_RO) && !(pte & PTE_R)) { + break; /* Read access check failed */ + } else if ((iotlb->perm & IOMMU_WO) && !(pte & PTE_W)) { + break; /* Write access check failed */ + } else if ((iotlb->perm & IOMMU_RO) && !ade && !(pte & PTE_A)) { + break; /* Access bit not set */ + } else if ((iotlb->perm & IOMMU_WO) && !ade && !(pte & PTE_D)) { + break; /* Dirty bit not set */ + } else { + /* Leaf PTE, translation completed. */ + sc[pass].step =3D sc[pass].levels; + base =3D PPN_PHYS(ppn) | (addr & ((1ULL << va_skip) - 1)); + /* Update address mask based on smallest translation granulari= ty */ + iotlb->addr_mask &=3D (1ULL << va_skip) - 1; + /* Continue with S-Stage translation? */ + if (pass && sc[0].step !=3D sc[0].levels) { + pass =3D S_STAGE; + addr =3D iotlb->iova; + continue; + } + /* Translation phase completed (GPA or SPA) */ + iotlb->translated_addr =3D base; + iotlb->perm =3D (pte & PTE_W) ? ((pte & PTE_R) ? IOMMU_RW : IO= MMU_WO) + : IOMMU_RO; + + /* Check MSI GPA address match */ + if (pass =3D=3D S_STAGE && (iotlb->perm & IOMMU_WO) && + riscv_iommu_msi_check(s, ctx, base)) { + /* Trap MSI writes and return GPA address. */ + iotlb->target_as =3D &s->trap_as; + iotlb->addr_mask =3D ~TARGET_PAGE_MASK; + return 0; + } + + /* Continue with G-Stage translation? */ + if (!pass && en_g) { + pass =3D G_STAGE; + addr =3D base; + base =3D gatp; + sc[pass].step =3D 0; + continue; + } + + return 0; + } + + if (sc[pass].step =3D=3D sc[pass].levels) { + break; /* Can't find leaf PTE */ + } + + /* Continue with G-Stage translation? */ + if (!pass && en_g) { + pass =3D G_STAGE; + addr =3D base; + base =3D gatp; + sc[pass].step =3D 0; + } + } while (1); + + return (iotlb->perm & IOMMU_WO) ? + (pass ? RISCV_IOMMU_FQ_CAUSE_WR_FAULT_VS : + RISCV_IOMMU_FQ_CAUSE_WR_FAULT_S) : + (pass ? RISCV_IOMMU_FQ_CAUSE_RD_FAULT_VS : + RISCV_IOMMU_FQ_CAUSE_RD_FAULT_S); +} + +static void riscv_iommu_report_fault(RISCVIOMMUState *s, + RISCVIOMMUContext *ctx, + uint32_t fault_type, uint32_t cause, + bool pv, + uint64_t iotval, uint64_t iotval2) +{ + struct riscv_iommu_fq_record ev =3D { 0 }; + + if (ctx->tc & RISCV_IOMMU_DC_TC_DTF) { + switch (cause) { + case RISCV_IOMMU_FQ_CAUSE_DMA_DISABLED: + case RISCV_IOMMU_FQ_CAUSE_DDT_LOAD_FAULT: + case RISCV_IOMMU_FQ_CAUSE_DDT_INVALID: + case RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED: + case RISCV_IOMMU_FQ_CAUSE_DDT_CORRUPTED: + case RISCV_IOMMU_FQ_CAUSE_INTERNAL_DP_ERROR: + case RISCV_IOMMU_FQ_CAUSE_MSI_WR_FAULT: + break; + default: + /* DTF prevents reporting a fault for this given cause */ + return; + } + } + + ev.hdr =3D set_field(ev.hdr, RISCV_IOMMU_FQ_HDR_CAUSE, cause); + ev.hdr =3D set_field(ev.hdr, RISCV_IOMMU_FQ_HDR_TTYPE, fault_type); + ev.hdr =3D set_field(ev.hdr, RISCV_IOMMU_FQ_HDR_DID, ctx->devid); + ev.hdr =3D set_field(ev.hdr, RISCV_IOMMU_FQ_HDR_PV, true); + + if (pv) { + ev.hdr =3D set_field(ev.hdr, RISCV_IOMMU_FQ_HDR_PID, ctx->process_= id); + } + + ev.iotval =3D iotval; + ev.iotval2 =3D iotval2; + + riscv_iommu_fault(s, &ev); +} + +/* Redirect MSI write for given GPA. */ +static MemTxResult riscv_iommu_msi_write(RISCVIOMMUState *s, + RISCVIOMMUContext *ctx, uint64_t gpa, uint64_t data, + unsigned size, MemTxAttrs attrs) +{ + MemTxResult res; + dma_addr_t addr; + uint64_t intn; + uint32_t n190; + uint64_t pte[2]; + int fault_type =3D RISCV_IOMMU_FQ_TTYPE_UADDR_WR; + int cause; + + /* Interrupt File Number */ + intn =3D _pext_u64(PPN_DOWN(gpa), ctx->msi_addr_mask); + if (intn >=3D 256) { + /* Interrupt file number out of range */ + res =3D MEMTX_ACCESS_ERROR; + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_LOAD_FAULT; + goto err; + } + + /* fetch MSI PTE */ + addr =3D PPN_PHYS(get_field(ctx->msiptp, RISCV_IOMMU_DC_MSIPTP_PPN)); + addr =3D addr | (intn * sizeof(pte)); + res =3D dma_memory_read(s->target_as, addr, &pte, sizeof(pte), + MEMTXATTRS_UNSPECIFIED); + if (res !=3D MEMTX_OK) { + if (res =3D=3D MEMTX_DECODE_ERROR) { + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_PT_CORRUPTED; + } else { + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_LOAD_FAULT; + } + goto err; + } + + le64_to_cpus(&pte[0]); + le64_to_cpus(&pte[1]); + + if (!(pte[0] & RISCV_IOMMU_MSI_PTE_V) || (pte[0] & RISCV_IOMMU_MSI_PTE= _C)) { + /* + * The spec mentions that: "If msipte.C =3D=3D 1, then further + * processing to interpret the PTE is implementation + * defined.". We'll abort with cause =3D 262 for this + * case too. + */ + res =3D MEMTX_ACCESS_ERROR; + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_INVALID; + goto err; + } + + switch (get_field(pte[0], RISCV_IOMMU_MSI_PTE_M)) { + case RISCV_IOMMU_MSI_PTE_M_BASIC: + /* MSI Pass-through mode */ + addr =3D PPN_PHYS(get_field(pte[0], RISCV_IOMMU_MSI_PTE_PPN)); + + trace_riscv_iommu_msi(s->parent_obj.id, PCI_BUS_NUM(ctx->devid), + PCI_SLOT(ctx->devid), PCI_FUNC(ctx->devid), + gpa, addr); + + res =3D dma_memory_write(s->target_as, addr, &data, size, attrs); + if (res !=3D MEMTX_OK) { + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_WR_FAULT; + goto err; + } + + return MEMTX_OK; + case RISCV_IOMMU_MSI_PTE_M_MRIF: + /* MRIF mode, continue. */ + break; + default: + res =3D MEMTX_ACCESS_ERROR; + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_MISCONFIGURED; + goto err; + } + + /* + * Report an error for interrupt identities exceeding the maximum allo= wed + * for an IMSIC interrupt file (2047) or destination address is not 32= -bit + * aligned. See IOMMU Specification, Chapter 2.3. MSI page tables. + */ + if ((data > 2047) || (gpa & 3)) { + res =3D MEMTX_ACCESS_ERROR; + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_MISCONFIGURED; + goto err; + } + + /* MSI MRIF mode, non atomic pending bit update */ + + /* MRIF pending bit address */ + addr =3D get_field(pte[0], RISCV_IOMMU_MSI_PTE_MRIF_ADDR) << 9; + addr =3D addr | ((data & 0x7c0) >> 3); + + trace_riscv_iommu_msi(s->parent_obj.id, PCI_BUS_NUM(ctx->devid), + PCI_SLOT(ctx->devid), PCI_FUNC(ctx->devid), + gpa, addr); + + /* MRIF pending bit mask */ + data =3D 1ULL << (data & 0x03f); + res =3D dma_memory_read(s->target_as, addr, &intn, sizeof(intn), attrs= ); + if (res !=3D MEMTX_OK) { + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_LOAD_FAULT; + goto err; + } + + intn =3D intn | data; + res =3D dma_memory_write(s->target_as, addr, &intn, sizeof(intn), attr= s); + if (res !=3D MEMTX_OK) { + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_WR_FAULT; + goto err; + } + + /* Get MRIF enable bits */ + addr =3D addr + sizeof(intn); + res =3D dma_memory_read(s->target_as, addr, &intn, sizeof(intn), attrs= ); + if (res !=3D MEMTX_OK) { + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_LOAD_FAULT; + goto err; + } + + if (!(intn & data)) { + /* notification disabled, MRIF update completed. */ + return MEMTX_OK; + } + + /* Send notification message */ + addr =3D PPN_PHYS(get_field(pte[1], RISCV_IOMMU_MSI_MRIF_NPPN)); + n190 =3D get_field(pte[1], RISCV_IOMMU_MSI_MRIF_NID) | + (get_field(pte[1], RISCV_IOMMU_MSI_MRIF_NID_MSB) << 10); + + res =3D dma_memory_write(s->target_as, addr, &n190, sizeof(n190), attr= s); + if (res !=3D MEMTX_OK) { + cause =3D RISCV_IOMMU_FQ_CAUSE_MSI_WR_FAULT; + goto err; + } + + trace_riscv_iommu_mrif_notification(s->parent_obj.id, n190, addr); + + return MEMTX_OK; + +err: + riscv_iommu_report_fault(s, ctx, fault_type, cause, + !!ctx->process_id, 0, 0); + return res; +} + +/* + * Check device context configuration as described by the + * riscv-iommu spec section "Device-context configuration + * checks". + */ +static bool riscv_iommu_validate_device_ctx(RISCVIOMMUState *s, + RISCVIOMMUContext *ctx) +{ + uint32_t fsc_mode, msi_mode; + + if (!(ctx->tc & RISCV_IOMMU_DC_TC_EN_PRI) && + ctx->tc & RISCV_IOMMU_DC_TC_PRPR) { + return false; + } + + if (!(s->cap & RISCV_IOMMU_CAP_T2GPA) && + ctx->tc & RISCV_IOMMU_DC_TC_T2GPA) { + return false; + } + + if (s->cap & RISCV_IOMMU_CAP_MSI_FLAT) { + msi_mode =3D get_field(ctx->msiptp, RISCV_IOMMU_DC_MSIPTP_MODE); + + if (msi_mode !=3D RISCV_IOMMU_DC_MSIPTP_MODE_OFF && + msi_mode !=3D RISCV_IOMMU_DC_MSIPTP_MODE_FLAT) { + return false; + } + } + + fsc_mode =3D get_field(ctx->satp, RISCV_IOMMU_DC_FSC_MODE); + + if (ctx->tc & RISCV_IOMMU_DC_TC_PDTV) { + switch (fsc_mode) { + case RISCV_IOMMU_DC_FSC_PDTP_MODE_PD8: + if (!(s->cap & RISCV_IOMMU_CAP_PD8)) { + return false; + } + break; + case RISCV_IOMMU_DC_FSC_PDTP_MODE_PD17: + if (!(s->cap & RISCV_IOMMU_CAP_PD17)) { + return false; + } + break; + case RISCV_IOMMU_DC_FSC_PDTP_MODE_PD20: + if (!(s->cap & RISCV_IOMMU_CAP_PD20)) { + return false; + } + break; + } + } else { + /* DC.tc.PDTV is 0 */ + if (ctx->tc & RISCV_IOMMU_DC_TC_DPE) { + return false; + } + + if (ctx->tc & RISCV_IOMMU_DC_TC_SXL) { + if (fsc_mode =3D=3D RISCV_IOMMU_CAP_SV32 && + !(s->cap & RISCV_IOMMU_CAP_SV32)) { + return false; + } + } else { + switch (fsc_mode) { + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV39: + if (!(s->cap & RISCV_IOMMU_CAP_SV39)) { + return false; + } + break; + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV48: + if (!(s->cap & RISCV_IOMMU_CAP_SV48)) { + return false; + } + break; + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV57: + if (!(s->cap & RISCV_IOMMU_CAP_SV57)) { + return false; + } + break; + } + } + } + + /* + * CAP_END is always zero (only one endianess). FCTL_BE is + * always zero (little-endian accesses). Thus TC_SBE must + * always be LE, i.e. zero. + */ + if (ctx->tc & RISCV_IOMMU_DC_TC_SBE) { + return false; + } + + return true; +} + +/* + * Validate process context (PC) according to section + * "Process-context configuration checks". + */ +static bool riscv_iommu_validate_process_ctx(RISCVIOMMUState *s, + RISCVIOMMUContext *ctx) +{ + uint32_t mode; + + if (get_field(ctx->ta, RISCV_IOMMU_PC_TA_RESERVED)) { + return false; + } + + if (get_field(ctx->satp, RISCV_IOMMU_PC_FSC_RESERVED)) { + return false; + } + + mode =3D get_field(ctx->satp, RISCV_IOMMU_DC_FSC_MODE); + switch (mode) { + case RISCV_IOMMU_DC_FSC_MODE_BARE: + /* sv39 and sv32 modes have the same value (8) */ + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV39: + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV48: + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV57: + break; + default: + return false; + } + + if (ctx->tc & RISCV_IOMMU_DC_TC_SXL) { + if (mode =3D=3D RISCV_IOMMU_CAP_SV32 && + !(s->cap & RISCV_IOMMU_CAP_SV32)) { + return false; + } + } else { + switch (mode) { + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV39: + if (!(s->cap & RISCV_IOMMU_CAP_SV39)) { + return false; + } + break; + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV48: + if (!(s->cap & RISCV_IOMMU_CAP_SV48)) { + return false; + } + break; + case RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV57: + if (!(s->cap & RISCV_IOMMU_CAP_SV57)) { + return false; + } + break; + } + } + + return true; +} + +/* + * RISC-V IOMMU Device Context Loopkup - Device Directory Tree Walk + * + * @s : IOMMU Device State + * @ctx : Device Translation Context with devid and process_id set. + * @return : success or fault code. + */ +static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ct= x) +{ + const uint64_t ddtp =3D s->ddtp; + unsigned mode =3D get_field(ddtp, RISCV_IOMMU_DDTP_MODE); + dma_addr_t addr =3D PPN_PHYS(get_field(ddtp, RISCV_IOMMU_DDTP_PPN)); + struct riscv_iommu_dc dc; + /* Device Context format: 0: extended (64 bytes) | 1: base (32 bytes) = */ + const int dc_fmt =3D !s->enable_msi; + const size_t dc_len =3D sizeof(dc) >> dc_fmt; + unsigned depth; + uint64_t de; + + switch (mode) { + case RISCV_IOMMU_DDTP_MODE_OFF: + return RISCV_IOMMU_FQ_CAUSE_DMA_DISABLED; + + case RISCV_IOMMU_DDTP_MODE_BARE: + /* mock up pass-through translation context */ + ctx->gatp =3D set_field(0, RISCV_IOMMU_ATP_MODE_FIELD, + RISCV_IOMMU_DC_IOHGATP_MODE_BARE); + ctx->satp =3D set_field(0, RISCV_IOMMU_ATP_MODE_FIELD, + RISCV_IOMMU_DC_FSC_MODE_BARE); + ctx->tc =3D RISCV_IOMMU_DC_TC_V; + ctx->ta =3D 0; + ctx->msiptp =3D 0; + return 0; + + case RISCV_IOMMU_DDTP_MODE_1LVL: + depth =3D 0; + break; + + case RISCV_IOMMU_DDTP_MODE_2LVL: + depth =3D 1; + break; + + case RISCV_IOMMU_DDTP_MODE_3LVL: + depth =3D 2; + break; + + default: + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + + /* + * Check supported device id width (in bits). + * See IOMMU Specification, Chapter 6. Software guidelines. + * - if extended device-context format is used: + * 1LVL: 6, 2LVL: 15, 3LVL: 24 + * - if base device-context format is used: + * 1LVL: 7, 2LVL: 16, 3LVL: 24 + */ + if (ctx->devid >=3D (1 << (depth * 9 + 6 + (dc_fmt && depth !=3D 2))))= { + return RISCV_IOMMU_FQ_CAUSE_TTYPE_BLOCKED; + } + + /* Device directory tree walk */ + for (; depth-- > 0; ) { + /* + * Select device id index bits based on device directory tree level + * and device context format. + * See IOMMU Specification, Chapter 2. Data Structures. + * - if extended device-context format is used: + * device index: [23:15][14:6][5:0] + * - if base device-context format is used: + * device index: [23:16][15:7][6:0] + */ + const int split =3D depth * 9 + 6 + dc_fmt; + addr |=3D ((ctx->devid >> split) << 3) & ~TARGET_PAGE_MASK; + if (dma_memory_read(s->target_as, addr, &de, sizeof(de), + MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + return RISCV_IOMMU_FQ_CAUSE_DDT_LOAD_FAULT; + } + le64_to_cpus(&de); + if (!(de & RISCV_IOMMU_DDTE_VALID)) { + /* invalid directory entry */ + return RISCV_IOMMU_FQ_CAUSE_DDT_INVALID; + } + if (de & ~(RISCV_IOMMU_DDTE_PPN | RISCV_IOMMU_DDTE_VALID)) { + /* reserved bits set */ + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + addr =3D PPN_PHYS(get_field(de, RISCV_IOMMU_DDTE_PPN)); + } + + /* index into device context entry page */ + addr |=3D (ctx->devid * dc_len) & ~TARGET_PAGE_MASK; + + memset(&dc, 0, sizeof(dc)); + if (dma_memory_read(s->target_as, addr, &dc, dc_len, + MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + return RISCV_IOMMU_FQ_CAUSE_DDT_LOAD_FAULT; + } + + /* Set translation context. */ + ctx->tc =3D le64_to_cpu(dc.tc); + ctx->gatp =3D le64_to_cpu(dc.iohgatp); + ctx->satp =3D le64_to_cpu(dc.fsc); + ctx->ta =3D le64_to_cpu(dc.ta); + ctx->msiptp =3D le64_to_cpu(dc.msiptp); + ctx->msi_addr_mask =3D le64_to_cpu(dc.msi_addr_mask); + ctx->msi_addr_pattern =3D le64_to_cpu(dc.msi_addr_pattern); + + if (!(ctx->tc & RISCV_IOMMU_DC_TC_V)) { + return RISCV_IOMMU_FQ_CAUSE_DDT_INVALID; + } + + if (!riscv_iommu_validate_device_ctx(s, ctx)) { + return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED; + } + + /* FSC field checks */ + mode =3D get_field(ctx->satp, RISCV_IOMMU_DC_FSC_MODE); + addr =3D PPN_PHYS(get_field(ctx->satp, RISCV_IOMMU_DC_FSC_PPN)); + + if (!(ctx->tc & RISCV_IOMMU_DC_TC_PDTV)) { + if (ctx->process_id !=3D RISCV_IOMMU_NOPROCID) { + /* PID is disabled */ + return RISCV_IOMMU_FQ_CAUSE_TTYPE_BLOCKED; + } + if (mode > RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV57) { + /* Invalid translation mode */ + return RISCV_IOMMU_FQ_CAUSE_DDT_INVALID; + } + return 0; + } + + if (ctx->process_id =3D=3D RISCV_IOMMU_NOPROCID) { + if (!(ctx->tc & RISCV_IOMMU_DC_TC_DPE)) { + /* No default process_id enabled, set BARE mode */ + ctx->satp =3D 0ULL; + return 0; + } else { + /* Use default process_id #0 */ + ctx->process_id =3D 0; + } + } + + if (mode =3D=3D RISCV_IOMMU_DC_FSC_MODE_BARE) { + /* No S-Stage translation, done. */ + return 0; + } + + /* FSC.TC.PDTV enabled */ + if (mode > RISCV_IOMMU_DC_FSC_PDTP_MODE_PD20) { + /* Invalid PDTP.MODE */ + return RISCV_IOMMU_FQ_CAUSE_PDT_MISCONFIGURED; + } + + for (depth =3D mode - RISCV_IOMMU_DC_FSC_PDTP_MODE_PD8; depth-- > 0; )= { + /* + * Select process id index bits based on process directory tree + * level. See IOMMU Specification, 2.2. Process-Directory-Table. + */ + const int split =3D depth * 9 + 8; + addr |=3D ((ctx->process_id >> split) << 3) & ~TARGET_PAGE_MASK; + if (dma_memory_read(s->target_as, addr, &de, sizeof(de), + MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + return RISCV_IOMMU_FQ_CAUSE_PDT_LOAD_FAULT; + } + le64_to_cpus(&de); + if (!(de & RISCV_IOMMU_PC_TA_V)) { + return RISCV_IOMMU_FQ_CAUSE_PDT_INVALID; + } + addr =3D PPN_PHYS(get_field(de, RISCV_IOMMU_PC_FSC_PPN)); + } + + /* Leaf entry in PDT */ + addr |=3D (ctx->process_id << 4) & ~TARGET_PAGE_MASK; + if (dma_memory_read(s->target_as, addr, &dc.ta, sizeof(uint64_t) * 2, + MEMTXATTRS_UNSPECIFIED) !=3D MEMTX_OK) { + return RISCV_IOMMU_FQ_CAUSE_PDT_LOAD_FAULT; + } + + /* Use FSC and TA from process directory entry. */ + ctx->ta =3D le64_to_cpu(dc.ta); + ctx->satp =3D le64_to_cpu(dc.fsc); + + if (!(ctx->ta & RISCV_IOMMU_PC_TA_V)) { + return RISCV_IOMMU_FQ_CAUSE_PDT_INVALID; + } + + if (!riscv_iommu_validate_process_ctx(s, ctx)) { + return RISCV_IOMMU_FQ_CAUSE_PDT_MISCONFIGURED; + } + + return 0; +} + +/* Translation Context cache support */ +static gboolean __ctx_equal(gconstpointer v1, gconstpointer v2) +{ + RISCVIOMMUContext *c1 =3D (RISCVIOMMUContext *) v1; + RISCVIOMMUContext *c2 =3D (RISCVIOMMUContext *) v2; + return c1->devid =3D=3D c2->devid && + c1->process_id =3D=3D c2->process_id; +} + +static guint __ctx_hash(gconstpointer v) +{ + RISCVIOMMUContext *ctx =3D (RISCVIOMMUContext *) v; + /* + * Generate simple hash of (process_id, devid) + * assuming 24-bit wide devid. + */ + return (guint)(ctx->devid) + ((guint)(ctx->process_id) << 24); +} + +static void __ctx_inval_devid_procid(gpointer key, gpointer value, + gpointer data) +{ + RISCVIOMMUContext *ctx =3D (RISCVIOMMUContext *) value; + RISCVIOMMUContext *arg =3D (RISCVIOMMUContext *) data; + if (ctx->tc & RISCV_IOMMU_DC_TC_V && + ctx->devid =3D=3D arg->devid && + ctx->process_id =3D=3D arg->process_id) { + ctx->tc &=3D ~RISCV_IOMMU_DC_TC_V; + } +} + +static void __ctx_inval_devid(gpointer key, gpointer value, gpointer data) +{ + RISCVIOMMUContext *ctx =3D (RISCVIOMMUContext *) value; + RISCVIOMMUContext *arg =3D (RISCVIOMMUContext *) data; + if (ctx->tc & RISCV_IOMMU_DC_TC_V && + ctx->devid =3D=3D arg->devid) { + ctx->tc &=3D ~RISCV_IOMMU_DC_TC_V; + } +} + +static void __ctx_inval_all(gpointer key, gpointer value, gpointer data) +{ + RISCVIOMMUContext *ctx =3D (RISCVIOMMUContext *) value; + if (ctx->tc & RISCV_IOMMU_DC_TC_V) { + ctx->tc &=3D ~RISCV_IOMMU_DC_TC_V; + } +} + +static void riscv_iommu_ctx_inval(RISCVIOMMUState *s, GHFunc func, + uint32_t devid, uint32_t process_id) +{ + GHashTable *ctx_cache; + RISCVIOMMUContext key =3D { + .devid =3D devid, + .process_id =3D process_id, + }; + ctx_cache =3D g_hash_table_ref(s->ctx_cache); + qemu_mutex_lock(&s->ctx_lock); + g_hash_table_foreach(ctx_cache, func, &key); + qemu_mutex_unlock(&s->ctx_lock); + g_hash_table_unref(ctx_cache); +} + +/* Find or allocate translation context for a given {device_id, process_id= } */ +static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s, + unsigned devid, unsigned process= _id, + void **ref) +{ + GHashTable *ctx_cache; + RISCVIOMMUContext *ctx; + RISCVIOMMUContext key =3D { + .devid =3D devid, + .process_id =3D process_id, + }; + + ctx_cache =3D g_hash_table_ref(s->ctx_cache); + qemu_mutex_lock(&s->ctx_lock); + ctx =3D g_hash_table_lookup(ctx_cache, &key); + qemu_mutex_unlock(&s->ctx_lock); + + if (ctx && (ctx->tc & RISCV_IOMMU_DC_TC_V)) { + *ref =3D ctx_cache; + return ctx; + } + + ctx =3D g_new0(RISCVIOMMUContext, 1); + ctx->devid =3D devid; + ctx->process_id =3D process_id; + + int fault =3D riscv_iommu_ctx_fetch(s, ctx); + if (!fault) { + qemu_mutex_lock(&s->ctx_lock); + if (g_hash_table_size(ctx_cache) >=3D LIMIT_CACHE_CTX) { + g_hash_table_unref(ctx_cache); + ctx_cache =3D g_hash_table_new_full(__ctx_hash, __ctx_equal, + g_free, NULL); + g_hash_table_ref(ctx_cache); + g_hash_table_unref(qatomic_xchg(&s->ctx_cache, ctx_cache)); + } + g_hash_table_add(ctx_cache, ctx); + qemu_mutex_unlock(&s->ctx_lock); + *ref =3D ctx_cache; + return ctx; + } + + g_hash_table_unref(ctx_cache); + *ref =3D NULL; + + riscv_iommu_report_fault(s, ctx, RISCV_IOMMU_FQ_TTYPE_UADDR_RD, + fault, !!process_id, 0, 0); + + g_free(ctx); + return NULL; +} + +static void riscv_iommu_ctx_put(RISCVIOMMUState *s, void *ref) +{ + if (ref) { + g_hash_table_unref((GHashTable *)ref); + } +} + +/* Find or allocate address space for a given device */ +static AddressSpace *riscv_iommu_space(RISCVIOMMUState *s, uint32_t devid) +{ + RISCVIOMMUSpace *as; + + /* FIXME: PCIe bus remapping for attached endpoints. */ + devid |=3D s->bus << 8; + + qemu_mutex_lock(&s->core_lock); + QLIST_FOREACH(as, &s->spaces, list) { + if (as->devid =3D=3D devid) { + break; + } + } + qemu_mutex_unlock(&s->core_lock); + + if (as =3D=3D NULL) { + char name[64]; + as =3D g_new0(RISCVIOMMUSpace, 1); + + as->iommu =3D s; + as->devid =3D devid; + + snprintf(name, sizeof(name), "riscv-iommu-%04x:%02x.%d-iova", + PCI_BUS_NUM(as->devid), PCI_SLOT(as->devid), PCI_FUNC(as->devi= d)); + + /* IOVA address space, untranslated addresses */ + memory_region_init_iommu(&as->iova_mr, sizeof(as->iova_mr), + TYPE_RISCV_IOMMU_MEMORY_REGION, + OBJECT(as), "riscv_iommu", UINT64_MAX); + address_space_init(&as->iova_as, MEMORY_REGION(&as->iova_mr), name= ); + + qemu_mutex_lock(&s->core_lock); + QLIST_INSERT_HEAD(&s->spaces, as, list); + qemu_mutex_unlock(&s->core_lock); + + trace_riscv_iommu_new(s->parent_obj.id, PCI_BUS_NUM(as->devid), + PCI_SLOT(as->devid), PCI_FUNC(as->devid)); + } + return &as->iova_as; +} + +static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ct= x, + IOMMUTLBEntry *iotlb) +{ + bool enable_pid; + bool enable_pri; + int fault; + + /* + * TC[32] is reserved for custom extensions, used here to temporarily + * enable automatic page-request generation for ATS queries. + */ + enable_pri =3D (iotlb->perm =3D=3D IOMMU_NONE) && (ctx->tc & BIT_ULL(3= 2)); + enable_pid =3D (ctx->tc & RISCV_IOMMU_DC_TC_PDTV); + + /* Translate using device directory / page table information. */ + fault =3D riscv_iommu_spa_fetch(s, ctx, iotlb); + + if (enable_pri && fault) { + struct riscv_iommu_pq_record pr =3D {0}; + if (enable_pid) { + pr.hdr =3D set_field(RISCV_IOMMU_PREQ_HDR_PV, + RISCV_IOMMU_PREQ_HDR_PID, ctx->process_id); + } + pr.hdr =3D set_field(pr.hdr, RISCV_IOMMU_PREQ_HDR_DID, ctx->devid); + pr.payload =3D (iotlb->iova & TARGET_PAGE_MASK) | + RISCV_IOMMU_PREQ_PAYLOAD_M; + riscv_iommu_pri(s, &pr); + return fault; + } + + if (fault) { + unsigned ttype; + + if (iotlb->perm & IOMMU_RW) { + ttype =3D RISCV_IOMMU_FQ_TTYPE_UADDR_WR; + } else { + ttype =3D RISCV_IOMMU_FQ_TTYPE_UADDR_RD; + } + + riscv_iommu_report_fault(s, ctx, ttype, fault, enable_pid, + iotlb->iova, iotlb->translated_addr); + return fault; + } + + return 0; +} + +/* IOMMU Command Interface */ +static MemTxResult riscv_iommu_iofence(RISCVIOMMUState *s, bool notify, + uint64_t addr, uint32_t data) +{ + /* + * ATS processing in this implementation of the IOMMU is synchronous, + * no need to wait for completions here. + */ + if (!notify) { + return MEMTX_OK; + } + + return dma_memory_write(s->target_as, addr, &data, sizeof(data), + MEMTXATTRS_UNSPECIFIED); +} + +static void riscv_iommu_process_ddtp(RISCVIOMMUState *s) +{ + uint64_t old_ddtp =3D s->ddtp; + uint64_t new_ddtp =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_DDTP); + unsigned new_mode =3D get_field(new_ddtp, RISCV_IOMMU_DDTP_MODE); + unsigned old_mode =3D get_field(old_ddtp, RISCV_IOMMU_DDTP_MODE); + bool ok =3D false; + + /* + * Check for allowed DDTP.MODE transitions: + * {OFF, BARE} -> {OFF, BARE, 1LVL, 2LVL, 3LVL} + * {1LVL, 2LVL, 3LVL} -> {OFF, BARE} + */ + if (new_mode =3D=3D old_mode || + new_mode =3D=3D RISCV_IOMMU_DDTP_MODE_OFF || + new_mode =3D=3D RISCV_IOMMU_DDTP_MODE_BARE) { + ok =3D true; + } else if (new_mode =3D=3D RISCV_IOMMU_DDTP_MODE_1LVL || + new_mode =3D=3D RISCV_IOMMU_DDTP_MODE_2LVL || + new_mode =3D=3D RISCV_IOMMU_DDTP_MODE_3LVL) { + ok =3D old_mode =3D=3D RISCV_IOMMU_DDTP_MODE_OFF || + old_mode =3D=3D RISCV_IOMMU_DDTP_MODE_BARE; + } + + if (ok) { + /* clear reserved and busy bits, report back sanitized version */ + new_ddtp =3D set_field(new_ddtp & RISCV_IOMMU_DDTP_PPN, + RISCV_IOMMU_DDTP_MODE, new_mode); + } else { + new_ddtp =3D old_ddtp; + } + s->ddtp =3D new_ddtp; + + riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_DDTP, new_ddtp); +} + +/* Command function and opcode field. */ +#define RISCV_IOMMU_CMD(func, op) (((func) << 7) | (op)) + +static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s) +{ + struct riscv_iommu_command cmd; + MemTxResult res; + dma_addr_t addr; + uint32_t tail, head, ctrl; + uint64_t cmd_opcode; + GHFunc func; + + ctrl =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_CQCSR); + tail =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_CQT) & s->cq_mask; + head =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_CQH) & s->cq_mask; + + /* Check for pending error or queue processing disabled */ + if (!(ctrl & RISCV_IOMMU_CQCSR_CQON) || + !!(ctrl & (RISCV_IOMMU_CQCSR_CMD_ILL | RISCV_IOMMU_CQCSR_CQMF))) { + return; + } + + while (tail !=3D head) { + addr =3D s->cq_addr + head * sizeof(cmd); + res =3D dma_memory_read(s->target_as, addr, &cmd, sizeof(cmd), + MEMTXATTRS_UNSPECIFIED); + + if (res !=3D MEMTX_OK) { + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_CQCSR, + RISCV_IOMMU_CQCSR_CQMF, 0); + goto fault; + } + + trace_riscv_iommu_cmd(s->parent_obj.id, cmd.dword0, cmd.dword1); + + cmd_opcode =3D get_field(cmd.dword0, + RISCV_IOMMU_CMD_OPCODE | RISCV_IOMMU_CMD_FU= NC); + + switch (cmd_opcode) { + case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IOFENCE_FUNC_C, + RISCV_IOMMU_CMD_IOFENCE_OPCODE): + res =3D riscv_iommu_iofence(s, + cmd.dword0 & RISCV_IOMMU_CMD_IOFENCE_AV, cmd.dword1, + get_field(cmd.dword0, RISCV_IOMMU_CMD_IOFENCE_DATA)); + + if (res !=3D MEMTX_OK) { + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_CQCSR, + RISCV_IOMMU_CQCSR_CQMF, 0); + goto fault; + } + break; + + case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IOTINVAL_FUNC_GVMA, + RISCV_IOMMU_CMD_IOTINVAL_OPCODE): + if (cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_PSCV) { + /* illegal command arguments IOTINVAL.GVMA & PSCV =3D=3D 1= */ + goto cmd_ill; + } + /* translation cache not implemented yet */ + break; + + case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IOTINVAL_FUNC_VMA, + RISCV_IOMMU_CMD_IOTINVAL_OPCODE): + /* translation cache not implemented yet */ + break; + + case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IODIR_FUNC_INVAL_DDT, + RISCV_IOMMU_CMD_IODIR_OPCODE): + if (!(cmd.dword0 & RISCV_IOMMU_CMD_IODIR_DV)) { + /* invalidate all device context cache mappings */ + func =3D __ctx_inval_all; + } else { + /* invalidate all device context matching DID */ + func =3D __ctx_inval_devid; + } + riscv_iommu_ctx_inval(s, func, + get_field(cmd.dword0, RISCV_IOMMU_CMD_IODIR_DID), 0); + break; + + case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IODIR_FUNC_INVAL_PDT, + RISCV_IOMMU_CMD_IODIR_OPCODE): + if (!(cmd.dword0 & RISCV_IOMMU_CMD_IODIR_DV)) { + /* illegal command arguments IODIR_PDT & DV =3D=3D 0 */ + goto cmd_ill; + } else { + func =3D __ctx_inval_devid_procid; + } + riscv_iommu_ctx_inval(s, func, + get_field(cmd.dword0, RISCV_IOMMU_CMD_IODIR_DID), + get_field(cmd.dword0, RISCV_IOMMU_CMD_IODIR_PID)); + break; + + default: + cmd_ill: + /* Invalid instruction, do not advance instruction index. */ + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_CQCSR, + RISCV_IOMMU_CQCSR_CMD_ILL, 0); + goto fault; + } + + /* Advance and update head pointer after command completes. */ + head =3D (head + 1) & s->cq_mask; + riscv_iommu_reg_set32(s, RISCV_IOMMU_REG_CQH, head); + } + return; + +fault: + if (ctrl & RISCV_IOMMU_CQCSR_CIE) { + riscv_iommu_notify(s, RISCV_IOMMU_INTR_CQ); + } +} + +static void riscv_iommu_process_cq_control(RISCVIOMMUState *s) +{ + uint64_t base; + uint32_t ctrl_set =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_CQCSR); + uint32_t ctrl_clr; + bool enable =3D !!(ctrl_set & RISCV_IOMMU_CQCSR_CQEN); + bool active =3D !!(ctrl_set & RISCV_IOMMU_CQCSR_CQON); + + if (enable && !active) { + base =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_CQB); + s->cq_mask =3D (2ULL << get_field(base, RISCV_IOMMU_CQB_LOG2SZ)) -= 1; + s->cq_addr =3D PPN_PHYS(get_field(base, RISCV_IOMMU_CQB_PPN)); + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_CQT], ~s->cq_mask); + stl_le_p(&s->regs_rw[RISCV_IOMMU_REG_CQH], 0); + stl_le_p(&s->regs_rw[RISCV_IOMMU_REG_CQT], 0); + ctrl_set =3D RISCV_IOMMU_CQCSR_CQON; + ctrl_clr =3D RISCV_IOMMU_CQCSR_BUSY | RISCV_IOMMU_CQCSR_CQMF | + RISCV_IOMMU_CQCSR_CMD_ILL | RISCV_IOMMU_CQCSR_CMD_TO | + RISCV_IOMMU_CQCSR_FENCE_W_IP; + } else if (!enable && active) { + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_CQT], ~0); + ctrl_set =3D 0; + ctrl_clr =3D RISCV_IOMMU_CQCSR_BUSY | RISCV_IOMMU_CQCSR_CQON; + } else { + ctrl_set =3D 0; + ctrl_clr =3D RISCV_IOMMU_CQCSR_BUSY; + } + + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_CQCSR, ctrl_set, ctrl_clr); +} + +static void riscv_iommu_process_fq_control(RISCVIOMMUState *s) +{ + uint64_t base; + uint32_t ctrl_set =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FQCSR); + uint32_t ctrl_clr; + bool enable =3D !!(ctrl_set & RISCV_IOMMU_FQCSR_FQEN); + bool active =3D !!(ctrl_set & RISCV_IOMMU_FQCSR_FQON); + + if (enable && !active) { + base =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_FQB); + s->fq_mask =3D (2ULL << get_field(base, RISCV_IOMMU_FQB_LOG2SZ)) -= 1; + s->fq_addr =3D PPN_PHYS(get_field(base, RISCV_IOMMU_FQB_PPN)); + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_FQH], ~s->fq_mask); + stl_le_p(&s->regs_rw[RISCV_IOMMU_REG_FQH], 0); + stl_le_p(&s->regs_rw[RISCV_IOMMU_REG_FQT], 0); + ctrl_set =3D RISCV_IOMMU_FQCSR_FQON; + ctrl_clr =3D RISCV_IOMMU_FQCSR_BUSY | RISCV_IOMMU_FQCSR_FQMF | + RISCV_IOMMU_FQCSR_FQOF; + } else if (!enable && active) { + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_FQH], ~0); + ctrl_set =3D 0; + ctrl_clr =3D RISCV_IOMMU_FQCSR_BUSY | RISCV_IOMMU_FQCSR_FQON; + } else { + ctrl_set =3D 0; + ctrl_clr =3D RISCV_IOMMU_FQCSR_BUSY; + } + + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_FQCSR, ctrl_set, ctrl_clr); +} + +static void riscv_iommu_process_pq_control(RISCVIOMMUState *s) +{ + uint64_t base; + uint32_t ctrl_set =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_PQCSR); + uint32_t ctrl_clr; + bool enable =3D !!(ctrl_set & RISCV_IOMMU_PQCSR_PQEN); + bool active =3D !!(ctrl_set & RISCV_IOMMU_PQCSR_PQON); + + if (enable && !active) { + base =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_PQB); + s->pq_mask =3D (2ULL << get_field(base, RISCV_IOMMU_PQB_LOG2SZ)) -= 1; + s->pq_addr =3D PPN_PHYS(get_field(base, RISCV_IOMMU_PQB_PPN)); + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_PQH], ~s->pq_mask); + stl_le_p(&s->regs_rw[RISCV_IOMMU_REG_PQH], 0); + stl_le_p(&s->regs_rw[RISCV_IOMMU_REG_PQT], 0); + ctrl_set =3D RISCV_IOMMU_PQCSR_PQON; + ctrl_clr =3D RISCV_IOMMU_PQCSR_BUSY | RISCV_IOMMU_PQCSR_PQMF | + RISCV_IOMMU_PQCSR_PQOF; + } else if (!enable && active) { + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_PQH], ~0); + ctrl_set =3D 0; + ctrl_clr =3D RISCV_IOMMU_PQCSR_BUSY | RISCV_IOMMU_PQCSR_PQON; + } else { + ctrl_set =3D 0; + ctrl_clr =3D RISCV_IOMMU_PQCSR_BUSY; + } + + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_PQCSR, ctrl_set, ctrl_clr); +} + +typedef void riscv_iommu_process_fn(RISCVIOMMUState *s); + +static void riscv_iommu_update_icvec(RISCVIOMMUState *s, uint64_t data) +{ + uint64_t icvec =3D 0; + + icvec |=3D MIN(data & RISCV_IOMMU_ICVEC_CIV, + s->icvec_avail_vectors & RISCV_IOMMU_ICVEC_CIV); + + icvec |=3D MIN(data & RISCV_IOMMU_ICVEC_FIV, + s->icvec_avail_vectors & RISCV_IOMMU_ICVEC_FIV); + + icvec |=3D MIN(data & RISCV_IOMMU_ICVEC_PMIV, + s->icvec_avail_vectors & RISCV_IOMMU_ICVEC_PMIV); + + icvec |=3D MIN(data & RISCV_IOMMU_ICVEC_PIV, + s->icvec_avail_vectors & RISCV_IOMMU_ICVEC_PIV); + + trace_riscv_iommu_icvec_write(data, icvec); + + riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_ICVEC, icvec); +} + +static void riscv_iommu_update_ipsr(RISCVIOMMUState *s, uint64_t data) +{ + uint32_t cqcsr, fqcsr, pqcsr; + uint32_t ipsr_set =3D 0; + uint32_t ipsr_clr =3D 0; + + if (data & RISCV_IOMMU_IPSR_CIP) { + cqcsr =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_CQCSR); + + if (cqcsr & RISCV_IOMMU_CQCSR_CIE && + (cqcsr & RISCV_IOMMU_CQCSR_FENCE_W_IP || + cqcsr & RISCV_IOMMU_CQCSR_CMD_ILL || + cqcsr & RISCV_IOMMU_CQCSR_CMD_TO || + cqcsr & RISCV_IOMMU_CQCSR_CQMF)) { + ipsr_set |=3D RISCV_IOMMU_IPSR_CIP; + } else { + ipsr_clr |=3D RISCV_IOMMU_IPSR_CIP; + } + } else { + ipsr_clr |=3D RISCV_IOMMU_IPSR_CIP; + } + + if (data & RISCV_IOMMU_IPSR_FIP) { + fqcsr =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FQCSR); + + if (fqcsr & RISCV_IOMMU_FQCSR_FIE && + (fqcsr & RISCV_IOMMU_FQCSR_FQOF || + fqcsr & RISCV_IOMMU_FQCSR_FQMF)) { + ipsr_set |=3D RISCV_IOMMU_IPSR_FIP; + } else { + ipsr_clr |=3D RISCV_IOMMU_IPSR_FIP; + } + } else { + ipsr_clr |=3D RISCV_IOMMU_IPSR_FIP; + } + + if (data & RISCV_IOMMU_IPSR_PIP) { + pqcsr =3D riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_PQCSR); + + if (pqcsr & RISCV_IOMMU_PQCSR_PIE && + (pqcsr & RISCV_IOMMU_PQCSR_PQOF || + pqcsr & RISCV_IOMMU_PQCSR_PQMF)) { + ipsr_set |=3D RISCV_IOMMU_IPSR_PIP; + } else { + ipsr_clr |=3D RISCV_IOMMU_IPSR_PIP; + } + } else { + ipsr_clr |=3D RISCV_IOMMU_IPSR_PIP; + } + + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IPSR, ipsr_set, ipsr_clr); +} + +static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size, MemTxAttrs attrs) +{ + riscv_iommu_process_fn *process_fn =3D NULL; + RISCVIOMMUState *s =3D opaque; + uint32_t regb =3D addr & ~3; + uint32_t busy =3D 0; + uint64_t val =3D 0; + + if ((addr & (size - 1)) !=3D 0) { + /* Unsupported MMIO alignment or access size */ + return MEMTX_ERROR; + } + + if (addr + size > RISCV_IOMMU_REG_MSI_CONFIG) { + /* Unsupported MMIO access location. */ + return MEMTX_ACCESS_ERROR; + } + + /* Track actionable MMIO write. */ + switch (regb) { + case RISCV_IOMMU_REG_DDTP: + case RISCV_IOMMU_REG_DDTP + 4: + process_fn =3D riscv_iommu_process_ddtp; + regb =3D RISCV_IOMMU_REG_DDTP; + busy =3D RISCV_IOMMU_DDTP_BUSY; + break; + + case RISCV_IOMMU_REG_CQT: + process_fn =3D riscv_iommu_process_cq_tail; + break; + + case RISCV_IOMMU_REG_CQCSR: + process_fn =3D riscv_iommu_process_cq_control; + busy =3D RISCV_IOMMU_CQCSR_BUSY; + break; + + case RISCV_IOMMU_REG_FQCSR: + process_fn =3D riscv_iommu_process_fq_control; + busy =3D RISCV_IOMMU_FQCSR_BUSY; + break; + + case RISCV_IOMMU_REG_PQCSR: + process_fn =3D riscv_iommu_process_pq_control; + busy =3D RISCV_IOMMU_PQCSR_BUSY; + break; + + case RISCV_IOMMU_REG_ICVEC: + case RISCV_IOMMU_REG_IPSR: + /* + * ICVEC and IPSR have special read/write procedures. We'll + * call their respective helpers and exit. + */ + qemu_spin_lock(&s->regs_lock); + + if (size =3D=3D 4) { + uint32_t ro =3D ldl_le_p(&s->regs_ro[addr]); + uint32_t wc =3D ldl_le_p(&s->regs_wc[addr]); + uint32_t rw =3D ldl_le_p(&s->regs_rw[addr]); + stl_le_p(&val, ((rw & ro) | (data & ~ro)) & ~(data & wc)); + } else if (size =3D=3D 8) { + uint64_t ro =3D ldq_le_p(&s->regs_ro[addr]); + uint64_t wc =3D ldq_le_p(&s->regs_wc[addr]); + uint64_t rw =3D ldq_le_p(&s->regs_rw[addr]); + stq_le_p(&val, ((rw & ro) | (data & ~ro)) & ~(data & wc)); + } + + qemu_spin_unlock(&s->regs_lock); + + if (regb =3D=3D RISCV_IOMMU_REG_ICVEC) { + riscv_iommu_update_icvec(s, val); + } else { + riscv_iommu_update_ipsr(s, val); + } + + return MEMTX_OK; + + default: + break; + } + + /* + * Registers update might be not synchronized with core logic. + * If system software updates register when relevant BUSY bit + * is set IOMMU behavior of additional writes to the register + * is UNSPECIFIED. + */ + qemu_spin_lock(&s->regs_lock); + if (size =3D=3D 1) { + uint8_t ro =3D s->regs_ro[addr]; + uint8_t wc =3D s->regs_wc[addr]; + uint8_t rw =3D s->regs_rw[addr]; + s->regs_rw[addr] =3D ((rw & ro) | (data & ~ro)) & ~(data & wc); + } else if (size =3D=3D 2) { + uint16_t ro =3D lduw_le_p(&s->regs_ro[addr]); + uint16_t wc =3D lduw_le_p(&s->regs_wc[addr]); + uint16_t rw =3D lduw_le_p(&s->regs_rw[addr]); + stw_le_p(&s->regs_rw[addr], ((rw & ro) | (data & ~ro)) & ~(data & = wc)); + } else if (size =3D=3D 4) { + uint32_t ro =3D ldl_le_p(&s->regs_ro[addr]); + uint32_t wc =3D ldl_le_p(&s->regs_wc[addr]); + uint32_t rw =3D ldl_le_p(&s->regs_rw[addr]); + stl_le_p(&s->regs_rw[addr], ((rw & ro) | (data & ~ro)) & ~(data & = wc)); + } else if (size =3D=3D 8) { + uint64_t ro =3D ldq_le_p(&s->regs_ro[addr]); + uint64_t wc =3D ldq_le_p(&s->regs_wc[addr]); + uint64_t rw =3D ldq_le_p(&s->regs_rw[addr]); + stq_le_p(&s->regs_rw[addr], ((rw & ro) | (data & ~ro)) & ~(data & = wc)); + } + + /* Busy flag update, MSB 4-byte register. */ + if (busy) { + uint32_t rw =3D ldl_le_p(&s->regs_rw[regb]); + stl_le_p(&s->regs_rw[regb], rw | busy); + } + qemu_spin_unlock(&s->regs_lock); + + if (process_fn) { + qemu_mutex_lock(&s->core_lock); + process_fn(s); + qemu_mutex_unlock(&s->core_lock); + } + + return MEMTX_OK; +} + +static MemTxResult riscv_iommu_mmio_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, MemTxAttrs attrs) +{ + RISCVIOMMUState *s =3D opaque; + uint64_t val =3D -1; + uint8_t *ptr; + + if ((addr & (size - 1)) !=3D 0) { + /* Unsupported MMIO alignment. */ + return MEMTX_ERROR; + } + + if (addr + size > RISCV_IOMMU_REG_MSI_CONFIG) { + return MEMTX_ACCESS_ERROR; + } + + ptr =3D &s->regs_rw[addr]; + + if (size =3D=3D 1) { + val =3D (uint64_t)*ptr; + } else if (size =3D=3D 2) { + val =3D lduw_le_p(ptr); + } else if (size =3D=3D 4) { + val =3D ldl_le_p(ptr); + } else if (size =3D=3D 8) { + val =3D ldq_le_p(ptr); + } else { + return MEMTX_ERROR; + } + + *data =3D val; + + return MEMTX_OK; +} + +static const MemoryRegionOps riscv_iommu_mmio_ops =3D { + .read_with_attrs =3D riscv_iommu_mmio_read, + .write_with_attrs =3D riscv_iommu_mmio_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + .unaligned =3D false, + }, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + } +}; + +/* + * Translations matching MSI pattern check are redirected to "riscv-iommu-= trap" + * memory region as untranslated address, for additional MSI/MRIF intercep= tion + * by IOMMU interrupt remapping implementation. + * Note: Device emulation code generating an MSI is expected to provide a = valid + * memory transaction attributes with requested_id set. + */ +static MemTxResult riscv_iommu_trap_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size, MemTxAttrs attrs) +{ + RISCVIOMMUState* s =3D (RISCVIOMMUState *)opaque; + RISCVIOMMUContext *ctx; + MemTxResult res; + void *ref; + uint32_t devid =3D attrs.requester_id; + + if (attrs.unspecified) { + return MEMTX_ACCESS_ERROR; + } + + /* FIXME: PCIe bus remapping for attached endpoints. */ + devid |=3D s->bus << 8; + + ctx =3D riscv_iommu_ctx(s, devid, 0, &ref); + if (ctx =3D=3D NULL) { + res =3D MEMTX_ACCESS_ERROR; + } else { + res =3D riscv_iommu_msi_write(s, ctx, addr, data, size, attrs); + } + riscv_iommu_ctx_put(s, ref); + return res; +} + +static MemTxResult riscv_iommu_trap_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, MemTxAttrs attrs) +{ + return MEMTX_ACCESS_ERROR; +} + +static const MemoryRegionOps riscv_iommu_trap_ops =3D { + .read_with_attrs =3D riscv_iommu_trap_read, + .write_with_attrs =3D riscv_iommu_trap_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + .unaligned =3D true, + }, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + } +}; + +static void riscv_iommu_realize(DeviceState *dev, Error **errp) +{ + RISCVIOMMUState *s =3D RISCV_IOMMU(dev); + + s->cap =3D s->version & RISCV_IOMMU_CAP_VERSION; + if (s->enable_msi) { + s->cap |=3D RISCV_IOMMU_CAP_MSI_FLAT | RISCV_IOMMU_CAP_MSI_MRIF; + } + if (s->enable_s_stage) { + s->cap |=3D RISCV_IOMMU_CAP_SV32 | RISCV_IOMMU_CAP_SV39 | + RISCV_IOMMU_CAP_SV48 | RISCV_IOMMU_CAP_SV57; + } + if (s->enable_g_stage) { + s->cap |=3D RISCV_IOMMU_CAP_SV32X4 | RISCV_IOMMU_CAP_SV39X4 | + RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4; + } + /* Report QEMU target physical address space limits */ + s->cap =3D set_field(s->cap, RISCV_IOMMU_CAP_PAS, + TARGET_PHYS_ADDR_SPACE_BITS); + + /* TODO: method to report supported PID bits */ + s->pid_bits =3D 8; /* restricted to size of MemTxAttrs.pid */ + s->cap |=3D RISCV_IOMMU_CAP_PD8; + + /* Out-of-reset translation mode: OFF (DMA disabled) BARE (passthrough= ) */ + s->ddtp =3D set_field(0, RISCV_IOMMU_DDTP_MODE, s->enable_off ? + RISCV_IOMMU_DDTP_MODE_OFF : RISCV_IOMMU_DDTP_MODE_= BARE); + + /* register storage */ + s->regs_rw =3D g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); + s->regs_ro =3D g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); + s->regs_wc =3D g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); + + /* Mark all registers read-only */ + memset(s->regs_ro, 0xff, RISCV_IOMMU_REG_SIZE); + + /* + * Register complete MMIO space, including MSI/PBA registers. + * Note, PCIDevice implementation will add overlapping MR for MSI/PBA, + * managed directly by the PCIDevice implementation. + */ + memory_region_init_io(&s->regs_mr, OBJECT(dev), &riscv_iommu_mmio_ops,= s, + "riscv-iommu-regs", RISCV_IOMMU_REG_SIZE); + + /* Set power-on register state */ + stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_CAP], s->cap); + stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_FCTL], 0); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_FCTL], + ~(RISCV_IOMMU_FCTL_BE | RISCV_IOMMU_FCTL_WSI)); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_DDTP], + ~(RISCV_IOMMU_DDTP_PPN | RISCV_IOMMU_DDTP_MODE)); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_CQB], + ~(RISCV_IOMMU_CQB_LOG2SZ | RISCV_IOMMU_CQB_PPN)); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_FQB], + ~(RISCV_IOMMU_FQB_LOG2SZ | RISCV_IOMMU_FQB_PPN)); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_PQB], + ~(RISCV_IOMMU_PQB_LOG2SZ | RISCV_IOMMU_PQB_PPN)); + stl_le_p(&s->regs_wc[RISCV_IOMMU_REG_CQCSR], RISCV_IOMMU_CQCSR_CQMF | + RISCV_IOMMU_CQCSR_CMD_TO | RISCV_IOMMU_CQCSR_CMD_ILL); + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_CQCSR], RISCV_IOMMU_CQCSR_CQON | + RISCV_IOMMU_CQCSR_BUSY); + stl_le_p(&s->regs_wc[RISCV_IOMMU_REG_FQCSR], RISCV_IOMMU_FQCSR_FQMF | + RISCV_IOMMU_FQCSR_FQOF); + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_FQCSR], RISCV_IOMMU_FQCSR_FQON | + RISCV_IOMMU_FQCSR_BUSY); + stl_le_p(&s->regs_wc[RISCV_IOMMU_REG_PQCSR], RISCV_IOMMU_PQCSR_PQMF | + RISCV_IOMMU_PQCSR_PQOF); + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_PQCSR], RISCV_IOMMU_PQCSR_PQON | + RISCV_IOMMU_PQCSR_BUSY); + stl_le_p(&s->regs_wc[RISCV_IOMMU_REG_IPSR], ~0); + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_ICVEC], 0); + stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_DDTP], s->ddtp); + + /* Memory region for downstream access, if specified. */ + if (s->target_mr) { + s->target_as =3D g_new0(AddressSpace, 1); + address_space_init(s->target_as, s->target_mr, + "riscv-iommu-downstream"); + } else { + /* Fallback to global system memory. */ + s->target_as =3D &address_space_memory; + } + + /* Memory region for untranslated MRIF/MSI writes */ + memory_region_init_io(&s->trap_mr, OBJECT(dev), &riscv_iommu_trap_ops,= s, + "riscv-iommu-trap", ~0ULL); + address_space_init(&s->trap_as, &s->trap_mr, "riscv-iommu-trap-as"); + + /* Device translation context cache */ + s->ctx_cache =3D g_hash_table_new_full(__ctx_hash, __ctx_equal, + g_free, NULL); + qemu_mutex_init(&s->ctx_lock); + + s->iommus.le_next =3D NULL; + s->iommus.le_prev =3D NULL; + QLIST_INIT(&s->spaces); + qemu_mutex_init(&s->core_lock); + qemu_spin_init(&s->regs_lock); +} + +static void riscv_iommu_unrealize(DeviceState *dev) +{ + RISCVIOMMUState *s =3D RISCV_IOMMU(dev); + + qemu_mutex_destroy(&s->core_lock); + g_hash_table_unref(s->ctx_cache); +} + +static Property riscv_iommu_properties[] =3D { + DEFINE_PROP_UINT32("version", RISCVIOMMUState, version, + RISCV_IOMMU_SPEC_DOT_VER), + DEFINE_PROP_UINT32("bus", RISCVIOMMUState, bus, 0x0), + DEFINE_PROP_BOOL("intremap", RISCVIOMMUState, enable_msi, TRUE), + DEFINE_PROP_BOOL("off", RISCVIOMMUState, enable_off, TRUE), + DEFINE_PROP_BOOL("s-stage", RISCVIOMMUState, enable_s_stage, TRUE), + DEFINE_PROP_BOOL("g-stage", RISCVIOMMUState, enable_g_stage, TRUE), + DEFINE_PROP_LINK("downstream-mr", RISCVIOMMUState, target_mr, + TYPE_MEMORY_REGION, MemoryRegion *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void riscv_iommu_class_init(ObjectClass *klass, void* data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + /* internal device for riscv-iommu-{pci/sys}, not user-creatable */ + dc->user_creatable =3D false; + dc->realize =3D riscv_iommu_realize; + dc->unrealize =3D riscv_iommu_unrealize; + device_class_set_props(dc, riscv_iommu_properties); +} + +static const TypeInfo riscv_iommu_info =3D { + .name =3D TYPE_RISCV_IOMMU, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(RISCVIOMMUState), + .class_init =3D riscv_iommu_class_init, +}; + +static const char *IOMMU_FLAG_STR[] =3D { + "NA", + "RO", + "WR", + "RW", +}; + +/* RISC-V IOMMU Memory Region - Address Translation Space */ +static IOMMUTLBEntry riscv_iommu_memory_region_translate( + IOMMUMemoryRegion *iommu_mr, hwaddr addr, + IOMMUAccessFlags flag, int iommu_idx) +{ + RISCVIOMMUSpace *as =3D container_of(iommu_mr, RISCVIOMMUSpace, iova_m= r); + RISCVIOMMUContext *ctx; + void *ref; + IOMMUTLBEntry iotlb =3D { + .iova =3D addr, + .target_as =3D as->iommu->target_as, + .addr_mask =3D ~0ULL, + .perm =3D flag, + }; + + ctx =3D riscv_iommu_ctx(as->iommu, as->devid, iommu_idx, &ref); + if (ctx =3D=3D NULL) { + /* Translation disabled or invalid. */ + iotlb.addr_mask =3D 0; + iotlb.perm =3D IOMMU_NONE; + } else if (riscv_iommu_translate(as->iommu, ctx, &iotlb)) { + /* Translation disabled or fault reported. */ + iotlb.addr_mask =3D 0; + iotlb.perm =3D IOMMU_NONE; + } + + /* Trace all dma translations with original access flags. */ + trace_riscv_iommu_dma(as->iommu->parent_obj.id, PCI_BUS_NUM(as->devid), + PCI_SLOT(as->devid), PCI_FUNC(as->devid), iommu_= idx, + IOMMU_FLAG_STR[flag & IOMMU_RW], iotlb.iova, + iotlb.translated_addr); + + riscv_iommu_ctx_put(as->iommu, ref); + + return iotlb; +} + +static int riscv_iommu_memory_region_notify( + IOMMUMemoryRegion *iommu_mr, IOMMUNotifierFlag old, + IOMMUNotifierFlag new, Error **errp) +{ + RISCVIOMMUSpace *as =3D container_of(iommu_mr, RISCVIOMMUSpace, iova_m= r); + + if (old =3D=3D IOMMU_NOTIFIER_NONE) { + as->notifier =3D true; + trace_riscv_iommu_notifier_add(iommu_mr->parent_obj.name); + } else if (new =3D=3D IOMMU_NOTIFIER_NONE) { + as->notifier =3D false; + trace_riscv_iommu_notifier_del(iommu_mr->parent_obj.name); + } + + return 0; +} + +static inline bool pci_is_iommu(PCIDevice *pdev) +{ + return pci_get_word(pdev->config + PCI_CLASS_DEVICE) =3D=3D 0x0806; +} + +static AddressSpace *riscv_iommu_find_as(PCIBus *bus, void *opaque, int de= vfn) +{ + RISCVIOMMUState *s =3D (RISCVIOMMUState *) opaque; + PCIDevice *pdev =3D pci_find_device(bus, pci_bus_num(bus), devfn); + AddressSpace *as =3D NULL; + + if (pdev && pci_is_iommu(pdev)) { + return s->target_as; + } + + /* Find first registered IOMMU device */ + while (s->iommus.le_prev) { + s =3D *(s->iommus.le_prev); + } + + /* Find first matching IOMMU */ + while (s !=3D NULL && as =3D=3D NULL) { + as =3D riscv_iommu_space(s, PCI_BUILD_BDF(pci_bus_num(bus), devfn)= ); + s =3D s->iommus.le_next; + } + + return as ? as : &address_space_memory; +} + +static const PCIIOMMUOps riscv_iommu_ops =3D { + .get_address_space =3D riscv_iommu_find_as, +}; + +void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, + Error **errp) +{ + if (bus->iommu_ops && + bus->iommu_ops->get_address_space =3D=3D riscv_iommu_find_as) { + /* Allow multiple IOMMUs on the same PCIe bus, link known devices = */ + RISCVIOMMUState *last =3D (RISCVIOMMUState *)bus->iommu_opaque; + QLIST_INSERT_AFTER(last, iommu, iommus); + } else if (!bus->iommu_ops && !bus->iommu_opaque) { + pci_setup_iommu(bus, &riscv_iommu_ops, iommu); + } else { + error_setg(errp, "can't register secondary IOMMU for PCI bus #%d", + pci_bus_num(bus)); + } +} + +static int riscv_iommu_memory_region_index(IOMMUMemoryRegion *iommu_mr, + MemTxAttrs attrs) +{ + return attrs.unspecified ? RISCV_IOMMU_NOPROCID : (int)attrs.pid; +} + +static int riscv_iommu_memory_region_index_len(IOMMUMemoryRegion *iommu_mr) +{ + RISCVIOMMUSpace *as =3D container_of(iommu_mr, RISCVIOMMUSpace, iova_m= r); + return 1 << as->iommu->pid_bits; +} + +static void riscv_iommu_memory_region_init(ObjectClass *klass, void *data) +{ + IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_CLASS(klass); + + imrc->translate =3D riscv_iommu_memory_region_translate; + imrc->notify_flag_changed =3D riscv_iommu_memory_region_notify; + imrc->attrs_to_index =3D riscv_iommu_memory_region_index; + imrc->num_indexes =3D riscv_iommu_memory_region_index_len; +} + +static const TypeInfo riscv_iommu_memory_region_info =3D { + .parent =3D TYPE_IOMMU_MEMORY_REGION, + .name =3D TYPE_RISCV_IOMMU_MEMORY_REGION, + .class_init =3D riscv_iommu_memory_region_init, +}; + +static void riscv_iommu_register_mr_types(void) +{ + type_register_static(&riscv_iommu_memory_region_info); + type_register_static(&riscv_iommu_info); +} + +type_init(riscv_iommu_register_mr_types); diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index a2030e3a6f..f69d6e3c8e 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -1,3 +1,6 @@ +config RISCV_IOMMU + bool + config RISCV_NUMA bool =20 @@ -47,6 +50,7 @@ config RISCV_VIRT select SERIAL select RISCV_ACLINT select RISCV_APLIC + select RISCV_IOMMU select RISCV_IMSIC select SIFIVE_PLIC select SIFIVE_TEST diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build index f872674093..cbc99c6e8e 100644 --- a/hw/riscv/meson.build +++ b/hw/riscv/meson.build @@ -10,5 +10,6 @@ riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sif= ive_u.c')) riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfs= oc.c')) riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) +riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c')) =20 hw_arch +=3D {'riscv': riscv_ss} diff --git a/hw/riscv/trace-events b/hw/riscv/trace-events new file mode 100644 index 0000000000..3d5c33102d --- /dev/null +++ b/hw/riscv/trace-events @@ -0,0 +1,14 @@ +# See documentation at docs/devel/tracing.rst + +# riscv-iommu.c +riscv_iommu_new(const char *id, unsigned b, unsigned d, unsigned f) "%s: d= evice attached %04x:%02x.%d" +riscv_iommu_flt(const char *id, unsigned b, unsigned d, unsigned f, uint64= _t reason, uint64_t iova) "%s: fault %04x:%02x.%u reason: 0x%"PRIx64" iova:= 0x%"PRIx64 +riscv_iommu_pri(const char *id, unsigned b, unsigned d, unsigned f, uint64= _t iova) "%s: page request %04x:%02x.%u iova: 0x%"PRIx64 +riscv_iommu_dma(const char *id, unsigned b, unsigned d, unsigned f, unsign= ed pasid, const char *dir, uint64_t iova, uint64_t phys) "%s: translate %04= x:%02x.%u #%u %s 0x%"PRIx64" -> 0x%"PRIx64 +riscv_iommu_msi(const char *id, unsigned b, unsigned d, unsigned f, uint64= _t iova, uint64_t phys) "%s: translate %04x:%02x.%u MSI 0x%"PRIx64" -> 0x%"= PRIx64 +riscv_iommu_mrif_notification(const char *id, uint32_t nid, uint64_t phys)= "%s: sent MRIF notification 0x%x to 0x%"PRIx64 +riscv_iommu_cmd(const char *id, uint64_t l, uint64_t u) "%s: command 0x%"P= RIx64" 0x%"PRIx64 +riscv_iommu_notifier_add(const char *id) "%s: dev-iotlb notifier added" +riscv_iommu_notifier_del(const char *id) "%s: dev-iotlb notifier removed" +riscv_iommu_notify_int_vector(uint32_t cause, uint32_t vector) "Interrupt = cause 0x%x sent via vector 0x%x" +riscv_iommu_icvec_write(uint32_t orig, uint32_t actual) "ICVEC write: inco= ming 0x%x actual 0x%x" --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119128; cv=none; d=zohomail.com; s=zohoarc; b=jvBPICI9RxB1FcvYiiVxK0jI9GnFxx1TWwAxfOU7AR4lLvljBDR0/lgwQ0YB1khd99BoIlDr71ydIezg1LOgy6HKWpJOfMsq+fDhxZrlSvV/9yN77gSPQm/5cpIxZFr7ijQRtKsnrsDw0TDmsKApnTwYLuudNru5cBMAZI1l8ro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119128; h=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=YbZqF++ZhMtcJDIF2/NlKZuD8jEV76FLyT7OsIr+hLI=; b=YeopjLyJEgqeQ1LilW0Gi0hBgWJm/fBusSnW5Lz5pb2jCLSrHDOuGL4mIsgvK9Sek2wWR0+IDqnsTL+OxIscahlr6bR/oMAkFjBqImWlkU7mV01aefF7FVlDd5LdyNk4/IbAFtZyMH34Ga9AyG4KpqjD8mtsKhT7iATx91aVc9I= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119128061830.1526256175387; Wed, 11 Sep 2024 22:32:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQ0-0002Xz-Sz; Thu, 12 Sep 2024 01:31:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socPx-0002Ix-2O for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:57 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socPu-00033W-Na for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:56 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-718d91eef2eso324443b3a.1 for ; Wed, 11 Sep 2024 22:30:54 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119053; x=1726723853; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YbZqF++ZhMtcJDIF2/NlKZuD8jEV76FLyT7OsIr+hLI=; b=MBla3g1hGX+Hqp8tnTAu2XBAVYzKnh2vpP9u7iWpYN19EEqAs26izWm7Ols7AIkpeN aG6oWo8MsJy5GpcG1PamASCr9Vojp4QFXQlUF6EvSvMAmecbBy0IG/UHYfCswNqxzxBY XWLROiCEjYSwaVyl2pRpSumIKS9queihYN/j1tgfOyUC9pOJyymgdfxfTgsvpDajhSB8 x4sA5TKo4dNoL4zaAhMEIIZve5x6kTCI3+T3pJQbOAawTZbBllvcXqMTvt1Y/kFKzqDA UadDYqrlwjEx/nl/qScJeC+F+W7NGwi3wDV13h59JExIhwssSzlfIkhXz3dc+B19oAqo VGLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119053; x=1726723853; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YbZqF++ZhMtcJDIF2/NlKZuD8jEV76FLyT7OsIr+hLI=; b=aKonrkjPZuXLIRYEtVMuYjefi/ilWYPhs48DZhQ319HT2UmHcrJ+LbXiVih0mCxNCU ur5b1dPcNRCWZvZINWCjNGt91Cagx/qFDWpsZgDY4549hiFdcNiyxygbfC8c1xZXMwgY ujfLIPocYemnO/DPRn//wKz5NFV/TJp01rGPtE74VLtkaSSldyLSFBlLSCrwlI+frc4v 1q7Vedjv8wGR94xSrjiF8IS6gLE3sRswTPq5snSnuz+l4a0Jg8PtytSfYBG8vLqvIaaL SPyseDS0wYEA/rZs56xi3RxzClsftwQqJfRsnBjBr2MFQQEyFijHi1LqFQftXzik3wsW KRjA== X-Gm-Message-State: AOJu0Yx4Ax0zPUPap8wORj3gyulYZcGokFW19mQtlT9huOsZTGWZRokO iRdlEveJpCW3b6dST8ICQe6q0s/AaY+acqNRU28JQIAOZrKffj8vzdIu5g== X-Google-Smtp-Source: AGHT+IHcWfo7Ib/qebmo2el2FLgk2tKIMEkpmiqAaKFM3ItvbYl1aiFIkUgovc8jiOgrJlO/g7heuw== X-Received: by 2002:a05:6a00:194b:b0:704:151d:dcce with SMTP id d2e1a72fcca58-719263cb4e2mr2662724b3a.5.1726119052670; Wed, 11 Sep 2024 22:30:52 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Gerd Hoffmann , Frank Chang , Alistair Francis Subject: [PULL 17/47] pci-ids.rst: add Red Hat pci-id for RISC-V IOMMU device Date: Thu, 12 Sep 2024 15:29:22 +1000 Message-ID: <20240912052953.2552501-18-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=alistair23@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119128398116600 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza The RISC-V IOMMU PCI device we're going to add next is a reference implementation of the riscv-iommu spec [1], which predicts that the IOMMU can be implemented as a PCIe device. However, RISC-V International (RVI), the entity that ratified the riscv-iommu spec, didn't bother assigning a PCI ID for this IOMMU PCIe implementation that the spec predicts. This puts us in an uncommon situation because we want to add the reference IOMMU PCIe implementation but we don't have a PCI ID for it. Given that RVI doesn't provide a PCI ID for it we reached out to Red Hat and Gerd Hoffman, and they were kind enough to give us a PCI ID for the RISC-V IOMMU PCI reference device. Thanks Red Hat and Gerd for this RISC-V IOMMU PCIe device ID. [1] https://github.com/riscv-non-isa/riscv-iommu/releases/tag/v1.0.0 Cc: Gerd Hoffmann Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Reviewed-by: Gerd Hoffmann Message-ID: <20240903201633.93182-5-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- docs/specs/pci-ids.rst | 2 ++ include/hw/pci/pci.h | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/specs/pci-ids.rst b/docs/specs/pci-ids.rst index 328ab31fe8..261b0f359f 100644 --- a/docs/specs/pci-ids.rst +++ b/docs/specs/pci-ids.rst @@ -98,6 +98,8 @@ PCI devices (other than virtio): PCI ACPI ERST device (``-device acpi-erst``) 1b36:0013 PCI UFS device (``-device ufs``) +1b36:0014 + PCI RISC-V IOMMU device =20 All these devices are documented in :doc:`index`. =20 diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index eb26cac810..35d4fe0bbf 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -116,6 +116,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0011 #define PCI_DEVICE_ID_REDHAT_ACPI_ERST 0x0012 #define PCI_DEVICE_ID_REDHAT_UFS 0x0013 +#define PCI_DEVICE_ID_REDHAT_RISCV_IOMMU 0x0014 #define PCI_DEVICE_ID_REDHAT_QXL 0x0100 =20 #define FMT_PCIBUS PRIx64 --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119665; cv=none; d=zohomail.com; s=zohoarc; b=bRkIvDATrQh2my52uxfVfsMInkud79ABGDcGDk7VUXcHhaD/g5EU+kWttmiloxaXwg2iL7XuYeMx1faQtJbA7bIVDGADLhw/uUxSf2CRt7k28Rq9ZY3/WQIm4GPgjqhZWOeblcCfv7hynUskYz7+sLq5AGQ7897Yl6Scrd0k5HY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119665; h=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=cNL4ebP42v/T0EQmBLUNhHTUGwhKOhNapIeT5SvV/ns=; b=HGhepf/jo9eJwY+HkTvh74+wSy4m9tRQX1fsiDp2U5bqvKuPndtgkF87j+Rbfec5W3l+uJpHegmSKL4FljUmT9U04r6eRGXfHYIynnjGoCvheTVCrxeUlhb+JHnYy3UtAez2G+xTL684gAEd0fKDwyqXz19sJqS8ggGE7il3yxs= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172611966576091.65952466969395; Wed, 11 Sep 2024 22:41:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQ2-0002f2-A3; Thu, 12 Sep 2024 01:31:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQ0-0002VU-7o for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:00 -0400 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 1socPy-00034F-0h for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:30:59 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-7c1324be8easo1191145a12.1 for ; Wed, 11 Sep 2024 22:30:57 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119056; x=1726723856; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cNL4ebP42v/T0EQmBLUNhHTUGwhKOhNapIeT5SvV/ns=; b=WIXScZ0DXXyuaQkOcLOCXAogz9Zpqk34QxOlkjt1GjsV+Q3QPdIh9ewz9vEBGgga5Q +Nwlp8j4ByUNRte6AJfyGc/4hlNhBdA/ckboh16H9r7ItQAMkCqnBzbI8DZr+YiglJXX 8/tnJx73tHPlR3YD9cHdhHnJBtgDidvn6NcwutYUBMercoRPGpU9QoCYBUsysGAdgq1F YugPsqDdxiYuWnYj+QECZDBf6X3kuwXDB02EKGapsg8EyCOsh390zk3CFwtSLPHpqbof 73D+oDwP6TdeQR2tQcbqVOkkYPUwP+lmqYcbUpS4tUq1CRUxKrouTTuaVuMKNAsvcfUL OGRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119056; x=1726723856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cNL4ebP42v/T0EQmBLUNhHTUGwhKOhNapIeT5SvV/ns=; b=C2sdA+r3M8si/wLlt49WIj744g2W30vgDfYHYDfO7ON/EUu4bLsdeLtjwssKZkCQ+S kK1mFcbNgf+QFTvlL01zw0ydtjz+D/zbbyIRt2gjZJKNy6F0p3vIxbnuXb2SYJzqLIPT G5RSxr7v3rotAtv7T804J3mYJYgiTNOx4P+vDwCrYZ1ljG7m5DQDTJ1EgzNzjS1sg04Q mig/UTy4I8ArECqIS8oko65iil1j2TEKv6pUZVGxijaGijMGi4RMQiBFmM/GnCRuHihU rc7oEDFHOJdZZuJtYgQPgVTPsBoFCZfbToDi6yxHqqPvAC10j3HiTdU8Q9kzfz9WPODR V9Hg== X-Gm-Message-State: AOJu0Yw+tBM1FObGQv/FzhQzcu8BKXzuLSfSDZQFCYIKw+foJqtHbEO9 AT1kYy18wgNIqFGMp6jLoziTEwDlPn2haMRb/2kEMxMfk9mXTACYEbyD5w== X-Google-Smtp-Source: AGHT+IFx21/lO/7y9SIy8QE6kpdY8kyL4ozDq4L6YkoD6DJ9zwWC3DMmlzyAxyEpyWSLq30E9olw+A== X-Received: by 2002:a05:6a20:c70b:b0:1cf:359b:1a31 with SMTP id adf61e73a8af0-1cf756c404bmr2740966637.19.1726119055940; Wed, 11 Sep 2024 22:30:55 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 18/47] hw/riscv: add riscv-iommu-pci reference device Date: Thu, 12 Sep 2024 15:29:23 +1000 Message-ID: <20240912052953.2552501-19-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=alistair23@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119667528116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach The RISC-V IOMMU can be modelled as a PCIe device following the guidelines of the RISC-V IOMMU spec, chapter 7.1, "Integrating an IOMMU as a PCIe device". Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Reviewed-by: Alistair Francis Message-ID: <20240903201633.93182-6-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/riscv-iommu-pci.c | 202 +++++++++++++++++++++++++++++++++++++ hw/riscv/meson.build | 2 +- 2 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 hw/riscv/riscv-iommu-pci.c diff --git a/hw/riscv/riscv-iommu-pci.c b/hw/riscv/riscv-iommu-pci.c new file mode 100644 index 0000000000..6be6bc7383 --- /dev/null +++ b/hw/riscv/riscv-iommu-pci.c @@ -0,0 +1,202 @@ +/* + * QEMU emulation of an RISC-V IOMMU + * + * Copyright (C) 2022-2023 Rivos Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/pci/msi.h" +#include "hw/pci/msix.h" +#include "hw/pci/pci_bus.h" +#include "hw/qdev-properties.h" +#include "hw/riscv/riscv_hart.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/host-utils.h" +#include "qom/object.h" + +#include "cpu_bits.h" +#include "riscv-iommu.h" +#include "riscv-iommu-bits.h" + +/* RISC-V IOMMU PCI Device Emulation */ +#define RISCV_PCI_CLASS_SYSTEM_IOMMU 0x0806 + +/* + * 4 MSIx vectors for ICVEC, one for MRIF. The spec mentions in + * the "Placement and data flow" section that: + * + * "The interfaces related to recording an incoming MSI in a memory-reside= nt + * interrupt file (MRIF) are implementation-specific. The partitioning of + * responsibility between the IOMMU and the IO bridge for recording the + * incoming MSI in an MRIF and generating the associated notice MSI are + * implementation-specific." + * + * We're making a design decision to create the MSIx for MRIF in the + * IOMMU MSIx emulation. + */ +#define RISCV_IOMMU_PCI_MSIX_VECTORS 5 + +/* + * 4 vectors that can be used by civ, fiv, pmiv and piv. Number of + * vectors is represented by 2^N, where N =3D number of writable bits + * in each cause. For 4 vectors we'll write 0b11 (3) in each reg. + */ +#define RISCV_IOMMU_PCI_ICVEC_VECTORS 0x3333 + +typedef struct RISCVIOMMUStatePci { + PCIDevice pci; /* Parent PCIe device state */ + uint16_t vendor_id; + uint16_t device_id; + uint8_t revision; + MemoryRegion bar0; /* PCI BAR (including MSI-x config) */ + RISCVIOMMUState iommu; /* common IOMMU state */ +} RISCVIOMMUStatePci; + +/* interrupt delivery callback */ +static void riscv_iommu_pci_notify(RISCVIOMMUState *iommu, unsigned vector) +{ + RISCVIOMMUStatePci *s =3D container_of(iommu, RISCVIOMMUStatePci, iomm= u); + + if (msix_enabled(&(s->pci))) { + msix_notify(&(s->pci), vector); + } +} + +static void riscv_iommu_pci_realize(PCIDevice *dev, Error **errp) +{ + RISCVIOMMUStatePci *s =3D DO_UPCAST(RISCVIOMMUStatePci, pci, dev); + RISCVIOMMUState *iommu =3D &s->iommu; + uint8_t *pci_conf =3D dev->config; + Error *err =3D NULL; + + pci_set_word(pci_conf + PCI_VENDOR_ID, s->vendor_id); + pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, s->vendor_id); + pci_set_word(pci_conf + PCI_DEVICE_ID, s->device_id); + pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, s->device_id); + pci_set_byte(pci_conf + PCI_REVISION_ID, s->revision); + + /* Set device id for trace / debug */ + DEVICE(iommu)->id =3D g_strdup_printf("%02x:%02x.%01x", + pci_dev_bus_num(dev), PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); + qdev_realize(DEVICE(iommu), NULL, errp); + + memory_region_init(&s->bar0, OBJECT(s), "riscv-iommu-bar0", + QEMU_ALIGN_UP(memory_region_size(&iommu->regs_mr), TARGET_PAGE_SIZ= E)); + memory_region_add_subregion(&s->bar0, 0, &iommu->regs_mr); + + pcie_endpoint_cap_init(dev, 0); + + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_TYPE_64, &s->bar0); + + int ret =3D msix_init(dev, RISCV_IOMMU_PCI_MSIX_VECTORS, + &s->bar0, 0, RISCV_IOMMU_REG_MSI_CONFIG, + &s->bar0, 0, RISCV_IOMMU_REG_MSI_CONFIG + 256, 0, = &err); + + if (ret =3D=3D -ENOTSUP) { + /* + * MSI-x is not supported by the platform. + * Driver should use timer/polling based notification handlers. + */ + warn_report_err(err); + } else if (ret < 0) { + error_propagate(errp, err); + return; + } else { + /* Mark all ICVEC MSIx vectors as used */ + for (int i =3D 0; i < RISCV_IOMMU_PCI_MSIX_VECTORS; i++) { + msix_vector_use(dev, i); + } + + iommu->notify =3D riscv_iommu_pci_notify; + } + + PCIBus *bus =3D pci_device_root_bus(dev); + if (!bus) { + error_setg(errp, "can't find PCIe root port for %02x:%02x.%x", + pci_bus_num(pci_get_bus(dev)), PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); + return; + } + + riscv_iommu_pci_setup_iommu(iommu, bus, errp); +} + +static void riscv_iommu_pci_exit(PCIDevice *pci_dev) +{ + pci_setup_iommu(pci_device_root_bus(pci_dev), NULL, NULL); +} + +static const VMStateDescription riscv_iommu_vmstate =3D { + .name =3D "riscv-iommu", + .unmigratable =3D 1 +}; + +static void riscv_iommu_pci_init(Object *obj) +{ + RISCVIOMMUStatePci *s =3D RISCV_IOMMU_PCI(obj); + RISCVIOMMUState *iommu =3D &s->iommu; + + object_initialize_child(obj, "iommu", iommu, TYPE_RISCV_IOMMU); + qdev_alias_all_properties(DEVICE(iommu), obj); + + iommu->icvec_avail_vectors =3D RISCV_IOMMU_PCI_ICVEC_VECTORS; +} + +static Property riscv_iommu_pci_properties[] =3D { + DEFINE_PROP_UINT16("vendor-id", RISCVIOMMUStatePci, vendor_id, + PCI_VENDOR_ID_REDHAT), + DEFINE_PROP_UINT16("device-id", RISCVIOMMUStatePci, device_id, + PCI_DEVICE_ID_REDHAT_RISCV_IOMMU), + DEFINE_PROP_UINT8("revision", RISCVIOMMUStatePci, revision, 0x01), + DEFINE_PROP_END_OF_LIST(), +}; + +static void riscv_iommu_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + + k->realize =3D riscv_iommu_pci_realize; + k->exit =3D riscv_iommu_pci_exit; + k->class_id =3D RISCV_PCI_CLASS_SYSTEM_IOMMU; + dc->desc =3D "RISCV-IOMMU DMA Remapping device"; + dc->vmsd =3D &riscv_iommu_vmstate; + dc->hotpluggable =3D false; + dc->user_creatable =3D true; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, riscv_iommu_pci_properties); +} + +static const TypeInfo riscv_iommu_pci =3D { + .name =3D TYPE_RISCV_IOMMU_PCI, + .parent =3D TYPE_PCI_DEVICE, + .class_init =3D riscv_iommu_pci_class_init, + .instance_init =3D riscv_iommu_pci_init, + .instance_size =3D sizeof(RISCVIOMMUStatePci), + .interfaces =3D (InterfaceInfo[]) { + { INTERFACE_PCIE_DEVICE }, + { }, + }, +}; + +static void riscv_iommu_register_pci_types(void) +{ + type_register_static(&riscv_iommu_pci); +} + +type_init(riscv_iommu_register_pci_types); diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build index cbc99c6e8e..adbef8a9b2 100644 --- a/hw/riscv/meson.build +++ b/hw/riscv/meson.build @@ -10,6 +10,6 @@ riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sif= ive_u.c')) riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfs= oc.c')) riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) -riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c')) +riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c', '= riscv-iommu-pci.c')) =20 hw_arch +=3D {'riscv': riscv_ss} --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119240; cv=none; d=zohomail.com; s=zohoarc; b=nRLHHmQh0wbcitREVYvjU0jwCSwqypXT5CNF+Al99qmah+vMowRqh1z78HjBK5QAzPHgbaXOIU/pforNMADXD5zpQDqHAD5F4q1fSrJkkN72GSG8xGx6XTaN0RLb3Da2+YgS3evv2F0TfGFZ+AW4WdaJrmEnu7jfFVOAjfA4bf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119240; h=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=Vpqv3/ZDv8FKVW4tPIQmJ+l/8/cnMP9HRshZ49Evbfs=; b=mJ2v4MdJHR48hOKJvVOhjesHZt2JlEZ0JIDZwBZzSkx1gv1vZR816/cEmtCRBAYPVlcYddidJjOy6oxGtMHZuK6WFTK5wopwOH8zLbxWBTJId6jGTjbNuAw/Bib2GQ6LPVORlPXEgU1BKe3O/qwniSbd+Cn9P+aMCt77rvV260A= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119240622387.9136652348228; Wed, 11 Sep 2024 22:34:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQ5-0002qT-TK; Thu, 12 Sep 2024 01:31:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQ2-0002g2-Gj for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:02 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQ0-00034R-SF for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:02 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-6e7b121be30so426774a12.1 for ; Wed, 11 Sep 2024 22:31:00 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119059; x=1726723859; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vpqv3/ZDv8FKVW4tPIQmJ+l/8/cnMP9HRshZ49Evbfs=; b=JZYHhL3MjaA4SvQbN1ol2cVM52HsBLWJs2e3DlJafZlrAP/pnB4h936KQqfJ6FWiqt odYPvfc3odLd8DjZ4RY2QZHyH0oEPlz7BEdeCr43oan3IXPZGAZY9v7WydUBpL0EzBee rMHHXLyQOT4xSY9j+P/nSWvkf77LmxmBxr6rNu4n6YgWVtJTXVsvadDjZqjCuA9iM2fi KkmcBAebrpzm4GDHpQ70ppcG8joI86oiEP3GoJ+nMLpGsM/2vOmkH4pBR82YuPDBPx8f o1pwsAlwKgecjzh50+GwAL5LnJydJsRXIPqZysVAzTKJcNhr5pd0fE77BYlALYZsajsc virQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119059; x=1726723859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vpqv3/ZDv8FKVW4tPIQmJ+l/8/cnMP9HRshZ49Evbfs=; b=dn3sPnWTvDbdQaV8Qn2saTgBUNCvgLR2+1z0qg9ccgvJjqIxdVYjJdKxDiCgtxbCjQ CFnQfUCd2S5vUim+N5DsfcZUyo1gJb4R1xREonZn+3rANGehXXTV7o63RoIxQ9pEiRdb rr0VKWNrYi+JtpFazGGgV7ag+FWnj3ace3Ms+YlNrc79bBqTp67jrw2IWz++/YP67Ndn E0rsPKD6iAuGJjakPvrBrFNsR5rTpnwu3ff1lncY56BzF0wGA+p42A0vd5LXDdxm6iXp gzwML1Arx9cOjDs5QNUphb67uHB18UMiWinwDOhjBLf4BK1RT77qM/fs83G18lxII1Az E9eA== X-Gm-Message-State: AOJu0YxeDD/ZRNMG99ShrIbWRTEIHDvN14yb2i7JyHPYKFmeQBPkC6Ra MHaQsNK+4A954rgjoLnecv629v8NmZfigawTlRAwLjOEyNdRbbMRaaqF7g== X-Google-Smtp-Source: AGHT+IHf8FkB6NGoluqROlaJ9C25MESz/rQvijfbYgANNpA7nFr+eWPIRZErViKtG0UFF6hpS3H0aQ== X-Received: by 2002:a05:6a21:398b:b0:1cf:506a:cdd8 with SMTP id adf61e73a8af0-1cf75ee48bemr2266487637.12.1726119059207; Wed, 11 Sep 2024 22:30:59 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 19/47] hw/riscv/virt.c: support for RISC-V IOMMU PCIDevice hotplug Date: Thu, 12 Sep 2024 15:29:24 +1000 Message-ID: <20240912052953.2552501-20-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=alistair23@gmail.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119242734116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach Generate device tree entry for riscv-iommu PCI device, along with mapping all PCI device identifiers to the single IOMMU device instance. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Reviewed-by: Alistair Francis Message-ID: <20240903201633.93182-7-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/virt.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index cef41c150a..63d553ac98 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -32,6 +32,7 @@ #include "hw/core/sysbus-fdt.h" #include "target/riscv/pmu.h" #include "hw/riscv/riscv_hart.h" +#include "hw/riscv/iommu.h" #include "hw/riscv/virt.h" #include "hw/riscv/boot.h" #include "hw/riscv/numa.h" @@ -1032,6 +1033,30 @@ static void create_fdt_virtio_iommu(RISCVVirtState *= s, uint16_t bdf) bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf); } =20 +static void create_fdt_iommu(RISCVVirtState *s, uint16_t bdf) +{ + const char comp[] =3D "riscv,pci-iommu"; + void *fdt =3D MACHINE(s)->fdt; + uint32_t iommu_phandle; + g_autofree char *iommu_node =3D NULL; + g_autofree char *pci_node =3D NULL; + + pci_node =3D g_strdup_printf("/soc/pci@%lx", + (long) virt_memmap[VIRT_PCIE_ECAM].base); + iommu_node =3D g_strdup_printf("%s/iommu@%x", pci_node, bdf); + iommu_phandle =3D qemu_fdt_alloc_phandle(fdt); + qemu_fdt_add_subnode(fdt, iommu_node); + + qemu_fdt_setprop(fdt, iommu_node, "compatible", comp, sizeof(comp)); + qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1); + qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle); + qemu_fdt_setprop_cells(fdt, iommu_node, "reg", + bdf << 8, 0, 0, 0, 0); + qemu_fdt_setprop_cells(fdt, pci_node, "iommu-map", + 0, iommu_phandle, 0, bdf, + bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf); +} + static void finalize_fdt(RISCVVirtState *s) { uint32_t phandle =3D 1, irq_mmio_phandle =3D 1, msi_pcie_phandle =3D 1; @@ -1738,9 +1763,11 @@ static HotplugHandler *virt_machine_get_hotplug_hand= ler(MachineState *machine, MachineClass *mc =3D MACHINE_GET_CLASS(machine); =20 if (device_is_dynamic_sysbus(mc, dev) || - object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_RISCV_IOMMU_PCI)) { return HOTPLUG_HANDLER(machine); } + return NULL; } =20 @@ -1761,6 +1788,10 @@ static void virt_machine_device_plug_cb(HotplugHandl= er *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { create_fdt_virtio_iommu(s, pci_get_bdf(PCI_DEVICE(dev))); } + + if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_IOMMU_PCI)) { + create_fdt_iommu(s, pci_get_bdf(PCI_DEVICE(dev))); + } } =20 static void virt_machine_class_init(ObjectClass *oc, void *data) --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119676; cv=none; d=zohomail.com; s=zohoarc; b=jcOCDD1K1kO9sn4/gNXFA0OzjhHBwcegpehDdalBktbNSCo8FbAaCyNAV2eAP21TgGbGx+qNwhxUI8dXztMeMnDPN0L91S8GZUGLcwHIc4VYin423DIVamLYxvi1oSiaw1JnWSNsfIh5OaArfj+Yt2AHZS4XWjhMOcguf3mIwtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119676; h=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=2ByTGLA2ohy+rmq/nypuCycWKA7WUf0mVlcyTFolxao=; b=UQf7vXgeVPefRRthBdtsQICdb+h3MBQ/V0GgJ4+O+4DhQG2N0VHPUj/Rmlv2zf1hDSN3VA4kuY76dISaMiIJeT3/iwb6fnVJGnMvJvMVJtz6xcqePH/PSZc66kbotnUVrjCxkCM54haF1xVfouc311KBYcFOBr6jT0sMfUgqp8I= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119676110966.7129590190773; Wed, 11 Sep 2024 22:41:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQC-0003IG-Uj; Thu, 12 Sep 2024 01:31:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQ6-0002vJ-Dm for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:06 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQ4-00034f-2Q for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:05 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-71798a15ce5so1208996b3a.0 for ; Wed, 11 Sep 2024 22:31:03 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119062; x=1726723862; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2ByTGLA2ohy+rmq/nypuCycWKA7WUf0mVlcyTFolxao=; b=XxKmvz+MSFqZOyQRPIujsiGZzycOGGfJvkJ0MRLrb/qZL5sqQZZVSeRmvEvvmQrZy8 WSyTA1gX/NpyFGy7RpJFATof4m3rInPWjcLdbByA/uG2NNBWFTFOujlIlgSee+X8UnHh 5zJa4uRi+GVjNldn12ig65froSq87chaySj5it83HU+Dof/fSsfLrtQJnBWNkgaj3U6m 6RJe2dFXl5GBHNEJZl9drMJ26vf2EmOA408BKvrCqzRxxMaMtnHc8yqWGFL4dYz6A/q+ wKHZDWNP4ys1dIRwVJMxxy5ZHgCDZfwRVIMdv+r82wo5oEhP97o8WTu8qXqjMUZcehAQ vxMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119062; x=1726723862; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ByTGLA2ohy+rmq/nypuCycWKA7WUf0mVlcyTFolxao=; b=oxRG6aV3RVMFZzyvOUN7Gy7+3H8cSQnOYxcaAB8QAh7DxTtDYsndbEzXTMsPNV0BBk c4tILBHGPL0v5U8EaDyfRQxSTGB+D1PV6tRFZsftNlDNvTpcJuCSXAXdHSF1nAHFpI4l 6Gmib3rduLTkO0r1fW0Jhmxdv7+M7B8RoWuktQVR6XkxyePinWlJ9m5BSza/U9uHQRqH VxXdCYCewifS2Tkf+5s/HmKCxSHp+BxUwB9DYL/jTfZxMLN4JrE/WEXiMw6omo0wIuRs HgiU0a/GAP3ChmdC9agLdb1rAkPh+JN6cuddkm2hjLQk6XzpcOykA0/v/mkKJyEbSO1p cZeg== X-Gm-Message-State: AOJu0YxYoJJGP1GEHdxZECqTUKgFYLAaFxl0+R9msqUcIaxcGl9p/7Bv I+DoCkxUaPZsI2UQWcRQr5Av2DnwfAQUdPJ0l99cXPmPybPjyx7BvETVQA== X-Google-Smtp-Source: AGHT+IGDeCbrQl5kIBITEnZGe7uvQeJZXD38N102Q8/sBgtv0UdDFql8WIguiFBU6B3OMeLhgqBdig== X-Received: by 2002:a05:6a00:18a3:b0:717:9896:fb03 with SMTP id d2e1a72fcca58-719263cbe2emr2546728b3a.6.1726119062150; Wed, 11 Sep 2024 22:31:02 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 20/47] test/qtest: add riscv-iommu-pci tests Date: Thu, 12 Sep 2024 15:29:25 +1000 Message-ID: <20240912052953.2552501-21-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=alistair23@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119677629116600 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza To test the RISC-V IOMMU emulation we'll use its PCI representation. Create a new 'riscv-iommu-pci' libqos device that will be present with CONFIG_RISCV_IOMMU. This config is only available for RISC-V, so this device will only be consumed by the RISC-V libqos machine. Start with basic tests: a PCI sanity check and a reset state register test. The reset test was taken from the RISC-V IOMMU spec chapter 5.2, "Reset behavior". More tests will be added later. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Acked-by: Alistair Francis Message-ID: <20240903201633.93182-8-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- tests/qtest/libqos/riscv-iommu.h | 71 ++++++++++++++++++++++++ tests/qtest/libqos/riscv-iommu.c | 76 ++++++++++++++++++++++++++ tests/qtest/riscv-iommu-test.c | 93 ++++++++++++++++++++++++++++++++ tests/qtest/libqos/meson.build | 4 ++ tests/qtest/meson.build | 1 + 5 files changed, 245 insertions(+) create mode 100644 tests/qtest/libqos/riscv-iommu.h create mode 100644 tests/qtest/libqos/riscv-iommu.c create mode 100644 tests/qtest/riscv-iommu-test.c diff --git a/tests/qtest/libqos/riscv-iommu.h b/tests/qtest/libqos/riscv-io= mmu.h new file mode 100644 index 0000000000..d123efb41f --- /dev/null +++ b/tests/qtest/libqos/riscv-iommu.h @@ -0,0 +1,71 @@ +/* + * libqos driver riscv-iommu-pci framework + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at = your + * option) any later version. See the COPYING file in the top-level direc= tory. + * + */ + +#ifndef TESTS_LIBQOS_RISCV_IOMMU_H +#define TESTS_LIBQOS_RISCV_IOMMU_H + +#include "qgraph.h" +#include "pci.h" +#include "qemu/bitops.h" + +#ifndef GENMASK_ULL +#define GENMASK_ULL(h, l) (((~0ULL) >> (63 - (h) + (l))) << (l)) +#endif + +/* + * RISC-V IOMMU uses PCI_VENDOR_ID_REDHAT 0x1b36 and + * PCI_DEVICE_ID_REDHAT_RISCV_IOMMU 0x0014. + */ +#define RISCV_IOMMU_PCI_VENDOR_ID 0x1b36 +#define RISCV_IOMMU_PCI_DEVICE_ID 0x0014 +#define RISCV_IOMMU_PCI_DEVICE_CLASS 0x0806 + +/* Common field positions */ +#define RISCV_IOMMU_QUEUE_ENABLE BIT(0) +#define RISCV_IOMMU_QUEUE_INTR_ENABLE BIT(1) +#define RISCV_IOMMU_QUEUE_MEM_FAULT BIT(8) +#define RISCV_IOMMU_QUEUE_ACTIVE BIT(16) +#define RISCV_IOMMU_QUEUE_BUSY BIT(17) + +#define RISCV_IOMMU_REG_CAP 0x0000 +#define RISCV_IOMMU_CAP_VERSION GENMASK_ULL(7, 0) + +#define RISCV_IOMMU_REG_DDTP 0x0010 +#define RISCV_IOMMU_DDTP_BUSY BIT_ULL(4) +#define RISCV_IOMMU_DDTP_MODE GENMASK_ULL(3, 0) +#define RISCV_IOMMU_DDTP_MODE_OFF 0 + +#define RISCV_IOMMU_REG_CQCSR 0x0048 +#define RISCV_IOMMU_CQCSR_CQEN RISCV_IOMMU_QUEUE_ENABLE +#define RISCV_IOMMU_CQCSR_CIE RISCV_IOMMU_QUEUE_INTR_ENABLE +#define RISCV_IOMMU_CQCSR_CQON RISCV_IOMMU_QUEUE_ACTIVE +#define RISCV_IOMMU_CQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY + +#define RISCV_IOMMU_REG_FQCSR 0x004C +#define RISCV_IOMMU_FQCSR_FQEN RISCV_IOMMU_QUEUE_ENABLE +#define RISCV_IOMMU_FQCSR_FIE RISCV_IOMMU_QUEUE_INTR_ENABLE +#define RISCV_IOMMU_FQCSR_FQON RISCV_IOMMU_QUEUE_ACTIVE +#define RISCV_IOMMU_FQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY + +#define RISCV_IOMMU_REG_PQCSR 0x0050 +#define RISCV_IOMMU_PQCSR_PQEN RISCV_IOMMU_QUEUE_ENABLE +#define RISCV_IOMMU_PQCSR_PIE RISCV_IOMMU_QUEUE_INTR_ENABLE +#define RISCV_IOMMU_PQCSR_PQON RISCV_IOMMU_QUEUE_ACTIVE +#define RISCV_IOMMU_PQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY + +#define RISCV_IOMMU_REG_IPSR 0x0054 + +typedef struct QRISCVIOMMU { + QOSGraphObject obj; + QPCIDevice dev; + QPCIBar reg_bar; +} QRISCVIOMMU; + +#endif diff --git a/tests/qtest/libqos/riscv-iommu.c b/tests/qtest/libqos/riscv-io= mmu.c new file mode 100644 index 0000000000..01e3b31c0b --- /dev/null +++ b/tests/qtest/libqos/riscv-iommu.c @@ -0,0 +1,76 @@ +/* + * libqos driver riscv-iommu-pci framework + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at = your + * option) any later version. See the COPYING file in the top-level direc= tory. + * + */ + +#include "qemu/osdep.h" +#include "../libqtest.h" +#include "qemu/module.h" +#include "qgraph.h" +#include "pci.h" +#include "riscv-iommu.h" + +static void *riscv_iommu_pci_get_driver(void *obj, const char *interface) +{ + QRISCVIOMMU *r_iommu_pci =3D obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &r_iommu_pci->dev; + } + + fprintf(stderr, "%s not present in riscv_iommu_pci\n", interface); + g_assert_not_reached(); +} + +static void riscv_iommu_pci_start_hw(QOSGraphObject *obj) +{ + QRISCVIOMMU *pci =3D (QRISCVIOMMU *)obj; + qpci_device_enable(&pci->dev); +} + +static void riscv_iommu_pci_destructor(QOSGraphObject *obj) +{ + QRISCVIOMMU *pci =3D (QRISCVIOMMU *)obj; + qpci_iounmap(&pci->dev, pci->reg_bar); +} + +static void *riscv_iommu_pci_create(void *pci_bus, QGuestAllocator *alloc, + void *addr) +{ + QRISCVIOMMU *r_iommu_pci =3D g_new0(QRISCVIOMMU, 1); + QPCIBus *bus =3D pci_bus; + + qpci_device_init(&r_iommu_pci->dev, bus, addr); + r_iommu_pci->reg_bar =3D qpci_iomap(&r_iommu_pci->dev, 0, NULL); + + r_iommu_pci->obj.get_driver =3D riscv_iommu_pci_get_driver; + r_iommu_pci->obj.start_hw =3D riscv_iommu_pci_start_hw; + r_iommu_pci->obj.destructor =3D riscv_iommu_pci_destructor; + return &r_iommu_pci->obj; +} + +static void riscv_iommu_pci_register_nodes(void) +{ + QPCIAddress addr =3D { + .vendor_id =3D RISCV_IOMMU_PCI_VENDOR_ID, + .device_id =3D RISCV_IOMMU_PCI_DEVICE_ID, + .devfn =3D QPCI_DEVFN(1, 0), + }; + + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "addr=3D01.0", + }; + + add_qpci_address(&opts, &addr); + + qos_node_create_driver("riscv-iommu-pci", riscv_iommu_pci_create); + qos_node_produces("riscv-iommu-pci", "pci-device"); + qos_node_consumes("riscv-iommu-pci", "pci-bus", &opts); +} + +libqos_init(riscv_iommu_pci_register_nodes); diff --git a/tests/qtest/riscv-iommu-test.c b/tests/qtest/riscv-iommu-test.c new file mode 100644 index 0000000000..7f0dbd0211 --- /dev/null +++ b/tests/qtest/riscv-iommu-test.c @@ -0,0 +1,93 @@ +/* + * QTest testcase for RISC-V IOMMU + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at = your + * option) any later version. See the COPYING file in the top-level direc= tory. + * + */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "qemu/module.h" +#include "libqos/qgraph.h" +#include "libqos/riscv-iommu.h" +#include "hw/pci/pci_regs.h" + +static uint32_t riscv_iommu_read_reg32(QRISCVIOMMU *r_iommu, int reg_offse= t) +{ + uint32_t reg; + + qpci_memread(&r_iommu->dev, r_iommu->reg_bar, reg_offset, + ®, sizeof(reg)); + return reg; +} + +static uint64_t riscv_iommu_read_reg64(QRISCVIOMMU *r_iommu, int reg_offse= t) +{ + uint64_t reg; + + qpci_memread(&r_iommu->dev, r_iommu->reg_bar, reg_offset, + ®, sizeof(reg)); + return reg; +} + +static void test_pci_config(void *obj, void *data, QGuestAllocator *t_allo= c) +{ + QRISCVIOMMU *r_iommu =3D obj; + QPCIDevice *dev =3D &r_iommu->dev; + uint16_t vendorid, deviceid, classid; + + vendorid =3D qpci_config_readw(dev, PCI_VENDOR_ID); + deviceid =3D qpci_config_readw(dev, PCI_DEVICE_ID); + classid =3D qpci_config_readw(dev, PCI_CLASS_DEVICE); + + g_assert_cmpuint(vendorid, =3D=3D, RISCV_IOMMU_PCI_VENDOR_ID); + g_assert_cmpuint(deviceid, =3D=3D, RISCV_IOMMU_PCI_DEVICE_ID); + g_assert_cmpuint(classid, =3D=3D, RISCV_IOMMU_PCI_DEVICE_CLASS); +} + +static void test_reg_reset(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QRISCVIOMMU *r_iommu =3D obj; + uint64_t cap; + uint32_t reg; + + cap =3D riscv_iommu_read_reg64(r_iommu, RISCV_IOMMU_REG_CAP); + g_assert_cmpuint(cap & RISCV_IOMMU_CAP_VERSION, =3D=3D, 0x10); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_CQCSR); + g_assert_cmpuint(reg & RISCV_IOMMU_CQCSR_CQEN, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_CQCSR_CIE, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_CQCSR_CQON, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_CQCSR_BUSY, =3D=3D, 0); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_FQCSR); + g_assert_cmpuint(reg & RISCV_IOMMU_FQCSR_FQEN, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_FQCSR_FIE, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_FQCSR_FQON, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_FQCSR_BUSY, =3D=3D, 0); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_PQCSR); + g_assert_cmpuint(reg & RISCV_IOMMU_PQCSR_PQEN, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_PQCSR_PIE, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_PQCSR_PQON, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_PQCSR_BUSY, =3D=3D, 0); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_DDTP); + g_assert_cmpuint(reg & RISCV_IOMMU_DDTP_BUSY, =3D=3D, 0); + g_assert_cmpuint(reg & RISCV_IOMMU_DDTP_MODE, =3D=3D, + RISCV_IOMMU_DDTP_MODE_OFF); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_IPSR); + g_assert_cmpuint(reg, =3D=3D, 0); +} + +static void register_riscv_iommu_test(void) +{ + qos_add_test("pci_config", "riscv-iommu-pci", test_pci_config, NULL); + qos_add_test("reg_reset", "riscv-iommu-pci", test_reg_reset, NULL); +} + +libqos_init(register_riscv_iommu_test); diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build index 1b2b2dbb22..586fcacdc8 100644 --- a/tests/qtest/libqos/meson.build +++ b/tests/qtest/libqos/meson.build @@ -68,6 +68,10 @@ if have_virtfs libqos_srcs +=3D files('virtio-9p.c', 'virtio-9p-client.c') endif =20 +if config_all_devices.has_key('CONFIG_RISCV_IOMMU') + libqos_srcs +=3D files('riscv-iommu.c') +endif + libqos =3D static_library('qos', libqos_srcs + genh, build_by_default: false) =20 diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index fc852f3d8b..68cb7615a5 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -298,6 +298,7 @@ qos_test_ss.add( 'vmxnet3-test.c', 'igb-test.c', 'ufs-test.c', + 'riscv-iommu-test.c', ) =20 if config_all_devices.has_key('CONFIG_VIRTIO_SERIAL') --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119936; cv=none; d=zohomail.com; s=zohoarc; b=IS9ajDT1GtPqplbpP1UftnQ7sYo0Rq5WonJ3/l5h3puROy/FEH5UiApkSbZy6rfmygr9g5SRfBi2WdaLU4nUj6sUfJznnqVlWL+IqZvKrO8lKvDMDcN5zmdPHRDFd1CJ2f6843WwdeILPnzowGVgKaV10F4vAWXPX4I8MXZKhnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119936; h=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=D8IzRrTG3yIv5J3skaJtLVawEmGkxz4syszpjSziKs0=; b=hNhY/dY5vqMj1UHAVgwpMADvPmz4OcTC/urYk9IUlndDrKMHFy2zveUO8dqT1yKQh6UXF38SoMVQi7rk2CDhmqRlvYL34JELB7tXl7VwW4wSDcdcS4BIzNNCJoBBeKTfjiRkvhI6g5CzgFf9GABlIJTuT8UDVpSoKoaZhbf5muY= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119936472992.8588591302929; Wed, 11 Sep 2024 22:45:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQP-0003OZ-38; Thu, 12 Sep 2024 01:31:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQ9-00035x-F3 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:12 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQ7-00034p-3i for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:09 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-7db174f9050so191343a12.3 for ; Wed, 11 Sep 2024 22:31:06 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119065; x=1726723865; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D8IzRrTG3yIv5J3skaJtLVawEmGkxz4syszpjSziKs0=; b=fFV5VEZPbNDpG1qCy477Wp1XjDS7j4UqCYUzRYlyrBOWErwUJksL/dWBLGiughQK6L LsjFRVXgXQNQvYmlF2ORlpk1pihFLp99TGvtYta9BfhtY9lXxrNxAP+1sg45mJBR0Bho /mFGjsJsrCnAzXzvbuKbXCWT8UQ7zsyEbmILBTt33TGhkm3v+QEu9EAIYB90XKJnXVaV OF0M23U34tlXcffq9C9E53QfGw6Sfvnlq9gOD9RfC1lXjCemmrkwvL+ia0+PVtyTkcvd JN7hBfI/wnXxbb5NyRcXZ/Be8yMaX5WKnQYrzvamJwijQFhxLqcVsWhzR7cqO7GmVr8P wvbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119065; x=1726723865; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D8IzRrTG3yIv5J3skaJtLVawEmGkxz4syszpjSziKs0=; b=dmNT1TKa8uEXjmHWB+OdVlCLd62Twnu7xuBtqWWfT3ZYX68owetd2arVMFWJnsV07f 2BIeQLRv/hiNAB6gnxfFc7Qq34OjKtz0FVmQdOedpChtmQiO3twxkRPNK2SQYBiZ4ADL c07X7A8EKG96jYYzJL1/kY5y2WwHJNTlM92212InwImN+U9yrhws6mcmNTOESbWQzgZh Thsh23WI7d+aZkstjkib0qj+56ADWvNL+cxWDYRlWGIwi+bLx658BIQqxZwjFroalLUW xqOeWoQE2J+s38eYlCNk3qn1pKquNfQ17rI7cdFhZeLL7qq+Z8t3G4kSibEOC83B6Umf Ilsw== X-Gm-Message-State: AOJu0YxwWF3CVfJJRKLUiUS3KSoREsJhNzzR3BpIcDWv/+yyM+t5kebU z8edhNyQtfw8JQDwWmA0MISXOiW6llZdERzJV4YlTX9BNnYDyKInKzBQcg== X-Google-Smtp-Source: AGHT+IGbPrZSDWYu2nWp0p40I1Msos7p6oUFllizKHw80k9Dn/Wn1H1ofnl77s12PxJqSmzpu/9Sfg== X-Received: by 2002:a05:6a21:3942:b0:1cf:4326:5602 with SMTP id adf61e73a8af0-1cf761f9b30mr2103201637.36.1726119065413; Wed, 11 Sep 2024 22:31:05 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 21/47] hw/riscv/riscv-iommu: add Address Translation Cache (IOATC) Date: Thu, 12 Sep 2024 15:29:26 +1000 Message-ID: <20240912052953.2552501-22-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=alistair23@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119938737116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach The RISC-V IOMMU spec predicts that the IOMMU can use translation caches to hold entries from the DDT. This includes implementation for all cache commands that are marked as 'not implemented'. There are some artifacts included in the cache that predicts s-stage and g-stage elements, although we don't support it yet. We'll introduce them next. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Acked-by: Alistair Francis Message-ID: <20240903201633.93182-9-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/riscv-iommu.h | 3 + hw/riscv/riscv-iommu.c | 205 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 204 insertions(+), 4 deletions(-) diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index 95b4ce8d50..ddf5d50cf9 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -72,6 +72,9 @@ struct RISCVIOMMUState { =20 GHashTable *ctx_cache; /* Device translation Context Cache */ QemuMutex ctx_lock; /* Device translation Cache update lock */ + GHashTable *iot_cache; /* IO Translated Address Cache */ + QemuMutex iot_lock; /* IO TLB Cache update lock */ + unsigned iot_limit; /* IO Translation Cache size limit */ =20 /* MMIO Hardware Interface */ MemoryRegion regs_mr; diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 061a5efe19..fe81072b1c 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -65,6 +65,16 @@ struct RISCVIOMMUContext { uint64_t msiptp; /* MSI redirection page table pointer */ }; =20 +/* Address translation cache entry */ +struct RISCVIOMMUEntry { + uint64_t iova:44; /* IOVA Page Number */ + uint64_t pscid:20; /* Process Soft-Context identifier */ + uint64_t phys:44; /* Physical Page Number */ + uint64_t gscid:16; /* Guest Soft-Context identifier */ + uint64_t perm:2; /* IOMMU_RW flags */ + uint64_t __rfu:2; +}; + /* IOMMU index for transactions without process_id specified. */ #define RISCV_IOMMU_NOPROCID 0 =20 @@ -1156,13 +1166,130 @@ static AddressSpace *riscv_iommu_space(RISCVIOMMUS= tate *s, uint32_t devid) return &as->iova_as; } =20 +/* Translation Object cache support */ +static gboolean __iot_equal(gconstpointer v1, gconstpointer v2) +{ + RISCVIOMMUEntry *t1 =3D (RISCVIOMMUEntry *) v1; + RISCVIOMMUEntry *t2 =3D (RISCVIOMMUEntry *) v2; + return t1->gscid =3D=3D t2->gscid && t1->pscid =3D=3D t2->pscid && + t1->iova =3D=3D t2->iova; +} + +static guint __iot_hash(gconstpointer v) +{ + RISCVIOMMUEntry *t =3D (RISCVIOMMUEntry *) v; + return (guint)t->iova; +} + +/* GV: 1 PSCV: 1 AV: 1 */ +static void __iot_inval_pscid_iova(gpointer key, gpointer value, gpointer = data) +{ + RISCVIOMMUEntry *iot =3D (RISCVIOMMUEntry *) value; + RISCVIOMMUEntry *arg =3D (RISCVIOMMUEntry *) data; + if (iot->gscid =3D=3D arg->gscid && + iot->pscid =3D=3D arg->pscid && + iot->iova =3D=3D arg->iova) { + iot->perm =3D IOMMU_NONE; + } +} + +/* GV: 1 PSCV: 1 AV: 0 */ +static void __iot_inval_pscid(gpointer key, gpointer value, gpointer data) +{ + RISCVIOMMUEntry *iot =3D (RISCVIOMMUEntry *) value; + RISCVIOMMUEntry *arg =3D (RISCVIOMMUEntry *) data; + if (iot->gscid =3D=3D arg->gscid && + iot->pscid =3D=3D arg->pscid) { + iot->perm =3D IOMMU_NONE; + } +} + +/* GV: 1 GVMA: 1 */ +static void __iot_inval_gscid_gpa(gpointer key, gpointer value, gpointer d= ata) +{ + RISCVIOMMUEntry *iot =3D (RISCVIOMMUEntry *) value; + RISCVIOMMUEntry *arg =3D (RISCVIOMMUEntry *) data; + if (iot->gscid =3D=3D arg->gscid) { + /* simplified cache, no GPA matching */ + iot->perm =3D IOMMU_NONE; + } +} + +/* GV: 1 GVMA: 0 */ +static void __iot_inval_gscid(gpointer key, gpointer value, gpointer data) +{ + RISCVIOMMUEntry *iot =3D (RISCVIOMMUEntry *) value; + RISCVIOMMUEntry *arg =3D (RISCVIOMMUEntry *) data; + if (iot->gscid =3D=3D arg->gscid) { + iot->perm =3D IOMMU_NONE; + } +} + +/* GV: 0 */ +static void __iot_inval_all(gpointer key, gpointer value, gpointer data) +{ + RISCVIOMMUEntry *iot =3D (RISCVIOMMUEntry *) value; + iot->perm =3D IOMMU_NONE; +} + +/* caller should keep ref-count for iot_cache object */ +static RISCVIOMMUEntry *riscv_iommu_iot_lookup(RISCVIOMMUContext *ctx, + GHashTable *iot_cache, hwaddr iova) +{ + RISCVIOMMUEntry key =3D { + .gscid =3D get_field(ctx->gatp, RISCV_IOMMU_DC_IOHGATP_GSCID), + .pscid =3D get_field(ctx->ta, RISCV_IOMMU_DC_TA_PSCID), + .iova =3D PPN_DOWN(iova), + }; + return g_hash_table_lookup(iot_cache, &key); +} + +/* caller should keep ref-count for iot_cache object */ +static void riscv_iommu_iot_update(RISCVIOMMUState *s, + GHashTable *iot_cache, RISCVIOMMUEntry *iot) +{ + if (!s->iot_limit) { + return; + } + + qemu_mutex_lock(&s->iot_lock); + if (g_hash_table_size(s->iot_cache) >=3D s->iot_limit) { + iot_cache =3D g_hash_table_new_full(__iot_hash, __iot_equal, + g_free, NULL); + g_hash_table_unref(qatomic_xchg(&s->iot_cache, iot_cache)); + } + g_hash_table_add(iot_cache, iot); + qemu_mutex_unlock(&s->iot_lock); +} + +static void riscv_iommu_iot_inval(RISCVIOMMUState *s, GHFunc func, + uint32_t gscid, uint32_t pscid, hwaddr iova) +{ + GHashTable *iot_cache; + RISCVIOMMUEntry key =3D { + .gscid =3D gscid, + .pscid =3D pscid, + .iova =3D PPN_DOWN(iova), + }; + + iot_cache =3D g_hash_table_ref(s->iot_cache); + qemu_mutex_lock(&s->iot_lock); + g_hash_table_foreach(iot_cache, func, &key); + qemu_mutex_unlock(&s->iot_lock); + g_hash_table_unref(iot_cache); +} + static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ct= x, - IOMMUTLBEntry *iotlb) + IOMMUTLBEntry *iotlb, bool enable_cache) { + RISCVIOMMUEntry *iot; + IOMMUAccessFlags perm; bool enable_pid; bool enable_pri; + GHashTable *iot_cache; int fault; =20 + iot_cache =3D g_hash_table_ref(s->iot_cache); /* * TC[32] is reserved for custom extensions, used here to temporarily * enable automatic page-request generation for ATS queries. @@ -1170,9 +1297,45 @@ static int riscv_iommu_translate(RISCVIOMMUState *s,= RISCVIOMMUContext *ctx, enable_pri =3D (iotlb->perm =3D=3D IOMMU_NONE) && (ctx->tc & BIT_ULL(3= 2)); enable_pid =3D (ctx->tc & RISCV_IOMMU_DC_TC_PDTV); =20 + qemu_mutex_lock(&s->iot_lock); + iot =3D riscv_iommu_iot_lookup(ctx, iot_cache, iotlb->iova); + qemu_mutex_unlock(&s->iot_lock); + perm =3D iot ? iot->perm : IOMMU_NONE; + if (perm !=3D IOMMU_NONE) { + iotlb->translated_addr =3D PPN_PHYS(iot->phys); + iotlb->addr_mask =3D ~TARGET_PAGE_MASK; + iotlb->perm =3D perm; + fault =3D 0; + goto done; + } + /* Translate using device directory / page table information. */ fault =3D riscv_iommu_spa_fetch(s, ctx, iotlb); =20 + if (!fault && iotlb->target_as =3D=3D &s->trap_as) { + /* Do not cache trapped MSI translations */ + goto done; + } + + /* + * We made an implementation choice to not cache identity-mapped + * translations, as allowed by the specification, to avoid + * translation cache evictions for other devices sharing the + * IOMMU hardware model. + */ + if (!fault && iotlb->translated_addr !=3D iotlb->iova && enable_cache)= { + iot =3D g_new0(RISCVIOMMUEntry, 1); + iot->iova =3D PPN_DOWN(iotlb->iova); + iot->phys =3D PPN_DOWN(iotlb->translated_addr); + iot->gscid =3D get_field(ctx->gatp, RISCV_IOMMU_DC_IOHGATP_GSCID); + iot->pscid =3D get_field(ctx->ta, RISCV_IOMMU_DC_TA_PSCID); + iot->perm =3D iotlb->perm; + riscv_iommu_iot_update(s, iot_cache, iot); + } + +done: + g_hash_table_unref(iot_cache); + if (enable_pri && fault) { struct riscv_iommu_pq_record pr =3D {0}; if (enable_pid) { @@ -1312,13 +1475,40 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUS= tate *s) if (cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_PSCV) { /* illegal command arguments IOTINVAL.GVMA & PSCV =3D=3D 1= */ goto cmd_ill; + } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_GV)) { + /* invalidate all cache mappings */ + func =3D __iot_inval_all; + } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_AV)) { + /* invalidate cache matching GSCID */ + func =3D __iot_inval_gscid; + } else { + /* invalidate cache matching GSCID and ADDR (GPA) */ + func =3D __iot_inval_gscid_gpa; } - /* translation cache not implemented yet */ + riscv_iommu_iot_inval(s, func, + get_field(cmd.dword0, RISCV_IOMMU_CMD_IOTINVAL_GSCID), 0, + cmd.dword1 & TARGET_PAGE_MASK); break; =20 case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IOTINVAL_FUNC_VMA, RISCV_IOMMU_CMD_IOTINVAL_OPCODE): - /* translation cache not implemented yet */ + if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_GV)) { + /* invalidate all cache mappings, simplified model */ + func =3D __iot_inval_all; + } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_PSCV)) { + /* invalidate cache matching GSCID, simplified model */ + func =3D __iot_inval_gscid; + } else if (!(cmd.dword0 & RISCV_IOMMU_CMD_IOTINVAL_AV)) { + /* invalidate cache matching GSCID and PSCID */ + func =3D __iot_inval_pscid; + } else { + /* invalidate cache matching GSCID and PSCID and ADDR (IOV= A) */ + func =3D __iot_inval_pscid_iova; + } + riscv_iommu_iot_inval(s, func, + get_field(cmd.dword0, RISCV_IOMMU_CMD_IOTINVAL_GSCID), + get_field(cmd.dword0, RISCV_IOMMU_CMD_IOTINVAL_PSCID), + cmd.dword1 & TARGET_PAGE_MASK); break; =20 case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_IODIR_FUNC_INVAL_DDT, @@ -1857,6 +2047,10 @@ static void riscv_iommu_realize(DeviceState *dev, Er= ror **errp) g_free, NULL); qemu_mutex_init(&s->ctx_lock); =20 + s->iot_cache =3D g_hash_table_new_full(__iot_hash, __iot_equal, + g_free, NULL); + qemu_mutex_init(&s->iot_lock); + s->iommus.le_next =3D NULL; s->iommus.le_prev =3D NULL; QLIST_INIT(&s->spaces); @@ -1869,6 +2063,7 @@ static void riscv_iommu_unrealize(DeviceState *dev) RISCVIOMMUState *s =3D RISCV_IOMMU(dev); =20 qemu_mutex_destroy(&s->core_lock); + g_hash_table_unref(s->iot_cache); g_hash_table_unref(s->ctx_cache); } =20 @@ -1876,6 +2071,8 @@ static Property riscv_iommu_properties[] =3D { DEFINE_PROP_UINT32("version", RISCVIOMMUState, version, RISCV_IOMMU_SPEC_DOT_VER), DEFINE_PROP_UINT32("bus", RISCVIOMMUState, bus, 0x0), + DEFINE_PROP_UINT32("ioatc-limit", RISCVIOMMUState, iot_limit, + LIMIT_CACHE_IOT), DEFINE_PROP_BOOL("intremap", RISCVIOMMUState, enable_msi, TRUE), DEFINE_PROP_BOOL("off", RISCVIOMMUState, enable_off, TRUE), DEFINE_PROP_BOOL("s-stage", RISCVIOMMUState, enable_s_stage, TRUE), @@ -1930,7 +2127,7 @@ static IOMMUTLBEntry riscv_iommu_memory_region_transl= ate( /* Translation disabled or invalid. */ iotlb.addr_mask =3D 0; iotlb.perm =3D IOMMU_NONE; - } else if (riscv_iommu_translate(as->iommu, ctx, &iotlb)) { + } else if (riscv_iommu_translate(as->iommu, ctx, &iotlb, true)) { /* Translation disabled or fault reported. */ iotlb.addr_mask =3D 0; iotlb.perm =3D IOMMU_NONE; --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119712; cv=none; d=zohomail.com; s=zohoarc; b=Z7KgkrefTukQ5on7SCpLQbSINKEelSM/j8qaR00rK9xzvQM54aYabv8t0WoXnyMKv9qHfvBxREK52GtZpbqH8Szn4tv6mlghde3FftpSKLWlpOnUiG8v5fEOFEgv43PXHarjyXo6+hx6+/2Gfn3X0gkcIVJLED5un6+ZshwXBnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119712; h=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=5LI2If9P1EQTIv4Ss1QM9OqSfJCOuj5E+lEZueFfChk=; b=m+FLW+F7YA60Af27kFvZqQ99SxQlflfnpK5jndLBopX2qPM164+lCmZY2YThuAEFqwbRPtYKprcyohNDqU0BDDiH527BuK8uV2MQn3AWwYQcWG5rs20QHeDfUamLzCAfWzLGAML3ItAI8uR0OXWsWsb2oFi+oll9N3HIAOMJlOQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119712771223.6286258882177; Wed, 11 Sep 2024 22:41:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQp-00056f-2R; Thu, 12 Sep 2024 01:31:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQC-0003IW-PK for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:12 -0400 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 1socQA-000353-BY for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:12 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7d50e7a3652so409471a12.3 for ; Wed, 11 Sep 2024 22:31:09 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119069; x=1726723869; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5LI2If9P1EQTIv4Ss1QM9OqSfJCOuj5E+lEZueFfChk=; b=lPkXQGCwC7vEEtK1gXJ4IPLDVKf7HYtgVojCKUifWFGRMSZkH+voWfRbiJcXqs6IxV wx8SaImAZP5WgEpogmnsyr6GIrGQ004yfC/e4hG6y3MTCejOsSJQVF7TOa8buMDmsmdv ++SQKdaSjh9Z/j1+v0HzGbpSwopImngySwpvHo0+1FxJeIj0M+QijnVGMZKDVM+GtU2o TJDrKyFsjQt29pDeVVoNZjRbh0UiNdNDeRZgJJqxB7yPnHi+AscRId+N9RD78CBvyT55 QN8DCMH7GHs3ZVtajbytVJhgMaFTljmJj5t3/gLAxwXZku+phAaw/kGKBpXu9UKno/UY A6Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119069; x=1726723869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5LI2If9P1EQTIv4Ss1QM9OqSfJCOuj5E+lEZueFfChk=; b=OEl6bJMPWKIHDSLq0INa/737pK5ybhTzcIC0vijpu3gwSiOyNQVl2A6sJJ5AB8/vy9 ZVijYTN9PsB/lF0lepkHfonw/uNi5c5j9SfWXbDOh55/k2RY/jybBianlv9aZ3SWDU+6 8zEW7zWd03ihSMxFkav5YtULvWQH17zLO7HNBfYdXASwof66UX28qCOjcfJC7OBpjwVR v7jfp9ANeKXHpXCKM3p0S44nbJ6j2fQHvM6fLOEoc32QsgJsIbBtuQODk8gDrEDIFmM+ 5rWuevZD8pbgv6sZ9fllY0RtBuAuEp1B6IzcX95YW+o7vysq0BM1xRZMGlaJClFqVgm7 Vriw== X-Gm-Message-State: AOJu0YzhZpuEjjYWHarC7vGuuny/PYNP6ZYm6wy0tBoNHIg6fBzwvixx 5GSjNFc2o9PjoENzR7I85mOsi+Fr0AlzATS0wtevqEOmfhNQiCwXTme84Q== X-Google-Smtp-Source: AGHT+IHvWwrklW3YcYFoBV9jKuks2HjL5wd/oNyS5QjM/ZhF3HQt9WGQlBMKct6rDjcarxA3XXfCJA== X-Received: by 2002:a05:6a21:4a4b:b0:1cf:287a:414e with SMTP id adf61e73a8af0-1cf75d76cfdmr2382651637.1.1726119068673; Wed, 11 Sep 2024 22:31:08 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 22/47] hw/riscv/riscv-iommu: add ATS support Date: Thu, 12 Sep 2024 15:29:27 +1000 Message-ID: <20240912052953.2552501-23-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=alistair23@gmail.com; helo=mail-pg1-x530.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119713587116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach Add PCIe Address Translation Services (ATS) capabilities to the IOMMU. This will add support for ATS translation requests in Fault/Event queues, Page-request queue and IOATC invalidations. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Acked-by: Alistair Francis Message-ID: <20240903201633.93182-10-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/riscv-iommu-bits.h | 43 +++++++++++- hw/riscv/riscv-iommu.h | 1 + hw/riscv/riscv-iommu.c | 129 +++++++++++++++++++++++++++++++++++- hw/riscv/trace-events | 3 + 4 files changed, 173 insertions(+), 3 deletions(-) diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h index b1c477f5c3..96a994b9aa 100644 --- a/hw/riscv/riscv-iommu-bits.h +++ b/hw/riscv/riscv-iommu-bits.h @@ -79,6 +79,7 @@ struct riscv_iommu_pq_record { #define RISCV_IOMMU_CAP_SV57X4 BIT_ULL(19) #define RISCV_IOMMU_CAP_MSI_FLAT BIT_ULL(22) #define RISCV_IOMMU_CAP_MSI_MRIF BIT_ULL(23) +#define RISCV_IOMMU_CAP_ATS BIT_ULL(25) #define RISCV_IOMMU_CAP_T2GPA BIT_ULL(26) #define RISCV_IOMMU_CAP_IGS GENMASK_ULL(29, 28) #define RISCV_IOMMU_CAP_PAS GENMASK_ULL(37, 32) @@ -212,6 +213,7 @@ struct riscv_iommu_dc { =20 /* Translation control fields */ #define RISCV_IOMMU_DC_TC_V BIT_ULL(0) +#define RISCV_IOMMU_DC_TC_EN_ATS BIT_ULL(1) #define RISCV_IOMMU_DC_TC_EN_PRI BIT_ULL(2) #define RISCV_IOMMU_DC_TC_T2GPA BIT_ULL(3) #define RISCV_IOMMU_DC_TC_DTF BIT_ULL(4) @@ -273,6 +275,20 @@ struct riscv_iommu_command { #define RISCV_IOMMU_CMD_IODIR_DV BIT_ULL(33) #define RISCV_IOMMU_CMD_IODIR_DID GENMASK_ULL(63, 40) =20 +/* 3.1.4 I/O MMU PCIe ATS */ +#define RISCV_IOMMU_CMD_ATS_OPCODE 4 +#define RISCV_IOMMU_CMD_ATS_FUNC_INVAL 0 +#define RISCV_IOMMU_CMD_ATS_FUNC_PRGR 1 +#define RISCV_IOMMU_CMD_ATS_PID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_CMD_ATS_PV BIT_ULL(32) +#define RISCV_IOMMU_CMD_ATS_DSV BIT_ULL(33) +#define RISCV_IOMMU_CMD_ATS_RID GENMASK_ULL(55, 40) +#define RISCV_IOMMU_CMD_ATS_DSEG GENMASK_ULL(63, 56) +/* dword1 is the ATS payload, two different payload types for INVAL and PR= GR */ + +/* ATS.PRGR payload */ +#define RISCV_IOMMU_CMD_ATS_PRGR_RESP_CODE GENMASK_ULL(47, 44) + enum riscv_iommu_dc_fsc_atp_modes { RISCV_IOMMU_DC_FSC_MODE_BARE =3D 0, RISCV_IOMMU_DC_FSC_IOSATP_MODE_SV32 =3D 8, @@ -339,7 +355,32 @@ enum riscv_iommu_fq_ttypes { RISCV_IOMMU_FQ_TTYPE_TADDR_INST_FETCH =3D 5, RISCV_IOMMU_FQ_TTYPE_TADDR_RD =3D 6, RISCV_IOMMU_FQ_TTYPE_TADDR_WR =3D 7, - RISCV_IOMMU_FW_TTYPE_PCIE_MSG_REQ =3D 8, + RISCV_IOMMU_FQ_TTYPE_PCIE_ATS_REQ =3D 8, + RISCV_IOMMU_FW_TTYPE_PCIE_MSG_REQ =3D 9, +}; + +/* Header fields */ +#define RISCV_IOMMU_PREQ_HDR_PID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_PREQ_HDR_PV BIT_ULL(32) +#define RISCV_IOMMU_PREQ_HDR_PRIV BIT_ULL(33) +#define RISCV_IOMMU_PREQ_HDR_EXEC BIT_ULL(34) +#define RISCV_IOMMU_PREQ_HDR_DID GENMASK_ULL(63, 40) + +/* Payload fields */ +#define RISCV_IOMMU_PREQ_PAYLOAD_R BIT_ULL(0) +#define RISCV_IOMMU_PREQ_PAYLOAD_W BIT_ULL(1) +#define RISCV_IOMMU_PREQ_PAYLOAD_L BIT_ULL(2) +#define RISCV_IOMMU_PREQ_PAYLOAD_M GENMASK_ULL(2, 0) +#define RISCV_IOMMU_PREQ_PRG_INDEX GENMASK_ULL(11, 3) +#define RISCV_IOMMU_PREQ_UADDR GENMASK_ULL(63, 12) + + +/* + * struct riscv_iommu_msi_pte - MSI Page Table Entry + */ +struct riscv_iommu_msi_pte { + uint64_t pte; + uint64_t mrif_info; }; =20 /* Fields on pte */ diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index ddf5d50cf9..9f15c2b139 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -39,6 +39,7 @@ struct RISCVIOMMUState { =20 bool enable_off; /* Enable out-of-reset OFF mode (DMA disabled) */ bool enable_msi; /* Enable MSI remapping */ + bool enable_ats; /* Enable ATS support */ bool enable_s_stage; /* Enable S/VS-Stage translation */ bool enable_g_stage; /* Enable G-Stage translation */ =20 diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index fe81072b1c..50740442bb 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -665,6 +665,20 @@ static bool riscv_iommu_validate_device_ctx(RISCVIOMMU= State *s, RISCVIOMMUContext *ctx) { uint32_t fsc_mode, msi_mode; + uint64_t gatp; + + if (!(s->cap & RISCV_IOMMU_CAP_ATS) && + (ctx->tc & RISCV_IOMMU_DC_TC_EN_ATS || + ctx->tc & RISCV_IOMMU_DC_TC_EN_PRI || + ctx->tc & RISCV_IOMMU_DC_TC_PRPR)) { + return false; + } + + if (!(ctx->tc & RISCV_IOMMU_DC_TC_EN_ATS) && + (ctx->tc & RISCV_IOMMU_DC_TC_T2GPA || + ctx->tc & RISCV_IOMMU_DC_TC_EN_PRI)) { + return false; + } =20 if (!(ctx->tc & RISCV_IOMMU_DC_TC_EN_PRI) && ctx->tc & RISCV_IOMMU_DC_TC_PRPR) { @@ -685,6 +699,12 @@ static bool riscv_iommu_validate_device_ctx(RISCVIOMMU= State *s, } } =20 + gatp =3D get_field(ctx->gatp, RISCV_IOMMU_ATP_MODE_FIELD); + if (ctx->tc & RISCV_IOMMU_DC_TC_T2GPA && + gatp =3D=3D RISCV_IOMMU_DC_IOHGATP_MODE_BARE) { + return false; + } + fsc_mode =3D get_field(ctx->satp, RISCV_IOMMU_DC_FSC_MODE); =20 if (ctx->tc & RISCV_IOMMU_DC_TC_PDTV) { @@ -835,7 +855,12 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, R= ISCVIOMMUContext *ctx) RISCV_IOMMU_DC_IOHGATP_MODE_BARE); ctx->satp =3D set_field(0, RISCV_IOMMU_ATP_MODE_FIELD, RISCV_IOMMU_DC_FSC_MODE_BARE); + ctx->tc =3D RISCV_IOMMU_DC_TC_V; + if (s->enable_ats) { + ctx->tc |=3D RISCV_IOMMU_DC_TC_EN_ATS; + } + ctx->ta =3D 0; ctx->msiptp =3D 0; return 0; @@ -1297,6 +1322,16 @@ static int riscv_iommu_translate(RISCVIOMMUState *s,= RISCVIOMMUContext *ctx, enable_pri =3D (iotlb->perm =3D=3D IOMMU_NONE) && (ctx->tc & BIT_ULL(3= 2)); enable_pid =3D (ctx->tc & RISCV_IOMMU_DC_TC_PDTV); =20 + /* Check for ATS request. */ + if (iotlb->perm =3D=3D IOMMU_NONE) { + /* Check if ATS is disabled. */ + if (!(ctx->tc & RISCV_IOMMU_DC_TC_EN_ATS)) { + enable_pri =3D false; + fault =3D RISCV_IOMMU_FQ_CAUSE_TTYPE_BLOCKED; + goto done; + } + } + qemu_mutex_lock(&s->iot_lock); iot =3D riscv_iommu_iot_lookup(ctx, iot_cache, iotlb->iova); qemu_mutex_unlock(&s->iot_lock); @@ -1350,11 +1385,11 @@ done: } =20 if (fault) { - unsigned ttype; + unsigned ttype =3D RISCV_IOMMU_FQ_TTYPE_PCIE_ATS_REQ; =20 if (iotlb->perm & IOMMU_RW) { ttype =3D RISCV_IOMMU_FQ_TTYPE_UADDR_WR; - } else { + } else if (iotlb->perm & IOMMU_RO) { ttype =3D RISCV_IOMMU_FQ_TTYPE_UADDR_RD; } =20 @@ -1382,6 +1417,73 @@ static MemTxResult riscv_iommu_iofence(RISCVIOMMUSta= te *s, bool notify, MEMTXATTRS_UNSPECIFIED); } =20 +static void riscv_iommu_ats(RISCVIOMMUState *s, + struct riscv_iommu_command *cmd, IOMMUNotifierFlag flag, + IOMMUAccessFlags perm, + void (*trace_fn)(const char *id)) +{ + RISCVIOMMUSpace *as =3D NULL; + IOMMUNotifier *n; + IOMMUTLBEvent event; + uint32_t pid; + uint32_t devid; + const bool pv =3D cmd->dword0 & RISCV_IOMMU_CMD_ATS_PV; + + if (cmd->dword0 & RISCV_IOMMU_CMD_ATS_DSV) { + /* Use device segment and requester id */ + devid =3D get_field(cmd->dword0, + RISCV_IOMMU_CMD_ATS_DSEG | RISCV_IOMMU_CMD_ATS_RID); + } else { + devid =3D get_field(cmd->dword0, RISCV_IOMMU_CMD_ATS_RID); + } + + pid =3D get_field(cmd->dword0, RISCV_IOMMU_CMD_ATS_PID); + + qemu_mutex_lock(&s->core_lock); + QLIST_FOREACH(as, &s->spaces, list) { + if (as->devid =3D=3D devid) { + break; + } + } + qemu_mutex_unlock(&s->core_lock); + + if (!as || !as->notifier) { + return; + } + + event.type =3D flag; + event.entry.perm =3D perm; + event.entry.target_as =3D s->target_as; + + IOMMU_NOTIFIER_FOREACH(n, &as->iova_mr) { + if (!pv || n->iommu_idx =3D=3D pid) { + event.entry.iova =3D n->start; + event.entry.addr_mask =3D n->end - n->start; + trace_fn(as->iova_mr.parent_obj.name); + memory_region_notify_iommu_one(n, &event); + } + } +} + +static void riscv_iommu_ats_inval(RISCVIOMMUState *s, + struct riscv_iommu_command *cmd) +{ + return riscv_iommu_ats(s, cmd, IOMMU_NOTIFIER_DEVIOTLB_UNMAP, IOMMU_NO= NE, + trace_riscv_iommu_ats_inval); +} + +static void riscv_iommu_ats_prgr(RISCVIOMMUState *s, + struct riscv_iommu_command *cmd) +{ + unsigned resp_code =3D get_field(cmd->dword1, + RISCV_IOMMU_CMD_ATS_PRGR_RESP_CODE); + + /* Using the access flag to carry response code information */ + IOMMUAccessFlags perm =3D resp_code ? IOMMU_NONE : IOMMU_RW; + return riscv_iommu_ats(s, cmd, IOMMU_NOTIFIER_MAP, perm, + trace_riscv_iommu_ats_prgr); +} + static void riscv_iommu_process_ddtp(RISCVIOMMUState *s) { uint64_t old_ddtp =3D s->ddtp; @@ -1537,6 +1639,25 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUSt= ate *s) get_field(cmd.dword0, RISCV_IOMMU_CMD_IODIR_PID)); break; =20 + /* ATS commands */ + case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_ATS_FUNC_INVAL, + RISCV_IOMMU_CMD_ATS_OPCODE): + if (!s->enable_ats) { + goto cmd_ill; + } + + riscv_iommu_ats_inval(s, &cmd); + break; + + case RISCV_IOMMU_CMD(RISCV_IOMMU_CMD_ATS_FUNC_PRGR, + RISCV_IOMMU_CMD_ATS_OPCODE): + if (!s->enable_ats) { + goto cmd_ill; + } + + riscv_iommu_ats_prgr(s, &cmd); + break; + default: cmd_ill: /* Invalid instruction, do not advance instruction index. */ @@ -1962,6 +2083,9 @@ static void riscv_iommu_realize(DeviceState *dev, Err= or **errp) if (s->enable_msi) { s->cap |=3D RISCV_IOMMU_CAP_MSI_FLAT | RISCV_IOMMU_CAP_MSI_MRIF; } + if (s->enable_ats) { + s->cap |=3D RISCV_IOMMU_CAP_ATS; + } if (s->enable_s_stage) { s->cap |=3D RISCV_IOMMU_CAP_SV32 | RISCV_IOMMU_CAP_SV39 | RISCV_IOMMU_CAP_SV48 | RISCV_IOMMU_CAP_SV57; @@ -2074,6 +2198,7 @@ static Property riscv_iommu_properties[] =3D { DEFINE_PROP_UINT32("ioatc-limit", RISCVIOMMUState, iot_limit, LIMIT_CACHE_IOT), DEFINE_PROP_BOOL("intremap", RISCVIOMMUState, enable_msi, TRUE), + DEFINE_PROP_BOOL("ats", RISCVIOMMUState, enable_ats, TRUE), DEFINE_PROP_BOOL("off", RISCVIOMMUState, enable_off, TRUE), DEFINE_PROP_BOOL("s-stage", RISCVIOMMUState, enable_s_stage, TRUE), DEFINE_PROP_BOOL("g-stage", RISCVIOMMUState, enable_g_stage, TRUE), diff --git a/hw/riscv/trace-events b/hw/riscv/trace-events index 3d5c33102d..0527c56c91 100644 --- a/hw/riscv/trace-events +++ b/hw/riscv/trace-events @@ -12,3 +12,6 @@ riscv_iommu_notifier_add(const char *id) "%s: dev-iotlb n= otifier added" riscv_iommu_notifier_del(const char *id) "%s: dev-iotlb notifier removed" riscv_iommu_notify_int_vector(uint32_t cause, uint32_t vector) "Interrupt = cause 0x%x sent via vector 0x%x" riscv_iommu_icvec_write(uint32_t orig, uint32_t actual) "ICVEC write: inco= ming 0x%x actual 0x%x" +riscv_iommu_ats(const char *id, unsigned b, unsigned d, unsigned f, uint64= _t iova) "%s: translate request %04x:%02x.%u iova: 0x%"PRIx64 +riscv_iommu_ats_inval(const char *id) "%s: dev-iotlb invalidate" +riscv_iommu_ats_prgr(const char *id) "%s: dev-iotlb page request group res= ponse" --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119975; cv=none; d=zohomail.com; s=zohoarc; b=g3xxOwFcCZNZcH0nMozkO4N/IgCCeifILg024LCBnbFo4zTTeXtGg5eeZeuFgnTbScnFU5JNkyj9iOg0gpS6PGmy4/mQkeZOju3yvD0D8g9LhnAQTDrG1kIT41U1Z2Fy1yYurv8RewxuNfd9P0DntLZB4p9MT5/QZJg9ivX26mY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119975; h=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=B7ulgV/0yhdaMUg8tOzbRsPvCYjJb8I3tzF5dANUGBA=; b=f7J1sN/wHfgqgJXDIK5WAnWiegN/YWw0Qdixk9uqQa2PhaDAW05z1QOynX6WiL6NMnoWGH5F2P6S41m+sdqIoBBCz7uiFBULlaGFFxPRJw0e0eboH+1PBCdlY1hvtjUdpBAjsR1ydwNBeQIWba6N6XijWMP7E2APHnnhJUstoPg= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119975288309.91526609741004; Wed, 11 Sep 2024 22:46:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQx-0006VG-BB; Thu, 12 Sep 2024 01:31:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQH-0003eC-68 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:23 -0400 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 1socQF-00035K-3C for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:16 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7193010d386so14942b3a.1 for ; Wed, 11 Sep 2024 22:31:13 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119072; x=1726723872; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B7ulgV/0yhdaMUg8tOzbRsPvCYjJb8I3tzF5dANUGBA=; b=UVJx+1+0ZuYbxSl1r3TqglxbzTyqL24u1BZpjOaqmRUb7i2+gTIVEt7TnlCJPOVqlR L2IGck95KfGX52upsJ4Ng/Z72gUtCF2+PK2QuHvKTaaP9/04pM6gEYIv2y1Lxy2JMCJQ JvZcQZrj4ps2X4ksD0+QYMuoupmG+1JEPlcVuOXg0SSwJmsE+GfhsqjeLq2XlwqkGum8 vjpp2EythPK92Gfr2z2jaXe4ScYQ37Qh3lWG+W4wPtmSdiFJhB5WqmlfHSVI8M3p/rtI Yon1SkY5ggiLSl4V7cMmdsiO401OnkNPz+aydMH+73U17EEpHPQ5yr76EHgsgwtpdKFf SI7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119072; x=1726723872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B7ulgV/0yhdaMUg8tOzbRsPvCYjJb8I3tzF5dANUGBA=; b=i7LS4833Wftte2sbw74lFVG36eQ7zqe2REcx/tRo/jA/lHAAq8RXkIug1wNaQfnDyD QYthg7nlRpicnyP6FTcnYSqcTb52ipiVJhoxJCM4X6LHKfJlKSNbnXF61pRsdIa3foAS XBTakbhLbrlDjpcthl4Yp5anm9COsKXXYL7ZMkoxiKWbxxLgxk3LWaUy826WCJsuGo7h 6jmawWnhiCSGYOviMdXk2SDBW+yK6Bkt9GRjtM0l5hDDAU03olMb16umKZ99h5CXWURL S1dKzMVyhFo5fF2aJLNuMVU7ul8+8W5CQuFE79stXmv1xAvnf58K5CQAo6H5ZNABIQ/U plAA== X-Gm-Message-State: AOJu0Yz7RqVdWvFIdtypwmL3GryN5R9/pYyqMow4Klhax8ZyBN5CwmXR swGqPLpY7xmswS/2FIzi6IJvJ1t1S3C0DAGY9dqmI4Q34X0+r2iDChH5GQ== X-Google-Smtp-Source: AGHT+IHzBRYu2hGJ8CfGZx9UOtLNuldrBHc7EuWNHKAlQMqn6rO6/58YYq4cP7X24r5HjIOa6JZpUg== X-Received: by 2002:a05:6a00:1953:b0:717:bce8:f8a9 with SMTP id d2e1a72fcca58-7192606086fmr2623640b3a.1.1726119071968; Wed, 11 Sep 2024 22:31:11 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 23/47] hw/riscv/riscv-iommu: add DBG support Date: Thu, 12 Sep 2024 15:29:28 +1000 Message-ID: <20240912052953.2552501-24-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119976571116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach DBG support adds three additional registers: tr_req_iova, tr_req_ctl and tr_response. The DBG cap is always enabled. No on/off toggle is provided for it. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Reviewed-by: Alistair Francis Message-ID: <20240903201633.93182-11-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/riscv-iommu-bits.h | 17 +++++++++++ hw/riscv/riscv-iommu.c | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h index 96a994b9aa..6359ae0353 100644 --- a/hw/riscv/riscv-iommu-bits.h +++ b/hw/riscv/riscv-iommu-bits.h @@ -82,6 +82,7 @@ struct riscv_iommu_pq_record { #define RISCV_IOMMU_CAP_ATS BIT_ULL(25) #define RISCV_IOMMU_CAP_T2GPA BIT_ULL(26) #define RISCV_IOMMU_CAP_IGS GENMASK_ULL(29, 28) +#define RISCV_IOMMU_CAP_DBG BIT_ULL(31) #define RISCV_IOMMU_CAP_PAS GENMASK_ULL(37, 32) #define RISCV_IOMMU_CAP_PD8 BIT_ULL(38) #define RISCV_IOMMU_CAP_PD17 BIT_ULL(39) @@ -184,6 +185,22 @@ enum { RISCV_IOMMU_INTR_COUNT }; =20 +/* 5.24 Translation request IOVA (64bits) */ +#define RISCV_IOMMU_REG_TR_REQ_IOVA 0x0258 + +/* 5.25 Translation request control (64bits) */ +#define RISCV_IOMMU_REG_TR_REQ_CTL 0x0260 +#define RISCV_IOMMU_TR_REQ_CTL_GO_BUSY BIT_ULL(0) +#define RISCV_IOMMU_TR_REQ_CTL_NW BIT_ULL(3) +#define RISCV_IOMMU_TR_REQ_CTL_PID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_TR_REQ_CTL_DID GENMASK_ULL(63, 40) + +/* 5.26 Translation request response (64bits) */ +#define RISCV_IOMMU_REG_TR_RESPONSE 0x0268 +#define RISCV_IOMMU_TR_RESPONSE_FAULT BIT_ULL(0) +#define RISCV_IOMMU_TR_RESPONSE_S BIT_ULL(9) +#define RISCV_IOMMU_TR_RESPONSE_PPN RISCV_IOMMU_PPN_FIELD + /* 5.27 Interrupt cause to vector (64bits) */ #define RISCV_IOMMU_REG_ICVEC 0x02F8 #define RISCV_IOMMU_ICVEC_CIV GENMASK_ULL(3, 0) diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 50740442bb..135f461ccf 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -1769,6 +1769,50 @@ static void riscv_iommu_process_pq_control(RISCVIOMM= UState *s) riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_PQCSR, ctrl_set, ctrl_clr); } =20 +static void riscv_iommu_process_dbg(RISCVIOMMUState *s) +{ + uint64_t iova =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_TR_REQ_IOVA= ); + uint64_t ctrl =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_TR_REQ_CTL); + unsigned devid =3D get_field(ctrl, RISCV_IOMMU_TR_REQ_CTL_DID); + unsigned pid =3D get_field(ctrl, RISCV_IOMMU_TR_REQ_CTL_PID); + RISCVIOMMUContext *ctx; + void *ref; + + if (!(ctrl & RISCV_IOMMU_TR_REQ_CTL_GO_BUSY)) { + return; + } + + ctx =3D riscv_iommu_ctx(s, devid, pid, &ref); + if (ctx =3D=3D NULL) { + riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_TR_RESPONSE, + RISCV_IOMMU_TR_RESPONSE_FAULT | + (RISCV_IOMMU_FQ_CAUSE_DMA_DISABLED << 10)= ); + } else { + IOMMUTLBEntry iotlb =3D { + .iova =3D iova, + .perm =3D ctrl & RISCV_IOMMU_TR_REQ_CTL_NW ? IOMMU_RO : IOMMU_= RW, + .addr_mask =3D ~0, + .target_as =3D NULL, + }; + int fault =3D riscv_iommu_translate(s, ctx, &iotlb, false); + if (fault) { + iova =3D RISCV_IOMMU_TR_RESPONSE_FAULT | (((uint64_t) fault) <= < 10); + } else { + iova =3D iotlb.translated_addr & ~iotlb.addr_mask; + iova >>=3D TARGET_PAGE_BITS; + iova &=3D RISCV_IOMMU_TR_RESPONSE_PPN; + + /* We do not support superpages (> 4kbs) for now */ + iova &=3D ~RISCV_IOMMU_TR_RESPONSE_S; + } + riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_TR_RESPONSE, iova); + } + + riscv_iommu_reg_mod64(s, RISCV_IOMMU_REG_TR_REQ_CTL, 0, + RISCV_IOMMU_TR_REQ_CTL_GO_BUSY); + riscv_iommu_ctx_put(s, ref); +} + typedef void riscv_iommu_process_fn(RISCVIOMMUState *s); =20 static void riscv_iommu_update_icvec(RISCVIOMMUState *s, uint64_t data) @@ -1922,6 +1966,12 @@ static MemTxResult riscv_iommu_mmio_write(void *opaq= ue, hwaddr addr, =20 return MEMTX_OK; =20 + case RISCV_IOMMU_REG_TR_REQ_CTL: + process_fn =3D riscv_iommu_process_dbg; + regb =3D RISCV_IOMMU_REG_TR_REQ_CTL; + busy =3D RISCV_IOMMU_TR_REQ_CTL_GO_BUSY; + break; + default: break; } @@ -2094,6 +2144,9 @@ static void riscv_iommu_realize(DeviceState *dev, Err= or **errp) s->cap |=3D RISCV_IOMMU_CAP_SV32X4 | RISCV_IOMMU_CAP_SV39X4 | RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4; } + /* Enable translation debug interface */ + s->cap |=3D RISCV_IOMMU_CAP_DBG; + /* Report QEMU target physical address space limits */ s->cap =3D set_field(s->cap, RISCV_IOMMU_CAP_PAS, TARGET_PHYS_ADDR_SPACE_BITS); @@ -2150,6 +2203,12 @@ static void riscv_iommu_realize(DeviceState *dev, Er= ror **errp) stl_le_p(&s->regs_wc[RISCV_IOMMU_REG_IPSR], ~0); stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_ICVEC], 0); stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_DDTP], s->ddtp); + /* If debug registers enabled. */ + if (s->cap & RISCV_IOMMU_CAP_DBG) { + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_TR_REQ_IOVA], 0); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_TR_REQ_CTL], + RISCV_IOMMU_TR_REQ_CTL_GO_BUSY); + } =20 /* Memory region for downstream access, if specified. */ if (s->target_mr) { --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119959; cv=none; d=zohomail.com; s=zohoarc; b=h6HQ5O22ovqYMp5Ad8JIi8j3WOLkDNR/HaNbgUF2gmGXT2sf4uGOiiXudfYaGPc7Nlwx7Qdz6dpSQgUi7VzQyqF6blqwOACa3mcrmzZJtc4CdAQ9/yeJBmoCuNsM9BPRO5gxveeInZej1MF5QgIxzeWnUNvGc8wbRa5x7fmtRcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119959; h=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=W0QoSfGJXqOMmELOrOr90/RAPKmZ/9pld+RMp498JFM=; b=VFJmtW9MRP6mOVQEceJ3Bu3nsvyzq3asj3losoMO7mEFwfaDoT+ElXj4MmFucdu/N6Bi/nGv34h+YP2SFfLoFBvfVs4wEXC+LFbkn/YJugya8Fla25hIOqrEIyDWW7SebBvFuTCvXWnqy76fa65wcOv5m9uv4Oln1lxrrE6QO5E= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119959961708.833750297132; Wed, 11 Sep 2024 22:45:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQx-0006WD-Cy; Thu, 12 Sep 2024 01:31:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQJ-0003hU-0n for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:23 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQG-00035T-Kh for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:18 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-656d8b346d2so425699a12.2 for ; Wed, 11 Sep 2024 22:31:16 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119075; x=1726723875; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W0QoSfGJXqOMmELOrOr90/RAPKmZ/9pld+RMp498JFM=; b=MVZ/tHr9QEzVG18+mclv+Tixoxax8SvH7isStwA3eH3Mhe4GXg7FPj51Sh1uk/pgUh oUplAMeFRV8azGGPtWw53idDpJqmwx/V6TvSJOgZaMMU9mkKifBcPIUwSAvEyuDQXlub gPb/QedgeN8pczmhREL1xFPcUyhxRKvN9NyQUqWjcAQ2Xx3WWj8NIG5BF0qxmHWdlhru /UxRJM7xp4lWesFbyiA7q+saRdq2LgYMQadlWKoQWN8+cmo1uHzFEqgFQxorZCAYru33 Mzih5K5wzdwDGqncLJ9Q3ylBcp0vA6LxLSmsjrzicdire5zHLmdN7fSwe1VqpvKs4zvg u21g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119075; x=1726723875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W0QoSfGJXqOMmELOrOr90/RAPKmZ/9pld+RMp498JFM=; b=AriX8Jpafno9WcL5toM0aGamxTQKJTP2cM7ZWg0HcGOrwMKqBUZhium/2HP6xFJcQH JMtbjjj9MduE5RLXCehMCvl1U9yVf58rIxxO68KgEP1dgM4HBatzedI68K6fFPrM/Dpb pscuR1SKmVN2CCNOYaOifTEEQLqDNbhpWDd7r9BYRpNpREUEHE5o3ZOjXc0cEsBdFvVm CUHkNADjBPUp1OnbLKKMwRV1U2K4XpxGPb3evEZi/OaZ55ALtVGHSeT7taPK0deEl4KS 24kaq5n/uddos/3+fetgOGu8FhBDNumub1pMkP2k1JJkKsuiJVnNkcCNQPQhUiIH4Jo8 5u/g== X-Gm-Message-State: AOJu0YyNTryQBy6zCDdATFE28APEiORLBT4iLWqTxvasShXdI1x+eCQY Vh4MvFGP9TTR1fZZTF2g2ZM1BgeORwyilBUG/tompdPLMkRN2UldG8fwMA== X-Google-Smtp-Source: AGHT+IFINdLzsheOopuexKEJ90gMyuDC6sN9x8R4KB/vZvCjk2JCPxvtk2JhI+ADLuBgzprq+irWhQ== X-Received: by 2002:a05:6a21:164a:b0:1cf:54bd:393a with SMTP id adf61e73a8af0-1cf7620c101mr1916357637.37.1726119074955; Wed, 11 Sep 2024 22:31:14 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 24/47] qtest/riscv-iommu-test: add init queues test Date: Thu, 12 Sep 2024 15:29:29 +1000 Message-ID: <20240912052953.2552501-25-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=alistair23@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119960558116600 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza Add an additional test to further exercise the IOMMU where we attempt to initialize the command, fault and page-request queues. These steps are taken from chapter 6.2 of the RISC-V IOMMU spec, "Guidelines for initialization". It emulates what we expect from the software/OS when initializing the IOMMU. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Acked-by: Alistair Francis Message-ID: <20240903201633.93182-12-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- tests/qtest/libqos/riscv-iommu.h | 30 ++++++++ tests/qtest/riscv-iommu-test.c | 127 +++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) diff --git a/tests/qtest/libqos/riscv-iommu.h b/tests/qtest/libqos/riscv-io= mmu.h index d123efb41f..318db13799 100644 --- a/tests/qtest/libqos/riscv-iommu.h +++ b/tests/qtest/libqos/riscv-iommu.h @@ -62,6 +62,36 @@ =20 #define RISCV_IOMMU_REG_IPSR 0x0054 =20 +#define RISCV_IOMMU_REG_IVEC 0x02F8 +#define RISCV_IOMMU_REG_IVEC_CIV GENMASK_ULL(3, 0) +#define RISCV_IOMMU_REG_IVEC_FIV GENMASK_ULL(7, 4) +#define RISCV_IOMMU_REG_IVEC_PMIV GENMASK_ULL(11, 8) +#define RISCV_IOMMU_REG_IVEC_PIV GENMASK_ULL(15, 12) + +#define RISCV_IOMMU_REG_CQB 0x0018 +#define RISCV_IOMMU_CQB_PPN_START 10 +#define RISCV_IOMMU_CQB_PPN_LEN 44 +#define RISCV_IOMMU_CQB_LOG2SZ_START 0 +#define RISCV_IOMMU_CQB_LOG2SZ_LEN 5 + +#define RISCV_IOMMU_REG_CQT 0x0024 + +#define RISCV_IOMMU_REG_FQB 0x0028 +#define RISCV_IOMMU_FQB_PPN_START 10 +#define RISCV_IOMMU_FQB_PPN_LEN 44 +#define RISCV_IOMMU_FQB_LOG2SZ_START 0 +#define RISCV_IOMMU_FQB_LOG2SZ_LEN 5 + +#define RISCV_IOMMU_REG_FQT 0x0034 + +#define RISCV_IOMMU_REG_PQB 0x0038 +#define RISCV_IOMMU_PQB_PPN_START 10 +#define RISCV_IOMMU_PQB_PPN_LEN 44 +#define RISCV_IOMMU_PQB_LOG2SZ_START 0 +#define RISCV_IOMMU_PQB_LOG2SZ_LEN 5 + +#define RISCV_IOMMU_REG_PQT 0x0044 + typedef struct QRISCVIOMMU { QOSGraphObject obj; QPCIDevice dev; diff --git a/tests/qtest/riscv-iommu-test.c b/tests/qtest/riscv-iommu-test.c index 7f0dbd0211..c38a0a160d 100644 --- a/tests/qtest/riscv-iommu-test.c +++ b/tests/qtest/riscv-iommu-test.c @@ -33,6 +33,20 @@ static uint64_t riscv_iommu_read_reg64(QRISCVIOMMU *r_io= mmu, int reg_offset) return reg; } =20 +static void riscv_iommu_write_reg32(QRISCVIOMMU *r_iommu, int reg_offset, + uint32_t val) +{ + qpci_memwrite(&r_iommu->dev, r_iommu->reg_bar, reg_offset, + &val, sizeof(val)); +} + +static void riscv_iommu_write_reg64(QRISCVIOMMU *r_iommu, int reg_offset, + uint64_t val) +{ + qpci_memwrite(&r_iommu->dev, r_iommu->reg_bar, reg_offset, + &val, sizeof(val)); +} + static void test_pci_config(void *obj, void *data, QGuestAllocator *t_allo= c) { QRISCVIOMMU *r_iommu =3D obj; @@ -84,10 +98,123 @@ static void test_reg_reset(void *obj, void *data, QGue= stAllocator *t_alloc) g_assert_cmpuint(reg, =3D=3D, 0); } =20 +/* + * Common timeout-based poll for CQCSR, FQCSR and PQCSR. All + * their ON bits are mapped as RISCV_IOMMU_QUEUE_ACTIVE (16), + */ +static void qtest_wait_for_queue_active(QRISCVIOMMU *r_iommu, + uint32_t queue_csr) +{ + QTestState *qts =3D global_qtest; + guint64 timeout_us =3D 2 * 1000 * 1000; + gint64 start_time =3D g_get_monotonic_time(); + uint32_t reg; + + for (;;) { + qtest_clock_step(qts, 100); + + reg =3D riscv_iommu_read_reg32(r_iommu, queue_csr); + if (reg & RISCV_IOMMU_QUEUE_ACTIVE) { + break; + } + g_assert(g_get_monotonic_time() - start_time <=3D timeout_us); + } +} + +/* + * Goes through the queue activation procedures of chapter 6.2, + * "Guidelines for initialization", of the RISCV-IOMMU spec. + */ +static void test_iommu_init_queues(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QRISCVIOMMU *r_iommu =3D obj; + uint64_t reg64, q_addr; + uint32_t reg; + int k =3D 2; + + reg64 =3D riscv_iommu_read_reg64(r_iommu, RISCV_IOMMU_REG_CAP); + g_assert_cmpuint(reg64 & RISCV_IOMMU_CAP_VERSION, =3D=3D, 0x10); + + /* + * Program the command queue. Write 0xF to civ, fiv, pmiv and + * piv. With the current PCI device impl we expect 2 writable + * bits for each (k =3D 2) since we have N =3D 4 total vectors (2^k). + */ + riscv_iommu_write_reg32(r_iommu, RISCV_IOMMU_REG_IVEC, 0xFFFF); + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_IVEC); + g_assert_cmpuint(reg & RISCV_IOMMU_REG_IVEC_CIV, =3D=3D, 0x3); + g_assert_cmpuint(reg & RISCV_IOMMU_REG_IVEC_FIV, =3D=3D, 0x30); + g_assert_cmpuint(reg & RISCV_IOMMU_REG_IVEC_PMIV, =3D=3D, 0x300); + g_assert_cmpuint(reg & RISCV_IOMMU_REG_IVEC_PIV, =3D=3D, 0x3000); + + /* Alloc a 4*16 bytes buffer and use it to set cqb */ + q_addr =3D guest_alloc(t_alloc, 4 * 16); + reg64 =3D 0; + deposit64(reg64, RISCV_IOMMU_CQB_PPN_START, + RISCV_IOMMU_CQB_PPN_LEN, q_addr); + deposit64(reg64, RISCV_IOMMU_CQB_LOG2SZ_START, + RISCV_IOMMU_CQB_LOG2SZ_LEN, k - 1); + riscv_iommu_write_reg64(r_iommu, RISCV_IOMMU_REG_CQB, reg64); + + /* cqt =3D 0, cqcsr.cqen =3D 1, poll cqcsr.cqon until it reads 1 */ + riscv_iommu_write_reg32(r_iommu, RISCV_IOMMU_REG_CQT, 0); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_CQCSR); + reg |=3D RISCV_IOMMU_CQCSR_CQEN; + riscv_iommu_write_reg32(r_iommu, RISCV_IOMMU_REG_CQCSR, reg); + + qtest_wait_for_queue_active(r_iommu, RISCV_IOMMU_REG_CQCSR); + + /* + * Program the fault queue. Alloc a 4*32 bytes (instead of 4*16) + * buffer and use it to set fqb. + */ + q_addr =3D guest_alloc(t_alloc, 4 * 32); + reg64 =3D 0; + deposit64(reg64, RISCV_IOMMU_FQB_PPN_START, + RISCV_IOMMU_FQB_PPN_LEN, q_addr); + deposit64(reg64, RISCV_IOMMU_FQB_LOG2SZ_START, + RISCV_IOMMU_FQB_LOG2SZ_LEN, k - 1); + riscv_iommu_write_reg64(r_iommu, RISCV_IOMMU_REG_FQB, reg64); + + /* fqt =3D 0, fqcsr.fqen =3D 1, poll fqcsr.fqon until it reads 1 */ + riscv_iommu_write_reg32(r_iommu, RISCV_IOMMU_REG_FQT, 0); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_FQCSR); + reg |=3D RISCV_IOMMU_FQCSR_FQEN; + riscv_iommu_write_reg32(r_iommu, RISCV_IOMMU_REG_FQCSR, reg); + + qtest_wait_for_queue_active(r_iommu, RISCV_IOMMU_REG_FQCSR); + + /* + * Program the page-request queue. Alloc a 4*16 bytes buffer + * and use it to set pqb. + */ + q_addr =3D guest_alloc(t_alloc, 4 * 16); + reg64 =3D 0; + deposit64(reg64, RISCV_IOMMU_PQB_PPN_START, + RISCV_IOMMU_PQB_PPN_LEN, q_addr); + deposit64(reg64, RISCV_IOMMU_PQB_LOG2SZ_START, + RISCV_IOMMU_PQB_LOG2SZ_LEN, k - 1); + riscv_iommu_write_reg64(r_iommu, RISCV_IOMMU_REG_PQB, reg64); + + /* pqt =3D 0, pqcsr.pqen =3D 1, poll pqcsr.pqon until it reads 1 */ + riscv_iommu_write_reg32(r_iommu, RISCV_IOMMU_REG_PQT, 0); + + reg =3D riscv_iommu_read_reg32(r_iommu, RISCV_IOMMU_REG_PQCSR); + reg |=3D RISCV_IOMMU_PQCSR_PQEN; + riscv_iommu_write_reg32(r_iommu, RISCV_IOMMU_REG_PQCSR, reg); + + qtest_wait_for_queue_active(r_iommu, RISCV_IOMMU_REG_PQCSR); +} + static void register_riscv_iommu_test(void) { qos_add_test("pci_config", "riscv-iommu-pci", test_pci_config, NULL); qos_add_test("reg_reset", "riscv-iommu-pci", test_reg_reset, NULL); + qos_add_test("iommu_init_queues", "riscv-iommu-pci", + test_iommu_init_queues, NULL); } =20 libqos_init(register_riscv_iommu_test); --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119242; cv=none; d=zohomail.com; s=zohoarc; b=MqVifWkz/JR4x2CXCTnGWwbP8NoHB1V0zDzKKttTZlqa36rVHzVJr6bvMXvEqQOB+fzbvYJ7NYrHaA0mZymGAwBfPYlqCML5RK9MLBGFFVasPg4AyuKqWdp1CyMTfUnnGK/Z2jPDmwc3s7dBj1+Jk7sIxfGqm5bij3RtHSIpRKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119242; h=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=8QtNUqA5hzjqHQ1utnO5lqd/Ye1GPhrNMIuM3vhjm+0=; b=CKO6sMxOuxIbarZ7Ma4BZIEUhWhaBNq/zs/WxWZoAjS8+/5fowTjiAmnI3VY+ZPiKUDNadbqVIWQ16UxZhfAHeubGy8pQLNCnLwooWoQfHNXUj4TDXefxfmTVtzIQi0PN5R0MAMaFwsG/UKS9OVR4ULfXqgL+JOJVJIMP8M59c0= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119242836331.2880805199559; Wed, 11 Sep 2024 22:34:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQk-00052k-5C; Thu, 12 Sep 2024 01:31:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQN-0003kc-KF for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:25 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQJ-00035n-Gj for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:21 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7191f58054aso453604b3a.0 for ; Wed, 11 Sep 2024 22:31:19 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119078; x=1726723878; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8QtNUqA5hzjqHQ1utnO5lqd/Ye1GPhrNMIuM3vhjm+0=; b=B0g+g8jFB3lI0305ng+TqcInwe2LYe+xdSgiH37+wrdCyEnePmMPKfcfM9Pdq6TWMU K8UDFFBzdty8aHBW3XifgmpumRxBDQcjVD+dEaWX/H7xI++Zxh5KfGsRnX5YnUDrqsKR glFik/wmBLT+brI2FqFJKc/sFsWh+DK1JHRgQbVnU8uHGRK6u87sgtDxdG2N3pJlm9/W G6ACeDe/sK+d8A0AR5HwZMWd/zIVNJYCkmZRNy51n9iCAtBav9rprP3ow3D0erKDF67X vmArcz6CHYZ+wsmCF5mohti4+phvHD9GsF5rG0I44XzpAadE4jlOvGafhVzF3i7skIhn 079g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119078; x=1726723878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8QtNUqA5hzjqHQ1utnO5lqd/Ye1GPhrNMIuM3vhjm+0=; b=tv4CgKszLRuOVkmP325fFi/LHMbuOslYjrlNy7Dq9MAxs3zm3HlCTjmYMrU4H0KX04 HABuj4rXFYWkDt4empCBVLoj+LNJ9ZNk54XIJ+y9/6Rkri+uxwTVEA1ZKIYQYcGtX3DT +NBZu6rjvRWaHdCKDcv7ZvTJHBFEQUTrGAlimYgfHCcenuaPDmf8vetUQGZbZFrLHIyf 33htrjK4h2VtEjjUHZYd2PLPVFdo4vVhfFdwbrBUyOfNrjO91SuawkQlhf98CMPNOeUT aG9Kj6itxIhuM/6oXsJnL9NudqdT2veB74+hD/Ij17Uw3jlQI1vMNYIZCBF06zCBCVha zVnA== X-Gm-Message-State: AOJu0Yw1HAn86erGdDAV71xEs/OuH1/2IeYAyW+d/cku2d0bCe2+j550 bQniZaSB7cwFKA9Iuaduhk+Rs74AbPW+f/55Tkve+vjXR5Gk+6XvgeZ8EA== X-Google-Smtp-Source: AGHT+IHH95tQmZCBxavcXX2jMWDZ/OxbWcvZxPjMZjLVJLd/qUz9NzVgoxebllCydgb5wnSJ18N7Og== X-Received: by 2002:a05:6a20:db0a:b0:1d0:3a28:d2ad with SMTP id adf61e73a8af0-1d03a28d330mr311102637.33.1726119077660; Wed, 11 Sep 2024 22:31:17 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Alistair Francis Subject: [PULL 25/47] docs/specs: add riscv-iommu Date: Thu, 12 Sep 2024 15:29:30 +1000 Message-ID: <20240912052953.2552501-26-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=alistair23@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119244825116600 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza Add a simple guideline to use the existing RISC-V IOMMU support we just added. This doc will be updated once we add the riscv-iommu-sys device. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Message-ID: <20240903201633.93182-13-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- docs/specs/index.rst | 1 + docs/specs/riscv-iommu.rst | 90 ++++++++++++++++++++++++++++++++++++++ docs/system/riscv/virt.rst | 13 ++++++ 3 files changed, 104 insertions(+) create mode 100644 docs/specs/riscv-iommu.rst diff --git a/docs/specs/index.rst b/docs/specs/index.rst index 6495ed5ed9..ff5a1f03da 100644 --- a/docs/specs/index.rst +++ b/docs/specs/index.rst @@ -36,3 +36,4 @@ guest hardware that is specific to QEMU. vmgenid rapl-msr rocker + riscv-iommu diff --git a/docs/specs/riscv-iommu.rst b/docs/specs/riscv-iommu.rst new file mode 100644 index 0000000000..463f4cffb6 --- /dev/null +++ b/docs/specs/riscv-iommu.rst @@ -0,0 +1,90 @@ +.. _riscv-iommu: + +RISC-V IOMMU support for RISC-V machines +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +QEMU implements a RISC-V IOMMU emulation based on the RISC-V IOMMU spec +version 1.0 `iommu1.0`_. + +The emulation includes a PCI reference device, riscv-iommu-pci, that QEMU +RISC-V boards can use. The 'virt' RISC-V machine is compatible with this +device. + +riscv-iommu-pci reference device +-------------------------------- + +This device implements the RISC-V IOMMU emulation as recommended by the se= ction +"Integrating an IOMMU as a PCIe device" of `iommu1.0`_: a PCI device with = base +class 08h, sub-class 06h and programming interface 00h. + +As a reference device it doesn't implement anything outside of the specifi= cation, +so it uses a generic default PCI ID given by QEMU: 1b36:0014. + +To include the device in the 'virt' machine: + +.. code-block:: bash + + $ qemu-system-riscv64 -M virt -device riscv-iommu-pci,[optional_pci_opts= ] (...) + +This will add a RISC-V IOMMU PCI device in the board following any additio= nal +PCI parameters (like PCI bus address). The behavior of the RISC-V IOMMU is +defined by the spec but its operation is OS dependent. + +As of this writing the existing Linux kernel support `linux-v8`_, not yet = merged, +does not have support for features like VFIO passthrough. The IOMMU emula= tion +was tested using a public Ventana Micro Systems kernel repository in +`ventana-linux`_. This kernel is based on `linux-v8`_ with additional pat= ches that +enable features like KVM VFIO passthrough with irqbypass. Until the kerne= l support +is feature complete feel free to use the kernel available in the Ventana M= icro Systems +mirror. + +The current Linux kernel support will use the IOMMU device to create IOMMU= groups +with any eligible cards available in the system, regardless of factors suc= h as the +order in which the devices are added in the command line. + +This means that these command lines are equivalent as far as the current +IOMMU kernel driver behaves: + +.. code-block:: bash + + $ qemu-system-riscv64 \ + -M virt,aia=3Daplic-imsic,aia-guests=3D5 \ + -device riscv-iommu-pci,addr=3D1.0,vendor-id=3D0x1efd,device-id=3D= 0xedf1 \ + -device e1000e,netdev=3Dnet1 -netdev user,id=3Dnet1,net=3D192.168.= 0.0/24 \ + -device e1000e,netdev=3Dnet2 -netdev user,id=3Dnet2,net=3D192.168.= 200.0/24 \ + (...) + + $ qemu-system-riscv64 \ + -M virt,aia=3Daplic-imsic,aia-guests=3D5 \ + -device e1000e,netdev=3Dnet1 -netdev user,id=3Dnet1,net=3D192.168.= 0.0/24 \ + -device e1000e,netdev=3Dnet2 -netdev user,id=3Dnet2,net=3D192.168.= 200.0/24 \ + -device riscv-iommu-pci,addr=3D1.0,vendor-id=3D0x1efd,device-id=3D= 0xedf1 \ + (...) + +Both will create iommu groups for the two e1000e cards. + +Another thing to notice on `linux-v8`_ and `ventana-linux`_ is that the ke= rnel driver +considers an IOMMU identified as a Rivos device, i.e. it uses Rivos vendor= ID. To +use the riscv-iommu-pci device with the existing kernel support we need to= emulate +a Rivos PCI IOMMU by setting 'vendor-id' and 'device-id': + +.. code-block:: bash + + $ qemu-system-riscv64 -M virt \ + -device riscv-iommu-pci,vendor-id=3D0x1efd,device-id=3D0xedf1 (...) + +Several options are available to control the capabilities of the device, n= amely: + +- "bus": the bus that the IOMMU device uses +- "ioatc-limit": size of the Address Translation Cache (default to 2Mb) +- "intremap": enable/disable MSI support +- "ats": enable ATS support +- "off" (Out-of-reset translation mode: 'on' for DMA disabled, 'off' for '= BARE' (passthrough)) +- "s-stage": enable s-stage support +- "g-stage": enable g-stage support + +.. _iommu1.0: https://github.com/riscv-non-isa/riscv-iommu/releases/downlo= ad/v1.0/riscv-iommu.pdf + +.. _linux-v8: https://lore.kernel.org/linux-riscv/cover.1718388908.git.tje= znach@rivosinc.com/ + +.. _ventana-linux: https://github.com/ventanamicro/linux/tree/dev-upstream diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index 9a06f95a34..8e9a2e4dda 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -84,6 +84,19 @@ none``, as in =20 Firmware images used for pflash must be exactly 32 MiB in size. =20 +riscv-iommu support +------------------- + +The board has support for the riscv-iommu-pci device by using the following +command line: + +.. code-block:: bash + + $ qemu-system-riscv64 -M virt -device riscv-iommu-pci (...) + +Refer to :ref:`riscv-iommu` for more information on how the RISC-V IOMMU s= upport +works. + Machine-specific options ------------------------ =20 --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119974; cv=none; d=zohomail.com; s=zohoarc; b=Pk4aKXqGzpaGi237gYVTE2JlB9X0PEnPy389donD6eSX5go4AJvvV363OCKLMB03YJR+wytBFeg/3mZBEtScaZjjzy8ExLQkA+2a9iNVJwBZ0onNyPfBbEVqf5Ww2sMSCCjeHuRi2tYHC3M11LAYqSKk9y0PMlRxnXC66PvllD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119974; h=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=YVK9TI3s4BFy65/tNanCHqrpz7AQul+OpsDeLsd5Jhg=; b=CmCdBLFxedHdNOJqhiXq5emdVKyymsQbJ5P5yAo19tNTr35ig4u4x/5haOrKJks0cdPuVk7xZ3czrb/BRDL9Vk2iNTGcGnqfsy4/Ung0VSC0VTQSbx1cN4n9hdjOFI3Jl3y65St31opPVjvXCUvkI3AFwGCsG44te6R6LJcgydA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172611997473322.708807882547262; Wed, 11 Sep 2024 22:46:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQx-0006V9-Ah; Thu, 12 Sep 2024 01:31:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQP-0003v2-1m for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:28 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQN-00036A-0v for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:24 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7179069d029so372263b3a.2 for ; Wed, 11 Sep 2024 22:31:22 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119081; x=1726723881; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YVK9TI3s4BFy65/tNanCHqrpz7AQul+OpsDeLsd5Jhg=; b=awS8w8Qmi6CP3FT//LU3xKRetvCH8LGhOFE+yNU5uz7y3SrTjbe3DNIGT773gK8p1w 2tPc1phPN+cQFC5q46qXMkYZBFbRjVC8IYq3hEhFZPEW5lMcsn7FNOpbT9U7DpP6kNVC PbgpY2hpv6+zZJf5VtLRh/m0R0DZyq+3q++GZUPi5HKhsPrD5kNJ3k+WUDXKGh10Z6fJ RzFUoOeyIvSMXT1kfOdE3OEIdSKC6FebVdxmbrEDb5XhcCGZVO9d4FUQ4pSoN0vMIyAY 1spf1g/JI2OokNJdS+kPTBIfr08fgJnn8rv6MKJPcRgcpLXUbzCNH5vzgtzsI4P2iKzY UdeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119081; x=1726723881; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YVK9TI3s4BFy65/tNanCHqrpz7AQul+OpsDeLsd5Jhg=; b=jdLdSj+l72cOuPcMVbuT/OjtTj9yqsHhID4I6npimpWQJ2ko9bRNhaHkpJ7c55JZju mFh1ujaAVmeq6PqvuUx/4CCE2L4BKZ9x83ZIOXoCFIj8PIHUGk/24Q6LFFLRP52njlm1 Hge6YOKpvyLML7DiBJTqCr20MG+HNJefvUq39DWjpWAtTs6HiJACd8KRpZYystUedEGY CACBlZccDeLg9KcSD8b1TTtYKFogAp3a1E+AVxpEw7zrphr6rREWNREkuKbC9UKeJLZz WYFGKpANMEqyoi2Hm/uBxbB8tul8E5la6lbrPCSuVz+321xMOrruLiBwGlzvt62tjUwU rPNw== X-Gm-Message-State: AOJu0Yyg3OJXbsXXWw3zDsjUXFEYNT4szxfuQrBRTH1Y9mLVtgPB2tOh kjW1G2F9c0jQ0xTYSaERJGmCf2nNPyJbSXDDm8I2m4xU4nBbZO78sWcoqw== X-Google-Smtp-Source: AGHT+IEVoM5te6rM3HJ2Ot5U9uDXTKZRhUfY6u7/I8ETDgpBHJkylQcM1KIW9fWM2EoX0A3mw73oTA== X-Received: by 2002:a05:6a00:1804:b0:70d:1dcf:e2b4 with SMTP id d2e1a72fcca58-71926059119mr2673129b3a.1.1726119081211; Wed, 11 Sep 2024 22:31:21 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Jessica Clarke , Richard Henderson , Alistair Francis Subject: [PULL 26/47] bsd-user: Implement RISC-V CPU initialization and main loop Date: Thu, 12 Sep 2024 15:29:31 +1000 Message-ID: <20240912052953.2552501-27-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119976580116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added the initial implementation for RISC-V CPU initialization and main loop. This includes setting up the general-purpose registers and program counter based on the provided target architecture definitions. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-2-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_cpu.h | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 bsd-user/riscv/target_arch_cpu.h diff --git a/bsd-user/riscv/target_arch_cpu.h b/bsd-user/riscv/target_arch_= cpu.h new file mode 100644 index 0000000000..e17c910ae9 --- /dev/null +++ b/bsd-user/riscv/target_arch_cpu.h @@ -0,0 +1,39 @@ +/* + * RISC-V CPU init and loop + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_CPU_H +#define TARGET_ARCH_CPU_H + +#include "target_arch.h" + +#define TARGET_DEFAULT_CPU_MODEL "max" + +static inline void target_cpu_init(CPURISCVState *env, + struct target_pt_regs *regs) +{ + int i; + + for (i =3D 1; i < 32; i++) { + env->gpr[i] =3D regs->regs[i]; + } + + env->pc =3D regs->sepc; +} + +#endif /* TARGET_ARCH_CPU_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119249; cv=none; d=zohomail.com; s=zohoarc; b=K8Hi+gw51+GlR8WzXycu8K7c2L2++HArM2Q/w8t6mS4YScdmy2AsMJBjmCCbWrVTC6uWueI9qfYD3LZLu63yEN7QCTUYOXPM5vIiFDVC5McgnZyPQOaheXF+vq2PGQriFDUA5/7YcBhw1DMm6YhKWP8GKhZ//4Q6qRArN2F7Mlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119249; h=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=E8kqQOO07s/lXe7azl0i3Zls58n2NpD50p6A7IulL6U=; b=DOlkcjKHawb/JZx6afhQlHOJYbEIyW2Sxh/NZf3Xq6jm8+qbVnyyJIOM4kluVqfivJbNzQEQmW/w2kpC5TEZ49SwVMj2TqaxN3ZWVHhNKUsSJNAbt7RoqG1ZvsAgC2bfOieSy4VnZKgkKaIDW/dLM66e6bpskwvPcNPMKMY32ug= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119249500444.1050075230463; Wed, 11 Sep 2024 22:34:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR0-0006sI-16; Thu, 12 Sep 2024 01:32:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQT-0004C1-0c for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:32 -0400 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 1socQR-00036V-3F for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:28 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-719232ade93so509795b3a.2 for ; Wed, 11 Sep 2024 22:31:26 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119085; x=1726723885; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E8kqQOO07s/lXe7azl0i3Zls58n2NpD50p6A7IulL6U=; b=mcSteSlBtObYMgffV1oXWh2Gbr1JQ18AAmmSIrbKjciqk/NOtUuLrhJwVVqcX0G/q3 ZGDndwxkoH9gjpZodkzBYBb25Ahy3/WmJCf7ckt3WEeO3opyMFeyzNewTDMtLPbFX7j6 qexc42TDQmZc5m+Q14q/htaFhkGNSNIGYzICgbsx+7LqW5GPk+Y6JSs++mNAGqjY6lak LNmDlhQeHH+Ti6GWMbKK7+39q44G3r2M52KVrpiv7TPudHv8hOBYGalavJtKHmwW3p79 8AaMQc5LWzVGISuHWVXHjSywUSAG9eZAsPwQNRek36qA8c38stYfEqpiJb3mHCjtwND8 kJ9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119085; x=1726723885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E8kqQOO07s/lXe7azl0i3Zls58n2NpD50p6A7IulL6U=; b=iRr6PqEImgf10tzSSecpfcAsgySQggG6DQF8qNabqmSqxa4Q8OL2Da17p+Zfm9iYgQ dQo4K2141wvF8Ses02OHAr/WuFFrp970/BPNhAq3eUVwp+GzLOwhSd6U3WVMBvJi4a1S jyoC22RxHhw4POi0g2wWdRAuIS7ZuLpPVC9028LArPwSlCGpAM+3QF2hugPKzpM68vor i214KZ8mLOp2ZZ6qtryZxZbmN+KVEtxBCeZbEXy2zrU42vMrxl79zv0/KwRuBgqSqBXM LqDy0XbyYJvOQLQUen/zzbSNO5DjGwiGv6cKZGNn4Waj+WMqsPEOtULmubK+MqWXU89t wj+w== X-Gm-Message-State: AOJu0YzVX7X4zj5GTUZllNi5Gle9XBQ0AKFni+O8L+UUTSzfkS6yGWnJ rUYyL/jUSgtvi6Wx5BcBiFXwRQRePpBK1hSYkdcsywTOexIDCcXG4Ws+Pg== X-Google-Smtp-Source: AGHT+IGoECLeYMy/QdisTJx8qkw+47og9bgJWO/hw0VDS4uk/+zBn9afJ70lrMcTRJYqXX1cNPra7Q== X-Received: by 2002:a05:6a00:3e23:b0:717:8f0d:ec37 with SMTP id d2e1a72fcca58-71926206e36mr2172746b3a.25.1726119085088; Wed, 11 Sep 2024 22:31:25 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Jessica Clarke , Kyle Evans , Richard Henderson , Alistair Francis Subject: [PULL 27/47] bsd-user: Add RISC-V CPU execution loop and syscall handling Date: Thu, 12 Sep 2024 15:29:32 +1000 Message-ID: <20240912052953.2552501-28-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119250841116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Implemented the RISC-V CPU execution loop, including handling various exceptions and system calls. The loop continuously executes CPU instructions,processes exceptions, and handles system calls by invoking FreeBSD syscall handlers. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-3-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_cpu.h | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/bsd-user/riscv/target_arch_cpu.h b/bsd-user/riscv/target_arch_= cpu.h index e17c910ae9..ea2a8d1ace 100644 --- a/bsd-user/riscv/target_arch_cpu.h +++ b/bsd-user/riscv/target_arch_cpu.h @@ -36,4 +36,98 @@ static inline void target_cpu_init(CPURISCVState *env, env->pc =3D regs->sepc; } =20 +static inline void target_cpu_loop(CPURISCVState *env) +{ + CPUState *cs =3D env_cpu(env); + int trapnr; + abi_long ret; + unsigned int syscall_num; + int32_t signo, code; + + for (;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + signo =3D 0; + + switch (trapnr) { + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + case RISCV_EXCP_U_ECALL: + syscall_num =3D env->gpr[xT0]; + env->pc +=3D TARGET_INSN_SIZE; + /* Compare to cpu_fetch_syscall_args() in riscv/riscv/trap.c */ + if (TARGET_FREEBSD_NR___syscall =3D=3D syscall_num || + TARGET_FREEBSD_NR_syscall =3D=3D syscall_num) { + ret =3D do_freebsd_syscall(env, + env->gpr[xA0], + env->gpr[xA1], + env->gpr[xA2], + env->gpr[xA3], + env->gpr[xA4], + env->gpr[xA5], + env->gpr[xA6], + env->gpr[xA7], + 0); + } else { + ret =3D do_freebsd_syscall(env, + syscall_num, + env->gpr[xA0], + env->gpr[xA1], + env->gpr[xA2], + env->gpr[xA3], + env->gpr[xA4], + env->gpr[xA5], + env->gpr[xA6], + env->gpr[xA7] + ); + } + + /* + * Compare to cpu_set_syscall_retval() in + * riscv/riscv/vm_machdep.c + */ + if (ret >=3D 0) { + env->gpr[xA0] =3D ret; + env->gpr[xT0] =3D 0; + } else if (ret =3D=3D -TARGET_ERESTART) { + env->pc -=3D TARGET_INSN_SIZE; + } else if (ret !=3D -TARGET_EJUSTRETURN) { + env->gpr[xA0] =3D -ret; + env->gpr[xT0] =3D 1; + } + break; + case RISCV_EXCP_ILLEGAL_INST: + signo =3D TARGET_SIGILL; + code =3D TARGET_ILL_ILLOPC; + break; + case RISCV_EXCP_BREAKPOINT: + signo =3D TARGET_SIGTRAP; + code =3D TARGET_TRAP_BRKPT; + break; + case EXCP_DEBUG: + signo =3D TARGET_SIGTRAP; + code =3D TARGET_TRAP_BRKPT; + break; + default: + fprintf(stderr, "qemu: unhandled CPU exception " + "0x%x - aborting\n", trapnr); + cpu_dump_state(cs, stderr, 0); + abort(); + } + + if (signo) { + force_sig_fault(signo, code, env->pc); + } + + process_pending_signals(env); + } +} + #endif /* TARGET_ARCH_CPU_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119649; cv=none; d=zohomail.com; s=zohoarc; b=WzSrKdLSauNkbtCKNhvsUj9esIZqzC3u4DHqT+/5K4RPT21PtCNdiHDqm1wy3y87sgop5jVCu6Hls8517Buo/twqI7Dq2ipilvGbnX2o1h/xVkiqTMUagdclqqjT+1qCUh16QI5PsMnw+3eRa4sp3G8NUbbL+buD+NkHrk8TCN8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119649; h=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=qJALkI8HV3SBcr9TBDcg3UJ2jagYIjwgM/kVzVZonT8=; b=T2QAsuN9vtYZpAM2OHefJovyTbCou8fRFt3HCDF6aRVMMhqWml0DA3yUU0EKRNKuGWo5xtYhD7zMeRKan3uEYlhnFeXubG52BKcFfYuFT4V6L9hOt9jywMmERHAz1gW+t94FiIseYU/DZvI1sVM4a7RYUqIG2jnsiPKsWpQX45s= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119649890171.20909145615747; Wed, 11 Sep 2024 22:40:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR0-0006tB-1H; Thu, 12 Sep 2024 01:32:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQV-0004KR-HX for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:32 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQT-00036n-VL for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:31 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-71798a15ce5so1209263b3a.0 for ; Wed, 11 Sep 2024 22:31:29 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119088; x=1726723888; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qJALkI8HV3SBcr9TBDcg3UJ2jagYIjwgM/kVzVZonT8=; b=jACjA6K5UxpKhuOZmdr2teJoZ5M2RPf53Mr+TYvXf0dEQxCjsITZA9BMVCNcF/GKqi Kg9L1d3SgjW9pIVQyJOx5/W0ZzqTE7cEjeMM4SD5gdx4OdLJgK9p8zY/6ytzePfYCrqO 7cTcmzDsKFbBa/LDbhlSyIuzsgY82aDLgWiwOF6v3ygiJqi9Xs/J5m5TtEFAkGUDMWVa OGS556tXqbE+QpkDhLfAtcUnkg4w6Cm13EiBOZ9E1npNAVhywFvsep6v9cs9sa9oDiOc /aSPCzNYd3Ve60a8N+I9FxNNErKW6eDZEgLuE/CX/fLd19bL4ISSDjKbQuZQgt5VUscz oJCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119088; x=1726723888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qJALkI8HV3SBcr9TBDcg3UJ2jagYIjwgM/kVzVZonT8=; b=WBvlZZep50CN9krIrA8YHzeZrTOcJ5EamtXKwTTkVRlwQSrjfFdVWoY3lxEr0WcxOl 5bDg3T4RSMLSYiXEYnbf9lPBiF+uBDOC4YxYlGGrbx3VmK612+J6WoJ4b/lLOS6cmi/t cEJXciFBL8bt9RurAJtvwJU9L1A7JqluyWeDnaRnroijTdm20/zAG2mFN//8FwpGwc6r EKVppdBTmwsz7JD7Yn3ZqdAs7MZSyN1l7YRU5GrX0Osl7QvTOQ0KEqKdNoKFriHqsd8m 9axdSLyf5ZsEydyn7AQ0DFQUShq9pecXf80uGlfzOavGFMhdBxYM9E7K1eyLXWoiLvJk No4w== X-Gm-Message-State: AOJu0YwQpoVExtRC3QBu/12NwJVShkBq5dgheXp+UjPAngrZ841qrnLz WZ3SNEgOXMDeSnZG1A/sBFCLlQfKSqucrtTN2yO0sL1jaCr7lzd7rHf2qQ== X-Google-Smtp-Source: AGHT+IGdvC2c7mVFo+8JYHgrsqCC31/1y5aARZNbfvqJsaOvnEgf38NhRRcjhv5kr67guYLSzIVy4g== X-Received: by 2002:a05:6a21:1190:b0:1cf:49a6:992a with SMTP id adf61e73a8af0-1cf758ddaacmr2710725637.21.1726119088373; Wed, 11 Sep 2024 22:31:28 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 28/47] bsd-user: Implement RISC-V CPU register cloning and reset functions Date: Thu, 12 Sep 2024 15:29:33 +1000 Message-ID: <20240912052953.2552501-29-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119651618116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added functions for cloning CPU registers and resetting the CPU state for RISC-V architecture. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-4-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_cpu.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bsd-user/riscv/target_arch_cpu.h b/bsd-user/riscv/target_arch_= cpu.h index ea2a8d1ace..57abfbd556 100644 --- a/bsd-user/riscv/target_arch_cpu.h +++ b/bsd-user/riscv/target_arch_cpu.h @@ -130,4 +130,18 @@ static inline void target_cpu_loop(CPURISCVState *env) } } =20 +static inline void target_cpu_clone_regs(CPURISCVState *env, target_ulong = newsp) +{ + if (newsp) { + env->gpr[xSP] =3D newsp; + } + + env->gpr[xA0] =3D 0; + env->gpr[xT0] =3D 0; +} + +static inline void target_cpu_reset(CPUArchState *env) +{ +} + #endif /* TARGET_ARCH_CPU_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119670; cv=none; d=zohomail.com; s=zohoarc; b=mC5CNUgLtxh1YfjyePWGLkRjYu/JjSovTwKla0MGnum0wGnjmPwSTEQ0RvfNTYAIgPxKruaIu6rZ2M39Wfw6HoATyDP4AgTiey9WbgmujpEcegcBQXtKo680ghTuJUbSot2Y5yRvv+gmw6pDuQURGFe80jrzYHzHvTBlt9UfqUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119670; h=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=7qpB4NVt4C+I5VfPrM9R/rMjCMRzZy9LsNvhPuKirm0=; b=i9JhK63mBwok0YvZ8LEofQWBR0t6NWyF+aEIxS2axSwQLUwM8P/bUSKqklLXrkmmM7adK+6fah0rI88iyjL3+FulnOBZcbugVcqhkRbQ/sX5pafFv7EKSveeKmz1yxcZIP+2J3cUBvO+NDTcg3qnxhqljJPJYdaGvlZWr8GnfQA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119670039328.66601544351363; Wed, 11 Sep 2024 22:41:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socQp-000571-1o; Thu, 12 Sep 2024 01:31:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQZ-0004dD-Cb for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:36 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQX-00038F-E2 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:35 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-71798a15ce5so1209296b3a.0 for ; Wed, 11 Sep 2024 22:31:32 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119092; x=1726723892; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7qpB4NVt4C+I5VfPrM9R/rMjCMRzZy9LsNvhPuKirm0=; b=cFCE5OH4njKvFAp3qnUwT0lrwRZzjdynSyWdTe7WP2+9UESztFf+A5vS7EHrIoZZ7i ujjni/JBkUXp4AiZpuFOnnlvU7Q6YhaVqP+02p5ywIn28FqAm6Jva+85Al4BPFNPbVKR 23O2ELbgalKdSSpTHa3YxxcRSTXfNdKphH0nxPStF3e4Umn2VFy/5W9t4e4ROlJV3YUk kRUZ4gQW1G7qcNdCoH7I85P/K9ZKWqJL2BQXYiMBzo237tmdUhR5Gav6PYXUc3cKbGBD 5lz3GdwIoCby3Fab08iOZCvd94rP61YUaPuctfHbMpjS0OHIOPx5J/tKw2/YRQPyItWT QcuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119092; x=1726723892; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qpB4NVt4C+I5VfPrM9R/rMjCMRzZy9LsNvhPuKirm0=; b=FYXpdL/FTasPieseRuuMdYb9T4GwtXJwImkUE8DWF2IVTLalOa/+DG/yJktuI457Zl O1Eb2Hlv8JnWdDMFK1KLJdxurz7f9JeP6oXQqNOPCwP1VU5gdYiq67Y6g0O6pfAOK9ZJ 4YBRaEsB9HhSdspyZHDVzU95C9ktLrNerDxaF30PM2ibnXbFkmmrCskj//BpRTJT7tB6 O5O7WWfpuAQlahptF/68a/G8np97TVuSb5qdLwFdJyyvS2dss54zdgJtzcfSkXHiJYry H/G4FLVkg0zK88RRHp8+VHZH3keBwHLEXDIe3Tx+p0wOyHuS5gAfW+3cccAj/jiSNMQ5 uvMA== X-Gm-Message-State: AOJu0YzpZTrORxnl/6/fCOqWeX/ePaJ7QuodmU43S3NLj2T5p81ENZWu aCHaARrPxpP3FnfEE5lPa5Nl96zl/YQ9VEm7dZ7rnX5n9jmRvRmh8/qjrQ== X-Google-Smtp-Source: AGHT+IHzM7zT9cRQyeTw24pRSPnTlYdyaU63H69Rv0q6xKrr4PyasAE/IUpXZcPvHpGsYtO6MkfCdQ== X-Received: by 2002:a05:6a00:1d96:b0:714:2336:fa91 with SMTP id d2e1a72fcca58-71907f71a66mr16316061b3a.14.1726119091588; Wed, 11 Sep 2024 22:31:31 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 29/47] bsd-user: Implement RISC-V TLS register setup Date: Thu, 12 Sep 2024 15:29:34 +1000 Message-ID: <20240912052953.2552501-30-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=alistair23@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119671494116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Included the prototype for the 'target_cpu_set_tls' function in the 'target_arch.h' header file. This function is responsible for setting the Thread Local Storage (TLS) register for RISC-V architecture. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-5-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch.h | 27 +++++++++++++++++++++++++++ bsd-user/riscv/target_arch_cpu.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 bsd-user/riscv/target_arch.h create mode 100644 bsd-user/riscv/target_arch_cpu.c diff --git a/bsd-user/riscv/target_arch.h b/bsd-user/riscv/target_arch.h new file mode 100644 index 0000000000..26ce07f343 --- /dev/null +++ b/bsd-user/riscv/target_arch.h @@ -0,0 +1,27 @@ +/* + * RISC-V specific prototypes + * + * Copyright (c) 2019 Mark Corbin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_H +#define TARGET_ARCH_H + +#include "qemu.h" + +void target_cpu_set_tls(CPURISCVState *env, target_ulong newtls); + +#endif /* TARGET_ARCH_H */ diff --git a/bsd-user/riscv/target_arch_cpu.c b/bsd-user/riscv/target_arch_= cpu.c new file mode 100644 index 0000000000..44e25d2ddf --- /dev/null +++ b/bsd-user/riscv/target_arch_cpu.c @@ -0,0 +1,29 @@ +/* + * RISC-V CPU related code + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" + +#include "target_arch.h" + +#define TP_OFFSET 16 + +/* Compare with cpu_set_user_tls() in riscv/riscv/vm_machdep.c */ +void target_cpu_set_tls(CPURISCVState *env, target_ulong newtls) +{ + env->gpr[xTP] =3D newtls + TP_OFFSET; +} --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119709; cv=none; d=zohomail.com; s=zohoarc; b=B9I/uK9XZpvP3VzgSSsO5BbbncBDWhsOhIfZVur2aqTxI5qBWY/3Q0m2pU0CX9hiQxCrxcnYzbdSHuiaUzA7/lVL+pcBxeYuEYcdCsTT+ub7JAb/2VknTBb5b1uhaI+XbScl99ZOcDS+sTVWXtXDebXQ23hPT/aAhSt9zRFWNhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119709; h=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=OWRNqBOLFq4FyL64x5nOZ4nnL8+3dptfcD0f4BZvp8g=; b=Se3R4ElRazvshKRy2HkisMl+1VCoHKFI+TO39NGcA63Az4zyVlqsxlnWLM0uxGuUXx6ZH688qMJPIQk9WDNZbg+wvbcPjCgHqTELOprmzn/vz2hw2JS8HybphUPRTmJtpji8EIHOrNPQIeHp+KP+kWbXzzo7SjBJs0Fi8JixaD4= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17261197098350.39535163524874406; Wed, 11 Sep 2024 22:41:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR2-0007HY-Iv; Thu, 12 Sep 2024 01:32:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQd-00053k-Op for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:40 -0400 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 1socQb-00038n-7I for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:39 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7193010d386so15145b3a.1 for ; Wed, 11 Sep 2024 22:31:36 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119095; x=1726723895; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OWRNqBOLFq4FyL64x5nOZ4nnL8+3dptfcD0f4BZvp8g=; b=FxNrfpRyyRUohmHnJel6/VdwdlecvR6yiA56tpJkeCOex1A94HWngyeVspf2TmXoeT LUs6g8nf8NFIeaqW5+c2YIS8tnVzOka/m7LLM+IR6NLHbOtJ/BjQVndeGj0zqgf3xaOg I5hNn1G34rkcbMRCIiOfO11bTCmTIIS3twb8ptc3gDV+vA1waDNJrhp2ddssCnEnl5Nc UYQnnunc5m9/w7Tr8mw7OshmWYtrFUO5aO7ADQ4X7nskZiBRqwx0WUIyPRVxmNe2stNZ Md/2uWZWzXDIJDyfpmjHsRknVc5OZYTUnD1n8IjeiKjNe59f82WSlSh9UOfG0Hscrxs+ sgyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119095; x=1726723895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OWRNqBOLFq4FyL64x5nOZ4nnL8+3dptfcD0f4BZvp8g=; b=ta485MSiOMFoWXVeyoaISIHsWbRwB/iIWHcvd1ElfWJdXSFa+v72HmC2oQN5NpwXbC tZqFOtFavZeBJ+EQIjwgIue7flEf1pCGgeUyc9EoHdkhmFucxYU44XVe4cTn06fJUnGE KPFNRgy+URtcKg420idicdTx1lWojtSfYuLVqiTeOlBQNibWEsGGqI/rmdtLDwWsqnnd ZaJSkkxHZNou5CrqxrKCOkTnesB7FBE7fyYwyd/aLRtWwkOVvJaJB7NSsYhSo6lJlr9x tbXyncC7IHo3K0jfDq43fSAclaPdMtyJg5kSfgFqAyKWKSIAhWkkCpN5FV8HbyjvflZX STWw== X-Gm-Message-State: AOJu0Yze0FuJ4i1zfvp1vAc100hHAd1y3Buis4C0dg2/BtVeWK53i4f5 MYXW9kvERVZJhfy3OYCayIudEtv/cojsWrRiq4/aWxpQESzeZlEGtD+uEw== X-Google-Smtp-Source: AGHT+IEyDw/nz2T4O3EeoQBhyYl9xwnRvpNnUZy8+M+BrRtkthzZepjosIjEMfqZLbtJnlMLUP59WQ== X-Received: by 2002:a05:6a00:1a93:b0:718:d519:20de with SMTP id d2e1a72fcca58-7192608f698mr2278081b3a.13.1726119095107; Wed, 11 Sep 2024 22:31:35 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Kyle Evans , Richard Henderson , Alistair Francis Subject: [PULL 30/47] bsd-user: Add RISC-V ELF definitions and hardware capability detection Date: Thu, 12 Sep 2024 15:29:35 +1000 Message-ID: <20240912052953.2552501-31-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=alistair23@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119711550116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Introduced RISC-V specific ELF definitions and hardware capability detection. Additionally, a function to retrieve hardware capabilities ('get_elf_hwcap') is implemented, which returns the common bits set in each CPU's ISA strings. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-6-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_elf.h | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bsd-user/riscv/target_arch_elf.h diff --git a/bsd-user/riscv/target_arch_elf.h b/bsd-user/riscv/target_arch_= elf.h new file mode 100644 index 0000000000..4eb915e61e --- /dev/null +++ b/bsd-user/riscv/target_arch_elf.h @@ -0,0 +1,42 @@ +/* + * RISC-V ELF definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_ELF_H +#define TARGET_ARCH_ELF_H + +#define elf_check_arch(x) ((x) =3D=3D EM_RISCV) +#define ELF_START_MMAP 0x80000000 +#define ELF_ET_DYN_LOAD_ADDR 0x100000 +#define ELF_CLASS ELFCLASS64 + +#define ELF_DATA ELFDATA2LSB +#define ELF_ARCH EM_RISCV + +#define ELF_HWCAP get_elf_hwcap() +static uint32_t get_elf_hwcap(void) +{ + RISCVCPU *cpu =3D RISCV_CPU(thread_cpu); + + return cpu->env.misa_ext_mask; +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +#endif /* TARGET_ARCH_ELF_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119785; cv=none; d=zohomail.com; s=zohoarc; b=PTaasJN199oQmAaO9oHbKQwPB8+hfXgJme4mLVNjKM1QK9MQQtmuLTRQ2yflhq4SVG+pHTtJa1OxkE/PiIOnrwem1NaSC0gdzKzz01tz9UE4krgK9Kh/HDSJcNjikM5q1danMweQWjXPumPvuo4vGJmvrHRiuxJQS/baQ3D5H+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119785; h=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=1j2Ad7p2xrt5eoNNWaCw2vkgAgSrMVEmLQC+U7vNLW4=; b=L8xMRMjDRN/hkTkuhj3AtHL6DwE8XLqlFzcRlLpxfXldut+CB+Jry/PZ/lFvDf8RQ7euEKMsVS9DUsfq58vwfgP4IJL1bsiojmhFeoV53xYZaUbj+gUEyqI7wOCfOa0RmfLaRa3y0t4b+wtJjbmtZIPkokQeb4lA5GYKkDXOyFg= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119785776383.68253291770884; Wed, 11 Sep 2024 22:43:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR2-0007GL-Gg; Thu, 12 Sep 2024 01:32:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQg-0005Dd-5T for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:46 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQe-00038x-66 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:41 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-718e6299191so292203b3a.2 for ; Wed, 11 Sep 2024 22:31:39 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119098; x=1726723898; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1j2Ad7p2xrt5eoNNWaCw2vkgAgSrMVEmLQC+U7vNLW4=; b=bEG43uRSK7cAsysAvnDQd3o7UBOwl2Rhh2OG78GJWeCc5tFWf7eqoJIZou4tugG/E8 SxSq+npEB4EllHLdoLAKkIidRTiX24frU4PrrrMcU38ZeNR47szcT128dHPX9yun+XpS BMH9FR7fIyCplZAN6wK+8HxdSnutSAgMuiZaVInBStjRvAPbpnEny0KCzVrXH3jiL73f ZJ6MVvOf0hFMn7kbdMH4eL/UI4aWCVueoSl/rlzPDkpVr+zoPyRKxyKZgaYgZ04ll3Sg tPSCAYZaS6qzJ1M3i8mCiVwzFGS3/uNtZzKKTzBoUWD4b0L/pvSxmvAMrf8++szJ46dI ZSVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119098; x=1726723898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1j2Ad7p2xrt5eoNNWaCw2vkgAgSrMVEmLQC+U7vNLW4=; b=SuCWHSEkr2B/7AOZiV2LJ1ImMTRdar5823ngFJNug2JW9ryPYtaqJaZd1itsk89Zvq o9nVwcc8lEn3A09kw4ayq1qZtD0OmxtkaSuthqeKeeRHda6EXMLi8BxT+IvODIjmMeSh xHZPpZY1BssXrU9QwU0/jEAqLMuSEuQ0rUfz0lSVF0XxwXbftU03nt75wl3q1W3HwSvb kmhvcPoiciPGNd3y42IzTcxSQjWdhcYn+on2KFHoUlr/DkYC9G1nEuvYFEFVHAAH6TrY UiesJzFtcvR+3Bw0hIkgUagmaYkpzH+1hyqR7gLIptac1OAdGl2aSUQjvkFiJbbZf9wY F39A== X-Gm-Message-State: AOJu0YxLAskttLW0cuYL53MS2qG/M9e9UZ383Hi5+NRuJJUNpJoPDKp3 lzv4kHI1x6cj7V1OjKNEaIvdDr/Q5dRLbLxKk2EEd2gMx61eUpsRgg5M3A== X-Google-Smtp-Source: AGHT+IHtgNVxIy7QkQG1DfSA+76sFMFlvDw4tmfxxnElxRH9GHWd/JbgYKXhdfx1QRjRN88iDe+5ug== X-Received: by 2002:a05:6a00:2e11:b0:717:85a0:1ddb with SMTP id d2e1a72fcca58-7192606c443mr2937406b3a.10.1726119098438; Wed, 11 Sep 2024 22:31:38 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 31/47] bsd-user: Define RISC-V register structures and register copying Date: Thu, 12 Sep 2024 15:29:36 +1000 Message-ID: <20240912052953.2552501-32-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=alistair23@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119787962116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added definitions for RISC-V register structures, including general-purpose registers and floating-point registers, in 'target_arch_reg.h'. Implemented the 'target_copy_regs' function to copy register values from the CPU state to the target register structure, ensuring proper endianness handling using 'tswapreg'. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-7-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_reg.h | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 bsd-user/riscv/target_arch_reg.h diff --git a/bsd-user/riscv/target_arch_reg.h b/bsd-user/riscv/target_arch_= reg.h new file mode 100644 index 0000000000..12b1c96b61 --- /dev/null +++ b/bsd-user/riscv/target_arch_reg.h @@ -0,0 +1,88 @@ +/* + * RISC-V register structures + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_REG_H +#define TARGET_ARCH_REG_H + +/* Compare with riscv/include/reg.h */ +typedef struct target_reg { + uint64_t ra; /* return address */ + uint64_t sp; /* stack pointer */ + uint64_t gp; /* global pointer */ + uint64_t tp; /* thread pointer */ + uint64_t t[7]; /* temporaries */ + uint64_t s[12]; /* saved registers */ + uint64_t a[8]; /* function arguments */ + uint64_t sepc; /* exception program counter */ + uint64_t sstatus; /* status register */ +} target_reg_t; + +typedef struct target_fpreg { + uint64_t fp_x[32][2]; /* Floating point registers */ + uint64_t fp_fcsr; /* Floating point control reg */ +} target_fpreg_t; + +#define tswapreg(ptr) tswapal(ptr) + +/* Compare with struct trapframe in riscv/include/frame.h */ +static inline void target_copy_regs(target_reg_t *regs, + const CPURISCVState *env) +{ + + regs->ra =3D tswapreg(env->gpr[1]); + regs->sp =3D tswapreg(env->gpr[2]); + regs->gp =3D tswapreg(env->gpr[3]); + regs->tp =3D tswapreg(env->gpr[4]); + + regs->t[0] =3D tswapreg(env->gpr[5]); + regs->t[1] =3D tswapreg(env->gpr[6]); + regs->t[2] =3D tswapreg(env->gpr[7]); + regs->t[3] =3D tswapreg(env->gpr[28]); + regs->t[4] =3D tswapreg(env->gpr[29]); + regs->t[5] =3D tswapreg(env->gpr[30]); + regs->t[6] =3D tswapreg(env->gpr[31]); + + regs->s[0] =3D tswapreg(env->gpr[8]); + regs->s[1] =3D tswapreg(env->gpr[9]); + regs->s[2] =3D tswapreg(env->gpr[18]); + regs->s[3] =3D tswapreg(env->gpr[19]); + regs->s[4] =3D tswapreg(env->gpr[20]); + regs->s[5] =3D tswapreg(env->gpr[21]); + regs->s[6] =3D tswapreg(env->gpr[22]); + regs->s[7] =3D tswapreg(env->gpr[23]); + regs->s[8] =3D tswapreg(env->gpr[24]); + regs->s[9] =3D tswapreg(env->gpr[25]); + regs->s[10] =3D tswapreg(env->gpr[26]); + regs->s[11] =3D tswapreg(env->gpr[27]); + + regs->a[0] =3D tswapreg(env->gpr[10]); + regs->a[1] =3D tswapreg(env->gpr[11]); + regs->a[2] =3D tswapreg(env->gpr[12]); + regs->a[3] =3D tswapreg(env->gpr[13]); + regs->a[4] =3D tswapreg(env->gpr[14]); + regs->a[5] =3D tswapreg(env->gpr[15]); + regs->a[6] =3D tswapreg(env->gpr[16]); + regs->a[7] =3D tswapreg(env->gpr[17]); + + regs->sepc =3D tswapreg(env->pc); +} + +#undef tswapreg + +#endif /* TARGET_ARCH_REG_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119167; cv=none; d=zohomail.com; s=zohoarc; b=nWz6AToBTn+pE9lyftDXwz4bOXmLDt5eZ+O4/Hqzifu6jZ3iCfM1uV8kIbiwWb9x4T/8aCksAjb5a65jxoExKOfJXwPdfTtkcgchKQ2gLxiovc5qatEQ/eLHZ6D8iukb5+JGiDoYSJ61+aMMjj4UiL80tKoYJUub+wFdpu64LPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119167; h=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=Z3t80eNs9kvylNawc0Wkcda6DFCgx+hJ52Hiw8JLovs=; b=ZboYuf0vS1WC2cSgEGLrac97MtDhMqGIYFM2/5I04vbkPgQ3C1A1tNujTjtmOWrtqfaDIYqbjsfOxKbASxEIWxNzUoSNGo4yI4GO/YtIMOjHKAf+nuulOE1PXthLY620lVKOX/zvaNFD0JhHEJSm7cfYpc9T99nRABkTVHOboMA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119166899598.2313525692775; Wed, 11 Sep 2024 22:32:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR9-00082M-8w; Thu, 12 Sep 2024 01:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQk-0005W2-Ag for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:51 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQi-00039A-BZ for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:45 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7d82b0ebd51so249959a12.2 for ; Wed, 11 Sep 2024 22:31:42 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119102; x=1726723902; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z3t80eNs9kvylNawc0Wkcda6DFCgx+hJ52Hiw8JLovs=; b=ZOUVuU5/ZZBiJinRmKznjzWXAHDkIZye6KgiVsjLdztPPac+wyX/wFtvb36eKf1XP6 ZX8LwYeA4Ae1+A/sFB7yEKVxgzy06IC1lbH+VdDuiRw2kpKJFywLBWq3NUYbyeGHZi/4 QOrN1qw2WDTO73/iUwjdn7u7EiUL2pZpbpFD2aJZEid2JKVur87jTWgLZkCAclduRqUc BdhcC6XBReB4WDvxordBG4Erw9dYigG34rGZLLRyXkvGXRsUrM4QNWx+3Py6J34Tw3oD OXWnIeN5hlxXvbxGMoVh5txpnNzfv27SZOnq7IBknmBNf9jCZrkflP2QO7j1UgWfu4Tb pKLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119102; x=1726723902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z3t80eNs9kvylNawc0Wkcda6DFCgx+hJ52Hiw8JLovs=; b=a7wtYu5wB4DY1HR7ATF92KutKMaATIPUBzAiKw1Ya2b9xWcnmtFdeBvgKVQFYnf8Cb XVIZrimSXVp+WVhGIwviX+qhCqJBiuIha6cxTjrWu22IIdLoh9dSJc7q89PyHcgh57lP ScFzbEdLAQKGDsJNoVC55Z9RsK83ECQbpHNCOp6AWmR8rGX/Teb06qXATJlJi9mmBJpf vgBgglIjzKskDGd+yG/Voz8U6Cq6OQiZ4N9dPsMCxGOZRNvnWzFc/0WCNioAe9dR1Eeu VzV2FVnus2rmzYhKpbhmQE8hR0m9+5xj96IsCTka60Utkb1imqUxfG7kQBHPNBpZb6/U 6XpA== X-Gm-Message-State: AOJu0YzH3VPbrlLJIxFMU0mGiC76o+m04BgFdGJJxzZcAPRPBFmmB7Fh 5EnZ4j/ISIO3FEDDwnxtLwWkXE3bWLYikhAs1dwDGRjpbEEXC8lrG/5Mug== X-Google-Smtp-Source: AGHT+IFD2eOMSa4x5uX3ITCPQT15QXVoxW/oxrdnJ5YHgBfq55Pzq+1iw2SJDqRJQ6qBpBuy1Me4/A== X-Received: by 2002:a05:6a20:43a0:b0:1cf:38cf:df92 with SMTP id adf61e73a8af0-1cf76067aa4mr2244108637.30.1726119101624; Wed, 11 Sep 2024 22:31:41 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 32/47] bsd-user: Add RISC-V signal trampoline setup function Date: Thu, 12 Sep 2024 15:29:37 +1000 Message-ID: <20240912052953.2552501-33-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=alistair23@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119168672116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Implemented the 'setup_sigtramp' function for setting up the signal trampoline code in the RISC-V architecture. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-8-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_sigtramp.h | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bsd-user/riscv/target_arch_sigtramp.h diff --git a/bsd-user/riscv/target_arch_sigtramp.h b/bsd-user/riscv/target_= arch_sigtramp.h new file mode 100644 index 0000000000..83345f3961 --- /dev/null +++ b/bsd-user/riscv/target_arch_sigtramp.h @@ -0,0 +1,42 @@ +/* + * RISC-V sigcode + * + * Copyright (c) 2019 Mark Corbin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_SIGTRAMP_H +#define TARGET_ARCH_SIGTRAMP_H + +/* Compare with sigcode() in riscv/riscv/locore.S */ +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, + unsigned sys_sigreturn) +{ + int i; + uint32_t sys_exit =3D TARGET_FREEBSD_NR_exit; + + static const uint32_t sigtramp_code[] =3D { + /*1*/ const_le32(0x00010513), /*mv a0, sp*/ + /*2*/ const_le32(0x00050513 + (sigf_uc << 20)), /*addi a0,a0,sigf= _uc*/ + /*3*/ const_le32(0x00000293 + (sys_sigreturn << 20)),/*li t0,sys_sigre= turn*/ + /*4*/ const_le32(0x00000073), /*ecall*/ + /*5*/ const_le32(0x00000293 + (sys_exit << 20)), /*li t0,sys_exit*/ + /*6*/ const_le32(0x00000073), /*ecall*/ + /*7*/ const_le32(0xFF1FF06F) /*b -16*/ + }; + + return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); +} +#endif /* TARGET_ARCH_SIGTRAMP_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119253; cv=none; d=zohomail.com; s=zohoarc; b=PvMCgw329Ph7i+uOQXh850hqPyCjRJdqmEUxxUEO308debD44VQRymlrplCsr3ev9+aMy8IcVJqvbyx5Ynj4Ho1jomGBlaaCUEdJnZkJaeoIFpPkAFxh5gOpCDGkMWGCom/GdDAH9kEuibf7eV1UqSj+ATKuKdEJxb604PcHXPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119253; h=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=raD5wFnRa3LjZYQkzjXwjgGbirsM75uwQ48wbj5UKfI=; b=GrJ/CJmpFw/FeaRr88QKrsOGZ+aNb0Kg2YBvdV3zgVNw9hNInGIpkTJv8lpBcB/V8eiAURKNQRExQkh9ErTH1QIndV9hzYMKe7QOkwYQyMbpxi5OrIEoBByhkpc7nWef1xLdpPO4wDlXOCB2NmjdwygReYDQjrKb2zShK65zgq8= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119253276906.2855226838477; Wed, 11 Sep 2024 22:34:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR0-0006u4-19; Thu, 12 Sep 2024 01:32:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQm-0005f5-LZ for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:51 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQk-00039F-Ow for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:48 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7179802b8fcso365815b3a.1 for ; Wed, 11 Sep 2024 22:31:46 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119105; x=1726723905; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=raD5wFnRa3LjZYQkzjXwjgGbirsM75uwQ48wbj5UKfI=; b=IJjDW0Q3HZHU4erYiHUpbfEr9FFU59kIarP0Jkr4pKRvU6VAm3Tfh4/gA33hu1OYcI egWIC/crP2DdBsrXzRKsyVkdp+DwR3zppLVu5RY+xynxZZGbav+kUwx/Qos9ijDCr4qT a2vl8sIlR07Zd0kAUXD8pMfUEPEpKAyzgaDT75hPGaA1fRLpZznIejq4jHltLslR4F2A sdNHXjI3T0mThpn/LtKshK4/UGYZ22x7Dh7qz0nV44ovESpp/EOm0pevahTOlStFU4he qzI7xWHCIUUFQi8gLFwgymzleoFDkWCQnZHyYPIiRHCXv6FNfnDvEHHpUcDhbpCpgm6D MeDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119105; x=1726723905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=raD5wFnRa3LjZYQkzjXwjgGbirsM75uwQ48wbj5UKfI=; b=tHi5neKcCk2httttCfKUHSDvSBYnf8AV2kLwJ9qwgV5dPZ30J0SOx1720Lk0CEsuj3 GEWrxAffkfCJIdJGavSJepPKHBRLjKg5owUjapeld5vdm8iu3fu8qMTQyEW6m5A3OFTo vN7x4ButI6Iqxs9pjq0e9XY34m8PXKfhPtugMqCw6Kk2G5hNTfq4g9Ds2t0qQPTzFh1U tFvLyzwsWEb/fA7Ix2V97B0j6oakXE80BYQgRlY9R684Dp94VxL/eoVGprt2L2kNTDIT XkXAjFzeP9Z4Ui0ThoJxQC7UnZieNwEwAdaXyUH4Db0rSvf2lZZnk0MpJOX1F67aQ5R6 LXMA== X-Gm-Message-State: AOJu0Yxg3j5xlSji12LCWT8TPJ7Cp/5Gjbs65LzuBXOZT/yatidjYHwZ oKwpO5ESQwoQKCAthbcwIM8UYH4A3ZoMHABm3q5muKXzBDZeMa442tQr3A== X-Google-Smtp-Source: AGHT+IHtyAYUFqysefWlr4fs5g2hLvZctuMb3pi1+Xpa8w2b4nPF2rQ2MH/Xn2gsqDNHu+QEN1Hofg== X-Received: by 2002:a05:6a00:218f:b0:70d:7547:90f7 with SMTP id d2e1a72fcca58-71926081525mr3059051b3a.12.1726119104796; Wed, 11 Sep 2024 22:31:44 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 33/47] bsd-user: Implement RISC-V sysarch system call emulation Date: Thu, 12 Sep 2024 15:29:38 +1000 Message-ID: <20240912052953.2552501-34-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=alistair23@gmail.com; helo=mail-pf1-x429.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119254855116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added the 'do_freebsd_arch_sysarch' function to emulate the 'sysarch' system call for the RISC-V architecture. Currently, this function returns '-TARGET_EOPNOTSUPP' to indicate that the operation is not supported. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-9-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_sysarch.h | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bsd-user/riscv/target_arch_sysarch.h diff --git a/bsd-user/riscv/target_arch_sysarch.h b/bsd-user/riscv/target_a= rch_sysarch.h new file mode 100644 index 0000000000..9af42331b4 --- /dev/null +++ b/bsd-user/riscv/target_arch_sysarch.h @@ -0,0 +1,41 @@ +/* + * RISC-V sysarch() system call emulation + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_SYSARCH_H +#define TARGET_ARCH_SYSARCH_H + +#include "target_syscall.h" +#include "target_arch.h" + +static inline abi_long do_freebsd_arch_sysarch(CPURISCVState *env, int op, + abi_ulong parms) +{ + + return -TARGET_EOPNOTSUPP; +} + +static inline void do_freebsd_arch_print_sysarch( + const struct syscallname *name, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ + + gemu_log("UNKNOWN OP: %d, " TARGET_ABI_FMT_lx ")", (int)arg1, arg2); +} + +#endif /* TARGET_ARCH_SYSARCH_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119136; cv=none; d=zohomail.com; s=zohoarc; b=jBrqi9ltQPqa8BAQrivYqGm5VXKg+q5xIXxN2cUPrO3bt1nby2zw90c12taBuEq2PXSCq/zEaQcuQo00JRbBGQkBX1skLQCaNPH7B9zJOdqHYZ12XCZfBZ5X3ZX1KqbbvkZCBCPDHEW7JCDxYMrJ349ufcZRhnhLpux/Z8R77bQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119136; h=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=P36rIm3k+ox30i3dfuK/oNDXOR5kab8ZxM5c1Oh0acY=; b=hEPQp4bHj/ik+sbeeROH4FkM9og2Vbyaql2UUF28UsFS12loOTm2S/4gNGcKKS6DbQyD+/uKv3ss5VfVoDndJR0POh09n3BxutOp5cVr/jnCE0f9FHj3knyWflO+eQOcr1DsP2tXcaZ/7eEl/7hem2UEQ0/daQWGb2tU1CbbiNc= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119136584942.8752813555058; Wed, 11 Sep 2024 22:32:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR9-00086Y-Lm; Thu, 12 Sep 2024 01:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQq-0005tY-0y for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:53 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQo-00039T-5m for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:51 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7191ee537cbso412534b3a.2 for ; Wed, 11 Sep 2024 22:31:49 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119109; x=1726723909; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P36rIm3k+ox30i3dfuK/oNDXOR5kab8ZxM5c1Oh0acY=; b=R5VuzJum2b+o+gCL6ks5V3ifePn0uxBaPjZ9a2rpLP98dPgki4t1nMqjsRTl7weIAC 4k/gHm8Jn7Ftig+vAsi3xzDzAJNT0S64hX4O+zX3m6deD1cZjgON0KMZ66oAzDVrrWIL r/AEO8tAZCksLQD11vUrW3xbC0VkuUnoQDj15pjAhgYs+m4EjIL6mNLMpnHr7uKEHR9i hrvhaH3V0fSfCn0fX/qlTQS76EhPiKcCncrhTf4fk90p2toO+jZOaT3IO479Z7fGG4XM UlArBi42SGzwo3/f9lKL43YO26jnR6MMHZsQnRnoUd9B7uXsXyh72HPQSAY4uTAX/bnS 7A9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119109; x=1726723909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P36rIm3k+ox30i3dfuK/oNDXOR5kab8ZxM5c1Oh0acY=; b=g4xY+SulPO7k0L4Clvo14z3+kMdG8lRlMjXXxcstQTDKzJxQdSm33Nx7a9f2yYnynE NF6Th5hKPVUPh2UFahyOh/mYm+x664Kt0PePA4SFnffM5huHt/GyOKqTnJsWtJUSCO5e YqFDCxjkCsxSiOLsx/eQjQH2OvMhr2K3c2XMhs778PQy3ggeOacBAE4Hrfz4mLOCkTCY 58OQObWHQISUdqzm9l70h8UuMHpZny9eGAWh9S9Vjn8zvXIF2qgVEFOhgvkPXUZpXXD7 KfHkPIrkaX4Ydnwpj1cQuCm1pkU0lCVsemanEGQd4QehVrka8hKu55wPBOBIoGmTrO+D kusQ== X-Gm-Message-State: AOJu0YyXX4sMRPhjwSlewBopBVoo1EcCVcXT4ROF4xSX92q+TFtMeRwS 1ysNlHH3tIaTCXrpclGUYiJAe+o759OHq7MRhgs7tIm954i5IqInuoLH8w== X-Google-Smtp-Source: AGHT+IEXhm7ZfeSw24XnS1aTL+zEA3e2Y04XgXO3rA16g3/ig6Fif+MQAaSQW6XJP5cD6vp3NU0jhg== X-Received: by 2002:a05:6a21:e8e:b0:1bd:2214:e92f with SMTP id adf61e73a8af0-1cf75eaeaedmr2309668637.14.1726119108624; Wed, 11 Sep 2024 22:31:48 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Jessica Clarke , Kyle Evans , Richard Henderson , Alistair Francis Subject: [PULL 34/47] bsd-user: Add RISC-V thread setup and initialization support Date: Thu, 12 Sep 2024 15:29:39 +1000 Message-ID: <20240912052953.2552501-35-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=alistair23@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119138529116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Implemented functions for setting up and initializing threads in the RISC-V architecture. The 'target_thread_set_upcall' function sets up the stack pointer, program counter, and function argument for new threads. The 'target_thread_init' function initializes thread registers based on the provided image information. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-10-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_thread.h | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 bsd-user/riscv/target_arch_thread.h diff --git a/bsd-user/riscv/target_arch_thread.h b/bsd-user/riscv/target_ar= ch_thread.h new file mode 100644 index 0000000000..95cd0b6ad7 --- /dev/null +++ b/bsd-user/riscv/target_arch_thread.h @@ -0,0 +1,47 @@ +/* + * RISC-V thread support + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_THREAD_H +#define TARGET_ARCH_THREAD_H + +/* Compare with cpu_set_upcall() in riscv/riscv/vm_machdep.c */ +static inline void target_thread_set_upcall(CPURISCVState *regs, + abi_ulong entry, abi_ulong arg, abi_ulong stack_base, + abi_ulong stack_size) +{ + abi_ulong sp; + + sp =3D ROUND_DOWN(stack_base + stack_size, 16); + + regs->gpr[xSP] =3D sp; + regs->pc =3D entry; + regs->gpr[xA0] =3D arg; +} + +/* Compare with exec_setregs() in riscv/riscv/machdep.c */ +static inline void target_thread_init(struct target_pt_regs *regs, + struct image_info *infop) +{ + regs->sepc =3D infop->entry; + regs->regs[xRA] =3D infop->entry; + regs->regs[xA0] =3D infop->start_stack; + regs->regs[xSP] =3D ROUND_DOWN(infop->start_stack, 16); +} + +#endif /* TARGET_ARCH_THREAD_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119786; cv=none; d=zohomail.com; s=zohoarc; b=YH5J9wioNKOMLbrqGCyBldUc4s/hq5hyoRJV1likIucOTBglgZW0T+3nxWLha7NXdHcoReMbJY8SxYe+dNvph8RyKHl0NolUlRgtb1WL6NUB6XdYyM1jwQWUM/XIXAxIIelxf++QtQvTwzP5p0JAMUJGlUp5YjuqvrhIBurHnYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119786; h=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=/0zFg4BSTwNx23YXwcuWcDUOiXr3L+CnToybFG8Q9/0=; b=nDrqIilHZuEM5FAUb1sm20EQRJCkf1x7qOUccIONyutBYwv61dv6mdm3UbqZpLJwBqq0Ox7hcvMFBmCVLgBAPCYZXfRC/eOseYg3JVK1P46sM3zEHIn3UXVHyTcbUctihgzTqZX+fAOs9UP2WjuCE334IJyUHxr949PEEMJfsDM= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119786399188.12616672107322; Wed, 11 Sep 2024 22:43:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socR8-00081R-UC; Thu, 12 Sep 2024 01:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQt-0006Al-Ll for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:55 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socQr-00039i-OO for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:55 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-71798661a52so408076b3a.0 for ; Wed, 11 Sep 2024 22:31:53 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119112; x=1726723912; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/0zFg4BSTwNx23YXwcuWcDUOiXr3L+CnToybFG8Q9/0=; b=Np4zR3ueQiKn28+a4JF16eC3O6xq8zTPqHWzDY+djVbCHuoyjEkOJSCe108RlYpV8T 2Kb3tycxfZa1zZZZCfc0KA4TZ8oVXREUFB3jPBkBbQUmW2EXUkeNDoz/VyiDt7d4zVYF 5AdhmKlZ+DNtEZn045n1WJqUHOJ0qUGsUze16ob5RrdMD+3SPQLoMWvgVopVGBtIwuoF XtdnEFRt+cRvOTZPEF9HMxMuyy45HxTbjY+1OWke3Pa2eaXld19aCVtdRZdiExV9GvbU Wzoei9CnOQ/CMJ+MGzo1W+omfLnQ+OB61fwCqT/GWEYwLK9PwA4kSBCGOmS/SwUGOMEP NIMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119112; x=1726723912; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/0zFg4BSTwNx23YXwcuWcDUOiXr3L+CnToybFG8Q9/0=; b=IIhq8n4a+p6K2IzfpS20q3skqY560IeB3dOec8PN5WTdekZmUQK3WaL9f9tORvnntE g5oLj408RH8B4ysKpef97UKBcC+U4w8vRLlDmXy1AA9ov1O7dDY4O6lz18ew0sbaMOc7 aak7umkiN8NgRz0fsqRxPn2BPKYlX9DAS7/5zEGPOeMf9kvw28/GV8xpZUNgAMrZGEUS YByYaWS7zZo4K1cwapSRUgvuElUq7fxBFofI0LU0sIfdB5d49g/8WkxMKXZFosiUREp/ SLu4D54S4n62cYFXtYtd1Ji+6SuXNMrznkZoj2zOltjICkw/QZ77YPO0MQagT3gxwiw0 2RjQ== X-Gm-Message-State: AOJu0YwGh7KoA4aUHc3f3JvC6Z7k4rrkwwbjzk808IzCWCxIyG/i0nJF IHtnrFC9AQOcVI+DIYRH0zKoF3ORUzGP6HZrgpl9DbJGUB4wguqub9CQJw== X-Google-Smtp-Source: AGHT+IGUMS4qPyLS3tw7iI+P2ToT0GUS5jMurzfsYMe0uj7VpqpClgRy+zwZ2daqSgeS1Ryq/Emu/w== X-Received: by 2002:a05:6a00:17a7:b0:708:41c4:8849 with SMTP id d2e1a72fcca58-7192643cd9cmr2439478b3a.9.1726119111844; Wed, 11 Sep 2024 22:31:51 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 35/47] bsd-user: Define RISC-V VM parameters and helper functions Date: Thu, 12 Sep 2024 15:29:40 +1000 Message-ID: <20240912052953.2552501-36-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=alistair23@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119787939116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added definitions for RISC-V VM parameters, including maximum and default sizes for text, data, and stack, as well as address space limits. Implemented helper functions for retrieving and setting specific values in the CPU state, such as stack pointer and return values. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-11-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_vmparam.h | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bsd-user/riscv/target_arch_vmparam.h diff --git a/bsd-user/riscv/target_arch_vmparam.h b/bsd-user/riscv/target_a= rch_vmparam.h new file mode 100644 index 0000000000..0f2486def1 --- /dev/null +++ b/bsd-user/riscv/target_arch_vmparam.h @@ -0,0 +1,53 @@ +/* + * RISC-V VM parameters definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_VMPARAM_H +#define TARGET_ARCH_VMPARAM_H + +#include "cpu.h" + +/* Compare with riscv/include/vmparam.h */ +#define TARGET_MAXTSIZ (1 * GiB) /* max text size */ +#define TARGET_DFLDSIZ (128 * MiB) /* initial data size limit= */ +#define TARGET_MAXDSIZ (1 * GiB) /* max data size */ +#define TARGET_DFLSSIZ (128 * MiB) /* initial stack size limi= t */ +#define TARGET_MAXSSIZ (1 * GiB) /* max stack size */ +#define TARGET_SGROWSIZ (128 * KiB) /* amount to grow stack */ + +#define TARGET_VM_MINUSER_ADDRESS (0x0000000000000000UL) +#define TARGET_VM_MAXUSER_ADDRESS (0x0000004000000000UL) + +#define TARGET_USRSTACK (TARGET_VM_MAXUSER_ADDRESS - TARGET_PAGE_SIZE) + +static inline abi_ulong get_sp_from_cpustate(CPURISCVState *state) +{ + return state->gpr[xSP]; +} + +static inline void set_second_rval(CPURISCVState *state, abi_ulong retval2) +{ + state->gpr[xA1] =3D retval2; +} + +static inline abi_ulong get_second_rval(CPURISCVState *state) +{ + return state->gpr[xA1]; +} + +#endif /* TARGET_ARCH_VMPARAM_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119824; cv=none; d=zohomail.com; s=zohoarc; b=Qn42s/a2icBjqzM/LheybhwUtZ8XeZCjgHHQoO1PPKgZCi+HALXr19gjU/OPSucvgjGoosEVkf9n6B4sdamx6GWP1jeS0XV4WHLcZSdSogZgdKyTELkC1rNhm1D4hSMSWhg9quXvBmlp77siUN7RUzeyePwZTkLxoLNiMZaPAlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119824; h=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=QgbEkrj6Ne3TXHG2dEG6b1QuSqV5+ef92+ftslfdewQ=; b=hNBnXGMPDncxX3gRP38JYBwlS7L1RjoZdD5rp6MMjTsZPL5yqn4actU/Z5qxKZVAo+/MtCFzZ9KPHwy9vp5NDD7EBG6zXyI6BBLnxvt+I61dCARB0Zyx+bl19PsmoSvTnNWfdb+0aS/QIB7jJH0/Af4X//Gqk1mdFwrjOqMLyEo= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119824865786.6521896193746; Wed, 11 Sep 2024 22:43:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socRc-0000dk-TY; Thu, 12 Sep 2024 01:32:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQx-0006bC-HN for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:59 -0400 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 1socQv-00039y-LQ for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:31:59 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-718d704704aso420809b3a.3 for ; Wed, 11 Sep 2024 22:31:56 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119115; x=1726723915; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QgbEkrj6Ne3TXHG2dEG6b1QuSqV5+ef92+ftslfdewQ=; b=PI0NrjXm5PsBUiAUFTKJJWRajhDVH4tfkb5Cr1247zyJsswZ2LP9wbNI7cgrPVBOCY O8o9UEHVJshoVHURiaq1Pdmv0FLRszP6Y0FTOqDN2+KAggI2mUCbYrEhudT1qCiDTagd z12cVYtV/fE79Kcw3pTBd3PABL88Nk6UjAd0T1uUz7g6O0jVgxbAz/r48NXVykYzPzBN Ck3Q8dQd0kE82K/347r1sFj/pHRqQg+cIUtx0kci7DDkqyfpZIv9LOi2m7VzKiIPAjHo L1l/PFvx9ym2K/Eu2lkxBqC+clu++FPkB976f1VEOR2PQW3t9T6A8uvyXBqO47RAe38H +SnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119115; x=1726723915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QgbEkrj6Ne3TXHG2dEG6b1QuSqV5+ef92+ftslfdewQ=; b=ar+kFpJ2hieDbuvXuyCM6wW7S/jyrnB29/yAyVxBjha3RzNpwDtWuPrjN7oPuno1+G szrhUosE6Rn+l6DvpOBnlzuTZkunlDYlaVhEiLMCj760VIvzIjM6b8bzlgppjmdk+jnO GIJgURfTwL4XrYA9TXMnOuuUUmWaQXI9KAMfQ6dbiM4o12Ui/Y7aOXfA7KROBJzFJPCn I0JK9MJxxUt8v+w92n87rJJSqVXRLMF/DJbgAk+UPQAxejqtuXYsb/eXpErvCmOq/Y59 Igd3BThmosZyIxmMoJ4juJWNNBXY59h84DAZuMmE5duqkRztDl4SRjUeSQ5aoHSsBplw SiNA== X-Gm-Message-State: AOJu0YydMAberVJhhfWYXvDYyO3Rf8vJLBnkyLSULMtN7NJRq1poteqM tmJgl9SrAw0EYymJV27LKLatGC0B4g/t06JUb2FfK83KwHjIK6eYEQgqyA== X-Google-Smtp-Source: AGHT+IGPP/yjpq6tkLlCO0h5UMbvAOoUSzJmiafR8/0JqhruSZFdyJ+eNk760Rl0zWFzTQpc3qizHA== X-Received: by 2002:a05:6a00:2302:b0:718:d7de:3be2 with SMTP id d2e1a72fcca58-71926091b7dmr2783115b3a.14.1726119115349; Wed, 11 Sep 2024 22:31:55 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Jessica Clarke , Richard Henderson , Alistair Francis Subject: [PULL 36/47] bsd-user: Define RISC-V system call structures and constants Date: Thu, 12 Sep 2024 15:29:41 +1000 Message-ID: <20240912052953.2552501-37-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=alistair23@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119826060116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Introduced definitions for the RISC-V system call interface, including the 'target_pt_regs' structure that outlines the register storage layout during a system call. Added constants for hardware machine identifiers. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-12-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_syscall.h | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 bsd-user/riscv/target_syscall.h diff --git a/bsd-user/riscv/target_syscall.h b/bsd-user/riscv/target_syscal= l.h new file mode 100644 index 0000000000..e7e5231309 --- /dev/null +++ b/bsd-user/riscv/target_syscall.h @@ -0,0 +1,38 @@ +/* + * RISC-V system call definitions + * + * Copyright (c) Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef BSD_USER_RISCV_TARGET_SYSCALL_H +#define BSD_USER_RISCV_TARGET_SYSCALL_H + +/* + * struct target_pt_regs defines the way the registers are stored on the s= tack + * during a system call. + */ + +struct target_pt_regs { + abi_ulong regs[32]; + abi_ulong sepc; +}; + +#define UNAME_MACHINE "riscv64" + +#define TARGET_HW_MACHINE "riscv" +#define TARGET_HW_MACHINE_ARCH UNAME_MACHINE + +#endif /* BSD_USER_RISCV_TARGET_SYSCALL_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119784; cv=none; d=zohomail.com; s=zohoarc; b=FtPERJEdq1vvctjHFcA+iaEx/JYm6LHBgEeKhWNOtWKydlp6NmiKV/krvN07aIMhUJBD0B+ueh/rPQTk2Kq3/gnz0/HaUzFaQ/7aPLZWXeu7dBtPu0OQ1rjN5XmhSsNuZ1j1ZEPkggZ2Pwdw/e91DCYWDVKjDemkKCVwxwMaTfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119784; h=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=/tNX42OJCNCOILNqFAqiVHWCMdtEBvk2w09U2xNMBqo=; b=EH4HsV4SKETqnwLc0uBAl8EWA0x0JZZnJRv/40rZQMGR4vVIHnabZHaT2sWvam+0mmsYUMY0IEzPyOWKraHRXS9t6582q9PFnWRGTXPB9xJC5yVawjVZjzcrRhiNTNoGBmdIhgU9TzudZvBnK1qM3L0ujch5a+NAWee0ssg+Yag= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119784562822.5042170098601; Wed, 11 Sep 2024 22:43:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socRq-00031q-Nj; Thu, 12 Sep 2024 01:32:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socQz-0006uq-MP for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:01 -0400 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 1socQy-0003AA-5L for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:01 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-718e6299191so292286b3a.2 for ; Wed, 11 Sep 2024 22:31:59 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119118; x=1726723918; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/tNX42OJCNCOILNqFAqiVHWCMdtEBvk2w09U2xNMBqo=; b=APpB4KzfUdbQFWfub0v/CtfLWJm+mzlwHLMMePUM8ZEMeXAeU6v2yhjSzTV8gzPTQD Amtw+s3r0/OSOUrKmd7cwTLODfvqaKf0C5E71GDLDupwBOUV+qvsjpnQhWjiQHv81Mry ReefqHQDBzhU9wVQUX6Gz3vyLp2YtAERhFHSAzM6AgybXLymZqIJwmesNIb2hpJIXgqe aFSN0yqWDrqiDf5YtIS3n6aYEnB5JspRsv7Y15HStv75oTpb4Zium5vUVFk4a0RuuFL7 KS2hnluysv/c/qtvi5cUfnYmrj2Jo42ejOCkHWfhkA4r1Ag/+jTRyFzyvVhF6Xx3etsV sleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119118; x=1726723918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/tNX42OJCNCOILNqFAqiVHWCMdtEBvk2w09U2xNMBqo=; b=pvIk4xkRxtUPxHXCiBErNxHCKHtFUucJpuwOP4hiYzWb6SRtL00IdKp8lwcvuC7uRB Gy/AezOUGg/tVHuD5wf6/XgwZE78I5E2iHli/qZ89GoT++ba/edE5fngSblY7KuQ8viF Y5jdmQ8SaNhDIbddT7jc438/1WFHcm6B6+a0D2Tb+jWIydWr2i4LqZek/H7Imq0K7WdB 5HeLe48VQFiyTkmEULcdFl0YzRlskPYsB72g4lCKafBOW1dlHamGcgEGSZcmOiblwM2q OmAhoSEENquw5YQ3Zm+4PRkYAsCL1Imqx8WKC72UoUCVaB42aDxJ1hBiQWdxPQ7cs445 YreQ== X-Gm-Message-State: AOJu0YzYMC7fKsy1hAEIYq8WsNDEl8mPOdmsj1VA0N5L4MtAu+c0dpf4 JIST1HGpkW4TzhptmoC+nruGH4NBmuSg/wnzntyPcTTZPZFP0ROmmOBL7g== X-Google-Smtp-Source: AGHT+IGiLlzFQNAE6LALOsuccmAY5P48mDoZEkcjl8k0rBu2eFCrtgtGtUelaN1hi+GZHZzmB+dpLw== X-Received: by 2002:a05:6a00:993:b0:714:157a:bfc7 with SMTP id d2e1a72fcca58-71926084bb4mr2756081b3a.15.1726119118533; Wed, 11 Sep 2024 22:31:58 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Warner Losh , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 37/47] bsd-user: Add generic RISC-V64 target definitions Date: Thu, 12 Sep 2024 15:29:42 +1000 Message-ID: <20240912052953.2552501-38-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119785986116600 Content-Type: text/plain; charset="utf-8" From: Warner Losh Added a generic definition for RISC-V64 target-specific details. Implemented the 'regpairs_aligned' function,which returns 'false' to indicate that register pairs are not aligned in the RISC-V64 ABI. Signed-off-by: Warner Losh Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-13-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bsd-user/riscv/target.h diff --git a/bsd-user/riscv/target.h b/bsd-user/riscv/target.h new file mode 100644 index 0000000000..036ddd185e --- /dev/null +++ b/bsd-user/riscv/target.h @@ -0,0 +1,20 @@ +/* + * Riscv64 general target stuff that's common to all aarch details + * + * Copyright (c) 2022 M. Warner Losh + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_H +#define TARGET_H + +/* + * riscv64 ABI does not 'lump' the registers for 64-bit args. + */ +static inline bool regpairs_aligned(void *cpu_env) +{ + return false; +} + +#endif /* TARGET_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119789; cv=none; d=zohomail.com; s=zohoarc; b=hWHsv7h98n07jLx1nxtH8Oy9r9A1rqDVcz3Qk5UxNz43T7TWN/RzMjGqV2NfwuGpKVtWnDhy3uagbVFf8NRoIJI/1kXEOrwhZmG0PHLfePYF3IXBuo8goHH4PAr/HrTjcdsWNPq1bbx6k3tjugJUQgQxzI6NSo0OaYb8Vp9L7HE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119789; h=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=00k0Mqx/EpFUnR82ExpzBJkLkNZLP5MDHD2q8XNb0eY=; b=frNjh6so9HTS6QxV/vgXTeO+s8Uta5AorSyzv7yGBpH8ToB+uWRZHPRVZaVpzFpR0eyOtJDGRAVlIwdSKnCViqlSpfi7dhOV1caGuOK5vRTT3HpI3XYoxGG0IMFDpELqGB7Fk+JVn1iq/18eQBYDpFE6Quun/4mBw14oVYZ7k5g= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17261197891865.823550715974534; Wed, 11 Sep 2024 22:43:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socRn-0002ct-W1; Thu, 12 Sep 2024 01:32:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socR3-0007Pw-IO for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:05 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socR1-0003AQ-Mq for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:05 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2054e22ce3fso6251825ad.2 for ; Wed, 11 Sep 2024 22:32:03 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119122; x=1726723922; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=00k0Mqx/EpFUnR82ExpzBJkLkNZLP5MDHD2q8XNb0eY=; b=PIyG4vwvhQ5+Vl770jNqy5xp56ACpiJLSYvkM4o0MLGXuRex3X31ThQ/B0AA8j0PS1 qiHOm1feSNQJQW7vCyfV3cmAF5V80QqHRAl3gLlLzoqw7m98Krlvfl4M9Q23UXxeD62e cqEYe4DxIHCaw/WdGJkct9unyV/jNMGVa356mMGiD5951VBlgPpvJUXs+WthOtLBFw5D fWQ8yR8BYVzzdBBF3fU+bp4UrpGuMc9REETV9ihPtVoZF84JM02vUo+eEuTQXAWdtmiP 9KnapWoDakx1dzsyWlV9zG3WVpVE2exDCNAyYBcorb/yjDX6kozQLWIYEOTz/Lh9R6jW bPGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119122; x=1726723922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=00k0Mqx/EpFUnR82ExpzBJkLkNZLP5MDHD2q8XNb0eY=; b=uDFu8b5AMlo/5PlWhZZy2kFa2QfYp5RI4Y0eFnSfMH01Ovhs1ZJgn7L21FI3bZ/tQk rNQPdekwtGavw3hF8cw45gv7YoJ6NBnC4Lmrr9+OKAoxzOHezbJp4fTrasx95Hmm8WkG eMjuPGn9tkhMJKbHtkvdVFp1g16mVg/GegdUmjwJbiGVlvKppQWIkHQ94Vl/qR82BEmn jDL5hZZQPCKZ8Q9zSDFAX8NSAhKMbGNyGOLwhWYbxWgXhdY71v6KfGYj4IZytGCCOVoJ 52NvUmoiD/jVu0HNYB0GTQsZ57gzuXgZ1h6irhiVjy3S/RQb3ZnHsD0c/uT4LvWwDHso NsZQ== X-Gm-Message-State: AOJu0Yz3jBbEsz042Fxc2bQyNU61bkQf+7zXQGYn/q2H7Bw7USjhLPY5 AvNXLq5mpUnMk7NJd3UhxW5ReUoOfmmAdc8MrECvzBkc8wRF8R0iQHzbjA== X-Google-Smtp-Source: AGHT+IGokXQU+krw4BySG5/0ZY/OlN9RfUUfqek2zBZGxtavXhP2vT/OfN8M9VuIlnIfmnNRx4YXhg== X-Received: by 2002:a05:6a21:3318:b0:1c8:fdc7:8813 with SMTP id adf61e73a8af0-1cf75f2a590mr2135044637.23.1726119122017; Wed, 11 Sep 2024 22:32:02 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Warner Losh , Richard Henderson , Alistair Francis Subject: [PULL 38/47] bsd-user: Define RISC-V signal handling structures and constants Date: Thu, 12 Sep 2024 15:29:43 +1000 Message-ID: <20240912052953.2552501-39-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=alistair23@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119789959116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added definitions for RISC-V signal handling, including structures and constants for managing signal frames and context Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-14-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/target_arch_signal.h | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 bsd-user/riscv/target_arch_signal.h diff --git a/bsd-user/riscv/target_arch_signal.h b/bsd-user/riscv/target_ar= ch_signal.h new file mode 100644 index 0000000000..1a634b865b --- /dev/null +++ b/bsd-user/riscv/target_arch_signal.h @@ -0,0 +1,75 @@ +/* + * RISC-V signal definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_SIGNAL_H +#define TARGET_ARCH_SIGNAL_H + +#include "cpu.h" + + +#define TARGET_INSN_SIZE 4 /* riscv instruction size */ + +/* Size of the signal trampoline code placed on the stack. */ +#define TARGET_SZSIGCODE ((abi_ulong)(7 * TARGET_INSN_SIZE)) + +/* Compare with riscv/include/_limits.h */ +#define TARGET_MINSIGSTKSZ (1024 * 4) +#define TARGET_SIGSTKSZ (TARGET_MINSIGSTKSZ + 32768) + +struct target_gpregs { + uint64_t gp_ra; + uint64_t gp_sp; + uint64_t gp_gp; + uint64_t gp_tp; + uint64_t gp_t[7]; + uint64_t gp_s[12]; + uint64_t gp_a[8]; + uint64_t gp_sepc; + uint64_t gp_sstatus; +}; + +struct target_fpregs { + uint64_t fp_x[32][2]; + uint64_t fp_fcsr; + uint32_t fp_flags; + uint32_t pad; +}; + +typedef struct target_mcontext { + struct target_gpregs mc_gpregs; + struct target_fpregs mc_fpregs; + uint32_t mc_flags; +#define TARGET_MC_FP_VALID 0x01 + uint32_t mc_pad; + uint64_t mc_spare[8]; +} target_mcontext_t; + +#define TARGET_MCONTEXT_SIZE 864 +#define TARGET_UCONTEXT_SIZE 936 + +#include "target_os_ucontext.h" + +struct target_sigframe { + target_ucontext_t sf_uc; /* =3D *sf_uncontext */ + target_siginfo_t sf_si; /* =3D *sf_siginfo (SA_SIGINFO case)*/ +}; + +#define TARGET_SIGSTACK_ALIGN 16 + +#endif /* TARGET_ARCH_SIGNAL_H */ --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119841; cv=none; d=zohomail.com; s=zohoarc; b=etgGB9X35cLzPku72TeN5FDEfqWTKyN2tfxI/MH+/s834VWFuZmG3DRkLMEbX2v6q6vRYkYrKsIh2IVt57Nx9hqS+UmUlrBv0NxeQjo/o7GzEbLXPfLt3vxU2QR2pvIe7IX31Sbkcs30qU3yAj0n0sYLhlw9eoHZ3yjBzJ5afEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119841; h=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=WaeqxvC3mnFGIbOSUJJaOixs9NZ+BPRonjXCXyhDCUI=; b=ENqlV8lA2v88p+tHR7oOiqufKM1STw6x5UJFxh3mofDZ1CxICFAb+ZM8y6E0bliZ5X7z03+mNHRdEEeqqQLFoufYIyLOQTZkhZnBgDPzZbfqb9DDXq7JKMIP5URFTmoTZqj1lHfqbrFfQsgN0sfvM+XxoxHQyvIE/DJBr16SfhE= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119841122960.3072052438071; Wed, 11 Sep 2024 22:44:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socRu-0003U2-CK; Thu, 12 Sep 2024 01:33:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socR7-0007xa-Mn for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:10 -0400 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 1socR5-0003Ae-Cv for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:09 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-7d4f8a1626cso483641a12.3 for ; Wed, 11 Sep 2024 22:32:06 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119125; x=1726723925; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WaeqxvC3mnFGIbOSUJJaOixs9NZ+BPRonjXCXyhDCUI=; b=U+mMBKrfGttswZifVcHsoHYFtVbnp7qHkEhAd99+I8MIt/cdHufk5wdpLeK9SGENer BQAPvhH+vEeDs+clSEmouN/uI9wYYaVyxGymOxt4vOZsONcnON5pmOcQAREzpJCpr2Dl ytBwN+0jXySO0oDy/jgbnDbFH2qzvVqUIfSxh5veswvdZLephxeEDAPHro/3UtuJRfCX 5+Erm5X26r19nGCBt5H6Aidj8KHXfd2rE2hHEZclaqt2evH0h+tVkOU9Lxui6H0WCNuT jqBd3uaK2voogN6z84SvryEZEmOiBj73JSRkN/8NX06Opzc3QaFAQmyNEYSnhrhonw3L 2odQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119125; x=1726723925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WaeqxvC3mnFGIbOSUJJaOixs9NZ+BPRonjXCXyhDCUI=; b=GdDfNEeIzDUmslgfg7L7EJDP+HwUF0bfwBbU4NkE8HMp8dc0J8EZW5umUZ7ByyXCOF jEzEzV4n5KrRnNhE5NIFIiaB0SUbRGFSf6bzUdLpgdjgkcPVSuP5BfgfuSwEP7juyIfs ElFsNnzNUdip6l00rRL8TaHks/mnfokD1uJSSzngsD4n8bDjHD8u76ULOhuU3HyhfZMo st3lP17SK4DXM55hg+poQ+hj4H4Z8wLm2EGn0AplEtMnbpZwzZpAccmgVCVA+lz19VHR 4s4aWtr3dEYT0wWRyYVq834lPw+hPxNtEvyONsjaYZNO5qknfNw3N6nGRH3I50ZJBciw MtnA== X-Gm-Message-State: AOJu0Yw4PszQQAAQYn5plGLEuNcn0Vk1eIrDt4tYyf1ZEoo8DjWvIDt5 XD46z9xJzGEOnd6d+qxLc9GiVtjkvUV5riIBC6TPF7lMjk90lfWxqMUlxw== X-Google-Smtp-Source: AGHT+IE938VDAYJJPaThw6CIJA4hwrb7XAg/5GUdYdZpz0jKMqYKetJACm9abNtJs0a0dlcTKyiUKQ== X-Received: by 2002:a05:6a20:d81a:b0:1cf:21c7:2aff with SMTP id adf61e73a8af0-1cf75f1bfa2mr2293508637.23.1726119125518; Wed, 11 Sep 2024 22:32:05 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Warner Losh , Richard Henderson , Alistair Francis Subject: [PULL 39/47] bsd-user: Implement RISC-V signal trampoline setup functions Date: Thu, 12 Sep 2024 15:29:44 +1000 Message-ID: <20240912052953.2552501-40-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=alistair23@gmail.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119842223116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added functions for setting up the RISC-V signal trampoline and signal frame: 'set_sigtramp_args()': Configures the RISC-V CPU state with arguments for the signal handler. It sets up the registers with the signal number,pointers to the signal info and user context, the signal handler address, and the signal frame pointer. 'setup_sigframe_arch()': Initializes the signal frame with the current machine context.This function copies the context from the CPU state to the signal frame, preparing it for the signal handler. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Signed-off-by: Warner Losh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-15-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/signal.c | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bsd-user/riscv/signal.c diff --git a/bsd-user/riscv/signal.c b/bsd-user/riscv/signal.c new file mode 100644 index 0000000000..2597fec2fd --- /dev/null +++ b/bsd-user/riscv/signal.c @@ -0,0 +1,63 @@ +/* + * RISC-V signal definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" + +#include "qemu.h" + +/* + * Compare with sendsig() in riscv/riscv/exec_machdep.c + * Assumes that target stack frame memory is locked. + */ +abi_long +set_sigtramp_args(CPURISCVState *regs, int sig, struct target_sigframe *fr= ame, + abi_ulong frame_addr, struct target_sigaction *ka) +{ + /* + * Arguments to signal handler: + * a0 (10) =3D signal number + * a1 (11) =3D siginfo pointer + * a2 (12) =3D ucontext pointer + * pc =3D signal pointer handler + * sp (2) =3D sigframe pointer + * ra (1) =3D sigtramp at base of user stack + */ + + regs->gpr[xA0] =3D sig; + regs->gpr[xA1] =3D frame_addr + + offsetof(struct target_sigframe, sf_si); + regs->gpr[xA2] =3D frame_addr + + offsetof(struct target_sigframe, sf_uc); + regs->pc =3D ka->_sa_handler; + regs->gpr[xSP] =3D frame_addr; + regs->gpr[xRA] =3D TARGET_PS_STRINGS - TARGET_SZSIGCODE; + return 0; +} + +/* + * Compare to riscv/riscv/exec_machdep.c sendsig() + * Assumes that the memory is locked if frame points to user memory. + */ +abi_long setup_sigframe_arch(CPURISCVState *env, abi_ulong frame_addr, + struct target_sigframe *frame, int flags) +{ + target_mcontext_t *mcp =3D &frame->sf_uc.uc_mcontext; + + get_mcontext(env, mcp, flags); + return 0; +} --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119242; cv=none; d=zohomail.com; s=zohoarc; b=euRO3yHCuRMofj33zhjawcdf0ALC6Xb/li2egID+XaMNfyyBLbcRIUURRiZ0563IsPhjKppzBXogNq+7FmaVHoC8HbzjnSk7bZ+otKILZQadFCfc0QA3m8ecgUEiDn6NNqS4JABIbruqJxgiym3C857IsiycoevnY5lS5zZjjEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119242; h=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=ZObrB5tvafThUxGiM5moLAEXEy58t5ZXPielg0jlmmc=; b=k9E2ota45eFeDwDpbHhpM10ILkYH81hS7sC3kst9iIeo1noNpCSGXkFiOGKsvatfbQ2EenI6SN0zmpvpWpdRlEfToNtIAFjlhiLW5aSd2nMbtvWMGER0OQoRd0kOCqS79Q/4nt1LmvkP2+KOSVRvP4JRYa09mlr0ASoxO3e8sPA= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119242272787.8969955629495; Wed, 11 Sep 2024 22:34:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socSQ-0005Xj-L6; Thu, 12 Sep 2024 01:33:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRB-0008LX-2w for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:13 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socR8-0003Ao-TB for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:12 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-71790ed8c2dso431779b3a.3 for ; Wed, 11 Sep 2024 22:32:10 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119129; x=1726723929; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZObrB5tvafThUxGiM5moLAEXEy58t5ZXPielg0jlmmc=; b=XtDiqGkkAD7YxpzHCY5467ZSgaXaaq2CcQQkfdRvGkJ1zZr4pW9HAVKjnCdpNv8gzq jWgNBzTCUoDG9r4GseRxihFHgXn7ImMKr72IyqMvWQvuq4rxFmhFTq3TAqyl3MD0qKAp mBRnpV/6i6PcuvAHtd22zwSwC0NbUnaDUZ78MWfAL6kz92i907DNPdLt0foroDB25tvt IsTEHBdQ5OevnfEg6h+BRuSlkpPC+T0U9pUsEG0oUoNZ5rF3LKSgt7ne6cQaGiwSOSyY XR5AvjUkNnarQ8YMes8JTb7qVY8MryRbcVWeYk3fxL+1/UEX94oMler2BrzZ8kwSHaYm WmyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119129; x=1726723929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZObrB5tvafThUxGiM5moLAEXEy58t5ZXPielg0jlmmc=; b=sYmFqQ3ZzRsdZkYi/NbKa3/HNrz8bo4PC20Wk5HGUDVTbsTDofgCVzv5Sy7BskJwKl sCaPeIY9Gl/8YaIi57+ZoiQDJJpfqb3L0t4sESzgAv6Dbxro8qXiliXmqduWlWtbsS7b Imf4W+UayYiXluc3BNGxaXpXrJFbR/IfUoPUZoYbmxfa9AsWa5D3tRkeDZaWcMsEEX64 1Q/oDnCvlXgz/52utpuuU+O8YJzsV1c4S2EXmqZZw06osob22A8wqjQryTbwG0/3tlgh y5/cwOEwp6llO4HKLMtTVrMiISujc6C7i0NQQXPkqBNQLdiO6YXrB0VudoodL2PI1mdu QW3Q== X-Gm-Message-State: AOJu0YyUjgrunMndPZYHwcx6vuOPpKoLuojgCri4eXKpnQIY5ZMUfqCq mjs7JGdhbeXYI2Hw5MM4/TWhZwKEBZfSBtelbaMdny5UfZ9oErrUDkz7mw== X-Google-Smtp-Source: AGHT+IHY0au5VgUruQMMWXc3yC2PXQEJVTUWzfy9Pa7PUPHdXIATVY3wH3wXqi1ZUcwtVWQQGNyIOQ== X-Received: by 2002:a05:6a00:acd:b0:717:8a87:7d02 with SMTP id d2e1a72fcca58-71926210f14mr3337769b3a.23.1726119129227; Wed, 11 Sep 2024 22:32:09 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Ajeet Singh , Warner Losh , Richard Henderson , Alistair Francis Subject: [PULL 40/47] bsd-user: Implement 'get_mcontext' for RISC-V Date: Thu, 12 Sep 2024 15:29:45 +1000 Message-ID: <20240912052953.2552501-41-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=alistair23@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119242731116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added the 'get_mcontext' function to extract and populate the RISC-V machine context from the CPU state. This function is used to gather the current state of the general-purpose registers and store it in a 'target_mcontext_' structure. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Signed-off-by: Warner Losh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-16-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/signal.c | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/bsd-user/riscv/signal.c b/bsd-user/riscv/signal.c index 2597fec2fd..072ad821d2 100644 --- a/bsd-user/riscv/signal.c +++ b/bsd-user/riscv/signal.c @@ -61,3 +61,56 @@ abi_long setup_sigframe_arch(CPURISCVState *env, abi_ulo= ng frame_addr, get_mcontext(env, mcp, flags); return 0; } + +/* + * Compare with get_mcontext() in riscv/riscv/machdep.c + * Assumes that the memory is locked if mcp points to user memory. + */ +abi_long get_mcontext(CPURISCVState *regs, target_mcontext_t *mcp, + int flags) +{ + + mcp->mc_gpregs.gp_t[0] =3D tswap64(regs->gpr[5]); + mcp->mc_gpregs.gp_t[1] =3D tswap64(regs->gpr[6]); + mcp->mc_gpregs.gp_t[2] =3D tswap64(regs->gpr[7]); + mcp->mc_gpregs.gp_t[3] =3D tswap64(regs->gpr[28]); + mcp->mc_gpregs.gp_t[4] =3D tswap64(regs->gpr[29]); + mcp->mc_gpregs.gp_t[5] =3D tswap64(regs->gpr[30]); + mcp->mc_gpregs.gp_t[6] =3D tswap64(regs->gpr[31]); + + mcp->mc_gpregs.gp_s[0] =3D tswap64(regs->gpr[8]); + mcp->mc_gpregs.gp_s[1] =3D tswap64(regs->gpr[9]); + mcp->mc_gpregs.gp_s[2] =3D tswap64(regs->gpr[18]); + mcp->mc_gpregs.gp_s[3] =3D tswap64(regs->gpr[19]); + mcp->mc_gpregs.gp_s[4] =3D tswap64(regs->gpr[20]); + mcp->mc_gpregs.gp_s[5] =3D tswap64(regs->gpr[21]); + mcp->mc_gpregs.gp_s[6] =3D tswap64(regs->gpr[22]); + mcp->mc_gpregs.gp_s[7] =3D tswap64(regs->gpr[23]); + mcp->mc_gpregs.gp_s[8] =3D tswap64(regs->gpr[24]); + mcp->mc_gpregs.gp_s[9] =3D tswap64(regs->gpr[25]); + mcp->mc_gpregs.gp_s[10] =3D tswap64(regs->gpr[26]); + mcp->mc_gpregs.gp_s[11] =3D tswap64(regs->gpr[27]); + + mcp->mc_gpregs.gp_a[0] =3D tswap64(regs->gpr[10]); + mcp->mc_gpregs.gp_a[1] =3D tswap64(regs->gpr[11]); + mcp->mc_gpregs.gp_a[2] =3D tswap64(regs->gpr[12]); + mcp->mc_gpregs.gp_a[3] =3D tswap64(regs->gpr[13]); + mcp->mc_gpregs.gp_a[4] =3D tswap64(regs->gpr[14]); + mcp->mc_gpregs.gp_a[5] =3D tswap64(regs->gpr[15]); + mcp->mc_gpregs.gp_a[6] =3D tswap64(regs->gpr[16]); + mcp->mc_gpregs.gp_a[7] =3D tswap64(regs->gpr[17]); + + if (flags & TARGET_MC_GET_CLEAR_RET) { + mcp->mc_gpregs.gp_a[0] =3D 0; /* a0 */ + mcp->mc_gpregs.gp_a[1] =3D 0; /* a1 */ + mcp->mc_gpregs.gp_t[0] =3D 0; /* clear syscall error */ + } + + mcp->mc_gpregs.gp_ra =3D tswap64(regs->gpr[1]); + mcp->mc_gpregs.gp_sp =3D tswap64(regs->gpr[2]); + mcp->mc_gpregs.gp_gp =3D tswap64(regs->gpr[3]); + mcp->mc_gpregs.gp_tp =3D tswap64(regs->gpr[4]); + mcp->mc_gpregs.gp_sepc =3D tswap64(regs->pc); + + return 0; +} --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119666; cv=none; d=zohomail.com; s=zohoarc; b=LFTtkW/MWgicIZSH7td5qBMz/YmaUlqwex2PF+61C3JyYL4VvVvFSUreD4nSVLPRex61zv2qM2tMn9+xzPQET51bj0s6oTcITTNtMtOtasx9RiF2F7AtZQmqBIHYogAnakVa9coUDKeQJ+zZHfXFtJmHDaAR3B+R+grxfMKfoM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119666; h=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=8/idt6rpfEFMkn6tMIzI2R9hwW9xCaF2jjdNSxMJKJY=; b=EVsKWnxfcnrlRlQTWHW2XZZ5wkax2k1TGyFiKYXQde5zI4cQnhtJD1RzKEPqECzNYS8fDreyzC8M7vhUV+NrTGfIiXEBP+3W7GskxI7zT+El/s4MHLUcfbu9Lt5BLxdX1t3PFW2Z42N2tfs/fiwVZacxSOBOQ4WggpQjXcGJJ98= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119666672958.2160931460439; Wed, 11 Sep 2024 22:41:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socSo-0007zj-BN; Thu, 12 Sep 2024 01:33:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRE-0000EB-8l for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:20 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socRC-0003Az-Gz for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:15 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7179069d029so372729b3a.2 for ; Wed, 11 Sep 2024 22:32:14 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119133; x=1726723933; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8/idt6rpfEFMkn6tMIzI2R9hwW9xCaF2jjdNSxMJKJY=; b=IabP3aUirkMx/eqiTfkb3sY5Zw+9liPk2KO8Qz1OtLVehckTt7syYCjfoPM6rghCK7 6ROMk+bvH53jI9FkoLyxlOs1w3iUTuCRgTvLkNe07vZljObF0681ucNKzyRo7KSsa767 fLHE5yF5zkGHE0P7pNzjqXoAPqBoLQaK40LOShZyssq8UQ7e7a19DEWgmojVLOD4b9cJ aoC5R7U/cVyDP4CZN3sxSe3oJUlFOm50M0epmh8Tgse3CbsVj3UnC9HlK0NueaxfNRQT ZHRpsd6VRDmO7own92RWEL5SUJc7kbhi1XeBWDcEnUvYSmkk9PlCmL73bkXU4IfQxrLf XABw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119133; x=1726723933; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8/idt6rpfEFMkn6tMIzI2R9hwW9xCaF2jjdNSxMJKJY=; b=Na/l5iEOp1d+TIo03iI2/GNKJWa2g7qiriKkyBRF0KpJ0r6jpWso7JEyJTXmCbHYw4 YurXGJYEIZQLA5uPkQKSI4fZSqGb/9I57vqtTLSHKYnbx2LmqWqRw3aRhD60KLUILWVH boGuJ3yeR0ETXab1Sn5I8fUAUC6NOefgddsMSEpaI3TeufpZEUpJpyytMEOqg0YmVgP4 kYVaFnRpFcc28+BNgzh+j7iFCbGZmzyodnQ5JJbiu0Ev7WXHOCcoUQVXG5WKUmYDtbTn N8ErvO2J0IqCOP4c1BP65zKEgU88j1m5eLpgoUh1h8MOhioH/Q6wuXRkSwEuUqqbTN0Z B14w== X-Gm-Message-State: AOJu0YyvBnrl/iJ34kSrOhnju5eI2xwuN+JaEfBG+9rv0QCueC1q/CBI ewiXQ/DhHAATphBaDIcQoOLewCe/UVesMdq3VsbAOuZV3lEI7xDfLJK2MA== X-Google-Smtp-Source: AGHT+IERbovb4KSavIPg1/NElBDZnMmD8Lhw7B+wUkVOy4ZmcC/MEV9digp73m/NozXLiQdZPQdNyA== X-Received: by 2002:aa7:9e05:0:b0:717:8d9f:2dbc with SMTP id d2e1a72fcca58-719261fb115mr2147810b3a.23.1726119132697; Wed, 11 Sep 2024 22:32:12 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 41/47] bsd-user: Implement set_mcontext and get_ucontext_sigreturn for RISCV Date: Thu, 12 Sep 2024 15:29:46 +1000 Message-ID: <20240912052953.2552501-42-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=alistair23@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119667487116600 Content-Type: text/plain; charset="utf-8" From: Mark Corbin Added implementations for 'set_mcontext' and 'get_ucontext_sigreturn' functions for RISC-V architecture, Both functions ensure that the CPU state and user context are properly managed. Signed-off-by: Mark Corbin Signed-off-by: Warner Losh Signed-off-by: Ajeet Singh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-17-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- bsd-user/riscv/signal.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/bsd-user/riscv/signal.c b/bsd-user/riscv/signal.c index 072ad821d2..10c940cd49 100644 --- a/bsd-user/riscv/signal.c +++ b/bsd-user/riscv/signal.c @@ -114,3 +114,57 @@ abi_long get_mcontext(CPURISCVState *regs, target_mcon= text_t *mcp, =20 return 0; } + +/* Compare with set_mcontext() in riscv/riscv/exec_machdep.c */ +abi_long set_mcontext(CPURISCVState *regs, target_mcontext_t *mcp, + int srflag) +{ + + regs->gpr[5] =3D tswap64(mcp->mc_gpregs.gp_t[0]); + regs->gpr[6] =3D tswap64(mcp->mc_gpregs.gp_t[1]); + regs->gpr[7] =3D tswap64(mcp->mc_gpregs.gp_t[2]); + regs->gpr[28] =3D tswap64(mcp->mc_gpregs.gp_t[3]); + regs->gpr[29] =3D tswap64(mcp->mc_gpregs.gp_t[4]); + regs->gpr[30] =3D tswap64(mcp->mc_gpregs.gp_t[5]); + regs->gpr[31] =3D tswap64(mcp->mc_gpregs.gp_t[6]); + + regs->gpr[8] =3D tswap64(mcp->mc_gpregs.gp_s[0]); + regs->gpr[9] =3D tswap64(mcp->mc_gpregs.gp_s[1]); + regs->gpr[18] =3D tswap64(mcp->mc_gpregs.gp_s[2]); + regs->gpr[19] =3D tswap64(mcp->mc_gpregs.gp_s[3]); + regs->gpr[20] =3D tswap64(mcp->mc_gpregs.gp_s[4]); + regs->gpr[21] =3D tswap64(mcp->mc_gpregs.gp_s[5]); + regs->gpr[22] =3D tswap64(mcp->mc_gpregs.gp_s[6]); + regs->gpr[23] =3D tswap64(mcp->mc_gpregs.gp_s[7]); + regs->gpr[24] =3D tswap64(mcp->mc_gpregs.gp_s[8]); + regs->gpr[25] =3D tswap64(mcp->mc_gpregs.gp_s[9]); + regs->gpr[26] =3D tswap64(mcp->mc_gpregs.gp_s[10]); + regs->gpr[27] =3D tswap64(mcp->mc_gpregs.gp_s[11]); + + regs->gpr[10] =3D tswap64(mcp->mc_gpregs.gp_a[0]); + regs->gpr[11] =3D tswap64(mcp->mc_gpregs.gp_a[1]); + regs->gpr[12] =3D tswap64(mcp->mc_gpregs.gp_a[2]); + regs->gpr[13] =3D tswap64(mcp->mc_gpregs.gp_a[3]); + regs->gpr[14] =3D tswap64(mcp->mc_gpregs.gp_a[4]); + regs->gpr[15] =3D tswap64(mcp->mc_gpregs.gp_a[5]); + regs->gpr[16] =3D tswap64(mcp->mc_gpregs.gp_a[6]); + regs->gpr[17] =3D tswap64(mcp->mc_gpregs.gp_a[7]); + + + regs->gpr[1] =3D tswap64(mcp->mc_gpregs.gp_ra); + regs->gpr[2] =3D tswap64(mcp->mc_gpregs.gp_sp); + regs->gpr[3] =3D tswap64(mcp->mc_gpregs.gp_gp); + regs->gpr[4] =3D tswap64(mcp->mc_gpregs.gp_tp); + regs->pc =3D tswap64(mcp->mc_gpregs.gp_sepc); + + return 0; +} + +/* Compare with sys_sigreturn() in riscv/riscv/machdep.c */ +abi_long get_ucontext_sigreturn(CPURISCVState *regs, + abi_ulong target_sf, abi_ulong *target_uc) +{ + + *target_uc =3D target_sf; + return 0; +} --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119440; cv=none; d=zohomail.com; s=zohoarc; b=POc0AtLTP5lenkHGQ1cV8INwC1QczsCQ15xlQwpkymXQv4bPx70HNFSiv7qoiziLbhl3dd76vql6rBU5JoZiBC64MAzVTIaz2d3f0fql1FRMjc/Ud6g5sZWaq7cJM9W1kYdP14VU8Eq38j9a2xiy6Yz1uQMmoVKEFtzRBJEGYU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119440; h=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=1OZtUQ3CFcWEdjE0VCal/gtVrOv/C/IET7Ot8GrKz+4=; b=gAW+DaeQGTmEfSbJA2wdOjtxqcaUe4q2joURBs8dFq4tg+0o0XjohuWElfmYekve98qg9fXIL0puz/eKjyTx2/bivWZcZpEFwSLwCQXCvecSCONj1KLvy34cA4KEJtvsYZsI6MnnYWrHZpP0PcXiimaab7lsufdCWwXaAvOLPUQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119440047426.216362724296; Wed, 11 Sep 2024 22:37:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socRm-0002P8-K6; Thu, 12 Sep 2024 01:32:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRJ-0000cP-F5 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:31 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socRG-0003BH-Vp for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:21 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7db12af2f31so572311a12.1 for ; Wed, 11 Sep 2024 22:32:17 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119136; x=1726723936; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1OZtUQ3CFcWEdjE0VCal/gtVrOv/C/IET7Ot8GrKz+4=; b=CeSVFWOcB1opvsk9a70AkSaaTkGY+PGoJkw+J2kRj7R/CO7gxPtX4YEnAyLjJr2rSU TvHcv16jAEKLhE+ufLeXixvX5QRItXwXjf6BtTzsxHKHCq+wNYoSm8pik5fB8HeNDlFt 12/9/RfnBSJBm+AedElOYvvihIJdk3sOpnrhjAj16GaI+AoXIMJmzdkLIxQJXHpyCvFN EEBeJRwFhGLT4azoWCTKr0EumkAVM826C63twE/Kl7NeXbINrukIKiIftZ8Gnk1v5f/O fliigwwoxOrzi5SkY7AJNwDaHfW4DrJNW6/TmBOGq6GCRgG3laayBv8RGlhq1LRprbtK um/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119136; x=1726723936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1OZtUQ3CFcWEdjE0VCal/gtVrOv/C/IET7Ot8GrKz+4=; b=SkGBp5VPb/ijBKmuCJXR8Dno/UEFroM2g4bw9XIzYsEelTMKFFV0Or3cpP9p4nEXEd Wyy0mxp5Br3Fc74LASOh8djYPk/r1pJDBKzmgC2gdIswn84qNmgoOreTDOHpdp86huCw UCnPuQnI2cdipadMBNbM5zuC+p1PL+OmFzyFx3n7mBP3OAlXaVIWv/rPF+UBMaK7vWsP 9n751ip/1Ym6uV5Z0pky71XtLSzw80Xy3aRgZthPYNwMTNd/AXNV3MxI/PJIvv0EdAB6 57MtdAyqNKkT/uEcsMtQfWKqOxdOx25OtXoSrANpNtqnLNmWgQX30ZuWYWZWst6XKGzP FLXg== X-Gm-Message-State: AOJu0Yx5sPwRNVhBdDN/Qp1ZwHUq4+YR93epiMUYPY8693XMwbuoKkJL RUd3d8ZUfLI2hTsYVw75QfjEngPV9k+XSQ947S5QrV6xlm84j/dE8qVcBA== X-Google-Smtp-Source: AGHT+IFsQlaTs7tmehCRGLmNP+gJRUcmESzbmKM8Xlz3o67pu+czUHJT2gMXsEN79W5HT0VCh75tNg== X-Received: by 2002:a05:6a21:458b:b0:1cc:e3a1:b9e3 with SMTP id adf61e73a8af0-1cf75f2a66cmr2496240637.25.1726119135921; Wed, 11 Sep 2024 22:32:15 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Warner Losh , Ajeet Singh , Richard Henderson , Alistair Francis Subject: [PULL 42/47] bsd-user: Add RISC-V 64-bit Target Configuration and Debug XML Files Date: Thu, 12 Sep 2024 15:29:47 +1000 Message-ID: <20240912052953.2552501-43-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=alistair23@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119441598116600 Content-Type: text/plain; charset="utf-8" From: Warner Losh Added configuration for RISC-V 64-bit target to the build system. Signed-off-by: Warner Losh Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-ID: <20240907031927.1908-18-itachis@FreeBSD.org> Signed-off-by: Alistair Francis --- configs/targets/riscv64-bsd-user.mak | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 configs/targets/riscv64-bsd-user.mak diff --git a/configs/targets/riscv64-bsd-user.mak b/configs/targets/riscv64= -bsd-user.mak new file mode 100644 index 0000000000..191c2c483f --- /dev/null +++ b/configs/targets/riscv64-bsd-user.mak @@ -0,0 +1,4 @@ +TARGET_ARCH=3Driscv64 +TARGET_BASE_ARCH=3Driscv +TARGET_ABI_DIR=3Driscv +TARGET_XML_FILES=3D gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xm= l gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-virtual.xml --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119667; cv=none; d=zohomail.com; s=zohoarc; b=aHC9YZXIu2FhdzgmPBilEsR7tCEyheMsVrXknZVg2jjcUP/osSf64LbH3Te+n9JZgQY7e0CgU681xt5PSDqjJOs+93cAMHqzgVWnconmQucM+4XTviof7tpabJnqjn8AzCZvWm/CaXncgYdiIrbXPuzm8c/ixlPh9gAAI+LMkhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119667; h=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=UefArdR4LpqgzKnpldqKOmOZkzLrdIAn+UhHLQmgqqU=; b=My3xGnCDNhmA1jrEZzPSKkAqjqHOQGumD+jTqqikcO+2xwCG1g0woB0l3bXuJmflgtZJW3a8u4Rp3suKB67KfX4H9eIovx8xEbhV5b+czohd7fma3xa9pNra0sRlOogmTRiTt/Q489n6ed0rGe2QBhZywiY1f9HvmC1c7PQl+dI= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119667106334.09846786733385; Wed, 11 Sep 2024 22:41:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socST-0005l7-OY; Thu, 12 Sep 2024 01:33:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRL-0000iY-2Y for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:31 -0400 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 1socRI-0003BS-9K for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:22 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-7d50b3a924bso227732a12.0 for ; Wed, 11 Sep 2024 22:32:19 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119139; x=1726723939; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UefArdR4LpqgzKnpldqKOmOZkzLrdIAn+UhHLQmgqqU=; b=UuFsntjDKrV+CraBzMt2my9HaHXsUjvC+IVy3gfvg0B7Vq8eCx8zsj10CutTcEblBO 93YHYZP8nz5+fdik/GmFFQYV+Z9jRVfSYmvMvJLTQE0gKwnFWuqs7Q7TWBJ3qvmeDAkd SiujG3m18tVoX7kE7EctkYxthD8jsIt5pH5x7N+NfXcHppV5rSl6Q8kPzGpYB/7Rz2vW FyPMijvIxYOTrALAU81AJmWe7sG6DlQkOPQKFijEFyXL7eAddfUjHIs5PO0jyQqkZFjZ OwbxmGYr/GU8SpYVOW8mj6h3Wtnge217Un/Y+GbC2mQOv84ddIoNvZYklDYuD7mjxD5O dMEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119139; x=1726723939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UefArdR4LpqgzKnpldqKOmOZkzLrdIAn+UhHLQmgqqU=; b=ZdlaZQTQniDqTYOgL8vsXaBMOq3+FBJ2dKxRQEUy9Bfv901UxRfpXYxYcQBhIJ4BEI szPprvkIldaH/iU7M8/qA1kC4abosVFadO7+GhGmCPPdUhPI+/ZlcZLe3EZvFnmjGyqb 7IxJHOJdoXy9vhjWBywcn73Cn8dPf+bb7m5eA8fZb1zXonlmt16QGXleWDW/K7dG5+78 Yi2cEC2Qqy/g+ZbWHlEqKwuK8ZeQPKeoB+AfPRncm/QKBynj5UHOztR/XqgYi09z1foG tT8tWYIWPCA+1nf+T4/QXRlA4yvQro/yo+qZaNGkDttxJNHepomgc0NBU2mPhOA5hkSn LLig== X-Gm-Message-State: AOJu0YwZajcta5J8pTm1EFLxisxsKd2jjJH+uK72uQvSR7CiXHRPTUcE f+21sMp9h5QLqBMTBlsp4tacgPESscCXofPe5kIYOEhCXFPZhY0mxCVRUA== X-Google-Smtp-Source: AGHT+IESiYOArJ/J27v5x/MEFjyyiZ9A+X6VFHcXpzgvv+fp2gNjNx3/99F+n/q6chtwRUNzUFJlTg== X-Received: by 2002:a05:6a21:478b:b0:1cf:334d:ffae with SMTP id adf61e73a8af0-1cf761e59b8mr2020650637.32.1726119138595; Wed, 11 Sep 2024 22:32:18 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Samuel Holland , Alistair Francis Subject: [PULL 43/47] hw/riscv: Respect firmware ELF entry point Date: Thu, 12 Sep 2024 15:29:48 +1000 Message-ID: <20240912052953.2552501-44-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=alistair23@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119667548116600 Content-Type: text/plain; charset="utf-8" From: Samuel Holland When riscv_load_firmware() loads an ELF, the ELF segment addresses are used, not the passed-in firmware_load_addr. The machine models assume the firmware entry point is what they provided for firmware_load_addr, and use that address to generate the boot ROM, so if the ELF is linked at any other address, the boot ROM will jump to empty memory. Pass back the ELF entry point to use when generating the boot ROM, so the boot ROM can jump to firmware loaded anywhere in RAM. For example, on the virt machine, this allows using an OpenSBI fw_dynamic.elf built with FW_TEXT_START values other than 0x80000000. Signed-off-by: Samuel Holland Reviewed-by: Alistair Francis Message-ID: <20240817002651.3209701-1-samuel.holland@sifive.com> Signed-off-by: Alistair Francis --- include/hw/riscv/boot.h | 4 ++-- hw/riscv/boot.c | 11 ++++++----- hw/riscv/microchip_pfsoc.c | 2 +- hw/riscv/opentitan.c | 3 ++- hw/riscv/shakti_c.c | 13 ++++++------- hw/riscv/sifive_u.c | 4 ++-- hw/riscv/spike.c | 5 +++-- hw/riscv/virt.c | 4 ++-- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h index a2e4ae9cb0..18bfe9f7bf 100644 --- a/include/hw/riscv/boot.h +++ b/include/hw/riscv/boot.h @@ -35,13 +35,13 @@ target_ulong riscv_calc_kernel_start_addr(RISCVHartArra= yState *harts, target_ulong firmware_end_addr); target_ulong riscv_find_and_load_firmware(MachineState *machine, const char *default_machine_firm= ware, - hwaddr firmware_load_addr, + hwaddr *firmware_load_addr, symbol_fn_t sym_cb); const char *riscv_default_firmware_name(RISCVHartArrayState *harts); char *riscv_find_firmware(const char *firmware_filename, const char *default_machine_firmware); target_ulong riscv_load_firmware(const char *firmware_filename, - hwaddr firmware_load_addr, + hwaddr *firmware_load_addr, symbol_fn_t sym_cb); target_ulong riscv_load_kernel(MachineState *machine, RISCVHartArrayState *harts, diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index 47281ca853..9115ecd91f 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -128,11 +128,11 @@ char *riscv_find_firmware(const char *firmware_filena= me, =20 target_ulong riscv_find_and_load_firmware(MachineState *machine, const char *default_machine_firm= ware, - hwaddr firmware_load_addr, + hwaddr *firmware_load_addr, symbol_fn_t sym_cb) { char *firmware_filename; - target_ulong firmware_end_addr =3D firmware_load_addr; + target_ulong firmware_end_addr =3D *firmware_load_addr; =20 firmware_filename =3D riscv_find_firmware(machine->firmware, default_machine_firmware); @@ -148,7 +148,7 @@ target_ulong riscv_find_and_load_firmware(MachineState = *machine, } =20 target_ulong riscv_load_firmware(const char *firmware_filename, - hwaddr firmware_load_addr, + hwaddr *firmware_load_addr, symbol_fn_t sym_cb) { uint64_t firmware_entry, firmware_end; @@ -159,15 +159,16 @@ target_ulong riscv_load_firmware(const char *firmware= _filename, if (load_elf_ram_sym(firmware_filename, NULL, NULL, NULL, &firmware_entry, NULL, &firmware_end, NULL, 0, EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) { + *firmware_load_addr =3D firmware_entry; return firmware_end; } =20 firmware_size =3D load_image_targphys_as(firmware_filename, - firmware_load_addr, + *firmware_load_addr, current_machine->ram_size, NULL= ); =20 if (firmware_size > 0) { - return firmware_load_addr + firmware_size; + return *firmware_load_addr + firmware_size; } =20 error_report("could not load firmware '%s'", firmware_filename); diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c index 7725dfbde5..f9a3b43d2e 100644 --- a/hw/riscv/microchip_pfsoc.c +++ b/hw/riscv/microchip_pfsoc.c @@ -613,7 +613,7 @@ static void microchip_icicle_kit_machine_init(MachineSt= ate *machine) =20 /* Load the firmware */ firmware_end_addr =3D riscv_find_and_load_firmware(machine, firmware_n= ame, - firmware_load_addr, N= ULL); + &firmware_load_addr, = NULL); =20 if (kernel_as_payload) { kernel_start_addr =3D riscv_calc_kernel_start_addr(&s->soc.u_cpus, diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index 436503f1ba..e2830e9dc2 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -98,7 +98,8 @@ static void opentitan_machine_init(MachineState *machine) memmap[IBEX_DEV_RAM].base, machine->ram); =20 if (machine->firmware) { - riscv_load_firmware(machine->firmware, memmap[IBEX_DEV_RAM].base, = NULL); + hwaddr firmware_load_addr =3D memmap[IBEX_DEV_RAM].base; + riscv_load_firmware(machine->firmware, &firmware_load_addr, NULL); } =20 if (machine->kernel_filename) { diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c index 3888034c2b..2dccc1eff2 100644 --- a/hw/riscv/shakti_c.c +++ b/hw/riscv/shakti_c.c @@ -45,6 +45,7 @@ static void shakti_c_machine_state_init(MachineState *mst= ate) { ShaktiCMachineState *sms =3D RISCV_SHAKTI_MACHINE(mstate); MemoryRegion *system_memory =3D get_system_memory(); + hwaddr firmware_load_addr =3D shakti_c_memmap[SHAKTI_C_RAM].base; =20 /* Initialize SoC */ object_initialize_child(OBJECT(mstate), "soc", &sms->soc, @@ -56,16 +57,14 @@ static void shakti_c_machine_state_init(MachineState *m= state) shakti_c_memmap[SHAKTI_C_RAM].base, mstate->ram); =20 + if (mstate->firmware) { + riscv_load_firmware(mstate->firmware, &firmware_load_addr, NULL); + } + /* ROM reset vector */ - riscv_setup_rom_reset_vec(mstate, &sms->soc.cpus, - shakti_c_memmap[SHAKTI_C_RAM].base, + riscv_setup_rom_reset_vec(mstate, &sms->soc.cpus, firmware_load_addr, shakti_c_memmap[SHAKTI_C_ROM].base, shakti_c_memmap[SHAKTI_C_ROM].size, 0, 0); - if (mstate->firmware) { - riscv_load_firmware(mstate->firmware, - shakti_c_memmap[SHAKTI_C_RAM].base, - NULL); - } } =20 static void shakti_c_machine_instance_init(Object *obj) diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index af5f923f54..35a689309d 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -515,7 +515,7 @@ static void sifive_u_machine_init(MachineState *machine) SiFiveUState *s =3D RISCV_U_MACHINE(machine); MemoryRegion *system_memory =3D get_system_memory(); MemoryRegion *flash0 =3D g_new(MemoryRegion, 1); - target_ulong start_addr =3D memmap[SIFIVE_U_DEV_DRAM].base; + hwaddr start_addr =3D memmap[SIFIVE_U_DEV_DRAM].base; target_ulong firmware_end_addr, kernel_start_addr; const char *firmware_name; uint32_t start_addr_hi32 =3D 0x00000000; @@ -589,7 +589,7 @@ static void sifive_u_machine_init(MachineState *machine) =20 firmware_name =3D riscv_default_firmware_name(&s->soc.u_cpus); firmware_end_addr =3D riscv_find_and_load_firmware(machine, firmware_n= ame, - start_addr, NULL); + &start_addr, NULL); =20 if (machine->kernel_filename) { kernel_start_addr =3D riscv_calc_kernel_start_addr(&s->soc.u_cpus, diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index 64074395bc..fceb91d946 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -198,6 +198,7 @@ static void spike_board_init(MachineState *machine) MemoryRegion *system_memory =3D get_system_memory(); MemoryRegion *mask_rom =3D g_new(MemoryRegion, 1); target_ulong firmware_end_addr =3D memmap[SPIKE_DRAM].base; + hwaddr firmware_load_addr =3D memmap[SPIKE_DRAM].base; target_ulong kernel_start_addr; char *firmware_name; uint32_t fdt_load_addr; @@ -290,7 +291,7 @@ static void spike_board_init(MachineState *machine) /* Load firmware */ if (firmware_name) { firmware_end_addr =3D riscv_load_firmware(firmware_name, - memmap[SPIKE_DRAM].base, + &firmware_load_addr, htif_symbol_callback); g_free(firmware_name); } @@ -320,7 +321,7 @@ static void spike_board_init(MachineState *machine) riscv_load_fdt(fdt_load_addr, machine->fdt); =20 /* load the reset vector */ - riscv_setup_rom_reset_vec(machine, &s->soc[0], memmap[SPIKE_DRAM].base, + riscv_setup_rom_reset_vec(machine, &s->soc[0], firmware_load_addr, memmap[SPIKE_MROM].base, memmap[SPIKE_MROM].size, kernel_entry, fdt_load_addr); diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 63d553ac98..1d32b4b0f3 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1360,7 +1360,7 @@ static void virt_machine_done(Notifier *notifier, voi= d *data) machine_done); const MemMapEntry *memmap =3D virt_memmap; MachineState *machine =3D MACHINE(s); - target_ulong start_addr =3D memmap[VIRT_DRAM].base; + hwaddr start_addr =3D memmap[VIRT_DRAM].base; target_ulong firmware_end_addr, kernel_start_addr; const char *firmware_name =3D riscv_default_firmware_name(&s->soc[0]); uint64_t fdt_load_addr; @@ -1392,7 +1392,7 @@ static void virt_machine_done(Notifier *notifier, voi= d *data) } =20 firmware_end_addr =3D riscv_find_and_load_firmware(machine, firmware_n= ame, - start_addr, NULL); + &start_addr, NULL); =20 pflash_blk0 =3D pflash_cfi01_get_blk(s->flash[0]); if (pflash_blk0) { --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119837; cv=none; d=zohomail.com; s=zohoarc; b=hSepwGvF6W4N0H+YK4hQ+W5eK7euGP72tXWclDmQXDLg9PG5kYT+f4tNiMnkPRTSFSYiXrcFJPOJM16A2emV8nVYNxp74OYCY+5Hvl1ED8huCBxKf6IdUeSu/YSsyLozzucVKnbc82zwIG7AM3aHRLpCsMNJOtneB+gutuJe1lA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119837; h=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=rkFJkoUJd/HT9/094fGs2I2PCMVZbUiqtYOftglCzrg=; b=kB1OWhq3KSp7edVXPCHjEo0V1f7LxLTYAlIbA/+/+f93dw+8DhZuyYq2badC6gb5MiMEYgMwYBjnemLSHaCOheFc4sA35XpceEcoCdfuzePYoavlyG6MdDzL0HanocAxEc5mSGABmfG3bruHQRVCCpt+NMaOcRl8eLtm4nUwhkQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119837326576.5209360769474; Wed, 11 Sep 2024 22:43:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socSl-0007Wm-M5; Thu, 12 Sep 2024 01:33:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRN-0000su-OA for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:31 -0400 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 1socRK-0003Bi-Sq for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:24 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7179069d029so372806b3a.2 for ; Wed, 11 Sep 2024 22:32:22 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119141; x=1726723941; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rkFJkoUJd/HT9/094fGs2I2PCMVZbUiqtYOftglCzrg=; b=f4P/3j78pHImy8Sru7e3Z8Ln7z/fh8kmBEiMWM6ArBt59Q1VxkxJuxUFsYsrx4OwlK 2SccLnw9kp43MwrjYeN57eKtcyNYIh6l9lK9F2rozaMG8SlgbVpbFmmRVXEn59S2hyo8 Hf0VinDbOdiGfc9nZZTS1h8vHqFoLkYOVYgx/X3MLtPlVlYe+lmUIsdcrMuPjc7wZcMc zbKQBW1k6ZpMtns6QUx+d+0wjLgrfYx01mLip8ftOcmtqO2Ozdshmk3DdSdoTv0hM43H IKnKTK2Znc4w3SPxncA1VH4GgBQKnRdmdSW3+IxiLI8URPXm9zZGKlIJcLNS4wsCV1fK nMvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119141; x=1726723941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rkFJkoUJd/HT9/094fGs2I2PCMVZbUiqtYOftglCzrg=; b=HQ/haFgcVtqwWP3H2VszpB5haHlLF9epTsskal/Jve7UF6QcTNL7d5viuYgx5N878r 99jkZ5ECm4ApVYv3gwRIsAtJNTzv1tDkI4KYem21/OpXmR980ZWvJN0GKQKDa1rzC987 MkHocPI6Uw01ELwEo3o1CKNo29Fq3AebM1FHx4WhDajE9qcvj9uYr7YIz+krPb+w9paX cdDWx22EWLBirTsSF3BSJPBP8mlBo0w8qvte4qqt+jr9Qjf1z4ABLsZqG1/ii0ryMJOV 9QLjK/GCFkA+aCU8Epe+8OUrj07OV85l/uyHKpqeHT326WMRzQ5WMBxVKKAPMvtA7+l5 K6Rg== X-Gm-Message-State: AOJu0YzqvCC8zg56I3fPvT85lP7KIj+t98Q6dOk5gbwjE+ejzx7il7Ub DXVfr4W8RZotcw75hpxIfHmyN2t5sTs3mxMucW8nUSfJijdJT2d3tC9Tqw== X-Google-Smtp-Source: AGHT+IHUPAi7uCdOZoqoBDDeK/nKiyXIvApcmmtHKlDqWJbzsrDBSbtot8XFFP4SRZ+RHnPakjLK6A== X-Received: by 2002:a05:6a00:1906:b0:714:1a74:9953 with SMTP id d2e1a72fcca58-71926087dc4mr2476261b3a.16.1726119141281; Wed, 11 Sep 2024 22:32:21 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Alexandre Ghiti , Alistair Francis Subject: [PULL 44/47] target: riscv: Add Svvptc extension support Date: Thu, 12 Sep 2024 15:29:49 +1000 Message-ID: <20240912052953.2552501-45-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=alistair23@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119838171116600 Content-Type: text/plain; charset="utf-8" From: Alexandre Ghiti The Svvptc extension describes a uarch that does not cache invalid TLB entries: that's the case for qemu so there is nothing particular to implement other than the introduction of this extension. Since qemu already exposes Svvptc behaviour, let's enable it by default since it allows to drastically reduce the number of sfence.vma emitted by S-mode. Signed-off-by: Alexandre Ghiti Reviewed-by: Alistair Francis Message-ID: <20240828083651.203861-1-alexghiti@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu_cfg.h | 1 + target/riscv/cpu.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 96fe26d4ea..355afedfd3 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -81,6 +81,7 @@ struct RISCVCPUConfig { bool ext_svinval; bool ext_svnapot; bool ext_svpbmt; + bool ext_svvptc; bool ext_zdinx; bool ext_zaamo; bool ext_zacas; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d215681905..cb675f0278 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -197,6 +197,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot), ISA_EXT_DATA_ENTRY(svpbmt, PRIV_VERSION_1_12_0, ext_svpbmt), + ISA_EXT_DATA_ENTRY(svvptc, PRIV_VERSION_1_13_0, ext_svvptc), ISA_EXT_DATA_ENTRY(xtheadba, PRIV_VERSION_1_11_0, ext_xtheadba), ISA_EXT_DATA_ENTRY(xtheadbb, PRIV_VERSION_1_11_0, ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs), @@ -1520,6 +1521,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("svinval", ext_svinval, false), MULTI_EXT_CFG_BOOL("svnapot", ext_svnapot, false), MULTI_EXT_CFG_BOOL("svpbmt", ext_svpbmt, false), + MULTI_EXT_CFG_BOOL("svvptc", ext_svvptc, true), =20 MULTI_EXT_CFG_BOOL("zicntr", ext_zicntr, true), MULTI_EXT_CFG_BOOL("zihpm", ext_zihpm, true), --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119937; cv=none; d=zohomail.com; s=zohoarc; b=W106ZpZq1HNuYwVNI0Pb+zOe2OtzrX/oE7y1pwpW4gYL/FsJOrZanDZjAOpwm61MN4st4iItjxlvuADlAzZrtMtKbjbBIw7Vhs1gSmaO4/x1YoVCmZFwU/ACVqJpT/KJXrnw4KeY6oGzORxXx335ysl0VVFa0zzMwM6hLtrwE7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119937; h=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=GWryAgOwLMSF+r/4gq1tiWKnxg+KJOz4OtvMHYQlMIk=; b=IKqgbmogWj8fO+IefISq+YEIevuEmhhNEjy0TJdBKg2eJ4RH7L3gr9GGpy3Dio3+5cUF1hK9g5aJATKMqaswm1Gv3LM3NM63S+PGfUa4bRqvHTQneVgjtI79nWC6NifB11ojxNDX/EBBgKQT3MMgBALUC1ryIBoNCELt80iVpe8= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119937172253.9143544552087; Wed, 11 Sep 2024 22:45:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socS1-0003Zo-1S; Thu, 12 Sep 2024 01:33:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRP-0000ys-9s for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:32 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socRN-0003Bw-OR for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:27 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7191fb54147so363088b3a.2 for ; Wed, 11 Sep 2024 22:32:25 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119144; x=1726723944; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GWryAgOwLMSF+r/4gq1tiWKnxg+KJOz4OtvMHYQlMIk=; b=PRQkvqtvZA4QDr1FYdRPIVC9c0PIqy5QChaNPk533IlDn+lp/K0cdkQOaUjs5WDKSE 9wZOBbRfR/YUGmm4zWyJyALfnqGz7aMEf5VfFxC46y3QuF5Nwoscfq5hzihSzGsWbyz/ QfkRwsb/SKEba8a9Pkj66IkLL3/AAnZMQsGUuivdYTGNCllqn/EUUZ9rWTHytx6/rs4d LonDKKOE5srGANJEv9pbfvPvbbaqjSDDn4LjUH9DxZzoFqXUdbeAB/Y9+FrTrgUKb6Ta XA52jfe94eVrbPsAcThqzpONhMYt4MBrFxnGm1Mb8wJE44egd0DD0m04P3aOkEhnxcDa vrIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119144; x=1726723944; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GWryAgOwLMSF+r/4gq1tiWKnxg+KJOz4OtvMHYQlMIk=; b=ktub0fYtutL/2yhr0wfnSWc7PtKZ8ACIyXpYDxFXnJtw8jUsHMFPjqtFid9Xh+I1cK S0Ck4+HMnPjrVrYfSMVr4vil9iZxt3I45qTQASOoEoQP0vhBhKP8dKYh/tU2f6wSl4Jd p9Tm19HL3pHxeyu+1wZWauvjhjoMBviueutA9zmEoStFjSt8Q/m+OmjAH3mQmbKde1uE msDaMuyTYBRZaJvgURJMmcjJ9Pt4jctDYWl4D28xlw2EVwcNdgQpvPHsOltwyfA4Ef+l gPmPHsj257YZt8XTOPYP+CjiV5oBjk69UBBshfWH+E1VwVgyX4woraFVPBwJ9cTswI1t TF4A== X-Gm-Message-State: AOJu0YxBPCvjCA9mp9yREff781/xjEaPtzc6tvr7s6HuPu2Dc2kNKk1S Err4LJbwGcYlQhd4bIWQlAIyKKdbXhsbwM04AbjgbMqg/gQn6gV1EX640g== X-Google-Smtp-Source: AGHT+IGIl5jveHVwWGuuFk+fS1DwvPJL8BUDe40YpjoHbyqVXsfzosIGklU55xRNDILGJdR3WFW/rg== X-Received: by 2002:a05:6a00:3e29:b0:70d:2b95:d9c0 with SMTP id d2e1a72fcca58-71926090ecdmr2621079b3a.14.1726119144174; Wed, 11 Sep 2024 22:32:24 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Andrew Jones , Alistair Francis , Richard Henderson Subject: [PULL 45/47] target/riscv32: Fix masking of physical address Date: Thu, 12 Sep 2024 15:29:50 +1000 Message-ID: <20240912052953.2552501-46-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=alistair23@gmail.com; helo=mail-pf1-x429.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119938641116600 Content-Type: text/plain; charset="utf-8" From: Andrew Jones C doesn't extend the sign bit for unsigned types since there isn't a sign bit to extend. This means a promotion of a u32 to a u64 results in the upper 32 bits of the u64 being zero. If that result is then used as a mask on another u64 the upper 32 bits will be cleared. rv32 physical addresses may be up to 34 bits wide, so we don't want to clear the high bits while page aligning the address. The fix is to use hwaddr for the mask, which, even on rv32, is 64-bits wide. Fixes: af3fc195e3c8 ("target/riscv: Change the TLB page size depends on PMP= entries.") Signed-off-by: Andrew Jones Reviewed-by: Alistair Francis Reviewed-by: Richard Henderson Message-ID: <20240909083241.43836-2-ajones@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/cpu_helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 395a1d9140..4b2c72780c 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1323,7 +1323,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, = int size, int ret =3D TRANSLATE_FAIL; int mode =3D mmuidx_priv(mmu_idx); /* default TLB page size */ - target_ulong tlb_size =3D TARGET_PAGE_SIZE; + hwaddr tlb_size =3D TARGET_PAGE_SIZE; =20 env->guest_phys_fault_addr =3D 0; =20 @@ -1375,7 +1375,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, = int size, =20 qemu_log_mask(CPU_LOG_MMU, "%s PMP address=3D" HWADDR_FMT_plx " ret %d = prot" - " %d tlb_size " TARGET_FMT_lu "\n", + " %d tlb_size %" HWADDR_PRIu "\n", __func__, pa, ret, prot_pmp, tlb_size); =20 prot &=3D prot_pmp; @@ -1409,7 +1409,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, = int size, =20 qemu_log_mask(CPU_LOG_MMU, "%s PMP address=3D" HWADDR_FMT_plx " ret %d prot" - " %d tlb_size " TARGET_FMT_lu "\n", + " %d tlb_size %" HWADDR_PRIu "\n", __func__, pa, ret, prot_pmp, tlb_size); =20 prot &=3D prot_pmp; --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119650; cv=none; d=zohomail.com; s=zohoarc; b=Q4bmCDqQPT4sNM+mf1hcOEZjplV/rxxHypT5xdCP636sYjm0L/ExRbubtbE5bVUyt+Bhs7BlOo8Vup1qRwFs1v28Lhg9QrBvak9jDEalwEmXLL7oGzdc9cqvrepWXDiDAi8G1Kx2sVR+7ZQAtQwqaE21ZXUJOf1ZAQCNbh4p74A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119650; h=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=B6fZIAVQ4yCQPRQVlhgL3MODNobQ/HUxNCiJ7ns1wzI=; b=DL3vBu88w7gBEKfulGA51cQW4FRUgWakGEVdkE4aDjLPOQ2hqIuXL4M5b7SER1Kd5wYWXfhQvdenLcVxx+sext18sXshL/YLEH37z2IQY+SAgubktEOSdtWc2ABSEaTHFMl3KIW5A2MKPKC8Ng4upgqKO3xqU2XJcd6mcut1JUU= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119650021975.4950439562251; Wed, 11 Sep 2024 22:40:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socRr-0003CV-OT; Thu, 12 Sep 2024 01:32:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRT-0001Fw-PP for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:37 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1socRR-0003CB-OC for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:31 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7d4f8a1626cso483950a12.3 for ; Wed, 11 Sep 2024 22:32:28 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119147; x=1726723947; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B6fZIAVQ4yCQPRQVlhgL3MODNobQ/HUxNCiJ7ns1wzI=; b=STWCefWSs9s+iNHK/hEqq5Xh1ino7ohRDYVdNYeADtcDeRX9nfrkwrWn+YKXfJAaPw VfqBzD+mUeLYeoRxujfZ55nahJ+pwoB+FdIYI33jm3loq2vKN4m/awCJuKgZ/J9Lwe8G f/R1URdLoT2ExvpRBqyP5IG4Xs+BA8N36MFGCFaFK5QdN3BrJiWdM08NYGjkFbJAWUz0 D81nW1OSqs/x10uGuQ2ZDJG1yNVJCHFfCDgSRiuFfl0/zzZrcrsLsCVk8MRu4aDUHodZ eRWRU3Ijn8FrLgjmqTIQRITFniJt56kbRYCuxVgTBVf7I0K4Ui0/FxHz86PessJD9myG LJuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119147; x=1726723947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B6fZIAVQ4yCQPRQVlhgL3MODNobQ/HUxNCiJ7ns1wzI=; b=UmKuTU4pkHjJjulrw0P4vN/b78xK+obfPIFVG2h+T0Vcw3m4lX8wyivSjXowfYodm5 pd7OpkhZ2A6U2UfJhXolYQmFN5s+Y3ppS/JZUT7mjQIb/pZX8W35bWj3u7F79oT1M/LM EZfVFf6fPlhy4+sWqzTerP1XD3aHkDaHupbNdTBO07j5JCjDyr0N2tuhNZACrsTnnS3o Y24WNpGdD20U5aiBjuJ5vrgnMspYFZ0rSkf9dmqHJmPZOaiEttbbIuR+/l2VhTAsnxFB OQOZaKaA89ifpCnrnyvGFhHeF4Lf1Apgg5OBXbbBp61eqVHCIPuK4s39Le242n94dChJ o/Ww== X-Gm-Message-State: AOJu0Yw8opw648u+sIvTUGR0tvra+GHg+E9vvQjSqd+UeQxXHfs8quO1 or16F9KXHZX51zfrozS+EfBJXBHBgN2z4I6YBVyqyjhtsZjNZflCjPH29Q== X-Google-Smtp-Source: AGHT+IGIJ1Kg+/6j1jIBVeM0AEqz8SVFmJpZuqRXOpR9nP6/9QfF0IyJfwfrtW3sBrd8kS8AWSANAg== X-Received: by 2002:a05:6a20:2d09:b0:1cf:2901:2506 with SMTP id adf61e73a8af0-1cf75ed390bmr2380511637.14.1726119146855; Wed, 11 Sep 2024 22:32:26 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Thomas Huth , Alistair Francis Subject: [PULL 46/47] target/riscv/cpu_helper: Fix linking problem with semihosting disabled Date: Thu, 12 Sep 2024 15:29:51 +1000 Message-ID: <20240912052953.2552501-47-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=alistair23@gmail.com; helo=mail-pg1-x52b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119651488116600 Content-Type: text/plain; charset="utf-8" From: Thomas Huth If QEMU has been configured with "--without-default-devices", the build is currently failing with: /usr/bin/ld: libqemu-riscv32-softmmu.a.p/target_riscv_cpu_helper.c.o: in function `riscv_cpu_do_interrupt': .../qemu/target/riscv/cpu_helper.c:1678:(.text+0x2214): undefined reference to `do_common_semihosting' We always want semihosting to be enabled if TCG is available, so change the "imply" statements in the Kconfig file to "select", and make sure to avoid calling into do_common_semihosting() if TCG is not available. Signed-off-by: Thomas Huth Reviewed-by: Alistair Francis Message-ID: <20240906094858.718105-1-thuth@redhat.com> Signed-off-by: Alistair Francis --- target/riscv/cpu_helper.c | 2 ++ target/riscv/Kconfig | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 4b2c72780c..a935377b4a 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1674,10 +1674,12 @@ void riscv_cpu_do_interrupt(CPUState *cs) if (!async) { /* set tval to badaddr for traps with address information */ switch (cause) { +#ifdef CONFIG_TCG case RISCV_EXCP_SEMIHOST: do_common_semihosting(cs); env->pc +=3D 4; return; +#endif case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT: case RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT: case RISCV_EXCP_LOAD_ADDR_MIS: diff --git a/target/riscv/Kconfig b/target/riscv/Kconfig index c332616d36..11bc09b414 100644 --- a/target/riscv/Kconfig +++ b/target/riscv/Kconfig @@ -1,9 +1,9 @@ config RISCV32 bool - imply ARM_COMPATIBLE_SEMIHOSTING if TCG + select ARM_COMPATIBLE_SEMIHOSTING if TCG select DEVICE_TREE # needed by boot.c =20 config RISCV64 bool - imply ARM_COMPATIBLE_SEMIHOSTING if TCG + select ARM_COMPATIBLE_SEMIHOSTING if TCG select DEVICE_TREE # needed by boot.c --=20 2.46.0 From nobody Sun Nov 24 06:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1726119280; cv=none; d=zohomail.com; s=zohoarc; b=YCiqmGwpnS2TEAArnhumDvmxakicoxTKXl0aDv5AjJ27WmPglmpVBdXJ5A/ee0k4CzABqosIsZEpklDphB23qcZvU8HdMnsGFYZINGdmODuh+xp3/tWXc/MYhK89PepKutQG36XBr3tA6c9VwUNd/oamEBTLFGndy1U+ibBv46A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726119280; h=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=5zhLGtCZcCsv5nuPN09/CvN94G3XOM8d23tZVuRBYY0=; b=QP3CEaEfehuQ5mWp3ZT34YjfQ4PGBlFrSYi9h0KnWXGSORy4x5vWik+hu+iFuuzMGXTnOPfcdzsMCn3TKk8w7uV6KuUYkmiOrB3PETW4bck24eFMc3ItaG9dQZemqcLwM4niMzD4Cj8pECXzC3B4JrQajAMUmh3CWCue/l7QJ+c= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726119280406455.3972456664236; Wed, 11 Sep 2024 22:34:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1socRq-0002wr-Em; Thu, 12 Sep 2024 01:32:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1socRV-0001OH-Cq for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:37 -0400 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 1socRT-0003CL-I4 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 01:32:33 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7178df70f28so394530b3a.2 for ; Wed, 11 Sep 2024 22:32:30 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8fdesm3833034b3a.1.2024.09.11.22.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726119150; x=1726723950; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5zhLGtCZcCsv5nuPN09/CvN94G3XOM8d23tZVuRBYY0=; b=QjCjrDEjTGdnWKf+H0Z+BChnUahrtkOteDZcqxD5vZJpqndoRrQCgUqcVM36MEd5kP NF9psgarVzAilPjdblZ9JBx2jjwItsv3BbZjF/Zfqd2Rxe+4aY3BLe6ZmvXj+cOkC01s 2GYo9b23B+PoKYHGomcm0kyhFocImoueGIj39JJd9YTWrGNIQjRxaMZkOTUMQlPIYcq+ YazatZCuSqhLpH25GFjaGvsyjCwIoywvDpIWaedmE0SW298LGDpRn+ibouTCJYiCBRSW wxGTTV+bhjoe+wgnHkkL2YhJs92OxX61YMR/x2GOv+hPJQ+YNmMtX1WeBnrsA24nYfq6 Q+CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726119150; x=1726723950; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5zhLGtCZcCsv5nuPN09/CvN94G3XOM8d23tZVuRBYY0=; b=TrXt+TbtpUggHO4Zo1Qip4RY+Yvwj8mA5+NB7dQAe4PiMF2b+cEIoQEVnehIGDR+4N Torvx01NSBlViYy5iK/POZRkBlMDyRF++ugrdwKNkfAVLjjfMaeoLJWf+Cz+99m1t57H AyUTepX1uYhDqwSGUpYwXTDH0nHWd1COhEVpUpzaYhF/a0nfDAh0/EFXN2IwnCyI8dMT qgJx01dqOZmUUHBYGgd0GbIaIJ49aqpCYnZ8p/9o9KFhlJ2mcIaupMmZwV8wZe7lfgAv qftVJfZk7tL3ksq1o8LAYbEXLEbyetFDh/HSV7rQjn/piAsvraFVRX2mHi9jfMrlsFh4 ZFtg== X-Gm-Message-State: AOJu0Yzwfc+pHOKPQ4Kqs4mCZ1+nc3ScEQfV7o80J4tiBOvFk/QDODr7 fS8KPPKqSRGvAeZwMgNY8SX5Dtt855JLG8Ge4VTytilsz45LmEgUcc8hCQ== X-Google-Smtp-Source: AGHT+IG/81Q56w6sffhk9aDWntHda+qv0m7ca4orwUvZw8u2DFZD5/q9Ni1ZAqPRJEYKsppTQG10NA== X-Received: by 2002:a05:6a00:228a:b0:717:87af:fca0 with SMTP id d2e1a72fcca58-71925f9de4emr2900521b3a.0.1726119149517; Wed, 11 Sep 2024 22:32:29 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Alistair Francis Subject: [PULL 47/47] hw/intc: riscv-imsic: Fix interrupt state updates. Date: Thu, 12 Sep 2024 15:29:52 +1000 Message-ID: <20240912052953.2552501-48-alistair.francis@wdc.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912052953.2552501-1-alistair.francis@wdc.com> References: <20240912052953.2552501-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=alistair23@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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 @gmail.com) X-ZM-MESSAGEID: 1726119280998116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach The IMSIC state variable eistate[] is modified by CSR instructions within a range dedicated to the local CPU and by MMIO writes from any CPU. Access to eistate from MMIO accessors is protected by the BQL, but read-modify-write (RMW) sequences from CSRRW do not acquire the BQL, making the RMW sequence vulnerable to a race condition with MMIO access from a remote CPU. This race can manifest as missing IPI or MSI in multi-CPU systems, eg: [ 43.008092] watchdog: BUG: soft lockup - CPU#2 stuck for 27s! [kworker/u= 19:1:52] [ 43.011723] CPU: 2 UID: 0 PID: 52 Comm: kworker/u19:1 Not tainted 6.11.0= -rc6 [ 43.013070] Workqueue: events_unbound deferred_probe_work_func [ 43.018776] [] smp_call_function_many_cond+0x190/0x5c2 [ 43.019205] [] on_each_cpu_cond_mask+0x20/0x32 [ 43.019447] [] __flush_tlb_range+0xf2/0x190 [ 43.019683] [] flush_tlb_kernel_range+0x20/0x28 The interrupt line raise/lower sequence was changed to prevent a race between the evaluation of the eistate and the execution of the qemu_irq raise/lower, ensuring that the interrupt line is not incorrectly deactivated based on a stale topei check result. To avoid holding BQL all modifications of eistate are converted to atomic operations. Signed-off-by: Tomasz Jeznach Reviewed-by: Alistair Francis Message-ID: Signed-off-by: Alistair Francis --- hw/intc/riscv_imsic.c | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c index b90f0d731d..9ef65d4012 100644 --- a/hw/intc/riscv_imsic.c +++ b/hw/intc/riscv_imsic.c @@ -55,7 +55,7 @@ static uint32_t riscv_imsic_topei(RISCVIMSICState *imsic,= uint32_t page) (imsic->eithreshold[page] <=3D imsic->num_irqs)) ? imsic->eithreshold[page] : imsic->num_irqs; for (i =3D 1; i < max_irq; i++) { - if ((imsic->eistate[base + i] & IMSIC_EISTATE_ENPEND) =3D=3D + if ((qatomic_read(&imsic->eistate[base + i]) & IMSIC_EISTATE_ENPEN= D) =3D=3D IMSIC_EISTATE_ENPEND) { return (i << IMSIC_TOPEI_IID_SHIFT) | i; } @@ -66,10 +66,24 @@ static uint32_t riscv_imsic_topei(RISCVIMSICState *imsi= c, uint32_t page) =20 static void riscv_imsic_update(RISCVIMSICState *imsic, uint32_t page) { + uint32_t base =3D page * imsic->num_irqs; + + /* + * Lower the interrupt line if necessary, then evaluate the current + * IMSIC state. + * This sequence ensures that any race between evaluating the eistate = and + * updating the interrupt line will not result in an incorrectly + * deactivated connected CPU IRQ line. + * If multiple interrupts are pending, this sequence functions identic= ally + * to qemu_irq_pulse. + */ + + if (qatomic_fetch_and(&imsic->eistate[base], ~IMSIC_EISTATE_ENPEND)) { + qemu_irq_lower(imsic->external_irqs[page]); + } if (imsic->eidelivery[page] && riscv_imsic_topei(imsic, page)) { qemu_irq_raise(imsic->external_irqs[page]); - } else { - qemu_irq_lower(imsic->external_irqs[page]); + qatomic_or(&imsic->eistate[base], IMSIC_EISTATE_ENPEND); } } =20 @@ -125,12 +139,11 @@ static int riscv_imsic_topei_rmw(RISCVIMSICState *ims= ic, uint32_t page, topei >>=3D IMSIC_TOPEI_IID_SHIFT; base =3D page * imsic->num_irqs; if (topei) { - imsic->eistate[base + topei] &=3D ~IMSIC_EISTATE_PENDING; + qatomic_and(&imsic->eistate[base + topei], ~IMSIC_EISTATE_PEND= ING); } - - riscv_imsic_update(imsic, page); } =20 + riscv_imsic_update(imsic, page); return 0; } =20 @@ -139,7 +152,7 @@ static int riscv_imsic_eix_rmw(RISCVIMSICState *imsic, uint32_t num, bool pend, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { - uint32_t i, base; + uint32_t i, base, prev; target_ulong mask; uint32_t state =3D (pend) ? IMSIC_EISTATE_PENDING : IMSIC_EISTATE_ENAB= LED; =20 @@ -157,10 +170,6 @@ static int riscv_imsic_eix_rmw(RISCVIMSICState *imsic, =20 if (val) { *val =3D 0; - for (i =3D 0; i < xlen; i++) { - mask =3D (target_ulong)1 << i; - *val |=3D (imsic->eistate[base + i] & state) ? mask : 0; - } } =20 for (i =3D 0; i < xlen; i++) { @@ -172,10 +181,15 @@ static int riscv_imsic_eix_rmw(RISCVIMSICState *imsic, mask =3D (target_ulong)1 << i; if (wr_mask & mask) { if (new_val & mask) { - imsic->eistate[base + i] |=3D state; + prev =3D qatomic_fetch_or(&imsic->eistate[base + i], state= ); } else { - imsic->eistate[base + i] &=3D ~state; + prev =3D qatomic_fetch_and(&imsic->eistate[base + i], ~sta= te); } + } else { + prev =3D qatomic_read(&imsic->eistate[base + i]); + } + if (val && (prev & state)) { + *val |=3D mask; } } =20 @@ -302,14 +316,14 @@ static void riscv_imsic_write(void *opaque, hwaddr ad= dr, uint64_t value, page =3D addr >> IMSIC_MMIO_PAGE_SHIFT; if ((addr & (IMSIC_MMIO_PAGE_SZ - 1)) =3D=3D IMSIC_MMIO_PAGE_LE) { if (value && (value < imsic->num_irqs)) { - imsic->eistate[(page * imsic->num_irqs) + value] |=3D - IMSIC_EISTATE_PENDING; + qatomic_or(&imsic->eistate[(page * imsic->num_irqs) + value], + IMSIC_EISTATE_PENDING); + + /* Update CPU external interrupt status */ + riscv_imsic_update(imsic, page); } } =20 - /* Update CPU external interrupt status */ - riscv_imsic_update(imsic, page); - return; =20 err: --=20 2.46.0