* [edk2-devel] [edk2-platforms 1/3] AmdPlatformPkg: Removes unused gBoardBdsBootFromDevicePathProtocolGuid
2024-05-28 14:07 [edk2-devel] [edk2-platforms 0/3] AmdPlatformPkg: SmbiosDxe and SPI supporting libraries Abdul Lateef Attar via groups.io
@ 2024-05-28 14:07 ` Abdul Lateef Attar via groups.io
2024-05-29 8:56 ` Chang, Abner via groups.io
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 2/3] AmdPlatformPkg: Implements SmmCorePlatformHookLib library Abdul Lateef Attar via groups.io
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 3/3] AmdPlatformPkg: Adds SPI smm core platform hook Abdul Lateef Attar via groups.io
2 siblings, 1 reply; 7+ messages in thread
From: Abdul Lateef Attar via groups.io @ 2024-05-28 14:07 UTC (permalink / raw)
To: devel; +Cc: Abdul Lateef Attar, Abner Chang, Paul Grimes
Removes unused gBoardBdsBootFromDevicePathProtocolGuid protocol,
and its corresponding code changes.
Adds missing Pcd/SmbiosPcd.h file.
Cc: Abner Chang <abner.chang@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
.../AmdPlatformPkg/Include/Pcd/SmbiosPcd.h | 58 ++++++++
.../SmbiosCommonDxe/DefaultLomDevicePath.c | 130 ------------------
.../Universal/SmbiosCommonDxe/SmbiosCommon.h | 12 --
.../SmbiosCommonDxe/SmbiosCommonDxe.inf | 3 -
.../SmbiosCommonDxe/SmbiosCommonEntryPoint.c | 2 -
5 files changed, 58 insertions(+), 147 deletions(-)
create mode 100644 Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h
delete mode 100644 Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLomDevicePath.c
diff --git a/Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h b/Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h
new file mode 100644
index 0000000000..2dd0480df9
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h
@@ -0,0 +1,58 @@
+/** @file
+ Miscellaneous smbios data structures.
+
+ Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef AMD_SMBIOS_PCD_H_
+#define AMD_SMBIOS_PCD_H_
+
+#include <IndustryStandard/SmBios.h>
+#include <Uefi.h>
+
+#define AMD_SMBIOS_TYPE8_MAX_PORT_CONNETORS 16
+#define AMD_SMBIOS_TYPE41_MAX_ONBOARD_DEVICES 16
+
+typedef struct {
+ CHAR8 IntDesignatorStr[SMBIOS_STRING_MAX_LENGTH];
+ CHAR8 ExtDesignatorStr[SMBIOS_STRING_MAX_LENGTH];
+} PORT_CONNECTOR_STR;
+
+//
+// AMD SMBIOS type 8 record structure.
+//
+typedef struct {
+ SMBIOS_TABLE_TYPE8 Type8Data;
+ PORT_CONNECTOR_STR DesinatorStr;
+} SMBIOS_PORT_CONNECTOR_RECORD;
+
+//
+// AMD SMBIOS type 8 record structure array.
+//
+typedef struct {
+ SMBIOS_PORT_CONNECTOR_RECORD SmbiosPortConnectorRecords[AMD_SMBIOS_TYPE8_MAX_PORT_CONNETORS];
+} SMBIOS_PORT_CONNECTOR_RECORD_ARRAY;
+
+//
+// AMD SMBIOS type 41 record structure
+//
+typedef struct {
+ SMBIOS_TABLE_STRING ReferenceDesignation;
+ UINT8 DeviceType;
+ UINT8 DeviceEnabled;
+ UINT8 DeviceTypeInstance;
+ UINT16 VendorId;
+ UINT16 DeviceId;
+ CHAR8 RefDesignationStr[SMBIOS_STRING_MAX_LENGTH];
+} SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD;
+
+//
+// AMD SMBIOS type 41 record structure array.
+//
+typedef struct {
+ SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD SmbiosOnboardDevExtInfos[AMD_SMBIOS_TYPE41_MAX_ONBOARD_DEVICES];
+} SMBIOS_ONBOARD_DEV_EXT_INFO_ARRAY;
+
+#endif // AMD_SMBIOS_PCD_H_
diff --git a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLomDevicePath.c b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLomDevicePath.c
deleted file mode 100644
index 92c7aa5e07..0000000000
--- a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLomDevicePath.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/** @file
- This file contains the implementation of the DefaultLomDevicePath protocol.
- The DefaultLomDevicePath protocol is used to identify the default LOM device
- path for the system. The protocol is installed by the SmbiosCommonDxe driver
- and is used by the BDS to identify the default LOM device path for the system.
-
- Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
-
- SPDX-License-Identifier: BSD-2-Clause-Patent
-**/
-
-#include <Library/IoLib.h>
-#include <Library/PciLib.h>
-#include <Protocol/PciEnumerationComplete.h>
-#include <IndustryStandard/Ipmi.h>
-#include <Bus/Pci/PciBusDxe/PciBus.h>
-#include <Pcd/SmbiosPcd.h>
-#include <Library/PciSegmentLib.h>
-#include <Pcd/SmbiosPcd.h>
-#include "SmbiosCommon.h"
-#include <IndustryStandard/Ipmi.h>
-#include <Library/BoardBdsHookLib.h>
-
-EFI_HANDLE mBoardBdsHandle = NULL;
-BOARD_BDS_BOOT_FROM_DEVICE_PATH_PROTOCOL mBootDevicePathProtocol;
-
-/**
- Find the Lan-On-Motherboard device path. Installs BOARD_BDS_BOOT_FROM_DEVICE_PATH_PROTOCOL
- with the LOM device path protocol
-
- @retval EFI NOT_FOUND LOM device path is not found
- @retval EFI_SUCCESS LOM device path found
-**/
-EFI_STATUS
-EFIAPI
-InstallLomDevicePath (
- )
-{
- SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD *DevExtInfoRecord;
- EFI_STATUS Status;
- EFI_HANDLE *PciHandles;
- UINTN PciHandlesSize;
- UINTN Index;
- EFI_PCI_IO_PROTOCOL *PciProtocol;
- PCI_IO_DEVICE *PciIoDevice;
- UINT8 NumberOfDevices;
- UINT8 DevIdx;
- UINTN SegmentNumber;
- UINTN BusNumber;
- UINTN DeviceNumber;
- UINTN FunctionNumber;
-
- NumberOfDevices = PcdGet8 (PcdAmdSmbiosType41Number);
- DevExtInfoRecord = (SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD *)PcdGetPtr (PcdAmdSmbiosType41);
-
- // No device entries found
- if (NumberOfDevices == 0) {
- DEBUG ((DEBUG_INFO, "No onboard devices found.\n"));
- return EFI_NOT_FOUND;
- }
-
- // search through present on board devices, look for onboard ethernet
- for (DevIdx = 0; DevIdx < NumberOfDevices; DevIdx++) {
- if (AsciiStrCmp (DevExtInfoRecord->RefDesignationStr, "Onboard Ethernet") == 0) {
- break;
- }
-
- DevExtInfoRecord++;
- }
-
- // edge case, no Onboard Ethernet designator
- if (AsciiStrCmp (DevExtInfoRecord->RefDesignationStr, "Onboard Ethernet") != 0) {
- DEBUG ((DEBUG_INFO, "No Onboard ethernet SMBIOS designator found!\n"));
- return EFI_NOT_FOUND;
- }
-
- Status = gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiPciIoProtocolGuid,
- NULL,
- &PciHandlesSize,
- &PciHandles
- );
-
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "Can't locate gEfiPciIoProtocolGuid Protocol: Status = %r\n\n", Status));
- return Status;
- }
-
- for (Index = 0; Index < PciHandlesSize; Index++) {
- Status = gBS->HandleProtocol (
- PciHandles[Index],
- &gEfiPciIoProtocolGuid,
- (VOID **)&PciProtocol
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "ERROR - Status = %r when locating PciIoProtocol\n", Status));
- continue;
- }
-
- PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciProtocol);
- Status = PciIoDevice->PciIo.GetLocation (&PciIoDevice->PciIo, &SegmentNumber, &BusNumber, &DeviceNumber, &FunctionNumber);
-
- if ((PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS (SegmentNumber, BusNumber, DeviceNumber, FunctionNumber, 2)) == DevExtInfoRecord->DeviceId) &&
- (PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS (SegmentNumber, BusNumber, DeviceNumber, FunctionNumber, 0)) == DevExtInfoRecord->VendorId))
- {
- // Making Lan0 default for systems with two LANs
- if (FunctionNumber == 0) {
- DEBUG ((DEBUG_INFO, "Found Onboard Device with DeviceID=0x%X, VendorID=0x%X\n", DevExtInfoRecord->DeviceId, DevExtInfoRecord->VendorId));
- Status = EFI_SUCCESS;
- // install device path protocol here
- mBootDevicePathProtocol.Device = PciIoDevice->DevicePath;
- mBootDevicePathProtocol.IpmiBootDeviceSelectorType = IPMI_BOOT_DEVICE_SELECTOR_PXE;
- Status = gBS->InstallProtocolInterface (
- &mBoardBdsHandle,
- &gBoardBdsBootFromDevicePathProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &mBootDevicePathProtocol
- );
- if (!EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "BoardBdsBootFromDevicePathProtocol installed successfully\n"));
- }
-
- break;
- }
- }
- }
-
- return Status;
-}
diff --git a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommon.h b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommon.h
index 770053e42b..0ea3434916 100644
--- a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommon.h
+++ b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommon.h
@@ -186,18 +186,6 @@ OnboardDevExtInfoFunction (
IN EFI_SMBIOS_PROTOCOL *Smbios
);
-/**
- Find the Lan-On-Motherboard device path. Installs BOARD_BDS_BOOT_FROM_DEVICE_PATH_PROTOCOL
- with the LOM device path protocol
-
- @retval EFI NOT_FOUND LOM device path is not found
- @retval EFI_SUCCESS LOM device path found
-**/
-EFI_STATUS
-EFIAPI
-InstallLomDevicePath (
- );
-
typedef
EFI_STATUS
(EFIAPI EFI_COMMON_SMBIOS_DATA_FUNCTION)(
diff --git a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonDxe.inf b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonDxe.inf
index fc407c3bec..548a6b0af4 100644
--- a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonDxe.inf
+++ b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonDxe.inf
@@ -30,13 +30,11 @@
Type12SystemCfgOptionsFunction.c
Type13BiosLanguageInfoFunction.c
Type41OnboardDevExtInfoFunction.c
- DefaultLomDevicePath.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
AmdPlatformPkg/AmdPlatformPkg.dec
- BoardModulePkg/BoardModulePkg.dec
[LibraryClasses]
BaseLib
@@ -54,7 +52,6 @@
gEfiSmbiosProtocolGuid ## PROTOCOL ALWAYS_CONSUMED
gEfiPciEnumerationCompleteProtocolGuid ## CONSUMES
gEfiPciIoProtocolGuid ## CONSUMES
- gBoardBdsBootFromDevicePathProtocolGuid ## PRODUCES
[Pcd]
gAmdPlatformPkgTokenSpaceGuid.PcdAmdSmbiosType8 ## CONSUMES
diff --git a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonEntryPoint.c b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonEntryPoint.c
index eaa66be454..eb3635ca34 100644
--- a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonEntryPoint.c
+++ b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonEntryPoint.c
@@ -80,8 +80,6 @@ OnPciEnumerationComplete (
EfiStatus
));
}
-
- EfiStatus = InstallLomDevicePath ();
}
/**
--
2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119305): https://edk2.groups.io/g/devel/message/119305
Mute This Topic: https://groups.io/mt/106349078/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [edk2-devel] [edk2-platforms 1/3] AmdPlatformPkg: Removes unused gBoardBdsBootFromDevicePathProtocolGuid
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 1/3] AmdPlatformPkg: Removes unused gBoardBdsBootFromDevicePathProtocolGuid Abdul Lateef Attar via groups.io
@ 2024-05-29 8:56 ` Chang, Abner via groups.io
0 siblings, 0 replies; 7+ messages in thread
From: Chang, Abner via groups.io @ 2024-05-29 8:56 UTC (permalink / raw)
To: Attar, AbdulLateef (Abdul Lateef), devel@edk2.groups.io
Cc: Attar, AbdulLateef (Abdul Lateef), Grimes, Paul
[AMD Official Use Only - AMD Internal Distribution Only]
Reviewed-by: Abner Chang <abner.chang@amd.com>
> -----Original Message-----
> From: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
> Sent: Tuesday, May 28, 2024 10:08 PM
> To: devel@edk2.groups.io
> Cc: Attar, AbdulLateef (Abdul Lateef) <AbdulLateef.Attar@amd.com>; Chang,
> Abner <Abner.Chang@amd.com>; Grimes, Paul <Paul.Grimes@amd.com>
> Subject: [edk2-platforms 1/3] AmdPlatformPkg: Removes unused
> gBoardBdsBootFromDevicePathProtocolGuid
>
> Removes unused gBoardBdsBootFromDevicePathProtocolGuid protocol,
> and its corresponding code changes.
> Adds missing Pcd/SmbiosPcd.h file.
>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Paul Grimes <paul.grimes@amd.com>
> Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
> ---
> .../AmdPlatformPkg/Include/Pcd/SmbiosPcd.h | 58 ++++++++
> .../SmbiosCommonDxe/DefaultLomDevicePath.c | 130 ------------------
> .../Universal/SmbiosCommonDxe/SmbiosCommon.h | 12 --
> .../SmbiosCommonDxe/SmbiosCommonDxe.inf | 3 -
> .../SmbiosCommonDxe/SmbiosCommonEntryPoint.c | 2 -
> 5 files changed, 58 insertions(+), 147 deletions(-)
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h
> delete mode 100644
> Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLom
> DevicePath.c
>
> diff --git a/Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h
> b/Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h
> new file mode 100644
> index 0000000000..2dd0480df9
> --- /dev/null
> +++ b/Platform/AMD/AmdPlatformPkg/Include/Pcd/SmbiosPcd.h
> @@ -0,0 +1,58 @@
> +/** @file
> + Miscellaneous smbios data structures.
> +
> + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +
> +#ifndef AMD_SMBIOS_PCD_H_
> +#define AMD_SMBIOS_PCD_H_
> +
> +#include <IndustryStandard/SmBios.h>
> +#include <Uefi.h>
> +
> +#define AMD_SMBIOS_TYPE8_MAX_PORT_CONNETORS 16
> +#define AMD_SMBIOS_TYPE41_MAX_ONBOARD_DEVICES 16
> +
> +typedef struct {
> + CHAR8 IntDesignatorStr[SMBIOS_STRING_MAX_LENGTH];
> + CHAR8 ExtDesignatorStr[SMBIOS_STRING_MAX_LENGTH];
> +} PORT_CONNECTOR_STR;
> +
> +//
> +// AMD SMBIOS type 8 record structure.
> +//
> +typedef struct {
> + SMBIOS_TABLE_TYPE8 Type8Data;
> + PORT_CONNECTOR_STR DesinatorStr;
> +} SMBIOS_PORT_CONNECTOR_RECORD;
> +
> +//
> +// AMD SMBIOS type 8 record structure array.
> +//
> +typedef struct {
> + SMBIOS_PORT_CONNECTOR_RECORD
> SmbiosPortConnectorRecords[AMD_SMBIOS_TYPE8_MAX_PORT_CONNETOR
> S];
> +} SMBIOS_PORT_CONNECTOR_RECORD_ARRAY;
> +
> +//
> +// AMD SMBIOS type 41 record structure
> +//
> +typedef struct {
> + SMBIOS_TABLE_STRING ReferenceDesignation;
> + UINT8 DeviceType;
> + UINT8 DeviceEnabled;
> + UINT8 DeviceTypeInstance;
> + UINT16 VendorId;
> + UINT16 DeviceId;
> + CHAR8 RefDesignationStr[SMBIOS_STRING_MAX_LENGTH];
> +} SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD;
> +
> +//
> +// AMD SMBIOS type 41 record structure array.
> +//
> +typedef struct {
> + SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD
> SmbiosOnboardDevExtInfos[AMD_SMBIOS_TYPE41_MAX_ONBOARD_DEVIC
> ES];
> +} SMBIOS_ONBOARD_DEV_EXT_INFO_ARRAY;
> +
> +#endif // AMD_SMBIOS_PCD_H_
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLo
> mDevicePath.c
> b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLo
> mDevicePath.c
> deleted file mode 100644
> index 92c7aa5e07..0000000000
> ---
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/DefaultLo
> mDevicePath.c
> +++ /dev/null
> @@ -1,130 +0,0 @@
> -/** @file
> - This file contains the implementation of the DefaultLomDevicePath protocol.
> - The DefaultLomDevicePath protocol is used to identify the default LOM
> device
> - path for the system. The protocol is installed by the SmbiosCommonDxe
> driver
> - and is used by the BDS to identify the default LOM device path for the
> system.
> -
> - Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> -
> - SPDX-License-Identifier: BSD-2-Clause-Patent
> -**/
> -
> -#include <Library/IoLib.h>
> -#include <Library/PciLib.h>
> -#include <Protocol/PciEnumerationComplete.h>
> -#include <IndustryStandard/Ipmi.h>
> -#include <Bus/Pci/PciBusDxe/PciBus.h>
> -#include <Pcd/SmbiosPcd.h>
> -#include <Library/PciSegmentLib.h>
> -#include <Pcd/SmbiosPcd.h>
> -#include "SmbiosCommon.h"
> -#include <IndustryStandard/Ipmi.h>
> -#include <Library/BoardBdsHookLib.h>
> -
> -EFI_HANDLE mBoardBdsHandle = NULL;
> -BOARD_BDS_BOOT_FROM_DEVICE_PATH_PROTOCOL
> mBootDevicePathProtocol;
> -
> -/**
> - Find the Lan-On-Motherboard device path. Installs
> BOARD_BDS_BOOT_FROM_DEVICE_PATH_PROTOCOL
> - with the LOM device path protocol
> -
> - @retval EFI NOT_FOUND LOM device path is not found
> - @retval EFI_SUCCESS LOM device path found
> -**/
> -EFI_STATUS
> -EFIAPI
> -InstallLomDevicePath (
> - )
> -{
> - SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD *DevExtInfoRecord;
> - EFI_STATUS Status;
> - EFI_HANDLE *PciHandles;
> - UINTN PciHandlesSize;
> - UINTN Index;
> - EFI_PCI_IO_PROTOCOL *PciProtocol;
> - PCI_IO_DEVICE *PciIoDevice;
> - UINT8 NumberOfDevices;
> - UINT8 DevIdx;
> - UINTN SegmentNumber;
> - UINTN BusNumber;
> - UINTN DeviceNumber;
> - UINTN FunctionNumber;
> -
> - NumberOfDevices = PcdGet8 (PcdAmdSmbiosType41Number);
> - DevExtInfoRecord = (SMBIOS_ONBOARD_DEV_EXT_INFO_RECORD
> *)PcdGetPtr (PcdAmdSmbiosType41);
> -
> - // No device entries found
> - if (NumberOfDevices == 0) {
> - DEBUG ((DEBUG_INFO, "No onboard devices found.\n"));
> - return EFI_NOT_FOUND;
> - }
> -
> - // search through present on board devices, look for onboard ethernet
> - for (DevIdx = 0; DevIdx < NumberOfDevices; DevIdx++) {
> - if (AsciiStrCmp (DevExtInfoRecord->RefDesignationStr, "Onboard
> Ethernet") == 0) {
> - break;
> - }
> -
> - DevExtInfoRecord++;
> - }
> -
> - // edge case, no Onboard Ethernet designator
> - if (AsciiStrCmp (DevExtInfoRecord->RefDesignationStr, "Onboard
> Ethernet") != 0) {
> - DEBUG ((DEBUG_INFO, "No Onboard ethernet SMBIOS designator
> found!\n"));
> - return EFI_NOT_FOUND;
> - }
> -
> - Status = gBS->LocateHandleBuffer (
> - ByProtocol,
> - &gEfiPciIoProtocolGuid,
> - NULL,
> - &PciHandlesSize,
> - &PciHandles
> - );
> -
> - if (EFI_ERROR (Status)) {
> - DEBUG ((DEBUG_INFO, "Can't locate gEfiPciIoProtocolGuid Protocol: Status
> = %r\n\n", Status));
> - return Status;
> - }
> -
> - for (Index = 0; Index < PciHandlesSize; Index++) {
> - Status = gBS->HandleProtocol (
> - PciHandles[Index],
> - &gEfiPciIoProtocolGuid,
> - (VOID **)&PciProtocol
> - );
> - if (EFI_ERROR (Status)) {
> - DEBUG ((DEBUG_INFO, "ERROR - Status = %r when locating
> PciIoProtocol\n", Status));
> - continue;
> - }
> -
> - PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciProtocol);
> - Status = PciIoDevice->PciIo.GetLocation (&PciIoDevice->PciIo,
> &SegmentNumber, &BusNumber, &DeviceNumber, &FunctionNumber);
> -
> - if ((PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS (SegmentNumber,
> BusNumber, DeviceNumber, FunctionNumber, 2)) == DevExtInfoRecord-
> >DeviceId) &&
> - (PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS (SegmentNumber,
> BusNumber, DeviceNumber, FunctionNumber, 0)) == DevExtInfoRecord-
> >VendorId))
> - {
> - // Making Lan0 default for systems with two LANs
> - if (FunctionNumber == 0) {
> - DEBUG ((DEBUG_INFO, "Found Onboard Device with DeviceID=0x%X,
> VendorID=0x%X\n", DevExtInfoRecord->DeviceId, DevExtInfoRecord-
> >VendorId));
> - Status = EFI_SUCCESS;
> - // install device path protocol here
> - mBootDevicePathProtocol.Device = PciIoDevice->DevicePath;
> - mBootDevicePathProtocol.IpmiBootDeviceSelectorType =
> IPMI_BOOT_DEVICE_SELECTOR_PXE;
> - Status = gBS->InstallProtocolInterface (
> - &mBoardBdsHandle,
> -
> &gBoardBdsBootFromDevicePathProtocolGuid,
> - EFI_NATIVE_INTERFACE,
> - &mBootDevicePathProtocol
> - );
> - if (!EFI_ERROR (Status)) {
> - DEBUG ((DEBUG_INFO, "BoardBdsBootFromDevicePathProtocol
> installed successfully\n"));
> - }
> -
> - break;
> - }
> - }
> - }
> -
> - return Status;
> -}
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmon.h
> b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmon.h
> index 770053e42b..0ea3434916 100644
> ---
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmon.h
> +++
> b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmon.h
> @@ -186,18 +186,6 @@ OnboardDevExtInfoFunction (
> IN EFI_SMBIOS_PROTOCOL *Smbios
> );
>
> -/**
> - Find the Lan-On-Motherboard device path. Installs
> BOARD_BDS_BOOT_FROM_DEVICE_PATH_PROTOCOL
> - with the LOM device path protocol
> -
> - @retval EFI NOT_FOUND LOM device path is not found
> - @retval EFI_SUCCESS LOM device path found
> -**/
> -EFI_STATUS
> -EFIAPI
> -InstallLomDevicePath (
> - );
> -
> typedef
> EFI_STATUS
> (EFIAPI EFI_COMMON_SMBIOS_DATA_FUNCTION)(
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonDxe.inf
> b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonDxe.inf
> index fc407c3bec..548a6b0af4 100644
> ---
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonDxe.inf
> +++
> b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonDxe.inf
> @@ -30,13 +30,11 @@
> Type12SystemCfgOptionsFunction.c
> Type13BiosLanguageInfoFunction.c
> Type41OnboardDevExtInfoFunction.c
> - DefaultLomDevicePath.c
>
> [Packages]
> MdePkg/MdePkg.dec
> MdeModulePkg/MdeModulePkg.dec
> AmdPlatformPkg/AmdPlatformPkg.dec
> - BoardModulePkg/BoardModulePkg.dec
>
> [LibraryClasses]
> BaseLib
> @@ -54,7 +52,6 @@
> gEfiSmbiosProtocolGuid ## PROTOCOL ALWAYS_CONSUMED
> gEfiPciEnumerationCompleteProtocolGuid ## CONSUMES
> gEfiPciIoProtocolGuid ## CONSUMES
> - gBoardBdsBootFromDevicePathProtocolGuid ## PRODUCES
>
> [Pcd]
> gAmdPlatformPkgTokenSpaceGuid.PcdAmdSmbiosType8 ##
> CONSUMES
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonEntryPoint.c
> b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonEntryPoint.c
> index eaa66be454..eb3635ca34 100644
> ---
> a/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonEntryPoint.c
> +++
> b/Platform/AMD/AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCo
> mmonEntryPoint.c
> @@ -80,8 +80,6 @@ OnPciEnumerationComplete (
> EfiStatus
> ));
> }
> -
> - EfiStatus = InstallLomDevicePath ();
> }
>
> /**
> --
> 2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119333): https://edk2.groups.io/g/devel/message/119333
Mute This Topic: https://groups.io/mt/106349078/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 7+ messages in thread
* [edk2-devel] [edk2-platforms 2/3] AmdPlatformPkg: Implements SmmCorePlatformHookLib library
2024-05-28 14:07 [edk2-devel] [edk2-platforms 0/3] AmdPlatformPkg: SmbiosDxe and SPI supporting libraries Abdul Lateef Attar via groups.io
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 1/3] AmdPlatformPkg: Removes unused gBoardBdsBootFromDevicePathProtocolGuid Abdul Lateef Attar via groups.io
@ 2024-05-28 14:07 ` Abdul Lateef Attar via groups.io
2024-05-29 8:57 ` Chang, Abner via groups.io
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 3/3] AmdPlatformPkg: Adds SPI smm core platform hook Abdul Lateef Attar via groups.io
2 siblings, 1 reply; 7+ messages in thread
From: Abdul Lateef Attar via groups.io @ 2024-05-28 14:07 UTC (permalink / raw)
To: devel; +Cc: Abdul Lateef Attar, Abner Chang, Paul Grimes
Implements SmmCorePlatformHookLib library for AMD platform.
Cc: Abner Chang <abner.chang@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
.../AMD/AmdPlatformPkg/AmdPlatformPkg.dec | 5 +
.../AMD/AmdPlatformPkg/AmdPlatformPkg.dsc | 6 +
.../Library/AmdSmmCorePlatformHookLib.h | 68 +++++++
.../SmmCorePlatformHookLib.c | 169 ++++++++++++++++++
.../SmmCorePlatformHookLib.inf | 39 ++++
.../SmmCorePlatformHookLib.uni | 11 ++
6 files changed, 298 insertions(+)
create mode 100644 Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHookLib.h
create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.c
create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf
create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.uni
diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
index 106820dc85..3020e628a3 100644
--- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
+++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
@@ -21,6 +21,11 @@
## @libraryclass Defines a get/set interface for platform specific data.
PlatformSocLib|Include/Library/AmdPlatformSocLib.h
+ ## @libraryclass AMD SMM core platform hook library
+ # Provide the functions to register hook before and
+ # after SMM dispatcher.
+ SmmCorePlatformHookLib|Include/Library/AmdSmmCorePlatformHookLib.h
+
[Guids]
gAmdPlatformPkgTokenSpaceGuid = { 0x663DE733, 0x70E0, 0x4D37, { 0xBB, 0x30, 0x7D, 0x9E, 0xAF, 0x9B, 0xDA, 0xE9 }}
diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
index d11d3594e3..482e6f2f30 100644
--- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
+++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
@@ -62,6 +62,9 @@
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
PlatformSocLib|AmdPlatformPkg/Library/DxePlatformSocLib/DxePlatformSocLibNull.inf
+[LibraryClasses.common.SMM_CORE]
+ SmmCorePlatformHookLib|AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf
+
[Components]
AmdPlatformPkg/Library/BaseAlwaysFalseDepexLib/BaseAlwaysFalseDepexLib.inf
AmdPlatformPkg/Library/DxePlatformSocLib/DxePlatformSocLibNull.inf
@@ -73,3 +76,6 @@
AmdPlatformPkg/Universal/LogoDxe/LogoDxe.inf # Server platfrom Bitmap logo driver
AmdPlatformPkg/Universal/LogoDxe/S3LogoDxe.inf
AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonDxe.inf
+
+[Components.common.SMM_CORE]
+ AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf
diff --git a/Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHookLib.h b/Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHookLib.h
new file mode 100644
index 0000000000..6ae76920b4
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHookLib.h
@@ -0,0 +1,68 @@
+/** @file
+ AMD Smm Core Platform Hook Library
+
+ Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef AMD_SMM_CORE_PLATFORM_HOOK_LIB_
+#define AMD_SMM_CORE_PLATFORM_HOOK_LIB_
+
+/**
+ This is the prototype of SMM Dispatcher hook before.
+
+ @retval EFI_STATUS
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *AMD_SMM_DISPATCH_HOOK_BEFORE)(
+ VOID
+ );
+
+/**
+ This is the prototype of SMM Dispatcher after before.
+
+ @retval EFI_STATUS
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *AMD_SMM_DISPATCH_HOOK_AFTER)(
+ VOID
+ );
+
+typedef UINT32 AMD_SMM_DISPATCH_HOOK_PRIORITY;
+
+///
+/// This is the structure of the SMM Dispatcher hook record
+///
+typedef struct {
+ LIST_ENTRY NextList; ///< Point to next AMD_SMM_DISPATCH_HOOK.
+ AMD_SMM_DISPATCH_HOOK_BEFORE AmdSmmDispatchHookBefore; ///< The hook before function.
+ AMD_SMM_DISPATCH_HOOK_AFTER AmdSmmDispatchHookAfter; ///< The hook after function.
+ AMD_SMM_DISPATCH_HOOK_PRIORITY Priority; ///< The priority of this hook instance.
+ ///< Priority could be implemented for
+ ///< future usage.
+} AMD_SMM_DISPATCH_HOOK;
+
+/**
+ Register a SMM dispatcher hook.
+
+ @param[in] SmmDispatchHookBefore Function hook to SMM Dispatch before.
+ @param[in] SmmDispatchHookAfter Function hook to SMM Dispatch after.
+ @param[in] Priority The priority to execute the hook.
+
+ @retval EFI_SUCCESS The hook is registered successfully.
+
+**/
+EFI_STATUS
+RegisterSmmDispatcherHook (
+ IN AMD_SMM_DISPATCH_HOOK_BEFORE SmmDispatchHookBefore OPTIONAL,
+ IN AMD_SMM_DISPATCH_HOOK_AFTER SmmDispatchHookAfter OPTIONAL,
+ IN AMD_SMM_DISPATCH_HOOK_PRIORITY Priority
+ );
+
+#endif // AMD_SMM_CORE_PLATFORM_HOOK_LIB_
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.c b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.c
new file mode 100644
index 0000000000..ad6a40749f
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.c
@@ -0,0 +1,169 @@
+/** @file
+ AMD SMM core hook library
+
+ Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiSmm.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/SmmCorePlatformHookLib.h>
+#include <Library/AmdSmmCorePlatformHookLib.h>
+
+LIST_ENTRY *RegisteredHookPtr = NULL;
+LIST_ENTRY RegisteredHook;
+
+/**
+ Register a SMM dispatcher hook.
+
+ @param[in] SmmDispatchHookBefore Function hook to SMM Dispatch before.
+ @param[in] SmmDispatchHookAfter Function hook to SMM Dispatch after.
+ @param[in] Priority The priority to execute the hook.
+
+ @retval EFI_SUCCESS The hook is registered successfully.
+
+**/
+EFI_STATUS
+RegisterSmmDispatcherHook (
+ IN AMD_SMM_DISPATCH_HOOK_BEFORE SmmDispatchHookBefore OPTIONAL,
+ IN AMD_SMM_DISPATCH_HOOK_AFTER SmmDispatchHookAfter OPTIONAL,
+ IN AMD_SMM_DISPATCH_HOOK_PRIORITY Priority
+ )
+{
+ AMD_SMM_DISPATCH_HOOK *ThisHook;
+
+ if ((SmmDispatchHookBefore == NULL) && (SmmDispatchHookAfter == NULL)) {
+ DEBUG ((DEBUG_ERROR, "%a: Both SmmDispatchHookBefore and SmmDispatchHookAfter are NULL.\n", __func__));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (RegisteredHookPtr == NULL) {
+ InitializeListHead (&RegisteredHook);
+ RegisteredHookPtr = &RegisteredHook;
+ }
+
+ ThisHook = (AMD_SMM_DISPATCH_HOOK *)AllocateZeroPool (sizeof (AMD_SMM_DISPATCH_HOOK));
+ if (ThisHook == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Insufficient memory for AMD_SMM_DISPATCH_HOOK.\n", __func__));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ InitializeListHead (&ThisHook->NextList);
+ ThisHook->AmdSmmDispatchHookBefore = SmmDispatchHookBefore;
+ ThisHook->AmdSmmDispatchHookAfter = SmmDispatchHookAfter;
+ ThisHook->Priority = Priority;
+ InsertHeadList (&RegisteredHook, &ThisHook->NextList);
+ DEBUG ((DEBUG_VERBOSE, "%a: New AMD_SMM_DISPATCH_HOOK is inserted.\n", __func__));
+ return EFI_SUCCESS;
+}
+
+/**
+ Performs platform specific tasks before invoking registered SMI handlers.
+
+ This function performs platform specific tasks before invoking registered SMI handlers.
+
+ @retval EFI_SUCCESS The platform hook completes successfully.
+ @retval Other values The platform hook cannot complete due to some error.
+
+**/
+EFI_STATUS
+EFIAPI
+PlatformHookBeforeSmmDispatch (
+ VOID
+ )
+{
+ AMD_SMM_DISPATCH_HOOK *ThisHook;
+
+ if (IsListEmpty (&RegisteredHook)) {
+ return EFI_NOT_FOUND;
+ }
+
+ ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetFirstNode (&RegisteredHook);
+ while (TRUE) {
+ //
+ // We can handle priority in the future when needed.
+ //
+ if (ThisHook->AmdSmmDispatchHookBefore != NULL) {
+ ThisHook->AmdSmmDispatchHookBefore ();
+ }
+
+ if (IsNodeAtEnd (&RegisteredHook, &ThisHook->NextList)) {
+ break;
+ }
+
+ ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetNextNode (&RegisteredHook, &ThisHook->NextList);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Performs platform specific tasks after invoking registered SMI handlers.
+
+ This function performs platform specific tasks after invoking registered SMI handlers.
+
+ @retval EFI_SUCCESS The platform hook completes successfully.
+ @retval Other values The platform hook cannot complete due to some error.
+
+**/
+EFI_STATUS
+EFIAPI
+PlatformHookAfterSmmDispatch (
+ VOID
+ )
+{
+ AMD_SMM_DISPATCH_HOOK *ThisHook;
+
+ if (IsListEmpty (&RegisteredHook)) {
+ return EFI_NOT_FOUND;
+ }
+
+ ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetFirstNode (&RegisteredHook);
+ while (TRUE) {
+ //
+ // We can handle priority in the future when needed.
+ //
+ if (ThisHook->AmdSmmDispatchHookAfter != NULL) {
+ ThisHook->AmdSmmDispatchHookAfter ();
+ }
+
+ if (IsNodeAtEnd (&RegisteredHook, &ThisHook->NextList)) {
+ break;
+ }
+
+ ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetNextNode (&RegisteredHook, &ThisHook->NextList);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Constructor for SmmLockBox library.
+ This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+ @param[in] ImageHandle Image handle of this driver.
+ @param[in] SystemTable A Pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS
+ @return Others Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+SmmCorePlatformHookConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ if (RegisteredHookPtr == NULL) {
+ InitializeListHead (&RegisteredHook);
+ RegisteredHookPtr = &RegisteredHook;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf
new file mode 100644
index 0000000000..a79fc56077
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf
@@ -0,0 +1,39 @@
+## @file
+# INF of SMM Core hook library INF file.
+#
+# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SmmCorePlatformHookLib
+ MODULE_UNI_FILE = SmmCorePlatformHookLib.uni
+ FILE_GUID = 70ACB6CA-80D2-46a9-A0EB-0C83DFC476C9
+ MODULE_TYPE = SMM_CORE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x0001000A
+ LIBRARY_CLASS = SmmCorePlatformHookLib|SMM_CORE
+ CONSTRUCTOR = SmmCorePlatformHookConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ SmmCorePlatformHookLib.c
+
+[Packages]
+ AmdPlatformPkg/AmdPlatformPkg.dec
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ MemoryAllocationLib
+ SmmServicesTableLib
+
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.uni b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.uni
new file mode 100644
index 0000000000..0b326c159b
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.uni
@@ -0,0 +1,11 @@
+## @file
+# UNI file of SMM Core hook library module
+#
+# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+#string STR_MODULE_ABSTRACT #language en-US "SMM Core Platform Hook Library instance"
+
+#string STR_MODULE_DESCRIPTION #language en-US "SMM Core Platform Hook Library instance"
--
2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119307): https://edk2.groups.io/g/devel/message/119307
Mute This Topic: https://groups.io/mt/106349081/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [edk2-devel] [edk2-platforms 2/3] AmdPlatformPkg: Implements SmmCorePlatformHookLib library
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 2/3] AmdPlatformPkg: Implements SmmCorePlatformHookLib library Abdul Lateef Attar via groups.io
@ 2024-05-29 8:57 ` Chang, Abner via groups.io
0 siblings, 0 replies; 7+ messages in thread
From: Chang, Abner via groups.io @ 2024-05-29 8:57 UTC (permalink / raw)
To: Attar, AbdulLateef (Abdul Lateef), devel@edk2.groups.io
Cc: Attar, AbdulLateef (Abdul Lateef), Grimes, Paul
[AMD Official Use Only - AMD Internal Distribution Only]
Reviewed-by: Abner Chang <abner.chang@amd.com>
> -----Original Message-----
> From: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
> Sent: Tuesday, May 28, 2024 10:08 PM
> To: devel@edk2.groups.io
> Cc: Attar, AbdulLateef (Abdul Lateef) <AbdulLateef.Attar@amd.com>; Chang,
> Abner <Abner.Chang@amd.com>; Grimes, Paul <Paul.Grimes@amd.com>
> Subject: [edk2-platforms 2/3] AmdPlatformPkg: Implements
> SmmCorePlatformHookLib library
>
> Implements SmmCorePlatformHookLib library for AMD platform.
>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Paul Grimes <paul.grimes@amd.com>
> Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
> ---
> .../AMD/AmdPlatformPkg/AmdPlatformPkg.dec | 5 +
> .../AMD/AmdPlatformPkg/AmdPlatformPkg.dsc | 6 +
> .../Library/AmdSmmCorePlatformHookLib.h | 68 +++++++
> .../SmmCorePlatformHookLib.c | 169 ++++++++++++++++++
> .../SmmCorePlatformHookLib.inf | 39 ++++
> .../SmmCorePlatformHookLib.uni | 11 ++
> 6 files changed, 298 insertions(+)
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHoo
> kLib.h
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCor
> ePlatformHookLib.c
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCor
> ePlatformHookLib.inf
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCor
> ePlatformHookLib.uni
>
> diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> index 106820dc85..3020e628a3 100644
> --- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> +++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> @@ -21,6 +21,11 @@
> ## @libraryclass Defines a get/set interface for platform specific data.
> PlatformSocLib|Include/Library/AmdPlatformSocLib.h
>
> + ## @libraryclass AMD SMM core platform hook library
> + # Provide the functions to register hook before and
> + # after SMM dispatcher.
> +
> SmmCorePlatformHookLib|Include/Library/AmdSmmCorePlatformHookLib.h
> +
> [Guids]
> gAmdPlatformPkgTokenSpaceGuid = { 0x663DE733, 0x70E0, 0x4D37,
> { 0xBB, 0x30, 0x7D, 0x9E, 0xAF, 0x9B, 0xDA, 0xE9 }}
>
> diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> index d11d3594e3..482e6f2f30 100644
> --- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> +++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> @@ -62,6 +62,9 @@
>
> MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemor
> yAllocationLib.inf
>
> PlatformSocLib|AmdPlatformPkg/Library/DxePlatformSocLib/DxePlatformSoc
> LibNull.inf
>
> +[LibraryClasses.common.SMM_CORE]
> +
> SmmCorePlatformHookLib|AmdPlatformPkg/Library/SmmCorePlatformHook
> Lib/SmmCorePlatformHookLib.inf
> +
> [Components]
>
> AmdPlatformPkg/Library/BaseAlwaysFalseDepexLib/BaseAlwaysFalseDepexLi
> b.inf
> AmdPlatformPkg/Library/DxePlatformSocLib/DxePlatformSocLibNull.inf
> @@ -73,3 +76,6 @@
> AmdPlatformPkg/Universal/LogoDxe/LogoDxe.inf #
> Server platfrom Bitmap logo driver
> AmdPlatformPkg/Universal/LogoDxe/S3LogoDxe.inf
> AmdPlatformPkg/Universal/SmbiosCommonDxe/SmbiosCommonDxe.inf
> +
> +[Components.common.SMM_CORE]
> +
> AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHook
> Lib.inf
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHo
> okLib.h
> b/Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHo
> okLib.h
> new file mode 100644
> index 0000000000..6ae76920b4
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Include/Library/AmdSmmCorePlatformHo
> okLib.h
> @@ -0,0 +1,68 @@
> +/** @file
> + AMD Smm Core Platform Hook Library
> +
> + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef AMD_SMM_CORE_PLATFORM_HOOK_LIB_
> +#define AMD_SMM_CORE_PLATFORM_HOOK_LIB_
> +
> +/**
> + This is the prototype of SMM Dispatcher hook before.
> +
> + @retval EFI_STATUS
> +
> +**/
> +typedef
> +EFI_STATUS
> +(EFIAPI *AMD_SMM_DISPATCH_HOOK_BEFORE)(
> + VOID
> + );
> +
> +/**
> + This is the prototype of SMM Dispatcher after before.
> +
> + @retval EFI_STATUS
> +
> +**/
> +typedef
> +EFI_STATUS
> +(EFIAPI *AMD_SMM_DISPATCH_HOOK_AFTER)(
> + VOID
> + );
> +
> +typedef UINT32 AMD_SMM_DISPATCH_HOOK_PRIORITY;
> +
> +///
> +/// This is the structure of the SMM Dispatcher hook record
> +///
> +typedef struct {
> + LIST_ENTRY NextList; ///< Point to next
> AMD_SMM_DISPATCH_HOOK.
> + AMD_SMM_DISPATCH_HOOK_BEFORE AmdSmmDispatchHookBefore;
> ///< The hook before function.
> + AMD_SMM_DISPATCH_HOOK_AFTER AmdSmmDispatchHookAfter; ///<
> The hook after function.
> + AMD_SMM_DISPATCH_HOOK_PRIORITY Priority; ///< The priority
> of this hook instance.
> + ///< Priority could be implemented for
> + ///< future usage.
> +} AMD_SMM_DISPATCH_HOOK;
> +
> +/**
> + Register a SMM dispatcher hook.
> +
> + @param[in] SmmDispatchHookBefore Function hook to SMM Dispatch
> before.
> + @param[in] SmmDispatchHookAfter Function hook to SMM Dispatch
> after.
> + @param[in] Priority The priority to execute the hook.
> +
> + @retval EFI_SUCCESS The hook is registered successfully.
> +
> +**/
> +EFI_STATUS
> +RegisterSmmDispatcherHook (
> + IN AMD_SMM_DISPATCH_HOOK_BEFORE SmmDispatchHookBefore
> OPTIONAL,
> + IN AMD_SMM_DISPATCH_HOOK_AFTER SmmDispatchHookAfter
> OPTIONAL,
> + IN AMD_SMM_DISPATCH_HOOK_PRIORITY Priority
> + );
> +
> +#endif // AMD_SMM_CORE_PLATFORM_HOOK_LIB_
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.c
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.c
> new file mode 100644
> index 0000000000..ad6a40749f
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.c
> @@ -0,0 +1,169 @@
> +/** @file
> + AMD SMM core hook library
> +
> + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiSmm.h>
> +#include <Library/SmmServicesTableLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/SmmCorePlatformHookLib.h>
> +#include <Library/AmdSmmCorePlatformHookLib.h>
> +
> +LIST_ENTRY *RegisteredHookPtr = NULL;
> +LIST_ENTRY RegisteredHook;
> +
> +/**
> + Register a SMM dispatcher hook.
> +
> + @param[in] SmmDispatchHookBefore Function hook to SMM Dispatch
> before.
> + @param[in] SmmDispatchHookAfter Function hook to SMM Dispatch
> after.
> + @param[in] Priority The priority to execute the hook.
> +
> + @retval EFI_SUCCESS The hook is registered successfully.
> +
> +**/
> +EFI_STATUS
> +RegisterSmmDispatcherHook (
> + IN AMD_SMM_DISPATCH_HOOK_BEFORE SmmDispatchHookBefore
> OPTIONAL,
> + IN AMD_SMM_DISPATCH_HOOK_AFTER SmmDispatchHookAfter
> OPTIONAL,
> + IN AMD_SMM_DISPATCH_HOOK_PRIORITY Priority
> + )
> +{
> + AMD_SMM_DISPATCH_HOOK *ThisHook;
> +
> + if ((SmmDispatchHookBefore == NULL) && (SmmDispatchHookAfter ==
> NULL)) {
> + DEBUG ((DEBUG_ERROR, "%a: Both SmmDispatchHookBefore and
> SmmDispatchHookAfter are NULL.\n", __func__));
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + if (RegisteredHookPtr == NULL) {
> + InitializeListHead (&RegisteredHook);
> + RegisteredHookPtr = &RegisteredHook;
> + }
> +
> + ThisHook = (AMD_SMM_DISPATCH_HOOK *)AllocateZeroPool (sizeof
> (AMD_SMM_DISPATCH_HOOK));
> + if (ThisHook == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a: Insufficient memory for
> AMD_SMM_DISPATCH_HOOK.\n", __func__));
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + InitializeListHead (&ThisHook->NextList);
> + ThisHook->AmdSmmDispatchHookBefore = SmmDispatchHookBefore;
> + ThisHook->AmdSmmDispatchHookAfter = SmmDispatchHookAfter;
> + ThisHook->Priority = Priority;
> + InsertHeadList (&RegisteredHook, &ThisHook->NextList);
> + DEBUG ((DEBUG_VERBOSE, "%a: New AMD_SMM_DISPATCH_HOOK is
> inserted.\n", __func__));
> + return EFI_SUCCESS;
> +}
> +
> +/**
> + Performs platform specific tasks before invoking registered SMI handlers.
> +
> + This function performs platform specific tasks before invoking registered
> SMI handlers.
> +
> + @retval EFI_SUCCESS The platform hook completes successfully.
> + @retval Other values The platform hook cannot complete due to some
> error.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +PlatformHookBeforeSmmDispatch (
> + VOID
> + )
> +{
> + AMD_SMM_DISPATCH_HOOK *ThisHook;
> +
> + if (IsListEmpty (&RegisteredHook)) {
> + return EFI_NOT_FOUND;
> + }
> +
> + ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetFirstNode
> (&RegisteredHook);
> + while (TRUE) {
> + //
> + // We can handle priority in the future when needed.
> + //
> + if (ThisHook->AmdSmmDispatchHookBefore != NULL) {
> + ThisHook->AmdSmmDispatchHookBefore ();
> + }
> +
> + if (IsNodeAtEnd (&RegisteredHook, &ThisHook->NextList)) {
> + break;
> + }
> +
> + ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetNextNode
> (&RegisteredHook, &ThisHook->NextList);
> + }
> +
> + return EFI_SUCCESS;
> +}
> +
> +/**
> + Performs platform specific tasks after invoking registered SMI handlers.
> +
> + This function performs platform specific tasks after invoking registered SMI
> handlers.
> +
> + @retval EFI_SUCCESS The platform hook completes successfully.
> + @retval Other values The platform hook cannot complete due to some
> error.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +PlatformHookAfterSmmDispatch (
> + VOID
> + )
> +{
> + AMD_SMM_DISPATCH_HOOK *ThisHook;
> +
> + if (IsListEmpty (&RegisteredHook)) {
> + return EFI_NOT_FOUND;
> + }
> +
> + ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetFirstNode
> (&RegisteredHook);
> + while (TRUE) {
> + //
> + // We can handle priority in the future when needed.
> + //
> + if (ThisHook->AmdSmmDispatchHookAfter != NULL) {
> + ThisHook->AmdSmmDispatchHookAfter ();
> + }
> +
> + if (IsNodeAtEnd (&RegisteredHook, &ThisHook->NextList)) {
> + break;
> + }
> +
> + ThisHook = (AMD_SMM_DISPATCH_HOOK *)GetNextNode
> (&RegisteredHook, &ThisHook->NextList);
> + }
> +
> + return EFI_SUCCESS;
> +}
> +
> +/**
> + Constructor for SmmLockBox library.
> + This is used to set SmmLockBox context, which will be used in PEI phase in
> S3 boot path later.
> +
> + @param[in] ImageHandle Image handle of this driver.
> + @param[in] SystemTable A Pointer to the EFI System Table.
> +
> + @retval EFI_SUCCESS
> + @return Others Some error occurs.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCorePlatformHookConstructor (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + if (RegisteredHookPtr == NULL) {
> + InitializeListHead (&RegisteredHook);
> + RegisteredHookPtr = &RegisteredHook;
> + }
> +
> + return EFI_SUCCESS;
> +}
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.inf
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.inf
> new file mode 100644
> index 0000000000..a79fc56077
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.inf
> @@ -0,0 +1,39 @@
> +## @file
> +# INF of SMM Core hook library INF file.
> +#
> +# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +[Defines]
> + INF_VERSION = 0x00010005
> + BASE_NAME = SmmCorePlatformHookLib
> + MODULE_UNI_FILE = SmmCorePlatformHookLib.uni
> + FILE_GUID = 70ACB6CA-80D2-46a9-A0EB-0C83DFC476C9
> + MODULE_TYPE = SMM_CORE
> + VERSION_STRING = 1.0
> + PI_SPECIFICATION_VERSION = 0x0001000A
> + LIBRARY_CLASS = SmmCorePlatformHookLib|SMM_CORE
> + CONSTRUCTOR = SmmCorePlatformHookConstructor
> +
> +#
> +# The following information is for reference only and not required by the build
> tools.
> +#
> +# VALID_ARCHITECTURES = IA32 X64
> +#
> +
> +[Sources]
> + SmmCorePlatformHookLib.c
> +
> +[Packages]
> + AmdPlatformPkg/AmdPlatformPkg.dec
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> +
> +[LibraryClasses]
> + BaseLib
> + BaseMemoryLib
> + DebugLib
> + MemoryAllocationLib
> + SmmServicesTableLib
> +
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.uni
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.uni
> new file mode 100644
> index 0000000000..0b326c159b
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmC
> orePlatformHookLib.uni
> @@ -0,0 +1,11 @@
> +## @file
> +# UNI file of SMM Core hook library module
> +#
> +# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +#string STR_MODULE_ABSTRACT #language en-US "SMM Core
> Platform Hook Library instance"
> +
> +#string STR_MODULE_DESCRIPTION #language en-US "SMM Core
> Platform Hook Library instance"
> --
> 2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119335): https://edk2.groups.io/g/devel/message/119335
Mute This Topic: https://groups.io/mt/106349081/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 7+ messages in thread
* [edk2-devel] [edk2-platforms 3/3] AmdPlatformPkg: Adds SPI smm core platform hook
2024-05-28 14:07 [edk2-devel] [edk2-platforms 0/3] AmdPlatformPkg: SmbiosDxe and SPI supporting libraries Abdul Lateef Attar via groups.io
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 1/3] AmdPlatformPkg: Removes unused gBoardBdsBootFromDevicePathProtocolGuid Abdul Lateef Attar via groups.io
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 2/3] AmdPlatformPkg: Implements SmmCorePlatformHookLib library Abdul Lateef Attar via groups.io
@ 2024-05-28 14:07 ` Abdul Lateef Attar via groups.io
2024-05-29 8:57 ` Chang, Abner via groups.io
2 siblings, 1 reply; 7+ messages in thread
From: Abdul Lateef Attar via groups.io @ 2024-05-28 14:07 UTC (permalink / raw)
To: devel; +Cc: Abdul Lateef Attar, Abner Chang, Paul Grimes
Register a smm core platform hook handler for SPI device,
using AMD SmmCorePlatformHookLib library.
This platform hook saves the SPI host controller state.
Cc: Abner Chang <abner.chang@amd.com>
Cc: Paul Grimes <paul.grimes@amd.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
.../AMD/AmdPlatformPkg/AmdPlatformPkg.dec | 3 +
.../AMD/AmdPlatformPkg/AmdPlatformPkg.dsc | 2 +
.../Include/Protocol/AmdSpiSmmHcState.h | 107 +++++++++++++
.../SmmCoreAmdSpiHcHookLib.c | 145 ++++++++++++++++++
.../SmmCoreAmdSpiHcHookLib.h | 20 +++
.../SmmCoreAmdSpiHcHookLib.inf | 41 +++++
.../SmmCoreAmdSpiHcHookLib.uni | 11 ++
7 files changed, 329 insertions(+)
create mode 100644 Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h
create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.c
create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.h
create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.inf
create mode 100644 Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.uni
diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
index 3020e628a3..907c5b9b74 100644
--- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
+++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
@@ -29,6 +29,9 @@
[Guids]
gAmdPlatformPkgTokenSpaceGuid = { 0x663DE733, 0x70E0, 0x4D37, { 0xBB, 0x30, 0x7D, 0x9E, 0xAF, 0x9B, 0xDA, 0xE9 }}
+[Protocols]
+ gAmdSpiHcStateProtocolGuid = { 0x189566ab, 0x245, 0x43ae, {0x9d, 0x1, 0xd2, 0x21, 0x1c, 0xb9, 0x1a, 0xda }}
+
[PcdsDynamic]
## Event GUID to trigger logo displaying
# Default set to gMinPlatformPkgTokenSpaceGuid.gBdsEventAfterConsoleReadyBeforeBootOptionGuid
diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
index 482e6f2f30..012270074d 100644
--- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
+++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
@@ -64,6 +64,7 @@
[LibraryClasses.common.SMM_CORE]
SmmCorePlatformHookLib|AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf
+ SmmCoreAmdSpiHcHookLib|AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.inf
[Components]
AmdPlatformPkg/Library/BaseAlwaysFalseDepexLib/BaseAlwaysFalseDepexLib.inf
@@ -79,3 +80,4 @@
[Components.common.SMM_CORE]
AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHookLib.inf
+ AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.inf
diff --git a/Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h b/Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h
new file mode 100644
index 0000000000..0e2bccb3ef
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h
@@ -0,0 +1,107 @@
+/** @file
+ Header file of AMD SMM SPI host controller state protocol
+
+ Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef AMD_SMM_SPI_HC_STATE_PROTOCOL_H_
+#define AMD_SMM_SPI_HC_STATE_PROTOCOL_H_
+
+typedef struct _SMM_EFI_SPI_HC_STATE_PROTOCOL SMM_EFI_SPI_HC_STATE_PROTOCOL;
+
+/**
+ Save/Restore the state of the SPI Host Controller
+
+ Use a chipset specific method to save the state of the SPI Host controller so
+ it can be used without disturbing other transactions.
+
+ @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL structure.
+
+ @retval EFI_SUCCESS The State was saved successfully
+ @retval DEVICE_ERROR SPI Executes command failed
+
+**/
+typedef EFI_STATUS
+(EFIAPI *SMM_SPI_HC_STATE)(
+ IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This
+ );
+
+/**
+ Lock/Unlock the SPI host controller register
+
+ Use a chipset specific method to lock or unlock SPI host controller register.
+
+ @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL structure.
+
+ @retval EFI_SUCCESS The clock was set up successfully
+ @retval DEVICE_ERROR SPI Executes command failed
+
+
+**/
+typedef EFI_STATUS
+(EFIAPI *SMM_SPI_HC_LOCK_UNLOCK)(
+ IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This
+ );
+
+/**
+ Block/Unblock SPI opcode
+
+ Use a chipset specific method to block and unclock specific SPI opcode.
+
+ @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL structure.
+
+ @retval EFI_SUCCESS The clock was set up successfully
+ @retval DEVICE_ERROR SPI Executes command failed
+
+**/
+typedef EFI_STATUS
+(EFIAPI *SMM_SPI_HC_BLOCK_UNBLOCK_OPCODE)(
+ IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This,
+ IN UINT8 Opcode
+ );
+
+/**
+ Block/Unblock any SPI opcodes
+
+ Use a chipset specific method to block and unclock all SPI opcodes.
+
+ @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL structure.
+
+ @retval EFI_SUCCESS The clock was set up successfully
+ @retval DEVICE_ERROR SPI Executes command failed
+
+**/
+typedef EFI_STATUS
+(EFIAPI *SMM_SPI_HC_BLOCK_UNBLOCK_ALL_OPCODES)(
+ IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This
+ );
+
+///
+/// Manage and control the SPI host controller state.
+///
+struct _SMM_EFI_SPI_HC_STATE_PROTOCOL {
+ ///
+ /// Save and Restore SPI host controller state.
+ ///
+ SMM_SPI_HC_STATE SaveState;
+ SMM_SPI_HC_STATE RestoreState;
+
+ ///
+ /// Lock and Unlock SPI host controller registers
+ ///
+ SMM_SPI_HC_LOCK_UNLOCK Lock;
+ SMM_SPI_HC_LOCK_UNLOCK Unlock;
+
+ ///
+ /// Block and Unblock SPI Opcode
+ ///
+ SMM_SPI_HC_BLOCK_UNBLOCK_OPCODE BlockOpcode;
+ SMM_SPI_HC_BLOCK_UNBLOCK_OPCODE UnblockOpcode;
+ SMM_SPI_HC_BLOCK_UNBLOCK_ALL_OPCODES UnblockAllOpcodes;
+};
+
+extern EFI_GUID gAmdSpiHcStateProtocolGuid;
+
+#endif // AMD_SMM_SPI_HC_STATE_PROTOCOL_H__
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.c b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.c
new file mode 100644
index 0000000000..4284f13a5e
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.c
@@ -0,0 +1,145 @@
+/** @file
+ SMM core hook for AMD SPI Host Controller State
+
+ Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include <PiSmm.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Protocol/AmdSpiSmmHcState.h>
+
+#include <Library/AmdSmmCorePlatformHookLib.h>
+#include "SmmCoreAmdSpiHcHookLib.h"
+
+VOID *mSmmCorePlatformHookHcStateRegistration = NULL;
+
+SMM_CORE_HOOK_AMD_SPI_HC_STATE_CONTEXT mSmmCorePlatformHookContext;
+
+/**
+ Performs platform specific tasks before invoking registered SMI handlers.
+
+ This function performs platform specific tasks before invoking registered SMI handlers.
+
+ @retval EFI_SUCCESS The platform hook completes successfully.
+ @retval Other values The platform hook cannot complete due to some error.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmCoreSpiHcHookBeforeSmmDispatch (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ SMM_EFI_SPI_HC_STATE_PROTOCOL *SpiHcState;
+
+ Status = EFI_SUCCESS;
+ SpiHcState = mSmmCorePlatformHookContext.SmmSpiHcStateInterface;
+ if (SpiHcState != NULL) {
+ Status = SpiHcState->SaveState (SpiHcState);
+ // Open up SPI HC for SMM, Restore state will automatically return back to
+ // state on SMM entry
+ Status = SpiHcState->Unlock (SpiHcState);
+ Status = SpiHcState->UnblockAllOpcodes (SpiHcState);
+ }
+
+ return Status;
+}
+
+/**
+ Performs platform specific tasks after invoking registered SMI handlers.
+
+ This function performs platform specific tasks after invoking registered SMI handlers.
+
+ @retval EFI_SUCCESS The platform hook completes successfully.
+ @retval Other values The platform hook cannot complete due to some error.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmCoreSpiHcHookAfterSmmDispatch (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ SMM_EFI_SPI_HC_STATE_PROTOCOL *SpiHcState;
+
+ Status = EFI_SUCCESS;
+ SpiHcState = mSmmCorePlatformHookContext.SmmSpiHcStateInterface;
+ if (SpiHcState != NULL) {
+ Status = SpiHcState->RestoreState (SpiHcState);
+ }
+
+ return Status;
+}
+
+/**
+ Notification for SMM ReadyToLock protocol.
+
+ @param[in] Protocol Points to the protocol's unique identifier.
+ @param[in] Interface Points to the interface instance.
+ @param[in] Handle The handle on which the interface was installed.
+
+ @retval EFI_SUCCESS Notification runs successfully.
+**/
+EFI_STATUS
+EFIAPI
+SmmCorePlatformHookHcStateNotify (
+ IN CONST EFI_GUID *Protocol,
+ IN VOID *Interface,
+ IN EFI_HANDLE Handle
+ )
+{
+ mSmmCorePlatformHookContext.SmmSpiHcStateInterface = Interface;
+ mSmmCorePlatformHookContext.SmmSpiHcStateHandle = Handle;
+ return EFI_SUCCESS;
+}
+
+/**
+ Constructor for SmmLockBox library.
+ This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+ @param[in] ImageHandle Image handle of this driver.
+ @param[in] SystemTable A Pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS
+ @return Others Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+SmmCoreAmdSpiHcHookConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ SetMem (
+ &mSmmCorePlatformHookContext,
+ sizeof (mSmmCorePlatformHookContext),
+ 0
+ );
+ //
+ // Register gAmdSpiHcStateProtocolGuid notification.
+ //
+ Status = gSmst->SmmRegisterProtocolNotify (
+ &gAmdSpiHcStateProtocolGuid,
+ SmmCorePlatformHookHcStateNotify,
+ &mSmmCorePlatformHookHcStateRegistration
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Register AMD SMM Dispatcher hook instance.
+ //
+ Status = RegisterSmmDispatcherHook (
+ SmmCoreSpiHcHookBeforeSmmDispatch,
+ SmmCoreSpiHcHookAfterSmmDispatch,
+ 0
+ );
+ return Status;
+}
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.h b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.h
new file mode 100644
index 0000000000..8a5dfe623c
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.h
@@ -0,0 +1,20 @@
+/** @file
+ Header file of SMM core platform hook for AMD SPI Host Controller state library
+
+ Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef SMM_CORE_AMD_SPI_HC_HOOK_LIB_H_
+#define SMM_CORE_AMD_SPI_HC_HOOK_LIB_H_
+
+///
+/// Structure of AMD SPI HC State record
+///
+typedef struct {
+ VOID *SmmSpiHcStateInterface; ///< AMD SMM SPI HC State Protocol Interface
+ EFI_HANDLE SmmSpiHcStateHandle; ///< Handle of MD SMM SPI HC State Protocol handle
+} SMM_CORE_HOOK_AMD_SPI_HC_STATE_CONTEXT;
+
+#endif // SMM_CORE_AMD_SPI_HC_HOOK_LIB_H_
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.inf b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.inf
new file mode 100644
index 0000000000..9855aa8543
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.inf
@@ -0,0 +1,41 @@
+## @file
+# INF of SMM Core AMD SPI Host Contoller State hook library.
+#
+# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SmmCoreAmdSpiHcHookLib
+ MODULE_UNI_FILE = SmmCoreAmdSpiHcHookLib.uni
+ FILE_GUID = 65D0E2A5-C8C6-4DEE-8FD0-5A006A49E9B7
+ MODULE_TYPE = SMM_CORE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x0001000A
+ LIBRARY_CLASS = SmmCoreAmdSpiHcHookLib|SMM_CORE
+ CONSTRUCTOR = SmmCoreAmdSpiHcHookConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ SmmCoreAmdSpiHcHookLib.c
+ SmmCoreAmdSpiHcHookLib.h
+
+[Packages]
+ AmdPlatformPkg/AmdPlatformPkg.dec
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ SmmServicesTableLib
+ BaseLib
+ DebugLib
+ BaseMemoryLib
+
+[Protocols]
+ gAmdSpiHcStateProtocolGuid
diff --git a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.uni b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.uni
new file mode 100644
index 0000000000..0a73c4acb4
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcHookLib.uni
@@ -0,0 +1,11 @@
+## @file
+# UNI file of SMM Core AMD SPI Host Controller State hook library module
+#
+# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+#string STR_MODULE_ABSTRACT #language en-US "SMM Core AMD SPI HC State Hook Library instance"
+
+#string STR_MODULE_DESCRIPTION #language en-US "SMM Core AMD SPI Host Controller Hook Library instance"
--
2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119306): https://edk2.groups.io/g/devel/message/119306
Mute This Topic: https://groups.io/mt/106349079/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [edk2-devel] [edk2-platforms 3/3] AmdPlatformPkg: Adds SPI smm core platform hook
2024-05-28 14:07 ` [edk2-devel] [edk2-platforms 3/3] AmdPlatformPkg: Adds SPI smm core platform hook Abdul Lateef Attar via groups.io
@ 2024-05-29 8:57 ` Chang, Abner via groups.io
0 siblings, 0 replies; 7+ messages in thread
From: Chang, Abner via groups.io @ 2024-05-29 8:57 UTC (permalink / raw)
To: Attar, AbdulLateef (Abdul Lateef), devel@edk2.groups.io
Cc: Attar, AbdulLateef (Abdul Lateef), Grimes, Paul
[AMD Official Use Only - AMD Internal Distribution Only]
Reviewed-by: Abner Chang <abner.chang@amd.com>
> -----Original Message-----
> From: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
> Sent: Tuesday, May 28, 2024 10:08 PM
> To: devel@edk2.groups.io
> Cc: Attar, AbdulLateef (Abdul Lateef) <AbdulLateef.Attar@amd.com>; Chang,
> Abner <Abner.Chang@amd.com>; Grimes, Paul <Paul.Grimes@amd.com>
> Subject: [edk2-platforms 3/3] AmdPlatformPkg: Adds SPI smm core platform
> hook
>
> Register a smm core platform hook handler for SPI device,
> using AMD SmmCorePlatformHookLib library.
>
> This platform hook saves the SPI host controller state.
>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Paul Grimes <paul.grimes@amd.com>
> Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
> ---
> .../AMD/AmdPlatformPkg/AmdPlatformPkg.dec | 3 +
> .../AMD/AmdPlatformPkg/AmdPlatformPkg.dsc | 2 +
> .../Include/Protocol/AmdSpiSmmHcState.h | 107 +++++++++++++
> .../SmmCoreAmdSpiHcHookLib.c | 145 ++++++++++++++++++
> .../SmmCoreAmdSpiHcHookLib.h | 20 +++
> .../SmmCoreAmdSpiHcHookLib.inf | 41 +++++
> .../SmmCoreAmdSpiHcHookLib.uni | 11 ++
> 7 files changed, 329 insertions(+)
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmC
> oreAmdSpiHcHookLib.c
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmC
> oreAmdSpiHcHookLib.h
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmC
> oreAmdSpiHcHookLib.inf
> create mode 100644
> Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmC
> oreAmdSpiHcHookLib.uni
>
> diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> index 3020e628a3..907c5b9b74 100644
> --- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> +++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
> @@ -29,6 +29,9 @@
> [Guids]
> gAmdPlatformPkgTokenSpaceGuid = { 0x663DE733, 0x70E0, 0x4D37,
> { 0xBB, 0x30, 0x7D, 0x9E, 0xAF, 0x9B, 0xDA, 0xE9 }}
>
> +[Protocols]
> + gAmdSpiHcStateProtocolGuid = { 0x189566ab, 0x245, 0x43ae, {0x9d,
> 0x1, 0xd2, 0x21, 0x1c, 0xb9, 0x1a, 0xda }}
> +
> [PcdsDynamic]
> ## Event GUID to trigger logo displaying
> # Default set to
> gMinPlatformPkgTokenSpaceGuid.gBdsEventAfterConsoleReadyBeforeBootO
> ptionGuid
> diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> index 482e6f2f30..012270074d 100644
> --- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> +++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
> @@ -64,6 +64,7 @@
>
> [LibraryClasses.common.SMM_CORE]
>
> SmmCorePlatformHookLib|AmdPlatformPkg/Library/SmmCorePlatformHook
> Lib/SmmCorePlatformHookLib.inf
> +
> SmmCoreAmdSpiHcHookLib|AmdPlatformPkg/Library/SmmCoreAmdSpiHcH
> ookLib/SmmCoreAmdSpiHcHookLib.inf
>
> [Components]
>
> AmdPlatformPkg/Library/BaseAlwaysFalseDepexLib/BaseAlwaysFalseDepexLi
> b.inf
> @@ -79,3 +80,4 @@
>
> [Components.common.SMM_CORE]
>
> AmdPlatformPkg/Library/SmmCorePlatformHookLib/SmmCorePlatformHook
> Lib.inf
> +
> AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/SmmCoreAmdSpiHcH
> ookLib.inf
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h
> b/Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h
> new file mode 100644
> index 0000000000..0e2bccb3ef
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Include/Protocol/AmdSpiSmmHcState.h
> @@ -0,0 +1,107 @@
> +/** @file
> + Header file of AMD SMM SPI host controller state protocol
> +
> + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +
> +#ifndef AMD_SMM_SPI_HC_STATE_PROTOCOL_H_
> +#define AMD_SMM_SPI_HC_STATE_PROTOCOL_H_
> +
> +typedef struct _SMM_EFI_SPI_HC_STATE_PROTOCOL
> SMM_EFI_SPI_HC_STATE_PROTOCOL;
> +
> +/**
> + Save/Restore the state of the SPI Host Controller
> +
> + Use a chipset specific method to save the state of the SPI Host controller so
> + it can be used without disturbing other transactions.
> +
> + @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL
> structure.
> +
> + @retval EFI_SUCCESS The State was saved successfully
> + @retval DEVICE_ERROR SPI Executes command failed
> +
> +**/
> +typedef EFI_STATUS
> +(EFIAPI *SMM_SPI_HC_STATE)(
> + IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This
> + );
> +
> +/**
> + Lock/Unlock the SPI host controller register
> +
> + Use a chipset specific method to lock or unlock SPI host controller register.
> +
> + @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL
> structure.
> +
> + @retval EFI_SUCCESS The clock was set up successfully
> + @retval DEVICE_ERROR SPI Executes command failed
> +
> +
> +**/
> +typedef EFI_STATUS
> +(EFIAPI *SMM_SPI_HC_LOCK_UNLOCK)(
> + IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This
> + );
> +
> +/**
> + Block/Unblock SPI opcode
> +
> + Use a chipset specific method to block and unclock specific SPI opcode.
> +
> + @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL
> structure.
> +
> + @retval EFI_SUCCESS The clock was set up successfully
> + @retval DEVICE_ERROR SPI Executes command failed
> +
> +**/
> +typedef EFI_STATUS
> +(EFIAPI *SMM_SPI_HC_BLOCK_UNBLOCK_OPCODE)(
> + IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This,
> + IN UINT8 Opcode
> + );
> +
> +/**
> + Block/Unblock any SPI opcodes
> +
> + Use a chipset specific method to block and unclock all SPI opcodes.
> +
> + @param[in] This Pointer to an SMM_EFI_SPI_HC_STATE_PROTOCOL
> structure.
> +
> + @retval EFI_SUCCESS The clock was set up successfully
> + @retval DEVICE_ERROR SPI Executes command failed
> +
> +**/
> +typedef EFI_STATUS
> +(EFIAPI *SMM_SPI_HC_BLOCK_UNBLOCK_ALL_OPCODES)(
> + IN CONST SMM_EFI_SPI_HC_STATE_PROTOCOL *This
> + );
> +
> +///
> +/// Manage and control the SPI host controller state.
> +///
> +struct _SMM_EFI_SPI_HC_STATE_PROTOCOL {
> + ///
> + /// Save and Restore SPI host controller state.
> + ///
> + SMM_SPI_HC_STATE SaveState;
> + SMM_SPI_HC_STATE RestoreState;
> +
> + ///
> + /// Lock and Unlock SPI host controller registers
> + ///
> + SMM_SPI_HC_LOCK_UNLOCK Lock;
> + SMM_SPI_HC_LOCK_UNLOCK Unlock;
> +
> + ///
> + /// Block and Unblock SPI Opcode
> + ///
> + SMM_SPI_HC_BLOCK_UNBLOCK_OPCODE BlockOpcode;
> + SMM_SPI_HC_BLOCK_UNBLOCK_OPCODE UnblockOpcode;
> + SMM_SPI_HC_BLOCK_UNBLOCK_ALL_OPCODES UnblockAllOpcodes;
> +};
> +
> +extern EFI_GUID gAmdSpiHcStateProtocolGuid;
> +
> +#endif // AMD_SMM_SPI_HC_STATE_PROTOCOL_H__
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Smm
> CoreAmdSpiHcHookLib.c
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.c
> new file mode 100644
> index 0000000000..4284f13a5e
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.c
> @@ -0,0 +1,145 @@
> +/** @file
> + SMM core hook for AMD SPI Host Controller State
> +
> + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +#include <PiSmm.h>
> +#include <Library/SmmServicesTableLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Protocol/AmdSpiSmmHcState.h>
> +
> +#include <Library/AmdSmmCorePlatformHookLib.h>
> +#include "SmmCoreAmdSpiHcHookLib.h"
> +
> +VOID *mSmmCorePlatformHookHcStateRegistration = NULL;
> +
> +SMM_CORE_HOOK_AMD_SPI_HC_STATE_CONTEXT
> mSmmCorePlatformHookContext;
> +
> +/**
> + Performs platform specific tasks before invoking registered SMI handlers.
> +
> + This function performs platform specific tasks before invoking registered
> SMI handlers.
> +
> + @retval EFI_SUCCESS The platform hook completes successfully.
> + @retval Other values The platform hook cannot complete due to some
> error.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCoreSpiHcHookBeforeSmmDispatch (
> + VOID
> + )
> +{
> + EFI_STATUS Status;
> + SMM_EFI_SPI_HC_STATE_PROTOCOL *SpiHcState;
> +
> + Status = EFI_SUCCESS;
> + SpiHcState = mSmmCorePlatformHookContext.SmmSpiHcStateInterface;
> + if (SpiHcState != NULL) {
> + Status = SpiHcState->SaveState (SpiHcState);
> + // Open up SPI HC for SMM, Restore state will automatically return back to
> + // state on SMM entry
> + Status = SpiHcState->Unlock (SpiHcState);
> + Status = SpiHcState->UnblockAllOpcodes (SpiHcState);
> + }
> +
> + return Status;
> +}
> +
> +/**
> + Performs platform specific tasks after invoking registered SMI handlers.
> +
> + This function performs platform specific tasks after invoking registered SMI
> handlers.
> +
> + @retval EFI_SUCCESS The platform hook completes successfully.
> + @retval Other values The platform hook cannot complete due to some
> error.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCoreSpiHcHookAfterSmmDispatch (
> + VOID
> + )
> +{
> + EFI_STATUS Status;
> + SMM_EFI_SPI_HC_STATE_PROTOCOL *SpiHcState;
> +
> + Status = EFI_SUCCESS;
> + SpiHcState = mSmmCorePlatformHookContext.SmmSpiHcStateInterface;
> + if (SpiHcState != NULL) {
> + Status = SpiHcState->RestoreState (SpiHcState);
> + }
> +
> + return Status;
> +}
> +
> +/**
> + Notification for SMM ReadyToLock protocol.
> +
> + @param[in] Protocol Points to the protocol's unique identifier.
> + @param[in] Interface Points to the interface instance.
> + @param[in] Handle The handle on which the interface was installed.
> +
> + @retval EFI_SUCCESS Notification runs successfully.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCorePlatformHookHcStateNotify (
> + IN CONST EFI_GUID *Protocol,
> + IN VOID *Interface,
> + IN EFI_HANDLE Handle
> + )
> +{
> + mSmmCorePlatformHookContext.SmmSpiHcStateInterface = Interface;
> + mSmmCorePlatformHookContext.SmmSpiHcStateHandle = Handle;
> + return EFI_SUCCESS;
> +}
> +
> +/**
> + Constructor for SmmLockBox library.
> + This is used to set SmmLockBox context, which will be used in PEI phase in
> S3 boot path later.
> +
> + @param[in] ImageHandle Image handle of this driver.
> + @param[in] SystemTable A Pointer to the EFI System Table.
> +
> + @retval EFI_SUCCESS
> + @return Others Some error occurs.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmCoreAmdSpiHcHookConstructor (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + EFI_STATUS Status;
> +
> + SetMem (
> + &mSmmCorePlatformHookContext,
> + sizeof (mSmmCorePlatformHookContext),
> + 0
> + );
> + //
> + // Register gAmdSpiHcStateProtocolGuid notification.
> + //
> + Status = gSmst->SmmRegisterProtocolNotify (
> + &gAmdSpiHcStateProtocolGuid,
> + SmmCorePlatformHookHcStateNotify,
> + &mSmmCorePlatformHookHcStateRegistration
> + );
> + ASSERT_EFI_ERROR (Status);
> +
> + //
> + // Register AMD SMM Dispatcher hook instance.
> + //
> + Status = RegisterSmmDispatcherHook (
> + SmmCoreSpiHcHookBeforeSmmDispatch,
> + SmmCoreSpiHcHookAfterSmmDispatch,
> + 0
> + );
> + return Status;
> +}
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Smm
> CoreAmdSpiHcHookLib.h
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.h
> new file mode 100644
> index 0000000000..8a5dfe623c
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.h
> @@ -0,0 +1,20 @@
> +/** @file
> + Header file of SMM core platform hook for AMD SPI Host Controller state
> library
> +
> + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +
> +#ifndef SMM_CORE_AMD_SPI_HC_HOOK_LIB_H_
> +#define SMM_CORE_AMD_SPI_HC_HOOK_LIB_H_
> +
> +///
> +/// Structure of AMD SPI HC State record
> +///
> +typedef struct {
> + VOID *SmmSpiHcStateInterface; ///< AMD SMM SPI HC State Protocol
> Interface
> + EFI_HANDLE SmmSpiHcStateHandle; ///< Handle of MD SMM SPI HC
> State Protocol handle
> +} SMM_CORE_HOOK_AMD_SPI_HC_STATE_CONTEXT;
> +
> +#endif // SMM_CORE_AMD_SPI_HC_HOOK_LIB_H_
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Smm
> CoreAmdSpiHcHookLib.inf
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.inf
> new file mode 100644
> index 0000000000..9855aa8543
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.inf
> @@ -0,0 +1,41 @@
> +## @file
> +# INF of SMM Core AMD SPI Host Contoller State hook library.
> +#
> +# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +[Defines]
> + INF_VERSION = 0x00010005
> + BASE_NAME = SmmCoreAmdSpiHcHookLib
> + MODULE_UNI_FILE = SmmCoreAmdSpiHcHookLib.uni
> + FILE_GUID = 65D0E2A5-C8C6-4DEE-8FD0-5A006A49E9B7
> + MODULE_TYPE = SMM_CORE
> + VERSION_STRING = 1.0
> + PI_SPECIFICATION_VERSION = 0x0001000A
> + LIBRARY_CLASS = SmmCoreAmdSpiHcHookLib|SMM_CORE
> + CONSTRUCTOR = SmmCoreAmdSpiHcHookConstructor
> +
> +#
> +# The following information is for reference only and not required by the build
> tools.
> +#
> +# VALID_ARCHITECTURES = IA32 X64
> +#
> +
> +[Sources]
> + SmmCoreAmdSpiHcHookLib.c
> + SmmCoreAmdSpiHcHookLib.h
> +
> +[Packages]
> + AmdPlatformPkg/AmdPlatformPkg.dec
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> +
> +[LibraryClasses]
> + SmmServicesTableLib
> + BaseLib
> + DebugLib
> + BaseMemoryLib
> +
> +[Protocols]
> + gAmdSpiHcStateProtocolGuid
> diff --git
> a/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Smm
> CoreAmdSpiHcHookLib.uni
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.uni
> new file mode 100644
> index 0000000000..0a73c4acb4
> --- /dev/null
> +++
> b/Platform/AMD/AmdPlatformPkg/Library/SmmCoreAmdSpiHcHookLib/Sm
> mCoreAmdSpiHcHookLib.uni
> @@ -0,0 +1,11 @@
> +## @file
> +# UNI file of SMM Core AMD SPI Host Controller State hook library module
> +#
> +# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +#string STR_MODULE_ABSTRACT #language en-US "SMM Core AMD
> SPI HC State Hook Library instance"
> +
> +#string STR_MODULE_DESCRIPTION #language en-US "SMM Core AMD
> SPI Host Controller Hook Library instance"
> --
> 2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119334): https://edk2.groups.io/g/devel/message/119334
Mute This Topic: https://groups.io/mt/106349079/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 7+ messages in thread