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