blob: 4430053ae17a14105a7f1dbea89771b948dd0986 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#ifndef BIOS_H
2#define BIOS_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <asm/byteorder.h>
9#include <stddef.h>
10#include <stdint.h>
11
12#include "base.h"
John Wang08c05952019-12-20 15:40:39 +080013#include "utils.h"
Sampa Misra032bd502019-03-06 05:03:22 -060014
15/* Response lengths are inclusive of completion code */
16#define PLDM_GET_DATE_TIME_RESP_BYTES 8
17
Sampa Misrab37be312019-07-03 02:26:41 -050018#define PLDM_GET_BIOS_TABLE_REQ_BYTES 6
19#define PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES 6
John Wang4d844792019-08-15 15:51:40 +080020#define PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES 5
21#define PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES 5
Zahed Hossaind69af0b2019-07-30 01:33:31 -050022#define PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES 7
John Wang8721ed62019-12-05 14:44:43 +080023#define PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES 6
Sampa Misrab37be312019-07-03 02:26:41 -050024
25enum pldm_bios_completion_codes {
26 PLDM_BIOS_TABLE_UNAVAILABLE = 0x83,
27 PLDM_INVALID_BIOS_TABLE_DATA_INTEGRITY_CHECK = 0x84,
28 PLDM_INVALID_BIOS_TABLE_TYPE = 0x85,
John Wang8721ed62019-12-05 14:44:43 +080029 PLDM_INVALID_BIOS_ATTR_HANDLE = 0x88,
Sampa Misrab37be312019-07-03 02:26:41 -050030};
31enum pldm_bios_commands {
32 PLDM_GET_BIOS_TABLE = 0x01,
John Wang4d844792019-08-15 15:51:40 +080033 PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE = 0x07,
Zahed Hossaind69af0b2019-07-30 01:33:31 -050034 PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE = 0x08,
35 PLDM_GET_DATE_TIME = 0x0c,
Xiaochao Ma39ae2a92019-11-12 20:30:34 +080036 PLDM_SET_DATE_TIME = 0x0d,
Sampa Misrab37be312019-07-03 02:26:41 -050037};
Sampa Misra032bd502019-03-06 05:03:22 -060038
Deepak Kodihallicb7f2d42019-06-19 13:25:31 +053039enum pldm_bios_table_types {
40 PLDM_BIOS_STRING_TABLE,
41 PLDM_BIOS_ATTR_TABLE,
42 PLDM_BIOS_ATTR_VAL_TABLE,
43};
44
45struct pldm_bios_string_table_entry {
46 uint16_t string_handle;
47 uint16_t string_length;
48 char name[1];
49} __attribute__((packed));
50
51struct pldm_bios_attr_table_entry {
52 uint16_t attr_handle;
53 uint8_t attr_type;
54 uint16_t string_handle;
55 uint8_t metadata[1];
56} __attribute__((packed));
57
58struct pldm_bios_enum_attr {
59 uint8_t num_possible_values;
60 uint16_t indices[1];
61} __attribute__((packed));
62
63struct pldm_bios_attr_val_table_entry {
64 uint16_t attr_handle;
65 uint8_t attr_type;
66 uint8_t value[1];
67} __attribute__((packed));
68
Sampa Misrab37be312019-07-03 02:26:41 -050069enum pldm_bios_attribute_type {
70 PLDM_BIOS_ENUMERATION = 0x0,
71 PLDM_BIOS_STRING = 0x1,
72 PLDM_BIOS_PASSWORD = 0x2,
73 PLDM_BIOS_INTEGER = 0x3,
74 PLDM_BIOS_ENUMERATION_READ_ONLY = 0x80,
75 PLDM_BIOS_STRING_READ_ONLY = 0x81,
76 PLDM_BIOS_PASSWORD_READ_ONLY = 0x82,
77 PLDM_BIOS_INTEGER_READ_ONLY = 0x83,
78};
79
80/** @struct pldm_get_bios_table_req
81 *
82 * structure representing GetBIOSTable request packet
83 */
84struct pldm_get_bios_table_req {
85 uint32_t transfer_handle;
86 uint8_t transfer_op_flag;
87 uint8_t table_type;
88} __attribute__((packed));
89
90/** @struct pldm_get_bios_table_resp
91 *
92 * structure representing GetBIOSTable response packet
93 */
94struct pldm_get_bios_table_resp {
95 uint8_t completion_code;
96 uint32_t next_transfer_handle;
97 uint8_t transfer_flag;
98 uint8_t table_data[1];
99} __attribute__((packed));
100
Priyanga5dcd1802019-06-10 01:50:39 -0500101/** @struct pldm_get_date_time_resp
102 *
103 * Structure representing PLDM get date time response
104 */
105struct pldm_get_date_time_resp {
106 uint8_t completion_code; //!< completion code
107 uint8_t seconds; //!< Seconds in BCD format
108 uint8_t minutes; //!< Minutes in BCD format
109 uint8_t hours; //!< Hours in BCD format
110 uint8_t day; //!< Day of the month in BCD format
111 uint8_t month; //!< Month in BCD format
112 uint16_t year; //!< Year in BCD format
113} __attribute__((packed));
114
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800115/** @struct pldm_set_date_time_req
116 *
117 * structure representing SetDateTime request packet
118 *
119 */
120struct pldm_set_date_time_req {
121 uint8_t seconds; //!< Seconds in BCD format
122 uint8_t minutes; //!< Minutes in BCD format
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500123 uint8_t hours; //!< Hours in BCD format
124 uint8_t day; //!< Day of the month in BCD format
125 uint8_t month; //!< Month in BCD format
126 uint16_t year; //!< Year in BCD format
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800127} __attribute__((packed));
128
129/** @struct pldm_only_cc_resp
130 *
131 * Structure representing PLDM responses only have completion code
132 */
133struct pldm_only_cc_resp {
134 uint8_t completion_code;
135} __attribute__((packed));
136
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500137/** @struct pldm_get_bios_attribute_current_value_by_handle_req
138 *
139 * structure representing GetBIOSAttributeCurrentValueByHandle request packet
140 */
141struct pldm_get_bios_attribute_current_value_by_handle_req {
142 uint32_t transfer_handle;
143 uint8_t transfer_op_flag;
144 uint16_t attribute_handle;
145} __attribute__((packed));
146
147/** @struct pldm_get_bios_attribute_current_value_by_handle_resp
148 *
149 * structure representing GetBIOSAttributeCurrentValueByHandle response
150 */
151struct pldm_get_bios_attribute_current_value_by_handle_resp {
152 uint8_t completion_code;
153 uint32_t next_transfer_handle;
154 uint8_t transfer_flag;
155 uint8_t attribute_data[1];
156} __attribute__((packed));
157
John Wang4d844792019-08-15 15:51:40 +0800158/** @struct pldm_set_bios_attribute_current_value_req
159 *
160 * structure representing SetBiosAttributeCurrentValue request packet
161 *
162 */
163struct pldm_set_bios_attribute_current_value_req {
164 uint32_t transfer_handle;
165 uint8_t transfer_flag;
166 uint8_t attribute_data[1];
167} __attribute__((packed));
168
169/** @struct pldm_set_bios_attribute_current_value_resp
170 *
171 * structure representing SetBiosCurrentValue response packet
172 *
173 */
174struct pldm_set_bios_attribute_current_value_resp {
175 uint8_t completion_code;
176 uint32_t next_transfer_handle;
177} __attribute__((packed));
178
Sampa Misra032bd502019-03-06 05:03:22 -0600179/* Requester */
180
181/* GetDateTime */
182
183/** @brief Create a PLDM request message for GetDateTime
184 *
185 * @param[in] instance_id - Message's instance id
186 * @param[out] msg - Message will be written to this
187 * @return pldm_completion_codes
188 * @note Caller is responsible for memory alloc and dealloc of param
189 * 'msg.body.payload'
190 */
191
192int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg);
193
194/** @brief Decode a GetDateTime response message
195 *
George Liu684a7162019-12-06 15:10:52 +0800196 * Note:
197 * * If the return value is not PLDM_SUCCESS, it represents a
198 * transport layer error.
199 * * If the completion_code value is not PLDM_SUCCESS, it represents a
200 * protocol layer error and all the out-parameters are invalid.
201 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500202 * @param[in] msg - Response message
vkaverapa6575b82019-04-03 05:33:52 -0500203 * @param[in] payload_length - Length of response message payload
Sampa Misra032bd502019-03-06 05:03:22 -0600204 * @param[out] completion_code - Pointer to response msg's PLDM completion code
205 * @param[out] seconds - Seconds in BCD format
206 * @param[out] minutes - minutes in BCD format
207 * @param[out] hours - hours in BCD format
208 * @param[out] day - day of month in BCD format
209 * @param[out] month - number of month in BCD format
210 * @param[out] year - year in BCD format
211 * @return pldm_completion_codes
212 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500213int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
Sampa Misra032bd502019-03-06 05:03:22 -0600214 uint8_t *completion_code, uint8_t *seconds,
215 uint8_t *minutes, uint8_t *hours, uint8_t *day,
216 uint8_t *month, uint16_t *year);
217
John Wang4d844792019-08-15 15:51:40 +0800218/* SetBiosAttributeCurrentValue */
219
220/** @brief Create a PLDM request message for SetBiosAttributeCurrentValue
221 *
222 * @param[in] instance_id - Message's instance id
223 * @param[in] transfer_handle - Handle to identify a BIOS table transfer
224 * @param[in] transfer_flag - Flag to indicate what part of the transfer
225 * this request represents
226 * @param[in] attribute_data - Contains current value of attribute
227 * @param[in] attribute_length - Length of attribute
228 * @param[out] msg - Message will be written to this
229 * @param[in] payload_length - Length of message payload
230 * @return pldm_completion_codes
231 * @note Caller is responsible for memory alloc and dealloc of params
232 * 'msg.payload'
233 */
234int encode_set_bios_attribute_current_value_req(
235 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
236 const uint8_t *attribute_data, size_t attribute_length,
237 struct pldm_msg *msg, size_t payload_length);
238
239/** @brief Decode a SetBiosAttributeCurrentValue response message
240 *
George Liu684a7162019-12-06 15:10:52 +0800241 * Note:
242 * * If the return value is not PLDM_SUCCESS, it represents a
243 * transport layer error.
244 * * If the completion_code value is not PLDM_SUCCESS, it represents a
245 * protocol layer error and all the out-parameters are invalid.
246 *
John Wang4d844792019-08-15 15:51:40 +0800247 * @param[in] msg - Response message
248 * @param[in] payload_length - Length of response message payload
249 * @param[out] completion_code - Pointer to response msg's PLDM completion code
250 * @param[out] next_transfer_handle - Pointer to a handle that identify the
George Liu684a7162019-12-06 15:10:52 +0800251 * next portion of the transfer
John Wang4d844792019-08-15 15:51:40 +0800252 * @return pldm_completion_codes
253 */
254int decode_set_bios_attribute_current_value_resp(
255 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
256 uint32_t *next_transfer_handle);
257
Sampa Misra032bd502019-03-06 05:03:22 -0600258/* Responder */
259
260/* GetDateTime */
261
262/** @brief Create a PLDM response message for GetDateTime
263 *
264 * @param[in] instance_id - Message's instance id
265 * @param[in] completion_code - PLDM completion code
266 * @param[in] seconds - seconds in BCD format
267 * @param[in] minutes - minutes in BCD format
268 * @param[in] hours - hours in BCD format
269 * @param[in] day - day of the month in BCD format
270 * @param[in] month - number of month in BCD format
271 * @param[in] year - year in BCD format
272 * @param[out] msg - Message will be written to this
273 * @return pldm_completion_codes
274 * @note Caller is responsible for memory alloc and dealloc of param
275 * 'msg.body.payload'
276 */
277
278int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code,
279 uint8_t seconds, uint8_t minutes, uint8_t hours,
280 uint8_t day, uint8_t month, uint16_t year,
281 struct pldm_msg *msg);
282
Sampa Misrab37be312019-07-03 02:26:41 -0500283/* GetBIOSTable */
284
285/** @brief Create a PLDM response message for GetBIOSTable
286 *
287 * @param[in] instance_id - Message's instance id
288 * @param[in] completion_code - PLDM completion code
289 * @param[in] next_transfer_handle - handle to identify the next portion of the
290 * transfer
291 * @param[in] transfer_flag - To indicate what part of the transfer this
292 * response represents
293 * @param[in] table_data - BIOS Table type specific data
294 * @param[in] payload_length - Length of payload message
295 * @param[out] msg - Message will be written to this
296 * @return pldm_completion_codes
297 */
298int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
299 uint32_t next_transfer_handle,
300 uint8_t transfer_flag, uint8_t *table_data,
301 size_t payload_length, struct pldm_msg *msg);
302
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500303/** @brief Encode GetBIOSTable request packet
304 *
305 * @param[in] instance_id - Message's instance id
306 * @param[in] transfer_handle - Handle to identify a BIOS table transfer
307 * @param[in] transfer_op_flag - Flag to indicate the start of a multipart
308 * transfer
309 * @param[in] table_type - BIOS table type
310 * @param[out] msg - Message will be written to this
311 * @return pldm_completion_codes
312 */
313int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
314 uint8_t transfer_op_flag, uint8_t table_type,
315 struct pldm_msg *msg);
316
Sampa Misrab37be312019-07-03 02:26:41 -0500317/** @brief Decode GetBIOSTable request packet
318 *
319 * @param[in] msg - Request message
320 * @param[in] payload_length - Length of request message payload
321 * @param[out] transfer_handle - Handle to identify a BIOS table transfer
322 * @param[out] transfer_op_flag - Flag to indicate the start of a multipart
323 * transfer
324 * @param[out] table_type - BIOS table type
325 * @return pldm_completion_codes
326 */
327int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
328 uint32_t *transfer_handle,
329 uint8_t *transfer_op_flag, uint8_t *table_type);
330
Sridevi Ramesh08efc7b2019-12-05 05:39:46 -0600331/** @brief Decode GetBIOSTable response packet
332 *
333 * @param[in] msg - Response message
334 * @param[in] payload_length - Length of response message payload
335 * @param[in] completion_code - PLDM completion code
336 * @param[in] next_transfer_handle - handle to identify the next portion of the
337 * transfer
338 * @param[in] transfer_flag - To indicate what part of the transfer this
339 * response represents
340 * @param[out] bios_table_offset - Offset where bios table data should be read
341 * in pldm msg
342 * @return pldm_completion_codes
343 */
344int decode_get_bios_table_resp(const struct pldm_msg *msg,
345 size_t payload_length, uint8_t *completion_code,
346 uint32_t *next_transfer_handle,
347 uint8_t *transfer_flag,
348 size_t *bios_table_offset);
349
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500350/* GetBIOSAttributeCurrentValueByHandle */
351
352/** @brief Decode GetBIOSAttributeCurrentValueByHandle request packet
353 *
Adair Lica37ccb2020-04-24 14:32:58 +0800354 * @param[in] instance_id - Message's instance id
355 * @param[in] transfer_handle - Handle to identify a BIOS attribute transfer
356 * @param[in] transfer_op_flag - Flag to indicate the start of a multipart
357 * transfer
358 * @param[in] attribute_handle - Handle to identify the BIOS attribute
359 * @param[out] msg - Message will be written to this
360 * @return pldm_completion_codes
361 */
362int encode_get_bios_attribute_current_value_by_handle_req(
363 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
364 uint16_t attribute_handle, struct pldm_msg *msg);
365
366/** @brief Decode GetBIOSAttributeCurrentValueByHandle response packet
367 *
368 * @param[in] msg - Response message
369 * @param[in] payload_length - Length of response message payload
370 * @param[out] completion_code - PLDM completion code
371 * @param[out] next_transfer_handle - handle to identify the next portion of
372 * the transfer
373 * @param[out] transfer_flag - To indicate what part of the transfer this
374 * response represents
375 * @param[out] attribute_data - contains current value of attribute
376 * @return pldm_completion_codes
377 */
378int decode_get_bios_attribute_current_value_by_handle_resp(
379 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
380 uint32_t *next_transfer_handle, uint8_t *transfer_flag,
381 struct variable_field *attribute_data);
382
383/** @brief Decode GetBIOSAttributeCurrentValueByHandle request packet
384 *
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500385 * @param[in] msg - Request message
386 * @param[in] payload_length - Length of request message payload
387 * @param[out] transfer_handle - Handle to identify a BIOS table transfer
388 * @param[out] transfer_op_flag - Flag to indicate the start of a multipart
389 * transfer
390 * @param[out] attribute_handle - Handle to identify the BIOS attribute
391 * @return pldm_completion_codes
392 */
393int decode_get_bios_attribute_current_value_by_handle_req(
394 const struct pldm_msg *msg, size_t payload_length,
395 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
396 uint16_t *attribute_handle);
397
398/** @brief Create a PLDM response message for
399 * GetBIOSAttributeCurrentValueByHandle
400 *
401 * @param[in] instance_id - Message's instance id
402 * @param[in] completion_code - PLDM completion code
403 * @param[in] next_transfer_handle - handle to identify the next portion of the
404 * transfer
405 * @param[in] transfer_flag - To indicate what part of the transfer this
406 * response represents
407 * @param[in] attribute_data - contains current value of attribute
408 * @param[in] attribute_length - Length of attribute
409 * @param[out] msg - Message will be written to this
410 * @return pldm_completion_codes
411 */
412int encode_get_bios_current_value_by_handle_resp(
413 uint8_t instance_id, uint8_t completion_code, uint32_t next_transfer_handle,
414 uint8_t transfer_flag, const uint8_t *attribute_data,
415 size_t attribute_length, struct pldm_msg *msg);
416
John Wang4d844792019-08-15 15:51:40 +0800417/* SetBiosAttributeCurrentValue */
418
419/** @brief Decode SetBIOSAttributeCurrentValue request packet
420 *
421 * @param[in] msg - Request message
422 * @param[in] payload_length - Length of request message payload
423 * @param[out] transfer_handle - Handle to identify a BIOS table transfer
424 * @param[out] transfer_flag - Flag to indicate what part of the transfer
John Wang08c05952019-12-20 15:40:39 +0800425 * this request represents
426 * @param[out] attribute - Struct variable_field, contains a pointer to the
427 * attribute field in the buffer of \p msg, \p msg must
428 * be valid when \p attribute is used.
John Wang4d844792019-08-15 15:51:40 +0800429 * @return pldm_completion_codes
430 */
John Wang08c05952019-12-20 15:40:39 +0800431int decode_set_bios_attribute_current_value_req(
432 const struct pldm_msg *msg, size_t payload_length,
433 uint32_t *transfer_handle, uint8_t *transfer_flag,
434 struct variable_field *attribute);
John Wang4d844792019-08-15 15:51:40 +0800435
436/** @brief Create a PLDM response message for SetBiosAttributeCurrentValue
437 *
438 * @param[in] instance_id - Message's instance id
439 * @param[in] completion_code - PLDM completion code
440 * @param[in] next_transfer_handle - handle to identify the next portion of the
441 * @param[out] msg - Message will be written to this
442 */
443int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
444 uint8_t completion_code,
445 uint32_t next_transfer_handle,
446 struct pldm_msg *msg);
447
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800448/** @brief Create a PLDM request message for SetDateTime
449 *
450 * @param[in] instance_id - Message's instance id
Xiaochao Ma501a6fd2019-12-17 14:44:57 +0800451 * @param[in] seconds - Seconds in decimal format. Value range 0~59
452 * @param[in] minutes - minutes in decimal format. Value range 0~59
453 * @param[in] hours - hours in decimal format. Value range 0~23
454 * @param[in] day - day of month in decimal format. Value range 1~31
455 * @param[in] month - number of month in decimal format. Value range 1~12
456 * @param[in] year - year in decimal format. Value range 1970~
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800457 * @param[out] msg - Message will be written to this
458 * @param[in] payload_length - Length of request message payload
459 * @return pldm_completion_codes
460 * @note Caller is responsible for memory alloc and dealloc of param
461 * 'msg.body.payload'
462 */
463int encode_set_date_time_req(uint8_t instance_id, uint8_t seconds,
464 uint8_t minutes, uint8_t hours, uint8_t day,
465 uint8_t month, uint16_t year, struct pldm_msg *msg,
466 size_t payload_length);
467
468/** @brief Decode a SetDateTime request message
469 *
470 * @param[in] msg - Response message
471 * @param[in] payload_length - Length of request message payload
472 * @param[out] seconds - seconds in BCD format
473 * @param[out] minutes - minutes in BCD format
474 * @param[out] hours - hours in BCD format
475 * @param[out] day - day of the month in BCD format
476 * @param[out] month - number of month in BCD format
477 * @param[out] year - year in BCD format
478 * @return pldm_completion_codes
479 */
480int decode_set_date_time_req(const struct pldm_msg *msg, size_t payload_length,
481 uint8_t *seconds, uint8_t *minutes, uint8_t *hours,
482 uint8_t *day, uint8_t *month, uint16_t *year);
483
484/** @brief Create a PLDM response message for SetDateTime
485 *
486 * @param[in] instance_id - Message's instance id
487 * @param[in] completion_code - PLDM completion code
488 * @param[out] msg - Message will be written to this
489 * @param[in] payload_length - Length of response message payload
490 * @return pldm_completion_codes
491 * @note Caller is responsible for memory alloc and dealloc of param
492 * 'msg.body.payload'
493 */
494int encode_set_date_time_resp(uint8_t instance_id, uint8_t completion_code,
495 struct pldm_msg *msg, size_t payload_length);
496
497/** @brief Decode a SetDateTime response message
498 *
George Liu684a7162019-12-06 15:10:52 +0800499 * Note:
500 * * If the return value is not PLDM_SUCCESS, it represents a
501 * transport layer error.
502 * * If the completion_code value is not PLDM_SUCCESS, it represents a
503 * protocol layer error and all the out-parameters are invalid.
504 *
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800505 * @param[in] msg - Response message
506 * @param[in] payload_length - Length of response message payload
507 * @param[out] completion_code - Pointer to response msg's PLDM completion code
508 * @return pldm_completion_codes
509 */
510int decode_set_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
511 uint8_t *completion_code);
512
Sampa Misra032bd502019-03-06 05:03:22 -0600513#ifdef __cplusplus
514}
515#endif
516
517#endif /* BIOS_H */