blob: 9caafbea99c14e60e6d2c7ab12bb9da249a190f7 [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"
Bob King23243f82020-07-29 10:38:57 +080020#include "services.hpp"
Shawn McCarney4bf310e2020-03-10 17:48:11 -050021
22#include <memory>
Shawn McCarneya2461b32019-10-24 18:53:01 -050023#include <string>
Shawn McCarney4bf310e2020-03-10 17:48:11 -050024#include <utility>
Shawn McCarneya2461b32019-10-24 18:53:01 -050025
Shawn McCarneyea7385b2019-11-07 12:19:32 -060026namespace phosphor::power::regulators
Shawn McCarneya2461b32019-10-24 18:53:01 -050027{
28
Shawn McCarney779b9562020-04-13 17:05:45 -050029// Forward declarations to avoid circular dependencies
30class Chassis;
31class Device;
32class System;
33
Shawn McCarneya2461b32019-10-24 18:53:01 -050034/**
35 * @class Rail
36 *
37 * A voltage rail produced by a voltage regulator.
38 *
39 * Voltage regulators produce one or more rails. Each rail typically provides a
40 * different output voltage level, such as 1.1V.
41 */
42class Rail
43{
44 public:
45 // Specify which compiler-generated methods we want
46 Rail() = delete;
47 Rail(const Rail&) = delete;
48 Rail(Rail&&) = delete;
49 Rail& operator=(const Rail&) = delete;
50 Rail& operator=(Rail&&) = delete;
51 ~Rail() = default;
52
53 /**
54 * Constructor.
55 *
56 * @param id unique rail ID
Shawn McCarney4bf310e2020-03-10 17:48:11 -050057 * @param configuration configuration changes to apply to this rail, if any
58 * @param sensorMonitoring sensor monitoring for this rail, if any
Shawn McCarneya2461b32019-10-24 18:53:01 -050059 */
Shawn McCarney4bf310e2020-03-10 17:48:11 -050060 explicit Rail(
61 const std::string& id,
62 std::unique_ptr<Configuration> configuration = nullptr,
63 std::unique_ptr<SensorMonitoring> sensorMonitoring = nullptr) :
64 id{id},
65 configuration{std::move(configuration)}, sensorMonitoring{std::move(
66 sensorMonitoring)}
Shawn McCarneya2461b32019-10-24 18:53:01 -050067 {
68 }
69
70 /**
Shawn McCarney779b9562020-04-13 17:05:45 -050071 * Configure this rail.
72 *
73 * Applies the configuration changes that are defined for this rail, if any.
74 *
75 * This method should be called during the boot before regulators are
76 * enabled.
77 *
Bob King23243f82020-07-29 10:38:57 +080078 * @param services system services like error logging and the journal
Shawn McCarney779b9562020-04-13 17:05:45 -050079 * @param system system that contains the chassis
80 * @param chassis chassis that contains the device
81 * @param device device that contains this rail
82 */
Bob King23243f82020-07-29 10:38:57 +080083 void configure(Services& services, System& system, Chassis& chassis,
84 Device& device);
Shawn McCarney779b9562020-04-13 17:05:45 -050085
86 /**
Shawn McCarney4bf310e2020-03-10 17:48:11 -050087 * Returns the configuration changes to apply to this rail, if any.
88 *
89 * @return Pointer to Configuration object. Will equal nullptr if no
90 * configuration changes are defined for this rail.
91 */
92 const std::unique_ptr<Configuration>& getConfiguration() const
93 {
94 return configuration;
95 }
96
97 /**
Shawn McCarneya2461b32019-10-24 18:53:01 -050098 * Returns the unique ID of this rail.
99 *
100 * @return rail ID
101 */
Shawn McCarney4afb2852019-10-27 18:28:53 -0500102 const std::string& getID() const
Shawn McCarneya2461b32019-10-24 18:53:01 -0500103 {
104 return id;
105 }
106
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500107 /**
Bob King7b743432020-06-22 17:35:04 +0800108 * Monitor the sensors for this rail.
109 *
110 * Sensor monitoring is optional. If sensor monitoring is defined for this
111 * rail, the sensor values are read.
112 *
113 * This method should be called once per second.
114 *
115 * @param system system that contains the chassis
116 * @param chassis chassis that contains the device
117 * @param device device that contains this rail
118 */
119 void monitorSensors(System& system, Chassis& chassis, Device& device);
120
121 /**
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500122 * Returns the sensor monitoring for this rail, if any.
123 *
124 * @return Pointer to SensorMonitoring object. Will equal nullptr if no
125 * sensor monitoring is defined for this rail.
126 */
127 const std::unique_ptr<SensorMonitoring>& getSensorMonitoring() const
128 {
129 return sensorMonitoring;
130 }
131
Shawn McCarneya2461b32019-10-24 18:53:01 -0500132 private:
133 /**
134 * Unique ID of this rail.
135 */
136 const std::string id{};
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500137
138 /**
139 * Configuration changes to apply to this rail, if any. Set to nullptr if
140 * no configuration changes are defined for this rail.
141 */
142 std::unique_ptr<Configuration> configuration{};
143
144 /**
145 * Sensor monitoring for this rail, if any. Set to nullptr if no sensor
146 * monitoring is defined for this rail.
147 */
148 std::unique_ptr<SensorMonitoring> sensorMonitoring{};
Shawn McCarneya2461b32019-10-24 18:53:01 -0500149};
150
Shawn McCarneyea7385b2019-11-07 12:19:32 -0600151} // namespace phosphor::power::regulators