blob: fd7d466c5e56160dc9b7e1bc21f80fcf122193ff [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
24/** @brief Convert power mode string to OCC SysPwrMode value
25 *
26 * @param[in] i_modeString - power mode string
27 *
28 * @return SysPwrMode or SysPwrMode::NO_CHANGE if not found
29 */
30SysPwrMode convertStringToMode(const std::string& i_modeString);
31
32/** @class PowerMode
33 * @brief Monitors for changes to the power mode and notifies occ
34 *
35 * The customer power mode is provided to the OCC by host TMGT when the occ
36 * first goes active or is reset. This code is responsible for sending
37 * the power mode to the OCC if the mode is changed while the occ is active.
38 */
39
40class PowerMode
41{
42 public:
43 /** @brief PowerMode object to inform occ of changes to mode
44 *
45 * This object will monitor for changes to the power mode setting.
46 * If a change is detected, and the occ is active, then this object will
47 * notify the OCC of the change.
48 *
49 * @param[in] occStatus - The occ status object
50 */
51 PowerMode(Status& occStatus) :
52 occStatus(occStatus),
53 pmodeMatch(utils::getBus(),
54 sdbusplus::bus::match::rules::propertiesChanged(
55 PMODE_PATH, PMODE_INTERFACE),
56 [this](auto& msg) { this->modeChanged(msg); }){};
57
58 private:
59 /** @brief Callback for pmode setting changes
60 *
61 * Process change and inform OCC
62 *
63 * @param[in] msg - Data associated with pmode change signal
64 *
65 */
66 void modeChanged(sdbusplus::message::message& msg);
67
68 /* @brief OCC Status object */
69 Status& occStatus;
70
71 /** @brief Used to subscribe to dbus pmode property changes **/
72 sdbusplus::bus::match_t pmodeMatch;
73};
74
75} // namespace powermode
76
77} // namespace occ
78
79} // namespace open_power
80#endif