Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 1 | /** |
| 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 McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 18 | #include "configuration.hpp" |
| 19 | #include "sensor_monitoring.hpp" |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 20 | #include "services.hpp" |
Shawn McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 21 | |
| 22 | #include <memory> |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 23 | #include <string> |
Shawn McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 24 | #include <utility> |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 25 | |
Shawn McCarney | ea7385b | 2019-11-07 12:19:32 -0600 | [diff] [blame] | 26 | namespace phosphor::power::regulators |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 27 | { |
| 28 | |
Shawn McCarney | 779b956 | 2020-04-13 17:05:45 -0500 | [diff] [blame] | 29 | // Forward declarations to avoid circular dependencies |
| 30 | class Chassis; |
| 31 | class Device; |
| 32 | class System; |
| 33 | |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 34 | /** |
| 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 | */ |
| 42 | class 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 McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 57 | * @param configuration configuration changes to apply to this rail, if any |
| 58 | * @param sensorMonitoring sensor monitoring for this rail, if any |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 59 | */ |
Shawn McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 60 | 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 McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 67 | { |
| 68 | } |
| 69 | |
| 70 | /** |
Shawn McCarney | 2ccf961 | 2021-05-14 11:09:17 -0500 | [diff] [blame] | 71 | * Clears all error history. |
| 72 | * |
| 73 | * All data on previously logged errors will be deleted. If errors occur |
| 74 | * again in the future they will be logged again. |
| 75 | * |
| 76 | * This method is normally called when the system is being powered on. |
| 77 | */ |
| 78 | void clearErrorHistory(); |
| 79 | |
| 80 | /** |
Shawn McCarney | 779b956 | 2020-04-13 17:05:45 -0500 | [diff] [blame] | 81 | * Configure this rail. |
| 82 | * |
| 83 | * Applies the configuration changes that are defined for this rail, if any. |
| 84 | * |
| 85 | * This method should be called during the boot before regulators are |
| 86 | * enabled. |
| 87 | * |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 88 | * @param services system services like error logging and the journal |
Shawn McCarney | 779b956 | 2020-04-13 17:05:45 -0500 | [diff] [blame] | 89 | * @param system system that contains the chassis |
| 90 | * @param chassis chassis that contains the device |
| 91 | * @param device device that contains this rail |
| 92 | */ |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 93 | void configure(Services& services, System& system, Chassis& chassis, |
| 94 | Device& device); |
Shawn McCarney | 779b956 | 2020-04-13 17:05:45 -0500 | [diff] [blame] | 95 | |
| 96 | /** |
Shawn McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 97 | * Returns the configuration changes to apply to this rail, if any. |
| 98 | * |
| 99 | * @return Pointer to Configuration object. Will equal nullptr if no |
| 100 | * configuration changes are defined for this rail. |
| 101 | */ |
| 102 | const std::unique_ptr<Configuration>& getConfiguration() const |
| 103 | { |
| 104 | return configuration; |
| 105 | } |
| 106 | |
| 107 | /** |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 108 | * Returns the unique ID of this rail. |
| 109 | * |
| 110 | * @return rail ID |
| 111 | */ |
Shawn McCarney | 4afb285 | 2019-10-27 18:28:53 -0500 | [diff] [blame] | 112 | const std::string& getID() const |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 113 | { |
| 114 | return id; |
| 115 | } |
| 116 | |
Shawn McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 117 | /** |
Bob King | 7b74343 | 2020-06-22 17:35:04 +0800 | [diff] [blame] | 118 | * Monitor the sensors for this rail. |
| 119 | * |
| 120 | * Sensor monitoring is optional. If sensor monitoring is defined for this |
| 121 | * rail, the sensor values are read. |
| 122 | * |
| 123 | * This method should be called once per second. |
| 124 | * |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 125 | * @param services system services like error logging and the journal |
Bob King | 7b74343 | 2020-06-22 17:35:04 +0800 | [diff] [blame] | 126 | * @param system system that contains the chassis |
| 127 | * @param chassis chassis that contains the device |
| 128 | * @param device device that contains this rail |
| 129 | */ |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 130 | void monitorSensors(Services& services, System& system, Chassis& chassis, |
| 131 | Device& device); |
Bob King | 7b74343 | 2020-06-22 17:35:04 +0800 | [diff] [blame] | 132 | |
| 133 | /** |
Shawn McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 134 | * Returns the sensor monitoring for this rail, if any. |
| 135 | * |
| 136 | * @return Pointer to SensorMonitoring object. Will equal nullptr if no |
| 137 | * sensor monitoring is defined for this rail. |
| 138 | */ |
| 139 | const std::unique_ptr<SensorMonitoring>& getSensorMonitoring() const |
| 140 | { |
| 141 | return sensorMonitoring; |
| 142 | } |
| 143 | |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 144 | private: |
| 145 | /** |
| 146 | * Unique ID of this rail. |
| 147 | */ |
| 148 | const std::string id{}; |
Shawn McCarney | 4bf310e | 2020-03-10 17:48:11 -0500 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * Configuration changes to apply to this rail, if any. Set to nullptr if |
| 152 | * no configuration changes are defined for this rail. |
| 153 | */ |
| 154 | std::unique_ptr<Configuration> configuration{}; |
| 155 | |
| 156 | /** |
| 157 | * Sensor monitoring for this rail, if any. Set to nullptr if no sensor |
| 158 | * monitoring is defined for this rail. |
| 159 | */ |
| 160 | std::unique_ptr<SensorMonitoring> sensorMonitoring{}; |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 161 | }; |
| 162 | |
Shawn McCarney | ea7385b | 2019-11-07 12:19:32 -0600 | [diff] [blame] | 163 | } // namespace phosphor::power::regulators |