blob: bead9e1af940e7fce2792afdc532006d8a1fb166 [file] [log] [blame]
Sunny Srivastava867ee752025-04-15 12:24:23 +05301#pragma once
2
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05303#include "backup_restore.hpp"
4#include "gpio_monitor.hpp"
Anupama B Rc7565ed2025-06-19 02:08:39 -05005#include "listener.hpp"
Souvik Roya5e18b82025-09-25 05:59:56 +00006#include "logger.hpp"
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05307#include "worker.hpp"
8
9#include <sdbusplus/asio/object_server.hpp>
10
11#include <memory>
12
Sunny Srivastava867ee752025-04-15 12:24:23 +053013namespace vpd
14{
15/**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053016 * @brief Class to handle OEM specific use case.
Sunny Srivastava867ee752025-04-15 12:24:23 +053017 *
18 * Few pre-requisites needs to be taken case specifically, which will be
19 * encapsulated by this class.
20 */
21class 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.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053033 *
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.
Anupama B Rda9806b2025-08-29 02:41:10 -050038 * @param[in] i_progressiFace - Interface to track collection progress.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053039 * @param[in] i_ioCon - IO context.
40 * @param[in] i_asioConnection - Dbus Connection.
Sunny Srivastava867ee752025-04-15 12:24:23 +053041 */
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053042 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,
Anupama B Rda9806b2025-08-29 02:41:10 -050046 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_progressiFace,
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053047 const std::shared_ptr<boost::asio::io_context>& i_ioCon,
48 const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection);
49
Anupama B R7127ab42025-06-26 01:39:08 -050050 /**
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
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053066 private:
67 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053068 * @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 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053080 * @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
Sunny Srivastava78a50422025-04-25 11:17:56 +0530104 /**
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 API to prime system blueprint.
115 *
116 * The API will traverse the system config JSON and will prime all the FRU
117 * paths which qualifies for priming.
118 */
119 void primeSystemBlueprint();
120
121 /**
122 * @brief Function to enable and bring MUX out of idle state.
123 *
124 * This finds all the MUX defined in the system json and enables them by
125 * setting the holdidle parameter to 0.
126 *
127 * @throw std::runtime_error
128 */
129 void enableMuxChips();
130
Anupama B Rec7f8862025-05-23 01:21:01 -0500131 /**
132 * @brief API to check if priming is required.
133 *
134 * The API will traverse the system config JSON and counts the FRU
135 * paths which qualifies for priming and compares with count of object paths
136 * found under PIM which hosts the "com.ibm.VPD.Collection" interface. If
137 * the dbus count is equal to or greater than the count from JSON config
138 * consider as priming is not required.
139 *
140 * @return true if priming is required, false otherwise.
141 */
142 bool isPrimingRequired() const noexcept;
143
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530144 // Parsed system config json object.
145 nlohmann::json m_sysCfgJsonObj{};
146
147 // Shared pointer to worker class
148 std::shared_ptr<Worker>& m_worker;
149
150 // Shared pointer to backup and restore object.
151 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
152
153 // Shared pointer to GpioMonitor object.
154 std::shared_ptr<GpioMonitor> m_gpioMonitor;
155
156 // Shared pointer to Dbus interface class.
157 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
158
Anupama B Rda9806b2025-08-29 02:41:10 -0500159 // Shared pointer to Dbus collection progress interface class.
160 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface;
161
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530162 // Shared pointer to asio context object.
163 const std::shared_ptr<boost::asio::io_context>& m_ioContext;
164
165 // Shared pointer to bus connection.
166 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
Anupama B Rc7565ed2025-06-19 02:08:39 -0500167
168 // Shared pointer to Listener object.
169 std::shared_ptr<Listener> m_eventListener;
Souvik Roya5e18b82025-09-25 05:59:56 +0000170
171 // Shared pointer to Logger object.
172 std::shared_ptr<Logger> m_logger;
Sunny Srivastava867ee752025-04-15 12:24:23 +0530173};
174} // namespace vpd