]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Protocol/FirmwareVolumeBlock.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Include / Protocol / FirmwareVolumeBlock.h
CommitLineData
d1f95000 1/** @file\r
2 This file provides control over block-oriented firmware devices.\r
3\r
9095d37b 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
d1f95000 6\r
d1f95000 7 @par Revision Reference: PI\r
5bd46269 8 Version 1.0 and 1.2.\r
d1f95000 9\r
10**/\r
11\r
12#ifndef __FIRMWARE_VOLUME_BLOCK_H__\r
13#define __FIRMWARE_VOLUME_BLOCK_H__\r
14\r
5bd46269 15//\r
16// EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL is defined in PI 1.0 spec and its GUID value\r
17// is later updated to be the same as that of EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL\r
9095d37b 18// defined in PI 1.2 spec.\r
5bd46269 19//\r
d1f95000 20#define EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID \\r
5bd46269 21 { 0x8f644fa9, 0xe850, 0x4db1, {0x9c, 0xe2, 0xb, 0x44, 0x69, 0x8e, 0x8d, 0xa4 } }\r
d1f95000 22\r
5bd46269 23#define EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL_GUID \\r
24 { 0x8f644fa9, 0xe850, 0x4db1, {0x9c, 0xe2, 0xb, 0x44, 0x69, 0x8e, 0x8d, 0xa4 } }\r
d1f95000 25\r
26typedef struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL;\r
27\r
9095d37b 28typedef EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL;\r
5bd46269 29\r
d1f95000 30/**\r
31 The GetAttributes() function retrieves the attributes and\r
5209f2a9 32 current settings of the block.\r
d1f95000 33\r
5bd46269 34 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
d1f95000 35\r
4ba967e7 36 @param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the\r
d1f95000 37 attributes and current settings are\r
4ba967e7 38 returned. Type EFI_FVB_ATTRIBUTES_2 is defined\r
d1f95000 39 in EFI_FIRMWARE_VOLUME_HEADER.\r
40\r
41 @retval EFI_SUCCESS The firmware volume attributes were\r
42 returned.\r
43\r
44**/\r
45typedef\r
46EFI_STATUS\r
8b13229b 47(EFIAPI * EFI_FVB_GET_ATTRIBUTES)(\r
5bd46269 48 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
4ba967e7 49 OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r
d1f95000 50);\r
51\r
52\r
53/**\r
54 The SetAttributes() function sets configurable firmware volume\r
55 attributes and returns the new settings of the firmware volume.\r
56\r
5bd46269 57 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
d1f95000 58\r
59 @param Attributes On input, Attributes is a pointer to\r
4ba967e7 60 EFI_FVB_ATTRIBUTES_2 that contains the\r
d1f95000 61 desired firmware volume settings. On\r
62 successful return, it contains the new\r
63 settings of the firmware volume. Type\r
4ba967e7 64 EFI_FVB_ATTRIBUTES_2 is defined in\r
d1f95000 65 EFI_FIRMWARE_VOLUME_HEADER.\r
9095d37b 66\r
4ca9b6c4 67 @retval EFI_SUCCESS The firmware volume attributes were returned.\r
d1f95000 68\r
69 @retval EFI_INVALID_PARAMETER The attributes requested are in\r
70 conflict with the capabilities\r
71 as declared in the firmware\r
72 volume header.\r
73\r
74**/\r
75typedef\r
76EFI_STATUS\r
8b13229b 77(EFIAPI * EFI_FVB_SET_ATTRIBUTES)(\r
5bd46269 78 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
4ba967e7 79 IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r
d1f95000 80);\r
81\r
82\r
83/**\r
84 The GetPhysicalAddress() function retrieves the base address of\r
85 a memory-mapped firmware volume. This function should be called\r
86 only for memory-mapped firmware volumes.\r
87\r
5bd46269 88 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
9095d37b 89\r
d1f95000 90 @param Address Pointer to a caller-allocated\r
91 EFI_PHYSICAL_ADDRESS that, on successful\r
92 return from GetPhysicalAddress(), contains the\r
4ca9b6c4 93 base address of the firmware volume.\r
9095d37b 94\r
af2dc6a7 95 @retval EFI_SUCCESS The firmware volume base address was returned.\r
9095d37b 96\r
5fbfa2d0 97 @retval EFI_UNSUPPORTED The firmware volume is not memory mapped.\r
d1f95000 98\r
99**/\r
100typedef\r
101EFI_STATUS\r
8b13229b 102(EFIAPI * EFI_FVB_GET_PHYSICAL_ADDRESS)(\r
5bd46269 103 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
d1f95000 104 OUT EFI_PHYSICAL_ADDRESS *Address\r
105);\r
106\r
107/**\r
108 The GetBlockSize() function retrieves the size of the requested\r
109 block. It also returns the number of additional blocks with\r
110 the identical size. The GetBlockSize() function is used to\r
111 retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).\r
112\r
113\r
5bd46269 114 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
d1f95000 115\r
4ca9b6c4 116 @param Lba Indicates the block for which to return the size.\r
d1f95000 117\r
4ca9b6c4
LG
118 @param BlockSize Pointer to a caller-allocated UINTN in which\r
119 the size of the block is returned.\r
d1f95000 120\r
121 @param NumberOfBlocks Pointer to a caller-allocated UINTN in\r
122 which the number of consecutive blocks,\r
123 starting with Lba, is returned. All\r
124 blocks in this range have a size of\r
125 BlockSize.\r
126\r
9095d37b 127\r
af2dc6a7 128 @retval EFI_SUCCESS The firmware volume base address was returned.\r
9095d37b 129\r
4ca9b6c4 130 @retval EFI_INVALID_PARAMETER The requested LBA is out of range.\r
d1f95000 131\r
132**/\r
133typedef\r
134EFI_STATUS\r
8b13229b 135(EFIAPI * EFI_FVB_GET_BLOCK_SIZE)(\r
5bd46269 136 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
de339b9d 137 IN EFI_LBA Lba,\r
d1f95000 138 OUT UINTN *BlockSize,\r
139 OUT UINTN *NumberOfBlocks\r
140);\r
141\r
142\r
143/**\r
eecd469b
LG
144 Reads the specified number of bytes into a buffer from the specified block.\r
145\r
d1f95000 146 The Read() function reads the requested number of bytes from the\r
147 requested block and stores them in the provided buffer.\r
148 Implementations should be mindful that the firmware volume\r
149 might be in the ReadDisabled state. If it is in this state,\r
150 the Read() function must return the status code\r
151 EFI_ACCESS_DENIED without modifying the contents of the\r
152 buffer. The Read() function must also prevent spanning block\r
153 boundaries. If a read is requested that would span a block\r
154 boundary, the read must read up to the boundary but not\r
155 beyond. The output parameter NumBytes must be set to correctly\r
156 indicate the number of bytes actually read. The caller must be\r
157 aware that a read may be partially completed.\r
158\r
5bd46269 159 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
9095d37b 160\r
4ca9b6c4
LG
161 @param Lba The starting logical block index\r
162 from which to read.\r
d1f95000 163\r
4ca9b6c4 164 @param Offset Offset into the block at which to begin reading.\r
d1f95000 165\r
166 @param NumBytes Pointer to a UINTN. At entry, *NumBytes\r
167 contains the total size of the buffer. At\r
168 exit, *NumBytes contains the total number of\r
169 bytes read.\r
170\r
171 @param Buffer Pointer to a caller-allocated buffer that will\r
172 be used to hold the data that is read.\r
173\r
af2dc6a7 174 @retval EFI_SUCCESS The firmware volume was read successfully,\r
4ca9b6c4 175 and contents are in Buffer.\r
9095d37b 176\r
d1f95000 177 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA\r
178 boundary. On output, NumBytes\r
179 contains the total number of bytes\r
180 returned in Buffer.\r
9095d37b 181\r
d1f95000 182 @retval EFI_ACCESS_DENIED The firmware volume is in the\r
183 ReadDisabled state.\r
9095d37b 184\r
d1f95000 185 @retval EFI_DEVICE_ERROR The block device is not\r
186 functioning correctly and could\r
187 not be read.\r
188\r
189**/\r
190typedef\r
191EFI_STATUS\r
8b13229b 192(EFIAPI *EFI_FVB_READ)(\r
5bd46269 193 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
de339b9d 194 IN EFI_LBA Lba,\r
195 IN UINTN Offset,\r
d1f95000 196 IN OUT UINTN *NumBytes,\r
96219b7d 197 IN OUT UINT8 *Buffer\r
d1f95000 198);\r
199\r
d1f95000 200/**\r
eecd469b
LG
201 Writes the specified number of bytes from the input buffer to the block.\r
202\r
d1f95000 203 The Write() function writes the specified number of bytes from\r
204 the provided buffer to the specified block and offset. If the\r
205 firmware volume is sticky write, the caller must ensure that\r
206 all the bits of the specified range to write are in the\r
207 EFI_FVB_ERASE_POLARITY state before calling the Write()\r
208 function, or else the result will be unpredictable. This\r
209 unpredictability arises because, for a sticky-write firmware\r
210 volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY\r
af2dc6a7 211 state but cannot flip it back again. Before calling the\r
9095d37b 212 Write() function, it is recommended for the caller to first call\r
af2dc6a7 213 the EraseBlocks() function to erase the specified block to\r
d1f95000 214 write. A block erase cycle will transition bits from the\r
215 (NOT)EFI_FVB_ERASE_POLARITY state back to the\r
216 EFI_FVB_ERASE_POLARITY state. Implementations should be\r
217 mindful that the firmware volume might be in the WriteDisabled\r
218 state. If it is in this state, the Write() function must\r
219 return the status code EFI_ACCESS_DENIED without modifying the\r
220 contents of the firmware volume. The Write() function must\r
221 also prevent spanning block boundaries. If a write is\r
222 requested that spans a block boundary, the write must store up\r
223 to the boundary but not beyond. The output parameter NumBytes\r
224 must be set to correctly indicate the number of bytes actually\r
225 written. The caller must be aware that a write may be\r
226 partially completed. All writes, partial or otherwise, must be\r
227 fully flushed to the hardware before the Write() service\r
228 returns.\r
229\r
5bd46269 230 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r
9095d37b 231\r
4ca9b6c4 232 @param Lba The starting logical block index to write to.\r
9095d37b 233\r
4ca9b6c4 234 @param Offset Offset into the block at which to begin writing.\r
9095d37b 235\r
af2dc6a7 236 @param NumBytes The pointer to a UINTN. At entry, *NumBytes\r
d1f95000 237 contains the total size of the buffer. At\r
238 exit, *NumBytes contains the total number of\r
239 bytes actually written.\r
9095d37b 240\r
af2dc6a7 241 @param Buffer The pointer to a caller-allocated buffer that\r
4ca9b6c4 242 contains the source for the write.\r
9095d37b 243\r
4ca9b6c4 244 @retval EFI_SUCCESS The firmware volume was written successfully.\r
9095d37b 245\r
d1f95000 246 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an\r
247 LBA boundary. On output, NumBytes\r
248 contains the total number of bytes\r
249 actually written.\r
9095d37b 250\r
d1f95000 251 @retval EFI_ACCESS_DENIED The firmware volume is in the\r
252 WriteDisabled state.\r
9095d37b 253\r
d1f95000 254 @retval EFI_DEVICE_ERROR The block device is malfunctioning\r
255 and could not be written.\r
256\r
257\r
258**/\r
259typedef\r
260EFI_STATUS\r
8b13229b 261(EFIAPI * EFI_FVB_WRITE)(\r
5bd46269 262 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
de339b9d 263 IN EFI_LBA Lba,\r
264 IN UINTN Offset,\r
d1f95000 265 IN OUT UINTN *NumBytes,\r
85c528bd 266 IN UINT8 *Buffer\r
d1f95000 267);\r
268\r
269\r
270\r
271\r
a4e0b060 272///\r
273/// EFI_LBA_LIST_TERMINATOR\r
274///\r
d1f95000 275#define EFI_LBA_LIST_TERMINATOR 0xFFFFFFFFFFFFFFFFULL\r
276\r
277\r
278/**\r
eecd469b
LG
279 Erases and initializes a firmware volume block.\r
280\r
f754f721 281 The EraseBlocks() function erases one or more blocks as denoted\r
d1f95000 282 by the variable argument list. The entire parameter list of\r
283 blocks must be verified before erasing any blocks. If a block is\r
284 requested that does not exist within the associated firmware\r
285 volume (it has a larger index than the last block of the\r
286 firmware volume), the EraseBlocks() function must return the\r
287 status code EFI_INVALID_PARAMETER without modifying the contents\r
288 of the firmware volume. Implementations should be mindful that\r
289 the firmware volume might be in the WriteDisabled state. If it\r
290 is in this state, the EraseBlocks() function must return the\r
291 status code EFI_ACCESS_DENIED without modifying the contents of\r
292 the firmware volume. All calls to EraseBlocks() must be fully\r
293 flushed to the hardware before the EraseBlocks() service\r
294 returns.\r
295\r
5bd46269 296 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL\r
d1f95000 297 instance.\r
298\r
299 @param ... The variable argument list is a list of tuples.\r
300 Each tuple describes a range of LBAs to erase\r
301 and consists of the following:\r
302 - An EFI_LBA that indicates the starting LBA\r
303 - A UINTN that indicates the number of blocks to\r
af2dc6a7 304 erase.\r
d1f95000 305\r
306 The list is terminated with an\r
307 EFI_LBA_LIST_TERMINATOR. For example, the\r
308 following indicates that two ranges of blocks\r
309 (5-7 and 10-11) are to be erased: EraseBlocks\r
310 (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);\r
311\r
af2dc6a7 312 @retval EFI_SUCCESS The erase request successfully\r
d1f95000 313 completed.\r
9095d37b 314\r
d1f95000 315 @retval EFI_ACCESS_DENIED The firmware volume is in the\r
316 WriteDisabled state.\r
317 @retval EFI_DEVICE_ERROR The block device is not functioning\r
318 correctly and could not be written.\r
319 The firmware device may have been\r
320 partially erased.\r
321 @retval EFI_INVALID_PARAMETER One or more of the LBAs listed\r
322 in the variable argument list do\r
9095d37b 323 not exist in the firmware volume.\r
d1f95000 324\r
325**/\r
326typedef\r
327EFI_STATUS\r
8b13229b 328(EFIAPI * EFI_FVB_ERASE_BLOCKS)(\r
5bd46269 329 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r
d1f95000 330 ...\r
331);\r
332\r
44717a39 333///\r
334/// The Firmware Volume Block Protocol is the low-level interface\r
335/// to a firmware volume. File-level access to a firmware volume\r
336/// should not be done using the Firmware Volume Block Protocol.\r
337/// Normal access to a firmware volume must use the Firmware\r
338/// Volume Protocol. Typically, only the file system driver that\r
339/// produces the Firmware Volume Protocol will bind to the\r
340/// Firmware Volume Block Protocol.\r
341///\r
5bd46269 342struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL{\r
d1f95000 343 EFI_FVB_GET_ATTRIBUTES GetAttributes;\r
344 EFI_FVB_SET_ATTRIBUTES SetAttributes;\r
345 EFI_FVB_GET_PHYSICAL_ADDRESS GetPhysicalAddress;\r
346 EFI_FVB_GET_BLOCK_SIZE GetBlockSize;\r
347 EFI_FVB_READ Read;\r
348 EFI_FVB_WRITE Write;\r
349 EFI_FVB_ERASE_BLOCKS EraseBlocks;\r
a4e0b060 350 ///\r
af2dc6a7 351 /// The handle of the parent firmware volume.\r
9095d37b 352 ///\r
d1f95000 353 EFI_HANDLE ParentHandle;\r
354};\r
355\r
356\r
357extern EFI_GUID gEfiFirmwareVolumeBlockProtocolGuid;\r
5bd46269 358extern EFI_GUID gEfiFirmwareVolumeBlock2ProtocolGuid;\r
d1f95000 359\r
360#endif\r