blob: 29e318fecf780911668a33ba62cfe25a0eac433d [file] [log] [blame]
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06001#pragma once
2
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06003#include "xyz/openbmc_project/State/BMC/server.hpp"
4
Tim Lee2bfb1ef2021-03-17 09:50:35 +08005#include <linux/watchdog.h>
6
Andrew Geisslere426b582020-05-28 12:40:55 -05007#include <sdbusplus/bus.hpp>
8
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06009namespace phosphor
10{
11namespace state
12{
13namespace manager
14{
15
Patrick Williamsf053e6f2022-07-22 19:26:54 -050016using BMCInherit = sdbusplus::server::object_t<
Andrew Geissler58a18012018-01-19 19:36:05 -080017 sdbusplus::xyz::openbmc_project::State::server::BMC>;
Patrick Williamsd32f8182017-05-05 15:55:24 -050018namespace sdbusRule = sdbusplus::bus::match::rules;
19
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060020/** @class BMC
21 * @brief OpenBMC BMC state management implementation.
22 * @details A concrete implementation for xyz.openbmc_project.State.BMC
23 * DBus API.
24 */
Patrick Williamsd32f8182017-05-05 15:55:24 -050025class BMC : public BMCInherit
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060026{
Andrew Geissler58a18012018-01-19 19:36:05 -080027 public:
28 /** @brief Constructs BMC State Manager
29 *
30 * @param[in] bus - The Dbus bus object
31 * @param[in] busName - The Dbus name to own
32 * @param[in] objPath - The Dbus object path
33 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050034 BMC(sdbusplus::bus_t& bus, const char* objPath) :
Patrick Williams76070742022-04-05 15:20:12 -050035 BMCInherit(bus, objPath, BMCInherit::action::defer_emit), bus(bus),
Andrew Geissler58a18012018-01-19 19:36:05 -080036 stateSignal(std::make_unique<decltype(stateSignal)::element_type>(
37 bus,
38 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
39 sdbusRule::path("/org/freedesktop/systemd1") +
40 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
William A. Kennington IIIbd28f022022-11-22 17:11:49 -080041 [this](sdbusplus::message_t& m) { bmcStateChange(m); }))
Andrew Geissler58a18012018-01-19 19:36:05 -080042 {
43 subscribeToSystemdSignals();
44 discoverInitialState();
Tim Lee2bfb1ef2021-03-17 09:50:35 +080045 discoverLastRebootCause();
Andrew Geissler58a18012018-01-19 19:36:05 -080046 this->emit_object_added();
47 };
Josh D. King6db38222016-12-19 14:52:40 -060048
Andrew Geissler58a18012018-01-19 19:36:05 -080049 /** @brief Set value of BMCTransition **/
50 Transition requestedBMCTransition(Transition value) override;
Josh D. King6db38222016-12-19 14:52:40 -060051
Andrew Geissler58a18012018-01-19 19:36:05 -080052 /** @brief Set value of CurrentBMCState **/
53 BMCState currentBMCState(BMCState value) override;
Josh D. King6db38222016-12-19 14:52:40 -060054
Matt Spinlere6710b72018-07-12 16:05:55 -050055 /** @brief Returns the last time the BMC was rebooted
56 *
57 * @details Uses uptime information to determine when
58 * the BMC was last rebooted.
59 *
60 * @return uint64_t - Epoch time, in milliseconds, of the
61 * last reboot.
62 */
63 uint64_t lastRebootTime() const override;
64
Tim Lee2bfb1ef2021-03-17 09:50:35 +080065 /** @brief Set value of LastRebootCause **/
66 RebootCause lastRebootCause(RebootCause value) override;
67
Andrew Geissler58a18012018-01-19 19:36:05 -080068 private:
69 /**
Andrew Geissler2774c782022-02-17 16:57:14 -060070 * @brief Retrieve input systemd unit state
71 **/
72 std::string getUnitState(const std::string& unitToCheck);
73 /**
Andrew Geissler58a18012018-01-19 19:36:05 -080074 * @brief discover the state of the bmc
75 **/
76 void discoverInitialState();
Josh D. Kingd3e58472017-02-02 11:09:11 -060077
Andrew Geissler58a18012018-01-19 19:36:05 -080078 /**
79 * @brief subscribe to the systemd signals
80 **/
81 void subscribeToSystemdSignals();
Josh D. King6db38222016-12-19 14:52:40 -060082
Andrew Geissler58a18012018-01-19 19:36:05 -080083 /** @brief Execute the transition request
84 *
85 * @param[in] tranReq - Transition requested
86 */
87 void executeTransition(Transition tranReq);
Josh D. King5162a7b2016-12-19 16:15:00 -060088
Andrew Geissler58a18012018-01-19 19:36:05 -080089 /** @brief Callback function on bmc state change
90 *
91 * Check if the state is relevant to the BMC and if so, update
92 * corresponding BMC object's state
93 *
94 * @param[in] msg - Data associated with subscribed signal
95 *
96 */
Patrick Williamsf053e6f2022-07-22 19:26:54 -050097 int bmcStateChange(sdbusplus::message_t& msg);
Josh D. Kingd613b812016-12-19 16:47:45 -060098
Andrew Geissler58a18012018-01-19 19:36:05 -080099 /** @brief Persistent sdbusplus DBus bus connection. **/
Patrick Williamsf053e6f2022-07-22 19:26:54 -0500100 sdbusplus::bus_t& bus;
Josh D. King6db38222016-12-19 14:52:40 -0600101
Andrew Geissler58a18012018-01-19 19:36:05 -0800102 /** @brief Used to subscribe to dbus system state changes **/
103 std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
Tim Lee2bfb1ef2021-03-17 09:50:35 +0800104
105 /**
106 * @brief discover the last reboot cause of the bmc
107 **/
108 void discoverLastRebootCause();
Josh D. Kingbdd9cb72016-12-19 11:13:43 -0600109};
110
111} // namespace manager
112} // namespace state
113} // namespace phosphor