blob: e1da24ae30c88a3199fbbba2a42821afa387eaa8 [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 *)
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093060 pldm_bios_table_iter_value(iter);
Andrew Jeffery9c766792022-08-10 23:12:49 +093061}
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 *)
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093071 pldm_bios_table_iter_value(iter);
Andrew Jeffery9c766792022-08-10 23:12:49 +093072}
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 *)
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093082 pldm_bios_table_iter_value(iter);
Andrew Jeffery9c766792022-08-10 23:12:49 +093083}
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
Andrew Jeffery91f4b542023-06-13 20:59:51 +0930102 *
Andrew Jeffery9c766792022-08-10 23:12:49 +0930103 * @param[out] entry - Pointer to a buffer to create an entry
104 * @param[in] entry_length - Length of the buffer to create an entry
105 * @param[in] str - String itself
106 * @param[in] str_length - Length of the string
Andrew Jeffery91f4b542023-06-13 20:59:51 +0930107 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or str are NULL, or
108 * PLDM_ERROR_INVALID_LENGTH if entry_length is insufficient for encoding str. An
109 * appropriate value for entry_length can be determined using
110 * @ref pldm_bios_table_string_entry_encode_length
Andrew Jeffery9c766792022-08-10 23:12:49 +0930111 */
112int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
113 const char *str,
114 uint16_t str_length);
115
116/** @brief Get the string handle for the entry
117 * @param[in] entry - Pointer to a bios string table entry
118 * @return Handle to identify a string in the bios string table
119 */
120uint16_t pldm_bios_table_string_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930121 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930122
123/** @brief Get the string length for the entry
124 * @param[in] entry - Pointer to a bios string table entry
125 * @return Length of string in bytes
126 */
127uint16_t pldm_bios_table_string_entry_decode_string_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930128 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930129
130/** @brief Get the string(at most one less than *size* characters) from the
131 * entry
132 * @param[in] entry - Pointer to a bios string table entry
133 * @param[out] buffer - Pointer to a buffer to store the string
134 * @param[in] size - Size of the buffer to store the string
135 * @return Length of the string decoded
136 */
137uint16_t pldm_bios_table_string_entry_decode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930138 const struct pldm_bios_string_table_entry *entry, char *buffer,
139 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930140
141/** @brief Get the string from the entry and check the validity of the
142 * parameters
143 * @param[in] entry - Pointer to a bios string table entry
144 * @param[out] buffer - Pointer to a buffer to store the string
145 * @param[in] size - Size of the buffer to store the string
146 * @return pldm_completion_codes
147 */
148int pldm_bios_table_string_entry_decode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930149 const struct pldm_bios_string_table_entry *entry, char *buffer,
150 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930151
152/** @brief Find an entry in bios string table by string
153 * @param[in] table - The BIOS String Table
154 * @param[in] length - Length of the BIOS String Table
155 * @param[in] str - String itself
156 * @return Pointer to an entry in the bios string table
157 */
158const struct pldm_bios_string_table_entry *
159pldm_bios_table_string_find_by_string(const void *table, size_t length,
160 const char *str);
161/** @brief Find an entry in bios string table by handle
162 * @param[in] table - The BIOS String Table
163 * @param[in] length - Length of the BIOS String Table
164 * @param[in] handle - Handle to identify a string in the bios string table
165 * @return Pointer to an entry in the bios string table
166 */
167const struct pldm_bios_string_table_entry *
168pldm_bios_table_string_find_by_handle(const void *table, size_t length,
169 uint16_t handle);
170
171/** @brief Get the attribute handle from the attribute table entry
172 * @param[in] entry - Pointer to bios attribute table entry
173 * @return handle to identify the attribute in the attribute table
174 */
175uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930176 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930177
178/** @brief Get the attribute type of the attribute table entry
179 * @param[in] entry - Pointer to bios attribute table entry
180 * @return Type of the attribute table entry
181 */
182uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930183 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930184
185/** @brief Get the attribute name handle from the attribute table entry
186 * @param[in] entry - Pointer to bios attribute table entry
187 * @return handle to identify the name of the attribute, this handle points
188 * to a string in the bios string table.
189 */
190uint16_t pldm_bios_table_attr_entry_decode_string_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930191 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930192
193/** @brief Find an entry in attribute table by handle
194 * @param[in] table - The BIOS Attribute Table
195 * @param[in] length - Length of the BIOS Attribute Table
196 * @param[in] handle - handle to identify the attribute in the attribute table
197 * @return Pointer to the entry
198 */
199const struct pldm_bios_attr_table_entry *
200pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
201 uint16_t handle);
202
203/** @brief Find an entry in attribute table by string handle
204 * @param[in] table - The BIOS Attribute Table
205 * @param[in] length - Length of the BIOS Attribute Table
206 * @param[in] handle - The string handle
207 * @return Pointer to the entry
208 */
209const struct pldm_bios_attr_table_entry *
210pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
211 uint16_t handle);
212
213/** @struct pldm_bios_table_attr_entry_enum_info
214 *
215 * An auxiliary structure for passing parameters to @ref
216 * pldm_bios_table_attr_entry_enum_encode
217 *
218 */
219struct pldm_bios_table_attr_entry_enum_info {
220 uint16_t name_handle; //!< attribute name handle
221 bool read_only; //!< indicate whether the attribute is read-only
222 uint8_t pv_num; //!< number of possible values
223 const uint16_t *pv_handle; //!< handles of possible values
224 uint8_t def_num; //!< nnumber of default values
225 const uint8_t *def_index; //!< indices of default values.
226};
227
228/** @brief Get length that an attribute entry(type: enum) will take
229 * @param[in] pv_num - Number of possible values
230 * @param[in] def_num - Number of default values
231 * @return The length that an entry(type: enum) will take
232 */
233size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
234 uint8_t def_num);
235
236/** @brief Create an entry of BIOS Attribute Table (type: enum)
237 * @param[out] entry - Pointer to a buffer to create an entry
238 * @param[in] entry_length - Length of the buffer to create an entry
239 * @param[in] info - Pointer to an auxiliary structure @ref
240 * pldm_bios_table_attr_entry_enum_info
241 */
242void pldm_bios_table_attr_entry_enum_encode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930243 void *entry, size_t entry_length,
244 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930245
246/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
247 * validity of the parameters
248 * @param[out] entry - Pointer to a buffer to create an entry
249 * @param[in] entry_length - Length of the buffer to create an entry
250 * @param[in] info - Pointer to an auxiliary structure @ref
251 * pldm_bios_table_attr_entry_enum_info
252 * @return pldm_completion_codes
253 */
254int pldm_bios_table_attr_entry_enum_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930255 void *entry, size_t entry_length,
256 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930257
258/** @brief Get the total number of possible values for the entry
259 * @param[in] entry - Pointer to bios attribute table entry
260 * @return total number of possible values
261 */
262uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930263 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930264
265/** @brief Get the total number of possible values for the entry and check the
266 * validity of the parameters
267 * @param[in] entry - Pointer to bios attribute table entry
268 * @param[out] pv_num - Pointer to total number of possible values
269 * @return pldm_completion_codes
270 */
271int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930272 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930273
274/** @brief Get the total number of default values for the entry
275 * @param[in] entry - Pointer to bios attribute table entry
276 * @return total number of default values
277 */
278uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930279 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930280
281/** @brief Get the total number of default values for the entry and check the
282 * validity of the parameters
283 * @param[in] entry - Pointer to bios attribute table entry
284 * @param[out] def_num - Pointer to total number of default values
285 * @return pldm_completion_codes
286 */
287int pldm_bios_table_attr_entry_enum_decode_def_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930288 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930289
290/** @brief Get possible values string handles
291 * @param[in] entry - Pointer to bios attribute table entry
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930292 * @param[out] pv_hdls - Pointer to a buffer to store
Andrew Jeffery9c766792022-08-10 23:12:49 +0930293 * PossibleValuesStringHandles
294 * @param[in] pv_num - Number of PossibleValuesStringHandles expected
295 * @return pldm_completion_codes
296 */
297uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930298 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
299 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930300
301/** @brief Get possible values string handles and check the validity of the
302 * parameters
303 * @param[in] entry - Pointer to bios attribute table entry
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930304 * @param[out] pv_hdls - Pointer to a buffer to store
Andrew Jeffery9c766792022-08-10 23:12:49 +0930305 * PossibleValuesStringHandles
306 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930307 * store
Andrew Jeffery9c766792022-08-10 23:12:49 +0930308 * @return Number of PossibleValuesStringHandles decoded
309 */
310int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930311 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
312 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930313
314/** @brief Get Indices of default values
315 * @param[in] entry - Pointer to bios attribute table entry
316 * @param[out] def_indices - Pointer to a buffer to store
317 * default value indices
318 * @param[in] def_num - Number of DefaultValues the buffer can
319 * store
320 * @return Number of default values decoded
321 */
322uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930323 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
324 uint8_t def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930325
326/** @struct pldm_bios_table_attr_entry_string_info
327 *
328 * An auxiliary structure for passing parameters to @ref
329 * pldm_bios_table_attr_entry_string_encode
330 *
331 */
332struct pldm_bios_table_attr_entry_string_info {
333 uint16_t name_handle; //!< attribute name handle
334 bool read_only; //!< indicate whether the attribute is read-only
335 uint8_t string_type; //!< The type of the string
336 uint16_t min_length; //!< The minimum length of the string in bytes
337 uint16_t max_length; //!< The maximum length of the string in bytes
338 uint16_t def_length; //!< The length of the defaut string in bytes
339 const char *def_string; //!< The default string itself
340};
341
342/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
343 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
344 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
345 * memory
346 * @return pldm_completion_codes
347 */
348int pldm_bios_table_attr_entry_string_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930349 const struct pldm_bios_table_attr_entry_string_info *info,
350 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930351
352/** @brief Get length that an attribute entry(type: string) will take
353 * @param[in] def_str_len - Length of default string
354 * @return The length that an entry(type: string) will take
355 */
356size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
357
358/** @brief Create an entry of BIOS Attribute Table (type: string)
359 * @param[out] entry - Pointer to a buffer to create an entry
360 * @param[in] entry_length - Length of the buffer to create an entry
361 * @param[in] info - Pointer to an auxiliary structure @ref
362 * pldm_bios_table_attr_entry_string_info
363 */
364void pldm_bios_table_attr_entry_string_encode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930365 void *entry, size_t entry_length,
366 const struct pldm_bios_table_attr_entry_string_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930367
368/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
369 * validity of the parameters
370 * @param[out] entry - Pointer to a buffer to create an entry
371 * @param[in] entry_length - Length of the buffer to create an entry
372 * @param[in] info - Pointer to an auxiliary structure @ref
373 * pldm_bios_table_attr_entry_string_info
374 * @return pldm_completion_codes
375 */
376int pldm_bios_table_attr_entry_string_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930377 void *entry, size_t entry_length,
378 const struct pldm_bios_table_attr_entry_string_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930379
380/** @brief Get the length of default string in bytes for the entry
381 * @param[in] entry - Pointer to bios attribute table entry
382 * @return length of default string in bytes
383 */
384uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930385 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930386
387/** @brief Get the length of default string in bytes for the entry and check the
388 * validity of the parameters
389 * @param[in] entry - Pointer to bios attribute table entry
390 * @param[out] def_string_length Pointer to length of default string in bytes
391 * @return pldm_completion_codes
392 */
393int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930394 const struct pldm_bios_attr_table_entry *entry,
395 uint16_t *def_string_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930396
397/** @brief Get the type of string of bios attribute table entry
398 * @param[in] entry - Pointer to bios attribute table entry
399 * @return Type of the string
400 */
401uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930402 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930403
404/** @brief Get maximum length of the string from a bios attribute table entry in
405 * bytes
406 * @param[in] entry - Pointer to a bios attribute table entry
407 * @return Maximum length of the string
408 */
409uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930410 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930411
412/** @brief Get minimum length of the string from a bios attribute table entry in
413 * bytes
414 * @param[in] entry - Pointer to a bios attribute table entry
415 * @return Minimum length of the string
416 */
417uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930418 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930419
420/** @brief Get the default string from a bios attribute table entry
421 * @param[out] buffer - Pointer to a buffer to store the string
422 * @param[in] size - Size of the buffer to store the string
423 * @return Length of the string decoded
424 */
425uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930426 const struct pldm_bios_attr_table_entry *entry, char *buffer,
427 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930428
429/** @struct pldm_bios_table_attr_entry_integer_info
430 *
431 * An auxiliary structure for passing parameters to @ref
432 * pldm_bios_table_attr_entry_integer_encode
433 *
434 */
435struct pldm_bios_table_attr_entry_integer_info {
436 uint16_t name_handle; //!< attribute name handle
437 bool read_only; //!< indicate whether the attribute is read-only
438 uint64_t lower_bound; //!< The lower bound on the integer value
439 uint64_t upper_bound; //!< The upper bound on the integer value
440 uint32_t scalar_increment; //!< The scalar value that is used for the
441 //!< increments to this integer
442 uint64_t default_value; //!< The default value of the integer
443};
444
445/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
446 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
447 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
448 * memory
449 * @return pldm_completion_codes
450 */
451int pldm_bios_table_attr_entry_integer_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930452 const struct pldm_bios_table_attr_entry_integer_info *info,
453 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930454
455/** @brief Get length that an attribute entry(type: integer) will take
456 * @return The length that an entry(type: integer) will take
457 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930458size_t pldm_bios_table_attr_entry_integer_encode_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930459
460/** @brief Create an entry of BIOS Attribute Table (type: integer)
461 * @param[out] entry - Pointer to a buffer to create an entry
462 * @param[in] entry_length - Length of the buffer to create an entry
463 * @param[in] info - Pointer to an auxiliary structure @ref
464 * pldm_bios_table_attr_entry_integer_info
465 */
466void pldm_bios_table_attr_entry_integer_encode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930467 void *entry, size_t entry_length,
468 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930469
470/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
471 * validity of the parameters
472 * @param[out] entry - Pointer to a buffer to create an entry
473 * @param[in] entry_length - Length of the buffer to create an entry
474 * @param[in] info - Pointer to an auxiliary structure @ref
475 * pldm_bios_table_attr_entry_integer_info
476 * @return pldm_completion_codes
477 */
478int pldm_bios_table_attr_entry_integer_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930479 void *entry, size_t entry_length,
480 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930481
482/** @brief Decode the specific fields(integer) of attribute table entry
483 * @param[in] entry - Pointer to an entry of attribute table
484 * @param[out] lower - The lower bound on the integer value
485 * @param[out] upper - The upper bound on the integer value
486 * @param[out] scalar - The scalar value that is used for the increments to
487 * this integer
488 * @param[out] def - The default value of the integer
489 */
490void pldm_bios_table_attr_entry_integer_decode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930491 const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
492 uint64_t *upper, uint32_t *scalar, uint64_t *def);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930493
494/** @brief Get the attribute handle from the attribute value table entry
495 * @param[in] entry - Pointer to bios attribute value table entry
496 * @return handle to identify the attribute in the attribute value table
497 */
498uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930499 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930500
501/** @brief Get the attribute type from the attribute value table entry
502 * @param[in] entry - Pointer to bios attribute value table entry
503 * @return Type of the attribute value entry
504 */
505uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930506 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930507
508/** @brief Get length that an attribute value entry(type: enum) will take
509 * @param[in] count - Total number of current values for this enumeration
510 * @return The length that an entry(type: enum) will take
511 */
512size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
513
514/** @brief Create an attribute value entry(type: enum)
515 * @param[out] entry - Pointer to bios attribute value entry
516 * @param[in] entry_length - Length of attribute value entry
517 * @param[in] attr_handle - This handle points to an attribute in the
518 * BIOS Attribute Vlaue Table.
519 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
520 * Table
521 * @param[in] count - Total number of current values for this enum attribute
522 * @param[in] handle_indexes - Index into the array(provided in the BIOS
523 * Attribute Table) of the possible values of string handles for this attribute.
524 */
525void pldm_bios_table_attr_value_entry_encode_enum(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930526 void *entry, size_t entry_length, uint16_t attr_handle,
527 uint8_t attr_type, uint8_t count, const uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930528
529/** @brief Get number of current values for the enum entry
530 * @param[in] entry - Pointer to bios attribute value table entry
531 * @return Total number of current values for this enumeration
532 */
533uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930534 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930535
536/** @brief Get CurrentValueStringHandleIndex
537 * @param[in] entry - Pointer to bios attribute value table entry
538 * @param[in, out] handles - Pointer to a buffer to store
539 * CurrentValueStringHandleIndex
540 * @param[in] number - Number of PossibleValuesStringHandles expected
541 * @return Number of CurrentValueStringHandleIndex decoded.
542 */
543uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930544 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
545 uint8_t number);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930546
547/** @brief Create an attribute value entry(type: enum) and check the validity of
548 * the parameters
549 * @param[out] entry - Pointer to bios attribute value entry
550 * @param[in] entry_length - Length of attribute value entry
551 * @param[in] attr_handle - This handle points to an attribute in the
552 * BIOS Attribute Vlaue Table.
553 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
554 * Table
555 * @param[in] count - Total number of current values for this enum attribute
556 * @param[in] handle_indexes - Index into the array(provided in the BIOS
557 * Attribute Table) of the possible values of string handles for this attribute.
558 * @return pldm_completion_codes
559 */
560int pldm_bios_table_attr_value_entry_encode_enum_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930561 void *entry, size_t entry_length, uint16_t attr_handle,
562 uint8_t attr_type, uint8_t count, uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930563
564/** @brief Get length that an attribute value entry(type: string) will take
565 * @param[in] string_length - Length of the current string in byte, 0 indicates
566 * that the current string value is not set.
567 * @return The length that an entry(type: string) will take
568 */
569size_t
570pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
571
572/** @brief Create an attribute value entry(type: string)
573 * @param[out] entry - Pointer to bios attribute value entry
574 * @param[in] entry_length - Length of attribute value entry
575 * @param[in] attr_handle - This handle points to an attribute in the
576 * BIOS Attribute Vlaue Table.
577 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
578 * Table
579 * @param[in] string_length - Length of current string in bytes. 0 indicates
580 * that the current string value is not set.
581 * @param[in] string - The current string itsel
582 */
583void pldm_bios_table_attr_value_entry_encode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930584 void *entry, size_t entry_length, uint16_t attr_handle,
585 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930586
587/** @brief Get length of the current string in bytes
588 * @param [in] entry - Pointer to bios attribute value table entry
589 * @return The length of the current string in bytes
590 */
591uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930592 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930593
594/** @brief Get Current String Itself
595 * @param[in] entry - Pointer to bios attribute value table entry
596 * @param[in, out] current_string - Struct variable_field, contains a pointer
597 * to the CurrentString field in the buffer of
598 * \p entry, \p entry must be valid
599 * when \p current_string is used.
600 */
601void pldm_bios_table_attr_value_entry_string_decode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930602 const struct pldm_bios_attr_val_table_entry *entry,
603 struct variable_field *current_string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930604
605/** @brief Create an attribute value entry(type: string) and check the validity
606 * of the parameters
607 * @param[out] entry - Pointer to bios attribute value entry
608 * @param[in] entry_length - Length of attribute value entry
609 * @param[in] attr_handle - This handle points to an attribute in the
610 * BIOS Attribute Vlaue Table.
611 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
612 * Table
613 * @param[in] string_length - Length of current string in bytes. 0 indicates
614 * that the current string value is not set.
615 * @param[in] string - The current string itsel
616 * @return pldm_completion_codes
617 */
618int pldm_bios_table_attr_value_entry_encode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930619 void *entry, size_t entry_length, uint16_t attr_handle,
620 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930621
622/** @brief Get length that an attribute value entry(type: integer) will take
623 * @return The length that an entry(type: integer) will take
624 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930625size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930626
627/** @brief Create an attribute value entry(type: integer)
628 * @param[out] entry - Pointer to bios attribute value entry
629 * @param[in] entry_length - Length of attribute value entry
630 * @param[in] attr_handle - This handle points to an attribute in the
631 * BIOS Attribute Vlaue Table.
632 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
633 * Table
634 * @param[in] cv - Current Value
635 */
636void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
637 size_t entry_length,
638 uint16_t attr_handle,
639 uint8_t attr_type,
640 uint64_t cv);
641
642/** @brief Get current values for the integer entry
643 * @param[in] entry - Pointer to bios attribute value table entry
644 * @return Current Value
645 */
646uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930647 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930648
649/** @brief Create an attribute value entry(type: integer) and check the validity
650 * of the parameters
651 * @param[out] entry - Pointer to bios attribute value entry
652 * @param[in] entry_length - Length of attribute value entry
653 * @param[in] attr_handle - This handle points to an attribute in the
654 * BIOS Attribute Vlaue Table.
655 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
656 * Table
657 * @param[in] cv - Current Value
658 * @return pldm_completion_codes
659 */
660int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
661 size_t entry_length,
662 uint16_t attr_handle,
663 uint8_t attr_type,
664 uint64_t cv);
665
666/** @brief Get the handle from the attribute value entry
667 * @param[in] entry - Pointer to bios attribute value entry
668 * @return handle to identify the attribute in the attribute value table
669 */
670uint16_t pldm_bios_table_attr_value_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930671 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930672
673/** @brief Get the length of the attribute value entry
674 * @param[in] entry - Pointer to bios attribute value entry
675 * @return Length of the entry
676 */
677size_t pldm_bios_table_attr_value_entry_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930678 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930679
680/** @brief Find an entry in attribute value table by handle
681 * @param[in] table - The BIOS Attribute Value Table
682 * @param[in] length - Length of the BIOS Attribute Value Table
683 * @param[in] handle - handle to identify the attribute in the attribute value
684 * table
685 * @return Pointer to the entry
686 */
687const struct pldm_bios_attr_val_table_entry *
688pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
689 uint16_t handle);
690
691/** @brief Get the size of pad and checksum
692 * @param[in] size_without_pad - Table size without pad
693 * @return The size of pad and checksum
694 */
695size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
696
697/** @brief Append pad and checksum at the end of the table
698 * @param[in,out] table - Pointer to a buffer of a bios table
699 * @param[in] size - Size of the buffer of a bios table
700 * @param[in] size_without_pad - Table size without pad and checksum
701 * @return Total size of the table
702 */
703size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
704 size_t size_without_pad);
705
706/** @brief Build a new table and update an entry
707 * @param[in] src_table - Pointer to the source table
708 * @param[in] src_length - Size of the source table
709 * @param[out] dest_table - Pointer to the buffer of destination table
710 * @param[in,out] dest_length - Buffer size of the destination table as input
711 * parameter and will be assigned the length of
712 * the new table, if the function returns
713 * PLDM_SUCCESS
714 * @param[in] entry - Pointer to an entry
715 * @param[in] entry_length - Size of the entry
716 * @return pldm_completion_codes
717 */
718int pldm_bios_table_attr_value_copy_and_update(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930719 const void *src_table, size_t src_length, void *dest_table,
720 size_t *dest_length, const void *entry, size_t entry_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930721
722/** @brief Verify the crc value of the complete table
723 * @param[in] table - Pointer to a buffer of a bios table
724 * @param[in] size - Size of the buffer of a bios table
725 * @return true: crc value is correct
726 */
727bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
728
729#ifdef __cplusplus
730}
731#endif
732
733#endif