From: "PierreGondois" <pierre.gondois@arm.com>
To: devel@edk2.groups.io
Cc: Jiewen Yao <jiewen.yao@intel.com>, Yi Li <yi1.li@intel.com>,
Xiaoyu Lu <xiaoyu1.lu@intel.com>,
Guomin Jiang <guomin.jiang@intel.com>,
Leif Lindholm <quic_llindhol@quicinc.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Sami Mujawar <sami.mujawar@arm.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Michael D Kinney <michael.d.kinney@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>
Subject: [edk2-devel] [PATCH v2 6/7] CryptoPkg/OpensslLib: Add AArch64Cap for arch specific hooks
Date: Thu, 9 Nov 2023 10:23:06 +0100 [thread overview]
Message-ID: <20231109092307.1770332-7-pierre.gondois@arm.com> (raw)
In-Reply-To: <20231109092307.1770332-1-pierre.gondois@arm.com>
Add AARCH64 specific implementations of:
- OPENSSL_cpuid_setup(), probing hardware capabilitie
(presence of FEAT_AES, etc.)
- OPENSSL_rdtsc(), returning non-trusted entropy by accessing
system counter.
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
.../Library/OpensslLib/OpensslLibAccel.inf | 1 +
.../OpensslLib/OpensslLibFullAccel.inf | 1 +
.../OpensslLib/OpensslStub/AArch64Cap.c | 107 ++++++++++++++++++
3 files changed, 109 insertions(+)
create mode 100644 CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c
diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf
index 3d1a9638b1c1..fa1f5e6c57d8 100644
--- a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf
+++ b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf
@@ -1329,6 +1329,7 @@ [Sources.X64]
# Autogenerated files list ends here
[Sources.AARCH64]
+ OpensslStub/AArch64Cap.c
# Autogenerated files list starts here
$(OPENSSL_PATH)/crypto/aes/aes_cbc.c
$(OPENSSL_PATH)/crypto/aes/aes_cfb.c
diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
index e7e83d419f4b..4de717712c2c 100644
--- a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
+++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
@@ -1432,6 +1432,7 @@ [Sources.X64]
# Autogenerated files list ends here
[Sources.AARCH64]
+ OpensslStub/AArch64Cap.c
# Autogenerated files list starts here
$(OPENSSL_PATH)/crypto/aes/aes_cbc.c
$(OPENSSL_PATH)/crypto/aes/aes_cfb.c
diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c b/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c
new file mode 100644
index 000000000000..3a21d54462e3
--- /dev/null
+++ b/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c
@@ -0,0 +1,107 @@
+/** @file
+ Arm capabilities probing.
+
+ Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <openssl/types.h>
+#include "crypto/arm_arch.h"
+
+#include <Library/BaseLib.h>
+
+/** Get bits from a value.
+
+ Shift the input value from 'shift' bits and apply 'mask'.
+
+ @param value The value to get the bits from.
+ @param shift Index of the bits to read.
+ @param mask Mask to apply to the value once shifted.
+
+ @return The desired bitfield from the value.
+**/
+#define GET_BITFIELD(value, shift, mask) \
+ ((value >> shift) & mask)
+
+UINT32 OPENSSL_armcap_P = 0;
+
+void
+OPENSSL_cpuid_setup (
+ void
+ )
+{
+ UINT64 Isar0;
+
+ OPENSSL_armcap_P = 0;
+ Isar0 = ArmReadIdAA64Isar0Reg ();
+
+ /* Access to EL0 registers is possible from higher ELx. */
+ OPENSSL_armcap_P |= ARMV8_CPUID;
+ /* Access to Physical timer is possible. */
+ OPENSSL_armcap_P |= ARMV7_TICK;
+
+ /* Neon support is not guaranteed, but it is assumed to be present.
+ Arm ARM for Armv8, sA1.5 Advanced SIMD and floating-point support
+ */
+ OPENSSL_armcap_P |= ARMV7_NEON;
+
+ if (GET_BITFIELD (
+ Isar0,
+ ARM_ID_AA64ISAR0_EL1_AES_SHIFT,
+ ARM_ID_AA64ISAR0_EL1_AES_MASK
+ ) != 0)
+ {
+ OPENSSL_armcap_P |= ARMV8_AES;
+ }
+
+ if (GET_BITFIELD (
+ Isar0,
+ ARM_ID_AA64ISAR0_EL1_SHA1_SHIFT,
+ ARM_ID_AA64ISAR0_EL1_SHA1_MASK
+ ) != 0)
+ {
+ OPENSSL_armcap_P |= ARMV8_SHA1;
+ }
+
+ if (GET_BITFIELD (
+ Isar0,
+ ARM_ID_AA64ISAR0_EL1_SHA2_SHIFT,
+ ARM_ID_AA64ISAR0_EL1_SHA2_MASK
+ ) != 0)
+ {
+ OPENSSL_armcap_P |= ARMV8_SHA256;
+ }
+
+ if (GET_BITFIELD (
+ Isar0,
+ ARM_ID_AA64ISAR0_EL1_AES_SHIFT,
+ ARM_ID_AA64ISAR0_EL1_AES_MASK
+ ) >= ARM_ID_AA64ISAR0_EL1_AES_FEAT_PMULL_MASK)
+ {
+ OPENSSL_armcap_P |= ARMV8_PMULL;
+ }
+
+ if (GET_BITFIELD (
+ Isar0,
+ ARM_ID_AA64ISAR0_EL1_SHA2_SHIFT,
+ ARM_ID_AA64ISAR0_EL1_SHA2_MASK
+ ) >= ARM_ID_AA64ISAR0_EL1_SHA2_FEAT_SHA512_MASK)
+ {
+ OPENSSL_armcap_P |= ARMV8_SHA512;
+ }
+}
+
+/** Read system counter value.
+
+ Used to get some non-trusted entropy.
+
+ @return Lower bits of the physical counter.
+**/
+uint32_t
+OPENSSL_rdtsc (
+ void
+ )
+{
+ return (UINT32)ArmReadCntPctReg ();
+}
--
2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110959): https://edk2.groups.io/g/devel/message/110959
Mute This Topic: https://groups.io/mt/102482404/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-11-09 9:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 9:23 [edk2-devel] [PATCH v2 0/7] CryptoPkg: Enable Openssl native instruction support for AARCH64 PierreGondois
2023-11-09 9:23 ` [edk2-devel] [PATCH v2 1/7] MdePkg/BaseLib: AARCH64: Add ArmReadCntPctReg() PierreGondois
2023-11-09 14:11 ` Leif Lindholm
2023-11-10 9:04 ` PierreGondois
2023-11-09 9:23 ` [edk2-devel] [PATCH v2 2/7] MdePkg/BaseLib: AARCH64: Add ArmReadIdAA64Isar0Reg() PierreGondois
2023-11-09 14:14 ` Leif Lindholm
2023-11-09 9:23 ` [edk2-devel] [PATCH v2 3/7] MdePkg/BaseRngLib: Prefer ArmReadIdAA64Isar0Reg() over ArmReadIdIsar0() PierreGondois
2023-11-09 9:23 ` [edk2-devel] [PATCH v2 4/7] CryptoPkg/OpensslLib: Add native instruction support for AARCH64 PierreGondois
2023-11-09 9:23 ` [edk2-devel] [PATCH v2 5/7] CryptoPkg/OpensslLib: Generate files for AARCH64 native support PierreGondois
2023-11-09 9:23 ` PierreGondois [this message]
2023-11-09 9:23 ` [edk2-devel] [PATCH v2 7/7] CryptoPkg: Enable Openssl Accel builds for AARCH64 PierreGondois
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231109092307.1770332-7-pierre.gondois@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox