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