lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <dc41915d-4cd8-857f-8f2b-78e821ab9ab1@amd.com>
Date:   Tue, 29 Mar 2022 10:46:25 -0400
From:   Harry Wentland <harry.wentland@....com>
To:     Ryan Lin <tsung-hua.lin@....com>, sunpeng.li@....com,
        alexander.deucher@....com, christian.koenig@....com,
        David1.Zhou@....com, airlied@...ux.ie, daniel@...ll.ch,
        seanpaul@...omium.org, bas@...nieuwenhuizen.nl,
        nicholas.kazlauskas@....com, sashal@...nel.org,
        markyacoub@...gle.com, victorchengchi.lu@....com,
        ching-shih.li@....corp-partner.google.com,
        Rodrigo.Siqueira@....com, ddavenport@...omium.org,
        amd-gfx@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
        linux-kernel@...r.kernel.org, leon.li@....com
Subject: Re: [PATCH] UPSTREAM: drm/amdgpu: Disable ABM when AC mode



On 2022-03-29 10:33, Harry Wentland wrote:
> 
> 
> On 2022-03-24 19:10, Ryan Lin wrote:
>> Disable ABM feature when the system is running on AC mode to get
>> the more perfect contrast of the display.
>>
>> Signed-off-by: Ryan Lin <tsung-hua.lin@....com>
>>
>> ---
>>  drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c      |  4 ++
>>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
>>  drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c | 58 ++++++++++++-------
>>  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  1 +
>>  4 files changed, 42 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
>> index c560c1ab62ecb..bc8bb9aad2e36 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
>> @@ -822,6 +822,10 @@ static int amdgpu_acpi_event(struct notifier_block *nb,
>>  	struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);
>>  	struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
>>  
>> +	if (strcmp(entry->device_class, "battery") == 0) {
>> +		adev->pm.ac_power = power_supply_is_system_supplied() > 0;
>> +	}
>> +
>>  	if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
>>  		if (power_supply_is_system_supplied() > 0)
>>  			DRM_DEBUG_DRIVER("pm: AC\n");
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> index abfcc1304ba0c..3a0afe7602727 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> @@ -3454,6 +3454,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>>  
>>  	adev->gfx.gfx_off_req_count = 1;
>>  	adev->pm.ac_power = power_supply_is_system_supplied() > 0;
>> +	adev->pm.old_ac_power = true;
>>  
>>  	atomic_set(&adev->throttling_logging_enabled, 1);
>>  	/*
>> diff --git a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c
>> index 54a1408c8015c..478a734b66926 100644
>> --- a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c
>> +++ b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c
>> @@ -23,6 +23,8 @@
>>   *
>>   */
>>  
>> +#include <linux/power_supply.h>
>> +#include "amdgpu.h"
>>  #include "dmub_abm.h"
>>  #include "dce_abm.h"
>>  #include "dc.h"
>> @@ -51,6 +53,7 @@
>>  #define DISABLE_ABM_IMMEDIATELY 255
>>  
>>  
>> +extern uint amdgpu_dm_abm_level;
>>  
>>  static void dmub_abm_enable_fractional_pwm(struct dc_context *dc)
>>  {
>> @@ -117,28 +120,6 @@ static void dmub_abm_init(struct abm *abm, uint32_t backlight)
>>  	dmub_abm_enable_fractional_pwm(abm->ctx);
>>  }
>>  
>> -static unsigned int dmub_abm_get_current_backlight(struct abm *abm)
>> -{
>> -	struct dce_abm *dce_abm = TO_DMUB_ABM(abm);
>> -	unsigned int backlight = REG_READ(BL1_PWM_CURRENT_ABM_LEVEL);
>> -
>> -	/* return backlight in hardware format which is unsigned 17 bits, with
>> -	 * 1 bit integer and 16 bit fractional
>> -	 */
>> -	return backlight;
>> -}
>> -
>> -static unsigned int dmub_abm_get_target_backlight(struct abm *abm)
>> -{
>> -	struct dce_abm *dce_abm = TO_DMUB_ABM(abm);
>> -	unsigned int backlight = REG_READ(BL1_PWM_TARGET_ABM_LEVEL);
>> -
>> -	/* return backlight in hardware format which is unsigned 17 bits, with
>> -	 * 1 bit integer and 16 bit fractional
>> -	 */
>> -	return backlight;
>> -}
>> -
>>  static bool dmub_abm_set_level(struct abm *abm, uint32_t level)
>>  {
>>  	union dmub_rb_cmd cmd;
>> @@ -148,6 +129,9 @@ static bool dmub_abm_set_level(struct abm *abm, uint32_t level)
>>  	int edp_num;
>>  	uint8_t panel_mask = 0;
>>  
>> +	if (power_supply_is_system_supplied() > 0)
>> +		level = 0;
>> +
>>  	get_edp_links(dc->dc, edp_links, &edp_num);
>>  
>>  	for (i = 0; i < edp_num; i++) {
>> @@ -170,6 +154,36 @@ static bool dmub_abm_set_level(struct abm *abm, uint32_t level)
>>  	return true;
>>  }
>>  
>> +static unsigned int dmub_abm_get_current_backlight(struct abm *abm)
>> +{
>> +	struct dce_abm *dce_abm = TO_DMUB_ABM(abm);
>> +	unsigned int backlight = REG_READ(BL1_PWM_CURRENT_ABM_LEVEL);
>> +	struct dc_context *dc = abm->ctx;
>> +	struct amdgpu_device *adev = dc->driver_context;
>> +
>> +	if (adev->pm.ac_power != adev->pm.old_ac_power) {
> 
> This patch still has the problem of accessing adev from within DC.
> That'll break things on other platforms. This information needs to
> come in through the DC interface if we want to enable/disable ABM in
> this function.
> 
> After a closer look I also don't think that amdgpu is the right place
> to control the logic to disable ABM in AC mode, i.e. to switch between
> ABM levels. Take a look at dm_connector_state.abm_level and the
> abm_level_property. It's exposed to userspace as "abm level".
> 
> The "abm level" defaults to "0" unless userspace sets the "abm level"
> to something else. The same component that sets the "abm level"
> initially is the one that should set it to "0" when in AC mode.
> 

It might be that the ABM level is controlled via the abmlevel module
parameter. If that's the case and there isn't a userspace that sets the
"abm level" property then the easiest way to handle this is to switch
between 0 and amdgpu_dm_abm_level inside amdgpu_dm when there is a
AC/DC switch. Either way we shouldn't need to change DC.

Harry

> Harry
> 
>> +		dmub_abm_set_level(abm, amdgpu_dm_abm_level);
>> +		adev->pm.ac_power = power_supply_is_system_supplied() > 0;
>> +		adev->pm.old_ac_power = adev->pm.ac_power;
>> +	}
>> +
>> +	/* return backlight in hardware format which is unsigned 17 bits, with
>> +	 * 1 bit integer and 16 bit fractional
>> +	 */
>> +	return backlight;
>> +}
>> +
>> +static unsigned int dmub_abm_get_target_backlight(struct abm *abm)
>> +{
>> +	struct dce_abm *dce_abm = TO_DMUB_ABM(abm);
>> +	unsigned int backlight = REG_READ(BL1_PWM_TARGET_ABM_LEVEL);
>> +
>> +	/* return backlight in hardware format which is unsigned 17 bits, with
>> +	 * 1 bit integer and 16 bit fractional
>> +	 */
>> +	return backlight;
>> +}
>> +
>>  static bool dmub_abm_init_config(struct abm *abm,
>>  	const char *src,
>>  	unsigned int bytes,
>> diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
>> index f6e0e7d8a0077..de459411a0e83 100644
>> --- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
>> +++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
>> @@ -445,6 +445,7 @@ struct amdgpu_pm {
>>  	uint32_t                smu_prv_buffer_size;
>>  	struct amdgpu_bo        *smu_prv_buffer;
>>  	bool ac_power;
>> +	bool old_ac_power;
>>  	/* powerplay feature */
>>  	uint32_t pp_feature;
>>  
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ