blob: 3fd379235beba3707a9573509e3f36b05e90e7da [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"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050020
21#include <memory>
22#include <stdexcept>
23#include <string>
24#include <utility>
25#include <vector>
26
27namespace phosphor::power::regulators
28{
29
Shawn McCarney525e20c2020-04-14 11:05:39 -050030// Forward declarations to avoid circular dependencies
31class System;
32
Shawn McCarney8a3afd72020-03-12 14:28:44 -050033/**
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 */
45class 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 McCarneydb0b8332020-04-06 14:13:04 -050081 * 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 McCarney050531f2020-06-02 14:17:12 -050088 * Close the devices within this chassis, if any.
89 */
90 void closeDevices();
91
92 /**
Shawn McCarney525e20c2020-04-14 11:05:39 -050093 * 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 McCarney8a3afd72020-03-12 14:28:44 -0500103 * 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