1 #pragma once 2 3 #include "backup_restore.hpp" 4 #include "constants.hpp" 5 #include "gpio_monitor.hpp" 6 #include "types.hpp" 7 #include "worker.hpp" 8 9 #include <oem-handler/ibm_handler.hpp> 10 #include <sdbusplus/asio/object_server.hpp> 11 12 namespace vpd 13 { 14 /** 15 * @brief Class to manage VPD processing. 16 * 17 * The class is responsible to implement methods to manage VPD on the system. 18 * It also implements methods to be exposed over D-Bus required to access/edit 19 * VPD data. 20 */ 21 class Manager 22 { 23 public: 24 /** 25 * List of deleted methods. 26 */ 27 Manager(const Manager&) = delete; 28 Manager& operator=(const Manager&) = delete; 29 Manager(Manager&&) = delete; 30 31 /** 32 * @brief Constructor. 33 * 34 * @param[in] ioCon - IO context. 35 * @param[in] iFace - interface to implement. 36 * @param[in] progressiFace - Interface to track collection progress. 37 * @param[in] connection - Dbus Connection. 38 */ 39 Manager( 40 const std::shared_ptr<boost::asio::io_context>& ioCon, 41 const std::shared_ptr<sdbusplus::asio::dbus_interface>& iFace, 42 const std::shared_ptr<sdbusplus::asio::dbus_interface>& progressiFace, 43 const std::shared_ptr<sdbusplus::asio::connection>& asioConnection); 44 45 /** 46 * @brief Destructor. 47 */ 48 ~Manager() = default; 49 50 /** 51 * @brief Update keyword value. 52 * 53 * This API is used to update keyword value on the given input path and its 54 * redundant path(s) if any taken from system config JSON. 55 * 56 * To update IPZ type VPD, input parameter for writing should be in the form 57 * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}). 58 * 59 * To update Keyword type VPD, input parameter for writing should be in the 60 * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}). 61 * 62 * @param[in] i_vpdPath - Path (inventory object path/FRU EEPROM path). 63 * @param[in] i_paramsToWriteData - Input details. 64 * 65 * @return On success returns number of bytes written, on failure returns 66 * -1. 67 */ 68 int updateKeyword(const types::Path i_vpdPath, 69 const types::WriteVpdParams i_paramsToWriteData); 70 71 /** 72 * @brief Update keyword value on hardware. 73 * 74 * This API is used to update keyword value on hardware. Updates only on the 75 * given input hardware path, does not look for corresponding redundant or 76 * primary path against the given path. To update corresponding paths, make 77 * separate call with respective path. 78 * 79 * To update IPZ type VPD, input parameter for writing should be in the form 80 * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}). 81 * 82 * To update Keyword type VPD, input parameter for writing should be in the 83 * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}). 84 * 85 * @param[in] i_fruPath - EEPROM path of the FRU. 86 * @param[in] i_paramsToWriteData - Input details. 87 * 88 * @return On success returns number of bytes written, on failure returns 89 * -1. 90 */ 91 int updateKeywordOnHardware( 92 const types::Path i_fruPath, 93 const types::WriteVpdParams i_paramsToWriteData) noexcept; 94 95 /** 96 * @brief Read keyword value. 97 * 98 * API can be used to read VPD keyword from the given input path. 99 * 100 * To read keyword of type IPZ, input parameter for reading should be in the 101 * form of (Record, Keyword). Eg: ("VINI", "SN"). 102 * 103 * To read keyword from keyword type VPD, just keyword name has to be 104 * supplied in the input parameter. Eg: ("SN"). 105 * 106 * @param[in] i_fruPath - EEPROM path. 107 * @param[in] i_paramsToReadData - Input details. 108 * 109 * @throw 110 * sdbusplus::xyz::openbmc_project::Common::Device::Error::ReadFailure. 111 * 112 * @return On success returns the read value in variant of array of bytes. 113 * On failure throws exception. 114 */ 115 types::DbusVariantType readKeyword( 116 const types::Path i_fruPath, 117 const types::ReadVpdParams i_paramsToReadData); 118 119 /** 120 * @brief Collect single FRU VPD 121 * API can be used to perform VPD collection for the given FRU, only if the 122 * current state of the system matches with the state at which the FRU is 123 * allowed for VPD recollection. 124 * 125 * @param[in] i_dbusObjPath - D-bus object path 126 */ 127 void collectSingleFruVpd( 128 const sdbusplus::message::object_path& i_dbusObjPath); 129 130 /** 131 * @brief Delete single FRU VPD 132 * API can be used to perform VPD deletion for the given FRU. 133 * 134 * @param[in] i_dbusObjPath - D-bus object path 135 */ 136 void deleteSingleFruVpd( 137 const sdbusplus::message::object_path& i_dbusObjPath); 138 139 /** 140 * @brief Get expanded location code. 141 * 142 * API to get expanded location code from the unexpanded location code. 143 * 144 * @param[in] i_unexpandedLocationCode - Unexpanded location code. 145 * @param[in] i_nodeNumber - Denotes the node in case of a multi-node 146 * configuration, defaulted to zero incase of single node system. 147 * 148 * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 149 * invalid argument. 150 * 151 * @return Location code of the FRU. 152 */ 153 std::string getExpandedLocationCode( 154 const std::string& i_unexpandedLocationCode, 155 [[maybe_unused]] const uint16_t i_nodeNumber = 0); 156 157 /** 158 * @brief Get D-Bus object path of FRUs from expanded location code. 159 * 160 * An API to get list of FRU D-Bus object paths for a given expanded 161 * location code. 162 * 163 * @param[in] i_expandedLocationCode - Expanded location code. 164 * 165 * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 166 * invalid argument. 167 * 168 * @return List of FRUs D-Bus object paths for the given location code. 169 */ 170 types::ListOfPaths getFrusByExpandedLocationCode( 171 const std::string& i_expandedLocationCode); 172 173 /** 174 * @brief Get D-Bus object path of FRUs from unexpanded location code. 175 * 176 * An API to get list of FRU D-Bus object paths for a given unexpanded 177 * location code. 178 * 179 * @param[in] i_unexpandedLocationCode - Unexpanded location code. 180 * @param[in] i_nodeNumber - Denotes the node in case of a multi-node 181 * configuration, defaulted to zero incase of single node system. 182 * 183 * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 184 * invalid argument. 185 * 186 * @return List of FRUs D-Bus object paths for the given location code. 187 */ 188 types::ListOfPaths getFrusByUnexpandedLocationCode( 189 const std::string& i_unexpandedLocationCode, 190 [[maybe_unused]] const uint16_t i_nodeNumber = 0); 191 192 /** 193 * @brief Get Hardware path 194 * API can be used to get EEPROM path for the given inventory path. 195 * 196 * @param[in] i_dbusObjPath - D-bus object path 197 * 198 * @return Corresponding EEPROM path. 199 */ 200 std::string getHwPath(const sdbusplus::message::object_path& i_dbusObjPath); 201 202 /** 203 * @brief Perform VPD recollection 204 * This api will trigger parser to perform VPD recollection for FRUs that 205 * can be replaced at standby. 206 */ 207 void performVpdRecollection(); 208 209 /** 210 * @brief Get unexpanded location code. 211 * 212 * An API to get unexpanded location code and node number from expanded 213 * location code. 214 * 215 * @param[in] i_expandedLocationCode - Expanded location code. 216 * 217 * @throw xyz.openbmc_project.Common.Error.InvalidArgument for 218 * invalid argument. 219 * 220 * @return Location code in unexpanded format and its node number. 221 */ 222 std::tuple<std::string, uint16_t> getUnexpandedLocationCode( 223 const std::string& i_expandedLocationCode); 224 225 /** 226 * @brief API to collect all FRUs VPD. 227 * 228 * This api will call OEM handler API to perform VPD collection for all FRUs 229 * present in the system config JSON. 230 * 231 * Note: 232 * System VPD collection will always be skipped. 233 * If host is in power on state, FRUs marked as 'powerOffOnly' in the 234 * system config JSON will be skipped. 235 * 236 * @return true on successful request made, false otherwise. 237 */ 238 bool collectAllFruVpd() const noexcept; 239 240 private: 241 /** 242 * @brief An api to check validity of unexpanded location code. 243 * 244 * @param[in] i_locationCode - Unexpanded location code. 245 * 246 * @return True/False based on validity check. 247 */ 248 bool isValidUnexpandedLocationCode(const std::string& i_locationCode); 249 250 // Shared pointer to asio context object. 251 const std::shared_ptr<boost::asio::io_context>& m_ioContext; 252 253 // Shared pointer to Dbus interface class. 254 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface; 255 256 // Shared pointer to collection progress interface class. 257 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface; 258 259 // Shared pointer to bus connection. 260 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection; 261 262 // Shared pointer to worker class 263 std::shared_ptr<Worker> m_worker; 264 265 // Shared pointer to GpioMonitor class 266 std::shared_ptr<GpioMonitor> m_gpioMonitor; 267 268 // Variable to hold current collection status 269 std::string m_vpdCollectionStatus{constants::vpdCollectionNotStarted}; 270 271 // Shared pointer to backup and restore class 272 std::shared_ptr<BackupAndRestore> m_backupAndRestoreObj; 273 274 // Shared pointer to oem specific class. 275 std::shared_ptr<IbmHandler> m_ibmHandler; 276 }; 277 278 } // namespace vpd 279