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