Date   

[edk2-platforms] [PATCH V1 1/4] KabylakeOpenBoardPkg: Indicate width of CLK duty cycle in FADT

Nate DeSimone
 

Set the location of the DUTY_CYCLE field in the P_CNT register
and indicate the width of the clock duty cycle to OS power management

Merged missing PCD settings into GalagoPro3

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Ankit Sinha <ankit.sinha@...>
Cc: Michael Kubacki <michael.kubacki@...>
Cc: Benjamin Doron <benjamin.doron00@...>
Cc: Jeremy Soller <jeremy@...>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@...>
---
.../AspireVn7Dash572G/OpenBoardPkgPcd.dsc | 9 +++-
.../GalagoPro3/OpenBoardPkgPcd.dsc | 52 +++++++++++++++++--
.../KabylakeRvp3/OpenBoardPkgPcd.dsc | 11 +++-
3 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkgPcd.dsc b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkgPcd.dsc
index 21ee86403d..02080aa864 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkgPcd.dsc
+++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkgPcd.dsc
@@ -1,7 +1,7 @@
## @file
# PCD configuration build description file for the Aspire VN7-572G board.
#
-# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -346,6 +346,13 @@
gSiPkgTokenSpaceGuid.PcdHstiIhvFeature1|0xF2 # FIXME: Boot Guard and BIOS Guard not present, measured boot enforcement checking code not present
gSiPkgTokenSpaceGuid.PcdHstiIhvFeature2|0x07

+ #
+ # Set the location of the DUTY_CYCLE field in the P_CNT register
+ # and indicate the width of the clock duty cycle to OS power management
+ #
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyOffset|0x1
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyWidth|0x3
+
######################################
# Platform Configuration
######################################
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkgPcd.dsc b/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkgPcd.dsc
index 44dacdf082..26e2c16aae 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkgPcd.dsc
+++ b/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkgPcd.dsc
@@ -1,7 +1,7 @@
## @file
# PCD configuration build description file for the GalagoPro3 board.
#
-# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -40,6 +40,26 @@
#
gMinPlatformPkgTokenSpaceGuid.PcdFspWrapperBootMode|TRUE

+ #
+ # FALSE: The PEI Main included in FvPreMemory is used to dispatch all PEIMs
+ # (both inside FSP and outside FSP).
+ # Pros:
+ # * PEI Main is re-built from source and is always the latest version
+ # * Platform code can link any desired LibraryClass to PEI Main
+ # (Ex: Custom DebugLib instance, SerialPortLib, etc.)
+ # Cons:
+ # * The PEI Main being used to execute FSP PEIMs is not the PEI Main
+ # that the FSP PEIMs were tested with, adding risk of breakage.
+ # * Two copies of PEI Main will exist in the final binary,
+ # #1 in FSP-M, #2 in FvPreMemory. The copy in FSP-M is never
+ # executed, wasting space.
+ #
+ # <b>TRUE</b>: The PEI Main included in FSP is used to dispatch all PEIMs
+ # (both inside FSP and outside FSP). PEI Main will not be included in
+ # FvPreMemory. This is the default and is the recommended choice.
+ #
+ gMinPlatformPkgTokenSpaceGuid.PcdFspDispatchModeUseFspPeiMain|TRUE
+
#
# FSP Base address PCD will be updated in FDF basing on flash map.
#
@@ -52,6 +72,7 @@
gSiPkgTokenSpaceGuid.PcdTemporaryRamSize|0x00040000
gSiPkgTokenSpaceGuid.PcdTsegSize|0x1000000

+!if gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection == 1
#
# FSP API mode does not share stack with the boot loader,
# so FSP needs more temporary memory for FSP heap + stack size.
@@ -63,6 +84,24 @@
# since the stacks are separate.
#
gSiPkgTokenSpaceGuid.PcdPeiTemporaryRamStackSize|0x20000
+!else
+ #
+ # In FSP Dispatch mode boot loader stack size must be large
+ # enough for executing both boot loader and FSP.
+ #
+ gSiPkgTokenSpaceGuid.PcdPeiTemporaryRamStackSize|0x40000
+!endif
+
+!if (gMinPlatformPkgTokenSpaceGuid.PcdFspWrapperBootMode == FALSE) || (gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection == 1)
+ gSiPkgTokenSpaceGuid.PcdSiPciExpressBaseAddress|gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
+ gSiPkgTokenSpaceGuid.PcdSiPciExpressRegionLength|gMinPlatformPkgTokenSpaceGuid.PcdPciExpressRegionLength
+!else
+ #
+ # FSP Dispatch mode requires more platform memory as boot loader and FSP sharing the same
+ # platform memory.
+ #
+ gSiPkgTokenSpaceGuid.PcdPeiMinMemorySize|0x5500000
+!endif

[PcdsFeatureFlag.common]
######################################
@@ -222,7 +261,7 @@
gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|1000
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout|10000
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x20000
-
+!if (gMinPlatformPkgTokenSpaceGuid.PcdFspWrapperBootMode == FALSE) || (gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection == 1)
#
# In non-FSP build (EDK2 build) or FSP API mode below PCD are FixedAtBuild
# (They will be DynamicEx in FSP Dispatch mode)
@@ -242,6 +281,7 @@
# 3: Place AP in the Run-Loop state.
# @Prompt The AP wait loop state.
gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode|2
+!endif

######################################
# Silicon Configuration
@@ -251,8 +291,12 @@
gSiPkgTokenSpaceGuid.PcdHstiIhvFeature1|0xF2
gSiPkgTokenSpaceGuid.PcdHstiIhvFeature2|0x07

- gSiPkgTokenSpaceGuid.PcdSiPciExpressBaseAddress|gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
- gSiPkgTokenSpaceGuid.PcdSiPciExpressRegionLength|gMinPlatformPkgTokenSpaceGuid.PcdPciExpressRegionLength
+ #
+ # Set the location of the DUTY_CYCLE field in the P_CNT register
+ # and indicate the width of the clock duty cycle to OS power management
+ #
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyOffset|0x1
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyWidth|0x3

######################################
# Platform Configuration
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc
index 725596cbf7..ccf757e202 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc
+++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc
@@ -1,7 +1,7 @@
## @file
# PCD configuration build description file for the KabylakeRvp3 board.
#
-# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -78,6 +78,7 @@
# so FSP needs more temporary memory for FSP heap + stack size.
#
gIntelFsp2PkgTokenSpaceGuid.PcdFspTemporaryRamSize|0x26000
+
#
# FSP API mode does not need to enlarge the boot loader stack size
# since the stacks are separate.
@@ -290,6 +291,13 @@
gSiPkgTokenSpaceGuid.PcdHstiIhvFeature1|0xF2
gSiPkgTokenSpaceGuid.PcdHstiIhvFeature2|0x07

+ #
+ # Set the location of the DUTY_CYCLE field in the P_CNT register
+ # and indicate the width of the clock duty cycle to OS power management
+ #
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyOffset|0x1
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyWidth|0x3
+
######################################
# Platform Configuration
######################################
@@ -346,7 +354,6 @@
gMinPlatformPkgTokenSpaceGuid.PcdTestPointIbvPlatformFeature|{0x03, 0x0F, 0x07, 0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
!endif

-
######################################
# Board Configuration
######################################
--
2.27.0.windows.1


[edk2-platforms] [PATCH V1 3/4] CometlakeOpenBoardPkg: Indicate width of CLK duty cycle in FADT

Nate DeSimone
 

Set the location of the DUTY_CYCLE field in the P_CNT register
and indicate the width of the clock duty cycle to OS power management

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Ankit Sinha <ankit.sinha@...>
Cc: Michael Kubacki <michael.kubacki@...>
Cc: Sai Chaganty <rangasai.v.chaganty@...>
Cc: Deepika Kethi Reddy <deepika.kethi.reddy@...>
Cc: Kathappan Esakkithevar <kathappan.esakkithevar@...>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@...>
---
.../CometlakeURvp/OpenBoardPkgPcd.dsc | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Platform/Intel/CometlakeOpenBoardPkg/CometlakeURvp/OpenBoardPkgPcd.dsc b/Platform/Intel/CometlakeOpenBoardPkg/CometlakeURvp/OpenBoardPkgPcd.dsc
index 589b002d06..68dd08423b 100644
--- a/Platform/Intel/CometlakeOpenBoardPkg/CometlakeURvp/OpenBoardPkgPcd.dsc
+++ b/Platform/Intel/CometlakeOpenBoardPkg/CometlakeURvp/OpenBoardPkgPcd.dsc
@@ -1,7 +1,7 @@
## @file
# PCD configuration build description file for the CometlakeURvp board.
#
-# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -253,6 +253,13 @@
gMinPlatformPkgTokenSpaceGuid.PcdMaxCpuCoreCount|8
gMinPlatformPkgTokenSpaceGuid.PcdMaxCpuThreadCount|2

+ #
+ # Set the location of the DUTY_CYCLE field in the P_CNT register
+ # and indicate the width of the clock duty cycle to OS power management
+ #
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyOffset|0x1
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyWidth|0x3
+
#
# The PCDs are used to control the Windows SMM Security Mitigations Table - Protection Flags
#
--
2.27.0.windows.1


[edk2-platforms] [PATCH V1 2/4] WhiskeylakeOpenBoardPkg: Indicate width of CLK duty cycle in FADT

Nate DeSimone
 

Set the location of the DUTY_CYCLE field in the P_CNT register
and indicate the width of the clock duty cycle to OS power management

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Ankit Sinha <ankit.sinha@...>
Cc: Michael Kubacki <michael.kubacki@...>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@...>
---
.../WhiskeylakeOpenBoardPkg/UpXtreme/OpenBoardPkgPcd.dsc | 9 ++++++++-
.../WhiskeylakeURvp/OpenBoardPkgPcd.dsc | 9 ++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Platform/Intel/WhiskeylakeOpenBoardPkg/UpXtreme/OpenBoardPkgPcd.dsc b/Platform/Intel/WhiskeylakeOpenBoardPkg/UpXtreme/OpenBoardPkgPcd.dsc
index 84d4ec1331..8f3cc6ba28 100644
--- a/Platform/Intel/WhiskeylakeOpenBoardPkg/UpXtreme/OpenBoardPkgPcd.dsc
+++ b/Platform/Intel/WhiskeylakeOpenBoardPkg/UpXtreme/OpenBoardPkgPcd.dsc
@@ -1,7 +1,7 @@
## @file
# PCD configuration build description file for the UpXtreme board.
#
-# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -259,6 +259,13 @@
gSiPkgTokenSpaceGuid.PcdSerialIoUartNumber|2
gSiPkgTokenSpaceGuid.PcdPciExpressRegionLength|gMinPlatformPkgTokenSpaceGuid.PcdPciExpressRegionLength

+ #
+ # Set the location of the DUTY_CYCLE field in the P_CNT register
+ # and indicate the width of the clock duty cycle to OS power management
+ #
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyOffset|0x1
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyWidth|0x3
+
######################################
# Platform Configuration
######################################
diff --git a/Platform/Intel/WhiskeylakeOpenBoardPkg/WhiskeylakeURvp/OpenBoardPkgPcd.dsc b/Platform/Intel/WhiskeylakeOpenBoardPkg/WhiskeylakeURvp/OpenBoardPkgPcd.dsc
index 4a7ba4d5f0..4a5d5ef03b 100644
--- a/Platform/Intel/WhiskeylakeOpenBoardPkg/WhiskeylakeURvp/OpenBoardPkgPcd.dsc
+++ b/Platform/Intel/WhiskeylakeOpenBoardPkg/WhiskeylakeURvp/OpenBoardPkgPcd.dsc
@@ -1,7 +1,7 @@
## @file
# PCD configuration build description file for the WhiskeylakeURvp board.
#
-# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -242,6 +242,13 @@
######################################
gSiPkgTokenSpaceGuid.PcdPciExpressRegionLength|gMinPlatformPkgTokenSpaceGuid.PcdPciExpressRegionLength

+ #
+ # Set the location of the DUTY_CYCLE field in the P_CNT register
+ # and indicate the width of the clock duty cycle to OS power management
+ #
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyOffset|0x1
+ gMinPlatformPkgTokenSpaceGuid.PcdFadtDutyWidth|0x3
+
######################################
# Platform Configuration
######################################
--
2.27.0.windows.1


[edk2-platforms] [PATCH V1 0/4] Enable CPU pwr mgmt in FADT for Intel client boards

Nate DeSimone
 

This patch series sets the DUTY_OFFSET and DUTY_WIDTH fields in the ACPI FADT
to 1 and 3 respectively. This will enable OS power management to set the CPU
clock speed in the P_CNT register on these platforms.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Ankit Sinha <ankit.sinha@...>
Cc: Sai Chaganty <rangasai.v.chaganty@...>
Cc: Michael Kubacki <michael.kubacki@...>
Cc: Heng Luo <heng.luo@...>
Cc: Deepika Kethi Reddy <deepika.kethi.reddy@...>
Cc: Kathappan Esakkithevar <kathappan.esakkithevar@...>
Cc: Benjamin Doron <benjamin.doron00@...>
Cc: Jeremy Soller <jeremy@...>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@...>

Nate DeSimone (4):
KabylakeOpenBoardPkg: Indicate width of CLK duty cycle in FADT
WhiskeylakeOpenBoardPkg: Indicate width of CLK duty cycle in FADT
CometlakeOpenBoardPkg: Indicate width of CLK duty cycle in FADT
TigerlakeOpenBoardPkg: Indicate width of CLK duty cycle in FADT

.../CometlakeURvp/OpenBoardPkgPcd.dsc | 9 +++-
.../AspireVn7Dash572G/OpenBoardPkgPcd.dsc | 9 +++-
.../GalagoPro3/OpenBoardPkgPcd.dsc | 52 +++++++++++++++++--
.../KabylakeRvp3/OpenBoardPkgPcd.dsc | 11 +++-
.../TigerlakeURvp/OpenBoardPkgPcd.dsc | 10 +++-
.../UpXtreme/OpenBoardPkgPcd.dsc | 9 +++-
.../WhiskeylakeURvp/OpenBoardPkgPcd.dsc | 9 +++-
7 files changed, 98 insertions(+), 11 deletions(-)

--
2.27.0.windows.1


Re: [edk2-platforms][PATCH v1 0/3] MinPlatformPkg: Add FADT duty offset and width PCDs

Nate DeSimone
 

The series has been pushed as ~3018b1f..61af470

-----Original Message-----
From: mikuback@... <mikuback@...>
Sent: Monday, April 11, 2022 1:58 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel <chasel.chiu@...>; Desimone, Nathaniel L <nathaniel.l.desimone@...>; Gao, Liming <gaoliming@...>; Dong, Eric <eric.dong@...>
Subject: [edk2-platforms][PATCH v1 0/3] MinPlatformPkg: Add FADT duty offset and width PCDs

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

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

Adds PCDs to the MinPlatformPkg DEC file so MinPlatformPkg consumers (board packages) can customize the DUTY_OFFSET and DUTY_CYCLE values in their build files.

The copy of AcpiPlatform in SimicsOpenBoardPkg is also updated to keep the change in sync with the source MinPlatformPkg module.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Liming Gao <gaoliming@...>
Cc: Eric Dong <eric.dong@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>

Michael Kubacki (3):
MinPlatformPkg: Add FADT duty offset and duty width PCDs
MinPlatformPkg/AcpiPlatform: Use FADT duty offset and width PCDs
SimicsOpenBoardPkg/AcpiPlatform: Use FADT duty offset and width PCDs

Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 3 +++
Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.c | 4 ++--
Platform/Intel/SimicsOpenBoardPkg/AcpiTables/MinPlatformAcpiTables/AcpiPlatform.c | 3 +++
Platform/Intel/SimicsOpenBoardPkg/AcpiTables/MinPlatformAcpiTables/Fadt/Fadt.c | 4 ++--
Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf | 2 ++
Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec | 15 +++++++++++++++
Platform/Intel/SimicsOpenBoardPkg/AcpiTables/MinPlatformAcpiTables/AcpiPlatform.inf | 2 ++
7 files changed, 29 insertions(+), 4 deletions(-)

--
2.28.0.windows.1


Re: [edk2-platforms][PATCH v1 0/3] MinPlatformPkg: Add FADT duty offset and width PCDs

Nate DeSimone
 

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@...>

-----Original Message-----
From: mikuback@... <mikuback@...>
Sent: Monday, April 11, 2022 1:58 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel <chasel.chiu@...>; Desimone, Nathaniel L <nathaniel.l.desimone@...>; Gao, Liming <gaoliming@...>; Dong, Eric <eric.dong@...>
Subject: [edk2-platforms][PATCH v1 0/3] MinPlatformPkg: Add FADT duty offset and width PCDs

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

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

Adds PCDs to the MinPlatformPkg DEC file so MinPlatformPkg consumers (board packages) can customize the DUTY_OFFSET and DUTY_CYCLE values in their build files.

The copy of AcpiPlatform in SimicsOpenBoardPkg is also updated to keep the change in sync with the source MinPlatformPkg module.

Cc: Chasel Chiu <chasel.chiu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Liming Gao <gaoliming@...>
Cc: Eric Dong <eric.dong@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>

Michael Kubacki (3):
MinPlatformPkg: Add FADT duty offset and duty width PCDs
MinPlatformPkg/AcpiPlatform: Use FADT duty offset and width PCDs
SimicsOpenBoardPkg/AcpiPlatform: Use FADT duty offset and width PCDs

Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 3 +++
Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.c | 4 ++--
Platform/Intel/SimicsOpenBoardPkg/AcpiTables/MinPlatformAcpiTables/AcpiPlatform.c | 3 +++
Platform/Intel/SimicsOpenBoardPkg/AcpiTables/MinPlatformAcpiTables/Fadt/Fadt.c | 4 ++--
Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf | 2 ++
Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec | 15 +++++++++++++++
Platform/Intel/SimicsOpenBoardPkg/AcpiTables/MinPlatformAcpiTables/AcpiPlatform.inf | 2 ++
7 files changed, 29 insertions(+), 4 deletions(-)

--
2.28.0.windows.1


Re: [PATCH V1 1/1] .pytool: UncrustifyCheck: Set IgnoreFiles path relative to package path

Michael Kubacki
 

Reviewed-by: Michael Kubacki <michael.kubacki@...>

On 6/6/2022 3:52 PM, Kun Qin wrote:
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3942
`IgnoreFiles` tag is specified in the CI YAML files in each individual
packages. The current logic for UncrustifyCheck script bases specified
file paths from workspace, which requires the package name to be included
in each entry.
This change updates the ignore checking logic to be based on current
package path in order to reduce redundancy. It also keeps the consistency
of `IgnoreFiles` field other pytools such as SpellCheck and EccCheck.
Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Michael Kubacki <mikuback@...>
Signed-off-by: Kun Qin <kuqin12@...>
---
.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
index 00d78864656f..8dc9ffe6945a 100644
--- a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
+++ b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
@@ -290,7 +290,7 @@ class UncrustifyCheck(ICiBuildPlugin):
# This information is only used for reporting (not used here) and
# the ignore lines are being passed directly as they are given to
# this plugin.
- return parse_gitignore_lines(ignored_files, "Package configuration file", self._abs_workspace_path)
+ return parse_gitignore_lines(ignored_files, "Package configuration file", self._abs_package_path)
def _get_git_ignored_paths(self) -> List[str]:
""""


[PATCH V1 1/1] .pytool: UncrustifyCheck: Set IgnoreFiles path relative to package path

Kun Qin
 

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

`IgnoreFiles` tag is specified in the CI YAML files in each individual
packages. The current logic for UncrustifyCheck script bases specified
file paths from workspace, which requires the package name to be included
in each entry.

This change updates the ignore checking logic to be based on current
package path in order to reduce redundancy. It also keeps the consistency
of `IgnoreFiles` field other pytools such as SpellCheck and EccCheck.

Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Michael Kubacki <mikuback@...>

Signed-off-by: Kun Qin <kuqin12@...>
---
.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
index 00d78864656f..8dc9ffe6945a 100644
--- a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
+++ b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
@@ -290,7 +290,7 @@ class UncrustifyCheck(ICiBuildPlugin):
# This information is only used for reporting (not used here) and
# the ignore lines are being passed directly as they are given to
# this plugin.
- return parse_gitignore_lines(ignored_files, "Package configuration file", self._abs_workspace_path)
+ return parse_gitignore_lines(ignored_files, "Package configuration file", self._abs_package_path)

def _get_git_ignored_paths(self) -> List[str]:
""""
--
2.35.1.windows.2


[PATCH V1 0/1] UncrustifyCheck ignore file list paths reduction

Kun Qin
 

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

When UncrustifyCheck plugin checks against "IgnoreFiles" tag, the script
references the files relative to the workspace.

This will require all files listed under such category to specify the
package name in the corresponding package CI YAML file.

To resolve this issue, the ignore files' paths are changed to be based on
the applicable package path.

Patch v1 branch: https://github.com/kuqin12/edk2/pull/new/uncrustify_ignore_pkg

Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>


Kun Qin (1):
.pytool: UncrustifyCheck: Set IgnoreFiles path relative to package
path

.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--
2.35.1.windows.2


Re: [GSOC 2022] Adding Rust support to EDK II: Introducing Myself

Michael Kubacki
 

Hi Ayush,

We will be meeting weekly on Microsoft Teams. We're finalizing proposed meeting times given the three mentor time zones.

I will be sending you a meeting series invitation this week when that is done to check your availability as well.

Regards,
Michael

On 6/6/2022 7:54 AM, Ayush Singh wrote:
Hi Michael,
I was wondering when we can start the discussions about the project.
After doing some more research, I would like to make some changes to
the proposed schedule and iron out some implementation details.
So it would be great if you can clarify how and where the discussions
should take place.
Yours Sincerely
Ayush Singh
On Thu, May 26, 2022 at 2:20 AM Michael Kubacki
<mikuback@...> wrote:

Hi Ayush,

Welcome! I'm excited about this project too and I look forward to
working you.

We will be reaching out soon to set up our regularly scheduled
discussions and meet you.

Regards,
Michael

On 5/21/2022 1:09 AM, Ayush Singh wrote:
Hello Everyone,

I am Ayush Singh, a 2nd-year university student from the Indian
Institute of Technology (Indian School of Mines), Dhanbad, India. In
Google Summer of Code 2022, I will be working on Adding Rust support
to EDK II. The original Task from the wiki can be found here:
https://github.com/tianocore/tianocore.github.io/wiki/Tasks-Add-Rust-Support-to-EDK-II

This email is just to formally introduce myself to the mailing list. I
hope I will be able to help improve the EDK II project during the
course of Google Summer of Code, and even after that.

According to the GSoC dashboard, Michael Kinney and Michael Kubacki
are the mentors for this project, so I would like to get in touch with
them soon as well.

I look forward to working on this wonderful and exciting project.

Yours Sincerely
Ayush Singh



[PATCH v1 2/2] MdeModulePkg/AhciPei: Use PCI_DEVICE_PPI to manage AHCI device

Maciej Czajkowski
 

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

This change modifies AhciPei library to allow usage both EDKII_PCI_DEVICE_PPI
and EDKII_PEI_ATA_AHCI_HOST_CONTROLLER_PPI to manage ATA HDD working under
AHCI mode.

Cc: Hao A Wu <hao.a.wu@...>
Cc: Ray Ni <ray.ni@...>
Signed-off-by: Maciej Czajkowski <maciej.czajkowski@...>
---
MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c | 615 +++++++++++++++-----
MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c | 44 --
MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf | 5 +-
3 files changed, 458 insertions(+), 206 deletions(-)

diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c
index 208b7e9a3606..31bb3c0760ab 100644
--- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c
+++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c
@@ -9,6 +9,47 @@
**/

#include "AhciPei.h"
+#include <Ppi/PciDevice.h>
+#include <Library/DevicePathLib.h>
+#include <IndustryStandard/Pci.h>
+
+/**
+ Callback for EDKII_ATA_AHCI_HOST_CONTROLLER_PPI installation.
+
+ @param[in] PeiServices Pointer to PEI Services Table.
+ @param[in] NotifyDescriptor Pointer to the descriptor for the Notification
+ event that caused this function to execute.
+ @param[in] Ppi Pointer to the PPI data associated with this function.
+
+ @retval EFI_SUCCESS The function completes successfully
+
+**/
+EFI_STATUS
+EFIAPI
+AtaAhciHostControllerPpiInstallationCallback (
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
+ IN VOID *Ppi
+ );
+
+/**
+ Callback for EDKII_PCI_DEVICE_PPI installation.
+
+ @param[in] PeiServices Pointer to PEI Services Table.
+ @param[in] NotifyDescriptor Pointer to the descriptor for the Notification
+ event that caused this function to execute.
+ @param[in] Ppi Pointer to the PPI data associated with this function.
+
+ @retval EFI_SUCCESS The function completes successfully
+
+**/
+EFI_STATUS
+EFIAPI
+AtaAhciPciDevicePpiInstallationCallback (
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
+ IN VOID *Ppi
+ );

EFI_PEI_PPI_DESCRIPTOR mAhciAtaPassThruPpiListTemplate = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
@@ -40,6 +81,18 @@ EFI_PEI_NOTIFY_DESCRIPTOR mAhciEndOfPeiNotifyListTemplate = {
AhciPeimEndOfPei
};

+EFI_PEI_NOTIFY_DESCRIPTOR mAtaAhciHostControllerNotify = {
+ (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gEdkiiPeiAtaAhciHostControllerPpiGuid,
+ AtaAhciHostControllerPpiInstallationCallback
+};
+
+EFI_PEI_NOTIFY_DESCRIPTOR mPciDevicePpiNotify = {
+ (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gEdkiiPeiPciDevicePpiGuid,
+ AtaAhciPciDevicePpiInstallationCallback
+};
+
/**
Free the DMA resources allocated by an ATA AHCI controller.

@@ -111,33 +164,28 @@ AhciPeimEndOfPei (
}

/**
- Entry point of the PEIM.
+ Initialize and install PrivateData PPIs.

- @param[in] FileHandle Handle of the file being invoked.
- @param[in] PeiServices Describes the list of possible PEI Services.
-
- @retval EFI_SUCCESS PPI successfully installed.
+ @param[in] Private A pointer to the PEI_AHCI_CONTROLLER_PRIVATE_DATA data
+ structure.

+ @retval EFI_SUCCESS AHCI controller initialized and PPIs installed
+ @retval others Failed to initialize AHCI controller
**/
EFI_STATUS
-EFIAPI
-AtaAhciPeimEntry (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN CONST EFI_PEI_SERVICES **PeiServices
+AtaAhciInitPrivateData (
+ IN UINTN MmioBase,
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN UINTN DevicePathLength
)
{
- EFI_STATUS Status;
- EFI_BOOT_MODE BootMode;
- EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *AhciHcPpi;
- UINT8 Controller;
- UINTN MmioBase;
- UINTN DevicePathLength;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- UINT32 PortBitMap;
- PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
- UINT8 NumberOfPorts;
+ EFI_STATUS Status;
+ UINT32 PortBitMap;
+ UINT8 NumberOfPorts;
+ PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
+ EFI_BOOT_MODE BootMode;

- DEBUG ((DEBUG_INFO, "%a: Enters.\n", __FUNCTION__));
+ DEBUG ((DEBUG_INFO, "Initializing private data for ATA\n"));

//
// Get the current boot mode.
@@ -149,19 +197,149 @@ AtaAhciPeimEntry (
}

//
- // Locate the ATA AHCI host controller PPI.
- //
- Status = PeiServicesLocatePpi (
- &gEdkiiPeiAtaAhciHostControllerPpiGuid,
- 0,
- NULL,
- (VOID **)&AhciHcPpi
- );
+ // Check validity of the device path of the ATA AHCI controller.
+ //
+ Status = AhciIsHcDevicePathValid (DevicePath, DevicePathLength);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: The device path is invalid.\n",
+ __FUNCTION__
+ ));
+ return Status;
+ }
+
+ //
+ // For S3 resume performance consideration, not all ports on an ATA AHCI
+ // controller will be enumerated/initialized. The driver consumes the
+ // content within S3StorageDeviceInitList LockBox to get the ports that
+ // will be enumerated/initialized during S3 resume.
+ //
+ if (BootMode == BOOT_ON_S3_RESUME) {
+ NumberOfPorts = AhciS3GetEumeratePorts (DevicePath, DevicePathLength, &PortBitMap);
+ if (NumberOfPorts == 0) {
+ return EFI_SUCCESS;
+ }
+ } else {
+ PortBitMap = MAX_UINT32;
+ }
+
+ //
+ // Memory allocation for controller private data.
+ //
+ Private = AllocateZeroPool (sizeof (PEI_AHCI_CONTROLLER_PRIVATE_DATA));
+ if (Private == NULL) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Fail to allocate private data.\n",
+ __FUNCTION__
+ ));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Initialize controller private data.
+ //
+ Private->Signature = AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE;
+ Private->MmioBase = MmioBase;
+ Private->DevicePathLength = DevicePathLength;
+ Private->DevicePath = DevicePath;
+ Private->PortBitMap = PortBitMap;
+ InitializeListHead (&Private->DeviceList);
+
+ Status = AhciModeInitialization (Private);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: Failed to locate AtaAhciHostControllerPpi.\n", __FUNCTION__));
- return EFI_UNSUPPORTED;
+ return Status;
+ }
+
+ Private->AtaPassThruMode.Attributes = EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL |
+ EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL;
+ Private->AtaPassThruMode.IoAlign = sizeof (UINTN);
+ Private->AtaPassThruPpi.Revision = EDKII_PEI_ATA_PASS_THRU_PPI_REVISION;
+ Private->AtaPassThruPpi.Mode = &Private->AtaPassThruMode;
+ Private->AtaPassThruPpi.PassThru = AhciAtaPassThruPassThru;
+ Private->AtaPassThruPpi.GetNextPort = AhciAtaPassThruGetNextPort;
+ Private->AtaPassThruPpi.GetNextDevice = AhciAtaPassThruGetNextDevice;
+ Private->AtaPassThruPpi.GetDevicePath = AhciAtaPassThruGetDevicePath;
+ CopyMem (
+ &Private->AtaPassThruPpiList,
+ &mAhciAtaPassThruPpiListTemplate,
+ sizeof (EFI_PEI_PPI_DESCRIPTOR)
+ );
+ Private->AtaPassThruPpiList.Ppi = &Private->AtaPassThruPpi;
+ PeiServicesInstallPpi (&Private->AtaPassThruPpiList);
+
+ Private->BlkIoPpi.GetNumberOfBlockDevices = AhciBlockIoGetDeviceNo;
+ Private->BlkIoPpi.GetBlockDeviceMediaInfo = AhciBlockIoGetMediaInfo;
+ Private->BlkIoPpi.ReadBlocks = AhciBlockIoReadBlocks;
+ CopyMem (
+ &Private->BlkIoPpiList,
+ &mAhciBlkIoPpiListTemplate,
+ sizeof (EFI_PEI_PPI_DESCRIPTOR)
+ );
+ Private->BlkIoPpiList.Ppi = &Private->BlkIoPpi;
+ PeiServicesInstallPpi (&Private->BlkIoPpiList);
+
+ Private->BlkIo2Ppi.Revision = EFI_PEI_RECOVERY_BLOCK_IO2_PPI_REVISION;
+ Private->BlkIo2Ppi.GetNumberOfBlockDevices = AhciBlockIoGetDeviceNo2;
+ Private->BlkIo2Ppi.GetBlockDeviceMediaInfo = AhciBlockIoGetMediaInfo2;
+ Private->BlkIo2Ppi.ReadBlocks = AhciBlockIoReadBlocks2;
+ CopyMem (
+ &Private->BlkIo2PpiList,
+ &mAhciBlkIo2PpiListTemplate,
+ sizeof (EFI_PEI_PPI_DESCRIPTOR)
+ );
+ Private->BlkIo2PpiList.Ppi = &Private->BlkIo2Ppi;
+ PeiServicesInstallPpi (&Private->BlkIo2PpiList);
+
+ if (Private->TrustComputingDevices != 0) {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: Security Security Command PPI will be produced.\n",
+ __FUNCTION__
+ ));
+ Private->StorageSecurityPpi.Revision = EDKII_STORAGE_SECURITY_PPI_REVISION;
+ Private->StorageSecurityPpi.GetNumberofDevices = AhciStorageSecurityGetDeviceNo;
+ Private->StorageSecurityPpi.GetDevicePath = AhciStorageSecurityGetDevicePath;
+ Private->StorageSecurityPpi.ReceiveData = AhciStorageSecurityReceiveData;
+ Private->StorageSecurityPpi.SendData = AhciStorageSecuritySendData;
+ CopyMem (
+ &Private->StorageSecurityPpiList,
+ &mAhciStorageSecurityPpiListTemplate,
+ sizeof (EFI_PEI_PPI_DESCRIPTOR)
+ );
+ Private->StorageSecurityPpiList.Ppi = &Private->StorageSecurityPpi;
+ PeiServicesInstallPpi (&Private->StorageSecurityPpiList);
}

+ CopyMem (
+ &Private->EndOfPeiNotifyList,
+ &mAhciEndOfPeiNotifyListTemplate,
+ sizeof (EFI_PEI_NOTIFY_DESCRIPTOR)
+ );
+ PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Initialize AHCI controller from EDKII_ATA_AHCI_HOST_CONTROLLER_PPI instance.
+
+ @param[in] AhciHcPpi Pointer to the AHCI Host Controller PPI instance.
+
+ @retval EFI_SUCCESS PPI successfully installed.
+**/
+EFI_STATUS
+AtaAhciInitPrivateDataFromHostControllerPpi (
+ IN EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *AhciHcPpi
+ )
+{
+ UINT8 Controller;
+ UINTN MmioBase;
+ UINTN DevicePathLength;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_STATUS Status;
+
Controller = 0;
MmioBase = 0;
while (TRUE) {
@@ -193,65 +371,7 @@ AtaAhciPeimEntry (
return Status;
}

- //
- // Check validity of the device path of the ATA AHCI controller.
- //
- Status = AhciIsHcDevicePathValid (DevicePath, DevicePathLength);
- if (EFI_ERROR (Status)) {
- DEBUG ((
- DEBUG_ERROR,
- "%a: The device path is invalid for Controller %d.\n",
- __FUNCTION__,
- Controller
- ));
- Controller++;
- continue;
- }
-
- //
- // For S3 resume performance consideration, not all ports on an ATA AHCI
- // controller will be enumerated/initialized. The driver consumes the
- // content within S3StorageDeviceInitList LockBox to get the ports that
- // will be enumerated/initialized during S3 resume.
- //
- if (BootMode == BOOT_ON_S3_RESUME) {
- NumberOfPorts = AhciS3GetEumeratePorts (DevicePath, DevicePathLength, &PortBitMap);
- if (NumberOfPorts == 0) {
- //
- // No ports need to be enumerated for this controller.
- //
- Controller++;
- continue;
- }
- } else {
- PortBitMap = MAX_UINT32;
- }
-
- //
- // Memory allocation for controller private data.
- //
- Private = AllocateZeroPool (sizeof (PEI_AHCI_CONTROLLER_PRIVATE_DATA));
- if (Private == NULL) {
- DEBUG ((
- DEBUG_ERROR,
- "%a: Fail to allocate private data for Controller %d.\n",
- __FUNCTION__,
- Controller
- ));
- return EFI_OUT_OF_RESOURCES;
- }
-
- //
- // Initialize controller private data.
- //
- Private->Signature = AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE;
- Private->MmioBase = MmioBase;
- Private->DevicePathLength = DevicePathLength;
- Private->DevicePath = DevicePath;
- Private->PortBitMap = PortBitMap;
- InitializeListHead (&Private->DeviceList);
-
- Status = AhciModeInitialization (Private);
+ Status = AtaAhciInitPrivateData (MmioBase, DevicePath, DevicePathLength);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
@@ -260,86 +380,261 @@ AtaAhciPeimEntry (
Controller,
Status
));
- Controller++;
- continue;
- }
-
- Private->AtaPassThruMode.Attributes = EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL |
- EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL;
- Private->AtaPassThruMode.IoAlign = sizeof (UINTN);
- Private->AtaPassThruPpi.Revision = EDKII_PEI_ATA_PASS_THRU_PPI_REVISION;
- Private->AtaPassThruPpi.Mode = &Private->AtaPassThruMode;
- Private->AtaPassThruPpi.PassThru = AhciAtaPassThruPassThru;
- Private->AtaPassThruPpi.GetNextPort = AhciAtaPassThruGetNextPort;
- Private->AtaPassThruPpi.GetNextDevice = AhciAtaPassThruGetNextDevice;
- Private->AtaPassThruPpi.GetDevicePath = AhciAtaPassThruGetDevicePath;
- CopyMem (
- &Private->AtaPassThruPpiList,
- &mAhciAtaPassThruPpiListTemplate,
- sizeof (EFI_PEI_PPI_DESCRIPTOR)
- );
- Private->AtaPassThruPpiList.Ppi = &Private->AtaPassThruPpi;
- PeiServicesInstallPpi (&Private->AtaPassThruPpiList);
-
- Private->BlkIoPpi.GetNumberOfBlockDevices = AhciBlockIoGetDeviceNo;
- Private->BlkIoPpi.GetBlockDeviceMediaInfo = AhciBlockIoGetMediaInfo;
- Private->BlkIoPpi.ReadBlocks = AhciBlockIoReadBlocks;
- CopyMem (
- &Private->BlkIoPpiList,
- &mAhciBlkIoPpiListTemplate,
- sizeof (EFI_PEI_PPI_DESCRIPTOR)
- );
- Private->BlkIoPpiList.Ppi = &Private->BlkIoPpi;
- PeiServicesInstallPpi (&Private->BlkIoPpiList);
-
- Private->BlkIo2Ppi.Revision = EFI_PEI_RECOVERY_BLOCK_IO2_PPI_REVISION;
- Private->BlkIo2Ppi.GetNumberOfBlockDevices = AhciBlockIoGetDeviceNo2;
- Private->BlkIo2Ppi.GetBlockDeviceMediaInfo = AhciBlockIoGetMediaInfo2;
- Private->BlkIo2Ppi.ReadBlocks = AhciBlockIoReadBlocks2;
- CopyMem (
- &Private->BlkIo2PpiList,
- &mAhciBlkIo2PpiListTemplate,
- sizeof (EFI_PEI_PPI_DESCRIPTOR)
- );
- Private->BlkIo2PpiList.Ppi = &Private->BlkIo2Ppi;
- PeiServicesInstallPpi (&Private->BlkIo2PpiList);
-
- if (Private->TrustComputingDevices != 0) {
+ } else {
DEBUG ((
DEBUG_INFO,
- "%a: Security Security Command PPI will be produced for Controller %d.\n",
+ "%a: Controller %d has been successfully initialized.\n",
__FUNCTION__,
Controller
));
- Private->StorageSecurityPpi.Revision = EDKII_STORAGE_SECURITY_PPI_REVISION;
- Private->StorageSecurityPpi.GetNumberofDevices = AhciStorageSecurityGetDeviceNo;
- Private->StorageSecurityPpi.GetDevicePath = AhciStorageSecurityGetDevicePath;
- Private->StorageSecurityPpi.ReceiveData = AhciStorageSecurityReceiveData;
- Private->StorageSecurityPpi.SendData = AhciStorageSecuritySendData;
- CopyMem (
- &Private->StorageSecurityPpiList,
- &mAhciStorageSecurityPpiListTemplate,
- sizeof (EFI_PEI_PPI_DESCRIPTOR)
- );
- Private->StorageSecurityPpiList.Ppi = &Private->StorageSecurityPpi;
- PeiServicesInstallPpi (&Private->StorageSecurityPpiList);
}

- CopyMem (
- &Private->EndOfPeiNotifyList,
- &mAhciEndOfPeiNotifyListTemplate,
- sizeof (EFI_PEI_NOTIFY_DESCRIPTOR)
- );
- PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);
-
- DEBUG ((
- DEBUG_INFO,
- "%a: Controller %d has been successfully initialized.\n",
- __FUNCTION__,
- Controller
- ));
Controller++;
}

return EFI_SUCCESS;
}
+
+/**
+ Callback for EDKII_ATA_AHCI_HOST_CONTROLLER_PPI installation.
+
+ @param[in] PeiServices Pointer to PEI Services Table.
+ @param[in] NotifyDescriptor Pointer to the descriptor for the Notification
+ event that caused this function to execute.
+ @param[in] Ppi Pointer to the PPI data associated with this function.
+
+ @retval EFI_SUCCESS The function completes successfully
+
+**/
+EFI_STATUS
+EFIAPI
+AtaAhciHostControllerPpiInstallationCallback (
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
+ IN VOID *Ppi
+ )
+{
+ EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *AhciHcPpi;
+
+ if (Ppi == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AhciHcPpi = (EDKII_ATA_AHCI_HOST_CONTROLLER_PPI*) Ppi;
+
+ return AtaAhciInitPrivateDataFromHostControllerPpi (AhciHcPpi);
+}
+
+/**
+ Callback for EDKII_PCI_DEVICE_PPI installation.
+
+ @param[in] PeiServices Pointer to PEI Services Table.
+ @param[in] NotifyDescriptor Pointer to the descriptor for the Notification
+ event that caused this function to execute.
+ @param[in] Ppi Pointer to the PPI data associated with this function.
+
+ @retval EFI_SUCCESS The function completes successfully
+
+**/
+EFI_STATUS
+EFIAPI
+AtaAhciPciDevicePpiInstallationCallback (
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
+ IN VOID *Ppi
+ )
+{
+ EDKII_PCI_DEVICE_PPI *PciDevice;
+ PCI_TYPE00 PciData;
+ UINTN MmioBase;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN DevicePathLength;
+ EFI_STATUS Status;
+
+ PciDevice = (EDKII_PCI_DEVICE_PPI*) Ppi;
+
+ //
+ // Now further check the PCI header: Base Class (offset 0x0B) and
+ // Sub Class (offset 0x0A). This controller should be an SATA controller
+ //
+ Status = PciDevice->PciIo.Pci.Read (
+ &PciDevice->PciIo,
+ EfiPciIoWidthUint8,
+ PCI_CLASSCODE_OFFSET,
+ sizeof (PciData.Hdr.ClassCode),
+ PciData.Hdr.ClassCode
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (!IS_PCI_IDE (&PciData) && !IS_PCI_SATADPA (&PciData)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = PciDevice->PciIo.Attributes (
+ &PciDevice->PciIo,
+ EfiPciIoAttributeOperationSet,
+ EFI_PCI_DEVICE_ENABLE,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = PciDevice->PciIo.Pci.Read (
+ &PciDevice->PciIo,
+ EfiPciIoWidthUint32,
+ 0x24,
+ sizeof (UINTN),
+ &MmioBase
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ DevicePathLength = GetDevicePathSize (PciDevice->DevicePath);
+ DevicePath = PciDevice->DevicePath;
+
+ Status = AtaAhciInitPrivateData (MmioBase, DevicePath, DevicePathLength);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: Failed to init controller, with Status - %r\n",
+ __FUNCTION__,
+ Status
+ ));
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+AtaAhciInitPrivateDataFromPciDevice (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN ControllerIndex;
+ EDKII_PCI_DEVICE_PPI *PciDevice;
+ PCI_TYPE00 PciData;
+ UINTN MmioBase;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN DevicePathLength;
+
+ Status = EFI_SUCCESS;
+ for (ControllerIndex = 0; Status != EFI_NOT_FOUND; ControllerIndex++ ) {
+ Status = PeiServicesLocatePpi (
+ &gEdkiiPeiPciDevicePpiGuid,
+ ControllerIndex,
+ NULL,
+ (VOID**) &PciDevice
+ );
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+
+ //
+ // Now further check the PCI header: Base Class (offset 0x0B) and
+ // Sub Class (offset 0x0A). This controller should be an SATA controller
+ //
+ Status = PciDevice->PciIo.Pci.Read (
+ &PciDevice->PciIo,
+ EfiPciIoWidthUint8,
+ PCI_CLASSCODE_OFFSET,
+ sizeof (PciData.Hdr.ClassCode),
+ PciData.Hdr.ClassCode
+ );
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+
+ if (!IS_PCI_IDE (&PciData) && !IS_PCI_SATADPA (&PciData)) {
+ continue;
+ }
+
+ Status = PciDevice->PciIo.Attributes (
+ &PciDevice->PciIo,
+ EfiPciIoAttributeOperationSet,
+ EFI_PCI_DEVICE_ENABLE,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+
+ Status = PciDevice->PciIo.Pci.Read (
+ &PciDevice->PciIo,
+ EfiPciIoWidthUint32,
+ 0x24,
+ sizeof (UINTN),
+ &MmioBase
+ );
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+
+ DevicePathLength = GetDevicePathSize (PciDevice->DevicePath);
+ DevicePath = PciDevice->DevicePath;
+
+ Status = AtaAhciInitPrivateData (MmioBase, DevicePath, DevicePathLength);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: Failed to init controller, with Status - %r\n",
+ __FUNCTION__,
+ Status
+ ));
+ }
+ //
+ // Override the status to continue the for loop
+ //
+ Status = EFI_SUCCESS;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Entry point of the PEIM.
+
+ @param[in] FileHandle Handle of the file being invoked.
+ @param[in] PeiServices Describes the list of possible PEI Services.
+
+ @retval EFI_SUCCESS PPI successfully installed.
+
+**/
+EFI_STATUS
+EFIAPI
+AtaAhciPeimEntry (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+ EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *AhciHcPpi;
+
+ DEBUG ((DEBUG_INFO, "%a: Enters.\n", __FUNCTION__));
+
+ PeiServicesNotifyPpi (&mAtaAhciHostControllerNotify);
+
+ PeiServicesNotifyPpi (&mPciDevicePpiNotify);
+
+ Status = AtaAhciInitPrivateDataFromPciDevice ();
+
+ //
+ // Locate the ATA AHCI host controller PPI.
+ //
+ Status = PeiServicesLocatePpi (
+ &gEdkiiPeiAtaAhciHostControllerPpiGuid,
+ 0,
+ NULL,
+ (VOID **)&AhciHcPpi
+ );
+ if (!EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Using AtaAhciHostControllerPpi to initialize private data.\n", __FUNCTION__));
+ Status = AtaAhciInitPrivateDataFromHostControllerPpi (AhciHcPpi);
+ }
+
+ return Status;
+}
diff --git a/MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c b/MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c
index 81f8743d40d8..cf0955929dde 100644
--- a/MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c
+++ b/MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c
@@ -38,50 +38,6 @@ EFI_DEVICE_PATH_PROTOCOL mAhciEndDevicePathNodeTemplate = {
}
};

-/**
- Returns the 16-bit Length field of a device path node.
-
- Returns the 16-bit Length field of the device path node specified by Node.
- Node is not required to be aligned on a 16-bit boundary, so it is recommended
- that a function such as ReadUnaligned16() be used to extract the contents of
- the Length field.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @return The 16-bit Length field of the device path node specified by Node.
-
-**/
-UINTN
-DevicePathNodeLength (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);
-}
-
-/**
- Returns a pointer to the next node in a device path.
-
- If Node is NULL, then ASSERT().
-
- @param Node A pointer to a device path node data structure.
-
- @return a pointer to the device path node that follows the device path node
- specified by Node.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-NextDevicePathNode (
- IN CONST VOID *Node
- )
-{
- ASSERT (Node != NULL);
- return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength (Node));
-}
-
/**
Get the size of the current device path instance.

diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf
index 912ff7a8ba4f..788660b33299 100644
--- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf
+++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf
@@ -50,11 +50,13 @@ [LibraryClasses]
TimerLib
LockBoxLib
PeimEntryPoint
+ DevicePathLib

[Ppis]
gEdkiiPeiAtaAhciHostControllerPpiGuid ## CONSUMES
gEdkiiIoMmuPpiGuid ## CONSUMES
gEfiEndOfPeiSignalPpiGuid ## CONSUMES
+ gEdkiiPeiPciDevicePpiGuid ## CONSUMES
gEdkiiPeiAtaPassThruPpiGuid ## SOMETIMES_PRODUCES
gEfiPeiVirtualBlockIoPpiGuid ## SOMETIMES_PRODUCES
gEfiPeiVirtualBlockIo2PpiGuid ## SOMETIMES_PRODUCES
@@ -65,8 +67,7 @@ [Guids]

[Depex]
gEfiPeiMemoryDiscoveredPpiGuid AND
- gEfiPeiMasterBootModePpiGuid AND
- gEdkiiPeiAtaAhciHostControllerPpiGuid
+ gEfiPeiMasterBootModePpiGuid

[UserExtensions.TianoCore."ExtraFiles"]
AhciPeiExtra.uni
--
2.27.0.windows.1

---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.


[PATCH v1 0/2] Add EDKII_PCI_DEVICE_PPI support to EDK2

Maciej Czajkowski
 

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

The purpose of those changes is to introduce the way to enumerate and assign resources in PEI
for the systems with more than one PCI root. Here is a need to have an interface that will
support such a mechanizm.
For now, the part that performs the enumeration will be implemented in the silicon code.
Sample code can be seen here: https://github.com/mczaj/edk2-platforms/commit/d443062e58f9fba228869b54f2546d9735b3b506

Cc: Hao A Wu <hao.a.wu@...>
Cc: Ray Ni <ray.ni@...>
Cc: Liming Gao <gaoliming@...>

Maciej Czajkowski (2):
MdeModulePkg: Add EDKII_PCI_DEVICE_PPI definition
MdeModulePkg/AhciPei: Use PCI_DEVICE_PPI to manage AHCI device

MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c | 615 +++++++++++++++-----
MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c | 44 --
MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf | 5 +-
MdeModulePkg/Include/Ppi/PciDevice.h | 32 +
MdeModulePkg/MdeModulePkg.dec | 3 +
5 files changed, 493 insertions(+), 206 deletions(-)
create mode 100644 MdeModulePkg/Include/Ppi/PciDevice.h

--
2.27.0.windows.1

---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.


[PATCH v1 1/2] MdeModulePkg: Add EDKII_PCI_DEVICE_PPI definition

Maciej Czajkowski
 

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

This commit introduces EDKII_PCI_DEVICE_PPI. The purpose of this PPI is
to provide a way of accessing PCI devices to drvice drivers such as
NvmExpressPei or AhciPei.

Cc: Hao A Wu <hao.a.wu@...>
Cc: Ray Ni <ray.ni@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Maciej Czajkowski <maciej.czajkowski@...>
---
MdeModulePkg/Include/Ppi/PciDevice.h | 32 ++++++++++++++++++++
MdeModulePkg/MdeModulePkg.dec | 3 ++
2 files changed, 35 insertions(+)

diff --git a/MdeModulePkg/Include/Ppi/PciDevice.h b/MdeModulePkg/Include/Ppi/PciDevice.h
new file mode 100644
index 000000000000..3e391c61f6d9
--- /dev/null
+++ b/MdeModulePkg/Include/Ppi/PciDevice.h
@@ -0,0 +1,32 @@
+/** @file
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _EDKII_PCI_DEVICE_PPI_H_
+#define _EDKII_PCI_DEVICE_PPI_H_
+
+#include <Protocol/PciIo.h>
+#include <Protocol/DevicePath.h>
+
+///
+/// Global ID for the EDKII_PCI_DEVICE_PPI_GUID.
+///
+#define EDKII_PCI_DEVICE_PPI_GUID \
+ { \
+ 0x1597ab4f, 0xd542, 0x4efe, { 0x9a, 0xf7, 0xb2, 0x44, 0xec, 0x54, 0x4c, 0x0b } \
+ }
+
+///
+/// PCI Device PPI structure.
+///
+typedef struct {
+ EFI_PCI_IO_PROTOCOL PciIo;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+} EDKII_PCI_DEVICE_PPI;
+
+extern EFI_GUID gEdkiiPeiPciDevicePpiGuid;
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 2bcb9f9453af..7d989108324a 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -509,6 +509,9 @@ [Ppis]
## Include/Ppi/NvmExpressPassThru.h
gEdkiiPeiNvmExpressPassThruPpiGuid = { 0x6af31b2c, 0x3be, 0x46c1, { 0xb1, 0x2d, 0xea, 0x4a, 0x36, 0xdf, 0xa7, 0x4c } }

+ ## Include/Ppi/PciDevice.h
+ gEdkiiPeiPciDevicePpiGuid = { 0x1597ab4f, 0xd542, 0x4efe, { 0x9a, 0xf7, 0xb2, 0x44, 0xec, 0x54, 0x4c, 0x0b } }
+
## Include/Ppi/CapsuleOnDisk.h
gEdkiiPeiCapsuleOnDiskPpiGuid = { 0x71a9ea61, 0x5a35, 0x4a5d, { 0xac, 0xef, 0x9c, 0xf8, 0x6d, 0x6d, 0x67, 0xe0 } }
gEdkiiPeiBootInCapsuleOnDiskModePpiGuid = { 0xb08a11e4, 0xe2b7, 0x4b75, { 0xb5, 0x15, 0xaf, 0x61, 0x6, 0x68, 0xbf, 0xd1 } }
--
2.27.0.windows.1

---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.


Re: [GSOC 2022] Adding Rust support to EDK II: Introducing Myself

 

Hi Michael,

I was wondering when we can start the discussions about the project.
After doing some more research, I would like to make some changes to
the proposed schedule and iron out some implementation details.

So it would be great if you can clarify how and where the discussions
should take place.

Yours Sincerely
Ayush Singh

On Thu, May 26, 2022 at 2:20 AM Michael Kubacki
<mikuback@...> wrote:

Hi Ayush,

Welcome! I'm excited about this project too and I look forward to
working you.

We will be reaching out soon to set up our regularly scheduled
discussions and meet you.

Regards,
Michael

On 5/21/2022 1:09 AM, Ayush Singh wrote:
Hello Everyone,

I am Ayush Singh, a 2nd-year university student from the Indian
Institute of Technology (Indian School of Mines), Dhanbad, India. In
Google Summer of Code 2022, I will be working on Adding Rust support
to EDK II. The original Task from the wiki can be found here:
https://github.com/tianocore/tianocore.github.io/wiki/Tasks-Add-Rust-Support-to-EDK-II

This email is just to formally introduce myself to the mailing list. I
hope I will be able to help improve the EDK II project during the
course of Google Summer of Code, and even after that.

According to the GSoC dashboard, Michael Kinney and Michael Kubacki
are the mentors for this project, so I would like to get in touch with
them soon as well.

I look forward to working on this wonderful and exciting project.

Yours Sincerely
Ayush Singh




Re: [PATCH 5/5] CpuException: Add InitializeSeparateExceptionStacks

Dong, Eric
 

Acked-by: Eric Dong <eric.dong@...>

-----Original Message-----
From: Ni, Ray <ray.ni@...>
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>; Wang, Jian J <jian.j.wang@...>
Subject: [PATCH 5/5] CpuException: Add InitializeSeparateExceptionStacks

Today InitializeCpuExceptionHandlersEx is called from three modules:
1. DxeCore (links to DxeCpuExceptionHandlerLib)
DxeCore expects it initializes the IDT entries as well as
assigning separate stacks for #DF and #PF.
2. CpuMpPei (links to PeiCpuExceptionHandlerLib)
and CpuDxe (links to DxeCpuExceptionHandlerLib)
It's called for each thread for only assigning separate stacks for
#DF and #PF. The IDT entries initialization is skipped because
caller sets InitData->X64.InitDefaultHandlers to FALSE.

Additionally, SecPeiCpuExceptionHandlerLib, SmmCpuExceptionHandlerLib also implement such API and the behavior of the API is simply to initialize IDT entries only.

Because it mixes the IDT entries initialization and separate stacks assignment for certain exception handlers together, in order to know whether the function call only initializes IDT entries, or assigns stacks, we need to check:
1. value of InitData->X64.InitDefaultHandlers 2. library instance

This patch cleans up the code to separate the stack assignment to a new API:
InitializeSeparateExceptionStacks().

Only when caller calls the new API, the separate stacks are assigned.
With this change, the SecPei and Smm instance can return unsupported which gives caller a very clear status.

The old API InitializeCpuExceptionHandlersEx() is removed in this patch.
Because no platform module is consuming the old API, the impact is none.

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
Cc: Jian J Wang <jian.j.wang@...>
---
MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 2 +-
.../Include/Library/CpuExceptionHandlerLib.h | 24 ++---
.../CpuExceptionHandlerLibNull.c | 26 ++----
UefiCpuPkg/CpuDxe/CpuMp.c | 6 +-
UefiCpuPkg/CpuMpPei/CpuMpPei.c | 4 +-
.../CpuExceptionHandlerLib/DxeException.c | 91 ++++++-------------
.../CpuExceptionHandlerLib/PeiCpuException.c | 51 ++---------
.../SecPeiCpuException.c | 27 ++----
.../CpuExceptionHandlerLib/SmmException.c | 27 ++----
9 files changed, 74 insertions(+), 184 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
index 2c27fc0695..83f49d7c00 100644
--- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
+++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
@@ -253,7 +253,7 @@ DxeMain (
VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob)); } - Status = InitializeCpuExceptionHandlersEx (VectorInfoList, NULL);+ Status = InitializeCpuExceptionHandlers (VectorInfoList); ASSERT_EFI_ERROR (Status); //diff --git a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
index d4649bebe1..9a495081f7 100644
--- a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
+++ b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
@@ -103,32 +103,20 @@ InitializeCpuExceptionHandlers (
); /**- Initializes all CPU exceptions entries with optional extra initializations.+ Setup separate stacks for certain exception handlers. - By default, this method should include all functionalities implemented by- InitializeCpuExceptionHandlers(), plus extra initialization works, if any.- This could be done by calling InitializeCpuExceptionHandlers() directly- in this method besides the extra works.+ InitData is optional and processor arch dependent. - InitData is optional and its use and content are processor arch dependent.- The typical usage of it is to convey resources which have to be reserved- elsewhere and are necessary for the extra initializations of exception.+ @param[in] InitData Pointer to data optional for information about how+ to assign stacks for certain exception handlers. - @param[in] VectorInfo Pointer to reserved vector list.- @param[in] InitData Pointer to data optional for extra initializations- of exception.-- @retval EFI_SUCCESS The exceptions have been successfully- initialized.- @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid- content.+ @retval EFI_SUCCESS The stacks are assigned successfully. @retval EFI_UNSUPPORTED This function is not supported. **/ EFI_STATUS EFIAPI-InitializeCpuExceptionHandlersEx (- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,+InitializeSeparateExceptionStacks ( IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL ); diff --git a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.c b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.c
index 54f38788fe..8aeedcb4d1 100644
--- a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.c
+++ b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandle
+++ rLibNull.c
@@ -82,34 +82,22 @@ DumpCpuContext (
} /**- Initializes all CPU exceptions entries with optional extra initializations.+ Setup separate stacks for certain exception handlers. - By default, this method should include all functionalities implemented by- InitializeCpuExceptionHandlers(), plus extra initialization works, if any.- This could be done by calling InitializeCpuExceptionHandlers() directly- in this method besides the extra works.+ InitData is optional and processor arch dependent. - InitData is optional and its use and content are processor arch dependent.- The typical usage of it is to convey resources which have to be reserved- elsewhere and are necessary for the extra initializations of exception.+ @param[in] InitData Pointer to data optional for information about how+ to assign stacks for certain exception handlers. - @param[in] VectorInfo Pointer to reserved vector list.- @param[in] InitData Pointer to data optional for extra initializations- of exception.-- @retval EFI_SUCCESS The exceptions have been successfully- initialized.- @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid- content.+ @retval EFI_SUCCESS The stacks are assigned successfully. @retval EFI_UNSUPPORTED This function is not supported. **/ EFI_STATUS EFIAPI-InitializeCpuExceptionHandlersEx (- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,+InitializeSeparateExceptionStacks ( IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL ) {- return InitializeCpuExceptionHandlers (VectorInfo);+ return EFI_UNSUPPORTED; }diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index 1f218367b3..e385f585c7 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -1,7 +1,7 @@
/** @file CPU DXE Module to produce CPU MP Protocol. - Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>+ Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/@@ -617,7 +617,7 @@ GetGdtr (
/** Initializes CPU exceptions handlers for the sake of stack switch requirement. - This function is a wrapper of InitializeCpuExceptionHandlersEx. It's mainly+ This function is a wrapper of InitializeSeparateExceptionStacks. It's mainly for the sake of AP's init because of EFI_AP_PROCEDURE API requirement. @param[in,out] Buffer The pointer to private data buffer.@@ -641,7 +641,7 @@ InitializeExceptionStackSwitchHandlers (
AsmReadIdtr (&Idtr); EssData->Ia32.IdtTable = (VOID *)Idtr.Base; EssData->Ia32.IdtTableSize = Idtr.Limit + 1;- Status = InitializeCpuExceptionHandlersEx (NULL, EssData);+ Status = InitializeSeparateExceptionStacks (EssData); ASSERT_EFI_ERROR (Status); } diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index 1e68c91d95..d4786979fa 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -432,7 +432,7 @@ GetGdtr (
/** Initializes CPU exceptions handlers for the sake of stack switch requirement. - This function is a wrapper of InitializeCpuExceptionHandlersEx. It's mainly+ This function is a wrapper of InitializeSeparateExceptionStacks. It's mainly for the sake of AP's init because of EFI_AP_PROCEDURE API requirement. @param[in,out] Buffer The pointer to private data buffer.@@ -456,7 +456,7 @@ InitializeExceptionStackSwitchHandlers (
AsmReadIdtr (&Idtr); EssData->Ia32.IdtTable = (VOID *)Idtr.Base; EssData->Ia32.IdtTableSize = Idtr.Limit + 1;- Status = InitializeCpuExceptionHandlersEx (NULL, EssData);+ Status = InitializeSeparateExceptionStacks (EssData); ASSERT_EFI_ERROR (Status); } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index c7c1fe31d2..e62bb5e6c0 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -103,82 +103,49 @@ RegisterCpuInterruptHandler (
} /**- Initializes CPU exceptions entries and setup stack switch for given exceptions.+ Setup separate stacks for certain exception handlers. - This method will call InitializeCpuExceptionHandlers() to setup default- exception handlers unless indicated not to do it explicitly.+ InitData is optional and processor arch dependent. - If InitData is passed with NULL, this method will use the resource reserved- by global variables to initialize it; Otherwise it will use data in InitData- to setup stack switch. This is for the different use cases in DxeCore and- Cpu MP exception initialization.+ @param[in] InitData Pointer to data optional for information about how+ to assign stacks for certain exception handlers. - @param[in] VectorInfo Pointer to reserved vector list.- @param[in] InitData Pointer to data required to setup stack switch for- given exceptions.-- @retval EFI_SUCCESS The exceptions have been successfully- initialized.- @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid- content.+ @retval EFI_SUCCESS The stacks are assigned successfully.+ @retval EFI_UNSUPPORTED This function is not supported. **/ EFI_STATUS EFIAPI-InitializeCpuExceptionHandlersEx (- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,+InitializeSeparateExceptionStacks ( IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL ) {- EFI_STATUS Status; CPU_EXCEPTION_INIT_DATA EssData; IA32_DESCRIPTOR Idtr; IA32_DESCRIPTOR Gdtr; - //- // To avoid repeat initialization of default handlers, the caller should pass- // an extended init data with InitDefaultHandlers set to FALSE. There's no- // need to call this method to just initialize default handlers. Call non-ex- // version instead; or this method must be implemented as a simple wrapper of- // non-ex version of it, if this version has to be called.- //- if ((InitData == NULL) || InitData->X64.InitDefaultHandlers) {- Status = InitializeCpuExceptionHandlers (VectorInfo);- } else {- Status = EFI_SUCCESS;- }-- if (!EFI_ERROR (Status)) {- //- // Initializing stack switch is only necessary for Stack Guard functionality.- //- if (PcdGetBool (PcdCpuStackGuard)) {- if (InitData == NULL) {- SetMem (mNewGdt, sizeof (mNewGdt), 0);-- AsmReadIdtr (&Idtr);- AsmReadGdtr (&Gdtr);-- EssData.X64.Revision = CPU_EXCEPTION_INIT_DATA_REV;- EssData.X64.KnownGoodStackTop = (UINTN)mNewStack + sizeof (mNewStack);- EssData.X64.KnownGoodStackSize = CPU_KNOWN_GOOD_STACK_SIZE;- EssData.X64.StackSwitchExceptions = CPU_STACK_SWITCH_EXCEPTION_LIST;- EssData.X64.StackSwitchExceptionNumber = CPU_STACK_SWITCH_EXCEPTION_NUMBER;- EssData.X64.IdtTable = (VOID *)Idtr.Base;- EssData.X64.IdtTableSize = Idtr.Limit + 1;- EssData.X64.GdtTable = mNewGdt;- EssData.X64.GdtTableSize = sizeof (mNewGdt);- EssData.X64.ExceptionTssDesc = mNewGdt + Gdtr.Limit + 1;- EssData.X64.ExceptionTssDescSize = CPU_TSS_DESC_SIZE;- EssData.X64.ExceptionTss = mNewGdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;- EssData.X64.ExceptionTssSize = CPU_TSS_SIZE;-- InitData = &EssData;- }-- Status = ArchSetupExceptionStack (InitData);- }+ if (InitData == NULL) {+ SetMem (mNewGdt, sizeof (mNewGdt), 0);++ AsmReadIdtr (&Idtr);+ AsmReadGdtr (&Gdtr);++ EssData.X64.Revision = CPU_EXCEPTION_INIT_DATA_REV;+ EssData.X64.KnownGoodStackTop = (UINTN)mNewStack + sizeof (mNewStack);+ EssData.X64.KnownGoodStackSize = CPU_KNOWN_GOOD_STACK_SIZE;+ EssData.X64.StackSwitchExceptions = CPU_STACK_SWITCH_EXCEPTION_LIST;+ EssData.X64.StackSwitchExceptionNumber = CPU_STACK_SWITCH_EXCEPTION_NUMBER;+ EssData.X64.IdtTable = (VOID *)Idtr.Base;+ EssData.X64.IdtTableSize = Idtr.Limit + 1;+ EssData.X64.GdtTable = mNewGdt;+ EssData.X64.GdtTableSize = sizeof (mNewGdt);+ EssData.X64.ExceptionTssDesc = mNewGdt + Gdtr.Limit + 1;+ EssData.X64.ExceptionTssDescSize = CPU_TSS_DESC_SIZE;+ EssData.X64.ExceptionTss = mNewGdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;+ EssData.X64.ExceptionTssSize = CPU_TSS_SIZE;++ InitData = &EssData; } - return Status;+ return ArchSetupExceptionStack (InitData); }diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
index 1ae611c75e..494c2ab433 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
@@ -150,57 +150,26 @@ InitializeCpuExceptionHandlers (
} /**- Initializes all CPU exceptions entries with optional extra initializations.+ Setup separate stacks for certain exception handlers. - By default, this method should include all functionalities implemented by- InitializeCpuExceptionHandlers(), plus extra initialization works, if any.- This could be done by calling InitializeCpuExceptionHandlers() directly- in this method besides the extra works.+ InitData is optional and processor arch dependent. - InitData is optional and its use and content are processor arch dependent.- The typical usage of it is to convey resources which have to be reserved- elsewhere and are necessary for the extra initializations of exception.+ @param[in] InitData Pointer to data optional for information about how+ to assign stacks for certain exception handlers. - @param[in] VectorInfo Pointer to reserved vector list.- @param[in] InitData Pointer to data optional for extra initializations- of exception.-- @retval EFI_SUCCESS The exceptions have been successfully- initialized.- @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid- content.+ @retval EFI_SUCCESS The stacks are assigned successfully.+ @retval EFI_UNSUPPORTED This function is not supported. **/ EFI_STATUS EFIAPI-InitializeCpuExceptionHandlersEx (- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,+InitializeSeparateExceptionStacks ( IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL ) {- EFI_STATUS Status;-- //- // To avoid repeat initialization of default handlers, the caller should pass- // an extended init data with InitDefaultHandlers set to FALSE. There's no- // need to call this method to just initialize default handlers. Call non-ex- // version instead; or this method must be implemented as a simple wrapper of- // non-ex version of it, if this version has to be called.- //- if ((InitData == NULL) || InitData->Ia32.InitDefaultHandlers) {- Status = InitializeCpuExceptionHandlers (VectorInfo);- } else {- Status = EFI_SUCCESS;- }-- if (!EFI_ERROR (Status)) {- //- // Initializing stack switch is only necessary for Stack Guard functionality.- //- if (PcdGetBool (PcdCpuStackGuard) && (InitData != NULL)) {- Status = ArchSetupExceptionStack (InitData);- }+ if (InitData == NULL) {+ return EFI_UNSUPPORTED; } - return Status;+ return ArchSetupExceptionStack (InitData); }diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
index e894ead612..4313cc5582 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
@@ -200,33 +200,22 @@ RegisterCpuInterruptHandler (
} /**- Initializes all CPU exceptions entries with optional extra initializations.+ Setup separate stacks for certain exception handlers. - By default, this method should include all functionalities implemented by- InitializeCpuExceptionHandlers(), plus extra initialization works, if any.- This could be done by calling InitializeCpuExceptionHandlers() directly- in this method besides the extra works.+ InitData is optional and processor arch dependent. - InitData is optional and its use and content are processor arch dependent.- The typical usage of it is to convey resources which have to be reserved- elsewhere and are necessary for the extra initializations of exception.+ @param[in] InitData Pointer to data optional for information about how+ to assign stacks for certain exception handlers. - @param[in] VectorInfo Pointer to reserved vector list.- @param[in] InitData Pointer to data optional for extra initializations- of exception.-- @retval EFI_SUCCESS The exceptions have been successfully- initialized.- @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid- content.+ @retval EFI_SUCCESS The stacks are assigned successfully.+ @retval EFI_UNSUPPORTED This function is not supported. **/ EFI_STATUS EFIAPI-InitializeCpuExceptionHandlersEx (- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,+InitializeSeparateExceptionStacks ( IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL ) {- return InitializeCpuExceptionHandlers (VectorInfo);+ return EFI_UNSUPPORTED; }diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
index ec643556c7..1c97dab926 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
@@ -96,33 +96,22 @@ RegisterCpuInterruptHandler (
} /**- Initializes all CPU exceptions entries with optional extra initializations.+ Setup separate stacks for certain exception handlers. - By default, this method should include all functionalities implemented by- InitializeCpuExceptionHandlers(), plus extra initialization works, if any.- This could be done by calling InitializeCpuExceptionHandlers() directly- in this method besides the extra works.+ InitData is optional and processor arch dependent. - InitData is optional and its use and content are processor arch dependent.- The typical usage of it is to convey resources which have to be reserved- elsewhere and are necessary for the extra initializations of exception.+ @param[in] InitData Pointer to data optional for information about how+ to assign stacks for certain exception handlers. - @param[in] VectorInfo Pointer to reserved vector list.- @param[in] InitData Pointer to data optional for extra initializations- of exception.-- @retval EFI_SUCCESS The exceptions have been successfully- initialized.- @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid- content.+ @retval EFI_SUCCESS The stacks are assigned successfully.+ @retval EFI_UNSUPPORTED This function is not supported. **/ EFI_STATUS EFIAPI-InitializeCpuExceptionHandlersEx (- IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,+InitializeSeparateExceptionStacks ( IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL ) {- return InitializeCpuExceptionHandlers (VectorInfo);+ return EFI_UNSUPPORTED; }--
2.35.1.windows.2


Re: [PATCH 4/5] CpuException: Remove InitializeCpuInterruptHandlers

Dong, Eric
 

Acked-by: Eric Dong eric.dong@...

 

From: Ni, Ray <ray.ni@...>
Sent: Tuesday, May 24, 2022 4:04 PM
To: Wang, Jian J <jian.j.wang@...>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: Re: [edk2-devel] [PATCH 4/5] CpuException: Remove InitializeCpuInterruptHandlers

 

Jian,
I think we need discussion on where to put the common CPU_INTERRUPT_NUM definition.

Do you agree that we can leave that to another patch?

________________________________________
From: Wang, Jian J <jian.j.wang@...>
Sent: Monday, May 23, 2022 0:27
To: devel@edk2.groups.io; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 4/5] CpuException: Remove InitializeCpuInterruptHandlers

Hi Ray,

Both CpuDxe.c and CpuExceptionCommon.h have CPU_INTERRUPT_NUM defined.
I'd suggest to move it to a common place, such as BaseLib.h. I don't see any issue
if they are defined to different value. It just gives me a feeling that it might cause
potential problems sometimes in the future.


Regards,
Jian

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray
> Sent: Friday, May 20, 2022 10:16 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@...>
> Subject: [edk2-devel] [PATCH 4/5] CpuException: Remove
> InitializeCpuInterruptHandlers
>
> InitializeCpuExceptionHandlers() expects caller allocates IDT while
> InitializeCpuInterruptHandlers() allocates 256 IDT entries itself.
>
> InitializeCpuExceptionHandlers() fills max 32 IDT entries allocated
> by caller. If caller allocates 10 entries, the API just fills 10 IDT
> entries.
>
> The inconsistency between the two APIs makes code hard to
> unerstand and hard to share.
>
> Because there is only one caller (CpuDxe) for
> InitializeCpuInterruptHandler(), this patch updates CpuDxe driver
> to allocates 256 IDT entries then call
> InitializeCpuExceptionHandlers().
>
> With this change, InitializeCpuInterruptHandlers() is removed
> completely.
>
> And InitializeCpuExceptionHandlers() fills max 32 entries for PEI
> and SMM instance, max 256 entries for DXE instance.
> Such behavior matches to the original one.
>
> Signed-off-by: Ray Ni <ray.ni@...>
> Cc: Eric Dong <eric.dong@...>
> ---
>  .../Include/Library/CpuExceptionHandlerLib.h  | 28 +------
>  .../CpuExceptionHandlerLibNull.c              | 31 +------
>  UefiCpuPkg/CpuDxe/CpuDxe.c                    | 33 ++++++--
>  .../CpuExceptionHandlerLib/DxeException.c     | 80 ++-----------------
>  .../CpuExceptionHandlerLib/PeiCpuException.c  | 61 +-------------
>  .../PeiDxeSmmCpuException.c                   | 19 ++---
>  .../SecPeiCpuException.c                      | 31 +------
>  .../CpuExceptionHandlerLib/SmmException.c     | 35 ++------
>  8 files changed, 56 insertions(+), 262 deletions(-)
>
> diff --git a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> index 22a4408f9f..d4649bebe1 100644
> --- a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> +++ b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> @@ -2,7 +2,7 @@
>    CPU Exception library provides the default CPU interrupt/exception handler.
>
>    It also provides capability to register user interrupt/exception handler.
>
>
>
> -  Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
>
> +  Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -132,28 +132,6 @@ InitializeCpuExceptionHandlersEx (
>    IN CPU_EXCEPTION_INIT_DATA  *InitData OPTIONAL
>
>    );
>
>
>
> -/**
>
> -  Initializes all CPU interrupt/exceptions entries and provides the default
> interrupt/exception handlers.
>
> -
>
> -  Caller should try to get an array of interrupt and/or exception vectors that are
> in use and need to
>
> -  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
>
> -  If caller cannot get reserved vector list or it does not exists, set VectorInfo to
> NULL.
>
> -  If VectorInfo is not NULL, the exception vectors will be initialized per vector
> attribute accordingly.
>
> -
>
> -  @param[in]  VectorInfo    Pointer to reserved vector list.
>
> -
>
> -  @retval EFI_SUCCESS           All CPU interrupt/exception entries have been
> successfully initialized
>
> -                                with default interrupt/exception handlers.
>
> -  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
> VectorInfo is not NULL.
>
> -  @retval EFI_UNSUPPORTED       This function is not supported.
>
> -
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -InitializeCpuInterruptHandlers (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
>
> -  );
>
> -
>
>  /**
>
>    Registers a function to be called from the processor interrupt handler.
>
>
>
> @@ -161,8 +139,8 @@ InitializeCpuInterruptHandlers (
>    interrupt or exception type specified by InterruptType. If InterruptHandler is
> NULL, then the
>
>    handler for the processor interrupt or exception type specified by
> InterruptType is uninstalled.
>
>    The installed handler is called once for each processor interrupt or exception.
>
> -  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> or
>
> -  InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
> returned.
>
> +  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> is invoked,
>
> +  otherwise EFI_UNSUPPORTED returned.
>
>
>
>    @param[in]  InterruptType     Defines which interrupt or exception to hook.
>
>    @param[in]  InterruptHandler  A pointer to a function of type
> EFI_CPU_INTERRUPT_HANDLER that is called
>
> diff --git
> a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
> Null.c
> b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
> Null.c
> index 35ab5a8db5..54f38788fe 100644
> ---
> a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
> Null.c
> +++
> b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLib
> Null.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>    CPU Exception Handler library implementition with empty functions.
>
>
>
> -  Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
>
> +  Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -33,31 +33,6 @@ InitializeCpuExceptionHandlers (
>    return EFI_SUCCESS;
>
>  }
>
>
>
> -/**
>
> -  Initializes all CPU interrupt/exceptions entries and provides the default
> interrupt/exception handlers.
>
> -
>
> -  Caller should try to get an array of interrupt and/or exception vectors that are
> in use and need to
>
> -  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
>
> -  If caller cannot get reserved vector list or it does not exists, set VectorInfo to
> NULL.
>
> -  If VectorInfo is not NULL, the exception vectors will be initialized per vector
> attribute accordingly.
>
> -
>
> -  @param[in]  VectorInfo    Pointer to reserved vector list.
>
> -
>
> -  @retval EFI_SUCCESS           All CPU interrupt/exception entries have been
> successfully initialized
>
> -                                with default interrupt/exception handlers.
>
> -  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
> VectorInfo is not NULL.
>
> -  @retval EFI_UNSUPPORTED       This function is not supported.
>
> -
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -InitializeCpuInterruptHandlers (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
>
> -  )
>
> -{
>
> -  return EFI_SUCCESS;
>
> -}
>
> -
>
>  /**
>
>    Registers a function to be called from the processor interrupt handler.
>
>
>
> @@ -65,8 +40,8 @@ InitializeCpuInterruptHandlers (
>    interrupt or exception type specified by InterruptType. If InterruptHandler is
> NULL, then the
>
>    handler for the processor interrupt or exception type specified by
> InterruptType is uninstalled.
>
>    The installed handler is called once for each processor interrupt or exception.
>
> -  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> or
>
> -  InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
> returned.
>
> +  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> is invoked,
>
> +  otherwise EFI_UNSUPPORTED returned.
>
>
>
>    @param[in]  InterruptType     Defines which interrupt or exception to hook.
>
>    @param[in]  InterruptHandler  A pointer to a function of type
> EFI_CPU_INTERRUPT_HANDLER that is called
>
> diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c
> index 00f3cb0957..a6a91507f6 100644
> --- a/UefiCpuPkg/CpuDxe/CpuDxe.c
> +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>    CPU DXE Module to produce CPU ARCH Protocol.
>
>
>
> -  Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
>
> +  Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR>
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -10,6 +10,8 @@
>  #include "CpuMp.h"
>
>  #include "CpuPageTable.h"
>
>
>
> +#define CPU_INTERRUPT_NUM  256
>
> +
>
>  //
>
>  // Global Variables
>
>  //
>
> @@ -924,9 +926,12 @@ InitInterruptDescriptorTable (
>    VOID
>
>    )
>
>  {
>
> -  EFI_STATUS               Status;
>
> -  EFI_VECTOR_HANDOFF_INFO  *VectorInfoList;
>
> -  EFI_VECTOR_HANDOFF_INFO  *VectorInfo;
>
> +  EFI_STATUS                Status;
>
> +  EFI_VECTOR_HANDOFF_INFO   *VectorInfoList;
>
> +  EFI_VECTOR_HANDOFF_INFO   *VectorInfo;
>
> +  IA32_IDT_GATE_DESCRIPTOR  *IdtTable;
>
> +  IA32_DESCRIPTOR           IdtDescriptor;
>
> +  UINTN                     IdtEntryCount;
>
>
>
>    VectorInfo = NULL;
>
>    Status     = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid,
> (VOID **)&VectorInfoList);
>
> @@ -934,7 +939,25 @@ InitInterruptDescriptorTable (
>      VectorInfo = VectorInfoList;
>
>    }
>
>
>
> -  Status = InitializeCpuInterruptHandlers (VectorInfo);
>
> +  AsmReadIdtr (&IdtDescriptor);
>
> +  IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
> (IA32_IDT_GATE_DESCRIPTOR);
>
> +  if (IdtEntryCount < CPU_INTERRUPT_NUM) {
>
> +    //
>
> +    // Increase Interrupt Descriptor Table and Copy the old IDT table in
>
> +    //
>
> +    IdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) *
> CPU_INTERRUPT_NUM);
>
> +    ASSERT (IdtTable != NULL);
>
> +    CopyMem (IdtTable, (VOID *)IdtDescriptor.Base, sizeof
> (IA32_IDT_GATE_DESCRIPTOR) * IdtEntryCount);
>
> +
>
> +    //
>
> +    // Load Interrupt Descriptor Table
>
> +    //
>
> +    IdtDescriptor.Base  = (UINTN)IdtTable;
>
> +    IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) *
> CPU_INTERRUPT_NUM - 1);
>
> +    AsmWriteIdtr (&IdtDescriptor);
>
> +  }
>
> +
>
> +  Status = InitializeCpuExceptionHandlers (VectorInfo);
>
>    ASSERT_EFI_ERROR (Status);
>
>  }
>
>
>
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> index f139131a7c..c7c1fe31d2 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>    CPU exception handler library implemenation for DXE modules.
>
>
>
> -  Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>
>
> +  Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -17,8 +17,8 @@ CONST UINTN  mDoFarReturnFlag = 0;
>  RESERVED_VECTORS_DATA      mReservedVectorsData[CPU_INTERRUPT_NUM];
>
>  EFI_CPU_INTERRUPT_HANDLER
> mExternalInterruptHandlerTable[CPU_INTERRUPT_NUM];
>
>  EXCEPTION_HANDLER_DATA     mExceptionHandlerData = {
>
> -  0,   // To be fixed
>
> -  0,   // To be fixed
>
> +  CPU_INTERRUPT_NUM,
>
> +  0,                     // To be fixed
>
>    mReservedVectorsData,
>
>    mExternalInterruptHandlerTable
>
>  };
>
> @@ -69,76 +69,6 @@ InitializeCpuExceptionHandlers (
>    return InitializeCpuExceptionHandlersWorker (VectorInfo,
> &mExceptionHandlerData);
>
>  }
>
>
>
> -/**
>
> -  Initializes all CPU interrupt/exceptions entries and provides the default
> interrupt/exception handlers.
>
> -
>
> -  Caller should try to get an array of interrupt and/or exception vectors that are
> in use and need to
>
> -  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
>
> -  If caller cannot get reserved vector list or it does not exists, set VectorInfo to
> NULL.
>
> -  If VectorInfo is not NULL, the exception vectors will be initialized per vector
> attribute accordingly.
>
> -
>
> -  @param[in]  VectorInfo    Pointer to reserved vector list.
>
> -
>
> -  @retval EFI_SUCCESS           All CPU interrupt/exception entries have been
> successfully initialized
>
> -                                with default interrupt/exception handlers.
>
> -  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
> VectorInfo is not NULL.
>
> -  @retval EFI_UNSUPPORTED       This function is not supported.
>
> -
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -InitializeCpuInterruptHandlers (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
>
> -  )
>
> -{
>
> -  EFI_STATUS                      Status;
>
> -  IA32_IDT_GATE_DESCRIPTOR        *IdtTable;
>
> -  IA32_DESCRIPTOR                 IdtDescriptor;
>
> -  UINTN                           IdtEntryCount;
>
> -  EXCEPTION_HANDLER_TEMPLATE_MAP  TemplateMap;
>
> -
>
> -  SetMem ((VOID *)mReservedVectorsData, sizeof (RESERVED_VECTORS_DATA)
> * CPU_INTERRUPT_NUM, 0xff);
>
> -  if (VectorInfo != NULL) {
>
> -    Status = ReadAndVerifyVectorInfo (VectorInfo, mReservedVectorsData,
> CPU_INTERRUPT_NUM);
>
> -    if (EFI_ERROR (Status)) {
>
> -      return EFI_INVALID_PARAMETER;
>
> -    }
>
> -  }
>
> -
>
> -  //
>
> -  // Read IDT descriptor and calculate IDT size
>
> -  //
>
> -  AsmReadIdtr (&IdtDescriptor);
>
> -  IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
> (IA32_IDT_GATE_DESCRIPTOR);
>
> -  if (IdtEntryCount > CPU_INTERRUPT_NUM) {
>
> -    IdtEntryCount = CPU_INTERRUPT_NUM;
>
> -  }
>
> -
>
> -  //
>
> -  // Create Interrupt Descriptor Table and Copy the old IDT table in
>
> -  //
>
> -  IdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) *
> CPU_INTERRUPT_NUM);
>
> -  ASSERT (IdtTable != NULL);
>
> -  CopyMem (IdtTable, (VOID *)IdtDescriptor.Base, sizeof
> (IA32_IDT_GATE_DESCRIPTOR) * IdtEntryCount);
>
> -
>
> -  AsmGetTemplateAddressMap (&TemplateMap);
>
> -  ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);
>
> -
>
> -  mExceptionHandlerData.IdtEntryCount            = CPU_INTERRUPT_NUM;
>
> -  InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);
>
> -
>
> -  UpdateIdtTable (IdtTable, &TemplateMap, &mExceptionHandlerData);
>
> -
>
> -  //
>
> -  // Load Interrupt Descriptor Table
>
> -  //
>
> -  IdtDescriptor.Base  = (UINTN)IdtTable;
>
> -  IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) *
> CPU_INTERRUPT_NUM - 1);
>
> -  AsmWriteIdtr ((IA32_DESCRIPTOR *)&IdtDescriptor);
>
> -
>
> -  return EFI_SUCCESS;
>
> -}
>
> -
>
>  /**
>
>    Registers a function to be called from the processor interrupt handler.
>
>
>
> @@ -146,8 +76,8 @@ InitializeCpuInterruptHandlers (
>    interrupt or exception type specified by InterruptType. If InterruptHandler is
> NULL, then the
>
>    handler for the processor interrupt or exception type specified by
> InterruptType is uninstalled.
>
>    The installed handler is called once for each processor interrupt or exception.
>
> -  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> or
>
> -  InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
> returned.
>
> +  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> is invoked,
>
> +  otherwise EFI_UNSUPPORTED returned.
>
>
>
>    @param[in]  InterruptType     Defines which interrupt or exception to hook.
>
>    @param[in]  InterruptHandler  A pointer to a function of type
> EFI_CPU_INTERRUPT_HANDLER that is called
>
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> index 687fc4177f..1ae611c75e 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>    CPU exception handler library implementation for PEIM module.
>
>
>
> -Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
>
> +Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.<BR>
>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -133,6 +133,7 @@ InitializeCpuExceptionHandlers (
>
>
>    ExceptionHandlerData = AllocatePool (sizeof (EXCEPTION_HANDLER_DATA));
>
>    ASSERT (ExceptionHandlerData != NULL);
>
> +  ExceptionHandlerData->IdtEntryCount            = CPU_EXCEPTION_NUM;
>
>    ExceptionHandlerData->ReservedVectors          = ReservedVectors;
>
>    ExceptionHandlerData->ExternalInterruptHandler = NULL;
>
>    InitializeSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);
>
> @@ -148,64 +149,6 @@ InitializeCpuExceptionHandlers (
>    return EFI_SUCCESS;
>
>  }
>
>
>
> -/**
>
> -  Initializes all CPU interrupt/exceptions entries and provides the default
> interrupt/exception handlers.
>
> -
>
> -  Caller should try to get an array of interrupt and/or exception vectors that are
> in use and need to
>
> -  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
>
> -  If caller cannot get reserved vector list or it does not exists, set VectorInfo to
> NULL.
>
> -  If VectorInfo is not NULL, the exception vectors will be initialized per vector
> attribute accordingly.
>
> -
>
> -  @param[in]  VectorInfo    Pointer to reserved vector list.
>
> -
>
> -  @retval EFI_SUCCESS           All CPU interrupt/exception entries have been
> successfully initialized
>
> -                                with default interrupt/exception handlers.
>
> -  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
> VectorInfo is not NULL.
>
> -  @retval EFI_UNSUPPORTED       This function is not supported.
>
> -
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -InitializeCpuInterruptHandlers (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
>
> -  )
>
> -{
>
> -  return EFI_UNSUPPORTED;
>
> -}
>
> -
>
> -/**
>
> -  Registers a function to be called from the processor interrupt handler.
>
> -
>
> -  This function registers and enables the handler specified by InterruptHandler
> for a processor
>
> -  interrupt or exception type specified by InterruptType. If InterruptHandler is
> NULL, then the
>
> -  handler for the processor interrupt or exception type specified by
> InterruptType is uninstalled.
>
> -  The installed handler is called once for each processor interrupt or exception.
>
> -  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> or
>
> -  InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
> returned.
>
> -
>
> -  @param[in]  InterruptType     Defines which interrupt or exception to hook.
>
> -  @param[in]  InterruptHandler  A pointer to a function of type
> EFI_CPU_INTERRUPT_HANDLER that is called
>
> -                                when a processor interrupt occurs. If this parameter is NULL,
> then the handler
>
> -                                will be uninstalled.
>
> -
>
> -  @retval EFI_SUCCESS           The handler for the processor interrupt was
> successfully installed or uninstalled.
>
> -  @retval EFI_ALREADY_STARTED   InterruptHandler is not NULL, and a handler
> for InterruptType was
>
> -                                previously installed.
>
> -  @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for
> InterruptType was not
>
> -                                previously installed.
>
> -  @retval EFI_UNSUPPORTED       The interrupt specified by InterruptType is not
> supported,
>
> -                                or this function is not supported.
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -RegisterCpuInterruptHandler (
>
> -  IN EFI_EXCEPTION_TYPE         InterruptType,
>
> -  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler
>
> -  )
>
> -{
>
> -  return EFI_UNSUPPORTED;
>
> -}
>
> -
>
>  /**
>
>    Initializes all CPU exceptions entries with optional extra initializations.
>
>
>
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
> index f47a80dcab..a7d0897ef1 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>    CPU Exception Library provides PEI/DXE/SMM CPU common exception handler.
>
>
>
> -Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
>
> +Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>
>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -261,31 +261,26 @@ InitializeCpuExceptionHandlersWorker (
>    RESERVED_VECTORS_DATA           *ReservedVectors;
>
>
>
>    ReservedVectors = ExceptionHandlerData->ReservedVectors;
>
> -  SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) *
> CPU_EXCEPTION_NUM, 0xff);
>
> +  SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) *
> ExceptionHandlerData->IdtEntryCount, 0xff);
>
>    if (VectorInfo != NULL) {
>
> -    Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors,
> CPU_EXCEPTION_NUM);
>
> +    Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors,
> ExceptionHandlerData->IdtEntryCount);
>
>      if (EFI_ERROR (Status)) {
>
>        return EFI_INVALID_PARAMETER;
>
>      }
>
>    }
>
>
>
>    //
>
> -  // Read IDT descriptor and calculate IDT size
>
> +  // Setup the exception handlers according to IDT size, but no more than
>
> +  //   ExceptionHandlerData->IdtEntryCount (32 in PEI and SMM, 256 in DXE)
> handlers.
>
>    //
>
>    AsmReadIdtr (&IdtDescriptor);
>
> -  IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof
> (IA32_IDT_GATE_DESCRIPTOR);
>
> -  if (IdtEntryCount > CPU_EXCEPTION_NUM) {
>
> -    //
>
> -    // CPU exception library only setup CPU_EXCEPTION_NUM exception handler
> at most
>
> -    //
>
> -    IdtEntryCount = CPU_EXCEPTION_NUM;
>
> -  }
>
> +  IdtEntryCount                       = (IdtDescriptor.Limit + 1) / sizeof
> (IA32_IDT_GATE_DESCRIPTOR);
>
> +  ExceptionHandlerData->IdtEntryCount = MIN (IdtEntryCount,
> ExceptionHandlerData->IdtEntryCount);
>
>
>
>    IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
>
>    AsmGetTemplateAddressMap (&TemplateMap);
>
>    ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);
>
>
>
> -  ExceptionHandlerData->IdtEntryCount = IdtEntryCount;
>
>    UpdateIdtTable (IdtTable, &TemplateMap, ExceptionHandlerData);
>
>
>
>    return EFI_SUCCESS;
>
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
> index 6e5216380d..e894ead612 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>    CPU exception handler library implemenation for SEC/PEIM modules.
>
>
>
> -Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
>
> +Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>
>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -166,31 +166,6 @@ InitializeCpuExceptionHandlers (
>    return EFI_SUCCESS;
>
>  }
>
>
>
> -/**
>
> -  Initializes all CPU interrupt/exceptions entries and provides the default
> interrupt/exception handlers.
>
> -
>
> -  Caller should try to get an array of interrupt and/or exception vectors that are
> in use and need to
>
> -  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
>
> -  If caller cannot get reserved vector list or it does not exists, set VectorInfo to
> NULL.
>
> -  If VectorInfo is not NULL, the exception vectors will be initialized per vector
> attribute accordingly.
>
> -
>
> -  @param[in]  VectorInfo    Pointer to reserved vector list.
>
> -
>
> -  @retval EFI_SUCCESS           All CPU interrupt/exception entries have been
> successfully initialized
>
> -                                with default interrupt/exception handlers.
>
> -  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
> VectorInfo is not NULL.
>
> -  @retval EFI_UNSUPPORTED       This function is not supported.
>
> -
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -InitializeCpuInterruptHandlers (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
>
> -  )
>
> -{
>
> -  return EFI_UNSUPPORTED;
>
> -}
>
> -
>
>  /**
>
>    Registers a function to be called from the processor interrupt handler.
>
>
>
> @@ -198,8 +173,8 @@ InitializeCpuInterruptHandlers (
>    interrupt or exception type specified by InterruptType. If InterruptHandler is
> NULL, then the
>
>    handler for the processor interrupt or exception type specified by
> InterruptType is uninstalled.
>
>    The installed handler is called once for each processor interrupt or exception.
>
> -  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> or
>
> -  InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
> returned.
>
> +  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> is invoked,
>
> +  otherwise EFI_UNSUPPORTED returned.
>
>
>
>    @param[in]  InterruptType     Defines which interrupt or exception to hook.
>
>    @param[in]  InterruptHandler  A pointer to a function of type
> EFI_CPU_INTERRUPT_HANDLER that is called
>
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
> index 9f0af4120a..ec643556c7 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>    CPU exception handler library implementation for SMM modules.
>
>
>
> -  Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>
>
> +  Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -14,8 +14,8 @@ CONST UINTN  mDoFarReturnFlag = 1;
>  RESERVED_VECTORS_DATA      mReservedVectorsData[CPU_EXCEPTION_NUM];
>
>  EFI_CPU_INTERRUPT_HANDLER
> mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
>
>  EXCEPTION_HANDLER_DATA     mExceptionHandlerData = {
>
> -  0,   // To be fixed
>
> -  0,   // To be fixed
>
> +  CPU_EXCEPTION_NUM,
>
> +  0,                     // To be fixed
>
>    mReservedVectorsData,
>
>    mExternalInterruptHandlerTable
>
>  };
>
> @@ -62,31 +62,6 @@ InitializeCpuExceptionHandlers (
>    return InitializeCpuExceptionHandlersWorker (VectorInfo,
> &mExceptionHandlerData);
>
>  }
>
>
>
> -/**
>
> -  Initializes all CPU interrupt/exceptions entries and provides the default
> interrupt/exception handlers.
>
> -
>
> -  Caller should try to get an array of interrupt and/or exception vectors that are
> in use and need to
>
> -  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
>
> -  If caller cannot get reserved vector list or it does not exists, set VectorInfo to
> NULL.
>
> -  If VectorInfo is not NULL, the exception vectors will be initialized per vector
> attribute accordingly.
>
> -
>
> -  @param[in]  VectorInfo    Pointer to reserved vector list.
>
> -
>
> -  @retval EFI_SUCCESS           All CPU interrupt/exception entries have been
> successfully initialized
>
> -                                with default interrupt/exception handlers.
>
> -  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if
> VectorInfo is not NULL.
>
> -  @retval EFI_UNSUPPORTED       This function is not supported.
>
> -
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -InitializeCpuInterruptHandlers (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
>
> -  )
>
> -{
>
> -  return EFI_UNSUPPORTED;
>
> -}
>
> -
>
>  /**
>
>    Registers a function to be called from the processor interrupt handler.
>
>
>
> @@ -94,8 +69,8 @@ InitializeCpuInterruptHandlers (
>    interrupt or exception type specified by InterruptType. If InterruptHandler is
> NULL, then the
>
>    handler for the processor interrupt or exception type specified by
> InterruptType is uninstalled.
>
>    The installed handler is called once for each processor interrupt or exception.
>
> -  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> or
>
> -  InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED
> returned.
>
> +  NOTE: This function should be invoked after InitializeCpuExceptionHandlers()
> is invoked,
>
> +  otherwise EFI_UNSUPPORTED returned.
>
>
>
>    @param[in]  InterruptType     Defines which interrupt or exception to hook.
>
>    @param[in]  InterruptHandler  A pointer to a function of type
> EFI_CPU_INTERRUPT_HANDLER that is called
>
> --
> 2.35.1.windows.2
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#89919): https://edk2.groups.io/g/devel/message/89919
> Mute This Topic: https://groups.io/mt/91231770/1768734
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [jian.j.wang@...]
> -=-=-=-=-=-=
>


Re: [PATCH 3/5] CpuException: Avoid allocating page but using global variables

Dong, Eric
 

Acked-by: Eric Dong <eric.dong@...>

-----Original Message-----
From: Ni, Ray <ray.ni@...>
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: [PATCH 3/5] CpuException: Avoid allocating page but using global variables

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
---
.../CpuExceptionHandlerLib/DxeException.c | 24 ++++---------------
1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index da5b96d6c6..f139131a7c 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -14,8 +14,8 @@


CONST UINTN mDoFarReturnFlag = 0;



-RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];

-EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];

+RESERVED_VECTORS_DATA mReservedVectorsData[CPU_INTERRUPT_NUM];

+EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_INTERRUPT_NUM];

EXCEPTION_HANDLER_DATA mExceptionHandlerData = {

0, // To be fixed

0, // To be fixed

@@ -96,27 +96,15 @@ InitializeCpuInterruptHandlers (
IA32_DESCRIPTOR IdtDescriptor;

UINTN IdtEntryCount;

EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;

- RESERVED_VECTORS_DATA *ReservedVectors;

- EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;

-

- Status = gBS->AllocatePool (

- EfiBootServicesCode,

- sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM,

- (VOID **)&ReservedVectors

- );

- ASSERT (!EFI_ERROR (Status) && ReservedVectors != NULL);

- SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);

+

+ SetMem ((VOID *)mReservedVectorsData, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);

if (VectorInfo != NULL) {

- Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, CPU_INTERRUPT_NUM);

+ Status = ReadAndVerifyVectorInfo (VectorInfo, mReservedVectorsData, CPU_INTERRUPT_NUM);

if (EFI_ERROR (Status)) {

- FreePool (ReservedVectors);

return EFI_INVALID_PARAMETER;

}

}



- ExternalInterruptHandler = AllocateZeroPool (sizeof (EFI_CPU_INTERRUPT_HANDLER) * CPU_INTERRUPT_NUM);

- ASSERT (ExternalInterruptHandler != NULL);

-

//

// Read IDT descriptor and calculate IDT size

//

@@ -137,8 +125,6 @@ InitializeCpuInterruptHandlers (
ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);



mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM;

- mExceptionHandlerData.ReservedVectors = ReservedVectors;

- mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;

InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);



UpdateIdtTable (IdtTable, &TemplateMap, &mExceptionHandlerData);

--
2.35.1.windows.2


Re: [PATCH 2/5] CpuException: Init global variables in-place

Dong, Eric
 

Acked-by: Eric Dong <eric.dong@...>

-----Original Message-----
From: Ni, Ray <ray.ni@...>
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: [PATCH 2/5] CpuException: Init global variables in-place

Additionally removed two useless global variables:
"SPIN_LOCK mDisplayMessageSpinLock" from SMM instance.
"UINTN mEnabledInterruptNum" from DXE instance.

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
---
.../Library/CpuExceptionHandlerLib/DxeException.c | 11 ++++++----- .../Library/CpuExceptionHandlerLib/SmmException.c | 14 ++++++--------
2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index 5083c4b8e8..da5b96d6c6 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -16,9 +16,12 @@ CONST UINTN mDoFarReturnFlag = 0;
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM]; EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];-UINTN mEnabledInterruptNum = 0;--EXCEPTION_HANDLER_DATA mExceptionHandlerData;+EXCEPTION_HANDLER_DATA mExceptionHandlerData = {+ 0, // To be fixed+ 0, // To be fixed+ mReservedVectorsData,+ mExternalInterruptHandlerTable+}; UINT8 mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER * CPU_KNOWN_GOOD_STACK_SIZE];@@ -62,8 +65,6 @@ InitializeCpuExceptionHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL ) {- mExceptionHandlerData.ReservedVectors = mReservedVectorsData;- mExceptionHandlerData.ExternalInterruptHandler = mExternalInterruptHandlerTable; InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock); return InitializeCpuExceptionHandlersWorker (VectorInfo, &mExceptionHandlerData); }diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
index 77ee74579f..9f0af4120a 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
@@ -11,14 +11,14 @@
CONST UINTN mDoFarReturnFlag = 1; -//-// Spin lock for CPU information display-//-SPIN_LOCK mDisplayMessageSpinLock;- RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM]; EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];-EXCEPTION_HANDLER_DATA mExceptionHandlerData;+EXCEPTION_HANDLER_DATA mExceptionHandlerData = {+ 0, // To be fixed+ 0, // To be fixed+ mReservedVectorsData,+ mExternalInterruptHandlerTable+}; /** Common exception handler.@@ -58,8 +58,6 @@ InitializeCpuExceptionHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL ) {- mExceptionHandlerData.ReservedVectors = mReservedVectorsData;- mExceptionHandlerData.ExternalInterruptHandler = mExternalInterruptHandlerTable; InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock); return InitializeCpuExceptionHandlersWorker (VectorInfo, &mExceptionHandlerData); }--
2.35.1.windows.2


Re: [PATCH 1/5] CpuException: Avoid allocating code pages for DXE instance

Dong, Eric
 

Acked-by: Eric Dong <eric.dong@...>

 

From: Ni, Ray <ray.ni@...>
Sent: Tuesday, May 24, 2022 4:02 PM
To: Wang, Jian J <jian.j.wang@...>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>
Subject: Re: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages for DXE instance

 

Jian,
Ia32/ExceptionHandlerAsm.nasm is used by 32bit DxeCpuExceptionHandlerLib instance.

I agree the commit message is not correct. The commit message says
SEC still creates 32 entries but 32bit SEC creates 256 entries.

I will update the commit message to align to code behavior.

Thanks,
Ray

________________________________________
From: Wang, Jian J <jian.j.wang@...>
Sent: Monday, May 23, 2022 0:40
To: devel@edk2.groups.io; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages for DXE instance

Ray,

You changed "%rep 32" to "%rep 256" in Ia32/ExceptionHandlerAsm.nasm.
According to my understanding and your comments, this should be done
only to X64 code, right?

Regards,
Jian

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray
> Sent: Friday, May 20, 2022 10:16 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@...>
> Subject: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages
> for DXE instance
>
> Today the DXE instance allocates code page and then copies the IDT
> vectors to the allocated code page. Then it fixes up the vector number
> in the IDT vector.
>
> But if we update the NASM file to generate 256 IDT vectors, there is
> no need to do the copy and fix-up.
>
> A side effect is up to 4096 bytes (HOOKAFTER_STUB_SIZE * 256) is
> used for 256 IDT vectors. While 32 IDT vectors only require 512 bytes.
>
> But considering the code logic simplification, 3.5K space is not a big
> deal. SEC instance still generates 32 IDT vectors so no impact to SEC.
> If 3.5K is too much a waste in PEI phase, we can enhance the code
> further to generate 32 vectors for PEI.
>
> Signed-off-by: Ray Ni <ray.ni@...>
> Cc: Eric Dong <eric.dong@...>
> ---
>  .../CpuExceptionHandlerLib/DxeException.c     | 22 -------------------
>  .../Ia32/ExceptionHandlerAsm.nasm             |  4 ++--
>  .../X64/ExceptionHandlerAsm.nasm              |  2 ++
>  .../X64/Xcode5ExceptionHandlerAsm.nasm        |  9 ++++----
>  4 files changed, 9 insertions(+), 28 deletions(-)
>
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> index 61f11e98f8..5083c4b8e8 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> @@ -95,9 +95,6 @@ InitializeCpuInterruptHandlers (
>    IA32_DESCRIPTOR                 IdtDescriptor;
>
>    UINTN                           IdtEntryCount;
>
>    EXCEPTION_HANDLER_TEMPLATE_MAP  TemplateMap;
>
> -  UINTN                           Index;
>
> -  UINTN                           InterruptEntry;
>
> -  UINT8                           *InterruptEntryCode;
>
>    RESERVED_VECTORS_DATA           *ReservedVectors;
>
>    EFI_CPU_INTERRUPT_HANDLER       *ExternalInterruptHandler;
>
>
>
> @@ -138,25 +135,6 @@ InitializeCpuInterruptHandlers (
>    AsmGetTemplateAddressMap (&TemplateMap);
>
>    ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);
>
>
>
> -  Status = gBS->AllocatePool (
>
> -                  EfiBootServicesCode,
>
> -                  TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM,
>
> -                  (VOID **)&InterruptEntryCode
>
> -                  );
>
> -  ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);
>
> -
>
> -  InterruptEntry = (UINTN)InterruptEntryCode;
>
> -  for (Index = 0; Index < CPU_INTERRUPT_NUM; Index++) {
>
> -    CopyMem (
>
> -      (VOID *)InterruptEntry,
>
> -      (VOID *)TemplateMap.ExceptionStart,
>
> -      TemplateMap.ExceptionStubHeaderSize
>
> -      );
>
> -    AsmVectorNumFixup ((VOID *)InterruptEntry, (UINT8)Index, (VOID
> *)TemplateMap.ExceptionStart);
>
> -    InterruptEntry += TemplateMap.ExceptionStubHeaderSize;
>
> -  }
>
> -
>
> -  TemplateMap.ExceptionStart                     = (UINTN)InterruptEntryCode;
>
>    mExceptionHandlerData.IdtEntryCount            = CPU_INTERRUPT_NUM;
>
>    mExceptionHandlerData.ReservedVectors          = ReservedVectors;
>
>    mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;
>
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
> m
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
> m
> index 3fe9aed1e8..8ed2b8f455 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
> m
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nas
> m
> @@ -33,7 +33,7 @@ ALIGN   8
>  ;
>
>  AsmIdtVectorBegin:
>
>  %assign Vector 0
>
> -%rep  32
>
> +%rep  256
>
>      push    byte %[Vector];
>
>      push    eax
>
>      mov     eax, ASM_PFX(CommonInterruptEntry)
>
> @@ -439,7 +439,7 @@ ASM_PFX(AsmGetTemplateAddressMap):
>
>
>      mov ebx, dword [ebp + 0x8]
>
>      mov dword [ebx],      AsmIdtVectorBegin
>
> -    mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32
>
> +    mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256
>
>      mov dword [ebx + 0x8], HookAfterStubBegin
>
>
>
>      popad
>
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
> index 9a806d1f86..aaf8d622e6 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
> @@ -31,6 +31,8 @@ SECTION .text
>
>
>  ALIGN   8
>
>
>
> +; Generate 32 IDT vectors.
>
> +; 32 IDT vectors are enough because interrupts (32+) are not enabled in SEC and
> PEI phase.
>
>  AsmIdtVectorBegin:
>
>  %assign Vector 0
>
>  %rep  32
>
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
> m.nasm
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
> m.nasm
> index 9c72fa5815..7c0e3d3b0b 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
> m.nasm
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAs
> m.nasm
> @@ -53,9 +53,10 @@ SECTION .text
>
>
>  ALIGN   8
>
>
>
> +; Generate 256 IDT vectors.
>
>  AsmIdtVectorBegin:
>
>  %assign Vector 0
>
> -%rep  32
>
> +%rep  256
>
>      push    byte %[Vector]
>
>      push    rax
>
>      mov     rax, strict qword 0 ;    mov     rax, ASM_PFX(CommonInterruptEntry)
>
> @@ -453,16 +454,16 @@ global ASM_PFX(AsmGetTemplateAddressMap)
>  ASM_PFX(AsmGetTemplateAddressMap):
>
>      lea     rax, [AsmIdtVectorBegin]
>
>      mov     qword [rcx], rax
>
> -    mov     qword [rcx + 0x8],  (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32
>
> +    mov     qword [rcx + 0x8],  (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256
>
>      lea     rax, [HookAfterStubHeaderBegin]
>
>      mov     qword [rcx + 0x10], rax
>
>
>
>  ; Fix up CommonInterruptEntry address
>
>      lea    rax, [ASM_PFX(CommonInterruptEntry)]
>
>      lea    rcx, [AsmIdtVectorBegin]
>
> -%rep  32
>
> +%rep  256
>
>      mov    qword [rcx + (JmpAbsoluteAddress - 8 - HookAfterStubHeaderBegin)],
> rax
>
> -    add    rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32
>
> +    add    rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256
>
>  %endrep
>
>  ; Fix up HookAfterStubHeaderEnd
>
>      lea    rax, [HookAfterStubHeaderEnd]
>
> --
> 2.35.1.windows.2
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#89916): https://edk2.groups.io/g/devel/message/89916
> Mute This Topic: https://groups.io/mt/91231767/1768734
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [jian.j.wang@...]
> -=-=-=-=-=-=
>


Re: [PATCH 04/14] MdePkg: Add UEFI Unaccepted memory definition

Yao, Jiewen
 

Reviewed-by: Jiewen Yao <Jiewen.yao@...>

-----Original Message-----
From: Xu, Min M <min.m.xu@...>
Sent: Monday, June 6, 2022 11:00 AM
To: devel@edk2.groups.io
Cc: Xu, Min M <min.m.xu@...>; Kinney, Michael D
<michael.d.kinney@...>; Gao, Liming <gaoliming@...>; Liu,
Zhiguang <zhiguang.liu@...>; Aktas, Erdem <erdemaktas@...>;
Gerd Hoffmann <kraxel@...>; James Bottomley <jejb@...>;
Yao, Jiewen <jiewen.yao@...>; Tom Lendacky
<thomas.lendacky@...>
Subject: [PATCH 04/14] MdePkg: Add UEFI Unaccepted memory definition

From: Min M Xu <min.m.xu@...>

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

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

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdePkg/Include/Pi/PiDxeCis.h | 5 +++++
MdePkg/Include/Uefi/UefiMultiPhase.h | 5 +++++
2 files changed, 10 insertions(+)

diff --git a/MdePkg/Include/Pi/PiDxeCis.h b/MdePkg/Include/Pi/PiDxeCis.h
index d0f2ed0e58df..67c99801b00d 100644
--- a/MdePkg/Include/Pi/PiDxeCis.h
+++ b/MdePkg/Include/Pi/PiDxeCis.h
@@ -56,6 +56,11 @@ typedef enum {
/// system. If all memory has the same reliability, then this bit is not used.
///
EfiGcdMemoryTypeMoreReliable,
+ ///
+ /// A memory region that describes system memory that has not been
accepted
+ /// by a corresponding call to the underlying isolation architecture.
+ ///
+ EfiGcdMemoryTypeUnaccepted,
EfiGcdMemoryTypeMaximum
} EFI_GCD_MEMORY_TYPE;

diff --git a/MdePkg/Include/Uefi/UefiMultiPhase.h
b/MdePkg/Include/Uefi/UefiMultiPhase.h
index 22bae43e36e8..29aabab5948e 100644
--- a/MdePkg/Include/Uefi/UefiMultiPhase.h
+++ b/MdePkg/Include/Uefi/UefiMultiPhase.h
@@ -103,6 +103,11 @@ typedef enum {
/// however it happens to also support byte-addressable non-volatility.
///
EfiPersistentMemory,
+ ///
+ /// A memory region that describes system memory that has not been
accepted
+ /// by a corresponding call to the underlying isolation architecture.
+ ///
+ EfiUnacceptedMemory,
EfiMaxMemoryType
} EFI_MEMORY_TYPE;

--
2.29.2.windows.2

6481 - 6500 of 96644