xref: /openbmc/phosphor-power/phosphor-regulators/src/system.hpp (revision f54021972b91be5058b50e9046bb0dd5a3b22a80)
1c3991f16SShawn McCarney /**
2c3991f16SShawn McCarney  * Copyright © 2020 IBM Corporation
3c3991f16SShawn McCarney  *
4c3991f16SShawn McCarney  * Licensed under the Apache License, Version 2.0 (the "License");
5c3991f16SShawn McCarney  * you may not use this file except in compliance with the License.
6c3991f16SShawn McCarney  * You may obtain a copy of the License at
7c3991f16SShawn McCarney  *
8c3991f16SShawn McCarney  *     http://www.apache.org/licenses/LICENSE-2.0
9c3991f16SShawn McCarney  *
10c3991f16SShawn McCarney  * Unless required by applicable law or agreed to in writing, software
11c3991f16SShawn McCarney  * distributed under the License is distributed on an "AS IS" BASIS,
12c3991f16SShawn McCarney  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c3991f16SShawn McCarney  * See the License for the specific language governing permissions and
14c3991f16SShawn McCarney  * limitations under the License.
15c3991f16SShawn McCarney  */
16c3991f16SShawn McCarney #pragma once
17c3991f16SShawn McCarney 
18c3991f16SShawn McCarney #include "chassis.hpp"
19c3991f16SShawn McCarney #include "id_map.hpp"
20c3991f16SShawn McCarney #include "rule.hpp"
2123243f84SBob King #include "services.hpp"
22c3991f16SShawn McCarney 
23c3991f16SShawn McCarney #include <memory>
24c3991f16SShawn McCarney #include <utility>
25c3991f16SShawn McCarney #include <vector>
26c3991f16SShawn McCarney 
27c3991f16SShawn McCarney namespace phosphor::power::regulators
28c3991f16SShawn McCarney {
29c3991f16SShawn McCarney 
30c3991f16SShawn McCarney /**
31c3991f16SShawn McCarney  * @class System
32c3991f16SShawn McCarney  *
33c3991f16SShawn McCarney  * The computer system being controlled and monitored by the BMC.
34c3991f16SShawn McCarney  *
35c3991f16SShawn McCarney  * The system contains one or more chassis.  Chassis are large enclosures that
36c3991f16SShawn McCarney  * can be independently powered off and on by the BMC.
37c3991f16SShawn McCarney  */
38c3991f16SShawn McCarney class System
39c3991f16SShawn McCarney {
40c3991f16SShawn McCarney   public:
41c3991f16SShawn McCarney     // Specify which compiler-generated methods we want
42c3991f16SShawn McCarney     System() = delete;
43c3991f16SShawn McCarney     System(const System&) = delete;
44c3991f16SShawn McCarney     System(System&&) = delete;
45c3991f16SShawn McCarney     System& operator=(const System&) = delete;
46c3991f16SShawn McCarney     System& operator=(System&&) = delete;
47c3991f16SShawn McCarney     ~System() = default;
48c3991f16SShawn McCarney 
49c3991f16SShawn McCarney     /**
50c3991f16SShawn McCarney      * Constructor.
51c3991f16SShawn McCarney      *
52c3991f16SShawn McCarney      * @param rules rules used to monitor and control regulators in the system
53c3991f16SShawn McCarney      * @param chassis chassis in the system
54c3991f16SShawn McCarney      */
System(std::vector<std::unique_ptr<Rule>> rules,std::vector<std::unique_ptr<Chassis>> chassis)55c3991f16SShawn McCarney     explicit System(std::vector<std::unique_ptr<Rule>> rules,
56c3991f16SShawn McCarney                     std::vector<std::unique_ptr<Chassis>> chassis) :
57*f5402197SPatrick Williams         rules{std::move(rules)}, chassis{std::move(chassis)}
58c3991f16SShawn McCarney     {
59db0b833cSShawn McCarney         buildIDMap();
60c3991f16SShawn McCarney     }
61c3991f16SShawn McCarney 
62c3991f16SShawn McCarney     /**
639bd94d36SShawn McCarney      * Clear any cached data about hardware devices.
649bd94d36SShawn McCarney      */
659bd94d36SShawn McCarney     void clearCache();
669bd94d36SShawn McCarney 
679bd94d36SShawn McCarney     /**
6823b0d0d1SShawn McCarney      * Clears all error history.
6923b0d0d1SShawn McCarney      *
7023b0d0d1SShawn McCarney      * All data on previously logged errors will be deleted.  If errors occur
7123b0d0d1SShawn McCarney      * again in the future they will be logged again.
7223b0d0d1SShawn McCarney      *
7323b0d0d1SShawn McCarney      * This method is normally called when the system is being powered on.
7423b0d0d1SShawn McCarney      */
7523b0d0d1SShawn McCarney     void clearErrorHistory();
7623b0d0d1SShawn McCarney 
7723b0d0d1SShawn McCarney     /**
785b19ea51SShawn McCarney      * Close the regulator devices in the system.
79d692d6dfSBob King      *
80d692d6dfSBob King      * @param services system services like error logging and the journal
815b19ea51SShawn McCarney      */
82d692d6dfSBob King     void closeDevices(Services& services);
835b19ea51SShawn McCarney 
845b19ea51SShawn McCarney     /**
852af5289dSShawn McCarney      * Configure the regulator devices in the system.
862af5289dSShawn McCarney      *
872af5289dSShawn McCarney      * This method should be called during the boot before regulators are
882af5289dSShawn McCarney      * enabled.
8923243f84SBob King      *
9023243f84SBob King      * @param services system services like error logging and the journal
912af5289dSShawn McCarney      */
9223243f84SBob King     void configure(Services& services);
932af5289dSShawn McCarney 
942af5289dSShawn McCarney     /**
9537af670eSShawn McCarney      * Detect redundant phase faults in regulator devices in the system.
9637af670eSShawn McCarney      *
9754b3ab9bSShawn McCarney      * This method should be called repeatedly based on a timer.
9837af670eSShawn McCarney      *
9937af670eSShawn McCarney      * @param services system services like error logging and the journal
10037af670eSShawn McCarney      */
10137af670eSShawn McCarney     void detectPhaseFaults(Services& services);
10237af670eSShawn McCarney 
10337af670eSShawn McCarney     /**
104c3991f16SShawn McCarney      * Returns the chassis in the system.
105c3991f16SShawn McCarney      *
106c3991f16SShawn McCarney      * @return chassis
107c3991f16SShawn McCarney      */
getChassis() const108c3991f16SShawn McCarney     const std::vector<std::unique_ptr<Chassis>>& getChassis() const
109c3991f16SShawn McCarney     {
110c3991f16SShawn McCarney         return chassis;
111c3991f16SShawn McCarney     }
112c3991f16SShawn McCarney 
113c3991f16SShawn McCarney     /**
114c3991f16SShawn McCarney      * Returns the IDMap for the system.
115c3991f16SShawn McCarney      *
116c3991f16SShawn McCarney      * The IDMap provides a mapping from string IDs to the associated Device,
117c3991f16SShawn McCarney      * Rail, and Rule objects.
118c3991f16SShawn McCarney      *
119c3991f16SShawn McCarney      * @return IDMap
120c3991f16SShawn McCarney      */
getIDMap() const121c3991f16SShawn McCarney     const IDMap& getIDMap() const
122c3991f16SShawn McCarney     {
123c3991f16SShawn McCarney         return idMap;
124c3991f16SShawn McCarney     }
125c3991f16SShawn McCarney 
126c3991f16SShawn McCarney     /**
127c3991f16SShawn McCarney      * Returns the rules used to monitor and control regulators in the system.
128c3991f16SShawn McCarney      *
129c3991f16SShawn McCarney      * @return rules
130c3991f16SShawn McCarney      */
getRules() const131c3991f16SShawn McCarney     const std::vector<std::unique_ptr<Rule>>& getRules() const
132c3991f16SShawn McCarney     {
133c3991f16SShawn McCarney         return rules;
134c3991f16SShawn McCarney     }
135c3991f16SShawn McCarney 
1368e2294dcSBob King     /**
1378e2294dcSBob King      * Monitors the sensors for the voltage rails produced by this system, if
1388e2294dcSBob King      * any.
1398e2294dcSBob King      *
14054b3ab9bSShawn McCarney      * This method should be called repeatedly based on a timer.
1418a55292dSBob King      *
1428a55292dSBob King      * @param services system services like error logging and the journal
1438e2294dcSBob King      */
1448a55292dSBob King     void monitorSensors(Services& services);
1458e2294dcSBob King 
146c3991f16SShawn McCarney   private:
147c3991f16SShawn McCarney     /**
148db0b833cSShawn McCarney      * Builds the IDMap for the system.
149db0b833cSShawn McCarney      *
150db0b833cSShawn McCarney      * Adds the Device, Rail, and Rule objects in the system to the map.
151db0b833cSShawn McCarney      */
152db0b833cSShawn McCarney     void buildIDMap();
153db0b833cSShawn McCarney 
154db0b833cSShawn McCarney     /**
155c3991f16SShawn McCarney      * Rules used to monitor and control regulators in the system.
156c3991f16SShawn McCarney      */
157c3991f16SShawn McCarney     std::vector<std::unique_ptr<Rule>> rules{};
158c3991f16SShawn McCarney 
159c3991f16SShawn McCarney     /**
160c3991f16SShawn McCarney      * Chassis in the system.
161c3991f16SShawn McCarney      */
162c3991f16SShawn McCarney     std::vector<std::unique_ptr<Chassis>> chassis{};
163c3991f16SShawn McCarney 
164c3991f16SShawn McCarney     /**
165c3991f16SShawn McCarney      * Mapping from string IDs to the associated Device, Rail, and Rule objects.
166c3991f16SShawn McCarney      */
167c3991f16SShawn McCarney     IDMap idMap{};
168c3991f16SShawn McCarney };
169c3991f16SShawn McCarney 
170c3991f16SShawn McCarney } // namespace phosphor::power::regulators
171