Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 3 | #include "xyz/openbmc_project/State/BMC/server.hpp" |
| 4 | |
Tim Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 5 | #include <linux/watchdog.h> |
| 6 | |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
| 8 | |
| 9 | #include <functional> |
| 10 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 11 | namespace phosphor |
| 12 | { |
| 13 | namespace state |
| 14 | { |
| 15 | namespace manager |
| 16 | { |
| 17 | |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 18 | using BMCInherit = sdbusplus::server::object::object< |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 19 | sdbusplus::xyz::openbmc_project::State::server::BMC>; |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 20 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 21 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 22 | /** @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 Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 27 | class BMC : public BMCInherit |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 28 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 29 | 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 Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 48 | discoverLastRebootCause(); |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 49 | this->emit_object_added(); |
| 50 | }; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 51 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 52 | /** @brief Set value of BMCTransition **/ |
| 53 | Transition requestedBMCTransition(Transition value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 54 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 55 | /** @brief Set value of CurrentBMCState **/ |
| 56 | BMCState currentBMCState(BMCState value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 57 | |
Matt Spinler | e6710b7 | 2018-07-12 16:05:55 -0500 | [diff] [blame] | 58 | /** @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 Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 68 | /** @brief Set value of LastRebootCause **/ |
| 69 | RebootCause lastRebootCause(RebootCause value) override; |
| 70 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 71 | private: |
| 72 | /** |
| 73 | * @brief discover the state of the bmc |
| 74 | **/ |
| 75 | void discoverInitialState(); |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame] | 76 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 77 | /** |
| 78 | * @brief subscribe to the systemd signals |
| 79 | **/ |
| 80 | void subscribeToSystemdSignals(); |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 81 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 82 | /** @brief Execute the transition request |
| 83 | * |
| 84 | * @param[in] tranReq - Transition requested |
| 85 | */ |
| 86 | void executeTransition(Transition tranReq); |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame] | 87 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 88 | /** @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. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 97 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 98 | /** @brief Persistent sdbusplus DBus bus connection. **/ |
| 99 | sdbusplus::bus::bus& bus; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 100 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 101 | /** @brief Used to subscribe to dbus system state changes **/ |
| 102 | std::unique_ptr<sdbusplus::bus::match_t> stateSignal; |
Tim Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * @brief discover the last reboot cause of the bmc |
| 106 | **/ |
| 107 | void discoverLastRebootCause(); |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } // namespace manager |
| 111 | } // namespace state |
| 112 | } // namespace phosphor |