blob: 23ff5db9860997255d24991737f18633f40bb6d7 [file] [log] [blame]
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +05301#pragma once
2
Patrick Venture0b02be92018-08-31 11:55:55 -07003#include "config.h"
4
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <functional>
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +05306#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server/object.hpp>
Vernon Mauery1181af72018-10-08 12:05:00 -07008#include <sdbusplus/timer.hpp>
Andrew Geisslerf0f496c2017-05-02 13:54:35 -05009#include <xyz/openbmc_project/Control/Host/server.hpp>
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +053010#include <xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp>
11namespace phosphor
12{
13namespace ipmi
14{
15
16namespace Base = sdbusplus::xyz::openbmc_project::Ipmi::Internal::server;
Andrew Geisslerf0f496c2017-05-02 13:54:35 -050017using namespace sdbusplus::xyz::openbmc_project::Control::server;
18
19namespace sdbusRule = sdbusplus::bus::match::rules;
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +053020
Patrick Williams5adc2d42022-04-07 15:53:44 -050021namespace
22{
23using SoftPowerOffInherit = sdbusplus::server::object_t<Base::SoftPowerOff>;
24}
25
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +053026/** @class SoftPowerOff
27 * @brief Responsible for coordinating Host SoftPowerOff operation
28 */
Patrick Williams5adc2d42022-04-07 15:53:44 -050029class SoftPowerOff : public SoftPowerOffInherit
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +053030{
Patrick Venture0b02be92018-08-31 11:55:55 -070031 public:
32 /** @brief Constructs SoftPowerOff object.
33 *
34 * @param[in] bus - system dbus handler
35 * @param[in] event - sd_event handler
36 * @param[in] objPath - The Dbus path hosting SoftPowerOff function
37 */
Patrick Williams5d82f472022-07-22 19:26:53 -050038 SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event, const char* objPath) :
Patrick Williams5adc2d42022-04-07 15:53:44 -050039 SoftPowerOffInherit(bus, objPath,
40 SoftPowerOffInherit::action::defer_emit),
Patrick Venture0b02be92018-08-31 11:55:55 -070041 bus(bus), timer(event),
42 hostControlSignal(
43 bus,
44 sdbusRule::type::signal() + sdbusRule::member("CommandComplete") +
45 sdbusRule::path("/xyz/openbmc_project/control/host0") +
46 sdbusRule::interface(CONTROL_HOST_BUSNAME) +
47 sdbusRule::argN(0, convertForMessage(Host::Command::SoftOff)),
48 std::bind(std::mem_fn(&SoftPowerOff::hostControlEvent), this,
49 std::placeholders::_1))
50 {
51 // Need to announce since we may get the response
52 // very quickly on host shutdown command
53 emit_object_added();
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +053054
Patrick Venture0b02be92018-08-31 11:55:55 -070055 // The whole purpose of this application is to send a host shutdown
56 // command and watch for the soft power off to go through. We need
57 // the interface added signal emitted before we send the shutdown
58 // command just to attend to lightning fast response from host
59 sendHostShutDownCmd();
60 }
Vishwanatha Subbanna7cc9d712017-01-24 18:48:40 +053061
Patrick Venture0b02be92018-08-31 11:55:55 -070062 /** @brief Tells if the objective of this application is completed */
63 inline auto isCompleted()
64 {
65 return completed;
66 }
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +053067
Patrick Venture0b02be92018-08-31 11:55:55 -070068 /** @brief Tells if the referenced timer is expired or not */
69 inline auto isTimerExpired()
70 {
71 return timer.isExpired();
72 }
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +053073
Patrick Venture0b02be92018-08-31 11:55:55 -070074 /** @brief overloaded property setter function
75 *
76 * @param[in] value - One of SoftOffReceived / HostShutdown
77 *
78 * @return Success or exception thrown
79 */
80 HostResponse responseReceived(HostResponse value) override;
Vishwanatha Subbanna31272b82017-02-01 18:53:14 +053081
Patrick Venture0b02be92018-08-31 11:55:55 -070082 /** @brief Using the base class's getter method */
83 using Base::SoftPowerOff::responseReceived;
Vishwanatha Subbanna917454b2017-02-24 00:16:05 +053084
Patrick Venture0b02be92018-08-31 11:55:55 -070085 /** @brief Calls to start a timer
86 *
87 * @param[in] usec - Time in microseconds
88 *
89 * @return Success or exception thrown
90 */
91 int startTimer(const std::chrono::microseconds& usec);
Vishwanatha Subbanna917454b2017-02-24 00:16:05 +053092
Patrick Venture0b02be92018-08-31 11:55:55 -070093 private:
94 // Need this to send SMS_ATTN
95 // TODO : Switch over to using mapper service in a different patch
96 static constexpr auto HOST_IPMI_BUS = "org.openbmc.HostIpmi";
97 static constexpr auto HOST_IPMI_OBJ = "/org/openbmc/HostIpmi/1";
98 static constexpr auto HOST_IPMI_INTF = "org.openbmc.HostIpmi";
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +053099
Patrick Venture0b02be92018-08-31 11:55:55 -0700100 /* @brief sdbusplus handle */
Patrick Williams5d82f472022-07-22 19:26:53 -0500101 sdbusplus::bus_t& bus;
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +0530102
Patrick Venture0b02be92018-08-31 11:55:55 -0700103 /** @brief Reference to Timer object */
104 Timer timer;
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +0530105
Patrick Venture0b02be92018-08-31 11:55:55 -0700106 /** @brief Marks the end of life of this application.
107 *
108 * This is set to true if host gives appropriate responses
109 * for the sequence of commands.
110 */
111 bool completed = false;
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +0530112
Patrick Venture0b02be92018-08-31 11:55:55 -0700113 /** @brief Subscribe to host control signals
114 *
115 * Protocol is to send the host power off request to the host
116 * control interface and then wait for a signal indicating pass/fail
117 **/
118 sdbusplus::bus::match_t hostControlSignal;
Andrew Geisslerf0f496c2017-05-02 13:54:35 -0500119
Patrick Venture0b02be92018-08-31 11:55:55 -0700120 /** @brief Sends host control command to tell host to shut down
121 *
122 * After sending the command, wait for a signal indicating the status
123 * of the command.
124 *
125 * After receiving the initial response, start a timer for 30 minutes
126 * to let host do a clean shutdown of partitions. When the response is
127 * received from the host, it indicates that BMC can do a power off.
128 * If BMC fails to get any response, then a hard power off would
129 * be forced.
130 *
131 * @return - Does not return anything. Error will result in exception
132 * being thrown
133 */
134 void sendHostShutDownCmd();
Andrew Geisslerf0f496c2017-05-02 13:54:35 -0500135
Patrick Venture0b02be92018-08-31 11:55:55 -0700136 /** @brief Callback function on host control signals
137 *
138 * @param[in] msg - Data associated with subscribed signal
139 *
140 */
Patrick Williams5d82f472022-07-22 19:26:53 -0500141 void hostControlEvent(sdbusplus::message_t& msg);
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +0530142};
143} // namespace ipmi
144} // namespace phosphor