George Liu | d6a1bae | 2022-06-20 13:47:31 +0800 | [diff] [blame] | 1 | #include "config.h" |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 2 | |
George Liu | d6a1bae | 2022-06-20 13:47:31 +0800 | [diff] [blame] | 3 | #include "button_handler.hpp" |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 4 | |
Matt Spinler | 1a309f7 | 2023-04-04 13:12:19 -0500 | [diff] [blame] | 5 | #include "power_button_profile_factory.hpp" |
| 6 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 8 | #include <xyz/openbmc_project/State/Chassis/server.hpp> |
| 9 | #include <xyz/openbmc_project/State/Host/server.hpp> |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 10 | namespace phosphor |
| 11 | { |
| 12 | namespace button |
| 13 | { |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 14 | |
| 15 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 16 | using namespace sdbusplus::xyz::openbmc_project::State::server; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 17 | |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 18 | constexpr auto chassisIface = "xyz.openbmc_project.State.Chassis"; |
| 19 | constexpr auto hostIface = "xyz.openbmc_project.State.Host"; |
| 20 | constexpr auto powerButtonIface = "xyz.openbmc_project.Chassis.Buttons.Power"; |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 21 | constexpr auto idButtonIface = "xyz.openbmc_project.Chassis.Buttons.ID"; |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 22 | constexpr auto resetButtonIface = "xyz.openbmc_project.Chassis.Buttons.Reset"; |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 23 | constexpr auto ledGroupIface = "xyz.openbmc_project.Led.Group"; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 24 | constexpr auto ledGroupBasePath = "/xyz/openbmc_project/led/groups/"; |
| 25 | constexpr auto hostSelectorIface = |
| 26 | "xyz.openbmc_project.Chassis.Buttons.HostSelector"; |
| 27 | constexpr auto debugHostSelectorIface = |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 28 | "xyz.openbmc_project.Chassis.Buttons.Button"; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 29 | |
| 30 | constexpr auto propertyIface = "org.freedesktop.DBus.Properties"; |
| 31 | constexpr auto mapperIface = "xyz.openbmc_project.ObjectMapper"; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 32 | |
| 33 | constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; |
| 34 | constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 35 | constexpr auto BMC_POSITION = 0; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 36 | |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 37 | Handler::Handler(sdbusplus::bus_t& bus) : bus(bus) |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 38 | { |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 39 | try |
| 40 | { |
| 41 | if (!getService(POWER_DBUS_OBJECT_NAME, powerButtonIface).empty()) |
| 42 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 43 | lg2::info("Starting power button handler"); |
Matt Spinler | 1a309f7 | 2023-04-04 13:12:19 -0500 | [diff] [blame] | 44 | |
| 45 | // Check for a custom handler |
| 46 | powerButtonProfile = |
| 47 | PowerButtonProfileFactory::instance().createProfile(bus); |
| 48 | |
| 49 | if (!powerButtonProfile) |
| 50 | { |
| 51 | powerButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 52 | bus, |
| 53 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 54 | sdbusRule::path(POWER_DBUS_OBJECT_NAME) + |
| 55 | sdbusRule::interface(powerButtonIface), |
| 56 | std::bind(std::mem_fn(&Handler::powerReleased), this, |
| 57 | std::placeholders::_1)); |
| 58 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 59 | } |
| 60 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 61 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 62 | { |
| 63 | // The button wasn't implemented |
| 64 | } |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 65 | |
| 66 | try |
| 67 | { |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 68 | if (!getService(ID_DBUS_OBJECT_NAME, idButtonIface).empty()) |
| 69 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 70 | lg2::info("Registering ID button handler"); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 71 | idButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 72 | bus, |
| 73 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 74 | sdbusRule::path(ID_DBUS_OBJECT_NAME) + |
| 75 | sdbusRule::interface(idButtonIface), |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 76 | std::bind(std::mem_fn(&Handler::idReleased), this, |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 77 | std::placeholders::_1)); |
| 78 | } |
| 79 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 80 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 81 | { |
| 82 | // The button wasn't implemented |
| 83 | } |
| 84 | |
| 85 | try |
| 86 | { |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 87 | if (!getService(RESET_DBUS_OBJECT_NAME, resetButtonIface).empty()) |
| 88 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 89 | lg2::info("Registering reset button handler"); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 90 | resetButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 91 | bus, |
| 92 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 93 | sdbusRule::path(RESET_DBUS_OBJECT_NAME) + |
| 94 | sdbusRule::interface(resetButtonIface), |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 95 | std::bind(std::mem_fn(&Handler::resetReleased), this, |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 96 | std::placeholders::_1)); |
| 97 | } |
| 98 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 99 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 100 | { |
| 101 | // The button wasn't implemented |
| 102 | } |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 103 | try |
| 104 | { |
| 105 | if (!getService(DBG_HS_DBUS_OBJECT_NAME, debugHostSelectorIface) |
| 106 | .empty()) |
| 107 | { |
| 108 | lg2::info("Registering debug host selector button handler"); |
| 109 | debugHSButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 110 | bus, |
| 111 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 112 | sdbusRule::path(DBG_HS_DBUS_OBJECT_NAME) + |
| 113 | sdbusRule::interface(debugHostSelectorIface), |
| 114 | std::bind(std::mem_fn(&Handler::debugHostSelectorReleased), |
| 115 | this, std::placeholders::_1)); |
| 116 | } |
| 117 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 118 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 119 | { |
| 120 | // The button wasn't implemented |
| 121 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 122 | } |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 123 | bool Handler::isMultiHost() |
| 124 | { |
| 125 | // return true in case host selector object is available |
| 126 | return (!getService(HS_DBUS_OBJECT_NAME, hostSelectorIface).empty()); |
| 127 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 128 | std::string Handler::getService(const std::string& path, |
| 129 | const std::string& interface) const |
| 130 | { |
| 131 | auto method = bus.new_method_call(mapperService, mapperObjPath, mapperIface, |
| 132 | "GetObject"); |
| 133 | method.append(path, std::vector{interface}); |
Thang Q. Nguyen | 4250785 | 2022-08-12 09:11:35 +0700 | [diff] [blame] | 134 | try |
| 135 | { |
| 136 | auto result = bus.call(method); |
| 137 | std::map<std::string, std::vector<std::string>> objectData; |
| 138 | result.read(objectData); |
| 139 | return objectData.begin()->first; |
| 140 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 141 | catch (const sdbusplus::exception_t& e) |
Thang Q. Nguyen | 4250785 | 2022-08-12 09:11:35 +0700 | [diff] [blame] | 142 | { |
| 143 | return std::string(); |
| 144 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 145 | } |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 146 | size_t Handler::getHostSelectorValue() |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 147 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 148 | auto HSService = getService(HS_DBUS_OBJECT_NAME, hostSelectorIface); |
| 149 | |
| 150 | if (HSService.empty()) |
| 151 | { |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 152 | lg2::info("Host selector dbus object not available"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 153 | throw std::invalid_argument("Host selector dbus object not available"); |
| 154 | } |
| 155 | |
| 156 | try |
| 157 | { |
| 158 | auto method = bus.new_method_call( |
| 159 | HSService.c_str(), HS_DBUS_OBJECT_NAME, propertyIface, "Get"); |
| 160 | method.append(hostSelectorIface, "Position"); |
| 161 | auto result = bus.call(method); |
| 162 | |
| 163 | std::variant<size_t> HSPositionVariant; |
| 164 | result.read(HSPositionVariant); |
| 165 | |
| 166 | auto position = std::get<size_t>(HSPositionVariant); |
| 167 | return position; |
| 168 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 169 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 170 | { |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 171 | lg2::error("Error reading host selector position: {ERROR}", "ERROR", e); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 172 | throw; |
| 173 | } |
| 174 | } |
| 175 | bool Handler::poweredOn(size_t hostNumber) const |
| 176 | { |
Potin Lai | c0fee46 | 2022-12-23 14:19:23 +0800 | [diff] [blame] | 177 | auto hostObjectName = HOST_STATE_OBJECT_NAME + std::to_string(hostNumber); |
| 178 | auto service = getService(hostObjectName.c_str(), hostIface); |
| 179 | auto method = bus.new_method_call(service.c_str(), hostObjectName.c_str(), |
| 180 | propertyIface, "Get"); |
| 181 | method.append(hostIface, "CurrentHostState"); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 182 | auto result = bus.call(method); |
| 183 | |
Patrick Williams | 5ed4cc0 | 2020-05-13 17:52:15 -0500 | [diff] [blame] | 184 | std::variant<std::string> state; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 185 | result.read(state); |
| 186 | |
Potin Lai | c0fee46 | 2022-12-23 14:19:23 +0800 | [diff] [blame] | 187 | return Host::HostState::Off != |
| 188 | Host::convertHostStateFromString(std::get<std::string>(state)); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 189 | } |
| 190 | |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 191 | void Handler::handlePowerEvent(PowerEvent powerEventType, |
| 192 | std::chrono::microseconds duration) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 193 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 194 | std::string objPathName; |
| 195 | std::string dbusIfaceName; |
| 196 | std::string transitionName; |
| 197 | std::variant<Host::Transition, Chassis::Transition> transition; |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 198 | uint64_t durationMs = |
| 199 | std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 200 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 201 | size_t hostNumber = 0; |
| 202 | auto isMultiHostSystem = isMultiHost(); |
| 203 | if (isMultiHostSystem) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 204 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 205 | hostNumber = getHostSelectorValue(); |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 206 | lg2::info("Multi-host system detected : {POSITION}", "POSITION", |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 207 | hostNumber); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | std::string hostNumStr = std::to_string(hostNumber); |
| 211 | |
| 212 | // ignore power and reset button events if BMC is selected. |
| 213 | if (isMultiHostSystem && (hostNumber == BMC_POSITION) && |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 214 | (powerEventType != PowerEvent::powerReleased) && |
| 215 | (durationMs <= LONG_PRESS_TIME_MS)) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 216 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 217 | lg2::info( |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 218 | "handlePowerEvent : BMC selected on multi-host system. ignoring power and reset button events..."); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 219 | return; |
| 220 | } |
| 221 | |
| 222 | switch (powerEventType) |
| 223 | { |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 224 | case PowerEvent::powerReleased: |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 225 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 226 | if (durationMs <= LONG_PRESS_TIME_MS) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 227 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 228 | objPathName = HOST_STATE_OBJECT_NAME + hostNumStr; |
| 229 | dbusIfaceName = hostIface; |
| 230 | transitionName = "RequestedHostTransition"; |
| 231 | |
| 232 | transition = Host::Transition::On; |
| 233 | |
| 234 | if (poweredOn(hostNumber)) |
| 235 | { |
| 236 | transition = Host::Transition::Off; |
| 237 | } |
| 238 | lg2::info("handlePowerEvent : Handle power button press "); |
| 239 | |
| 240 | break; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 241 | } |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 242 | else |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 243 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 244 | dbusIfaceName = chassisIface; |
| 245 | transitionName = "RequestedPowerTransition"; |
| 246 | objPathName = CHASSIS_STATE_OBJECT_NAME + hostNumStr; |
| 247 | transition = Chassis::Transition::Off; |
| 248 | |
| 249 | /* multi host system : |
| 250 | hosts (1 to N) - host shutdown |
| 251 | bmc (0) - sled cycle |
| 252 | single host system : |
| 253 | host(0) - host shutdown |
| 254 | */ |
| 255 | if (isMultiHostSystem && (hostNumber == BMC_POSITION)) |
| 256 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 257 | #if CHASSIS_SYSTEM_RESET_ENABLED |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 258 | objPathName = CHASSISSYSTEM_STATE_OBJECT_NAME + hostNumStr; |
| 259 | transition = Chassis::Transition::PowerCycle; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 260 | #else |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 261 | return; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 262 | #endif |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 263 | } |
| 264 | else if (!poweredOn(hostNumber)) |
| 265 | { |
| 266 | lg2::info( |
| 267 | "Power is off so ignoring long power button press"); |
| 268 | return; |
| 269 | } |
| 270 | lg2::info("handlePowerEvent : handle long power button press"); |
| 271 | break; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 272 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 273 | } |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 274 | case PowerEvent::resetReleased: |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 275 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 276 | objPathName = HOST_STATE_OBJECT_NAME + hostNumStr; |
| 277 | dbusIfaceName = hostIface; |
| 278 | transitionName = "RequestedHostTransition"; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 279 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 280 | if (!poweredOn(hostNumber)) |
| 281 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 282 | lg2::info("Power is off so ignoring reset button press"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 283 | return; |
| 284 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 285 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 286 | lg2::info("Handling reset button press"); |
HuyLe | 9456ffc | 2023-06-22 15:21:22 +0700 | [diff] [blame] | 287 | #ifdef ENABLE_RESET_BUTTON_DO_WARM_REBOOT |
| 288 | transition = Host::Transition::ForceWarmReboot; |
| 289 | #else |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 290 | transition = Host::Transition::Reboot; |
HuyLe | 9456ffc | 2023-06-22 15:21:22 +0700 | [diff] [blame] | 291 | #endif |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 292 | break; |
| 293 | } |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 294 | default: |
| 295 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 296 | lg2::error("{EVENT} is invalid power event. skipping...", "EVENT", |
Patrick Williams | 3610608 | 2024-02-26 10:26:43 -0600 | [diff] [blame^] | 297 | powerEventType); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 298 | |
| 299 | return; |
| 300 | } |
| 301 | } |
| 302 | auto service = getService(objPathName.c_str(), dbusIfaceName); |
| 303 | auto method = bus.new_method_call(service.c_str(), objPathName.c_str(), |
| 304 | propertyIface, "Set"); |
| 305 | method.append(dbusIfaceName, transitionName, transition); |
| 306 | bus.call(method); |
| 307 | } |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 308 | void Handler::powerReleased(sdbusplus::message_t& msg) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 309 | { |
| 310 | try |
| 311 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 312 | uint64_t time; |
| 313 | msg.read(time); |
| 314 | |
| 315 | handlePowerEvent(PowerEvent::powerReleased, |
| 316 | std::chrono::microseconds(time)); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 317 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 318 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 319 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 320 | lg2::error("Failed power state change on a power button press: {ERROR}", |
| 321 | "ERROR", e); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 322 | } |
| 323 | } |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 324 | |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 325 | void Handler::resetReleased(sdbusplus::message_t& /* msg */) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 326 | { |
| 327 | try |
| 328 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame] | 329 | // No need to calculate duration, set to 0. |
| 330 | handlePowerEvent(PowerEvent::resetReleased, |
| 331 | std::chrono::microseconds(0)); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 332 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 333 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 334 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 335 | lg2::error("Failed power state change on a reset button press: {ERROR}", |
| 336 | "ERROR", e); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 337 | } |
| 338 | } |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 339 | |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 340 | void Handler::idReleased(sdbusplus::message_t& /* msg */) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 341 | { |
| 342 | std::string groupPath{ledGroupBasePath}; |
| 343 | groupPath += ID_LED_GROUP; |
| 344 | |
| 345 | auto service = getService(groupPath, ledGroupIface); |
| 346 | |
| 347 | if (service.empty()) |
| 348 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 349 | lg2::info("No found {GROUP} during ID button press:", "GROUP", |
| 350 | groupPath); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
| 354 | try |
| 355 | { |
| 356 | auto method = bus.new_method_call(service.c_str(), groupPath.c_str(), |
| 357 | propertyIface, "Get"); |
| 358 | method.append(ledGroupIface, "Asserted"); |
| 359 | auto result = bus.call(method); |
| 360 | |
Patrick Williams | 5ed4cc0 | 2020-05-13 17:52:15 -0500 | [diff] [blame] | 361 | std::variant<bool> state; |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 362 | result.read(state); |
| 363 | |
Patrick Williams | 51f5e8b | 2020-05-13 11:33:44 -0500 | [diff] [blame] | 364 | state = !std::get<bool>(state); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 365 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 366 | lg2::info( |
| 367 | "Changing ID LED group state on ID LED press, GROUP = {GROUP}, STATE = {STATE}", |
| 368 | "GROUP", groupPath, "STATE", std::get<bool>(state)); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 369 | |
| 370 | method = bus.new_method_call(service.c_str(), groupPath.c_str(), |
| 371 | propertyIface, "Set"); |
| 372 | |
| 373 | method.append(ledGroupIface, "Asserted", state); |
| 374 | result = bus.call(method); |
| 375 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 376 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 377 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 378 | lg2::error("Error toggling ID LED group on ID button press: {ERROR}", |
| 379 | "ERROR", e); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 380 | } |
| 381 | } |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 382 | |
| 383 | void Handler::increaseHostSelectorPosition() |
| 384 | { |
| 385 | try |
| 386 | { |
| 387 | auto HSService = getService(HS_DBUS_OBJECT_NAME, hostSelectorIface); |
| 388 | |
| 389 | if (HSService.empty()) |
| 390 | { |
| 391 | lg2::error("Host selector service not available"); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | auto method = |
| 396 | bus.new_method_call(HSService.c_str(), HS_DBUS_OBJECT_NAME, |
| 397 | phosphor::button::propertyIface, "GetAll"); |
| 398 | method.append(phosphor::button::hostSelectorIface); |
| 399 | auto result = bus.call(method); |
| 400 | std::unordered_map<std::string, std::variant<size_t>> properties; |
| 401 | result.read(properties); |
| 402 | |
| 403 | auto maxPosition = std::get<size_t>(properties.at("MaxPosition")); |
| 404 | auto position = std::get<size_t>(properties.at("Position")); |
| 405 | |
| 406 | std::variant<size_t> HSPositionVariant = |
| 407 | (position < maxPosition) ? (position + 1) : 0; |
| 408 | |
| 409 | method = bus.new_method_call(HSService.c_str(), HS_DBUS_OBJECT_NAME, |
| 410 | phosphor::button::propertyIface, "Set"); |
| 411 | method.append(phosphor::button::hostSelectorIface, "Position"); |
| 412 | |
| 413 | method.append(HSPositionVariant); |
| 414 | result = bus.call(method); |
| 415 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 416 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 417 | { |
| 418 | lg2::error("Error modifying host selector position : {ERROR}", "ERROR", |
| 419 | e); |
| 420 | } |
| 421 | } |
| 422 | |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 423 | void Handler::debugHostSelectorReleased(sdbusplus::message_t& /* msg */) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 424 | { |
| 425 | try |
| 426 | { |
| 427 | increaseHostSelectorPosition(); |
| 428 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 429 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 430 | { |
| 431 | lg2::error( |
| 432 | "Failed power process debug host selector button press : {ERROR}", |
| 433 | "ERROR", e); |
| 434 | } |
| 435 | } |
| 436 | |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 437 | } // namespace button |
| 438 | } // namespace phosphor |