blob: 5a07e7b49437dd38ba66303b83ffe393c66925d8 [file] [log] [blame]
Andrew Jeffery4edb7082023-04-05 19:09:52 +09301#ifndef LIBPLDM_BIOS_TABLE_H
2#define LIBPLDM_BIOS_TABLE_H
Andrew Jeffery9c766792022-08-10 23:12:49 +09303
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "bios.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09309#include <stdbool.h>
10#include <stddef.h>
11#include <stdint.h>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +053012struct variable_field;
Andrew Jeffery9c766792022-08-10 23:12:49 +093013
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
63/** @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
74/** @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
85/** @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
167/** @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
174/** @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
181/** @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
199/** @brief Find an entry in attribute table by string handle
200 * @param[in] table - The BIOS Attribute Table
201 * @param[in] length - Length of the BIOS Attribute Table
202 * @param[in] handle - The string handle
203 * @return Pointer to the entry
204 */
205const struct pldm_bios_attr_table_entry *
206pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
207 uint16_t handle);
208
209/** @struct pldm_bios_table_attr_entry_enum_info
210 *
211 * An auxiliary structure for passing parameters to @ref
212 * pldm_bios_table_attr_entry_enum_encode
213 *
214 */
215struct pldm_bios_table_attr_entry_enum_info {
216 uint16_t name_handle; //!< attribute name handle
217 bool read_only; //!< indicate whether the attribute is read-only
218 uint8_t pv_num; //!< number of possible values
219 const uint16_t *pv_handle; //!< handles of possible values
220 uint8_t def_num; //!< nnumber of default values
221 const uint8_t *def_index; //!< indices of default values.
222};
223
224/** @brief Get length that an attribute entry(type: enum) will take
225 * @param[in] pv_num - Number of possible values
226 * @param[in] def_num - Number of default values
227 * @return The length that an entry(type: enum) will take
228 */
229size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
230 uint8_t def_num);
231
232/** @brief Create an entry of BIOS Attribute Table (type: enum)
233 * @param[out] entry - Pointer to a buffer to create an entry
234 * @param[in] entry_length - Length of the buffer to create an entry
235 * @param[in] info - Pointer to an auxiliary structure @ref
236 * pldm_bios_table_attr_entry_enum_info
237 */
238void pldm_bios_table_attr_entry_enum_encode(
239 void *entry, size_t entry_length,
240 const struct pldm_bios_table_attr_entry_enum_info *info);
241
242/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
243 * validity of the parameters
244 * @param[out] entry - Pointer to a buffer to create an entry
245 * @param[in] entry_length - Length of the buffer to create an entry
246 * @param[in] info - Pointer to an auxiliary structure @ref
247 * pldm_bios_table_attr_entry_enum_info
248 * @return pldm_completion_codes
249 */
250int pldm_bios_table_attr_entry_enum_encode_check(
251 void *entry, size_t entry_length,
252 const struct pldm_bios_table_attr_entry_enum_info *info);
253
254/** @brief Get the total number of possible values for the entry
255 * @param[in] entry - Pointer to bios attribute table entry
256 * @return total number of possible values
257 */
258uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
259 const struct pldm_bios_attr_table_entry *entry);
260
261/** @brief Get the total number of possible values for the entry and check the
262 * validity of the parameters
263 * @param[in] entry - Pointer to bios attribute table entry
264 * @param[out] pv_num - Pointer to total number of possible values
265 * @return pldm_completion_codes
266 */
267int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
268 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
269
270/** @brief Get the total number of default values for the entry
271 * @param[in] entry - Pointer to bios attribute table entry
272 * @return total number of default values
273 */
274uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
275 const struct pldm_bios_attr_table_entry *entry);
276
277/** @brief Get the total number of default values for the entry and check the
278 * validity of the parameters
279 * @param[in] entry - Pointer to bios attribute table entry
280 * @param[out] def_num - Pointer to total number of default values
281 * @return pldm_completion_codes
282 */
283int pldm_bios_table_attr_entry_enum_decode_def_num_check(
284 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
285
286/** @brief Get possible values string handles
287 * @param[in] entry - Pointer to bios attribute table entry
288 * @param[out] pv_hdls - Pointer to a buffer to stroe
289 * PossibleValuesStringHandles
290 * @param[in] pv_num - Number of PossibleValuesStringHandles expected
291 * @return pldm_completion_codes
292 */
293uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
294 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
295 uint8_t pv_num);
296
297/** @brief Get possible values string handles and check the validity of the
298 * parameters
299 * @param[in] entry - Pointer to bios attribute table entry
300 * @param[out] pv_hdls - Pointer to a buffer to stroe
301 * PossibleValuesStringHandles
302 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
303 * stroe
304 * @return Number of PossibleValuesStringHandles decoded
305 */
306int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
307 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
308 uint8_t pv_num);
309
310/** @brief Get Indices of default values
311 * @param[in] entry - Pointer to bios attribute table entry
312 * @param[out] def_indices - Pointer to a buffer to store
313 * default value indices
314 * @param[in] def_num - Number of DefaultValues the buffer can
315 * store
316 * @return Number of default values decoded
317 */
318uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
319 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
320 uint8_t def_num);
321
322/** @struct pldm_bios_table_attr_entry_string_info
323 *
324 * An auxiliary structure for passing parameters to @ref
325 * pldm_bios_table_attr_entry_string_encode
326 *
327 */
328struct pldm_bios_table_attr_entry_string_info {
329 uint16_t name_handle; //!< attribute name handle
330 bool read_only; //!< indicate whether the attribute is read-only
331 uint8_t string_type; //!< The type of the string
332 uint16_t min_length; //!< The minimum length of the string in bytes
333 uint16_t max_length; //!< The maximum length of the string in bytes
334 uint16_t def_length; //!< The length of the defaut string in bytes
335 const char *def_string; //!< The default string itself
336};
337
338/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
339 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
340 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
341 * memory
342 * @return pldm_completion_codes
343 */
344int pldm_bios_table_attr_entry_string_info_check(
345 const struct pldm_bios_table_attr_entry_string_info *info,
346 const char **errmsg);
347
348/** @brief Get length that an attribute entry(type: string) will take
349 * @param[in] def_str_len - Length of default string
350 * @return The length that an entry(type: string) will take
351 */
352size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
353
354/** @brief Create an entry of BIOS Attribute Table (type: string)
355 * @param[out] entry - Pointer to a buffer to create an entry
356 * @param[in] entry_length - Length of the buffer to create an entry
357 * @param[in] info - Pointer to an auxiliary structure @ref
358 * pldm_bios_table_attr_entry_string_info
359 */
360void pldm_bios_table_attr_entry_string_encode(
361 void *entry, size_t entry_length,
362 const struct pldm_bios_table_attr_entry_string_info *info);
363
364/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
365 * validity of the parameters
366 * @param[out] entry - Pointer to a buffer to create an entry
367 * @param[in] entry_length - Length of the buffer to create an entry
368 * @param[in] info - Pointer to an auxiliary structure @ref
369 * pldm_bios_table_attr_entry_string_info
370 * @return pldm_completion_codes
371 */
372int pldm_bios_table_attr_entry_string_encode_check(
373 void *entry, size_t entry_length,
374 const struct pldm_bios_table_attr_entry_string_info *info);
375
376/** @brief Get the length of default string in bytes for the entry
377 * @param[in] entry - Pointer to bios attribute table entry
378 * @return length of default string in bytes
379 */
380uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
381 const struct pldm_bios_attr_table_entry *entry);
382
383/** @brief Get the length of default string in bytes for the entry and check the
384 * validity of the parameters
385 * @param[in] entry - Pointer to bios attribute table entry
386 * @param[out] def_string_length Pointer to length of default string in bytes
387 * @return pldm_completion_codes
388 */
389int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
390 const struct pldm_bios_attr_table_entry *entry,
391 uint16_t *def_string_length);
392
393/** @brief Get the type of string of bios attribute table entry
394 * @param[in] entry - Pointer to bios attribute table entry
395 * @return Type of the string
396 */
397uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
398 const struct pldm_bios_attr_table_entry *entry);
399
400/** @brief Get maximum length of the string from a bios attribute table entry in
401 * bytes
402 * @param[in] entry - Pointer to a bios attribute table entry
403 * @return Maximum length of the string
404 */
405uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
406 const struct pldm_bios_attr_table_entry *entry);
407
408/** @brief Get minimum length of the string from a bios attribute table entry in
409 * bytes
410 * @param[in] entry - Pointer to a bios attribute table entry
411 * @return Minimum length of the string
412 */
413uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
414 const struct pldm_bios_attr_table_entry *entry);
415
416/** @brief Get the default string from a bios attribute table entry
417 * @param[out] buffer - Pointer to a buffer to store the string
418 * @param[in] size - Size of the buffer to store the string
419 * @return Length of the string decoded
420 */
421uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
422 const struct pldm_bios_attr_table_entry *entry, char *buffer, size_t size);
423
424/** @struct pldm_bios_table_attr_entry_integer_info
425 *
426 * An auxiliary structure for passing parameters to @ref
427 * pldm_bios_table_attr_entry_integer_encode
428 *
429 */
430struct pldm_bios_table_attr_entry_integer_info {
431 uint16_t name_handle; //!< attribute name handle
432 bool read_only; //!< indicate whether the attribute is read-only
433 uint64_t lower_bound; //!< The lower bound on the integer value
434 uint64_t upper_bound; //!< The upper bound on the integer value
435 uint32_t scalar_increment; //!< The scalar value that is used for the
436 //!< increments to this integer
437 uint64_t default_value; //!< The default value of the integer
438};
439
440/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
441 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
442 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
443 * memory
444 * @return pldm_completion_codes
445 */
446int pldm_bios_table_attr_entry_integer_info_check(
447 const struct pldm_bios_table_attr_entry_integer_info *info,
448 const char **errmsg);
449
450/** @brief Get length that an attribute entry(type: integer) will take
451 * @return The length that an entry(type: integer) will take
452 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930453size_t pldm_bios_table_attr_entry_integer_encode_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930454
455/** @brief Create an entry of BIOS Attribute Table (type: integer)
456 * @param[out] entry - Pointer to a buffer to create an entry
457 * @param[in] entry_length - Length of the buffer to create an entry
458 * @param[in] info - Pointer to an auxiliary structure @ref
459 * pldm_bios_table_attr_entry_integer_info
460 */
461void pldm_bios_table_attr_entry_integer_encode(
462 void *entry, size_t entry_length,
463 const struct pldm_bios_table_attr_entry_integer_info *info);
464
465/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
466 * validity of the parameters
467 * @param[out] entry - Pointer to a buffer to create an entry
468 * @param[in] entry_length - Length of the buffer to create an entry
469 * @param[in] info - Pointer to an auxiliary structure @ref
470 * pldm_bios_table_attr_entry_integer_info
471 * @return pldm_completion_codes
472 */
473int pldm_bios_table_attr_entry_integer_encode_check(
474 void *entry, size_t entry_length,
475 const struct pldm_bios_table_attr_entry_integer_info *info);
476
477/** @brief Decode the specific fields(integer) of attribute table entry
478 * @param[in] entry - Pointer to an entry of attribute table
479 * @param[out] lower - The lower bound on the integer value
480 * @param[out] upper - The upper bound on the integer value
481 * @param[out] scalar - The scalar value that is used for the increments to
482 * this integer
483 * @param[out] def - The default value of the integer
484 */
485void pldm_bios_table_attr_entry_integer_decode(
486 const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
487 uint64_t *upper, uint32_t *scalar, uint64_t *def);
488
489/** @brief Get the attribute handle from the attribute value table entry
490 * @param[in] entry - Pointer to bios attribute value table entry
491 * @return handle to identify the attribute in the attribute value table
492 */
493uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
494 const struct pldm_bios_attr_val_table_entry *entry);
495
496/** @brief Get the attribute type from the attribute value table entry
497 * @param[in] entry - Pointer to bios attribute value table entry
498 * @return Type of the attribute value entry
499 */
500uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
501 const struct pldm_bios_attr_val_table_entry *entry);
502
503/** @brief Get length that an attribute value entry(type: enum) will take
504 * @param[in] count - Total number of current values for this enumeration
505 * @return The length that an entry(type: enum) will take
506 */
507size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
508
509/** @brief Create an attribute value entry(type: enum)
510 * @param[out] entry - Pointer to bios attribute value entry
511 * @param[in] entry_length - Length of attribute value entry
512 * @param[in] attr_handle - This handle points to an attribute in the
513 * BIOS Attribute Vlaue Table.
514 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
515 * Table
516 * @param[in] count - Total number of current values for this enum attribute
517 * @param[in] handle_indexes - Index into the array(provided in the BIOS
518 * Attribute Table) of the possible values of string handles for this attribute.
519 */
520void pldm_bios_table_attr_value_entry_encode_enum(
521 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
Andrew Jeffery9145a412023-04-05 20:24:50 +0930522 uint8_t count, const uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930523
524/** @brief Get number of current values for the enum entry
525 * @param[in] entry - Pointer to bios attribute value table entry
526 * @return Total number of current values for this enumeration
527 */
528uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
529 const struct pldm_bios_attr_val_table_entry *entry);
530
531/** @brief Get CurrentValueStringHandleIndex
532 * @param[in] entry - Pointer to bios attribute value table entry
533 * @param[in, out] handles - Pointer to a buffer to store
534 * CurrentValueStringHandleIndex
535 * @param[in] number - Number of PossibleValuesStringHandles expected
536 * @return Number of CurrentValueStringHandleIndex decoded.
537 */
538uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
539 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
540 uint8_t number);
541
542/** @brief Create an attribute value entry(type: enum) and check the validity of
543 * the parameters
544 * @param[out] entry - Pointer to bios attribute value entry
545 * @param[in] entry_length - Length of attribute value entry
546 * @param[in] attr_handle - This handle points to an attribute in the
547 * BIOS Attribute Vlaue Table.
548 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
549 * Table
550 * @param[in] count - Total number of current values for this enum attribute
551 * @param[in] handle_indexes - Index into the array(provided in the BIOS
552 * Attribute Table) of the possible values of string handles for this attribute.
553 * @return pldm_completion_codes
554 */
555int pldm_bios_table_attr_value_entry_encode_enum_check(
556 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
Andrew Jeffery9145a412023-04-05 20:24:50 +0930557 uint8_t count, uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930558
559/** @brief Get length that an attribute value entry(type: string) will take
560 * @param[in] string_length - Length of the current string in byte, 0 indicates
561 * that the current string value is not set.
562 * @return The length that an entry(type: string) will take
563 */
564size_t
565pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
566
567/** @brief Create an attribute value entry(type: string)
568 * @param[out] entry - Pointer to bios attribute value entry
569 * @param[in] entry_length - Length of attribute value entry
570 * @param[in] attr_handle - This handle points to an attribute in the
571 * BIOS Attribute Vlaue Table.
572 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
573 * Table
574 * @param[in] string_length - Length of current string in bytes. 0 indicates
575 * that the current string value is not set.
576 * @param[in] string - The current string itsel
577 */
578void pldm_bios_table_attr_value_entry_encode_string(
579 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
Andrew Jeffery9145a412023-04-05 20:24:50 +0930580 uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930581
582/** @brief Get length of the current string in bytes
583 * @param [in] entry - Pointer to bios attribute value table entry
584 * @return The length of the current string in bytes
585 */
586uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
587 const struct pldm_bios_attr_val_table_entry *entry);
588
589/** @brief Get Current String Itself
590 * @param[in] entry - Pointer to bios attribute value table entry
591 * @param[in, out] current_string - Struct variable_field, contains a pointer
592 * to the CurrentString field in the buffer of
593 * \p entry, \p entry must be valid
594 * when \p current_string is used.
595 */
596void pldm_bios_table_attr_value_entry_string_decode_string(
597 const struct pldm_bios_attr_val_table_entry *entry,
598 struct variable_field *current_string);
599
600/** @brief Create an attribute value entry(type: string) and check the validity
601 * of the parameters
602 * @param[out] entry - Pointer to bios attribute value entry
603 * @param[in] entry_length - Length of attribute value entry
604 * @param[in] attr_handle - This handle points to an attribute in the
605 * BIOS Attribute Vlaue Table.
606 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
607 * Table
608 * @param[in] string_length - Length of current string in bytes. 0 indicates
609 * that the current string value is not set.
610 * @param[in] string - The current string itsel
611 * @return pldm_completion_codes
612 */
613int pldm_bios_table_attr_value_entry_encode_string_check(
614 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
Andrew Jeffery9145a412023-04-05 20:24:50 +0930615 uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930616
617/** @brief Get length that an attribute value entry(type: integer) will take
618 * @return The length that an entry(type: integer) will take
619 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930620size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930621
622/** @brief Create an attribute value entry(type: integer)
623 * @param[out] entry - Pointer to bios attribute value entry
624 * @param[in] entry_length - Length of attribute value entry
625 * @param[in] attr_handle - This handle points to an attribute in the
626 * BIOS Attribute Vlaue Table.
627 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
628 * Table
629 * @param[in] cv - Current Value
630 */
631void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
632 size_t entry_length,
633 uint16_t attr_handle,
634 uint8_t attr_type,
635 uint64_t cv);
636
637/** @brief Get current values for the integer entry
638 * @param[in] entry - Pointer to bios attribute value table entry
639 * @return Current Value
640 */
641uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
642 const struct pldm_bios_attr_val_table_entry *entry);
643
644/** @brief Create an attribute value entry(type: integer) and check the validity
645 * of the parameters
646 * @param[out] entry - Pointer to bios attribute value entry
647 * @param[in] entry_length - Length of attribute value entry
648 * @param[in] attr_handle - This handle points to an attribute in the
649 * BIOS Attribute Vlaue Table.
650 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
651 * Table
652 * @param[in] cv - Current Value
653 * @return pldm_completion_codes
654 */
655int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
656 size_t entry_length,
657 uint16_t attr_handle,
658 uint8_t attr_type,
659 uint64_t cv);
660
661/** @brief Get the handle from the attribute value entry
662 * @param[in] entry - Pointer to bios attribute value entry
663 * @return handle to identify the attribute in the attribute value table
664 */
665uint16_t pldm_bios_table_attr_value_entry_decode_handle(
666 const struct pldm_bios_attr_val_table_entry *entry);
667
668/** @brief Get the length of the attribute value entry
669 * @param[in] entry - Pointer to bios attribute value entry
670 * @return Length of the entry
671 */
672size_t pldm_bios_table_attr_value_entry_length(
673 const struct pldm_bios_attr_val_table_entry *entry);
674
675/** @brief Find an entry in attribute value table by handle
676 * @param[in] table - The BIOS Attribute Value Table
677 * @param[in] length - Length of the BIOS Attribute Value Table
678 * @param[in] handle - handle to identify the attribute in the attribute value
679 * table
680 * @return Pointer to the entry
681 */
682const struct pldm_bios_attr_val_table_entry *
683pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
684 uint16_t handle);
685
686/** @brief Get the size of pad and checksum
687 * @param[in] size_without_pad - Table size without pad
688 * @return The size of pad and checksum
689 */
690size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
691
692/** @brief Append pad and checksum at the end of the table
693 * @param[in,out] table - Pointer to a buffer of a bios table
694 * @param[in] size - Size of the buffer of a bios table
695 * @param[in] size_without_pad - Table size without pad and checksum
696 * @return Total size of the table
697 */
698size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
699 size_t size_without_pad);
700
701/** @brief Build a new table and update an entry
702 * @param[in] src_table - Pointer to the source table
703 * @param[in] src_length - Size of the source table
704 * @param[out] dest_table - Pointer to the buffer of destination table
705 * @param[in,out] dest_length - Buffer size of the destination table as input
706 * parameter and will be assigned the length of
707 * the new table, if the function returns
708 * PLDM_SUCCESS
709 * @param[in] entry - Pointer to an entry
710 * @param[in] entry_length - Size of the entry
711 * @return pldm_completion_codes
712 */
713int pldm_bios_table_attr_value_copy_and_update(
714 const void *src_table, size_t src_length, void *dest_table,
715 size_t *dest_length, const void *entry, size_t entry_length);
716
717/** @brief Verify the crc value of the complete table
718 * @param[in] table - Pointer to a buffer of a bios table
719 * @param[in] size - Size of the buffer of a bios table
720 * @return true: crc value is correct
721 */
722bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
723
724#ifdef __cplusplus
725}
726#endif
727
728#endif