summaryrefslogtreecommitdiff
path: root/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
blob: d18b70280c31946bc9d793c873df76b7f2b81912 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/** @file
  Instance of EDKII PLDM Protocol Library in DXE phase

  Copyright (C) 2023-2026 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/PcdLib.h>
#include <Library/ManageabilityTransportHelperLib.h>
#include <Library/UefiBootServicesTableLib.h>

EDKII_PLDM_PROTOCOL  *mEdkiiPldmProtocol        = NULL;
UINT8                mSourcePldmTerminusId      = 0;
UINT8                mDestinationPldmTerminusId = 0;

/**
  This function sets the PLDM source terminus and destination terminus
  ID for SMBIOS PLDM transfer.

  @param[in]         SourceId       PLDM source terminus ID.
  @param[in]         DestinationId  PLDM destination terminus 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.

  @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", __func__, Status));
      return EFI_NOT_FOUND;
    }
  }

  DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: PLDM Type: 0x%x, Command: 0x%x\n", __func__, 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,
                                                       mSourcePldmTerminusId,
                                                       mDestinationPldmTerminusId,
                                                       RequestData,
                                                       RequestDataSize,
                                                       ResponseData,
                                                       ResponseDataSize
                                                       );
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "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;
}

/**

  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;
}