| 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" | 
| Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 7 |  | 
|  | 8 | #include <libphal.H> | 
| Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 9 | #endif | 
| Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 10 | #include "powercap.hpp" | 
| George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 11 | #include "utils.hpp" | 
| Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 12 | #ifdef POWER10 | 
|  | 13 | #include "powermode.hpp" | 
|  | 14 | #endif | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 15 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 16 | #include <sdbusplus/bus.hpp> | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 17 | #include <sdeventplus/event.hpp> | 
|  | 18 | #include <sdeventplus/utility/timer.hpp> | 
| George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 19 |  | 
|  | 20 | #include <cstring> | 
|  | 21 | #include <functional> | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 22 | #include <vector> | 
|  | 23 |  | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 24 | namespace sdbusRule = sdbusplus::bus::match::rules; | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 25 | namespace open_power | 
|  | 26 | { | 
|  | 27 | namespace occ | 
|  | 28 | { | 
|  | 29 |  | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 30 | #ifdef READ_OCC_SENSORS | 
|  | 31 | enum occFruType | 
|  | 32 | { | 
|  | 33 | processorCore = 0, | 
|  | 34 | internalMemCtlr = 1, | 
|  | 35 | dimm = 2, | 
|  | 36 | memCtrlAndDimm = 3, | 
|  | 37 | VRMVdd = 6, | 
|  | 38 | PMIC = 7, | 
| Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 39 | memCtlrExSensor = 8, | 
|  | 40 | processorIoRing = 9 | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 41 | }; | 
|  | 42 | #endif | 
|  | 43 |  | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 44 | /** @brief Default time, in seconds, between OCC poll commands */ | 
| Matt Spinler | 3792346 | 2021-09-24 11:38:05 -0500 | [diff] [blame] | 45 | #ifndef POWER10 | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 46 | constexpr unsigned int defaultPollingInterval = 1; | 
| Matt Spinler | 3792346 | 2021-09-24 11:38:05 -0500 | [diff] [blame] | 47 | #else | 
|  | 48 | constexpr unsigned int defaultPollingInterval = 5; | 
|  | 49 | #endif | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 50 |  | 
| Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 51 | constexpr auto AMBIENT_PATH = | 
|  | 52 | "/xyz/openbmc_project/sensors/temperature/Ambient_Virtual_Temp"; | 
|  | 53 | constexpr auto AMBIENT_INTERFACE = "xyz.openbmc_project.Sensor.Value"; | 
|  | 54 | constexpr auto AMBIENT_PROP = "Value"; | 
|  | 55 | constexpr auto ALTITUDE_PATH = "/xyz/openbmc_project/sensors/altitude/Altitude"; | 
|  | 56 | constexpr auto ALTITUDE_INTERFACE = "xyz.openbmc_project.Sensor.Value"; | 
|  | 57 | constexpr auto ALTITUDE_PROP = "Value"; | 
|  | 58 |  | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 59 | /** @class Manager | 
|  | 60 | *  @brief Builds and manages OCC objects | 
|  | 61 | */ | 
|  | 62 | struct Manager | 
|  | 63 | { | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 64 | public: | 
|  | 65 | Manager() = delete; | 
|  | 66 | Manager(const Manager&) = delete; | 
|  | 67 | Manager& operator=(const Manager&) = delete; | 
|  | 68 | Manager(Manager&&) = delete; | 
|  | 69 | Manager& operator=(Manager&&) = delete; | 
|  | 70 | ~Manager() = default; | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 71 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 72 | /** @brief Adds OCC pass-through and status objects on the bus | 
|  | 73 | *         when corresponding CPU inventory is created. | 
|  | 74 | * | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 75 | *  @param[in] event - Unique ptr reference to sd_event | 
|  | 76 | */ | 
| George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 77 | explicit Manager(EventPtr& event) : | 
| George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 78 | event(event), pollInterval(defaultPollingInterval), | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 79 | sdpEvent(sdeventplus::Event::get_default()), | 
|  | 80 | _pollTimer( | 
|  | 81 | std::make_unique< | 
|  | 82 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>( | 
| Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 83 | sdpEvent, std::bind(&Manager::pollerTimerExpired, this))), | 
|  | 84 | ambientPropChanged( | 
|  | 85 | utils::getBus(), | 
|  | 86 | sdbusRule::member("PropertiesChanged") + | 
|  | 87 | sdbusRule::path(AMBIENT_PATH) + | 
|  | 88 | sdbusRule::argN(0, AMBIENT_INTERFACE) + | 
|  | 89 | sdbusRule::interface("org.freedesktop.DBus.Properties"), | 
|  | 90 | std::bind(&Manager::ambientCallback, this, std::placeholders::_1)) | 
| Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 91 | #ifdef PLDM | 
|  | 92 | , | 
|  | 93 | pldmHandle(std::make_unique<pldm::Interface>( | 
| George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 94 | std::bind(std::mem_fn(&Manager::updateOCCActive), this, | 
| Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 95 | std::placeholders::_1, std::placeholders::_2), | 
|  | 96 | std::bind(std::mem_fn(&Manager::sbeHRESETResult), this, | 
| Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 97 | std::placeholders::_1, std::placeholders::_2), | 
|  | 98 | event)) | 
| Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 99 | #endif | 
| Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 100 | #ifdef POWER10 | 
|  | 101 | , | 
|  | 102 | discoverTimer( | 
|  | 103 | std::make_unique< | 
|  | 104 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>( | 
| Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 105 | sdpEvent, std::bind(&Manager::findAndCreateObjects, this))), | 
|  | 106 | waitForAllOccsTimer( | 
|  | 107 | std::make_unique< | 
|  | 108 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>( | 
|  | 109 | sdpEvent, std::bind(&Manager::occsNotAllRunning, this))) | 
| Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 110 | #endif | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 111 | { | 
| Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 112 | #ifdef I2C_OCC | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 113 | // I2C OCC status objects are initialized directly | 
|  | 114 | initStatusObjects(); | 
| Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 115 | #else | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 116 | findAndCreateObjects(); | 
| Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 117 | #endif | 
| Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 118 | readAltitude(); | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 119 | } | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 120 |  | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 121 | /** @brief Return the number of bound OCCs */ | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 122 | inline auto getNumOCCs() const | 
|  | 123 | { | 
|  | 124 | return activeCount; | 
|  | 125 | } | 
| Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 126 |  | 
| Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 127 | #ifdef PLDM | 
|  | 128 | /** @brief Called by a Device to report that the SBE timed out | 
|  | 129 | *         and appropriate action should be taken | 
|  | 130 | * | 
|  | 131 | * @param[in] instance - the OCC instance id | 
|  | 132 | */ | 
|  | 133 | void sbeTimeout(unsigned int instance); | 
|  | 134 | #endif | 
|  | 135 |  | 
| Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 136 | /** @brief Return the latest ambient and altitude readings | 
|  | 137 | * | 
|  | 138 | *  @param[out] ambientValid - true if ambientTemp is valid | 
|  | 139 | *  @param[out] ambient - ambient temperature in degrees C | 
|  | 140 | *  @param[out] altitude - altitude in meters | 
|  | 141 | */ | 
|  | 142 | void getAmbientData(bool& ambientValid, uint8_t& ambientTemp, | 
|  | 143 | uint16_t& altitude) const; | 
|  | 144 |  | 
| Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 145 | /** @brief Notify pcap object to update bounds */ | 
|  | 146 | void updatePcapBounds() const; | 
|  | 147 |  | 
| Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 148 | /** @brief Set all sensor values of this OCC to NaN and non functional. | 
|  | 149 | * | 
|  | 150 | *  @param[in] id - Id of the OCC. | 
|  | 151 | */ | 
|  | 152 | void setSensorValueToNonFunctional(uint32_t id) const; | 
|  | 153 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 154 | private: | 
| Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 155 | /** @brief Creates the OCC D-Bus objects. | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 156 | */ | 
|  | 157 | void findAndCreateObjects(); | 
| Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 158 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 159 | /** @brief Callback that responds to cpu creation in the inventory - | 
|  | 160 | *         by creating the needed objects. | 
|  | 161 | * | 
|  | 162 | *  @param[in] msg - bus message | 
|  | 163 | * | 
|  | 164 | *  @returns 0 to indicate success | 
|  | 165 | */ | 
|  | 166 | int cpuCreated(sdbusplus::message::message& msg); | 
| Deepak Kodihalli | 5f031f3 | 2017-07-26 08:25:59 -0500 | [diff] [blame] | 167 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 168 | /** @brief Create child OCC objects. | 
|  | 169 | * | 
|  | 170 | *  @param[in] occ - the occ name, such as occ0. | 
|  | 171 | */ | 
|  | 172 | void createObjects(const std::string& occ); | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 173 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 174 | /** @brief Callback handler invoked by Status object when the OccActive | 
|  | 175 | *         property is changed. This is needed to make sure that the | 
|  | 176 | *         error detection is started only after all the OCCs are bound. | 
|  | 177 | *         Similarly, when one of the OCC gets its OccActive property | 
|  | 178 | *         un-set, then the OCC error detection needs to be stopped on | 
|  | 179 | *         all the OCCs | 
|  | 180 | * | 
|  | 181 | *  @param[in] status - OccActive status | 
|  | 182 | */ | 
| Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 183 | void statusCallBack(instanceID instance, bool status); | 
| Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 184 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 185 | /** @brief Sends a Heartbeat command to host control command handler */ | 
|  | 186 | void sendHeartBeat(); | 
| Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 187 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 188 | /** @brief reference to sd_event wrapped in unique_ptr */ | 
|  | 189 | EventPtr& event; | 
| Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 190 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 191 | /** @brief OCC pass-through objects */ | 
|  | 192 | std::vector<std::unique_ptr<PassThrough>> passThroughObjects; | 
| Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 193 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 194 | /** @brief OCC Status objects */ | 
|  | 195 | std::vector<std::unique_ptr<Status>> statusObjects; | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 196 |  | 
| Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 197 | /** @brief Power cap monitor and occ notification object */ | 
|  | 198 | std::unique_ptr<open_power::occ::powercap::PowerCap> pcap; | 
|  | 199 |  | 
| Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 200 | #ifdef POWER10 | 
|  | 201 | /** @brief Power mode monitor and notification object */ | 
|  | 202 | std::unique_ptr<open_power::occ::powermode::PowerMode> pmode; | 
|  | 203 | #endif | 
|  | 204 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 205 | /** @brief sbdbusplus match objects */ | 
|  | 206 | std::vector<sdbusplus::bus::match_t> cpuMatches; | 
| Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 207 |  | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 208 | /** @brief Number of OCCs that are bound */ | 
|  | 209 | uint8_t activeCount = 0; | 
| Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 210 |  | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 211 | /** @brief Number of seconds between poll commands */ | 
|  | 212 | uint8_t pollInterval; | 
|  | 213 |  | 
| Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 214 | /** @brief Ambient temperature of the system in degrees C */ | 
|  | 215 | uint8_t ambient = 0xFF; // default: not available | 
|  | 216 |  | 
|  | 217 | /** @brief Altitude of the system in meters */ | 
|  | 218 | uint16_t altitude = 0xFFFF; // default: not available | 
|  | 219 |  | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 220 | /** @brief Poll timer event */ | 
|  | 221 | sdeventplus::Event sdpEvent; | 
|  | 222 |  | 
| Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 223 | /** @brief Flags to indicate if waiting for all of the OCC active sensors to | 
|  | 224 | * come online */ | 
|  | 225 | bool waitingForAllOccActiveSensors = false; | 
|  | 226 |  | 
| Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 227 | /** @brief Set containing intance numbers of any OCCs that became active | 
|  | 228 | *         while waiting for status objects to be created */ | 
|  | 229 | std::set<uint8_t> queuedActiveState; | 
|  | 230 |  | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 231 | /** | 
|  | 232 | * @brief The timer to be used once the OCC goes active.  When it expires, | 
|  | 233 | *        a POLL command will be sent to the OCC and then timer restarted. | 
|  | 234 | */ | 
|  | 235 | std::unique_ptr< | 
|  | 236 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>> | 
|  | 237 | _pollTimer; | 
|  | 238 |  | 
| Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 239 | /** @brief Subscribe to ambient temperature changed events */ | 
|  | 240 | sdbusplus::bus::match_t ambientPropChanged; | 
|  | 241 |  | 
| Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 242 | #ifdef I2C_OCC | 
| Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 243 | /** @brief Init Status objects for I2C OCC devices | 
|  | 244 | * | 
|  | 245 | * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices | 
|  | 246 | * and creates status objects. | 
|  | 247 | */ | 
|  | 248 | void initStatusObjects(); | 
| Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 249 | #endif | 
| Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 250 |  | 
|  | 251 | #ifdef PLDM | 
|  | 252 | /** @brief Callback handler invoked by the PLDM event handler when state of | 
|  | 253 | *         the OCC is toggled by the host. The caller passes the instance | 
|  | 254 | *         of the OCC and state of the OCC. | 
|  | 255 | * | 
|  | 256 | *  @param[in] instance - instance of the OCC | 
|  | 257 | *  @param[in] status - true when the OCC goes active and false when the OCC | 
|  | 258 | *                      goes inactive | 
|  | 259 | * | 
|  | 260 | *  @return true if setting the state of OCC is successful and false if it | 
|  | 261 | *          fails. | 
|  | 262 | */ | 
|  | 263 | bool updateOCCActive(instanceID instance, bool status); | 
|  | 264 |  | 
| Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 265 | /** @brief Callback handler invoked by PLDM sensor change when | 
|  | 266 | *         the HRESET succeeds or fails. | 
|  | 267 | * | 
|  | 268 | *  @param[in] instance - the SBE instance id | 
|  | 269 | *  @param[in] success - true if the HRESET succeeded, otherwise false | 
|  | 270 | */ | 
|  | 271 | void sbeHRESETResult(instanceID instance, bool success); | 
|  | 272 |  | 
|  | 273 | /** @brief Helper function to check whether an SBE dump should be collected | 
|  | 274 | *         now. | 
|  | 275 | * | 
|  | 276 | *  @param[in] instance - the SBE instance id | 
|  | 277 | * | 
|  | 278 | *  @return true if an SBE dump should be collected and false if not | 
|  | 279 | */ | 
|  | 280 | bool sbeCanDump(unsigned int instance); | 
|  | 281 |  | 
|  | 282 | /** @brief Helper function to set the SBE state through PDBG/PHAL | 
|  | 283 | * | 
|  | 284 | * @param[in] instance - instance of the SBE | 
|  | 285 | * @param[in] state - the state to which the SBE should be set | 
|  | 286 | * | 
|  | 287 | */ | 
|  | 288 | void setSBEState(unsigned int instance, enum sbe_state state); | 
|  | 289 |  | 
|  | 290 | /** @brief Helper function to get the SBE instance PDBG processor target | 
|  | 291 | * | 
|  | 292 | * @param[in] instance - the SBE instance id | 
|  | 293 | * | 
|  | 294 | * @return a pointer to the PDBG target | 
|  | 295 | */ | 
|  | 296 | struct pdbg_target* getPdbgTarget(unsigned int instance); | 
|  | 297 |  | 
|  | 298 | /** @brief Whether pdbg_targets_init has been called */ | 
|  | 299 | bool pdbgInitialized = false; | 
|  | 300 |  | 
| Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 301 | std::unique_ptr<pldm::Interface> pldmHandle = nullptr; | 
|  | 302 | #endif | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 303 |  | 
| Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 304 | #ifdef POWER10 | 
|  | 305 | /** | 
|  | 306 | * @brief Timer used when discovering OCCs in /dev. | 
|  | 307 | */ | 
|  | 308 | std::unique_ptr< | 
|  | 309 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>> | 
|  | 310 | discoverTimer; | 
|  | 311 |  | 
|  | 312 | /** | 
|  | 313 | * @brief Used when discovering /dev/occ objects to know if | 
|  | 314 | *        any were added since the last check. | 
|  | 315 | */ | 
|  | 316 | std::vector<int> prevOCCSearch; | 
| Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 317 |  | 
|  | 318 | /** | 
|  | 319 | * @brief Timer used when waiting for OCCs to go active. | 
|  | 320 | */ | 
|  | 321 | std::unique_ptr< | 
|  | 322 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>> | 
|  | 323 | waitForAllOccsTimer; | 
|  | 324 |  | 
|  | 325 | /** @brief Called when code times out waiting for all OCCs to be running or | 
|  | 326 | *         after the app is restarted (Status does not callback into | 
|  | 327 | * Manager). | 
|  | 328 | */ | 
|  | 329 | void occsNotAllRunning(); | 
| Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 330 |  | 
|  | 331 | /** @brief Check if all of the OCC Active sensors are available and if not | 
|  | 332 | * restart the discoverTimer | 
|  | 333 | */ | 
|  | 334 | void checkAllActiveSensors(); | 
| Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 335 | #endif | 
|  | 336 |  | 
| Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 337 | /** | 
|  | 338 | * @brief Called when poll timer expires and forces a POLL command to the | 
|  | 339 | * OCC. The poll timer will then be restarted. | 
|  | 340 | * */ | 
|  | 341 | void pollerTimerExpired(); | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 342 |  | 
| Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 343 | /** | 
|  | 344 | * @brief Finds the OCC devices in /dev | 
|  | 345 | * | 
|  | 346 | * @return The IDs of the OCCs - 0, 1, etc. | 
|  | 347 | */ | 
|  | 348 | std::vector<int> findOCCsInDev(); | 
|  | 349 |  | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 350 | #ifdef READ_OCC_SENSORS | 
|  | 351 | /** | 
|  | 352 | * @brief Gets the occ sensor values. | 
| Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 353 | * @param[in] occ - pointer to OCCs Status object | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 354 | * */ | 
| Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 355 | void getSensorValues(std::unique_ptr<Status>& occ); | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 356 |  | 
|  | 357 | /** | 
|  | 358 | * @brief Trigger OCC driver to read the temperature sensors. | 
|  | 359 | * @param[in] path - path of the OCC sensors. | 
|  | 360 | * @param[in] id - Id of the OCC. | 
|  | 361 | * */ | 
|  | 362 | void readTempSensors(const fs::path& path, uint32_t id); | 
|  | 363 |  | 
|  | 364 | /** | 
|  | 365 | * @brief Trigger OCC driver to read the power sensors. | 
|  | 366 | * @param[in] path - path of the OCC sensors. | 
|  | 367 | * @param[in] id - Id of the OCC. | 
|  | 368 | * */ | 
|  | 369 | void readPowerSensors(const fs::path& path, uint32_t id); | 
|  | 370 |  | 
|  | 371 | /** | 
|  | 372 | * @brief Set all sensor values of this OCC to NaN. | 
|  | 373 | * @param[in] id - Id of the OCC. | 
|  | 374 | * */ | 
|  | 375 | void setSensorValueToNaN(uint32_t id); | 
|  | 376 |  | 
|  | 377 | /** @brief Store the existing OCC sensors on D-BUS */ | 
|  | 378 | std::map<std::string, uint32_t> existingSensors; | 
|  | 379 |  | 
|  | 380 | /** @brief Get FunctionID from the `powerX_label` file. | 
|  | 381 | *  @param[in] value - the value of the `powerX_label` file. | 
|  | 382 | *  @returns FunctionID of the power sensors. | 
|  | 383 | */ | 
|  | 384 | std::optional<std::string> | 
|  | 385 | getPowerLabelFunctionID(const std::string& value); | 
|  | 386 |  | 
|  | 387 | /** @brief The power sensor names map */ | 
|  | 388 | const std::map<std::string, std::string> powerSensorName = { | 
|  | 389 | {"system", "total_power"}, {"1", "p0_mem_power"}, | 
|  | 390 | {"2", "p1_mem_power"},     {"3", "p2_mem_power"}, | 
|  | 391 | {"4", "p3_mem_power"},     {"5", "p0_power"}, | 
|  | 392 | {"6", "p1_power"},         {"7", "p2_power"}, | 
|  | 393 | {"8", "p3_power"},         {"9", "p0_cache_power"}, | 
|  | 394 | {"10", "p1_cache_power"},  {"11", "p2_cache_power"}, | 
|  | 395 | {"12", "p3_cache_power"},  {"13", "io_a_power"}, | 
|  | 396 | {"14", "io_b_power"},      {"15", "io_c_power"}, | 
|  | 397 | {"16", "fans_a_power"},    {"17", "fans_b_power"}, | 
|  | 398 | {"18", "storage_a_power"}, {"19", "storage_b_power"}, | 
|  | 399 | {"23", "mem_cache_power"}, {"25", "p0_mem_0_power"}, | 
| Sheldon Bailey | 11fd131 | 2022-04-19 10:16:58 -0500 | [diff] [blame] | 400 | {"26", "p0_mem_1_power"},  {"27", "p0_mem_2_power"}, | 
|  | 401 | {"35", "pcie_dcm0_power"}, {"36", "pcie_dcm1_power"}, | 
|  | 402 | {"37", "pcie_dcm2_power"}, {"38", "pcie_dcm3_power"}, | 
|  | 403 | {"39", "io_dcm0_power"},   {"40", "io_dcm1_power"}, | 
|  | 404 | {"41", "io_dcm2_power"},   {"42", "io_dcm3_power"}, | 
|  | 405 | {"43", "avdd_total_power"}}; | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 406 |  | 
| Sheldon Bailey | 11fd131 | 2022-04-19 10:16:58 -0500 | [diff] [blame] | 407 | /** @brief The dimm temperature sensor names map  */ | 
| Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 408 | const std::map<uint32_t, std::string> dimmTempSensorName = { | 
|  | 409 | {internalMemCtlr, "_intmb_temp"}, | 
|  | 410 | {dimm, "_dram_temp"}, | 
|  | 411 | {memCtrlAndDimm, "_dram_extmb_temp"}, | 
|  | 412 | {PMIC, "_pmic_temp"}, | 
|  | 413 | {memCtlrExSensor, "_extmb_temp"}}; | 
|  | 414 | #endif | 
| Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 415 |  | 
|  | 416 | /** @brief Read the altitude from DBus */ | 
|  | 417 | void readAltitude(); | 
|  | 418 |  | 
|  | 419 | /** @brief Callback function when ambient temperature changes | 
|  | 420 | * | 
|  | 421 | *  @param[in]  msg - Data associated with subscribed signal | 
|  | 422 | */ | 
|  | 423 | void ambientCallback(sdbusplus::message::message& msg); | 
| Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 424 |  | 
|  | 425 | /** @brief Confirm that a single OCC master was found and start presence | 
|  | 426 | * monitoring | 
|  | 427 | */ | 
|  | 428 | void validateOccMaster(); | 
| Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 429 | }; | 
|  | 430 |  | 
|  | 431 | } // namespace occ | 
|  | 432 | } // namespace open_power |