| #include "tlbmc/sensors/peci_hwmon_based_sensor.h" |
| |
| #include <memory> |
| #include <optional> |
| #include <string> |
| #include <utility> |
| |
| #include "google/protobuf/duration.pb.h" |
| #include "absl/log/log.h" |
| #include "absl/status/status.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/str_cat.h" |
| #include "boost/asio.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "boost/asio/error.hpp" // NOLINT |
| #include "boost/asio/random_access_file.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "boost/filesystem.hpp" // NOLINT: boost::filesystem is commonly used in BMC |
| #include "boost/filesystem/operations.hpp" // NOLINT |
| #include "boost/system/detail/error_code.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "g3/macros.h" |
| #include "hal_common_config.pb.h" |
| #include "tlbmc/hal/sysfs/peci.h" |
| #include "resource.pb.h" |
| #include "sensor.pb.h" |
| #include "tlbmc/sensors/hwmon_based_sensor.h" |
| |
| namespace milotic_tlbmc { |
| |
| PeciHwmonBasedSensor::PeciHwmonBasedSensor( |
| const std::string& input_dev_path, |
| const std::shared_ptr<boost::asio::io_context>& io_context, |
| SensorAttributesStatic&& sensor_attributes_static, |
| const ThresholdConfigs& threshold_configs, |
| std::optional<NotificationCb> on_batch_notify, const PeciSysfs& peci_sysfs) |
| : HwmonBasedSensor(input_dev_path, io_context, |
| std::move(sensor_attributes_static), |
| threshold_configs, on_batch_notify), |
| peci_sysfs_(peci_sysfs) {} |
| |
| absl::StatusOr<boost::filesystem::path> PeciHwmonBasedSensor::CreateDevice( |
| const HalCommonConfig& hal_config) { |
| // If the device is already created, return the existing path. |
| if (peci_sysfs_.IsDevicePresent(hal_config)) { |
| LOG(INFO) << "Device " << hal_config << " already exists"; |
| |
| return peci_sysfs_.GetBusPath(hal_config.bus()) / |
| peci_sysfs_.GetDeviceDirectoryName(hal_config); |
| } |
| |
| ECCLESIA_RETURN_IF_ERROR(peci_sysfs_.NewDevice(hal_config, "peci-client")); |
| if (!peci_sysfs_.IsDevicePresent(hal_config)) { |
| return absl::InternalError(absl::StrCat("Failed to find device ", |
| hal_config, " after creating it")); |
| } |
| |
| // Now the device is created, e.g. /sys/bus/peci/devices/peci-0/0-30/ |
| return peci_sysfs_.GetBusPath(hal_config.bus()) / |
| peci_sysfs_.GetDeviceDirectoryName(hal_config); |
| } |
| |
| } // namespace milotic_tlbmc |