Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <cstring> |
| 4 | #include <vector> |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 5 | #include <functional> |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include "occ_pass_through.hpp" |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 8 | #include "occ_status.hpp" |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 9 | #include "powercap.hpp" |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 10 | |
| 11 | namespace sdbusRule = sdbusplus::bus::match::rules; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 12 | namespace open_power |
| 13 | { |
| 14 | namespace occ |
| 15 | { |
| 16 | |
| 17 | /** @class Manager |
| 18 | * @brief Builds and manages OCC objects |
| 19 | */ |
| 20 | struct Manager |
| 21 | { |
| 22 | public: |
| 23 | Manager() = delete; |
| 24 | Manager(const Manager&) = delete; |
| 25 | Manager& operator=(const Manager&) = delete; |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 26 | Manager(Manager&&) = delete; |
| 27 | Manager& operator=(Manager&&) = delete; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 28 | ~Manager() = default; |
| 29 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 30 | /** @brief Adds OCC pass-through and status objects on the bus |
| 31 | * when corresponding CPU inventory is created. |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 32 | * |
| 33 | * @param[in] bus - handle to the bus |
| 34 | * @param[in] event - Unique ptr reference to sd_event |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 35 | */ |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 36 | Manager(sdbusplus::bus::bus& bus, |
| 37 | EventPtr& event) : |
| 38 | bus(bus), |
| 39 | event(event) |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 40 | { |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 41 | #ifdef I2C_OCC |
| 42 | // I2C OCC status objects are initialized directly |
| 43 | initStatusObjects(); |
| 44 | #else |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 45 | findAndCreateObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 46 | #endif |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 47 | } |
| 48 | |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 49 | inline auto getNumOCCs() const |
| 50 | { |
| 51 | return activeCount; |
| 52 | } |
| 53 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 54 | private: |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 55 | /** @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 Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 61 | /** @brief Callback that responds to cpu creation in the inventory - |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 62 | * by creating the needed objects. |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 63 | * |
| 64 | * @param[in] msg - bus message |
| 65 | * |
| 66 | * @returns 0 to indicate success |
| 67 | */ |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 68 | int cpuCreated(sdbusplus::message::message& msg); |
Deepak Kodihalli | 5f031f3 | 2017-07-26 08:25:59 -0500 | [diff] [blame] | 69 | |
Deepak Kodihalli | 5f031f3 | 2017-07-26 08:25:59 -0500 | [diff] [blame] | 70 | /** @brief Create child OCC objects. |
| 71 | * |
| 72 | * @param[in] occ - the occ name, such as occ0. |
| 73 | */ |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 74 | void createObjects(const std::string& occ); |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 75 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 76 | /** @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 Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 85 | void statusCallBack(bool status); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 86 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 87 | /** @brief Sends a Heartbeat command to host control command handler */ |
| 88 | void sendHeartBeat(); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 89 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 90 | /** @brief reference to the bus */ |
| 91 | sdbusplus::bus::bus& bus; |
| 92 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 93 | /** @brief reference to sd_event wrapped in unique_ptr */ |
| 94 | EventPtr& event; |
| 95 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 96 | /** @brief OCC pass-through objects */ |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 97 | std::vector<std::unique_ptr<PassThrough>> passThroughObjects; |
| 98 | |
| 99 | /** @brief OCC Status objects */ |
| 100 | std::vector<std::unique_ptr<Status>> statusObjects; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 101 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 102 | /** @brief Power cap monitor and occ notification object */ |
| 103 | std::unique_ptr<open_power::occ::powercap::PowerCap> pcap; |
| 104 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 105 | /** @brief sbdbusplus match objects */ |
| 106 | std::vector<sdbusplus::bus::match_t> cpuMatches; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 107 | |
| 108 | /** @brief Number of OCCs that are bound */ |
| 109 | uint8_t activeCount = 0; |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 110 | |
| 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 Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 117 | void initStatusObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 118 | #endif |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | } // namespace occ |
| 122 | } // namespace open_power |