]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Pei/PeiLib/Decompress.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Pei / PeiLib / Decompress.c
1 /*++
2
3 Copyright (c) 2004, 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 #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 #ifndef UINT8_MAX
139 #define UINT8_MAX 0xff
140 #endif
141 #define BAD_TABLE - 1
142
143 //
144 // C: Char&Len Set; P: Position Set; T: exTra Set
145 //
146 #define NC (0xff + MAXMATCH + 2 - THRESHOLD)
147 #define CBIT 9
148 #define MAXPBIT 5
149 #define TBIT 5
150 #define MAXNP ((1U << MAXPBIT) - 1)
151 #define NT (CODE_BIT + 3)
152 #if NT > MAXNP
153 #define NPT NT
154 #else
155 #define NPT MAXNP
156 #endif
157
158 typedef struct {
159 UINT8 *mSrcBase; // Starting address of compressed data
160 UINT8 *mDstBase; // Starting address of decompressed data
161 UINT32 mOutBuf;
162 UINT32 mInBuf;
163
164 UINT16 mBitCount;
165 UINT32 mBitBuf;
166 UINT32 mSubBitBuf;
167 UINT16 mBlockSize;
168 UINT32 mCompSize;
169 UINT32 mOrigSize;
170
171 UINT16 mBadTableFlag;
172
173 UINT16 mLeft[2 * NC - 1];
174 UINT16 mRight[2 * NC - 1];
175 UINT8 mCLen[NC];
176 UINT8 mPTLen[NPT];
177 UINT16 mCTable[4096];
178 UINT16 mPTTable[256];
179
180 //
181 // The length of the field 'Position Set Code Length Array Size' in Block Header.
182 // For EFI 1.1 de/compression algorithm, mPBit = 4
183 // For Tiano de/compression algorithm, mPBit = 5
184 //
185 UINT8 mPBit;
186 } SCRATCH_DATA;
187
188 STATIC
189 VOID
190 FillBuf (
191 IN SCRATCH_DATA *Sd,
192 IN UINT16 NumOfBits
193 )
194 /*++
195
196 Routine Description:
197
198 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
199
200 Arguments:
201
202 Sd - The global scratch data
203 NumOfBits - The number of bits to shift and read.
204
205 Returns: (VOID)
206
207 --*/
208 {
209 Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);
210
211 while (NumOfBits > Sd->mBitCount) {
212
213 Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));
214
215 if (Sd->mCompSize > 0) {
216 //
217 // Get 1 byte into SubBitBuf
218 //
219 Sd->mCompSize--;
220 Sd->mSubBitBuf = 0;
221 Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
222 Sd->mBitCount = 8;
223
224 } else {
225 //
226 // No more bits from the source, just pad zero bit.
227 //
228 Sd->mSubBitBuf = 0;
229 Sd->mBitCount = 8;
230
231 }
232 }
233
234 Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
235 Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
236 }
237
238 STATIC
239 UINT32
240 GetBits (
241 IN SCRATCH_DATA *Sd,
242 IN UINT16 NumOfBits
243 )
244 /*++
245
246 Routine Description:
247
248 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
249 NumOfBits of bits from source. Returns NumOfBits of bits that are
250 popped out.
251
252 Arguments:
253
254 Sd - The global scratch data.
255 NumOfBits - The number of bits to pop and read.
256
257 Returns:
258
259 The bits that are popped out.
260
261 --*/
262 {
263 UINT32 OutBits;
264
265 OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
266
267 FillBuf (Sd, NumOfBits);
268
269 return OutBits;
270 }
271
272 STATIC
273 UINT16
274 MakeTable (
275 IN SCRATCH_DATA *Sd,
276 IN UINT16 NumOfChar,
277 IN UINT8 *BitLen,
278 IN UINT16 TableBits,
279 OUT UINT16 *Table
280 )
281 /*++
282
283 Routine Description:
284
285 Creates Huffman Code mapping table according to code length array.
286
287 Arguments:
288
289 Sd - The global scratch data
290 NumOfChar - Number of symbols in the symbol set
291 BitLen - Code length array
292 TableBits - The width of the mapping table
293 Table - The table
294
295 Returns:
296
297 0 - OK.
298 BAD_TABLE - The table is corrupted.
299
300 --*/
301 {
302 UINT16 Count[17];
303 UINT16 Weight[17];
304 UINT16 Start[18];
305 UINT16 *Pointer;
306 UINT16 Index3;
307 UINT16 Index;
308 UINT16 Len;
309 UINT16 Char;
310 UINT16 JuBits;
311 UINT16 Avail;
312 UINT16 NextCode;
313 UINT16 Mask;
314
315 for (Index = 1; Index <= 16; Index++) {
316 Count[Index] = 0;
317 }
318
319 for (Index = 0; Index < NumOfChar; Index++) {
320 Count[BitLen[Index]]++;
321 }
322
323 Start[1] = 0;
324
325 for (Index = 1; Index <= 16; Index++) {
326 Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));
327 }
328
329 if (Start[17] != 0) {
330 /*(1U << 16)*/
331 return (UINT16) BAD_TABLE;
332 }
333
334 JuBits = (UINT16) (16 - TableBits);
335
336 for (Index = 1; Index <= TableBits; Index++) {
337 Start[Index] >>= JuBits;
338 Weight[Index] = (UINT16) (1U << (TableBits - Index));
339 }
340
341 while (Index <= 16) {
342 Weight[Index] = (UINT16) (1U << (16 - Index));
343 Index++;
344 }
345
346 Index = (UINT16) (Start[TableBits + 1] >> JuBits);
347
348 if (Index != 0) {
349 Index3 = (UINT16) (1U << TableBits);
350 while (Index != Index3) {
351 Table[Index++] = 0;
352 }
353 }
354
355 Avail = NumOfChar;
356 Mask = (UINT16) (1U << (15 - TableBits));
357
358 for (Char = 0; Char < NumOfChar; Char++) {
359
360 Len = BitLen[Char];
361 if (Len == 0) {
362 continue;
363 }
364
365 NextCode = (UINT16) (Start[Len] + Weight[Len]);
366
367 if (Len <= TableBits) {
368
369 for (Index = Start[Len]; Index < NextCode; Index++) {
370 Table[Index] = Char;
371 }
372
373 } else {
374
375 Index3 = Start[Len];
376 Pointer = &Table[Index3 >> JuBits];
377 Index = (UINT16) (Len - TableBits);
378
379 while (Index != 0) {
380 if (*Pointer == 0) {
381 Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
382 *Pointer = Avail++;
383 }
384
385 if (Index3 & Mask) {
386 Pointer = &Sd->mRight[*Pointer];
387 } else {
388 Pointer = &Sd->mLeft[*Pointer];
389 }
390
391 Index3 <<= 1;
392 Index--;
393 }
394
395 *Pointer = Char;
396
397 }
398
399 Start[Len] = NextCode;
400 }
401 //
402 // Succeeds
403 //
404 return 0;
405 }
406
407 STATIC
408 UINT32
409 DecodeP (
410 IN SCRATCH_DATA *Sd
411 )
412 /*++
413
414 Routine Description:
415
416 Decodes a position value.
417
418 Arguments:
419
420 Sd - the global scratch data
421
422 Returns:
423
424 The position value decoded.
425
426 --*/
427 {
428 UINT16 Val;
429 UINT32 Mask;
430 UINT32 Pos;
431
432 Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
433
434 if (Val >= MAXNP) {
435 Mask = 1U << (BITBUFSIZ - 1 - 8);
436
437 do {
438
439 if (Sd->mBitBuf & Mask) {
440 Val = Sd->mRight[Val];
441 } else {
442 Val = Sd->mLeft[Val];
443 }
444
445 Mask >>= 1;
446 } while (Val >= MAXNP);
447 }
448 //
449 // Advance what we have read
450 //
451 FillBuf (Sd, Sd->mPTLen[Val]);
452
453 Pos = Val;
454 if (Val > 1) {
455 Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
456 }
457
458 return Pos;
459 }
460
461 STATIC
462 UINT16
463 ReadPTLen (
464 IN SCRATCH_DATA *Sd,
465 IN UINT16 nn,
466 IN UINT16 nbit,
467 IN UINT16 Special
468 )
469 /*++
470
471 Routine Description:
472
473 Reads code lengths for the Extra Set or the Position Set
474
475 Arguments:
476
477 Sd - The global scratch data
478 nn - Number of symbols
479 nbit - Number of bits needed to represent nn
480 Special - The special symbol that needs to be taken care of
481
482 Returns:
483
484 0 - OK.
485 BAD_TABLE - Table is corrupted.
486
487 --*/
488 {
489 UINT16 Number;
490 UINT16 CharC;
491 UINT16 Index;
492 UINT32 Mask;
493
494 Number = (UINT16) GetBits (Sd, nbit);
495
496 if (Number == 0) {
497 CharC = (UINT16) GetBits (Sd, nbit);
498
499 for (Index = 0; Index < 256; Index++) {
500 Sd->mPTTable[Index] = CharC;
501 }
502
503 for (Index = 0; Index < nn; Index++) {
504 Sd->mPTLen[Index] = 0;
505 }
506
507 return 0;
508 }
509
510 Index = 0;
511
512 while (Index < Number) {
513
514 CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
515
516 if (CharC == 7) {
517 Mask = 1U << (BITBUFSIZ - 1 - 3);
518 while (Mask & Sd->mBitBuf) {
519 Mask >>= 1;
520 CharC += 1;
521 }
522 }
523
524 FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
525
526 Sd->mPTLen[Index++] = (UINT8) CharC;
527
528 if (Index == Special) {
529 CharC = (UINT16) GetBits (Sd, 2);
530 while ((INT16) (--CharC) >= 0) {
531 Sd->mPTLen[Index++] = 0;
532 }
533 }
534 }
535
536 while (Index < nn) {
537 Sd->mPTLen[Index++] = 0;
538 }
539
540 return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
541 }
542
543 STATIC
544 VOID
545 ReadCLen (
546 SCRATCH_DATA *Sd
547 )
548 /*++
549
550 Routine Description:
551
552 Reads code lengths for Char&Len Set.
553
554 Arguments:
555
556 Sd - the global scratch data
557
558 Returns: (VOID)
559
560 --*/
561 {
562 UINT16 Number;
563 UINT16 CharC;
564 UINT16 Index;
565 UINT32 Mask;
566
567 Number = (UINT16) GetBits (Sd, CBIT);
568
569 if (Number == 0) {
570 CharC = (UINT16) GetBits (Sd, CBIT);
571
572 for (Index = 0; Index < NC; Index++) {
573 Sd->mCLen[Index] = 0;
574 }
575
576 for (Index = 0; Index < 4096; Index++) {
577 Sd->mCTable[Index] = CharC;
578 }
579
580 return ;
581 }
582
583 Index = 0;
584 while (Index < Number) {
585
586 CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
587 if (CharC >= NT) {
588 Mask = 1U << (BITBUFSIZ - 1 - 8);
589
590 do {
591
592 if (Mask & Sd->mBitBuf) {
593 CharC = Sd->mRight[CharC];
594 } else {
595 CharC = Sd->mLeft[CharC];
596 }
597
598 Mask >>= 1;
599
600 } while (CharC >= NT);
601 }
602 //
603 // Advance what we have read
604 //
605 FillBuf (Sd, Sd->mPTLen[CharC]);
606
607 if (CharC <= 2) {
608
609 if (CharC == 0) {
610 CharC = 1;
611 } else if (CharC == 1) {
612 CharC = (UINT16) (GetBits (Sd, 4) + 3);
613 } else if (CharC == 2) {
614 CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
615 }
616
617 while ((INT16) (--CharC) >= 0) {
618 Sd->mCLen[Index++] = 0;
619 }
620
621 } else {
622
623 Sd->mCLen[Index++] = (UINT8) (CharC - 2);
624
625 }
626 }
627
628 while (Index < NC) {
629 Sd->mCLen[Index++] = 0;
630 }
631
632 MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
633
634 return ;
635 }
636
637 STATIC
638 UINT16
639 DecodeC (
640 SCRATCH_DATA *Sd
641 )
642 /*++
643
644 Routine Description:
645
646 Decode a character/length value.
647
648 Arguments:
649
650 Sd - The global scratch data.
651
652 Returns:
653
654 The value decoded.
655
656 --*/
657 {
658 UINT16 Index2;
659 UINT32 Mask;
660
661 if (Sd->mBlockSize == 0) {
662 //
663 // Starting a new block
664 //
665 Sd->mBlockSize = (UINT16) GetBits (Sd, 16);
666 Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
667 if (Sd->mBadTableFlag != 0) {
668 return 0;
669 }
670
671 ReadCLen (Sd);
672
673 Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));
674 if (Sd->mBadTableFlag != 0) {
675 return 0;
676 }
677 }
678
679 Sd->mBlockSize--;
680 Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
681
682 if (Index2 >= NC) {
683 Mask = 1U << (BITBUFSIZ - 1 - 12);
684
685 do {
686 if (Sd->mBitBuf & Mask) {
687 Index2 = Sd->mRight[Index2];
688 } else {
689 Index2 = Sd->mLeft[Index2];
690 }
691
692 Mask >>= 1;
693 } while (Index2 >= NC);
694 }
695 //
696 // Advance what we have read
697 //
698 FillBuf (Sd, Sd->mCLen[Index2]);
699
700 return Index2;
701 }
702
703 STATIC
704 VOID
705 Decode (
706 SCRATCH_DATA *Sd
707 )
708 /*++
709
710 Routine Description:
711
712 Decode the source data and put the resulting data into the destination buffer.
713
714 Arguments:
715
716 Sd - The global scratch data
717
718 Returns: (VOID)
719
720 --*/
721 {
722 UINT16 BytesRemain;
723 UINT32 DataIdx;
724 UINT16 CharC;
725
726 BytesRemain = (UINT16) (-1);
727
728 DataIdx = 0;
729
730 for (;;) {
731 CharC = DecodeC (Sd);
732 if (Sd->mBadTableFlag != 0) {
733 return ;
734 }
735
736 if (CharC < 256) {
737 //
738 // Process an Original character
739 //
740 if (Sd->mOutBuf >= Sd->mOrigSize) {
741 return ;
742 } else {
743 Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
744 }
745
746 } else {
747 //
748 // Process a Pointer
749 //
750 CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));
751
752 BytesRemain = CharC;
753
754 DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;
755
756 BytesRemain--;
757 while ((INT16) (BytesRemain) >= 0) {
758 Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
759 if (Sd->mOutBuf >= Sd->mOrigSize) {
760 return ;
761 }
762
763 BytesRemain--;
764 }
765 }
766 }
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 }