2 Microcode update header file.
4 Copyright (c) 2016 - 2018, 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
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.
15 #ifndef _MICROCODE_FMP_H_
16 #define _MICROCODE_FMP_H_
20 #include <Guid/SystemResourceTable.h>
21 #include <Guid/MicrocodeFmp.h>
23 #include <IndustryStandard/FirmwareInterfaceTable.h>
25 #include <Protocol/FirmwareManagement.h>
26 #include <Protocol/MpService.h>
28 #include <Library/BaseLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/PcdLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/UefiRuntimeServicesTableLib.h>
36 #include <Library/UefiDriverEntryPoint.h>
37 #include <Library/DevicePathLib.h>
38 #include <Library/HobLib.h>
39 #include <Library/MicrocodeFlashAccessLib.h>
41 #include <Register/Cpuid.h>
42 #include <Register/Msr.h>
43 #include <Register/Microcode.h>
45 #define MICROCODE_FMP_PRIVATE_DATA_SIGNATURE SIGNATURE_32('M', 'C', 'U', 'F')
48 // Microcode FMP private data structure.
52 UINT32 LastAttemptVersion
;
53 UINT32 LastAttemptStatus
;
54 } MICROCODE_FMP_LAST_ATTEMPT_VARIABLE
;
57 CPU_MICROCODE_HEADER
*MicrocodeEntryPoint
;
63 CPU_MICROCODE_HEADER
*MicrocodeEntryPoint
;
71 UINT32 ProcessorSignature
;
73 UINT32 MicrocodeRevision
;
80 } MICROCODE_LOAD_BUFFER
;
82 struct _MICROCODE_FMP_PRIVATE_DATA
{
84 EFI_FIRMWARE_MANAGEMENT_PROTOCOL Fmp
;
86 VOID
*MicrocodePatchAddress
;
87 UINTN MicrocodePatchRegionSize
;
88 UINT8 DescriptorCount
;
89 EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageDescriptor
;
90 MICROCODE_INFO
*MicrocodeInfo
;
91 UINT32 PackageVersion
;
92 CHAR16
*PackageVersionName
;
93 MICROCODE_FMP_LAST_ATTEMPT_VARIABLE LastAttempt
;
94 EFI_MP_SERVICES_PROTOCOL
*MpService
;
97 PROCESSOR_INFO
*ProcessorInfo
;
98 UINT32 FitMicrocodeEntryCount
;
99 FIT_MICROCODE_INFO
*FitMicrocodeInfo
;
102 typedef struct _MICROCODE_FMP_PRIVATE_DATA MICROCODE_FMP_PRIVATE_DATA
;
104 #define MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME L"MicrocodeLastAttemptVar"
107 Returns a pointer to the MICROCODE_FMP_PRIVATE_DATA structure from the input a as Fmp.
109 If the signatures matches, then a pointer to the data structure that contains
110 a specified field of that data structure is returned.
112 @param a Pointer to the field specified by ServiceBinding within
113 a data structure of type MICROCODE_FMP_PRIVATE_DATA.
116 #define MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(a) \
119 MICROCODE_FMP_PRIVATE_DATA, \
121 MICROCODE_FMP_PRIVATE_DATA_SIGNATURE \
125 Get Microcode Region.
127 @param[out] MicrocodePatchAddress The address of Microcode
128 @param[out] MicrocodePatchRegionSize The region size of Microcode
130 @retval TRUE The Microcode region is returned.
131 @retval FALSE No Microcode region.
135 OUT VOID
**MicrocodePatchAddress
,
136 OUT UINTN
*MicrocodePatchRegionSize
140 Collect processor information.
141 The function prototype for invoking a function on an Application Processor.
143 @param[in,out] Buffer The pointer to private data buffer.
147 CollectProcessorInfo (
152 Get current Microcode information.
154 The ProcessorInformation (BspIndex/ProcessorCount/ProcessorInfo)
155 in MicrocodeFmpPrivate must be initialized.
157 The MicrocodeInformation (DescriptorCount/ImageDescriptor/MicrocodeInfo)
158 in MicrocodeFmpPrivate may not be avaiable in this function.
160 @param[in] MicrocodeFmpPrivate The Microcode driver private data
161 @param[in] DescriptorCount The count of Microcode ImageDescriptor allocated.
162 @param[out] ImageDescriptor Microcode ImageDescriptor
163 @param[out] MicrocodeInfo Microcode information
165 @return Microcode count
169 IN MICROCODE_FMP_PRIVATE_DATA
*MicrocodeFmpPrivate
,
170 IN UINTN DescriptorCount
, OPTIONAL
171 OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageDescriptor
, OPTIONAL
172 OUT MICROCODE_INFO
*MicrocodeInfo OPTIONAL
178 Caution: This function may receive untrusted input.
180 @param[in] MicrocodeFmpPrivate The Microcode driver private data
181 @param[in] Image The Microcode image buffer.
182 @param[in] ImageSize The size of Microcode image buffer in bytes.
183 @param[in] TryLoad Try to load Microcode or not.
184 @param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
185 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
186 details for the aborted operation. The buffer is allocated by this function
187 with AllocatePool(), and it is the caller's responsibility to free it with a
189 @param[in, out] TargetCpuIndex On input, the index of target CPU which tries to match the Microcode. (UINTN)-1 means to try all.
190 On output, the index of target CPU which matches the Microcode.
192 @retval EFI_SUCCESS The Microcode image passes verification.
193 @retval EFI_VOLUME_CORRUPTED The Microcode image is corrupt.
194 @retval EFI_INCOMPATIBLE_VERSION The Microcode image version is incorrect.
195 @retval EFI_UNSUPPORTED The Microcode ProcessorSignature or ProcessorFlags is incorrect.
196 @retval EFI_SECURITY_VIOLATION The Microcode image fails to load.
200 IN MICROCODE_FMP_PRIVATE_DATA
*MicrocodeFmpPrivate
,
204 OUT UINT32
*LastAttemptStatus
,
205 OUT CHAR16
**AbortReason
, OPTIONAL
206 IN OUT UINTN
*TargetCpuIndex OPTIONAL
212 @param[in] MicrocodeFmpPrivate The Microcode driver private data
213 @param[in] Image The Microcode image buffer.
214 @param[in] ImageSize The size of Microcode image buffer in bytes.
215 @param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
216 @param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
217 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
218 details for the aborted operation. The buffer is allocated by this function
219 with AllocatePool(), and it is the caller's responsibility to free it with a
222 @retval EFI_SUCCESS The Microcode image is written.
223 @retval EFI_VOLUME_CORRUPTED The Microcode image is corrupt.
224 @retval EFI_INCOMPATIBLE_VERSION The Microcode image version is incorrect.
225 @retval EFI_SECURITY_VIOLATION The Microcode image fails to load.
226 @retval EFI_WRITE_PROTECTED The flash device is read only.
230 IN MICROCODE_FMP_PRIVATE_DATA
*MicrocodeFmpPrivate
,
233 OUT UINT32
*LastAttemptVersion
,
234 OUT UINT32
*LastAttemptStatus
,
235 OUT CHAR16
**AbortReason
239 Dump private information.
241 @param[in] MicrocodeFmpPrivate private data structure.
245 IN MICROCODE_FMP_PRIVATE_DATA
*MicrocodeFmpPrivate
249 Returns information about the current firmware image(s) of the device.
251 This function allows a copy of the current firmware image to be created and saved.
252 The saved copy could later been used, for example, in firmware image recovery or rollback.
254 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
255 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
256 On input, this is the size of the buffer allocated by the caller.
257 On output, it is the size of the buffer returned by the firmware
258 if the buffer was large enough, or the size of the buffer needed
259 to contain the image(s) information if the buffer was too small.
260 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
261 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
262 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
263 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
264 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
265 descriptors or firmware images within this device.
266 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
267 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
268 @param[out] PackageVersion A version number that represents all the firmware images in the device.
269 The format is vendor specific and new version must have a greater value
270 than the old version. If PackageVersion is not supported, the value is
271 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
272 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
273 that package version update is in progress.
274 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
275 package version name. The buffer is allocated by this function with
276 AllocatePool(), and it is the caller's responsibility to free it with a call
279 @retval EFI_SUCCESS The device was successfully updated with the new image.
280 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
281 needed to hold the image(s) information is returned in ImageInfoSize.
282 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
283 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
289 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
290 IN OUT UINTN
*ImageInfoSize
,
291 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR
*ImageInfo
,
292 OUT UINT32
*DescriptorVersion
,
293 OUT UINT8
*DescriptorCount
,
294 OUT UINTN
*DescriptorSize
,
295 OUT UINT32
*PackageVersion
,
296 OUT CHAR16
**PackageVersionName
300 Retrieves a copy of the current firmware image of the device.
302 This function allows a copy of the current firmware image to be created and saved.
303 The saved copy could later been used, for example, in firmware image recovery or rollback.
305 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
306 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
307 The number is between 1 and DescriptorCount.
308 @param[in,out] Image Points to the buffer where the current image is copied to.
309 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
310 On return, points to the length of the image, in bytes.
312 @retval EFI_SUCCESS The device was successfully updated with the new image.
313 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
314 image. The current buffer size needed to hold the image is returned
316 @retval EFI_INVALID_PARAMETER The Image was NULL.
317 @retval EFI_NOT_FOUND The current image is not copied to the buffer.
318 @retval EFI_UNSUPPORTED The operation is not supported.
319 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
325 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
328 IN OUT UINTN
*ImageSize
332 Updates the firmware image of the device.
334 This function updates the hardware with the new firmware image.
335 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.
336 If the firmware image is updatable, the function should perform the following minimal validations
337 before proceeding to do the firmware image update.
338 - Validate the image authentication if image has attribute
339 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns
340 EFI_SECURITY_VIOLATION if the validation fails.
341 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if
342 the image is unsupported. The function can optionally provide more detailed information on
343 why the image is not a supported image.
344 - Validate the data from VendorCode if not null. Image validation must be performed before
345 VendorCode data validation. VendorCode data is ignored or considered invalid if image
346 validation failed. The function returns EFI_ABORTED if the data is invalid.
348 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if
349 the caller did not specify the policy or use the default policy. As an example, vendor can implement
350 a policy to allow an option to force a firmware image update when the abort reason is due to the new
351 firmware image version is older than the current firmware image version or bad image checksum.
352 Sensitive operations such as those wiping the entire firmware image and render the device to be
353 non-functional should be encoded in the image itself rather than passed with the VendorCode.
354 AbortReason enables vendor to have the option to provide a more detailed description of the abort
355 reason to the caller.
357 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
358 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
359 The number is between 1 and DescriptorCount.
360 @param[in] Image Points to the new image.
361 @param[in] ImageSize Size of the new image in bytes.
362 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.
363 Null indicates the caller did not specify the policy or use the default policy.
364 @param[in] Progress A function used by the driver to report the progress of the firmware update.
365 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
366 details for the aborted operation. The buffer is allocated by this function
367 with AllocatePool(), and it is the caller's responsibility to free it with a
370 @retval EFI_SUCCESS The device was successfully updated with the new image.
371 @retval EFI_ABORTED The operation is aborted.
372 @retval EFI_INVALID_PARAMETER The Image was NULL.
373 @retval EFI_UNSUPPORTED The operation is not supported.
374 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
380 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
382 IN CONST VOID
*Image
,
384 IN CONST VOID
*VendorCode
,
385 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress
,
386 OUT CHAR16
**AbortReason
390 Checks if the firmware image is valid for the device.
392 This function allows firmware update application to validate the firmware image without
393 invoking the SetImage() first.
395 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
396 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
397 The number is between 1 and DescriptorCount.
398 @param[in] Image Points to the new image.
399 @param[in] ImageSize Size of the new image in bytes.
400 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
401 if available, additional information if the image is invalid.
403 @retval EFI_SUCCESS The image was successfully checked.
404 @retval EFI_INVALID_PARAMETER The Image was NULL.
405 @retval EFI_UNSUPPORTED The operation is not supported.
406 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
412 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
414 IN CONST VOID
*Image
,
416 OUT UINT32
*ImageUpdatable
420 Returns information about the firmware package.
422 This function returns package information.
424 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
425 @param[out] PackageVersion A version number that represents all the firmware images in the device.
426 The format is vendor specific and new version must have a greater value
427 than the old version. If PackageVersion is not supported, the value is
428 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
429 comparison is to be performed using PackageVersionName. A value of
430 0xFFFFFFFD indicates that package version update is in progress.
431 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
432 the package version name. The buffer is allocated by this function with
433 AllocatePool(), and it is the caller's responsibility to free it with a
435 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
436 package version name. A value of 0 indicates the device does not support
437 update of package version name. Length is the number of Unicode characters,
438 including the terminating null character.
439 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
440 Definitions' for possible returned values of this parameter. A value of 1
441 indicates the attribute is supported and the current setting value is
442 indicated in AttributesSetting. A value of 0 indicates the attribute is not
443 supported and the current setting value in AttributesSetting is meaningless.
444 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
445 values of this parameter
447 @retval EFI_SUCCESS The package information was successfully returned.
448 @retval EFI_UNSUPPORTED The operation is not supported.
454 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
455 OUT UINT32
*PackageVersion
,
456 OUT CHAR16
**PackageVersionName
,
457 OUT UINT32
*PackageVersionNameMaxLen
,
458 OUT UINT64
*AttributesSupported
,
459 OUT UINT64
*AttributesSetting
463 Updates information about the firmware package.
465 This function updates package information.
466 This function returns EFI_UNSUPPORTED if the package information is not updatable.
467 VendorCode enables vendor to implement vendor-specific package information update policy.
468 Null if the caller did not specify this policy or use the default policy.
470 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
471 @param[in] Image Points to the authentication image.
472 Null if authentication is not required.
473 @param[in] ImageSize Size of the authentication image in bytes.
474 0 if authentication is not required.
475 @param[in] VendorCode This enables vendor to implement vendor-specific firmware
477 Null indicates the caller did not specify this policy or use
479 @param[in] PackageVersion The new package version.
480 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
481 the package version name.
482 The string length is equal to or less than the value returned in
483 PackageVersionNameMaxLen.
485 @retval EFI_SUCCESS The device was successfully updated with the new package
487 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
488 returned in PackageVersionNameMaxLen.
489 @retval EFI_UNSUPPORTED The operation is not supported.
490 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
496 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL
*This
,
497 IN CONST VOID
*Image
,
499 IN CONST VOID
*VendorCode
,
500 IN UINT32 PackageVersion
,
501 IN CONST CHAR16
*PackageVersionName