Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Geissler | 928bbf1 | 2023-02-14 13:30:14 -0600 | [diff] [blame^] | 3 | #include "utils.hpp" |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 4 | #include "xyz/openbmc_project/State/BMC/server.hpp" |
| 5 | |
Tim Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 6 | #include <linux/watchdog.h> |
| 7 | |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 10 | namespace phosphor |
| 11 | { |
| 12 | namespace state |
| 13 | { |
| 14 | namespace manager |
| 15 | { |
| 16 | |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 17 | using BMCInherit = sdbusplus::server::object_t< |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 18 | sdbusplus::xyz::openbmc_project::State::server::BMC>; |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 19 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 20 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 21 | /** @class BMC |
| 22 | * @brief OpenBMC BMC state management implementation. |
| 23 | * @details A concrete implementation for xyz.openbmc_project.State.BMC |
| 24 | * DBus API. |
| 25 | */ |
Patrick Williams | d32f818 | 2017-05-05 15:55:24 -0500 | [diff] [blame] | 26 | class BMC : public BMCInherit |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 27 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 28 | public: |
| 29 | /** @brief Constructs BMC State Manager |
| 30 | * |
| 31 | * @param[in] bus - The Dbus bus object |
| 32 | * @param[in] busName - The Dbus name to own |
| 33 | * @param[in] objPath - The Dbus object path |
| 34 | */ |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 35 | BMC(sdbusplus::bus_t& bus, const char* objPath) : |
Patrick Williams | 7607074 | 2022-04-05 15:20:12 -0500 | [diff] [blame] | 36 | BMCInherit(bus, objPath, BMCInherit::action::defer_emit), bus(bus), |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 37 | stateSignal(std::make_unique<decltype(stateSignal)::element_type>( |
| 38 | bus, |
| 39 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 40 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 41 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
William A. Kennington III | bd28f02 | 2022-11-22 17:11:49 -0800 | [diff] [blame] | 42 | [this](sdbusplus::message_t& m) { bmcStateChange(m); })) |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 43 | { |
Andrew Geissler | 928bbf1 | 2023-02-14 13:30:14 -0600 | [diff] [blame^] | 44 | utils::subscribeToSystemdSignals(bus); |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 45 | discoverInitialState(); |
Tim Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 46 | discoverLastRebootCause(); |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 47 | this->emit_object_added(); |
| 48 | }; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 49 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 50 | /** @brief Set value of BMCTransition **/ |
| 51 | Transition requestedBMCTransition(Transition value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 52 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 53 | /** @brief Set value of CurrentBMCState **/ |
| 54 | BMCState currentBMCState(BMCState value) override; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 55 | |
Matt Spinler | e6710b7 | 2018-07-12 16:05:55 -0500 | [diff] [blame] | 56 | /** @brief Returns the last time the BMC was rebooted |
| 57 | * |
| 58 | * @details Uses uptime information to determine when |
| 59 | * the BMC was last rebooted. |
| 60 | * |
| 61 | * @return uint64_t - Epoch time, in milliseconds, of the |
| 62 | * last reboot. |
| 63 | */ |
| 64 | uint64_t lastRebootTime() const override; |
| 65 | |
Tim Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 66 | /** @brief Set value of LastRebootCause **/ |
| 67 | RebootCause lastRebootCause(RebootCause value) override; |
| 68 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 69 | private: |
| 70 | /** |
Andrew Geissler | 2774c78 | 2022-02-17 16:57:14 -0600 | [diff] [blame] | 71 | * @brief Retrieve input systemd unit state |
| 72 | **/ |
| 73 | std::string getUnitState(const std::string& unitToCheck); |
| 74 | /** |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 75 | * @brief discover the state of the bmc |
| 76 | **/ |
| 77 | void discoverInitialState(); |
Josh D. King | d3e5847 | 2017-02-02 11:09:11 -0600 | [diff] [blame] | 78 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 79 | /** @brief Execute the transition request |
| 80 | * |
| 81 | * @param[in] tranReq - Transition requested |
| 82 | */ |
| 83 | void executeTransition(Transition tranReq); |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame] | 84 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 85 | /** @brief Callback function on bmc state change |
| 86 | * |
| 87 | * Check if the state is relevant to the BMC and if so, update |
| 88 | * corresponding BMC object's state |
| 89 | * |
| 90 | * @param[in] msg - Data associated with subscribed signal |
| 91 | * |
| 92 | */ |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 93 | int bmcStateChange(sdbusplus::message_t& msg); |
Josh D. King | d613b81 | 2016-12-19 16:47:45 -0600 | [diff] [blame] | 94 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 95 | /** @brief Persistent sdbusplus DBus bus connection. **/ |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 96 | sdbusplus::bus_t& bus; |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 97 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 98 | /** @brief Used to subscribe to dbus system state changes **/ |
| 99 | std::unique_ptr<sdbusplus::bus::match_t> stateSignal; |
Tim Lee | 2bfb1ef | 2021-03-17 09:50:35 +0800 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * @brief discover the last reboot cause of the bmc |
| 103 | **/ |
| 104 | void discoverLastRebootCause(); |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // namespace manager |
| 108 | } // namespace state |
| 109 | } // namespace phosphor |