Skip to contentSkip to conversation

create sun sysfs file

PATCH Superseded Yasuaki Ishimatsu 3 participants 5 messages Jul 30, 2012 – Aug 7, 2012

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 create sun sysfs file

Even if a device has _SUN method, there is no way to know the slot unique-ID. Thus the patch creates "sun" file in sysfs so that we can recognize it.

---
 drivers/acpi/scan.c     |   25 +++++++++++++++++++++++++
 include/acpi/acpi_bus.h |    1 +
 2 files changed, 26 insertions(+)
include/acpi/acpi_bus.h +1 -0
Index: linux-3.5/include/acpi/acpi_bus.h
===================================================================
@@ -209,6 +209,7 @@ struct acpi_device_pnp {
 	struct list_head ids;		/* _HID and _CIDs */
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
+	unsigned long sun;		/* _SUN */
 };
 
 #define acpi_device_bid(d)	((d)->pnp.bus_id)
drivers/acpi/scan.c +25 -0
Index: linux-3.5/drivers/acpi/scan.c
===================================================================
@@ -192,10 +192,21 @@ end:
 }
 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
 
+static ssize_t
+acpi_device_sun_show(struct device *dev, struct device_attribute *attr, char *buf) {
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	int result;
+
+	result = sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
+	return result;
+}
+static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
+
 static int acpi_device_setup_files(struct acpi_device *dev)
 {
 	acpi_status status;
 	acpi_handle temp;
+	unsigned long long sun;
 	int result = 0;
 
 	/*
@@ -217,6 +228,16 @@ static int acpi_device_setup_files(struc
 			goto end;
 	}
 
+	status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
+	if (ACPI_SUCCESS(status)) {
+		dev->pnp.sun = (unsigned long)sun;
+		result = device_create_file(&dev->dev, &dev_attr_sun);
+		if (result)
+			goto end;
+	} else {
+		dev->pnp.sun = (unsigned long)-1;
+	}
+
         /*
          * If device has _EJ0, 'eject' file is created that is used to trigger
          * hot-removal function from userland.
@@ -241,6 +262,10 @@ static void acpi_device_remove_files(str
 	if (ACPI_SUCCESS(status))
 		device_remove_file(&dev->dev, &dev_attr_eject);
 
+	status = acpi_get_handle(dev->handle, "_SUN", &temp);
+	if (ACPI_SUCCESS(status))
+		device_remove_file(&dev->dev, &dev_attr_sun);
+
 	device_remove_file(&dev->dev, &dev_attr_modalias);
 	device_remove_file(&dev->dev, &dev_attr_hid);
 	if (dev->handle)
Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Yasuaki Ishimatsu

Even if a device has _SUN method, there is no way to know the slot unique-ID. Thus the patch creates "sun" file in sysfs so that we can recognize it.

Hi Yasuaki,

Thanks for the quick update. Looks good.

-Toshi

Quoted 72 lines
---
 drivers/acpi/scan.c     |   25 +++++++++++++++++++++++++
 include/acpi/acpi_bus.h |    1 +
 2 files changed, 26 insertions(+)

Index: linux-3.5/include/acpi/acpi_bus.h
===================================================================

include/acpi/acpi_bus.h +1 -0
@@ -209,6 +209,7 @@ struct acpi_device_pnp {
 	struct list_head ids;		/* _HID and _CIDs */
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
+	unsigned long sun;		/* _SUN */
 };
 
 #define acpi_device_bid(d)	((d)->pnp.bus_id)

Index: linux-3.5/drivers/acpi/scan.c
===================================================================

drivers/acpi/scan.c +25 -0
@@ -192,10 +192,21 @@ end:
 }
 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
 
+static ssize_t
+acpi_device_sun_show(struct device *dev, struct device_attribute *attr, char *buf) {
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	int result;
+
+	result = sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
+	return result;
+}
+static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
+
 static int acpi_device_setup_files(struct acpi_device *dev)
 {
 	acpi_status status;
 	acpi_handle temp;
+	unsigned long long sun;
 	int result = 0;
 
 	/*
@@ -217,6 +228,16 @@ static int acpi_device_setup_files(struc
 			goto end;
 	}
 
+	status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
+	if (ACPI_SUCCESS(status)) {
+		dev->pnp.sun = (unsigned long)sun;
+		result = device_create_file(&dev->dev, &dev_attr_sun);
+		if (result)
+			goto end;
+	} else {
+		dev->pnp.sun = (unsigned long)-1;
+	}
+
         /*
          * If device has _EJ0, 'eject' file is created that is used to trigger
          * hot-removal function from userland.
@@ -241,6 +262,10 @@ static void acpi_device_remove_files(str
 	if (ACPI_SUCCESS(status))
 		device_remove_file(&dev->dev, &dev_attr_eject);
 
+	status = acpi_get_handle(dev->handle, "_SUN", &temp);
+	if (ACPI_SUCCESS(status))
+		device_remove_file(&dev->dev, &dev_attr_sun);
+
 	device_remove_file(&dev->dev, &dev_attr_modalias);
 	device_remove_file(&dev->dev, &dev_attr_hid);
 	if (dev->handle)
#2 lore raw

Hi Toshi,

Quoted 11 lines · Toshi Kani
Quoted 4 lines · Yasuaki Ishimatsu

Even if a device has _SUN method, there is no way to know the slot unique-ID. Thus the patch creates "sun" file in sysfs so that we can recognize it.

Hi Yasuaki,

Thanks for the quick update. Looks good.

Thanks you for reviewing my patch.

Thanks,
Yasuaki Ishimatsu

Quoted 77 lines

-Toshi

Quoted 72 lines
---
  drivers/acpi/scan.c     |   25 +++++++++++++++++++++++++
  include/acpi/acpi_bus.h |    1 +
  2 files changed, 26 insertions(+)

Index: linux-3.5/include/acpi/acpi_bus.h
===================================================================

include/acpi/acpi_bus.h +1 -0
@@ -209,6 +209,7 @@ struct acpi_device_pnp {
  	struct list_head ids;		/* _HID and _CIDs */
  	acpi_device_name device_name;	/* Driver-determined */
  	acpi_device_class device_class;	/*        "          */
+	unsigned long sun;		/* _SUN */
  };
 
  #define acpi_device_bid(d)	((d)->pnp.bus_id)

Index: linux-3.5/drivers/acpi/scan.c
===================================================================

drivers/acpi/scan.c +25 -0
@@ -192,10 +192,21 @@ end:
  }
  static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
 
+static ssize_t
+acpi_device_sun_show(struct device *dev, struct device_attribute *attr, char *buf) {
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	int result;
+
+	result = sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
+	return result;
+}
+static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
+
  static int acpi_device_setup_files(struct acpi_device *dev)
  {
  	acpi_status status;
  	acpi_handle temp;
+	unsigned long long sun;
  	int result = 0;
 
  	/*
@@ -217,6 +228,16 @@ static int acpi_device_setup_files(struc
  			goto end;
  	}
 
+	status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
+	if (ACPI_SUCCESS(status)) {
+		dev->pnp.sun = (unsigned long)sun;
+		result = device_create_file(&dev->dev, &dev_attr_sun);
+		if (result)
+			goto end;
+	} else {
+		dev->pnp.sun = (unsigned long)-1;
+	}
+
          /*
           * If device has _EJ0, 'eject' file is created that is used to trigger
           * hot-removal function from userland.
@@ -241,6 +262,10 @@ static void acpi_device_remove_files(str
  	if (ACPI_SUCCESS(status))
  		device_remove_file(&dev->dev, &dev_attr_eject);
 
+	status = acpi_get_handle(dev->handle, "_SUN", &temp);
+	if (ACPI_SUCCESS(status))
+		device_remove_file(&dev->dev, &dev_attr_sun);
+
  	device_remove_file(&dev->dev, &dev_attr_modalias);
  	device_remove_file(&dev->dev, &dev_attr_hid);
  	if (dev->handle)
#3 lore raw
In reply to Yasuaki Ishimatsu
Quoted 27 lines · Yasuaki Ishimatsu

Even if a device has _SUN method, there is no way to know the slot unique-ID. Thus the patch creates "sun" file in sysfs so that we can recognize it.

---
 drivers/acpi/scan.c     |   25 +++++++++++++++++++++++++
 include/acpi/acpi_bus.h |    1 +
 2 files changed, 26 insertions(+)

Index: linux-3.5/include/acpi/acpi_bus.h
===================================================================

include/acpi/acpi_bus.h +1 -0
@@ -209,6 +209,7 @@ struct acpi_device_pnp {
 	struct list_head ids;		/* _HID and _CIDs */
 	acpi_device_name device_name;	/* Driver-determined */
 	acpi_device_class device_class;	/*        "          */
+	unsigned long sun;		/* _SUN */
 };
 
 #define acpi_device_bid(d)	((d)->pnp.bus_id)

Index: linux-3.5/drivers/acpi/scan.c
===================================================================

drivers/acpi/scan.c end: · line 196

Quoted 5 lines
drivers/acpi/scan.c +2 -0
@@ -192,10 +192,21 @@ end:
 }
 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
 
+static ssize_t
+acpi_device_sun_show(struct device *dev, struct device_attribute *attr, char *buf) {

The above line is more than 80 characters.

drivers/acpi/scan.c end: · line 201

Quoted 5 lines
drivers/acpi/scan.c +5 -0
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	int result;
+
+	result = sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
+	return result;

How about just
return sprintf(buf, "%lu\n", acpi_dev->pnp.sun);

Quoted 46 lines
drivers/acpi/scan.c +18 -1
+}
+static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
+
 static int acpi_device_setup_files(struct acpi_device *dev)
 {
 	acpi_status status;
 	acpi_handle temp;
+	unsigned long long sun;
 	int result = 0;
 
 	/*
@@ -217,6 +228,16 @@ static int acpi_device_setup_files(struc
 			goto end;
 	}
 
+	status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
+	if (ACPI_SUCCESS(status)) {
+		dev->pnp.sun = (unsigned long)sun;
+		result = device_create_file(&dev->dev, &dev_attr_sun);
+		if (result)
+			goto end;
+	} else {
+		dev->pnp.sun = (unsigned long)-1;
+	}
+
         /*
          * If device has _EJ0, 'eject' file is created that is used to trigger
          * hot-removal function from userland.
@@ -241,6 +262,10 @@ static void acpi_device_remove_files(str
 	if (ACPI_SUCCESS(status))
 		device_remove_file(&dev->dev, &dev_attr_eject);
 
+	status = acpi_get_handle(dev->handle, "_SUN", &temp);
+	if (ACPI_SUCCESS(status))
+		device_remove_file(&dev->dev, &dev_attr_sun);
+
 	device_remove_file(&dev->dev, &dev_attr_modalias);
 	device_remove_file(&dev->dev, &dev_attr_hid);
 	if (dev->handle)
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw

Hi Jiang,

Sorry for late reply. I could not work by private reason.

Quoted 31 lines · Jiang Liu
Quoted 30 lines · Yasuaki Ishimatsu

Even if a device has _SUN method, there is no way to know the slot unique-ID. Thus the patch creates "sun" file in sysfs so that we can recognize it.

---
  drivers/acpi/scan.c     |   25 +++++++++++++++++++++++++
  include/acpi/acpi_bus.h |    1 +
  2 files changed, 26 insertions(+)

Index: linux-3.5/include/acpi/acpi_bus.h
===================================================================

include/acpi/acpi_bus.h +1 -0
@@ -209,6 +209,7 @@ struct acpi_device_pnp {
  	struct list_head ids;		/* _HID and _CIDs */
  	acpi_device_name device_name;	/* Driver-determined */
  	acpi_device_class device_class;	/*        "          */
+	unsigned long sun;		/* _SUN */
  };
 
  #define acpi_device_bid(d)	((d)->pnp.bus_id)

Index: linux-3.5/drivers/acpi/scan.c
===================================================================

drivers/acpi/scan.c +0 -0
@@ -192,10 +192,21 @@ end:
  }
  static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
 
Quoted 3 lines

drivers/acpi/scan.c end: · line 196

Quoted 2 lines
drivers/acpi/scan.c +2 -0
+static ssize_t
+acpi_device_sun_show(struct device *dev, struct device_attribute *attr, char *buf) {

The above line is more than 80 characters.

I'll update it soon.

Quoted 8 lines

drivers/acpi/scan.c end: · line 201

Quoted 6 lines
drivers/acpi/scan.c +5 -0
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	int result;
+
+	result = sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
+	return result;

How about just
return sprintf(buf, "%lu\n", acpi_dev->pnp.sun);

I'll update it soon.

Thanks,
Yasuaki Ishimatsu

Quoted 48 lines
Quoted 47 lines
drivers/acpi/scan.c +18 -1
+}
+static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
+
  static int acpi_device_setup_files(struct acpi_device *dev)
  {
  	acpi_status status;
  	acpi_handle temp;
+	unsigned long long sun;
  	int result = 0;
 
  	/*
@@ -217,6 +228,16 @@ static int acpi_device_setup_files(struc
  			goto end;
  	}
 
+	status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
+	if (ACPI_SUCCESS(status)) {
+		dev->pnp.sun = (unsigned long)sun;
+		result = device_create_file(&dev->dev, &dev_attr_sun);
+		if (result)
+			goto end;
+	} else {
+		dev->pnp.sun = (unsigned long)-1;
+	}
+
          /*
           * If device has _EJ0, 'eject' file is created that is used to trigger
           * hot-removal function from userland.
@@ -241,6 +262,10 @@ static void acpi_device_remove_files(str
  	if (ACPI_SUCCESS(status))
  		device_remove_file(&dev->dev, &dev_attr_eject);
 
+	status = acpi_get_handle(dev->handle, "_SUN", &temp);
+	if (ACPI_SUCCESS(status))
+		device_remove_file(&dev->dev, &dev_attr_sun);
+
  	device_remove_file(&dev->dev, &dev_attr_modalias);
  	device_remove_file(&dev->dev, &dev_attr_hid);
  	if (dev->handle)
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/