ACPI: Avoid executing _PRW twice for all devices
Subsystems (2)
cover ACPI: Avoid executing _PRW twice for all devices
Hi,
The following patches have already been sent once and (except for [1/4]) they have been in your test branch for some time, but they stopped applying after the previous ACPICA changes were merged. So, here they go again, rebased on top of your test branch.
[1/4] - Fixes a test supposed to check if a GPE has a method or handler.
[2/4] - Drops the code walikng the namespace in search of _PRW and adds
acpi_gpe_can_wake() so that the host OS can disable wakeup GPEs previously enabled unconditionally by the ACPICA initialization code. This basically reproduces the current behavior except that the GPEs are temporarily enabled befor acpi_bus_extract_wakeup_device_power_package()
runs for all devices with _PRW referring to them.
[3/4] - Simplifies code in acpi_ev_initialize_gpe_block(), which only is a
cosmetic thing, but worth doing IMO.
[4/4] - Changes acpi_gpe_wakeup() to return error code for the GPEs whose
ACPI_GPE_CAN_WAKE flags are not set.
Please apply.
Rafael
PATCH RESEND 1/4 ACPI: Fix bogus GPE test in acpi_bus_set_run_wake_flags()
From: Rafael J. Wysocki <[email protected]>
When we check if a GPE can be used for runtime signaling, we only search the FADT GPE blocks, which is incorrect, becuase the GPE may be located elsewhere. We really should be using the GPE device information previously returned by _PRW here, so make that happen.
--- drivers/acpi/scan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/scan.c +3 -2
@@ -764,8 +764,9 @@ static void acpi_bus_set_run_wake_flags(return ; } - status =acpi_get_gpe_status (NULL , device->wakeup.gpe_number, - &event_status); + status =acpi_get_gpe_status (device->wakeup.gpe_device, + device->wakeup.gpe_number, + &event_status);if (status ==AE_OK ) device->wakeup.flags.run_wake = !!(event_status &ACPI_EVENT_FLAG_HANDLE );
PATCH RESEND 1/4 ACPI: Fix bogus GPE test in acpi_bus_set_run_wake_flags()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
When we check if a GPE can be used for runtime signaling, we only search the FADT GPE blocks, which is incorrect, becuase the GPE may be located elsewhere. We really should be using the GPE device information previously returned by _PRW here, so make that happen.
--- drivers/acpi/scan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/scan.c +3 -2
@@ -764,8 +764,9 @@ static void acpi_bus_set_run_wake_flags(return ; } - status =acpi_get_gpe_status (NULL , device->wakeup.gpe_number, - &event_status); + status =acpi_get_gpe_status (device->wakeup.gpe_device, + device->wakeup.gpe_number, + &event_status);if (status ==AE_OK ) device->wakeup.flags.run_wake = !!(event_status &ACPI_EVENT_FLAG_HANDLE );
PATCH RESEND 2/4 ACPI / ACPICA: Do not execute _PRW methods during initialization
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Currently, during initialization ACPICA walks the entire ACPI namespace in search of any device objects with assciated _PRW methods. All of the _PRW methods found are executed in the process to extract the GPE information returned by them, so that the GPEs in question can be marked as "able to wakeup" (more precisely, the ACPI_GPE_CAN_WAKE flag is set for them). The only purpose of this exercise is to avoid enabling the CAN_WAKE GPEs automatically, even if there are _Lxx/_Exx methods associated with them. However, it is both costly and unnecessary, because the host OS has to execute the _PRW methods anyway to check which devices can wake up the system from sleep states. Moreover, it then uses full information returned by _PRW, including the GPE information, so it can take care of disabling the GPEs if necessary.
Remove the code that walks the namespace and executes _PRW from ACPICA and modify comments to reflect that change. Make acpi_bus_set_run_wake_flags() disable GPEs for wakeup devices so that they don't cause spurious wakeup events to be signaled. This not only reduces the complexity of the ACPICA initialization code, but in some cases it should reduce the kernel boot time as well.
Unfortunately, for this purpose we need a new ACPICA function, acpi_gpe_can_wake(), to be called by the host OS in order to disable the GPEs that can wake up the system and were previously enabled by acpi_ev_initialize_gpe_block() or acpi_ev_update_gpes() (such a GPE should be disabled only once, because the initialization code enables it only once, but it may be pointed to by _PRW for multiple devices and that's why the additional function is necessary).
--- drivers/acpi/acpica/acglobal.h | 7 - drivers/acpi/acpica/evevent.c | 5 drivers/acpi/acpica/evgpeblk.c | 47 -------- drivers/acpi/acpica/evgpeinit.c | 235 ++-------------------------------------- drivers/acpi/acpica/evxfevnt.c | 55 +++++++++ drivers/acpi/acpica/exconfig.c | 2 drivers/acpi/acpica/utxface.c | 8 - drivers/acpi/osl.c | 20 --- drivers/acpi/scan.c | 2 include/acpi/acpixf.h | 3 10 files changed, 85 insertions(+), 299 deletions(-)
drivers/acpi/scan.c +2 -0
@@ -740,6 +740,8 @@ acpi_bus_extract_wakeup_device_power_pac device->wakeup.resources.handles[i] = element->reference.handle; } +acpi_gpe_can_wake (device->wakeup.gpe_device, device->wakeup.gpe_number); +return AE_OK ; }
drivers/acpi/acpica/evgpeinit.c +17 -218
280 lines not on this page · raw message
drivers/acpi/acpica/evgpeblk.c +5 -42
73 lines not on this page · raw message
drivers/acpi/acpica/evxfevnt.c +54 -1
67 lines not on this page · raw message
drivers/acpi/acpica/utxface.c +2 -6
@@ -293,12 +293,8 @@ acpi_status acpi_initialize_objects(u32* Complete the GPE initialization for the GPE blocks defined in the FADT * (GPE block 0 and 1). * -* Note1: This is where the _PRW methods are executed for the GPEs. These -* methods can only be executed after the SCI and Global Lock handlers are -* installed and initialized. -* -* Note2: Currently, there seems to be no need to run the _REG methods -* before execution of the _PRW methods and enabling of the GPEs. +* NOTE: Currently, there seems to be no need to run the _REG methods +* before enabling the GPEs. */ if (!(flags &ACPI_NO_EVENT_INIT )) { status =acpi_ev_install_fadt_gpes ();
drivers/acpi/acpica/evevent.c +2 -3
@@ -102,9 +102,8 @@ acpi_status acpi_ev_initialize_events(vo* RETURN: Status * * DESCRIPTION: Completes initialization of the FADT-defined GPE blocks -* (0 and 1). This causes the _PRW methods to be run, so the HW -* must be fully initialized at this point, including global lock -* support. +* (0 and 1). The HW must be fully initialized at this point, +* including global lock support. * ******************************************************************************/
drivers/acpi/acpica/exconfig.c +1 -1
@@ -120,7 +120,7 @@ acpi_ex_add_table(u32 table_index,acpi_ns_exec_module_code_list ();acpi_ex_enter_interpreter (); -/* Update GPEs for any new _PRW or _Lxx/_Exx methods. Ignore errors */ +/* Update GPEs for any new _Lxx/_Exx methods. Ignore errors */ status =acpi_tb_get_owner_id (table_index, &owner_id);if (ACPI_SUCCESS (status)) {
include/acpi/acpixf.h +2 -1
@@ -63,7 +63,6 @@ extern u32 acpi_dbg_layer;extern u8 acpi_gbl_enable_interpreter_slack;extern u8 acpi_gbl_all_methods_serialized;extern u8 acpi_gbl_create_osi_method; -extern u8 acpi_gbl_leave_wake_gpes_disabled;extern u8 acpi_gbl_use_default_register_widths;extern acpi_name acpi_gbl_trace_method_name;extern u32 acpi_gbl_trace_flags;
@@ -286,6 +285,8 @@ acpi_status acpi_enable_gpe(acpi_handleacpi_status acpi_disable_gpe (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_gpe_can_wake (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_clear_gpe (acpi_handle gpe_device,u32 gpe_number);acpi_status acpi_gpe_wakeup (acpi_handle gpe_device,u32 gpe_number,u8 action);
drivers/acpi/acpica/acglobal.h +0 -7
@@ -100,13 +100,6 @@ u8 ACPI_INIT_GLOBAL(acpi_gbl_all_methodsu8 ACPI_INIT_GLOBAL (acpi_gbl_create_osi_method ,TRUE );/* -* Disable wakeup GPEs during runtime? Default is TRUE because WAKE and -* RUNTIME GPEs should never be shared, and WAKE GPEs should typically only -* be enabled just before going to sleep. -*/ -u8 ACPI_INIT_GLOBAL (acpi_gbl_leave_wake_gpes_disabled ,TRUE ); - -/* * Optionally use default values for the ACPI register widths. Set this to * TRUE to use the defaults, if an FADT contains incorrect widths/lengths. */
drivers/acpi/osl.c +0 -20
@@ -1064,26 +1064,6 @@ static int __init acpi_serialize_setup(c__setup ("acpi_serialize" , acpi_serialize_setup); -/* -* Wake and Run-Time GPES are expected to be separate. -* We disable wake-GPEs at run-time to prevent spurious -* interrupts. -* -* However, if a system exists that shares Wake and -* Run-time events on the same GPE this flag is available -* to tell Linux to keep the wake-time GPEs enabled at run-time. -*/ -static int __init acpi_wake_gpes_always_on_setup (char *str) -{ - printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); - - acpi_gbl_leave_wake_gpes_disabled = FALSE; - -return 1 ; -} - -__setup ("acpi_wake_gpes_always_on" , acpi_wake_gpes_always_on_setup); -/* Check of resource interference between native drivers and ACPI * OperationRegions (SystemIO and System Memory only). * IO ports and memory declared in ACPI might be used by the ACPI subsystem
PATCH RESEND 2/4 ACPI / ACPICA: Do not execute _PRW methods during initialization
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Currently, during initialization ACPICA walks the entire ACPI namespace in search of any device objects with assciated _PRW methods. All of the _PRW methods found are executed in the process to extract the GPE information returned by them, so that the GPEs in question can be marked as "able to wakeup" (more precisely, the ACPI_GPE_CAN_WAKE flag is set for them). The only purpose of this exercise is to avoid enabling the CAN_WAKE GPEs automatically, even if there are _Lxx/_Exx methods associated with them. However, it is both costly and unnecessary, because the host OS has to execute the _PRW methods anyway to check which devices can wake up the system from sleep states. Moreover, it then uses full information returned by _PRW, including the GPE information, so it can take care of disabling the GPEs if necessary.
Remove the code that walks the namespace and executes _PRW from ACPICA and modify comments to reflect that change. Make acpi_bus_set_run_wake_flags() disable GPEs for wakeup devices so that they don't cause spurious wakeup events to be signaled. This not only reduces the complexity of the ACPICA initialization code, but in some cases it should reduce the kernel boot time as well.
Unfortunately, for this purpose we need a new ACPICA function, acpi_gpe_can_wake(), to be called by the host OS in order to disable the GPEs that can wake up the system and were previously enabled by acpi_ev_initialize_gpe_block() or acpi_ev_update_gpes() (such a GPE should be disabled only once, because the initialization code enables it only once, but it may be pointed to by _PRW for multiple devices and that's why the additional function is necessary).
--- drivers/acpi/acpica/acglobal.h | 7 - drivers/acpi/acpica/evevent.c | 5 drivers/acpi/acpica/evgpeblk.c | 47 -------- drivers/acpi/acpica/evgpeinit.c | 235 ++-------------------------------------- drivers/acpi/acpica/evxfevnt.c | 55 +++++++++ drivers/acpi/acpica/exconfig.c | 2 drivers/acpi/acpica/utxface.c | 8 - drivers/acpi/osl.c | 20 --- drivers/acpi/scan.c | 2 include/acpi/acpixf.h | 3 10 files changed, 85 insertions(+), 299 deletions(-)
drivers/acpi/scan.c +2 -0
@@ -740,6 +740,8 @@ acpi_bus_extract_wakeup_device_power_pac device->wakeup.resources.handles[i] = element->reference.handle; } +acpi_gpe_can_wake (device->wakeup.gpe_device, device->wakeup.gpe_number); +return AE_OK ; }
drivers/acpi/acpica/evgpeinit.c +17 -218
280 lines not on this page · raw message
drivers/acpi/acpica/evgpeblk.c +5 -42
73 lines not on this page · raw message
drivers/acpi/acpica/evxfevnt.c +54 -1
67 lines not on this page · raw message
drivers/acpi/acpica/utxface.c +2 -6
@@ -293,12 +293,8 @@ acpi_status acpi_initialize_objects(u32* Complete the GPE initialization for the GPE blocks defined in the FADT * (GPE block 0 and 1). * -* Note1: This is where the _PRW methods are executed for the GPEs. These -* methods can only be executed after the SCI and Global Lock handlers are -* installed and initialized. -* -* Note2: Currently, there seems to be no need to run the _REG methods -* before execution of the _PRW methods and enabling of the GPEs. +* NOTE: Currently, there seems to be no need to run the _REG methods +* before enabling the GPEs. */ if (!(flags &ACPI_NO_EVENT_INIT )) { status =acpi_ev_install_fadt_gpes ();
drivers/acpi/acpica/evevent.c +2 -3
@@ -102,9 +102,8 @@ acpi_status acpi_ev_initialize_events(vo* RETURN: Status * * DESCRIPTION: Completes initialization of the FADT-defined GPE blocks -* (0 and 1). This causes the _PRW methods to be run, so the HW -* must be fully initialized at this point, including global lock -* support. +* (0 and 1). The HW must be fully initialized at this point, +* including global lock support. * ******************************************************************************/
drivers/acpi/acpica/exconfig.c +1 -1
@@ -120,7 +120,7 @@ acpi_ex_add_table(u32 table_index,acpi_ns_exec_module_code_list ();acpi_ex_enter_interpreter (); -/* Update GPEs for any new _PRW or _Lxx/_Exx methods. Ignore errors */ +/* Update GPEs for any new _Lxx/_Exx methods. Ignore errors */ status =acpi_tb_get_owner_id (table_index, &owner_id);if (ACPI_SUCCESS (status)) {
include/acpi/acpixf.h +2 -1
@@ -63,7 +63,6 @@ extern u32 acpi_dbg_layer;extern u8 acpi_gbl_enable_interpreter_slack;extern u8 acpi_gbl_all_methods_serialized;extern u8 acpi_gbl_create_osi_method; -extern u8 acpi_gbl_leave_wake_gpes_disabled;extern u8 acpi_gbl_use_default_register_widths;extern acpi_name acpi_gbl_trace_method_name;extern u32 acpi_gbl_trace_flags;
@@ -286,6 +285,8 @@ acpi_status acpi_enable_gpe(acpi_handleacpi_status acpi_disable_gpe (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_gpe_can_wake (acpi_handle gpe_device,u32 gpe_number); +acpi_status acpi_clear_gpe (acpi_handle gpe_device,u32 gpe_number);acpi_status acpi_gpe_wakeup (acpi_handle gpe_device,u32 gpe_number,u8 action);
drivers/acpi/acpica/acglobal.h +0 -7
@@ -100,13 +100,6 @@ u8 ACPI_INIT_GLOBAL(acpi_gbl_all_methodsu8 ACPI_INIT_GLOBAL (acpi_gbl_create_osi_method ,TRUE );/* -* Disable wakeup GPEs during runtime? Default is TRUE because WAKE and -* RUNTIME GPEs should never be shared, and WAKE GPEs should typically only -* be enabled just before going to sleep. -*/ -u8 ACPI_INIT_GLOBAL (acpi_gbl_leave_wake_gpes_disabled ,TRUE ); - -/* * Optionally use default values for the ACPI register widths. Set this to * TRUE to use the defaults, if an FADT contains incorrect widths/lengths. */
drivers/acpi/osl.c +0 -20
@@ -1064,26 +1064,6 @@ static int __init acpi_serialize_setup(c__setup ("acpi_serialize" , acpi_serialize_setup); -/* -* Wake and Run-Time GPES are expected to be separate. -* We disable wake-GPEs at run-time to prevent spurious -* interrupts. -* -* However, if a system exists that shares Wake and -* Run-time events on the same GPE this flag is available -* to tell Linux to keep the wake-time GPEs enabled at run-time. -*/ -static int __init acpi_wake_gpes_always_on_setup (char *str) -{ - printk(KERN_INFO PREFIX "wake GPEs not disabled\n"); - - acpi_gbl_leave_wake_gpes_disabled = FALSE; - -return 1 ; -} - -__setup ("acpi_wake_gpes_always_on" , acpi_wake_gpes_always_on_setup); -/* Check of resource interference between native drivers and ACPI * OperationRegions (SystemIO and System Memory only). * IO ports and memory declared in ACPI might be used by the ACPI subsystem
PATCH RESEND 3/4 ACPI / ACPICA: Simplify acpi_ev_initialize_gpe_block()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Simplify the main loop in acpi_ev_initialize_gpe_block() by rearranging code and removing the "enabled" label that is not necessary any more.
--- drivers/acpi/acpica/evgpeblk.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/acpi/acpica/evgpeblk.c +8 -13
@@ -472,26 +472,21 @@ acpi_ev_initialize_gpe_block(struct acpi gpe_event_info = &gpe_block->event_info[gpe_index]; gpe_number = gpe_index + gpe_block->block_base_number; -/* -* If the GPE has already been enabled for runtime -* signaling, make sure it remains enabled, but do not -* increment its reference counter. -*/ -if (gpe_event_info->runtime_count) { - status =acpi_ev_enable_gpe (gpe_event_info); - goto enabled; - } -/* Ignore GPEs that have no corresponding _Lxx/_Exx method */ if (!(gpe_event_info->flags &ACPI_GPE_DISPATCH_METHOD )) {continue ; } -/* Enable this GPE */ +/* +* If the GPE has already been enabled for runtime +* signaling, make sure it remains enabled, but do not +* increment its reference counter. +*/ + status = gpe_event_info->runtime_count ? +acpi_ev_enable_gpe (gpe_event_info) : +acpi_enable_gpe (gpe_device, gpe_number); - status =acpi_enable_gpe (gpe_device, gpe_number); - enabled:if (ACPI_FAILURE (status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not enable GPE 0x%02X",
PATCH RESEND 3/4 ACPI / ACPICA: Simplify acpi_ev_initialize_gpe_block()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Simplify the main loop in acpi_ev_initialize_gpe_block() by rearranging code and removing the "enabled" label that is not necessary any more.
--- drivers/acpi/acpica/evgpeblk.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/acpi/acpica/evgpeblk.c +8 -13
@@ -472,26 +472,21 @@ acpi_ev_initialize_gpe_block(struct acpi gpe_event_info = &gpe_block->event_info[gpe_index]; gpe_number = gpe_index + gpe_block->block_base_number; -/* -* If the GPE has already been enabled for runtime -* signaling, make sure it remains enabled, but do not -* increment its reference counter. -*/ -if (gpe_event_info->runtime_count) { - status =acpi_ev_enable_gpe (gpe_event_info); - goto enabled; - } -/* Ignore GPEs that have no corresponding _Lxx/_Exx method */ if (!(gpe_event_info->flags &ACPI_GPE_DISPATCH_METHOD )) {continue ; } -/* Enable this GPE */ +/* +* If the GPE has already been enabled for runtime +* signaling, make sure it remains enabled, but do not +* increment its reference counter. +*/ + status = gpe_event_info->runtime_count ? +acpi_ev_enable_gpe (gpe_event_info) : +acpi_enable_gpe (gpe_device, gpe_number); - status =acpi_enable_gpe (gpe_device, gpe_number); - enabled:if (ACPI_FAILURE (status)) { ACPI_EXCEPTION((AE_INFO, status, "Could not enable GPE 0x%02X",
PATCH RESEND 4/4 ACPI / ACPICA: Fail acpi_gpe_wakeup() if ACPI_GPE_CAN_WAKE is unset
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Make acpi_gpe_wakeup() return error code for GPEs whose ACPI_GPE_CAN_WAKE flag is not set. This way acpi_gpe_wakeup() will only wake for the GPEs reported by the host OS as "wakeup" ones with the help of acpi_gpe_can_wake().
--- drivers/acpi/acpica/evxfevnt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/evxfevnt.c +1 -1
@@ -239,7 +239,7 @@ acpi_status acpi_gpe_wakeup(acpi_handle/* Ensure that we have a valid GPE number */ gpe_event_info =acpi_ev_get_gpe_event_info (gpe_device, gpe_number); -if (!gpe_event_info) { +if (!gpe_event_info || !(gpe_event_info->flags &ACPI_GPE_CAN_WAKE )) { status =AE_BAD_PARAMETER ; goto unlock_and_exit; }
PATCH RESEND 4/4 ACPI / ACPICA: Fail acpi_gpe_wakeup() if ACPI_GPE_CAN_WAKE is unset
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Make acpi_gpe_wakeup() return error code for GPEs whose ACPI_GPE_CAN_WAKE flag is not set. This way acpi_gpe_wakeup() will only wake for the GPEs reported by the host OS as "wakeup" ones with the help of acpi_gpe_can_wake().
--- drivers/acpi/acpica/evxfevnt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/evxfevnt.c +1 -1
@@ -239,7 +239,7 @@ acpi_status acpi_gpe_wakeup(acpi_handle/* Ensure that we have a valid GPE number */ gpe_event_info =acpi_ev_get_gpe_event_info (gpe_device, gpe_number); -if (!gpe_event_info) { +if (!gpe_event_info || !(gpe_event_info->flags &ACPI_GPE_CAN_WAKE )) { status =AE_BAD_PARAMETER ; goto unlock_and_exit; }
Len Brown
reviewerQuoted 3 lines
[3/4] - Simplifies code in
acpi_ev_initialize_gpe_block(), which only is a
cosmetic thing, but worth doing IMO.
FYI, this one had a white-space issue on the line with the "enabled:" label -- the patch was missing some tabs and spaces that were in the tree; but that was the only problem with it.
Quoted 1 line
Please apply.
done.
thanks,
-Len Brown, Intel Open Source Technology Center
Len Brown
reviewerQuoted 3 lines
[3/4] - Simplifies code in
acpi_ev_initialize_gpe_block(), which only is a
cosmetic thing, but worth doing IMO.
FYI, this one had a white-space issue on the line with the "enabled:" label -- the patch was missing some tabs and spaces that were in the tree; but that was the only problem with it.
Quoted 1 line
Please apply.
done.
thanks,
-Len Brown, Intel Open Source Technology Center
Quoted 9 lines · Len Brown
Quoted 3 lines
[3/4] - Simplifies code in
acpi_ev_initialize_gpe_block(), which only is a
cosmetic thing, but worth doing IMO.FYI, this one had a white-space issue on the line with the "enabled:" label -- the patch was missing some tabs and spaces that were in the tree; but that was the only problem with it.
Quoted 1 line
Please apply.
Thanks!
Rafael
Quoted 9 lines · Len Brown
Quoted 3 lines
[3/4] - Simplifies code in
acpi_ev_initialize_gpe_block(), which only is a
cosmetic thing, but worth doing IMO.FYI, this one had a white-space issue on the line with the "enabled:" label -- the patch was missing some tabs and spaces that were in the tree; but that was the only problem with it.
Quoted 1 line
Please apply.
Thanks!
Rafael