2 This file provides control over block-oriented firmware devices.
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 @par Revision Reference: PI
18 #ifndef __FIRMWARE_VOLUME_BLOCK_H__
19 #define __FIRMWARE_VOLUME_BLOCK_H__
22 #define EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID \
23 { 0xDE28BC59, 0x6228, 0x41BD, {0xBD, 0xF6, 0xA3, 0xB9, 0xAD,0xB5, 0x8D, 0xA1 } }
26 typedef struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
;
29 The GetAttributes() function retrieves the attributes and
30 current settings of the block. Status Codes Returned
32 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
34 @param Attributes Pointer to EFI_FVB_ATTRIBUTES in which the
35 attributes and current settings are
36 returned. Type EFI_FVB_ATTRIBUTES is defined
37 in EFI_FIRMWARE_VOLUME_HEADER.
39 @retval EFI_SUCCESS The firmware volume attributes were
45 (EFIAPI
* EFI_FVB_GET_ATTRIBUTES
)(
46 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*This
,
47 OUT EFI_FVB_ATTRIBUTES
*Attributes
52 The SetAttributes() function sets configurable firmware volume
53 attributes and returns the new settings of the firmware volume.
55 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
57 @param Attributes On input, Attributes is a pointer to
58 EFI_FVB_ATTRIBUTES that contains the
59 desired firmware volume settings. On
60 successful return, it contains the new
61 settings of the firmware volume. Type
62 EFI_FVB_ATTRIBUTES is defined in
63 EFI_FIRMWARE_VOLUME_HEADER.
65 @retval EFI_SUCCESS The firmware volume attributes were returned.
67 @retval EFI_INVALID_PARAMETER The attributes requested are in
68 conflict with the capabilities
69 as declared in the firmware
75 (EFIAPI
* EFI_FVB_SET_ATTRIBUTES
)(
76 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*This
,
77 IN OUT EFI_FVB_ATTRIBUTES
*Attributes
82 The GetPhysicalAddress() function retrieves the base address of
83 a memory-mapped firmware volume. This function should be called
84 only for memory-mapped firmware volumes.
86 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
88 @param Address Pointer to a caller-allocated
89 EFI_PHYSICAL_ADDRESS that, on successful
90 return from GetPhysicalAddress(), contains the
91 base address of the firmware volume.
93 @retval EFI_SUCCESS The firmware volume base address is returned.
95 @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.
100 (EFIAPI
* EFI_FVB_GET_PHYSICAL_ADDRESS
)(
101 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*This
,
102 OUT EFI_PHYSICAL_ADDRESS
*Address
106 The GetBlockSize() function retrieves the size of the requested
107 block. It also returns the number of additional blocks with
108 the identical size. The GetBlockSize() function is used to
109 retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).
112 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
114 @param Lba Indicates the block for which to return the size.
116 @param BlockSize Pointer to a caller-allocated UINTN in which
117 the size of the block is returned.
119 @param NumberOfBlocks Pointer to a caller-allocated UINTN in
120 which the number of consecutive blocks,
121 starting with Lba, is returned. All
122 blocks in this range have a size of
126 @retval EFI_SUCCESS The firmware volume base address is returned.
128 @retval EFI_INVALID_PARAMETER The requested LBA is out of range.
133 (EFIAPI
* EFI_FVB_GET_BLOCK_SIZE
)(
134 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*This
,
136 OUT UINTN
*BlockSize
,
137 OUT UINTN
*NumberOfBlocks
142 The Read() function reads the requested number of bytes from the
143 requested block and stores them in the provided buffer.
144 Implementations should be mindful that the firmware volume
145 might be in the ReadDisabled state. If it is in this state,
146 the Read() function must return the status code
147 EFI_ACCESS_DENIED without modifying the contents of the
148 buffer. The Read() function must also prevent spanning block
149 boundaries. If a read is requested that would span a block
150 boundary, the read must read up to the boundary but not
151 beyond. The output parameter NumBytes must be set to correctly
152 indicate the number of bytes actually read. The caller must be
153 aware that a read may be partially completed.
155 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
157 @param Lba The starting logical block index
160 @param Offset Offset into the block at which to begin reading.
162 @param NumBytes Pointer to a UINTN. At entry, *NumBytes
163 contains the total size of the buffer. At
164 exit, *NumBytes contains the total number of
167 @param Buffer Pointer to a caller-allocated buffer that will
168 be used to hold the data that is read.
170 @retval EFI_SUCCESS The firmware volume was read successfully
171 and contents are in Buffer.
173 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA
174 boundary. On output, NumBytes
175 contains the total number of bytes
178 @retval EFI_ACCESS_DENIED The firmware volume is in the
181 @retval EFI_DEVICE_ERROR The block device is not
182 functioning correctly and could
188 (EFIAPI
*EFI_FVB_READ
)(
189 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*This
,
192 IN OUT UINTN
*NumBytes
,
197 The Write() function writes the specified number of bytes from
198 the provided buffer to the specified block and offset. If the
199 firmware volume is sticky write, the caller must ensure that
200 all the bits of the specified range to write are in the
201 EFI_FVB_ERASE_POLARITY state before calling the Write()
202 function, or else the result will be unpredictable. This
203 unpredictability arises because, for a sticky-write firmware
204 volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY
205 state but it cannot flip it back again. In general, before
206 calling the Write() function, the caller should call the
207 EraseBlocks() function first to erase the specified block to
208 write. A block erase cycle will transition bits from the
209 (NOT)EFI_FVB_ERASE_POLARITY state back to the
210 EFI_FVB_ERASE_POLARITY state. Implementations should be
211 mindful that the firmware volume might be in the WriteDisabled
212 state. If it is in this state, the Write() function must
213 return the status code EFI_ACCESS_DENIED without modifying the
214 contents of the firmware volume. The Write() function must
215 also prevent spanning block boundaries. If a write is
216 requested that spans a block boundary, the write must store up
217 to the boundary but not beyond. The output parameter NumBytes
218 must be set to correctly indicate the number of bytes actually
219 written. The caller must be aware that a write may be
220 partially completed. All writes, partial or otherwise, must be
221 fully flushed to the hardware before the Write() service
224 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL instance.
226 @param Lba The starting logical block index to write to.
228 @param Offset Offset into the block at which to begin writing.
230 @param NumBytes Pointer to a UINTN. At entry, *NumBytes
231 contains the total size of the buffer. At
232 exit, *NumBytes contains the total number of
233 bytes actually written.
235 @param Buffer Pointer to a caller-allocated buffer that
236 contains the source for the write.
238 @retval EFI_SUCCESS The firmware volume was written successfully.
240 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an
241 LBA boundary. On output, NumBytes
242 contains the total number of bytes
245 @retval EFI_ACCESS_DENIED The firmware volume is in the
248 @retval EFI_DEVICE_ERROR The block device is malfunctioning
249 and could not be written.
255 (EFIAPI
* EFI_FVB_WRITE
)(
256 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*This
,
259 IN OUT UINTN
*NumBytes
,
267 // EFI_LBA_LIST_TERMINATOR
269 #define EFI_LBA_LIST_TERMINATOR 0xFFFFFFFFFFFFFFFFULL
273 The EraseBlocks() function erases one or more blocks as denoted
274 by the variable argument list. The entire parameter list of
275 blocks must be verified before erasing any blocks. If a block is
276 requested that does not exist within the associated firmware
277 volume (it has a larger index than the last block of the
278 firmware volume), the EraseBlocks() function must return the
279 status code EFI_INVALID_PARAMETER without modifying the contents
280 of the firmware volume. Implementations should be mindful that
281 the firmware volume might be in the WriteDisabled state. If it
282 is in this state, the EraseBlocks() function must return the
283 status code EFI_ACCESS_DENIED without modifying the contents of
284 the firmware volume. All calls to EraseBlocks() must be fully
285 flushed to the hardware before the EraseBlocks() service
288 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
291 @param ... The variable argument list is a list of tuples.
292 Each tuple describes a range of LBAs to erase
293 and consists of the following:
294 - An EFI_LBA that indicates the starting LBA
295 - A UINTN that indicates the number of blocks to
298 The list is terminated with an
299 EFI_LBA_LIST_TERMINATOR. For example, the
300 following indicates that two ranges of blocks
301 (5-7 and 10-11) are to be erased: EraseBlocks
302 (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);
304 @retval EFI_SUCCESS The erase request was successfully
307 @retval EFI_ACCESS_DENIED The firmware volume is in the
309 @retval EFI_DEVICE_ERROR The block device is not functioning
310 correctly and could not be written.
311 The firmware device may have been
313 @retval EFI_INVALID_PARAMETER One or more of the LBAs listed
314 in the variable argument list do
315 not exist in the firmware volume.
320 (EFIAPI
* EFI_FVB_ERASE_BLOCKS
)(
321 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*This
,
328 @par Protocol Description:
329 The Firmware Volume Block Protocol is the low-level interface
330 to a firmware volume. File-level access to a firmware volume
331 should not be done using the Firmware Volume Block Protocol.
332 Normal access to a firmware volume must use the Firmware
333 Volume Protocol. Typically, only the file system driver that
334 produces the Firmware Volume Protocol will bind to the
335 Firmware Volume Block Protocol. The Firmware Volume Block
336 Protocol provides the following:
337 - Byte-level read/write functionality.
338 - Block-level erase functionality.
339 - It further exposes device-hardening features, such as may be
340 equired to protect the firmware from unwanted overwriting
342 - It is useful to layer a file system driver on top of the
343 Firmware Volume Block Protocol.
345 This file system driver produces the Firmware Volume Protocol,
346 which provides file-level access to a firmware volume. The
347 Firmware Volume Protocol abstracts the file system that is
348 used to format the firmware volume and the hardware
349 device-hardening features that may be present.
352 @param GetPhysicalAddress Retrieves the memory-mapped
353 address of the firmware volume.
355 @param GetBlockSize Retrieves the size for a specific block.
356 Also returns the number of consecutive
357 similarly sized blocks.
359 @param Read Reads n bytes into a buffer from the firmware
362 @param Write Writes n bytes from a buffer into the firmware
365 @param EraseBlocks Erases specified block(s) and sets all
366 values as indicated by the
367 EFI_FVB_ERASE_POLARITY bit. See the
368 EraseBlocks() function description. Type
369 EFI_FVB_ERASE_POLARITY is defined in
370 EFI_FIRMWARE_VOLUME_HEADER. ParentHandle
371 Handle of the parent firmware volume.
373 @param GetAttributes Retrieves the current volume attributes.
375 @param SetAttributes Sets the current volume attributes.
378 struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
{
379 EFI_FVB_GET_ATTRIBUTES GetAttributes
;
380 EFI_FVB_SET_ATTRIBUTES SetAttributes
;
381 EFI_FVB_GET_PHYSICAL_ADDRESS GetPhysicalAddress
;
382 EFI_FVB_GET_BLOCK_SIZE GetBlockSize
;
385 EFI_FVB_ERASE_BLOCKS EraseBlocks
;
386 EFI_HANDLE ParentHandle
;
390 extern EFI_GUID gEfiFirmwareVolumeBlockProtocolGuid
;