]> git.proxmox.com Git - mirror_edk2.git/log
mirror_edk2.git
17 months agoUnitTestFrameworkPkg/Library/CmockaLib: Generate symbol information
Michael D Kinney [Thu, 3 Nov 2022 22:38:25 +0000 (15:38 -0700)]
UnitTestFrameworkPkg/Library/CmockaLib: Generate symbol information

Add /Zi to CC_FLAGS in CmockaLib.inf to enable symbol information

Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com>
17 months agoUnitTestFrameworkPkg: Add googletest submodule and GoogleTestLib
Michael D Kinney [Tue, 21 Jun 2022 02:52:03 +0000 (19:52 -0700)]
UnitTestFrameworkPkg: Add googletest submodule and GoogleTestLib

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

Add submodule for googletest and add GoogleTestLib that is
required for GoogleTest based unit tests. Add GoogleTest
documentation to Readme.md along with a port of the sample
unit test to the GoogleTest style.

A few typos in Readme.md are also fixed.

Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com>
Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
17 months agoMdePkg/Include/Library: Undefine _ASSERT() if already defined
Michael D Kinney [Tue, 11 Oct 2022 19:03:48 +0000 (12:03 -0700)]
MdePkg/Include/Library: Undefine _ASSERT() if already defined

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

When unit testing is enabled, make sure _ASSERT() is not already
defined by the host environment before defining _ASSERT().  This
avoids conflicts with VS20xx builds of GoogleTest based unit tests.

Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoMdePkg/Include: Update Base.h to improve C++ compatibility
Michael D Kinney [Tue, 21 Jun 2022 19:30:07 +0000 (12:30 -0700)]
MdePkg/Include: Update Base.h to improve C++ compatibility

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

* Map NULL to nullptr or __null when c++ compiler is used.
* Map STATIC_ASSERT to static_assert when a c++ compiler is used.
* Typecast RETURN_SUCCESS to type RETURN_STATUS to match type used
  by all return error/warning status codes.  C++ has stricter type
  checking and found this inconsistency.

Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoIntelFsp2Pkg: Improvement of supporting null UPD pointer in FSP-T
Kuo, Ted [Wed, 9 Nov 2022 11:30:57 +0000 (03:30 -0800)]
IntelFsp2Pkg: Improvement of supporting null UPD pointer in FSP-T

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4114

1.Use xmm5 slot 1 and xmm6 slot 3 to save ucode status and UPD pointer
  respectively in TempRamInitApi in IA32 FspSecCoreT.
2.Correct inappropriate description in the return value of
  AsmGetFspInfoHeader.
3.Replace hardcoded offset value 0x1C with FSP_HEADER_IMGBASE_OFFSET in
  FspHeler.nasm.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Chinni B Duggapu <chinni.b.duggapu@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
17 months agoArmPkg/ArmTrngLib: Fix incorrect GUID reference in DEBUG() output
Ard Biesheuvel [Thu, 10 Nov 2022 13:47:36 +0000 (21:47 +0800)]
ArmPkg/ArmTrngLib: Fix incorrect GUID reference in DEBUG() output

ArmTrngLib crashes when run in DEBUG mode due to the fact that it passed
the [truncated] GUID value to a DEBUG() print statement instead of a
pointer to the GUID which is what the %g conversion expects.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
17 months ago.github/workflows: Update CodeQL to install Python 3.10.6
Michael D Kinney [Fri, 11 Nov 2022 01:44:53 +0000 (17:44 -0800)]
.github/workflows: Update CodeQL to install Python 3.10.6

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com>
17 months agoShellPkg:Improved Smbios Type9 data under smbiosview
Sainadh Nagolu [Fri, 4 Nov 2022 10:53:08 +0000 (16:23 +0530)]
ShellPkg:Improved Smbios Type9 data under smbiosview

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4135

Added spec version check while publishing new Type9 fields,
added Slot Pitch field which was missing and
corrected the publishing order as per Smbios spec.

Cc: Vasudevan S <vasudevans@ami.com>
Cc: Sundaresan S <sundaresans@ami.com>
Signed-off-by: Sainadh Nagolu <sainadhn@ami.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agopip-requirements.txt: Update edk2-pytool-library to 0.12.0
Michael D Kinney [Thu, 10 Nov 2022 04:21:16 +0000 (20:21 -0800)]
pip-requirements.txt: Update edk2-pytool-library to 0.12.0

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4146

Update edk2-pytool-library to version 0.12.0 that adds support for
the environment variable PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_PACKAGES
that can be set to true to ignore nested packages instead of breaking
the build with an exception. Nested packages are not allowed by the
edk2 specifications.  This environment variable allows pytools to run
with reduced functionality if nested packages are present giving
downstream consumers of edk2 that use pytools time to resolve the use
of nested packages and restore all features of pytools.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
17 months agoedk2.qls: Allow error severity results and add new queries
Michael Kubacki [Tue, 8 Nov 2022 15:19:17 +0000 (10:19 -0500)]
edk2.qls: Allow error severity results and add new queries

The query cpp/conditionallyuninitializedvariable was initially
enabled with the CodeQL code because work was in progress on those
changes. The results were filtered out so CodeQL passed so we could
verify the CodeQL workflow without impacting CI results.

This change allows error severity messages and substitutes that query
with two queries that do not return failures. This allows these
queries to find future problems and prepares the CodeQL workflow to
catch future failures as queries are enabled.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Sean Brogan <sean.brogan@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
17 months agoBaseTools: Fix wrong type of arguments to formatting functions
Michael Kubacki [Tue, 8 Nov 2022 17:17:59 +0000 (12:17 -0500)]
BaseTools: Fix wrong type of arguments to formatting functions

Fixes issues found with the cpp/wrong-type-format-argument CodeQL
rule in BaseTools.

Reference:
https://cwe.mitre.org/data/definitions/686.html

The following CodeQL errors are resolved:

1. Check failure on line 1115 in
   BaseTools/Source/C/EfiRom/EfiRom.c

   - This argument should be of type 'int' but is of type 'char *'.
   - This argument should be of type 'int' but is of type 'signed
     char *'.

2. Check failure on line 359 in
   BaseTools/Source/C/GenFw/Elf32Convert.c

   - This argument should be of type 'CHAR8 *' but is of type
     'unsigned int'.

3. Check failure on line 1841 in
   BaseTools/Source/C/GenFw/Elf64Convert.c

   - This argument should be of type 'unsigned int' but is of type
     'unsigned long long'.

4. Check failure on line 1871 in
   BaseTools/Source/C/GenFw/Elf64Convert.c

   - This argument should be of type 'unsigned int' but is of type
     'unsigned long long'.

5. Check failure on line 2400 in
   BaseTools/Source/C/GenFv/GenFvInternalLib.c

   - This argument should be of type 'unsigned long long' but is of
     type 'unsigned int'.

6. Check failure on line 1099 in
   BaseTools/Source/C/GenFw/Elf64Convert.c

   - This argument should be of type 'CHAR8 *' but is of type
     'unsigned int'.

7. Check failure on line 1098 in
   BaseTools/Source/C/GenSec/GenSec.c

   - This argument should be of type 'CHAR8 *' but is of type
     'char **'.

8. Check failure on line 911 in
   BaseTools/Source/C/GenSec/GenSec.c

  - This argument should be of type 'CHAR8 *' but is of type
    'char **'.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Sean Brogan <sean.brogan@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
17 months agoBaseTools/Source/C: Use /Z7 instead of /Zi for host tools
Michael D Kinney [Sat, 5 Nov 2022 19:43:24 +0000 (12:43 -0700)]
BaseTools/Source/C: Use /Z7 instead of /Zi for host tools

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4139

Update ms.common and *.mak files to use /Z7 instead of /Zi to embed
symbol information in obj files for host tools built with VS compilers.
This prevents vcxxx.pdb files from being generated in the root of
the local edk2 repository or in BaseTools directories.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoPrmPkg/PrmSsdtInstallDxe: Update PRMT Device CID to PNP0C02.
Wei6 Xu [Mon, 7 Nov 2022 08:29:39 +0000 (16:29 +0800)]
PrmPkg/PrmSsdtInstallDxe: Update PRMT Device CID to PNP0C02.

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4141

PRMT device is an unknown device in Device Manager if there is no
Windows Driver installed for it. It will cause WHQL Signed Driver
test failure.

To complete WHQL certification, update PRMT Device CID to PNP0C02.

In this way, PRMT Device will be a Motherboard Resources when no
real driver is loaded (default), but will be shown as the actual
device name when a legitimate Windows Driver is loaded.

Cc: Michael Kubacki <michael.kubacki@microsoft.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Ankit Sinha <ankit.sinha@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
Reviewed-by: Ankit Sinha <ankit.sinha@intel.com>
Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
17 months ago.github: Add initial CodeQL config and workflow files
Michael Kubacki [Wed, 3 Aug 2022 20:19:02 +0000 (16:19 -0400)]
.github: Add initial CodeQL config and workflow files

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4115

Adds initial support for enabling CodeQL Code Scanning in this
repository per the RFC:

  https://github.com/tianocore/edk2/discussions/3258

Adds the following new files:
  - .github/workflows/codql-analysis.yml - The main GitHub workflow
    file used to setup CodeQL in the repo.
  - .github/codeql/codeql-config.yml - The main CodeQL configuration
    file used to customize the queries and other resources the repo
    is using for CodeQL.
  - edk2.qls - A query set of queries to run for CodeQL.

Cc: Sean Brogan <sean.brogan@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: Michael D Kinney <michael.d.kinney@intel.com>
17 months agoMaintainers.txt: Add .github maintainers and reviewers
Michael Kubacki [Wed, 3 Aug 2022 20:28:38 +0000 (16:28 -0400)]
Maintainers.txt: Add .github maintainers and reviewers

Adds the maintainers and reviewers for the new .github directory
being added to hold GitHub workflows files.

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
17 months agoCryptoPkg: Sha1 functions causing build errors
Judah Vang [Mon, 7 Nov 2022 20:02:25 +0000 (04:02 +0800)]
CryptoPkg: Sha1 functions causing build errors

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3991

Fix build issue when DiSABLE_SHA1_DEPRECATED_INTERFACES
is defined. Percolate the #ifndef DiSABLE_SHA1_DEPRECATED_INTERFACES
to all the Sha1 functions.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Nishant C Mistry <nishant.c.mistry@intel.com>
Signed-off-by: Judah Vang <judah.vang@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoPrmPkg: Use UnitTestFrameworkPkg UEFI BS library
Michael Kubacki [Fri, 4 Nov 2022 00:11:39 +0000 (20:11 -0400)]
PrmPkg: Use UnitTestFrameworkPkg UEFI BS library

Updates PrmPkg to use UnitTestUefiBootServicesTableLib from
UnitTestFrameworkPkg instead of UefiBootServicesTableLibUnitTest
in PrmPkg.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
17 months agoUnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib
Michael Kubacki [Fri, 4 Nov 2022 00:07:49 +0000 (20:07 -0400)]
UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib

This library supports a Boot Services table library implementation
that allows code dependent upon UefiBootServicesTableLib to operate
in an isolated execution environment such as within
the context of a host-based unit test framework.

The unit test should initialize the Boot Services database with any
required elements (e.g. protocols, events, handles, etc.) prior to
the services being invoked by code under test.

It is strongly recommended to clean any global databases (e.g.
protocol, event, handles, etc.) after every unit test so the tests
execute in a predictable manner from a clean state.

This library is being moved here from PrmPkg so it can be made more
generally available to other packages and improved upon for others
use.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
17 months agoCryptoPkg/Readme.md: typo and grammar fixes
Laszlo Ersek [Fri, 4 Nov 2022 12:02:14 +0000 (20:02 +0800)]
CryptoPkg/Readme.md: typo and grammar fixes

Commit 244ce33bdd2f ("CryptoPkg: Add Readme.md", 2022-10-24) had added the
long-awaited documentation on the dynamic crypto services. Fix some of the
typos and arguable grammar errors in "Readme.md". A few light
clarifications are also snuck in.

Cc: Christopher Zurcher <christopher.zurcher@microsoft.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Xiaoyu Lu <xiaoyu1.lu@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Christopher Zurcher <christopher.zurcher@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoMdePkg/BaseLib: Fix out-of-bounds reads in SafeString
Pedro Falcato [Thu, 3 Nov 2022 01:11:49 +0000 (09:11 +0800)]
MdePkg/BaseLib: Fix out-of-bounds reads in SafeString

There was a OOB access in *StrHexTo* functions, when passed strings like
"XDEADBEEF".

OpenCore folks established an ASAN-equipped project to fuzz Ext4Dxe,
which was able to catch these (mostly harmless) issues.

Cc: Vitaly Cheptsov <vit9696@protonmail.com>
Cc: Marvin H?user <mhaeuser@posteo.de>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
Acked-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@Intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoArmVirtPkg: Kvmtool: Add RNG support using Arm TRNG interface
Sami Mujawar [Fri, 28 Oct 2022 15:32:59 +0000 (17:32 +0200)]
ArmVirtPkg: Kvmtool: Add RNG support using Arm TRNG interface

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

The EFI_RNG_PROTOCOL published by RngDxe has been updated to
implement the EFI_RNG_ALGORITHM_RAW using the Arm TRNG interface
to provide access to entropy.

Therefore, enable EFI_RNG_PROTOCOL for the Kvmtool guest/virtual
firmware.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
17 months agoSecurityPkg/RngDxe: Add Arm support of RngDxe
Pierre Gondois [Fri, 28 Oct 2022 15:32:58 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Add Arm support of RngDxe

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

Add RngDxe support for Arm. This implementation uses the ArmTrngLib
to support the RawAlgorithm and doens't support the RNDR instruction.

To re-use the RngGetRNG(), RngGetInfo() and FreeAvailableAlgorithms()
functions, create Arm/AArch64 files which implement the arch specific
function GetAvailableAlgorithms(). Indeed, FEAT_RNG instruction is not
supported on Arm.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Rename AArch64/RngDxe.c
Pierre Gondois [Fri, 28 Oct 2022 15:32:57 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Rename AArch64/RngDxe.c

To re-use the AArch64/RngDxe.c for an Arm implementation,
rename AArch64/RngDxe.c to ArmRngDxe.c.

Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Add debug warning for NULL PcdCpuRngSupportedAlgorithm
Pierre Gondois [Fri, 28 Oct 2022 15:32:56 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Add debug warning for NULL PcdCpuRngSupportedAlgorithm

PcdCpuRngSupportedAlgorithm should allow to identify the the algorithm
used by the RNDR CPU instruction to generate a random number.
Add a debug warning if the Pcd is not set.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Add AArch64 RawAlgorithm support through ArmTrngLib
Sami Mujawar [Fri, 28 Oct 2022 15:32:55 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Add AArch64 RawAlgorithm support through ArmTrngLib

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

RawAlgorithm is used to provide access to entropy that is suitable
for cryptographic applications. Therefore, add RawAlgorithm support
that provides access to entropy using the ArmTrngLib.

Also remove unused UefiBootServicesTableLib library inclusion
and Status variable.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Check before advertising Cpu Rng algo
Pierre Gondois [Fri, 28 Oct 2022 15:32:54 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Check before advertising Cpu Rng algo

RngGetBytes() relies on the RngLib. The RngLib might use the RNDR
instruction if the FEAT_RNG feature is present. RngGetInfo and
RngGetRNG both must check that RngGetBytes() is working before
advertising/using it.

To do so, allocate an array storing the available algorithms.
The Rng algorithm at the lowest index will be the default Rng
algorithm. The array is shared between RngGetInfo and RngGetRNG.

This array is allocated when the driver is loaded, and freed
when unloaded.

This patch also prevents from having PcdCpuRngSupportedAlgorithm
let to a zero GUID, but let the possibility to have no valid Rng
algorithm in such case.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Documentation/include/parameter cleanup
Pierre Gondois [Fri, 28 Oct 2022 15:32:53 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Documentation/include/parameter cleanup

This patch:
-Update RngGetBytes() documentation to align the function
 definition and declaration.
-Improve input parameter checking. Even though 'This'
 it is not used, the parameter should always point to the
 current EFI_RNG_PROTOCOL.
-Removes TimerLib inclusion as unused.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Remove ArchGetSupportedRngAlgorithms()
Pierre Gondois [Fri, 28 Oct 2022 15:32:52 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Remove ArchGetSupportedRngAlgorithms()

RngGetInfo() is one of the 2 functions of the EFI_RNG_PROTOCOL.
RngGetInfo() is currently a mere wrapper around
ArchGetSupportedRngAlgorithms() which is implemented differently
depending on the architecture used.

RngGetInfo() does nothing more than calling
ArchGetSupportedRngAlgorithms(). So remove it, and let RngGetInfo()
be implemented differently according to the architecture.

This follows the implementation of the other function of the
EFI_RNG_PROTOCOL, RngGetRNG().

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Replace Pcd with Sp80090Ctr256Guid
Pierre Gondois [Fri, 28 Oct 2022 15:32:51 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Replace Pcd with Sp80090Ctr256Guid

gEfiRngAlgorithmSp80090Ctr256Guid was used as the default algorithm
in RngGetRNG(). The commit below set the default algorithm to
PcdCpuRngSupportedAlgorithm, which is a zero GUID by default.

As the Pcd value is not defined for any platform in the edk2-platfoms
repository, assume it was an error and go back to the first version,
using gEfiRngAlgorithmSp80090Ctr256Guid.

Fixes: 4e5ecdbac8bd ("SecurityPkg: Add support for RngDxe on AARCH64")
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoSecurityPkg/RngDxe: Rename RdRandGenerateEntropy to generic name
Sami Mujawar [Fri, 28 Oct 2022 15:32:50 +0000 (17:32 +0200)]
SecurityPkg/RngDxe: Rename RdRandGenerateEntropy to generic name

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

Rename RdRandGenerateEntropy() to GenerateEntropy() to provide a
common interface to generate entropy on other architectures.
GenerateEntropy() is intended to generate high quality entropy.

Also move the definition to RngDxeInternals.h

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agoArmPkg/ArmTrngLib: Add Arm TRNG library
Sami Mujawar [Fri, 28 Oct 2022 15:32:49 +0000 (17:32 +0200)]
ArmPkg/ArmTrngLib: Add Arm TRNG library

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

The Arm True Random Number Generator Firmware, Interface 1.0,
Platform Design Document
(https://developer.arm.com/documentation/den0098/latest/)
defines an interface between an Operating System (OS) executing
at EL1 and Firmware (FW) exposing a conditioned entropy source
that is provided by a TRNG back end.

The conditioned entropy, that is provided by the Arm TRNG interface,
is commonly used to seed deterministic random number generators.

This patch adds an ArmTrngLib library that implements the Arm TRNG
interface.

Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
17 months agoArmPkg: Add FID definitions for Arm TRNG
Sami Mujawar [Fri, 28 Oct 2022 15:32:48 +0000 (17:32 +0200)]
ArmPkg: Add FID definitions for Arm TRNG

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

The Arm True Random Number Generator Firmware, Interface 1.0,
Platform Design Document
(https://developer.arm.com/documentation/den0098/latest/)
defines an interface between an Operating System (OS) executing
at EL1 and Firmware (FW) exposing a conditioned entropy source
that is provided by a TRNG back end.

New function IDs have been defined by the specification for
accessing the TRNG services. Therefore, add these definitions
to the Arm standard SMC header.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
17 months agoMdePkg/ArmTrngLib: Add NULL instance of Arm TRNG Library
Sami Mujawar [Fri, 28 Oct 2022 15:32:47 +0000 (17:32 +0200)]
MdePkg/ArmTrngLib: Add NULL instance of Arm TRNG Library

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

The Arm True Random Number Generator (TRNG) library defines an
interface to access the entropy source on a platform. On platforms
that do not have access to an entropy source, a NULL instance of
the TRNG library may be useful to satisfy the build dependency.

Therefore, add a NULL instance of the Arm TRNG library.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoMdePkg/ArmTrngLib: Definition for Arm TRNG library class interface
Sami Mujawar [Fri, 28 Oct 2022 15:32:46 +0000 (17:32 +0200)]
MdePkg/ArmTrngLib: Definition for Arm TRNG library class interface

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

The NIST Special Publications 800-90A, 800-90B and 800-90C
provide recommendations for random number generation. The
NIST 800-90C, Recommendation for Random Bit Generator (RBG)
Constructions, defines the GetEntropy() interface that is
used to access the entropy source. The GetEntropy() interface
is further used by Deterministic Random Bit Generators (DRBG)
to generate random numbers.

The Arm True Random Number Generator (TRNG) library defines an
interface to access the entropy source on a platform, following
the 'Arm True Random Number Generator Firmware Interface'
specification.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoArmPkg/ArmHvcLibNull: Add NULL instance of ArmHvcLib
Pierre Gondois [Fri, 28 Oct 2022 15:32:45 +0000 (17:32 +0200)]
ArmPkg/ArmHvcLibNull: Add NULL instance of ArmHvcLib

Add a Null instance of ArmHvcLib in case of library dependencies.

Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
17 months agoArmPkg: Sort HVC/SMC section alphbetically in ArmPkg.dsc
Pierre Gondois [Fri, 28 Oct 2022 15:32:44 +0000 (17:32 +0200)]
ArmPkg: Sort HVC/SMC section alphbetically in ArmPkg.dsc

Sort the section containing HVC/SMC libraries prior to
adding new libraries in this specific section.

Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
17 months agoArmPkg/ArmMonitorLib: Add ArmMonitorLib
Pierre Gondois [Fri, 28 Oct 2022 15:32:43 +0000 (17:32 +0200)]
ArmPkg/ArmMonitorLib: Add ArmMonitorLib

The ArmMonitorLib provides an abstract interface to issue
an HyperVisor Call (HVC) or System Monitor Call (SMC) depending
on the default conduit.
The PcdMonitorConduitHvc PCD allows to select the default conduit.

Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
17 months agoArmPkg/ArmMonitorLib: Definition for ArmMonitorLib library class
Pierre Gondois [Fri, 28 Oct 2022 15:32:42 +0000 (17:32 +0200)]
ArmPkg/ArmMonitorLib: Definition for ArmMonitorLib library class

The ArmMonitorLib provides an abstract interface to issue
an HyperVisor Call (HVC) or System Monitor Call (SMC) depending
on the default conduit.
The PcdMonitorConduitHvc PCD allows to select the default conduit.

The new library relies on the ArmHvcLib and ArmSmcLib libraries.
A Null instance of these libraries can be used for the unused conduit.

Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
17 months agoArmPkg: PCD to select conduit for monitor calls
Sami Mujawar [Fri, 28 Oct 2022 15:32:41 +0000 (17:32 +0200)]
ArmPkg: PCD to select conduit for monitor calls

Define a PCD 'PcdMonitorConduitHvc' to select the conduit to use for
monitor calls. PcdMonitorConduitHvc is defined as FALSE by default,
meaning the SMC conduit is enabled as default.

Adding PcdMonitorConduitHvc allows selection of HVC conduit to be used
by virtual firmware implementations.

Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
17 months agoArmPlatformPkg: Retire NorFlashDxe driver
Ard Biesheuvel [Mon, 24 Oct 2022 16:53:35 +0000 (18:53 +0200)]
ArmPlatformPkg: Retire NorFlashDxe driver

The NorFlashDxe driver in ArmPlatformPkg was shared between development
platforms built by ARM Ltd, and virtual platforms that were once modeled
after Versatile Express, but have very little in common with actual bare
metal implementations.

Both sides have migrated to a domain specific version of the driver, so
we can retire the old one.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
17 months agoOvmfPkg/VmgExitLig: HALT on #VE when access to private memory
Min M Xu [Fri, 28 Oct 2022 08:24:01 +0000 (16:24 +0800)]
OvmfPkg/VmgExitLig: HALT on #VE when access to private memory

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4125

EPT-violation #VE should be always on shared memory, which means the
shared bit of the GuestPA should be set. But in current #VE Handler
it is not checked. When it occurs, stop TD immediately and log out
the error.

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: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Guorui Yu <ruogui.ygr@alibaba-inc.com>
Tested-by: Guorui Yu <ruogui.ygr@alibaba-inc.com>
17 months agoUefiPayloadPkg: Boot mode in PHIT HOB will not be updated
VictorX Hsu [Thu, 3 Nov 2022 10:52:41 +0000 (18:52 +0800)]
UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4136

System will depend on Boot Mode value to do different behavior
Update during Capsule Update process. So UPL need to support
update boot mode.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Reviewed-by: James Lu <james.lu@intel.com>
Reviewed-by: Gua Guo <gua.guo@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
17 months agoMdeModulePkg/Ufs :Coverity scan flags multiple issues in edk2-stable202205
Sivaparvathi C [Fri, 28 Oct 2022 07:18:32 +0000 (12:48 +0530)]
MdeModulePkg/Ufs :Coverity scan flags multiple issues in edk2-stable202205

BugZilla ID:https://bugzilla.tianocore.org/show_bug.cgi?id=3989

Added changes to resolve the Coverity Issues in UFS driver

Cc: Vasudevan Sambandan <vasudevans@ami.com>
Cc: Sundaresan Selvaraj <sundaresans@ami.com>
Signed-off-by: Sivaparvathi Chellaiah <sivaparvathic@ami.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoMdeModulePkg/scsi :Coverity scan flags multiple issues in edk2-stable202205
Sivaparvathi C [Thu, 27 Oct 2022 11:06:59 +0000 (16:36 +0530)]
MdeModulePkg/scsi :Coverity scan flags multiple issues in edk2-stable202205

Added changes to resolve the SCSI driver Coverity issues.

Cc: Vasudevan Sambandan <vasudevans@ami.com>
Cc: Sundaresan Selvaraj <sundaresans@ami.com>
Signed-off-by: Sivaparvathi chellaiah <sivaparvathic@ami.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoIntelFsp2Pkg: FSP should support input UPD as NULL.
Chasel Chiu [Mon, 24 Oct 2022 03:00:57 +0000 (20:00 -0700)]
IntelFsp2Pkg: FSP should support input UPD as NULL.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4114

FSP specification supports input UPD as NULL cases which FSP will
use built-in UPD region instead.
FSP should not return INVALID_PARAMETER in such cases.

In FSP-T entry point case, the valid FSP-T UPD region pointer will be
passed to platform FSP code to consume.
In FSP-M and FSP-S cases, valid UPD pointer will be decided when
updating corresponding pointer field in FspGlobalData.

Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Reviewed-by: Ted Kuo <ted.kuo@intel.com>
17 months agoMdeModulePkg/PiSmmCore: SmmEntryPoint underflow (CVE-2021-38578)
Miki Demeter [Thu, 27 Oct 2022 23:20:54 +0000 (16:20 -0700)]
MdeModulePkg/PiSmmCore: SmmEntryPoint underflow (CVE-2021-38578)

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3387

Added use of SafeIntLib to validate values are not causing overflows or
underflows in user controlled values when calculating buffer sizes.

Signed-off-by: Miki Demeter <miki.demeter@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
17 months agoIntelFsp2Pkg: Update Function header to support IA32/X64.
Chasel Chiu [Fri, 28 Oct 2022 02:37:27 +0000 (19:37 -0700)]
IntelFsp2Pkg: Update Function header to support IA32/X64.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4126

Common functions will have either 32bit or 64bit instances which
having different return code size. Function header should support both
scenarios.

Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
17 months agoUefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c
Abner Chang [Mon, 31 Oct 2022 07:59:36 +0000 (15:59 +0800)]
UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Remove the header files those are already included in
CpuFeatureLib.h.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
17 months agoUefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code
Abner Chang [Mon, 31 Oct 2022 02:37:49 +0000 (10:37 +0800)]
UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

This change stripped away the code that can be
shared with other archs or vendors from Intel
implementation and put in to the common file,
leaves the Intel X86 implementation in the
IntelSmmCpuFeatureLib. Also updates the header
file and INF file.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
17 months agoUefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file
Abner Chang [Sat, 1 Oct 2022 15:09:54 +0000 (23:09 +0800)]
UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Rename SmmCpuFeaturesLiCommon.c to
IntelSmmCpuFeaturesLib, because it was developed
specifically for Intel implementation. The code
that can be shared by other archs or vendors
will be stripped away and put in the common
file in the next patch.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
17 months agoCryptoPkg/Test: Simplify BaseCryptLib host based unit tests
Michael D Kinney [Fri, 28 Oct 2022 18:58:24 +0000 (11:58 -0700)]
CryptoPkg/Test: Simplify BaseCryptLib host based unit tests

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4130

Remove TestBaseCryptLibHostAccel.inf and instead use FILE_GUID
override in DSC file to run the same unit test INF against
OpensslLibFull.inf and OpensslLibFullAccel.inf

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyu1.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
17 months agopip-requirements.txt: Bump pytool extensions and library
Michael Kubacki [Tue, 1 Nov 2022 23:40:14 +0000 (07:40 +0800)]
pip-requirements.txt: Bump pytool extensions and library

Fixes edk2 CI failure due to VM images being updated to Python 3.11
and the old pip modules not being compatible with Python 3.11.

Updates the following pip modules:

  - edk2-pytool-library from 0.11.2 to 0.11.6
  - edk2-pytool-extensions from 0.16 to 0.19.1

Needed to fix an issue with Python 3.11 compatibility.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
18 months agoUnitTestFrameworkPkg: Support FILE_GUID override in host based unit tests
Michael D Kinney [Fri, 28 Oct 2022 15:41:34 +0000 (08:41 -0700)]
UnitTestFrameworkPkg: Support FILE_GUID override in host based unit tests

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4129

Always use the module name with FILE_GUID to generate the host-based
unit test executable image and symbol files.  This allows the same
host-based unit test INF file to be used more than once in a single
DSC file with FILE_GUID override.  This is valuable when there is a
requirement to run the same host-based unit test with different PCD
settings, library mappings, or build options.

Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com>
Reviewed-by: Sean Brogan <sean.brogan@microsoft.com>
18 months agoOvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages
Min M Xu [Tue, 1 Nov 2022 05:13:49 +0000 (13:13 +0800)]
OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

After EdkiiMemoryAcceptProtocol is implemented in TdxDxe driver, we can
call it to accept pages in DXE phase.

Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
18 months agoOvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe
Min M Xu [Tue, 1 Nov 2022 05:13:48 +0000 (13:13 +0800)]
OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

Memory usage may exceed the amount accepted at the begining (SEC), TDVF
needs to accept memory dynamically when OUT_OF_RESOURCE occurs.

Another usage is in SetOrClearSharedBit. If a memory region is changed from
shared to private, it must be accepted again.

EdkiiMemoryAcceptProtocol is defined in MdePkg and is implementated /
installed in TdxDxe for Intel TDX memory acceptance.

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: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
18 months agoMdePkg: The prototype definition of EdkiiMemoryAcceptProtocol
Jiaqi Gao [Tue, 1 Nov 2022 05:13:47 +0000 (13:13 +0800)]
MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

EdkiiMemoryAcceptProtocol is defined in MdePkg, the method AcceptMemory()
can be called when memory needs to be accepted.

EdkiiMemoryAcceptProtocol can be installed by architecture-specific
drivers such as TdxDxe. This allows different isolation architectures
to realize their own low-level methods to accept memory.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.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: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
18 months agoOvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
Min M Xu [Tue, 1 Nov 2022 05:13:46 +0000 (13:13 +0800)]
OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

There are below major changes in PlatformInitLib/PlatformPei
1. ProcessHobList
  The unaccepted memory is accepted if it is under 4G address.
  Please be noted: in current stage, we only accept the memory under 4G.
  We will re-visit here in the future when on-demand accept memory is
  required.

2. TransferTdxHobList
  Transfer the unaccepted memory hob to EFI_RESOURCE_SYSTEM_MEMORY hob
  if it is accepted.

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: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
18 months agoShellPkg: Update shell command memmap to show unaccepted memory
Min M Xu [Tue, 1 Nov 2022 05:13:45 +0000 (13:13 +0800)]
ShellPkg: Update shell command memmap to show unaccepted memory

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

ShellCommandRunMemMap() is updated to handle the case of unaccepted
memory type.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.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: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
18 months agoMdeModulePkg: Update Dxe to handle unaccepted memory type
Min M Xu [Tue, 1 Nov 2022 05:13:44 +0000 (13:13 +0800)]
MdeModulePkg: Update Dxe to handle unaccepted memory type

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

Unaccepted memory is a kind of new memory type,
CoreInitializeGcdServices() and CoreGetMemoryMap() are updated to handle
the unaccepted memory type.

Ref: microsoft/mu_basecore@97e9c31

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.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: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
18 months agoMdePkg: Add UEFI Unaccepted memory definition
Min M Xu [Tue, 1 Nov 2022 05:13:43 +0000 (13:13 +0800)]
MdePkg: Add UEFI Unaccepted memory definition

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

Plase refer to:
  UEFI Spec v2.9 Table 7-5 Memory Type Usage before ExitBootServices()

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.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: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
18 months agoOvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED defined in MdeModulePkg
Min M Xu [Tue, 1 Nov 2022 05:13:42 +0000 (13:13 +0800)]
OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED defined in MdeModulePkg

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined in MdeModulePkg. The
files which use the definition are updated as well.

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: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
18 months agoMdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
Min M Xu [Tue, 1 Nov 2022 05:13:41 +0000 (13:13 +0800)]
MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
But this defitinion has not been officially in the PI spec. Base
on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at
MdeModulePkg/Include/Pi/PrePiHob.h and update EFI_RESOURCE_MAX_MEMORY_TYPE
to 8. After BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is officially published
in PI spec, we will re-visit here.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.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: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
18 months agoMdeModulePkg: Add PrePiHob.h
Min M Xu [Tue, 1 Nov 2022 05:13:40 +0000 (13:13 +0800)]
MdeModulePkg: Add PrePiHob.h

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
But this defitinion has not been officially in the PI spec. Base
on the code-first we define BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED at
MdeModulePkg/Include/Pi/PrePiHob.h.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.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: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
18 months agoRedfishPkg/RedfishDiscoverDxe: Fix memory free issue
Abner Chang [Fri, 28 Oct 2022 10:16:55 +0000 (18:16 +0800)]
RedfishPkg/RedfishDiscoverDxe: Fix memory free issue

Check the memory block pointer before freeing it.

Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Signed-off-by: Abner Chang <abner.chang@amd.com>
Reviewed-by: Nickle Wang <nicklew@nvidia.com>
18 months agoMaintainers.txt: Add 'Pierre Gondois' as DynamicTablesPkg reviewer
Pierre Gondois [Fri, 23 Sep 2022 13:35:01 +0000 (15:35 +0200)]
Maintainers.txt: Add 'Pierre Gondois' as DynamicTablesPkg reviewer

Add myself as reviewer for the DynamicTablesPkg.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Alexei Fedorov <Alexei.Fedorov@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoShellPkg/AcpiView: Update PCCT fields for ACPI 6.5
Pierre Gondois [Mon, 10 Oct 2022 09:20:58 +0000 (11:20 +0200)]
ShellPkg/AcpiView: Update PCCT fields for ACPI 6.5

The ACPI specification updated some terms in accordance with:
s1.1.1 Principle of Inclusive Terminology

Update the PCCT parser accordincly with these new terms.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Readme.md: Update available tables for generation
Pierre Gondois [Mon, 10 Oct 2022 09:20:57 +0000 (11:20 +0200)]
DynamicTablesPkg: Readme.md: Update available tables for generation

The following tables can now be generated by the DynamicTablesPkg:
 - PCCT
 - PPTT
 - SRAT

Update the documentation accordingly.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg/AmlLib: Allow larger AccessSize for Pcc address space
Pierre Gondois [Mon, 10 Oct 2022 09:20:56 +0000 (11:20 +0200)]
DynamicTablesPkg/AmlLib: Allow larger AccessSize for Pcc address space

For Pcc address space, the AccessSize field of a Register is
used to delcare the Pcc Subspace Id. This Id can be up to 256.

Cf. ACPI 6.4, s14.7 Referencing the PCC address space

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Add PCCT Generator
Pierre Gondois [Mon, 10 Oct 2022 09:20:55 +0000 (11:20 +0200)]
DynamicTablesPkg: Add PCCT Generator

The Platform Communication Channel Table (PCCT) generator collates
the relevant information required for generating a PCCT table from
configuration manager using the configuration manager protocol.
The DynamicTablesManager then install the PCCT table.

From ACPI 6.4, s14 PLATFORM COMMUNICATIONS CHANNEL (PCC):
  The platform communication channel (PCC) is a generic mechanism
  for OSPM to communicate with an entity in the platform.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Add PCCT related objects
Pierre Gondois [Mon, 10 Oct 2022 09:20:54 +0000 (11:20 +0200)]
DynamicTablesPkg: Add PCCT related objects

Introduce the following CmObj in the ArmNameSpaceObjects:
 - CM_ARM_MAILBOX_REGISTER_INFO
 - CM_ARM_PCC_SUBSPACE_CHANNEL_TIMING_INFO
 - CM_ARM_PCC_SUBSPACE_GENERIC_INFO
 - CM_ARM_PCC_SUBPSACE_TYPE0_INFO
 - CM_ARM_PCC_SUBPSACE_TYPE1_INFO
 - CM_ARM_PCC_SUBPSACE_TYPE2_INFO
 - CM_ARM_PCC_SUBPSACE_TYPE3_INFO
 - CM_ARM_PCC_SUBPSACE_TYPE4_INFO
 - CM_ARM_PCC_SUBPSACE_TYPE5_INFO

These objects allow to describe mailbox registers, pcc timings
and PCCT subspaces. They prepare the enablement of a PCCT generator.

Also add the CmObjParsers associated to each object.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Fix Ssdt PCI generation comments
Pierre Gondois [Mon, 10 Oct 2022 09:20:53 +0000 (11:20 +0200)]
DynamicTablesPkg: Fix Ssdt PCI generation comments

The second model of the _PRT object is used. Indeed:
- the interrupts described are not re-configurable
- OSes are aware of the polarity of PCI legacy interrupts,
  so there is no need to accurately describe the polarity.

Also, fix a comment for the CM_ARM_PCI_INTERRUPT_MAP_INFO obj.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: FdtHwInfoParserLib: Remove wrong comment
Pierre Gondois [Mon, 10 Oct 2022 09:20:52 +0000 (11:20 +0200)]
DynamicTablesPkg: FdtHwInfoParserLib: Remove wrong comment

commit 13136cc3111f ("DynamicTablesPkg: FdtHwInfoParserLib:
Parse Pmu info")
adds support for pmu parsing. Thus, remove the wrong comment.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Remove deprecated APIs
Pierre Gondois [Mon, 10 Oct 2022 09:20:51 +0000 (11:20 +0200)]
DynamicTablesPkg: Remove deprecated APIs

commit 691c5f776274 ("DynamicTablesPkg: Deprecate Crs specific methods
in AmlLib")
deprecates some APIs. Finally remove them.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Fix wrong/missing fields in CmObjParser
Pierre Gondois [Mon, 10 Oct 2022 09:20:50 +0000 (11:20 +0200)]
DynamicTablesPkg: Fix wrong/missing fields in CmObjParser

Add missing fields to the following CmObjParser objects:
- EArmObjGicDInfo
- EArmObjCacheInfo
and fix wrong formatting of:
- EArmObjLpiInfo

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Fix GTBlock and GTBlockTimerFrame CmObjParsers
Pierre Gondois [Mon, 10 Oct 2022 09:20:49 +0000 (11:20 +0200)]
DynamicTablesPkg: Fix GTBlock and GTBlockTimerFrame CmObjParsers

The CmObjParsers of the following objects was inverted, probably
due to a wrong ordering placement in the file defining the structures:
-EArmObjGTBlockTimerFrameInfo
-EArmObjPlatformGTBlockInfo

Assign the correct parser for each object, and re-order the
structures in the file defining them.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Update CmObjParser for MinorRevision
Pierre Gondois [Mon, 10 Oct 2022 09:20:48 +0000 (11:20 +0200)]
DynamicTablesPkg: Update CmObjParser for MinorRevision

commit 0d23c447d6f5 ("DynamicTablesPkg: Add support to specify FADT
minor revision")
adds new 'MinorRevision' field to CM_STD_OBJ_ACPI_TABLE_INFO.
Reflect the change in this patch to the CmObjectParser.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Update CmObjParser for IORT Rev E.d
Pierre Gondois [Mon, 10 Oct 2022 09:20:47 +0000 (11:20 +0200)]
DynamicTablesPkg: Update CmObjParser for IORT Rev E.d

commit de200b7e2c3c ("DynamicTablesPkg: Update ArmNameSpaceObjects for
IORT Rev E.d")
adds new CmObj structures and fields to the ArmNameSpaceObjects.
Update the CmObjectParser accordingly.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Add PrintString to CmObjParser
Pierre Gondois [Mon, 10 Oct 2022 09:20:46 +0000 (11:20 +0200)]
DynamicTablesPkg: Add PrintString to CmObjParser

Add a PrintString to print strings in the CmObjParser.
String must be NULL terminated and no buffer overrun check
is done by this function.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoDynamicTablesPkg: Use correct print formatter
Pierre Gondois [Mon, 10 Oct 2022 09:20:45 +0000 (11:20 +0200)]
DynamicTablesPkg: Use correct print formatter

In C, the 'long long' types are 64-bits. The 'll' printf length
specifier should be used to pring these values. Just '%x' allows to
print values that are on 16-bits or more. Use that instead.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
18 months agoMdeModulePkg/ScsiDiskDxe: Update proper device name for ScsiDisk drive
Cheripally Gopi [Wed, 26 Oct 2022 12:07:25 +0000 (17:37 +0530)]
MdeModulePkg/ScsiDiskDxe: Update proper device name for ScsiDisk drive

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4100

ScsiDiskDxe driver updates ControllerNameTable with common string
"SCSI Disk Device" for all SCSI disks. Due to this, when multiple
SCSI disk devices connected, facing difficulty in identifying correct SCSI
disk device. As per SCSI spec, standard Inquiry Data is having the fields
to know Vendor and Product information. Updated "ControllerNameTable" with
Vendor and Product information. So that, device specific name can be
retrieved using ComponentName protocol.

Cc: Vasudevan Sambandan <vasudevans@ami.com>
Cc: Sundaresan Selvaraj <sundaresans@ami.com>
Signed-off-by: Cheripally Gopi <gopic@ami.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
18 months agoUefiCpuPkg: Restore HpetTimer after CpuExceptionHandlerLib test
Tan, Dun [Fri, 28 Oct 2022 03:51:18 +0000 (11:51 +0800)]
UefiCpuPkg: Restore HpetTimer after CpuExceptionHandlerLib test

Disable/Restore HpetTimer before and after running the Dxe
CpuExceptionHandlerLib unit test module. During the UnitTest, a
new Idt is initialized for the test. There is no handler for timer
intrrupt in this new idt. After the test module, HpetTimer does
not work any more since the comparator value register and main
counter value register for timer does not match. To fix this issue,
disable/restore HpetTimer before and after Unit Test if HpetTimer
driver has been dispatched. We don't need to send Apic Eoi in this
unit test module.When disabling timer, after RaiseTPL(), if there
is a pending timer interrupt, bit64 of Interrupt Request Register
(IRR) will be set to 1 to indicate there is a pending timer
interrupt. After RestoreTPL(), CPU will handle the pending
interrupt in IRR.Then TimerInterruptHandler calls SendApicEoi().

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
18 months agoArmVirtPkg/ArmVirtKvmTool: Migrate to OVMF's VirtNorFlashDxe
Ard Biesheuvel [Mon, 24 Oct 2022 16:51:43 +0000 (18:51 +0200)]
ArmVirtPkg/ArmVirtKvmTool: Migrate to OVMF's VirtNorFlashDxe

Migrate to the virt specific NOR flash driver as the ArmPlatformPkg is
going away.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoArmVirtPkg/ArmVirtQemu: migrate to OVMF's VirtNorFlashDxe
Ard Biesheuvel [Mon, 24 Oct 2022 16:41:22 +0000 (18:41 +0200)]
ArmVirtPkg/ArmVirtQemu: migrate to OVMF's VirtNorFlashDxe

Switch to the virt specific NorFlashDxe driver implementation that was
added recently.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg/VirtNorFlashDxe: use EFI_MEMORY_WC and drop AlignedCopyMem()
Ard Biesheuvel [Mon, 24 Oct 2022 16:16:18 +0000 (18:16 +0200)]
OvmfPkg/VirtNorFlashDxe: use EFI_MEMORY_WC and drop AlignedCopyMem()

NOR flash emulation under KVM involves switching between two modes,
where array mode is backed by a read-only memslot, and programming mode
is fully emulated, i.e., the memory region is not backed by anything,
and the faulting accesses are forwarded to the VMM by the hypervisor,
which translates them into NOR flash programming commands.

Normally, we are limited to the use of device attributes when mapping
such regions, given that the programming mode has MMIO semantics.
However, when running under KVM, the chosen memory attributes only take
effect when in array mode, since no memory mapping exists otherwise.

This means we can tune the memory mapping so it behaves a bit more like
a ROM, by switching to EFI_MEMORY_WC attributes. This means we no longer
need a special CopyMem() implementation that avoids unaligned accesses
at all cost.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop
Ard Biesheuvel [Mon, 24 Oct 2022 15:58:07 +0000 (17:58 +0200)]
OvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop

Currently, when dealing with small updates that can be written out
directly (i.e., if they only involve clearing bits and not setting bits,
as the latter requires a block level erase), we iterate over the data
one word at a time, read the old value, compare it, write the new value,
and repeat, unless we encountered a value that we cannot write (0->1
transition), in which case we fall back to a block level operation.

This is inefficient for two reasons:
- reading and writing a word at a time involves switching between array
and programming mode for every word of data, which is
disproportionately costly when running under KVM;
- we end up writing some data twice, as we may not notice that a block
erase is needed until after some data has been written to flash.

So replace this sequence with a single read of up to twice the buffered
write maximum size, followed by one or two buffered writes if the data
can be written directly. Otherwise, fall back to the existing block
level sequence, but without writing out part of the data twice.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg/VirtNorFlashDxe: avoid array mode switch after each word write
Ard Biesheuvel [Mon, 24 Oct 2022 15:34:09 +0000 (17:34 +0200)]
OvmfPkg/VirtNorFlashDxe: avoid array mode switch after each word write

NorFlashWriteSingleWord() switches into programming mode and back into
array mode for every single word that it writes. Under KVM, this
involves tearing down the read-only memslot, and setting it up again,
which is costly and unnecessary.

Instead, move the array mode switch into the callers, and only make the
switch when the writing is done.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg/VirtNorFlashDxe: drop block I/O protocol implementation
Ard Biesheuvel [Mon, 24 Oct 2022 15:12:08 +0000 (17:12 +0200)]
OvmfPkg/VirtNorFlashDxe: drop block I/O protocol implementation

We never boot from NOR flash, and generally rely on the firmware volume
PI protocols to expose the contents. So drop the block I/O protocol
implementation from VirtNorFlashDxe.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg/VirtNorFlashDxe: remove disk I/O protocol implementation
Ard Biesheuvel [Mon, 24 Oct 2022 14:50:05 +0000 (16:50 +0200)]
OvmfPkg/VirtNorFlashDxe: remove disk I/O protocol implementation

We only use NOR flash for firmware volumes, either for executable images
or for the variable store. So we have no need for exposing disk I/O on
top of the NOR flash partitions so let's remove it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg/VirtNorFlashDxe: remove CheckBlockLocked feature
Ard Biesheuvel [Mon, 24 Oct 2022 14:45:02 +0000 (16:45 +0200)]
OvmfPkg/VirtNorFlashDxe: remove CheckBlockLocked feature

We inherited a feature from the ArmPlatformPkg version of this driver
that never gets enabled. Let's remove it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg/VirtNorFlashDxe: clone ArmPlatformPkg's NOR flash driver
Ard Biesheuvel [Mon, 24 Oct 2022 14:41:43 +0000 (16:41 +0200)]
OvmfPkg/VirtNorFlashDxe: clone ArmPlatformPkg's NOR flash driver

QEMU's mach-virt is loosely based on ARM Versatile Express, and inherits
its NOR flash driver, which is now being used on other QEMU emulated
architectures as well.

In order to permit ourselves the freedom to optimize this driver for
use under KVM emulation, let's clone it into OvmfPkg, so we have a
version we can hack without the risk of regressing bare metal platforms.

The cloned version is mostly identical to the original, but it depends
on the newly added VirtNorFlashPlatformLib library class instead of the
original one from ArmPlatformPkg. Beyond that, only cosmetic changes
related to #include order etc were made.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoOvmfPkg: clone NorFlashPlatformLib into VirtNorFlashPlatformLib
Ard Biesheuvel [Mon, 24 Oct 2022 16:35:10 +0000 (18:35 +0200)]
OvmfPkg: clone NorFlashPlatformLib into VirtNorFlashPlatformLib

Create a new library class in Ovmf that duplicates the existing
NorFlashPlatformLib, but which will be tied to the VirtNorFlashDxe
driver that will be introduced in a subsequent patch. This allows us to
retire the original from ArmPlatformPkg.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
18 months agoArmVirtPkg/ArmVirtQemu: Clear XIP flags instead of overriding them
Ard Biesheuvel [Wed, 26 Oct 2022 19:51:38 +0000 (21:51 +0200)]
ArmVirtPkg/ArmVirtQemu: Clear XIP flags instead of overriding them

Clang does not support undoing the effects of -mstrict-align by passing
the -mno-strict-align counterpart, so appending the latter to the
compiler's XIPFLAGS does not work. Instead, clear the flags entirely.

This also removes -mgeneral-regs-only, but this is fine - we can
tolerate SIMD codegen in PEIMs or BASE libraries as they run with the
MMU and caches enabled.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/ArmVirtQemu: omit PCD PEIM unless TPM support is enabled
Ard Biesheuvel [Sun, 25 Sep 2022 15:22:04 +0000 (17:22 +0200)]
ArmVirtPkg/ArmVirtQemu: omit PCD PEIM unless TPM support is enabled

The TPM discovery code relies on a dynamic PCD to communicate the TPM
base address to other components. But no other code relies on dynamic
PCDs in the PEI phase so let's drop the PCD PEIM when TPM support is not
enabled.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/QemuVirtMemInfoLib: use HOB not PCD to record the memory size
Ard Biesheuvel [Sun, 25 Sep 2022 14:53:27 +0000 (16:53 +0200)]
ArmVirtPkg/QemuVirtMemInfoLib: use HOB not PCD to record the memory size

Due to the way we inherited the formerly fixed PCDs to describe the
system memory base and size from ArmPlatformPkg, we ended up with a
MemoryInit PEIM that relies on dynamic PCDs to communicate the size of
system memory between the constructor of one of its library dependencies
and the core module. This is unnecessary, and forces us to incorporate
the PCD PEIM as well, for no good reason. So instead, let's use a HOB.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/ArmVirtQemu: avoid shadowing PEIMs unless necessary
Ard Biesheuvel [Sun, 25 Sep 2022 15:24:41 +0000 (17:24 +0200)]
ArmVirtPkg/ArmVirtQemu: avoid shadowing PEIMs unless necessary

Some PEIMs register for shadow execution explicitly, but others exist
that don't care and can happily execute in place. Since the emulated NOR
flash is just RAM, shadowing has no performance benefits so let's only
do this if needed.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/ArmVirtQemu: Drop unused variable PEIM
Ard Biesheuvel [Sun, 25 Sep 2022 14:02:36 +0000 (16:02 +0200)]
ArmVirtPkg/ArmVirtQemu: Drop unused variable PEIM

The variable PEIM is included in the build but its runtime prerequisites
are absent so it is never dispatched. Just drop it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/ArmVirtQemu: enable initial ID map at early boot
Ard Biesheuvel [Sat, 2 Jul 2022 17:27:37 +0000 (19:27 +0200)]
ArmVirtPkg/ArmVirtQemu: enable initial ID map at early boot

Now that we have all the pieces in place, switch the AArch64 version of
ArmVirtQemu to a mode where the first thing it does out of reset is
enable a preliminary ID map that covers the NOR flash and sufficient
DRAM to create the UEFI page tables as usual.

The advantage of this is that no manipulation of memory occurs any
longer before the MMU is enabled, which removes the need for explicit
coherency management, which is cumbersome and bad for performance.

It also means we no longer need to build all components that may execute
with the MMU off (including BASE libraries) with strict alignment.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory
Ard Biesheuvel [Sat, 2 Jul 2022 17:24:13 +0000 (19:24 +0200)]
ArmVirtPkg/ArmVirtQemu: use first 128 MiB as permanent PEI memory

In order to allow booting with the MMU and caches enabled really early,
we need to ensure that the code that populates the page tables can
access those page tables with the statically defined ID map active.

So let's put the permanent PEI RAM in the first 128 MiB of memory, which
we will cover with this initial ID map (as it is the minimum supported
DRAM size for ArmVirtQemu).

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/ArmVirtQemu: implement ArmPlatformLib with static ID map
Ard Biesheuvel [Sat, 2 Jul 2022 17:19:05 +0000 (19:19 +0200)]
ArmVirtPkg/ArmVirtQemu: implement ArmPlatformLib with static ID map

To substantially reduce the amount of processing that takes place with
the MMU and caches off, implement a version of ArmPlatformLib specific
for QEMU/mach-virt in AArch64 mode that carries a statically allocated
and populated ID map that covers the NOR flash and device region, and
128 MiB of DRAM at the base of memory (0x4000_0000).

Note that 128 MiB has always been the minimum amount of DRAM we support
for this configuration, and the existing code already ASSERT()s in DEBUG
mode when booting with less.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
18 months agoArmVirtPkg/ArmVirtQemu: wire up timeout PCD to Timeout variable
Ard Biesheuvel [Tue, 2 Aug 2022 16:53:51 +0000 (18:53 +0200)]
ArmVirtPkg/ArmVirtQemu: wire up timeout PCD to Timeout variable

Use the appropriate PCD definition in the ArmVirtQemu DSC so that the
boot timeout is taken from the Timeout variable automatically, which is
what Linux tools such as efibootmgr expect.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>