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/archives/binary.hpp> 1036f9cdedSChris Cain #include <cereal/cereal.hpp> 1136f9cdedSChris Cain #include <cereal/types/string.hpp> 1236f9cdedSChris Cain #include <cereal/types/tuple.hpp> 1336f9cdedSChris Cain #include <cereal/types/vector.hpp> 1478e86012SChris Cain #include <sdbusplus/bus.hpp> 1578e86012SChris Cain #include <sdbusplus/bus/match.hpp> 161be4337bSChris Cain #include <xyz/openbmc_project/Control/Power/IdlePowerSaver/server.hpp> 171be4337bSChris Cain #include <xyz/openbmc_project/Control/Power/Mode/server.hpp> 1878e86012SChris Cain 19bcef3b48SGeorge Liu #include <filesystem> 20b5ca1015SGeorge Liu 2178e86012SChris Cain namespace open_power 2278e86012SChris Cain { 2378e86012SChris Cain namespace occ 2478e86012SChris Cain { 2536f9cdedSChris Cain 2636f9cdedSChris Cain class Manager; 2736f9cdedSChris Cain 2878e86012SChris Cain namespace powermode 2978e86012SChris Cain { 301be4337bSChris Cain namespace Base = sdbusplus::xyz::openbmc_project::Control::Power::server; 311be4337bSChris Cain using ModeInterface = sdbusplus::server::object::object<Base::Mode>; 321be4337bSChris Cain using IpsInterface = sdbusplus::server::object::object<Base::IdlePowerSaver>; 331be4337bSChris Cain using namespace std::literals::string_literals; 3478e86012SChris Cain 3578e86012SChris Cain constexpr auto PMODE_PATH = "/xyz/openbmc_project/control/host0/power_mode"; 3678e86012SChris Cain constexpr auto PMODE_INTERFACE = "xyz.openbmc_project.Control.Power.Mode"; 3778e86012SChris Cain constexpr auto POWER_MODE_PROP = "PowerMode"; 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"; 42*ea2b22ebSSheldon 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; 7636f9cdedSChris Cain 7736f9cdedSChris Cain /** @brief Function specifying data to archive for cereal. 7836f9cdedSChris Cain */ 7936f9cdedSChris Cain template <class Archive> 8036f9cdedSChris Cain void serialize(Archive& archive) 8136f9cdedSChris Cain { 821be4337bSChris Cain archive(modeInitialized, mode, oemModeData, ipsInitialized, ipsEnabled, 831be4337bSChris Cain ipsEnterUtil, ipsEnterTime, ipsExitUtil, ipsExitTime); 8436f9cdedSChris Cain } 8536f9cdedSChris Cain }; 8636f9cdedSChris Cain 8736f9cdedSChris Cain /** @class OccPersistData 8836f9cdedSChris Cain * @brief Provides persistent container to store data for OCC 8936f9cdedSChris Cain * 9036f9cdedSChris Cain * Data is stored via cereal 9136f9cdedSChris Cain */ 9236f9cdedSChris Cain class OccPersistData 9336f9cdedSChris Cain { 9436f9cdedSChris Cain public: 9536f9cdedSChris Cain ~OccPersistData() = default; 9636f9cdedSChris Cain OccPersistData(const OccPersistData&) = default; 9736f9cdedSChris Cain OccPersistData& operator=(const OccPersistData&) = default; 9836f9cdedSChris Cain OccPersistData(OccPersistData&&) = default; 9936f9cdedSChris Cain OccPersistData& operator=(OccPersistData&&) = default; 10036f9cdedSChris Cain 1011be4337bSChris Cain /** @brief Loads any saved power mode data */ 10236f9cdedSChris Cain OccPersistData() 10336f9cdedSChris Cain { 10436f9cdedSChris Cain load(); 10536f9cdedSChris Cain } 10636f9cdedSChris Cain 10736f9cdedSChris Cain /** @brief Save Power Mode data to persistent file 10836f9cdedSChris Cain * 1091be4337bSChris Cain * @param[in] newMode - desired System Power Mode 1101be4337bSChris Cain * @param[in] oemModeData - data required by some OEM Power Modes 11136f9cdedSChris Cain */ 1121be4337bSChris Cain void updateMode(const SysPwrMode newMode, const uint16_t oemModeData) 11336f9cdedSChris Cain { 1141be4337bSChris Cain modeData.mode = newMode; 1151be4337bSChris Cain modeData.oemModeData = oemModeData; 1161be4337bSChris Cain modeData.modeInitialized = true; 11736f9cdedSChris Cain save(); 11836f9cdedSChris Cain } 11936f9cdedSChris Cain 1201be4337bSChris Cain /** @brief Write Idle Power Saver parameters to persistent file 12136f9cdedSChris Cain * 1221be4337bSChris Cain * @param[in] enabled - Idle Power Save status (true = enabled) 1231be4337bSChris Cain * @param[in] enterUtil - IPS Enter Utilization (%) 1241be4337bSChris Cain * @param[in] enterTime - IPS Enter Time (seconds) 1251be4337bSChris Cain * @param[in] exitUtil - IPS Exit Utilization (%) 1261be4337bSChris Cain * @param[in] exitTime - IPS Exit Time (seconds) 12736f9cdedSChris Cain */ 1281be4337bSChris Cain void updateIPS(const bool enabled, const uint8_t enterUtil, 1291be4337bSChris Cain const uint16_t enterTime, const uint8_t exitUtil, 1301be4337bSChris Cain const uint16_t exitTime) 13136f9cdedSChris Cain { 1321be4337bSChris Cain modeData.ipsEnabled = enabled; 1331be4337bSChris Cain modeData.ipsEnterUtil = enterUtil; 1341be4337bSChris Cain modeData.ipsEnterTime = enterTime; 1351be4337bSChris Cain modeData.ipsExitUtil = exitUtil; 1361be4337bSChris Cain modeData.ipsExitTime = exitTime; 1371be4337bSChris Cain modeData.ipsInitialized = true; 1381be4337bSChris Cain save(); 1391be4337bSChris Cain } 1401be4337bSChris Cain 1411be4337bSChris Cain /** @brief Return the Power Mode and mode data 1421be4337bSChris Cain * 1431be4337bSChris Cain * @param[out] mode - current system power mode 1441be4337bSChris Cain * @param[out] oemModeData - frequency data for some OEM mode 1451be4337bSChris Cain * 1461be4337bSChris Cain * @returns true if mode was available 1471be4337bSChris Cain */ 1481be4337bSChris Cain bool getMode(SysPwrMode& mode, uint16_t& oemModeData) const 1491be4337bSChris Cain { 1501be4337bSChris Cain if (!modeData.modeInitialized) 15136f9cdedSChris Cain { 15236f9cdedSChris Cain return false; 15336f9cdedSChris Cain } 15436f9cdedSChris Cain 1551be4337bSChris Cain mode = modeData.mode; 1561be4337bSChris Cain oemModeData = modeData.oemModeData; 15736f9cdedSChris Cain return true; 15836f9cdedSChris Cain } 15936f9cdedSChris Cain 1601be4337bSChris Cain /** @brief Get the Idle Power Saver properties from DBus 1611be4337bSChris Cain * 1621be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 1631be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 1641be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 1651be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 1661be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 1671be4337bSChris Cain * 1681be4337bSChris Cain * @return true if parameters were read successfully 1691be4337bSChris Cain */ 1701be4337bSChris Cain bool getIPS(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, 1711be4337bSChris Cain uint8_t& exitUtil, uint16_t& exitTime) 1721be4337bSChris Cain { 1731be4337bSChris Cain if (!modeData.ipsInitialized) 1741be4337bSChris Cain { 1751be4337bSChris Cain return false; 1761be4337bSChris Cain } 1771be4337bSChris Cain 1781be4337bSChris Cain enabled = modeData.ipsEnabled; 1791be4337bSChris Cain enterUtil = modeData.ipsEnterUtil; 1801be4337bSChris Cain enterTime = modeData.ipsEnterTime; 1811be4337bSChris Cain exitUtil = modeData.ipsExitUtil; 1821be4337bSChris Cain exitTime = modeData.ipsExitTime; 1831be4337bSChris Cain return true; 1841be4337bSChris Cain } 1851be4337bSChris Cain 1861be4337bSChris Cain /** @brief Return true if the power mode is available */ 1871be4337bSChris Cain bool modeAvailable() 1881be4337bSChris Cain { 1891be4337bSChris Cain return (modeData.modeInitialized); 1901be4337bSChris Cain } 1911be4337bSChris Cain 192cde7bea3SChris Cain /** @brief Return true if the IPS data is available */ 1931be4337bSChris Cain bool ipsAvailable() 1941be4337bSChris Cain { 1951be4337bSChris Cain return (modeData.ipsInitialized); 1961be4337bSChris Cain } 1971be4337bSChris Cain 19836f9cdedSChris Cain /** @brief Saves the Power Mode data in the filesystem using cereal. */ 19936f9cdedSChris Cain void save(); 20036f9cdedSChris Cain 2011be4337bSChris Cain /** @brief Trace the Power Mode and IPS parameters. */ 2021be4337bSChris Cain void print(); 20336f9cdedSChris Cain 20436f9cdedSChris Cain private: 2051be4337bSChris Cain /** @brief Power Mode data filename to store persistent data */ 2061be4337bSChris Cain static constexpr auto powerModeFilename = "powerModeData"; 20736f9cdedSChris Cain 2081be4337bSChris Cain /** @brief Power Mode data object to be persisted */ 2091be4337bSChris Cain PowerModeData modeData; 21036f9cdedSChris Cain 21136f9cdedSChris Cain /** @brief Loads the OEM mode data in the filesystem using cereal. */ 21236f9cdedSChris Cain void load(); 21336f9cdedSChris Cain }; 21436f9cdedSChris Cain 21578e86012SChris Cain /** @class PowerMode 21678e86012SChris Cain * @brief Monitors for changes to the power mode and notifies occ 21778e86012SChris Cain * 21878e86012SChris Cain * The customer power mode is provided to the OCC by host TMGT when the occ 21978e86012SChris Cain * first goes active or is reset. This code is responsible for sending 22078e86012SChris Cain * the power mode to the OCC if the mode is changed while the occ is active. 22178e86012SChris Cain */ 22278e86012SChris Cain 2231be4337bSChris Cain class PowerMode : public ModeInterface, public IpsInterface 22478e86012SChris Cain { 22578e86012SChris Cain public: 22678e86012SChris Cain /** @brief PowerMode object to inform occ of changes to mode 22778e86012SChris Cain * 22878e86012SChris Cain * This object will monitor for changes to the power mode setting. 22978e86012SChris Cain * If a change is detected, and the occ is active, then this object will 23078e86012SChris Cain * notify the OCC of the change. 23178e86012SChris Cain * 2321be4337bSChris Cain * @param[in] managerRef - manager object reference 2331be4337bSChris Cain * @param[in] modePath - Power Mode dbus path 2341be4337bSChris Cain * @param[in] ipsPath - Idle Power Saver dbus path 23578e86012SChris Cain */ 2361be4337bSChris Cain explicit PowerMode(const Manager& managerRef, const char* modePath, 237*ea2b22ebSSheldon Bailey const char* ipsPath 238*ea2b22ebSSheldon Bailey #ifdef POWER10 239*ea2b22ebSSheldon Bailey , 240*ea2b22ebSSheldon Bailey EventPtr& event 241*ea2b22ebSSheldon Bailey #endif 242*ea2b22ebSSheldon Bailey ) : 2431be4337bSChris Cain ModeInterface(utils::getBus(), modePath, false), 2441be4337bSChris Cain IpsInterface(utils::getBus(), ipsPath, false), manager(managerRef), 24578e86012SChris Cain pmodeMatch(utils::getBus(), 24678e86012SChris Cain sdbusplus::bus::match::rules::propertiesChanged( 24778e86012SChris Cain PMODE_PATH, PMODE_INTERFACE), 24836f9cdedSChris Cain [this](auto& msg) { this->modeChanged(msg); }), 24936f9cdedSChris Cain ipsMatch(utils::getBus(), 25036f9cdedSChris Cain sdbusplus::bus::match::rules::propertiesChanged( 25136f9cdedSChris Cain PIPS_PATH, PIPS_INTERFACE), 25236f9cdedSChris Cain [this](auto& msg) { this->ipsChanged(msg); }), 2531be4337bSChris Cain defaultsUpdateMatch( 2541be4337bSChris Cain utils::getBus(), 2551be4337bSChris Cain sdbusplus::bus::match::rules::propertiesChangedNamespace( 2561be4337bSChris Cain "/xyz/openbmc_project/inventory", PMODE_DEFAULT_INTERFACE), 2571be4337bSChris Cain [this](auto& msg) { this->defaultsReady(msg); }), 2581be4337bSChris Cain masterOccSet(false), masterActive(false) 259*ea2b22ebSSheldon Bailey #ifdef POWER10 260*ea2b22ebSSheldon Bailey , 261*ea2b22ebSSheldon Bailey event(event) 262*ea2b22ebSSheldon Bailey #endif 2631be4337bSChris Cain { 2641be4337bSChris Cain // restore Power Mode to DBus 2651be4337bSChris Cain SysPwrMode currentMode; 2661be4337bSChris Cain uint16_t oemModeData = 0; 2671be4337bSChris Cain if (getMode(currentMode, oemModeData)) 2681be4337bSChris Cain { 2691be4337bSChris Cain updateDbusMode(currentMode); 2701be4337bSChris Cain } 2711be4337bSChris Cain // restore Idle Power Saver parameters to DBus 2721be4337bSChris Cain uint8_t enterUtil, exitUtil; 2731be4337bSChris Cain uint16_t enterTime, exitTime; 2741be4337bSChris Cain bool ipsEnabled; 2751be4337bSChris Cain if (getIPSParms(ipsEnabled, enterUtil, enterTime, exitUtil, exitTime)) 2761be4337bSChris Cain { 2771be4337bSChris Cain updateDbusIPS(ipsEnabled, enterUtil, enterTime, exitUtil, exitTime); 2781be4337bSChris Cain } 2791be4337bSChris Cain }; 28036f9cdedSChris Cain 2811be4337bSChris Cain /** @brief Initialize the persistent data with default values 2821be4337bSChris Cain * 2831be4337bSChris Cain * @return true if initialization completed 2841be4337bSChris Cain */ 2851be4337bSChris Cain bool initPersistentData(); 2861be4337bSChris Cain 2871be4337bSChris Cain /** @brief Set the current power mode property 2881be4337bSChris Cain * 2891be4337bSChris Cain * @param[in] newMode - desired system power mode 2901be4337bSChris Cain * @param[in] oemModeData - data required by some OEM Power Modes 2911be4337bSChris Cain * 2921be4337bSChris Cain * @return true if mode accepted 2931be4337bSChris Cain */ 2941be4337bSChris Cain bool setMode(const SysPwrMode newMode, const uint16_t oemModeData); 29536f9cdedSChris Cain 29636f9cdedSChris Cain /** @brief Send mode change command to the master OCC 29736f9cdedSChris Cain * @return SUCCESS on success 29836f9cdedSChris Cain */ 29936f9cdedSChris Cain CmdStatus sendModeChange(); 30036f9cdedSChris Cain 30136f9cdedSChris Cain /** @brief Send Idle Power Saver config data to the master OCC 30236f9cdedSChris Cain * @return SUCCESS on success 30336f9cdedSChris Cain */ 30436f9cdedSChris Cain CmdStatus sendIpsData(); 30536f9cdedSChris Cain 3066fa848a9SChris Cain /** @brief Set the master OCC path 3076fa848a9SChris Cain * 3086fa848a9SChris Cain * @param[in] occPath - hwmon path for master OCC 3096fa848a9SChris Cain */ 3106fa848a9SChris Cain void setMasterOcc(const std::string& occPath); 3116fa848a9SChris Cain 31236f9cdedSChris Cain /** @brief Notify object of master OCC state. If not acitve, no 31336f9cdedSChris Cain * commands will be sent to the master OCC 31436f9cdedSChris Cain * 31536f9cdedSChris Cain * @param[in] isActive - true when master OCC is active 31636f9cdedSChris Cain */ 31736f9cdedSChris Cain void setMasterActive(const bool isActive = true) 31836f9cdedSChris Cain { 31936f9cdedSChris Cain masterActive = isActive; 32036f9cdedSChris Cain }; 32178e86012SChris Cain 322*ea2b22ebSSheldon Bailey #ifdef POWER10 323*ea2b22ebSSheldon Bailey /** @brief Starts to monitor for IPS active state change conditions 324*ea2b22ebSSheldon Bailey * 325*ea2b22ebSSheldon Bailey * @param[in] poll - Indicates whether or not the IPS state file should 326*ea2b22ebSSheldon Bailey * actually be read for changes. 327*ea2b22ebSSheldon Bailey */ 328*ea2b22ebSSheldon Bailey void addIpsWatch(bool poll = true); 329*ea2b22ebSSheldon Bailey 330*ea2b22ebSSheldon Bailey /** @brief Removes IPS active watch */ 331*ea2b22ebSSheldon Bailey void removeIpsWatch(); 332*ea2b22ebSSheldon Bailey #endif 333*ea2b22ebSSheldon Bailey 33478e86012SChris Cain private: 33536f9cdedSChris Cain /** @brief OCC manager object */ 33636f9cdedSChris Cain const Manager& manager; 33736f9cdedSChris Cain 33836f9cdedSChris Cain /** @brief Pass-through occ path on the bus */ 33936f9cdedSChris Cain std::string path; 34036f9cdedSChris Cain 34136f9cdedSChris Cain /** @brief OCC instance number */ 34236f9cdedSChris Cain int occInstance; 34336f9cdedSChris Cain 34436f9cdedSChris Cain /** @brief Object to send commands to the OCC */ 3456fa848a9SChris Cain std::unique_ptr<open_power::occ::OccCommand> occCmd; 34636f9cdedSChris Cain 34736f9cdedSChris Cain /** @brief Used to subscribe to dbus pmode property changes **/ 34836f9cdedSChris Cain sdbusplus::bus::match_t pmodeMatch; 34936f9cdedSChris Cain 35036f9cdedSChris Cain /** @brief Used to subscribe to dbus IPS property changes **/ 35136f9cdedSChris Cain sdbusplus::bus::match_t ipsMatch; 35236f9cdedSChris Cain 3531be4337bSChris Cain /** @brief Used to subscribe to dbus defaults property changes **/ 3541be4337bSChris Cain sdbusplus::bus::match_t defaultsUpdateMatch; 3551be4337bSChris Cain 35636f9cdedSChris Cain OccPersistData persistedData; 35736f9cdedSChris Cain 3586fa848a9SChris Cain /** @brief True when the master OCC has been established */ 3596fa848a9SChris Cain bool masterOccSet; 3606fa848a9SChris Cain 3616fa848a9SChris Cain /** @brief True when the master OCC is active */ 36236f9cdedSChris Cain bool masterActive; 36336f9cdedSChris Cain 364*ea2b22ebSSheldon Bailey #ifdef POWER10 365*ea2b22ebSSheldon Bailey /** @brief IPS status data filename to read */ 366*ea2b22ebSSheldon Bailey const fs::path ipsStatusFile = std::filesystem::path{OCC_HWMON_PATH} / 367*ea2b22ebSSheldon Bailey std::filesystem::path{OCC_MASTER_NAME} / 368*ea2b22ebSSheldon Bailey "occ_ips_status"; 369*ea2b22ebSSheldon Bailey 370*ea2b22ebSSheldon Bailey /** @brief Current state of error watching */ 371*ea2b22ebSSheldon Bailey bool watching = false; 372*ea2b22ebSSheldon Bailey 373*ea2b22ebSSheldon Bailey /** @brief register for the callback from the POLL IPS changed event */ 374*ea2b22ebSSheldon Bailey void registerIpsStatusCallBack(); 375*ea2b22ebSSheldon Bailey #endif 376*ea2b22ebSSheldon Bailey 37778e86012SChris Cain /** @brief Callback for pmode setting changes 37878e86012SChris Cain * 37978e86012SChris Cain * Process change and inform OCC 38078e86012SChris Cain * 38178e86012SChris Cain * @param[in] msg - Data associated with pmode change signal 38278e86012SChris Cain * 38378e86012SChris Cain */ 38478e86012SChris Cain void modeChanged(sdbusplus::message::message& msg); 38578e86012SChris Cain 3861be4337bSChris Cain /** @brief Get the current power mode property 3871be4337bSChris Cain * 3881be4337bSChris Cain * @param[out] currentMode - current system power mode 3891be4337bSChris Cain * @param[out] oemModeData - frequency data for some OEM mode 3901be4337bSChris Cain * 3911be4337bSChris Cain * @return true if data read successfully 3921d51da29SChris Cain */ 3931be4337bSChris Cain bool getMode(SysPwrMode& currentMode, uint16_t& oemModeData); 3941d51da29SChris Cain 39536f9cdedSChris Cain /** @brief Update the power mode property on DBus 39636f9cdedSChris Cain * 39736f9cdedSChris Cain * @param[in] newMode - desired power mode 39836f9cdedSChris Cain * 39936f9cdedSChris Cain * @return true on success 40036f9cdedSChris Cain */ 40136f9cdedSChris Cain bool updateDbusMode(const SysPwrMode newMode); 40236f9cdedSChris Cain 4031d51da29SChris Cain /** @brief Callback for IPS setting changes 4041d51da29SChris Cain * 4051d51da29SChris Cain * Process change and inform OCC 4061d51da29SChris Cain * 4071d51da29SChris Cain * @param[in] msg - Data associated with IPS change signal 4081d51da29SChris Cain * 4091d51da29SChris Cain */ 4101d51da29SChris Cain void ipsChanged(sdbusplus::message::message& msg); 4111d51da29SChris Cain 4121be4337bSChris Cain /** @brief Get the Idle Power Saver properties 4131be4337bSChris Cain * 4141be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 4151be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 4161be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 4171be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 4181be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 4191be4337bSChris Cain * 4201be4337bSChris Cain * @return true if data read successfully 42136f9cdedSChris Cain */ 4221be4337bSChris Cain bool getIPSParms(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, 4231be4337bSChris Cain uint8_t& exitUtil, uint16_t& exitTime); 4241be4337bSChris Cain 4251be4337bSChris Cain /** Update the Idle Power Saver data on DBus 4261be4337bSChris Cain * 4271be4337bSChris Cain * @param[in] enabled - Idle Power Save status (true = enabled) 4281be4337bSChris Cain * @param[in] enterUtil - IPS Enter Utilization (%) 4291be4337bSChris Cain * @param[in] enterTime - IPS Enter Time (seconds) 4301be4337bSChris Cain * @param[in] exitUtil - IPS Exit Utilization (%) 4311be4337bSChris Cain * @param[in] exitTime - IPS Exit Time (seconds) 4321be4337bSChris Cain * 4331be4337bSChris Cain * @return true if parameters were set successfully 4341be4337bSChris Cain */ 4351be4337bSChris Cain bool updateDbusIPS(const bool enabled, const uint8_t enterUtil, 4361be4337bSChris Cain const uint16_t enterTime, const uint8_t exitUtil, 4371be4337bSChris Cain const uint16_t exitTime); 4381be4337bSChris Cain 4391be4337bSChris Cain /** @brief Callback for entity manager default changes 4401be4337bSChris Cain * 4411be4337bSChris Cain * Called when PowerModeProperties defaults are available 4421be4337bSChris Cain */ 4431be4337bSChris Cain void defaultsReady(sdbusplus::message::message& msg); 4441be4337bSChris Cain 4451be4337bSChris Cain /** @brief Get the default power mode property for this system type 4461be4337bSChris Cain * 4471be4337bSChris Cain * @param[out] defaultMode - default system power mode 4481be4337bSChris Cain * 4491be4337bSChris Cain * @return true if data read successfully 4501be4337bSChris Cain */ 4511be4337bSChris Cain bool getDefaultMode(SysPwrMode& defaultMode); 4521be4337bSChris Cain 4531be4337bSChris Cain /** @brief Get the default Idle Power Saver properties for this system type 4541be4337bSChris Cain * 4551be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 4561be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 4571be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 4581be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 4591be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 4601be4337bSChris Cain * 4611be4337bSChris Cain * @return true if parameters were read successfully 4621be4337bSChris Cain */ 4631be4337bSChris Cain bool getDefaultIPSParms(bool& enabled, uint8_t& enterUtil, 4641be4337bSChris Cain uint16_t& enterTime, uint8_t& exitUtil, 46536f9cdedSChris Cain uint16_t& exitTime); 466cde7bea3SChris Cain 467cde7bea3SChris Cain /** @brief Read the default Idle Power Saver parameters and save them to the 468cde7bea3SChris Cain * DBUS so they will get used 469cde7bea3SChris Cain * 470cde7bea3SChris Cain * @return true if restore was successful 471cde7bea3SChris Cain */ 472cde7bea3SChris Cain bool useDefaultIPSParms(); 473*ea2b22ebSSheldon Bailey 474*ea2b22ebSSheldon Bailey #ifdef POWER10 475*ea2b22ebSSheldon Bailey /** @brief callback for the POLL IPS changed event 476*ea2b22ebSSheldon Bailey * 477*ea2b22ebSSheldon Bailey * @param[in] es - Populated event source 478*ea2b22ebSSheldon Bailey * @param[in] fd - Associated File descriptor 479*ea2b22ebSSheldon Bailey * @param[in] revents - Type of event 480*ea2b22ebSSheldon Bailey * @param[in] userData - User data that was passed during registration 481*ea2b22ebSSheldon Bailey */ 482*ea2b22ebSSheldon Bailey static int ipsStatusCallBack(sd_event_source* es, int fd, uint32_t revents, 483*ea2b22ebSSheldon Bailey void* userData); 484*ea2b22ebSSheldon Bailey 485*ea2b22ebSSheldon Bailey /** @brief Opens the IPS file and populates fd */ 486*ea2b22ebSSheldon Bailey bool openIpsFile(); 487*ea2b22ebSSheldon Bailey 488*ea2b22ebSSheldon Bailey /** @brief sd_event wrapped in unique_ptr */ 489*ea2b22ebSSheldon Bailey EventPtr& event; 490*ea2b22ebSSheldon Bailey 491*ea2b22ebSSheldon Bailey /** @brief event source wrapped in unique_ptr */ 492*ea2b22ebSSheldon Bailey EventSourcePtr eventSource; 493*ea2b22ebSSheldon Bailey 494*ea2b22ebSSheldon Bailey /** @brief When the ips status event is received, analyzes it */ 495*ea2b22ebSSheldon Bailey virtual void analyzeIpsEvent(); 496*ea2b22ebSSheldon Bailey 497*ea2b22ebSSheldon Bailey protected: 498*ea2b22ebSSheldon Bailey /** @brief File descriptor to watch for errors */ 499*ea2b22ebSSheldon Bailey int fd = -1; 500*ea2b22ebSSheldon Bailey #endif 5011d51da29SChris Cain }; 5021d51da29SChris Cain 50378e86012SChris Cain } // namespace powermode 50478e86012SChris Cain 50578e86012SChris Cain } // namespace occ 50678e86012SChris Cain 50778e86012SChris Cain } // namespace open_power 50878e86012SChris Cain #endif 509