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