blob: 54ce58a5abded6cb01af6c388bb25f3c8edfa99a [file] [log] [blame]
Carol Wangdc059392020-03-13 17:39:17 +08001#pragma once
2
Thang Tran9f381522024-10-18 10:11:01 +07003#include "config.h"
4
Carol Wangdc059392020-03-13 17:39:17 +08005#include <sdbusplus/bus.hpp>
Andrew Geissler9d4d0c92022-01-26 13:18:12 -06006#include <xyz/openbmc_project/Logging/Entry/server.hpp>
Carol Wangdc059392020-03-13 17:39:17 +08007
8namespace phosphor
9{
10namespace state
11{
12namespace manager
13{
14namespace utils
15{
16
Andrew Geissler928bbf12023-02-14 13:30:14 -060017/** @brief Tell systemd to generate d-bus events
18 *
19 * @param[in] bus - The Dbus bus object
20 *
21 * @return void, will throw exception on failure
22 */
Patrick Williams5c4a0822023-02-28 02:40:35 -060023void subscribeToSystemdSignals(sdbusplus::bus_t& bus);
Andrew Geissler928bbf12023-02-14 13:30:14 -060024
Carol Wangdc059392020-03-13 17:39:17 +080025/** @brief Get service name from object path and interface
26 *
27 * @param[in] bus - The Dbus bus object
28 * @param[in] path - The Dbus object path
29 * @param[in] interface - The Dbus interface
30 *
31 * @return The name of the service
32 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050033std::string getService(sdbusplus::bus_t& bus, std::string path,
Carol Wangdc059392020-03-13 17:39:17 +080034 std::string interface);
35
Andrew Geissler49e67132022-01-26 14:27:52 -060036/** @brief Get the value of input property
37 *
38 * @param[in] bus - The Dbus bus object
39 * @param[in] path - The Dbus object path
40 * @param[in] interface - The Dbus interface
41 * @param[in] property - The property name to get
42 *
43 * @return The value of the property
44 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050045std::string getProperty(sdbusplus::bus_t& bus, const std::string& path,
Andrew Geissler49e67132022-01-26 14:27:52 -060046 const std::string& interface,
47 const std::string& propertyName);
48
Carol Wangdc059392020-03-13 17:39:17 +080049/** @brief Set the value of property
50 *
51 * @param[in] bus - The Dbus bus object
52 * @param[in] path - The Dbus object path
53 * @param[in] interface - The Dbus interface
54 * @param[in] property - The property name to set
55 * @param[in] value - The value of property
56 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050057void setProperty(sdbusplus::bus_t& bus, const std::string& path,
Carol Wangdc059392020-03-13 17:39:17 +080058 const std::string& interface, const std::string& property,
59 const std::string& value);
60
Andrew Geisslerf8ae6a02022-01-21 17:00:20 -060061/** @brief Return the value of the input GPIO
62 *
63 * @param[in] gpioName - The name of the GPIO to read
64 *
65 * * @return The value of the gpio (0 or 1) or -1 on error
66 */
67int getGpioValue(const std::string& gpioName);
68
Andrew Geissler9d4d0c92022-01-26 13:18:12 -060069/** @brief Create an error log
70 *
Andrew Geisslerd49f51e2022-03-07 14:57:07 -060071 * @param[in] bus - The Dbus bus object
72 * @param[in] errorMsg - The error message
73 * @param[in] errLevel - The error level
74 * parampin] additionalData - Optional extra data to add to the log
Andrew Geissler9d4d0c92022-01-26 13:18:12 -060075 */
76void createError(
Patrick Williamsf053e6f2022-07-22 19:26:54 -050077 sdbusplus::bus_t& bus, const std::string& errorMsg,
Patrick Williams7e969cb2023-08-23 16:24:23 -050078 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level errLevel,
Andrew Geisslerd49f51e2022-03-07 14:57:07 -060079 std::map<std::string, std::string> additionalData = {});
Andrew Geissler9d4d0c92022-01-26 13:18:12 -060080
Andrew Geissler55e96ac2022-04-19 11:44:53 -040081/** @brief Call phosphor-dump-manager to create BMC user dump
82 *
83 * @param[in] bus - The Dbus bus object
84 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050085void createBmcDump(sdbusplus::bus_t& bus);
Andrew Geissler55e96ac2022-04-19 11:44:53 -040086
NodeMan9727d1e142022-07-27 15:10:07 -050087/** @brief Attempt to locate the obmc-chassis-lost-power@ file
Manojkiran Eda3ff5a362024-06-17 10:59:07 +053088 * to indicate that an AC loss occurred.
NodeMan9727d1e142022-07-27 15:10:07 -050089 *
90 * @param[in] chassisId - the chassis instance
91 */
92bool checkACLoss(size_t& chassisId);
93
Andrew Geisslerfc1020f2023-05-24 17:07:38 -040094/** @brief Determine if the BMC is at its Ready state
95 *
96 * @param[in] bus - The Dbus bus object
97 */
98bool isBmcReady(sdbusplus::bus_t& bus);
99
Potin Lai08865452023-11-07 23:28:11 +0800100/** @brief Wait BMC to enter ready state or timeout reached.
101 *
102 * @param[in] bus - The Dbus bus object
103 * @param[in] timeout - Timeout in second
104 */
105bool waitBmcReady(sdbusplus::bus_t& bus, std::chrono::seconds timeout);
106
Thang Tran9f381522024-10-18 10:11:01 +0700107#ifdef CHECK_FWUPDATE_BEFORE_DO_TRANSITION
108/** @brief Determine if any firmware being updated
109 *
110 * @param[in] bus - The Dbus bus object
111 */
112bool isFirmwareUpdating(sdbusplus::bus_t& bus);
113#endif // CHECK_FWUPDATE_BEFORE_DO_TRANSITION
114
Carol Wangdc059392020-03-13 17:39:17 +0800115} // namespace utils
116} // namespace manager
117} // namespace state
Andrew Geisslerf8ae6a02022-01-21 17:00:20 -0600118} // namespace phosphor