Shawn McCarney | d3a8aab | 2020-03-10 10:30:02 -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 "action.hpp" |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <optional> |
| 22 | #include <utility> |
| 23 | #include <vector> |
| 24 | |
| 25 | namespace phosphor::power::regulators |
| 26 | { |
| 27 | |
| 28 | /** |
| 29 | * @class Configuration |
| 30 | * |
| 31 | * Configuration changes that should be applied to a device or regulator rail. |
| 32 | * These changes usually override hardware default settings. |
| 33 | * |
| 34 | * The most common configuration change is setting the output voltage for a |
| 35 | * regulator rail. Other examples include modifying pgood thresholds and |
| 36 | * overcurrent settings. |
| 37 | * |
| 38 | * The configuration changes are applied during the boot before regulators are |
| 39 | * enabled. |
| 40 | * |
| 41 | * The configuration changes are applied by executing one or more actions. |
| 42 | * |
| 43 | * An output voltage value can be specified if necessary. The value will be |
| 44 | * stored in the ActionEnvironment when the actions are executed. Actions that |
| 45 | * require a volts value, such as PMBusWriteVoutCommandAction, can obtain it |
| 46 | * from the ActionEnvironment. |
| 47 | */ |
| 48 | class Configuration |
| 49 | { |
| 50 | public: |
| 51 | // Specify which compiler-generated methods we want |
| 52 | Configuration() = delete; |
| 53 | Configuration(const Configuration&) = delete; |
| 54 | Configuration(Configuration&&) = delete; |
| 55 | Configuration& operator=(const Configuration&) = delete; |
| 56 | Configuration& operator=(Configuration&&) = delete; |
| 57 | ~Configuration() = default; |
| 58 | |
| 59 | /** |
| 60 | * Constructor. |
| 61 | * |
| 62 | * @param volts optional output voltage value |
| 63 | * @param actions actions that configure the device/rail |
| 64 | */ |
| 65 | explicit Configuration(std::optional<double> volts, |
| 66 | std::vector<std::unique_ptr<Action>> actions) : |
| 67 | volts{volts}, |
| 68 | actions{std::move(actions)} |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Executes the actions to configure the device/rail. |
| 74 | */ |
| 75 | void execute() |
| 76 | { |
| 77 | // TODO: Create ActionEnvironment, set volts value if specified, execute |
| 78 | // actions, catch and handle any exceptions |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the actions that configure the device/rail. |
| 83 | * |
| 84 | * @return actions |
| 85 | */ |
| 86 | const std::vector<std::unique_ptr<Action>>& getActions() const |
| 87 | { |
| 88 | return actions; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns the optional output voltage value. |
| 93 | * |
| 94 | * @return optional volts value |
| 95 | */ |
| 96 | std::optional<double> getVolts() const |
| 97 | { |
| 98 | return volts; |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | /** |
| 103 | * Optional output voltage value. |
| 104 | */ |
| 105 | const std::optional<double> volts{}; |
| 106 | |
| 107 | /** |
| 108 | * Actions that configure the device/rail. |
| 109 | */ |
| 110 | std::vector<std::unique_ptr<Action>> actions{}; |
| 111 | }; |
| 112 | |
| 113 | } // namespace phosphor::power::regulators |