blob: 9c9ebc0fd040389a6d4d2efd03f3fd0824cd0faf [file] [log] [blame]
George Liu45d31232024-12-06 16:37:18 +08001#include "types.hpp"
2#include "utils.hpp"
3
4#include <ipmid/api.hpp>
5
6namespace ipmi
7{
8namespace iei
9{
10namespace power
11{
12
13void registerIEIPowerFunctions() __attribute__((constructor));
14
15static constexpr auto settingsService = "xyz.openbmc_project.Settings";
16
17static constexpr auto powerRestorePolicyPath =
18 "/xyz/openbmc_project/control/host0/power_restore_policy";
19static constexpr auto powerRestorePolicyIface =
20 "xyz.openbmc_project.Control.Power.RestorePolicy";
21static constexpr auto powerRestoreDelayProp = "PowerRestoreDelay";
22
23RspType<> ipmiIEISetPowerDelay(ipmi::Context::ptr ctx,
24 uint16_t powerRestoreDelay)
25{
26 uint64_t powerRestoreDelayInUs = powerRestoreDelay * 1000 * 1000;
27
28 auto ec = iei::setDbusProperty(
29 ctx, settingsService, powerRestorePolicyPath, powerRestorePolicyIface,
30 powerRestoreDelayProp, powerRestoreDelayInUs);
31
32 return ipmi::response(ec);
33}
34
35RspType<uint16_t> ipmiIEIGetPowerDelay(ipmi::Context::ptr ctx)
36{
37 uint64_t powerRestoreDelayInUs = 0;
38
39 auto ec = iei::getDbusProperty(
40 ctx, settingsService, powerRestorePolicyPath, powerRestorePolicyIface,
41 powerRestoreDelayProp, powerRestoreDelayInUs);
42 if (ec)
43 {
44 return ipmi::response(ec);
45 }
46
47 uint16_t powerRestoreDelay = powerRestoreDelayInUs / (1000 * 1000);
48
49 return ipmi::responseSuccess(powerRestoreDelay);
50}
51
52void registerIEIPowerFunctions()
53{
54 // Set power delay
55 ipmi::registerHandler(prioOemBase, netFnIEI, cmdSetPowerDelay,
56 ipmi::Privilege::Operator, ipmiIEISetPowerDelay);
57
58 // Get power delay
59 ipmi::registerHandler(prioOemBase, netFnIEI, cmdGetPowerDelay,
60 ipmi::Privilege::Operator, ipmiIEIGetPowerDelay);
61}
62
63} // namespace power
64} // namespace iei
65} // namespace ipmi