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