1 #pragma once 2 3 #include <sdbusplus/bus.hpp> 4 #include <sdbusplus/bus/match.hpp> 5 #include "occ_status.hpp" 6 #include "config.h" 7 8 namespace open_power 9 { 10 namespace occ 11 { 12 namespace powercap 13 { 14 15 namespace sdbusRule = sdbusplus::bus::match::rules; 16 17 /** @class PowerCap 18 * @brief Monitors for changes to the power cap and notifies occ 19 * 20 * The customer power cap is provided to the OCC by host TMGT when the occ 21 * first goes active or is reset. This code is responsible for sending 22 * the power cap to the OCC if the cap is changed while the occ is active. 23 */ 24 25 class PowerCap 26 { 27 public: 28 /** @brief PowerCap object to inform occ of changes to cap 29 * 30 * This object will monitor for changes to the power cap setting and 31 * power cap enable properties. If a change is detected, and the occ 32 * is active, then this object will notify the OCC of the change. 33 * 34 * @param[in] bus - The Dbus bus object 35 * @param[in] occStatus - The occ status object 36 */ 37 PowerCap(sdbusplus::bus::bus &bus, 38 Status &occStatus) : 39 bus(bus), 40 occStatus(occStatus), 41 pcapMatch( 42 bus, 43 sdbusRule::member("PropertiesChanged") + 44 sdbusRule::path( 45 "/xyz/openbmc_project/control/host0/power_cap") + 46 sdbusRule::argN(0, "xyz.openbmc_project.Control.Power.Cap") + 47 sdbusRule::interface("org.freedesktop.DBus.Properties"), 48 std::bind(std::mem_fn(&PowerCap::pcapChanged), 49 this, std::placeholders::_1)) 50 {}; 51 52 /** @brief Return the appropriate value to write to the OCC 53 * 54 * @param[in] pcap - Current user power cap setting 55 * @param[in] pcapEnabled - Current power cap enable setting 56 * 57 * @return The value to write to the occ user pcap 58 */ 59 uint32_t getOccInput(uint32_t pcap, bool pcapEnabled); 60 61 private: 62 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, 80 std::string interface); 81 82 /** @brief Get the power cap property 83 * 84 * @return Power cap, 0 on failure to indicate no pcap 85 */ 86 uint32_t getPcap(); 87 88 /** @brief Get the power cap enable property 89 * 90 * @return Whether power cap enabled, will return false on error 91 */ 92 bool getPcapEnabled(); 93 94 /** @brief Write the input power cap to the occ hwmon entry 95 * 96 * @param[in] pcapValue - Power cap value to write to OCC 97 */ 98 void writeOcc(uint32_t pcapValue); 99 100 /** @brief Reference to sdbus **/ 101 sdbusplus::bus::bus& bus; 102 103 /* @brief OCC Status object */ 104 Status &occStatus; 105 106 /** @brief Used to subscribe to dbus pcap propety changes **/ 107 sdbusplus::bus::match_t pcapMatch; 108 109 }; 110 111 } // namespace open_power 112 113 } // namespace occ 114 115 }// namespace powercap 116