]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVol / FwVolDriver.h
CommitLineData
162ed594 1/** @file\r
797a9d67 2 Firmware File System protocol. Layers on top of Firmware\r
3 Block protocol to produce a file abstraction of FV based files.\r
23c98c94 4\r
eb1cace2 5Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
28a00297 7\r
797a9d67 8**/\r
28a00297 9\r
162ed594 10#ifndef __FW_VOL_DRIVER_H_\r
11#define __FW_VOL_DRIVER_H_\r
28a00297 12\r
1436aea4 13#define FV2_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '2')\r
0c2b5da8 14\r
28a00297 15//\r
16// Used to track all non-deleted files\r
17//\r
18typedef struct {\r
1436aea4
MK
19 LIST_ENTRY Link;\r
20 EFI_FFS_FILE_HEADER *FfsHeader;\r
21 UINTN StreamHandle;\r
22 BOOLEAN FileCached;\r
28a00297 23} FFS_FILE_LIST_ENTRY;\r
24\r
25typedef struct {\r
1436aea4
MK
26 UINTN Signature;\r
27 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r
28 EFI_HANDLE Handle;\r
29 EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;\r
28a00297 30\r
1436aea4
MK
31 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
32 UINT8 *CachedFv;\r
33 UINT8 *EndOfCachedFv;\r
28a00297 34\r
1436aea4 35 FFS_FILE_LIST_ENTRY *LastKey;\r
28a00297 36\r
1436aea4 37 LIST_ENTRY FfsFileListHeader;\r
28a00297 38\r
1436aea4
MK
39 UINT32 AuthenticationStatus;\r
40 UINT8 ErasePolarity;\r
41 BOOLEAN IsFfs3Fv;\r
42 BOOLEAN IsMemoryMapped;\r
28a00297 43} FV_DEVICE;\r
44\r
1436aea4 45#define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)\r
28a00297 46\r
162ed594 47/**\r
48 Retrieves attributes, insures positive polarity of attribute bits, returns\r
49 resulting attributes in output parameter.\r
28a00297 50\r
13492369 51 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
52 @param Attributes output buffer which contains attributes.\r
162ed594 53\r
13492369 54 @retval EFI_SUCCESS Successfully got volume attributes.\r
162ed594 55\r
56**/\r
28a00297 57EFI_STATUS\r
58EFIAPI\r
59FvGetVolumeAttributes (\r
1436aea4
MK
60 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
61 OUT EFI_FV_ATTRIBUTES *Attributes\r
23c98c94 62 );\r
28a00297 63\r
162ed594 64/**\r
65 Sets current attributes for volume\r
28a00297 66\r
13492369 67 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 68 @param Attributes At input, contains attributes to be set. At output\r
13492369 69 contains new value of FV.\r
28a00297 70\r
162ed594 71 @retval EFI_UNSUPPORTED Could not be set.\r
28a00297 72\r
162ed594 73**/\r
28a00297 74EFI_STATUS\r
75EFIAPI\r
76FvSetVolumeAttributes (\r
23c98c94 77 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
78 IN OUT EFI_FV_ATTRIBUTES *Attributes\r
79 );\r
28a00297 80\r
162ed594 81/**\r
82 Given the input key, search for the next matching file in the volume.\r
83\r
13492369 84 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 85 @param Key Key is a pointer to a caller allocated\r
86 buffer that contains implementation specific\r
87 data that is used to track where to begin\r
88 the search for the next file. The size of\r
89 the buffer must be at least This->KeySize\r
90 bytes long. To reinitialize the search and\r
91 begin from the beginning of the firmware\r
92 volume, the entire buffer must be cleared to\r
93 zero. Other than clearing the buffer to\r
94 initiate a new search, the caller must not\r
95 modify the data in the buffer between calls\r
96 to GetNextFile().\r
97 @param FileType FileType is a pointer to a caller allocated\r
98 EFI_FV_FILETYPE. The GetNextFile() API can\r
99 filter it's search for files based on the\r
100 value of *FileType input. A *FileType input\r
101 of 0 causes GetNextFile() to search for\r
102 files of all types. If a file is found, the\r
103 file's type is returned in *FileType.\r
104 *FileType is not modified if no file is\r
105 found.\r
106 @param NameGuid NameGuid is a pointer to a caller allocated\r
107 EFI_GUID. If a file is found, the file's\r
108 name is returned in *NameGuid. *NameGuid is\r
109 not modified if no file is found.\r
110 @param Attributes Attributes is a pointer to a caller\r
111 allocated EFI_FV_FILE_ATTRIBUTES. If a file\r
112 is found, the file's attributes are returned\r
113 in *Attributes. *Attributes is not modified\r
114 if no file is found.\r
115 @param Size Size is a pointer to a caller allocated\r
116 UINTN. If a file is found, the file's size\r
117 is returned in *Size. *Size is not modified\r
118 if no file is found.\r
119\r
120 @retval EFI_SUCCESS Successfully find the file.\r
121 @retval EFI_DEVICE_ERROR Device error.\r
122 @retval EFI_ACCESS_DENIED Fv could not read.\r
123 @retval EFI_NOT_FOUND No matching file found.\r
162ed594 124 @retval EFI_INVALID_PARAMETER Invalid parameter\r
28a00297 125\r
162ed594 126**/\r
28a00297 127EFI_STATUS\r
128EFIAPI\r
129FvGetNextFile (\r
1436aea4
MK
130 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
131 IN OUT VOID *Key,\r
132 IN OUT EFI_FV_FILETYPE *FileType,\r
133 OUT EFI_GUID *NameGuid,\r
134 OUT EFI_FV_FILE_ATTRIBUTES *Attributes,\r
135 OUT UINTN *Size\r
23c98c94 136 );\r
28a00297 137\r
162ed594 138/**\r
139 Locates a file in the firmware volume and\r
140 copies it to the supplied buffer.\r
141\r
13492369 142 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 143 @param NameGuid Pointer to an EFI_GUID, which is the\r
144 filename.\r
145 @param Buffer Buffer is a pointer to pointer to a buffer\r
146 in which the file or section contents or are\r
147 returned.\r
148 @param BufferSize BufferSize is a pointer to caller allocated\r
149 UINTN. On input *BufferSize indicates the\r
150 size in bytes of the memory region pointed\r
151 to by Buffer. On output, *BufferSize\r
152 contains the number of bytes required to\r
153 read the file.\r
154 @param FoundType FoundType is a pointer to a caller allocated\r
155 EFI_FV_FILETYPE that on successful return\r
156 from Read() contains the type of file read.\r
157 This output reflects the file type\r
158 irrespective of the value of the SectionType\r
159 input.\r
160 @param FileAttributes FileAttributes is a pointer to a caller\r
161 allocated EFI_FV_FILE_ATTRIBUTES. On\r
162 successful return from Read(),\r
163 *FileAttributes contains the attributes of\r
164 the file read.\r
165 @param AuthenticationStatus AuthenticationStatus is a pointer to a\r
166 caller allocated UINTN in which the\r
167 authentication status is returned.\r
168\r
169 @retval EFI_SUCCESS Successfully read to memory buffer.\r
170 @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small.\r
171 @retval EFI_NOT_FOUND Not found.\r
172 @retval EFI_DEVICE_ERROR Device error.\r
173 @retval EFI_ACCESS_DENIED Could not read.\r
174 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
162ed594 175 @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated.\r
176\r
177**/\r
28a00297 178EFI_STATUS\r
179EFIAPI\r
180FvReadFile (\r
1436aea4
MK
181 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
182 IN CONST EFI_GUID *NameGuid,\r
183 IN OUT VOID **Buffer,\r
184 IN OUT UINTN *BufferSize,\r
185 OUT EFI_FV_FILETYPE *FoundType,\r
186 OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,\r
187 OUT UINT32 *AuthenticationStatus\r
23c98c94 188 );\r
28a00297 189\r
162ed594 190/**\r
191 Locates a section in a given FFS File and\r
192 copies it to the supplied buffer (not including section header).\r
193\r
13492369 194 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 195 @param NameGuid Pointer to an EFI_GUID, which is the\r
196 filename.\r
197 @param SectionType Indicates the section type to return.\r
198 @param SectionInstance Indicates which instance of sections with a\r
199 type of SectionType to return.\r
200 @param Buffer Buffer is a pointer to pointer to a buffer\r
201 in which the file or section contents or are\r
202 returned.\r
203 @param BufferSize BufferSize is a pointer to caller allocated\r
162ed594 204 UINTN.\r
022c6d45 205 @param AuthenticationStatus AuthenticationStatus is a pointer to a\r
206 caller allocated UINT32 in which the\r
207 authentication status is returned.\r
208\r
209 @retval EFI_SUCCESS Successfully read the file section into\r
210 buffer.\r
211 @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small.\r
212 @retval EFI_NOT_FOUND Section not found.\r
213 @retval EFI_DEVICE_ERROR Device error.\r
214 @retval EFI_ACCESS_DENIED Could not read.\r
162ed594 215 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
216\r
217**/\r
28a00297 218EFI_STATUS\r
219EFIAPI\r
220FvReadFileSection (\r
23c98c94 221 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
0c2b5da8 222 IN CONST EFI_GUID *NameGuid,\r
223 IN EFI_SECTION_TYPE SectionType,\r
224 IN UINTN SectionInstance,\r
225 IN OUT VOID **Buffer,\r
226 IN OUT UINTN *BufferSize,\r
227 OUT UINT32 *AuthenticationStatus\r
23c98c94 228 );\r
28a00297 229\r
162ed594 230/**\r
231 Writes one or more files to the firmware volume.\r
232\r
13492369 233 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 234 @param NumberOfFiles Number of files.\r
235 @param WritePolicy WritePolicy indicates the level of reliability\r
236 for the write in the event of a power failure or\r
237 other system failure during the write operation.\r
238 @param FileData FileData is an pointer to an array of\r
162ed594 239 EFI_FV_WRITE_DATA. Each element of array\r
022c6d45 240 FileData represents a file to be written.\r
241\r
242 @retval EFI_SUCCESS Files successfully written to firmware volume\r
243 @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated.\r
244 @retval EFI_DEVICE_ERROR Device error.\r
245 @retval EFI_WRITE_PROTECTED Write protected.\r
246 @retval EFI_NOT_FOUND Not found.\r
247 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
162ed594 248 @retval EFI_UNSUPPORTED This function not supported.\r
249\r
250**/\r
28a00297 251EFI_STATUS\r
252EFIAPI\r
253FvWriteFile (\r
23c98c94 254 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
255 IN UINT32 NumberOfFiles,\r
256 IN EFI_FV_WRITE_POLICY WritePolicy,\r
257 IN EFI_FV_WRITE_FILE_DATA *FileData\r
258 );\r
28a00297 259\r
162ed594 260/**\r
261 Return information of type InformationType for the requested firmware\r
262 volume.\r
263\r
022c6d45 264 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
265 @param InformationType InformationType for requested.\r
266 @param BufferSize On input, size of Buffer.On output, the amount of data\r
267 returned in Buffer.\r
268 @param Buffer A poniter to the data buffer to return.\r
162ed594 269\r
270 @retval EFI_SUCCESS Successfully got volume Information.\r
271\r
272**/\r
0c2b5da8 273EFI_STATUS\r
274EFIAPI\r
275FvGetVolumeInfo (\r
1436aea4
MK
276 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
277 IN CONST EFI_GUID *InformationType,\r
278 IN OUT UINTN *BufferSize,\r
279 OUT VOID *Buffer\r
23c98c94 280 );\r
0c2b5da8 281\r
162ed594 282/**\r
283 Set information of type InformationType for the requested firmware\r
0c2b5da8 284 volume.\r
0c2b5da8 285\r
022c6d45 286 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
287 @param InformationType InformationType for requested.\r
288 @param BufferSize On input, size of Buffer.On output, the amount of data\r
289 returned in Buffer.\r
290 @param Buffer A poniter to the data buffer to return.\r
162ed594 291\r
292 @retval EFI_SUCCESS Successfully set volume Information.\r
28a00297 293\r
162ed594 294**/\r
0c2b5da8 295EFI_STATUS\r
296EFIAPI\r
297FvSetVolumeInfo (\r
1436aea4
MK
298 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
299 IN CONST EFI_GUID *InformationType,\r
300 IN UINTN BufferSize,\r
301 IN CONST VOID *Buffer\r
23c98c94 302 );\r
022c6d45 303\r
162ed594 304/**\r
305 Check if a block of buffer is erased.\r
306\r
022c6d45 307 @param ErasePolarity Erase polarity attribute of the firmware volume\r
308 @param InBuffer The buffer to be checked\r
309 @param BufferSize Size of the buffer in bytes\r
162ed594 310\r
022c6d45 311 @retval TRUE The block of buffer is erased\r
162ed594 312 @retval FALSE The block of buffer is not erased\r
313\r
314**/\r
28a00297 315BOOLEAN\r
316IsBufferErased (\r
1436aea4
MK
317 IN UINT8 ErasePolarity,\r
318 IN VOID *InBuffer,\r
319 IN UINTN BufferSize\r
23c98c94 320 );\r
28a00297 321\r
162ed594 322/**\r
323 Get the FFS file state by checking the highest bit set in the header's state field.\r
28a00297 324\r
022c6d45 325 @param ErasePolarity Erase polarity attribute of the firmware volume\r
326 @param FfsHeader Points to the FFS file header\r
162ed594 327\r
328 @return FFS File state\r
329\r
330**/\r
23c98c94 331EFI_FFS_FILE_STATE\r
28a00297 332GetFileState (\r
333 IN UINT8 ErasePolarity,\r
334 IN EFI_FFS_FILE_HEADER *FfsHeader\r
23c98c94 335 );\r
28a00297 336\r
162ed594 337/**\r
338 Set the FFS file state.\r
339\r
022c6d45 340 @param State The state to be set.\r
341 @param FfsHeader Points to the FFS file header\r
162ed594 342\r
343 @return None.\r
28a00297 344\r
162ed594 345**/\r
28a00297 346VOID\r
347SetFileState (\r
348 IN UINT8 State,\r
349 IN EFI_FFS_FILE_HEADER *FfsHeader\r
23c98c94 350 );\r
28a00297 351\r
162ed594 352/**\r
353 Check if it's a valid FFS file header.\r
354\r
022c6d45 355 @param ErasePolarity Erase polarity attribute of the firmware volume\r
356 @param FfsHeader Points to the FFS file header to be checked\r
357 @param FileState FFS file state to be returned\r
162ed594 358\r
022c6d45 359 @retval TRUE Valid FFS file header\r
162ed594 360 @retval FALSE Invalid FFS file header\r
361\r
362**/\r
28a00297 363BOOLEAN\r
364IsValidFfsHeader (\r
23c98c94 365 IN UINT8 ErasePolarity,\r
366 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
367 OUT EFI_FFS_FILE_STATE *FileState\r
368 );\r
28a00297 369\r
162ed594 370/**\r
371 Check if it's a valid FFS file.\r
372 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.\r
373\r
022c6d45 374 @param ErasePolarity Erase polarity attribute of the firmware volume\r
375 @param FfsHeader Points to the FFS file to be checked\r
28a00297 376\r
022c6d45 377 @retval TRUE Valid FFS file\r
162ed594 378 @retval FALSE Invalid FFS file\r
379\r
380**/\r
28a00297 381BOOLEAN\r
382IsValidFfsFile (\r
383 IN UINT8 ErasePolarity,\r
384 IN EFI_FFS_FILE_HEADER *FfsHeader\r
23c98c94 385 );\r
28a00297 386\r
28a00297 387#endif\r