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