blob: dbfcfda1809994c61648288c5c7de1aeb0b7b646 [file] [log] [blame]
Matt Spinler69b0cf02020-10-14 10:59:03 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "power_interface.hpp"
17
Mike Capps477b13b2022-07-11 10:45:46 -040018#include "logging.hpp"
Matt Spinler69b0cf02020-10-14 10:59:03 -050019#include "sdbusplus.hpp"
20
21namespace phosphor::fan::monitor
22{
23
24constexpr auto systemdService = "org.freedesktop.systemd1";
25constexpr auto systemdPath = "/org/freedesktop/systemd1";
26constexpr auto systemdMgrIface = "org.freedesktop.systemd1.Manager";
27
28void PowerInterface::softPowerOff()
29{
30 util::SDBusPlus::callMethod(systemdService, systemdPath, systemdMgrIface,
31 "StartUnit", "obmc-host-shutdown@0.target",
32 "replace");
33}
34
Matt Spinlerbb449c12021-06-14 11:45:28 -060035void PowerInterface::executeHardPowerOff()
Matt Spinler69b0cf02020-10-14 10:59:03 -050036{
37 util::SDBusPlus::callMethod(
38 systemdService, systemdPath, systemdMgrIface, "StartUnit",
39 "obmc-chassis-hard-poweroff@0.target", "replace");
Mike Capps683a96c2022-04-27 16:46:06 -040040
41 try
42 {
43 util::SDBusPlus::callMethod(
44 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump/bmc",
45 "xyz.openbmc_project.Dump.Create", "CreateDump",
46 std::vector<
47 std::pair<std::string, std::variant<std::string, uint64_t>>>());
48 }
Mike Capps477b13b2022-07-11 10:45:46 -040049 catch (const std::exception& e)
50 {
51 getLogger().log(
Patrick Williamsfbf47032023-07-17 12:27:34 -050052 std::format("Caught exception while creating BMC dump: {}",
Mike Capps477b13b2022-07-11 10:45:46 -040053 e.what()),
54 Logger::error);
55 }
Matt Spinler69b0cf02020-10-14 10:59:03 -050056}
57
Matt Spinlerbb449c12021-06-14 11:45:28 -060058void PowerInterface::hardPowerOff()
59{
60 executeHardPowerOff();
61}
62
Matt Spinler69b0cf02020-10-14 10:59:03 -050063} // namespace phosphor::fan::monitor