blob: d8026656b2823a072fc19640b3bb5fc29a45cf8a [file] [log] [blame]
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -05001/**
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"
Bob King23243f82020-07-29 10:38:57 +080019#include "services.hpp"
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -050020
21#include <memory>
22#include <optional>
Shawn McCarney39765002020-04-09 18:03:26 -050023#include <string>
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -050024#include <utility>
25#include <vector>
26
27namespace phosphor::power::regulators
28{
29
Shawn McCarney39765002020-04-09 18:03:26 -050030// Forward declarations to avoid circular dependencies
31class Chassis;
32class Device;
33class Rail;
34class System;
35
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -050036/**
37 * @class Configuration
38 *
39 * Configuration changes that should be applied to a device or regulator rail.
40 * These changes usually override hardware default settings.
41 *
42 * The most common configuration change is setting the output voltage for a
43 * regulator rail. Other examples include modifying pgood thresholds and
44 * overcurrent settings.
45 *
46 * The configuration changes are applied during the boot before regulators are
47 * enabled.
48 *
49 * The configuration changes are applied by executing one or more actions.
50 *
51 * An output voltage value can be specified if necessary. The value will be
52 * stored in the ActionEnvironment when the actions are executed. Actions that
53 * require a volts value, such as PMBusWriteVoutCommandAction, can obtain it
54 * from the ActionEnvironment.
55 */
56class Configuration
57{
58 public:
59 // Specify which compiler-generated methods we want
60 Configuration() = delete;
61 Configuration(const Configuration&) = delete;
62 Configuration(Configuration&&) = delete;
63 Configuration& operator=(const Configuration&) = delete;
64 Configuration& operator=(Configuration&&) = delete;
65 ~Configuration() = default;
66
67 /**
68 * Constructor.
69 *
70 * @param volts optional output voltage value
71 * @param actions actions that configure the device/rail
72 */
73 explicit Configuration(std::optional<double> volts,
74 std::vector<std::unique_ptr<Action>> actions) :
Patrick Williamsf5402192024-08-16 15:20:53 -040075 volts{volts}, actions{std::move(actions)}
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000076 {}
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -050077
78 /**
Shawn McCarney39765002020-04-09 18:03:26 -050079 * Executes the actions to configure the specified device.
80 *
81 * This method should be called during the boot before regulators are
82 * enabled.
83 *
Bob King23243f82020-07-29 10:38:57 +080084 * @param services system services like error logging and the journal
Shawn McCarney39765002020-04-09 18:03:26 -050085 * @param system system that contains the chassis
86 * @param chassis chassis that contains the device
87 * @param device device to configure
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -050088 */
Bob King23243f82020-07-29 10:38:57 +080089 void execute(Services& services, System& system, Chassis& chassis,
90 Device& device);
Shawn McCarney39765002020-04-09 18:03:26 -050091
92 /**
93 * Executes the actions to configure the specified rail.
94 *
95 * This method should be called during the boot before regulators are
96 * enabled.
97 *
Bob King23243f82020-07-29 10:38:57 +080098 * @param services system services like error logging and the journal
Shawn McCarney39765002020-04-09 18:03:26 -050099 * @param system system that contains the chassis
100 * @param chassis chassis that contains the device
101 * @param device device that contains the rail
102 * @param rail rail to configure
103 */
Bob King23243f82020-07-29 10:38:57 +0800104 void execute(Services& services, System& system, Chassis& chassis,
105 Device& device, Rail& rail);
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -0500106
107 /**
108 * Returns the actions that configure the device/rail.
109 *
110 * @return actions
111 */
112 const std::vector<std::unique_ptr<Action>>& getActions() const
113 {
114 return actions;
115 }
116
117 /**
118 * Returns the optional output voltage value.
119 *
120 * @return optional volts value
121 */
122 std::optional<double> getVolts() const
123 {
124 return volts;
125 }
126
127 private:
128 /**
Shawn McCarney39765002020-04-09 18:03:26 -0500129 * Executes the actions to configure a device or rail.
130 *
Bob King23243f82020-07-29 10:38:57 +0800131 * @param services system services like error logging and the journal
Shawn McCarney39765002020-04-09 18:03:26 -0500132 * @param system system that contains the chassis
133 * @param chassis chassis that contains the device
134 * @param device device to configure or that contains rail to configure
135 * @param deviceOrRailID ID of the device or rail to configure
136 */
Bob King23243f82020-07-29 10:38:57 +0800137 void execute(Services& services, System& system, Chassis& chassis,
138 Device& device, const std::string& deviceOrRailID);
Shawn McCarney39765002020-04-09 18:03:26 -0500139
140 /**
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -0500141 * Optional output voltage value.
142 */
143 const std::optional<double> volts{};
144
145 /**
146 * Actions that configure the device/rail.
147 */
148 std::vector<std::unique_ptr<Action>> actions{};
149};
150
151} // namespace phosphor::power::regulators