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 | { |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 161 | if (modeData.modeInitialized) |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 162 | { |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 163 | mode = modeData.mode; |
| 164 | oemModeData = modeData.oemModeData; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 165 | } |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 166 | return modeData.modeInitialized; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 167 | } |
| 168 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 169 | /** @brief Get the Idle Power Saver properties from DBus |
| 170 | * |
| 171 | * @param[out] enabled - Idle Power Save status (true = enabled) |
| 172 | * @param[out] enterUtil - IPS Enter Utilization (%) |
| 173 | * @param[out] enterTime - IPS Enter Time (seconds) |
| 174 | * @param[out] exitUtil - IPS Exit Utilization (%) |
| 175 | * @param[out] exitTime - IPS Exit Time (seconds) |
| 176 | * |
| 177 | * @return true if parameters were read successfully |
| 178 | */ |
| 179 | bool getIPS(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, |
| 180 | uint8_t& exitUtil, uint16_t& exitTime) |
| 181 | { |
| 182 | if (!modeData.ipsInitialized) |
| 183 | { |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | enabled = modeData.ipsEnabled; |
| 188 | enterUtil = modeData.ipsEnterUtil; |
| 189 | enterTime = modeData.ipsEnterTime; |
| 190 | exitUtil = modeData.ipsExitUtil; |
| 191 | exitTime = modeData.ipsExitTime; |
| 192 | return true; |
| 193 | } |
| 194 | |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 195 | /** @brief Return persisted mode lock */ |
| 196 | bool getModeLock() |
| 197 | { |
| 198 | return modeData.modeLocked; |
| 199 | } |
| 200 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 201 | /** @brief Return true if the power mode is available */ |
| 202 | bool modeAvailable() |
| 203 | { |
| 204 | return (modeData.modeInitialized); |
| 205 | } |
| 206 | |
Chris Cain | cde7bea | 2022-01-28 15:54:24 -0600 | [diff] [blame] | 207 | /** @brief Return true if the IPS data is available */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 208 | bool ipsAvailable() |
| 209 | { |
| 210 | return (modeData.ipsInitialized); |
| 211 | } |
| 212 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 213 | /** @brief Saves the Power Mode data in the filesystem using cereal. */ |
| 214 | void save(); |
| 215 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 216 | /** @brief Trace the Power Mode and IPS parameters. */ |
| 217 | void print(); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 218 | |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 219 | /** @brief Invalidate the persisted mode */ |
| 220 | void invalidateMode() |
| 221 | { |
| 222 | modeData.modeInitialized = false; |
| 223 | } |
| 224 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 225 | private: |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 226 | /** @brief Power Mode data filename to store persistent data */ |
| 227 | static constexpr auto powerModeFilename = "powerModeData"; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 228 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 229 | /** @brief Power Mode data object to be persisted */ |
| 230 | PowerModeData modeData; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 231 | |
| 232 | /** @brief Loads the OEM mode data in the filesystem using cereal. */ |
| 233 | void load(); |
| 234 | }; |
| 235 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 236 | /** @class PowerMode |
| 237 | * @brief Monitors for changes to the power mode and notifies occ |
| 238 | * |
| 239 | * The customer power mode is provided to the OCC by host TMGT when the occ |
| 240 | * first goes active or is reset. This code is responsible for sending |
| 241 | * the power mode to the OCC if the mode is changed while the occ is active. |
| 242 | */ |
| 243 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 244 | class PowerMode : public ModeInterface, public IpsInterface |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 245 | { |
| 246 | public: |
| 247 | /** @brief PowerMode object to inform occ of changes to mode |
| 248 | * |
| 249 | * This object will monitor for changes to the power mode setting. |
| 250 | * If a change is detected, and the occ is active, then this object will |
| 251 | * notify the OCC of the change. |
| 252 | * |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 253 | * @param[in] managerRef - manager object reference |
| 254 | * @param[in] modePath - Power Mode dbus path |
| 255 | * @param[in] ipsPath - Idle Power Saver dbus path |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 256 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 257 | explicit PowerMode(const Manager& managerRef, const char* modePath, |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 258 | const char* ipsPath, EventPtr& event); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 259 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 260 | /** @brief Initialize the persistent data with default values |
| 261 | * |
| 262 | * @return true if initialization completed |
| 263 | */ |
| 264 | bool initPersistentData(); |
| 265 | |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 266 | /** @brief Set the power mode lock (dbus method) |
| 267 | * |
| 268 | * @return true if successful |
| 269 | */ |
| 270 | bool powerModeLock(); |
| 271 | |
| 272 | /** @brief Get the power mode lock status (dbus method) |
| 273 | * |
| 274 | * @return true if locked |
| 275 | */ |
| 276 | bool powerModeLockStatus(); |
| 277 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 278 | /** @brief Set the current power mode property |
| 279 | * |
| 280 | * @param[in] newMode - desired system power mode |
| 281 | * @param[in] oemModeData - data required by some OEM Power Modes |
| 282 | * |
| 283 | * @return true if mode accepted |
| 284 | */ |
| 285 | bool setMode(const SysPwrMode newMode, const uint16_t oemModeData); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 286 | |
| 287 | /** @brief Send mode change command to the master OCC |
| 288 | * @return SUCCESS on success |
| 289 | */ |
| 290 | CmdStatus sendModeChange(); |
| 291 | |
| 292 | /** @brief Send Idle Power Saver config data to the master OCC |
| 293 | * @return SUCCESS on success |
| 294 | */ |
| 295 | CmdStatus sendIpsData(); |
| 296 | |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 297 | /** @brief Set the master OCC path |
| 298 | * |
| 299 | * @param[in] occPath - hwmon path for master OCC |
| 300 | */ |
| 301 | void setMasterOcc(const std::string& occPath); |
| 302 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 303 | /** @brief Notify object of master OCC state. If not acitve, no |
| 304 | * commands will be sent to the master OCC |
| 305 | * |
| 306 | * @param[in] isActive - true when master OCC is active |
| 307 | */ |
| 308 | void setMasterActive(const bool isActive = true) |
| 309 | { |
| 310 | masterActive = isActive; |
| 311 | }; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 312 | |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 313 | /** @brief Starts to monitor for IPS active state change conditions |
| 314 | * |
| 315 | * @param[in] poll - Indicates whether or not the IPS state file should |
| 316 | * actually be read for changes. |
| 317 | */ |
| 318 | void addIpsWatch(bool poll = true); |
| 319 | |
| 320 | /** @brief Removes IPS active watch */ |
| 321 | void removeIpsWatch(); |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 322 | |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 323 | /** @brief Set dbus property to SAFE Mode(true) or clear SAFE Mode(false)*/ |
| 324 | void updateDbusSafeMode(const bool safeMode); |
| 325 | |
Ben Tyner | 3576d65 | 2022-05-22 18:05:53 -0500 | [diff] [blame] | 326 | /** @brief override the set/get MODE function |
| 327 | * |
| 328 | * @param[in] value - Intended value |
| 329 | * |
| 330 | * @return - the value or Updated value of the property |
| 331 | */ |
| 332 | Base::Mode::PowerMode powerMode(Base::Mode::PowerMode value) override; |
| 333 | |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 334 | /** @brief Determine if the supplied mode is valid for the system |
| 335 | * |
| 336 | * @param[in] mode - potential mode |
| 337 | * |
| 338 | * @return - true if the mode is valid |
| 339 | */ |
| 340 | bool isValidMode(const SysPwrMode mode); |
| 341 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 342 | private: |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 343 | /** @brief OCC manager object */ |
| 344 | const Manager& manager; |
| 345 | |
| 346 | /** @brief Pass-through occ path on the bus */ |
| 347 | std::string path; |
| 348 | |
| 349 | /** @brief OCC instance number */ |
| 350 | int occInstance; |
| 351 | |
| 352 | /** @brief Object to send commands to the OCC */ |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 353 | std::unique_ptr<open_power::occ::OccCommand> occCmd; |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 354 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 355 | /** @brief Used to subscribe to dbus IPS property changes **/ |
| 356 | sdbusplus::bus::match_t ipsMatch; |
| 357 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 358 | /** @brief Used to subscribe to dbus defaults property changes **/ |
| 359 | sdbusplus::bus::match_t defaultsUpdateMatch; |
| 360 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 361 | OccPersistData persistedData; |
| 362 | |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 363 | /** @brief True when the master OCC has been established **/ |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 364 | bool masterOccSet; |
| 365 | |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 366 | /** @brief True when the master OCC is active **/ |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 367 | bool masterActive; |
| 368 | |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 369 | /** @brief True when the ecoModes are supported for this system **/ |
| 370 | bool ecoModeSupport = false; |
| 371 | |
| 372 | /** @brief List of customer supported power modes **/ |
| 373 | std::set<SysPwrMode> customerModeList = { |
| 374 | SysPwrMode::STATIC, SysPwrMode::POWER_SAVING, SysPwrMode::MAX_PERF}; |
| 375 | |
| 376 | /** @brief List of OEM supported power modes **/ |
| 377 | std::set<SysPwrMode> oemModeList = {SysPwrMode::SFP, SysPwrMode::FFO, |
| 378 | SysPwrMode::MAX_FREQ}; |
| 379 | |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 380 | /** @brief IPS status data filename to read */ |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 381 | const fs::path ipsStatusFile = |
| 382 | std::filesystem::path{OCC_HWMON_PATH} / |
| 383 | std::filesystem::path{OCC_MASTER_NAME} / "occ_ips_status"; |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 384 | |
| 385 | /** @brief Current state of error watching */ |
| 386 | bool watching = false; |
| 387 | |
| 388 | /** @brief register for the callback from the POLL IPS changed event */ |
| 389 | void registerIpsStatusCallBack(); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 390 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 391 | /** @brief Get the current power mode property |
| 392 | * |
| 393 | * @param[out] currentMode - current system power mode |
| 394 | * @param[out] oemModeData - frequency data for some OEM mode |
| 395 | * |
| 396 | * @return true if data read successfully |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 397 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 398 | bool getMode(SysPwrMode& currentMode, uint16_t& oemModeData); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 399 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 400 | /** @brief Update the power mode property on DBus |
| 401 | * |
| 402 | * @param[in] newMode - desired power mode |
| 403 | * |
| 404 | * @return true on success |
| 405 | */ |
| 406 | bool updateDbusMode(const SysPwrMode newMode); |
| 407 | |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 408 | /** @brief Callback for IPS setting changes |
| 409 | * |
| 410 | * Process change and inform OCC |
| 411 | * |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 412 | * @param[in] msg - Data associated with IPS change signal |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 413 | * |
| 414 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 415 | void ipsChanged(sdbusplus::message_t& msg); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 416 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 417 | /** @brief Get the Idle Power Saver properties |
| 418 | * |
| 419 | * @param[out] enabled - Idle Power Save status (true = enabled) |
| 420 | * @param[out] enterUtil - IPS Enter Utilization (%) |
| 421 | * @param[out] enterTime - IPS Enter Time (seconds) |
| 422 | * @param[out] exitUtil - IPS Exit Utilization (%) |
| 423 | * @param[out] exitTime - IPS Exit Time (seconds) |
| 424 | * |
| 425 | * @return true if data read successfully |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 426 | */ |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 427 | bool getIPSParms(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, |
| 428 | uint8_t& exitUtil, uint16_t& exitTime); |
| 429 | |
| 430 | /** Update the Idle Power Saver data on DBus |
| 431 | * |
| 432 | * @param[in] enabled - Idle Power Save status (true = enabled) |
| 433 | * @param[in] enterUtil - IPS Enter Utilization (%) |
| 434 | * @param[in] enterTime - IPS Enter Time (seconds) |
| 435 | * @param[in] exitUtil - IPS Exit Utilization (%) |
| 436 | * @param[in] exitTime - IPS Exit Time (seconds) |
| 437 | * |
| 438 | * @return true if parameters were set successfully |
| 439 | */ |
| 440 | bool updateDbusIPS(const bool enabled, const uint8_t enterUtil, |
| 441 | const uint16_t enterTime, const uint8_t exitUtil, |
| 442 | const uint16_t exitTime); |
| 443 | |
| 444 | /** @brief Callback for entity manager default changes |
| 445 | * |
| 446 | * Called when PowerModeProperties defaults are available |
| 447 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 448 | void defaultsReady(sdbusplus::message_t& msg); |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 449 | |
| 450 | /** @brief Get the default power mode property for this system type |
| 451 | * |
| 452 | * @param[out] defaultMode - default system power mode |
| 453 | * |
| 454 | * @return true if data read successfully |
| 455 | */ |
| 456 | bool getDefaultMode(SysPwrMode& defaultMode); |
| 457 | |
| 458 | /** @brief Get the default Idle Power Saver properties for this system type |
| 459 | * |
| 460 | * @param[out] enabled - Idle Power Save status (true = enabled) |
| 461 | * @param[out] enterUtil - IPS Enter Utilization (%) |
| 462 | * @param[out] enterTime - IPS Enter Time (seconds) |
| 463 | * @param[out] exitUtil - IPS Exit Utilization (%) |
| 464 | * @param[out] exitTime - IPS Exit Time (seconds) |
| 465 | * |
| 466 | * @return true if parameters were read successfully |
| 467 | */ |
| 468 | bool getDefaultIPSParms(bool& enabled, uint8_t& enterUtil, |
| 469 | uint16_t& enterTime, uint8_t& exitUtil, |
| 470 | uint16_t& exitTime); |
Chris Cain | cde7bea | 2022-01-28 15:54:24 -0600 | [diff] [blame] | 471 | |
| 472 | /** @brief Read the default Idle Power Saver parameters and save them to the |
| 473 | * DBUS so they will get used |
| 474 | * |
| 475 | * @return true if restore was successful |
| 476 | */ |
| 477 | bool useDefaultIPSParms(); |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 478 | |
Chris Cain | 30040d9 | 2024-06-19 16:50:34 -0500 | [diff] [blame] | 479 | /** @brief Read the supported power modes from entity-manager and update |
| 480 | * AllowedPowerModes on dbus |
| 481 | * |
| 482 | * @return true if data was found/updated |
| 483 | */ |
| 484 | bool getSupportedModes(); |
| 485 | |
Sheldon Bailey | ea2b22e | 2022-04-04 12:24:46 -0500 | [diff] [blame] | 486 | /** @brief callback for the POLL IPS changed event |
| 487 | * |
| 488 | * @param[in] es - Populated event source |
| 489 | * @param[in] fd - Associated File descriptor |
| 490 | * @param[in] revents - Type of event |
| 491 | * @param[in] userData - User data that was passed during registration |
| 492 | */ |
| 493 | static int ipsStatusCallBack(sd_event_source* es, int fd, uint32_t revents, |
| 494 | void* userData); |
| 495 | |
| 496 | /** @brief Opens the IPS file and populates fd */ |
| 497 | bool openIpsFile(); |
| 498 | |
| 499 | /** @brief sd_event wrapped in unique_ptr */ |
| 500 | EventPtr& event; |
| 501 | |
| 502 | /** @brief event source wrapped in unique_ptr */ |
| 503 | EventSourcePtr eventSource; |
| 504 | |
| 505 | /** @brief When the ips status event is received, analyzes it */ |
| 506 | virtual void analyzeIpsEvent(); |
| 507 | |
| 508 | protected: |
| 509 | /** @brief File descriptor to watch for errors */ |
| 510 | int fd = -1; |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 511 | }; |
| 512 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 513 | } // namespace powermode |
| 514 | |
| 515 | } // namespace occ |
| 516 | |
| 517 | } // namespace open_power |
| 518 | #endif |