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" |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame^] | 5 | #ifdef PLDM |
| 6 | #include "pldm.hpp" |
| 7 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 8 | #include "powercap.hpp" |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 9 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 10 | #include <cstring> |
| 11 | #include <functional> |
| 12 | #include <sdbusplus/bus.hpp> |
| 13 | #include <vector> |
| 14 | |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 15 | namespace sdbusRule = sdbusplus::bus::match::rules; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 16 | namespace open_power |
| 17 | { |
| 18 | namespace occ |
| 19 | { |
| 20 | |
| 21 | /** @class Manager |
| 22 | * @brief Builds and manages OCC objects |
| 23 | */ |
| 24 | struct Manager |
| 25 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 26 | public: |
| 27 | Manager() = delete; |
| 28 | Manager(const Manager&) = delete; |
| 29 | Manager& operator=(const Manager&) = delete; |
| 30 | Manager(Manager&&) = delete; |
| 31 | Manager& operator=(Manager&&) = delete; |
| 32 | ~Manager() = default; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 33 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 34 | /** @brief Adds OCC pass-through and status objects on the bus |
| 35 | * when corresponding CPU inventory is created. |
| 36 | * |
| 37 | * @param[in] bus - handle to the bus |
| 38 | * @param[in] event - Unique ptr reference to sd_event |
| 39 | */ |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame^] | 40 | Manager(sdbusplus::bus::bus& bus, EventPtr& event) : |
| 41 | bus(bus), event(event) |
| 42 | #ifdef PLDM |
| 43 | , |
| 44 | pldmHandle(std::make_unique<pldm::Interface>( |
| 45 | bus, std::bind(std::mem_fn(&Manager::updateOCCActive), this, |
| 46 | std::placeholders::_1, std::placeholders::_2))) |
| 47 | #endif |
| 48 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 49 | { |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 50 | #ifdef I2C_OCC |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 51 | // I2C OCC status objects are initialized directly |
| 52 | initStatusObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 53 | #else |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 54 | findAndCreateObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 55 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 56 | } |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 57 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 58 | inline auto getNumOCCs() const |
| 59 | { |
| 60 | return activeCount; |
| 61 | } |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 62 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 63 | private: |
| 64 | /** @brief Checks if the CPU inventory is present and if so, creates |
| 65 | * the occ D-Bus objects. Else, registers a handler to be |
| 66 | * called when inventory is created. |
| 67 | */ |
| 68 | void findAndCreateObjects(); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 69 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 70 | /** @brief Callback that responds to cpu creation in the inventory - |
| 71 | * by creating the needed objects. |
| 72 | * |
| 73 | * @param[in] msg - bus message |
| 74 | * |
| 75 | * @returns 0 to indicate success |
| 76 | */ |
| 77 | int cpuCreated(sdbusplus::message::message& msg); |
Deepak Kodihalli | 5f031f3 | 2017-07-26 08:25:59 -0500 | [diff] [blame] | 78 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 79 | /** @brief Create child OCC objects. |
| 80 | * |
| 81 | * @param[in] occ - the occ name, such as occ0. |
| 82 | */ |
| 83 | void createObjects(const std::string& occ); |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 84 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 85 | /** @brief Callback handler invoked by Status object when the OccActive |
| 86 | * property is changed. This is needed to make sure that the |
| 87 | * error detection is started only after all the OCCs are bound. |
| 88 | * Similarly, when one of the OCC gets its OccActive property |
| 89 | * un-set, then the OCC error detection needs to be stopped on |
| 90 | * all the OCCs |
| 91 | * |
| 92 | * @param[in] status - OccActive status |
| 93 | */ |
| 94 | void statusCallBack(bool status); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 95 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 96 | /** @brief Sends a Heartbeat command to host control command handler */ |
| 97 | void sendHeartBeat(); |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 98 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 99 | /** @brief reference to the bus */ |
| 100 | sdbusplus::bus::bus& bus; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 101 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 102 | /** @brief reference to sd_event wrapped in unique_ptr */ |
| 103 | EventPtr& event; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 104 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 105 | /** @brief OCC pass-through objects */ |
| 106 | std::vector<std::unique_ptr<PassThrough>> passThroughObjects; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 107 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 108 | /** @brief OCC Status objects */ |
| 109 | std::vector<std::unique_ptr<Status>> statusObjects; |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 110 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 111 | /** @brief Power cap monitor and occ notification object */ |
| 112 | std::unique_ptr<open_power::occ::powercap::PowerCap> pcap; |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 113 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 114 | /** @brief sbdbusplus match objects */ |
| 115 | std::vector<sdbusplus::bus::match_t> cpuMatches; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 116 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 117 | /** @brief Number of OCCs that are bound */ |
| 118 | uint8_t activeCount = 0; |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 119 | |
| 120 | #ifdef I2C_OCC |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 121 | /** @brief Init Status objects for I2C OCC devices |
| 122 | * |
| 123 | * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices |
| 124 | * and creates status objects. |
| 125 | */ |
| 126 | void initStatusObjects(); |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 127 | #endif |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame^] | 128 | |
| 129 | #ifdef PLDM |
| 130 | /** @brief Callback handler invoked by the PLDM event handler when state of |
| 131 | * the OCC is toggled by the host. The caller passes the instance |
| 132 | * of the OCC and state of the OCC. |
| 133 | * |
| 134 | * @param[in] instance - instance of the OCC |
| 135 | * @param[in] status - true when the OCC goes active and false when the OCC |
| 136 | * goes inactive |
| 137 | * |
| 138 | * @return true if setting the state of OCC is successful and false if it |
| 139 | * fails. |
| 140 | */ |
| 141 | bool updateOCCActive(instanceID instance, bool status); |
| 142 | |
| 143 | std::unique_ptr<pldm::Interface> pldmHandle = nullptr; |
| 144 | #endif |
Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | } // namespace occ |
| 148 | } // namespace open_power |