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> serializeopen_power::occ::powermode::PowerModeData8136f9cdedSChris 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 */ OccPersistData()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 */ updateMode(const SysPwrMode newMode,const uint16_t oemModeData)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 */ updateModeLock(const bool modeLock)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 */ updateIPS(const bool enabled,const uint8_t enterUtil,const uint16_t enterTime,const uint8_t exitUtil,const uint16_t exitTime)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 */ getMode(SysPwrMode & mode,uint16_t & oemModeData) const1591be4337bSChris 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 */ getIPS(bool & enabled,uint8_t & enterUtil,uint16_t & enterTime,uint8_t & exitUtil,uint16_t & exitTime)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 */ getModeLock()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 */ modeAvailable()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 */ ipsAvailable()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 */ invalidateMode()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 244*1fe436dcSChris Cain class PowerMode : public ModeInterface 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 */ setMasterActive(const bool isActive=true)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 342*1fe436dcSChris Cain /** @brief If IPS is supported, set flag indicating need to send IPS data */ needToSendIPS()343*1fe436dcSChris Cain void needToSendIPS() 344*1fe436dcSChris Cain { 345*1fe436dcSChris Cain if (ipsObject) 346*1fe436dcSChris Cain { 347*1fe436dcSChris Cain needToSendIpsData = true; 348*1fe436dcSChris Cain } 349*1fe436dcSChris Cain } 350*1fe436dcSChris Cain 35178e86012SChris Cain private: 35236f9cdedSChris Cain /** @brief OCC manager object */ 35336f9cdedSChris Cain const Manager& manager; 35436f9cdedSChris Cain 35536f9cdedSChris Cain /** @brief Pass-through occ path on the bus */ 35636f9cdedSChris Cain std::string path; 35736f9cdedSChris Cain 35836f9cdedSChris Cain /** @brief OCC instance number */ 35936f9cdedSChris Cain int occInstance; 36036f9cdedSChris Cain 36136f9cdedSChris Cain /** @brief Object to send commands to the OCC */ 3626fa848a9SChris Cain std::unique_ptr<open_power::occ::OccCommand> occCmd; 36336f9cdedSChris Cain 36436f9cdedSChris Cain /** @brief Used to subscribe to dbus IPS property changes **/ 36536f9cdedSChris Cain sdbusplus::bus::match_t ipsMatch; 36636f9cdedSChris Cain 3671be4337bSChris Cain /** @brief Used to subscribe to dbus defaults property changes **/ 3681be4337bSChris Cain sdbusplus::bus::match_t defaultsUpdateMatch; 3691be4337bSChris Cain 37036f9cdedSChris Cain OccPersistData persistedData; 37136f9cdedSChris Cain 37230040d9dSChris Cain /** @brief True when the master OCC has been established **/ 3736fa848a9SChris Cain bool masterOccSet; 3746fa848a9SChris Cain 37530040d9dSChris Cain /** @brief True when the master OCC is active **/ 37636f9cdedSChris Cain bool masterActive; 37736f9cdedSChris Cain 37830040d9dSChris Cain /** @brief True when the ecoModes are supported for this system **/ 37930040d9dSChris Cain bool ecoModeSupport = false; 38030040d9dSChris Cain 38130040d9dSChris Cain /** @brief List of customer supported power modes **/ 38230040d9dSChris Cain std::set<SysPwrMode> customerModeList = { 38330040d9dSChris Cain SysPwrMode::STATIC, SysPwrMode::POWER_SAVING, SysPwrMode::MAX_PERF}; 38430040d9dSChris Cain 38530040d9dSChris Cain /** @brief List of OEM supported power modes **/ 38630040d9dSChris Cain std::set<SysPwrMode> oemModeList = {SysPwrMode::SFP, SysPwrMode::FFO, 38730040d9dSChris Cain SysPwrMode::MAX_FREQ}; 38830040d9dSChris Cain 389ea2b22ebSSheldon Bailey /** @brief IPS status data filename to read */ 390d7542c83SPatrick Williams const fs::path ipsStatusFile = 391d7542c83SPatrick Williams std::filesystem::path{OCC_HWMON_PATH} / 392d7542c83SPatrick Williams std::filesystem::path{OCC_MASTER_NAME} / "occ_ips_status"; 393ea2b22ebSSheldon Bailey 394ea2b22ebSSheldon Bailey /** @brief Current state of error watching */ 395ea2b22ebSSheldon Bailey bool watching = false; 396ea2b22ebSSheldon Bailey 397*1fe436dcSChris Cain /** @brief Set at IPS object creation and cleared after sending IPS data */ 398*1fe436dcSChris Cain bool needToSendIpsData = false; 399*1fe436dcSChris Cain 400*1fe436dcSChris Cain /** @brief Object path for IPS on DBUS */ 401*1fe436dcSChris Cain const char* ipsObjectPath; 402*1fe436dcSChris Cain 403*1fe436dcSChris Cain /** @brief IPS DBUS Object */ 404*1fe436dcSChris Cain std::unique_ptr<IpsInterface> ipsObject; 405*1fe436dcSChris Cain 406ea2b22ebSSheldon Bailey /** @brief register for the callback from the POLL IPS changed event */ 407ea2b22ebSSheldon Bailey void registerIpsStatusCallBack(); 40878e86012SChris Cain 4091be4337bSChris Cain /** @brief Get the current power mode property 4101be4337bSChris Cain * 4111be4337bSChris Cain * @param[out] currentMode - current system power mode 4121be4337bSChris Cain * @param[out] oemModeData - frequency data for some OEM mode 4131be4337bSChris Cain * 4141be4337bSChris Cain * @return true if data read successfully 4151d51da29SChris Cain */ 4161be4337bSChris Cain bool getMode(SysPwrMode& currentMode, uint16_t& oemModeData); 4171d51da29SChris Cain 41836f9cdedSChris Cain /** @brief Update the power mode property on DBus 41936f9cdedSChris Cain * 42036f9cdedSChris Cain * @param[in] newMode - desired power mode 42136f9cdedSChris Cain * 42236f9cdedSChris Cain * @return true on success 42336f9cdedSChris Cain */ 42436f9cdedSChris Cain bool updateDbusMode(const SysPwrMode newMode); 42536f9cdedSChris Cain 4261d51da29SChris Cain /** @brief Callback for IPS setting changes 4271d51da29SChris Cain * 4281d51da29SChris Cain * Process change and inform OCC 4291d51da29SChris Cain * 4301d51da29SChris Cain * @param[in] msg - Data associated with IPS change signal 4311d51da29SChris Cain * 4321d51da29SChris Cain */ 433af40808fSPatrick Williams void ipsChanged(sdbusplus::message_t& msg); 4341d51da29SChris Cain 4351be4337bSChris Cain /** @brief Get the Idle Power Saver properties 4361be4337bSChris Cain * 4371be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 4381be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 4391be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 4401be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 4411be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 4421be4337bSChris Cain * 4431be4337bSChris Cain * @return true if data read successfully 44436f9cdedSChris Cain */ 4451be4337bSChris Cain bool getIPSParms(bool& enabled, uint8_t& enterUtil, uint16_t& enterTime, 4461be4337bSChris Cain uint8_t& exitUtil, uint16_t& exitTime); 4471be4337bSChris Cain 4481be4337bSChris Cain /** Update the Idle Power Saver data on DBus 4491be4337bSChris Cain * 4501be4337bSChris Cain * @param[in] enabled - Idle Power Save status (true = enabled) 4511be4337bSChris Cain * @param[in] enterUtil - IPS Enter Utilization (%) 4521be4337bSChris Cain * @param[in] enterTime - IPS Enter Time (seconds) 4531be4337bSChris Cain * @param[in] exitUtil - IPS Exit Utilization (%) 4541be4337bSChris Cain * @param[in] exitTime - IPS Exit Time (seconds) 4551be4337bSChris Cain * 4561be4337bSChris Cain * @return true if parameters were set successfully 4571be4337bSChris Cain */ 4581be4337bSChris Cain bool updateDbusIPS(const bool enabled, const uint8_t enterUtil, 4591be4337bSChris Cain const uint16_t enterTime, const uint8_t exitUtil, 4601be4337bSChris Cain const uint16_t exitTime); 4611be4337bSChris Cain 4621be4337bSChris Cain /** @brief Callback for entity manager default changes 4631be4337bSChris Cain * 4641be4337bSChris Cain * Called when PowerModeProperties defaults are available 4651be4337bSChris Cain */ 466af40808fSPatrick Williams void defaultsReady(sdbusplus::message_t& msg); 4671be4337bSChris Cain 4681be4337bSChris Cain /** @brief Get the default power mode property for this system type 4691be4337bSChris Cain * 4701be4337bSChris Cain * @param[out] defaultMode - default system power mode 4711be4337bSChris Cain * 4721be4337bSChris Cain * @return true if data read successfully 4731be4337bSChris Cain */ 4741be4337bSChris Cain bool getDefaultMode(SysPwrMode& defaultMode); 4751be4337bSChris Cain 4761be4337bSChris Cain /** @brief Get the default Idle Power Saver properties for this system type 4771be4337bSChris Cain * 4781be4337bSChris Cain * @param[out] enabled - Idle Power Save status (true = enabled) 4791be4337bSChris Cain * @param[out] enterUtil - IPS Enter Utilization (%) 4801be4337bSChris Cain * @param[out] enterTime - IPS Enter Time (seconds) 4811be4337bSChris Cain * @param[out] exitUtil - IPS Exit Utilization (%) 4821be4337bSChris Cain * @param[out] exitTime - IPS Exit Time (seconds) 4831be4337bSChris Cain * 4841be4337bSChris Cain * @return true if parameters were read successfully 4851be4337bSChris Cain */ 4861be4337bSChris Cain bool getDefaultIPSParms(bool& enabled, uint8_t& enterUtil, 4871be4337bSChris Cain uint16_t& enterTime, uint8_t& exitUtil, 48836f9cdedSChris Cain uint16_t& exitTime); 489cde7bea3SChris Cain 490cde7bea3SChris Cain /** @brief Read the default Idle Power Saver parameters and save them to the 491cde7bea3SChris Cain * DBUS so they will get used 492cde7bea3SChris Cain * 493cde7bea3SChris Cain * @return true if restore was successful 494cde7bea3SChris Cain */ 495cde7bea3SChris Cain bool useDefaultIPSParms(); 496ea2b22ebSSheldon Bailey 49730040d9dSChris Cain /** @brief Read the supported power modes from entity-manager and update 49830040d9dSChris Cain * AllowedPowerModes on dbus 49930040d9dSChris Cain * 50030040d9dSChris Cain * @return true if data was found/updated 50130040d9dSChris Cain */ 50230040d9dSChris Cain bool getSupportedModes(); 50330040d9dSChris Cain 504*1fe436dcSChris Cain /** @brief Create IPS DBUS Object */ 505*1fe436dcSChris Cain void createIpsObject(); 506*1fe436dcSChris Cain 507*1fe436dcSChris Cain /** @brief Remove IPS DBUS Object */ 508*1fe436dcSChris Cain void removeIpsObject(); 509*1fe436dcSChris Cain 510ea2b22ebSSheldon Bailey /** @brief callback for the POLL IPS changed event 511ea2b22ebSSheldon Bailey * 512ea2b22ebSSheldon Bailey * @param[in] es - Populated event source 513ea2b22ebSSheldon Bailey * @param[in] fd - Associated File descriptor 514ea2b22ebSSheldon Bailey * @param[in] revents - Type of event 515ea2b22ebSSheldon Bailey * @param[in] userData - User data that was passed during registration 516ea2b22ebSSheldon Bailey */ 517ea2b22ebSSheldon Bailey static int ipsStatusCallBack(sd_event_source* es, int fd, uint32_t revents, 518ea2b22ebSSheldon Bailey void* userData); 519ea2b22ebSSheldon Bailey 520ea2b22ebSSheldon Bailey /** @brief Opens the IPS file and populates fd */ 521ea2b22ebSSheldon Bailey bool openIpsFile(); 522ea2b22ebSSheldon Bailey 523ea2b22ebSSheldon Bailey /** @brief sd_event wrapped in unique_ptr */ 524ea2b22ebSSheldon Bailey EventPtr& event; 525ea2b22ebSSheldon Bailey 526ea2b22ebSSheldon Bailey /** @brief event source wrapped in unique_ptr */ 527ea2b22ebSSheldon Bailey EventSourcePtr eventSource; 528ea2b22ebSSheldon Bailey 529ea2b22ebSSheldon Bailey /** @brief When the ips status event is received, analyzes it */ 530ea2b22ebSSheldon Bailey virtual void analyzeIpsEvent(); 531ea2b22ebSSheldon Bailey 532ea2b22ebSSheldon Bailey protected: 533ea2b22ebSSheldon Bailey /** @brief File descriptor to watch for errors */ 534ea2b22ebSSheldon Bailey int fd = -1; 5351d51da29SChris Cain }; 5361d51da29SChris Cain 53778e86012SChris Cain } // namespace powermode 53878e86012SChris Cain 53978e86012SChris Cain } // namespace occ 54078e86012SChris Cain 54178e86012SChris Cain } // namespace open_power 54278e86012SChris Cain #endif 543