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