Date   

Re: [PATCH v3 1/8] IntelFsp2Pkg: X64 compatible changes to support PEI in 64bit

Ni, Ray
 

-; UINT32
+; UINTN
; EFIAPI
-; AsmReadEsp (
+; AsmReadStackPointer (
; VOID
; );
;------------------------------------------------------------------------------
-global ASM_PFX(AsmReadEsp)
-ASM_PFX(AsmReadEsp):
+global ASM_PFX(AsmReadStackPointer)
+ASM_PFX(AsmReadStackPointer):
mov eax, esp
ret
I guess it's possible that bootloader sets up the stack above 4G.
If that's the case, above code doesn't work.


Re: [PATCH v2 0/3] BaseTools: Add support for gdb and lldb

Rebecca Cran
 

Could I have some more reviews on this please? I'd like to get this into the tree soon.

--
Rebecca Cran

On 3/21/22 14:20, Rebecca Cran wrote:
This patch set adds debugging support for gdb and lldb.
It also adds generic debugging classes that use a file like object to
make it easy to import into any debugger that supports Python.

Changes from v1 to v2:
- Moved scripts from the root of the repo into BaseTools/Scripts.
- Fixed typo of "RISCV" as "RISKV".

Testing:
- Tested gdb on Ubuntu and lldb on macOS for IA32 and X64.
- Tested gdb on openSUSE for AARCH64.

Rebecca Cran (3):
BaseTools: efi_debugging.py: Add debugger agnostic dbg Python Classes
BaseTools: Scripts/efi_gdb.py: Add gdb EFI commands and pretty Print
BaseTools: Scripts/efi_lldb.py: Add lldb EFI commands and pretty Print

BaseTools/Scripts/efi_debugging.py | 2185 ++++++++++++++++++++
BaseTools/Scripts/efi_gdb.py | 918 ++++++++
BaseTools/Scripts/efi_lldb.py | 1044 ++++++++++
3 files changed, 4147 insertions(+)
create mode 100755 BaseTools/Scripts/efi_debugging.py
create mode 100755 BaseTools/Scripts/efi_gdb.py
create mode 100755 BaseTools/Scripts/efi_lldb.py


Re: Applying for GSoC 2022: Add Rust Support to EDK II

Pedro Falcato
 

Hi Ayush!

I had a decent look at your proposal, and I have some questions (note that you can always re-submit proposals until April 19th):

1) How are you planning to reconcile the cargo build system with EDK2's build system?

2) If you go ahead with cargo, will the new Rust code require a lot of tiny crates? I'm personally not very enthusiastic about having lots of dependencies all over the place,
especially somewhere Tianocore doesn't control. I've seen Rust crates that were integrated into an operating system (https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/third_party/rust_crates/),
where they essentially maintain their own versions of the crate, with the "proper" build system that the project uses.

3) How much of std are you going to implement? Note that traditionally, EDK2, like a lot of this firmware/kernel/bootloader code, doesn't actually implement much of the standard library (and that's the reasoning behind edk2-libc).

4) Do you have any idea of what DXE driver you're going to implement? Do you have any experience writing drivers?

5) Any plans for generation of C <-> Rust bindings? Does https://github.com/rust-lang/rust-bindgen work out of the box?

Best regards,
Pedro 

On Mon, Apr 4, 2022 at 6:18 PM Ayush Singh <ayushdevel1325@...> wrote:
Hello everyone, I am a 2nd-year University Student from India. I am
interested in applying for adding Rust support to EDK2. I have already
introduced myself to the mailing list earlier
(https://edk2.groups.io/g/devel/message/87637) and have even submitted
some patches for the edkii-rust branch in edk2-staging (which were not
merged since that branch seems to be abandoned now).
- https://edk2.groups.io/g/devel/message/87753
- https://edk2.groups.io/g/devel/message/87754
- https://edk2.groups.io/g/devel/message/87755
- https://edk2.groups.io/g/devel/message/87756

Anyway, since no mentor has been listed for this project, I was
wondering who should I discuss the proposal with? Normally, I think
one is supposed to discuss the proposal details with a mentor in form
of a google doc or something before submitting an application. So
should I directly start by submitting a proposal through the GSoC
application portal? Or is there someone I should contact first?

Ayush Singh







--
Pedro Falcato


Re: [edk2-platforms PATCH] Marvell/SolidRun: Rework Readme.md files

Marcin Wojtas
 

Hi,

pon., 14 mar 2022 o 18:17 Sunny Wang <Sunny.Wang@...> napisał(a):

Looks good. Thanks much, Marcin.

This will be helpful as http://wiki.macchiatobin.net/tiki-index.php has been not accessible for quite a while.

Reviewed-by: Sunny Wang <sunny.wang@...>
Do you have any feedback about the patch?

Best regards,
Marcin

Best Regards,
Sunny
-----Original Message-----
From: Marcin Wojtas <mw@...>
Sent: 14 March 2022 12:06
To: devel@edk2.groups.io
Cc: quic_llindhol@...; ardb+tianocore@...; jaz@...; gjb@...; Sunny Wang <Sunny.Wang@...>; Marcin Wojtas <mw@...>
Subject: [edk2-platforms PATCH] Marvell/SolidRun: Rework Readme.md files

From: Grzegorz Bernacki <gjb@...>

This patch reworks Readme.md files of Marvell and SolidRun
platforms as follows:
* Add supported features list.
* Leave minmal EDK2 build command.
* Add 'NOTE' box about INCLUDE_TFTP_COMMAND build flag.
* Move full firmware image build/burn howtos to external wiki pages.
* Add links and update paragraphs.

Signed-off-by: Marcin Wojtas <mw@...>

---
In order to ease review/merge the patch is available in a public repository:
https://github.com/Semihalf/edk2-platforms/commits/marvell-howtos-upstream-r20220314

Platform/Marvell/Cn913xDb/Readme.md | 104 +++++++-----------
Platform/SolidRun/Armada80x0McBin/Readme.md | 113 ++++++++------------
Platform/SolidRun/Cn913xCEx7Eval/Readme.md | 109 ++++++++-----------
3 files changed, 124 insertions(+), 202 deletions(-)

diff --git a/Platform/Marvell/Cn913xDb/Readme.md b/Platform/Marvell/Cn913xDb/Readme.md
index ecdb78302b..0b2ab676f8 100644
--- a/Platform/Marvell/Cn913xDb/Readme.md
+++ b/Platform/Marvell/Cn913xDb/Readme.md
@@ -5,93 +5,65 @@


This is a port of 64-bit TianoCore EDK II firmware for the Marvell CN913x Development Board.



-# Building the firmware

-

-## Prepare toolchain (for cross-compilation only):

-

-1. Download the toolchain:

-

- ```

- wget https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz

- ```

+# Supported features



-1. After extracting, setup the path and compiler prefix to GCC5\_AARCH64\_PREFIX variable:

+Features supported in EDK2:



- ```

- export GCC5_AARCH64_PREFIX=<toolchain_path>/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

- ```

+* 1x PCIE root complex

+* Networking:

+ * 3x 10 GbE via SFP+

+ * 2x 1 GbE RGMII via RJ45

+* 5x USB 2.0/3.0

+* 3x SATA

+* 2x uSD

+* 1x eMMC

+* RTC

+* SPI flash & memory-mapped variable storage access

+* I2C

+* GPIO



-## Prepare prerequisites

+Hardware description:



-1. Create a new folder (directory) on your local development machine

- for use as your workspace. This example uses `/work/git/tianocore`, modify as

- appropriate for your needs.

+* ACPI (default)

+* Device Tree



- ```

- $ export WORKSPACE=/work/git/tianocore

- $ mkdir -p $WORKSPACE

- $ cd $WORKSPACE

- ```

+Others:



-1. Clone the Trusted Firmware repository:

+* Signed capsule update

+* X64 option ROM emulator



- ```

- $ cd ${WORKSPACE}

- $ git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git

- ```

-1. Clone repository for auxiliary firmware on the SoC co-processors and checkout to binaries-marvell-armada-SDK10.0.1.0:

-

- ```

- $ cd ${WORKSPACE}

- $ git clone https://github.com/MarvellEmbeddedProcessors/binaries-marvell.git

- $ cd binaries-marvell/

- $ git checkout -b binaries-marvell-armada-SDK10.0.1.0 origin/binaries-marvell-armada-SDK10.0.1.0

- ```

-1. Clone the DDR training code from:

+# Building the firmware



- ```

- $ cd ${WORKSPACE}

- $ git clone https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell.git

- ```

## Prepare EDKII environment:



-Please follow instructions from "Obtaining source code" and "Manual building" from the top level edk2-platforms [Readme.md](https://github.com/tianocore/edk2-platforms#readme).

+Please follow instructions from [Obtaining source code](https://github.com/tianocore/edk2-platforms#obtaining-source-code)

+and [Manual building](https://github.com/tianocore/edk2-platforms#manual-building) from the

+top level edk2-platforms [Readme.md](https://github.com/tianocore/edk2-platforms#readme).



## Build EDKII:



-1. Use below build command:

+Use below build command:



- ```

- $ cd ${WORKSPACE}

- $ build -a AARCH64 -t GCC5 -b RELEASE -D CN9132 -D INCLUDE_TFTP_COMMAND -D CAPSULE_ENABLE -p Platform/Marvell/Cn913xDb/Cn913xDbA.dsc

- ```

+ ```

+ $ build -a AARCH64 -t GCC5 -b RELEASE -D CN9132 -D CAPSULE_ENABLE -D X64EMU_ENABLE -p Platform/Marvell/Cn913xDb/Cn913xDbA.dsc

+ ```



-## Build the final firmware image:

+---

+**NOTE**



-1. Set BL33 variable to path to EDK II output binary:

+'-D INCLUDE_TFTP_COMMAND' is optional and can be added in order to enable `tftp` command in UEFI Shell.



- ```

- $ export BL33=${WORKSPACE}/Build/Cn9132DbA-AARCH64/RELEASE_GCC5/FV/ARMADA_EFI.fd

- ```

-1. Export SCP_BL2 variable:

+---



- ```

- $ export SCP_BL2=${WORKSKPACE}/binaries-marvell/mrvl_scp_bl2.img

- ```

-1. Export compiler variables (for cross-compilation only):

+## Build the final firmware image:



- ```

- $ export ARCH=arm64

- $ export CROSS_COMPILE=<toolchain_path>/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

- ```

-1. Build the image:

+In addition to EDKII binary, the complete firmware image comprises the TF-A and other components.

+A complete build instruction can be found at [wiki page](https://github.com/Semihalf/edk2-platforms/wiki/Build_firmware).



- ```

- $ cd ${WORKSPACE}/trusted-firmware-a/

- $ make LOG_LEVEL=20 MV_DDR_PATH=${WORKSPACE}/mv-ddr-marvell CP_NUM=3 PLAT=t9130 all fip mrvl_flash

+## Burning the firmware



- ```

-The firmware image `flash-image.bin` can be found in `build/t9130/release/` directory.

+Please follow instruction at [wiki page](https://github.com/Semihalf/edk2-platforms/wiki/Burning_firmware)

+to burn image to desired boot device.



# ARM System Ready certification.



diff --git a/Platform/SolidRun/Armada80x0McBin/Readme.md b/Platform/SolidRun/Armada80x0McBin/Readme.md
index c63cf41b2d..8c514835c4 100644
--- a/Platform/SolidRun/Armada80x0McBin/Readme.md
+++ b/Platform/SolidRun/Armada80x0McBin/Readme.md
@@ -3,94 +3,69 @@


# Summary



-This is a port of 64-bit TianoCore EDK II firmware for the SolidRun MacchiatoBin platform based on the Marvell ARMADA 8040 SoC.

+This is a port of 64-bit TianoCore EDK II firmware for the [SolidRun MacchiatoBin Double Shot](https://solidrun.atlassian.net/wiki/spaces/developer/pages/286655749/MACCHIATObin+Single+Double+Shot+Quick+Start+Guide)

+platform based on the Marvell ARMADA 8040 SoC.



-# Building the firmware

+# Supported features



-## Prepare toolchain (for cross-compilation only):

+Features supported in EDK2:



-1. Download the toolchain:

+* 1x PCIE x4

+* Networking:

+ * 2x 10 GbE via SFP+ / RJ45

+ * 1x 2500 Base-X via SFP+

+ * 1x 1 GbE SGMII via RJ45

+* 1x USB 3.0

+* 2x USB 2.0

+* 3x SATA

+* 1x uSD

+* 1x eMMC

+* RTC

+* SPI flash & memory-mapped variable storage access

+* GPIO



- ```

- wget https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz

- ```

+Hardware description:



-1. After extracting, setup the path and compiler prefix to GCC5\_AARCH64\_PREFIX variable:

+* ACPI (default)

+* Device Tree



- ```

- export GCC5_AARCH64_PREFIX=<toolchain_path>/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

- ```

+Others:



-## Prepare prerequisites

+* Signed capsule update

+* X64 option ROM emulator



-1. Create a new folder (directory) on your local development machine

- for use as your workspace. This example uses `/work/git/tianocore`, modify as

- appropriate for your needs.

+# Building the firmware



- ```

- $ export WORKSPACE=/work/git/tianocore

- $ mkdir -p $WORKSPACE

- $ cd $WORKSPACE

- ```

+## Prepare EDKII environment:



-1. Clone the Trusted Firmware repository:

+Please follow instructions from [Obtaining source code](https://github.com/tianocore/edk2-platforms#obtaining-source-code)

+and [Manual building](https://github.com/tianocore/edk2-platforms#manual-building) from the

+top level edk2-platforms [Readme.md](https://github.com/tianocore/edk2-platforms#readme).



- ```

- $ cd ${WORKSPACE}

- $ git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git

- ```

-1. Clone repository for auxiliary firmware on the SoC co-processors and checkout to binaries-marvell-armada-SDK10.0.1.0:

+## Build EDKII:



- ```

- $ cd ${WORKSPACE}

- $ git clone https://github.com/MarvellEmbeddedProcessors/binaries-marvell.git

- $ cd binaries-marvell/

- $ git checkout -b binaries-marvell-armada-SDK10.0.1.0 origin/binaries-marvell-armada-SDK10.0.1.0

- ```

-1. Clone the DDR training code from:

+Use below build command:



- ```

- $ cd ${WORKSPACE}

- $ git clone https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell.git

- ```

-## Prepare EDKII environment:

+ ```

+ $ build -a AARCH64 -t GCC5 -b RELEASE -D X64EMU_ENABLE -p Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc

+ ```



-Please follow instructions from "Obtaining source code" and "Manual building" from the top level edk2-platforms [Readme.md](https://github.com/tianocore/edk2-platforms#readme).

+---

+**NOTE**



-## Build EDKII:

-

-1. Use below build command:

+'-D INCLUDE_TFTP_COMMAND' is optional and can be added in order to enable `tftp` command in UEFI Shell.



- ```

- $ cd ${WORKSPACE}

- $ build -a AARCH64 -t GCC5 -b RELEASE -D INCLUDE_TFTP_COMMAND -D X64EMU_ENABLE -p Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc

- ```

+---



## Build the final firmware image:



-1. Set BL33 variable to path to EDK II output binary:

-

- ```

- $ export BL33=${WORKSPACE}/Build/Armada80x0McBin-AARCH64/RELEASE_GCC5/FV/ARMADA_EFI.fd

- ```

-1. Export SCP_BL2 variable:

-

- ```

- $ export SCP_BL2=${WORKSKPACE}/binaries-marvell/mrvl_scp_bl2.img

- ```

-1. Export compiler variables (for cross-compilation only):

-

- ```

- $ export ARCH=arm64

- $ export CROSS_COMPILE=<toolchain_path>/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

- ```

-1. Build the image:

-

- ```

- $ cd ${WORKSPACE}/trusted-firmware-a/

- $ make LOG_LEVEL=20 MV_DDR_PATH=${WORKSPACE}/mv-ddr-marvell PLAT=a80x0_mcbin all fip mrvl_flash

- ```

-The firmware image `flash-image.bin` can be found in `build/a80x0_mcbin/release/` directory.

+In addition to EDKII binary, the complete firmware image comprises the TF-A and other components.

+A complete build instruction can be found at [wiki page](https://github.com/Semihalf/edk2-platforms/wiki/Build_firmware).

+

+## Burning the firmware

+

+Please follow instruction at [wiki page](https://github.com/Semihalf/edk2-platforms/wiki/Burning_firmware)

+to burn image to desired boot device.



# ARM System Ready certification.



diff --git a/Platform/SolidRun/Cn913xCEx7Eval/Readme.md b/Platform/SolidRun/Cn913xCEx7Eval/Readme.md
index 813e723b65..0db22b5175 100644
--- a/Platform/SolidRun/Cn913xCEx7Eval/Readme.md
+++ b/Platform/SolidRun/Cn913xCEx7Eval/Readme.md
@@ -3,95 +3,70 @@


# Summary



-This is a port of 64-bit TianoCore EDK II firmware for the SolidRun CN913x CEx7 Evaluation Board.

+This is a port of 64-bit TianoCore EDK II firmware for the [SolidRun CN913x CEx7 Evaluation Board](https://solidrun.atlassian.net/wiki/spaces/developer/pages/197493948/CN9132+COM+EVK+Quick+Start+Guide).



-# Building the firmware

-

-## Prepare toolchain (for cross-compilation only):

-

-1. Download the toolchain:

-

- ```

- wget https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz

- ```

+# Supported features



-1. After extracting, setup the path and compiler prefix to GCC5\_AARCH64\_PREFIX variable:

+Features supported in EDK2:



- ```

- export GCC5_AARCH64_PREFIX=<toolchain_path>/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

- ```

+* 1x PCIE x4 + 6x PCIE x1

+* Networking:

+ * 1x 10 GbE via SFP+

+ * 2x 5 GbE via RJ45

+ * 1x 2500 Base-X via quad 1 Gbps switch

+ * 1x 1 GbE RGMII via RJ45

+* 2x USB 3.0

+* 4x USB 2.0

+* 2x SATA

+* 1x uSD

+* 1x eMMC

+* RTC

+* SPI flash & memory-mapped variable storage access

+* I2C

+* GPIO



-## Prepare prerequisites

+Hardware description:



-1. Create a new folder (directory) on your local development machine

- for use as your workspace. This example uses `/work/git/tianocore`, modify as

- appropriate for your needs.

+* ACPI (default)

+* Device Tree



- ```

- $ export WORKSPACE=/work/git/tianocore

- $ mkdir -p $WORKSPACE

- $ cd $WORKSPACE

- ```

+Others:



-1. Clone the Trusted Firmware repository:

+* Signed capsule update

+* X64 option ROM emulator



- ```

- $ cd ${WORKSPACE}

- $ git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git

- ```

-1. Clone repository for auxiliary firmware on the SoC co-processors and checkout to binaries-marvell-armada-SDK10.0.1.0:

-

- ```

- $ cd ${WORKSPACE}

- $ git clone https://github.com/MarvellEmbeddedProcessors/binaries-marvell.git

- $ cd binaries-marvell/

- $ git checkout -b binaries-marvell-armada-SDK10.0.1.0 origin/binaries-marvell-armada-SDK10.0.1.0

- ```

-1. Clone the DDR training code from:

+# Building the firmware



- ```

- $ cd ${WORKSPACE}

- $ git clone https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell.git

- ```

## Prepare EDKII environment:



-Please follow instructions from "Obtaining source code" and "Manual building" from the top level edk2-platforms [Readme.md](https://github.com/tianocore/edk2-platforms#readme).

+Please follow instructions from [Obtaining source code](https://github.com/tianocore/edk2-platforms#obtaining-source-code)

+and [Manual building](https://github.com/tianocore/edk2-platforms#manual-building) from the

+top level edk2-platforms [Readme.md](https://github.com/tianocore/edk2-platforms#readme).



## Build EDKII:



-1. Use below build command:

+Use below build command:



- ```

- $ cd ${WORKSPACE}

- $ build -a AARCH64 -t GCC5 -b RELEASE -D INCLUDE_TFTP_COMMAND -D CAPSULE_ENABLE -D X64EMU_ENABLE -p Platform/SolidRun/Cn913xCEx7Eval/Cn913xCEx7Eval.dsc

- ```

+ ```

+ build -a AARCH64 -t GCC5 -b RELEASE -D CAPSULE_ENABLE -D X64EMU_ENABLE -p Platform/SolidRun/Cn913xCEx7Eval/Cn913xCEx7Eval.dsc

+ ```



-## Build the final firmware image:

+---

+**NOTE**



-1. Set BL33 variable to path to EDK II output binary:

+'-D INCLUDE_TFTP_COMMAND' is optional and can be added in order to enable `tftp` command in UEFI Shell.



- ```

- $ export BL33=${WORKSPACE}/Build/Cn913xCEx7Eval-AARCH64/RELEASE_GCC5/FV/ARMADA_EFI.fd

- ```

-1. Export SCP_BL2 variable:

+---



- ```

- $ export SCP_BL2=${WORKSKPACE}/binaries-marvell/mrvl_scp_bl2.img

- ```

-1. Export compiler variables (for cross-compilation only):

+## Build the final firmware image:



- ```

- $ export ARCH=arm64

- $ export CROSS_COMPILE=<toolchain_path>/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

- ```

-1. Build the image:

+In addition to EDKII binary, the complete firmware image comprises the TF-A and other components.

+A complete build instruction can be found at [wiki page](https://github.com/Semihalf/edk2-platforms/wiki/Build_firmware).



- ```

- $ cd ${WORKSPACE}/trusted-firmware-a/

- $ make LOG_LEVEL=20 MV_DDR_PATH=${WORKSPACE}/mv-ddr-marvell CP_NUM=3 PLAT=t9130_cex7_eval all fip mrvl_flash

+## Burning the firmware



- ```

-The firmware image `flash-image.bin` can be found in `build/t9130_cex7_eval/release/` directory.

+Please follow instruction at [wiki page](https://github.com/Semihalf/edk2-platforms/wiki/Burning_firmware)

+to burn image to desired boot device.



# ARM System Ready certification.



--
2.29.0

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


Re: [edk2-platforms PATCH 0/8] Marvell Pp2Dxe fixes

Marcin Wojtas
 

Hi,


pon., 14 mar 2022 o 16:38 Marcin Wojtas <mw@...> napisał(a):

Hi,

ES ACS v1.0 test suite (https://github.com/ARM-software/arm-systemready)
unveiled a number of issues in Pp2Dxe SNP callbacks.
This patchset fixes all of them and allow for
successful SCT tests run.

For convenience, the patches are exposed on a public branch:
https://github.com/semihalf-wojtas-marcin/edk2-platforms/commits/pp2dxe-upstream-r20220314

Any comments or remarks would be welcome.

Best regards,
Marcin

Marcin Wojtas (8):
Marvell/Drivers: Pp2Dxe: Fix Pp2SnpShutdown
Marvell/Drivers: Pp2Dxe: Fix Pp2SnpReceiveFilters
Marvell/Drivers: Pp2Dxe: Fix Pp2SnpStart & Pp2SnpStop
Marvell/Drivers: Pp2Dxe: Implement Pp2SnpIpToMac
Marvell/Drivers: Pp2Dxe: Fix Pp2SnpGetStatus
Marvell/Drivers: Pp2Dxe: Fix Pp2SnpTransmit
Marvell/Drivers: Pp2Dxe: Fix Pp2SnpReset
Marvell/Drivers: Pp2Dxe: Fix Pp2SnpReceive

Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c | 333 ++++++++++++++++++--
1 file changed, 299 insertions(+), 34 deletions(-)
Do you have any feedback about the patchset?

Best regards,
Marcin


Re: [PATCH v2] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Peter Grehan
 

[re-posting from my personal email account, since my mail to > freebsd-virtualization got rejected]> > I seem to remember seeing
previous feedback that Bhyve developers > strongly preferred the BhyveFwCtl mechanism. I've been out of the loop > though (busy with $dayjob) so I don't know if things have changed. > Hopefully other people can provide feedback.
I'm fine with phasing out BhyveFwCtl, so long as backwards compat is maintained.

later,

Peter.


edk2-libc Python Build issue

M.T.
 

Hello

I am trying to build the Python environment for UEFI as per Py368ReadMe.txt.
I am doing this on Ubuntu 20.04.4 LTS with GCC5 for X64, all instructions seem to be meant for windows and MSFT.
I was able to build everything else and verify that it works, so I don't see why this should be an issue, but I am running into several issues.

Initial error is missing Python.h.
The path to AppPkg/Applications/Python/Python-3.6.8/Include seems to be missing from the build command, I was able to fix that by modifying Python368.inf and under BuildOptions, adding: 
GCC:*_*_*_CC_FLAGS = -I$(WORKSPACE)/AppPkg/Applications/Python/Python-3.6.8/Include
However this then results in other errors such as unused functions - fixed with -Wno-unused-functions added to the same line above, and then finally redfinitions.

Is the build process of Python 3.6.8 documented anywhere that might help me out, or if someone could point me in the right direction, that would be greatly appreciated.

Thank you
xp


Re: [PATCH v2] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Rebecca Cran
 

[re-posting from my personal email account, since my mail to freebsd-virtualization got rejected]

I seem to remember seeing previous feedback that Bhyve developers strongly preferred the BhyveFwCtl mechanism. I've been out of the loop though (busy with $dayjob) so I don't know if things have changed. Hopefully other people can provide feedback.

--
Rebecca Cran

On 4/6/22 01:00, Corvin Köhne wrote:
Any comments from bhyve folks on that?


Best regards
Corvin

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075


-----Original Message-----
From: Corvin Köhne <C.Koehne@...>
Sent: Tuesday, March 29, 2022 12:14 PM
Cc: Corvin Köhne <C.Koehne@...>; Corvin Köhne <C.Koehne@...>; Ard Biesheuvel <ardb+tianocore@...>; Jiewen Yao <jiewen.yao@...>; Jordan Justen <jordan.l.justen@...>; Rebecca Cran <rebecca@...>; Peter Grehan <grehan@...>; devel@edk2.groups.io; FreeBSD Virtualization <freebsd-virtualization@...>; Gerd Hoffmann <kraxel@...>
Subject: [PATCH v2] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

From: Corvin Köhne <CorvinK@...>

QemuFwCfg is much more powerful than BhyveFwCtl. Sadly, BhyveFwCtl
decided to use the same IO ports as QemuFwCfg. It's not possible to use
both interfaces simultaneously. So, prefer QemuFwCfg over BhyveFwCtl.

Signed-off-by: Corvin Köhne <c.koehne@...>
Acked-by: Gerd Hoffmann <kraxel@...>
CC: Ard Biesheuvel <ardb+tianocore@...>
CC: Jiewen Yao <jiewen.yao@...>
CC: Jordan Justen <jordan.l.justen@...>
CC: Rebecca Cran <rebecca@...>
CC: Peter Grehan <grehan@...>
CC: devel@edk2.groups.io
CC: FreeBSD Virtualization <freebsd-virtualization@...>
---
OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 +
OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c | 41 ++++++++++++++++++++---
OvmfPkg/Bhyve/BhyveX64.dsc | 4 +--
3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 595fd055f9..94c65f32dc 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -43,6 +43,7 @@
MemoryAllocationLib
OrderedCollectionLib
PcdLib
+ QemuFwCfgLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
index 8e80aa33e1..e216a21bfa 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
@@ -11,6 +11,41 @@
#include <Library/BaseMemoryLib.h>
#include <Library/BhyveFwCtlLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/QemuFwCfgLib.h> // QemuFwCfgFindFile()
+
+STATIC
+EFI_STATUS
+EFIAPI
+BhyveGetCpuCount (
+ OUT UINT32 *CpuCount
+ )
+{
+ FIRMWARE_CONFIG_ITEM Item;
+ UINTN Size;
+
+ if (QemuFwCfgIsAvailable ()) {
+ if (EFI_ERROR (QemuFwCfgFindFile ("opt/bhyve/hw.ncpu", &Item, &Size))) {
+ return EFI_NOT_FOUND;
+ } else if (Size != sizeof (*CpuCount)) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ QemuFwCfgSelectItem (Item);
+ QemuFwCfgReadBytes (Size, CpuCount);
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // QemuFwCfg not available, try BhyveFwCtl.
+ //
+ Size = sizeof (*CpuCount);
+ if (BhyveFwCtlGet ("hw.ncpu", CpuCount, &Size) == RETURN_SUCCESS) {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_UNSUPPORTED;
+}

STATIC
EFI_STATUS
@@ -23,7 +58,6 @@ BhyveInstallAcpiMadtTable (
)
{
UINT32 CpuCount;
- UINTN cSize;
UINTN NewBufferSize;
EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;
@@ -36,9 +70,8 @@ BhyveInstallAcpiMadtTable (
ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));

// Query the host for the number of vCPUs
- CpuCount = 0;
- cSize = sizeof (CpuCount);
- if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) {
+ Status = BhyveGetCpuCount (&CpuCount);
+ if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));
ASSERT (CpuCount >= 1);
} else {
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 5fa08bebd7..14070fd6dd 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -163,8 +163,7 @@
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf
- QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf
- QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf
BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
@@ -355,6 +354,7 @@
!endif
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf
+ QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf

[LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
--
2.11.0

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075







Re: [PATCH v2] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Rebecca Cran
 

I seem to remember seeing previous feedback that Bhyve developers strongly preferred the BhyveFwCtl mechanism. I've been out of the loop though (busy with $dayjob) so I don't know if things have changed. Hopefully other people can provide feedback.

--
Rebecca Cran

On 4/6/22 01:00, Corvin Köhne wrote:
Any comments from bhyve folks on that?


Best regards
Corvin

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075


-----Original Message-----
From: Corvin Köhne <C.Koehne@...>
Sent: Tuesday, March 29, 2022 12:14 PM
Cc: Corvin Köhne <C.Koehne@...>; Corvin Köhne <C.Koehne@...>; Ard Biesheuvel <ardb+tianocore@...>; Jiewen Yao <jiewen.yao@...>; Jordan Justen <jordan.l.justen@...>; Rebecca Cran <rebecca@...>; Peter Grehan <grehan@...>; devel@edk2.groups.io; FreeBSD Virtualization <freebsd-virtualization@...>; Gerd Hoffmann <kraxel@...>
Subject: [PATCH v2] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

From: Corvin Köhne <CorvinK@...>

QemuFwCfg is much more powerful than BhyveFwCtl. Sadly, BhyveFwCtl
decided to use the same IO ports as QemuFwCfg. It's not possible to use
both interfaces simultaneously. So, prefer QemuFwCfg over BhyveFwCtl.

Signed-off-by: Corvin Köhne <c.koehne@...>
Acked-by: Gerd Hoffmann <kraxel@...>
CC: Ard Biesheuvel <ardb+tianocore@...>
CC: Jiewen Yao <jiewen.yao@...>
CC: Jordan Justen <jordan.l.justen@...>
CC: Rebecca Cran <rebecca@...>
CC: Peter Grehan <grehan@...>
CC: devel@edk2.groups.io
CC: FreeBSD Virtualization <freebsd-virtualization@...>
---
OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 +
OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c | 41 ++++++++++++++++++++---
OvmfPkg/Bhyve/BhyveX64.dsc | 4 +--
3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 595fd055f9..94c65f32dc 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -43,6 +43,7 @@
MemoryAllocationLib
OrderedCollectionLib
PcdLib
+ QemuFwCfgLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
index 8e80aa33e1..e216a21bfa 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
@@ -11,6 +11,41 @@
#include <Library/BaseMemoryLib.h>
#include <Library/BhyveFwCtlLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/QemuFwCfgLib.h> // QemuFwCfgFindFile()
+
+STATIC
+EFI_STATUS
+EFIAPI
+BhyveGetCpuCount (
+ OUT UINT32 *CpuCount
+ )
+{
+ FIRMWARE_CONFIG_ITEM Item;
+ UINTN Size;
+
+ if (QemuFwCfgIsAvailable ()) {
+ if (EFI_ERROR (QemuFwCfgFindFile ("opt/bhyve/hw.ncpu", &Item, &Size))) {
+ return EFI_NOT_FOUND;
+ } else if (Size != sizeof (*CpuCount)) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ QemuFwCfgSelectItem (Item);
+ QemuFwCfgReadBytes (Size, CpuCount);
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // QemuFwCfg not available, try BhyveFwCtl.
+ //
+ Size = sizeof (*CpuCount);
+ if (BhyveFwCtlGet ("hw.ncpu", CpuCount, &Size) == RETURN_SUCCESS) {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_UNSUPPORTED;
+}

STATIC
EFI_STATUS
@@ -23,7 +58,6 @@ BhyveInstallAcpiMadtTable (
)
{
UINT32 CpuCount;
- UINTN cSize;
UINTN NewBufferSize;
EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;
@@ -36,9 +70,8 @@ BhyveInstallAcpiMadtTable (
ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));

// Query the host for the number of vCPUs
- CpuCount = 0;
- cSize = sizeof (CpuCount);
- if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) {
+ Status = BhyveGetCpuCount (&CpuCount);
+ if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));
ASSERT (CpuCount >= 1);
} else {
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 5fa08bebd7..14070fd6dd 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -163,8 +163,7 @@
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf
- QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf
- QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf
BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
@@ -355,6 +354,7 @@
!endif
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf
+ QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf

[LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
--
2.11.0

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075







[PATCH v3 8/8] IntelFsp2WrapperPkg: SecFspWrapperPlatformSecLibSample support for X64

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
1.Added SecFspWrapperPlatformSecLibSample support for X64.
2.Adopted FSPT_ARCH2_UPD in SecFspWrapperPlatformSecLibSample.
3.Moved Fsp.h up one level to be shared across IA32 and X64.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
.../{Ia32 => }/Fsp.h | 0
.../Ia32/Stack.nasm | 6 +-
.../SecFspWrapperPlatformSecLibSample.inf | 7 +-
.../SecRamInitData.c | 22 +--
.../X64/PeiCoreEntry.nasm | 149 ++++++++++++++++++
.../X64/SecEntry.nasm | 171 +++++++++++++++++++++
.../X64/Stack.nasm | 73 +++++++++
7 files changed, 415 insertions(+), 13 deletions(-)
rename IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/{Ia32 => }/Fsp.h (100%)
create mode 100644 IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/PeiCoreEntry.nasm
create mode 100644 IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/SecEntry.nasm
create mode 100644 IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/Stack.nasm

diff --git a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Ia32/Fsp.h b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Fsp.h
similarity index 100%
rename from IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Ia32/Fsp.h
rename to IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Fsp.h
diff --git a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Ia32/Stack.nasm b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Ia32/Stack.nasm
index d7394cf286..65e9c2e895 100644
--- a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Ia32/Stack.nasm
+++ b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/Ia32/Stack.nasm
@@ -22,7 +22,7 @@
global ASM_PFX(SecSwitchStack)
ASM_PFX(SecSwitchStack):
;
- ; Save three register: eax, ebx, ecx
+ ; Save four register: eax, ebx, ecx, edx
;
push eax
push ebx
@@ -55,7 +55,7 @@ ASM_PFX(SecSwitchStack):
mov dword [eax + 12], edx
mov edx, dword [esp + 16] ; Update this function's return address into permanent memory
mov dword [eax + 16], edx
- mov esp, eax ; From now, esp is pointed to permanent memory
+ mov esp, eax ; From now, esp is pointed to permanent memory

;
; Fixup the ebp point to permanent memory
@@ -63,7 +63,7 @@ ASM_PFX(SecSwitchStack):
mov eax, ebp
sub eax, ebx
add eax, ecx
- mov ebp, eax ; From now, ebp is pointed to permanent memory
+ mov ebp, eax ; From now, ebp is pointed to permanent memory

pop edx
pop ecx
diff --git a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecFspWrapperPlatformSecLibSample.inf b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecFspWrapperPlatformSecLibSample.inf
index 027b127724..7aa4297bcc 100644
--- a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecFspWrapperPlatformSecLibSample.inf
+++ b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecFspWrapperPlatformSecLibSample.inf
@@ -39,13 +39,18 @@
SecGetPerformance.c
SecTempRamDone.c
PlatformInit.c
+ Fsp.h

[Sources.IA32]
- Ia32/Fsp.h
Ia32/SecEntry.nasm
Ia32/PeiCoreEntry.nasm
Ia32/Stack.nasm

+[Sources.X64]
+ X64/SecEntry.nasm
+ X64/PeiCoreEntry.nasm
+ X64/Stack.nasm
+
################################################################################
#
# Package Dependency Section - list of Package files that are required for
diff --git a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecRamInitData.c b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecRamInitData.c
index 03616cb418..4a7478c2c3 100644
--- a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecRamInitData.c
+++ b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecRamInitData.c
@@ -10,18 +10,20 @@
#include <FspEas.h>

typedef struct {
- UINT32 MicrocodeRegionBase;
- UINT32 MicrocodeRegionSize;
- UINT32 CodeRegionBase;
- UINT32 CodeRegionSize;
+ EFI_PHYSICAL_ADDRESS MicrocodeRegionBase;
+ UINT64 MicrocodeRegionSize;
+ EFI_PHYSICAL_ADDRESS CodeRegionBase;
+ UINT64 CodeRegionSize;
} FSPT_CORE_UPD;

typedef struct {
FSP_UPD_HEADER FspUpdHeader;
//
- // If platform does not support FSP spec 2.2 remove FSPT_ARCH_UPD structure.
+ // If FSP spec version < 2.2, remove FSPT_ARCH_UPD structure.
+ // Else If FSP spec version >= 2.2 and FSP spec version < 2.4, use FSPT_ARCH_UPD structure.
+ // Else, use FSPT_ARCH2_UPD structure.
//
- FSPT_ARCH_UPD FsptArchUpd;
+ FSPT_ARCH2_UPD FsptArchUpd;
FSPT_CORE_UPD FsptCoreUpd;
} FSPT_UPD_CORE_DATA;

@@ -36,10 +38,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST FSPT_UPD_CORE_DATA FsptUpdDataPtr = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
},
//
- // If platform does not support FSP spec 2.2 remove FSPT_ARCH_UPD structure.
+ // If FSP spec version < 2.2, remove FSPT_ARCH_UPD structure.
+ // Else If FSP spec version >= 2.2 and FSP spec version < 2.4, use FSPT_ARCH_UPD structure.
+ // Else, use FSPT_ARCH2_UPD structure.
//
{
- 0x01,
+ 0x02,
{
0x00, 0x00, 0x00
},
@@ -47,7 +51,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST FSPT_UPD_CORE_DATA FsptUpdDataPtr = {
0x00000000,
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}
},
{
diff --git a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/PeiCoreEntry.nasm b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/PeiCoreEntry.nasm
new file mode 100644
index 0000000000..0c0766acb8
--- /dev/null
+++ b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/PeiCoreEntry.nasm
@@ -0,0 +1,149 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+; PeiCoreEntry.nasm
+;
+; Abstract:
+;
+; Find and call SecStartup
+;
+;------------------------------------------------------------------------------
+
+SECTION .text
+
+%include "PushPopRegsNasm.inc"
+
+extern ASM_PFX(SecStartup)
+extern ASM_PFX(PlatformInit)
+
+;
+; args 1:XMM, 2:REG, 3:IDX
+;
+%macro LXMMN 3
+ pextrq %2, %1, (%3 & 3)
+ %endmacro
+
+;
+; args 1:YMM, 2:XMM, 3:IDX (0 - lower 128bits, 1 - upper 128bits)
+;
+%macro LYMMN 3
+ vextractf128 %2, %1, %3
+ %endmacro
+
+%macro LOAD_TS 1
+ LYMMN ymm6, xmm5, 1
+ LXMMN xmm5, %1, 1
+ %endmacro
+
+global ASM_PFX(CallPeiCoreEntryPoint)
+ASM_PFX(CallPeiCoreEntryPoint):
+ ;
+ ; Per X64 calling convention, make sure RSP is 16-byte aligned.
+ ;
+ mov rax, rsp
+ and rax, 0fh
+ sub rsp, rax
+
+ ;
+ ; Platform init
+ ;
+ PUSHA_64
+ sub rsp, 20h
+ call ASM_PFX(PlatformInit)
+ add rsp, 20h
+ POPA_64
+
+ ;
+ ; Set stack top pointer
+ ;
+ mov rsp, r8
+
+ ;
+ ; Push the hob list pointer
+ ;
+ push rcx
+
+ ;
+ ; RBP holds start of BFV passed from Vtf0. Save it to r10.
+ ;
+ mov r10, rbp
+
+ ;
+ ; Save the value
+ ; RDX: start of range
+ ; r8: end of range
+ ;
+ mov rbp, rsp
+ push rdx
+ push r8
+ mov r14, rdx
+ mov r15, r8
+
+ ;
+ ; Push processor count to stack first, then BIST status (AP then BSP)
+ ;
+ mov eax, 1
+ cpuid
+ shr ebx, 16
+ and ebx, 0000000FFh
+ cmp bl, 1
+ jae PushProcessorCount
+
+ ;
+ ; Some processors report 0 logical processors. Effectively 0 = 1.
+ ; So we fix up the processor count
+ ;
+ inc ebx
+
+PushProcessorCount:
+ sub rsp, 4
+ mov rdi, rsp
+ mov DWORD [rdi], ebx
+
+ ;
+ ; We need to implement a long-term solution for BIST capture. For now, we just copy BSP BIST
+ ; for all processor threads
+ ;
+ xor ecx, ecx
+ mov cl, bl
+PushBist:
+ sub rsp, 4
+ mov rdi, rsp
+ movd eax, mm0
+ mov DWORD [rdi], eax
+ loop PushBist
+
+ ; Save Time-Stamp Counter
+ LOAD_TS rax
+ push rax
+
+ ;
+ ; Pass entry point of the PEI core
+ ;
+ mov rdi, 0FFFFFFE0h
+ mov edi, DWORD [rdi]
+ mov r9, rdi
+
+ ;
+ ; Pass BFV into the PEI Core
+ ;
+ mov r8, r10
+
+ ;
+ ; Pass stack size into the PEI Core
+ ;
+ mov rcx, r15 ; Start of TempRam
+ mov rdx, r14 ; End of TempRam
+
+ sub rcx, rdx ; Size of TempRam
+
+ ;
+ ; Pass Control into the PEI Core
+ ;
+ sub rsp, 20h
+ call ASM_PFX(SecStartup)
+
diff --git a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/SecEntry.nasm b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/SecEntry.nasm
new file mode 100644
index 0000000000..dbbf63336e
--- /dev/null
+++ b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/SecEntry.nasm
@@ -0,0 +1,171 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+; SecEntry.asm
+;
+; Abstract:
+;
+; This is the code that calls TempRamInit API from FSP binary and passes
+; control into PEI core.
+;
+;------------------------------------------------------------------------------
+
+#include "Fsp.h"
+
+IA32_CR4_OSFXSR equ 200h
+IA32_CR4_OSXMMEXCPT equ 400h
+IA32_CR0_MP equ 2h
+
+IA32_CPUID_SSE2 equ 02000000h
+IA32_CPUID_SSE2_B equ 26
+
+SECTION .text
+
+extern ASM_PFX(CallPeiCoreEntryPoint)
+extern ASM_PFX(FsptUpdDataPtr)
+
+; Pcds
+extern ASM_PFX(PcdGet32 (PcdFsptBaseAddress))
+
+;----------------------------------------------------------------------------
+;
+; Procedure: _ModuleEntryPoint
+;
+; Input: None
+;
+; Output: None
+;
+; Destroys: Assume all registers
+;
+; Description:
+;
+; Call TempRamInit API from FSP binary. After TempRamInit done, pass
+; control into PEI core.
+;
+; Return: None
+;
+; MMX Usage:
+; MM0 = BIST State
+;
+;----------------------------------------------------------------------------
+
+BITS 64
+align 16
+global ASM_PFX(ModuleEntryPoint)
+ASM_PFX(ModuleEntryPoint):
+ fninit ; clear any pending Floating point exceptions
+ ;
+ ; Store the BIST value in mm0
+ ;
+ movd mm0, eax
+
+ ; Find the fsp info header
+ mov rax, ASM_PFX(PcdGet32 (PcdFsptBaseAddress))
+ mov edi, [eax]
+
+ mov eax, dword [edi + FVH_SIGINATURE_OFFSET]
+ cmp eax, FVH_SIGINATURE_VALID_VALUE
+ jnz FspHeaderNotFound
+
+ xor eax, eax
+ mov ax, word [edi + FVH_EXTHEADER_OFFSET_OFFSET]
+ cmp ax, 0
+ jnz FspFvExtHeaderExist
+
+ xor eax, eax
+ mov ax, word [edi + FVH_HEADER_LENGTH_OFFSET] ; Bypass Fv Header
+ add edi, eax
+ jmp FspCheckFfsHeader
+
+FspFvExtHeaderExist:
+ add edi, eax
+ mov eax, dword [edi + FVH_EXTHEADER_SIZE_OFFSET] ; Bypass Ext Fv Header
+ add edi, eax
+
+ ; Round up to 8 byte alignment
+ mov eax, edi
+ and al, 07h
+ jz FspCheckFfsHeader
+
+ and edi, 0FFFFFFF8h
+ add edi, 08h
+
+FspCheckFfsHeader:
+ ; Check the ffs guid
+ mov eax, dword [edi]
+ cmp eax, FSP_HEADER_GUID_DWORD1
+ jnz FspHeaderNotFound
+
+ mov eax, dword [edi + 4]
+ cmp eax, FSP_HEADER_GUID_DWORD2
+ jnz FspHeaderNotFound
+
+ mov eax, dword [edi + 8]
+ cmp eax, FSP_HEADER_GUID_DWORD3
+ jnz FspHeaderNotFound
+
+ mov eax, dword [edi + 0Ch]
+ cmp eax, FSP_HEADER_GUID_DWORD4
+ jnz FspHeaderNotFound
+
+ add edi, FFS_HEADER_SIZE_VALUE ; Bypass the ffs header
+
+ ; Check the section type as raw section
+ mov al, byte [edi + SECTION_HEADER_TYPE_OFFSET]
+ cmp al, 019h
+ jnz FspHeaderNotFound
+
+ add edi, RAW_SECTION_HEADER_SIZE_VALUE ; Bypass the section header
+ jmp FspHeaderFound
+
+FspHeaderNotFound:
+ jmp $
+
+FspHeaderFound:
+ ; Get the fsp TempRamInit Api address
+ mov eax, dword [edi + FSP_HEADER_IMAGEBASE_OFFSET]
+ add eax, dword [edi + FSP_HEADER_TEMPRAMINIT_OFFSET]
+
+ ; Setup the hardcode stack
+ mov rsp, TempRamInitStack
+
+ ; Call the fsp TempRamInit Api
+ jmp rax
+
+TempRamInitDone:
+ cmp rax, 0800000000000000Eh ; Check if EFI_NOT_FOUND returned. Error code for Microcode Update not found.
+ je CallSecFspInit ; If microcode not found, don't hang, but continue.
+
+ cmp rax, 0 ; Check if EFI_SUCCESS returned.
+ jnz FspApiFailed
+
+ ; RDX: start of range
+ ; R8: end of range
+CallSecFspInit:
+
+ mov r8, rdx
+ mov rdx, rcx
+ xor ecx, ecx ; zero - no Hob List Yet
+ mov rsp, r8
+
+ ;
+ ; Per X64 calling convention, make sure RSP is 16-byte aligned.
+ ;
+ mov rax, rsp
+ and rax, 0fh
+ sub rsp, rax
+
+ call ASM_PFX(CallPeiCoreEntryPoint)
+
+FspApiFailed:
+ jmp $
+
+align 10h
+TempRamInitStack:
+ DQ TempRamInitDone
+ DQ ASM_PFX(FsptUpdDataPtr) ; TempRamInitParams
+
diff --git a/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/Stack.nasm b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/Stack.nasm
new file mode 100644
index 0000000000..64e46ce953
--- /dev/null
+++ b/IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/Stack.nasm
@@ -0,0 +1,73 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Abstract:
+;
+; Switch the stack from temporary memory to permanent memory.
+;
+;------------------------------------------------------------------------------
+
+ SECTION .text
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; SecSwitchStack (
+; UINT32 TemporaryMemoryBase,
+; UINT32 PermanentMemoryBase
+; );
+;------------------------------------------------------------------------------
+global ASM_PFX(SecSwitchStack)
+ASM_PFX(SecSwitchStack):
+ ;
+ ; Save four register: rax, rbx, rcx, rdx
+ ;
+ push rax
+ push rbx
+ push rcx
+ push rdx
+
+ ;
+ ; !!CAUTION!! this function address's is pushed into stack after
+ ; migration of whole temporary memory, so need save it to permanent
+ ; memory at first!
+ ;
+
+ mov rbx, rcx ; Save the first parameter
+ mov rcx, rdx ; Save the second parameter
+
+ ;
+ ; Save this function's return address into permanent memory at first.
+ ; Then, Fixup the esp point to permanent memory
+ ;
+ mov rax, rsp
+ sub rax, rbx
+ add rax, rcx
+ mov rdx, qword [rsp] ; copy pushed register's value to permanent memory
+ mov qword [rax], rdx
+ mov rdx, qword [rsp + 8]
+ mov qword [rax + 8], rdx
+ mov rdx, qword [rsp + 16]
+ mov qword [rax + 16], rdx
+ mov rdx, qword [rsp + 24]
+ mov qword [rax + 24], rdx
+ mov rdx, qword [rsp + 32] ; Update this function's return address into permanent memory
+ mov qword [rax + 32], rdx
+ mov rsp, rax ; From now, rsp is pointed to permanent memory
+
+ ;
+ ; Fixup the rbp point to permanent memory
+ ;
+ mov rax, rbp
+ sub rax, rbx
+ add rax, rcx
+ mov rbp, rax ; From now, rbp is pointed to permanent memory
+
+ pop rdx
+ pop rcx
+ pop rbx
+ pop rax
+ ret
+
--
2.16.2.windows.1


[PATCH v3 7/8] IntelFsp2WrapperPkg: BaseFspWrapperApiLib support for X64

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
Add Execute64BitCode to execute 64bit code from long mode directly
in PEI 64bit.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
.../BaseFspWrapperApiLib/FspWrapperApiLib.c | 42 +++++++++++++++++---
.../BaseFspWrapperApiLib/IA32/DispatchExecute.c | 21 ++++++++++
.../BaseFspWrapperApiLib/X64/DispatchExecute.c | 45 +++++++++++++++++++++-
3 files changed, 101 insertions(+), 7 deletions(-)

diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
index 67faad927c..ba4fe3903e 100644
--- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
+++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
@@ -13,7 +13,7 @@
#include <Library/BaseMemoryLib.h>

/**
- Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
+ Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
long mode.

@param[in] Function The 32bit code entry to be executed.
@@ -29,6 +29,22 @@ Execute32BitCode (
IN UINT64 Param2
);

+/**
+ Wrapper to execute 64-bit code directly from long mode.
+
+ @param[in] Function The 64bit code entry to be executed.
+ @param[in] Param1 The first parameter to pass to 64bit code.
+ @param[in] Param2 The second parameter to pass to 64bit code.
+
+ @return EFI_STATUS.
+**/
+EFI_STATUS
+Execute64BitCode (
+ IN UINT64 Function,
+ IN UINT64 Param1,
+ IN UINT64 Param2
+ );
+
/**
Find FSP header pointer.

@@ -94,7 +110,11 @@ CallFspNotifyPhase (

NotifyPhaseApi = (FSP_NOTIFY_PHASE)((UINTN)FspHeader->ImageBase + FspHeader->NotifyPhaseEntryOffset);
InterruptState = SaveAndDisableInterrupts ();
- Status = Execute32BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams, (UINTN)NULL);
+ if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {
+ Status = Execute32BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams, (UINTN)NULL);
+ } else {
+ Status = Execute64BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams, (UINTN)NULL);
+ }
SetInterruptState (InterruptState);

return Status;
@@ -127,7 +147,11 @@ CallFspMemoryInit (

FspMemoryInitApi = (FSP_MEMORY_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspMemoryInitEntryOffset);
InterruptState = SaveAndDisableInterrupts ();
- Status = Execute32BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);
+ if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {
+ Status = Execute32BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);
+ } else {
+ Status = Execute64BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);
+ }
SetInterruptState (InterruptState);

return Status;
@@ -158,7 +182,11 @@ CallTempRamExit (

TempRamExitApi = (FSP_TEMP_RAM_EXIT)((UINTN)FspHeader->ImageBase + FspHeader->TempRamExitEntryOffset);
InterruptState = SaveAndDisableInterrupts ();
- Status = Execute32BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam, (UINTN)NULL);
+ if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {
+ Status = Execute32BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam, (UINTN)NULL);
+ } else {
+ Status = Execute64BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam, (UINTN)NULL);
+ }
SetInterruptState (InterruptState);

return Status;
@@ -189,7 +217,11 @@ CallFspSiliconInit (

FspSiliconInitApi = (FSP_SILICON_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspSiliconInitEntryOffset);
InterruptState = SaveAndDisableInterrupts ();
- Status = Execute32BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspsUpdDataPtr, (UINTN)NULL);
+ if ((FspHeader->ImageAttribute & IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT) == FSP_IA32) {
+ Status = Execute32BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspsUpdDataPtr, (UINTN)NULL);
+ } else {
+ Status = Execute64BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspsUpdDataPtr, (UINTN)NULL);
+ }
SetInterruptState (InterruptState);

return Status;
diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/IA32/DispatchExecute.c b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/IA32/DispatchExecute.c
index 4f6a8dd1a7..a22ed2d539 100644
--- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/IA32/DispatchExecute.c
+++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/IA32/DispatchExecute.c
@@ -49,3 +49,24 @@ Execute32BitCode (

return Status;
}
+
+/**
+ Wrapper for a thunk to transition from compatibility mode to long mode to execute 64-bit code and then transit back to
+ compatibility mode.
+
+ @param[in] Function The 64bit code entry to be executed.
+ @param[in] Param1 The first parameter to pass to 64bit code.
+ @param[in] Param2 The second parameter to pass to 64bit code.
+
+ @return EFI_STATUS.
+**/
+EFI_STATUS
+Execute64BitCode (
+ IN UINT64 Function,
+ IN UINT64 Param1,
+ IN UINT64 Param2
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/X64/DispatchExecute.c b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/X64/DispatchExecute.c
index 2ee5bc3dd4..bae216f639 100644
--- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/X64/DispatchExecute.c
+++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/X64/DispatchExecute.c
@@ -1,5 +1,5 @@
/** @file
- Execute 32-bit code in Long Mode.
+ Execute 64-bit code in Long Mode.
Provide a thunk function to transition from long mode to compatibility mode to execute 32-bit code and then transit
back to long mode.

@@ -12,6 +12,21 @@
#include <Library/BaseLib.h>
#include <FspEas.h>

+/**
+ FSP API functions.
+
+ @param[in] Param1 The first parameter to pass to 64bit code.
+ @param[in] Param2 The second parameter to pass to 64bit code.
+
+ @return EFI_STATUS.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *FSP_FUNCTION)(
+ IN VOID *Param1,
+ IN VOID *Param2
+ );
+
#pragma pack(1)
typedef union {
struct {
@@ -80,7 +95,7 @@ AsmExecute32BitCode (
);

/**
- Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
+ Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to
long mode.

@param[in] Function The 32bit code entry to be executed.
@@ -110,3 +125,29 @@ Execute32BitCode (

return Status;
}
+
+/**
+ Wrapper to execute 64-bit code directly from long mode.
+
+ @param[in] Function The 64bit code entry to be executed.
+ @param[in] Param1 The first parameter to pass to 64bit code.
+ @param[in] Param2 The second parameter to pass to 64bit code.
+
+ @return EFI_STATUS.
+**/
+EFI_STATUS
+Execute64BitCode (
+ IN UINT64 Function,
+ IN UINT64 Param1,
+ IN UINT64 Param2
+ )
+{
+ FSP_FUNCTION EntryFunc;
+ EFI_STATUS Status;
+
+ EntryFunc = (FSP_FUNCTION)(UINTN)(Function);
+ Status = EntryFunc ((VOID *)(UINTN)Param1, (VOID *)(UINTN)Param2);
+
+ return Status;
+}
+
--
2.16.2.windows.1


[PATCH v3 6/8] IntelFsp2WrapperPkg: Adopt FSPM_UPD_COMMON_FSP24 for X64

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
Adopt FSPM_UPD_COMMON_FSP24 in FspmWrapperPeim to support X64.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
.../FspmWrapperPeim/FspmWrapperPeim.c | 25 ++++++++++++++--------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c b/IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c
index b0c6b2f8a6..62a34467e0 100644
--- a/IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c
+++ b/IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c
@@ -71,7 +71,7 @@ PeiFspMemoryInit (
UINT64 TimeStampCounterStart;
VOID *FspHobListPtr;
VOID *HobData;
- FSPM_UPD_COMMON *FspmUpdDataPtr;
+ VOID *FspmUpdDataPtr;
UINTN *SourceData;

DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));
@@ -89,7 +89,7 @@ PeiFspMemoryInit (
//
// Copy default FSP-M UPD data from Flash
//
- FspmUpdDataPtr = (FSPM_UPD_COMMON *)AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);
+ FspmUpdDataPtr = AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);
ASSERT (FspmUpdDataPtr != NULL);
SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);
CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);
@@ -97,17 +97,24 @@ PeiFspMemoryInit (
//
// External UPD is ready, get the buffer from PCD pointer.
//
- FspmUpdDataPtr = (FSPM_UPD_COMMON *) GetFspmUpdDataAddress();
+ FspmUpdDataPtr = (VOID *) GetFspmUpdDataAddress();
ASSERT (FspmUpdDataPtr != NULL);
}

DEBUG ((DEBUG_INFO, "UpdateFspmUpdData enter\n"));
- UpdateFspmUpdData ((VOID *)FspmUpdDataPtr);
- DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.NvsBufferPtr));
- DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackBase));
- DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackSize));
- DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootLoaderTolumSize));
- DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootMode));
+ UpdateFspmUpdData (FspmUpdDataPtr);
+ if (((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.Revision >= 3) {
+ DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
+ DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
+ DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
+ DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
+ } else {
+ DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.NvsBufferPtr));
+ DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
+ DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
+ DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
+ DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
+ }
DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));

TimeStampCounterStart = AsmReadTsc ();
--
2.16.2.windows.1


[PATCH v3 5/8] IntelFsp2Pkg: SecFspSecPlatformLibNull support for X64

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
1.Added SecFspSecPlatformLibNull support for X64.
2.Added X64 support to IntelFsp2Pkg.dsc.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
IntelFsp2Pkg/IntelFsp2Pkg.dsc | 2 +-
.../SecFspSecPlatformLibNull.inf | 6 +++-
.../SecFspSecPlatformLibNull/X64/Long64.nasm | 31 +++++++++++++++++
.../SecFspSecPlatformLibNull/X64/SecCarInit.nasm | 40 ++++++++++++++++++++++
4 files changed, 77 insertions(+), 2 deletions(-)
create mode 100644 IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/Long64.nasm
create mode 100644 IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/SecCarInit.nasm

diff --git a/IntelFsp2Pkg/IntelFsp2Pkg.dsc b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
index c1414f7e75..1284aa042c 100644
--- a/IntelFsp2Pkg/IntelFsp2Pkg.dsc
+++ b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
@@ -12,7 +12,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/IntelFsp2Pkg
- SUPPORTED_ARCHITECTURES = IA32
+ SUPPORTED_ARCHITECTURES = IA32|X64
BUILD_TARGETS = DEBUG|RELEASE|NOOPT
SKUID_IDENTIFIER = DEFAULT

diff --git a/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/SecFspSecPlatformLibNull.inf b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/SecFspSecPlatformLibNull.inf
index 42e7d83c32..ef859d5ea5 100644
--- a/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/SecFspSecPlatformLibNull.inf
+++ b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/SecFspSecPlatformLibNull.inf
@@ -23,7 +23,7 @@
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32
+# VALID_ARCHITECTURES = IA32 X64
#

################################################################################
@@ -39,6 +39,10 @@
Ia32/Flat32.nasm
Ia32/SecCarInit.nasm

+[Sources.X64]
+ X64/Long64.nasm
+ X64/SecCarInit.nasm
+
################################################################################
#
# Package Dependency Section - list of Package files that are required for
diff --git a/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/Long64.nasm b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/Long64.nasm
new file mode 100644
index 0000000000..836257f962
--- /dev/null
+++ b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/Long64.nasm
@@ -0,0 +1,31 @@
+;; @file
+; This is the code that performs early platform initialization.
+; It consumes the reset vector, configures the stack.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+;
+; Define assembler characteristics
+;
+
+extern ASM_PFX(TempRamInitApi)
+
+SECTION .text
+
+%macro RET_RSI 0
+
+ movd rsi, mm7 ; restore RSI from MM7
+ jmp rsi
+
+%endmacro
+
+;
+; Perform early platform initialization
+;
+global ASM_PFX(SecPlatformInit)
+ASM_PFX(SecPlatformInit):
+
+ RET_RSI
+
diff --git a/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/SecCarInit.nasm b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/SecCarInit.nasm
new file mode 100644
index 0000000000..e64c77ed18
--- /dev/null
+++ b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/SecCarInit.nasm
@@ -0,0 +1,40 @@
+;; @file
+; SEC CAR function
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+;
+; Define assembler characteristics
+;
+
+%macro RET_RSI 0
+
+ movd rsi, mm7 ; move ReturnAddress from MM7 to RSI
+ jmp rsi
+
+%endmacro
+
+SECTION .text
+
+;-----------------------------------------------------------------------------
+;
+; Section: SecCarInit
+;
+; Description: This function initializes the Cache for Data, Stack, and Code
+;
+;-----------------------------------------------------------------------------
+global ASM_PFX(SecCarInit)
+ASM_PFX(SecCarInit):
+
+ ;
+ ; Set up CAR
+ ;
+
+ xor rax, rax
+
+SecCarInitExit:
+
+ RET_RSI
+
--
2.16.2.windows.1


[PATCH v3 4/8] IntelFsp2Pkg: FspSecCore support for X64

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
1.Added FspSecCore support for X64.
2.Bumped FSP header revision to 7 to indicate FSP 64bit is supported.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
IntelFsp2Pkg/FspSecCore/Fsp22SecCoreS.inf | 8 +-
IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf | 9 +-
IntelFsp2Pkg/FspSecCore/FspSecCoreS.inf | 8 +-
IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf | 10 +-
.../FspSecCore/Ia32/FspApiEntryCommon.nasm | 4 +-
IntelFsp2Pkg/FspSecCore/X64/Fsp22ApiEntryS.nasm | 103 +++++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryCommon.nasm | 76 ++++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryM.nasm | 262 +++++++++++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryS.nasm | 67 +++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm | 495 +++++++++++++++++++++
IntelFsp2Pkg/FspSecCore/X64/FspHelper.nasm | 34 ++
IntelFsp2Pkg/FspSecCore/X64/MicrocodeLoadNasm.inc | 11 +
IntelFsp2Pkg/FspSecCore/X64/ReadRsp.nasm | 22 +
IntelFsp2Pkg/FspSecCore/X64/Stack.nasm | 73 +++
IntelFsp2Pkg/Include/Guid/FspHeaderFile.h | 14 +-
IntelFsp2Pkg/Include/SaveRestoreSseAvxNasm.inc | 284 ++++++++++++
.../Library/BaseFspCommonLib/FspCommonLib.c | 1 +
.../Library/BaseFspSwitchStackLib/X64/Stack.nasm | 5 +-
18 files changed, 1475 insertions(+), 11 deletions(-)
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/Fsp22ApiEntryS.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryCommon.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryM.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryS.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspHelper.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/MicrocodeLoadNasm.inc
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/ReadRsp.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/Stack.nasm
create mode 100644 IntelFsp2Pkg/Include/SaveRestoreSseAvxNasm.inc

diff --git a/IntelFsp2Pkg/FspSecCore/Fsp22SecCoreS.inf b/IntelFsp2Pkg/FspSecCore/Fsp22SecCoreS.inf
index 0a24eb2a8b..d64ec12499 100644
--- a/IntelFsp2Pkg/FspSecCore/Fsp22SecCoreS.inf
+++ b/IntelFsp2Pkg/FspSecCore/Fsp22SecCoreS.inf
@@ -17,7 +17,7 @@
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32
+# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
@@ -30,6 +30,12 @@
Ia32/FspApiEntryCommon.nasm
Ia32/FspHelper.nasm

+[Sources.X64]
+ X64/Stack.nasm
+ X64/Fsp22ApiEntryS.nasm
+ X64/FspApiEntryCommon.nasm
+ X64/FspHelper.nasm
+
[Binaries.Ia32]
RAW|Vtf0/Bin/ResetVec.ia32.raw |GCC

diff --git a/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf b/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
index 7b05cae641..34794dd16e 100644
--- a/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
+++ b/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
@@ -17,7 +17,7 @@
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32
+# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
@@ -34,6 +34,13 @@
Ia32/FspHelper.nasm
Ia32/ReadEsp.nasm

+[Sources.X64]
+ X64/Stack.nasm
+ X64/FspApiEntryM.nasm
+ X64/FspApiEntryCommon.nasm
+ X64/FspHelper.nasm
+ X64/ReadRsp.nasm
+
[Binaries.Ia32]
RAW|Vtf0/Bin/ResetVec.ia32.raw |GCC

diff --git a/IntelFsp2Pkg/FspSecCore/FspSecCoreS.inf b/IntelFsp2Pkg/FspSecCore/FspSecCoreS.inf
index 1d9c2554d1..79d4e0674e 100644
--- a/IntelFsp2Pkg/FspSecCore/FspSecCoreS.inf
+++ b/IntelFsp2Pkg/FspSecCore/FspSecCoreS.inf
@@ -17,7 +17,7 @@
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32
+# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
@@ -30,6 +30,12 @@
Ia32/FspApiEntryCommon.nasm
Ia32/FspHelper.nasm

+[Sources.X64]
+ X64/Stack.nasm
+ X64/FspApiEntryS.nasm
+ X64/FspApiEntryCommon.nasm
+ X64/FspHelper.nasm
+
[Binaries.Ia32]
RAW|Vtf0/Bin/ResetVec.ia32.raw |GCC

diff --git a/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf b/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
index 664bde5678..f08a3b2c2b 100644
--- a/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
+++ b/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
@@ -17,17 +17,19 @@
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32
+# VALID_ARCHITECTURES = IA32 X64
#

-[Sources]
-
-
[Sources.IA32]
Ia32/Stack.nasm
Ia32/FspApiEntryT.nasm
Ia32/FspHelper.nasm

+[Sources.X64]
+ X64/Stack.nasm
+ X64/FspApiEntryT.nasm
+ X64/FspHelper.nasm
+
[Binaries.Ia32]
RAW|Vtf0/Bin/ResetVec.ia32.raw |GCC

diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryCommon.nasm b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryCommon.nasm
index 26ae7d9fd3..024f7aec5c 100644
--- a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryCommon.nasm
+++ b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryCommon.nasm
@@ -7,6 +7,8 @@

SECTION .text

+STACK_SAVED_EAX_OFFSET EQU 4 * 7 ; size of a general purpose register * eax index
+
;
; Following functions will be provided in C
;
@@ -52,7 +54,7 @@ FspApiCommon1:
add esp, 8
cmp eax, 0
jz FspApiCommon2
- mov dword [esp + (4 * 7)], eax
+ mov dword [esp + STACK_SAVED_EAX_OFFSET], eax
popad
exit:
ret
diff --git a/IntelFsp2Pkg/FspSecCore/X64/Fsp22ApiEntryS.nasm b/IntelFsp2Pkg/FspSecCore/X64/Fsp22ApiEntryS.nasm
new file mode 100644
index 0000000000..c739793a39
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/Fsp22ApiEntryS.nasm
@@ -0,0 +1,103 @@
+;; @file
+; Provide FSP API entry points.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+ SECTION .text
+
+;
+; Following functions will be provided in C
+;
+extern ASM_PFX(FspApiCommon)
+extern ASM_PFX(FspMultiPhaseSiInitApiHandler)
+
+STACK_SAVED_RAX_OFFSET EQU 8 * 7 ; size of a general purpose register * rax index
+
+;----------------------------------------------------------------------------
+; NotifyPhase API
+;
+; This FSP API will notify the FSP about the different phases in the boot
+; process
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(NotifyPhaseApi)
+ASM_PFX(NotifyPhaseApi):
+ mov eax, 2 ; FSP_API_INDEX.NotifyPhaseApiIndex
+ jmp ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; FspSiliconInit API
+;
+; This FSP API initializes the CPU and the chipset including the IO
+; controllers in the chipset to enable normal operation of these devices.
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(FspSiliconInitApi)
+ASM_PFX(FspSiliconInitApi):
+ mov eax, 5 ; FSP_API_INDEX.FspSiliconInitApiIndex
+ jmp ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; FspMultiPhaseSiInitApi API
+;
+; This FSP API provides multi-phase silicon initialization, which brings greater
+; modularity beyond the existing FspSiliconInit() API.
+; Increased modularity is achieved by adding an extra API to FSP-S.
+; This allows the bootloader to add board specific initialization steps throughout
+; the SiliconInit flow as needed.
+;
+;----------------------------------------------------------------------------
+
+%include "PushPopRegsNasm.inc"
+
+global ASM_PFX(FspMultiPhaseSiInitApi)
+ASM_PFX(FspMultiPhaseSiInitApi):
+ mov eax, 6 ; FSP_API_INDEX.FspMultiPhaseSiInitApiIndex
+ jmp ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; FspApiCommonContinue API
+;
+; This is the FSP API common entry point to resume the FSP execution
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(FspApiCommonContinue)
+ASM_PFX(FspApiCommonContinue):
+ ;
+ ; Handle FspMultiPhaseSiInitApiIndex API
+ ;
+ cmp eax, 6
+ jnz NotMultiPhaseSiInitApi
+
+ PUSHA_64
+ mov rdx, rcx ; move ApiParam to rdx
+ mov rcx, rax ; move ApiIdx to rcx
+ call ASM_PFX(FspMultiPhaseSiInitApiHandler)
+ mov qword [rsp + STACK_SAVED_RAX_OFFSET], rax
+ POPA_64
+ ret
+
+NotMultiPhaseSiInitApi:
+ jmp $
+ ret
+
+;----------------------------------------------------------------------------
+; TempRamInit API
+;
+; Empty function for WHOLEARCHIVE build option
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(TempRamInitApi)
+ASM_PFX(TempRamInitApi):
+ jmp $
+ ret
+
+;----------------------------------------------------------------------------
+; Module Entrypoint API
+;----------------------------------------------------------------------------
+global ASM_PFX(_ModuleEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
+ jmp $
+
diff --git a/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryCommon.nasm b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryCommon.nasm
new file mode 100644
index 0000000000..718e672e02
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryCommon.nasm
@@ -0,0 +1,76 @@
+;; @file
+; Provide FSP API entry points.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+ SECTION .text
+
+%include "PushPopRegsNasm.inc"
+
+STACK_SAVED_RAX_OFFSET EQU 8 * 7 ; size of a general purpose register * rax index
+
+;
+; Following functions will be provided in C
+;
+extern ASM_PFX(Loader2PeiSwitchStack)
+extern ASM_PFX(FspApiCallingCheck)
+
+;
+; Following functions will be provided in ASM
+;
+extern ASM_PFX(FspApiCommonContinue)
+extern ASM_PFX(AsmGetFspInfoHeader)
+
+;----------------------------------------------------------------------------
+; FspApiCommon API
+;
+; This is the FSP API common entry point to resume the FSP execution
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(FspApiCommon)
+ASM_PFX(FspApiCommon):
+ ;
+ ; RAX holds the API index
+ ;
+
+ ;
+ ; Stack must be ready
+ ;
+ push rax
+ add rsp, 8
+ cmp rax, [rsp - 8]
+ jz FspApiCommon1
+ mov rax, 08000000000000003h
+ jmp exit
+
+FspApiCommon1:
+ ;
+ ; Verify the calling condition
+ ;
+ PUSHA_64
+ mov rdx, rcx ; move ApiParam to rdx
+ mov rcx, rax ; move ApiIdx to rcx
+ call ASM_PFX(FspApiCallingCheck)
+ cmp rax, 0
+ jz FspApiCommon2
+ mov [rsp + STACK_SAVED_RAX_OFFSET], rax
+ POPA_64
+exit:
+ ret
+
+FspApiCommon2:
+ POPA_64
+ cmp rax, 3 ; FspMemoryInit API
+ jz FspApiCommon3
+
+ cmp rax, 6 ; FspMultiPhaseSiInitApiIndex API
+ jz FspApiCommon3
+
+ call ASM_PFX(AsmGetFspInfoHeader)
+ jmp ASM_PFX(Loader2PeiSwitchStack)
+
+FspApiCommon3:
+ jmp ASM_PFX(FspApiCommonContinue)
+
diff --git a/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryM.nasm b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryM.nasm
new file mode 100644
index 0000000000..17ad389b2b
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryM.nasm
@@ -0,0 +1,262 @@
+;; @file
+; Provide FSP API entry points.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+ SECTION .text
+
+%include "PushPopRegsNasm.inc"
+
+;
+; Following are fixed PCDs
+;
+extern ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))
+
+struc FSPM_UPD_COMMON_FSP24
+ ; FSP_UPD_HEADER {
+ .FspUpdHeader: resd 8
+ ; }
+ ; FSPM_ARCH2_UPD {
+ .Revision: resb 1
+ .Reserved: resb 3
+ .Length resd 1
+ .StackBase: resq 1
+ .StackSize: resq 1
+ .BootLoaderTolumSize: resd 1
+ .BootMode: resd 1
+ .FspEventHandler resq 1
+ .Reserved1: resb 24
+ ; }
+ .size:
+endstruc
+
+;
+; Following functions will be provided in C
+;
+extern ASM_PFX(SecStartup)
+extern ASM_PFX(FspApiCommon)
+
+;
+; Following functions will be provided in PlatformSecLib
+;
+extern ASM_PFX(AsmGetFspBaseAddress)
+extern ASM_PFX(AsmGetFspInfoHeader)
+
+FSP_HEADER_IMGBASE_OFFSET EQU 1Ch
+FSP_HEADER_CFGREG_OFFSET EQU 24h
+
+;----------------------------------------------------------------------------
+; FspMemoryInit API
+;
+; This FSP API is called after TempRamInit and initializes the memory.
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(FspMemoryInitApi)
+ASM_PFX(FspMemoryInitApi):
+ mov eax, 3 ; FSP_API_INDEX.FspMemoryInitApiIndex
+ jmp ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; TempRamExitApi API
+;
+; This API tears down temporary RAM
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(TempRamExitApi)
+ASM_PFX(TempRamExitApi):
+ mov eax, 4 ; FSP_API_INDEX.TempRamExitApiIndex
+ jmp ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; FspApiCommonContinue API
+;
+; This is the FSP API common entry point to resume the FSP execution
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(FspApiCommonContinue)
+ASM_PFX(FspApiCommonContinue):
+ ;
+ ; RAX holds the API index
+ ; Push RDX and RCX to form CONTEXT_STACK_64
+ ;
+ push rdx ; Push a QWORD data for stack alignment
+ push rdx ; Push API Parameter2 on stack
+ push rcx ; Push API Parameter1 on stack
+
+ ;
+ ; FspMemoryInit API setup the initial stack frame
+ ;
+
+ ;
+ ; Place holder to store the FspInfoHeader pointer
+ ;
+ push rax
+
+ ;
+ ; Update the FspInfoHeader pointer
+ ;
+ push rax
+ call ASM_PFX(AsmGetFspInfoHeader)
+ mov [rsp + 8], rax
+ pop rax
+
+ ;
+ ; Create a Task Frame in the stack for the Boot Loader
+ ;
+ pushfq
+ cli
+ PUSHA_64
+
+ ; Reserve 16 bytes for IDT save/restore
+ sub rsp, 16
+ sidt [rsp]
+
+ ; Get Stackbase and StackSize from FSPM_UPD Param
+ mov rdx, rcx ; Put FSPM_UPD Param to rdx
+ cmp rdx, 0
+ jnz FspStackSetup
+
+ ; Get UPD default values if FspmUpdDataPtr (ApiParam1) is null
+ xchg rbx, rax
+ call ASM_PFX(AsmGetFspInfoHeader)
+ mov edx, [rax + FSP_HEADER_IMGBASE_OFFSET]
+ add edx, [rax + FSP_HEADER_CFGREG_OFFSET]
+ xchg rbx, rax
+
+FspStackSetup:
+ ;
+ ; StackBase = temp memory base, StackSize = temp memory size
+ ;
+ mov rdi, [rdx + FSPM_UPD_COMMON_FSP24.StackBase]
+ mov ecx, [rdx + FSPM_UPD_COMMON_FSP24.StackSize]
+
+ ;
+ ; Keep using bootloader stack if heap size % is 0
+ ;
+ mov rbx, ASM_PFX(PcdGet8 (PcdFspHeapSizePercentage))
+ mov bl, BYTE [rbx]
+ cmp bl, 0
+ jz SkipStackSwitch
+
+ ;
+ ; Set up a dedicated temp ram stack for FSP if FSP heap size % doesn't equal 0
+ ;
+ add rdi, rcx
+ ;
+ ; Switch to new FSP stack
+ ;
+ xchg rdi, rsp ; Exchange rdi and rsp, rdi will be assigned to the current rsp pointer and rsp will be Stack base + Stack size
+
+SkipStackSwitch:
+ ;
+ ; If heap size % is 0:
+ ; EDI is FSPM_UPD_COMMON_FSP24.StackBase and will hold ESP later (boot loader stack pointer)
+ ; ECX is FSPM_UPD_COMMON_FSP24.StackSize
+ ; ESP is boot loader stack pointer (no stack switch)
+ ; BL is 0 to indicate no stack switch (EBX will hold FSPM_UPD_COMMON_FSP24.StackBase later)
+ ;
+ ; If heap size % is not 0
+ ; EDI is boot loader stack pointer
+ ; ECX is FSPM_UPD_COMMON_FSP24.StackSize
+ ; ESP is new stack (FSPM_UPD_COMMON_FSP24.StackBase + FSPM_UPD_COMMON_FSP24.StackSize)
+ ; BL is NOT 0 to indicate stack has switched
+ ;
+ cmp bl, 0
+ jnz StackHasBeenSwitched
+
+ mov rbx, rdi ; Put FSPM_UPD_COMMON_FSP24.StackBase to rbx as temp memory base
+ mov rdi, rsp ; Put boot loader stack pointer to rdi
+ jmp StackSetupDone
+
+StackHasBeenSwitched:
+ mov rbx, rsp ; Put Stack base + Stack size in ebx
+ sub rbx, rcx ; Stack base + Stack size - Stack size as temp memory base
+
+StackSetupDone:
+
+ ;
+ ; Per X64 calling convention, make sure RSP is 16-byte aligned.
+ ;
+ mov rdx, rsp
+ and rdx, 0fh
+ sub rsp, rdx
+
+ ;
+ ; Pass the API Idx to SecStartup
+ ;
+ push rax
+
+ ;
+ ; Pass the BootLoader stack to SecStartup
+ ;
+ push rdi
+
+ ;
+ ; Pass BFV into the PEI Core
+ ; It uses relative address to calculate the actual boot FV base
+ ; For FSP implementation with single FV, PcdFspBootFirmwareVolumeBase and
+ ; PcdFspAreaBaseAddress are the same. For FSP with multiple FVs,
+ ; they are different. The code below can handle both cases.
+ ;
+ call ASM_PFX(AsmGetFspBaseAddress)
+ mov r8, rax
+
+ ;
+ ; Pass entry point of the PEI core
+ ;
+ call ASM_PFX(AsmGetPeiCoreOffset)
+ lea r9, [r8 + rax]
+
+ ;
+ ; Pass stack base and size into the PEI Core
+ ;
+ mov rcx, rcx
+ mov rdx, rbx
+
+ ;
+ ; Pass Control into the PEI Core
+ ; RCX = SizeOfRam, RDX = TempRamBase, R8 = BFV, R9 = PeiCoreEntry, Last 1 Stack = BL stack, Last 2 Stack = API index
+ ; According to X64 calling convention, caller has to allocate 32 bytes as a shadow store on call stack right before
+ ; calling the function.
+ ;
+ sub rsp, 20h
+ call ASM_PFX(SecStartup)
+ add rsp, 20h
+exit:
+ ret
+
+global ASM_PFX(FspPeiCoreEntryOff)
+ASM_PFX(FspPeiCoreEntryOff):
+ ;
+ ; This value will be pached by the build script
+ ;
+ DD 0x12345678
+
+global ASM_PFX(AsmGetPeiCoreOffset)
+ASM_PFX(AsmGetPeiCoreOffset):
+ push rbx
+ mov rbx, ASM_PFX(FspPeiCoreEntryOff)
+ mov eax, dword[ebx]
+ pop rbx
+ ret
+
+;----------------------------------------------------------------------------
+; TempRamInit API
+;
+; Empty function for WHOLEARCHIVE build option
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(TempRamInitApi)
+ASM_PFX(TempRamInitApi):
+ jmp $
+ ret
+
+;----------------------------------------------------------------------------
+; Module Entrypoint API
+;----------------------------------------------------------------------------
+global ASM_PFX(_ModuleEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
+ jmp $
+
diff --git a/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryS.nasm b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryS.nasm
new file mode 100644
index 0000000000..f863ef0078
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryS.nasm
@@ -0,0 +1,67 @@
+;; @file
+; Provide FSP API entry points.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+ SECTION .text
+
+;
+; Following functions will be provided in C
+;
+extern ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; NotifyPhase API
+;
+; This FSP API will notify the FSP about the different phases in the boot
+; process
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(NotifyPhaseApi)
+ASM_PFX(NotifyPhaseApi):
+ mov eax, 2 ; FSP_API_INDEX.NotifyPhaseApiIndex
+ jmp ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; FspSiliconInit API
+;
+; This FSP API initializes the CPU and the chipset including the IO
+; controllers in the chipset to enable normal operation of these devices.
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(FspSiliconInitApi)
+ASM_PFX(FspSiliconInitApi):
+ mov eax, 5 ; FSP_API_INDEX.FspSiliconInitApiIndex
+ jmp ASM_PFX(FspApiCommon)
+
+;----------------------------------------------------------------------------
+; FspApiCommonContinue API
+;
+; This is the FSP API common entry point to resume the FSP execution
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(FspApiCommonContinue)
+ASM_PFX(FspApiCommonContinue):
+ jmp $
+ ret
+
+;----------------------------------------------------------------------------
+; TempRamInit API
+;
+; Empty function for WHOLEARCHIVE build option
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(TempRamInitApi)
+ASM_PFX(TempRamInitApi):
+ jmp $
+ ret
+
+;----------------------------------------------------------------------------
+; Module Entrypoint API
+;----------------------------------------------------------------------------
+global ASM_PFX(_ModuleEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
+ jmp $
+
diff --git a/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm
new file mode 100644
index 0000000000..a9f5f28ed7
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm
@@ -0,0 +1,495 @@
+;; @file
+; Provide FSP API entry points.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+ SECTION .text
+
+%include "SaveRestoreSseAvxNasm.inc"
+%include "MicrocodeLoadNasm.inc"
+
+;
+; Following are fixed PCDs
+;
+extern ASM_PFX(PcdGet32 (PcdTemporaryRamBase))
+extern ASM_PFX(PcdGet32 (PcdTemporaryRamSize))
+extern ASM_PFX(PcdGet32 (PcdFspReservedBufferSize))
+
+;
+; Following functions will be provided in PlatformSecLib
+;
+extern ASM_PFX(AsmGetFspBaseAddress)
+extern ASM_PFX(AsmGetFspInfoHeader)
+;extern ASM_PFX(LoadMicrocode) ; @todo: needs a weak implementation
+extern ASM_PFX(SecPlatformInit) ; @todo: needs a weak implementation
+extern ASM_PFX(SecCarInit)
+
+;
+; Define the data length that we saved on the stack top
+;
+DATA_LEN_OF_PER0 EQU 18h
+DATA_LEN_OF_MCUD EQU 18h
+DATA_LEN_AT_STACK_TOP EQU (DATA_LEN_OF_PER0 + DATA_LEN_OF_MCUD + 4)
+
+;
+; @todo: These structures are moved from MicrocodeLoadNasm.inc to avoid
+; build error. This needs to be fixed later on.
+;
+struc MicrocodeHdr
+ .MicrocodeHdrVersion: resd 1
+ .MicrocodeHdrRevision: resd 1
+ .MicrocodeHdrDate: resd 1
+ .MicrocodeHdrProcessor: resd 1
+ .MicrocodeHdrChecksum: resd 1
+ .MicrocodeHdrLoader: resd 1
+ .MicrocodeHdrFlags: resd 1
+ .MicrocodeHdrDataSize: resd 1
+ .MicrocodeHdrTotalSize: resd 1
+ .MicrocodeHdrRsvd: resd 3
+ .size:
+endstruc
+
+struc ExtSigHdr
+ .ExtSigHdrCount: resd 1
+ .ExtSigHdrChecksum: resd 1
+ .ExtSigHdrRsvd: resd 3
+ .size:
+endstruc
+
+struc ExtSig
+ .ExtSigProcessor: resd 1
+ .ExtSigFlags: resd 1
+ .ExtSigChecksum: resd 1
+ .size:
+endstruc
+
+struc LoadMicrocodeParamsFsp24
+ ; FSP_UPD_HEADER {
+ .FspUpdHeaderSignature: resd 2
+ .FspUpdHeaderRevision: resb 1
+ .FspUpdHeaderReserved: resb 23
+ ; }
+ ; FSPT_ARCH2_UPD {
+ .FsptArchRevision: resb 1
+ .FsptArchReserved: resb 3
+ .FsptArchLength: resd 1
+ .FspDebugHandler resq 1
+ .FsptArchUpd: resd 4
+ ; }
+ ; FSPT_CORE_UPD {
+ .MicrocodeCodeAddr: resq 1
+ .MicrocodeCodeSize: resq 1
+ .CodeRegionBase: resq 1
+ .CodeRegionSize: resq 1
+ ; }
+ .size:
+endstruc
+
+;
+; @todo: The strong/weak implementation does not work.
+; This needs to be reviewed later.
+;
+;------------------------------------------------------------------------------
+;
+;;global ASM_PFX(SecPlatformInitDefault)
+;ASM_PFX(SecPlatformInitDefault):
+; ; Inputs:
+; ; ymm7 -> Return address
+; ; Outputs:
+; ; rax -> 0 - Successful, Non-zero - Failed.
+; ; Register Usage:
+; ; rax is cleared and rbp is used for return address.
+; ; All others reserved.
+;
+; ; Save return address to RBP
+; LOAD_RBP
+;
+; xor rax, rax
+;Exit1:
+; jmp rbp
+
+;------------------------------------------------------------------------------
+global ASM_PFX(LoadMicrocodeDefault)
+ASM_PFX(LoadMicrocodeDefault):
+ ; Inputs:
+ ; rsp -> LoadMicrocodeParams pointer
+ ; Register Usage:
+ ; rsp Preserved
+ ; All others destroyed
+ ; Assumptions:
+ ; No memory available, stack is hard-coded and used for return address
+ ; Executed by SBSP and NBSP
+ ; Beginning of microcode update region starts on paragraph boundary
+
+ ;
+ ; Save return address to RBP
+ ;
+ LOAD_RBP
+
+ cmp rsp, 0
+ jz ParamError
+ mov eax, dword [rsp + 8] ; Parameter pointer
+ cmp eax, 0
+ jz ParamError
+ mov esp, eax
+
+ ; skip loading Microcode if the MicrocodeCodeSize is zero
+ ; and report error if size is less than 2k
+ ; first check UPD header revision
+ cmp byte [rsp + LoadMicrocodeParamsFsp24.FspUpdHeaderRevision], 2
+ jb ParamError
+ cmp byte [rsp + LoadMicrocodeParamsFsp24.FsptArchRevision], 2
+ jne ParamError
+
+ ; UPD structure is compliant with FSP spec 2.4
+ mov eax, dword [rsp + LoadMicrocodeParamsFsp24.MicrocodeCodeSize]
+ cmp eax, 0
+ jz Exit2
+ cmp eax, 0800h
+ jl ParamError
+
+ mov esi, dword [rsp + LoadMicrocodeParamsFsp24.MicrocodeCodeAddr]
+ cmp esi, 0
+ jnz CheckMainHeader
+
+ParamError:
+ mov rax, 08000000000000002h
+ jmp Exit2
+
+CheckMainHeader:
+ ; Get processor signature and platform ID from the installed processor
+ ; and save into registers for later use
+ ; ebx = processor signature
+ ; edx = platform ID
+ mov eax, 1
+ cpuid
+ mov ebx, eax
+ mov ecx, MSR_IA32_PLATFORM_ID
+ rdmsr
+ mov ecx, edx
+ shr ecx, 50-32 ; shift (50d-32d=18d=0x12) bits
+ and ecx, 7h ; platform id at bit[52..50]
+ mov edx, 1
+ shl edx, cl
+
+ ; Current register usage
+ ; esp -> stack with parameters
+ ; esi -> microcode update to check
+ ; ebx = processor signature
+ ; edx = platform ID
+
+ ; Check for valid microcode header
+ ; Minimal test checking for header version and loader version as 1
+ mov eax, dword 1
+ cmp dword [esi + MicrocodeHdr.MicrocodeHdrVersion], eax
+ jne AdvanceFixedSize
+ cmp dword [esi + MicrocodeHdr.MicrocodeHdrLoader], eax
+ jne AdvanceFixedSize
+
+ ; Check if signature and plaform ID match
+ cmp ebx, dword [esi + MicrocodeHdr.MicrocodeHdrProcessor]
+ jne LoadMicrocodeDefault1
+ test edx, dword [esi + MicrocodeHdr.MicrocodeHdrFlags ]
+ jnz LoadCheck ; Jif signature and platform ID match
+
+LoadMicrocodeDefault1:
+ ; Check if extended header exists
+ ; First check if MicrocodeHdrTotalSize and MicrocodeHdrDataSize are valid
+ xor rax, rax
+ cmp dword [esi + MicrocodeHdr.MicrocodeHdrTotalSize], eax
+ je NextMicrocode
+ cmp dword [esi + MicrocodeHdr.MicrocodeHdrDataSize], eax
+ je NextMicrocode
+
+ ; Then verify total size - sizeof header > data size
+ mov ecx, dword [esi + MicrocodeHdr.MicrocodeHdrTotalSize]
+ sub ecx, MicrocodeHdr.size
+ cmp ecx, dword [esi + MicrocodeHdr.MicrocodeHdrDataSize]
+ jng NextMicrocode ; Jif extended header does not exist
+
+ ; Set edi -> extended header
+ mov edi, esi
+ add edi, MicrocodeHdr.size
+ add edi, dword [esi + MicrocodeHdr.MicrocodeHdrDataSize]
+
+ ; Get count of extended structures
+ mov ecx, dword [edi + ExtSigHdr.ExtSigHdrCount]
+
+ ; Move pointer to first signature structure
+ add edi, ExtSigHdr.size
+
+CheckExtSig:
+ ; Check if extended signature and platform ID match
+ cmp dword [edi + ExtSig.ExtSigProcessor], ebx
+ jne LoadMicrocodeDefault2
+ test dword [edi + ExtSig.ExtSigFlags], edx
+ jnz LoadCheck ; Jif signature and platform ID match
+LoadMicrocodeDefault2:
+ ; Check if any more extended signatures exist
+ add edi, ExtSig.size
+ loop CheckExtSig
+
+NextMicrocode:
+ ; Advance just after end of this microcode
+ xor rax, rax
+ cmp dword [esi + MicrocodeHdr.MicrocodeHdrTotalSize], eax
+ je LoadMicrocodeDefault3
+ add esi, dword [esi + MicrocodeHdr.MicrocodeHdrTotalSize]
+ jmp CheckAddress
+LoadMicrocodeDefault3:
+ add esi, dword 2048
+ jmp CheckAddress
+
+AdvanceFixedSize:
+ ; Advance by 4X dwords
+ add esi, dword 1024
+
+CheckAddress:
+ ; Check UPD header revision
+ cmp byte [rsp + LoadMicrocodeParamsFsp24.FspUpdHeaderRevision], 2
+ jb ParamError
+ cmp byte [rsp + LoadMicrocodeParamsFsp24.FsptArchRevision], 2
+ jne ParamError
+
+ ; UPD structure is compliant with FSP spec 2.4
+ ; Is automatic size detection ?
+ mov rax, qword [rsp + LoadMicrocodeParamsFsp24.MicrocodeCodeSize]
+ cmp rax, 0ffffffffffffffffh
+ jz LoadMicrocodeDefault4
+
+ ; Address >= microcode region address + microcode region size?
+ add rax, qword [rsp + LoadMicrocodeParamsFsp24.MicrocodeCodeAddr]
+ cmp rsi, rax
+ jae Done ;Jif address is outside of microcode region
+ jmp CheckMainHeader
+
+LoadMicrocodeDefault4:
+ ; Is valid Microcode start point ?
+ cmp dword [esi + MicrocodeHdr.MicrocodeHdrVersion], 0ffffffffh
+ jz Done
+
+LoadCheck:
+ ; Get the revision of the current microcode update loaded
+ mov ecx, MSR_IA32_BIOS_SIGN_ID
+ xor eax, eax ; Clear EAX
+ xor edx, edx ; Clear EDX
+ wrmsr ; Load 0 to MSR at 8Bh
+
+ mov eax, 1
+ cpuid
+ mov ecx, MSR_IA32_BIOS_SIGN_ID
+ rdmsr ; Get current microcode signature
+
+ ; Verify this microcode update is not already loaded
+ cmp dword [esi + MicrocodeHdr.MicrocodeHdrRevision], edx
+ je Continue
+
+LoadMicrocode:
+ ; EAX contains the linear address of the start of the Update Data
+ ; EDX contains zero
+ ; ECX contains 79h (IA32_BIOS_UPDT_TRIG)
+ ; Start microcode load with wrmsr
+ mov eax, esi
+ add eax, MicrocodeHdr.size
+ xor edx, edx
+ mov ecx, MSR_IA32_BIOS_UPDT_TRIG
+ wrmsr
+ mov eax, 1
+ cpuid
+
+Continue:
+ jmp NextMicrocode
+
+Done:
+ mov eax, 1
+ cpuid
+ mov ecx, MSR_IA32_BIOS_SIGN_ID
+ rdmsr ; Get current microcode signature
+ xor eax, eax
+ cmp edx, 0
+ jnz Exit2
+ mov eax, 0800000000000000Eh
+
+Exit2:
+ jmp rbp
+
+
+global ASM_PFX(EstablishStackFsp)
+ASM_PFX(EstablishStackFsp):
+ ;
+ ; Save parameter pointer in rdx
+ ;
+ mov rdx, qword [rsp + 8]
+
+ ;
+ ; Enable FSP STACK
+ ;
+ mov rax, ASM_PFX(PcdGet32 (PcdTemporaryRamBase))
+ mov esp, DWORD[rax]
+ mov rax, ASM_PFX(PcdGet32 (PcdTemporaryRamSize))
+ add esp, DWORD[rax]
+
+ sub esp, 4
+ mov dword[esp], DATA_LEN_OF_MCUD ; Size of the data region
+ sub esp, 4
+ mov dword[esp], 4455434Dh ; Signature of the data region 'MCUD'
+
+ ; check UPD structure revision (rdx + 8)
+ cmp byte [rdx + LoadMicrocodeParamsFsp24.FspUpdHeaderRevision], 2
+ jb ParamError1
+ cmp byte [rdx + LoadMicrocodeParamsFsp24.FsptArchRevision], 2
+ je Fsp24UpdHeader
+
+ParamError1:
+ mov rax, 08000000000000002h
+ jmp EstablishStackFspExit
+
+Fsp24UpdHeader:
+ ; UPD structure is compliant with FSP spec 2.4
+ xor rax, rax
+ mov rax, qword [rdx + LoadMicrocodeParamsFsp24.CodeRegionSize] ; Code size sizeof(FSPT_UPD_COMMON) + 18h
+ sub rsp, 8
+ mov qword[rsp], rax
+ mov rax, qword [rdx + LoadMicrocodeParamsFsp24.CodeRegionBase] ; Code base sizeof(FSPT_UPD_COMMON) + 10h
+ sub rsp, 8
+ mov qword[rsp], rax
+ mov rax, qword [rdx + LoadMicrocodeParamsFsp24.MicrocodeCodeSize] ; Microcode size sizeof(FSPT_UPD_COMMON) + 8h
+ sub rsp, 8
+ mov qword[rsp], rax
+ mov rax, qword [rdx + LoadMicrocodeParamsFsp24.MicrocodeCodeAddr] ; Microcode base sizeof(FSPT_UPD_COMMON) + 0h
+ sub rsp, 8
+ mov qword[rsp], rax
+
+ContinueAfterUpdPush:
+ ;
+ ; Save API entry/exit timestamp into stack
+ ;
+ sub esp, 4
+ mov dword[esp], DATA_LEN_OF_PER0 ; Size of the data region
+ sub esp, 4
+ mov dword[esp], 30524550h ; Signature of the data region 'PER0'
+ rdtsc
+ sub esp, 4
+ mov dword[esp], edx
+ sub esp, 4
+ mov dword[esp], eax
+ LOAD_TS rax
+ push rax
+
+ ;
+ ; Terminator for the data on stack
+ ;
+ push 0
+
+ ;
+ ; Set ECX/EDX to the BootLoader temporary memory range
+ ;
+ mov rcx, ASM_PFX(PcdGet32 (PcdTemporaryRamBase))
+ mov edx, [ecx]
+ mov rcx, ASM_PFX(PcdGet32 (PcdTemporaryRamSize))
+ add edx, [ecx]
+ mov rcx, ASM_PFX(PcdGet32 (PcdFspReservedBufferSize))
+ sub edx, [ecx]
+ mov rcx, ASM_PFX(PcdGet32 (PcdTemporaryRamBase))
+ mov ecx, [ecx]
+
+ cmp ecx, edx ; If PcdFspReservedBufferSize >= PcdTemporaryRamSize, then error.
+ jb EstablishStackFspSuccess
+ mov rax, 08000000000000003h ; EFI_UNSUPPORTED
+ jmp EstablishStackFspExit
+EstablishStackFspSuccess:
+ xor rax, rax
+
+EstablishStackFspExit:
+ RET_YMM
+
+;----------------------------------------------------------------------------
+; TempRamInit API
+;
+; This FSP API will load the microcode update, enable code caching for the
+; region specified by the boot loader and also setup a temporary stack to be
+; used till main memory is initialized.
+;
+;----------------------------------------------------------------------------
+global ASM_PFX(TempRamInitApi)
+ASM_PFX(TempRamInitApi):
+ ;
+ ; Ensure both SSE and AVX are enabled
+ ;
+ ENABLE_SSE
+ ENABLE_AVX
+
+ ;
+ ; Save RBP, RBX, RSI, RDI and RSP in YMM7, YMM8 and YMM6
+ ;
+ SAVE_REGS
+
+ ;
+ ; Save BFV address in YMM9
+ ;
+ SAVE_BFV rbp
+
+ ;
+ ; Save timestamp into YMM6
+ ;
+ rdtsc
+ shl rdx, 32
+ or rax, rdx
+ SAVE_TS rax
+
+ ;
+ ; Check Parameter
+ ;
+ mov rax, qword [rsp + 8]
+ cmp rax, 0
+ mov rax, 08000000000000002h
+ jz TempRamInitExit
+
+ ;
+ ; Sec Platform Init
+ ;
+ CALL_YMM ASM_PFX(SecPlatformInit)
+ cmp eax, 0
+ jnz TempRamInitExit
+
+ ; Load microcode
+ LOAD_RSP
+ CALL_YMM ASM_PFX(LoadMicrocodeDefault)
+ SAVE_UCODE_STATUS rax ; Save microcode return status in SLOT 0 in YMM9 (upper 128bits).
+ ; @note If return value rax is not 0, microcode did not load, but continue and attempt to boot.
+
+ ; Call Sec CAR Init
+ LOAD_RSP
+ CALL_YMM ASM_PFX(SecCarInit)
+ cmp rax, 0
+ jnz TempRamInitExit
+
+ LOAD_RSP
+ CALL_YMM ASM_PFX(EstablishStackFsp)
+ cmp rax, 0
+ jnz TempRamInitExit
+
+ LOAD_UCODE_STATUS rax ; Restore microcode status if no CAR init error from SLOT 0 in YMM9 (upper 128bits).
+
+TempRamInitExit:
+ mov bl, al ; save al data in bl
+ mov al, 07Fh ; API exit postcode 7f
+ out 080h, al
+ mov al, bl ; restore al data from bl
+
+ ;
+ ; Load RBP, RBX, RSI, RDI and RSP from YMM7, YMM8 and YMM6
+ ;
+ LOAD_REGS
+ LOAD_BFV rbp
+ ret
+
+;----------------------------------------------------------------------------
+; Module Entrypoint API
+;----------------------------------------------------------------------------
+global ASM_PFX(_ModuleEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
+ jmp $
+
diff --git a/IntelFsp2Pkg/FspSecCore/X64/FspHelper.nasm b/IntelFsp2Pkg/FspSecCore/X64/FspHelper.nasm
new file mode 100644
index 0000000000..122fa1d174
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/FspHelper.nasm
@@ -0,0 +1,34 @@
+;; @file
+; Provide FSP helper function.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+ DEFAULT REL
+ SECTION .text
+
+global ASM_PFX(AsmGetFspBaseAddress)
+ASM_PFX(AsmGetFspBaseAddress):
+ call ASM_PFX(AsmGetFspInfoHeader)
+ add rax, 0x1C
+ mov eax, [rax]
+ ret
+
+global ASM_PFX(AsmGetFspInfoHeader)
+ASM_PFX(AsmGetFspInfoHeader):
+ lea rax, [ASM_PFX(AsmGetFspInfoHeader)]
+ DB 0x48, 0x2d ; sub rax, 0x????????
+global ASM_PFX(FspInfoHeaderRelativeOff)
+ASM_PFX(FspInfoHeaderRelativeOff):
+ DD 0x12345678 ; This value must be patched by the build script
+ and rax, 0xffffffff
+ ret
+
+global ASM_PFX(AsmGetFspInfoHeaderNoStack)
+ASM_PFX(AsmGetFspInfoHeaderNoStack):
+ lea rax, [ASM_PFX(AsmGetFspInfoHeader)]
+ lea rcx, [ASM_PFX(FspInfoHeaderRelativeOff)]
+ mov ecx, [rcx]
+ sub rax, rcx
+ and rax, 0xffffffff
+ jmp rdi
diff --git a/IntelFsp2Pkg/FspSecCore/X64/MicrocodeLoadNasm.inc b/IntelFsp2Pkg/FspSecCore/X64/MicrocodeLoadNasm.inc
new file mode 100644
index 0000000000..4ec5070d25
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/MicrocodeLoadNasm.inc
@@ -0,0 +1,11 @@
+;; @file
+;
+;@copyright
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+MSR_IA32_PLATFORM_ID equ 000000017h
+MSR_IA32_BIOS_UPDT_TRIG equ 000000079h
+MSR_IA32_BIOS_SIGN_ID equ 00000008bh
+
diff --git a/IntelFsp2Pkg/FspSecCore/X64/ReadRsp.nasm b/IntelFsp2Pkg/FspSecCore/X64/ReadRsp.nasm
new file mode 100644
index 0000000000..af82509803
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/ReadRsp.nasm
@@ -0,0 +1,22 @@
+;; @file
+; Provide read RSP function
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+;------------------------------------------------------------------------------
+
+ SECTION .text
+
+;------------------------------------------------------------------------------
+; UINTN
+; EFIAPI
+; AsmReadStackPointer (
+; VOID
+; );
+;------------------------------------------------------------------------------
+global ASM_PFX(AsmReadStackPointer)
+ASM_PFX(AsmReadStackPointer):
+ mov rax, rsp
+ ret
+
diff --git a/IntelFsp2Pkg/FspSecCore/X64/Stack.nasm b/IntelFsp2Pkg/FspSecCore/X64/Stack.nasm
new file mode 100644
index 0000000000..0af7f54f6f
--- /dev/null
+++ b/IntelFsp2Pkg/FspSecCore/X64/Stack.nasm
@@ -0,0 +1,73 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Abstract:
+;
+; Switch the stack from temporary memory to permanent memory.
+;
+;------------------------------------------------------------------------------
+
+ SECTION .text
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; SecSwitchStack (
+; UINT64 TemporaryMemoryBase,
+; UINT64 PermanentMemoryBase
+; );
+;------------------------------------------------------------------------------
+global ASM_PFX(SecSwitchStack)
+ASM_PFX(SecSwitchStack):
+ ;
+ ; Save four register: rax, rbx, rcx, rdx
+ ;
+ push rax
+ push rbx
+ push rcx
+ push rdx
+
+ ;
+ ; !!CAUTION!! this function address's is pushed into stack after
+ ; migration of whole temporary memory, so need save it to permanent
+ ; memory at first!
+ ;
+
+ mov rbx, rcx ; Save the first parameter
+ mov rcx, rdx ; Save the second parameter
+
+ ;
+ ; Save this function's return address into permanent memory at first.
+ ; Then, Fixup the esp point to permanent memory
+ ;
+ mov rax, rsp
+ sub rax, rbx
+ add rax, rcx
+ mov rdx, qword [rsp] ; copy pushed register's value to permanent memory
+ mov qword [rax], rdx
+ mov rdx, qword [rsp + 8]
+ mov qword [rax + 8], rdx
+ mov rdx, qword [rsp + 16]
+ mov qword [rax + 16], rdx
+ mov rdx, qword [rsp + 24]
+ mov qword [rax + 24], rdx
+ mov rdx, qword [rsp + 32] ; Update this function's return address into permanent memory
+ mov qword [rax + 32], rdx
+ mov rsp, rax ; From now, rsp is pointed to permanent memory
+
+ ;
+ ; Fixup the rbp point to permanent memory
+ ;
+ mov rax, rbp
+ sub rax, rbx
+ add rax, rcx
+ mov rbp, rax ; From now, rbp is pointed to permanent memory
+
+ pop rdx
+ pop rcx
+ pop rbx
+ pop rax
+ ret
+
diff --git a/IntelFsp2Pkg/Include/Guid/FspHeaderFile.h b/IntelFsp2Pkg/Include/Guid/FspHeaderFile.h
index e5a9d7a2b4..79ad57116a 100644
--- a/IntelFsp2Pkg/Include/Guid/FspHeaderFile.h
+++ b/IntelFsp2Pkg/Include/Guid/FspHeaderFile.h
@@ -7,6 +7,8 @@

**/

+#include <Base.h>
+
#ifndef __FSP_HEADER_FILE_H__
#define __FSP_HEADER_FILE_H__

@@ -24,6 +26,12 @@

#define FSP_INFO_HEADER_SIGNATURE SIGNATURE_32 ('F', 'S', 'P', 'H')

+#define IMAGE_ATTRIBUTE_GRAPHICS_SUPPORT BIT0
+#define IMAGE_ATTRIBUTE_DISPATCH_MODE_SUPPORT BIT1
+#define IMAGE_ATTRIBUTE_64BIT_MODE_SUPPORT BIT2
+#define FSP_IA32 0
+#define FSP_X64 1
+
#pragma pack(1)

///
@@ -49,7 +57,7 @@ typedef struct {
UINT8 SpecVersion;
///
/// Byte 0x0B: Revision of the FSP Information Header.
- /// The Current value for this field is 0x6.
+ /// The Current value for this field is 0x7.
///
UINT8 HeaderRevision;
///
@@ -82,6 +90,10 @@ typedef struct {
UINT32 ImageBase;
///
/// Byte 0x20: Attribute for the FSP binary.
+ /// Bit 0: Graphics Support - Set to 1 when FSP supports enabling Graphics Display.
+ /// Bit 1: Dispatch Mode Support - Set to 1 when FSP supports the optional Dispatch Mode API defined in Section 7.2 and 9. This bit is only valid if FSP HeaderRevision is >= 4.
+ /// Bit 2: 64-bit mode support - Set to 1 to indicate FSP supports 64-bit long mode interfaces. Set to 0 to indicate FSP supports 32-bit mode interfaces. This bit is only valid if FSP HeaderRevision is >= 7.
+ /// Bits 15:3 - Reserved
///
UINT16 ImageAttribute;
///
diff --git a/IntelFsp2Pkg/Include/SaveRestoreSseAvxNasm.inc b/IntelFsp2Pkg/Include/SaveRestoreSseAvxNasm.inc
new file mode 100644
index 0000000000..e8bd91669d
--- /dev/null
+++ b/IntelFsp2Pkg/Include/SaveRestoreSseAvxNasm.inc
@@ -0,0 +1,284 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Abstract:
+;
+; Provide macro for register save/restore using SSE registers
+;
+;------------------------------------------------------------------------------
+
+;
+; Define SSE and AVX instruction set
+;
+;
+; Define SSE macros using SSE 4.1 instructions
+; args 1:XMM, 2:IDX, 3:REG
+;
+%macro SXMMN 3
+ pinsrq %1, %3, (%2 & 3)
+ %endmacro
+
+;
+; args 1:XMM, 2:REG, 3:IDX
+;
+%macro LXMMN 3
+ pextrq %2, %1, (%3 & 3)
+ %endmacro
+
+;
+; Define AVX macros using AVX instructions
+; Save XMM to YMM
+; args 1:YMM, 2:IDX (0 - lower 128bits, 1 - upper 128bits), 3:XMM
+;
+%macro SYMMN 3
+ vinsertf128 %1, %1, %3, %2
+ %endmacro
+
+;
+; Restore XMM from YMM
+; args 1:YMM, 2:XMM, 3:IDX (0 - lower 128bits, 1 - upper 128bits)
+;
+%macro LYMMN 3
+ vextractf128 %2, %1, %3
+ %endmacro
+
+;
+; Upper half of YMM7 to save RBP and RBX. Upper half of YMM8 to save RSI and RDI.
+; Modified: XMM5, YMM6, YMM7 and YMM8
+;
+%macro SAVE_REGS 0
+ SXMMN xmm5, 0, rbp
+ SXMMN xmm5, 1, rbx
+ SYMMN ymm7, 1, xmm5
+ SXMMN xmm5, 0, rsi
+ SXMMN xmm5, 1, rdi
+ SYMMN ymm8, 1, xmm5
+ SAVE_RSP
+ %endmacro
+
+;
+; Upper half of YMM7 to restore RBP and RBX. Upper half of YMM8 to restore RSI and RDI.
+; Modified: XMM5, RBP, RBX, RSI, RDI and RSP
+;
+%macro LOAD_REGS 0
+ LYMMN ymm7, xmm5, 1
+ LXMMN xmm5, rbp, 0
+ LXMMN xmm5, rbx, 1
+ LYMMN ymm8, xmm5, 1
+ LXMMN xmm5, rsi, 0
+ LXMMN xmm5, rdi, 1
+ LOAD_RSP
+ %endmacro
+;
+; Restore RBP from YMM7[128:191]
+; Modified: XMM5 and RBP
+;
+%macro LOAD_RBP 0
+ LYMMN ymm7, xmm5, 1
+ movq rbp, xmm5
+ %endmacro
+
+;
+; Restore RBX from YMM7[192:255]
+; Modified: XMM5 and RBX
+;
+%macro LOAD_RBX 0
+ LYMMN ymm7, xmm5, 1
+ LXMMN xmm5, rbx, 1
+ %endmacro
+
+;
+; Upper half of YMM6 to save/restore Time Stamp, RSP
+;
+;
+; Save Time Stamp to YMM6[192:255]
+; arg 1:general purpose register which holds time stamp
+; Modified: XMM5 and YMM6
+;
+%macro SAVE_TS 1
+ LYMMN ymm6, xmm5, 1
+ SXMMN xmm5, 1, %1
+ SYMMN ymm6, 1, xmm5
+ %endmacro
+
+;
+; Restore Time Stamp from YMM6[192:255]
+; arg 1:general purpose register where to save time stamp
+; Modified: XMM5 and %1
+;
+%macro LOAD_TS 1
+ LYMMN ymm6, xmm5, 1
+ LXMMN xmm5, %1, 1
+ %endmacro
+
+;
+; Save RSP to YMM6[128:191]
+; Modified: XMM5 and YMM6
+;
+%macro SAVE_RSP 0
+ LYMMN ymm6, xmm5, 1
+ SXMMN xmm5, 0, rsp
+ SYMMN ymm6, 1, xmm5
+ %endmacro
+
+;
+; Restore RSP from YMM6[128:191]
+; Modified: XMM5 and RSP
+;
+%macro LOAD_RSP 0
+ LYMMN ymm6, xmm5, 1
+ movq rsp, xmm5
+ %endmacro
+
+;
+; Upper half of YMM9 to save/restore UCODE status, BFV address
+;
+;
+; Save uCode status to YMM9[192:255]
+; arg 1:general purpose register which holds uCode status
+; Modified: XMM5 and YMM9
+;
+%macro SAVE_UCODE_STATUS 1
+ LYMMN ymm9, xmm5, 1
+ SXMMN xmm5, 0, %1
+ SYMMN ymm9, 1, xmm5
+ %endmacro
+
+;
+; Restore uCode status from YMM9[192:255]
+; arg 1:general purpose register where to save uCode status
+; Modified: XMM5 and %1
+;
+%macro LOAD_UCODE_STATUS 1
+ LYMMN ymm9, xmm5, 1
+ movq %1, xmm5
+ %endmacro
+
+;
+; Save BFV address to YMM9[128:191]
+; arg 1:general purpose register which holds BFV address
+; Modified: XMM5 and YMM9
+;
+%macro SAVE_BFV 1
+ LYMMN ymm9, xmm5, 1
+ SXMMN xmm5, 1, %1
+ SYMMN ymm9, 1, xmm5
+ %endmacro
+
+;
+; Restore BFV address from YMM9[128:191]
+; arg 1:general purpose register where to save BFV address
+; Modified: XMM5 and %1
+;
+%macro LOAD_BFV 1
+ LYMMN ymm9, xmm5, 1
+ LXMMN xmm5, %1, 1
+ %endmacro
+
+;
+; YMM7[128:191] for calling stack
+; arg 1:Entry
+; Modified: RSI, XMM5, YMM7
+;
+%macro CALL_YMM 1
+ mov rsi, %%ReturnAddress
+ LYMMN ymm7, xmm5, 1
+ SXMMN xmm5, 0, rsi
+ SYMMN ymm7, 1, xmm5
+ mov rsi, %1
+ jmp rsi
+%%ReturnAddress:
+ %endmacro
+;
+; Restore RIP from YMM7[128:191]
+; Modified: RSI, XMM5
+;
+%macro RET_YMM 0
+ LYMMN ymm7, xmm5, 1
+ movq rsi, xmm5
+ jmp rsi
+ %endmacro
+
+%macro ENABLE_SSE 0
+ ;
+ ; Initialize floating point units
+ ;
+ jmp NextAddress
+align 4
+ ;
+ ; Float control word initial value:
+ ; all exceptions masked, double-precision, round-to-nearest
+ ;
+FpuControlWord DW 027Fh
+ ;
+ ; Multimedia-extensions control word:
+ ; all exceptions masked, round-to-nearest, flush to zero for masked underflow
+ ;
+MmxControlWord DQ 01F80h
+SseError:
+ ;
+ ; Processor has to support SSE
+ ;
+ jmp SseError
+NextAddress:
+ finit
+ mov rax, FpuControlWord
+ fldcw [rax]
+
+ ;
+ ; Use CpuId instruction (CPUID.01H:EDX.SSE[bit 25] = 1) to test
+ ; whether the processor supports SSE instruction.
+ ;
+ mov rax, 1
+ cpuid
+ bt rdx, 25
+ jnc SseError
+
+ ;
+ ; SSE 4.1 support
+ ;
+ bt ecx, 19
+ jnc SseError
+
+ ;
+ ; Set OSFXSR bit (bit #9) & OSXMMEXCPT bit (bit #10)
+ ;
+ mov rax, cr4
+ or rax, 00000600h
+ mov cr4, rax
+
+ ;
+ ; The processor should support SSE instruction and we can use
+ ; ldmxcsr instruction
+ ;
+ mov rax, MmxControlWord
+ ldmxcsr [rax]
+ %endmacro
+
+%macro ENABLE_AVX 0
+ mov eax, 1
+ cpuid
+ and ecx, 10000000h
+ cmp ecx, 10000000h ; check AVX feature flag
+ je EnableAvx
+AvxError:
+ ;
+ ; Processor has to support AVX
+ ;
+ jmp AvxError
+EnableAvx:
+ ;
+ ; Set OSXSAVE bit (bit #18) to enable xgetbv/xsetbv instruction
+ ;
+ mov rax, cr4
+ or rax, 00040000h
+ mov cr4, rax
+
+ mov rcx, 0 ; index 0
+ xgetbv ; result in edx:eax
+ or eax, 00000006h ; Set XCR0 bit #1 and bit #2 to enable SSE state and AVX state
+ xsetbv
+ %endmacro
+
diff --git a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
index cd10b63c95..7aac68bf23 100644
--- a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
+++ b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
@@ -54,6 +54,7 @@ typedef struct {
UINT32 Flags[2];
UINT64 FspInfoHeader;
UINT64 ApiParam[2];
+ UINT64 Reserved; // The reserved QWORD is needed for stack alignment in X64.
UINT64 ApiRet; // 64bit stack format is different from the 32bit one due to x64 calling convention
} CONTEXT_STACK_64;

diff --git a/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm b/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm
index bd36fe4b8b..1ea1220608 100644
--- a/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm
+++ b/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm
@@ -47,7 +47,8 @@ ASM_PFX(Loader2PeiSwitchStack):
;------------------------------------------------------------------------------
global ASM_PFX(FspSwitchStack)
ASM_PFX(FspSwitchStack):
- ; Save current contexts
+ ; Save current contexts. The format must align with CONTEXT_STACK_64.
+ push rdx ; Reserved QWORD for stack alignment
push rdx ; ApiParam2
push rcx ; ApiParam1
push rax ; FspInfoHeader
@@ -67,6 +68,6 @@ ASM_PFX(FspSwitchStack):
add rsp, 16
POPA_64
popfq
- add rsp, 24 ; FspInfoHeader + ApiParam[2]
+ add rsp, 32 ; FspInfoHeader + ApiParam[2] + Reserved QWORD
ret

--
2.16.2.windows.1


[PATCH v3 3/8] IntelFsp2Pkg: Update FSP_GLOBAL_DATA and FSP_PLAT_DATA for X64

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
Updated FSP_GLOBAL_DATA and FSP_PLAT_DATA structures to support
both IA32 and X64.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
IntelFsp2Pkg/FspSecCore/SecFsp.c | 2 +-
IntelFsp2Pkg/Include/FspGlobalData.h | 51 +++++++++++++++++++++++++-----------
2 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.c b/IntelFsp2Pkg/FspSecCore/SecFsp.c
index 85fbc7664c..1ead3c9ce6 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.c
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.c
@@ -130,7 +130,7 @@ FspGlobalDataInit (
ZeroMem ((VOID *)PeiFspData, sizeof (FSP_GLOBAL_DATA));

PeiFspData->Signature = FSP_GLOBAL_DATA_SIGNATURE;
- PeiFspData->Version = 0;
+ PeiFspData->Version = FSP_GLOBAL_DATA_VERSION;
PeiFspData->CoreStack = BootLoaderStack;
PeiFspData->PerfIdx = 2;
PeiFspData->PerfSig = FSP_PERFORMANCE_DATA_SIGNATURE;
diff --git a/IntelFsp2Pkg/Include/FspGlobalData.h b/IntelFsp2Pkg/Include/FspGlobalData.h
index 2b534075ae..dcfeed7501 100644
--- a/IntelFsp2Pkg/Include/FspGlobalData.h
+++ b/IntelFsp2Pkg/Include/FspGlobalData.h
@@ -10,8 +10,9 @@

#include <FspEas.h>

-#define FSP_IN_API_MODE 0
-#define FSP_IN_DISPATCH_MODE 1
+#define FSP_IN_API_MODE 0
+#define FSP_IN_DISPATCH_MODE 1
+#define FSP_GLOBAL_DATA_VERSION 1

#pragma pack(1)

@@ -28,10 +29,11 @@ typedef enum {

typedef struct {
VOID *DataPtr;
- UINT32 MicrocodeRegionBase;
- UINT32 MicrocodeRegionSize;
- UINT32 CodeRegionBase;
- UINT32 CodeRegionSize;
+ UINTN MicrocodeRegionBase;
+ UINTN MicrocodeRegionSize;
+ UINTN CodeRegionBase;
+ UINTN CodeRegionSize;
+ UINTN Reserved;
} FSP_PLAT_DATA;

#define FSP_GLOBAL_DATA_SIGNATURE SIGNATURE_32 ('F', 'S', 'P', 'D')
@@ -42,15 +44,15 @@ typedef struct {
UINT32 Signature;
UINT8 Version;
UINT8 Reserved1[3];
+ ///
+ /// Offset 0x08
+ ///
UINTN CoreStack;
+ UINTN Reserved2;
+ ///
+ /// IA32: Offset 0x10; X64: Offset 0x18
+ ///
UINT32 StatusCode;
- UINT32 Reserved2[8];
- FSP_PLAT_DATA PlatformData;
- FSP_INFO_HEADER *FspInfoHeader;
- VOID *UpdDataPtr;
- VOID *TempRamInitUpdPtr;
- VOID *MemoryInitUpdPtr;
- VOID *SiliconInitUpdPtr;
UINT8 ApiIdx;
///
/// 0: FSP in API mode; 1: FSP in DISPATCH mode
@@ -60,15 +62,34 @@ typedef struct {
UINT8 Reserved3;
UINT32 NumberOfPhases;
UINT32 PhasesExecuted;
+ UINT32 Reserved4[8];
///
+ /// IA32: Offset 0x40; X64: Offset 0x48
+ /// Start of UINTN and pointer section
+ /// All UINTN and pointer members must be put in this section
+ /// except CoreStack and Reserved2. In addition, the number of
+ /// UINTN and pointer members must be even for natural alignment
+ /// in both IA32 and X64.
+ ///
+ FSP_PLAT_DATA PlatformData;
+ VOID *TempRamInitUpdPtr;
+ VOID *MemoryInitUpdPtr;
+ VOID *SiliconInitUpdPtr;
+ ///
+ /// IA32: Offset 0x64; X64: Offset 0x90
/// To store function parameters pointer
/// so it can be retrieved after stack switched.
///
VOID *FunctionParameterPtr;
- UINT8 Reserved4[16];
+ FSP_INFO_HEADER *FspInfoHeader;
+ VOID *UpdDataPtr;
+ ///
+ /// End of UINTN and pointer section
+ ///
+ UINT8 Reserved5[16];
UINT32 PerfSig;
UINT16 PerfLen;
- UINT16 Reserved5;
+ UINT16 Reserved6;
UINT32 PerfIdx;
UINT64 PerfData[32];
} FSP_GLOBAL_DATA;
--
2.16.2.windows.1


[PATCH v3 1/8] IntelFsp2Pkg: X64 compatible changes to support PEI in 64bit

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
1.Added EFIAPI to FspNotifyPhasePeimEntryPoint.
2.Changed AsmReadEsp to AsmReadStackPointer.
3.Changed the type of the return value of AsmReadStackPointer
from UINT32 to UINTN.
4.Changed the type of TemporaryMemoryBase, PermenentMemoryBase
and BootLoaderStack from UINT32 to UINTN.
5.Some type casting to pointers are UINT32. Changed them to
UINTN to accommodate both IA32 and X64.
6.Corrected some typos.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.c | 1 +
IntelFsp2Pkg/FspSecCore/Ia32/ReadEsp.nasm | 8 ++++----
IntelFsp2Pkg/FspSecCore/Ia32/Stack.nasm | 10 +++++-----
IntelFsp2Pkg/FspSecCore/SecFsp.c | 8 ++++----
IntelFsp2Pkg/FspSecCore/SecFsp.h | 2 +-
IntelFsp2Pkg/FspSecCore/SecFspApiChk.c | 8 ++++----
IntelFsp2Pkg/FspSecCore/SecMain.c | 8 ++++----
IntelFsp2Pkg/FspSecCore/SecMain.h | 10 +++++-----
IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/Ia32/Flat32.nasm | 2 +-
9 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.c b/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.c
index 88f5540fef..66d39cc70c 100644
--- a/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.c
+++ b/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.c
@@ -112,6 +112,7 @@ WaitForNotify (
@retval EFI_OUT_OF_RESOURCES Insufficient resources to create database
**/
EFI_STATUS
+EFIAPI
FspNotifyPhasePeimEntryPoint (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/ReadEsp.nasm b/IntelFsp2Pkg/FspSecCore/Ia32/ReadEsp.nasm
index 8046b43745..d40dad5a52 100644
--- a/IntelFsp2Pkg/FspSecCore/Ia32/ReadEsp.nasm
+++ b/IntelFsp2Pkg/FspSecCore/Ia32/ReadEsp.nasm
@@ -9,14 +9,14 @@
SECTION .text

;------------------------------------------------------------------------------
-; UINT32
+; UINTN
; EFIAPI
-; AsmReadEsp (
+; AsmReadStackPointer (
; VOID
; );
;------------------------------------------------------------------------------
-global ASM_PFX(AsmReadEsp)
-ASM_PFX(AsmReadEsp):
+global ASM_PFX(AsmReadStackPointer)
+ASM_PFX(AsmReadStackPointer):
mov eax, esp
ret

diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/Stack.nasm b/IntelFsp2Pkg/FspSecCore/Ia32/Stack.nasm
index 5a7e27c240..ce20639890 100644
--- a/IntelFsp2Pkg/FspSecCore/Ia32/Stack.nasm
+++ b/IntelFsp2Pkg/FspSecCore/Ia32/Stack.nasm
@@ -9,20 +9,20 @@
;
;------------------------------------------------------------------------------

-SECTION .text
+ SECTION .text

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; SecSwitchStack (
; UINT32 TemporaryMemoryBase,
-; UINT32 PermenentMemoryBase
+; UINT32 PermanentMemoryBase
; );
;------------------------------------------------------------------------------
global ASM_PFX(SecSwitchStack)
ASM_PFX(SecSwitchStack):
;
- ; Save three register: eax, ebx, ecx
+ ; Save four register: eax, ebx, ecx, edx
;
push eax
push ebx
@@ -55,7 +55,7 @@ ASM_PFX(SecSwitchStack):
mov dword [eax + 12], edx
mov edx, dword [esp + 16] ; Update this function's return address into permanent memory
mov dword [eax + 16], edx
- mov esp, eax ; From now, esp is pointed to permanent memory
+ mov esp, eax ; From now, esp is pointed to permanent memory

;
; Fixup the ebp point to permanent memory
@@ -63,7 +63,7 @@ ASM_PFX(SecSwitchStack):
mov eax, ebp
sub eax, ebx
add eax, ecx
- mov ebp, eax ; From now, ebp is pointed to permanent memory
+ mov ebp, eax ; From now, ebp is pointed to permanent memory

pop edx
pop ecx
diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.c b/IntelFsp2Pkg/FspSecCore/SecFsp.c
index 68e588dd41..85fbc7664c 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.c
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.c
@@ -26,7 +26,7 @@ FspGetExceptionHandler (
IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor;
FSP_INFO_HEADER *FspInfoHeader;

- FspInfoHeader = (FSP_INFO_HEADER *)AsmGetFspInfoHeader ();
+ FspInfoHeader = (FSP_INFO_HEADER *)(UINTN)AsmGetFspInfoHeader ();
ExceptionHandler = IdtEntryTemplate;
IdtGateDescriptor = (IA32_IDT_GATE_DESCRIPTOR *)&ExceptionHandler;
Entry = (IdtGateDescriptor->Bits.OffsetHigh << 16) | IdtGateDescriptor->Bits.OffsetLow;
@@ -115,7 +115,7 @@ SecGetPlatformData (
VOID
FspGlobalDataInit (
IN OUT FSP_GLOBAL_DATA *PeiFspData,
- IN UINT32 BootLoaderStack,
+ IN UINTN BootLoaderStack,
IN UINT8 ApiIdx
)
{
@@ -141,7 +141,7 @@ FspGlobalDataInit (
// Get FSP Header offset
// It may have multiple FVs, so look into the last one for FSP header
//
- PeiFspData->FspInfoHeader = (FSP_INFO_HEADER *)AsmGetFspInfoHeader ();
+ PeiFspData->FspInfoHeader = (FSP_INFO_HEADER *)(UINTN)AsmGetFspInfoHeader ();
SecGetPlatformData (PeiFspData);

//
@@ -154,7 +154,7 @@ FspGlobalDataInit (
//
FspmUpdDataPtr = (VOID *)GetFspApiParameter ();
if (FspmUpdDataPtr == NULL) {
- FspmUpdDataPtr = (VOID *)(PeiFspData->FspInfoHeader->ImageBase + PeiFspData->FspInfoHeader->CfgRegionOffset);
+ FspmUpdDataPtr = (VOID *)(UINTN)(PeiFspData->FspInfoHeader->ImageBase + PeiFspData->FspInfoHeader->CfgRegionOffset);
}

SetFspUpdDataPointer (FspmUpdDataPtr);
diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.h b/IntelFsp2Pkg/FspSecCore/SecFsp.h
index 7c9be85fe0..7fb31c3f87 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.h
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h
@@ -48,7 +48,7 @@ FspGetExceptionHandler (
VOID
FspGlobalDataInit (
IN OUT FSP_GLOBAL_DATA *PeiFspData,
- IN UINT32 BootLoaderStack,
+ IN UINTN BootLoaderStack,
IN UINT8 ApiIdx
);

diff --git a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
index 7d6ef11fe7..a746e8b64e 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
+++ b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
@@ -31,7 +31,7 @@ FspApiCallingCheck (
//
// NotifyPhase check
//
- if ((FspData == NULL) || ((UINT32)FspData == 0xFFFFFFFF)) {
+ if ((FspData == NULL) || ((UINTN)FspData == 0xFFFFFFFF)) {
Status = EFI_UNSUPPORTED;
} else {
if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE) {
@@ -42,7 +42,7 @@ FspApiCallingCheck (
//
// FspMemoryInit check
//
- if ((UINT32)FspData != 0xFFFFFFFF) {
+ if ((UINTN)FspData != 0xFFFFFFFF) {
Status = EFI_UNSUPPORTED;
} else if (EFI_ERROR (FspUpdSignatureCheck (ApiIdx, ApiParam))) {
Status = EFI_INVALID_PARAMETER;
@@ -51,7 +51,7 @@ FspApiCallingCheck (
//
// TempRamExit check
//
- if ((FspData == NULL) || ((UINT32)FspData == 0xFFFFFFFF)) {
+ if ((FspData == NULL) || ((UINTN)FspData == 0xFFFFFFFF)) {
Status = EFI_UNSUPPORTED;
} else {
if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE) {
@@ -62,7 +62,7 @@ FspApiCallingCheck (
//
// FspSiliconInit check
//
- if ((FspData == NULL) || ((UINT32)FspData == 0xFFFFFFFF)) {
+ if ((FspData == NULL) || ((UINTN)FspData == 0xFFFFFFFF)) {
Status = EFI_UNSUPPORTED;
} else {
if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE) {
diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c b/IntelFsp2Pkg/FspSecCore/SecMain.c
index d376fb8361..9e9332ffcd 100644
--- a/IntelFsp2Pkg/FspSecCore/SecMain.c
+++ b/IntelFsp2Pkg/FspSecCore/SecMain.c
@@ -54,7 +54,7 @@ SecStartup (
IN UINT32 TempRamBase,
IN VOID *BootFirmwareVolume,
IN PEI_CORE_ENTRY PeiCore,
- IN UINT32 BootLoaderStack,
+ IN UINTN BootLoaderStack,
IN UINT32 ApiIdx
)
{
@@ -233,7 +233,7 @@ SecTemporaryRamSupport (
GetFspGlobalDataPointer ()->OnSeparateStack = 1;

if (PcdGet8 (PcdFspHeapSizePercentage) == 0) {
- CurrentStack = AsmReadEsp ();
+ CurrentStack = AsmReadStackPointer ();
FspStackBase = (UINTN)GetFspEntryStack ();

StackSize = FspStackBase - CurrentStack;
@@ -292,8 +292,8 @@ SecTemporaryRamSupport (
// permanent memory.
//
SecSwitchStack (
- (UINT32)(UINTN)OldStack,
- (UINT32)(UINTN)NewStack
+ (UINTN)OldStack,
+ (UINTN)NewStack
);

return EFI_SUCCESS;
diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.h b/IntelFsp2Pkg/FspSecCore/SecMain.h
index 7794255af1..3c60b15f01 100644
--- a/IntelFsp2Pkg/FspSecCore/SecMain.h
+++ b/IntelFsp2Pkg/FspSecCore/SecMain.h
@@ -51,8 +51,8 @@ typedef struct _SEC_IDT_TABLE {
VOID
EFIAPI
SecSwitchStack (
- IN UINT32 TemporaryMemoryBase,
- IN UINT32 PermenentMemoryBase
+ IN UINTN TemporaryMemoryBase,
+ IN UINTN PermenentMemoryBase
);

/**
@@ -104,7 +104,7 @@ SecStartup (
IN UINT32 TempRamBase,
IN VOID *BootFirmwareVolume,
IN PEI_CORE_ENTRY PeiCore,
- IN UINT32 BootLoaderStack,
+ IN UINTN BootLoaderStack,
IN UINT32 ApiIdx
);

@@ -127,9 +127,9 @@ ProcessLibraryConstructorList (
@return value of esp.

**/
-UINT32
+UINTN
EFIAPI
-AsmReadEsp (
+AsmReadStackPointer (
VOID
);

diff --git a/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/Ia32/Flat32.nasm b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/Ia32/Flat32.nasm
index aef7f96d1d..7be570c4e5 100644
--- a/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/Ia32/Flat32.nasm
+++ b/IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/Ia32/Flat32.nasm
@@ -16,7 +16,7 @@ SECTION .text

%macro RET_ESI 0

- movd esi, mm7 ; restore ESP from MM7
+ movd esi, mm7 ; restore EIP from MM7
jmp esi

%endmacro
--
2.16.2.windows.1


[PATCH v3 2/8] IntelFsp2Pkg: Add FSPx_ARCH2_UPD support for X64

Kuo, Ted
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3893
1.Added FSPx_ARCH2_UPD structures which support both IA32 and X64.
2.Added FSPx_UPD_COMMON_FSP24 structures.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Ashraf Ali S <ashraf.ali.s@...>
Signed-off-by: Ted Kuo <ted.kuo@...>
---
IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm | 28 +++++
IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm | 96 +++++++++++++---
IntelFsp2Pkg/Include/FspEas/FspApi.h | 145 ++++++++++++++++++++++++-
IntelFsp2Pkg/Tools/GenCfgOpt.py | 4 +-
4 files changed, 254 insertions(+), 19 deletions(-)

diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm
index e7261b41cd..9fa9f28030 100644
--- a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm
+++ b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm
@@ -32,6 +32,24 @@ struc FSPM_UPD_COMMON
.size:
endstruc

+struc FSPM_UPD_COMMON_FSP24
+ ; FSP_UPD_HEADER {
+ .FspUpdHeader: resd 8
+ ; }
+ ; FSPM_ARCH2_UPD {
+ .Revision: resb 1
+ .Reserved: resb 3
+ .Length resd 1
+ .StackBase: resq 1
+ .StackSize: resq 1
+ .BootLoaderTolumSize: resd 1
+ .BootMode: resd 1
+ .FspEventHandler resq 1
+ .Reserved1: resb 24
+ ; }
+ .size:
+endstruc
+
;
; Following functions will be provided in C
;
@@ -124,12 +142,22 @@ ASM_PFX(FspApiCommonContinue):
pop eax

FspStackSetup:
+ mov ecx, [edx + FSPM_UPD_COMMON.Revision]
+ cmp ecx, 3
+ jae FspmUpdCommon2
+
;
; StackBase = temp memory base, StackSize = temp memory size
;
mov edi, [edx + FSPM_UPD_COMMON.StackBase]
mov ecx, [edx + FSPM_UPD_COMMON.StackSize]
+ jmp ChkFspHeapSize
+
+FspmUpdCommon2:
+ mov edi, [edx + FSPM_UPD_COMMON_FSP24.StackBase]
+ mov ecx, [edx + FSPM_UPD_COMMON_FSP24.StackSize]

+ChkFspHeapSize:
;
; Keep using bootloader stack if heap size % is 0
;
diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
index 7fd3d6d843..554b143ffa 100644
--- a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
+++ b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
@@ -84,8 +84,10 @@ struc LoadMicrocodeParamsFsp22
.FspUpdHeaderRevision: resb 1
.FspUpdHeaderReserved: resb 23
; }
- ; FSPT_ARCH_UPD{
- .FsptArchUpd: resd 8
+ ; FSPT_ARCH_UPD {
+ .FsptArchRevision: resb 1
+ .FsptArchReserved: resb 3
+ .FsptArchUpd: resd 7
; }
; FSPT_CORE_UPD {
.MicrocodeCodeAddr: resd 1
@@ -96,6 +98,28 @@ struc LoadMicrocodeParamsFsp22
.size:
endstruc

+struc LoadMicrocodeParamsFsp24
+ ; FSP_UPD_HEADER {
+ .FspUpdHeaderSignature: resd 2
+ .FspUpdHeaderRevision: resb 1
+ .FspUpdHeaderReserved: resb 23
+ ; }
+ ; FSPT_ARCH2_UPD {
+ .FsptArchRevision: resb 1
+ .FsptArchReserved: resb 3
+ .FsptArchLength: resd 1
+ .FspDebugHandler resq 1
+ .FsptArchUpd: resd 4
+ ; }
+ ; FSPT_CORE_UPD {
+ .MicrocodeCodeAddr: resq 1
+ .MicrocodeCodeSize: resq 1
+ .CodeRegionBase: resq 1
+ .CodeRegionSize: resq 1
+ ; }
+ .size:
+endstruc
+
;
; Define SSE macros
;
@@ -172,9 +196,9 @@ ASM_PFX(LoadMicrocodeDefault):
; Executed by SBSP and NBSP
; Beginning of microcode update region starts on paragraph boundary

- ;
;
; Save return address to EBP
+ ;
movd ebp, mm7

cmp esp, 0
@@ -188,8 +212,12 @@ ASM_PFX(LoadMicrocodeDefault):
; and report error if size is less than 2k
; first check UPD header revision
cmp byte [esp + LoadMicrocodeParamsFsp22.FspUpdHeaderRevision], 2
- jae Fsp22UpdHeader
+ jb Fsp20UpdHeader
+ cmp byte [esp + LoadMicrocodeParamsFsp22.FsptArchRevision], 2
+ je Fsp24UpdHeader
+ jmp Fsp22UpdHeader

+Fsp20UpdHeader:
; UPD structure is compliant with FSP spec 2.0/2.1
mov eax, dword [esp + LoadMicrocodeParams.MicrocodeCodeSize]
cmp eax, 0
@@ -213,6 +241,19 @@ Fsp22UpdHeader:
mov esi, dword [esp + LoadMicrocodeParamsFsp22.MicrocodeCodeAddr]
cmp esi, 0
jnz CheckMainHeader
+ jmp ParamError
+
+Fsp24UpdHeader:
+ ; UPD structure is compliant with FSP spec 2.4
+ mov eax, dword [esp + LoadMicrocodeParamsFsp24.MicrocodeCodeSize]
+ cmp eax, 0
+ jz Exit2
+ cmp eax, 0800h
+ jl ParamError
+
+ mov esi, dword [esp + LoadMicrocodeParamsFsp24.MicrocodeCodeAddr]
+ cmp esi, 0
+ jnz CheckMainHeader

ParamError:
mov eax, 080000002h
@@ -308,9 +349,13 @@ AdvanceFixedSize:

CheckAddress:
; Check UPD header revision
- cmp byte [esp + LoadMicrocodeParamsFsp22.FspUpdHeaderRevision], 2
- jae Fsp22UpdHeader1
+ cmp byte [esp + LoadMicrocodeParamsFsp22.FspUpdHeaderRevision], 2
+ jb Fsp20UpdHeader1
+ cmp byte [esp + LoadMicrocodeParamsFsp22.FsptArchRevision], 2
+ je Fsp24UpdHeader1;
+ jmp Fsp22UpdHeader1

+Fsp20UpdHeader1:
; UPD structure is compliant with FSP spec 2.0/2.1
; Is automatic size detection ?
mov eax, dword [esp + LoadMicrocodeParams.MicrocodeCodeSize]
@@ -336,6 +381,19 @@ Fsp22UpdHeader1:
jae Done ;Jif address is outside of microcode region
jmp CheckMainHeader

+Fsp24UpdHeader1:
+ ; UPD structure is compliant with FSP spec 2.4
+ ; Is automatic size detection ?
+ mov eax, dword [esp + LoadMicrocodeParamsFsp24.MicrocodeCodeSize]
+ cmp eax, 0ffffffffh
+ jz LoadMicrocodeDefault4
+
+ ; Address >= microcode region address + microcode region size?
+ add eax, dword [esp + LoadMicrocodeParamsFsp24.MicrocodeCodeAddr]
+ cmp esi, eax
+ jae Done ;Jif address is outside of microcode region
+ jmp CheckMainHeader
+
LoadMicrocodeDefault4:
; Is valid Microcode start point ?
cmp dword [esi + MicrocodeHdr.MicrocodeHdrVersion], 0ffffffffh
@@ -351,7 +409,7 @@ LoadCheck:
mov eax, 1
cpuid
mov ecx, MSR_IA32_BIOS_SIGN_ID
- rdmsr ; Get current microcode signature
+ rdmsr ; Get current microcode signature

; Verify this microcode update is not already loaded
cmp dword [esi + MicrocodeHdr.MicrocodeHdrRevision], edx
@@ -405,8 +463,12 @@ ASM_PFX(EstablishStackFsp):

; check UPD structure revision (edx + 8)
cmp byte [edx + LoadMicrocodeParamsFsp22.FspUpdHeaderRevision], 2
- jae Fsp22UpdHeader2
+ jb Fsp20UpdHeader2
+ cmp byte [esp + LoadMicrocodeParamsFsp22.FsptArchRevision], 2
+ je Fsp24UpdHeader2
+ jmp Fsp22UpdHeader2

+Fsp20UpdHeader2:
; UPD structure is compliant with FSP spec 2.0/2.1
push dword [edx + LoadMicrocodeParams.CodeRegionSize] ; Code size sizeof(FSPT_UPD_COMMON) + 12
push dword [edx + LoadMicrocodeParams.CodeRegionBase] ; Code base sizeof(FSPT_UPD_COMMON) + 8
@@ -420,6 +482,14 @@ Fsp22UpdHeader2:
push dword [edx + LoadMicrocodeParamsFsp22.CodeRegionBase] ; Code base sizeof(FSPT_UPD_COMMON) + 8
push dword [edx + LoadMicrocodeParamsFsp22.MicrocodeCodeSize] ; Microcode size sizeof(FSPT_UPD_COMMON) + 4
push dword [edx + LoadMicrocodeParamsFsp22.MicrocodeCodeAddr] ; Microcode base sizeof(FSPT_UPD_COMMON) + 0
+ jmp ContinueAfterUpdPush
+
+Fsp24UpdHeader2:
+ ; UPD structure is compliant with FSP spec 2.4
+ push dword [edx + LoadMicrocodeParamsFsp24.CodeRegionSize] ; Code size sizeof(FSPT_UPD_COMMON) + 24
+ push dword [edx + LoadMicrocodeParamsFsp24.CodeRegionBase] ; Code base sizeof(FSPT_UPD_COMMON) + 16
+ push dword [edx + LoadMicrocodeParamsFsp24.MicrocodeCodeSize] ; Microcode size sizeof(FSPT_UPD_COMMON) + 8
+ push dword [edx + LoadMicrocodeParamsFsp24.MicrocodeCodeAddr] ; Microcode base sizeof(FSPT_UPD_COMMON) + 0

ContinueAfterUpdPush:
;
@@ -517,13 +587,13 @@ ASM_PFX(TempRamInitApi):
cmp eax, 0
jnz TempRamInitExit

- LXMMN xmm6, eax, 3 ;Restore microcode status if no CAR init error from ECX-SLOT 3 in xmm6.
+ LXMMN xmm6, eax, 3 ;Restore microcode status if no CAR init error from ECX-SLOT 3 in xmm6.

TempRamInitExit:
- mov bl, al ; save al data in bl
- mov al, 07Fh ; API exit postcode 7f
- out 080h, al
- mov al, bl ; restore al data from bl
+ mov bl, al ; save al data in bl
+ mov al, 07Fh ; API exit postcode 7f
+ out 080h, al
+ mov al, bl ; restore al data from bl

;
; Load EBP, EBX, ESI, EDI & ESP from XMM7 & XMM6
diff --git a/IntelFsp2Pkg/Include/FspEas/FspApi.h b/IntelFsp2Pkg/Include/FspEas/FspApi.h
index 794f94dc7a..3526c7faf0 100644
--- a/IntelFsp2Pkg/Include/FspEas/FspApi.h
+++ b/IntelFsp2Pkg/Include/FspEas/FspApi.h
@@ -112,12 +112,12 @@ typedef struct {
///
typedef struct {
///
- /// Revision Revision of the structure is 1 for this version of the specification.
+ /// Revision of the structure is 1 for this version of the specification.
///
UINT8 Revision;
UINT8 Reserved[3];
///
- /// Length Length of the structure in bytes. The current value for this field is 32.
+ /// Length of the structure in bytes. The current value for this field is 32.
///
UINT32 Length;
///
@@ -128,6 +128,27 @@ typedef struct {
UINT8 Reserved1[20];
} FSPT_ARCH_UPD;

+///
+/// FSPT_ARCH2_UPD Configuration.
+///
+typedef struct {
+ ///
+ /// Revision of the structure is 2 for this version of the specification.
+ ///
+ UINT8 Revision;
+ UINT8 Reserved[3];
+ ///
+ /// Length of the structure in bytes. The current value for this field is 64.
+ ///
+ UINT32 Length;
+ ///
+ /// FspDebugHandler Optional debug handler for the bootloader to receive debug messages
+ /// occurring during FSP execution.
+ ///
+ EFI_PHYSICAL_ADDRESS FspDebugHandler;
+ UINT8 Reserved1[16];
+} FSPT_ARCH2_UPD;
+
///
/// FSPM_ARCH_UPD Configuration.
///
@@ -169,14 +190,57 @@ typedef struct {
UINT8 Reserved1[4];
} FSPM_ARCH_UPD;

+///
+/// FSPM_ARCH2_UPD Configuration.
+///
+typedef struct {
+ ///
+ /// Revision of the structure is 3 for this version of the specification.
+ ///
+ UINT8 Revision;
+ UINT8 Reserved[3];
+ ///
+ /// Lengthe of the structure in bytes. The current value for this field is 64.
+ ///
+ UINT32 Length;
+ ///
+ /// Pointer to the temporary stack base address to be
+ /// consumed inside FspMemoryInit() API.
+ ///
+ EFI_PHYSICAL_ADDRESS StackBase;
+ ///
+ /// Temporary stack size to be consumed inside
+ /// FspMemoryInit() API.
+ ///
+ UINT64 StackSize;
+ ///
+ /// Size of memory to be reserved by FSP below "top
+ /// of low usable memory" for bootloader usage.
+ ///
+ UINT32 BootLoaderTolumSize;
+ ///
+ /// Current boot mode.
+ ///
+ UINT32 BootMode;
+ ///
+ /// Optional event handler for the bootloader to be informed of events occurring during FSP execution.
+ /// This value is only valid if Revision is >= 2.
+ ///
+ EFI_PHYSICAL_ADDRESS FspEventHandler;
+ UINT8 Reserved1[24];
+} FSPM_ARCH2_UPD;
+
+///
+/// FSPS_ARCH_UPD Configuration.
+///
typedef struct {
///
- /// Revision Revision of the structure is 1 for this version of the specification.
+ /// Revision of the structure is 1 for this version of the specification.
///
UINT8 Revision;
UINT8 Reserved[3];
///
- /// Length Length of the structure in bytes. The current value for this field is 32.
+ /// Length of the structure in bytes. The current value for this field is 32.
///
UINT32 Length;
///
@@ -195,6 +259,35 @@ typedef struct {
UINT8 Reserved1[19];
} FSPS_ARCH_UPD;

+///
+/// FSPS_ARCH2_UPD Configuration.
+///
+typedef struct {
+ ///
+ /// Revision of the structure is 2 for this version of the specification.
+ ///
+ UINT8 Revision;
+ UINT8 Reserved[3];
+ ///
+ /// Length of the structure in bytes. The current value for this field is 32.
+ ///
+ UINT32 Length;
+ ///
+ /// FspEventHandler Optional event handler for the bootloader to be informed of events
+ /// occurring during FSP execution.
+ ///
+ EFI_PHYSICAL_ADDRESS FspEventHandler;
+ ///
+ /// A FSP binary may optionally implement multi-phase silicon initialization,
+ /// This is only supported if the FspMultiPhaseSiInitEntryOffset field in FSP_INFO_HEADER
+ /// is non-zero.
+ /// To enable multi-phase silicon initialization, the bootloader must set
+ /// EnableMultiPhaseSiliconInit to a non-zero value.
+ ///
+ UINT8 EnableMultiPhaseSiliconInit;
+ UINT8 Reserved1[15];
+} FSPS_ARCH2_UPD;
+
///
/// FSPT_UPD_COMMON Configuration.
///
@@ -220,6 +313,21 @@ typedef struct {
FSPT_ARCH_UPD FsptArchUpd;
} FSPT_UPD_COMMON_FSP22;

+///
+/// FSPT_UPD_COMMON Configuration for FSP spec. 2.4 and above.
+///
+typedef struct {
+ ///
+ /// FSP_UPD_HEADER Configuration.
+ ///
+ FSP_UPD_HEADER FspUpdHeader;
+
+ ///
+ /// FSPT_ARCH2_UPD Configuration.
+ ///
+ FSPT_ARCH2_UPD FsptArchUpd;
+} FSPT_UPD_COMMON_FSP24;
+
///
/// FSPM_UPD_COMMON Configuration.
///
@@ -234,6 +342,20 @@ typedef struct {
FSPM_ARCH_UPD FspmArchUpd;
} FSPM_UPD_COMMON;

+///
+/// FSPM_UPD_COMMON Configuration for FSP spec. 2.4 and above.
+///
+typedef struct {
+ ///
+ /// FSP_UPD_HEADER Configuration.
+ ///
+ FSP_UPD_HEADER FspUpdHeader;
+ ///
+ /// FSPM_ARCH2_UPD Configuration.
+ ///
+ FSPM_ARCH2_UPD FspmArchUpd;
+} FSPM_UPD_COMMON_FSP24;
+
///
/// FSPS_UPD_COMMON Configuration.
///
@@ -259,6 +381,21 @@ typedef struct {
FSPS_ARCH_UPD FspsArchUpd;
} FSPS_UPD_COMMON_FSP22;

+///
+/// FSPS_UPD_COMMON Configuration for FSP spec. 2.4 and above.
+///
+typedef struct {
+ ///
+ /// FSP_UPD_HEADER Configuration.
+ ///
+ FSP_UPD_HEADER FspUpdHeader;
+
+ ///
+ /// FSPS_ARCH2_UPD Configuration.
+ ///
+ FSPS_ARCH2_UPD FspsArchUpd;
+} FSPS_UPD_COMMON_FSP24;
+
///
/// Enumeration of FSP_INIT_PHASE for NOTIFY_PHASE.
///
diff --git a/IntelFsp2Pkg/Tools/GenCfgOpt.py b/IntelFsp2Pkg/Tools/GenCfgOpt.py
index 714b2d8b1a..690adfd947 100644
--- a/IntelFsp2Pkg/Tools/GenCfgOpt.py
+++ b/IntelFsp2Pkg/Tools/GenCfgOpt.py
@@ -1397,7 +1397,7 @@ EndList
UpdRegionCheck = ['FSPT', 'FSPM', 'FSPS'] # FSPX_UPD_REGION
UpdConfigCheck = ['FSP_T', 'FSP_M', 'FSP_S'] # FSP_X_CONFIG, FSP_X_TEST_CONFIG, FSP_X_RESTRICTED_CONFIG
UpdSignatureCheck = ['FSPT_UPD_SIGNATURE', 'FSPM_UPD_SIGNATURE', 'FSPS_UPD_SIGNATURE']
- ExcludedSpecificUpd = ['FSPT_ARCH_UPD', 'FSPM_ARCH_UPD', 'FSPS_ARCH_UPD']
+ ExcludedSpecificUpd = ['FSPT_ARCH', 'FSPM_ARCH', 'FSPS_ARCH']

IncLines = []
if InputHeaderFile != '':
@@ -1695,7 +1695,7 @@ EndList


def Usage():
- print ("GenCfgOpt Version 0.56")
+ print ("GenCfgOpt Version 0.57")
print ("Usage:")
print (" GenCfgOpt UPDTXT PlatformDscFile BuildFvDir [-D Macros]")
print (" GenCfgOpt HEADER PlatformDscFile BuildFvDir InputHFile [-D Macros]")
--
2.16.2.windows.1


[PATCH v3 0/8] Support PEI 64bit in IntelFsp2Pkg and IntelFsp2WrapperPkg

Kuo, Ted
 

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

Currently PEI drivers/libraries only support 32bit in IntelFsp2Pkg and
IntelFsp2WrapperPkg. The patches below are needed to support these
drivers/libraries in 64bit.

V2 changes:
1.Change FSPM_UPD_COMMON2 to FSPM_UPD_COMMON_FSP24 in FspApiEntryM.nasm.
2.Add FSPx_UPD_COMMON_FSP24 in FspApi.h.
3.Add 3 additional patches for supporting X64 in IntelFsp2WrapperPkg.

V3 changes:
1.Update FSPT_ARCH2_UPD and add FSPT_CORE_UPD back.
2.Use 0xFFFFFFFF instead of MAX_ADDRESS to reflect the default of FspData.
3.Remove EnableMultiPhaseMemoryInit from FSPM_ARCH2_UPD.
4.Bump GenCfgOpt version to 0.57.

Ted Kuo (8):
IntelFsp2Pkg: X64 compatible changes to support PEI in 64bit
IntelFsp2Pkg: Add FSPx_ARCH2_UPD support for X64
IntelFsp2Pkg: Update FSP_GLOBAL_DATA and FSP_PLAT_DATA for X64
IntelFsp2Pkg: FspSecCore support for X64
IntelFsp2Pkg: SecFspSecPlatformLibNull support for X64
IntelFsp2WrapperPkg: Adopt FSPM_UPD_COMMON_FSP24 for X64
IntelFsp2WrapperPkg: BaseFspWrapperApiLib support for X64
IntelFsp2WrapperPkg: SecFspWrapperPlatformSecLibSample support for X64

IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.c | 1 +
IntelFsp2Pkg/FspSecCore/Fsp22SecCoreS.inf | 8 +-
IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf | 9 +-
IntelFsp2Pkg/FspSecCore/FspSecCoreS.inf | 8 +-
IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf | 10 +-
.../FspSecCore/Ia32/FspApiEntryCommon.nasm | 4 +-
IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryM.nasm | 28 ++
IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm | 96 +++-
IntelFsp2Pkg/FspSecCore/Ia32/ReadEsp.nasm | 8 +-
IntelFsp2Pkg/FspSecCore/Ia32/Stack.nasm | 10 +-
IntelFsp2Pkg/FspSecCore/SecFsp.c | 10 +-
IntelFsp2Pkg/FspSecCore/SecFsp.h | 2 +-
IntelFsp2Pkg/FspSecCore/SecFspApiChk.c | 8 +-
IntelFsp2Pkg/FspSecCore/SecMain.c | 8 +-
IntelFsp2Pkg/FspSecCore/SecMain.h | 10 +-
IntelFsp2Pkg/FspSecCore/X64/Fsp22ApiEntryS.nasm | 103 +++++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryCommon.nasm | 76 ++++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryM.nasm | 262 +++++++++++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryS.nasm | 67 +++
IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm | 495 +++++++++++++++++++++
IntelFsp2Pkg/FspSecCore/X64/FspHelper.nasm | 34 ++
IntelFsp2Pkg/FspSecCore/X64/MicrocodeLoadNasm.inc | 11 +
IntelFsp2Pkg/FspSecCore/X64/ReadRsp.nasm | 22 +
IntelFsp2Pkg/FspSecCore/X64/Stack.nasm | 73 +++
IntelFsp2Pkg/Include/FspEas/FspApi.h | 145 +++++-
IntelFsp2Pkg/Include/FspGlobalData.h | 51 ++-
IntelFsp2Pkg/Include/Guid/FspHeaderFile.h | 14 +-
IntelFsp2Pkg/Include/SaveRestoreSseAvxNasm.inc | 284 ++++++++++++
IntelFsp2Pkg/IntelFsp2Pkg.dsc | 2 +-
.../Library/BaseFspCommonLib/FspCommonLib.c | 1 +
.../Library/BaseFspSwitchStackLib/X64/Stack.nasm | 5 +-
.../SecFspSecPlatformLibNull/Ia32/Flat32.nasm | 2 +-
.../SecFspSecPlatformLibNull.inf | 6 +-
.../SecFspSecPlatformLibNull/X64/Long64.nasm | 31 ++
.../SecFspSecPlatformLibNull/X64/SecCarInit.nasm | 40 ++
IntelFsp2Pkg/Tools/GenCfgOpt.py | 4 +-
.../FspmWrapperPeim/FspmWrapperPeim.c | 25 +-
.../BaseFspWrapperApiLib/FspWrapperApiLib.c | 42 +-
.../BaseFspWrapperApiLib/IA32/DispatchExecute.c | 21 +
.../BaseFspWrapperApiLib/X64/DispatchExecute.c | 45 +-
.../{Ia32 => }/Fsp.h | 0
.../Ia32/Stack.nasm | 6 +-
.../SecFspWrapperPlatformSecLibSample.inf | 7 +-
.../SecRamInitData.c | 22 +-
.../X64/PeiCoreEntry.nasm | 149 +++++++
.../X64/SecEntry.nasm | 171 +++++++
.../X64/Stack.nasm | 73 +++
47 files changed, 2404 insertions(+), 105 deletions(-)
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/Fsp22ApiEntryS.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryCommon.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryM.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryS.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/FspHelper.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/MicrocodeLoadNasm.inc
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/ReadRsp.nasm
create mode 100644 IntelFsp2Pkg/FspSecCore/X64/Stack.nasm
create mode 100644 IntelFsp2Pkg/Include/SaveRestoreSseAvxNasm.inc
create mode 100644 IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/Long64.nasm
create mode 100644 IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/X64/SecCarInit.nasm
rename IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/{Ia32 => }/Fsp.h (100%)
create mode 100644 IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/PeiCoreEntry.nasm
create mode 100644 IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/SecEntry.nasm
create mode 100644 IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/X64/Stack.nasm

--
2.16.2.windows.1


[PATCH v1 3/3] MdeModulePkg/FaultTolerantWrite: Consume Variable Info HOB

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

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

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

This supplements support added earlier for the variable store base
address and size passed with the Variable Flash Information HOB.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c =
| 111 +++++++++++++++++---
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c =
| 7 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c =
| 92 ++++++++++++++--
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h =
| 9 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf =
| 11 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf =
| 11 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon=
eMm.inf | 11 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf =
| 10 +-
8 files changed, 221 insertions(+), 41 deletions(-)

diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/Mde=
ModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
index 661e1487673b..5066fe0d3711 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
@@ -972,6 +972,48 @@ GetPreviousRecordOfWrites (
return EFI_SUCCESS;
}
=20
+/**
+ Get the HOB that contains variable flash information.
+
+ @param[out] VariableFlashInfo Pointer to a pointer to set to the var=
iable flash information structure.
+
+ @retval EFI_SUCCESS Variable flash information was found s=
uccessfully.
+ @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is=
NULL.
+ @retval EFI_NOT_FOUND Variable flash information could not b=
e found.
+
+**/
+EFI_STATUS
+GetVariableFlashInfo (
+ OUT VARIABLE_FLASH_INFO **VariableFlashInfo
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ if (VariableFlashInfo =3D=3D NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid);
+ if (GuidHob =3D=3D NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob);
+
+ //
+ // Assert if more than one variable flash information HOB is present.
+ //
+ DEBUG_CODE (
+ if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidH=
ob)) !=3D NULL)) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HO=
Bs\n"));
+ ASSERT (FALSE);
+ }
+
+ );
+
+ return EFI_SUCCESS;
+}
+
/**
Allocate private data for FTW driver and initialize it.
=20
@@ -987,22 +1029,71 @@ InitFtwDevice (
OUT EFI_FTW_DEVICE **FtwData
)
{
- EFI_FTW_DEVICE *FtwDevice;
+ EFI_STATUS Status;
+ EFI_STATUS VariableFlashInfoStatus;
+ UINTN FtwWorkingSize;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
+ EFI_FTW_DEVICE *FtwDevice;
+
+ FtwWorkingSize =3D 0;
+ VariableFlashInfoStatus =3D GetVariableFlashInfo (&VariableFlashInfo);
+ if (!EFI_ERROR (VariableFlashInfoStatus)) {
+ Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwWorkingLength, &=
FtwWorkingSize);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ FtwWorkingSize =3D 0;
+ }
+ }
+
+ if (FtwWorkingSize =3D=3D 0) {
+ FtwWorkingSize =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize)=
;
+ }
=20
//
// Allocate private data of this driver,
// Including the FtwWorkSpace[FTW_WORK_SPACE_SIZE].
//
- FtwDevice =3D AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + PcdGet32 (Pc=
dFlashNvStorageFtwWorkingSize));
+ FtwDevice =3D AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + FtwWorkingSi=
ze);
if (FtwDevice =3D=3D NULL) {
return EFI_OUT_OF_RESOURCES;
}
=20
+ FtwDevice->WorkSpaceLength =3D FtwWorkingSize;
+
+ if (!EFI_ERROR (VariableFlashInfoStatus)) {
+ // This driver currently assumes the size will be UINT32 so only acc=
ept
+ // that for now.
+ Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwSpareLength, &Ft=
wDevice->SpareAreaLength);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ FtwDevice->SpareAreaLength =3D 0;
+ }
+
+ FtwDevice->SpareAreaAddress =3D VariableFlashInfo->FtwSpareBaseAddre=
ss;
+ FtwDevice->WorkSpaceAddress =3D VariableFlashInfo->FtwWorkingBaseAdd=
ress;
+ }
+
+ if (FtwDevice->SpareAreaLength =3D=3D 0) {
+ FtwDevice->SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtw=
SpareSize);
+ }
+
+ if (FtwDevice->SpareAreaAddress =3D=3D 0) {
+ FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdF=
lashNvStorageFtwSpareBase64);
+ if (FtwDevice->SpareAreaAddress =3D=3D 0) {
+ FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (Pc=
dFlashNvStorageFtwSpareBase);
+ }
+ }
+
+ if (FtwDevice->WorkSpaceAddress =3D=3D 0) {
+ FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdF=
lashNvStorageFtwWorkingBase64);
+ if (FtwDevice->WorkSpaceAddress =3D=3D 0) {
+ FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (Pc=
dFlashNvStorageFtwWorkingBase);
+ }
+ }
+
//
// Initialize other parameters, and set WorkSpace as FTW_ERASED_BYTE.
//
- FtwDevice->WorkSpaceLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWo=
rkingSize);
- FtwDevice->SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwSp=
areSize);
if ((FtwDevice->WorkSpaceLength =3D=3D 0) || (FtwDevice->SpareAreaLeng=
th =3D=3D 0)) {
DEBUG ((DEBUG_ERROR, "Ftw: Workspace or Spare block does not exist!\=
n"));
FreePool (FtwDevice);
@@ -1015,16 +1106,6 @@ InitFtwDevice (
FtwDevice->FtwWorkSpaceLba =3D (EFI_LBA)(-1);
FtwDevice->FtwSpareLba =3D (EFI_LBA)(-1);
=20
- FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFla=
shNvStorageFtwWorkingBase64);
- if (FtwDevice->WorkSpaceAddress =3D=3D 0) {
- FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdF=
lashNvStorageFtwWorkingBase);
- }
-
- FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFla=
shNvStorageFtwSpareBase64);
- if (FtwDevice->SpareAreaAddress =3D=3D 0) {
- FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdF=
lashNvStorageFtwSpareBase);
- }
-
*FtwData =3D FtwDevice;
return EFI_SUCCESS;
}
@@ -1277,7 +1358,7 @@ InitFtwProtocol (
FtwDevice->FtwLastWriteHeader =3D NULL;
FtwDevice->FtwLastWriteRecord =3D NULL;
=20
- InitializeLocalWorkSpaceHeader ();
+ InitializeLocalWorkSpaceHeader (FtwDevice->WorkSpaceLength);
=20
//
// Refresh the working space data from working block
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBl=
ock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
index 61e7a92ccea1..fd563643eb63 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
@@ -16,10 +16,13 @@ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBloc=
kHeader =3D { ZERO_GUID, 0, 0
=20
Since Signature and WriteQueueSize have been known, Crc can be calcula=
ted out,
then the work space header will be fixed.
+
+ @param[in] WorkSpaceLength Length in bytes of the FTW workspace a=
rea.
+
**/
VOID
InitializeLocalWorkSpaceHeader (
- VOID
+ IN UINTN WorkSpaceLength
)
{
//
@@ -46,7 +49,7 @@ InitializeLocalWorkSpaceHeader (
&gEdkiiWorkingBlockSignatureGuid,
sizeof (EFI_GUID)
);
- mWorkingBlockHeader.WriteQueueSize =3D PcdGet32 (PcdFlashNvStorageFtwW=
orkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
+ mWorkingBlockHeader.WriteQueueSize =3D WorkSpaceLength - sizeof (EFI_F=
AULT_TOLERANT_WORKING_BLOCK_HEADER);
=20
//
// Crc is calculated with all the fields except Crc and STATE, so leav=
e them as FTW_ERASED_BYTE.
diff --git a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWr=
itePei.c b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWrit=
ePei.c
index 15543f12ed29..7abf8f72d569 100644
--- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
c
+++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
c
@@ -11,11 +11,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
=20
#include <Guid/SystemNvDataGuid.h>
#include <Guid/FaultTolerantWrite.h>
+#include <Guid/VariableFlashInfo.h>
#include <Library/PeiServicesLib.h>
#include <Library/PcdLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/HobLib.h>
+#include <Library/SafeIntLib.h>
=20
EFI_PEI_PPI_DESCRIPTOR mPpiListVariable =3D {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
@@ -186,6 +188,48 @@ IsValidWorkSpace (
return TRUE;
}
=20
+/**
+ Get the HOB that contains variable flash information.
+
+ @param[out] VariableFlashInfo Pointer to a pointer to set to the var=
iable flash information structure.
+
+ @retval EFI_SUCCESS Variable flash information was found s=
uccessfully.
+ @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is=
NULL.
+ @retval EFI_NOT_FOUND Variable flash information could not b=
e found.
+
+**/
+EFI_STATUS
+GetVariableFlashInfo (
+ OUT VARIABLE_FLASH_INFO **VariableFlashInfo
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ if (VariableFlashInfo =3D=3D NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid);
+ if (GuidHob =3D=3D NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob);
+
+ //
+ // Assert if more than one variable flash information HOB is present.
+ //
+ DEBUG_CODE (
+ if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidH=
ob)) !=3D NULL)) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HO=
Bs\n"));
+ ASSERT (FALSE);
+ }
+
+ );
+
+ return EFI_SUCCESS;
+}
+
/**
Main entry for Fault Tolerant Write PEIM.
=20
@@ -207,6 +251,7 @@ PeimFaultTolerantWriteInitialize (
EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkingBlockHeader;
EFI_FAULT_TOLERANT_WRITE_HEADER *FtwLastWriteHeader;
EFI_FAULT_TOLERANT_WRITE_RECORD *FtwLastWriteRecord;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
EFI_PHYSICAL_ADDRESS WorkSpaceAddress;
UINTN WorkSpaceLength;
EFI_PHYSICAL_ADDRESS SpareAreaAddress;
@@ -218,19 +263,52 @@ PeimFaultTolerantWriteInitialize (
FtwLastWriteHeader =3D NULL;
FtwLastWriteRecord =3D NULL;
=20
- WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorage=
FtwWorkingBase64);
- if (WorkSpaceAddress =3D=3D 0) {
- WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStora=
geFtwWorkingBase);
+ SpareAreaAddress =3D 0;
+ SpareAreaLength =3D 0;
+ WorkSpaceAddress =3D 0;
+ WorkSpaceLength =3D 0;
+
+ Status =3D GetVariableFlashInfo (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ // This driver currently assumes the size will be UINT32 so only acc=
ept
+ // that for now.
+ Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwSpareLength, &Sp=
areAreaLength);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ SpareAreaLength =3D 0;
+ }
+
+ Status =3D SafeUint64ToUintn (VariableFlashInfo->FtwWorkingLength, &=
WorkSpaceLength);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ WorkSpaceLength =3D 0;
+ }
+
+ SpareAreaAddress =3D VariableFlashInfo->FtwSpareBaseAddress;
+ WorkSpaceAddress =3D VariableFlashInfo->FtwWorkingBaseAddress;
}
=20
- WorkSpaceLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
+ if (SpareAreaLength =3D=3D 0) {
+ SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
+ }
+
+ if (WorkSpaceLength =3D=3D 0) {
+ WorkSpaceLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize=
);
+ }
=20
- SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorage=
FtwSpareBase64);
if (SpareAreaAddress =3D=3D 0) {
- SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStora=
geFtwSpareBase);
+ SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStora=
geFtwSpareBase64);
+ if (SpareAreaAddress =3D=3D 0) {
+ SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvSto=
rageFtwSpareBase);
+ }
}
=20
- SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
+ if (WorkSpaceAddress =3D=3D 0) {
+ WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStora=
geFtwWorkingBase64);
+ if (WorkSpaceAddress =3D=3D 0) {
+ WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvSto=
rageFtwWorkingBase);
+ }
+ }
=20
//
// The address of FTW working base and spare base must not be 0.
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
ite.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
index c14e47b5c7b2..40ef44c069eb 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
@@ -14,11 +14,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <PiDxe.h>
=20
#include <Guid/SystemNvDataGuid.h>
+#include <Guid/VariableFlashInfo.h>
#include <Guid/ZeroGuid.h>
#include <Protocol/FaultTolerantWrite.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Protocol/SwapAddressRange.h>
=20
+#include <Library/HobLib.h>
+#include <Library/SafeIntLib.h>
#include <Library/PcdLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
@@ -706,12 +709,16 @@ InitFtwProtocol (
/**
Initialize a local work space header.
=20
+
Since Signature and WriteQueueSize have been known, Crc can be calcula=
ted out,
then the work space header will be fixed.
+
+ @param[in] WorkSpaceLength Length in bytes of the FTW workspace a=
rea.
+
**/
VOID
InitializeLocalWorkSpaceHeader (
- VOID
+ IN UINTN WorkSpaceLength
);
=20
/**
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteDxe.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteDxe.inf
index 96165614d178..923f0231a047 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.=
inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.=
inf
@@ -46,6 +46,8 @@ [LibraryClasses]
UefiLib
PcdLib
ReportStatusCodeLib
+ HobLib
+ SafeIntLib
=20
[Guids]
#
@@ -54,6 +56,7 @@ [Guids]
## CONSUMES ## GUID
## PRODUCES ## GUID
gEdkiiWorkingBlockSignatureGuid
+ gVariableFlashInfoHobGuid ## CONSUMES ## HOB
=20
[Protocols]
gEfiSwapAddressRangeProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdF=
ullFtwServiceEnable ## SOMETIMES_CONSUMES
@@ -67,11 +70,11 @@ [FeaturePcd]
=20
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## S=
OMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## S=
OMETIMES_CONSUMES
=20
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteSmm.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteSmm.inf
index 8cc6028470d8..bbed17e4b611 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.=
inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.=
inf
@@ -52,6 +52,8 @@ [LibraryClasses]
ReportStatusCodeLib
SmmMemLib
BaseLib
+ HobLib
+ SafeIntLib
=20
[Guids]
#
@@ -60,6 +62,7 @@ [Guids]
## CONSUMES ## GUID
## PRODUCES ## GUID
gEdkiiWorkingBlockSignatureGuid
+ gVariableFlashInfoHobGuid ## CONSUMES ## HOB
=20
[Protocols]
gEfiSmmSwapAddressRangeProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.P=
cdFullFtwServiceEnable ## SOMETIMES_CONSUMES
@@ -76,11 +79,11 @@ [FeaturePcd]
=20
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## S=
OMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## S=
OMETIMES_CONSUMES
=20
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteStandaloneMm.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultT=
olerantWriteStandaloneMm.inf
index d0fab7d9414f..0b394b04da7b 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStan=
daloneMm.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStan=
daloneMm.inf
@@ -46,10 +46,12 @@ [LibraryClasses]
BaseLib
BaseMemoryLib
DebugLib
+ HobLib
MemoryAllocationLib
MmServicesTableLib
PcdLib
ReportStatusCodeLib
+ SafeIntLib
StandaloneMmDriverEntryPoint
=20
[Guids]
@@ -59,6 +61,7 @@ [Guids]
## CONSUMES ## GUID
## PRODUCES ## GUID
gEdkiiWorkingBlockSignatureGuid
+ gVariableFlashInfoHobGuid ## CONSUMES ## HOB
=20
[Protocols]
gEfiSmmSwapAddressRangeProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.P=
cdFullFtwServiceEnable ## SOMETIMES_CONSUMES
@@ -75,11 +78,11 @@ [FeaturePcd]
=20
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## S=
OMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## S=
OMETIMES_CONSUMES
=20
[Depex]
TRUE
diff --git a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWr=
itePei.inf b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWr=
itePei.inf
index f90892ad4493..ff9d53bf7040 100644
--- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
inf
+++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
inf
@@ -39,6 +39,7 @@ [LibraryClasses]
HobLib
BaseMemoryLib
PcdLib
+ SafeIntLib
=20
[Guids]
## SOMETIMES_PRODUCES ## HOB
@@ -46,14 +47,15 @@ [Guids]
gEdkiiFaultTolerantWriteGuid
gEdkiiWorkingBlockSignatureGuid ## SOMETIMES_CONSUMES =
## GUID
gEfiSystemNvDataFvGuid ## SOMETIMES_CONSUMES =
## GUID
+ gVariableFlashInfoHobGuid ## CONSUMES =
## HOB
=20
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## S=
OMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## S=
OMETIMES_CONSUMES
=20
[Depex]
TRUE
--=20
2.28.0.windows.1


[PATCH v1 2/3] MdeModulePkg/Variable: Consume Variable Info HOB

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

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

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

If the HOB is not present, the drivers will continue to directly
read flash information from PCDs.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Universal/Variable/Pei/Variable.c | 66=
++++++++++++++++++--
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 42=
+++++++++++++
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 25=
++++++--
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 20=
++++--
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 20=
+++++-
MdeModulePkg/Universal/Variable/Pei/Variable.h | 2=
+
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 6=
+-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 17=
+++++
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 6=
+-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 6=
+-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 6=
+-
11 files changed, 194 insertions(+), 22 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePk=
g/Universal/Variable/Pei/Variable.c
index b36dd0de67b2..b19a26965ef2 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -553,6 +553,48 @@ GetHobVariableStore (
}
}
=20
+/**
+ Get the HOB that contains variable flash information.
+
+ @param[out] VariableFlashInfo Pointer to a pointer to set to the var=
iable flash information structure.
+
+ @retval EFI_SUCCESS Variable flash information was found s=
uccessfully.
+ @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is=
NULL.
+ @retval EFI_NOT_FOUND Variable flash information could not b=
e found.
+
+**/
+EFI_STATUS
+GetVariableFlashInfo (
+ OUT VARIABLE_FLASH_INFO **VariableFlashInfo
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ if (VariableFlashInfo =3D=3D NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid);
+ if (GuidHob =3D=3D NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob);
+
+ //
+ // Assert if more than one variable flash information HOB is present.
+ //
+ DEBUG_CODE (
+ if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidH=
ob)) !=3D NULL)) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HO=
Bs\n"));
+ ASSERT (FALSE);
+ }
+
+ );
+
+ return EFI_SUCCESS;
+}
+
/**
Return the variable store header and the store info based on the Index=
.
=20
@@ -567,8 +609,10 @@ GetVariableStore (
OUT VARIABLE_STORE_INFO *StoreInfo
)
{
+ EFI_STATUS Status;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
VARIABLE_STORE_HEADER *VariableStoreHeader;
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT32 NvStorageSize;
@@ -591,11 +635,23 @@ GetVariableStore (
// Emulated non-volatile variable mode is not enabled.
//
=20
- NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize);
- NvStorageBase =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvSto=
rageVariableBase64) !=3D 0 ?
- PcdGet64 (PcdFlashNvStora=
geVariableBase64) :
- PcdGet32 (PcdFlashNvStora=
geVariableBase)
- );
+ Status =3D GetVariableFlashInfo (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ NvStorageBase =3D VariableFlashInfo->NvStorageBaseAddress;
+ Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvSto=
rageLength, &NvStorageSize);
+ // This driver currently assumes the size will be UINT32 so on=
ly accept
+ // that for now.
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ if (EFI_ERROR (Status)) {
+ NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize);
+ NvStorageBase =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvS=
torageVariableBase64) !=3D 0 ?
+ PcdGet64 (PcdFlashNvSto=
rageVariableBase64) :
+ PcdGet32 (PcdFlashNvSto=
rageVariableBase)
+ );
+ }
+
ASSERT (NvStorageBase !=3D 0);
=20
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeM=
odulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 6c1a3440ac8c..6ab4efd62a7e 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -3701,6 +3701,48 @@ GetHobVariableStore (
return EFI_SUCCESS;
}
=20
+/**
+ Get the HOB that contains variable flash information.
+
+ @param[out] VariableFlashInfo Pointer to a pointer to set to the var=
iable flash information structure.
+
+ @retval EFI_SUCCESS Variable flash information was found s=
uccessfully.
+ @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is=
NULL.
+ @retval EFI_NOT_FOUND Variable flash information could not b=
e found.
+
+**/
+EFI_STATUS
+GetVariableFlashInfo (
+ OUT VARIABLE_FLASH_INFO **VariableFlashInfo
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ if (VariableFlashInfo =3D=3D NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid);
+ if (GuidHob =3D=3D NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob);
+
+ //
+ // Assert if more than one variable flash information HOB is present.
+ //
+ DEBUG_CODE (
+ if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidH=
ob)) !=3D NULL)) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HO=
Bs\n"));
+ ASSERT (FALSE);
+ }
+
+ );
+
+ return EFI_SUCCESS;
+}
+
/**
Initializes variable store area for non-volatile and volatile variable=
.
=20
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c b/M=
deModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
index 03fec3048dc4..1dc121d78e35 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
@@ -416,6 +416,7 @@ FtwNotificationEvent (
EFI_STATUS Status;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
EFI_PHYSICAL_ADDRESS BaseAddress;
@@ -423,6 +424,7 @@ FtwNotificationEvent (
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
UINTN FtwMaxBlockSize;
+ UINT32 NvStorageVariableSize;
=20
//
// Ensure FTW protocol is installed.
@@ -432,14 +434,29 @@ FtwNotificationEvent (
return;
}
=20
+ Status =3D GetVariableFlashInfo (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ NvStorageVariableBase =3D VariableFlashInfo->NvStorageBaseAddress;
+ Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvS=
torageLength, &NvStorageVariableSize);
+ // This driver currently assumes the size will be UINT32 so only acc=
ept
+ // that for now.
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ if (EFI_ERROR (Status)) {
+ NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE;
+ NvStorageVariableSize =3D PcdGet32 (PcdFlashNvStorageVariableSize);
+ }
+
+ ASSERT (NvStorageVariableBase !=3D 0);
+
+ VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->Header=
Length;
+
Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize=
);
if (!EFI_ERROR (Status)) {
- ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz=
e);
+ ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize);
}
=20
- NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE;
- VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->He=
aderLength;
-
//
// Let NonVolatileVariableBase point to flash variable store base dire=
ctly after FTW ready.
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolati=
le.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
index 5e9d40b67ac2..e424c210248a 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
@@ -137,6 +137,7 @@ InitRealNonVolatileVariableStore (
{
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
VARIABLE_STORE_HEADER *VariableStore;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
UINT32 VariableStoreLength;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_PHYSICAL_ADDRESS NvStorageBase;
@@ -153,19 +154,30 @@ InitRealNonVolatileVariableStore (
=20
mVariableModuleGlobal->FvbInstance =3D NULL;
=20
+ Status =3D GetVariableFlashInfo (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ NvStorageBase =3D VariableFlashInfo->NvStorageBaseAddress;
+ Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvStorageLe=
ngth, &NvStorageSize);
+ // This driver currently assumes the size will be UINT32 so only acc=
ept that for now.
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ if (EFI_ERROR (Status)) {
+ NvStorageBase =3D NV_STORAGE_VARIABLE_BASE;
+ NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize);
+ }
+
+ ASSERT (NvStorageBase !=3D 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 =3D PcdGet32 (PcdFlashNvStorageVariableSize);
NvStorageData =3D AllocateRuntimeZeroPool (NvStorageSize);
if (NvStorageData =3D=3D NULL) {
return EFI_OUT_OF_RESOURCES;
}
=20
- NvStorageBase =3D NV_STORAGE_VARIABLE_BASE;
- ASSERT (NvStorageBase !=3D 0);
-
//
// Copy NV storage data to the memory buffer.
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/M=
deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
index 517cae7b00f8..c8667dd6ca34 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
@@ -1082,8 +1082,10 @@ SmmFtwNotificationEvent (
EFI_PHYSICAL_ADDRESS VariableStoreBase;
EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;
EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
UINTN FtwMaxBlockSize;
+ UINT32 NvStorageVariableSize;
=20
if (mVariableModuleGlobal->FvbInstance !=3D NULL) {
return EFI_SUCCESS;
@@ -1097,9 +1099,25 @@ SmmFtwNotificationEvent (
return Status;
}
=20
+ Status =3D GetVariableFlashInfo (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ NvStorageVariableBase =3D VariableFlashInfo->NvStorageBaseAddress;
+ Status =3D SafeUint64ToUint32 (VariableFlashInfo->NvS=
torageLength, &NvStorageVariableSize);
+ // This driver currently assumes the size will be UINT32 so only acc=
ept that for now.
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ if (EFI_ERROR (Status)) {
+ NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE;
+ NvStorageVariableSize =3D PcdGet32 (PcdFlashNvStorageVariableSize);
+ }
+
+ ASSERT (NvStorageVariableBase !=3D 0);
+ VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->Header=
Length;
+
Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize=
);
if (!EFI_ERROR (Status)) {
- ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz=
e);
+ ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize);
}
=20
NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE;
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.h b/MdeModulePk=
g/Universal/Variable/Pei/Variable.h
index 7f9ad5bfc357..b2ba30b841c1 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.h
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.h
@@ -20,7 +20,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/PeiServicesLib.h>
+#include <Library/SafeIntLib.h>
=20
+#include <Guid/VariableFlashInfo.h>
#include <Guid/VariableFormat.h>
#include <Guid/VariableIndexTable.h>
#include <Guid/SystemNvDataGuid.h>
diff --git a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf b/MdeMod=
ulePkg/Universal/Variable/Pei/VariablePei.inf
index 7cbdd2385e8f..2557219f9b30 100644
--- a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
+++ b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
@@ -39,6 +39,7 @@ [LibraryClasses]
DebugLib
PeiServicesTablePointerLib
PeiServicesLib
+ SafeIntLib
=20
[Guids]
## CONSUMES ## GUID # Variable store header
@@ -54,14 +55,15 @@ [Guids]
## SOMETIMES_CONSUMES ## HOB
## CONSUMES ## GUID # Dependence
gEdkiiFaultTolerantWriteGuid
+ gVariableFlashInfoHobGuid ## CONSUMES ## HOB
=20
[Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
=20
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## S=
OMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## S=
OMETIMES_CONSUMES
=20
[Depex]
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeM=
odulePkg/Universal/Variable/RuntimeDxe/Variable.h
index 31e408976a35..c9bbd1568567 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
@@ -31,12 +31,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>
#include <Library/AuthVariableLib.h>
#include <Library/VarCheckLib.h>
+#include <Library/SafeIntLib.h>
#include <Guid/GlobalVariable.h>
#include <Guid/EventGroup.h>
#include <Guid/VariableFormat.h>
#include <Guid/SystemNvDataGuid.h>
#include <Guid/FaultTolerantWrite.h>
#include <Guid/VarErrorFlag.h>
+#include <Guid/VariableFlashInfo.h>
=20
#include "PrivilegePolymorphic.h"
=20
@@ -126,6 +128,21 @@ typedef struct {
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;
} VARIABLE_MODULE_GLOBAL;
=20
+/**
+ Get the HOB that contains variable flash information.
+
+ @param[out] VariableFlashInfo Pointer to a pointer to set to the var=
iable flash information structure.
+
+ @retval EFI_SUCCESS Variable flash information was found s=
uccessfully.
+ @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is=
NULL.
+ @retval EFI_NOT_FOUND Variable flash information could not b=
e found.
+
+**/
+EFI_STATUS
+GetVariableFlashInfo (
+ OUT VARIABLE_FLASH_INFO **VariableFlashInfo
+ );
+
/**
Flush the HOB variable to flash.
=20
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDx=
e.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
index c9434df631ee..6df350afa260 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
@@ -73,6 +73,7 @@ [LibraryClasses]
VarCheckLib
VariablePolicyLib
VariablePolicyHelperLib
+ SafeIntLib
=20
[Protocols]
gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES
@@ -114,6 +115,7 @@ [Guids]
gEfiSystemNvDataFvGuid ## CONSUMES =
## GUID
gEfiEndOfDxeEventGroupGuid ## CONSUMES =
## Event
gEdkiiFaultTolerantWriteGuid ## SOMETIMES_CONSUMES =
## HOB
+ gVariableFlashInfoHobGuid ## CONSUMES =
## HOB
=20
## SOMETIMES_CONSUMES ## Variable:L"VarErrorFlag"
## SOMETIMES_PRODUCES ## Variable:L"VarErrorFlag"
@@ -125,9 +127,9 @@ [Guids]
gEfiImageSecurityDatabaseGuid
=20
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## S=
OMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## C=
ONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## S=
OMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## C=
ONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## C=
ONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## C=
ONSUMES
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b=
/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
index eaa97a01c6e5..398e7d9060ab 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
@@ -82,6 +82,7 @@ [LibraryClasses]
UefiBootServicesTableLib
VariablePolicyLib
VariablePolicyHelperLib
+ SafeIntLib
=20
[Protocols]
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES
@@ -121,15 +122,16 @@ [Guids]
gSmmVariableWriteGuid ## PRODUCES =
## GUID # Install protocol
gEfiSystemNvDataFvGuid ## CONSUMES =
## GUID
gEdkiiFaultTolerantWriteGuid ## SOMETIMES_CONSUMES =
## HOB
+ gVariableFlashInfoHobGuid ## CONSUMES =
## HOB
=20
## SOMETIMES_CONSUMES ## Variable:L"VarErrorFlag"
## SOMETIMES_PRODUCES ## Variable:L"VarErrorFlag"
gEdkiiVarErrorFlagGuid
=20
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## =
CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## =
SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## =
SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## =
CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## =
SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## =
CONSUMES
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandalon=
eMm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm=
.inf
index d8c4f77e7f1f..efc9290ae759 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
@@ -73,6 +73,7 @@ [LibraryClasses]
HobLib
MemoryAllocationLib
MmServicesTableLib
+ SafeIntLib
StandaloneMmDriverEntryPoint
SynchronizationLib
VarCheckLib
@@ -114,6 +115,7 @@ [Guids]
=20
gEfiSystemNvDataFvGuid ## CONSUMES =
## GUID
gEdkiiFaultTolerantWriteGuid ## SOMETIMES_CONSUMES =
## HOB
+ gVariableFlashInfoHobGuid ## CONSUMES =
## HOB
=20
## SOMETIMES_CONSUMES ## Variable:L"VarErrorFlag"
## SOMETIMES_PRODUCES ## Variable:L"VarErrorFlag"
@@ -121,8 +123,8 @@ [Guids]
=20
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## =
SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## =
CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## =
CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## =
SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## =
SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## =
CONSUMES
--=20
2.28.0.windows.1

3921 - 3940 of 92312