blob: 74f982b33ecfba1e03a8bc4f24d0a32a6659c159 [file] [log] [blame]
George Hung9d538eb2021-04-28 10:26:40 +08001From a1f9d797753e32b36e08e7d611ff88b10e9bbad2 Mon Sep 17 00:00:00 2001
2From: "Jason M. Bills" <jason.m.bills@linux.intel.com>
3Date: Thu, 30 Jan 2020 16:18:33 -0800
4Subject: [PATCH 1/3] Add Chassis State Transition interface
5
6This adds the Chassis State Transition interface in preparation
7to support the mapping defined in the design document below.
8
9ref: https://gerrit.openbmc-project.xyz/c/openbmc/docs/+/22358
10
11Tested:
12Ran each IPMI chassis control command to confirm the expected
13behavior:
14ipmitool power on: system is powered-on
15ipmitool power off: system is forced off
16ipmitool power cycle: system is forced off then powered-on
17ipmitool power reset: system is hard reset
18ipmitool power soft: soft power-off requested from system software
19
20Change-Id: I6acfb795a9a33ff5227a5d6e1830774ab732ac0c
21Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
22---
23 chassishandler.cpp | 33 +++++++++++++++++++++++++++++++++
24 1 file changed, 33 insertions(+)
25
26diff --git a/chassishandler.cpp b/chassishandler.cpp
27index 0d318647..fdbb9fa5 100644
28--- a/chassishandler.cpp
29+++ b/chassishandler.cpp
30@@ -31,6 +31,7 @@
31 #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
32 #include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
33 #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
34+#include <xyz/openbmc_project/State/Chassis/server.hpp>
35 #include <xyz/openbmc_project/State/Host/server.hpp>
36 #include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
37
38@@ -865,6 +866,38 @@ int initiate_state_transition(State::Host::Transition transition)
39 return rc;
40 }
41
42+//------------------------------------------
43+// Calls into Chassis State Manager Dbus object
44+//------------------------------------------
45+int initiateChassisStateTransition(State::Chassis::Transition transition)
46+{
47+ // OpenBMC Chassis State Manager dbus framework
48+ constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0";
49+ constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis";
50+
51+ auto service =
52+ ipmi::getService(*getSdBus(), chassisStateIntf, chassisStatePath);
53+
54+ // Convert to string equivalent of the passed in transition enum.
55+ auto request = State::convertForMessage(transition);
56+
57+ try
58+ {
59+ ipmi::setDbusProperty(*getSdBus(), service, chassisStatePath,
60+ chassisStateIntf, "RequestedPowerTransition",
61+ request);
62+ }
63+ catch (std::exception& e)
64+ {
65+ log<level::ERR>(
66+ "Failed to initiate transition",
67+ entry("EXCEPTION=%s, REQUEST=%s", e.what(), request.c_str()));
68+ return -1;
69+ }
70+
71+ return 0;
72+}
73+
74 //------------------------------------------
75 // Set Enabled property to inform NMI source
76 // handling to trigger a NMI_OUT BSOD.
77--
782.21.0
79