blob: 8340d07b00dbdde94cdb9ea8a77d908ec74525ee [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 /**
Bob King7b743432020-06-22 17:35:04 +0800105 * Monitor the sensors for this rail.
106 *
107 * Sensor monitoring is optional. If sensor monitoring is defined for this
108 * rail, the sensor values are read.
109 *
110 * This method should be called once per second.
111 *
112 * @param system system that contains the chassis
113 * @param chassis chassis that contains the device
114 * @param device device that contains this rail
115 */
116 void monitorSensors(System& system, Chassis& chassis, Device& device);
117
118 /**
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500119 * Returns the sensor monitoring for this rail, if any.
120 *
121 * @return Pointer to SensorMonitoring object. Will equal nullptr if no
122 * sensor monitoring is defined for this rail.
123 */
124 const std::unique_ptr<SensorMonitoring>& getSensorMonitoring() const
125 {
126 return sensorMonitoring;
127 }
128
Shawn McCarneya2461b32019-10-24 18:53:01 -0500129 private:
130 /**
131 * Unique ID of this rail.
132 */
133 const std::string id{};
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500134
135 /**
136 * Configuration changes to apply to this rail, if any. Set to nullptr if
137 * no configuration changes are defined for this rail.
138 */
139 std::unique_ptr<Configuration> configuration{};
140
141 /**
142 * Sensor monitoring for this rail, if any. Set to nullptr if no sensor
143 * monitoring is defined for this rail.
144 */
145 std::unique_ptr<SensorMonitoring> sensorMonitoring{};
Shawn McCarneya2461b32019-10-24 18:53:01 -0500146};
147
Shawn McCarneyea7385b2019-11-07 12:19:32 -0600148} // namespace phosphor::power::regulators