xref: /openbmc/phosphor-host-ipmid/softoff/softoff.hpp (revision 917454bb139be75f656ddfa451e5036fc24ce640)
1506aa0f3SVishwanatha Subbanna #pragma once
2506aa0f3SVishwanatha Subbanna 
3506aa0f3SVishwanatha Subbanna #include <sdbusplus/bus.hpp>
4506aa0f3SVishwanatha Subbanna #include <sdbusplus/server/object.hpp>
5506aa0f3SVishwanatha Subbanna #include <xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp>
6bcb76886SVishwanatha Subbanna #include "timer.hpp"
7506aa0f3SVishwanatha Subbanna namespace phosphor
8506aa0f3SVishwanatha Subbanna {
9506aa0f3SVishwanatha Subbanna namespace ipmi
10506aa0f3SVishwanatha Subbanna {
11506aa0f3SVishwanatha Subbanna 
12506aa0f3SVishwanatha Subbanna namespace Base = sdbusplus::xyz::openbmc_project::Ipmi::Internal::server;
13506aa0f3SVishwanatha Subbanna 
14506aa0f3SVishwanatha Subbanna /** @class SoftPowerOff
15506aa0f3SVishwanatha Subbanna  *  @brief Responsible for coordinating Host SoftPowerOff operation
16506aa0f3SVishwanatha Subbanna  */
17506aa0f3SVishwanatha Subbanna class SoftPowerOff : public sdbusplus::server::object::object<
18506aa0f3SVishwanatha Subbanna                      Base::SoftPowerOff>
19506aa0f3SVishwanatha Subbanna {
20506aa0f3SVishwanatha Subbanna     public:
21506aa0f3SVishwanatha Subbanna         /** @brief Constructs SoftPowerOff object.
22506aa0f3SVishwanatha Subbanna          *
23506aa0f3SVishwanatha Subbanna          *  @param[in] bus       - system dbus handler
24bcb76886SVishwanatha Subbanna          *  @param[in] event     - sd_event handler
25bcb76886SVishwanatha Subbanna          *  @param[in] objPath   - The Dbus path hosting SoftPowerOff function
26506aa0f3SVishwanatha Subbanna          */
27506aa0f3SVishwanatha Subbanna         SoftPowerOff(sdbusplus::bus::bus& bus,
28bcb76886SVishwanatha Subbanna                      sd_event* event,
29506aa0f3SVishwanatha Subbanna                      const char* objPath) :
307cc9d716SVishwanatha Subbanna             sdbusplus::server::object::object<
31bcb76886SVishwanatha Subbanna                 Base::SoftPowerOff>(bus, objPath, false),
32bcb76886SVishwanatha Subbanna                 bus(bus),
33bcb76886SVishwanatha Subbanna                 timer(event)
34506aa0f3SVishwanatha Subbanna         {
35bcb76886SVishwanatha Subbanna             // Need to announce since we may get the response
36bcb76886SVishwanatha Subbanna             // very quickly on SMS_ATN
37bcb76886SVishwanatha Subbanna             emit_object_added();
38bcb76886SVishwanatha Subbanna 
397cc9d716SVishwanatha Subbanna             // The whole purpose of this application is to send SMS_ATTN
407cc9d716SVishwanatha Subbanna             // and watch for the soft power off to go through. We need the
417cc9d716SVishwanatha Subbanna             // interface added signal emitted before we send SMS_ATN just to
427cc9d716SVishwanatha Subbanna             // attend to lightning fast response from host
437cc9d716SVishwanatha Subbanna             sendSMSAttn();
44506aa0f3SVishwanatha Subbanna         }
457cc9d716SVishwanatha Subbanna 
46bcb76886SVishwanatha Subbanna         /** @brief Tells if the objective of this application is completed */
47bcb76886SVishwanatha Subbanna         inline auto isCompleted()
48bcb76886SVishwanatha Subbanna         {
49bcb76886SVishwanatha Subbanna             return completed;
50bcb76886SVishwanatha Subbanna         }
51bcb76886SVishwanatha Subbanna 
52bcb76886SVishwanatha Subbanna         /** @brief Tells if the referenced timer is expired or not */
53bcb76886SVishwanatha Subbanna         inline auto isTimerExpired()
54bcb76886SVishwanatha Subbanna         {
55bcb76886SVishwanatha Subbanna             return timer.isExpired();
56bcb76886SVishwanatha Subbanna         }
57bcb76886SVishwanatha Subbanna 
5831272b84SVishwanatha Subbanna         /** @brief overloaded property setter function
5931272b84SVishwanatha Subbanna          *
6031272b84SVishwanatha Subbanna          *  @param[in] value - One of SoftOffReceived / HostShutdown
6131272b84SVishwanatha Subbanna          *
6231272b84SVishwanatha Subbanna          *  @return Success or exception thrown
6331272b84SVishwanatha Subbanna          */
6431272b84SVishwanatha Subbanna         HostResponse responseReceived(HostResponse value) override;
6531272b84SVishwanatha Subbanna 
66*917454bbSVishwanatha Subbanna         /** @brief Using the base class's getter method */
67*917454bbSVishwanatha Subbanna         using Base::SoftPowerOff::responseReceived;
68*917454bbSVishwanatha Subbanna 
69*917454bbSVishwanatha Subbanna         /** @brief Calls to start a timer
70*917454bbSVishwanatha Subbanna          *
71*917454bbSVishwanatha Subbanna          *  @param[in] usec - Time in microseconds
72*917454bbSVishwanatha Subbanna          *
73*917454bbSVishwanatha Subbanna          *  @return Success or exception thrown
74*917454bbSVishwanatha Subbanna          */
75*917454bbSVishwanatha Subbanna         int startTimer(const std::chrono::microseconds& usec);
76*917454bbSVishwanatha Subbanna 
777cc9d716SVishwanatha Subbanna     private:
78bcb76886SVishwanatha Subbanna         // Need this to send SMS_ATTN
79bcb76886SVishwanatha Subbanna         // TODO : Switch over to using mapper service in a different patch
80bcb76886SVishwanatha Subbanna         static constexpr auto HOST_IPMI_BUS  = "org.openbmc.HostIpmi";
81bcb76886SVishwanatha Subbanna         static constexpr auto HOST_IPMI_OBJ  = "/org/openbmc/HostIpmi/1";
82bcb76886SVishwanatha Subbanna         static constexpr auto HOST_IPMI_INTF = "org.openbmc.HostIpmi";
83bcb76886SVishwanatha Subbanna 
84bcb76886SVishwanatha Subbanna         /* @brief sdbusplus handle */
85bcb76886SVishwanatha Subbanna         sdbusplus::bus::bus& bus;
86bcb76886SVishwanatha Subbanna 
87bcb76886SVishwanatha Subbanna         /** @brief Reference to Timer object */
88bcb76886SVishwanatha Subbanna         Timer timer;
89bcb76886SVishwanatha Subbanna 
90bcb76886SVishwanatha Subbanna         /** @brief Marks the end of life of this application.
91bcb76886SVishwanatha Subbanna          *
92bcb76886SVishwanatha Subbanna          *  This is set to true if host gives appropriate responses
93bcb76886SVishwanatha Subbanna          *  for the sequence of commands.
94bcb76886SVishwanatha Subbanna          */
95bcb76886SVishwanatha Subbanna         bool completed = false;
96bcb76886SVishwanatha Subbanna 
977cc9d716SVishwanatha Subbanna         /** @brief Sends SMS_ATN to host to initiate soft power off process.
987cc9d716SVishwanatha Subbanna          *
99bcb76886SVishwanatha Subbanna          *  After sending the SMS_ATN, starts a timer for 30
1007cc9d716SVishwanatha Subbanna          *  seconds and expects a initial response from the host.
101bcb76886SVishwanatha Subbanna          *  After receiving the initial response, starts another
1027cc9d716SVishwanatha Subbanna          *  timer for 30 minutes to let host do a clean shutdown of
1037cc9d716SVishwanatha Subbanna          *  partitions. When the second response is received from the
1047cc9d716SVishwanatha Subbanna          *  host, it indicates that BMC can do a power off.
1057cc9d716SVishwanatha Subbanna          *  If BMC fails to get any response, then a hard power off would
1067cc9d716SVishwanatha Subbanna          *  be forced.
1077cc9d716SVishwanatha Subbanna          *
1087cc9d716SVishwanatha Subbanna          *  @return - Does not return anything. Error will result in exception
1097cc9d716SVishwanatha Subbanna          *            being thrown
1107cc9d716SVishwanatha Subbanna          */
1117cc9d716SVishwanatha Subbanna         void sendSMSAttn();
112506aa0f3SVishwanatha Subbanna };
113506aa0f3SVishwanatha Subbanna } // namespace ipmi
114506aa0f3SVishwanatha Subbanna } // namespace phosphor
115