Skip to content

Add UUID-GUID conversion interfaces in ArmFfaLib #11004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 2 additions & 45 deletions MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -525,7 +482,7 @@ ArmFfaLibPartitionInfoGet (
}

if (ServiceGuid != NULL) {
ConvertEfiGuidToUuid (ServiceGuid, Uuid);
ConvertGuidToUuid (ServiceGuid, Uuid);
} else {
ZeroMem (Uuid, sizeof (Uuid));
}
Expand Down Expand Up @@ -689,7 +646,7 @@ ArmFfaLibMsgSendDirectReq2 (
}

if (ServiceGuid != NULL) {
ConvertEfiGuidToUuid (ServiceGuid, Uuid);
ConvertGuidToUuid (ServiceGuid, Uuid);
} else {
ZeroMem (Uuid, sizeof (Uuid));
}
Expand Down
46 changes: 46 additions & 0 deletions MdePkg/Include/Library/BaseLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
1 change: 1 addition & 0 deletions MdePkg/Library/BaseLib/BaseLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
DivS64x64Remainder.c
ARShiftU64.c
BitField.c
ConvertGuidUuid.c
CpuDeadLoop.c
Cpu.c
LinkedList.c
Expand Down
74 changes: 74 additions & 0 deletions MdePkg/Library/BaseLib/ConvertGuidUuid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/** @file
Convert between GUID and UUID RFC4122 format.

Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
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
);
}
Loading