]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptDxe/Arm/MemLibGuid.c
MdePkg: Replace BSD License with BSD+Patent License
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "MemLibInternals.h"
11
12 /**
13 Internal function to compare two GUIDs.
14
15 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
16 If there are any bit differences in the two GUIDs, then FALSE is returned.
17
18 @param Guid1 A pointer to a 128 bit GUID.
19 @param Guid2 A pointer to a 128 bit GUID.
20
21 @retval TRUE Guid1 and Guid2 are identical.
22 @retval FALSE Guid1 and Guid2 are not identical.
23
24 **/
25 BOOLEAN
26 EFIAPI
27 InternalMemCompareGuid (
28 IN CONST GUID *Guid1,
29 IN CONST GUID *Guid2
30 );
31
32 /**
33 Copies a source GUID to a destination GUID.
34
35 This function copies the contents of the 128-bit GUID specified by SourceGuid to
36 DestinationGuid, and returns DestinationGuid.
37
38 If DestinationGuid is NULL, then ASSERT().
39 If SourceGuid is NULL, then ASSERT().
40
41 @param DestinationGuid The pointer to the destination GUID.
42 @param SourceGuid The pointer to the source GUID.
43
44 @return DestinationGuid.
45
46 **/
47 GUID *
48 EFIAPI
49 CopyGuid (
50 OUT GUID *DestinationGuid,
51 IN CONST GUID *SourceGuid
52 )
53 {
54 ASSERT (DestinationGuid != NULL);
55 ASSERT (SourceGuid != NULL);
56
57 return InternalMemCopyMem (DestinationGuid, SourceGuid, sizeof (GUID));
58 }
59
60 /**
61 Compares two GUIDs.
62
63 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
64 If there are any bit differences in the two GUIDs, then FALSE is returned.
65
66 If Guid1 is NULL, then ASSERT().
67 If Guid2 is NULL, then ASSERT().
68
69 @param Guid1 A pointer to a 128 bit GUID.
70 @param Guid2 A pointer to a 128 bit GUID.
71
72 @retval TRUE Guid1 and Guid2 are identical.
73 @retval FALSE Guid1 and Guid2 are not identical.
74
75 **/
76 BOOLEAN
77 EFIAPI
78 CompareGuid (
79 IN CONST GUID *Guid1,
80 IN CONST GUID *Guid2
81 )
82 {
83 ASSERT (Guid1 != NULL);
84 ASSERT (Guid2 != NULL);
85
86 return InternalMemCompareGuid (Guid1, Guid2);
87 }
88
89 /**
90 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
91 in the target buffer.
92
93 This function searches the target buffer specified by Buffer and Length from
94 the lowest address to the highest address at 128-bit increments for the 128-bit
95 GUID value that matches Guid. If a match is found, then a pointer to the matching
96 GUID in the target buffer is returned. If no match is found, then NULL is returned.
97 If Length is 0, then NULL is returned.
98
99 If Length > 0 and Buffer is NULL, then ASSERT().
100 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
101 If Length is not aligned on a 128-bit boundary, then ASSERT().
102 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
103
104 @param Buffer The pointer to the target buffer to scan.
105 @param Length The number of bytes in Buffer to scan.
106 @param Guid The value to search for in the target buffer.
107
108 @return A pointer to the matching Guid in the target buffer or NULL otherwise.
109
110 **/
111 VOID *
112 EFIAPI
113 ScanGuid (
114 IN CONST VOID *Buffer,
115 IN UINTN Length,
116 IN CONST GUID *Guid
117 )
118 {
119 CONST GUID *GuidPtr;
120
121 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);
122 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
123 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);
124
125 GuidPtr = (GUID*)Buffer;
126 Buffer = GuidPtr + Length / sizeof (*GuidPtr);
127 while (GuidPtr < (CONST GUID*)Buffer) {
128 if (InternalMemCompareGuid (GuidPtr, Guid)) {
129 return (VOID*)GuidPtr;
130 }
131 GuidPtr++;
132 }
133 return NULL;
134 }
135
136 /**
137 Checks if the given GUID is a zero GUID.
138
139 This function checks whether the given GUID is a zero GUID. If the GUID is
140 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
141
142 If Guid is NULL, then ASSERT().
143
144 @param Guid The pointer to a 128 bit GUID.
145
146 @retval TRUE Guid is a zero GUID.
147 @retval FALSE Guid is not a zero GUID.
148
149 **/
150 BOOLEAN
151 EFIAPI
152 IsZeroGuid (
153 IN CONST GUID *Guid
154 )
155 {
156 ASSERT (Guid != NULL);
157
158 return InternalMemCompareGuid (Guid, NULL);
159 }