1 #include <experimental/filesystem> 2 3 #include <phosphor-logging/elog-errors.hpp> 4 #include <xyz/openbmc_project/Sensor/Device/error.hpp> 5 6 #include "sensor.hpp" 7 #include "sensorset.hpp" 8 #include "hwmon.hpp" 9 #include "sysfs.hpp" 10 11 namespace sensor 12 { 13 14 std::shared_ptr<StatusObject> addStatus( 15 const SensorSet::key_type& sensor, 16 const hwmonio::HwmonIO& ioAccess, 17 const std::string& devPath, 18 ObjectInfo& info) 19 { 20 namespace fs = std::experimental::filesystem; 21 22 std::shared_ptr<StatusObject> iface = nullptr; 23 static constexpr bool deferSignals = true; 24 auto& bus = *std::get<sdbusplus::bus::bus*>(info); 25 auto& objPath = std::get<std::string>(info); 26 auto& obj = std::get<Object>(info); 27 28 // Check if fault sysfs file exists 29 std::string faultName = sensor.first; 30 std::string faultID = sensor.second; 31 std::string entry = hwmon::entry::fault; 32 33 auto sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(), 34 faultName, 35 faultID, 36 entry); 37 if (fs::exists(sysfsFullPath)) 38 { 39 bool functional = true; 40 uint32_t fault = 0; 41 try 42 { 43 fault = ioAccess.read(faultName, 44 faultID, 45 entry, 46 hwmonio::retries, 47 hwmonio::delay); 48 if (fault != 0) 49 { 50 functional = false; 51 } 52 } 53 catch (const std::system_error& e) 54 { 55 using namespace phosphor::logging; 56 using namespace sdbusplus::xyz::openbmc_project:: 57 Sensor::Device::Error; 58 using metadata = xyz::openbmc_project::Sensor:: 59 Device::ReadFailure; 60 61 report<ReadFailure>( 62 metadata::CALLOUT_ERRNO(e.code().value()), 63 metadata::CALLOUT_DEVICE_PATH(devPath.c_str())); 64 65 log<level::INFO>("Logging failing sysfs file", 66 phosphor::logging::entry( 67 "FILE=%s", sysfsFullPath.c_str())); 68 } 69 70 iface = std::make_shared<StatusObject>( 71 bus, 72 objPath.c_str(), 73 deferSignals); 74 // Set functional property 75 iface->functional(functional); 76 77 obj[InterfaceType::STATUS] = iface; 78 } 79 80 return iface; 81 } 82 83 } // namespace sensor 84