]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptDxe/Arm/MemLibGuid.c
8f1e50b2ed02647380ce86c534eae87bde521031
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptDxe / Arm / MemLibGuid.c
1 /** @file
2 Implementation of GUID functions for ARM and AARCH64
3
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "MemLibInternals.h"
17
18 BOOLEAN
19 EFIAPI
20 InternalMemCompareGuid (
21 IN CONST GUID *Guid1,
22 IN CONST GUID *Guid2
23 );
24
25 /**
26 Copies a source GUID to a destination GUID.
27
28 This function copies the contents of the 128-bit GUID specified by SourceGuid to
29 DestinationGuid, and returns DestinationGuid.
30
31 If DestinationGuid is NULL, then ASSERT().
32 If SourceGuid is NULL, then ASSERT().
33
34 @param DestinationGuid The pointer to the destination GUID.
35 @param SourceGuid The 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 ASSERT (DestinationGuid != NULL);
48 ASSERT (SourceGuid != NULL);
49
50 return InternalMemCopyMem (DestinationGuid, SourceGuid, sizeof (GUID));
51 }
52
53 /**
54 Compares two GUIDs.
55
56 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
57 If there are any bit differences in the two GUIDs, then FALSE is returned.
58
59 If Guid1 is NULL, then ASSERT().
60 If Guid2 is NULL, then ASSERT().
61
62 @param Guid1 A pointer to a 128 bit GUID.
63 @param Guid2 A pointer to a 128 bit GUID.
64
65 @retval TRUE Guid1 and Guid2 are identical.
66 @retval FALSE Guid1 and Guid2 are not identical.
67
68 **/
69 BOOLEAN
70 EFIAPI
71 CompareGuid (
72 IN CONST GUID *Guid1,
73 IN CONST GUID *Guid2
74 )
75 {
76 ASSERT (Guid1 != NULL);
77 ASSERT (Guid2 != NULL);
78
79 return InternalMemCompareGuid (Guid1, Guid2);
80 }
81
82 /**
83 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
84 in the target buffer.
85
86 This function searches the target buffer specified by Buffer and Length from
87 the lowest address to the highest address at 128-bit increments for the 128-bit
88 GUID value that matches Guid. If a match is found, then a pointer to the matching
89 GUID in the target buffer is returned. If no match is found, then NULL is returned.
90 If Length is 0, then NULL is returned.
91
92 If Length > 0 and Buffer is NULL, then ASSERT().
93 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
94 If Length is not aligned on a 128-bit boundary, then ASSERT().
95 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
96
97 @param Buffer The pointer to the target buffer to scan.
98 @param Length The number of bytes in Buffer to scan.
99 @param Guid The value to search for in the target buffer.
100
101 @return A pointer to the matching Guid in the target buffer or NULL otherwise.
102
103 **/
104 VOID *
105 EFIAPI
106 ScanGuid (
107 IN CONST VOID *Buffer,
108 IN UINTN Length,
109 IN CONST GUID *Guid
110 )
111 {
112 CONST GUID *GuidPtr;
113
114 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);
115 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
116 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);
117
118 GuidPtr = (GUID*)Buffer;
119 Buffer = GuidPtr + Length / sizeof (*GuidPtr);
120 while (GuidPtr < (CONST GUID*)Buffer) {
121 if (InternalMemCompareGuid (GuidPtr, Guid)) {
122 return (VOID*)GuidPtr;
123 }
124 GuidPtr++;
125 }
126 return NULL;
127 }
128
129 /**
130 Checks if the given GUID is a zero GUID.
131
132 This function checks whether the given GUID is a zero GUID. If the GUID is
133 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
134
135 If Guid is NULL, then ASSERT().
136
137 @param Guid The pointer to a 128 bit GUID.
138
139 @retval TRUE Guid is a zero GUID.
140 @retval FALSE Guid is not a zero GUID.
141
142 **/
143 BOOLEAN
144 EFIAPI
145 IsZeroGuid (
146 IN CONST GUID *Guid
147 )
148 {
149 ASSERT (Guid != NULL);
150
151 return InternalMemCompareGuid (Guid, NULL);
152 }