blob: 1aaffc8660284fb722154ebc5b40a3c1e61cb80a [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;
26 Manager(Manager&&) = default;
27 Manager& operator=(Manager&&) = default;
28 ~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
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053049 private:
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053050 /** @brief Checks if the CPU inventory is present and if so, creates
51 * the occ D-Bus objects. Else, registers a handler to be
52 * called when inventory is created.
53 */
54 void findAndCreateObjects();
55
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053056 /** @brief Callback that responds to cpu creation in the inventory -
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053057 * by creating the needed objects.
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053058 *
59 * @param[in] msg - bus message
60 *
61 * @returns 0 to indicate success
62 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053063 int cpuCreated(sdbusplus::message::message& msg);
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050064
Deepak Kodihalli5f031f32017-07-26 08:25:59 -050065 /** @brief Create child OCC objects.
66 *
67 * @param[in] occ - the occ name, such as occ0.
68 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053069 void createObjects(const std::string& occ);
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053070
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053071 /** @brief Callback handler invoked by Status object when the OccActive
72 * property is changed. This is needed to make sure that the
73 * error detection is started only after all the OCCs are bound.
74 * Similarly, when one of the OCC gets its OccActive property
75 * un-set, then the OCC error detection needs to be stopped on
76 * all the OCCs
77 *
78 * @param[in] status - OccActive status
79 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053080 void statusCallBack(bool status);
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053081
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +053082 /** @brief Sends a Heartbeat command to host control command handler */
83 void sendHeartBeat();
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053084
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053085 /** @brief reference to the bus */
86 sdbusplus::bus::bus& bus;
87
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053088 /** @brief reference to sd_event wrapped in unique_ptr */
89 EventPtr& event;
90
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053091 /** @brief OCC pass-through objects */
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053092 std::vector<std::unique_ptr<PassThrough>> passThroughObjects;
93
94 /** @brief OCC Status objects */
95 std::vector<std::unique_ptr<Status>> statusObjects;
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +053096
Andrew Geissler52cf26a2017-07-06 12:56:32 -050097 /** @brief Power cap monitor and occ notification object */
98 std::unique_ptr<open_power::occ::powercap::PowerCap> pcap;
99
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530100 /** @brief sbdbusplus match objects */
101 std::vector<sdbusplus::bus::match_t> cpuMatches;
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530102
103 /** @brief Number of OCCs that are bound */
104 uint8_t activeCount = 0;
Lei YU0ab90ca2017-07-13 17:02:23 +0800105
106#ifdef I2C_OCC
107 /** @brief Init Status objects for I2C OCC devices
108 *
109 * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices
110 * and creates status objects.
111 */
Vishwanatha Subbannadfc7ec72017-09-07 18:18:01 +0530112 void initStatusObjects();
Lei YU0ab90ca2017-07-13 17:02:23 +0800113#endif
Vishwanatha Subbanna2180b2d2017-06-28 14:05:57 +0530114};
115
116} // namespace occ
117} // namespace open_power