blob: 64ee68385f921b5e19fbc2eb2323d1dd7935a769 [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
123 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
127} __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 *
354 * @param[in] msg - Request message
355 * @param[in] payload_length - Length of request message payload
356 * @param[out] transfer_handle - Handle to identify a BIOS table transfer
357 * @param[out] transfer_op_flag - Flag to indicate the start of a multipart
358 * transfer
359 * @param[out] attribute_handle - Handle to identify the BIOS attribute
360 * @return pldm_completion_codes
361 */
362int decode_get_bios_attribute_current_value_by_handle_req(
363 const struct pldm_msg *msg, size_t payload_length,
364 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
365 uint16_t *attribute_handle);
366
367/** @brief Create a PLDM response message for
368 * GetBIOSAttributeCurrentValueByHandle
369 *
370 * @param[in] instance_id - Message's instance id
371 * @param[in] completion_code - PLDM completion code
372 * @param[in] next_transfer_handle - handle to identify the next portion of the
373 * transfer
374 * @param[in] transfer_flag - To indicate what part of the transfer this
375 * response represents
376 * @param[in] attribute_data - contains current value of attribute
377 * @param[in] attribute_length - Length of attribute
378 * @param[out] msg - Message will be written to this
379 * @return pldm_completion_codes
380 */
381int encode_get_bios_current_value_by_handle_resp(
382 uint8_t instance_id, uint8_t completion_code, uint32_t next_transfer_handle,
383 uint8_t transfer_flag, const uint8_t *attribute_data,
384 size_t attribute_length, struct pldm_msg *msg);
385
John Wang4d844792019-08-15 15:51:40 +0800386/* SetBiosAttributeCurrentValue */
387
388/** @brief Decode SetBIOSAttributeCurrentValue request packet
389 *
390 * @param[in] msg - Request message
391 * @param[in] payload_length - Length of request message payload
392 * @param[out] transfer_handle - Handle to identify a BIOS table transfer
393 * @param[out] transfer_flag - Flag to indicate what part of the transfer
John Wang08c05952019-12-20 15:40:39 +0800394 * this request represents
395 * @param[out] attribute - Struct variable_field, contains a pointer to the
396 * attribute field in the buffer of \p msg, \p msg must
397 * be valid when \p attribute is used.
John Wang4d844792019-08-15 15:51:40 +0800398 * @return pldm_completion_codes
399 */
John Wang08c05952019-12-20 15:40:39 +0800400int decode_set_bios_attribute_current_value_req(
401 const struct pldm_msg *msg, size_t payload_length,
402 uint32_t *transfer_handle, uint8_t *transfer_flag,
403 struct variable_field *attribute);
John Wang4d844792019-08-15 15:51:40 +0800404
405/** @brief Create a PLDM response message for SetBiosAttributeCurrentValue
406 *
407 * @param[in] instance_id - Message's instance id
408 * @param[in] completion_code - PLDM completion code
409 * @param[in] next_transfer_handle - handle to identify the next portion of the
410 * @param[out] msg - Message will be written to this
411 */
412int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
413 uint8_t completion_code,
414 uint32_t next_transfer_handle,
415 struct pldm_msg *msg);
416
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800417/** @brief Create a PLDM request message for SetDateTime
418 *
419 * @param[in] instance_id - Message's instance id
Xiaochao Ma501a6fd2019-12-17 14:44:57 +0800420 * @param[in] seconds - Seconds in decimal format. Value range 0~59
421 * @param[in] minutes - minutes in decimal format. Value range 0~59
422 * @param[in] hours - hours in decimal format. Value range 0~23
423 * @param[in] day - day of month in decimal format. Value range 1~31
424 * @param[in] month - number of month in decimal format. Value range 1~12
425 * @param[in] year - year in decimal format. Value range 1970~
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800426 * @param[out] msg - Message will be written to this
427 * @param[in] payload_length - Length of request message payload
428 * @return pldm_completion_codes
429 * @note Caller is responsible for memory alloc and dealloc of param
430 * 'msg.body.payload'
431 */
432int encode_set_date_time_req(uint8_t instance_id, uint8_t seconds,
433 uint8_t minutes, uint8_t hours, uint8_t day,
434 uint8_t month, uint16_t year, struct pldm_msg *msg,
435 size_t payload_length);
436
437/** @brief Decode a SetDateTime request message
438 *
439 * @param[in] msg - Response message
440 * @param[in] payload_length - Length of request message payload
441 * @param[out] seconds - seconds in BCD format
442 * @param[out] minutes - minutes in BCD format
443 * @param[out] hours - hours in BCD format
444 * @param[out] day - day of the month in BCD format
445 * @param[out] month - number of month in BCD format
446 * @param[out] year - year in BCD format
447 * @return pldm_completion_codes
448 */
449int decode_set_date_time_req(const struct pldm_msg *msg, size_t payload_length,
450 uint8_t *seconds, uint8_t *minutes, uint8_t *hours,
451 uint8_t *day, uint8_t *month, uint16_t *year);
452
453/** @brief Create a PLDM response message for SetDateTime
454 *
455 * @param[in] instance_id - Message's instance id
456 * @param[in] completion_code - PLDM completion code
457 * @param[out] msg - Message will be written to this
458 * @param[in] payload_length - Length of response 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_resp(uint8_t instance_id, uint8_t completion_code,
464 struct pldm_msg *msg, size_t payload_length);
465
466/** @brief Decode a SetDateTime response message
467 *
George Liu684a7162019-12-06 15:10:52 +0800468 * Note:
469 * * If the return value is not PLDM_SUCCESS, it represents a
470 * transport layer error.
471 * * If the completion_code value is not PLDM_SUCCESS, it represents a
472 * protocol layer error and all the out-parameters are invalid.
473 *
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800474 * @param[in] msg - Response message
475 * @param[in] payload_length - Length of response message payload
476 * @param[out] completion_code - Pointer to response msg's PLDM completion code
477 * @return pldm_completion_codes
478 */
479int decode_set_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
480 uint8_t *completion_code);
481
Sampa Misra032bd502019-03-06 05:03:22 -0600482#ifdef __cplusplus
483}
484#endif
485
486#endif /* BIOS_H */