xref: /openbmc/openpower-vpd-parser/vpd-manager/include/types.hpp (revision fa5e4d325ef9cea3c841fe89d202c340f92bd8c6)
1 #pragma once
2 
3 #include <phosphor-logging/elog-errors.hpp>
4 #include <sdbusplus/asio/property.hpp>
5 #include <sdbusplus/server.hpp>
6 #include <xyz/openbmc_project/Common/Device/error.hpp>
7 #include <xyz/openbmc_project/Common/error.hpp>
8 
9 #include <tuple>
10 #include <unordered_map>
11 #include <variant>
12 
13 namespace vpd
14 {
15 namespace types
16 {
17 
18 using BiosProperty = std::tuple<
19     std::string, bool, std::string, std::string, std::string,
20     std::variant<int64_t, std::string>, std::variant<int64_t, std::string>,
21     std::vector<std::tuple<std::string, std::variant<int64_t, std::string>,
22                            std::string>>>;
23 using BiosBaseTable =
24     std::variant<std::monostate, std::map<std::string, BiosProperty>>;
25 using BiosBaseTableType = std::map<std::string, BiosBaseTable>;
26 using BiosAttributeCurrentValue =
27     std::variant<std::monostate, int64_t, std::string>;
28 using BiosAttributePendingValue = std::variant<int64_t, std::string>;
29 using BiosGetAttrRetType = std::tuple<std::string, BiosAttributeCurrentValue,
30                                       BiosAttributePendingValue>;
31 using PendingBIOSAttrItem =
32     std::pair<std::string, std::tuple<std::string, BiosAttributePendingValue>>;
33 using PendingBIOSAttrs = std::vector<PendingBIOSAttrItem>;
34 
35 using BinaryVector = std::vector<uint8_t>;
36 
37 // This covers mostly all the data type supported over Dbus for a property.
38 // clang-format off
39 using DbusVariantType = std::variant<
40     std::vector<std::tuple<std::string, std::string, std::string>>,
41     std::vector<std::string>,
42     std::vector<double>,
43     std::string,
44     int64_t,
45     uint64_t,
46     double,
47     int32_t,
48     uint32_t,
49     int16_t,
50     uint16_t,
51     uint8_t,
52     bool,
53     BinaryVector,
54     std::vector<uint32_t>,
55     std::vector<uint16_t>,
56     sdbusplus::message::object_path,
57     std::tuple<uint64_t, std::vector<std::tuple<std::string, std::string, double, uint64_t>>>,
58     std::vector<std::tuple<std::string, std::string>>,
59     std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>,
60     std::vector<std::tuple<uint32_t, size_t>>,
61     std::vector<std::tuple<sdbusplus::message::object_path, std::string,
62                            std::string, std::string>>,
63     PendingBIOSAttrs
64  >;
65 
66 using MapperGetObject =
67     std::vector<std::pair<std::string, std::vector<std::string>>>;
68 using MapperGetSubTree = std::map<std::string, std::map<std::string, std::vector<std::string>>>;
69 
70 /* A type for holding the innermost map of property::value.*/
71 using IPZKwdValueMap = std::unordered_map<std::string, std::string>;
72 /*IPZ VPD Map of format <Record name, <keyword, value>>*/
73 using IPZVpdMap = std::unordered_map<std::string, IPZKwdValueMap>;
74 
75 /*Value types supported by Keyword VPD*/
76 using KWdVPDValueType = std::variant<BinaryVector,std::string, size_t>;
77 /* This hold map of parsed data of keyword VPD type*/
78 using KeywordVpdMap = std::unordered_map<std::string, KWdVPDValueType>;
79 
80 /**
81  * Both Keyword VPD parser and DDIMM parser stores the
82  * parsed VPD in the same format.
83  * To have better readability, two types are defined for underneath data structure.
84 */
85 using DdimmVpdMap = KeywordVpdMap;
86 
87 /**
88  * Both Keyword VPD parser and ISDIMM parser stores the
89  * parsed SPD in the same format.
90 */
91 using JedecSpdMap = KeywordVpdMap;
92 
93 /**
94  * Type to hold keyword::value map of a VPD.
95  * Variant can be extended to support additional type.
96 */
97 using VPDKWdValueMap = std::variant<IPZKwdValueMap, KeywordVpdMap>;
98 
99 /* Map<Property, Value>*/
100 using PropertyMap = std::map<std::string, DbusVariantType>;
101 /* Map<Interface<Property, Value>>*/
102 using InterfaceMap = std::map<std::string, PropertyMap>;
103 using ObjectMap = std::map<sdbusplus::message::object_path, InterfaceMap>;
104 
105 using KwSize = uint8_t;
106 using RecordId = uint8_t;
107 using RecordSize = uint16_t;
108 using RecordType = uint16_t;
109 using RecordOffset = uint16_t;
110 using RecordLength = uint16_t;
111 using ECCOffset = uint16_t;
112 using ECCLength = uint16_t;
113 using PoundKwSize = uint16_t;
114 
115 using RecordOffsetList = std::vector<uint32_t>;
116 
117 using VPDMapVariant = std::variant<std::monostate, IPZVpdMap, KeywordVpdMap>;
118 
119 using HWVerList = std::vector<std::pair<std::string, std::string>>;
120 /**
121  * Map of <systemIM, pair<Default version, vector<HW version, JSON suffix>>>
122 */
123 using SystemTypeMap =
124     std::unordered_map<std::string, std::pair<std::string, HWVerList>>;
125 
126 using Path = std::string;
127 using Record = std::string;
128 using Keyword = std::string;
129 
130 using IpzData = std::tuple<Record, Keyword, BinaryVector>;
131 using KwData = std::tuple<Keyword, BinaryVector>;
132 using VpdData = std::variant<IpzData, KwData>;
133 
134 using IpzType = std::tuple<Record, Keyword>;
135 using ReadVpdParams = std::variant<IpzType, Keyword>;
136 using WriteVpdParams = std::variant<IpzData, KwData>;
137 
138 using ListOfPaths = std::vector<sdbusplus::message::object_path>;
139 using RecordData = std::tuple<RecordOffset, RecordLength, ECCOffset, ECCLength>;
140 
141 using DbusInvalidArgument =
142     sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
143 using DbusNotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
144 
145 using InvalidArgument = phosphor::logging::xyz::openbmc_project::Common::InvalidArgument;
146 
147 namespace DeviceError = sdbusplus::xyz::openbmc_project::Common::Device::Error;
148 
149 /* PEL Severity enum as defined in [xyz.openbmc_project.Logging.Entry.Level]log.hpp from 'phosphor-logging' repo. */
150 enum SeverityType
151 {
152     Notice,
153     Informational,
154     Debug,
155     Warning,
156     Critical,
157     Emergency,
158     Alert,
159     Error
160 };
161 
162 /* PEL callout priority from 'phosphor-logging' pel_types.hpp. If any change in 'phosphor-logging', it needs update here as well. */
163 enum CalloutPriority
164 {
165     High,
166     Medium,
167     MediumGroupA,
168     MediumGroupB,
169     MediumGroupC,
170     Low
171 };
172 
173 /* The Message property of the event entry for creating PEL, to introduce new message needs to be added in 'phosphor-logging' message_registry.json as well. */
174 enum ErrorType
175 {
176     DefaultValue,
177     InvalidVpdMessage,
178     VpdMismatch,
179     InvalidEeprom,
180     EccCheckFailed,
181     JsonFailure,
182     DbusFailure,
183     InvalidSystem,
184     EssentialFru,
185     GpioError
186 };
187 
188 using InventoryCalloutData = std::tuple<std::string, CalloutPriority>;
189 using DeviceCalloutData = std::tuple<std::string, std::string>;
190 using I2cBusCalloutData = std::tuple<std::string, std::string, std::string>;
191 } // namespace types
192 } // namespace vpd
193