1 /** 2 * Copyright © 2020 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 "device.hpp" 19 #include "id_map.hpp" 20 21 #include <memory> 22 #include <stdexcept> 23 #include <string> 24 #include <utility> 25 #include <vector> 26 27 namespace phosphor::power::regulators 28 { 29 30 // Forward declarations to avoid circular dependencies 31 class System; 32 33 /** 34 * @class Chassis 35 * 36 * A chassis within the system. 37 * 38 * Chassis are large enclosures that can be independently powered off and on by 39 * the BMC. Small and mid-sized systems may contain a single chassis. In a 40 * large rack-mounted system, each drawer may correspond to a chassis. 41 * 42 * A C++ Chassis object only needs to be created if the physical chassis 43 * contains regulators that need to be configured or monitored. 44 */ 45 class Chassis 46 { 47 public: 48 // Specify which compiler-generated methods we want 49 Chassis() = delete; 50 Chassis(const Chassis&) = delete; 51 Chassis(Chassis&&) = delete; 52 Chassis& operator=(const Chassis&) = delete; 53 Chassis& operator=(Chassis&&) = delete; 54 ~Chassis() = default; 55 56 /** 57 * Constructor. 58 * 59 * Throws an exception if any of the input parameters are invalid. 60 * 61 * @param number Chassis number within the system. Chassis numbers start at 62 * 1 because chassis 0 represents the entire system. 63 * @param devices Devices within this chassis, if any. The vector should 64 * contain regulator devices and any related devices required 65 * to perform regulator operations. 66 */ 67 explicit Chassis(unsigned int number, 68 std::vector<std::unique_ptr<Device>> devices = 69 std::vector<std::unique_ptr<Device>>{}) : 70 number{number}, 71 devices{std::move(devices)} 72 { 73 if (number < 1) 74 { 75 throw std::invalid_argument{"Invalid chassis number: " + 76 std::to_string(number)}; 77 } 78 } 79 80 /** 81 * Adds the Device and Rail objects in this chassis to the specified IDMap. 82 * 83 * @param idMap mapping from IDs to the associated Device/Rail/Rule objects 84 */ 85 void addToIDMap(IDMap& idMap); 86 87 /** 88 * Close the devices within this chassis, if any. 89 */ 90 void closeDevices(); 91 92 /** 93 * Configure the devices within this chassis, if any. 94 * 95 * This method should be called during the boot before regulators are 96 * enabled. 97 * 98 * @param system system that contains this chassis 99 */ 100 void configure(System& system); 101 102 /** 103 * Returns the devices within this chassis, if any. 104 * 105 * The vector contains regulator devices and any related devices 106 * required to perform regulator operations. 107 * 108 * @return devices in chassis 109 */ 110 const std::vector<std::unique_ptr<Device>>& getDevices() const 111 { 112 return devices; 113 } 114 115 /** 116 * Returns the chassis number within the system. 117 * 118 * @return chassis number 119 */ 120 unsigned int getNumber() const 121 { 122 return number; 123 } 124 125 /** 126 * Monitors the sensors for the voltage rails produced by this chassis, if 127 * any. 128 * 129 * This method should be called once per second. 130 * 131 * @param system system that contains the chassis 132 */ 133 void monitorSensors(System& system); 134 135 private: 136 /** 137 * Chassis number within the system. 138 * 139 * Chassis numbers start at 1 because chassis 0 represents the entire 140 * system. 141 */ 142 const unsigned int number{}; 143 144 /** 145 * Devices within this chassis, if any. 146 * 147 * The vector contains regulator devices and any related devices 148 * required to perform regulator operations. 149 */ 150 std::vector<std::unique_ptr<Device>> devices{}; 151 }; 152 153 } // namespace phosphor::power::regulators 154