Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
George Liu | bddcf85 | 2021-09-08 08:46:22 +0800 | [diff] [blame] | 5 | #ifdef POWER10 |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 6 | #include "occ_command.hpp" |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 7 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 8 | #include <cereal/archives/json.hpp> |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 9 | #include <cereal/cereal.hpp> |
| 10 | #include <cereal/types/string.hpp> |
| 11 | #include <cereal/types/tuple.hpp> |
| 12 | #include <cereal/types/vector.hpp> |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 13 | #include <sdbusplus/bus.hpp> |
| 14 | #include <sdbusplus/bus/match.hpp> |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 15 | #include <xyz/openbmc_project/Control/Power/IdlePowerSaver/server.hpp> |
| 16 | #include <xyz/openbmc_project/Control/Power/Mode/server.hpp> |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 17 | |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 18 | #include <filesystem> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 19 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 20 | namespace open_power |
| 21 | { |
| 22 | namespace occ |
| 23 | { |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 24 | |
| 25 | class Manager; |
| 26 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 27 | namespace powermode |
| 28 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 29 | namespace Base = sdbusplus::xyz::openbmc_project::Control::Power::server; |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 30 | using ModeInterface = sdbusplus::server::object_t<Base::Mode>; |
| 31 | using IpsInterface = sdbusplus::server::object_t<Base::IdlePowerSaver>; |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 32 | using namespace std::literals::string_literals; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 33 | |
| 34 | constexpr auto PMODE_PATH = "/xyz/openbmc_project/control/host0/power_mode"; |
| 35 | constexpr auto PMODE_INTERFACE = "xyz.openbmc_project.Control.Power.Mode"; |
| 36 | constexpr auto POWER_MODE_PROP = "PowerMode"; |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 37 | constexpr auto POWER_SAFE_MODE_PROP = "SafeMode"; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 38 | |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 39 | constexpr auto PIPS_PATH = "/xyz/openbmc_project/control/host0/power_ips"; |
| 40 | constexpr auto PIPS_INTERFACE = |
| 41 | "xyz.openbmc_project.Control.Power.IdlePowerSaver"; |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 42 | constexpr auto IPS_ACTIVE_PROP = "Active"; |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 43 | constexpr auto IPS_ENABLED_PROP = "Enabled"; |
| 44 | constexpr auto IPS_ENTER_UTIL = "EnterUtilizationPercent"; |
| 45 | constexpr auto IPS_ENTER_TIME = "EnterDwellTime"; |
| 46 | constexpr auto IPS_EXIT_UTIL = "ExitUtilizationPercent"; |
| 47 | constexpr auto IPS_EXIT_TIME = "ExitDwellTime"; |
| 48 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 49 | const auto PMODE_DEFAULT_INTERFACE = |
| 50 | "xyz.openbmc_project.Configuration.PowerModeProperties"s; |
| 51 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 52 | /** @brief Query the current Hypervisor target |
| 53 | * @return true if the current Hypervisor target is PowerVM |
| 54 | */ |
| 55 | bool isPowerVM(); |
| 56 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 57 | /** @brief Convert power mode string to OCC SysPwrMode value |
| 58 | * |
| 59 | * @param[in] i_modeString - power mode string |
| 60 | * |
| 61 | * @return SysPwrMode or SysPwrMode::NO_CHANGE if not found |
| 62 | */ |
| 63 | SysPwrMode convertStringToMode(const std::string& i_modeString); |
| 64 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 65 | struct PowerModeData |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 66 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 67 | bool modeInitialized = false; |
| 68 | SysPwrMode mode = SysPwrMode::NO_CHANGE; |
| 69 | uint16_t oemModeData = 0x0000; |
| 70 | bool ipsInitialized = false; |
| 71 | bool ipsEnabled = true; |
| 72 | uint8_t ipsEnterUtil = 0; |
| 73 | uint16_t ipsEnterTime = 0; |
| 74 | uint8_t ipsExitUtil = 0; |
| 75 | uint16_t ipsExitTime = 0; |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 76 | bool modeLocked = false; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 77 | |
| 78 | /** @brief Function specifying data to archive for cereal. |
| 79 | */ |
| 80 | template <class Archive> |
| 81 | void serialize(Archive& archive) |
| 82 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 83 | archive(modeInitialized, mode, oemModeData, ipsInitialized, ipsEnabled, |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 84 | ipsEnterUtil, ipsEnterTime, ipsExitUtil, ipsExitTime, |
| 85 | modeLocked); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 86 | } |
| 87 | }; |
| 88 | |
| 89 | /** @class OccPersistData |
| 90 | * @brief Provides persistent container to store data for OCC |
| 91 | * |
| 92 | * Data is stored via cereal |
| 93 | */ |
| 94 | class OccPersistData |
| 95 | { |
| 96 | public: |
| 97 | ~OccPersistData() = default; |
| 98 | OccPersistData(const OccPersistData&) = default; |
| 99 | OccPersistData& operator=(const OccPersistData&) = default; |
| 100 | OccPersistData(OccPersistData&&) = default; |
| 101 | OccPersistData& operator=(OccPersistData&&) = default; |
| 102 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 103 | /** @brief Loads any saved power mode data */ |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 104 | OccPersistData() |
| 105 | { |
| 106 | load(); |
| 107 | } |
| 108 | |
| 109 | /** @brief Save Power Mode data to persistent file |
| 110 | * |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 111 | * @param[in] newMode - desired System Power Mode |
| 112 | * @param[in] oemModeData - data required by some OEM Power Modes |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 113 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 114 | void updateMode(const SysPwrMode newMode, const uint16_t oemModeData) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 115 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 116 | modeData.mode = newMode; |
| 117 | modeData.oemModeData = oemModeData; |
| 118 | modeData.modeInitialized = true; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 119 | save(); |
| 120 | } |
| 121 | |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 122 | /** @brief Save Power Mode Lock value to persistent file |
| 123 | * |
| 124 | * @param[in] modeLock - desired System Power Mode Lock |
| 125 | */ |
| 126 | void updateModeLock(const bool modeLock) |
| 127 | { |
| 128 | modeData.modeLocked = modeLock; |
| 129 | save(); |
| 130 | } |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 131 | /** @brief Write Idle Power Saver parameters to persistent file |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 132 | * |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 133 | * @param[in] enabled - Idle Power Save status (true = enabled) |
| 134 | * @param[in] enterUtil - IPS Enter Utilization (%) |
| 135 | * @param[in] enterTime - IPS Enter Time (seconds) |
| 136 | * @param[in] exitUtil - IPS Exit Utilization (%) |
| 137 | * @param[in] exitTime - IPS Exit Time (seconds) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 138 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 139 | void updateIPS(const bool enabled, const uint8_t enterUtil, |
| 140 | const uint16_t enterTime, const uint8_t exitUtil, |
| 141 | const uint16_t exitTime) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 142 | { |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 143 | modeData.ipsEnabled = enabled; |
| 144 | modeData.ipsEnterUtil = enterUtil; |
| 145 | modeData.ipsEnterTime = enterTime; |
| 146 | modeData.ipsExitUtil = exitUtil; |
| 147 | modeData.ipsExitTime = exitTime; |
| 148 | modeData.ipsInitialized = true; |
| 149 | save(); |
| 150 | } |
| 151 | |
| 152 | /** @brief Return the Power Mode and mode data |
| 153 | * |
| 154 | * @param[out] mode - current system power mode |
| 155 | * @param[out] oemModeData - frequency data for some OEM mode |
| 156 | * |
| 157 | * @returns true if mode was available |
| 158 | */ |
| 159 | bool getMode(SysPwrMode& mode, uint16_t& oemModeData) const |
| 160 | { |
| 161 | if (!modeData.modeInitialized) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 162 | { |
| 163 | return false; |
| 164 | } |
| 165 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 166 | mode = modeData.mode; |
| 167 | oemModeData = modeData.oemModeData; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 168 | return true; |
| 169 | } |
| 170 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 171 | /** @brief Get the Idle Power Saver properties from DBus |
| 172 | * |
| 173 | * @param[out] enabled - Idle Power Save status (true = enabled) |
| 174 | * @param[out] enterUtil - IPS Enter Utilization (%) |
| 175 | * @param[out] enterTime - IPS Enter Time (seconds) |
| 176 | * @param[out] exitUtil - IPS Exit Utilization (%) |
| 177 | * @param[out] exitTime - IPS Exit Time (seconds) |
| 178 | * |
| 179 | * @return true if parameters were read successfully |
| 180 | */ |
| 181 | bool getIPS(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, |
| 182 | uint8_t& exitUtil, uint16_t& exitTime) |
| 183 | { |
| 184 | if (!modeData.ipsInitialized) |
| 185 | { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | enabled = modeData.ipsEnabled; |
| 190 | enterUtil = modeData.ipsEnterUtil; |
| 191 | enterTime = modeData.ipsEnterTime; |
| 192 | exitUtil = modeData.ipsExitUtil; |
| 193 | exitTime = modeData.ipsExitTime; |
| 194 | return true; |
| 195 | } |
| 196 | |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 197 | /** @brief Return persisted mode lock */ |
| 198 | bool getModeLock() |
| 199 | { |
| 200 | return modeData.modeLocked; |
| 201 | } |
| 202 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 203 | /** @brief Return true if the power mode is available */ |
| 204 | bool modeAvailable() |
| 205 | { |
| 206 | return (modeData.modeInitialized); |
| 207 | } |
| 208 | |
Chris Cain | cde7bea | 2022-01-28 15:54:24 -0600 | [diff] [blame] | 209 | /** @brief Return true if the IPS data is available */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 210 | bool ipsAvailable() |
| 211 | { |
| 212 | return (modeData.ipsInitialized); |
| 213 | } |
| 214 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 215 | /** @brief Saves the Power Mode data in the filesystem using cereal. */ |
| 216 | void save(); |
| 217 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 218 | /** @brief Trace the Power Mode and IPS parameters. */ |
| 219 | void print(); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 220 | |
| 221 | private: |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 222 | /** @brief Power Mode data filename to store persistent data */ |
| 223 | static constexpr auto powerModeFilename = "powerModeData"; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 224 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 225 | /** @brief Power Mode data object to be persisted */ |
| 226 | PowerModeData modeData; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 227 | |
| 228 | /** @brief Loads the OEM mode data in the filesystem using cereal. */ |
| 229 | void load(); |
| 230 | }; |
| 231 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 232 | /** @class PowerMode |
| 233 | * @brief Monitors for changes to the power mode and notifies occ |
| 234 | * |
| 235 | * The customer power mode is provided to the OCC by host TMGT when the occ |
| 236 | * first goes active or is reset. This code is responsible for sending |
| 237 | * the power mode to the OCC if the mode is changed while the occ is active. |
| 238 | */ |
| 239 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 240 | class PowerMode : public ModeInterface, public IpsInterface |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 241 | { |
| 242 | public: |
| 243 | /** @brief PowerMode object to inform occ of changes to mode |
| 244 | * |
| 245 | * This object will monitor for changes to the power mode setting. |
| 246 | * If a change is detected, and the occ is active, then this object will |
| 247 | * notify the OCC of the change. |
| 248 | * |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 249 | * @param[in] managerRef - manager object reference |
| 250 | * @param[in] modePath - Power Mode dbus path |
| 251 | * @param[in] ipsPath - Idle Power Saver dbus path |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 252 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 253 | explicit PowerMode(const Manager& managerRef, const char* modePath, |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 254 | const char* ipsPath |
| 255 | #ifdef POWER10 |
| 256 | , |
| 257 | EventPtr& event |
| 258 | #endif |
| 259 | ) : |
Andrew Geissler | cdaf998 | 2022-04-21 11:57:20 -0400 | [diff] [blame] | 260 | ModeInterface(utils::getBus(), modePath, |
| 261 | ModeInterface::action::emit_no_signals), |
| 262 | IpsInterface(utils::getBus(), ipsPath, |
| 263 | IpsInterface::action::emit_no_signals), |
| 264 | manager(managerRef), |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 265 | pmodeMatch(utils::getBus(), |
| 266 | sdbusplus::bus::match::rules::propertiesChanged( |
| 267 | PMODE_PATH, PMODE_INTERFACE), |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 268 | [this](auto& msg) { this->modeChanged(msg); }), |
| 269 | ipsMatch(utils::getBus(), |
| 270 | sdbusplus::bus::match::rules::propertiesChanged( |
| 271 | PIPS_PATH, PIPS_INTERFACE), |
| 272 | [this](auto& msg) { this->ipsChanged(msg); }), |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 273 | defaultsUpdateMatch( |
| 274 | utils::getBus(), |
| 275 | sdbusplus::bus::match::rules::propertiesChangedNamespace( |
| 276 | "/xyz/openbmc_project/inventory", PMODE_DEFAULT_INTERFACE), |
| 277 | [this](auto& msg) { this->defaultsReady(msg); }), |
| 278 | masterOccSet(false), masterActive(false) |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 279 | #ifdef POWER10 |
| 280 | , |
| 281 | event(event) |
| 282 | #endif |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 283 | { |
| 284 | // restore Power Mode to DBus |
| 285 | SysPwrMode currentMode; |
| 286 | uint16_t oemModeData = 0; |
| 287 | if (getMode(currentMode, oemModeData)) |
| 288 | { |
| 289 | updateDbusMode(currentMode); |
| 290 | } |
| 291 | // restore Idle Power Saver parameters to DBus |
| 292 | uint8_t enterUtil, exitUtil; |
| 293 | uint16_t enterTime, exitTime; |
| 294 | bool ipsEnabled; |
| 295 | if (getIPSParms(ipsEnabled, enterUtil, enterTime, exitUtil, exitTime)) |
| 296 | { |
| 297 | updateDbusIPS(ipsEnabled, enterUtil, enterTime, exitUtil, exitTime); |
| 298 | } |
| 299 | }; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 300 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 301 | /** @brief Initialize the persistent data with default values |
| 302 | * |
| 303 | * @return true if initialization completed |
| 304 | */ |
| 305 | bool initPersistentData(); |
| 306 | |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 307 | /** @brief Set the power mode lock (dbus method) |
| 308 | * |
| 309 | * @return true if successful |
| 310 | */ |
| 311 | bool powerModeLock(); |
| 312 | |
| 313 | /** @brief Get the power mode lock status (dbus method) |
| 314 | * |
| 315 | * @return true if locked |
| 316 | */ |
| 317 | bool powerModeLockStatus(); |
| 318 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 319 | /** @brief Set the current power mode property |
| 320 | * |
| 321 | * @param[in] newMode - desired system power mode |
| 322 | * @param[in] oemModeData - data required by some OEM Power Modes |
| 323 | * |
| 324 | * @return true if mode accepted |
| 325 | */ |
| 326 | bool setMode(const SysPwrMode newMode, const uint16_t oemModeData); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 327 | |
| 328 | /** @brief Send mode change command to the master OCC |
| 329 | * @return SUCCESS on success |
| 330 | */ |
| 331 | CmdStatus sendModeChange(); |
| 332 | |
| 333 | /** @brief Send Idle Power Saver config data to the master OCC |
| 334 | * @return SUCCESS on success |
| 335 | */ |
| 336 | CmdStatus sendIpsData(); |
| 337 | |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 338 | /** @brief Set the master OCC path |
| 339 | * |
| 340 | * @param[in] occPath - hwmon path for master OCC |
| 341 | */ |
| 342 | void setMasterOcc(const std::string& occPath); |
| 343 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 344 | /** @brief Notify object of master OCC state. If not acitve, no |
| 345 | * commands will be sent to the master OCC |
| 346 | * |
| 347 | * @param[in] isActive - true when master OCC is active |
| 348 | */ |
| 349 | void setMasterActive(const bool isActive = true) |
| 350 | { |
| 351 | masterActive = isActive; |
| 352 | }; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 353 | |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 354 | #ifdef POWER10 |
| 355 | /** @brief Starts to monitor for IPS active state change conditions |
| 356 | * |
| 357 | * @param[in] poll - Indicates whether or not the IPS state file should |
| 358 | * actually be read for changes. |
| 359 | */ |
| 360 | void addIpsWatch(bool poll = true); |
| 361 | |
| 362 | /** @brief Removes IPS active watch */ |
| 363 | void removeIpsWatch(); |
| 364 | #endif |
| 365 | |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 366 | /** @brief Set dbus property to SAFE Mode(true) or clear SAFE Mode(false)*/ |
| 367 | void updateDbusSafeMode(const bool safeMode); |
| 368 | |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 369 | /** @brief override the set/get MODE function |
| 370 | * |
| 371 | * @param[in] value - Intended value |
| 372 | * |
| 373 | * @return - the value or Updated value of the property |
| 374 | */ |
| 375 | Base::Mode::PowerMode powerMode(Base::Mode::PowerMode value) override; |
| 376 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 377 | private: |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 378 | /** @brief OCC manager object */ |
| 379 | const Manager& manager; |
| 380 | |
| 381 | /** @brief Pass-through occ path on the bus */ |
| 382 | std::string path; |
| 383 | |
| 384 | /** @brief OCC instance number */ |
| 385 | int occInstance; |
| 386 | |
| 387 | /** @brief Object to send commands to the OCC */ |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 388 | std::unique_ptr<open_power::occ::OccCommand> occCmd; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 389 | |
| 390 | /** @brief Used to subscribe to dbus pmode property changes **/ |
| 391 | sdbusplus::bus::match_t pmodeMatch; |
| 392 | |
| 393 | /** @brief Used to subscribe to dbus IPS property changes **/ |
| 394 | sdbusplus::bus::match_t ipsMatch; |
| 395 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 396 | /** @brief Used to subscribe to dbus defaults property changes **/ |
| 397 | sdbusplus::bus::match_t defaultsUpdateMatch; |
| 398 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 399 | OccPersistData persistedData; |
| 400 | |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 401 | /** @brief True when the master OCC has been established */ |
| 402 | bool masterOccSet; |
| 403 | |
| 404 | /** @brief True when the master OCC is active */ |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 405 | bool masterActive; |
| 406 | |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 407 | #ifdef POWER10 |
| 408 | /** @brief IPS status data filename to read */ |
| 409 | const fs::path ipsStatusFile = std::filesystem::path{OCC_HWMON_PATH} / |
| 410 | std::filesystem::path{OCC_MASTER_NAME} / |
| 411 | "occ_ips_status"; |
| 412 | |
| 413 | /** @brief Current state of error watching */ |
| 414 | bool watching = false; |
| 415 | |
| 416 | /** @brief register for the callback from the POLL IPS changed event */ |
| 417 | void registerIpsStatusCallBack(); |
| 418 | #endif |
| 419 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 420 | /** @brief Callback for pmode setting changes |
| 421 | * |
| 422 | * Process change and inform OCC |
| 423 | * |
| 424 | * @param[in] msg - Data associated with pmode change signal |
| 425 | * |
| 426 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 427 | void modeChanged(sdbusplus::message_t& msg); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 428 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 429 | /** @brief Get the current power mode property |
| 430 | * |
| 431 | * @param[out] currentMode - current system power mode |
| 432 | * @param[out] oemModeData - frequency data for some OEM mode |
| 433 | * |
| 434 | * @return true if data read successfully |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 435 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 436 | bool getMode(SysPwrMode& currentMode, uint16_t& oemModeData); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 437 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 438 | /** @brief Update the power mode property on DBus |
| 439 | * |
| 440 | * @param[in] newMode - desired power mode |
| 441 | * |
| 442 | * @return true on success |
| 443 | */ |
| 444 | bool updateDbusMode(const SysPwrMode newMode); |
| 445 | |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 446 | /** @brief Callback for IPS setting changes |
| 447 | * |
| 448 | * Process change and inform OCC |
| 449 | * |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 450 | * @param[in] msg - Data associated with IPS change signal |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 451 | * |
| 452 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 453 | void ipsChanged(sdbusplus::message_t& msg); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 454 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 455 | /** @brief Get the Idle Power Saver properties |
| 456 | * |
| 457 | * @param[out] enabled - Idle Power Save status (true = enabled) |
| 458 | * @param[out] enterUtil - IPS Enter Utilization (%) |
| 459 | * @param[out] enterTime - IPS Enter Time (seconds) |
| 460 | * @param[out] exitUtil - IPS Exit Utilization (%) |
| 461 | * @param[out] exitTime - IPS Exit Time (seconds) |
| 462 | * |
| 463 | * @return true if data read successfully |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 464 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 465 | bool getIPSParms(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, |
| 466 | uint8_t& exitUtil, uint16_t& exitTime); |
| 467 | |
| 468 | /** Update the Idle Power Saver data on DBus |
| 469 | * |
| 470 | * @param[in] enabled - Idle Power Save status (true = enabled) |
| 471 | * @param[in] enterUtil - IPS Enter Utilization (%) |
| 472 | * @param[in] enterTime - IPS Enter Time (seconds) |
| 473 | * @param[in] exitUtil - IPS Exit Utilization (%) |
| 474 | * @param[in] exitTime - IPS Exit Time (seconds) |
| 475 | * |
| 476 | * @return true if parameters were set successfully |
| 477 | */ |
| 478 | bool updateDbusIPS(const bool enabled, const uint8_t enterUtil, |
| 479 | const uint16_t enterTime, const uint8_t exitUtil, |
| 480 | const uint16_t exitTime); |
| 481 | |
| 482 | /** @brief Callback for entity manager default changes |
| 483 | * |
| 484 | * Called when PowerModeProperties defaults are available |
| 485 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 486 | void defaultsReady(sdbusplus::message_t& msg); |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 487 | |
| 488 | /** @brief Get the default power mode property for this system type |
| 489 | * |
| 490 | * @param[out] defaultMode - default system power mode |
| 491 | * |
| 492 | * @return true if data read successfully |
| 493 | */ |
| 494 | bool getDefaultMode(SysPwrMode& defaultMode); |
| 495 | |
| 496 | /** @brief Get the default Idle Power Saver properties for this system type |
| 497 | * |
| 498 | * @param[out] enabled - Idle Power Save status (true = enabled) |
| 499 | * @param[out] enterUtil - IPS Enter Utilization (%) |
| 500 | * @param[out] enterTime - IPS Enter Time (seconds) |
| 501 | * @param[out] exitUtil - IPS Exit Utilization (%) |
| 502 | * @param[out] exitTime - IPS Exit Time (seconds) |
| 503 | * |
| 504 | * @return true if parameters were read successfully |
| 505 | */ |
| 506 | bool getDefaultIPSParms(bool& enabled, uint8_t& enterUtil, |
| 507 | uint16_t& enterTime, uint8_t& exitUtil, |
| 508 | uint16_t& exitTime); |
Chris Cain | cde7bea | 2022-01-28 15:54:24 -0600 | [diff] [blame] | 509 | |
| 510 | /** @brief Read the default Idle Power Saver parameters and save them to the |
| 511 | * DBUS so they will get used |
| 512 | * |
| 513 | * @return true if restore was successful |
| 514 | */ |
| 515 | bool useDefaultIPSParms(); |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 516 | |
| 517 | #ifdef POWER10 |
| 518 | /** @brief callback for the POLL IPS changed event |
| 519 | * |
| 520 | * @param[in] es - Populated event source |
| 521 | * @param[in] fd - Associated File descriptor |
| 522 | * @param[in] revents - Type of event |
| 523 | * @param[in] userData - User data that was passed during registration |
| 524 | */ |
| 525 | static int ipsStatusCallBack(sd_event_source* es, int fd, uint32_t revents, |
| 526 | void* userData); |
| 527 | |
| 528 | /** @brief Opens the IPS file and populates fd */ |
| 529 | bool openIpsFile(); |
| 530 | |
| 531 | /** @brief sd_event wrapped in unique_ptr */ |
| 532 | EventPtr& event; |
| 533 | |
| 534 | /** @brief event source wrapped in unique_ptr */ |
| 535 | EventSourcePtr eventSource; |
| 536 | |
| 537 | /** @brief When the ips status event is received, analyzes it */ |
| 538 | virtual void analyzeIpsEvent(); |
| 539 | |
| 540 | protected: |
| 541 | /** @brief File descriptor to watch for errors */ |
| 542 | int fd = -1; |
| 543 | #endif |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 544 | }; |
| 545 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 546 | } // namespace powermode |
| 547 | |
| 548 | } // namespace occ |
| 549 | |
| 550 | } // namespace open_power |
| 551 | #endif |