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