All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers
@ 2013-06-26 16:30 Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 1/9] ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times Jiang Liu
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel

From: Jiang Liu <jiang.liu@huawei.com>

This is an following up patchset of "[PATCH 0/3] ACPI / dock / PCI: Fix
problems with dock and PCI hotplug" with minor code cleanups and
refinements. It applies to
git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next

Due to hardware resource limitation, I have only done compilation and
boot tests.

Jiang Liu (9):
  ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times
  ACPI, DOCK: kill redundant spin lock in dock station object
  ACPI, DOCK: mark initialization functions with __init
  ACPI, DOCK: simplify implementation of dock_create_acpi_device()
  ACPI: introduce three helper functions
  ACPI: change acpi_[bay|dock]_match() in scan.c as global functions
  ACPI: simplify dock driver with new interfaces
  ACPI: simpilify scan.c with new interfaces
  ACPI: simplify acpiphp driver with new interfaces

 drivers/acpi/dock.c                | 152 ++++---------------------------
 drivers/acpi/scan.c                | 182 ++++++++++++-------------------------
 drivers/acpi/utils.c               |  72 +++++++++++++++
 drivers/pci/hotplug/acpiphp_glue.c |  30 ++----
 include/acpi/acpi_bus.h            |   8 ++
 5 files changed, 168 insertions(+), 276 deletions(-)

-- 
1.8.1.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 1/9] ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
@ 2013-06-26 16:30 ` Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 2/9] ACPI, DOCK: kill redundant spin lock in dock station object Jiang Liu
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

From: Jiang Liu <jiang.liu@huawei.com>

Function dock_add() will be called multiple times if there are multiple
dock stations, which causes acpi_dock_notifier_list being initialized
multiple times. So move initialization of acpi_dock_notifier_list from
dock_add() to acpi_dock_init().

Signed-off-by: Jiang Liu <jiang.liu@huawei.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/dock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 14de9f4..e944e39 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -1007,7 +1007,6 @@ static int __init dock_add(acpi_handle handle)
 	mutex_init(&dock_station->hp_lock);
 	spin_lock_init(&dock_station->dd_lock);
 	INIT_LIST_HEAD(&dock_station->sibling);
-	ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
 	INIT_LIST_HEAD(&dock_station->dependent_devices);
 
 	/* we want the dock device to send uevents */
@@ -1078,6 +1077,7 @@ int __init acpi_dock_init(void)
 		return 0;
 	}
 
+	ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
 	register_acpi_bus_notifier(&dock_acpi_notifier);
 	pr_info(PREFIX "%s: %d docks/bays found\n",
 		ACPI_DOCK_DRIVER_DESCRIPTION, dock_station_count);
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 2/9] ACPI, DOCK: kill redundant spin lock in dock station object
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 1/9] ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times Jiang Liu
@ 2013-06-26 16:30 ` Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 3/9] ACPI, DOCK: mark initialization functions with __init Jiang Liu
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

From: Jiang Liu <jiang.liu@huawei.com>

All dock station objects are created during initialization and don't
change at runtime, so kill the redundant spin lock in dock station
object.

Signed-off-by: Jiang Liu <jiang.liu@huawei.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/dock.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index e944e39..a73571f 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -63,7 +63,6 @@ struct dock_station {
 	acpi_handle handle;
 	unsigned long last_dock_time;
 	u32 flags;
-	spinlock_t dd_lock;
 	struct mutex hp_lock;
 	struct list_head dependent_devices;
 
@@ -112,10 +111,7 @@ add_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
 
 	dd->handle = handle;
 	INIT_LIST_HEAD(&dd->list);
-
-	spin_lock(&ds->dd_lock);
 	list_add_tail(&dd->list, &ds->dependent_devices);
-	spin_unlock(&ds->dd_lock);
 
 	return 0;
 }
@@ -220,14 +216,10 @@ find_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
 {
 	struct dock_dependent_device *dd;
 
-	spin_lock(&ds->dd_lock);
-	list_for_each_entry(dd, &ds->dependent_devices, list) {
-		if (handle == dd->handle) {
-			spin_unlock(&ds->dd_lock);
+	list_for_each_entry(dd, &ds->dependent_devices, list)
+		if (handle == dd->handle)
 			return dd;
-		}
-	}
-	spin_unlock(&ds->dd_lock);
+
 	return NULL;
 }
 
@@ -1005,7 +997,6 @@ static int __init dock_add(acpi_handle handle)
 	dock_station->last_dock_time = jiffies - HZ;
 
 	mutex_init(&dock_station->hp_lock);
-	spin_lock_init(&dock_station->dd_lock);
 	INIT_LIST_HEAD(&dock_station->sibling);
 	INIT_LIST_HEAD(&dock_station->dependent_devices);
 
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 3/9] ACPI, DOCK: mark initialization functions with __init
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 1/9] ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 2/9] ACPI, DOCK: kill redundant spin lock in dock station object Jiang Liu
@ 2013-06-26 16:30 ` Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 4/9] ACPI, DOCK: simplify implementation of dock_create_acpi_device() Jiang Liu
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

From: Jiang Liu <jiang.liu@huawei.com>

Mark all initialization functions with __init to reduce runtime memory
consumption.

Signed-off-by: Jiang Liu <jiang.liu@huawei.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/dock.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index a73571f..8c4214d 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -100,7 +100,7 @@ struct dock_dependent_device {
  *
  * Add the dependent device to the dock's dependent device list.
  */
-static int
+static int __init
 add_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
 {
 	struct dock_dependent_device *dd;
@@ -244,7 +244,7 @@ static int is_dock(acpi_handle handle)
 	return 1;
 }
 
-static int is_ejectable(acpi_handle handle)
+static int __init is_ejectable(acpi_handle handle)
 {
 	acpi_status status;
 	acpi_handle tmp;
@@ -255,7 +255,7 @@ static int is_ejectable(acpi_handle handle)
 	return 1;
 }
 
-static int is_ata(acpi_handle handle)
+static int __init is_ata(acpi_handle handle)
 {
 	acpi_handle tmp;
 
@@ -268,7 +268,7 @@ static int is_ata(acpi_handle handle)
 	return 0;
 }
 
-static int is_battery(acpi_handle handle)
+static int __init is_battery(acpi_handle handle)
 {
 	struct acpi_device_info *info;
 	int ret = 1;
@@ -284,7 +284,7 @@ static int is_battery(acpi_handle handle)
 	return ret;
 }
 
-static int is_ejectable_bay(acpi_handle handle)
+static int __init is_ejectable_bay(acpi_handle handle)
 {
 	acpi_handle phandle;
 
@@ -848,7 +848,7 @@ static struct notifier_block dock_acpi_notifier = {
  * check to see if an object has an _EJD method.  If it does, then it
  * will see if it is dependent on the dock station.
  */
-static acpi_status
+static acpi_status __init
 find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
 	acpi_status status;
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 4/9] ACPI, DOCK: simplify implementation of dock_create_acpi_device()
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
                   ` (2 preceding siblings ...)
  2013-06-26 16:30 ` [PATCH v2 3/9] ACPI, DOCK: mark initialization functions with __init Jiang Liu
@ 2013-06-26 16:30 ` Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 5/9] ACPI: introduce three helper functions Jiang Liu
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

From: Jiang Liu <jiang.liu@huawei.com>

The return value of dock_create_acpi_device() is not used at all,
so change the signature to return void and simplify implementation.

Signed-off-by: Jiang Liu <jiang.liu@huawei.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/dock.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 8c4214d..22183c4 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -351,10 +351,8 @@ static int dock_present(struct dock_station *ds)
  *  handle if one does not exist already.  This should cause
  *  acpi to scan for drivers for the given devices, and call
  *  matching driver's add routine.
- *
- *  Returns a pointer to the acpi_device corresponding to the handle.
  */
-static struct acpi_device * dock_create_acpi_device(acpi_handle handle)
+static void dock_create_acpi_device(acpi_handle handle)
 {
 	struct acpi_device *device;
 	int ret;
@@ -367,10 +365,7 @@ static struct acpi_device * dock_create_acpi_device(acpi_handle handle)
 		ret = acpi_bus_scan(handle);
 		if (ret)
 			pr_debug("error adding bus, %x\n", -ret);
-
-		acpi_bus_get_device(handle, &device);
 	}
-	return device;
 }
 
 /**
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 5/9] ACPI: introduce three helper functions
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
                   ` (3 preceding siblings ...)
  2013-06-26 16:30 ` [PATCH v2 4/9] ACPI, DOCK: simplify implementation of dock_create_acpi_device() Jiang Liu
@ 2013-06-26 16:30 ` Jiang Liu
  2013-06-26 18:49   ` Rafael J. Wysocki
  2013-06-26 16:30 ` [PATCH v2 6/9] ACPI: change acpi_[bay|dock]_match() in scan.c as global functions Jiang Liu
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

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(+)

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>
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 6/9] ACPI: change acpi_[bay|dock]_match() in scan.c as global functions
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
                   ` (4 preceding siblings ...)
  2013-06-26 16:30 ` [PATCH v2 5/9] ACPI: introduce three helper functions Jiang Liu
@ 2013-06-26 16:30 ` Jiang Liu
  2013-06-26 16:30 ` [PATCH v2 7/9] ACPI: simplify dock driver with new interfaces Jiang Liu
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

From: Jiang Liu <jiang.liu@huawei.com>

Function acpi_[bay|dock]_match() in scan.c could be shared with dock.c
to reduce duplicated code, so refine and change them as global functions.
Also add a new function acpi_ata_match() to check whether an ACPI object
device is an ATA device.

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/scan.c     | 82 ++++++++++++++++++++++---------------------------
 include/acpi/acpi_bus.h |  3 ++
 2 files changed, 40 insertions(+), 45 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index dfe76f1..3ddba74 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1532,46 +1532,45 @@ static void acpi_device_get_busid(struct acpi_device *device)
 }
 
 /*
+ * acpi_ata_match - see if an acpi object is an ATA device
+ *
+ * If an acpi object has one of the ACPI ATA methods defined,
+ * then we can safely call it an ATA device.
+ */
+bool acpi_ata_match(acpi_handle handle)
+{
+	return acpi_has_method(handle, "_GTF") ||
+	       acpi_has_method(handle, "_GTM") ||
+	       acpi_has_method(handle, "_STM") ||
+	       acpi_has_method(handle, "_SDD");
+}
+
+/*
  * acpi_bay_match - see if an acpi object is an ejectable driver bay
  *
  * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
  * then we can safely call it an ejectable drive bay
  */
-static int acpi_bay_match(acpi_handle handle)
+bool acpi_bay_match(acpi_handle handle)
 {
-	acpi_status status;
-	acpi_handle tmp;
 	acpi_handle phandle;
 
-	status = acpi_get_handle(handle, "_EJ0", &tmp);
-	if (ACPI_FAILURE(status))
-		return -ENODEV;
-
-	if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
-		(ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
-		(ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
-		(ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
-		return 0;
-
-	if (acpi_get_parent(handle, &phandle))
-		return -ENODEV;
-
-        if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
-                (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
-                (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
-                (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
-                return 0;
+	if (!acpi_has_method(handle, "_EJ0"))
+		return false;
+	if (acpi_ata_match(handle))
+		return true;
+	if (ACPI_FAILURE(acpi_get_parent(handle, &phandle)))
+		return false;
 
-	return -ENODEV;
+	return acpi_ata_match(phandle);
 }
 
 /*
  * acpi_dock_match - see if an acpi object has a _DCK method
  */
-static int acpi_dock_match(acpi_handle handle)
+bool acpi_dock_match(acpi_handle handle)
 {
-	acpi_handle tmp;
-	return acpi_get_handle(handle, "_DCK", &tmp);
+	return acpi_has_method(handle, "_DCK");
 }
 
 const char *acpi_device_hid(struct acpi_device *device)
@@ -1609,34 +1608,27 @@ static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id)
  * lacks the SMBUS01 HID and the methods do not have the necessary "_"
  * prefix.  Work around this.
  */
-static int acpi_ibm_smbus_match(acpi_handle handle)
+static bool acpi_ibm_smbus_match(acpi_handle handle)
 {
 	acpi_handle h_dummy;
-	struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
-	int result;
+	char node_name[ACPI_PATH_SEGMENT_LENGTH];
+	struct acpi_buffer path = { sizeof(node_name), node_name };
 
 	if (!dmi_name_in_vendors("IBM"))
-		return -ENODEV;
+		return false;
 
 	/* Look for SMBS object */
-	result = acpi_get_name(handle, ACPI_SINGLE_NAME, &path);
-	if (result)
-		return result;
-
-	if (strcmp("SMBS", path.pointer)) {
-		result = -ENODEV;
-		goto out;
-	}
+	if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &path)) ||
+	    strcmp("SMBS", path.pointer))
+		return false;
 
 	/* Does it have the necessary (but misnamed) methods? */
-	result = -ENODEV;
 	if (ACPI_SUCCESS(acpi_get_handle(handle, "SBI", &h_dummy)) &&
 	    ACPI_SUCCESS(acpi_get_handle(handle, "SBR", &h_dummy)) &&
 	    ACPI_SUCCESS(acpi_get_handle(handle, "SBW", &h_dummy)))
-		result = 0;
-out:
-	kfree(path.pointer);
-	return result;
+		return true;
+
+	return false;
 }
 
 static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
@@ -1684,11 +1676,11 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 		 */
 		if (acpi_is_video_device(handle))
 			acpi_add_id(pnp, ACPI_VIDEO_HID);
-		else if (ACPI_SUCCESS(acpi_bay_match(handle)))
+		else if (acpi_bay_match(handle))
 			acpi_add_id(pnp, ACPI_BAY_HID);
-		else if (ACPI_SUCCESS(acpi_dock_match(handle)))
+		else if (acpi_dock_match(handle))
 			acpi_add_id(pnp, ACPI_DOCK_HID);
-		else if (!acpi_ibm_smbus_match(handle))
+		else if (acpi_ibm_smbus_match(handle))
 			acpi_add_id(pnp, ACPI_SMBUS_IBM_HID);
 		else if (list_empty(&pnp->ids) && handle == ACPI_ROOT_OBJECT) {
 			acpi_add_id(pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 3db3b97..a4e4427 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -60,6 +60,9 @@ 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);
+bool acpi_ata_match(acpi_handle handle);
+bool acpi_bay_match(acpi_handle handle);
+bool acpi_dock_match(acpi_handle handle);
 
 #ifdef CONFIG_ACPI
 
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 7/9] ACPI: simplify dock driver with new interfaces
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
                   ` (5 preceding siblings ...)
  2013-06-26 16:30 ` [PATCH v2 6/9] ACPI: change acpi_[bay|dock]_match() in scan.c as global functions Jiang Liu
@ 2013-06-26 16:30 ` Jiang Liu
  2013-06-26 23:12   ` Bjorn Helgaas
  2013-06-26 16:31 ` [PATCH v2 8/9] ACPI: simpilify scan.c " Jiang Liu
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:30 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

From: Jiang Liu <jiang.liu@huawei.com>

Use new helper functions to simpilify ACPI dock driver.

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/dock.c | 122 ++++++----------------------------------------------
 1 file changed, 12 insertions(+), 110 deletions(-)

diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 22183c4..31ab001 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -226,48 +226,6 @@ find_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
 /*****************************************************************************
  *                         Dock functions                                    *
  *****************************************************************************/
-/**
- * is_dock - see if a device is a dock station
- * @handle: acpi handle of the device
- *
- * If an acpi object has a _DCK method, then it is by definition a dock
- * station, so return true.
- */
-static int is_dock(acpi_handle handle)
-{
-	acpi_status status;
-	acpi_handle tmp;
-
-	status = acpi_get_handle(handle, "_DCK", &tmp);
-	if (ACPI_FAILURE(status))
-		return 0;
-	return 1;
-}
-
-static int __init is_ejectable(acpi_handle handle)
-{
-	acpi_status status;
-	acpi_handle tmp;
-
-	status = acpi_get_handle(handle, "_EJ0", &tmp);
-	if (ACPI_FAILURE(status))
-		return 0;
-	return 1;
-}
-
-static int __init is_ata(acpi_handle handle)
-{
-	acpi_handle tmp;
-
-	if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
-	   (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
-	   (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
-	   (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
-		return 1;
-
-	return 0;
-}
-
 static int __init is_battery(acpi_handle handle)
 {
 	struct acpi_device_info *info;
@@ -284,17 +242,13 @@ static int __init is_battery(acpi_handle handle)
 	return ret;
 }
 
-static int __init is_ejectable_bay(acpi_handle handle)
+/* Check whether ACPI object is an ejectable battery or disk bay */
+static bool __init is_ejectable_bay(acpi_handle handle)
 {
-	acpi_handle phandle;
+	if (acpi_has_method(handle, "_EJ0") && is_battery(handle))
+		return true;
 
-	if (!is_ejectable(handle))
-		return 0;
-	if (is_battery(handle) || is_ata(handle))
-		return 1;
-	if (!acpi_get_parent(handle, &phandle) && is_ata(phandle))
-		return 1;
-	return 0;
+	return acpi_bay_match(handle);
 }
 
 /**
@@ -312,7 +266,7 @@ int is_dock_device(acpi_handle handle)
 	if (!dock_station_count)
 		return 0;
 
-	if (is_dock(handle))
+	if (acpi_dock_match(handle))
 		return 1;
 
 	list_for_each_entry(dock_station, &dock_stations, sibling)
@@ -447,37 +401,6 @@ static void dock_event(struct dock_station *ds, u32 event, int num)
 }
 
 /**
- * eject_dock - respond to a dock eject request
- * @ds: the dock station
- *
- * This is called after _DCK is called, to execute the dock station's
- * _EJ0 method.
- */
-static void eject_dock(struct dock_station *ds)
-{
-	struct acpi_object_list arg_list;
-	union acpi_object arg;
-	acpi_status status;
-	acpi_handle tmp;
-
-	/* all dock devices should have _EJ0, but check anyway */
-	status = acpi_get_handle(ds->handle, "_EJ0", &tmp);
-	if (ACPI_FAILURE(status)) {
-		pr_debug("No _EJ0 support for dock device\n");
-		return;
-	}
-
-	arg_list.count = 1;
-	arg_list.pointer = &arg;
-	arg.type = ACPI_TYPE_INTEGER;
-	arg.integer.value = 1;
-
-	status = acpi_evaluate_object(ds->handle, "_EJ0", &arg_list, NULL);
-	if (ACPI_FAILURE(status))
-		pr_debug("Failed to evaluate _EJ0!\n");
-}
-
-/**
  * handle_dock - handle a dock event
  * @ds: the dock station
  * @dock: to dock, or undock - that is the question
@@ -537,27 +460,6 @@ static inline void complete_undock(struct dock_station *ds)
 	ds->flags &= ~(DOCK_UNDOCKING);
 }
 
-static void dock_lock(struct dock_station *ds, int lock)
-{
-	struct acpi_object_list arg_list;
-	union acpi_object arg;
-	acpi_status status;
-
-	arg_list.count = 1;
-	arg_list.pointer = &arg;
-	arg.type = ACPI_TYPE_INTEGER;
-	arg.integer.value = !!lock;
-	status = acpi_evaluate_object(ds->handle, "_LCK", &arg_list, NULL);
-	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
-		if (lock)
-			acpi_handle_warn(ds->handle,
-				"Locking device failed (0x%x)\n", status);
-		else
-			acpi_handle_warn(ds->handle,
-				"Unlocking device failed (0x%x)\n", status);
-	}
-}
-
 /**
  * dock_in_progress - see if we are in the middle of handling a dock event
  * @ds: the dock station
@@ -692,8 +594,8 @@ static int handle_eject_request(struct dock_station *ds, u32 event)
 
 	hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
 	undock(ds);
-	dock_lock(ds, 0);
-	eject_dock(ds);
+	acpi_evaluate_lck(ds->handle, 0);
+	acpi_evaluate_ej0(ds->handle);
 	if (dock_present(ds)) {
 		acpi_handle_err(ds->handle, "Unable to undock!\n");
 		return -EBUSY;
@@ -752,7 +654,7 @@ static void dock_notify(acpi_handle handle, u32 event, void *data)
 			hotplug_dock_devices(ds, event);
 			complete_dock(ds);
 			dock_event(ds, event, DOCK_EVENT);
-			dock_lock(ds, 1);
+			acpi_evaluate_lck(ds->handle, 1);
 			acpi_update_all_gpes();
 			break;
 		}
@@ -998,9 +900,9 @@ static int __init dock_add(acpi_handle handle)
 	/* we want the dock device to send uevents */
 	dev_set_uevent_suppress(&dd->dev, 0);
 
-	if (is_dock(handle))
+	if (acpi_dock_match(handle))
 		dock_station->flags |= DOCK_IS_DOCK;
-	if (is_ata(handle))
+	if (acpi_ata_match(handle))
 		dock_station->flags |= DOCK_IS_ATA;
 	if (is_battery(handle))
 		dock_station->flags |= DOCK_IS_BAT;
@@ -1043,7 +945,7 @@ err_unregister:
 static __init acpi_status
 find_dock_and_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
-	if (is_dock(handle) || is_ejectable_bay(handle))
+	if (acpi_dock_match(handle) || is_ejectable_bay(handle))
 		dock_add(handle);
 
 	return AE_OK;
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 8/9] ACPI: simpilify scan.c with new interfaces
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
                   ` (6 preceding siblings ...)
  2013-06-26 16:30 ` [PATCH v2 7/9] ACPI: simplify dock driver with new interfaces Jiang Liu
@ 2013-06-26 16:31 ` Jiang Liu
  2013-06-26 16:31 ` [PATCH v2 9/9] ACPI: simplify acpiphp driver " Jiang Liu
  2013-06-26 18:34 ` [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Rafael J. Wysocki
  9 siblings, 0 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:31 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

From: Jiang Liu <jiang.liu@huawei.com>

Use new interfaces to simpilify scan.c.

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/scan.c | 100 ++++++++++++----------------------------------------
 1 file changed, 23 insertions(+), 77 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 3ddba74..d228926 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -194,9 +194,6 @@ static acpi_status acpi_bus_online_companions(acpi_handle handle, u32 lvl,
 static int acpi_scan_hot_remove(struct acpi_device *device)
 {
 	acpi_handle handle = device->handle;
-	acpi_handle not_used;
-	struct acpi_object_list arg_list;
-	union acpi_object arg;
 	struct device *errdev;
 	acpi_status status;
 	unsigned long long sta;
@@ -259,32 +256,15 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
 	put_device(&device->dev);
 	device = NULL;
 
-	if (ACPI_SUCCESS(acpi_get_handle(handle, "_LCK", &not_used))) {
-		arg_list.count = 1;
-		arg_list.pointer = &arg;
-		arg.type = ACPI_TYPE_INTEGER;
-		arg.integer.value = 0;
-		acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
-	}
-
-	arg_list.count = 1;
-	arg_list.pointer = &arg;
-	arg.type = ACPI_TYPE_INTEGER;
-	arg.integer.value = 1;
-
+	acpi_evaluate_lck(handle, 0);
 	/*
 	 * TBD: _EJD support.
 	 */
-	status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
-	if (ACPI_FAILURE(status)) {
-		if (status == AE_NOT_FOUND) {
-			return -ENODEV;
-		} else {
-			acpi_handle_warn(handle, "Eject failed (0x%x)\n",
-								status);
-			return -EIO;
-		}
-	}
+	status = acpi_evaluate_ej0(handle);
+	if (status == AE_NOT_FOUND)
+		return -ENODEV;
+	else if (ACPI_FAILURE(status))
+		return -EIO;
 
 	/*
 	 * Verify if eject was indeed successful.  If not, log an error
@@ -653,7 +633,6 @@ static int acpi_device_setup_files(struct acpi_device *dev)
 {
 	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
 	acpi_status status;
-	acpi_handle temp;
 	unsigned long long sun;
 	int result = 0;
 
@@ -679,8 +658,7 @@ static int acpi_device_setup_files(struct acpi_device *dev)
 	/*
 	 * If device has _STR, 'description' file is created
 	 */
-	status = acpi_get_handle(dev->handle, "_STR", &temp);
-	if (ACPI_SUCCESS(status)) {
+	if (acpi_has_method(dev->handle, "_STR")) {
 		status = acpi_evaluate_object(dev->handle, "_STR",
 					NULL, &buffer);
 		if (ACPI_FAILURE(status))
@@ -710,8 +688,7 @@ static int acpi_device_setup_files(struct acpi_device *dev)
          * If device has _EJ0, 'eject' file is created that is used to trigger
          * hot-removal function from userland.
          */
-	status = acpi_get_handle(dev->handle, "_EJ0", &temp);
-	if (ACPI_SUCCESS(status)) {
+	if (acpi_has_method(dev->handle, "_EJ0")) {
 		result = device_create_file(&dev->dev, &dev_attr_eject);
 		if (result)
 			return result;
@@ -733,9 +710,6 @@ end:
 
 static void acpi_device_remove_files(struct acpi_device *dev)
 {
-	acpi_status status;
-	acpi_handle temp;
-
 	if (dev->flags.power_manageable) {
 		device_remove_file(&dev->dev, &dev_attr_power_state);
 		if (dev->power.flags.power_resources)
@@ -746,20 +720,17 @@ static void acpi_device_remove_files(struct acpi_device *dev)
 	/*
 	 * If device has _STR, remove 'description' file
 	 */
-	status = acpi_get_handle(dev->handle, "_STR", &temp);
-	if (ACPI_SUCCESS(status)) {
+	if (acpi_has_method(dev->handle, "_STR")) {
 		kfree(dev->pnp.str_obj);
 		device_remove_file(&dev->dev, &dev_attr_description);
 	}
 	/*
 	 * If device has _EJ0, remove 'eject' file.
 	 */
-	status = acpi_get_handle(dev->handle, "_EJ0", &temp);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(dev->handle, "_EJ0"))
 		device_remove_file(&dev->dev, &dev_attr_eject);
 
-	status = acpi_get_handle(dev->handle, "_SUN", &temp);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(dev->handle, "_SUN"))
 		device_remove_file(&dev->dev, &dev_attr_sun);
 
 	if (dev->pnp.unique_id)
@@ -1335,13 +1306,10 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
 
 static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
 {
-	acpi_handle temp;
-	acpi_status status = 0;
 	int err;
 
 	/* Presence of _PRW indicates wake capable */
-	status = acpi_get_handle(device->handle, "_PRW", &temp);
-	if (ACPI_FAILURE(status))
+	if (!acpi_has_method(device->handle, "_PRW"))
 		return;
 
 	err = acpi_bus_extract_wakeup_device_power_package(device->handle,
@@ -1371,7 +1339,6 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state)
 	struct acpi_device_power_state *ps = &device->power.states[state];
 	char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-	acpi_handle handle;
 	acpi_status status;
 
 	INIT_LIST_HEAD(&ps->resources);
@@ -1394,8 +1361,7 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state)
 
 	/* Evaluate "_PSx" to see if we can do explicit sets */
 	pathname[2] = 'S';
-	status = acpi_get_handle(device->handle, pathname, &handle);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(device->handle, pathname))
 		ps->flags.explicit_set = 1;
 
 	/*
@@ -1414,28 +1380,21 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state)
 
 static void acpi_bus_get_power_flags(struct acpi_device *device)
 {
-	acpi_status status;
-	acpi_handle handle;
 	u32 i;
 
 	/* Presence of _PS0|_PR0 indicates 'power manageable' */
-	status = acpi_get_handle(device->handle, "_PS0", &handle);
-	if (ACPI_FAILURE(status)) {
-		status = acpi_get_handle(device->handle, "_PR0", &handle);
-		if (ACPI_FAILURE(status))
-			return;
-	}
+	if (!acpi_has_method(device->handle, "_PS0") &&
+	    !acpi_has_method(device->handle, "_PR0"))
+		return;
 
 	device->flags.power_manageable = 1;
 
 	/*
 	 * Power Management Flags
 	 */
-	status = acpi_get_handle(device->handle, "_PSC", &handle);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(device->handle, "_PSC"))
 		device->power.flags.explicit_get = 1;
-	status = acpi_get_handle(device->handle, "_IRC", &handle);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(device->handle, "_IRC"))
 		device->power.flags.inrush_current = 1;
 
 	/*
@@ -1469,28 +1428,18 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
 
 static void acpi_bus_get_flags(struct acpi_device *device)
 {
-	acpi_status status = AE_OK;
-	acpi_handle temp = NULL;
-
 	/* Presence of _STA indicates 'dynamic_status' */
-	status = acpi_get_handle(device->handle, "_STA", &temp);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(device->handle, "_STA"))
 		device->flags.dynamic_status = 1;
 
 	/* Presence of _RMV indicates 'removable' */
-	status = acpi_get_handle(device->handle, "_RMV", &temp);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(device->handle, "_RMV"))
 		device->flags.removable = 1;
 
 	/* Presence of _EJD|_EJ0 indicates 'ejectable' */
-	status = acpi_get_handle(device->handle, "_EJD", &temp);
-	if (ACPI_SUCCESS(status))
+	if (acpi_has_method(device->handle, "_EJD") ||
+	    acpi_has_method(device->handle, "_EJ0"))
 		device->flags.ejectable = 1;
-	else {
-		status = acpi_get_handle(device->handle, "_EJ0", &temp);
-		if (ACPI_SUCCESS(status))
-			device->flags.ejectable = 1;
-	}
 }
 
 static void acpi_device_get_busid(struct acpi_device *device)
@@ -1891,7 +1840,6 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
 	struct acpi_device *device = NULL;
 	int type;
 	unsigned long long sta;
-	acpi_status status;
 	int result;
 
 	acpi_bus_get_device(handle, &device);
@@ -1912,10 +1860,8 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
 	if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
 	    !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
 		struct acpi_device_wakeup wakeup;
-		acpi_handle temp;
 
-		status = acpi_get_handle(handle, "_PRW", &temp);
-		if (ACPI_SUCCESS(status)) {
+		if (acpi_has_method(handle, "_PRW")) {
 			acpi_bus_extract_wakeup_device_power_package(handle,
 								     &wakeup);
 			acpi_power_resources_list_free(&wakeup.resources);
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 9/9] ACPI: simplify acpiphp driver with new interfaces
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
                   ` (7 preceding siblings ...)
  2013-06-26 16:31 ` [PATCH v2 8/9] ACPI: simpilify scan.c " Jiang Liu
@ 2013-06-26 16:31 ` Jiang Liu
  2013-06-26 18:34 ` [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Rafael J. Wysocki
  9 siblings, 0 replies; 14+ messages in thread
From: Jiang Liu @ 2013-06-26 16:31 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: liuj97, Jiang Liu, Yijing Wang, linux-acpi, linux-kernel,
	Bjorn Helgaas, Yinghai Lu, Len Brown, linux-pci

From: Jiang Liu <jiang.liu@huawei.com>

Use new interfaces to simplify acpiphp driver.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Jiang Liu <liuj97@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Yijing Wang <wangyijing@huawei.com>
Cc: linux-acpi@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/pci/hotplug/acpiphp_glue.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 59df857..a0a7133 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -201,7 +201,6 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
 	struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
 	struct acpiphp_slot *slot;
 	struct acpiphp_func *newfunc;
-	acpi_handle tmp;
 	acpi_status status = AE_OK;
 	unsigned long long adr, sun;
 	int device, function, retval, found = 0;
@@ -232,19 +231,19 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
 	newfunc->handle = handle;
 	newfunc->function = function;
 
-	if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
+	if (acpi_has_method(handle, "_EJ0"))
 		newfunc->flags = FUNC_HAS_EJ0;
 
-	if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp)))
+	if (acpi_has_method(handle, "_STA"))
 		newfunc->flags |= FUNC_HAS_STA;
 
-	if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS0", &tmp)))
+	if (acpi_has_method(handle, "_PS0"))
 		newfunc->flags |= FUNC_HAS_PS0;
 
-	if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp)))
+	if (acpi_has_method(handle, "_PS3"))
 		newfunc->flags |= FUNC_HAS_PS3;
 
-	if (ACPI_SUCCESS(acpi_get_handle(handle, "_DCK", &tmp)))
+	if (acpi_has_method(handle, "_DCK"))
 		newfunc->flags |= FUNC_HAS_DCK;
 
 	status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
@@ -843,25 +842,14 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
  */
 int acpiphp_eject_slot(struct acpiphp_slot *slot)
 {
-	acpi_status status;
 	struct acpiphp_func *func;
-	struct acpi_object_list arg_list;
-	union acpi_object arg;
 
 	list_for_each_entry(func, &slot->funcs, sibling) {
 		/* We don't want to call _EJ0 on non-existing functions. */
 		if ((func->flags & FUNC_HAS_EJ0)) {
-			/* _EJ0 method take one argument */
-			arg_list.count = 1;
-			arg_list.pointer = &arg;
-			arg.type = ACPI_TYPE_INTEGER;
-			arg.integer.value = 1;
-
-			status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
-			if (ACPI_FAILURE(status)) {
-				warn("%s: _EJ0 failed\n", __func__);
+			if (ACPI_FAILURE(acpi_evaluate_ej0(func->handle)))
 				return -1;
-			} else
+			else
 				break;
 		}
 	}
@@ -1171,7 +1159,6 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type,
  */
 void acpiphp_enumerate_slots(struct pci_bus *bus, acpi_handle handle)
 {
-	acpi_handle dummy_handle;
 	struct acpiphp_bridge *bridge;
 
 	if (acpiphp_disabled)
@@ -1200,8 +1187,7 @@ void acpiphp_enumerate_slots(struct pci_bus *bus, acpi_handle handle)
 	get_device(&bus->dev);
 
 	if (!pci_is_root_bus(bridge->pci_bus) &&
-	    ACPI_SUCCESS(acpi_get_handle(bridge->handle,
-					"_EJ0", &dummy_handle))) {
+	    acpi_has_method(bridge->handle, "_EJ0")) {
 		dbg("found ejectable p2p bridge\n");
 		bridge->flags |= BRIDGE_HAS_EJ0;
 		bridge->func = acpiphp_bridge_handle_to_function(handle);
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers
  2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
                   ` (8 preceding siblings ...)
  2013-06-26 16:31 ` [PATCH v2 9/9] ACPI: simplify acpiphp driver " Jiang Liu
@ 2013-06-26 18:34 ` Rafael J. Wysocki
  9 siblings, 0 replies; 14+ messages in thread
From: Rafael J. Wysocki @ 2013-06-26 18:34 UTC (permalink / raw)
  To: Jiang Liu; +Cc: Jiang Liu, Yijing Wang, linux-acpi, linux-kernel

On Thursday, June 27, 2013 12:30:52 AM Jiang Liu wrote:
> From: Jiang Liu <jiang.liu@huawei.com>
> 
> This is an following up patchset of "[PATCH 0/3] ACPI / dock / PCI: Fix
> problems with dock and PCI hotplug" with minor code cleanups and
> refinements. It applies to
> git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
> 
> Due to hardware resource limitation, I have only done compilation and
> boot tests.
> 
> Jiang Liu (9):
>   ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times
>   ACPI, DOCK: kill redundant spin lock in dock station object
>   ACPI, DOCK: mark initialization functions with __init
>   ACPI, DOCK: simplify implementation of dock_create_acpi_device()
>   ACPI: introduce three helper functions
>   ACPI: change acpi_[bay|dock]_match() in scan.c as global functions
>   ACPI: simplify dock driver with new interfaces
>   ACPI: simpilify scan.c with new interfaces
>   ACPI: simplify acpiphp driver with new interfaces
> 
>  drivers/acpi/dock.c                | 152 ++++---------------------------
>  drivers/acpi/scan.c                | 182 ++++++++++++-------------------------
>  drivers/acpi/utils.c               |  72 +++++++++++++++
>  drivers/pci/hotplug/acpiphp_glue.c |  30 ++----
>  include/acpi/acpi_bus.h            |   8 ++
>  5 files changed, 168 insertions(+), 276 deletions(-)

I'll queue up patches [1-4/9] for 3.12, but I have comments regarding the rest.

Thanks,
Rafael


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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 5/9] ACPI: introduce three helper functions
  2013-06-26 16:30 ` [PATCH v2 5/9] ACPI: introduce three helper functions Jiang Liu
@ 2013-06-26 18:49   ` Rafael J. Wysocki
  2013-06-26 23:46     ` Rafael J. Wysocki
  0 siblings, 1 reply; 14+ messages in thread
From: Rafael J. Wysocki @ 2013-06-26 18:49 UTC (permalink / raw)
  To: Jiang Liu; +Cc: Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

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

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 7/9] ACPI: simplify dock driver with new interfaces
  2013-06-26 16:30 ` [PATCH v2 7/9] ACPI: simplify dock driver with new interfaces Jiang Liu
@ 2013-06-26 23:12   ` Bjorn Helgaas
  0 siblings, 0 replies; 14+ messages in thread
From: Bjorn Helgaas @ 2013-06-26 23:12 UTC (permalink / raw)
  To: Jiang Liu
  Cc: Rafael J . Wysocki, Jiang Liu, Yijing Wang, linux-acpi,
	linux-kernel, Len Brown

On Wed, Jun 26, 2013 at 10:30 AM, Jiang Liu <liuj97@gmail.com> wrote:
> From: Jiang Liu <jiang.liu@huawei.com>
>
> Use new helper functions to simpilify ACPI dock driver.

s/simpilify/simplify/

I noticed this spelling error in other places, too, some in subject lines.

Very nice cleanups overall.

> 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/dock.c | 122 ++++++----------------------------------------------
>  1 file changed, 12 insertions(+), 110 deletions(-)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 5/9] ACPI: introduce three helper functions
  2013-06-26 18:49   ` Rafael J. Wysocki
@ 2013-06-26 23:46     ` Rafael J. Wysocki
  0 siblings, 0 replies; 14+ messages in thread
From: Rafael J. Wysocki @ 2013-06-26 23:46 UTC (permalink / raw)
  To: Jiang Liu; +Cc: Jiang Liu, Yijing Wang, linux-acpi, linux-kernel, Len Brown

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


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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-06-26 23:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-26 16:30 [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Jiang Liu
2013-06-26 16:30 ` [PATCH v2 1/9] ACPI, DOCK: avoid initializing acpi_dock_notifier_list multiple times Jiang Liu
2013-06-26 16:30 ` [PATCH v2 2/9] ACPI, DOCK: kill redundant spin lock in dock station object Jiang Liu
2013-06-26 16:30 ` [PATCH v2 3/9] ACPI, DOCK: mark initialization functions with __init Jiang Liu
2013-06-26 16:30 ` [PATCH v2 4/9] ACPI, DOCK: simplify implementation of dock_create_acpi_device() Jiang Liu
2013-06-26 16:30 ` [PATCH v2 5/9] ACPI: introduce three helper functions Jiang Liu
2013-06-26 18:49   ` Rafael J. Wysocki
2013-06-26 23:46     ` Rafael J. Wysocki
2013-06-26 16:30 ` [PATCH v2 6/9] ACPI: change acpi_[bay|dock]_match() in scan.c as global functions Jiang Liu
2013-06-26 16:30 ` [PATCH v2 7/9] ACPI: simplify dock driver with new interfaces Jiang Liu
2013-06-26 23:12   ` Bjorn Helgaas
2013-06-26 16:31 ` [PATCH v2 8/9] ACPI: simpilify scan.c " Jiang Liu
2013-06-26 16:31 ` [PATCH v2 9/9] ACPI: simplify acpiphp driver " Jiang Liu
2013-06-26 18:34 ` [PATCH v2 0/9] minor improvements for ACPI dock and acpiphp drivers Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.