178e86012SChris Cain #pragma once 278e86012SChris Cain 378e86012SChris Cain #include "config.h" 478e86012SChris Cain 5bddcf853SGeorge Liu #ifdef POWER10 636f9cdedSChris Cain #include "occ_command.hpp" 778e86012SChris Cain 836f9cdedSChris Cain #include <cereal/archives/json.hpp> 936f9cdedSChris Cain #include <cereal/cereal.hpp> 1036f9cdedSChris Cain #include <cereal/types/string.hpp> 1136f9cdedSChris Cain #include <cereal/types/tuple.hpp> 1236f9cdedSChris Cain #include <cereal/types/vector.hpp> 1378e86012SChris Cain #include <sdbusplus/bus.hpp> 1478e86012SChris Cain #include <sdbusplus/bus/match.hpp> 151be4337bSChris Cain #include <xyz/openbmc_project/Control/Power/IdlePowerSaver/server.hpp> 161be4337bSChris Cain #include <xyz/openbmc_project/Control/Power/Mode/server.hpp> 1778e86012SChris Cain 18bcef3b48SGeorge Liu #include <filesystem> 19b5ca1015SGeorge Liu 2078e86012SChris Cain namespace open_power 2178e86012SChris Cain { 2278e86012SChris Cain namespace occ 2378e86012SChris Cain { 2436f9cdedSChris Cain 2536f9cdedSChris Cain class Manager; 2636f9cdedSChris Cain 2778e86012SChris Cain namespace powermode 2878e86012SChris Cain { 291be4337bSChris Cain namespace Base = sdbusplus::xyz::openbmc_project::Control::Power::server; 30af40808fSPatrick Williams using ModeInterface = sdbusplus::server::object_t<Base::Mode>; 31af40808fSPatrick Williams using IpsInterface = sdbusplus::server::object_t<Base::IdlePowerSaver>; 321be4337bSChris Cain using namespace std::literals::string_literals; 3378e86012SChris Cain 3478e86012SChris Cain constexpr auto PMODE_PATH = "/xyz/openbmc_project/control/host0/power_mode"; 3578e86012SChris Cain constexpr auto PMODE_INTERFACE = "xyz.openbmc_project.Control.Power.Mode"; 3678e86012SChris Cain constexpr auto POWER_MODE_PROP = "PowerMode"; 3731a2f13aSSheldon Bailey constexpr auto POWER_SAFE_MODE_PROP = "SafeMode"; 3878e86012SChris Cain 391d51da29SChris Cain constexpr auto PIPS_PATH = "/xyz/openbmc_project/control/host0/power_ips"; 401d51da29SChris Cain constexpr auto PIPS_INTERFACE = 411d51da29SChris Cain "xyz.openbmc_project.Control.Power.IdlePowerSaver"; 42ea2b22ebSSheldon Bailey constexpr auto IPS_ACTIVE_PROP = "Active"; 431d51da29SChris Cain constexpr auto IPS_ENABLED_PROP = "Enabled"; 441d51da29SChris Cain constexpr auto IPS_ENTER_UTIL = "EnterUtilizationPercent"; 451d51da29SChris Cain constexpr auto IPS_ENTER_TIME = "EnterDwellTime"; 461d51da29SChris Cain constexpr auto IPS_EXIT_UTIL = "ExitUtilizationPercent"; 471d51da29SChris Cain constexpr auto IPS_EXIT_TIME = "ExitDwellTime"; 481d51da29SChris Cain 491be4337bSChris Cain const auto PMODE_DEFAULT_INTERFACE = 501be4337bSChris Cain "xyz.openbmc_project.Configuration.PowerModeProperties"s; 511be4337bSChris Cain 5236f9cdedSChris Cain /** @brief Query the current Hypervisor target 5336f9cdedSChris Cain * @return true if the current Hypervisor target is PowerVM 5436f9cdedSChris Cain */ 5536f9cdedSChris Cain bool isPowerVM(); 5636f9cdedSChris Cain 5778e86012SChris Cain /** @brief Convert power mode string to OCC SysPwrMode value 5878e86012SChris Cain * 5978e86012SChris Cain * @param[in] i_modeString - power mode string 6078e86012SChris Cain * 6178e86012SChris Cain * @return SysPwrMode or SysPwrMode::NO_CHANGE if not found 6278e86012SChris Cain */ 6378e86012SChris Cain SysPwrMode convertStringToMode(const std::string& i_modeString); 6478e86012SChris Cain 651be4337bSChris Cain struct PowerModeData 6636f9cdedSChris Cain { 671be4337bSChris Cain bool modeInitialized = false; 681be4337bSChris Cain SysPwrMode mode = SysPwrMode::NO_CHANGE; 691be4337bSChris Cain uint16_t oemModeData = 0x0000; 701be4337bSChris Cain bool ipsInitialized = false; 711be4337bSChris Cain bool ipsEnabled = true; 721be4337bSChris Cain uint8_t ipsEnterUtil = 0; 731be4337bSChris Cain uint16_t ipsEnterTime = 0; 741be4337bSChris Cain uint8_t ipsExitUtil = 0; 751be4337bSChris Cain uint16_t ipsExitTime = 0; 763576d65eSBen Tyner bool modeLocked = false; 7736f9cdedSChris Cain 7836f9cdedSChris Cain /** @brief Function specifying data to archive for cereal. 7936f9cdedSChris Cain */ 8036f9cdedSChris Cain template <class Archive> 8136f9cdedSChris Cain void serialize(Archive& archive) 8236f9cdedSChris Cain { 831be4337bSChris Cain archive(modeInitialized, mode, oemModeData, ipsInitialized, ipsEnabled, 843576d65eSBen Tyner ipsEnterUtil, ipsEnterTime, ipsExitUtil, ipsExitTime, 853576d65eSBen Tyner modeLocked); 8636f9cdedSChris Cain } 8736f9cdedSChris Cain }; 8836f9cdedSChris Cain 8936f9cdedSChris Cain /** @class OccPersistData 9036f9cdedSChris Cain * @brief Provides persistent container to store data for OCC 9136f9cdedSChris Cain * 9236f9cdedSChris Cain * Data is stored via cereal 9336f9cdedSChris Cain */ 9436f9cdedSChris Cain class OccPersistData 9536f9cdedSChris Cain { 9636f9cdedSChris Cain public: 9736f9cdedSChris Cain ~OccPersistData() = default; 9836f9cdedSChris Cain OccPersistData(const OccPersistData&) = default; 9936f9cdedSChris Cain OccPersistData& operator=(const OccPersistData&) = default; 10036f9cdedSChris Cain OccPersistData(OccPersistData&&) = default; 10136f9cdedSChris Cain OccPersistData& operator=(OccPersistData&&) = default; 10236f9cdedSChris Cain 1031be4337bSChris Cain /** @brief Loads any saved power mode data */ 10436f9cdedSChris Cain OccPersistData() 10536f9cdedSChris Cain { 10636f9cdedSChris Cain load(); 10736f9cdedSChris Cain } 10836f9cdedSChris Cain 10936f9cdedSChris Cain /** @brief Save Power Mode data to persistent file 11036f9cdedSChris Cain * 1111be4337bSChris Cain * @param[in] newMode - desired System Power Mode 1121be4337bSChris Cain * @param[in] oemModeData - data required by some OEM Power Modes 11336f9cdedSChris Cain */ 1141be4337bSChris Cain void updateMode(const SysPwrMode newMode, const uint16_t oemModeData) 11536f9cdedSChris Cain { 1161be4337bSChris Cain modeData.mode = newMode; 1171be4337bSChris Cain modeData.oemModeData = oemModeData; 1181be4337bSChris Cain modeData.modeInitialized = true; 11936f9cdedSChris Cain save(); 12036f9cdedSChris Cain } 12136f9cdedSChris Cain 1223576d65eSBen Tyner /** @brief Save Power Mode Lock value to persistent file 1233576d65eSBen Tyner * 1243576d65eSBen Tyner * @param[in] modeLock - desired System Power Mode Lock 1253576d65eSBen Tyner */ 1263576d65eSBen Tyner void updateModeLock(const bool modeLock) 1273576d65eSBen Tyner { 1283576d65eSBen Tyner modeData.modeLocked = modeLock; 1293576d65eSBen Tyner save(); 1303576d65eSBen Tyner } 1311be4337bSChris Cain /** @brief Write Idle Power Saver parameters to persistent file 13236f9cdedSChris Cain * 1331be4337bSChris Cain * @param[in] enabled - Idle Power Save status (true = enabled) 1341be4337bSChris Cain * @param[in] enterUtil - IPS Enter Utilization (%) 1351be4337bSChris Cain * @param[in] enterTime - IPS Enter Time (seconds) 1361be4337bSChris Cain * @param[in] exitUtil - IPS Exit Utilization (%) 1371be4337bSChris Cain * @param[in] exitTime - IPS Exit Time (seconds) 13836f9cdedSChris Cain */ 1391be4337bSChris Cain void updateIPS(const bool enabled, const uint8_t enterUtil, 1401be4337bSChris Cain const uint16_t enterTime, const uint8_t exitUtil, 1411be4337bSChris Cain const uint16_t exitTime) 14236f9cdedSChris Cain { 1431be4337bSChris Cain modeData.ipsEnabled = enabled; 1441be4337bSChris Cain modeData.ipsEnterUtil = enterUtil; 1451be4337bSChris Cain modeData.ipsEnterTime = enterTime; 1461be4337bSChris Cain modeData.ipsExitUtil = exitUtil; 1471be4337bSChris Cain modeData.ipsExitTime = exitTime; 1481be4337bSChris Cain modeData.ipsInitialized = true; 1491be4337bSChris Cain save(); 1501be4337bSChris Cain } 1511be4337bSChris Cain 1521be4337bSChris Cain /** @brief Return the Power Mode and mode data 1531be4337bSChris Cain * 1541be4337bSChris Cain * @param[out] mode - current system power mode 1551be4337bSChris Cain * @param[out] oemModeData - frequency data for some OEM mode 1561be4337bSChris Cain * 1571be4337bSChris Cain * @returns true if mode was available 1581be4337bSChris Cain */ 1591be4337bSChris Cain bool getMode(SysPwrMode& mode, uint16_t& oemModeData) const 1601be4337bSChris Cain { 16130040d9dSChris Cain if (modeData.modeInitialized) 16236f9cdedSChris Cain { 1631be4337bSChris Cain mode = modeData.mode; 1641be4337bSChris Cain oemModeData = modeData.oemModeData; 16530040d9dSChris Cain } 16630040d9dSChris Cain return modeData.modeInitialized; 16736f9cdedSChris Cain } 16836f9cdedSChris Cain 1691be4337bSChris Cain /** @brief Get the Idle Power Saver properties from DBus 1701be4337bSChris Cain * 1711be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 1721be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 1731be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 1741be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 1751be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 1761be4337bSChris Cain * 1771be4337bSChris Cain * @return true if parameters were read successfully 1781be4337bSChris Cain */ 1791be4337bSChris Cain bool getIPS(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, 1801be4337bSChris Cain uint8_t& exitUtil, uint16_t& exitTime) 1811be4337bSChris Cain { 1821be4337bSChris Cain if (!modeData.ipsInitialized) 1831be4337bSChris Cain { 1841be4337bSChris Cain return false; 1851be4337bSChris Cain } 1861be4337bSChris Cain 1871be4337bSChris Cain enabled = modeData.ipsEnabled; 1881be4337bSChris Cain enterUtil = modeData.ipsEnterUtil; 1891be4337bSChris Cain enterTime = modeData.ipsEnterTime; 1901be4337bSChris Cain exitUtil = modeData.ipsExitUtil; 1911be4337bSChris Cain exitTime = modeData.ipsExitTime; 1921be4337bSChris Cain return true; 1931be4337bSChris Cain } 1941be4337bSChris Cain 1953576d65eSBen Tyner /** @brief Return persisted mode lock */ 1963576d65eSBen Tyner bool getModeLock() 1973576d65eSBen Tyner { 1983576d65eSBen Tyner return modeData.modeLocked; 1993576d65eSBen Tyner } 2003576d65eSBen Tyner 2011be4337bSChris Cain /** @brief Return true if the power mode is available */ 2021be4337bSChris Cain bool modeAvailable() 2031be4337bSChris Cain { 2041be4337bSChris Cain return (modeData.modeInitialized); 2051be4337bSChris Cain } 2061be4337bSChris Cain 207cde7bea3SChris Cain /** @brief Return true if the IPS data is available */ 2081be4337bSChris Cain bool ipsAvailable() 2091be4337bSChris Cain { 2101be4337bSChris Cain return (modeData.ipsInitialized); 2111be4337bSChris Cain } 2121be4337bSChris Cain 21336f9cdedSChris Cain /** @brief Saves the Power Mode data in the filesystem using cereal. */ 21436f9cdedSChris Cain void save(); 21536f9cdedSChris Cain 2161be4337bSChris Cain /** @brief Trace the Power Mode and IPS parameters. */ 2171be4337bSChris Cain void print(); 21836f9cdedSChris Cain 21930040d9dSChris Cain /** @brief Invalidate the persisted mode */ 22030040d9dSChris Cain void invalidateMode() 22130040d9dSChris Cain { 22230040d9dSChris Cain modeData.modeInitialized = false; 22330040d9dSChris Cain } 22430040d9dSChris Cain 22536f9cdedSChris Cain private: 2261be4337bSChris Cain /** @brief Power Mode data filename to store persistent data */ 2271be4337bSChris Cain static constexpr auto powerModeFilename = "powerModeData"; 22836f9cdedSChris Cain 2291be4337bSChris Cain /** @brief Power Mode data object to be persisted */ 2301be4337bSChris Cain PowerModeData modeData; 23136f9cdedSChris Cain 23236f9cdedSChris Cain /** @brief Loads the OEM mode data in the filesystem using cereal. */ 23336f9cdedSChris Cain void load(); 23436f9cdedSChris Cain }; 23536f9cdedSChris Cain 23678e86012SChris Cain /** @class PowerMode 23778e86012SChris Cain * @brief Monitors for changes to the power mode and notifies occ 23878e86012SChris Cain * 23978e86012SChris Cain * The customer power mode is provided to the OCC by host TMGT when the occ 24078e86012SChris Cain * first goes active or is reset. This code is responsible for sending 24178e86012SChris Cain * the power mode to the OCC if the mode is changed while the occ is active. 24278e86012SChris Cain */ 24378e86012SChris Cain 2441be4337bSChris Cain class PowerMode : public ModeInterface, public IpsInterface 24578e86012SChris Cain { 24678e86012SChris Cain public: 24778e86012SChris Cain /** @brief PowerMode object to inform occ of changes to mode 24878e86012SChris Cain * 24978e86012SChris Cain * This object will monitor for changes to the power mode setting. 25078e86012SChris Cain * If a change is detected, and the occ is active, then this object will 25178e86012SChris Cain * notify the OCC of the change. 25278e86012SChris Cain * 2531be4337bSChris Cain * @param[in] managerRef - manager object reference 2541be4337bSChris Cain * @param[in] modePath - Power Mode dbus path 2551be4337bSChris Cain * @param[in] ipsPath - Idle Power Saver dbus path 25678e86012SChris Cain */ 2571be4337bSChris Cain explicit PowerMode(const Manager& managerRef, const char* modePath, 25830040d9dSChris Cain const char* ipsPath, EventPtr& event); 25936f9cdedSChris Cain 2601be4337bSChris Cain /** @brief Initialize the persistent data with default values 2611be4337bSChris Cain * 2621be4337bSChris Cain * @return true if initialization completed 2631be4337bSChris Cain */ 2641be4337bSChris Cain bool initPersistentData(); 2651be4337bSChris Cain 2663576d65eSBen Tyner /** @brief Set the power mode lock (dbus method) 2673576d65eSBen Tyner * 2683576d65eSBen Tyner * @return true if successful 2693576d65eSBen Tyner */ 2703576d65eSBen Tyner bool powerModeLock(); 2713576d65eSBen Tyner 2723576d65eSBen Tyner /** @brief Get the power mode lock status (dbus method) 2733576d65eSBen Tyner * 2743576d65eSBen Tyner * @return true if locked 2753576d65eSBen Tyner */ 2763576d65eSBen Tyner bool powerModeLockStatus(); 2773576d65eSBen Tyner 2781be4337bSChris Cain /** @brief Set the current power mode property 2791be4337bSChris Cain * 2801be4337bSChris Cain * @param[in] newMode - desired system power mode 2811be4337bSChris Cain * @param[in] oemModeData - data required by some OEM Power Modes 2821be4337bSChris Cain * 2831be4337bSChris Cain * @return true if mode accepted 2841be4337bSChris Cain */ 2851be4337bSChris Cain bool setMode(const SysPwrMode newMode, const uint16_t oemModeData); 28636f9cdedSChris Cain 28736f9cdedSChris Cain /** @brief Send mode change command to the master OCC 28836f9cdedSChris Cain * @return SUCCESS on success 28936f9cdedSChris Cain */ 29036f9cdedSChris Cain CmdStatus sendModeChange(); 29136f9cdedSChris Cain 29236f9cdedSChris Cain /** @brief Send Idle Power Saver config data to the master OCC 29336f9cdedSChris Cain * @return SUCCESS on success 29436f9cdedSChris Cain */ 29536f9cdedSChris Cain CmdStatus sendIpsData(); 29636f9cdedSChris Cain 2976fa848a9SChris Cain /** @brief Set the master OCC path 2986fa848a9SChris Cain * 2996fa848a9SChris Cain * @param[in] occPath - hwmon path for master OCC 3006fa848a9SChris Cain */ 3016fa848a9SChris Cain void setMasterOcc(const std::string& occPath); 3026fa848a9SChris Cain 30336f9cdedSChris Cain /** @brief Notify object of master OCC state. If not acitve, no 30436f9cdedSChris Cain * commands will be sent to the master OCC 30536f9cdedSChris Cain * 30636f9cdedSChris Cain * @param[in] isActive - true when master OCC is active 30736f9cdedSChris Cain */ 30836f9cdedSChris Cain void setMasterActive(const bool isActive = true) 30936f9cdedSChris Cain { 31036f9cdedSChris Cain masterActive = isActive; 31136f9cdedSChris Cain }; 31278e86012SChris Cain 313ea2b22ebSSheldon Bailey /** @brief Starts to monitor for IPS active state change conditions 314ea2b22ebSSheldon Bailey * 315ea2b22ebSSheldon Bailey * @param[in] poll - Indicates whether or not the IPS state file should 316ea2b22ebSSheldon Bailey * actually be read for changes. 317ea2b22ebSSheldon Bailey */ 318ea2b22ebSSheldon Bailey void addIpsWatch(bool poll = true); 319ea2b22ebSSheldon Bailey 320ea2b22ebSSheldon Bailey /** @brief Removes IPS active watch */ 321ea2b22ebSSheldon Bailey void removeIpsWatch(); 322ea2b22ebSSheldon Bailey 32331a2f13aSSheldon Bailey /** @brief Set dbus property to SAFE Mode(true) or clear SAFE Mode(false)*/ 32431a2f13aSSheldon Bailey void updateDbusSafeMode(const bool safeMode); 32531a2f13aSSheldon Bailey 3263576d65eSBen Tyner /** @brief override the set/get MODE function 3273576d65eSBen Tyner * 3283576d65eSBen Tyner * @param[in] value - Intended value 3293576d65eSBen Tyner * 3303576d65eSBen Tyner * @return - the value or Updated value of the property 3313576d65eSBen Tyner */ 3323576d65eSBen Tyner Base::Mode::PowerMode powerMode(Base::Mode::PowerMode value) override; 3333576d65eSBen Tyner 33430040d9dSChris Cain /** @brief Determine if the supplied mode is valid for the system 33530040d9dSChris Cain * 33630040d9dSChris Cain * @param[in] mode - potential mode 33730040d9dSChris Cain * 33830040d9dSChris Cain * @return - true if the mode is valid 33930040d9dSChris Cain */ 34030040d9dSChris Cain bool isValidMode(const SysPwrMode mode); 34130040d9dSChris Cain 34278e86012SChris Cain private: 34336f9cdedSChris Cain /** @brief OCC manager object */ 34436f9cdedSChris Cain const Manager& manager; 34536f9cdedSChris Cain 34636f9cdedSChris Cain /** @brief Pass-through occ path on the bus */ 34736f9cdedSChris Cain std::string path; 34836f9cdedSChris Cain 34936f9cdedSChris Cain /** @brief OCC instance number */ 35036f9cdedSChris Cain int occInstance; 35136f9cdedSChris Cain 35236f9cdedSChris Cain /** @brief Object to send commands to the OCC */ 3536fa848a9SChris Cain std::unique_ptr<open_power::occ::OccCommand> occCmd; 35436f9cdedSChris Cain 35536f9cdedSChris Cain /** @brief Used to subscribe to dbus IPS property changes **/ 35636f9cdedSChris Cain sdbusplus::bus::match_t ipsMatch; 35736f9cdedSChris Cain 3581be4337bSChris Cain /** @brief Used to subscribe to dbus defaults property changes **/ 3591be4337bSChris Cain sdbusplus::bus::match_t defaultsUpdateMatch; 3601be4337bSChris Cain 36136f9cdedSChris Cain OccPersistData persistedData; 36236f9cdedSChris Cain 36330040d9dSChris Cain /** @brief True when the master OCC has been established **/ 3646fa848a9SChris Cain bool masterOccSet; 3656fa848a9SChris Cain 36630040d9dSChris Cain /** @brief True when the master OCC is active **/ 36736f9cdedSChris Cain bool masterActive; 36836f9cdedSChris Cain 36930040d9dSChris Cain /** @brief True when the ecoModes are supported for this system **/ 37030040d9dSChris Cain bool ecoModeSupport = false; 37130040d9dSChris Cain 37230040d9dSChris Cain /** @brief List of customer supported power modes **/ 37330040d9dSChris Cain std::set<SysPwrMode> customerModeList = { 37430040d9dSChris Cain SysPwrMode::STATIC, SysPwrMode::POWER_SAVING, SysPwrMode::MAX_PERF}; 37530040d9dSChris Cain 37630040d9dSChris Cain /** @brief List of OEM supported power modes **/ 37730040d9dSChris Cain std::set<SysPwrMode> oemModeList = {SysPwrMode::SFP, SysPwrMode::FFO, 37830040d9dSChris Cain SysPwrMode::MAX_FREQ}; 37930040d9dSChris Cain 380ea2b22ebSSheldon Bailey /** @brief IPS status data filename to read */ 381*d7542c83SPatrick Williams const fs::path ipsStatusFile = 382*d7542c83SPatrick Williams std::filesystem::path{OCC_HWMON_PATH} / 383*d7542c83SPatrick Williams std::filesystem::path{OCC_MASTER_NAME} / "occ_ips_status"; 384ea2b22ebSSheldon Bailey 385ea2b22ebSSheldon Bailey /** @brief Current state of error watching */ 386ea2b22ebSSheldon Bailey bool watching = false; 387ea2b22ebSSheldon Bailey 388ea2b22ebSSheldon Bailey /** @brief register for the callback from the POLL IPS changed event */ 389ea2b22ebSSheldon Bailey void registerIpsStatusCallBack(); 39078e86012SChris Cain 3911be4337bSChris Cain /** @brief Get the current power mode property 3921be4337bSChris Cain * 3931be4337bSChris Cain * @param[out] currentMode - current system power mode 3941be4337bSChris Cain * @param[out] oemModeData - frequency data for some OEM mode 3951be4337bSChris Cain * 3961be4337bSChris Cain * @return true if data read successfully 3971d51da29SChris Cain */ 3981be4337bSChris Cain bool getMode(SysPwrMode& currentMode, uint16_t& oemModeData); 3991d51da29SChris Cain 40036f9cdedSChris Cain /** @brief Update the power mode property on DBus 40136f9cdedSChris Cain * 40236f9cdedSChris Cain * @param[in] newMode - desired power mode 40336f9cdedSChris Cain * 40436f9cdedSChris Cain * @return true on success 40536f9cdedSChris Cain */ 40636f9cdedSChris Cain bool updateDbusMode(const SysPwrMode newMode); 40736f9cdedSChris Cain 4081d51da29SChris Cain /** @brief Callback for IPS setting changes 4091d51da29SChris Cain * 4101d51da29SChris Cain * Process change and inform OCC 4111d51da29SChris Cain * 4121d51da29SChris Cain * @param[in] msg - Data associated with IPS change signal 4131d51da29SChris Cain * 4141d51da29SChris Cain */ 415af40808fSPatrick Williams void ipsChanged(sdbusplus::message_t& msg); 4161d51da29SChris Cain 4171be4337bSChris Cain /** @brief Get the Idle Power Saver properties 4181be4337bSChris Cain * 4191be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 4201be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 4211be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 4221be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 4231be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 4241be4337bSChris Cain * 4251be4337bSChris Cain * @return true if data read successfully 42636f9cdedSChris Cain */ 4271be4337bSChris Cain bool getIPSParms(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, 4281be4337bSChris Cain uint8_t& exitUtil, uint16_t& exitTime); 4291be4337bSChris Cain 4301be4337bSChris Cain /** Update the Idle Power Saver data on DBus 4311be4337bSChris Cain * 4321be4337bSChris Cain * @param[in] enabled - Idle Power Save status (true = enabled) 4331be4337bSChris Cain * @param[in] enterUtil - IPS Enter Utilization (%) 4341be4337bSChris Cain * @param[in] enterTime - IPS Enter Time (seconds) 4351be4337bSChris Cain * @param[in] exitUtil - IPS Exit Utilization (%) 4361be4337bSChris Cain * @param[in] exitTime - IPS Exit Time (seconds) 4371be4337bSChris Cain * 4381be4337bSChris Cain * @return true if parameters were set successfully 4391be4337bSChris Cain */ 4401be4337bSChris Cain bool updateDbusIPS(const bool enabled, const uint8_t enterUtil, 4411be4337bSChris Cain const uint16_t enterTime, const uint8_t exitUtil, 4421be4337bSChris Cain const uint16_t exitTime); 4431be4337bSChris Cain 4441be4337bSChris Cain /** @brief Callback for entity manager default changes 4451be4337bSChris Cain * 4461be4337bSChris Cain * Called when PowerModeProperties defaults are available 4471be4337bSChris Cain */ 448af40808fSPatrick Williams void defaultsReady(sdbusplus::message_t& msg); 4491be4337bSChris Cain 4501be4337bSChris Cain /** @brief Get the default power mode property for this system type 4511be4337bSChris Cain * 4521be4337bSChris Cain * @param[out] defaultMode - default system power mode 4531be4337bSChris Cain * 4541be4337bSChris Cain * @return true if data read successfully 4551be4337bSChris Cain */ 4561be4337bSChris Cain bool getDefaultMode(SysPwrMode& defaultMode); 4571be4337bSChris Cain 4581be4337bSChris Cain /** @brief Get the default Idle Power Saver properties for this system type 4591be4337bSChris Cain * 4601be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 4611be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 4621be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 4631be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 4641be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 4651be4337bSChris Cain * 4661be4337bSChris Cain * @return true if parameters were read successfully 4671be4337bSChris Cain */ 4681be4337bSChris Cain bool getDefaultIPSParms(bool& enabled, uint8_t& enterUtil, 4691be4337bSChris Cain uint16_t& enterTime, uint8_t& exitUtil, 47036f9cdedSChris Cain uint16_t& exitTime); 471cde7bea3SChris Cain 472cde7bea3SChris Cain /** @brief Read the default Idle Power Saver parameters and save them to the 473cde7bea3SChris Cain * DBUS so they will get used 474cde7bea3SChris Cain * 475cde7bea3SChris Cain * @return true if restore was successful 476cde7bea3SChris Cain */ 477cde7bea3SChris Cain bool useDefaultIPSParms(); 478ea2b22ebSSheldon Bailey 47930040d9dSChris Cain /** @brief Read the supported power modes from entity-manager and update 48030040d9dSChris Cain * AllowedPowerModes on dbus 48130040d9dSChris Cain * 48230040d9dSChris Cain * @return true if data was found/updated 48330040d9dSChris Cain */ 48430040d9dSChris Cain bool getSupportedModes(); 48530040d9dSChris Cain 486ea2b22ebSSheldon Bailey /** @brief callback for the POLL IPS changed event 487ea2b22ebSSheldon Bailey * 488ea2b22ebSSheldon Bailey * @param[in] es - Populated event source 489ea2b22ebSSheldon Bailey * @param[in] fd - Associated File descriptor 490ea2b22ebSSheldon Bailey * @param[in] revents - Type of event 491ea2b22ebSSheldon Bailey * @param[in] userData - User data that was passed during registration 492ea2b22ebSSheldon Bailey */ 493ea2b22ebSSheldon Bailey static int ipsStatusCallBack(sd_event_source* es, int fd, uint32_t revents, 494ea2b22ebSSheldon Bailey void* userData); 495ea2b22ebSSheldon Bailey 496ea2b22ebSSheldon Bailey /** @brief Opens the IPS file and populates fd */ 497ea2b22ebSSheldon Bailey bool openIpsFile(); 498ea2b22ebSSheldon Bailey 499ea2b22ebSSheldon Bailey /** @brief sd_event wrapped in unique_ptr */ 500ea2b22ebSSheldon Bailey EventPtr& event; 501ea2b22ebSSheldon Bailey 502ea2b22ebSSheldon Bailey /** @brief event source wrapped in unique_ptr */ 503ea2b22ebSSheldon Bailey EventSourcePtr eventSource; 504ea2b22ebSSheldon Bailey 505ea2b22ebSSheldon Bailey /** @brief When the ips status event is received, analyzes it */ 506ea2b22ebSSheldon Bailey virtual void analyzeIpsEvent(); 507ea2b22ebSSheldon Bailey 508ea2b22ebSSheldon Bailey protected: 509ea2b22ebSSheldon Bailey /** @brief File descriptor to watch for errors */ 510ea2b22ebSSheldon Bailey int fd = -1; 5111d51da29SChris Cain }; 5121d51da29SChris Cain 51378e86012SChris Cain } // namespace powermode 51478e86012SChris Cain 51578e86012SChris Cain } // namespace occ 51678e86012SChris Cain 51778e86012SChris Cain } // namespace open_power 51878e86012SChris Cain #endif 519