blob: c9d3f0eaa26e0fc5ca1498927d7498465534c618 [file] [log] [blame]
Chris Cain78e86012021-03-04 16:15:31 -06001#pragma once
2
Chris Cain78e86012021-03-04 16:15:31 -06003#include "config.h"
4
George Liubddcf852021-09-08 08:46:22 +08005#ifdef POWER10
Chris Cain78e86012021-03-04 16:15:31 -06006#include "occ_status.hpp"
7
Chris Cain78e86012021-03-04 16:15:31 -06008#include <sdbusplus/bus.hpp>
9#include <sdbusplus/bus/match.hpp>
10
George Liubcef3b42021-09-10 12:39:02 +080011#include <filesystem>
George Liub5ca1012021-09-10 12:53:11 +080012
Chris Cain78e86012021-03-04 16:15:31 -060013namespace open_power
14{
15namespace occ
16{
17namespace powermode
18{
19
20constexpr auto PMODE_PATH = "/xyz/openbmc_project/control/host0/power_mode";
21constexpr auto PMODE_INTERFACE = "xyz.openbmc_project.Control.Power.Mode";
22constexpr auto POWER_MODE_PROP = "PowerMode";
23
Chris Cain1d51da22021-09-21 14:13:41 -050024constexpr auto PIPS_PATH = "/xyz/openbmc_project/control/host0/power_ips";
25constexpr auto PIPS_INTERFACE =
26 "xyz.openbmc_project.Control.Power.IdlePowerSaver";
27constexpr auto IPS_ENABLED_PROP = "Enabled";
28constexpr auto IPS_ENTER_UTIL = "EnterUtilizationPercent";
29constexpr auto IPS_ENTER_TIME = "EnterDwellTime";
30constexpr auto IPS_EXIT_UTIL = "ExitUtilizationPercent";
31constexpr auto IPS_EXIT_TIME = "ExitDwellTime";
32
Chris Cain78e86012021-03-04 16:15:31 -060033/** @brief Convert power mode string to OCC SysPwrMode value
34 *
35 * @param[in] i_modeString - power mode string
36 *
37 * @return SysPwrMode or SysPwrMode::NO_CHANGE if not found
38 */
39SysPwrMode convertStringToMode(const std::string& i_modeString);
40
41/** @class PowerMode
42 * @brief Monitors for changes to the power mode and notifies occ
43 *
44 * The customer power mode is provided to the OCC by host TMGT when the occ
45 * first goes active or is reset. This code is responsible for sending
46 * the power mode to the OCC if the mode is changed while the occ is active.
47 */
48
49class PowerMode
50{
51 public:
52 /** @brief PowerMode object to inform occ of changes to mode
53 *
54 * This object will monitor for changes to the power mode setting.
55 * If a change is detected, and the occ is active, then this object will
56 * notify the OCC of the change.
57 *
58 * @param[in] occStatus - The occ status object
59 */
60 PowerMode(Status& occStatus) :
61 occStatus(occStatus),
62 pmodeMatch(utils::getBus(),
63 sdbusplus::bus::match::rules::propertiesChanged(
64 PMODE_PATH, PMODE_INTERFACE),
65 [this](auto& msg) { this->modeChanged(msg); }){};
66
67 private:
68 /** @brief Callback for pmode setting changes
69 *
70 * Process change and inform OCC
71 *
72 * @param[in] msg - Data associated with pmode change signal
73 *
74 */
75 void modeChanged(sdbusplus::message::message& msg);
76
77 /* @brief OCC Status object */
78 Status& occStatus;
79
80 /** @brief Used to subscribe to dbus pmode property changes **/
81 sdbusplus::bus::match_t pmodeMatch;
82};
83
Chris Cain1d51da22021-09-21 14:13:41 -050084class PowerIPS
85{
86 public:
87 /** @brief PowerIPS object to inform occ of changes to Idle Power Saver
88 * parms
89 *
90 * This object will monitor for changes to the Idle Power Saver settings.
91 * If a change is detected, and the occ is active, then this object will
92 * notify the OCC of the change.
93 *
94 * @param[in] occStatus - The occ status object
95 */
96 PowerIPS(Status& occStatus) :
97 occStatus(occStatus),
98 ipsMatch(utils::getBus(),
99 sdbusplus::bus::match::rules::propertiesChanged(
100 PIPS_PATH, PIPS_INTERFACE),
101 [this](auto& msg) { this->ipsChanged(msg); }){};
102
103 private:
104 /** @brief Callback for IPS setting changes
105 *
106 * Process change and inform OCC
107 *
108 * @param[in] msg - Data associated with IPS change signal
109 *
110 */
111 void ipsChanged(sdbusplus::message::message& msg);
112
113 /* @brief OCC Status object */
114 Status& occStatus;
115
116 /** @brief Used to subscribe to dbus IPS property changes **/
117 sdbusplus::bus::match_t ipsMatch;
118};
119
Chris Cain78e86012021-03-04 16:15:31 -0600120} // namespace powermode
121
122} // namespace occ
123
124} // namespace open_power
125#endif