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 18 #include "configuration.hpp" 19 #include "sensor_monitoring.hpp" 20 #include "services.hpp" 21 22 #include <memory> 23 #include <string> 24 #include <utility> 25 26 namespace phosphor::power::regulators 27 { 28 29 // Forward declarations to avoid circular dependencies 30 class Chassis; 31 class Device; 32 class System; 33 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 57 * @param configuration configuration changes to apply to this rail, if any 58 * @param sensorMonitoring sensor monitoring for this rail, if any 59 */ 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)} 67 { 68 } 69 70 /** 71 * 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 * 78 * @param services system services like error logging and the journal 79 * @param system system that contains the chassis 80 * @param chassis chassis that contains the device 81 * @param device device that contains this rail 82 */ 83 void configure(Services& services, System& system, Chassis& chassis, 84 Device& device); 85 86 /** 87 * 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 /** 98 * Returns the unique ID of this rail. 99 * 100 * @return rail ID 101 */ 102 const std::string& getID() const 103 { 104 return id; 105 } 106 107 /** 108 * 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 services system services like error logging and the journal 116 * @param system system that contains the chassis 117 * @param chassis chassis that contains the device 118 * @param device device that contains this rail 119 */ 120 void monitorSensors(Services& services, System& system, Chassis& chassis, 121 Device& device); 122 123 /** 124 * Returns the sensor monitoring for this rail, if any. 125 * 126 * @return Pointer to SensorMonitoring object. Will equal nullptr if no 127 * sensor monitoring is defined for this rail. 128 */ 129 const std::unique_ptr<SensorMonitoring>& getSensorMonitoring() const 130 { 131 return sensorMonitoring; 132 } 133 134 private: 135 /** 136 * Unique ID of this rail. 137 */ 138 const std::string id{}; 139 140 /** 141 * Configuration changes to apply to this rail, if any. Set to nullptr if 142 * no configuration changes are defined for this rail. 143 */ 144 std::unique_ptr<Configuration> configuration{}; 145 146 /** 147 * Sensor monitoring for this rail, if any. Set to nullptr if no sensor 148 * monitoring is defined for this rail. 149 */ 150 std::unique_ptr<SensorMonitoring> sensorMonitoring{}; 151 }; 152 153 } // namespace phosphor::power::regulators 154