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; |
| 26 | Manager(Manager&&) = default; |
| 27 | Manager& operator=(Manager&&) = default; |
| 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 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 49 | private: |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 50 | /** @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 Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 56 | /** @brief Callback that responds to cpu creation in the inventory - |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 57 | * by creating the needed objects. |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 58 | * |
| 59 | * @param[in] msg - bus message |
| 60 | * |
| 61 | * @returns 0 to indicate success |
| 62 | */ |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 63 | int cpuCreated(sdbusplus::message::message& msg); |
Deepak Kodihalli | 5f031f3 | 2017-07-26 08:25:59 -0500 | [diff] [blame] | 64 | |
Deepak Kodihalli | 5f031f3 | 2017-07-26 08:25:59 -0500 | [diff] [blame] | 65 | /** @brief Create child OCC objects. |
| 66 | * |
| 67 | * @param[in] occ - the occ name, such as occ0. |
| 68 | */ |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 69 | void createObjects(const std::string& occ); |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 70 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 71 | /** @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 Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 80 | void statusCallBack(bool status); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 81 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 82 | /** @brief Sends a Heartbeat command to host control command handler */ |
| 83 | void sendHeartBeat(); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 84 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 85 | /** @brief reference to the bus */ |
| 86 | sdbusplus::bus::bus& bus; |
| 87 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 88 | /** @brief reference to sd_event wrapped in unique_ptr */ |
| 89 | EventPtr& event; |
| 90 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 91 | /** @brief OCC pass-through objects */ |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 92 | std::vector<std::unique_ptr<PassThrough>> passThroughObjects; |
| 93 | |
| 94 | /** @brief OCC Status objects */ |
| 95 | std::vector<std::unique_ptr<Status>> statusObjects; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 96 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 97 | /** @brief Power cap monitor and occ notification object */ |
| 98 | std::unique_ptr<open_power::occ::powercap::PowerCap> pcap; |
| 99 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 100 | /** @brief sbdbusplus match objects */ |
| 101 | std::vector<sdbusplus::bus::match_t> cpuMatches; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 102 | |
| 103 | /** @brief Number of OCCs that are bound */ |
| 104 | uint8_t activeCount = 0; |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 105 | |
| 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 Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 112 | void initStatusObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 113 | #endif |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace occ |
| 117 | } // namespace open_power |