Skip to contentSkip to conversation

ACPI: sysfs: Add device cid attribute for exposing _CID lists

PATCH Superseded Rafael J. Wysocki 2 participants 3 messages Dec 12, 2025 – Dec 29, 2025 ACPI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 ACPI: sysfs: Add device cid attribute for exposing _CID lists

From: Rafael J. Wysocki <[email protected]>

Add a new sysfs attribute called "cid" under struct acpi_device for exposing the list of compatible device IDs returned by the device's _CID object, if present.

The new attribute will be present only if the _CID object is present.

---
 drivers/acpi/device_sysfs.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/acpi/device_sysfs.c +31 -0
@@ -403,6 +403,33 @@ hid_show(struct device *dev, struct devi
 }
 static DEVICE_ATTR_RO(hid);
 
+static ssize_t cid_show(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	struct acpi_device_info *info = NULL;
+	ssize_t len = 0;
+
+	acpi_get_object_info(acpi_dev->handle, &info);
+	if (!info)
+		return 0;
+
+	if (info->valid & ACPI_VALID_CID) {
+		struct acpi_pnp_device_id_list *cid_list = &info->compatible_id_list;
+		int i;
+
+		for (i = 0; i < cid_list->count - 1; i++)
+			len += sysfs_emit(buf, "%s,", cid_list->ids[i].string);
+
+		len += sysfs_emit(buf, "%s\n", cid_list->ids[i].string);
+	}
+
+	kfree(info);
+
+	return len;
+}
+static DEVICE_ATTR_RO(cid);
+
 static ssize_t uid_show(struct device *dev,
 			struct device_attribute *attr, char *buf)
 {
@@ -520,6 +547,7 @@ static DEVICE_ATTR_RO(status);
 static struct attribute *acpi_attrs[] = {
 	&dev_attr_path.attr,
 	&dev_attr_hid.attr,
+	&dev_attr_cid.attr,
 	&dev_attr_modalias.attr,
 	&dev_attr_description.attr,
 	&dev_attr_adr.attr,
@@ -562,6 +590,9 @@ static bool acpi_show_attr(struct acpi_d
 	if (attr == &dev_attr_status)
 		return acpi_has_method(dev->handle, "_STA");
 
+	if (attr == &dev_attr_cid)
+		return acpi_has_method(dev->handle, "_CID");
+
 	/*
 	 * If device has _EJ0, 'eject' file is created that is used to trigger
 	 * hot-removal function from userland.
#1 lore raw
Quoted 7 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Add a new sysfs attribute called "cid" under struct acpi_device for exposing the list of compatible device IDs returned by the device's _CID object, if present.

The new attribute will be present only if the _CID object is present.

...

Quoted 9 lines
drivers/acpi/device_sysfs.c +9 -0
+static ssize_t cid_show(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	struct acpi_device_info *info = NULL;
+	ssize_t len = 0;
+
+	acpi_get_object_info(acpi_dev->handle, &info);
+	if (!info)

drivers/acpi/device_sysfs.c hid_show(struct device *dev, struct devi · line 424

Quoted 10 lines
drivers/acpi/device_sysfs.c +10 -0
+		return 0;
+
+	if (info->valid & ACPI_VALID_CID) {
+		struct acpi_pnp_device_id_list *cid_list = &info->compatible_id_list;
+		int i;
+
+		for (i = 0; i < cid_list->count - 1; i++)
+			len += sysfs_emit(buf, "%s,", cid_list->ids[i].string);
+
+		len += sysfs_emit(buf, "%s\n", cid_list->ids[i].string);

You definitely meant to use sysfs_emit_at().

drivers/acpi/device_sysfs.c hid_show(struct device *dev, struct devi · line 431

Quoted 7 lines
drivers/acpi/device_sysfs.c +7 -0
+	}
+
+	kfree(info);
+
+	return len;
+}
+static DEVICE_ATTR_RO(cid);

Do wee have any ABI documentation for these sysfs attributes? If so, it needs to be updated, otherwise perhaps create one?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#2 lore raw
Quoted 25 lines · Andy Shevchenko
Quoted 7 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Add a new sysfs attribute called "cid" under struct acpi_device for exposing the list of compatible device IDs returned by the device's _CID object, if present.

The new attribute will be present only if the _CID object is present.

...

Quoted 13 lines
drivers/acpi/device_sysfs.c +13 -0
+static ssize_t cid_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
+{
+     struct acpi_device *acpi_dev = to_acpi_device(dev);
+     struct acpi_device_info *info = NULL;
+     ssize_t len = 0;
+
+     acpi_get_object_info(acpi_dev->handle, &info);
+     if (!info)
+             return 0;
+
+     if (info->valid & ACPI_VALID_CID) {
+             struct acpi_pnp_device_id_list *cid_list = &info->compatible_id_list;
Quoted 8 lines

drivers/acpi/device_sysfs.c hid_show(struct device *dev, struct devi · line 424

Quoted 6 lines
drivers/acpi/device_sysfs.c +6 -0
+             int i;
+
+             for (i = 0; i < cid_list->count - 1; i++)
+                     len += sysfs_emit(buf, "%s,", cid_list->ids[i].string);
+
+             len += sysfs_emit(buf, "%s\n", cid_list->ids[i].string);

You definitely meant to use sysfs_emit_at().

Right, thanks!

Quoted 9 lines

drivers/acpi/device_sysfs.c hid_show(struct device *dev, struct devi · line 431

Quoted 7 lines
drivers/acpi/device_sysfs.c +7 -0
+     }
+
+     kfree(info);
+
+     return len;
+}
+static DEVICE_ATTR_RO(cid);

Do wee have any ABI documentation for these sysfs attributes?

No, there's none I know of.

Quoted 1 line

If so, it needs to be updated, otherwise perhaps create one?

Well, feel free to do so.