]>
Commit | Line | Data |
---|---|---|
85e923a5 LG |
1 | /** @file\r |
2 | \r | |
3 | The internal header file includes the common header files, defines\r | |
0d3edd9d | 4 | internal structure and functions used by Ftw module.\r |
85e923a5 | 5 | \r |
d1102dba | 6 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
85e923a5 LG |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #ifndef _EFI_FAULT_TOLERANT_WRITE_H_\r | |
12 | #define _EFI_FAULT_TOLERANT_WRITE_H_\r | |
13 | \r | |
14 | #include <PiDxe.h>\r | |
15 | \r | |
16 | #include <Guid/SystemNvDataGuid.h>\r | |
05cfd5f2 | 17 | #include <Guid/ZeroGuid.h>\r |
85e923a5 LG |
18 | #include <Protocol/FaultTolerantWrite.h>\r |
19 | #include <Protocol/FirmwareVolumeBlock.h>\r | |
20 | #include <Protocol/SwapAddressRange.h>\r | |
21 | \r | |
22 | #include <Library/PcdLib.h>\r | |
23 | #include <Library/DebugLib.h>\r | |
93367605 | 24 | #include <Library/UefiLib.h>\r |
85e923a5 LG |
25 | #include <Library/UefiDriverEntryPoint.h>\r |
26 | #include <Library/BaseMemoryLib.h>\r | |
27 | #include <Library/MemoryAllocationLib.h>\r | |
2c4b18e0 | 28 | #include <Library/ReportStatusCodeLib.h>\r |
8db39c60 MK |
29 | #include <Library/SafeIntLib.h>\r |
30 | #include <Library/VariableFlashInfoLib.h>\r | |
85e923a5 LG |
31 | \r |
32 | //\r | |
33 | // Flash erase polarity is 1\r | |
34 | //\r | |
35 | #define FTW_ERASE_POLARITY 1\r | |
36 | \r | |
1436aea4 MK |
37 | #define FTW_ERASED_BYTE ((UINT8) (255))\r |
38 | #define FTW_POLARITY_REVERT ((UINT8) (255))\r | |
85e923a5 | 39 | \r |
85e923a5 LG |
40 | #define HEADER_ALLOCATED 0x1\r |
41 | #define WRITES_ALLOCATED 0x2\r | |
42 | #define WRITES_COMPLETED 0x4\r | |
85e923a5 | 43 | \r |
1436aea4 MK |
44 | #define BOOT_BLOCK_UPDATE 0x1\r |
45 | #define SPARE_COMPLETED 0x2\r | |
46 | #define DEST_COMPLETED 0x4\r | |
85e923a5 | 47 | \r |
1436aea4 | 48 | #define FTW_BLOCKS(Length, BlockSize) ((UINTN) ((Length) / (BlockSize) + (((Length) & ((BlockSize) - 1)) ? 1 : 0)))\r |
85e923a5 LG |
49 | \r |
50 | #define FTW_DEVICE_SIGNATURE SIGNATURE_32 ('F', 'T', 'W', 'D')\r | |
51 | \r | |
52 | //\r | |
53 | // EFI Fault tolerant protocol private data structure\r | |
54 | //\r | |
55 | typedef struct {\r | |
1436aea4 MK |
56 | UINTN Signature;\r |
57 | EFI_HANDLE Handle;\r | |
58 | EFI_FAULT_TOLERANT_WRITE_PROTOCOL FtwInstance;\r | |
59 | EFI_PHYSICAL_ADDRESS WorkSpaceAddress; // Base address of working space range in flash.\r | |
60 | EFI_PHYSICAL_ADDRESS SpareAreaAddress; // Base address of spare range in flash.\r | |
61 | UINTN WorkSpaceLength; // Size of working space range in flash.\r | |
62 | UINTN NumberOfWorkSpaceBlock; // Number of the blocks in work block for work space.\r | |
63 | UINTN WorkBlockSize; // Block size in bytes of the work blocks in flash\r | |
64 | UINTN SpareAreaLength; // Size of spare range in flash.\r | |
65 | UINTN NumberOfSpareBlock; // Number of the blocks in spare block.\r | |
66 | UINTN SpareBlockSize; // Block size in bytes of the spare blocks in flash\r | |
67 | EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkSpaceHeader; // Pointer to Working Space Header in memory buffer\r | |
68 | EFI_FAULT_TOLERANT_WRITE_HEADER *FtwLastWriteHeader; // Pointer to last record header in memory buffer\r | |
69 | EFI_FAULT_TOLERANT_WRITE_RECORD *FtwLastWriteRecord; // Pointer to last record in memory buffer\r | |
70 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwFvBlock; // FVB of working block\r | |
71 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwBackupFvb; // FVB of spare block\r | |
72 | EFI_LBA FtwSpareLba; // Start LBA of spare block\r | |
73 | EFI_LBA FtwWorkBlockLba; // Start LBA of working block that contains working space in its last block.\r | |
74 | UINTN NumberOfWorkBlock; // Number of the blocks in work block.\r | |
75 | EFI_LBA FtwWorkSpaceLba; // Start LBA of working space\r | |
76 | UINTN FtwWorkSpaceBase; // Offset into the FtwWorkSpaceLba block.\r | |
77 | UINTN FtwWorkSpaceSize; // Size of working space range that stores write record.\r | |
78 | EFI_LBA FtwWorkSpaceLbaInSpare; // Start LBA of working space in spare block.\r | |
79 | UINTN FtwWorkSpaceBaseInSpare; // Offset into the FtwWorkSpaceLbaInSpare block.\r | |
80 | UINT8 *FtwWorkSpace; // Point to Work Space in memory buffer\r | |
85e923a5 LG |
81 | //\r |
82 | // Following a buffer of FtwWorkSpace[FTW_WORK_SPACE_SIZE],\r | |
83 | // Allocated with EFI_FTW_DEVICE.\r | |
84 | //\r | |
85 | } EFI_FTW_DEVICE;\r | |
86 | \r | |
87 | #define FTW_CONTEXT_FROM_THIS(a) CR (a, EFI_FTW_DEVICE, FtwInstance, FTW_DEVICE_SIGNATURE)\r | |
88 | \r | |
89 | //\r | |
90 | // Driver entry point\r | |
91 | //\r | |
1436aea4 | 92 | \r |
85e923a5 LG |
93 | /**\r |
94 | This function is the entry point of the Fault Tolerant Write driver.\r | |
95 | \r | |
96 | @param ImageHandle A handle for the image that is initializing this driver\r | |
97 | @param SystemTable A pointer to the EFI system table\r | |
98 | \r | |
99 | @return EFI_SUCCESS FTW has finished the initialization\r | |
100 | @retval EFI_NOT_FOUND Locate FVB protocol error\r | |
101 | @retval EFI_OUT_OF_RESOURCES Allocate memory error\r | |
102 | @retval EFI_VOLUME_CORRUPTED Firmware volume is error\r | |
103 | @retval EFI_ABORTED FTW initialization error\r | |
104 | \r | |
105 | **/\r | |
106 | EFI_STATUS\r | |
107 | EFIAPI\r | |
108 | InitializeFaultTolerantWrite (\r | |
1436aea4 MK |
109 | IN EFI_HANDLE ImageHandle,\r |
110 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
85e923a5 LG |
111 | );\r |
112 | \r | |
113 | //\r | |
114 | // Fault Tolerant Write Protocol API\r | |
115 | //\r | |
116 | \r | |
117 | /**\r | |
118 | Query the largest block that may be updated in a fault tolerant manner.\r | |
119 | \r | |
120 | \r | |
121 | @param This Indicates a pointer to the calling context.\r | |
122 | @param BlockSize A pointer to a caller allocated UINTN that is updated to\r | |
123 | indicate the size of the largest block that can be updated.\r | |
124 | \r | |
125 | @return EFI_SUCCESS The function completed successfully\r | |
126 | \r | |
127 | **/\r | |
128 | EFI_STATUS\r | |
129 | EFIAPI\r | |
130 | FtwGetMaxBlockSize (\r | |
1436aea4 MK |
131 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r |
132 | OUT UINTN *BlockSize\r | |
85e923a5 LG |
133 | );\r |
134 | \r | |
135 | /**\r | |
136 | Allocates space for the protocol to maintain information about writes.\r | |
137 | Since writes must be completed in a fault tolerant manner and multiple\r | |
138 | updates will require more resources to be successful, this function\r | |
139 | enables the protocol to ensure that enough space exists to track\r | |
140 | information about the upcoming writes.\r | |
141 | \r | |
142 | All writes must be completed or aborted before another fault tolerant write can occur.\r | |
143 | \r | |
144 | @param This Indicates a pointer to the calling context.\r | |
145 | @param CallerId The GUID identifying the write.\r | |
146 | @param PrivateDataSize The size of the caller's private data\r | |
147 | that must be recorded for each write.\r | |
148 | @param NumberOfWrites The number of fault tolerant block writes\r | |
149 | that will need to occur.\r | |
150 | \r | |
151 | @return EFI_SUCCESS The function completed successfully\r | |
152 | @retval EFI_ABORTED The function could not complete successfully.\r | |
153 | @retval EFI_ACCESS_DENIED All allocated writes have not been completed.\r | |
154 | \r | |
155 | **/\r | |
156 | EFI_STATUS\r | |
157 | EFIAPI\r | |
158 | FtwAllocate (\r | |
1436aea4 MK |
159 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r |
160 | IN EFI_GUID *CallerId,\r | |
161 | IN UINTN PrivateDataSize,\r | |
162 | IN UINTN NumberOfWrites\r | |
85e923a5 LG |
163 | );\r |
164 | \r | |
165 | /**\r | |
166 | Starts a target block update. This function will record data about write\r | |
167 | in fault tolerant storage and will complete the write in a recoverable\r | |
168 | manner, ensuring at all times that either the original contents or\r | |
169 | the modified contents are available.\r | |
170 | \r | |
171 | \r | |
172 | @param This Calling context\r | |
173 | @param Lba The logical block address of the target block.\r | |
174 | @param Offset The offset within the target block to place the data.\r | |
175 | @param Length The number of bytes to write to the target block.\r | |
176 | @param PrivateData A pointer to private data that the caller requires to\r | |
177 | complete any pending writes in the event of a fault.\r | |
178 | @param FvBlockHandle The handle of FVB protocol that provides services for\r | |
179 | reading, writing, and erasing the target block.\r | |
180 | @param Buffer The data to write.\r | |
181 | \r | |
d1102dba LG |
182 | @retval EFI_SUCCESS The function completed successfully\r |
183 | @retval EFI_ABORTED The function could not complete successfully.\r | |
184 | @retval EFI_BAD_BUFFER_SIZE The input data can't fit within the spare block.\r | |
85e923a5 | 185 | Offset + *NumBytes > SpareAreaLength.\r |
d1102dba | 186 | @retval EFI_ACCESS_DENIED No writes have been allocated.\r |
85e923a5 LG |
187 | @retval EFI_OUT_OF_RESOURCES Cannot allocate enough memory resource.\r |
188 | @retval EFI_NOT_FOUND Cannot find FVB protocol by handle.\r | |
189 | \r | |
190 | **/\r | |
191 | EFI_STATUS\r | |
192 | EFIAPI\r | |
193 | FtwWrite (\r | |
1436aea4 MK |
194 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r |
195 | IN EFI_LBA Lba,\r | |
196 | IN UINTN Offset,\r | |
197 | IN UINTN Length,\r | |
198 | IN VOID *PrivateData,\r | |
199 | IN EFI_HANDLE FvBlockHandle,\r | |
200 | IN VOID *Buffer\r | |
85e923a5 LG |
201 | );\r |
202 | \r | |
203 | /**\r | |
204 | Restarts a previously interrupted write. The caller must provide the\r | |
205 | block protocol needed to complete the interrupted write.\r | |
206 | \r | |
207 | @param This Calling context.\r | |
208 | @param FvBlockHandle The handle of FVB protocol that provides services for\r | |
209 | reading, writing, and erasing the target block.\r | |
210 | \r | |
211 | @retval EFI_SUCCESS The function completed successfully\r | |
212 | @retval EFI_ACCESS_DENIED No pending writes exist\r | |
213 | @retval EFI_NOT_FOUND FVB protocol not found by the handle\r | |
214 | @retval EFI_ABORTED The function could not complete successfully\r | |
215 | \r | |
216 | **/\r | |
217 | EFI_STATUS\r | |
218 | EFIAPI\r | |
219 | FtwRestart (\r | |
1436aea4 MK |
220 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r |
221 | IN EFI_HANDLE FvBlockHandle\r | |
85e923a5 LG |
222 | );\r |
223 | \r | |
224 | /**\r | |
225 | Aborts all previous allocated writes.\r | |
226 | \r | |
227 | @param This Calling context\r | |
228 | \r | |
229 | @retval EFI_SUCCESS The function completed successfully\r | |
230 | @retval EFI_ABORTED The function could not complete successfully.\r | |
231 | @retval EFI_NOT_FOUND No allocated writes exist.\r | |
232 | \r | |
233 | **/\r | |
234 | EFI_STATUS\r | |
235 | EFIAPI\r | |
236 | FtwAbort (\r | |
1436aea4 | 237 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This\r |
85e923a5 LG |
238 | );\r |
239 | \r | |
240 | /**\r | |
241 | Starts a target block update. This records information about the write\r | |
242 | in fault tolerant storage and will complete the write in a recoverable\r | |
243 | manner, ensuring at all times that either the original contents or\r | |
244 | the modified contents are available.\r | |
245 | \r | |
246 | @param This Indicates a pointer to the calling context.\r | |
247 | @param CallerId The GUID identifying the last write.\r | |
248 | @param Lba The logical block address of the last write.\r | |
249 | @param Offset The offset within the block of the last write.\r | |
250 | @param Length The length of the last write.\r | |
251 | @param PrivateDataSize bytes from the private data\r | |
252 | stored for this write.\r | |
253 | @param PrivateData A pointer to a buffer. The function will copy\r | |
254 | @param Complete A Boolean value with TRUE indicating\r | |
255 | that the write was completed.\r | |
256 | \r | |
257 | @retval EFI_SUCCESS The function completed successfully\r | |
258 | @retval EFI_ABORTED The function could not complete successfully\r | |
259 | @retval EFI_NOT_FOUND No allocated writes exist\r | |
260 | @retval EFI_BUFFER_TOO_SMALL Input buffer is not larget enough\r | |
261 | \r | |
262 | **/\r | |
263 | EFI_STATUS\r | |
264 | EFIAPI\r | |
265 | FtwGetLastWrite (\r | |
1436aea4 MK |
266 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r |
267 | OUT EFI_GUID *CallerId,\r | |
268 | OUT EFI_LBA *Lba,\r | |
269 | OUT UINTN *Offset,\r | |
270 | OUT UINTN *Length,\r | |
271 | IN OUT UINTN *PrivateDataSize,\r | |
272 | OUT VOID *PrivateData,\r | |
273 | OUT BOOLEAN *Complete\r | |
85e923a5 LG |
274 | );\r |
275 | \r | |
276 | /**\r | |
277 | Erase spare block.\r | |
278 | \r | |
279 | @param FtwDevice The private data of FTW driver\r | |
280 | \r | |
281 | @retval EFI_SUCCESS The erase request was successfully completed.\r | |
282 | @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.\r | |
283 | @retval EFI_DEVICE_ERROR The block device is not functioning\r | |
284 | correctly and could not be written.\r | |
285 | The firmware device may have been\r | |
286 | partially erased.\r | |
287 | @retval EFI_INVALID_PARAMETER One or more of the LBAs listed\r | |
288 | in the variable argument list do\r | |
d1102dba | 289 | not exist in the firmware volume.\r |
85e923a5 LG |
290 | \r |
291 | \r | |
292 | **/\r | |
293 | EFI_STATUS\r | |
294 | FtwEraseSpareBlock (\r | |
1436aea4 | 295 | IN EFI_FTW_DEVICE *FtwDevice\r |
85e923a5 LG |
296 | );\r |
297 | \r | |
298 | /**\r | |
0a18956d | 299 | Retrieve the proper FVB protocol interface by HANDLE.\r |
85e923a5 LG |
300 | \r |
301 | \r | |
302 | @param FvBlockHandle The handle of FVB protocol that provides services for\r | |
303 | reading, writing, and erasing the target block.\r | |
304 | @param FvBlock The interface of FVB protocol\r | |
305 | \r | |
306 | @retval EFI_SUCCESS The function completed successfully\r | |
307 | @retval EFI_ABORTED The function could not complete successfully\r | |
308 | \r | |
309 | **/\r | |
310 | EFI_STATUS\r | |
311 | FtwGetFvbByHandle (\r | |
312 | IN EFI_HANDLE FvBlockHandle,\r | |
313 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r | |
314 | );\r | |
315 | \r | |
316 | /**\r | |
317 | \r | |
318 | Is it in working block?\r | |
319 | \r | |
320 | @param FtwDevice The private data of FTW driver\r | |
321 | @param FvBlock Fvb protocol instance\r | |
322 | @param Lba The block specified\r | |
323 | \r | |
324 | @return A BOOLEAN value indicating in working block or not.\r | |
325 | \r | |
326 | **/\r | |
327 | BOOLEAN\r | |
328 | IsWorkingBlock (\r | |
329 | EFI_FTW_DEVICE *FtwDevice,\r | |
330 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r | |
331 | EFI_LBA Lba\r | |
332 | );\r | |
333 | \r | |
334 | /**\r | |
335 | \r | |
336 | Is it in boot block?\r | |
337 | \r | |
338 | @param FtwDevice The private data of FTW driver\r | |
339 | @param FvBlock Fvb protocol instance\r | |
85e923a5 LG |
340 | \r |
341 | @return A BOOLEAN value indicating in boot block or not.\r | |
342 | \r | |
343 | **/\r | |
344 | BOOLEAN\r | |
345 | IsBootBlock (\r | |
346 | EFI_FTW_DEVICE *FtwDevice,\r | |
0d3edd9d | 347 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock\r |
85e923a5 LG |
348 | );\r |
349 | \r | |
350 | /**\r | |
351 | Copy the content of spare block to a target block. Size is FTW_BLOCK_SIZE.\r | |
0d3edd9d SZ |
352 | Spare block is accessed by FTW backup FVB protocol interface.\r |
353 | Target block is accessed by FvBlock protocol interface.\r | |
85e923a5 LG |
354 | \r |
355 | \r | |
356 | @param FtwDevice The private data of FTW driver\r | |
357 | @param FvBlock FVB Protocol interface to access target block\r | |
358 | @param Lba Lba of the target block\r | |
0d3edd9d SZ |
359 | @param BlockSize The size of the block\r |
360 | @param NumberOfBlocks The number of consecutive blocks starting with Lba\r | |
85e923a5 LG |
361 | \r |
362 | @retval EFI_SUCCESS Spare block content is copied to target block\r | |
363 | @retval EFI_INVALID_PARAMETER Input parameter error\r | |
364 | @retval EFI_OUT_OF_RESOURCES Allocate memory error\r | |
365 | @retval EFI_ABORTED The function could not complete successfully\r | |
366 | \r | |
367 | **/\r | |
368 | EFI_STATUS\r | |
369 | FlushSpareBlockToTargetBlock (\r | |
370 | EFI_FTW_DEVICE *FtwDevice,\r | |
371 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r | |
0d3edd9d SZ |
372 | EFI_LBA Lba,\r |
373 | UINTN BlockSize,\r | |
374 | UINTN NumberOfBlocks\r | |
85e923a5 LG |
375 | );\r |
376 | \r | |
377 | /**\r | |
378 | Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE.\r | |
379 | Spare block is accessed by FTW backup FVB protocol interface. LBA is\r | |
380 | FtwDevice->FtwSpareLba.\r | |
381 | Working block is accessed by FTW working FVB protocol interface. LBA is\r | |
382 | FtwDevice->FtwWorkBlockLba.\r | |
383 | \r | |
384 | Since the working block header is important when FTW initializes, the\r | |
385 | state of the operation should be handled carefully. The Crc value is\r | |
386 | calculated without STATE element.\r | |
387 | \r | |
388 | @param FtwDevice The private data of FTW driver\r | |
389 | \r | |
390 | @retval EFI_SUCCESS Spare block content is copied to target block\r | |
391 | @retval EFI_OUT_OF_RESOURCES Allocate memory error\r | |
392 | @retval EFI_ABORTED The function could not complete successfully\r | |
393 | \r | |
394 | **/\r | |
395 | EFI_STATUS\r | |
396 | FlushSpareBlockToWorkingBlock (\r | |
1436aea4 | 397 | EFI_FTW_DEVICE *FtwDevice\r |
85e923a5 LG |
398 | );\r |
399 | \r | |
400 | /**\r | |
401 | Copy the content of spare block to a boot block. Size is FTW_BLOCK_SIZE.\r | |
0d3edd9d SZ |
402 | Spare block is accessed by FTW working FVB protocol interface.\r |
403 | Target block is accessed by FvBlock protocol interface.\r | |
85e923a5 LG |
404 | \r |
405 | FTW will do extra work on boot block update.\r | |
406 | FTW should depend on a protocol of EFI_ADDRESS_RANGE_SWAP_PROTOCOL,\r | |
407 | which is produced by a chipset driver.\r | |
408 | FTW updating boot block steps may be:\r | |
409 | 1. GetRangeLocation(), if the Range is inside the boot block, FTW know\r | |
410 | that boot block will be update. It shall add a FLAG in the working block.\r | |
411 | 2. When spare block is ready,\r | |
0d3edd9d | 412 | 3. SetSwapState(SWAPPED)\r |
85e923a5 LG |
413 | 4. erasing boot block,\r |
414 | 5. programming boot block until the boot block is ok.\r | |
415 | 6. SetSwapState(UNSWAPPED)\r | |
416 | FTW shall not allow to update boot block when battery state is error.\r | |
417 | \r | |
418 | @param FtwDevice The private data of FTW driver\r | |
419 | \r | |
420 | @retval EFI_SUCCESS Spare block content is copied to boot block\r | |
421 | @retval EFI_INVALID_PARAMETER Input parameter error\r | |
422 | @retval EFI_OUT_OF_RESOURCES Allocate memory error\r | |
423 | @retval EFI_ABORTED The function could not complete successfully\r | |
424 | \r | |
425 | **/\r | |
426 | EFI_STATUS\r | |
427 | FlushSpareBlockToBootBlock (\r | |
1436aea4 | 428 | EFI_FTW_DEVICE *FtwDevice\r |
85e923a5 LG |
429 | );\r |
430 | \r | |
431 | /**\r | |
432 | Update a bit of state on a block device. The location of the bit is\r | |
433 | calculated by the (Lba, Offset, bit). Here bit is determined by the\r | |
434 | the name of a certain bit.\r | |
435 | \r | |
436 | \r | |
437 | @param FvBlock FVB Protocol interface to access SrcBlock and DestBlock\r | |
0d3edd9d | 438 | @param BlockSize The size of the block\r |
85e923a5 LG |
439 | @param Lba Lba of a block\r |
440 | @param Offset Offset on the Lba\r | |
441 | @param NewBit New value that will override the old value if it can be change\r | |
442 | \r | |
443 | @retval EFI_SUCCESS A state bit has been updated successfully\r | |
444 | @retval Others Access block device error.\r | |
445 | Notes:\r | |
446 | Assume all bits of State are inside the same BYTE.\r | |
447 | @retval EFI_ABORTED Read block fail\r | |
448 | \r | |
449 | **/\r | |
450 | EFI_STATUS\r | |
451 | FtwUpdateFvState (\r | |
452 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r | |
0d3edd9d | 453 | IN UINTN BlockSize,\r |
85e923a5 LG |
454 | IN EFI_LBA Lba,\r |
455 | IN UINTN Offset,\r | |
456 | IN UINT8 NewBit\r | |
457 | );\r | |
458 | \r | |
459 | /**\r | |
460 | Get the last Write Header pointer.\r | |
461 | The last write header is the header whose 'complete' state hasn't been set.\r | |
462 | After all, this header may be a EMPTY header entry for next Allocate.\r | |
463 | \r | |
464 | \r | |
465 | @param FtwWorkSpaceHeader Pointer of the working block header\r | |
466 | @param FtwWorkSpaceSize Size of the work space\r | |
467 | @param FtwWriteHeader Pointer to retrieve the last write header\r | |
468 | \r | |
469 | @retval EFI_SUCCESS Get the last write record successfully\r | |
470 | @retval EFI_ABORTED The FTW work space is damaged\r | |
471 | \r | |
472 | **/\r | |
473 | EFI_STATUS\r | |
474 | FtwGetLastWriteHeader (\r | |
475 | IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkSpaceHeader,\r | |
476 | IN UINTN FtwWorkSpaceSize,\r | |
477 | OUT EFI_FAULT_TOLERANT_WRITE_HEADER **FtwWriteHeader\r | |
478 | );\r | |
479 | \r | |
480 | /**\r | |
481 | Get the last Write Record pointer. The last write Record is the Record\r | |
482 | whose DestinationCompleted state hasn't been set. After all, this Record\r | |
483 | may be a EMPTY record entry for next write.\r | |
484 | \r | |
485 | \r | |
486 | @param FtwWriteHeader Pointer to the write record header\r | |
487 | @param FtwWriteRecord Pointer to retrieve the last write record\r | |
488 | \r | |
489 | @retval EFI_SUCCESS Get the last write record successfully\r | |
490 | @retval EFI_ABORTED The FTW work space is damaged\r | |
491 | \r | |
492 | **/\r | |
493 | EFI_STATUS\r | |
494 | FtwGetLastWriteRecord (\r | |
1436aea4 MK |
495 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwWriteHeader,\r |
496 | OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwWriteRecord\r | |
85e923a5 LG |
497 | );\r |
498 | \r | |
499 | /**\r | |
500 | To check if FtwRecord is the first record of FtwHeader.\r | |
501 | \r | |
502 | @param FtwHeader Pointer to the write record header\r | |
503 | @param FtwRecord Pointer to the write record\r | |
504 | \r | |
505 | @retval TRUE FtwRecord is the first Record of the FtwHeader\r | |
506 | @retval FALSE FtwRecord is not the first Record of the FtwHeader\r | |
507 | \r | |
508 | **/\r | |
509 | BOOLEAN\r | |
510 | IsFirstRecordOfWrites (\r | |
1436aea4 MK |
511 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,\r |
512 | IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord\r | |
85e923a5 LG |
513 | );\r |
514 | \r | |
515 | /**\r | |
516 | To check if FtwRecord is the last record of FtwHeader. Because the\r | |
517 | FtwHeader has NumberOfWrites & PrivateDataSize, the FtwRecord can be\r | |
518 | determined if it is the last record of FtwHeader.\r | |
519 | \r | |
520 | @param FtwHeader Pointer to the write record header\r | |
521 | @param FtwRecord Pointer to the write record\r | |
522 | \r | |
523 | @retval TRUE FtwRecord is the last Record of the FtwHeader\r | |
524 | @retval FALSE FtwRecord is not the last Record of the FtwHeader\r | |
525 | \r | |
526 | **/\r | |
527 | BOOLEAN\r | |
528 | IsLastRecordOfWrites (\r | |
1436aea4 MK |
529 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,\r |
530 | IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord\r | |
85e923a5 LG |
531 | );\r |
532 | \r | |
533 | /**\r | |
534 | To check if FtwRecord is the first record of FtwHeader.\r | |
535 | \r | |
536 | @param FtwHeader Pointer to the write record header\r | |
537 | @param FtwRecord Pointer to retrieve the previous write record\r | |
538 | \r | |
539 | @retval EFI_ACCESS_DENIED Input record is the first record, no previous record is return.\r | |
540 | @retval EFI_SUCCESS The previous write record is found.\r | |
541 | \r | |
542 | **/\r | |
543 | EFI_STATUS\r | |
544 | GetPreviousRecordOfWrites (\r | |
1436aea4 MK |
545 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,\r |
546 | IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwRecord\r | |
85e923a5 LG |
547 | );\r |
548 | \r | |
549 | /**\r | |
550 | \r | |
551 | Check whether a flash buffer is erased.\r | |
552 | \r | |
553 | @param Buffer Buffer to check\r | |
554 | @param BufferSize Size of the buffer\r | |
555 | \r | |
556 | @return A BOOLEAN value indicating erased or not.\r | |
557 | \r | |
558 | **/\r | |
559 | BOOLEAN\r | |
560 | IsErasedFlashBuffer (\r | |
1436aea4 MK |
561 | IN UINT8 *Buffer,\r |
562 | IN UINTN BufferSize\r | |
85e923a5 | 563 | );\r |
1436aea4 | 564 | \r |
85e923a5 LG |
565 | /**\r |
566 | Initialize a work space when there is no work space.\r | |
567 | \r | |
568 | @param WorkingHeader Pointer of working block header\r | |
569 | \r | |
570 | @retval EFI_SUCCESS The function completed successfully\r | |
571 | @retval EFI_ABORTED The function could not complete successfully.\r | |
572 | \r | |
573 | **/\r | |
574 | EFI_STATUS\r | |
575 | InitWorkSpaceHeader (\r | |
1436aea4 | 576 | IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader\r |
85e923a5 | 577 | );\r |
1436aea4 | 578 | \r |
85e923a5 LG |
579 | /**\r |
580 | Read from working block to refresh the work space in memory.\r | |
581 | \r | |
582 | @param FtwDevice Point to private data of FTW driver\r | |
583 | \r | |
584 | @retval EFI_SUCCESS The function completed successfully\r | |
585 | @retval EFI_ABORTED The function could not complete successfully.\r | |
586 | \r | |
587 | **/\r | |
588 | EFI_STATUS\r | |
589 | WorkSpaceRefresh (\r | |
590 | IN EFI_FTW_DEVICE *FtwDevice\r | |
591 | );\r | |
1436aea4 | 592 | \r |
85e923a5 LG |
593 | /**\r |
594 | Check to see if it is a valid work space.\r | |
595 | \r | |
596 | \r | |
597 | @param WorkingHeader Pointer of working block header\r | |
598 | \r | |
599 | @retval EFI_SUCCESS The function completed successfully\r | |
600 | @retval EFI_ABORTED The function could not complete successfully.\r | |
601 | \r | |
602 | **/\r | |
603 | BOOLEAN\r | |
604 | IsValidWorkSpace (\r | |
1436aea4 | 605 | IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader\r |
85e923a5 | 606 | );\r |
1436aea4 | 607 | \r |
85e923a5 LG |
608 | /**\r |
609 | Reclaim the work space on the working block.\r | |
610 | \r | |
611 | @param FtwDevice Point to private data of FTW driver\r | |
612 | @param PreserveRecord Whether to preserve the working record is needed\r | |
613 | \r | |
614 | @retval EFI_SUCCESS The function completed successfully\r | |
615 | @retval EFI_OUT_OF_RESOURCES Allocate memory error\r | |
616 | @retval EFI_ABORTED The function could not complete successfully\r | |
617 | \r | |
618 | **/\r | |
619 | EFI_STATUS\r | |
620 | FtwReclaimWorkSpace (\r | |
621 | IN EFI_FTW_DEVICE *FtwDevice,\r | |
622 | IN BOOLEAN PreserveRecord\r | |
623 | );\r | |
624 | \r | |
625 | /**\r | |
626 | \r | |
0d3edd9d | 627 | Get firmware volume block by address.\r |
85e923a5 LG |
628 | \r |
629 | \r | |
630 | @param Address Address specified the block\r | |
631 | @param FvBlock The block caller wanted\r | |
632 | \r | |
633 | @retval EFI_SUCCESS The protocol instance if found.\r | |
634 | @retval EFI_NOT_FOUND Block not found\r | |
635 | \r | |
636 | **/\r | |
637 | EFI_HANDLE\r | |
638 | GetFvbByAddress (\r | |
1436aea4 MK |
639 | IN EFI_PHYSICAL_ADDRESS Address,\r |
640 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r | |
85e923a5 LG |
641 | );\r |
642 | \r | |
8a2d4996 | 643 | /**\r |
0a18956d | 644 | Retrieve the proper Swap Address Range protocol interface.\r |
8a2d4996 | 645 | \r |
646 | @param[out] SarProtocol The interface of SAR protocol\r | |
647 | \r | |
648 | @retval EFI_SUCCESS The SAR protocol instance was found and returned in SarProtocol.\r | |
649 | @retval EFI_NOT_FOUND The SAR protocol instance was not found.\r | |
650 | @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r | |
651 | \r | |
652 | **/\r | |
653 | EFI_STATUS\r | |
654 | FtwGetSarProtocol (\r | |
1436aea4 | 655 | OUT VOID **SarProtocol\r |
8a2d4996 | 656 | );\r |
d1102dba | 657 | \r |
8a2d4996 | 658 | /**\r |
659 | Function returns an array of handles that support the FVB protocol\r | |
d1102dba | 660 | in a buffer allocated from pool.\r |
8a2d4996 | 661 | \r |
662 | @param[out] NumberHandles The number of handles returned in Buffer.\r | |
663 | @param[out] Buffer A pointer to the buffer to return the requested\r | |
664 | array of handles that support FVB protocol.\r | |
665 | \r | |
666 | @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of\r | |
667 | handles in Buffer was returned in NumberHandles.\r | |
668 | @retval EFI_NOT_FOUND No FVB handle was found.\r | |
669 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.\r | |
670 | @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r | |
671 | \r | |
672 | **/\r | |
673 | EFI_STATUS\r | |
674 | GetFvbCountAndBuffer (\r | |
1436aea4 MK |
675 | OUT UINTN *NumberHandles,\r |
676 | OUT EFI_HANDLE **Buffer\r | |
8a2d4996 | 677 | );\r |
678 | \r | |
8a2d4996 | 679 | /**\r |
680 | Allocate private data for FTW driver and initialize it.\r | |
681 | \r | |
682 | @param[out] FtwData Pointer to the FTW device structure\r | |
683 | \r | |
684 | @retval EFI_SUCCESS Initialize the FTW device successfully.\r | |
685 | @retval EFI_OUT_OF_RESOURCES Allocate memory error\r | |
686 | @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist\r | |
687 | \r | |
688 | **/\r | |
689 | EFI_STATUS\r | |
690 | InitFtwDevice (\r | |
1436aea4 | 691 | OUT EFI_FTW_DEVICE **FtwData\r |
8a2d4996 | 692 | );\r |
693 | \r | |
8a2d4996 | 694 | /**\r |
695 | Initialization for Fault Tolerant Write is done in this handler.\r | |
696 | \r | |
32732a33 | 697 | @param[in, out] FtwDevice Pointer to the FTW device structure\r |
8a2d4996 | 698 | \r |
699 | @retval EFI_SUCCESS Initialize the FTW protocol successfully.\r | |
700 | @retval EFI_NOT_FOUND No proper FVB protocol was found.\r | |
d1102dba | 701 | \r |
8a2d4996 | 702 | **/\r |
703 | EFI_STATUS\r | |
704 | InitFtwProtocol (\r | |
1436aea4 | 705 | IN OUT EFI_FTW_DEVICE *FtwDevice\r |
8a2d4996 | 706 | );\r |
05cfd5f2 SZ |
707 | \r |
708 | /**\r | |
709 | Initialize a local work space header.\r | |
710 | \r | |
711 | Since Signature and WriteQueueSize have been known, Crc can be calculated out,\r | |
712 | then the work space header will be fixed.\r | |
8db39c60 MK |
713 | \r |
714 | @param[in] WorkSpaceLength Length in bytes of the FTW workspace area.\r | |
715 | \r | |
05cfd5f2 SZ |
716 | **/\r |
717 | VOID\r | |
718 | InitializeLocalWorkSpaceHeader (\r | |
8db39c60 | 719 | IN UINTN WorkSpaceLength\r |
05cfd5f2 | 720 | );\r |
0d3edd9d SZ |
721 | \r |
722 | /**\r | |
723 | Read work space data from work block or spare block.\r | |
724 | \r | |
725 | @param FvBlock FVB Protocol interface to access the block.\r | |
726 | @param BlockSize The size of the block.\r | |
727 | @param Lba Lba of the block.\r | |
728 | @param Offset The offset within the block.\r | |
729 | @param Length The number of bytes to read from the block.\r | |
730 | @param Buffer The data is read.\r | |
731 | \r | |
732 | @retval EFI_SUCCESS The function completed successfully.\r | |
733 | @retval EFI_ABORTED The function could not complete successfully.\r | |
734 | \r | |
735 | **/\r | |
736 | EFI_STATUS\r | |
737 | ReadWorkSpaceData (\r | |
1436aea4 MK |
738 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r |
739 | IN UINTN BlockSize,\r | |
740 | IN EFI_LBA Lba,\r | |
741 | IN UINTN Offset,\r | |
742 | IN UINTN Length,\r | |
743 | OUT UINT8 *Buffer\r | |
0d3edd9d SZ |
744 | );\r |
745 | \r | |
746 | /**\r | |
747 | Write data to work block.\r | |
748 | \r | |
749 | @param FvBlock FVB Protocol interface to access the block.\r | |
750 | @param BlockSize The size of the block.\r | |
751 | @param Lba Lba of the block.\r | |
752 | @param Offset The offset within the block to place the data.\r | |
753 | @param Length The number of bytes to write to the block.\r | |
754 | @param Buffer The data to write.\r | |
755 | \r | |
756 | @retval EFI_SUCCESS The function completed successfully.\r | |
757 | @retval EFI_ABORTED The function could not complete successfully.\r | |
758 | \r | |
759 | **/\r | |
760 | EFI_STATUS\r | |
761 | WriteWorkSpaceData (\r | |
1436aea4 MK |
762 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r |
763 | IN UINTN BlockSize,\r | |
764 | IN EFI_LBA Lba,\r | |
765 | IN UINTN Offset,\r | |
766 | IN UINTN Length,\r | |
767 | IN UINT8 *Buffer\r | |
0d3edd9d SZ |
768 | );\r |
769 | \r | |
22cedf5b AB |
770 | /**\r |
771 | Internal implementation of CRC32. Depending on the execution context\r | |
772 | (traditional SMM or DXE vs standalone MM), this function is implemented\r | |
773 | via a call to the CalculateCrc32 () boot service, or via a library\r | |
774 | call.\r | |
775 | \r | |
776 | If Buffer is NULL, then ASSERT().\r | |
777 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
778 | \r | |
779 | @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is\r | |
780 | to be computed.\r | |
781 | @param[in] Length The number of bytes in the buffer Data.\r | |
782 | \r | |
783 | @retval Crc32 The 32-bit CRC was computed for the data buffer.\r | |
784 | \r | |
785 | **/\r | |
786 | UINT32\r | |
787 | FtwCalculateCrc32 (\r | |
1436aea4 MK |
788 | IN VOID *Buffer,\r |
789 | IN UINTN Length\r | |
22cedf5b AB |
790 | );\r |
791 | \r | |
85e923a5 | 792 | #endif\r |