1 #ifndef __HOST_IPMI_DCMI_HANDLER_H__
2 #define __HOST_IPMI_DCMI_HANDLER_H__
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include <sdbusplus/bus.hpp>
8 
9 namespace dcmi
10 {
11 
12 enum Commands
13 {
14     // Get capability bits
15     GET_POWER_LIMIT = 0x03,
16     SET_POWER_LIMIT = 0x04,
17     APPLY_POWER_LIMIT = 0x05,
18     GET_ASSET_TAG = 0x06,
19     SET_ASSET_TAG = 0x08,
20 };
21 
22 
23 static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
24 static constexpr auto assetTagIntf =
25         "xyz.openbmc_project.Inventory.Decorator.AssetTag";
26 static constexpr auto assetTagProp = "AssetTag";
27 
28 namespace assettag
29 {
30 
31     using ObjectPath = std::string;
32     using Service = std::string;
33     using Interfaces = std::vector<std::string>;
34     using ObjectTree = std::map<ObjectPath, std::map<Service, Interfaces>>;
35 
36 } //namespace assettag
37 
38 static constexpr auto groupExtId = 0xDC;
39 
40 static constexpr auto assetTagMaxOffset = 62;
41 static constexpr auto assetTagMaxSize = 63;
42 static constexpr auto maxBytes = 16;
43 
44 /** @struct GetAssetTagRequest
45  *
46  *  DCMI payload for Get Asset Tag command request.
47  */
48 struct GetAssetTagRequest
49 {
50     uint8_t groupID;            //!< Group extension identification.
51     uint8_t offset;             //!< Offset to read.
52     uint8_t bytes;              //!< Number of bytes to read.
53 } __attribute__((packed));
54 
55 /** @struct GetAssetTagResponse
56  *
57  *  DCMI payload for Get Asset Tag command response.
58  */
59 struct GetAssetTagResponse
60 {
61     uint8_t groupID;            //!< Group extension identification.
62     uint8_t tagLength;          //!< Total asset tag length.
63 } __attribute__((packed));
64 
65 /** @struct SetAssetTagRequest
66  *
67  *  DCMI payload for Set Asset Tag command request.
68  */
69 struct SetAssetTagRequest
70 {
71     uint8_t groupID;            //!< Group extension identification.
72     uint8_t offset;             //!< Offset to write.
73     uint8_t bytes;              //!< Number of bytes to write.
74 } __attribute__((packed));
75 
76 /** @struct SetAssetTagResponse
77  *
78  *  DCMI payload for Set Asset Tag command response.
79  */
80 struct SetAssetTagResponse
81 {
82     uint8_t groupID;            //!< Group extension identification.
83     uint8_t tagLength;          //!< Total asset tag length.
84 } __attribute__((packed));
85 
86 /** @brief Read the object tree to fetch the object path that implemented the
87  *         Asset tag interface.
88  *
89  *  @param[in,out] objectTree - object tree
90  *
91  *  @return On success return the object tree with the object path that
92  *          implemented the AssetTag interface.
93  */
94 void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree);
95 
96 /** @brief Read the asset tag of the server
97  *
98  *  @return On success return the asset tag.
99  */
100 std::string readAssetTag();
101 
102 /** @brief Write the asset tag to the asset tag DBUS property
103  *
104  *  @param[in] assetTag - Asset Tag to be written to the property.
105  */
106 void writeAssetTag(const std::string& assetTag);
107 
108 /** @brief Read the current power cap value
109  *
110  *  @param[in] bus - dbus connection
111  *
112  *  @return On success return the power cap value.
113  */
114 uint32_t getPcap(sdbusplus::bus::bus& bus);
115 
116 /** @brief Check if the power capping is enabled
117  *
118  *  @param[in] bus - dbus connection
119  *
120  *  @return true if the powerCap is enabled and false if the powercap
121  *          is disabled.
122  */
123 bool getPcapEnabled(sdbusplus::bus::bus& bus);
124 
125 /** @struct GetPowerLimitRequest
126  *
127  *  DCMI payload for Get Power Limit command request.
128  */
129 struct GetPowerLimitRequest
130 {
131     uint8_t groupID;            //!< Group extension identification.
132     uint16_t reserved;          //!< Reserved
133 } __attribute__((packed));
134 
135 /** @struct GetPowerLimitResponse
136  *
137  *  DCMI payload for Get Power Limit command response.
138  */
139 struct GetPowerLimitResponse
140 {
141     uint8_t groupID;            //!< Group extension identification.
142     uint16_t reserved;          //!< Reserved.
143     uint8_t exceptionAction;    //!< Exception action.
144     uint16_t powerLimit;        //!< Power limit requested in watts.
145     uint32_t correctionTime;    //!< Correction time limit in milliseconds.
146     uint16_t reserved1;         //!< Reserved.
147     uint16_t samplingPeriod;    //!< Statistics sampling period in seconds.
148 } __attribute__((packed));
149 
150 /** @brief Set the power cap value
151  *
152  *  @param[in] bus - dbus connection
153  *  @param[in] powerCap - power cap value
154  */
155 void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap);
156 
157 /** @struct SetPowerLimitRequest
158  *
159  *  DCMI payload for Set Power Limit command request.
160  */
161 struct SetPowerLimitRequest
162 {
163     uint8_t groupID;            //!< Group extension identification.
164     uint16_t reserved;          //!< Reserved
165     uint8_t reserved1;          //!< Reserved
166     uint8_t exceptionAction;    //!< Exception action.
167     uint16_t powerLimit;        //!< Power limit requested in watts.
168     uint32_t correctionTime;    //!< Correction time limit in milliseconds.
169     uint16_t reserved2;         //!< Reserved.
170     uint16_t samplingPeriod;    //!< Statistics sampling period in seconds.
171 } __attribute__((packed));
172 
173 /** @struct SetPowerLimitResponse
174  *
175  *  DCMI payload for Set Power Limit command response.
176  */
177 struct SetPowerLimitResponse
178 {
179     uint8_t groupID;            //!< Group extension identification.
180 } __attribute__((packed));
181 
182 /** @brief Enable or disable the power capping
183  *
184  *  @param[in] bus - dbus connection
185  *  @param[in] enabled - enable/disable
186  */
187 void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled);
188 
189 /** @struct ApplyPowerLimitRequest
190  *
191  *  DCMI payload for Activate/Deactivate Power Limit command request.
192  */
193 struct ApplyPowerLimitRequest
194 {
195     uint8_t groupID;            //!< Group extension identification.
196     uint8_t powerLimitAction;   //!< Power limit activation
197     uint16_t reserved;          //!< Reserved
198 } __attribute__((packed));
199 
200 /** @struct ApplyPowerLimitResponse
201  *
202  *  DCMI payload for Acticate/Deactivate Power Limit command response.
203  */
204 struct ApplyPowerLimitResponse
205 {
206     uint8_t groupID;            //!< Group extension identification.
207 } __attribute__((packed));
208 
209 } // namespace dcmi
210 
211 #endif
212