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 | |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 24 | constexpr auto PIPS_PATH = "/xyz/openbmc_project/control/host0/power_ips"; |
| 25 | constexpr auto PIPS_INTERFACE = |
| 26 | "xyz.openbmc_project.Control.Power.IdlePowerSaver"; |
| 27 | constexpr auto IPS_ENABLED_PROP = "Enabled"; |
| 28 | constexpr auto IPS_ENTER_UTIL = "EnterUtilizationPercent"; |
| 29 | constexpr auto IPS_ENTER_TIME = "EnterDwellTime"; |
| 30 | constexpr auto IPS_EXIT_UTIL = "ExitUtilizationPercent"; |
| 31 | constexpr auto IPS_EXIT_TIME = "ExitDwellTime"; |
| 32 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 33 | /** @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 | */ |
| 39 | SysPwrMode 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 | |
| 49 | class 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 Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 84 | class 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 Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 120 | } // namespace powermode |
| 121 | |
| 122 | } // namespace occ |
| 123 | |
| 124 | } // namespace open_power |
| 125 | #endif |