Compare commits

...

16 Commits

Author SHA1 Message Date
16779ede2d Removed prefix to match AsmRelocateApMailBoxLoopStart
This fixes a compilation issue.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Jehl Theo <theojehl76@gmail.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Rebecca Cran <quic_rcran@quicinc.com>
Tested-by: Rebecca Cran <quic_rcran@quicinc.com>
2022-05-26 09:59:43 +00:00
07c0c2eb0a OvmfPkg: fix PcdFSBClock
kvm FSB clock is 1GHz, not 100 MHz.  Timings are off by factor 10.
Fix all affected build configurations.  Not changed: Microvm and
Cloudhw (they have already have the correct value), and Xen (has
no fixed frequency, the PCD is configured at runtime by platform
initialization code).

Fixes: c37cbc030d ("OvmfPkg: Switch timer in build time for OvmfPkg")
Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2022-05-25 13:34:26 +00:00
9c733f0b90 OvmfPkg: TdxDxe: Fix AsmRelocateApMailBoxLoop
In TDX, Application Processor busy-loops on Mailbox for OS to issue
MpProtectedModeWakeupCommandWakeup command to UEFI.  As the AP acking to
it, it clears the command member according to ACPI spec 6.4, 5.2.12.19
Multiprocessor Wakeup Structure: "The application processor need clear the
command to Noop(0) as the acknowledgement that the command is received."
However, AsmRelocateApMailBoxLoop wrongly clears WakeupVector.  Correctly
clear command instead of WakeupVector.

Without this patch, TD guest kernel fails to boot APs.

Fixes: fae5c1464d ("OvmfPkg: Add TdxDxe driver")

Cc: Min Xu <min.m.xu@intel.com>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Min Xu <min.m.xu@intel.com>
2022-05-25 12:34:46 +00:00
a21a3438f7 OvmfPkg: Make an Ia32/X64 hybrid build work with SEV
The BaseMemEncryptSevLib functionality was updated to rely on the use of
the OVMF/SEV workarea to check for SEV guests. However, this area is only
updated when running the X64 OVMF build, not the hybrid Ia32/X64 build.
Base SEV support is allowed under the Ia32/X64 build, but it now fails
to boot as a result of the change.

Update the ResetVector code to check for SEV features when built for
32-bit mode, not just 64-bit mode (requiring updates to both the Ia32
and Ia32X64 fdf files).

Fixes: f1d1c337e7
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Michael Roth <michael.roth@amd.com>
Cc: Min Xu <min.m.xu@intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2022-05-20 06:29:34 +00:00
a72d552f19 OvmfPkg/OvmfPkgX64: Use different CcProbeLib when SMM is on or off
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3930

CcProbeLib is designed to check the vm guest type. The OvmfPkg/CcProbeLib
reads the OvmfWorkArea (0x80B000) to get the vm guest type which is
written by each guest (SEV or TDX guest). But in SMM drivers the access
to OvmfWorkArea is illegal. PiSmmCpuDxeSmm.inf is an example. It uses
IoLib which in OvmfPkgX64 BaseIoLibIntrinsicSev.inf is included. The
IoLib probes if the working guest is td guest by calling CcProbe().

So CcProbeLibNull will be included when SMM_REQUIRE is set. Currently
only TDVF uses CcProbe to check the guest type, and TDVF doesn't
support SMM, so this fix has no side-effect.

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Dann Frazier <dann.frazier@canonical.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Tested-by: dann frazier <dann.frazier@canonical.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
2022-05-20 01:18:26 +00:00
1f026ababf UefiPayloadPkg: Add VariableFlashInfoLib
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Guo Dong <guo.dong@intel.com>
2022-05-19 06:11:20 +00:00
a7d3d4e7c4 OvmfPkg: Add VariableFlashInfoLib
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Julien Grall <julien@xen.org>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Peter Grehan <grehan@freebsd.org>
Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Sebastien Boeuf <sebastien.boeuf@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Rebecca Cran <rebecca@bsdio.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
2022-05-19 06:11:20 +00:00
a69eac7578 EmulatorPkg: Add VariableFlashInfoLib
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Andrew Fish <afish@apple.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Abner Chang <abner.chang@hpe.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Abner Chang <abner.chang@hpe.com>
2022-05-19 06:11:20 +00:00
524a15c1fa ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
2022-05-19 06:11:20 +00:00
8db39c60cd MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Adds support to the UEFI variable fault tolerant write (FTW) drivers
to receive FTW base and size information dynamically via the Variable
Flash Information library.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
2022-05-19 06:11:20 +00:00
4dbebc2d10 MdeModulePkg/Variable: Consume Variable Flash Info
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Updates VariableRuntimeDxe, VariableSmm, and VariableStandaloneMm
to acquire variable flash information from the Variable Flash
Information library.

Note: This introduces a dependency on VariableFlashInfoLib in these
modules. Therefore, a platform building the variable modules must
specify an instance of VariableFlashInfoLib in their platform build.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
2022-05-19 06:11:20 +00:00
60b519456c MdeModulePkg/VariableFlashInfoLib: Add initial library
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Adds a new library class VariableFlashInfoLib that abstracts access
to variable flash information. The instance provided first attempts
to retrieve information from the Variable Flash Info HOB. If that
HOB is not present, it falls back to the PCDs defined in
MdeModulePkg.

This fall back behavior provides backward compatibility for platforms
that only provide PCDs but also allows platforms that need to
dynamically provide the information using the Variable Flash Info HOB
to do so at runtime.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
2022-05-19 06:11:20 +00:00
0903042b66 MdeModulePkg: Add Variable Flash Info HOB
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

Adds a new GUID that is used to identify a HOB that passes variable
flash information to UEFI variable drivers in HOB consumption phases
such as DXE, Traditional MM, and Standalone MM.

This information was previously passed directly with PCDs such
as EfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
and gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize.

However, the Standalone MM variable driver instance does not have
direct access to the PCD database. Therefore, this HOB will first
be considered as the source for variable flash information and
if platforms do not produce the HOB, reading the information from
the PCDs directly will be a backup to provide backward
compatibility.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
2022-05-19 06:11:20 +00:00
2189c71026 .pytool/plugin/SpellCheck: Add more common words
Appends the word list to reduce the number of errors encountered
by individual packages.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
2022-05-19 03:02:14 +00:00
7b126978e1 .pytool/plugin/SpellCheck: Allow compound words
Sets "allowCompoundWords" to "true" to reduce the number of compound
word issues encountered in the future.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
2022-05-19 03:02:14 +00:00
2d1138a1a8 .azurepipelines: Fix cspell version to v5.20.0
The v5.21.0 update introduced a number of new issues that might
impact stable tag integration so this fixes the version to the
previous release.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

This value can be revisited in the future to update the
2022-05-19 03:02:14 +00:00
46 changed files with 751 additions and 143 deletions

View File

@ -17,6 +17,6 @@ steps:
#checkLatest: false # Optional
condition: and(gt(variables.pkg_count, 0), succeeded())
- script: npm install -g cspell
- script: npm install -g cspell@5.20.0
displayName: 'Install cspell npm'
condition: and(gt(variables.pkg_count, 0), succeeded())

View File

@ -21,7 +21,7 @@
"*.jpg"
],
"minWordLength": 5,
"allowCompoundWords": false,
"allowCompoundWords": true,
"maxNumberOfProblems": 200,
"maxDuplicateProblems": 200,
"ignoreWords": [
@ -178,6 +178,117 @@
"vcruntimed",
"ucrtd",
"msvcrtd",
"XIPFLAGS"
"XIPFLAGS",
"bootflow",
"bootup",
"cacheability",
"cachetype",
"conout",
"deadloop",
"devicepath",
"hisilicon",
"littleendian",
"nonsecure",
"pagetable",
"postmem",
"premem",
"reglist",
"semihalf",
"subvendor",
"subhierarchy",
"targetlist",
"tmpname",
"watchdogtimer",
"writeback",
"langcode",
"langcodes",
"autoreload",
"bootable",
"endiannness",
"fvmain",
"prefetchable",
"multiboot",
"ramdisk",
"unbootable",
"setjump",
"bytecodes",
"bytelist",
"bytestream",
"countof",
"deregistering",
"devicetree",
"mainpage",
"mismanipulation",
"pytool",
"wbinvd",
"armltd",
"datacache",
"lastattemptstatus",
"lastattemptversion",
"lowestsupportedversion",
"updateable",
"pecoff",
"autodetect",
"harddisk",
"toctou",
"bugbug",
"depexes",
"fwvol",
"hoblist",
"imagehandle",
"schedulable",
"StandaloneMMCore",
"systemtable",
"uncacheable",
"devpath",
"testsuites",
"testcase",
"pxmldoc",
"pcxml",
"pclutf",
"pcunicode",
"ntxmltransformcharacter",
"ntxmlcomparestrings",
"pcxmldoc",
"ntxmlfetchcharacterdecoder",
"ntxml",
"ntxmlspecialstringcompare",
"rtlxmlcallback",
"xmlef",
"osruntime",
"readytoboot",
"hwerrrec",
"xformed",
"xform",
"undock",
"qrencoder",
"selawik",
"ntxmlrawnextcharacter",
"undocked",
"reprompt",
"yesno",
"okcancel",
"qrencoding",
"qrlevel",
"shiftn",
"unenroll",
"pcxmlstructure",
"pxmlstructure",
"pcencoder",
"pcvoid",
"nofailure",
"blockio",
"lockv",
"uefishelldebug",
"mtrrcap",
"drhds",
"rmrrs",
"creatorid",
"dxeipl",
"swmdialogs",
"unrecovered",
"cmocka",
"unenrolling",
"unconfigure"
]
}

View File

@ -176,6 +176,7 @@
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
!endif
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf

View File

@ -122,6 +122,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLibRuntimeDxe.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf

View File

@ -0,0 +1,111 @@
/** @file
This file defines the GUID and data structure used to pass information about
a variable store mapped on flash (i.e. a MMIO firmware volume) to the modules
that consume that information such as the DXE and MM UEFI variable drivers.
The HOB described in this file is currently optional. It is primarily provided
to allow a platform to dynamically describe the flash information to environments
such as Standalone MM that cannot access the prior method using dynamic PCDs.
Even for platforms that use Standalone MM, if the information is only stored
statically such as with FixedAtBuild PCDs, the HOB is not required.
Every point of consumption in this package that uses the PCDs will first check
for the HOB and use its value if present.
Early modules such as the PEI UEFI variable driver might also consume this
information. For modules such as these, that execute early in the boot flow,
at least two approaches are possible depending on platform design.
1. If the information in the HOB exactly matches the information in the PCDs,
(i.e. the HOB values are set using the PCD values), let the driver read
the information from the PCD and produce the HOB later in boot.
2. Produce the HOB very early in boot. For example, the earliest point the HOB
is currently consumed is in FaultTolerantWritePei. Note that FaultTolerantWritePei
produces gEdkiiFaultTolerantWriteGuid which is a dependency for VariablePei.
Therefore, attaching a NULL class library to FaultTolerantWritePei with a
constructor that produces the HOB will guarantee it is produced before the first
point of consumption as the constructor is executed before the module entry point.
Copyright (c) Microsoft Corporation.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef VARIABLE_FLASH_INFO_H_
#define VARIABLE_FLASH_INFO_H_
#define VARIABLE_FLASH_INFO_HOB_GUID \
{ 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0xc2, 0xfb, 0xa2, 0x89, 0x20, 0xfc, 0x90 }}
#define VARIABLE_FLASH_INFO_HOB_VERSION 1
extern EFI_GUID gVariableFlashInfoHobGuid;
#pragma pack (push, 1)
///
/// This structure can be used to describe UEFI variable
/// flash information.
///
typedef struct {
///
/// Version of this structure.
///
/// Increment the value when the structure is modified.
///
UINT32 Version;
///
/// Reserved field.
///
/// Currently reserved for natural alignment.
///
UINT32 Reserved;
///
/// Base address of the non-volatile variable range in the flash device.
///
/// Note that this address should align with the block size requirements of the flash device.
///
EFI_PHYSICAL_ADDRESS NvVariableBaseAddress;
///
/// Size of the non-volatile variable range in the flash device.
///
/// Note that this value should be less than or equal to FtwSpareLength to support reclaim of
/// entire variable store area.
/// Note that this address should align with the block size requirements of the flash device.
///
UINT64 NvVariableLength;
///
/// Base address of the FTW spare block range in the flash device.
///
/// Note that this address should align with the block size requirements of the flash device.
///
EFI_PHYSICAL_ADDRESS FtwSpareBaseAddress;
///
/// Size of the FTW spare block range in the flash device.
///
/// Note that this value should be greater than or equal to NvVariableLength.
/// Note that this address should align with the block size requirements of the flash device.
///
UINT64 FtwSpareLength;
///
/// Base address of the FTW working block range in the flash device.
///
/// Note that if FtwWorkingLength is larger than on block size, this value should be block size aligned.
///
EFI_PHYSICAL_ADDRESS FtwWorkingBaseAddress;
///
/// Size of the FTW working block range in the flash device.
///
/// Note that if the value is less than on block size, the range should not span blocks.
/// Note that if the value is larger than one block size, this value should be block size aligned.
///
UINT64 FtwWorkingLength;
} VARIABLE_FLASH_INFO;
#pragma pack (pop)
#endif

View File

@ -0,0 +1,68 @@
/** @file
Variable Flash Information Library
Copyright (c) Microsoft Corporation<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef VARIABLE_FLASH_INFO_LIB_H_
#define VARIABLE_FLASH_INFO_LIB_H_
/**
Get the base address and size for the NV storage area used for UEFI variable storage.
@param[out] BaseAddress The NV storage base address.
@param[out] Length The NV storage length in bytes.
@retval EFI_SUCCESS NV storage information was found successfully.
@retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
@retval EFI_NOT_FOUND NV storage information could not be found.
**/
EFI_STATUS
EFIAPI
GetVariableFlashNvStorageInfo (
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
);
/**
Get the base address and size for the fault tolerant write (FTW) spare
area used for UEFI variable storage.
@param[out] BaseAddress The FTW spare base address.
@param[out] Length The FTW spare length in bytes.
@retval EFI_SUCCESS FTW spare information was found successfully.
@retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
@retval EFI_NOT_FOUND FTW spare information could not be found.
**/
EFI_STATUS
EFIAPI
GetVariableFlashFtwSpareInfo (
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
);
/**
Get the base address and size for the fault tolerant write (FTW) working
area used for UEFI variable storage.
@param[out] BaseAddress The FTW working area base address.
@param[out] Length The FTW working area length in bytes.
@retval EFI_SUCCESS FTW working information was found successfully.
@retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
@retval EFI_NOT_FOUND FTW working information could not be found.
**/
EFI_STATUS
EFIAPI
GetVariableFlashFtwWorkingInfo (
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
);
#endif

View File

@ -0,0 +1,179 @@
/** @file
Variable Flash Information Library
Copyright (c) Microsoft Corporation<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Pi/PiMultiPhase.h>
#include <Guid/VariableFlashInfo.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/VariableFlashInfoLib.h>
/**
Get the HOB that contains variable flash information.
@param[out] VariableFlashInfo Pointer to a pointer to set to the variable flash information structure.
@retval EFI_SUCCESS Variable flash information was found successfully.
@retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is NULL.
@retval EFI_NOT_FOUND Variable flash information could not be found.
**/
STATIC
EFI_STATUS
GetVariableFlashInfoFromHob (
OUT VARIABLE_FLASH_INFO **VariableFlashInfo
)
{
EFI_HOB_GUID_TYPE *GuidHob;
if (VariableFlashInfo == NULL) {
return EFI_INVALID_PARAMETER;
}
GuidHob = GetFirstGuidHob (&gVariableFlashInfoHobGuid);
if (GuidHob == NULL) {
return EFI_NOT_FOUND;
}
*VariableFlashInfo = GET_GUID_HOB_DATA (GuidHob);
//
// Assert if more than one variable flash information HOB is present.
//
DEBUG_CODE (
if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HOBs\n"));
ASSERT (FALSE);
}
);
return EFI_SUCCESS;
}
/**
Get the base address and size for the NV storage area used for UEFI variable storage.
@param[out] BaseAddress The NV storage base address.
@param[out] Length The NV storage length in bytes.
@retval EFI_SUCCESS NV storage information was found successfully.
@retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
**/
EFI_STATUS
EFIAPI
GetVariableFlashNvStorageInfo (
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
)
{
EFI_STATUS Status;
VARIABLE_FLASH_INFO *VariableFlashInfo;
if ((BaseAddress == NULL) || (Length == NULL)) {
return EFI_INVALID_PARAMETER;
}
Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
if (!EFI_ERROR (Status)) {
*BaseAddress = VariableFlashInfo->NvVariableBaseAddress;
*Length = VariableFlashInfo->NvVariableLength;
} else {
*BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
PcdGet64 (PcdFlashNvStorageVariableBase64) :
PcdGet32 (PcdFlashNvStorageVariableBase)
);
*Length = (UINT64)PcdGet32 (PcdFlashNvStorageVariableSize);
}
return EFI_SUCCESS;
}
/**
Get the base address and size for the fault tolerant write (FTW) spare
area used for UEFI variable storage.
@param[out] BaseAddress The FTW spare base address.
@param[out] Length The FTW spare length in bytes.
@retval EFI_SUCCESS FTW spare information was found successfully.
@retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
@retval EFI_NOT_FOUND FTW spare information could not be found.
**/
EFI_STATUS
EFIAPI
GetVariableFlashFtwSpareInfo (
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
)
{
EFI_STATUS Status;
VARIABLE_FLASH_INFO *VariableFlashInfo;
if ((BaseAddress == NULL) || (Length == NULL)) {
return EFI_INVALID_PARAMETER;
}
Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
if (!EFI_ERROR (Status)) {
*BaseAddress = VariableFlashInfo->FtwSpareBaseAddress;
*Length = VariableFlashInfo->FtwSpareLength;
} else {
*BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwSpareBase64) != 0 ?
PcdGet64 (PcdFlashNvStorageFtwSpareBase64) :
PcdGet32 (PcdFlashNvStorageFtwSpareBase)
);
*Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
}
return EFI_SUCCESS;
}
/**
Get the base address and size for the fault tolerant write (FTW) working
area used for UEFI variable storage.
@param[out] BaseAddress The FTW working area base address.
@param[out] Length The FTW working area length in bytes.
@retval EFI_SUCCESS FTW working information was found successfully.
@retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
@retval EFI_NOT_FOUND FTW working information could not be found.
**/
EFI_STATUS
EFIAPI
GetVariableFlashFtwWorkingInfo (
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
)
{
EFI_STATUS Status;
VARIABLE_FLASH_INFO *VariableFlashInfo;
if ((BaseAddress == NULL) || (Length == NULL)) {
return EFI_INVALID_PARAMETER;
}
Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
if (!EFI_ERROR (Status)) {
*BaseAddress = VariableFlashInfo->FtwWorkingBaseAddress;
*Length = VariableFlashInfo->FtwWorkingLength;
} else {
*BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) != 0 ?
PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) :
PcdGet32 (PcdFlashNvStorageFtwWorkingBase)
);
*Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
}
return EFI_SUCCESS;
}

View File

@ -0,0 +1,48 @@
## @file
# Variable Flash Information Library
#
# Provides services to access UEFI variable flash information.
#
# Copyright (c) Microsoft Corporation<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = BaseVariableFlashInfoLib
MODULE_UNI_FILE = BaseVariableFlashInfoLib.uni
FILE_GUID = DEC426C9-C92E-4BAD-8E93-3F61C261118B
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = VariableFlashInfoLib
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = ANY
#
[Sources]
BaseVariableFlashInfoLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
DebugLib
HobLib
[Guids]
gVariableFlashInfoHobGuid ## CONSUMES ## HOB
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## SOMETIMES_CONSUMES

View File

@ -0,0 +1,12 @@
// /** @file
// Variable Flash Information Library
//
// Copyright (c) Microsoft Corporation<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "UEFI variable flash information library"
#string STR_MODULE_DESCRIPTION #language en-US "Provides services to access UEFI variable flash information."

View File

@ -154,6 +154,10 @@
#
VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h
## @libraryclass Provides services to access UEFI variable flash information.
#
VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h
[Guids]
## MdeModule package token space guid
# Include/Guid/MdeModulePkgTokenSpace.h
@ -226,6 +230,10 @@
# Include/Guid/SmmVariableCommon.h
gSmmVariableWriteGuid = { 0x93ba1826, 0xdffb, 0x45dd, { 0x82, 0xa7, 0xe7, 0xdc, 0xaa, 0x3b, 0xbd, 0xf3 }}
## Guid of the variable flash information HOB.
# Include/Guid/VariableFlashInfo.h
gVariableFlashInfoHobGuid = { 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0xc2, 0xfb, 0xa2, 0x89, 0x20, 0xfc, 0x90 }}
## Performance protocol guid that also acts as the performance HOB guid and performance variable GUID
# Include/Guid/Performance.h
gPerformanceProtocolGuid = { 0x76B6BDFA, 0x2ACD, 0x4462, { 0x9E, 0x3F, 0xCB, 0x58, 0xC9, 0x69, 0xD9, 0x37 } }

View File

@ -103,6 +103,7 @@
DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgressLibGraphics.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
[LibraryClasses.EBC.PEIM]
IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
@ -440,6 +441,7 @@
MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
[Components.IA32, Components.X64, Components.AARCH64]
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

View File

@ -26,6 +26,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/SafeIntLib.h>
#include <Library/VariableFlashInfoLib.h>
//
// Flash erase polarity is 1
@ -708,10 +710,13 @@ InitFtwProtocol (
Since Signature and WriteQueueSize have been known, Crc can be calculated out,
then the work space header will be fixed.
@param[in] WorkSpaceLength Length in bytes of the FTW workspace area.
**/
VOID
InitializeLocalWorkSpaceHeader (
VOID
IN UINTN WorkSpaceLength
);
/**

View File

@ -46,6 +46,8 @@
UefiLib
PcdLib
ReportStatusCodeLib
SafeIntLib
VariableFlashInfoLib
[Guids]
#
@ -65,14 +67,6 @@
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
# PI spec said: When the DXE Foundation is notified that the EFI_RUNTIME_ARCH_PROTOCOL

View File

@ -52,6 +52,8 @@
ReportStatusCodeLib
SmmMemLib
BaseLib
SafeIntLib
VariableFlashInfoLib
[Guids]
#
@ -74,14 +76,6 @@
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
# PI spec said: When the DXE Foundation is notified that the EFI_RUNTIME_ARCH_PROTOCOL

View File

@ -50,7 +50,9 @@
MmServicesTableLib
PcdLib
ReportStatusCodeLib
SafeIntLib
StandaloneMmDriverEntryPoint
VariableFlashInfoLib
[Guids]
#
@ -73,13 +75,5 @@
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
[Depex]
TRUE

View File

@ -987,22 +987,43 @@ InitFtwDevice (
OUT EFI_FTW_DEVICE **FtwData
)
{
EFI_FTW_DEVICE *FtwDevice;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS WorkSpaceAddress;
UINT64 Size;
UINTN FtwWorkingSize;
EFI_FTW_DEVICE *FtwDevice;
FtwWorkingSize = 0;
Status = GetVariableFlashFtwWorkingInfo (&WorkSpaceAddress, &Size);
ASSERT_EFI_ERROR (Status);
Status = SafeUint64ToUintn (Size, &FtwWorkingSize);
// This driver currently assumes the size will be UINTN so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
//
// Allocate private data of this driver,
// Including the FtwWorkSpace[FTW_WORK_SPACE_SIZE].
//
FtwDevice = AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize));
FtwDevice = AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + FtwWorkingSize);
if (FtwDevice == NULL) {
return EFI_OUT_OF_RESOURCES;
}
FtwDevice->WorkSpaceAddress = WorkSpaceAddress;
FtwDevice->WorkSpaceLength = FtwWorkingSize;
Status = GetVariableFlashFtwSpareInfo (&FtwDevice->SpareAreaAddress, &Size);
ASSERT_EFI_ERROR (Status);
Status = SafeUint64ToUintn (Size, &FtwDevice->SpareAreaLength);
// This driver currently assumes the size will be UINTN so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
//
// Initialize other parameters, and set WorkSpace as FTW_ERASED_BYTE.
//
FtwDevice->WorkSpaceLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
FtwDevice->SpareAreaLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
if ((FtwDevice->WorkSpaceLength == 0) || (FtwDevice->SpareAreaLength == 0)) {
DEBUG ((DEBUG_ERROR, "Ftw: Workspace or Spare block does not exist!\n"));
FreePool (FtwDevice);
@ -1015,16 +1036,6 @@ InitFtwDevice (
FtwDevice->FtwWorkSpaceLba = (EFI_LBA)(-1);
FtwDevice->FtwSpareLba = (EFI_LBA)(-1);
FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwWorkingBase64);
if (FtwDevice->WorkSpaceAddress == 0) {
FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
}
FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwSpareBase64);
if (FtwDevice->SpareAreaAddress == 0) {
FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwSpareBase);
}
*FtwData = FtwDevice;
return EFI_SUCCESS;
}
@ -1277,7 +1288,7 @@ InitFtwProtocol (
FtwDevice->FtwLastWriteHeader = NULL;
FtwDevice->FtwLastWriteRecord = NULL;
InitializeLocalWorkSpaceHeader ();
InitializeLocalWorkSpaceHeader (FtwDevice->WorkSpaceLength);
//
// Refresh the working space data from working block

View File

@ -16,10 +16,13 @@ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBlockHeader = { ZERO_GUID, 0, 0
Since Signature and WriteQueueSize have been known, Crc can be calculated out,
then the work space header will be fixed.
@param[in] WorkSpaceLength Length in bytes of the FTW workspace area.
**/
VOID
InitializeLocalWorkSpaceHeader (
VOID
IN UINTN WorkSpaceLength
)
{
//
@ -46,7 +49,7 @@ InitializeLocalWorkSpaceHeader (
&gEdkiiWorkingBlockSignatureGuid,
sizeof (EFI_GUID)
);
mWorkingBlockHeader.WriteQueueSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
mWorkingBlockHeader.WriteQueueSize = WorkSpaceLength - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
//
// Crc is calculated with all the fields except Crc and STATE, so leave them as FTW_ERASED_BYTE.

View File

@ -16,6 +16,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/HobLib.h>
#include <Library/SafeIntLib.h>
#include <Library/VariableFlashInfoLib.h>
EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
@ -212,25 +214,31 @@ PeimFaultTolerantWriteInitialize (
EFI_PHYSICAL_ADDRESS SpareAreaAddress;
UINTN SpareAreaLength;
EFI_PHYSICAL_ADDRESS WorkSpaceInSpareArea;
UINT64 Size;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA FtwLastWrite;
FtwWorkingBlockHeader = NULL;
FtwLastWriteHeader = NULL;
FtwLastWriteRecord = NULL;
WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwWorkingBase64);
if (WorkSpaceAddress == 0) {
WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
}
SpareAreaAddress = 0;
SpareAreaLength = 0;
WorkSpaceAddress = 0;
WorkSpaceLength = 0;
WorkSpaceLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
Status = GetVariableFlashFtwWorkingInfo (&WorkSpaceAddress, &Size);
ASSERT_EFI_ERROR (Status);
SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwSpareBase64);
if (SpareAreaAddress == 0) {
SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwSpareBase);
}
Status = SafeUint64ToUintn (Size, &WorkSpaceLength);
// This driver currently assumes the size will be UINTN so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
SpareAreaLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
Status = GetVariableFlashFtwSpareInfo (&SpareAreaAddress, &Size);
ASSERT_EFI_ERROR (Status);
Status = SafeUint64ToUintn (Size, &SpareAreaLength);
// This driver currently assumes the size will be UINTN so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
//
// The address of FTW working base and spare base must not be 0.

View File

@ -39,6 +39,8 @@
HobLib
BaseMemoryLib
PcdLib
SafeIntLib
VariableFlashInfoLib
[Guids]
## SOMETIMES_PRODUCES ## HOB
@ -47,14 +49,6 @@
gEdkiiWorkingBlockSignatureGuid ## SOMETIMES_CONSUMES ## GUID
gEfiSystemNvDataFvGuid ## SOMETIMES_CONSUMES ## GUID
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
[Depex]
TRUE

View File

@ -567,11 +567,13 @@ GetVariableStore (
OUT VARIABLE_STORE_INFO *StoreInfo
)
{
EFI_STATUS Status;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
VARIABLE_STORE_HEADER *VariableStoreHeader;
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT32 NvStorageSize;
UINT64 NvStorageSize64;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
@ -591,11 +593,13 @@ GetVariableStore (
// Emulated non-volatile variable mode is not enabled.
//
NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);
NvStorageBase = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
PcdGet64 (PcdFlashNvStorageVariableBase64) :
PcdGet32 (PcdFlashNvStorageVariableBase)
);
Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
ASSERT_EFI_ERROR (Status);
Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
ASSERT (NvStorageBase != 0);
//

View File

@ -20,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/SafeIntLib.h>
#include <Library/VariableFlashInfoLib.h>
#include <Guid/VariableFormat.h>
#include <Guid/VariableIndexTable.h>

View File

@ -39,6 +39,8 @@
DebugLib
PeiServicesTablePointerLib
PeiServicesLib
SafeIntLib
VariableFlashInfoLib
[Guids]
## CONSUMES ## GUID # Variable store header
@ -59,9 +61,6 @@
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## SOMETIMES_CONSUMES
[Depex]

View File

@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>
#include <Library/AuthVariableLib.h>
#include <Library/VarCheckLib.h>
#include <Library/VariableFlashInfoLib.h>
#include <Library/SafeIntLib.h>
#include <Guid/GlobalVariable.h>
#include <Guid/EventGroup.h>
#include <Guid/VariableFormat.h>
@ -40,11 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "PrivilegePolymorphic.h"
#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS)\
(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \
PcdGet64 (PcdFlashNvStorageVariableBase64) : \
PcdGet32 (PcdFlashNvStorageVariableBase))
#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
EFI_VARIABLE_RUNTIME_ACCESS | \

View File

@ -423,6 +423,8 @@ FtwNotificationEvent (
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
UINTN FtwMaxBlockSize;
UINT32 NvStorageVariableSize;
UINT64 NvStorageVariableSize64;
//
// Ensure FTW protocol is installed.
@ -432,14 +434,20 @@ FtwNotificationEvent (
return;
}
Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);
ASSERT_EFI_ERROR (Status);
Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
if (!EFI_ERROR (Status)) {
ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);
ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);
}
NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
//
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
//

View File

@ -142,6 +142,7 @@ InitRealNonVolatileVariableStore (
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT8 *NvStorageData;
UINT32 NvStorageSize;
UINT64 NvStorageSize64;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
UINT32 BackUpSize;
@ -153,19 +154,24 @@ InitRealNonVolatileVariableStore (
mVariableModuleGlobal->FvbInstance = NULL;
Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
ASSERT_EFI_ERROR (Status);
Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
ASSERT (NvStorageBase != 0);
//
// Allocate runtime memory used for a memory copy of the FLASH region.
// Keep the memory and the FLASH in sync as updates occur.
//
NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);
NvStorageData = AllocateRuntimeZeroPool (NvStorageSize);
if (NvStorageData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
NvStorageBase = NV_STORAGE_VARIABLE_BASE;
ASSERT (NvStorageBase != 0);
//
// Copy NV storage data to the memory buffer.
//

View File

@ -71,8 +71,10 @@
TpmMeasurementLib
AuthVariableLib
VarCheckLib
VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
SafeIntLib
[Protocols]
gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES
@ -125,9 +127,6 @@
gEfiImageSecurityDatabaseGuid
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES

View File

@ -1084,6 +1084,8 @@ SmmFtwNotificationEvent (
EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
UINTN FtwMaxBlockSize;
UINT32 NvStorageVariableSize;
UINT64 NvStorageVariableSize64;
if (mVariableModuleGlobal->FvbInstance != NULL) {
return EFI_SUCCESS;
@ -1097,14 +1099,21 @@ SmmFtwNotificationEvent (
return Status;
}
Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);
ASSERT_EFI_ERROR (Status);
Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);
// This driver currently assumes the size will be UINT32 so assert the value is safe for now.
ASSERT_EFI_ERROR (Status);
ASSERT (NvStorageVariableBase != 0);
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
if (!EFI_ERROR (Status)) {
ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);
ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);
}
NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
//
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
//

View File

@ -80,8 +80,10 @@
AuthVariableLib
VarCheckLib
UefiBootServicesTableLib
VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
SafeIntLib
[Protocols]
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES
@ -127,9 +129,6 @@
gEdkiiVarErrorFlagGuid
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES

View File

@ -73,9 +73,11 @@
HobLib
MemoryAllocationLib
MmServicesTableLib
SafeIntLib
StandaloneMmDriverEntryPoint
SynchronizationLib
VarCheckLib
VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
@ -120,9 +122,6 @@
gEdkiiVarErrorFlagGuid
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES

View File

@ -196,6 +196,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
!if $(BUILD_SHELL) == TRUE
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
@ -577,7 +578,7 @@
!include OvmfPkg/OvmfTpmPcds.dsc.inc
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
[PcdsDynamicHii]
!include OvmfPkg/OvmfTpmPcdsHii.dsc.inc

View File

@ -206,6 +206,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
#
# Network libraries

View File

@ -217,6 +217,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
#

View File

@ -190,6 +190,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
@ -510,7 +511,7 @@
# Set ConfidentialComputing defaults
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
################################################################################
#

View File

@ -207,6 +207,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
#

View File

@ -214,6 +214,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
#
@ -650,7 +651,7 @@
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0
!if $(CSM_ENABLE) == FALSE
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
!endif
[PcdsDynamicHii]

View File

@ -76,6 +76,9 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase|gUefiOvmfPkgTokenSpaceGuid.
0x007000|0x001000
gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize
0x008000|0x001000
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize
0x010000|0x010000
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
@ -87,6 +90,14 @@ FV = PEIFV
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize
FV = DXEFV
##########################################################################################
# Set the SEV-ES specific work area PCDs (used for all forms of SEV since the
# the SEV STATUS MSR is now saved in the work area)
#
SET gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase = $(MEMFD_BASE_ADDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
SET gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize = gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
##########################################################################################
################################################################################
[FV.SECFV]

View File

@ -218,6 +218,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
#
@ -658,7 +659,7 @@
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0
!if $(CSM_ENABLE) == FALSE
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
!endif
[PcdsDynamicDefault.X64]

View File

@ -90,6 +90,14 @@ FV = PEIFV
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize
FV = DXEFV
##########################################################################################
# Set the SEV-ES specific work area PCDs (used for all forms of SEV since the
# the SEV STATUS MSR is now saved in the work area)
#
SET gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase = $(MEMFD_BASE_ADDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
SET gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize = gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
##########################################################################################
################################################################################
[FV.SECFV]

View File

@ -171,7 +171,6 @@
PciCapLib|OvmfPkg/Library/BasePciCapLib/BasePciCapLib.inf
PciCapPciSegmentLib|OvmfPkg/Library/BasePciCapPciSegmentLib/BasePciCapPciSegmentLib.inf
PciCapPciIoLib|OvmfPkg/Library/UefiPciCapPciIoLib/UefiPciCapPciIoLib.inf
CcProbeLib|OvmfPkg/Library/CcProbeLib/CcProbeLib.inf
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf
@ -198,6 +197,9 @@
!if $(SMM_REQUIRE) == FALSE
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf
CcProbeLib|OvmfPkg/Library/CcProbeLib/CcProbeLib.inf
!else
CcProbeLib|MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf
!endif
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
@ -232,6 +234,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
#
@ -681,7 +684,7 @@
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0
!if $(CSM_ENABLE) == FALSE
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|100000000
gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1000000000
!endif
[PcdsDynamicHii]

View File

@ -106,7 +106,8 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvm
FV = DXEFV
##########################################################################################
# Set the SEV-ES specific work area PCDs
# Set the SEV-ES specific work area PCDs (used for all forms of SEV since the
# the SEV STATUS MSR is now saved in the work area)
#
SET gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase = $(MEMFD_BASE_ADDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
SET gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize = gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader

View File

@ -196,6 +196,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
#

View File

@ -150,6 +150,8 @@ BITS 32
SevEsUnexpectedRespTerminate:
TerminateVmgExit TERM_UNEXPECTED_RESP_CODE
%ifdef ARCH_X64
; If SEV-ES is enabled then initialize and make the GHCB page shared
SevClearPageEncMaskForGhcbPage:
; Check if SEV is enabled
@ -209,6 +211,8 @@ GetSevCBitMaskAbove31:
GetSevCBitMaskAbove31Exit:
OneTimeCallRet GetSevCBitMaskAbove31
%endif
; Check if Secure Encrypted Virtualization (SEV) features are enabled.
;
; Register usage is tight in this routine, so multiple calls for the

View File

@ -75,6 +75,12 @@ SearchBfv:
%ifdef ARCH_IA32
;
; SEV support can be built and run using the Ia32/X64 split environment.
; Set the OVMF/SEV work area as appropriate.
;
OneTimeCall CheckSevFeatures
;
; Restore initial EAX value into the EAX register
;

View File

@ -47,7 +47,36 @@
%include "Ia32/SearchForBfvBase.asm"
%include "Ia32/SearchForSecEntry.asm"
%define WORK_AREA_GUEST_TYPE (FixedPcdGet32 (PcdOvmfWorkAreaBase))
%define WORK_AREA_GUEST_TYPE (FixedPcdGet32 (PcdOvmfWorkAreaBase))
%define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Offset))
%define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase))
%define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase))
%define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize))
%define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase))
%define SEV_ES_WORK_AREA_SIZE 25
%define SEV_ES_WORK_AREA_STATUS_MSR (FixedPcdGet32 (PcdSevEsWorkAreaBase))
%define SEV_ES_WORK_AREA_RDRAND (FixedPcdGet32 (PcdSevEsWorkAreaBase) + 8)
%define SEV_ES_WORK_AREA_ENC_MASK (FixedPcdGet32 (PcdSevEsWorkAreaBase) + 16)
%define SEV_ES_WORK_AREA_RECEIVED_VC (FixedPcdGet32 (PcdSevEsWorkAreaBase) + 24)
%define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize))
%define SEV_SNP_SECRETS_BASE (FixedPcdGet32 (PcdOvmfSnpSecretsBase))
%define SEV_SNP_SECRETS_SIZE (FixedPcdGet32 (PcdOvmfSnpSecretsSize))
%define CPUID_BASE (FixedPcdGet32 (PcdOvmfCpuidBase))
%define CPUID_SIZE (FixedPcdGet32 (PcdOvmfCpuidSize))
%define SNP_SEC_MEM_BASE_DESC_1 (FixedPcdGet32 (PcdOvmfSecPageTablesBase))
%define SNP_SEC_MEM_SIZE_DESC_1 (FixedPcdGet32 (PcdOvmfSecGhcbBase) - SNP_SEC_MEM_BASE_DESC_1)
;
; The PcdOvmfSecGhcbBase reserves two GHCB pages. The first page is used
; as GHCB shared page and second is used for bookkeeping to support the
; nested GHCB in SEC phase. The bookkeeping page is mapped private. The VMM
; does not need to validate the shared page but it need to validate the
; bookkeeping page.
;
%define SNP_SEC_MEM_BASE_DESC_2 (GHCB_BASE + 0x1000)
%define SNP_SEC_MEM_SIZE_DESC_2 (SEV_SNP_SECRETS_BASE - SNP_SEC_MEM_BASE_DESC_2)
%define SNP_SEC_MEM_BASE_DESC_3 (CPUID_BASE + CPUID_SIZE)
%define SNP_SEC_MEM_SIZE_DESC_3 (FixedPcdGet32 (PcdOvmfPeiMemFvBase) - SNP_SEC_MEM_BASE_DESC_3)
%ifdef ARCH_X64
#include <AutoGen.h>
@ -94,44 +123,15 @@
%define TDX_WORK_AREA_PGTBL_READY (FixedPcdGet32 (PcdOvmfWorkAreaBase) + 4)
%define TDX_WORK_AREA_GPAW (FixedPcdGet32 (PcdOvmfWorkAreaBase) + 8)
%define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Offset))
%define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase))
%define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase))
%define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize))
%define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase))
%define SEV_ES_WORK_AREA_SIZE 25
%define SEV_ES_WORK_AREA_STATUS_MSR (FixedPcdGet32 (PcdSevEsWorkAreaBase))
%define SEV_ES_WORK_AREA_RDRAND (FixedPcdGet32 (PcdSevEsWorkAreaBase) + 8)
%define SEV_ES_WORK_AREA_ENC_MASK (FixedPcdGet32 (PcdSevEsWorkAreaBase) + 16)
%define SEV_ES_WORK_AREA_RECEIVED_VC (FixedPcdGet32 (PcdSevEsWorkAreaBase) + 24)
%define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize))
%define SEV_SNP_SECRETS_BASE (FixedPcdGet32 (PcdOvmfSnpSecretsBase))
%define SEV_SNP_SECRETS_SIZE (FixedPcdGet32 (PcdOvmfSnpSecretsSize))
%define CPUID_BASE (FixedPcdGet32 (PcdOvmfCpuidBase))
%define CPUID_SIZE (FixedPcdGet32 (PcdOvmfCpuidSize))
%define SNP_SEC_MEM_BASE_DESC_1 (FixedPcdGet32 (PcdOvmfSecPageTablesBase))
%define SNP_SEC_MEM_SIZE_DESC_1 (FixedPcdGet32 (PcdOvmfSecGhcbBase) - SNP_SEC_MEM_BASE_DESC_1)
;
; The PcdOvmfSecGhcbBase reserves two GHCB pages. The first page is used
; as GHCB shared page and second is used for bookkeeping to support the
; nested GHCB in SEC phase. The bookkeeping page is mapped private. The VMM
; does not need to validate the shared page but it need to validate the
; bookkeeping page.
;
%define SNP_SEC_MEM_BASE_DESC_2 (GHCB_BASE + 0x1000)
%define SNP_SEC_MEM_SIZE_DESC_2 (SEV_SNP_SECRETS_BASE - SNP_SEC_MEM_BASE_DESC_2)
%define SNP_SEC_MEM_BASE_DESC_3 (CPUID_BASE + CPUID_SIZE)
%define SNP_SEC_MEM_SIZE_DESC_3 (FixedPcdGet32 (PcdOvmfPeiMemFvBase) - SNP_SEC_MEM_BASE_DESC_3)
%include "X64/IntelTdxMetadata.asm"
%include "Ia32/Flat32ToFlat64.asm"
%include "Ia32/AmdSev.asm"
%include "Ia32/PageTables64.asm"
%include "Ia32/IntelTdx.asm"
%include "X64/OvmfSevMetadata.asm"
%include "X64/IntelTdxMetadata.asm"
%include "Ia32/Flat32ToFlat64.asm"
%include "Ia32/PageTables64.asm"
%include "Ia32/IntelTdx.asm"
%include "X64/OvmfSevMetadata.asm"
%endif
%include "Ia32/AmdSev.asm"
%include "Ia16/Real16ToFlat32.asm"
%include "Ia16/Init16.asm"

View File

@ -69,7 +69,7 @@ MailBoxWakeUp:
mov rax, [rbx + WakeupVectorOffset]
; OS sends a wakeup command for a given APIC ID, firmware is supposed to reset
; the command field back to zero as acknowledgement.
mov qword [rbx + WakeupVectorOffset], 0
mov qword [rbx + CommandOffset], 0
jmp rax
MailBoxSleep:
jmp $
@ -83,7 +83,7 @@ AsmRelocateApMailBoxLoopEnd:
;-------------------------------------------------------------------------------------
global ASM_PFX(AsmGetRelocationMap)
ASM_PFX(AsmGetRelocationMap):
lea rax, [ASM_PFX(AsmRelocateApMailBoxLoopStart)]
lea rax, [AsmRelocateApMailBoxLoopStart]
mov qword [rcx], rax
mov qword [rcx + 8h], AsmRelocateApMailBoxLoopEnd - AsmRelocateApMailBoxLoopStart
ret

View File

@ -272,6 +272,7 @@
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf