blob: 5a6febc4f788078fa94b21c3019eb243ff4a3f94 [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,
Matt Spinlerf0f02b92018-10-25 16:12:43 -050052 sdbusplus::bus::bus& b, const sdeventplus::Event& e,
53 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))
58 {
59 }
Matt Spinler70849272017-08-22 09:14:40 -050060
Matt Spinlerf0f02b92018-10-25 16:12:43 -050061 /**
62 * Clears faults and then runs DeviceMonitor::run to
63 * call Device::analyze() on an ongoing interval.
64 *
65 * @return the return value from sd_event_loop()
66 */
67 int run() override;
Matt Spinler70849272017-08-22 09:14:40 -050068
Matt Spinlerf0f02b92018-10-25 16:12:43 -050069 private:
70 /**
71 * The PowerLost signal handler.
72 *
73 * After doing an analysis, will issue a power off
74 * as some device has a power fault and needs to be
75 * properly shut down.
76 *
77 * @param[in] msg - D-Bus message for callback
78 */
79 void onPowerLost(sdbusplus::message::message& msg);
Matt Spinler70849272017-08-22 09:14:40 -050080
Matt Spinlerf0f02b92018-10-25 16:12:43 -050081 /**
82 * Returns the match string for the PowerLost signal
83 */
84 std::string getMatchString()
85 {
86 using namespace sdbusplus::bus::match::rules;
Matt Spinler70849272017-08-22 09:14:40 -050087
Matt Spinlerf0f02b92018-10-25 16:12:43 -050088 std::string s = type::signal() + path("/org/openbmc/control/power0") +
89 interface("org.openbmc.control.Power") +
90 member("PowerLost");
Matt Spinler70849272017-08-22 09:14:40 -050091
Matt Spinlerf0f02b92018-10-25 16:12:43 -050092 return s;
93 }
Matt Spinler70849272017-08-22 09:14:40 -050094
Matt Spinlerf0f02b92018-10-25 16:12:43 -050095 /**
96 * The D-Bus object
97 */
98 sdbusplus::bus::bus& bus;
Matt Spinler70849272017-08-22 09:14:40 -050099
Matt Spinlerf0f02b92018-10-25 16:12:43 -0500100 /**
101 * Match object for PowerLost signals
102 */
103 sdbusplus::bus::match_t match;
Matt Spinler70849272017-08-22 09:14:40 -0500104};
105
Matt Spinlerf0f02b92018-10-25 16:12:43 -0500106} // namespace power
Lei YUab093322019-10-09 16:43:22 +0800107} // namespace phosphor