blob: d0e06a420ea83271a41e85a01f18f55bf32da355 [file] [log] [blame]
John Wang02700402019-10-06 16:34:29 +08001#ifndef BIOS_TABLE_H__
2#define BIOS_TABLE_H__
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "bios.h"
John Wangb0da7a02020-01-07 16:55:00 +08009#include "utils.h"
John Wang02700402019-10-06 16:34:29 +080010#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13
14/** @struct pldm_bios_table_iter
15 * structure representing bios table iterator
16 */
17struct pldm_bios_table_iter;
18
19/** @brief Create a bios table iterator
20 * @param[in] table - Pointer to table data
21 * @param[in] length - Length of table data
22 * @param[in] type - Type of pldm bios table
23 * @return Iterator to the beginning
24 */
25struct pldm_bios_table_iter *
26pldm_bios_table_iter_create(const void *table, size_t length,
27 enum pldm_bios_table_types type);
28
29/** @brief Release a bios table iterator
30 * @param[in] iter - Pointer to bios table iterator
31 */
32void pldm_bios_table_iter_free(struct pldm_bios_table_iter *iter);
33
34/** @brief Check if the iterator reaches the end of the bios table
35 * @param[in] iter - Pointer to the bios table iterator
36 * @return true if iterator reaches the end
37 * @note *end* is a position after the last entry.
38 */
39bool pldm_bios_table_iter_is_end(const struct pldm_bios_table_iter *iter);
40
41/** @brief Get iterator to next entry
42 * @param[in] iter - Pointer the bios table iterator
43 */
44void pldm_bios_table_iter_next(struct pldm_bios_table_iter *iter);
45
46/** @brief Get the bios table entry that the iterator points to
47 * @param[in] iter - Pointer to the bios table iterator
48 * @return Pointer to an entry in bios table
49 */
50const void *pldm_bios_table_iter_value(struct pldm_bios_table_iter *iter);
51
52/** @brief Get the bios attribute table entry that the iterator points to
53 * @param[in] iter - Pointer the bios attribute table iterator
54 * @return Pointer to an entry in bios attribute table
55 */
56static inline const struct pldm_bios_attr_table_entry *
57pldm_bios_table_iter_attr_entry_value(struct pldm_bios_table_iter *iter)
58{
59 return (const struct pldm_bios_attr_table_entry *)
60 pldm_bios_table_iter_value(iter);
61}
62
John Wangdd9a6282019-10-11 18:52:46 +080063/** @brief Get the bios string table entry that the iterator ponit to
64 * @param[in] iter - Pointer the bios string table iterator
65 * @return Pointer to an entry in bios string table
66 */
67static inline const struct pldm_bios_string_table_entry *
68pldm_bios_table_iter_string_entry_value(struct pldm_bios_table_iter *iter)
69{
70 return (const struct pldm_bios_string_table_entry *)
71 pldm_bios_table_iter_value(iter);
72}
73
John Wang49484a12019-12-02 14:21:53 +080074/** @brief Get the bios attribute value table entry that the iterator ponit to
75 * @param[in] iter - Pointer the bios attribute value table iterator
76 * @return Pointer to an entry in bios attribute value table
77 */
78static inline const struct pldm_bios_attr_val_table_entry *
79pldm_bios_table_iter_attr_value_entry_value(struct pldm_bios_table_iter *iter)
80{
81 return (const struct pldm_bios_attr_val_table_entry *)
82 pldm_bios_table_iter_value(iter);
83}
84
John Wangdd9a6282019-10-11 18:52:46 +080085/** @brief Get the length of an entry in the BIOS String Table
86 * @param[in] string_length - Length of string
87 * @return Length of an entry in bytes
88 */
89size_t pldm_bios_table_string_entry_encode_length(uint16_t string_length);
90
91/** @brief Create an entry of BIOS String Table
92 * @param[out] entry - Pointer to a buffer to create an entry
93 * @param[in] entry_length - Length of the buffer to create an entry
94 * @param[in] str - String itself
95 * @param[in] str_length - Length of the string
96 */
97void pldm_bios_table_string_entry_encode(void *entry, size_t entry_length,
98 const char *str, uint16_t str_length);
99
100/** @brief Create an entry of BIOS String Table and check the validity of the
101 * parameters
102 * @param[out] entry - Pointer to a buffer to create an entry
103 * @param[in] entry_length - Length of the buffer to create an entry
104 * @param[in] str - String itself
105 * @param[in] str_length - Length of the string
106 * @return pldm_completion_codes
107 */
108int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
109 const char *str,
110 uint16_t str_length);
111
112/** @brief Get the string handle for the entry
113 * @param[in] entry - Pointer to a bios string table entry
114 * @return Handle to identify a string in the bios string table
115 */
116uint16_t pldm_bios_table_string_entry_decode_handle(
117 const struct pldm_bios_string_table_entry *entry);
118
119/** @brief Get the string length for the entry
120 * @param[in] entry - Pointer to a bios string table entry
121 * @return Length of string in bytes
122 */
123uint16_t pldm_bios_table_string_entry_decode_string_length(
124 const struct pldm_bios_string_table_entry *entry);
125
126/** @brief Get the string(at most one less than *size* characters) from the
127 * entry
128 * @param[in] entry - Pointer to a bios string table entry
129 * @param[out] buffer - Pointer to a buffer to store the string
130 * @param[in] size - Size of the buffer to store the string
131 * @return Length of the string decoded
132 */
133uint16_t pldm_bios_table_string_entry_decode_string(
134 const struct pldm_bios_string_table_entry *entry, char *buffer,
135 size_t size);
136
137/** @brief Get the string from the entry and check the validity of the
138 * parameters
139 * @param[in] entry - Pointer to a bios string table entry
140 * @param[out] buffer - Pointer to a buffer to store the string
141 * @param[in] size - Size of the buffer to store the string
142 * @return pldm_completion_codes
143 */
144int pldm_bios_table_string_entry_decode_string_check(
145 const struct pldm_bios_string_table_entry *entry, char *buffer,
146 size_t size);
147
148/** @brief Find an entry in bios string table by string
149 * @param[in] table - The BIOS String Table
150 * @param[in] length - Length of the BIOS String Table
151 * @param[in] str - String itself
152 * @return Pointer to an entry in the bios string table
153 */
154const struct pldm_bios_string_table_entry *
155pldm_bios_table_string_find_by_string(const void *table, size_t length,
156 const char *str);
157/** @brief Find an entry in bios string table by handle
158 * @param[in] table - The BIOS String Table
159 * @param[in] length - Length of the BIOS String Table
160 * @param[in] handle - Handle to identify a string in the bios string table
161 * @return Pointer to an entry in the bios string table
162 */
163const struct pldm_bios_string_table_entry *
164pldm_bios_table_string_find_by_handle(const void *table, size_t length,
165 uint16_t handle);
166
John Wangb0da7a02020-01-07 16:55:00 +0800167/** @brief Get the attribute handle from the attribute table entry
168 * @param[in] entry - Pointer to bios attribute table entry
169 * @return handle to identify the attribute in the attribute table
170 */
171uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
172 const struct pldm_bios_attr_table_entry *entry);
173
John Wang50218a62020-02-12 17:10:28 +0800174/** @brief Get the attribute type of the attribute table entry
175 * @param[in] entry - Pointer to bios attribute table entry
176 * @return Type of the attribute table entry
177 */
178uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
179 const struct pldm_bios_attr_table_entry *entry);
180
John Wangb0da7a02020-01-07 16:55:00 +0800181/** @brief Get the attribute name handle from the attribute table entry
182 * @param[in] entry - Pointer to bios attribute table entry
183 * @return handle to identify the name of the attribute, this handle points
184 * to a string in the bios string table.
185 */
186uint16_t pldm_bios_table_attr_entry_decode_string_handle(
187 const struct pldm_bios_attr_table_entry *entry);
188
189/** @brief Find an entry in attribute table by handle
190 * @param[in] table - The BIOS Attribute Table
191 * @param[in] length - Length of the BIOS Attribute Table
192 * @param[in] handle - handle to identify the attribute in the attribute table
193 * @return Pointer to the entry
194 */
195const struct pldm_bios_attr_table_entry *
196pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
197 uint16_t handle);
198
John Wangccc04552019-10-14 14:28:25 +0800199/** @struct pldm_bios_table_attr_entry_enum_info
200 *
201 * An auxiliary structure for passing parameters to @ref
202 * pldm_bios_table_attr_entry_enum_encode
203 *
204 */
205struct pldm_bios_table_attr_entry_enum_info {
206 uint16_t name_handle; //!< attribute name handle
207 bool read_only; //!< indicate whether the attribute is read-only
208 uint8_t pv_num; //!< number of possible values
209 const uint16_t *pv_handle; //!< handles of possible values
210 uint8_t def_num; //!< nnumber of default values
211 const uint8_t *def_index; //!< indices of default values.
212};
213
214/** @brief Get length that an attribute entry(type: enum) will take
215 * @param[in] pv_num - Number of possible values
216 * @param[in] def_num - Number of default values
217 * @return The length that an entry(type: enum) will take
218 */
219size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
220 uint8_t def_num);
221
222/** @brief Create an entry of BIOS Attribute Table (type: enum)
223 * @param[out] entry - Pointer to a buffer to create an entry
224 * @param[in] entry_length - Length of the buffer to create an entry
225 * @param[in] info - Pointer to an auxiliary structure @ref
226 * pldm_bios_table_attr_entry_enum_info
227 */
228void pldm_bios_table_attr_entry_enum_encode(
229 void *entry, size_t entry_length,
230 const struct pldm_bios_table_attr_entry_enum_info *info);
231
232/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
233 * validity of the parameters
234 * @param[out] entry - Pointer to a buffer to create an entry
235 * @param[in] entry_length - Length of the buffer to create an entry
236 * @param[in] info - Pointer to an auxiliary structure @ref
237 * pldm_bios_table_attr_entry_enum_info
238 * @return pldm_completion_codes
239 */
240int pldm_bios_table_attr_entry_enum_encode_check(
241 void *entry, size_t entry_length,
242 const struct pldm_bios_table_attr_entry_enum_info *info);
243
John Wang02700402019-10-06 16:34:29 +0800244/** @brief Get the total number of possible values for the entry
245 * @param[in] entry - Pointer to bios attribute table entry
246 * @return total number of possible values
247 */
248uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
249 const struct pldm_bios_attr_table_entry *entry);
250
251/** @brief Get the total number of possible values for the entry and check the
252 * validity of the parameters
253 * @param[in] entry - Pointer to bios attribute table entry
254 * @param[out] pv_num - Pointer to total number of possible values
255 * @return pldm_completion_codes
256 */
257int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
258 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
259
260/** @brief Get the total number of default values for the entry
261 * @param[in] entry - Pointer to bios attribute table entry
262 * @return total number of default values
263 */
264uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
265 const struct pldm_bios_attr_table_entry *entry);
266
267/** @brief Get the total number of default values for the entry and check the
268 * validity of the parameters
269 * @param[in] entry - Pointer to bios attribute table entry
270 * @param[out] def_num - Pointer to total number of default values
271 * @return pldm_completion_codes
272 */
273int pldm_bios_table_attr_entry_enum_decode_def_num_check(
274 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
275
John Wang3ad21752019-10-06 16:42:21 +0800276/** @brief Get possible values string handles
277 * @param[in] entry - Pointer to bios attribute table entry
278 * @param[out] pv_hdls - Pointer to a buffer to stroe
279 * PossibleValuesStringHandles
280 * @param[in] pv_num - Number of PossibleValuesStringHandles expected
281 * @return pldm_completion_codes
282 */
283uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
284 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
285 uint8_t pv_num);
286
287/** @brief Get possible values string handles and check the validity of the
288 * parameters
289 * @param[in] entry - Pointer to bios attribute table entry
290 * @param[out] pv_hdls - Pointer to a buffer to stroe
291 * PossibleValuesStringHandles
292 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
293 * stroe
294 * @return Number of PossibleValuesStringHandles decoded
295 */
296int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
297 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
298 uint8_t pv_num);
299
John Wang50218a62020-02-12 17:10:28 +0800300/** @brief Get Indices of default values
301 * @param[in] entry - Pointer to bios attribute table entry
302 * @param[out] def_indices - Pointer to a buffer to store
303 * default value indices
304 * @param[in] def_num - Number of DefaultValues the buffer can
305 * store
306 * @return Number of default values decoded
307 */
308uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
309 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
310 uint8_t def_num);
311
John Wangccc04552019-10-14 14:28:25 +0800312/** @struct pldm_bios_table_attr_entry_string_info
313 *
314 * An auxiliary structure for passing parameters to @ref
315 * pldm_bios_table_attr_entry_string_encode
316 *
317 */
318struct pldm_bios_table_attr_entry_string_info {
319 uint16_t name_handle; //!< attribute name handle
320 bool read_only; //!< indicate whether the attribute is read-only
321 uint8_t string_type; //!< The type of the string
322 uint16_t min_length; //!< The minimum length of the string in bytes
323 uint16_t max_length; //!< The maximum length of the string in bytes
324 uint16_t def_length; //!< The length of the defaut string in bytes
325 const char *def_string; //!< The default string itself
326};
327
John Wang827c5de2019-11-07 18:27:27 +0800328/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
329 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
330 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
331 * memory
332 * @return pldm_completion_codes
333 */
334int pldm_bios_table_attr_entry_string_info_check(
335 const struct pldm_bios_table_attr_entry_string_info *info,
336 const char **errmsg);
337
John Wangccc04552019-10-14 14:28:25 +0800338/** @brief Get length that an attribute entry(type: string) will take
339 * @param[in] def_str_len - Length of default string
340 * @return The length that an entry(type: string) will take
341 */
342size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
343
344/** @brief Create an entry of BIOS Attribute Table (type: string)
345 * @param[out] entry - Pointer to a buffer to create an entry
346 * @param[in] entry_length - Length of the buffer to create an entry
347 * @param[in] info - Pointer to an auxiliary structure @ref
348 * pldm_bios_table_attr_entry_string_info
349 */
350void pldm_bios_table_attr_entry_string_encode(
351 void *entry, size_t entry_length,
352 const struct pldm_bios_table_attr_entry_string_info *info);
353
354/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
355 * validity of the parameters
356 * @param[out] entry - Pointer to a buffer to create an entry
357 * @param[in] entry_length - Length of the buffer to create an entry
358 * @param[in] info - Pointer to an auxiliary structure @ref
359 * pldm_bios_table_attr_entry_string_info
360 * @return pldm_completion_codes
361 */
362int pldm_bios_table_attr_entry_string_encode_check(
363 void *entry, size_t entry_length,
364 const struct pldm_bios_table_attr_entry_string_info *info);
365
John Wang02700402019-10-06 16:34:29 +0800366/** @brief Get the length of default string in bytes for the entry
367 * @param[in] entry - Pointer to bios attribute table entry
368 * @return length of default string in bytes
369 */
370uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
371 const struct pldm_bios_attr_table_entry *entry);
372
373/** @brief Get the length of default string in bytes for the entry and check the
374 * validity of the parameters
375 * @param[in] entry - Pointer to bios attribute table entry
376 * @param[out] def_string_length Pointer to length of default string in bytes
377 * @return pldm_completion_codes
378 */
379int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
380 const struct pldm_bios_attr_table_entry *entry,
381 uint16_t *def_string_length);
382
John Wangb0da7a02020-01-07 16:55:00 +0800383/** @brief Get the type of string of bios attribute table entry
384 * @param[in] entry - Pointer to bios attribute table entry
385 * @return Type of the string
386 */
387uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
388 const struct pldm_bios_attr_table_entry *entry);
389
John Wang50218a62020-02-12 17:10:28 +0800390/** @brief Get maximum length of the string from a bios attribute table entry in
391 * bytes
392 * @param[in] entry - Pointer to a bios attribute table entry
393 * @return Maximum length of the string
394 */
395uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
396 const struct pldm_bios_attr_table_entry *entry);
397
398/** @brief Get minimum length of the string from a bios attribute table entry in
399 * bytes
400 * @param[in] entry - Pointer to a bios attribute table entry
401 * @return Minimum length of the string
402 */
403uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
404 const struct pldm_bios_attr_table_entry *entry);
405
406/** @brief Get the default string from a bios attribute table entry
407 * @param[out] buffer - Pointer to a buffer to store the string
408 * @param[in] size - Size of the buffer to store the string
409 * @return Length of the string decoded
410 */
411uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
412 const struct pldm_bios_attr_table_entry *entry, char *buffer, size_t size);
413
John Wangca230822019-10-16 11:39:27 +0800414/** @struct pldm_bios_table_attr_entry_integer_info
415 *
416 * An auxiliary structure for passing parameters to @ref
417 * pldm_bios_table_attr_entry_integer_encode
418 *
419 */
420struct pldm_bios_table_attr_entry_integer_info {
421 uint16_t name_handle; //!< attribute name handle
422 bool read_only; //!< indicate whether the attribute is read-only
423 uint64_t lower_bound; //!< The lower bound on the integer value
424 uint64_t upper_bound; //!< The upper bound on the integer value
425 uint32_t scalar_increment; //!< The scalar value that is used for the
426 //!< increments to this integer
427 uint64_t default_value; //!< The default value of the integer
428};
429
John Wang827c5de2019-11-07 18:27:27 +0800430/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
431 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
432 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
433 * memory
434 * @return pldm_completion_codes
435 */
436int pldm_bios_table_attr_entry_integer_info_check(
437 const struct pldm_bios_table_attr_entry_integer_info *info,
438 const char **errmsg);
439
John Wangca230822019-10-16 11:39:27 +0800440/** @brief Get length that an attribute entry(type: integer) will take
441 * @return The length that an entry(type: integer) will take
442 */
443size_t pldm_bios_table_attr_entry_integer_encode_length();
444
445/** @brief Create an entry of BIOS Attribute Table (type: integer)
446 * @param[out] entry - Pointer to a buffer to create an entry
447 * @param[in] entry_length - Length of the buffer to create an entry
448 * @param[in] info - Pointer to an auxiliary structure @ref
449 * pldm_bios_table_attr_entry_integer_info
450 */
451void pldm_bios_table_attr_entry_integer_encode(
452 void *entry, size_t entry_length,
453 const struct pldm_bios_table_attr_entry_integer_info *info);
454
455/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
456 * validity of the parameters
457 * @param[out] entry - Pointer to a buffer to create an entry
458 * @param[in] entry_length - Length of the buffer to create an entry
459 * @param[in] info - Pointer to an auxiliary structure @ref
460 * pldm_bios_table_attr_entry_integer_info
461 * @return pldm_completion_codes
462 */
463int pldm_bios_table_attr_entry_integer_encode_check(
464 void *entry, size_t entry_length,
465 const struct pldm_bios_table_attr_entry_integer_info *info);
466
John Wang50218a62020-02-12 17:10:28 +0800467/** @brief Decode the specific fields(integer) of attribute table entry
468 * @param[in] entry - Pointer to an entry of attribute table
469 * @param[out] lower - The lower bound on the integer value
470 * @param[out] upper - The upper bound on the integer value
471 * @param[out] scalar - The scalar value that is used for the increments to
472 * this integer
473 * @param[out] def - The default value of the integer
474 */
475void pldm_bios_table_attr_entry_integer_decode(
476 const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
477 uint64_t *upper, uint32_t *scalar, uint64_t *def);
478
John Wangb0da7a02020-01-07 16:55:00 +0800479/** @brief Get the attribute handle from the attribute value table entry
480 * @param[in] entry - Pointer to bios attribute value table entry
481 * @return handle to identify the attribute in the attribute value table
482 */
483uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
484 const struct pldm_bios_attr_val_table_entry *entry);
485
486/** @brief Get the attribute type from the attribute value table entry
487 * @param[in] entry - Pointer to bios attribute value table entry
488 * @return Type of the attribute value entry
489 */
490uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
491 const struct pldm_bios_attr_val_table_entry *entry);
492
John Wang3ad21752019-10-06 16:42:21 +0800493/** @brief Get length that an attribute value entry(type: enum) will take
494 * @param[in] count - Total number of current values for this enumeration
495 * @return The length that an entry(type: enum) will take
496 */
497size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
498
499/** @brief Create an attribute value entry(type: enum)
500 * @param[out] entry - Pointer to bios attribute value entry
501 * @param[in] entry_length - Length of attribute value entry
502 * @param[in] attr_handle - This handle points to an attribute in the
503 * BIOS Attribute Vlaue Table.
504 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
505 * Table
506 * @param[in] count - Total number of current values for this enum attribute
507 * @param[in] handle_indexes - Index into the array(provided in the BIOS
508 * Attribute Table) of the possible values of string handles for this attribute.
509 */
510void pldm_bios_table_attr_value_entry_encode_enum(
511 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
512 uint8_t count, uint8_t *handle_indexes);
513
John Wang49484a12019-12-02 14:21:53 +0800514/** @brief Get number of current values for the enum entry
515 * @param[in] entry - Pointer to bios attribute value table entry
516 * @return Total number of current values for this enumeration
517 */
518uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
519 const struct pldm_bios_attr_val_table_entry *entry);
520
John Wangb0da7a02020-01-07 16:55:00 +0800521/** @brief Get CurrentValueStringHandleIndex
522 * @param[in] entry - Pointer to bios attribute value table entry
523 * @param[in, out] handles - Pointer to a buffer to store
524 * CurrentValueStringHandleIndex
525 * @param[in] number - Number of PossibleValuesStringHandles expected
526 * @return Number of CurrentValueStringHandleIndex decoded.
527 */
528uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
529 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
530 uint8_t number);
531
John Wang3ad21752019-10-06 16:42:21 +0800532/** @brief Create an attribute value entry(type: enum) and check the validity of
533 * the parameters
534 * @param[out] entry - Pointer to bios attribute value entry
535 * @param[in] entry_length - Length of attribute value entry
536 * @param[in] attr_handle - This handle points to an attribute in the
537 * BIOS Attribute Vlaue Table.
538 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
539 * Table
540 * @param[in] count - Total number of current values for this enum attribute
541 * @param[in] handle_indexes - Index into the array(provided in the BIOS
542 * Attribute Table) of the possible values of string handles for this attribute.
543 * @return pldm_completion_codes
544 */
545int pldm_bios_table_attr_value_entry_encode_enum_check(
546 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
547 uint8_t count, uint8_t *handle_indexes);
548
549/** @brief Get length that an attribute value entry(type: string) will take
550 * @param[in] string_length - Length of the current string in byte, 0 indicates
551 * that the current string value is not set.
552 * @return The length that an entry(type: string) will take
553 */
554size_t
555pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
556
557/** @brief Create an attribute value entry(type: string)
558 * @param[out] entry - Pointer to bios attribute value entry
559 * @param[in] entry_length - Length of attribute value entry
560 * @param[in] attr_handle - This handle points to an attribute in the
561 * BIOS Attribute Vlaue Table.
562 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
563 * Table
564 * @param[in] string_length - Length of current string in bytes. 0 indicates
565 * that the current string value is not set.
566 * @param[in] string - The current string itsel
567 */
568void pldm_bios_table_attr_value_entry_encode_string(
569 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
570 uint16_t string_length, const char *string);
John Wang49484a12019-12-02 14:21:53 +0800571
572/** @brief Get length of the current string in bytes
573 * @param [in] entry - Pointer to bios attribute value table entry
574 * @return The length of the current string in bytes
575 */
576uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
577 const struct pldm_bios_attr_val_table_entry *entry);
578
John Wangb0da7a02020-01-07 16:55:00 +0800579/** @brief Get Current String Itself
580 * @param[in] entry - Pointer to bios attribute value table entry
581 * @param[in, out] current_string - Struct variable_field, contains a pointer
582 * to the CurrentString field in the buffer of
583 * \p entry, \p entry must be valid
584 * when \p current_string is used.
585 */
586void pldm_bios_table_attr_value_entry_string_decode_string(
587 const struct pldm_bios_attr_val_table_entry *entry,
588 struct variable_field *current_string);
589
John Wang3ad21752019-10-06 16:42:21 +0800590/** @brief Create an attribute value entry(type: string) and check the validity
591 * of the parameters
592 * @param[out] entry - Pointer to bios attribute value entry
593 * @param[in] entry_length - Length of attribute value entry
594 * @param[in] attr_handle - This handle points to an attribute in the
595 * BIOS Attribute Vlaue Table.
596 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
597 * Table
598 * @param[in] string_length - Length of current string in bytes. 0 indicates
599 * that the current string value is not set.
600 * @param[in] string - The current string itsel
601 * @return pldm_completion_codes
602 */
603int pldm_bios_table_attr_value_entry_encode_string_check(
604 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
605 uint16_t string_length, const char *string);
606
John Wangca230822019-10-16 11:39:27 +0800607/** @brief Get length that an attribute value entry(type: integer) will take
608 * @return The length that an entry(type: integer) will take
609 */
610size_t pldm_bios_table_attr_value_entry_encode_integer_length();
611
612/** @brief Create an attribute value entry(type: integer)
613 * @param[out] entry - Pointer to bios attribute value entry
614 * @param[in] entry_length - Length of attribute value entry
615 * @param[in] attr_handle - This handle points to an attribute in the
616 * BIOS Attribute Vlaue Table.
617 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
618 * Table
619 * @param[in] cv - Current Value
620 */
621void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
622 size_t entry_length,
623 uint16_t attr_handle,
624 uint8_t attr_type,
625 uint64_t cv);
626
John Wangb0da7a02020-01-07 16:55:00 +0800627/** @brief Get current values for the integer entry
628 * @param[in] entry - Pointer to bios attribute value table entry
629 * @return Current Value
630 */
631uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
632 const struct pldm_bios_attr_val_table_entry *entry);
633
John Wangca230822019-10-16 11:39:27 +0800634/** @brief Create an attribute value entry(type: integer) and check the validity
635 * of the parameters
636 * @param[out] entry - Pointer to bios attribute value entry
637 * @param[in] entry_length - Length of attribute value entry
638 * @param[in] attr_handle - This handle points to an attribute in the
639 * BIOS Attribute Vlaue Table.
640 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
641 * Table
642 * @param[in] cv - Current Value
643 * @return pldm_completion_codes
644 */
645int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
646 size_t entry_length,
647 uint16_t attr_handle,
648 uint8_t attr_type,
649 uint64_t cv);
John Wang79c37f12019-10-31 15:46:31 +0800650
John Wang3342adb2019-11-29 16:03:58 +0800651/** @brief Get the handle from the attribute value entry
652 * @param[in] entry - Pointer to bios attribute value entry
653 * @return handle to identify the attribute in the attribute value table
654 */
655uint16_t pldm_bios_table_attr_value_entry_decode_handle(
656 const struct pldm_bios_attr_val_table_entry *entry);
657
John Wang8e877e02020-02-03 16:06:55 +0800658/** @brief Get the length of the attribute value entry
John Wang3342adb2019-11-29 16:03:58 +0800659 * @param[in] entry - Pointer to bios attribute value entry
John Wang8e877e02020-02-03 16:06:55 +0800660 * @return Length of the entry
John Wang3342adb2019-11-29 16:03:58 +0800661 */
John Wang8e877e02020-02-03 16:06:55 +0800662size_t pldm_bios_table_attr_value_entry_length(
John Wang3342adb2019-11-29 16:03:58 +0800663 const struct pldm_bios_attr_val_table_entry *entry);
664
665/** @brief Find an entry in attribute value table by handle
666 * @param[in] table - The BIOS Attribute Value Table
667 * @param[in] length - Length of the BIOS Attribute Value Table
668 * @param[in] handle - handle to identify the attribute in the attribute value
669 * table
670 * @return Pointer to the entry
671 */
672const struct pldm_bios_attr_val_table_entry *
673pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
674 uint16_t handle);
675
John Wang79c37f12019-10-31 15:46:31 +0800676/** @brief Get the size of pad and checksum
677 * @param[in] size_without_pad - Table size without pad
678 * @return The size of pad and checksum
679 */
680size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
681
682/** @brief Append pad and checksum at the end of the table
683 * @param[in,out] table - Pointer to a buffer of a bios table
684 * @param[in] size - Size of the buffer of a bios table
685 * @param[in] size_without_pad - Table size without pad and checksum
John Wang871c9272019-12-09 18:02:15 +0800686 * @return Total size of the table
John Wang79c37f12019-10-31 15:46:31 +0800687 */
John Wang871c9272019-12-09 18:02:15 +0800688size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
689 size_t size_without_pad);
690
691/** @brief Build a new table and update an entry
692 * @param[in] src_table - Pointer to the source table
693 * @param[in] src_length - Size of the source table
694 * @param[out] dest_table - Pointer to the buffer of destination table
695 * @param[in,out] dest_length - Buffer size of the destination table as input
696 * parameter and will be assigned the length of
697 * the new table, if the function returns
698 * PLDM_SUCCESS
699 * @param[in] entry - Pointer to an entry
700 * @param[in] entry_length - Size of the entry
701 * @return pldm_completion_codes
702 */
703int pldm_bios_table_attr_value_copy_and_update(
704 const void *src_table, size_t src_length, void *dest_table,
705 size_t *dest_length, const void *entry, size_t entry_length);
John Wang79c37f12019-10-31 15:46:31 +0800706
John Wang02700402019-10-06 16:34:29 +0800707#ifdef __cplusplus
708}
709#endif
710
711#endif