Home | History | Annotate | Download | only in Common
      1 /*++
      2 
      3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
      4 This program and the accompanying materials
      5 are licensed and made available under the terms and conditions of the BSD License
      6 which accompanies this distribution.  The full text of the license may be found at
      7 http://opensource.org/licenses/bsd-license.php
      8 
      9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 
     12 Module Name:
     13 
     14   Decompress.c
     15 
     16 Abstract:
     17 
     18   Decompressor. Algorithm Ported from OPSD code (Decomp.asm)
     19 
     20 --*/
     21 
     22 #include "TianoCommon.h"
     23 
     24 
     25 //
     26 // Decompression algorithm begins here
     27 //
     28 #define BITBUFSIZ 32
     29 #define MAXMATCH  256
     30 #define THRESHOLD 3
     31 #define CODE_BIT  16
     32 #define UINT8_MAX 0xff
     33 #define BAD_TABLE - 1
     34 
     35 //
     36 // C: Char&Len Set; P: Position Set; T: exTra Set
     37 //
     38 #define NC      (0xff + MAXMATCH + 2 - THRESHOLD)
     39 #define CBIT    9
     40 #define MAXPBIT 5
     41 #define TBIT    5
     42 #define MAXNP   ((1U << MAXPBIT) - 1)
     43 #define NT      (CODE_BIT + 3)
     44 #if NT > MAXNP
     45 #define NPT NT
     46 #else
     47 #define NPT MAXNP
     48 #endif
     49 
     50 typedef struct {
     51   UINT8   *mSrcBase;  // Starting address of compressed data
     52   UINT8   *mDstBase;  // Starting address of decompressed data
     53   UINT32  mOutBuf;
     54   UINT32  mInBuf;
     55 
     56   UINT16  mBitCount;
     57   UINT32  mBitBuf;
     58   UINT32  mSubBitBuf;
     59   UINT16  mBlockSize;
     60   UINT32  mCompSize;
     61   UINT32  mOrigSize;
     62 
     63   UINT16  mBadTableFlag;
     64 
     65   UINT16  mLeft[2 * NC - 1];
     66   UINT16  mRight[2 * NC - 1];
     67   UINT8   mCLen[NC];
     68   UINT8   mPTLen[NPT];
     69   UINT16  mCTable[4096];
     70   UINT16  mPTTable[256];
     71 
     72   //
     73   // The length of the field 'Position Set Code Length Array Size' in Block Header.
     74   // For EFI 1.1 de/compression algorithm, mPBit = 4
     75   // For Tiano de/compression algorithm, mPBit = 5
     76   //
     77   UINT8   mPBit;
     78 } SCRATCH_DATA;
     79 
     80 STATIC
     81 VOID
     82 FillBuf (
     83   IN  SCRATCH_DATA  *Sd,
     84   IN  UINT16        NumOfBits
     85   )
     86 /*++
     87 
     88 Routine Description:
     89 
     90   Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
     91 
     92 Arguments:
     93 
     94   Sd        - The global scratch data
     95   NumOfBits  - The number of bits to shift and read.
     96 
     97 Returns: (VOID)
     98 
     99 --*/
    100 {
    101   Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);
    102 
    103   while (NumOfBits > Sd->mBitCount) {
    104 
    105     Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));
    106 
    107     if (Sd->mCompSize > 0) {
    108       //
    109       // Get 1 byte into SubBitBuf
    110       //
    111       Sd->mCompSize--;
    112       Sd->mSubBitBuf  = 0;
    113       Sd->mSubBitBuf  = Sd->mSrcBase[Sd->mInBuf++];
    114       Sd->mBitCount   = 8;
    115 
    116     } else {
    117       //
    118       // No more bits from the source, just pad zero bit.
    119       //
    120       Sd->mSubBitBuf  = 0;
    121       Sd->mBitCount   = 8;
    122 
    123     }
    124   }
    125 
    126   Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
    127   Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
    128 }
    129 
    130 STATIC
    131 UINT32
    132 GetBits (
    133   IN  SCRATCH_DATA  *Sd,
    134   IN  UINT16        NumOfBits
    135   )
    136 /*++
    137 
    138 Routine Description:
    139 
    140   Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
    141   NumOfBits of bits from source. Returns NumOfBits of bits that are
    142   popped out.
    143 
    144 Arguments:
    145 
    146   Sd            - The global scratch data.
    147   NumOfBits     - The number of bits to pop and read.
    148 
    149 Returns:
    150 
    151   The bits that are popped out.
    152 
    153 --*/
    154 {
    155   UINT32  OutBits;
    156 
    157   OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
    158 
    159   FillBuf (Sd, NumOfBits);
    160 
    161   return OutBits;
    162 }
    163 
    164 STATIC
    165 UINT16
    166 MakeTable (
    167   IN  SCRATCH_DATA  *Sd,
    168   IN  UINT16        NumOfChar,
    169   IN  UINT8         *BitLen,
    170   IN  UINT16        TableBits,
    171   OUT UINT16        *Table
    172   )
    173 /*++
    174 
    175 Routine Description:
    176 
    177   Creates Huffman Code mapping table according to code length array.
    178 
    179 Arguments:
    180 
    181   Sd        - The global scratch data
    182   NumOfChar - Number of symbols in the symbol set
    183   BitLen    - Code length array
    184   TableBits - The width of the mapping table
    185   Table     - The table
    186 
    187 Returns:
    188 
    189   0         - OK.
    190   BAD_TABLE - The table is corrupted.
    191 
    192 --*/
    193 {
    194   UINT16  Count[17];
    195   UINT16  Weight[17];
    196   UINT16  Start[18];
    197   UINT16  *Pointer;
    198   UINT16  Index3;
    199   UINT16  Index;
    200   UINT16  Len;
    201   UINT16  Char;
    202   UINT16  JuBits;
    203   UINT16  Avail;
    204   UINT16  NextCode;
    205   UINT16  Mask;
    206 
    207   for (Index = 1; Index <= 16; Index++) {
    208     Count[Index] = 0;
    209   }
    210 
    211   for (Index = 0; Index < NumOfChar; Index++) {
    212     Count[BitLen[Index]]++;
    213   }
    214 
    215   Start[1] = 0;
    216 
    217   for (Index = 1; Index <= 16; Index++) {
    218     Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));
    219   }
    220 
    221   if (Start[17] != 0) {
    222     /*(1U << 16)*/
    223     return (UINT16) BAD_TABLE;
    224   }
    225 
    226   JuBits = (UINT16) (16 - TableBits);
    227 
    228   for (Index = 1; Index <= TableBits; Index++) {
    229     Start[Index] >>= JuBits;
    230     Weight[Index] = (UINT16) (1U << (TableBits - Index));
    231   }
    232 
    233   while (Index <= 16) {
    234     Weight[Index++] = (UINT16) (1U << (16 - Index));
    235   }
    236 
    237   Index = (UINT16) (Start[TableBits + 1] >> JuBits);
    238 
    239   if (Index != 0) {
    240     Index3 = (UINT16) (1U << TableBits);
    241     while (Index != Index3) {
    242       Table[Index++] = 0;
    243     }
    244   }
    245 
    246   Avail = NumOfChar;
    247   Mask  = (UINT16) (1U << (15 - TableBits));
    248 
    249   for (Char = 0; Char < NumOfChar; Char++) {
    250 
    251     Len = BitLen[Char];
    252     if (Len == 0) {
    253       continue;
    254     }
    255 
    256     NextCode = (UINT16) (Start[Len] + Weight[Len]);
    257 
    258     if (Len <= TableBits) {
    259 
    260       for (Index = Start[Len]; Index < NextCode; Index++) {
    261         Table[Index] = Char;
    262       }
    263 
    264     } else {
    265 
    266       Index3  = Start[Len];
    267       Pointer = &Table[Index3 >> JuBits];
    268       Index   = (UINT16) (Len - TableBits);
    269 
    270       while (Index != 0) {
    271         if (*Pointer == 0) {
    272           Sd->mRight[Avail]                     = Sd->mLeft[Avail] = 0;
    273           *Pointer = Avail++;
    274         }
    275 
    276         if (Index3 & Mask) {
    277           Pointer = &Sd->mRight[*Pointer];
    278         } else {
    279           Pointer = &Sd->mLeft[*Pointer];
    280         }
    281 
    282         Index3 <<= 1;
    283         Index--;
    284       }
    285 
    286       *Pointer = Char;
    287 
    288     }
    289 
    290     Start[Len] = NextCode;
    291   }
    292   //
    293   // Succeeds
    294   //
    295   return 0;
    296 }
    297 
    298 STATIC
    299 UINT32
    300 DecodeP (
    301   IN  SCRATCH_DATA  *Sd
    302   )
    303 /*++
    304 
    305 Routine Description:
    306 
    307   Decodes a position value.
    308 
    309 Arguments:
    310 
    311   Sd      - the global scratch data
    312 
    313 Returns:
    314 
    315   The position value decoded.
    316 
    317 --*/
    318 {
    319   UINT16  Val;
    320   UINT32  Mask;
    321   UINT32  Pos;
    322 
    323   Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
    324 
    325   if (Val >= MAXNP) {
    326     Mask = 1U << (BITBUFSIZ - 1 - 8);
    327 
    328     do {
    329 
    330       if (Sd->mBitBuf & Mask) {
    331         Val = Sd->mRight[Val];
    332       } else {
    333         Val = Sd->mLeft[Val];
    334       }
    335 
    336       Mask >>= 1;
    337     } while (Val >= MAXNP);
    338   }
    339   //
    340   // Advance what we have read
    341   //
    342   FillBuf (Sd, Sd->mPTLen[Val]);
    343 
    344   Pos = Val;
    345   if (Val > 1) {
    346     Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
    347   }
    348 
    349   return Pos;
    350 }
    351 
    352 STATIC
    353 UINT16
    354 ReadPTLen (
    355   IN  SCRATCH_DATA  *Sd,
    356   IN  UINT16        nn,
    357   IN  UINT16        nbit,
    358   IN  UINT16        Special
    359   )
    360 /*++
    361 
    362 Routine Description:
    363 
    364   Reads code lengths for the Extra Set or the Position Set
    365 
    366 Arguments:
    367 
    368   Sd        - The global scratch data
    369   nn        - Number of symbols
    370   nbit      - Number of bits needed to represent nn
    371   Special   - The special symbol that needs to be taken care of
    372 
    373 Returns:
    374 
    375   0         - OK.
    376   BAD_TABLE - Table is corrupted.
    377 
    378 --*/
    379 {
    380   UINT16  Number;
    381   UINT16  CharC;
    382   UINT16  Index;
    383   UINT32  Mask;
    384 
    385   Number = (UINT16) GetBits (Sd, nbit);
    386 
    387   if (Number == 0) {
    388     CharC = (UINT16) GetBits (Sd, nbit);
    389 
    390     for (Index = 0; Index < 256; Index++) {
    391       Sd->mPTTable[Index] = CharC;
    392     }
    393 
    394     for (Index = 0; Index < nn; Index++) {
    395       Sd->mPTLen[Index] = 0;
    396     }
    397 
    398     return 0;
    399   }
    400 
    401   Index = 0;
    402 
    403   while (Index < Number) {
    404 
    405     CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
    406 
    407     if (CharC == 7) {
    408       Mask = 1U << (BITBUFSIZ - 1 - 3);
    409       while (Mask & Sd->mBitBuf) {
    410         Mask >>= 1;
    411         CharC += 1;
    412       }
    413     }
    414 
    415     FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
    416 
    417     Sd->mPTLen[Index++] = (UINT8) CharC;
    418 
    419     if (Index == Special) {
    420       CharC = (UINT16) GetBits (Sd, 2);
    421       while ((INT16) (--CharC) >= 0) {
    422         Sd->mPTLen[Index++] = 0;
    423       }
    424     }
    425   }
    426 
    427   while (Index < nn) {
    428     Sd->mPTLen[Index++] = 0;
    429   }
    430 
    431   return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
    432 }
    433 
    434 STATIC
    435 VOID
    436 ReadCLen (
    437   SCRATCH_DATA  *Sd
    438   )
    439 /*++
    440 
    441 Routine Description:
    442 
    443   Reads code lengths for Char&Len Set.
    444 
    445 Arguments:
    446 
    447   Sd    - the global scratch data
    448 
    449 Returns: (VOID)
    450 
    451 --*/
    452 {
    453   UINT16  Number;
    454   UINT16  CharC;
    455   UINT16  Index;
    456   UINT32  Mask;
    457 
    458   Number = (UINT16) GetBits (Sd, CBIT);
    459 
    460   if (Number == 0) {
    461     CharC = (UINT16) GetBits (Sd, CBIT);
    462 
    463     for (Index = 0; Index < NC; Index++) {
    464       Sd->mCLen[Index] = 0;
    465     }
    466 
    467     for (Index = 0; Index < 4096; Index++) {
    468       Sd->mCTable[Index] = CharC;
    469     }
    470 
    471     return ;
    472   }
    473 
    474   Index = 0;
    475   while (Index < Number) {
    476 
    477     CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
    478     if (CharC >= NT) {
    479       Mask = 1U << (BITBUFSIZ - 1 - 8);
    480 
    481       do {
    482 
    483         if (Mask & Sd->mBitBuf) {
    484           CharC = Sd->mRight[CharC];
    485         } else {
    486           CharC = Sd->mLeft[CharC];
    487         }
    488 
    489         Mask >>= 1;
    490 
    491       } while (CharC >= NT);
    492     }
    493     //
    494     // Advance what we have read
    495     //
    496     FillBuf (Sd, Sd->mPTLen[CharC]);
    497 
    498     if (CharC <= 2) {
    499 
    500       if (CharC == 0) {
    501         CharC = 1;
    502       } else if (CharC == 1) {
    503         CharC = (UINT16) (GetBits (Sd, 4) + 3);
    504       } else if (CharC == 2) {
    505         CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
    506       }
    507 
    508       while ((INT16) (--CharC) >= 0) {
    509         Sd->mCLen[Index++] = 0;
    510       }
    511 
    512     } else {
    513 
    514       Sd->mCLen[Index++] = (UINT8) (CharC - 2);
    515 
    516     }
    517   }
    518 
    519   while (Index < NC) {
    520     Sd->mCLen[Index++] = 0;
    521   }
    522 
    523   MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
    524 
    525   return ;
    526 }
    527 
    528 STATIC
    529 UINT16
    530 DecodeC (
    531   SCRATCH_DATA  *Sd
    532   )
    533 /*++
    534 
    535 Routine Description:
    536 
    537   Decode a character/length value.
    538 
    539 Arguments:
    540 
    541   Sd    - The global scratch data.
    542 
    543 Returns:
    544 
    545   The value decoded.
    546 
    547 --*/
    548 {
    549   UINT16  Index2;
    550   UINT32  Mask;
    551 
    552   if (Sd->mBlockSize == 0) {
    553     //
    554     // Starting a new block
    555     //
    556     Sd->mBlockSize    = (UINT16) GetBits (Sd, 16);
    557     Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
    558     if (Sd->mBadTableFlag != 0) {
    559       return 0;
    560     }
    561 
    562     ReadCLen (Sd);
    563 
    564     Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));
    565     if (Sd->mBadTableFlag != 0) {
    566       return 0;
    567     }
    568   }
    569 
    570   Sd->mBlockSize--;
    571   Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
    572 
    573   if (Index2 >= NC) {
    574     Mask = 1U << (BITBUFSIZ - 1 - 12);
    575 
    576     do {
    577       if (Sd->mBitBuf & Mask) {
    578         Index2 = Sd->mRight[Index2];
    579       } else {
    580         Index2 = Sd->mLeft[Index2];
    581       }
    582 
    583       Mask >>= 1;
    584     } while (Index2 >= NC);
    585   }
    586   //
    587   // Advance what we have read
    588   //
    589   FillBuf (Sd, Sd->mCLen[Index2]);
    590 
    591   return Index2;
    592 }
    593 
    594 STATIC
    595 VOID
    596 Decode (
    597   SCRATCH_DATA  *Sd
    598   )
    599 /*++
    600 
    601 Routine Description:
    602 
    603   Decode the source data and put the resulting data into the destination buffer.
    604 
    605 Arguments:
    606 
    607   Sd            - The global scratch data
    608 
    609 Returns: (VOID)
    610 
    611  --*/
    612 {
    613   UINT16  BytesRemain;
    614   UINT32  DataIdx;
    615   UINT16  CharC;
    616 
    617   BytesRemain = (UINT16) (-1);
    618 
    619   DataIdx     = 0;
    620 
    621   for (;;) {
    622     CharC = DecodeC (Sd);
    623     if (Sd->mBadTableFlag != 0) {
    624       return ;
    625     }
    626 
    627     if (CharC < 256) {
    628       //
    629       // Process an Original character
    630       //
    631       if (Sd->mOutBuf >= Sd->mOrigSize) {
    632         return ;
    633       } else {
    634         Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
    635       }
    636 
    637     } else {
    638       //
    639       // Process a Pointer
    640       //
    641       CharC       = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));
    642 
    643       BytesRemain = CharC;
    644 
    645       DataIdx     = Sd->mOutBuf - DecodeP (Sd) - 1;
    646 
    647       BytesRemain--;
    648       while ((INT16) (BytesRemain) >= 0) {
    649         Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
    650         if (Sd->mOutBuf >= Sd->mOrigSize) {
    651           return ;
    652         }
    653 
    654         BytesRemain--;
    655       }
    656     }
    657   }
    658 
    659   return ;
    660 }
    661 
    662 EFI_STATUS
    663 GetInfo (
    664   IN      VOID    *Source,
    665   IN      UINT32  SrcSize,
    666   OUT     UINT32  *DstSize,
    667   OUT     UINT32  *ScratchSize
    668   )
    669 /*++
    670 
    671 Routine Description:
    672 
    673   The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().
    674 
    675 Arguments:
    676 
    677   Source      - The source buffer containing the compressed data.
    678   SrcSize     - The size of source buffer
    679   DstSize     - The size of destination buffer.
    680   ScratchSize - The size of scratch buffer.
    681 
    682 Returns:
    683 
    684   EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.
    685   EFI_INVALID_PARAMETER - The source data is corrupted
    686 
    687 --*/
    688 {
    689   UINT8 *Src;
    690 
    691   *ScratchSize  = sizeof (SCRATCH_DATA);
    692 
    693   Src           = Source;
    694   if (SrcSize < 8) {
    695     return EFI_INVALID_PARAMETER;
    696   }
    697 
    698   *DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
    699   return EFI_SUCCESS;
    700 }
    701 
    702 EFI_STATUS
    703 Decompress (
    704   IN      VOID    *Source,
    705   IN      UINT32  SrcSize,
    706   IN OUT  VOID    *Destination,
    707   IN      UINT32  DstSize,
    708   IN OUT  VOID    *Scratch,
    709   IN      UINT32  ScratchSize,
    710   IN      UINT8   Version
    711   )
    712 /*++
    713 
    714 Routine Description:
    715 
    716   The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().
    717 
    718 Arguments:
    719 
    720   Source      - The source buffer containing the compressed data.
    721   SrcSize     - The size of source buffer
    722   Destination - The destination buffer to store the decompressed data
    723   DstSize     - The size of destination buffer.
    724   Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.
    725   ScratchSize - The size of scratch buffer.
    726   Version     - The version of de/compression algorithm.
    727                 Version 1 for EFI 1.1 de/compression algorithm.
    728                 Version 2 for Tiano de/compression algorithm.
    729 
    730 Returns:
    731 
    732   EFI_SUCCESS           - Decompression is successfull
    733   EFI_INVALID_PARAMETER - The source data is corrupted
    734 
    735 --*/
    736 {
    737   UINT32        Index;
    738   UINT32        CompSize;
    739   UINT32        OrigSize;
    740   EFI_STATUS    Status;
    741   SCRATCH_DATA  *Sd;
    742   UINT8         *Src;
    743   UINT8         *Dst;
    744 
    745   Status  = EFI_SUCCESS;
    746   Src     = Source;
    747   Dst     = Destination;
    748 
    749   if (ScratchSize < sizeof (SCRATCH_DATA)) {
    750     return EFI_INVALID_PARAMETER;
    751   }
    752 
    753   Sd = (SCRATCH_DATA *) Scratch;
    754 
    755   if (SrcSize < 8) {
    756     return EFI_INVALID_PARAMETER;
    757   }
    758 
    759   CompSize  = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
    760   OrigSize  = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
    761 
    762   //
    763   // If compressed file size is 0, return
    764   //
    765   if (OrigSize == 0) {
    766     return Status;
    767   }
    768 
    769   if (SrcSize < CompSize + 8) {
    770     return EFI_INVALID_PARAMETER;
    771   }
    772 
    773   if (DstSize != OrigSize) {
    774     return EFI_INVALID_PARAMETER;
    775   }
    776 
    777   Src = Src + 8;
    778 
    779   for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {
    780     ((UINT8 *) Sd)[Index] = 0;
    781   }
    782   //
    783   // The length of the field 'Position Set Code Length Array Size' in Block Header.
    784   // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4
    785   // For Tiano de/compression algorithm(Version 2), mPBit = 5
    786   //
    787   switch (Version) {
    788   case 1:
    789     Sd->mPBit = 4;
    790     break;
    791 
    792   case 2:
    793     Sd->mPBit = 5;
    794     break;
    795 
    796   default:
    797     //
    798     // Currently, only have 2 versions
    799     //
    800     return EFI_INVALID_PARAMETER;
    801   }
    802 
    803   Sd->mSrcBase  = Src;
    804   Sd->mDstBase  = Dst;
    805   Sd->mCompSize = CompSize;
    806   Sd->mOrigSize = OrigSize;
    807 
    808   //
    809   // Fill the first BITBUFSIZ bits
    810   //
    811   FillBuf (Sd, BITBUFSIZ);
    812 
    813   //
    814   // Decompress it
    815   //
    816   Decode (Sd);
    817 
    818   if (Sd->mBadTableFlag != 0) {
    819     //
    820     // Something wrong with the source
    821     //
    822     Status = EFI_INVALID_PARAMETER;
    823   }
    824 
    825   return Status;
    826 }
    827 
    828 EFI_STATUS
    829 EFIAPI
    830 EfiGetInfo (
    831   IN      VOID                    *Source,
    832   IN      UINT32                  SrcSize,
    833   OUT     UINT32                  *DstSize,
    834   OUT     UINT32                  *ScratchSize
    835   )
    836 /*++
    837 
    838 Routine Description:
    839 
    840   The implementation is same as that  of EFI_DECOMPRESS_PROTOCOL.GetInfo().
    841 
    842 Arguments:
    843 
    844   This        - The protocol instance pointer
    845   Source      - The source buffer containing the compressed data.
    846   SrcSize     - The size of source buffer
    847   DstSize     - The size of destination buffer.
    848   ScratchSize - The size of scratch buffer.
    849 
    850 Returns:
    851 
    852   EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.
    853   EFI_INVALID_PARAMETER - The source data is corrupted
    854 
    855 --*/
    856 {
    857   return GetInfo (
    858           Source,
    859           SrcSize,
    860           DstSize,
    861           ScratchSize
    862           );
    863 }
    864 
    865 EFI_STATUS
    866 EFIAPI
    867 EfiDecompress (
    868   IN      VOID                    *Source,
    869   IN      UINT32                  SrcSize,
    870   IN OUT  VOID                    *Destination,
    871   IN      UINT32                  DstSize,
    872   IN OUT  VOID                    *Scratch,
    873   IN      UINT32                  ScratchSize
    874   )
    875 /*++
    876 
    877 Routine Description:
    878 
    879   The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().
    880 
    881 Arguments:
    882 
    883   This        - The protocol instance pointer
    884   Source      - The source buffer containing the compressed data.
    885   SrcSize     - The size of source buffer
    886   Destination - The destination buffer to store the decompressed data
    887   DstSize     - The size of destination buffer.
    888   Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.
    889   ScratchSize - The size of scratch buffer.
    890 
    891 Returns:
    892 
    893   EFI_SUCCESS           - Decompression is successfull
    894   EFI_INVALID_PARAMETER - The source data is corrupted
    895 
    896 --*/
    897 {
    898   //
    899   // For EFI 1.1 de/compression algorithm, the version is 1.
    900   //
    901   return Decompress (
    902           Source,
    903           SrcSize,
    904           Destination,
    905           DstSize,
    906           Scratch,
    907           ScratchSize,
    908           1
    909           );
    910 }
    911 
    912 EFI_STATUS
    913 EFIAPI
    914 TianoGetInfo (
    915   IN      VOID                          *Source,
    916   IN      UINT32                        SrcSize,
    917   OUT     UINT32                        *DstSize,
    918   OUT     UINT32                        *ScratchSize
    919   )
    920 /*++
    921 
    922 Routine Description:
    923 
    924   The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo().
    925 
    926 Arguments:
    927 
    928   This        - The protocol instance pointer
    929   Source      - The source buffer containing the compressed data.
    930   SrcSize     - The size of source buffer
    931   DstSize     - The size of destination buffer.
    932   ScratchSize - The size of scratch buffer.
    933 
    934 Returns:
    935 
    936   EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.
    937   EFI_INVALID_PARAMETER - The source data is corrupted
    938 
    939 --*/
    940 {
    941   return GetInfo (
    942           Source,
    943           SrcSize,
    944           DstSize,
    945           ScratchSize
    946           );
    947 }
    948 
    949 EFI_STATUS
    950 EFIAPI
    951 TianoDecompress (
    952   IN      VOID                          *Source,
    953   IN      UINT32                        SrcSize,
    954   IN OUT  VOID                          *Destination,
    955   IN      UINT32                        DstSize,
    956   IN OUT  VOID                          *Scratch,
    957   IN      UINT32                        ScratchSize
    958   )
    959 /*++
    960 
    961 Routine Description:
    962 
    963   The implementation is same as that  of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().
    964 
    965 Arguments:
    966 
    967   This        - The protocol instance pointer
    968   Source      - The source buffer containing the compressed data.
    969   SrcSize     - The size of source buffer
    970   Destination - The destination buffer to store the decompressed data
    971   DstSize     - The size of destination buffer.
    972   Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.
    973   ScratchSize - The size of scratch buffer.
    974 
    975 Returns:
    976 
    977   EFI_SUCCESS           - Decompression is successfull
    978   EFI_INVALID_PARAMETER - The source data is corrupted
    979 
    980 --*/
    981 {
    982   //
    983   // For Tiano de/compression algorithm, the version is 2.
    984   //
    985   return Decompress (
    986           Source,
    987           SrcSize,
    988           Destination,
    989           DstSize,
    990           Scratch,
    991           ScratchSize,
    992           2
    993           );
    994 }
    995 
    996