From ff37a5485d5477e90e3dc4db29267c5c7e4022a7 Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Thu, 24 Apr 2025 16:57:44 -0700 Subject: [PATCH 1/3] MdePkg: BaseLib: Add UUID-GUID conversion function With interactions between Standalone MM partitions and normal UEFI environment, there is constant need to convert UUID to GUID and back. This change added 2 new interfaces to BaseLib that support such usage. Signed-off-by: Kun Qin --- MdePkg/Include/Library/BaseLib.h | 46 +++++++++++++++ MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Library/BaseLib/ConvertGuidUuid.c | 74 ++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 MdePkg/Library/BaseLib/ConvertGuidUuid.c diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index 9658026d9c60..dc4ab6e6a086 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -4715,6 +4715,52 @@ BitFieldCountOnes64 ( IN UINTN EndBit ); +/** + Convert GUID to RFC4122 UUID format. + + For example, If there is GUID named + "378daedc-f06b-4446-8314-40ab933c87a3", + + GUID is saved in memory like: + dc ae 8d 37 + 6b f0 46 44 + 83 14 40 ab + 93 3c 87 a3 + + However, UUID should be saved like: + 37 8d ae dc + f0 6b 44 46 + 83 14 40 ab + 93 3c 87 a3 + + Other software components (i.e. linux-kernel) uses RFC4122 UUID format. + + @param [in] Guid GUID + @param [out] Uuid Uuid + +**/ +VOID +EFIAPI +ConvertGuidToUuid ( + IN GUID *Guid, + OUT UINT64 *Uuid + ); + +/** + Convert UUID to GUID to RFC4122 UUID format, which is the inverse of + ConvertEfiGuidToUuid. + + @param [in] Uuid Uuid + @param [out] Guid GUID + +**/ +VOID +EFIAPI +ConvertUuidToGuid ( + IN UINT64 *Uuid, + OUT GUID *Guid + ); + // // Base Library Checksum Functions // diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf index 317d32cf68a4..ec40349654b3 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -55,6 +55,7 @@ DivS64x64Remainder.c ARShiftU64.c BitField.c + ConvertGuidUuid.c CpuDeadLoop.c Cpu.c LinkedList.c diff --git a/MdePkg/Library/BaseLib/ConvertGuidUuid.c b/MdePkg/Library/BaseLib/ConvertGuidUuid.c new file mode 100644 index 000000000000..3dbc92e7fd31 --- /dev/null +++ b/MdePkg/Library/BaseLib/ConvertGuidUuid.c @@ -0,0 +1,74 @@ +/** @file + Convert between GUID and UUID RFC4122 format. + + Copyright (c) 2024, Arm Limited. All rights reserved.
+ Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include "BaseLibInternals.h" + +/** + Convert GUID to RFC4122 UUID format. + + For example, If there is GUID named + "378daedc-f06b-4446-8314-40ab933c87a3", + + GUID is saved in memory like: + dc ae 8d 37 + 6b f0 46 44 + 83 14 40 ab + 93 3c 87 a3 + + However, UUID should be saved like: + 37 8d ae dc + f0 6b 44 46 + 83 14 40 ab + 93 3c 87 a3 + + Other software components (i.e. linux-kernel) uses RFC4122 UUID format. + + @param [in] Guid GUID + @param [out] Uuid Uuid + +**/ +VOID +EFIAPI +ConvertGuidToUuid ( + IN GUID *Guid, + OUT UINT64 *Uuid + ) +{ + UINT32 *Data32; + UINT16 *Data16; + + CopyGuid ((GUID *)Uuid, Guid); + Data32 = (UINT32 *)Uuid; + Data32[0] = SwapBytes32 (Data32[0]); + Data16 = (UINT16 *)&Data32[1]; + Data16[0] = SwapBytes16 (Data16[0]); + Data16[1] = SwapBytes16 (Data16[1]); +} + +/** + Convert UUID to GUID to RFC4122 UUID format, which is the inverse of + ConvertEfiGuidToUuid. + + @param [in] Uuid Uuid + @param [out] Guid GUID + +**/ +VOID +EFIAPI +ConvertUuidToGuid ( + IN UINT64 *Uuid, + OUT GUID *Guid + ) +{ + // The conversion is symmetric, so we can use the same function. + // The only difference is the order of the parameters. + ConvertGuidToUuid ( + (GUID *)Uuid, + (UINT64 *)Guid + ); +} From bf8ac73af0d24f83fd6f9c5f9ab17afe08685037 Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Thu, 24 Apr 2025 16:52:52 -0700 Subject: [PATCH 2/3] MdeModulePkg: ArmFfaLib: Support UUID-GUID conversion interfaces This change moves the existing ConvertEfiGuidToUuid function to public interface to support newly defined functions prototypes. This change also adds the `ArmConvertUuidToEfiGuid` function implementation, which is an inverse of the original conversion. Signed-off-by: Kun Qin --- MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c | 47 +------------------ 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c index 1a2d8985e2e4..25fc19c09fdd 100644 --- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c @@ -32,49 +32,6 @@ BOOLEAN gFfaSupported; UINT16 gPartId; -/** - Convert EFI_GUID to UUID format. - for example, If there is EFI_GUID named - "378daedc-f06b-4446-8314-40ab933c87a3", - - EFI_GUID is saved in memory like: - dc ae 8d 37 - 6b f0 46 44 - 83 14 40 ab - 93 3c 87 a3 - - However, UUID should be saved like: - 37 8d ae dc - f0 6b 44 46 - 83 14 40 ab - 93 3c 87 a3 - - FF-A and other software components (i.e. linux-kernel) - uses below format. - - @param [in] Guid EFI_GUID - @param [out] Uuid Uuid - -**/ -STATIC -VOID -EFIAPI -ConvertEfiGuidToUuid ( - IN EFI_GUID *Guid, - OUT UINT64 *Uuid - ) -{ - UINT32 *Data32; - UINT16 *Data16; - - CopyGuid ((EFI_GUID *)Uuid, Guid); - Data32 = (UINT32 *)Uuid; - Data32[0] = SwapBytes32 (Data32[0]); - Data16 = (UINT16 *)&Data32[1]; - Data16[0] = SwapBytes16 (Data16[0]); - Data16[1] = SwapBytes16 (Data16[1]); -} - /** Convert EFI_STATUS to FFA return code. @@ -525,7 +482,7 @@ ArmFfaLibPartitionInfoGet ( } if (ServiceGuid != NULL) { - ConvertEfiGuidToUuid (ServiceGuid, Uuid); + ConvertGuidToUuid (ServiceGuid, Uuid); } else { ZeroMem (Uuid, sizeof (Uuid)); } @@ -689,7 +646,7 @@ ArmFfaLibMsgSendDirectReq2 ( } if (ServiceGuid != NULL) { - ConvertEfiGuidToUuid (ServiceGuid, Uuid); + ConvertGuidToUuid (ServiceGuid, Uuid); } else { ZeroMem (Uuid, sizeof (Uuid)); } From 30f0366d26d1bce204ab0b08dd7fa34cd86ca52d Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Thu, 24 Apr 2025 17:02:09 -0700 Subject: [PATCH 3/3] ArmPkg: ArmStandaloneMmCoreEntryPoint: Use common UUID conversion routine As new interfaces are made available to support UUID-GUID conversion, this change is made to leverage new interfaces and remove the locally duplicated code. Signed-off-by: Kun Qin --- .../ArmStandaloneMmCoreEntryPoint.c | 48 +------------------ 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c b/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c index 7b78834f7d9e..4bf13e6ebb9d 100644 --- a/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c +++ b/ArmPkg/Library/ArmStandaloneMmCoreEntryPoint/ArmStandaloneMmCoreEntryPoint.c @@ -796,52 +796,6 @@ InitializeMiscMmCommunicateBuffer ( CopyGuid (&Buffer->HeaderGuid, ServiceGuid); } -/** - Convert UUID to EFI_GUID format. - for example, If there is EFI_GUID named - "378daedc-f06b-4446-8314-40ab933c87a3", - - EFI_GUID is saved in memory like: - dc ae 8d 37 - 6b f0 46 44 - 83 14 40 ab - 93 3c 87 a3 - - However, UUID should be saved like: - 37 8d ae dc - f0 6b 44 46 - 83 14 40 ab - 93 3c 87 a3 - - FF-A and other software components (i.e. linux-kernel) - uses below format. - - To patch mm-service properly, the passed uuid should be converted to - EFI_GUID format. - - @param [in] Uuid Uuid - @param [out] Guid EFI_GUID - -**/ -STATIC -VOID -EFIAPI -ConvertUuidToEfiGuid ( - IN UINT64 *Uuid, - OUT EFI_GUID *Guid - ) -{ - UINT32 *Data32; - UINT16 *Data16; - - Data32 = (UINT32 *)Uuid; - Data32[0] = SwapBytes32 (Data32[0]); - Data16 = (UINT16 *)&Data32[1]; - Data16[0] = SwapBytes16 (Data16[0]); - Data16[1] = SwapBytes16 (Data16[1]); - CopyGuid (Guid, (EFI_GUID *)Uuid); -} - /** A loop to delegate events from SPMC. DelegatedEventLoop() calls ArmCallSvc() to exit to SPMC. @@ -911,7 +865,7 @@ DelegatedEventLoop ( FfaMsgInfo.DirectMsgVersion = DirectMsgV2; Uuid[0] = EventCompleteSvcArgs->Arg2; Uuid[1] = EventCompleteSvcArgs->Arg3; - ConvertUuidToEfiGuid (Uuid, &ServiceGuid); + ConvertUuidToGuid (Uuid, &ServiceGuid); ServiceType = GetServiceType (&ServiceGuid); } else { Status = EFI_INVALID_PARAMETER;