Debian Codegraph @

src/core/info/amd/gpuinfopmoverdrive.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "gpuinfopmoverdrive.h"
5
6 #include "common/fileutils.h"
7 #include "core/components/amdutils.h"
8 #include "core/info/infoproviderregistry.h"
9 #include <algorithm>
10 #include <utility>
11
12 namespace AMD {
13
14 class GPUInfoPMOverdriveDataSource
15 : public IDataSource<std::vector<std::string>, std::filesystem::path const>
16 {
17 public:
18 std::string source() const override
19 {
20 return "pp_od_clk_voltage";
21 }
22
23 bool read(std::vector<std::string> &data,
24 std::filesystem::path const &path) override
25 {
26 auto const filePath = path / source();
27 if (Utils::File::isSysFSEntryValid(filePath)) {
28 auto lines = Utils::File::readFileLines(filePath);
29 if (!lines.empty()) {
30 data = lines;
31 return true;
32 }
33 }
34
35 return false;
36 }
37 };
38 } // namespace AMD
39
40 AMD::GPUInfoPMOverdrive::GPUInfoPMOverdrive(
41 std::unique_ptr<IDataSource<std::vector<std::string>, std::filesystem::path const>>
42 &&dataSource) noexcept
43 : dataSource_(std::move(dataSource))
44 {
45 }
46
47 std::vector<std::pair<std::string, std::string>>
48 AMD::GPUInfoPMOverdrive::provideInfo(Vendor, int, IGPUInfo::Path const &,
49 IHWIDTranslator const &) const
50 {
51 return {};
52 }
53
54 std::vector<std::string>
55 AMD::GPUInfoPMOverdrive::provideCapabilities(Vendor vendor, int,
56 IGPUInfo::Path const &path) const
57 {
58 std::vector<std::string> cap;
59
60 if (vendor == Vendor::AMD) {
61
62 std::vector<std::string> data;
63 if (dataSource_->read(data, path.sys)) {
64
65 if (Utils::AMD::hasOverdriveClkVoltControl(data))
66 cap.emplace_back(GPUInfoPMOverdrive::ClkVolt);
67 else if (Utils::AMD::hasOverdriveClkControl(data))
68 cap.emplace_back(GPUInfoPMOverdrive::Clk);
69
70 if (Utils::AMD::hasOverdriveClkOffsetControl(data))
71 cap.emplace_back(GPUInfoPMOverdrive::ClkOffset);
72
73 if (Utils::AMD::hasOverdriveVoltCurveControl(data))
74 cap.emplace_back(GPUInfoPMOverdrive::VoltCurve);
75
76 if (Utils::AMD::hasOverdriveVoltOffsetControl(data))
77 cap.emplace_back(GPUInfoPMOverdrive::VoltOffset);
78 }
79 }
80
81 return cap;
82 }
83
84 bool AMD::GPUInfoPMOverdrive::registered_ =
85 InfoProviderRegistry::add(std::make_unique<AMD::GPUInfoPMOverdrive>(
86 std::make_unique<AMD::GPUInfoPMOverdriveDataSource>()));