Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/server/object.hpp> |
| 5 | #include <xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp> |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 6 | #include "timer.hpp" |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace ipmi |
| 10 | { |
| 11 | |
| 12 | namespace Base = sdbusplus::xyz::openbmc_project::Ipmi::Internal::server; |
| 13 | |
| 14 | /** @class SoftPowerOff |
| 15 | * @brief Responsible for coordinating Host SoftPowerOff operation |
| 16 | */ |
| 17 | class SoftPowerOff : public sdbusplus::server::object::object< |
| 18 | Base::SoftPowerOff> |
| 19 | { |
| 20 | public: |
| 21 | /** @brief Constructs SoftPowerOff object. |
| 22 | * |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 23 | * @param[in] bus - system dbus handler |
| 24 | * @param[in] event - sd_event handler |
| 25 | * @param[in] objPath - The Dbus path hosting SoftPowerOff function |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 26 | */ |
| 27 | SoftPowerOff(sdbusplus::bus::bus& bus, |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 28 | sd_event* event, |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 29 | const char* objPath) : |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 30 | sdbusplus::server::object::object< |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 31 | Base::SoftPowerOff>(bus, objPath, false), |
| 32 | bus(bus), |
| 33 | timer(event) |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 34 | { |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 35 | // Need to announce since we may get the response |
| 36 | // very quickly on SMS_ATN |
| 37 | emit_object_added(); |
| 38 | |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 39 | // The whole purpose of this application is to send SMS_ATTN |
| 40 | // and watch for the soft power off to go through. We need the |
| 41 | // interface added signal emitted before we send SMS_ATN just to |
| 42 | // attend to lightning fast response from host |
| 43 | sendSMSAttn(); |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 44 | } |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 45 | |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 46 | /** @brief Tells if the objective of this application is completed */ |
| 47 | inline auto isCompleted() |
| 48 | { |
| 49 | return completed; |
| 50 | } |
| 51 | |
| 52 | /** @brief Tells if the referenced timer is expired or not */ |
| 53 | inline auto isTimerExpired() |
| 54 | { |
| 55 | return timer.isExpired(); |
| 56 | } |
| 57 | |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 58 | /** @brief overloaded property setter function |
| 59 | * |
| 60 | * @param[in] value - One of SoftOffReceived / HostShutdown |
| 61 | * |
| 62 | * @return Success or exception thrown |
| 63 | */ |
| 64 | HostResponse responseReceived(HostResponse value) override; |
| 65 | |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 66 | /** @brief Using the base class's getter method */ |
| 67 | using Base::SoftPowerOff::responseReceived; |
| 68 | |
| 69 | /** @brief Calls to start a timer |
| 70 | * |
| 71 | * @param[in] usec - Time in microseconds |
| 72 | * |
| 73 | * @return Success or exception thrown |
| 74 | */ |
| 75 | int startTimer(const std::chrono::microseconds& usec); |
| 76 | |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 77 | private: |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 78 | // Need this to send SMS_ATTN |
| 79 | // TODO : Switch over to using mapper service in a different patch |
| 80 | static constexpr auto HOST_IPMI_BUS = "org.openbmc.HostIpmi"; |
| 81 | static constexpr auto HOST_IPMI_OBJ = "/org/openbmc/HostIpmi/1"; |
| 82 | static constexpr auto HOST_IPMI_INTF = "org.openbmc.HostIpmi"; |
| 83 | |
| 84 | /* @brief sdbusplus handle */ |
| 85 | sdbusplus::bus::bus& bus; |
| 86 | |
| 87 | /** @brief Reference to Timer object */ |
| 88 | Timer timer; |
| 89 | |
| 90 | /** @brief Marks the end of life of this application. |
| 91 | * |
| 92 | * This is set to true if host gives appropriate responses |
| 93 | * for the sequence of commands. |
| 94 | */ |
| 95 | bool completed = false; |
| 96 | |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 97 | /** @brief Sends SMS_ATN to host to initiate soft power off process. |
| 98 | * |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 99 | * After sending the SMS_ATN, starts a timer for 30 |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 100 | * seconds and expects a initial response from the host. |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 101 | * After receiving the initial response, starts another |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 102 | * timer for 30 minutes to let host do a clean shutdown of |
| 103 | * partitions. When the second response is received from the |
| 104 | * host, it indicates that BMC can do a power off. |
| 105 | * If BMC fails to get any response, then a hard power off would |
| 106 | * be forced. |
| 107 | * |
| 108 | * @return - Does not return anything. Error will result in exception |
| 109 | * being thrown |
| 110 | */ |
| 111 | void sendSMSAttn(); |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 112 | }; |
| 113 | } // namespace ipmi |
| 114 | } // namespace phosphor |