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