blob: d8282b1c30c6c99d08ce5dcf05e39c9812f70864 [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"
Tom Joseph815f9f52020-07-27 12:12:13 +05305#ifdef PLDM
6#include "pldm.hpp"
7#endif
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +05308#include "powercap.hpp"
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +05309
Gunnar Mills94df8c92018-09-14 14:50:03 -050010#include <cstring>
11#include <functional>
12#include <sdbusplus/bus.hpp>
13#include <vector>
14
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053015namespace sdbusRule = sdbusplus::bus::match::rules;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053016namespace open_power
17{
18namespace occ
19{
20
21/** @class Manager
22 * @brief Builds and manages OCC objects
23 */
24struct Manager
25{
Gunnar Mills94df8c92018-09-14 14:50:03 -050026 public:
27 Manager() = delete;
28 Manager(const Manager&) = delete;
29 Manager& operator=(const Manager&) = delete;
30 Manager(Manager&&) = delete;
31 Manager& operator=(Manager&&) = delete;
32 ~Manager() = default;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053033
Gunnar Mills94df8c92018-09-14 14:50:03 -050034 /** @brief Adds OCC pass-through and status objects on the bus
35 * when corresponding CPU inventory is created.
36 *
37 * @param[in] bus - handle to the bus
38 * @param[in] event - Unique ptr reference to sd_event
39 */
Tom Joseph815f9f52020-07-27 12:12:13 +053040 Manager(sdbusplus::bus::bus& bus, EventPtr& event) :
41 bus(bus), event(event)
42#ifdef PLDM
43 ,
44 pldmHandle(std::make_unique<pldm::Interface>(
45 bus, std::bind(std::mem_fn(&Manager::updateOCCActive), this,
46 std::placeholders::_1, std::placeholders::_2)))
47#endif
48
Gunnar Mills94df8c92018-09-14 14:50:03 -050049 {
Lei YU0ab90ca2017-07-13 17:02:23 +080050#ifdef I2C_OCC
Gunnar Mills94df8c92018-09-14 14:50:03 -050051 // I2C OCC status objects are initialized directly
52 initStatusObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +080053#else
Gunnar Mills94df8c92018-09-14 14:50:03 -050054 findAndCreateObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +080055#endif
Gunnar Mills94df8c92018-09-14 14:50:03 -050056 }
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053057
Gunnar Mills94df8c92018-09-14 14:50:03 -050058 inline auto getNumOCCs() const
59 {
60 return activeCount;
61 }
Edward A. James636577f2017-10-06 10:53:55 -050062
Gunnar Mills94df8c92018-09-14 14:50:03 -050063 private:
64 /** @brief Checks if the CPU inventory is present and if so, creates
65 * the occ D-Bus objects. Else, registers a handler to be
66 * called when inventory is created.
67 */
68 void findAndCreateObjects();
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053069
Gunnar Mills94df8c92018-09-14 14:50:03 -050070 /** @brief Callback that responds to cpu creation in the inventory -
71 * by creating the needed objects.
72 *
73 * @param[in] msg - bus message
74 *
75 * @returns 0 to indicate success
76 */
77 int cpuCreated(sdbusplus::message::message& msg);
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050078
Gunnar Mills94df8c92018-09-14 14:50:03 -050079 /** @brief Create child OCC objects.
80 *
81 * @param[in] occ - the occ name, such as occ0.
82 */
83 void createObjects(const std::string& occ);
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053084
Gunnar Mills94df8c92018-09-14 14:50:03 -050085 /** @brief Callback handler invoked by Status object when the OccActive
86 * property is changed. This is needed to make sure that the
87 * error detection is started only after all the OCCs are bound.
88 * Similarly, when one of the OCC gets its OccActive property
89 * un-set, then the OCC error detection needs to be stopped on
90 * all the OCCs
91 *
92 * @param[in] status - OccActive status
93 */
94 void statusCallBack(bool status);
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053095
Gunnar Mills94df8c92018-09-14 14:50:03 -050096 /** @brief Sends a Heartbeat command to host control command handler */
97 void sendHeartBeat();
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053098
Gunnar Mills94df8c92018-09-14 14:50:03 -050099 /** @brief reference to the bus */
100 sdbusplus::bus::bus& bus;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530101
Gunnar Mills94df8c92018-09-14 14:50:03 -0500102 /** @brief reference to sd_event wrapped in unique_ptr */
103 EventPtr& event;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530104
Gunnar Mills94df8c92018-09-14 14:50:03 -0500105 /** @brief OCC pass-through objects */
106 std::vector<std::unique_ptr<PassThrough>> passThroughObjects;
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530107
Gunnar Mills94df8c92018-09-14 14:50:03 -0500108 /** @brief OCC Status objects */
109 std::vector<std::unique_ptr<Status>> statusObjects;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530110
Gunnar Mills94df8c92018-09-14 14:50:03 -0500111 /** @brief Power cap monitor and occ notification object */
112 std::unique_ptr<open_power::occ::powercap::PowerCap> pcap;
Andrew Geissler52cf26a2017-07-06 12:56:32 -0500113
Gunnar Mills94df8c92018-09-14 14:50:03 -0500114 /** @brief sbdbusplus match objects */
115 std::vector<sdbusplus::bus::match_t> cpuMatches;
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530116
Gunnar Mills94df8c92018-09-14 14:50:03 -0500117 /** @brief Number of OCCs that are bound */
118 uint8_t activeCount = 0;
Lei YU0ab90ca2017-07-13 17:02:23 +0800119
120#ifdef I2C_OCC
Gunnar Mills94df8c92018-09-14 14:50:03 -0500121 /** @brief Init Status objects for I2C OCC devices
122 *
123 * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices
124 * and creates status objects.
125 */
126 void initStatusObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +0800127#endif
Tom Joseph815f9f52020-07-27 12:12:13 +0530128
129#ifdef PLDM
130 /** @brief Callback handler invoked by the PLDM event handler when state of
131 * the OCC is toggled by the host. The caller passes the instance
132 * of the OCC and state of the OCC.
133 *
134 * @param[in] instance - instance of the OCC
135 * @param[in] status - true when the OCC goes active and false when the OCC
136 * goes inactive
137 *
138 * @return true if setting the state of OCC is successful and false if it
139 * fails.
140 */
141 bool updateOCCActive(instanceID instance, bool status);
142
143 std::unique_ptr<pldm::Interface> pldmHandle = nullptr;
144#endif
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530145};
146
147} // namespace occ
148} // namespace open_power