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