SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 3 | #include "bios_handler.hpp" |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 4 | #include "editor_impl.hpp" |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 5 | #include "gpioMonitor.hpp" |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 6 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 7 | #include <sdbusplus/asio/object_server.hpp> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 8 | |
Patrick Williams | c78d887 | 2023-05-10 07:50:56 -0500 | [diff] [blame] | 9 | #include <map> |
| 10 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 11 | namespace openpower |
| 12 | { |
| 13 | namespace vpd |
| 14 | { |
| 15 | namespace manager |
| 16 | { |
| 17 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 18 | /** @class Manager |
| 19 | * @brief OpenBMC VPD Manager implementation. |
| 20 | * |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 21 | * Implements methods under interface com.ibm.vpd.Manager. |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 22 | */ |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 23 | class Manager |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 24 | { |
| 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 Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 39 | ~Manager() |
| 40 | { |
| 41 | sd_bus_unref(sdBus); |
| 42 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 43 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 44 | /** @brief Constructor. |
| 45 | * @param[in] ioCon - IO context. |
| 46 | * @param[in] iFace - interface to implement. |
| 47 | * @param[in] connection - Dbus Connection. |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 48 | */ |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 49 | 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); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 52 | |
| 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 Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 62 | void writeKeyword(const sdbusplus::message::object_path& path, |
| 63 | const std::string& recordName, const std::string& keyword, |
| 64 | const Binary& value); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 65 | |
| 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 | */ |
Patrick Williams | 08dc31c | 2024-08-16 15:21:06 -0400 | [diff] [blame] | 78 | inventory::ListOfPaths getFRUsByUnexpandedLocationCode( |
| 79 | const std::string& locationCode, const uint16_t nodeNumber); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 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 | */ |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 91 | inventory::ListOfPaths |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 92 | getFRUsByExpandedLocationCode(const std::string& locationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 93 | |
| 94 | /** @brief Implementation for GetExpandedLocationCode |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 95 | * An API to get expanded location code corresponding to a given |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 96 | * 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 Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 104 | std::string getExpandedLocationCode(const std::string& locationCode, |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 105 | const uint16_t nodeNumber); |
| 106 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 107 | /** @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 Srivastava | 28abd6e | 2021-07-28 02:58:28 -0500 | [diff] [blame] | 113 | /** @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 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 120 | /** @brief Api to perform VPD collection for a single fru. |
| 121 | * @param[in] path - Dbus object path of that fru. |
| 122 | */ |
| 123 | void collectFRUVPD(const sdbusplus::message::object_path& path); |
| 124 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 125 | private: |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 126 | /** |
| 127 | * @brief An api to process some initial requirements. |
| 128 | */ |
| 129 | void initManager(); |
| 130 | |
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 | /** |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 166 | * @brief An api to trigger vpd collection for a fru by bind/unbind of |
| 167 | * driver. |
| 168 | * @param[in] singleFru - Json of a single fru inder a given EEPROM path. |
| 169 | * @param[in] path - Inventory path. |
| 170 | */ |
| 171 | void triggerVpdCollection(const nlohmann::json& singleFru, |
| 172 | const std::string& path); |
| 173 | |
Sunny Srivastava | 8377086 | 2023-10-31 12:57:20 -0500 | [diff] [blame] | 174 | /** @brief Update FRU that back up system VPD. |
| 175 | * |
| 176 | * The API checks if the FRU being updated is system FRU and the record |
| 177 | * keyword pair being updated is the one that needs to be backed up and |
| 178 | * updates the back up FRU accordingly. |
| 179 | * |
| 180 | * @param[in] recordName - name of the record. |
| 181 | * @param[in] keyword - keyword whose value needs to be updated. |
| 182 | * @param[in] value - value that needs to be updated. |
| 183 | */ |
| 184 | void updateSystemVPDBackUpFRU(const std::string& recordName, |
| 185 | const std::string& keyword, |
| 186 | const Binary& value); |
| 187 | |
Sunny Srivastava | 6a1bd39 | 2021-06-02 04:39:24 -0500 | [diff] [blame] | 188 | /** |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 189 | * @brief Check for essential fru in the system. |
| 190 | * The api check for the presence of FRUs marked as essential and logs PEL |
| 191 | * in case they are missing. |
| 192 | */ |
| 193 | void checkEssentialFrus(); |
| 194 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 195 | // Shared pointer to asio context object. |
| 196 | std::shared_ptr<boost::asio::io_context>& ioContext; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 197 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 198 | // Shared pointer to Dbus interface class. |
| 199 | std::shared_ptr<sdbusplus::asio::dbus_interface>& interface; |
| 200 | |
| 201 | // Shared pointer to bus connection. |
| 202 | std::shared_ptr<sdbusplus::asio::connection>& conn; |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 203 | |
| 204 | // file to store parsed json |
| 205 | nlohmann::json jsonFile; |
| 206 | |
| 207 | // map to hold mapping to inventory path to vpd file path |
| 208 | // we need as map here as it is in reverse order to that of json |
| 209 | inventory::FrusMap frus; |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 210 | |
| 211 | // map to hold the mapping of location code and inventory path |
| 212 | inventory::LocationCodeMap fruLocationCode; |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 213 | |
| 214 | // map to hold FRUs which can be replaced at standby |
| 215 | inventory::ReplaceableFrus replaceableFrus; |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 216 | |
Sunny Srivastava | 523af2e | 2022-02-14 07:30:10 -0600 | [diff] [blame] | 217 | // Shared pointer to gpio monitor object. |
| 218 | std::shared_ptr<GpioMonitor> gpioMon; |
| 219 | |
| 220 | // Shared pointer to instance of the BIOS handler. |
| 221 | std::shared_ptr<BiosHandler> biosHandler; |
| 222 | |
Sunny Srivastava | fdf9ff2 | 2022-06-15 11:15:54 -0500 | [diff] [blame] | 223 | // List of FRUs marked as essential in the system. |
| 224 | inventory::EssentialFrus essentialFrus; |
| 225 | |
| 226 | // sd-bus |
| 227 | sd_bus* sdBus = nullptr; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | } // namespace manager |
| 231 | } // namespace vpd |
| 232 | } // namespace openpower |