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 | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 20 | #include "types.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 | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 24 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 25 | #include <any> |
| 26 | #include <functional> |
| 27 | #include <map> |
| 28 | #include <tuple> |
| 29 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 30 | namespace phosphor::fan::control::json |
| 31 | { |
| 32 | |
| 33 | using json = nlohmann::json; |
| 34 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 35 | /* Interface property handler function */ |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 36 | using propHandler = std::function<ZoneHandler(const json&, bool)>; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 37 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 38 | /** |
| 39 | * @class Zone - Represents a configured fan control zone |
| 40 | * |
| 41 | * A zone object contains the configured attributes for a zone that groups |
| 42 | * a number of fans together to be under the same speed control. These |
| 43 | * configuration attributes include, but are not limited to, the full speed |
| 44 | * of the fans within the zone, a default floor speed, the delay between speed |
| 45 | * increases, a decrease interval, and any profiles(OPTIONAL) the zone should |
| 46 | * be included in. |
| 47 | * |
| 48 | * (When no profile for a zone is given, the zone defaults to always exist) |
| 49 | * |
| 50 | */ |
| 51 | class Zone : public ConfigBase |
| 52 | { |
| 53 | public: |
| 54 | /* JSON file name for zones */ |
| 55 | static constexpr auto confFileName = "zones.json"; |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 56 | static constexpr auto thermModeIntf = |
| 57 | "xyz.openbmc_project.Control.ThermalMode"; |
| 58 | static constexpr auto supportedProp = "Supported"; |
| 59 | static constexpr auto currentProp = "Current"; |
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 | acd737c | 2021-03-04 11:04:01 -0600 | [diff] [blame] | 72 | * @param[in] bus - sdbusplus bus object |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 73 | * @param[in] jsonObj - JSON object |
| 74 | */ |
Matthew Barth | acd737c | 2021-03-04 11:04:01 -0600 | [diff] [blame] | 75 | Zone(sdbusplus::bus::bus& bus, const json& jsonObj); |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * @brief Get the full speed |
| 79 | * |
| 80 | * Full speed is the speed set to the fans within this zone unless there |
| 81 | * are events configured that alter the fan speeds. |
| 82 | * |
| 83 | * @return Full speed of this zone |
| 84 | */ |
| 85 | inline const auto& getFullSpeed() const |
| 86 | { |
| 87 | return _fullSpeed; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @brief Get the default floor speed |
| 92 | * |
| 93 | * The default floor speed is the lowest speed the fans within this zone |
| 94 | * are allowed to decrease to. The zone's floor speed defaults to this |
| 95 | * unless changed by some configured event. |
| 96 | * |
| 97 | * @return Default floor speed |
| 98 | */ |
| 99 | inline const auto& getDefaultFloor() const |
| 100 | { |
| 101 | return _defaultFloor; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @brief Get the speed increase delay(OPTIONAL) |
| 106 | * |
| 107 | * The speed increase delay is the amount of time(in seconds) increases |
| 108 | * to a target speed are delayed before being made. The default is 0, which |
| 109 | * results in immediate speed increase requests when any events result in |
| 110 | * a change to the target speed. |
| 111 | * |
| 112 | * It is recommend a value other than 0 is configured, but that inherently |
| 113 | * depends on the fan controller and configured speed increases. |
| 114 | * |
| 115 | * @return Speed increase delay(in seconds) |
| 116 | */ |
| 117 | inline const auto& getIncDelay() const |
| 118 | { |
| 119 | return _incDelay; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @brief Get the speed decrease interval |
| 124 | * |
| 125 | * Speed decreases happen on a set interval when no requests for an increase |
| 126 | * in fan speeds exists. This is the interval(in seconds) at which the fans |
| 127 | * within the zone are decreased if events exist that result in a target |
| 128 | * speed decrease. |
| 129 | * |
| 130 | * @return Speed decrease interval(in seconds) |
| 131 | */ |
| 132 | inline const auto& getDecInterval() const |
| 133 | { |
| 134 | return _decInterval; |
| 135 | } |
| 136 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 137 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 138 | * @brief Get the configuration of zone interface handlers |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 139 | * |
| 140 | * Interfaces hosted by a zone can optionally be configured to set their |
| 141 | * property values and/or persistency. These interfaces must be supported |
| 142 | * by the zone object they are configured for. |
| 143 | * |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 144 | * @return List of zone interface handler functions that set an interface's |
| 145 | * property values and persistency states |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 146 | */ |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 147 | inline const auto& getZoneHandlers() const |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 148 | { |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 149 | return _zoneHandlers; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame^] | 152 | /** |
| 153 | * @brief Add a fan object to the zone |
| 154 | * |
| 155 | * @param[in] fan - Unique pointer to a fan object that will be moved into |
| 156 | * the zone |
| 157 | * |
| 158 | * Adds a fan object to the list of fans that make up the zone by moving the |
| 159 | * fan object into the list. |
| 160 | */ |
| 161 | void addFan(std::unique_ptr<Fan> fan); |
| 162 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 163 | private: |
| 164 | /* The zone's full speed value for fans */ |
| 165 | uint64_t _fullSpeed; |
| 166 | |
| 167 | /* The zone's default floor speed value for fans */ |
| 168 | uint64_t _defaultFloor; |
| 169 | |
| 170 | /* Zone's speed increase delay(in seconds) (OPTIONAL) */ |
| 171 | uint64_t _incDelay; |
| 172 | |
| 173 | /* Zone's speed decrease interval(in seconds) */ |
| 174 | uint64_t _decInterval; |
| 175 | |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 176 | /** |
| 177 | * Zone interface handler functions for its |
| 178 | * configured interfaces (OPTIONAL) |
| 179 | */ |
| 180 | std::vector<ZoneHandler> _zoneHandlers; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 181 | |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 182 | /* Interface to property mapping of their associated handler function */ |
| 183 | static const std::map<std::string, std::map<std::string, propHandler>> |
| 184 | _intfPropHandlers; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 185 | |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame^] | 186 | /* List of fans included in this zone */ |
| 187 | std::vector<std::unique_ptr<Fan>> _fans; |
| 188 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 189 | /** |
| 190 | * @brief Parse and set the zone's full speed value |
| 191 | * |
| 192 | * @param[in] jsonObj - JSON object for the zone |
| 193 | * |
| 194 | * Sets the full speed value for the zone from the JSON configuration object |
| 195 | */ |
| 196 | void setFullSpeed(const json& jsonObj); |
| 197 | |
| 198 | /** |
| 199 | * @brief Parse and set the zone's default floor speed value |
| 200 | * |
| 201 | * @param[in] jsonObj - JSON object for the zone |
| 202 | * |
| 203 | * Sets the default floor speed value for the zone from the JSON |
| 204 | * configuration object |
| 205 | */ |
| 206 | void setDefaultFloor(const json& jsonObj); |
| 207 | |
| 208 | /** |
| 209 | * @brief Parse and set the zone's decrease interval(in seconds) |
| 210 | * |
| 211 | * @param[in] jsonObj - JSON object for the zone |
| 212 | * |
| 213 | * Sets the speed decrease interval(in seconds) for the zone from the JSON |
| 214 | * configuration object |
| 215 | */ |
| 216 | void setDecInterval(const json& jsonObj); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 217 | |
| 218 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 219 | * @brief Parse and set the interfaces served by the zone(OPTIONAL) |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 220 | * |
| 221 | * @param[in] jsonObj - JSON object for the zone |
| 222 | * |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 223 | * Constructs any zone interface handler functions for interfaces that the |
| 224 | * zone serves which contains the interface's property's value and |
| 225 | * persistency state (OPTIONAL). A property's "persist" state is defaulted |
| 226 | * to not be persisted when not given. |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 227 | */ |
| 228 | void setInterfaces(const json& jsonObj); |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 229 | }; |
| 230 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 231 | /** |
| 232 | * Properties of interfaces supported by the zone configuration |
| 233 | */ |
| 234 | namespace zone::property |
| 235 | { |
| 236 | |
| 237 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 238 | * @brief "Supported" property on the "xyz.openbmc_project.Control.ThermalMode" |
| 239 | * interface |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 240 | * |
| 241 | * @param[in] jsonObj - JSON object for the "Supported" property |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 242 | * @param[in] persist - Whether to persist the value or not |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 243 | * |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 244 | * @return Zone interface handler function for the property |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 245 | */ |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 246 | ZoneHandler supported(const json& jsonObj, bool persist); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 247 | |
| 248 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 249 | * @brief "Current" property on the "xyz.openbmc_project.Control.ThermalMode" |
| 250 | * interface |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 251 | * |
| 252 | * @param[in] jsonObj - JSON object for the "Current" property |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 253 | * @param[in] persist - Whether to persist the value or not |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 254 | * |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 255 | * @return Zone interface handler function for the property |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 256 | */ |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 257 | ZoneHandler current(const json& jsonObj, bool persist); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 258 | |
| 259 | } // namespace zone::property |
| 260 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 261 | } // namespace phosphor::fan::control::json |