blob: 02a33eb45ed529d8053feab12b7867fbc430a36e [file] [log] [blame]
Shawn McCarneyc3991f12020-04-05 13:16:06 -05001/**
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 King23243f82020-07-29 10:38:57 +080021#include "services.hpp"
Shawn McCarneyc3991f12020-04-05 13:16:06 -050022
23#include <memory>
24#include <utility>
25#include <vector>
26
27namespace 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 */
38class 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) :
Patrick Williamsf5402192024-08-16 15:20:53 -040057 rules{std::move(rules)}, chassis{std::move(chassis)}
Shawn McCarneyc3991f12020-04-05 13:16:06 -050058 {
Shawn McCarneydb0b8332020-04-06 14:13:04 -050059 buildIDMap();
Shawn McCarneyc3991f12020-04-05 13:16:06 -050060 }
61
62 /**
Shawn McCarney9bd94d32021-01-25 19:40:42 -060063 * Clear any cached data about hardware devices.
64 */
65 void clearCache();
66
67 /**
Shawn McCarney23b0d0d2021-05-14 15:27:59 -050068 * Clears all error history.
69 *
70 * All data on previously logged errors will be deleted. If errors occur
71 * again in the future they will be logged again.
72 *
73 * This method is normally called when the system is being powered on.
74 */
75 void clearErrorHistory();
76
77 /**
Shawn McCarney5b19ea52020-06-02 18:52:56 -050078 * Close the regulator devices in the system.
Bob Kingd692d6d2020-09-14 13:42:57 +080079 *
80 * @param services system services like error logging and the journal
Shawn McCarney5b19ea52020-06-02 18:52:56 -050081 */
Bob Kingd692d6d2020-09-14 13:42:57 +080082 void closeDevices(Services& services);
Shawn McCarney5b19ea52020-06-02 18:52:56 -050083
84 /**
Shawn McCarney2af52892020-04-14 11:54:45 -050085 * Configure the regulator devices in the system.
86 *
87 * This method should be called during the boot before regulators are
88 * enabled.
Bob King23243f82020-07-29 10:38:57 +080089 *
90 * @param services system services like error logging and the journal
Shawn McCarney2af52892020-04-14 11:54:45 -050091 */
Bob King23243f82020-07-29 10:38:57 +080092 void configure(Services& services);
Shawn McCarney2af52892020-04-14 11:54:45 -050093
94 /**
Shawn McCarney37af6702021-09-10 00:16:52 -050095 * Detect redundant phase faults in regulator devices in the system.
96 *
Shawn McCarney54b3ab92021-09-14 17:28:56 -050097 * This method should be called repeatedly based on a timer.
Shawn McCarney37af6702021-09-10 00:16:52 -050098 *
99 * @param services system services like error logging and the journal
100 */
101 void detectPhaseFaults(Services& services);
102
103 /**
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500104 * Returns the chassis in the system.
105 *
106 * @return chassis
107 */
108 const std::vector<std::unique_ptr<Chassis>>& getChassis() const
109 {
110 return chassis;
111 }
112
113 /**
114 * Returns the IDMap for the system.
115 *
116 * The IDMap provides a mapping from string IDs to the associated Device,
117 * Rail, and Rule objects.
118 *
119 * @return IDMap
120 */
121 const IDMap& getIDMap() const
122 {
123 return idMap;
124 }
125
126 /**
127 * Returns the rules used to monitor and control regulators in the system.
128 *
129 * @return rules
130 */
131 const std::vector<std::unique_ptr<Rule>>& getRules() const
132 {
133 return rules;
134 }
135
Bob King8e2294d2020-07-14 17:41:31 +0800136 /**
137 * Monitors the sensors for the voltage rails produced by this system, if
138 * any.
139 *
Shawn McCarney54b3ab92021-09-14 17:28:56 -0500140 * This method should be called repeatedly based on a timer.
Bob King8a552922020-08-05 17:02:31 +0800141 *
142 * @param services system services like error logging and the journal
Bob King8e2294d2020-07-14 17:41:31 +0800143 */
Bob King8a552922020-08-05 17:02:31 +0800144 void monitorSensors(Services& services);
Bob King8e2294d2020-07-14 17:41:31 +0800145
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500146 private:
147 /**
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500148 * Builds the IDMap for the system.
149 *
150 * Adds the Device, Rail, and Rule objects in the system to the map.
151 */
152 void buildIDMap();
153
154 /**
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500155 * Rules used to monitor and control regulators in the system.
156 */
157 std::vector<std::unique_ptr<Rule>> rules{};
158
159 /**
160 * Chassis in the system.
161 */
162 std::vector<std::unique_ptr<Chassis>> chassis{};
163
164 /**
165 * Mapping from string IDs to the associated Device, Rail, and Rule objects.
166 */
167 IDMap idMap{};
168};
169
170} // namespace phosphor::power::regulators