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