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