Skip to contentSkip to conversation

ACPICA: Add acpi_check_gpe_method() to check GPE method

RFC PATCH In review Lan Tianyu 3 participants 8 messages Jul 8, 2014 – Jul 11, 2014

Subsystems (2)
lore
Share & tools
lore

Lan Tianyu

author
#0 lore raw

RFC PATCH 1/2 ACPICA: Add acpi_check_gpe_method() to check GPE method

This patch is to expose acpi_check_gpe_method() to check whether there is a GPE method for the given gpe. Enabling ACPI button devices' gpes will depend on the new function's result.

---
 drivers/acpi/acpica/evxface.c | 39 ++++++++++++++++++++++++++++++++++++++-
 include/acpi/acpixf.h         |  3 +++
 2 files changed, 41 insertions(+), 1 deletion(-)
drivers/acpi/acpica/evxface.c +38 -1
index 11e5803..0fcb248 100644
@@ -717,6 +717,44 @@ ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
 
 /*******************************************************************************
  *
+ * FUNCTION:    acpi_check_gpe_method
+ *
+ * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT
+ *                                defined GPEs)
+ *              gpe_number      - The event to remove a handler
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Check whether the given GPE has associated event method.
+ *
+ ******************************************************************************/
+acpi_status
+acpi_check_gpe_method(acpi_handle gpe_device, u32 gpe_number)
+{
+	struct acpi_gpe_event_info *gpe_event_info;
+	acpi_status status = AE_NOT_EXIST;
+	acpi_cpu_flags flags;
+
+	ACPI_FUNCTION_TRACE(acpi_check_gpe_method);
+
+	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
+	if (!gpe_event_info) {
+		status = AE_ERROR;
+		goto unlock_and_exit;
+	}
+
+	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)
+		status = AE_OK;
+
+unlock_and_exit:
+	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+	return status;
+}
+ACPI_EXPORT_SYMBOL(acpi_check_gpe_method)
+
+/*******************************************************************************
+ *
  * FUNCTION:    acpi_install_gpe_handler
  *
  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT
@@ -821,7 +859,6 @@ free_and_exit:
 	ACPI_FREE(handler);
 	goto unlock_and_exit;
 }
-
 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
 
 /*******************************************************************************
include/acpi/acpixf.h +3 -0
index 35b525c..5b475c6 100644
@@ -554,6 +554,9 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 							  address,
 							  void *context))
 ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
+				acpi_check_gpe_method(acpi_handle gpe_device,
+							u32 gpe_number))
+ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 				 acpi_remove_gpe_handler(acpi_handle gpe_device,
 							 u32 gpe_number,
 							 acpi_gpe_handler
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
author
#1 lore raw

RFC PATCH 2/2 ACPI/Wakup: Enable button wakeup GPEs if these GPEs have associated GPE methods.

The button wakeup GPEs are enabled unconditionally in the current world by commit 2a5d24(ACPI / Wakeup: Enable button GPEs unconditionally during initialization). Because button's GPE methods needs to be run to clear GPE status on some machines when there is GPE interrupt. If not, it will cause machines resume immediately after being suspended since GPE status isn't cleared correctly.

But if there is no GPE method for button wakeup GPE, these GPEs should not be enabled since nothing needs to be done when they are triggered and this also causes LID GPE storm on Lenovo Ideapad y560p.

This patch is to check Button GPE method and enable it if there is associated GPE method.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=61051

---
 drivers/acpi/wakeup.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/acpi/wakeup.c +8 -3
index 1638401..5b20ae4 100644
@@ -86,9 +86,14 @@ int __init acpi_wakeup_device_init(void)
 						       struct acpi_device,
 						       wakeup_list);
 		if (device_can_wakeup(&dev->dev)) {
-			/* Button GPEs are supposed to be always enabled. */
-			acpi_enable_gpe(dev->wakeup.gpe_device,
-					dev->wakeup.gpe_number);
+			/*
+			 * Button GPEs are supposed to be always enabled if
+			 * they have associated GPE methods.
+			 */
+			if (ACPI_SUCCESS(acpi_check_gpe_method(
+			    dev->wakeup.gpe_device, dev->wakeup.gpe_number)))
+				acpi_enable_gpe(dev->wakeup.gpe_device,
+						dev->wakeup.gpe_number);
 			device_set_wakeup_enable(&dev->dev, true);
 		}
 	}
Signature · 1 line
1.8.4.rc0.1.g8f6a3e5.dirty
#2 lore raw

Re: [RFC PATCH 2/2] ACPI/Wakup: Enable button wakeup GPEs if these GPEs have associated GPE methods.

Quoted 7 lines · Lan Tianyu

The button wakeup GPEs are enabled unconditionally in the current world by commit 2a5d24(ACPI / Wakeup: Enable button GPEs unconditionally during initialization). Because button's GPE methods needs to be run to clear GPE status on some machines when there is GPE interrupt. If not, it will cause machines resume immediately after being suspended since GPE status isn't cleared correctly.

Quoted 6 lines

But if there is no GPE method for button wakeup GPE, these GPEs should not be enabled since nothing needs to be done when they are triggered and this also causes LID GPE storm on Lenovo Ideapad y560p.

This patch is to check Button GPE method and enable it if there is associated GPE method.

Part of the problem is that we call acpi_setup_gpe_for_wake() for buttons too and it sets ACPI_GPE_DISPATCH_NOTIFY unconditionally. While we could address this the way you're proposing, it seems a bit less than straightforward so to speak.

Let me think more about how to address that.

Quoted 30 lines

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=61051

---
 drivers/acpi/wakeup.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/acpi/wakeup.c +8 -3
index 1638401..5b20ae4 100644
@@ -86,9 +86,14 @@ int __init acpi_wakeup_device_init(void)
 						       struct acpi_device,
 						       wakeup_list);
 		if (device_can_wakeup(&dev->dev)) {
-			/* Button GPEs are supposed to be always enabled. */
-			acpi_enable_gpe(dev->wakeup.gpe_device,
-					dev->wakeup.gpe_number);
+			/*
+			 * Button GPEs are supposed to be always enabled if
+			 * they have associated GPE methods.
+			 */
+			if (ACPI_SUCCESS(acpi_check_gpe_method(
+			    dev->wakeup.gpe_device, dev->wakeup.gpe_number)))
+				acpi_enable_gpe(dev->wakeup.gpe_device,
+						dev->wakeup.gpe_number);
 			device_set_wakeup_enable(&dev->dev, true);
 		}
 	}
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
author
#3 lore raw

Re: [RFC PATCH 2/2] ACPI/Wakup: Enable button wakeup GPEs if these GPEs have associated GPE methods.

Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Lan Tianyu

The button wakeup GPEs are enabled unconditionally in the current world by commit 2a5d24(ACPI / Wakeup: Enable button GPEs unconditionally during initialization). Because button's GPE methods needs to be run to clear GPE status on some machines when there is GPE interrupt. If not, it will cause machines resume immediately after being suspended since GPE status isn't cleared correctly.

But if there is no GPE method for button wakeup GPE, these GPEs should not be enabled since nothing needs to be done when they are triggered and this also causes LID GPE storm on Lenovo Ideapad y560p.

Quoted 5 lines
Quoted 2 lines

This patch is to check Button GPE method and enable it if there is associated GPE method.

Part of the problem is that we call acpi_setup_gpe_for_wake() for buttons too and it sets ACPI_GPE_DISPATCH_NOTIFY unconditionally.

Yes, this is why the GPE wasn't disabled by CA. From my opinion, original reason of enabling button wakeup GPE in the runtime is that it may have associated GPE method and the method will notify button driver and clear some hardware status. But if it didn't have GPE method, I don't why we need to enable the GPE. I check some machines and they use EC Query event to notify button driver.

Quoted 5 lines

While we could address
this the way you're proposing, it seems a bit less than straightforward so to speak.

Let me think more about how to address that.

Ok. I get it.

Quoted 32 lines
Quoted 31 lines

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=61051

---
 drivers/acpi/wakeup.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/acpi/wakeup.c +8 -3
index 1638401..5b20ae4 100644
@@ -86,9 +86,14 @@ int __init acpi_wakeup_device_init(void)
 						       struct acpi_device,
 						       wakeup_list);
 		if (device_can_wakeup(&dev->dev)) {
-			/* Button GPEs are supposed to be always enabled. */
-			acpi_enable_gpe(dev->wakeup.gpe_device,
-					dev->wakeup.gpe_number);
+			/*
+			 * Button GPEs are supposed to be always enabled if
+			 * they have associated GPE methods.
+			 */
+			if (ACPI_SUCCESS(acpi_check_gpe_method(
+			    dev->wakeup.gpe_device, dev->wakeup.gpe_number)))
+				acpi_enable_gpe(dev->wakeup.gpe_device,
+						dev->wakeup.gpe_number);
 			device_set_wakeup_enable(&dev->dev, true);
 		}
 	}
Signature · 6 lines
Best regards
Tianyu Lan
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

Re: [RFC PATCH 2/2] ACPI/Wakup: Enable button wakeup GPEs if these GPEs have associated GPE methods.

Quoted 16 lines · Lan Tianyu
Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Lan Tianyu

The button wakeup GPEs are enabled unconditionally in the current world by commit 2a5d24(ACPI / Wakeup: Enable button GPEs unconditionally during initialization). Because button's GPE methods needs to be run to clear GPE status on some machines when there is GPE interrupt. If not, it will cause machines resume immediately after being suspended since GPE status isn't cleared correctly.

But if there is no GPE method for button wakeup GPE, these GPEs should not be enabled since nothing needs to be done when they are triggered and this also causes LID GPE storm on Lenovo Ideapad y560p.

This patch is to check Button GPE method and enable it if there is associated GPE method.

Quoted 8 lines
Quoted 2 lines

Part of the problem is that we call acpi_setup_gpe_for_wake() for buttons too and it sets ACPI_GPE_DISPATCH_NOTIFY unconditionally.

Yes, this is why the GPE wasn't disabled by CA. From my opinion, original reason of enabling button wakeup GPE in the runtime is that it may have associated GPE method and the method will notify button driver and clear some hardware status. But if it didn't have GPE method, I don't why we need to enable the GPE.

I think you're right, but "is there a handler method for that GPE present?" is a bit too low-level question to ask from outside of ACPICA. We should be asking "is there any kind of handling registered for it?" if anything, but in my opinion the cleanest approach would be to modify acpi_enable_gpe() to return an error code if there's no handler/method/notify for the GPE in question.

The patch I attached to the BZ entry doesn't do that just yet, because I'm wondering whether or not it will make the ACPICA's auto-disabling trigger. :-)

Rafael

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

#5 lore raw
In reply to Lan Tianyu
Quoted 21 lines · Lan Tianyu

This patch is to expose acpi_check_gpe_method() to check whether there is a GPE method for the given gpe. Enabling ACPI button devices' gpes will depend on the new function's result.

---
 drivers/acpi/acpica/evxface.c | 39 ++++++++++++++++++++++++++++++++++++++-
 include/acpi/acpixf.h         |  3 +++
 2 files changed, 41 insertions(+), 1 deletion(-)
drivers/acpi/acpica/evxface.c +3 -0
index 11e5803..0fcb248 100644
@@ -717,6 +717,44 @@ ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
 
 /*******************************************************************************
  *
+ * FUNCTION:    acpi_check_gpe_method
+ *
+ * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT

drivers/acpi/acpica/evxface.c ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler) · line 732

Quoted 10 lines
drivers/acpi/acpica/evxface.c +10 -0
+ *                                defined GPEs)
+ *              gpe_number      - The event to remove a handler
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Check whether the given GPE has associated event method.
+ *
+ ******************************************************************************/
+acpi_status
+acpi_check_gpe_method(acpi_handle gpe_device, u32 gpe_number)

This should be a boolean routine (ie. returning 0 or 1) called something like acpi_gpe_has_method() that will return 1 if there's a method for the given GPE and 0 otherwise.

Quoted 51 lines
drivers/acpi/acpica/evxface.c +25 -1
+{
+	struct acpi_gpe_event_info *gpe_event_info;
+	acpi_status status = AE_NOT_EXIST;
+	acpi_cpu_flags flags;
+
+	ACPI_FUNCTION_TRACE(acpi_check_gpe_method);
+
+	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
+	if (!gpe_event_info) {
+		status = AE_ERROR;
+		goto unlock_and_exit;
+	}
+
+	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)
+		status = AE_OK;
+
+unlock_and_exit:
+	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+	return status;
+}
+ACPI_EXPORT_SYMBOL(acpi_check_gpe_method)
+
+/*******************************************************************************
+ *
  * FUNCTION:    acpi_install_gpe_handler
  *
  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT
@@ -821,7 +859,6 @@ free_and_exit:
 	ACPI_FREE(handler);
 	goto unlock_and_exit;
 }
-
 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
 
 /*******************************************************************************
include/acpi/acpixf.h +3 -0
index 35b525c..5b475c6 100644
@@ -554,6 +554,9 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 							  address,
 							  void *context))
 ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
+				acpi_check_gpe_method(acpi_handle gpe_device,
+							u32 gpe_number))
+ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 				 acpi_remove_gpe_handler(acpi_handle gpe_device,
 							 u32 gpe_number,
 							 acpi_gpe_handler
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#6 lore raw
In reply to Lan Tianyu

Since what is returned by this interface is essentially a piece of information about the particular GPE, I think that it might be better to generalize this interface to a "GetInfo" type of interface that returns a few pieces of information about the GPE.

Quoted 100 lines

-----Original Message-----
From: Lan, Tianyu
Sent: Monday, July 07, 2014 11:58 PM
To: Moore, Robert; Zheng, Lv; Wysocki, Rafael J; [email protected]
Cc: Lan, Tianyu; [email protected]; [email protected]
Subject: [RFC PATCH 1/2] ACPICA: Add acpi_check_gpe_method() to check GPE method

This patch is to expose acpi_check_gpe_method() to check whether there is a GPE method for the given gpe. Enabling ACPI button devices' gpes will depend on the new function's result.

---
 drivers/acpi/acpica/evxface.c | 39
++++++++++++++++++++++++++++++++++++++-
 include/acpi/acpixf.h         |  3 +++
 2 files changed, 41 insertions(+), 1 deletion(-)
drivers/acpi/acpica/evxface.c +3 -0
index 11e5803..0fcb248 100644
@@ -717,6 +717,44 @@ ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
 
 
 /*************************************************************************
 ******
  *
+ * FUNCTION:    acpi_check_gpe_method
+ *
+ * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for

FADT
+ * defined GPEs)
+ * gpe_number - The event to remove a handler
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Check whether the given GPE has associated event method.
+ *

drivers/acpi/acpica/evxface.c +30 -0
+
+***********************************************************************
+*******/
+acpi_status
+acpi_check_gpe_method(acpi_handle gpe_device, u32 gpe_number) {
+	struct acpi_gpe_event_info *gpe_event_info;
+	acpi_status status = AE_NOT_EXIST;
+	acpi_cpu_flags flags;
+
+	ACPI_FUNCTION_TRACE(acpi_check_gpe_method);
+
+	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
+	if (!gpe_event_info) {
+		status = AE_ERROR;
+		goto unlock_and_exit;
+	}
+
+	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)
+		status = AE_OK;
+
+unlock_and_exit:
+	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+	return status;
+}
+ACPI_EXPORT_SYMBOL(acpi_check_gpe_method)
+
+/**********************************************************************
+*********
+ *
  * FUNCTION:    acpi_install_gpe_handler
  *
  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for

FADT

drivers/acpi/acpica/evxface.c +0 -1
@@ -821,7 +859,6 @@ free_and_exit:
 	ACPI_FREE(handler);
 	goto unlock_and_exit;
 }
-
 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
 
 

/*************************************************************************
******

include/acpi/acpixf.h index renamed from include/acpi/acpixf.h +0 -0

35b525c..5b475c6 100644

include/acpi/acpixf.h +3 -1
@@ -554,6 +554,9 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 							  address,
 							  void *context))
 ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
+				acpi_check_gpe_method(acpi_handle gpe_device,
+							u32 gpe_number))
+ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 				 acpi_remove_gpe_handler(acpi_handle gpe_device,
 							 u32 gpe_number,
 							 acpi_gpe_handler
--

1.8.4.rc0.1.g8f6a3e5.dirty

author
#7 lore raw
Quoted 2 lines · Robert

Since what is returned by this interface is essentially a piece of information about the particular GPE, I think that it might be better to generalize this interface to a "GetInfo" type of interface that returns a few pieces of information about the GPE.

Hi Bob:

Thanks for your review. Yes, that's good suggestion. But Rafael has new
solution to fix the issue. So this patch maybe not necessary.

Quoted 103 lines
Quoted 102 lines

-----Original Message-----
From: Lan, Tianyu
Sent: Monday, July 07, 2014 11:58 PM
To: Moore, Robert; Zheng, Lv; Wysocki, Rafael J; [email protected]
Cc: Lan, Tianyu; [email protected]; [email protected]
Subject: [RFC PATCH 1/2] ACPICA: Add acpi_check_gpe_method() to check GPE method

This patch is to expose acpi_check_gpe_method() to check whether there is a GPE method for the given gpe. Enabling ACPI button devices' gpes will depend on the new function's result.

---
 drivers/acpi/acpica/evxface.c | 39
++++++++++++++++++++++++++++++++++++++-
 include/acpi/acpixf.h         |  3 +++
 2 files changed, 41 insertions(+), 1 deletion(-)
drivers/acpi/acpica/evxface.c +3 -0
index 11e5803..0fcb248 100644
@@ -717,6 +717,44 @@ ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
 
 
 /*************************************************************************
 ******
  *
+ * FUNCTION:    acpi_check_gpe_method
+ *
+ * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for

FADT
+ * defined GPEs)
+ * gpe_number - The event to remove a handler
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Check whether the given GPE has associated event method.
+ *

drivers/acpi/acpica/evxface.c +30 -0
+
+***********************************************************************
+*******/
+acpi_status
+acpi_check_gpe_method(acpi_handle gpe_device, u32 gpe_number) {
+	struct acpi_gpe_event_info *gpe_event_info;
+	acpi_status status = AE_NOT_EXIST;
+	acpi_cpu_flags flags;
+
+	ACPI_FUNCTION_TRACE(acpi_check_gpe_method);
+
+	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
+	if (!gpe_event_info) {
+		status = AE_ERROR;
+		goto unlock_and_exit;
+	}
+
+	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)
+		status = AE_OK;
+
+unlock_and_exit:
+	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+	return status;
+}
+ACPI_EXPORT_SYMBOL(acpi_check_gpe_method)
+
+/**********************************************************************
+*********
+ *
  * FUNCTION:    acpi_install_gpe_handler
  *
  * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for

FADT

drivers/acpi/acpica/evxface.c +0 -1
@@ -821,7 +859,6 @@ free_and_exit:
 	ACPI_FREE(handler);
 	goto unlock_and_exit;
 }
-
 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
 
 

/*************************************************************************
******

include/acpi/acpixf.h index renamed from include/acpi/acpixf.h +0 -0

35b525c..5b475c6 100644

include/acpi/acpixf.h +3 -1
@@ -554,6 +554,9 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 							  address,
 							  void *context))
 ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
+				acpi_check_gpe_method(acpi_handle gpe_device,
+							u32 gpe_number))
+ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
 				 acpi_remove_gpe_handler(acpi_handle gpe_device,
 							 u32 gpe_number,
 							 acpi_gpe_handler
--

1.8.4.rc0.1.g8f6a3e5.dirty

Signature · 6 lines
Best regards
Tianyu Lan
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html