| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "pmfixedprovider.h" |
| 5 | |
| 6 | #include "../pmperfmodeprovider.h" |
| 7 | #include "common/fileutils.h" |
| 8 | #include "core/info/amd/gpuinfopm.h" |
| 9 | #include "core/sysfsdatasource.h" |
| 10 | #include "pmfixedlegacy.h" |
| 11 | #include "pmfixedr600.h" |
| 12 | #include <filesystem> |
| 13 | #include <memory> |
| 14 | #include <string> |
| 15 | |
| 16 | std::vector<std::unique_ptr<IControl>> |
| 17 | AMD::PMFixedProvider::provideGPUControls(IGPUInfo const &gpuInfo, |
| 18 | ISWInfo const &) const |
| 19 | { |
| 20 | std::vector<std::unique_ptr<IControl>> controls; |
| 21 | |
| 22 | if (gpuInfo.vendor() != Vendor::AMD) |
| 23 | return {}; |
| 24 | |
| 25 | auto driver = gpuInfo.info(IGPUInfo::Keys::driver); |
| 26 | if (gpuInfo.hasCapability(GPUInfoPM::Legacy)) { |
| 27 | |
| 28 | auto powerMethod = gpuInfo.path().sys / "power_method"; |
| 29 | auto powerProfile = gpuInfo.path().sys / "power_profile"; |
| 30 | if (!(Utils::File::isSysFSEntryValid(powerMethod) && |
| 31 | Utils::File::isSysFSEntryValid(powerProfile))) |
| 32 | return {}; |
| 33 | |
| 34 | controls.emplace_back(std::make_unique<AMD::PMFixedLegacy>( |
| 35 | std::make_unique<SysFSDataSource<std::string>>(powerMethod), |
| 36 | std::make_unique<SysFSDataSource<std::string>>(powerProfile))); |
| 37 | } |
| 38 | else if (gpuInfo.hasCapability(GPUInfoPM::Radeon) || driver == "amdgpu") { |
| 39 | |
| 40 | auto perfLevel = gpuInfo.path().sys / "power_dpm_force_performance_level"; |
| 41 | if (!Utils::File::isSysFSEntryValid(perfLevel)) |
| 42 | return {}; |
| 43 | |
| 44 | controls.emplace_back(std::make_unique<AMD::PMFixedR600>( |
| 45 | std::make_unique<SysFSDataSource<std::string>>(perfLevel))); |
| 46 | } |
| 47 | |
| 48 | return controls; |
| 49 | } |
| 50 | |
| 51 | bool const AMD::PMFixedProvider::registered_ = |
| 52 | AMD::PMPerfModeProvider::registerProvider( |
| 53 | std::make_unique<AMD::PMFixedProvider>()); |