Skip to content

Commit 3c3bb84

Browse files
pierregondoisJavagedes
authored andcommitted
MdePkg/BaseLib: AARCH64: Add ArmReadIdAA64Isar0Reg()
To enable AARCH64 native instruction support for Openssl, some interfaces must be implemented. OPENSSL_cpuid_setup() allows to probe the supported features of the platform. Add ArmReadIdAA64Isar0Reg() to read the AA64Isar0, containing Arm64 instruction capabilities. A similar ArmReadIdAA64Isar0() function is available in the ArmPkg, but the CryptoPkg where OPENSSL_cpuid_setup will reside cannot rely on the ArmPkg. Signed-off-by: Pierre Gondois <[email protected]>
1 parent 4074228 commit 3c3bb84

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

MdePkg/Include/Library/BaseLib.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,92 @@ typedef struct {
126126

127127
#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
128128

129+
/**
130+
Reads the current value of CNTPCT_EL0 register.
131+
132+
Reads and returns the current value of CNTPCT_EL0.
133+
This function is only available on AARCH64.
134+
135+
@return The current value of CNTPCT_EL0
136+
**/
137+
UINT64
138+
EFIAPI
139+
ArmReadCntPctReg (
140+
VOID
141+
);
142+
143+
//
144+
// Bit shifts for the ID_AA64ISAR0_EL1 register.
145+
//
146+
#define ARM_ID_AA64ISAR0_EL1_AES_SHIFT (4U)
147+
#define ARM_ID_AA64ISAR0_EL1_SHA1_SHIFT (8U)
148+
#define ARM_ID_AA64ISAR0_EL1_SHA2_SHIFT (12U)
149+
#define ARM_ID_AA64ISAR0_EL1_CRC32_SHIFT (16U)
150+
#define ARM_ID_AA64ISAR0_EL1_ATOMIC_SHIFT (20U)
151+
#define ARM_ID_AA64ISAR0_EL1_RDM_SHIFT (28U)
152+
#define ARM_ID_AA64ISAR0_EL1_SHA3_SHIFT (32U)
153+
#define ARM_ID_AA64ISAR0_EL1_SM3_SHIFT (36U)
154+
#define ARM_ID_AA64ISAR0_EL1_SM4_SHIFT (40U)
155+
#define ARM_ID_AA64ISAR0_EL1_DP_SHIFT (44U)
156+
#define ARM_ID_AA64ISAR0_EL1_FHM_SHIFT (48U)
157+
#define ARM_ID_AA64ISAR0_EL1_TS_SHIFT (52U)
158+
#define ARM_ID_AA64ISAR0_EL1_TLB_SHIFT (56U)
159+
#define ARM_ID_AA64ISAR0_EL1_RNDR_SHIFT (60U)
160+
161+
//
162+
// Bit masks for the ID_AA64ISAR0_EL1 fields.
163+
//
164+
#define ARM_ID_AA64ISAR0_EL1_AES_MASK (0xFU)
165+
#define ARM_ID_AA64ISAR0_EL1_SHA1_MASK (0xFU)
166+
#define ARM_ID_AA64ISAR0_EL1_SHA2_MASK (0xFU)
167+
#define ARM_ID_AA64ISAR0_EL1_CRC32_MASK (0xFU)
168+
#define ARM_ID_AA64ISAR0_EL1_ATOMIC_MASK (0xFU)
169+
#define ARM_ID_AA64ISAR0_EL1_RDM_MASK (0xFU)
170+
#define ARM_ID_AA64ISAR0_EL1_SHA3_MASK (0xFU)
171+
#define ARM_ID_AA64ISAR0_EL1_SM3_MASK (0xFU)
172+
#define ARM_ID_AA64ISAR0_EL1_SM4_MASK (0xFU)
173+
#define ARM_ID_AA64ISAR0_EL1_DP_MASK (0xFU)
174+
#define ARM_ID_AA64ISAR0_EL1_FHM_MASK (0xFU)
175+
#define ARM_ID_AA64ISAR0_EL1_TS_MASK (0xFU)
176+
#define ARM_ID_AA64ISAR0_EL1_TLB_MASK (0xFU)
177+
#define ARM_ID_AA64ISAR0_EL1_RNDR_MASK (0xFU)
178+
179+
//
180+
// Bit masks for the ID_AA64ISAR0_EL1 field values.
181+
//
182+
#define ARM_ID_AA64ISAR0_EL1_AES_FEAT_AES_MASK (0x1U)
183+
#define ARM_ID_AA64ISAR0_EL1_AES_FEAT_PMULL_MASK (0x2U)
184+
#define ARM_ID_AA64ISAR0_EL1_SHA1_FEAT_SHA1_MASK (0x1U)
185+
#define ARM_ID_AA64ISAR0_EL1_SHA2_FEAT_SHA256_MASK (0x1U)
186+
#define ARM_ID_AA64ISAR0_EL1_SHA2_FEAT_SHA512_MASK (0x2U)
187+
#define ARM_ID_AA64ISAR0_EL1_CRC32_HAVE_CRC32_MASK (0x1U)
188+
#define ARM_ID_AA64ISAR0_EL1_ATOMIC_FEAT_LSE_MASK (0x2U)
189+
#define ARM_ID_AA64ISAR0_EL1_RDM_FEAT_RDM_MASK (0x1U)
190+
#define ARM_ID_AA64ISAR0_EL1_SHA3_FEAT_SHA3_MASK (0x1U)
191+
#define ARM_ID_AA64ISAR0_EL1_SM3_FEAT_SM3_MASK (0x1U)
192+
#define ARM_ID_AA64ISAR0_EL1_SM4_FEAT_SM4_MASK (0x1U)
193+
#define ARM_ID_AA64ISAR0_EL1_DP_FEAT_DOTPROD_MASK (0x1U)
194+
#define ARM_ID_AA64ISAR0_EL1_FHM_FEAT_FHM_MASK (0x1U)
195+
#define ARM_ID_AA64ISAR0_EL1_TS_FEAT_FLAGM_MASK (0x1U)
196+
#define ARM_ID_AA64ISAR0_EL1_TS_FEAT_FLAGM2_MASK (0x2U)
197+
#define ARM_ID_AA64ISAR0_EL1_TLB_FEAT_TLBIOS_MASK (0x1U)
198+
#define ARM_ID_AA64ISAR0_EL1_TLB_FEAT_TLBIRANGE_MASK (0x2U)
199+
#define ARM_ID_AA64ISAR0_EL1_RNDR_FEAT_RNG_MASK (0x1U)
200+
201+
/**
202+
Reads the current value of ID_AA64ISAR0_EL1 register.
203+
204+
Reads and returns the current value of ID_AA64ISAR0_EL1.
205+
This function is only available on AARCH64.
206+
207+
@return The current value of ID_AA64ISAR0_EL1
208+
**/
209+
UINT64
210+
EFIAPI
211+
ArmReadIdAA64Isar0Reg (
212+
VOID
213+
);
214+
129215
#endif // defined (MDE_CPU_AARCH64)
130216

131217
#if defined (MDE_CPU_RISCV64)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#------------------------------------------------------------------------------
2+
#
3+
# ArmReadIdAA64Isar0Reg() for AArch64
4+
#
5+
# Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
6+
#
7+
# SPDX-License-Identifier: BSD-2-Clause-Patent
8+
#
9+
#------------------------------------------------------------------------------
10+
11+
.text
12+
.p2align 2
13+
GCC_ASM_EXPORT(ArmReadIdAA64Isar0Reg)
14+
15+
#/**
16+
# Reads the ID_AA64ISAR0 Register.
17+
#
18+
# @return The contents of the ID_AA64ISAR0 register.
19+
#
20+
#**/
21+
#UINT64
22+
#EFIAPI
23+
#ArmReadIdAA64Isar0Reg (
24+
# VOID
25+
# );
26+
#
27+
ASM_PFX(ArmReadIdAA64Isar0Reg):
28+
AARCH64_BTI(c)
29+
mrs x0, id_aa64isar0_el1
30+
ret
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
;------------------------------------------------------------------------------
2+
;
3+
; ArmReadIdAA64Isar0Reg() for AArch64
4+
;
5+
; Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
6+
;
7+
; SPDX-License-Identifier: BSD-2-Clause-Patent
8+
;
9+
;------------------------------------------------------------------------------
10+
11+
EXPORT ArmReadIdAA64Isar0Reg
12+
AREA BaseLib_LowLevel, CODE, READONLY
13+
14+
;/**
15+
; Reads the ID_AA64ISAR0 Register.
16+
;
17+
; @return The contents of the ID_AA64ISAR0 register.
18+
;
19+
;**/
20+
;UINT64
21+
;EFIAPI
22+
;ArmReadIdAA64Isar0Reg (
23+
; VOID
24+
; );
25+
;
26+
ArmReadIdAA64Isar0Reg
27+
mrs x0, id_aa64isar0_el1
28+
ret
29+
30+
END

MdePkg/Library/BaseLib/BaseLib.inf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
AArch64/SetJumpLongJump.S | GCC
381381
AArch64/CpuBreakpoint.S | GCC
382382
AArch64/SpeculationBarrier.S | GCC
383+
AArch64/ArmReadIdAA64Isar0Reg.S | GCC
383384
AArch64/CpuBreakAssert.S | GCC ## MU_CHANGE
384385

385386
AArch64/MemoryFence.asm | MSFT
@@ -390,6 +391,7 @@
390391
AArch64/SetJumpLongJump.asm | MSFT
391392
AArch64/CpuBreakpoint.asm | MSFT
392393
AArch64/SpeculationBarrier.asm | MSFT
394+
AArch64/ArmReadIdAA64Isar0Reg.asm | MSFT
393395
AArch64/CpuBreakAssert.c | MSFT ## MU_CHANGE
394396

395397
[Sources.RISCV64]

0 commit comments

Comments
 (0)