George Liu | 45d3123 | 2024-12-06 16:37:18 +0800 | [diff] [blame^] | 1 | #include "types.hpp" |
| 2 | #include "utils.hpp" |
| 3 | |
| 4 | #include <ipmid/api.hpp> |
| 5 | |
| 6 | namespace ipmi |
| 7 | { |
| 8 | namespace iei |
| 9 | { |
| 10 | namespace power |
| 11 | { |
| 12 | |
| 13 | void registerIEIPowerFunctions() __attribute__((constructor)); |
| 14 | |
| 15 | static constexpr auto settingsService = "xyz.openbmc_project.Settings"; |
| 16 | |
| 17 | static constexpr auto powerRestorePolicyPath = |
| 18 | "/xyz/openbmc_project/control/host0/power_restore_policy"; |
| 19 | static constexpr auto powerRestorePolicyIface = |
| 20 | "xyz.openbmc_project.Control.Power.RestorePolicy"; |
| 21 | static constexpr auto powerRestoreDelayProp = "PowerRestoreDelay"; |
| 22 | |
| 23 | RspType<> 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 | |
| 35 | RspType<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 | |
| 52 | void 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 |