blob: 74429a2244cef3396758ee488dd30299706e8b49 [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"
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05306#include "worker.hpp"
7
8#include <sdbusplus/asio/object_server.hpp>
9
10#include <memory>
11
Sunny Srivastava867ee752025-04-15 12:24:23 +053012namespace vpd
13{
14/**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053015 * @brief Class to handle OEM specific use case.
Sunny Srivastava867ee752025-04-15 12:24:23 +053016 *
17 * Few pre-requisites needs to be taken case specifically, which will be
18 * encapsulated by this class.
19 */
20class 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.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053032 *
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.
Sunny Srivastava867ee752025-04-15 12:24:23 +053039 */
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053040 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
Anupama B R7127ab42025-06-26 01:39:08 -050047 /**
48 * @brief API to collect all FRUs VPD.
49 *
50 * This api will call worker API to perform VPD collection for all FRUs
51 * present in the system config JSON and publish it on DBus. Also updates
52 * the Dbus VPD collection status property hosted under vpd-manager.
53 *
54 * Note:
55 * System VPD collection will always be skipped.
56 * If host is in power on state, FRUs marked as 'powerOffOnly' in the
57 * system config JSON will be skipped.
58 *
59 * @throw JsonException, runtime_error
60 */
61 void collectAllFruVpd();
62
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053063 private:
64 /**
65 * @brief API to set timer to detect system VPD over D-Bus.
66 *
67 * System VPD is required before bus name for VPD-Manager is claimed. Once
68 * system VPD is published, VPD for other FRUs should be collected. This API
69 * detects id system VPD is already published on D-Bus and based on that
70 * triggers VPD collection for rest of the FRUs.
71 *
72 * Note: Throws exception in case of any failure. Needs to be handled by the
73 * caller.
74 */
75 void SetTimerToDetectSVPDOnDbus();
76
77 /**
78 * @brief Set timer to detect and set VPD collection status for the system.
79 *
80 * Collection of FRU VPD is triggered in a separate thread. Resulting in
81 * multiple threads at a given time. The API creates a timer which on
82 * regular interval will check if all the threads were collected back and
83 * sets the status of the VPD collection for the system accordingly.
84 *
85 * @throw std::runtime_error
86 */
87 void SetTimerToDetectVpdCollectionStatus();
88
89 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053090 * @brief API to process VPD collection thread failed EEPROMs.
91 */
92 void processFailedEeproms();
93
94 /**
95 * @brief API to check and update PowerVS VPD.
96 *
97 * The API will read the existing data from the DBus and if found
98 * different than what has been read from JSON, it will update the VPD with
99 * JSON data on hardware and DBus both.
100 *
101 * @param[in] i_powerVsJsonObj - PowerVS JSON object.
102 * @param[out] o_failedPathList - List of path failed to update.
103 */
104 void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj,
105 std::vector<std::string>& o_failedPathList);
106 /**
107 * @brief API to handle configuration w.r.t. PowerVS systems.
108 *
109 * Some FRUs VPD is specific to powerVS system. The API detects the
110 * powerVS configuration and updates the VPD accordingly.
111 */
112 void ConfigurePowerVsSystem();
113
Sunny Srivastava78a50422025-04-25 11:17:56 +0530114 /**
115 * @brief API to perform initial setup before manager claims Bus name.
116 *
117 * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
118 * corret device tree, inventory JSON w.r.t system should be linked and
119 * system VPD should be on DBus.
120 */
121 void performInitialSetup();
122
123 /**
124 * @brief API to prime system blueprint.
125 *
126 * The API will traverse the system config JSON and will prime all the FRU
127 * paths which qualifies for priming.
128 */
129 void primeSystemBlueprint();
130
131 /**
132 * @brief Function to enable and bring MUX out of idle state.
133 *
134 * This finds all the MUX defined in the system json and enables them by
135 * setting the holdidle parameter to 0.
136 *
137 * @throw std::runtime_error
138 */
139 void enableMuxChips();
140
Anupama B Rec7f8862025-05-23 01:21:01 -0500141 /**
142 * @brief API to check if priming is required.
143 *
144 * The API will traverse the system config JSON and counts the FRU
145 * paths which qualifies for priming and compares with count of object paths
146 * found under PIM which hosts the "com.ibm.VPD.Collection" interface. If
147 * the dbus count is equal to or greater than the count from JSON config
148 * consider as priming is not required.
149 *
150 * @return true if priming is required, false otherwise.
151 */
152 bool isPrimingRequired() const noexcept;
153
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530154 // Parsed system config json object.
155 nlohmann::json m_sysCfgJsonObj{};
156
157 // Shared pointer to worker class
158 std::shared_ptr<Worker>& m_worker;
159
160 // Shared pointer to backup and restore object.
161 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
162
163 // Shared pointer to GpioMonitor object.
164 std::shared_ptr<GpioMonitor> m_gpioMonitor;
165
166 // Shared pointer to Dbus interface class.
167 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
168
169 // Shared pointer to asio context object.
170 const std::shared_ptr<boost::asio::io_context>& m_ioContext;
171
172 // Shared pointer to bus connection.
173 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
Anupama B Rc7565ed2025-06-19 02:08:39 -0500174
175 // Shared pointer to Listener object.
176 std::shared_ptr<Listener> m_eventListener;
Sunny Srivastava867ee752025-04-15 12:24:23 +0530177};
178} // namespace vpd