diff mbox

[v2,5/9] ACPI: introduce three helper functions

Message ID 1372264261-17442-6-git-send-email-liuj97@gmail.com (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Jiang Liu June 26, 2013, 4:30 p.m. UTC
From: Jiang Liu <jiang.liu@huawei.com>

Introduce three helper functions, which will be used to simplify code.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Jiang Liu <liuj97@gmail.com>
Cc: Len Brown <lenb@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: linux-acpi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/acpi/utils.c    | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  5 ++++
 2 files changed, 77 insertions(+)

Comments

Rafael Wysocki June 26, 2013, 6:49 p.m. UTC | #1
On Thursday, June 27, 2013 12:30:57 AM Jiang Liu wrote:
> From: Jiang Liu <jiang.liu@huawei.com>
> 
> Introduce three helper functions, which will be used to simplify code.

First, please introduce acpi_has_method() and use it everywhere where
applicable (at least under drivers/acpi/) in one separate patch.

> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
> Cc: Jiang Liu <liuj97@gmail.com>
> Cc: Len Brown <lenb@kernel.org>
> Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
> Cc: linux-acpi@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/acpi/utils.c    | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/acpi/acpi_bus.h |  5 ++++
>  2 files changed, 77 insertions(+)
> 
> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> index 74437130..5bcf068 100644
> --- a/drivers/acpi/utils.c
> +++ b/drivers/acpi/utils.c
> @@ -495,3 +495,75 @@ acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
>  	kfree(buffer.pointer);
>  }
>  EXPORT_SYMBOL(acpi_handle_printk);
> +
> +static acpi_status

This style isn't preferred.  Please always use

static acpi_status <function name>(...)

> +acpi_evaluate_object_with_int_arg(acpi_handle handle, char *method, u64 val)

The name is awful.  Perhaps "acpi_execute_simple_method()" would be better.
And please change the name of the last argument to 'arg'.

> +{
> +	union acpi_object arg;
> +	struct acpi_object_list arg_list;
> +
> +	arg.type = ACPI_TYPE_INTEGER;
> +	arg.integer.value = val;
> +	arg_list.count = 1;
> +	arg_list.pointer = &arg;

Besides, why not to do that this way:

	union acpi_object obj = { .type = ACPI_TYPE_INTEGER, .integer.value = arg, };
	struct acpi_object_list arg_list = { .count = 1, .pointer = &obj, };

and that function would be useful outside of utils.c I suppose.

> +
> +	return acpi_evaluate_object(handle, method, &arg_list, NULL);
> +}
> +
> +/**
> + * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations
> + * @handle: ACPI device handle
> + *
> + * Evaluate device's _EJ0 method for hotplug operations.
> + */
> +acpi_status acpi_evaluate_ej0(acpi_handle handle)
> +{
> +	acpi_status status;
> +
> +	status = acpi_evaluate_object_with_int_arg(handle, "_EJ0", 1);
> +	if (status == AE_NOT_FOUND)
> +		acpi_handle_warn(handle, "No _EJ0 support for device\n");
> +	else if (ACPI_FAILURE(status))
> +		acpi_handle_warn(handle, "Eject failed (0x%x)\n", status);
> +
> +	return status;
> +}
> +
> +/**
> + * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
> + * @handle: ACPI device handle
> + * @lock: lock device if non-zero, otherwise unlock device
> + *
> + * Evaluate device's _LCK method if present to lock/unlock device
> + */
> +acpi_status acpi_evaluate_lck(acpi_handle handle, int lock)
> +{
> +	acpi_status status;
> +
> +	status = acpi_evaluate_object_with_int_arg(handle, "_LCK", !!lock);
> +	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
> +		if (lock)
> +			acpi_handle_warn(handle,
> +				"Locking device failed (0x%x)\n", status);
> +		else
> +			acpi_handle_warn(handle,
> +				"Unlocking device failed (0x%x)\n", status);
> +	}
> +
> +	return status;
> +}
> +
> +/**
> + * acpi_has_method: Check whether @handle has a method named @name
> + * @handle: ACPI device handle
> + * @name: name of object or method
> + *
> + * Check whether @handle has a method named @name.
> + */
> +bool acpi_has_method(acpi_handle handle, char *name)
> +{
> +	acpi_handle tmp;
> +
> +	return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp));
> +}
> +EXPORT_SYMBOL(acpi_has_method);
> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index ca081ac..3db3b97 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -56,6 +56,11 @@ acpi_evaluate_hotplug_ost(acpi_handle handle, u32 source_event,
>  
>  acpi_status
>  acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
> +
> +acpi_status acpi_evaluate_ej0(acpi_handle handle);
> +acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
> +bool acpi_has_method(acpi_handle handle, char *name);
> +
>  #ifdef CONFIG_ACPI
>  
>  #include <linux/proc_fs.h>

Thanks,
Rafael
Rafael Wysocki June 26, 2013, 11:46 p.m. UTC | #2
On Wednesday, June 26, 2013 08:49:21 PM Rafael J. Wysocki wrote:
> On Thursday, June 27, 2013 12:30:57 AM Jiang Liu wrote:
> > From: Jiang Liu <jiang.liu@huawei.com>
> > 
> > Introduce three helper functions, which will be used to simplify code.
> 
> First, please introduce acpi_has_method() and use it everywhere where
> applicable (at least under drivers/acpi/)

Well, except for drivers/acpi/acpica/.  And even that might be too much ...

Please just move the definition of acpi_has_method() and all of the
simplifications you've done using it into one separate patch.

Thanks,
Rafael
diff mbox

Patch

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 74437130..5bcf068 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -495,3 +495,75 @@  acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
 	kfree(buffer.pointer);
 }
 EXPORT_SYMBOL(acpi_handle_printk);
+
+static acpi_status
+acpi_evaluate_object_with_int_arg(acpi_handle handle, char *method, u64 val)
+{
+	union acpi_object arg;
+	struct acpi_object_list arg_list;
+
+	arg.type = ACPI_TYPE_INTEGER;
+	arg.integer.value = val;
+	arg_list.count = 1;
+	arg_list.pointer = &arg;
+
+	return acpi_evaluate_object(handle, method, &arg_list, NULL);
+}
+
+/**
+ * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations
+ * @handle: ACPI device handle
+ *
+ * Evaluate device's _EJ0 method for hotplug operations.
+ */
+acpi_status acpi_evaluate_ej0(acpi_handle handle)
+{
+	acpi_status status;
+
+	status = acpi_evaluate_object_with_int_arg(handle, "_EJ0", 1);
+	if (status == AE_NOT_FOUND)
+		acpi_handle_warn(handle, "No _EJ0 support for device\n");
+	else if (ACPI_FAILURE(status))
+		acpi_handle_warn(handle, "Eject failed (0x%x)\n", status);
+
+	return status;
+}
+
+/**
+ * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
+ * @handle: ACPI device handle
+ * @lock: lock device if non-zero, otherwise unlock device
+ *
+ * Evaluate device's _LCK method if present to lock/unlock device
+ */
+acpi_status acpi_evaluate_lck(acpi_handle handle, int lock)
+{
+	acpi_status status;
+
+	status = acpi_evaluate_object_with_int_arg(handle, "_LCK", !!lock);
+	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+		if (lock)
+			acpi_handle_warn(handle,
+				"Locking device failed (0x%x)\n", status);
+		else
+			acpi_handle_warn(handle,
+				"Unlocking device failed (0x%x)\n", status);
+	}
+
+	return status;
+}
+
+/**
+ * acpi_has_method: Check whether @handle has a method named @name
+ * @handle: ACPI device handle
+ * @name: name of object or method
+ *
+ * Check whether @handle has a method named @name.
+ */
+bool acpi_has_method(acpi_handle handle, char *name)
+{
+	acpi_handle tmp;
+
+	return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp));
+}
+EXPORT_SYMBOL(acpi_has_method);
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index ca081ac..3db3b97 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -56,6 +56,11 @@  acpi_evaluate_hotplug_ost(acpi_handle handle, u32 source_event,
 
 acpi_status
 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
+
+acpi_status acpi_evaluate_ej0(acpi_handle handle);
+acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
+bool acpi_has_method(acpi_handle handle, char *name);
+
 #ifdef CONFIG_ACPI
 
 #include <linux/proc_fs.h>