Skip to contentSkip to conversation

ACPI: Introduce and use acpi_dev_is_video_device() helper

PATCH Applied Andy Shevchenko 5 participants 18 messages Jul 14 – Jul 28

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

v2 cover ACPI: Introduce and use acpi_dev_is_video_device() helper

There are a few users that open code functionality of matching a given device against ACPI video device IDs. The current approach duplicates ID table along with the matching code. Consolidate it under the acpi_dev_is_video_device() helper's hood.

Supposed to go via ACPI tree, please ack.

Changelog v2:
- rebased on top of the latest code base
- renamed helper and changed its prototype (Rafael, Mika)
- added tag (Wolfram)
- added patch to change scan.c as well

v1: [email protected]

Andy Shevchenko (6):
ACPI: utils: Introduce acpi_dev_is_video_device() helper
ACPI: scan: Convert to use acpi_dev_is_video_device() helper
ACPI: video: Convert to use acpi_dev_is_video_device() helper
i2c: acpi: Convert to use acpi_dev_is_video_device() helper PCI/VGA: Convert to use acpi_dev_is_video_device() helper platform/x86: thinkpad_acpi: Convert to use acpi_dev_is_video_device()
helper

 drivers/acpi/scan.c                         |  4 +++-
 drivers/acpi/utils.c                        | 17 +++++++++++++++++
 drivers/acpi/video_detect.c                 |  7 +------
 drivers/i2c/i2c-core-acpi.c                 | 15 +++++----------
 drivers/pci/vgaarb.c                        |  4 +---
 drivers/platform/x86/lenovo/thinkpad_acpi.c |  2 +-
 include/linux/acpi.h                        |  1 +
 7 files changed, 29 insertions(+), 21 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/6 ACPI: utils: Introduce acpi_dev_is_video_device() helper

There are a couple of users that open code functionality of matching a given handle against ACPI video device IDs. The current approach duplicates ID table along with the matching code. Consolidate it under the acpi_dev_is_video_device() helper's hood.

---
 drivers/acpi/utils.c | 17 +++++++++++++++++
 include/linux/acpi.h |  1 +
 2 files changed, 18 insertions(+)
drivers/acpi/utils.c +17 -0
index 6ab27e4826d1..8b3e49f3cefa 100644
@@ -1047,6 +1047,23 @@ static int __init acpi_backlight(char *str)
 }
 __setup("acpi_backlight=", acpi_backlight);
 
+static const struct acpi_device_id video_device_ids[] = {
+	{ .id = ACPI_VIDEO_HID },
+	{ }
+};
+
+/**
+ * acpi_dev_is_video_device - test if device matches against ACPI video device IDs
+ * @adev: ACPI device to test
+ *
+ * Return: true when matches, otherwise false.
+ */
+bool acpi_dev_is_video_device(struct acpi_device *adev)
+{
+	return adev && !acpi_match_device_ids(adev, video_device_ids);
+}
+EXPORT_SYMBOL(acpi_dev_is_video_device);
+
 /**
  * acpi_match_platform_list - Check if the system matches with a given list
  * @plat: pointer to acpi_platform_list table terminated by a NULL entry
include/linux/acpi.h +1 -0
index 899dc00b4b01..99afad0eb49e 100644
@@ -457,6 +457,7 @@ extern char *wmi_get_acpi_device_uid(const char *guid);
 #define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VIDEO		0x0800
 
 extern char acpi_video_backlight_string[];
+extern bool acpi_dev_is_video_device(struct acpi_device *adev);
 extern long acpi_is_video_device(acpi_handle handle);
 
 extern void acpi_osi_setup(char *str);
Signature · 1 line
2.50.1
#2 lore raw

Re: [PATCH v2 1/6] ACPI: utils: Introduce acpi_dev_is_video_device() helper

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

There are a couple of users that open code functionality of matching a given handle against ACPI video device IDs. The current approach duplicates ID table along with the matching code. Consolidate it under the acpi_dev_is_video_device() helper's hood.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v2 2/6 ACPI: scan: Convert to use acpi_dev_is_video_device() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_dev_is_video_device() helper.

---
 drivers/acpi/scan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/scan.c +3 -1
index 2f6185dbe785..ef9995bac746 100644
@@ -1764,7 +1764,6 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
 	 * Some ACPI devs contain SerialBus resources even though they are not
 	 * attached to a serial bus at all.
 	 */
-		{ACPI_VIDEO_HID, },
 		{"MSHW0028", },
 	/*
 	 * HIDs of device with an UartSerialBusV2 resource for which userspace
@@ -1787,6 +1786,9 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
 	     fwnode_property_present(&device->fwnode, "baud")))
 		return true;
 
+	if (acpi_dev_is_video_device(device))
+		return false;
+
 	if (!acpi_match_device_ids(device, ignore_serial_bus_ids))
 		return false;
 
Signature · 1 line
2.50.1
#4 lore raw

Re: [PATCH v2 2/6] ACPI: scan: Convert to use acpi_dev_is_video_device() helper

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 3 lines

Replace open coded variant of acpi_dev_is_video_device() helper.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH v2 3/6 ACPI: video: Convert to use acpi_dev_is_video_device() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_dev_is_video_device() helper.

---
 drivers/acpi/video_detect.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/video_detect.c +1 -6
index 458efa4fe9d4..cf267b518d2b 100644
@@ -67,12 +67,7 @@ find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
 	long *cap = context;
 	struct pci_dev *dev;
 
-	static const struct acpi_device_id video_ids[] = {
-		{ACPI_VIDEO_HID, 0},
-		{"", 0},
-	};
-
-	if (acpi_dev && !acpi_match_device_ids(acpi_dev, video_ids)) {
+	if (acpi_dev_is_video_device(acpi_dev)) {
 		dev = acpi_get_pci_dev(handle);
 		if (!dev)
 			return AE_OK;
Signature · 1 line
2.50.1
#6 lore raw

Re: [PATCH v2 3/6] ACPI: video: Convert to use acpi_dev_is_video_device() helper

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 3 lines

Replace open coded variant of acpi_dev_is_video_device() helper.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH v2 4/6 i2c: acpi: Convert to use acpi_dev_is_video_device() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_dev_is_video_device() helper.

---
 drivers/i2c/i2c-core-acpi.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/i2c/i2c-core-acpi.c +5 -10
index 10cdceaba475..8f3bdd50186e 100644
@@ -131,15 +131,6 @@ static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data)
 	return 1;
 }
 
-static const struct acpi_device_id i2c_acpi_ignored_device_ids[] = {
-	/*
-	 * ACPI video acpi_devices, which are handled by the acpi-video driver
-	 * sometimes contain a SERIAL_TYPE_I2C ACPI resource, ignore these.
-	 */
-	{ ACPI_VIDEO_HID, 0 },
-	{}
-};
-
 struct i2c_acpi_irq_context {
 	int irq;
 	bool wake_capable;
@@ -158,7 +149,11 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,
 	if (!acpi_dev_ready_for_enumeration(adev))
 		return -ENODEV;
 
-	if (acpi_match_device_ids(adev, i2c_acpi_ignored_device_ids) == 0)
+	/*
+	 * ACPI video devices, which are handled by the acpi-video driver,
+	 * sometimes contain a SERIAL_TYPE_I2C ACPI resource, ignore these.
+	 */
+	if (acpi_dev_is_video_device(adev))
 		return -ENODEV;
 
 	memset(info, 0, sizeof(*info));
Signature · 1 line
2.50.1
#8 lore raw

Re: [PATCH v2 4/6] i2c: acpi: Convert to use acpi_dev_is_video_device() helper

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

Replace open coded variant of acpi_dev_is_video_device() helper.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#10 lore raw

PATCH v2 5/6 PCI/VGA: Convert to use acpi_dev_is_video_device() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_dev_is_video_device() helper.

---
 drivers/pci/vgaarb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/vgaarb.c +1 -3
index c360eee11dd9..3de05aee7859 100644
@@ -575,9 +575,7 @@ static bool vga_is_firmware_default(struct pci_dev *pdev)
 static bool vga_arb_integrated_gpu(struct device *dev)
 {
 #if defined(CONFIG_ACPI)
-	struct acpi_device *adev = ACPI_COMPANION(dev);
-
-	return adev && !strcmp(acpi_device_hid(adev), ACPI_VIDEO_HID);
+	return acpi_dev_is_video_device(ACPI_COMPANION(dev));
 #else
 	return false;
 #endif
Signature · 1 line
2.50.1
#11 lore raw

Re: [PATCH v2 5/6] PCI/VGA: Convert to use acpi_dev_is_video_device() helper

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 3 lines

Replace open coded variant of acpi_dev_is_video_device() helper.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
maintainer
#12 lore raw

Re: [PATCH v2 5/6] PCI/VGA: Convert to use acpi_dev_is_video_device() helper

In reply to Andy Shevchenko
Quoted 12 lines · Andy Shevchenko

Replace open coded variant of acpi_dev_is_video_device() helper.

---
 drivers/pci/vgaarb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/vgaarb.c +0 -0
index c360eee11dd9..3de05aee7859 100644

drivers/pci/vgaarb.c static bool vga_is_firmware_default(struct pci_dev *pdev) · line 581

Quoted 10 lines
drivers/pci/vgaarb.c +1 -3
@@ -575,9 +575,7 @@ static bool vga_is_firmware_default(struct pci_dev *pdev)
 static bool vga_arb_integrated_gpu(struct device *dev)
 {
 #if defined(CONFIG_ACPI)
-	struct acpi_device *adev = ACPI_COMPANION(dev);
-
-	return adev && !strcmp(acpi_device_hid(adev), ACPI_VIDEO_HID);
+	return acpi_dev_is_video_device(ACPI_COMPANION(dev));
 #else
 	return false;
 #endif

How about adding a stub for acpi_dev_is_video_device() if !CONFIG_ACPI so this code can do without ifdeffery?

Signature · 1 line
 i.
#13 lore raw

Re: [PATCH v2 5/6] PCI/VGA: Convert to use acpi_dev_is_video_device() helper

Quoted 1 line · Ilpo Järvinen

On Tue, 14 Jul 2026, Andy Shevchenko wrote:

...

Quoted 11 lines

drivers/pci/vgaarb.c static bool vga_is_firmware_default(struct pci_dev *pdev) · line 581

Quoted 8 lines

#if defined(CONFIG_ACPI)

drivers/pci/vgaarb.c +1 -3
-	struct acpi_device *adev = ACPI_COMPANION(dev);
-
-	return adev && !strcmp(acpi_device_hid(adev), ACPI_VIDEO_HID);
+	return acpi_dev_is_video_device(ACPI_COMPANION(dev));
 #else
 	return false;
 #endif

How about adding a stub for acpi_dev_is_video_device() if !CONFIG_ACPI so this code can do without ifdeffery?

So far it's the only the case where it may gain something, but overall it's not required, all other current users already implied that. So, I do not see the value in this churn. When we have more such users, we may reconsider.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

PATCH v2 6/6 platform/x86: thinkpad_acpi: Convert to use acpi_dev_is_video_device() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_dev_is_video_device() helper.

---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/lenovo/thinkpad_acpi.c +1 -1
index 6dd7c28fc0db..aaeada46a0e7 100644
@@ -774,7 +774,7 @@ static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle,
 	if (!strcmp(context, "video")) {
 		struct acpi_device *dev = acpi_fetch_acpi_dev(handle);
 
-		if (!dev || strcmp(ACPI_VIDEO_HID, acpi_device_hid(dev)))
+		if (!acpi_dev_is_video_device(dev))
 			return AE_OK;
 	}
 
Signature · 1 line
2.50.1
#15 lore raw

Re: [PATCH v2 6/6] platform/x86: thinkpad_acpi: Convert to use acpi_dev_is_video_device() helper

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 3 lines

Replace open coded variant of acpi_dev_is_video_device() helper.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
maintainer Acked-by on v2 6/6
#16 lore raw

Re: [PATCH v2 6/6] platform/x86: thinkpad_acpi: Convert to use acpi_dev_is_video_device() helper

In reply to Andy Shevchenko
Quoted 12 lines · Andy Shevchenko

Replace open coded variant of acpi_dev_is_video_device() helper.

---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/lenovo/thinkpad_acpi.c +0 -0
index 6dd7c28fc0db..aaeada46a0e7 100644

drivers/platform/x86/lenovo/thinkpad_acpi.c static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle, · line 778

Quoted 6 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +1 -1
@@ -774,7 +774,7 @@ static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle,
 	if (!strcmp(context, "video")) {
 		struct acpi_device *dev = acpi_fetch_acpi_dev(handle);
 
-		if (!dev || strcmp(ACPI_VIDEO_HID, acpi_device_hid(dev)))
+		if (!acpi_dev_is_video_device(dev))
 			return AE_OK;
Signature · 1 line
 i.
maintainer Applied
#17 lore raw
In reply to Andy Shevchenko
Quoted 34 lines · Andy Shevchenko

There are a few users that open code functionality of matching a given device against ACPI video device IDs. The current approach duplicates ID table along with the matching code. Consolidate it under the acpi_dev_is_video_device() helper's hood.

Supposed to go via ACPI tree, please ack.

Changelog v2:
- rebased on top of the latest code base
- renamed helper and changed its prototype (Rafael, Mika)
- added tag (Wolfram)
- added patch to change scan.c as well

v1: [email protected]

Andy Shevchenko (6):
ACPI: utils: Introduce acpi_dev_is_video_device() helper
ACPI: scan: Convert to use acpi_dev_is_video_device() helper
ACPI: video: Convert to use acpi_dev_is_video_device() helper
i2c: acpi: Convert to use acpi_dev_is_video_device() helper PCI/VGA: Convert to use acpi_dev_is_video_device() helper platform/x86: thinkpad_acpi: Convert to use acpi_dev_is_video_device()
helper

 drivers/acpi/scan.c                         |  4 +++-
 drivers/acpi/utils.c                        | 17 +++++++++++++++++
 drivers/acpi/video_detect.c                 |  7 +------
 drivers/i2c/i2c-core-acpi.c                 | 15 +++++----------
 drivers/pci/vgaarb.c                        |  4 +---
 drivers/platform/x86/lenovo/thinkpad_acpi.c |  2 +-
 include/linux/acpi.h                        |  1 +
 7 files changed, 29 insertions(+), 21 deletions(-)
Quoted 1 line

--

Applied as 7.3 material with an adjustment in the first patch, thanks!