Skip to contentSkip to conversation

Adjust ACPI video detection fallback path

PATCH In review Mario Limonciello 4 participants 10 messages Dec 8, 2022 – Jan 3, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover Adjust ACPI video detection fallback path

In kernel 6.1 the backlight registration code was overhauled so that at most one backlight device got registered. As part of this change there was code added to still allow making an acpi_video0 device if the BIOS contained backlight control methods but no native or vendor drivers registered.

Even after the overhaul this fallback logic is failing on the BIOS from a number of motherboard manufacturers supporting Ryzen APUs. What happens is the amdgpu driver finishes registration and as expected doesn't create a backlight control device since no eDP panels are connected to a desktop.

Then 8 seconds later the ACPI video detection code creates an acpi_video0 device that is non-operational. GNOME then creates a backlight slider.

To avoid this situation from happening make two sets of changes:

Prevent desktop problems w/ fallback logic
------------------------------------------
1) Add support for the video detect code to let native drivers cancel the fallback logic if they didn't find a panel.

This is done this way so that if another driver decides that the ACPI mechanism is still needed it can instead directly call the registration function.

2) Add code to amdgpu to notify the ACPI video detection code that no panel was detected on an APU.

Disable fallback logic by default
---------------------------------
This fallback logic was introduced to prevent regressions in the backlight overhaul. As it has been deemed unnecessary by Hans explicitly disable the timeout. If this turns out to be mistake and this part is reverted, the other patches for preventing desktop problems will avoid regressions on desktops.

Mario Limonciello (3):
ACPI: video: Allow GPU drivers to report no panels drm/amd/display: Report to ACPI video if no panels were found
ACPI: video: Don't enable fallback path for creating ACPI backlight by
default

 drivers/acpi/acpi_video.c                       | 17 ++++++++++++-----
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c   |  4 ++++
 include/acpi/video.h                            |  2 ++
 3 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/3 ACPI: video: Allow GPU drivers to report no panels

The current logic for the ACPI backlight detection will create a backlight device if no native or vendor drivers have created 8 seconds after the system has booted if the ACPI tables included backlight control methods.

If the GPU drivers have loaded, they may be able to report whether any LCD panels were found. Allow using this information to factor in whether to enable the fallback logic for making an acpi_video0 backlight device.

---
v2->v3:
* Add Hans' R-b
* Add missing declaration for non CONFIG_ACPI_VIDEO case
v1->v2:
* Cancel registration for backlight device instead (Hans)
* drop desktop check (Dan)

---
 drivers/acpi/acpi_video.c | 11 +++++++++++
 include/acpi/video.h      |  2 ++
 2 files changed, 13 insertions(+)
drivers/acpi/acpi_video.c +11 -0
index 32953646caeb..f64fdb029090 100644
@@ -2178,6 +2178,17 @@ static bool should_check_lcd_flag(void)
 	return false;
 }
 
+/*
+ * At least one graphics driver has reported that no LCD is connected
+ * via the native interface. cancel the registration for fallback acpi_video0.
+ * If another driver still deems this necessary, it can explicitly register it.
+ */
+void acpi_video_report_nolcd(void)
+{
+	cancel_delayed_work(&video_bus_register_backlight_work);
+}
+EXPORT_SYMBOL(acpi_video_report_nolcd);
+
 int acpi_video_register(void)
 {
 	int ret = 0;
include/acpi/video.h +2 -0
index a275c35e5249..a56c8d45e9f8 100644
@@ -53,6 +53,7 @@ enum acpi_backlight_type {
 };
 
 #if IS_ENABLED(CONFIG_ACPI_VIDEO)
+extern void acpi_video_report_nolcd(void);
 extern int acpi_video_register(void);
 extern void acpi_video_unregister(void);
 extern void acpi_video_register_backlight(void);
@@ -69,6 +70,7 @@ extern int acpi_video_get_levels(struct acpi_device *device,
 				 struct acpi_video_device_brightness **dev_br,
 				 int *pmax_level);
 #else
+static inline void acpi_video_report_nolcd(void) { return; };
 static inline int acpi_video_register(void) { return -ENODEV; }
 static inline void acpi_video_unregister(void) { return; }
 static inline void acpi_video_register_backlight(void) { return; }
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/3] ACPI: video: Allow GPU drivers to report no panels

Quoted 34 lines · Mario Limonciello

The current logic for the ACPI backlight detection will create a backlight device if no native or vendor drivers have created 8 seconds after the system has booted if the ACPI tables included backlight control methods.

If the GPU drivers have loaded, they may be able to report whether any LCD panels were found. Allow using this information to factor in whether to enable the fallback logic for making an acpi_video0 backlight device.

---
v2->v3:
* Add Hans' R-b
* Add missing declaration for non CONFIG_ACPI_VIDEO case
v1->v2:
* Cancel registration for backlight device instead (Hans)
* drop desktop check (Dan)

---
 drivers/acpi/acpi_video.c | 11 +++++++++++
 include/acpi/video.h      |  2 ++
 2 files changed, 13 insertions(+)
drivers/acpi/acpi_video.c +1 -0
index 32953646caeb..f64fdb029090 100644
@@ -2178,6 +2178,17 @@ static bool should_check_lcd_flag(void)
 	return false;
 }
 
+/*

drivers/acpi/acpi_video.c static bool should_check_lcd_flag(void) · line 2191

Quoted 10 lines
drivers/acpi/acpi_video.c +10 -0
+ * At least one graphics driver has reported that no LCD is connected
+ * via the native interface. cancel the registration for fallback acpi_video0.
+ * If another driver still deems this necessary, it can explicitly register it.
+ */
+void acpi_video_report_nolcd(void)
+{
+	cancel_delayed_work(&video_bus_register_backlight_work);
+}
+EXPORT_SYMBOL(acpi_video_report_nolcd);
+

Thanks for removing the desktop check.

It's not entirely clear to me what happens if you try to cancel a delayed work that was never scheduled. I got as far as determining that del_timer() in kernel/time/timer.c will probably return 0, but I didn't really feel like walking through the rest of try_to_grab_pending() to figure out what happens next. You've probably already tested this with the default disabled timer, so as long as nothing bad happened there, this seems fine.

This is probably overly complicated, so if you think it's worth doing, I would definitely add it later, but I wonder if it might make sense to pass an acpi_handle to a _BC[LM] method or one of its parents, so that this could be scoped to a particular device. Looking at the ACPI table dump from a random multi-GPU laptop, it looks like there are two instances of _BCL, one under _SB.GP<number>.VGA.LCD for the iGPU, and the other under _SB.PCI<num>.GPP<num>.PEGP.EDP<num> for the dGPU. The caller would pass in handles for methods/devices that it will handle, and then the fallback, if it runs at all, would skip any handles that were registered with it when it crawls for _BC[LM]. Or the equivalent inverse logic, or something else like that. I think it's probably fine to keep the current unscoped design and just assert that any other GPU drivers that want the ACPI video driver to handle panel backlight should register it explicitly; if for some reason that ends up not working out, we could revisit scoping it then.

Quoted 26 lines
drivers/acpi/acpi_video.c +0 -0
 int acpi_video_register(void)
 {
 	int ret = 0;
include/acpi/video.h +2 -0
index a275c35e5249..a56c8d45e9f8 100644
@@ -53,6 +53,7 @@ enum acpi_backlight_type {
 };
 
 #if IS_ENABLED(CONFIG_ACPI_VIDEO)
+extern void acpi_video_report_nolcd(void);
 extern int acpi_video_register(void);
 extern void acpi_video_unregister(void);
 extern void acpi_video_register_backlight(void);
@@ -69,6 +70,7 @@ extern int acpi_video_get_levels(struct acpi_device *device,
 				 struct acpi_video_device_brightness **dev_br,
 				 int *pmax_level);
 #else
+static inline void acpi_video_report_nolcd(void) { return; };
 static inline int acpi_video_register(void) { return -ENODEV; }
 static inline void acpi_video_unregister(void) { return; }
 static inline void acpi_video_register_backlight(void) { return; }
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v3 1/3] ACPI: video: Allow GPU drivers to report no panels

Quoted 34 lines · Daniel Dadap
Quoted 33 lines · Mario Limonciello

The current logic for the ACPI backlight detection will create a backlight device if no native or vendor drivers have created 8 seconds after the system has booted if the ACPI tables included backlight control methods.

If the GPU drivers have loaded, they may be able to report whether any LCD panels were found. Allow using this information to factor in whether to enable the fallback logic for making an acpi_video0 backlight device.

---
v2->v3:
* Add Hans' R-b
* Add missing declaration for non CONFIG_ACPI_VIDEO case
v1->v2:
* Cancel registration for backlight device instead (Hans)
* drop desktop check (Dan)

---
  drivers/acpi/acpi_video.c | 11 +++++++++++
  include/acpi/video.h      |  2 ++
  2 files changed, 13 insertions(+)
drivers/acpi/acpi_video.c +0 -0
index 32953646caeb..f64fdb029090 100644
@@ -2178,6 +2178,17 @@ static bool should_check_lcd_flag(void)
  	return false;
  }
 
Quoted 13 lines

drivers/acpi/acpi_video.c static bool should_check_lcd_flag(void) · line 2191

Quoted 11 lines
drivers/acpi/acpi_video.c +11 -0
+/*
+ * At least one graphics driver has reported that no LCD is connected
+ * via the native interface. cancel the registration for fallback acpi_video0.
+ * If another driver still deems this necessary, it can explicitly register it.
+ */
+void acpi_video_report_nolcd(void)
+{
+	cancel_delayed_work(&video_bus_register_backlight_work);
+}
+EXPORT_SYMBOL(acpi_video_report_nolcd);
+

Thanks for removing the desktop check.

Sure.

Quoted 9 lines

It's not entirely clear to me what happens if you try to cancel a delayed work that was never scheduled. I got as far as determining that del_timer() in kernel/time/timer.c will probably return 0, but I didn't really feel like walking through the rest of try_to_grab_pending() to figure out what happens next. You've probably already tested this with the default disabled timer, so as long as nothing bad happened there, this seems fine.

Yeah; I did test it and nothing blew up during my test.

Quoted 7 lines

This is probably overly complicated, so if you think it's worth doing, I would definitely add it later, but I wonder if it might make sense to pass an acpi_handle to a _BC[LM] method or one of its parents, so that this could be scoped to a particular device. Looking at the ACPI table dump from a random multi-GPU laptop, it looks like there are two instances of _BCL, one under _SB.GP<number>.VGA.LCD for the iGPU, and the other under _SB.PCI<num>.GPP<num>.PEGP.EDP<num> for the dGPU. The

Quoted 8 lines

caller would pass in handles for methods/devices that it will handle, and then the fallback, if it runs at all, would skip any handles that were registered with it when it crawls for _BC[LM]. Or the equivalent inverse logic, or something else like that. I think it's probably fine to keep the current unscoped design and just assert that any other GPU drivers that want the ACPI video driver to handle panel backlight should register it explicitly; if for some reason that ends up not working out, we could revisit scoping it then.

Yeah that is a lot more complex but complete setup. I think if we end up having to revert the 3rd patch and having GPU drivers call the registration explicitly isn't a good idea for some reason it's worth considering.

Quoted 27 lines
Quoted 27 lines
drivers/acpi/acpi_video.c +0 -0
  int acpi_video_register(void)
  {
  	int ret = 0;
include/acpi/video.h +2 -0
index a275c35e5249..a56c8d45e9f8 100644
@@ -53,6 +53,7 @@ enum acpi_backlight_type {
  };
 
  #if IS_ENABLED(CONFIG_ACPI_VIDEO)
+extern void acpi_video_report_nolcd(void);
  extern int acpi_video_register(void);
  extern void acpi_video_unregister(void);
  extern void acpi_video_register_backlight(void);
@@ -69,6 +70,7 @@ extern int acpi_video_get_levels(struct acpi_device *device,
  				 struct acpi_video_device_brightness **dev_br,
  				 int *pmax_level);
  #else
+static inline void acpi_video_report_nolcd(void) { return; };
  static inline int acpi_video_register(void) { return -ENODEV; }
  static inline void acpi_video_unregister(void) { return; }
  static inline void acpi_video_register_backlight(void) { return; }
Signature · 1 line
2.34.1
#4 lore raw

PATCH v3 2/3 drm/amd/display: Report to ACPI video if no panels were found

In reply to Mario Limonciello

On desktop APUs amdgpu doesn't create a native backlight device as no eDP panels are found. However if the BIOS has reported backlight control methods in the ACPI tables then an acpi_video0 backlight device will be made 8 seconds after boot.

This has manifested in a power slider on a number of desktop APUs ranging from Ryzen 5000 through Ryzen 7000 on various motherboard manufacturers. To avoid this, report to the acpi video detection that the system does not have any panel connected in the native driver.

---
v2->v3:
* Add Hans' R-b
v1->v2:
* No changes

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -0
index 512c32327eb1..b73f61ac5dd5 100644
@@ -4371,6 +4371,10 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
 		amdgpu_set_panel_orientation(&aconnector->base);
 	}
 
+	/* If we didn't find a panel, notify the acpi video detection */
+	if (dm->adev->flags & AMD_IS_APU && dm->num_of_edps == 0)
+		acpi_video_report_nolcd();
+
 	/* Software is initialized. Now we can register interrupt handlers. */
 	switch (adev->asic_type) {
 #if defined(CONFIG_DRM_AMD_DC_SI)
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 2/3
#5 lore raw

Re: [PATCH v3 2/3] drm/amd/display: Report to ACPI video if no panels were found

Quoted 11 lines · Mario Limonciello

On desktop APUs amdgpu doesn't create a native backlight device as no eDP panels are found. However if the BIOS has reported backlight control methods in the ACPI tables then an acpi_video0 backlight device will be made 8 seconds after boot.

This has manifested in a power slider on a number of desktop APUs ranging from Ryzen 5000 through Ryzen 7000 on various motherboard manufacturers. To avoid this, report to the acpi video detection that the system does not have any panel connected in the native driver.

Quoted 4 lines

Harry

Quoted 24 lines

---
v2->v3:
* Add Hans' R-b
v1->v2:
* No changes

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -0
index 512c32327eb1..b73f61ac5dd5 100644
@@ -4371,6 +4371,10 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
 		amdgpu_set_panel_orientation(&aconnector->base);
 	}
 
+	/* If we didn't find a panel, notify the acpi video detection */
+	if (dm->adev->flags & AMD_IS_APU && dm->num_of_edps == 0)
+		acpi_video_report_nolcd();
+
 	/* Software is initialized. Now we can register interrupt handlers. */
 	switch (adev->asic_type) {
 #if defined(CONFIG_DRM_AMD_DC_SI)
#6 lore raw

PATCH v3 3/3 ACPI: video: Don't enable fallback path for creating ACPI backlight by default

In reply to Mario Limonciello

The ACPI video detection code has a module parameter register_backlight_delay which is currently configured to 8 seconds. This means that if after 8 seconds of booting no native driver has created a backlight device then the code will attempt to make an ACPI video backlight device.

This was intended as a safety mechanism with the backlight overhaul that occurred in kernel 6.1, but as it doesn't appear necesssary set it to be disabled by default.

---
v2->v3:
* Add Hans' R-b
v1->v2:
* New patch

---
 drivers/acpi/acpi_video.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/acpi/acpi_video.c +1 -5
index f64fdb029090..0c79f463fbfd 100644
@@ -70,11 +70,7 @@ module_param(device_id_scheme, bool, 0444);
 static int only_lcd = -1;
 module_param(only_lcd, int, 0444);
 
-/*
- * Display probing is known to take up to 5 seconds, so delay the fallback
- * backlight registration by 5 seconds + 3 seconds for some extra margin.
- */
-static int register_backlight_delay = 8;
+static int register_backlight_delay;
 module_param(register_backlight_delay, int, 0444);
 MODULE_PARM_DESC(register_backlight_delay,
 	"Delay in seconds before doing fallback (non GPU driver triggered) "
Signature · 1 line
2.34.1
#7 lore raw
In reply to Mario Limonciello

[Public]

Quoted 55 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Thursday, December 8, 2022 10:42
To: Rafael J . Wysocki <[email protected]>; Deucher, Alexander <[email protected]>; Hans de Goede <[email protected]>
Cc: [email protected]; [email protected]; Daniel Dadap <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 0/3] Adjust ACPI video detection fallback path

In kernel 6.1 the backlight registration code was overhauled so that at most one backlight device got registered. As part of this change there was code added to still allow making an acpi_video0 device if the BIOS contained backlight control methods but no native or vendor drivers registered.

Even after the overhaul this fallback logic is failing on the BIOS from a number of motherboard manufacturers supporting Ryzen APUs. What happens is the amdgpu driver finishes registration and as expected doesn't create a backlight control device since no eDP panels are connected to a desktop.

Then 8 seconds later the ACPI video detection code creates an acpi_video0 device that is non-operational. GNOME then creates a backlight slider.

To avoid this situation from happening make two sets of changes:

Prevent desktop problems w/ fallback logic
------------------------------------------
1) Add support for the video detect code to let native drivers cancel the fallback logic if they didn't find a panel.

This is done this way so that if another driver decides that the ACPI mechanism is still needed it can instead directly call the registration function.

2) Add code to amdgpu to notify the ACPI video detection code that no panel was detected on an APU.

Disable fallback logic by default
---------------------------------
This fallback logic was introduced to prevent regressions in the backlight overhaul. As it has been deemed unnecessary by Hans explicitly disable the timeout. If this turns out to be mistake and this part is reverted, the other patches for preventing desktop problems will avoid regressions on desktops.

Mario Limonciello (3):
ACPI: video: Allow GPU drivers to report no panels drm/amd/display: Report to ACPI video if no panels were found
ACPI: video: Don't enable fallback path for creating ACPI backlight by
default

Quoted 7 lines
 drivers/acpi/acpi_video.c                       | 17 ++++++++++++-----
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c   |  4 ++++
 include/acpi/video.h                            |  2 ++
 3 files changed, 18 insertions(+), 5 deletions(-)

--
2.34.1

FYI, besides me, this series also tested successfully by one of the reporters to the Red Hat bugzilla.

https://bugzilla.redhat.com/show_bug.cgi?id=1783786#c8

#8 lore raw
Quoted 63 lines · Mario

[Public]

Quoted 60 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Thursday, December 8, 2022 10:42
To: Rafael J . Wysocki <[email protected]>; Deucher, Alexander <[email protected]>; Hans de Goede <[email protected]>
Cc: [email protected]; [email protected]; Daniel Dadap <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 0/3] Adjust ACPI video detection fallback path

In kernel 6.1 the backlight registration code was overhauled so that at most one backlight device got registered. As part of this change there was code added to still allow making an acpi_video0 device if the BIOS contained backlight control methods but no native or vendor drivers registered.

Even after the overhaul this fallback logic is failing on the BIOS from a number of motherboard manufacturers supporting Ryzen APUs. What happens is the amdgpu driver finishes registration and as expected doesn't create a backlight control device since no eDP panels are connected to a desktop.

Then 8 seconds later the ACPI video detection code creates an acpi_video0 device that is non-operational. GNOME then creates a backlight slider.

To avoid this situation from happening make two sets of changes:

Prevent desktop problems w/ fallback logic
------------------------------------------
1) Add support for the video detect code to let native drivers cancel the fallback logic if they didn't find a panel.

This is done this way so that if another driver decides that the ACPI mechanism is still needed it can instead directly call the registration function.

2) Add code to amdgpu to notify the ACPI video detection code that no panel was detected on an APU.

Disable fallback logic by default
---------------------------------
This fallback logic was introduced to prevent regressions in the backlight overhaul. As it has been deemed unnecessary by Hans explicitly disable the timeout. If this turns out to be mistake and this part is reverted, the other patches for preventing desktop problems will avoid regressions on desktops.

Mario Limonciello (3):
ACPI: video: Allow GPU drivers to report no panels drm/amd/display: Report to ACPI video if no panels were found
ACPI: video: Don't enable fallback path for creating ACPI backlight by
default

 drivers/acpi/acpi_video.c                       | 17 ++++++++++++-----
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c   |  4 ++++
 include/acpi/video.h                            |  2 ++
 3 files changed, 18 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 2 lines

--
2.34.1

FYI, besides me, this series also tested successfully by one of the reporters to the Red Hat bugzilla.

https://bugzilla.redhat.com/show_bug.cgi?id=1783786#c8

Thanks for letting me know!

I'll queue it up for 6.2-rc next week.

#9 lore raw
Quoted 69 lines · Rafael J. Wysocki
Quoted 66 lines · Mario

[Public]

Quoted 62 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Thursday, December 8, 2022 10:42
To: Rafael J . Wysocki <[email protected]>; Deucher, Alexander <[email protected]>; Hans de Goede <[email protected]>
Cc: [email protected]; [email protected]; Daniel Dadap <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 0/3] Adjust ACPI video detection fallback path

In kernel 6.1 the backlight registration code was overhauled so that at most one backlight device got registered. As part of this change there was code added to still allow making an acpi_video0 device if the BIOS contained backlight control methods but no native or vendor drivers registered.

Even after the overhaul this fallback logic is failing on the BIOS from a number of motherboard manufacturers supporting Ryzen APUs. What happens is the amdgpu driver finishes registration and as expected doesn't create a backlight control device since no eDP panels are connected to a desktop.

Then 8 seconds later the ACPI video detection code creates an acpi_video0 device that is non-operational. GNOME then creates a backlight slider.

To avoid this situation from happening make two sets of changes:

Prevent desktop problems w/ fallback logic
------------------------------------------
1) Add support for the video detect code to let native drivers cancel the fallback logic if they didn't find a panel.

This is done this way so that if another driver decides that the ACPI mechanism is still needed it can instead directly call the registration function.

2) Add code to amdgpu to notify the ACPI video detection code that no panel was detected on an APU.

Disable fallback logic by default
---------------------------------
This fallback logic was introduced to prevent regressions in the backlight overhaul. As it has been deemed unnecessary by Hans explicitly disable the timeout. If this turns out to be mistake and this part is reverted, the other patches for preventing desktop problems will avoid regressions on desktops.

Mario Limonciello (3):
ACPI: video: Allow GPU drivers to report no panels drm/amd/display: Report to ACPI video if no panels were found
ACPI: video: Don't enable fallback path for creating ACPI backlight by
default

 drivers/acpi/acpi_video.c                       | 17 ++++++++++++-----
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c   |  4 ++++
 include/acpi/video.h                            |  2 ++
 3 files changed, 18 insertions(+), 5 deletions(-)

--
2.34.1

Quoted 8 lines
Quoted 4 lines

FYI, besides me, this series also tested successfully by one of the reporters to the Red Hat bugzilla.

https://bugzilla.redhat.com/show_bug.cgi?id=1783786#c8

Thanks for letting me know!

I'll queue it up for 6.2-rc next week.

Done now, thanks!