Debian Codegraph @

src/core/components/controls/amd/fan/fixed/fanfixedprovider.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "fanfixedprovider.h"
5
6 #include "../fanmodeprovider.h"
7 #include "common/fileutils.h"
8 #include "common/stringutils.h"
9 #include "core/info/amd/gpuinfoodfanctrl.h"
10 #include "core/info/igpuinfo.h"
11 #include "core/info/iswinfo.h"
12 #include "core/sysfsdatasource.h"
13 #include "fanfixed.h"
14 #include <filesystem>
15 #include <memory>
16 #include <spdlog/spdlog.h>
17 #include <string>
18
19 std::vector<std::unique_ptr<IControl>>
20 AMD::FanFixedProvider::provideGPUControls(IGPUInfo const &gpuInfo,
21 ISWInfo const &) const
22 {
23 if (!(gpuInfo.vendor() == Vendor::AMD &&
24 !gpuInfo.hasCapability(GPUInfoOdFanCtrl::ID)))
25 return {};
26
27 auto path = Utils::File::findHWMonXDirectory(gpuInfo.path().sys / "hwmon");
28 if (!path)
29 return {};
30
31 auto pwmEnable = path.value() / "pwm1_enable";
32 auto pwm = path.value() / "pwm1";
33 if (!(Utils::File::isSysFSEntryValid(pwm) &&
34 Utils::File::isSysFSEntryValid(pwmEnable)))
35 return {};
36
37 unsigned int value;
38
39 auto pwmEnableLines = Utils::File::readFileLines(pwmEnable);
40 if (!Utils::String::toNumber<unsigned int>(value, pwmEnableLines.front())) {
41 SPDLOG_WARN("Unknown data format on {}", pwmEnable.string());
42 SPDLOG_DEBUG(pwmEnableLines.front());
43 return {};
44 }
45
46 auto pwmLines = Utils::File::readFileLines(pwm);
47 if (!Utils::String::toNumber<unsigned int>(value, pwmLines.front())) {
48 SPDLOG_WARN("Unknown data format on {}", pwm.string());
49 SPDLOG_DEBUG(pwmLines.front());
50 return {};
51 }
52
53 std::vector<std::unique_ptr<IControl>> controls;
54 controls.emplace_back(std::make_unique<AMD::FanFixed>(
55 std::make_unique<SysFSDataSource<unsigned int>>(
56 pwmEnable,
57 [](std::string const &data, unsigned int &output) {
58 Utils::String::toNumber<unsigned int>(output, data);
59 }),
60 std::make_unique<SysFSDataSource<unsigned int>>(
61 pwm, [](std::string const &data, unsigned int &output) {
62 Utils::String::toNumber<unsigned int>(output, data);
63 })));
64
65 return controls;
66 }
67
68 bool const AMD::FanFixedProvider::registered_ =
69 AMD::FanModeProvider::registerProvider(
70 std::make_unique<AMD::FanFixedProvider>());