blob: 542c7d9e18d997fb3a2c6a8658d87d959b37356c [file] [log] [blame]
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +05301#pragma once
2
3#include <cstring>
4#include <vector>
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +05305#include <functional>
6#include <sdbusplus/bus.hpp>
7#include "occ_pass_through.hpp"
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05308#include "occ_status.hpp"
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +05309#include "powercap.hpp"
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053010
11namespace sdbusRule = sdbusplus::bus::match::rules;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053012namespace open_power
13{
14namespace occ
15{
16
17/** @class Manager
18 * @brief Builds and manages OCC objects
19 */
20struct Manager
21{
22 public:
23 Manager() = delete;
24 Manager(const Manager&) = delete;
25 Manager& operator=(const Manager&) = delete;
Edward A. James636577f2017-10-06 10:53:55 -050026 Manager(Manager&&) = delete;
27 Manager& operator=(Manager&&) = delete;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053028 ~Manager() = default;
29
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053030 /** @brief Adds OCC pass-through and status objects on the bus
31 * when corresponding CPU inventory is created.
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053032 *
33 * @param[in] bus - handle to the bus
34 * @param[in] event - Unique ptr reference to sd_event
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053035 */
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053036 Manager(sdbusplus::bus::bus& bus,
37 EventPtr& event) :
38 bus(bus),
39 event(event)
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053040 {
Lei YU0ab90ca2017-07-13 17:02:23 +080041#ifdef I2C_OCC
42 // I2C OCC status objects are initialized directly
43 initStatusObjects();
44#else
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053045 findAndCreateObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +080046#endif
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053047 }
48
Edward A. James636577f2017-10-06 10:53:55 -050049 inline auto getNumOCCs() const
50 {
51 return activeCount;
52 }
53
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053054 private:
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053055 /** @brief Checks if the CPU inventory is present and if so, creates
56 * the occ D-Bus objects. Else, registers a handler to be
57 * called when inventory is created.
58 */
59 void findAndCreateObjects();
60
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053061 /** @brief Callback that responds to cpu creation in the inventory -
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053062 * by creating the needed objects.
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053063 *
64 * @param[in] msg - bus message
65 *
66 * @returns 0 to indicate success
67 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053068 int cpuCreated(sdbusplus::message::message& msg);
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050069
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050070 /** @brief Create child OCC objects.
71 *
72 * @param[in] occ - the occ name, such as occ0.
73 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053074 void createObjects(const std::string& occ);
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053075
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053076 /** @brief Callback handler invoked by Status object when the OccActive
77 * property is changed. This is needed to make sure that the
78 * error detection is started only after all the OCCs are bound.
79 * Similarly, when one of the OCC gets its OccActive property
80 * un-set, then the OCC error detection needs to be stopped on
81 * all the OCCs
82 *
83 * @param[in] status - OccActive status
84 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053085 void statusCallBack(bool status);
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053086
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053087 /** @brief Sends a Heartbeat command to host control command handler */
88 void sendHeartBeat();
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053089
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053090 /** @brief reference to the bus */
91 sdbusplus::bus::bus& bus;
92
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053093 /** @brief reference to sd_event wrapped in unique_ptr */
94 EventPtr& event;
95
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053096 /** @brief OCC pass-through objects */
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053097 std::vector<std::unique_ptr<PassThrough>> passThroughObjects;
98
99 /** @brief OCC Status objects */
100 std::vector<std::unique_ptr<Status>> statusObjects;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530101
Andrew Geissler52cf26a2017-07-06 12:56:32 -0500102 /** @brief Power cap monitor and occ notification object */
103 std::unique_ptr<open_power::occ::powercap::PowerCap> pcap;
104
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530105 /** @brief sbdbusplus match objects */
106 std::vector<sdbusplus::bus::match_t> cpuMatches;
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530107
108 /** @brief Number of OCCs that are bound */
109 uint8_t activeCount = 0;
Lei YU0ab90ca2017-07-13 17:02:23 +0800110
111#ifdef I2C_OCC
112 /** @brief Init Status objects for I2C OCC devices
113 *
114 * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices
115 * and creates status objects.
116 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +0530117 void initStatusObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +0800118#endif
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530119};
120
121} // namespace occ
122} // namespace open_power