John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 1 | #ifndef BIOS_TABLE_H__ |
| 2 | #define BIOS_TABLE_H__ |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include "bios.h" |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 9 | #include "utils.h" |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 10 | #include <stdbool.h> |
| 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | /** @struct pldm_bios_table_iter |
| 15 | * structure representing bios table iterator |
| 16 | */ |
| 17 | struct 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 | */ |
| 25 | struct pldm_bios_table_iter * |
| 26 | pldm_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 | */ |
| 32 | void 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 | */ |
| 39 | bool 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 | */ |
| 44 | void 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 | */ |
| 50 | const 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 | */ |
| 56 | static inline const struct pldm_bios_attr_table_entry * |
| 57 | pldm_bios_table_iter_attr_entry_value(struct pldm_bios_table_iter *iter) |
| 58 | { |
| 59 | return (const struct pldm_bios_attr_table_entry *) |
| 60 | pldm_bios_table_iter_value(iter); |
| 61 | } |
| 62 | |
John Wang | dd9a628 | 2019-10-11 18:52:46 +0800 | [diff] [blame] | 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 | */ |
| 67 | static inline const struct pldm_bios_string_table_entry * |
| 68 | pldm_bios_table_iter_string_entry_value(struct pldm_bios_table_iter *iter) |
| 69 | { |
| 70 | return (const struct pldm_bios_string_table_entry *) |
| 71 | pldm_bios_table_iter_value(iter); |
| 72 | } |
| 73 | |
John Wang | 49484a1 | 2019-12-02 14:21:53 +0800 | [diff] [blame] | 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 | */ |
| 78 | static inline const struct pldm_bios_attr_val_table_entry * |
| 79 | pldm_bios_table_iter_attr_value_entry_value(struct pldm_bios_table_iter *iter) |
| 80 | { |
| 81 | return (const struct pldm_bios_attr_val_table_entry *) |
| 82 | pldm_bios_table_iter_value(iter); |
| 83 | } |
| 84 | |
John Wang | dd9a628 | 2019-10-11 18:52:46 +0800 | [diff] [blame] | 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 | */ |
| 89 | size_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 | */ |
| 97 | void 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 |
| 102 | * @param[out] entry - Pointer to a buffer to create an entry |
| 103 | * @param[in] entry_length - Length of the buffer to create an entry |
| 104 | * @param[in] str - String itself |
| 105 | * @param[in] str_length - Length of the string |
| 106 | * @return pldm_completion_codes |
| 107 | */ |
| 108 | int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length, |
| 109 | const char *str, |
| 110 | uint16_t str_length); |
| 111 | |
| 112 | /** @brief Get the string handle for the entry |
| 113 | * @param[in] entry - Pointer to a bios string table entry |
| 114 | * @return Handle to identify a string in the bios string table |
| 115 | */ |
| 116 | uint16_t pldm_bios_table_string_entry_decode_handle( |
| 117 | const struct pldm_bios_string_table_entry *entry); |
| 118 | |
| 119 | /** @brief Get the string length for the entry |
| 120 | * @param[in] entry - Pointer to a bios string table entry |
| 121 | * @return Length of string in bytes |
| 122 | */ |
| 123 | uint16_t pldm_bios_table_string_entry_decode_string_length( |
| 124 | const struct pldm_bios_string_table_entry *entry); |
| 125 | |
| 126 | /** @brief Get the string(at most one less than *size* characters) from the |
| 127 | * entry |
| 128 | * @param[in] entry - Pointer to a bios string table entry |
| 129 | * @param[out] buffer - Pointer to a buffer to store the string |
| 130 | * @param[in] size - Size of the buffer to store the string |
| 131 | * @return Length of the string decoded |
| 132 | */ |
| 133 | uint16_t pldm_bios_table_string_entry_decode_string( |
| 134 | const struct pldm_bios_string_table_entry *entry, char *buffer, |
| 135 | size_t size); |
| 136 | |
| 137 | /** @brief Get the string from the entry and check the validity of the |
| 138 | * parameters |
| 139 | * @param[in] entry - Pointer to a bios string table entry |
| 140 | * @param[out] buffer - Pointer to a buffer to store the string |
| 141 | * @param[in] size - Size of the buffer to store the string |
| 142 | * @return pldm_completion_codes |
| 143 | */ |
| 144 | int pldm_bios_table_string_entry_decode_string_check( |
| 145 | const struct pldm_bios_string_table_entry *entry, char *buffer, |
| 146 | size_t size); |
| 147 | |
| 148 | /** @brief Find an entry in bios string table by string |
| 149 | * @param[in] table - The BIOS String Table |
| 150 | * @param[in] length - Length of the BIOS String Table |
| 151 | * @param[in] str - String itself |
| 152 | * @return Pointer to an entry in the bios string table |
| 153 | */ |
| 154 | const struct pldm_bios_string_table_entry * |
| 155 | pldm_bios_table_string_find_by_string(const void *table, size_t length, |
| 156 | const char *str); |
| 157 | /** @brief Find an entry in bios string table by handle |
| 158 | * @param[in] table - The BIOS String Table |
| 159 | * @param[in] length - Length of the BIOS String Table |
| 160 | * @param[in] handle - Handle to identify a string in the bios string table |
| 161 | * @return Pointer to an entry in the bios string table |
| 162 | */ |
| 163 | const struct pldm_bios_string_table_entry * |
| 164 | pldm_bios_table_string_find_by_handle(const void *table, size_t length, |
| 165 | uint16_t handle); |
| 166 | |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 167 | /** @brief Get the attribute handle from the attribute table entry |
| 168 | * @param[in] entry - Pointer to bios attribute table entry |
| 169 | * @return handle to identify the attribute in the attribute table |
| 170 | */ |
| 171 | uint16_t pldm_bios_table_attr_entry_decode_attribute_handle( |
| 172 | const struct pldm_bios_attr_table_entry *entry); |
| 173 | |
John Wang | 50218a6 | 2020-02-12 17:10:28 +0800 | [diff] [blame] | 174 | /** @brief Get the attribute type of the attribute table entry |
| 175 | * @param[in] entry - Pointer to bios attribute table entry |
| 176 | * @return Type of the attribute table entry |
| 177 | */ |
| 178 | uint8_t pldm_bios_table_attr_entry_decode_attribute_type( |
| 179 | const struct pldm_bios_attr_table_entry *entry); |
| 180 | |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 181 | /** @brief Get the attribute name handle from the attribute table entry |
| 182 | * @param[in] entry - Pointer to bios attribute table entry |
| 183 | * @return handle to identify the name of the attribute, this handle points |
| 184 | * to a string in the bios string table. |
| 185 | */ |
| 186 | uint16_t pldm_bios_table_attr_entry_decode_string_handle( |
| 187 | const struct pldm_bios_attr_table_entry *entry); |
| 188 | |
| 189 | /** @brief Find an entry in attribute table by handle |
| 190 | * @param[in] table - The BIOS Attribute Table |
| 191 | * @param[in] length - Length of the BIOS Attribute Table |
| 192 | * @param[in] handle - handle to identify the attribute in the attribute table |
| 193 | * @return Pointer to the entry |
| 194 | */ |
| 195 | const struct pldm_bios_attr_table_entry * |
| 196 | pldm_bios_table_attr_find_by_handle(const void *table, size_t length, |
| 197 | uint16_t handle); |
| 198 | |
John Wang | 45fed20 | 2020-04-01 16:42:26 +0800 | [diff] [blame] | 199 | /** @brief Find an entry in attribute table by string handle |
| 200 | * @param[in] table - The BIOS Attribute Table |
| 201 | * @param[in] length - Length of the BIOS Attribute Table |
| 202 | * @param[in] handle - The string handle |
| 203 | * @return Pointer to the entry |
| 204 | */ |
| 205 | const struct pldm_bios_attr_table_entry * |
| 206 | pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length, |
| 207 | uint16_t handle); |
| 208 | |
John Wang | ccc0455 | 2019-10-14 14:28:25 +0800 | [diff] [blame] | 209 | /** @struct pldm_bios_table_attr_entry_enum_info |
| 210 | * |
| 211 | * An auxiliary structure for passing parameters to @ref |
| 212 | * pldm_bios_table_attr_entry_enum_encode |
| 213 | * |
| 214 | */ |
| 215 | struct pldm_bios_table_attr_entry_enum_info { |
| 216 | uint16_t name_handle; //!< attribute name handle |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 217 | bool read_only; //!< indicate whether the attribute is read-only |
| 218 | uint8_t pv_num; //!< number of possible values |
John Wang | ccc0455 | 2019-10-14 14:28:25 +0800 | [diff] [blame] | 219 | const uint16_t *pv_handle; //!< handles of possible values |
| 220 | uint8_t def_num; //!< nnumber of default values |
| 221 | const uint8_t *def_index; //!< indices of default values. |
| 222 | }; |
| 223 | |
| 224 | /** @brief Get length that an attribute entry(type: enum) will take |
| 225 | * @param[in] pv_num - Number of possible values |
| 226 | * @param[in] def_num - Number of default values |
| 227 | * @return The length that an entry(type: enum) will take |
| 228 | */ |
| 229 | size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num, |
| 230 | uint8_t def_num); |
| 231 | |
| 232 | /** @brief Create an entry of BIOS Attribute Table (type: enum) |
| 233 | * @param[out] entry - Pointer to a buffer to create an entry |
| 234 | * @param[in] entry_length - Length of the buffer to create an entry |
| 235 | * @param[in] info - Pointer to an auxiliary structure @ref |
| 236 | * pldm_bios_table_attr_entry_enum_info |
| 237 | */ |
| 238 | void pldm_bios_table_attr_entry_enum_encode( |
| 239 | void *entry, size_t entry_length, |
| 240 | const struct pldm_bios_table_attr_entry_enum_info *info); |
| 241 | |
| 242 | /** @brief Create an entry of BIOS Attribute Table (type: enum) and check the |
| 243 | * validity of the parameters |
| 244 | * @param[out] entry - Pointer to a buffer to create an entry |
| 245 | * @param[in] entry_length - Length of the buffer to create an entry |
| 246 | * @param[in] info - Pointer to an auxiliary structure @ref |
| 247 | * pldm_bios_table_attr_entry_enum_info |
| 248 | * @return pldm_completion_codes |
| 249 | */ |
| 250 | int pldm_bios_table_attr_entry_enum_encode_check( |
| 251 | void *entry, size_t entry_length, |
| 252 | const struct pldm_bios_table_attr_entry_enum_info *info); |
| 253 | |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 254 | /** @brief Get the total number of possible values for the entry |
| 255 | * @param[in] entry - Pointer to bios attribute table entry |
| 256 | * @return total number of possible values |
| 257 | */ |
| 258 | uint8_t pldm_bios_table_attr_entry_enum_decode_pv_num( |
| 259 | const struct pldm_bios_attr_table_entry *entry); |
| 260 | |
| 261 | /** @brief Get the total number of possible values for the entry and check the |
| 262 | * validity of the parameters |
| 263 | * @param[in] entry - Pointer to bios attribute table entry |
| 264 | * @param[out] pv_num - Pointer to total number of possible values |
| 265 | * @return pldm_completion_codes |
| 266 | */ |
| 267 | int pldm_bios_table_attr_entry_enum_decode_pv_num_check( |
| 268 | const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num); |
| 269 | |
| 270 | /** @brief Get the total number of default values for the entry |
| 271 | * @param[in] entry - Pointer to bios attribute table entry |
| 272 | * @return total number of default values |
| 273 | */ |
| 274 | uint8_t pldm_bios_table_attr_entry_enum_decode_def_num( |
| 275 | const struct pldm_bios_attr_table_entry *entry); |
| 276 | |
| 277 | /** @brief Get the total number of default values for the entry and check the |
| 278 | * validity of the parameters |
| 279 | * @param[in] entry - Pointer to bios attribute table entry |
| 280 | * @param[out] def_num - Pointer to total number of default values |
| 281 | * @return pldm_completion_codes |
| 282 | */ |
| 283 | int pldm_bios_table_attr_entry_enum_decode_def_num_check( |
| 284 | const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num); |
| 285 | |
John Wang | 3ad2175 | 2019-10-06 16:42:21 +0800 | [diff] [blame] | 286 | /** @brief Get possible values string handles |
| 287 | * @param[in] entry - Pointer to bios attribute table entry |
| 288 | * @param[out] pv_hdls - Pointer to a buffer to stroe |
| 289 | * PossibleValuesStringHandles |
| 290 | * @param[in] pv_num - Number of PossibleValuesStringHandles expected |
| 291 | * @return pldm_completion_codes |
| 292 | */ |
| 293 | uint8_t pldm_bios_table_attr_entry_enum_decode_pv_hdls( |
| 294 | const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls, |
| 295 | uint8_t pv_num); |
| 296 | |
| 297 | /** @brief Get possible values string handles and check the validity of the |
| 298 | * parameters |
| 299 | * @param[in] entry - Pointer to bios attribute table entry |
| 300 | * @param[out] pv_hdls - Pointer to a buffer to stroe |
| 301 | * PossibleValuesStringHandles |
| 302 | * @param[in] pv_num - Number of PossibleValuesStringHandles the buffer can |
| 303 | * stroe |
| 304 | * @return Number of PossibleValuesStringHandles decoded |
| 305 | */ |
| 306 | int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check( |
| 307 | const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls, |
| 308 | uint8_t pv_num); |
| 309 | |
John Wang | 50218a6 | 2020-02-12 17:10:28 +0800 | [diff] [blame] | 310 | /** @brief Get Indices of default values |
| 311 | * @param[in] entry - Pointer to bios attribute table entry |
| 312 | * @param[out] def_indices - Pointer to a buffer to store |
| 313 | * default value indices |
| 314 | * @param[in] def_num - Number of DefaultValues the buffer can |
| 315 | * store |
| 316 | * @return Number of default values decoded |
| 317 | */ |
| 318 | uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices( |
| 319 | const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices, |
| 320 | uint8_t def_num); |
| 321 | |
John Wang | ccc0455 | 2019-10-14 14:28:25 +0800 | [diff] [blame] | 322 | /** @struct pldm_bios_table_attr_entry_string_info |
| 323 | * |
| 324 | * An auxiliary structure for passing parameters to @ref |
| 325 | * pldm_bios_table_attr_entry_string_encode |
| 326 | * |
| 327 | */ |
| 328 | struct pldm_bios_table_attr_entry_string_info { |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 329 | uint16_t name_handle; //!< attribute name handle |
John Wang | ccc0455 | 2019-10-14 14:28:25 +0800 | [diff] [blame] | 330 | bool read_only; //!< indicate whether the attribute is read-only |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 331 | uint8_t string_type; //!< The type of the string |
| 332 | uint16_t min_length; //!< The minimum length of the string in bytes |
| 333 | uint16_t max_length; //!< The maximum length of the string in bytes |
| 334 | uint16_t def_length; //!< The length of the defaut string in bytes |
John Wang | ccc0455 | 2019-10-14 14:28:25 +0800 | [diff] [blame] | 335 | const char *def_string; //!< The default string itself |
| 336 | }; |
| 337 | |
John Wang | 827c5de | 2019-11-07 18:27:27 +0800 | [diff] [blame] | 338 | /** @brief Check fields in @ref pldm_bios_table_attr_entry_string_info |
| 339 | * @param[in] info - Pointer to the pldm_bios_table_attr_entry_string_info |
| 340 | * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated |
| 341 | * memory |
| 342 | * @return pldm_completion_codes |
| 343 | */ |
| 344 | int pldm_bios_table_attr_entry_string_info_check( |
| 345 | const struct pldm_bios_table_attr_entry_string_info *info, |
| 346 | const char **errmsg); |
| 347 | |
John Wang | ccc0455 | 2019-10-14 14:28:25 +0800 | [diff] [blame] | 348 | /** @brief Get length that an attribute entry(type: string) will take |
| 349 | * @param[in] def_str_len - Length of default string |
| 350 | * @return The length that an entry(type: string) will take |
| 351 | */ |
| 352 | size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len); |
| 353 | |
| 354 | /** @brief Create an entry of BIOS Attribute Table (type: string) |
| 355 | * @param[out] entry - Pointer to a buffer to create an entry |
| 356 | * @param[in] entry_length - Length of the buffer to create an entry |
| 357 | * @param[in] info - Pointer to an auxiliary structure @ref |
| 358 | * pldm_bios_table_attr_entry_string_info |
| 359 | */ |
| 360 | void pldm_bios_table_attr_entry_string_encode( |
| 361 | void *entry, size_t entry_length, |
| 362 | const struct pldm_bios_table_attr_entry_string_info *info); |
| 363 | |
| 364 | /** @brief Create an entry of BIOS Attribute Table (type: string) and check the |
| 365 | * validity of the parameters |
| 366 | * @param[out] entry - Pointer to a buffer to create an entry |
| 367 | * @param[in] entry_length - Length of the buffer to create an entry |
| 368 | * @param[in] info - Pointer to an auxiliary structure @ref |
| 369 | * pldm_bios_table_attr_entry_string_info |
| 370 | * @return pldm_completion_codes |
| 371 | */ |
| 372 | int pldm_bios_table_attr_entry_string_encode_check( |
| 373 | void *entry, size_t entry_length, |
| 374 | const struct pldm_bios_table_attr_entry_string_info *info); |
| 375 | |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 376 | /** @brief Get the length of default string in bytes for the entry |
| 377 | * @param[in] entry - Pointer to bios attribute table entry |
| 378 | * @return length of default string in bytes |
| 379 | */ |
| 380 | uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length( |
| 381 | const struct pldm_bios_attr_table_entry *entry); |
| 382 | |
| 383 | /** @brief Get the length of default string in bytes for the entry and check the |
| 384 | * validity of the parameters |
| 385 | * @param[in] entry - Pointer to bios attribute table entry |
| 386 | * @param[out] def_string_length Pointer to length of default string in bytes |
| 387 | * @return pldm_completion_codes |
| 388 | */ |
| 389 | int pldm_bios_table_attr_entry_string_decode_def_string_length_check( |
| 390 | const struct pldm_bios_attr_table_entry *entry, |
| 391 | uint16_t *def_string_length); |
| 392 | |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 393 | /** @brief Get the type of string of bios attribute table entry |
| 394 | * @param[in] entry - Pointer to bios attribute table entry |
| 395 | * @return Type of the string |
| 396 | */ |
| 397 | uint8_t pldm_bios_table_attr_entry_string_decode_string_type( |
| 398 | const struct pldm_bios_attr_table_entry *entry); |
| 399 | |
John Wang | 50218a6 | 2020-02-12 17:10:28 +0800 | [diff] [blame] | 400 | /** @brief Get maximum length of the string from a bios attribute table entry in |
| 401 | * bytes |
| 402 | * @param[in] entry - Pointer to a bios attribute table entry |
| 403 | * @return Maximum length of the string |
| 404 | */ |
| 405 | uint16_t pldm_bios_table_attr_entry_string_decode_max_length( |
| 406 | const struct pldm_bios_attr_table_entry *entry); |
| 407 | |
| 408 | /** @brief Get minimum length of the string from a bios attribute table entry in |
| 409 | * bytes |
| 410 | * @param[in] entry - Pointer to a bios attribute table entry |
| 411 | * @return Minimum length of the string |
| 412 | */ |
| 413 | uint16_t pldm_bios_table_attr_entry_string_decode_min_length( |
| 414 | const struct pldm_bios_attr_table_entry *entry); |
| 415 | |
| 416 | /** @brief Get the default string from a bios attribute table entry |
| 417 | * @param[out] buffer - Pointer to a buffer to store the string |
| 418 | * @param[in] size - Size of the buffer to store the string |
| 419 | * @return Length of the string decoded |
| 420 | */ |
| 421 | uint16_t pldm_bios_table_attr_entry_string_decode_def_string( |
| 422 | const struct pldm_bios_attr_table_entry *entry, char *buffer, size_t size); |
| 423 | |
John Wang | ca23082 | 2019-10-16 11:39:27 +0800 | [diff] [blame] | 424 | /** @struct pldm_bios_table_attr_entry_integer_info |
| 425 | * |
| 426 | * An auxiliary structure for passing parameters to @ref |
| 427 | * pldm_bios_table_attr_entry_integer_encode |
| 428 | * |
| 429 | */ |
| 430 | struct pldm_bios_table_attr_entry_integer_info { |
| 431 | uint16_t name_handle; //!< attribute name handle |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 432 | bool read_only; //!< indicate whether the attribute is read-only |
John Wang | ca23082 | 2019-10-16 11:39:27 +0800 | [diff] [blame] | 433 | uint64_t lower_bound; //!< The lower bound on the integer value |
| 434 | uint64_t upper_bound; //!< The upper bound on the integer value |
| 435 | uint32_t scalar_increment; //!< The scalar value that is used for the |
| 436 | //!< increments to this integer |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 437 | uint64_t default_value; //!< The default value of the integer |
John Wang | ca23082 | 2019-10-16 11:39:27 +0800 | [diff] [blame] | 438 | }; |
| 439 | |
John Wang | 827c5de | 2019-11-07 18:27:27 +0800 | [diff] [blame] | 440 | /** @brief Check fields in @ref pldm_bios_table_attr_entry_integer_info |
| 441 | * @param[in] info - Pointer to the pldm_bios_table_attr_entry_integer_info |
| 442 | * @param[out] errmsg - Pointer to an errmsg stored in the statically allocated |
| 443 | * memory |
| 444 | * @return pldm_completion_codes |
| 445 | */ |
| 446 | int pldm_bios_table_attr_entry_integer_info_check( |
| 447 | const struct pldm_bios_table_attr_entry_integer_info *info, |
| 448 | const char **errmsg); |
| 449 | |
John Wang | ca23082 | 2019-10-16 11:39:27 +0800 | [diff] [blame] | 450 | /** @brief Get length that an attribute entry(type: integer) will take |
| 451 | * @return The length that an entry(type: integer) will take |
| 452 | */ |
| 453 | size_t pldm_bios_table_attr_entry_integer_encode_length(); |
| 454 | |
| 455 | /** @brief Create an entry of BIOS Attribute Table (type: integer) |
| 456 | * @param[out] entry - Pointer to a buffer to create an entry |
| 457 | * @param[in] entry_length - Length of the buffer to create an entry |
| 458 | * @param[in] info - Pointer to an auxiliary structure @ref |
| 459 | * pldm_bios_table_attr_entry_integer_info |
| 460 | */ |
| 461 | void pldm_bios_table_attr_entry_integer_encode( |
| 462 | void *entry, size_t entry_length, |
| 463 | const struct pldm_bios_table_attr_entry_integer_info *info); |
| 464 | |
| 465 | /** @brief Create an entry of BIOS Attribute Table (type: integer) and check the |
| 466 | * validity of the parameters |
| 467 | * @param[out] entry - Pointer to a buffer to create an entry |
| 468 | * @param[in] entry_length - Length of the buffer to create an entry |
| 469 | * @param[in] info - Pointer to an auxiliary structure @ref |
| 470 | * pldm_bios_table_attr_entry_integer_info |
| 471 | * @return pldm_completion_codes |
| 472 | */ |
| 473 | int pldm_bios_table_attr_entry_integer_encode_check( |
| 474 | void *entry, size_t entry_length, |
| 475 | const struct pldm_bios_table_attr_entry_integer_info *info); |
| 476 | |
John Wang | 50218a6 | 2020-02-12 17:10:28 +0800 | [diff] [blame] | 477 | /** @brief Decode the specific fields(integer) of attribute table entry |
| 478 | * @param[in] entry - Pointer to an entry of attribute table |
| 479 | * @param[out] lower - The lower bound on the integer value |
| 480 | * @param[out] upper - The upper bound on the integer value |
| 481 | * @param[out] scalar - The scalar value that is used for the increments to |
| 482 | * this integer |
| 483 | * @param[out] def - The default value of the integer |
| 484 | */ |
| 485 | void pldm_bios_table_attr_entry_integer_decode( |
| 486 | const struct pldm_bios_attr_table_entry *entry, uint64_t *lower, |
| 487 | uint64_t *upper, uint32_t *scalar, uint64_t *def); |
| 488 | |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 489 | /** @brief Get the attribute handle from the attribute value table entry |
| 490 | * @param[in] entry - Pointer to bios attribute value table entry |
| 491 | * @return handle to identify the attribute in the attribute value table |
| 492 | */ |
| 493 | uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle( |
| 494 | const struct pldm_bios_attr_val_table_entry *entry); |
| 495 | |
| 496 | /** @brief Get the attribute type from the attribute value table entry |
| 497 | * @param[in] entry - Pointer to bios attribute value table entry |
| 498 | * @return Type of the attribute value entry |
| 499 | */ |
| 500 | uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type( |
| 501 | const struct pldm_bios_attr_val_table_entry *entry); |
| 502 | |
John Wang | 3ad2175 | 2019-10-06 16:42:21 +0800 | [diff] [blame] | 503 | /** @brief Get length that an attribute value entry(type: enum) will take |
| 504 | * @param[in] count - Total number of current values for this enumeration |
| 505 | * @return The length that an entry(type: enum) will take |
| 506 | */ |
| 507 | size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count); |
| 508 | |
| 509 | /** @brief Create an attribute value entry(type: enum) |
| 510 | * @param[out] entry - Pointer to bios attribute value entry |
| 511 | * @param[in] entry_length - Length of attribute value entry |
| 512 | * @param[in] attr_handle - This handle points to an attribute in the |
| 513 | * BIOS Attribute Vlaue Table. |
| 514 | * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value |
| 515 | * Table |
| 516 | * @param[in] count - Total number of current values for this enum attribute |
| 517 | * @param[in] handle_indexes - Index into the array(provided in the BIOS |
| 518 | * Attribute Table) of the possible values of string handles for this attribute. |
| 519 | */ |
| 520 | void pldm_bios_table_attr_value_entry_encode_enum( |
| 521 | void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type, |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 522 | uint8_t count, const uint8_t *handle_indexes); |
John Wang | 3ad2175 | 2019-10-06 16:42:21 +0800 | [diff] [blame] | 523 | |
John Wang | 49484a1 | 2019-12-02 14:21:53 +0800 | [diff] [blame] | 524 | /** @brief Get number of current values for the enum entry |
| 525 | * @param[in] entry - Pointer to bios attribute value table entry |
| 526 | * @return Total number of current values for this enumeration |
| 527 | */ |
| 528 | uint8_t pldm_bios_table_attr_value_entry_enum_decode_number( |
| 529 | const struct pldm_bios_attr_val_table_entry *entry); |
| 530 | |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 531 | /** @brief Get CurrentValueStringHandleIndex |
| 532 | * @param[in] entry - Pointer to bios attribute value table entry |
| 533 | * @param[in, out] handles - Pointer to a buffer to store |
| 534 | * CurrentValueStringHandleIndex |
| 535 | * @param[in] number - Number of PossibleValuesStringHandles expected |
| 536 | * @return Number of CurrentValueStringHandleIndex decoded. |
| 537 | */ |
| 538 | uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles( |
| 539 | const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles, |
| 540 | uint8_t number); |
| 541 | |
John Wang | 3ad2175 | 2019-10-06 16:42:21 +0800 | [diff] [blame] | 542 | /** @brief Create an attribute value entry(type: enum) and check the validity of |
| 543 | * the parameters |
| 544 | * @param[out] entry - Pointer to bios attribute value entry |
| 545 | * @param[in] entry_length - Length of attribute value entry |
| 546 | * @param[in] attr_handle - This handle points to an attribute in the |
| 547 | * BIOS Attribute Vlaue Table. |
| 548 | * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value |
| 549 | * Table |
| 550 | * @param[in] count - Total number of current values for this enum attribute |
| 551 | * @param[in] handle_indexes - Index into the array(provided in the BIOS |
| 552 | * Attribute Table) of the possible values of string handles for this attribute. |
| 553 | * @return pldm_completion_codes |
| 554 | */ |
| 555 | int pldm_bios_table_attr_value_entry_encode_enum_check( |
| 556 | void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type, |
| 557 | uint8_t count, uint8_t *handle_indexes); |
| 558 | |
| 559 | /** @brief Get length that an attribute value entry(type: string) will take |
| 560 | * @param[in] string_length - Length of the current string in byte, 0 indicates |
| 561 | * that the current string value is not set. |
| 562 | * @return The length that an entry(type: string) will take |
| 563 | */ |
| 564 | size_t |
| 565 | pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length); |
| 566 | |
| 567 | /** @brief Create an attribute value entry(type: string) |
| 568 | * @param[out] entry - Pointer to bios attribute value entry |
| 569 | * @param[in] entry_length - Length of attribute value entry |
| 570 | * @param[in] attr_handle - This handle points to an attribute in the |
| 571 | * BIOS Attribute Vlaue Table. |
| 572 | * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value |
| 573 | * Table |
| 574 | * @param[in] string_length - Length of current string in bytes. 0 indicates |
| 575 | * that the current string value is not set. |
| 576 | * @param[in] string - The current string itsel |
| 577 | */ |
| 578 | void pldm_bios_table_attr_value_entry_encode_string( |
| 579 | void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type, |
| 580 | uint16_t string_length, const char *string); |
John Wang | 49484a1 | 2019-12-02 14:21:53 +0800 | [diff] [blame] | 581 | |
| 582 | /** @brief Get length of the current string in bytes |
| 583 | * @param [in] entry - Pointer to bios attribute value table entry |
| 584 | * @return The length of the current string in bytes |
| 585 | */ |
| 586 | uint16_t pldm_bios_table_attr_value_entry_string_decode_length( |
| 587 | const struct pldm_bios_attr_val_table_entry *entry); |
| 588 | |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 589 | /** @brief Get Current String Itself |
| 590 | * @param[in] entry - Pointer to bios attribute value table entry |
| 591 | * @param[in, out] current_string - Struct variable_field, contains a pointer |
| 592 | * to the CurrentString field in the buffer of |
| 593 | * \p entry, \p entry must be valid |
| 594 | * when \p current_string is used. |
| 595 | */ |
| 596 | void pldm_bios_table_attr_value_entry_string_decode_string( |
| 597 | const struct pldm_bios_attr_val_table_entry *entry, |
| 598 | struct variable_field *current_string); |
| 599 | |
John Wang | 3ad2175 | 2019-10-06 16:42:21 +0800 | [diff] [blame] | 600 | /** @brief Create an attribute value entry(type: string) and check the validity |
| 601 | * of the parameters |
| 602 | * @param[out] entry - Pointer to bios attribute value entry |
| 603 | * @param[in] entry_length - Length of attribute value entry |
| 604 | * @param[in] attr_handle - This handle points to an attribute in the |
| 605 | * BIOS Attribute Vlaue Table. |
| 606 | * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value |
| 607 | * Table |
| 608 | * @param[in] string_length - Length of current string in bytes. 0 indicates |
| 609 | * that the current string value is not set. |
| 610 | * @param[in] string - The current string itsel |
| 611 | * @return pldm_completion_codes |
| 612 | */ |
| 613 | int pldm_bios_table_attr_value_entry_encode_string_check( |
| 614 | void *entry, size_t entry_length, uint16_t attr_handle, uint8_t attr_type, |
| 615 | uint16_t string_length, const char *string); |
| 616 | |
John Wang | ca23082 | 2019-10-16 11:39:27 +0800 | [diff] [blame] | 617 | /** @brief Get length that an attribute value entry(type: integer) will take |
| 618 | * @return The length that an entry(type: integer) will take |
| 619 | */ |
| 620 | size_t pldm_bios_table_attr_value_entry_encode_integer_length(); |
| 621 | |
| 622 | /** @brief Create an attribute value entry(type: integer) |
| 623 | * @param[out] entry - Pointer to bios attribute value entry |
| 624 | * @param[in] entry_length - Length of attribute value entry |
| 625 | * @param[in] attr_handle - This handle points to an attribute in the |
| 626 | * BIOS Attribute Vlaue Table. |
| 627 | * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value |
| 628 | * Table |
| 629 | * @param[in] cv - Current Value |
| 630 | */ |
| 631 | void pldm_bios_table_attr_value_entry_encode_integer(void *entry, |
| 632 | size_t entry_length, |
| 633 | uint16_t attr_handle, |
| 634 | uint8_t attr_type, |
| 635 | uint64_t cv); |
| 636 | |
John Wang | b0da7a0 | 2020-01-07 16:55:00 +0800 | [diff] [blame] | 637 | /** @brief Get current values for the integer entry |
| 638 | * @param[in] entry - Pointer to bios attribute value table entry |
| 639 | * @return Current Value |
| 640 | */ |
| 641 | uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv( |
| 642 | const struct pldm_bios_attr_val_table_entry *entry); |
| 643 | |
John Wang | ca23082 | 2019-10-16 11:39:27 +0800 | [diff] [blame] | 644 | /** @brief Create an attribute value entry(type: integer) and check the validity |
| 645 | * of the parameters |
| 646 | * @param[out] entry - Pointer to bios attribute value entry |
| 647 | * @param[in] entry_length - Length of attribute value entry |
| 648 | * @param[in] attr_handle - This handle points to an attribute in the |
| 649 | * BIOS Attribute Vlaue Table. |
| 650 | * @param[in] attr_type - Type of this attribute in the BIOS Attribute Value |
| 651 | * Table |
| 652 | * @param[in] cv - Current Value |
| 653 | * @return pldm_completion_codes |
| 654 | */ |
| 655 | int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry, |
| 656 | size_t entry_length, |
| 657 | uint16_t attr_handle, |
| 658 | uint8_t attr_type, |
| 659 | uint64_t cv); |
John Wang | 79c37f1 | 2019-10-31 15:46:31 +0800 | [diff] [blame] | 660 | |
John Wang | 3342adb | 2019-11-29 16:03:58 +0800 | [diff] [blame] | 661 | /** @brief Get the handle from the attribute value entry |
| 662 | * @param[in] entry - Pointer to bios attribute value entry |
| 663 | * @return handle to identify the attribute in the attribute value table |
| 664 | */ |
| 665 | uint16_t pldm_bios_table_attr_value_entry_decode_handle( |
| 666 | const struct pldm_bios_attr_val_table_entry *entry); |
| 667 | |
John Wang | 8e877e0 | 2020-02-03 16:06:55 +0800 | [diff] [blame] | 668 | /** @brief Get the length of the attribute value entry |
John Wang | 3342adb | 2019-11-29 16:03:58 +0800 | [diff] [blame] | 669 | * @param[in] entry - Pointer to bios attribute value entry |
John Wang | 8e877e0 | 2020-02-03 16:06:55 +0800 | [diff] [blame] | 670 | * @return Length of the entry |
John Wang | 3342adb | 2019-11-29 16:03:58 +0800 | [diff] [blame] | 671 | */ |
John Wang | 8e877e0 | 2020-02-03 16:06:55 +0800 | [diff] [blame] | 672 | size_t pldm_bios_table_attr_value_entry_length( |
John Wang | 3342adb | 2019-11-29 16:03:58 +0800 | [diff] [blame] | 673 | const struct pldm_bios_attr_val_table_entry *entry); |
| 674 | |
| 675 | /** @brief Find an entry in attribute value table by handle |
| 676 | * @param[in] table - The BIOS Attribute Value Table |
| 677 | * @param[in] length - Length of the BIOS Attribute Value Table |
| 678 | * @param[in] handle - handle to identify the attribute in the attribute value |
| 679 | * table |
| 680 | * @return Pointer to the entry |
| 681 | */ |
| 682 | const struct pldm_bios_attr_val_table_entry * |
| 683 | pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length, |
| 684 | uint16_t handle); |
| 685 | |
John Wang | 79c37f1 | 2019-10-31 15:46:31 +0800 | [diff] [blame] | 686 | /** @brief Get the size of pad and checksum |
| 687 | * @param[in] size_without_pad - Table size without pad |
| 688 | * @return The size of pad and checksum |
| 689 | */ |
| 690 | size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad); |
| 691 | |
| 692 | /** @brief Append pad and checksum at the end of the table |
| 693 | * @param[in,out] table - Pointer to a buffer of a bios table |
| 694 | * @param[in] size - Size of the buffer of a bios table |
| 695 | * @param[in] size_without_pad - Table size without pad and checksum |
John Wang | 871c927 | 2019-12-09 18:02:15 +0800 | [diff] [blame] | 696 | * @return Total size of the table |
John Wang | 79c37f1 | 2019-10-31 15:46:31 +0800 | [diff] [blame] | 697 | */ |
John Wang | 871c927 | 2019-12-09 18:02:15 +0800 | [diff] [blame] | 698 | size_t pldm_bios_table_append_pad_checksum(void *table, size_t size, |
| 699 | size_t size_without_pad); |
| 700 | |
| 701 | /** @brief Build a new table and update an entry |
| 702 | * @param[in] src_table - Pointer to the source table |
| 703 | * @param[in] src_length - Size of the source table |
| 704 | * @param[out] dest_table - Pointer to the buffer of destination table |
| 705 | * @param[in,out] dest_length - Buffer size of the destination table as input |
| 706 | * parameter and will be assigned the length of |
| 707 | * the new table, if the function returns |
| 708 | * PLDM_SUCCESS |
| 709 | * @param[in] entry - Pointer to an entry |
| 710 | * @param[in] entry_length - Size of the entry |
| 711 | * @return pldm_completion_codes |
| 712 | */ |
| 713 | int pldm_bios_table_attr_value_copy_and_update( |
| 714 | const void *src_table, size_t src_length, void *dest_table, |
| 715 | size_t *dest_length, const void *entry, size_t entry_length); |
John Wang | 79c37f1 | 2019-10-31 15:46:31 +0800 | [diff] [blame] | 716 | |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 717 | #ifdef __cplusplus |
| 718 | } |
| 719 | #endif |
| 720 | |
| 721 | #endif |