Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
| 5 | #include "occ_status.hpp" |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 6 | #include "utils.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 7 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/bus/match.hpp> |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 10 | |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 11 | #include <filesystem> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 12 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 13 | namespace open_power |
| 14 | { |
| 15 | namespace occ |
| 16 | { |
| 17 | namespace powercap |
| 18 | { |
| 19 | |
| 20 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 21 | |
| 22 | /** @class PowerCap |
| 23 | * @brief Monitors for changes to the power cap and notifies occ |
| 24 | * |
| 25 | * The customer power cap is provided to the OCC by host TMGT when the occ |
| 26 | * first goes active or is reset. This code is responsible for sending |
| 27 | * the power cap to the OCC if the cap is changed while the occ is active. |
| 28 | */ |
| 29 | |
| 30 | class PowerCap |
| 31 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 32 | public: |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 33 | /** @brief PowerCap object to inform occ of changes to cap |
| 34 | * |
| 35 | * This object will monitor for changes to the power cap setting and |
| 36 | * power cap enable properties. If a change is detected, and the occ |
| 37 | * is active, then this object will notify the OCC of the change. |
| 38 | * |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 39 | * @param[in] occStatus - The occ status object |
| 40 | */ |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 41 | PowerCap(Status& occStatus, |
Lei YU | 41470e5 | 2017-11-30 16:03:50 +0800 | [diff] [blame] | 42 | const std::string& occMasterName = OCC_MASTER_NAME) : |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 43 | occMasterName(occMasterName), |
| 44 | occStatus(occStatus), |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 45 | pcapMatch( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 46 | utils::getBus(), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 47 | sdbusRule::member("PropertiesChanged") + |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 48 | sdbusRule::path( |
| 49 | "/xyz/openbmc_project/control/host0/power_cap") + |
| 50 | sdbusRule::argN(0, "xyz.openbmc_project.Control.Power.Cap") + |
| 51 | sdbusRule::interface("org.freedesktop.DBus.Properties"), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 52 | std::bind(std::mem_fn(&PowerCap::pcapChanged), this, |
| 53 | std::placeholders::_1)){}; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 54 | |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 55 | /** @brief Return the appropriate value to write to the OCC |
| 56 | * |
| 57 | * @param[in] pcap - Current user power cap setting |
| 58 | * @param[in] pcapEnabled - Current power cap enable setting |
| 59 | * |
| 60 | * @return The value to write to the occ user pcap |
| 61 | */ |
| 62 | uint32_t getOccInput(uint32_t pcap, bool pcapEnabled); |
| 63 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 64 | private: |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 65 | /** @brief Callback for pcap setting changes |
| 66 | * |
| 67 | * Process change and inform OCC |
| 68 | * |
| 69 | * @param[in] msg - Data associated with pcap change signal |
| 70 | * |
| 71 | */ |
| 72 | void pcapChanged(sdbusplus::message::message& msg); |
| 73 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 74 | /** @brief Get the power cap property |
| 75 | * |
| 76 | * @return Power cap, 0 on failure to indicate no pcap |
| 77 | */ |
| 78 | uint32_t getPcap(); |
| 79 | |
| 80 | /** @brief Get the power cap enable property |
| 81 | * |
| 82 | * @return Whether power cap enabled, will return false on error |
| 83 | */ |
| 84 | bool getPcapEnabled(); |
| 85 | |
Andrew Geissler | 6ac874e | 2017-07-10 15:54:58 -0500 | [diff] [blame] | 86 | /** @brief Write the input power cap to the occ hwmon entry |
| 87 | * |
| 88 | * @param[in] pcapValue - Power cap value to write to OCC |
| 89 | */ |
| 90 | void writeOcc(uint32_t pcapValue); |
| 91 | |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 92 | /** |
| 93 | * @brief Returns the filename to use for the user power cap |
| 94 | * |
| 95 | * The file is of the form "powerX_cap_user", where X is any |
| 96 | * number. |
| 97 | * |
| 98 | * @param[in] path - The directory to look for the file in |
| 99 | * |
| 100 | * @return std::string - The filename, or empty string if not found. |
| 101 | */ |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 102 | std::string getPcapFilename(const std::filesystem::path& path); |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 103 | |
Lei YU | 41470e5 | 2017-11-30 16:03:50 +0800 | [diff] [blame] | 104 | /** @brief The master occ name */ |
| 105 | std::string occMasterName; |
| 106 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 107 | /* @brief OCC Status object */ |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 108 | Status& occStatus; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 109 | |
Gunnar Mills | 85e6520 | 2018-04-08 15:01:54 -0500 | [diff] [blame] | 110 | /** @brief Used to subscribe to dbus pcap property changes **/ |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 111 | sdbusplus::bus::match_t pcapMatch; |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 112 | }; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 113 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 114 | } // namespace powercap |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 115 | |
| 116 | } // namespace occ |
| 117 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 118 | } // namespace open_power |