1 #pragma once 2 3 #include "config.h" 4 5 #include "occ_status.hpp" 6 7 #include <sdbusplus/bus.hpp> 8 #include <sdbusplus/bus/match.hpp> 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 { 29 public: 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 */ 39 PowerCap(sdbusplus::bus::bus& bus, Status& occStatus, 40 const std::string& occMasterName = OCC_MASTER_NAME) : 41 bus(bus), 42 occMasterName(occMasterName), occStatus(occStatus), 43 pcapMatch( 44 bus, 45 sdbusRule::member("PropertiesChanged") + 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"), 50 std::bind(std::mem_fn(&PowerCap::pcapChanged), this, 51 std::placeholders::_1)){}; 52 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 62 private: 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 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 */ 79 std::string getService(std::string path, std::string interface); 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 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 99 /** @brief Reference to sdbus **/ 100 sdbusplus::bus::bus& bus; 101 102 /** @brief The master occ name */ 103 std::string occMasterName; 104 105 /* @brief OCC Status object */ 106 Status& occStatus; 107 108 /** @brief Used to subscribe to dbus pcap property changes **/ 109 sdbusplus::bus::match_t pcapMatch; 110 }; 111 112 } // namespace powercap 113 114 } // namespace occ 115 116 } // namespace open_power 117