Date   

回复: [edk2-devel] [PATCH v2 4/4] MdePkg: Signal AfterReadyToBoot after ReadyToBoot

gaoliming
 

Dionna:
I add my comments below.

-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Dionna Glaze
via groups.io
发送时间: 2022年11月9日 5:16
收件人: devel@edk2.groups.io
抄送: Dionna Glaze <dionnaglaze@...>; Michael D Kinney
<michael.d.kinney@...>; Ard Biesheuvel <ardb@...>; Gerd
Hoffman <kraxel@...>; Jiewen Yao <jiewen.yao@...>
主题: [edk2-devel] [PATCH v2 4/4] MdePkg: Signal AfterReadyToBoot after
ReadyToBoot

The Uefi v2.9 specification adds this event group in section 3.1.7,
with its GUID defined in the Related Definitions section of
EFI_BOOT_SERVICES.CreateEventEx() in chapter 7.

Cc: "Michael D Kinney" <michael.d.kinney@...>
Cc: Ard Biesheuvel <ardb@...>
Cc: Gerd Hoffman <kraxel@...>
Cc: Jiewen Yao <jiewen.yao@...>

Signed-off-by: Dionna Glaze <dionnaglaze@...>
---
MdePkg/Include/Library/UefiLib.h | 2 ++
MdePkg/Library/UefiLib/UefiLib.inf | 1 +
MdePkg/Library/UefiLib/UefiNotTiano.c | 18 ++++++++++++++++++
3 files changed, 21 insertions(+)

diff --git a/MdePkg/Include/Library/UefiLib.h
b/MdePkg/Include/Library/UefiLib.h
index be7da7fdf7..2c3342351e 100644
--- a/MdePkg/Include/Library/UefiLib.h
+++ b/MdePkg/Include/Library/UefiLib.h
@@ -890,6 +890,8 @@ UnicodeStringDisplayLength (
/**
Create, Signal, and Close the Ready to Boot event using
EfiSignalEventReadyToBoot().

+ If successful, then create, signal and close the After Ready to Boot event.
+
This function abstracts the signaling of the Ready to Boot Event. The
Framework moved
from a proprietary to UEFI 2.0 based mechanism. This library abstracts
the caller
from how this event is created to prevent to code form having to change
with the
diff --git a/MdePkg/Library/UefiLib/UefiLib.inf
b/MdePkg/Library/UefiLib/UefiLib.inf
index 01ed92092d..5c4064eafa 100644
--- a/MdePkg/Library/UefiLib/UefiLib.inf
+++ b/MdePkg/Library/UefiLib/UefiLib.inf
@@ -60,6 +60,7 @@
gEfiGlobalVariableGuid ##
SOMETIMES_CONSUMES ## Variable
gEfiAcpi20TableGuid ##
SOMETIMES_CONSUMES ## SystemTable
gEfiAcpi10TableGuid ##
SOMETIMES_CONSUMES ## SystemTable
+ gEfiEventAfterReadyToBootGuid ##
SOMETIMES_CONSUMES ## Event

[Protocols]
gEfiDriverBindingProtocolGuid ##
SOMETIMES_PRODUCES
diff --git a/MdePkg/Library/UefiLib/UefiNotTiano.c
b/MdePkg/Library/UefiLib/UefiNotTiano.c
index d84e91fd01..04fe42f9f7 100644
--- a/MdePkg/Library/UefiLib/UefiNotTiano.c
+++ b/MdePkg/Library/UefiLib/UefiNotTiano.c
@@ -208,6 +208,8 @@ EfiCreateEventReadyToBootEx (
/**
Create, Signal, and Close the Ready to Boot event using
EfiSignalEventReadyToBoot().

+ If successful, then create, signal and close the After Ready to Boot event.
+
This function abstracts the signaling of the Ready to Boot Event. The
Framework moved
from a proprietary to UEFI 2.0 based mechanism. This library abstracts
the caller
from how this event is created to prevent to code form having to change
with the
@@ -222,11 +224,27 @@ EfiSignalEventReadyToBoot (
{
EFI_STATUS Status;
EFI_EVENT ReadyToBootEvent;
+ EFI_EVENT AfterReadyToBootEvent;

Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
if (!EFI_ERROR (Status)) {
gBS->SignalEvent (ReadyToBootEvent);
gBS->CloseEvent (ReadyToBootEvent);
+ return;
+ }
+
Return should not be here. This means ReadyToBoot event creates successfully and return.
But, the behavior should be ReadyToBoot and AfterReadyToBoot event both trig.

Thanks
Liming
+ /* Then immediately signal the after ready to boot event group */
+ Status = gBS->CreateEventEx (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ EfiEventEmptyFunction,
+ NULL,
+ &gEfiEventAfterReadyToBootGuid,
+ AfterReadyToBootEvent
+ );
+ if (!EFI_ERROR(Status)) {
+ gBS->SignalEvent (AfterReadyToBootEvent);
+ gBS->CloseEvent (AfterReadyToBootEvent);
}
}

--
2.38.1.431.g37b22c650d-goog





Re: feature flag change notifications

dann frazier
 

Hi Liming,

Thank you, that is appreciated. Going forward I'll let you know if I
trip over any not already documented.

-dann

On Tue, Dec 6, 2022 at 5:59 PM gaoliming via groups.io
<gaoliming@...> wrote:

Dann:
I base on new features to collect the incompatible changes, and add them into the updated notes.

If you find any missing, please send the mail to me.

Thanks
Liming
-----邮件原件-----
发件人: Kinney, Michael D <michael.d.kinney@...>
发送时间: 2022年12月6日 9:22
收件人: devel@edk2.groups.io; dann.frazier@...; Gao, Liming
<gaoliming@...>
主题: RE: [edk2-devel] feature flag change notifications

Hi Dann,

These are reasonable requests.

Adding Liming Gao who is currently responsible for the edk2 releases.

Let's start with release notes and see if some of these can be added
to the release documentation and add to the edk2 release process
to clearly note these type of changes in future release notes.

As far as #error and #warn. Those are possible, but we would need
to do some analysis for the types of changes that would require
that behavior. Your examples are useful as a starting point.

Once concern is how many of those #error/#warn conditions will
build up over time and then a process to remove them after an
expiration period.

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of dann
frazier
Sent: Monday, December 5, 2022 4:10 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] feature flag change notifications

Hi,
I maintain the edk2 packages in the Debian and Ubuntu
distributions. A few times over the years I've had users report
regressions that turned out to be due to upstream build flag
changes. I wonder if it would be possible for upstream to communicate
such changes - either via release notes or, where possible, as
build-time checks - to us downstream projects. Here are the examples I
recall:

commit 4de8d61bcec02a13ceed84f92b0cf3ea58adf9c5
Author: Gerd Hoffmann <kraxel@...>
Date: Wed Dec 15 12:39:20 2021 +0100

OvmfPkg: rework TPM configuration
For this I needed to change -DTPM_ENABLE=TRUE to
-DTPM2_ENABLE=TRUE. I
feel like a build-time check would've been a good way to communicate
this one, e.g.:

#ifdef TPM_ENABLE
#error TPM_ENABLE has been renamed to TPM2_ENABLE
#endif

commit 1631bb26ae991e530d3c96fe3161ea15144b358e
Author: Gary Lin <glin@...>
Date: Mon Jun 10 14:55:09 2019 +0800

OvmfPkg/README: Update the network build flags

The following network build flags changed due to the inclusion of
NetworkPkg/Network.fdf.inc.
Similar to the above, I needed to deal with this by setting
-DNETWORK_HTTP_BOOT_ENABLE=TRUE instead of
-DHTTP_BOOT_ENABLE=TRUE. It
seems like maybe an #error on the removed #define could've helped
here as well.

And finally:

commit 57783adfb579da32b1eeda77b2bec028a5e0b7b3
Author: Michael D Kinney <michael.d.kinney@...>
Date: Tue Jul 26 12:40:00 2022 -0700

OvmfPkg: Change default to disable MptScsi and PvScsi
With this types of change, it would be useful just to know this is
coming and why so I can decide to either notify users of the change
and/or override the default to avoid the regression. Would it be
possible to describe such changes in the release notes at
https://github.com/tianocore/edk2/releases - and, if not urgent,
perhaps #warn of deprecation in the source for one stable release
cycle?

-dann










Re: feature flag change notifications

dann frazier
 

Hi Mike,

Thanks for the consideration. I think the release notes are a
sufficient starting point.

-dann

On Mon, Dec 5, 2022 at 6:22 PM Kinney, Michael D
<michael.d.kinney@...> wrote:

Hi Dann,

These are reasonable requests.

Adding Liming Gao who is currently responsible for the edk2 releases.

Let's start with release notes and see if some of these can be added
to the release documentation and add to the edk2 release process
to clearly note these type of changes in future release notes.

As far as #error and #warn. Those are possible, but we would need
to do some analysis for the types of changes that would require
that behavior. Your examples are useful as a starting point.

Once concern is how many of those #error/#warn conditions will
build up over time and then a process to remove them after an
expiration period.

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of dann frazier
Sent: Monday, December 5, 2022 4:10 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] feature flag change notifications

Hi,
I maintain the edk2 packages in the Debian and Ubuntu
distributions. A few times over the years I've had users report
regressions that turned out to be due to upstream build flag
changes. I wonder if it would be possible for upstream to communicate
such changes - either via release notes or, where possible, as
build-time checks - to us downstream projects. Here are the examples I
recall:

commit 4de8d61bcec02a13ceed84f92b0cf3ea58adf9c5
Author: Gerd Hoffmann <kraxel@...>
Date: Wed Dec 15 12:39:20 2021 +0100

OvmfPkg: rework TPM configuration
For this I needed to change -DTPM_ENABLE=TRUE to -DTPM2_ENABLE=TRUE. I
feel like a build-time check would've been a good way to communicate
this one, e.g.:

#ifdef TPM_ENABLE
#error TPM_ENABLE has been renamed to TPM2_ENABLE
#endif

commit 1631bb26ae991e530d3c96fe3161ea15144b358e
Author: Gary Lin <glin@...>
Date: Mon Jun 10 14:55:09 2019 +0800

OvmfPkg/README: Update the network build flags

The following network build flags changed due to the inclusion of
NetworkPkg/Network.fdf.inc.
Similar to the above, I needed to deal with this by setting
-DNETWORK_HTTP_BOOT_ENABLE=TRUE instead of -DHTTP_BOOT_ENABLE=TRUE. It
seems like maybe an #error on the removed #define could've helped
here as well.

And finally:

commit 57783adfb579da32b1eeda77b2bec028a5e0b7b3
Author: Michael D Kinney <michael.d.kinney@...>
Date: Tue Jul 26 12:40:00 2022 -0700

OvmfPkg: Change default to disable MptScsi and PvScsi
With this types of change, it would be useful just to know this is
coming and why so I can decide to either notify users of the change
and/or override the default to avoid the regression. Would it be
possible to describe such changes in the release notes at
https://github.com/tianocore/edk2/releases - and, if not urgent,
perhaps #warn of deprecation in the source for one stable release
cycle?

-dann




Re: [PATCH] MdePkg/UnitTestHostBaseLib: Remove HOST_APPLICATION limitation

Zhiguang Liu
 

Hi Liming,
Sure, I will update the patch

Thanks
Zhiguang

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
gaoliming via groups.io
Sent: Wednesday, December 7, 2022 9:02 AM
To: devel@edk2.groups.io; Liu, Zhiguang <zhiguang.liu@...>; Ni, Ray
<ray.ni@...>
Cc: Kinney, Michael D <michael.d.kinney@...>
Subject: 回复: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib: Remove
HOST_APPLICATION limitation

Zhiguang and Ray:
Thanks for your sharing. It is OK to use UnitTestHostBaseLib in emulator
platform.
Please also update the file header in module inf to describe this usage.

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Zhiguang Liu
发送时间: 2022年12月5日 13:53
收件人: Ni, Ray <ray.ni@...>; devel@edk2.groups.io; Gao, Liming
<gaoliming@...>
抄送: Kinney, Michael D <michael.d.kinney@...>
主题: Re: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib: Remove
HOST_APPLICATION limitation

Hi Liming,
Like ray said, we are trying to use some baselib function in
EmulatorPkg, which is assembly code in normal BaseLib, and is mocked
in UnitTestBaseLib, such as AsmWriteMsr64 and AsmCpuid.

Thanks
Zhiguang

-----Original Message-----
From: Ni, Ray <ray.ni@...>
Sent: Monday, December 5, 2022 1:38 PM
To: devel@edk2.groups.io; Gao, Liming <gaoliming@...>;
Liu, Zhiguang <zhiguang.liu@...>
Cc: Kinney, Michael D <michael.d.kinney@...>
Subject: RE: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib:
Remove
HOST_APPLICATION limitation

Liming,
We are running some code that requires MSR access (e.g.: MtrrLib) in
EmulatorPkg.

Thanks,
Ray

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
gaoliming via groups.io
Sent: Friday, December 2, 2022 5:48 PM
To: devel@edk2.groups.io; Liu, Zhiguang <zhiguang.liu@...>
Cc: Kinney, Michael D <michael.d.kinney@...>; Ni, Ray
<ray.ni@...>
Subject: 回复: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib:
Remove
HOST_APPLICATION limitation

Zhiguang:
Can you explain more about the emulator usage model for this library?

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表
Zhiguang
Liu
发送时间: 2022年12月2日 14:25
收件人: devel@edk2.groups.io
抄送: Zhiguang Liu <zhiguang.liu@...>; Michael D Kinney
<michael.d.kinney@...>; Liming Gao
<gaoliming@...>;
Ray Ni <ray.ni@...>
主题: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib: Remove
HOST_APPLICATION limitation

Remove HOST_APPLICATION limitation for UnitTestHostBaseLib, so
that this library can be used as BaseLib by Emulator.
Also, add some missing files

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Ray Ni <ray.ni@...>
---
MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
index 09a610c31c..fefa2e79f6 100644
--- a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+++ b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
@@ -1,7 +1,7 @@
## @file
# Base Library implementation for use with host based unit tests.
#
-# Copyright (c) 2007 - 2021, Intel Corporation. All rights
reserved.<BR>
+# Copyright (c) 2007 - 2022, Intel Corporation. All rights
+reserved.<BR>
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights
reserved.<BR>
# Portions copyright (c) 2011 - 2013, ARM Ltd. All rights
reserved.<BR> # Copyright (c) 2020, Hewlett Packard Enterprise
Development LP. All rights reserved.<BR> @@ -18,7 +18,7 @@
FILE_GUID =
9555A0D3-09BA-46C4-A51A-45198E3C765E
MODULE_TYPE = BASE
VERSION_STRING = 1.1
- LIBRARY_CLASS =
BaseLib|HOST_APPLICATION
+ LIBRARY_CLASS = BaseLib
LIBRARY_CLASS =
UnitTestHostBaseLib|HOST_APPLICATION

#
@@ -128,6 +128,7 @@
X86RdRand.c
X86SpeculationBarrier.c
X86UnitTestHost.c
+ IntelTdxNull.c

[Sources.X64]
X64/LongJump.nasm
@@ -168,6 +169,7 @@
X64/RdRand.nasm
ChkStkGcc.c | GCC
X86UnitTestHost.c
+ IntelTdxNull.c

[Sources.EBC]
Ebc/CpuBreakpoint.c
--
2.31.1.windows.1


















回复: [edk2][PATCH 0/2] Add Events introduced in UEFI 2.9

gaoliming
 

Robert:
EFI_EVENT_GROUP_AFTER_READY_TO_BOOT should be trig in Edk2\MdeModulePkg\Library\UefiBootManagerLib like ReadyToBoot event.

Thanks
Liming

-----邮件原件-----
发件人: Kinney, Michael D <michael.d.kinney@...>
发送时间: 2022年11月9日 6:45
收件人: devel@edk2.groups.io; robert@...; Kinney, Michael D
<michael.d.kinney@...>
抄送: Gao, Liming <gaoliming@...>; Liu, Zhiguang
<zhiguang.liu@...>; Bi, Dandan <dandan.bi@...>
主题: RE: [edk2][PATCH 0/2] Add Events introduced in UEFI 2.9

Hi Robert,

I do not see the signal of the after exit boot services event.

Thanks,

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Robert
Phelps via groups.io
Sent: Tuesday, November 8, 2022 12:28 PM
To: devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@...>; Gao, Liming
<gaoliming@...>; Liu, Zhiguang
<zhiguang.liu@...>; Bi, Dandan <dandan.bi@...>
Subject: [edk2-devel] [edk2][PATCH 0/2] Add Events introduced in UEFI 2.9

The following patches contain the new definitions for new events that
were added in UEFI 2.9: Before Exit Boot Services and After Ready to
Boot. The second patch adds the call to signal the Before Exit Boot
Services Event in DxeMain.c and the addition of the GUID in the INF
file DxeMain.inf.


Cc: Michael D Kinney <michael.d.kinney@...> [mdkinney]
Cc: Liming Gao <gaoliming@...> [lgao4]
Cc: Zhiguang Liu <zhiguang.liu@...> [LiuZhiguang001]
Cc: Dandan Bi <dandan.bi@...> [dandanbi]
Signed-off-by: Robert Phelps <robert@...>

Robert Phelps (2):
MdePkg: Add New Event Definitions from UEFI 2.9
MdeModulePkg: Added call to signal New Event

MdeModulePkg/Core/Dxe/DxeMain.inf | 1 +
MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 2 ++
MdePkg/Include/Guid/EventGroup.h | 10 ++++++++++
MdePkg/MdePkg.dec | 6 ++++++
4 files changed, 19 insertions(+)

--
2.36.1.windows.1
-The information contained in this message may be confidential and
proprietary to American Megatrends (AMI). This communication
is intended to be read only by the individual or entity to whom it is
addressed or by their designee. If the reader of this
message is not the intended recipient, you are on notice that any
distribution of this message, in any form, is strictly
prohibited. Please promptly notify the sender by reply e-mail or by
telephone at 770-246-8600, and then delete or destroy all
copies of the transmission.




Re: [PATCH v2 1/1] MdeModulePkg: Put USB DEBUGs that occur for bulk timeouts under VERBOSE

Wu, Hao A
 

Reviewed-by: Hao A Wu <hao.a.wu@...>
Will wait a couple of days before merging to see if comments from other reviewers.

Best Regards,
Hao Wu

-----Original Message-----
From: Rebecca Cran <rebecca@...>
Sent: Tuesday, December 6, 2022 10:31 PM
To: devel@edk2.groups.io; Gao, Liming <gaoliming@...>; Ni,
Ray <ray.ni@...>; Wang, Jian J <jian.j.wang@...>; Wu, Hao A
<hao.a.wu@...>
Cc: Rebecca Cran <rebecca@...>
Subject: [PATCH v2 1/1] MdeModulePkg: Put USB DEBUGs that occur for bulk
timeouts under VERBOSE

With the pending commit of UsbNetworkPkg, it will become common for
UsbBulkTransfer calls to timeout, given that the drivers are called from
MnpSystemPoll every MNP_SYS_POLL_INTERVAL milliseconds: the drivers
check for network packets by calling UsbBulkTransfer with a timeout of
1ms.

Avoid console spam by moving DEBUG messages that occur each time a bulk
transfer request times out from DEBUG_ERROR to DEBUG_VERBOSE, for
both
EHCI and XHCI drivers.

Signed-off-by: Rebecca Cran <rebecca@...>
---
MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 9 ++++++++-
MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 2 +-
MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 9 ++++++++-
MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 6 +++---
4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
index 0b7270f4e930..e903593b0198 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
@@ -848,6 +848,7 @@ EhcBulkTransfer (
URB *Urb;
EFI_TPL OldTpl;
EFI_STATUS Status;
+ UINTN DebugErrorLevel;

//
// Validate the parameters
@@ -932,7 +933,13 @@ EhcBulkTransfer (
gBS->RestoreTPL (OldTpl);

if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "EhcBulkTransfer: error - %r, transfer - %x\n",
Status, *TransferResult));
+ if (Status == EFI_TIMEOUT) {
+ DebugErrorLevel = DEBUG_VERBOSE;
+ } else {
+ DebugErrorLevel = DEBUG_ERROR;
+ }
+
+ DEBUG ((DebugErrorLevel, "EhcBulkTransfer: error - %r, transfer - %x\n",
Status, *TransferResult));
}

return Status;
diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
index 5da26afbe120..6967aabceb78 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
@@ -702,7 +702,7 @@ EhcExecTransfer (
}

if (!Finished) {
- DEBUG ((DEBUG_ERROR, "EhcExecTransfer: transfer not finished
in %dms\n", (UINT32)TimeOut));
+ DEBUG ((DEBUG_VERBOSE, "EhcExecTransfer: transfer not finished
in %dms\n", (UINT32)TimeOut));
EhcDumpQh (Urb->Qh, NULL, FALSE);

Status = EFI_TIMEOUT;
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index c05431ff30ec..15fb49f28fa0 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -1242,6 +1242,7 @@ XhcBulkTransfer (
UINT8 SlotId;
EFI_STATUS Status;
EFI_TPL OldTpl;
+ UINTN DebugErrorLevel;

//
// Validate the parameters
@@ -1304,7 +1305,13 @@ XhcBulkTransfer (

ON_EXIT:
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "XhcBulkTransfer: error - %r, transfer - %x\n",
Status, *TransferResult));
+ if (Status == EFI_TIMEOUT) {
+ DebugErrorLevel = DEBUG_VERBOSE;
+ } else {
+ DebugErrorLevel = DEBUG_ERROR;
+ }
+
+ DEBUG ((DebugErrorLevel, "XhcBulkTransfer: error - %r, transfer - %x\n",
Status, *TransferResult));
}

gBS->RestoreTPL (OldTpl);
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index 13b0400e83d7..13247f7b0dfc 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -734,7 +734,7 @@ XhcDequeueTrbFromEndpoint (
Dci = XhcEndpointToDci (Urb->Ep.EpAddr, (UINT8)(Urb->Ep.Direction));
ASSERT (Dci < 32);

- DEBUG ((DEBUG_INFO, "Stop Slot = %x,Dci = %x\n", SlotId, Dci));
+ DEBUG ((DEBUG_VERBOSE, "Stop Slot = %x,Dci = %x\n", SlotId, Dci));

//
// 1) Send Stop endpoint command to stop xHC from executing of the TDs
on the endpoint
@@ -3376,7 +3376,7 @@ XhcStopEndpoint (
EVT_TRB_COMMAND_COMPLETION *EvtTrb;
CMD_TRB_STOP_ENDPOINT CmdTrbStopED;

- DEBUG ((DEBUG_INFO, "XhcStopEndpoint: Slot = 0x%x, Dci = 0x%x\n",
SlotId, Dci));
+ DEBUG ((DEBUG_VERBOSE, "XhcStopEndpoint: Slot = 0x%x, Dci = 0x%x\n",
SlotId, Dci));

//
// When XhcCheckUrbResult waits for the Stop_Endpoint completion, it
also checks
@@ -3497,7 +3497,7 @@ XhcSetTrDequeuePointer (
CMD_SET_TR_DEQ_POINTER CmdSetTRDeq;
EFI_PHYSICAL_ADDRESS PhyAddr;

- DEBUG ((DEBUG_INFO, "XhcSetTrDequeuePointer: Slot = 0x%x, Dci = 0x%x,
Urb = 0x%x\n", SlotId, Dci, Urb));
+ DEBUG ((DEBUG_VERBOSE, "XhcSetTrDequeuePointer: Slot = 0x%x, Dci =
0x%x, Urb = 0x%x\n", SlotId, Dci, Urb));

//
// Send stop endpoint command to transit Endpoint from running to stop
state
--
2.30.2


回复: [PATCH] MdePkg: Update new Form Browser Action Request

gaoliming
 

Robert:
Will you also update SetupBrowser to support this new action?

Thanks
Liming
-----邮件原件-----
发件人: Robert Phelps <Robert@...>
发送时间: 2022年11月9日 4:13
收件人: devel@edk2.groups.io
抄送: michael.d.kinney@...; gaoliming@...;
zhiguang.liu@...
主题: [PATCH] MdePkg: Update new Form Browser Action Request

The UEFI 2.9 specification added a new FORM_BROWSER_ACTION_REQUEST.
This
adds FORM_BROWSER_ACTION_REQUEST_QUESTION_APPLY.



Signed-off-by: Robert Phelps <robert@...>
---
MdePkg/Include/Protocol/FormBrowser2.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/MdePkg/Include/Protocol/FormBrowser2.h
b/MdePkg/Include/Protocol/FormBrowser2.h
index 436a7723c1..7498dc2a07 100644
--- a/MdePkg/Include/Protocol/FormBrowser2.h
+++ b/MdePkg/Include/Protocol/FormBrowser2.h
@@ -55,6 +55,7 @@ typedef UINTN EFI_BROWSER_ACTION_REQUEST;
#define EFI_BROWSER_ACTION_REQUEST_FORM_APPLY 6

#define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD 7

#define EFI_BROWSER_ACTION_REQUEST_RECONNECT 8

+#define EFI_BROWSER_ACTION_REQUEST_QUESTION_APPLY 9



/**

Initialize the browser to display the specified configuration forms.

--
2.36.1.windows.1
-The information contained in this message may be confidential and
proprietary to American Megatrends (AMI). This communication is intended
to
be read only by the individual or entity to whom it is addressed or by
their
designee. If the reader of this message is not the intended recipient, you
are
on notice that any distribution of this message, in any form, is strictly
prohibited. Please promptly notify the sender by reply e-mail or by
telephone
at 770-246-8600, and then delete or destroy all copies of the
transmission=


回复: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib: Remove HOST_APPLICATION limitation

gaoliming
 

Zhiguang and Ray:
Thanks for your sharing. It is OK to use UnitTestHostBaseLib in emulator platform.
Please also update the file header in module inf to describe this usage.

Thanks
Liming

-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Zhiguang Liu
发送时间: 2022年12月5日 13:53
收件人: Ni, Ray <ray.ni@...>; devel@edk2.groups.io; Gao, Liming
<gaoliming@...>
抄送: Kinney, Michael D <michael.d.kinney@...>
主题: Re: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib: Remove
HOST_APPLICATION limitation

Hi Liming,
Like ray said, we are trying to use some baselib function in EmulatorPkg,
which is assembly code in normal BaseLib, and is mocked in UnitTestBaseLib,
such as AsmWriteMsr64 and AsmCpuid.

Thanks
Zhiguang

-----Original Message-----
From: Ni, Ray <ray.ni@...>
Sent: Monday, December 5, 2022 1:38 PM
To: devel@edk2.groups.io; Gao, Liming <gaoliming@...>; Liu,
Zhiguang <zhiguang.liu@...>
Cc: Kinney, Michael D <michael.d.kinney@...>
Subject: RE: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib: Remove
HOST_APPLICATION limitation

Liming,
We are running some code that requires MSR access (e.g.: MtrrLib) in
EmulatorPkg.

Thanks,
Ray

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
gaoliming via groups.io
Sent: Friday, December 2, 2022 5:48 PM
To: devel@edk2.groups.io; Liu, Zhiguang <zhiguang.liu@...>
Cc: Kinney, Michael D <michael.d.kinney@...>; Ni, Ray
<ray.ni@...>
Subject: 回复: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib:
Remove
HOST_APPLICATION limitation

Zhiguang:
Can you explain more about the emulator usage model for this library?

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表
Zhiguang
Liu
发送时间: 2022年12月2日 14:25
收件人: devel@edk2.groups.io
抄送: Zhiguang Liu <zhiguang.liu@...>; Michael D Kinney
<michael.d.kinney@...>; Liming Gao
<gaoliming@...>;
Ray Ni <ray.ni@...>
主题: [edk2-devel] [PATCH] MdePkg/UnitTestHostBaseLib: Remove
HOST_APPLICATION limitation

Remove HOST_APPLICATION limitation for UnitTestHostBaseLib, so that
this library can be used as BaseLib by Emulator.
Also, add some missing files

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Ray Ni <ray.ni@...>
---
MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
index 09a610c31c..fefa2e79f6 100644
--- a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+++ b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
@@ -1,7 +1,7 @@
## @file
# Base Library implementation for use with host based unit tests.
#
-# Copyright (c) 2007 - 2021, Intel Corporation. All rights
reserved.<BR>
+# Copyright (c) 2007 - 2022, Intel Corporation. All rights
+reserved.<BR>
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights
reserved.<BR>
# Portions copyright (c) 2011 - 2013, ARM Ltd. All rights
reserved.<BR> # Copyright (c) 2020, Hewlett Packard Enterprise
Development LP. All rights reserved.<BR> @@ -18,7 +18,7 @@
FILE_GUID =
9555A0D3-09BA-46C4-A51A-45198E3C765E
MODULE_TYPE = BASE
VERSION_STRING = 1.1
- LIBRARY_CLASS =
BaseLib|HOST_APPLICATION
+ LIBRARY_CLASS = BaseLib
LIBRARY_CLASS =
UnitTestHostBaseLib|HOST_APPLICATION

#
@@ -128,6 +128,7 @@
X86RdRand.c
X86SpeculationBarrier.c
X86UnitTestHost.c
+ IntelTdxNull.c

[Sources.X64]
X64/LongJump.nasm
@@ -168,6 +169,7 @@
X64/RdRand.nasm
ChkStkGcc.c | GCC
X86UnitTestHost.c
+ IntelTdxNull.c

[Sources.EBC]
Ebc/CpuBreakpoint.c
--
2.31.1.windows.1













回复: [edk2-devel] feature flag change notifications

gaoliming
 

Dann:
I base on new features to collect the incompatible changes, and add them into the updated notes.

If you find any missing, please send the mail to me.

Thanks
Liming

-----邮件原件-----
发件人: Kinney, Michael D <michael.d.kinney@...>
发送时间: 2022年12月6日 9:22
收件人: devel@edk2.groups.io; dann.frazier@...; Gao, Liming
<gaoliming@...>
主题: RE: [edk2-devel] feature flag change notifications

Hi Dann,

These are reasonable requests.

Adding Liming Gao who is currently responsible for the edk2 releases.

Let's start with release notes and see if some of these can be added
to the release documentation and add to the edk2 release process
to clearly note these type of changes in future release notes.

As far as #error and #warn. Those are possible, but we would need
to do some analysis for the types of changes that would require
that behavior. Your examples are useful as a starting point.

Once concern is how many of those #error/#warn conditions will
build up over time and then a process to remove them after an
expiration period.

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of dann
frazier
Sent: Monday, December 5, 2022 4:10 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] feature flag change notifications

Hi,
I maintain the edk2 packages in the Debian and Ubuntu
distributions. A few times over the years I've had users report
regressions that turned out to be due to upstream build flag
changes. I wonder if it would be possible for upstream to communicate
such changes - either via release notes or, where possible, as
build-time checks - to us downstream projects. Here are the examples I
recall:

commit 4de8d61bcec02a13ceed84f92b0cf3ea58adf9c5
Author: Gerd Hoffmann <kraxel@...>
Date: Wed Dec 15 12:39:20 2021 +0100

OvmfPkg: rework TPM configuration
For this I needed to change -DTPM_ENABLE=TRUE to
-DTPM2_ENABLE=TRUE. I
feel like a build-time check would've been a good way to communicate
this one, e.g.:

#ifdef TPM_ENABLE
#error TPM_ENABLE has been renamed to TPM2_ENABLE
#endif

commit 1631bb26ae991e530d3c96fe3161ea15144b358e
Author: Gary Lin <glin@...>
Date: Mon Jun 10 14:55:09 2019 +0800

OvmfPkg/README: Update the network build flags

The following network build flags changed due to the inclusion of
NetworkPkg/Network.fdf.inc.
Similar to the above, I needed to deal with this by setting
-DNETWORK_HTTP_BOOT_ENABLE=TRUE instead of
-DHTTP_BOOT_ENABLE=TRUE. It
seems like maybe an #error on the removed #define could've helped
here as well.

And finally:

commit 57783adfb579da32b1eeda77b2bec028a5e0b7b3
Author: Michael D Kinney <michael.d.kinney@...>
Date: Tue Jul 26 12:40:00 2022 -0700

OvmfPkg: Change default to disable MptScsi and PvScsi
With this types of change, it would be useful just to know this is
coming and why so I can decide to either notify users of the change
and/or override the default to avoid the regression. Would it be
possible to describe such changes in the release notes at
https://github.com/tianocore/edk2/releases - and, if not urgent,
perhaps #warn of deprecation in the source for one stable release
cycle?

-dann




Re: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Clark-williams, Zachary
 

++ Michal's coverage Michal and Lukasz

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Tuesday, December 6, 2022 10:38 AM
To: devel@edk2.groups.io; Clark-williams, Zachary <zachary.clark-williams@...>; Rabeda, Maciej <maciej.rabeda@...>; Zimmer, Vincent <vincent.zimmer@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Alappat, Paul <paul.alappat@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hey Maciej and All,

Is there any update in ability to review this patch for Wifi Profile Sync Protocol and Wifi Connection Manager?

Thank you,
Zack

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Clark-williams, Zachary
Sent: Wednesday, November 2, 2022 8:58 AM
To: Rabeda, Maciej <maciej.rabeda@...>; Zimmer, Vincent <vincent.zimmer@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Alappat, Paul <paul.alappat@...>; Patil, Ajit <ajit.patil@...>
Subject: Re: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hey Maciej,

I can understand that and appreciate the attention you can spare for reviewing this change.
If there are any peers you know who can/will want to review or have valuable input on this PR please feel free to send them an invite to review.

Thanks,
Zack

-----Original Message-----
From: Rabeda, Maciej <maciej.rabeda@...>
Sent: Wednesday, November 2, 2022 5:35 AM
To: Clark-williams, Zachary <zachary.clark-williams@...>; Zimmer, Vincent <vincent.zimmer@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Alappat, Paul <paul.alappat@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

@Kinney, Michael D
With the amount of work around IPUs, I can hardly spare time (maybe 2h/week on average - including code).
My time for EDK2 is currently fully allocated to:
1. https://github.com/tianocore/edk2-staging/tree/HttpProxy (@Kasbekar, Saloni) 2. NVMe-oF boot prototype under nvme.org umbrella (@Zimmer, Vincent)

@Clark-williams, Zachary
Your patch is non-trivial and requires understanding on my side. Based on that and the above, this will take time.

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Tuesday, November 1, 2022 6:41 PM
To: Zimmer, Vincent <vincent.zimmer@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Great thank you Vincent, I will add them to the protocol header file and send an updated patch today.

-----Original Message-----
From: Zimmer, Vincent <vincent.zimmer@...>
Sent: Tuesday, November 1, 2022 10:39 AM
To: Clark-williams, Zachary <zachary.clark-williams@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

That's great
If these links are not already in the .h files of the patch I'd add them.
Typically the uefi networking code leverages uefi spec or ietf rfc's or other public collateral. Letting folks know the background of these interfaces with a reference should help consumers IMHO Vincent

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Tuesday, November 1, 2022 10:35 AM
To: Zimmer, Vincent <vincent.zimmer@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hey Vincent,

The documentation for describing the features in the PR description can be found in the CSME documentation found on the public accessible intel link below.

OCR - https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Foneclickrecovery.htm

KVM - https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Foneclickrecovery.htm

Thanks,
Zack

-----Original Message-----
From: Zimmer, Vincent <vincent.zimmer@...>
Sent: Monday, October 31, 2022 2:16 PM
To: Clark-williams, Zachary <zachary.clark-williams@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Quick question

Are the features described in " Enables KVM and One Click Recovery WLAN capability with WiFi Profile Sync feature and protocol. Adding WiFiProfileSyncProtocol, which supports the profilesync driver operations for transferring WiFi profiles from AMT to the Supplicant. WiFiConnectionManager will check for the WifiProfileSyncProtocol and if found will operate on the premise of a One Click Recovery, or KVM flow with a Wifi profile provided by AMT." in a public document? Things like concept of profile sync? I'm guessing they are since Linux probably does the same in the intel iwl driver?

Vincent

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Clark-williams, Zachary
Sent: Monday, October 31, 2022 12:31 PM
To: Kinney, Michael D <michael.d.kinney@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; 'Fu, Siyuan' <siyuan.fu@...>; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: Re: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

++ visibility

-----Original Message-----
From: Clark-williams, Zachary
Sent: Friday, October 28, 2022 1:13 PM
To: Kinney, Michael D <michael.d.kinney@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Fu, Siyuan <siyuan.fu@...>; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Subject: RE: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

++More for reviewal!

-----Original Message-----
From: Clark-williams, Zachary
Sent: Friday, October 28, 2022 1:10 PM
To: Kinney, Michael D <michael.d.kinney@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io
Subject: RE: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Thanks for the forward Mike!

Maciej and All,

If you could please review the PR below. I would like to get this review completed within the week.

Thanks,
Zack

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Thursday, October 27, 2022 1:09 PM
To: Rabeda, Maciej <maciej.rabeda@...>; Kinney, Michael D <michael.d.kinney@...>; Clark-williams, Zachary <zachary.clark-williams@...>
Subject: FW: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hi Maciej,

Can you please help review these NetworkPkg changes.

I am not sure if you monitor your linux.intel.com account as closely as your intel.com account.

Thanks,

Mike

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Thursday, October 27, 2022 12:33 PM
To: Kinney, Michael D <michael.d.kinney@...>
Subject: FW: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hey Mike,

I'm struggling to get any feedback on this PR. Do you have any suggestions to get better visibility and responses so I can get this miving?

Thanks,
Zack

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Thursday, October 27, 2022 12:31 PM
To: devel@edk2.groups.io
Cc: Zachary Clark-Williams <zclarkw112@...>; Maciej Rabeda <maciej.rabeda@...>; Fu Siyuan <siyuan.fu@...>; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>; Clark-williams, Zachary <zachary.clark-williams@...>
Subject: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

From: Zachary Clark-Williams <zclarkw112@...>

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

Enables KVM and One Click Recovery WLAN capability with WiFi Profile Sync feature and protocol. Adding WiFiProfileSyncProtocol, which supports the profilesync driver operations for transferring WiFi profiles from AMT to the Supplicant. WiFiConnectionManager will check for the WifiProfileSyncProtocol and if found will operate on the premise of a One Click Recovery, or KVM flow with a Wifi profile provided by AMT.

Cc: Maciej Rabeda <maciej.rabeda@...>
Cc: Fu Siyuan <siyuan.fu@...>
Cc: Wu Jiaxin <jiaxin.wu@...>
Cc: Andrei Otcheretianski <andrei.otcheretianski@...>

Signed-off-by: Zachary Clark-Williams <zachary.clark-williams@...>
---
.../Protocol/WiFiProfileSyncProtocol.h | 83 ++++++++
NetworkPkg/NetworkPkg.dec | 3 +
.../WifiConnectionManagerDxe.inf | 3 +-
.../WifiConnectionMgrConfigNVDataStruct.h | 2 +-
.../WifiConnectionMgrDriver.c | 126 ++++++++----
.../WifiConnectionMgrDxe.h | 4 +-
.../WifiConnectionMgrImpl.c | 193 ++++++++++++++++--
.../WifiConnectionMgrMisc.c | 13 ++
8 files changed, 367 insertions(+), 60 deletions(-) create mode 100644 NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h

diff --git a/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h b/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h
new file mode 100644
index 0000000000..e36daceabf
--- /dev/null
+++ b/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h
@@ -0,0 +1,83 @@
+/** @file
+ WiFi profile sync protocol. Supports One Click Recovery or KVM OS
+recovery
+ boot flow over WiFi.
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/
+
+#ifndef WIFI_PROFILE_SYNC_PROTOCOL_H_
+#define WIFI_PROFILE_SYNC_PROTOCOL_H_
+
+#include <WifiConnectionManagerDxe/WifiConnectionMgrConfig.h>
+
+//
+// WiFi Profile Sync Protocol GUID variable.
+//
+extern EFI_GUID gEfiWiFiProfileSyncProtocolGuid;
+
+/**
+ Used by the WiFi connection manager to get the WiFi profile that AMT
+shared
+ and was stored in WiFi profile protocol. Aligns the AMT WiFi profile
+data to
+ the WiFi connection manager profile structure fo connection use.
+
+ @param[in, out] WcmProfile WiFi Connection Manager profile structure
+ @param[in, out] MacAddress MAC address from AMT saved to NiC MAC address
+
+ @retval EFI_SUCCESS Stored WiFi profile converted and returned succefully
+ @retval EFI_UNSUPPORTED Profile protocol sharing not supported or enabled
+ @retval EFI_NOT_FOUND No profiles to returned
+ @retval Others Error Occurred
+**/
+typedef
+EFI_STATUS
+(EFIAPI *WIFI_PROFILE_GET)(
+ IN OUT WIFI_MGR_NETWORK_PROFILE *Profile,
+ IN OUT EFI_80211_MAC_ADDRESS MacAddress
+ );
+
+/**
+ Saves the WiFi connection status recieved by the
+WiFiConnectionManager when
+ in a KVM OR One Click Recovery WLAN recovery flow. Input as
+ EFI_80211_CONNECT_NETWORK_RESULT_CODE then converted and stored as EFI_STATUS type.
+
+ @param[in] ConnectionStatus WiFi connection attempt results
+**/
+typedef
+VOID
+(EFIAPI *WIFI_SET_CONNECT_STATE)(
+ IN EFI_80211_CONNECT_NETWORK_RESULT_CODE ConnectionStatus
+ );
+
+/**
+ Retrieves the stored WiFi connection status when in either KVM OR One
+Click
+ Recovery WLAN recovery flow.
+
+ @retval EFI_SUCCESS WiFi connection completed succesfully
+ @retval Others Connection failure occurred
+**/
+typedef
+EFI_STATUS
+(EFIAPI *WIFI_GET_CONNECT_STATE)(
+ VOID
+ );
+
+//
+// WiFi Profile Sync Protocol structure.
+//
+typedef struct {
+ UINT32 Revision;
+ WIFI_SET_CONNECT_STATE WifiProfileSyncSetConnectState;
+ WIFI_GET_CONNECT_STATE WifiProfileSyncGetConnectState;
+ WIFI_PROFILE_GET WifiProfileSyncGetProfile;
+} EFI_WIFI_PROFILE_SYNC_PROTOCOL;
+
+/**
+ WiFi Profile Protocol revision number.
+
+ Revision 1: Initial version
+**/
+#define EFI_WIFI_PROFILE_SYNC_PROTOCOL_REVISION 1
+
+#endif // WIFI_PROFILE_SYNC_PROTOCOL_H_
diff --git a/NetworkPkg/NetworkPkg.dec b/NetworkPkg/NetworkPkg.dec index 5e43ebf8c5..53fb34c4a0 100644
--- a/NetworkPkg/NetworkPkg.dec
+++ b/NetworkPkg/NetworkPkg.dec
@@ -91,6 +91,9 @@
## Include/Protocol/HttpCallback.h
gEdkiiHttpCallbackProtocolGuid = {0x611114f1, 0xa37b, 0x4468, {0xa4, 0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2, 0x40}}

+ ## Include/Protocol/WiFiProfileSyncProtocol.h
+ gEfiWiFiProfileSyncProtocolGuid = {0x399a2b8a, 0xc267, 0x44aa, {0x9a,
+ 0xb4, 0x30, 0x58, 0x8c, 0xd2, 0x2d, 0xcc}}
+
[PcdsFixedAtBuild]
## The max attempt number will be created by iSCSI driver.
# @Prompt Max attempt number.
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
index 4394b6f4bb..7e36016cf8 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
@@ -9,7 +9,7 @@
# 2). WPA2 Personal Network
# 3). EAP Networks (EAP-TLS, EAP-TTLS/MSCHAPv2 and PEAPv0/MSCHAPv2) # -# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2019 - 2022, Intel Corporation. All rights
+reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -71,6 +71,7 @@
gEfiAdapterInformationProtocolGuid ## SOMETIMES_CONSUMES
gEfiSupplicantProtocolGuid ## SOMETIMES_CONSUMES
gEfiEapConfigurationProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiWiFiProfileSyncProtocolGuid ## SOMETIMES_CONSUMES

[Guids]
gWifiConfigGuid ## PRODUCES ## GUID
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h
index b5518a74d8..dcc4bf7e27 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataS
+++ truct.h
@@ -25,7 +25,7 @@

#define PASSWORD_MIN_LEN 8
#define PASSWORD_MAX_LEN 63
-#define PASSWORD_STORAGE_SIZE 64
+#define PASSWORD_STORAGE_SIZE 65

#define EAP_IDENTITY_LEN 63
#define EAP_IDENTITY_SIZE 64
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
index 67a01ca058..97ca7a9f0b 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
@@ -1,7 +1,7 @@
/** @file
The driver binding protocol for the WiFi Connection Manager.

- Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2019 - 2022, Intel Corporation. All rights
+ reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -39,6 +39,11 @@ EFI_GUID mWifiConfigNetworkListRefreshGuid = WIFI_CONFIG_NETWORK_LIST_REFRESH_G
EFI_GUID mWifiConfigConnectFormRefreshGuid = WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID;
EFI_GUID mWifiConfigMainFormRefreshGuid = WIFI_CONFIG_MAIN_FORM_REFRESH_GUID;

+//
+// Wifi connection attempt counter for retries // extern UINT8
+mWifiConnectionCount;
+
/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
@@ -167,8 +172,10 @@ WifiMgrDxeDriverBindingStart (
EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL *Wmp;
EFI_SUPPLICANT_PROTOCOL *Supplicant;
EFI_EAP_CONFIGURATION_PROTOCOL *EapConfig;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

- Nic = NULL;
+ mWifiConnectionCount = 0;
+ Nic = NULL;

//
// Open Protocols
@@ -236,47 +243,73 @@ WifiMgrDxeDriverBindingStart (
InitializeListHead (&Nic->ProfileList);

//
- // Record the MAC address of the incoming NIC.
+ // WiFi profile sync protocol installation check for OS recovery flow.
//
- Status = NetLibGetMacAddress (
- ControllerHandle,
- (EFI_MAC_ADDRESS *)&Nic->MacAddress,
- &AddressSize
- );
- if (EFI_ERROR (Status)) {
- goto ERROR2;
- }
-
- //
- // Create and start the timer for the status check
- //
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL | EVT_TIMER,
- TPL_CALLBACK,
- WifiMgrOnTimerTick,
- Nic,
- &Nic->TickTimer
+ Status = gBS->LocateProtocol (
+ &gEfiWiFiProfileSyncProtocolGuid,
+ NULL,
+ (VOID **)&WiFiProfileSyncProtocol
);
- if (EFI_ERROR (Status)) {
- goto ERROR2;
- }
+ if (!EFI_ERROR (Status)) {
+ Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));
+ if (Nic->ConnectPendingNetwork == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ERROR1;
+ }

- Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));
- if (EFI_ERROR (Status)) {
- goto ERROR3;
- }
+ WiFiProfileSyncProtocol->WifiProfileSyncGetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);
+ if (Nic->ConnectPendingNetwork != NULL) {
+ Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);
+ if (EFI_ERROR (Status)) {
+ WiFiProfileSyncProtocol->WifiProfileSyncSetConnectState (Status);
+ }
+ } else {
+ goto ERROR1;
+ }
+ } else {
+ //
+ // Record the MAC address of the incoming NIC.
+ //
+ Status = NetLibGetMacAddress (
+ ControllerHandle,
+ (EFI_MAC_ADDRESS *)&Nic->MacAddress,
+ &AddressSize
+ );
+ if (EFI_ERROR (Status)) {
+ goto ERROR2;
+ }

- Nic->ConnectState = WifiMgrDisconnected;
- Nic->ScanState = WifiMgrScanFinished;
+ //
+ // Create and start the timer for the status check
+ //
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL | EVT_TIMER,
+ TPL_CALLBACK,
+ WifiMgrOnTimerTick,
+ Nic,
+ &Nic->TickTimer
+ );
+ if (EFI_ERROR (Status)) {
+ goto ERROR2;
+ }

- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
- InsertTailList (&mPrivate->NicList, &Nic->Link);
- Nic->NicIndex = mPrivate->NicCount++;
- if (mPrivate->CurrentNic == NULL) {
- mPrivate->CurrentNic = Nic;
- }
+ Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));
+ if (EFI_ERROR (Status)) {
+ goto ERROR3;
+ }

- gBS->RestoreTPL (OldTpl);
+ Nic->ConnectState = WifiMgrDisconnected;
+ Nic->ScanState = WifiMgrScanFinished;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+ InsertTailList (&mPrivate->NicList, &Nic->Link);
+ Nic->NicIndex = mPrivate->NicCount++;
+ if (mPrivate->CurrentNic == NULL) {
+ mPrivate->CurrentNic = Nic;
+ }
+
+ gBS->RestoreTPL (OldTpl);
+ }

Status = gBS->InstallProtocolInterface (
&ControllerHandle,
@@ -385,10 +418,11 @@ WifiMgrDxeDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_TPL OldTpl;
- WIFI_MGR_PRIVATE_PROTOCOL *WifiMgrIdentifier;
- WIFI_MGR_DEVICE_DATA *Nic;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+ WIFI_MGR_PRIVATE_PROTOCOL *WifiMgrIdentifier;
+ WIFI_MGR_DEVICE_DATA *Nic;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

Status = gBS->OpenProtocol (
ControllerHandle,
@@ -481,7 +515,15 @@ WifiMgrDxeDriverBindingStop (
//
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

- RemoveEntryList (&Nic->Link);
+ Status = gBS->LocateProtocol (
+ &gEfiWiFiProfileSyncProtocolGuid,
+ NULL,
+ (VOID **)&WiFiProfileSyncProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ RemoveEntryList (&Nic->Link);
+ }
+
mPrivate->NicCount--;
if (mPrivate->CurrentNic == Nic) {
mPrivate->CurrentNic = NULL;
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
index 7b2e41e155..047f85dbc2 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
@@ -47,6 +47,7 @@
#include <Protocol/SimpleNetwork.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/EapConfiguration.h>
+#include <Protocol/WiFiProfileSyncProtocol.h>

//
// Produced Protocols
@@ -73,7 +74,8 @@
//
#define WIFI_MGR_DXE_VERSION 0xb

-#define OUI_IEEE_80211I 0xAC0F00
+#define OUI_IEEE_80211I 0xAC0F00
+#define MAX_WIFI_CONNETION_ATTEMPTS 3

typedef enum {
Ieee80211PairwiseCipherSuiteUseGroupCipherSuite = 0, diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
index 59bac48c42..a73ab9f710 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
@@ -19,6 +19,8 @@ EFI_EAP_TYPE mEapSecondAuthMethod[] = {
EFI_EAP_TYPE_MSCHAPV2
};

+UINT8 mWifiConnectionCount = 0;
+
/**
The callback function for scan operation. This function updates networks
according to the latest scan result, and trigger UI refresh.
@@ -424,18 +426,26 @@ WifiMgrConfigPassword (
return EFI_NOT_FOUND;
}

- AsciiPassword = AllocateZeroPool ((StrLen (Profile->Password) + 1) * sizeof (UINT8));
+ if (StrLen (Profile->Password) >= PASSWORD_STORAGE_SIZE) {
+ ASSERT (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AsciiPassword = AllocateZeroPool ((StrLen (Profile->Password) + 1) *
+ sizeof (CHAR8));
if (AsciiPassword == NULL) {
return EFI_OUT_OF_RESOURCES;
}

- UnicodeStrToAsciiStrS (Profile->Password, (CHAR8 *)AsciiPassword, PASSWORD_STORAGE_SIZE);
- Status = Supplicant->SetData (
- Supplicant,
- EfiSupplicant80211PskPassword,
- AsciiPassword,
- (StrLen (Profile->Password) + 1) * sizeof (UINT8)
- );
+ Status = UnicodeStrToAsciiStrS (Profile->Password, (CHAR8
+ *)AsciiPassword, (StrLen (Profile->Password) + 1)); if (!EFI_ERROR (Status)) {
+ Status = Supplicant->SetData (
+ Supplicant,
+ EfiSupplicant80211PskPassword,
+ AsciiPassword,
+ (StrLen (Profile->Password) + 1) * sizeof (CHAR8)
+ );
+ }
+
ZeroMem (AsciiPassword, AsciiStrLen ((CHAR8 *)AsciiPassword) + 1);
FreePool (AsciiPassword);

@@ -466,6 +476,7 @@ WifiMgrConfigEap (
)
{
EFI_STATUS Status;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;
EFI_EAP_CONFIGURATION_PROTOCOL *EapConfig;
EFI_EAP_TYPE EapAuthMethod;
EFI_EAP_TYPE EapSecondAuthMethod;
@@ -567,7 +578,13 @@ WifiMgrConfigEap (
return EFI_OUT_OF_RESOURCES;
}

- UnicodeStrToAsciiStrS (Profile->EapIdentity, Identity, IdentitySize);
+ Status = gBS->LocateProtocol (&gEfiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);
+ if (!EFI_ERROR (Status)) {
+ CopyMem (Identity, &Profile->EapIdentity, IdentitySize);
+ } else {
+ UnicodeStrToAsciiStrS (Profile->EapIdentity, Identity, IdentitySize);
+ }
+
Status = EapConfig->SetData (
EapConfig,
EFI_EAP_TYPE_IDENTITY, @@ -892,6 +909,133 @@ WifiMgrPrepareConnection (
return EFI_SUCCESS;
}

+/**
+ Will reset NiC data, get profile from profile sync driver, and send
+for
+ another connection attempt.This function should not be called more
+than
+ 3 times.
+
+ @param[in] WiFiProfileSyncProtocol The target network profile to connect.
+
+ @retval EFI_SUCCESS The operation is completed.
+ @retval other Operation failure.
+
+**/
+EFI_STATUS
+ConnectionRetry (
+ IN EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol
+ )
+{
+ EFI_STATUS Status;
+ WIFI_MGR_DEVICE_DATA *Nic;
+ EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL *Wmp;
+ EFI_SUPPLICANT_PROTOCOL *Supplicant;
+ EFI_EAP_CONFIGURATION_PROTOCOL *EapConfig;
+
+ Nic = NULL;
+
+ Status = gBS->LocateProtocol (
+ &gEfiWiFi2ProtocolGuid,
+ NULL,
+ (VOID **)&Wmp
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = gBS->LocateProtocol (
+ &gEfiSupplicantProtocolGuid,
+ NULL,
+ (VOID **)&Supplicant
+ );
+ if (EFI_ERROR (Status)) {
+ Supplicant = NULL;
+ }
+
+ Status = gBS->LocateProtocol (
+ &gEfiEapConfigurationProtocolGuid,
+ NULL,
+ (VOID **)&EapConfig
+ );
+ if (EFI_ERROR (Status)) {
+ EapConfig = NULL;
+ }
+
+ //
+ // Initialize Nic device data
+ //
+ Nic = AllocateZeroPool (sizeof (WIFI_MGR_DEVICE_DATA)); if (Nic ==
+ NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ return Status;
+ }
+
+ Nic->Signature = WIFI_MGR_DEVICE_DATA_SIGNATURE;
+ Nic->Private = mPrivate;
+ Nic->Wmp = Wmp;
+ Nic->Supplicant = Supplicant;
+ Nic->EapConfig = EapConfig;
+ Nic->UserSelectedProfile = NULL;
+ Nic->OneTimeScanRequest = FALSE;
+
+ if (Nic->Supplicant != NULL) {
+ Status = WifiMgrGetSupportedSuites (Nic); }
+
+ if (!EFI_ERROR (Status)) {
+ InitializeListHead (&Nic->ProfileList);
+
+ Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));
+ if (Nic->ConnectPendingNetwork == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to allocate memory for ConnectPendingNetwork\n"));
+ goto ERROR;
+ }
+
+ Status = WiFiProfileSyncProtocol->WifiProfileSyncGetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);
+ if (!EFI_ERROR (Status) && (Nic->ConnectPendingNetwork != NULL)) {
+ Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);
+ if (!EFI_ERROR (Status)) {
+ return Status;
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to get WiFi profile with status %r\n", Status));
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to get
+ Supported suites with status %r\n", Status)); }
+
+ if (Nic->ConnectPendingNetwork != NULL) {
+ if (Nic->ConnectPendingNetwork->Network.AKMSuite != NULL) {
+ FreePool (Nic->ConnectPendingNetwork->Network.AKMSuite);
+ }
+
+ if (Nic->ConnectPendingNetwork->Network.CipherSuite != NULL) {
+ FreePool (Nic->ConnectPendingNetwork->Network.CipherSuite);
+ }
+
+ FreePool (Nic->ConnectPendingNetwork); }
+
+ERROR:
+ if (Nic->Supplicant != NULL) {
+ if (Nic->SupportedSuites.SupportedAKMSuites != NULL) {
+ FreePool (Nic->SupportedSuites.SupportedAKMSuites);
+ }
+
+ if (Nic->SupportedSuites.SupportedSwCipherSuites != NULL) {
+ FreePool (Nic->SupportedSuites.SupportedSwCipherSuites);
+ }
+
+ if (Nic->SupportedSuites.SupportedHwCipherSuites != NULL) {
+ FreePool (Nic->SupportedSuites.SupportedHwCipherSuites);
+ }
+ }
+
+ FreePool (Nic);
+
+ return Status;
+}
+
/**
The callback function for connect operation.

@@ -908,12 +1052,13 @@ WifiMgrOnConnectFinished (
IN VOID *Context
)
{
- EFI_STATUS Status;
- WIFI_MGR_MAC_CONFIG_TOKEN *ConfigToken;
- WIFI_MGR_NETWORK_PROFILE *ConnectedProfile;
- UINT8 SecurityType;
- UINT8 SSIdLen;
- CHAR8 *AsciiSSId;
+ EFI_STATUS Status;
+ WIFI_MGR_MAC_CONFIG_TOKEN *ConfigToken;
+ WIFI_MGR_NETWORK_PROFILE *ConnectedProfile;
+ UINT8 SecurityType;
+ UINT8 SSIdLen;
+ CHAR8 *AsciiSSId;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

ASSERT (Context != NULL);

@@ -925,6 +1070,24 @@ WifiMgrOnConnectFinished (
ASSERT (ConfigToken->Type == TokenTypeConnectNetworkToken);

ASSERT (ConfigToken->Token.ConnectNetworkToken != NULL);
+
+ Status = gBS->LocateProtocol (&gEfiWiFiProfileSyncProtocolGuid, NULL,
+ (VOID **)&WiFiProfileSyncProtocol); if (!EFI_ERROR (Status)) {
+ WiFiProfileSyncProtocol->WifiProfileSyncSetConnectState (ConfigToken->Token.ConnectNetworkToken->ResultCode);
+ if ((mWifiConnectionCount < MAX_WIFI_CONNETION_ATTEMPTS) &&
+ (ConfigToken->Token.ConnectNetworkToken->ResultCode != ConnectSuccess))
+ {
+ mWifiConnectionCount++;
+ gBS->CloseEvent (Event);
+ Status = ConnectionRetry (WiFiProfileSyncProtocol);
+ if (!EFI_ERROR (Status)) {
+ return;
+ }
+
+ WiFiProfileSyncProtocol->WifiProfileSyncSetConnectState (Status);
+ }
+ }
+
if (ConfigToken->Token.ConnectNetworkToken->Status != EFI_SUCCESS) {
if (ConfigToken->Nic->OneTimeConnectRequest) {
//
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
index 4ad5643c24..87adfc5033 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
@@ -672,10 +672,23 @@ WifiMgrCleanProfileSecrets (
IN WIFI_MGR_NETWORK_PROFILE *Profile
)
{
+ EFI_STATUS Status;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;
+
ZeroMem (Profile->Password, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
ZeroMem (Profile->EapPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
ZeroMem (Profile->PrivateKeyPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);

+ //
+ // When EFI WiFi profile sync protocol is found the system is
+ performing a recovery boot in secure // boot mode. The profile sync
+ driver will manage the CA certificate, client certificate, and key // data, cleaning them at exit boot services.
+ //
+ Status = gBS->LocateProtocol (&gEfiWiFiProfileSyncProtocolGuid, NULL,
+ (VOID **)&WiFiProfileSyncProtocol); if (!EFI_ERROR (Status)) {
+ return;
+ }
+
if (Profile->CACertData != NULL) {
ZeroMem (Profile->CACertData, Profile->CACertSize);
FreePool (Profile->CACertData);
--
2.37.3.windows.1


Re: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Clark-williams, Zachary
 

Hey Maciej and All,

Is there any update in ability to review this patch for Wifi Profile Sync Protocol and Wifi Connection Manager?

Thank you,
Zack

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Clark-williams, Zachary
Sent: Wednesday, November 2, 2022 8:58 AM
To: Rabeda, Maciej <maciej.rabeda@...>; Zimmer, Vincent <vincent.zimmer@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Alappat, Paul <paul.alappat@...>; Patil, Ajit <ajit.patil@...>
Subject: Re: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hey Maciej,

I can understand that and appreciate the attention you can spare for reviewing this change.
If there are any peers you know who can/will want to review or have valuable input on this PR please feel free to send them an invite to review.

Thanks,
Zack

-----Original Message-----
From: Rabeda, Maciej <maciej.rabeda@...>
Sent: Wednesday, November 2, 2022 5:35 AM
To: Clark-williams, Zachary <zachary.clark-williams@...>; Zimmer, Vincent <vincent.zimmer@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Alappat, Paul <paul.alappat@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

@Kinney, Michael D
With the amount of work around IPUs, I can hardly spare time (maybe 2h/week on average - including code).
My time for EDK2 is currently fully allocated to:
1. https://github.com/tianocore/edk2-staging/tree/HttpProxy (@Kasbekar, Saloni) 2. NVMe-oF boot prototype under nvme.org umbrella (@Zimmer, Vincent)

@Clark-williams, Zachary
Your patch is non-trivial and requires understanding on my side. Based on that and the above, this will take time.

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Tuesday, November 1, 2022 6:41 PM
To: Zimmer, Vincent <vincent.zimmer@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Great thank you Vincent, I will add them to the protocol header file and send an updated patch today.

-----Original Message-----
From: Zimmer, Vincent <vincent.zimmer@...>
Sent: Tuesday, November 1, 2022 10:39 AM
To: Clark-williams, Zachary <zachary.clark-williams@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

That's great
If these links are not already in the .h files of the patch I'd add them.
Typically the uefi networking code leverages uefi spec or ietf rfc's or other public collateral. Letting folks know the background of these interfaces with a reference should help consumers IMHO Vincent

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Tuesday, November 1, 2022 10:35 AM
To: Zimmer, Vincent <vincent.zimmer@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hey Vincent,

The documentation for describing the features in the PR description can be found in the CSME documentation found on the public accessible intel link below.

OCR - https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Foneclickrecovery.htm

KVM - https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/default.htm?turl=WordDocuments%2Foneclickrecovery.htm

Thanks,
Zack

-----Original Message-----
From: Zimmer, Vincent <vincent.zimmer@...>
Sent: Monday, October 31, 2022 2:16 PM
To: Clark-williams, Zachary <zachary.clark-williams@...>
Subject: RE: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Quick question

Are the features described in " Enables KVM and One Click Recovery WLAN capability with WiFi Profile Sync feature and protocol. Adding WiFiProfileSyncProtocol, which supports the profilesync driver operations for transferring WiFi profiles from AMT to the Supplicant. WiFiConnectionManager will check for the WifiProfileSyncProtocol and if found will operate on the premise of a One Click Recovery, or KVM flow with a Wifi profile provided by AMT." in a public document? Things like concept of profile sync? I'm guessing they are since Linux probably does the same in the intel iwl driver?

Vincent

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Clark-williams, Zachary
Sent: Monday, October 31, 2022 12:31 PM
To: Kinney, Michael D <michael.d.kinney@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; 'Fu, Siyuan' <siyuan.fu@...>; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Cc: Alappat, Paul <paul.alappat@...>; Kasbekar, Saloni <saloni.kasbekar@...>; Patil, Ajit <ajit.patil@...>
Subject: Re: [edk2-devel] [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

++ visibility

-----Original Message-----
From: Clark-williams, Zachary
Sent: Friday, October 28, 2022 1:13 PM
To: Kinney, Michael D <michael.d.kinney@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io; Fu, Siyuan <siyuan.fu@...>; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>
Subject: RE: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

++More for reviewal!

-----Original Message-----
From: Clark-williams, Zachary
Sent: Friday, October 28, 2022 1:10 PM
To: Kinney, Michael D <michael.d.kinney@...>; Rabeda, Maciej <maciej.rabeda@...>; Luo, Heng <heng.luo@...>; Kuo, Scottie <scottie.kuo@...>; Kuo, Ted <ted.kuo@...>; Dutkiewicz, Michal <michal.dutkiewicz@...>; devel@edk2.groups.io
Subject: RE: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Thanks for the forward Mike!

Maciej and All,

If you could please review the PR below. I would like to get this review completed within the week.

Thanks,
Zack

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Thursday, October 27, 2022 1:09 PM
To: Rabeda, Maciej <maciej.rabeda@...>; Kinney, Michael D <michael.d.kinney@...>; Clark-williams, Zachary <zachary.clark-williams@...>
Subject: FW: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hi Maciej,

Can you please help review these NetworkPkg changes.

I am not sure if you monitor your linux.intel.com account as closely as your intel.com account.

Thanks,

Mike

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Thursday, October 27, 2022 12:33 PM
To: Kinney, Michael D <michael.d.kinney@...>
Subject: FW: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

Hey Mike,

I'm struggling to get any feedback on this PR. Do you have any suggestions to get better visibility and responses so I can get this miving?

Thanks,
Zack

-----Original Message-----
From: Clark-williams, Zachary <zachary.clark-williams@...>
Sent: Thursday, October 27, 2022 12:31 PM
To: devel@edk2.groups.io
Cc: Zachary Clark-Williams <zclarkw112@...>; Maciej Rabeda <maciej.rabeda@...>; Fu Siyuan <siyuan.fu@...>; Wu, Jiaxin <jiaxin.wu@...>; Otcheretianski, Andrei <andrei.otcheretianski@...>; Clark-williams, Zachary <zachary.clark-williams@...>
Subject: [PATCH v4] NetworkPkg/WifiProfileSync: Add WiFi profile sync protocol support

From: Zachary Clark-Williams <zclarkw112@...>

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

Enables KVM and One Click Recovery WLAN capability with WiFi Profile Sync feature and protocol. Adding WiFiProfileSyncProtocol, which supports the profilesync driver operations for transferring WiFi profiles from AMT to the Supplicant. WiFiConnectionManager will check for the WifiProfileSyncProtocol and if found will operate on the premise of a One Click Recovery, or KVM flow with a Wifi profile provided by AMT.

Cc: Maciej Rabeda <maciej.rabeda@...>
Cc: Fu Siyuan <siyuan.fu@...>
Cc: Wu Jiaxin <jiaxin.wu@...>
Cc: Andrei Otcheretianski <andrei.otcheretianski@...>

Signed-off-by: Zachary Clark-Williams <zachary.clark-williams@...>
---
.../Protocol/WiFiProfileSyncProtocol.h | 83 ++++++++
NetworkPkg/NetworkPkg.dec | 3 +
.../WifiConnectionManagerDxe.inf | 3 +-
.../WifiConnectionMgrConfigNVDataStruct.h | 2 +-
.../WifiConnectionMgrDriver.c | 126 ++++++++----
.../WifiConnectionMgrDxe.h | 4 +-
.../WifiConnectionMgrImpl.c | 193 ++++++++++++++++--
.../WifiConnectionMgrMisc.c | 13 ++
8 files changed, 367 insertions(+), 60 deletions(-) create mode 100644 NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h

diff --git a/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h b/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h
new file mode 100644
index 0000000000..e36daceabf
--- /dev/null
+++ b/NetworkPkg/Include/Protocol/WiFiProfileSyncProtocol.h
@@ -0,0 +1,83 @@
+/** @file
+ WiFi profile sync protocol. Supports One Click Recovery or KVM OS
+recovery
+ boot flow over WiFi.
+
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/
+
+#ifndef WIFI_PROFILE_SYNC_PROTOCOL_H_
+#define WIFI_PROFILE_SYNC_PROTOCOL_H_
+
+#include <WifiConnectionManagerDxe/WifiConnectionMgrConfig.h>
+
+//
+// WiFi Profile Sync Protocol GUID variable.
+//
+extern EFI_GUID gEfiWiFiProfileSyncProtocolGuid;
+
+/**
+ Used by the WiFi connection manager to get the WiFi profile that AMT
+shared
+ and was stored in WiFi profile protocol. Aligns the AMT WiFi profile
+data to
+ the WiFi connection manager profile structure fo connection use.
+
+ @param[in, out] WcmProfile WiFi Connection Manager profile structure
+ @param[in, out] MacAddress MAC address from AMT saved to NiC MAC address
+
+ @retval EFI_SUCCESS Stored WiFi profile converted and returned succefully
+ @retval EFI_UNSUPPORTED Profile protocol sharing not supported or enabled
+ @retval EFI_NOT_FOUND No profiles to returned
+ @retval Others Error Occurred
+**/
+typedef
+EFI_STATUS
+(EFIAPI *WIFI_PROFILE_GET)(
+ IN OUT WIFI_MGR_NETWORK_PROFILE *Profile,
+ IN OUT EFI_80211_MAC_ADDRESS MacAddress
+ );
+
+/**
+ Saves the WiFi connection status recieved by the
+WiFiConnectionManager when
+ in a KVM OR One Click Recovery WLAN recovery flow. Input as
+ EFI_80211_CONNECT_NETWORK_RESULT_CODE then converted and stored as EFI_STATUS type.
+
+ @param[in] ConnectionStatus WiFi connection attempt results
+**/
+typedef
+VOID
+(EFIAPI *WIFI_SET_CONNECT_STATE)(
+ IN EFI_80211_CONNECT_NETWORK_RESULT_CODE ConnectionStatus
+ );
+
+/**
+ Retrieves the stored WiFi connection status when in either KVM OR One
+Click
+ Recovery WLAN recovery flow.
+
+ @retval EFI_SUCCESS WiFi connection completed succesfully
+ @retval Others Connection failure occurred
+**/
+typedef
+EFI_STATUS
+(EFIAPI *WIFI_GET_CONNECT_STATE)(
+ VOID
+ );
+
+//
+// WiFi Profile Sync Protocol structure.
+//
+typedef struct {
+ UINT32 Revision;
+ WIFI_SET_CONNECT_STATE WifiProfileSyncSetConnectState;
+ WIFI_GET_CONNECT_STATE WifiProfileSyncGetConnectState;
+ WIFI_PROFILE_GET WifiProfileSyncGetProfile;
+} EFI_WIFI_PROFILE_SYNC_PROTOCOL;
+
+/**
+ WiFi Profile Protocol revision number.
+
+ Revision 1: Initial version
+**/
+#define EFI_WIFI_PROFILE_SYNC_PROTOCOL_REVISION 1
+
+#endif // WIFI_PROFILE_SYNC_PROTOCOL_H_
diff --git a/NetworkPkg/NetworkPkg.dec b/NetworkPkg/NetworkPkg.dec index 5e43ebf8c5..53fb34c4a0 100644
--- a/NetworkPkg/NetworkPkg.dec
+++ b/NetworkPkg/NetworkPkg.dec
@@ -91,6 +91,9 @@
## Include/Protocol/HttpCallback.h
gEdkiiHttpCallbackProtocolGuid = {0x611114f1, 0xa37b, 0x4468, {0xa4, 0x36, 0x5b, 0xdd, 0xa1, 0x6a, 0xa2, 0x40}}

+ ## Include/Protocol/WiFiProfileSyncProtocol.h
+ gEfiWiFiProfileSyncProtocolGuid = {0x399a2b8a, 0xc267, 0x44aa, {0x9a,
+ 0xb4, 0x30, 0x58, 0x8c, 0xd2, 0x2d, 0xcc}}
+
[PcdsFixedAtBuild]
## The max attempt number will be created by iSCSI driver.
# @Prompt Max attempt number.
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
index 4394b6f4bb..7e36016cf8 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionManagerDxe.inf
@@ -9,7 +9,7 @@
# 2). WPA2 Personal Network
# 3). EAP Networks (EAP-TLS, EAP-TTLS/MSCHAPv2 and PEAPv0/MSCHAPv2) # -# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2019 - 2022, Intel Corporation. All rights
+reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -71,6 +71,7 @@
gEfiAdapterInformationProtocolGuid ## SOMETIMES_CONSUMES
gEfiSupplicantProtocolGuid ## SOMETIMES_CONSUMES
gEfiEapConfigurationProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiWiFiProfileSyncProtocolGuid ## SOMETIMES_CONSUMES

[Guids]
gWifiConfigGuid ## PRODUCES ## GUID
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h
index b5518a74d8..dcc4bf7e27 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataStruct.h
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrConfigNVDataS
+++ truct.h
@@ -25,7 +25,7 @@

#define PASSWORD_MIN_LEN 8
#define PASSWORD_MAX_LEN 63
-#define PASSWORD_STORAGE_SIZE 64
+#define PASSWORD_STORAGE_SIZE 65

#define EAP_IDENTITY_LEN 63
#define EAP_IDENTITY_SIZE 64
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
index 67a01ca058..97ca7a9f0b 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDriver.c
@@ -1,7 +1,7 @@
/** @file
The driver binding protocol for the WiFi Connection Manager.

- Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2019 - 2022, Intel Corporation. All rights
+ reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -39,6 +39,11 @@ EFI_GUID mWifiConfigNetworkListRefreshGuid = WIFI_CONFIG_NETWORK_LIST_REFRESH_G
EFI_GUID mWifiConfigConnectFormRefreshGuid = WIFI_CONFIG_CONNECT_FORM_REFRESH_GUID;
EFI_GUID mWifiConfigMainFormRefreshGuid = WIFI_CONFIG_MAIN_FORM_REFRESH_GUID;

+//
+// Wifi connection attempt counter for retries // extern UINT8
+mWifiConnectionCount;
+
/**
Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device.
@@ -167,8 +172,10 @@ WifiMgrDxeDriverBindingStart (
EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL *Wmp;
EFI_SUPPLICANT_PROTOCOL *Supplicant;
EFI_EAP_CONFIGURATION_PROTOCOL *EapConfig;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

- Nic = NULL;
+ mWifiConnectionCount = 0;
+ Nic = NULL;

//
// Open Protocols
@@ -236,47 +243,73 @@ WifiMgrDxeDriverBindingStart (
InitializeListHead (&Nic->ProfileList);

//
- // Record the MAC address of the incoming NIC.
+ // WiFi profile sync protocol installation check for OS recovery flow.
//
- Status = NetLibGetMacAddress (
- ControllerHandle,
- (EFI_MAC_ADDRESS *)&Nic->MacAddress,
- &AddressSize
- );
- if (EFI_ERROR (Status)) {
- goto ERROR2;
- }
-
- //
- // Create and start the timer for the status check
- //
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL | EVT_TIMER,
- TPL_CALLBACK,
- WifiMgrOnTimerTick,
- Nic,
- &Nic->TickTimer
+ Status = gBS->LocateProtocol (
+ &gEfiWiFiProfileSyncProtocolGuid,
+ NULL,
+ (VOID **)&WiFiProfileSyncProtocol
);
- if (EFI_ERROR (Status)) {
- goto ERROR2;
- }
+ if (!EFI_ERROR (Status)) {
+ Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));
+ if (Nic->ConnectPendingNetwork == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ERROR1;
+ }

- Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));
- if (EFI_ERROR (Status)) {
- goto ERROR3;
- }
+ WiFiProfileSyncProtocol->WifiProfileSyncGetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);
+ if (Nic->ConnectPendingNetwork != NULL) {
+ Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);
+ if (EFI_ERROR (Status)) {
+ WiFiProfileSyncProtocol->WifiProfileSyncSetConnectState (Status);
+ }
+ } else {
+ goto ERROR1;
+ }
+ } else {
+ //
+ // Record the MAC address of the incoming NIC.
+ //
+ Status = NetLibGetMacAddress (
+ ControllerHandle,
+ (EFI_MAC_ADDRESS *)&Nic->MacAddress,
+ &AddressSize
+ );
+ if (EFI_ERROR (Status)) {
+ goto ERROR2;
+ }

- Nic->ConnectState = WifiMgrDisconnected;
- Nic->ScanState = WifiMgrScanFinished;
+ //
+ // Create and start the timer for the status check
+ //
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL | EVT_TIMER,
+ TPL_CALLBACK,
+ WifiMgrOnTimerTick,
+ Nic,
+ &Nic->TickTimer
+ );
+ if (EFI_ERROR (Status)) {
+ goto ERROR2;
+ }

- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
- InsertTailList (&mPrivate->NicList, &Nic->Link);
- Nic->NicIndex = mPrivate->NicCount++;
- if (mPrivate->CurrentNic == NULL) {
- mPrivate->CurrentNic = Nic;
- }
+ Status = gBS->SetTimer (Nic->TickTimer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISECONDS (500));
+ if (EFI_ERROR (Status)) {
+ goto ERROR3;
+ }

- gBS->RestoreTPL (OldTpl);
+ Nic->ConnectState = WifiMgrDisconnected;
+ Nic->ScanState = WifiMgrScanFinished;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+ InsertTailList (&mPrivate->NicList, &Nic->Link);
+ Nic->NicIndex = mPrivate->NicCount++;
+ if (mPrivate->CurrentNic == NULL) {
+ mPrivate->CurrentNic = Nic;
+ }
+
+ gBS->RestoreTPL (OldTpl);
+ }

Status = gBS->InstallProtocolInterface (
&ControllerHandle,
@@ -385,10 +418,11 @@ WifiMgrDxeDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
- EFI_STATUS Status;
- EFI_TPL OldTpl;
- WIFI_MGR_PRIVATE_PROTOCOL *WifiMgrIdentifier;
- WIFI_MGR_DEVICE_DATA *Nic;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+ WIFI_MGR_PRIVATE_PROTOCOL *WifiMgrIdentifier;
+ WIFI_MGR_DEVICE_DATA *Nic;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

Status = gBS->OpenProtocol (
ControllerHandle,
@@ -481,7 +515,15 @@ WifiMgrDxeDriverBindingStop (
//
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

- RemoveEntryList (&Nic->Link);
+ Status = gBS->LocateProtocol (
+ &gEfiWiFiProfileSyncProtocolGuid,
+ NULL,
+ (VOID **)&WiFiProfileSyncProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ RemoveEntryList (&Nic->Link);
+ }
+
mPrivate->NicCount--;
if (mPrivate->CurrentNic == Nic) {
mPrivate->CurrentNic = NULL;
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
index 7b2e41e155..047f85dbc2 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrDxe.h
@@ -47,6 +47,7 @@
#include <Protocol/SimpleNetwork.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/EapConfiguration.h>
+#include <Protocol/WiFiProfileSyncProtocol.h>

//
// Produced Protocols
@@ -73,7 +74,8 @@
//
#define WIFI_MGR_DXE_VERSION 0xb

-#define OUI_IEEE_80211I 0xAC0F00
+#define OUI_IEEE_80211I 0xAC0F00
+#define MAX_WIFI_CONNETION_ATTEMPTS 3

typedef enum {
Ieee80211PairwiseCipherSuiteUseGroupCipherSuite = 0, diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
index 59bac48c42..a73ab9f710 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
@@ -19,6 +19,8 @@ EFI_EAP_TYPE mEapSecondAuthMethod[] = {
EFI_EAP_TYPE_MSCHAPV2
};

+UINT8 mWifiConnectionCount = 0;
+
/**
The callback function for scan operation. This function updates networks
according to the latest scan result, and trigger UI refresh.
@@ -424,18 +426,26 @@ WifiMgrConfigPassword (
return EFI_NOT_FOUND;
}

- AsciiPassword = AllocateZeroPool ((StrLen (Profile->Password) + 1) * sizeof (UINT8));
+ if (StrLen (Profile->Password) >= PASSWORD_STORAGE_SIZE) {
+ ASSERT (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AsciiPassword = AllocateZeroPool ((StrLen (Profile->Password) + 1) *
+ sizeof (CHAR8));
if (AsciiPassword == NULL) {
return EFI_OUT_OF_RESOURCES;
}

- UnicodeStrToAsciiStrS (Profile->Password, (CHAR8 *)AsciiPassword, PASSWORD_STORAGE_SIZE);
- Status = Supplicant->SetData (
- Supplicant,
- EfiSupplicant80211PskPassword,
- AsciiPassword,
- (StrLen (Profile->Password) + 1) * sizeof (UINT8)
- );
+ Status = UnicodeStrToAsciiStrS (Profile->Password, (CHAR8
+ *)AsciiPassword, (StrLen (Profile->Password) + 1)); if (!EFI_ERROR (Status)) {
+ Status = Supplicant->SetData (
+ Supplicant,
+ EfiSupplicant80211PskPassword,
+ AsciiPassword,
+ (StrLen (Profile->Password) + 1) * sizeof (CHAR8)
+ );
+ }
+
ZeroMem (AsciiPassword, AsciiStrLen ((CHAR8 *)AsciiPassword) + 1);
FreePool (AsciiPassword);

@@ -466,6 +476,7 @@ WifiMgrConfigEap (
)
{
EFI_STATUS Status;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;
EFI_EAP_CONFIGURATION_PROTOCOL *EapConfig;
EFI_EAP_TYPE EapAuthMethod;
EFI_EAP_TYPE EapSecondAuthMethod;
@@ -567,7 +578,13 @@ WifiMgrConfigEap (
return EFI_OUT_OF_RESOURCES;
}

- UnicodeStrToAsciiStrS (Profile->EapIdentity, Identity, IdentitySize);
+ Status = gBS->LocateProtocol (&gEfiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);
+ if (!EFI_ERROR (Status)) {
+ CopyMem (Identity, &Profile->EapIdentity, IdentitySize);
+ } else {
+ UnicodeStrToAsciiStrS (Profile->EapIdentity, Identity, IdentitySize);
+ }
+
Status = EapConfig->SetData (
EapConfig,
EFI_EAP_TYPE_IDENTITY, @@ -892,6 +909,133 @@ WifiMgrPrepareConnection (
return EFI_SUCCESS;
}

+/**
+ Will reset NiC data, get profile from profile sync driver, and send
+for
+ another connection attempt.This function should not be called more
+than
+ 3 times.
+
+ @param[in] WiFiProfileSyncProtocol The target network profile to connect.
+
+ @retval EFI_SUCCESS The operation is completed.
+ @retval other Operation failure.
+
+**/
+EFI_STATUS
+ConnectionRetry (
+ IN EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol
+ )
+{
+ EFI_STATUS Status;
+ WIFI_MGR_DEVICE_DATA *Nic;
+ EFI_WIRELESS_MAC_CONNECTION_II_PROTOCOL *Wmp;
+ EFI_SUPPLICANT_PROTOCOL *Supplicant;
+ EFI_EAP_CONFIGURATION_PROTOCOL *EapConfig;
+
+ Nic = NULL;
+
+ Status = gBS->LocateProtocol (
+ &gEfiWiFi2ProtocolGuid,
+ NULL,
+ (VOID **)&Wmp
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = gBS->LocateProtocol (
+ &gEfiSupplicantProtocolGuid,
+ NULL,
+ (VOID **)&Supplicant
+ );
+ if (EFI_ERROR (Status)) {
+ Supplicant = NULL;
+ }
+
+ Status = gBS->LocateProtocol (
+ &gEfiEapConfigurationProtocolGuid,
+ NULL,
+ (VOID **)&EapConfig
+ );
+ if (EFI_ERROR (Status)) {
+ EapConfig = NULL;
+ }
+
+ //
+ // Initialize Nic device data
+ //
+ Nic = AllocateZeroPool (sizeof (WIFI_MGR_DEVICE_DATA)); if (Nic ==
+ NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ return Status;
+ }
+
+ Nic->Signature = WIFI_MGR_DEVICE_DATA_SIGNATURE;
+ Nic->Private = mPrivate;
+ Nic->Wmp = Wmp;
+ Nic->Supplicant = Supplicant;
+ Nic->EapConfig = EapConfig;
+ Nic->UserSelectedProfile = NULL;
+ Nic->OneTimeScanRequest = FALSE;
+
+ if (Nic->Supplicant != NULL) {
+ Status = WifiMgrGetSupportedSuites (Nic); }
+
+ if (!EFI_ERROR (Status)) {
+ InitializeListHead (&Nic->ProfileList);
+
+ Nic->ConnectPendingNetwork = (WIFI_MGR_NETWORK_PROFILE *)AllocateZeroPool (sizeof (WIFI_MGR_NETWORK_PROFILE));
+ if (Nic->ConnectPendingNetwork == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to allocate memory for ConnectPendingNetwork\n"));
+ goto ERROR;
+ }
+
+ Status = WiFiProfileSyncProtocol->WifiProfileSyncGetProfile (Nic->ConnectPendingNetwork, Nic->MacAddress);
+ if (!EFI_ERROR (Status) && (Nic->ConnectPendingNetwork != NULL)) {
+ Status = WifiMgrConnectToNetwork (Nic, Nic->ConnectPendingNetwork);
+ if (!EFI_ERROR (Status)) {
+ return Status;
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to get WiFi profile with status %r\n", Status));
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "[WiFi Connection Manager] Failed to get
+ Supported suites with status %r\n", Status)); }
+
+ if (Nic->ConnectPendingNetwork != NULL) {
+ if (Nic->ConnectPendingNetwork->Network.AKMSuite != NULL) {
+ FreePool (Nic->ConnectPendingNetwork->Network.AKMSuite);
+ }
+
+ if (Nic->ConnectPendingNetwork->Network.CipherSuite != NULL) {
+ FreePool (Nic->ConnectPendingNetwork->Network.CipherSuite);
+ }
+
+ FreePool (Nic->ConnectPendingNetwork); }
+
+ERROR:
+ if (Nic->Supplicant != NULL) {
+ if (Nic->SupportedSuites.SupportedAKMSuites != NULL) {
+ FreePool (Nic->SupportedSuites.SupportedAKMSuites);
+ }
+
+ if (Nic->SupportedSuites.SupportedSwCipherSuites != NULL) {
+ FreePool (Nic->SupportedSuites.SupportedSwCipherSuites);
+ }
+
+ if (Nic->SupportedSuites.SupportedHwCipherSuites != NULL) {
+ FreePool (Nic->SupportedSuites.SupportedHwCipherSuites);
+ }
+ }
+
+ FreePool (Nic);
+
+ return Status;
+}
+
/**
The callback function for connect operation.

@@ -908,12 +1052,13 @@ WifiMgrOnConnectFinished (
IN VOID *Context
)
{
- EFI_STATUS Status;
- WIFI_MGR_MAC_CONFIG_TOKEN *ConfigToken;
- WIFI_MGR_NETWORK_PROFILE *ConnectedProfile;
- UINT8 SecurityType;
- UINT8 SSIdLen;
- CHAR8 *AsciiSSId;
+ EFI_STATUS Status;
+ WIFI_MGR_MAC_CONFIG_TOKEN *ConfigToken;
+ WIFI_MGR_NETWORK_PROFILE *ConnectedProfile;
+ UINT8 SecurityType;
+ UINT8 SSIdLen;
+ CHAR8 *AsciiSSId;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;

ASSERT (Context != NULL);

@@ -925,6 +1070,24 @@ WifiMgrOnConnectFinished (
ASSERT (ConfigToken->Type == TokenTypeConnectNetworkToken);

ASSERT (ConfigToken->Token.ConnectNetworkToken != NULL);
+
+ Status = gBS->LocateProtocol (&gEfiWiFiProfileSyncProtocolGuid, NULL,
+ (VOID **)&WiFiProfileSyncProtocol); if (!EFI_ERROR (Status)) {
+ WiFiProfileSyncProtocol->WifiProfileSyncSetConnectState (ConfigToken->Token.ConnectNetworkToken->ResultCode);
+ if ((mWifiConnectionCount < MAX_WIFI_CONNETION_ATTEMPTS) &&
+ (ConfigToken->Token.ConnectNetworkToken->ResultCode != ConnectSuccess))
+ {
+ mWifiConnectionCount++;
+ gBS->CloseEvent (Event);
+ Status = ConnectionRetry (WiFiProfileSyncProtocol);
+ if (!EFI_ERROR (Status)) {
+ return;
+ }
+
+ WiFiProfileSyncProtocol->WifiProfileSyncSetConnectState (Status);
+ }
+ }
+
if (ConfigToken->Token.ConnectNetworkToken->Status != EFI_SUCCESS) {
if (ConfigToken->Nic->OneTimeConnectRequest) {
//
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
index 4ad5643c24..87adfc5033 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrMisc.c
@@ -672,10 +672,23 @@ WifiMgrCleanProfileSecrets (
IN WIFI_MGR_NETWORK_PROFILE *Profile
)
{
+ EFI_STATUS Status;
+ EFI_WIFI_PROFILE_SYNC_PROTOCOL *WiFiProfileSyncProtocol;
+
ZeroMem (Profile->Password, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
ZeroMem (Profile->EapPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);
ZeroMem (Profile->PrivateKeyPassword, sizeof (CHAR16) * PASSWORD_STORAGE_SIZE);

+ //
+ // When EFI WiFi profile sync protocol is found the system is
+ performing a recovery boot in secure // boot mode. The profile sync
+ driver will manage the CA certificate, client certificate, and key // data, cleaning them at exit boot services.
+ //
+ Status = gBS->LocateProtocol (&gEfiWiFiProfileSyncProtocolGuid, NULL,
+ (VOID **)&WiFiProfileSyncProtocol); if (!EFI_ERROR (Status)) {
+ return;
+ }
+
if (Profile->CACertData != NULL) {
ZeroMem (Profile->CACertData, Profile->CACertSize);
FreePool (Profile->CACertData);
--
2.37.3.windows.1


MdeModulePkg/UefiBootManagerLib: Use hob size to process MemoryTypeInfo

Anbazhagan, Baraneedharan
 

Current code relies on last entry in hob to be MaxMemoryType enum value

which keeps changing on new memory type definition. If the HOB is

created by binaries built with older Edk2, current code leads to hang

which could be avoided by using hob size.

 

Signed-off-by: Baraneedharan Anbazhagan anbazhagan@...

---

MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)

 

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c

index a5e32ebdba..014e4557bf 100644

--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c

+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c

@@ -140,6 +140,7 @@ BmSetMemoryTypeInformationVariable (

   UINT32                       Current;

   UINT32                       Next;

   EFI_HOB_GUID_TYPE            *GuidHob;

+  UINTN                        NoOfEntries;

   BOOLEAN                      MemoryTypeInformationModified;

   BOOLEAN                      MemoryTypeInformationVariableExists;

   EFI_BOOT_MODE                BootMode;

@@ -200,6 +201,7 @@ BmSetMemoryTypeInformationVariable (

   }

   VariableSize                  = GET_GUID_HOB_DATA_SIZE (GuidHob);

+  NoOfEntries                   = VariableSize / sizeof(EFI_MEMORY_TYPE_INFORMATION);

   PreviousMemoryTypeInformation = AllocateCopyPool (VariableSize, GET_GUID_HOB_DATA (GuidHob));

   if (PreviousMemoryTypeInformation == NULL) {

     return;

@@ -212,8 +214,8 @@ BmSetMemoryTypeInformationVariable (

   DEBUG ((DEBUG_INFO, " Type    Pages     Pages     Pages  \n"));

   DEBUG ((DEBUG_INFO, "======  ========  ========  ========\n"));

-  for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {

-    for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {

+  for (Index = 0; Index < NoOfEntries; Index++) {

+    for (Index1 = 0; Index1 < NoOfEntries; Index1++) {

       if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {

         break;

       }

--

2.38.1.windows.1

 


Re: [Patch 1/2] OvmfPkg: Change default to disable MptScsi and PvScsi

Mike Maslenkin
 

Greetings All!

As I can see LSI_SCSI_ENABLE related to LSI LSI_53C895A_PCI_DEVICE_ID
Vid/Did 0x1000:0x0012.
I guess it is some old Megaraid adapter.

A patch mentioned above set MPT_SCSI_ENABLE=FALSE, that removed
support for LSI 53C1030 and SAS1068.
These SCSI controllers were emulated by VMware, Parallels and I guess
VitualBox.
This is generic setup for VMware VMs, as far as I remember.
So the booting of such VMs (probably migrated from VMware and others)
was definitely broken.

Regards,
Mike.

On Tue, Dec 6, 2022 at 5:38 PM dann frazier <dann.frazier@...> wrote:

On Tue, Dec 06, 2022 at 06:56:49AM +0100, Gerd Hoffmann wrote:
On Mon, Dec 05, 2022 at 04:36:15PM -0700, dann frazier wrote:
On Tue, Jul 26, 2022 at 12:46:39PM -0700, Michael D Kinney wrote:
The email addresses for the reviewers of the MptScsi and
PvScsi are no longer valid. Disable the MptScsi and PvScsi
drivers in all DSC files until new maintainers/reviewers can
be identified.
Hi Michael,

This seems likely to be the reason for the following regression
report in Debian:

https://bugs.debian.org/1016359
I'm not so sure about that.

- DEFINE PVSCSI_ENABLE = TRUE
- DEFINE MPT_SCSI_ENABLE = TRUE
+ DEFINE PVSCSI_ENABLE = FALSE
+ DEFINE MPT_SCSI_ENABLE = FALSE
DEFINE LSI_SCSI_ENABLE = FALSE
The bug report talks about lsilogic and virtio-scsi.

lsilogic was already disabled by default before this patch.

virtio-scsi support is included and there are no plans to change
that because it is a rather essential driver. It works just fine
upstream, and there isn't even a config switch to disable it.
Thanks Gerd - I'll work with the users to clarify via the bug (thanks
for responding there as well btw).

-dann





Re: [Patch 1/2] OvmfPkg: Change default to disable MptScsi and PvScsi

dann frazier
 

On Tue, Dec 06, 2022 at 06:56:49AM +0100, Gerd Hoffmann wrote:
On Mon, Dec 05, 2022 at 04:36:15PM -0700, dann frazier wrote:
On Tue, Jul 26, 2022 at 12:46:39PM -0700, Michael D Kinney wrote:
The email addresses for the reviewers of the MptScsi and
PvScsi are no longer valid. Disable the MptScsi and PvScsi
drivers in all DSC files until new maintainers/reviewers can
be identified.
Hi Michael,

This seems likely to be the reason for the following regression
report in Debian:

https://bugs.debian.org/1016359
I'm not so sure about that.

- DEFINE PVSCSI_ENABLE = TRUE
- DEFINE MPT_SCSI_ENABLE = TRUE
+ DEFINE PVSCSI_ENABLE = FALSE
+ DEFINE MPT_SCSI_ENABLE = FALSE
DEFINE LSI_SCSI_ENABLE = FALSE
The bug report talks about lsilogic and virtio-scsi.

lsilogic was already disabled by default before this patch.

virtio-scsi support is included and there are no plans to change
that because it is a rather essential driver. It works just fine
upstream, and there isn't even a config switch to disable it.
Thanks Gerd - I'll work with the users to clarify via the bug (thanks
for responding there as well btw).

-dann


Re: [Patch 1/1] RedfishPkg: Remove overlapping private include path in DEC file

Igor Kulchytskyy
 

Reviewed-by: Igor Kulchytskyy <igork@ami.com>


From: Chang, Abner <Abner.Chang@...>
Sent: Tuesday, December 6, 2022 3:23:56 AM
To: Michael D Kinney <michael.d.kinney@...>; devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Nickle Wang <nicklew@...>; Igor Kulchytskyy <igork@...>
Subject: [EXTERNAL] RE: [Patch 1/1] RedfishPkg: Remove overlapping private include path in DEC file
 

**CAUTION: The e-mail below is from an external source. Please exercise caution before opening attachments, clicking links, or following guidance.**

[AMD Official Use Only - General]

Reviewed-by: Abner Chang <abner.chang@...>

> -----Original Message-----
> From: Michael D Kinney <michael.d.kinney@...>
> Sent: Tuesday, December 6, 2022 8:45 AM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@...>; Nickle Wang
> <nicklew@...>; Igor Kulchytskyy <igork@...>
> Subject: [Patch 1/1] RedfishPkg: Remove overlapping private include path in
> DEC file
>
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> Update ReadfishPkg.dec to remove PrivateInclude from the
> [Includes.Common.Private] section.  The PrivateInclude directory does not
> contain any include files, and the PrivateInclude/Crt include path remaining in
> the [Includes.Common.Private] section providing the include path required
> to access the CRT related include files by components within the RedfishPkg.
>
> Without this update, there are two forms of #include statements that can be
> used to include the CRT related include files.
> Include files should only be available using one form of #include statements.
>
> Cc: Abner Chang <abner.chang@...>
> Cc: Nickle Wang <nicklew@...>
> Cc: Igor Kulchytskyy <igork@...>
> Signed-off-by: Michael D Kinney <michael.d.kinney@...>
> ---
>  RedfishPkg/RedfishPkg.dec | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec index
> 0aa26883e220..d2b189b13d8c 100644
> --- a/RedfishPkg/RedfishPkg.dec
> +++ b/RedfishPkg/RedfishPkg.dec
> @@ -17,7 +17,6 @@ [Includes]
>    Include
>
>  [Includes.Common.Private]
> -  PrivateInclude                # Private header files for C RTL.
>    PrivateInclude/Crt            # Private header files for C RTL.
>    Library/JsonLib               # Private header files for jansson
>                                  # configuration files.
> --
> 2.37.1.windows.1
-The information contained in this message may be confidential and proprietary to American Megatrends (AMI). This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.


[PATCH v2 1/1] MdeModulePkg: Put USB DEBUGs that occur for bulk timeouts under VERBOSE

Rebecca Cran <quic_rcran@...>
 

With the pending commit of UsbNetworkPkg, it will become common for
UsbBulkTransfer calls to timeout, given that the drivers are called from
MnpSystemPoll every MNP_SYS_POLL_INTERVAL milliseconds: the drivers
check for network packets by calling UsbBulkTransfer with a timeout of
1ms.

Avoid console spam by moving DEBUG messages that occur each time a bulk
transfer request times out from DEBUG_ERROR to DEBUG_VERBOSE, for both
EHCI and XHCI drivers.

Signed-off-by: Rebecca Cran <rebecca@...>
---
MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 9 ++++++++-
MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 2 +-
MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 9 ++++++++-
MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 6 +++---
4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
index 0b7270f4e930..e903593b0198 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
@@ -848,6 +848,7 @@ EhcBulkTransfer (
URB *Urb;
EFI_TPL OldTpl;
EFI_STATUS Status;
+ UINTN DebugErrorLevel;

//
// Validate the parameters
@@ -932,7 +933,13 @@ EhcBulkTransfer (
gBS->RestoreTPL (OldTpl);

if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "EhcBulkTransfer: error - %r, transfer - %x\n", Status, *TransferResult));
+ if (Status == EFI_TIMEOUT) {
+ DebugErrorLevel = DEBUG_VERBOSE;
+ } else {
+ DebugErrorLevel = DEBUG_ERROR;
+ }
+
+ DEBUG ((DebugErrorLevel, "EhcBulkTransfer: error - %r, transfer - %x\n", Status, *TransferResult));
}

return Status;
diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
index 5da26afbe120..6967aabceb78 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
@@ -702,7 +702,7 @@ EhcExecTransfer (
}

if (!Finished) {
- DEBUG ((DEBUG_ERROR, "EhcExecTransfer: transfer not finished in %dms\n", (UINT32)TimeOut));
+ DEBUG ((DEBUG_VERBOSE, "EhcExecTransfer: transfer not finished in %dms\n", (UINT32)TimeOut));
EhcDumpQh (Urb->Qh, NULL, FALSE);

Status = EFI_TIMEOUT;
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index c05431ff30ec..15fb49f28fa0 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -1242,6 +1242,7 @@ XhcBulkTransfer (
UINT8 SlotId;
EFI_STATUS Status;
EFI_TPL OldTpl;
+ UINTN DebugErrorLevel;

//
// Validate the parameters
@@ -1304,7 +1305,13 @@ XhcBulkTransfer (

ON_EXIT:
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "XhcBulkTransfer: error - %r, transfer - %x\n", Status, *TransferResult));
+ if (Status == EFI_TIMEOUT) {
+ DebugErrorLevel = DEBUG_VERBOSE;
+ } else {
+ DebugErrorLevel = DEBUG_ERROR;
+ }
+
+ DEBUG ((DebugErrorLevel, "XhcBulkTransfer: error - %r, transfer - %x\n", Status, *TransferResult));
}

gBS->RestoreTPL (OldTpl);
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index 13b0400e83d7..13247f7b0dfc 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -734,7 +734,7 @@ XhcDequeueTrbFromEndpoint (
Dci = XhcEndpointToDci (Urb->Ep.EpAddr, (UINT8)(Urb->Ep.Direction));
ASSERT (Dci < 32);

- DEBUG ((DEBUG_INFO, "Stop Slot = %x,Dci = %x\n", SlotId, Dci));
+ DEBUG ((DEBUG_VERBOSE, "Stop Slot = %x,Dci = %x\n", SlotId, Dci));

//
// 1) Send Stop endpoint command to stop xHC from executing of the TDs on the endpoint
@@ -3376,7 +3376,7 @@ XhcStopEndpoint (
EVT_TRB_COMMAND_COMPLETION *EvtTrb;
CMD_TRB_STOP_ENDPOINT CmdTrbStopED;

- DEBUG ((DEBUG_INFO, "XhcStopEndpoint: Slot = 0x%x, Dci = 0x%x\n", SlotId, Dci));
+ DEBUG ((DEBUG_VERBOSE, "XhcStopEndpoint: Slot = 0x%x, Dci = 0x%x\n", SlotId, Dci));

//
// When XhcCheckUrbResult waits for the Stop_Endpoint completion, it also checks
@@ -3497,7 +3497,7 @@ XhcSetTrDequeuePointer (
CMD_SET_TR_DEQ_POINTER CmdSetTRDeq;
EFI_PHYSICAL_ADDRESS PhyAddr;

- DEBUG ((DEBUG_INFO, "XhcSetTrDequeuePointer: Slot = 0x%x, Dci = 0x%x, Urb = 0x%x\n", SlotId, Dci, Urb));
+ DEBUG ((DEBUG_VERBOSE, "XhcSetTrDequeuePointer: Slot = 0x%x, Dci = 0x%x, Urb = 0x%x\n", SlotId, Dci, Urb));

//
// Send stop endpoint command to transit Endpoint from running to stop state
--
2.30.2


[PATCH v2 0/1] MdeModulePkg: Put USB DEBUGs that occur for bulk timeouts under VERBOSE

Rebecca Cran <quic_rcran@...>
 

*Changes between v1 and v2*

Only switch to DEBUG_VERBOSE for EFI_TIMEOUT errors.

Test Pull Request: https://github.com/tianocore/edk2/pull/3705

---

MdeModulePkg: Put USB DEBUGs that occur for bulk timeouts under VERBOSE

With the pending commit of UsbNetworkPkg, it will become common for
UsbBulkTransfer calls to timeout, given that the drivers are called from
MnpSystemPoll every MNP_SYS_POLL_INTERVAL milliseconds: the drivers
check for network packets by calling UsbBulkTransfer with a timeout of
1ms.

Avoid console spam by moving DEBUG messages that occur each time a bulk
transfer request times out from DEBUG_ERROR to DEBUG_VERBOSE, for both
EHCI and XHCI drivers.

Rebecca Cran (1):
MdeModulePkg: Put USB DEBUGs that occur for bulk timeouts under
VERBOSE

MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 9 ++++++++-
MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 2 +-
MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 9 ++++++++-
MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 6 +++---
4 files changed, 20 insertions(+), 6 deletions(-)

--
2.30.2


[PATCH v1 5/5] UefiCpuPkg/AmdSmmCpuFeaturesLib: Handles S3 save state

Abdul Lateef Attar
 

From: Abdul Lateef Attar <AbdulLateef.Attar@...>

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

Handles S3 save state restore condition.
Implements SmmCpuFeaturesCompleteSmmReadyToLock() to
sync all processor and update S3 resume entry point.

Cc: Paul Grimes <paul.grimes@...>
Cc: Garrett Kirkendall <garrett.kirkendall@...>
Cc: Abner Chang <abner.chang@...>
Cc: Eric Dong <eric.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rahul Kumar <rahul1.kumar@...>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@...>
---
.../AmdSmmCpuFeaturesLib.inf | 1 +
.../SmmCpuFeaturesLib/Amd/SmramSaveState.h | 19 +++++++++++
.../SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c | 32 +++++++++++++++++++
3 files changed, 52 insertions(+)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
index 95eb31d16ead..7fd559e91ad8 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
@@ -27,6 +27,7 @@ [Sources]
[Packages]
MdePkg/MdePkg.dec
UefiCpuPkg/UefiCpuPkg.dec
+ MdeModulePkg/MdeModulePkg.dec

[LibraryClasses]
BaseLib
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
index 290ebdbc9227..474a5dbd9765 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
@@ -17,6 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/DebugLib.h>
#include <Library/SmmServicesTableLib.h>
#include <Register/Amd/SmramSaveStateMap.h>
+#include <Guid/AcpiS3Context.h>

// EFER register LMA bit
#define LMA BIT10
@@ -106,4 +107,22 @@ InternalSmmCpuFeaturesWriteSaveStateRegister (
IN CONST VOID *Buffer
);

+/**
+ Initialize MP synchronization data.
+**/
+VOID
+EFIAPI
+InitializeMpSyncData (
+ VOID
+ );
+
+/**
+ Perform SMM MP sync Semaphores re-initialization in the S3 boot path.
+**/
+VOID
+EFIAPI
+SmmS3MpSemaphoreInit (
+ VOID
+ );
+
#endif
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
index 10bed4116397..b855573d9401 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
@@ -14,6 +14,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// The mode of the CPU at the time an SMI occurs
extern UINT8 mSmmSaveStateRegisterLma;

+// SMM S3 resume state Ptr
+extern SMM_S3_RESUME_STATE *mSmmS3ResumeState;
+
/**
Read an SMM Save State register on the target processor. If this function
returns EFI_UNSUPPORTED, then the caller is responsible for reading the
@@ -441,4 +444,33 @@ SmmCpuFeaturesCompleteSmmReadyToLock (
VOID
)
{
+ if (mSmmS3ResumeState != NULL ) {
+ mSmmS3ResumeState->SmmS3ResumeEntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)SmmS3MpSemaphoreInit;
+ }
+}
+
+/**
+ Perform SMM MP sync Semaphores re-initialization in the S3 boot path.
+**/
+VOID
+EFIAPI
+SmmS3MpSemaphoreInit (
+ VOID
+ )
+{
+ InitializeMpSyncData ();
+
+ DEBUG ((DEBUG_INFO, "SMM S3 Return CS = %x\n", mSmmS3ResumeState->ReturnCs));
+ DEBUG ((DEBUG_INFO, "SMM S3 Return Entry Point = %x\n", mSmmS3ResumeState->ReturnEntryPoint));
+ DEBUG ((DEBUG_INFO, "SMM S3 Return Context1 = %x\n", mSmmS3ResumeState->ReturnContext1));
+ DEBUG ((DEBUG_INFO, "SMM S3 Return Context2 = %x\n", mSmmS3ResumeState->ReturnContext2));
+ DEBUG ((DEBUG_INFO, "SMM S3 Return Stack Pointer = %x\n", mSmmS3ResumeState->ReturnStackPointer));
+
+ AsmDisablePaging64 (
+ mSmmS3ResumeState->ReturnCs,
+ (UINT32)mSmmS3ResumeState->ReturnEntryPoint,
+ (UINT32)mSmmS3ResumeState->ReturnContext1,
+ (UINT32)mSmmS3ResumeState->ReturnContext2,
+ (UINT32)mSmmS3ResumeState->ReturnStackPointer
+ );
}
--
2.25.1


[PATCH v1 4/5] UefiCpuPkg: Implements SmmCpuFeaturesLib for AMD Family

Abdul Lateef Attar
 

From: Abdul Lateef Attar <AbdulLateef.Attar@...>

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

Implements interfaces to read and write save state
registers of AMD's processor family.
Initializes processor SMMADDR and MASK depends
on PcdSmrrEnable flag.
Program or corrects the IP once control returns from SMM.

Cc: Paul Grimes <paul.grimes@...>
Cc: Garrett Kirkendall <garrett.kirkendall@...>
Cc: Abner Chang <abner.chang@...>
Cc: Eric Dong <eric.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rahul Kumar <rahul1.kumar@...>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@...>
---
.../AmdSmmCpuFeaturesLib.inf | 2 +
.../SmmCpuFeaturesLib/Amd/SmramSaveState.h | 109 +++++
.../SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c | 97 ++++-
.../SmmCpuFeaturesLib/Amd/SmramSaveState.c | 409 ++++++++++++++++++
4 files changed, 612 insertions(+), 5 deletions(-)
create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
index 08ac0262022f..95eb31d16ead 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
@@ -21,6 +21,8 @@ [Sources]
SmmCpuFeaturesLib.c
SmmCpuFeaturesLibCommon.c
Amd/SmmCpuFeaturesLib.c
+ Amd/SmramSaveState.c
+ Amd/SmramSaveState.h

[Packages]
MdePkg/MdePkg.dec
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
new file mode 100644
index 000000000000..290ebdbc9227
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.h
@@ -0,0 +1,109 @@
+/** @file
+SMRAM Save State Map header file.
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef SMRAM_SAVESTATE_H_
+#define SMRAM_SAVESTATE_H_
+
+#include <Library/SmmCpuFeaturesLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PcdLib.h>
+#include <Library/DebugLib.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Register/Amd/SmramSaveStateMap.h>
+
+// EFER register LMA bit
+#define LMA BIT10
+
+// Machine Specific Registers (MSRs)
+#define SMMADDR_ADDRESS 0xC0010112ul
+#define SMMMASK_ADDRESS 0xC0010113ul
+#define EFER_ADDRESS 0XC0000080ul
+
+// Macro used to simplify the lookup table entries of type CPU_SMM_SAVE_STATE_LOOKUP_ENTRY
+#define SMM_CPU_OFFSET(Field) OFFSET_OF (AMD_SMRAM_SAVE_STATE_MAP, Field)
+
+// Macro used to simplify the lookup table entries of type CPU_SMM_SAVE_STATE_REGISTER_RANGE
+#define SMM_REGISTER_RANGE(Start, End) { Start, End, End - Start + 1 }
+
+// Structure used to describe a range of registers
+typedef struct {
+ EFI_SMM_SAVE_STATE_REGISTER Start;
+ EFI_SMM_SAVE_STATE_REGISTER End;
+ UINTN Length;
+} CPU_SMM_SAVE_STATE_REGISTER_RANGE;
+
+// Structure used to build a lookup table to retrieve the widths and offsets
+// associated with each supported EFI_SMM_SAVE_STATE_REGISTER value
+
+#define SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX 1
+#define SMM_SAVE_STATE_REGISTER_MAX_INDEX 2
+
+typedef struct {
+ UINT8 Width32;
+ UINT8 Width64;
+ UINT16 Offset32;
+ UINT16 Offset64Lo;
+ UINT16 Offset64Hi;
+ BOOLEAN Writeable;
+} CPU_SMM_SAVE_STATE_LOOKUP_ENTRY;
+
+/**
+ Read an SMM Save State register on the target processor. If this function
+ returns EFI_UNSUPPORTED, then the caller is responsible for reading the
+ SMM Save Sate register.
+
+ @param[in] CpuIndex The index of the CPU to read the SMM Save State. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] Register The SMM Save State register to read.
+ @param[in] Width The number of bytes to read from the CPU save state.
+ @param[out] Buffer Upon return, this holds the CPU register value read
+ from the save state.
+
+ @retval EFI_SUCCESS The register was read from Save State.
+ @retval EFI_INVALID_PARAMTER Buffer is NULL.
+ @retval EFI_UNSUPPORTED This function does not support reading Register.
+
+**/
+EFI_STATUS
+EFIAPI
+InternalSmmCpuFeaturesReadSaveStateRegister (
+ IN UINTN CpuIndex,
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,
+ IN UINTN Width,
+ OUT VOID *Buffer
+ );
+
+/**
+ Writes an SMM Save State register on the target processor. If this function
+ returns EFI_UNSUPPORTED, then the caller is responsible for writing the
+ SMM Save Sate register.
+
+ @param[in] CpuIndex The index of the CPU to write the SMM Save State. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] Register The SMM Save State register to write.
+ @param[in] Width The number of bytes to write to the CPU save state.
+ @param[in] Buffer Upon entry, this holds the new CPU register value.
+
+ @retval EFI_SUCCESS The register was written to Save State.
+ @retval EFI_INVALID_PARAMTER Buffer is NULL.
+ @retval EFI_UNSUPPORTED This function does not support writing Register.
+**/
+EFI_STATUS
+EFIAPI
+InternalSmmCpuFeaturesWriteSaveStateRegister (
+ IN UINTN CpuIndex,
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,
+ IN UINTN Width,
+ IN CONST VOID *Buffer
+ );
+
+#endif
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
index dc3fed0302d2..10bed4116397 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
@@ -9,8 +9,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

**/

-#include <Library/SmmCpuFeaturesLib.h>
-#include <Uefi/UefiBaseType.h>
+#include "SmramSaveState.h"
+
+// The mode of the CPU at the time an SMI occurs
+extern UINT8 mSmmSaveStateRegisterLma;

/**
Read an SMM Save State register on the target processor. If this function
@@ -39,7 +41,7 @@ SmmCpuFeaturesReadSaveStateRegister (
OUT VOID *Buffer
)
{
- return EFI_SUCCESS;
+ return InternalSmmCpuFeaturesReadSaveStateRegister (CpuIndex, Register, Width, Buffer);
}

/**
@@ -67,7 +69,7 @@ SmmCpuFeaturesWriteSaveStateRegister (
IN CONST VOID *Buffer
)
{
- return EFI_SUCCESS;
+ return InternalSmmCpuFeaturesWriteSaveStateRegister (CpuIndex, Register, Width, Buffer);
}

/**
@@ -82,6 +84,13 @@ CpuFeaturesLibInitialization (
VOID
)
{
+ UINT32 LMAValue;
+
+ LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA;
+ mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT;
+ if (LMAValue) {
+ mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT;
+ }
}

/**
@@ -117,6 +126,52 @@ SmmCpuFeaturesInitializeProcessor (
IN CPU_HOT_PLUG_DATA *CpuHotPlugData
)
{
+ AMD_SMRAM_SAVE_STATE_MAP *CpuState;
+ UINT32 LMAValue;
+
+ //
+ // Configure SMBASE.
+ //
+ CpuState = (AMD_SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
+ CpuState->x64.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];
+
+ // Re-initialize the value of mSmmSaveStateRegisterLma flag which might have been changed in PiCpuSmmDxeSmm Driver
+ // Entry point, to make sure correct value on AMD platform is assigned to be used by SmmCpuFeaturesLib.
+ LMAValue = (UINT32)AsmReadMsr64 (EFER_ADDRESS) & LMA;
+ mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT;
+ if (LMAValue) {
+ mSmmSaveStateRegisterLma = EFI_SMM_SAVE_STATE_REGISTER_LMA_64BIT;
+ }
+
+ //
+ // If SMRR is supported, then program SMRR base/mask MSRs.
+ // The EFI_MSR_SMRR_PHYS_MASK_VALID bit is not set until the first normal SMI.
+ // The code that initializes SMM environment is running in normal mode
+ // from SMRAM region. If SMRR is enabled here, then the SMRAM region
+ // is protected and the normal mode code execution will fail.
+ //
+ if (FeaturePcdGet (PcdSmrrEnable)) {
+ //
+ // SMRR size cannot be less than 4-KBytes
+ // SMRR size must be of length 2^n
+ // SMRR base alignment cannot be less than SMRR length
+ //
+ if ((CpuHotPlugData->SmrrSize < SIZE_4KB) ||
+ (CpuHotPlugData->SmrrSize != GetPowerOfTwo32 (CpuHotPlugData->SmrrSize)) ||
+ ((CpuHotPlugData->SmrrBase & ~(CpuHotPlugData->SmrrSize - 1)) != CpuHotPlugData->SmrrBase))
+ {
+ //
+ // Print message and halt if CPU is Monarch
+ //
+ if (IsMonarch) {
+ DEBUG ((DEBUG_ERROR, "SMM Base/Size does not meet alignment/size requirement!\n"));
+ CpuDeadLoop ();
+ }
+ } else {
+ AsmWriteMsr64 (SMMADDR_ADDRESS, CpuHotPlugData->SmrrBase);
+ AsmWriteMsr64 (SMMMASK_ADDRESS, ((~(UINT64)(CpuHotPlugData->SmrrSize - 1)) | 0x6600));
+ }
+ }
}

/**
@@ -159,7 +214,39 @@ SmmCpuFeaturesHookReturnFromSmm (
IN UINT64 NewInstructionPointer
)
{
- return 0;
+ UINT64 OriginalInstructionPointer;
+ AMD_SMRAM_SAVE_STATE_MAP *AmdCpuState;
+
+ AmdCpuState = (AMD_SMRAM_SAVE_STATE_MAP *)CpuState;
+
+ if (mSmmSaveStateRegisterLma == EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT) {
+ OriginalInstructionPointer = (UINT64)AmdCpuState->x86._EIP;
+ AmdCpuState->x86._EIP = (UINT32)NewInstructionPointer;
+ //
+ // Clear the auto HALT restart flag so the RSM instruction returns
+ // program control to the instruction following the HLT instruction.
+ //
+ if ((AmdCpuState->x86.AutoHALTRestart & BIT0) != 0) {
+ AmdCpuState->x86.AutoHALTRestart &= ~BIT0;
+ }
+ } else {
+ OriginalInstructionPointer = AmdCpuState->x64._RIP;
+ if ((AmdCpuState->x64.EFER & LMA) == 0) {
+ AmdCpuState->x64._RIP = (UINT32)NewInstructionPointer32;
+ } else {
+ AmdCpuState->x64._RIP = (UINT32)NewInstructionPointer;
+ }
+
+ //
+ // Clear the auto HALT restart flag so the RSM instruction returns
+ // program control to the instruction following the HLT instruction.
+ //
+ if ((AmdCpuState->x64.AutoHALTRestart & BIT0) != 0) {
+ AmdCpuState->x64.AutoHALTRestart &= ~BIT0;
+ }
+ }
+
+ return OriginalInstructionPointer;
}

/**
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.c
new file mode 100644
index 000000000000..c1e7e6d6c6d9
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmramSaveState.c
@@ -0,0 +1,409 @@
+/** @file
+Provides services to access SMRAM Save State Map
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "SmramSaveState.h"
+
+// The mode of the CPU at the time an SMI occurs
+extern UINT8 mSmmSaveStateRegisterLma;
+
+// Table used by GetRegisterIndex() to convert an EFI_SMM_SAVE_STATE_REGISTER
+// value to an index into a table of type CPU_SMM_SAVE_STATE_LOOKUP_ENTRY
+static CONST CPU_SMM_SAVE_STATE_REGISTER_RANGE mSmmCpuRegisterRanges[] = {
+ SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_GDTBASE, EFI_SMM_SAVE_STATE_REGISTER_LDTINFO),
+ SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_ES, EFI_SMM_SAVE_STATE_REGISTER_RIP),
+ SMM_REGISTER_RANGE (EFI_SMM_SAVE_STATE_REGISTER_RFLAGS, EFI_SMM_SAVE_STATE_REGISTER_CR4),
+ { (EFI_SMM_SAVE_STATE_REGISTER)0, (EFI_SMM_SAVE_STATE_REGISTER)0, 0}
+};
+
+// Lookup table used to retrieve the widths and offsets associated with each
+// supported EFI_SMM_SAVE_STATE_REGISTER value
+static CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmCpuWidthOffset[] = {
+ { 0, 0, 0, 0, FALSE }, // Reserved
+
+ //
+ // Internally defined CPU Save State Registers. Not defined in PI SMM CPU Protocol.
+ //
+ { 4, 4, SMM_CPU_OFFSET (x86.SMMRevId), SMM_CPU_OFFSET (x64.SMMRevId), 0, FALSE}, // SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX = 1
+
+ //
+ // CPU Save State registers defined in PI SMM CPU Protocol.
+ //
+ { 4, 8, SMM_CPU_OFFSET (x86.GDTBase), SMM_CPU_OFFSET (x64._GDTRBaseLoDword), SMM_CPU_OFFSET (x64._GDTRBaseHiDword), FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_GDTBASE = 4
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._IDTRBaseLoDword), SMM_CPU_OFFSET (x64._IDTRBaseLoDword), FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_IDTBASE = 5
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._LDTRBaseLoDword), SMM_CPU_OFFSET (x64._LDTRBaseLoDword), FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_LDTBASE = 6
+ { 0, 2, 0, SMM_CPU_OFFSET (x64._GDTRLimit), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_GDTLIMIT = 7
+ { 0, 2, 0, SMM_CPU_OFFSET (x64._IDTRLimit), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_IDTLIMIT = 8
+ { 0, 4, 0, SMM_CPU_OFFSET (x64._LDTRLimit), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_LDTLIMIT = 9
+ { 0, 0, 0, 0, 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_LDTINFO = 10
+ { 4, 2, SMM_CPU_OFFSET (x86._ES), SMM_CPU_OFFSET (x64._ES), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_ES = 20
+ { 4, 2, SMM_CPU_OFFSET (x86._CS), SMM_CPU_OFFSET (x64._CS), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_CS = 21
+ { 4, 2, SMM_CPU_OFFSET (x86._SS), SMM_CPU_OFFSET (x64._SS), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_SS = 22
+ { 4, 2, SMM_CPU_OFFSET (x86._DS), SMM_CPU_OFFSET (x64._DS), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_DS = 23
+ { 4, 2, SMM_CPU_OFFSET (x86._FS), SMM_CPU_OFFSET (x64._FS), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_FS = 24
+ { 4, 2, SMM_CPU_OFFSET (x86._GS), SMM_CPU_OFFSET (x64._GS), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_GS = 25
+ { 0, 2, 0, SMM_CPU_OFFSET (x64._LDTR), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_LDTR_SEL = 26
+ { 0, 2, 0, SMM_CPU_OFFSET (x64._TR), 0, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_TR_SEL = 27
+ { 4, 8, SMM_CPU_OFFSET (x86._DR7), SMM_CPU_OFFSET (x64._DR7), SMM_CPU_OFFSET (x64._DR7) + 4, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_DR7 = 28
+ { 4, 8, SMM_CPU_OFFSET (x86._DR6), SMM_CPU_OFFSET (x64._DR6), SMM_CPU_OFFSET (x64._DR6) + 4, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_DR6 = 29
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R8), SMM_CPU_OFFSET (x64._R8) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R8 = 30
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R9), SMM_CPU_OFFSET (x64._R9) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R9 = 31
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R10), SMM_CPU_OFFSET (x64._R10) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R10 = 32
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R11), SMM_CPU_OFFSET (x64._R11) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R11 = 33
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R12), SMM_CPU_OFFSET (x64._R12) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R12 = 34
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R13), SMM_CPU_OFFSET (x64._R13) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R13 = 35
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R14), SMM_CPU_OFFSET (x64._R14) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R14 = 36
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._R15), SMM_CPU_OFFSET (x64._R15) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_R15 = 37
+ { 4, 8, SMM_CPU_OFFSET (x86._EAX), SMM_CPU_OFFSET (x64._RAX), SMM_CPU_OFFSET (x64._RAX) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RAX = 38
+ { 4, 8, SMM_CPU_OFFSET (x86._EBX), SMM_CPU_OFFSET (x64._RBX), SMM_CPU_OFFSET (x64._RBX) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RBX = 39
+ { 4, 8, SMM_CPU_OFFSET (x86._ECX), SMM_CPU_OFFSET (x64._RCX), SMM_CPU_OFFSET (x64._RCX) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RBX = 39
+ { 4, 8, SMM_CPU_OFFSET (x86._EDX), SMM_CPU_OFFSET (x64._RDX), SMM_CPU_OFFSET (x64._RDX) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RDX = 41
+ { 4, 8, SMM_CPU_OFFSET (x86._ESP), SMM_CPU_OFFSET (x64._RSP), SMM_CPU_OFFSET (x64._RSP) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RSP = 42
+ { 4, 8, SMM_CPU_OFFSET (x86._EBP), SMM_CPU_OFFSET (x64._RBP), SMM_CPU_OFFSET (x64._RBP) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RBP = 43
+ { 4, 8, SMM_CPU_OFFSET (x86._ESI), SMM_CPU_OFFSET (x64._RSI), SMM_CPU_OFFSET (x64._RSI) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RSI = 44
+ { 4, 8, SMM_CPU_OFFSET (x86._EDI), SMM_CPU_OFFSET (x64._RDI), SMM_CPU_OFFSET (x64._RDI) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RDI = 45
+ { 4, 8, SMM_CPU_OFFSET (x86._EIP), SMM_CPU_OFFSET (x64._RIP), SMM_CPU_OFFSET (x64._RIP) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RIP = 46
+
+ { 4, 8, SMM_CPU_OFFSET (x86._EFLAGS), SMM_CPU_OFFSET (x64._RFLAGS), SMM_CPU_OFFSET (x64._RFLAGS) + 4, TRUE}, // EFI_SMM_SAVE_STATE_REGISTER_RFLAGS = 51
+ { 4, 8, SMM_CPU_OFFSET (x86._CR0), SMM_CPU_OFFSET (x64._CR0), SMM_CPU_OFFSET (x64._CR0) + 4, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_CR0 = 52
+ { 4, 8, SMM_CPU_OFFSET (x86._CR3), SMM_CPU_OFFSET (x64._CR3), SMM_CPU_OFFSET (x64._CR3) + 4, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_CR3 = 53
+ { 0, 8, 0, SMM_CPU_OFFSET (x64._CR4), SMM_CPU_OFFSET (x64._CR4) + 4, FALSE}, // EFI_SMM_SAVE_STATE_REGISTER_CR4 = 54
+ { 0, 0, 0, 0, 0 }
+};
+
+/**
+ Read information from the CPU save state.
+
+ @param Register Specifies the CPU register to read form the save state.
+
+ @retval 0 Register is not valid
+ @retval >0 Index into mSmmCpuWidthOffset[] associated with Register
+
+**/
+STATIC
+UINTN
+EFIAPI
+GetRegisterIndex (
+ IN EFI_SMM_SAVE_STATE_REGISTER Register
+ )
+{
+ UINTN Index;
+ UINTN Offset;
+
+ for (Index = 0, Offset = SMM_SAVE_STATE_REGISTER_MAX_INDEX; mSmmCpuRegisterRanges[Index].Length != 0; Index++) {
+ if ((Register >= mSmmCpuRegisterRanges[Index].Start) && (Register <= mSmmCpuRegisterRanges[Index].End)) {
+ return Register - mSmmCpuRegisterRanges[Index].Start + Offset;
+ }
+
+ Offset += mSmmCpuRegisterRanges[Index].Length;
+ }
+
+ return 0;
+}
+
+/**
+ Read a CPU Save State register on the target processor.
+
+ This function abstracts the differences that whether the CPU Save State register is in the
+ IA32 CPU Save State Map or X64 CPU Save State Map.
+
+ This function supports reading a CPU Save State register in SMBase relocation handler.
+
+ @param[in] CpuIndex Specifies the zero-based index of the CPU save state.
+ @param[in] RegisterIndex Index into mSmmCpuWidthOffset[] look up table.
+ @param[in] Width The number of bytes to read from the CPU save state.
+ @param[out] Buffer Upon return, this holds the CPU register value read from the save state.
+
+ @retval EFI_SUCCESS The register was read from Save State.
+ @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor.
+ @retval EFI_INVALID_PARAMTER This or Buffer is NULL.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ReadSaveStateRegisterByIndex (
+ IN UINTN CpuIndex,
+ IN UINTN RegisterIndex,
+ IN UINTN Width,
+ OUT VOID *Buffer
+ )
+{
+ AMD_SMRAM_SAVE_STATE_MAP *CpuSaveState;
+
+ // UINT32 SmmRevId;
+
+ if (RegisterIndex == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ CpuSaveState = gSmst->CpuSaveState[CpuIndex];
+ // SmmRevId = CpuSaveState->x86.SMMRevId;
+
+ if (mSmmSaveStateRegisterLma == EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT) {
+ //
+ // If 32-bit mode width is zero, then the specified register can not be accessed
+ //
+ if (mSmmCpuWidthOffset[RegisterIndex].Width32 == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // If Width is bigger than the 32-bit mode width, then the specified register can not be accessed
+ //
+ if (Width > mSmmCpuWidthOffset[RegisterIndex].Width32) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Write return buffer
+ //
+ ASSERT (CpuSaveState != NULL);
+ CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Width);
+ } else {
+ //
+ // If 64-bit mode width is zero, then the specified register can not be accessed
+ //
+ if (mSmmCpuWidthOffset[RegisterIndex].Width64 == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // If Width is bigger than the 64-bit mode width, then the specified register can not be accessed
+ //
+ if (Width > mSmmCpuWidthOffset[RegisterIndex].Width64) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Write lower 32-bits of return buffer
+ //
+ CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, MIN (4, Width));
+ if (Width >= 4) {
+ //
+ // Write upper 32-bits of return buffer
+ //
+ CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4);
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Read an SMM Save State register on the target processor. If this function
+ returns EFI_UNSUPPORTED, then the caller is responsible for reading the
+ SMM Save Sate register.
+
+ @param[in] CpuIndex The index of the CPU to read the SMM Save State. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] Register The SMM Save State register to read.
+ @param[in] Width The number of bytes to read from the CPU save state.
+ @param[out] Buffer Upon return, this holds the CPU register value read
+ from the save state.
+
+ @retval EFI_SUCCESS The register was read from Save State.
+ @retval EFI_INVALID_PARAMTER Buffer is NULL.
+ @retval EFI_UNSUPPORTED This function does not support reading Register.
+
+**/
+EFI_STATUS
+EFIAPI
+InternalSmmCpuFeaturesReadSaveStateRegister (
+ IN UINTN CpuIndex,
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,
+ IN UINTN Width,
+ OUT VOID *Buffer
+ )
+{
+ UINT32 SmmRevId;
+ EFI_SMM_SAVE_STATE_IO_INFO *IoInfo;
+ AMD_SMRAM_SAVE_STATE_MAP *CpuSaveState;
+ UINT8 DataWidth;
+
+ // Read CPU State
+ CpuSaveState = (AMD_SMRAM_SAVE_STATE_MAP *)gSmst->CpuSaveState[CpuIndex];
+
+ // Check for special EFI_SMM_SAVE_STATE_REGISTER_LMA
+ if (Register == EFI_SMM_SAVE_STATE_REGISTER_LMA) {
+ // Only byte access is supported for this register
+ if (Width != 1) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *(UINT8 *)Buffer = mSmmSaveStateRegisterLma;
+
+ return EFI_SUCCESS;
+ }
+
+ // Check for special EFI_SMM_SAVE_STATE_REGISTER_IO
+
+ if (Register == EFI_SMM_SAVE_STATE_REGISTER_IO) {
+ //
+ // Get SMM Revision ID
+ //
+ ReadSaveStateRegisterByIndex (CpuIndex, SMM_SAVE_STATE_REGISTER_SMMREVID_INDEX, sizeof (SmmRevId), &SmmRevId);
+
+ //
+ // See if the CPU supports the IOMisc register in the save state
+ //
+ if (SmmRevId < AMD_SMM_MIN_REV_ID_X64) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Check if IO Restart Dword [IO Trap] is valid or not using bit 1.
+ if (!(CpuSaveState->x64.IO_DWord & 0x02u)) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Zero the IoInfo structure that will be returned in Buffer
+ IoInfo = (EFI_SMM_SAVE_STATE_IO_INFO *)Buffer;
+ ZeroMem (IoInfo, sizeof (EFI_SMM_SAVE_STATE_IO_INFO));
+
+ IoInfo->IoPort = (UINT16)(CpuSaveState->x64.IO_DWord >> 16u);
+
+ if (CpuSaveState->x64.IO_DWord & 0x10u) {
+ IoInfo->IoWidth = EFI_SMM_SAVE_STATE_IO_WIDTH_UINT8;
+ DataWidth = 0x01u;
+ } else if (CpuSaveState->x64.IO_DWord & 0x20u) {
+ IoInfo->IoWidth = EFI_SMM_SAVE_STATE_IO_WIDTH_UINT16;
+ DataWidth = 0x02u;
+ } else {
+ IoInfo->IoWidth = EFI_SMM_SAVE_STATE_IO_WIDTH_UINT32;
+ DataWidth = 0x04u;
+ }
+
+ if (CpuSaveState->x64.IO_DWord & 0x01u) {
+ IoInfo->IoType = EFI_SMM_SAVE_STATE_IO_TYPE_INPUT;
+ } else {
+ IoInfo->IoType = EFI_SMM_SAVE_STATE_IO_TYPE_OUTPUT;
+ }
+
+ if ((IoInfo->IoType == EFI_SMM_SAVE_STATE_IO_TYPE_INPUT) || (IoInfo->IoType == EFI_SMM_SAVE_STATE_IO_TYPE_OUTPUT)) {
+ SmmCpuFeaturesReadSaveStateRegister (CpuIndex, EFI_SMM_SAVE_STATE_REGISTER_RAX, DataWidth, &IoInfo->IoData);
+ }
+
+ return EFI_SUCCESS;
+ }
+
+ // Convert Register to a register lookup table index
+ return ReadSaveStateRegisterByIndex (CpuIndex, GetRegisterIndex (Register), Width, Buffer);
+}
+
+/**
+ Writes an SMM Save State register on the target processor. If this function
+ returns EFI_UNSUPPORTED, then the caller is responsible for writing the
+ SMM Save Sate register.
+
+ @param[in] CpuIndex The index of the CPU to write the SMM Save State. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] Register The SMM Save State register to write.
+ @param[in] Width The number of bytes to write to the CPU save state.
+ @param[in] Buffer Upon entry, this holds the new CPU register value.
+
+ @retval EFI_SUCCESS The register was written to Save State.
+ @retval EFI_INVALID_PARAMTER Buffer is NULL.
+ @retval EFI_UNSUPPORTED This function does not support writing Register.
+**/
+EFI_STATUS
+EFIAPI
+InternalSmmCpuFeaturesWriteSaveStateRegister (
+ IN UINTN CpuIndex,
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,
+ IN UINTN Width,
+ IN CONST VOID *Buffer
+ )
+{
+ UINTN RegisterIndex;
+ AMD_SMRAM_SAVE_STATE_MAP *CpuSaveState;
+
+ //
+ // Writes to EFI_SMM_SAVE_STATE_REGISTER_LMA are ignored
+ //
+ if (Register == EFI_SMM_SAVE_STATE_REGISTER_LMA) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Writes to EFI_SMM_SAVE_STATE_REGISTER_IO are not supported
+ //
+ if (Register == EFI_SMM_SAVE_STATE_REGISTER_IO) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Convert Register to a register lookup table index
+ //
+ RegisterIndex = GetRegisterIndex (Register);
+ if (RegisterIndex == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ CpuSaveState = gSmst->CpuSaveState[CpuIndex];
+
+ //
+ // Do not write non-writable SaveState, because it will cause exception.
+ //
+ if (!mSmmCpuWidthOffset[RegisterIndex].Writeable) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Check CPU mode
+ //
+ if (mSmmSaveStateRegisterLma == EFI_SMM_SAVE_STATE_REGISTER_LMA_32BIT) {
+ //
+ // If 32-bit mode width is zero, then the specified register can not be accessed
+ //
+ if (mSmmCpuWidthOffset[RegisterIndex].Width32 == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // If Width is bigger than the 32-bit mode width, then the specified register can not be accessed
+ //
+ if (Width > mSmmCpuWidthOffset[RegisterIndex].Width32) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Write SMM State register
+ //
+ ASSERT (CpuSaveState != NULL);
+ CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Buffer, Width);
+ } else {
+ //
+ // If 64-bit mode width is zero, then the specified register can not be accessed
+ //
+ if (mSmmCpuWidthOffset[RegisterIndex].Width64 == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // If Width is bigger than the 64-bit mode width, then the specified register can not be accessed
+ //
+ if (Width > mSmmCpuWidthOffset[RegisterIndex].Width64) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Write lower 32-bits of SMM State register
+ //
+ CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, Buffer, MIN (4, Width));
+ if (Width >= 4) {
+ //
+ // Write upper 32-bits of SMM State register
+ //
+ CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, (UINT8 *)Buffer + 4, Width - 4);
+ }
+ }
+
+ return EFI_SUCCESS;
+}
--
2.25.1


[PATCH v1 3/5] UefiCpuPkg: Initial implementation of AMD's SmmCpuFeaturesLib

Abdul Lateef Attar
 

From: Abdul Lateef Attar <AbdulLateef.Attar@...>

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

Adds initial defination for AMD's SmmCpuFeaturesLib
library implementation.
All function's body either empty or just returns
value. Its initial skeleton of library implementation.

Cc: Paul Grimes <paul.grimes@...>
Cc: Garrett Kirkendall <garrett.kirkendall@...>
Cc: Abner Chang <abner.chang@...>
Cc: Eric Dong <eric.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rahul Kumar <rahul1.kumar@...>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@...>
---
UefiCpuPkg/UefiCpuPkg.dsc | 9 +
.../AmdSmmCpuFeaturesLib.inf | 37 ++
.../SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c | 357 ++++++++++++++++++
3 files changed, 403 insertions(+)
create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c

diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index 67b0ce46e455..8aeaf992af9b 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -2,6 +2,7 @@
# UefiCpuPkg Package
#
# Copyright (c) 2007 - 2022, Intel Corporation. All rights reserved.<BR>
+# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -160,6 +161,7 @@ [Components.IA32, Components.X64]
UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.inf
UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.inf
UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf
+ UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -176,6 +178,13 @@ [Components.IA32, Components.X64]
<LibraryClasses>
SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
}
+ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf {
+ <Defines>
+ FILE_GUID = B7242C74-BD21-49EE-84B4-07162E8C080D
+ <LibraryClasses>
+ SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
+ SmmCpuPlatformHookLib|UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf
+ }
UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf
UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
new file mode 100644
index 000000000000..08ac0262022f
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/AmdSmmCpuFeaturesLib.inf
@@ -0,0 +1,37 @@
+## @file
+# The CPU specific programming for PiSmmCpuDxeSmm module.
+#
+# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SmmCpuFeaturesLib
+ MODULE_UNI_FILE = SmmCpuFeaturesLib.uni
+ FILE_GUID = 5849E964-78EC-428E-8CBD-848A7E359134
+ MODULE_TYPE = DXE_SMM_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = SmmCpuFeaturesLib
+ CONSTRUCTOR = SmmCpuFeaturesLibConstructor
+
+[Sources]
+ SmmCpuFeaturesLib.c
+ SmmCpuFeaturesLibCommon.c
+ Amd/SmmCpuFeaturesLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ PcdLib
+ MemoryAllocationLib
+ DebugLib
+
+[FeaturePcd]
+ gUefiCpuPkgTokenSpaceGuid.PcdSmrrEnable ## CONSUMES
+ gUefiCpuPkgTokenSpaceGuid.PcdSmmFeatureControlEnable ## CONSUMES
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
new file mode 100644
index 000000000000..dc3fed0302d2
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Amd/SmmCpuFeaturesLib.c
@@ -0,0 +1,357 @@
+/** @file
+Implementation specific to the SmmCpuFeatureLib library instance
+for AMD based platforms.
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.<BR>
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/SmmCpuFeaturesLib.h>
+#include <Uefi/UefiBaseType.h>
+
+/**
+ Read an SMM Save State register on the target processor. If this function
+ returns EFI_UNSUPPORTED, then the caller is responsible for reading the
+ SMM Save Sate register.
+
+ @param[in] CpuIndex The index of the CPU to read the SMM Save State. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] Register The SMM Save State register to read.
+ @param[in] Width The number of bytes to read from the CPU save state.
+ @param[out] Buffer Upon return, this holds the CPU register value read
+ from the save state.
+
+ @retval EFI_SUCCESS The register was read from Save State.
+ @retval EFI_INVALID_PARAMTER Buffer is NULL.
+ @retval EFI_UNSUPPORTED This function does not support reading Register.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmCpuFeaturesReadSaveStateRegister (
+ IN UINTN CpuIndex,
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,
+ IN UINTN Width,
+ OUT VOID *Buffer
+ )
+{
+ return EFI_SUCCESS;
+}
+
+/**
+ Writes an SMM Save State register on the target processor. If this function
+ returns EFI_UNSUPPORTED, then the caller is responsible for writing the
+ SMM Save Sate register.
+
+ @param[in] CpuIndex The index of the CPU to write the SMM Save State. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] Register The SMM Save State register to write.
+ @param[in] Width The number of bytes to write to the CPU save state.
+ @param[in] Buffer Upon entry, this holds the new CPU register value.
+
+ @retval EFI_SUCCESS The register was written to Save State.
+ @retval EFI_INVALID_PARAMTER Buffer is NULL.
+ @retval EFI_UNSUPPORTED This function does not support writing Register.
+**/
+EFI_STATUS
+EFIAPI
+SmmCpuFeaturesWriteSaveStateRegister (
+ IN UINTN CpuIndex,
+ IN EFI_SMM_SAVE_STATE_REGISTER Register,
+ IN UINTN Width,
+ IN CONST VOID *Buffer
+ )
+{
+ return EFI_SUCCESS;
+}
+
+/**
+ Performs library initialization.
+
+ This initialization function contains common functionality shared betwen all
+ library instance constructors.
+
+**/
+VOID
+CpuFeaturesLibInitialization (
+ VOID
+ )
+{
+}
+
+/**
+ Called during the very first SMI into System Management Mode to initialize
+ CPU features, including SMBASE, for the currently executing CPU. Since this
+ is the first SMI, the SMRAM Save State Map is at the default address of
+ AMD_SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET. The currently executing
+ CPU is specified by CpuIndex and CpuIndex can be used to access information
+ about the currently executing CPU in the ProcessorInfo array and the
+ HotPlugCpuData data structure.
+
+ @param[in] CpuIndex The index of the CPU to initialize. The value
+ must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] IsMonarch TRUE if the CpuIndex is the index of the CPU that
+ was elected as monarch during System Management
+ Mode initialization.
+ FALSE if the CpuIndex is not the index of the CPU
+ that was elected as monarch during System
+ Management Mode initialization.
+ @param[in] ProcessorInfo Pointer to an array of EFI_PROCESSOR_INFORMATION
+ structures. ProcessorInfo[CpuIndex] contains the
+ information for the currently executing CPU.
+ @param[in] CpuHotPlugData Pointer to the CPU_HOT_PLUG_DATA structure that
+ contains the ApidId and SmBase arrays.
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesInitializeProcessor (
+ IN UINTN CpuIndex,
+ IN BOOLEAN IsMonarch,
+ IN EFI_PROCESSOR_INFORMATION *ProcessorInfo,
+ IN CPU_HOT_PLUG_DATA *CpuHotPlugData
+ )
+{
+}
+
+/**
+ This function updates the SMRAM save state on the currently executing CPU
+ to resume execution at a specific address after an RSM instruction. This
+ function must evaluate the SMRAM save state to determine the execution mode
+ the RSM instruction resumes and update the resume execution address with
+ either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart
+ flag in the SMRAM save state must always be cleared. This function returns
+ the value of the instruction pointer from the SMRAM save state that was
+ replaced. If this function returns 0, then the SMRAM save state was not
+ modified.
+
+ This function is called during the very first SMI on each CPU after
+ SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode
+ to signal that the SMBASE of each CPU has been updated before the default
+ SMBASE address is used for the first SMI to the next CPU.
+
+ @param[in] CpuIndex The index of the CPU to hook. The value
+ must be between 0 and the NumberOfCpus
+ field in the System Management System Table
+ (SMST).
+ @param[in] CpuState Pointer to SMRAM Save State Map for the
+ currently executing CPU.
+ @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to
+ 32-bit execution mode from 64-bit SMM.
+ @param[in] NewInstructionPointer Instruction pointer to use if resuming to
+ same execution mode as SMM.
+
+ @retval 0 This function did modify the SMRAM save state.
+ @retval > 0 The original instruction pointer value from the SMRAM save state
+ before it was replaced.
+**/
+UINT64
+EFIAPI
+SmmCpuFeaturesHookReturnFromSmm (
+ IN UINTN CpuIndex,
+ IN SMRAM_SAVE_STATE_MAP *CpuState,
+ IN UINT64 NewInstructionPointer32,
+ IN UINT64 NewInstructionPointer
+ )
+{
+ return 0;
+}
+
+/**
+ Return the size, in bytes, of a custom SMI Handler in bytes. If 0 is
+ returned, then a custom SMI handler is not provided by this library,
+ and the default SMI handler must be used.
+
+ @retval 0 Use the default SMI handler.
+ @retval > 0 Use the SMI handler installed by SmmCpuFeaturesInstallSmiHandler()
+ The caller is required to allocate enough SMRAM for each CPU to
+ support the size of the custom SMI handler.
+**/
+UINTN
+EFIAPI
+SmmCpuFeaturesGetSmiHandlerSize (
+ VOID
+ )
+{
+ return 0;
+}
+
+/**
+ Install a custom SMI handler for the CPU specified by CpuIndex. This function
+ is only called if SmmCpuFeaturesGetSmiHandlerSize() returns a size is greater
+ than zero and is called by the CPU that was elected as monarch during System
+ Management Mode initialization.
+
+ @param[in] CpuIndex The index of the CPU to install the custom SMI handler.
+ The value must be between 0 and the NumberOfCpus field
+ in the System Management System Table (SMST).
+ @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.
+ @param[in] SmiStack The stack to use when an SMI is processed by the
+ the CPU specified by CpuIndex.
+ @param[in] StackSize The size, in bytes, if the stack used when an SMI is
+ processed by the CPU specified by CpuIndex.
+ @param[in] GdtBase The base address of the GDT to use when an SMI is
+ processed by the CPU specified by CpuIndex.
+ @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is
+ processed by the CPU specified by CpuIndex.
+ @param[in] IdtBase The base address of the IDT to use when an SMI is
+ processed by the CPU specified by CpuIndex.
+ @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is
+ processed by the CPU specified by CpuIndex.
+ @param[in] Cr3 The base address of the page tables to use when an SMI
+ is processed by the CPU specified by CpuIndex.
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesInstallSmiHandler (
+ IN UINTN CpuIndex,
+ IN UINT32 SmBase,
+ IN VOID *SmiStack,
+ IN UINTN StackSize,
+ IN UINTN GdtBase,
+ IN UINTN GdtSize,
+ IN UINTN IdtBase,
+ IN UINTN IdtSize,
+ IN UINT32 Cr3
+ )
+{
+}
+
+/**
+ Determines if MTRR registers must be configured to set SMRAM cache-ability
+ when executing in System Management Mode.
+
+ @retval TRUE MTRR registers must be configured to set SMRAM cache-ability.
+ @retval FALSE MTRR registers do not need to be configured to set SMRAM
+ cache-ability.
+**/
+BOOLEAN
+EFIAPI
+SmmCpuFeaturesNeedConfigureMtrrs (
+ VOID
+ )
+{
+ return FALSE;
+}
+
+/**
+ Disable SMRR register if SMRR is supported and SmmCpuFeaturesNeedConfigureMtrrs()
+ returns TRUE.
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesDisableSmrr (
+ VOID
+ )
+{
+}
+
+/**
+ Enable SMRR register if SMRR is supported and SmmCpuFeaturesNeedConfigureMtrrs()
+ returns TRUE.
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesReenableSmrr (
+ VOID
+ )
+{
+}
+
+/**
+ Processor specific hook point each time a CPU enters System Management Mode.
+
+ @param[in] CpuIndex The index of the CPU that has entered SMM. The value
+ must be between 0 and the NumberOfCpus field in the
+ System Management System Table (SMST).
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesRendezvousEntry (
+ IN UINTN CpuIndex
+ )
+{
+}
+
+/**
+ Returns the current value of the SMM register for the specified CPU.
+ If the SMM register is not supported, then 0 is returned.
+
+ @param[in] CpuIndex The index of the CPU to read the SMM register. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] RegName Identifies the SMM register to read.
+
+ @return The value of the SMM register specified by RegName from the CPU
+ specified by CpuIndex.
+**/
+UINT64
+EFIAPI
+SmmCpuFeaturesGetSmmRegister (
+ IN UINTN CpuIndex,
+ IN SMM_REG_NAME RegName
+ )
+{
+ return 0;
+}
+
+/**
+ Sets the value of an SMM register on a specified CPU.
+ If the SMM register is not supported, then no action is performed.
+
+ @param[in] CpuIndex The index of the CPU to write the SMM register. The
+ value must be between 0 and the NumberOfCpus field in
+ the System Management System Table (SMST).
+ @param[in] RegName Identifies the SMM register to write.
+ registers are read-only.
+ @param[in] Value The value to write to the SMM register.
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesSetSmmRegister (
+ IN UINTN CpuIndex,
+ IN SMM_REG_NAME RegName,
+ IN UINT64 Value
+ )
+{
+}
+
+/**
+ Check to see if an SMM register is supported by a specified CPU.
+
+ @param[in] CpuIndex The index of the CPU to check for SMM register support.
+ The value must be between 0 and the NumberOfCpus field
+ in the System Management System Table (SMST).
+ @param[in] RegName Identifies the SMM register to check for support.
+
+ @retval TRUE The SMM register specified by RegName is supported by the CPU
+ specified by CpuIndex.
+ @retval FALSE The SMM register specified by RegName is not supported by the
+ CPU specified by CpuIndex.
+**/
+BOOLEAN
+EFIAPI
+SmmCpuFeaturesIsSmmRegisterSupported (
+ IN UINTN CpuIndex,
+ IN SMM_REG_NAME RegName
+ )
+{
+ return FALSE;
+}
+
+/**
+ This function is hook point called after the gEfiSmmReadyToLockProtocolGuid
+ notification is completely processed.
+**/
+VOID
+EFIAPI
+SmmCpuFeaturesCompleteSmmReadyToLock (
+ VOID
+ )
+{
+}
--
2.25.1