blob: 303f6d00a11bc657dd2d0977752c70a24189c76b [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#pragma once
Tom Josephbe5eaa12017-07-12 19:54:44 +05302
Patrick Venture0b02be92018-08-31 11:55:55 -07003#include "nlohmann/json.hpp"
4
Tom Josephbe5eaa12017-07-12 19:54:44 +05305#include <map>
Patrick Venture0b02be92018-08-31 11:55:55 -07006#include <sdbusplus/bus.hpp>
Tom Josephbe5eaa12017-07-12 19:54:44 +05307#include <string>
8#include <vector>
9
Tom Josephbe5eaa12017-07-12 19:54:44 +053010namespace dcmi
11{
12
Deepak Kodihalli0b459552018-02-06 06:25:12 -060013using NumInstances = size_t;
14using Json = nlohmann::json;
15
Ratan Gupta11ddbd22017-08-05 11:59:39 +053016enum Commands
17{
18 // Get capability bits
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -060019 GET_CAPABILITIES = 0x01,
Marri Devender Rao66c5fda2018-01-18 10:48:37 -060020 GET_POWER_READING = 0x02,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053021 GET_POWER_LIMIT = 0x03,
22 SET_POWER_LIMIT = 0x04,
23 APPLY_POWER_LIMIT = 0x05,
24 GET_ASSET_TAG = 0x06,
Deepak Kodihalli0b459552018-02-06 06:25:12 -060025 GET_SENSOR_INFO = 0x07,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053026 SET_ASSET_TAG = 0x08,
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030027 GET_MGMNT_CTRL_ID_STR = 0x09,
28 SET_MGMNT_CTRL_ID_STR = 0x0A,
Deepak Kodihalliee717d72018-01-24 04:53:09 -060029 GET_TEMP_READINGS = 0x10,
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060030 SET_CONF_PARAMS = 0x12,
31 GET_CONF_PARAMS = 0x13,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053032};
33
Tom Josephbe5eaa12017-07-12 19:54:44 +053034static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
35static constexpr auto assetTagIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070036 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Tom Josephbe5eaa12017-07-12 19:54:44 +053037static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030038static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
Patrick Venture0b02be92018-08-31 11:55:55 -070039static constexpr auto networkConfigObj = "/xyz/openbmc_project/network/config";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030040static constexpr auto networkConfigIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070041 "xyz.openbmc_project.Network.SystemConfiguration";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030042static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060043static constexpr auto temperatureSensorType = 0x01;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060044static constexpr auto maxInstances = 255;
Kirill Pakhomova2573622018-11-02 19:00:18 +030045static constexpr auto gDCMISensorsConfig =
Deepak Kodihalli0b459552018-02-06 06:25:12 -060046 "/usr/share/ipmi-providers/dcmi_sensors.json";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060047static constexpr auto ethernetIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070048 "xyz.openbmc_project.Network.EthernetInterface";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060049static constexpr auto ethernetDefaultChannelNum = 0x1;
50static constexpr auto networkRoot = "/xyz/openbmc_project/network";
Jian Zhang958806d2022-12-13 13:37:09 +080051static constexpr auto dhcpObj = "/xyz/openbmc_project/network/dhcp";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060052static constexpr auto dhcpIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070053 "xyz.openbmc_project.Network.DHCPConfiguration";
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -060054static constexpr auto systemBusName = "org.freedesktop.systemd1";
55static constexpr auto systemPath = "/org/freedesktop/systemd1";
56static constexpr auto systemIntf = "org.freedesktop.systemd1.Manager";
Kirill Pakhomova2573622018-11-02 19:00:18 +030057static constexpr auto gDCMICapabilitiesConfig =
58 "/usr/share/ipmi-providers/dcmi_cap.json";
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +030059static constexpr auto gDCMIPowerMgmtCapability = "PowerManagement";
60static constexpr auto gDCMIPowerMgmtSupported = 0x1;
Kirill Pakhomovdb5d9b02018-11-06 19:17:51 +030061static constexpr auto gMaxSELEntriesMask = 0xFFF;
62static constexpr auto gByteBitSize = 8;
Tom Josephbe5eaa12017-07-12 19:54:44 +053063
64namespace assettag
65{
66
Patrick Venture0b02be92018-08-31 11:55:55 -070067using ObjectPath = std::string;
68using Service = std::string;
69using Interfaces = std::vector<std::string>;
70using ObjectTree = std::map<ObjectPath, std::map<Service, Interfaces>>;
Tom Josephbe5eaa12017-07-12 19:54:44 +053071
Patrick Venture0b02be92018-08-31 11:55:55 -070072} // namespace assettag
Tom Josephbe5eaa12017-07-12 19:54:44 +053073
Deepak Kodihalliee717d72018-01-24 04:53:09 -060074namespace temp_readings
75{
Patrick Venture0b02be92018-08-31 11:55:55 -070076static constexpr auto maxDataSets = 8;
77static constexpr auto maxTemp = 127; // degrees C
Deepak Kodihalliee717d72018-01-24 04:53:09 -060078
Patrick Venture0b02be92018-08-31 11:55:55 -070079/** @struct Response
80 *
81 * DCMI payload for Get Temperature Readings response
82 */
83struct Response
84{
Deepak Kodihalliee717d72018-01-24 04:53:09 -060085#if BYTE_ORDER == LITTLE_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070086 uint8_t temperature : 7; //!< Temperature reading in Celsius
87 uint8_t sign : 1; //!< Sign bit
Deepak Kodihalliee717d72018-01-24 04:53:09 -060088#endif
89#if BYTE_ORDER == BIG_ENDIAN
Patrick Venture0b02be92018-08-31 11:55:55 -070090 uint8_t sign : 1; //!< Sign bit
91 uint8_t temperature : 7; //!< Temperature reading in Celsius
Deepak Kodihalliee717d72018-01-24 04:53:09 -060092#endif
Patrick Venture0b02be92018-08-31 11:55:55 -070093 uint8_t instance; //!< Entity instance number
94} __attribute__((packed));
Deepak Kodihalliee717d72018-01-24 04:53:09 -060095
Patrick Venture0b02be92018-08-31 11:55:55 -070096using ResponseList = std::vector<Response>;
97using Value = uint8_t;
98using Sign = bool;
99using Temperature = std::tuple<Value, Sign>;
100} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600101
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600102namespace sensor_info
103{
Patrick Venture0b02be92018-08-31 11:55:55 -0700104static constexpr auto maxRecords = 8;
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600105
Patrick Venture0b02be92018-08-31 11:55:55 -0700106/** @struct Response
107 *
108 * DCMI payload for Get Sensor Info response
109 */
110struct Response
111{
112 uint8_t recordIdLsb; //!< SDR record id LS byte
113 uint8_t recordIdMsb; //!< SDR record id MS byte
114} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600115
Patrick Venture0b02be92018-08-31 11:55:55 -0700116using ResponseList = std::vector<Response>;
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600117} // namespace sensor_info
118
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530119static constexpr auto groupExtId = 0xDC;
120
121static constexpr auto assetTagMaxOffset = 62;
122static constexpr auto assetTagMaxSize = 63;
123static constexpr auto maxBytes = 16;
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300124static constexpr size_t maxCtrlIdStrLen = 63;
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530125
126/** @struct GetAssetTagRequest
127 *
128 * DCMI payload for Get Asset Tag command request.
129 */
130struct GetAssetTagRequest
131{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700132 uint8_t offset; //!< Offset to read.
133 uint8_t bytes; //!< Number of bytes to read.
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530134} __attribute__((packed));
135
136/** @struct GetAssetTagResponse
137 *
138 * DCMI payload for Get Asset Tag command response.
139 */
140struct GetAssetTagResponse
141{
Patrick Venture0b02be92018-08-31 11:55:55 -0700142 uint8_t tagLength; //!< Total asset tag length.
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530143} __attribute__((packed));
144
Tom Joseph545dd232017-07-12 20:20:49 +0530145/** @struct SetAssetTagRequest
146 *
147 * DCMI payload for Set Asset Tag command request.
148 */
149struct SetAssetTagRequest
150{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700151 uint8_t offset; //!< Offset to write.
152 uint8_t bytes; //!< Number of bytes to write.
Tom Joseph545dd232017-07-12 20:20:49 +0530153} __attribute__((packed));
154
155/** @struct SetAssetTagResponse
156 *
157 * DCMI payload for Set Asset Tag command response.
158 */
159struct SetAssetTagResponse
160{
Patrick Venture0b02be92018-08-31 11:55:55 -0700161 uint8_t tagLength; //!< Total asset tag length.
Tom Joseph545dd232017-07-12 20:20:49 +0530162} __attribute__((packed));
163
Kirill Pakhomov2c2af2c2018-11-06 16:06:10 +0300164/** @brief Check whether DCMI power management is supported
165 * in the DCMI Capabilities config file.
166 *
167 * @return True if DCMI power management is supported
168 */
169bool isDCMIPowerMgmtSupported();
170
Tom Josephbe5eaa12017-07-12 19:54:44 +0530171/** @brief Read the object tree to fetch the object path that implemented the
172 * Asset tag interface.
173 *
174 * @param[in,out] objectTree - object tree
175 *
176 * @return On success return the object tree with the object path that
177 * implemented the AssetTag interface.
178 */
179void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree);
180
181/** @brief Read the asset tag of the server
182 *
183 * @return On success return the asset tag.
184 */
185std::string readAssetTag();
186
Tom Josephbe5b9892017-07-15 00:55:23 +0530187/** @brief Write the asset tag to the asset tag DBUS property
188 *
189 * @param[in] assetTag - Asset Tag to be written to the property.
190 */
191void writeAssetTag(const std::string& assetTag);
192
Tom Josephb9d86f42017-07-26 18:03:47 +0530193/** @brief Read the current power cap value
194 *
195 * @param[in] bus - dbus connection
196 *
197 * @return On success return the power cap value.
198 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500199uint32_t getPcap(sdbusplus::bus_t& bus);
Tom Josephb9d86f42017-07-26 18:03:47 +0530200
201/** @brief Check if the power capping is enabled
202 *
203 * @param[in] bus - dbus connection
204 *
205 * @return true if the powerCap is enabled and false if the powercap
206 * is disabled.
207 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500208bool getPcapEnabled(sdbusplus::bus_t& bus);
Tom Josephb9d86f42017-07-26 18:03:47 +0530209
Tom Josephb9d86f42017-07-26 18:03:47 +0530210/** @struct GetPowerLimitResponse
211 *
212 * DCMI payload for Get Power Limit command response.
213 */
214struct GetPowerLimitResponse
215{
Patrick Venture0b02be92018-08-31 11:55:55 -0700216 uint16_t reserved; //!< Reserved.
217 uint8_t exceptionAction; //!< Exception action.
218 uint16_t powerLimit; //!< Power limit requested in watts.
219 uint32_t correctionTime; //!< Correction time limit in milliseconds.
220 uint16_t reserved1; //!< Reserved.
221 uint16_t samplingPeriod; //!< Statistics sampling period in seconds.
Tom Josephb9d86f42017-07-26 18:03:47 +0530222} __attribute__((packed));
223
Tom Joseph46fa37d2017-07-26 18:11:55 +0530224/** @brief Set the power cap value
225 *
226 * @param[in] bus - dbus connection
227 * @param[in] powerCap - power cap value
228 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500229void setPcap(sdbusplus::bus_t& bus, const uint32_t powerCap);
Tom Joseph46fa37d2017-07-26 18:11:55 +0530230
231/** @struct SetPowerLimitRequest
232 *
233 * DCMI payload for Set Power Limit command request.
234 */
235struct SetPowerLimitRequest
236{
Patrick Venture0b02be92018-08-31 11:55:55 -0700237 uint16_t reserved; //!< Reserved
238 uint8_t reserved1; //!< Reserved
239 uint8_t exceptionAction; //!< Exception action.
240 uint16_t powerLimit; //!< Power limit requested in watts.
241 uint32_t correctionTime; //!< Correction time limit in milliseconds.
242 uint16_t reserved2; //!< Reserved.
243 uint16_t samplingPeriod; //!< Statistics sampling period in seconds.
Tom Joseph46fa37d2017-07-26 18:11:55 +0530244} __attribute__((packed));
245
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530246/** @brief Enable or disable the power capping
247 *
248 * @param[in] bus - dbus connection
249 * @param[in] enabled - enable/disable
250 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500251void setPcapEnable(sdbusplus::bus_t& bus, bool enabled);
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530252
253/** @struct ApplyPowerLimitRequest
254 *
255 * DCMI payload for Activate/Deactivate Power Limit command request.
256 */
257struct ApplyPowerLimitRequest
258{
Patrick Venture0b02be92018-08-31 11:55:55 -0700259 uint8_t powerLimitAction; //!< Power limit activation
260 uint16_t reserved; //!< Reserved
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530261} __attribute__((packed));
262
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300263/** @struct GetMgmntCtrlIdStrRequest
264 *
265 * DCMI payload for Get Management Controller Identifier String cmd request.
266 */
267struct GetMgmntCtrlIdStrRequest
268{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700269 uint8_t offset; //!< Offset to read.
270 uint8_t bytes; //!< Number of bytes to read.
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300271} __attribute__((packed));
272
273/** @struct GetMgmntCtrlIdStrResponse
274 *
275 * DCMI payload for Get Management Controller Identifier String cmd response.
276 */
277struct GetMgmntCtrlIdStrResponse
278{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700279 uint8_t strLen; //!< ID string length.
280 char data[]; //!< ID string
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300281} __attribute__((packed));
282
283/** @struct SetMgmntCtrlIdStrRequest
284 *
285 * DCMI payload for Set Management Controller Identifier String cmd request.
286 */
287struct SetMgmntCtrlIdStrRequest
288{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700289 uint8_t offset; //!< Offset to write.
290 uint8_t bytes; //!< Number of bytes to read.
291 char data[]; //!< ID string
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300292} __attribute__((packed));
293
294/** @struct GetMgmntCtrlIdStrResponse
295 *
296 * DCMI payload for Get Management Controller Identifier String cmd response.
297 */
298struct SetMgmntCtrlIdStrResponse
299{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700300 uint8_t offset; //!< Last Offset Written.
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300301} __attribute__((packed));
302
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600303/** @enum DCMICapParameters
304 *
305 * DCMI Capability parameters
306 */
307enum class DCMICapParameters
308{
309 SUPPORTED_DCMI_CAPS = 0x01, //!< Supported DCMI Capabilities
310 MANDATORY_PLAT_ATTRIBUTES = 0x02, //!< Mandatory Platform Attributes
311 OPTIONAL_PLAT_ATTRIBUTES = 0x03, //!< Optional Platform Attributes
312 MANAGEABILITY_ACCESS_ATTRIBUTES = 0x04, //!< Manageability Access Attributes
313};
314
315/** @struct GetDCMICapRequest
316 *
317 * DCMI payload for Get capabilities cmd request.
318 */
319struct GetDCMICapRequest
320{
William A. Kennington III5d06cc62019-04-25 02:10:55 -0700321 uint8_t param; //!< Capability parameter selector.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600322} __attribute__((packed));
323
324/** @struct GetDCMICapRequest
325 *
326 * DCMI payload for Get capabilities cmd response.
327 */
328struct GetDCMICapResponse
329{
Patrick Venture0b02be92018-08-31 11:55:55 -0700330 uint8_t major; //!< DCMI Specification Conformance - major ver
331 uint8_t minor; //!< DCMI Specification Conformance - minor ver
332 uint8_t paramRevision; //!< Parameter Revision = 02h
333 uint8_t data[]; //!< Capability array
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600334} __attribute__((packed));
335
336/** @struct DCMICap
337 *
338 * DCMI capabilities protocol info.
339 */
340struct DCMICap
341{
Patrick Venture0b02be92018-08-31 11:55:55 -0700342 std::string name; //!< Name of DCMI capability.
343 uint8_t bytePosition; //!< Starting byte number from DCMI spec.
344 uint8_t position; //!< bit position from the DCMI spec.
345 uint8_t length; //!< Length of the value from DCMI spec.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600346};
347
348using DCMICapList = std::vector<DCMICap>;
349
350/** @struct DCMICapEntry
351 *
352 * DCMI capabilities list and size for each parameter.
353 */
354struct DCMICapEntry
355{
Patrick Venture0b02be92018-08-31 11:55:55 -0700356 uint8_t size; //!< Size of capability array in bytes.
357 DCMICapList capList; //!< List of capabilities for a parameter.
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600358};
359
360using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>;
361
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600362/** @struct GetTempReadingsRequest
363 *
364 * DCMI payload for Get Temperature Readings request
365 */
366struct GetTempReadingsRequest
367{
Patrick Venture0b02be92018-08-31 11:55:55 -0700368 uint8_t sensorType; //!< Type of the sensor
369 uint8_t entityId; //!< Entity ID
370 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
371 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600372} __attribute__((packed));
373
374/** @struct GetTempReadingsResponse
375 *
376 * DCMI header for Get Temperature Readings response
377 */
378struct GetTempReadingsResponseHdr
379{
Patrick Venture0b02be92018-08-31 11:55:55 -0700380 uint8_t numInstances; //!< No. of instances for requested id
381 uint8_t numDataSets; //!< No. of sets of temperature data
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600382} __attribute__((packed));
383
Kirill Pakhomova2573622018-11-02 19:00:18 +0300384/** @brief Parse out JSON config file.
385 *
386 * @param[in] configFile - JSON config file name
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600387 *
388 * @return A json object
389 */
Kirill Pakhomova2573622018-11-02 19:00:18 +0300390Json parseJSONConfig(const std::string& configFile);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600391
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600392namespace temp_readings
393{
Patrick Venture0b02be92018-08-31 11:55:55 -0700394/** @brief Read temperature from a d-bus object, scale it as per dcmi
395 * get temperature reading requirements.
396 *
397 * @param[in] dbusService - the D-Bus service
398 * @param[in] dbusPath - the D-Bus path
399 *
400 * @return A temperature reading
401 */
402Temperature readTemp(const std::string& dbusService,
403 const std::string& dbusPath);
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600404
Patrick Venture0b02be92018-08-31 11:55:55 -0700405/** @brief Read temperatures and fill up DCMI response for the Get
406 * Temperature Readings command. This looks at a specific
407 * instance.
408 *
409 * @param[in] type - one of "inlet", "cpu", "baseboard"
410 * @param[in] instance - A non-zero Entity instance number
411 *
412 * @return A tuple, containing a temperature reading and the
413 * number of instances.
414 */
415std::tuple<Response, NumInstances> read(const std::string& type,
416 uint8_t instance);
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600417
Patrick Venture0b02be92018-08-31 11:55:55 -0700418/** @brief Read temperatures and fill up DCMI response for the Get
419 * Temperature Readings command. This looks at a range of
420 * instances.
421 *
422 * @param[in] type - one of "inlet", "cpu", "baseboard"
423 * @param[in] instanceStart - Entity instance start index
424 *
425 * @return A tuple, containing a list of temperature readings and the
426 * number of instances.
427 */
428std::tuple<ResponseList, NumInstances> readAll(const std::string& type,
429 uint8_t instanceStart);
430} // namespace temp_readings
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600431
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600432namespace sensor_info
433{
Patrick Venture0b02be92018-08-31 11:55:55 -0700434/** @brief Create response from JSON config.
435 *
436 * @param[in] config - JSON config info about DCMI sensors
437 *
438 * @return Sensor info response
439 */
440Response createFromJson(const Json& config);
Deepak Kodihallidd4cff12018-02-06 06:48:29 -0600441
Patrick Venture0b02be92018-08-31 11:55:55 -0700442/** @brief Read sensor info and fill up DCMI response for the Get
443 * Sensor Info command. This looks at a specific
444 * instance.
445 *
446 * @param[in] type - one of "inlet", "cpu", "baseboard"
447 * @param[in] instance - A non-zero Entity instance number
448 * @param[in] config - JSON config info about DCMI sensors
449 *
450 * @return A tuple, containing a sensor info response and
451 * number of instances.
452 */
453std::tuple<Response, NumInstances> read(const std::string& type,
454 uint8_t instance, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600455
Patrick Venture0b02be92018-08-31 11:55:55 -0700456/** @brief Read sensor info and fill up DCMI response for the Get
457 * Sensor Info command. This looks at a range of
458 * instances.
459 *
460 * @param[in] type - one of "inlet", "cpu", "baseboard"
461 * @param[in] instanceStart - Entity instance start index
462 * @param[in] config - JSON config info about DCMI sensors
463 *
464 * @return A tuple, containing a list of sensor info responses and the
465 * number of instances.
466 */
467std::tuple<ResponseList, NumInstances>
468 readAll(const std::string& type, uint8_t instanceStart, const Json& config);
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600469} // namespace sensor_info
470
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600471/** @brief Read power reading from power reading sensor object
472 *
473 * @param[in] bus - dbus connection
474 *
475 * @return total power reading
476 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500477int64_t getPowerReading(sdbusplus::bus_t& bus);
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600478
479/** @struct GetPowerReadingRequest
480 *
481 * DCMI Get Power Reading command request.
482 * Refer DCMI specification Version 1.1 Section 6.6.1
483 */
484struct GetPowerReadingRequest
485{
Patrick Venture0b02be92018-08-31 11:55:55 -0700486 uint8_t mode; //!< Mode
487 uint8_t modeAttribute; //!< Mode Attributes
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600488} __attribute__((packed));
489
490/** @struct GetPowerReadingResponse
491 *
492 * DCMI Get Power Reading command response.
493 * Refer DCMI specification Version 1.1 Section 6.6.1
494 */
495struct GetPowerReadingResponse
496{
Patrick Venture0b02be92018-08-31 11:55:55 -0700497 uint16_t currentPower; //!< Current power in watts
498 uint16_t minimumPower; //!< Minimum power over sampling duration
499 //!< in watts
500 uint16_t maximumPower; //!< Maximum power over sampling duration
501 //!< in watts
502 uint16_t averagePower; //!< Average power over sampling duration
503 //!< in watts
504 uint32_t timeStamp; //!< IPMI specification based time stamp
505 uint32_t timeFrame; //!< Statistics reporting time period in milli
506 //!< seconds.
507 uint8_t powerReadingState; //!< Power Reading State
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600508} __attribute__((packed));
509
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600510/** @struct GetSensorInfoRequest
511 *
512 * DCMI payload for Get Sensor Info request
513 */
514struct GetSensorInfoRequest
515{
Patrick Venture0b02be92018-08-31 11:55:55 -0700516 uint8_t sensorType; //!< Type of the sensor
517 uint8_t entityId; //!< Entity ID
518 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
519 uint8_t instanceStart; //!< Instance start (used if instance is 0)
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600520} __attribute__((packed));
521
522/** @struct GetSensorInfoResponseHdr
523 *
524 * DCMI header for Get Sensor Info response
525 */
526struct GetSensorInfoResponseHdr
527{
Patrick Venture0b02be92018-08-31 11:55:55 -0700528 uint8_t numInstances; //!< No. of instances for requested id
529 uint8_t numRecords; //!< No. of record ids in the response
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600530} __attribute__((packed));
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600531/**
532 * @brief Parameters for DCMI Configuration Parameters
533 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700534enum class DCMIConfigParameters : uint8_t
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600535{
536 ActivateDHCP = 1,
537 DiscoveryConfig,
538 DHCPTiming1,
539 DHCPTiming2,
540 DHCPTiming3,
541};
542
543/** @struct SetConfParamsRequest
544 *
545 * DCMI Set DCMI Configuration Parameters Command.
546 * Refer DCMI specification Version 1.1 Section 6.1.2
547 */
548struct SetConfParamsRequest
549{
Patrick Venture0b02be92018-08-31 11:55:55 -0700550 uint8_t paramSelect; //!< Parameter selector.
551 uint8_t setSelect; //!< Set Selector (use 00h for parameters that only
552 //!< have one set).
553 uint8_t data[]; //!< Configuration parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600554} __attribute__((packed));
555
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600556/** @struct GetConfParamsRequest
557 *
558 * DCMI Get DCMI Configuration Parameters Command.
559 * Refer DCMI specification Version 1.1 Section 6.1.3
560 */
561struct GetConfParamsRequest
562{
Patrick Venture0b02be92018-08-31 11:55:55 -0700563 uint8_t paramSelect; //!< Parameter selector.
564 uint8_t setSelect; //!< Set Selector. Selects a given set of parameters
565 //!< under a given Parameter selector value. 00h if
566 //!< parameter doesn't use a Set Selector.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600567} __attribute__((packed));
568
569/** @struct GetConfParamsResponse
570 *
571 * DCMI Get DCMI Configuration Parameters Command response.
572 * Refer DCMI specification Version 1.1 Section 6.1.3
573 */
574struct GetConfParamsResponse
575{
Patrick Venture0b02be92018-08-31 11:55:55 -0700576 uint8_t major; //!< DCMI Spec Conformance - major ver = 01h.
577 uint8_t minor; //!< DCMI Spec Conformance - minor ver = 05h.
578 uint8_t paramRevision; //!< Parameter Revision = 01h.
579 uint8_t data[]; //!< Parameter data.
Nagaraju Goruganti22be97b2018-02-07 01:19:59 -0600580} __attribute__((packed));
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600581
Tom Josephbe5eaa12017-07-12 19:54:44 +0530582} // namespace dcmi