blob: 4992801141731df556d4099e56b6732892750848 [file] [log] [blame]
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06001#pragma once
2
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -06003#include "editor_impl.hpp"
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06004#include "types.hpp"
5
6#include <com/ibm/VPD/Manager/server.hpp>
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -06007#include <map>
8#include <nlohmann/json.hpp>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06009
10namespace sdbusplus
11{
12namespace bus
13{
14class bus;
15}
16} // namespace sdbusplus
17
18namespace openpower
19{
20namespace vpd
21{
22namespace manager
23{
24
25template <typename T>
26using ServerObject = T;
27
28using ManagerIface = sdbusplus::com::ibm::VPD::server::Manager;
29
30/** @class Manager
31 * @brief OpenBMC VPD Manager implementation.
32 *
33 * A concrete implementation for the
34 * com.ibm.vpd.Manager
35 */
36class Manager : public ServerObject<ManagerIface>
37{
38 public:
39 /* Define all of the basic class operations:
40 * Not allowed:
41 * - Default constructor to avoid nullptrs.
42 * - Copy operations due to internal unique_ptr.
43 * - Move operations due to 'this' being registered as the
44 * 'context' with sdbus.
45 * Allowed:
46 * - Destructor.
47 */
48 Manager() = delete;
49 Manager(const Manager&) = delete;
50 Manager& operator=(const Manager&) = delete;
51 Manager(Manager&&) = delete;
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -050052 ~Manager()
53 {
54 sd_bus_unref(sdBus);
55 }
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060056
57 /** @brief Constructor to put object onto bus at a dbus path.
58 * @param[in] bus - Bus connection.
59 * @param[in] busName - Name to be requested on Bus
60 * @param[in] objPath - Path to attach at.
61 * @param[in] iFace - interface to implement
62 */
Patrick Williams2eb01762022-07-22 19:26:56 -050063 Manager(sdbusplus::bus_t&& bus, const char* busName, const char* objPath,
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060064 const char* iFace);
65
66 /** @brief Implementation for WriteKeyword
67 * Api to update the keyword value for a given inventory.
68 *
69 * @param[in] path - Path to the D-Bus object that represents the FRU.
70 * @param[in] recordName - name of the record for which the keyword value
71 * has to be modified
72 * @param[in] keyword - keyword whose value needs to be updated
73 * @param[in] value - value that needs to be updated
74 */
75 void writeKeyword(const sdbusplus::message::object_path path,
76 const std::string recordName, const std::string keyword,
77 const Binary value);
78
79 /** @brief Implementation for GetFRUsByUnexpandedLocationCode
80 * A method to get list of FRU D-BUS object paths for a given unexpanded
81 * location code. Returns empty vector if no FRU found for that location
82 * code.
83 *
84 * @param[in] locationCode - An un-expanded Location code.
85 * @param[in] nodeNumber - Denotes the node in case of a multi-node
86 * configuration, ignored on a single node system.
87 *
88 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
89 * List of all the FRUs D-Bus object paths for the given location code.
90 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -050091 inventory::ListOfPaths
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060092 getFRUsByUnexpandedLocationCode(const std::string locationCode,
93 const uint16_t nodeNumber);
94
95 /** @brief Implementation for GetFRUsByExpandedLocationCode
96 * A method to get list of FRU D-BUS object paths for a given expanded
97 * location code. Returns empty vector if no FRU found for that location
98 * code.
99 *
100 * @param[in] locationCode - Location code in expanded format.
101 *
102 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
103 * List of all the FRUs D-Bus object path for the given location code.
104 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -0500105 inventory::ListOfPaths
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600106 getFRUsByExpandedLocationCode(const std::string locationCode);
107
108 /** @brief Implementation for GetExpandedLocationCode
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -0500109 * An API to get expanded location code corresponding to a given
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600110 * un-expanded location code.
111 *
112 * @param[in] locationCode - Location code in un-expaned format.
113 * @param[in] nodeNumber - Denotes the node in case of multi-node
114 * configuration. Ignored in case of single node configuration.
115 *
116 * @return locationCode[std::string] - Location code in expanded format.
117 */
118 std::string getExpandedLocationCode(const std::string locationCode,
119 const uint16_t nodeNumber);
120
121 /** @brief Start processing DBus messages. */
122 void run();
123
SunnySrivastava19849a195542020-09-07 06:04:50 -0500124 /** @brief Api to perform VPD recollection.
125 * This api will trigger parser to perform VPD recollection for FRUs that
126 * can be replaced at standby.
127 */
128 void performVPDRecollection();
129
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600130 private:
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600131 /** @brief process the given JSON file
132 */
133 void processJSON();
134
Sunny Srivastavaecb5c7d2021-09-02 07:20:24 -0500135 /** @brief Api to register host state callback.
136 * This api will register callback to listen for host state property change.
137 */
138 void listenHostState();
139
140 /** @brief Callback to listen for Host state change
141 * @param[in] msg - callback message.
142 */
Patrick Williams2eb01762022-07-22 19:26:56 -0500143 void hostStateCallBack(sdbusplus::message_t& msg);
Sunny Srivastavaecb5c7d2021-09-02 07:20:24 -0500144
Santosh Puranikb62f6052022-04-06 18:37:54 +0530145 /** @brief Api to register AssetTag property change.
146 * This api will register callback to listen for asset tag property change.
147 */
148 void listenAssetTag();
149
150 /** @brief Callback to listen for Asset tag change
151 * @param[in] msg - callback message.
152 */
Patrick Williams2eb01762022-07-22 19:26:56 -0500153 void assetTagCallback(sdbusplus::message_t& msg);
Santosh Puranikb62f6052022-04-06 18:37:54 +0530154
Santosh Puranik6b2b5372022-06-02 20:49:02 +0530155 /**
156 * @brief Restores and defaulted VPD on the system VPD EEPROM.
157 *
158 * This function will read the system VPD EEPROM and check if any of the
159 * keywords that need to be preserved across FRU replacements are defaulted
160 * in the EEPROM. If they are, this function will restore them from the
161 * value that is in the D-Bus cache.
162 */
163 void restoreSystemVpd();
164
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500165 /**
166 * @brief Check for essential fru in the system.
167 * The api check for the presence of FRUs marked as essential and logs PEL
168 * in case they are missing.
169 */
170 void checkEssentialFrus();
171
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600172 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williams2eb01762022-07-22 19:26:56 -0500173 sdbusplus::bus_t _bus;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600174
175 /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */
Patrick Williams2eb01762022-07-22 19:26:56 -0500176 sdbusplus::server::manager_t _manager;
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600177
178 // file to store parsed json
179 nlohmann::json jsonFile;
180
181 // map to hold mapping to inventory path to vpd file path
182 // we need as map here as it is in reverse order to that of json
183 inventory::FrusMap frus;
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -0500184
185 // map to hold the mapping of location code and inventory path
186 inventory::LocationCodeMap fruLocationCode;
SunnySrivastava19849a195542020-09-07 06:04:50 -0500187
188 // map to hold FRUs which can be replaced at standby
189 inventory::ReplaceableFrus replaceableFrus;
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500190
191 // List of FRUs marked as essential in the system.
192 inventory::EssentialFrus essentialFrus;
193
194 // sd-bus
195 sd_bus* sdBus = nullptr;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600196};
197
198} // namespace manager
199} // namespace vpd
200} // namespace openpower