hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
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
/** @file
  A Library to support all BMC access via IPMI command during PEI Phase.
 
  @copyright
  Copyright 2017 - 2021 Intel Corporation. <BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
 
#include <PiPei.h>
#include <Library/IpmiBaseLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/DebugLib.h>
#include <Ppi/IpmiTransportPpi.h>
 
 
/**
  Initialize the global varible with the pointer of IpmiTransport Protocol.
 
  @return EFI_SUCCESS - Always return success
 
**/
EFI_STATUS
InitializeIpmiBase (
  VOID
  )
{
  EFI_STATUS                                Status;
  PEI_IPMI_TRANSPORT_PPI                    *IpmiTransport;
 
  Status = PeiServicesLocatePpi (&gPeiIpmiTransportPpiGuid, 0, NULL, (VOID **) &IpmiTransport);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
  }
  return Status;
}
 
/**
  Routine to send commands to BMC.
 
  @param NetFunction       - Net function of the command
  @param Command           - IPMI Command
  @param CommandData       - Command Data
  @param CommandDataSize   - Size of CommandData
  @param ResponseData      - Response Data
  @param ResponseDataSize  - Response Data Size
 
  @return EFI_NOT_AVAILABLE_YET - IpmiTransport Protocol is not installed yet
 
**/
EFI_STATUS
IpmiSubmitCommand (
  IN UINT8        NetFunction,
  IN UINT8        Command,
  IN UINT8        *CommandData,
  IN UINT32       CommandDataSize,
  OUT UINT8       *ResponseData,
  IN OUT UINT32   *ResponseDataSize
  )
{
  EFI_STATUS                                Status;
  PEI_IPMI_TRANSPORT_PPI                    *IpmiTransport;
 
  Status = PeiServicesLocatePpi (&gPeiIpmiTransportPpiGuid, 0, NULL, (VOID **) &IpmiTransport);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    return Status;
  }
  Status = IpmiTransport->IpmiSubmitCommand (
                            IpmiTransport,
                            NetFunction,
                            0,
                            Command,
                            CommandData,
                            CommandDataSize,
                            ResponseData,
                            ResponseDataSize
                            );
  return Status;
}
 
/**
  Routine to send commands to BMC.
 
  @param BmcStatus       - Ststus of Bmc
  @param ComAddress      - IPMI Address
 
  @return EFI_NOT_AVAILABLE_YET - IpmiTransport Protocol is not installed yet
 
**/
EFI_STATUS
GetBmcStatus (
  OUT BMC_STATUS                       *BmcStatus,
  OUT SM_COM_ADDRESS                   *ComAddress
  )
{
  EFI_STATUS                                Status;
  PEI_IPMI_TRANSPORT_PPI                    *IpmiTransport;
 
  Status = PeiServicesLocatePpi (&gPeiIpmiTransportPpiGuid, 0, NULL, (VOID **) &IpmiTransport);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    return Status;
  }
  Status = IpmiTransport->GetBmcStatus (
                            IpmiTransport,
                            BmcStatus,
                            ComAddress
                            );
  return Status;
}