1d3a8aab4SShawn McCarney /** 2d3a8aab4SShawn McCarney * Copyright © 2020 IBM Corporation 3d3a8aab4SShawn McCarney * 4d3a8aab4SShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License"); 5d3a8aab4SShawn McCarney * you may not use this file except in compliance with the License. 6d3a8aab4SShawn McCarney * You may obtain a copy of the License at 7d3a8aab4SShawn McCarney * 8d3a8aab4SShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0 9d3a8aab4SShawn McCarney * 10d3a8aab4SShawn McCarney * Unless required by applicable law or agreed to in writing, software 11d3a8aab4SShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS, 12d3a8aab4SShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3a8aab4SShawn McCarney * See the License for the specific language governing permissions and 14d3a8aab4SShawn McCarney * limitations under the License. 15d3a8aab4SShawn McCarney */ 16d3a8aab4SShawn McCarney #pragma once 17d3a8aab4SShawn McCarney 18d3a8aab4SShawn McCarney #include "action.hpp" 1923243f84SBob King #include "services.hpp" 20d3a8aab4SShawn McCarney 21d3a8aab4SShawn McCarney #include <memory> 22d3a8aab4SShawn McCarney #include <optional> 233976500fSShawn McCarney #include <string> 24d3a8aab4SShawn McCarney #include <utility> 25d3a8aab4SShawn McCarney #include <vector> 26d3a8aab4SShawn McCarney 27d3a8aab4SShawn McCarney namespace phosphor::power::regulators 28d3a8aab4SShawn McCarney { 29d3a8aab4SShawn McCarney 303976500fSShawn McCarney // Forward declarations to avoid circular dependencies 313976500fSShawn McCarney class Chassis; 323976500fSShawn McCarney class Device; 333976500fSShawn McCarney class Rail; 343976500fSShawn McCarney class System; 353976500fSShawn McCarney 36d3a8aab4SShawn McCarney /** 37d3a8aab4SShawn McCarney * @class Configuration 38d3a8aab4SShawn McCarney * 39d3a8aab4SShawn McCarney * Configuration changes that should be applied to a device or regulator rail. 40d3a8aab4SShawn McCarney * These changes usually override hardware default settings. 41d3a8aab4SShawn McCarney * 42d3a8aab4SShawn McCarney * The most common configuration change is setting the output voltage for a 43d3a8aab4SShawn McCarney * regulator rail. Other examples include modifying pgood thresholds and 44d3a8aab4SShawn McCarney * overcurrent settings. 45d3a8aab4SShawn McCarney * 46d3a8aab4SShawn McCarney * The configuration changes are applied during the boot before regulators are 47d3a8aab4SShawn McCarney * enabled. 48d3a8aab4SShawn McCarney * 49d3a8aab4SShawn McCarney * The configuration changes are applied by executing one or more actions. 50d3a8aab4SShawn McCarney * 51d3a8aab4SShawn McCarney * An output voltage value can be specified if necessary. The value will be 52d3a8aab4SShawn McCarney * stored in the ActionEnvironment when the actions are executed. Actions that 53d3a8aab4SShawn McCarney * require a volts value, such as PMBusWriteVoutCommandAction, can obtain it 54d3a8aab4SShawn McCarney * from the ActionEnvironment. 55d3a8aab4SShawn McCarney */ 56d3a8aab4SShawn McCarney class Configuration 57d3a8aab4SShawn McCarney { 58d3a8aab4SShawn McCarney public: 59d3a8aab4SShawn McCarney // Specify which compiler-generated methods we want 60d3a8aab4SShawn McCarney Configuration() = delete; 61d3a8aab4SShawn McCarney Configuration(const Configuration&) = delete; 62d3a8aab4SShawn McCarney Configuration(Configuration&&) = delete; 63d3a8aab4SShawn McCarney Configuration& operator=(const Configuration&) = delete; 64d3a8aab4SShawn McCarney Configuration& operator=(Configuration&&) = delete; 65d3a8aab4SShawn McCarney ~Configuration() = default; 66d3a8aab4SShawn McCarney 67d3a8aab4SShawn McCarney /** 68d3a8aab4SShawn McCarney * Constructor. 69d3a8aab4SShawn McCarney * 70d3a8aab4SShawn McCarney * @param volts optional output voltage value 71d3a8aab4SShawn McCarney * @param actions actions that configure the device/rail 72d3a8aab4SShawn McCarney */ Configuration(std::optional<double> volts,std::vector<std::unique_ptr<Action>> actions)73d3a8aab4SShawn McCarney explicit Configuration(std::optional<double> volts, 74d3a8aab4SShawn McCarney std::vector<std::unique_ptr<Action>> actions) : 75*f5402197SPatrick Williams volts{volts}, actions{std::move(actions)} 760c9a33d6SAdriana Kobylak {} 77d3a8aab4SShawn McCarney 78d3a8aab4SShawn McCarney /** 793976500fSShawn McCarney * Executes the actions to configure the specified device. 803976500fSShawn McCarney * 813976500fSShawn McCarney * This method should be called during the boot before regulators are 823976500fSShawn McCarney * enabled. 833976500fSShawn McCarney * 8423243f84SBob King * @param services system services like error logging and the journal 853976500fSShawn McCarney * @param system system that contains the chassis 863976500fSShawn McCarney * @param chassis chassis that contains the device 873976500fSShawn McCarney * @param device device to configure 88d3a8aab4SShawn McCarney */ 8923243f84SBob King void execute(Services& services, System& system, Chassis& chassis, 9023243f84SBob King Device& device); 913976500fSShawn McCarney 923976500fSShawn McCarney /** 933976500fSShawn McCarney * Executes the actions to configure the specified rail. 943976500fSShawn McCarney * 953976500fSShawn McCarney * This method should be called during the boot before regulators are 963976500fSShawn McCarney * enabled. 973976500fSShawn McCarney * 9823243f84SBob King * @param services system services like error logging and the journal 993976500fSShawn McCarney * @param system system that contains the chassis 1003976500fSShawn McCarney * @param chassis chassis that contains the device 1013976500fSShawn McCarney * @param device device that contains the rail 1023976500fSShawn McCarney * @param rail rail to configure 1033976500fSShawn McCarney */ 10423243f84SBob King void execute(Services& services, System& system, Chassis& chassis, 10523243f84SBob King Device& device, Rail& rail); 106d3a8aab4SShawn McCarney 107d3a8aab4SShawn McCarney /** 108d3a8aab4SShawn McCarney * Returns the actions that configure the device/rail. 109d3a8aab4SShawn McCarney * 110d3a8aab4SShawn McCarney * @return actions 111d3a8aab4SShawn McCarney */ getActions() const112d3a8aab4SShawn McCarney const std::vector<std::unique_ptr<Action>>& getActions() const 113d3a8aab4SShawn McCarney { 114d3a8aab4SShawn McCarney return actions; 115d3a8aab4SShawn McCarney } 116d3a8aab4SShawn McCarney 117d3a8aab4SShawn McCarney /** 118d3a8aab4SShawn McCarney * Returns the optional output voltage value. 119d3a8aab4SShawn McCarney * 120d3a8aab4SShawn McCarney * @return optional volts value 121d3a8aab4SShawn McCarney */ getVolts() const122d3a8aab4SShawn McCarney std::optional<double> getVolts() const 123d3a8aab4SShawn McCarney { 124d3a8aab4SShawn McCarney return volts; 125d3a8aab4SShawn McCarney } 126d3a8aab4SShawn McCarney 127d3a8aab4SShawn McCarney private: 128d3a8aab4SShawn McCarney /** 1293976500fSShawn McCarney * Executes the actions to configure a device or rail. 1303976500fSShawn McCarney * 13123243f84SBob King * @param services system services like error logging and the journal 1323976500fSShawn McCarney * @param system system that contains the chassis 1333976500fSShawn McCarney * @param chassis chassis that contains the device 1343976500fSShawn McCarney * @param device device to configure or that contains rail to configure 1353976500fSShawn McCarney * @param deviceOrRailID ID of the device or rail to configure 1363976500fSShawn McCarney */ 13723243f84SBob King void execute(Services& services, System& system, Chassis& chassis, 13823243f84SBob King Device& device, const std::string& deviceOrRailID); 1393976500fSShawn McCarney 1403976500fSShawn McCarney /** 141d3a8aab4SShawn McCarney * Optional output voltage value. 142d3a8aab4SShawn McCarney */ 143d3a8aab4SShawn McCarney const std::optional<double> volts{}; 144d3a8aab4SShawn McCarney 145d3a8aab4SShawn McCarney /** 146d3a8aab4SShawn McCarney * Actions that configure the device/rail. 147d3a8aab4SShawn McCarney */ 148d3a8aab4SShawn McCarney std::vector<std::unique_ptr<Action>> actions{}; 149d3a8aab4SShawn McCarney }; 150d3a8aab4SShawn McCarney 151d3a8aab4SShawn McCarney } // namespace phosphor::power::regulators 152