]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BaseMemoryLibStm/MemLibGuid.c
BeagleBoardPkg: remove dependency on ArmPkg/BaseMemoryLibStm
[mirror_edk2.git] / ArmPkg / Library / BaseMemoryLibStm / MemLibGuid.c
CommitLineData
d39eb83c 1/** @file\r
2 Implementation of GUID functions.\r
3\r
4 The following BaseMemoryLib instances contain the same copy of this file:\r
3402aac7 5\r
d39eb83c 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
d6ebcab7
HT
15 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
16 This program and the accompanying materials\r
d39eb83c 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
19 http://opensource.org/licenses/bsd-license.php\r
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
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
3402aac7 33\r
d39eb83c 34 If DestinationGuid is NULL, then ASSERT().\r
35 If SourceGuid is NULL, then ASSERT().\r
36\r
37 @param DestinationGuid Pointer to the destination GUID.\r
38 @param SourceGuid Pointer to the source GUID.\r
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
3402aac7 66\r
d39eb83c 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
c4c90866 84 return (CompareMem(Guid1, Guid2, sizeof(GUID)) == 0) ? TRUE : FALSE;\r
d39eb83c 85}\r
86\r
87/**\r
88 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
89 in the target buffer.\r
90\r
91 This function searches the target buffer specified by Buffer and Length from\r
92 the lowest address to the highest address at 128-bit increments for the 128-bit\r
93 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
94 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
95 If Length is 0, then NULL is returned.\r
3402aac7 96\r
d39eb83c 97 If Length > 0 and Buffer is NULL, then ASSERT().\r
98 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
99 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
100 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
101\r
102 @param Buffer Pointer to the target buffer to scan.\r
103 @param Length Number of bytes in Buffer to scan.\r
104 @param Guid Value to search for in the target buffer.\r
105\r
106 @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
107\r
108**/\r
109VOID *\r
110EFIAPI\r
111ScanGuid (\r
112 IN CONST VOID *Buffer,\r
113 IN UINTN Length,\r
114 IN CONST GUID *Guid\r
115 )\r
116{\r
117 CONST GUID *GuidPtr;\r
118\r
119 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);\r
120 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
121 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);\r
122\r
123 GuidPtr = (GUID*)Buffer;\r
124 Buffer = GuidPtr + Length / sizeof (*GuidPtr);\r
125 while (GuidPtr < (CONST GUID*)Buffer) {\r
126 if (CompareGuid (GuidPtr, Guid)) {\r
127 return (VOID*)GuidPtr;\r
128 }\r
129 GuidPtr++;\r
130 }\r
131 return NULL;\r
132}\r
a548a542
AB
133\r
134/**\r
135 Checks if the given GUID is a zero GUID.\r
136\r
137 This function checks whether the given GUID is a zero GUID. If the GUID is\r
138 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.\r
139\r
140 If Guid is NULL, then ASSERT().\r
141\r
142 @param Guid The pointer to a 128 bit GUID.\r
143\r
144 @retval TRUE Guid is a zero GUID.\r
145 @retval FALSE Guid is not a zero GUID.\r
146\r
147**/\r
148BOOLEAN\r
149EFIAPI\r
150IsZeroGuid (\r
151 IN CONST GUID *Guid\r
152 )\r
153{\r
154 UINT64 LowPartOfGuid;\r
155 UINT64 HighPartOfGuid;\r
156\r
157 LowPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid);\r
158 HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);\r
159\r
160 return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);\r
161}\r