Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #ifdef POWER10 |
| 4 | #include "config.h" |
| 5 | |
| 6 | #include "occ_status.hpp" |
| 7 | |
| 8 | #include <experimental/filesystem> |
| 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/bus/match.hpp> |
| 11 | |
| 12 | namespace open_power |
| 13 | { |
| 14 | namespace occ |
| 15 | { |
| 16 | namespace powermode |
| 17 | { |
| 18 | |
| 19 | constexpr auto PMODE_PATH = "/xyz/openbmc_project/control/host0/power_mode"; |
| 20 | constexpr auto PMODE_INTERFACE = "xyz.openbmc_project.Control.Power.Mode"; |
| 21 | constexpr auto POWER_MODE_PROP = "PowerMode"; |
| 22 | |
| 23 | /** @brief Convert power mode string to OCC SysPwrMode value |
| 24 | * |
| 25 | * @param[in] i_modeString - power mode string |
| 26 | * |
| 27 | * @return SysPwrMode or SysPwrMode::NO_CHANGE if not found |
| 28 | */ |
| 29 | SysPwrMode convertStringToMode(const std::string& i_modeString); |
| 30 | |
| 31 | /** @class PowerMode |
| 32 | * @brief Monitors for changes to the power mode and notifies occ |
| 33 | * |
| 34 | * The customer power mode is provided to the OCC by host TMGT when the occ |
| 35 | * first goes active or is reset. This code is responsible for sending |
| 36 | * the power mode to the OCC if the mode is changed while the occ is active. |
| 37 | */ |
| 38 | |
| 39 | class PowerMode |
| 40 | { |
| 41 | public: |
| 42 | /** @brief PowerMode object to inform occ of changes to mode |
| 43 | * |
| 44 | * This object will monitor for changes to the power mode setting. |
| 45 | * If a change is detected, and the occ is active, then this object will |
| 46 | * notify the OCC of the change. |
| 47 | * |
| 48 | * @param[in] occStatus - The occ status object |
| 49 | */ |
| 50 | PowerMode(Status& occStatus) : |
| 51 | occStatus(occStatus), |
| 52 | pmodeMatch(utils::getBus(), |
| 53 | sdbusplus::bus::match::rules::propertiesChanged( |
| 54 | PMODE_PATH, PMODE_INTERFACE), |
| 55 | [this](auto& msg) { this->modeChanged(msg); }){}; |
| 56 | |
| 57 | private: |
| 58 | /** @brief Callback for pmode setting changes |
| 59 | * |
| 60 | * Process change and inform OCC |
| 61 | * |
| 62 | * @param[in] msg - Data associated with pmode change signal |
| 63 | * |
| 64 | */ |
| 65 | void modeChanged(sdbusplus::message::message& msg); |
| 66 | |
| 67 | /* @brief OCC Status object */ |
| 68 | Status& occStatus; |
| 69 | |
| 70 | /** @brief Used to subscribe to dbus pmode property changes **/ |
| 71 | sdbusplus::bus::match_t pmodeMatch; |
| 72 | }; |
| 73 | |
| 74 | } // namespace powermode |
| 75 | |
| 76 | } // namespace occ |
| 77 | |
| 78 | } // namespace open_power |
| 79 | #endif |