blob: 6a77c9dd044439ee776c5db6b9cd1703e27ba23b [file] [log] [blame]
Andrew Geissler32016d12017-06-20 15:46:52 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/bus/match.hpp>
5#include "occ_status.hpp"
6#include "config.h"
7
8namespace open_power
9{
10namespace occ
11{
12namespace powercap
13{
14
15namespace 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
25class PowerCap
26{
27public:
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,
Lei YU41470e52017-11-30 16:03:50 +080038 Status &occStatus,
39 const std::string& occMasterName = OCC_MASTER_NAME) :
Andrew Geissler32016d12017-06-20 15:46:52 -050040 bus(bus),
Lei YU41470e52017-11-30 16:03:50 +080041 occMasterName(occMasterName),
Andrew Geissler32016d12017-06-20 15:46:52 -050042 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),
51 this, std::placeholders::_1))
52 {};
53
Andrew Geissler4cea4d22017-07-10 15:13:33 -050054 /** @brief Return the appropriate value to write to the OCC
55 *
56 * @param[in] pcap - Current user power cap setting
57 * @param[in] pcapEnabled - Current power cap enable setting
58 *
59 * @return The value to write to the occ user pcap
60 */
61 uint32_t getOccInput(uint32_t pcap, bool pcapEnabled);
62
Andrew Geissler32016d12017-06-20 15:46:52 -050063private:
64
65 /** @brief Callback for pcap setting changes
66 *
67 * Process change and inform OCC
68 *
69 * @param[in] msg - Data associated with pcap change signal
70 *
71 */
72 void pcapChanged(sdbusplus::message::message& msg);
73
Andrew Geissler52cf26a2017-07-06 12:56:32 -050074 /** @brief Look up DBUS service for input path/interface
75 *
76 * @param[in] path - DBUS path
77 * @param[in] path - DBUS interface
78 *
79 * @return Distinct service name for input path/interface
80 */
81 std::string getService(std::string path,
82 std::string interface);
83
84 /** @brief Get the power cap property
85 *
86 * @return Power cap, 0 on failure to indicate no pcap
87 */
88 uint32_t getPcap();
89
90 /** @brief Get the power cap enable property
91 *
92 * @return Whether power cap enabled, will return false on error
93 */
94 bool getPcapEnabled();
95
Andrew Geissler6ac874e2017-07-10 15:54:58 -050096 /** @brief Write the input power cap to the occ hwmon entry
97 *
98 * @param[in] pcapValue - Power cap value to write to OCC
99 */
100 void writeOcc(uint32_t pcapValue);
101
Andrew Geissler32016d12017-06-20 15:46:52 -0500102 /** @brief Reference to sdbus **/
103 sdbusplus::bus::bus& bus;
104
Lei YU41470e52017-11-30 16:03:50 +0800105 /** @brief The master occ name */
106 std::string occMasterName;
107
Andrew Geissler32016d12017-06-20 15:46:52 -0500108 /* @brief OCC Status object */
109 Status &occStatus;
110
111 /** @brief Used to subscribe to dbus pcap propety changes **/
112 sdbusplus::bus::match_t pcapMatch;
113
114 };
115
116} // namespace open_power
117
118} // namespace occ
119
120}// namespace powercap