blob: 6c1a55446ad084249752ec22cf2c4e652a1fa1c6 [file] [log] [blame]
Ben Tyner324234b2021-06-28 17:01:17 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
Ben Tyner13159682022-02-16 14:55:38 -06004#include <util/ffdc_file.hpp>
Ben Tyner324234b2021-06-28 17:01:17 -05005
6#include <string>
7#include <variant>
8#include <vector>
9
10namespace util
11{
Ben Tyner324234b2021-06-28 17:01:17 -050012namespace dbus
13{
Ben Tyner324234b2021-06-28 17:01:17 -050014using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>,
Ben Tyner2b26b2b2022-12-15 15:42:02 -060015 std::vector<std::string>, int32_t>;
Ben Tyner324234b2021-06-28 17:01:17 -050016using DBusProperty = std::string;
17using DBusInterface = std::string;
18using DBusService = std::string;
19using DBusPath = std::string;
20using DBusInterfaceList = std::vector<DBusInterface>;
21using DBusSubTree =
22 std::map<DBusPath, std::map<DBusService, DBusInterfaceList>>;
23
24/**
25 * Find the dbus object path and service that implements the given interface
26 *
27 * @param[in] i_interface Interface to search for
28 * @param[out] o_path Path of dbus object implementing the interface
29 * @param[out] o_service Service implementing the dbus object path
30 * @return non-zero on error
31 */
32int find(const std::string& i_interface, std::string& o_path,
33 std::string& o_service);
34
35/**
36 * Find the dbus service that implements the given dbus object and interface
37 *
38 * @param[in] i_interface Interface that maps to the service
39 * @param[in] i_path Path that maps to the service
40 * @param[out] o_service Service implementing the dbus object and interface
41 * @return non-zer on error
42 */
43int findService(const std::string& i_interface, const std::string& i_path,
44 std::string& o_service);
45
46/**
47 * Read a property from a dbus object interface
48 *
49 * @param[in] i_interface Interface implementing the property
50 * @param[in] i_path Path of the dbus object
51 * @param[in] i_service Service implementing the dbus object and interface
52 * @param[in] i_property Property to read
53 * @return non-zero on error
54 */
55int getProperty(const std::string& i_interface, const std::string& i_path,
56 const std::string& i_service, const std::string& i_property,
57 DBusValue& o_response);
58
59/**
60 * Get the IBM compatible names defined for this system
61 *
62 * @return A vector of strings containing the system names
63 */
64std::vector<std::string> systemNames();
65
Ben Tynerfe2c50d2021-07-23 13:38:53 -050066/** @brief Host transition states for host transition operations */
Ben Tyner93067162021-07-23 10:39:30 -050067enum class HostState
68{
69 Quiesce,
70 Diagnostic,
71 Crash
72};
73
74/**
75 * @brief Transition the host state
76 *
77 * We will transition the host state by starting the appropriate dbus target.
78 *
79 * @param i_hostState the state to transition the host to
80 */
81void transitionHost(const HostState i_hostState);
82
Ben Tynerffb48672021-07-23 12:29:03 -050083/**
Ben Tyner39fcf652021-10-19 20:38:29 -050084 * @brief Read autoRebootEnabled property
Ben Tynerffb48672021-07-23 12:29:03 -050085 *
Ben Tyner39fcf652021-10-19 20:38:29 -050086 * @return false if autoRebootEnabled policy false, else true
Ben Tynerffb48672021-07-23 12:29:03 -050087 */
88bool autoRebootEnabled();
89
Ben Tynerfe2c50d2021-07-23 13:38:53 -050090/** @brief Host running states for host running operations */
91enum class HostRunningState
92{
93 Unknown,
94 NotStarted,
95 Started
96};
97
98/**
99 * Get the host running state
100 *
101 * Use host boot progress to determine if a host has been started. If host
102 * boot progress can not be determined then host state will be unknown.
103 *
104 * @return HostType == "Unknown", "Started or "NotStarted"
105 */
106HostRunningState hostRunningState();
107
Ben Tyner39fcf652021-10-19 20:38:29 -0500108/**
109 * @brief Read dumpPolicyEnabled property
110 *
111 * @return false if dumpPolicyEnabled property is false, else true
112 */
113bool dumpPolicyEnabled();
114
Ben Tyner13159682022-02-16 14:55:38 -0600115/**
116 * Create a PEL
117 *
118 * The additional data provided in the map will be placed in a user data
119 * section of the PEL and may additionally contain key words to trigger
120 * certain behaviors by the backend logging code. Each set of data described
121 * in the vector of ffdc data will be placed in additional user data
122 * sections. Note that the PID of the caller will be added to the additional
123 * data map with key "_PID".
124 *
125 * @param i_message - the event type
126 * @param i_severity - the severity level
127 * @param io_additional - map of additional data
128 * @param i_ffdc - vector of ffdc data
129 * @return Platform log id or 0 if error
130 */
131uint32_t createPel(const std::string& i_message, const std::string& i_severity,
132 std::map<std::string, std::string>& io_additional,
133 const std::vector<FFDCTuple>& i_ffdc);
134
Caleb Palmer626270a2022-02-21 11:05:08 -0600135/** @brief Machine ID definitions */
136enum class MachineType
137{
138 Rainier_2S4U,
139 Rainier_2S2U,
140 Rainier_1S4U,
141 Rainier_1S2U,
142 Everest,
143};
144
145/**
146 * @brief Read the System IM keyword to get the machine type
147 *
148 * @return An enum representing the machine type
149 */
150MachineType getMachineType();
151
Ben Tyner88b10092022-12-14 20:43:50 -0600152/** @brief Get list of state sensor PDRs
153 *
154 * @param[out] pdrList - list of PDRs
155 * @param[in] stateSetId - ID of the state set of interest
156 *
157 * @return true if successful otherwise false
158 */
159bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList,
160 uint16_t stateSetId);
Ben Tyner324234b2021-06-28 17:01:17 -0500161
Ben Tyner88b10092022-12-14 20:43:50 -0600162/** @brief Get list of state effecter PDRs
163 *
164 * @param[out] pdrList - list of PDRs
165 * @param[in] stateSetId - ID of the state set of interest
166 *
167 * @return true if successful otherwise false
168 */
169bool getStateEffecterPdrs(std::vector<std::vector<uint8_t>>& pdrList,
170 uint16_t stateSetId);
171
172/**
173 * @brief Get MCTP instance ID associated with endpoint
174 *
175 * @param[out] mctpInstance - instance of MCTP
176 * @param[in] Eid - MCTP enpoint ID
177 *
178 * @return True on success otherwise False
179 */
180bool getMctpInstance(uint8_t& mctpInstance, uint8_t Eid);
181
Ben Tyner2b26b2b2022-12-15 15:42:02 -0600182/**
183 * @brief Determine if power fault was detected
184 *
185 * @return true if power fault or unknown, false otherwise
186 */
187bool powerFault();
188
Ben Tyner88b10092022-12-14 20:43:50 -0600189} // namespace dbus
Ben Tyner324234b2021-06-28 17:01:17 -0500190} // namespace util