xref: /openbmc/openpower-vpd-parser/vpd-manager/include/types.hpp (revision b6fc6de8c81727629a0154f77c3cb2f10dc44d61)
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/Progress/common.hpp>
8 #include <xyz/openbmc_project/Common/error.hpp>
9 
10 #include <tuple>
11 #include <unordered_map>
12 #include <variant>
13 
14 namespace vpd
15 {
16 namespace types
17 {
18 
19 using BiosProperty = std::tuple<
20     std::string, bool, std::string, std::string, std::string,
21     std::variant<int64_t, std::string>, std::variant<int64_t, std::string>,
22     std::vector<std::tuple<std::string, std::variant<int64_t, std::string>,
23                            std::string>>>;
24 using BiosBaseTable =
25     std::variant<std::monostate, std::map<std::string, BiosProperty>>;
26 using BiosBaseTableType = std::map<std::string, BiosBaseTable>;
27 using BiosAttributeCurrentValue =
28     std::variant<std::monostate, int64_t, std::string>;
29 using BiosAttributePendingValue = std::variant<int64_t, std::string>;
30 using BiosGetAttrRetType = std::tuple<std::string, BiosAttributeCurrentValue,
31                                       BiosAttributePendingValue>;
32 using PendingBIOSAttrItem =
33     std::pair<std::string, std::tuple<std::string, BiosAttributePendingValue>>;
34 using PendingBIOSAttrs = std::vector<PendingBIOSAttrItem>;
35 
36 using BinaryVector = std::vector<uint8_t>;
37 
38 // This covers mostly all the data type supported over Dbus for a property.
39 // clang-format off
40 using DbusVariantType = std::variant<
41     std::vector<std::tuple<std::string, std::string, std::string>>,
42     std::vector<std::string>,
43     std::vector<double>,
44     std::string,
45     int64_t,
46     uint64_t,
47     double,
48     int32_t,
49     uint32_t,
50     int16_t,
51     uint16_t,
52     uint8_t,
53     bool,
54     BinaryVector,
55     std::vector<uint32_t>,
56     std::vector<uint16_t>,
57     sdbusplus::message::object_path,
58     std::tuple<uint64_t, std::vector<std::tuple<std::string, std::string, double, uint64_t>>>,
59     std::vector<std::tuple<std::string, std::string>>,
60     std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>,
61     std::vector<std::tuple<uint32_t, size_t>>,
62     std::vector<std::tuple<sdbusplus::message::object_path, std::string,
63                            std::string, std::string>>,
64     PendingBIOSAttrs
65  >;
66 
67 using MapperGetObject =
68     std::vector<std::pair<std::string, std::vector<std::string>>>;
69 using MapperGetSubTree = std::map<std::string, std::map<std::string, std::vector<std::string>>>;
70 
71 /* A type for holding the innermost map of property::value.*/
72 using IPZKwdValueMap = std::unordered_map<std::string, std::string>;
73 /*IPZ VPD Map of format <Record name, <keyword, value>>*/
74 using IPZVpdMap = std::unordered_map<std::string, IPZKwdValueMap>;
75 
76 /*Value types supported by Keyword VPD*/
77 using KWdVPDValueType = std::variant<BinaryVector,std::string, size_t>;
78 /* This hold map of parsed data of keyword VPD type*/
79 using KeywordVpdMap = std::unordered_map<std::string, KWdVPDValueType>;
80 
81 /**
82  * Both Keyword VPD parser and DDIMM parser stores the
83  * parsed VPD in the same format.
84  * To have better readability, two types are defined for underneath data structure.
85 */
86 using DdimmVpdMap = KeywordVpdMap;
87 
88 /**
89  * Both Keyword VPD parser and ISDIMM parser stores the
90  * parsed SPD in the same format.
91 */
92 using JedecSpdMap = KeywordVpdMap;
93 
94 /**
95  * Type to hold keyword::value map of a VPD.
96  * Variant can be extended to support additional type.
97 */
98 using VPDKWdValueMap = std::variant<IPZKwdValueMap, KeywordVpdMap>;
99 
100 /* Map<Property, Value>*/
101 using PropertyMap = std::map<std::string, DbusVariantType>;
102 /* Map<Interface<Property, Value>>*/
103 using InterfaceMap = std::map<std::string, PropertyMap>;
104 using ObjectMap = std::map<sdbusplus::message::object_path, InterfaceMap>;
105 
106 using KwSize = uint8_t;
107 using RecordId = uint8_t;
108 using RecordSize = uint16_t;
109 using RecordType = uint16_t;
110 using RecordOffset = uint16_t;
111 using RecordLength = uint16_t;
112 using ECCOffset = uint16_t;
113 using ECCLength = uint16_t;
114 using PoundKwSize = uint16_t;
115 
116 using RecordOffsetList = std::vector<uint32_t>;
117 
118 using VPDMapVariant = std::variant<std::monostate, IPZVpdMap, KeywordVpdMap>;
119 
120 using HWVerList = std::vector<std::pair<std::string, std::string>>;
121 /**
122  * Map of <systemIM, pair<Default version, vector<HW version, JSON suffix>>>
123 */
124 using SystemTypeMap =
125     std::unordered_map<std::string, std::pair<std::string, HWVerList>>;
126 
127 using Path = std::string;
128 using Record = std::string;
129 using Keyword = std::string;
130 
131 using IpzData = std::tuple<Record, Keyword, BinaryVector>;
132 using KwData = std::tuple<Keyword, BinaryVector>;
133 using VpdData = std::variant<IpzData, KwData>;
134 
135 using IpzType = std::tuple<Record, Keyword>;
136 using ReadVpdParams = std::variant<IpzType, Keyword>;
137 using WriteVpdParams = std::variant<IpzData, KwData>;
138 
139 using ListOfPaths = std::vector<sdbusplus::message::object_path>;
140 using RecordData = std::tuple<RecordOffset, RecordLength, ECCOffset, ECCLength>;
141 
142 using DbusInvalidArgument =
143     sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
144 using DbusNotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
145 
146 using InvalidArgument = phosphor::logging::xyz::openbmc_project::Common::InvalidArgument;
147 
148 namespace DeviceError = sdbusplus::xyz::openbmc_project::Common::Device::Error;
149 
150 /* PEL Severity enum as defined in [xyz.openbmc_project.Logging.Entry.Level]log.hpp from 'phosphor-logging' repo. */
151 enum SeverityType
152 {
153     Notice,
154     Informational,
155     Debug,
156     Warning,
157     Critical,
158     Emergency,
159     Alert,
160     Error
161 };
162 
163 /* PEL callout priority from 'phosphor-logging' pel_types.hpp. If any change in 'phosphor-logging', it needs update here as well. */
164 enum CalloutPriority
165 {
166     High,
167     Medium,
168     MediumGroupA,
169     MediumGroupB,
170     MediumGroupC,
171     Low
172 };
173 
174 /* 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. */
175 enum ErrorType
176 {
177     DefaultValue,
178     InvalidVpdMessage,
179     VpdMismatch,
180     InvalidEeprom,
181     EccCheckFailed,
182     JsonFailure,
183     DbusFailure,
184     InvalidSystem,
185     EssentialFru,
186     GpioError,
187     InternalFailure, /* Should be used for any generic firmware failure */
188     FruMissing, /* Should be used in case of presence failure */
189     SystemTypeMismatch,
190     UndefinedError,
191     UnknownSystemSettings,
192     FirmwareError,
193     VpdParseError /* Should be used in case of any generic VPD parsing error. */
194 };
195 
196 /**
197  * @brief Enum which defines VPD collection modes
198  */
199 enum class VpdCollectionMode : uint8_t
200 {
201     HARDWARE_MODE,
202     MIXED_MODE,
203     FILE_MODE,
204     DEFAULT_MODE = HARDWARE_MODE
205 };
206 
207 using InventoryCalloutData = std::tuple<std::string, CalloutPriority>;
208 using DeviceCalloutData = std::tuple<std::string, std::string>;
209 using I2cBusCalloutData = std::tuple<std::string, std::string, std::string>;
210 
211 using ExceptionInfoVariant = std::variant<std::monostate, ErrorType, std::string>;
212 /* Error info map of format <Error format, Value> */
213 using ExceptionDataMap = std::map<std::string, ExceptionInfoVariant>;
214 
215 /* Pair of invalid record name and error encountered while parsing the record*/
216 using InvalidRecordEntry = std::pair<Record,ErrorType>;
217 /* List of invalid record entries*/
218 using InvalidRecordList = std::vector<InvalidRecordEntry>;
219 /* Map of inventory path -> Present property match object */
220 using FruPresenceMatchObjectMap = std::map<Path, std::shared_ptr<sdbusplus::bus::match_t>>;
221 /* A map of interface to match object*/
222 using MatchObjectInterfaceMap = std::map<std::string,std::shared_ptr<sdbusplus::bus::match_t>>;
223 /* A map of service name to match object interface map*/
224 using MatchObjectMap = std::map<std::string,MatchObjectInterfaceMap>;
225 
226 /*
227 * Tuple of Error type, severity, internal rc, userdata1, userdata2, symFru, Procedure
228 */
229 using PelInfoTuple =
230     std::tuple<types::ErrorType, std::optional<types::SeverityType>, uint8_t, std::optional<std::string>,
231                std::optional<std::string>, std::optional<std::string>,
232                std::optional<std::string>>;
233 /* A tuple of Dbus object path, interface and property*/
234 using DbusPropertyEntry = std::tuple<std::string, std::string, std::string>;
235 /* A list of Dbus property entries */
236 using DbusPropertyList = std::vector<DbusPropertyEntry>;
237 
238 using CommonProgress = sdbusplus::common::xyz::openbmc_project::common::Progress;
239 using VpdCollectionStatus = CommonProgress::OperationStatus;
240 } // namespace types
241 } // namespace vpd
242