| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_FRU_SCANNER_FRAM_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_FRU_SCANNER_FRAM_H_ |
| |
| #include <cstdint> |
| #include <memory> |
| #include <string> |
| #include <vector> |
| |
| #include "absl/status/statusor.h" |
| #include "absl/time/time.h" |
| #include "io/ioctl.h" |
| #include "io/smbus/kernel_dev.h" |
| #include "io/smbus/smbus.h" |
| #include "time/clock.h" |
| #include "tlbmc/hal/fru_scanner.h" |
| |
| namespace milotic_tlbmc { |
| |
| // Fru scanner for reading from fram |
| class FruScannerFram : public FruScanner { |
| public: |
| struct Options { |
| std::string i2c_dev_dir = "/dev"; |
| // TODO(b/435256084): Refine FRAM reading to use the Log Offset |
| // from the status register instead of a fixed size. |
| // Currently, 4096 is used based on experimental validation for Cavium HSM |
| // FRAM.. |
| uint32_t fram_size = 4096; |
| // Currently the only FRAM FRU we need to scan. When we have |
| // multiple, we can add support for bus and address ranges in the future. |
| int bus = 6; |
| int address = 0x52; // Decimal 82 |
| }; |
| |
| static std::unique_ptr<FruScannerFram> Create(const Options& options); |
| |
| ~FruScannerFram() override; |
| |
| absl::StatusOr<std::unique_ptr<I2cFruInfo>> GetI2cFruInfoFromBus( |
| int bus, int address, absl::Duration delay_between_reads) const override; |
| |
| absl::StatusOr<std::vector<std::unique_ptr<I2cFruInfo>>> ScanAllI2cFrus() |
| const override; |
| |
| protected: |
| explicit FruScannerFram(const Options& options) |
| : options_(options), |
| sys_ioctl_(), |
| smbus_access_(std::make_unique<ecclesia::KernelSmbusAccess>( |
| options.i2c_dev_dir, &sys_ioctl_)) {} |
| |
| const Options options_; |
| ecclesia::SysIoctl sys_ioctl_; |
| std::unique_ptr<ecclesia::SmbusAccessInterface> smbus_access_; |
| ecclesia::Clock* clock_ = ecclesia::Clock::RealClock(); |
| |
| private: |
| void SleepIfNeeded(absl::Duration delay) const; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_FRU_SCANNER_FRAM_H_ |