Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include "config_base.hpp" |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame] | 19 | #include "fan.hpp" |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 20 | #include "xyz/openbmc_project/Control/ThermalMode/server.hpp" |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 21 | |
| 22 | #include <nlohmann/json.hpp> |
Matthew Barth | acd737c | 2021-03-04 11:04:01 -0600 | [diff] [blame] | 23 | #include <sdbusplus/bus.hpp> |
Matthew Barth | 603ef16 | 2021-03-24 15:34:53 -0500 | [diff] [blame] | 24 | #include <sdeventplus/event.hpp> |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 25 | #include <sdeventplus/utility/timer.hpp> |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 26 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 27 | #include <any> |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 28 | #include <chrono> |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 29 | #include <functional> |
| 30 | #include <map> |
| 31 | #include <tuple> |
| 32 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 33 | namespace phosphor::fan::control::json |
| 34 | { |
| 35 | |
Matthew Barth | 603ef16 | 2021-03-24 15:34:53 -0500 | [diff] [blame] | 36 | class Manager; |
| 37 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 38 | using json = nlohmann::json; |
| 39 | |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 40 | /* Extend the Control::ThermalMode interface */ |
| 41 | using ThermalObject = sdbusplus::server::object::object< |
| 42 | sdbusplus::xyz::openbmc_project::Control::server::ThermalMode>; |
| 43 | |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 44 | /* Dbus event timer */ |
| 45 | using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>; |
| 46 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 47 | /** |
| 48 | * @class Zone - Represents a configured fan control zone |
| 49 | * |
| 50 | * A zone object contains the configured attributes for a zone that groups |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 51 | * a number of fans together to be under the same target control. These |
| 52 | * configuration attributes include, but are not limited to, the default ceiling |
| 53 | * of the fans within the zone, a default floor, the delay between increases, a |
| 54 | * decrease interval, and any profiles(OPTIONAL) the zone should be included in. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 55 | * |
| 56 | * (When no profile for a zone is given, the zone defaults to always exist) |
| 57 | * |
| 58 | */ |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 59 | class Zone : public ConfigBase, public ThermalObject |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 60 | { |
| 61 | public: |
| 62 | /* JSON file name for zones */ |
| 63 | static constexpr auto confFileName = "zones.json"; |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 64 | static constexpr auto thermModeIntf = |
| 65 | "xyz.openbmc_project.Control.ThermalMode"; |
| 66 | static constexpr auto supportedProp = "Supported"; |
| 67 | static constexpr auto currentProp = "Current"; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 68 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 69 | Zone() = delete; |
| 70 | Zone(const Zone&) = delete; |
| 71 | Zone(Zone&&) = delete; |
| 72 | Zone& operator=(const Zone&) = delete; |
| 73 | Zone& operator=(Zone&&) = delete; |
| 74 | ~Zone() = default; |
| 75 | |
| 76 | /** |
| 77 | * Constructor |
| 78 | * Parses and populates a zone from JSON object data |
| 79 | * |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 80 | * @param[in] jsonObj - JSON object |
Matthew Barth | 603ef16 | 2021-03-24 15:34:53 -0500 | [diff] [blame] | 81 | * @param[in] event - sdeventplus event loop |
| 82 | * @param[in] mgr - Manager of this zone |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 83 | */ |
Matthew Barth | 9403a21 | 2021-05-17 09:31:50 -0500 | [diff] [blame] | 84 | Zone(const json& jsonObj, const sdeventplus::Event& event, Manager* mgr); |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 85 | |
| 86 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 87 | * @brief Get the default ceiling |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 88 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 89 | * Default ceiling is the highest target the fans within this zone is |
| 90 | * allowed to increase to. The zone's ceiling defaults to this unless |
| 91 | * changed by some configured event. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 92 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 93 | * @return Default ceiling of this zone |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 94 | */ |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 95 | inline const auto& getDefaultCeiling() const |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 96 | { |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 97 | return _defaultCeiling; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 101 | * @brief Get the default floor |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 102 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 103 | * The default floor is the lowest target the fans within this zone |
| 104 | * are allowed to decrease to. The zone's floor defaults to this |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 105 | * unless changed by some configured event. |
| 106 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 107 | * @return Default floor |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 108 | */ |
| 109 | inline const auto& getDefaultFloor() const |
| 110 | { |
| 111 | return _defaultFloor; |
| 112 | } |
| 113 | |
| 114 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 115 | * @brief Get the increase delay(OPTIONAL) |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 116 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 117 | * The increase delay is the amount of time(in seconds) increases |
| 118 | * to a target are delayed before being made. The default is 0, which |
| 119 | * results in immediate increase requests when any events result in |
| 120 | * a change to the target. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 121 | * |
| 122 | * It is recommend a value other than 0 is configured, but that inherently |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 123 | * depends on the fan controller and configured increases. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 124 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 125 | * @return Increase delay(in seconds) |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 126 | */ |
| 127 | inline const auto& getIncDelay() const |
| 128 | { |
| 129 | return _incDelay; |
| 130 | } |
| 131 | |
| 132 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 133 | * @brief Get the decrease interval |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 134 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 135 | * Decreases happen on a set interval when no requests for an increase |
| 136 | * in fan targets exists. This is the interval(in seconds) at which the fans |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 137 | * within the zone are decreased if events exist that result in a target |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 138 | * decrease. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 139 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 140 | * @return Decrease interval(in seconds) |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 141 | */ |
| 142 | inline const auto& getDecInterval() const |
| 143 | { |
| 144 | return _decInterval; |
| 145 | } |
| 146 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 147 | /** |
Matthew Barth | 6f78730 | 2021-03-25 15:01:01 -0500 | [diff] [blame] | 148 | * @brief Get the current target of the zone |
| 149 | * |
| 150 | * @return - The current target of the zone |
| 151 | */ |
| 152 | inline const auto& getTarget() const |
| 153 | { |
| 154 | return _target; |
| 155 | } |
| 156 | |
| 157 | /** |
Matthew Barth | dc776c8 | 2021-02-25 16:06:16 -0600 | [diff] [blame] | 158 | * @brief Get the target increase delta |
| 159 | * |
| 160 | * @return - The current target increase delta |
| 161 | */ |
| 162 | inline auto& getIncDelta() const |
| 163 | { |
| 164 | return _incDelta; |
| 165 | }; |
| 166 | |
| 167 | /** |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 168 | * @brief Get the target decrease delta |
| 169 | * |
| 170 | * @return - The current target decrease delta |
| 171 | */ |
| 172 | inline auto& getDecDelta() const |
| 173 | { |
| 174 | return _decDelta; |
| 175 | }; |
| 176 | |
| 177 | /** |
Matthew Barth | 603ef16 | 2021-03-24 15:34:53 -0500 | [diff] [blame] | 178 | * @brief Get the manager of the zone |
| 179 | * |
| 180 | * @return - The manager of the zone |
| 181 | */ |
| 182 | inline auto* getManager() const |
| 183 | { |
| 184 | return _manager; |
| 185 | } |
| 186 | |
| 187 | /** |
Matthew Barth | 14303a4 | 2021-05-21 13:04:08 -0500 | [diff] [blame] | 188 | * @brief Enable the zone |
| 189 | * |
| 190 | * Performs the necessary tasks to enable the zone such as restoring any |
| 191 | * dbus property states(if persisted), starting the decrement timer, etc... |
| 192 | */ |
| 193 | void enable(); |
| 194 | |
| 195 | /** |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame] | 196 | * @brief Add a fan object to the zone |
| 197 | * |
| 198 | * @param[in] fan - Unique pointer to a fan object that will be moved into |
| 199 | * the zone |
| 200 | * |
| 201 | * Adds a fan object to the list of fans that make up the zone by moving the |
| 202 | * fan object into the list. |
| 203 | */ |
| 204 | void addFan(std::unique_ptr<Fan> fan); |
| 205 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 206 | /** |
Matthew Barth | 8ba715e | 2021-03-05 09:00:05 -0600 | [diff] [blame] | 207 | * Sets all fans in the zone to the target given when the zone is active |
| 208 | * |
| 209 | * @param[in] target - Target for fans |
| 210 | */ |
| 211 | void setTarget(uint64_t target); |
| 212 | |
| 213 | /** |
| 214 | * @brief Sets the automatic fan control allowed active state |
| 215 | * |
| 216 | * @param[in] ident - An identifier that affects the active state |
| 217 | * @param[in] isActiveAllow - Active state according to group |
| 218 | */ |
| 219 | void setActiveAllow(const std::string& ident, bool isActiveAllow); |
| 220 | |
| 221 | /** |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 222 | * @brief Set the floor to the given target and increase target to the floor |
| 223 | * when the target is below the floor value when floor changes are allowed. |
| 224 | * |
| 225 | * @param[in] target - Target to set the floor to |
| 226 | */ |
| 227 | void setFloor(uint64_t target); |
| 228 | |
| 229 | /** |
| 230 | * @brief Sets the floor change allowed state |
| 231 | * |
| 232 | * @param[in] ident - An identifier that affects floor changes |
| 233 | * @param[in] isAllow - Allow state according to the identifier |
| 234 | */ |
| 235 | inline void setFloorChangeAllow(const std::string& ident, bool isAllow) |
| 236 | { |
| 237 | _floorChange[ident] = isAllow; |
| 238 | } |
| 239 | |
| 240 | /** |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 241 | * @brief Sets the decrease allowed state of a group |
| 242 | * |
| 243 | * @param[in] ident - An identifier that affects speed decreases |
| 244 | * @param[in] isAllow - Allow state according to the identifier |
| 245 | */ |
| 246 | inline void setDecreaseAllow(const std::string& ident, bool isAllow) |
| 247 | { |
| 248 | _decAllowed[ident] = isAllow; |
| 249 | } |
| 250 | |
| 251 | /** |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 252 | * @brief Calculate the requested target from the given delta and increases |
| 253 | * the fans, not going above the ceiling. |
| 254 | * |
| 255 | * @param[in] targetDelta - The delta to increase the target by |
| 256 | */ |
| 257 | void requestIncrease(uint64_t targetDelta); |
| 258 | |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 259 | /** |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 260 | * @brief Callback function for the increase timer that delays |
| 261 | * processing of requested target increases while fans are increasing |
| 262 | */ |
| 263 | void incTimerExpired(); |
| 264 | |
| 265 | /** |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 266 | * @brief Calculate the lowest requested decrease target from the given |
| 267 | * delta within a decrease interval. |
| 268 | * |
| 269 | * @param[in] targetDelta - The delta to decrease the target by |
| 270 | */ |
| 271 | void requestDecrease(uint64_t targetDelta); |
| 272 | |
| 273 | /** |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 274 | * @brief Callback function for the decrease timer that processes any |
| 275 | * requested target decreases if allowed |
| 276 | */ |
| 277 | void decTimerExpired(); |
| 278 | |
| 279 | /** |
Matthew Barth | 07fecfc | 2021-01-29 09:04:43 -0600 | [diff] [blame] | 280 | * @brief Set the requested target base to be used as the target to base a |
| 281 | * new requested target from |
| 282 | * |
| 283 | * @param[in] targetBase - Base target value to use |
| 284 | */ |
| 285 | inline void setRequestTargetBase(uint64_t targetBase) |
| 286 | { |
| 287 | _requestTargetBase = targetBase; |
| 288 | }; |
| 289 | |
| 290 | /** |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 291 | * @brief Set a property to be persisted |
| 292 | * |
| 293 | * @param[in] intf - Interface containing property |
| 294 | * @param[in] prop - Property to be persisted |
| 295 | */ |
| 296 | void setPersisted(const std::string& intf, const std::string& prop); |
| 297 | |
| 298 | /** |
Matthew Barth | 279183f | 2021-05-25 10:19:43 -0500 | [diff] [blame^] | 299 | * @brief Is the property persisted |
| 300 | * |
| 301 | * @param[in] intf - Interface containing property |
| 302 | * @param[in] prop - Property to check if persisted |
| 303 | * |
| 304 | * @return - True if property is to be persisted, false otherwise |
| 305 | */ |
| 306 | bool isPersisted(const std::string& intf, const std::string& prop) const; |
| 307 | |
| 308 | /** |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 309 | * @brief Overridden thermal object's set 'Current' property function |
| 310 | * |
| 311 | * @param[in] value - Value to set 'Current' to |
| 312 | * |
| 313 | * @return - The updated value of the 'Current' property |
| 314 | */ |
| 315 | std::string current(std::string value) override; |
| 316 | |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 317 | /** |
| 318 | * @brief A handler function to set/update a property on a zone |
| 319 | * @details Sets or updates a zone's dbus property to the given value using |
| 320 | * the provided base dbus object's set property function |
| 321 | * |
| 322 | * @param[in] intf - Interface on zone object |
| 323 | * @param[in] prop - Property on interface |
| 324 | * @param[in] func - Zone object's set property function pointer |
| 325 | * @param[in] value - Value to set property to |
| 326 | * @param[in] persist - Persist property value or not |
| 327 | * |
| 328 | * @return Lambda function |
| 329 | * A lambda function to set/update the zone's dbus property |
| 330 | */ |
| 331 | template <typename T> |
| 332 | static auto setProperty(const char* intf, const char* prop, |
| 333 | T (Zone::*func)(T), T&& value, bool persist) |
| 334 | { |
| 335 | return [=, value = std::forward<T>(value)](Zone* zone) { |
| 336 | (zone->*func)(value); |
| 337 | if (persist) |
| 338 | { |
| 339 | zone->setPersisted(intf, prop); |
| 340 | } |
| 341 | }; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * @brief A handler function to set/update a zone's dbus property's persist |
| 346 | * state |
| 347 | * @details Sets or updates a zone's dbus property's persist state where the |
| 348 | * value of the property is to be left unchanged |
| 349 | * |
| 350 | * @param[in] intf - Interface on zone object |
| 351 | * @param[in] prop - Property on interface |
| 352 | * @param[in] persist - Persist property value or not |
| 353 | * |
| 354 | * @return Lambda function |
| 355 | * A lambda function to set/update the zone's dbus property's persist |
| 356 | * state |
| 357 | */ |
| 358 | static auto setPropertyPersist(const char* intf, const char* prop, |
| 359 | bool persist) |
| 360 | { |
| 361 | return [=](Zone* zone) { |
| 362 | if (persist) |
| 363 | { |
| 364 | zone->setPersisted(intf, prop); |
| 365 | } |
| 366 | }; |
| 367 | } |
| 368 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 369 | private: |
Matthew Barth | 603ef16 | 2021-03-24 15:34:53 -0500 | [diff] [blame] | 370 | /* The zone's manager */ |
| 371 | Manager* _manager; |
| 372 | |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 373 | /* The zone's default ceiling value for fans */ |
| 374 | uint64_t _defaultCeiling; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 375 | |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 376 | /* The zone's default floor value for fans */ |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 377 | uint64_t _defaultFloor; |
| 378 | |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 379 | /* Zone's increase delay(in seconds) (OPTIONAL) */ |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 380 | std::chrono::seconds _incDelay; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 381 | |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 382 | /* Zone's decrease interval(in seconds) */ |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 383 | std::chrono::seconds _decInterval; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 384 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 385 | /* The floor target to not go below */ |
| 386 | uint64_t _floor; |
| 387 | |
| 388 | /* Target for this zone */ |
| 389 | uint64_t _target; |
| 390 | |
Matthew Barth | 2b3253e | 2021-03-09 14:51:16 -0600 | [diff] [blame] | 391 | /* Zone increase delta */ |
| 392 | uint64_t _incDelta; |
| 393 | |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 394 | /* Zone decrease delta */ |
| 395 | uint64_t _decDelta; |
| 396 | |
Matthew Barth | 2b3253e | 2021-03-09 14:51:16 -0600 | [diff] [blame] | 397 | /* The ceiling target to not go above */ |
| 398 | uint64_t _ceiling; |
| 399 | |
| 400 | /* Requested target base */ |
| 401 | uint64_t _requestTargetBase; |
| 402 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 403 | /* Map of whether floor changes are allowed by a string identifier */ |
| 404 | std::map<std::string, bool> _floorChange; |
| 405 | |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 406 | /* Map of controlling decreases allowed by a string identifer */ |
| 407 | std::map<std::string, bool> _decAllowed; |
| 408 | |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 409 | /* Map of interfaces to persisted properties the zone hosts*/ |
| 410 | std::map<std::string, std::vector<std::string>> _propsPersisted; |
| 411 | |
Matthew Barth | 8ba715e | 2021-03-05 09:00:05 -0600 | [diff] [blame] | 412 | /* Automatic fan control active state */ |
| 413 | bool _isActive; |
| 414 | |
Matthew Barth | 007de09 | 2021-03-25 13:56:04 -0500 | [diff] [blame] | 415 | /* The target increase timer object */ |
| 416 | Timer _incTimer; |
| 417 | |
| 418 | /* The target decrease timer object */ |
| 419 | Timer _decTimer; |
| 420 | |
Matthew Barth | 8ba715e | 2021-03-05 09:00:05 -0600 | [diff] [blame] | 421 | /* Map of active fan control allowed by a string identifier */ |
| 422 | std::map<std::string, bool> _active; |
| 423 | |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 424 | /* Interface to property mapping of their associated set property handler |
| 425 | * function */ |
| 426 | static const std::map< |
| 427 | std::string, |
| 428 | std::map<std::string, |
| 429 | std::function<std::function<void(Zone*)>(const json&, bool)>>> |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 430 | _intfPropHandlers; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 431 | |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame] | 432 | /* List of fans included in this zone */ |
| 433 | std::vector<std::unique_ptr<Fan>> _fans; |
| 434 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 435 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 436 | * @brief Parse and set the zone's default ceiling value |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 437 | * |
| 438 | * @param[in] jsonObj - JSON object for the zone |
| 439 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 440 | * Sets the default ceiling value for the zone from the JSON configuration |
| 441 | * object |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 442 | */ |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 443 | void setDefaultCeiling(const json& jsonObj); |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 444 | |
| 445 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 446 | * @brief Parse and set the zone's default floor value |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 447 | * |
| 448 | * @param[in] jsonObj - JSON object for the zone |
| 449 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 450 | * Sets the default floor value for the zone from the JSON configuration |
| 451 | * object |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 452 | */ |
| 453 | void setDefaultFloor(const json& jsonObj); |
| 454 | |
| 455 | /** |
| 456 | * @brief Parse and set the zone's decrease interval(in seconds) |
| 457 | * |
| 458 | * @param[in] jsonObj - JSON object for the zone |
| 459 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 460 | * Sets the decrease interval(in seconds) for the zone from the JSON |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 461 | * configuration object |
| 462 | */ |
| 463 | void setDecInterval(const json& jsonObj); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 464 | |
| 465 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 466 | * @brief Parse and set the interfaces served by the zone(OPTIONAL) |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 467 | * |
| 468 | * @param[in] jsonObj - JSON object for the zone |
| 469 | * |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 470 | * Constructs any zone interface handler functions for interfaces that the |
| 471 | * zone serves which contains the interface's property's value and |
| 472 | * persistency state (OPTIONAL). A property's "persist" state is defaulted |
| 473 | * to not be persisted when not given. |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 474 | */ |
| 475 | void setInterfaces(const json& jsonObj); |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 476 | |
| 477 | /** |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 478 | * @brief Save the thermal control current mode property to persisted |
| 479 | * storage |
| 480 | */ |
| 481 | void saveCurrentMode(); |
Matthew Barth | 2b3253e | 2021-03-09 14:51:16 -0600 | [diff] [blame] | 482 | |
| 483 | /** |
Matthew Barth | a448374 | 2021-03-25 14:09:01 -0500 | [diff] [blame] | 484 | * @brief Restore persisted thermal control current mode property |
| 485 | * value, setting the mode to "Default" otherwise |
| 486 | */ |
| 487 | void restoreCurrentMode(); |
| 488 | |
| 489 | /** |
Matthew Barth | 2b3253e | 2021-03-09 14:51:16 -0600 | [diff] [blame] | 490 | * @brief Get the request target base if defined, otherwise the the current |
| 491 | * target is returned |
| 492 | * |
| 493 | * @return - The request target base or current target |
| 494 | */ |
| 495 | inline auto getRequestTargetBase() const |
| 496 | { |
| 497 | return (_requestTargetBase != 0) ? _requestTargetBase : _target; |
| 498 | }; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 499 | }; |
| 500 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 501 | /** |
| 502 | * Properties of interfaces supported by the zone configuration |
| 503 | */ |
| 504 | namespace zone::property |
| 505 | { |
| 506 | |
| 507 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 508 | * @brief "Supported" property on the "xyz.openbmc_project.Control.ThermalMode" |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 509 | * interface parser. Also creates the handler function for the Zone object to |
| 510 | * initialize the property according to what's parsed from the configuration. |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 511 | * |
| 512 | * @param[in] jsonObj - JSON object for the "Supported" property |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 513 | * @param[in] persist - Whether to persist the value or not |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 514 | * |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 515 | * @return Zone interface set property handler function for the "Supported" |
| 516 | * property |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 517 | */ |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 518 | std::function<void(Zone*)> supported(const json& jsonObj, bool persist); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 519 | |
| 520 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 521 | * @brief "Current" property on the "xyz.openbmc_project.Control.ThermalMode" |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 522 | * interface parser. Also creates the handler function for the Zone object to |
| 523 | * initialize the property according to what's parsed from the configuration. |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 524 | * |
| 525 | * @param[in] jsonObj - JSON object for the "Current" property |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 526 | * @param[in] persist - Whether to persist the value or not |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 527 | * |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 528 | * @return Zone interface set property handler function for the "Current" |
| 529 | * property |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 530 | */ |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 531 | std::function<void(Zone*)> current(const json& jsonObj, bool persist); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 532 | |
| 533 | } // namespace zone::property |
| 534 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 535 | } // namespace phosphor::fan::control::json |