]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptPei / MemLibGuid.c
CommitLineData
7b3b4b29 1/** @file\r
2 Implementation of GUID functions.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 The following BaseMemoryLib instances share the same version of this file:\r
14\r
15 BaseMemoryLib\r
16 BaseMemoryLibMmx\r
17 BaseMemoryLibSse2\r
18 BaseMemoryLibRepStr\r
19 PeiMemoryLib\r
20 DxeMemoryLib\r
21\r
22**/\r
23\r
1efcc4ae 24\r
38bbd3d9 25#include "MemLibInternals.h"\r
7b3b4b29 26\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
33 If DestinationGuid is NULL, then ASSERT().\r
34 If SourceGuid is NULL, then ASSERT().\r
35\r
36 @param DestinationGuid Pointer to the destination GUID.\r
37 @param SourceGuid Pointer to the source GUID.\r
38\r
39 @return DestinationGuid.\r
40\r
41**/\r
42GUID *\r
43EFIAPI\r
44CopyGuid (\r
45 OUT GUID *DestinationGuid,\r
46 IN CONST GUID *SourceGuid\r
47 )\r
48{\r
49 WriteUnaligned64 (\r
50 (UINT64*)DestinationGuid,\r
51 ReadUnaligned64 ((CONST UINT64*)SourceGuid)\r
52 );\r
53 WriteUnaligned64 (\r
54 (UINT64*)DestinationGuid + 1,\r
55 ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)\r
56 );\r
57 return DestinationGuid;\r
58}\r
59\r
60/**\r
61 Compares two GUIDs.\r
62\r
63 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r
64 If there are any bit differences in the two GUIDs, then FALSE is returned.\r
65 If Guid1 is NULL, then ASSERT().\r
66 If Guid2 is NULL, then ASSERT().\r
67\r
68 @param Guid1 A pointer to a 128 bit GUID.\r
69 @param Guid2 A pointer to a 128 bit GUID.\r
70\r
71 @retval TRUE Guid1 and Guid2 are identical.\r
72 @retval FALSE Guid1 and Guid2 are not identical.\r
73\r
74**/\r
75BOOLEAN\r
76EFIAPI\r
77CompareGuid (\r
78 IN CONST GUID *Guid1,\r
79 IN CONST GUID *Guid2\r
80 )\r
81{\r
82 UINT64 LowPartOfGuid1;\r
83 UINT64 LowPartOfGuid2;\r
84 UINT64 HighPartOfGuid1;\r
85 UINT64 HighPartOfGuid2;\r
86\r
87 LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1);\r
88 LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2);\r
89 HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1);\r
90 HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1);\r
91\r
92 return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);\r
93}\r
94\r
95/**\r
96 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
97 in the target buffer.\r
98\r
99 This function searches target the buffer specified by Buffer and Length from\r
100 the lowest address to the highest address at 128-bit increments for the 128-bit\r
101 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
102 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
103 If Length is 0, then NULL is returned.\r
104 If Length > 0 and Buffer is NULL, then ASSERT().\r
105 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
106 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
cc4e0485 107 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
7b3b4b29 108\r
109 @param Buffer Pointer to the target buffer to scan.\r
110 @param Length Number of bytes in Buffer to scan.\r
111 @param Guid Value to search for in the target buffer.\r
112\r
113 @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
114\r
115**/\r
116VOID *\r
117EFIAPI\r
118ScanGuid (\r
119 IN CONST VOID *Buffer,\r
120 IN UINTN Length,\r
121 IN CONST GUID *Guid\r
122 )\r
123{\r
124 CONST GUID *GuidPtr;\r
125\r
126 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);\r
127 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
128 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);\r
129\r
130 GuidPtr = (GUID*)Buffer;\r
131 Buffer = GuidPtr + Length / sizeof (*GuidPtr);\r
132 while (GuidPtr < (CONST GUID*)Buffer) {\r
133 if (CompareGuid (GuidPtr, Guid)) {\r
134 return (VOID*)GuidPtr;\r
135 }\r
136 GuidPtr++;\r
137 }\r
138 return NULL;\r
139}\r