]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiMemoryLib/MemLibGuid.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / PeiMemoryLib / MemLibGuid.c
1 /** @file
2 Implementation of GUID functions.
3
4 The following BaseMemoryLib instances contain the same copy of this file:
5
6 BaseMemoryLib
7 BaseMemoryLibMmx
8 BaseMemoryLibSse2
9 BaseMemoryLibRepStr
10 BaseMemoryLibOptDxe
11 BaseMemoryLibOptPei
12 PeiMemoryLib
13 UefiMemoryLib
14
15 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
16 SPDX-License-Identifier: BSD-2-Clause-Patent
17
18 **/
19
20 #include "MemLibInternals.h"
21
22 /**
23 Copies a source GUID to a destination GUID.
24
25 This function copies the contents of the 128-bit GUID specified by SourceGuid to
26 DestinationGuid, and returns DestinationGuid.
27
28 If DestinationGuid is NULL, then ASSERT().
29 If SourceGuid is NULL, then ASSERT().
30
31 @param DestinationGuid The pointer to the destination GUID.
32 @param SourceGuid The pointer to the source GUID.
33
34 @return DestinationGuid.
35
36 **/
37 GUID *
38 EFIAPI
39 CopyGuid (
40 OUT GUID *DestinationGuid,
41 IN CONST GUID *SourceGuid
42 )
43 {
44 WriteUnaligned64 (
45 (UINT64 *)DestinationGuid,
46 ReadUnaligned64 ((CONST UINT64 *)SourceGuid)
47 );
48 WriteUnaligned64 (
49 (UINT64 *)DestinationGuid + 1,
50 ReadUnaligned64 ((CONST UINT64 *)SourceGuid + 1)
51 );
52 return DestinationGuid;
53 }
54
55 /**
56 Compares two GUIDs.
57
58 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
59 If there are any bit differences in the two GUIDs, then FALSE is returned.
60
61 If Guid1 is NULL, then ASSERT().
62 If Guid2 is NULL, then ASSERT().
63
64 @param Guid1 A pointer to a 128 bit GUID.
65 @param Guid2 A pointer to a 128 bit GUID.
66
67 @retval TRUE Guid1 and Guid2 are identical.
68 @retval FALSE Guid1 and Guid2 are not identical.
69
70 **/
71 BOOLEAN
72 EFIAPI
73 CompareGuid (
74 IN CONST GUID *Guid1,
75 IN CONST GUID *Guid2
76 )
77 {
78 UINT64 LowPartOfGuid1;
79 UINT64 LowPartOfGuid2;
80 UINT64 HighPartOfGuid1;
81 UINT64 HighPartOfGuid2;
82
83 LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64 *)Guid1);
84 LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64 *)Guid2);
85 HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64 *)Guid1 + 1);
86 HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64 *)Guid2 + 1);
87
88 return (BOOLEAN)(LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);
89 }
90
91 /**
92 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
93 in the target buffer.
94
95 This function searches the target buffer specified by Buffer and Length from
96 the lowest address to the highest address at 128-bit increments for the 128-bit
97 GUID value that matches Guid. If a match is found, then a pointer to the matching
98 GUID in the target buffer is returned. If no match is found, then NULL is returned.
99 If Length is 0, then NULL is returned.
100
101 If Length > 0 and Buffer is NULL, then ASSERT().
102 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
103 If Length is not aligned on a 128-bit boundary, then ASSERT().
104 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
105
106 @param Buffer The pointer to the target buffer to scan.
107 @param Length The number of bytes in Buffer to scan.
108 @param Guid The value to search for in the target buffer.
109
110 @return A pointer to the matching Guid in the target buffer or NULL otherwise.
111
112 **/
113 VOID *
114 EFIAPI
115 ScanGuid (
116 IN CONST VOID *Buffer,
117 IN UINTN Length,
118 IN CONST GUID *Guid
119 )
120 {
121 CONST GUID *GuidPtr;
122
123 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);
124 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
125 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);
126
127 GuidPtr = (GUID *)Buffer;
128 Buffer = GuidPtr + Length / sizeof (*GuidPtr);
129 while (GuidPtr < (CONST GUID *)Buffer) {
130 if (CompareGuid (GuidPtr, Guid)) {
131 return (VOID *)GuidPtr;
132 }
133
134 GuidPtr++;
135 }
136
137 return NULL;
138 }
139
140 /**
141 Checks if the given GUID is a zero GUID.
142
143 This function checks whether the given GUID is a zero GUID. If the GUID is
144 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
145
146 If Guid is NULL, then ASSERT().
147
148 @param Guid The pointer to a 128 bit GUID.
149
150 @retval TRUE Guid is a zero GUID.
151 @retval FALSE Guid is not a zero GUID.
152
153 **/
154 BOOLEAN
155 EFIAPI
156 IsZeroGuid (
157 IN CONST GUID *Guid
158 )
159 {
160 UINT64 LowPartOfGuid;
161 UINT64 HighPartOfGuid;
162
163 LowPartOfGuid = ReadUnaligned64 ((CONST UINT64 *)Guid);
164 HighPartOfGuid = ReadUnaligned64 ((CONST UINT64 *)Guid + 1);
165
166 return (BOOLEAN)(LowPartOfGuid == 0 && HighPartOfGuid == 0);
167 }