SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 3 | #include "editor_impl.hpp" |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 4 | #include "types.hpp" |
| 5 | |
| 6 | #include <com/ibm/VPD/Manager/server.hpp> |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <nlohmann/json.hpp> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 9 | |
| 10 | namespace sdbusplus |
| 11 | { |
| 12 | namespace bus |
| 13 | { |
| 14 | class bus; |
| 15 | } |
| 16 | } // namespace sdbusplus |
| 17 | |
| 18 | namespace openpower |
| 19 | { |
| 20 | namespace vpd |
| 21 | { |
| 22 | namespace manager |
| 23 | { |
| 24 | |
| 25 | template <typename T> |
| 26 | using ServerObject = T; |
| 27 | |
| 28 | using 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 | */ |
| 36 | class 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 Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame^] | 52 | ~Manager() |
| 53 | { |
| 54 | sd_bus_unref(sdBus); |
| 55 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 56 | |
| 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 Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 63 | Manager(sdbusplus::bus_t&& bus, const char* busName, const char* objPath, |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 64 | 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 | */ |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 91 | inventory::ListOfPaths |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 92 | 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 | */ |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 105 | inventory::ListOfPaths |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 106 | getFRUsByExpandedLocationCode(const std::string locationCode); |
| 107 | |
| 108 | /** @brief Implementation for GetExpandedLocationCode |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 109 | * An API to get expanded location code corresponding to a given |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 110 | * 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 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 124 | /** @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 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 130 | private: |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 131 | /** @brief process the given JSON file |
| 132 | */ |
| 133 | void processJSON(); |
| 134 | |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 135 | /** @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 Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 143 | void hostStateCallBack(sdbusplus::message_t& msg); |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 144 | |
Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 145 | /** @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 Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 153 | void assetTagCallback(sdbusplus::message_t& msg); |
Santosh Puranik | b62f605 | 2022-04-06 18:37:54 +0530 | [diff] [blame] | 154 | |
Santosh Puranik | 6b2b537 | 2022-06-02 20:49:02 +0530 | [diff] [blame] | 155 | /** |
| 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 Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame^] | 165 | /** |
| 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 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 172 | /** @brief Persistent sdbusplus DBus bus connection. */ |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 173 | sdbusplus::bus_t _bus; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 174 | |
| 175 | /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */ |
Patrick Williams | 2eb0176 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 176 | sdbusplus::server::manager_t _manager; |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 177 | |
| 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; |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 184 | |
| 185 | // map to hold the mapping of location code and inventory path |
| 186 | inventory::LocationCodeMap fruLocationCode; |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 187 | |
| 188 | // map to hold FRUs which can be replaced at standby |
| 189 | inventory::ReplaceableFrus replaceableFrus; |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame^] | 190 | |
| 191 | // List of FRUs marked as essential in the system. |
| 192 | inventory::EssentialFrus essentialFrus; |
| 193 | |
| 194 | // sd-bus |
| 195 | sd_bus* sdBus = nullptr; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | } // namespace manager |
| 199 | } // namespace vpd |
| 200 | } // namespace openpower |