Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
George Liu | bddcf85 | 2021-09-08 08:46:22 +0800 | [diff] [blame] | 5 | #ifdef POWER10 |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 6 | #include "occ_status.hpp" |
| 7 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/bus/match.hpp> |
| 10 | |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 11 | #include <filesystem> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 12 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 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 |