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