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" |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 20 | |
| 21 | #include <memory> |
| 22 | #include <stdexcept> |
| 23 | #include <string> |
| 24 | #include <utility> |
| 25 | #include <vector> |
| 26 | |
| 27 | namespace phosphor::power::regulators |
| 28 | { |
| 29 | |
Shawn McCarney | 525e20c | 2020-04-14 11:05:39 -0500 | [diff] [blame] | 30 | // Forward declarations to avoid circular dependencies |
| 31 | class System; |
| 32 | |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 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 | /** |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 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 | /** |
Shawn McCarney | 050531f | 2020-06-02 14:17:12 -0500 | [diff] [blame] | 88 | * Close the devices within this chassis, if any. |
| 89 | */ |
| 90 | void closeDevices(); |
| 91 | |
| 92 | /** |
Shawn McCarney | 525e20c | 2020-04-14 11:05:39 -0500 | [diff] [blame] | 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 | /** |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 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 | private: |
| 126 | /** |
| 127 | * Chassis number within the system. |
| 128 | * |
| 129 | * Chassis numbers start at 1 because chassis 0 represents the entire |
| 130 | * system. |
| 131 | */ |
| 132 | const unsigned int number{}; |
| 133 | |
| 134 | /** |
| 135 | * Devices within this chassis, if any. |
| 136 | * |
| 137 | * The vector contains regulator devices and any related devices |
| 138 | * required to perform regulator operations. |
| 139 | */ |
| 140 | std::vector<std::unique_ptr<Device>> devices{}; |
| 141 | }; |
| 142 | |
| 143 | } // namespace phosphor::power::regulators |