]> git.proxmox.com Git - mirror_edk2.git/blame - IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c
IntelSiliconPkg MicrocodeUpdateDxe: Honor FIT table
[mirror_edk2.git] / IntelSiliconPkg / Feature / Capsule / MicrocodeUpdateDxe / MicrocodeFmp.c
CommitLineData
88266859
JY
1/** @file\r
2 Produce FMP instance for Microcode.\r
3\r
1779cf40 4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
88266859
JY
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
1779cf40 164 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
88266859
JY
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
2ed65824 177 MICROCODE_INFO *MicrocodeInfo;\r
88266859
JY
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
2ed65824
JY
189 MicrocodeInfo = &MicrocodeFmpPrivate->MicrocodeInfo[ImageIndex - 1];\r
190\r
191 if (*ImageSize < MicrocodeInfo->TotalSize) {\r
192 *ImageSize = MicrocodeInfo->TotalSize;\r
193 return EFI_BUFFER_TOO_SMALL;\r
194 }\r
195\r
196 *ImageSize = MicrocodeInfo->TotalSize;\r
197 CopyMem (Image, MicrocodeInfo->MicrocodeEntryPoint, MicrocodeInfo->TotalSize);\r
198 return EFI_SUCCESS;\r
88266859
JY
199}\r
200\r
201/**\r
202 Updates the firmware image of the device.\r
203\r
204 This function updates the hardware with the new firmware image.\r
205 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
206 If the firmware image is updatable, the function should perform the following minimal validations\r
207 before proceeding to do the firmware image update.\r
208 - Validate the image authentication if image has attribute\r
209 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
210 EFI_SECURITY_VIOLATION if the validation fails.\r
211 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
212 the image is unsupported. The function can optionally provide more detailed information on\r
213 why the image is not a supported image.\r
214 - Validate the data from VendorCode if not null. Image validation must be performed before\r
215 VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
216 validation failed. The function returns EFI_ABORTED if the data is invalid.\r
217\r
218 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
219 the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
220 a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
221 firmware image version is older than the current firmware image version or bad image checksum.\r
222 Sensitive operations such as those wiping the entire firmware image and render the device to be\r
223 non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
224 AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
225 reason to the caller.\r
226\r
227 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
228 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
229 The number is between 1 and DescriptorCount.\r
230 @param[in] Image Points to the new image.\r
231 @param[in] ImageSize Size of the new image in bytes.\r
232 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r
233 Null indicates the caller did not specify the policy or use the default policy.\r
234 @param[in] Progress A function used by the driver to report the progress of the firmware update.\r
235 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r
236 details for the aborted operation. The buffer is allocated by this function\r
237 with AllocatePool(), and it is the caller's responsibility to free it with a\r
238 call to FreePool().\r
239\r
240 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
241 @retval EFI_ABORTED The operation is aborted.\r
242 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
243 @retval EFI_UNSUPPORTED The operation is not supported.\r
1779cf40 244 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
88266859
JY
245\r
246**/\r
247EFI_STATUS\r
248EFIAPI\r
249FmpSetImage (\r
250 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
251 IN UINT8 ImageIndex,\r
252 IN CONST VOID *Image,\r
253 IN UINTN ImageSize,\r
254 IN CONST VOID *VendorCode,\r
255 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r
256 OUT CHAR16 **AbortReason\r
257 )\r
258{\r
259 EFI_STATUS Status;\r
260 EFI_STATUS VarStatus;\r
261 MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
262\r
263 if (Image == NULL || AbortReason == NULL) {\r
264 return EFI_INVALID_PARAMETER;\r
265 }\r
266\r
267 MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
268 *AbortReason = NULL;\r
269\r
270 if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || Image == NULL) {\r
271 return EFI_INVALID_PARAMETER;\r
272 }\r
273\r
2ed65824 274 Status = MicrocodeWrite(MicrocodeFmpPrivate, (VOID *)Image, ImageSize, &MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, &MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus, AbortReason);\r
e9179788 275 DEBUG((DEBUG_INFO, "SetImage - LastAttempt Version - 0x%x, Status - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
88266859
JY
276 VarStatus = gRT->SetVariable(\r
277 MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
278 &gEfiCallerIdGuid,\r
279 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
280 sizeof(MicrocodeFmpPrivate->LastAttempt),\r
281 &MicrocodeFmpPrivate->LastAttempt\r
282 );\r
e9179788 283 DEBUG((DEBUG_INFO, "SetLastAttempt - %r\n", VarStatus));\r
88266859
JY
284\r
285 if (!EFI_ERROR(Status)) {\r
286 InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
31d060d9 287 DumpPrivateInfo (MicrocodeFmpPrivate);\r
88266859
JY
288 }\r
289\r
290 return Status;\r
291}\r
292\r
293/**\r
294 Checks if the firmware image is valid for the device.\r
295\r
296 This function allows firmware update application to validate the firmware image without\r
297 invoking the SetImage() first.\r
298\r
299 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
300 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
301 The number is between 1 and DescriptorCount.\r
302 @param[in] Image Points to the new image.\r
303 @param[in] ImageSize Size of the new image in bytes.\r
304 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r
305 if available, additional information if the image is invalid.\r
306\r
307 @retval EFI_SUCCESS The image was successfully checked.\r
308 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
309 @retval EFI_UNSUPPORTED The operation is not supported.\r
1779cf40 310 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
88266859
JY
311\r
312**/\r
313EFI_STATUS\r
314EFIAPI\r
315FmpCheckImage (\r
316 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
317 IN UINT8 ImageIndex,\r
318 IN CONST VOID *Image,\r
319 IN UINTN ImageSize,\r
320 OUT UINT32 *ImageUpdatable\r
321 )\r
322{\r
323 return EFI_UNSUPPORTED;\r
324}\r
325\r
326/**\r
327 Returns information about the firmware package.\r
328\r
329 This function returns package information.\r
330\r
331 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
332 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
333 The format is vendor specific and new version must have a greater value\r
334 than the old version. If PackageVersion is not supported, the value is\r
335 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
336 comparison is to be performed using PackageVersionName. A value of\r
337 0xFFFFFFFD indicates that package version update is in progress.\r
338 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r
339 the package version name. The buffer is allocated by this function with\r
340 AllocatePool(), and it is the caller's responsibility to free it with a\r
341 call to FreePool().\r
342 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
343 package version name. A value of 0 indicates the device does not support\r
344 update of package version name. Length is the number of Unicode characters,\r
345 including the terminating null character.\r
346 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r
347 Definitions' for possible returned values of this parameter. A value of 1\r
348 indicates the attribute is supported and the current setting value is\r
349 indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
350 supported and the current setting value in AttributesSetting is meaningless.\r
351 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r
352 values of this parameter\r
353\r
354 @retval EFI_SUCCESS The package information was successfully returned.\r
355 @retval EFI_UNSUPPORTED The operation is not supported.\r
356\r
357**/\r
358EFI_STATUS\r
359EFIAPI\r
360FmpGetPackageInfo (\r
361 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
362 OUT UINT32 *PackageVersion,\r
363 OUT CHAR16 **PackageVersionName,\r
364 OUT UINT32 *PackageVersionNameMaxLen,\r
365 OUT UINT64 *AttributesSupported,\r
366 OUT UINT64 *AttributesSetting\r
367 )\r
368{\r
369 return EFI_UNSUPPORTED;\r
370}\r
371\r
372/**\r
373 Updates information about the firmware package.\r
374\r
375 This function updates package information.\r
376 This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
377 VendorCode enables vendor to implement vendor-specific package information update policy.\r
378 Null if the caller did not specify this policy or use the default policy.\r
379\r
380 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
381 @param[in] Image Points to the authentication image.\r
382 Null if authentication is not required.\r
383 @param[in] ImageSize Size of the authentication image in bytes.\r
384 0 if authentication is not required.\r
385 @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r
386 image update policy.\r
387 Null indicates the caller did not specify this policy or use\r
388 the default policy.\r
389 @param[in] PackageVersion The new package version.\r
390 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r
391 the package version name.\r
392 The string length is equal to or less than the value returned in\r
393 PackageVersionNameMaxLen.\r
394\r
395 @retval EFI_SUCCESS The device was successfully updated with the new package\r
396 information.\r
397 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r
398 returned in PackageVersionNameMaxLen.\r
399 @retval EFI_UNSUPPORTED The operation is not supported.\r
1779cf40 400 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
88266859
JY
401\r
402**/\r
403EFI_STATUS\r
404EFIAPI\r
405FmpSetPackageInfo (\r
406 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
407 IN CONST VOID *Image,\r
408 IN UINTN ImageSize,\r
409 IN CONST VOID *VendorCode,\r
410 IN UINT32 PackageVersion,\r
411 IN CONST CHAR16 *PackageVersionName\r
412 )\r
413{\r
414 return EFI_UNSUPPORTED;\r
415}\r
416\r
e9179788
SZ
417/**\r
418 Sort FIT microcode entries based upon MicrocodeEntryPoint, from low to high.\r
419\r
420 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
421\r
422**/\r
423VOID\r
424SortFitMicrocodeInfo (\r
425 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
426 )\r
427{\r
428 FIT_MICROCODE_INFO *FitMicrocodeEntry;\r
429 FIT_MICROCODE_INFO *NextFitMicrocodeEntry;\r
430 FIT_MICROCODE_INFO TempFitMicrocodeEntry;\r
431 FIT_MICROCODE_INFO *FitMicrocodeEntryEnd;\r
432\r
433 FitMicrocodeEntry = MicrocodeFmpPrivate->FitMicrocodeInfo;\r
434 NextFitMicrocodeEntry = FitMicrocodeEntry + 1;\r
435 FitMicrocodeEntryEnd = MicrocodeFmpPrivate->FitMicrocodeInfo + MicrocodeFmpPrivate->FitMicrocodeEntryCount;\r
436 while (FitMicrocodeEntry < FitMicrocodeEntryEnd) {\r
437 while (NextFitMicrocodeEntry < FitMicrocodeEntryEnd) {\r
438 if (FitMicrocodeEntry->MicrocodeEntryPoint > NextFitMicrocodeEntry->MicrocodeEntryPoint) {\r
439 CopyMem (&TempFitMicrocodeEntry, FitMicrocodeEntry, sizeof (FIT_MICROCODE_INFO));\r
440 CopyMem (FitMicrocodeEntry, NextFitMicrocodeEntry, sizeof (FIT_MICROCODE_INFO));\r
441 CopyMem (NextFitMicrocodeEntry, &TempFitMicrocodeEntry, sizeof (FIT_MICROCODE_INFO));\r
442 }\r
443\r
444 NextFitMicrocodeEntry = NextFitMicrocodeEntry + 1;\r
445 }\r
446\r
447 FitMicrocodeEntry = FitMicrocodeEntry + 1;\r
448 NextFitMicrocodeEntry = FitMicrocodeEntry + 1;\r
449 }\r
450}\r
451\r
452/**\r
453 Initialize FIT microcode information.\r
454\r
455 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
456\r
457 @return EFI_SUCCESS FIT microcode information is initialized.\r
458 @return EFI_OUT_OF_RESOURCES No enough resource for the initialization.\r
459 @return EFI_DEVICE_ERROR There is something wrong in FIT microcode entry.\r
460**/\r
461EFI_STATUS\r
462InitializeFitMicrocodeInfo (\r
463 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
464 )\r
465{\r
466 UINT64 FitPointer;\r
467 FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry;\r
468 UINT32 EntryNum;\r
469 UINT32 MicrocodeEntryNum;\r
470 UINT32 Index;\r
471 UINTN Address;\r
472 VOID *MicrocodePatchAddress;\r
473 UINTN MicrocodePatchRegionSize;\r
474 FIT_MICROCODE_INFO *FitMicrocodeInfo;\r
475 FIT_MICROCODE_INFO *FitMicrocodeInfoNext;\r
476 CPU_MICROCODE_HEADER *MicrocodeEntryPoint;\r
477 CPU_MICROCODE_HEADER *MicrocodeEntryPointNext;\r
478 UINTN FitMicrocodeIndex;\r
479 MICROCODE_INFO *MicrocodeInfo;\r
480 UINTN MicrocodeIndex;\r
481\r
482 if (MicrocodeFmpPrivate->FitMicrocodeInfo != NULL) {\r
483 FreePool (MicrocodeFmpPrivate->FitMicrocodeInfo);\r
484 MicrocodeFmpPrivate->FitMicrocodeInfo = NULL;\r
485 MicrocodeFmpPrivate->FitMicrocodeEntryCount = 0;\r
486 }\r
487\r
488 FitPointer = *(UINT64 *) (UINTN) FIT_POINTER_ADDRESS;\r
489 if ((FitPointer == 0) ||\r
490 (FitPointer == 0xFFFFFFFFFFFFFFFF) ||\r
491 (FitPointer == 0xEEEEEEEEEEEEEEEE)) {\r
492 //\r
493 // No FIT table.\r
494 //\r
495 return EFI_SUCCESS;\r
496 }\r
497 FitEntry = (FIRMWARE_INTERFACE_TABLE_ENTRY *) (UINTN) FitPointer;\r
498 if ((FitEntry[0].Type != FIT_TYPE_00_HEADER) ||\r
499 (FitEntry[0].Address != FIT_TYPE_00_SIGNATURE)) {\r
500 //\r
501 // Invalid FIT table, treat it as no FIT table.\r
502 //\r
503 return EFI_SUCCESS;\r
504 }\r
505\r
506 EntryNum = *(UINT32 *)(&FitEntry[0].Size[0]) & 0xFFFFFF;\r
507\r
508 //\r
509 // Calculate microcode entry number.\r
510 //\r
511 MicrocodeEntryNum = 0;\r
512 for (Index = 0; Index < EntryNum; Index++) {\r
513 if (FitEntry[Index].Type == FIT_TYPE_01_MICROCODE) {\r
514 MicrocodeEntryNum++;\r
515 }\r
516 }\r
517 if (MicrocodeEntryNum == 0) {\r
518 //\r
519 // No FIT microcode entry.\r
520 //\r
521 return EFI_SUCCESS;\r
522 }\r
523\r
524 //\r
525 // Allocate buffer.\r
526 //\r
527 MicrocodeFmpPrivate->FitMicrocodeInfo = AllocateZeroPool (MicrocodeEntryNum * sizeof (FIT_MICROCODE_INFO));\r
528 if (MicrocodeFmpPrivate->FitMicrocodeInfo == NULL) {\r
529 return EFI_OUT_OF_RESOURCES;\r
530 }\r
531\r
532 MicrocodeFmpPrivate->FitMicrocodeEntryCount = MicrocodeEntryNum;\r
533\r
534 MicrocodePatchAddress = MicrocodeFmpPrivate->MicrocodePatchAddress;\r
535 MicrocodePatchRegionSize = MicrocodeFmpPrivate->MicrocodePatchRegionSize;\r
536\r
537 //\r
538 // Collect microcode entry info.\r
539 //\r
540 MicrocodeEntryNum = 0;\r
541 for (Index = 0; Index < EntryNum; Index++) {\r
542 if (FitEntry[Index].Type == FIT_TYPE_01_MICROCODE) {\r
543 Address = (UINTN) FitEntry[Index].Address;\r
544 if ((Address < (UINTN) MicrocodePatchAddress) ||\r
545 (Address >= ((UINTN) MicrocodePatchAddress + MicrocodePatchRegionSize))) {\r
546 DEBUG ((\r
547 DEBUG_ERROR,\r
548 "InitializeFitMicrocodeInfo - Address (0x%x) is not in Microcode Region\n",\r
549 Address\r
550 ));\r
551 goto ErrorExit;\r
552 }\r
553 FitMicrocodeInfo = &MicrocodeFmpPrivate->FitMicrocodeInfo[MicrocodeEntryNum];\r
554 FitMicrocodeInfo->MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) Address;\r
555 if ((*(UINT32 *) Address) == 0xFFFFFFFF) {\r
556 //\r
557 // It is the empty slot as long as the first dword is 0xFFFF_FFFF.\r
558 //\r
559 FitMicrocodeInfo->Empty = TRUE;\r
560 } else {\r
561 FitMicrocodeInfo->Empty = FALSE;\r
562 }\r
563 MicrocodeEntryNum++;\r
564 }\r
565 }\r
566\r
567 //\r
568 // Every microcode should have a FIT microcode entry.\r
569 //\r
570 for (MicrocodeIndex = 0; MicrocodeIndex < MicrocodeFmpPrivate->DescriptorCount; MicrocodeIndex++) {\r
571 MicrocodeInfo = &MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex];\r
572 for (FitMicrocodeIndex = 0; FitMicrocodeIndex < MicrocodeFmpPrivate->FitMicrocodeEntryCount; FitMicrocodeIndex++) {\r
573 FitMicrocodeInfo = &MicrocodeFmpPrivate->FitMicrocodeInfo[FitMicrocodeIndex];\r
574 if (MicrocodeInfo->MicrocodeEntryPoint == FitMicrocodeInfo->MicrocodeEntryPoint) {\r
575 FitMicrocodeInfo->TotalSize = MicrocodeInfo->TotalSize;\r
576 FitMicrocodeInfo->InUse = MicrocodeInfo->InUse;\r
577 break;\r
578 }\r
579 }\r
580 if (FitMicrocodeIndex >= MicrocodeFmpPrivate->FitMicrocodeEntryCount) {\r
581 DEBUG ((\r
582 DEBUG_ERROR,\r
583 "InitializeFitMicrocodeInfo - There is no FIT microcode entry for Microcode (0x%x)\n",\r
584 MicrocodeInfo->MicrocodeEntryPoint\r
585 ));\r
586 goto ErrorExit;\r
587 }\r
588 }\r
589\r
590 SortFitMicrocodeInfo (MicrocodeFmpPrivate);\r
591\r
592 //\r
593 // Check overlap.\r
594 //\r
595 for (FitMicrocodeIndex = 0; FitMicrocodeIndex < MicrocodeFmpPrivate->FitMicrocodeEntryCount - 1; FitMicrocodeIndex++) {\r
596 FitMicrocodeInfo = &MicrocodeFmpPrivate->FitMicrocodeInfo[FitMicrocodeIndex];\r
597 MicrocodeEntryPoint = FitMicrocodeInfo->MicrocodeEntryPoint;\r
598 FitMicrocodeInfoNext = &MicrocodeFmpPrivate->FitMicrocodeInfo[FitMicrocodeIndex + 1];\r
599 MicrocodeEntryPointNext = FitMicrocodeInfoNext->MicrocodeEntryPoint;\r
600 if ((MicrocodeEntryPoint >= MicrocodeEntryPointNext) ||\r
601 ((FitMicrocodeInfo->TotalSize != 0) &&\r
602 ((UINTN) MicrocodeEntryPoint + FitMicrocodeInfo->TotalSize) >\r
603 (UINTN) MicrocodeEntryPointNext)) {\r
604 DEBUG ((\r
605 DEBUG_ERROR,\r
606 "InitializeFitMicrocodeInfo - There is overlap between FIT microcode entries (0x%x 0x%x)\n",\r
607 MicrocodeEntryPoint,\r
608 MicrocodeEntryPointNext\r
609 ));\r
610 goto ErrorExit;\r
611 }\r
612 }\r
613\r
614 return EFI_SUCCESS;\r
615\r
616ErrorExit:\r
617 FreePool (MicrocodeFmpPrivate->FitMicrocodeInfo);\r
618 MicrocodeFmpPrivate->FitMicrocodeInfo = NULL;\r
619 MicrocodeFmpPrivate->FitMicrocodeEntryCount = 0;\r
620 return EFI_DEVICE_ERROR;\r
621}\r
622\r
31d060d9
JY
623/**\r
624 Initialize Processor Microcode Index.\r
625\r
626 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
627**/\r
628VOID\r
629InitializedProcessorMicrocodeIndex (\r
630 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
631 )\r
632{\r
633 UINTN CpuIndex;\r
634 UINTN MicrocodeIndex;\r
635 UINTN TargetCpuIndex;\r
636 UINT32 AttemptStatus;\r
637 EFI_STATUS Status;\r
638\r
639 for (CpuIndex = 0; CpuIndex < MicrocodeFmpPrivate->ProcessorCount; CpuIndex++) {\r
640 if (MicrocodeFmpPrivate->ProcessorInfo[CpuIndex].MicrocodeIndex != (UINTN)-1) {\r
641 continue;\r
642 }\r
643 for (MicrocodeIndex = 0; MicrocodeIndex < MicrocodeFmpPrivate->DescriptorCount; MicrocodeIndex++) {\r
644 if (!MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].InUse) {\r
645 continue;\r
646 }\r
647 TargetCpuIndex = CpuIndex;\r
648 Status = VerifyMicrocode(\r
649 MicrocodeFmpPrivate,\r
650 MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].MicrocodeEntryPoint,\r
651 MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].TotalSize,\r
652 FALSE,\r
653 &AttemptStatus,\r
654 NULL,\r
655 &TargetCpuIndex\r
656 );\r
657 if (!EFI_ERROR(Status)) {\r
658 MicrocodeFmpPrivate->ProcessorInfo[CpuIndex].MicrocodeIndex = MicrocodeIndex;\r
659 }\r
660 }\r
661 }\r
662}\r
663\r
88266859
JY
664/**\r
665 Initialize Microcode Descriptor.\r
666\r
667 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
668\r
e9179788
SZ
669 @return EFI_SUCCESS Microcode Descriptor is initialized.\r
670 @return EFI_OUT_OF_RESOURCES No enough resource for the initialization.\r
88266859
JY
671**/\r
672EFI_STATUS\r
673InitializeMicrocodeDescriptor (\r
674 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
675 )\r
676{\r
e9179788
SZ
677 EFI_STATUS Status;\r
678 UINT8 CurrentMicrocodeCount;\r
88266859 679\r
2ed65824 680 CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, 0, NULL, NULL);\r
88266859
JY
681\r
682 if (CurrentMicrocodeCount > MicrocodeFmpPrivate->DescriptorCount) {\r
683 if (MicrocodeFmpPrivate->ImageDescriptor != NULL) {\r
684 FreePool(MicrocodeFmpPrivate->ImageDescriptor);\r
685 MicrocodeFmpPrivate->ImageDescriptor = NULL;\r
686 }\r
2ed65824
JY
687 if (MicrocodeFmpPrivate->MicrocodeInfo != NULL) {\r
688 FreePool(MicrocodeFmpPrivate->MicrocodeInfo);\r
689 MicrocodeFmpPrivate->MicrocodeInfo = NULL;\r
690 }\r
88266859
JY
691 } else {\r
692 ZeroMem(MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
2ed65824 693 ZeroMem(MicrocodeFmpPrivate->MicrocodeInfo, MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r
88266859
JY
694 }\r
695\r
696 MicrocodeFmpPrivate->DescriptorCount = CurrentMicrocodeCount;\r
697\r
698 if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
699 MicrocodeFmpPrivate->ImageDescriptor = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
700 if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
701 return EFI_OUT_OF_RESOURCES;\r
702 }\r
703 }\r
2ed65824
JY
704 if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r
705 MicrocodeFmpPrivate->MicrocodeInfo = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r
706 if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r
e9179788 707 FreePool (MicrocodeFmpPrivate->ImageDescriptor);\r
2ed65824
JY
708 return EFI_OUT_OF_RESOURCES;\r
709 }\r
710 }\r
88266859 711\r
2ed65824 712 CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, MicrocodeFmpPrivate->DescriptorCount, MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->MicrocodeInfo);\r
88266859
JY
713 ASSERT(CurrentMicrocodeCount == MicrocodeFmpPrivate->DescriptorCount);\r
714\r
31d060d9
JY
715 InitializedProcessorMicrocodeIndex (MicrocodeFmpPrivate);\r
716\r
e9179788
SZ
717 Status = InitializeFitMicrocodeInfo (MicrocodeFmpPrivate);\r
718 if (EFI_ERROR(Status)) {\r
719 FreePool (MicrocodeFmpPrivate->ImageDescriptor);\r
720 FreePool (MicrocodeFmpPrivate->MicrocodeInfo);\r
721 DEBUG((DEBUG_ERROR, "InitializeFitMicrocodeInfo - %r\n", Status));\r
722 return Status;\r
723 }\r
724\r
31d060d9
JY
725 return EFI_SUCCESS;\r
726}\r
727\r
728/**\r
729 Initialize MicrocodeFmpDriver multiprocessor information.\r
730\r
731 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
732\r
e9179788
SZ
733 @return EFI_SUCCESS Processor information is initialized.\r
734 @return EFI_OUT_OF_RESOURCES No enough resource for the initialization.\r
31d060d9
JY
735**/\r
736EFI_STATUS\r
737InitializeProcessorInfo (\r
738 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
739 )\r
740{\r
741 EFI_STATUS Status;\r
742 EFI_MP_SERVICES_PROTOCOL *MpService;\r
743 UINTN NumberOfProcessors;\r
744 UINTN NumberOfEnabledProcessors;\r
745 UINTN Index;\r
746 UINTN BspIndex;\r
747\r
748 Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpService);\r
749 ASSERT_EFI_ERROR(Status);\r
750\r
751 MicrocodeFmpPrivate->MpService = MpService;\r
752 MicrocodeFmpPrivate->ProcessorCount = 0;\r
753 MicrocodeFmpPrivate->ProcessorInfo = NULL;\r
754\r
755 Status = MpService->GetNumberOfProcessors (MpService, &NumberOfProcessors, &NumberOfEnabledProcessors);\r
756 ASSERT_EFI_ERROR(Status);\r
757 MicrocodeFmpPrivate->ProcessorCount = NumberOfProcessors;\r
758\r
759 Status = MpService->WhoAmI (MpService, &BspIndex);\r
760 ASSERT_EFI_ERROR(Status);\r
761 MicrocodeFmpPrivate->BspIndex = BspIndex;\r
762\r
763 MicrocodeFmpPrivate->ProcessorInfo = AllocateZeroPool (sizeof(PROCESSOR_INFO) * MicrocodeFmpPrivate->ProcessorCount);\r
764 if (MicrocodeFmpPrivate->ProcessorInfo == NULL) {\r
765 return EFI_OUT_OF_RESOURCES;\r
766 }\r
767\r
768 for (Index = 0; Index < NumberOfProcessors; Index++) {\r
769 MicrocodeFmpPrivate->ProcessorInfo[Index].CpuIndex = Index;\r
770 MicrocodeFmpPrivate->ProcessorInfo[Index].MicrocodeIndex = (UINTN)-1;\r
771 if (Index == BspIndex) {\r
772 CollectProcessorInfo (&MicrocodeFmpPrivate->ProcessorInfo[Index]);\r
773 } else {\r
774 Status = MpService->StartupThisAP (\r
775 MpService,\r
776 CollectProcessorInfo,\r
777 Index,\r
778 NULL,\r
779 0,\r
780 &MicrocodeFmpPrivate->ProcessorInfo[Index],\r
781 NULL\r
782 );\r
783 ASSERT_EFI_ERROR(Status);\r
784 }\r
785 }\r
786\r
88266859
JY
787 return EFI_SUCCESS;\r
788}\r
789\r
31d060d9
JY
790/**\r
791 Dump private information.\r
792\r
793 @param[in] MicrocodeFmpPrivate private data structure.\r
794**/\r
795VOID\r
796DumpPrivateInfo (\r
797 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
798 )\r
799{\r
800 UINTN Index;\r
801 PROCESSOR_INFO *ProcessorInfo;\r
802 MICROCODE_INFO *MicrocodeInfo;\r
803 EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;\r
e9179788 804 FIT_MICROCODE_INFO *FitMicrocodeInfo;\r
31d060d9
JY
805\r
806 DEBUG ((DEBUG_INFO, "ProcessorInfo:\n"));\r
807 DEBUG ((DEBUG_INFO, " ProcessorCount - 0x%x\n", MicrocodeFmpPrivate->ProcessorCount));\r
808 DEBUG ((DEBUG_INFO, " BspIndex - 0x%x\n", MicrocodeFmpPrivate->BspIndex));\r
809\r
810 ProcessorInfo = MicrocodeFmpPrivate->ProcessorInfo;\r
811 for (Index = 0; Index < MicrocodeFmpPrivate->ProcessorCount; Index++) {\r
812 DEBUG ((\r
813 DEBUG_INFO,\r
814 " ProcessorInfo[0x%x] - 0x%08x, 0x%02x, 0x%08x, (0x%x)\n",\r
815 ProcessorInfo[Index].CpuIndex,\r
816 ProcessorInfo[Index].ProcessorSignature,\r
817 ProcessorInfo[Index].PlatformId,\r
818 ProcessorInfo[Index].MicrocodeRevision,\r
819 ProcessorInfo[Index].MicrocodeIndex\r
820 ));\r
821 }\r
822\r
823 DEBUG ((DEBUG_INFO, "MicrocodeInfo:\n"));\r
824 MicrocodeInfo = MicrocodeFmpPrivate->MicrocodeInfo;\r
825 DEBUG ((DEBUG_INFO, " MicrocodeRegion - 0x%x - 0x%x\n", MicrocodeFmpPrivate->MicrocodePatchAddress, MicrocodeFmpPrivate->MicrocodePatchRegionSize));\r
826 DEBUG ((DEBUG_INFO, " MicrocodeCount - 0x%x\n", MicrocodeFmpPrivate->DescriptorCount));\r
827 for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
828 DEBUG ((\r
829 DEBUG_INFO,\r
830 " MicrocodeInfo[0x%x] - 0x%08x, 0x%08x, (0x%x)\n",\r
831 Index,\r
832 MicrocodeInfo[Index].MicrocodeEntryPoint,\r
833 MicrocodeInfo[Index].TotalSize,\r
834 MicrocodeInfo[Index].InUse\r
835 ));\r
836 }\r
837\r
838 ImageDescriptor = MicrocodeFmpPrivate->ImageDescriptor;\r
839 DEBUG ((DEBUG_VERBOSE, "ImageDescriptor:\n"));\r
840 for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
841 DEBUG((DEBUG_VERBOSE, " ImageDescriptor (%d)\n", Index));\r
842 DEBUG((DEBUG_VERBOSE, " ImageIndex - 0x%x\n", ImageDescriptor[Index].ImageIndex));\r
843 DEBUG((DEBUG_VERBOSE, " ImageTypeId - %g\n", &ImageDescriptor[Index].ImageTypeId));\r
844 DEBUG((DEBUG_VERBOSE, " ImageId - 0x%lx\n", ImageDescriptor[Index].ImageId));\r
845 DEBUG((DEBUG_VERBOSE, " ImageIdName - %s\n", ImageDescriptor[Index].ImageIdName));\r
846 DEBUG((DEBUG_VERBOSE, " Version - 0x%x\n", ImageDescriptor[Index].Version));\r
847 DEBUG((DEBUG_VERBOSE, " VersionName - %s\n", ImageDescriptor[Index].VersionName));\r
848 DEBUG((DEBUG_VERBOSE, " Size - 0x%x\n", ImageDescriptor[Index].Size));\r
849 DEBUG((DEBUG_VERBOSE, " AttributesSupported - 0x%lx\n", ImageDescriptor[Index].AttributesSupported));\r
850 DEBUG((DEBUG_VERBOSE, " AttributesSetting - 0x%lx\n", ImageDescriptor[Index].AttributesSetting));\r
851 DEBUG((DEBUG_VERBOSE, " Compatibilities - 0x%lx\n", ImageDescriptor[Index].Compatibilities));\r
852 DEBUG((DEBUG_VERBOSE, " LowestSupportedImageVersion - 0x%x\n", ImageDescriptor[Index].LowestSupportedImageVersion));\r
853 DEBUG((DEBUG_VERBOSE, " LastAttemptVersion - 0x%x\n", ImageDescriptor[Index].LastAttemptVersion));\r
854 DEBUG((DEBUG_VERBOSE, " LastAttemptStatus - 0x%x\n", ImageDescriptor[Index].LastAttemptStatus));\r
855 DEBUG((DEBUG_VERBOSE, " HardwareInstance - 0x%lx\n", ImageDescriptor[Index].HardwareInstance));\r
856 }\r
e9179788
SZ
857\r
858 if (MicrocodeFmpPrivate->FitMicrocodeInfo != NULL) {\r
859 DEBUG ((DEBUG_INFO, "FitMicrocodeInfo:\n"));\r
860 FitMicrocodeInfo = MicrocodeFmpPrivate->FitMicrocodeInfo;\r
861 DEBUG ((DEBUG_INFO, " FitMicrocodeEntryCount - 0x%x\n", MicrocodeFmpPrivate->FitMicrocodeEntryCount));\r
862 for (Index = 0; Index < MicrocodeFmpPrivate->FitMicrocodeEntryCount; Index++) {\r
863 DEBUG ((\r
864 DEBUG_INFO,\r
865 " FitMicrocodeInfo[0x%x] - 0x%08x, 0x%08x, (0x%x, 0x%x)\n",\r
866 Index,\r
867 FitMicrocodeInfo[Index].MicrocodeEntryPoint,\r
868 FitMicrocodeInfo[Index].TotalSize,\r
869 FitMicrocodeInfo[Index].InUse,\r
870 FitMicrocodeInfo[Index].Empty\r
871 ));\r
872 }\r
873 }\r
31d060d9
JY
874}\r
875\r
88266859
JY
876/**\r
877 Initialize MicrocodeFmpDriver private data structure.\r
878\r
879 @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
880\r
881 @return EFI_SUCCESS private data is initialized.\r
882**/\r
883EFI_STATUS\r
884InitializePrivateData (\r
885 IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
886 )\r
887{\r
888 EFI_STATUS Status;\r
889 EFI_STATUS VarStatus;\r
890 UINTN VarSize;\r
2ed65824 891 BOOLEAN Result;\r
88266859
JY
892\r
893 MicrocodeFmpPrivate->Signature = MICROCODE_FMP_PRIVATE_DATA_SIGNATURE;\r
894 MicrocodeFmpPrivate->Handle = NULL;\r
895 CopyMem(&MicrocodeFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL));\r
896\r
897 MicrocodeFmpPrivate->PackageVersion = 0x1;\r
898 MicrocodeFmpPrivate->PackageVersionName = L"Microcode";\r
899\r
900 MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;\r
901 MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;\r
902 VarSize = sizeof(MicrocodeFmpPrivate->LastAttempt);\r
903 VarStatus = gRT->GetVariable(\r
904 MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
905 &gEfiCallerIdGuid,\r
906 NULL,\r
907 &VarSize,\r
908 &MicrocodeFmpPrivate->LastAttempt\r
909 );\r
e9179788
SZ
910 DEBUG((DEBUG_INFO, "GetLastAttempt - %r\n", VarStatus));\r
911 DEBUG((DEBUG_INFO, "GetLastAttempt Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
88266859 912\r
2ed65824
JY
913 Result = GetMicrocodeRegion(&MicrocodeFmpPrivate->MicrocodePatchAddress, &MicrocodeFmpPrivate->MicrocodePatchRegionSize);\r
914 if (!Result) {\r
915 DEBUG((DEBUG_ERROR, "Fail to get Microcode Region\n"));\r
916 return EFI_NOT_FOUND;\r
917 }\r
918\r
31d060d9
JY
919 Status = InitializeProcessorInfo (MicrocodeFmpPrivate);\r
920 if (EFI_ERROR(Status)) {\r
921 DEBUG((DEBUG_ERROR, "InitializeProcessorInfo - %r\n", Status));\r
922 return Status;\r
923 }\r
924\r
88266859 925 Status = InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
31d060d9 926 if (EFI_ERROR(Status)) {\r
e9179788 927 FreePool (MicrocodeFmpPrivate->ProcessorInfo);\r
31d060d9
JY
928 DEBUG((DEBUG_ERROR, "InitializeMicrocodeDescriptor - %r\n", Status));\r
929 return Status;\r
930 }\r
931\r
932 DumpPrivateInfo (MicrocodeFmpPrivate);\r
88266859
JY
933\r
934 return Status;\r
935}\r
936\r
937/**\r
938 Microcode FMP module entrypoint\r
939\r
940 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
941 @param[in] SystemTable A pointer to the EFI System Table.\r
942\r
943 @return EFI_SUCCESS Microcode FMP module is initialized.\r
944**/\r
945EFI_STATUS\r
946EFIAPI\r
947MicrocodeFmpMain (\r
948 IN EFI_HANDLE ImageHandle,\r
949 IN EFI_SYSTEM_TABLE *SystemTable\r
950 )\r
951{\r
952 EFI_STATUS Status;\r
953\r
954 //\r
955 // Initialize MicrocodeFmpPrivateData\r
956 //\r
957 mMicrocodeFmpPrivate = AllocateZeroPool (sizeof(MICROCODE_FMP_PRIVATE_DATA));\r
958 if (mMicrocodeFmpPrivate == NULL) {\r
959 return EFI_OUT_OF_RESOURCES;\r
960 }\r
961\r
962 Status = InitializePrivateData(mMicrocodeFmpPrivate);\r
963 if (EFI_ERROR(Status)) {\r
964 FreePool(mMicrocodeFmpPrivate);\r
965 mMicrocodeFmpPrivate = NULL;\r
966 return Status;\r
967 }\r
968\r
969 //\r
970 // Install FMP protocol.\r
971 //\r
972 Status = gBS->InstallProtocolInterface (\r
973 &mMicrocodeFmpPrivate->Handle,\r
974 &gEfiFirmwareManagementProtocolGuid,\r
975 EFI_NATIVE_INTERFACE,\r
976 &mMicrocodeFmpPrivate->Fmp\r
977 );\r
978 if (EFI_ERROR (Status)) {\r
979 FreePool(mMicrocodeFmpPrivate);\r
980 mMicrocodeFmpPrivate = NULL;\r
981 return Status;\r
982 }\r
983\r
984 return Status;\r
985}\r