1 #pragma once
2 
3 #include "device.hpp"
4 #include "device_monitor.hpp"
5 
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/server.hpp>
8 #include <sdeventplus/event.hpp>
9 
10 namespace phosphor
11 {
12 namespace power
13 {
14 
15 /**
16  * @class PGOODMonitor
17  *
18  * Monitors PGOOD and checks for errors on the power sequencer
19  * if it doesn't come on in time.
20  *
21  * The run() function is designed to be called right after the
22  * power sequencer device is told to kick off a power on.
23  *
24  * Future commits will analyze the power sequencer chip for errors
25  * on a PGOOD fail.
26  */
27 class PGOODMonitor : public DeviceMonitor
28 {
29   public:
30     PGOODMonitor() = delete;
31     ~PGOODMonitor() = default;
32     PGOODMonitor(const PGOODMonitor&) = delete;
33     PGOODMonitor& operator=(const PGOODMonitor&) = delete;
34     PGOODMonitor(PGOODMonitor&&) = delete;
35     PGOODMonitor& operator=(PGOODMonitor&&) = delete;
36 
37     /**
38      * Constructor
39      *
40      * @param[in] d - the device to monitor
41      * @param[in] b - D-Bus bus object
42      * @param[in] e - event object
43      * @param[in] t - time to allow PGOOD to come up
44      */
PGOODMonitor(std::unique_ptr<phosphor::power::Device> && d,sdbusplus::bus_t & b,const sdeventplus::Event & e,std::chrono::milliseconds & t)45     PGOODMonitor(std::unique_ptr<phosphor::power::Device>&& d,
46                  sdbusplus::bus_t& b, const sdeventplus::Event& e,
47                  std::chrono::milliseconds& t) :
48         DeviceMonitor(std::move(d), e, t), bus(b)
49     {}
50 
51     /**
52      * Analyzes the power sequencer for fails and then
53      * notifies the event loop that it can exit.
54      *
55      * The timer callback.
56      */
57     void analyze() override;
58 
59     /**
60      * Waits a specified amount of time for PGOOD to
61      * come on, and if it fails to come on in that time
62      * it will analyze the power sequencer for faults.
63      *
64      * It will exit after either PGOOD is asserted or
65      * the device is analyzed for faults.
66      *
67      * @return - the return value from sd_event_loop()
68      */
69     int run() override;
70 
71   private:
72     /**
73      * Enables the properties changed signal callback
74      * on the power object so we can tell when PGOOD
75      * comes on.
76      */
77     void startListening();
78 
79     /**
80      * The callback function for the properties changed
81      * signal.
82      */
83     void propertyChanged();
84 
85     /**
86      * Returns true if the system has been turned on
87      * but PGOOD isn't up yet.
88      */
89     bool pgoodPending();
90 
91     /**
92      * Used to break out of the event loop in run()
93      */
94     void exitEventLoop();
95 
96     /**
97      * The D-Bus object
98      */
99     sdbusplus::bus_t& bus;
100 
101     /**
102      * The match object for the properties changed signal
103      */
104     std::unique_ptr<sdbusplus::bus::match_t> match;
105 };
106 
107 } // namespace power
108 } // namespace phosphor
109