blob: 30f62ffe2503bc5aba574a0a5b0807124ea2fce4 [file] [log] [blame]
Shawn McCarney8a3afd72020-03-12 14:28:44 -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 "device.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050019#include "id_map.hpp"
Bob King23243f82020-07-29 10:38:57 +080020#include "services.hpp"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050021
22#include <memory>
23#include <stdexcept>
24#include <string>
25#include <utility>
26#include <vector>
27
28namespace phosphor::power::regulators
29{
30
Shawn McCarney525e20c2020-04-14 11:05:39 -050031// Forward declarations to avoid circular dependencies
32class System;
33
Shawn McCarney8a3afd72020-03-12 14:28:44 -050034/**
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 */
46class 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.
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050064 * @param inventoryPath D-Bus inventory path for this chassis
Shawn McCarney8a3afd72020-03-12 14:28:44 -050065 * @param devices Devices within this chassis, if any. The vector should
66 * contain regulator devices and any related devices required
67 * to perform regulator operations.
68 */
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050069 explicit Chassis(unsigned int number, const std::string& inventoryPath,
Shawn McCarney8a3afd72020-03-12 14:28:44 -050070 std::vector<std::unique_ptr<Device>> devices =
71 std::vector<std::unique_ptr<Device>>{}) :
72 number{number},
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050073 inventoryPath{inventoryPath}, devices{std::move(devices)}
Shawn McCarney8a3afd72020-03-12 14:28:44 -050074 {
75 if (number < 1)
76 {
77 throw std::invalid_argument{"Invalid chassis number: " +
78 std::to_string(number)};
79 }
80 }
81
82 /**
Shawn McCarneydb0b8332020-04-06 14:13:04 -050083 * Adds the Device and Rail objects in this chassis to the specified IDMap.
84 *
85 * @param idMap mapping from IDs to the associated Device/Rail/Rule objects
86 */
87 void addToIDMap(IDMap& idMap);
88
89 /**
Shawn McCarney9bd94d32021-01-25 19:40:42 -060090 * Clear any cached data about hardware devices.
91 */
92 void clearCache();
93
94 /**
Shawn McCarney050531f2020-06-02 14:17:12 -050095 * Close the devices within this chassis, if any.
Bob Kingd692d6d2020-09-14 13:42:57 +080096 *
97 * @param services system services like error logging and the journal
Shawn McCarney050531f2020-06-02 14:17:12 -050098 */
Bob Kingd692d6d2020-09-14 13:42:57 +080099 void closeDevices(Services& services);
Shawn McCarney050531f2020-06-02 14:17:12 -0500100
101 /**
Shawn McCarney525e20c2020-04-14 11:05:39 -0500102 * Configure the devices within this chassis, if any.
103 *
104 * This method should be called during the boot before regulators are
105 * enabled.
106 *
Bob King23243f82020-07-29 10:38:57 +0800107 * @param services system services like error logging and the journal
Shawn McCarney525e20c2020-04-14 11:05:39 -0500108 * @param system system that contains this chassis
109 */
Bob King23243f82020-07-29 10:38:57 +0800110 void configure(Services& services, System& system);
Shawn McCarney525e20c2020-04-14 11:05:39 -0500111
112 /**
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500113 * Returns the devices within this chassis, if any.
114 *
115 * The vector contains regulator devices and any related devices
116 * required to perform regulator operations.
117 *
118 * @return devices in chassis
119 */
120 const std::vector<std::unique_ptr<Device>>& getDevices() const
121 {
122 return devices;
123 }
124
125 /**
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500126 * Returns the D-Bus inventory path for this chassis.
127 *
128 * @return inventory path
129 */
130 const std::string& getInventoryPath() const
131 {
132 return inventoryPath;
133 }
134
135 /**
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500136 * Returns the chassis number within the system.
137 *
138 * @return chassis number
139 */
140 unsigned int getNumber() const
141 {
142 return number;
143 }
144
Bob Kinga2c81a62020-07-08 13:31:16 +0800145 /**
146 * Monitors the sensors for the voltage rails produced by this chassis, if
147 * any.
148 *
149 * This method should be called once per second.
150 *
Bob King8a552922020-08-05 17:02:31 +0800151 * @param services system services like error logging and the journal
Bob Kinga2c81a62020-07-08 13:31:16 +0800152 * @param system system that contains the chassis
153 */
Bob King8a552922020-08-05 17:02:31 +0800154 void monitorSensors(Services& services, System& system);
Bob Kinga2c81a62020-07-08 13:31:16 +0800155
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500156 private:
157 /**
158 * Chassis number within the system.
159 *
160 * Chassis numbers start at 1 because chassis 0 represents the entire
161 * system.
162 */
163 const unsigned int number{};
164
165 /**
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500166 * D-Bus inventory path for this chassis.
167 */
168 const std::string inventoryPath{};
169
170 /**
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500171 * Devices within this chassis, if any.
172 *
173 * The vector contains regulator devices and any related devices
174 * required to perform regulator operations.
175 */
176 std::vector<std::unique_ptr<Device>> devices{};
177};
178
179} // namespace phosphor::power::regulators