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