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