]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibRepStr / MemLibGuid.c
index b14abbc75a51f125a3a057bc33aee65fc153be68..9ded5ca0f105b6d198d2181761329b79d169fb47 100644 (file)
@@ -2,7 +2,7 @@
   Implementation of GUID functions.\r
 \r
   The following BaseMemoryLib instances contain the same copy of this file:\r
-  \r
+\r
     BaseMemoryLib\r
     BaseMemoryLibMmx\r
     BaseMemoryLibSse2\r
     BaseMemoryLibOptDxe\r
     BaseMemoryLibOptPei\r
     PeiMemoryLib\r
-    DxeMemoryLib\r
-\r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
+    UefiMemoryLib\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
   This function copies the contents of the 128-bit GUID specified by SourceGuid to\r
   DestinationGuid, and returns DestinationGuid.\r
-  \r
+\r
   If DestinationGuid is NULL, then ASSERT().\r
   If SourceGuid is NULL, then ASSERT().\r
 \r
-  @param  DestinationGuid   Pointer to the destination GUID.\r
-  @param  SourceGuid        Pointer to the source GUID.\r
+  @param  DestinationGuid   The pointer to the destination GUID.\r
+  @param  SourceGuid        The pointer to the source GUID.\r
 \r
   @return DestinationGuid.\r
 \r
@@ -48,12 +42,12 @@ CopyGuid (
   )\r
 {\r
   WriteUnaligned64 (\r
-    (UINT64*)DestinationGuid,\r
-    ReadUnaligned64 ((CONST UINT64*)SourceGuid)\r
+    (UINT64 *)DestinationGuid,\r
+    ReadUnaligned64 ((CONST UINT64 *)SourceGuid)\r
     );\r
   WriteUnaligned64 (\r
-    (UINT64*)DestinationGuid + 1,\r
-    ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)\r
+    (UINT64 *)DestinationGuid + 1,\r
+    ReadUnaligned64 ((CONST UINT64 *)SourceGuid + 1)\r
     );\r
   return DestinationGuid;\r
 }\r
@@ -63,7 +57,7 @@ CopyGuid (
 \r
   This function compares Guid1 to Guid2.  If the GUIDs are identical then TRUE is returned.\r
   If there are any bit differences in the two GUIDs, then FALSE is returned.\r
-  \r
+\r
   If Guid1 is NULL, then ASSERT().\r
   If Guid2 is NULL, then ASSERT().\r
 \r
@@ -86,32 +80,32 @@ CompareGuid (
   UINT64  HighPartOfGuid1;\r
   UINT64  HighPartOfGuid2;\r
 \r
-  LowPartOfGuid1  = ReadUnaligned64 ((CONST UINT64*) Guid1);\r
-  LowPartOfGuid2  = ReadUnaligned64 ((CONST UINT64*) Guid2);\r
-  HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1);\r
-  HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1);\r
+  LowPartOfGuid1  = ReadUnaligned64 ((CONST UINT64 *)Guid1);\r
+  LowPartOfGuid2  = ReadUnaligned64 ((CONST UINT64 *)Guid2);\r
+  HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64 *)Guid1 + 1);\r
+  HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64 *)Guid2 + 1);\r
 \r
-  return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);\r
+  return (BOOLEAN)(LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);\r
 }\r
 \r
 /**\r
   Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
   in the target buffer.\r
 \r
-  This function searches target the buffer specified by Buffer and Length from\r
+  This function searches the target buffer specified by Buffer and Length from\r
   the lowest address to the highest address at 128-bit increments for the 128-bit\r
   GUID value that matches Guid.  If a match is found, then a pointer to the matching\r
   GUID in the target buffer is returned.  If no match is found, then NULL is returned.\r
   If Length is 0, then NULL is returned.\r
-  \r
+\r
   If Length > 0 and Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is not aligned on a 128-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer  Pointer to the target buffer to scan.\r
-  @param  Length  Number of bytes in Buffer to scan.\r
-  @param  Guid    Value to search for in the target buffer.\r
+  @param  Buffer  The pointer to the target buffer to scan.\r
+  @param  Length  The number of bytes in Buffer to scan.\r
+  @param  Guid    The value to search for in the target buffer.\r
 \r
   @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
 \r
@@ -124,19 +118,50 @@ ScanGuid (
   IN CONST GUID  *Guid\r
   )\r
 {\r
-  CONST GUID                        *GuidPtr;\r
+  CONST GUID  *GuidPtr;\r
 \r
   ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);\r
   ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
   ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);\r
 \r
-  GuidPtr = (GUID*)Buffer;\r
+  GuidPtr = (GUID *)Buffer;\r
   Buffer  = GuidPtr + Length / sizeof (*GuidPtr);\r
-  while (GuidPtr < (CONST GUID*)Buffer) {\r
+  while (GuidPtr < (CONST GUID *)Buffer) {\r
     if (CompareGuid (GuidPtr, Guid)) {\r
-      return (VOID*)GuidPtr;\r
+      return (VOID *)GuidPtr;\r
     }\r
+\r
     GuidPtr++;\r
   }\r
+\r
   return NULL;\r
 }\r
+\r
+/**\r
+  Checks if the given GUID is a zero GUID.\r
+\r
+  This function checks whether the given GUID is a zero GUID. If the GUID is\r
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.\r
+\r
+  If Guid is NULL, then ASSERT().\r
+\r
+  @param  Guid        The pointer to a 128 bit GUID.\r
+\r
+  @retval TRUE        Guid is a zero GUID.\r
+  @retval FALSE       Guid is not a zero GUID.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroGuid (\r
+  IN CONST GUID  *Guid\r
+  )\r
+{\r
+  UINT64  LowPartOfGuid;\r
+  UINT64  HighPartOfGuid;\r
+\r
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64 *)Guid);\r
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64 *)Guid + 1);\r
+\r
+  return (BOOLEAN)(LowPartOfGuid == 0 && HighPartOfGuid == 0);\r
+}\r