// SPDX-License-Identifier: GPL-3.0-or-later // Copyright 2019 Juan Palacios #pragma once #include #include #include #include #include #include #include #include #include #include #include namespace Utils::AMD { template bool readAMDGPUInfoSensor(int deviceFD, Data *value, std::uint32_t sensor) { #if defined(AMDGPU_INFO_SENSOR) && defined(DRM_IOCTL_AMDGPU_INFO) struct drm_amdgpu_info buffer = {}; buffer.query = AMDGPU_INFO_SENSOR; buffer.return_pointer = reinterpret_cast(value); buffer.return_size = sizeof(*value); buffer.sensor_info.type = sensor; return ioctl(deviceFD, DRM_IOCTL_AMDGPU_INFO, &buffer) >= 0; #else return false; #endif } template bool readAMDGPUInfo(int deviceFD, Data *value, std::uint32_t query) { #if defined(DRM_IOCTL_AMDGPU_INFO) struct drm_amdgpu_info buffer = {}; buffer.query = query; buffer.return_pointer = reinterpret_cast(value); buffer.return_size = sizeof(*value); return ioctl(deviceFD, DRM_IOCTL_AMDGPU_INFO, &buffer) >= 0; #else return false; #endif } bool readAMDGPUVRamSize(int deviceFD, units::data::megabyte_t *size); template bool readRadeonInfoSensor(int deviceFD, Data *value, std::uint32_t sensor) { #if defined(DRM_IOCTL_RADEON_INFO) struct drm_radeon_info buffer = {}; buffer.request = sensor; buffer.value = reinterpret_cast(value); return ioctl(deviceFD, DRM_IOCTL_RADEON_INFO, &buffer) >= 0; #else return false; #endif } bool readRadeonVRamSize(int deviceFD, units::data::megabyte_t *size); /// Returns DPM states clocks. (4.6+) /// @param ppDpmLines pp_dpm_sclk / pp_dpm_mclk data source contents std::optional>> parseDPMStates(std::vector const &ppDpmLines); /// Returns the current state index from pp_dpm_sclk / pp_dpm_mclk. (4.6+) /// @param ppDpmLines pp_dpm_sclk / pp_dpm_mclk data source contents std::optional parseDPMCurrentStateIndex(std::vector const &ppDpmLines); /// Returns power profile modes. (4.17+) /// NOTE For use with non-columnar data only. /// @param ppPowerProfileModeLines pp_power_profile_mode data source contents std::optional>> parsePowerProfileModeModes(std::vector const &ppPowerProfileModeLines); /// Returns current power profile mode index. (4.17+) /// NOTE For use with non-columnar data only. /// @param ppPowerProfileModeLines pp_power_profile_mode data source contents std::optional parsePowerProfileModeCurrentModeIndex( std::vector const &ppPowerProfileModeLines); /// Returns power profile modes on ASICs with columnar data. (6.11+) /// @param ppPowerProfileModeLines pp_power_profile_mode data source contents std::optional>> parsePowerProfileModeModesColumnar( std::vector const &ppPowerProfileModeLines); /// Returns current power profile mode index on ASICs with columnar data. (6.11+) /// @param ppPowerProfileModeLines pp_power_profile_mode data source contents std::optional parsePowerProfileModeCurrentModeIndexColumnar( std::vector const &ppPowerProfileModeLines); /// Returns the available clock + voltage states for a control. (4.17+) /// @param controlName name of the control /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional>> parseOverdriveClksVolts(std::string_view controlName, std::vector const &ppOdClkVoltageLines); /// Returns the state's clock range for a control. (4.18+) /// @param controlName name of the control /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional> parseOverdriveClkRange(std::string_view controlName, std::vector const &ppOdClkVoltageLines); /// Returns the state's voltage range. (4.18+) /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional> parseOverdriveVoltRange(std::vector const &ppOdClkVoltageLines); /// Returns the available clock states for a control. (4.20+, vega20+) /// @param controlName name of the control /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional>> parseOverdriveClks(std::string_view controlName, std::vector const &ppOdClkVoltageLines); /// Returns the voltage curve points for curve voltage ASICs. (4.20+, vega20+) /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional>> parseOverdriveVoltCurve(std::vector const &ppOdClkVoltageLines); /// Returns voltage range of curve points for curve voltage ASICs. (4.20+, vega20+) /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional, std::pair>>> parseOverdriveVoltCurveRange(std::vector const &ppOdClkVoltageLines); /// Returns the voltage offset. /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional parseOverdriveVoltOffset(std::vector const &ppOdClkVoltageLines); /// Returns voltage offset range. (6.14+) /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional> parseOverdriveVoltOffsetRange(std::vector const &ppOdClkVoltageLines); /// Returns a list containing the name of the available CLK controls. /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional> parseOverdriveClkControls(std::vector const &ppOdClkVoltageLines); /// Translates a CLK control name to the control commit command id. /// @param controlName name of the control /// @returns commit command id std::optional getOverdriveClkControlCmdId(std::string_view controlName); /// Translates a CLK offset control name to the control commit command id. /// @param controlName name of the control /// @returns commit command id std::optional getOverdriveClkOffsetControlCmdId(std::string_view controlName); /// Returns a list containing the name of the available CLK offset controls (6.14+). /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional> parseOverdriveClkOffsetControls( std::vector const &ppOdClkVoltageLines); /// Returns the frequency offset value of a control. (6.14+) /// @param controlName name of the control /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional parseOverdriveClkOffset(std::string_view controlName, std::vector const &ppOdClkVoltageLines); /// Returns the frequency offset range of a control. (6.14+) /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional> parseOverdriveClkOffsetRange(std::string_view controlName, std::vector const &ppOdClkVoltageLines); /// Returns a list containing the indices of all out of range states present on /// pp_od_clk_voltage for the given control name. /// @param controlName name of the control /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents std::optional> ppOdClkVoltageFreqRangeOutOfRangeStates( std::string const &controlName, std::vector const &ppOdClkVoltageLines); /// Returns whether pp_od_clk_voltage has known frequency + voltage control quirks. /// @param controlName name of the control /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents bool ppOdClkVoltageHasKnownFreqVoltQuirks( std::string const &controlName, std::vector const &ppOdClkVoltageLines); /// Returns whether pp_od_clk_voltage has known voltage curve control quirks. /// @param ppOdClkVoltageLines pp_od_clk_voltage data source contents bool ppOdClkVoltageHasKnownVoltCurveQuirks( std::vector const &ppOdClkVoltageLines); /// Returns the fan curve points for the overdrive based fan control. (6.7+, RDNA3+) /// @param fanCurveLines fan_curve data source contents std::optional>> parseOverdriveFanCurve(std::vector const &fanCurveLines); /// Returns the fan curve temperature range for the overdrive based fan control. (6.7+, RDNA3+) /// @param fanCurveLines fan_curve data source contents std::optional> parseOverdriveFanCurveTempRange(std::vector const &fanCurveLines); /// Returns the fan curve speed range for the overdrive based fan control. (6.7+, RDNA3+) /// @param fanCurveLines fan_curve data source contents std::optional< std::pair> parseOverdriveFanCurveSpeedRange(std::vector const &fanCurveLines); /// Returns the fan stop value for the overdrive based fan control. (6.13+, RDNA3+) /// @param fanStopLines fan_zero_rpm_enable data source contents std::optional parseOverdriveFanStop(std::vector const &fanStopLines); /// Returns the fan stop temperature value for the overdrive based fan control. (6.13+, RDNA3+) /// @param fanStopTempLines fan_zero_rpm_stop_temperature data source contents std::optional parseOverdriveFanStopTemp(std::vector const &fanStopTempLines); /// Returns the fan stop temperature range for the overdrive based fan control. (6.13+, RDNA3+) /// @param fanStopTempLines fan_zero_rpm_stop_temperature data source contents std::optional> parseOverdriveFanStopTempRange(std::vector const &fanStopTempLines); /// Returns true when pp_power_profile_mode data has columnar format. bool isPowerProfileModeDataColumnar(std::vector const &data); /// Returns true when overdrive clock + voltage state control is available. bool hasOverdriveClkVoltControl(std::vector const &data); /// Returns true when overdrive clock control is available. bool hasOverdriveClkControl(std::vector const &data); /// Returns true when overdrive clock offset control is available. bool hasOverdriveClkOffsetControl(std::vector const &data); /// Returns true when overdrive voltage curve control is available. bool hasOverdriveVoltCurveControl(std::vector const &data); /// Returns true when overdrive voltage offset control is available. bool hasOverdriveVoltOffsetControl(std::vector const &data); /// Returns true when overdrive fan target temperature control is available. bool hasOverdriveFanTargetTempControl(std::vector const &data); /// Returns true when overdrive fan minimum pwm control is available. bool hasOverdriveFanMinimumPWMControl(std::vector const &data); /// Returns true when overdrive fan acoustic target rpm threshold control is /// available. bool hasOverdriveFanAcousticTargetControl(std::vector const &data); /// Returns true when overdrive fan acoustic limit rpm threshold control is /// available. bool hasOverdriveFanAcousticLimitControl(std::vector const &data); } // namespace Utils::AMD