From: Abner Chang <abner.ch...@amd.com>

PldmProtocolLib provides the library
function to PLDM protocol.

Signed-off-by: Abner Chang <abner.ch...@amd.com>
Cc: Isaac Oram <isaac.w.o...@intel.com>
Cc: Abdul Lateef Attar <abdat...@amd.com>
Cc: Nickle Wang <nick...@nvidia.com>
Cc: Igor Kulchytskyy <ig...@ami.com>
---
 .../ManageabilityPkg/ManageabilityPkg.dec     |  3 +
 .../Include/Dsc/Manageability.dsc             |  3 +
 .../ManageabilityPkg/ManageabilityPkg.dsc     |  1 +
 .../Dxe/PldmProtocolLib.inf                   | 42 +++++++++
 .../Include/Library/BasePldmProtocolLib.h     | 41 +++++++++
 .../Include/Protocol/PldmProtocol.h           | 87 +++++++++++++++++++
 .../PldmProtocolLibrary/Dxe/PldmProtocolLib.c | 87 +++++++++++++++++++
 .../Dxe/PldmProtocolLib.uni                   | 18 ++++
 8 files changed, 282 insertions(+)
 create mode 100644 
Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
 create mode 100644 
Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
 create mode 100644 Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
 create mode 100644 
Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
 create mode 100644 
Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni

diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec 
b/Features/ManageabilityPkg/ManageabilityPkg.dec
index 9a930d3e4b..1e9245c8dc 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dec
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dec
@@ -48,3 +48,6 @@
   gManageabilityProtocolMctpGuid    = { 0x76FED8F1, 0x0BE5, 0x4269, { 0xA3, 
0x1A, 0x38, 0x0F, 0x54, 0xF1, 0xA1, 0x8A } }
   # Manageability Protocol PLDM
   gManageabilityProtocolPldmGuid    = { 0x3958090D, 0x69DD, 0x4868, { 0x9C, 
0x41, 0xC9, 0xAC, 0x31, 0xB5, 0x25, 0xC5 } }
+
+[Protocols]
+  gEdkiiPldmProtocolGuid                = { 0x60997616, 0xDB70, 0x4B5F, { 
0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 } }
diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc 
b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
index 0d868fdf4a..59549eb39a 100644
--- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
+++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
@@ -8,6 +8,9 @@
 [LibraryClasses]
   
ManageabilityTransportHelperLib|ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
 
+[LibraryClasses.common.DXE_DRIVER]
+  
PldmProtocolLib|ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
+
 [LibraryClasses.ARM, LibraryClasses.AARCH64]
   #
   # This library provides the instrinsic functions generated by a given 
compiler.
diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc 
b/Features/ManageabilityPkg/ManageabilityPkg.dsc
index 6a083385fd..412029ef6c 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
@@ -37,6 +37,7 @@
 
 [Components]
   
ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/DxeManageabilityTransportKcs.inf
+  ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
 
 [LibraryClasses]
   
ManageabilityTransportLib|ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.inf
diff --git 
a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf 
b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
new file mode 100644
index 0000000000..1233d76726
--- /dev/null
+++ 
b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
@@ -0,0 +1,42 @@
+## @file
+#  Instance of PLDM Protocol Library in DXE phase.
+#
+#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PldmProtocolLib
+  MODULE_UNI_FILE                = PldmProtocolLib.uni
+  FILE_GUID                      = 5B1173E8-6A5A-468B-BDA4-02303530C55C
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = PldmProtocolLib|DXE_RUNTIME_DRIVER 
DXE_DRIVER DXE_CORE UEFI_DRIVER UEFI_APPLICATION
+
+#
+#  VALID_ARCHITECTURES          = IA32 X64
+#
+
+[Sources]
+  PldmProtocolLib.c
+
+[Packages]
+  ManageabilityPkg/ManageabilityPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  DebugLib
+  ManageabilityTransportHelperLib
+  UefiBootServicesTableLib
+
+[Guids]
+  gManageabilityProtocolPldmGuid
+
+[Protocols]
+  gEdkiiPldmProtocolGuid          ## ALWAYS_CONSUMES
+
diff --git a/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h 
b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
new file mode 100644
index 0000000000..5523ac3a4d
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
@@ -0,0 +1,41 @@
+/** @file
+
+  This file defines EDKII Pldm Protocol library and functions.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef EDKII_PLDM_PROTOCOL_LIB_H_
+#define EDKII_PLDM_PROTOCOL_LIB_H_
+
+/**
+  This service enables submitting commands via EDKII PLDM protocol.
+
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         Command           PLDM Command of PLDM message type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion 
code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            PLDM message was successfully sent to 
transport interface
+                                 and a response was successfully received.
+  @retval EFI_NOT_FOUND          Transport interface is not found.
+  @retval EFI_NOT_READY          Transport interface is not ready for PLDM 
message.
+  @retval EFI_DEVICE_ERROR       Transport interface has an hardware error.
+  @retval EFI_TIMEOUT            Send PLDM message got a timeout.
+  @retval EFI_UNSUPPORTED        PLDM message is unsupported.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource or 
data size error.
+**/
+EFI_STATUS
+PldmSubmitCommand (
+  IN     UINT8   PldmType,
+  IN     UINT8   Command,
+  IN     UINT8   *RequestData,
+  IN     UINT32  RequestDataSize,
+  OUT UINT8      *ResponseData,
+  IN OUT UINT32  *ResponseDataSize
+  );
+
+#endif
diff --git a/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h 
b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
new file mode 100644
index 0000000000..651997e1ad
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
@@ -0,0 +1,87 @@
+/** @file
+  Protocol of EDKII PLDM Protocol.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EDKII_PLDM_PROTOCOL_H_
+#define EDKII_PLDM_PROTOCOL_H_
+
+#include <IndustryStandard/Pldm.h>
+
+typedef struct  _EDKII_PLDM_PROTOCOL EDKII_PLDM_PROTOCOL;
+
+#define EDKII_PLDM_PROTOCOL_GUID \
+  { \
+    0x60997616, 0xDB70, 0x4B5F, 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 
\
+  }
+
+#define EDKII_PLDM_PROTOCOL_VERSION_MAJOR  1
+#define EDKII_PLDM_PROTOCOL_VERSION_MINOR  0
+#define EDKII_PLDM_PROTOCOL_VERSION        ((EDKII_PLDM_PROTOCOL_VERSION_MAJOR 
<< 8) |\
+                                       EDKII_PLDM_PROTOCOL_VERSION_MINOR)
+
+/**
+  This service enables submitting commands via EDKII PLDM protocol.
+
+  @param[in]         This              EDKII_PLDM_PROTOCOL instance.
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         Command           PLDM Command of PLDM message type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion 
code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            The command byte stream was successfully 
submit to the device and a response was successfully received.
+  @retval EFI_NOT_FOUND          The command was not successfully sent to the 
device or a response was not successfully received from the device.
+  @retval EFI_NOT_READY          PLDM transport interface is not ready for 
PLDM command access.
+  @retval EFI_DEVICE_ERROR       PLDM transport interface Device hardware 
error.
+  @retval EFI_TIMEOUT            The command time out.
+  @retval EFI_UNSUPPORTED        The command was not successfully sent to the 
device.
+  @retval EFI_OUT_OF_RESOURCES   The resource allcation is out of resource or 
data size error.
+  @retval EFI_INVALID_PARAMETER  Both RequestData and ResponseData are NULL
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_SUBMIT_COMMAND)(
+  IN     EDKII_PLDM_PROTOCOL  *This,
+  IN     UINT8                PldmType,
+  IN     UINT8                Command,
+  IN     UINT8                *RequestData,
+  IN     UINT32               RequestDataSize,
+  OUT    UINT8                *ResponseData,
+  IN OUT UINT32               *ResponseDataSize
+  );
+
+//
+// EDKII_PLDM_PROTOCOL Version 1.0
+//
+typedef struct {
+  PLDM_SUBMIT_COMMAND    PldmSubmitCommand;
+} EDKII_PLDM_PROTOCOL_V1_0;
+
+///
+/// Definitions of EDKII_PLDM_PROTOCOL.
+/// This is a union that can accommodate the new functionalities defined
+/// in PLDM Base specification in the future.
+/// The new added function must has its own EDKII_PLDM_PROTOCOL
+/// structure with the incremental version number.
+///   e.g., EDKII_PLDM_PROTOCOL_V1_1.
+///
+/// The new function must be added base on the last version of
+/// EDKII_PLDM_PROTOCOL to keep the backward compatability.
+///
+typedef union {
+  EDKII_PLDM_PROTOCOL_V1_0    *Version1_0;
+} EDKII_PLDM_PROTOCOL_FUNCTION;
+
+struct _EDKII_PLDM_PROTOCOL {
+  UINT16                          ProtocolVersion;
+  EDKII_PLDM_PROTOCOL_FUNCTION    Functions;
+};
+
+extern EFI_GUID  gEdkiiPldmProtocolGuid;
+
+#endif // EDKII_PLDM_PROTOCOL_H_
diff --git 
a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c 
b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
new file mode 100644
index 0000000000..ac6225ed92
--- /dev/null
+++ 
b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
@@ -0,0 +1,87 @@
+/** @file
+  Instance of EDKII PLDM Protocol Library in DXE phase
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiDxe.h>
+#include <Protocol/PldmProtocol.h>
+#include <Library/DebugLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+EDKII_PLDM_PROTOCOL  *mEdkiiPldmProtocol = NULL;
+
+/**
+  This service enables submitting commands via EDKII PLDM protocol.
+
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         Command           PLDM Command of PLDM message type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion 
code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            PLDM message was successfully sent to 
transport interface
+                                 and a response was successfully received.
+  @retval EFI_NOT_FOUND          Transport interface is not found.
+  @retval EFI_NOT_READY          Transport interface is not ready for PLDM 
message.
+  @retval EFI_DEVICE_ERROR       Transport interface has an hardware error.
+  @retval EFI_TIMEOUT            Send PLDM message got a timeout.
+  @retval EFI_UNSUPPORTED        PLDM message is unsupported.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource or 
data size error.
+**/
+EFI_STATUS
+PldmSubmitCommand (
+  IN     UINT8   PldmType,
+  IN     UINT8   Command,
+  IN     UINT8   *RequestData,
+  IN     UINT32  RequestDataSize,
+  OUT UINT8      *ResponseData,
+  IN OUT UINT32  *ResponseDataSize
+  )
+{
+  EFI_STATUS  Status;
+
+  if (mEdkiiPldmProtocol == NULL) {
+    Status = gBS->LocateProtocol (
+                    &gEdkiiPldmProtocolGuid,
+                    NULL,
+                    (VOID **)&mEdkiiPldmProtocol
+                    );
+    if (EFI_ERROR (Status)) {
+      //
+      // Dxe PLDM Protocol is not installed. So, PLDM device is not present.
+      //
+      DEBUG ((DEBUG_ERROR, "%a: EDKII PLDM protocol is not found - %r\n", 
Status));
+      return EFI_NOT_FOUND;
+    }
+  }
+
+  DEBUG ((DEBUG_INFO, "%a: PLDM Type: 0x%x, Command: 0x%x\n", __FUNCTION__, 
PldmType, Command));
+  if ((RequestData != NULL) && (RequestDataSize != 0)) {
+    HelperManageabilityDebugPrint ((VOID *)RequestData, RequestDataSize, "PLDM 
PLDM application layer Type/Command specific request payload\n");
+  }
+
+  Status = mEdkiiPldmProtocol->Functions.Version1_0->PldmSubmitCommand (
+                                                       mEdkiiPldmProtocol,
+                                                       PldmType,
+                                                       Command,
+                                                       RequestData,
+                                                       RequestDataSize,
+                                                       ResponseData,
+                                                       ResponseDataSize
+                                                       );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_INFO, "Fails to send PLDM package - %r\n", Status));
+    return Status;
+  }
+
+  if ((ResponseData != NULL) && (*ResponseDataSize != 0)) {
+    HelperManageabilityDebugPrint ((VOID *)ResponseData, *ResponseDataSize, 
"PLDM application layer response payload\n");
+  }
+
+  return Status;
+}
diff --git 
a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni 
b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni
new file mode 100644
index 0000000000..b58a2ac146
--- /dev/null
+++ 
b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni
@@ -0,0 +1,18 @@
+// /** @file
+// Instance of PLDM Protocol Library in DXE phase.
+//
+//  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+//
+//  SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT
+#language en-US
+"Instance of PLDM Protocol Library in DXE phase."
+
+#string STR_MODULE_DESCRIPTION
+#language en-US
+"Instance of PLDM Protocol Library in DXE phase."
+
+
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#102419): https://edk2.groups.io/g/devel/message/102419
Mute This Topic: https://groups.io/mt/98037372/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to