]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/FirmwareVolumeBlock.h
b059edf4b3c9602b2e85b59bb6a1b9766b11e51b
[mirror_edk2.git] / MdePkg / Include / Protocol / FirmwareVolumeBlock.h
1 /** @file
2 This file provides control over block-oriented firmware devices.
3
4 Copyright (c) 2006 - 2007, 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
9
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.
12
13 @par Revision Reference: PI
14 Version 1.00.
15
16 **/
17
18 #ifndef __FIRMWARE_VOLUME_BLOCK_H__
19 #define __FIRMWARE_VOLUME_BLOCK_H__
20
21
22 #define EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID \
23 { 0xDE28BC59, 0x6228, 0x41BD, {0xBD, 0xF6, 0xA3, 0xB9, 0xAD,0xB5, 0x8D, 0xA1 } }
24
25
26 typedef struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL;
27
28 /**
29 The GetAttributes() function retrieves the attributes and
30 current settings of the block. Status Codes Returned
31
32 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
33 instance.
34
35 @param Attributes Pointer to EFI_FVB_ATTRIBUTES in which the
36 attributes and current settings are
37 returned. Type EFI_FVB_ATTRIBUTES is defined
38 in EFI_FIRMWARE_VOLUME_HEADER.
39
40 @retval EFI_SUCCESS The firmware volume attributes were
41 returned.
42
43 **/
44 typedef
45 EFI_STATUS
46 (EFIAPI * EFI_FVB_GET_ATTRIBUTES) (
47 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
48 OUT EFI_FVB_ATTRIBUTES *Attributes
49 );
50
51
52 /**
53 The SetAttributes() function sets configurable firmware volume
54 attributes and returns the new settings of the firmware volume.
55
56 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
57 instance.
58
59 @param Attributes On input, Attributes is a pointer to
60 EFI_FVB_ATTRIBUTES that contains the
61 desired firmware volume settings. On
62 successful return, it contains the new
63 settings of the firmware volume. Type
64 EFI_FVB_ATTRIBUTES is defined in
65 EFI_FIRMWARE_VOLUME_HEADER.
66
67
68 @retval EFI_SUCCESS The firmware volume attributes were
69 returned.
70
71 @retval EFI_INVALID_PARAMETER The attributes requested are in
72 conflict with the capabilities
73 as declared in the firmware
74 volume header.
75
76 **/
77 typedef
78 EFI_STATUS
79 (EFIAPI * EFI_FVB_SET_ATTRIBUTES) (
80 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
81 IN OUT EFI_FVB_ATTRIBUTES *Attributes
82 );
83
84
85 /**
86 The GetPhysicalAddress() function retrieves the base address of
87 a memory-mapped firmware volume. This function should be called
88 only for memory-mapped firmware volumes.
89
90 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
91 nstance.
92
93 @param Address Pointer to a caller-allocated
94 EFI_PHYSICAL_ADDRESS that, on successful
95 return from GetPhysicalAddress(), contains the
96 base address of the firmware volume. Type
97 EFI_PHYSICAL_ADDRESS is defined in
98 AllocatePages() in the UEFI 2.0 specification.
99
100 @retval EFI_SUCCESS The firmware volume base address is
101 returned.
102
103 @retval EFI_NOT_SUPPORTED The firmware volume is not memory
104 mapped.
105
106
107 **/
108 typedef
109 EFI_STATUS
110 (EFIAPI * EFI_FVB_GET_PHYSICAL_ADDRESS) (
111 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
112 OUT EFI_PHYSICAL_ADDRESS *Address
113 );
114
115 /**
116 The GetBlockSize() function retrieves the size of the requested
117 block. It also returns the number of additional blocks with
118 the identical size. The GetBlockSize() function is used to
119 retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).
120
121
122 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
123 instance.
124
125 @param Lba Indicates the block for which to return the size.
126 Type EFI_LBA is defined in the BLOCK_IO Protocol
127 (section 11.6) in the UEFI 2.0 specification.
128
129 @param BlockSize Pointer to a caller-allocated UINTN in which
130 the size of the block is returned.
131
132 @param NumberOfBlocks Pointer to a caller-allocated UINTN in
133 which the number of consecutive blocks,
134 starting with Lba, is returned. All
135 blocks in this range have a size of
136 BlockSize.
137
138
139 @retval EFI_SUCCESS The firmware volume base address is
140 returned.
141
142 @retval EFI_INVALID_PARAMETER The requested LBA is out of
143 range.
144
145 **/
146 typedef
147 EFI_STATUS
148 (EFIAPI * EFI_FVB_GET_BLOCK_SIZE) (
149 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
150 IN CONST EFI_LBA Lba,
151 OUT UINTN *BlockSize,
152 OUT UINTN *NumberOfBlocks
153 );
154
155
156 /**
157 The Read() function reads the requested number of bytes from the
158 requested block and stores them in the provided buffer.
159 Implementations should be mindful that the firmware volume
160 might be in the ReadDisabled state. If it is in this state,
161 the Read() function must return the status code
162 EFI_ACCESS_DENIED without modifying the contents of the
163 buffer. The Read() function must also prevent spanning block
164 boundaries. If a read is requested that would span a block
165 boundary, the read must read up to the boundary but not
166 beyond. The output parameter NumBytes must be set to correctly
167 indicate the number of bytes actually read. The caller must be
168 aware that a read may be partially completed.
169
170 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
171 instance. Lba The starting logical block index
172 from which to read. Type EFI_LBA is defined in the
173 BLOCK_IO Protocol (section 11.6) in the UEFI 2.0
174 specification.
175
176 @param Offset Offset into the block at which to begin reading.
177
178 @param NumBytes Pointer to a UINTN. At entry, *NumBytes
179 contains the total size of the buffer. At
180 exit, *NumBytes contains the total number of
181 bytes read.
182
183 @param Buffer Pointer to a caller-allocated buffer that will
184 be used to hold the data that is read.
185
186 @retval EFI_SUCCESS The firmware volume was read successfully
187 and contents are in Buffer.
188
189 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA
190 boundary. On output, NumBytes
191 contains the total number of bytes
192 returned in Buffer.
193
194 @retval EFI_ACCESS_DENIED The firmware volume is in the
195 ReadDisabled state.
196
197 @retval EFI_DEVICE_ERROR The block device is not
198 functioning correctly and could
199 not be read.
200
201 **/
202 typedef
203 EFI_STATUS
204 (EFIAPI *EFI_FVB_READ) (
205 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
206 IN CONST EFI_LBA Lba,
207 IN CONST UINTN Offset,
208 IN OUT UINTN *NumBytes,
209 IN OUT UINT8 *Buffer
210 );
211
212
213
214 /**
215 The Write() function writes the specified number of bytes from
216 the provided buffer to the specified block and offset. If the
217 firmware volume is sticky write, the caller must ensure that
218 all the bits of the specified range to write are in the
219 EFI_FVB_ERASE_POLARITY state before calling the Write()
220 function, or else the result will be unpredictable. This
221 unpredictability arises because, for a sticky-write firmware
222 volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY
223 state but it cannot flip it back again. In general, before
224 calling the Write() function, the caller should call the
225 EraseBlocks() function first to erase the specified block to
226 write. A block erase cycle will transition bits from the
227 (NOT)EFI_FVB_ERASE_POLARITY state back to the
228 EFI_FVB_ERASE_POLARITY state. Implementations should be
229 mindful that the firmware volume might be in the WriteDisabled
230 state. If it is in this state, the Write() function must
231 return the status code EFI_ACCESS_DENIED without modifying the
232 contents of the firmware volume. The Write() function must
233 also prevent spanning block boundaries. If a write is
234 requested that spans a block boundary, the write must store up
235 to the boundary but not beyond. The output parameter NumBytes
236 must be set to correctly indicate the number of bytes actually
237 written. The caller must be aware that a write may be
238 partially completed. All writes, partial or otherwise, must be
239 fully flushed to the hardware before the Write() service
240 returns.
241
242 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
243 instance.
244
245 @param Lba The starting logical block index to write to. Type
246 EFI_LBA is defined in the BLOCK_IO Protocol
247 (section 11.6) in the UEFI 2.0 specification.
248 Offset Offset into the block at which to begin
249 writing.
250
251 @param NumBytes Pointer to a UINTN. At entry, *NumBytes
252 contains the total size of the buffer. At
253 exit, *NumBytes contains the total number of
254 bytes actually written.
255
256 @param Buffer Pointer to a caller-allocated buffer that
257 contains the source for the write.
258
259 @retval EFI_SUCCESS The firmware volume was written
260 successfully.
261
262 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an
263 LBA boundary. On output, NumBytes
264 contains the total number of bytes
265 actually written.
266
267 @retval EFI_ACCESS_DENIED The firmware volume is in the
268 WriteDisabled state.
269
270 @retval EFI_DEVICE_ERROR The block device is malfunctioning
271 and could not be written.
272
273
274 **/
275 typedef
276 EFI_STATUS
277 (EFIAPI * EFI_FVB_WRITE) (
278 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
279 IN CONST EFI_LBA Lba,
280 IN CONST UINTN Offset,
281 IN OUT UINTN *NumBytes,
282 IN CONST UINT8 *Buffer
283 );
284
285
286
287
288 //
289 // EFI_LBA_LIST_TERMINATOR
290 //
291 #define EFI_LBA_LIST_TERMINATOR 0xFFFFFFFFFFFFFFFFULL
292
293
294 /**
295 The EraseBlocks() function erases one or more blocks as denoted
296 by the variable argument list. The entire parameter list of
297 blocks must be verified before erasing any blocks. If a block is
298 requested that does not exist within the associated firmware
299 volume (it has a larger index than the last block of the
300 firmware volume), the EraseBlocks() function must return the
301 status code EFI_INVALID_PARAMETER without modifying the contents
302 of the firmware volume. Implementations should be mindful that
303 the firmware volume might be in the WriteDisabled state. If it
304 is in this state, the EraseBlocks() function must return the
305 status code EFI_ACCESS_DENIED without modifying the contents of
306 the firmware volume. All calls to EraseBlocks() must be fully
307 flushed to the hardware before the EraseBlocks() service
308 returns.
309
310 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
311 instance.
312
313 @param ... The variable argument list is a list of tuples.
314 Each tuple describes a range of LBAs to erase
315 and consists of the following:
316 - An EFI_LBA that indicates the starting LBA
317 - A UINTN that indicates the number of blocks to
318 erase
319
320 The list is terminated with an
321 EFI_LBA_LIST_TERMINATOR. For example, the
322 following indicates that two ranges of blocks
323 (5-7 and 10-11) are to be erased: EraseBlocks
324 (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);
325
326 @retval EFI_SUCCESS The erase request was successfully
327 completed.
328
329 @retval EFI_ACCESS_DENIED The firmware volume is in the
330 WriteDisabled state.
331 @retval EFI_DEVICE_ERROR The block device is not functioning
332 correctly and could not be written.
333 The firmware device may have been
334 partially erased.
335 @retval EFI_INVALID_PARAMETER One or more of the LBAs listed
336 in the variable argument list do
337 not exist in the firmware volume.
338
339 **/
340 typedef
341 EFI_STATUS
342 (EFIAPI * EFI_FVB_ERASE_BLOCKS) (
343 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
344 ...
345 );
346
347
348
349 /**
350 The Firmware Volume Block Protocol is the low-level interface
351 to a firmware volume. File-level access to a firmware volume
352 should not be done using the Firmware Volume Block Protocol.
353 Normal access to a firmware volume must use the Firmware
354 Volume Protocol. Typically, only the file system driver that
355 produces the Firmware Volume Protocol will bind to the
356 Firmware Volume Block Protocol. The Firmware Volume Block
357 Protocol provides the following:
358 - Byte-level read/write functionality.
359 - Block-level erase functionality.
360 - It further exposes device-hardening features, such as may be
361 equired to protect the firmware from unwanted overwriting
362 and/or erasure.
363 - It is useful to layer a file system driver on top of the
364 Firmware Volume Block Protocol.
365
366 This file system driver produces the Firmware Volume Protocol,
367 which provides file-level access to a firmware volume. The
368 Firmware Volume Protocol abstracts the file system that is
369 used to format the firmware volume and the hardware
370 device-hardening features that may be present.
371
372
373 @param GetPhysicalAddress Retrieves the memory-mapped
374 address of the firmware volume.
375 See the GetPhysicalAddress()
376 function description.
377
378 @param GetBlockSize Retrieves the size for a specific block.
379 Also returns the number of consecutive
380 similarly sized blocks. See the
381 GetBlockSize() function description.
382
383 @param Read Reads n bytes into a buffer from the firmware
384 volume hardware. See the Read() function
385 description.
386
387 @param Write Writes n bytes from a buffer into the firmware
388 volume hardware. See the Write() function
389 description.
390
391 @param EraseBlocks Erases specified block(s) and sets all
392 values as indicated by the
393 EFI_FVB_ERASE_POLARITY bit. See the
394 EraseBlocks() function description. Type
395 EFI_FVB_ERASE_POLARITY is defined in
396 EFI_FIRMWARE_VOLUME_HEADER. ParentHandle
397 Handle of the parent firmware volume. Type
398 EFI_HANDLE is defined in
399 InstallProtocolInterface() in the UEFI 2.0
400 specification.
401
402 @param GetAttributes Retrieves the current volume attributes.
403 See the GetAttributes() function
404 description.
405
406 @param SetAttributes Sets the current volume attributes. See
407 the SetAttributes() function description.
408
409
410 **/
411 struct _EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL {
412 EFI_FVB_GET_ATTRIBUTES GetAttributes;
413 EFI_FVB_SET_ATTRIBUTES SetAttributes;
414 EFI_FVB_GET_PHYSICAL_ADDRESS GetPhysicalAddress;
415 EFI_FVB_GET_BLOCK_SIZE GetBlockSize;
416 EFI_FVB_READ Read;
417 EFI_FVB_WRITE Write;
418 EFI_FVB_ERASE_BLOCKS EraseBlocks;
419 EFI_HANDLE ParentHandle;
420 };
421
422
423 extern EFI_GUID gEfiFirmwareVolumeBlockProtocolGuid;
424
425
426 #endif