From 5bdf8acc138474408a7f39e793e5dfe571d0421b Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Fri, 8 Jul 2022 17:07:00 +0100 Subject: [PATCH] MdePkg: Add helper function to detect RME Add helper function to check if the Realm Management Extension (RME) is implemented by the hardware. Cc: Ard Biesheuvel Cc: Leif Lindholm Signed-off-by: Sami Mujawar --- MdePkg/Include/AArch64/AArch64.h | 1 + MdePkg/Include/Library/ArmLib.h | 13 ++++++++++++- MdePkg/Library/ArmLib/AArch64/AArch64Lib.c | 16 +++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/MdePkg/Include/AArch64/AArch64.h b/MdePkg/Include/AArch64/AArch64.h index 40ecd7b668..7349dcf077 100644 --- a/MdePkg/Include/AArch64/AArch64.h +++ b/MdePkg/Include/AArch64/AArch64.h @@ -36,6 +36,7 @@ // ID_AA64PFR0 - AArch64 Processor Feature Register 0 definitions #define AARCH64_PFR0_FP (0xF << 16) #define AARCH64_PFR0_GIC (0xF << 24) +#define AARCH64_PFR0_RME (0xFULL << 52) // ID_AA64PFR2 - AArch64 Processor Feature Register 2 definitions #define AARCH64_PFR2_GCIE (0xF << 12) diff --git a/MdePkg/Include/Library/ArmLib.h b/MdePkg/Include/Library/ArmLib.h index 2a830b6ba7..3f38c026e4 100644 --- a/MdePkg/Include/Library/ArmLib.h +++ b/MdePkg/Include/Library/ArmLib.h @@ -1,7 +1,7 @@ /** @file Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2023, Arm Limited. All rights reserved.
Copyright (c) 2020 - 2021, NUVIA Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -721,3 +721,14 @@ EFIAPI ArmHas52BitTgran4 ( VOID ); + +/** Checks if RME is implemented. + + @retval TRUE RME is implemented. + @retval FALSE RME is not implemented. +**/ +BOOLEAN +EFIAPI +ArmHasRme ( + VOID + ); diff --git a/MdePkg/Library/ArmLib/AArch64/AArch64Lib.c b/MdePkg/Library/ArmLib/AArch64/AArch64Lib.c index 53ea3966a1..ead6dc813a 100644 --- a/MdePkg/Library/ArmLib/AArch64/AArch64Lib.c +++ b/MdePkg/Library/ArmLib/AArch64/AArch64Lib.c @@ -1,7 +1,7 @@ /** @file Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Portions copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ Portions copyright (c) 2011 - 2023, Arm Limited. All rights reserved.
Copyright (c) 2021, NUVIA Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -127,3 +127,17 @@ ArmHas52BitTgran4 ( return ((Mmfr0 & AARCH64_MMFR0_TGRAN4_MASK) == AARCH64_MMFR0_TGRAN4_52BITS); } + +/** Checks if RME is implemented. + + @retval TRUE RME is implemented. + @retval FALSE RME is not implemented. +**/ +BOOLEAN +EFIAPI +ArmHasRme ( + VOID + ) +{ + return ((ArmReadIdAA64Pfr0 () & AARCH64_PFR0_RME) != 0); +}