From 301fd47f7f21a780b06c4403a657d31e967934bf Mon Sep 17 00:00:00 2001 From: wangjue Date: Fri, 3 Jan 2025 18:57:29 +0800 Subject: [PATCH] Trigger to read dimm temp by vwgpio1 Signed-off-by: wangjue %% original patch: 0014-Trigger-to-read-dimm-temp-by-vwgpio1.patch --- src/DIMMTempSensor.cpp | 107 +++++++++++++++++++++++++++++++++++++++-- src/DIMMTempSensor.hpp | 2 + 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp index a0c9d76..852810b 100644 --- a/src/DIMMTempSensor.cpp +++ b/src/DIMMTempSensor.cpp @@ -49,6 +49,9 @@ constexpr auto dimmSensorPath = "/xyz/openbmc_project/sensors/temperature/"; constexpr auto dimmSpdReaderService = "xyz.openbmc_project.DimmSpdReader"; constexpr auto dbusProperties = "org.freedesktop.DBus.Properties"; constexpr auto tempInterface = "xyz.openbmc_project.Dimm.Temperature"; +constexpr auto HostMiscDbusName = "xyz.openbmc_project.Host.Misc.Manager"; +constexpr auto platformStatePath = "/xyz/openbmc_project/misc/platform_state"; +constexpr auto platformStateInterface = "xyz.openbmc_project.State.Host.Misc"; #define PECI_MBX_INDEX_DDR_DIMM_TEMP 0x0E @@ -78,6 +81,60 @@ static void setupDimmLEDMatch( std::move(eventHandler)); } +static bool getDbusMsgState(sdbusplus::message_t& msg, bool& value) +{ + std::string pltStateInterface; + std::string event; + boost::container::flat_map> + propertiesChanged; + try + { + msg.read(pltStateInterface, propertiesChanged); + if (propertiesChanged.empty()) + { + return false; + } + + std::string property = propertiesChanged.begin()->first; + + if (property.empty() || property != "dimmI3cSwitch") + { + return false; + } + + value = std::get(propertiesChanged.begin()->second); + return true; + } + catch (const std::exception& e) + { + std::cerr << "exception while reading dbus property dimmI3cSwitch" << "\n"; + return false; + } +} + +static void dimmI3cSwitchMatcher( + std::vector& matches, sdbusplus::bus_t& connection, + std::function&& onMatch) +{ + auto pulseEventMatcherCallback = + [onMatch{std::move(onMatch)}](sdbusplus::message_t& msg) { + bool value = false; + if (!getDbusMsgState(msg, value)) + { + return; + } + onMatch(value); + }; + + matches.emplace_back( + connection, + "type='signal',interface='org.freedesktop.DBus.Properties',member='" + "PropertiesChanged',arg0='" + + std::string(platformStateInterface) + "'", + std::move(pulseEventMatcherCallback)); +} + + DIMMTempSensor::DIMMTempSensor( std::shared_ptr& conn, boost::asio::io_context& io, const std::string& sensorName, @@ -121,6 +178,8 @@ DIMMTempSensor::DIMMTempSensor( association::interface); setInitialProperties(units); + + dimmI3cSwitchState = getdimmI3cSwitchState(io); } DIMMTempSensor::~DIMMTempSensor() @@ -202,10 +261,10 @@ void DIMMTempSensor::getDIMMRegsTemp(const std::string& sensorName) std::weak_ptr weakRef = weak_from_this(); dbusConnection->async_method_call( - [weakRef](const boost::system::error_code ec, const std::variant value) { + [weakRef, sensorName](const boost::system::error_code ec, const std::variant value) { if (ec) { - std::cerr << "Error setting DIMM sensor Temp" << "\n"; + std::cerr << "Error getting DIMM sensor " << sensorName << " Temp" << "\n"; return; } auto self = weakRef.lock(); @@ -241,7 +300,7 @@ void DIMMTempSensor::read(const std::string& sensorName) std::cerr << "timer error\n"; return; } - if (readingStateGood() && dimmLEDState == "ON") + if (readingStateGood() && dimmI3cSwitchState) { getDIMMRegsTemp(sensorName); } @@ -257,6 +316,7 @@ void DIMMTempSensor::read(const std::string& sensorName) void DIMMTempSensor::setupMatches(const std::string& sensorName) { std::weak_ptr weakRef = weak_from_this(); + std::shared_ptr sharedRef = weakRef.lock(); setupDimmLEDMatch(matches, *dbusConnection, sensorName, [weakRef, sensorName](const std::string& value) { auto self = weakRef.lock(); @@ -272,4 +332,45 @@ void DIMMTempSensor::setupMatches(const std::string& sensorName) } } ); + + dimmI3cSwitchMatcher(matches, *dbusConnection, [sharedRef](bool state) + { + if (!sharedRef) + { + return; + } + if (!state) + { + sharedRef->dimmI3cSwitchState = false; + } + else + { + sharedRef->dimmI3cSwitchState = true; + } + std::cout << "dimmI3cSwitchState: " << (int)sharedRef->dimmI3cSwitchState << std::endl; + }); +} + +bool DIMMTempSensor::getdimmI3cSwitchState(boost::asio::io_context& io) +{ + auto conn = std::make_shared(io); + auto mesg = conn->new_method_call(HostMiscDbusName, platformStatePath, + "org.freedesktop.DBus.Properties", "Get"); + mesg.append(platformStateInterface, "dimmI3cSwitch"); + + bool state = false; + try + { + auto resp = conn->call(mesg); + std::variant value; + resp.read(value); + state = std::get(value); + std::cout << " get dimmI3cSwitch State: " << (int)state << std::endl; + } + catch (std::exception& e) + { + std::cerr << "auto shutdown: failed to read node id"; + } + + return state; } diff --git a/src/DIMMTempSensor.hpp b/src/DIMMTempSensor.hpp index 5e629da..fc51928 100644 --- a/src/DIMMTempSensor.hpp +++ b/src/DIMMTempSensor.hpp @@ -27,6 +27,7 @@ struct DIMMTempSensor : public Sensor, std::enable_shared_from_this matches; }; -- 2.34.1