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