blob: 0b20109f7704c73a4e4da6f5760d4162828b7c4b [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
62/** @brief Get the total number of possible values for the entry
63 * @param[in] entry - Pointer to bios attribute table entry
64 * @return total number of possible values
65 */
66uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num(
67 const struct pldm_bios_attr_table_entry *entry);
68
69/** @brief Get the total number of possible values for the entry and check the
70 * validity of the parameters
71 * @param[in] entry - Pointer to bios attribute table entry
72 * @param[out] pv_num - Pointer to total number of possible values
73 * @return pldm_completion_codes
74 */
75int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
76 const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num);
77
78/** @brief Get the total number of default values for the entry
79 * @param[in] entry - Pointer to bios attribute table entry
80 * @return total number of default values
81 */
82uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
83 const struct pldm_bios_attr_table_entry *entry);
84
85/** @brief Get the total number of default values for the entry and check the
86 * validity of the parameters
87 * @param[in] entry - Pointer to bios attribute table entry
88 * @param[out] def_num - Pointer to total number of default values
89 * @return pldm_completion_codes
90 */
91int pldm_bios_table_attr_entry_enum_decode_def_num_check(
92 const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num);
93
John Wang3ad21752019-10-06 16:42:21 +080094/** @brief Get possible values string handles
95 * @param[in] entry - Pointer to bios attribute table entry
96 * @param[out] pv_hdls - Pointer to a buffer to stroe
97 * PossibleValuesStringHandles
98 * @param[in] pv_num - Number of PossibleValuesStringHandles expected
99 * @return pldm_completion_codes
100 */
101uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls(
102 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
103 uint8_t pv_num);
104
105/** @brief Get possible values string handles and check the validity of the
106 * parameters
107 * @param[in] entry - Pointer to bios attribute table entry
108 * @param[out] pv_hdls - Pointer to a buffer to stroe
109 * PossibleValuesStringHandles
110 * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can
111 * stroe
112 * @return Number of PossibleValuesStringHandles decoded
113 */
114int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
115 const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
116 uint8_t pv_num);
117
John Wang02700402019-10-06 16:34:29 +0800118/** @brief Get the length of default string in bytes for the entry
119 * @param[in] entry - Pointer to bios attribute table entry
120 * @return length of default string in bytes
121 */
122uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
123 const struct pldm_bios_attr_table_entry *entry);
124
125/** @brief Get the length of default string in bytes for the entry and check the
126 * validity of the parameters
127 * @param[in] entry - Pointer to bios attribute table entry
128 * @param[out] def_string_length Pointer to length of default string in bytes
129 * @return pldm_completion_codes
130 */
131int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
132 const struct pldm_bios_attr_table_entry *entry,
133 uint16_t *def_string_length);
134
John Wang3ad21752019-10-06 16:42:21 +0800135/** @brief Get length that an attribute value entry(type: enum) will take
136 * @param[in] count - Total number of current values for this enumeration
137 * @return The length that an entry(type: enum) will take
138 */
139size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count);
140
141/** @brief Create an attribute value entry(type: enum)
142 * @param[out] entry - Pointer to bios attribute value entry
143 * @param[in] entry_length - Length of attribute value entry
144 * @param[in] attr_handle - This handle points to an attribute in the
145 * BIOS Attribute Vlaue Table.
146 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
147 * Table
148 * @param[in] count - Total number of current values for this enum attribute
149 * @param[in] handle_indexes - Index into the array(provided in the BIOS
150 * Attribute Table) of the possible values of string handles for this attribute.
151 */
152void pldm_bios_table_attr_value_entry_encode_enum(
153 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
154 uint8_t count, uint8_t *handle_indexes);
155
156/** @brief Create an attribute value entry(type: enum) and check the validity of
157 * the parameters
158 * @param[out] entry - Pointer to bios attribute value entry
159 * @param[in] entry_length - Length of attribute value entry
160 * @param[in] attr_handle - This handle points to an attribute in the
161 * BIOS Attribute Vlaue Table.
162 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
163 * Table
164 * @param[in] count - Total number of current values for this enum attribute
165 * @param[in] handle_indexes - Index into the array(provided in the BIOS
166 * Attribute Table) of the possible values of string handles for this attribute.
167 * @return pldm_completion_codes
168 */
169int pldm_bios_table_attr_value_entry_encode_enum_check(
170 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
171 uint8_t count, uint8_t *handle_indexes);
172
173/** @brief Get length that an attribute value entry(type: string) will take
174 * @param[in] string_length - Length of the current string in byte, 0 indicates
175 * that the current string value is not set.
176 * @return The length that an entry(type: string) will take
177 */
178size_t
179pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length);
180
181/** @brief Create an attribute value entry(type: string)
182 * @param[out] entry - Pointer to bios attribute value entry
183 * @param[in] entry_length - Length of attribute value entry
184 * @param[in] attr_handle - This handle points to an attribute in the
185 * BIOS Attribute Vlaue Table.
186 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
187 * Table
188 * @param[in] string_length - Length of current string in bytes. 0 indicates
189 * that the current string value is not set.
190 * @param[in] string - The current string itsel
191 */
192void pldm_bios_table_attr_value_entry_encode_string(
193 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
194 uint16_t string_length, const char *string);
195/** @brief Create an attribute value entry(type: string) and check the validity
196 * of the parameters
197 * @param[out] entry - Pointer to bios attribute value entry
198 * @param[in] entry_length - Length of attribute value entry
199 * @param[in] attr_handle - This handle points to an attribute in the
200 * BIOS Attribute Vlaue Table.
201 * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value
202 * Table
203 * @param[in] string_length - Length of current string in bytes. 0 indicates
204 * that the current string value is not set.
205 * @param[in] string - The current string itsel
206 * @return pldm_completion_codes
207 */
208int pldm_bios_table_attr_value_entry_encode_string_check(
209 void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type,
210 uint16_t string_length, const char *string);
211
John Wang02700402019-10-06 16:34:29 +0800212#ifdef __cplusplus
213}
214#endif
215
216#endif