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