blob: 97c64ce82fe55d5f2caa999da9e383b00e5e839d [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
272/** @brief Get length that an attribute entry(type: string) will take
273 * @param[in] def_str_len - Length of default string
274 * @return The length that an entry(type: string) will take
275 */
276size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len);
277
278/** @brief Create an entry of BIOS Attribute Table (type: string)
279 * @param[out] entry - Pointer to a buffer to create an entry
280 * @param[in] entry_length - Length of the buffer to create an entry
281 * @param[in] info - Pointer to an auxiliary structure @ref
282 * pldm_bios_table_attr_entry_string_info
283 */
284void pldm_bios_table_attr_entry_string_encode(
285 void *entry, size_t entry_length,
286 const struct pldm_bios_table_attr_entry_string_info *info);
287
288/** @brief Create an entry of BIOS Attribute Table (type: string) and check the
289 * validity of the parameters
290 * @param[out] entry - Pointer to a buffer to create an entry
291 * @param[in] entry_length - Length of the buffer to create an entry
292 * @param[in] info - Pointer to an auxiliary structure @ref
293 * pldm_bios_table_attr_entry_string_info
294 * @return pldm_completion_codes
295 */
296int pldm_bios_table_attr_entry_string_encode_check(
297 void *entry, size_t entry_length,
298 const struct pldm_bios_table_attr_entry_string_info *info);
299
John Wang02700402019-10-06 16:34:29 +0800300/** @brief Get the length of default string in bytes for the entry
301 * @param[in] entry - Pointer to bios attribute table entry
302 * @return length of default string in bytes
303 */
304uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
305 const struct pldm_bios_attr_table_entry *entry);
306
307/** @brief Get the length of default string in bytes for the entry and check the
308 * validity of the parameters
309 * @param[in] entry - Pointer to bios attribute table entry
310 * @param[out] def_string_length Pointer to length of default string in bytes
311 * @return pldm_completion_codes
312 */
313int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
314 const struct pldm_bios_attr_table_entry *entry,
315 uint16_t *def_string_length);
316
John Wang3ad21752019-10-06 16:42:21 +0800317/** @brief Get length that an attribute value entry(type: enum) will take
318 * @param[in] count - Total number of current values for this enumeration
319 * @return The length that an entry(type: enum) will take
320 */
321size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
322
323/** @brief Create an attribute value entry(type: enum)
324 * @param[out] entry - Pointer to bios attribute value entry
325 * @param[in] entry_length - Length of attribute value entry
326 * @param[in] attr_handle - This handle points to an attribute in the
327 * BIOS Attribute Vlaue Table.
328 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
329 * Table
330 * @param[in] count - Total number of current values for this enum attribute
331 * @param[in] handle_indexes - Index into the array(provided in the BIOS
332 * Attribute Table) of the possible values of string handles for this attribute.
333 */
334void pldm_bios_table_attr_value_entry_encode_enum(
335 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
336 uint8_t count, uint8_t *handle_indexes);
337
338/** @brief Create an attribute value entry(type: enum) and check the validity of
339 * the parameters
340 * @param[out] entry - Pointer to bios attribute value entry
341 * @param[in] entry_length - Length of attribute value entry
342 * @param[in] attr_handle - This handle points to an attribute in the
343 * BIOS Attribute Vlaue Table.
344 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
345 * Table
346 * @param[in] count - Total number of current values for this enum attribute
347 * @param[in] handle_indexes - Index into the array(provided in the BIOS
348 * Attribute Table) of the possible values of string handles for this attribute.
349 * @return pldm_completion_codes
350 */
351int pldm_bios_table_attr_value_entry_encode_enum_check(
352 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
353 uint8_t count, uint8_t *handle_indexes);
354
355/** @brief Get length that an attribute value entry(type: string) will take
356 * @param[in] string_length - Length of the current string in byte, 0 indicates
357 * that the current string value is not set.
358 * @return The length that an entry(type: string) will take
359 */
360size_t
361pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
362
363/** @brief Create an attribute value entry(type: string)
364 * @param[out] entry - Pointer to bios attribute value entry
365 * @param[in] entry_length - Length of attribute value entry
366 * @param[in] attr_handle - This handle points to an attribute in the
367 * BIOS Attribute Vlaue Table.
368 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
369 * Table
370 * @param[in] string_length - Length of current string in bytes. 0 indicates
371 * that the current string value is not set.
372 * @param[in] string - The current string itsel
373 */
374void pldm_bios_table_attr_value_entry_encode_string(
375 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
376 uint16_t string_length, const char *string);
377/** @brief Create an attribute value entry(type: string) and check the validity
378 * of the parameters
379 * @param[out] entry - Pointer to bios attribute value entry
380 * @param[in] entry_length - Length of attribute value entry
381 * @param[in] attr_handle - This handle points to an attribute in the
382 * BIOS Attribute Vlaue Table.
383 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
384 * Table
385 * @param[in] string_length - Length of current string in bytes. 0 indicates
386 * that the current string value is not set.
387 * @param[in] string - The current string itsel
388 * @return pldm_completion_codes
389 */
390int pldm_bios_table_attr_value_entry_encode_string_check(
391 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
392 uint16_t string_length, const char *string);
393
John Wang02700402019-10-06 16:34:29 +0800394#ifdef __cplusplus
395}
396#endif
397
398#endif