blob: f69fa71bc7e9f676bdc4da1583fd398a1107d684 [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
Andrew Jeffery9c766792022-08-10 23:12:49 +093091/** @brief Create an entry of BIOS String Table and check the validity of the
92 * parameters
Andrew Jeffery91f4b542023-06-13 20:59:51 +093093 *
Andrew Jeffery9c766792022-08-10 23:12:49 +093094 * @param[out] entry - Pointer to a buffer to create an entry
95 * @param[in] entry_length - Length of the buffer to create an entry
96 * @param[in] str - String itself
97 * @param[in] str_length - Length of the string
Andrew Jeffery91f4b542023-06-13 20:59:51 +093098 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or str are NULL, or
99 * PLDM_ERROR_INVALID_LENGTH if entry_length is insufficient for encoding str. An
100 * appropriate value for entry_length can be determined using
101 * @ref pldm_bios_table_string_entry_encode_length
Andrew Jeffery9c766792022-08-10 23:12:49 +0930102 */
103int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
104 const char *str,
105 uint16_t str_length);
106
107/** @brief Get the string handle for the entry
108 * @param[in] entry - Pointer to a bios string table entry
109 * @return Handle to identify a string in the bios string table
110 */
111uint16_t pldm_bios_table_string_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930112 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930113
114/** @brief Get the string length for the entry
115 * @param[in] entry - Pointer to a bios string table entry
116 * @return Length of string in bytes
117 */
118uint16_t pldm_bios_table_string_entry_decode_string_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930119 const struct pldm_bios_string_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930120
Andrew Jeffery9c766792022-08-10 23:12:49 +0930121/** @brief Get the string from the entry and check the validity of the
122 * parameters
123 * @param[in] entry - Pointer to a bios string table entry
124 * @param[out] buffer - Pointer to a buffer to store the string
125 * @param[in] size - Size of the buffer to store the string
Andrew Jeffery23250312023-06-13 21:07:46 +0930126 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or buffer are NULL, or
Andrew Jeffery98c1e692023-06-14 14:41:19 +0930127 * PLDM_ERROR_INVALID_LENGTH if size is insufficient for NUL termination. An
Andrew Jeffery23250312023-06-13 21:07:46 +0930128 * appropriate value for size can be determined using the expression
Andrew Jeffery98c1e692023-06-14 14:41:19 +0930129 * `pldm_bios_table_string_entry_decode_string_length(entry) + 1`. The provided size value
130 * may be smaller than the entry's string, in which case the string placed in buffer will
131 * be truncated (but still NUL terminated).
Andrew Jeffery9c766792022-08-10 23:12:49 +0930132 */
133int pldm_bios_table_string_entry_decode_string_check(
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 Find an entry in bios string table by string
138 * @param[in] table - The BIOS String Table
139 * @param[in] length - Length of the BIOS String Table
140 * @param[in] str - String itself
141 * @return Pointer to an entry in the bios string table
142 */
143const struct pldm_bios_string_table_entry *
144pldm_bios_table_string_find_by_string(const void *table, size_t length,
145 const char *str);
146/** @brief Find an entry in bios string table by handle
147 * @param[in] table - The BIOS String Table
148 * @param[in] length - Length of the BIOS String Table
149 * @param[in] handle - Handle to identify a string in the bios string table
150 * @return Pointer to an entry in the bios string table
151 */
152const struct pldm_bios_string_table_entry *
153pldm_bios_table_string_find_by_handle(const void *table, size_t length,
154 uint16_t handle);
155
156/** @brief Get the attribute handle from the attribute table entry
157 * @param[in] entry - Pointer to bios attribute table entry
158 * @return handle to identify the attribute in the attribute table
159 */
160uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930161 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930162
163/** @brief Get the attribute type of the attribute table entry
164 * @param[in] entry - Pointer to bios attribute table entry
165 * @return Type of the attribute table entry
166 */
167uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930168 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930169
170/** @brief Get the attribute name handle from the attribute table entry
171 * @param[in] entry - Pointer to bios attribute table entry
172 * @return handle to identify the name of the attribute, this handle points
173 * to a string in the bios string table.
174 */
175uint16_t pldm_bios_table_attr_entry_decode_string_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 Find an entry in attribute table by handle
179 * @param[in] table - The BIOS Attribute Table
180 * @param[in] length - Length of the BIOS Attribute Table
181 * @param[in] handle - handle to identify the attribute in the attribute table
182 * @return Pointer to the entry
183 */
184const struct pldm_bios_attr_table_entry *
185pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
186 uint16_t handle);
187
188/** @brief Find an entry in attribute table by string handle
189 * @param[in] table - The BIOS Attribute Table
190 * @param[in] length - Length of the BIOS Attribute Table
191 * @param[in] handle - The string handle
192 * @return Pointer to the entry
193 */
194const struct pldm_bios_attr_table_entry *
195pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
196 uint16_t handle);
197
198/** @struct pldm_bios_table_attr_entry_enum_info
199 *
200 * An auxiliary structure for passing parameters to @ref
Andrew Jeffery6409c8a2023-06-14 11:38:31 +0930201 * pldm_bios_table_attr_entry_enum_encode_check
Andrew Jeffery9c766792022-08-10 23:12:49 +0930202 *
203 */
204struct pldm_bios_table_attr_entry_enum_info {
205 uint16_t name_handle; //!< attribute name handle
206 bool read_only; //!< indicate whether the attribute is read-only
207 uint8_t pv_num; //!< number of possible values
208 const uint16_t *pv_handle; //!< handles of possible values
209 uint8_t def_num; //!< nnumber of default values
210 const uint8_t *def_index; //!< indices of default values.
211};
212
213/** @brief Get length that an attribute entry(type: enum) will take
214 * @param[in] pv_num - Number of possible values
215 * @param[in] def_num - Number of default values
216 * @return The length that an entry(type: enum) will take
217 */
218size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
219 uint8_t def_num);
220
Andrew Jeffery9c766792022-08-10 23:12:49 +0930221/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
222 * validity of the parameters
223 * @param[out] entry - Pointer to a buffer to create an entry
224 * @param[in] entry_length - Length of the buffer to create an entry
225 * @param[in] info - Pointer to an auxiliary structure @ref
226 * pldm_bios_table_attr_entry_enum_info
Andrew Jeffery657bfd02023-06-14 07:14:42 +0930227 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or info are NULL, or
228 * PLDM_ERROR_INVALID_LENGTH if entry_length is insufficient to encode info. An appropriate
229 * value for entry_length can be determined using @ref
230 * pldm_bios_table_attr_entry_enum_encode_length.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930231 */
232int pldm_bios_table_attr_entry_enum_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930233 void *entry, size_t entry_length,
234 const struct pldm_bios_table_attr_entry_enum_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930235
Andrew Jeffery9c766792022-08-10 23:12:49 +0930236/** @brief Get the total number of possible values for the entry and check the
237 * validity of the parameters
238 * @param[in] entry - Pointer to bios attribute table entry
239 * @param[out] pv_num - Pointer to total number of possible values
Andrew Jeffery4f7ebda2023-06-13 21:49:38 +0930240 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or pv_num are NULL, or
241 * PLDM_ERROR_INVALID_DATA if entry is not a valid PLDM_BIOS_ENUMERATION
Andrew Jeffery9c766792022-08-10 23:12:49 +0930242 */
243int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930244 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930245
Andrew Jeffery9c766792022-08-10 23:12:49 +0930246/** @brief Get the total number of default values for the entry and check the
247 * validity of the parameters
248 * @param[in] entry - Pointer to bios attribute table entry
249 * @param[out] def_num - Pointer to total number of default values
Andrew Jeffery437a83a2023-06-13 22:36:26 +0930250 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_num are NULL,
251 * or entry is not of type PLDM_BIOS_ENUMERATION.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930252 */
253int pldm_bios_table_attr_entry_enum_decode_def_num_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930254 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930255
Andrew Jeffery9c766792022-08-10 23:12:49 +0930256/** @brief Get possible values string handles and check the validity of the
257 * parameters
258 * @param[in] entry - Pointer to bios attribute table entry
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930259 * @param[out] pv_hdls - Pointer to a buffer to store
Andrew Jeffery9c766792022-08-10 23:12:49 +0930260 * PossibleValuesStringHandles
261 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
Andrew Jeffery2ebec8d2023-06-13 22:16:08 +0930262 * store
Andrew Jefferyf3d851f2023-06-13 22:24:48 +0930263 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or pv_hdls are NULL,
Andrew Jeffery0c9f5a82023-06-14 15:01:06 +0930264 * or entry is not of type PLDM_BIOS_ENUMERATION. An appropriate value for pv_num can be
265 * determined using @ref pldm_bios_table_attr_entry_enum_decode_pv_num_check. pv_num may be
266 * less than the value provided by @ref
267 * pldm_bios_table_attr_entry_enum_decode_pv_num_check, in which case only the first pv_num
268 * handles will be decoded.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930269 */
270int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930271 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
272 uint8_t pv_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930273
274/** @brief Get Indices of default values
275 * @param[in] entry - Pointer to bios attribute table entry
276 * @param[out] def_indices - Pointer to a buffer to store
277 * default value indices
278 * @param[in] def_num - Number of DefaultValues the buffer can
279 * store
280 * @return Number of default values decoded
281 */
282uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930283 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
284 uint8_t def_num);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930285
286/** @struct pldm_bios_table_attr_entry_string_info
287 *
288 * An auxiliary structure for passing parameters to @ref
289 * pldm_bios_table_attr_entry_string_encode
290 *
291 */
292struct pldm_bios_table_attr_entry_string_info {
293 uint16_t name_handle; //!< attribute name handle
294 bool read_only; //!< indicate whether the attribute is read-only
295 uint8_t string_type; //!< The type of the string
296 uint16_t min_length; //!< The minimum length of the string in bytes
297 uint16_t max_length; //!< The maximum length of the string in bytes
298 uint16_t def_length; //!< The length of the defaut string in bytes
299 const char *def_string; //!< The default string itself
300};
301
302/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
303 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
304 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
305 * memory
306 * @return pldm_completion_codes
307 */
308int pldm_bios_table_attr_entry_string_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930309 const struct pldm_bios_table_attr_entry_string_info *info,
310 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930311
312/** @brief Get length that an attribute entry(type: string) will take
313 * @param[in] def_str_len - Length of default string
314 * @return The length that an entry(type: string) will take
315 */
316size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
317
Andrew Jeffery9c766792022-08-10 23:12:49 +0930318/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
319 * validity of the parameters
320 * @param[out] entry - Pointer to a buffer to create an entry
321 * @param[in] entry_length - Length of the buffer to create an entry
322 * @param[in] info - Pointer to an auxiliary structure @ref
323 * pldm_bios_table_attr_entry_string_info
Andrew Jefferya5c32872023-06-13 21:34:26 +0930324 * @return PLDM_SUCCESS on success, PLDM_ERROR_INVALID_DATA if entry or info are NULL or info
325 * contains logically inconsistent data, or PLDM_ERROR_INVALID_LENGTH if entry_length is
326 * not sufficient to encode info. An appropriate value for entry_length can be determined
327 * using @ref pldm_bios_table_attr_entry_string_encode_length
Andrew Jeffery9c766792022-08-10 23:12:49 +0930328 */
329int pldm_bios_table_attr_entry_string_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930330 void *entry, size_t entry_length,
331 const struct pldm_bios_table_attr_entry_string_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930332
Andrew Jeffery9c766792022-08-10 23:12:49 +0930333/** @brief Get the length of default string in bytes for the entry and check the
334 * validity of the parameters
335 * @param[in] entry - Pointer to bios attribute table entry
336 * @param[out] def_string_length Pointer to length of default string in bytes
Andrew Jefferyb9a87692023-06-13 22:36:43 +0930337 * @return PLDM_SUCCESS on success, otherwise PLDM_ERROR_INVALID_DATA if entry or def_string_length
338 * are NULL, or entry is not of type PLDM_BIOS_STRING
Andrew Jeffery9c766792022-08-10 23:12:49 +0930339 */
340int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930341 const struct pldm_bios_attr_table_entry *entry,
342 uint16_t *def_string_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930343
344/** @brief Get the type of string of bios attribute table entry
345 * @param[in] entry - Pointer to bios attribute table entry
346 * @return Type of the string
347 */
348uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930349 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930350
351/** @brief Get maximum length of the string from a bios attribute table entry in
352 * bytes
353 * @param[in] entry - Pointer to a bios attribute table entry
354 * @return Maximum length of the string
355 */
356uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930357 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930358
359/** @brief Get minimum length of the string from a bios attribute table entry in
360 * bytes
361 * @param[in] entry - Pointer to a bios attribute table entry
362 * @return Minimum length of the string
363 */
364uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930365 const struct pldm_bios_attr_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930366
367/** @brief Get the default string from a bios attribute table entry
368 * @param[out] buffer - Pointer to a buffer to store the string
369 * @param[in] size - Size of the buffer to store the string
370 * @return Length of the string decoded
371 */
372uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930373 const struct pldm_bios_attr_table_entry *entry, char *buffer,
374 size_t size);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930375
376/** @struct pldm_bios_table_attr_entry_integer_info
377 *
378 * An auxiliary structure for passing parameters to @ref
379 * pldm_bios_table_attr_entry_integer_encode
380 *
381 */
382struct pldm_bios_table_attr_entry_integer_info {
383 uint16_t name_handle; //!< attribute name handle
384 bool read_only; //!< indicate whether the attribute is read-only
385 uint64_t lower_bound; //!< The lower bound on the integer value
386 uint64_t upper_bound; //!< The upper bound on the integer value
387 uint32_t scalar_increment; //!< The scalar value that is used for the
388 //!< increments to this integer
389 uint64_t default_value; //!< The default value of the integer
390};
391
392/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
393 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
394 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
395 * memory
396 * @return pldm_completion_codes
397 */
398int pldm_bios_table_attr_entry_integer_info_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930399 const struct pldm_bios_table_attr_entry_integer_info *info,
400 const char **errmsg);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930401
402/** @brief Get length that an attribute entry(type: integer) will take
403 * @return The length that an entry(type: integer) will take
404 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930405size_t pldm_bios_table_attr_entry_integer_encode_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930406
407/** @brief Create an entry of BIOS Attribute Table (type: integer)
408 * @param[out] entry - Pointer to a buffer to create an entry
409 * @param[in] entry_length - Length of the buffer to create an entry
410 * @param[in] info - Pointer to an auxiliary structure @ref
411 * pldm_bios_table_attr_entry_integer_info
412 */
413void pldm_bios_table_attr_entry_integer_encode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930414 void *entry, size_t entry_length,
415 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930416
417/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
418 * validity of the parameters
419 * @param[out] entry - Pointer to a buffer to create an entry
420 * @param[in] entry_length - Length of the buffer to create an entry
421 * @param[in] info - Pointer to an auxiliary structure @ref
422 * pldm_bios_table_attr_entry_integer_info
Andrew Jefferyfe0f01d2023-06-27 11:51:58 +0930423 * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry or info are null, or the data
424 * in info is not logically consistent. PLDM_ERROR_INVALID_LENGTH if entry_length lacks
425 * capacity to encode the attribute.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930426 */
427int pldm_bios_table_attr_entry_integer_encode_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930428 void *entry, size_t entry_length,
429 const struct pldm_bios_table_attr_entry_integer_info *info);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930430
431/** @brief Decode the specific fields(integer) of attribute table entry
432 * @param[in] entry - Pointer to an entry of attribute table
433 * @param[out] lower - The lower bound on the integer value
434 * @param[out] upper - The upper bound on the integer value
435 * @param[out] scalar - The scalar value that is used for the increments to
436 * this integer
437 * @param[out] def - The default value of the integer
438 */
439void pldm_bios_table_attr_entry_integer_decode(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930440 const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
441 uint64_t *upper, uint32_t *scalar, uint64_t *def);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930442
443/** @brief Get the attribute handle from the attribute value table entry
444 * @param[in] entry - Pointer to bios attribute value table entry
445 * @return handle to identify the attribute in the attribute value table
446 */
447uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930448 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930449
450/** @brief Get the attribute type from the attribute value table entry
451 * @param[in] entry - Pointer to bios attribute value table entry
452 * @return Type of the attribute value entry
453 */
454uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930455 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930456
457/** @brief Get length that an attribute value entry(type: enum) will take
458 * @param[in] count - Total number of current values for this enumeration
459 * @return The length that an entry(type: enum) will take
460 */
461size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
462
463/** @brief Create an attribute value entry(type: enum)
464 * @param[out] entry - Pointer to bios attribute value entry
465 * @param[in] entry_length - Length of attribute value entry
466 * @param[in] attr_handle - This handle points to an attribute in the
467 * BIOS Attribute Vlaue Table.
468 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
469 * Table
470 * @param[in] count - Total number of current values for this enum attribute
471 * @param[in] handle_indexes - Index into the array(provided in the BIOS
472 * Attribute Table) of the possible values of string handles for this attribute.
473 */
474void pldm_bios_table_attr_value_entry_encode_enum(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930475 void *entry, size_t entry_length, uint16_t attr_handle,
476 uint8_t attr_type, uint8_t count, const uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930477
478/** @brief Get number of current values for the enum entry
479 * @param[in] entry - Pointer to bios attribute value table entry
480 * @return Total number of current values for this enumeration
481 */
482uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930483 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930484
485/** @brief Get CurrentValueStringHandleIndex
486 * @param[in] entry - Pointer to bios attribute value table entry
487 * @param[in, out] handles - Pointer to a buffer to store
488 * CurrentValueStringHandleIndex
489 * @param[in] number - Number of PossibleValuesStringHandles expected
490 * @return Number of CurrentValueStringHandleIndex decoded.
491 */
492uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930493 const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
494 uint8_t number);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930495
496/** @brief Create an attribute value entry(type: enum) and check the validity of
497 * the parameters
498 * @param[out] entry - Pointer to bios attribute value entry
499 * @param[in] entry_length - Length of attribute value entry
500 * @param[in] attr_handle - This handle points to an attribute in the
501 * BIOS Attribute Vlaue Table.
502 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
503 * Table
504 * @param[in] count - Total number of current values for this enum attribute
505 * @param[in] handle_indexes - Index into the array(provided in the BIOS
506 * Attribute Table) of the possible values of string handles for this attribute.
Andrew Jeffery7aeb7ed2023-06-27 13:13:36 +0930507 * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry or handles are NULL, or if
508 * attr_type is not a PLDM_BIOS_ENUMERATION. PLDM_ERROR_INVALID_LENGTH if entry_length
509 * lacks capacity to encode handles into entry.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930510 */
511int pldm_bios_table_attr_value_entry_encode_enum_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930512 void *entry, size_t entry_length, uint16_t attr_handle,
Andrew Jeffery7aeb7ed2023-06-27 13:13:36 +0930513 uint8_t attr_type, uint8_t count, const uint8_t *handles);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930514
515/** @brief Get length that an attribute value entry(type: string) will take
516 * @param[in] string_length - Length of the current string in byte, 0 indicates
517 * that the current string value is not set.
518 * @return The length that an entry(type: string) will take
519 */
520size_t
521pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
522
523/** @brief Create an attribute value entry(type: string)
524 * @param[out] entry - Pointer to bios attribute value entry
525 * @param[in] entry_length - Length of attribute value entry
526 * @param[in] attr_handle - This handle points to an attribute in the
527 * BIOS Attribute Vlaue Table.
528 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
529 * Table
530 * @param[in] string_length - Length of current string in bytes. 0 indicates
531 * that the current string value is not set.
532 * @param[in] string - The current string itsel
533 */
534void pldm_bios_table_attr_value_entry_encode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930535 void *entry, size_t entry_length, uint16_t attr_handle,
536 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930537
538/** @brief Get length of the current string in bytes
539 * @param [in] entry - Pointer to bios attribute value table entry
540 * @return The length of the current string in bytes
541 */
542uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930543 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930544
545/** @brief Get Current String Itself
546 * @param[in] entry - Pointer to bios attribute value table entry
547 * @param[in, out] current_string - Struct variable_field, contains a pointer
548 * to the CurrentString field in the buffer of
549 * \p entry, \p entry must be valid
550 * when \p current_string is used.
551 */
552void pldm_bios_table_attr_value_entry_string_decode_string(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930553 const struct pldm_bios_attr_val_table_entry *entry,
554 struct variable_field *current_string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930555
556/** @brief Create an attribute value entry(type: string) and check the validity
557 * of the parameters
558 * @param[out] entry - Pointer to bios attribute value entry
559 * @param[in] entry_length - Length of attribute value entry
560 * @param[in] attr_handle - This handle points to an attribute in the
561 * BIOS Attribute Vlaue Table.
562 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
563 * Table
564 * @param[in] string_length - Length of current string in bytes. 0 indicates
565 * that the current string value is not set.
566 * @param[in] string - The current string itsel
Andrew Jeffery2d663932023-06-27 14:19:15 +0930567 * @return PLDM_SUCCESS on success. PLDM_ERROR_INVALID_DATA if entry is NULL, str is NULL while
568 * str_length is non-zero, or attr_type is not PLDM_BIOS_STRING. PLDM_ERROR_INVALID_LENGTH
569 * if entry_length lacks capacity to encode str into entry.
Andrew Jeffery9c766792022-08-10 23:12:49 +0930570 */
571int pldm_bios_table_attr_value_entry_encode_string_check(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930572 void *entry, size_t entry_length, uint16_t attr_handle,
573 uint8_t attr_type, uint16_t str_length, const char *string);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930574
575/** @brief Get length that an attribute value entry(type: integer) will take
576 * @return The length that an entry(type: integer) will take
577 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930578size_t pldm_bios_table_attr_value_entry_encode_integer_length(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930579
580/** @brief Create an attribute value entry(type: integer)
581 * @param[out] entry - Pointer to bios attribute value entry
582 * @param[in] entry_length - Length of attribute value entry
583 * @param[in] attr_handle - This handle points to an attribute in the
584 * BIOS Attribute Vlaue Table.
585 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
586 * Table
587 * @param[in] cv - Current Value
588 */
589void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
590 size_t entry_length,
591 uint16_t attr_handle,
592 uint8_t attr_type,
593 uint64_t cv);
594
595/** @brief Get current values for the integer entry
596 * @param[in] entry - Pointer to bios attribute value table entry
597 * @return Current Value
598 */
599uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930600 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930601
602/** @brief Create an attribute value entry(type: integer) and check the validity
603 * of the parameters
604 * @param[out] entry - Pointer to bios attribute value entry
605 * @param[in] entry_length - Length of attribute value entry
606 * @param[in] attr_handle - This handle points to an attribute in the
607 * BIOS Attribute Vlaue Table.
608 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
609 * Table
610 * @param[in] cv - Current Value
611 * @return pldm_completion_codes
612 */
613int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
614 size_t entry_length,
615 uint16_t attr_handle,
616 uint8_t attr_type,
617 uint64_t cv);
618
619/** @brief Get the handle from the attribute value entry
620 * @param[in] entry - Pointer to bios attribute value entry
621 * @return handle to identify the attribute in the attribute value table
622 */
623uint16_t pldm_bios_table_attr_value_entry_decode_handle(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930624 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930625
626/** @brief Get the length of the attribute value entry
627 * @param[in] entry - Pointer to bios attribute value entry
628 * @return Length of the entry
629 */
630size_t pldm_bios_table_attr_value_entry_length(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930631 const struct pldm_bios_attr_val_table_entry *entry);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930632
633/** @brief Find an entry in attribute value table by handle
634 * @param[in] table - The BIOS Attribute Value Table
635 * @param[in] length - Length of the BIOS Attribute Value Table
636 * @param[in] handle - handle to identify the attribute in the attribute value
637 * table
638 * @return Pointer to the entry
639 */
640const struct pldm_bios_attr_val_table_entry *
641pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
642 uint16_t handle);
643
644/** @brief Get the size of pad and checksum
645 * @param[in] size_without_pad - Table size without pad
646 * @return The size of pad and checksum
647 */
648size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad);
649
650/** @brief Append pad and checksum at the end of the table
651 * @param[in,out] table - Pointer to a buffer of a bios table
652 * @param[in] size - Size of the buffer of a bios table
653 * @param[in] size_without_pad - Table size without pad and checksum
654 * @return Total size of the table
655 */
656size_t pldm_bios_table_append_pad_checksum(void *table, size_t size,
657 size_t size_without_pad);
658
659/** @brief Build a new table and update an entry
660 * @param[in] src_table - Pointer to the source table
661 * @param[in] src_length - Size of the source table
662 * @param[out] dest_table - Pointer to the buffer of destination table
663 * @param[in,out] dest_length - Buffer size of the destination table as input
664 * parameter and will be assigned the length of
665 * the new table, if the function returns
666 * PLDM_SUCCESS
667 * @param[in] entry - Pointer to an entry
668 * @param[in] entry_length - Size of the entry
669 * @return pldm_completion_codes
670 */
671int pldm_bios_table_attr_value_copy_and_update(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930672 const void *src_table, size_t src_length, void *dest_table,
673 size_t *dest_length, const void *entry, size_t entry_length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930674
675/** @brief Verify the crc value of the complete table
676 * @param[in] table - Pointer to a buffer of a bios table
677 * @param[in] size - Size of the buffer of a bios table
678 * @return true: crc value is correct
679 */
680bool pldm_bios_table_checksum(const uint8_t *table, size_t size);
681
682#ifdef __cplusplus
683}
684#endif
685
686#endif