Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "hypervisor_state_manager.hpp" |
| 4 | |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 5 | #include <phosphor-logging/elog-errors.hpp> |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 7 | #include <sdbusplus/exception.hpp> |
| 8 | #include <sdbusplus/server.hpp> |
| 9 | |
| 10 | #include <fstream> |
| 11 | #include <iostream> |
| 12 | #include <map> |
| 13 | #include <string> |
| 14 | |
| 15 | namespace phosphor |
| 16 | { |
| 17 | namespace state |
| 18 | { |
| 19 | namespace manager |
| 20 | { |
| 21 | |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 22 | PHOSPHOR_LOG2_USING; |
| 23 | |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 24 | // When you see server:: you know we're referencing our base class |
Patrick Williams | 7e969cb | 2023-08-23 16:24:23 -0500 | [diff] [blame] | 25 | namespace server = sdbusplus::server::xyz::openbmc_project::state; |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 26 | using namespace phosphor::logging; |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 27 | |
| 28 | server::Host::Transition Hypervisor::requestedHostTransition(Transition value) |
| 29 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 30 | info("Hypervisor state transition request of {TRAN_REQUEST}", |
| 31 | "TRAN_REQUEST", value); |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 32 | |
| 33 | // Only support the transition to On |
| 34 | if (value != server::Host::Transition::On) |
| 35 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 36 | error("Hypervisor state only supports a transition to On"); |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 37 | // TODO raise appropriate error exception |
| 38 | return server::Host::Transition::Off; |
| 39 | } |
| 40 | |
| 41 | // This property is monitored by a separate application (for example PLDM) |
| 42 | // which is responsible for propagating the On request to the hypervisor |
| 43 | |
| 44 | return server::Host::requestedHostTransition(value); |
| 45 | } |
| 46 | |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 47 | server::Host::HostState Hypervisor::currentHostState(HostState value) |
| 48 | { |
Andrew Geissler | 9f444d4 | 2023-02-03 12:40:55 -0700 | [diff] [blame] | 49 | // Only log a message if this has changed since last |
| 50 | if (value != server::Host::currentHostState()) |
| 51 | { |
| 52 | info("Change to Hypervisor State: {HYP_STATE}", "HYP_STATE", value); |
| 53 | } |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 54 | return server::Host::currentHostState(value); |
| 55 | } |
| 56 | |
Andrew Geissler | e4a39de | 2023-08-22 15:11:09 -0400 | [diff] [blame] | 57 | server::Host::HostState Hypervisor::currentHostState() const |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 58 | { |
| 59 | return server::Host::currentHostState(); |
| 60 | } |
| 61 | |
| 62 | void Hypervisor::updateCurrentHostState(std::string& bootProgress) |
| 63 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 64 | debug("New BootProgress: {BOOTPROGRESS}", "BOOTPROGRESS", bootProgress); |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 65 | |
| 66 | if (bootProgress == "xyz.openbmc_project.State.Boot.Progress." |
| 67 | "ProgressStages.SystemInitComplete") |
| 68 | { |
| 69 | currentHostState(server::Host::HostState::Standby); |
| 70 | } |
| 71 | else if (bootProgress == "xyz.openbmc_project.State.Boot.Progress." |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 72 | "ProgressStages.OSRunning") |
| 73 | { |
| 74 | currentHostState(server::Host::HostState::Running); |
| 75 | } |
Andrew Geissler | 75f38ee | 2021-02-10 13:50:21 -0600 | [diff] [blame] | 76 | else if (bootProgress == "xyz.openbmc_project.State.Boot.Progress." |
| 77 | "ProgressStages.Unspecified") |
| 78 | { |
| 79 | // Unspecified is set when the system is powered off so |
| 80 | // set the state to off and reset the requested host state |
| 81 | // back to its default |
| 82 | currentHostState(server::Host::HostState::Off); |
| 83 | server::Host::requestedHostTransition(server::Host::Transition::Off); |
| 84 | } |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 85 | else |
| 86 | { |
| 87 | // BootProgress changed and it is not one of the above so |
| 88 | // set hypervisor state to off |
| 89 | currentHostState(server::Host::HostState::Off); |
| 90 | } |
| 91 | } |
| 92 | |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 93 | void Hypervisor::bootProgressChangeEvent(sdbusplus::message_t& msg) |
Andrew Geissler | c74716e | 2021-02-09 15:11:10 -0600 | [diff] [blame] | 94 | { |
| 95 | std::string statusInterface; |
| 96 | std::map<std::string, std::variant<std::string>> msgData; |
| 97 | msg.read(statusInterface, msgData); |
| 98 | |
| 99 | auto propertyMap = msgData.find("BootProgress"); |
| 100 | if (propertyMap != msgData.end()) |
| 101 | { |
| 102 | // Extract the BootProgress |
| 103 | auto& bootProgress = std::get<std::string>(propertyMap->second); |
| 104 | updateCurrentHostState(bootProgress); |
| 105 | } |
| 106 | } |
| 107 | |
Andrew Geissler | fe270d3 | 2021-01-27 14:06:46 -0600 | [diff] [blame] | 108 | } // namespace manager |
| 109 | } // namespace state |
| 110 | } // namespace phosphor |