]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c
MdeModulePkg/FaultTolerantWriteSmmDxe: switch to MM communicate 2
[mirror_edk2.git] / MdeModulePkg / Universal / FaultTolerantWriteDxe / FaultTolerantWriteSmmDxe.c
CommitLineData
f3b80a8e 1/** @file\r
2\r
d1102dba 3 Implement the Fault Tolerant Write (FTW) protocol based on SMM FTW\r
f3b80a8e 4 module.\r
5\r
d1102dba 6Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved. <BR>\r
9d510e61 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
f3b80a8e 8\r
9**/\r
10\r
11#include "FaultTolerantWriteSmmDxe.h"\r
12\r
13EFI_HANDLE mHandle = NULL;\r
fa37a846 14EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;\r
f3b80a8e 15UINTN mPrivateDataSize = 0;\r
16\r
17EFI_FAULT_TOLERANT_WRITE_PROTOCOL mFaultTolerantWriteDriver = {\r
18 FtwGetMaxBlockSize,\r
19 FtwAllocate,\r
20 FtwWrite,\r
21 FtwRestart,\r
22 FtwAbort,\r
23 FtwGetLastWrite\r
24};\r
25\r
26/**\r
27 Initialize the communicate buffer using DataSize and Function number.\r
28\r
29 @param[out] CommunicateBuffer The communicate buffer. Caller should free it after use.\r
30 @param[out] DataPtr Points to the data in the communicate buffer. Caller should not free it.\r
31 @param[in] DataSize The payload size.\r
32 @param[in] Function The function number used to initialize the communicate header.\r
33\r
34**/\r
35VOID\r
36InitCommunicateBuffer (\r
37 OUT VOID **CommunicateBuffer,\r
38 OUT VOID **DataPtr,\r
39 IN UINTN DataSize,\r
40 IN UINTN Function\r
41 )\r
42{\r
fa37a846 43 EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;\r
d1102dba 44 SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;\r
f3b80a8e 45\r
46 //\r
47 // The whole buffer size: SMM_COMMUNICATE_HEADER_SIZE + SMM_FTW_COMMUNICATE_HEADER_SIZE + DataSize.\r
48 //\r
49 SmmCommunicateHeader = AllocateZeroPool (DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_FTW_COMMUNICATE_HEADER_SIZE);\r
50 ASSERT (SmmCommunicateHeader != NULL);\r
d1102dba 51\r
f3b80a8e 52 //\r
53 // Prepare data buffer.\r
54 //\r
55 CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmFaultTolerantWriteProtocolGuid);\r
56 SmmCommunicateHeader->MessageLength = DataSize + SMM_FTW_COMMUNICATE_HEADER_SIZE;\r
d1102dba 57\r
f3b80a8e 58 SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *) SmmCommunicateHeader->Data;\r
59 SmmFtwFunctionHeader->Function = Function;\r
60\r
61 *CommunicateBuffer = SmmCommunicateHeader;\r
62 if (DataPtr != NULL) {\r
63 *DataPtr = SmmFtwFunctionHeader->Data;\r
d1102dba 64 }\r
f3b80a8e 65}\r
66\r
67\r
68/**\r
69 Send the data in communicate buffer to SMI handler and get response.\r
70\r
a02ab69a 71 @param[in, out] SmmCommunicateHeader The communicate buffer.\r
f3b80a8e 72 @param[in] DataSize The payload size.\r
d1102dba 73\r
f3b80a8e 74**/\r
75EFI_STATUS\r
76SendCommunicateBuffer (\r
fa37a846 77 IN OUT EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader,\r
f3b80a8e 78 IN UINTN DataSize\r
79 )\r
80{\r
81 EFI_STATUS Status;\r
82 UINTN CommSize;\r
d1102dba
LG
83 SMM_FTW_COMMUNICATE_FUNCTION_HEADER *SmmFtwFunctionHeader;\r
84\r
f3b80a8e 85 CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_FTW_COMMUNICATE_HEADER_SIZE;\r
fa37a846
AB
86 Status = mMmCommunication2->Communicate (mMmCommunication2,\r
87 SmmCommunicateHeader,\r
88 SmmCommunicateHeader,\r
89 &CommSize);\r
f3b80a8e 90 ASSERT_EFI_ERROR (Status);\r
91\r
92 SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *) SmmCommunicateHeader->Data;\r
93 return SmmFtwFunctionHeader->ReturnStatus;\r
94}\r
95\r
96\r
97/**\r
98 Get the FvbBaseAddress and FvbAttributes from the FVB handle FvbHandle.\r
99\r
a02ab69a 100 @param[in] FvbHandle The handle of FVB protocol that provides services.\r
101 @param[out] FvbBaseAddress The base address of the FVB attached with FvbHandle.\r
102 @param[out] FvbAttributes The attributes of the FVB attached with FvbHandle.\r
d1102dba 103\r
f3b80a8e 104 @retval EFI_SUCCESS The function completed successfully.\r
105 @retval Others The function could not complete successfully.\r
106\r
107**/\r
108EFI_STATUS\r
109ConvertFvbHandle (\r
110 IN EFI_HANDLE FvbHandle,\r
111 OUT EFI_PHYSICAL_ADDRESS *FvbBaseAddress,\r
112 OUT EFI_FVB_ATTRIBUTES_2 *FvbAttributes\r
113 )\r
114{\r
115 EFI_STATUS Status;\r
116 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r
117\r
118 Status = gBS->HandleProtocol (FvbHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **) &Fvb);\r
119 if (EFI_ERROR (Status)) {\r
120 return Status;\r
121 }\r
d1102dba 122\r
f3b80a8e 123 Status = Fvb->GetPhysicalAddress (Fvb, FvbBaseAddress);\r
124 if (EFI_ERROR (Status)) {\r
125 return Status;\r
126 }\r
127\r
128 Status = Fvb->GetAttributes (Fvb, FvbAttributes);\r
d1102dba 129 return Status;\r
f3b80a8e 130}\r
131\r
132\r
133/**\r
134 Get the size of the largest block that can be updated in a fault-tolerant manner.\r
135\r
136 @param[in] This Indicates a pointer to the calling context.\r
137 @param[out] BlockSize A pointer to a caller-allocated UINTN that is\r
138 updated to indicate the size of the largest block\r
139 that can be updated.\r
140\r
141 @retval EFI_SUCCESS The function completed successfully.\r
142 @retval EFI_ABORTED The function could not complete successfully.\r
143\r
144**/\r
145EFI_STATUS\r
146EFIAPI\r
147FtwGetMaxBlockSize (\r
148 IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r
149 OUT UINTN *BlockSize\r
150 )\r
151{\r
152 EFI_STATUS Status;\r
153 UINTN PayloadSize;\r
fa37a846 154 EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;\r
f3b80a8e 155 SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *SmmFtwBlockSizeHeader;\r
156\r
157 //\r
158 // Initialize the communicate buffer.\r
159 //\r
160 PayloadSize = sizeof (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER);\r
161 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwBlockSizeHeader, PayloadSize, FTW_FUNCTION_GET_MAX_BLOCK_SIZE);\r
d1102dba 162\r
f3b80a8e 163 //\r
164 // Send data to SMM.\r
165 //\r
166 Status = SendCommunicateBuffer (SmmCommunicateHeader, PayloadSize);\r
167\r
168 //\r
169 // Get data from SMM\r
170 //\r
d1102dba 171 *BlockSize = SmmFtwBlockSizeHeader->BlockSize;\r
f3b80a8e 172 FreePool (SmmCommunicateHeader);\r
d1102dba 173\r
f3b80a8e 174 return Status;\r
175}\r
176\r
177\r
178/**\r
179 Allocates space for the protocol to maintain information about writes.\r
180 Since writes must be completed in a fault-tolerant manner and multiple\r
181 writes require more resources to be successful, this function\r
182 enables the protocol to ensure that enough space exists to track\r
183 information about upcoming writes.\r
184\r
185 @param[in] This A pointer to the calling context.\r
186 @param[in] CallerId The GUID identifying the write.\r
187 @param[in] PrivateDataSize The size of the caller's private data that must be\r
188 recorded for each write.\r
189 @param[in] NumberOfWrites The number of fault tolerant block writes that will\r
190 need to occur.\r
191\r
192 @retval EFI_SUCCESS The function completed successfully\r
193 @retval EFI_ABORTED The function could not complete successfully.\r
194 @retval EFI_ACCESS_DENIED Not all allocated writes have been completed. All\r
195 writes must be completed or aborted before another\r
196 fault tolerant write can occur.\r
197\r
198**/\r
199EFI_STATUS\r
200EFIAPI\r
201FtwAllocate (\r
202 IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r
203 IN EFI_GUID *CallerId,\r
204 IN UINTN PrivateDataSize,\r
205 IN UINTN NumberOfWrites\r
206 )\r
207{\r
208 EFI_STATUS Status;\r
209 UINTN PayloadSize;\r
fa37a846 210 EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;\r
f3b80a8e 211 SMM_FTW_ALLOCATE_HEADER *SmmFtwAllocateHeader;\r
212\r
213 //\r
214 // Initialize the communicate buffer.\r
215 //\r
216 PayloadSize = sizeof (SMM_FTW_ALLOCATE_HEADER);\r
217 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwAllocateHeader, PayloadSize, FTW_FUNCTION_ALLOCATE);\r
218 CopyGuid (&SmmFtwAllocateHeader->CallerId, CallerId);\r
219 SmmFtwAllocateHeader->PrivateDataSize = PrivateDataSize;\r
d1102dba
LG
220 SmmFtwAllocateHeader->NumberOfWrites = NumberOfWrites;\r
221\r
f3b80a8e 222 //\r
223 // Send data to SMM.\r
224 //\r
225 Status = SendCommunicateBuffer (SmmCommunicateHeader, PayloadSize);\r
226 if (!EFI_ERROR( Status)) {\r
227 mPrivateDataSize = PrivateDataSize;\r
228 }\r
229\r
230 FreePool (SmmCommunicateHeader);\r
231 return Status;\r
232}\r
233\r
234\r
235/**\r
236 Starts a target block update. This records information about the write\r
237 in fault tolerant storage, and will complete the write in a recoverable\r
238 manner, ensuring at all times that either the original contents or\r
239 the modified contents are available.\r
240\r
241 @param[in] This The calling context.\r
242 @param[in] Lba The logical block address of the target block.\r
243 @param[in] Offset The offset within the target block to place the\r
244 data.\r
245 @param[in] Length The number of bytes to write to the target block.\r
246 @param[in] PrivateData A pointer to private data that the caller requires\r
247 to complete any pending writes in the event of a\r
248 fault.\r
249 @param[in] FvBlockHandle The handle of FVB protocol that provides services\r
250 for reading, writing, and erasing the target block.\r
251 @param[in] Buffer The data to write.\r
252\r
253 @retval EFI_SUCCESS The function completed successfully.\r
254 @retval EFI_ABORTED The function could not complete successfully.\r
255 @retval EFI_BAD_BUFFER_SIZE The write would span a block boundary, which is not\r
256 a valid action.\r
257 @retval EFI_ACCESS_DENIED No writes have been allocated.\r
258 @retval EFI_NOT_READY The last write has not been completed. Restart()\r
259 must be called to complete it.\r
260\r
261**/\r
262EFI_STATUS\r
263EFIAPI\r
264FtwWrite (\r
265 IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r
266 IN EFI_LBA Lba,\r
267 IN UINTN Offset,\r
268 IN UINTN Length,\r
269 IN VOID *PrivateData,\r
270 IN EFI_HANDLE FvBlockHandle,\r
271 IN VOID *Buffer\r
272 )\r
273{\r
274 EFI_STATUS Status;\r
275 UINTN PayloadSize;\r
fa37a846 276 EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;\r
f3b80a8e 277 SMM_FTW_WRITE_HEADER *SmmFtwWriteHeader;\r
278\r
279 //\r
280 // Initialize the communicate buffer.\r
281 //\r
282 PayloadSize = OFFSET_OF (SMM_FTW_WRITE_HEADER, Data) + Length;\r
283 if (PrivateData != NULL) {\r
284 //\r
285 // The private data buffer size should be the same one in FtwAllocate API.\r
286 //\r
287 PayloadSize += mPrivateDataSize;\r
288 }\r
289 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwWriteHeader, PayloadSize, FTW_FUNCTION_WRITE);\r
290\r
291 //\r
d1102dba 292 // FvBlockHandle can not be used in SMM environment. Here we get the FVB protocol first, then get FVB base address\r
f3b80a8e 293 // and its attribute. Send these information to SMM handler, the SMM handler will find the proper FVB to write data.\r
294 //\r
295 Status = ConvertFvbHandle (FvBlockHandle, &SmmFtwWriteHeader->FvbBaseAddress, &SmmFtwWriteHeader->FvbAttributes);\r
296 if (EFI_ERROR (Status)) {\r
297 FreePool (SmmCommunicateHeader);\r
298 return EFI_ABORTED;\r
299 }\r
d1102dba 300\r
f3b80a8e 301 SmmFtwWriteHeader->Lba = Lba;\r
d1102dba 302 SmmFtwWriteHeader->Offset = Offset;\r
f3b80a8e 303 SmmFtwWriteHeader->Length = Length;\r
304 CopyMem (SmmFtwWriteHeader->Data, Buffer, Length);\r
305 if (PrivateData == NULL) {\r
306 SmmFtwWriteHeader->PrivateDataSize = 0;\r
307 } else {\r
308 SmmFtwWriteHeader->PrivateDataSize = mPrivateDataSize;\r
309 CopyMem (&SmmFtwWriteHeader->Data[Length], PrivateData, mPrivateDataSize);\r
310 }\r
311\r
312 //\r
313 // Send data to SMM.\r
314 //\r
315 Status = SendCommunicateBuffer (SmmCommunicateHeader, PayloadSize);\r
d1102dba 316 FreePool (SmmCommunicateHeader);\r
f3b80a8e 317 return Status;\r
318}\r
319\r
320\r
321/**\r
322 Restarts a previously interrupted write. The caller must provide the\r
323 block protocol needed to complete the interrupted write.\r
324\r
325 @param[in] This The calling context.\r
326 @param[in] FvBlockHandle The handle of FVB protocol that provides services.\r
327\r
328 @retval EFI_SUCCESS The function completed successfully.\r
329 @retval EFI_ABORTED The function could not complete successfully.\r
330 @retval EFI_ACCESS_DENIED No pending writes exist.\r
331\r
332**/\r
333EFI_STATUS\r
334EFIAPI\r
335FtwRestart (\r
336 IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r
337 IN EFI_HANDLE FvBlockHandle\r
338 )\r
339{\r
340 EFI_STATUS Status;\r
341 UINTN PayloadSize;\r
fa37a846 342 EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;\r
f3b80a8e 343 SMM_FTW_RESTART_HEADER *SmmFtwRestartHeader;\r
d1102dba 344\r
f3b80a8e 345 //\r
346 // Initialize the communicate buffer.\r
347 //\r
348 PayloadSize = sizeof (SMM_FTW_RESTART_HEADER);\r
d1102dba 349 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwRestartHeader, PayloadSize, FTW_FUNCTION_RESTART);\r
f3b80a8e 350\r
351 //\r
d1102dba 352 // FvBlockHandle can not be used in SMM environment. Here we get the FVB protocol first, then get FVB base address\r
f3b80a8e 353 // and its attribute. Send these information to SMM handler, the SMM handler will find the proper FVB to write data.\r
354 //\r
355 Status = ConvertFvbHandle (FvBlockHandle, &SmmFtwRestartHeader->FvbBaseAddress, &SmmFtwRestartHeader->FvbAttributes);\r
356 if (EFI_ERROR (Status)) {\r
d1102dba 357 FreePool (SmmCommunicateHeader);\r
f3b80a8e 358 return EFI_ABORTED;\r
359 }\r
360\r
361 //\r
362 // Send data to SMM.\r
363 //\r
364 Status = SendCommunicateBuffer (SmmCommunicateHeader, PayloadSize);\r
d1102dba 365 FreePool (SmmCommunicateHeader);\r
f3b80a8e 366 return Status;\r
367}\r
368\r
369\r
370/**\r
371 Aborts all previously allocated writes.\r
372\r
373 @param[in] This The calling context.\r
374\r
375 @retval EFI_SUCCESS The function completed successfully.\r
376 @retval EFI_ABORTED The function could not complete successfully.\r
377 @retval EFI_NOT_FOUND No allocated writes exist.\r
378\r
379**/\r
380EFI_STATUS\r
381EFIAPI\r
382FtwAbort (\r
383 IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This\r
384 )\r
385{\r
386 EFI_STATUS Status;\r
fa37a846 387 EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;\r
d1102dba 388\r
f3b80a8e 389 //\r
390 // Initialize the communicate buffer.\r
391 //\r
392 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, NULL, 0, FTW_FUNCTION_ABORT);\r
d1102dba 393\r
f3b80a8e 394 //\r
395 // Send data to SMM.\r
396 //\r
397 Status = SendCommunicateBuffer (SmmCommunicateHeader, 0);\r
398\r
d1102dba 399 FreePool (SmmCommunicateHeader);\r
f3b80a8e 400 return Status;\r
401}\r
402\r
403\r
404/**\r
405 Starts a target block update. This function records information about the write\r
406 in fault-tolerant storage and completes the write in a recoverable\r
407 manner, ensuring at all times that either the original contents or\r
408 the modified contents are available.\r
409\r
410 @param[in] This Indicates a pointer to the calling context.\r
411 @param[out] CallerId The GUID identifying the last write.\r
412 @param[out] Lba The logical block address of the last write.\r
413 @param[out] Offset The offset within the block of the last write.\r
414 @param[out] Length The length of the last write.\r
415 @param[in, out] PrivateDataSize On input, the size of the PrivateData buffer. On\r
416 output, the size of the private data stored for\r
417 this write.\r
418 @param[out] PrivateData A pointer to a buffer. The function will copy\r
419 PrivateDataSize bytes from the private data stored\r
420 for this write.\r
421 @param[out] Complete A Boolean value with TRUE indicating that the write\r
422 was completed.\r
423\r
424 @retval EFI_SUCCESS The function completed successfully.\r
425 @retval EFI_ABORTED The function could not complete successfully.\r
426 @retval EFI_NOT_FOUND No allocated writes exist.\r
427\r
428**/\r
429EFI_STATUS\r
430EFIAPI\r
431FtwGetLastWrite (\r
432 IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,\r
433 OUT EFI_GUID *CallerId,\r
434 OUT EFI_LBA *Lba,\r
435 OUT UINTN *Offset,\r
436 OUT UINTN *Length,\r
437 IN OUT UINTN *PrivateDataSize,\r
438 OUT VOID *PrivateData,\r
439 OUT BOOLEAN *Complete\r
440 )\r
441{\r
442 EFI_STATUS Status;\r
443 UINTN PayloadSize;\r
fa37a846 444 EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader;\r
f3b80a8e 445 SMM_FTW_GET_LAST_WRITE_HEADER *SmmFtwGetLastWriteHeader;\r
446\r
447 //\r
448 // Initialize the communicate buffer.\r
449 //\r
450 PayloadSize = OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data) + *PrivateDataSize;\r
451 InitCommunicateBuffer ((VOID **)&SmmCommunicateHeader, (VOID **)&SmmFtwGetLastWriteHeader, PayloadSize, FTW_FUNCTION_GET_LAST_WRITE);\r
452 SmmFtwGetLastWriteHeader->PrivateDataSize = *PrivateDataSize;\r
453\r
454 //\r
455 // Send data to SMM.\r
456 //\r
457 Status = SendCommunicateBuffer (SmmCommunicateHeader, PayloadSize);\r
458\r
459 //\r
460 // Get data from SMM\r
461 //\r
462 *PrivateDataSize = SmmFtwGetLastWriteHeader->PrivateDataSize;\r
5e5bb2a9 463 if (Status == EFI_SUCCESS || Status == EFI_BUFFER_TOO_SMALL) {\r
f3b80a8e 464 *Lba = SmmFtwGetLastWriteHeader->Lba;\r
d1102dba 465 *Offset = SmmFtwGetLastWriteHeader->Offset;\r
f3b80a8e 466 *Length = SmmFtwGetLastWriteHeader->Length;\r
467 *Complete = SmmFtwGetLastWriteHeader->Complete;\r
468 CopyGuid (CallerId, &SmmFtwGetLastWriteHeader->CallerId);\r
5e5bb2a9
SZ
469 if (Status == EFI_SUCCESS) {\r
470 CopyMem (PrivateData, SmmFtwGetLastWriteHeader->Data, *PrivateDataSize);\r
471 }\r
472 } else if (Status == EFI_NOT_FOUND) {\r
473 *Complete = SmmFtwGetLastWriteHeader->Complete;\r
f3b80a8e 474 }\r
475\r
d1102dba 476 FreePool (SmmCommunicateHeader);\r
f3b80a8e 477 return Status;\r
478}\r
479\r
480/**\r
481 SMM Fault Tolerant Write Protocol notification event handler.\r
482\r
483 Install Fault Tolerant Write Protocol.\r
484\r
485 @param[in] Event Event whose notification function is being invoked.\r
486 @param[in] Context Pointer to the notification function's context.\r
487**/\r
488VOID\r
489EFIAPI\r
490SmmFtwReady (\r
491 IN EFI_EVENT Event,\r
492 IN VOID *Context\r
493 )\r
494{\r
495 EFI_STATUS Status;\r
496 EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r
497\r
498 //\r
499 // Just return to avoid install SMM FaultTolerantWriteProtocol again\r
500 // if Fault Tolerant Write protocol had been installed.\r
d1102dba 501 //\r
f3b80a8e 502 Status = gBS->LocateProtocol (&gEfiFaultTolerantWriteProtocolGuid, NULL, (VOID **)&FtwProtocol);\r
503 if (!EFI_ERROR (Status)) {\r
504 return;\r
505 }\r
d1102dba 506\r
fa37a846 507 Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **) &mMmCommunication2);\r
f3b80a8e 508 ASSERT_EFI_ERROR (Status);\r
509\r
510 //\r
511 // Install protocol interface\r
512 //\r
513 Status = gBS->InstallProtocolInterface (\r
514 &mHandle,\r
515 &gEfiFaultTolerantWriteProtocolGuid,\r
516 EFI_NATIVE_INTERFACE,\r
517 &mFaultTolerantWriteDriver\r
518 );\r
519 ASSERT_EFI_ERROR (Status);\r
d1102dba 520\r
f3b80a8e 521 Status = gBS->CloseEvent (Event);\r
d1102dba 522 ASSERT_EFI_ERROR (Status);\r
f3b80a8e 523}\r
524\r
525\r
526/**\r
527 The driver entry point for Fault Tolerant Write driver.\r
528\r
529 The function does the necessary initialization work.\r
530\r
531 @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r
532 @param[in] SystemTable A pointer to the EFI system table.\r
533\r
534 @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.\r
535\r
536**/\r
537EFI_STATUS\r
538EFIAPI\r
539FaultTolerantWriteSmmInitialize (\r
540 IN EFI_HANDLE ImageHandle,\r
541 IN EFI_SYSTEM_TABLE *SystemTable\r
542 )\r
543{\r
544 VOID *SmmFtwRegistration;\r
545\r
546 //\r
547 // Smm FTW driver is ready\r
548 //\r
549 EfiCreateProtocolNotifyEvent (\r
550 &gEfiSmmFaultTolerantWriteProtocolGuid,\r
d1102dba
LG
551 TPL_CALLBACK,\r
552 SmmFtwReady,\r
553 NULL,\r
f3b80a8e 554 &SmmFtwRegistration\r
555 );\r
d1102dba 556\r
f3b80a8e 557 return EFI_SUCCESS;\r
558}\r
559\r