blob: 13de42e25943b2e65964071c042eb062d7e0a313 [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
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -06007#include <map>
Sunny Srivastava523af2e2022-02-14 07:30:10 -06008#include <sdbusplus/asio/object_server.hpp>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06009
10namespace openpower
11{
12namespace vpd
13{
14namespace manager
15{
16
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060017/** @class Manager
18 * @brief OpenBMC VPD Manager implementation.
19 *
Sunny Srivastava523af2e2022-02-14 07:30:10 -060020 * Implements methods under interface com.ibm.vpd.Manager.
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060021 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -060022class Manager
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060023{
24 public:
25 /* Define all of the basic class operations:
26 * Not allowed:
27 * - Default constructor to avoid nullptrs.
28 * - Copy operations due to internal unique_ptr.
29 * - Move operations due to 'this' being registered as the
30 * 'context' with sdbus.
31 * Allowed:
32 * - Destructor.
33 */
34 Manager() = delete;
35 Manager(const Manager&) = delete;
36 Manager& operator=(const Manager&) = delete;
37 Manager(Manager&&) = delete;
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -050038 ~Manager()
39 {
40 sd_bus_unref(sdBus);
41 }
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060042
Sunny Srivastava523af2e2022-02-14 07:30:10 -060043 /** @brief Constructor.
44 * @param[in] ioCon - IO context.
45 * @param[in] iFace - interface to implement.
46 * @param[in] connection - Dbus Connection.
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060047 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -060048 Manager(std::shared_ptr<boost::asio::io_context>& ioCon,
49 std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace,
50 std::shared_ptr<sdbusplus::asio::connection>& conn);
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060051
52 /** @brief Implementation for WriteKeyword
53 * Api to update the keyword value for a given inventory.
54 *
55 * @param[in] path - Path to the D-Bus object that represents the FRU.
56 * @param[in] recordName - name of the record for which the keyword value
57 * has to be modified
58 * @param[in] keyword - keyword whose value needs to be updated
59 * @param[in] value - value that needs to be updated
60 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -060061 void writeKeyword(const sdbusplus::message::object_path& path,
62 const std::string& recordName, const std::string& keyword,
63 const Binary& value);
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060064
65 /** @brief Implementation for GetFRUsByUnexpandedLocationCode
66 * A method to get list of FRU D-BUS object paths for a given unexpanded
67 * location code. Returns empty vector if no FRU found for that location
68 * code.
69 *
70 * @param[in] locationCode - An un-expanded Location code.
71 * @param[in] nodeNumber - Denotes the node in case of a multi-node
72 * configuration, ignored on a single node system.
73 *
74 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
75 * List of all the FRUs D-Bus object paths for the given location code.
76 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -050077 inventory::ListOfPaths
Sunny Srivastava523af2e2022-02-14 07:30:10 -060078 getFRUsByUnexpandedLocationCode(const std::string& locationCode,
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060079 const uint16_t nodeNumber);
80
81 /** @brief Implementation for GetFRUsByExpandedLocationCode
82 * A method to get list of FRU D-BUS object paths for a given expanded
83 * location code. Returns empty vector if no FRU found for that location
84 * code.
85 *
86 * @param[in] locationCode - Location code in expanded format.
87 *
88 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
89 * List of all the FRUs D-Bus object path for the given location code.
90 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -050091 inventory::ListOfPaths
Sunny Srivastava523af2e2022-02-14 07:30:10 -060092 getFRUsByExpandedLocationCode(const std::string& locationCode);
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060093
94 /** @brief Implementation for GetExpandedLocationCode
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -050095 * An API to get expanded location code corresponding to a given
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060096 * un-expanded location code.
97 *
98 * @param[in] locationCode - Location code in un-expaned format.
99 * @param[in] nodeNumber - Denotes the node in case of multi-node
100 * configuration. Ignored in case of single node configuration.
101 *
102 * @return locationCode[std::string] - Location code in expanded format.
103 */
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600104 std::string getExpandedLocationCode(const std::string& locationCode,
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600105 const uint16_t nodeNumber);
106
SunnySrivastava19849a195542020-09-07 06:04:50 -0500107 /** @brief Api to perform VPD recollection.
108 * This api will trigger parser to perform VPD recollection for FRUs that
109 * can be replaced at standby.
110 */
111 void performVPDRecollection();
112
Sunny Srivastava28abd6e2021-07-28 02:58:28 -0500113 /** @brief Api to delete FRU VPD.
114 * This api will set the present property of given FRU to false. If already
115 * set to false, It will log an error.
116 * @param[in] path - Object path of FRU.
117 */
118 void deleteFRUVPD(const sdbusplus::message::object_path& path);
119
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600120 private:
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600121 /**
122 * @brief An api to process some initial requirements.
123 */
124 void initManager();
125
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600126 /** @brief process the given JSON file
127 */
128 void processJSON();
129
Sunny Srivastavaecb5c7d2021-09-02 07:20:24 -0500130 /** @brief Api to register host state callback.
131 * This api will register callback to listen for host state property change.
132 */
133 void listenHostState();
134
135 /** @brief Callback to listen for Host state change
136 * @param[in] msg - callback message.
137 */
Patrick Williams2eb01762022-07-22 19:26:56 -0500138 void hostStateCallBack(sdbusplus::message_t& msg);
Sunny Srivastavaecb5c7d2021-09-02 07:20:24 -0500139
Santosh Puranikb62f6052022-04-06 18:37:54 +0530140 /** @brief Api to register AssetTag property change.
141 * This api will register callback to listen for asset tag property change.
142 */
143 void listenAssetTag();
144
145 /** @brief Callback to listen for Asset tag change
146 * @param[in] msg - callback message.
147 */
Patrick Williams2eb01762022-07-22 19:26:56 -0500148 void assetTagCallback(sdbusplus::message_t& msg);
Santosh Puranikb62f6052022-04-06 18:37:54 +0530149
Santosh Puranik6b2b5372022-06-02 20:49:02 +0530150 /**
151 * @brief Restores and defaulted VPD on the system VPD EEPROM.
152 *
153 * This function will read the system VPD EEPROM and check if any of the
154 * keywords that need to be preserved across FRU replacements are defaulted
155 * in the EEPROM. If they are, this function will restore them from the
156 * value that is in the D-Bus cache.
157 */
158 void restoreSystemVpd();
159
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500160 /**
161 * @brief Check for essential fru in the system.
162 * The api check for the presence of FRUs marked as essential and logs PEL
163 * in case they are missing.
164 */
165 void checkEssentialFrus();
166
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600167 // Shared pointer to asio context object.
168 std::shared_ptr<boost::asio::io_context>& ioContext;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600169
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600170 // Shared pointer to Dbus interface class.
171 std::shared_ptr<sdbusplus::asio::dbus_interface>& interface;
172
173 // Shared pointer to bus connection.
174 std::shared_ptr<sdbusplus::asio::connection>& conn;
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600175
176 // file to store parsed json
177 nlohmann::json jsonFile;
178
179 // map to hold mapping to inventory path to vpd file path
180 // we need as map here as it is in reverse order to that of json
181 inventory::FrusMap frus;
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -0500182
183 // map to hold the mapping of location code and inventory path
184 inventory::LocationCodeMap fruLocationCode;
SunnySrivastava19849a195542020-09-07 06:04:50 -0500185
186 // map to hold FRUs which can be replaced at standby
187 inventory::ReplaceableFrus replaceableFrus;
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500188
Sunny Srivastava523af2e2022-02-14 07:30:10 -0600189 // Shared pointer to gpio monitor object.
190 std::shared_ptr<GpioMonitor> gpioMon;
191
192 // Shared pointer to instance of the BIOS handler.
193 std::shared_ptr<BiosHandler> biosHandler;
194
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500195 // List of FRUs marked as essential in the system.
196 inventory::EssentialFrus essentialFrus;
197
198 // sd-bus
199 sd_bus* sdBus = nullptr;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600200};
201
202} // namespace manager
203} // namespace vpd
204} // namespace openpower