blob: f8b7cbcf0ffcd38e74b6a1f39ce36eaac9cdee70 [file] [log] [blame]
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06001#pragma once
2
Sunny Srivastava523af2e2022-02-14 07:30:10 -06003#include "bios_handler.hpp"
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -06004#include "editor_impl.hpp"
Sunny Srivastava523af2e2022-02-14 07:30:10 -06005#include "gpioMonitor.hpp"
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06006
Sunny Srivastava523af2e2022-02-14 07:30:10 -06007#include <sdbusplus/asio/object_server.hpp>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06008
Patrick Williamsc78d8872023-05-10 07:50:56 -05009#include <map>
10
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060011namespace openpower
12{
13namespace vpd
14{
15namespace manager
16{
17
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060018/** @class Manager
19 * @brief OpenBMC VPD Manager implementation.
20 *
Sunny Srivastava523af2e2022-02-14 07:30:10 -060021 * Implements methods under interface com.ibm.vpd.Manager.
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060022 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -060023class Manager
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060024{
25 public:
26 /* Define all of the basic class operations:
27 * Not allowed:
28 * - Default constructor to avoid nullptrs.
29 * - Copy operations due to internal unique_ptr.
30 * - Move operations due to 'this' being registered as the
31 * 'context' with sdbus.
32 * Allowed:
33 * - Destructor.
34 */
35 Manager() = delete;
36 Manager(const Manager&) = delete;
37 Manager& operator=(const Manager&) = delete;
38 Manager(Manager&&) = delete;
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -050039 ~Manager()
40 {
41 sd_bus_unref(sdBus);
42 }
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060043
Sunny Srivastava523af2e2022-02-14 07:30:10 -060044 /** @brief Constructor.
45 * @param[in] ioCon - IO context.
46 * @param[in] iFace - interface to implement.
47 * @param[in] connection - Dbus Connection.
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060048 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -060049 Manager(std::shared_ptr<boost::asio::io_context>& ioCon,
50 std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace,
51 std::shared_ptr<sdbusplus::asio::connection>& conn);
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060052
53 /** @brief Implementation for WriteKeyword
54 * Api to update the keyword value for a given inventory.
55 *
56 * @param[in] path - Path to the D-Bus object that represents the FRU.
57 * @param[in] recordName - name of the record for which the keyword value
58 * has to be modified
59 * @param[in] keyword - keyword whose value needs to be updated
60 * @param[in] value - value that needs to be updated
61 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -060062 void writeKeyword(const sdbusplus::message::object_path& path,
63 const std::string& recordName, const std::string& keyword,
64 const Binary& value);
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060065
66 /** @brief Implementation for GetFRUsByUnexpandedLocationCode
67 * A method to get list of FRU D-BUS object paths for a given unexpanded
68 * location code. Returns empty vector if no FRU found for that location
69 * code.
70 *
71 * @param[in] locationCode - An un-expanded Location code.
72 * @param[in] nodeNumber - Denotes the node in case of a multi-node
73 * configuration, ignored on a single node system.
74 *
75 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
76 * List of all the FRUs D-Bus object paths for the given location code.
77 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -050078 inventory::ListOfPaths
Sunny Srivastava523af2e2022-02-14 07:30:10 -060079 getFRUsByUnexpandedLocationCode(const std::string& locationCode,
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060080 const uint16_t nodeNumber);
81
82 /** @brief Implementation for GetFRUsByExpandedLocationCode
83 * A method to get list of FRU D-BUS object paths for a given expanded
84 * location code. Returns empty vector if no FRU found for that location
85 * code.
86 *
87 * @param[in] locationCode - Location code in expanded format.
88 *
89 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
90 * List of all the FRUs D-Bus object path for the given location code.
91 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -050092 inventory::ListOfPaths
Sunny Srivastava523af2e2022-02-14 07:30:10 -060093 getFRUsByExpandedLocationCode(const std::string& locationCode);
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060094
95 /** @brief Implementation for GetExpandedLocationCode
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -050096 * An API to get expanded location code corresponding to a given
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060097 * un-expanded location code.
98 *
99 * @param[in] locationCode - Location code in un-expaned format.
100 * @param[in] nodeNumber - Denotes the node in case of multi-node
101 * configuration. Ignored in case of single node configuration.
102 *
103 * @return locationCode[std::string] - Location code in expanded format.
104 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600105 std::string getExpandedLocationCode(const std::string& locationCode,
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600106 const uint16_t nodeNumber);
107
SunnySrivastava19849a195542020-09-07 06:04:50 -0500108 /** @brief Api to perform VPD recollection.
109 * This api will trigger parser to perform VPD recollection for FRUs that
110 * can be replaced at standby.
111 */
112 void performVPDRecollection();
113
Sunny Srivastava28abd6e2021-07-28 02:58:28 -0500114 /** @brief Api to delete FRU VPD.
115 * This api will set the present property of given FRU to false. If already
116 * set to false, It will log an error.
117 * @param[in] path - Object path of FRU.
118 */
119 void deleteFRUVPD(const sdbusplus::message::object_path& path);
120
Sunny Srivastava6a1bd392021-06-02 04:39:24 -0500121 /** @brief Api to perform VPD collection for a single fru.
122 * @param[in] path - Dbus object path of that fru.
123 */
124 void collectFRUVPD(const sdbusplus::message::object_path& path);
125
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600126 private:
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600127 /**
128 * @brief An api to process some initial requirements.
129 */
130 void initManager();
131
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600132 /** @brief process the given JSON file
133 */
134 void processJSON();
135
Sunny Srivastavaecb5c7d2021-09-02 07:20:24 -0500136 /** @brief Api to register host state callback.
137 * This api will register callback to listen for host state property change.
138 */
139 void listenHostState();
140
141 /** @brief Callback to listen for Host state change
142 * @param[in] msg - callback message.
143 */
Patrick Williams2eb01762022-07-22 19:26:56 -0500144 void hostStateCallBack(sdbusplus::message_t& msg);
Sunny Srivastavaecb5c7d2021-09-02 07:20:24 -0500145
Santosh Puranikb62f6052022-04-06 18:37:54 +0530146 /** @brief Api to register AssetTag property change.
147 * This api will register callback to listen for asset tag property change.
148 */
149 void listenAssetTag();
150
151 /** @brief Callback to listen for Asset tag change
152 * @param[in] msg - callback message.
153 */
Patrick Williams2eb01762022-07-22 19:26:56 -0500154 void assetTagCallback(sdbusplus::message_t& msg);
Santosh Puranikb62f6052022-04-06 18:37:54 +0530155
Santosh Puranik6b2b5372022-06-02 20:49:02 +0530156 /**
157 * @brief Restores and defaulted VPD on the system VPD EEPROM.
158 *
159 * This function will read the system VPD EEPROM and check if any of the
160 * keywords that need to be preserved across FRU replacements are defaulted
161 * in the EEPROM. If they are, this function will restore them from the
162 * value that is in the D-Bus cache.
163 */
164 void restoreSystemVpd();
165
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500166 /**
Sunny Srivastava6a1bd392021-06-02 04:39:24 -0500167 * @brief An api to trigger vpd collection for a fru by bind/unbind of
168 * driver.
169 * @param[in] singleFru - Json of a single fru inder a given EEPROM path.
170 * @param[in] path - Inventory path.
171 */
172 void triggerVpdCollection(const nlohmann::json& singleFru,
173 const std::string& path);
174
175 /**
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500176 * @brief Check for essential fru in the system.
177 * The api check for the presence of FRUs marked as essential and logs PEL
178 * in case they are missing.
179 */
180 void checkEssentialFrus();
181
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600182 // Shared pointer to asio context object.
183 std::shared_ptr<boost::asio::io_context>& ioContext;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600184
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600185 // Shared pointer to Dbus interface class.
186 std::shared_ptr<sdbusplus::asio::dbus_interface>& interface;
187
188 // Shared pointer to bus connection.
189 std::shared_ptr<sdbusplus::asio::connection>& conn;
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600190
191 // file to store parsed json
192 nlohmann::json jsonFile;
193
194 // map to hold mapping to inventory path to vpd file path
195 // we need as map here as it is in reverse order to that of json
196 inventory::FrusMap frus;
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -0500197
198 // map to hold the mapping of location code and inventory path
199 inventory::LocationCodeMap fruLocationCode;
SunnySrivastava19849a195542020-09-07 06:04:50 -0500200
201 // map to hold FRUs which can be replaced at standby
202 inventory::ReplaceableFrus replaceableFrus;
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500203
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600204 // Shared pointer to gpio monitor object.
205 std::shared_ptr<GpioMonitor> gpioMon;
206
207 // Shared pointer to instance of the BIOS handler.
208 std::shared_ptr<BiosHandler> biosHandler;
209
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500210 // List of FRUs marked as essential in the system.
211 inventory::EssentialFrus essentialFrus;
212
213 // sd-bus
214 sd_bus* sdBus = nullptr;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600215};
216
217} // namespace manager
218} // namespace vpd
219} // namespace openpower