xref: /openbmc/openpower-vpd-parser/vpd-manager/oem-handler/ibm_handler.hpp (revision 56e4537c80d009d1d072d141b2d96f4368203a95)
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_ioCon - IO context.
38      * @param[in] i_asioConnection - Dbus Connection.
39      */
40     IbmHandler(
41         std::shared_ptr<Worker>& o_worker,
42         std::shared_ptr<BackupAndRestore>& o_backupAndRestoreObj,
43         const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_iFace,
44         const std::shared_ptr<boost::asio::io_context>& i_ioCon,
45         const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection);
46 
47   private:
48     /**
49      * @brief API to set timer to detect system VPD over D-Bus.
50      *
51      * System VPD is required before bus name for VPD-Manager is claimed. Once
52      * system VPD is published, VPD for other FRUs should be collected. This API
53      * detects id system VPD is already published on D-Bus and based on that
54      * triggers VPD collection for rest of the FRUs.
55      *
56      * Note: Throws exception in case of any failure. Needs to be handled by the
57      * caller.
58      */
59     void SetTimerToDetectSVPDOnDbus();
60 
61     /**
62      * @brief Set timer to detect and set VPD collection status for the system.
63      *
64      * Collection of FRU VPD is triggered in a separate thread. Resulting in
65      * multiple threads at  a given time. The API creates a timer which on
66      * regular interval will check if all the threads were collected back and
67      * sets the status of the VPD collection for the system accordingly.
68      *
69      * @throw std::runtime_error
70      */
71     void SetTimerToDetectVpdCollectionStatus();
72 
73     /**
74      * @brief API to process VPD collection thread failed EEPROMs.
75      */
76     void processFailedEeproms();
77 
78     /**
79      * @brief API to check and update PowerVS VPD.
80      *
81      * The API will read the existing data from the DBus and if found
82      * different than what has been read from JSON, it will update the VPD with
83      * JSON data on hardware and DBus both.
84      *
85      * @param[in] i_powerVsJsonObj - PowerVS JSON object.
86      * @param[out] o_failedPathList - List of path failed to update.
87      */
88     void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj,
89                                   std::vector<std::string>& o_failedPathList);
90     /**
91      * @brief API to handle configuration w.r.t. PowerVS systems.
92      *
93      * Some FRUs VPD is specific to powerVS system. The API detects the
94      * powerVS configuration and updates the VPD accordingly.
95      */
96     void ConfigurePowerVsSystem();
97 
98     /**
99      * @brief API to perform initial setup before manager claims Bus name.
100      *
101      * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
102      * corret device tree, inventory JSON w.r.t system should be linked and
103      * system VPD should be on DBus.
104      */
105     void performInitialSetup();
106 
107     /**
108      * @brief API to prime system blueprint.
109      *
110      * The API will traverse the system config JSON and will prime all the FRU
111      * paths which qualifies for priming.
112      */
113     void primeSystemBlueprint();
114 
115     /**
116      * @brief Function to enable and bring MUX out of idle state.
117      *
118      * This finds all the MUX defined in the system json and enables them by
119      * setting the holdidle parameter to 0.
120      *
121      * @throw std::runtime_error
122      */
123     void enableMuxChips();
124 
125     /**
126      * @brief API to check if priming is required.
127      *
128      * The API will traverse the system config JSON and counts the FRU
129      * paths which qualifies for priming and compares with count of object paths
130      * found under PIM which hosts the "com.ibm.VPD.Collection" interface. If
131      * the dbus count is equal to or greater than the count from JSON config
132      * consider as priming is not required.
133      *
134      * @return true if priming is required, false otherwise.
135      */
136     bool isPrimingRequired() const noexcept;
137 
138     // Parsed system config json object.
139     nlohmann::json m_sysCfgJsonObj{};
140 
141     // Shared pointer to worker class
142     std::shared_ptr<Worker>& m_worker;
143 
144     // Shared pointer to backup and restore object.
145     std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
146 
147     // Shared pointer to GpioMonitor object.
148     std::shared_ptr<GpioMonitor> m_gpioMonitor;
149 
150     // Shared pointer to Dbus interface class.
151     const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
152 
153     // Shared pointer to asio context object.
154     const std::shared_ptr<boost::asio::io_context>& m_ioContext;
155 
156     // Shared pointer to bus connection.
157     const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
158 
159     // Shared pointer to Listener object.
160     std::shared_ptr<Listener> m_eventListener;
161 };
162 } // namespace vpd
163