]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelSiliconPkg: Move MicrocodeUpdate from UefiCpuPkg
authorStar Zeng <star.zeng@intel.com>
Fri, 17 Nov 2017 06:28:25 +0000 (14:28 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 30 Nov 2017 01:25:28 +0000 (09:25 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=540

To consume FIT table for Microcode update,
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe
needs to be updated to consume
IntelSiliconPkg/Include/IndustryStandard/FirmwareInterfaceTable.h,
but UefiCpuPkg could not depend on IntelSiliconPkg.

Since the Microcode update feature is specific to Intel,
we can first move the Microcode update feature code from
UefiCpuPkg to IntelSiliconPkg [first step], then update
the code to consume FIT table [second step].

This patch series is for the first step.

Note: No any code change in this patch, just move.
Next patch will update MicrocodeUpdate to build with the package.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
39 files changed:
IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/Microcode/Microcode.inf [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/Readme.md [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.uni [new file with mode: 0644]
IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxeExtra.uni [new file with mode: 0644]
IntelSiliconPkg/Include/Guid/MicrocodeFmp.h [new file with mode: 0644]
IntelSiliconPkg/Include/Library/MicrocodeFlashAccessLib.h [new file with mode: 0644]
IntelSiliconPkg/IntelSiliconPkg.dec
UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c [deleted file]
UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf [deleted file]
UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Microcode/Microcode.inf [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Readme.md [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.uni [deleted file]
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxeExtra.uni [deleted file]
UefiCpuPkg/Include/Guid/MicrocodeFmp.h [deleted file]
UefiCpuPkg/Include/Library/MicrocodeFlashAccessLib.h [deleted file]
UefiCpuPkg/UefiCpuPkg.dec
UefiCpuPkg/UefiCpuPkg.dsc

diff --git a/IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c b/IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c
new file mode 100644 (file)
index 0000000..7a5ec15
--- /dev/null
@@ -0,0 +1,42 @@
+/** @file\r
+  Microcode flash device access library NULL instance.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MicrocodeFlashAccessLib.h>\r
+\r
+/**\r
+  Perform microcode write opreation.\r
+\r
+  @param[in] FlashAddress      The address of flash device to be accessed.\r
+  @param[in] Buffer            The pointer to the data buffer.\r
+  @param[in] Length            The length of data buffer in bytes.\r
+\r
+  @retval EFI_SUCCESS           The operation returns successfully.\r
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.\r
+  @retval EFI_UNSUPPORTED       The flash device access is unsupported.\r
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MicrocodeFlashWrite (\r
+  IN EFI_PHYSICAL_ADDRESS         FlashAddress,\r
+  IN VOID                         *Buffer,\r
+  IN UINTN                        Length\r
+  )\r
+{\r
+  CopyMem((VOID *)(UINTN)(FlashAddress), Buffer, Length);\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf b/IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
new file mode 100644 (file)
index 0000000..a4a47e0
--- /dev/null
@@ -0,0 +1,40 @@
+## @file\r
+#  Microcode flash device access library.\r
+#\r
+#  Microcode flash device access library NULL instance.\r
+#\r
+#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = MicrocodeFlashAccessLibNull\r
+  MODULE_UNI_FILE                = MicrocodeFlashAccessLibNull.uni\r
+  FILE_GUID                      = 6F871ADD-9D86-4676-8BAD-68E2E451FC5B\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = MicrocodeFlashAccessLib\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  MicrocodeFlashAccessLibNull.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UefiCpuPkg/UefiCpuPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
diff --git a/IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni b/IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
new file mode 100644 (file)
index 0000000..cc4195c
--- /dev/null
@@ -0,0 +1,21 @@
+// /** @file\r
+//  Microcode flash device access library.\r
+//\r
+//  Microcode flash device access library NULL instance.\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution. The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "Microcode flash device access library."\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "Microcode flash device access library NULL instance."\r
+\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc b/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc
new file mode 100644 (file)
index 0000000..1b22c55
--- /dev/null
@@ -0,0 +1,33 @@
+## @file\r
+# MicrocodeCapsulePdb\r
+#\r
+# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials\r
+#    are licensed and made available under the terms and conditions of the BSD License\r
+#    which accompanies this distribution. The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+#\r
+# Uncomment the following line and update with your platform pkg name\r
+#\r
+#  PLATFORM_NAME                  = <PlatformPkg>\r
+  PLATFORM_GUID                  = 6875FD33-602E-4EF9-9DF2-8BA7D8B7A7AF\r
+  PLATFORM_VERSION               = 0.1\r
+#\r
+# Uncomment the following line and update with your platform pkg name\r
+#\r
+#  FLASH_DEFINITION               = <PlatformPkg>/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf\r
+#\r
+# Uncomment the following line and update with your platform pkg name\r
+#\r
+#  OUTPUT_DIRECTORY               = Build/<PlatformPkg>\r
+  SUPPORTED_ARCHITECTURES        = IA32|X64\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf b/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf
new file mode 100644 (file)
index 0000000..f171604
--- /dev/null
@@ -0,0 +1,32 @@
+## @file\r
+#\r
+# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials\r
+#    are licensed and made available under the terms and conditions of the BSD License\r
+#    which accompanies this distribution. The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[FmpPayload.FmpPayloadMicrocode1]\r
+IMAGE_HEADER_INIT_VERSION = 0x02\r
+IMAGE_TYPE_ID             = 96d4fdcd-1502-424d-9d4c-9b12d2dcae5c # Microcode GUID (do not change it)\r
+IMAGE_INDEX               = 0x1\r
+HARDWARE_INSTANCE         = 0x0\r
+\r
+#\r
+# Uncomment the following line and update with path to Microcode PDB file\r
+#\r
+#FILE DATA = $(WORKSPACE)/<PlatformPkg>/Microcode/Microcode.pdb\r
+\r
+[Capsule.MicrocodeCapsule]\r
+CAPSULE_GUID                = 6dcbd5ed-e82d-4c44-bda1-7194199ad92a # FMP special Guid (do not change it)\r
+CAPSULE_FLAGS               = PersistAcrossReset,InitiateReset\r
+CAPSULE_HEADER_SIZE         = 0x20\r
+CAPSULE_HEADER_INIT_VERSION = 0x1\r
+\r
+FMP_PAYLOAD = FmpPayloadMicrocode1\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md b/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md
new file mode 100644 (file)
index 0000000..9f81373
--- /dev/null
@@ -0,0 +1,20 @@
+# How to generate Microcode FMP from Microcode PDB file\r
+\r
+1) Copy directory `UefiCpuPkg/Feature/Capsule/MicrocodeUpdatePdb` to `<Your Platform Package>/MicrocodeUpdatePdb`.\r
+\r
+2) Uncomment and update `FILE DATA` statement in `<Your Platform Package>/MicrocodeUpdatePdb/MicrocodeCapsulePdb.fdf` with path to a Microcode PDB file.  The PDB file can placed in `<Your Platform Package>/MicrocodeUpdatePdb` or any other path.\r
+\r
+`FILE DATA = <your Microcode PDB file path>`\r
+\r
+Uncomment and update `PLATFORM_NAME`, `FLASH_DEFINITION`, `OUTPUT_DIRECTORY` section in `<Your Platform Package>/MicrocodeUpdatePdb/MicrocodeCapsulePdb.dsc` with <Your Platform Package>.\r
+\r
+    PLATFORM_NAME                  = <Your Platform Package>\r
+    FLASH_DEFINITION               = <Your Platform Package>/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf\r
+    OUTPUT_DIRECTORY               = Build/<Your Platform Package>\r
+\r
+3) Use EDK II build tools to generate the Microcode FMP Capsule\r
+\r
+`build -p <Your Platform Package>/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc`\r
+\r
+4) The Microcode FMP Capsule is generated at `$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/MicrocodeCapsule.Cap`\r
+\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/Microcode/Microcode.inf b/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/Microcode/Microcode.inf
new file mode 100644 (file)
index 0000000..81af841
--- /dev/null
@@ -0,0 +1,27 @@
+## @file\r
+# Microcode text file to binary\r
+#\r
+# Convert text format microcode to binary format.\r
+#\r
+#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+BASE_NAME            = Microcode\r
+FILE_GUID            = ABC36AAC-2031-4422-896E-0A3B899AD0B4\r
+COMPONENT_TYPE       = Microcode\r
+FFS_EXT              = .ffs\r
+\r
+[Sources]\r
+#\r
+# Uncomment the following line and update with name of Microcode TXT file\r
+#\r
+#Microcode.txt\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc b/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc
new file mode 100644 (file)
index 0000000..a66f89b
--- /dev/null
@@ -0,0 +1,39 @@
+## @file\r
+# MicrocodeCapsuleTxt\r
+#\r
+# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials\r
+#    are licensed and made available under the terms and conditions of the BSD License\r
+#    which accompanies this distribution. The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+#\r
+# Uncomment the following line and update with your platform pkg name\r
+#\r
+#  PLATFORM_NAME                  = <PlatformPkg>\r
+  PLATFORM_GUID                  = 6875FD33-602E-4EF9-9DF2-8BA7D8B7A7AF\r
+  PLATFORM_VERSION               = 0.1\r
+#\r
+# Uncomment the following line and update with your platform pkg name\r
+#\r
+#  FLASH_DEFINITION               = <PlatformPkg>/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf\r
+#\r
+# Uncomment the following line and update with your platform pkg name\r
+#\r
+#  OUTPUT_DIRECTORY               = Build/<PlatformPkg>\r
+  SUPPORTED_ARCHITECTURES        = IA32|X64\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+\r
+[Components]\r
+#\r
+# Uncomment the following line and update with path to Microcode INF file\r
+#\r
+#  <PlatformPkg>/MicrocodeCapsuleTxt/Microcode/Microcode.inf\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf b/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf
new file mode 100644 (file)
index 0000000..113693b
--- /dev/null
@@ -0,0 +1,32 @@
+## @file\r
+#\r
+# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#    This program and the accompanying materials\r
+#    are licensed and made available under the terms and conditions of the BSD License\r
+#    which accompanies this distribution. The full text of the license may be found at\r
+#    http://opensource.org/licenses/bsd-license.php\r
+#\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[FmpPayload.FmpPayloadMicrocode1]\r
+IMAGE_HEADER_INIT_VERSION = 0x02\r
+IMAGE_TYPE_ID             = 96d4fdcd-1502-424d-9d4c-9b12d2dcae5c # Microcode GUID (do not change it)\r
+IMAGE_INDEX               = 0x1\r
+HARDWARE_INSTANCE         = 0x0\r
+\r
+#\r
+# Uncomment the following line and update with path to Microcode MCB file\r
+#\r
+#FILE DATA = $(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/IA32/PlatformPkg/MicrocodeCapsuleTxt/Microcode/Microcode/OUTPUT/Microcode.mcb\r
+\r
+[Capsule.MicrocodeCapsule]\r
+CAPSULE_GUID                = 6dcbd5ed-e82d-4c44-bda1-7194199ad92a # FMP special Guid (do not change it)\r
+CAPSULE_FLAGS               = PersistAcrossReset,InitiateReset\r
+CAPSULE_HEADER_SIZE         = 0x20\r
+CAPSULE_HEADER_INIT_VERSION = 0x1\r
+\r
+FMP_PAYLOAD = FmpPayloadMicrocode1\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/Readme.md b/IntelSiliconPkg/Feature/Capsule/MicrocodeCapsuleTxt/Readme.md
new file mode 100644 (file)
index 0000000..f7d7040
--- /dev/null
@@ -0,0 +1,33 @@
+# How to generate Microcode FMP from Microcode TXT file\r
+\r
+1) Copy directory `UefiCpuPkg/Feature/Capsule/MicrocodeUpdateTxt` to `<Your Platform Package>/MicrocodeUpdateTxt`\r
+\r
+2) Copy microcode TXT file to`<Your Platform Package>/MicrocodeUpdateTxt/Microcode`\r
+\r
+3) Uncomment and update statement in `[Sources]` section of `<Your Platform Package>/MicrocodeUpdateTxt/Microcode/Microcode.inf` with name of Microcode TXT file copied in previous step.\r
+\r
+    [Sources]\r
+    <Your Microcode TXT file>\r
+\r
+Uncomment and update `FILE DATA` statement in `<Your Platform Package>/MicrocodeUpdateTxt/MicrocodeCapsuleTxt.fdf` with path to a Microcode MCB file.  The MCB file is placed in `$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/IA32/<Your Platform Package>/MicrocodeUpdateTxt/Microcode/Microcode/OUTPUT/`.\r
+\r
+`FILE DATA = <your Microcode MCB file path>`\r
+\r
+Uncomment and update `PLATFORM_NAME`, `FLASH_DEFINITION`, `OUTPUT_DIRECTORY` section in `<Your Platform Package>/MicrocodeUpdateTxt/MicrocodeCapsuleTxt.dsc` with <Your Platform Package>.\r
+\r
+    PLATFORM_NAME                  = <Your Platform Package>\r
+    FLASH_DEFINITION               = <Your Platform Package>/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf\r
+    OUTPUT_DIRECTORY               = Build/<Your Platform Package>\r
+\r
+Uncomment and update statement in `Components` section of `<Your Platform Package>/MicrocodeUpdateTxt/MicrocodeCapsuleTxt.dsc` with path to a Microcode INF file.\r
+\r
+    [Components]\r
+    <Your Microcode INF file>\r
+\r
+4) Use EDK II build tools to generate the Microcode FMP Capsule\r
+\r
+`build -p <Your Platform Package>/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc`\r
+\r
+5) The generated Microcode FMP Capsule is found at `$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/MicrocodeCapsule.Cap`\r
+\r
+\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c
new file mode 100644 (file)
index 0000000..ebde93a
--- /dev/null
@@ -0,0 +1,748 @@
+/** @file\r
+  Produce FMP instance for Microcode.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "MicrocodeUpdate.h"\r
+\r
+//\r
+// MicrocodeFmp driver private data\r
+//\r
+MICROCODE_FMP_PRIVATE_DATA *mMicrocodeFmpPrivate = NULL;\r
+\r
+EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol = {\r
+  FmpGetImageInfo,\r
+  FmpGetImage,\r
+  FmpSetImage,\r
+  FmpCheckImage,\r
+  FmpGetPackageInfo,\r
+  FmpSetPackageInfo\r
+};\r
+\r
+/**\r
+  Initialize Microcode Descriptor.\r
+\r
+  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
+\r
+  @return EFI_SUCCESS Microcode Descriptor is initialized.\r
+**/\r
+EFI_STATUS\r
+InitializeMicrocodeDescriptor (\r
+  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
+  );\r
+\r
+/**\r
+  Returns information about the current firmware image(s) of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]      This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in, out] ImageInfoSize      A pointer to the size, in bytes, of the ImageInfo buffer.\r
+                                     On input, this is the size of the buffer allocated by the caller.\r
+                                     On output, it is the size of the buffer returned by the firmware\r
+                                     if the buffer was large enough, or the size of the buffer needed\r
+                                     to contain the image(s) information if the buffer was too small.\r
+  @param[in, out] ImageInfo          A pointer to the buffer in which firmware places the current image(s)\r
+                                     information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
+  @param[out]     DescriptorVersion  A pointer to the location in which firmware returns the version number\r
+                                     associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     DescriptorCount    A pointer to the location in which firmware returns the number of\r
+                                     descriptors or firmware images within this device.\r
+  @param[out]     DescriptorSize     A pointer to the location in which firmware returns the size, in bytes,\r
+                                     of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     PackageVersion     A version number that represents all the firmware images in the device.\r
+                                     The format is vendor specific and new version must have a greater value\r
+                                     than the old version. If PackageVersion is not supported, the value is\r
+                                     0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
+                                     is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
+                                     that package version update is in progress.\r
+  @param[out]     PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
+                                     package version name. The buffer is allocated by this function with\r
+                                     AllocatePool(), and it is the caller's responsibility to free it with a call\r
+                                     to FreePool().\r
+\r
+  @retval EFI_SUCCESS                The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL       The ImageInfo buffer was too small. The current buffer size\r
+                                     needed to hold the image(s) information is returned in ImageInfoSize.\r
+  @retval EFI_INVALID_PARAMETER      ImageInfoSize is NULL.\r
+  @retval EFI_DEVICE_ERROR           Valid information could not be returned. Possible corrupted image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImageInfo (\r
+  IN        EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN OUT    UINTN                             *ImageInfoSize,\r
+  IN OUT    EFI_FIRMWARE_IMAGE_DESCRIPTOR     *ImageInfo,\r
+  OUT       UINT32                            *DescriptorVersion,\r
+  OUT       UINT8                             *DescriptorCount,\r
+  OUT       UINTN                             *DescriptorSize,\r
+  OUT       UINT32                            *PackageVersion,\r
+  OUT       CHAR16                            **PackageVersionName\r
+  )\r
+{\r
+  MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
+  UINTN                      Index;\r
+\r
+  MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
+\r
+  if(ImageInfoSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (*ImageInfoSize < sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount) {\r
+    *ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  if (ImageInfo == NULL ||\r
+      DescriptorVersion == NULL ||\r
+      DescriptorCount == NULL ||\r
+      DescriptorSize == NULL ||\r
+      PackageVersion == NULL ||\r
+      PackageVersionName == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ImageInfoSize      = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r
+  *DescriptorSize     = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r
+  *DescriptorCount    = MicrocodeFmpPrivate->DescriptorCount;\r
+  *DescriptorVersion  = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;\r
+\r
+  //\r
+  // supports 1 ImageInfo descriptor\r
+  //\r
+  CopyMem(&ImageInfo[0], MicrocodeFmpPrivate->ImageDescriptor, sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount);\r
+  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
+    if ((ImageInfo[Index].AttributesSetting & IMAGE_ATTRIBUTE_IN_USE) != 0) {\r
+      ImageInfo[Index].LastAttemptVersion = MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion;\r
+      ImageInfo[Index].LastAttemptStatus = MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus;\r
+    }\r
+  }\r
+\r
+  //\r
+  // package version\r
+  //\r
+  *PackageVersion = MicrocodeFmpPrivate->PackageVersion;\r
+  if (MicrocodeFmpPrivate->PackageVersionName != NULL) {\r
+    *PackageVersionName = AllocateCopyPool(StrSize(MicrocodeFmpPrivate->PackageVersionName), MicrocodeFmpPrivate->PackageVersionName);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves a copy of the current firmware image of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]     This            A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]     ImageIndex      A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in,out] Image           Points to the buffer where the current image is copied to.\r
+  @param[in,out] ImageSize       On entry, points to the size of the buffer pointed to by Image, in bytes.\r
+                                 On return, points to the length of the image, in bytes.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to hold the\r
+                                 image. The current buffer size needed to hold the image is returned\r
+                                 in ImageSize.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_NOT_FOUND          The current image is not copied to the buffer.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  OUT  VOID                         *Image,\r
+  IN  OUT  UINTN                        *ImageSize\r
+  )\r
+{\r
+  MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
+  MICROCODE_INFO             *MicrocodeInfo;\r
+\r
+  if (Image == NULL || ImageSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
+\r
+  if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || ImageSize == NULL || Image == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  MicrocodeInfo = &MicrocodeFmpPrivate->MicrocodeInfo[ImageIndex - 1];\r
+\r
+  if (*ImageSize < MicrocodeInfo->TotalSize) {\r
+    *ImageSize = MicrocodeInfo->TotalSize;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  *ImageSize = MicrocodeInfo->TotalSize;\r
+  CopyMem (Image, MicrocodeInfo->MicrocodeEntryPoint, MicrocodeInfo->TotalSize);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Updates the firmware image of the device.\r
+\r
+  This function updates the hardware with the new firmware image.\r
+  This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
+  If the firmware image is updatable, the function should perform the following minimal validations\r
+  before proceeding to do the firmware image update.\r
+  - Validate the image authentication if image has attribute\r
+    IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
+    EFI_SECURITY_VIOLATION if the validation fails.\r
+  - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
+    the image is unsupported. The function can optionally provide more detailed information on\r
+    why the image is not a supported image.\r
+  - Validate the data from VendorCode if not null. Image validation must be performed before\r
+    VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
+    validation failed. The function returns EFI_ABORTED if the data is invalid.\r
+\r
+  VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
+  the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
+  a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
+  firmware image version is older than the current firmware image version or bad image checksum.\r
+  Sensitive operations such as those wiping the entire firmware image and render the device to be\r
+  non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
+  AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
+  reason to the caller.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware image update policy.\r
+                                 Null indicates the caller did not specify the policy or use the default policy.\r
+  @param[in]  Progress           A function used by the driver to report the progress of the firmware update.\r
+  @param[out] AbortReason        A pointer to a pointer to a null-terminated string providing more\r
+                                 details for the aborted operation. The buffer is allocated by this function\r
+                                 with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                 call to FreePool().\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_ABORTED            The operation is aborted.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                 *This,\r
+  IN  UINT8                                            ImageIndex,\r
+  IN  CONST VOID                                       *Image,\r
+  IN  UINTN                                            ImageSize,\r
+  IN  CONST VOID                                       *VendorCode,\r
+  IN  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS    Progress,\r
+  OUT CHAR16                                           **AbortReason\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_STATUS                 VarStatus;\r
+  MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
+\r
+  if (Image == NULL || AbortReason == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
+  *AbortReason     = NULL;\r
+\r
+  if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || Image == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = MicrocodeWrite(MicrocodeFmpPrivate, (VOID *)Image, ImageSize, &MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, &MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus, AbortReason);\r
+  DEBUG((DEBUG_INFO, "SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
+  VarStatus = gRT->SetVariable(\r
+                     MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
+                     &gEfiCallerIdGuid,\r
+                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                     sizeof(MicrocodeFmpPrivate->LastAttempt),\r
+                     &MicrocodeFmpPrivate->LastAttempt\r
+                     );\r
+  DEBUG((DEBUG_INFO, "SetLastAttemp - %r\n", VarStatus));\r
+\r
+  if (!EFI_ERROR(Status)) {\r
+    InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
+    DumpPrivateInfo (MicrocodeFmpPrivate);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Checks if the firmware image is valid for the device.\r
+\r
+  This function allows firmware update application to validate the firmware image without\r
+  invoking the SetImage() first.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[out] ImageUpdatable     Indicates if the new image is valid for update. It also provides,\r
+                                 if available, additional information if the image is invalid.\r
+\r
+  @retval EFI_SUCCESS            The image was successfully checked.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpCheckImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  CONST VOID                        *Image,\r
+  IN  UINTN                             ImageSize,\r
+  OUT UINT32                            *ImageUpdatable\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Returns information about the firmware package.\r
+\r
+  This function returns package information.\r
+\r
+  @param[in]  This                     A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[out] PackageVersion           A version number that represents all the firmware images in the device.\r
+                                       The format is vendor specific and new version must have a greater value\r
+                                       than the old version. If PackageVersion is not supported, the value is\r
+                                       0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
+                                       comparison is to be performed using PackageVersionName. A value of\r
+                                       0xFFFFFFFD indicates that package version update is in progress.\r
+  @param[out] PackageVersionName       A pointer to a pointer to a null-terminated string representing\r
+                                       the package version name. The buffer is allocated by this function with\r
+                                       AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                       call to FreePool().\r
+  @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
+                                       package version name. A value of 0 indicates the device does not support\r
+                                       update of package version name. Length is the number of Unicode characters,\r
+                                       including the terminating null character.\r
+  @param[out] AttributesSupported      Package attributes that are supported by this device. See 'Package Attribute\r
+                                       Definitions' for possible returned values of this parameter. A value of 1\r
+                                       indicates the attribute is supported and the current setting value is\r
+                                       indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
+                                       supported and the current setting value in AttributesSetting is meaningless.\r
+  @param[out] AttributesSetting        Package attributes. See 'Package Attribute Definitions' for possible returned\r
+                                       values of this parameter\r
+\r
+  @retval EFI_SUCCESS                  The package information was successfully returned.\r
+  @retval EFI_UNSUPPORTED              The operation is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
+  OUT UINT32                           *PackageVersion,\r
+  OUT CHAR16                           **PackageVersionName,\r
+  OUT UINT32                           *PackageVersionNameMaxLen,\r
+  OUT UINT64                           *AttributesSupported,\r
+  OUT UINT64                           *AttributesSetting\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Updates information about the firmware package.\r
+\r
+  This function updates package information.\r
+  This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
+  VendorCode enables vendor to implement vendor-specific package information update policy.\r
+  Null if the caller did not specify this policy or use the default policy.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  Image              Points to the authentication image.\r
+                                 Null if authentication is not required.\r
+  @param[in]  ImageSize          Size of the authentication image in bytes.\r
+                                 0 if authentication is not required.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware\r
+                                 image update policy.\r
+                                 Null indicates the caller did not specify this policy or use\r
+                                 the default policy.\r
+  @param[in]  PackageVersion     The new package version.\r
+  @param[in]  PackageVersionName A pointer to the new null-terminated Unicode string representing\r
+                                 the package version name.\r
+                                 The string length is equal to or less than the value returned in\r
+                                 PackageVersionNameMaxLen.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new package\r
+                                 information.\r
+  @retval EFI_INVALID_PARAMETER  The PackageVersionName length is longer than the value\r
+                                 returned in PackageVersionNameMaxLen.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL   *This,\r
+  IN  CONST VOID                         *Image,\r
+  IN  UINTN                              ImageSize,\r
+  IN  CONST VOID                         *VendorCode,\r
+  IN  UINT32                             PackageVersion,\r
+  IN  CONST CHAR16                       *PackageVersionName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Initialize Processor Microcode Index.\r
+\r
+  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
+**/\r
+VOID\r
+InitializedProcessorMicrocodeIndex (\r
+  IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
+  )\r
+{\r
+  UINTN       CpuIndex;\r
+  UINTN       MicrocodeIndex;\r
+  UINTN       TargetCpuIndex;\r
+  UINT32      AttemptStatus;\r
+  EFI_STATUS  Status;\r
+\r
+  for (CpuIndex = 0; CpuIndex < MicrocodeFmpPrivate->ProcessorCount; CpuIndex++) {\r
+    if (MicrocodeFmpPrivate->ProcessorInfo[CpuIndex].MicrocodeIndex != (UINTN)-1) {\r
+      continue;\r
+    }\r
+    for (MicrocodeIndex = 0; MicrocodeIndex < MicrocodeFmpPrivate->DescriptorCount; MicrocodeIndex++) {\r
+      if (!MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].InUse) {\r
+        continue;\r
+      }\r
+      TargetCpuIndex = CpuIndex;\r
+      Status = VerifyMicrocode(\r
+                 MicrocodeFmpPrivate,\r
+                 MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].MicrocodeEntryPoint,\r
+                 MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].TotalSize,\r
+                 FALSE,\r
+                 &AttemptStatus,\r
+                 NULL,\r
+                 &TargetCpuIndex\r
+                 );\r
+      if (!EFI_ERROR(Status)) {\r
+        MicrocodeFmpPrivate->ProcessorInfo[CpuIndex].MicrocodeIndex = MicrocodeIndex;\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+/**\r
+  Initialize Microcode Descriptor.\r
+\r
+  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
+\r
+  @return EFI_SUCCESS Microcode Descriptor is initialized.\r
+**/\r
+EFI_STATUS\r
+InitializeMicrocodeDescriptor (\r
+  IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
+  )\r
+{\r
+  UINT8    CurrentMicrocodeCount;\r
+\r
+  CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, 0, NULL, NULL);\r
+\r
+  if (CurrentMicrocodeCount > MicrocodeFmpPrivate->DescriptorCount) {\r
+    if (MicrocodeFmpPrivate->ImageDescriptor != NULL) {\r
+      FreePool(MicrocodeFmpPrivate->ImageDescriptor);\r
+      MicrocodeFmpPrivate->ImageDescriptor = NULL;\r
+    }\r
+    if (MicrocodeFmpPrivate->MicrocodeInfo != NULL) {\r
+      FreePool(MicrocodeFmpPrivate->MicrocodeInfo);\r
+      MicrocodeFmpPrivate->MicrocodeInfo = NULL;\r
+    }\r
+  } else {\r
+    ZeroMem(MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
+    ZeroMem(MicrocodeFmpPrivate->MicrocodeInfo, MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r
+  }\r
+\r
+  MicrocodeFmpPrivate->DescriptorCount = CurrentMicrocodeCount;\r
+\r
+  if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
+    MicrocodeFmpPrivate->ImageDescriptor = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
+    if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+  if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r
+    MicrocodeFmpPrivate->MicrocodeInfo = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r
+    if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+\r
+  CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, MicrocodeFmpPrivate->DescriptorCount, MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->MicrocodeInfo);\r
+  ASSERT(CurrentMicrocodeCount == MicrocodeFmpPrivate->DescriptorCount);\r
+\r
+  InitializedProcessorMicrocodeIndex (MicrocodeFmpPrivate);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Initialize MicrocodeFmpDriver multiprocessor information.\r
+\r
+  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
+\r
+  @return EFI_SUCCESS private data is initialized.\r
+**/\r
+EFI_STATUS\r
+InitializeProcessorInfo (\r
+  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
+  )\r
+{\r
+  EFI_STATUS                           Status;\r
+  EFI_MP_SERVICES_PROTOCOL             *MpService;\r
+  UINTN                                NumberOfProcessors;\r
+  UINTN                                NumberOfEnabledProcessors;\r
+  UINTN                                Index;\r
+  UINTN                                BspIndex;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpService);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  MicrocodeFmpPrivate->MpService = MpService;\r
+  MicrocodeFmpPrivate->ProcessorCount = 0;\r
+  MicrocodeFmpPrivate->ProcessorInfo = NULL;\r
+\r
+  Status = MpService->GetNumberOfProcessors (MpService, &NumberOfProcessors, &NumberOfEnabledProcessors);\r
+  ASSERT_EFI_ERROR(Status);\r
+  MicrocodeFmpPrivate->ProcessorCount = NumberOfProcessors;\r
+\r
+  Status = MpService->WhoAmI (MpService, &BspIndex);\r
+  ASSERT_EFI_ERROR(Status);\r
+  MicrocodeFmpPrivate->BspIndex = BspIndex;\r
+\r
+  MicrocodeFmpPrivate->ProcessorInfo = AllocateZeroPool (sizeof(PROCESSOR_INFO) * MicrocodeFmpPrivate->ProcessorCount);\r
+  if (MicrocodeFmpPrivate->ProcessorInfo == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Index = 0; Index < NumberOfProcessors; Index++) {\r
+    MicrocodeFmpPrivate->ProcessorInfo[Index].CpuIndex = Index;\r
+    MicrocodeFmpPrivate->ProcessorInfo[Index].MicrocodeIndex = (UINTN)-1;\r
+    if (Index == BspIndex) {\r
+      CollectProcessorInfo (&MicrocodeFmpPrivate->ProcessorInfo[Index]);\r
+    } else {\r
+      Status = MpService->StartupThisAP (\r
+                            MpService,\r
+                            CollectProcessorInfo,\r
+                            Index,\r
+                            NULL,\r
+                            0,\r
+                            &MicrocodeFmpPrivate->ProcessorInfo[Index],\r
+                            NULL\r
+                            );\r
+      ASSERT_EFI_ERROR(Status);\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Dump private information.\r
+\r
+  @param[in] MicrocodeFmpPrivate private data structure.\r
+**/\r
+VOID\r
+DumpPrivateInfo (\r
+  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
+  )\r
+{\r
+  UINTN                                Index;\r
+  PROCESSOR_INFO                       *ProcessorInfo;\r
+  MICROCODE_INFO                       *MicrocodeInfo;\r
+  EFI_FIRMWARE_IMAGE_DESCRIPTOR        *ImageDescriptor;\r
+\r
+  DEBUG ((DEBUG_INFO, "ProcessorInfo:\n"));\r
+  DEBUG ((DEBUG_INFO, "  ProcessorCount - 0x%x\n", MicrocodeFmpPrivate->ProcessorCount));\r
+  DEBUG ((DEBUG_INFO, "  BspIndex - 0x%x\n", MicrocodeFmpPrivate->BspIndex));\r
+\r
+  ProcessorInfo = MicrocodeFmpPrivate->ProcessorInfo;\r
+  for (Index = 0; Index < MicrocodeFmpPrivate->ProcessorCount; Index++) {\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "  ProcessorInfo[0x%x] - 0x%08x, 0x%02x, 0x%08x, (0x%x)\n",\r
+      ProcessorInfo[Index].CpuIndex,\r
+      ProcessorInfo[Index].ProcessorSignature,\r
+      ProcessorInfo[Index].PlatformId,\r
+      ProcessorInfo[Index].MicrocodeRevision,\r
+      ProcessorInfo[Index].MicrocodeIndex\r
+      ));\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "MicrocodeInfo:\n"));\r
+  MicrocodeInfo = MicrocodeFmpPrivate->MicrocodeInfo;\r
+  DEBUG ((DEBUG_INFO, "  MicrocodeRegion - 0x%x - 0x%x\n", MicrocodeFmpPrivate->MicrocodePatchAddress, MicrocodeFmpPrivate->MicrocodePatchRegionSize));\r
+  DEBUG ((DEBUG_INFO, "  MicrocodeCount - 0x%x\n", MicrocodeFmpPrivate->DescriptorCount));\r
+  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "  MicrocodeInfo[0x%x] - 0x%08x, 0x%08x, (0x%x)\n",\r
+      Index,\r
+      MicrocodeInfo[Index].MicrocodeEntryPoint,\r
+      MicrocodeInfo[Index].TotalSize,\r
+      MicrocodeInfo[Index].InUse\r
+      ));\r
+  }\r
+\r
+  ImageDescriptor = MicrocodeFmpPrivate->ImageDescriptor;\r
+  DEBUG ((DEBUG_VERBOSE, "ImageDescriptor:\n"));\r
+  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
+    DEBUG((DEBUG_VERBOSE, "  ImageDescriptor (%d)\n", Index));\r
+    DEBUG((DEBUG_VERBOSE, "    ImageIndex                  - 0x%x\n", ImageDescriptor[Index].ImageIndex));\r
+    DEBUG((DEBUG_VERBOSE, "    ImageTypeId                 - %g\n", &ImageDescriptor[Index].ImageTypeId));\r
+    DEBUG((DEBUG_VERBOSE, "    ImageId                     - 0x%lx\n", ImageDescriptor[Index].ImageId));\r
+    DEBUG((DEBUG_VERBOSE, "    ImageIdName                 - %s\n", ImageDescriptor[Index].ImageIdName));\r
+    DEBUG((DEBUG_VERBOSE, "    Version                     - 0x%x\n", ImageDescriptor[Index].Version));\r
+    DEBUG((DEBUG_VERBOSE, "    VersionName                 - %s\n", ImageDescriptor[Index].VersionName));\r
+    DEBUG((DEBUG_VERBOSE, "    Size                        - 0x%x\n", ImageDescriptor[Index].Size));\r
+    DEBUG((DEBUG_VERBOSE, "    AttributesSupported         - 0x%lx\n", ImageDescriptor[Index].AttributesSupported));\r
+    DEBUG((DEBUG_VERBOSE, "    AttributesSetting           - 0x%lx\n", ImageDescriptor[Index].AttributesSetting));\r
+    DEBUG((DEBUG_VERBOSE, "    Compatibilities             - 0x%lx\n", ImageDescriptor[Index].Compatibilities));\r
+    DEBUG((DEBUG_VERBOSE, "    LowestSupportedImageVersion - 0x%x\n", ImageDescriptor[Index].LowestSupportedImageVersion));\r
+    DEBUG((DEBUG_VERBOSE, "    LastAttemptVersion          - 0x%x\n", ImageDescriptor[Index].LastAttemptVersion));\r
+    DEBUG((DEBUG_VERBOSE, "    LastAttemptStatus           - 0x%x\n", ImageDescriptor[Index].LastAttemptStatus));\r
+    DEBUG((DEBUG_VERBOSE, "    HardwareInstance            - 0x%lx\n", ImageDescriptor[Index].HardwareInstance));\r
+  }\r
+}\r
+\r
+/**\r
+  Initialize MicrocodeFmpDriver private data structure.\r
+\r
+  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
+\r
+  @return EFI_SUCCESS private data is initialized.\r
+**/\r
+EFI_STATUS\r
+InitializePrivateData (\r
+  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
+  )\r
+{\r
+  EFI_STATUS       Status;\r
+  EFI_STATUS       VarStatus;\r
+  UINTN            VarSize;\r
+  BOOLEAN          Result;\r
+\r
+  MicrocodeFmpPrivate->Signature       = MICROCODE_FMP_PRIVATE_DATA_SIGNATURE;\r
+  MicrocodeFmpPrivate->Handle          = NULL;\r
+  CopyMem(&MicrocodeFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL));\r
+\r
+  MicrocodeFmpPrivate->PackageVersion = 0x1;\r
+  MicrocodeFmpPrivate->PackageVersionName = L"Microcode";\r
+\r
+  MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;\r
+  MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;\r
+  VarSize = sizeof(MicrocodeFmpPrivate->LastAttempt);\r
+  VarStatus = gRT->GetVariable(\r
+                     MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
+                     &gEfiCallerIdGuid,\r
+                     NULL,\r
+                     &VarSize,\r
+                     &MicrocodeFmpPrivate->LastAttempt\r
+                     );\r
+  DEBUG((DEBUG_INFO, "GetLastAttemp - %r\n", VarStatus));\r
+  DEBUG((DEBUG_INFO, "GetLastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
+\r
+  Result = GetMicrocodeRegion(&MicrocodeFmpPrivate->MicrocodePatchAddress, &MicrocodeFmpPrivate->MicrocodePatchRegionSize);\r
+  if (!Result) {\r
+    DEBUG((DEBUG_ERROR, "Fail to get Microcode Region\n"));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  Status = InitializeProcessorInfo (MicrocodeFmpPrivate);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((DEBUG_ERROR, "InitializeProcessorInfo - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  Status = InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((DEBUG_ERROR, "InitializeMicrocodeDescriptor - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  DumpPrivateInfo (MicrocodeFmpPrivate);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Microcode FMP module entrypoint\r
+\r
+  @param[in]  ImageHandle       The firmware allocated handle for the EFI image.\r
+  @param[in]  SystemTable       A pointer to the EFI System Table.\r
+\r
+  @return EFI_SUCCESS Microcode FMP module is initialized.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MicrocodeFmpMain (\r
+  IN EFI_HANDLE                         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+\r
+  //\r
+  // Initialize MicrocodeFmpPrivateData\r
+  //\r
+  mMicrocodeFmpPrivate = AllocateZeroPool (sizeof(MICROCODE_FMP_PRIVATE_DATA));\r
+  if (mMicrocodeFmpPrivate == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = InitializePrivateData(mMicrocodeFmpPrivate);\r
+  if (EFI_ERROR(Status)) {\r
+    FreePool(mMicrocodeFmpPrivate);\r
+    mMicrocodeFmpPrivate = NULL;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Install FMP protocol.\r
+  //\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &mMicrocodeFmpPrivate->Handle,\r
+                  &gEfiFirmwareManagementProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mMicrocodeFmpPrivate->Fmp\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool(mMicrocodeFmpPrivate);\r
+    mMicrocodeFmpPrivate = NULL;\r
+    return Status;\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c
new file mode 100644 (file)
index 0000000..4e8f1d5
--- /dev/null
@@ -0,0 +1,981 @@
+/** @file\r
+  SetImage instance to update Microcode.\r
+\r
+  Caution: This module requires additional review when modified.\r
+  This module will have external input - capsule image.\r
+  This external input must be validated carefully to avoid security issue like\r
+  buffer overflow, integer overflow.\r
+\r
+  MicrocodeWrite() and VerifyMicrocode() will receive untrusted input and do basic validation.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "MicrocodeUpdate.h"\r
+\r
+/**\r
+  Get Microcode Region.\r
+\r
+  @param[out] MicrocodePatchAddress      The address of Microcode\r
+  @param[out] MicrocodePatchRegionSize   The region size of Microcode\r
+\r
+  @retval TRUE   The Microcode region is returned.\r
+  @retval FALSE  No Microcode region.\r
+**/\r
+BOOLEAN\r
+GetMicrocodeRegion (\r
+  OUT VOID     **MicrocodePatchAddress,\r
+  OUT UINTN    *MicrocodePatchRegionSize\r
+  )\r
+{\r
+  *MicrocodePatchAddress = (VOID *)(UINTN)PcdGet64(PcdCpuMicrocodePatchAddress);\r
+  *MicrocodePatchRegionSize = (UINTN)PcdGet64(PcdCpuMicrocodePatchRegionSize);\r
+\r
+  if ((*MicrocodePatchAddress == NULL) || (*MicrocodePatchRegionSize == 0)) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+/**\r
+  Get Microcode update signature of currently loaded Microcode update.\r
+\r
+  @return  Microcode signature.\r
+\r
+**/\r
+UINT32\r
+GetCurrentMicrocodeSignature (\r
+  VOID\r
+  )\r
+{\r
+  UINT64 Signature;\r
+\r
+  AsmWriteMsr64(MSR_IA32_BIOS_SIGN_ID, 0);\r
+  AsmCpuid(CPUID_VERSION_INFO, NULL, NULL, NULL, NULL);\r
+  Signature = AsmReadMsr64(MSR_IA32_BIOS_SIGN_ID);\r
+  return (UINT32)RShiftU64(Signature, 32);\r
+}\r
+\r
+/**\r
+  Get current processor signature.\r
+\r
+  @return current processor signature.\r
+**/\r
+UINT32\r
+GetCurrentProcessorSignature (\r
+  VOID\r
+  )\r
+{\r
+  UINT32                                  RegEax;\r
+  AsmCpuid(CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL);\r
+  return RegEax;\r
+}\r
+\r
+/**\r
+  Get current platform ID.\r
+\r
+  @return current platform ID.\r
+**/\r
+UINT8\r
+GetCurrentPlatformId (\r
+  VOID\r
+  )\r
+{\r
+  UINT8                                   PlatformId;\r
+\r
+  PlatformId = (UINT8)AsmMsrBitFieldRead64(MSR_IA32_PLATFORM_ID, 50, 52);\r
+  return PlatformId;\r
+}\r
+\r
+/**\r
+  Load new Microcode.\r
+\r
+  @param[in] Address  The address of new Microcode.\r
+\r
+  @return  Loaded Microcode signature.\r
+\r
+**/\r
+UINT32\r
+LoadMicrocode (\r
+  IN UINT64  Address\r
+  )\r
+{\r
+  AsmWriteMsr64(MSR_IA32_BIOS_UPDT_TRIG, Address);\r
+  return GetCurrentMicrocodeSignature();\r
+}\r
+\r
+/**\r
+  Load Microcode on an Application Processor.\r
+  The function prototype for invoking a function on an Application Processor.\r
+\r
+  @param[in,out] Buffer  The pointer to private data buffer.\r
+**/\r
+VOID\r
+EFIAPI\r
+MicrocodeLoadAp (\r
+  IN OUT VOID  *Buffer\r
+  )\r
+{\r
+  MICROCODE_LOAD_BUFFER                *MicrocodeLoadBuffer;\r
+\r
+  MicrocodeLoadBuffer = Buffer;\r
+  MicrocodeLoadBuffer->Revision = LoadMicrocode (MicrocodeLoadBuffer->Address);\r
+}\r
+\r
+/**\r
+  Load new Microcode on this processor\r
+\r
+  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]  CpuIndex                   The index of the processor.\r
+  @param[in]  Address                    The address of new Microcode.\r
+\r
+  @return  Loaded Microcode signature.\r
+\r
+**/\r
+UINT32\r
+LoadMicrocodeOnThis (\r
+  IN  MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
+  IN  UINTN                       CpuIndex,\r
+  IN  UINT64                      Address\r
+  )\r
+{\r
+  EFI_STATUS                           Status;\r
+  EFI_MP_SERVICES_PROTOCOL             *MpService;\r
+  MICROCODE_LOAD_BUFFER                MicrocodeLoadBuffer;\r
+\r
+  if (CpuIndex == MicrocodeFmpPrivate->BspIndex) {\r
+    return LoadMicrocode (Address);\r
+  } else {\r
+    MpService = MicrocodeFmpPrivate->MpService;\r
+    MicrocodeLoadBuffer.Address = Address;\r
+    MicrocodeLoadBuffer.Revision = 0;\r
+    Status = MpService->StartupThisAP (\r
+                          MpService,\r
+                          MicrocodeLoadAp,\r
+                          CpuIndex,\r
+                          NULL,\r
+                          0,\r
+                          &MicrocodeLoadBuffer,\r
+                          NULL\r
+                          );\r
+    ASSERT_EFI_ERROR(Status);\r
+    return MicrocodeLoadBuffer.Revision;\r
+  }\r
+}\r
+\r
+/**\r
+  Collect processor information.\r
+  The function prototype for invoking a function on an Application Processor.\r
+\r
+  @param[in,out] Buffer  The pointer to private data buffer.\r
+**/\r
+VOID\r
+EFIAPI\r
+CollectProcessorInfo (\r
+  IN OUT VOID  *Buffer\r
+  )\r
+{\r
+  PROCESSOR_INFO  *ProcessorInfo;\r
+\r
+  ProcessorInfo = Buffer;\r
+  ProcessorInfo->ProcessorSignature = GetCurrentProcessorSignature();\r
+  ProcessorInfo->PlatformId = GetCurrentPlatformId();\r
+  ProcessorInfo->MicrocodeRevision = GetCurrentMicrocodeSignature();\r
+}\r
+\r
+/**\r
+  Get current Microcode information.\r
+\r
+  The ProcessorInformation (BspIndex/ProcessorCount/ProcessorInfo)\r
+  in MicrocodeFmpPrivate must be initialized.\r
+\r
+  The MicrocodeInformation (DescriptorCount/ImageDescriptor/MicrocodeInfo)\r
+  in MicrocodeFmpPrivate may not be avaiable in this function.\r
+\r
+  @param[in]   MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]   DescriptorCount            The count of Microcode ImageDescriptor allocated.\r
+  @param[out]  ImageDescriptor            Microcode ImageDescriptor\r
+  @param[out]  MicrocodeInfo              Microcode information\r
+\r
+  @return Microcode count\r
+**/\r
+UINTN\r
+GetMicrocodeInfo (\r
+  IN  MICROCODE_FMP_PRIVATE_DATA     *MicrocodeFmpPrivate,\r
+  IN  UINTN                          DescriptorCount,  OPTIONAL\r
+  OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR  *ImageDescriptor, OPTIONAL\r
+  OUT MICROCODE_INFO                 *MicrocodeInfo    OPTIONAL\r
+  )\r
+{\r
+  VOID                                    *MicrocodePatchAddress;\r
+  UINTN                                   MicrocodePatchRegionSize;\r
+  CPU_MICROCODE_HEADER                    *MicrocodeEntryPoint;\r
+  UINTN                                   MicrocodeEnd;\r
+  UINTN                                   TotalSize;\r
+  UINTN                                   Count;\r
+  UINT64                                  ImageAttributes;\r
+  BOOLEAN                                 IsInUse;\r
+  EFI_STATUS                              Status;\r
+  UINT32                                  AttemptStatus;\r
+  UINTN                                   TargetCpuIndex;\r
+\r
+  MicrocodePatchAddress = MicrocodeFmpPrivate->MicrocodePatchAddress;\r
+  MicrocodePatchRegionSize = MicrocodeFmpPrivate->MicrocodePatchRegionSize;\r
+\r
+  DEBUG((DEBUG_INFO, "Microcode Region - 0x%x - 0x%x\n", MicrocodePatchAddress, MicrocodePatchRegionSize));\r
+\r
+  Count = 0;\r
+\r
+  MicrocodeEnd = (UINTN)MicrocodePatchAddress + MicrocodePatchRegionSize;\r
+  MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) MicrocodePatchAddress;\r
+  do {\r
+    if (MicrocodeEntryPoint->HeaderVersion == 0x1 && MicrocodeEntryPoint->LoaderRevision == 0x1) {\r
+      //\r
+      // It is the microcode header. It is not the padding data between microcode patches\r
+      // becasue the padding data should not include 0x00000001 and it should be the repeated\r
+      // byte format (like 0xXYXYXYXY....).\r
+      //\r
+      if (MicrocodeEntryPoint->DataSize == 0) {\r
+        TotalSize = 2048;\r
+      } else {\r
+        TotalSize = MicrocodeEntryPoint->TotalSize;\r
+      }\r
+\r
+      TargetCpuIndex = (UINTN)-1;\r
+      Status = VerifyMicrocode(MicrocodeFmpPrivate, MicrocodeEntryPoint, TotalSize, FALSE, &AttemptStatus, NULL, &TargetCpuIndex);\r
+      if (!EFI_ERROR(Status)) {\r
+        IsInUse = TRUE;\r
+        ASSERT (TargetCpuIndex < MicrocodeFmpPrivate->ProcessorCount);\r
+        MicrocodeFmpPrivate->ProcessorInfo[TargetCpuIndex].MicrocodeIndex = Count;\r
+      } else {\r
+        IsInUse = FALSE;\r
+      }\r
+\r
+      if (ImageDescriptor != NULL && DescriptorCount > Count) {\r
+        ImageDescriptor[Count].ImageIndex = (UINT8)(Count + 1);\r
+        CopyGuid (&ImageDescriptor[Count].ImageTypeId, &gMicrocodeFmpImageTypeIdGuid);\r
+        ImageDescriptor[Count].ImageId = LShiftU64(MicrocodeEntryPoint->ProcessorFlags, 32) + MicrocodeEntryPoint->ProcessorSignature.Uint32;\r
+        ImageDescriptor[Count].ImageIdName = NULL;\r
+        ImageDescriptor[Count].Version = MicrocodeEntryPoint->UpdateRevision;\r
+        ImageDescriptor[Count].VersionName = NULL;\r
+        ImageDescriptor[Count].Size = TotalSize;\r
+        ImageAttributes = IMAGE_ATTRIBUTE_IMAGE_UPDATABLE | IMAGE_ATTRIBUTE_RESET_REQUIRED;\r
+        if (IsInUse) {\r
+          ImageAttributes |= IMAGE_ATTRIBUTE_IN_USE;\r
+        }\r
+        ImageDescriptor[Count].AttributesSupported = ImageAttributes | IMAGE_ATTRIBUTE_IN_USE;\r
+        ImageDescriptor[Count].AttributesSetting = ImageAttributes;\r
+        ImageDescriptor[Count].Compatibilities = 0;\r
+        ImageDescriptor[Count].LowestSupportedImageVersion = MicrocodeEntryPoint->UpdateRevision; // do not support rollback\r
+        ImageDescriptor[Count].LastAttemptVersion = 0;\r
+        ImageDescriptor[Count].LastAttemptStatus = 0;\r
+        ImageDescriptor[Count].HardwareInstance = 0;\r
+      }\r
+      if (MicrocodeInfo != NULL && DescriptorCount > Count) {\r
+        MicrocodeInfo[Count].MicrocodeEntryPoint = MicrocodeEntryPoint;\r
+        MicrocodeInfo[Count].TotalSize = TotalSize;\r
+        MicrocodeInfo[Count].InUse = IsInUse;\r
+      }\r
+    } else {\r
+      //\r
+      // It is the padding data between the microcode patches for microcode patches alignment.\r
+      // Because the microcode patch is the multiple of 1-KByte, the padding data should not\r
+      // exist if the microcode patch alignment value is not larger than 1-KByte. So, the microcode\r
+      // alignment value should be larger than 1-KByte. We could skip SIZE_1KB padding data to\r
+      // find the next possible microcode patch header.\r
+      //\r
+      MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) MicrocodeEntryPoint) + SIZE_1KB);\r
+      continue;\r
+    }\r
+\r
+    Count++;\r
+    ASSERT(Count < 0xFF);\r
+\r
+    //\r
+    // Get the next patch.\r
+    //\r
+    MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) MicrocodeEntryPoint) + TotalSize);\r
+  } while (((UINTN) MicrocodeEntryPoint < MicrocodeEnd));\r
+\r
+  return Count;\r
+}\r
+\r
+/**\r
+  Return matched processor information.\r
+\r
+  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]  ProcessorSignature         The processor signature to be matched\r
+  @param[in]  ProcessorFlags             The processor flags to be matched\r
+  @param[in, out] TargetCpuIndex         On input, the index of target CPU which tries to match the Microcode. (UINTN)-1 means to try all.\r
+                                         On output, the index of target CPU which matches the Microcode.\r
+\r
+  @return matched processor information.\r
+**/\r
+PROCESSOR_INFO *\r
+GetMatchedProcessor (\r
+  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
+  IN UINT32                      ProcessorSignature,\r
+  IN UINT32                      ProcessorFlags,\r
+  IN OUT UINTN                   *TargetCpuIndex\r
+  )\r
+{\r
+  UINTN  Index;\r
+\r
+  if (*TargetCpuIndex != (UINTN)-1) {\r
+    Index = *TargetCpuIndex;\r
+    if ((ProcessorSignature == MicrocodeFmpPrivate->ProcessorInfo[Index].ProcessorSignature) &&\r
+        ((ProcessorFlags & (1 << MicrocodeFmpPrivate->ProcessorInfo[Index].PlatformId)) != 0)) {\r
+      return &MicrocodeFmpPrivate->ProcessorInfo[Index];\r
+    } else {\r
+      return NULL;\r
+    }\r
+  }\r
+\r
+  for (Index = 0; Index < MicrocodeFmpPrivate->ProcessorCount; Index++) {\r
+    if ((ProcessorSignature == MicrocodeFmpPrivate->ProcessorInfo[Index].ProcessorSignature) &&\r
+        ((ProcessorFlags & (1 << MicrocodeFmpPrivate->ProcessorInfo[Index].PlatformId)) != 0)) {\r
+      *TargetCpuIndex = Index;\r
+      return &MicrocodeFmpPrivate->ProcessorInfo[Index];\r
+    }\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Verify Microcode.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]  Image                      The Microcode image buffer.\r
+  @param[in]  ImageSize                  The size of Microcode image buffer in bytes.\r
+  @param[in]  TryLoad                    Try to load Microcode or not.\r
+  @param[out] LastAttemptStatus          The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out] AbortReason                A pointer to a pointer to a null-terminated string providing more\r
+                                         details for the aborted operation. The buffer is allocated by this function\r
+                                         with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                         call to FreePool().\r
+  @param[in, out] TargetCpuIndex         On input, the index of target CPU which tries to match the Microcode. (UINTN)-1 means to try all.\r
+                                         On output, the index of target CPU which matches the Microcode.\r
+\r
+  @retval EFI_SUCCESS               The Microcode image passes verification.\r
+  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
+  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
+  @retval EFI_UNSUPPORTED           The Microcode ProcessorSignature or ProcessorFlags is incorrect.\r
+  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
+**/\r
+EFI_STATUS\r
+VerifyMicrocode (\r
+  IN  MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
+  IN  VOID                        *Image,\r
+  IN  UINTN                       ImageSize,\r
+  IN  BOOLEAN                     TryLoad,\r
+  OUT UINT32                      *LastAttemptStatus,\r
+  OUT CHAR16                      **AbortReason,   OPTIONAL\r
+  IN OUT UINTN                    *TargetCpuIndex\r
+  )\r
+{\r
+  UINTN                                   Index;\r
+  CPU_MICROCODE_HEADER                    *MicrocodeEntryPoint;\r
+  UINTN                                   TotalSize;\r
+  UINTN                                   DataSize;\r
+  UINT32                                  CurrentRevision;\r
+  PROCESSOR_INFO                          *ProcessorInfo;\r
+  UINT32                                  CheckSum32;\r
+  UINTN                                   ExtendedTableLength;\r
+  UINT32                                  ExtendedTableCount;\r
+  CPU_MICROCODE_EXTENDED_TABLE            *ExtendedTable;\r
+  CPU_MICROCODE_EXTENDED_TABLE_HEADER     *ExtendedTableHeader;\r
+  BOOLEAN                                 CorrectMicrocode;\r
+\r
+  //\r
+  // Check HeaderVersion\r
+  //\r
+  MicrocodeEntryPoint = Image;\r
+  if (MicrocodeEntryPoint->HeaderVersion != 0x1) {\r
+    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on HeaderVersion\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"InvalidHeaderVersion"), L"InvalidHeaderVersion");\r
+    }\r
+    return EFI_INCOMPATIBLE_VERSION;\r
+  }\r
+  //\r
+  // Check LoaderRevision\r
+  //\r
+  if (MicrocodeEntryPoint->LoaderRevision != 0x1) {\r
+    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on LoaderRevision\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"InvalidLoaderVersion"), L"InvalidLoaderVersion");\r
+    }\r
+    return EFI_INCOMPATIBLE_VERSION;\r
+  }\r
+  //\r
+  // Check Size\r
+  //\r
+  if (MicrocodeEntryPoint->DataSize == 0) {\r
+    TotalSize = 2048;\r
+  } else {\r
+    TotalSize = MicrocodeEntryPoint->TotalSize;\r
+  }\r
+  if (TotalSize <= sizeof(CPU_MICROCODE_HEADER)) {\r
+    DEBUG((DEBUG_ERROR, "VerifyMicrocode - TotalSize too small\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"InvalidTotalSize"), L"InvalidTotalSize");\r
+    }\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+  if (TotalSize != ImageSize) {\r
+    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on TotalSize\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"InvalidTotalSize"), L"InvalidTotalSize");\r
+    }\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+  //\r
+  // Check CheckSum32\r
+  //\r
+  if (MicrocodeEntryPoint->DataSize == 0) {\r
+    DataSize = 2048 - sizeof(CPU_MICROCODE_HEADER);\r
+  } else {\r
+    DataSize = MicrocodeEntryPoint->DataSize;\r
+  }\r
+  if (DataSize > TotalSize - sizeof(CPU_MICROCODE_HEADER)) {\r
+    DEBUG((DEBUG_ERROR, "VerifyMicrocode - DataSize too big\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"InvalidDataSize"), L"InvalidDataSize");\r
+    }\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+  if ((DataSize & 0x3) != 0) {\r
+    DEBUG((DEBUG_ERROR, "VerifyMicrocode - DataSize not aligned\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"InvalidDataSize"), L"InvalidDataSize");\r
+    }\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+  CheckSum32 = CalculateSum32((UINT32 *)MicrocodeEntryPoint, DataSize + sizeof(CPU_MICROCODE_HEADER));\r
+  if (CheckSum32 != 0) {\r
+    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on CheckSum32\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"InvalidChecksum"), L"InvalidChecksum");\r
+    }\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+\r
+  //\r
+  // Check ProcessorSignature/ProcessorFlags\r
+  //\r
+\r
+  ProcessorInfo = GetMatchedProcessor (MicrocodeFmpPrivate, MicrocodeEntryPoint->ProcessorSignature.Uint32, MicrocodeEntryPoint->ProcessorFlags, TargetCpuIndex);\r
+  if (ProcessorInfo == NULL) {\r
+    CorrectMicrocode = FALSE;\r
+    ExtendedTableLength = TotalSize - (DataSize + sizeof(CPU_MICROCODE_HEADER));\r
+    if (ExtendedTableLength != 0) {\r
+      //\r
+      // Extended Table exist, check if the CPU in support list\r
+      //\r
+      ExtendedTableHeader = (CPU_MICROCODE_EXTENDED_TABLE_HEADER *)((UINT8 *)(MicrocodeEntryPoint) + DataSize + sizeof(CPU_MICROCODE_HEADER));\r
+      //\r
+      // Calculate Extended Checksum\r
+      //\r
+      if ((ExtendedTableLength > sizeof(CPU_MICROCODE_EXTENDED_TABLE_HEADER)) && ((ExtendedTableLength & 0x3) != 0)) {\r
+        CheckSum32 = CalculateSum32((UINT32 *)ExtendedTableHeader, ExtendedTableLength);\r
+        if (CheckSum32 == 0) {\r
+          //\r
+          // Checksum correct\r
+          //\r
+          ExtendedTableCount = ExtendedTableHeader->ExtendedSignatureCount;\r
+          if (ExtendedTableCount <= (ExtendedTableLength - sizeof(CPU_MICROCODE_EXTENDED_TABLE_HEADER)) / sizeof(CPU_MICROCODE_EXTENDED_TABLE)) {\r
+            ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE *)(ExtendedTableHeader + 1);\r
+            for (Index = 0; Index < ExtendedTableCount; Index++) {\r
+              CheckSum32 = CalculateSum32((UINT32 *)ExtendedTable, sizeof(CPU_MICROCODE_EXTENDED_TABLE));\r
+              if (CheckSum32 == 0) {\r
+                //\r
+                // Verify Header\r
+                //\r
+                ProcessorInfo = GetMatchedProcessor (MicrocodeFmpPrivate, ExtendedTable->ProcessorSignature.Uint32, ExtendedTable->ProcessorFlag, TargetCpuIndex);\r
+                if (ProcessorInfo != NULL) {\r
+                  //\r
+                  // Find one\r
+                  //\r
+                  CorrectMicrocode = TRUE;\r
+                  break;\r
+                }\r
+              }\r
+              ExtendedTable++;\r
+            }\r
+          }\r
+        }\r
+      }\r
+    }\r
+    if (!CorrectMicrocode) {\r
+      if (TryLoad) {\r
+        DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on CurrentProcessorSignature/ProcessorFlags\n"));\r
+      }\r
+      *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;\r
+      if (AbortReason != NULL) {\r
+        *AbortReason = AllocateCopyPool(sizeof(L"UnsupportedProcessSignature/ProcessorFlags"), L"UnsupportedProcessSignature/ProcessorFlags");\r
+      }\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Check UpdateRevision\r
+  //\r
+  CurrentRevision = ProcessorInfo->MicrocodeRevision;\r
+  if ((MicrocodeEntryPoint->UpdateRevision < CurrentRevision) ||\r
+      (TryLoad && (MicrocodeEntryPoint->UpdateRevision == CurrentRevision))) {\r
+    if (TryLoad) {\r
+      DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on UpdateRevision\n"));\r
+    }\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;\r
+    if (AbortReason != NULL) {\r
+      *AbortReason = AllocateCopyPool(sizeof(L"IncorrectRevision"), L"IncorrectRevision");\r
+    }\r
+    return EFI_INCOMPATIBLE_VERSION;\r
+  }\r
+\r
+  //\r
+  // try load MCU\r
+  //\r
+  if (TryLoad) {\r
+    CurrentRevision = LoadMicrocodeOnThis(MicrocodeFmpPrivate, ProcessorInfo->CpuIndex, (UINTN)MicrocodeEntryPoint + sizeof(CPU_MICROCODE_HEADER));\r
+    if (MicrocodeEntryPoint->UpdateRevision != CurrentRevision) {\r
+      DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on LoadMicrocode\n"));\r
+      *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;\r
+      if (AbortReason != NULL) {\r
+        *AbortReason = AllocateCopyPool(sizeof(L"InvalidData"), L"InvalidData");\r
+      }\r
+      return EFI_SECURITY_VIOLATION;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Get next Microcode entrypoint.\r
+\r
+  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]  MicrocodeEntryPoint        Current Microcode entrypoint\r
+\r
+  @return next Microcode entrypoint.\r
+**/\r
+CPU_MICROCODE_HEADER *\r
+GetNextMicrocode (\r
+  IN MICROCODE_FMP_PRIVATE_DATA              *MicrocodeFmpPrivate,\r
+  IN CPU_MICROCODE_HEADER                    *MicrocodeEntryPoint\r
+  )\r
+{\r
+  UINTN                                   Index;\r
+\r
+  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
+    if (MicrocodeEntryPoint == MicrocodeFmpPrivate->MicrocodeInfo[Index].MicrocodeEntryPoint) {\r
+      if (Index == (UINTN)MicrocodeFmpPrivate->DescriptorCount - 1) {\r
+        // it is last one\r
+        return NULL;\r
+      } else {\r
+        // return next one\r
+        return MicrocodeFmpPrivate->MicrocodeInfo[Index + 1].MicrocodeEntryPoint;\r
+      }\r
+    }\r
+  }\r
+\r
+  ASSERT(FALSE);\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Get current Microcode used region size.\r
+\r
+  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
+\r
+  @return current Microcode used region size.\r
+**/\r
+UINTN\r
+GetCurrentMicrocodeUsedRegionSize (\r
+  IN MICROCODE_FMP_PRIVATE_DATA              *MicrocodeFmpPrivate\r
+  )\r
+{\r
+  if (MicrocodeFmpPrivate->DescriptorCount == 0) {\r
+    return 0;\r
+  }\r
+\r
+  return (UINTN)MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeFmpPrivate->DescriptorCount - 1].MicrocodeEntryPoint\r
+         + (UINTN)MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeFmpPrivate->DescriptorCount - 1].TotalSize\r
+         - (UINTN)MicrocodeFmpPrivate->MicrocodePatchAddress;\r
+}\r
+\r
+/**\r
+  Update Microcode.\r
+\r
+  @param[in]   Address            The flash address of Microcode.\r
+  @param[in]   Image              The Microcode image buffer.\r
+  @param[in]   ImageSize          The size of Microcode image buffer in bytes.\r
+  @param[out]  LastAttemptStatus  The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+\r
+  @retval EFI_SUCCESS           The Microcode image is updated.\r
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.\r
+**/\r
+EFI_STATUS\r
+UpdateMicrocode (\r
+  IN UINT64   Address,\r
+  IN VOID     *Image,\r
+  IN UINTN    ImageSize,\r
+  OUT UINT32  *LastAttemptStatus\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  DEBUG((DEBUG_INFO, "PlatformUpdate:"));\r
+  DEBUG((DEBUG_INFO, "  Address - 0x%lx,", Address));\r
+  DEBUG((DEBUG_INFO, "  Legnth - 0x%x\n", ImageSize));\r
+\r
+  Status = MicrocodeFlashWrite (\r
+             Address,\r
+             Image,\r
+             ImageSize\r
+             );\r
+  if (!EFI_ERROR(Status)) {\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
+  } else {\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Update Microcode flash region.\r
+\r
+  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]  TargetMicrocodeEntryPoint  Target Microcode entrypoint to be updated\r
+  @param[in]  Image                      The Microcode image buffer.\r
+  @param[in]  ImageSize                  The size of Microcode image buffer in bytes.\r
+  @param[out] LastAttemptStatus          The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+\r
+  @retval EFI_SUCCESS             The Microcode image is written.\r
+  @retval EFI_WRITE_PROTECTED     The flash device is read only.\r
+**/\r
+EFI_STATUS\r
+UpdateMicrocodeFlashRegion (\r
+  IN  MICROCODE_FMP_PRIVATE_DATA              *MicrocodeFmpPrivate,\r
+  IN  CPU_MICROCODE_HEADER                    *TargetMicrocodeEntryPoint,\r
+  IN  VOID                                    *Image,\r
+  IN  UINTN                                   ImageSize,\r
+  OUT UINT32                                  *LastAttemptStatus\r
+  )\r
+{\r
+  VOID                                    *MicrocodePatchAddress;\r
+  UINTN                                   MicrocodePatchRegionSize;\r
+  UINTN                                   TargetTotalSize;\r
+  UINTN                                   UsedRegionSize;\r
+  EFI_STATUS                              Status;\r
+  VOID                                    *MicrocodePatchScratchBuffer;\r
+  UINT8                                   *ScratchBufferPtr;\r
+  UINTN                                   ScratchBufferSize;\r
+  UINTN                                   RestSize;\r
+  UINTN                                   AvailableSize;\r
+  VOID                                    *NextMicrocodeEntryPoint;\r
+  MICROCODE_INFO                          *MicrocodeInfo;\r
+  UINTN                                   MicrocodeCount;\r
+  UINTN                                   Index;\r
+\r
+  DEBUG((DEBUG_INFO, "UpdateMicrocodeFlashRegion: Image - 0x%x, size - 0x%x\n", Image, ImageSize));\r
+\r
+  MicrocodePatchAddress = MicrocodeFmpPrivate->MicrocodePatchAddress;\r
+  MicrocodePatchRegionSize = MicrocodeFmpPrivate->MicrocodePatchRegionSize;\r
+\r
+  MicrocodePatchScratchBuffer = AllocateZeroPool (MicrocodePatchRegionSize);\r
+  if (MicrocodePatchScratchBuffer == NULL) {\r
+    DEBUG((DEBUG_ERROR, "Fail to allocate Microcode Scratch buffer\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  ScratchBufferPtr = MicrocodePatchScratchBuffer;\r
+  ScratchBufferSize = 0;\r
+\r
+  //\r
+  // Target data collection\r
+  //\r
+  TargetTotalSize = 0;\r
+  AvailableSize = 0;\r
+  NextMicrocodeEntryPoint = NULL;\r
+  if (TargetMicrocodeEntryPoint != NULL) {\r
+    if (TargetMicrocodeEntryPoint->DataSize == 0) {\r
+      TargetTotalSize = 2048;\r
+    } else {\r
+      TargetTotalSize = TargetMicrocodeEntryPoint->TotalSize;\r
+    }\r
+    DEBUG((DEBUG_INFO, "  TargetTotalSize - 0x%x\n", TargetTotalSize));\r
+    NextMicrocodeEntryPoint = GetNextMicrocode(MicrocodeFmpPrivate, TargetMicrocodeEntryPoint);\r
+    DEBUG((DEBUG_INFO, "  NextMicrocodeEntryPoint - 0x%x\n", NextMicrocodeEntryPoint));\r
+    if (NextMicrocodeEntryPoint != NULL) {\r
+      ASSERT ((UINTN)NextMicrocodeEntryPoint >= ((UINTN)TargetMicrocodeEntryPoint + TargetTotalSize));\r
+      AvailableSize = (UINTN)NextMicrocodeEntryPoint - (UINTN)TargetMicrocodeEntryPoint;\r
+    } else {\r
+      AvailableSize = (UINTN)MicrocodePatchAddress + MicrocodePatchRegionSize - (UINTN)TargetMicrocodeEntryPoint;\r
+    }\r
+    DEBUG((DEBUG_INFO, "  AvailableSize - 0x%x\n", AvailableSize));\r
+  }\r
+  ASSERT (AvailableSize >= TargetTotalSize);\r
+  UsedRegionSize = GetCurrentMicrocodeUsedRegionSize(MicrocodeFmpPrivate);\r
+  DEBUG((DEBUG_INFO, "  UsedRegionSize - 0x%x\n", UsedRegionSize));\r
+  ASSERT (UsedRegionSize >= TargetTotalSize);\r
+  if (TargetMicrocodeEntryPoint != NULL) {\r
+    ASSERT ((UINTN)MicrocodePatchAddress + UsedRegionSize >= ((UINTN)TargetMicrocodeEntryPoint + TargetTotalSize));\r
+  }\r
+  //\r
+  // Total Size means the Microcode data size.\r
+  // Available Size means the Microcode data size plus the pad till (1) next Microcode or (2) the end.\r
+  //\r
+  // (1)\r
+  // +------+-----------+-----+------+===================+\r
+  // | MCU1 | Microcode | PAD | MCU2 |      Empty        |\r
+  // +------+-----------+-----+------+===================+\r
+  //        | TotalSize |\r
+  //        |<-AvailableSize->|\r
+  // |<-        UsedRegionSize     ->|\r
+  //\r
+  // (2)\r
+  // +------+-----------+===================+\r
+  // | MCU  | Microcode |      Empty        |\r
+  // +------+-----------+===================+\r
+  //        | TotalSize |\r
+  //        |<-      AvailableSize        ->|\r
+  // |<-UsedRegionSize->|\r
+  //\r
+\r
+  //\r
+  // Update based on policy\r
+  //\r
+\r
+  //\r
+  // 1. If there is enough space to update old one in situ, replace old microcode in situ.\r
+  //\r
+  if (AvailableSize >= ImageSize) {\r
+    DEBUG((DEBUG_INFO, "Replace old microcode in situ\n"));\r
+    //\r
+    // +------+------------+------+===================+\r
+    // |Other1| Old Image  |Other2|      Empty        |\r
+    // +------+------------+------+===================+\r
+    //\r
+    // +------+---------+--+------+===================+\r
+    // |Other1|New Image|FF|Other2|      Empty        |\r
+    // +------+---------+--+------+===================+\r
+    //\r
+    // 1.1. Copy new image\r
+    CopyMem (ScratchBufferPtr, Image, ImageSize);\r
+    ScratchBufferSize += ImageSize;\r
+    ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
+    // 1.2. Pad 0xFF\r
+    RestSize = AvailableSize - ImageSize;\r
+    if (RestSize > 0) {\r
+      SetMem (ScratchBufferPtr, RestSize, 0xFF);\r
+      ScratchBufferSize += RestSize;\r
+      ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
+    }\r
+    Status = UpdateMicrocode((UINTN)TargetMicrocodeEntryPoint, MicrocodePatchScratchBuffer, ScratchBufferSize, LastAttemptStatus);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // 2. If there is enough space to remove old one and add new one, reorg and replace old microcode.\r
+  //\r
+  if (MicrocodePatchRegionSize - (UsedRegionSize - TargetTotalSize) >= ImageSize) {\r
+    if (TargetMicrocodeEntryPoint == NULL) {\r
+      DEBUG((DEBUG_INFO, "Append new microcode\n"));\r
+      //\r
+      // +------+------------+------+===================+\r
+      // |Other1|   Other    |Other2|      Empty        |\r
+      // +------+------------+------+===================+\r
+      //\r
+      // +------+------------+------+-----------+=======+\r
+      // |Other1|   Other    |Other2| New Image | Empty |\r
+      // +------+------------+------+-----------+=======+\r
+      //\r
+      Status = UpdateMicrocode((UINTN)MicrocodePatchAddress + UsedRegionSize, Image, ImageSize, LastAttemptStatus);\r
+    } else {\r
+      DEBUG((DEBUG_INFO, "Reorg and replace old microcode\n"));\r
+      //\r
+      // +------+------------+------+===================+\r
+      // |Other1| Old Image  |Other2|      Empty        |\r
+      // +------+------------+------+===================+\r
+      //\r
+      // +------+---------------+------+================+\r
+      // |Other1|   New Image   |Other2|      Empty     |\r
+      // +------+---------------+------+================+\r
+      //\r
+      // 2.1. Copy new image\r
+      CopyMem (ScratchBufferPtr, Image, ImageSize);\r
+      ScratchBufferSize += ImageSize;\r
+      ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
+      // 2.2. Copy rest images after the old image.\r
+      if (NextMicrocodeEntryPoint != 0) {\r
+        RestSize = (UINTN)MicrocodePatchAddress + UsedRegionSize - ((UINTN)NextMicrocodeEntryPoint);\r
+        CopyMem (ScratchBufferPtr, (UINT8 *)TargetMicrocodeEntryPoint + TargetTotalSize, RestSize);\r
+        ScratchBufferSize += RestSize;\r
+        ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
+      }\r
+      Status = UpdateMicrocode((UINTN)TargetMicrocodeEntryPoint, MicrocodePatchScratchBuffer, ScratchBufferSize, LastAttemptStatus);\r
+    }\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // 3. The new image can be put in MCU region, but not all others can be put.\r
+  //    So all the unused MCU is removed.\r
+  //\r
+  if (MicrocodePatchRegionSize >= ImageSize) {\r
+    //\r
+    // +------+------------+------+===================+\r
+    // |Other1| Old Image  |Other2|      Empty        |\r
+    // +------+------------+------+===================+\r
+    //\r
+    // +-------------------------------------+--------+\r
+    // |        New Image                    | Other  |\r
+    // +-------------------------------------+--------+\r
+    //\r
+    DEBUG((DEBUG_INFO, "Add new microcode from beginning\n"));\r
+\r
+    MicrocodeCount = MicrocodeFmpPrivate->DescriptorCount;\r
+    MicrocodeInfo = MicrocodeFmpPrivate->MicrocodeInfo;\r
+\r
+    // 3.1. Copy new image\r
+    CopyMem (ScratchBufferPtr, Image, ImageSize);\r
+    ScratchBufferSize += ImageSize;\r
+    ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
+    // 3.2. Copy some others to rest buffer\r
+    for (Index = 0; Index < MicrocodeCount; Index++) {\r
+      if (!MicrocodeInfo[Index].InUse) {\r
+        continue;\r
+      }\r
+      if (MicrocodeInfo[Index].MicrocodeEntryPoint == TargetMicrocodeEntryPoint) {\r
+        continue;\r
+      }\r
+      if (MicrocodeInfo[Index].TotalSize <= MicrocodePatchRegionSize - ScratchBufferSize) {\r
+        CopyMem (ScratchBufferPtr, MicrocodeInfo[Index].MicrocodeEntryPoint, MicrocodeInfo[Index].TotalSize);\r
+        ScratchBufferSize += MicrocodeInfo[Index].TotalSize;\r
+        ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
+      }\r
+    }\r
+    // 3.3. Pad 0xFF\r
+    RestSize = MicrocodePatchRegionSize - ScratchBufferSize;\r
+    if (RestSize > 0) {\r
+      SetMem (ScratchBufferPtr, RestSize, 0xFF);\r
+      ScratchBufferSize += RestSize;\r
+      ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
+    }\r
+    Status = UpdateMicrocode((UINTN)MicrocodePatchAddress, MicrocodePatchScratchBuffer, ScratchBufferSize, LastAttemptStatus);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // 4. The new image size is bigger than the whole MCU region.\r
+  //\r
+  DEBUG((DEBUG_ERROR, "Microcode too big\n"));\r
+  *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;\r
+  Status = EFI_OUT_OF_RESOURCES;\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Write Microcode.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]   MicrocodeFmpPrivate The Microcode driver private data\r
+  @param[in]   Image               The Microcode image buffer.\r
+  @param[in]   ImageSize           The size of Microcode image buffer in bytes.\r
+  @param[out]  LastAttemptVersion  The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]  LastAttemptStatus   The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]  AbortReason         A pointer to a pointer to a null-terminated string providing more\r
+                                   details for the aborted operation. The buffer is allocated by this function\r
+                                   with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                   call to FreePool().\r
+\r
+  @retval EFI_SUCCESS               The Microcode image is written.\r
+  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
+  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
+  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
+  @retval EFI_WRITE_PROTECTED       The flash device is read only.\r
+**/\r
+EFI_STATUS\r
+MicrocodeWrite (\r
+  IN  MICROCODE_FMP_PRIVATE_DATA   *MicrocodeFmpPrivate,\r
+  IN  VOID                         *Image,\r
+  IN  UINTN                        ImageSize,\r
+  OUT UINT32                       *LastAttemptVersion,\r
+  OUT UINT32                       *LastAttemptStatus,\r
+  OUT CHAR16                       **AbortReason\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  VOID                                    *AlignedImage;\r
+  CPU_MICROCODE_HEADER                    *TargetMicrocodeEntryPoint;\r
+  UINTN                                   TargetCpuIndex;\r
+  UINTN                                   TargetMicrcodeIndex;\r
+\r
+  //\r
+  // MCU must be 16 bytes aligned\r
+  //\r
+  AlignedImage = AllocateCopyPool(ImageSize, Image);\r
+  if (AlignedImage == NULL) {\r
+    DEBUG((DEBUG_ERROR, "Fail to allocate aligned image\n"));\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  *LastAttemptVersion = ((CPU_MICROCODE_HEADER *)Image)->UpdateRevision;\r
+  TargetCpuIndex = (UINTN)-1;\r
+  Status = VerifyMicrocode(MicrocodeFmpPrivate, AlignedImage, ImageSize, TRUE, LastAttemptStatus, AbortReason, &TargetCpuIndex);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((DEBUG_ERROR, "Fail to verify Microcode Region\n"));\r
+    FreePool(AlignedImage);\r
+    return Status;\r
+  }\r
+  DEBUG((DEBUG_INFO, "Pass VerifyMicrocode\n"));\r
+\r
+  DEBUG((DEBUG_INFO, "  TargetCpuIndex - 0x%x\n", TargetCpuIndex));\r
+  ASSERT (TargetCpuIndex < MicrocodeFmpPrivate->ProcessorCount);\r
+  TargetMicrcodeIndex = MicrocodeFmpPrivate->ProcessorInfo[TargetCpuIndex].MicrocodeIndex;\r
+  DEBUG((DEBUG_INFO, "  TargetMicrcodeIndex - 0x%x\n", TargetMicrcodeIndex));\r
+  if (TargetMicrcodeIndex != (UINTN)-1) {\r
+    ASSERT (TargetMicrcodeIndex < MicrocodeFmpPrivate->DescriptorCount);\r
+    TargetMicrocodeEntryPoint = MicrocodeFmpPrivate->MicrocodeInfo[TargetMicrcodeIndex].MicrocodeEntryPoint;\r
+  } else {\r
+    TargetMicrocodeEntryPoint = NULL;\r
+  }\r
+  DEBUG((DEBUG_INFO, "  TargetMicrocodeEntryPoint - 0x%x\n", TargetMicrocodeEntryPoint));\r
+\r
+  Status = UpdateMicrocodeFlashRegion(\r
+             MicrocodeFmpPrivate,\r
+             TargetMicrocodeEntryPoint,\r
+             AlignedImage,\r
+             ImageSize,\r
+             LastAttemptStatus\r
+             );\r
+\r
+  FreePool(AlignedImage);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h
new file mode 100644 (file)
index 0000000..9dc3063
--- /dev/null
@@ -0,0 +1,494 @@
+/** @file\r
+  Microcode update header file.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _MICROCODE_FMP_H_\r
+#define _MICROCODE_FMP_H_\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Guid/SystemResourceTable.h>\r
+#include <Guid/MicrocodeFmp.h>\r
+\r
+#include <Protocol/FirmwareManagement.h>\r
+#include <Protocol/MpService.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/MicrocodeFlashAccessLib.h>\r
+\r
+#include <Register/Cpuid.h>\r
+#include <Register/Msr.h>\r
+#include <Register/Microcode.h>\r
+\r
+#define MICROCODE_FMP_PRIVATE_DATA_SIGNATURE  SIGNATURE_32('M', 'C', 'U', 'F')\r
+\r
+//\r
+// Microcode FMP private data structure.\r
+//\r
+\r
+typedef struct {\r
+  UINT32 LastAttemptVersion;\r
+  UINT32 LastAttemptStatus;\r
+} MICROCODE_FMP_LAST_ATTEMPT_VARIABLE;\r
+\r
+typedef struct {\r
+  CPU_MICROCODE_HEADER   *MicrocodeEntryPoint;\r
+  UINTN                  TotalSize;\r
+  BOOLEAN                InUse;\r
+} MICROCODE_INFO;\r
+\r
+typedef struct {\r
+  UINTN                  CpuIndex;\r
+  UINT32                 ProcessorSignature;\r
+  UINT8                  PlatformId;\r
+  UINT32                 MicrocodeRevision;\r
+  UINTN                  MicrocodeIndex;\r
+} PROCESSOR_INFO;\r
+\r
+typedef struct {\r
+  UINT64                 Address;\r
+  UINT32                 Revision;\r
+} MICROCODE_LOAD_BUFFER;\r
+\r
+struct _MICROCODE_FMP_PRIVATE_DATA {\r
+  UINT32                               Signature;\r
+  EFI_FIRMWARE_MANAGEMENT_PROTOCOL     Fmp;\r
+  EFI_HANDLE                           Handle;\r
+  VOID                                 *MicrocodePatchAddress;\r
+  UINTN                                MicrocodePatchRegionSize;\r
+  UINT8                                DescriptorCount;\r
+  EFI_FIRMWARE_IMAGE_DESCRIPTOR        *ImageDescriptor;\r
+  MICROCODE_INFO                       *MicrocodeInfo;\r
+  UINT32                               PackageVersion;\r
+  CHAR16                               *PackageVersionName;\r
+  MICROCODE_FMP_LAST_ATTEMPT_VARIABLE  LastAttempt;\r
+  EFI_MP_SERVICES_PROTOCOL             *MpService;\r
+  UINTN                                BspIndex;\r
+  UINTN                                ProcessorCount;\r
+  PROCESSOR_INFO                       *ProcessorInfo;\r
+};\r
+\r
+typedef struct _MICROCODE_FMP_PRIVATE_DATA  MICROCODE_FMP_PRIVATE_DATA;\r
+\r
+#define MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME  L"MicrocodeLastAttempVar"\r
+\r
+/**\r
+  Returns a pointer to the MICROCODE_FMP_PRIVATE_DATA structure from the input a as Fmp.\r
+\r
+  If the signatures matches, then a pointer to the data structure that contains\r
+  a specified field of that data structure is returned.\r
+\r
+  @param  a              Pointer to the field specified by ServiceBinding within\r
+                         a data structure of type MICROCODE_FMP_PRIVATE_DATA.\r
+\r
+**/\r
+#define MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(a) \\r
+  CR ( \\r
+  (a), \\r
+  MICROCODE_FMP_PRIVATE_DATA, \\r
+  Fmp, \\r
+  MICROCODE_FMP_PRIVATE_DATA_SIGNATURE \\r
+  )\r
+\r
+/**\r
+  Get Microcode Region.\r
+\r
+  @param[out] MicrocodePatchAddress      The address of Microcode\r
+  @param[out] MicrocodePatchRegionSize   The region size of Microcode\r
+\r
+  @retval TRUE   The Microcode region is returned.\r
+  @retval FALSE  No Microcode region.\r
+**/\r
+BOOLEAN\r
+GetMicrocodeRegion (\r
+  OUT VOID     **MicrocodePatchAddress,\r
+  OUT UINTN    *MicrocodePatchRegionSize\r
+  );\r
+\r
+/**\r
+  Collect processor information.\r
+  The function prototype for invoking a function on an Application Processor.\r
+\r
+  @param[in,out] Buffer  The pointer to private data buffer.\r
+**/\r
+VOID\r
+EFIAPI\r
+CollectProcessorInfo (\r
+  IN OUT VOID  *Buffer\r
+  );\r
+\r
+/**\r
+  Get current Microcode information.\r
+\r
+  The ProcessorInformation (BspIndex/ProcessorCount/ProcessorInfo)\r
+  in MicrocodeFmpPrivate must be initialized.\r
+\r
+  The MicrocodeInformation (DescriptorCount/ImageDescriptor/MicrocodeInfo)\r
+  in MicrocodeFmpPrivate may not be avaiable in this function.\r
+\r
+  @param[in]   MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]   DescriptorCount            The count of Microcode ImageDescriptor allocated.\r
+  @param[out]  ImageDescriptor            Microcode ImageDescriptor\r
+  @param[out]  MicrocodeInfo              Microcode information\r
+\r
+  @return Microcode count\r
+**/\r
+UINTN\r
+GetMicrocodeInfo (\r
+  IN  MICROCODE_FMP_PRIVATE_DATA     *MicrocodeFmpPrivate,\r
+  IN  UINTN                          DescriptorCount,  OPTIONAL\r
+  OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR  *ImageDescriptor, OPTIONAL\r
+  OUT MICROCODE_INFO                 *MicrocodeInfo    OPTIONAL\r
+  );\r
+\r
+/**\r
+  Verify Microcode.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
+  @param[in]  Image                      The Microcode image buffer.\r
+  @param[in]  ImageSize                  The size of Microcode image buffer in bytes.\r
+  @param[in]  TryLoad                    Try to load Microcode or not.\r
+  @param[out] LastAttemptStatus          The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out] AbortReason                A pointer to a pointer to a null-terminated string providing more\r
+                                         details for the aborted operation. The buffer is allocated by this function\r
+                                         with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                         call to FreePool().\r
+  @param[in, out] TargetCpuIndex         On input, the index of target CPU which tries to match the Microcode. (UINTN)-1 means to try all.\r
+                                         On output, the index of target CPU which matches the Microcode.\r
+\r
+  @retval EFI_SUCCESS               The Microcode image passes verification.\r
+  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
+  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
+  @retval EFI_UNSUPPORTED           The Microcode ProcessorSignature or ProcessorFlags is incorrect.\r
+  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
+**/\r
+EFI_STATUS\r
+VerifyMicrocode (\r
+  IN  MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
+  IN  VOID                        *Image,\r
+  IN  UINTN                       ImageSize,\r
+  IN  BOOLEAN                     TryLoad,\r
+  OUT UINT32                      *LastAttemptStatus,\r
+  OUT CHAR16                      **AbortReason,   OPTIONAL\r
+  IN OUT UINTN                    *TargetCpuIndex  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Write Microcode.\r
+\r
+  @param[in]   MicrocodeFmpPrivate The Microcode driver private data\r
+  @param[in]   Image               The Microcode image buffer.\r
+  @param[in]   ImageSize           The size of Microcode image buffer in bytes.\r
+  @param[out]  LastAttemptVersion  The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]  LastAttemptStatus   The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]  AbortReason         A pointer to a pointer to a null-terminated string providing more\r
+                                   details for the aborted operation. The buffer is allocated by this function\r
+                                   with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                   call to FreePool().\r
+\r
+  @retval EFI_SUCCESS               The Microcode image is written.\r
+  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
+  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
+  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
+  @retval EFI_WRITE_PROTECTED       The flash device is read only.\r
+**/\r
+EFI_STATUS\r
+MicrocodeWrite (\r
+  IN MICROCODE_FMP_PRIVATE_DATA    *MicrocodeFmpPrivate,\r
+  IN VOID                          *Image,\r
+  IN UINTN                         ImageSize,\r
+  OUT UINT32                       *LastAttemptVersion,\r
+  OUT UINT32                       *LastAttemptStatus,\r
+  OUT CHAR16                       **AbortReason\r
+  );\r
+\r
+/**\r
+  Dump private information.\r
+\r
+  @param[in] MicrocodeFmpPrivate private data structure.\r
+**/\r
+VOID\r
+DumpPrivateInfo (\r
+  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
+  );\r
+\r
+/**\r
+  Returns information about the current firmware image(s) of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]      This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in, out] ImageInfoSize      A pointer to the size, in bytes, of the ImageInfo buffer.\r
+                                     On input, this is the size of the buffer allocated by the caller.\r
+                                     On output, it is the size of the buffer returned by the firmware\r
+                                     if the buffer was large enough, or the size of the buffer needed\r
+                                     to contain the image(s) information if the buffer was too small.\r
+  @param[in, out] ImageInfo          A pointer to the buffer in which firmware places the current image(s)\r
+                                     information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
+  @param[out]     DescriptorVersion  A pointer to the location in which firmware returns the version number\r
+                                     associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     DescriptorCount    A pointer to the location in which firmware returns the number of\r
+                                     descriptors or firmware images within this device.\r
+  @param[out]     DescriptorSize     A pointer to the location in which firmware returns the size, in bytes,\r
+                                     of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     PackageVersion     A version number that represents all the firmware images in the device.\r
+                                     The format is vendor specific and new version must have a greater value\r
+                                     than the old version. If PackageVersion is not supported, the value is\r
+                                     0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
+                                     is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
+                                     that package version update is in progress.\r
+  @param[out]     PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
+                                     package version name. The buffer is allocated by this function with\r
+                                     AllocatePool(), and it is the caller's responsibility to free it with a call\r
+                                     to FreePool().\r
+\r
+  @retval EFI_SUCCESS                The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL       The ImageInfo buffer was too small. The current buffer size\r
+                                     needed to hold the image(s) information is returned in ImageInfoSize.\r
+  @retval EFI_INVALID_PARAMETER      ImageInfoSize is NULL.\r
+  @retval EFI_DEVICE_ERROR           Valid information could not be returned. Possible corrupted image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImageInfo (\r
+  IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL       *This,\r
+  IN OUT    UINTN                           *ImageInfoSize,\r
+  IN OUT    EFI_FIRMWARE_IMAGE_DESCRIPTOR   *ImageInfo,\r
+  OUT       UINT32                          *DescriptorVersion,\r
+  OUT       UINT8                           *DescriptorCount,\r
+  OUT       UINTN                           *DescriptorSize,\r
+  OUT       UINT32                          *PackageVersion,\r
+  OUT       CHAR16                          **PackageVersionName\r
+  );\r
+\r
+/**\r
+  Retrieves a copy of the current firmware image of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]     This            A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]     ImageIndex      A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in,out] Image           Points to the buffer where the current image is copied to.\r
+  @param[in,out] ImageSize       On entry, points to the size of the buffer pointed to by Image, in bytes.\r
+                                 On return, points to the length of the image, in bytes.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to hold the\r
+                                 image. The current buffer size needed to hold the image is returned\r
+                                 in ImageSize.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_NOT_FOUND          The current image is not copied to the buffer.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  OUT  VOID                         *Image,\r
+  IN  OUT  UINTN                        *ImageSize\r
+  );\r
+\r
+/**\r
+  Updates the firmware image of the device.\r
+\r
+  This function updates the hardware with the new firmware image.\r
+  This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
+  If the firmware image is updatable, the function should perform the following minimal validations\r
+  before proceeding to do the firmware image update.\r
+  - Validate the image authentication if image has attribute\r
+    IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
+    EFI_SECURITY_VIOLATION if the validation fails.\r
+  - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
+    the image is unsupported. The function can optionally provide more detailed information on\r
+    why the image is not a supported image.\r
+  - Validate the data from VendorCode if not null. Image validation must be performed before\r
+    VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
+    validation failed. The function returns EFI_ABORTED if the data is invalid.\r
+\r
+  VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
+  the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
+  a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
+  firmware image version is older than the current firmware image version or bad image checksum.\r
+  Sensitive operations such as those wiping the entire firmware image and render the device to be\r
+  non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
+  AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
+  reason to the caller.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware image update policy.\r
+                                 Null indicates the caller did not specify the policy or use the default policy.\r
+  @param[in]  Progress           A function used by the driver to report the progress of the firmware update.\r
+  @param[out] AbortReason        A pointer to a pointer to a null-terminated string providing more\r
+                                 details for the aborted operation. The buffer is allocated by this function\r
+                                 with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                 call to FreePool().\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_ABORTED            The operation is aborted.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                 *This,\r
+  IN  UINT8                                            ImageIndex,\r
+  IN  CONST VOID                                       *Image,\r
+  IN  UINTN                                            ImageSize,\r
+  IN  CONST VOID                                       *VendorCode,\r
+  IN  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS    Progress,\r
+  OUT CHAR16                                           **AbortReason\r
+  );\r
+\r
+/**\r
+  Checks if the firmware image is valid for the device.\r
+\r
+  This function allows firmware update application to validate the firmware image without\r
+  invoking the SetImage() first.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[out] ImageUpdatable     Indicates if the new image is valid for update. It also provides,\r
+                                 if available, additional information if the image is invalid.\r
+\r
+  @retval EFI_SUCCESS            The image was successfully checked.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpCheckImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  CONST VOID                        *Image,\r
+  IN  UINTN                             ImageSize,\r
+  OUT UINT32                            *ImageUpdatable\r
+  );\r
+\r
+/**\r
+  Returns information about the firmware package.\r
+\r
+  This function returns package information.\r
+\r
+  @param[in]  This                     A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[out] PackageVersion           A version number that represents all the firmware images in the device.\r
+                                       The format is vendor specific and new version must have a greater value\r
+                                       than the old version. If PackageVersion is not supported, the value is\r
+                                       0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
+                                       comparison is to be performed using PackageVersionName. A value of\r
+                                       0xFFFFFFFD indicates that package version update is in progress.\r
+  @param[out] PackageVersionName       A pointer to a pointer to a null-terminated string representing\r
+                                       the package version name. The buffer is allocated by this function with\r
+                                       AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                       call to FreePool().\r
+  @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
+                                       package version name. A value of 0 indicates the device does not support\r
+                                       update of package version name. Length is the number of Unicode characters,\r
+                                       including the terminating null character.\r
+  @param[out] AttributesSupported      Package attributes that are supported by this device. See 'Package Attribute\r
+                                       Definitions' for possible returned values of this parameter. A value of 1\r
+                                       indicates the attribute is supported and the current setting value is\r
+                                       indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
+                                       supported and the current setting value in AttributesSetting is meaningless.\r
+  @param[out] AttributesSetting        Package attributes. See 'Package Attribute Definitions' for possible returned\r
+                                       values of this parameter\r
+\r
+  @retval EFI_SUCCESS                  The package information was successfully returned.\r
+  @retval EFI_UNSUPPORTED              The operation is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
+  OUT UINT32                           *PackageVersion,\r
+  OUT CHAR16                           **PackageVersionName,\r
+  OUT UINT32                           *PackageVersionNameMaxLen,\r
+  OUT UINT64                           *AttributesSupported,\r
+  OUT UINT64                           *AttributesSetting\r
+  );\r
+\r
+/**\r
+  Updates information about the firmware package.\r
+\r
+  This function updates package information.\r
+  This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
+  VendorCode enables vendor to implement vendor-specific package information update policy.\r
+  Null if the caller did not specify this policy or use the default policy.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  Image              Points to the authentication image.\r
+                                 Null if authentication is not required.\r
+  @param[in]  ImageSize          Size of the authentication image in bytes.\r
+                                 0 if authentication is not required.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware\r
+                                 image update policy.\r
+                                 Null indicates the caller did not specify this policy or use\r
+                                 the default policy.\r
+  @param[in]  PackageVersion     The new package version.\r
+  @param[in]  PackageVersionName A pointer to the new null-terminated Unicode string representing\r
+                                 the package version name.\r
+                                 The string length is equal to or less than the value returned in\r
+                                 PackageVersionNameMaxLen.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new package\r
+                                 information.\r
+  @retval EFI_INVALID_PARAMETER  The PackageVersionName length is longer than the value\r
+                                 returned in PackageVersionNameMaxLen.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL   *This,\r
+  IN  CONST VOID                         *Image,\r
+  IN  UINTN                              ImageSize,\r
+  IN  CONST VOID                         *VendorCode,\r
+  IN  UINT32                             PackageVersion,\r
+  IN  CONST CHAR16                       *PackageVersionName\r
+  );\r
+\r
+#endif\r
+\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf
new file mode 100644 (file)
index 0000000..55797cf
--- /dev/null
@@ -0,0 +1,71 @@
+## @file\r
+# Microcode FMP update driver.\r
+#\r
+# Produce FMP instance to update Microcode.\r
+#\r
+#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = MicrocodeUpdateDxe\r
+  MODULE_UNI_FILE                = MicrocodeUpdateDxe.uni\r
+  FILE_GUID                      = 0565365C-2FE1-4F88-B3BE-624C04623A20\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = MicrocodeFmpMain\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = X64\r
+#\r
+\r
+[Sources]\r
+  MicrocodeUpdate.h\r
+  MicrocodeFmp.c\r
+  MicrocodeUpdate.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UefiCpuPkg/UefiCpuPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  PcdLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  HobLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiDriverEntryPoint\r
+  MicrocodeFlashAccessLib\r
+\r
+[Guids]\r
+  gMicrocodeFmpImageTypeIdGuid                  ## CONSUMES   ## GUID\r
+\r
+[Protocols]\r
+  gEfiFirmwareManagementProtocolGuid            ## PRODUCES\r
+  gEfiMpServiceProtocolGuid                     ## CONSUMES\r
+\r
+[Pcd]\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress            ## CONSUMES\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize         ## CONSUMES\r
+\r
+[Depex]\r
+  gEfiVariableArchProtocolGuid AND\r
+  gEfiMpServiceProtocolGuid\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  MicrocodeUpdateDxeExtra.uni\r
+\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.uni b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.uni
new file mode 100644 (file)
index 0000000..1b0d494
--- /dev/null
@@ -0,0 +1,21 @@
+// /** @file\r
+// Microcode FMP update driver.\r
+//\r
+// Produce FMP instance to update Microcode.\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "Microcode FMP update driver."\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "Produce FMP instance to update Microcode."\r
diff --git a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxeExtra.uni b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxeExtra.uni
new file mode 100644 (file)
index 0000000..b667f12
--- /dev/null
@@ -0,0 +1,20 @@
+// /** @file\r
+// MicrocodeUpdateDxe Localized Strings and Content\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+#string STR_PROPERTIES_MODULE_NAME\r
+#language en-US\r
+"MicrocodeUpdate DXE Driver"\r
+\r
+\r
diff --git a/IntelSiliconPkg/Include/Guid/MicrocodeFmp.h b/IntelSiliconPkg/Include/Guid/MicrocodeFmp.h
new file mode 100644 (file)
index 0000000..88a1953
--- /dev/null
@@ -0,0 +1,21 @@
+/** @file\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __MICROCODE_FMP_GUID_H__\r
+#define __MICROCODE_FMP_GUID_H__\r
+\r
+#define MICROCODE_FMP_IMAGE_TYPE_ID_GUID { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }\r
+\r
+extern EFI_GUID gMicrocodeFmpImageTypeIdGuid;\r
+\r
+#endif\r
diff --git a/IntelSiliconPkg/Include/Library/MicrocodeFlashAccessLib.h b/IntelSiliconPkg/Include/Library/MicrocodeFlashAccessLib.h
new file mode 100644 (file)
index 0000000..0dfc3ef
--- /dev/null
@@ -0,0 +1,39 @@
+/** @file\r
+  Microcode flash device access library.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+#ifndef __MICROCODE_FLASH_ACCESS_LIB_H__\r
+#define __MICROCODE_FLASH_ACCESS_LIB_H__\r
+\r
+/**\r
+  Perform microcode write opreation.\r
+\r
+  @param[in] FlashAddress      The address of flash device to be accessed.\r
+  @param[in] Buffer            The pointer to the data buffer.\r
+  @param[in] Length            The length of data buffer in bytes.\r
+\r
+  @retval EFI_SUCCESS           The operation returns successfully.\r
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.\r
+  @retval EFI_UNSUPPORTED       The flash device access is unsupported.\r
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MicrocodeFlashWrite (\r
+  IN EFI_PHYSICAL_ADDRESS         FlashAddress,\r
+  IN VOID                         *Buffer,\r
+  IN UINTN                        Length\r
+  );\r
+\r
+#endif\r
index b88630d13835c1564779b134e6e3c3bc37e49850..a15d3dee392cd07377e3d7d0d58cd94e6eb7e654 100644 (file)
@@ -3,7 +3,7 @@
 #\r
 # This package provides common open source Intel silicon modules.\r
 #\r
-# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials are licensed and made available under\r
 # the terms and conditions of the BSD License that accompanies this distribution.\r
 # The full text of the license may be found at\r
 [Includes]\r
   Include\r
 \r
+[LibraryClasses.IA32, LibraryClasses.X64]\r
+  ## @libraryclass  Provides services to access Microcode region on flash device.\r
+  #\r
+  MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h\r
+\r
 [Guids]\r
   ## GUID for Package token space\r
   # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}\r
@@ -33,6 +38,9 @@
   # Generic DXE Library / Driver can locate HOB(s) and add SMBIOS records into SMBIOS table\r
   gIntelSmbiosDataHobGuid         = { 0x798e722e, 0x15b2, 0x4e13, { 0x8a, 0xe9, 0x6b, 0xa3, 0x0f, 0xf7, 0xf1, 0x67 }}\r
 \r
+  ## Include/Guid/MicrocodeFmp.h\r
+  gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }\r
+\r
 [Ppis]\r
   gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97, 0x67, 0x67, 0xaf, 0x2b, 0x25, 0x68, 0x4a } }\r
 \r
diff --git a/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c
deleted file mode 100644 (file)
index 7a5ec15..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/** @file\r
-  Microcode flash device access library NULL instance.\r
-\r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include <PiDxe.h>\r
-\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MicrocodeFlashAccessLib.h>\r
-\r
-/**\r
-  Perform microcode write opreation.\r
-\r
-  @param[in] FlashAddress      The address of flash device to be accessed.\r
-  @param[in] Buffer            The pointer to the data buffer.\r
-  @param[in] Length            The length of data buffer in bytes.\r
-\r
-  @retval EFI_SUCCESS           The operation returns successfully.\r
-  @retval EFI_WRITE_PROTECTED   The flash device is read only.\r
-  @retval EFI_UNSUPPORTED       The flash device access is unsupported.\r
-  @retval EFI_INVALID_PARAMETER The input parameter is not valid.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-MicrocodeFlashWrite (\r
-  IN EFI_PHYSICAL_ADDRESS         FlashAddress,\r
-  IN VOID                         *Buffer,\r
-  IN UINTN                        Length\r
-  )\r
-{\r
-  CopyMem((VOID *)(UINTN)(FlashAddress), Buffer, Length);\r
-  return EFI_SUCCESS;\r
-}\r
diff --git a/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
deleted file mode 100644 (file)
index a4a47e0..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-## @file\r
-#  Microcode flash device access library.\r
-#\r
-#  Microcode flash device access library NULL instance.\r
-#\r
-#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-#  This program and the accompanying materials\r
-#  are licensed and made available under the terms and conditions of the BSD License\r
-#  which accompanies this distribution.  The full text of the license may be found at\r
-#  http://opensource.org/licenses/bsd-license.php\r
-#\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[Defines]\r
-  INF_VERSION                    = 0x00010005\r
-  BASE_NAME                      = MicrocodeFlashAccessLibNull\r
-  MODULE_UNI_FILE                = MicrocodeFlashAccessLibNull.uni\r
-  FILE_GUID                      = 6F871ADD-9D86-4676-8BAD-68E2E451FC5B\r
-  MODULE_TYPE                    = BASE\r
-  VERSION_STRING                 = 1.0\r
-  LIBRARY_CLASS                  = MicrocodeFlashAccessLib\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
-#\r
-\r
-[Sources]\r
-  MicrocodeFlashAccessLibNull.c\r
-\r
-[Packages]\r
-  MdePkg/MdePkg.dec\r
-  UefiCpuPkg/UefiCpuPkg.dec\r
-\r
-[LibraryClasses]\r
-  BaseMemoryLib\r
diff --git a/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
deleted file mode 100644 (file)
index cc4195c..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// /** @file\r
-//  Microcode flash device access library.\r
-//\r
-//  Microcode flash device access library NULL instance.\r
-//\r
-// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-//\r
-// This program and the accompanying materials\r
-// are licensed and made available under the terms and conditions of the BSD License\r
-// which accompanies this distribution. The full text of the license may be found at\r
-// http://opensource.org/licenses/bsd-license.php\r
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-//\r
-// **/\r
-\r
-\r
-#string STR_MODULE_ABSTRACT             #language en-US "Microcode flash device access library."\r
-\r
-#string STR_MODULE_DESCRIPTION          #language en-US "Microcode flash device access library NULL instance."\r
-\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc
deleted file mode 100644 (file)
index 1b22c55..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-## @file\r
-# MicrocodeCapsulePdb\r
-#\r
-# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-#\r
-#    This program and the accompanying materials\r
-#    are licensed and made available under the terms and conditions of the BSD License\r
-#    which accompanies this distribution. The full text of the license may be found at\r
-#    http://opensource.org/licenses/bsd-license.php\r
-#\r
-#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[Defines]\r
-#\r
-# Uncomment the following line and update with your platform pkg name\r
-#\r
-#  PLATFORM_NAME                  = <PlatformPkg>\r
-  PLATFORM_GUID                  = 6875FD33-602E-4EF9-9DF2-8BA7D8B7A7AF\r
-  PLATFORM_VERSION               = 0.1\r
-#\r
-# Uncomment the following line and update with your platform pkg name\r
-#\r
-#  FLASH_DEFINITION               = <PlatformPkg>/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf\r
-#\r
-# Uncomment the following line and update with your platform pkg name\r
-#\r
-#  OUTPUT_DIRECTORY               = Build/<PlatformPkg>\r
-  SUPPORTED_ARCHITECTURES        = IA32|X64\r
-  BUILD_TARGETS                  = DEBUG|RELEASE\r
-  SKUID_IDENTIFIER               = DEFAULT\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf
deleted file mode 100644 (file)
index f171604..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-## @file\r
-#\r
-# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-#\r
-#    This program and the accompanying materials\r
-#    are licensed and made available under the terms and conditions of the BSD License\r
-#    which accompanies this distribution. The full text of the license may be found at\r
-#    http://opensource.org/licenses/bsd-license.php\r
-#\r
-#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[FmpPayload.FmpPayloadMicrocode1]\r
-IMAGE_HEADER_INIT_VERSION = 0x02\r
-IMAGE_TYPE_ID             = 96d4fdcd-1502-424d-9d4c-9b12d2dcae5c # Microcode GUID (do not change it)\r
-IMAGE_INDEX               = 0x1\r
-HARDWARE_INSTANCE         = 0x0\r
-\r
-#\r
-# Uncomment the following line and update with path to Microcode PDB file\r
-#\r
-#FILE DATA = $(WORKSPACE)/<PlatformPkg>/Microcode/Microcode.pdb\r
-\r
-[Capsule.MicrocodeCapsule]\r
-CAPSULE_GUID                = 6dcbd5ed-e82d-4c44-bda1-7194199ad92a # FMP special Guid (do not change it)\r
-CAPSULE_FLAGS               = PersistAcrossReset,InitiateReset\r
-CAPSULE_HEADER_SIZE         = 0x20\r
-CAPSULE_HEADER_INIT_VERSION = 0x1\r
-\r
-FMP_PAYLOAD = FmpPayloadMicrocode1\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md
deleted file mode 100644 (file)
index 9f81373..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-# How to generate Microcode FMP from Microcode PDB file\r
-\r
-1) Copy directory `UefiCpuPkg/Feature/Capsule/MicrocodeUpdatePdb` to `<Your Platform Package>/MicrocodeUpdatePdb`.\r
-\r
-2) Uncomment and update `FILE DATA` statement in `<Your Platform Package>/MicrocodeUpdatePdb/MicrocodeCapsulePdb.fdf` with path to a Microcode PDB file.  The PDB file can placed in `<Your Platform Package>/MicrocodeUpdatePdb` or any other path.\r
-\r
-`FILE DATA = <your Microcode PDB file path>`\r
-\r
-Uncomment and update `PLATFORM_NAME`, `FLASH_DEFINITION`, `OUTPUT_DIRECTORY` section in `<Your Platform Package>/MicrocodeUpdatePdb/MicrocodeCapsulePdb.dsc` with <Your Platform Package>.\r
-\r
-    PLATFORM_NAME                  = <Your Platform Package>\r
-    FLASH_DEFINITION               = <Your Platform Package>/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf\r
-    OUTPUT_DIRECTORY               = Build/<Your Platform Package>\r
-\r
-3) Use EDK II build tools to generate the Microcode FMP Capsule\r
-\r
-`build -p <Your Platform Package>/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc`\r
-\r
-4) The Microcode FMP Capsule is generated at `$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/MicrocodeCapsule.Cap`\r
-\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Microcode/Microcode.inf b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Microcode/Microcode.inf
deleted file mode 100644 (file)
index 81af841..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-## @file\r
-# Microcode text file to binary\r
-#\r
-# Convert text format microcode to binary format.\r
-#\r
-#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-#  This program and the accompanying materials\r
-#  are licensed and made available under the terms and conditions of the BSD License\r
-#  which accompanies this distribution.  The full text of the license may be found at\r
-#  http://opensource.org/licenses/bsd-license.php\r
-#\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[Defines]\r
-BASE_NAME            = Microcode\r
-FILE_GUID            = ABC36AAC-2031-4422-896E-0A3B899AD0B4\r
-COMPONENT_TYPE       = Microcode\r
-FFS_EXT              = .ffs\r
-\r
-[Sources]\r
-#\r
-# Uncomment the following line and update with name of Microcode TXT file\r
-#\r
-#Microcode.txt\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc
deleted file mode 100644 (file)
index a66f89b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-## @file\r
-# MicrocodeCapsuleTxt\r
-#\r
-# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-#\r
-#    This program and the accompanying materials\r
-#    are licensed and made available under the terms and conditions of the BSD License\r
-#    which accompanies this distribution. The full text of the license may be found at\r
-#    http://opensource.org/licenses/bsd-license.php\r
-#\r
-#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[Defines]\r
-#\r
-# Uncomment the following line and update with your platform pkg name\r
-#\r
-#  PLATFORM_NAME                  = <PlatformPkg>\r
-  PLATFORM_GUID                  = 6875FD33-602E-4EF9-9DF2-8BA7D8B7A7AF\r
-  PLATFORM_VERSION               = 0.1\r
-#\r
-# Uncomment the following line and update with your platform pkg name\r
-#\r
-#  FLASH_DEFINITION               = <PlatformPkg>/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf\r
-#\r
-# Uncomment the following line and update with your platform pkg name\r
-#\r
-#  OUTPUT_DIRECTORY               = Build/<PlatformPkg>\r
-  SUPPORTED_ARCHITECTURES        = IA32|X64\r
-  BUILD_TARGETS                  = DEBUG|RELEASE\r
-  SKUID_IDENTIFIER               = DEFAULT\r
-\r
-[Components]\r
-#\r
-# Uncomment the following line and update with path to Microcode INF file\r
-#\r
-#  <PlatformPkg>/MicrocodeCapsuleTxt/Microcode/Microcode.inf\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf
deleted file mode 100644 (file)
index 113693b..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-## @file\r
-#\r
-# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-#\r
-#    This program and the accompanying materials\r
-#    are licensed and made available under the terms and conditions of the BSD License\r
-#    which accompanies this distribution. The full text of the license may be found at\r
-#    http://opensource.org/licenses/bsd-license.php\r
-#\r
-#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[FmpPayload.FmpPayloadMicrocode1]\r
-IMAGE_HEADER_INIT_VERSION = 0x02\r
-IMAGE_TYPE_ID             = 96d4fdcd-1502-424d-9d4c-9b12d2dcae5c # Microcode GUID (do not change it)\r
-IMAGE_INDEX               = 0x1\r
-HARDWARE_INSTANCE         = 0x0\r
-\r
-#\r
-# Uncomment the following line and update with path to Microcode MCB file\r
-#\r
-#FILE DATA = $(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/IA32/PlatformPkg/MicrocodeCapsuleTxt/Microcode/Microcode/OUTPUT/Microcode.mcb\r
-\r
-[Capsule.MicrocodeCapsule]\r
-CAPSULE_GUID                = 6dcbd5ed-e82d-4c44-bda1-7194199ad92a # FMP special Guid (do not change it)\r
-CAPSULE_FLAGS               = PersistAcrossReset,InitiateReset\r
-CAPSULE_HEADER_SIZE         = 0x20\r
-CAPSULE_HEADER_INIT_VERSION = 0x1\r
-\r
-FMP_PAYLOAD = FmpPayloadMicrocode1\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Readme.md b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Readme.md
deleted file mode 100644 (file)
index f7d7040..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-# How to generate Microcode FMP from Microcode TXT file\r
-\r
-1) Copy directory `UefiCpuPkg/Feature/Capsule/MicrocodeUpdateTxt` to `<Your Platform Package>/MicrocodeUpdateTxt`\r
-\r
-2) Copy microcode TXT file to`<Your Platform Package>/MicrocodeUpdateTxt/Microcode`\r
-\r
-3) Uncomment and update statement in `[Sources]` section of `<Your Platform Package>/MicrocodeUpdateTxt/Microcode/Microcode.inf` with name of Microcode TXT file copied in previous step.\r
-\r
-    [Sources]\r
-    <Your Microcode TXT file>\r
-\r
-Uncomment and update `FILE DATA` statement in `<Your Platform Package>/MicrocodeUpdateTxt/MicrocodeCapsuleTxt.fdf` with path to a Microcode MCB file.  The MCB file is placed in `$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/IA32/<Your Platform Package>/MicrocodeUpdateTxt/Microcode/Microcode/OUTPUT/`.\r
-\r
-`FILE DATA = <your Microcode MCB file path>`\r
-\r
-Uncomment and update `PLATFORM_NAME`, `FLASH_DEFINITION`, `OUTPUT_DIRECTORY` section in `<Your Platform Package>/MicrocodeUpdateTxt/MicrocodeCapsuleTxt.dsc` with <Your Platform Package>.\r
-\r
-    PLATFORM_NAME                  = <Your Platform Package>\r
-    FLASH_DEFINITION               = <Your Platform Package>/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf\r
-    OUTPUT_DIRECTORY               = Build/<Your Platform Package>\r
-\r
-Uncomment and update statement in `Components` section of `<Your Platform Package>/MicrocodeUpdateTxt/MicrocodeCapsuleTxt.dsc` with path to a Microcode INF file.\r
-\r
-    [Components]\r
-    <Your Microcode INF file>\r
-\r
-4) Use EDK II build tools to generate the Microcode FMP Capsule\r
-\r
-`build -p <Your Platform Package>/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc`\r
-\r
-5) The generated Microcode FMP Capsule is found at `$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/MicrocodeCapsule.Cap`\r
-\r
-\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c
deleted file mode 100644 (file)
index ebde93a..0000000
+++ /dev/null
@@ -1,748 +0,0 @@
-/** @file\r
-  Produce FMP instance for Microcode.\r
-\r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "MicrocodeUpdate.h"\r
-\r
-//\r
-// MicrocodeFmp driver private data\r
-//\r
-MICROCODE_FMP_PRIVATE_DATA *mMicrocodeFmpPrivate = NULL;\r
-\r
-EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol = {\r
-  FmpGetImageInfo,\r
-  FmpGetImage,\r
-  FmpSetImage,\r
-  FmpCheckImage,\r
-  FmpGetPackageInfo,\r
-  FmpSetPackageInfo\r
-};\r
-\r
-/**\r
-  Initialize Microcode Descriptor.\r
-\r
-  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
-\r
-  @return EFI_SUCCESS Microcode Descriptor is initialized.\r
-**/\r
-EFI_STATUS\r
-InitializeMicrocodeDescriptor (\r
-  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
-  );\r
-\r
-/**\r
-  Returns information about the current firmware image(s) of the device.\r
-\r
-  This function allows a copy of the current firmware image to be created and saved.\r
-  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
-\r
-  @param[in]      This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in, out] ImageInfoSize      A pointer to the size, in bytes, of the ImageInfo buffer.\r
-                                     On input, this is the size of the buffer allocated by the caller.\r
-                                     On output, it is the size of the buffer returned by the firmware\r
-                                     if the buffer was large enough, or the size of the buffer needed\r
-                                     to contain the image(s) information if the buffer was too small.\r
-  @param[in, out] ImageInfo          A pointer to the buffer in which firmware places the current image(s)\r
-                                     information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
-  @param[out]     DescriptorVersion  A pointer to the location in which firmware returns the version number\r
-                                     associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]     DescriptorCount    A pointer to the location in which firmware returns the number of\r
-                                     descriptors or firmware images within this device.\r
-  @param[out]     DescriptorSize     A pointer to the location in which firmware returns the size, in bytes,\r
-                                     of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]     PackageVersion     A version number that represents all the firmware images in the device.\r
-                                     The format is vendor specific and new version must have a greater value\r
-                                     than the old version. If PackageVersion is not supported, the value is\r
-                                     0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
-                                     is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
-                                     that package version update is in progress.\r
-  @param[out]     PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
-                                     package version name. The buffer is allocated by this function with\r
-                                     AllocatePool(), and it is the caller's responsibility to free it with a call\r
-                                     to FreePool().\r
-\r
-  @retval EFI_SUCCESS                The device was successfully updated with the new image.\r
-  @retval EFI_BUFFER_TOO_SMALL       The ImageInfo buffer was too small. The current buffer size\r
-                                     needed to hold the image(s) information is returned in ImageInfoSize.\r
-  @retval EFI_INVALID_PARAMETER      ImageInfoSize is NULL.\r
-  @retval EFI_DEVICE_ERROR           Valid information could not be returned. Possible corrupted image.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpGetImageInfo (\r
-  IN        EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
-  IN OUT    UINTN                             *ImageInfoSize,\r
-  IN OUT    EFI_FIRMWARE_IMAGE_DESCRIPTOR     *ImageInfo,\r
-  OUT       UINT32                            *DescriptorVersion,\r
-  OUT       UINT8                             *DescriptorCount,\r
-  OUT       UINTN                             *DescriptorSize,\r
-  OUT       UINT32                            *PackageVersion,\r
-  OUT       CHAR16                            **PackageVersionName\r
-  )\r
-{\r
-  MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
-  UINTN                      Index;\r
-\r
-  MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
-\r
-  if(ImageInfoSize == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (*ImageInfoSize < sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount) {\r
-    *ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  if (ImageInfo == NULL ||\r
-      DescriptorVersion == NULL ||\r
-      DescriptorCount == NULL ||\r
-      DescriptorSize == NULL ||\r
-      PackageVersion == NULL ||\r
-      PackageVersionName == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  *ImageInfoSize      = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r
-  *DescriptorSize     = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r
-  *DescriptorCount    = MicrocodeFmpPrivate->DescriptorCount;\r
-  *DescriptorVersion  = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;\r
-\r
-  //\r
-  // supports 1 ImageInfo descriptor\r
-  //\r
-  CopyMem(&ImageInfo[0], MicrocodeFmpPrivate->ImageDescriptor, sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount);\r
-  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
-    if ((ImageInfo[Index].AttributesSetting & IMAGE_ATTRIBUTE_IN_USE) != 0) {\r
-      ImageInfo[Index].LastAttemptVersion = MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion;\r
-      ImageInfo[Index].LastAttemptStatus = MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus;\r
-    }\r
-  }\r
-\r
-  //\r
-  // package version\r
-  //\r
-  *PackageVersion = MicrocodeFmpPrivate->PackageVersion;\r
-  if (MicrocodeFmpPrivate->PackageVersionName != NULL) {\r
-    *PackageVersionName = AllocateCopyPool(StrSize(MicrocodeFmpPrivate->PackageVersionName), MicrocodeFmpPrivate->PackageVersionName);\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Retrieves a copy of the current firmware image of the device.\r
-\r
-  This function allows a copy of the current firmware image to be created and saved.\r
-  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
-\r
-  @param[in]     This            A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]     ImageIndex      A unique number identifying the firmware image(s) within the device.\r
-                                 The number is between 1 and DescriptorCount.\r
-  @param[in,out] Image           Points to the buffer where the current image is copied to.\r
-  @param[in,out] ImageSize       On entry, points to the size of the buffer pointed to by Image, in bytes.\r
-                                 On return, points to the length of the image, in bytes.\r
-\r
-  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
-  @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to hold the\r
-                                 image. The current buffer size needed to hold the image is returned\r
-                                 in ImageSize.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_NOT_FOUND          The current image is not copied to the buffer.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpGetImage (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
-  IN  UINT8                             ImageIndex,\r
-  IN  OUT  VOID                         *Image,\r
-  IN  OUT  UINTN                        *ImageSize\r
-  )\r
-{\r
-  MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
-  MICROCODE_INFO             *MicrocodeInfo;\r
-\r
-  if (Image == NULL || ImageSize == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
-\r
-  if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || ImageSize == NULL || Image == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  MicrocodeInfo = &MicrocodeFmpPrivate->MicrocodeInfo[ImageIndex - 1];\r
-\r
-  if (*ImageSize < MicrocodeInfo->TotalSize) {\r
-    *ImageSize = MicrocodeInfo->TotalSize;\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *ImageSize = MicrocodeInfo->TotalSize;\r
-  CopyMem (Image, MicrocodeInfo->MicrocodeEntryPoint, MicrocodeInfo->TotalSize);\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Updates the firmware image of the device.\r
-\r
-  This function updates the hardware with the new firmware image.\r
-  This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
-  If the firmware image is updatable, the function should perform the following minimal validations\r
-  before proceeding to do the firmware image update.\r
-  - Validate the image authentication if image has attribute\r
-    IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
-    EFI_SECURITY_VIOLATION if the validation fails.\r
-  - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
-    the image is unsupported. The function can optionally provide more detailed information on\r
-    why the image is not a supported image.\r
-  - Validate the data from VendorCode if not null. Image validation must be performed before\r
-    VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
-    validation failed. The function returns EFI_ABORTED if the data is invalid.\r
-\r
-  VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
-  the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
-  a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
-  firmware image version is older than the current firmware image version or bad image checksum.\r
-  Sensitive operations such as those wiping the entire firmware image and render the device to be\r
-  non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
-  AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
-  reason to the caller.\r
-\r
-  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
-                                 The number is between 1 and DescriptorCount.\r
-  @param[in]  Image              Points to the new image.\r
-  @param[in]  ImageSize          Size of the new image in bytes.\r
-  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware image update policy.\r
-                                 Null indicates the caller did not specify the policy or use the default policy.\r
-  @param[in]  Progress           A function used by the driver to report the progress of the firmware update.\r
-  @param[out] AbortReason        A pointer to a pointer to a null-terminated string providing more\r
-                                 details for the aborted operation. The buffer is allocated by this function\r
-                                 with AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                 call to FreePool().\r
-\r
-  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
-  @retval EFI_ABORTED            The operation is aborted.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpSetImage (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                 *This,\r
-  IN  UINT8                                            ImageIndex,\r
-  IN  CONST VOID                                       *Image,\r
-  IN  UINTN                                            ImageSize,\r
-  IN  CONST VOID                                       *VendorCode,\r
-  IN  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS    Progress,\r
-  OUT CHAR16                                           **AbortReason\r
-  )\r
-{\r
-  EFI_STATUS                 Status;\r
-  EFI_STATUS                 VarStatus;\r
-  MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r
-\r
-  if (Image == NULL || AbortReason == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r
-  *AbortReason     = NULL;\r
-\r
-  if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || Image == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  Status = MicrocodeWrite(MicrocodeFmpPrivate, (VOID *)Image, ImageSize, &MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, &MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus, AbortReason);\r
-  DEBUG((DEBUG_INFO, "SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
-  VarStatus = gRT->SetVariable(\r
-                     MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
-                     &gEfiCallerIdGuid,\r
-                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                     sizeof(MicrocodeFmpPrivate->LastAttempt),\r
-                     &MicrocodeFmpPrivate->LastAttempt\r
-                     );\r
-  DEBUG((DEBUG_INFO, "SetLastAttemp - %r\n", VarStatus));\r
-\r
-  if (!EFI_ERROR(Status)) {\r
-    InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
-    DumpPrivateInfo (MicrocodeFmpPrivate);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Checks if the firmware image is valid for the device.\r
-\r
-  This function allows firmware update application to validate the firmware image without\r
-  invoking the SetImage() first.\r
-\r
-  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
-                                 The number is between 1 and DescriptorCount.\r
-  @param[in]  Image              Points to the new image.\r
-  @param[in]  ImageSize          Size of the new image in bytes.\r
-  @param[out] ImageUpdatable     Indicates if the new image is valid for update. It also provides,\r
-                                 if available, additional information if the image is invalid.\r
-\r
-  @retval EFI_SUCCESS            The image was successfully checked.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpCheckImage (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
-  IN  UINT8                             ImageIndex,\r
-  IN  CONST VOID                        *Image,\r
-  IN  UINTN                             ImageSize,\r
-  OUT UINT32                            *ImageUpdatable\r
-  )\r
-{\r
-  return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
-  Returns information about the firmware package.\r
-\r
-  This function returns package information.\r
-\r
-  @param[in]  This                     A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[out] PackageVersion           A version number that represents all the firmware images in the device.\r
-                                       The format is vendor specific and new version must have a greater value\r
-                                       than the old version. If PackageVersion is not supported, the value is\r
-                                       0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
-                                       comparison is to be performed using PackageVersionName. A value of\r
-                                       0xFFFFFFFD indicates that package version update is in progress.\r
-  @param[out] PackageVersionName       A pointer to a pointer to a null-terminated string representing\r
-                                       the package version name. The buffer is allocated by this function with\r
-                                       AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                       call to FreePool().\r
-  @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
-                                       package version name. A value of 0 indicates the device does not support\r
-                                       update of package version name. Length is the number of Unicode characters,\r
-                                       including the terminating null character.\r
-  @param[out] AttributesSupported      Package attributes that are supported by this device. See 'Package Attribute\r
-                                       Definitions' for possible returned values of this parameter. A value of 1\r
-                                       indicates the attribute is supported and the current setting value is\r
-                                       indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
-                                       supported and the current setting value in AttributesSetting is meaningless.\r
-  @param[out] AttributesSetting        Package attributes. See 'Package Attribute Definitions' for possible returned\r
-                                       values of this parameter\r
-\r
-  @retval EFI_SUCCESS                  The package information was successfully returned.\r
-  @retval EFI_UNSUPPORTED              The operation is not supported.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpGetPackageInfo (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
-  OUT UINT32                           *PackageVersion,\r
-  OUT CHAR16                           **PackageVersionName,\r
-  OUT UINT32                           *PackageVersionNameMaxLen,\r
-  OUT UINT64                           *AttributesSupported,\r
-  OUT UINT64                           *AttributesSetting\r
-  )\r
-{\r
-  return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
-  Updates information about the firmware package.\r
-\r
-  This function updates package information.\r
-  This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
-  VendorCode enables vendor to implement vendor-specific package information update policy.\r
-  Null if the caller did not specify this policy or use the default policy.\r
-\r
-  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]  Image              Points to the authentication image.\r
-                                 Null if authentication is not required.\r
-  @param[in]  ImageSize          Size of the authentication image in bytes.\r
-                                 0 if authentication is not required.\r
-  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware\r
-                                 image update policy.\r
-                                 Null indicates the caller did not specify this policy or use\r
-                                 the default policy.\r
-  @param[in]  PackageVersion     The new package version.\r
-  @param[in]  PackageVersionName A pointer to the new null-terminated Unicode string representing\r
-                                 the package version name.\r
-                                 The string length is equal to or less than the value returned in\r
-                                 PackageVersionNameMaxLen.\r
-\r
-  @retval EFI_SUCCESS            The device was successfully updated with the new package\r
-                                 information.\r
-  @retval EFI_INVALID_PARAMETER  The PackageVersionName length is longer than the value\r
-                                 returned in PackageVersionNameMaxLen.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpSetPackageInfo (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL   *This,\r
-  IN  CONST VOID                         *Image,\r
-  IN  UINTN                              ImageSize,\r
-  IN  CONST VOID                         *VendorCode,\r
-  IN  UINT32                             PackageVersion,\r
-  IN  CONST CHAR16                       *PackageVersionName\r
-  )\r
-{\r
-  return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
-  Initialize Processor Microcode Index.\r
-\r
-  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
-**/\r
-VOID\r
-InitializedProcessorMicrocodeIndex (\r
-  IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
-  )\r
-{\r
-  UINTN       CpuIndex;\r
-  UINTN       MicrocodeIndex;\r
-  UINTN       TargetCpuIndex;\r
-  UINT32      AttemptStatus;\r
-  EFI_STATUS  Status;\r
-\r
-  for (CpuIndex = 0; CpuIndex < MicrocodeFmpPrivate->ProcessorCount; CpuIndex++) {\r
-    if (MicrocodeFmpPrivate->ProcessorInfo[CpuIndex].MicrocodeIndex != (UINTN)-1) {\r
-      continue;\r
-    }\r
-    for (MicrocodeIndex = 0; MicrocodeIndex < MicrocodeFmpPrivate->DescriptorCount; MicrocodeIndex++) {\r
-      if (!MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].InUse) {\r
-        continue;\r
-      }\r
-      TargetCpuIndex = CpuIndex;\r
-      Status = VerifyMicrocode(\r
-                 MicrocodeFmpPrivate,\r
-                 MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].MicrocodeEntryPoint,\r
-                 MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeIndex].TotalSize,\r
-                 FALSE,\r
-                 &AttemptStatus,\r
-                 NULL,\r
-                 &TargetCpuIndex\r
-                 );\r
-      if (!EFI_ERROR(Status)) {\r
-        MicrocodeFmpPrivate->ProcessorInfo[CpuIndex].MicrocodeIndex = MicrocodeIndex;\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-/**\r
-  Initialize Microcode Descriptor.\r
-\r
-  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
-\r
-  @return EFI_SUCCESS Microcode Descriptor is initialized.\r
-**/\r
-EFI_STATUS\r
-InitializeMicrocodeDescriptor (\r
-  IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r
-  )\r
-{\r
-  UINT8    CurrentMicrocodeCount;\r
-\r
-  CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, 0, NULL, NULL);\r
-\r
-  if (CurrentMicrocodeCount > MicrocodeFmpPrivate->DescriptorCount) {\r
-    if (MicrocodeFmpPrivate->ImageDescriptor != NULL) {\r
-      FreePool(MicrocodeFmpPrivate->ImageDescriptor);\r
-      MicrocodeFmpPrivate->ImageDescriptor = NULL;\r
-    }\r
-    if (MicrocodeFmpPrivate->MicrocodeInfo != NULL) {\r
-      FreePool(MicrocodeFmpPrivate->MicrocodeInfo);\r
-      MicrocodeFmpPrivate->MicrocodeInfo = NULL;\r
-    }\r
-  } else {\r
-    ZeroMem(MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
-    ZeroMem(MicrocodeFmpPrivate->MicrocodeInfo, MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r
-  }\r
-\r
-  MicrocodeFmpPrivate->DescriptorCount = CurrentMicrocodeCount;\r
-\r
-  if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
-    MicrocodeFmpPrivate->ImageDescriptor = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r
-    if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-  }\r
-  if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r
-    MicrocodeFmpPrivate->MicrocodeInfo = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r
-    if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-  }\r
-\r
-  CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, MicrocodeFmpPrivate->DescriptorCount, MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->MicrocodeInfo);\r
-  ASSERT(CurrentMicrocodeCount == MicrocodeFmpPrivate->DescriptorCount);\r
-\r
-  InitializedProcessorMicrocodeIndex (MicrocodeFmpPrivate);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Initialize MicrocodeFmpDriver multiprocessor information.\r
-\r
-  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
-\r
-  @return EFI_SUCCESS private data is initialized.\r
-**/\r
-EFI_STATUS\r
-InitializeProcessorInfo (\r
-  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
-  )\r
-{\r
-  EFI_STATUS                           Status;\r
-  EFI_MP_SERVICES_PROTOCOL             *MpService;\r
-  UINTN                                NumberOfProcessors;\r
-  UINTN                                NumberOfEnabledProcessors;\r
-  UINTN                                Index;\r
-  UINTN                                BspIndex;\r
-\r
-  Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpService);\r
-  ASSERT_EFI_ERROR(Status);\r
-\r
-  MicrocodeFmpPrivate->MpService = MpService;\r
-  MicrocodeFmpPrivate->ProcessorCount = 0;\r
-  MicrocodeFmpPrivate->ProcessorInfo = NULL;\r
-\r
-  Status = MpService->GetNumberOfProcessors (MpService, &NumberOfProcessors, &NumberOfEnabledProcessors);\r
-  ASSERT_EFI_ERROR(Status);\r
-  MicrocodeFmpPrivate->ProcessorCount = NumberOfProcessors;\r
-\r
-  Status = MpService->WhoAmI (MpService, &BspIndex);\r
-  ASSERT_EFI_ERROR(Status);\r
-  MicrocodeFmpPrivate->BspIndex = BspIndex;\r
-\r
-  MicrocodeFmpPrivate->ProcessorInfo = AllocateZeroPool (sizeof(PROCESSOR_INFO) * MicrocodeFmpPrivate->ProcessorCount);\r
-  if (MicrocodeFmpPrivate->ProcessorInfo == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  for (Index = 0; Index < NumberOfProcessors; Index++) {\r
-    MicrocodeFmpPrivate->ProcessorInfo[Index].CpuIndex = Index;\r
-    MicrocodeFmpPrivate->ProcessorInfo[Index].MicrocodeIndex = (UINTN)-1;\r
-    if (Index == BspIndex) {\r
-      CollectProcessorInfo (&MicrocodeFmpPrivate->ProcessorInfo[Index]);\r
-    } else {\r
-      Status = MpService->StartupThisAP (\r
-                            MpService,\r
-                            CollectProcessorInfo,\r
-                            Index,\r
-                            NULL,\r
-                            0,\r
-                            &MicrocodeFmpPrivate->ProcessorInfo[Index],\r
-                            NULL\r
-                            );\r
-      ASSERT_EFI_ERROR(Status);\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Dump private information.\r
-\r
-  @param[in] MicrocodeFmpPrivate private data structure.\r
-**/\r
-VOID\r
-DumpPrivateInfo (\r
-  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
-  )\r
-{\r
-  UINTN                                Index;\r
-  PROCESSOR_INFO                       *ProcessorInfo;\r
-  MICROCODE_INFO                       *MicrocodeInfo;\r
-  EFI_FIRMWARE_IMAGE_DESCRIPTOR        *ImageDescriptor;\r
-\r
-  DEBUG ((DEBUG_INFO, "ProcessorInfo:\n"));\r
-  DEBUG ((DEBUG_INFO, "  ProcessorCount - 0x%x\n", MicrocodeFmpPrivate->ProcessorCount));\r
-  DEBUG ((DEBUG_INFO, "  BspIndex - 0x%x\n", MicrocodeFmpPrivate->BspIndex));\r
-\r
-  ProcessorInfo = MicrocodeFmpPrivate->ProcessorInfo;\r
-  for (Index = 0; Index < MicrocodeFmpPrivate->ProcessorCount; Index++) {\r
-    DEBUG ((\r
-      DEBUG_INFO,\r
-      "  ProcessorInfo[0x%x] - 0x%08x, 0x%02x, 0x%08x, (0x%x)\n",\r
-      ProcessorInfo[Index].CpuIndex,\r
-      ProcessorInfo[Index].ProcessorSignature,\r
-      ProcessorInfo[Index].PlatformId,\r
-      ProcessorInfo[Index].MicrocodeRevision,\r
-      ProcessorInfo[Index].MicrocodeIndex\r
-      ));\r
-  }\r
-\r
-  DEBUG ((DEBUG_INFO, "MicrocodeInfo:\n"));\r
-  MicrocodeInfo = MicrocodeFmpPrivate->MicrocodeInfo;\r
-  DEBUG ((DEBUG_INFO, "  MicrocodeRegion - 0x%x - 0x%x\n", MicrocodeFmpPrivate->MicrocodePatchAddress, MicrocodeFmpPrivate->MicrocodePatchRegionSize));\r
-  DEBUG ((DEBUG_INFO, "  MicrocodeCount - 0x%x\n", MicrocodeFmpPrivate->DescriptorCount));\r
-  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
-    DEBUG ((\r
-      DEBUG_INFO,\r
-      "  MicrocodeInfo[0x%x] - 0x%08x, 0x%08x, (0x%x)\n",\r
-      Index,\r
-      MicrocodeInfo[Index].MicrocodeEntryPoint,\r
-      MicrocodeInfo[Index].TotalSize,\r
-      MicrocodeInfo[Index].InUse\r
-      ));\r
-  }\r
-\r
-  ImageDescriptor = MicrocodeFmpPrivate->ImageDescriptor;\r
-  DEBUG ((DEBUG_VERBOSE, "ImageDescriptor:\n"));\r
-  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
-    DEBUG((DEBUG_VERBOSE, "  ImageDescriptor (%d)\n", Index));\r
-    DEBUG((DEBUG_VERBOSE, "    ImageIndex                  - 0x%x\n", ImageDescriptor[Index].ImageIndex));\r
-    DEBUG((DEBUG_VERBOSE, "    ImageTypeId                 - %g\n", &ImageDescriptor[Index].ImageTypeId));\r
-    DEBUG((DEBUG_VERBOSE, "    ImageId                     - 0x%lx\n", ImageDescriptor[Index].ImageId));\r
-    DEBUG((DEBUG_VERBOSE, "    ImageIdName                 - %s\n", ImageDescriptor[Index].ImageIdName));\r
-    DEBUG((DEBUG_VERBOSE, "    Version                     - 0x%x\n", ImageDescriptor[Index].Version));\r
-    DEBUG((DEBUG_VERBOSE, "    VersionName                 - %s\n", ImageDescriptor[Index].VersionName));\r
-    DEBUG((DEBUG_VERBOSE, "    Size                        - 0x%x\n", ImageDescriptor[Index].Size));\r
-    DEBUG((DEBUG_VERBOSE, "    AttributesSupported         - 0x%lx\n", ImageDescriptor[Index].AttributesSupported));\r
-    DEBUG((DEBUG_VERBOSE, "    AttributesSetting           - 0x%lx\n", ImageDescriptor[Index].AttributesSetting));\r
-    DEBUG((DEBUG_VERBOSE, "    Compatibilities             - 0x%lx\n", ImageDescriptor[Index].Compatibilities));\r
-    DEBUG((DEBUG_VERBOSE, "    LowestSupportedImageVersion - 0x%x\n", ImageDescriptor[Index].LowestSupportedImageVersion));\r
-    DEBUG((DEBUG_VERBOSE, "    LastAttemptVersion          - 0x%x\n", ImageDescriptor[Index].LastAttemptVersion));\r
-    DEBUG((DEBUG_VERBOSE, "    LastAttemptStatus           - 0x%x\n", ImageDescriptor[Index].LastAttemptStatus));\r
-    DEBUG((DEBUG_VERBOSE, "    HardwareInstance            - 0x%lx\n", ImageDescriptor[Index].HardwareInstance));\r
-  }\r
-}\r
-\r
-/**\r
-  Initialize MicrocodeFmpDriver private data structure.\r
-\r
-  @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r
-\r
-  @return EFI_SUCCESS private data is initialized.\r
-**/\r
-EFI_STATUS\r
-InitializePrivateData (\r
-  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
-  )\r
-{\r
-  EFI_STATUS       Status;\r
-  EFI_STATUS       VarStatus;\r
-  UINTN            VarSize;\r
-  BOOLEAN          Result;\r
-\r
-  MicrocodeFmpPrivate->Signature       = MICROCODE_FMP_PRIVATE_DATA_SIGNATURE;\r
-  MicrocodeFmpPrivate->Handle          = NULL;\r
-  CopyMem(&MicrocodeFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL));\r
-\r
-  MicrocodeFmpPrivate->PackageVersion = 0x1;\r
-  MicrocodeFmpPrivate->PackageVersionName = L"Microcode";\r
-\r
-  MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;\r
-  MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;\r
-  VarSize = sizeof(MicrocodeFmpPrivate->LastAttempt);\r
-  VarStatus = gRT->GetVariable(\r
-                     MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
-                     &gEfiCallerIdGuid,\r
-                     NULL,\r
-                     &VarSize,\r
-                     &MicrocodeFmpPrivate->LastAttempt\r
-                     );\r
-  DEBUG((DEBUG_INFO, "GetLastAttemp - %r\n", VarStatus));\r
-  DEBUG((DEBUG_INFO, "GetLastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r
-\r
-  Result = GetMicrocodeRegion(&MicrocodeFmpPrivate->MicrocodePatchAddress, &MicrocodeFmpPrivate->MicrocodePatchRegionSize);\r
-  if (!Result) {\r
-    DEBUG((DEBUG_ERROR, "Fail to get Microcode Region\n"));\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  Status = InitializeProcessorInfo (MicrocodeFmpPrivate);\r
-  if (EFI_ERROR(Status)) {\r
-    DEBUG((DEBUG_ERROR, "InitializeProcessorInfo - %r\n", Status));\r
-    return Status;\r
-  }\r
-\r
-  Status = InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r
-  if (EFI_ERROR(Status)) {\r
-    DEBUG((DEBUG_ERROR, "InitializeMicrocodeDescriptor - %r\n", Status));\r
-    return Status;\r
-  }\r
-\r
-  DumpPrivateInfo (MicrocodeFmpPrivate);\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Microcode FMP module entrypoint\r
-\r
-  @param[in]  ImageHandle       The firmware allocated handle for the EFI image.\r
-  @param[in]  SystemTable       A pointer to the EFI System Table.\r
-\r
-  @return EFI_SUCCESS Microcode FMP module is initialized.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-MicrocodeFmpMain (\r
-  IN EFI_HANDLE                         ImageHandle,\r
-  IN EFI_SYSTEM_TABLE                   *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS                            Status;\r
-\r
-  //\r
-  // Initialize MicrocodeFmpPrivateData\r
-  //\r
-  mMicrocodeFmpPrivate = AllocateZeroPool (sizeof(MICROCODE_FMP_PRIVATE_DATA));\r
-  if (mMicrocodeFmpPrivate == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Status = InitializePrivateData(mMicrocodeFmpPrivate);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(mMicrocodeFmpPrivate);\r
-    mMicrocodeFmpPrivate = NULL;\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Install FMP protocol.\r
-  //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &mMicrocodeFmpPrivate->Handle,\r
-                  &gEfiFirmwareManagementProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &mMicrocodeFmpPrivate->Fmp\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    FreePool(mMicrocodeFmpPrivate);\r
-    mMicrocodeFmpPrivate = NULL;\r
-    return Status;\r
-  }\r
-\r
-  return Status;\r
-}\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c
deleted file mode 100644 (file)
index 4e8f1d5..0000000
+++ /dev/null
@@ -1,981 +0,0 @@
-/** @file\r
-  SetImage instance to update Microcode.\r
-\r
-  Caution: This module requires additional review when modified.\r
-  This module will have external input - capsule image.\r
-  This external input must be validated carefully to avoid security issue like\r
-  buffer overflow, integer overflow.\r
-\r
-  MicrocodeWrite() and VerifyMicrocode() will receive untrusted input and do basic validation.\r
-\r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "MicrocodeUpdate.h"\r
-\r
-/**\r
-  Get Microcode Region.\r
-\r
-  @param[out] MicrocodePatchAddress      The address of Microcode\r
-  @param[out] MicrocodePatchRegionSize   The region size of Microcode\r
-\r
-  @retval TRUE   The Microcode region is returned.\r
-  @retval FALSE  No Microcode region.\r
-**/\r
-BOOLEAN\r
-GetMicrocodeRegion (\r
-  OUT VOID     **MicrocodePatchAddress,\r
-  OUT UINTN    *MicrocodePatchRegionSize\r
-  )\r
-{\r
-  *MicrocodePatchAddress = (VOID *)(UINTN)PcdGet64(PcdCpuMicrocodePatchAddress);\r
-  *MicrocodePatchRegionSize = (UINTN)PcdGet64(PcdCpuMicrocodePatchRegionSize);\r
-\r
-  if ((*MicrocodePatchAddress == NULL) || (*MicrocodePatchRegionSize == 0)) {\r
-    return FALSE;\r
-  }\r
-\r
-  return TRUE;\r
-}\r
-\r
-/**\r
-  Get Microcode update signature of currently loaded Microcode update.\r
-\r
-  @return  Microcode signature.\r
-\r
-**/\r
-UINT32\r
-GetCurrentMicrocodeSignature (\r
-  VOID\r
-  )\r
-{\r
-  UINT64 Signature;\r
-\r
-  AsmWriteMsr64(MSR_IA32_BIOS_SIGN_ID, 0);\r
-  AsmCpuid(CPUID_VERSION_INFO, NULL, NULL, NULL, NULL);\r
-  Signature = AsmReadMsr64(MSR_IA32_BIOS_SIGN_ID);\r
-  return (UINT32)RShiftU64(Signature, 32);\r
-}\r
-\r
-/**\r
-  Get current processor signature.\r
-\r
-  @return current processor signature.\r
-**/\r
-UINT32\r
-GetCurrentProcessorSignature (\r
-  VOID\r
-  )\r
-{\r
-  UINT32                                  RegEax;\r
-  AsmCpuid(CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL);\r
-  return RegEax;\r
-}\r
-\r
-/**\r
-  Get current platform ID.\r
-\r
-  @return current platform ID.\r
-**/\r
-UINT8\r
-GetCurrentPlatformId (\r
-  VOID\r
-  )\r
-{\r
-  UINT8                                   PlatformId;\r
-\r
-  PlatformId = (UINT8)AsmMsrBitFieldRead64(MSR_IA32_PLATFORM_ID, 50, 52);\r
-  return PlatformId;\r
-}\r
-\r
-/**\r
-  Load new Microcode.\r
-\r
-  @param[in] Address  The address of new Microcode.\r
-\r
-  @return  Loaded Microcode signature.\r
-\r
-**/\r
-UINT32\r
-LoadMicrocode (\r
-  IN UINT64  Address\r
-  )\r
-{\r
-  AsmWriteMsr64(MSR_IA32_BIOS_UPDT_TRIG, Address);\r
-  return GetCurrentMicrocodeSignature();\r
-}\r
-\r
-/**\r
-  Load Microcode on an Application Processor.\r
-  The function prototype for invoking a function on an Application Processor.\r
-\r
-  @param[in,out] Buffer  The pointer to private data buffer.\r
-**/\r
-VOID\r
-EFIAPI\r
-MicrocodeLoadAp (\r
-  IN OUT VOID  *Buffer\r
-  )\r
-{\r
-  MICROCODE_LOAD_BUFFER                *MicrocodeLoadBuffer;\r
-\r
-  MicrocodeLoadBuffer = Buffer;\r
-  MicrocodeLoadBuffer->Revision = LoadMicrocode (MicrocodeLoadBuffer->Address);\r
-}\r
-\r
-/**\r
-  Load new Microcode on this processor\r
-\r
-  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]  CpuIndex                   The index of the processor.\r
-  @param[in]  Address                    The address of new Microcode.\r
-\r
-  @return  Loaded Microcode signature.\r
-\r
-**/\r
-UINT32\r
-LoadMicrocodeOnThis (\r
-  IN  MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
-  IN  UINTN                       CpuIndex,\r
-  IN  UINT64                      Address\r
-  )\r
-{\r
-  EFI_STATUS                           Status;\r
-  EFI_MP_SERVICES_PROTOCOL             *MpService;\r
-  MICROCODE_LOAD_BUFFER                MicrocodeLoadBuffer;\r
-\r
-  if (CpuIndex == MicrocodeFmpPrivate->BspIndex) {\r
-    return LoadMicrocode (Address);\r
-  } else {\r
-    MpService = MicrocodeFmpPrivate->MpService;\r
-    MicrocodeLoadBuffer.Address = Address;\r
-    MicrocodeLoadBuffer.Revision = 0;\r
-    Status = MpService->StartupThisAP (\r
-                          MpService,\r
-                          MicrocodeLoadAp,\r
-                          CpuIndex,\r
-                          NULL,\r
-                          0,\r
-                          &MicrocodeLoadBuffer,\r
-                          NULL\r
-                          );\r
-    ASSERT_EFI_ERROR(Status);\r
-    return MicrocodeLoadBuffer.Revision;\r
-  }\r
-}\r
-\r
-/**\r
-  Collect processor information.\r
-  The function prototype for invoking a function on an Application Processor.\r
-\r
-  @param[in,out] Buffer  The pointer to private data buffer.\r
-**/\r
-VOID\r
-EFIAPI\r
-CollectProcessorInfo (\r
-  IN OUT VOID  *Buffer\r
-  )\r
-{\r
-  PROCESSOR_INFO  *ProcessorInfo;\r
-\r
-  ProcessorInfo = Buffer;\r
-  ProcessorInfo->ProcessorSignature = GetCurrentProcessorSignature();\r
-  ProcessorInfo->PlatformId = GetCurrentPlatformId();\r
-  ProcessorInfo->MicrocodeRevision = GetCurrentMicrocodeSignature();\r
-}\r
-\r
-/**\r
-  Get current Microcode information.\r
-\r
-  The ProcessorInformation (BspIndex/ProcessorCount/ProcessorInfo)\r
-  in MicrocodeFmpPrivate must be initialized.\r
-\r
-  The MicrocodeInformation (DescriptorCount/ImageDescriptor/MicrocodeInfo)\r
-  in MicrocodeFmpPrivate may not be avaiable in this function.\r
-\r
-  @param[in]   MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]   DescriptorCount            The count of Microcode ImageDescriptor allocated.\r
-  @param[out]  ImageDescriptor            Microcode ImageDescriptor\r
-  @param[out]  MicrocodeInfo              Microcode information\r
-\r
-  @return Microcode count\r
-**/\r
-UINTN\r
-GetMicrocodeInfo (\r
-  IN  MICROCODE_FMP_PRIVATE_DATA     *MicrocodeFmpPrivate,\r
-  IN  UINTN                          DescriptorCount,  OPTIONAL\r
-  OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR  *ImageDescriptor, OPTIONAL\r
-  OUT MICROCODE_INFO                 *MicrocodeInfo    OPTIONAL\r
-  )\r
-{\r
-  VOID                                    *MicrocodePatchAddress;\r
-  UINTN                                   MicrocodePatchRegionSize;\r
-  CPU_MICROCODE_HEADER                    *MicrocodeEntryPoint;\r
-  UINTN                                   MicrocodeEnd;\r
-  UINTN                                   TotalSize;\r
-  UINTN                                   Count;\r
-  UINT64                                  ImageAttributes;\r
-  BOOLEAN                                 IsInUse;\r
-  EFI_STATUS                              Status;\r
-  UINT32                                  AttemptStatus;\r
-  UINTN                                   TargetCpuIndex;\r
-\r
-  MicrocodePatchAddress = MicrocodeFmpPrivate->MicrocodePatchAddress;\r
-  MicrocodePatchRegionSize = MicrocodeFmpPrivate->MicrocodePatchRegionSize;\r
-\r
-  DEBUG((DEBUG_INFO, "Microcode Region - 0x%x - 0x%x\n", MicrocodePatchAddress, MicrocodePatchRegionSize));\r
-\r
-  Count = 0;\r
-\r
-  MicrocodeEnd = (UINTN)MicrocodePatchAddress + MicrocodePatchRegionSize;\r
-  MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) MicrocodePatchAddress;\r
-  do {\r
-    if (MicrocodeEntryPoint->HeaderVersion == 0x1 && MicrocodeEntryPoint->LoaderRevision == 0x1) {\r
-      //\r
-      // It is the microcode header. It is not the padding data between microcode patches\r
-      // becasue the padding data should not include 0x00000001 and it should be the repeated\r
-      // byte format (like 0xXYXYXYXY....).\r
-      //\r
-      if (MicrocodeEntryPoint->DataSize == 0) {\r
-        TotalSize = 2048;\r
-      } else {\r
-        TotalSize = MicrocodeEntryPoint->TotalSize;\r
-      }\r
-\r
-      TargetCpuIndex = (UINTN)-1;\r
-      Status = VerifyMicrocode(MicrocodeFmpPrivate, MicrocodeEntryPoint, TotalSize, FALSE, &AttemptStatus, NULL, &TargetCpuIndex);\r
-      if (!EFI_ERROR(Status)) {\r
-        IsInUse = TRUE;\r
-        ASSERT (TargetCpuIndex < MicrocodeFmpPrivate->ProcessorCount);\r
-        MicrocodeFmpPrivate->ProcessorInfo[TargetCpuIndex].MicrocodeIndex = Count;\r
-      } else {\r
-        IsInUse = FALSE;\r
-      }\r
-\r
-      if (ImageDescriptor != NULL && DescriptorCount > Count) {\r
-        ImageDescriptor[Count].ImageIndex = (UINT8)(Count + 1);\r
-        CopyGuid (&ImageDescriptor[Count].ImageTypeId, &gMicrocodeFmpImageTypeIdGuid);\r
-        ImageDescriptor[Count].ImageId = LShiftU64(MicrocodeEntryPoint->ProcessorFlags, 32) + MicrocodeEntryPoint->ProcessorSignature.Uint32;\r
-        ImageDescriptor[Count].ImageIdName = NULL;\r
-        ImageDescriptor[Count].Version = MicrocodeEntryPoint->UpdateRevision;\r
-        ImageDescriptor[Count].VersionName = NULL;\r
-        ImageDescriptor[Count].Size = TotalSize;\r
-        ImageAttributes = IMAGE_ATTRIBUTE_IMAGE_UPDATABLE | IMAGE_ATTRIBUTE_RESET_REQUIRED;\r
-        if (IsInUse) {\r
-          ImageAttributes |= IMAGE_ATTRIBUTE_IN_USE;\r
-        }\r
-        ImageDescriptor[Count].AttributesSupported = ImageAttributes | IMAGE_ATTRIBUTE_IN_USE;\r
-        ImageDescriptor[Count].AttributesSetting = ImageAttributes;\r
-        ImageDescriptor[Count].Compatibilities = 0;\r
-        ImageDescriptor[Count].LowestSupportedImageVersion = MicrocodeEntryPoint->UpdateRevision; // do not support rollback\r
-        ImageDescriptor[Count].LastAttemptVersion = 0;\r
-        ImageDescriptor[Count].LastAttemptStatus = 0;\r
-        ImageDescriptor[Count].HardwareInstance = 0;\r
-      }\r
-      if (MicrocodeInfo != NULL && DescriptorCount > Count) {\r
-        MicrocodeInfo[Count].MicrocodeEntryPoint = MicrocodeEntryPoint;\r
-        MicrocodeInfo[Count].TotalSize = TotalSize;\r
-        MicrocodeInfo[Count].InUse = IsInUse;\r
-      }\r
-    } else {\r
-      //\r
-      // It is the padding data between the microcode patches for microcode patches alignment.\r
-      // Because the microcode patch is the multiple of 1-KByte, the padding data should not\r
-      // exist if the microcode patch alignment value is not larger than 1-KByte. So, the microcode\r
-      // alignment value should be larger than 1-KByte. We could skip SIZE_1KB padding data to\r
-      // find the next possible microcode patch header.\r
-      //\r
-      MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) MicrocodeEntryPoint) + SIZE_1KB);\r
-      continue;\r
-    }\r
-\r
-    Count++;\r
-    ASSERT(Count < 0xFF);\r
-\r
-    //\r
-    // Get the next patch.\r
-    //\r
-    MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) MicrocodeEntryPoint) + TotalSize);\r
-  } while (((UINTN) MicrocodeEntryPoint < MicrocodeEnd));\r
-\r
-  return Count;\r
-}\r
-\r
-/**\r
-  Return matched processor information.\r
-\r
-  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]  ProcessorSignature         The processor signature to be matched\r
-  @param[in]  ProcessorFlags             The processor flags to be matched\r
-  @param[in, out] TargetCpuIndex         On input, the index of target CPU which tries to match the Microcode. (UINTN)-1 means to try all.\r
-                                         On output, the index of target CPU which matches the Microcode.\r
-\r
-  @return matched processor information.\r
-**/\r
-PROCESSOR_INFO *\r
-GetMatchedProcessor (\r
-  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
-  IN UINT32                      ProcessorSignature,\r
-  IN UINT32                      ProcessorFlags,\r
-  IN OUT UINTN                   *TargetCpuIndex\r
-  )\r
-{\r
-  UINTN  Index;\r
-\r
-  if (*TargetCpuIndex != (UINTN)-1) {\r
-    Index = *TargetCpuIndex;\r
-    if ((ProcessorSignature == MicrocodeFmpPrivate->ProcessorInfo[Index].ProcessorSignature) &&\r
-        ((ProcessorFlags & (1 << MicrocodeFmpPrivate->ProcessorInfo[Index].PlatformId)) != 0)) {\r
-      return &MicrocodeFmpPrivate->ProcessorInfo[Index];\r
-    } else {\r
-      return NULL;\r
-    }\r
-  }\r
-\r
-  for (Index = 0; Index < MicrocodeFmpPrivate->ProcessorCount; Index++) {\r
-    if ((ProcessorSignature == MicrocodeFmpPrivate->ProcessorInfo[Index].ProcessorSignature) &&\r
-        ((ProcessorFlags & (1 << MicrocodeFmpPrivate->ProcessorInfo[Index].PlatformId)) != 0)) {\r
-      *TargetCpuIndex = Index;\r
-      return &MicrocodeFmpPrivate->ProcessorInfo[Index];\r
-    }\r
-  }\r
-  return NULL;\r
-}\r
-\r
-/**\r
-  Verify Microcode.\r
-\r
-  Caution: This function may receive untrusted input.\r
-\r
-  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]  Image                      The Microcode image buffer.\r
-  @param[in]  ImageSize                  The size of Microcode image buffer in bytes.\r
-  @param[in]  TryLoad                    Try to load Microcode or not.\r
-  @param[out] LastAttemptStatus          The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out] AbortReason                A pointer to a pointer to a null-terminated string providing more\r
-                                         details for the aborted operation. The buffer is allocated by this function\r
-                                         with AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                         call to FreePool().\r
-  @param[in, out] TargetCpuIndex         On input, the index of target CPU which tries to match the Microcode. (UINTN)-1 means to try all.\r
-                                         On output, the index of target CPU which matches the Microcode.\r
-\r
-  @retval EFI_SUCCESS               The Microcode image passes verification.\r
-  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
-  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
-  @retval EFI_UNSUPPORTED           The Microcode ProcessorSignature or ProcessorFlags is incorrect.\r
-  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
-**/\r
-EFI_STATUS\r
-VerifyMicrocode (\r
-  IN  MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
-  IN  VOID                        *Image,\r
-  IN  UINTN                       ImageSize,\r
-  IN  BOOLEAN                     TryLoad,\r
-  OUT UINT32                      *LastAttemptStatus,\r
-  OUT CHAR16                      **AbortReason,   OPTIONAL\r
-  IN OUT UINTN                    *TargetCpuIndex\r
-  )\r
-{\r
-  UINTN                                   Index;\r
-  CPU_MICROCODE_HEADER                    *MicrocodeEntryPoint;\r
-  UINTN                                   TotalSize;\r
-  UINTN                                   DataSize;\r
-  UINT32                                  CurrentRevision;\r
-  PROCESSOR_INFO                          *ProcessorInfo;\r
-  UINT32                                  CheckSum32;\r
-  UINTN                                   ExtendedTableLength;\r
-  UINT32                                  ExtendedTableCount;\r
-  CPU_MICROCODE_EXTENDED_TABLE            *ExtendedTable;\r
-  CPU_MICROCODE_EXTENDED_TABLE_HEADER     *ExtendedTableHeader;\r
-  BOOLEAN                                 CorrectMicrocode;\r
-\r
-  //\r
-  // Check HeaderVersion\r
-  //\r
-  MicrocodeEntryPoint = Image;\r
-  if (MicrocodeEntryPoint->HeaderVersion != 0x1) {\r
-    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on HeaderVersion\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"InvalidHeaderVersion"), L"InvalidHeaderVersion");\r
-    }\r
-    return EFI_INCOMPATIBLE_VERSION;\r
-  }\r
-  //\r
-  // Check LoaderRevision\r
-  //\r
-  if (MicrocodeEntryPoint->LoaderRevision != 0x1) {\r
-    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on LoaderRevision\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"InvalidLoaderVersion"), L"InvalidLoaderVersion");\r
-    }\r
-    return EFI_INCOMPATIBLE_VERSION;\r
-  }\r
-  //\r
-  // Check Size\r
-  //\r
-  if (MicrocodeEntryPoint->DataSize == 0) {\r
-    TotalSize = 2048;\r
-  } else {\r
-    TotalSize = MicrocodeEntryPoint->TotalSize;\r
-  }\r
-  if (TotalSize <= sizeof(CPU_MICROCODE_HEADER)) {\r
-    DEBUG((DEBUG_ERROR, "VerifyMicrocode - TotalSize too small\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"InvalidTotalSize"), L"InvalidTotalSize");\r
-    }\r
-    return EFI_VOLUME_CORRUPTED;\r
-  }\r
-  if (TotalSize != ImageSize) {\r
-    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on TotalSize\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"InvalidTotalSize"), L"InvalidTotalSize");\r
-    }\r
-    return EFI_VOLUME_CORRUPTED;\r
-  }\r
-  //\r
-  // Check CheckSum32\r
-  //\r
-  if (MicrocodeEntryPoint->DataSize == 0) {\r
-    DataSize = 2048 - sizeof(CPU_MICROCODE_HEADER);\r
-  } else {\r
-    DataSize = MicrocodeEntryPoint->DataSize;\r
-  }\r
-  if (DataSize > TotalSize - sizeof(CPU_MICROCODE_HEADER)) {\r
-    DEBUG((DEBUG_ERROR, "VerifyMicrocode - DataSize too big\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"InvalidDataSize"), L"InvalidDataSize");\r
-    }\r
-    return EFI_VOLUME_CORRUPTED;\r
-  }\r
-  if ((DataSize & 0x3) != 0) {\r
-    DEBUG((DEBUG_ERROR, "VerifyMicrocode - DataSize not aligned\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"InvalidDataSize"), L"InvalidDataSize");\r
-    }\r
-    return EFI_VOLUME_CORRUPTED;\r
-  }\r
-  CheckSum32 = CalculateSum32((UINT32 *)MicrocodeEntryPoint, DataSize + sizeof(CPU_MICROCODE_HEADER));\r
-  if (CheckSum32 != 0) {\r
-    DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on CheckSum32\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"InvalidChecksum"), L"InvalidChecksum");\r
-    }\r
-    return EFI_VOLUME_CORRUPTED;\r
-  }\r
-\r
-  //\r
-  // Check ProcessorSignature/ProcessorFlags\r
-  //\r
-\r
-  ProcessorInfo = GetMatchedProcessor (MicrocodeFmpPrivate, MicrocodeEntryPoint->ProcessorSignature.Uint32, MicrocodeEntryPoint->ProcessorFlags, TargetCpuIndex);\r
-  if (ProcessorInfo == NULL) {\r
-    CorrectMicrocode = FALSE;\r
-    ExtendedTableLength = TotalSize - (DataSize + sizeof(CPU_MICROCODE_HEADER));\r
-    if (ExtendedTableLength != 0) {\r
-      //\r
-      // Extended Table exist, check if the CPU in support list\r
-      //\r
-      ExtendedTableHeader = (CPU_MICROCODE_EXTENDED_TABLE_HEADER *)((UINT8 *)(MicrocodeEntryPoint) + DataSize + sizeof(CPU_MICROCODE_HEADER));\r
-      //\r
-      // Calculate Extended Checksum\r
-      //\r
-      if ((ExtendedTableLength > sizeof(CPU_MICROCODE_EXTENDED_TABLE_HEADER)) && ((ExtendedTableLength & 0x3) != 0)) {\r
-        CheckSum32 = CalculateSum32((UINT32 *)ExtendedTableHeader, ExtendedTableLength);\r
-        if (CheckSum32 == 0) {\r
-          //\r
-          // Checksum correct\r
-          //\r
-          ExtendedTableCount = ExtendedTableHeader->ExtendedSignatureCount;\r
-          if (ExtendedTableCount <= (ExtendedTableLength - sizeof(CPU_MICROCODE_EXTENDED_TABLE_HEADER)) / sizeof(CPU_MICROCODE_EXTENDED_TABLE)) {\r
-            ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE *)(ExtendedTableHeader + 1);\r
-            for (Index = 0; Index < ExtendedTableCount; Index++) {\r
-              CheckSum32 = CalculateSum32((UINT32 *)ExtendedTable, sizeof(CPU_MICROCODE_EXTENDED_TABLE));\r
-              if (CheckSum32 == 0) {\r
-                //\r
-                // Verify Header\r
-                //\r
-                ProcessorInfo = GetMatchedProcessor (MicrocodeFmpPrivate, ExtendedTable->ProcessorSignature.Uint32, ExtendedTable->ProcessorFlag, TargetCpuIndex);\r
-                if (ProcessorInfo != NULL) {\r
-                  //\r
-                  // Find one\r
-                  //\r
-                  CorrectMicrocode = TRUE;\r
-                  break;\r
-                }\r
-              }\r
-              ExtendedTable++;\r
-            }\r
-          }\r
-        }\r
-      }\r
-    }\r
-    if (!CorrectMicrocode) {\r
-      if (TryLoad) {\r
-        DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on CurrentProcessorSignature/ProcessorFlags\n"));\r
-      }\r
-      *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;\r
-      if (AbortReason != NULL) {\r
-        *AbortReason = AllocateCopyPool(sizeof(L"UnsupportedProcessSignature/ProcessorFlags"), L"UnsupportedProcessSignature/ProcessorFlags");\r
-      }\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Check UpdateRevision\r
-  //\r
-  CurrentRevision = ProcessorInfo->MicrocodeRevision;\r
-  if ((MicrocodeEntryPoint->UpdateRevision < CurrentRevision) ||\r
-      (TryLoad && (MicrocodeEntryPoint->UpdateRevision == CurrentRevision))) {\r
-    if (TryLoad) {\r
-      DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on UpdateRevision\n"));\r
-    }\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;\r
-    if (AbortReason != NULL) {\r
-      *AbortReason = AllocateCopyPool(sizeof(L"IncorrectRevision"), L"IncorrectRevision");\r
-    }\r
-    return EFI_INCOMPATIBLE_VERSION;\r
-  }\r
-\r
-  //\r
-  // try load MCU\r
-  //\r
-  if (TryLoad) {\r
-    CurrentRevision = LoadMicrocodeOnThis(MicrocodeFmpPrivate, ProcessorInfo->CpuIndex, (UINTN)MicrocodeEntryPoint + sizeof(CPU_MICROCODE_HEADER));\r
-    if (MicrocodeEntryPoint->UpdateRevision != CurrentRevision) {\r
-      DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on LoadMicrocode\n"));\r
-      *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;\r
-      if (AbortReason != NULL) {\r
-        *AbortReason = AllocateCopyPool(sizeof(L"InvalidData"), L"InvalidData");\r
-      }\r
-      return EFI_SECURITY_VIOLATION;\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Get next Microcode entrypoint.\r
-\r
-  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]  MicrocodeEntryPoint        Current Microcode entrypoint\r
-\r
-  @return next Microcode entrypoint.\r
-**/\r
-CPU_MICROCODE_HEADER *\r
-GetNextMicrocode (\r
-  IN MICROCODE_FMP_PRIVATE_DATA              *MicrocodeFmpPrivate,\r
-  IN CPU_MICROCODE_HEADER                    *MicrocodeEntryPoint\r
-  )\r
-{\r
-  UINTN                                   Index;\r
-\r
-  for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r
-    if (MicrocodeEntryPoint == MicrocodeFmpPrivate->MicrocodeInfo[Index].MicrocodeEntryPoint) {\r
-      if (Index == (UINTN)MicrocodeFmpPrivate->DescriptorCount - 1) {\r
-        // it is last one\r
-        return NULL;\r
-      } else {\r
-        // return next one\r
-        return MicrocodeFmpPrivate->MicrocodeInfo[Index + 1].MicrocodeEntryPoint;\r
-      }\r
-    }\r
-  }\r
-\r
-  ASSERT(FALSE);\r
-  return NULL;\r
-}\r
-\r
-/**\r
-  Get current Microcode used region size.\r
-\r
-  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
-\r
-  @return current Microcode used region size.\r
-**/\r
-UINTN\r
-GetCurrentMicrocodeUsedRegionSize (\r
-  IN MICROCODE_FMP_PRIVATE_DATA              *MicrocodeFmpPrivate\r
-  )\r
-{\r
-  if (MicrocodeFmpPrivate->DescriptorCount == 0) {\r
-    return 0;\r
-  }\r
-\r
-  return (UINTN)MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeFmpPrivate->DescriptorCount - 1].MicrocodeEntryPoint\r
-         + (UINTN)MicrocodeFmpPrivate->MicrocodeInfo[MicrocodeFmpPrivate->DescriptorCount - 1].TotalSize\r
-         - (UINTN)MicrocodeFmpPrivate->MicrocodePatchAddress;\r
-}\r
-\r
-/**\r
-  Update Microcode.\r
-\r
-  @param[in]   Address            The flash address of Microcode.\r
-  @param[in]   Image              The Microcode image buffer.\r
-  @param[in]   ImageSize          The size of Microcode image buffer in bytes.\r
-  @param[out]  LastAttemptStatus  The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-\r
-  @retval EFI_SUCCESS           The Microcode image is updated.\r
-  @retval EFI_WRITE_PROTECTED   The flash device is read only.\r
-**/\r
-EFI_STATUS\r
-UpdateMicrocode (\r
-  IN UINT64   Address,\r
-  IN VOID     *Image,\r
-  IN UINTN    ImageSize,\r
-  OUT UINT32  *LastAttemptStatus\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-\r
-  DEBUG((DEBUG_INFO, "PlatformUpdate:"));\r
-  DEBUG((DEBUG_INFO, "  Address - 0x%lx,", Address));\r
-  DEBUG((DEBUG_INFO, "  Legnth - 0x%x\n", ImageSize));\r
-\r
-  Status = MicrocodeFlashWrite (\r
-             Address,\r
-             Image,\r
-             ImageSize\r
-             );\r
-  if (!EFI_ERROR(Status)) {\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
-  } else {\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
-  }\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Update Microcode flash region.\r
-\r
-  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]  TargetMicrocodeEntryPoint  Target Microcode entrypoint to be updated\r
-  @param[in]  Image                      The Microcode image buffer.\r
-  @param[in]  ImageSize                  The size of Microcode image buffer in bytes.\r
-  @param[out] LastAttemptStatus          The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-\r
-  @retval EFI_SUCCESS             The Microcode image is written.\r
-  @retval EFI_WRITE_PROTECTED     The flash device is read only.\r
-**/\r
-EFI_STATUS\r
-UpdateMicrocodeFlashRegion (\r
-  IN  MICROCODE_FMP_PRIVATE_DATA              *MicrocodeFmpPrivate,\r
-  IN  CPU_MICROCODE_HEADER                    *TargetMicrocodeEntryPoint,\r
-  IN  VOID                                    *Image,\r
-  IN  UINTN                                   ImageSize,\r
-  OUT UINT32                                  *LastAttemptStatus\r
-  )\r
-{\r
-  VOID                                    *MicrocodePatchAddress;\r
-  UINTN                                   MicrocodePatchRegionSize;\r
-  UINTN                                   TargetTotalSize;\r
-  UINTN                                   UsedRegionSize;\r
-  EFI_STATUS                              Status;\r
-  VOID                                    *MicrocodePatchScratchBuffer;\r
-  UINT8                                   *ScratchBufferPtr;\r
-  UINTN                                   ScratchBufferSize;\r
-  UINTN                                   RestSize;\r
-  UINTN                                   AvailableSize;\r
-  VOID                                    *NextMicrocodeEntryPoint;\r
-  MICROCODE_INFO                          *MicrocodeInfo;\r
-  UINTN                                   MicrocodeCount;\r
-  UINTN                                   Index;\r
-\r
-  DEBUG((DEBUG_INFO, "UpdateMicrocodeFlashRegion: Image - 0x%x, size - 0x%x\n", Image, ImageSize));\r
-\r
-  MicrocodePatchAddress = MicrocodeFmpPrivate->MicrocodePatchAddress;\r
-  MicrocodePatchRegionSize = MicrocodeFmpPrivate->MicrocodePatchRegionSize;\r
-\r
-  MicrocodePatchScratchBuffer = AllocateZeroPool (MicrocodePatchRegionSize);\r
-  if (MicrocodePatchScratchBuffer == NULL) {\r
-    DEBUG((DEBUG_ERROR, "Fail to allocate Microcode Scratch buffer\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  ScratchBufferPtr = MicrocodePatchScratchBuffer;\r
-  ScratchBufferSize = 0;\r
-\r
-  //\r
-  // Target data collection\r
-  //\r
-  TargetTotalSize = 0;\r
-  AvailableSize = 0;\r
-  NextMicrocodeEntryPoint = NULL;\r
-  if (TargetMicrocodeEntryPoint != NULL) {\r
-    if (TargetMicrocodeEntryPoint->DataSize == 0) {\r
-      TargetTotalSize = 2048;\r
-    } else {\r
-      TargetTotalSize = TargetMicrocodeEntryPoint->TotalSize;\r
-    }\r
-    DEBUG((DEBUG_INFO, "  TargetTotalSize - 0x%x\n", TargetTotalSize));\r
-    NextMicrocodeEntryPoint = GetNextMicrocode(MicrocodeFmpPrivate, TargetMicrocodeEntryPoint);\r
-    DEBUG((DEBUG_INFO, "  NextMicrocodeEntryPoint - 0x%x\n", NextMicrocodeEntryPoint));\r
-    if (NextMicrocodeEntryPoint != NULL) {\r
-      ASSERT ((UINTN)NextMicrocodeEntryPoint >= ((UINTN)TargetMicrocodeEntryPoint + TargetTotalSize));\r
-      AvailableSize = (UINTN)NextMicrocodeEntryPoint - (UINTN)TargetMicrocodeEntryPoint;\r
-    } else {\r
-      AvailableSize = (UINTN)MicrocodePatchAddress + MicrocodePatchRegionSize - (UINTN)TargetMicrocodeEntryPoint;\r
-    }\r
-    DEBUG((DEBUG_INFO, "  AvailableSize - 0x%x\n", AvailableSize));\r
-  }\r
-  ASSERT (AvailableSize >= TargetTotalSize);\r
-  UsedRegionSize = GetCurrentMicrocodeUsedRegionSize(MicrocodeFmpPrivate);\r
-  DEBUG((DEBUG_INFO, "  UsedRegionSize - 0x%x\n", UsedRegionSize));\r
-  ASSERT (UsedRegionSize >= TargetTotalSize);\r
-  if (TargetMicrocodeEntryPoint != NULL) {\r
-    ASSERT ((UINTN)MicrocodePatchAddress + UsedRegionSize >= ((UINTN)TargetMicrocodeEntryPoint + TargetTotalSize));\r
-  }\r
-  //\r
-  // Total Size means the Microcode data size.\r
-  // Available Size means the Microcode data size plus the pad till (1) next Microcode or (2) the end.\r
-  //\r
-  // (1)\r
-  // +------+-----------+-----+------+===================+\r
-  // | MCU1 | Microcode | PAD | MCU2 |      Empty        |\r
-  // +------+-----------+-----+------+===================+\r
-  //        | TotalSize |\r
-  //        |<-AvailableSize->|\r
-  // |<-        UsedRegionSize     ->|\r
-  //\r
-  // (2)\r
-  // +------+-----------+===================+\r
-  // | MCU  | Microcode |      Empty        |\r
-  // +------+-----------+===================+\r
-  //        | TotalSize |\r
-  //        |<-      AvailableSize        ->|\r
-  // |<-UsedRegionSize->|\r
-  //\r
-\r
-  //\r
-  // Update based on policy\r
-  //\r
-\r
-  //\r
-  // 1. If there is enough space to update old one in situ, replace old microcode in situ.\r
-  //\r
-  if (AvailableSize >= ImageSize) {\r
-    DEBUG((DEBUG_INFO, "Replace old microcode in situ\n"));\r
-    //\r
-    // +------+------------+------+===================+\r
-    // |Other1| Old Image  |Other2|      Empty        |\r
-    // +------+------------+------+===================+\r
-    //\r
-    // +------+---------+--+------+===================+\r
-    // |Other1|New Image|FF|Other2|      Empty        |\r
-    // +------+---------+--+------+===================+\r
-    //\r
-    // 1.1. Copy new image\r
-    CopyMem (ScratchBufferPtr, Image, ImageSize);\r
-    ScratchBufferSize += ImageSize;\r
-    ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
-    // 1.2. Pad 0xFF\r
-    RestSize = AvailableSize - ImageSize;\r
-    if (RestSize > 0) {\r
-      SetMem (ScratchBufferPtr, RestSize, 0xFF);\r
-      ScratchBufferSize += RestSize;\r
-      ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
-    }\r
-    Status = UpdateMicrocode((UINTN)TargetMicrocodeEntryPoint, MicrocodePatchScratchBuffer, ScratchBufferSize, LastAttemptStatus);\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // 2. If there is enough space to remove old one and add new one, reorg and replace old microcode.\r
-  //\r
-  if (MicrocodePatchRegionSize - (UsedRegionSize - TargetTotalSize) >= ImageSize) {\r
-    if (TargetMicrocodeEntryPoint == NULL) {\r
-      DEBUG((DEBUG_INFO, "Append new microcode\n"));\r
-      //\r
-      // +------+------------+------+===================+\r
-      // |Other1|   Other    |Other2|      Empty        |\r
-      // +------+------------+------+===================+\r
-      //\r
-      // +------+------------+------+-----------+=======+\r
-      // |Other1|   Other    |Other2| New Image | Empty |\r
-      // +------+------------+------+-----------+=======+\r
-      //\r
-      Status = UpdateMicrocode((UINTN)MicrocodePatchAddress + UsedRegionSize, Image, ImageSize, LastAttemptStatus);\r
-    } else {\r
-      DEBUG((DEBUG_INFO, "Reorg and replace old microcode\n"));\r
-      //\r
-      // +------+------------+------+===================+\r
-      // |Other1| Old Image  |Other2|      Empty        |\r
-      // +------+------------+------+===================+\r
-      //\r
-      // +------+---------------+------+================+\r
-      // |Other1|   New Image   |Other2|      Empty     |\r
-      // +------+---------------+------+================+\r
-      //\r
-      // 2.1. Copy new image\r
-      CopyMem (ScratchBufferPtr, Image, ImageSize);\r
-      ScratchBufferSize += ImageSize;\r
-      ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
-      // 2.2. Copy rest images after the old image.\r
-      if (NextMicrocodeEntryPoint != 0) {\r
-        RestSize = (UINTN)MicrocodePatchAddress + UsedRegionSize - ((UINTN)NextMicrocodeEntryPoint);\r
-        CopyMem (ScratchBufferPtr, (UINT8 *)TargetMicrocodeEntryPoint + TargetTotalSize, RestSize);\r
-        ScratchBufferSize += RestSize;\r
-        ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
-      }\r
-      Status = UpdateMicrocode((UINTN)TargetMicrocodeEntryPoint, MicrocodePatchScratchBuffer, ScratchBufferSize, LastAttemptStatus);\r
-    }\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // 3. The new image can be put in MCU region, but not all others can be put.\r
-  //    So all the unused MCU is removed.\r
-  //\r
-  if (MicrocodePatchRegionSize >= ImageSize) {\r
-    //\r
-    // +------+------------+------+===================+\r
-    // |Other1| Old Image  |Other2|      Empty        |\r
-    // +------+------------+------+===================+\r
-    //\r
-    // +-------------------------------------+--------+\r
-    // |        New Image                    | Other  |\r
-    // +-------------------------------------+--------+\r
-    //\r
-    DEBUG((DEBUG_INFO, "Add new microcode from beginning\n"));\r
-\r
-    MicrocodeCount = MicrocodeFmpPrivate->DescriptorCount;\r
-    MicrocodeInfo = MicrocodeFmpPrivate->MicrocodeInfo;\r
-\r
-    // 3.1. Copy new image\r
-    CopyMem (ScratchBufferPtr, Image, ImageSize);\r
-    ScratchBufferSize += ImageSize;\r
-    ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
-    // 3.2. Copy some others to rest buffer\r
-    for (Index = 0; Index < MicrocodeCount; Index++) {\r
-      if (!MicrocodeInfo[Index].InUse) {\r
-        continue;\r
-      }\r
-      if (MicrocodeInfo[Index].MicrocodeEntryPoint == TargetMicrocodeEntryPoint) {\r
-        continue;\r
-      }\r
-      if (MicrocodeInfo[Index].TotalSize <= MicrocodePatchRegionSize - ScratchBufferSize) {\r
-        CopyMem (ScratchBufferPtr, MicrocodeInfo[Index].MicrocodeEntryPoint, MicrocodeInfo[Index].TotalSize);\r
-        ScratchBufferSize += MicrocodeInfo[Index].TotalSize;\r
-        ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
-      }\r
-    }\r
-    // 3.3. Pad 0xFF\r
-    RestSize = MicrocodePatchRegionSize - ScratchBufferSize;\r
-    if (RestSize > 0) {\r
-      SetMem (ScratchBufferPtr, RestSize, 0xFF);\r
-      ScratchBufferSize += RestSize;\r
-      ScratchBufferPtr = (UINT8 *)MicrocodePatchScratchBuffer + ScratchBufferSize;\r
-    }\r
-    Status = UpdateMicrocode((UINTN)MicrocodePatchAddress, MicrocodePatchScratchBuffer, ScratchBufferSize, LastAttemptStatus);\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // 4. The new image size is bigger than the whole MCU region.\r
-  //\r
-  DEBUG((DEBUG_ERROR, "Microcode too big\n"));\r
-  *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;\r
-  Status = EFI_OUT_OF_RESOURCES;\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Write Microcode.\r
-\r
-  Caution: This function may receive untrusted input.\r
-\r
-  @param[in]   MicrocodeFmpPrivate The Microcode driver private data\r
-  @param[in]   Image               The Microcode image buffer.\r
-  @param[in]   ImageSize           The size of Microcode image buffer in bytes.\r
-  @param[out]  LastAttemptVersion  The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]  LastAttemptStatus   The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]  AbortReason         A pointer to a pointer to a null-terminated string providing more\r
-                                   details for the aborted operation. The buffer is allocated by this function\r
-                                   with AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                   call to FreePool().\r
-\r
-  @retval EFI_SUCCESS               The Microcode image is written.\r
-  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
-  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
-  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
-  @retval EFI_WRITE_PROTECTED       The flash device is read only.\r
-**/\r
-EFI_STATUS\r
-MicrocodeWrite (\r
-  IN  MICROCODE_FMP_PRIVATE_DATA   *MicrocodeFmpPrivate,\r
-  IN  VOID                         *Image,\r
-  IN  UINTN                        ImageSize,\r
-  OUT UINT32                       *LastAttemptVersion,\r
-  OUT UINT32                       *LastAttemptStatus,\r
-  OUT CHAR16                       **AbortReason\r
-  )\r
-{\r
-  EFI_STATUS                              Status;\r
-  VOID                                    *AlignedImage;\r
-  CPU_MICROCODE_HEADER                    *TargetMicrocodeEntryPoint;\r
-  UINTN                                   TargetCpuIndex;\r
-  UINTN                                   TargetMicrcodeIndex;\r
-\r
-  //\r
-  // MCU must be 16 bytes aligned\r
-  //\r
-  AlignedImage = AllocateCopyPool(ImageSize, Image);\r
-  if (AlignedImage == NULL) {\r
-    DEBUG((DEBUG_ERROR, "Fail to allocate aligned image\n"));\r
-    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  *LastAttemptVersion = ((CPU_MICROCODE_HEADER *)Image)->UpdateRevision;\r
-  TargetCpuIndex = (UINTN)-1;\r
-  Status = VerifyMicrocode(MicrocodeFmpPrivate, AlignedImage, ImageSize, TRUE, LastAttemptStatus, AbortReason, &TargetCpuIndex);\r
-  if (EFI_ERROR(Status)) {\r
-    DEBUG((DEBUG_ERROR, "Fail to verify Microcode Region\n"));\r
-    FreePool(AlignedImage);\r
-    return Status;\r
-  }\r
-  DEBUG((DEBUG_INFO, "Pass VerifyMicrocode\n"));\r
-\r
-  DEBUG((DEBUG_INFO, "  TargetCpuIndex - 0x%x\n", TargetCpuIndex));\r
-  ASSERT (TargetCpuIndex < MicrocodeFmpPrivate->ProcessorCount);\r
-  TargetMicrcodeIndex = MicrocodeFmpPrivate->ProcessorInfo[TargetCpuIndex].MicrocodeIndex;\r
-  DEBUG((DEBUG_INFO, "  TargetMicrcodeIndex - 0x%x\n", TargetMicrcodeIndex));\r
-  if (TargetMicrcodeIndex != (UINTN)-1) {\r
-    ASSERT (TargetMicrcodeIndex < MicrocodeFmpPrivate->DescriptorCount);\r
-    TargetMicrocodeEntryPoint = MicrocodeFmpPrivate->MicrocodeInfo[TargetMicrcodeIndex].MicrocodeEntryPoint;\r
-  } else {\r
-    TargetMicrocodeEntryPoint = NULL;\r
-  }\r
-  DEBUG((DEBUG_INFO, "  TargetMicrocodeEntryPoint - 0x%x\n", TargetMicrocodeEntryPoint));\r
-\r
-  Status = UpdateMicrocodeFlashRegion(\r
-             MicrocodeFmpPrivate,\r
-             TargetMicrocodeEntryPoint,\r
-             AlignedImage,\r
-             ImageSize,\r
-             LastAttemptStatus\r
-             );\r
-\r
-  FreePool(AlignedImage);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h
deleted file mode 100644 (file)
index 9dc3063..0000000
+++ /dev/null
@@ -1,494 +0,0 @@
-/** @file\r
-  Microcode update header file.\r
-\r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#ifndef _MICROCODE_FMP_H_\r
-#define _MICROCODE_FMP_H_\r
-\r
-#include <PiDxe.h>\r
-\r
-#include <Guid/SystemResourceTable.h>\r
-#include <Guid/MicrocodeFmp.h>\r
-\r
-#include <Protocol/FirmwareManagement.h>\r
-#include <Protocol/MpService.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/DevicePathLib.h>\r
-#include <Library/HobLib.h>\r
-#include <Library/MicrocodeFlashAccessLib.h>\r
-\r
-#include <Register/Cpuid.h>\r
-#include <Register/Msr.h>\r
-#include <Register/Microcode.h>\r
-\r
-#define MICROCODE_FMP_PRIVATE_DATA_SIGNATURE  SIGNATURE_32('M', 'C', 'U', 'F')\r
-\r
-//\r
-// Microcode FMP private data structure.\r
-//\r
-\r
-typedef struct {\r
-  UINT32 LastAttemptVersion;\r
-  UINT32 LastAttemptStatus;\r
-} MICROCODE_FMP_LAST_ATTEMPT_VARIABLE;\r
-\r
-typedef struct {\r
-  CPU_MICROCODE_HEADER   *MicrocodeEntryPoint;\r
-  UINTN                  TotalSize;\r
-  BOOLEAN                InUse;\r
-} MICROCODE_INFO;\r
-\r
-typedef struct {\r
-  UINTN                  CpuIndex;\r
-  UINT32                 ProcessorSignature;\r
-  UINT8                  PlatformId;\r
-  UINT32                 MicrocodeRevision;\r
-  UINTN                  MicrocodeIndex;\r
-} PROCESSOR_INFO;\r
-\r
-typedef struct {\r
-  UINT64                 Address;\r
-  UINT32                 Revision;\r
-} MICROCODE_LOAD_BUFFER;\r
-\r
-struct _MICROCODE_FMP_PRIVATE_DATA {\r
-  UINT32                               Signature;\r
-  EFI_FIRMWARE_MANAGEMENT_PROTOCOL     Fmp;\r
-  EFI_HANDLE                           Handle;\r
-  VOID                                 *MicrocodePatchAddress;\r
-  UINTN                                MicrocodePatchRegionSize;\r
-  UINT8                                DescriptorCount;\r
-  EFI_FIRMWARE_IMAGE_DESCRIPTOR        *ImageDescriptor;\r
-  MICROCODE_INFO                       *MicrocodeInfo;\r
-  UINT32                               PackageVersion;\r
-  CHAR16                               *PackageVersionName;\r
-  MICROCODE_FMP_LAST_ATTEMPT_VARIABLE  LastAttempt;\r
-  EFI_MP_SERVICES_PROTOCOL             *MpService;\r
-  UINTN                                BspIndex;\r
-  UINTN                                ProcessorCount;\r
-  PROCESSOR_INFO                       *ProcessorInfo;\r
-};\r
-\r
-typedef struct _MICROCODE_FMP_PRIVATE_DATA  MICROCODE_FMP_PRIVATE_DATA;\r
-\r
-#define MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME  L"MicrocodeLastAttempVar"\r
-\r
-/**\r
-  Returns a pointer to the MICROCODE_FMP_PRIVATE_DATA structure from the input a as Fmp.\r
-\r
-  If the signatures matches, then a pointer to the data structure that contains\r
-  a specified field of that data structure is returned.\r
-\r
-  @param  a              Pointer to the field specified by ServiceBinding within\r
-                         a data structure of type MICROCODE_FMP_PRIVATE_DATA.\r
-\r
-**/\r
-#define MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(a) \\r
-  CR ( \\r
-  (a), \\r
-  MICROCODE_FMP_PRIVATE_DATA, \\r
-  Fmp, \\r
-  MICROCODE_FMP_PRIVATE_DATA_SIGNATURE \\r
-  )\r
-\r
-/**\r
-  Get Microcode Region.\r
-\r
-  @param[out] MicrocodePatchAddress      The address of Microcode\r
-  @param[out] MicrocodePatchRegionSize   The region size of Microcode\r
-\r
-  @retval TRUE   The Microcode region is returned.\r
-  @retval FALSE  No Microcode region.\r
-**/\r
-BOOLEAN\r
-GetMicrocodeRegion (\r
-  OUT VOID     **MicrocodePatchAddress,\r
-  OUT UINTN    *MicrocodePatchRegionSize\r
-  );\r
-\r
-/**\r
-  Collect processor information.\r
-  The function prototype for invoking a function on an Application Processor.\r
-\r
-  @param[in,out] Buffer  The pointer to private data buffer.\r
-**/\r
-VOID\r
-EFIAPI\r
-CollectProcessorInfo (\r
-  IN OUT VOID  *Buffer\r
-  );\r
-\r
-/**\r
-  Get current Microcode information.\r
-\r
-  The ProcessorInformation (BspIndex/ProcessorCount/ProcessorInfo)\r
-  in MicrocodeFmpPrivate must be initialized.\r
-\r
-  The MicrocodeInformation (DescriptorCount/ImageDescriptor/MicrocodeInfo)\r
-  in MicrocodeFmpPrivate may not be avaiable in this function.\r
-\r
-  @param[in]   MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]   DescriptorCount            The count of Microcode ImageDescriptor allocated.\r
-  @param[out]  ImageDescriptor            Microcode ImageDescriptor\r
-  @param[out]  MicrocodeInfo              Microcode information\r
-\r
-  @return Microcode count\r
-**/\r
-UINTN\r
-GetMicrocodeInfo (\r
-  IN  MICROCODE_FMP_PRIVATE_DATA     *MicrocodeFmpPrivate,\r
-  IN  UINTN                          DescriptorCount,  OPTIONAL\r
-  OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR  *ImageDescriptor, OPTIONAL\r
-  OUT MICROCODE_INFO                 *MicrocodeInfo    OPTIONAL\r
-  );\r
-\r
-/**\r
-  Verify Microcode.\r
-\r
-  Caution: This function may receive untrusted input.\r
-\r
-  @param[in]  MicrocodeFmpPrivate        The Microcode driver private data\r
-  @param[in]  Image                      The Microcode image buffer.\r
-  @param[in]  ImageSize                  The size of Microcode image buffer in bytes.\r
-  @param[in]  TryLoad                    Try to load Microcode or not.\r
-  @param[out] LastAttemptStatus          The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out] AbortReason                A pointer to a pointer to a null-terminated string providing more\r
-                                         details for the aborted operation. The buffer is allocated by this function\r
-                                         with AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                         call to FreePool().\r
-  @param[in, out] TargetCpuIndex         On input, the index of target CPU which tries to match the Microcode. (UINTN)-1 means to try all.\r
-                                         On output, the index of target CPU which matches the Microcode.\r
-\r
-  @retval EFI_SUCCESS               The Microcode image passes verification.\r
-  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
-  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
-  @retval EFI_UNSUPPORTED           The Microcode ProcessorSignature or ProcessorFlags is incorrect.\r
-  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
-**/\r
-EFI_STATUS\r
-VerifyMicrocode (\r
-  IN  MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate,\r
-  IN  VOID                        *Image,\r
-  IN  UINTN                       ImageSize,\r
-  IN  BOOLEAN                     TryLoad,\r
-  OUT UINT32                      *LastAttemptStatus,\r
-  OUT CHAR16                      **AbortReason,   OPTIONAL\r
-  IN OUT UINTN                    *TargetCpuIndex  OPTIONAL\r
-  );\r
-\r
-/**\r
-  Write Microcode.\r
-\r
-  @param[in]   MicrocodeFmpPrivate The Microcode driver private data\r
-  @param[in]   Image               The Microcode image buffer.\r
-  @param[in]   ImageSize           The size of Microcode image buffer in bytes.\r
-  @param[out]  LastAttemptVersion  The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]  LastAttemptStatus   The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]  AbortReason         A pointer to a pointer to a null-terminated string providing more\r
-                                   details for the aborted operation. The buffer is allocated by this function\r
-                                   with AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                   call to FreePool().\r
-\r
-  @retval EFI_SUCCESS               The Microcode image is written.\r
-  @retval EFI_VOLUME_CORRUPTED      The Microcode image is corrupt.\r
-  @retval EFI_INCOMPATIBLE_VERSION  The Microcode image version is incorrect.\r
-  @retval EFI_SECURITY_VIOLATION    The Microcode image fails to load.\r
-  @retval EFI_WRITE_PROTECTED       The flash device is read only.\r
-**/\r
-EFI_STATUS\r
-MicrocodeWrite (\r
-  IN MICROCODE_FMP_PRIVATE_DATA    *MicrocodeFmpPrivate,\r
-  IN VOID                          *Image,\r
-  IN UINTN                         ImageSize,\r
-  OUT UINT32                       *LastAttemptVersion,\r
-  OUT UINT32                       *LastAttemptStatus,\r
-  OUT CHAR16                       **AbortReason\r
-  );\r
-\r
-/**\r
-  Dump private information.\r
-\r
-  @param[in] MicrocodeFmpPrivate private data structure.\r
-**/\r
-VOID\r
-DumpPrivateInfo (\r
-  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate\r
-  );\r
-\r
-/**\r
-  Returns information about the current firmware image(s) of the device.\r
-\r
-  This function allows a copy of the current firmware image to be created and saved.\r
-  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
-\r
-  @param[in]      This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in, out] ImageInfoSize      A pointer to the size, in bytes, of the ImageInfo buffer.\r
-                                     On input, this is the size of the buffer allocated by the caller.\r
-                                     On output, it is the size of the buffer returned by the firmware\r
-                                     if the buffer was large enough, or the size of the buffer needed\r
-                                     to contain the image(s) information if the buffer was too small.\r
-  @param[in, out] ImageInfo          A pointer to the buffer in which firmware places the current image(s)\r
-                                     information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
-  @param[out]     DescriptorVersion  A pointer to the location in which firmware returns the version number\r
-                                     associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]     DescriptorCount    A pointer to the location in which firmware returns the number of\r
-                                     descriptors or firmware images within this device.\r
-  @param[out]     DescriptorSize     A pointer to the location in which firmware returns the size, in bytes,\r
-                                     of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
-  @param[out]     PackageVersion     A version number that represents all the firmware images in the device.\r
-                                     The format is vendor specific and new version must have a greater value\r
-                                     than the old version. If PackageVersion is not supported, the value is\r
-                                     0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
-                                     is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
-                                     that package version update is in progress.\r
-  @param[out]     PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
-                                     package version name. The buffer is allocated by this function with\r
-                                     AllocatePool(), and it is the caller's responsibility to free it with a call\r
-                                     to FreePool().\r
-\r
-  @retval EFI_SUCCESS                The device was successfully updated with the new image.\r
-  @retval EFI_BUFFER_TOO_SMALL       The ImageInfo buffer was too small. The current buffer size\r
-                                     needed to hold the image(s) information is returned in ImageInfoSize.\r
-  @retval EFI_INVALID_PARAMETER      ImageInfoSize is NULL.\r
-  @retval EFI_DEVICE_ERROR           Valid information could not be returned. Possible corrupted image.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpGetImageInfo (\r
-  IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL       *This,\r
-  IN OUT    UINTN                           *ImageInfoSize,\r
-  IN OUT    EFI_FIRMWARE_IMAGE_DESCRIPTOR   *ImageInfo,\r
-  OUT       UINT32                          *DescriptorVersion,\r
-  OUT       UINT8                           *DescriptorCount,\r
-  OUT       UINTN                           *DescriptorSize,\r
-  OUT       UINT32                          *PackageVersion,\r
-  OUT       CHAR16                          **PackageVersionName\r
-  );\r
-\r
-/**\r
-  Retrieves a copy of the current firmware image of the device.\r
-\r
-  This function allows a copy of the current firmware image to be created and saved.\r
-  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
-\r
-  @param[in]     This            A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]     ImageIndex      A unique number identifying the firmware image(s) within the device.\r
-                                 The number is between 1 and DescriptorCount.\r
-  @param[in,out] Image           Points to the buffer where the current image is copied to.\r
-  @param[in,out] ImageSize       On entry, points to the size of the buffer pointed to by Image, in bytes.\r
-                                 On return, points to the length of the image, in bytes.\r
-\r
-  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
-  @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to hold the\r
-                                 image. The current buffer size needed to hold the image is returned\r
-                                 in ImageSize.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_NOT_FOUND          The current image is not copied to the buffer.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpGetImage (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
-  IN  UINT8                             ImageIndex,\r
-  IN  OUT  VOID                         *Image,\r
-  IN  OUT  UINTN                        *ImageSize\r
-  );\r
-\r
-/**\r
-  Updates the firmware image of the device.\r
-\r
-  This function updates the hardware with the new firmware image.\r
-  This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
-  If the firmware image is updatable, the function should perform the following minimal validations\r
-  before proceeding to do the firmware image update.\r
-  - Validate the image authentication if image has attribute\r
-    IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
-    EFI_SECURITY_VIOLATION if the validation fails.\r
-  - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
-    the image is unsupported. The function can optionally provide more detailed information on\r
-    why the image is not a supported image.\r
-  - Validate the data from VendorCode if not null. Image validation must be performed before\r
-    VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
-    validation failed. The function returns EFI_ABORTED if the data is invalid.\r
-\r
-  VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
-  the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
-  a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
-  firmware image version is older than the current firmware image version or bad image checksum.\r
-  Sensitive operations such as those wiping the entire firmware image and render the device to be\r
-  non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
-  AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
-  reason to the caller.\r
-\r
-  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
-                                 The number is between 1 and DescriptorCount.\r
-  @param[in]  Image              Points to the new image.\r
-  @param[in]  ImageSize          Size of the new image in bytes.\r
-  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware image update policy.\r
-                                 Null indicates the caller did not specify the policy or use the default policy.\r
-  @param[in]  Progress           A function used by the driver to report the progress of the firmware update.\r
-  @param[out] AbortReason        A pointer to a pointer to a null-terminated string providing more\r
-                                 details for the aborted operation. The buffer is allocated by this function\r
-                                 with AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                 call to FreePool().\r
-\r
-  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
-  @retval EFI_ABORTED            The operation is aborted.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpSetImage (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                 *This,\r
-  IN  UINT8                                            ImageIndex,\r
-  IN  CONST VOID                                       *Image,\r
-  IN  UINTN                                            ImageSize,\r
-  IN  CONST VOID                                       *VendorCode,\r
-  IN  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS    Progress,\r
-  OUT CHAR16                                           **AbortReason\r
-  );\r
-\r
-/**\r
-  Checks if the firmware image is valid for the device.\r
-\r
-  This function allows firmware update application to validate the firmware image without\r
-  invoking the SetImage() first.\r
-\r
-  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
-                                 The number is between 1 and DescriptorCount.\r
-  @param[in]  Image              Points to the new image.\r
-  @param[in]  ImageSize          Size of the new image in bytes.\r
-  @param[out] ImageUpdatable     Indicates if the new image is valid for update. It also provides,\r
-                                 if available, additional information if the image is invalid.\r
-\r
-  @retval EFI_SUCCESS            The image was successfully checked.\r
-  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpCheckImage (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
-  IN  UINT8                             ImageIndex,\r
-  IN  CONST VOID                        *Image,\r
-  IN  UINTN                             ImageSize,\r
-  OUT UINT32                            *ImageUpdatable\r
-  );\r
-\r
-/**\r
-  Returns information about the firmware package.\r
-\r
-  This function returns package information.\r
-\r
-  @param[in]  This                     A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[out] PackageVersion           A version number that represents all the firmware images in the device.\r
-                                       The format is vendor specific and new version must have a greater value\r
-                                       than the old version. If PackageVersion is not supported, the value is\r
-                                       0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
-                                       comparison is to be performed using PackageVersionName. A value of\r
-                                       0xFFFFFFFD indicates that package version update is in progress.\r
-  @param[out] PackageVersionName       A pointer to a pointer to a null-terminated string representing\r
-                                       the package version name. The buffer is allocated by this function with\r
-                                       AllocatePool(), and it is the caller's responsibility to free it with a\r
-                                       call to FreePool().\r
-  @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
-                                       package version name. A value of 0 indicates the device does not support\r
-                                       update of package version name. Length is the number of Unicode characters,\r
-                                       including the terminating null character.\r
-  @param[out] AttributesSupported      Package attributes that are supported by this device. See 'Package Attribute\r
-                                       Definitions' for possible returned values of this parameter. A value of 1\r
-                                       indicates the attribute is supported and the current setting value is\r
-                                       indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
-                                       supported and the current setting value in AttributesSetting is meaningless.\r
-  @param[out] AttributesSetting        Package attributes. See 'Package Attribute Definitions' for possible returned\r
-                                       values of this parameter\r
-\r
-  @retval EFI_SUCCESS                  The package information was successfully returned.\r
-  @retval EFI_UNSUPPORTED              The operation is not supported.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpGetPackageInfo (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
-  OUT UINT32                           *PackageVersion,\r
-  OUT CHAR16                           **PackageVersionName,\r
-  OUT UINT32                           *PackageVersionNameMaxLen,\r
-  OUT UINT64                           *AttributesSupported,\r
-  OUT UINT64                           *AttributesSetting\r
-  );\r
-\r
-/**\r
-  Updates information about the firmware package.\r
-\r
-  This function updates package information.\r
-  This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
-  VendorCode enables vendor to implement vendor-specific package information update policy.\r
-  Null if the caller did not specify this policy or use the default policy.\r
-\r
-  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
-  @param[in]  Image              Points to the authentication image.\r
-                                 Null if authentication is not required.\r
-  @param[in]  ImageSize          Size of the authentication image in bytes.\r
-                                 0 if authentication is not required.\r
-  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware\r
-                                 image update policy.\r
-                                 Null indicates the caller did not specify this policy or use\r
-                                 the default policy.\r
-  @param[in]  PackageVersion     The new package version.\r
-  @param[in]  PackageVersionName A pointer to the new null-terminated Unicode string representing\r
-                                 the package version name.\r
-                                 The string length is equal to or less than the value returned in\r
-                                 PackageVersionNameMaxLen.\r
-\r
-  @retval EFI_SUCCESS            The device was successfully updated with the new package\r
-                                 information.\r
-  @retval EFI_INVALID_PARAMETER  The PackageVersionName length is longer than the value\r
-                                 returned in PackageVersionNameMaxLen.\r
-  @retval EFI_UNSUPPORTED        The operation is not supported.\r
-  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-FmpSetPackageInfo (\r
-  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL   *This,\r
-  IN  CONST VOID                         *Image,\r
-  IN  UINTN                              ImageSize,\r
-  IN  CONST VOID                         *VendorCode,\r
-  IN  UINT32                             PackageVersion,\r
-  IN  CONST CHAR16                       *PackageVersionName\r
-  );\r
-\r
-#endif\r
-\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf
deleted file mode 100644 (file)
index 55797cf..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-## @file\r
-# Microcode FMP update driver.\r
-#\r
-# Produce FMP instance to update Microcode.\r
-#\r
-#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-#  This program and the accompanying materials\r
-#  are licensed and made available under the terms and conditions of the BSD License\r
-#  which accompanies this distribution.  The full text of the license may be found at\r
-#  http://opensource.org/licenses/bsd-license.php\r
-#\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-##\r
-\r
-[Defines]\r
-  INF_VERSION                    = 0x00010005\r
-  BASE_NAME                      = MicrocodeUpdateDxe\r
-  MODULE_UNI_FILE                = MicrocodeUpdateDxe.uni\r
-  FILE_GUID                      = 0565365C-2FE1-4F88-B3BE-624C04623A20\r
-  MODULE_TYPE                    = DXE_DRIVER\r
-  VERSION_STRING                 = 1.0\r
-  ENTRY_POINT                    = MicrocodeFmpMain\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-#  VALID_ARCHITECTURES           = X64\r
-#\r
-\r
-[Sources]\r
-  MicrocodeUpdate.h\r
-  MicrocodeFmp.c\r
-  MicrocodeUpdate.c\r
-\r
-[Packages]\r
-  MdePkg/MdePkg.dec\r
-  UefiCpuPkg/UefiCpuPkg.dec\r
-\r
-[LibraryClasses]\r
-  BaseLib\r
-  UefiLib\r
-  BaseMemoryLib\r
-  DebugLib\r
-  PcdLib\r
-  MemoryAllocationLib\r
-  UefiBootServicesTableLib\r
-  HobLib\r
-  UefiRuntimeServicesTableLib\r
-  UefiDriverEntryPoint\r
-  MicrocodeFlashAccessLib\r
-\r
-[Guids]\r
-  gMicrocodeFmpImageTypeIdGuid                  ## CONSUMES   ## GUID\r
-\r
-[Protocols]\r
-  gEfiFirmwareManagementProtocolGuid            ## PRODUCES\r
-  gEfiMpServiceProtocolGuid                     ## CONSUMES\r
-\r
-[Pcd]\r
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress            ## CONSUMES\r
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize         ## CONSUMES\r
-\r
-[Depex]\r
-  gEfiVariableArchProtocolGuid AND\r
-  gEfiMpServiceProtocolGuid\r
-\r
-[UserExtensions.TianoCore."ExtraFiles"]\r
-  MicrocodeUpdateDxeExtra.uni\r
-\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.uni b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.uni
deleted file mode 100644 (file)
index 1b0d494..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// /** @file\r
-// Microcode FMP update driver.\r
-//\r
-// Produce FMP instance to update Microcode.\r
-//\r
-// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-//\r
-// This program and the accompanying materials\r
-// are licensed and made available under the terms and conditions of the BSD License\r
-// which accompanies this distribution.  The full text of the license may be found at\r
-// http://opensource.org/licenses/bsd-license.php\r
-//\r
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-//\r
-// **/\r
-\r
-\r
-#string STR_MODULE_ABSTRACT             #language en-US "Microcode FMP update driver."\r
-\r
-#string STR_MODULE_DESCRIPTION          #language en-US "Produce FMP instance to update Microcode."\r
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxeExtra.uni b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxeExtra.uni
deleted file mode 100644 (file)
index b667f12..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// /** @file\r
-// MicrocodeUpdateDxe Localized Strings and Content\r
-//\r
-// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-//\r
-// This program and the accompanying materials\r
-// are licensed and made available under the terms and conditions of the BSD License\r
-// which accompanies this distribution.  The full text of the license may be found at\r
-// http://opensource.org/licenses/bsd-license.php\r
-//\r
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-//\r
-// **/\r
-\r
-#string STR_PROPERTIES_MODULE_NAME\r
-#language en-US\r
-"MicrocodeUpdate DXE Driver"\r
-\r
-\r
diff --git a/UefiCpuPkg/Include/Guid/MicrocodeFmp.h b/UefiCpuPkg/Include/Guid/MicrocodeFmp.h
deleted file mode 100644 (file)
index 88a1953..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/** @file\r
-\r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#ifndef __MICROCODE_FMP_GUID_H__\r
-#define __MICROCODE_FMP_GUID_H__\r
-\r
-#define MICROCODE_FMP_IMAGE_TYPE_ID_GUID { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }\r
-\r
-extern EFI_GUID gMicrocodeFmpImageTypeIdGuid;\r
-\r
-#endif\r
diff --git a/UefiCpuPkg/Include/Library/MicrocodeFlashAccessLib.h b/UefiCpuPkg/Include/Library/MicrocodeFlashAccessLib.h
deleted file mode 100644 (file)
index 0dfc3ef..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/** @file\r
-  Microcode flash device access library.\r
-\r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-\r
-#ifndef __MICROCODE_FLASH_ACCESS_LIB_H__\r
-#define __MICROCODE_FLASH_ACCESS_LIB_H__\r
-\r
-/**\r
-  Perform microcode write opreation.\r
-\r
-  @param[in] FlashAddress      The address of flash device to be accessed.\r
-  @param[in] Buffer            The pointer to the data buffer.\r
-  @param[in] Length            The length of data buffer in bytes.\r
-\r
-  @retval EFI_SUCCESS           The operation returns successfully.\r
-  @retval EFI_WRITE_PROTECTED   The flash device is read only.\r
-  @retval EFI_UNSUPPORTED       The flash device access is unsupported.\r
-  @retval EFI_INVALID_PARAMETER The input parameter is not valid.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-MicrocodeFlashWrite (\r
-  IN EFI_PHYSICAL_ADDRESS         FlashAddress,\r
-  IN VOID                         *Buffer,\r
-  IN UINTN                        Length\r
-  );\r
-\r
-#endif\r
index 3bd8740c987f47d01a641f66f43273dbe3c31a52..d2965ba14c2dba0154db0fde032464527ea2f99e 100644 (file)
   ##\r
   MpInitLib|Include/Library/MpInitLib.h\r
 \r
-  ## @libraryclass  Provides services to access Microcode region on flash device.\r
-  #\r
-  MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h\r
-\r
 [Guids]\r
   gUefiCpuPkgTokenSpaceGuid      = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}\r
   gMsegSmramGuid                 = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}\r
 \r
-  ## Include/Guid/MicrocodeFmp.h\r
-  gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }\r
-\r
   ## Include/Guid/CpuFeaturesSetDone.h\r
   gEdkiiCpuFeaturesSetDoneGuid   = { 0xa82485ce, 0xad6b, 0x4101, { 0x99, 0xd3, 0xe1, 0x35, 0x8c, 0x9e, 0x7e, 0x37 }}\r
 \r
index 41cf809559ca2c52dc76664d7cc93e285f11a305..d9a3d2d6547029236f1058e5631c5b07bafb805b 100644 (file)
@@ -61,7 +61,6 @@
   SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf\r
   PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
   PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf\r
-  MicrocodeFlashAccessLib|UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf\r
   TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf\r
 \r
 [LibraryClasses.common.SEC]\r
       SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf\r
   }\r
   UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf\r
-  UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf\r
 \r
 [BuildOptions]\r
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES\r