blob: 20002e400d1ce46a570b61abcbb8d120477e34fc [file] [log] [blame]
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +05301#pragma once
2
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +05303#include "occ_pass_through.hpp"
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05304#include "occ_status.hpp"
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +05305#include "powercap.hpp"
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +05306
Gunnar Mills94df8c92018-09-14 14:50:03 -05007#include <cstring>
8#include <functional>
9#include <sdbusplus/bus.hpp>
10#include <vector>
11
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053012namespace sdbusRule = sdbusplus::bus::match::rules;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053013namespace open_power
14{
15namespace occ
16{
17
18/** @class Manager
19 * @brief Builds and manages OCC objects
20 */
21struct Manager
22{
Gunnar Mills94df8c92018-09-14 14:50:03 -050023 public:
24 Manager() = delete;
25 Manager(const Manager&) = delete;
26 Manager& operator=(const Manager&) = delete;
27 Manager(Manager&&) = delete;
28 Manager& operator=(Manager&&) = delete;
29 ~Manager() = default;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053030
Gunnar Mills94df8c92018-09-14 14:50:03 -050031 /** @brief Adds OCC pass-through and status objects on the bus
32 * when corresponding CPU inventory is created.
33 *
34 * @param[in] bus - handle to the bus
35 * @param[in] event - Unique ptr reference to sd_event
36 */
37 Manager(sdbusplus::bus::bus& bus, EventPtr& event) : bus(bus), event(event)
38 {
Lei YU0ab90ca2017-07-13 17:02:23 +080039#ifdef I2C_OCC
Gunnar Mills94df8c92018-09-14 14:50:03 -050040 // I2C OCC status objects are initialized directly
41 initStatusObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +080042#else
Gunnar Mills94df8c92018-09-14 14:50:03 -050043 findAndCreateObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +080044#endif
Gunnar Mills94df8c92018-09-14 14:50:03 -050045 }
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053046
Gunnar Mills94df8c92018-09-14 14:50:03 -050047 inline auto getNumOCCs() const
48 {
49 return activeCount;
50 }
Edward A. James636577f2017-10-06 10:53:55 -050051
Gunnar Mills94df8c92018-09-14 14:50:03 -050052 private:
53 /** @brief Checks if the CPU inventory is present and if so, creates
54 * the occ D-Bus objects. Else, registers a handler to be
55 * called when inventory is created.
56 */
57 void findAndCreateObjects();
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053058
Gunnar Mills94df8c92018-09-14 14:50:03 -050059 /** @brief Callback that responds to cpu creation in the inventory -
60 * by creating the needed objects.
61 *
62 * @param[in] msg - bus message
63 *
64 * @returns 0 to indicate success
65 */
66 int cpuCreated(sdbusplus::message::message& msg);
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050067
Gunnar Mills94df8c92018-09-14 14:50:03 -050068 /** @brief Create child OCC objects.
69 *
70 * @param[in] occ - the occ name, such as occ0.
71 */
72 void createObjects(const std::string& occ);
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053073
Gunnar Mills94df8c92018-09-14 14:50:03 -050074 /** @brief Callback handler invoked by Status object when the OccActive
75 * property is changed. This is needed to make sure that the
76 * error detection is started only after all the OCCs are bound.
77 * Similarly, when one of the OCC gets its OccActive property
78 * un-set, then the OCC error detection needs to be stopped on
79 * all the OCCs
80 *
81 * @param[in] status - OccActive status
82 */
83 void statusCallBack(bool status);
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053084
Gunnar Mills94df8c92018-09-14 14:50:03 -050085 /** @brief Sends a Heartbeat command to host control command handler */
86 void sendHeartBeat();
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053087
Gunnar Mills94df8c92018-09-14 14:50:03 -050088 /** @brief reference to the bus */
89 sdbusplus::bus::bus& bus;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053090
Gunnar Mills94df8c92018-09-14 14:50:03 -050091 /** @brief reference to sd_event wrapped in unique_ptr */
92 EventPtr& event;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053093
Gunnar Mills94df8c92018-09-14 14:50:03 -050094 /** @brief OCC pass-through objects */
95 std::vector<std::unique_ptr<PassThrough>> passThroughObjects;
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053096
Gunnar Mills94df8c92018-09-14 14:50:03 -050097 /** @brief OCC Status objects */
98 std::vector<std::unique_ptr<Status>> statusObjects;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053099
Gunnar Mills94df8c92018-09-14 14:50:03 -0500100 /** @brief Power cap monitor and occ notification object */
101 std::unique_ptr<open_power::occ::powercap::PowerCap> pcap;
Andrew Geissler52cf26a2017-07-06 12:56:32 -0500102
Gunnar Mills94df8c92018-09-14 14:50:03 -0500103 /** @brief sbdbusplus match objects */
104 std::vector<sdbusplus::bus::match_t> cpuMatches;
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530105
Gunnar Mills94df8c92018-09-14 14:50:03 -0500106 /** @brief Number of OCCs that are bound */
107 uint8_t activeCount = 0;
Lei YU0ab90ca2017-07-13 17:02:23 +0800108
109#ifdef I2C_OCC
Gunnar Mills94df8c92018-09-14 14:50:03 -0500110 /** @brief Init Status objects for I2C OCC devices
111 *
112 * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices
113 * and creates status objects.
114 */
115 void initStatusObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +0800116#endif
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530117};
118
119} // namespace occ
120} // namespace open_power