blob: 1eb9d3f6b77a5b45aa47acd993f2f6a3b8b6bb21 [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.
Anupama B Rda9806b2025-08-29 02:41:10 -050037 * @param[in] i_progressiFace - Interface to track collection progress.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053038 * @param[in] i_ioCon - IO context.
39 * @param[in] i_asioConnection - Dbus Connection.
Sunny Srivastava867ee752025-04-15 12:24:23 +053040 */
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053041 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,
Anupama B Rda9806b2025-08-29 02:41:10 -050045 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_progressiFace,
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053046 const std::shared_ptr<boost::asio::io_context>& i_ioCon,
47 const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection);
48
Anupama B R7127ab42025-06-26 01:39:08 -050049 /**
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
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053065 private:
66 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053067 * @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 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053079 * @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
Sunny Srivastava78a50422025-04-25 11:17:56 +0530103 /**
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
Anupama B Rec7f8862025-05-23 01:21:01 -0500130 /**
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
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530143 // 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
Anupama B Rda9806b2025-08-29 02:41:10 -0500158 // Shared pointer to Dbus collection progress interface class.
159 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface;
160
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530161 // 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;
Anupama B Rc7565ed2025-06-19 02:08:39 -0500166
167 // Shared pointer to Listener object.
168 std::shared_ptr<Listener> m_eventListener;
Sunny Srivastava867ee752025-04-15 12:24:23 +0530169};
170} // namespace vpd