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