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