blob: f52046c2db1171d66ad90f336a7663049da2f0e2 [file] [log] [blame]
Jim Wrightc48551a2022-12-22 15:43:14 -06001#pragma once
2
3#include "pmbus.hpp"
4#include "power_sequencer_monitor.hpp"
5
6#include <sdbusplus/bus.hpp>
7#include <sdbusplus/bus/match.hpp>
8
9#include <cstdint>
10#include <filesystem>
11#include <map>
12#include <string>
13#include <vector>
14
15namespace phosphor::power::sequencer
16{
17
18struct Pin
19{
20 std::string name;
21 unsigned int line;
22 std::string presence;
23};
24
25struct Rail
26{
27 std::string name;
28 std::string presence;
29};
30
31/**
32 * @class UCD90xMonitor
33 * Define a base class for monitoring the UCD90* family of power sequencer
34 * devices.
35 */
36class UCD90xMonitor : public PowerSequencerMonitor
37{
38 public:
39 UCD90xMonitor() = delete;
40 UCD90xMonitor(const UCD90xMonitor&) = delete;
41 UCD90xMonitor& operator=(const UCD90xMonitor&) = delete;
42 UCD90xMonitor(UCD90xMonitor&&) = delete;
43 UCD90xMonitor& operator=(UCD90xMonitor&&) = delete;
44 virtual ~UCD90xMonitor() = default;
45
46 /**
47 * Create a base object for UCD90* monitoring.
48 * @param bus D-Bus bus object
49 * @param i2cBus The bus number of the power sequencer device
50 * @param i2cAddress The I2C address of the power sequencer device
51 * @param deviceName The name of the device
52 * @param numberPages The number of pages the PMBus device supports
53 */
54 UCD90xMonitor(sdbusplus::bus_t& bus, std::uint8_t i2cBus,
55 std::uint16_t i2cAddress, const std::string& deviceName,
56 size_t numberPages);
57
58 /**
59 * Callback function to handle interfacesAdded D-Bus signals
60 * @param msg Expanded sdbusplus message data
61 */
62 void interfacesAddedHandler(sdbusplus::message_t& msg);
63
64 /** @copydoc PowerSequencerMonitor::onFailure() */
65 void onFailure(bool timeout, const std::string& powerSupplyError) override;
66
67 protected:
68 /**
69 * Formats the GPIO values read from the device.
70 * @param values List of GPIO values
71 * @param numberLines Number of GPIO lines
72 * @param additionalData AdditionalData property of the error log entry
73 */
74 virtual void formatGpioValues(
75 const std::vector<int>& values, unsigned int numberLines,
76 std::map<std::string, std::string>& additionalData) const;
77
78 private:
79 /**
80 * Device name
81 */
82 std::string deviceName;
83
84 /**
85 * The match to Entity Manager interfaces added.
86 */
87 sdbusplus::bus::match_t match;
88
89 /**
90 * The number of pages the PMBus device supports
91 */
92 size_t numberPages;
93
94 /**
95 * List of pins
96 */
97 std::vector<Pin> pins;
98
99 /**
100 * The read/write interface to this hardware
101 */
102 pmbus::PMBus pmbusInterface;
103
104 /**
105 * List of rails
106 */
107 std::vector<Rail> rails;
108
109 /**
110 * Finds the list of compatible system types using D-Bus methods.
111 * This list is used to find the correct JSON configuration file for the
112 * current system.
113 */
114 void findCompatibleSystemTypes();
115
116 /**
117 * Finds the JSON configuration file.
118 * Looks for a configuration file based on the list of compatible system
119 * types.
120 * Throws an exception if an operating system error occurs while checking
121 * for the existance of a file.
122 * @param compatibleSystemTypes List of compatible system types
123 */
124 void findConfigFile(const std::vector<std::string>& compatibleSystemTypes);
125
126 /**
127 * Returns whether the hardware with the specified inventory path is
128 * present.
129 * If an error occurs while obtaining the presence value, presence is
130 * assumed to be false. An empty string path indicates no presence check is
131 * needed.
132 * @param inventoryPath D-Bus inventory path of the hardware
133 * @return true if hardware is present, false otherwise
134 */
135 bool isPresent(const std::string& inventoryPath);
136
137 /**
138 * Analyzes the device pins for errors when the device is known to be in an
139 * error state.
140 * @param message Message property of the error log entry
141 * @param additionalData AdditionalData property of the error log entry
142 */
143 void onFailureCheckPins(std::string& message,
144 std::map<std::string, std::string>& additionalData);
145
146 /**
147 * Analyzes the device rails for errors when the device is known to be in an
148 * error state.
149 * @param message Message property of the error log entry
150 * @param additionalData AdditionalData property of the error log entry
151 * @param powerSupplyError The power supply error to log. A default
152 * std:string, i.e. empty string (""), is passed when there is no power
153 * supply error to log.
154 */
155 void onFailureCheckRails(std::string& message,
156 std::map<std::string, std::string>& additionalData,
157 const std::string& powerSupplyError);
158
159 /**
160 * Parse the JSON configuration file.
161 * @param pathName the path name
162 */
163 void parseConfigFile(const std::filesystem::path& pathName);
164
165 /**
166 * Reads the mfr_status register
167 * @return the register contents
168 */
169 uint64_t readMFRStatus();
170
171 /**
172 * Reads the status_word register
173 * @return the register contents
174 */
175 uint16_t readStatusWord();
176};
177
178} // namespace phosphor::power::sequencer