xref: /openbmc/openpower-occ-control/powermode.hpp (revision 1d51da2916fb1b2b2eae3499af6d330ef1c8c393)
178e86012SChris Cain #pragma once
278e86012SChris Cain 
378e86012SChris Cain #include "config.h"
478e86012SChris Cain 
5bddcf853SGeorge Liu #ifdef POWER10
678e86012SChris Cain #include "occ_status.hpp"
778e86012SChris Cain 
878e86012SChris Cain #include <sdbusplus/bus.hpp>
978e86012SChris Cain #include <sdbusplus/bus/match.hpp>
1078e86012SChris Cain 
11bcef3b48SGeorge Liu #include <filesystem>
12b5ca1015SGeorge Liu 
1378e86012SChris Cain namespace open_power
1478e86012SChris Cain {
1578e86012SChris Cain namespace occ
1678e86012SChris Cain {
1778e86012SChris Cain namespace powermode
1878e86012SChris Cain {
1978e86012SChris Cain 
2078e86012SChris Cain constexpr auto PMODE_PATH = "/xyz/openbmc_project/control/host0/power_mode";
2178e86012SChris Cain constexpr auto PMODE_INTERFACE = "xyz.openbmc_project.Control.Power.Mode";
2278e86012SChris Cain constexpr auto POWER_MODE_PROP = "PowerMode";
2378e86012SChris Cain 
24*1d51da29SChris Cain constexpr auto PIPS_PATH = "/xyz/openbmc_project/control/host0/power_ips";
25*1d51da29SChris Cain constexpr auto PIPS_INTERFACE =
26*1d51da29SChris Cain     "xyz.openbmc_project.Control.Power.IdlePowerSaver";
27*1d51da29SChris Cain constexpr auto IPS_ENABLED_PROP = "Enabled";
28*1d51da29SChris Cain constexpr auto IPS_ENTER_UTIL = "EnterUtilizationPercent";
29*1d51da29SChris Cain constexpr auto IPS_ENTER_TIME = "EnterDwellTime";
30*1d51da29SChris Cain constexpr auto IPS_EXIT_UTIL = "ExitUtilizationPercent";
31*1d51da29SChris Cain constexpr auto IPS_EXIT_TIME = "ExitDwellTime";
32*1d51da29SChris Cain 
3378e86012SChris Cain /** @brief Convert power mode string to OCC SysPwrMode value
3478e86012SChris Cain  *
3578e86012SChris Cain  * @param[in] i_modeString - power mode string
3678e86012SChris Cain  *
3778e86012SChris Cain  * @return  SysPwrMode or SysPwrMode::NO_CHANGE if not found
3878e86012SChris Cain  */
3978e86012SChris Cain SysPwrMode convertStringToMode(const std::string& i_modeString);
4078e86012SChris Cain 
4178e86012SChris Cain /** @class PowerMode
4278e86012SChris Cain  *  @brief Monitors for changes to the power mode and notifies occ
4378e86012SChris Cain  *
4478e86012SChris Cain  *  The customer power mode is provided to the OCC by host TMGT when the occ
4578e86012SChris Cain  *  first goes active or is reset.  This code is responsible for sending
4678e86012SChris Cain  *  the power mode to the OCC if the mode is changed while the occ is active.
4778e86012SChris Cain  */
4878e86012SChris Cain 
4978e86012SChris Cain class PowerMode
5078e86012SChris Cain {
5178e86012SChris Cain   public:
5278e86012SChris Cain     /** @brief PowerMode object to inform occ of changes to mode
5378e86012SChris Cain      *
5478e86012SChris Cain      * This object will monitor for changes to the power mode setting.
5578e86012SChris Cain      * If a change is detected, and the occ is active, then this object will
5678e86012SChris Cain      * notify the OCC of the change.
5778e86012SChris Cain      *
5878e86012SChris Cain      * @param[in] occStatus - The occ status object
5978e86012SChris Cain      */
6078e86012SChris Cain     PowerMode(Status& occStatus) :
6178e86012SChris Cain         occStatus(occStatus),
6278e86012SChris Cain         pmodeMatch(utils::getBus(),
6378e86012SChris Cain                    sdbusplus::bus::match::rules::propertiesChanged(
6478e86012SChris Cain                        PMODE_PATH, PMODE_INTERFACE),
6578e86012SChris Cain                    [this](auto& msg) { this->modeChanged(msg); }){};
6678e86012SChris Cain 
6778e86012SChris Cain   private:
6878e86012SChris Cain     /** @brief Callback for pmode setting changes
6978e86012SChris Cain      *
7078e86012SChris Cain      * Process change and inform OCC
7178e86012SChris Cain      *
7278e86012SChris Cain      * @param[in]  msg       - Data associated with pmode change signal
7378e86012SChris Cain      *
7478e86012SChris Cain      */
7578e86012SChris Cain     void modeChanged(sdbusplus::message::message& msg);
7678e86012SChris Cain 
7778e86012SChris Cain     /* @brief OCC Status object */
7878e86012SChris Cain     Status& occStatus;
7978e86012SChris Cain 
8078e86012SChris Cain     /** @brief Used to subscribe to dbus pmode property changes **/
8178e86012SChris Cain     sdbusplus::bus::match_t pmodeMatch;
8278e86012SChris Cain };
8378e86012SChris Cain 
84*1d51da29SChris Cain class PowerIPS
85*1d51da29SChris Cain {
86*1d51da29SChris Cain   public:
87*1d51da29SChris Cain     /** @brief PowerIPS object to inform occ of changes to Idle Power Saver
88*1d51da29SChris Cain      * parms
89*1d51da29SChris Cain      *
90*1d51da29SChris Cain      * This object will monitor for changes to the Idle Power Saver settings.
91*1d51da29SChris Cain      * If a change is detected, and the occ is active, then this object will
92*1d51da29SChris Cain      * notify the OCC of the change.
93*1d51da29SChris Cain      *
94*1d51da29SChris Cain      * @param[in] occStatus - The occ status object
95*1d51da29SChris Cain      */
96*1d51da29SChris Cain     PowerIPS(Status& occStatus) :
97*1d51da29SChris Cain         occStatus(occStatus),
98*1d51da29SChris Cain         ipsMatch(utils::getBus(),
99*1d51da29SChris Cain                  sdbusplus::bus::match::rules::propertiesChanged(
100*1d51da29SChris Cain                      PIPS_PATH, PIPS_INTERFACE),
101*1d51da29SChris Cain                  [this](auto& msg) { this->ipsChanged(msg); }){};
102*1d51da29SChris Cain 
103*1d51da29SChris Cain   private:
104*1d51da29SChris Cain     /** @brief Callback for IPS setting changes
105*1d51da29SChris Cain      *
106*1d51da29SChris Cain      * Process change and inform OCC
107*1d51da29SChris Cain      *
108*1d51da29SChris Cain      * @param[in]  msg       - Data associated with IPS change signal
109*1d51da29SChris Cain      *
110*1d51da29SChris Cain      */
111*1d51da29SChris Cain     void ipsChanged(sdbusplus::message::message& msg);
112*1d51da29SChris Cain 
113*1d51da29SChris Cain     /* @brief OCC Status object */
114*1d51da29SChris Cain     Status& occStatus;
115*1d51da29SChris Cain 
116*1d51da29SChris Cain     /** @brief Used to subscribe to dbus IPS property changes **/
117*1d51da29SChris Cain     sdbusplus::bus::match_t ipsMatch;
118*1d51da29SChris Cain };
119*1d51da29SChris Cain 
12078e86012SChris Cain } // namespace powermode
12178e86012SChris Cain 
12278e86012SChris Cain } // namespace occ
12378e86012SChris Cain 
12478e86012SChris Cain } // namespace open_power
12578e86012SChris Cain #endif
126