]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c
remove vendor specific fields to improve CDROM read performance.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibRepStr / MemLibGuid.c
CommitLineData
e1f414b6 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
e1f414b6 5 BaseMemoryLib\r
6 BaseMemoryLibMmx\r
7 BaseMemoryLibSse2\r
8 BaseMemoryLibRepStr\r
2bfb6009
LG
9 BaseMemoryLibOptDxe\r
10 BaseMemoryLibOptPei\r
e1f414b6 11 PeiMemoryLib\r
12 DxeMemoryLib\r
13\r
d531bfee 14 Copyright (c) 2006, Intel Corporation<BR>\r
15 All rights reserved. This program and the accompanying materials\r
16 are licensed and made available under the terms and conditions of the BSD License\r
17 which accompanies this distribution. The full text of the license may be found at\r
18 http://opensource.org/licenses/bsd-license.php\r
19\r
20 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
21 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
22\r
e1f414b6 23**/\r
24\r
1efcc4ae 25\r
f734a10a 26#include "MemLibInternals.h"\r
e1f414b6 27\r
a326286c 28\r
e1f414b6 29/**\r
30 Copies a source GUID to a destination GUID.\r
31\r
32 This function copies the contents of the 128-bit GUID specified by SourceGuid to\r
33 DestinationGuid, and returns DestinationGuid.\r
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
66 If Guid1 is NULL, then ASSERT().\r
67 If Guid2 is NULL, then ASSERT().\r
68\r
69 @param Guid1 A pointer to a 128 bit GUID.\r
70 @param Guid2 A pointer to a 128 bit GUID.\r
71\r
72 @retval TRUE Guid1 and Guid2 are identical.\r
73 @retval FALSE Guid1 and Guid2 are not identical.\r
74\r
75**/\r
76BOOLEAN\r
77EFIAPI\r
78CompareGuid (\r
79 IN CONST GUID *Guid1,\r
80 IN CONST GUID *Guid2\r
81 )\r
82{\r
a326286c 83 UINT64 LowPartOfGuid1;\r
84 UINT64 LowPartOfGuid2;\r
85 UINT64 HighPartOfGuid1;\r
86 UINT64 HighPartOfGuid2;\r
d074a8e1 87\r
a326286c 88 LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1);\r
89 LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2);\r
90 HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1);\r
91 HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1);\r
d074a8e1 92\r
a326286c 93 return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);\r
e1f414b6 94}\r
95\r
96/**\r
97 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
98 in the target buffer.\r
99\r
100 This function searches target the buffer specified by Buffer and Length from\r
101 the lowest address to the highest address at 128-bit increments for the 128-bit\r
102 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
103 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
104 If Length is 0, then NULL is returned.\r
105 If Length > 0 and Buffer is NULL, then ASSERT().\r
106 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
107 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
cc4e0485 108 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
e1f414b6 109\r
110 @param Buffer Pointer to the target buffer to scan.\r
111 @param Length Number of bytes in Buffer to scan.\r
112 @param Guid Value to search for in the target buffer.\r
113\r
114 @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
115\r
116**/\r
117VOID *\r
118EFIAPI\r
119ScanGuid (\r
120 IN CONST VOID *Buffer,\r
121 IN UINTN Length,\r
122 IN CONST GUID *Guid\r
123 )\r
124{\r
125 CONST GUID *GuidPtr;\r
126\r
127 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);\r
128 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
129 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);\r
130\r
131 GuidPtr = (GUID*)Buffer;\r
132 Buffer = GuidPtr + Length / sizeof (*GuidPtr);\r
133 while (GuidPtr < (CONST GUID*)Buffer) {\r
134 if (CompareGuid (GuidPtr, Guid)) {\r
135 return (VOID*)GuidPtr;\r
136 }\r
137 GuidPtr++;\r
138 }\r
139 return NULL;\r
140}\r