ACPI[CA]: fix ECDT EC probe ordering issues
Subsystems (2)
cover ACPI[CA]: fix ECDT EC probe ordering issues
Hi All,
This series fixes some ECDT EC probe ordering issues which are causing issues om some laptops:
https://bugzilla.kernel.org/show_bug.cgi?id=214899
https://bugzilla.redhat.com/show_bug.cgi?id=1842039
This is a RFC because fixing this requires some ACPICA changes which obviously need to go upstream through the ACPICA project. But first I wanted to try and get some general feedback on the chosen approach.
The problem this fixed is best described by the commit message of patch 4:
ACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So acpi_bus_init() calls acpi_ec_ecdt_probe(), which calls acpi_install_address_space_handler() to install the EC's OpRegion handler, early on.
This not only installs the OpRegion handler, but also calls the EC's _REG method. The _REG method call is a problem because it may rely on initialization done by the _INI methods of one of the PCI / _SB root devs, see for example: https://bugzilla.kernel.org/show_bug.cgi?id=214899 .
This _REG depends on _INI problem can be fixed by calling the new ACPICA acpi_early_initialize_objects() function before acpi_ec_ecdt_probe().
But on some boards (e.g. Lenovo X1C8) the root devices _INI method relies on the EC OpRegion so executing the _INI methods before registering the EC OpRegion handler leads to errors there.
To allow fixing this the ACPICA code now allows to do the OpRegion handler installation early on (without calling _REG) and to do the EC's _REG execution later on as a separate step.
This commit uses this new ACPICA functions to fix the EC probe ordering by changing the acpi_bus_init() initialization order to this:
1. acpi_load_tables()
2. acpi_ec_ecdt_probe()
This now calls acpi_install_address_space_handler(ACPI_NO_EXEC__REG) which installs the OpRegion handler without executing _REG
3. acpi_enable_subsystem()
4. acpi_early_initialize_objects()
This calls the _INI method of the PCI and _SB root devices
5. acpi_ec_ecdt_exec_reg();
This executes the EC's _REG now that the root devices _INI has run
6. acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)
This allows the EC's _REG method to depend on e.g. the \OSYS global/GVNS variable often set by a root-device's _INI method, while at the same time allowing these _INI methods to access EmbeddedController OpRegions.
Regards,
Hans
Hans de Goede (4):
ACPICA: Add an acpi_early_initialize_objects() helper
ACPICA: Add \_SB.PC00, \SB.PCI0 to acpi_ns_early_initialize_devices()
ACPICA: Make address-space-handler install and _REG execution 2
separate steps
ACPI: fix ECDT EC probe ordering issues
drivers/acpi/acpica/acnamesp.h | 2 + drivers/acpi/acpica/evxfregn.c | 32 ++++--- drivers/acpi/acpica/nsinit.c | 170 ++++++++++++++++++++------------- drivers/acpi/acpica/utxfinit.c | 21 ++++ drivers/acpi/bus.c | 19 +++- drivers/acpi/ec.c | 38 ++++++-- drivers/acpi/internal.h | 1 + include/acpi/acpixf.h | 35 +++++-- include/acpi/actypes.h | 5 +- 9 files changed, 223 insertions(+), 100 deletions(-)
Signature · 1 line
2.36.0
RFC 1/4 ACPICA: Add an acpi_early_initialize_objects() helper
acpi_initialize_objects() calls \_INI and \_SB.INI before executing _REG OpRegion methods, because the _REG methods may rely on initialization done by these _INI methods.
ACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So the OS must probe the ECDT described EC early on and ends up calling the EC's _REG method before calling acpi_initialize_objects().
This may lead to the EC _REG method not working properly e.g. on a "Lenovo IdeaPad 5 15ITL05" \_SB.PC00.LPCB.EC0._REG gets evaluated before \_SB.PC00._INI and that _REG contains:
If ((OSYS == 0x07DF))
{
Local0 = 0x06
}
If ((Acquire (LFCM, 0xA000) == Zero))
{
OSTY = Local0
...With OSTY being a SystemMemory OpRegion field, due to the _INI running too late, Local0 stays at 0. Causing OSTY to be set to 0 instead of 6, which causes the brightness up/down keys to not work, see:
https://bugzilla.kernel.org/show_bug.cgi?id=214899
Factor out the early (root) object _INI calls into a new acpi_early_initialize_objects() helper. The OS code can then call this before executing the EC's _REG method so that it will work properly.
Note that if the OS code uses acpi_early_initialize_objects(), then it must also pass the new ACPI_NO_EARLY_DEVICE_INIT flag to acpi_initialize_objects() to avoid the _INI methods getting evaluated twice.
Without this flag acpi_initialize_objects() will still do the early object _INI calls as before. So by itself this patch does not cause any functional changes.
--- drivers/acpi/acpica/acnamesp.h | 2 + drivers/acpi/acpica/nsinit.c | 166 ++++++++++++++++++++------------- drivers/acpi/acpica/utxfinit.c | 21 +++++ include/acpi/acpixf.h | 2 + include/acpi/actypes.h | 3 +- 5 files changed, 127 insertions(+), 67 deletions(-)
drivers/acpi/acpica/acnamesp.h +2 -0
@@ -56,6 +56,8 @@*/ acpi_status acpi_ns_initialize_objects (void ); +acpi_status acpi_ns_early_initialize_devices (void ); +acpi_status acpi_ns_initialize_devices (u32 flags); acpi_status
drivers/acpi/acpica/nsinit.c +100 -66
200 lines not on this page · raw message
drivers/acpi/acpica/utxfinit.c +21 -0
@@ -193,6 +193,27 @@ acpi_status ACPI_INIT_FUNCTION acpi_enable_subsystem(u32 flags)ACPI_EXPORT_SYMBOL_INIT (acpi_enable_subsystem) +/******************************************************************************* +* +* FUNCTION: acpi_early_initialize_objects +* +* PARAMETERS: None +* +* RETURN: Status +* +* DESCRIPTION: Call _INI on various root objects, this must be done before +* any other AML evaluations as those might depend on this. +* This is automatically called by acpi_initialize_objects(), +* unless ACPI_NO_EARLY_DEVICE_INIT is passed. +* +******************************************************************************/ +acpi_status ACPI_INIT_FUNCTION acpi_early_initialize_objects(void) +{ +return acpi_ns_early_initialize_devices (); +} + +ACPI_EXPORT_SYMBOL_INIT (acpi_early_initialize_objects) +/******************************************************************************* * * FUNCTION: acpi_initialize_objects
include/acpi/acpixf.h +2 -0
@@ -410,6 +410,8 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION acpi_initialize_subsystem(void)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION acpi_enable_subsystem(u32 flags)) +ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION + acpi_early_initialize_objects(void)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION acpi_initialize_objects(u32 flags)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status ACPI_INIT_FUNCTION
include/acpi/actypes.h +2 -1
@@ -565,7 +565,8 @@ typedef u64 acpi_integer;#define ACPI_NO_HANDLER_INIT 0x0010#define ACPI_NO_OBJECT_INIT 0x0020#define ACPI_NO_DEVICE_INIT 0x0040 -#define ACPI_NO_ADDRESS_SPACE_INIT 0x0080 +#define ACPI_NO_EARLY_DEVICE_INIT 0x0080 +#define ACPI_NO_ADDRESS_SPACE_INIT 0x0100/* * Initialization state
Signature · 1 line
2.36.0
RFC 2/4 ACPICA: Add \_SB.PC00, \SB.PCI0 to acpi_ns_early_initialize_devices()
In reply to Hans de GoedeSince ACPICA commit f005ee6b90d1 / Linux commit 2d3349de8072 ("ACPICA: Namespace: Reorder \_SB._INI to make sure it is evaluated before _REG evaluations") acpi_initialize_objects() calls \_SB._INI before executing _REG OpRegion methods, because the _REG methods may rely on initialization done by this _INI method.
In many DSDTs the \_SB.PC00._INI / \_SB.PCI0._INI methods set an OSYS global variable based on _OSI evaluations.
In some cases there are _REG methods which depend on the OSYS value and before this change ACPICA would run these _REG methods before running _SB.PC00._INI / \_SB.PCI0._INI causing issues.
2 examples of problems caused by running _REG methods before these _INI methods are:
1. on a "Lenovo IdeaPad 5 15ITL05" \_SB.PC00.LPCB.EC0._REG gets evaluated before \_SB.PC00._INI and that _REG contains:
If ((OSYS == 0x07DF))
{
Local0 = 0x06
}
If ((Acquire (LFCM, 0xA000) == Zero))
{
OSTY = Local0
...With OSTY being a SystemMemory OpRegion field, due to the _INI running too late, Local0 stays at 0. Causing OSTY to be set to 0 instead of 6, which causes the brightness up/down keys to not work:
https://bugzilla.kernel.org/show_bug.cgi?id=214899
2. On a "Lenovo Thinkbook 14-ILL" \\_SB_.PCI0.I2C0._REG gets evaluated before \_SB.PCI0._INI and that _REG contains:
If ((OSYS == 0x07DF))
{
...
LNUX = Zero
TPID = 0x4E
}
else
{
LNUX = One
TPID = 0xBB
}And then later on the TPID value gets used to decide for which of multiple devices describing the touchpad _STA should return 0xF and the one which gets enabled by TPID=0xBB is broken, causing to the touchpad to not work:
https://bugzilla.redhat.com/show_bug.cgi?id=1842039
Fix these issues by adding \_SB.PC00._INI / \_SB.PCI0._INI to the list of _INI methods to run early (before executing _REG methods).
--- drivers/acpi/acpica/nsinit.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/acpi/acpica/nsinit.c +5 -1
@@ -105,6 +105,10 @@ static acpi_string const acpi_ns_early_init_paths[] = {/* There appears to be a strict order requirement for \_SB._INI, * which should be evaluated before any _REG evaluations. */ "\\_SB" , +/* \_SB.PC00._INI or \_SB.PCI0.INI may use \_OSI to set an OSYS global +* variable used in _REG methods. */ +"\\_SB.PC00" , + "\\_SB.PCI0", };acpi_status acpi_ns_early_initialize_devices (void )
@@ -519,7 +523,7 @@ acpi_ns_find_ini_methods(acpi_handle obj_handle,static u8 acpi_ns_is_early_init_device (struct acpi_namespace_node *device_node) { -char path[ACPI_PATH_SEGMENT_LENGTH +2 ]; +char path[ACPI_PATH_SEGMENT_LENGTH *2 +2 ];int i;acpi_ns_build_normalized_path (device_node, path,sizeof (path), TRUE);
Signature · 1 line
2.36.0
Andy Shevchenko
[Devel] Re: [RFC 2/4] ACPICA: Add \_SB.PC00, \SB.PCI0 to acpi_ns_early_initialize_devices()
Quoted 57 lines · Hans de Goede
Since ACPICA commit
f005ee6b90d1/ Linux commit2d3349de8072("ACPICA: Namespace: Reorder \_SB._INI to make sure it is evaluated before_REGevaluations")acpi_initialize_objects()calls \_SB._INI before executing_REGOpRegion methods, because the_REGmethods may rely on initialization done by this_INImethod.In many DSDTs the \_SB.PC00._INI / \_SB.PCI0._INI methods set an OSYS global variable based on
_OSIevaluations.In some cases there are
_REGmethods which depend on the OSYS value and before this change ACPICA would run these_REGmethods before running _SB.PC00._INI / \_SB.PCI0._INI causing issues.2 examples of problems caused by running
_REGmethods before these_INImethods are:1. on a "Lenovo IdeaPad 5 15ITL05" \_SB.PC00.LPCB.EC0._REG gets evaluated before \_SB.PC00._INI and that
_REGcontains:If ((OSYS == 0x07DF)) { Local0 = 0x06 } If ((Acquire (LFCM, 0xA000) == Zero)) { OSTY = Local0 ...With OSTY being a SystemMemory OpRegion field, due to the
_INIrunning too late, Local0 stays at 0. Causing OSTY to be set to 0 instead of 6, which causes the brightness up/down keys to not work:
https://bugzilla.kernel.org/show_bug.cgi?id=2148992. On a "Lenovo Thinkbook 14-ILL" \\_SB_.PCI0.I2C0._REG gets evaluated before \_SB.PCI0._INI and that
_REGcontains:If ((OSYS == 0x07DF)) { ... LNUX = Zero TPID = 0x4E } else { LNUX = One TPID = 0xBB }And then later on the TPID value gets used to decide for which of multiple devices describing the touchpad
_STAshould return0xFand the one which gets enabled by TPID=0xBB is broken, causing to the touchpad to not work:
https://bugzilla.redhat.com/show_bug.cgi?id=1842039Fix these issues by adding \_SB.PC00._INI / \_SB.PCI0._INI to the list of
_INImethods to run early (before executing_REGmethods).
...
drivers/acpi/acpica/nsinit.c acpi_ns_find_ini_methods(acpi_handle obj_handle, · line 526
Quoted 2 lines
drivers/acpi/acpica/nsinit.c +1
-1-char path[ACPI_PATH_SEGMENT_LENGTH +2 ]; +char path[ACPI_PATH_SEGMENT_LENGTH *2 +2 ];
Strictly speaking this should be, IIUC,
1 + ACPI_PATH_SEGMENT_LENGTH + ACPI_NAMESEG_SIZE + 1
\\ + path segment length (with a separator) + name + \0
That said, it seems the original code adds 1 unneeded byte.
Perhaps a comment in the code?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC 2/4] ACPICA: Add \_SB.PC00, \SB.PCI0 to acpi_ns_early_initialize_devices()
Hi,
Quoted 64 lines · Andy Shevchenko
Quoted 57 lines · Hans de Goede
Since ACPICA commit
f005ee6b90d1/ Linux commit2d3349de8072("ACPICA: Namespace: Reorder \_SB._INI to make sure it is evaluated before_REGevaluations")acpi_initialize_objects()calls \_SB._INI before executing_REGOpRegion methods, because the_REGmethods may rely on initialization done by this_INImethod.In many DSDTs the \_SB.PC00._INI / \_SB.PCI0._INI methods set an OSYS global variable based on
_OSIevaluations.In some cases there are
_REGmethods which depend on the OSYS value and before this change ACPICA would run these_REGmethods before running _SB.PC00._INI / \_SB.PCI0._INI causing issues.2 examples of problems caused by running
_REGmethods before these_INImethods are:1. on a "Lenovo IdeaPad 5 15ITL05" \_SB.PC00.LPCB.EC0._REG gets evaluated before \_SB.PC00._INI and that
_REGcontains:If ((OSYS == 0x07DF)) { Local0 = 0x06 } If ((Acquire (LFCM, 0xA000) == Zero)) { OSTY = Local0 ...With OSTY being a SystemMemory OpRegion field, due to the
_INIrunning too late, Local0 stays at 0. Causing OSTY to be set to 0 instead of 6, which causes the brightness up/down keys to not work:
https://bugzilla.kernel.org/show_bug.cgi?id=2148992. On a "Lenovo Thinkbook 14-ILL" \\_SB_.PCI0.I2C0._REG gets evaluated before \_SB.PCI0._INI and that
_REGcontains:If ((OSYS == 0x07DF)) { ... LNUX = Zero TPID = 0x4E } else { LNUX = One TPID = 0xBB }And then later on the TPID value gets used to decide for which of multiple devices describing the touchpad
_STAshould return0xFand the one which gets enabled by TPID=0xBB is broken, causing to the touchpad to not work:
https://bugzilla.redhat.com/show_bug.cgi?id=1842039Fix these issues by adding \_SB.PC00._INI / \_SB.PCI0._INI to the list of
_INImethods to run early (before executing_REGmethods)....
drivers/acpi/acpica/nsinit.c acpi_ns_find_ini_methods(acpi_handle obj_handle, · line 526
Quoted 2 lines
drivers/acpi/acpica/nsinit.c +1
-1-char path[ACPI_PATH_SEGMENT_LENGTH +2 ]; +char path[ACPI_PATH_SEGMENT_LENGTH *2 +2 ];
Quoted 7 lines
Strictly speaking this should be, IIUC,
1 +
ACPI_PATH_SEGMENT_LENGTH+ACPI_NAMESEG_SIZE+ 1\\ + path segment length (with a separator) + name + \0
That said, it seems the original code adds 1 unneeded byte.
Right I already knew I needed the " * 2" when writing the original code, so I decided to do things this way for KISS reasons.
Quoted 1 line
Perhaps a comment in the code?
I've added a comment to my local version now.
After this thread has had some more time to gather feedback I will turn the ACPICA patches into a acpica github pull-req with the comment added.
(or if necessary rework the entire series)
Regards,
Hans
Andy Shevchenko
[Devel] Re: [RFC 2/4] ACPICA: Add \_SB.PC00, \SB.PCI0 to acpi_ns_early_initialize_devices()
Quoted 2 lines · Hans de Goede
Quoted 1 line · Andy Shevchenko
On Wed, Jun 15, 2022 at 9:57 PM Hans de Goede <hdegoede(a)redhat.com> wrote:
...
Quoted 7 lines
Quoted 7 lines
drivers/acpi/acpica/nsinit.c acpi_ns_find_ini_methods(acpi_handle obj_handle, · line 526
Quoted 2 lines
drivers/acpi/acpica/nsinit.c +1
-1-char path[ACPI_PATH_SEGMENT_LENGTH +2 ]; +char path[ACPI_PATH_SEGMENT_LENGTH *2 +2 ];Strictly speaking this should be, IIUC,
1 +
ACPI_PATH_SEGMENT_LENGTH+ACPI_NAMESEG_SIZE+ 1
Quoted 7 lines
Quoted 3 lines
\\ + path segment length (with a separator) + name + \0
That said, it seems the original code adds 1 unneeded byte.
Right I already knew I needed the " * 2" when writing the original code, so I decided to do things this way for KISS reasons.
Yeah, but then you don't need + 2, it should be +1. I believe the initial use of ACPI_PATH_SEGMENT_LENGTH vs. ACPI_NAMESEG_SIZE is a bit misleading.
Quoted 9 lines
Quoted 1 line
Perhaps a comment in the code?
I've added a comment to my local version now.
After this thread has had some more time to gather feedback I will turn the ACPICA patches into a acpica github pull-req with the comment added.
(or if necessary rework the entire series)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC 2/4] ACPICA: Add \_SB.PC00, \SB.PCI0 to acpi_ns_early_initialize_devices()
Hi,
Quoted 17 lines · Andy Shevchenko
Quoted 2 lines · Hans de Goede
Quoted 1 line · Andy Shevchenko
On Wed, Jun 15, 2022 at 9:57 PM Hans de Goede <[email protected]> wrote:
...
Quoted 11 lines
Quoted 10 lines
drivers/acpi/acpica/nsinit.c acpi_ns_find_ini_methods(acpi_handle obj_handle, · line 526
Quoted 2 lines
drivers/acpi/acpica/nsinit.c +1
-1-char path[ACPI_PATH_SEGMENT_LENGTH +2 ]; +char path[ACPI_PATH_SEGMENT_LENGTH *2 +2 ];Strictly speaking this should be, IIUC,
1 +
ACPI_PATH_SEGMENT_LENGTH+ACPI_NAMESEG_SIZE+ 1\\ + path segment length (with a separator) + name + \0
That said, it seems the original code adds 1 unneeded byte.
Quoted 7 lines
Quoted 3 lines
Right I already knew I needed the " * 2" when writing the original code, so I decided to do things this way for KISS reasons.
Yeah, but then you don't need + 2, it should be +1. I believe the initial use of
ACPI_PATH_SEGMENT_LENGTHvs.ACPI_NAMESEG_SIZEis a bit misleading.
You are technicaly correct, but the code is IMHO just easier to read like this:
char path[ACPI_PATH_SEGMENT_LENGTH * 2 + 2];
Then like this:
char path[1 + ACPI_NAMESEG_SIZE + ACPI_PATH_SEGMENT_LENGT + 1];
And also to be more technically correct it would need to be:
char path[1 + strlen("_SB") + ACPI_PATH_SEGMENT_LENGT + 1];
Since "_SB" only uses 3 of the 4 bytes in ACPI_NAMESEG_SIZE, so that would save us not 1 but 2 bytes on the stack.
But those 2 stack bytes are really not worth the worse readability of these options IMHO.
Regards,
Hans
Quoted 12 lines
Quoted 10 lines
Quoted 2 lines
Perhaps a comment in the code?
I've added a comment to my local version now.
After this thread has had some more time to gather feedback I will turn the ACPICA patches into a acpica github pull-req with the comment added.
(or if necessary rework the entire series)
RFC 3/4 ACPICA: Make address-space-handler install and _REG execution 2 separate steps
In reply to Hans de GoedeACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So the OS must probe the ECDT described EC and install the OpRegion handler before calling acpi_enable_subsystem() and acpi_initialize_objects().
This is a problem because calling acpi_install_address_space_handler() does not just install the OpRegion handler, it also runs the EC's _REG method. This _REG method may rely on initialization done by the _INI methods of one of the PCI / _SB root devices.
This _REG depends on _INI problem can be fixed by calling the new acpi_early_initialize_objects() function before probing the EC. But on some boards (e.g. Lenovo X1C8) the root devices _INI method relies on the EC OpRegion so executing the _INI methods before registering the EC OpRegion handler leads to errors there.
For the default OpRegion handlers the ACPICA code solves these ordering issues by splitting the Opregion handler install and the _REG execution into 2 separate steps:
1. acpi_ev_install_region_handlers(), called early from acpi_load_tables()
2. acpi_ev_initialize_op_regions(), called from acpi_initialize_objects()
To fix the similar EC OpRegion issues, add a new flags parameter to acpi_install_address_space_handler() to allow doing things in 2 steps for the EC OpRegion handler too.
This will allow using the following initialization order to fix things:
1. acpi_load_tables()
2. probe EC, call acpi_install_address_space_handler(ACPI_NO_EXEC__REG)
3. acpi_enable_subsystem()
4. acpi_early_initialize_objects()
5. call acpi_install_address_space_handler(ACPI_NO_INSTALL_SPACE_HANDLER) to run the EC's _REG method
6. acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)
To avoid having to modify all acpi_install_address_space_handler() callers, the function is renamed to acpi_install_address_space_handler_flags() and a static inline acpi_install_address_space_handler() is provided.
--- drivers/acpi/acpica/evxfregn.c | 32 +++++++++++++++++++------------- include/acpi/acpixf.h | 33 ++++++++++++++++++++++++--------- include/acpi/actypes.h | 2 ++ 3 files changed, 45 insertions(+), 22 deletions(-)
drivers/acpi/acpica/evxfregn.c +19 -13
@@ -27,6 +27,7 @@ ACPI_MODULE_NAME("evxfregn")* handler - Address of the handler * setup - Address of the setup function * context - Value passed to the handler on each access +* flags - Flags * * RETURN: Status *
@@ -37,13 +38,18 @@ ACPI_MODULE_NAME("evxfregn")* are executed here, and these methods can only be safely executed after * the default handlers have been installed and the hardware has been * initialized (via acpi_enable_subsystem.) +* To avoid this problem pass the ACPI_NO_EXEC__REG flag and +* later call this function again with ACPI_NO_INSTALL_SPACE_HANDLER to +* execute _REG. * ******************************************************************************/ acpi_status -acpi_install_address_space_handler (acpi_handle device, -acpi_adr_space_type space_id, -acpi_adr_space_handler handler, -acpi_adr_space_setup setup,void *context) +acpi_install_address_space_handler_flags (acpi_handle device, +acpi_adr_space_type space_id, +acpi_adr_space_handler handler, +acpi_adr_space_setup setup, +void *context, +u32 flags) {struct acpi_namespace_node *node;acpi_status status;
@@ -70,24 +76,24 @@ acpi_install_address_space_handler(acpi_handle device, }/* Install the handler for all Regions for this Space ID */ - - status = -acpi_ev_install_space_handler (node, space_id, handler, setup, - context); -if (ACPI_FAILURE (status)) { - goto unlock_and_exit; +if (!(flags &ACPI_NO_INSTALL_SPACE_HANDLER )) { + status = +acpi_ev_install_space_handler (node, space_id, handler, setup, + context); +if (ACPI_FAILURE (status)) + goto unlock_and_exit; }/* Run all _REG methods for this address space */ - -acpi_ev_execute_reg_methods (node, space_id,ACPI_REG_CONNECT ); +if (!(flags &ACPI_NO_EXEC__REG )) +acpi_ev_execute_reg_methods (node, space_id,ACPI_REG_CONNECT ); unlock_and_exit: (void )acpi_ut_release_mutex (ACPI_MTX_NAMESPACE );return_ACPI_STATUS (status); } -ACPI_EXPORT_SYMBOL (acpi_install_address_space_handler) +ACPI_EXPORT_SYMBOL (acpi_install_address_space_handler_flags)/******************************************************************************* *
include/acpi/acpixf.h +24 -9
@@ -645,15 +645,30 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_statusacpi_notify_handler handler))ACPI_EXTERNAL_RETURN_STATUS (acpi_status - acpi_install_address_space_handler(acpi_handle - device, - acpi_adr_space_type - space_id, - acpi_adr_space_handler - handler, - acpi_adr_space_setup - setup, - void *context)) +acpi_install_address_space_handler_flags (acpi_handle + device, +acpi_adr_space_type + space_id, +acpi_adr_space_handler + handler, +acpi_adr_space_setup + setup, +void *context, +u32 flags)) +staticACPI_INLINE acpi_statusacpi_install_address_space_handler (acpi_handle + device, + acpi_adr_space_type + space_id, + acpi_adr_space_handler + handler, + acpi_adr_space_setup + setup, + void *context) +{ +return acpi_install_address_space_handler_flags ( + device, space_id, handler, setup, context, +ACPI_FULL_INITIALIZATION ); +} ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_remove_address_space_handler(acpi_handle device,
include/acpi/actypes.h +2 -0
@@ -567,6 +567,8 @@ typedef u64 acpi_integer;#define ACPI_NO_DEVICE_INIT 0x0040#define ACPI_NO_EARLY_DEVICE_INIT 0x0080#define ACPI_NO_ADDRESS_SPACE_INIT 0x0100 +#define ACPI_NO_INSTALL_SPACE_HANDLER 0x0200 +#define ACPI_NO_EXEC__REG 0x0400/* * Initialization state
Signature · 1 line
2.36.0
RFC 4/4 ACPI: fix ECDT EC probe ordering issues
In reply to Hans de GoedeACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So acpi_bus_init() calls acpi_ec_ecdt_probe(), which calls acpi_install_address_space_handler() to install the EC's OpRegion handler, early on.
This not only installs the OpRegion handler, but also calls the EC's _REG method. The _REG method call is a problem because it may rely on initialization done by the _INI methods of one of the PCI / _SB root devs, see for example: https://bugzilla.kernel.org/show_bug.cgi?id=214899 .
This _REG depends on _INI problem can be fixed by calling the new ACPICA acpi_early_initialize_objects() function before acpi_ec_ecdt_probe().
But on some boards (e.g. Lenovo X1C8) the root devices _INI method relies on the EC OpRegion so executing the _INI methods before registering the EC OpRegion handler leads to errors there.
To allow fixing this the ACPICA code now allows to do the OpRegion handler installation early on (without calling _REG) and to do the EC's _REG execution later on as a separate step.
This commit uses this new ACPICA functions to fix the EC probe ordering by changing the acpi_bus_init() initialization order to this:
1. acpi_load_tables()
2. acpi_ec_ecdt_probe()
This now calls acpi_install_address_space_handler(ACPI_NO_EXEC__REG) which installs the OpRegion handler without executing _REG
3. acpi_enable_subsystem()
4. acpi_early_initialize_objects()
This calls the _INI method of the PCI and _SB root devices
5. acpi_ec_ecdt_exec_reg();
This executes the EC's _REG now that the root devices _INI has run
6. acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)
This allows the EC's _REG method to depend on e.g. the \OSYS global/GVNS variable often set by a root-device's _INI method, while at the same time allowing these _INI methods to access EmbeddedController OpRegions.
--- drivers/acpi/bus.c | 19 ++++++++++++++++++- drivers/acpi/ec.c | 38 ++++++++++++++++++++++++++++---------- drivers/acpi/internal.h | 1 + 3 files changed, 47 insertions(+), 11 deletions(-)
drivers/acpi/bus.c +18 -1
@@ -1303,7 +1303,24 @@ static int __init acpi_bus_init(void) goto error1; } - status =acpi_initialize_objects (ACPI_FULL_INITIALIZATION ); +/* +* This usually sets an OSYS global variable based on _OSI checks, +* and the EC's _REG method may rely on this OSYS variable, so do +* this before acpi_ec_ecdt_exec_reg(). +*/ + status =acpi_early_initialize_objects (); +if (ACPI_FAILURE (status)) { +pr_err ("Unable to do early ACPI objects initialization\n" ); + goto error1; + } + +acpi_ec_ecdt_exec_reg (); + +/* +* ACPI_NO_EARLY_DEVICE_INIT to avoid ACPICA calling +* acpi_early_initialize_objects() a second time. +*/ + status =acpi_initialize_objects (ACPI_NO_EARLY_DEVICE_INIT );if (ACPI_FAILURE (status)) {pr_err ("Unable to initialize ACPI objects\n" ); goto error1;
drivers/acpi/ec.c +28 -10
@@ -1459,6 +1459,7 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec)* ec_install_handlers - Install service callbacks and register query methods. * @ec: Target EC. * @device: ACPI device object corresponding to @ec. +* @flags: Flags to pass to acpi_install_address_space_handler() * * Install a handler for the EC address space type unless it has been installed * already. If @device is not NULL, also look for EC query methods in the
@@ -1471,7 +1472,7 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec)* -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred, * or 0 (success) otherwise. */ -static int ec_install_handlers (struct acpi_ec *ec,struct acpi_device *device) +static int ec_install_handlers (struct acpi_ec *ec,struct acpi_device *device,u32 flags) {acpi_status status;
@@ -1479,10 +1480,10 @@ static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device)if (!test_bit (EC_FLAGS_EC_HANDLER_INSTALLED , &ec->flags)) {acpi_ec_enter_noirq (ec); - status =acpi_install_address_space_handler (ec->handle, -ACPI_ADR_SPACE_EC , - &acpi_ec_space_handler, -NULL , ec); + status =acpi_install_address_space_handler_flags (ec->handle, +ACPI_ADR_SPACE_EC , + &acpi_ec_space_handler, +NULL , ec, flags);if (ACPI_FAILURE (status)) {acpi_ec_stop (ec, false);return -ENODEV ;
@@ -1575,11 +1576,11 @@ static void ec_remove_handlers(struct acpi_ec *ec) } } -static int acpi_ec_setup (struct acpi_ec *ec,struct acpi_device *device) +static int acpi_ec_setup (struct acpi_ec *ec,struct acpi_device *device,u32 flags) {int ret; - ret =ec_install_handlers (ec, device); + ret =ec_install_handlers (ec, device, flags);if (ret)return ret;
@@ -1641,7 +1642,7 @@ static int acpi_ec_add(struct acpi_device *device) } } - ret =acpi_ec_setup (ec, device); + ret =acpi_ec_setup (ec, device,0 );if (ret) goto err;
@@ -1761,7 +1762,7 @@ void __init acpi_ec_dsdt_probe(void)* At this point, the GPE is not fully initialized, so do not to * handle the events. */ - ret =acpi_ec_setup (ec,NULL ); + ret =acpi_ec_setup (ec,NULL ,0 );if (ret) {acpi_ec_free (ec);return ;
@@ -1973,7 +1974,7 @@ void __init acpi_ec_ecdt_probe(void)* At this point, the namespace is not initialized, so do not find * the namespace objects, or handle the events. */ - ret =acpi_ec_setup (ec,NULL ); + ret =acpi_ec_setup (ec,NULL ,ACPI_NO_EXEC__REG );if (ret) {acpi_ec_free (ec); goto out;
@@ -1988,6 +1989,23 @@ void __init acpi_ec_ecdt_probe(void)acpi_put_table ((struct acpi_table_header *)ecdt_ptr); } +void __init acpi_ec_ecdt_exec_reg (void ) +{ +if (!boot_ec || !boot_ec_is_ecdt) +return ; + +/* +* Second call, first call is done in acpi_ec_ecdt_probe(), pass +* ACPI_NO_INSTALL_SPACE_HANDLER so as to only exec _REG now that +* the namespace has been setup. +*/ +acpi_install_address_space_handler_flags (boot_ec->handle, +ACPI_ADR_SPACE_EC , + &acpi_ec_space_handler,NULL , + boot_ec, +ACPI_NO_INSTALL_SPACE_HANDLER ); +} +#ifdef CONFIG_PM_SLEEP static int acpi_ec_suspend (struct device *dev) {
drivers/acpi/internal.h +1 -0
@@ -203,6 +203,7 @@ typedef int (*acpi_ec_query_func) (void *data);void acpi_ec_init (void );void acpi_ec_ecdt_probe (void ); +void acpi_ec_ecdt_exec_reg (void );void acpi_ec_dsdt_probe (void );void acpi_ec_block_transactions (void );void acpi_ec_unblock_transactions (void );
Signature · 1 line
2.36.0
Rafael J. Wysocki
[Devel] Re: [RFC 4/4] ACPI: fix ECDT EC probe ordering issues
First off, thanks for taking care of this issue!
Quoted 5 lines · Hans de Goede
ACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So
acpi_bus_init()callsacpi_ec_ecdt_probe(), which callsacpi_install_address_space_handler()to install the EC's OpRegion handler, early on.
I think that the key question is what Windows does in this respect.
I honestly don't think that it uses an allowlist to early call _INI for a few specific devices.
Quoted 16 lines
This not only installs the OpRegion handler, but also calls the EC's
_REGmethod. The_REGmethod call is a problem because it may rely on initialization done by the_INImethods of one of the PCI /_SBroot devs, see for example: https://bugzilla.kernel.org/show_bug.cgi?id=214899 .This
_REGdepends on_INIproblem can be fixed by calling the new ACPICAacpi_early_initialize_objects()function beforeacpi_ec_ecdt_probe().But on some boards (e.g. Lenovo X1C8) the root devices
_INImethod relies on the EC OpRegion so executing the_INImethods before registering the EC OpRegion handler leads to errors there.To allow fixing this the ACPICA code now allows to do the OpRegion handler installation early on (without calling
_REG) and to do the EC's_REGexecution later on as a separate step.
Quoted 7 lines
This commit uses this new ACPICA functions to fix the EC probe ordering by changing the
acpi_bus_init()initialization order to this:1.
acpi_load_tables()
2.acpi_ec_ecdt_probe()
This now callsacpi_install_address_space_handler(ACPI_NO_EXEC__REG)which installs the OpRegion handler without executing_REG
I'm not sure if installing an opregion without evaluating _REG for it is particularly useful.
No AML should use it before _REG is evaluated anyway.
Quoted 3 lines
3.
acpi_enable_subsystem()
4.acpi_early_initialize_objects()
This calls the_INImethod of the PCI and_SBroot devices
So this is a change in behavior that will affect every system using ACPI on the planet, not just the ones where the problem at hand is present. This appears to be somewhat risky to me.
Quoted 7 lines
5.
acpi_ec_ecdt_exec_reg();
This executes the EC's_REGnow that the root devices_INIhas run
6.acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)This allows the EC's
_REGmethod to depend on e.g. the \OSYS global/GVNS variable often set by a root-device's_INImethod, while at the same time allowing these_INImethods to access EmbeddedController OpRegions.
I'm wondering if it is possible to change the ordering of acpi_ec_ecdt_probe() or the part of it that installs the oprtegion handler to be called later?
Quoted 153 lines
Signed-off-by Hans de Goede <hdegoede(a)redhat.com>--- drivers/acpi/bus.c | 19 ++++++++++++++++++- drivers/acpi/ec.c | 38 ++++++++++++++++++++++++++++---------- drivers/acpi/internal.h | 1 + 3 files changed, 47 insertions(+), 11 deletions(-)drivers/acpi/bus.c +18
-1@@ -1303,7 +1303,24 @@ static int __init acpi_bus_init(void) goto error1; } - status =acpi_initialize_objects (ACPI_FULL_INITIALIZATION ); +/* +* This usually sets an OSYS global variable based on _OSI checks, +* and the EC's _REG method may rely on this OSYS variable, so do +* this before acpi_ec_ecdt_exec_reg(). +*/ + status =acpi_early_initialize_objects (); +if (ACPI_FAILURE (status)) { +pr_err ("Unable to do early ACPI objects initialization\n" ); + goto error1; + } + +acpi_ec_ecdt_exec_reg (); + +/* +* ACPI_NO_EARLY_DEVICE_INIT to avoid ACPICA calling +* acpi_early_initialize_objects() a second time. +*/ + status =acpi_initialize_objects (ACPI_NO_EARLY_DEVICE_INIT );if (ACPI_FAILURE (status)) {pr_err ("Unable to initialize ACPI objects\n" ); goto error1;drivers/acpi/ec.c +28
-10@@ -1459,6 +1459,7 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec)* ec_install_handlers - Install service callbacks and register query methods. * @ec: Target EC. * @device: ACPI device object corresponding to @ec. +* @flags: Flags to pass to acpi_install_address_space_handler() * * Install a handler for the EC address space type unless it has been installed * already. If @device is not NULL, also look for EC query methods in the @@ -1471,7 +1472,7 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec)* -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred, * or 0 (success) otherwise. */ -static int ec_install_handlers (struct acpi_ec *ec,struct acpi_device *device) +static int ec_install_handlers (struct acpi_ec *ec,struct acpi_device *device,u32 flags) {acpi_status status;@@ -1479,10 +1480,10 @@ static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device)if (!test_bit (EC_FLAGS_EC_HANDLER_INSTALLED , &ec->flags)) {acpi_ec_enter_noirq (ec); - status =acpi_install_address_space_handler (ec->handle, -ACPI_ADR_SPACE_EC , - &acpi_ec_space_handler, -NULL , ec); + status =acpi_install_address_space_handler_flags (ec->handle, +ACPI_ADR_SPACE_EC , + &acpi_ec_space_handler, +NULL , ec, flags);if (ACPI_FAILURE (status)) {acpi_ec_stop (ec, false);return -ENODEV ;@@ -1575,11 +1576,11 @@ static void ec_remove_handlers(struct acpi_ec *ec) } } -static int acpi_ec_setup (struct acpi_ec *ec,struct acpi_device *device) +static int acpi_ec_setup (struct acpi_ec *ec,struct acpi_device *device,u32 flags) {int ret; - ret =ec_install_handlers (ec, device); + ret =ec_install_handlers (ec, device, flags);if (ret)return ret;@@ -1641,7 +1642,7 @@ static int acpi_ec_add(struct acpi_device *device) } } - ret =acpi_ec_setup (ec, device); + ret =acpi_ec_setup (ec, device,0 );if (ret) goto err;@@ -1761,7 +1762,7 @@ void __init acpi_ec_dsdt_probe(void)* At this point, the GPE is not fully initialized, so do not to * handle the events. */ - ret =acpi_ec_setup (ec,NULL ); + ret =acpi_ec_setup (ec,NULL ,0 );if (ret) {acpi_ec_free (ec);return ;@@ -1973,7 +1974,7 @@ void __init acpi_ec_ecdt_probe(void)* At this point, the namespace is not initialized, so do not find * the namespace objects, or handle the events. */ - ret =acpi_ec_setup (ec,NULL ); + ret =acpi_ec_setup (ec,NULL ,ACPI_NO_EXEC__REG );if (ret) {acpi_ec_free (ec); goto out;@@ -1988,6 +1989,23 @@ void __init acpi_ec_ecdt_probe(void)acpi_put_table ((struct acpi_table_header *)ecdt_ptr); } +void __init acpi_ec_ecdt_exec_reg (void ) +{ +if (!boot_ec || !boot_ec_is_ecdt) +return ; + +/* +* Second call, first call is done in acpi_ec_ecdt_probe(), pass +* ACPI_NO_INSTALL_SPACE_HANDLER so as to only exec _REG now that +* the namespace has been setup. +*/ +acpi_install_address_space_handler_flags (boot_ec->handle, +ACPI_ADR_SPACE_EC , + &acpi_ec_space_handler,NULL , + boot_ec, +ACPI_NO_INSTALL_SPACE_HANDLER ); +} +#ifdef CONFIG_PM_SLEEP static int acpi_ec_suspend (struct device *dev) {drivers/acpi/internal.h +1
-1@@ -203,6 +203,7 @@ typedef int (*acpi_ec_query_func) (void *data);void acpi_ec_init (void );void acpi_ec_ecdt_probe (void ); +void acpi_ec_ecdt_exec_reg (void );void acpi_ec_dsdt_probe (void );void acpi_ec_block_transactions (void );void acpi_ec_unblock_transactions (void ); --2.36.0
Re: [RFC 4/4] ACPI: fix ECDT EC probe ordering issues
Hi,
Quoted 1 line · Rafael J. Wysocki
First off, thanks for taking care of this issue!
You're welcome.
Quoted 11 lines · Hans de Goede
Quoted 5 lines
ACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So
acpi_bus_init()callsacpi_ec_ecdt_probe(), which callsacpi_install_address_space_handler()to install the EC's OpRegion handler, early on.I think that the key question is what Windows does in this respect.
I honestly don't think that it uses an allowlist to early call
_INIfor a few specific devices.
Right, I guess that windows does things more hierarchicallly first calling \._INI then \._SB._INI and then calling other _INI-s around the time it enters there parts of the ACPI device hierarchy.
I have the feeling that Windows e.g. has the root PCI bridge fully setup before even parsing any ACPI objects under it.
This is quite different from how Linux (or ACPICa for that manner) works. So ATM I believe that the fixed list of object paths to call _INI on early is the best we can do.
Quoted 20 lines
Quoted 20 lines
This not only installs the OpRegion handler, but also calls the EC's
_REGmethod. The_REGmethod call is a problem because it may rely on initialization done by the_INImethods of one of the PCI /_SBroot devs, see for example: https://bugzilla.kernel.org/show_bug.cgi?id=214899 .This
_REGdepends on_INIproblem can be fixed by calling the new ACPICAacpi_early_initialize_objects()function beforeacpi_ec_ecdt_probe().But on some boards (e.g. Lenovo X1C8) the root devices
_INImethod relies on the EC OpRegion so executing the_INImethods before registering the EC OpRegion handler leads to errors there.To allow fixing this the ACPICA code now allows to do the OpRegion handler installation early on (without calling
_REG) and to do the EC's_REGexecution later on as a separate step.This commit uses this new ACPICA functions to fix the EC probe ordering by changing the
acpi_bus_init()initialization order to this:
Quoted 7 lines
Quoted 4 lines
1.
acpi_load_tables()
2.acpi_ec_ecdt_probe()
This now callsacpi_install_address_space_handler(ACPI_NO_EXEC__REG)which installs the OpRegion handler without executing_REGI'm not sure if installing an opregion without evaluating
_REGfor it is particularly useful.
We already do this for the SystemMemory / SystemIO and PCI_Config OpRegions. The handlers for these get installed from acpi_enable_subsystem() and their _REG functions get called later from acpi_initialize_objects().
This patch basically makes the EmbeddedControl OpRegion behave the same and according to the current code:
/*
* ACPI 2.0 requires the EC driver to be loaded and work before the EC
* device is found in the namespace.
*
* This is accomplished by looking for the ECDT table and getting the EC
* parameters out of that.
*
* Do that before calling acpi_initialize_objects() which may trigger EC
* address space accesses.
*/
acpi_ec_ecdt_probe();
This is mandated by ACPI-2.0 which also seems to match my analysis of this problem where on e.g. my Lenovo X1 carbon gen 8 the \_SB.PCI0._INI method uses an EmbeddedControl OpRegion without any _REG related checks.
Quoted 1 line
No AML should use it before
_REGis evaluated anyway.
See above, ACPI 2.x seems to allow this, like how it allows it for SystemIO / SystemMemory / PCI_Config. This seems to be the whole reason why there is a separate table describing the EC (the ECDT) so that the EC can be made available before any parsing of the DSDT has been done.
So we need to have the OpRegion available before running the "early" _INI methods. And because of _REG relying on the OSYS GVNS variable in some cases, which gets set from _INI on the PCI root bridge, that means running _REG after running (some) _INI methods.
Quoted 7 lines
Quoted 3 lines
3.
acpi_enable_subsystem()
4.acpi_early_initialize_objects()
This calls the_INImethod of the PCI and_SBroot devicesSo this is a change in behavior that will affect every system using ACPI on the planet, not just the ones where the problem at hand is present. This appears to be somewhat risky to me.
The ACPICA code already calls \.INI and \_SB._INI at the start of acpi_initialize_objects(), before evalutating any _REG methods, so this call in itself is no a change.
Except that \_SB.PCI0._INI and \_SB.PC0._INI are now also run early (patch 2/4).
Quoted 2 lines
Quoted 2 lines
5.
acpi_ec_ecdt_exec_reg();
This executes the EC's_REGnow that the root devices_INIhas run
This is the actual change moving the calling of _REG for the EC to after the running of the "early" _INI calls.
Quoted 9 lines
Quoted 5 lines
6.
acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)This allows the EC's
_REGmethod to depend on e.g. the \OSYS global/GVNS variable often set by a root-device's_INImethod, while at the same time allowing these_INImethods to access EmbeddedController OpRegions.I'm wondering if it is possible to change the ordering of
acpi_ec_ecdt_probe()or the part of it that installs the oprtegion handler to be called later?
Note splitting the install vs _REG calling of OpRegion handlers requires ACPICA changes (patch 3/4).
Assuming those changes are in place then we could delay calling of _REG also until the actual acpi-ec driver binds. This would put it a lot later in the init sequence though. So that would be much more of a change to the ordering then done in this RFC series.
I did consider this and I do think it makes sense to only call _REG once we actually have fully setup the ACPI device for the EC (rather then just parsed the ECDT as we do now), but it is a big change.
This would also put the _REG late enough that the _INI setting the OSYS variable has already run, avoiding the need for the "early" _INI calls from the EC _REG evaluation pov (1).
If we go this route then acpi_bus_init() would not need any changes. In this case the changes would be:
1. Change acpi_ec_ecdt_probe(); to only install the OpRegion handler and not call _REG
2. Call _REG from acpi_ec_add() before it callsacpi_dev_clear_dependencies(device);
If you think that is better I can implement this and ask the reporter of:
https://bugzilla.kernel.org/show_bug.cgi?id=214899
to give this new approach a test run.
Regards,
Hans
1) Note there also is another issue wrt _REG running vs _INI setting OSYS which is not EC related at all. Quoting from the commit msg of patch 2/4:
"""2. On a "Lenovo Thinkbook 14-ILL" \\_SB_.PCI0.I2C0._REG gets evaluated before \_SB.PCI0._INI and that _REG contains:
If ((OSYS == 0x07DF))
{
...
LNUX = Zero
TPID = 0x4E
}
else
{
LNUX = One
TPID = 0xBB
}And then later on the TPID value gets used to decide for which of multiple devices describing the touchpad _STA should return 0xF and the one which gets enabled by TPID=0xBB is broken, causing to the touchpad to not work:
https://bugzilla.redhat.com/show_bug.cgi?id=1842039
"""
I believe that fixing this still requires running the PCI root bridge's _INI method before calling _REG functions (on devices under that bridge in the ACPI device hierarchy).
We can analyse this issue seperately and fixing this is likely isolated to just ACPICA changes.
Quoted 155 lines
Quoted 154 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/acpi/bus.c | 19 ++++++++++++++++++- drivers/acpi/ec.c | 38 ++++++++++++++++++++++++++++---------- drivers/acpi/internal.h | 1 + 3 files changed, 47 insertions(+), 11 deletions(-)drivers/acpi/bus.c +18
-1@@ -1303,7 +1303,24 @@ static int __init acpi_bus_init(void) goto error1; } - status =acpi_initialize_objects (ACPI_FULL_INITIALIZATION ); +/* +* This usually sets an OSYS global variable based on _OSI checks, +* and the EC's _REG method may rely on this OSYS variable, so do +* this before acpi_ec_ecdt_exec_reg(). +*/ + status =acpi_early_initialize_objects (); +if (ACPI_FAILURE (status)) { +pr_err ("Unable to do early ACPI objects initialization\n" ); + goto error1; + } + +acpi_ec_ecdt_exec_reg (); + +/* +* ACPI_NO_EARLY_DEVICE_INIT to avoid ACPICA calling +* acpi_early_initialize_objects() a second time. +*/ + status =acpi_initialize_objects (ACPI_NO_EARLY_DEVICE_INIT );if (ACPI_FAILURE (status)) {pr_err ("Unable to initialize ACPI objects\n" ); goto error1;drivers/acpi/ec.c +28
-10@@ -1459,6 +1459,7 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec)* ec_install_handlers - Install service callbacks and register query methods. * @ec: Target EC. * @device: ACPI device object corresponding to @ec. +* @flags: Flags to pass to acpi_install_address_space_handler() * * Install a handler for the EC address space type unless it has been installed * already. If @device is not NULL, also look for EC query methods in the @@ -1471,7 +1472,7 @@ static bool install_gpio_irq_event_handler(struct acpi_ec *ec)* -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred, * or 0 (success) otherwise. */ -static int ec_install_handlers (struct acpi_ec *ec,struct acpi_device *device) +static int ec_install_handlers (struct acpi_ec *ec,struct acpi_device *device,u32 flags) {acpi_status status;@@ -1479,10 +1480,10 @@ static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device)if (!test_bit (EC_FLAGS_EC_HANDLER_INSTALLED , &ec->flags)) {acpi_ec_enter_noirq (ec); - status =acpi_install_address_space_handler (ec->handle, -ACPI_ADR_SPACE_EC , - &acpi_ec_space_handler, -NULL , ec); + status =acpi_install_address_space_handler_flags (ec->handle, +ACPI_ADR_SPACE_EC , + &acpi_ec_space_handler, +NULL , ec, flags);if (ACPI_FAILURE (status)) {acpi_ec_stop (ec, false);return -ENODEV ;@@ -1575,11 +1576,11 @@ static void ec_remove_handlers(struct acpi_ec *ec) } } -static int acpi_ec_setup (struct acpi_ec *ec,struct acpi_device *device) +static int acpi_ec_setup (struct acpi_ec *ec,struct acpi_device *device,u32 flags) {int ret; - ret =ec_install_handlers (ec, device); + ret =ec_install_handlers (ec, device, flags);if (ret)return ret;@@ -1641,7 +1642,7 @@ static int acpi_ec_add(struct acpi_device *device) } } - ret =acpi_ec_setup (ec, device); + ret =acpi_ec_setup (ec, device,0 );if (ret) goto err;@@ -1761,7 +1762,7 @@ void __init acpi_ec_dsdt_probe(void)* At this point, the GPE is not fully initialized, so do not to * handle the events. */ - ret =acpi_ec_setup (ec,NULL ); + ret =acpi_ec_setup (ec,NULL ,0 );if (ret) {acpi_ec_free (ec);return ;@@ -1973,7 +1974,7 @@ void __init acpi_ec_ecdt_probe(void)* At this point, the namespace is not initialized, so do not find * the namespace objects, or handle the events. */ - ret =acpi_ec_setup (ec,NULL ); + ret =acpi_ec_setup (ec,NULL ,ACPI_NO_EXEC__REG );if (ret) {acpi_ec_free (ec); goto out;@@ -1988,6 +1989,23 @@ void __init acpi_ec_ecdt_probe(void)acpi_put_table ((struct acpi_table_header *)ecdt_ptr); } +void __init acpi_ec_ecdt_exec_reg (void ) +{ +if (!boot_ec || !boot_ec_is_ecdt) +return ; + +/* +* Second call, first call is done in acpi_ec_ecdt_probe(), pass +* ACPI_NO_INSTALL_SPACE_HANDLER so as to only exec _REG now that +* the namespace has been setup. +*/ +acpi_install_address_space_handler_flags (boot_ec->handle, +ACPI_ADR_SPACE_EC , + &acpi_ec_space_handler,NULL , + boot_ec, +ACPI_NO_INSTALL_SPACE_HANDLER ); +} +#ifdef CONFIG_PM_SLEEP static int acpi_ec_suspend (struct device *dev) {drivers/acpi/internal.h +1
-1@@ -203,6 +203,7 @@ typedef int (*acpi_ec_query_func) (void *data);void acpi_ec_init (void );void acpi_ec_ecdt_probe (void ); +void acpi_ec_ecdt_exec_reg (void );void acpi_ec_dsdt_probe (void );void acpi_ec_block_transactions (void );void acpi_ec_unblock_transactions (void ); --2.36.0
Rafael J. Wysocki
[Devel] Re: [RFC 4/4] ACPI: fix ECDT EC probe ordering issues
Quoted 20 lines · Hans de Goede
Hi,
Quoted 1 line · Rafael J. Wysocki
First off, thanks for taking care of this issue!
You're welcome.
Quoted 11 lines · Hans de Goede
Quoted 5 lines
ACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So
acpi_bus_init()callsacpi_ec_ecdt_probe(), which callsacpi_install_address_space_handler()to install the EC's OpRegion handler, early on.I think that the key question is what Windows does in this respect.
I honestly don't think that it uses an allowlist to early call
_INIfor a few specific devices.
Quoted 6 lines
Right, I guess that windows does things more hierarchicallly first calling \._INI then \._SB._INI and then calling other _INI-s around the time it enters there parts of the ACPI device hierarchy.
I have the feeling that Windows e.g. has the root PCI bridge fully setup before even parsing any ACPI objects under it.
Which means that if the EC object is under PCI0, it will not evaluate its _REG before enumerating the PCI bus.
Quoted 3 lines
This is quite different from how Linux (or ACPICa for that manner) works. So ATM I believe that the fixed list of object paths to call
_INIon early is the best we can do.
Well, ACPICA follows the spec quite literally in that respect (and the spec says that _INI should be evaluated "at the table load time" IIRC).
Quoted 28 lines
Quoted 20 lines
Quoted 20 lines
This not only installs the OpRegion handler, but also calls the EC's
_REGmethod. The_REGmethod call is a problem because it may rely on initialization done by the_INImethods of one of the PCI /_SBroot devs, see for example: https://bugzilla.kernel.org/show_bug.cgi?id=214899 .This
_REGdepends on_INIproblem can be fixed by calling the new ACPICAacpi_early_initialize_objects()function beforeacpi_ec_ecdt_probe().But on some boards (e.g. Lenovo X1C8) the root devices
_INImethod relies on the EC OpRegion so executing the_INImethods before registering the EC OpRegion handler leads to errors there.To allow fixing this the ACPICA code now allows to do the OpRegion handler installation early on (without calling
_REG) and to do the EC's_REGexecution later on as a separate step.This commit uses this new ACPICA functions to fix the EC probe ordering by changing the
acpi_bus_init()initialization order to this:Quoted 7 lines
Quoted 4 lines
1.
acpi_load_tables()
2.acpi_ec_ecdt_probe()
This now callsacpi_install_address_space_handler(ACPI_NO_EXEC__REG)which installs the OpRegion handler without executing_REGI'm not sure if installing an opregion without evaluating
_REGfor it is particularly useful.
Quoted 6 lines
We already do this for the SystemMemory / SystemIO and
PCI_ConfigOpRegions. The handlers for these get installed fromacpi_enable_subsystem()and their_REGfunctions get called later fromacpi_initialize_objects().This patch basically makes the EmbeddedControl OpRegion behave the same and according to the current code:
I think that the evaluation of _REG can be deferred in this case.
Quoted 25 lines
/*
* ACPI 2.0 requires the EC driver to be loaded and work before the EC
* device is found in the namespace.
*
* This is accomplished by looking for the ECDT table and getting the EC
* parameters out of that.
*
* Do that before callingacpi_initialize_objects()which may trigger EC
* address space accesses.
*/
acpi_ec_ecdt_probe();This is mandated by ACPI-2.0 which also seems to match my analysis of this problem where on e.g. my Lenovo X1 carbon gen 8 the \_SB.PCI0._INI method uses an EmbeddedControl OpRegion without any
_REGrelated checks.Quoted 1 line
No AML should use it before
_REGis evaluated anyway.See above, ACPI 2.x seems to allow this, like how it allows it for SystemIO / SystemMemory /
PCI_Config. This seems to be the whole reason why there is a separate table describing the EC (the ECDT) so that the EC can be made available before any parsing of the DSDT has been done.
Quoted 5 lines
So we need to have the OpRegion available before running the "early"
_INImethods. And because of_REGrelying on the OSYS GVNS variable in some cases, which gets set from_INIon the PCI root bridge, that means running_REGafter running (some)_INImethods.
OK, so at least on some systems the EC address space will be accessed regardless of the _REG for it.
Quoted 39 lines
Quoted 7 lines
Quoted 3 lines
3.
acpi_enable_subsystem()
4.acpi_early_initialize_objects()
This calls the_INImethod of the PCI and_SBroot devicesSo this is a change in behavior that will affect every system using ACPI on the planet, not just the ones where the problem at hand is present. This appears to be somewhat risky to me.
The ACPICA code already calls \.INI and \_SB._INI at the start of
acpi_initialize_objects(), before evalutating any_REGmethods, so this call in itself is no a change.Except that \_SB.PCI0._INI and \_SB.PC0._INI are now also run early (patch 2/4).
Quoted 2 lines
Quoted 2 lines
5.
acpi_ec_ecdt_exec_reg();
This executes the EC's_REGnow that the root devices_INIhas runThis is the actual change moving the calling of
_REGfor the EC to after the running of the "early"_INIcalls.Quoted 9 lines
Quoted 5 lines
6.
acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)This allows the EC's
_REGmethod to depend on e.g. the \OSYS global/GVNS variable often set by a root-device's_INImethod, while at the same time allowing these_INImethods to access EmbeddedController OpRegions.I'm wondering if it is possible to change the ordering of
acpi_ec_ecdt_probe()or the part of it that installs the oprtegion handler to be called later?Note splitting the install vs
_REGcalling of OpRegion handlers requires ACPICA changes (patch 3/4).Assuming those changes are in place then we could delay calling of
_REGalso until the actual acpi-ec driver binds. This would put it a lot later in the init sequence though. So that would be much more of a change to the ordering then done in this RFC series.
Quoted 4 lines
I did consider this and I do think it makes sense to only call
_REGonce we actually have fully setup the ACPI device for the EC (rather then just parsed the ECDT as we do now), but it is a big change.
That's what I would like to do here.
Quoted 14 lines
This would also put the
_REGlate enough that the_INIsetting the OSYS variable has already run, avoiding the need for the "early"_INIcalls from the EC_REGevaluation pov (1).If we go this route then
acpi_bus_init()would not need any changes. In this case the changes would be:1. Change
acpi_ec_ecdt_probe(); to only install the OpRegion handler and not call_REG2. Call
_REGfromacpi_ec_add()before it callsacpi_dev_clear_dependencies(device);
Quoted 6 lines
If you think that is better I can implement this and ask the reporter of:
https://bugzilla.kernel.org/show_bug.cgi?id=214899
to give this new approach a test run.
Yes, please.
Re: [RFC 4/4] ACPI: fix ECDT EC probe ordering issues
Hi,
Quoted 25 lines · Rafael J. Wysocki
Quoted 24 lines · Hans de Goede
Hi,
Quoted 1 line · Rafael J. Wysocki
First off, thanks for taking care of this issue!
You're welcome.
Quoted 11 lines · Hans de Goede
Quoted 5 lines
ACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So
acpi_bus_init()callsacpi_ec_ecdt_probe(), which callsacpi_install_address_space_handler()to install the EC's OpRegion handler, early on.I think that the key question is what Windows does in this respect.
I honestly don't think that it uses an allowlist to early call
_INIfor a few specific devices.Right, I guess that windows does things more hierarchicallly first calling \._INI then \._SB._INI and then calling other _INI-s around the time it enters there parts of the ACPI device hierarchy.
Quoted 5 lines
Quoted 2 lines
I have the feeling that Windows e.g. has the root PCI bridge fully setup before even parsing any ACPI objects under it.
Which means that if the EC object is under PCI0, it will not evaluate its
_REGbefore enumerating the PCI bus.
Ack, assuming that my hunch of Windows behavior is correct.
Quoted 7 lines
Quoted 3 lines
This is quite different from how Linux (or ACPICa for that manner) works. So ATM I believe that the fixed list of object paths to call
_INIon early is the best we can do.Well, ACPICA follows the spec quite literally in that respect (and the spec says that
_INIshould be evaluated "at the table load time" IIRC).
<offtopic for the EC issue, sorry (but stronly related)>
I did notice one interesting thing while working on this, ACPICA has drivers/acpi/acpica/nsinit.c: acpi_ns_initialize_objects() which calls _INI for *all* objects and it also has:drivers/acpi/acpica/utxfinit.c: acpi_initialize_objects():
#ifdef ACPI_OBSOLETE_BEHAVIOR
/*
* 05/2019: Removed, initialization now happens at both object
* creation and table load time
*/
/*
* Initialize the objects that remain uninitialized. This
* runs the executable AML that may be part of the
* declaration of these objects: operation_regions, buffer_fields,
* bank_fields, Buffers, and Packages.
*/
if (!(flags & ACPI_NO_OBJECT_INIT)) {
status = acpi_ns_initialize_objects();
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
}#endif
Which means that at some point in time it used to indeed call _INI on all objects early on. But now this no longer happens
and instead acpi_initialize_objects() ends up in acpi_ns_initialize_devices() which does:
1. Run \._INI
2. Run \_SB._INI
3. Run _REG for all SystemIO / SystemMemory / PCI_Config handlers
4. Run _INI for all other objects
And I believe that this is causing similar issues as the EC issue we are discussing here in some cases. Specifically the earlier mentioned touchpad issue:
"""
On a "Lenovo Thinkbook 14-ILL" \\_SB_.PCI0.I2C0._REG gets evaluated before \_SB.PCI0._INI and that _REG contains:
If ((OSYS == 0x07DF))
{
...
LNUX = Zero
TPID = 0x4E
}
else
{
LNUX = One
TPID = 0xBB
}And then later on the TPID value gets used to decide for which of multiple devices describing the touchpad _STA should return 0xF and the one which gets enabled by TPID=0xBB is broken, causing to the touchpad to not work:
https://bugzilla.redhat.com/show_bug.cgi?id=1842039
"""
The difference between the EC problem and this one is that the troublesome code in the EC _REG handler is inside a:
If (((Arg0 == 0x03) && (Arg1 == One)))
{
}block, so any non EmbeddedController OpRegion _REG calls are not an issue.
Where as in the "Lenovo Thinkbook 14-ILL" touchpad case the troublesome _REG looks like this (simplified):
Method (_REG, 2, NotSerialized) // _REG: Region Availability
{
If ((TPID != Zero))
{
Return (Zero)
}
If ((OSYS == 0x07DF))
{
TPID = <one we want>
}
Else
{
TPID = <wrong-one>
}
Return (Zero)
}So it only checks OSYS the first time it runs (when TPID == 0) and the above mentioned steps 1-4 done by acpi_ns_initialize_devices() runs this _REG too early. The reasons why this runs too early is because the \_SB_.PCI0.I2C0 device which this is the _REG method for also uses a PCI_Config OpRegion, so the early _REG calls done by acpi_ns_initialize_devices() will run this _REG.
So even if we fix the EC issue by having the EC code call _REG later for the EC object we still have this issue wrt general _REG vs _INI ordering, any suggestions welcome. Otherwise I will likely still try to get patches 1 + 2 from this series upstream to fix this.
Or maybe we need to just make acpi_ns_initialize_devices() call all _INI methods before calling any _REG methods? That does somehow feel right, but I'm not sure how well it will work in practice.
</semi-offtopic>
Quoted 130 lines
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
This not only installs the OpRegion handler, but also calls the EC's
_REGmethod. The_REGmethod call is a problem because it may rely on initialization done by the_INImethods of one of the PCI /_SBroot devs, see for example: https://bugzilla.kernel.org/show_bug.cgi?id=214899 .This
_REGdepends on_INIproblem can be fixed by calling the new ACPICAacpi_early_initialize_objects()function beforeacpi_ec_ecdt_probe().But on some boards (e.g. Lenovo X1C8) the root devices
_INImethod relies on the EC OpRegion so executing the_INImethods before registering the EC OpRegion handler leads to errors there.To allow fixing this the ACPICA code now allows to do the OpRegion handler installation early on (without calling
_REG) and to do the EC's_REGexecution later on as a separate step.This commit uses this new ACPICA functions to fix the EC probe ordering by changing the
acpi_bus_init()initialization order to this:Quoted 7 lines
Quoted 4 lines
1.
acpi_load_tables()
2.acpi_ec_ecdt_probe()
This now callsacpi_install_address_space_handler(ACPI_NO_EXEC__REG)which installs the OpRegion handler without executing_REGI'm not sure if installing an opregion without evaluating
_REGfor it is particularly useful.Quoted 6 lines
We already do this for the SystemMemory / SystemIO and
PCI_ConfigOpRegions. The handlers for these get installed fromacpi_enable_subsystem()and their_REGfunctions get called later fromacpi_initialize_objects().This patch basically makes the EmbeddedControl OpRegion behave the same and according to the current code:
I think that the evaluation of
_REGcan be deferred in this case.Quoted 25 lines
/*
* ACPI 2.0 requires the EC driver to be loaded and work before the EC
* device is found in the namespace.
*
* This is accomplished by looking for the ECDT table and getting the EC
* parameters out of that.
*
* Do that before callingacpi_initialize_objects()which may trigger EC
* address space accesses.
*/
acpi_ec_ecdt_probe();This is mandated by ACPI-2.0 which also seems to match my analysis of this problem where on e.g. my Lenovo X1 carbon gen 8 the \_SB.PCI0._INI method uses an EmbeddedControl OpRegion without any
_REGrelated checks.Quoted 1 line
No AML should use it before
_REGis evaluated anyway.See above, ACPI 2.x seems to allow this, like how it allows it for SystemIO / SystemMemory /
PCI_Config. This seems to be the whole reason why there is a separate table describing the EC (the ECDT) so that the EC can be made available before any parsing of the DSDT has been done.Quoted 5 lines
So we need to have the OpRegion available before running the "early"
_INImethods. And because of_REGrelying on the OSYS GVNS variable in some cases, which gets set from_INIon the PCI root bridge, that means running_REGafter running (some)_INImethods.OK, so at least on some systems the EC address space will be accessed regardless of the
_REGfor it.Quoted 39 lines
Quoted 7 lines
Quoted 3 lines
3.
acpi_enable_subsystem()
4.acpi_early_initialize_objects()
This calls the_INImethod of the PCI and_SBroot devicesSo this is a change in behavior that will affect every system using ACPI on the planet, not just the ones where the problem at hand is present. This appears to be somewhat risky to me.
The ACPICA code already calls \.INI and \_SB._INI at the start of
acpi_initialize_objects(), before evalutating any_REGmethods, so this call in itself is no a change.Except that \_SB.PCI0._INI and \_SB.PC0._INI are now also run early (patch 2/4).
Quoted 2 lines
Quoted 2 lines
5.
acpi_ec_ecdt_exec_reg();
This executes the EC's_REGnow that the root devices_INIhas runThis is the actual change moving the calling of
_REGfor the EC to after the running of the "early"_INIcalls.Quoted 9 lines
Quoted 5 lines
6.
acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)This allows the EC's
_REGmethod to depend on e.g. the \OSYS global/GVNS variable often set by a root-device's_INImethod, while at the same time allowing these_INImethods to access EmbeddedController OpRegions.I'm wondering if it is possible to change the ordering of
acpi_ec_ecdt_probe()or the part of it that installs the oprtegion handler to be called later?Note splitting the install vs
_REGcalling of OpRegion handlers requires ACPICA changes (patch 3/4).Assuming those changes are in place then we could delay calling of
_REGalso until the actual acpi-ec driver binds. This would put it a lot later in the init sequence though. So that would be much more of a change to the ordering then done in this RFC series.Quoted 4 lines
I did consider this and I do think it makes sense to only call
_REGonce we actually have fully setup the ACPI device for the EC (rather then just parsed the ECDT as we do now), but it is a big change.That's what I would like to do here.
Quoted 14 lines
This would also put the
_REGlate enough that the_INIsetting the OSYS variable has already run, avoiding the need for the "early"_INIcalls from the EC_REGevaluation pov (1).If we go this route then
acpi_bus_init()would not need any changes. In this case the changes would be:1. Change
acpi_ec_ecdt_probe(); to only install the OpRegion handler and not call_REG2. Call
_REGfromacpi_ec_add()before it callsacpi_dev_clear_dependencies(device);
Quoted 8 lines
Quoted 6 lines
If you think that is better I can implement this and ask the reporter of:
https://bugzilla.kernel.org/show_bug.cgi?id=214899
to give this new approach a test run.
Yes, please.
Ok, will do. Not sure when I will get around to this though.
Regards,
Hans
Rafael J. Wysocki
[Devel] Re: [RFC 4/4] ACPI: fix ECDT EC probe ordering issues
Quoted 41 lines · Hans de Goede
Hi,
Quoted 25 lines · Rafael J. Wysocki
Quoted 24 lines · Hans de Goede
Hi,
Quoted 1 line · Rafael J. Wysocki
First off, thanks for taking care of this issue!
You're welcome.
Quoted 11 lines · Hans de Goede
Quoted 5 lines
ACPI-2.0 says that the EC OpRegion handler must be available immediately (like the standard default OpRegion handlers). So
acpi_bus_init()callsacpi_ec_ecdt_probe(), which callsacpi_install_address_space_handler()to install the EC's OpRegion handler, early on.I think that the key question is what Windows does in this respect.
I honestly don't think that it uses an allowlist to early call
_INIfor a few specific devices.Right, I guess that windows does things more hierarchicallly first calling \._INI then \._SB._INI and then calling other _INI-s around the time it enters there parts of the ACPI device hierarchy.
Quoted 5 lines
Quoted 2 lines
I have the feeling that Windows e.g. has the root PCI bridge fully setup before even parsing any ACPI objects under it.
Which means that if the EC object is under PCI0, it will not evaluate its
_REGbefore enumerating the PCI bus.Ack, assuming that my hunch of Windows behavior is correct.
Quoted 4 lines
Quoted 3 lines
This is quite different from how Linux (or ACPICa for that manner) works. So ATM I believe that the fixed list of object paths to call
_INIon early is the best we can do.
Quoted 5 lines
Quoted 3 lines
Well, ACPICA follows the spec quite literally in that respect (and the spec says that
_INIshould be evaluated "at the table load time" IIRC).<offtopic for the EC issue, sorry (but stronly related)>
Yes, it is related.
Quoted 25 lines
I did notice one interesting thing while working on this, ACPICA has
drivers/acpi/acpica/nsinit.c:acpi_ns_initialize_objects()which calls_INIfor *all* objects and it also has:drivers/acpi/acpica/utxfinit.c:acpi_initialize_objects():#ifdef ACPI_OBSOLETE_BEHAVIOR /* * 05/2019: Removed, initialization now happens at both object * creation and table load time */ /* * Initialize the objects that remain uninitialized. This * runs the executable AML that may be part of the * declaration of these objects: operation_regions, buffer_fields, * bank_fields, Buffers, and Packages. */ if (!(flags & ACPI_NO_OBJECT_INIT)) { status = acpi_ns_initialize_objects(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } }#endif
Quoted 8 lines
Which means that at some point in time it used to indeed call
_INIon all objects early on. But now this no longer happens
and insteadacpi_initialize_objects()ends up inacpi_ns_initialize_devices()which does:1. Run \._INI
2. Run \_SB._INI
3. Run_REGfor all SystemIO / SystemMemory /PCI_Confighandlers
Except that after (Linux) commit 8b1cafdcb4b7 ("ACPICA: Never run _REG on system_memory and system_IO") the former two are not run anyway.
Quoted 59 lines
4. Run
_INIfor all other objectsAnd I believe that this is causing similar issues as the EC issue we are discussing here in some cases. Specifically the earlier mentioned touchpad issue:
"""
On a "Lenovo Thinkbook 14-ILL" \\_SB_.PCI0.I2C0._REG gets evaluated before \_SB.PCI0._INI and that_REGcontains:If ((OSYS == 0x07DF)) { ... LNUX = Zero TPID = 0x4E } else { LNUX = One TPID = 0xBB }And then later on the TPID value gets used to decide for which of multiple devices describing the touchpad
_STAshould return0xFand the one which gets enabled by TPID=0xBB is broken, causing to the touchpad to not work:
https://bugzilla.redhat.com/show_bug.cgi?id=1842039
"""The difference between the EC problem and this one is that the troublesome code in the EC
_REGhandler is inside a:If (((Arg0 == 0x03) && (Arg1 == One))) { }block, so any non EmbeddedController OpRegion
_REGcalls are not an issue.Where as in the "Lenovo Thinkbook 14-ILL" touchpad case the troublesome
_REGlooks like this (simplified):Method (_REG, 2, NotSerialized) // _REG: Region Availability { If ((TPID != Zero)) { Return (Zero) } If ((OSYS == 0x07DF)) { TPID = <one we want> } Else { TPID = <wrong-one> } Return (Zero) }
Quoted 3 lines
So it only checks OSYS the first time it runs (when TPID == 0) and the above mentioned steps 1-4 done by
acpi_ns_initialize_devices()runs this_REGtoo early.
I think that this is a bug.
Quoted 4 lines
The reasons why this runs too early is
because the \_SB_.PCI0.I2C0 device which this is the_REGmethod for also uses aPCI_ConfigOpRegion, so the early_REGcalls done byacpi_ns_initialize_devices()will run this_REG.
Hmm.
Quoted 7 lines
So even if we fix the EC issue by having the EC code call
_REGlater for the EC object we still have this issue wrt general_REGvs_INIordering, any suggestions welcome. Otherwise I will likely still try to get patches 1 + 2 from this series upstream to fix this.Or maybe we need to just make
acpi_ns_initialize_devices()call all_INImethods before calling any_REGmethods?
At least we should make sure that _INI for all ancestors have been evaluated before evaluating _REG for a descendant (and obviously _REG should not be evaluated before _INI for the same device).
Quoted 1 line
That does somehow feel right, but I'm not sure how well it will work in practice.
I would even say that this is mandated by the spec, but of course the question regarding practice is a good one.
Quoted 135 lines
</semi-offtopic>
Quoted 133 lines
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
This not only installs the OpRegion handler, but also calls the EC's
_REGmethod. The_REGmethod call is a problem because it may rely on initialization done by the_INImethods of one of the PCI /_SBroot devs, see for example: https://bugzilla.kernel.org/show_bug.cgi?id=214899 .This
_REGdepends on_INIproblem can be fixed by calling the new ACPICAacpi_early_initialize_objects()function beforeacpi_ec_ecdt_probe().But on some boards (e.g. Lenovo X1C8) the root devices
_INImethod relies on the EC OpRegion so executing the_INImethods before registering the EC OpRegion handler leads to errors there.To allow fixing this the ACPICA code now allows to do the OpRegion handler installation early on (without calling
_REG) and to do the EC's_REGexecution later on as a separate step.This commit uses this new ACPICA functions to fix the EC probe ordering by changing the
acpi_bus_init()initialization order to this:Quoted 7 lines
Quoted 4 lines
1.
acpi_load_tables()
2.acpi_ec_ecdt_probe()
This now callsacpi_install_address_space_handler(ACPI_NO_EXEC__REG)which installs the OpRegion handler without executing_REGI'm not sure if installing an opregion without evaluating
_REGfor it is particularly useful.Quoted 6 lines
We already do this for the SystemMemory / SystemIO and
PCI_ConfigOpRegions. The handlers for these get installed fromacpi_enable_subsystem()and their_REGfunctions get called later fromacpi_initialize_objects().This patch basically makes the EmbeddedControl OpRegion behave the same and according to the current code:
I think that the evaluation of
_REGcan be deferred in this case.Quoted 25 lines
/*
* ACPI 2.0 requires the EC driver to be loaded and work before the EC
* device is found in the namespace.
*
* This is accomplished by looking for the ECDT table and getting the EC
* parameters out of that.
*
* Do that before callingacpi_initialize_objects()which may trigger EC
* address space accesses.
*/
acpi_ec_ecdt_probe();This is mandated by ACPI-2.0 which also seems to match my analysis of this problem where on e.g. my Lenovo X1 carbon gen 8 the \_SB.PCI0._INI method uses an EmbeddedControl OpRegion without any
_REGrelated checks.Quoted 1 line
No AML should use it before
_REGis evaluated anyway.See above, ACPI 2.x seems to allow this, like how it allows it for SystemIO / SystemMemory /
PCI_Config. This seems to be the whole reason why there is a separate table describing the EC (the ECDT) so that the EC can be made available before any parsing of the DSDT has been done.Quoted 5 lines
So we need to have the OpRegion available before running the "early"
_INImethods. And because of_REGrelying on the OSYS GVNS variable in some cases, which gets set from_INIon the PCI root bridge, that means running_REGafter running (some)_INImethods.OK, so at least on some systems the EC address space will be accessed regardless of the
_REGfor it.Quoted 39 lines
Quoted 7 lines
Quoted 3 lines
3.
acpi_enable_subsystem()
4.acpi_early_initialize_objects()
This calls the_INImethod of the PCI and_SBroot devicesSo this is a change in behavior that will affect every system using ACPI on the planet, not just the ones where the problem at hand is present. This appears to be somewhat risky to me.
The ACPICA code already calls \.INI and \_SB._INI at the start of
acpi_initialize_objects(), before evalutating any_REGmethods, so this call in itself is no a change.Except that \_SB.PCI0._INI and \_SB.PC0._INI are now also run early (patch 2/4).
Quoted 2 lines
Quoted 2 lines
5.
acpi_ec_ecdt_exec_reg();
This executes the EC's_REGnow that the root devices_INIhas runThis is the actual change moving the calling of
_REGfor the EC to after the running of the "early"_INIcalls.Quoted 9 lines
Quoted 5 lines
6.
acpi_initialize_objects(ACPI_NO_EARLY_DEVICE_INIT)This allows the EC's
_REGmethod to depend on e.g. the \OSYS global/GVNS variable often set by a root-device's_INImethod, while at the same time allowing these_INImethods to access EmbeddedController OpRegions.I'm wondering if it is possible to change the ordering of
acpi_ec_ecdt_probe()or the part of it that installs the oprtegion handler to be called later?Note splitting the install vs
_REGcalling of OpRegion handlers requires ACPICA changes (patch 3/4).Assuming those changes are in place then we could delay calling of
_REGalso until the actual acpi-ec driver binds. This would put it a lot later in the init sequence though. So that would be much more of a change to the ordering then done in this RFC series.Quoted 4 lines
I did consider this and I do think it makes sense to only call
_REGonce we actually have fully setup the ACPI device for the EC (rather then just parsed the ECDT as we do now), but it is a big change.That's what I would like to do here.
Quoted 17 lines
This would also put the
_REGlate enough that the_INIsetting the OSYS variable has already run, avoiding the need for the "early"_INIcalls from the EC_REGevaluation pov (1).If we go this route then
acpi_bus_init()would not need any changes. In this case the changes would be:1. Change
acpi_ec_ecdt_probe(); to only install the OpRegion handler and not call_REG2. Call
_REGfromacpi_ec_add()before it callsacpi_dev_clear_dependencies(device);If you think that is better I can implement this and ask the reporter of:
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
https://bugzilla.kernel.org/show_bug.cgi?id=214899
to give this new approach a test run.
Yes, please.
Ok, will do. Not sure when I will get around to this though.
No problem, please take your time.