blob: 9e0ce3d12a593845e0ee732347f5f214c604d32f [file] [log] [blame]
Shawn McCarneya2461b32019-10-24 18:53:01 -05001/**
2 * Copyright © 2019 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
Shawn McCarney4bf310e2020-03-10 17:48:11 -050018#include "configuration.hpp"
19#include "sensor_monitoring.hpp"
20
21#include <memory>
Shawn McCarneya2461b32019-10-24 18:53:01 -050022#include <string>
Shawn McCarney4bf310e2020-03-10 17:48:11 -050023#include <utility>
Shawn McCarneya2461b32019-10-24 18:53:01 -050024
Shawn McCarneyea7385b2019-11-07 12:19:32 -060025namespace phosphor::power::regulators
Shawn McCarneya2461b32019-10-24 18:53:01 -050026{
27
Shawn McCarney779b9562020-04-13 17:05:45 -050028// Forward declarations to avoid circular dependencies
29class Chassis;
30class Device;
31class System;
32
Shawn McCarneya2461b32019-10-24 18:53:01 -050033/**
34 * @class Rail
35 *
36 * A voltage rail produced by a voltage regulator.
37 *
38 * Voltage regulators produce one or more rails. Each rail typically provides a
39 * different output voltage level, such as 1.1V.
40 */
41class Rail
42{
43 public:
44 // Specify which compiler-generated methods we want
45 Rail() = delete;
46 Rail(const Rail&) = delete;
47 Rail(Rail&&) = delete;
48 Rail& operator=(const Rail&) = delete;
49 Rail& operator=(Rail&&) = delete;
50 ~Rail() = default;
51
52 /**
53 * Constructor.
54 *
55 * @param id unique rail ID
Shawn McCarney4bf310e2020-03-10 17:48:11 -050056 * @param configuration configuration changes to apply to this rail, if any
57 * @param sensorMonitoring sensor monitoring for this rail, if any
Shawn McCarneya2461b32019-10-24 18:53:01 -050058 */
Shawn McCarney4bf310e2020-03-10 17:48:11 -050059 explicit Rail(
60 const std::string& id,
61 std::unique_ptr<Configuration> configuration = nullptr,
62 std::unique_ptr<SensorMonitoring> sensorMonitoring = nullptr) :
63 id{id},
64 configuration{std::move(configuration)}, sensorMonitoring{std::move(
65 sensorMonitoring)}
Shawn McCarneya2461b32019-10-24 18:53:01 -050066 {
67 }
68
69 /**
Shawn McCarney779b9562020-04-13 17:05:45 -050070 * Configure this rail.
71 *
72 * Applies the configuration changes that are defined for this rail, if any.
73 *
74 * This method should be called during the boot before regulators are
75 * enabled.
76 *
77 * @param system system that contains the chassis
78 * @param chassis chassis that contains the device
79 * @param device device that contains this rail
80 */
81 void configure(System& system, Chassis& chassis, Device& device);
82
83 /**
Shawn McCarney4bf310e2020-03-10 17:48:11 -050084 * Returns the configuration changes to apply to this rail, if any.
85 *
86 * @return Pointer to Configuration object. Will equal nullptr if no
87 * configuration changes are defined for this rail.
88 */
89 const std::unique_ptr<Configuration>& getConfiguration() const
90 {
91 return configuration;
92 }
93
94 /**
Shawn McCarneya2461b32019-10-24 18:53:01 -050095 * Returns the unique ID of this rail.
96 *
97 * @return rail ID
98 */
Shawn McCarney4afb2852019-10-27 18:28:53 -050099 const std::string& getID() const
Shawn McCarneya2461b32019-10-24 18:53:01 -0500100 {
101 return id;
102 }
103
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500104 /**
105 * Returns the sensor monitoring for this rail, if any.
106 *
107 * @return Pointer to SensorMonitoring object. Will equal nullptr if no
108 * sensor monitoring is defined for this rail.
109 */
110 const std::unique_ptr<SensorMonitoring>& getSensorMonitoring() const
111 {
112 return sensorMonitoring;
113 }
114
Shawn McCarneya2461b32019-10-24 18:53:01 -0500115 private:
116 /**
117 * Unique ID of this rail.
118 */
119 const std::string id{};
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500120
121 /**
122 * Configuration changes to apply to this rail, if any. Set to nullptr if
123 * no configuration changes are defined for this rail.
124 */
125 std::unique_ptr<Configuration> configuration{};
126
127 /**
128 * Sensor monitoring for this rail, if any. Set to nullptr if no sensor
129 * monitoring is defined for this rail.
130 */
131 std::unique_ptr<SensorMonitoring> sensorMonitoring{};
Shawn McCarneya2461b32019-10-24 18:53:01 -0500132};
133
Shawn McCarneyea7385b2019-11-07 12:19:32 -0600134} // namespace phosphor::power::regulators