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