]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.c
MdePkg/UefiDebugLibDebugPortProtocol: Add destructor to CloseEvent
[mirror_edk2.git] / MdePkg / Library / BaseUefiDecompressLib / BaseUefiTianoCustomDecompressLib.c
CommitLineData
3f0055c8
DB
1/** @file\r
2 UEFI Decompress Library implementation refer to UEFI specification.\r
3\r
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8**/\r
9\r
10#include <PiPei.h>\r
11#include <Library/ExtractGuidedSectionLib.h>\r
12#include "BaseUefiDecompressLibInternals.h"\r
13\r
14/**\r
15 Examines a GUIDed section and returns the size of the decoded buffer and the\r
16 size of an optional scratch buffer required to actually decode the data in a GUIDed section.\r
17\r
18 Examines a GUIDed section specified by InputSection.\r
19 If GUID for InputSection does not match the GUID that this handler supports,\r
20 then RETURN_UNSUPPORTED is returned.\r
21 If the required information can not be retrieved from InputSection,\r
22 then RETURN_INVALID_PARAMETER is returned.\r
23 If the GUID of InputSection does match the GUID that this handler supports,\r
24 then the size required to hold the decoded buffer is returned in OututBufferSize,\r
25 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
26 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
27\r
28 If InputSection is NULL, then ASSERT().\r
29 If OutputBufferSize is NULL, then ASSERT().\r
30 If ScratchBufferSize is NULL, then ASSERT().\r
31 If SectionAttribute is NULL, then ASSERT().\r
32\r
33\r
34 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
35 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required\r
36 if the buffer specified by InputSection were decoded.\r
37 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space\r
38 if the buffer specified by InputSection were decoded.\r
39 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes\r
40 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
41\r
42 @retval RETURN_SUCCESS The information about InputSection was returned.\r
43 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
44 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.\r
45\r
46**/\r
47RETURN_STATUS\r
48EFIAPI\r
49TianoDecompressGetInfo (\r
50 IN CONST VOID *InputSection,\r
51 OUT UINT32 *OutputBufferSize,\r
52 OUT UINT32 *ScratchBufferSize,\r
53 OUT UINT16 *SectionAttribute\r
54 )\r
55\r
56{\r
57 ASSERT (SectionAttribute != NULL);\r
58\r
59 if (InputSection == NULL) {\r
60 return RETURN_INVALID_PARAMETER;\r
61 }\r
62\r
63 if (IS_SECTION2 (InputSection)) {\r
64 if (!CompareGuid (\r
65 &gTianoCustomDecompressGuid,\r
66 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
67 return RETURN_INVALID_PARAMETER;\r
68 }\r
69 //\r
70 // Get guid attribute of guid section.\r
71 //\r
72 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
73\r
74 //\r
75 // Call Tiano GetInfo to get the required size info.\r
76 //\r
77 return UefiDecompressGetInfo (\r
78 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
79 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
80 OutputBufferSize,\r
81 ScratchBufferSize\r
82 );\r
83 } else {\r
84 if (!CompareGuid (\r
85 &gTianoCustomDecompressGuid,\r
86 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
87 return RETURN_INVALID_PARAMETER;\r
88 }\r
89 //\r
90 // Get guid attribute of guid section.\r
91 //\r
92 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
93\r
94 //\r
95 // Call Tiano GetInfo to get the required size info.\r
96 //\r
97 return UefiDecompressGetInfo (\r
98 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
99 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
100 OutputBufferSize,\r
101 ScratchBufferSize\r
102 );\r
103 }\r
104}\r
105\r
106/**\r
107 Decompress a Tiano compressed GUIDed section into a caller allocated output buffer.\r
108\r
109 Decodes the GUIDed section specified by InputSection.\r
110 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.\r
111 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
112 If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
113 is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
114 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the\r
115 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,\r
116 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
117\r
118 If InputSection is NULL, then ASSERT().\r
119 If OutputBuffer is NULL, then ASSERT().\r
120 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
121 If AuthenticationStatus is NULL, then ASSERT().\r
122\r
123\r
124 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
125 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r
126 @param[in] ScratchBuffer A caller allocated buffer that may be required by this function\r
127 as a scratch buffer to perform the decode operation.\r
128 @param[out] AuthenticationStatus\r
129 A pointer to the authentication status of the decoded output buffer.\r
130 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
131 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
132 never be set by this handler.\r
133\r
134 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
135 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
136 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
137\r
138**/\r
139RETURN_STATUS\r
140EFIAPI\r
141TianoDecompress (\r
142 IN CONST VOID *InputSection,\r
143 OUT VOID **OutputBuffer,\r
144 IN VOID *ScratchBuffer, OPTIONAL\r
145 OUT UINT32 *AuthenticationStatus\r
146 )\r
147{\r
148 ASSERT (OutputBuffer != NULL);\r
149 ASSERT (InputSection != NULL);\r
150\r
151 if (IS_SECTION2 (InputSection)) {\r
152 if (!CompareGuid (\r
153 &gTianoCustomDecompressGuid,\r
154 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
155 return RETURN_INVALID_PARAMETER;\r
156 }\r
157\r
158 //\r
159 // Set Authentication to Zero.\r
160 //\r
161 *AuthenticationStatus = 0;\r
162\r
163 //\r
164 // Call Tiano Decompress to get the raw data\r
165 //\r
166 return UefiTianoDecompress (\r
167 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
168 *OutputBuffer,\r
169 ScratchBuffer,\r
170 2\r
171 );\r
172 } else {\r
173 if (!CompareGuid (\r
174 &gTianoCustomDecompressGuid,\r
175 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
176 return RETURN_INVALID_PARAMETER;\r
177 }\r
178\r
179 //\r
180 // Set Authentication to Zero.\r
181 //\r
182 *AuthenticationStatus = 0;\r
183\r
184 //\r
185 // Call Tiano Decompress to get the raw data\r
186 //\r
187 return UefiTianoDecompress (\r
188 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
189 *OutputBuffer,\r
190 ScratchBuffer,\r
191 2\r
192 );\r
193 }\r
194}\r
195\r
196/**\r
197 Registers TianoDecompress and TianoDecompressGetInfo handlers with TianoCustomerDecompressGuid\r
198\r
199 @retval RETURN_SUCCESS Register successfully.\r
200 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.\r
201**/\r
202RETURN_STATUS\r
203EFIAPI\r
204TianoDecompressLibConstructor (\r
205 VOID\r
206)\r
207{\r
208 return ExtractGuidedSectionRegisterHandlers (\r
209 &gTianoCustomDecompressGuid,\r
210 TianoDecompressGetInfo,\r
211 TianoDecompress\r
212 );\r
213}\r