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