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