Skip to contentSkip to conversation

Recent GPE patches - some questions.

RFC PATCH In review Moore, Robert 4 participants 25 messages Jan 29, 2010 – Feb 14, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Matthew,

I've looked at the new GPE code and I have some comments and questions. I'm still looking at Patch 3/3, "Remove old GPE API and transition code entirely to new one", but here are the questions I have so far.

Thanks,
Bob

[PATCH 0/3] acpica: Rewrite GPE handling

Overall, can we say that this change to the GPE code is primarily intended to add better support for shared GPEs?

I see that the execution of _PRW methods is no longer removed. This was a big question I had about the original patch.

[PATCH 1/3] ACPI: Add infrastructure for refcounting GPE consumers:

Quoted 3 lines

Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

I'm not sure which interface you are referring to, please explain

[PATCH 2/3] ACPI: Add support for new refcounted GPE API to drivers:

Reference count mechanism is meant to:
1) Enable GPE only on the first added reference
2) Disable GPE only on the last removed reference

Then I don't understand why the code below needs to call acpi_enable_gpe:

		acpi_enable_gpe(dev->wakeup.gpe_device,

dev->wakeup.gpe_number);
+ acpi_ref_wakeup_gpe(dev->wakeup.gpe_device,
+ dev->wakeup.gpe_number);

Because the GPE will be "enabled" (mask bit set for wakeup GPE) by acpi_ref_wakeup_gpe. There are several examples of this type of code. If it is true that the call to acpi_enable_gpe is unnecessary, then is acpi_enable_gpe interface needed at all? (same with disable_gpe).

[PATCH 2/3] acpica: Add support for unregistering ACPI GPE methods:

acpi_remove_gpe_method: Ok, this makes sense. Sad, but makes sense.

[PATCH 1/3] acpi: Provide default GPE handler if the firmware doesn't

Quoted 2 lines

Firmware may support using GPEs for system wakeup without providing any runtime GPE handlers.

Do you mean by "runtime GPE handlers" to mean the _Lxx/_Exx GPE methods? If so, this should be clarified in the comments.

#1 lore raw
Quoted 4 lines · Robert

[PATCH 0/3] acpica: Rewrite GPE handling

Overall, can we say that this change to the GPE code is primarily intended to add better support for shared GPEs?

Yes, that's probably the easiest way to look at it.

Quoted 7 lines

[PATCH 1/3] ACPI: Add infrastructure for refcounting GPE consumers:

Quoted 3 lines

Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

I'm not sure which interface you are referring to, please explain

This is simply the ref/unref functions.

Quoted 13 lines

[PATCH 2/3] ACPI: Add support for new refcounted GPE API to drivers:

Reference count mechanism is meant to:
1) Enable GPE only on the first added reference
2) Disable GPE only on the last removed reference

Then I don't understand why the code below needs to call acpi_enable_gpe:

		acpi_enable_gpe(dev->wakeup.gpe_device,
(quoted diff) +2 -0
 				dev->wakeup.gpe_number);
+		acpi_ref_wakeup_gpe(dev->wakeup.gpe_device,
+				    dev->wakeup.gpe_number);
Quoted 4 lines

Because the GPE will be "enabled" (mask bit set for wakeup GPE) by acpi_ref_wakeup_gpe. There are several examples of this type of code. If it is true that the call to acpi_enable_gpe is unnecessary, then is acpi_enable_gpe interface needed at all? (same with disable_gpe).

That's simply to make it easier to bisect through the changes - 3/3 removes the explicit enable_gpe call.

Quoted 6 lines

[PATCH 1/3] acpi: Provide default GPE handler if the firmware doesn't

Quoted 2 lines

Firmware may support using GPEs for system wakeup without providing any runtime GPE handlers.

Do you mean by "runtime GPE handlers" to mean the _Lxx/_Exx GPE methods? If so, this should be clarified in the comments.

Ok. I'm not sure that we'll be pushing this aspect of it yet, we'll have to wait and see what the hardware support situation ends up being.

Signature · 1 line
Matthew Garrett | [email protected]
#2 lore raw

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

While I understand the need for the reference counting mechanism, it is a good idea to support the shared GPEs, I think it may be simpler and cleaner to simply not directly expose this mechanism to GPE users.

I'm suggesting that we add the reference counting mechanism to the existing AcpiEnableGpe and AcpiDisableGpe interfaces and update their descriptions. We already hide the differences between wake, run, and wake-run GPEs behind these interfaces. Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first call.
AcpiDisableGpe: For a given GPE, it is actually disabled only on the last call.

Bob

Quoted 61 lines

-----Original Message-----
From: Matthew Garrett [mailto:[email protected]]
Sent: Monday, February 01, 2010 2:36 PM
To: Moore, Robert
Cc: [email protected]; [email protected]
Subject: Re: Recent GPE patches - some questions.

Quoted 4 lines · Robert

[PATCH 0/3] acpica: Rewrite GPE handling

Overall, can we say that this change to the GPE code is primarily intended to add better support for shared GPEs?

Yes, that's probably the easiest way to look at it.

Quoted 7 lines

[PATCH 1/3] ACPI: Add infrastructure for refcounting GPE consumers:

Quoted 3 lines

Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

I'm not sure which interface you are referring to, please explain

This is simply the ref/unref functions.

Quoted 13 lines

[PATCH 2/3] ACPI: Add support for new refcounted GPE API to drivers:

Reference count mechanism is meant to:
1) Enable GPE only on the first added reference
2) Disable GPE only on the last removed reference

Then I don't understand why the code below needs to call acpi_enable_gpe:

		acpi_enable_gpe(dev->wakeup.gpe_device,
(quoted diff) +2 -0
 				dev->wakeup.gpe_number);
+		acpi_ref_wakeup_gpe(dev->wakeup.gpe_device,
+				    dev->wakeup.gpe_number);
Quoted 4 lines

Because the GPE will be "enabled" (mask bit set for wakeup GPE) by acpi_ref_wakeup_gpe. There are several examples of this type of code. If it is true that the call to acpi_enable_gpe is unnecessary, then is acpi_enable_gpe interface needed at all? (same with disable_gpe).

That's simply to make it easier to bisect through the changes - 3/3 removes the explicit enable_gpe call.

Quoted 6 lines

[PATCH 1/3] acpi: Provide default GPE handler if the firmware doesn't

Quoted 2 lines

Firmware may support using GPEs for system wakeup without providing any runtime GPE handlers.

Do you mean by "runtime GPE handlers" to mean the _Lxx/_Exx GPE methods?

If so, this should be clarified in the comments.

Ok. I'm not sure that we'll be pushing this aspect of it yet, we'll have to wait and see what the hardware support situation ends up being.

--
Matthew Garrett | [email protected]

#3 lore raw

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

While I understand the need for the reference counting mechanism, it is a good idea to support the shared GPEs, I think it may be simpler and cleaner to simply not directly expose this mechanism to GPE users.

Well, it already is exposed to the users and in a way that doesn't look very clean to me. Namely, to enable a wakeup GPE for run time, the caller needs to set its type to ACPI_GPE_TYPE_WAKE_RUN before calling acpi_enable_gpe(), while with the Matthew's interface the only thing the caller would need to do would be calling acpi_ref_runtime_gpe().

Quoted 4 lines

I'm suggesting that we add the reference counting mechanism to the existing AcpiEnableGpe and AcpiDisableGpe interfaces and update their descriptions. We already hide the differences between wake, run, and wake-run GPEs behind these interfaces.

Not really, as I said above.

Moreover, we need two reference counters, because there are cases when a GPE should be enabled for wakeup and not enabled for run time and vice versa.

Quoted 6 lines

Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first call.
AcpiDisableGpe: For a given GPE, it is actually disabled only on the last call.

I suppose you mean acpi_enable_gpe() and acpi_disable_gpe().

That wouldn't work, because sometimes we need to actually hardware-disable GPEs and hardware-enable them regardless of the refcount mechanism, like for example in the EC suspend and resume routines.

That said, if you are afraid that the new interface may be cumbersome for the callers, I think we can introduce just two callbacks,

acpi_get_gpe()
acpi_put_gpe()

taking 3 arguments each, where the two first arguments are like for the Matthew's callbacks and the third argument is a mask of two bits:

ACPI_GPE_TYPE_WAKE
ACPI_GPE_TYPE_RUNTIME

that will tell the callback whether to use the wakeup or runtime counter for reference counting (if called with ACPI_GPE_TYPE_WAKE_RUN, both reference counters will be modified at the same time).

Please tell me what you think.

Rafael

#4 lore raw

cover Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

Quoted 56 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

While I understand the need for the reference counting mechanism, it is a good idea to support the shared GPEs, I think it may be simpler and cleaner to simply not directly expose this mechanism to GPE users.

Well, it already is exposed to the users and in a way that doesn't look very clean to me. Namely, to enable a wakeup GPE for run time, the caller needs to set its type to ACPI_GPE_TYPE_WAKE_RUN before calling acpi_enable_gpe(), while with the Matthew's interface the only thing the caller would need to do would be calling acpi_ref_runtime_gpe().

Quoted 4 lines

I'm suggesting that we add the reference counting mechanism to the existing AcpiEnableGpe and AcpiDisableGpe interfaces and update their descriptions. We already hide the differences between wake, run, and wake-run GPEs behind these interfaces.

Not really, as I said above.

Moreover, we need two reference counters, because there are cases when a GPE should be enabled for wakeup and not enabled for run time and vice versa.

Quoted 6 lines

Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first call.
AcpiDisableGpe: For a given GPE, it is actually disabled only on the last call.

I suppose you mean acpi_enable_gpe() and acpi_disable_gpe().

That wouldn't work, because sometimes we need to actually hardware-disable GPEs and hardware-enable them regardless of the refcount mechanism, like for example in the EC suspend and resume routines.

That said, if you are afraid that the new interface may be cumbersome for the callers, I think we can introduce just two callbacks,

acpi_get_gpe()
acpi_put_gpe()

taking 3 arguments each, where the two first arguments are like for the Matthew's callbacks and the third argument is a mask of two bits:

Quoted 8 lines

ACPI_GPE_TYPE_WAKE
ACPI_GPE_TYPE_RUNTIME

that will tell the callback whether to use the wakeup or runtime counter for reference counting (if called with ACPI_GPE_TYPE_WAKE_RUN, both reference counters will be modified at the same time).

Please tell me what you think.

For easier reference, I reworked the Matthew's patches to implement the above idea.

The patches follow, comments welcome.

Rafael

#5 lore raw

RFC PATCH 1/3 ACPI: Add infrastructure for refcounting GPE consumers

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

ACPI GPEs may map to multiple devices. The current GPE interface only provides a mechanism for enabling and disabling GPEs, making it difficult to change the state of GPEs at runtime without extensive cooperation between devices. Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

Based on a patch from Matthew Garrett <[email protected]>.

---
drivers/acpi/acpica/aclocal.h | 2 +

 drivers/acpi/acpica/aclocal.h  |    2 
 drivers/acpi/acpica/evxfevnt.c |   97 +++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpixf.h          |    4 +
 3 files changed, 103 insertions(+)
drivers/acpi/acpica/aclocal.h +2 -0
Index: linux-2.6/drivers/acpi/acpica/aclocal.h
===================================================================
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {
 	struct acpi_gpe_register_info *register_info;	/* Backpointer to register info */
 	u8 flags;		/* Misc info about this GPE */
 	u8 gpe_number;		/* This GPE */
+	u8 runtime_count;
+	u8 wakeup_count;
 };
 
 /* Information about a GPE register pair, one per each status/enable pair in an array */
drivers/acpi/acpica/evxfevnt.c +97 -0

103 lines not on this page · raw message

include/acpi/acpixf.h +4 -0
Index: linux-2.6/include/acpi/acpixf.h
===================================================================
@@ -283,6 +283,10 @@ acpi_status acpi_get_event_status(u32 ev
  */
 acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type);
 
+acpi_status acpi_get_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+
+acpi_status acpi_put_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+
 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number);
 
 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
#6 lore raw

RFC PATCH 2/3 ACPI: Modify GPE consumers to use GPE refcounting

In reply to Rafael J. Wysocki

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

Add GPE refcounting support to the existing GPE users. This will currently do little until the core is changed over to use the new behaviour.

Based on a patch from Matthew Garrett <[email protected]>.

---
drivers/acpi/button.c | 12 ++++++++++++

 drivers/acpi/button.c |   10 ++++++++++
 drivers/acpi/ec.c     |    4 +++-
 drivers/acpi/wakeup.c |   10 ++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
drivers/acpi/button.c +10 -0
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -427,6 +427,9 @@ static int acpi_button_add(struct acpi_d
 				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(device->wakeup.gpe_device,
 				device->wakeup.gpe_number);
+		acpi_get_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
 		device->wakeup.state.enabled = 1;
 	}
 
@@ -446,6 +449,13 @@ static int acpi_button_remove(struct acp
 {
 	struct acpi_button *button = acpi_driver_data(device);
 
+	if (device->wakeup.flags.valid) {
+		acpi_put_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
+		device->wakeup.state.enabled = 0;
+	}
+
 	acpi_button_remove_fs(device);
 	input_unregister_device(button->input);
 	kfree(button);
drivers/acpi/ec.c +3 -1
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -789,7 +789,7 @@ static int ec_install_handlers(struct ac
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
-	acpi_enable_gpe(NULL, ec->gpe);
+	acpi_get_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
 						    &acpi_ec_space_handler,
@@ -806,6 +806,7 @@ static int ec_install_handlers(struct ac
 		} else {
 			acpi_remove_gpe_handler(NULL, ec->gpe,
 				&acpi_ec_gpe_handler);
+			acpi_put_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 			return -ENODEV;
 		}
 	}
@@ -816,6 +817,7 @@ static int ec_install_handlers(struct ac
 
 static void ec_remove_handlers(struct acpi_ec *ec)
 {
+	acpi_put_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
 				ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
 		pr_err(PREFIX "failed to remove space handler\n");
drivers/acpi/wakeup.c +10 -0
Index: linux-2.6/drivers/acpi/wakeup.c
===================================================================
@@ -78,9 +78,15 @@ void acpi_enable_wakeup_device(u8 sleep_
 			}
 			continue;
 		}
+		/*
+		 * If the device is run_wake, the GPE is supposed to be enabled,
+		 * so we don't need to enable it once again.
+		 */
 		if (!dev->wakeup.flags.run_wake)
 			acpi_enable_gpe(dev->wakeup.gpe_device,
 					dev->wakeup.gpe_number);
+		acpi_get_gpe(dev->wakeup.gpe_device,
+				dev->wakeup.gpe_number, ACPI_GPE_TYPE_WAKE);
 	}
 }
 
@@ -121,6 +127,8 @@ void acpi_disable_wakeup_device(u8 sleep
 			acpi_clear_gpe(dev->wakeup.gpe_device,
 				       dev->wakeup.gpe_number, ACPI_NOT_ISR);
 		}
+		acpi_put_gpe(dev->wakeup.gpe_device,
+				dev->wakeup.gpe_number, ACPI_GPE_TYPE_WAKE);
 	}
 }
 
@@ -141,6 +149,8 @@ int __init acpi_wakeup_device_init(void)
 				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(dev->wakeup.gpe_device,
 				dev->wakeup.gpe_number);
+		acpi_get_gpe(dev->wakeup.gpe_device,
+				dev->wakeup.gpe_number, ACPI_GPE_TYPE_WAKE);
 		dev->wakeup.state.enabled = 1;
 	}
 	mutex_unlock(&acpi_device_lock);
#7 lore raw

RFC PATCH 3/3 ACPI: Remove old GPE API and transition code entirely to new one

In reply to Rafael J. Wysocki

From: Matthew Garrett <[email protected]>

Remove the old GPE type handling entirely, which gets rid of various quirks, like the implicit disabling with GPE type setting. This requires a small amount of rework in order to ensure that non-wake GPEs are enabled by default to preserve existing behaviour.

[rjw: Rework the patch to use acpi_get_gpe() and acpi_put_gpe().]

---
 drivers/acpi/acpica/acevents.h |    6 -
 drivers/acpi/acpica/evgpe.c    |  153 ++++-------------------------------------
 drivers/acpi/acpica/evgpeblk.c |   69 +++++-------------
 drivers/acpi/acpica/evxface.c  |   14 ---
 drivers/acpi/acpica/evxfevnt.c |   48 ------------
 drivers/acpi/button.c          |    5 -
 drivers/acpi/ec.c              |    2 
 drivers/acpi/wakeup.c          |   55 ++------------
 include/acpi/actypes.h         |   28 ++-----
 9 files changed, 59 insertions(+), 321 deletions(-)
drivers/acpi/acpica/acevents.h +1 -5
Index: linux-2.6/drivers/acpi/acpica/acevents.h
===================================================================
@@ -76,8 +76,7 @@ acpi_ev_queue_notify_request(struct acpi
  * evgpe - GPE handling and dispatch
  */
 acpi_status
-acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
-				u8 type);
+acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status
 acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
@@ -122,9 +121,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_eve
 u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
 
 acpi_status
-acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type);
-
-acpi_status
 acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status acpi_ev_gpe_initialize(void);
drivers/acpi/acpica/evgpe.c +16 -137

196 lines not on this page · raw message

drivers/acpi/acpica/evgpeblk.c +20 -49

121 lines not on this page · raw message

drivers/acpi/acpica/evxface.c +0 -14
Index: linux-2.6/drivers/acpi/acpica/evxface.c
===================================================================
@@ -617,13 +617,6 @@ acpi_install_gpe_handler(acpi_handle gpe
 	handler->context = context;
 	handler->method_node = gpe_event_info->dispatch.method_node;
 
-	/* Disable the GPE before installing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Install the handler */
 
 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
@@ -707,13 +700,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_
 		goto unlock_and_exit;
 	}
 
-	/* Disable the GPE before removing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Make sure all deferred tasks are completed */
 
 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
drivers/acpi/acpica/evxfevnt.c +2 -46

66 lines not on this page · raw message

drivers/acpi/button.c +0 -5
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -422,11 +422,6 @@ static int acpi_button_add(struct acpi_d
 
 	if (device->wakeup.flags.valid) {
 		/* Button's GPE is run-wake GPE */
-		acpi_set_gpe_type(device->wakeup.gpe_device,
-				  device->wakeup.gpe_number,
-				  ACPI_GPE_TYPE_WAKE_RUN);
-		acpi_enable_gpe(device->wakeup.gpe_device,
-				device->wakeup.gpe_number);
 		acpi_get_gpe(device->wakeup.gpe_device,
 				device->wakeup.gpe_number,
 				ACPI_GPE_TYPE_WAKE_RUN);
drivers/acpi/ec.c +1 -1
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -788,7 +788,7 @@ static int ec_install_handlers(struct ac
 				  &acpi_ec_gpe_handler, ec);
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
-	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
+
 	acpi_get_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
drivers/acpi/wakeup.c +9 -46

81 lines not on this page · raw message

include/acpi/actypes.h +10 -18
Index: linux-2.6/include/acpi/actypes.h
===================================================================
@@ -668,15 +668,16 @@ typedef u32 acpi_event_status;
 
 /*
  * GPE info flags - Per GPE
- * +-+-+-+---+---+-+
- * |7|6|5|4:3|2:1|0|
- * +-+-+-+---+---+-+
- *  | | |  |   |  |
- *  | | |  |   |  +--- Interrupt type: Edge or Level Triggered
- *  | | |  |   +--- Type: Wake-only, Runtime-only, or wake/runtime
+ * +-+-+-+---+-+-+-+
+ * |7|6|5|4:3|2|1|0|
+ * +-+-+-+---+-+-+-+
+ *  | | |  |  | | |
+ *  | | |  |  | | +--- Interrupt type: Edge or Level Triggered
+ *  | | |  |  | +--- GPE can wake the system
+ *  | | |  |  +--- Unused
  *  | | |  +--- Type of dispatch -- to method, handler, or none
- *  | | +--- Enabled for runtime?
- *  | +--- Enabled for wake?
+ *  | | +--- Unused
+ *  | +--- Unused
  *  +--- Unused
  */
 #define ACPI_GPE_XRUPT_TYPE_MASK        (u8) 0x01
@@ -687,22 +688,13 @@ typedef u32 acpi_event_status;
 #define ACPI_GPE_TYPE_WAKE_RUN          (u8) 0x06
 #define ACPI_GPE_TYPE_WAKE              (u8) 0x02
 #define ACPI_GPE_TYPE_RUNTIME           (u8) 0x04	/* Default */
+#define ACPI_GPE_CAN_WAKE		(u8) 0x02
 
 #define ACPI_GPE_DISPATCH_MASK          (u8) 0x18
 #define ACPI_GPE_DISPATCH_HANDLER       (u8) 0x08
 #define ACPI_GPE_DISPATCH_METHOD        (u8) 0x10
 #define ACPI_GPE_DISPATCH_NOT_USED      (u8) 0x00	/* Default */
 
-#define ACPI_GPE_RUN_ENABLE_MASK        (u8) 0x20
-#define ACPI_GPE_RUN_ENABLED            (u8) 0x20
-#define ACPI_GPE_RUN_DISABLED           (u8) 0x00	/* Default */
-
-#define ACPI_GPE_WAKE_ENABLE_MASK       (u8) 0x40
-#define ACPI_GPE_WAKE_ENABLED           (u8) 0x40
-#define ACPI_GPE_WAKE_DISABLED          (u8) 0x00	/* Default */
-
-#define ACPI_GPE_ENABLE_MASK            (u8) 0x60	/* Both run/wake */
-
 /*
  * Flags for GPE and Lock interfaces
  */
#8 lore raw

[Update] Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

In reply to Rafael J. Wysocki
Quoted 60 lines · Rafael J. Wysocki
Quoted 59 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

While I understand the need for the reference counting mechanism, it is a good idea to support the shared GPEs, I think it may be simpler and cleaner to simply not directly expose this mechanism to GPE users.

Well, it already is exposed to the users and in a way that doesn't look very clean to me. Namely, to enable a wakeup GPE for run time, the caller needs to set its type to ACPI_GPE_TYPE_WAKE_RUN before calling acpi_enable_gpe(), while with the Matthew's interface the only thing the caller would need to do would be calling acpi_ref_runtime_gpe().

Quoted 4 lines

I'm suggesting that we add the reference counting mechanism to the existing AcpiEnableGpe and AcpiDisableGpe interfaces and update their descriptions. We already hide the differences between wake, run, and wake-run GPEs behind these interfaces.

Not really, as I said above.

Moreover, we need two reference counters, because there are cases when a GPE should be enabled for wakeup and not enabled for run time and vice versa.

Quoted 6 lines

Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first call.
AcpiDisableGpe: For a given GPE, it is actually disabled only on the last call.

I suppose you mean acpi_enable_gpe() and acpi_disable_gpe().

That wouldn't work, because sometimes we need to actually hardware-disable GPEs and hardware-enable them regardless of the refcount mechanism, like for example in the EC suspend and resume routines.

That said, if you are afraid that the new interface may be cumbersome for the callers, I think we can introduce just two callbacks,

acpi_get_gpe()
acpi_put_gpe()

taking 3 arguments each, where the two first arguments are like for the Matthew's callbacks and the third argument is a mask of two bits:

ACPI_GPE_TYPE_WAKE
ACPI_GPE_TYPE_RUNTIME

Quoted 8 lines
Quoted 5 lines

that will tell the callback whether to use the wakeup or runtime counter for reference counting (if called with ACPI_GPE_TYPE_WAKE_RUN, both reference counters will be modified at the same time).

Please tell me what you think.

For easier reference, I reworked the Matthew's patches to implement the above idea.

I noticed that patch [2/3] was actually wrong, because it added the GPE refcounting to drivers/acpi/wakeup.c:acpi_[enable|disable]_wakeup_device(), while in fact it should have added it to drivers/acpi/sleep.c:acpi_pm_device_sleep_wake().

Moreover, patch [3/3] did not really enable the wakeup GPEs after they had been disabled by acpi_disable_all_gpes().

I fixed the two patches and added explanatory comments to patch [1/3].

Updated patches follow, comments welcome.

Rafael

#9 lore raw

[Update] Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

In reply to Rafael J. Wysocki
Quoted 60 lines · Rafael J. Wysocki
Quoted 59 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

While I understand the need for the reference counting mechanism, it is a good idea to support the shared GPEs, I think it may be simpler and cleaner to simply not directly expose this mechanism to GPE users.

Well, it already is exposed to the users and in a way that doesn't look very clean to me. Namely, to enable a wakeup GPE for run time, the caller needs to set its type to ACPI_GPE_TYPE_WAKE_RUN before calling acpi_enable_gpe(), while with the Matthew's interface the only thing the caller would need to do would be calling acpi_ref_runtime_gpe().

Quoted 4 lines

I'm suggesting that we add the reference counting mechanism to the existing AcpiEnableGpe and AcpiDisableGpe interfaces and update their descriptions. We already hide the differences between wake, run, and wake-run GPEs behind these interfaces.

Not really, as I said above.

Moreover, we need two reference counters, because there are cases when a GPE should be enabled for wakeup and not enabled for run time and vice versa.

Quoted 6 lines

Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first call.
AcpiDisableGpe: For a given GPE, it is actually disabled only on the last call.

I suppose you mean acpi_enable_gpe() and acpi_disable_gpe().

That wouldn't work, because sometimes we need to actually hardware-disable GPEs and hardware-enable them regardless of the refcount mechanism, like for example in the EC suspend and resume routines.

That said, if you are afraid that the new interface may be cumbersome for the callers, I think we can introduce just two callbacks,

acpi_get_gpe()
acpi_put_gpe()

taking 3 arguments each, where the two first arguments are like for the Matthew's callbacks and the third argument is a mask of two bits:

ACPI_GPE_TYPE_WAKE
ACPI_GPE_TYPE_RUNTIME

Quoted 8 lines
Quoted 5 lines

that will tell the callback whether to use the wakeup or runtime counter for reference counting (if called with ACPI_GPE_TYPE_WAKE_RUN, both reference counters will be modified at the same time).

Please tell me what you think.

For easier reference, I reworked the Matthew's patches to implement the above idea.

I noticed that patch [2/3] was actually wrong, because it added the GPE refcounting to drivers/acpi/wakeup.c:acpi_[enable|disable]_wakeup_device(), while in fact it should have added it to drivers/acpi/sleep.c:acpi_pm_device_sleep_wake().

Moreover, patch [3/3] did not really enable the wakeup GPEs after they had been disabled by acpi_disable_all_gpes().

I fixed the two patches and added explanatory comments to patch [1/3].

Updated patches follow, comments welcome.

Rafael

#10 lore raw

RFC PATCH 1/3 ACPI: Add infrastructure for refcounting GPE consumers

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

ACPI GPEs may map to multiple devices. The current GPE interface only provides a mechanism for enabling and disabling GPEs, making it difficult to change the state of GPEs at runtime without extensive cooperation between devices. Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

Based on a patch from Matthew Garrett <[email protected]>.

---
drivers/acpi/acpica/aclocal.h | 2 +

 drivers/acpi/acpica/aclocal.h  |    2 
 drivers/acpi/acpica/evxfevnt.c |  105 +++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpixf.h          |    4 +
 3 files changed, 111 insertions(+)
drivers/acpi/acpica/aclocal.h +2 -0
Index: linux-2.6/drivers/acpi/acpica/aclocal.h
===================================================================
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {
 	struct acpi_gpe_register_info *register_info;	/* Backpointer to register info */
 	u8 flags;		/* Misc info about this GPE */
 	u8 gpe_number;		/* This GPE */
+	u8 runtime_count;
+	u8 wakeup_count;
 };
 
 /* Information about a GPE register pair, one per each status/enable pair in an array */
drivers/acpi/acpica/evxfevnt.c +105 -0

111 lines not on this page · raw message

include/acpi/acpixf.h +4 -0
Index: linux-2.6/include/acpi/acpixf.h
===================================================================
@@ -283,6 +283,10 @@ acpi_status acpi_get_event_status(u32 ev
  */
 acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type);
 
+acpi_status acpi_get_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+
+acpi_status acpi_put_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+
 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number);
 
 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
#11 lore raw

RFC PATCH 1/3 ACPI: Add infrastructure for refcounting GPE consumers

In reply to Rafael J. Wysocki

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

ACPI GPEs may map to multiple devices. The current GPE interface only provides a mechanism for enabling and disabling GPEs, making it difficult to change the state of GPEs at runtime without extensive cooperation between devices. Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

Based on a patch from Matthew Garrett <[email protected]>.

---
drivers/acpi/acpica/aclocal.h | 2 +

 drivers/acpi/acpica/aclocal.h  |    2 
 drivers/acpi/acpica/evxfevnt.c |  105 +++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpixf.h          |    4 +
 3 files changed, 111 insertions(+)
drivers/acpi/acpica/aclocal.h +2 -0
Index: linux-2.6/drivers/acpi/acpica/aclocal.h
===================================================================
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {
 	struct acpi_gpe_register_info *register_info;	/* Backpointer to register info */
 	u8 flags;		/* Misc info about this GPE */
 	u8 gpe_number;		/* This GPE */
+	u8 runtime_count;
+	u8 wakeup_count;
 };
 
 /* Information about a GPE register pair, one per each status/enable pair in an array */
drivers/acpi/acpica/evxfevnt.c +105 -0

111 lines not on this page · raw message

include/acpi/acpixf.h +4 -0
Index: linux-2.6/include/acpi/acpixf.h
===================================================================
@@ -283,6 +283,10 @@ acpi_status acpi_get_event_status(u32 ev
  */
 acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type);
 
+acpi_status acpi_get_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+
+acpi_status acpi_put_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+
 acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number);
 
 acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
#12 lore raw

RFC PATCH 2/3 ACPI: Modify GPE consumers to use GPE refcounting

In reply to Rafael J. Wysocki

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

Add GPE refcounting support to the existing GPE users. This will currently do little until the core is changed over to fully implement the new behaviour.

Based on a patch from Matthew Garrett <[email protected]>.

---
 drivers/acpi/button.c |   10 ++++++++++
 drivers/acpi/ec.c     |    4 +++-
 drivers/acpi/sleep.c  |   15 ++++++++++++---
 drivers/acpi/wakeup.c |    2 ++
 4 files changed, 27 insertions(+), 4 deletions(-)
drivers/acpi/button.c +10 -0
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -427,6 +427,9 @@ static int acpi_button_add(struct acpi_d
 				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(device->wakeup.gpe_device,
 				device->wakeup.gpe_number);
+		acpi_get_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
 		device->wakeup.state.enabled = 1;
 	}
 
@@ -446,6 +449,13 @@ static int acpi_button_remove(struct acp
 {
 	struct acpi_button *button = acpi_driver_data(device);
 
+	if (device->wakeup.flags.valid) {
+		acpi_put_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
+		device->wakeup.state.enabled = 0;
+	}
+
 	acpi_button_remove_fs(device);
 	input_unregister_device(button->input);
 	kfree(button);
drivers/acpi/ec.c +3 -1
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -789,7 +789,7 @@ static int ec_install_handlers(struct ac
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
-	acpi_enable_gpe(NULL, ec->gpe);
+	acpi_get_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
 						    &acpi_ec_space_handler,
@@ -806,6 +806,7 @@ static int ec_install_handlers(struct ac
 		} else {
 			acpi_remove_gpe_handler(NULL, ec->gpe,
 				&acpi_ec_gpe_handler);
+			acpi_put_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 			return -ENODEV;
 		}
 	}
@@ -816,6 +817,7 @@ static int ec_install_handlers(struct ac
 
 static void ec_remove_handlers(struct acpi_ec *ec)
 {
+	acpi_put_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
 				ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
 		pr_err(PREFIX "failed to remove space handler\n");
drivers/acpi/sleep.c +12 -3
Index: linux-2.6/drivers/acpi/sleep.c
===================================================================
@@ -745,9 +745,18 @@ int acpi_pm_device_sleep_wake(struct dev
 		return -ENODEV;
 	}
 
-	error = enable ?
-		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
-		acpi_disable_wakeup_device_power(adev);
+	if (enable) {
+		error = acpi_enable_wakeup_device_power(adev,
+						acpi_target_sleep_state);
+		if (!error)
+			acpi_get_gpe(adev->wakeup.gpe_device,
+					adev->wakeup.gpe_number,
+					ACPI_GPE_TYPE_WAKE);
+	} else {
+		acpi_put_gpe(adev->wakeup.gpe_device, adev->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE);
+		error = acpi_disable_wakeup_device_power(adev);
+	}
 	if (!error)
 		dev_info(dev, "wake-up capability %s by ACPI\n",
 				enable ? "enabled" : "disabled");
drivers/acpi/wakeup.c +2 -0
Index: linux-2.6/drivers/acpi/wakeup.c
===================================================================
@@ -141,6 +141,8 @@ int __init acpi_wakeup_device_init(void)
 				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(dev->wakeup.gpe_device,
 				dev->wakeup.gpe_number);
+ 		acpi_get_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
+ 				ACPI_GPE_TYPE_WAKE);
 		dev->wakeup.state.enabled = 1;
 	}
 	mutex_unlock(&acpi_device_lock);
#13 lore raw

RFC PATCH 2/3 ACPI: Modify GPE consumers to use GPE refcounting

In reply to Rafael J. Wysocki

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

Add GPE refcounting support to the existing GPE users. This will currently do little until the core is changed over to fully implement the new behaviour.

Based on a patch from Matthew Garrett <[email protected]>.

---
 drivers/acpi/button.c |   10 ++++++++++
 drivers/acpi/ec.c     |    4 +++-
 drivers/acpi/sleep.c  |   15 ++++++++++++---
 drivers/acpi/wakeup.c |    2 ++
 4 files changed, 27 insertions(+), 4 deletions(-)
drivers/acpi/button.c +10 -0
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -427,6 +427,9 @@ static int acpi_button_add(struct acpi_d
 				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(device->wakeup.gpe_device,
 				device->wakeup.gpe_number);
+		acpi_get_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
 		device->wakeup.state.enabled = 1;
 	}
 
@@ -446,6 +449,13 @@ static int acpi_button_remove(struct acp
 {
 	struct acpi_button *button = acpi_driver_data(device);
 
+	if (device->wakeup.flags.valid) {
+		acpi_put_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
+		device->wakeup.state.enabled = 0;
+	}
+
 	acpi_button_remove_fs(device);
 	input_unregister_device(button->input);
 	kfree(button);
drivers/acpi/ec.c +3 -1
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -789,7 +789,7 @@ static int ec_install_handlers(struct ac
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
-	acpi_enable_gpe(NULL, ec->gpe);
+	acpi_get_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
 						    &acpi_ec_space_handler,
@@ -806,6 +806,7 @@ static int ec_install_handlers(struct ac
 		} else {
 			acpi_remove_gpe_handler(NULL, ec->gpe,
 				&acpi_ec_gpe_handler);
+			acpi_put_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 			return -ENODEV;
 		}
 	}
@@ -816,6 +817,7 @@ static int ec_install_handlers(struct ac
 
 static void ec_remove_handlers(struct acpi_ec *ec)
 {
+	acpi_put_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
 				ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
 		pr_err(PREFIX "failed to remove space handler\n");
drivers/acpi/sleep.c +12 -3
Index: linux-2.6/drivers/acpi/sleep.c
===================================================================
@@ -745,9 +745,18 @@ int acpi_pm_device_sleep_wake(struct dev
 		return -ENODEV;
 	}
 
-	error = enable ?
-		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
-		acpi_disable_wakeup_device_power(adev);
+	if (enable) {
+		error = acpi_enable_wakeup_device_power(adev,
+						acpi_target_sleep_state);
+		if (!error)
+			acpi_get_gpe(adev->wakeup.gpe_device,
+					adev->wakeup.gpe_number,
+					ACPI_GPE_TYPE_WAKE);
+	} else {
+		acpi_put_gpe(adev->wakeup.gpe_device, adev->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE);
+		error = acpi_disable_wakeup_device_power(adev);
+	}
 	if (!error)
 		dev_info(dev, "wake-up capability %s by ACPI\n",
 				enable ? "enabled" : "disabled");
drivers/acpi/wakeup.c +2 -0
Index: linux-2.6/drivers/acpi/wakeup.c
===================================================================
@@ -141,6 +141,8 @@ int __init acpi_wakeup_device_init(void)
 				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(dev->wakeup.gpe_device,
 				dev->wakeup.gpe_number);
+ 		acpi_get_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
+ 				ACPI_GPE_TYPE_WAKE);
 		dev->wakeup.state.enabled = 1;
 	}
 	mutex_unlock(&acpi_device_lock);
#14 lore raw

RFC PATCH 3/3 ACPI: Remove old GPE API and transition code entirely to new one

In reply to Rafael J. Wysocki

From: Matthew Garrett <[email protected]>

Remove the old GPE type handling entirely, which gets rid of various quirks, like the implicit disabling with GPE type setting. This requires a small amount of rework in order to ensure that non-wake GPEs are enabled by default to preserve existing behaviour.

[rjw: Reworked the patch to use acpi_get_gpe() and acpi_put_gpe() and
fixed the changes in drivers/acpi/wakeup.c]

---
 drivers/acpi/acpica/acevents.h |    6 -
 drivers/acpi/acpica/evgpe.c    |  153 ++++-------------------------------------
 drivers/acpi/acpica/evgpeblk.c |   69 +++++-------------
 drivers/acpi/acpica/evxface.c  |   14 ---
 drivers/acpi/acpica/evxfevnt.c |   48 ------------
 drivers/acpi/button.c          |    5 -
 drivers/acpi/ec.c              |    2 
 drivers/acpi/wakeup.c          |   78 ++++++--------------
 include/acpi/actypes.h         |   28 ++-----
 9 files changed, 74 insertions(+), 329 deletions(-)
drivers/acpi/acpica/acevents.h +1 -5
Index: linux-2.6/drivers/acpi/acpica/acevents.h
===================================================================
@@ -76,8 +76,7 @@ acpi_ev_queue_notify_request(struct acpi
  * evgpe - GPE handling and dispatch
  */
 acpi_status
-acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
-				u8 type);
+acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status
 acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
@@ -122,9 +121,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_eve
 u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
 
 acpi_status
-acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type);
-
-acpi_status
 acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status acpi_ev_gpe_initialize(void);
drivers/acpi/acpica/evgpe.c +16 -137

196 lines not on this page · raw message

drivers/acpi/acpica/evgpeblk.c +20 -49

121 lines not on this page · raw message

drivers/acpi/acpica/evxface.c +0 -14
Index: linux-2.6/drivers/acpi/acpica/evxface.c
===================================================================
@@ -617,13 +617,6 @@ acpi_install_gpe_handler(acpi_handle gpe
 	handler->context = context;
 	handler->method_node = gpe_event_info->dispatch.method_node;
 
-	/* Disable the GPE before installing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Install the handler */
 
 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
@@ -707,13 +700,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_
 		goto unlock_and_exit;
 	}
 
-	/* Disable the GPE before removing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Make sure all deferred tasks are completed */
 
 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
drivers/acpi/acpica/evxfevnt.c +2 -46

66 lines not on this page · raw message

drivers/acpi/button.c +0 -5
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -422,11 +422,6 @@ static int acpi_button_add(struct acpi_d
 
 	if (device->wakeup.flags.valid) {
 		/* Button's GPE is run-wake GPE */
-		acpi_set_gpe_type(device->wakeup.gpe_device,
-				  device->wakeup.gpe_number,
-				  ACPI_GPE_TYPE_WAKE_RUN);
-		acpi_enable_gpe(device->wakeup.gpe_device,
-				device->wakeup.gpe_number);
 		acpi_get_gpe(device->wakeup.gpe_device,
 				device->wakeup.gpe_number,
 				ACPI_GPE_TYPE_WAKE_RUN);
drivers/acpi/ec.c +1 -1
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -788,7 +788,7 @@ static int ec_install_handlers(struct ac
 				  &acpi_ec_gpe_handler, ec);
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
-	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
+
 	acpi_get_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
drivers/acpi/wakeup.c +24 -54

124 lines not on this page · raw message

include/acpi/actypes.h +10 -18
Index: linux-2.6/include/acpi/actypes.h
===================================================================
@@ -668,15 +668,16 @@ typedef u32 acpi_event_status;
 
 /*
  * GPE info flags - Per GPE
- * +-+-+-+---+---+-+
- * |7|6|5|4:3|2:1|0|
- * +-+-+-+---+---+-+
- *  | | |  |   |  |
- *  | | |  |   |  +--- Interrupt type: Edge or Level Triggered
- *  | | |  |   +--- Type: Wake-only, Runtime-only, or wake/runtime
+ * +-+-+-+---+-+-+-+
+ * |7|6|5|4:3|2|1|0|
+ * +-+-+-+---+-+-+-+
+ *  | | |  |  | | |
+ *  | | |  |  | | +--- Interrupt type: Edge or Level Triggered
+ *  | | |  |  | +--- GPE can wake the system
+ *  | | |  |  +--- Unused
  *  | | |  +--- Type of dispatch -- to method, handler, or none
- *  | | +--- Enabled for runtime?
- *  | +--- Enabled for wake?
+ *  | | +--- Unused
+ *  | +--- Unused
  *  +--- Unused
  */
 #define ACPI_GPE_XRUPT_TYPE_MASK        (u8) 0x01
@@ -687,22 +688,13 @@ typedef u32 acpi_event_status;
 #define ACPI_GPE_TYPE_WAKE_RUN          (u8) 0x06
 #define ACPI_GPE_TYPE_WAKE              (u8) 0x02
 #define ACPI_GPE_TYPE_RUNTIME           (u8) 0x04	/* Default */
+#define ACPI_GPE_CAN_WAKE		(u8) 0x02
 
 #define ACPI_GPE_DISPATCH_MASK          (u8) 0x18
 #define ACPI_GPE_DISPATCH_HANDLER       (u8) 0x08
 #define ACPI_GPE_DISPATCH_METHOD        (u8) 0x10
 #define ACPI_GPE_DISPATCH_NOT_USED      (u8) 0x00	/* Default */
 
-#define ACPI_GPE_RUN_ENABLE_MASK        (u8) 0x20
-#define ACPI_GPE_RUN_ENABLED            (u8) 0x20
-#define ACPI_GPE_RUN_DISABLED           (u8) 0x00	/* Default */
-
-#define ACPI_GPE_WAKE_ENABLE_MASK       (u8) 0x40
-#define ACPI_GPE_WAKE_ENABLED           (u8) 0x40
-#define ACPI_GPE_WAKE_DISABLED          (u8) 0x00	/* Default */
-
-#define ACPI_GPE_ENABLE_MASK            (u8) 0x60	/* Both run/wake */
-
 /*
  * Flags for GPE and Lock interfaces
  */
#15 lore raw

RFC PATCH 3/3 ACPI: Remove old GPE API and transition code entirely to new one

In reply to Rafael J. Wysocki

From: Matthew Garrett <[email protected]>

Remove the old GPE type handling entirely, which gets rid of various quirks, like the implicit disabling with GPE type setting. This requires a small amount of rework in order to ensure that non-wake GPEs are enabled by default to preserve existing behaviour.

[rjw: Reworked the patch to use acpi_get_gpe() and acpi_put_gpe() and
fixed the changes in drivers/acpi/wakeup.c]

---
 drivers/acpi/acpica/acevents.h |    6 -
 drivers/acpi/acpica/evgpe.c    |  153 ++++-------------------------------------
 drivers/acpi/acpica/evgpeblk.c |   69 +++++-------------
 drivers/acpi/acpica/evxface.c  |   14 ---
 drivers/acpi/acpica/evxfevnt.c |   48 ------------
 drivers/acpi/button.c          |    5 -
 drivers/acpi/ec.c              |    2 
 drivers/acpi/wakeup.c          |   78 ++++++--------------
 include/acpi/actypes.h         |   28 ++-----
 9 files changed, 74 insertions(+), 329 deletions(-)
drivers/acpi/acpica/acevents.h +1 -5
Index: linux-2.6/drivers/acpi/acpica/acevents.h
===================================================================
@@ -76,8 +76,7 @@ acpi_ev_queue_notify_request(struct acpi
  * evgpe - GPE handling and dispatch
  */
 acpi_status
-acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
-				u8 type);
+acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status
 acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
@@ -122,9 +121,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_eve
 u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
 
 acpi_status
-acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type);
-
-acpi_status
 acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status acpi_ev_gpe_initialize(void);
drivers/acpi/acpica/evgpe.c +16 -137

196 lines not on this page · raw message

drivers/acpi/acpica/evgpeblk.c +20 -49

121 lines not on this page · raw message

drivers/acpi/acpica/evxface.c +0 -14
Index: linux-2.6/drivers/acpi/acpica/evxface.c
===================================================================
@@ -617,13 +617,6 @@ acpi_install_gpe_handler(acpi_handle gpe
 	handler->context = context;
 	handler->method_node = gpe_event_info->dispatch.method_node;
 
-	/* Disable the GPE before installing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Install the handler */
 
 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
@@ -707,13 +700,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_
 		goto unlock_and_exit;
 	}
 
-	/* Disable the GPE before removing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Make sure all deferred tasks are completed */
 
 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
drivers/acpi/acpica/evxfevnt.c +2 -46

66 lines not on this page · raw message

drivers/acpi/button.c +0 -5
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -422,11 +422,6 @@ static int acpi_button_add(struct acpi_d
 
 	if (device->wakeup.flags.valid) {
 		/* Button's GPE is run-wake GPE */
-		acpi_set_gpe_type(device->wakeup.gpe_device,
-				  device->wakeup.gpe_number,
-				  ACPI_GPE_TYPE_WAKE_RUN);
-		acpi_enable_gpe(device->wakeup.gpe_device,
-				device->wakeup.gpe_number);
 		acpi_get_gpe(device->wakeup.gpe_device,
 				device->wakeup.gpe_number,
 				ACPI_GPE_TYPE_WAKE_RUN);
drivers/acpi/ec.c +1 -1
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -788,7 +788,7 @@ static int ec_install_handlers(struct ac
 				  &acpi_ec_gpe_handler, ec);
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
-	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
+
 	acpi_get_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
drivers/acpi/wakeup.c +24 -54

124 lines not on this page · raw message

include/acpi/actypes.h +10 -18
Index: linux-2.6/include/acpi/actypes.h
===================================================================
@@ -668,15 +668,16 @@ typedef u32 acpi_event_status;
 
 /*
  * GPE info flags - Per GPE
- * +-+-+-+---+---+-+
- * |7|6|5|4:3|2:1|0|
- * +-+-+-+---+---+-+
- *  | | |  |   |  |
- *  | | |  |   |  +--- Interrupt type: Edge or Level Triggered
- *  | | |  |   +--- Type: Wake-only, Runtime-only, or wake/runtime
+ * +-+-+-+---+-+-+-+
+ * |7|6|5|4:3|2|1|0|
+ * +-+-+-+---+-+-+-+
+ *  | | |  |  | | |
+ *  | | |  |  | | +--- Interrupt type: Edge or Level Triggered
+ *  | | |  |  | +--- GPE can wake the system
+ *  | | |  |  +--- Unused
  *  | | |  +--- Type of dispatch -- to method, handler, or none
- *  | | +--- Enabled for runtime?
- *  | +--- Enabled for wake?
+ *  | | +--- Unused
+ *  | +--- Unused
  *  +--- Unused
  */
 #define ACPI_GPE_XRUPT_TYPE_MASK        (u8) 0x01
@@ -687,22 +688,13 @@ typedef u32 acpi_event_status;
 #define ACPI_GPE_TYPE_WAKE_RUN          (u8) 0x06
 #define ACPI_GPE_TYPE_WAKE              (u8) 0x02
 #define ACPI_GPE_TYPE_RUNTIME           (u8) 0x04	/* Default */
+#define ACPI_GPE_CAN_WAKE		(u8) 0x02
 
 #define ACPI_GPE_DISPATCH_MASK          (u8) 0x18
 #define ACPI_GPE_DISPATCH_HANDLER       (u8) 0x08
 #define ACPI_GPE_DISPATCH_METHOD        (u8) 0x10
 #define ACPI_GPE_DISPATCH_NOT_USED      (u8) 0x00	/* Default */
 
-#define ACPI_GPE_RUN_ENABLE_MASK        (u8) 0x20
-#define ACPI_GPE_RUN_ENABLED            (u8) 0x20
-#define ACPI_GPE_RUN_DISABLED           (u8) 0x00	/* Default */
-
-#define ACPI_GPE_WAKE_ENABLE_MASK       (u8) 0x40
-#define ACPI_GPE_WAKE_ENABLED           (u8) 0x40
-#define ACPI_GPE_WAKE_DISABLED          (u8) 0x00	/* Default */
-
-#define ACPI_GPE_ENABLE_MASK            (u8) 0x60	/* Both run/wake */
-
 /*
  * Flags for GPE and Lock interfaces
  */
#16 lore raw

Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki

Hi,

Quoted 4 lines · Robert

Matthew,

Thanks for your response to my questions.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I've been thinking about these interfaces:

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

One minor, mostly off-topic question.
Currently to enable static wakeup one has to write /proc/acpi/wakeup. Do you consider propagating device wakeup settings to acpi, so /proc/acpi/wakeup could finally be deprecated?

Best regards,
Maxim Levitsky

#17 lore raw

Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

Quoted 11 lines · Maxim Levitsky
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

One minor, mostly off-topic question.
Currently to enable static wakeup one has to write /proc/acpi/wakeup.

That depends on the device. For PCI devices there's another interface for that, which is /sys/devices/.../power/wakeup .

Quoted 2 lines

Do you consider propagating device wakeup settings to acpi, so /proc/acpi/wakeup could finally be deprecated?

We already do that for PCI devices.

In fact, I'd only recommend using /proc/acpi/wakeup for reading the list of wakeup devices visible to ACPI.

Rafael

#18 lore raw

Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

Quoted 21 lines · Rafael J. Wysocki
Quoted 11 lines · Maxim Levitsky
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

One minor, mostly off-topic question.
Currently to enable static wakeup one has to write /proc/acpi/wakeup.

Quoted 7 lines

That depends on the device. For PCI devices there's another interface for that, which is /sys/devices/.../power/wakeup .

Quoted 2 lines

Do you consider propagating device wakeup settings to acpi, so /proc/acpi/wakeup could finally be deprecated?

We already do that for PCI devices.

Not in 2.6.33-rc6

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  
maxim@maxim-laptop:~$ echo enabled | sudo tee  /sys/devices/pci0000
\:00/0000\:00\:1d.0/power/wakeup 
enabled

cat /sys/devices/pci0000\:00/0000\:00\:1d.0/power/wakeup enabled

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  

Or am I mistaken somehow?

Best regards,
Maxim Levitsky

#19 lore raw

Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

Quoted 70 lines · Maxim Levitsky
Quoted 21 lines · Rafael J. Wysocki
Quoted 11 lines · Maxim Levitsky
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

One minor, mostly off-topic question.
Currently to enable static wakeup one has to write /proc/acpi/wakeup.

Quoted 7 lines

That depends on the device. For PCI devices there's another interface for that, which is /sys/devices/.../power/wakeup .

Quoted 2 lines

Do you consider propagating device wakeup settings to acpi, so /proc/acpi/wakeup could finally be deprecated?

We already do that for PCI devices.

Not in 2.6.33-rc6

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  
maxim@maxim-laptop:~$ echo enabled | sudo tee  /sys/devices/pci0000
\:00/0000\:00\:1d.0/power/wakeup 
enabled

cat /sys/devices/pci0000\:00/0000\:00\:1d.0/power/wakeup enabled

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  
Quoted 1 line

Or am I mistaken somehow?

You are. Please ignore the "Status" column in /proc/acpi/wakeup, it shows the value of a flag that's not used for PCI devices (unless you set it via /proc/acpi/wakeup).

Rafael

#20 lore raw

Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

Quoted 71 lines · Rafael J. Wysocki
Quoted 70 lines · Maxim Levitsky
Quoted 21 lines · Rafael J. Wysocki
Quoted 11 lines · Maxim Levitsky
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

One minor, mostly off-topic question.
Currently to enable static wakeup one has to write /proc/acpi/wakeup.

Quoted 7 lines

That depends on the device. For PCI devices there's another interface for that, which is /sys/devices/.../power/wakeup .

Quoted 2 lines

Do you consider propagating device wakeup settings to acpi, so /proc/acpi/wakeup could finally be deprecated?

We already do that for PCI devices.

Not in 2.6.33-rc6

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  
maxim@maxim-laptop:~$ echo enabled | sudo tee  /sys/devices/pci0000
\:00/0000\:00\:1d.0/power/wakeup 
enabled

cat /sys/devices/pci0000\:00/0000\:00\:1d.0/power/wakeup enabled

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  
Quoted 5 lines
Quoted 1 line

Or am I mistaken somehow?

You are. Please ignore the "Status" column in /proc/acpi/wakeup, it shows the value of a flag that's not used for PCI devices (unless you set it via /proc/acpi/wakeup

It is indeed true.

PnP device too are supported in this way?

Then I think it would be very nice to remove all pci and pnp devices from this list to avoid confusion.

Best regards,
Maxim Levitsky

#21 lore raw

Re: [RFC][PATCH 0/3] Introduce GPE refcounting (was: Re: Recent GPE patches - some questions.)

Quoted 74 lines · Maxim Levitsky
Quoted 73 lines · Rafael J. Wysocki
Quoted 71 lines · Maxim Levitsky
Quoted 21 lines · Rafael J. Wysocki
Quoted 11 lines · Maxim Levitsky
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

One minor, mostly off-topic question.
Currently to enable static wakeup one has to write /proc/acpi/wakeup.

Quoted 7 lines

That depends on the device. For PCI devices there's another interface for that, which is /sys/devices/.../power/wakeup .

Quoted 2 lines

Do you consider propagating device wakeup settings to acpi, so /proc/acpi/wakeup could finally be deprecated?

We already do that for PCI devices.

Not in 2.6.33-rc6

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  
maxim@maxim-laptop:~$ echo enabled | sudo tee  /sys/devices/pci0000
\:00/0000\:00\:1d.0/power/wakeup 
enabled

cat /sys/devices/pci0000\:00/0000\:00\:1d.0/power/wakeup enabled

maxim@maxim-laptop:~$ cat /proc/acpi/wakeup 
Device S-state   Status   Sysfs node
UHC1   S3 disabled  pci:0000:00:1d.0
UHC2   S3 disabled  pci:0000:00:1d.1
UHC3   S3 disabled  pci:0000:00:1d.2
UHC4   S3 disabled  pci:0000:00:1a.0
UHC5   S3 disabled  pci:0000:00:1a.1
EHC1   S3 disabled  pci:0000:00:1d.7
EHC2   S3 disabled  pci:0000:00:1a.7
EXP3   S4 disabled  pci:0000:00:1c.2
EXP5   S4 disabled  
EXP6   S4 disabled  
AZAL   S4 disabled  pci:0000:00:1b.0
MODM   S4 disabled  

Or am I mistaken somehow?

Quoted 7 lines
Quoted 3 lines

You are. Please ignore the "Status" column in /proc/acpi/wakeup, it shows the value of a flag that's not used for PCI devices (unless you set it via /proc/acpi/wakeup

It is indeed true.

PnP device too are supported in this way?

I don't know really.

Quoted 2 lines

Then I think it would be very nice to remove all pci and pnp devices from this list to avoid confusion.

I wouldn't do that, because it allows us to see easily which devices are seen by ACPI as wakeup-capable. Perhaps the format of the file may be changed, though.

Rafael

#22 lore raw
In reply to Rafael J. Wysocki
Quoted 57 lines

-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Saturday, February 06, 2010 3:32 PM
To: Moore, Robert
Cc: Matthew Garrett; [email protected]; Len Brown
Subject: Re: Recent GPE patches - some questions.

Hi,

Quoted 6 lines · Robert

Matthew,

Thanks for your response to my questions.

I've been thinking about these interfaces:

Quoted 7 lines

acpi_ref_runtime_gpe
acpi_ref_wakeup_gpe
acpi_unref_runtime_gpe
acpi_unref_wakeup_gpe

While I understand the need for the reference counting mechanism, it is a good idea to support the shared GPEs, I think it may be simpler and

cleaner

Quoted 1 line

to simply not directly expose this mechanism to GPE users.

Well, it already is exposed to the users and in a way that doesn't look very
clean to me. Namely, to enable a wakeup GPE for run time, the caller needs to
set its type to ACPI_GPE_TYPE_WAKE_RUN before calling acpi_enable_gpe(), while with the Matthew's interface the only thing the caller would need to do
would be calling acpi_ref_runtime_gpe().

Quoted 1 line

I'm suggesting that we add the reference counting mechanism to the

existing

Quoted 1 line

AcpiEnableGpe and AcpiDisableGpe interfaces and update their

descriptions.

Quoted 1 line

We already hide the differences between wake, run, and wake-run GPEs

behind

Quoted 1 line

these interfaces.

Not really, as I said above.

Moreover, we need two reference counters, because there are cases when a GPE should be enabled for wakeup and not enabled for run time and vice versa.

Quoted 5 lines

Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first

call.

Quoted 8 lines
Quoted 1 line

AcpiDisableGpe: For a given GPE, it is actually disabled only on the last

call.

I suppose you mean acpi_enable_gpe() and acpi_disable_gpe().

That wouldn't work, because sometimes we need to actually hardware-disable GPEs and hardware-enable them regardless of the refcount mechanism, like for example in the EC suspend and resume routines.

Yes, this makes sense, even if the EC GPE is shared.

Quoted 14 lines

That said, if you are afraid that the new interface may be cumbersome for the
callers, I think we can introduce just two callbacks,

acpi_get_gpe()
acpi_put_gpe()

taking 3 arguments each, where the two first arguments are like for the Matthew's callbacks and the third argument is a mask of two bits:

ACPI_GPE_TYPE_WAKE
ACPI_GPE_TYPE_RUNTIME

Quoted 8 lines

that will tell the callback whether to use the wakeup or runtime counter for
reference counting (if called with ACPI_GPE_TYPE_WAKE_RUN, both reference counters will be modified at the same time).

Please tell me what you think.

Rafael

Good, I like having the two interfaces better than the original four.

However, I'm having some trouble with the naming. I think I would like to keep acpi_enable_gpe and acpi_disable_gpe as the high-level enable/disable interfaces that may or may not actually touch the hardware depending on reference count, run vs. wake, etc. Thus, enable_gpe and disable_gpe remain similar to today (with addition of new reference count mechanisms) and would correspond to put_gpe and get_gpe above. I think this also has the advantage of reducing changes to existing drivers across all operating systems supported by ACPICA.

Then, we have the special case where a driver must absolutely (H/W) enable/disable a GPE, regardless of sharing. Probably only the EC driver needs this. I would like to see new interfaces for these. Actually, one new interface would probably suffice. Something like:

acpi_set_gpe (ENABLE | DISABLE)

Bob

#23 lore raw

PATCH 1/1 ACPI: Use GPE reference counting to support shared GPEs (was: Re: Recent GPE patches - some questions.)

Quoted 7 lines · Robert
Quoted 7 lines

-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Saturday, February 06, 2010 3:32 PM
To: Moore, Robert
Cc: Matthew Garrett; [email protected]; Len Brown
Subject: Re: Recent GPE patches - some questions.

...

Quoted 53 lines
Quoted 10 lines

Moreover, we need two reference counters, because there are cases when a GPE should be enabled for wakeup and not enabled for run time and vice versa.

Quoted 5 lines

Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first

call.

Quoted 8 lines
Quoted 1 line

AcpiDisableGpe: For a given GPE, it is actually disabled only on the last

call.

I suppose you mean acpi_enable_gpe() and acpi_disable_gpe().

That wouldn't work, because sometimes we need to actually hardware-disable GPEs and hardware-enable them regardless of the refcount mechanism, like for example in the EC suspend and resume routines.

Yes, this makes sense, even if the EC GPE is shared.

Quoted 14 lines

That said, if you are afraid that the new interface may be cumbersome for the
callers, I think we can introduce just two callbacks,

acpi_get_gpe()
acpi_put_gpe()

taking 3 arguments each, where the two first arguments are like for the Matthew's callbacks and the third argument is a mask of two bits:

ACPI_GPE_TYPE_WAKE
ACPI_GPE_TYPE_RUNTIME

Quoted 6 lines

that will tell the callback whether to use the wakeup or runtime counter for
reference counting (if called with ACPI_GPE_TYPE_WAKE_RUN, both reference counters will be modified at the same time).

Please tell me what you think.

Good, I like having the two interfaces better than the original four.

However, I'm having some trouble with the naming. I think I would like to keep acpi_enable_gpe and acpi_disable_gpe as the high-level enable/disable interfaces that may or may not actually touch the hardware depending on reference count, run vs. wake, etc. Thus, enable_gpe and disable_gpe remain similar to today (with addition of new reference count mechanisms) and would correspond to put_gpe and get_gpe above. I think this also has the advantage of reducing changes to existing drivers across all operating systems supported by ACPICA.

Quoted 6 lines

Then, we have the special case where a driver must absolutely (H/W) enable/disable a GPE, regardless of sharing. Probably only the EC driver needs this. I would like to see new interfaces for these. Actually, one new interface would probably suffice. Something like:

acpi_set_gpe (ENABLE | DISABLE)

OK

I had to fold the 3 patches into the appended one. I used the names like you suggested.

The patch has been initially tested on a few machines and appears to work fine.

Rafael

---
Subject: ACPI: Use GPE reference counting to support shared GPEs
From: Rafael J. Wysocki <[email protected]>

ACPI GPEs may map to multiple devices. The current GPE interface only provides a mechanism for enabling and disabling GPEs, making it difficult to change the state of GPEs at runtime without extensive cooperation between devices.

Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

Remove the old GPE type handling entirely, which gets rid of various quirks, like the implicit disabling with GPE type setting. This requires a small amount of rework in order to ensure that non-wake GPEs are enabled by default to preserve existing behaviour.

Based on patches from Matthew Garrett <[email protected]>.

---
 drivers/acpi/acpica/acevents.h |    6 -
 drivers/acpi/acpica/aclocal.h  |    2 
 drivers/acpi/acpica/evgpe.c    |  153 ++++-------------------------------------
 drivers/acpi/acpica/evgpeblk.c |   87 ++++++++---------------
 drivers/acpi/acpica/evxface.c  |   14 ---
 drivers/acpi/acpica/evxfevnt.c |   90 +++++++++++++++++-------
 drivers/acpi/button.c          |   13 ++-
 drivers/acpi/ec.c              |   14 ++-
 drivers/acpi/sleep.c           |   15 +++-
 drivers/acpi/system.c          |    4 -
 drivers/acpi/wakeup.c          |   81 +++++++--------------
 include/acpi/acpixf.h          |    6 -
 include/acpi/actypes.h         |   28 ++-----
 13 files changed, 188 insertions(+), 325 deletions(-)
drivers/acpi/acpica/aclocal.h +2 -0
Index: linux-2.6/drivers/acpi/acpica/aclocal.h
===================================================================
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {
 	struct acpi_gpe_register_info *register_info;	/* Backpointer to register info */
 	u8 flags;		/* Misc info about this GPE */
 	u8 gpe_number;		/* This GPE */
+	u8 runtime_count;
+	u8 wakeup_count;
 };
 
 /* Information about a GPE register pair, one per each status/enable pair in an array */
drivers/acpi/acpica/evxfevnt.c +65 -25

165 lines not on this page · raw message

include/acpi/acpixf.h +3 -3
Index: linux-2.6/include/acpi/acpixf.h
===================================================================
@@ -281,11 +281,11 @@ acpi_status acpi_get_event_status(u32 ev
 /*
  * GPE Interfaces
  */
-acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type);
+acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action);
 
-acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number);
+acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
 
-acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
+acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
 
 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags);
 
drivers/acpi/button.c +9 -4
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -422,11 +422,9 @@ static int acpi_button_add(struct acpi_d
 
 	if (device->wakeup.flags.valid) {
 		/* Button's GPE is run-wake GPE */
-		acpi_set_gpe_type(device->wakeup.gpe_device,
-				  device->wakeup.gpe_number,
-				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(device->wakeup.gpe_device,
-				device->wakeup.gpe_number);
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
 		device->wakeup.state.enabled = 1;
 	}
 
@@ -446,6 +444,13 @@ static int acpi_button_remove(struct acp
 {
 	struct acpi_button *button = acpi_driver_data(device);
 
+	if (device->wakeup.flags.valid) {
+		acpi_disable_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
+		device->wakeup.state.enabled = 0;
+	}
+
 	acpi_button_remove_fs(device);
 	input_unregister_device(button->input);
 	kfree(button);
drivers/acpi/ec.c +8 -6
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -307,7 +307,7 @@ static int acpi_ec_transaction(struct ac
 	pr_debug(PREFIX "transaction start\n");
 	/* disable GPE during transaction if storm is detected */
 	if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
-		acpi_disable_gpe(NULL, ec->gpe);
+		acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
 	}
 
 	status = acpi_ec_transaction_unlocked(ec, t);
@@ -317,7 +317,7 @@ static int acpi_ec_transaction(struct ac
 	if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
 		msleep(1);
 		/* it is safe to enable GPE outside of transaction */
-		acpi_enable_gpe(NULL, ec->gpe);
+		acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
 	} else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) {
 		pr_info(PREFIX "GPE storm detected, "
 			"transactions will use polling mode\n");
@@ -788,8 +788,8 @@ static int ec_install_handlers(struct ac
 				  &acpi_ec_gpe_handler, ec);
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
-	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
-	acpi_enable_gpe(NULL, ec->gpe);
+
+	acpi_enable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
 						    &acpi_ec_space_handler,
@@ -806,6 +806,7 @@ static int ec_install_handlers(struct ac
 		} else {
 			acpi_remove_gpe_handler(NULL, ec->gpe,
 				&acpi_ec_gpe_handler);
+			acpi_disable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 			return -ENODEV;
 		}
 	}
@@ -816,6 +817,7 @@ static int ec_install_handlers(struct ac
 
 static void ec_remove_handlers(struct acpi_ec *ec)
 {
+	acpi_disable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
 				ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
 		pr_err(PREFIX "failed to remove space handler\n");
@@ -1058,7 +1060,7 @@ static int acpi_ec_suspend(struct acpi_d
 {
 	struct acpi_ec *ec = acpi_driver_data(device);
 	/* Stop using GPE */
-	acpi_disable_gpe(NULL, ec->gpe);
+	acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
 	return 0;
 }
 
@@ -1066,7 +1068,7 @@ static int acpi_ec_resume(struct acpi_de
 {
 	struct acpi_ec *ec = acpi_driver_data(device);
 	/* Enable use of GPE back */
-	acpi_enable_gpe(NULL, ec->gpe);
+	acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
 	return 0;
 }
 
drivers/acpi/sleep.c +12 -3
Index: linux-2.6/drivers/acpi/sleep.c
===================================================================
@@ -745,9 +745,18 @@ int acpi_pm_device_sleep_wake(struct dev
 		return -ENODEV;
 	}
 
-	error = enable ?
-		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
-		acpi_disable_wakeup_device_power(adev);
+	if (enable) {
+		error = acpi_enable_wakeup_device_power(adev,
+						acpi_target_sleep_state);
+		if (!error)
+			acpi_enable_gpe(adev->wakeup.gpe_device,
+					adev->wakeup.gpe_number,
+					ACPI_GPE_TYPE_WAKE);
+	} else {
+		acpi_disable_gpe(adev->wakeup.gpe_device, adev->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE);
+		error = acpi_disable_wakeup_device_power(adev);
+	}
 	if (!error)
 		dev_info(dev, "wake-up capability %s by ACPI\n",
 				enable ? "enabled" : "disabled");
drivers/acpi/wakeup.c +27 -54

127 lines not on this page · raw message

drivers/acpi/acpica/acevents.h +1 -5
Index: linux-2.6/drivers/acpi/acpica/acevents.h
===================================================================
@@ -76,8 +76,7 @@ acpi_ev_queue_notify_request(struct acpi
  * evgpe - GPE handling and dispatch
  */
 acpi_status
-acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
-				u8 type);
+acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status
 acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
@@ -122,9 +121,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_eve
 u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
 
 acpi_status
-acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type);
-
-acpi_status
 acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status acpi_ev_gpe_initialize(void);
drivers/acpi/acpica/evgpe.c +16 -137

196 lines not on this page · raw message

drivers/acpi/acpica/evgpeblk.c +33 -54

150 lines not on this page · raw message

drivers/acpi/acpica/evxface.c +0 -14
Index: linux-2.6/drivers/acpi/acpica/evxface.c
===================================================================
@@ -617,13 +617,6 @@ acpi_install_gpe_handler(acpi_handle gpe
 	handler->context = context;
 	handler->method_node = gpe_event_info->dispatch.method_node;
 
-	/* Disable the GPE before installing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Install the handler */
 
 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
@@ -707,13 +700,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_
 		goto unlock_and_exit;
 	}
 
-	/* Disable the GPE before removing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Make sure all deferred tasks are completed */
 
 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
include/acpi/actypes.h +10 -18
Index: linux-2.6/include/acpi/actypes.h
===================================================================
@@ -668,15 +668,16 @@ typedef u32 acpi_event_status;
 
 /*
  * GPE info flags - Per GPE
- * +-+-+-+---+---+-+
- * |7|6|5|4:3|2:1|0|
- * +-+-+-+---+---+-+
- *  | | |  |   |  |
- *  | | |  |   |  +--- Interrupt type: Edge or Level Triggered
- *  | | |  |   +--- Type: Wake-only, Runtime-only, or wake/runtime
+ * +-+-+-+---+-+-+-+
+ * |7|6|5|4:3|2|1|0|
+ * +-+-+-+---+-+-+-+
+ *  | | |  |  | | |
+ *  | | |  |  | | +--- Interrupt type: Edge or Level Triggered
+ *  | | |  |  | +--- GPE can wake the system
+ *  | | |  |  +--- Unused
  *  | | |  +--- Type of dispatch -- to method, handler, or none
- *  | | +--- Enabled for runtime?
- *  | +--- Enabled for wake?
+ *  | | +--- Unused
+ *  | +--- Unused
  *  +--- Unused
  */
 #define ACPI_GPE_XRUPT_TYPE_MASK        (u8) 0x01
@@ -687,22 +688,13 @@ typedef u32 acpi_event_status;
 #define ACPI_GPE_TYPE_WAKE_RUN          (u8) 0x06
 #define ACPI_GPE_TYPE_WAKE              (u8) 0x02
 #define ACPI_GPE_TYPE_RUNTIME           (u8) 0x04	/* Default */
+#define ACPI_GPE_CAN_WAKE		(u8) 0x02
 
 #define ACPI_GPE_DISPATCH_MASK          (u8) 0x18
 #define ACPI_GPE_DISPATCH_HANDLER       (u8) 0x08
 #define ACPI_GPE_DISPATCH_METHOD        (u8) 0x10
 #define ACPI_GPE_DISPATCH_NOT_USED      (u8) 0x00	/* Default */
 
-#define ACPI_GPE_RUN_ENABLE_MASK        (u8) 0x20
-#define ACPI_GPE_RUN_ENABLED            (u8) 0x20
-#define ACPI_GPE_RUN_DISABLED           (u8) 0x00	/* Default */
-
-#define ACPI_GPE_WAKE_ENABLE_MASK       (u8) 0x40
-#define ACPI_GPE_WAKE_ENABLED           (u8) 0x40
-#define ACPI_GPE_WAKE_DISABLED          (u8) 0x00	/* Default */
-
-#define ACPI_GPE_ENABLE_MASK            (u8) 0x60	/* Both run/wake */
-
 /*
  * Flags for GPE and Lock interfaces
  */
drivers/acpi/system.c +2 -2
Index: linux-2.6/drivers/acpi/system.c
===================================================================
@@ -387,10 +387,10 @@ static ssize_t counter_set(struct kobjec
 	if (index < num_gpes) {
 		if (!strcmp(buf, "disable\n") &&
 				(status & ACPI_EVENT_FLAG_ENABLED))
-			result = acpi_disable_gpe(handle, index);
+			result = acpi_set_gpe(handle, index, ACPI_GPE_DISABLE);
 		else if (!strcmp(buf, "enable\n") &&
 				!(status & ACPI_EVENT_FLAG_ENABLED))
-			result = acpi_enable_gpe(handle, index);
+			result = acpi_set_gpe(handle, index, ACPI_GPE_ENABLE);
 		else if (!strcmp(buf, "clear\n") &&
 				(status & ACPI_EVENT_FLAG_SET))
 			result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR);
#24 lore raw

PATCH 1/1 ACPI: Use GPE reference counting to support shared GPEs (was: Re: Recent GPE patches - some questions.)

In reply to Moore, Robert
Quoted 7 lines · Robert
Quoted 7 lines

-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Saturday, February 06, 2010 3:32 PM
To: Moore, Robert
Cc: Matthew Garrett; [email protected]; Len Brown
Subject: Re: Recent GPE patches - some questions.

...

Quoted 53 lines
Quoted 10 lines

Moreover, we need two reference counters, because there are cases when a GPE should be enabled for wakeup and not enabled for run time and vice versa.

Quoted 5 lines

Adding the reference count semantic to these interfaces changes their behavior in a fairly simple way:

Support for shared GPEs:
AcpiEnableGpe: For a given GPE, it is actually enabled only on the first

call.

Quoted 8 lines
Quoted 1 line

AcpiDisableGpe: For a given GPE, it is actually disabled only on the last

call.

I suppose you mean acpi_enable_gpe() and acpi_disable_gpe().

That wouldn't work, because sometimes we need to actually hardware-disable GPEs and hardware-enable them regardless of the refcount mechanism, like for example in the EC suspend and resume routines.

Yes, this makes sense, even if the EC GPE is shared.

Quoted 14 lines

That said, if you are afraid that the new interface may be cumbersome for the
callers, I think we can introduce just two callbacks,

acpi_get_gpe()
acpi_put_gpe()

taking 3 arguments each, where the two first arguments are like for the Matthew's callbacks and the third argument is a mask of two bits:

ACPI_GPE_TYPE_WAKE
ACPI_GPE_TYPE_RUNTIME

Quoted 6 lines

that will tell the callback whether to use the wakeup or runtime counter for
reference counting (if called with ACPI_GPE_TYPE_WAKE_RUN, both reference counters will be modified at the same time).

Please tell me what you think.

Good, I like having the two interfaces better than the original four.

However, I'm having some trouble with the naming. I think I would like to keep acpi_enable_gpe and acpi_disable_gpe as the high-level enable/disable interfaces that may or may not actually touch the hardware depending on reference count, run vs. wake, etc. Thus, enable_gpe and disable_gpe remain similar to today (with addition of new reference count mechanisms) and would correspond to put_gpe and get_gpe above. I think this also has the advantage of reducing changes to existing drivers across all operating systems supported by ACPICA.

Quoted 6 lines

Then, we have the special case where a driver must absolutely (H/W) enable/disable a GPE, regardless of sharing. Probably only the EC driver needs this. I would like to see new interfaces for these. Actually, one new interface would probably suffice. Something like:

acpi_set_gpe (ENABLE | DISABLE)

OK

I had to fold the 3 patches into the appended one. I used the names like you suggested.

The patch has been initially tested on a few machines and appears to work fine.

Rafael

---
Subject: ACPI: Use GPE reference counting to support shared GPEs
From: Rafael J. Wysocki <[email protected]>

ACPI GPEs may map to multiple devices. The current GPE interface only provides a mechanism for enabling and disabling GPEs, making it difficult to change the state of GPEs at runtime without extensive cooperation between devices.

Add an API to allow devices to indicate whether or not they want their device's GPE to be enabled for both runtime and wakeup events.

Remove the old GPE type handling entirely, which gets rid of various quirks, like the implicit disabling with GPE type setting. This requires a small amount of rework in order to ensure that non-wake GPEs are enabled by default to preserve existing behaviour.

Based on patches from Matthew Garrett <[email protected]>.

---
 drivers/acpi/acpica/acevents.h |    6 -
 drivers/acpi/acpica/aclocal.h  |    2 
 drivers/acpi/acpica/evgpe.c    |  153 ++++-------------------------------------
 drivers/acpi/acpica/evgpeblk.c |   87 ++++++++---------------
 drivers/acpi/acpica/evxface.c  |   14 ---
 drivers/acpi/acpica/evxfevnt.c |   90 +++++++++++++++++-------
 drivers/acpi/button.c          |   13 ++-
 drivers/acpi/ec.c              |   14 ++-
 drivers/acpi/sleep.c           |   15 +++-
 drivers/acpi/system.c          |    4 -
 drivers/acpi/wakeup.c          |   81 +++++++--------------
 include/acpi/acpixf.h          |    6 -
 include/acpi/actypes.h         |   28 ++-----
 13 files changed, 188 insertions(+), 325 deletions(-)
drivers/acpi/acpica/aclocal.h +2 -0
Index: linux-2.6/drivers/acpi/acpica/aclocal.h
===================================================================
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {
 	struct acpi_gpe_register_info *register_info;	/* Backpointer to register info */
 	u8 flags;		/* Misc info about this GPE */
 	u8 gpe_number;		/* This GPE */
+	u8 runtime_count;
+	u8 wakeup_count;
 };
 
 /* Information about a GPE register pair, one per each status/enable pair in an array */
drivers/acpi/acpica/evxfevnt.c +65 -25

165 lines not on this page · raw message

include/acpi/acpixf.h +3 -3
Index: linux-2.6/include/acpi/acpixf.h
===================================================================
@@ -281,11 +281,11 @@ acpi_status acpi_get_event_status(u32 ev
 /*
  * GPE Interfaces
  */
-acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type);
+acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action);
 
-acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number);
+acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
 
-acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
+acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
 
 acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags);
 
drivers/acpi/button.c +9 -4
Index: linux-2.6/drivers/acpi/button.c
===================================================================
@@ -422,11 +422,9 @@ static int acpi_button_add(struct acpi_d
 
 	if (device->wakeup.flags.valid) {
 		/* Button's GPE is run-wake GPE */
-		acpi_set_gpe_type(device->wakeup.gpe_device,
-				  device->wakeup.gpe_number,
-				  ACPI_GPE_TYPE_WAKE_RUN);
 		acpi_enable_gpe(device->wakeup.gpe_device,
-				device->wakeup.gpe_number);
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
 		device->wakeup.state.enabled = 1;
 	}
 
@@ -446,6 +444,13 @@ static int acpi_button_remove(struct acp
 {
 	struct acpi_button *button = acpi_driver_data(device);
 
+	if (device->wakeup.flags.valid) {
+		acpi_disable_gpe(device->wakeup.gpe_device,
+				device->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE_RUN);
+		device->wakeup.state.enabled = 0;
+	}
+
 	acpi_button_remove_fs(device);
 	input_unregister_device(button->input);
 	kfree(button);
drivers/acpi/ec.c +8 -6
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
@@ -307,7 +307,7 @@ static int acpi_ec_transaction(struct ac
 	pr_debug(PREFIX "transaction start\n");
 	/* disable GPE during transaction if storm is detected */
 	if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
-		acpi_disable_gpe(NULL, ec->gpe);
+		acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
 	}
 
 	status = acpi_ec_transaction_unlocked(ec, t);
@@ -317,7 +317,7 @@ static int acpi_ec_transaction(struct ac
 	if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
 		msleep(1);
 		/* it is safe to enable GPE outside of transaction */
-		acpi_enable_gpe(NULL, ec->gpe);
+		acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
 	} else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) {
 		pr_info(PREFIX "GPE storm detected, "
 			"transactions will use polling mode\n");
@@ -788,8 +788,8 @@ static int ec_install_handlers(struct ac
 				  &acpi_ec_gpe_handler, ec);
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
-	acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
-	acpi_enable_gpe(NULL, ec->gpe);
+
+	acpi_enable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	status = acpi_install_address_space_handler(ec->handle,
 						    ACPI_ADR_SPACE_EC,
 						    &acpi_ec_space_handler,
@@ -806,6 +806,7 @@ static int ec_install_handlers(struct ac
 		} else {
 			acpi_remove_gpe_handler(NULL, ec->gpe,
 				&acpi_ec_gpe_handler);
+			acpi_disable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 			return -ENODEV;
 		}
 	}
@@ -816,6 +817,7 @@ static int ec_install_handlers(struct ac
 
 static void ec_remove_handlers(struct acpi_ec *ec)
 {
+	acpi_disable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
 	if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
 				ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
 		pr_err(PREFIX "failed to remove space handler\n");
@@ -1058,7 +1060,7 @@ static int acpi_ec_suspend(struct acpi_d
 {
 	struct acpi_ec *ec = acpi_driver_data(device);
 	/* Stop using GPE */
-	acpi_disable_gpe(NULL, ec->gpe);
+	acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
 	return 0;
 }
 
@@ -1066,7 +1068,7 @@ static int acpi_ec_resume(struct acpi_de
 {
 	struct acpi_ec *ec = acpi_driver_data(device);
 	/* Enable use of GPE back */
-	acpi_enable_gpe(NULL, ec->gpe);
+	acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
 	return 0;
 }
 
drivers/acpi/sleep.c +12 -3
Index: linux-2.6/drivers/acpi/sleep.c
===================================================================
@@ -745,9 +745,18 @@ int acpi_pm_device_sleep_wake(struct dev
 		return -ENODEV;
 	}
 
-	error = enable ?
-		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
-		acpi_disable_wakeup_device_power(adev);
+	if (enable) {
+		error = acpi_enable_wakeup_device_power(adev,
+						acpi_target_sleep_state);
+		if (!error)
+			acpi_enable_gpe(adev->wakeup.gpe_device,
+					adev->wakeup.gpe_number,
+					ACPI_GPE_TYPE_WAKE);
+	} else {
+		acpi_disable_gpe(adev->wakeup.gpe_device, adev->wakeup.gpe_number,
+				ACPI_GPE_TYPE_WAKE);
+		error = acpi_disable_wakeup_device_power(adev);
+	}
 	if (!error)
 		dev_info(dev, "wake-up capability %s by ACPI\n",
 				enable ? "enabled" : "disabled");
drivers/acpi/wakeup.c +27 -54

127 lines not on this page · raw message

drivers/acpi/acpica/acevents.h +1 -5
Index: linux-2.6/drivers/acpi/acpica/acevents.h
===================================================================
@@ -76,8 +76,7 @@ acpi_ev_queue_notify_request(struct acpi
  * evgpe - GPE handling and dispatch
  */
 acpi_status
-acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
-				u8 type);
+acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status
 acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
@@ -122,9 +121,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_eve
 u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
 
 acpi_status
-acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type);
-
-acpi_status
 acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info);
 
 acpi_status acpi_ev_gpe_initialize(void);
drivers/acpi/acpica/evgpe.c +16 -137

196 lines not on this page · raw message

drivers/acpi/acpica/evgpeblk.c +33 -54

150 lines not on this page · raw message

drivers/acpi/acpica/evxface.c +0 -14
Index: linux-2.6/drivers/acpi/acpica/evxface.c
===================================================================
@@ -617,13 +617,6 @@ acpi_install_gpe_handler(acpi_handle gpe
 	handler->context = context;
 	handler->method_node = gpe_event_info->dispatch.method_node;
 
-	/* Disable the GPE before installing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Install the handler */
 
 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
@@ -707,13 +700,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_
 		goto unlock_and_exit;
 	}
 
-	/* Disable the GPE before removing the handler */
-
-	status = acpi_ev_disable_gpe(gpe_event_info);
-	if (ACPI_FAILURE(status)) {
-		goto unlock_and_exit;
-	}
-
 	/* Make sure all deferred tasks are completed */
 
 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
include/acpi/actypes.h +10 -18
Index: linux-2.6/include/acpi/actypes.h
===================================================================
@@ -668,15 +668,16 @@ typedef u32 acpi_event_status;
 
 /*
  * GPE info flags - Per GPE
- * +-+-+-+---+---+-+
- * |7|6|5|4:3|2:1|0|
- * +-+-+-+---+---+-+
- *  | | |  |   |  |
- *  | | |  |   |  +--- Interrupt type: Edge or Level Triggered
- *  | | |  |   +--- Type: Wake-only, Runtime-only, or wake/runtime
+ * +-+-+-+---+-+-+-+
+ * |7|6|5|4:3|2|1|0|
+ * +-+-+-+---+-+-+-+
+ *  | | |  |  | | |
+ *  | | |  |  | | +--- Interrupt type: Edge or Level Triggered
+ *  | | |  |  | +--- GPE can wake the system
+ *  | | |  |  +--- Unused
  *  | | |  +--- Type of dispatch -- to method, handler, or none
- *  | | +--- Enabled for runtime?
- *  | +--- Enabled for wake?
+ *  | | +--- Unused
+ *  | +--- Unused
  *  +--- Unused
  */
 #define ACPI_GPE_XRUPT_TYPE_MASK        (u8) 0x01
@@ -687,22 +688,13 @@ typedef u32 acpi_event_status;
 #define ACPI_GPE_TYPE_WAKE_RUN          (u8) 0x06
 #define ACPI_GPE_TYPE_WAKE              (u8) 0x02
 #define ACPI_GPE_TYPE_RUNTIME           (u8) 0x04	/* Default */
+#define ACPI_GPE_CAN_WAKE		(u8) 0x02
 
 #define ACPI_GPE_DISPATCH_MASK          (u8) 0x18
 #define ACPI_GPE_DISPATCH_HANDLER       (u8) 0x08
 #define ACPI_GPE_DISPATCH_METHOD        (u8) 0x10
 #define ACPI_GPE_DISPATCH_NOT_USED      (u8) 0x00	/* Default */
 
-#define ACPI_GPE_RUN_ENABLE_MASK        (u8) 0x20
-#define ACPI_GPE_RUN_ENABLED            (u8) 0x20
-#define ACPI_GPE_RUN_DISABLED           (u8) 0x00	/* Default */
-
-#define ACPI_GPE_WAKE_ENABLE_MASK       (u8) 0x40
-#define ACPI_GPE_WAKE_ENABLED           (u8) 0x40
-#define ACPI_GPE_WAKE_DISABLED          (u8) 0x00	/* Default */
-
-#define ACPI_GPE_ENABLE_MASK            (u8) 0x60	/* Both run/wake */
-
 /*
  * Flags for GPE and Lock interfaces
  */
drivers/acpi/system.c +2 -2
Index: linux-2.6/drivers/acpi/system.c
===================================================================
@@ -387,10 +387,10 @@ static ssize_t counter_set(struct kobjec
 	if (index < num_gpes) {
 		if (!strcmp(buf, "disable\n") &&
 				(status & ACPI_EVENT_FLAG_ENABLED))
-			result = acpi_disable_gpe(handle, index);
+			result = acpi_set_gpe(handle, index, ACPI_GPE_DISABLE);
 		else if (!strcmp(buf, "enable\n") &&
 				!(status & ACPI_EVENT_FLAG_ENABLED))
-			result = acpi_enable_gpe(handle, index);
+			result = acpi_set_gpe(handle, index, ACPI_GPE_ENABLE);
 		else if (!strcmp(buf, "clear\n") &&
 				(status & ACPI_EVENT_FLAG_SET))
 			result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR);