blob: 4fe45dddea176ebaa8d96726ea37e2f407f3eb48 [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
Andrew Jeffery23250312023-06-13 21:07:46 +0930146 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or buffer are NULL, or
147 * PLDM_ERROR_INVALID_LENGTH if size is insufficient for the decoded string. An
148 * appropriate value for size can be determined using the expression
149 * `pldm_bios_table_string_entry_decode_string_length(entry) + 1`.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930150 */
151int pldm_bios_table_string_entry_decode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930152 const struct pldm_bios_string_table_entry *entry, char *buffer,
153 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930154
155/** @brief Find an entry in bios string table by string
156 * @param[in] table - The BIOS String Table
157 * @param[in] length - Length of the BIOS String Table
158 * @param[in] str - String itself
159 * @return Pointer to an entry in the bios string table
160 */
161const struct pldm_bios_string_table_entry *
162pldm_bios_table_string_find_by_string(const void *table, size_t length,
163 const char *str);
164/** @brief Find an entry in bios string table by handle
165 * @param[in] table - The BIOS String Table
166 * @param[in] length - Length of the BIOS String Table
167 * @param[in] handle - Handle to identify a string in the bios string table
168 * @return Pointer to an entry in the bios string table
169 */
170const struct pldm_bios_string_table_entry *
171pldm_bios_table_string_find_by_handle(const void *table, size_t length,
172 uint16_t handle);
173
174/** @brief Get the attribute handle from the attribute table entry
175 * @param[in] entry - Pointer to bios attribute table entry
176 * @return handle to identify the attribute in the attribute table
177 */
178uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
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 type of the attribute table entry
182 * @param[in] entry - Pointer to bios attribute table entry
183 * @return Type of the attribute table entry
184 */
185uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930186 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930187
188/** @brief Get the attribute name handle from the attribute table entry
189 * @param[in] entry - Pointer to bios attribute table entry
190 * @return handle to identify the name of the attribute, this handle points
191 * to a string in the bios string table.
192 */
193uint16_t pldm_bios_table_attr_entry_decode_string_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930194 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930195
196/** @brief Find an entry in attribute table by handle
197 * @param[in] table - The BIOS Attribute Table
198 * @param[in] length - Length of the BIOS Attribute Table
199 * @param[in] handle - handle to identify the attribute in the attribute table
200 * @return Pointer to the entry
201 */
202const struct pldm_bios_attr_table_entry *
203pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
204 uint16_t handle);
205
206/** @brief Find an entry in attribute table by string handle
207 * @param[in] table - The BIOS Attribute Table
208 * @param[in] length - Length of the BIOS Attribute Table
209 * @param[in] handle - The string handle
210 * @return Pointer to the entry
211 */
212const struct pldm_bios_attr_table_entry *
213pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
214 uint16_t handle);
215
216/** @struct pldm_bios_table_attr_entry_enum_info
217 *
218 * An auxiliary structure for passing parameters to @ref
219 * pldm_bios_table_attr_entry_enum_encode
220 *
221 */
222struct pldm_bios_table_attr_entry_enum_info {
223 uint16_t name_handle; //!< attribute name handle
224 bool read_only; //!< indicate whether the attribute is read-only
225 uint8_t pv_num; //!< number of possible values
226 const uint16_t *pv_handle; //!< handles of possible values
227 uint8_t def_num; //!< nnumber of default values
228 const uint8_t *def_index; //!< indices of default values.
229};
230
231/** @brief Get length that an attribute entry(type: enum) will take
232 * @param[in] pv_num - Number of possible values
233 * @param[in] def_num - Number of default values
234 * @return The length that an entry(type: enum) will take
235 */
236size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
237 uint8_t def_num);
238
239/** @brief Create an entry of BIOS Attribute Table (type: enum)
240 * @param[out] entry - Pointer to a buffer to create an entry
241 * @param[in] entry_length - Length of the buffer to create an entry
242 * @param[in] info - Pointer to an auxiliary structure @ref
243 * pldm_bios_table_attr_entry_enum_info
244 */
245void pldm_bios_table_attr_entry_enum_encode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930246 void *entry, size_t entry_length,
247 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930248
249/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
250 * validity of the parameters
251 * @param[out] entry - Pointer to a buffer to create an entry
252 * @param[in] entry_length - Length of the buffer to create an entry
253 * @param[in] info - Pointer to an auxiliary structure @ref
254 * pldm_bios_table_attr_entry_enum_info
255 * @return pldm_completion_codes
256 */
257int pldm_bios_table_attr_entry_enum_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930258 void *entry, size_t entry_length,
259 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930260
261/** @brief Get the total number of possible values for the entry
262 * @param[in] entry - Pointer to bios attribute table entry
263 * @return total number of possible values
264 */
265uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930266 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930267
268/** @brief Get the total number of possible values for the entry and check the
269 * validity of the parameters
270 * @param[in] entry - Pointer to bios attribute table entry
271 * @param[out] pv_num - Pointer to total number of possible values
Andrew Jeffery4f7ebda2023-06-13 21:49:38 +0930272 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or pv_num are NULL, or
273 * PLDM_ERROR_INVALID_DATA if entry is not a valid PLDM_BIOS_ENUMERATION
Andrew Jeffery9c766792022-08-10 23:12:49 +0930274 */
275int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930276 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930277
278/** @brief Get the total number of default values for the entry
279 * @param[in] entry - Pointer to bios attribute table entry
280 * @return total number of default values
281 */
282uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930283 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930284
285/** @brief Get the total number of default values for the entry and check the
286 * validity of the parameters
287 * @param[in] entry - Pointer to bios attribute table entry
288 * @param[out] def_num - Pointer to total number of default values
Andrew Jeffery437a83a2023-06-13 22:36:26 +0930289 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_num are NULL,
290 * or entry is not of type PLDM_BIOS_ENUMERATION.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930291 */
292int pldm_bios_table_attr_entry_enum_decode_def_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930293 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930294
295/** @brief Get possible values string handles
296 * @param[in] entry - Pointer to bios attribute table entry
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930297 * @param[out] pv_hdls - Pointer to a buffer to store
Andrew Jeffery9c766792022-08-10 23:12:49 +0930298 * PossibleValuesStringHandles
299 * @param[in] pv_num - Number of PossibleValuesStringHandles expected
300 * @return pldm_completion_codes
301 */
302uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930303 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
304 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930305
306/** @brief Get possible values string handles and check the validity of the
307 * parameters
308 * @param[in] entry - Pointer to bios attribute table entry
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930309 * @param[out] pv_hdls - Pointer to a buffer to store
Andrew Jeffery9c766792022-08-10 23:12:49 +0930310 * PossibleValuesStringHandles
311 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930312 * store
Andrew Jefferyf3d851f2023-06-13 22:24:48 +0930313 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or pv_hdls are NULL,
314 * or entry is not of type PLDM_BIOS_ENUMERATION, or the number of possible values is not
315 * equal to pv_num. An appropriate value for pv_num can be determined using @ref
316 * pldm_bios_table_attr_entry_enum_decode_pv_num_check
Andrew Jeffery9c766792022-08-10 23:12:49 +0930317 */
318int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930319 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
320 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930321
322/** @brief Get Indices of default values
323 * @param[in] entry - Pointer to bios attribute table entry
324 * @param[out] def_indices - Pointer to a buffer to store
325 * default value indices
326 * @param[in] def_num - Number of DefaultValues the buffer can
327 * store
328 * @return Number of default values decoded
329 */
330uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930331 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
332 uint8_t def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930333
334/** @struct pldm_bios_table_attr_entry_string_info
335 *
336 * An auxiliary structure for passing parameters to @ref
337 * pldm_bios_table_attr_entry_string_encode
338 *
339 */
340struct pldm_bios_table_attr_entry_string_info {
341 uint16_t name_handle; //!< attribute name handle
342 bool read_only; //!< indicate whether the attribute is read-only
343 uint8_t string_type; //!< The type of the string
344 uint16_t min_length; //!< The minimum length of the string in bytes
345 uint16_t max_length; //!< The maximum length of the string in bytes
346 uint16_t def_length; //!< The length of the defaut string in bytes
347 const char *def_string; //!< The default string itself
348};
349
350/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
351 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
352 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
353 * memory
354 * @return pldm_completion_codes
355 */
356int pldm_bios_table_attr_entry_string_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930357 const struct pldm_bios_table_attr_entry_string_info *info,
358 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930359
360/** @brief Get length that an attribute entry(type: string) will take
361 * @param[in] def_str_len - Length of default string
362 * @return The length that an entry(type: string) will take
363 */
364size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
365
366/** @brief Create an entry of BIOS Attribute Table (type: string)
367 * @param[out] entry - Pointer to a buffer to create an entry
368 * @param[in] entry_length - Length of the buffer to create an entry
369 * @param[in] info - Pointer to an auxiliary structure @ref
370 * pldm_bios_table_attr_entry_string_info
371 */
372void pldm_bios_table_attr_entry_string_encode(
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 Create an entry of BIOS Attribute Table (type: string) and check the
377 * validity of the parameters
378 * @param[out] entry - Pointer to a buffer to create an entry
379 * @param[in] entry_length - Length of the buffer to create an entry
380 * @param[in] info - Pointer to an auxiliary structure @ref
381 * pldm_bios_table_attr_entry_string_info
Andrew Jefferya5c32872023-06-13 21:34:26 +0930382 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or info are NULL or info
383 * contains logically inconsistent data, or PLDM_ERROR_INVALID_LENGTH if entry_length is
384 * not sufficient to encode info. An appropriate value for entry_length can be determined
385 * using @ref pldm_bios_table_attr_entry_string_encode_length
Andrew Jeffery9c766792022-08-10 23:12:49 +0930386 */
387int pldm_bios_table_attr_entry_string_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930388 void *entry, size_t entry_length,
389 const struct pldm_bios_table_attr_entry_string_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930390
391/** @brief Get the length of default string in bytes for the entry
392 * @param[in] entry - Pointer to bios attribute table entry
393 * @return length of default string in bytes
394 */
395uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930396 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930397
398/** @brief Get the length of default string in bytes for the entry and check the
399 * validity of the parameters
400 * @param[in] entry - Pointer to bios attribute table entry
401 * @param[out] def_string_length Pointer to length of default string in bytes
Andrew Jefferyb9a87692023-06-13 22:36:43 +0930402 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_string_length
403 * are NULL, or entry is not of type PLDM_BIOS_STRING
Andrew Jeffery9c766792022-08-10 23:12:49 +0930404 */
405int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930406 const struct pldm_bios_attr_table_entry *entry,
407 uint16_t *def_string_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930408
409/** @brief Get the type of string of bios attribute table entry
410 * @param[in] entry - Pointer to bios attribute table entry
411 * @return Type of the string
412 */
413uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
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 maximum length of the string from a bios attribute table entry in
417 * bytes
418 * @param[in] entry - Pointer to a bios attribute table entry
419 * @return Maximum length of the string
420 */
421uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930422 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930423
424/** @brief Get minimum length of the string from a bios attribute table entry in
425 * bytes
426 * @param[in] entry - Pointer to a bios attribute table entry
427 * @return Minimum length of the string
428 */
429uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930430 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930431
432/** @brief Get the default string from a bios attribute table entry
433 * @param[out] buffer - Pointer to a buffer to store the string
434 * @param[in] size - Size of the buffer to store the string
435 * @return Length of the string decoded
436 */
437uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930438 const struct pldm_bios_attr_table_entry *entry, char *buffer,
439 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930440
441/** @struct pldm_bios_table_attr_entry_integer_info
442 *
443 * An auxiliary structure for passing parameters to @ref
444 * pldm_bios_table_attr_entry_integer_encode
445 *
446 */
447struct pldm_bios_table_attr_entry_integer_info {
448 uint16_t name_handle; //!< attribute name handle
449 bool read_only; //!< indicate whether the attribute is read-only
450 uint64_t lower_bound; //!< The lower bound on the integer value
451 uint64_t upper_bound; //!< The upper bound on the integer value
452 uint32_t scalar_increment; //!< The scalar value that is used for the
453 //!< increments to this integer
454 uint64_t default_value; //!< The default value of the integer
455};
456
457/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
458 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
459 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
460 * memory
461 * @return pldm_completion_codes
462 */
463int pldm_bios_table_attr_entry_integer_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930464 const struct pldm_bios_table_attr_entry_integer_info *info,
465 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930466
467/** @brief Get length that an attribute entry(type: integer) will take
468 * @return The length that an entry(type: integer) will take
469 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930470size_t pldm_bios_table_attr_entry_integer_encode_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930471
472/** @brief Create an entry of BIOS Attribute Table (type: integer)
473 * @param[out] entry - Pointer to a buffer to create an entry
474 * @param[in] entry_length - Length of the buffer to create an entry
475 * @param[in] info - Pointer to an auxiliary structure @ref
476 * pldm_bios_table_attr_entry_integer_info
477 */
478void pldm_bios_table_attr_entry_integer_encode(
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 Create an entry of BIOS Attribute Table (type: integer) and check the
483 * validity of the parameters
484 * @param[out] entry - Pointer to a buffer to create an entry
485 * @param[in] entry_length - Length of the buffer to create an entry
486 * @param[in] info - Pointer to an auxiliary structure @ref
487 * pldm_bios_table_attr_entry_integer_info
488 * @return pldm_completion_codes
489 */
490int pldm_bios_table_attr_entry_integer_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930491 void *entry, size_t entry_length,
492 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930493
494/** @brief Decode the specific fields(integer) of attribute table entry
495 * @param[in] entry - Pointer to an entry of attribute table
496 * @param[out] lower - The lower bound on the integer value
497 * @param[out] upper - The upper bound on the integer value
498 * @param[out] scalar - The scalar value that is used for the increments to
499 * this integer
500 * @param[out] def - The default value of the integer
501 */
502void pldm_bios_table_attr_entry_integer_decode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930503 const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
504 uint64_t *upper, uint32_t *scalar, uint64_t *def);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930505
506/** @brief Get the attribute handle from the attribute value table entry
507 * @param[in] entry - Pointer to bios attribute value table entry
508 * @return handle to identify the attribute in the attribute value table
509 */
510uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930511 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930512
513/** @brief Get the attribute type from the attribute value table entry
514 * @param[in] entry - Pointer to bios attribute value table entry
515 * @return Type of the attribute value entry
516 */
517uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930518 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930519
520/** @brief Get length that an attribute value entry(type: enum) will take
521 * @param[in] count - Total number of current values for this enumeration
522 * @return The length that an entry(type: enum) will take
523 */
524size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
525
526/** @brief Create an attribute value entry(type: enum)
527 * @param[out] entry - Pointer to bios attribute value entry
528 * @param[in] entry_length - Length of attribute value entry
529 * @param[in] attr_handle - This handle points to an attribute in the
530 * BIOS Attribute Vlaue Table.
531 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
532 * Table
533 * @param[in] count - Total number of current values for this enum attribute
534 * @param[in] handle_indexes - Index into the array(provided in the BIOS
535 * Attribute Table) of the possible values of string handles for this attribute.
536 */
537void pldm_bios_table_attr_value_entry_encode_enum(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930538 void *entry, size_t entry_length, uint16_t attr_handle,
539 uint8_t attr_type, uint8_t count, const uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930540
541/** @brief Get number of current values for the enum entry
542 * @param[in] entry - Pointer to bios attribute value table entry
543 * @return Total number of current values for this enumeration
544 */
545uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930546 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930547
548/** @brief Get CurrentValueStringHandleIndex
549 * @param[in] entry - Pointer to bios attribute value table entry
550 * @param[in, out] handles - Pointer to a buffer to store
551 * CurrentValueStringHandleIndex
552 * @param[in] number - Number of PossibleValuesStringHandles expected
553 * @return Number of CurrentValueStringHandleIndex decoded.
554 */
555uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930556 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
557 uint8_t number);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930558
559/** @brief Create an attribute value entry(type: enum) and check the validity of
560 * the parameters
561 * @param[out] entry - Pointer to bios attribute value entry
562 * @param[in] entry_length - Length of attribute value entry
563 * @param[in] attr_handle - This handle points to an attribute in the
564 * BIOS Attribute Vlaue Table.
565 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
566 * Table
567 * @param[in] count - Total number of current values for this enum attribute
568 * @param[in] handle_indexes - Index into the array(provided in the BIOS
569 * Attribute Table) of the possible values of string handles for this attribute.
570 * @return pldm_completion_codes
571 */
572int pldm_bios_table_attr_value_entry_encode_enum_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930573 void *entry, size_t entry_length, uint16_t attr_handle,
574 uint8_t attr_type, uint8_t count, uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930575
576/** @brief Get length that an attribute value entry(type: string) will take
577 * @param[in] string_length - Length of the current string in byte, 0 indicates
578 * that the current string value is not set.
579 * @return The length that an entry(type: string) will take
580 */
581size_t
582pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
583
584/** @brief Create an attribute value entry(type: string)
585 * @param[out] entry - Pointer to bios attribute value entry
586 * @param[in] entry_length - Length of attribute value entry
587 * @param[in] attr_handle - This handle points to an attribute in the
588 * BIOS Attribute Vlaue Table.
589 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
590 * Table
591 * @param[in] string_length - Length of current string in bytes. 0 indicates
592 * that the current string value is not set.
593 * @param[in] string - The current string itsel
594 */
595void pldm_bios_table_attr_value_entry_encode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930596 void *entry, size_t entry_length, uint16_t attr_handle,
597 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930598
599/** @brief Get length of the current string in bytes
600 * @param [in] entry - Pointer to bios attribute value table entry
601 * @return The length of the current string in bytes
602 */
603uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930604 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930605
606/** @brief Get Current String Itself
607 * @param[in] entry - Pointer to bios attribute value table entry
608 * @param[in, out] current_string - Struct variable_field, contains a pointer
609 * to the CurrentString field in the buffer of
610 * \p entry, \p entry must be valid
611 * when \p current_string is used.
612 */
613void pldm_bios_table_attr_value_entry_string_decode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930614 const struct pldm_bios_attr_val_table_entry *entry,
615 struct variable_field *current_string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930616
617/** @brief Create an attribute value entry(type: string) and check the validity
618 * of the parameters
619 * @param[out] entry - Pointer to bios attribute value entry
620 * @param[in] entry_length - Length of attribute value entry
621 * @param[in] attr_handle - This handle points to an attribute in the
622 * BIOS Attribute Vlaue Table.
623 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
624 * Table
625 * @param[in] string_length - Length of current string in bytes. 0 indicates
626 * that the current string value is not set.
627 * @param[in] string - The current string itsel
628 * @return pldm_completion_codes
629 */
630int pldm_bios_table_attr_value_entry_encode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930631 void *entry, size_t entry_length, uint16_t attr_handle,
632 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930633
634/** @brief Get length that an attribute value entry(type: integer) will take
635 * @return The length that an entry(type: integer) will take
636 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930637size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930638
639/** @brief Create an attribute value entry(type: integer)
640 * @param[out] entry - Pointer to bios attribute value entry
641 * @param[in] entry_length - Length of attribute value entry
642 * @param[in] attr_handle - This handle points to an attribute in the
643 * BIOS Attribute Vlaue Table.
644 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
645 * Table
646 * @param[in] cv - Current Value
647 */
648void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
649 size_t entry_length,
650 uint16_t attr_handle,
651 uint8_t attr_type,
652 uint64_t cv);
653
654/** @brief Get current values for the integer entry
655 * @param[in] entry - Pointer to bios attribute value table entry
656 * @return Current Value
657 */
658uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930659 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930660
661/** @brief Create an attribute value entry(type: integer) and check the validity
662 * of the parameters
663 * @param[out] entry - Pointer to bios attribute value entry
664 * @param[in] entry_length - Length of attribute value entry
665 * @param[in] attr_handle - This handle points to an attribute in the
666 * BIOS Attribute Vlaue Table.
667 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
668 * Table
669 * @param[in] cv - Current Value
670 * @return pldm_completion_codes
671 */
672int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
673 size_t entry_length,
674 uint16_t attr_handle,
675 uint8_t attr_type,
676 uint64_t cv);
677
678/** @brief Get the handle from the attribute value entry
679 * @param[in] entry - Pointer to bios attribute value entry
680 * @return handle to identify the attribute in the attribute value table
681 */
682uint16_t pldm_bios_table_attr_value_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930683 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930684
685/** @brief Get the length of the attribute value entry
686 * @param[in] entry - Pointer to bios attribute value entry
687 * @return Length of the entry
688 */
689size_t pldm_bios_table_attr_value_entry_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930690 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930691
692/** @brief Find an entry in attribute value table by handle
693 * @param[in] table - The BIOS Attribute Value Table
694 * @param[in] length - Length of the BIOS Attribute Value Table
695 * @param[in] handle - handle to identify the attribute in the attribute value
696 * table
697 * @return Pointer to the entry
698 */
699const struct pldm_bios_attr_val_table_entry *
700pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
701 uint16_t handle);
702
703/** @brief Get the size of pad and checksum
704 * @param[in] size_without_pad - Table size without pad
705 * @return The size of pad and checksum
706 */
707size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
708
709/** @brief Append pad and checksum at the end of the table
710 * @param[in,out] table - Pointer to a buffer of a bios table
711 * @param[in] size - Size of the buffer of a bios table
712 * @param[in] size_without_pad - Table size without pad and checksum
713 * @return Total size of the table
714 */
715size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
716 size_t size_without_pad);
717
718/** @brief Build a new table and update an entry
719 * @param[in] src_table - Pointer to the source table
720 * @param[in] src_length - Size of the source table
721 * @param[out] dest_table - Pointer to the buffer of destination table
722 * @param[in,out] dest_length - Buffer size of the destination table as input
723 * parameter and will be assigned the length of
724 * the new table, if the function returns
725 * PLDM_SUCCESS
726 * @param[in] entry - Pointer to an entry
727 * @param[in] entry_length - Size of the entry
728 * @return pldm_completion_codes
729 */
730int pldm_bios_table_attr_value_copy_and_update(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930731 const void *src_table, size_t src_length, void *dest_table,
732 size_t *dest_length, const void *entry, size_t entry_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930733
734/** @brief Verify the crc value of the complete table
735 * @param[in] table - Pointer to a buffer of a bios table
736 * @param[in] size - Size of the buffer of a bios table
737 * @return true: crc value is correct
738 */
739bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
740
741#ifdef __cplusplus
742}
743#endif
744
745#endif