Skip to contentSkip to conversation

ACPI: utils: Introduce acpi_match_video_device_handle() helper

PATCH In review Andy Shevchenko 4 participants 10 messages Jun 30, 2022 – Jul 8, 2022

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

PATCH 1/5 ACPI: utils: Introduce acpi_match_video_device_handle() 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_match_video_device_handle() helper's hood.

---
 drivers/acpi/utils.c | 19 +++++++++++++++++++
 include/linux/acpi.h |  2 ++
 2 files changed, 21 insertions(+)
drivers/acpi/utils.c +19 -0
index 3a9773a09e19..4800aba3b99c 100644
@@ -929,6 +929,25 @@ static int __init acpi_backlight(char *str)
 }
 __setup("acpi_backlight=", acpi_backlight);
 
+static const struct acpi_device_id video_device_ids[] = {
+	{ACPI_VIDEO_HID, 0},
+	{}
+};
+
+/**
+ * acpi_match_video_device_handle - match handle against ACPI video device IDs
+ * @handle: ACPI handle to match
+ *
+ * Return: true when matches, otherwise false.
+ */
+bool acpi_match_video_device_handle(acpi_handle handle)
+{
+	struct acpi_device *adev = acpi_fetch_acpi_dev(handle);
+
+	return adev && !acpi_match_device_ids(adev, video_device_ids);
+}
+EXPORT_SYMBOL(acpi_match_video_device_handle);
+
 /**
  * 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 +2 -0
index 7b96a8bff6d2..c48e8a0df0cc 100644
@@ -439,6 +439,8 @@ extern char *wmi_get_acpi_device_uid(const char *guid);
 
 extern char acpi_video_backlight_string[];
 extern long acpi_is_video_device(acpi_handle handle);
+extern bool acpi_match_video_device_handle(acpi_handle handle);
+
 extern int acpi_blacklisted(void);
 extern void acpi_osi_setup(char *str);
 extern bool acpi_osi_is_win8(void);
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/5 ACPI: video: Convert to use acpi_match_video_device_handle() helper

Replace open coded variant of acpi_match_video_device_handle() helper.

---
 drivers/acpi/video_detect.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/acpi/video_detect.c +1 -7
index becc198e4c22..14ddbd821a46 100644
@@ -59,16 +59,10 @@ static void acpi_video_parse_cmdline(void)
 static acpi_status
 find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
-	struct acpi_device *acpi_dev = acpi_fetch_acpi_dev(handle);
 	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_match_video_device_handle(handle)) {
 		dev = acpi_get_pci_dev(handle);
 		if (!dev)
 			return AE_OK;
Signature · 1 line
2.35.1
#2 lore raw

PATCH 3/5 i2c: acpi: Convert to use acpi_match_video_device_handle() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_match_video_device_handle() helper.

---
 drivers/i2c/i2c-core-acpi.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/i2c/i2c-core-acpi.c +5 -10
index 08b561f0709d..e6de54dec010 100644
@@ -128,15 +128,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 },
-	{}
-};
-
 static int i2c_acpi_do_lookup(struct acpi_device *adev,
 			      struct i2c_acpi_lookup *lookup)
 {
@@ -150,7 +141,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_match_video_device_handle(adev->handle))
 		return -ENODEV;
 
 	memset(info, 0, sizeof(*info));
Signature · 1 line
2.35.1
#4 lore raw

PATCH 4/5 PCI/VGA: Convert to use acpi_match_video_device_handle() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_match_video_device_handle() helper.

---
 drivers/pci/vgaarb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/vgaarb.c +1 -3
index f80b6ec88dc3..47058f70c2c9 100644
@@ -585,9 +585,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_match_video_device_handle(ACPI_HANDLE(dev));
 #else
 	return false;
 #endif
Signature · 1 line
2.35.1
#5 lore raw

PATCH 5/5 platform/x86: thinkpad_acpi: Convert to use acpi_match_video_device_handle() helper

In reply to Andy Shevchenko

Replace open coded variant of acpi_match_video_device_handle() helper.

---
 drivers/platform/x86/thinkpad_acpi.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +1 -3
index 22d4e8633e30..624cb9436522 100644
@@ -748,9 +748,7 @@ static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle,
 			u32 level, void *context, void **return_value)
 {
 	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_match_video_device_handle(handle))
 			return AE_OK;
 	}
 
Signature · 1 line
2.35.1
#6 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 2 lines · Andy Shevchenko

extern long acpi_is_video_device(acpi_handle handle);
+extern bool acpi_match_video_device_handle(acpi_handle handle);

I think we can do slightly better here. The only caller of acpi_is_video_device() is in drivers/acpi/video_detect.c so we can move it there and make it static (is_video_device()).

Then we can name this one acpi_is_video_device() instead and in addition make it take struct acpi_device as parameter instead of acpi_handle (I think we should not use acpi_handles in drivers if possible).

#7 lore raw
Quoted 7 lines · Mika Westerberg

Hi Andy,

Quoted 2 lines · Andy Shevchenko

extern long acpi_is_video_device(acpi_handle handle);
+extern bool acpi_match_video_device_handle(acpi_handle handle);

Quoted 7 lines

I think we can do slightly better here. The only caller of acpi_is_video_device() is in drivers/acpi/video_detect.c so we can move it there and make it static (is_video_device()).

Then we can name this one acpi_is_video_device() instead and in addition make it take struct acpi_device as parameter instead of acpi_handle (I think we should not use acpi_handles in drivers if possible).

Agreed.

#8 lore raw
Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Mika Westerberg
Quoted 2 lines · Andy Shevchenko

extern long acpi_is_video_device(acpi_handle handle);
+extern bool acpi_match_video_device_handle(acpi_handle handle);

I think we can do slightly better here. The only caller of acpi_is_video_device() is in drivers/acpi/video_detect.c so we can move it there and make it static (is_video_device()).

AFAICS, the scan.c is user of it as well.

Quoted 5 lines
Quoted 3 lines

Then we can name this one acpi_is_video_device() instead and in addition make it take struct acpi_device as parameter instead of acpi_handle (I think we should not use acpi_handles in drivers if possible).

Agreed.

Not sure it will help to have acpi device since most of the callers asks for handle to be checked.

Taking into account above, what we can do is to rename it to

acpi_handle_is_video_device()

which should be clearer than initial proposal.

Thoughts?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line · Mika Westerberg

On Fri, Jul 01, 2022 at 12:28:15AM +0300, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

extern long acpi_is_video_device(acpi_handle handle);
+extern bool acpi_match_video_device_handle(acpi_handle handle);

I think we can do slightly better here. The only caller of acpi_is_video_device() is in drivers/acpi/video_detect.c so we can move it there and make it static (is_video_device()).

AFAICS, the scan.c is user of it as well.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Then we can name this one acpi_is_video_device() instead and in addition make it take struct acpi_device as parameter instead of acpi_handle (I think we should not use acpi_handles in drivers if possible).

Agreed.

Not sure it will help to have acpi device since most of the callers asks for handle to be checked.

Actually it's 2:2 now. I'm fine with ACPI device and name like

acpi_dev_is_video_device()

Quoted 7 lines

Taking into account above, what we can do is to rename it to

acpi_handle_is_video_device()

which should be clearer than initial proposal.

Thoughts?

Signature · 2 lines
With Best Regards,
Andy Shevchenko