Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 3 | #include "occ_pass_through.hpp" |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 4 | #include "occ_status.hpp" |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 5 | #include "powercap.hpp" |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 6 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 7 | #include <cstring> |
| 8 | #include <functional> |
| 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <vector> |
| 11 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 12 | namespace sdbusRule = sdbusplus::bus::match::rules; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 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 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 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; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 30 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 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 | { |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 39 | #ifdef I2C_OCC |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 40 | // I2C OCC status objects are initialized directly |
| 41 | initStatusObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 42 | #else |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 43 | findAndCreateObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 44 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 45 | } |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 46 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 47 | inline auto getNumOCCs() const |
| 48 | { |
| 49 | return activeCount; |
| 50 | } |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 51 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 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(); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 58 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 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); |
Deepak Kodihalli | 5f031f3 | 2017-07-26 08:25:59 -0500 | [diff] [blame] | 67 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 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); |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 73 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 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); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 84 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 85 | /** @brief Sends a Heartbeat command to host control command handler */ |
| 86 | void sendHeartBeat(); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 87 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 88 | /** @brief reference to the bus */ |
| 89 | sdbusplus::bus::bus& bus; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 90 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 91 | /** @brief reference to sd_event wrapped in unique_ptr */ |
| 92 | EventPtr& event; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 93 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 94 | /** @brief OCC pass-through objects */ |
| 95 | std::vector<std::unique_ptr<PassThrough>> passThroughObjects; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 96 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 97 | /** @brief OCC Status objects */ |
| 98 | std::vector<std::unique_ptr<Status>> statusObjects; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 99 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 100 | /** @brief Power cap monitor and occ notification object */ |
| 101 | std::unique_ptr<open_power::occ::powercap::PowerCap> pcap; |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 102 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 103 | /** @brief sbdbusplus match objects */ |
| 104 | std::vector<sdbusplus::bus::match_t> cpuMatches; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 105 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 106 | /** @brief Number of OCCs that are bound */ |
| 107 | uint8_t activeCount = 0; |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 108 | |
| 109 | #ifdef I2C_OCC |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 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(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 116 | #endif |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | } // namespace occ |
| 120 | } // namespace open_power |