blob: 4ea97840ddb6661bb7614de5acb34e115560eef1 [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
9#include <functional>
10
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060011namespace phosphor
12{
13namespace state
14{
15namespace manager
16{
17
Patrick Williamsd32f8182017-05-05 15:55:24 -050018using BMCInherit = sdbusplus::server::object::object<
Andrew Geissler58a18012018-01-19 19:36:05 -080019 sdbusplus::xyz::openbmc_project::State::server::BMC>;
Patrick Williamsd32f8182017-05-05 15:55:24 -050020namespace sdbusRule = sdbusplus::bus::match::rules;
21
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060022/** @class BMC
23 * @brief OpenBMC BMC state management implementation.
24 * @details A concrete implementation for xyz.openbmc_project.State.BMC
25 * DBus API.
26 */
Patrick Williamsd32f8182017-05-05 15:55:24 -050027class BMC : public BMCInherit
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060028{
Andrew Geissler58a18012018-01-19 19:36:05 -080029 public:
30 /** @brief Constructs BMC State Manager
31 *
32 * @param[in] bus - The Dbus bus object
33 * @param[in] busName - The Dbus name to own
34 * @param[in] objPath - The Dbus object path
35 */
36 BMC(sdbusplus::bus::bus& bus, const char* objPath) :
37 BMCInherit(bus, objPath, true), bus(bus),
38 stateSignal(std::make_unique<decltype(stateSignal)::element_type>(
39 bus,
40 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
41 sdbusRule::path("/org/freedesktop/systemd1") +
42 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
43 std::bind(std::mem_fn(&BMC::bmcStateChange), this,
44 std::placeholders::_1)))
45 {
46 subscribeToSystemdSignals();
47 discoverInitialState();
Tim Lee2bfb1ef2021-03-17 09:50:35 +080048 discoverLastRebootCause();
Andrew Geissler58a18012018-01-19 19:36:05 -080049 this->emit_object_added();
50 };
Josh D. King6db38222016-12-19 14:52:40 -060051
Andrew Geissler58a18012018-01-19 19:36:05 -080052 /** @brief Set value of BMCTransition **/
53 Transition requestedBMCTransition(Transition value) override;
Josh D. King6db38222016-12-19 14:52:40 -060054
Andrew Geissler58a18012018-01-19 19:36:05 -080055 /** @brief Set value of CurrentBMCState **/
56 BMCState currentBMCState(BMCState value) override;
Josh D. King6db38222016-12-19 14:52:40 -060057
Matt Spinlere6710b72018-07-12 16:05:55 -050058 /** @brief Returns the last time the BMC was rebooted
59 *
60 * @details Uses uptime information to determine when
61 * the BMC was last rebooted.
62 *
63 * @return uint64_t - Epoch time, in milliseconds, of the
64 * last reboot.
65 */
66 uint64_t lastRebootTime() const override;
67
Tim Lee2bfb1ef2021-03-17 09:50:35 +080068 /** @brief Set value of LastRebootCause **/
69 RebootCause lastRebootCause(RebootCause value) override;
70
Andrew Geissler58a18012018-01-19 19:36:05 -080071 private:
72 /**
73 * @brief discover the state of the bmc
74 **/
75 void discoverInitialState();
Josh D. Kingd3e58472017-02-02 11:09:11 -060076
Andrew Geissler58a18012018-01-19 19:36:05 -080077 /**
78 * @brief subscribe to the systemd signals
79 **/
80 void subscribeToSystemdSignals();
Josh D. King6db38222016-12-19 14:52:40 -060081
Andrew Geissler58a18012018-01-19 19:36:05 -080082 /** @brief Execute the transition request
83 *
84 * @param[in] tranReq - Transition requested
85 */
86 void executeTransition(Transition tranReq);
Josh D. King5162a7b2016-12-19 16:15:00 -060087
Andrew Geissler58a18012018-01-19 19:36:05 -080088 /** @brief Callback function on bmc state change
89 *
90 * Check if the state is relevant to the BMC and if so, update
91 * corresponding BMC object's state
92 *
93 * @param[in] msg - Data associated with subscribed signal
94 *
95 */
96 int bmcStateChange(sdbusplus::message::message& msg);
Josh D. Kingd613b812016-12-19 16:47:45 -060097
Andrew Geissler58a18012018-01-19 19:36:05 -080098 /** @brief Persistent sdbusplus DBus bus connection. **/
99 sdbusplus::bus::bus& bus;
Josh D. King6db38222016-12-19 14:52:40 -0600100
Andrew Geissler58a18012018-01-19 19:36:05 -0800101 /** @brief Used to subscribe to dbus system state changes **/
102 std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
Tim Lee2bfb1ef2021-03-17 09:50:35 +0800103
104 /**
105 * @brief discover the last reboot cause of the bmc
106 **/
107 void discoverLastRebootCause();
Josh D. Kingbdd9cb72016-12-19 11:13:43 -0600108};
109
110} // namespace manager
111} // namespace state
112} // namespace phosphor