blob: b28be8c86d3f1330bca35df1be49cd90c6f80c4e [file] [log] [blame]
Andrew Geissler32016d12017-06-20 15:46:52 -05001#pragma once
2
Gunnar Mills94df8c92018-09-14 14:50:03 -05003#include "config.h"
4
5#include "occ_status.hpp"
6
Andrew Geissler32016d12017-06-20 15:46:52 -05007#include <sdbusplus/bus.hpp>
8#include <sdbusplus/bus/match.hpp>
Andrew Geissler32016d12017-06-20 15:46:52 -05009
10namespace open_power
11{
12namespace occ
13{
14namespace powercap
15{
16
17namespace 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
27class PowerCap
28{
Gunnar Mills94df8c92018-09-14 14:50:03 -050029 public:
Andrew Geissler32016d12017-06-20 15:46:52 -050030 /** @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 Mills94df8c92018-09-14 14:50:03 -050039 PowerCap(sdbusplus::bus::bus& bus, Status& occStatus,
Lei YU41470e52017-11-30 16:03:50 +080040 const std::string& occMasterName = OCC_MASTER_NAME) :
Andrew Geissler32016d12017-06-20 15:46:52 -050041 bus(bus),
Gunnar Mills94df8c92018-09-14 14:50:03 -050042 occMasterName(occMasterName), occStatus(occStatus),
Andrew Geissler32016d12017-06-20 15:46:52 -050043 pcapMatch(
Gunnar Mills94df8c92018-09-14 14:50:03 -050044 bus,
45 sdbusRule::member("PropertiesChanged") +
Andrew Geissler32016d12017-06-20 15:46:52 -050046 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 Mills94df8c92018-09-14 14:50:03 -050050 std::bind(std::mem_fn(&PowerCap::pcapChanged), this,
51 std::placeholders::_1)){};
Andrew Geissler32016d12017-06-20 15:46:52 -050052
Andrew Geissler4cea4d22017-07-10 15:13:33 -050053 /** @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 Mills94df8c92018-09-14 14:50:03 -050062 private:
Andrew Geissler32016d12017-06-20 15:46:52 -050063 /** @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 Geissler52cf26a2017-07-06 12:56:32 -050072 /** @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 Mills94df8c92018-09-14 14:50:03 -050079 std::string getService(std::string path, std::string interface);
Andrew Geissler52cf26a2017-07-06 12:56:32 -050080
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 Geissler6ac874e2017-07-10 15:54:58 -050093 /** @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 Geissler32016d12017-06-20 15:46:52 -050099 /** @brief Reference to sdbus **/
100 sdbusplus::bus::bus& bus;
101
Lei YU41470e52017-11-30 16:03:50 +0800102 /** @brief The master occ name */
103 std::string occMasterName;
104
Andrew Geissler32016d12017-06-20 15:46:52 -0500105 /* @brief OCC Status object */
Gunnar Mills94df8c92018-09-14 14:50:03 -0500106 Status& occStatus;
Andrew Geissler32016d12017-06-20 15:46:52 -0500107
Gunnar Mills85e65202018-04-08 15:01:54 -0500108 /** @brief Used to subscribe to dbus pcap property changes **/
Andrew Geissler32016d12017-06-20 15:46:52 -0500109 sdbusplus::bus::match_t pcapMatch;
Gunnar Mills94df8c92018-09-14 14:50:03 -0500110};
Andrew Geissler32016d12017-06-20 15:46:52 -0500111
Gunnar Mills94df8c92018-09-14 14:50:03 -0500112} // namespace powercap
Andrew Geissler32016d12017-06-20 15:46:52 -0500113
114} // namespace occ
115
Gunnar Mills94df8c92018-09-14 14:50:03 -0500116} // namespace open_power