[edk2-devel] [PATCH edk2-platforms v3 12/16] PldmProtocolDxe: Correct TID argument usage

Konstantin Aladyshev aladyshev22 at gmail.com
Mon Oct 23 13:05:07 UTC 2023


From: Abner Chang <abner.chang at amd.com>

Currently the PLDM source/destination TID arguments for the PldmSubmit
function are not actually used in any way in the underlying MCTP
communication. The code just uses MCTP source/destination EID PCDs. So
we have to restructure code to actually use provided PLDM TIDs.
On the other case the PldmSubmitCommand function from the
PldmProtocolLib doesn't even accept the source/destination TID
arguments.
To address both these facts correct TID argument usage in the following
way:
- by default the TID values are taken from the built-time PCDs,
- user have an ability to provide custom TIDs either via PldmSubmit
function arguments or by calling PldmSetTerminus API.

Signed-off-by: Abner Chang <abner.chang at amd.com>
Signed-off-by: Konstantin Aladyshev <aladyshev22 at gmail.com>
---
 .../Include/Library/BasePldmProtocolLib.h     | 16 ++++++
 .../Include/Protocol/PldmProtocol.h           | 18 +++---
 .../PldmProtocolLibrary/Dxe/PldmProtocolLib.c | 49 +++++++++++++++-
 .../Dxe/PldmProtocolLib.inf                   |  6 +-
 .../PldmProtocol/Common/PldmProtocolCommon.c  | 28 +++++++---
 .../PldmProtocol/Common/PldmProtocolCommon.h  | 22 +++++---
 .../Universal/PldmProtocol/Dxe/PldmProtocol.c | 56 ++++++++++++++++---
 .../PldmProtocol/Dxe/PldmProtocolDxe.inf      |  4 --
 8 files changed, 162 insertions(+), 37 deletions(-)

diff --git a/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
index 5523ac3a4d..a698197263 100644
--- a/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
+++ b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
@@ -9,6 +9,22 @@
 #ifndef EDKII_PLDM_PROTOCOL_LIB_H_
 #define EDKII_PLDM_PROTOCOL_LIB_H_
 
+/**
+  This function sets the PLDM source termius and destination terminus
+  ID for SMBIOS PLDM transfer.
+
+  @param[in]         SourceId       PLDM source teminus ID.
+  @param[in]         DestinationId  PLDM destination teminus ID.
+
+  @retval EFI_SUCCESS            The terminus is set successfully.
+  @retval EFI_INVALID_PARAMETER  The terminus is set unsuccessfully.
+**/
+EFI_STATUS
+PldmSetTerminus (
+  IN  UINT8   SourceId,
+  IN  UINT8   DestinationId
+);
+
 /**
   This service enables submitting commands via EDKII PLDM protocol.
 
diff --git a/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
index 651997e1ad..02efb3015a 100644
--- a/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
+++ b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
@@ -26,13 +26,15 @@ typedef struct  _EDKII_PLDM_PROTOCOL EDKII_PLDM_PROTOCOL;
 /**
   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.
+  @param[in]         This                       EDKII_PLDM_PROTOCOL instance.
+  @param[in]         PldmType                   PLDM message type.
+  @param[in]         Command                    PLDM Command of PLDM message type.
+  @param[in]         PldmTerminusSourceId       PLDM source teminus ID.
+  @param[in]         PldmTerminusDestinationId  PLDM destination teminus ID.
+  @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.
@@ -49,6 +51,8 @@ EFI_STATUS
   IN     EDKII_PLDM_PROTOCOL  *This,
   IN     UINT8                PldmType,
   IN     UINT8                Command,
+  IN     UINT8                PldmTerminusSourceId,
+  IN     UINT8                PldmTerminusDestinationId,
   IN     UINT8                *RequestData,
   IN     UINT32               RequestDataSize,
   OUT    UINT8                *ResponseData,
diff --git a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
index 267bd8fbc1..37231b0756 100644
--- a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
+++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
@@ -9,10 +9,34 @@
 #include <PiDxe.h>
 #include <Protocol/PldmProtocol.h>
 #include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
 #include <Library/ManageabilityTransportHelperLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 
-EDKII_PLDM_PROTOCOL  *mEdkiiPldmProtocol = NULL;
+EDKII_PLDM_PROTOCOL  *mEdkiiPldmProtocol        = NULL;
+UINT8                mSourcePldmTerminusId      = 0;
+UINT8                mDestinationPldmTerminusId = 0;
+
+/**
+  This function sets the PLDM source termius and destination terminus
+  ID for SMBIOS PLDM transfer.
+
+  @param[in]         SourceId       PLDM source teminus ID.
+  @param[in]         DestinationId  PLDM destination teminus ID.
+
+  @retval EFI_SUCCESS            The terminus is set successfully.
+  @retval EFI_INVALID_PARAMETER  The terminus is set unsuccessfully.
+**/
+EFI_STATUS
+PldmSetTerminus (
+  IN  UINT8   SourceId,
+  IN  UINT8   DestinationId
+)
+{
+  mSourcePldmTerminusId      = SourceId;
+  mDestinationPldmTerminusId = DestinationId;
+  return EFI_SUCCESS;
+}
 
 /**
   This service enables submitting commands via EDKII PLDM protocol.
@@ -69,6 +93,8 @@ PldmSubmitCommand (
                                                        mEdkiiPldmProtocol,
                                                        PldmType,
                                                        Command,
+                                                       mSourcePldmTerminusId,
+                                                       mDestinationPldmTerminusId,
                                                        RequestData,
                                                        RequestDataSize,
                                                        ResponseData,
@@ -85,3 +111,24 @@ PldmSubmitCommand (
 
   return Status;
 }
+/**
+
+  Initialize mSourcePldmTerminusId and mDestinationPldmTerminusId.
+
+  @param ImageHandle     The image handle.
+  @param SystemTable     The system table.
+
+  @retval  EFI_SUCCESS  Protocol listener is registered successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+PldmProtocolLibConstructor (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+
+  PldmSetTerminus (PcdGet8(PcdPldmSourceTerminusId), PcdGet8(PcdPldmDestinationEndpointId));
+  return EFI_SUCCESS;
+}
diff --git a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
index 1233d76726..19c84840b6 100644
--- a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
+++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
@@ -16,7 +16,7 @@
   MODULE_TYPE                    = DXE_DRIVER
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = PldmProtocolLib|DXE_RUNTIME_DRIVER DXE_DRIVER DXE_CORE UEFI_DRIVER UEFI_APPLICATION
-
+  CONSTRUCTOR                    = PldmProtocolLibConstructor
 #
 #  VALID_ARCHITECTURES          = IA32 X64
 #
@@ -40,3 +40,7 @@
 [Protocols]
   gEdkiiPldmProtocolGuid          ## ALWAYS_CONSUMES
 
+[FixedPcd]
+  gManageabilityPkgTokenSpaceGuid.PcdPldmSourceTerminusId
+  gManageabilityPkgTokenSpaceGuid.PcdPldmDestinationEndpointId
+
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c
index 4edfe05955..ea3d4a22b2 100644
--- a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c
@@ -64,6 +64,8 @@ GetFullPacketResponseSize (
   @param[in]         TransportToken     The transport interface.
   @param[in]         PldmType           PLDM message type.
   @param[in]         PldmCommand        PLDM command of this PLDM type.
+  @param[in]         SourceId           PLDM source teminus ID.
+  @param[in]         DestinationId      PLDM destination teminus ID.
   @param[out]        PacketHeader       The pointer to receive header of request.
   @param[out]        PacketHeaderSize   Packet header size in bytes.
   @param[in, out]    PacketBody         The request body.
@@ -88,6 +90,8 @@ SetupPldmRequestTransportPacket (
   IN   MANAGEABILITY_TRANSPORT_TOKEN    *TransportToken,
   IN   UINT8                            PldmType,
   IN   UINT8                            PldmCommand,
+  IN   UINT8                            SourceId,
+  IN   UINT8                            DestinationId,
   OUT  MANAGEABILITY_TRANSPORT_HEADER   *PacketHeader,
   OUT  UINT16                           *PacketHeaderSize,
   IN OUT UINT8                          **PacketBody,
@@ -118,8 +122,8 @@ SetupPldmRequestTransportPacket (
       return EFI_OUT_OF_RESOURCES;
     }
 
-    MctpHeader->SourceEndpointId             = PcdGet8 (PcdMctpSourceEndpointId);
-    MctpHeader->DestinationEndpointId        = PcdGet8 (PcdMctpDestinationEndpointId);
+    MctpHeader->SourceEndpointId             = SourceId;
+    MctpHeader->DestinationEndpointId        = DestinationId;
     MctpHeader->MessageHeader.IntegrityCheck = FALSE;
     MctpHeader->MessageHeader.MessageType    = MCTP_MESSAGE_TYPE_PLDM;
     *PacketHeader                            = (MANAGEABILITY_TRANSPORT_HEADER *)MctpHeader;
@@ -161,13 +165,15 @@ SetupPldmRequestTransportPacket (
 /**
   Common code to submit PLDM commands
 
-  @param[in]         TransportToken    Transport token.
-  @param[in]         PldmType          PLDM message type.
-  @param[in]         PldmCommand       PLDM command of this PLDM 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.
+  @param[in]         TransportToken             Transport token.
+  @param[in]         PldmType                   PLDM message type.
+  @param[in]         PldmCommand                PLDM command of this PLDM type.
+  @param[in]         PldmTerminusSourceId       PLDM source teminus ID.
+  @param[in]         PldmTerminusDestinationId  PLDM destination teminus ID.
+  @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.
@@ -182,6 +188,8 @@ CommonPldmSubmitCommand (
   IN     MANAGEABILITY_TRANSPORT_TOKEN  *TransportToken,
   IN     UINT8                          PldmType,
   IN     UINT8                          PldmCommand,
+  IN     UINT8                          PldmTerminusSourceId,
+  IN     UINT8                          PldmTerminusDestinationId,
   IN     UINT8                          *RequestData OPTIONAL,
   IN     UINT32                         RequestDataSize,
   OUT    UINT8                          *ResponseData OPTIONAL,
@@ -225,6 +233,8 @@ CommonPldmSubmitCommand (
                            TransportToken,
                            PldmType,
                            PldmCommand,
+                           PldmTerminusSourceId,
+                           PldmTerminusDestinationId,
                            &PldmTransportHeader,
                            &HeaderSize,
                            &ThisRequestData,
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h
index 231d6e802e..79431dd3b1 100644
--- a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h
@@ -44,6 +44,8 @@ SetupPldmTransportHardwareInformation (
   @param[in]         TransportToken     The transport interface.
   @param[in]         PldmType           PLDM message type.
   @param[in]         PldmCommand        PLDM command of this PLDM type.
+  @param[in]         SourceId           PLDM source teminus ID.
+  @param[in]         DestinationId      PLDM destination teminus ID.
   @param[out]        PacketHeader       The pointer to receive header of request.
   @param[out]        PacketHeaderSize   Packet header size in bytes.
   @param[in, out]    PacketBody         The request body.
@@ -68,6 +70,8 @@ SetupPldmRequestTransportPacket (
   IN   MANAGEABILITY_TRANSPORT_TOKEN    *TransportToken,
   IN   UINT8                            PldmType,
   IN   UINT8                            PldmCommand,
+  IN   UINT8                            SourceId,
+  IN   UINT8                            DestinationId,
   OUT  MANAGEABILITY_TRANSPORT_HEADER   *PacketHeader,
   OUT  UINT16                           *PacketHeaderSize,
   IN OUT UINT8                          **PacketBody,
@@ -79,13 +83,15 @@ SetupPldmRequestTransportPacket (
 /**
   Common code to submit PLDM commands
 
-  @param[in]         TransportToken    Transport token.
-  @param[in]         PldmType          PLDM message type.
-  @param[in]         PldmCommand       PLDM command of this PLDM 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.
+  @param[in]         TransportToken             Transport token.
+  @param[in]         PldmType                   PLDM message type.
+  @param[in]         PldmCommand                PLDM command of this PLDM type.
+  @param[in]         PldmTerminusSourceId       PLDM source teminus ID.
+  @param[in]         PldmTerminusDestinationId  PLDM destination teminus ID.
+  @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.
@@ -100,6 +106,8 @@ CommonPldmSubmitCommand (
   IN     MANAGEABILITY_TRANSPORT_TOKEN  *TransportToken,
   IN     UINT8                          PldmType,
   IN     UINT8                          PldmCommand,
+  IN     UINT8                          PldmTerminusSourceId,
+  IN     UINT8                          PldmTerminusDestinationId,
   IN     UINT8                          *RequestData OPTIONAL,
   IN     UINT32                         RequestDataSize,
   OUT    UINT8                          *ResponseData OPTIONAL,
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c
index b2ca69b05f..726747416c 100644
--- a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c
@@ -25,13 +25,15 @@ UINT32                         TransportMaximumPayload;
 /**
   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.
+  @param[in]         This                       EDKII_PLDM_PROTOCOL instance.
+  @param[in]         PldmType                   PLDM message type.
+  @param[in]         Command                    PLDM Command of PLDM message type.
+  @param[in]         PldmTerminusSourceId       PLDM source teminus ID.
+  @param[in]         PldmTerminusDestinationId  PLDM destination teminus ID.
+  @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.
@@ -39,7 +41,7 @@ UINT32                         TransportMaximumPayload;
   @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 allocation is out of resource or data size error.
+  @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
 **/
 EFI_STATUS
@@ -48,6 +50,8 @@ PldmSubmitCommand (
   IN     EDKII_PLDM_PROTOCOL  *This,
   IN     UINT8                PldmType,
   IN     UINT8                Command,
+  IN     UINT8                PldmTerminusSourceId,
+  IN     UINT8                PldmTerminusDestinationId,
   IN     UINT8                *RequestData,
   IN     UINT32               RequestDataSize,
   OUT    UINT8                *ResponseData,
@@ -61,10 +65,46 @@ PldmSubmitCommand (
     return EFI_INVALID_PARAMETER;
   }
 
+  if (RequestData != NULL && RequestDataSize == 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: RequestDataSize == 0, however RequestData is not NULL for PLDM type: 0x%x, Command: 0x%x.\n",
+      __func__,
+      PldmType,
+      Command
+      ));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (ResponseData == NULL && *ResponseDataSize != 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: *ResponseDataSize != 0, however ResponseData is NULL for PLDM type: 0x%x, Command: 0x%x.\n",
+      __func__,
+      PldmType,
+      Command
+      ));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (ResponseData != NULL && *ResponseDataSize == 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: *ResponseDataSize == 0, however ResponseData is not NULL for PLDM type: 0x%x, Command: 0x%x.\n",
+      __func__,
+      PldmType,
+      Command
+      ));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((DEBUG_MANAGEABILITY, "%a: Source terminus ID: 0x%x, Destination terminus ID: 0x%x.\n"));
   Status = CommonPldmSubmitCommand (
              mTransportToken,
              PldmType,
              Command,
+             PldmTerminusSourceId,
+             PldmTerminusDestinationId,
              RequestData,
              RequestDataSize,
              ResponseData,
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
index 006f77b09a..aef25f6438 100644
--- a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
@@ -42,9 +42,5 @@
 [Protocols]
   gEdkiiPldmProtocolGuid
 
-[FixedPcd]
-  gManageabilityPkgTokenSpaceGuid.PcdMctpSourceEndpointId
-  gManageabilityPkgTokenSpaceGuid.PcdMctpDestinationEndpointId
-
 [Depex]
   TRUE
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109920): https://edk2.groups.io/g/devel/message/109920
Mute This Topic: https://groups.io/mt/102134662/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list