From nobody Mon Feb 9 00:18:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=sifive.com ARC-Seal: i=1; a=rsa-sha256; t=1745574354; cv=none; d=zohomail.com; s=zohoarc; b=T4Swmk8S0wv+PoWStX/FU2BG2nCpOPBzzGnEj57bO+oggdFE3rvaBPTa+oFdoZtF57PmjiEF2KB8Wu4stqDzONkllwU6oUlIILIFHW1zoA8wQv/WerszkBWRoPQ7gsQ+i1pBP78nnOPoT620nXm2dpL4yumBs45b8248SGsaozo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745574354; 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=3KzbB1hdkpFonoFDX89kp5voEfL/PIiiTiwDmD7yoVU=; b=NNmhOF0XBOBP7YCDuiziHy3IzBENZMLWcR0vsAJqpUH+ZtgELDWjBrVOwtqlPrFST4+TgcQLVCJYL/kPuQfauTrVsLQg/2OzFADxUQxTS0IhbKyey8pwcPJOx3Y7waGHYyaw7XLWENQgd8KiwkvnAsl+7AAJY6XFB0leAzeZ3yk= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745574354050661.7572641201854; Fri, 25 Apr 2025 02:45:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8FcQ-0007kJ-7w; Fri, 25 Apr 2025 05:45:14 -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 1u8FcL-0007cx-C9 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 05:45:09 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u8FcH-0001D5-P6 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 05:45:08 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-3054ef26da3so1718927a91.3 for ; Fri, 25 Apr 2025 02:45:05 -0700 (PDT) Received: from jchang-1875.internal.sifive.com ([136.226.228.205]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-309f27e22dasm2288826a91.17.2025.04.25.02.45.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 25 Apr 2025 02:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1745574304; x=1746179104; 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=3KzbB1hdkpFonoFDX89kp5voEfL/PIiiTiwDmD7yoVU=; b=eyT34N7zUpsHc2TABQvqUse7ktBgACbU8clSQXnSdbEEi2KFti2UPoWsqHxGliEhOT HPaQNK4tsglRWnkcYIU5FmLhINS1caJwojYqiLOHU/lZtz9ZK/uTkk03xY+E1lgjtXSd EFlCEtgtnuO05G67EnPHFqHq2aA9zGgGIw7yFDCC48VN+p5Yk7vYXkaeGWWzOS3HnZ2h wWeTsZbtWhh9nc753Pw9SpS4O0x/sb2ZD3zXsPhAQq+ifkhv5PScwEaCA3doNlBz1dXQ BSdvzLGEbiMG1V3MKe3AMfN4ECrO556jJ//831UpMOGGvTSaHB+YVcMIdu7itiLyZkcc xukQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745574304; x=1746179104; 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=3KzbB1hdkpFonoFDX89kp5voEfL/PIiiTiwDmD7yoVU=; b=PQOYZ1OU0mYUaqQe/wpeDunXEiqEmdSDhff8EGfB7ngAolzmwi1Rux0uU6D7WzZAEO YUnOS1+75LKMhf0flquBDJddL5UV1Ixvb5UPVSAuvI6I/Q+p2QW/yDjpsJyMccvVQ92+ d8Q3fpqJv6mmSsaafLe7BK2Kvpr7pcA6aO/O35l0Szk/J13jm+um1Y/B4vDtqG0Cged/ lKds0J6K35AfqRDq2Ykhozm4E7noqbeB1Yk8wO6mc8kF+l65AicvzHNQsDf1PkYLxZr8 Kq8AOxiKBwUZ/lcRW70ihK6teu7FvttnekhhlNeSpskq/wWJqHdMLp+CRiE0vVa5/Dp4 i31g== X-Gm-Message-State: AOJu0Yy0yNc+siPRlbG1p4MlJtwgv3g87C4gQ4LzgZzE42BGhJ8XvIgz cc2qBiK2bnSZS1Fw/OSxTMm39Y5MG9NVMEUegoG6TlyhqdMRsZHDX37kdCNubeN+IoEvMxTPeyJ qxGWwL5w/Lcwq2vFvHyTwg3MtUYctaBqteR4vsuSxy50xgWos+3fdAL+fNZSq5I5alFwMt1T0ts 3RC+DjwnxqYaL8+4LTcZmuaOoZRbuIZG+tqj49I9eg8UWZ X-Gm-Gg: ASbGncs5r6ZgdBmF7DkiaEkIz8FzidA/yyt4+LV0xeeOp/uAumLAkCo0SpJYUY289Mo gsERwKLoDB1B7T2QY3PgizcS2wevM6miZbItirBfVjc/SLVQ+b/6jHITeRHF+78fUJgZ9jEZsU/ s0pKayKFFvgRjMgkOMROLytnRwyI+kigI84MKT+t/5goHHZLTOTgP6Sj2u0WfMWMi+RjUUPLU+4 ddQSrRkTlaKD/3QPiFMhgBsUu4fbP1jYwCE5uWva5tCJO2Pvgdmy4GeDz7L9cIFhnANUbNUsUCs KJdOgwLvoe//F1FHUjgNw+kx5ltyE0RyGCI5e7oj9yDdUJ3i0Z+ldvctq1RyOVfVWKD7q4hco/P pAeX9XJR6cA== X-Google-Smtp-Source: AGHT+IGxPk3viY6u9OGg+cQz4CraYFdOr9CbyXJYZemI4mSjSEPOtjdbNhXarzQ4Z3LCB/inAyi2og== X-Received: by 2002:a17:90b:3a43:b0:2fe:99cf:f579 with SMTP id 98e67ed59e1d1-309f8d8cdbemr2102745a91.4.1745574303722; Fri, 25 Apr 2025 02:45:03 -0700 (PDT) From: Jay Chang To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Jay Chang , Frank Chang Subject: [PATCH v2 1/2] target/riscv: Extend PMP region up to 64 Date: Fri, 25 Apr 2025 17:44:51 +0800 Message-ID: <20250425094452.17013-2-jay.chang@sifive.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250425094452.17013-1-jay.chang@sifive.com> References: <20250425094452.17013-1-jay.chang@sifive.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::1032; envelope-from=jay.chang@sifive.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @sifive.com) X-ZM-MESSAGEID: 1745574354696019000 According to the RISC-V Privileged Specification (version >1.12), RV32 supports 16 CSRs (pmpcfg0=E2=80=93pmpcfg15) to configure 64 PMP regions (pmpaddr0=E2=80=93pmpaddr63). Reviewed-by: Frank Chang Signed-off-by: Jay Chang Reviewed-by: Alistair Francis --- target/riscv/cpu_bits.h | 60 +++++++++++++++++++ target/riscv/csr.c | 124 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 182 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index a30317c617..e6b3e28386 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -372,6 +372,18 @@ #define CSR_PMPCFG1 0x3a1 #define CSR_PMPCFG2 0x3a2 #define CSR_PMPCFG3 0x3a3 +#define CSR_PMPCFG4 0x3a4 +#define CSR_PMPCFG5 0x3a5 +#define CSR_PMPCFG6 0x3a6 +#define CSR_PMPCFG7 0x3a7 +#define CSR_PMPCFG8 0x3a8 +#define CSR_PMPCFG9 0x3a9 +#define CSR_PMPCFG10 0x3aa +#define CSR_PMPCFG11 0x3ab +#define CSR_PMPCFG12 0x3ac +#define CSR_PMPCFG13 0x3ad +#define CSR_PMPCFG14 0x3ae +#define CSR_PMPCFG15 0x3af #define CSR_PMPADDR0 0x3b0 #define CSR_PMPADDR1 0x3b1 #define CSR_PMPADDR2 0x3b2 @@ -388,6 +400,54 @@ #define CSR_PMPADDR13 0x3bd #define CSR_PMPADDR14 0x3be #define CSR_PMPADDR15 0x3bf +#define CSR_PMPADDR16 0x3c0 +#define CSR_PMPADDR17 0x3c1 +#define CSR_PMPADDR18 0x3c2 +#define CSR_PMPADDR19 0x3c3 +#define CSR_PMPADDR20 0x3c4 +#define CSR_PMPADDR21 0x3c5 +#define CSR_PMPADDR22 0x3c6 +#define CSR_PMPADDR23 0x3c7 +#define CSR_PMPADDR24 0x3c8 +#define CSR_PMPADDR25 0x3c9 +#define CSR_PMPADDR26 0x3ca +#define CSR_PMPADDR27 0x3cb +#define CSR_PMPADDR28 0x3cc +#define CSR_PMPADDR29 0x3cd +#define CSR_PMPADDR30 0x3ce +#define CSR_PMPADDR31 0x3cf +#define CSR_PMPADDR32 0x3d0 +#define CSR_PMPADDR33 0x3d1 +#define CSR_PMPADDR34 0x3d2 +#define CSR_PMPADDR35 0x3d3 +#define CSR_PMPADDR36 0x3d4 +#define CSR_PMPADDR37 0x3d5 +#define CSR_PMPADDR38 0x3d6 +#define CSR_PMPADDR39 0x3d7 +#define CSR_PMPADDR40 0x3d8 +#define CSR_PMPADDR41 0x3d9 +#define CSR_PMPADDR42 0x3da +#define CSR_PMPADDR43 0x3db +#define CSR_PMPADDR44 0x3dc +#define CSR_PMPADDR45 0x3dd +#define CSR_PMPADDR46 0x3de +#define CSR_PMPADDR47 0x3df +#define CSR_PMPADDR48 0x3e0 +#define CSR_PMPADDR49 0x3e1 +#define CSR_PMPADDR50 0x3e2 +#define CSR_PMPADDR51 0x3e3 +#define CSR_PMPADDR52 0x3e4 +#define CSR_PMPADDR53 0x3e5 +#define CSR_PMPADDR54 0x3e6 +#define CSR_PMPADDR55 0x3e7 +#define CSR_PMPADDR56 0x3e8 +#define CSR_PMPADDR57 0x3e9 +#define CSR_PMPADDR58 0x3ea +#define CSR_PMPADDR59 0x3eb +#define CSR_PMPADDR60 0x3ec +#define CSR_PMPADDR61 0x3ed +#define CSR_PMPADDR62 0x3ee +#define CSR_PMPADDR63 0x3ef =20 /* RNMI */ #define CSR_MNSCRATCH 0x740 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 560b45d10d..41cf469615 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -6093,6 +6093,30 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_PMPCFG1] =3D { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG2] =3D { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG3] =3D { "pmpcfg3", pmp, read_pmpcfg, write_pmpcfg }, + [CSR_PMPCFG4] =3D { "pmpcfg4", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG5] =3D { "pmpcfg5", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG6] =3D { "pmpcfg6", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG7] =3D { "pmpcfg7", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG8] =3D { "pmpcfg8", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG9] =3D { "pmpcfg9", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG10] =3D { "pmpcfg10", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG11] =3D { "pmpcfg11", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG12] =3D { "pmpcfg12", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG13] =3D { "pmpcfg13", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG14] =3D { "pmpcfg14", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPCFG15] =3D { "pmpcfg15", pmp, read_pmpcfg, write_pmpcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, [CSR_PMPADDR0] =3D { "pmpaddr0", pmp, read_pmpaddr, write_pmpaddr }, [CSR_PMPADDR1] =3D { "pmpaddr1", pmp, read_pmpaddr, write_pmpaddr }, [CSR_PMPADDR2] =3D { "pmpaddr2", pmp, read_pmpaddr, write_pmpaddr }, @@ -6107,8 +6131,104 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_PMPADDR11] =3D { "pmpaddr11", pmp, read_pmpaddr, write_pmpaddr }, [CSR_PMPADDR12] =3D { "pmpaddr12", pmp, read_pmpaddr, write_pmpaddr }, [CSR_PMPADDR13] =3D { "pmpaddr13", pmp, read_pmpaddr, write_pmpaddr }, - [CSR_PMPADDR14] =3D { "pmpaddr14", pmp, read_pmpaddr, write_pmpaddr }, - [CSR_PMPADDR15] =3D { "pmpaddr15", pmp, read_pmpaddr, write_pmpaddr }, + [CSR_PMPADDR14] =3D { "pmpaddr14", pmp, read_pmpaddr, write_pmpaddr }, + [CSR_PMPADDR15] =3D { "pmpaddr15", pmp, read_pmpaddr, write_pmpaddr }, + [CSR_PMPADDR16] =3D { "pmpaddr16", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR17] =3D { "pmpaddr17", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR18] =3D { "pmpaddr18", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR19] =3D { "pmpaddr19", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR20] =3D { "pmpaddr20", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR21] =3D { "pmpaddr21", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR22] =3D { "pmpaddr22", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR23] =3D { "pmpaddr23", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR24] =3D { "pmpaddr24", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR25] =3D { "pmpaddr25", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR26] =3D { "pmpaddr26", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR27] =3D { "pmpaddr27", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR28] =3D { "pmpaddr28", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR29] =3D { "pmpaddr29", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR30] =3D { "pmpaddr30", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR31] =3D { "pmpaddr31", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR32] =3D { "pmpaddr32", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR33] =3D { "pmpaddr33", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR34] =3D { "pmpaddr34", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR35] =3D { "pmpaddr35", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR36] =3D { "pmpaddr36", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR37] =3D { "pmpaddr37", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR38] =3D { "pmpaddr38", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR39] =3D { "pmpaddr39", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR40] =3D { "pmpaddr40", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR41] =3D { "pmpaddr41", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR42] =3D { "pmpaddr42", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR43] =3D { "pmpaddr43", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR44] =3D { "pmpaddr44", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR45] =3D { "pmpaddr45", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR46] =3D { "pmpaddr46", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR47] =3D { "pmpaddr47", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR48] =3D { "pmpaddr48", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR49] =3D { "pmpaddr49", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR50] =3D { "pmpaddr50", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR51] =3D { "pmpaddr51", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR52] =3D { "pmpaddr52", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR53] =3D { "pmpaddr53", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR54] =3D { "pmpaddr54", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR55] =3D { "pmpaddr55", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR56] =3D { "pmpaddr56", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR57] =3D { "pmpaddr57", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR58] =3D { "pmpaddr58", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR59] =3D { "pmpaddr59", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR60] =3D { "pmpaddr60", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR61] =3D { "pmpaddr61", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR62] =3D { "pmpaddr62", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_PMPADDR63] =3D { "pmpaddr63", pmp, read_pmpaddr, write_pmpaddr, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, =20 /* Debug CSRs */ [CSR_TSELECT] =3D { "tselect", debug, read_tselect, write_tselect= }, --=20 2.48.1 From nobody Mon Feb 9 00:18:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=sifive.com ARC-Seal: i=1; a=rsa-sha256; t=1745574357; cv=none; d=zohomail.com; s=zohoarc; b=dhfuxQMqO97SfruUssIwtx6R0zCve2ALJNYYl7B4vUPv1OO5jXTyrEqx41gttoi9c7CvqQFCTspydmdkZt8YFc9CJfb5qIFl2wYsfIKGs+hVKlUUkeeJzY5sq2mSvcaW93EZYbwX0JcgMLkU7yHhr3Tpo6GdmLtb+sFyi2Gu2xw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745574357; 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=wPyR9ISg3Z6Gzq43oyU6p3l7xjpmxyGvN24IK2eZha8=; b=CVhsDO0kiIUUQxikr8zbWsjtDQcP11A/HepC8l0FBul5D4uSl+moCHXI0nGVNAIVD7ry7iXStIqYB9+Ivc61hTjZOrKeCjqyQhPZVRxTX9zOYVMb/ag5/wCLTLYVXtdHqTwSDXEBjtYG523zRMCsfoqvu2dvKIwikcRg0QSDKcI= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745574357197353.37184715187107; Fri, 25 Apr 2025 02:45:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8FcV-0007ov-A1; Fri, 25 Apr 2025 05:45:19 -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 1u8FcO-0007i1-H9 for qemu-devel@nongnu.org; Fri, 25 Apr 2025 05:45:13 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u8FcL-0001GU-7A for qemu-devel@nongnu.org; Fri, 25 Apr 2025 05:45:11 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-22c336fcdaaso24219285ad.3 for ; Fri, 25 Apr 2025 02:45:08 -0700 (PDT) Received: from jchang-1875.internal.sifive.com ([136.226.228.205]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-309f27e22dasm2288826a91.17.2025.04.25.02.45.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 25 Apr 2025 02:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1745574307; x=1746179107; 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=wPyR9ISg3Z6Gzq43oyU6p3l7xjpmxyGvN24IK2eZha8=; b=FsEhOiabi1+0aW5FlCGFKzdblFafVa1gp19Zl8+1ik2bxxG8IlORiOhUgHBc4JWIMi WmI/Ujop1Vmip/Fs7Rc1AVovRQzbj+fAAquqy6E9dY0l1t02t4BDahVyB1n9kd8CEB/l UumO6PerQoKrveBLS2BOcKGJ/iuvZUvk4SzbFppfn7b2QKVNl/asKvkcUE2Ijos8svFH yjrygxrntWSNuqXxeJszxb43lduZfuQKuzqL8ztgwoXKD/g3RyLOsakR8UZR/9uisjQV 1jxUfif8vpp2OnIGBvs9XJcXZeA1BbCdWIELpLfj2BCXK7BCQL//HFQRQFVVE3FTMwDX deEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745574307; x=1746179107; 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=wPyR9ISg3Z6Gzq43oyU6p3l7xjpmxyGvN24IK2eZha8=; b=LYA7AjBQIogLjrNjnBCiiyjdR3wWdy8KNWDem20kT+5DBKvWaY/ojm37NLeFG3KQXL +LtB0eQnji2ZPuhf2JsKfSxX1fx91ZOncS55ekK3f1rF1AVtwfWTtqqeTA+zZydsgPgx B05WAI6cUn64bhhNTdi+XJHJLsDmXA4fHSHkUebgqtIvumHZP0qvzbFIzGKz7Z3Eph9R OvNtMIog3EouU+sQmk6gnhtpf8BWhmR+0Y47D76V1KMdc8Hy9tVtJWIqmbUBsQ9N/ucg iM43hieVKvlT6Z+ManDtXUF5RL+XR3UnCiQU/x6u24K8S3thun1hlCMfv+cmw0z4jG81 493g== X-Gm-Message-State: AOJu0Yy/hrZNAQEsj5R/g5Dgu24YYP1yhKRiup56dP4xv3KwohqpBTeA GPqKqO8b6Tj+o1G3nLap1YW1ybQ8KdwkPzsaPrAVzjisY2QlzQQ8GqR6NpEkpufIQUh6jTvu6zt Mj6Z0/Rzgl0bBV7R1F5wKyg5F5CbsfCpPbfh+ODB1I42QK0qqzBYknnAJmFGhQPdXxT7mapxlzM xuxVjhNUZDtfNQOlvzGp8MPBBMQgBnI4MiVGOyDJOZAdiy X-Gm-Gg: ASbGncu0AqbT48BLgVJhvNH0ezua7KqUod+6bKJq+eOv3aJpJnw3SHKwzJ/pcylVEBS fz+spyghTB+zZFAjhPJduj4NyvsFVmgz+I0CgswtfJwcQ9GHpPLMv8rrDJnus2Y2MiVItMdXUek wDklGj7+z+Edp3puUOLG7iNqLWebv6kEFtoOR+nz3JqiPIgcWKmfr+PrsxwGKMVd6RgE9wlzCrh Tq0Sw+cbWVdTvvDR1rjP1xSYE1z91h7zx4XPyPUbhpM63N7uHyjT4gqtjCuzz47PVFNb8uWeM6P VUnv/Q2FORVCUqEnhWR8IPNj3L9iHcyNWL2iutDe90IuR7hT9Vgcr8dsRE+LREdV6Y6qbTOBjPp JreDv8vFu+uZC34FP5Xl+ X-Google-Smtp-Source: AGHT+IEqq3nt6n75tIdmubGO21PuetqxIPHl6yVqppq6my43SHCp951bQdTpK7NfhDB0+eKdyJIGFg== X-Received: by 2002:a17:90b:5101:b0:305:2d27:7ba0 with SMTP id 98e67ed59e1d1-309f7d87675mr2877505a91.6.1745574306984; Fri, 25 Apr 2025 02:45:06 -0700 (PDT) From: Jay Chang To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Jay Chang , Frank Chang Subject: [PATCH v2 2/2] target/riscv: Make PMP region count configurable Date: Fri, 25 Apr 2025 17:44:52 +0800 Message-ID: <20250425094452.17013-3-jay.chang@sifive.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250425094452.17013-1-jay.chang@sifive.com> References: <20250425094452.17013-1-jay.chang@sifive.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::636; envelope-from=jay.chang@sifive.com; helo=mail-pl1-x636.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @sifive.com) X-ZM-MESSAGEID: 1745574359457019000 Content-Type: text/plain; charset="utf-8" Previously, the number of PMP regions was hardcoded to 16 in QEMU. This patch replaces the fixed value with a new `pmp_regions` field, allowing platforms to configure the number of PMP regions. If no specific value is provided, the default number of PMP regions remains 16 to preserve the existing behavior. A new CPU parameter num-pmp-regions has been introduced to the QEMU command line. For example: -cpu rv64, g=3Dtrue, c=3Dtrue, pmp=3Dtrue, num-pmp-regions=3D8 Reviewed-by: Frank Chang Signed-off-by: Jay Chang --- target/riscv/cpu.c | 54 +++++++++++++++++++++++++++++-- target/riscv/cpu.h | 2 +- target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/csr.c | 5 ++- target/riscv/machine.c | 3 +- target/riscv/pmp.c | 28 ++++++++++------ 6 files changed, 79 insertions(+), 14 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ee20bd7ca2..9cab08f9df 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1123,6 +1123,7 @@ static void riscv_cpu_init(Object *obj) cpu->cfg.cbom_blocksize =3D 64; cpu->cfg.cbop_blocksize =3D 64; cpu->cfg.cboz_blocksize =3D 64; + cpu->cfg.pmp_regions =3D 16; cpu->env.vext_ver =3D VEXT_VERSION_1_00_0; cpu->cfg.max_satp_mode =3D -1; =20 @@ -1574,6 +1575,46 @@ static const PropertyInfo prop_pmp =3D { .set =3D prop_pmp_set, }; =20 +static void prop_num_pmp_regions_set(Object *obj, Visitor *v, const char *= name, + void *opaque, Error **errp) +{ + RISCVCPU *cpu =3D RISCV_CPU(obj); + uint16_t value; + + visit_type_uint16(v, name, &value, errp); + + if (cpu->cfg.pmp_regions !=3D value && riscv_cpu_is_vendor(obj)) { + cpu_set_prop_err(cpu, name, errp); + return; + } + + if (cpu->env.priv_ver < PRIV_VERSION_1_12_0 && value > 16) { + error_setg(errp, "Number of PMP regions exceeds maximum available"= ); + return; + } else if (value > 64) { + error_setg(errp, "Number of PMP regions exceeds maximum available"= ); + return; + } + + cpu_option_add_user_setting(name, value); + cpu->cfg.pmp_regions =3D value; +} + +static void prop_num_pmp_regions_get(Object *obj, Visitor *v, const char *= name, + void *opaque, Error **errp) +{ + uint16_t value =3D RISCV_CPU(obj)->cfg.pmp_regions; + + visit_type_uint16(v, name, &value, errp); +} + +static const PropertyInfo prop_num_pmp_regions =3D { + .type =3D "uint16", + .description =3D "num-pmp-regions", + .get =3D prop_num_pmp_regions_get, + .set =3D prop_num_pmp_regions_set, +}; + static int priv_spec_from_str(const char *priv_spec_str) { int priv_version =3D -1; @@ -2573,6 +2614,7 @@ static const Property riscv_cpu_properties[] =3D { =20 {.name =3D "mmu", .info =3D &prop_mmu}, {.name =3D "pmp", .info =3D &prop_pmp}, + {.name =3D "num-pmp-regions", .info =3D &prop_num_pmp_regions}, =20 {.name =3D "priv_spec", .info =3D &prop_priv_spec}, {.name =3D "vext_spec", .info =3D &prop_vext_spec}, @@ -2895,6 +2937,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { DEFINE_ABSTRACT_RISCV_CPU(TYPE_RISCV_DYNAMIC_CPU, TYPE_RISCV_CPU, .cfg.mmu =3D true, .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8, .priv_spec =3D PRIV_VERSION_LATEST, ), =20 @@ -2941,7 +2984,8 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { .cfg.max_satp_mode =3D VM_1_10_MBARE, .cfg.ext_zifencei =3D true, .cfg.ext_zicsr =3D true, - .cfg.pmp =3D true + .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8 ), =20 DEFINE_ABSTRACT_RISCV_CPU(TYPE_RISCV_CPU_SIFIVE_U, TYPE_RISCV_VENDOR_C= PU, @@ -2952,7 +2996,8 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { .cfg.ext_zifencei =3D true, .cfg.ext_zicsr =3D true, .cfg.mmu =3D true, - .cfg.pmp =3D true + .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8 ), =20 #if defined(TARGET_RISCV32) || \ @@ -2970,6 +3015,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { .cfg.ext_zifencei =3D true, .cfg.ext_zicsr =3D true, .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8, .cfg.ext_smepmp =3D true, =20 .cfg.ext_zba =3D true, @@ -3044,6 +3090,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { .cfg.ext_xtheadmempair =3D true, .cfg.ext_xtheadsync =3D true, .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8, =20 .cfg.mvendorid =3D THEAD_VENDOR_ID, =20 @@ -3067,6 +3114,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { .cfg.rvv_ta_all_1s =3D true, .cfg.misa_w =3D true, .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8, .cfg.cbom_blocksize =3D 64, .cfg.cbop_blocksize =3D 64, .cfg.cboz_blocksize =3D 64, @@ -3123,6 +3171,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { .cfg.ext_zifencei =3D true, .cfg.ext_zicsr =3D true, .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8, .cfg.ext_zicbom =3D true, .cfg.cbom_blocksize =3D 64, .cfg.cboz_blocksize =3D 64, @@ -3167,6 +3216,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { =20 .cfg.mmu =3D true, .cfg.pmp =3D true, + .cfg.pmp_regions =3D 8, =20 .cfg.max_satp_mode =3D VM_1_10_SV39, ), diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 679f417336..de4517c4f8 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -162,7 +162,7 @@ extern RISCVCPUImpliedExtsRule *riscv_multi_ext_implied= _rules[]; =20 #define MMU_USER_IDX 3 =20 -#define MAX_RISCV_PMPS (16) +#define MAX_RISCV_PMPS (64) =20 #if !defined(CONFIG_USER_ONLY) #include "pmp.h" diff --git a/target/riscv/cpu_cfg_fields.h.inc b/target/riscv/cpu_cfg_field= s.h.inc index 59f134a419..d80eb1eb7b 100644 --- a/target/riscv/cpu_cfg_fields.h.inc +++ b/target/riscv/cpu_cfg_fields.h.inc @@ -163,6 +163,7 @@ TYPED_FIELD(uint16_t, elen, 0) TYPED_FIELD(uint16_t, cbom_blocksize, 0) TYPED_FIELD(uint16_t, cbop_blocksize, 0) TYPED_FIELD(uint16_t, cboz_blocksize, 0) +TYPED_FIELD(uint16_t, pmp_regions, 0) =20 TYPED_FIELD(int8_t, max_satp_mode, -1) =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 41cf469615..daaef8c438 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -736,7 +736,10 @@ static RISCVException dbltrp_hmode(CPURISCVState *env,= int csrno) static RISCVException pmp(CPURISCVState *env, int csrno) { if (riscv_cpu_cfg(env)->pmp) { - if (csrno <=3D CSR_PMPCFG3) { + uint16_t MAX_PMPCFG =3D (env->priv_ver >=3D PRIV_VERSION_1_12_0) ? ++ CSR_PMPCFG15 : CSR_PMPCFG3; + + if (csrno <=3D MAX_PMPCFG) { uint32_t reg_index =3D csrno - CSR_PMPCFG0; =20 /* TODO: RV128 restriction check */ diff --git a/target/riscv/machine.c b/target/riscv/machine.c index df2d5bad8d..e9a179ae55 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -36,8 +36,9 @@ static int pmp_post_load(void *opaque, int version_id) RISCVCPU *cpu =3D opaque; CPURISCVState *env =3D &cpu->env; int i; + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; =20 - for (i =3D 0; i < MAX_RISCV_PMPS; i++) { + for (i =3D 0; i < pmp_regions; i++) { pmp_update_rule_addr(env, i); } pmp_update_rule_nums(env); diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index c685f7f2c5..3439295d41 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -121,7 +121,9 @@ uint32_t pmp_get_num_rules(CPURISCVState *env) */ static inline uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t pmp_index) { - if (pmp_index < MAX_RISCV_PMPS) { + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; + + if (pmp_index < pmp_regions) { return env->pmp_state.pmp[pmp_index].cfg_reg; } =20 @@ -135,7 +137,9 @@ static inline uint8_t pmp_read_cfg(CPURISCVState *env, = uint32_t pmp_index) */ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t = val) { - if (pmp_index < MAX_RISCV_PMPS) { + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; + + if (pmp_index < pmp_regions) { if (env->pmp_state.pmp[pmp_index].cfg_reg =3D=3D val) { /* no change */ return false; @@ -235,9 +239,10 @@ void pmp_update_rule_addr(CPURISCVState *env, uint32_t= pmp_index) void pmp_update_rule_nums(CPURISCVState *env) { int i; + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; =20 env->pmp_state.num_rules =3D 0; - for (i =3D 0; i < MAX_RISCV_PMPS; i++) { + for (i =3D 0; i < pmp_regions; i++) { const uint8_t a_field =3D pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg); if (PMP_AMATCH_OFF !=3D a_field) { @@ -331,6 +336,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr, int pmp_size =3D 0; hwaddr s =3D 0; hwaddr e =3D 0; + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; =20 /* Short cut if no rules */ if (0 =3D=3D pmp_get_num_rules(env)) { @@ -355,7 +361,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr, * 1.10 draft priv spec states there is an implicit order * from low to high */ - for (i =3D 0; i < MAX_RISCV_PMPS; i++) { + for (i =3D 0; i < pmp_regions; i++) { s =3D pmp_is_in_range(env, i, addr); e =3D pmp_is_in_range(env, i, addr + pmp_size - 1); =20 @@ -526,8 +532,9 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t add= r_index, { trace_pmpaddr_csr_write(env->mhartid, addr_index, val); bool is_next_cfg_tor =3D false; + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; =20 - if (addr_index < MAX_RISCV_PMPS) { + if (addr_index < pmp_regions) { if (env->pmp_state.pmp[addr_index].addr_reg =3D=3D val) { /* no change */ return; @@ -537,7 +544,7 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t add= r_index, * In TOR mode, need to check the lock bit of the next pmp * (if there is a next). */ - if (addr_index + 1 < MAX_RISCV_PMPS) { + if (addr_index + 1 < pmp_regions) { uint8_t pmp_cfg =3D env->pmp_state.pmp[addr_index + 1].cfg_reg; is_next_cfg_tor =3D PMP_AMATCH_TOR =3D=3D pmp_get_a_field(pmp_= cfg); =20 @@ -572,8 +579,9 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t add= r_index, target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index) { target_ulong val =3D 0; + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; =20 - if (addr_index < MAX_RISCV_PMPS) { + if (addr_index < pmp_regions) { val =3D env->pmp_state.pmp[addr_index].addr_reg; trace_pmpaddr_csr_read(env->mhartid, addr_index, val); } else { @@ -591,6 +599,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong= val) { int i; uint64_t mask =3D MSECCFG_MMWP | MSECCFG_MML; + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; /* Update PMM field only if the value is valid according to Zjpm v1.0 = */ if (riscv_cpu_cfg(env)->ext_smmpm && riscv_cpu_mxl(env) =3D=3D MXL_RV64 && @@ -602,7 +611,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong= val) =20 /* RLB cannot be enabled if it's already 0 and if any regions are lock= ed */ if (!MSECCFG_RLB_ISSET(env)) { - for (i =3D 0; i < MAX_RISCV_PMPS; i++) { + for (i =3D 0; i < pmp_regions; i++) { if (pmp_is_locked(env, i)) { val &=3D ~MSECCFG_RLB; break; @@ -658,6 +667,7 @@ target_ulong pmp_get_tlb_size(CPURISCVState *env, hwadd= r addr) hwaddr tlb_sa =3D addr & ~(TARGET_PAGE_SIZE - 1); hwaddr tlb_ea =3D tlb_sa + TARGET_PAGE_SIZE - 1; int i; + uint16_t pmp_regions =3D riscv_cpu_cfg(env)->pmp_regions; =20 /* * If PMP is not supported or there are no PMP rules, the TLB page wil= l not @@ -668,7 +678,7 @@ target_ulong pmp_get_tlb_size(CPURISCVState *env, hwadd= r addr) return TARGET_PAGE_SIZE; } =20 - for (i =3D 0; i < MAX_RISCV_PMPS; i++) { + for (i =3D 0; i < pmp_regions; i++) { if (pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg) =3D=3D PMP_AMAT= CH_OFF) { continue; } --=20 2.48.1