blob: bd4269024f2dbb4c869cd3e95fcdee6c18f447d7 [file] [log] [blame]
John Wang02700402019-10-06 16:34:29 +08001#ifndef BIOS_TABLE_H__
2#define BIOS_TABLE_H__
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "bios.h"
9#include <stdbool.h>
10#include <stddef.h>
11#include <stdint.h>
12
13/** @struct pldm_bios_table_iter
14 * structure representing bios table iterator
15 */
16struct pldm_bios_table_iter;
17
18/** @brief Create a bios table iterator
19 * @param[in] table - Pointer to table data
20 * @param[in] length - Length of table data
21 * @param[in] type - Type of pldm bios table
22 * @return Iterator to the beginning
23 */
24struct pldm_bios_table_iter *
25pldm_bios_table_iter_create(const void *table, size_t length,
26 enum pldm_bios_table_types type);
27
28/** @brief Release a bios table iterator
29 * @param[in] iter - Pointer to bios table iterator
30 */
31void pldm_bios_table_iter_free(struct pldm_bios_table_iter *iter);
32
33/** @brief Check if the iterator reaches the end of the bios table
34 * @param[in] iter - Pointer to the bios table iterator
35 * @return true if iterator reaches the end
36 * @note *end* is a position after the last entry.
37 */
38bool pldm_bios_table_iter_is_end(const struct pldm_bios_table_iter *iter);
39
40/** @brief Get iterator to next entry
41 * @param[in] iter - Pointer the bios table iterator
42 */
43void pldm_bios_table_iter_next(struct pldm_bios_table_iter *iter);
44
45/** @brief Get the bios table entry that the iterator points to
46 * @param[in] iter - Pointer to the bios table iterator
47 * @return Pointer to an entry in bios table
48 */
49const void *pldm_bios_table_iter_value(struct pldm_bios_table_iter *iter);
50
51/** @brief Get the bios attribute table entry that the iterator points to
52 * @param[in] iter - Pointer the bios attribute table iterator
53 * @return Pointer to an entry in bios attribute table
54 */
55static inline const struct pldm_bios_attr_table_entry *
56pldm_bios_table_iter_attr_entry_value(struct pldm_bios_table_iter *iter)
57{
58 return (const struct pldm_bios_attr_table_entry *)
59 pldm_bios_table_iter_value(iter);
60}
61
John Wangdd9a6282019-10-11 18:52:46 +080062/** @brief Get the bios string table entry that the iterator ponit to
63 * @param[in] iter - Pointer the bios string table iterator
64 * @return Pointer to an entry in bios string table
65 */
66static inline const struct pldm_bios_string_table_entry *
67pldm_bios_table_iter_string_entry_value(struct pldm_bios_table_iter *iter)
68{
69 return (const struct pldm_bios_string_table_entry *)
70 pldm_bios_table_iter_value(iter);
71}
72
73/** @brief Get the length of an entry in the BIOS String Table
74 * @param[in] string_length - Length of string
75 * @return Length of an entry in bytes
76 */
77size_t pldm_bios_table_string_entry_encode_length(uint16_t string_length);
78
79/** @brief Create an entry of BIOS String Table
80 * @param[out] entry - Pointer to a buffer to create an entry
81 * @param[in] entry_length - Length of the buffer to create an entry
82 * @param[in] str - String itself
83 * @param[in] str_length - Length of the string
84 */
85void pldm_bios_table_string_entry_encode(void *entry, size_t entry_length,
86 const char *str, uint16_t str_length);
87
88/** @brief Create an entry of BIOS String Table and check the validity of the
89 * parameters
90 * @param[out] entry - Pointer to a buffer to create an entry
91 * @param[in] entry_length - Length of the buffer to create an entry
92 * @param[in] str - String itself
93 * @param[in] str_length - Length of the string
94 * @return pldm_completion_codes
95 */
96int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
97 const char *str,
98 uint16_t str_length);
99
100/** @brief Get the string handle for the entry
101 * @param[in] entry - Pointer to a bios string table entry
102 * @return Handle to identify a string in the bios string table
103 */
104uint16_t pldm_bios_table_string_entry_decode_handle(
105 const struct pldm_bios_string_table_entry *entry);
106
107/** @brief Get the string length for the entry
108 * @param[in] entry - Pointer to a bios string table entry
109 * @return Length of string in bytes
110 */
111uint16_t pldm_bios_table_string_entry_decode_string_length(
112 const struct pldm_bios_string_table_entry *entry);
113
114/** @brief Get the string(at most one less than *size* characters) from the
115 * entry
116 * @param[in] entry - Pointer to a bios string table entry
117 * @param[out] buffer - Pointer to a buffer to store the string
118 * @param[in] size - Size of the buffer to store the string
119 * @return Length of the string decoded
120 */
121uint16_t pldm_bios_table_string_entry_decode_string(
122 const struct pldm_bios_string_table_entry *entry, char *buffer,
123 size_t size);
124
125/** @brief Get the string from the entry and check the validity of the
126 * parameters
127 * @param[in] entry - Pointer to a bios string table entry
128 * @param[out] buffer - Pointer to a buffer to store the string
129 * @param[in] size - Size of the buffer to store the string
130 * @return pldm_completion_codes
131 */
132int pldm_bios_table_string_entry_decode_string_check(
133 const struct pldm_bios_string_table_entry *entry, char *buffer,
134 size_t size);
135
136/** @brief Find an entry in bios string table by string
137 * @param[in] table - The BIOS String Table
138 * @param[in] length - Length of the BIOS String Table
139 * @param[in] str - String itself
140 * @return Pointer to an entry in the bios string table
141 */
142const struct pldm_bios_string_table_entry *
143pldm_bios_table_string_find_by_string(const void *table, size_t length,
144 const char *str);
145/** @brief Find an entry in bios string table by handle
146 * @param[in] table - The BIOS String Table
147 * @param[in] length - Length of the BIOS String Table
148 * @param[in] handle - Handle to identify a string in the bios string table
149 * @return Pointer to an entry in the bios string table
150 */
151const struct pldm_bios_string_table_entry *
152pldm_bios_table_string_find_by_handle(const void *table, size_t length,
153 uint16_t handle);
154
John Wangccc04552019-10-14 14:28:25 +0800155/** @struct pldm_bios_table_attr_entry_enum_info
156 *
157 * An auxiliary structure for passing parameters to @ref
158 * pldm_bios_table_attr_entry_enum_encode
159 *
160 */
161struct pldm_bios_table_attr_entry_enum_info {
162 uint16_t name_handle; //!< attribute name handle
163 bool read_only; //!< indicate whether the attribute is read-only
164 uint8_t pv_num; //!< number of possible values
165 const uint16_t *pv_handle; //!< handles of possible values
166 uint8_t def_num; //!< nnumber of default values
167 const uint8_t *def_index; //!< indices of default values.
168};
169
170/** @brief Get length that an attribute entry(type: enum) will take
171 * @param[in] pv_num - Number of possible values
172 * @param[in] def_num - Number of default values
173 * @return The length that an entry(type: enum) will take
174 */
175size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
176 uint8_t def_num);
177
178/** @brief Create an entry of BIOS Attribute Table (type: enum)
179 * @param[out] entry - Pointer to a buffer to create an entry
180 * @param[in] entry_length - Length of the buffer to create an entry
181 * @param[in] info - Pointer to an auxiliary structure @ref
182 * pldm_bios_table_attr_entry_enum_info
183 */
184void pldm_bios_table_attr_entry_enum_encode(
185 void *entry, size_t entry_length,
186 const struct pldm_bios_table_attr_entry_enum_info *info);
187
188/** @brief Create an entry of BIOS Attribute Table (type: enum) and check the
189 * validity of the parameters
190 * @param[out] entry - Pointer to a buffer to create an entry
191 * @param[in] entry_length - Length of the buffer to create an entry
192 * @param[in] info - Pointer to an auxiliary structure @ref
193 * pldm_bios_table_attr_entry_enum_info
194 * @return pldm_completion_codes
195 */
196int pldm_bios_table_attr_entry_enum_encode_check(
197 void *entry, size_t entry_length,
198 const struct pldm_bios_table_attr_entry_enum_info *info);
199
John Wang02700402019-10-06 16:34:29 +0800200/** @brief Get the total number of possible values for the entry
201 * @param[in] entry - Pointer to bios attribute table entry
202 * @return total number of possible values
203 */
204uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
205 const struct pldm_bios_attr_table_entry *entry);
206
207/** @brief Get the total number of possible values for the entry and check the
208 * validity of the parameters
209 * @param[in] entry - Pointer to bios attribute table entry
210 * @param[out] pv_num - Pointer to total number of possible values
211 * @return pldm_completion_codes
212 */
213int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
214 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
215
216/** @brief Get the total number of default values for the entry
217 * @param[in] entry - Pointer to bios attribute table entry
218 * @return total number of default values
219 */
220uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
221 const struct pldm_bios_attr_table_entry *entry);
222
223/** @brief Get the total number of default values for the entry and check the
224 * validity of the parameters
225 * @param[in] entry - Pointer to bios attribute table entry
226 * @param[out] def_num - Pointer to total number of default values
227 * @return pldm_completion_codes
228 */
229int pldm_bios_table_attr_entry_enum_decode_def_num_check(
230 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
231
John Wang3ad21752019-10-06 16:42:21 +0800232/** @brief Get possible values string handles
233 * @param[in] entry - Pointer to bios attribute table entry
234 * @param[out] pv_hdls - Pointer to a buffer to stroe
235 * PossibleValuesStringHandles
236 * @param[in] pv_num - Number of PossibleValuesStringHandles expected
237 * @return pldm_completion_codes
238 */
239uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
240 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
241 uint8_t pv_num);
242
243/** @brief Get possible values string handles and check the validity of the
244 * parameters
245 * @param[in] entry - Pointer to bios attribute table entry
246 * @param[out] pv_hdls - Pointer to a buffer to stroe
247 * PossibleValuesStringHandles
248 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
249 * stroe
250 * @return Number of PossibleValuesStringHandles decoded
251 */
252int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
253 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
254 uint8_t pv_num);
255
John Wangccc04552019-10-14 14:28:25 +0800256/** @struct pldm_bios_table_attr_entry_string_info
257 *
258 * An auxiliary structure for passing parameters to @ref
259 * pldm_bios_table_attr_entry_string_encode
260 *
261 */
262struct pldm_bios_table_attr_entry_string_info {
263 uint16_t name_handle; //!< attribute name handle
264 bool read_only; //!< indicate whether the attribute is read-only
265 uint8_t string_type; //!< The type of the string
266 uint16_t min_length; //!< The minimum length of the string in bytes
267 uint16_t max_length; //!< The maximum length of the string in bytes
268 uint16_t def_length; //!< The length of the defaut string in bytes
269 const char *def_string; //!< The default string itself
270};
271
John Wang827c5de2019-11-07 18:27:27 +0800272/** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info
273 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info
274 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
275 * memory
276 * @return pldm_completion_codes
277 */
278int pldm_bios_table_attr_entry_string_info_check(
279 const struct pldm_bios_table_attr_entry_string_info *info,
280 const char **errmsg);
281
John Wangccc04552019-10-14 14:28:25 +0800282/** @brief Get length that an attribute entry(type: string) will take
283 * @param[in] def_str_len - Length of default string
284 * @return The length that an entry(type: string) will take
285 */
286size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
287
288/** @brief Create an entry of BIOS Attribute Table (type: string)
289 * @param[out] entry - Pointer to a buffer to create an entry
290 * @param[in] entry_length - Length of the buffer to create an entry
291 * @param[in] info - Pointer to an auxiliary structure @ref
292 * pldm_bios_table_attr_entry_string_info
293 */
294void pldm_bios_table_attr_entry_string_encode(
295 void *entry, size_t entry_length,
296 const struct pldm_bios_table_attr_entry_string_info *info);
297
298/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
299 * validity of the parameters
300 * @param[out] entry - Pointer to a buffer to create an entry
301 * @param[in] entry_length - Length of the buffer to create an entry
302 * @param[in] info - Pointer to an auxiliary structure @ref
303 * pldm_bios_table_attr_entry_string_info
304 * @return pldm_completion_codes
305 */
306int pldm_bios_table_attr_entry_string_encode_check(
307 void *entry, size_t entry_length,
308 const struct pldm_bios_table_attr_entry_string_info *info);
309
John Wang02700402019-10-06 16:34:29 +0800310/** @brief Get the length of default string in bytes for the entry
311 * @param[in] entry - Pointer to bios attribute table entry
312 * @return length of default string in bytes
313 */
314uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
315 const struct pldm_bios_attr_table_entry *entry);
316
317/** @brief Get the length of default string in bytes for the entry and check the
318 * validity of the parameters
319 * @param[in] entry - Pointer to bios attribute table entry
320 * @param[out] def_string_length Pointer to length of default string in bytes
321 * @return pldm_completion_codes
322 */
323int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
324 const struct pldm_bios_attr_table_entry *entry,
325 uint16_t *def_string_length);
326
John Wangca230822019-10-16 11:39:27 +0800327/** @struct pldm_bios_table_attr_entry_integer_info
328 *
329 * An auxiliary structure for passing parameters to @ref
330 * pldm_bios_table_attr_entry_integer_encode
331 *
332 */
333struct pldm_bios_table_attr_entry_integer_info {
334 uint16_t name_handle; //!< attribute name handle
335 bool read_only; //!< indicate whether the attribute is read-only
336 uint64_t lower_bound; //!< The lower bound on the integer value
337 uint64_t upper_bound; //!< The upper bound on the integer value
338 uint32_t scalar_increment; //!< The scalar value that is used for the
339 //!< increments to this integer
340 uint64_t default_value; //!< The default value of the integer
341};
342
John Wang827c5de2019-11-07 18:27:27 +0800343/** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info
344 * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info
345 * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated
346 * memory
347 * @return pldm_completion_codes
348 */
349int pldm_bios_table_attr_entry_integer_info_check(
350 const struct pldm_bios_table_attr_entry_integer_info *info,
351 const char **errmsg);
352
John Wangca230822019-10-16 11:39:27 +0800353/** @brief Get length that an attribute entry(type: integer) will take
354 * @return The length that an entry(type: integer) will take
355 */
356size_t pldm_bios_table_attr_entry_integer_encode_length();
357
358/** @brief Create an entry of BIOS Attribute Table (type: integer)
359 * @param[out] entry - Pointer to a buffer to create an entry
360 * @param[in] entry_length - Length of the buffer to create an entry
361 * @param[in] info - Pointer to an auxiliary structure @ref
362 * pldm_bios_table_attr_entry_integer_info
363 */
364void pldm_bios_table_attr_entry_integer_encode(
365 void *entry, size_t entry_length,
366 const struct pldm_bios_table_attr_entry_integer_info *info);
367
368/** @brief Create an entry of BIOS Attribute Table (type: integer) and check the
369 * validity of the parameters
370 * @param[out] entry - Pointer to a buffer to create an entry
371 * @param[in] entry_length - Length of the buffer to create an entry
372 * @param[in] info - Pointer to an auxiliary structure @ref
373 * pldm_bios_table_attr_entry_integer_info
374 * @return pldm_completion_codes
375 */
376int pldm_bios_table_attr_entry_integer_encode_check(
377 void *entry, size_t entry_length,
378 const struct pldm_bios_table_attr_entry_integer_info *info);
379
John Wang3ad21752019-10-06 16:42:21 +0800380/** @brief Get length that an attribute value entry(type: enum) will take
381 * @param[in] count - Total number of current values for this enumeration
382 * @return The length that an entry(type: enum) will take
383 */
384size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
385
386/** @brief Create an attribute value entry(type: enum)
387 * @param[out] entry - Pointer to bios attribute value entry
388 * @param[in] entry_length - Length of attribute value entry
389 * @param[in] attr_handle - This handle points to an attribute in the
390 * BIOS Attribute Vlaue Table.
391 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
392 * Table
393 * @param[in] count - Total number of current values for this enum attribute
394 * @param[in] handle_indexes - Index into the array(provided in the BIOS
395 * Attribute Table) of the possible values of string handles for this attribute.
396 */
397void pldm_bios_table_attr_value_entry_encode_enum(
398 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
399 uint8_t count, uint8_t *handle_indexes);
400
401/** @brief Create an attribute value entry(type: enum) and check the validity of
402 * the parameters
403 * @param[out] entry - Pointer to bios attribute value entry
404 * @param[in] entry_length - Length of attribute value entry
405 * @param[in] attr_handle - This handle points to an attribute in the
406 * BIOS Attribute Vlaue Table.
407 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
408 * Table
409 * @param[in] count - Total number of current values for this enum attribute
410 * @param[in] handle_indexes - Index into the array(provided in the BIOS
411 * Attribute Table) of the possible values of string handles for this attribute.
412 * @return pldm_completion_codes
413 */
414int pldm_bios_table_attr_value_entry_encode_enum_check(
415 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
416 uint8_t count, uint8_t *handle_indexes);
417
418/** @brief Get length that an attribute value entry(type: string) will take
419 * @param[in] string_length - Length of the current string in byte, 0 indicates
420 * that the current string value is not set.
421 * @return The length that an entry(type: string) will take
422 */
423size_t
424pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
425
426/** @brief Create an attribute value entry(type: string)
427 * @param[out] entry - Pointer to bios attribute value entry
428 * @param[in] entry_length - Length of attribute value entry
429 * @param[in] attr_handle - This handle points to an attribute in the
430 * BIOS Attribute Vlaue Table.
431 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
432 * Table
433 * @param[in] string_length - Length of current string in bytes. 0 indicates
434 * that the current string value is not set.
435 * @param[in] string - The current string itsel
436 */
437void pldm_bios_table_attr_value_entry_encode_string(
438 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
439 uint16_t string_length, const char *string);
440/** @brief Create an attribute value entry(type: string) and check the validity
441 * of the parameters
442 * @param[out] entry - Pointer to bios attribute value entry
443 * @param[in] entry_length - Length of attribute value entry
444 * @param[in] attr_handle - This handle points to an attribute in the
445 * BIOS Attribute Vlaue Table.
446 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
447 * Table
448 * @param[in] string_length - Length of current string in bytes. 0 indicates
449 * that the current string value is not set.
450 * @param[in] string - The current string itsel
451 * @return pldm_completion_codes
452 */
453int pldm_bios_table_attr_value_entry_encode_string_check(
454 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
455 uint16_t string_length, const char *string);
456
John Wangca230822019-10-16 11:39:27 +0800457/** @brief Get length that an attribute value entry(type: integer) will take
458 * @return The length that an entry(type: integer) will take
459 */
460size_t pldm_bios_table_attr_value_entry_encode_integer_length();
461
462/** @brief Create an attribute value entry(type: integer)
463 * @param[out] entry - Pointer to bios attribute value entry
464 * @param[in] entry_length - Length of attribute value entry
465 * @param[in] attr_handle - This handle points to an attribute in the
466 * BIOS Attribute Vlaue Table.
467 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
468 * Table
469 * @param[in] cv - Current Value
470 */
471void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
472 size_t entry_length,
473 uint16_t attr_handle,
474 uint8_t attr_type,
475 uint64_t cv);
476
477/** @brief Create an attribute value entry(type: integer) and check the validity
478 * of the parameters
479 * @param[out] entry - Pointer to bios attribute value entry
480 * @param[in] entry_length - Length of attribute value entry
481 * @param[in] attr_handle - This handle points to an attribute in the
482 * BIOS Attribute Vlaue Table.
483 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
484 * Table
485 * @param[in] cv - Current Value
486 * @return pldm_completion_codes
487 */
488int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
489 size_t entry_length,
490 uint16_t attr_handle,
491 uint8_t attr_type,
492 uint64_t cv);
John Wang02700402019-10-06 16:34:29 +0800493#ifdef __cplusplus
494}
495#endif
496
497#endif