| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "gpuinfovbios.h" |
| 5 | |
| 6 | #include "common/fileutils.h" |
| 7 | #include "core/info/infoproviderregistry.h" |
| 8 | #include <algorithm> |
| 9 | #include <cctype> |
| 10 | #include <spdlog/spdlog.h> |
| 11 | #include <utility> |
| 12 | |
| 13 | namespace AMD { |
| 14 | class GPUInfoVbiosDataSource |
| 15 | : public IDataSource<std::string, std::filesystem::path const> |
| 16 | { |
| 17 | public: |
| 18 | std::string source() const override |
| 19 | { |
| 20 | return "vbios_version"; |
| 21 | } |
| 22 | |
| 23 | bool read(std::string &data, std::filesystem::path const &path) override |
| 24 | { |
| 25 | auto const filePath = path / source(); |
| 26 | auto const lines = Utils::File::readFileLines(filePath); |
| 27 | if (!lines.empty()) { |
| 28 | data = lines.front(); |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | SPDLOG_WARN("Cannot retrieve bios version from {}", filePath.c_str()); |
| 33 | return false; |
| 34 | } |
| 35 | }; |
| 36 | } // namespace AMD |
| 37 | |
| 38 | AMD::GPUInfoVbios::GPUInfoVbios( |
| 39 | std::unique_ptr<IDataSource<std::string, std::filesystem::path const>> |
| 40 | &&dataSource) noexcept |
| 41 | : dataSource_(std::move(dataSource)) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | std::vector<std::pair<std::string, std::string>> |
| 46 | AMD::GPUInfoVbios::provideInfo(Vendor vendor, int, IGPUInfo::Path const &path, |
| 47 | IHWIDTranslator const &) const |
| 48 | { |
| 49 | std::vector<std::pair<std::string, std::string>> info; |
| 50 | |
| 51 | if (vendor == Vendor::AMD) { |
| 52 | std::string data; |
| 53 | if (dataSource_->read(data, path.sys)) { |
| 54 | std::transform(data.cbegin(), data.cend(), data.begin(), ::toupper); |
| 55 | info.emplace_back(GPUInfoVbios::version, std::move(data)); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return info; |
| 60 | } |
| 61 | |
| 62 | std::vector<std::string> |
| 63 | AMD::GPUInfoVbios::provideCapabilities(Vendor, int, IGPUInfo::Path const &) const |
| 64 | { |
| 65 | return {}; |
| 66 | } |
| 67 | |
| 68 | bool AMD::GPUInfoVbios::registered_ = |
| 69 | InfoProviderRegistry::add(std::make_unique<AMD::GPUInfoVbios>( |
| 70 | std::make_unique<GPUInfoVbiosDataSource>())); |