Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -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 "chassis.hpp" |
| 19 | #include "id_map.hpp" |
| 20 | #include "rule.hpp" |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 21 | #include "services.hpp" |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 22 | |
| 23 | #include <memory> |
| 24 | #include <utility> |
| 25 | #include <vector> |
| 26 | |
| 27 | namespace phosphor::power::regulators |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * @class System |
| 32 | * |
| 33 | * The computer system being controlled and monitored by the BMC. |
| 34 | * |
| 35 | * The system contains one or more chassis. Chassis are large enclosures that |
| 36 | * can be independently powered off and on by the BMC. |
| 37 | */ |
| 38 | class System |
| 39 | { |
| 40 | public: |
| 41 | // Specify which compiler-generated methods we want |
| 42 | System() = delete; |
| 43 | System(const System&) = delete; |
| 44 | System(System&&) = delete; |
| 45 | System& operator=(const System&) = delete; |
| 46 | System& operator=(System&&) = delete; |
| 47 | ~System() = default; |
| 48 | |
| 49 | /** |
| 50 | * Constructor. |
| 51 | * |
| 52 | * @param rules rules used to monitor and control regulators in the system |
| 53 | * @param chassis chassis in the system |
| 54 | */ |
| 55 | explicit System(std::vector<std::unique_ptr<Rule>> rules, |
| 56 | std::vector<std::unique_ptr<Chassis>> chassis) : |
| 57 | rules{std::move(rules)}, |
| 58 | chassis{std::move(chassis)} |
| 59 | { |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 60 | buildIDMap(); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 64 | * Clear any cached data about hardware devices. |
| 65 | */ |
| 66 | void clearCache(); |
| 67 | |
| 68 | /** |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 69 | * Close the regulator devices in the system. |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 70 | * |
| 71 | * @param services system services like error logging and the journal |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 72 | */ |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 73 | void closeDevices(Services& services); |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 74 | |
| 75 | /** |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 76 | * Configure the regulator devices in the system. |
| 77 | * |
| 78 | * This method should be called during the boot before regulators are |
| 79 | * enabled. |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 80 | * |
| 81 | * @param services system services like error logging and the journal |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 82 | */ |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 83 | void configure(Services& services); |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 84 | |
| 85 | /** |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 86 | * Returns the chassis in the system. |
| 87 | * |
| 88 | * @return chassis |
| 89 | */ |
| 90 | const std::vector<std::unique_ptr<Chassis>>& getChassis() const |
| 91 | { |
| 92 | return chassis; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the IDMap for the system. |
| 97 | * |
| 98 | * The IDMap provides a mapping from string IDs to the associated Device, |
| 99 | * Rail, and Rule objects. |
| 100 | * |
| 101 | * @return IDMap |
| 102 | */ |
| 103 | const IDMap& getIDMap() const |
| 104 | { |
| 105 | return idMap; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the rules used to monitor and control regulators in the system. |
| 110 | * |
| 111 | * @return rules |
| 112 | */ |
| 113 | const std::vector<std::unique_ptr<Rule>>& getRules() const |
| 114 | { |
| 115 | return rules; |
| 116 | } |
| 117 | |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 118 | /** |
| 119 | * Monitors the sensors for the voltage rails produced by this system, if |
| 120 | * any. |
| 121 | * |
| 122 | * This method should be called once per second. |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 123 | * |
| 124 | * @param services system services like error logging and the journal |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 125 | */ |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 126 | void monitorSensors(Services& services); |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 127 | |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 128 | private: |
| 129 | /** |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 130 | * Builds the IDMap for the system. |
| 131 | * |
| 132 | * Adds the Device, Rail, and Rule objects in the system to the map. |
| 133 | */ |
| 134 | void buildIDMap(); |
| 135 | |
| 136 | /** |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 137 | * Rules used to monitor and control regulators in the system. |
| 138 | */ |
| 139 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 140 | |
| 141 | /** |
| 142 | * Chassis in the system. |
| 143 | */ |
| 144 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
| 145 | |
| 146 | /** |
| 147 | * Mapping from string IDs to the associated Device, Rail, and Rule objects. |
| 148 | */ |
| 149 | IDMap idMap{}; |
| 150 | }; |
| 151 | |
| 152 | } // namespace phosphor::power::regulators |