]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Library/FvbServiceLib.h
a87750a7b46a53b2717882c93f9b64dd1d4094d5
[mirror_edk2.git] / MdeModulePkg / Include / Library / FvbServiceLib.h
1 /** @file
2 Firmeware Volume BLock Service Library
3
4 Copyright (c) 2006 - 2007, Intel Corporation.<BR>
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 **/
14
15 #ifndef __FVB_SERVICE_LIB_H__
16 #define __FVB_SERVICE_LIB_H__
17
18 /**
19 Reads specified number of bytes into a buffer from the specified block.
20
21 The EfiFvbReadBlock() function reads the requested number of bytes from
22 the requested block in the specified firmware volume and stores them in
23 the provided buffer. Implementations should be mindful that the firmware
24 volume might be in the ReadDisabled state. If it is in this state, the
25 EfiFvbReadBlock() function must return the status code EFI_ACCESS_DENIED
26 without modifying the contents of the buffer.
27
28 The EfiFvbReadBlock() function must also prevent spanning block boundaries.
29 If a read is requested that would span a block boundary, the read must read
30 up to the boundary but not beyond. The output parameter NumBytes must be
31 set to correctly indicate the number of bytes actually read.
32 The caller must be aware that a read may be partially completed.
33
34 If NumBytes is NULL, then ASSERT().
35
36 If Buffer is NULL, then ASSERT().
37
38 @param[in] Instance The FV instance to be read from.
39 @param[in] Lba The logical block address to be read from
40 @param[in] Offset The offset relative to the block, at which to begin reading.
41 @param[in, out] NumBytes Pointer to a UINTN. On input, *NumBytes contains the total
42 size of the buffer. On output, it contains the actual number
43 of bytes read.
44 @param[out] Buffer Pointer to a caller allocated buffer that will be
45 used to hold the data read.
46
47 @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.
48 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains
49 the total number of bytes returned in Buffer.
50 @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.
51 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.
52 @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index
53 is larger than the last block of the firmware volume. Offset is larger
54 than the block size.
55
56 **/
57 EFI_STATUS
58 EFIAPI
59 EfiFvbReadBlock (
60 IN UINTN Instance,
61 IN EFI_LBA Lba,
62 IN UINTN Offset,
63 IN OUT UINTN *NumBytes,
64 OUT UINT8 *Buffer
65 );
66
67
68 /**
69 Writes specified number of bytes from the input buffer to the block
70
71 The EfiFvbWriteBlock() function writes the specified number of bytes
72 from the provided buffer to the specified block and offset in the
73 requested firmware volume.
74
75 If the firmware volume is sticky write, the caller must ensure that
76 all the bits of the specified range to write are in the EFI_FVB_ERASE_POLARITY
77 state before calling the EfiFvbWriteBlock() function, or else the
78 result will be unpredictable. This unpredictability arises because,
79 for a sticky-write firmware volume, a write may negate a bit in the
80 EFI_FVB_ERASE_POLARITY state but it cannot flip it back again. In
81 general, before calling the EfiFvbWriteBlock() function, the caller
82 should call the EfiFvbEraseBlock() function first to erase the specified
83 block to write. A block erase cycle will transition bits from the
84 (NOT)EFI_FVB_ERASE_POLARITY state back to the EFI_FVB_ERASE_POLARITY state.
85 Implementations should be mindful that the firmware volume might be
86 in the WriteDisabled state. If it is in this state, the EfiFvbWriteBlock()
87 function must return the status code EFI_ACCESS_DENIED without modifying
88 the contents of the firmware volume.
89
90 The EfiFvbWriteBlock() function must also prevent spanning block boundaries.
91 If a write is requested that spans a block boundary, the write must store
92 up to the boundary but not beyond. The output parameter NumBytes must be
93 set to correctly indicate the number of bytes actually written. The caller
94 must be aware that a write may be partially completed.
95 All writes, partial or otherwise, must be fully flushed to the hardware
96 before the EfiFvbWriteBlock() function returns.
97
98 If NumBytes is NULL, then ASSERT().
99
100 @param Instance The FV instance to be written to
101 @param Lba The starting logical block index to write to
102 @param Offset The offset relative to the block, at which to begin writting.
103 @param NumBytes Pointer to a UINTN. On input, *NumBytes contains
104 the total size of the buffer. On output, it contains
105 the actual number of bytes written.
106 @param Buffer Pointer to a caller allocated buffer that contains
107 the source for the write
108
109 @retval EFI_SUCCESS The firmware volume was written successfully.
110 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
111 On output, NumBytes contains the total number of bytes actually written.
112 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
113 @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.
114 @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number.
115 Lba index is larger than the last block of the firmware volume.
116 Offset is larger than the block size.
117 **/
118 EFI_STATUS
119 EFIAPI
120 EfiFvbWriteBlock (
121 IN UINTN Instance,
122 IN EFI_LBA Lba,
123 IN UINTN Offset,
124 IN OUT UINTN *NumBytes,
125 IN UINT8 *Buffer
126 );
127
128
129 /**
130 Erases and initializes a firmware volume block.
131
132 The EfiFvbEraseBlock() function erases one block specified by Lba.
133 Implementations should be mindful that the firmware volume might
134 be in the WriteDisabled state. If it is in this state, the EfiFvbEraseBlock()
135 function must return the status code EFI_ACCESS_DENIED without
136 modifying the contents of the firmware volume. If Instance is
137 larger than the max FVB number, or Lba index is larger than the
138 last block of the firmware volume, this function return the status
139 code EFI_INVALID_PARAMETER.
140
141 All calls to EfiFvbEraseBlock() must be fully flushed to the
142 hardware before this function returns.
143
144 @param[in] Instance The FV instance to be erased.
145 @param[in] Lba The logical block index to be erased from.
146
147 @retval EFI_SUCCESS The erase request was successfully completed.
148 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
149 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and
150 could not be written. The firmware device may
151 have been partially erased.
152 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max
153 FVB number. Lba index is larger than the last block
154 of the firmware volume.
155
156 **/
157 EFI_STATUS
158 EFIAPI
159 EfiFvbEraseBlock (
160 IN UINTN Instance,
161 IN EFI_LBA Lba
162 );
163
164
165 /**
166 Retrieves the attributes and current settings of the specified block,
167 returns resulting attributes in output parameter.
168
169 The EfiFvbGetAttributes() function retrieves the attributes and current
170 settings of the block specified by Instance. If Instance is larger than
171 the max FVB number, this function returns the status code EFI_INVALID_PARAMETER.
172
173 If Attributes is NULL, then ASSERT().
174
175 @param[in] Instance The FV instance to be operated.
176 @param[out] Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the
177 attributes and current settings are returned.
178
179 @retval EFI_EFI_SUCCESS The firmware volume attributes were returned.
180 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
181 **/
182 EFI_STATUS
183 EFIAPI
184 EfiFvbGetVolumeAttributes (
185 IN UINTN Instance,
186 OUT EFI_FVB_ATTRIBUTES_2 *Attributes
187 );
188
189
190 /**
191 Modify the attributes and current settings of the specified block
192 according to the input parameter.
193
194 The EfiFvbSetAttributes() function sets configurable firmware volume
195 attributes and returns the new settings of the firmware volume specified
196 by Instance. If Instance is larger than the max FVB number, this function
197 returns the status code EFI_INVALID_PARAMETER.
198
199 If Attributes is NULL, then ASSERT().
200
201 @param[in] Instance The FV instance to be operated.
202 @param[in, out]Attributes On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2
203 that contains the desired firmware volume settings.
204 On successful return, it contains the new settings of the firmware volume.
205
206 @retval EFI_EFI_SUCCESS The firmware volume attributes were modified successfully.
207 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
208
209 **/
210 EFI_STATUS
211 EFIAPI
212 EfiFvbSetVolumeAttributes (
213 IN UINTN Instance,
214 IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
215 );
216
217
218 /**
219 Retrieves the physical address of the specified memory mapped FV.
220
221 Retrieve the base address of a memory-mapped firmware volume specified by Instance.
222 If Instance is larger than the max FVB number, this function returns the status
223 code EFI_INVALID_PARAMETER.
224
225 If BaseAddress is NULL, then ASSERT().
226
227 @param[in] Instance The FV instance to be operated.
228 @param[out] BaseAddress Pointer to a caller allocated EFI_PHYSICAL_ADDRESS
229 that on successful return, contains the base address
230 of the firmware volume.
231
232 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.
233 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
234
235 **/
236 EFI_STATUS
237 EFIAPI
238 EfiFvbGetPhysicalAddress (
239 IN UINTN Instance,
240 OUT EFI_PHYSICAL_ADDRESS *BaseAddress
241 );
242
243
244 /**
245 Retrieve the block size of the specified fv.
246
247 The EfiFvbGetBlockSize() function retrieves the size of the requested block.
248 It also returns the number of additional blocks with the identical size.
249 If Instance is larger than the max FVB number, or Lba index is larger than
250 the last block of the firmware volume, this function return the status code
251 EFI_INVALID_PARAMETER.
252
253 If BlockSize is NULL, then ASSERT().
254
255 If NumOfBlocks is NULL, then ASSERT().
256
257 @param[in] Instance The FV instance to be operated.
258 @param[in] Lba Indicates which block to return the size for.
259 @param[out] BlockSize Pointer to a caller-allocated UINTN in which the
260 size of the block is returned.
261 @param[out] NumOfBlocks Pointer to a caller-allocated UINTN in which the
262 number of consecutive blocks, starting with Lba,
263 is returned. All blocks in this range have a size of BlockSize.
264
265 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.
266 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
267 Lba index is larger than the last block of the firmware volume.
268
269 **/
270 EFI_STATUS
271 EFIAPI
272 EfiFvbGetBlockSize (
273 IN UINTN Instance,
274 IN EFI_LBA Lba,
275 OUT UINTN *BlockSize,
276 OUT UINTN *NumOfBlocks
277 );
278
279
280 /**
281 Erases and initializes a specified range of a firmware volume.
282
283 The EfiFvbEraseCustomBlockRange() function erases the specified range in the firmware
284 volume index by Instance. If Instance is larger than the max FVB number, StartLba or
285 LastLba index is larger than the last block of the firmware volume, StartLba > LastLba
286 or StartLba equal to LastLba but OffsetStartLba > OffsetLastLba, this function return
287 the status code EFI_INVALID_PARAMETER.
288
289 @param[in] Instance The FV instance to be operated.
290 @param[in] StartLba The starting logical block index to be erased.
291 @param[in] OffsetStartLba Offset into the starting block at which to
292 begin erasing.
293 @param[in] LastLba The last logical block index to be erased.
294 @param[in] OffsetLastLba Offset into the last block at which to end erasing.
295
296 @retval EFI_EFI_SUCCESS Successfully erase custom block range
297 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
298 @retval EFI_UNSUPPORTED Firmware volume block device has no this capability.
299
300 **/
301 EFI_STATUS
302 EFIAPI
303 EfiFvbEraseCustomBlockRange (
304 IN UINTN Instance,
305 IN EFI_LBA StartLba,
306 IN UINTN OffsetStartLba,
307 IN EFI_LBA LastLba,
308 IN UINTN OffsetLastLba
309 );
310
311 #endif