]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Library / BrotliCustomDecompressLib / GuidedSectionExtraction.c
CommitLineData
841b2590
SB
1/** @file\r
2 BROTLI Decompress GUIDed Section Extraction Library.\r
3 It wraps Brotli decompress interfaces to GUIDed Section Extraction interfaces\r
4 and registers them into GUIDed handler table.\r
5\r
6 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
9d510e61 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
841b2590
SB
8\r
9**/\r
10\r
11#include <BrotliDecompressLibInternal.h>\r
12\r
13/**\r
14 Examines a GUIDed section and returns the size of the decoded buffer and the\r
15 size of an scratch buffer required to actually decode the data in a GUIDed section.\r
16\r
17 Examines a GUIDed section specified by InputSection.\r
18 If GUID for InputSection does not match the GUID that this handler supports,\r
19 then RETURN_UNSUPPORTED is returned.\r
20 If the required information can not be retrieved from InputSection,\r
21 then RETURN_INVALID_PARAMETER is returned.\r
22 If the GUID of InputSection does match the GUID that this handler supports,\r
23 then the size required to hold the decoded buffer is returned in OututBufferSize,\r
24 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
25 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
26\r
27 If InputSection is NULL, then ASSERT().\r
28 If OutputBufferSize is NULL, then ASSERT().\r
29 If ScratchBufferSize is NULL, then ASSERT().\r
30 If SectionAttribute is NULL, then ASSERT().\r
31\r
32\r
33 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
34 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required\r
35 if the buffer specified by InputSection were decoded.\r
36 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space\r
37 if the buffer specified by InputSection were decoded.\r
38 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes\r
39 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
40\r
41 @retval RETURN_SUCCESS The information about InputSection was returned.\r
42 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
43 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.\r
44\r
45**/\r
46RETURN_STATUS\r
47EFIAPI\r
48BrotliGuidedSectionGetInfo (\r
49 IN CONST VOID *InputSection,\r
50 OUT UINT32 *OutputBufferSize,\r
51 OUT UINT32 *ScratchBufferSize,\r
52 OUT UINT16 *SectionAttribute\r
53 )\r
54{\r
55 ASSERT (InputSection != NULL);\r
56 ASSERT (OutputBufferSize != NULL);\r
57 ASSERT (ScratchBufferSize != NULL);\r
58 ASSERT (SectionAttribute != NULL);\r
59\r
60 if (IS_SECTION2 (InputSection)) {\r
61 if (!CompareGuid (\r
1436aea4
MK
62 &gBrotliCustomDecompressGuid,\r
63 &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)\r
64 ))\r
65 {\r
841b2590
SB
66 return RETURN_INVALID_PARAMETER;\r
67 }\r
68\r
1436aea4 69 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->Attributes;\r
841b2590
SB
70\r
71 return BrotliUefiDecompressGetInfo (\r
1436aea4
MK
72 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
73 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
841b2590
SB
74 OutputBufferSize,\r
75 ScratchBufferSize\r
76 );\r
77 } else {\r
78 if (!CompareGuid (\r
1436aea4
MK
79 &gBrotliCustomDecompressGuid,\r
80 &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)\r
81 ))\r
82 {\r
841b2590
SB
83 return RETURN_INVALID_PARAMETER;\r
84 }\r
85\r
1436aea4 86 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *)InputSection)->Attributes;\r
841b2590
SB
87\r
88 return BrotliUefiDecompressGetInfo (\r
1436aea4
MK
89 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
90 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
841b2590
SB
91 OutputBufferSize,\r
92 ScratchBufferSize\r
93 );\r
94 }\r
95}\r
96\r
97/**\r
98 Decompress a BROTLI compressed GUIDed section into a caller allocated output buffer.\r
99\r
100 Decodes the GUIDed section specified by InputSection.\r
101 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.\r
102 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
103 If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
104 is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
105 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the\r
106 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,\r
107 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
108\r
109 If InputSection is NULL, then ASSERT().\r
110 If OutputBuffer is NULL, then ASSERT().\r
111 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
112 If AuthenticationStatus is NULL, then ASSERT().\r
113\r
114 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
115 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r
116 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
117 as a scratch buffer to perform the decode operation.\r
118 @param[out] AuthenticationStatus\r
119 A pointer to the authentication status of the decoded output buffer.\r
120 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
121 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
122 never be set by this handler.\r
123\r
124 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
125 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
126 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
127\r
128**/\r
129RETURN_STATUS\r
130EFIAPI\r
131BrotliGuidedSectionExtraction (\r
132 IN CONST VOID *InputSection,\r
133 OUT VOID **OutputBuffer,\r
e3917e22 134 OUT VOID *ScratchBuffer OPTIONAL,\r
841b2590
SB
135 OUT UINT32 *AuthenticationStatus\r
136 )\r
137{\r
138 ASSERT (OutputBuffer != NULL);\r
139 ASSERT (InputSection != NULL);\r
140\r
141 if (IS_SECTION2 (InputSection)) {\r
142 if (!CompareGuid (\r
1436aea4
MK
143 &gBrotliCustomDecompressGuid,\r
144 &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid)\r
145 ))\r
146 {\r
841b2590
SB
147 return RETURN_INVALID_PARAMETER;\r
148 }\r
1436aea4 149\r
841b2590
SB
150 //\r
151 // Authentication is set to Zero, which may be ignored.\r
152 //\r
153 *AuthenticationStatus = 0;\r
154\r
155 return BrotliUefiDecompress (\r
1436aea4
MK
156 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
157 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *)InputSection)->DataOffset,\r
841b2590
SB
158 *OutputBuffer,\r
159 ScratchBuffer\r
160 );\r
161 } else {\r
162 if (!CompareGuid (\r
1436aea4
MK
163 &gBrotliCustomDecompressGuid,\r
164 &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid)\r
165 ))\r
166 {\r
841b2590
SB
167 return RETURN_INVALID_PARAMETER;\r
168 }\r
1436aea4 169\r
841b2590
SB
170 //\r
171 // Authentication is set to Zero, which may be ignored.\r
172 //\r
173 *AuthenticationStatus = 0;\r
174\r
175 return BrotliUefiDecompress (\r
1436aea4
MK
176 (UINT8 *)InputSection + ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
177 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *)InputSection)->DataOffset,\r
841b2590
SB
178 *OutputBuffer,\r
179 ScratchBuffer\r
1436aea4 180 );\r
841b2590
SB
181 }\r
182}\r
183\r
184/**\r
185 Register BrotliDecompress and BrotliDecompressGetInfo handlers with BrotliCustomerDecompressGuid.\r
186\r
187 @retval EFI_SUCCESS Register successfully.\r
188 @retval EFI_OUT_OF_RESOURCES No enough memory to store this handler.\r
189**/\r
190EFI_STATUS\r
191EFIAPI\r
192BrotliDecompressLibConstructor (\r
f826516d 193 VOID\r
841b2590
SB
194 )\r
195{\r
196 return ExtractGuidedSectionRegisterHandlers (\r
1436aea4
MK
197 &gBrotliCustomDecompressGuid,\r
198 BrotliGuidedSectionGetInfo,\r
199 BrotliGuidedSectionExtraction\r
200 );\r
841b2590 201}\r