From nobody Tue Dec 16 11:29:20 2025 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1753602169; cv=none; d=zohomail.com; s=zohoarc; b=WJU+kCJNkJfAlNVJx9JJI8HK7RA9Ziddz9rDaSbK2xp8TirxTggU9uEoEkUqxwJEYXRh0AC3Zn2vldYRtO5UtcqjTSaMr5OJr0ZGGpswpKVTMmONGxJX9v5uWNF2bMww9Lu6S+8B0zXQ5bMWQQL15QQKm6COQ0vsKGf2T445idM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753602169; 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=ZZEiredJhDqkeFwlGWRs9PoM2IRfxTwE098IMi+CROg=; b=ZPnsaAvp4lN5dmruBPu8x29vdvQnhUUOhD72s8cAXsRN4uKzNpdUmgxRCamz1BWc50u/WFyW7ZO+OCbTIzEIGb5w5XflzHEVMxg2S/ZeAr5uVazAAvgzTzqwpjdXQywoW+d9ouvNsJhxACJvgQALrLvymhuT1pvjhrdQXxP8Tk4= 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 1753602169204891.0964607405151; Sun, 27 Jul 2025 00:42:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ufw1a-0007GN-PG; Sun, 27 Jul 2025 03:42:26 -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 1ufw1U-0006S3-2t for qemu-devel@nongnu.org; Sun, 27 Jul 2025 03:42:20 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ufw1R-00016E-Vn for qemu-devel@nongnu.org; Sun, 27 Jul 2025 03:42:19 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-b390136ed88so2609271a12.2 for ; Sun, 27 Jul 2025 00:42:16 -0700 (PDT) Received: from localhost.localdomain (syn-098-150-199-049.res.spectrum.com. [98.150.199.49]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23fbe53b546sm29633055ad.177.2025.07.27.00.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Jul 2025 00:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1753602135; x=1754206935; 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=ZZEiredJhDqkeFwlGWRs9PoM2IRfxTwE098IMi+CROg=; b=Ieogk1CU26FotQWi6k0KO91QMTswGgwiQNHzYu/QNDP7uAZnjNKoqEzUqwYuM8dkF2 M7QrZ2/+fcmo05IyvAhZuYKwropQBF4a0XxkutawT4JCHoSifGbZKa7pWD3G+iyHMpCm no6ahfGyJNgiJK1x4/OZZH/xFl+FWSgw1urxKfWwou9XKrm8lsAZtmtHYvDx0V5tC01s endK9T4oiIoI6k+EnPLNeu4q+I7r0NgvEZJv/srKicT8SPWRuVm1sp7/wihnzn0gMm3m umG9wEqWzR0JaVnENb1P/xanFEY6FSc0JeoXS1RhPo6kK0kVaa/PC9UnWQZx4wnexofK oTHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753602135; x=1754206935; 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=ZZEiredJhDqkeFwlGWRs9PoM2IRfxTwE098IMi+CROg=; b=JOrLITJwT6rN0eRE6LnLNxH26V7fUUtgaOxcmjAKH8MfZHJaxe7Zu5pPvEHSQ4FrOq 4BBrrXJ+1zlSSxuIO6Q8Lc/8horbINY9RV3W4cqZOgWobBYMZExf1MUnQ1kd7gJSgas0 wdevjCGQaXEE7/DY68LfhH0SNeLkCVG9ajGEUB308fhgAEMkHccRIkMCm7WA4Nd9yL89 iIrN7idVpgURA48o16BXog9sG+2C8L/YHA5hXDft/LqW3BENVP1LzRLrw01Pv1DXysX1 SO1aMrzGMmFNBWkfjWbBweVQftn8eRwKBLfsAoE+2nFU/EpoNLxnCN904PD3k2H49SmP ewbg== X-Gm-Message-State: AOJu0YxPaDB78vrA5J2nrx4qhKfyoFD0svuEA1n1PDE6I61SYOD7UZLx G/86sdkHZIPUPHSzRe08DQho1BxAUzmuHxLZAJCDZyxcE9CeEV8+gnlo3bgUrksufIrJgkwZzZr Q3Azm X-Gm-Gg: ASbGncuQ3YtZor9dV8svn6BSP2e6O/uw/vyLx0LJqm/QXxlQrN+pZ+2W2lWZMwCHqGn WR4+iK18KWcIruXO7AODQQNFddm1+Yni+NVPnRWQKKu9c9NQr21ym51c6bxImLZ1c56wgswKd6E DDAjcS/GlsYFBEzCruleW6D2jojgFJzoJ1s/JzclZNZr9lpkrbsPk+RGETLKw5ITTZrr0rTpzCF 35Dx8JEpTHTa/ZYovH3JGzDXk8qePfHsX4OsZM17bAljuF0wFgiwYVRNKw+JPmCUvjhRFAb3vgx LRqYwKD8ZNhv1Z5J9jr/fkhP7vsecApH3dcdWYesdLPBECb3zPjIwVQEyFpDkllMFc9kYfivtO6 f833OA89/GvCiabF4RdeEEg09ddEiCK5J51pj7C4c08O1YbinsvNB0AXLwgsRwhLAvahaIspZgb /8a/0q9BBZLQ== X-Google-Smtp-Source: AGHT+IHlnv3cRavrG/Z+dmdJIbWIeUqVaf/04dVWIjo/GK8lSsQasIEfOjU6+ZkzrLZyZWdTBOeeuQ== X-Received: by 2002:a17:903:32d1:b0:234:ef42:5d75 with SMTP id d9443c01a7336-23fb3032327mr109497715ad.20.1753602135264; Sun, 27 Jul 2025 00:42:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Gustavo Romero Subject: [PATCH v9 5/6] target/arm: Implement FEAT_MEC registers Date: Sat, 26 Jul 2025 21:42:01 -1000 Message-ID: <20250727074202.83141-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250727074202.83141-1-richard.henderson@linaro.org> References: <20250727074202.83141-1-richard.henderson@linaro.org> 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::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1753602171537116600 Content-Type: text/plain; charset="utf-8" From: Gustavo Romero Add all FEAT_MEC registers. Enable access to the registers via the SCTLR2 and TCR2 control bits. Add the two new cache management instructions, which are nops in QEMU because we do not model caches. Signed-off-by: Gustavo Romero Message-ID: <20250711140828.1714666-3-gustavo.romero@linaro.org> Reviewed-by: Richard Henderson [rth: Squash 3 patches to add all registers at once.] Signed-off-by: Richard Henderson --- target/arm/cpu-features.h | 5 ++ target/arm/cpu.h | 10 ++++ target/arm/internals.h | 3 ++ target/arm/cpu.c | 3 ++ target/arm/helper.c | 106 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h index 8ec8c3feb3..9579d93cec 100644 --- a/target/arm/cpu-features.h +++ b/target/arm/cpu-features.h @@ -914,6 +914,11 @@ static inline bool isar_feature_aa64_sctlr2(const ARMI= SARegisters *id) return FIELD_EX64_IDREG(id, ID_AA64MMFR3, SCTLRX) !=3D 0; } =20 +static inline bool isar_feature_aa64_mec(const ARMISARegisters *id) +{ + return FIELD_EX64_IDREG(id, ID_AA64MMFR3, MEC) !=3D 0; +} + static inline bool isar_feature_aa64_pmuv3p1(const ARMISARegisters *id) { return FIELD_EX64_IDREG(id, ID_AA64DFR0, PMUVER) >=3D 4 && diff --git a/target/arm/cpu.h b/target/arm/cpu.h index c15d79a106..defe2852f2 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -578,6 +578,15 @@ typedef struct CPUArchState { =20 /* NV2 register */ uint64_t vncr_el2; + + /* MEC registers */ + uint64_t mecid_p0_el2; + uint64_t mecid_a0_el2; + uint64_t mecid_p1_el2; + uint64_t mecid_a1_el2; + uint64_t mecid_rl_a_el3; + uint64_t vmecid_p_el2; + uint64_t vmecid_a_el2; } cp15; =20 struct { @@ -1730,6 +1739,7 @@ static inline void xpsr_write(CPUARMState *env, uint3= 2_t val, uint32_t mask) #define SCR_TCR2EN (1ULL << 43) #define SCR_SCTLR2EN (1ULL << 44) #define SCR_GPF (1ULL << 48) +#define SCR_MECEN (1ULL << 49) #define SCR_NSE (1ULL << 62) =20 /* Return the current FPSCR value. */ diff --git a/target/arm/internals.h b/target/arm/internals.h index ffc981c3b6..118659815f 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -2001,4 +2001,7 @@ void vfp_clear_float_status_exc_flags(CPUARMState *en= v); void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask); bool arm_pan_enabled(CPUARMState *env); =20 +/* Used in FEAT_MEC to set the MECIDWidthm1 field in the MECIDR_EL2 regist= er. */ +#define MECID_WIDTH 16 + #endif diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 27a4610da5..f0545a276e 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -650,6 +650,9 @@ void arm_emulate_firmware_reset(CPUState *cpustate, int= target_el) if (cpu_isar_feature(aa64_sctlr2, cpu)) { env->cp15.scr_el3 |=3D SCR_SCTLR2EN; } + if (cpu_isar_feature(aa64_mec, cpu)) { + env->cp15.scr_el3 |=3D SCR_MECEN; + } } =20 if (target_el =3D=3D 2) { diff --git a/target/arm/helper.c b/target/arm/helper.c index 5a219703ae..20b69a12df 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -747,6 +747,9 @@ static void scr_write(CPUARMState *env, const ARMCPRegI= nfo *ri, uint64_t value) if (cpu_isar_feature(aa64_sctlr2, cpu)) { valid_mask |=3D SCR_SCTLR2EN; } + if (cpu_isar_feature(aa64_mec, cpu)) { + valid_mask |=3D SCR_MECEN; + } } else { valid_mask &=3D ~(SCR_RW | SCR_ST); if (cpu_isar_feature(aa32_ras, cpu)) { @@ -5215,6 +5218,93 @@ static const ARMCPRegInfo nmi_reginfo[] =3D { .resetfn =3D arm_cp_reset_ignore }, }; =20 +static CPAccessResult mecid_access(CPUARMState *env, + const ARMCPRegInfo *ri, bool isread) +{ + int el =3D arm_current_el(env); + + if (el =3D=3D 2) { + if (arm_security_space(env) !=3D ARMSS_Realm) { + return CP_ACCESS_UNDEFINED; + } + + if (!(env->cp15.scr_el3 & SCR_MECEN)) { + return CP_ACCESS_TRAP_EL3; + } + } + + return CP_ACCESS_OK; +} + +static void mecid_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + value =3D extract64(value, 0, MECID_WIDTH); + raw_write(env, ri, value); +} + +static CPAccessResult cipae_access(CPUARMState *env, const ARMCPRegInfo *r= i, + bool isread) +{ + switch (arm_security_space(env)) { + case ARMSS_Root: /* EL3 */ + case ARMSS_Realm: /* Realm EL2 */ + return CP_ACCESS_OK; + default: + return CP_ACCESS_UNDEFINED; + } +} + +static const ARMCPRegInfo mec_reginfo[] =3D { + { .name =3D "MECIDR_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 7, .crn =3D 10, .crm =3D 8, + .access =3D PL2_R, .type =3D ARM_CP_CONST, .resetvalue =3D MECID_WID= TH - 1 }, + { .name =3D "MECID_P0_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 0, .crn =3D 10, .crm =3D 8, + .access =3D PL2_RW, .accessfn =3D mecid_access, + .writefn =3D mecid_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.mecid_p0_el2) }, + { .name =3D "MECID_A0_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 1, .crn =3D 10, .crm =3D 8, + .access =3D PL2_RW, .accessfn =3D mecid_access, + .writefn =3D mecid_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.mecid_a0_el2) }, + { .name =3D "MECID_P1_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 2, .crn =3D 10, .crm =3D 8, + .access =3D PL2_RW, .accessfn =3D mecid_access, + .writefn =3D mecid_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.mecid_p1_el2) }, + { .name =3D "MECID_A1_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 3, .crn =3D 10, .crm =3D 8, + .access =3D PL2_RW, .accessfn =3D mecid_access, + .writefn =3D mecid_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.mecid_a1_el2) }, + { .name =3D "MECID_RL_A_EL3", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 6, .opc2 =3D 1, .crn =3D 10, .crm =3D 10, + .access =3D PL3_RW, .accessfn =3D mecid_access, + .writefn =3D mecid_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.mecid_rl_a_el3) }, + { .name =3D "VMECID_P_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 0, .crn =3D 10, .crm =3D 9, + .access =3D PL2_RW, .accessfn =3D mecid_access, + .writefn =3D mecid_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.vmecid_p_el2) }, + { .name =3D "VMECID_A_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 1, .crn =3D 10, .crm =3D 9, + .access =3D PL2_RW, .accessfn =3D mecid_access, + .writefn =3D mecid_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.vmecid_a_el2) }, + { .name =3D "DC_CIPAE", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 4, .crn =3D 7, .crm =3D 14, .opc2 =3D 0, + .access =3D PL2_W, .accessfn =3D cipae_access, .type =3D ARM_CP_NOP = }, +}; + +static const ARMCPRegInfo mec_mte_reginfo[] =3D { + { .name =3D "DC_CIGDPAE", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 1, .opc1 =3D 4, .crn =3D 7, .crm =3D 14, .opc2 =3D 7, + .access =3D PL2_W, .accessfn =3D cipae_access, .type =3D ARM_CP_NOP = }, +}; + #ifndef CONFIG_USER_ONLY /* * We don't know until after realize whether there's a GICv3 @@ -6053,6 +6143,9 @@ static void sctlr2_el2_write(CPUARMState *env, const = ARMCPRegInfo *ri, { uint64_t valid_mask =3D 0; =20 + if (cpu_isar_feature(aa64_mec, env_archcpu(env))) { + valid_mask |=3D SCTLR2_EMEC; + } value &=3D valid_mask; raw_write(env, ri, value); } @@ -6062,6 +6155,9 @@ static void sctlr2_el3_write(CPUARMState *env, const = ARMCPRegInfo *ri, { uint64_t valid_mask =3D 0; =20 + if (cpu_isar_feature(aa64_mec, env_archcpu(env))) { + valid_mask |=3D SCTLR2_EMEC; + } value &=3D valid_mask; raw_write(env, ri, value); } @@ -6122,6 +6218,9 @@ static void tcr2_el2_write(CPUARMState *env, const AR= MCPRegInfo *ri, { uint64_t valid_mask =3D 0; =20 + if (cpu_isar_feature(aa64_mec, env_archcpu(env))) { + valid_mask |=3D TCR2_AMEC0 | TCR2_AMEC1; + } value &=3D valid_mask; raw_write(env, ri, value); } @@ -7377,6 +7476,13 @@ void register_cp_regs_for_features(ARMCPU *cpu) define_arm_cp_regs(cpu, tcr2_reginfo); } =20 + if (cpu_isar_feature(aa64_mec, cpu)) { + define_arm_cp_regs(cpu, mec_reginfo); + if (cpu_isar_feature(aa64_mte, cpu)) { + define_arm_cp_regs(cpu, mec_mte_reginfo); + } + } + if (cpu_isar_feature(any_predinv, cpu)) { define_arm_cp_regs(cpu, predinv_reginfo); } --=20 2.43.0