Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Jeffery | 2abbce7 | 2023-10-18 10:17:35 +1030 | [diff] [blame] | 3 | #include "common/instance_id.hpp" |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 4 | #include "common/types.hpp" |
| 5 | #include "common/utils.hpp" |
Thu Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame^] | 6 | #include "platform-mc/manager.hpp" |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 7 | #include "requester/handler.hpp" |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 8 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
| 10 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <utility> |
| 13 | #include <vector> |
| 14 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 15 | PHOSPHOR_LOG2_USING; |
| 16 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 17 | namespace pldm |
| 18 | { |
| 19 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 20 | namespace host_effecters |
| 21 | { |
| 22 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 23 | using DbusChgHostEffecterProps = |
| 24 | std::map<dbus::Property, pldm::utils::PropertyValue>; |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 25 | |
| 26 | /** @struct State |
| 27 | * Contains the state set id and the possible states for |
| 28 | * an effecter |
| 29 | */ |
| 30 | struct PossibleState |
| 31 | { |
| 32 | uint16_t stateSetId; //!< State set id |
| 33 | std::vector<uint8_t> states; //!< Possible states |
| 34 | }; |
| 35 | |
| 36 | /** @struct DBusEffecterMapping |
| 37 | * Contains the D-Bus information for an effecter |
| 38 | */ |
| 39 | struct DBusEffecterMapping |
| 40 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 41 | pldm::utils::DBusMapping dbusMap; |
| 42 | std::vector<pldm::utils::PropertyValue> |
| 43 | propertyValues; //!< D-Bus property values |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 44 | PossibleState state; //!< Corresponding effecter states |
| 45 | }; |
| 46 | |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 47 | /** @struct DBusEffecterMapping |
| 48 | * Contains the D-Bus information for an effecter |
| 49 | */ |
| 50 | struct DBusNumericEffecterMapping |
| 51 | { |
| 52 | pldm::utils::DBusMapping dbusMap; |
| 53 | uint8_t dataSize; //!< Numeric effecter PDR data size |
| 54 | double resolution; //!< Numeric effecter PDR resolution |
| 55 | double offset; //!< Numeric effecter PDR offset |
| 56 | int8_t unitModifier; //!< Numeric effecter PDR unitModifier |
| 57 | double propertyValue; //!< D-Bus property values |
| 58 | }; |
| 59 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 60 | /** @struct EffecterInfo |
| 61 | * Contains the effecter information as a whole |
| 62 | */ |
| 63 | struct EffecterInfo |
| 64 | { |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 65 | uint8_t mctpEid; //!< Host mctp eid |
Thu Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame^] | 66 | std::string terminusName; //!< Terminus name |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 67 | uint8_t effecterPdrType; //!< Effecter PDR type state/numeric |
| 68 | uint16_t containerId; //!< Container Id for host effecter |
| 69 | uint16_t entityType; //!< Entity type for the host effecter |
| 70 | uint16_t entityInstance; //!< Entity instance for the host effecter |
| 71 | uint8_t compEffecterCnt; //!< Composite effecter count |
| 72 | bool checkHostState; //!< Check host state before setting effecter |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 73 | std::vector<DBusEffecterMapping> |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 74 | dbusInfo; //!< D-Bus information for the effecter id |
| 75 | std::vector<DBusNumericEffecterMapping> |
| 76 | dbusNumericEffecterInfo; //!< D-Bus information for the effecter id |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /** @class HostEffecterParser |
| 80 | * |
| 81 | * @brief This class parses the Host Effecter json file and monitors for the |
| 82 | * D-Bus changes for the effecters. Upon change, calls the corresponding |
| 83 | * setStateEffecterStates on the host |
| 84 | */ |
| 85 | class HostEffecterParser |
| 86 | { |
| 87 | public: |
| 88 | HostEffecterParser() = delete; |
| 89 | HostEffecterParser(const HostEffecterParser&) = delete; |
| 90 | HostEffecterParser& operator=(const HostEffecterParser&) = delete; |
| 91 | HostEffecterParser(HostEffecterParser&&) = delete; |
| 92 | HostEffecterParser& operator=(HostEffecterParser&&) = delete; |
| 93 | virtual ~HostEffecterParser() = default; |
| 94 | |
| 95 | /** @brief Constructor to create a HostEffecterParser object. |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 96 | * @param[in] instanceIdDb - PLDM InstanceIdDb object pointer |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 97 | * @param[in] fd - socket fd to communicate to host |
| 98 | * @param[in] repo - PLDM PDR repository |
| 99 | * @param[in] dbusHandler - D-bus Handler |
| 100 | * @param[in] jsonPath - path for the json file |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 101 | * @param[in] handler - PLDM request handler |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 102 | */ |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 103 | explicit HostEffecterParser( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 104 | pldm::InstanceIdDb* instanceIdDb, int fd, const pldm_pdr* repo, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 105 | pldm::utils::DBusHandler* const dbusHandler, |
| 106 | const std::string& jsonPath, |
Thu Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame^] | 107 | pldm::requester::Handler<pldm::requester::Request>* handler, |
| 108 | platform_mc::Manager* platformManager) : |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 109 | instanceIdDb(instanceIdDb), sockFd(fd), pdrRepo(repo), |
Thu Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame^] | 110 | dbusHandler(dbusHandler), handler(handler), |
| 111 | platformManager(platformManager) |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 112 | { |
| 113 | try |
| 114 | { |
| 115 | parseEffecterJson(jsonPath); |
| 116 | } |
| 117 | catch (const std::exception& e) |
| 118 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 119 | error( |
Riya Dixit | d6e10ad | 2024-03-28 19:44:16 -0500 | [diff] [blame] | 120 | "The json file '{PATH}' does not exist or malformed, error - '{ERROR}'", |
| 121 | "PATH", jsonPath, "ERROR", e); |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | /* @brief Parses the host effecter json |
| 126 | * |
| 127 | * @param[in] jsonPath - path for the json file |
| 128 | */ |
| 129 | void parseEffecterJson(const std::string& jsonPath); |
| 130 | |
| 131 | /* @brief Method to take action when the subscribed D-Bus property is |
| 132 | * changed |
| 133 | * @param[in] chProperties - list of properties which have changed |
| 134 | * @param[in] effecterInfoIndex - index of effecterInfo pointer in |
| 135 | * hostEffecterInfo |
| 136 | * @param[in] dbusInfoIndex - index on dbusInfo pointer in each effecterInfo |
| 137 | * @param[in] effecterId - host effecter id |
| 138 | * @return - none |
| 139 | */ |
| 140 | void processHostEffecterChangeNotification( |
| 141 | const DbusChgHostEffecterProps& chProperties, size_t effecterInfoIndex, |
| 142 | size_t dbusInfoIndex, uint16_t effecterId); |
| 143 | |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 144 | /* @brief Method to take action when the subscribed D-Bus property is |
| 145 | * changed |
| 146 | * @param[in] chProperties - list of properties which have changed |
| 147 | * @param[in] effecterInfoIndex - index of effecterInfo pointer in |
| 148 | * hostEffecterInfo |
| 149 | * @param[in] dbusInfoIndex - index on dbusInfo pointer in each effecterInfo |
| 150 | |
| 151 | * @param[in] effecterId - terminus numeric effecter id |
| 152 | * @return - none |
| 153 | */ |
| 154 | void processTerminusNumericEffecterChangeNotification( |
| 155 | const DbusChgHostEffecterProps& chProperties, size_t effecterInfoIndex, |
| 156 | size_t dbusInfoIndex, uint16_t effecterId); |
| 157 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 158 | /* @brief Populate the property values in each dbusInfo from the json |
| 159 | * |
| 160 | * @param[in] dBusValues - json values |
| 161 | * @param[out] propertyValues - dbusInfo property values |
| 162 | * @param[in] propertyType - type of the D-Bus property |
| 163 | * @return - none |
| 164 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 165 | void populatePropVals( |
| 166 | const pldm::utils::Json& dBusValues, |
| 167 | std::vector<pldm::utils::PropertyValue>& propertyValues, |
| 168 | const std::string& propertyType); |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 169 | |
| 170 | /* @brief Set a host state effecter |
| 171 | * |
| 172 | * @param[in] effecterInfoIndex - index of effecterInfo pointer in |
| 173 | * hostEffecterInfo |
| 174 | * @param[in] stateField - vector of state fields equal to composite |
| 175 | * effecter count in number |
| 176 | * @param[in] effecterId - host effecter id |
| 177 | * @return - PLDM status code |
| 178 | */ |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 179 | virtual int setHostStateEffecter( |
| 180 | size_t effecterInfoIndex, |
| 181 | std::vector<set_effecter_state_field>& stateField, uint16_t effecterId); |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 182 | |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 183 | /* @brief Set a terminus numeric effecter |
| 184 | * |
| 185 | * @param[in] effecterInfoIndex - index of effecterInfo pointer in |
| 186 | * hostEffecterInfo |
| 187 | * @param[in] effecterId - host effecter id |
| 188 | * @param[in] dataSize - data size |
| 189 | * @param[in] rawValue - raw value |
| 190 | * @return - PLDM status code |
| 191 | */ |
| 192 | virtual int setTerminusNumericEffecter(size_t effecterInfoIndex, |
| 193 | uint16_t effecterId, |
| 194 | uint8_t dataSize, double rawValue); |
| 195 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 196 | /* @brief Fetches the new state value and the index in stateField set which |
| 197 | * needs to be set with the new value in the setStateEffecter call |
| 198 | * @param[in] effecterInfoIndex - index of effecterInfo in hostEffecterInfo |
| 199 | * @param[in] dbusInfoIndex - index of dbusInfo within effecterInfo |
| 200 | * @param[in] propertyValue - the changed D-Bus property value |
| 201 | * @return - the new state value |
| 202 | */ |
| 203 | uint8_t findNewStateValue(size_t effecterInfoIndex, size_t dbusInfoIndex, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 204 | const pldm::utils::PropertyValue& propertyValue); |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 205 | |
| 206 | /* @brief Subscribes for D-Bus property change signal on the specified |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 207 | * object |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 208 | * |
| 209 | * @param[in] objectPath - D-Bus object path to look for |
| 210 | * @param[in] interface - D-Bus interface |
| 211 | * @param[in] effecterInfoIndex - index of effecterInfo pointer in |
| 212 | * hostEffecterInfo |
| 213 | * @param[in] dbusInfoIndex - index of dbusInfo within effecterInfo |
| 214 | * @param[in] effecterId - host effecter id |
| 215 | */ |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 216 | virtual void createHostEffecterMatch( |
| 217 | const std::string& objectPath, const std::string& interface, |
| 218 | size_t effecterInfoIndex, size_t dbusInfoIndex, uint16_t effecterId); |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 219 | |
Manojkiran Eda | 04ac997 | 2024-09-06 10:57:12 +0530 | [diff] [blame] | 220 | /* @brief Adjust the numeric effecter value base on the effecter |
Thu Nguyen | a34a64b | 2022-03-31 08:56:39 +0700 | [diff] [blame] | 221 | * configurations |
| 222 | * |
| 223 | * @param[in] value - Raw value |
| 224 | * @param[in] offset - offset config |
| 225 | * @param[in] resolution - resolution config |
| 226 | * @param[in] modify - modify config |
| 227 | * |
| 228 | * @return - Value of effecter |
| 229 | */ |
| 230 | double adjustValue(double value, double offset, double resolution, |
| 231 | int8_t modify); |
| 232 | |
| 233 | private: |
| 234 | /* @brief Verify host On state before configure the host effecters |
| 235 | * |
| 236 | * @return - true if host is on and false for others cases |
| 237 | */ |
| 238 | bool isHostOn(void); |
| 239 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 240 | protected: |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 241 | pldm::InstanceIdDb* instanceIdDb; //!< Reference to the InstanceIdDb object |
| 242 | //!< to obtain instance id |
| 243 | int sockFd; //!< Socket fd to send message to host |
| 244 | const pldm_pdr* pdrRepo; //!< Reference to PDR repo |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 245 | std::vector<EffecterInfo> hostEffecterInfo; //!< Parsed effecter information |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 246 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 247 | effecterInfoMatch; //!< vector to catch the D-Bus property change |
| 248 | //!< signals for the effecters |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 249 | const pldm::utils::DBusHandler* dbusHandler; //!< D-bus Handler |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 250 | /** @brief PLDM request handler */ |
| 251 | pldm::requester::Handler<pldm::requester::Request>* handler; |
Thu Nguyen | 38e12aa | 2025-01-21 22:47:56 +0000 | [diff] [blame^] | 252 | |
| 253 | /** @brief MC Platform manager*/ |
| 254 | platform_mc::Manager* platformManager = nullptr; |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | } // namespace host_effecters |
| 258 | } // namespace pldm |