]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseUefiDecompressLib / BaseUefiDecompressLibInternals.h
index a0e44dc07640a19ce1fa1ab7a538fd57132ca666..cb08c2b14d96507b84f3400c385de19e224fecd9 100644 (file)
@@ -1,71 +1,71 @@
 /** @file\r
-  Internal data structure defintions for Base UEFI Decompress Libary.\r
+  Internal data structure defintions for Base UEFI Decompress Library.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
-  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
-\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 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #ifndef __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__\r
 #define __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__\r
 \r
+#include <Base.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiDecompressLib.h>\r
 //\r
 // Decompression algorithm begins here\r
 //\r
-#define BITBUFSIZ 32\r
-#define MAXMATCH  256\r
-#define THRESHOLD 3\r
-#define CODE_BIT  16\r
-#define BAD_TABLE - 1\r
+#define BITBUFSIZ  32\r
+#define MAXMATCH   256\r
+#define THRESHOLD  3\r
+#define CODE_BIT   16\r
+#define BAD_TABLE  - 1\r
 \r
 //\r
 // C: Char&Len Set; P: Position Set; T: exTra Set\r
 //\r
-#define NC      (0xff + MAXMATCH + 2 - THRESHOLD)\r
-#define CBIT    9\r
-#define MAXPBIT 5\r
-#define TBIT    5\r
-#define MAXNP   ((1U << MAXPBIT) - 1)\r
-#define NT      (CODE_BIT + 3)\r
+#define NC       (0xff + MAXMATCH + 2 - THRESHOLD)\r
+#define CBIT     9\r
+#define MAXPBIT  5\r
+#define TBIT     5\r
+#define MAXNP    ((1U << MAXPBIT) - 1)\r
+#define NT       (CODE_BIT + 3)\r
 #if NT > MAXNP\r
-#define NPT NT\r
+#define NPT  NT\r
 #else\r
-#define NPT MAXNP\r
+#define NPT  MAXNP\r
 #endif\r
 \r
 typedef struct {\r
-  UINT8   *mSrcBase;  // Starting address of compressed data\r
-  UINT8   *mDstBase;  // Starting address of decompressed data\r
-  UINT32  mOutBuf;\r
-  UINT32  mInBuf;\r
-\r
-  UINT16  mBitCount;\r
-  UINT32  mBitBuf;\r
-  UINT32  mSubBitBuf;\r
-  UINT16  mBlockSize;\r
-  UINT32  mCompSize;\r
-  UINT32  mOrigSize;\r
-\r
-  UINT16  mBadTableFlag;\r
-\r
-  UINT16  mLeft[2 * NC - 1];\r
-  UINT16  mRight[2 * NC - 1];\r
-  UINT8   mCLen[NC];\r
-  UINT8   mPTLen[NPT];\r
-  UINT16  mCTable[4096];\r
-  UINT16  mPTTable[256];\r
+  UINT8     *mSrcBase; // The starting address of compressed data\r
+  UINT8     *mDstBase; // The starting address of decompressed data\r
+  UINT32    mOutBuf;\r
+  UINT32    mInBuf;\r
+\r
+  UINT16    mBitCount;\r
+  UINT32    mBitBuf;\r
+  UINT32    mSubBitBuf;\r
+  UINT16    mBlockSize;\r
+  UINT32    mCompSize;\r
+  UINT32    mOrigSize;\r
+\r
+  UINT16    mBadTableFlag;\r
+\r
+  UINT16    mLeft[2 * NC - 1];\r
+  UINT16    mRight[2 * NC - 1];\r
+  UINT8     mCLen[NC];\r
+  UINT8     mPTLen[NPT];\r
+  UINT16    mCTable[4096];\r
+  UINT16    mPTTable[256];\r
 \r
   ///\r
   /// The length of the field 'Position Set Code Length Array Size' in Block Header.\r
-  /// For UEFI 2.0 de/compression algorithm, mPBit = 4\r
+  /// For UEFI 2.0 de/compression algorithm, mPBit = 4.\r
+  /// For Tiano de/compression algorithm, mPBit = 5.\r
   ///\r
-  UINT8   mPBit;\r
+  UINT8     mPBit;\r
 } SCRATCH_DATA;\r
 \r
 /**\r
@@ -73,7 +73,7 @@ typedef struct {
 \r
   Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
 \r
-  @param  Sd        The global scratch data\r
+  @param  Sd        The global scratch data.\r
   @param  NumOfBits The number of bits to shift and read.\r
 \r
 **/\r
@@ -107,11 +107,12 @@ GetBits (
 \r
   Creates Huffman Code mapping table for Extra Set, Char&Len Set\r
   and Position Set according to code length array.\r
+  If TableBits > 16, then ASSERT ().\r
 \r
-  @param  Sd        The global scratch data\r
-  @param  NumOfChar Number of symbols in the symbol set\r
-  @param  BitLen    Code length array\r
-  @param  TableBits The width of the mapping table\r
+  @param  Sd        The global scratch data.\r
+  @param  NumOfChar The number of symbols in the symbol set.\r
+  @param  BitLen    Code length array.\r
+  @param  TableBits The width of the mapping table.\r
   @param  Table     The table to be created.\r
 \r
   @retval  0 OK.\r
@@ -132,7 +133,7 @@ MakeTable (
 \r
   Get a position value according to Position Huffman Table.\r
 \r
-  @param  Sd the global scratch data\r
+  @param  Sd The global scratch data.\r
 \r
   @return The position value decoded.\r
 \r
@@ -145,12 +146,12 @@ DecodeP (
 /**\r
   Reads code lengths for the Extra Set or the Position Set.\r
 \r
-  Read in the Extra Set or Pointion Set Length Arrary, then\r
+  Read in the Extra Set or Position Set Length Array, then\r
   generate the Huffman code mapping for them.\r
 \r
   @param  Sd      The global scratch data.\r
-  @param  nn      Number of symbols.\r
-  @param  nbit    Number of bits needed to represent nn.\r
+  @param  nn      The number of symbols.\r
+  @param  nbit    The number of bits needed to represent nn.\r
   @param  Special The special symbol that needs to be taken care of.\r
 \r
   @retval  0 OK.\r
@@ -171,7 +172,7 @@ ReadPTLen (
   Read in and decode the Char&Len Set Code Length Array, then\r
   generate the Huffman Code mapping table for the Char&Len Set.\r
 \r
-  @param  Sd the global scratch data\r
+  @param  Sd The global scratch data.\r
 \r
 **/\r
 VOID\r
@@ -199,7 +200,7 @@ DecodeC (
 /**\r
   Decode the source data and put the resulting data into the destination buffer.\r
 \r
-  @param  Sd The global scratch data\r
+  @param  Sd The global scratch data.\r
 \r
 **/\r
 VOID\r
@@ -207,4 +208,42 @@ Decode (
   SCRATCH_DATA  *Sd\r
   );\r
 \r
+/**\r
+  Decompresses a compressed source buffer.\r
+\r
+  Extracts decompressed data to its original form.\r
+  This function is designed so that the decompression algorithm can be implemented\r
+  without using any memory services.  As a result, this function is not allowed to\r
+  call any memory allocation services in its implementation.  It is the caller's\r
+  responsibility to allocate and free the Destination and Scratch buffers.\r
+  If the compressed source data specified by Source is successfully decompressed\r
+  into Destination, then RETURN_SUCCESS is returned.  If the compressed source data\r
+  specified by Source is not in a valid compressed data format,\r
+  then RETURN_INVALID_PARAMETER is returned.\r
+\r
+  If Source is NULL, then ASSERT().\r
+  If Destination is NULL, then ASSERT().\r
+  If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().\r
+\r
+  @param  Source      The source buffer containing the compressed data.\r
+  @param  Destination The destination buffer to store the decompressed data.\r
+  @param  Scratch     A temporary scratch buffer that is used to perform the decompression.\r
+                      This is an optional parameter that may be NULL if the\r
+                      required scratch buffer size is 0.\r
+  @param  Version     1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm.\r
+\r
+  @retval  RETURN_SUCCESS Decompression completed successfully, and\r
+                          the uncompressed buffer is returned in Destination.\r
+  @retval  RETURN_INVALID_PARAMETER\r
+                          The source buffer specified by Source is corrupted\r
+                          (not in a valid compressed format).\r
+**/\r
+RETURN_STATUS\r
+UefiTianoDecompress (\r
+  IN CONST VOID  *Source,\r
+  IN OUT VOID    *Destination,\r
+  IN OUT VOID    *Scratch,\r
+  IN UINT32      Version\r
+  );\r
+\r
 #endif\r