Skip to contentSkip to conversation

ACPI: Adds sysfs "ddn" attribute of the ACPI device objects to export its _DDN object.

PATCH Superseded Lv Zheng 2 participants 5 messages Mar 3, 2014 – Mar 6, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Lv Zheng

author
#1 lore raw

PATCH 1/1 ACPI: Adds sysfs "ddn" attribute of the ACPI device objects to export its _DDN object.

The information contained in _DDN (Dos Device Name) might be useful for userspace utilities, this patch thus exports such information using "ddn" attribute.
Note that the "ddn" attribute will be created as long as the _DDN identifying object exists, whatever its evaluation succeeds or not.

This patch must modify the code which is using "struct acpi_buffer" as the buffer.length must be reset to ACPI_ALLOCATE_BUFFER before reusing it to invoke acpi_evaluate_object() again.

Cc Arjan van de Ven <[email protected]>
---
 Documentation/ABI/testing/sysfs-bus-acpi |    7 +++++
 drivers/acpi/scan.c                      |   47 +++++++++++++++++++++++++++++-
 include/acpi/acpi_bus.h                  |    1 +
 3 files changed, 54 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-acpi +7 -0
index 7fa9cbc..db376b8 100644
@@ -49,6 +49,13 @@ Description:
 		This attribute contains the output of the device object's
 		_UID control method, if present.
 
+What:		/sys/bus/acpi/devices/.../ddn
+Date:		February 2014
+Contact:	Rafael J. Wysocki <[email protected]>
+Description:
+		This attribute contains the output of the device object's
+		_DDN control method, if present.
+
 What:		/sys/bus/acpi/devices/.../eject
 Date:		December 2006
 Contact:	Rafael J. Wysocki <[email protected]>
drivers/acpi/scan.c +46 -1

80 lines not on this page · raw message

include/acpi/acpi_bus.h +1 -0
index 9d82482..92cab35 100644
@@ -244,6 +244,7 @@ struct acpi_device_pnp {
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
 	union acpi_object *str_obj;	/* unicode string for _STR method */
+	char *ddn;			/* _DDN */
 	unsigned long sun;		/* _SUN */
 };
 
Signature · 1 line
1.7.10
#2 lore raw
Quoted 49 lines · Lv Zheng

The information contained in _DDN (Dos Device Name) might be useful for userspace utilities, this patch thus exports such information using "ddn" attribute.
Note that the "ddn" attribute will be created as long as the _DDN identifying object exists, whatever its evaluation succeeds or not.

This patch must modify the code which is using "struct acpi_buffer" as the buffer.length must be reset to ACPI_ALLOCATE_BUFFER before reusing it to invoke acpi_evaluate_object() again.

Cc Arjan van de Ven <[email protected]>

---

 Documentation/ABI/testing/sysfs-bus-acpi |    7 +++++
 drivers/acpi/scan.c                      |   47
 +++++++++++++++++++++++++++++- include/acpi/acpi_bus.h                  | 
   1 +
 3 files changed, 54 insertions(+), 1 deletion(-)

Patch

(quoted diff) +0 -0

b/Documentation/ABI/testing/sysfs-bus-acpi index 7fa9cbc..db376b8 100644

Documentation/ABI/testing/sysfs-bus-acpi +7 -0
@@ -49,6 +49,13 @@  Description:
 		This attribute contains the output of the device object's
 		_UID control method, if present.
 
+What:		/sys/bus/acpi/devices/.../ddn
+Date:		February 2014
+Contact:	Rafael J. Wysocki <[email protected]>
+Description:
+		This attribute contains the output of the device object's
+		_DDN control method, if present.
+
 
 What:		/sys/bus/acpi/devices/.../eject
 Date:		December 2006

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

drivers/acpi/scan.c +0 -0
index 4789c9b..5f039a6 100644

drivers/acpi/scan.c static ssize_t description_show(struct device *dev, · line 671

Quoted 10 lines
drivers/acpi/scan.c +6 -0
@@ -662,6 +662,18 @@  static ssize_t description_show(struct device *dev,
 
 }
 static DEVICE_ATTR(description, 0444, description_show, NULL);
 
+/* sysfs file that shows DOS device name text from the ACPI _DDN method */
+static ssize_t ddn_show(struct device *dev, struct device_attribute *attr,
+			char *buf) {
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+
+	if (acpi_dev->pnp.ddn == NULL)

Please use "if (!acpi_dev->pnp.ddn)"

Also, you can do

	return acpi_dev->pnp.ddn ? snprintf(buf, PAGE_SIZE, "%s\n", acpi_dev->pnp.ddn) : 0;
Quoted 58 lines
drivers/acpi/scan.c +6 -0
+		return 0;
+
+	return snprintf(buf, PAGE_SIZE, "%s\n", acpi_dev->pnp.ddn);
+}
+static DEVICE_ATTR(ddn, 0444, ddn_show, NULL);
+
 
 static ssize_t

acpi_device_sun_show(struct device *dev, struct device_attribute *attr,

drivers/acpi/scan.c +2 -1
 		     char *buf) {
@@ -687,10 +699,11 @@  static DEVICE_ATTR_RO(status);
 
 static int acpi_device_setup_files(struct acpi_device *dev)
 {
 
-	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+	struct acpi_buffer buffer;
 
 	acpi_status status;
 	unsigned long long sun;
 	int result = 0;
 
+	union acpi_object *object;
drivers/acpi/scan.c +2 -0
 	/*
 
 	 * Devices gotten from FADT don't have a "path" attribute
@@ -715,6 +728,8 @@  static int acpi_device_setup_files(struct acpi_device
 *dev)> 
 	 * If device has _STR, 'description' file is created
 	 */
 
 	if (acpi_has_method(dev->handle, "_STR")) {
 
+		buffer.length = ACPI_ALLOCATE_BUFFER;
+		buffer.pointer = NULL;
drivers/acpi/scan.c +6 -0
 		status = acpi_evaluate_object(dev->handle, "_STR",
 
 					NULL, &buffer);
 
 		if (ACPI_FAILURE(status))
@@ -725,6 +740,29 @@  static int acpi_device_setup_files(struct acpi_device
 *dev)> 
 			goto end;
 
 	}
 
+	/*
+	 * If device has _DDN, 'ddn' file is created
+	 */
+	if (acpi_has_method(dev->handle, "_DDN")) {
+		buffer.length = ACPI_ALLOCATE_BUFFER;
+		buffer.pointer = NULL;

drivers/acpi/scan.c static int acpi_device_setup_files(struct acpi_device · line 760

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+		status = acpi_evaluate_object_typed(dev->handle, "_DDN",
+						    NULL, &buffer,
+						    ACPI_TYPE_STRING);
+		if (ACPI_FAILURE(status))
+			buffer.pointer = NULL;
+		object = buffer.pointer;
+		if (object) {
+			dev->pnp.ddn = kstrndup(object->string.pointer,
+						object->string.length,
+						GFP_KERNEL);

Is the string guaranteed to be null-terminated after that?

Quoted 49 lines
drivers/acpi/scan.c +7 -0
+			kfree(object);
+		}
+		result = device_create_file(&dev->dev, &dev_attr_ddn);
+		if (result)
+			goto end;
+	}
+
 
drivers/acpi/scan.c +0 -0
 	if (dev->pnp.type.bus_address)
 
 		result = device_create_file(&dev->dev, &dev_attr_adr);
 
 	if (dev->pnp.unique_id)
@@ -787,6 +825,13 @@  static void acpi_device_remove_files(struct

acpi_device *dev)>

drivers/acpi/scan.c +7 -0
 		device_remove_file(&dev->dev, &dev_attr_description);
 
 	}
 	/*
 
+	 * If device has _DDN, remove 'ddn' file
+	 */
+	if (acpi_has_method(dev->handle, "_DDN")) {
+		device_remove_file(&dev->dev, &dev_attr_ddn);
+		kfree(dev->pnp.ddn);
+	}
+	/*
 
 	 * If device has _EJ0, remove 'eject' file.
 	 */
 
 	if (acpi_has_method(dev->handle, "_EJ0"))
include/acpi/acpi_bus.h +1 -0
index 9d82482..92cab35 100644
@@ -244,6 +244,7 @@  struct acpi_device_pnp {
 
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
 	union acpi_object *str_obj;	/* unicode string for _STR method */
 
+	char *ddn;			/* _DDN */
 

unsigned long sun; /* _SUN */

};

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
author
#3 lore raw

HI, Rafael

Thanks for commenting.

Quoted 66 lines

From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Monday, March 03, 2014 9:17 PM

Quoted 49 lines · Lv Zheng

The information contained in _DDN (Dos Device Name) might be useful for userspace utilities, this patch thus exports such information using "ddn" attribute.
Note that the "ddn" attribute will be created as long as the _DDN identifying object exists, whatever its evaluation succeeds or not.

This patch must modify the code which is using "struct acpi_buffer" as the buffer.length must be reset to ACPI_ALLOCATE_BUFFER before reusing it to invoke acpi_evaluate_object() again.

Cc Arjan van de Ven <[email protected]>

---

 Documentation/ABI/testing/sysfs-bus-acpi |    7 +++++
 drivers/acpi/scan.c                      |   47
 +++++++++++++++++++++++++++++- include/acpi/acpi_bus.h                  |
   1 +
 3 files changed, 54 insertions(+), 1 deletion(-)

Patch

(quoted diff) +0 -0

b/Documentation/ABI/testing/sysfs-bus-acpi index 7fa9cbc..db376b8 100644

Documentation/ABI/testing/sysfs-bus-acpi +7 -0
@@ -49,6 +49,13 @@  Description:
 		This attribute contains the output of the device object's
 		_UID control method, if present.
 
+What:		/sys/bus/acpi/devices/.../ddn
+Date:		February 2014
+Contact:	Rafael J. Wysocki <[email protected]>
+Description:
+		This attribute contains the output of the device object's
+		_DDN control method, if present.
+
 
 What:		/sys/bus/acpi/devices/.../eject
 Date:		December 2006

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

drivers/acpi/scan.c +0 -0
index 4789c9b..5f039a6 100644

drivers/acpi/scan.c static ssize_t description_show(struct device *dev, · line 671

Quoted 10 lines
drivers/acpi/scan.c +6 -0
@@ -662,6 +662,18 @@  static ssize_t description_show(struct device *dev,
 
 }
 static DEVICE_ATTR(description, 0444, description_show, NULL);
 
+/* sysfs file that shows DOS device name text from the ACPI _DDN method */
+static ssize_t ddn_show(struct device *dev, struct device_attribute *attr,
+			char *buf) {
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+
+	if (acpi_dev->pnp.ddn == NULL)

Please use "if (!acpi_dev->pnp.ddn)"

Quoted 3 lines

Also, you can do

	return acpi_dev->pnp.ddn ? snprintf(buf, PAGE_SIZE, "%s\n", acpi_dev->pnp.ddn) : 0;

OK, I'll update this.

Quoted 63 lines
Quoted 63 lines
drivers/acpi/scan.c +6 -0
+		return 0;
+
+	return snprintf(buf, PAGE_SIZE, "%s\n", acpi_dev->pnp.ddn);
+}
+static DEVICE_ATTR(ddn, 0444, ddn_show, NULL);
+
 
 static ssize_t

acpi_device_sun_show(struct device *dev, struct device_attribute *attr,

drivers/acpi/scan.c +2 -1
 		     char *buf) {
@@ -687,10 +699,11 @@  static DEVICE_ATTR_RO(status);
 
 static int acpi_device_setup_files(struct acpi_device *dev)
 {
 
-	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+	struct acpi_buffer buffer;
 
 	acpi_status status;
 	unsigned long long sun;
 	int result = 0;
 
+	union acpi_object *object;
drivers/acpi/scan.c +2 -0
 	/*
 
 	 * Devices gotten from FADT don't have a "path" attribute
@@ -715,6 +728,8 @@  static int acpi_device_setup_files(struct acpi_device
 *dev)>
 	 * If device has _STR, 'description' file is created
 	 */
 
 	if (acpi_has_method(dev->handle, "_STR")) {
 
+		buffer.length = ACPI_ALLOCATE_BUFFER;
+		buffer.pointer = NULL;
drivers/acpi/scan.c +10 -0
 		status = acpi_evaluate_object(dev->handle, "_STR",
 
 					NULL, &buffer);
 
 		if (ACPI_FAILURE(status))
@@ -725,6 +740,29 @@  static int acpi_device_setup_files(struct acpi_device
 *dev)>
 			goto end;
 
 	}
 
+	/*
+	 * If device has _DDN, 'ddn' file is created
+	 */
+	if (acpi_has_method(dev->handle, "_DDN")) {
+		buffer.length = ACPI_ALLOCATE_BUFFER;
+		buffer.pointer = NULL;
+		status = acpi_evaluate_object_typed(dev->handle, "_DDN",
+						    NULL, &buffer,
+						    ACPI_TYPE_STRING);
+		if (ACPI_FAILURE(status))
Quoted 8 lines

drivers/acpi/scan.c static int acpi_device_setup_files(struct acpi_device *dev) · line 758

Quoted 6 lines
drivers/acpi/scan.c +6 -0
+			buffer.pointer = NULL;
+		object = buffer.pointer;
+		if (object) {
+			dev->pnp.ddn = kstrndup(object->string.pointer,
+						object->string.length,
+						GFP_KERNEL);

Is the string guaranteed to be null-terminated after that?

Yes, ACPICA internal routines will use ACPI_STRNCPY and likewise to ensure this. I'll change it to kstrdup.

Thanks and best regards
-Lv

Quoted 55 lines
Quoted 49 lines
drivers/acpi/scan.c +7 -0
+			kfree(object);
+		}
+		result = device_create_file(&dev->dev, &dev_attr_ddn);
+		if (result)
+			goto end;
+	}
+
 
drivers/acpi/scan.c +0 -0
 	if (dev->pnp.type.bus_address)
 
 		result = device_create_file(&dev->dev, &dev_attr_adr);
 
 	if (dev->pnp.unique_id)
@@ -787,6 +825,13 @@  static void acpi_device_remove_files(struct

acpi_device *dev)>

drivers/acpi/scan.c +7 -0
 		device_remove_file(&dev->dev, &dev_attr_description);
 
 	}
 	/*
 
+	 * If device has _DDN, remove 'ddn' file
+	 */
+	if (acpi_has_method(dev->handle, "_DDN")) {
+		device_remove_file(&dev->dev, &dev_attr_ddn);
+		kfree(dev->pnp.ddn);
+	}
+	/*
 
 	 * If device has _EJ0, remove 'eject' file.
 	 */
 
 	if (acpi_has_method(dev->handle, "_EJ0"))
include/acpi/acpi_bus.h +1 -0
index 9d82482..92cab35 100644
@@ -244,6 +244,7 @@  struct acpi_device_pnp {
 
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
 	union acpi_object *str_obj;	/* unicode string for _STR method */
 
+	char *ddn;			/* _DDN */
 

unsigned long sun; /* _SUN */

Quoted 1 line

};

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

author
#4 lore raw

PATCH v2 1/1 ACPI: Adds sysfs "ddn" attribute of the ACPI device objects to export its _DDN object.

In reply to Lv Zheng

The information contained in _DDN (Dos Device Name) might be useful for userspace utilities, this patch thus exports such information using "ddn" attribute.
Note that the "ddn" attribute will be created as long as the _DDN identifying object exists, whatever its evaluation succeeds or not.

This patch must modify the code which is using "struct acpi_buffer" as the buffer.length must be reset to ACPI_ALLOCATE_BUFFER before reusing it to invoke acpi_evaluate_object() again.

Cc Arjan van de Ven <[email protected]>
---
 Documentation/ABI/testing/sysfs-bus-acpi |    7 +++++
 drivers/acpi/scan.c                      |   44 +++++++++++++++++++++++++++++-
 include/acpi/acpi_bus.h                  |    1 +
 3 files changed, 51 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-acpi +7 -0
index 7fa9cbc..db376b8 100644
@@ -49,6 +49,13 @@ Description:
 		This attribute contains the output of the device object's
 		_UID control method, if present.
 
+What:		/sys/bus/acpi/devices/.../ddn
+Date:		February 2014
+Contact:	Rafael J. Wysocki <[email protected]>
+Description:
+		This attribute contains the output of the device object's
+		_DDN control method, if present.
+
 What:		/sys/bus/acpi/devices/.../eject
 Date:		December 2006
 Contact:	Rafael J. Wysocki <[email protected]>
drivers/acpi/scan.c +43 -1

77 lines not on this page · raw message

include/acpi/acpi_bus.h +1 -0
index 84a2e29..7bc77d9 100644
@@ -244,6 +244,7 @@ struct acpi_device_pnp {
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
 	union acpi_object *str_obj;	/* unicode string for _STR method */
+	char *ddn;			/* _DDN */
 	unsigned long sun;		/* _SUN */
 };
 
Signature · 1 line
1.7.10
#5 lore raw
Quoted 6 lines · Lv Zheng

The information contained in _DDN (Dos Device Name) might be useful for userspace utilities, this patch thus exports such information using "ddn" attribute.
Note that the "ddn" attribute will be created as long as the _DDN identifying object exists, whatever its evaluation succeeds or not.

Quoted 6 lines

This patch must modify the code which is using "struct acpi_buffer" as the buffer.length must be reset to ACPI_ALLOCATE_BUFFER before reusing it to invoke acpi_evaluate_object() again.

Cc Arjan van de Ven <[email protected]>

Queued up for 3.15, thanks!

Quoted 123 lines
---
 Documentation/ABI/testing/sysfs-bus-acpi |    7 +++++
 drivers/acpi/scan.c                      |   44 +++++++++++++++++++++++++++++-
 include/acpi/acpi_bus.h                  |    1 +
 3 files changed, 51 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-acpi +7 -0
index 7fa9cbc..db376b8 100644
@@ -49,6 +49,13 @@ Description:
 		This attribute contains the output of the device object's
 		_UID control method, if present.
 
+What:		/sys/bus/acpi/devices/.../ddn
+Date:		February 2014
+Contact:	Rafael J. Wysocki <[email protected]>
+Description:
+		This attribute contains the output of the device object's
+		_DDN control method, if present.
+
 What:		/sys/bus/acpi/devices/.../eject
 Date:		December 2006
 Contact:	Rafael J. Wysocki <[email protected]>
drivers/acpi/scan.c +43 -1
index 7efe546..604b3bc 100644
@@ -660,6 +660,16 @@ static ssize_t description_show(struct device *dev,
 }
 static DEVICE_ATTR(description, 0444, description_show, NULL);
 
+/* sysfs file that shows DOS device name text from the ACPI _DDN method */
+static ssize_t ddn_show(struct device *dev, struct device_attribute *attr,
+			char *buf) {
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+
+	return acpi_dev->pnp.ddn ?
+	       snprintf(buf, PAGE_SIZE, "%s\n", acpi_dev->pnp.ddn) : 0;
+}
+static DEVICE_ATTR(ddn, 0444, ddn_show, NULL);
+
 static ssize_t
 acpi_device_sun_show(struct device *dev, struct device_attribute *attr,
 		     char *buf) {
@@ -685,10 +695,11 @@ static DEVICE_ATTR_RO(status);
 
 static int acpi_device_setup_files(struct acpi_device *dev)
 {
-	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+	struct acpi_buffer buffer;
 	acpi_status status;
 	unsigned long long sun;
 	int result = 0;
+	union acpi_object *object;
 
 	/*
 	 * Devices gotten from FADT don't have a "path" attribute
@@ -713,6 +724,8 @@ static int acpi_device_setup_files(struct acpi_device *dev)
 	 * If device has _STR, 'description' file is created
 	 */
 	if (acpi_has_method(dev->handle, "_STR")) {
+		buffer.length = ACPI_ALLOCATE_BUFFER;
+		buffer.pointer = NULL;
 		status = acpi_evaluate_object(dev->handle, "_STR",
 					NULL, &buffer);
 		if (ACPI_FAILURE(status))
@@ -723,6 +736,28 @@ static int acpi_device_setup_files(struct acpi_device *dev)
 			goto end;
 	}
 
+	/*
+	 * If device has _DDN, 'ddn' file is created
+	 */
+	if (acpi_has_method(dev->handle, "_DDN")) {
+		buffer.length = ACPI_ALLOCATE_BUFFER;
+		buffer.pointer = NULL;
+		status = acpi_evaluate_object_typed(dev->handle, "_DDN",
+						    NULL, &buffer,
+						    ACPI_TYPE_STRING);
+		if (ACPI_FAILURE(status))
+			buffer.pointer = NULL;
+		object = buffer.pointer;
+		if (object) {
+			dev->pnp.ddn = kstrdup(object->string.pointer,
+					       GFP_KERNEL);
+			kfree(object);
+		}
+		result = device_create_file(&dev->dev, &dev_attr_ddn);
+		if (result)
+			goto end;
+	}
+
 	if (dev->pnp.type.bus_address)
 		result = device_create_file(&dev->dev, &dev_attr_adr);
 	if (dev->pnp.unique_id)
@@ -785,6 +820,13 @@ static void acpi_device_remove_files(struct acpi_device *dev)
 		device_remove_file(&dev->dev, &dev_attr_description);
 	}
 	/*
+	 * If device has _DDN, remove 'ddn' file
+	 */
+	if (acpi_has_method(dev->handle, "_DDN")) {
+		device_remove_file(&dev->dev, &dev_attr_ddn);
+		kfree(dev->pnp.ddn);
+	}
+	/*
 	 * If device has _EJ0, remove 'eject' file.
 	 */
 	if (acpi_has_method(dev->handle, "_EJ0"))
include/acpi/acpi_bus.h +1 -0
index 84a2e29..7bc77d9 100644
@@ -244,6 +244,7 @@ struct acpi_device_pnp {
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
 	union acpi_object *str_obj;	/* unicode string for _STR method */
+	char *ddn;			/* _DDN */
 	unsigned long sun;		/* _SUN */
 };
 
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.