xref: /openbmc/openpower-vpd-parser/vpd-manager/oem-handler/ibm_handler.hpp (revision ca738cf1acca2a0cb9f0189adbf9ea0c1505efff)
1 #pragma once
2 
3 #include "backup_restore.hpp"
4 #include "gpio_monitor.hpp"
5 #include "listener.hpp"
6 #include "logger.hpp"
7 #include "worker.hpp"
8 
9 #include <sdbusplus/asio/object_server.hpp>
10 
11 #include <memory>
12 
13 namespace vpd
14 {
15 /**
16  * @brief Class to handle OEM specific use case.
17  *
18  * Few pre-requisites needs to be taken case specifically, which will be
19  * encapsulated by this class.
20  */
21 class IbmHandler
22 {
23   public:
24     /**
25      * List of deleted methods.
26      */
27     IbmHandler(const IbmHandler&) = delete;
28     IbmHandler& operator=(const IbmHandler&) = delete;
29     IbmHandler(IbmHandler&&) = delete;
30 
31     /**
32      * @brief Constructor.
33      *
34      * @param[in] o_worker - Reference to worker class object.
35      * @param[in] o_backupAndRestoreObj - Ref to back up and restore class
36      * object.
37      * @param[in] i_iFace - interface to implement.
38      * @param[in] i_progressiFace - Interface to track collection progress.
39      * @param[in] i_ioCon - IO context.
40      * @param[in] i_asioConnection - Dbus Connection.
41      */
42     IbmHandler(
43         std::shared_ptr<Worker>& o_worker,
44         std::shared_ptr<BackupAndRestore>& o_backupAndRestoreObj,
45         const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_iFace,
46         const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_progressiFace,
47         const std::shared_ptr<boost::asio::io_context>& i_ioCon,
48         const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection);
49 
50     /**
51      * @brief API to collect all FRUs VPD.
52      *
53      * This api will call worker API to perform VPD collection for all FRUs
54      * present in the system config JSON and publish it on DBus. Also updates
55      * the Dbus VPD collection status property hosted under vpd-manager.
56      *
57      * Note:
58      * System VPD collection will always be skipped.
59      * If host is in power on state, FRUs marked as 'powerOffOnly' in the
60      * system config JSON will be skipped.
61      *
62      * @throw JsonException, runtime_error
63      */
64     void collectAllFruVpd();
65 
66   private:
67     /**
68      * @brief Set timer to detect and set VPD collection status for the system.
69      *
70      * Collection of FRU VPD is triggered in a separate thread. Resulting in
71      * multiple threads at  a given time. The API creates a timer which on
72      * regular interval will check if all the threads were collected back and
73      * sets the status of the VPD collection for the system accordingly.
74      *
75      * @throw std::runtime_error
76      */
77     void SetTimerToDetectVpdCollectionStatus();
78 
79     /**
80      * @brief API to process VPD collection thread failed EEPROMs.
81      */
82     void processFailedEeproms();
83 
84     /**
85      * @brief API to check and update PowerVS VPD.
86      *
87      * The API will read the existing data from the DBus and if found
88      * different than what has been read from JSON, it will update the VPD with
89      * JSON data on hardware and DBus both.
90      *
91      * @param[in] i_powerVsJsonObj - PowerVS JSON object.
92      * @param[out] o_failedPathList - List of path failed to update.
93      */
94     void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj,
95                                   std::vector<std::string>& o_failedPathList);
96     /**
97      * @brief API to handle configuration w.r.t. PowerVS systems.
98      *
99      * Some FRUs VPD is specific to powerVS system. The API detects the
100      * powerVS configuration and updates the VPD accordingly.
101      */
102     void ConfigurePowerVsSystem();
103 
104     /**
105      * @brief API to perform initial setup before manager claims Bus name.
106      *
107      * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
108      * corret device tree, inventory JSON w.r.t system should be linked and
109      * system VPD should be on DBus.
110      */
111     void performInitialSetup();
112 
113     /**
114      * @brief Function to enable and bring MUX out of idle state.
115      *
116      * This finds all the MUX defined in the system json and enables them by
117      * setting the holdidle parameter to 0.
118      *
119      * @throw std::runtime_error
120      */
121     void enableMuxChips();
122 
123     // Parsed system config json object.
124     nlohmann::json m_sysCfgJsonObj{};
125 
126     // Shared pointer to worker class
127     std::shared_ptr<Worker>& m_worker;
128 
129     // Shared pointer to backup and restore object.
130     std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
131 
132     // Shared pointer to GpioMonitor object.
133     std::shared_ptr<GpioMonitor> m_gpioMonitor;
134 
135     // Shared pointer to Dbus interface class.
136     const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
137 
138     // Shared pointer to Dbus collection progress interface class.
139     const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface;
140 
141     // Shared pointer to asio context object.
142     const std::shared_ptr<boost::asio::io_context>& m_ioContext;
143 
144     // Shared pointer to bus connection.
145     const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
146 
147     // Shared pointer to Listener object.
148     std::shared_ptr<Listener> m_eventListener;
149 
150     // Shared pointer to Logger object.
151     std::shared_ptr<Logger> m_logger;
152 };
153 } // namespace vpd
154