blob: 298ba7ef0d75a3c5047ff6c520b181209a882093 [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
174/** @brief Get the attribute name handle from the attribute table entry
175 * @param[in] entry - Pointer to bios attribute table entry
176 * @return handle to identify the name of the attribute, this handle points
177 * to a string in the bios string table.
178 */
179uint16_t pldm_bios_table_attr_entry_decode_string_handle(
180 const struct pldm_bios_attr_table_entry *entry);
181
182/** @brief Find an entry in attribute table by handle
183 * @param[in] table - The BIOS Attribute Table
184 * @param[in] length - Length of the BIOS Attribute Table
185 * @param[in] handle - handle to identify the attribute in the attribute table
186 * @return Pointer to the entry
187 */
188const struct pldm_bios_attr_table_entry *
189pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
190 uint16_t handle);
191
John Wangccc04552019-10-14 14:28:25 +0800192/** @struct pldm_bios_table_attr_entry_enum_info
193 *
194 * An auxiliary structure for passing parameters to @ref
195 * pldm_bios_table_attr_entry_enum_encode
196 *
197 */
198struct pldm_bios_table_attr_entry_enum_info {
199 uint16_t name_handle; //!< attribute name handle
200 bool read_only; //!< indicate whether the attribute is read-only
201 uint8_t pv_num; //!< number of possible values
202 const uint16_t *pv_handle; //!< handles of possible values
203 uint8_t def_num; //!< nnumber of default values
204 const uint8_t *def_index; //!< indices of default values.
205};
206
207/** @brief Get length that an attribute entry(type: enum) will take
208 * @param[in] pv_num - Number of possible values
209 * @param[in] def_num - Number of default values
210 * @return The length that an entry(type: enum) will take
211 */
212size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
213 uint8_t def_num);
214
215/** @brief Create an entry of BIOS Attribute Table (type: enum)
216 * @param[out] entry - Pointer to a buffer to create an entry
217 * @param[in] entry_length - Length of the buffer to create an entry
218 * @param[in] info - Pointer to an auxiliary structure @ref
219 * pldm_bios_table_attr_entry_enum_info
220 */
221void pldm_bios_table_attr_entry_enum_encode(
222 void *entry, size_t entry_length,
223 const struct pldm_bios_table_attr_entry_enum_info *info);
224
225/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
226 * validity of the parameters
227 * @param[out] entry - Pointer to a buffer to create an entry
228 * @param[in] entry_length - Length of the buffer to create an entry
229 * @param[in] info - Pointer to an auxiliary structure @ref
230 * pldm_bios_table_attr_entry_enum_info
231 * @return pldm_completion_codes
232 */
233int pldm_bios_table_attr_entry_enum_encode_check(
234 void *entry, size_t entry_length,
235 const struct pldm_bios_table_attr_entry_enum_info *info);
236
John Wang02700402019-10-06 16:34:29 +0800237/** @brief Get the total number of possible values for the entry
238 * @param[in] entry - Pointer to bios attribute table entry
239 * @return total number of possible values
240 */
241uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
242 const struct pldm_bios_attr_table_entry *entry);
243
244/** @brief Get the total number of possible values for the entry and check the
245 * validity of the parameters
246 * @param[in] entry - Pointer to bios attribute table entry
247 * @param[out] pv_num - Pointer to total number of possible values
248 * @return pldm_completion_codes
249 */
250int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
251 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
252
253/** @brief Get the total number of default values for the entry
254 * @param[in] entry - Pointer to bios attribute table entry
255 * @return total number of default values
256 */
257uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
258 const struct pldm_bios_attr_table_entry *entry);
259
260/** @brief Get the total number of default values for the entry and check the
261 * validity of the parameters
262 * @param[in] entry - Pointer to bios attribute table entry
263 * @param[out] def_num - Pointer to total number of default values
264 * @return pldm_completion_codes
265 */
266int pldm_bios_table_attr_entry_enum_decode_def_num_check(
267 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
268
John Wang3ad21752019-10-06 16:42:21 +0800269/** @brief Get possible values string handles
270 * @param[in] entry - Pointer to bios attribute table entry
271 * @param[out] pv_hdls - Pointer to a buffer to stroe
272 * PossibleValuesStringHandles
273 * @param[in] pv_num - Number of PossibleValuesStringHandles expected
274 * @return pldm_completion_codes
275 */
276uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
277 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
278 uint8_t pv_num);
279
280/** @brief Get possible values string handles and check the validity of the
281 * parameters
282 * @param[in] entry - Pointer to bios attribute table entry
283 * @param[out] pv_hdls - Pointer to a buffer to stroe
284 * PossibleValuesStringHandles
285 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
286 * stroe
287 * @return Number of PossibleValuesStringHandles decoded
288 */
289int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
290 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
291 uint8_t pv_num);
292
John Wangccc04552019-10-14 14:28:25 +0800293/** @struct pldm_bios_table_attr_entry_string_info
294 *
295 * An auxiliary structure for passing parameters to @ref
296 * pldm_bios_table_attr_entry_string_encode
297 *
298 */
299struct pldm_bios_table_attr_entry_string_info {
300 uint16_t name_handle; //!< attribute name handle
301 bool read_only; //!< indicate whether the attribute is read-only
302 uint8_t string_type; //!< The type of the string
303 uint16_t min_length; //!< The minimum length of the string in bytes
304 uint16_t max_length; //!< The maximum length of the string in bytes
305 uint16_t def_length; //!< The length of the defaut string in bytes
306 const char *def_string; //!< The default string itself
307};
308
John Wang827c5de2019-11-07 18:27:27 +0800309/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
310 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
311 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
312 * memory
313 * @return pldm_completion_codes
314 */
315int pldm_bios_table_attr_entry_string_info_check(
316 const struct pldm_bios_table_attr_entry_string_info *info,
317 const char **errmsg);
318
John Wangccc04552019-10-14 14:28:25 +0800319/** @brief Get length that an attribute entry(type: string) will take
320 * @param[in] def_str_len - Length of default string
321 * @return The length that an entry(type: string) will take
322 */
323size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
324
325/** @brief Create an entry of BIOS Attribute Table (type: string)
326 * @param[out] entry - Pointer to a buffer to create an entry
327 * @param[in] entry_length - Length of the buffer to create an entry
328 * @param[in] info - Pointer to an auxiliary structure @ref
329 * pldm_bios_table_attr_entry_string_info
330 */
331void pldm_bios_table_attr_entry_string_encode(
332 void *entry, size_t entry_length,
333 const struct pldm_bios_table_attr_entry_string_info *info);
334
335/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
336 * validity of the parameters
337 * @param[out] entry - Pointer to a buffer to create an entry
338 * @param[in] entry_length - Length of the buffer to create an entry
339 * @param[in] info - Pointer to an auxiliary structure @ref
340 * pldm_bios_table_attr_entry_string_info
341 * @return pldm_completion_codes
342 */
343int pldm_bios_table_attr_entry_string_encode_check(
344 void *entry, size_t entry_length,
345 const struct pldm_bios_table_attr_entry_string_info *info);
346
John Wang02700402019-10-06 16:34:29 +0800347/** @brief Get the length of default string in bytes for the entry
348 * @param[in] entry - Pointer to bios attribute table entry
349 * @return length of default string in bytes
350 */
351uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
352 const struct pldm_bios_attr_table_entry *entry);
353
354/** @brief Get the length of default string in bytes for the entry and check the
355 * validity of the parameters
356 * @param[in] entry - Pointer to bios attribute table entry
357 * @param[out] def_string_length Pointer to length of default string in bytes
358 * @return pldm_completion_codes
359 */
360int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
361 const struct pldm_bios_attr_table_entry *entry,
362 uint16_t *def_string_length);
363
John Wangb0da7a02020-01-07 16:55:00 +0800364/** @brief Get the type of string of bios attribute table entry
365 * @param[in] entry - Pointer to bios attribute table entry
366 * @return Type of the string
367 */
368uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
369 const struct pldm_bios_attr_table_entry *entry);
370
John Wangca230822019-10-16 11:39:27 +0800371/** @struct pldm_bios_table_attr_entry_integer_info
372 *
373 * An auxiliary structure for passing parameters to @ref
374 * pldm_bios_table_attr_entry_integer_encode
375 *
376 */
377struct pldm_bios_table_attr_entry_integer_info {
378 uint16_t name_handle; //!< attribute name handle
379 bool read_only; //!< indicate whether the attribute is read-only
380 uint64_t lower_bound; //!< The lower bound on the integer value
381 uint64_t upper_bound; //!< The upper bound on the integer value
382 uint32_t scalar_increment; //!< The scalar value that is used for the
383 //!< increments to this integer
384 uint64_t default_value; //!< The default value of the integer
385};
386
John Wang827c5de2019-11-07 18:27:27 +0800387/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
388 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
389 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
390 * memory
391 * @return pldm_completion_codes
392 */
393int pldm_bios_table_attr_entry_integer_info_check(
394 const struct pldm_bios_table_attr_entry_integer_info *info,
395 const char **errmsg);
396
John Wangca230822019-10-16 11:39:27 +0800397/** @brief Get length that an attribute entry(type: integer) will take
398 * @return The length that an entry(type: integer) will take
399 */
400size_t pldm_bios_table_attr_entry_integer_encode_length();
401
402/** @brief Create an entry of BIOS Attribute Table (type: integer)
403 * @param[out] entry - Pointer to a buffer to create an entry
404 * @param[in] entry_length - Length of the buffer to create an entry
405 * @param[in] info - Pointer to an auxiliary structure @ref
406 * pldm_bios_table_attr_entry_integer_info
407 */
408void pldm_bios_table_attr_entry_integer_encode(
409 void *entry, size_t entry_length,
410 const struct pldm_bios_table_attr_entry_integer_info *info);
411
412/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
413 * validity of the parameters
414 * @param[out] entry - Pointer to a buffer to create an entry
415 * @param[in] entry_length - Length of the buffer to create an entry
416 * @param[in] info - Pointer to an auxiliary structure @ref
417 * pldm_bios_table_attr_entry_integer_info
418 * @return pldm_completion_codes
419 */
420int pldm_bios_table_attr_entry_integer_encode_check(
421 void *entry, size_t entry_length,
422 const struct pldm_bios_table_attr_entry_integer_info *info);
423
John Wangb0da7a02020-01-07 16:55:00 +0800424/** @brief Get the attribute handle from the attribute value table entry
425 * @param[in] entry - Pointer to bios attribute value table entry
426 * @return handle to identify the attribute in the attribute value table
427 */
428uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
429 const struct pldm_bios_attr_val_table_entry *entry);
430
431/** @brief Get the attribute type from the attribute value table entry
432 * @param[in] entry - Pointer to bios attribute value table entry
433 * @return Type of the attribute value entry
434 */
435uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
436 const struct pldm_bios_attr_val_table_entry *entry);
437
John Wang3ad21752019-10-06 16:42:21 +0800438/** @brief Get length that an attribute value entry(type: enum) will take
439 * @param[in] count - Total number of current values for this enumeration
440 * @return The length that an entry(type: enum) will take
441 */
442size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
443
444/** @brief Create an attribute value entry(type: enum)
445 * @param[out] entry - Pointer to bios attribute value entry
446 * @param[in] entry_length - Length of attribute value entry
447 * @param[in] attr_handle - This handle points to an attribute in the
448 * BIOS Attribute Vlaue Table.
449 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
450 * Table
451 * @param[in] count - Total number of current values for this enum attribute
452 * @param[in] handle_indexes - Index into the array(provided in the BIOS
453 * Attribute Table) of the possible values of string handles for this attribute.
454 */
455void pldm_bios_table_attr_value_entry_encode_enum(
456 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
457 uint8_t count, uint8_t *handle_indexes);
458
John Wang49484a12019-12-02 14:21:53 +0800459/** @brief Get number of current values for the enum entry
460 * @param[in] entry - Pointer to bios attribute value table entry
461 * @return Total number of current values for this enumeration
462 */
463uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
464 const struct pldm_bios_attr_val_table_entry *entry);
465
John Wangb0da7a02020-01-07 16:55:00 +0800466/** @brief Get CurrentValueStringHandleIndex
467 * @param[in] entry - Pointer to bios attribute value table entry
468 * @param[in, out] handles - Pointer to a buffer to store
469 * CurrentValueStringHandleIndex
470 * @param[in] number - Number of PossibleValuesStringHandles expected
471 * @return Number of CurrentValueStringHandleIndex decoded.
472 */
473uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
474 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
475 uint8_t number);
476
John Wang3ad21752019-10-06 16:42:21 +0800477/** @brief Create an attribute value entry(type: enum) and check the validity of
478 * the parameters
479 * @param[out] entry - Pointer to bios attribute value entry
480 * @param[in] entry_length - Length of attribute value entry
481 * @param[in] attr_handle - This handle points to an attribute in the
482 * BIOS Attribute Vlaue Table.
483 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
484 * Table
485 * @param[in] count - Total number of current values for this enum attribute
486 * @param[in] handle_indexes - Index into the array(provided in the BIOS
487 * Attribute Table) of the possible values of string handles for this attribute.
488 * @return pldm_completion_codes
489 */
490int pldm_bios_table_attr_value_entry_encode_enum_check(
491 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
492 uint8_t count, uint8_t *handle_indexes);
493
494/** @brief Get length that an attribute value entry(type: string) will take
495 * @param[in] string_length - Length of the current string in byte, 0 indicates
496 * that the current string value is not set.
497 * @return The length that an entry(type: string) will take
498 */
499size_t
500pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
501
502/** @brief Create an attribute value entry(type: string)
503 * @param[out] entry - Pointer to bios attribute value entry
504 * @param[in] entry_length - Length of attribute value entry
505 * @param[in] attr_handle - This handle points to an attribute in the
506 * BIOS Attribute Vlaue Table.
507 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
508 * Table
509 * @param[in] string_length - Length of current string in bytes. 0 indicates
510 * that the current string value is not set.
511 * @param[in] string - The current string itsel
512 */
513void pldm_bios_table_attr_value_entry_encode_string(
514 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
515 uint16_t string_length, const char *string);
John Wang49484a12019-12-02 14:21:53 +0800516
517/** @brief Get length of the current string in bytes
518 * @param [in] entry - Pointer to bios attribute value table entry
519 * @return The length of the current string in bytes
520 */
521uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
522 const struct pldm_bios_attr_val_table_entry *entry);
523
John Wangb0da7a02020-01-07 16:55:00 +0800524/** @brief Get Current String Itself
525 * @param[in] entry - Pointer to bios attribute value table entry
526 * @param[in, out] current_string - Struct variable_field, contains a pointer
527 * to the CurrentString field in the buffer of
528 * \p entry, \p entry must be valid
529 * when \p current_string is used.
530 */
531void pldm_bios_table_attr_value_entry_string_decode_string(
532 const struct pldm_bios_attr_val_table_entry *entry,
533 struct variable_field *current_string);
534
John Wang3ad21752019-10-06 16:42:21 +0800535/** @brief Create an attribute value entry(type: string) and check the validity
536 * of the parameters
537 * @param[out] entry - Pointer to bios attribute value entry
538 * @param[in] entry_length - Length of attribute value entry
539 * @param[in] attr_handle - This handle points to an attribute in the
540 * BIOS Attribute Vlaue Table.
541 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
542 * Table
543 * @param[in] string_length - Length of current string in bytes. 0 indicates
544 * that the current string value is not set.
545 * @param[in] string - The current string itsel
546 * @return pldm_completion_codes
547 */
548int pldm_bios_table_attr_value_entry_encode_string_check(
549 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
550 uint16_t string_length, const char *string);
551
John Wangca230822019-10-16 11:39:27 +0800552/** @brief Get length that an attribute value entry(type: integer) will take
553 * @return The length that an entry(type: integer) will take
554 */
555size_t pldm_bios_table_attr_value_entry_encode_integer_length();
556
557/** @brief Create an attribute value entry(type: integer)
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] cv - Current Value
565 */
566void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
567 size_t entry_length,
568 uint16_t attr_handle,
569 uint8_t attr_type,
570 uint64_t cv);
571
John Wangb0da7a02020-01-07 16:55:00 +0800572/** @brief Get current values for the integer entry
573 * @param[in] entry - Pointer to bios attribute value table entry
574 * @return Current Value
575 */
576uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
577 const struct pldm_bios_attr_val_table_entry *entry);
578
John Wangca230822019-10-16 11:39:27 +0800579/** @brief Create an attribute value entry(type: integer) and check the validity
580 * of the parameters
581 * @param[out] entry - Pointer to bios attribute value entry
582 * @param[in] entry_length - Length of attribute value entry
583 * @param[in] attr_handle - This handle points to an attribute in the
584 * BIOS Attribute Vlaue Table.
585 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
586 * Table
587 * @param[in] cv - Current Value
588 * @return pldm_completion_codes
589 */
590int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
591 size_t entry_length,
592 uint16_t attr_handle,
593 uint8_t attr_type,
594 uint64_t cv);
John Wang79c37f12019-10-31 15:46:31 +0800595
John Wang3342adb2019-11-29 16:03:58 +0800596/** @brief Get the handle from the attribute value entry
597 * @param[in] entry - Pointer to bios attribute value entry
598 * @return handle to identify the attribute in the attribute value table
599 */
600uint16_t pldm_bios_table_attr_value_entry_decode_handle(
601 const struct pldm_bios_attr_val_table_entry *entry);
602
John Wang8e877e02020-02-03 16:06:55 +0800603/** @brief Get the length of the attribute value entry
John Wang3342adb2019-11-29 16:03:58 +0800604 * @param[in] entry - Pointer to bios attribute value entry
John Wang8e877e02020-02-03 16:06:55 +0800605 * @return Length of the entry
John Wang3342adb2019-11-29 16:03:58 +0800606 */
John Wang8e877e02020-02-03 16:06:55 +0800607size_t pldm_bios_table_attr_value_entry_length(
John Wang3342adb2019-11-29 16:03:58 +0800608 const struct pldm_bios_attr_val_table_entry *entry);
609
610/** @brief Find an entry in attribute value table by handle
611 * @param[in] table - The BIOS Attribute Value Table
612 * @param[in] length - Length of the BIOS Attribute Value Table
613 * @param[in] handle - handle to identify the attribute in the attribute value
614 * table
615 * @return Pointer to the entry
616 */
617const struct pldm_bios_attr_val_table_entry *
618pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
619 uint16_t handle);
620
John Wang79c37f12019-10-31 15:46:31 +0800621/** @brief Get the size of pad and checksum
622 * @param[in] size_without_pad - Table size without pad
623 * @return The size of pad and checksum
624 */
625size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
626
627/** @brief Append pad and checksum at the end of the table
628 * @param[in,out] table - Pointer to a buffer of a bios table
629 * @param[in] size - Size of the buffer of a bios table
630 * @param[in] size_without_pad - Table size without pad and checksum
John Wang871c9272019-12-09 18:02:15 +0800631 * @return Total size of the table
John Wang79c37f12019-10-31 15:46:31 +0800632 */
John Wang871c9272019-12-09 18:02:15 +0800633size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
634 size_t size_without_pad);
635
636/** @brief Build a new table and update an entry
637 * @param[in] src_table - Pointer to the source table
638 * @param[in] src_length - Size of the source table
639 * @param[out] dest_table - Pointer to the buffer of destination table
640 * @param[in,out] dest_length - Buffer size of the destination table as input
641 * parameter and will be assigned the length of
642 * the new table, if the function returns
643 * PLDM_SUCCESS
644 * @param[in] entry - Pointer to an entry
645 * @param[in] entry_length - Size of the entry
646 * @return pldm_completion_codes
647 */
648int pldm_bios_table_attr_value_copy_and_update(
649 const void *src_table, size_t src_length, void *dest_table,
650 size_t *dest_length, const void *entry, size_t entry_length);
John Wang79c37f12019-10-31 15:46:31 +0800651
John Wang02700402019-10-06 16:34:29 +0800652#ifdef __cplusplus
653}
654#endif
655
656#endif