]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c
Update copyright for files modified in this year
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptPei / MemLibGuid.c
CommitLineData
7b3b4b29 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
eb1c78db 5 \r
7b3b4b29 6 BaseMemoryLib\r
7 BaseMemoryLibMmx\r
8 BaseMemoryLibSse2\r
9 BaseMemoryLibRepStr\r
2bfb6009
LG
10 BaseMemoryLibOptDxe\r
11 BaseMemoryLibOptPei\r
7b3b4b29 12 PeiMemoryLib\r
13 DxeMemoryLib\r
14\r
373ade0e 15 Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
eb1c78db 16 All rights reserved. This program and the accompanying materials\r
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
7b3b4b29 20\r
eb1c78db 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
1efcc4ae 23\r
eb1c78db 24**/\r
7b3b4b29 25\r
eb1c78db 26#include "MemLibInternals.h"\r
7b3b4b29 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
eb1c78db 33 \r
7b3b4b29 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
eb1c78db 66 \r
7b3b4b29 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
101 This function searches target the buffer specified by Buffer and Length from\r
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
eb1c78db 106 \r
7b3b4b29 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
7b3b4b29 111\r
112 @param Buffer Pointer to the target buffer to scan.\r
113 @param Length Number of bytes in Buffer to scan.\r
114 @param Guid Value to search for in the target buffer.\r
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