1 #pragma once 2 3 #include "config.h" 4 5 #ifdef POWER10 6 #include "occ_status.hpp" 7 8 #include <sdbusplus/bus.hpp> 9 #include <sdbusplus/bus/match.hpp> 10 11 #include <filesystem> 12 13 namespace open_power 14 { 15 namespace occ 16 { 17 namespace powermode 18 { 19 20 constexpr auto PMODE_PATH = "/xyz/openbmc_project/control/host0/power_mode"; 21 constexpr auto PMODE_INTERFACE = "xyz.openbmc_project.Control.Power.Mode"; 22 constexpr 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 */ 30 SysPwrMode 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 40 class 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 81