blob: 581ac1dc2f7a6d1c43a7614098b51c0064286730 [file] [log] [blame]
Tom Joseph52552ef2019-06-20 09:50:15 +05301#pragma once
2
John Wang0df0e042020-01-16 10:01:36 +08003#include "bios_table.hpp"
4
Tom Joseph52552ef2019-06-20 09:50:15 +05305#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 Wange96e7e52019-10-05 17:47:30 +080018 * 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 Joseph52552ef2019-06-20 09:50:15 +053021 *
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 Joseph52552ef2019-06-20 09:50:15 +053031namespace bios_parser
32{
33
John Wang0df0e042020-01-16 10:01:36 +080034using namespace pldm::responder::bios;
35using AttrName = std::string;
Tom Joseph52552ef2019-06-20 09:50:15 +053036using Strings = std::vector<std::string>;
Carol Wangdc220c82019-08-26 13:31:31 +080037inline constexpr auto bIOSEnumJson = "enum_attrs.json";
38inline constexpr auto bIOSStrJson = "string_attrs.json";
John Wangecb7d572019-10-17 13:38:53 +080039inline constexpr auto bIOSIntegerJson = "integer_attrs.json";
Tom Joseph52552ef2019-06-20 09:50:15 +053040
John Wange96e7e52019-10-05 17:47:30 +080041/** @brief Get all the preconfigured strings
42 * @return all the preconfigurated strings
Tom Joseph52552ef2019-06-20 09:50:15 +053043 */
John Wange96e7e52019-10-05 17:47:30 +080044const Strings& getStrings();
John Wang0df0e042020-01-16 10:01:36 +080045
John Wange96e7e52019-10-05 17:47:30 +080046/** @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 */
50int setupConfig(const char* dirPath);
Tom Joseph52552ef2019-06-20 09:50:15 +053051
John Wang0df0e042020-01-16 10:01:36 +080052int setAttributeValueOnDbus(const variable_field* attributeData,
53 const BIOSTable& attributeTable,
54 const BIOSStringTable& stringTable);
55
Tom Joseph52552ef2019-06-20 09:50:15 +053056namespace bios_enum
57{
58
Tom Joseph52552ef2019-06-20 09:50:15 +053059using IsReadOnly = bool;
60using PossibleValues = std::vector<std::string>;
61using DefaultValues = std::vector<std::string>;
62using 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 */
71const AttrValuesMap& getValues();
72
73using 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 */
81CurrentValues getAttrValue(const AttrName& attrName);
82
83} // namespace bios_enum
84
Carol Wang612f35b2019-08-26 17:14:26 +080085namespace bios_string
86{
87
Carol Wang612f35b2019-08-26 17:14:26 +080088using IsReadOnly = bool;
89using StrType = uint8_t;
90using MinStrLen = uint16_t;
91using MaxStrLen = uint16_t;
92using DefaultStrLen = uint16_t;
93using DefaultStr = std::string;
94using AttrValuesMap =
95 std::map<AttrName, std::tuple<IsReadOnly, StrType, MinStrLen, MaxStrLen,
96 DefaultStrLen, DefaultStr>>;
Carol Wang612f35b2019-08-26 17:14:26 +080097
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 */
104const AttrValuesMap& getValues();
105
Carol Wangb503f9e2019-09-02 16:34:10 +0800106/** @brief Get the current values for the BIOS Attribute
107 *
108 * @param[in] attrName - BIOS attribute name
109 *
110 * @return BIOS attribute value
111 */
112std::string getAttrValue(const AttrName& attrName);
113
Carol Wang612f35b2019-08-26 17:14:26 +0800114} // namespace bios_string
115
John Wangecb7d572019-10-17 13:38:53 +0800116namespace bios_integer
117{
118
John Wangecb7d572019-10-17 13:38:53 +0800119using IsReadOnly = bool;
120using LowerBound = uint64_t;
121using UpperBound = uint64_t;
122using ScalarIncrement = uint32_t;
123using DefaultValue = uint64_t;
124using AttrValues = std::tuple<IsReadOnly, LowerBound, UpperBound,
125 ScalarIncrement, DefaultValue>;
126
127constexpr auto AttrIsReadOnly = 0;
128constexpr auto AttrLowerBound = 1;
129constexpr auto AttrUpperBound = 2;
130constexpr auto AttrScalarIncrement = 3;
131constexpr auto AttrDefaultValue = 4;
132
133using 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 */
141const 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 */
149uint64_t getAttrValue(const AttrName& attrName);
150
151} // namespace bios_integer
152
Tom Joseph52552ef2019-06-20 09:50:15 +0530153} // namespace bios_parser