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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
/** @file
IPMI Command - NetFnChassis.
Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.<BR>
Copyright (C) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <PiPei.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/IpmiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <IndustryStandard/Ipmi.h>
/**
This function returns information about which main chassis management functions are
present and what addresses are used to access those functions.
@param [out] GetChassisCapabilitiesResponse Pointer to IPMI_GET_CHASSIS_CAPABILITIES_RESPONSE.
@retval EFI_STATUS See the return values of IpmiSubmitCommand () function.
**/
EFI_STATUS
EFIAPI
IpmiGetChassisCapabilities (
OUT IPMI_GET_CHASSIS_CAPABILITIES_RESPONSE *GetChassisCapabilitiesResponse
)
{
EFI_STATUS Status;
UINT32 DataSize;
DataSize = sizeof (*GetChassisCapabilitiesResponse);
Status = IpmiSubmitCommand (
IPMI_NETFN_CHASSIS,
IPMI_CHASSIS_GET_CAPABILITIES,
NULL,
0,
(VOID *)GetChassisCapabilitiesResponse,
&DataSize
);
return Status;
}
/**
This function gets information regarding the high-level status of the system
chassis and main power subsystem.
@param [out] GetChassisStatusResponse Pointer to IPMI_GET_CHASSIS_STATUS_RESPONSE.
@retval EFI_STATUS See the return values of IpmiSubmitCommand () function.
**/
EFI_STATUS
EFIAPI
IpmiGetChassisStatus (
OUT IPMI_GET_CHASSIS_STATUS_RESPONSE *GetChassisStatusResponse
)
{
EFI_STATUS Status;
UINT32 DataSize;
DataSize = sizeof (*GetChassisStatusResponse);
Status = IpmiSubmitCommand (
IPMI_NETFN_CHASSIS,
IPMI_CHASSIS_GET_STATUS,
NULL,
0,
(VOID *)GetChassisStatusResponse,
&DataSize
);
return Status;
}
/**
This function sends command to control power up, power down, and reset.
@param [in] ChassisControlRequest Pointer to IPMI_CHASSIS_CONTROL_REQUEST.
@param [out] CompletionCode IPMI completetion code, refer to Ipmi.h.
@retval EFI_STATUS See the return values of IpmiSubmitCommand () function.
**/
EFI_STATUS
EFIAPI
IpmiChassisControl (
IN IPMI_CHASSIS_CONTROL_REQUEST *ChassisControlRequest,
OUT UINT8 *CompletionCode
)
{
EFI_STATUS Status;
UINT32 DataSize;
DataSize = sizeof (*CompletionCode);
Status = IpmiSubmitCommand (
IPMI_NETFN_CHASSIS,
IPMI_CHASSIS_CONTROL,
(VOID *)ChassisControlRequest,
sizeof (*ChassisControlRequest),
(VOID *)CompletionCode,
&DataSize
);
return Status;
}
/**
This function is used to configure the power restore policy.
@param [in] ChassisControlRequest Pointer to IPMI_SET_POWER_RESTORE_POLICY_REQUEST.
@param [out] ChassisControlResponse Pointer to IPMI_SET_POWER_RESTORE_POLICY_RESPONSE.
@retval EFI_STATUS See the return values of IpmiSubmitCommand () function.
**/
EFI_STATUS
EFIAPI
IpmiSetPowerRestorePolicy (
IN IPMI_SET_POWER_RESTORE_POLICY_REQUEST *ChassisControlRequest,
OUT IPMI_SET_POWER_RESTORE_POLICY_RESPONSE *ChassisControlResponse
)
{
EFI_STATUS Status;
UINT32 DataSize;
DataSize = sizeof (*ChassisControlResponse);
Status = IpmiSubmitCommand (
IPMI_NETFN_CHASSIS,
IPMI_CHASSIS_SET_POWER_RESTORE_POLICY,
(VOID *)ChassisControlRequest,
sizeof (*ChassisControlRequest),
(VOID *)ChassisControlResponse,
&DataSize
);
return Status;
}
/**
This function is used to set parameters that direct the system boot
following a system power up or reset.
@param [in] BootOptionsRequest Pointer to IPMI_SET_BOOT_OPTIONS_REQUEST.
@param [out] BootOptionsResponse Pointer to IPMI_SET_BOOT_OPTIONS_RESPONSE.
@retval EFI_STATUS See the return values of IpmiSubmitCommand () function.
**/
EFI_STATUS
EFIAPI
IpmiSetSystemBootOptions (
IN IPMI_SET_BOOT_OPTIONS_REQUEST *BootOptionsRequest,
OUT IPMI_SET_BOOT_OPTIONS_RESPONSE *BootOptionsResponse
)
{
EFI_STATUS Status;
UINT32 RequestDataSize;
UINT32 ResponseDataSize;
ResponseDataSize = sizeof (*BootOptionsResponse);
RequestDataSize = sizeof (*BootOptionsRequest);
switch (BootOptionsRequest->ParameterValid.Bits.ParameterSelector) {
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_SET_IN_PROGRESS:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_0);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_SERVICE_PARTITION_SELECTOR:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_1);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_SERVICE_PARTITION_SCAN:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_2);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_BMC_BOOT_FLAG:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_3);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INFO_ACK:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_4);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_FLAGS:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_5);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INITIATOR_INFO:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_6);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INITIATOR_MAILBOX:
RequestDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_7);
break;
default:
return EFI_INVALID_PARAMETER;
break;
}
Status = IpmiSubmitCommand (
IPMI_NETFN_CHASSIS,
IPMI_CHASSIS_SET_SYSTEM_BOOT_OPTIONS,
(VOID *)BootOptionsRequest,
RequestDataSize,
(VOID *)BootOptionsResponse,
&ResponseDataSize
);
return Status;
}
/**
This function is used to retrieve the boot options set by the
Set System Boot Options command.
@param [in] BootOptionsRequest Pointer to IPMI_GET_BOOT_OPTIONS_REQUEST.
@param [out] BootOptionsResponse Pointer to IPMI_GET_BOOT_OPTIONS_RESPONSE.
@retval EFI_STATUS See the return values of IpmiSubmitCommand () function.
**/
EFI_STATUS
EFIAPI
IpmiGetSystemBootOptions (
IN IPMI_GET_BOOT_OPTIONS_REQUEST *BootOptionsRequest,
OUT IPMI_GET_BOOT_OPTIONS_RESPONSE *BootOptionsResponse
)
{
EFI_STATUS Status;
UINT32 ResponseDataSize;
ResponseDataSize = sizeof (*BootOptionsResponse);
switch (BootOptionsRequest->ParameterSelector.Bits.ParameterSelector) {
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_SET_IN_PROGRESS:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_0);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_SERVICE_PARTITION_SELECTOR:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_1);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_SERVICE_PARTITION_SCAN:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_2);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_SELECTOR_BMC_BOOT_FLAG:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_3);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INFO_ACK:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_4);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_FLAGS:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_5);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INITIATOR_INFO:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_6);
break;
case IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INITIATOR_MAILBOX:
ResponseDataSize += sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_7);
break;
default:
return EFI_INVALID_PARAMETER;
break;
}
Status = IpmiSubmitCommand (
IPMI_NETFN_CHASSIS,
IPMI_CHASSIS_GET_SYSTEM_BOOT_OPTIONS,
(VOID *)BootOptionsRequest,
sizeof (*BootOptionsRequest),
(VOID *)BootOptionsResponse,
&ResponseDataSize
);
return Status;
}
/**
Write data to the IPMI boot initiator mailbox helper function.
This function calls the IpmiSetSystemBootOptions function with
parameter 7 to write a maximum of 16 bytes to a selector block
in the boot initiator mailbox.
@param[in] SetSelector Set selector to write to
@param[in] Data Data to write to the mailbox
@param[in] Size Size of Data buffer in bytes
@retval EFI_SUCCESS On successfull IPMI transaction
@retval EFI_INVALID Data or Size is not valid
@retval Other On failing IPMI transaction
**/
EFI_STATUS
EFIAPI
IpmiWriteBootInitiatorMailbox (
IN UINT8 SetSelector,
IN UINT8 *Data,
IN UINTN Size
)
{
UINT8 *SetBootOptionsBuffer;
IPMI_SET_BOOT_OPTIONS_REQUEST *SetBootOptionsRequest;
IPMI_SET_BOOT_OPTIONS_RESPONSE SetBootOptionsResponse;
EFI_STATUS Status;
if ((Data == NULL) || (Size == 0) || (Size > 16)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (&SetBootOptionsResponse, sizeof (IPMI_SET_BOOT_OPTIONS_RESPONSE));
SetBootOptionsBuffer = (UINT8 *)AllocateZeroPool (sizeof (*SetBootOptionsRequest) + sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_7));
if (SetBootOptionsBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
SetBootOptionsBuffer[sizeof (*SetBootOptionsRequest)] = SetSelector;
CopyMem (&SetBootOptionsBuffer[sizeof (*SetBootOptionsRequest) + 1], Data, Size);
SetBootOptionsRequest = (IPMI_SET_BOOT_OPTIONS_REQUEST *)&SetBootOptionsBuffer[0];
SetBootOptionsRequest->ParameterValid.Bits.ParameterSelector = IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INITIATOR_MAILBOX;
SetBootOptionsRequest->ParameterValid.Bits.MarkParameterInvalid = 0; // mark as valid parameter
Status = IpmiSetSystemBootOptions (SetBootOptionsRequest, &SetBootOptionsResponse);
DEBUG ((DEBUG_INFO, "IpmiBootInitiator mailbox WRITE completion code 0x%X\n", SetBootOptionsResponse.CompletionCode));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Writing IPMI Boot Initiator mailbox unsuccessfull, Status - %r\n", Status));
}
FreePool (SetBootOptionsBuffer);
return Status;
}
/**
Read data from the IPMI boot initiator mailbox helper function.
This function calls the IpmiGetSystemBootOptions function with
parameter 7 to read a 16 byte selector block in the boot initiator
mailbox. ReadData is a 16 byte array and is required to be freed
by the caller.
@param[in] SetSelector Set selector to read from
@param[out] ReadData Data read from the Boot Initiator Mailbox
@retval EFI_SUCCESS On successfull IPMI transaction
@retval EFI_INVALID ReadData is NULL
@retval Other On failing IPMI transaction
**/
EFI_STATUS
EFIAPI
IpmiReadBootInitiatorMailbox (
IN UINT8 SetSelector,
OUT UINT8 **ReadData
)
{
UINT8 *GetBootOptionsBuffer;
IPMI_GET_BOOT_OPTIONS_REQUEST BootOptionsRequest;
IPMI_GET_BOOT_OPTIONS_RESPONSE *BootOptionsResponse;
IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_7 *BootOptionsParameterData;
UINT8 *BlockData;
EFI_STATUS Status;
UINT8 Count;
if (ReadData == NULL) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (&BootOptionsRequest, sizeof (IPMI_GET_BOOT_OPTIONS_REQUEST));
GetBootOptionsBuffer = AllocateZeroPool (sizeof (BootOptionsResponse) + sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_7));
if (GetBootOptionsBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
BlockData = AllocateZeroPool (sizeof (BootOptionsParameterData->BlockData));
if (BlockData == NULL) {
FreePool (GetBootOptionsBuffer);
return EFI_OUT_OF_RESOURCES;
}
// setup parameter data
BootOptionsRequest.ParameterSelector.Bits.ParameterSelector = IPMI_BOOT_OPTIONS_PARAMETER_BOOT_INITIATOR_MAILBOX;
BootOptionsRequest.SetSelector = SetSelector;
BootOptionsResponse = (IPMI_GET_BOOT_OPTIONS_RESPONSE *)&GetBootOptionsBuffer[0];
Status = IpmiGetSystemBootOptions (&BootOptionsRequest, BootOptionsResponse);
BootOptionsParameterData = (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_7 *)BootOptionsResponse->ParameterData;
// A parameter is invalid when a value of 1 is returned
if (EFI_ERROR (Status) || BootOptionsResponse->ParameterValid.Bits.ParameterValid) {
DEBUG ((
DEBUG_INFO,
"Reading IPMI Boot Initiator mailbox unsuccessful, Status - %r Parameter Valid = %d\n",
Status,
BootOptionsResponse->ParameterValid.Bits.ParameterValid
));
FreePool (BlockData);
FreePool (GetBootOptionsBuffer);
return Status;
}
DEBUG ((DEBUG_VERBOSE, "IPMI Mailbox Read Data: "));
for (Count = 0; Count < 16; Count++) {
DEBUG ((DEBUG_VERBOSE, "%x ", BootOptionsParameterData->BlockData[Count]));
}
DEBUG ((DEBUG_VERBOSE, "\n"));
// Copy data over to buffer and return this
CopyMem (BlockData, BootOptionsParameterData->BlockData, sizeof (BootOptionsParameterData->BlockData));
*ReadData = BlockData;
FreePool (GetBootOptionsBuffer);
return EFI_SUCCESS;
}
|