From nobody Thu Dec 18 21:08:44 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=1752166774; cv=none; d=zohomail.com; s=zohoarc; b=C/ZEs2G4MUHTrvQeNQ/JUoVW7jZHgb8XNz0zhhmgpDuk3pS4KCcl7Wk/I1ZWdPesFDeIQF1g1LfvqEttggU+uIM1ZJORjjF2iNkSScYTbbbfqo1dsiUQWRyv68aJSuUoNfCGgzXTprg2S9gla3vQOFPxEpRSwOZMyxoo0AtFPeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752166774; 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=vSHu2C6AHkdi6I2MI+MN+9VTwDs09gk+qY11owIPdS8=; b=l8Q4MF6r6sjLXURhNBTNJ8voHuaxVnZ1LzUW0BFcaRpIRhq1/nfnGKEq64lqAAEE560sxULP7v9brVzVK0Gu9k+aD5y08oBVpGMLvGJ+Lpm3kq2z7m4hcmO+CJxR2aETqPfp6TME5gCluzi9mSYKzLux/dAfyXjWhFMdyCz6NTM= 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 1752166774239905.2479173785217; Thu, 10 Jul 2025 09:59:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uZuav-0007Ko-DZ; Thu, 10 Jul 2025 12:58:01 -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 1uZuL3-0003PL-Ol for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:37 -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 1uZuL2-00018E-65 for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:37 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-b34c068faf8so1368543a12.2 for ; Thu, 10 Jul 2025 09:41:35 -0700 (PDT) Received: from gromero0.. (189-47-46-41.dsl.telesp.net.br. [189.47.46.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f5c7f7sm2919119b3a.142.2025.07.10.09.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 09:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752165695; x=1752770495; 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=vSHu2C6AHkdi6I2MI+MN+9VTwDs09gk+qY11owIPdS8=; b=NxrXbiQN9yu93AEExV/fCjmH6OgZB1JuTjSsrV7nUW3jopBDcojbK+/zETaCuXFO5u +bEPKPmggEIOQeqSZgoZPzxcmS3iXFde8Yjihq3K8WdfMxCYP6T2xQy2s0G2XShi43eA xjK26EEcNq/gB4UVei2HCA+e7Brd5DbeMT/FRyV5M5usM3OTXNtGp4naZsHqZ5fHzrRw Yo7WCUF8Gh6W3xg0wFB4hJj6oHvyTsRpcSl/GvWes/Pt18E1vHUgx3Tc+TcC6efCJeqw Tk/8SkhY2DpA8URs9z4RnKEaFMgULIPIf2v4oVSiiu3KKmYpgEM+0WuutT3g2ecyOPud ptzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752165695; x=1752770495; 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=vSHu2C6AHkdi6I2MI+MN+9VTwDs09gk+qY11owIPdS8=; b=UIPDtADF9xYwvaz5MjFNX0mFbZJabZYs56Wb6QS5QoENi7WEtrVevyKgTGaajUD0hu ll08WTQTJaOoV+DeWzJ0s/lASS9ia93LsujxA8EvtHSVY5HZAd9cAqGJM+BuvrZhkZ86 12yYnTSbDFfhBY42iPcNdi2wNa89b/N7RNScq0BhYMT71vwcNsZZ8g8RmI08hM1RKOh1 F9Mje7v+bkd+xnuoPy6dbXcbHrOwBpAaYeJJGrPxNYpEwFSqPVjFTIDJ/Fi2QVogWw/1 k5aOf0S55yRpUqR9lWA4pJQtZQu2X/INKtpSRIxM21HlRuXbyDxh6JT80txmoPVilKmi E/Fg== X-Gm-Message-State: AOJu0YzVroSQm1/FFUwTkuYBMjZB2Z+CjEn7AMeiEwtOzBOaHMiUKXK+ PtRizyVqIjOU4f+Lwwc4DoDBcuc2cZ4I1rlQHsZMkj7NKzmIgCv/RT1QR1uNxH+WIzQ= X-Gm-Gg: ASbGncudna5USpZ1KsnYsuIAeqPeqr6z8D5w0m0bCvZ5g3VPPY00dJjFw1x83wlrmaO ipBfpvLjsih998ryzD25V5XkDB8dfB5NPQx/s2tTgYthjMyBV05vSYLeVJnjD3GxpnFA2dv79dh bHaj/C+KT0DtLxAP1ZDoUgPmnu+sCDUUsxyVz+D593h24l+Vit/BemYMzkBLEO93bbLaBTgEKns NkGZK/XXPqqd5VWM64885dFqi/EvO+wvzG1kitmniK4ewDnKdLQ9HXYcjiYOE3yGeBwiAE7Wgh+ WwA5Yd6G4R08uVISHSitrEdz5uYyKheECfFQh5OM/mrGVT1G4oGt+6Ddc7C93KBxVELrl2ug5qk BX7BSx+XOJLiV/emq9Reoig== X-Google-Smtp-Source: AGHT+IHB9V2Vzu7afu7FqCHdjS/MfXtdEF5v+MV/DVnXUBFRlomNYDMZrcS7AKccHT6yeSWFB275eg== X-Received: by 2002:a05:6a20:ce43:b0:1f5:889c:3cbd with SMTP id adf61e73a8af0-2312050277emr89472637.35.1752165694709; Thu, 10 Jul 2025 09:41:34 -0700 (PDT) From: Gustavo Romero To: qemu-arm@nongnu.org, richard.henderson@linaro.org, alex.bennee@linaro.org Cc: qemu-devel@nongnu.org, gustavo.romero@linaro.org Subject: [PATCH v5 1/6] target/arm: Add the MECEn SCR_EL3 bit Date: Thu, 10 Jul 2025 16:38:54 +0000 Message-Id: <20250710163858.1094780-2-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710163858.1094780-1-gustavo.romero@linaro.org> References: <20250710163858.1094780-1-gustavo.romero@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::531; envelope-from=gustavo.romero@linaro.org; helo=mail-pg1-x531.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=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 @linaro.org) X-ZM-MESSAGEID: 1752166775293116600 Content-Type: text/plain; charset="utf-8" The MECEn bit in SCR_EL3 enables access to the EL2 MECID registers from EL2, so add it to the SCR mask list to use it later on. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- target/arm/cpu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index c8cf0ab417..0f64c7b163 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1717,6 +1717,7 @@ static inline void xpsr_write(CPUARMState *env, uint3= 2_t val, uint32_t mask) #define SCR_TRNDR (1ULL << 40) #define SCR_ENTP2 (1ULL << 41) #define SCR_GPF (1ULL << 48) +#define SCR_MECEN (1ULL << 49) #define SCR_NSE (1ULL << 62) =20 /* Return the current FPSCR value. */ --=20 2.34.1 From nobody Thu Dec 18 21:08:44 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=1752167011; cv=none; d=zohomail.com; s=zohoarc; b=GxRcdpieQuiTno14JyY8BOxMcdkse3qSvAFzxx407rMYo1aQpwGVN7WBGAFL+SrBH+txDm0ZPAoLvJ6ysIvt8sRtKeCQn2kf1J2Z5Vl1+194nuMKKq8bi71uyg5GcKHmuype8hYtRyBwutneNsGqh7n9kEXQswE4BFG7R+MYEtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752167011; 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=ZeG1zg84q+9XSbqQeM5w+nO7GmXG52C215che07ehKE=; b=BFwb13bzJQylhGO6Jtalbs56O/s04lYaJ+5WXl6rpPmjyQ+DcsmkKvEGckBLniFyz5rpL8MJUjQnksqaS2r5UjAwv/zEv7ybzkTED2dwrgHG7ezvPCCAdo86tAI0bTSbuvgCGR40ZyhjUnB2QB068D+C1AUKJ99zYWkye87DMi8= 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 1752167011712203.26295230526364; Thu, 10 Jul 2025 10:03:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uZufh-0005BQ-Hv; Thu, 10 Jul 2025 13:02:58 -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 1uZuL6-0003fs-Al for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:40 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uZuL4-00018f-Ch for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:40 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-748feca4a61so847760b3a.3 for ; Thu, 10 Jul 2025 09:41:37 -0700 (PDT) Received: from gromero0.. (189-47-46-41.dsl.telesp.net.br. [189.47.46.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f5c7f7sm2919119b3a.142.2025.07.10.09.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 09:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752165697; x=1752770497; 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=ZeG1zg84q+9XSbqQeM5w+nO7GmXG52C215che07ehKE=; b=UHDq2+mhxMGmVDLplaPSgAy/kzKC8PQ0ZdozZ9zONOQ6xfTD8BCL0Y519GxVPd0YLL sBByxFFg66b3IG7l+wMIj+DW5wFbgtPRC2CMGH5oIBFhppLxSXSrufZNTHysqfd6luXN iHnqhORdVryID2Q3DPITv+ahphCyY5fvcFU2WvtGE9yYERZb4fx3uuC9KoTemM9UCQrh GX4mRQ+LqaxbUgb4lhA2PsFfPbluJ+rF0FxVIvdbswr2A6KfwXZy0PCbVDV//xqte+mA 8zO+zxivm8lytb2Bbirr4qmK5xuKCwLbU+Ep08+rWxSrbA6kImvMIW88ZxCMg0B/vlqu cWcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752165697; x=1752770497; 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=ZeG1zg84q+9XSbqQeM5w+nO7GmXG52C215che07ehKE=; b=Zz18QwQuobAId6K4qqhCw1AhEANHkfil/MwEDA0cgs2YvndBCBCpeqWolZt/m7PN+R 34ad3UWnOaZt5A1JrOraEvHXU5HMcVo2CwmZ+rqZv2mhlR+8LO0L04RtB4EnQ9TiWIwS SV3A8OX6HdMV8+wmR5DavagTUJsi8IkMzlRYm+U4rRuFmqTMVVMSg24hofBSGxGQgz8h /mTkA5PqN8kSvtOR9WCGX42jKPgygYId+YzqvsqdpKscS4fGzvazhX9snkz11YyWajWE qirYsfCkHW+zSHUIxMAfLcv0FpTyJFmjHT4XCpNyHI2NHKZ1enXWW/mH097EihCd9LtY DPQA== X-Gm-Message-State: AOJu0Yyp20VclHzAdiH0UEt3Cjko1EXvNiixnd/d79gS5oSf92kBfXcs 7MQ70uzkCGZV1OP11b6fcPmWOBaxhBAyFAWnDDywX/eJNYtlEbdCGzG2FPagZeT3ghb6QLh/oQ0 QuK+tLJM= X-Gm-Gg: ASbGnctXRZkuvXGLOM139EWQEB5NNiqyqLM1SsXQtbvRKx22uKjnTCGIpfo3lFU6n5O oy7RQulZxJVk3DFa32LNy0qWmeyW9m9dqXGcsODbFijdF9p7LqMsIvLWwyIROkQVjpfJfzxT0He ZY7g2pa4fzAo5E3qp3lxYPmVsghNbxda25vqDA+MmGebdpJMi6iwm3lKpwDNznGZgP4+R0GpMA2 ycImEve+maXZwGrnbqTivU2+8ql68yGmW0L5yDFVBQI/cdQmJEwxzNKvePx9MhF2yFGe3Qt0awI CEwvFFqdKaU7wQn8OAyVqHNatndAFUASFhoPDVgbo0cgBAqpyNNGXjQZ2I+cTMb9RgQf+NKTyGQ To69oPd0pE51/vbQrBycWrQ== X-Google-Smtp-Source: AGHT+IH1oNED/ExH4aYYmqdEJ81dnY/8WeM810V+dPwsrLgD19oGNQPY1eW8IYzNULScAEVGwCmkKw== X-Received: by 2002:aa7:8888:0:b0:74c:efae:ffae with SMTP id d2e1a72fcca58-74eb8e8adc5mr4570316b3a.5.1752165696861; Thu, 10 Jul 2025 09:41:36 -0700 (PDT) From: Gustavo Romero To: qemu-arm@nongnu.org, richard.henderson@linaro.org, alex.bennee@linaro.org Cc: qemu-devel@nongnu.org, gustavo.romero@linaro.org Subject: [PATCH v5 2/6] target/arm: Add FEAT_MEC registers Date: Thu, 10 Jul 2025 16:38:55 +0000 Message-Id: <20250710163858.1094780-3-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710163858.1094780-1-gustavo.romero@linaro.org> References: <20250710163858.1094780-1-gustavo.romero@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::431; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x431.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=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 @linaro.org) X-ZM-MESSAGEID: 1752167013917116600 Content-Type: text/plain; charset="utf-8" Add all FEAT_MEC registers. To work properly, FEAT_MEC also depends on FEAT_SCTLR2 and FEAT_TCR2, which are not implemented in this commit. The bits in SCTLR2 and TCR2 control which translation regimes use MECIDs, and determine which MECID is selected and will be implemented in subsequent commits. FEAT_MEC also requires two new cache management instructions, not included in this commit, that will be implemented in a subsequent commit. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- target/arm/cpu-features.h | 5 +++ target/arm/cpu.h | 9 +++++ target/arm/helper.c | 70 +++++++++++++++++++++++++++++++++++++++ target/arm/internals.h | 3 ++ 4 files changed, 87 insertions(+) diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h index 5876162428..72b6fd9b27 100644 --- a/target/arm/cpu-features.h +++ b/target/arm/cpu-features.h @@ -904,6 +904,11 @@ static inline bool isar_feature_aa64_nv2(const ARMISAR= egisters *id) return FIELD_EX64_IDREG(id, ID_AA64MMFR2, NV) >=3D 2; } =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 0f64c7b163..40ca093331 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -576,6 +576,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 { diff --git a/target/arm/helper.c b/target/arm/helper.c index b3f0d6f17a..984406c945 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6827,6 +6827,72 @@ 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 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) }, +}; + static void define_pmu_regs(ARMCPU *cpu) { /* @@ -9014,6 +9080,10 @@ void register_cp_regs_for_features(ARMCPU *cpu) define_arm_cp_regs(cpu, nmi_reginfo); } =20 + if (cpu_isar_feature(aa64_mec, cpu)) { + define_arm_cp_regs(cpu, mec_reginfo); + } + if (cpu_isar_feature(any_predinv, cpu)) { define_arm_cp_regs(cpu, predinv_reginfo); } diff --git a/target/arm/internals.h b/target/arm/internals.h index 21a8d67edd..77ba2a2273 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1982,4 +1982,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); =20 +/* Used in FEAT_MEC to set the MECIDWidthm1 field in the MECIDR_EL2 regist= er. */ +#define MECID_WIDTH 16 + #endif --=20 2.34.1 From nobody Thu Dec 18 21:08:44 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=1752166774; cv=none; d=zohomail.com; s=zohoarc; b=iipGn7cOxyWt1NHFoOUZU25Z7fVifpOP/6n6el8Gpz6i4/PamLWbrsS0peva/bLDaKMlY76W3fPvhMGvVSeolEBlZKMsP8f1WgoiPnc+zbEYtJfeUWp+e1oRBHz/pQT21hfyku8m2T7vQTOkEntNnbVHUTLtpcCRWocouLsSi5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752166774; 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=FS5xA6GOc2Mt9sYqT6zR9mXdzFYKOmV3kMN80l8IgKM=; b=RwIDh2uyQZ43cj+uFqTyi7Dl2A8lafQ0C4Htsf0aRjrPsAzhHzkImkwp4kjmzRx1OFWQGw1ZiaSRxxK7d1+Jnw4ltdU+BLes+YXZqzkGubKOiGYQqPoUm+H9wUWlMJoVspC8DwELHY++vTOx/VICQCfTOLGF8O7Dovma0R66m1o= 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 1752166774272314.9667646078616; Thu, 10 Jul 2025 09:59:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uZub4-0007XF-Ge; Thu, 10 Jul 2025 12:58: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 1uZuL9-0003vK-4O for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:44 -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 1uZuL6-00019M-T3 for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:42 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-74b56b1d301so800079b3a.1 for ; Thu, 10 Jul 2025 09:41:40 -0700 (PDT) Received: from gromero0.. (189-47-46-41.dsl.telesp.net.br. [189.47.46.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f5c7f7sm2919119b3a.142.2025.07.10.09.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 09:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752165699; x=1752770499; 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=FS5xA6GOc2Mt9sYqT6zR9mXdzFYKOmV3kMN80l8IgKM=; b=s8kEZrMQyMua+nbs2Rh8xK2xPHgeO3EnD1/SF+FVoEMp+eGoOiA5BPhphJbJ58cFi6 fhftWCE1kYZaRaN5j+3czWBvIf+YAKiP4/zaREkyHIcHc1yPDhiA7n0qJ7RVFkrmV7M7 51TKedG34Mtgm+7MZV78FVCkQwZcxmOQpABR8W55Z8wtVqPz00G6dXxNeY5Yx+hbyani 91pb5BOVzpXj2bFR+Yop8DMw0jS3yiubcK8KlWUa7OFtGj4KRmvlMQCYYIP4+2sOOv1f 6FeW/L7ri/HRdFkqgSwd1kljsTc/wZI642kruu6smpM4LWTMle8y9wCRaGO0lzXHNxt3 Ykkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752165699; x=1752770499; 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=FS5xA6GOc2Mt9sYqT6zR9mXdzFYKOmV3kMN80l8IgKM=; b=XRSOju7vknsU2TdnWxMhzP+j9idpJrKxkYPGRXAM9QXDNCkvHmMv1HY8ZS+k60HwDI IQ2S4zfMvY3+wqdmVMnMctCP8k2k8H4OvvYhnVZ2UBoQ1lYr+IhXlNmgRiVhU1TpOHVv fYcpipi2PxJTikKhyINvHPFMPR5WAO+y9wtQ/dXGzX51EFMuuNFsr29FB9ctqvS0Uyli 18AbteQ6HHj0iUWbpI8GLY/DLFKUxTPWP2BuHc89qDI6YsnGQX2fcY1PzJJD4XHSk/iF K7WA3WOR1oXTV3DJQx8Ry3rSt51GATEnj4Zoyu1lS++sMkKrWJXptibDC/vYJHx0hvoT 5B9A== X-Gm-Message-State: AOJu0YzrwuRyUF2VGwyfeXWJdBJGfufi2N1mQ033OIEDNVoDNI/hK5qH MoS+kz5VJbalbeOiirUPbY7cpGU2b3DGTO/ZzAOwNo5kqw6cg0OxAqTN1GzYR9mGg0o= X-Gm-Gg: ASbGnctuOe9drjtoulaGgtUNqt1pfoNeVMXb3Dduodr78/g6ernOjt3NQzLIgxo1KLZ KXuMXnOy8iOpOnR3z0pJF3tA19zRwBS4AjFnqEPj7fef2UiKqvvsq9ybffjDi5i0Dhw8grKKlk1 iYCjQfyB09C+UKz1zgL1e+LO457i2cwDQAfXGLmyZp0yG5mdzkGay6J034qxAyZ99/P63SuCw2F GH6ya0u/IPfhOQGtGhjJk0FMECc8R+OQPKlprF10RLej+iH0YCSUb5QMQu8wtSid3fDVyATyOA1 vhoHpnUy1Pc7YYLLl+hub8xIjbG0ndqOiT/GVY46GrmgX6XxROLUSkNpVIamLOWgQyxp7WLfWJw VQB1HspLMaB/h3xCSeVhQYeJ/frxQLozA X-Google-Smtp-Source: AGHT+IG9hd28Qk2FKfz9fuFpLyvK5eIum7E22ZmTwwdApiQ7I4pUjoAw5b6XsTe3B/tT76j1gZlo2w== X-Received: by 2002:aa7:88c6:0:b0:732:2923:b70f with SMTP id d2e1a72fcca58-74eb8f7c139mr4584567b3a.11.1752165699076; Thu, 10 Jul 2025 09:41:39 -0700 (PDT) From: Gustavo Romero To: qemu-arm@nongnu.org, richard.henderson@linaro.org, alex.bennee@linaro.org Cc: qemu-devel@nongnu.org, gustavo.romero@linaro.org Subject: [PATCH v5 3/6] target/arm: Add FEAT_SCTLR2 Date: Thu, 10 Jul 2025 16:38:56 +0000 Message-Id: <20250710163858.1094780-4-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710163858.1094780-1-gustavo.romero@linaro.org> References: <20250710163858.1094780-1-gustavo.romero@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::432; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x432.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=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 @linaro.org) X-ZM-MESSAGEID: 1752166775520116600 Content-Type: text/plain; charset="utf-8" Add FEAT_SCTLR2, which introduces the SCTLR2_EL1, SCTLR2_EL2, and SCTLR2_EL3 registers. These registers are extensions of the SCTLR_ELx ones. Because the bits in these registers depend on other CPU features, and only FEAT_MEC is supported at the moment, this commit only implements the EMEC bits in CTLR2_EL2 and SCTLR2_EL3. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- docs/system/arm/emulation.rst | 1 + target/arm/cpu-features.h | 5 +++ target/arm/cpu.h | 15 +++++++ target/arm/helper.c | 78 +++++++++++++++++++++++++++++++++++ target/arm/internals.h | 1 + target/arm/tcg/cpu64.c | 5 ++- 6 files changed, 104 insertions(+), 1 deletion(-) diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index 890dc6fee2..66043b0747 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -121,6 +121,7 @@ the following architecture extensions: - FEAT_RPRES (Increased precision of FRECPE and FRSQRTE) - FEAT_S2FWB (Stage 2 forced Write-Back) - FEAT_SB (Speculation Barrier) +- FEAT_SCTLR2 (Extension to SCTLR_ELx) - FEAT_SEL2 (Secure EL2) - FEAT_SHA1 (SHA1 instructions) - FEAT_SHA256 (SHA256 instructions) diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h index 72b6fd9b27..a5fc2ca572 100644 --- a/target/arm/cpu-features.h +++ b/target/arm/cpu-features.h @@ -904,6 +904,11 @@ static inline bool isar_feature_aa64_nv2(const ARMISAR= egisters *id) return FIELD_EX64_IDREG(id, ID_AA64MMFR2, NV) >=3D 2; } =20 +static inline bool isar_feature_aa64_sctlr2(const ARMISARegisters *id) +{ + return FIELD_EX64_IDREG(id, ID_AA64MMFR3, SCTLRX) !=3D 0; +} + static inline bool isar_feature_aa64_mec(const ARMISARegisters *id) { return FIELD_EX64_IDREG(id, ID_AA64MMFR3, MEC) !=3D 0; diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 40ca093331..894e2a2997 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -337,6 +337,7 @@ typedef struct CPUArchState { }; uint64_t sctlr_el[4]; }; + uint64_t sctlr2_el[4]; /* Extension to System control register. */ uint64_t vsctlr; /* Virtualization System control register. */ uint64_t cpacr_el1; /* Architectural feature access control regist= er */ uint64_t cptr_el[4]; /* ARMv8 feature trap registers */ @@ -1433,6 +1434,19 @@ void pmu_init(ARMCPU *cpu); #define SCTLR_SPINTMASK (1ULL << 62) /* FEAT_NMI */ #define SCTLR_TIDCP (1ULL << 63) /* FEAT_TIDCP1 */ =20 +#define SCTLR2_EMEC (1ULL << 1) /* FEAT_MEC */ +#define SCTLR2_NMEA (1ULL << 2) /* FEAT_DoubleFault2 */ +#define SCTLR2_ENADERR (1ULL << 3) /* FEAT_ADERR */ +#define SCTLR2_ENANERR (1ULL << 4) /* FEAT_ANERR */ +#define SCTLR2_EASE (1ULL << 5) /* FEAT_DoubleFault2 */ +#define SCTLR2_ENIDCP128 (1ULL << 6) /* FEAT_SYSREG128 */ +#define SCTLR2_ENPACM (1ULL << 7) /* FEAT_PAuth_LR */ +#define SCTLR2_ENPACM0 (1ULL << 8 /* FEAT_PAuth_LR */ +#define SCTLR2_CPTA (1ULL << 9) /* FEAT_CPA2 */ +#define SCTLR2_CPTA0 (1ULL << 10) /* FEAT_CPA2 */ +#define SCTLR2_CPTM (1ULL << 11) /* FEAT_CPA2 */ +#define SCTLR2_CPTM0 (1ULL << 12) /* FEAT_CAP2 */ + #define CPSR_M (0x1fU) #define CPSR_T (1U << 5) #define CPSR_F (1U << 6) @@ -1725,6 +1739,7 @@ static inline void xpsr_write(CPUARMState *env, uint3= 2_t val, uint32_t mask) #define SCR_HXEN (1ULL << 38) #define SCR_TRNDR (1ULL << 40) #define SCR_ENTP2 (1ULL << 41) +#define SCR_SCTLR2EN (1ULL << 44) #define SCR_GPF (1ULL << 48) #define SCR_MECEN (1ULL << 49) #define SCR_NSE (1ULL << 62) diff --git a/target/arm/helper.c b/target/arm/helper.c index 984406c945..963d3e064b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6144,6 +6144,8 @@ static void define_arm_vh_e2h_redirects_aliases(ARMCP= U *cpu) static const struct E2HAlias aliases[] =3D { { K(3, 0, 1, 0, 0), K(3, 4, 1, 0, 0), K(3, 5, 1, 0, 0), "SCTLR", "SCTLR_EL2", "SCTLR_EL12" }, + { K(3, 0, 1, 0, 3), K(3, 4, 1, 0, 3), K(3, 5, 1, 0, 3), + "SCTLR2_EL1", "SCTLR2_EL2", "SCTLR2_EL12" }, { K(3, 0, 1, 0, 2), K(3, 4, 1, 1, 2), K(3, 5, 1, 0, 2), "CPACR", "CPTR_EL2", "CPACR_EL12" }, { K(3, 0, 2, 0, 0), K(3, 4, 2, 0, 0), K(3, 5, 2, 0, 0), @@ -7816,6 +7818,78 @@ static const ARMCPRegInfo actlr2_hactlr2_reginfo[] = =3D { .resetvalue =3D 0 }, }; =20 +static CPAccessResult sctlr2_el2_access(CPUARMState *env, + const ARMCPRegInfo *ri, + bool isread) +{ + if (arm_current_el(env) < 3 && !(env->cp15.scr_el3 & SCR_SCTLR2EN)) { + return CP_ACCESS_TRAP_EL3; + } + return CP_ACCESS_OK; +} + +static CPAccessResult sctlr2_el1_access(CPUARMState *env, + const ARMCPRegInfo *ri, + bool isread) +{ + CPAccessResult ret =3D access_tvm_trvm(env, ri, isread); + if (ret !=3D CP_ACCESS_OK) { + return ret; + } + if (arm_current_el(env) < 2 && !(arm_hcrx_el2_eff(env) & HCRX_SCTLR2EN= )) { + return CP_ACCESS_TRAP_EL2; + } + return sctlr2_el2_access(env, ri, isread); +} + +static void sctlr2_el1_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + /* This register does not control any feature yet. */ +} + +static void sctlr2_el2_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + uint64_t valid_mask =3D 0; + + if (cpu_isar_feature(aa64_mec, env_archcpu(env))) { + valid_mask |=3D SCTLR2_EMEC; + } + value &=3D valid_mask; + raw_write(env, ri, value); +} + +static void sctlr2_el3_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + uint64_t valid_mask =3D 0; + + if (cpu_isar_feature(aa64_mec, env_archcpu(env))) { + valid_mask |=3D SCTLR2_EMEC; + } + value &=3D valid_mask; + raw_write(env, ri, value); +} + +static const ARMCPRegInfo sctlr2_reginfo[] =3D { + { .name =3D "SCTLR2_EL1", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 0, .opc2 =3D 3, .crn =3D 1, .crm =3D 0, + .access =3D PL1_RW, .accessfn =3D sctlr2_el1_access, + .writefn =3D sctlr2_el1_write, .fgt =3D FGT_SCTLR_EL1, + .nv2_redirect_offset =3D 0x278 | NV2_REDIR_NV1, + .fieldoffset =3D offsetof(CPUARMState, cp15.sctlr2_el[1]) }, + { .name =3D "SCTLR2_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 3, .crn =3D 1, .crm =3D 0, + .access =3D PL2_RW, .accessfn =3D sctlr2_el2_access, + .writefn =3D sctlr2_el2_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.sctlr2_el[2]) }, + { .name =3D "SCTLR2_EL3", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 6, .opc2 =3D 3, .crn =3D 1, .crm =3D 0, + .access =3D PL3_RW, .writefn =3D sctlr2_el3_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.sctlr2_el[3]) }, +}; + void register_cp_regs_for_features(ARMCPU *cpu) { /* Register all the coprocessor registers based on feature bits */ @@ -9084,6 +9158,10 @@ void register_cp_regs_for_features(ARMCPU *cpu) define_arm_cp_regs(cpu, mec_reginfo); } =20 + if (cpu_isar_feature(aa64_sctlr2, cpu)) { + define_arm_cp_regs(cpu, sctlr2_reginfo); + } + if (cpu_isar_feature(any_predinv, cpu)) { define_arm_cp_regs(cpu, predinv_reginfo); } diff --git a/target/arm/internals.h b/target/arm/internals.h index 77ba2a2273..d18d0fb19a 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -232,6 +232,7 @@ FIELD(VTCR, SL2, 33, 1) #define HCRX_CMOW (1ULL << 9) #define HCRX_MCE2 (1ULL << 10) #define HCRX_MSCEN (1ULL << 11) +#define HCRX_SCTLR2EN (1ULL << 15) =20 #define HPFAR_NS (1ULL << 63) =20 diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index d0df50a2f3..30505fb293 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -1247,7 +1247,10 @@ void aarch64_max_tcg_initfn(Object *obj) t =3D FIELD_DP64(t, ID_AA64MMFR2, E0PD, 1); /* FEAT_E0PD */ SET_IDREG(isar, ID_AA64MMFR2, t); =20 - FIELD_DP64_IDREG(isar, ID_AA64MMFR3, SPEC_FPACC, 1); /* FEAT_FPACC_SPE= C */ + t =3D GET_IDREG(isar, ID_AA64MMFR3); + t =3D FIELD_DP64(t, ID_AA64MMFR3, SCTLRX, 1); /* FEAT_SCTLR2 */ + t =3D FIELD_DP64(t, ID_AA64MMFR3, SPEC_FPACC, 1); /* FEAT_FPACC_SPEC */ + SET_IDREG(isar, ID_AA64MMFR3, t); =20 t =3D GET_IDREG(isar, ID_AA64ZFR0); t =3D FIELD_DP64(t, ID_AA64ZFR0, SVEVER, 2); /* FEAT_SVE2p1 */ --=20 2.34.1 From nobody Thu Dec 18 21:08:44 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=1752167064; cv=none; d=zohomail.com; s=zohoarc; b=UiiEo+okCddjIkcQg9YSew1bQz44mEW7zlZNH8wGZrRuvXka8w3qf8VQ5Lfl+DCK0v3Z2hZ5SijeB5oqGzwvS9Ky4vHLWdP/94Hc6mB7j0BP7EnKhF+T2ydGCwu91psQlgMNH9/XADF2FlqSWglPRxPU1/XJtIPaXc1KTva0x9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752167064; 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=nVKucjOtP/Y4LoplarwkY4lSnfGgVt/kUo3oBzJMzZg=; b=bOBQrc5yE/QguSF+7Mn5Jq1ug2HLl80WAG/6Zb9O+SRxxj+36LCqk5HO2NqA9/oDcboDctKk0UAv9InlRxU4RGoAr9qShkEZ96kS/mxCC9xv6OU1I+dFDl9ihALp19TSbhpy6JYO0dlc6nONnM+rKA+It3BaG+wn8EDT2vfFztQ= 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 1752167064888614.5518460350726; Thu, 10 Jul 2025 10:04:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uZugj-0005c3-0D; Thu, 10 Jul 2025 13:04: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 1uZuLA-00040w-R0 for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:44 -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 1uZuL8-00019n-J9 for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:44 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-74264d1832eso1704561b3a.0 for ; Thu, 10 Jul 2025 09:41:42 -0700 (PDT) Received: from gromero0.. (189-47-46-41.dsl.telesp.net.br. [189.47.46.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f5c7f7sm2919119b3a.142.2025.07.10.09.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 09:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752165701; x=1752770501; 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=nVKucjOtP/Y4LoplarwkY4lSnfGgVt/kUo3oBzJMzZg=; b=J8zggZyCQlqzhf4C0i3i3SlI8i3BHuJwTZBxsZ/Q2GDc616ZdnnK2sol6SpW6VXSpf YTI96ZlUcpsV6OopMlqVqVZXYS2K56vNxvI5sGIiReI6/deDy//66bvlZ7SkwjPn33uY rT/G9FfDS4W34ZimJLNJ7p+Utd9CZQQt5mBHDfAkTtYc8kj3yMD74OKpY2KDyvnDHktS IQe9aqsHkjvxKUiYV6nMXdfR3KRtxniGxF+R/EN7/Dpb8KANfpCNryeu4YmZvU/KuaaY zT68Z4JAp0JiUbIy6RMUdy9jPOizs7FcAqHanB+Wr8Tgmx7KCNhRi1AfNp4DM0o3EgY6 10Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752165701; x=1752770501; 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=nVKucjOtP/Y4LoplarwkY4lSnfGgVt/kUo3oBzJMzZg=; b=YaS0Px4ffMn5des8RGMlr5d9HC6Le6Hj5zZG5M3jO/LqxyWsCOScG3sKBHq7gBDpMH /bRgZDIA7MlHr+6z/k/PUXx8aMt6j1KKsAtxgOrO8tC6k1U1a9MPlVweikOVyYKNV5dM a00vmVz2DFTtmEqBHzT9twYhUnOxME1XNw2SjkE7WDs7d8SdtpVyAOPXGHDm7QAa/lUh 4Tgp2bq0bAOxy0PRM6024CVzKC0GuTFD23/zotWejDeWbLSSqE0KjB33F+06wONa4UPu kSjXJ/Xj8kqeQwS5eCbvY035+rFshyDjK8zxHtbgprZiPDZlak3l3DUMV4Oiz2nGhD1F ZRZg== X-Gm-Message-State: AOJu0YwNOBVrJXNLVXeKvcyTY3oo712HhNdibd+nH/bm0D7/Mf0uCu+7 mfbAsD2q7OLBlxqXTkTfiKxaJhL5dChSLkrdPXGFP+yutXlm2IqyRSvBpV7ZUvhbZkcJlD3zr3r 9DKMo1ig= X-Gm-Gg: ASbGncvlGkU1omPZCWa+BB8US+/ILQ1NLkWKCvdk3wMww3FTSb65/8YYyO8P58G7h3a Wf0inZYda1uie8usidjAw/B8XrfO+tMYX2RUbgvHjKLSx3XGCoLkXAj7tEcxVLYj+AhsFORa1eQ taMjPRdRJCavljhxVMWdD5miIhh9HO/Aec2GX/uiljRdZjgpNkWMXtRbjVQxHdq0hLaazyuW+Bu C+IJ/iSCrHEx9ssZAMLKjn2xegUKbVTl6CYP/6mcV/AP3PMBUskVI1Za48z9EoBP+sq1KnsL7rc LHcVmpNVGPi4OtO9tCPNXdQFthm/nZHS+uSC3cymeqT3g8f/EeWXqQgw+nbSqOcNXP7bC9JBvBF fCgCcPsbYXmmbdD59u8gmVQ== X-Google-Smtp-Source: AGHT+IED4jj5vBYcJnIeNZe/BONl5cj1Y76CJ+Acg5cy1Z0OBuxh4yfGhf/DRV8KCK19o25BRRf+Qg== X-Received: by 2002:a05:6a20:a108:b0:225:c286:5907 with SMTP id adf61e73a8af0-2311d952742mr141432637.3.1752165701092; Thu, 10 Jul 2025 09:41:41 -0700 (PDT) From: Gustavo Romero To: qemu-arm@nongnu.org, richard.henderson@linaro.org, alex.bennee@linaro.org Cc: qemu-devel@nongnu.org, gustavo.romero@linaro.org Subject: [PATCH v5 4/6] target/arm: Add FEAT_TCR2 Date: Thu, 10 Jul 2025 16:38:57 +0000 Message-Id: <20250710163858.1094780-5-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710163858.1094780-1-gustavo.romero@linaro.org> References: <20250710163858.1094780-1-gustavo.romero@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::42e; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42e.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=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 @linaro.org) X-ZM-MESSAGEID: 1752167066899116600 Content-Type: text/plain; charset="utf-8" Add FEAT_TCR2, which introduces the TCR2_EL1 and TCR2_EL2 registers. These registers are extensions of the TCR_ELx registers and provide top-level control of the EL10 and EL20 translation regimes. Since the bits in these registers depend on other CPU features, and only FEAT_MEC is supported at the moment, the FEAT_TCR2 only implements the AMEC bits for now. Signed-off-by: Gustavo Romero --- docs/system/arm/emulation.rst | 1 + target/arm/cpu-features.h | 5 +++ target/arm/cpu.h | 2 ++ target/arm/helper.c | 60 +++++++++++++++++++++++++++++++++++ target/arm/internals.h | 19 +++++++++++ target/arm/tcg/cpu64.c | 1 + 6 files changed, 88 insertions(+) diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index 66043b0747..1c597d8673 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -149,6 +149,7 @@ the following architecture extensions: - FEAT_SPECRES (Speculation restriction instructions) - FEAT_SSBS (Speculative Store Bypass Safe) - FEAT_SSBS2 (MRS and MSR instructions for SSBS version 2) +- FEAT_TCR2 (Support for TCR2_ELx) - FEAT_TGran16K (Support for 16KB memory translation granule size at stage= 1) - FEAT_TGran4K (Support for 4KB memory translation granule size at stage 1) - FEAT_TGran64K (Support for 64KB memory translation granule size at stage= 1) diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h index a5fc2ca572..9579d93cec 100644 --- a/target/arm/cpu-features.h +++ b/target/arm/cpu-features.h @@ -904,6 +904,11 @@ static inline bool isar_feature_aa64_nv2(const ARMISAR= egisters *id) return FIELD_EX64_IDREG(id, ID_AA64MMFR2, NV) >=3D 2; } =20 +static inline bool isar_feature_aa64_tcr2(const ARMISARegisters *id) +{ + return FIELD_EX64_IDREG(id, ID_AA64MMFR3, TCRX) !=3D 0; +} + static inline bool isar_feature_aa64_sctlr2(const ARMISARegisters *id) { return FIELD_EX64_IDREG(id, ID_AA64MMFR3, SCTLRX) !=3D 0; diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 894e2a2997..9f900ee4f6 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -366,6 +366,7 @@ typedef struct CPUArchState { uint64_t vsttbr_el2; /* Secure Virtualization Translation Table. */ /* MMU translation table base control. */ uint64_t tcr_el[4]; + uint64_t tcr2_el[3]; uint64_t vtcr_el2; /* Virtualization Translation Control. */ uint64_t vstcr_el2; /* Secure Virtualization Translation Control. = */ uint32_t c2_data; /* MPU data cacheable bits. */ @@ -1739,6 +1740,7 @@ static inline void xpsr_write(CPUARMState *env, uint3= 2_t val, uint32_t mask) #define SCR_HXEN (1ULL << 38) #define SCR_TRNDR (1ULL << 40) #define SCR_ENTP2 (1ULL << 41) +#define SCR_TCR2EN (1ULL << 43) #define SCR_SCTLR2EN (1ULL << 44) #define SCR_GPF (1ULL << 48) #define SCR_MECEN (1ULL << 49) diff --git a/target/arm/helper.c b/target/arm/helper.c index 963d3e064b..6f678aceeb 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6154,6 +6154,8 @@ static void define_arm_vh_e2h_redirects_aliases(ARMCP= U *cpu) "TTBR1_EL1", "TTBR1_EL2", "TTBR1_EL12" }, { K(3, 0, 2, 0, 2), K(3, 4, 2, 0, 2), K(3, 5, 2, 0, 2), "TCR_EL1", "TCR_EL2", "TCR_EL12" }, + { K(3, 0, 2, 0, 3), K(3, 4, 2, 0, 3), K(3, 5, 2, 0, 3), + "TCR2_EL1", "TCR2_EL2", "TCR2_EL12" }, { K(3, 0, 4, 0, 0), K(3, 4, 4, 0, 0), K(3, 5, 4, 0, 0), "SPSR_EL1", "SPSR_EL2", "SPSR_EL12" }, { K(3, 0, 4, 0, 1), K(3, 4, 4, 0, 1), K(3, 5, 4, 0, 1), @@ -7890,6 +7892,60 @@ static const ARMCPRegInfo sctlr2_reginfo[] =3D { .fieldoffset =3D offsetof(CPUARMState, cp15.sctlr2_el[3]) }, }; =20 +static CPAccessResult tcr2_el2_access(CPUARMState *env, const ARMCPRegInfo= *ri, + bool isread) +{ + if (arm_current_el(env) < 3 && !(env->cp15.scr_el3 & SCR_TCR2EN)) { + return CP_ACCESS_TRAP_EL3; + } + return CP_ACCESS_OK; +}; + +static CPAccessResult tcr2_el1_access(CPUARMState *env, const ARMCPRegInfo= *ri, + bool isread) +{ + CPAccessResult ret =3D access_tvm_trvm(env, ri, isread); + if (ret !=3D CP_ACCESS_OK) { + return ret; + } + if (arm_current_el(env) < 2 && !(arm_hcrx_el2_eff(env) & HCRX_TCR2EN))= { + return CP_ACCESS_TRAP_EL2; + } + return tcr2_el2_access(env, ri, isread); +} + +static void tcr2_el1_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + /* This register does not control any feature yet. */ +} + +static void tcr2_el2_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + uint64_t valid_mask =3D 0; + + 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); +} + +static const ARMCPRegInfo tcr2_reginfo[] =3D { + { .name =3D "TCR2_EL1", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 0, .opc2 =3D 3, .crn =3D 2, .crm =3D 0, + .access =3D PL1_RW, .accessfn =3D tcr2_el1_access, + .writefn =3D tcr2_el1_write, .fgt =3D FGT_TCR_EL1, + .nv2_redirect_offset =3D 0x270 | NV2_REDIR_NV1, + .fieldoffset =3D offsetof(CPUARMState, cp15.tcr2_el[1]) }, + { .name =3D "TCR2_EL2", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 4, .opc2 =3D 3, .crn =3D 2, .crm =3D 0, + .access =3D PL2_RW, .accessfn =3D tcr2_el2_access, + .writefn =3D tcr2_el2_write, + .fieldoffset =3D offsetof(CPUARMState, cp15.tcr2_el[2]) }, +}; + void register_cp_regs_for_features(ARMCPU *cpu) { /* Register all the coprocessor registers based on feature bits */ @@ -9162,6 +9218,10 @@ void register_cp_regs_for_features(ARMCPU *cpu) define_arm_cp_regs(cpu, sctlr2_reginfo); } =20 + if (cpu_isar_feature(aa64_tcr2, cpu)) { + define_arm_cp_regs(cpu, tcr2_reginfo); + } + if (cpu_isar_feature(any_predinv, cpu)) { define_arm_cp_regs(cpu, predinv_reginfo); } diff --git a/target/arm/internals.h b/target/arm/internals.h index d18d0fb19a..8cb0709abe 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -201,6 +201,24 @@ FIELD(CPTR_EL3, TCPAC, 31, 1) #define TTBCR_SH1 (1U << 28) #define TTBCR_EAE (1U << 31) =20 +#define TCR2_PNCH (1ULL << 0) +#define TCR2_PIE (1ULL << 1) +#define TCR2_E0POE (1ULL << 2) +#define TCR2_POE (1ULL << 3) +#define TCR2_AIE (1ULL << 4) +#define TCR2_D128 (1ULL << 5) +#define TCR2_PTTWI (1ULL << 10) +#define TCR2_HAFT (1ULL << 11) +#define TCR2_AMEC0 (1ULL << 12) +#define TCR2_AMEC1 (1ULL << 13) +#define TCR2_DISCH0 (1ULL << 14) +#define TCR2_DISCH1 (1ULL << 15) +#define TCR2_A2 (1ULL << 16) +#define TCR2_FNG0 (1ULL << 17) +#define TCR2_FNG1 (1ULL << 18) +#define TCR2_FNGNA0 (1ULL << 20) +#define TCR2_FNGNA1 (1ULL << 21) + FIELD(VTCR, T0SZ, 0, 6) FIELD(VTCR, SL0, 6, 2) FIELD(VTCR, IRGN0, 8, 2) @@ -232,6 +250,7 @@ FIELD(VTCR, SL2, 33, 1) #define HCRX_CMOW (1ULL << 9) #define HCRX_MCE2 (1ULL << 10) #define HCRX_MSCEN (1ULL << 11) +#define HCRX_TCR2EN (1ULL << 14) #define HCRX_SCTLR2EN (1ULL << 15) =20 #define HPFAR_NS (1ULL << 63) diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index 30505fb293..ae2046a7f6 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -1248,6 +1248,7 @@ void aarch64_max_tcg_initfn(Object *obj) SET_IDREG(isar, ID_AA64MMFR2, t); =20 t =3D GET_IDREG(isar, ID_AA64MMFR3); + t =3D FIELD_DP64(t, ID_AA64MMFR3, TCRX, 1); /* FEAT_TCR2 */ t =3D FIELD_DP64(t, ID_AA64MMFR3, SCTLRX, 1); /* FEAT_SCTLR2 */ t =3D FIELD_DP64(t, ID_AA64MMFR3, SPEC_FPACC, 1); /* FEAT_FPACC_SPEC */ SET_IDREG(isar, ID_AA64MMFR3, t); --=20 2.34.1 From nobody Thu Dec 18 21:08:44 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=1752167120; cv=none; d=zohomail.com; s=zohoarc; b=MRv4IzPWK3ov2iAzN/0Ml5Gf02DKfUUPxY/8fbbeJk0rxF1muIbMWku1TbdOdj7MZtexoZ+8wY2M1q1Y4drmf5pgKO1Zh4tvZA2h0YrgK535hCb29m9I6SoyOfZDIEyoSO1yjgT5LBUI01j2zeqyjPzyUYHHayGzAxD5gs5YZbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752167120; 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=EtG2f9WC1Atw8TQNXmdprkNhtZEEPjSXEDq2fJcwOt8=; b=D6v3LnqM3EzzdYNk1W9VJ/yioxXVUSAU5KK2CZXnTINmMx/mflQjVNB+Pyy6W8vfmJkJrma1XmqMpF2vMiwVxPFMQ/umisJQDpgbVWeNVwMTUwudVY54OzVPbvLPfmZEwLyxEKIdw+Z/6FipGqQb0vZeCV2cTwM+cd3b7Wzm7DA= 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 1752167120442273.2905909818013; Thu, 10 Jul 2025 10:05:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uZuhe-0006IQ-HO; Thu, 10 Jul 2025 13:05: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 1uZuLC-0004GY-Id for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:46 -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 1uZuLA-0001AI-RU for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:46 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-74ad4533ac5so2033444b3a.0 for ; Thu, 10 Jul 2025 09:41:44 -0700 (PDT) Received: from gromero0.. (189-47-46-41.dsl.telesp.net.br. [189.47.46.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f5c7f7sm2919119b3a.142.2025.07.10.09.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 09:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752165703; x=1752770503; 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=EtG2f9WC1Atw8TQNXmdprkNhtZEEPjSXEDq2fJcwOt8=; b=GwPLV3Q/rZ9Cbu4lb7Yf8vjhid6+I85E60uT1f8q56ih4skErpCn3N9pIs6IaJHt9v HvzUIyZkYvVf+Lwn8hr7oyLQmnmyDimPQY1XyP4XMlteVMls5G9/QDlU6B8H1Ta+Bcsj XJmOf1PBAYpBDmyTvH/LF0O2OU652C3m7kDzIRwGmYhuhYIV4a1aSjxMrSQG1AI91LHI qSw7qxRo30cIpqGiSwHRmkfVe44njHxk+plfscCvJfBd0xqrMqiKVd91chkfaoanz9ln glWDS+afrBk3C+i1RyxsuIMu05u59NwMW7yUoxIN7G/p1Ckuv4XPhP7wzNfp6NVqbY87 KZDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752165703; x=1752770503; 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=EtG2f9WC1Atw8TQNXmdprkNhtZEEPjSXEDq2fJcwOt8=; b=V+ES+i6U6wGUkJ6z75ScUGC3ZQUXLhJUqa4/fnrOE+wHTsh3sWTTcd7CHudDbZuJX9 Ph2Z/aHrom90u+yImdh8cRfVKPWiGXS7Z9JJol9pgKOG7sn4RM4i1WpnzqVuIUr/lKsI oUwyhhMadqkXSOWGkS0NHeTSBbkyvCth+Qt8IJE8C/dqaC9BgT1bCHHjndGFqQB08+8z h53GM9L9nli8N9zQzQLCmUvnicZtQzFNJ7Hdtse4aN6i4CynasynHOtmMucSHBHRdiLz J8mRHh8YVbBrxisInCNSpZqbZIs2V8ErnqnD2/XqJVyNBlqoSI4KVwS2X62JTkEzvNX+ Qxvw== X-Gm-Message-State: AOJu0Yy1jEJBEA3y0Nhhr3sod2x/LuYjA4fN4fc917o2Ctj+7PQus4oP wVbJ+Fe4H1wo80WOUvuv+3/bqzyujK/U0TgyairC+pCfkXVG9nD+K12P07U5hXCfnVGApWRgH6n hgEL1r7E= X-Gm-Gg: ASbGncuJG94v8IyvyGUoe19ZHzNjNSt2qTztt7DlKuXJJi0eiyFwKxkOCiAlruURQvo ncCSViUg9SovaQrP5sfgk1yzF9ZXPPpC+Utldgcv6JOkg0Z62Vju+5Vs5BnsQRxQQCIVKRm3sPa ui+25qLnR37xw+D2+MrhAg2nEhLRGBo7CWsOVeTNoGinA0p0gAYuS6GZ2UMyytWk2hNfkKH4F9q JTDTRUiD24d4uHXcFy04TyvA00bCydTTE/H4TUvFyk9ilH9denit5Arv/m66MaWTiEJvhrkjNqh KbpU/3ns3xN8Wh1tdbO8oGCBGgycvvt2TPgQMbf9zfUd9p4rkcGTuL9BUPyfstPrAy8TPLSAGLG ov/xfJ2lblYPF5NdnA4WADA== X-Google-Smtp-Source: AGHT+IHn1M2Zub3MC32lkJYROXXoTEHubfXaq7lyDHdIYsD9Wee9Wfhu6jFBx47GkXNAiDl+skUzcA== X-Received: by 2002:a05:6a20:430c:b0:215:e02f:1eb8 with SMTP id adf61e73a8af0-22fc38bcf9cmr6743105637.14.1752165703233; Thu, 10 Jul 2025 09:41:43 -0700 (PDT) From: Gustavo Romero To: qemu-arm@nongnu.org, richard.henderson@linaro.org, alex.bennee@linaro.org Cc: qemu-devel@nongnu.org, gustavo.romero@linaro.org Subject: [PATCH v5 5/6] target/arm: Implement FEAT_MEC cache instructions Date: Thu, 10 Jul 2025 16:38:58 +0000 Message-Id: <20250710163858.1094780-6-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710163858.1094780-1-gustavo.romero@linaro.org> References: <20250710163858.1094780-1-gustavo.romero@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::429; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x429.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=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 @linaro.org) X-ZM-MESSAGEID: 1752167121098116600 Content-Type: text/plain; charset="utf-8" This commit implements the two cache maintenance instructions introduced by FEAT_MEC, DC CIPAE and DC CIGDPAE. Because QEMU does not model the cache topology, all cache maintenance instructions are implemented as NOPs, hence these new instructions are implemented as NOPs too. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- target/arm/helper.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/target/arm/helper.c b/target/arm/helper.c index 6f678aceeb..5aab9294bc 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6856,6 +6856,18 @@ static void mecid_write(CPUARMState *env, const ARMC= PRegInfo *ri, raw_write(env, ri, value); } =20 +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, @@ -6895,6 +6907,15 @@ static const ARMCPRegInfo mec_reginfo[] =3D { .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 = }, }; =20 static void define_pmu_regs(ARMCPU *cpu) @@ -9212,6 +9233,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) =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); + } } =20 if (cpu_isar_feature(aa64_sctlr2, cpu)) { --=20 2.34.1 From nobody Thu Dec 18 21:08:44 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=1752167172; cv=none; d=zohomail.com; s=zohoarc; b=H+LLFyQFxcbLKXQF61xg22aqWfV9UwvKDmeUP4t6sUCL/bT8c9mC0LEBPQ+6MTVBdwWx206HqudIrJ82mWv4pdcwTO0e09PRz7U6U4pEVBPYE3602FkOlQhwpEKU09mTrqxfsH7fTDS8e5/FCb2UWN1fScLUfcHiLf40sZ4F7PU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752167172; 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=XxglZr9FSbfBVmHLZ+FvVDfQKN3fWf8b03y6OHhLFac=; b=VXccSCUcb6h0pc1PkSN9771vqg5r/V4jZma7Ftra/nvaHqj3CdS/3eTCzdIaAjM9XR/gOdB26ZckH4cyxq8gAiZ8+9mgPcoO5oJ+ISPfhNuRC5K6JD27VDHKcJ9zW/i/JaUNMtG84CjtwPOyTCNUekOOgHQQebAOiD/mligXkI4= 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 1752167172235855.0532745762226; Thu, 10 Jul 2025 10:06:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uZuiY-0006xX-83; Thu, 10 Jul 2025 13:06:01 -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 1uZuLE-0004Pn-Kz for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:48 -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 1uZuLC-0001As-Tq for qemu-devel@nongnu.org; Thu, 10 Jul 2025 12:41:48 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-748d982e92cso843032b3a.1 for ; Thu, 10 Jul 2025 09:41:46 -0700 (PDT) Received: from gromero0.. (189-47-46-41.dsl.telesp.net.br. [189.47.46.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f5c7f7sm2919119b3a.142.2025.07.10.09.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 09:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752165705; x=1752770505; 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=XxglZr9FSbfBVmHLZ+FvVDfQKN3fWf8b03y6OHhLFac=; b=XbGyl32HuXid/Xp6ibSD/wCDSnax1aJiUgR6GzJhvj5Y27ctxt+u6k7TbGZbcNP1EL CE/jWd2U9f4T5+jB3kIXNHWqmTJKYENq0NouxUdVwwJl+UnIl7gygkHv7AptAlmyE7ud 2DhT1IM32dNG/syDsuWzXX1Jh7Q1R/gqY4xJ9PPmXYSqvBtLQ42pAhgfYSh7LxeMLeYI WDwHxXGXl3NjhURgHrM+hBO5ZTNTQOoGBGmHMsA4wZJY5Tyuc/vgmjCP7a8Bss7/faUc hmdrPPJpnwwMrIi+UgKD5+DwvtcwKbfH5r9faBPLN8FnWJBRXqGoiSvVBbWSxFIxtp1V DuWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752165705; x=1752770505; 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=XxglZr9FSbfBVmHLZ+FvVDfQKN3fWf8b03y6OHhLFac=; b=ClsXJT0X8cXj85nb+8sV+b7EKikT+p3F9o7vRL3QTLKQYi8u3D1yNioqJy4cgKntdP hxlMlEw8Lm6l362mVomK3AcPZNbe834KNl3AfcX0cHQqcZmxcJ78q3avik1/qO/zaGZb DRz2A17zy99TSMYMO8tSShAMAzsGQfgjgUofW5lpev4y20jB754KiEj6WZ5JuVRpcxfD fnx7+kHjVd65I2uMpc+jl0uBqOJxSqEEKq471/gUJn8aSs0Bsdn1UwawRclXN1akFlLo 39SernJR3DETJ+XMSWIGL9PZ2c2m8iY1Fu9IFv6pWwKwAcowhbemNTxrPV7Sad+wsEku fUGQ== X-Gm-Message-State: AOJu0YznNsXi8NDGn8bpH6KP7tnqkj1reTHASdpeMjaM7kiIbPM4kgB6 XiD84+tkqbbZBuA8Ar/nWRt8wjyO4jOeP0phxt8D6tynS8hl1VN18WjFBtVk/fSXPd4= X-Gm-Gg: ASbGncuHIR1wkGARx7r5vuZBlmW9ZKrU2q+BDLMX0eHQf0z1ALBnMAM1fNC6PzUq5D2 lwJjzFN5dFpc7l85swO7PIQ3Rr+bzPt4xYq0dp9Yc/FZZdRgiKDyz1hHeMbi4I/vsPEcc2bA7Tn 8LOQFAAxMUa+7qg58MTv9+k5pKVa4HvmyQ49jfmyPjrF1ALkqkkfVkLiXuAtH5Ee5DkXfP0f0IO R512VXvEH+pIhxrfAabkInYlJoB9YkI7h4H9xyJYa/ikzxHP7gH+8VwK7bgexnRchM8wixClDUW OORr25JQ4HDJKG4bNCe0baJzXpwIaXNyOOaowDtaBbF4MOavOqqzRYIrA7oLBkom+mkHoHytay/ 3d0G9gr70muqjLggAlWlJLQ== X-Google-Smtp-Source: AGHT+IHs6X6TJoZFV3hxG75A/LOqYKYH0DdE6kJoOtPODuPsbqQiF/CnEFD7ROf7LLpj5AehxDrz1g== X-Received: by 2002:a05:6a00:bd93:b0:73e:2d7a:8fc0 with SMTP id d2e1a72fcca58-74ea641180fmr10537784b3a.1.1752165705377; Thu, 10 Jul 2025 09:41:45 -0700 (PDT) From: Gustavo Romero To: qemu-arm@nongnu.org, richard.henderson@linaro.org, alex.bennee@linaro.org Cc: qemu-devel@nongnu.org, gustavo.romero@linaro.org Subject: [PATCH v5 6/6] target/arm: Advertise FEAT_MEC in cpu max Date: Thu, 10 Jul 2025 16:38:59 +0000 Message-Id: <20250710163858.1094780-7-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710163858.1094780-1-gustavo.romero@linaro.org> References: <20250710163858.1094780-1-gustavo.romero@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::430; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x430.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=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 @linaro.org) X-ZM-MESSAGEID: 1752167173615116600 Content-Type: text/plain; charset="utf-8" Advertise FEAT_MEC in AA64MMFR3 ID register for the Arm64 cpu max as a first step to fully support FEAT_MEC. The FEAT_MEC is an extension to FEAT_RME that implements multiple Memory Encryption Contexts (MEC) so the memory in a realm can be encrypted and accessing it from the wrong encryption context is not possible. An encryption context allow the selection of a memory encryption engine. At this point, no real memory encryption is supported, but software stacks that rely on FEAT_MEC to run should work properly. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- docs/system/arm/emulation.rst | 3 +++ target/arm/tcg/cpu64.c | 1 + 2 files changed, 4 insertions(+) diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index 1c597d8673..d207a9f266 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -89,6 +89,9 @@ the following architecture extensions: - FEAT_LSE (Large System Extensions) - FEAT_LSE2 (Large System Extensions v2) - FEAT_LVA (Large Virtual Address space) +- FEAT_MEC (Memory Encryption Contexts) + + * This is a register-only implementation without encryption. - FEAT_MixedEnd (Mixed-endian support) - FEAT_MixedEndEL0 (Mixed-endian support at EL0) - FEAT_MOPS (Standardization of memory operations) diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index ae2046a7f6..1b9b6475b6 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -1250,6 +1250,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =3D GET_IDREG(isar, ID_AA64MMFR3); t =3D FIELD_DP64(t, ID_AA64MMFR3, TCRX, 1); /* FEAT_TCR2 */ t =3D FIELD_DP64(t, ID_AA64MMFR3, SCTLRX, 1); /* FEAT_SCTLR2 */ + t =3D FIELD_DP64(t, ID_AA64MMFR3, MEC, 1); /* FEAT_MEC */ t =3D FIELD_DP64(t, ID_AA64MMFR3, SPEC_FPACC, 1); /* FEAT_FPACC_SPEC */ SET_IDREG(isar, ID_AA64MMFR3, t); =20 --=20 2.34.1