]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c
IntelFrameworkModulePkg KbDxe: Execute key notify func at TPL_CALLBACK
[mirror_edk2.git] / UefiCpuPkg / Feature / Capsule / MicrocodeUpdateDxe / MicrocodeFmp.c
... / ...
CommitLineData
1/** @file\r
2 Produce FMP instance for Microcode.\r
3\r
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "MicrocodeUpdate.h"\r
16\r
17//\r
18// MicrocodeFmp driver private data\r
19//\r
20MICROCODE_FMP_PRIVATE_DATA *mMicrocodeFmpPrivate = NULL;\r
21\r
22EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol = {\r
23 FmpGetImageInfo,\r
24 FmpGetImage,\r
25 FmpSetImage,\r
26 FmpCheckImage,\r
27 FmpGetPackageInfo,\r
28 FmpSetPackageInfo\r
29};\r
30\r
31/**\r
32 Initialize Microcode Descriptor.\r
33\r
34 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
35\r
36 @return EFI_SUCCESS Microcode Descriptor is initialized.\r
37**/\r
38EFI_STATUS\r
39InitializeMicrocodeDescriptor (\r
40 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
41 );\r
42\r
43/**\r
44 Returns information about the current firmware image(s) of the device.\r
45\r
46 This function allows a copy of the current firmware image to be created and saved.\r
47 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
48\r
49 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
50 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.\r
51 On input, this is the size of the buffer allocated by the caller.\r
52 On output, it is the size of the buffer returned by the firmware\r
53 if the buffer was large enough, or the size of the buffer needed\r
54 to contain the image(s) information if the buffer was too small.\r
55 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)\r
56 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
57 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number\r
58 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
59 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of\r
60 descriptors or firmware images within this device.\r
61 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,\r
62 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
63 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
64 The format is vendor specific and new version must have a greater value\r
65 than the old version. If PackageVersion is not supported, the value is\r
66 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
67 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
68 that package version update is in progress.\r
69 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
70 package version name. The buffer is allocated by this function with\r
71 AllocatePool(), and it is the caller's responsibility to free it with a call\r
72 to FreePool().\r
73\r
74 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
75 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size\r
76 needed to hold the image(s) information is returned in ImageInfoSize.\r
77 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.\r
78 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.\r
79\r
80**/\r
81EFI_STATUS\r
82EFIAPI\r
83FmpGetImageInfo (\r
84 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
85 IN OUT UINTN *ImageInfoSize,\r
86 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,\r
87 OUT UINT32 *DescriptorVersion,\r
88 OUT UINT8 *DescriptorCount,\r
89 OUT UINTN *DescriptorSize,\r
90 OUT UINT32 *PackageVersion,\r
91 OUT CHAR16 **PackageVersionName\r
92 )\r
93{\r
94 MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
95 UINTN Index;\r
96\r
97 MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
98\r
99 if(ImageInfoSize == NULL) {\r
100 return EFI_INVALID_PARAMETER;\r
101 }\r
102\r
103 if (*ImageInfoSize < sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount) {\r
104 *ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r
105 return EFI_BUFFER_TOO_SMALL;\r
106 }\r
107\r
108 if (ImageInfo == NULL ||\r
109 DescriptorVersion == NULL ||\r
110 DescriptorCount == NULL ||\r
111 DescriptorSize == NULL ||\r
112 PackageVersion == NULL ||\r
113 PackageVersionName == NULL) {\r
114 return EFI_INVALID_PARAMETER;\r
115 }\r
116\r
117 *ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r
118 *DescriptorSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r
119 *DescriptorCount = MicrocodeFmpPrivate->DescriptorCount;\r
120 *DescriptorVersion = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;\r
121\r
122 //\r
123 // supports 1 ImageInfo descriptor\r
124 //\r
125 CopyMem(&ImageInfo[0], MicrocodeFmpPrivate->ImageDescriptor, sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount);\r
126 for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
127 if ((ImageInfo[Index].AttributesSetting & IMAGE_ATTRIBUTE_IN_USE) != 0) {\r
128 ImageInfo[Index].LastAttemptVersion = MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion;\r
129 ImageInfo[Index].LastAttemptStatus = MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus;\r
130 }\r
131 }\r
132\r
133 //\r
134 // package version\r
135 //\r
136 *PackageVersion = MicrocodeFmpPrivate->PackageVersion;\r
137 if (MicrocodeFmpPrivate->PackageVersionName != NULL) {\r
138 *PackageVersionName = AllocateCopyPool(StrSize(MicrocodeFmpPrivate->PackageVersionName), MicrocodeFmpPrivate->PackageVersionName);\r
139 }\r
140\r
141 return EFI_SUCCESS;\r
142}\r
143\r
144/**\r
145 Retrieves a copy of the current firmware image of the device.\r
146\r
147 This function allows a copy of the current firmware image to be created and saved.\r
148 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
149\r
150 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
151 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
152 The number is between 1 and DescriptorCount.\r
153 @param[in,out] Image Points to the buffer where the current image is copied to.\r
154 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.\r
155 On return, points to the length of the image, in bytes.\r
156\r
157 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
158 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the\r
159 image. The current buffer size needed to hold the image is returned\r
160 in ImageSize.\r
161 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
162 @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r
163 @retval EFI_UNSUPPORTED The operation is not supported.\r
164 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
165\r
166**/\r
167EFI_STATUS\r
168EFIAPI\r
169FmpGetImage (\r
170 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
171 IN UINT8 ImageIndex,\r
172 IN OUT VOID *Image,\r
173 IN OUT UINTN *ImageSize\r
174 )\r
175{\r
176 MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
177 EFI_STATUS Status;\r
178\r
179 if (Image == NULL || ImageSize == NULL) {\r
180 return EFI_INVALID_PARAMETER;\r
181 }\r
182\r
183 MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
184\r
185 if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || ImageSize == NULL || Image == NULL) {\r
186 return EFI_INVALID_PARAMETER;\r
187 }\r
188\r
189 Status = MicrocodeRead(ImageIndex, (VOID *)Image, ImageSize);\r
190 return Status;\r
191}\r
192\r
193/**\r
194 Updates the firmware image of the device.\r
195\r
196 This function updates the hardware with the new firmware image.\r
197 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
198 If the firmware image is updatable, the function should perform the following minimal validations\r
199 before proceeding to do the firmware image update.\r
200 - Validate the image authentication if image has attribute\r
201 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
202 EFI_SECURITY_VIOLATION if the validation fails.\r
203 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
204 the image is unsupported. The function can optionally provide more detailed information on\r
205 why the image is not a supported image.\r
206 - Validate the data from VendorCode if not null. Image validation must be performed before\r
207 VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
208 validation failed. The function returns EFI_ABORTED if the data is invalid.\r
209\r
210 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
211 the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
212 a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
213 firmware image version is older than the current firmware image version or bad image checksum.\r
214 Sensitive operations such as those wiping the entire firmware image and render the device to be\r
215 non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
216 AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
217 reason to the caller.\r
218\r
219 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
220 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
221 The number is between 1 and DescriptorCount.\r
222 @param[in] Image Points to the new image.\r
223 @param[in] ImageSize Size of the new image in bytes.\r
224 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r
225 Null indicates the caller did not specify the policy or use the default policy.\r
226 @param[in] Progress A function used by the driver to report the progress of the firmware update.\r
227 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r
228 details for the aborted operation. The buffer is allocated by this function\r
229 with AllocatePool(), and it is the caller's responsibility to free it with a\r
230 call to FreePool().\r
231\r
232 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
233 @retval EFI_ABORTED The operation is aborted.\r
234 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
235 @retval EFI_UNSUPPORTED The operation is not supported.\r
236 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
237\r
238**/\r
239EFI_STATUS\r
240EFIAPI\r
241FmpSetImage (\r
242 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
243 IN UINT8 ImageIndex,\r
244 IN CONST VOID *Image,\r
245 IN UINTN ImageSize,\r
246 IN CONST VOID *VendorCode,\r
247 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r
248 OUT CHAR16 **AbortReason\r
249 )\r
250{\r
251 EFI_STATUS Status;\r
252 EFI_STATUS VarStatus;\r
253 MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
254\r
255 if (Image == NULL || AbortReason == NULL) {\r
256 return EFI_INVALID_PARAMETER;\r
257 }\r
258\r
259 MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
260 *AbortReason = NULL;\r
261\r
262 if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || Image == NULL) {\r
263 return EFI_INVALID_PARAMETER;\r
264 }\r
265\r
266 Status = MicrocodeWrite(ImageIndex, (VOID *)Image, ImageSize, &MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, &MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus, AbortReason);\r
267 DEBUG((DEBUG_INFO, "SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
268 VarStatus = gRT->SetVariable(\r
269 MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
270 &gEfiCallerIdGuid,\r
271 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
272 sizeof(MicrocodeFmpPrivate->LastAttempt),\r
273 &MicrocodeFmpPrivate->LastAttempt\r
274 );\r
275 DEBUG((DEBUG_INFO, "SetLastAttemp - %r\n", VarStatus));\r
276\r
277 if (!EFI_ERROR(Status)) {\r
278 InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
279 }\r
280\r
281 return Status;\r
282}\r
283\r
284/**\r
285 Checks if the firmware image is valid for the device.\r
286\r
287 This function allows firmware update application to validate the firmware image without\r
288 invoking the SetImage() first.\r
289\r
290 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
291 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
292 The number is between 1 and DescriptorCount.\r
293 @param[in] Image Points to the new image.\r
294 @param[in] ImageSize Size of the new image in bytes.\r
295 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r
296 if available, additional information if the image is invalid.\r
297\r
298 @retval EFI_SUCCESS The image was successfully checked.\r
299 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
300 @retval EFI_UNSUPPORTED The operation is not supported.\r
301 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
302\r
303**/\r
304EFI_STATUS\r
305EFIAPI\r
306FmpCheckImage (\r
307 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
308 IN UINT8 ImageIndex,\r
309 IN CONST VOID *Image,\r
310 IN UINTN ImageSize,\r
311 OUT UINT32 *ImageUpdatable\r
312 )\r
313{\r
314 return EFI_UNSUPPORTED;\r
315}\r
316\r
317/**\r
318 Returns information about the firmware package.\r
319\r
320 This function returns package information.\r
321\r
322 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
323 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
324 The format is vendor specific and new version must have a greater value\r
325 than the old version. If PackageVersion is not supported, the value is\r
326 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
327 comparison is to be performed using PackageVersionName. A value of\r
328 0xFFFFFFFD indicates that package version update is in progress.\r
329 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r
330 the package version name. The buffer is allocated by this function with\r
331 AllocatePool(), and it is the caller's responsibility to free it with a\r
332 call to FreePool().\r
333 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
334 package version name. A value of 0 indicates the device does not support\r
335 update of package version name. Length is the number of Unicode characters,\r
336 including the terminating null character.\r
337 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r
338 Definitions' for possible returned values of this parameter. A value of 1\r
339 indicates the attribute is supported and the current setting value is\r
340 indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
341 supported and the current setting value in AttributesSetting is meaningless.\r
342 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r
343 values of this parameter\r
344\r
345 @retval EFI_SUCCESS The package information was successfully returned.\r
346 @retval EFI_UNSUPPORTED The operation is not supported.\r
347\r
348**/\r
349EFI_STATUS\r
350EFIAPI\r
351FmpGetPackageInfo (\r
352 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
353 OUT UINT32 *PackageVersion,\r
354 OUT CHAR16 **PackageVersionName,\r
355 OUT UINT32 *PackageVersionNameMaxLen,\r
356 OUT UINT64 *AttributesSupported,\r
357 OUT UINT64 *AttributesSetting\r
358 )\r
359{\r
360 return EFI_UNSUPPORTED;\r
361}\r
362\r
363/**\r
364 Updates information about the firmware package.\r
365\r
366 This function updates package information.\r
367 This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
368 VendorCode enables vendor to implement vendor-specific package information update policy.\r
369 Null if the caller did not specify this policy or use the default policy.\r
370\r
371 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
372 @param[in] Image Points to the authentication image.\r
373 Null if authentication is not required.\r
374 @param[in] ImageSize Size of the authentication image in bytes.\r
375 0 if authentication is not required.\r
376 @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r
377 image update policy.\r
378 Null indicates the caller did not specify this policy or use\r
379 the default policy.\r
380 @param[in] PackageVersion The new package version.\r
381 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r
382 the package version name.\r
383 The string length is equal to or less than the value returned in\r
384 PackageVersionNameMaxLen.\r
385\r
386 @retval EFI_SUCCESS The device was successfully updated with the new package\r
387 information.\r
388 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r
389 returned in PackageVersionNameMaxLen.\r
390 @retval EFI_UNSUPPORTED The operation is not supported.\r
391 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
392\r
393**/\r
394EFI_STATUS\r
395EFIAPI\r
396FmpSetPackageInfo (\r
397 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
398 IN CONST VOID *Image,\r
399 IN UINTN ImageSize,\r
400 IN CONST VOID *VendorCode,\r
401 IN UINT32 PackageVersion,\r
402 IN CONST CHAR16 *PackageVersionName\r
403 )\r
404{\r
405 return EFI_UNSUPPORTED;\r
406}\r
407\r
408/**\r
409 Initialize Microcode Descriptor.\r
410\r
411 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
412\r
413 @return EFI_SUCCESS Microcode Descriptor is initialized.\r
414**/\r
415EFI_STATUS\r
416InitializeMicrocodeDescriptor (\r
417 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
418 )\r
419{\r
420 UINT8 CurrentMicrocodeCount;\r
421\r
422 CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo(NULL, 0);\r
423\r
424 if (CurrentMicrocodeCount > MicrocodeFmpPrivate->DescriptorCount) {\r
425 if (MicrocodeFmpPrivate->ImageDescriptor != NULL) {\r
426 FreePool(MicrocodeFmpPrivate->ImageDescriptor);\r
427 MicrocodeFmpPrivate->ImageDescriptor = NULL;\r
428 }\r
429 } else {\r
430 ZeroMem(MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
431 }\r
432\r
433 MicrocodeFmpPrivate->DescriptorCount = CurrentMicrocodeCount;\r
434\r
435 if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
436 MicrocodeFmpPrivate->ImageDescriptor = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
437 if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
438 return EFI_OUT_OF_RESOURCES;\r
439 }\r
440 }\r
441\r
442 CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo(MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->DescriptorCount);\r
443 ASSERT(CurrentMicrocodeCount == MicrocodeFmpPrivate->DescriptorCount);\r
444\r
445 return EFI_SUCCESS;\r
446}\r
447\r
448/**\r
449 Initialize MicrocodeFmpDriver private data structure.\r
450\r
451 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
452\r
453 @return EFI_SUCCESS private data is initialized.\r
454**/\r
455EFI_STATUS\r
456InitializePrivateData (\r
457 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
458 )\r
459{\r
460 EFI_STATUS Status;\r
461 EFI_STATUS VarStatus;\r
462 UINTN VarSize;\r
463\r
464 MicrocodeFmpPrivate->Signature = MICROCODE_FMP_PRIVATE_DATA_SIGNATURE;\r
465 MicrocodeFmpPrivate->Handle = NULL;\r
466 CopyMem(&MicrocodeFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL));\r
467\r
468 MicrocodeFmpPrivate->PackageVersion = 0x1;\r
469 MicrocodeFmpPrivate->PackageVersionName = L"Microcode";\r
470\r
471 MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;\r
472 MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;\r
473 VarSize = sizeof(MicrocodeFmpPrivate->LastAttempt);\r
474 VarStatus = gRT->GetVariable(\r
475 MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
476 &gEfiCallerIdGuid,\r
477 NULL,\r
478 &VarSize,\r
479 &MicrocodeFmpPrivate->LastAttempt\r
480 );\r
481 DEBUG((DEBUG_INFO, "GetLastAttemp - %r\n", VarStatus));\r
482 DEBUG((DEBUG_INFO, "GetLastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
483\r
484 Status = InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
485\r
486 return Status;\r
487}\r
488\r
489/**\r
490 Microcode FMP module entrypoint\r
491\r
492 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
493 @param[in] SystemTable A pointer to the EFI System Table.\r
494\r
495 @return EFI_SUCCESS Microcode FMP module is initialized.\r
496**/\r
497EFI_STATUS\r
498EFIAPI\r
499MicrocodeFmpMain (\r
500 IN EFI_HANDLE ImageHandle,\r
501 IN EFI_SYSTEM_TABLE *SystemTable\r
502 )\r
503{\r
504 EFI_STATUS Status;\r
505\r
506 //\r
507 // Initialize MicrocodeFmpPrivateData\r
508 //\r
509 mMicrocodeFmpPrivate = AllocateZeroPool (sizeof(MICROCODE_FMP_PRIVATE_DATA));\r
510 if (mMicrocodeFmpPrivate == NULL) {\r
511 return EFI_OUT_OF_RESOURCES;\r
512 }\r
513\r
514 Status = InitializePrivateData(mMicrocodeFmpPrivate);\r
515 if (EFI_ERROR(Status)) {\r
516 FreePool(mMicrocodeFmpPrivate);\r
517 mMicrocodeFmpPrivate = NULL;\r
518 return Status;\r
519 }\r
520\r
521 //\r
522 // Install FMP protocol.\r
523 //\r
524 Status = gBS->InstallProtocolInterface (\r
525 &mMicrocodeFmpPrivate->Handle,\r
526 &gEfiFirmwareManagementProtocolGuid,\r
527 EFI_NATIVE_INTERFACE,\r
528 &mMicrocodeFmpPrivate->Fmp\r
529 );\r
530 if (EFI_ERROR (Status)) {\r
531 FreePool(mMicrocodeFmpPrivate);\r
532 mMicrocodeFmpPrivate = NULL;\r
533 return Status;\r
534 }\r
535\r
536 return Status;\r
537}\r