blob: a194d2eb4f9b2bb4cb6ce0a49bf3c56b1dfc264e [file] [log] [blame]
Matt Spinler70849272017-08-22 09:14:40 -05001#pragma once
2
Matt Spinlerf0f02b92018-10-25 16:12:43 -05003#include "device.hpp"
4#include "device_monitor.hpp"
5
Matt Spinler70849272017-08-22 09:14:40 -05006#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server.hpp>
William A. Kennington IIIe5a8b472018-10-18 00:40:04 -07008#include <sdeventplus/event.hpp>
Matt Spinler70849272017-08-22 09:14:40 -05009
Lei YUab093322019-10-09 16:43:22 +080010namespace phosphor
Matt Spinler70849272017-08-22 09:14:40 -050011{
12namespace power
13{
14
15/**
16 * @class RuntimeMonitor
17 *
18 * Monitors the power sequencer for faults at runtime
19 *
20 * Triggers the power sequencer fault check 2 different ways:
21 *
22 * 1) Listens for the PowerLost signal that indicates master
23 * PGOOD was dropped due to a fatal fault. After the analysis,
24 * a power off will be issued so the sequencer will stop
25 * driving power to a faulted component.
26 *
27 * 2) Polls for faults, as some won't always drop PGOOD.
28 *
29 * The application this runs in will only run while PGOOD is
30 * expected to be asserted, so any loss of PGOOD is considered
31 * an error.
32 */
33class RuntimeMonitor : public DeviceMonitor
34{
Matt Spinlerf0f02b92018-10-25 16:12:43 -050035 public:
36 RuntimeMonitor() = delete;
37 ~RuntimeMonitor() = default;
38 RuntimeMonitor(const RuntimeMonitor&) = delete;
39 RuntimeMonitor& operator=(const RuntimeMonitor&) = delete;
40 RuntimeMonitor(RuntimeMonitor&&) = delete;
41 RuntimeMonitor& operator=(RuntimeMonitor&&) = delete;
Matt Spinler70849272017-08-22 09:14:40 -050042
Matt Spinlerf0f02b92018-10-25 16:12:43 -050043 /**
44 * Constructor
45 *
46 * @param[in] d - the device to monitor
47 * @param[in] b - D-Bus bus object
48 * @param[in] e - event object
49 * @param[in] i - poll interval
50 */
Lei YUab093322019-10-09 16:43:22 +080051 RuntimeMonitor(std::unique_ptr<phosphor::power::Device>&& d,
Patrick Williams7354ce62022-07-22 19:26:56 -050052 sdbusplus::bus_t& b, const sdeventplus::Event& e,
Matt Spinlerf0f02b92018-10-25 16:12:43 -050053 std::chrono::milliseconds& i) :
54 DeviceMonitor(std::move(d), e, i),
55 bus(b), match(bus, getMatchString(),
56 std::bind(std::mem_fn(&RuntimeMonitor::onPowerLost), this,
57 std::placeholders::_1))
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000058 {}
Matt Spinler70849272017-08-22 09:14:40 -050059
Matt Spinlerf0f02b92018-10-25 16:12:43 -050060 /**
61 * Clears faults and then runs DeviceMonitor::run to
62 * call Device::analyze() on an ongoing interval.
63 *
64 * @return the return value from sd_event_loop()
65 */
66 int run() override;
Matt Spinler70849272017-08-22 09:14:40 -050067
Matt Spinlerf0f02b92018-10-25 16:12:43 -050068 private:
69 /**
70 * The PowerLost signal handler.
71 *
72 * After doing an analysis, will issue a power off
73 * as some device has a power fault and needs to be
74 * properly shut down.
75 *
76 * @param[in] msg - D-Bus message for callback
77 */
Patrick Williams7354ce62022-07-22 19:26:56 -050078 void onPowerLost(sdbusplus::message_t& msg);
Matt Spinler70849272017-08-22 09:14:40 -050079
Matt Spinlerf0f02b92018-10-25 16:12:43 -050080 /**
81 * Returns the match string for the PowerLost signal
82 */
83 std::string getMatchString()
84 {
85 using namespace sdbusplus::bus::match::rules;
Matt Spinler70849272017-08-22 09:14:40 -050086
Matt Spinlerf0f02b92018-10-25 16:12:43 -050087 std::string s = type::signal() + path("/org/openbmc/control/power0") +
88 interface("org.openbmc.control.Power") +
89 member("PowerLost");
Matt Spinler70849272017-08-22 09:14:40 -050090
Matt Spinlerf0f02b92018-10-25 16:12:43 -050091 return s;
92 }
Matt Spinler70849272017-08-22 09:14:40 -050093
Matt Spinlerf0f02b92018-10-25 16:12:43 -050094 /**
95 * The D-Bus object
96 */
Patrick Williams7354ce62022-07-22 19:26:56 -050097 sdbusplus::bus_t& bus;
Matt Spinler70849272017-08-22 09:14:40 -050098
Matt Spinlerf0f02b92018-10-25 16:12:43 -050099 /**
100 * Match object for PowerLost signals
101 */
102 sdbusplus::bus::match_t match;
Matt Spinler70849272017-08-22 09:14:40 -0500103};
104
Matt Spinlerf0f02b92018-10-25 16:12:43 -0500105} // namespace power
Lei YUab093322019-10-09 16:43:22 +0800106} // namespace phosphor