blob: 403cd8c9e5bceadd3442fe74d869b4e0d9bda709 [file] [log] [blame]
Ben Tynerb797b3e2020-06-29 10:12:05 -05001#include <attn/attn_handler.hpp>
2#include <attn/attn_logging.hpp>
3#include <attn/ti_handler.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06004#include <sdbusplus/bus.hpp>
Ben Tynerff17f962020-09-23 08:21:19 -05005#include <sdbusplus/exception.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06006
Ben Tyner9ae5ca42020-02-28 13:13:50 -06007namespace attn
8{
9
Ben Tynerff17f962020-09-23 08:21:19 -050010/** @brief Start host diagnostic mode or quiesce host on TI */
Ben Tyner792f32f2020-06-02 08:50:47 -050011int tiHandler(TiDataArea* i_tiDataArea)
Ben Tyner9ae5ca42020-02-28 13:13:50 -060012{
Ben Tyner792f32f2020-06-02 08:50:47 -050013 int rc = RC_NOT_HANDLED; // assume TI not handled
Ben Tyner9ae5ca42020-02-28 13:13:50 -060014
Ben Tyner792f32f2020-06-02 08:50:47 -050015 if (0xa1 == i_tiDataArea->command)
16 {
Ben Tynerff17f962020-09-23 08:21:19 -050017 // Use the systemd service manager object interface to call the
18 // start unit method with the obmc-host-diagnostic-mode target.
Ben Tyner792f32f2020-06-02 08:50:47 -050019 auto bus = sdbusplus::bus::new_system();
20 auto method = bus.new_method_call(
21 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
22 "org.freedesktop.systemd1.Manager", "StartUnit");
Ben Tyner9ae5ca42020-02-28 13:13:50 -060023
Ben Tynerff17f962020-09-23 08:21:19 -050024 if (autoRebootEnabled())
25 {
26 // If autoreboot is enabled we will start diagnostic mode target
27 // which will ultimately mpipl the host.
28 trace<level::INFO>("start obmc-host-diagnostic-mode target");
29 method.append("obmc-host-diagnostic-mode@0.target");
30 }
31 else
32 {
33 // If autoreboot is disabled we will start the host quiesce target
34 trace<level::INFO>("start obmc-host-quiesce target");
35 method.append("obmc-host-quiesce@0.target");
36 }
Ben Tyner792f32f2020-06-02 08:50:47 -050037 method.append("replace"); // mode = replace conflicting queued jobs
38 bus.call_noreply(method); // start the service
39
40 rc = RC_SUCCESS;
41 }
42
43 return rc;
Ben Tyner9ae5ca42020-02-28 13:13:50 -060044}
45
Ben Tynerff17f962020-09-23 08:21:19 -050046/** @brief Read autoreboot property **/
47bool autoRebootEnabled()
48{
49 // Use dbus get-property interface to read the autoreboot property
50 auto bus = sdbusplus::bus::new_system();
51 auto method =
52 bus.new_method_call("xyz.openbmc_project.Settings",
53 "/xyz/openbmc_project/control/host0/auto_reboot",
54 "org.freedesktop.DBus.Properties", "Get");
55 method.append("xyz.openbmc_project.Control.Boot.RebootPolicy",
56 "AutoReboot");
57 try
58 {
59 auto reply = bus.call(method);
60 std::variant<bool> result;
61 reply.read(result);
62 auto autoReboot = std::get<bool>(result);
63 if (autoReboot)
64 {
65 trace<level::INFO>("Auto reboot enabled");
66 return true;
67 }
68 else
69 {
70 trace<level::INFO>("Auto reboot disabled.");
71 return false;
72 }
73 }
74 catch (const sdbusplus::exception::SdBusError& ec)
75 {
76 // Error reading autoreboot
77 std::string traceMessage =
78 "Error in AutoReboot Get: " + std::string(ec.what());
79 trace<level::INFO>(traceMessage.c_str());
80 return false; // assume autoreboot disabled
81 }
82}
Ben Tyner9ae5ca42020-02-28 13:13:50 -060083} // namespace attn