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