UefiCpuPkg/MicrocodeUpdate: enhance flash write logic

The patch updated MicrocodeWrite() to move the Microcode replacement logic
to a standalone function -  UpdateMicrocodeFlashRegion().
More detail description is added in UpdateMicrocodeFlashRegion()
to improve readability.

The Microcode information is collected in InitializeMicrocodeDescriptor(),
so that FmpGetImage() can get the info directly.
MicrocodeRead() is not needed any more.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
This commit is contained in:
Jiewen Yao
2016-12-26 23:35:41 +08:00
parent 1f20b2988c
commit 2ed658240c
3 changed files with 495 additions and 319 deletions

View File

@ -50,12 +50,21 @@ typedef struct {
UINT32 LastAttemptStatus;
} MICROCODE_FMP_LAST_ATTEMPT_VARIABLE;
typedef struct {
CPU_MICROCODE_HEADER *MicrocodeEntryPoint;
UINTN TotalSize;
BOOLEAN InUse;
} MICROCODE_INFO;
struct _MICROCODE_FMP_PRIVATE_DATA {
UINT32 Signature;
EFI_FIRMWARE_MANAGEMENT_PROTOCOL Fmp;
EFI_HANDLE Handle;
VOID *MicrocodePatchAddress;
UINTN MicrocodePatchRegionSize;
UINT8 DescriptorCount;
EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;
MICROCODE_INFO *MicrocodeInfo;
UINT32 PackageVersion;
CHAR16 *PackageVersionName;
MICROCODE_FMP_LAST_ATTEMPT_VARIABLE LastAttempt;
@ -83,64 +92,69 @@ typedef struct _MICROCODE_FMP_PRIVATE_DATA MICROCODE_FMP_PRIVATE_DATA;
MICROCODE_FMP_PRIVATE_DATA_SIGNATURE \
)
/**
Get Microcode Region.
@param[out] MicrocodePatchAddress The address of Microcode
@param[out] MicrocodePatchRegionSize The region size of Microcode
@retval TRUE The Microcode region is returned.
@retval FALSE No Microcode region.
**/
BOOLEAN
GetMicrocodeRegion (
OUT VOID **MicrocodePatchAddress,
OUT UINTN *MicrocodePatchRegionSize
);
/**
Get current Microcode information.
@param[out] ImageDescriptor Microcode ImageDescriptor
@param[in] DescriptorCount The count of Microcode ImageDescriptor allocated.
NOTE: The DescriptorCount/ImageDescriptor/MicrocodeInfo in MicrocodeFmpPrivate
are not avaiable in this function.
@param[in] MicrocodeFmpPrivate The Microcode driver private data
@param[in] DescriptorCount The count of Microcode ImageDescriptor allocated.
@param[out] ImageDescriptor Microcode ImageDescriptor
@param[out] MicrocodeInfo Microcode information
@return Microcode count
**/
UINTN
GetMicrocodeInfo (
IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate,
IN UINTN DescriptorCount, OPTIONAL
OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor, OPTIONAL
IN UINTN DescriptorCount OPTIONAL
);
/**
Read Microcode.
@param[in] ImageIndex The index of Microcode image.
@param[in, out] Image The Microcode image buffer.
@param[in, out] ImageSize The size of Microcode image buffer in bytes.
@retval EFI_SUCCESS The Microcode image is read.
@retval EFI_NOT_FOUND The Microcode image is not found.
**/
EFI_STATUS
MicrocodeRead (
IN UINTN ImageIndex,
IN OUT VOID *Image,
IN OUT UINTN *ImageSize
OUT MICROCODE_INFO *MicrocodeInfo OPTIONAL
);
/**
Write Microcode.
@param[in] ImageIndex The index of Microcode image.
@param[in] Image The Microcode image buffer.
@param[in] ImageSize The size of Microcode image buffer in bytes.
@param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
@param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
@param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
details for the aborted operation. The buffer is allocated by this function
with AllocatePool(), and it is the caller's responsibility to free it with a
call to FreePool().
@param[in] MicrocodeFmpPrivate The Microcode driver private data
@param[in] Image The Microcode image buffer.
@param[in] ImageSize The size of Microcode image buffer in bytes.
@param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
@param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
@param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
details for the aborted operation. The buffer is allocated by this function
with AllocatePool(), and it is the caller's responsibility to free it with a
call to FreePool().
@retval EFI_SUCCESS The Microcode image is written.
@retval EFI_VOLUME_CORRUPTED The Microcode image is corrupt.
@retval EFI_INCOMPATIBLE_VERSION The Microcode image version is incorrect.
@retval EFI_SECURITY_VIOLATION The Microcode image fails to load.
@retval EFI_WRITE_PROTECTED The flash device is read only.
@retval EFI_WRITE_PROTECTED The flash device is read only.
**/
EFI_STATUS
MicrocodeWrite (
IN UINTN ImageIndex,
IN VOID *Image,
IN UINTN ImageSize,
OUT UINT32 *LastAttemptVersion,
OUT UINT32 *LastAttemptStatus,
OUT CHAR16 **AbortReason
IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate,
IN VOID *Image,
IN UINTN ImageSize,
OUT UINT32 *LastAttemptVersion,
OUT UINT32 *LastAttemptStatus,
OUT CHAR16 **AbortReason
);
/**