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