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