]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c
Clean up: update "EFI" to "UEFI" if applicable.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / BaseUefiTianoCustomDecompressLib / BaseUefiTianoCustomDecompressLib.c
index 629f999da33c37499dd0ae26e6c5730ed948f253..510ca90ae3ae1126a576736d1c9e70ce6dd707d1 100644 (file)
@@ -1,5 +1,6 @@
-/*++\r
-\r
+/**@file\r
+  UEFI and Custom Decompress Library \r
+  \r
 Copyright (c) 2006, Intel Corporation                                                         \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
@@ -9,16 +10,9 @@ http://opensource.org/licenses/bsd-license.php
 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
 \r
-Module Name:\r
-\r
-  BaseUefiTianoCustomDecompressLib.c\r
-\r
-Abstract:\r
-\r
-  UEFI and Custom Decompress Library \r
-\r
---*/\r
+**/\r
 \r
+#include <Guid/CustomDecompress.h>\r
 #include "BaseUefiTianoCustomDecompressLibInternals.h"\r
 \r
 VOID\r
@@ -635,19 +629,18 @@ Returns:
   ASSERT (DestinationSize != NULL);\r
   ASSERT (ScratchSize != NULL);\r
 \r
-  *ScratchSize  = sizeof (SCRATCH_DATA);\r
-\r
   if (SourceSize < 8) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  CopyMem (&CompressedSize, Source, sizeof (UINT32));\r
-  CopyMem (DestinationSize, (VOID *)((UINT8 *)Source + 4), sizeof (UINT32));\r
-\r
+  CompressedSize   = *(UINT32 *) Source;\r
   if (SourceSize < (CompressedSize + 8)) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
+  *ScratchSize  = sizeof (SCRATCH_DATA);\r
+  *DestinationSize = *((UINT32 *) Source + 1);\r
+\r
   return RETURN_SUCCESS;\r
 }\r
 \r
@@ -712,7 +705,7 @@ Returns:
   }\r
   //\r
   // The length of the field 'Position Set Code Length Array Size' in Block Header.\r
-  // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4\r
+  // For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4\r
   // For Tiano de/compression algorithm(Version 2), mPBit = 5\r
   //\r
   switch (Version) {\r
@@ -781,60 +774,132 @@ Returns:
 \r
 RETURN_STATUS\r
 EFIAPI\r
-CustomDecompressGetInfo (\r
-  IN  CONST VOID  *Source,\r
-  IN  UINT32      SourceSize,\r
-  OUT UINT32      *DestinationSize,\r
-  OUT UINT32      *ScratchSize\r
+TianoDecompressGetInfo (\r
+  IN  CONST VOID  *InputSection,\r
+  OUT UINT32      *OutputBufferSize,\r
+  OUT UINT32      *ScratchBufferSize,\r
+  OUT UINT16      *SectionAttribute\r
   )\r
 /*++\r
 \r
 Routine Description:\r
 \r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
+  The internal implementation of Tiano decompress GetInfo.\r
 \r
 Arguments:\r
-\r
-  Source          - The source buffer containing the compressed data.\r
-  SourceSize      - The size of source buffer\r
-  DestinationSize - The size of destination buffer.\r
-  ScratchSize     - The size of scratch buffer.\r
+  InputSection          Buffer containing the input GUIDed section to be processed. \r
+  OutputBufferSize      The size of OutputBuffer.\r
+  ScratchBufferSize     The size of ScratchBuffer.\r
+  SectionAttribute      The attribute of the input guided section.\r
 \r
 Returns:\r
 \r
   RETURN_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
   RETURN_INVALID_PARAMETER - The source data is corrupted\r
+                             The GUID in InputSection does not match this instance guid.\r
 \r
 --*/\r
 {\r
-  return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);\r
+  ASSERT (SectionAttribute != NULL);\r
+\r
+  if (InputSection == NULL) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (!CompareGuid (\r
+        &gTianoCustomDecompressGuid, \r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Get guid attribute of guid section. \r
+  //\r
+  *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+\r
+  //\r
+  // Call Tiano GetInfo to get the required size info.\r
+  //\r
+  return UefiDecompressGetInfo (\r
+          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+          *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+          OutputBufferSize,\r
+          ScratchBufferSize\r
+         );\r
 }\r
 \r
 RETURN_STATUS\r
 EFIAPI\r
-CustomDecompress (\r
-  IN CONST VOID  *Source,\r
-  IN OUT VOID    *Destination,\r
-  IN OUT VOID    *Scratch\r
+TianoDecompress (\r
+  IN CONST  VOID    *InputSection,\r
+  OUT       VOID    **OutputBuffer,\r
+  IN        VOID    *ScratchBuffer,        OPTIONAL\r
+  OUT       UINT32  *AuthenticationStatus\r
   )\r
 /*++\r
 \r
 Routine Description:\r
 \r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
+  The implementation of Tiano Decompress().\r
 \r
 Arguments:\r
-\r
-  Source          - The source buffer containing the compressed data.\r
-  Destination     - The destination buffer to store the decompressed data\r
-  Scratch         - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  InputSection           Buffer containing the input GUIDed section to be processed. \r
+  OutputBuffer           OutputBuffer to point to the start of the section's contents.\r
+                         if guided data is not prcessed. Otherwise,\r
+                         OutputBuffer to contain the output data, which is allocated by the caller.\r
+  ScratchBuffer          A pointer to a caller-allocated buffer for function internal use. \r
+  AuthenticationStatus   A pointer to a caller-allocated UINT32 that indicates the\r
+                         authentication status of the output buffer. 
 \r
 Returns:\r
 \r
   RETURN_SUCCESS           - Decompression is successfull\r
-  RETURN_INVALID_PARAMETER - The source data is corrupted\r
+  RETURN_INVALID_PARAMETER - The source data is corrupted, or\r
+                             The GUID in InputSection does not match this instance guid.\r
 \r
 --*/\r
 {\r
-  return UefiTianoDecompress (Source, Destination, Scratch, 2);\r
+  ASSERT (OutputBuffer != NULL);\r
+\r
+  if (InputSection == NULL) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (!CompareGuid (\r
+        &gTianoCustomDecompressGuid, \r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Set Authentication to Zero.\r
+  //\r
+  *AuthenticationStatus = 0;\r
+  \r
+  //\r
+  // Call Tiano Decompress to get the raw data\r
+  //\r
+  return UefiTianoDecompress (\r
+          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+          *OutputBuffer,\r
+          ScratchBuffer,\r
+          2\r
+         );\r
+}\r
+\r
+/**
+  Register TianoDecompress handler.\r
+
+  @retval  RETURN_SUCCESS            Register successfully.\r
+  @retval  RETURN_OUT_OF_RESOURCES   No enough memory to store this handler.
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TianoDecompressLibConstructor (\r
+)\r
+{\r
+  return ExtractGuidedSectionRegisterHandlers (\r
+          &gTianoCustomDecompressGuid,\r
+          TianoDecompressGetInfo,\r
+          TianoDecompress\r
+          );      \r
 }\r