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