1 #pragma once 2 3 #include "occ_pass_through.hpp" 4 #include "occ_status.hpp" 5 #include "powercap.hpp" 6 7 #include <cstring> 8 #include <functional> 9 #include <sdbusplus/bus.hpp> 10 #include <vector> 11 12 namespace sdbusRule = sdbusplus::bus::match::rules; 13 namespace open_power 14 { 15 namespace occ 16 { 17 18 /** @class Manager 19 * @brief Builds and manages OCC objects 20 */ 21 struct Manager 22 { 23 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; 30 31 /** @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 { 39 #ifdef I2C_OCC 40 // I2C OCC status objects are initialized directly 41 initStatusObjects(); 42 #else 43 findAndCreateObjects(); 44 #endif 45 } 46 47 inline auto getNumOCCs() const 48 { 49 return activeCount; 50 } 51 52 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(); 58 59 /** @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); 67 68 /** @brief Create child OCC objects. 69 * 70 * @param[in] occ - the occ name, such as occ0. 71 */ 72 void createObjects(const std::string& occ); 73 74 /** @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); 84 85 /** @brief Sends a Heartbeat command to host control command handler */ 86 void sendHeartBeat(); 87 88 /** @brief reference to the bus */ 89 sdbusplus::bus::bus& bus; 90 91 /** @brief reference to sd_event wrapped in unique_ptr */ 92 EventPtr& event; 93 94 /** @brief OCC pass-through objects */ 95 std::vector<std::unique_ptr<PassThrough>> passThroughObjects; 96 97 /** @brief OCC Status objects */ 98 std::vector<std::unique_ptr<Status>> statusObjects; 99 100 /** @brief Power cap monitor and occ notification object */ 101 std::unique_ptr<open_power::occ::powercap::PowerCap> pcap; 102 103 /** @brief sbdbusplus match objects */ 104 std::vector<sdbusplus::bus::match_t> cpuMatches; 105 106 /** @brief Number of OCCs that are bound */ 107 uint8_t activeCount = 0; 108 109 #ifdef I2C_OCC 110 /** @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(); 116 #endif 117 }; 118 119 } // namespace occ 120 } // namespace open_power 121