blob: 76f41d171a31716a16ccce5a85273a10b0c3d87f [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
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930117 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930118
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930124 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930125
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930134 const struct pldm_bios_string_table_entry *entry, char *buffer,
135 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930136
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930145 const struct pldm_bios_string_table_entry *entry, char *buffer,
146 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930147
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930172 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930173
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930179 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930180
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930187 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930188
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930239 void *entry, size_t entry_length,
240 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930241
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930251 void *entry, size_t entry_length,
252 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930253
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930259 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930260
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930268 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930269
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930275 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930276
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930284 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930285
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930294 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
295 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930296
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930307 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
308 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930309
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930319 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
320 uint8_t def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930321
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930345 const struct pldm_bios_table_attr_entry_string_info *info,
346 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930347
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930361 void *entry, size_t entry_length,
362 const struct pldm_bios_table_attr_entry_string_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930363
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930373 void *entry, size_t entry_length,
374 const struct pldm_bios_table_attr_entry_string_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930375
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930381 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930382
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930390 const struct pldm_bios_attr_table_entry *entry,
391 uint16_t *def_string_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930392
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930398 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930399
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930406 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930407
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930414 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930415
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(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930422 const struct pldm_bios_attr_table_entry *entry, char *buffer,
423 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930424
425/** @struct pldm_bios_table_attr_entry_integer_info
426 *
427 * An auxiliary structure for passing parameters to @ref
428 * pldm_bios_table_attr_entry_integer_encode
429 *
430 */
431struct pldm_bios_table_attr_entry_integer_info {
432 uint16_t name_handle; //!< attribute name handle
433 bool read_only; //!< indicate whether the attribute is read-only
434 uint64_t lower_bound; //!< The lower bound on the integer value
435 uint64_t upper_bound; //!< The upper bound on the integer value
436 uint32_t scalar_increment; //!< The scalar value that is used for the
437 //!< increments to this integer
438 uint64_t default_value; //!< The default value of the integer
439};
440
441/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
442 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
443 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
444 * memory
445 * @return pldm_completion_codes
446 */
447int pldm_bios_table_attr_entry_integer_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930448 const struct pldm_bios_table_attr_entry_integer_info *info,
449 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930450
451/** @brief Get length that an attribute entry(type: integer) will take
452 * @return The length that an entry(type: integer) will take
453 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930454size_t pldm_bios_table_attr_entry_integer_encode_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930455
456/** @brief Create an entry of BIOS Attribute Table (type: integer)
457 * @param[out] entry - Pointer to a buffer to create an entry
458 * @param[in] entry_length - Length of the buffer to create an entry
459 * @param[in] info - Pointer to an auxiliary structure @ref
460 * pldm_bios_table_attr_entry_integer_info
461 */
462void pldm_bios_table_attr_entry_integer_encode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930463 void *entry, size_t entry_length,
464 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930465
466/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
467 * validity of the parameters
468 * @param[out] entry - Pointer to a buffer to create an entry
469 * @param[in] entry_length - Length of the buffer to create an entry
470 * @param[in] info - Pointer to an auxiliary structure @ref
471 * pldm_bios_table_attr_entry_integer_info
472 * @return pldm_completion_codes
473 */
474int pldm_bios_table_attr_entry_integer_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930475 void *entry, size_t entry_length,
476 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930477
478/** @brief Decode the specific fields(integer) of attribute table entry
479 * @param[in] entry - Pointer to an entry of attribute table
480 * @param[out] lower - The lower bound on the integer value
481 * @param[out] upper - The upper bound on the integer value
482 * @param[out] scalar - The scalar value that is used for the increments to
483 * this integer
484 * @param[out] def - The default value of the integer
485 */
486void pldm_bios_table_attr_entry_integer_decode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930487 const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
488 uint64_t *upper, uint32_t *scalar, uint64_t *def);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930489
490/** @brief Get the attribute handle from the attribute value table entry
491 * @param[in] entry - Pointer to bios attribute value table entry
492 * @return handle to identify the attribute in the attribute value table
493 */
494uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930495 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930496
497/** @brief Get the attribute type from the attribute value table entry
498 * @param[in] entry - Pointer to bios attribute value table entry
499 * @return Type of the attribute value entry
500 */
501uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930502 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930503
504/** @brief Get length that an attribute value entry(type: enum) will take
505 * @param[in] count - Total number of current values for this enumeration
506 * @return The length that an entry(type: enum) will take
507 */
508size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
509
510/** @brief Create an attribute value entry(type: enum)
511 * @param[out] entry - Pointer to bios attribute value entry
512 * @param[in] entry_length - Length of attribute value entry
513 * @param[in] attr_handle - This handle points to an attribute in the
514 * BIOS Attribute Vlaue Table.
515 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
516 * Table
517 * @param[in] count - Total number of current values for this enum attribute
518 * @param[in] handle_indexes - Index into the array(provided in the BIOS
519 * Attribute Table) of the possible values of string handles for this attribute.
520 */
521void pldm_bios_table_attr_value_entry_encode_enum(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930522 void *entry, size_t entry_length, uint16_t attr_handle,
523 uint8_t attr_type, uint8_t count, const uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930524
525/** @brief Get number of current values for the enum entry
526 * @param[in] entry - Pointer to bios attribute value table entry
527 * @return Total number of current values for this enumeration
528 */
529uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930530 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930531
532/** @brief Get CurrentValueStringHandleIndex
533 * @param[in] entry - Pointer to bios attribute value table entry
534 * @param[in, out] handles - Pointer to a buffer to store
535 * CurrentValueStringHandleIndex
536 * @param[in] number - Number of PossibleValuesStringHandles expected
537 * @return Number of CurrentValueStringHandleIndex decoded.
538 */
539uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930540 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
541 uint8_t number);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930542
543/** @brief Create an attribute value entry(type: enum) and check the validity of
544 * the parameters
545 * @param[out] entry - Pointer to bios attribute value entry
546 * @param[in] entry_length - Length of attribute value entry
547 * @param[in] attr_handle - This handle points to an attribute in the
548 * BIOS Attribute Vlaue Table.
549 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
550 * Table
551 * @param[in] count - Total number of current values for this enum attribute
552 * @param[in] handle_indexes - Index into the array(provided in the BIOS
553 * Attribute Table) of the possible values of string handles for this attribute.
554 * @return pldm_completion_codes
555 */
556int pldm_bios_table_attr_value_entry_encode_enum_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930557 void *entry, size_t entry_length, uint16_t attr_handle,
558 uint8_t attr_type, uint8_t count, uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930559
560/** @brief Get length that an attribute value entry(type: string) will take
561 * @param[in] string_length - Length of the current string in byte, 0 indicates
562 * that the current string value is not set.
563 * @return The length that an entry(type: string) will take
564 */
565size_t
566pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
567
568/** @brief Create an attribute value entry(type: string)
569 * @param[out] entry - Pointer to bios attribute value entry
570 * @param[in] entry_length - Length of attribute value entry
571 * @param[in] attr_handle - This handle points to an attribute in the
572 * BIOS Attribute Vlaue Table.
573 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
574 * Table
575 * @param[in] string_length - Length of current string in bytes. 0 indicates
576 * that the current string value is not set.
577 * @param[in] string - The current string itsel
578 */
579void pldm_bios_table_attr_value_entry_encode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930580 void *entry, size_t entry_length, uint16_t attr_handle,
581 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930582
583/** @brief Get length of the current string in bytes
584 * @param [in] entry - Pointer to bios attribute value table entry
585 * @return The length of the current string in bytes
586 */
587uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930588 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930589
590/** @brief Get Current String Itself
591 * @param[in] entry - Pointer to bios attribute value table entry
592 * @param[in, out] current_string - Struct variable_field, contains a pointer
593 * to the CurrentString field in the buffer of
594 * \p entry, \p entry must be valid
595 * when \p current_string is used.
596 */
597void pldm_bios_table_attr_value_entry_string_decode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930598 const struct pldm_bios_attr_val_table_entry *entry,
599 struct variable_field *current_string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930600
601/** @brief Create an attribute value entry(type: string) and check the validity
602 * of the parameters
603 * @param[out] entry - Pointer to bios attribute value entry
604 * @param[in] entry_length - Length of attribute value entry
605 * @param[in] attr_handle - This handle points to an attribute in the
606 * BIOS Attribute Vlaue Table.
607 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
608 * Table
609 * @param[in] string_length - Length of current string in bytes. 0 indicates
610 * that the current string value is not set.
611 * @param[in] string - The current string itsel
612 * @return pldm_completion_codes
613 */
614int pldm_bios_table_attr_value_entry_encode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930615 void *entry, size_t entry_length, uint16_t attr_handle,
616 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930617
618/** @brief Get length that an attribute value entry(type: integer) will take
619 * @return The length that an entry(type: integer) will take
620 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930621size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930622
623/** @brief Create an attribute value entry(type: integer)
624 * @param[out] entry - Pointer to bios attribute value entry
625 * @param[in] entry_length - Length of attribute value entry
626 * @param[in] attr_handle - This handle points to an attribute in the
627 * BIOS Attribute Vlaue Table.
628 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
629 * Table
630 * @param[in] cv - Current Value
631 */
632void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
633 size_t entry_length,
634 uint16_t attr_handle,
635 uint8_t attr_type,
636 uint64_t cv);
637
638/** @brief Get current values for the integer entry
639 * @param[in] entry - Pointer to bios attribute value table entry
640 * @return Current Value
641 */
642uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930643 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930644
645/** @brief Create an attribute value entry(type: integer) and check the validity
646 * of the parameters
647 * @param[out] entry - Pointer to bios attribute value entry
648 * @param[in] entry_length - Length of attribute value entry
649 * @param[in] attr_handle - This handle points to an attribute in the
650 * BIOS Attribute Vlaue Table.
651 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
652 * Table
653 * @param[in] cv - Current Value
654 * @return pldm_completion_codes
655 */
656int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
657 size_t entry_length,
658 uint16_t attr_handle,
659 uint8_t attr_type,
660 uint64_t cv);
661
662/** @brief Get the handle from the attribute value entry
663 * @param[in] entry - Pointer to bios attribute value entry
664 * @return handle to identify the attribute in the attribute value table
665 */
666uint16_t pldm_bios_table_attr_value_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930667 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930668
669/** @brief Get the length of the attribute value entry
670 * @param[in] entry - Pointer to bios attribute value entry
671 * @return Length of the entry
672 */
673size_t pldm_bios_table_attr_value_entry_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930674 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930675
676/** @brief Find an entry in attribute value table by handle
677 * @param[in] table - The BIOS Attribute Value Table
678 * @param[in] length - Length of the BIOS Attribute Value Table
679 * @param[in] handle - handle to identify the attribute in the attribute value
680 * table
681 * @return Pointer to the entry
682 */
683const struct pldm_bios_attr_val_table_entry *
684pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
685 uint16_t handle);
686
687/** @brief Get the size of pad and checksum
688 * @param[in] size_without_pad - Table size without pad
689 * @return The size of pad and checksum
690 */
691size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
692
693/** @brief Append pad and checksum at the end of the table
694 * @param[in,out] table - Pointer to a buffer of a bios table
695 * @param[in] size - Size of the buffer of a bios table
696 * @param[in] size_without_pad - Table size without pad and checksum
697 * @return Total size of the table
698 */
699size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
700 size_t size_without_pad);
701
702/** @brief Build a new table and update an entry
703 * @param[in] src_table - Pointer to the source table
704 * @param[in] src_length - Size of the source table
705 * @param[out] dest_table - Pointer to the buffer of destination table
706 * @param[in,out] dest_length - Buffer size of the destination table as input
707 * parameter and will be assigned the length of
708 * the new table, if the function returns
709 * PLDM_SUCCESS
710 * @param[in] entry - Pointer to an entry
711 * @param[in] entry_length - Size of the entry
712 * @return pldm_completion_codes
713 */
714int pldm_bios_table_attr_value_copy_and_update(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930715 const void *src_table, size_t src_length, void *dest_table,
716 size_t *dest_length, const void *entry, size_t entry_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930717
718/** @brief Verify the crc value of the complete table
719 * @param[in] table - Pointer to a buffer of a bios table
720 * @param[in] size - Size of the buffer of a bios table
721 * @return true: crc value is correct
722 */
723bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
724
725#ifdef __cplusplus
726}
727#endif
728
729#endif