Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
| 5 | #include "occ_status.hpp" |
| 6 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
| 8 | #include <sdbusplus/bus/match.hpp> |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 9 | |
| 10 | namespace open_power |
| 11 | { |
| 12 | namespace occ |
| 13 | { |
| 14 | namespace powercap |
| 15 | { |
| 16 | |
| 17 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 18 | |
| 19 | /** @class PowerCap |
| 20 | * @brief Monitors for changes to the power cap and notifies occ |
| 21 | * |
| 22 | * The customer power cap is provided to the OCC by host TMGT when the occ |
| 23 | * first goes active or is reset. This code is responsible for sending |
| 24 | * the power cap to the OCC if the cap is changed while the occ is active. |
| 25 | */ |
| 26 | |
| 27 | class PowerCap |
| 28 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 29 | public: |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 30 | /** @brief PowerCap object to inform occ of changes to cap |
| 31 | * |
| 32 | * This object will monitor for changes to the power cap setting and |
| 33 | * power cap enable properties. If a change is detected, and the occ |
| 34 | * is active, then this object will notify the OCC of the change. |
| 35 | * |
| 36 | * @param[in] bus - The Dbus bus object |
| 37 | * @param[in] occStatus - The occ status object |
| 38 | */ |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 39 | PowerCap(sdbusplus::bus::bus& bus, Status& occStatus, |
Lei YU | 41470e5 | 2017-11-30 16:03:50 +0800 | [diff] [blame] | 40 | const std::string& occMasterName = OCC_MASTER_NAME) : |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 41 | bus(bus), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 42 | occMasterName(occMasterName), occStatus(occStatus), |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 43 | pcapMatch( |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 44 | bus, |
| 45 | sdbusRule::member("PropertiesChanged") + |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 46 | sdbusRule::path( |
| 47 | "/xyz/openbmc_project/control/host0/power_cap") + |
| 48 | sdbusRule::argN(0, "xyz.openbmc_project.Control.Power.Cap") + |
| 49 | sdbusRule::interface("org.freedesktop.DBus.Properties"), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 50 | std::bind(std::mem_fn(&PowerCap::pcapChanged), this, |
| 51 | std::placeholders::_1)){}; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 52 | |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 53 | /** @brief Return the appropriate value to write to the OCC |
| 54 | * |
| 55 | * @param[in] pcap - Current user power cap setting |
| 56 | * @param[in] pcapEnabled - Current power cap enable setting |
| 57 | * |
| 58 | * @return The value to write to the occ user pcap |
| 59 | */ |
| 60 | uint32_t getOccInput(uint32_t pcap, bool pcapEnabled); |
| 61 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 62 | private: |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 63 | /** @brief Callback for pcap setting changes |
| 64 | * |
| 65 | * Process change and inform OCC |
| 66 | * |
| 67 | * @param[in] msg - Data associated with pcap change signal |
| 68 | * |
| 69 | */ |
| 70 | void pcapChanged(sdbusplus::message::message& msg); |
| 71 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 72 | /** @brief Look up DBUS service for input path/interface |
| 73 | * |
| 74 | * @param[in] path - DBUS path |
| 75 | * @param[in] path - DBUS interface |
| 76 | * |
| 77 | * @return Distinct service name for input path/interface |
| 78 | */ |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 79 | std::string getService(std::string path, std::string interface); |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 80 | |
| 81 | /** @brief Get the power cap property |
| 82 | * |
| 83 | * @return Power cap, 0 on failure to indicate no pcap |
| 84 | */ |
| 85 | uint32_t getPcap(); |
| 86 | |
| 87 | /** @brief Get the power cap enable property |
| 88 | * |
| 89 | * @return Whether power cap enabled, will return false on error |
| 90 | */ |
| 91 | bool getPcapEnabled(); |
| 92 | |
Andrew Geissler | 6ac874e | 2017-07-10 15:54:58 -0500 | [diff] [blame] | 93 | /** @brief Write the input power cap to the occ hwmon entry |
| 94 | * |
| 95 | * @param[in] pcapValue - Power cap value to write to OCC |
| 96 | */ |
| 97 | void writeOcc(uint32_t pcapValue); |
| 98 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 99 | /** @brief Reference to sdbus **/ |
| 100 | sdbusplus::bus::bus& bus; |
| 101 | |
Lei YU | 41470e5 | 2017-11-30 16:03:50 +0800 | [diff] [blame] | 102 | /** @brief The master occ name */ |
| 103 | std::string occMasterName; |
| 104 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 105 | /* @brief OCC Status object */ |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 106 | Status& occStatus; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 107 | |
Gunnar Mills | 85e6520 | 2018-04-08 15:01:54 -0500 | [diff] [blame] | 108 | /** @brief Used to subscribe to dbus pcap property changes **/ |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 109 | sdbusplus::bus::match_t pcapMatch; |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 110 | }; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 111 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 112 | } // namespace powercap |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 113 | |
| 114 | } // namespace occ |
| 115 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 116 | } // namespace open_power |