xref: /openbmc/openpower-vpd-parser/vpd-manager/include/manager.hpp (revision 380efbb50bef1581a9c45b53ca2546497ff4f417)
1 #pragma once
2 
3 #include "backup_restore.hpp"
4 #include "constants.hpp"
5 #include "gpio_monitor.hpp"
6 #include "types.hpp"
7 #include "worker.hpp"
8 
9 #include <oem-handler/ibm_handler.hpp>
10 #include <sdbusplus/asio/object_server.hpp>
11 
12 namespace vpd
13 {
14 /**
15  * @brief Class to manage VPD processing.
16  *
17  * The class is responsible to implement methods to manage VPD on the system.
18  * It also implements methods to be exposed over D-Bus required to access/edit
19  * VPD data.
20  */
21 class Manager
22 {
23   public:
24     /**
25      * List of deleted methods.
26      */
27     Manager(const Manager&) = delete;
28     Manager& operator=(const Manager&) = delete;
29     Manager(Manager&&) = delete;
30 
31     /**
32      * @brief Constructor.
33      *
34      * @param[in] ioCon - IO context.
35      * @param[in] iFace - interface to implement.
36      * @param[in] connection - Dbus Connection.
37      */
38     Manager(const std::shared_ptr<boost::asio::io_context>& ioCon,
39             const std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace,
40             const std::shared_ptr<sdbusplus::asio::connection>& asioConnection);
41 
42     /**
43      * @brief Destructor.
44      */
45     ~Manager() = default;
46 
47     /**
48      * @brief Update keyword value.
49      *
50      * This API is used to update keyword value on the given input path and its
51      * redundant path(s) if any taken from system config JSON.
52      *
53      * To update IPZ type VPD, input parameter for writing should be in the form
54      * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
55      *
56      * To update Keyword type VPD, input parameter for writing should be in the
57      * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
58      *
59      * @param[in] i_vpdPath - Path (inventory object path/FRU EEPROM path).
60      * @param[in] i_paramsToWriteData - Input details.
61      *
62      * @return On success returns number of bytes written, on failure returns
63      * -1.
64      */
65     int updateKeyword(const types::Path i_vpdPath,
66                       const types::WriteVpdParams i_paramsToWriteData);
67 
68     /**
69      * @brief Update keyword value on hardware.
70      *
71      * This API is used to update keyword value on hardware. Updates only on the
72      * given input hardware path, does not look for corresponding redundant or
73      * primary path against the given path. To update corresponding paths, make
74      * separate call with respective path.
75      *
76      * To update IPZ type VPD, input parameter for writing should be in the form
77      * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
78      *
79      * To update Keyword type VPD, input parameter for writing should be in the
80      * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
81      *
82      * @param[in] i_fruPath - EEPROM path of the FRU.
83      * @param[in] i_paramsToWriteData - Input details.
84      *
85      * @return On success returns number of bytes written, on failure returns
86      * -1.
87      */
88     int updateKeywordOnHardware(
89         const types::Path i_fruPath,
90         const types::WriteVpdParams i_paramsToWriteData) noexcept;
91 
92     /**
93      * @brief Read keyword value.
94      *
95      * API can be used to read VPD keyword from the given input path.
96      *
97      * To read keyword of type IPZ, input parameter for reading should be in the
98      * form of (Record, Keyword). Eg: ("VINI", "SN").
99      *
100      * To read keyword from keyword type VPD, just keyword name has to be
101      * supplied in the input parameter. Eg: ("SN").
102      *
103      * @param[in] i_fruPath - EEPROM path.
104      * @param[in] i_paramsToReadData - Input details.
105      *
106      * @throw
107      * sdbusplus::xyz::openbmc_project::Common::Device::Error::ReadFailure.
108      *
109      * @return On success returns the read value in variant of array of bytes.
110      * On failure throws exception.
111      */
112     types::DbusVariantType readKeyword(
113         const types::Path i_fruPath,
114         const types::ReadVpdParams i_paramsToReadData);
115 
116     /**
117      * @brief Collect single FRU VPD
118      * API can be used to perform VPD collection for the given FRU, only if the
119      * current state of the system matches with the state at which the FRU is
120      * allowed for VPD recollection.
121      *
122      * @param[in] i_dbusObjPath - D-bus object path
123      */
124     void collectSingleFruVpd(
125         const sdbusplus::message::object_path& i_dbusObjPath);
126 
127     /**
128      * @brief Delete single FRU VPD
129      * API can be used to perform VPD deletion for the given FRU.
130      *
131      * @param[in] i_dbusObjPath - D-bus object path
132      */
133     void deleteSingleFruVpd(
134         const sdbusplus::message::object_path& i_dbusObjPath);
135 
136     /**
137      * @brief Get expanded location code.
138      *
139      * API to get expanded location code from the unexpanded location code.
140      *
141      * @param[in] i_unexpandedLocationCode - Unexpanded location code.
142      * @param[in] i_nodeNumber - Denotes the node in case of a multi-node
143      * configuration, defaulted to zero incase of single node system.
144      *
145      * @throw xyz.openbmc_project.Common.Error.InvalidArgument for
146      * invalid argument.
147      *
148      * @return Location code of the FRU.
149      */
150     std::string getExpandedLocationCode(
151         const std::string& i_unexpandedLocationCode,
152         [[maybe_unused]] const uint16_t i_nodeNumber = 0);
153 
154     /**
155      * @brief Get D-Bus object path of FRUs from expanded location code.
156      *
157      * An API to get list of FRU D-Bus object paths for a given expanded
158      * location code.
159      *
160      * @param[in] i_expandedLocationCode - Expanded location code.
161      *
162      * @throw xyz.openbmc_project.Common.Error.InvalidArgument for
163      * invalid argument.
164      *
165      * @return List of FRUs D-Bus object paths for the given location code.
166      */
167     types::ListOfPaths getFrusByExpandedLocationCode(
168         const std::string& i_expandedLocationCode);
169 
170     /**
171      * @brief Get D-Bus object path of FRUs from unexpanded location code.
172      *
173      * An API to get list of FRU D-Bus object paths for a given unexpanded
174      * location code.
175      *
176      * @param[in] i_unexpandedLocationCode - Unexpanded location code.
177      * @param[in] i_nodeNumber - Denotes the node in case of a multi-node
178      * configuration, defaulted to zero incase of single node system.
179      *
180      * @throw xyz.openbmc_project.Common.Error.InvalidArgument for
181      * invalid argument.
182      *
183      * @return List of FRUs D-Bus object paths for the given location code.
184      */
185     types::ListOfPaths getFrusByUnexpandedLocationCode(
186         const std::string& i_unexpandedLocationCode,
187         [[maybe_unused]] const uint16_t i_nodeNumber = 0);
188 
189     /**
190      * @brief Get Hardware path
191      * API can be used to get EEPROM path for the given inventory path.
192      *
193      * @param[in] i_dbusObjPath - D-bus object path
194      *
195      * @return Corresponding EEPROM path.
196      */
197     std::string getHwPath(const sdbusplus::message::object_path& i_dbusObjPath);
198 
199     /**
200      * @brief  Perform VPD recollection
201      * This api will trigger parser to perform VPD recollection for FRUs that
202      * can be replaced at standby.
203      */
204     void performVpdRecollection();
205 
206     /**
207      * @brief Get unexpanded location code.
208      *
209      * An API to get unexpanded location code and node number from expanded
210      * location code.
211      *
212      * @param[in] i_expandedLocationCode - Expanded location code.
213      *
214      * @throw xyz.openbmc_project.Common.Error.InvalidArgument for
215      * invalid argument.
216      *
217      * @return Location code in unexpanded format and its node number.
218      */
219     std::tuple<std::string, uint16_t> getUnexpandedLocationCode(
220         const std::string& i_expandedLocationCode);
221 
222   private:
223     /**
224      * @brief An api to check validity of unexpanded location code.
225      *
226      * @param[in] i_locationCode - Unexpanded location code.
227      *
228      * @return True/False based on validity check.
229      */
230     bool isValidUnexpandedLocationCode(const std::string& i_locationCode);
231 
232     // Shared pointer to asio context object.
233     const std::shared_ptr<boost::asio::io_context>& m_ioContext;
234 
235     // Shared pointer to Dbus interface class.
236     const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
237 
238     // Shared pointer to bus connection.
239     const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
240 
241     // Shared pointer to worker class
242     std::shared_ptr<Worker> m_worker;
243 
244     // Shared pointer to GpioMonitor class
245     std::shared_ptr<GpioMonitor> m_gpioMonitor;
246 
247     // Variable to hold current collection status
248     std::string m_vpdCollectionStatus = "NotStarted";
249 
250     // Shared pointer to backup and restore class
251     std::shared_ptr<BackupAndRestore> m_backupAndRestoreObj;
252 
253     // Shared pointer to oem specific class.
254     std::shared_ptr<IbmHandler> m_ibmHandler;
255 };
256 
257 } // namespace vpd
258