1184f6026SChicago Duan #pragma once 2184f6026SChicago Duan 33fcfaa12SManojkiran Eda #include "common/instance_id.hpp" 41ed5f7a6SRashmica Gupta #include "common/transport.hpp" 5184f6026SChicago Duan #include "common/types.hpp" 6184f6026SChicago Duan 7*4d99c311SSagar Srinivas #include <nlohmann/json.hpp> 8184f6026SChicago Duan #include <sdbusplus/bus.hpp> 9184f6026SChicago Duan #include <sdbusplus/server.hpp> 10184f6026SChicago Duan #include <sdbusplus/server/object.hpp> 11184f6026SChicago Duan #include <sdbusplus/timer.hpp> 12184f6026SChicago Duan #include <sdeventplus/event.hpp> 13184f6026SChicago Duan 14184f6026SChicago Duan namespace pldm 15184f6026SChicago Duan { 16*4d99c311SSagar Srinivas using Json = nlohmann::json; 17184f6026SChicago Duan 18184f6026SChicago Duan /** @class SoftPowerOff 19184f6026SChicago Duan * @brief Responsible for coordinating Host SoftPowerOff operation 20184f6026SChicago Duan */ 21184f6026SChicago Duan class SoftPowerOff 22184f6026SChicago Duan { 23184f6026SChicago Duan public: 24184f6026SChicago Duan /** @brief Constructs SoftPowerOff object. 25184f6026SChicago Duan * 26184f6026SChicago Duan * @param[in] bus - system D-Bus handler 27184f6026SChicago Duan * @param[in] event - sd_event handler 283fcfaa12SManojkiran Eda * @param[in] instanceDb - pldm instance database 29184f6026SChicago Duan */ 303fcfaa12SManojkiran Eda SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event, 313fcfaa12SManojkiran Eda InstanceIdDb& instanceIdDb); 32184f6026SChicago Duan 33184f6026SChicago Duan /** @brief Is the pldm-softpoweroff has error. 34184f6026SChicago Duan * if hasError is true, that means the pldm-softpoweroff failed to 35184f6026SChicago Duan * trigger the host soft off,so the pldm-softpoweroff will exit. 36184f6026SChicago Duan */ isError()37184f6026SChicago Duan inline bool isError() 38184f6026SChicago Duan { 39184f6026SChicago Duan return hasError; 40184f6026SChicago Duan } 41184f6026SChicago Duan 42184f6026SChicago Duan /** @brief Is the timer expired. 43184f6026SChicago Duan */ isTimerExpired()44184f6026SChicago Duan inline bool isTimerExpired() 45184f6026SChicago Duan { 46184f6026SChicago Duan return timer.isExpired(); 47184f6026SChicago Duan } 48184f6026SChicago Duan 49184f6026SChicago Duan /** @brief Is the host soft off completed. 50184f6026SChicago Duan */ isCompleted()51184f6026SChicago Duan inline bool isCompleted() 52184f6026SChicago Duan { 53184f6026SChicago Duan return completed; 54184f6026SChicago Duan } 55184f6026SChicago Duan 56184f6026SChicago Duan /** @brief Is receive the response for the PLDM request msg. 57184f6026SChicago Duan */ isReceiveResponse()58184f6026SChicago Duan inline bool isReceiveResponse() 59184f6026SChicago Duan { 60184f6026SChicago Duan return responseReceived; 61184f6026SChicago Duan } 62184f6026SChicago Duan 63184f6026SChicago Duan /** @brief Send PLDM Set State Effecter States command and 64184f6026SChicago Duan * wait the host gracefully shutdown. 65184f6026SChicago Duan * 66184f6026SChicago Duan * @param[in] event - The event loop. 67184f6026SChicago Duan * 68184f6026SChicago Duan * @return PLDM_SUCCESS or PLDM_ERROR. 69184f6026SChicago Duan */ 70184f6026SChicago Duan int hostSoftOff(sdeventplus::Event& event); 71184f6026SChicago Duan 72184f6026SChicago Duan private: 73184f6026SChicago Duan /** @brief Getting the host current state. 74184f6026SChicago Duan */ 75184f6026SChicago Duan int getHostState(); 76184f6026SChicago Duan 77184f6026SChicago Duan /** @brief Stop the timer. 78184f6026SChicago Duan */ stopTimer()79184f6026SChicago Duan inline auto stopTimer() 80184f6026SChicago Duan { 81184f6026SChicago Duan return timer.stop(); 82184f6026SChicago Duan } 83184f6026SChicago Duan 84*4d99c311SSagar Srinivas /** @brief method to parse the config Json file for softoff 85*4d99c311SSagar Srinivas * 86*4d99c311SSagar Srinivas * @return Json - Json object of 87*4d99c311SSagar Srinivas */ 88*4d99c311SSagar Srinivas Json parseConfig(); 89*4d99c311SSagar Srinivas 90184f6026SChicago Duan /** @brief When host soft off completed, stop the timer and 91184f6026SChicago Duan * set the completed to true. 92184f6026SChicago Duan * 93184f6026SChicago Duan * @param[in] msg - Data associated with subscribed signal 94184f6026SChicago Duan */ 9584b790cbSPatrick Williams void hostSoftOffComplete(sdbusplus::message_t& msg); 96184f6026SChicago Duan 97184f6026SChicago Duan /** @brief Start the timer. 98184f6026SChicago Duan * 99184f6026SChicago Duan * @param[in] usec - Time to wait for the Host to gracefully shutdown. 100184f6026SChicago Duan * 101184f6026SChicago Duan * @return Success or exception thrown 102184f6026SChicago Duan */ 103184f6026SChicago Duan int startTimer(const std::chrono::microseconds& usec); 104184f6026SChicago Duan 105184f6026SChicago Duan /** @brief Get effecterID from PDRs. 106184f6026SChicago Duan * 107*4d99c311SSagar Srinivas * @param[in] entityType - entity type of the entity hosting 108*4d99c311SSagar Srinivas * hosting softoff PDR 109*4d99c311SSagar Srinivas * @param[in] stateSetId - state set ID of the softoff PDR 110*4d99c311SSagar Srinivas * 111*4d99c311SSagar Srinivas * @return true or false 112184f6026SChicago Duan */ 113*4d99c311SSagar Srinivas bool getEffecterID(pldm::pdr::EntityType& entityType, 114*4d99c311SSagar Srinivas pldm::pdr::StateSetId& stateSetId); 115184f6026SChicago Duan 116184f6026SChicago Duan /** @brief Get VMM/SystemFirmware Sensor info from PDRs. 117184f6026SChicago Duan * 118*4d99c311SSagar Srinivas * @param[in] entityType - entity type of the entity hosting 119*4d99c311SSagar Srinivas * hosting softoff PDR 120*4d99c311SSagar Srinivas * @param[in] stateSetId - state set ID of the softoff PDR 121*4d99c311SSagar Srinivas * 122184f6026SChicago Duan * @return PLDM_SUCCESS or PLDM_ERROR 123184f6026SChicago Duan */ 124*4d99c311SSagar Srinivas int getSensorInfo(pldm::pdr::EntityType& entityType, 125*4d99c311SSagar Srinivas pldm::pdr::StateSetId& stateSetId); 126184f6026SChicago Duan 127184f6026SChicago Duan /** @brief effecterID 128184f6026SChicago Duan */ 129184f6026SChicago Duan uint16_t effecterID; 130184f6026SChicago Duan 131184f6026SChicago Duan /** @brief sensorID. 132184f6026SChicago Duan */ 133184f6026SChicago Duan pldm::pdr::SensorID sensorID; 134184f6026SChicago Duan 135184f6026SChicago Duan /** @brief sensorOffset. 136184f6026SChicago Duan */ 137184f6026SChicago Duan pldm::pdr::SensorOffset sensorOffset; 138184f6026SChicago Duan 139184f6026SChicago Duan /** @brief Failed to send host soft off command flag. 140184f6026SChicago Duan */ 141184f6026SChicago Duan bool hasError = false; 142184f6026SChicago Duan 143184f6026SChicago Duan /** @brief Host soft off completed flag. 144184f6026SChicago Duan */ 145184f6026SChicago Duan bool completed = false; 146184f6026SChicago Duan 147184f6026SChicago Duan /** @brief The response for the PLDM request msg is received flag. 148184f6026SChicago Duan */ 149184f6026SChicago Duan bool responseReceived = false; 150184f6026SChicago Duan 151184f6026SChicago Duan /* @brief sdbusplus handle */ 15284b790cbSPatrick Williams sdbusplus::bus_t& bus; 153184f6026SChicago Duan 154184f6026SChicago Duan /** @brief Reference to Timer object */ 15535535cf2SPatrick Williams sdbusplus::Timer timer; 156184f6026SChicago Duan 157184f6026SChicago Duan /** @brief Used to subscribe to dbus pldm StateSensorEvent signal 158184f6026SChicago Duan * When the host soft off is complete, it sends an platform event message 159184f6026SChicago Duan * to BMC's pldmd, and the pldmd will emit the StateSensorEvent signal. 160184f6026SChicago Duan **/ 161184f6026SChicago Duan std::unique_ptr<sdbusplus::bus::match_t> pldmEventSignal; 1623fcfaa12SManojkiran Eda 1633fcfaa12SManojkiran Eda /** @brief Reference to the instance database 1643fcfaa12SManojkiran Eda */ 1653fcfaa12SManojkiran Eda InstanceIdDb& instanceIdDb; 166184f6026SChicago Duan }; 167184f6026SChicago Duan 168184f6026SChicago Duan } // namespace pldm 169