From nobody Tue Feb 10 03:40:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110548+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110548+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1698933276; cv=none; d=zohomail.com; s=zohoarc; b=Njz59s+1LZncO2VoRKNzo/BBWOek+XhDCnbErJno20Y/ZKb/Qd0MsQoSZJ6a7TwKBE+TKy/qDsGytkjShpLPCYeVSHnzW54dawsb6Hny2hWgfjhgJNHcN9/kIO9006Kh953F7V52VOCae/wQA7Zg+W6PziUGqfj2dHdAGjJSgUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698933276; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Pb9eXVMiAk1hFNXbi/mbBc9xKz7OfaHhwLnV9dpKaYo=; b=fUQNTFrphFrr/Th/hq4kUrSCteFAaTSufnjI6+3++muvlGwJQo9R1QDR2t0LSFs7i/ptp7IMsvO8pAB2Ay3AOnnbJiVwplrtCZu1qry5hmGR7LlAYZY4XPrZJg5KshXI9RDT9HxGzbCN9WxyqoXVUKQeItYapeq/b6T1+nJKCV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110548+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1698933276454377.5959260583744; Thu, 2 Nov 2023 06:54:36 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=JP8MiWb8twMXrtIp+1xizSFeuOK1E7QkqBlNzvRouLk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698933276; v=1; b=jcNzdvb2jedskSl1FErfy5YFnJQc8AwphEvwZ8ga92eUtDVKcfomz5OGZiqJXHyEF9cg1vRE WHMhKMUd7ajIsRw3BCnJgWk7tXsApoNk/iBqXC0r/ieRxJMEvXtYm8yHCHgYpUWTFk1E6tK3P1N 5OTRPwhsVszHS70MzWZtw3RA= X-Received: by 127.0.0.2 with SMTP id WL7iYY1788612xykyBcxTmvF; Thu, 02 Nov 2023 06:54:36 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.31441.1698933275349841278 for ; Thu, 02 Nov 2023 06:54:35 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3ABC7C15; Thu, 2 Nov 2023 06:55:17 -0700 (PDT) X-Received: from cam-smtp0.cambridge.arm.com (e126645.nice.arm.com [10.34.100.114]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9DA633F738; Thu, 2 Nov 2023 06:54:33 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Jiewen Yao , Yi Li , Xiaoyu Lu , Guomin Jiang , Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v1 1/7] MdePkg/BaseLib: AARCH64: Add ArmReadCntPctReg() Date: Thu, 2 Nov 2023 14:54:11 +0100 Message-Id: <20231102135417.336334-2-pierre.gondois@arm.com> In-Reply-To: <20231102135417.336334-1-pierre.gondois@arm.com> References: <20231102135417.336334-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 5HRHIAmorNalujWgwym6jbirx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698933278141100007 Content-Type: text/plain; charset="utf-8" To enable AARCH64 native instruction support for Openssl, some interfaces must be implemented. OPENSSL_rdtsc() requests an access to a counter to get some non-trusted entropy. Add ArmReadCntPctReg() to read system count. A similar ArmReadCntPct() function is available in the ArmPkg, but the CryptoPkg where OPENSSL_rdtsc will reside cannot rely on the ArmPkg. Signed-off-by: Pierre Gondois --- MdePkg/Include/Library/BaseLib.h | 14 +++++++++ .../BaseLib/AArch64/ArmReadCntPctReg.S | 30 +++++++++++++++++++ .../BaseLib/AArch64/ArmReadCntPctReg.asm | 30 +++++++++++++++++++ MdePkg/Library/BaseLib/BaseLib.inf | 4 ++- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 MdePkg/Library/BaseLib/AArch64/ArmReadCntPctReg.S create mode 100644 MdePkg/Library/BaseLib/AArch64/ArmReadCntPctReg.asm diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 5d7067ee854e..b81c9dd83508 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -126,6 +126,20 @@ typedef struct { =20 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8 =20 +/** + Reads the current value of CNTPCT_EL0 register. + + Reads and returns the current value of CNTPCT_EL0. + This function is only available on AARCH64. + + @return The current value of CNTPCT_EL0 +**/ +UINT64 +EFIAPI +ArmReadCntPctReg ( + VOID + ); + #endif // defined (MDE_CPU_AARCH64) =20 #if defined (MDE_CPU_RISCV64) diff --git a/MdePkg/Library/BaseLib/AArch64/ArmReadCntPctReg.S b/MdePkg/Lib= rary/BaseLib/AArch64/ArmReadCntPctReg.S new file mode 100644 index 000000000000..d5f3a0082a99 --- /dev/null +++ b/MdePkg/Library/BaseLib/AArch64/ArmReadCntPctReg.S @@ -0,0 +1,30 @@ +#-------------------------------------------------------------------------= ----- +# +# ArmReadCntPctReg() for AArch64 +# +# Copyright (c) 2023, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#-------------------------------------------------------------------------= ----- + +.text +.p2align 2 +GCC_ASM_EXPORT(ArmReadCntPctReg) + +#/** +# Reads the CNTPCT_EL0 Register. +# +# @return The contents of the CNTPCT_EL0 register. +# +#**/ +#UINT64 +#EFIAPI +#ArmReadCntPctReg ( +# VOID +# ); +# +ASM_PFX(ArmReadCntPctReg): + AARCH64_BTI(c) + mrs x0, cntpct_el0 + ret diff --git a/MdePkg/Library/BaseLib/AArch64/ArmReadCntPctReg.asm b/MdePkg/L= ibrary/BaseLib/AArch64/ArmReadCntPctReg.asm new file mode 100644 index 000000000000..cfdfe4cea4eb --- /dev/null +++ b/MdePkg/Library/BaseLib/AArch64/ArmReadCntPctReg.asm @@ -0,0 +1,30 @@ +;-------------------------------------------------------------------------= ----- +; +; ArmReadCntPctReg() for AArch64 +; +; Copyright (c) 2023, Arm Limited. All rights reserved.
+; +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;-------------------------------------------------------------------------= ----- + + EXPORT ArmReadCntPctReg + AREA BaseLib_LowLevel, CODE, READONLY + +;/** +; Reads the CNTPCT_EL0 Register. +; +; @return The contents of the CNTPCT_EL0 register. +; +;**/ +;UINT64 +;EFIAPI +;ArmReadCntPctReg ( +; VOID +; ); +; +ArmReadCntPctReg + mrs x0, cntpct_el0 + ret + + END diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 03c7b02e828b..24e5e6c3ecb5 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -3,7 +3,7 @@ # # Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
-# Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.
+# Portions copyright (c) 2011 - 2023, Arm Limited. All rights reserved. # Copyright (c) 2020 - 2021, Hewlett Packard Enterprise Development LP. A= ll rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -376,6 +376,7 @@ [Sources.AARCH64] AArch64/SetJumpLongJump.S | GCC AArch64/CpuBreakpoint.S | GCC AArch64/SpeculationBarrier.S | GCC + AArch64/ArmReadCntPctReg.S | GCC =20 AArch64/MemoryFence.asm | MSFT AArch64/SwitchStack.asm | MSFT @@ -385,6 +386,7 @@ [Sources.AARCH64] AArch64/SetJumpLongJump.asm | MSFT AArch64/CpuBreakpoint.asm | MSFT AArch64/SpeculationBarrier.asm | MSFT + AArch64/ArmReadCntPctReg.asm | MSFT =20 [Sources.RISCV64] Math64.c --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110548): https://edk2.groups.io/g/devel/message/110548 Mute This Topic: https://groups.io/mt/102342395/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-