Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
John Wang | 0df0e04 | 2020-01-16 10:01:36 +0800 | [diff] [blame] | 3 | #include "bios_table.hpp" |
| 4 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 5 | #include <map> |
| 6 | #include <string> |
| 7 | #include <tuple> |
| 8 | #include <variant> |
| 9 | #include <vector> |
| 10 | |
| 11 | /* |
| 12 | * BIOS Parser API usage: |
| 13 | * |
| 14 | * 1) bios_parser::getStrings gets all the attribute names and the preconfigured |
| 15 | * strings used in representing the values of the attributes. This will be |
| 16 | * used to populate the BIOS String table. |
| 17 | * |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame] | 18 | * 2) bios_parser::setupConfig has to be invoked to setup the lookup data |
| 19 | * structure all the attributes of that type. This API needs to be invoked |
| 20 | * before invoking bios_enum::getValues and bios_enum::getAttrValue. |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 21 | * |
| 22 | * 3) bios_enum::getValues is invoked to populate the BIOS attribute table for |
| 23 | * BIOSEnumeration and BIOSEnumerationReadonly types.(similar API for other |
| 24 | * BIOS attribute types) |
| 25 | * |
| 26 | * 4) bios_enum::getAttrValue will return the current values for the BIOS |
| 27 | * enumeration attribute. If there is no D-Bus mapping for the attribute then |
| 28 | * default value is returned.(similar API for other BIOS attribute types). |
| 29 | * |
| 30 | */ |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 31 | namespace bios_parser |
| 32 | { |
| 33 | |
John Wang | 0df0e04 | 2020-01-16 10:01:36 +0800 | [diff] [blame] | 34 | using namespace pldm::responder::bios; |
| 35 | using AttrName = std::string; |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 36 | using Strings = std::vector<std::string>; |
Carol Wang | dc220c8 | 2019-08-26 13:31:31 +0800 | [diff] [blame] | 37 | inline constexpr auto bIOSEnumJson = "enum_attrs.json"; |
| 38 | inline constexpr auto bIOSStrJson = "string_attrs.json"; |
John Wang | ecb7d57 | 2019-10-17 13:38:53 +0800 | [diff] [blame] | 39 | inline constexpr auto bIOSIntegerJson = "integer_attrs.json"; |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 40 | |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame] | 41 | /** @brief Get all the preconfigured strings |
| 42 | * @return all the preconfigurated strings |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 43 | */ |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame] | 44 | const Strings& getStrings(); |
John Wang | 0df0e04 | 2020-01-16 10:01:36 +0800 | [diff] [blame] | 45 | |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame] | 46 | /** @brief Parse every BIOS Configuration JSON file in the directory path |
| 47 | * @param[in] dirPath - directory path where all the bios configuration JSON |
| 48 | * files exist |
| 49 | */ |
| 50 | int setupConfig(const char* dirPath); |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 51 | |
John Wang | 0df0e04 | 2020-01-16 10:01:36 +0800 | [diff] [blame] | 52 | int setAttributeValueOnDbus(const variable_field* attributeData, |
| 53 | const BIOSTable& attributeTable, |
| 54 | const BIOSStringTable& stringTable); |
| 55 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 56 | namespace bios_enum |
| 57 | { |
| 58 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 59 | using IsReadOnly = bool; |
| 60 | using PossibleValues = std::vector<std::string>; |
| 61 | using DefaultValues = std::vector<std::string>; |
| 62 | using AttrValuesMap = |
| 63 | std::map<AttrName, std::tuple<IsReadOnly, PossibleValues, DefaultValues>>; |
| 64 | |
| 65 | /** @brief Get the possible values and the default values for the |
| 66 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 67 | * |
| 68 | * @return information needed to build the BIOS attribute table specific to |
| 69 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 70 | */ |
| 71 | const AttrValuesMap& getValues(); |
| 72 | |
| 73 | using CurrentValues = std::vector<std::string>; |
| 74 | |
| 75 | /** @brief Get the current values for the BIOS Attribute |
| 76 | * |
| 77 | * @param[in] attrName - BIOS attribute name |
| 78 | * |
| 79 | * @return BIOS attribute value |
| 80 | */ |
| 81 | CurrentValues getAttrValue(const AttrName& attrName); |
| 82 | |
| 83 | } // namespace bios_enum |
| 84 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 85 | namespace bios_string |
| 86 | { |
| 87 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 88 | using IsReadOnly = bool; |
| 89 | using StrType = uint8_t; |
| 90 | using MinStrLen = uint16_t; |
| 91 | using MaxStrLen = uint16_t; |
| 92 | using DefaultStrLen = uint16_t; |
| 93 | using DefaultStr = std::string; |
| 94 | using AttrValuesMap = |
| 95 | std::map<AttrName, std::tuple<IsReadOnly, StrType, MinStrLen, MaxStrLen, |
| 96 | DefaultStrLen, DefaultStr>>; |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 97 | |
| 98 | /** @brief Get the string related values and the default values for the |
| 99 | * BIOSString and BIOSStringReadOnly types |
| 100 | * |
| 101 | * @return information needed to build the BIOS attribute table specific to |
| 102 | * BIOSString and BIOSStringReadOnly types |
| 103 | */ |
| 104 | const AttrValuesMap& getValues(); |
| 105 | |
Carol Wang | b503f9e | 2019-09-02 16:34:10 +0800 | [diff] [blame] | 106 | /** @brief Get the current values for the BIOS Attribute |
| 107 | * |
| 108 | * @param[in] attrName - BIOS attribute name |
| 109 | * |
| 110 | * @return BIOS attribute value |
| 111 | */ |
| 112 | std::string getAttrValue(const AttrName& attrName); |
| 113 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 114 | } // namespace bios_string |
| 115 | |
John Wang | ecb7d57 | 2019-10-17 13:38:53 +0800 | [diff] [blame] | 116 | namespace bios_integer |
| 117 | { |
| 118 | |
John Wang | ecb7d57 | 2019-10-17 13:38:53 +0800 | [diff] [blame] | 119 | using IsReadOnly = bool; |
| 120 | using LowerBound = uint64_t; |
| 121 | using UpperBound = uint64_t; |
| 122 | using ScalarIncrement = uint32_t; |
| 123 | using DefaultValue = uint64_t; |
| 124 | using AttrValues = std::tuple<IsReadOnly, LowerBound, UpperBound, |
| 125 | ScalarIncrement, DefaultValue>; |
| 126 | |
| 127 | constexpr auto AttrIsReadOnly = 0; |
| 128 | constexpr auto AttrLowerBound = 1; |
| 129 | constexpr auto AttrUpperBound = 2; |
| 130 | constexpr auto AttrScalarIncrement = 3; |
| 131 | constexpr auto AttrDefaultValue = 4; |
| 132 | |
| 133 | using AttrValuesMap = std::map<AttrName, AttrValues>; |
| 134 | |
| 135 | /** @brief Get the values of all fields for the |
| 136 | * BIOSInteger and BIOSIntegerReadOnly types |
| 137 | * |
| 138 | * @return information needed to build the BIOS attribute table specific to |
| 139 | * BIOSInteger and BIOSIntegerReadOnly types |
| 140 | */ |
| 141 | const AttrValuesMap& getValues(); |
| 142 | |
| 143 | /** @brief Get the current values for the BIOS Attribute |
| 144 | * |
| 145 | * @param[in] attrName - BIOS attribute name |
| 146 | * |
| 147 | * @return BIOS attribute value |
| 148 | */ |
| 149 | uint64_t getAttrValue(const AttrName& attrName); |
| 150 | |
| 151 | } // namespace bios_integer |
| 152 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 153 | } // namespace bios_parser |