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] [day] [month] [year] [list]
Message-ID: <20220518004018.311332-1-tsung-hua.lin@amd.com>
Date:   Wed, 18 May 2022 08:40:14 +0800
From:   Ryan Lin <tsung-hua.lin@....com>
To:     unlisted-recipients:; (no To-header on input)
CC:     <leon.li@....com>, <Ching-shih.Li@....com>,
        Ryan Lin <tsung-hua.lin@....com>,
        Alex Deucher <alexander.deucher@....com>,
        Christian König <christian.koenig@....com>,
        "Pan, Xinhui" <Xinhui.Pan@....com>,
        David Airlie <airlied@...ux.ie>,
        Daniel Vetter <daniel@...ll.ch>,
        Harry Wentland <harry.wentland@....com>,
        Leo Li <sunpeng.li@....com>, Sean Paul <seanpaul@...omium.org>,
        Pratik Vishwakarma <Pratik.Vishwakarma@....com>,
        Lijo Lazar <lijo.lazar@....com>,
        Sathishkumar S <sathishkumar.sundararaju@....com>,
        Linux Patches Robot 
        <linux-patches-robot@...omeos-missing-patches.google.com.iam.gserviceaccount.com>,
        Andrey Grodzovsky <andrey.grodzovsky@....com>,
        Hawking Zhang <Hawking.Zhang@....com>,
        Chengming Gui <Jack.Gui@....com>,
        Huang Rui <ray.huang@....com>,
        Eric Huang <jinhuieric.huang@....com>,
        Likun Gao <Likun.Gao@....com>,
        Yifan Zhang <yifan1.zhang@....com>,
        Michel Dänzer <mdaenzer@...hat.com>,
        Jiri Kosina <jkosina@...e.cz>,
        Nicholas Kazlauskas <nicholas.kazlauskas@....com>,
        "Roman Li" <Roman.Li@....com>,
        Shirish S <shirish.s@....corp-partner.google.com>,
        Jude Shih <shenshih@....com>, Fangzhi Zuo <Jerry.Zuo@....com>,
        "Rodrigo Siqueira" <Rodrigo.Siqueira@....com>,
        Stylon Wang <stylon.wang@....com>,
        Wenjing Liu <wenjing.liu@....com>,
        Jimmy Kizito <Jimmy.Kizito@....com>,
        Mikita Lipski <mikita.lipski@....com>,
        Chris Park <Chris.Park@....com>,
        Robin Singh <robin.singh@....com>, Roy Chan <roy.chan@....com>,
        "Rouven Czerwinski" <rouven@...rwinskis.de>,
        Qingqing Zhuo <qingqing.zhuo@....com>,
        Jun Lei <Jun.Lei@....com>, Jake Wang <haonan.wang2@....com>,
        Nikola Cornij <nikola.cornij@....com>,
        <amd-gfx@...ts.freedesktop.org>, <dri-devel@...ts.freedesktop.org>,
        <linux-kernel@...r.kernel.org>
Subject: [PATCH v5] drm/amdgpu: Disable ABM when AC mode

Disable ABM feature when the system is running on AC mode to get the more
perfect contrast of the display.

v2: remove "UPSTREAM" from the subject.

v3: adv->pm.ac_power updating by amd gpu_acpi_event_handler.

v4: Add the file I lost to fix the build error.

v5: Move that function of the setting abm disabled from DC to amdgpu_dm.

Signed-off-by: Ryan Lin <tsung-hua.lin@....com>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c        |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c      |  1 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c   | 17 +++++++++++++++++
 drivers/gpu/drm/amd/display/dc/core/dc_link.c   | 10 ++++++++++
 drivers/gpu/drm/amd/display/dc/dc_link.h        |  2 ++
 drivers/gpu/drm/amd/include/amd_acpi.h          |  1 +
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h         |  1 +
 7 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
index 4811b0faafd9..6ac331ee4255 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -822,7 +822,8 @@ 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, ACPI_AC_CLASS) == 0) {
+	if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0 ||
+	    strcmp(entry->device_class, ACPI_BATTERY_CLASS) == 0) {
 		if (power_supply_is_system_supplied() > 0)
 			DRM_DEBUG_DRIVER("pm: AC\n");
 		else
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index abfcc1304ba0..b959d256ce46 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 = false;
 
 	atomic_set(&adev->throttling_logging_enabled, 1);
 	/*
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 87283e2da8c1..1ed1f2d00350 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3652,6 +3652,11 @@ amdgpu_dm_register_backlight_device(struct amdgpu_display_manager *dm)
 }
 #endif
 
+static void amdgpu_dm_abm_set_level(struct amdgpu_display_manager *dm, int level)
+{
+	dc_link_set_abm_level(dm->backlight_link[0], level);
+}
+
 static int initialize_plane(struct amdgpu_display_manager *dm,
 			    struct amdgpu_mode_info *mode_info, int plane_id,
 			    enum drm_plane_type plane_type,
@@ -9072,6 +9077,9 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
 		hdr_changed =
 			!drm_connector_atomic_hdr_metadata_equal(old_con_state, new_con_state);
 
+		if (adev->pm.ac_power)
+			dm_new_crtc_state->abm_level = 0;
+
 		if (!scaling_changed && !abm_changed && !hdr_changed)
 			continue;
 
@@ -9220,6 +9228,15 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
 			amdgpu_dm_backlight_set_level(dm, i, dm->brightness[i]);
 	}
 #endif
+
+	if (adev->pm.ac_power != adev->pm.old_ac_power) {
+		if (adev->pm.ac_power)
+			amdgpu_dm_abm_set_level(dm, 0);
+		else
+			amdgpu_dm_abm_set_level(dm, amdgpu_dm_abm_level);
+		adev->pm.old_ac_power = adev->pm.ac_power;
+	}
+
 	/*
 	 * send vblank event on all events not handled in flip and
 	 * mark consumed event for drm_atomic_helper_commit_hw_done
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link.c b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
index fb012ecd23a1..5edcf2a9dc4e 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
@@ -2616,6 +2616,16 @@ int dc_link_get_backlight_level(const struct dc_link *link)
 		return DC_ERROR_UNEXPECTED;
 }
 
+int dc_link_set_abm_level(const struct dc_link *link, int level)
+{
+	struct abm *abm = get_abm_from_stream_res(link);
+
+	if (abm != NULL && abm->funcs->set_abm_level != NULL)
+		return (int) abm->funcs->set_abm_level(abm, level);
+	else
+		return DC_ERROR_UNEXPECTED;
+}
+
 int dc_link_get_target_backlight_pwm(const struct dc_link *link)
 {
 	struct abm *abm = get_abm_from_stream_res(link);
diff --git a/drivers/gpu/drm/amd/display/dc/dc_link.h b/drivers/gpu/drm/amd/display/dc/dc_link.h
index 83845d006c54..b69a114ce154 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_link.h
+++ b/drivers/gpu/drm/amd/display/dc/dc_link.h
@@ -258,6 +258,8 @@ bool dc_link_set_default_brightness_aux(struct dc_link *link);
 
 int dc_link_get_backlight_level(const struct dc_link *dc_link);
 
+int dc_link_set_abm_level(const struct dc_link *link, int level);
+
 int dc_link_get_target_backlight_pwm(const struct dc_link *link);
 
 bool dc_link_set_psr_allow_active(struct dc_link *dc_link, bool enable,
diff --git a/drivers/gpu/drm/amd/include/amd_acpi.h b/drivers/gpu/drm/amd/include/amd_acpi.h
index 2d089d30518f..2d9aad582985 100644
--- a/drivers/gpu/drm/amd/include/amd_acpi.h
+++ b/drivers/gpu/drm/amd/include/amd_acpi.h
@@ -25,6 +25,7 @@
 #define AMD_ACPI_H
 
 #define ACPI_AC_CLASS           "ac_adapter"
+#define ACPI_BATTERY_CLASS	 "battery"
 
 struct atif_verify_interface {
 	u16 size;		/* structure size in bytes (includes size field) */
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index f6e0e7d8a007..de459411a0e8 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;
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ