Message ID | 20221003144214.345279-1-hdegoede@redhat.com |
---|---|
Headers | show |
Series | ACPI[CA]: fix ECDT EC probe ordering issues | expand |
On Mon, Oct 03, 2022 at 04:42:14PM +0200, Hans de Goede wrote: > ACPI-2.0 says that the EC OpRegion handler must be available immediately > (like the standard default OpRegion handlers): > > Quoting from the ACPI spec version 6.3: "6.5.4 _REG (Region) ... (Side note: As of today the revision 6.5 of the ACPI specification is available) > 2. OSPM must make Embedded Controller operation regions, accessed via > the Embedded Controllers described in ECDT, available before executing > any control method. These operation regions may become inaccessible > after OSPM runs _REG(EmbeddedControl, 0)." > > 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 . > > Generally speaking _REG methods are executed when the ACPI-device they > are part of has a driver bound to it. Where as _INI methods must be > executed at table load time (according to the spec). The problem here > is that the early acpi_install_address_space_handler() call causes > the _REG handler to run too early. > > To allow fixing this the ACPICA code now allows to split the OpRegion > handler installation and the executing of _REG into 2 separate steps. > > This commit uses this ACPICA functionality to fix the EC probe ordering > by delaying the executing of _REG for ECDT described ECs till the matching > EC device in the DSDT gets parsed and acpi_ec_add() for it gets called. > This moves the calling of _REG for the EC on devices with an ECDT to > the same point in time where it is called on devices without an ECDT table. ... > + if (call_reg && !test_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags)) { > + acpi_execute_reg_methods(ec->handle, ACPI_ADR_SPACE_EC); > + set_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags); Just to be sure: do you need atomic operation here? Does it prevent of any kind of races? Because if it had been the case, it would have been done via test_and_set_bit() rather than testing and setting separated. > + }
Hi, On 10/4/22 10:24, Andy Shevchenko wrote: > On Mon, Oct 03, 2022 at 04:42:14PM +0200, Hans de Goede wrote: >> ACPI-2.0 says that the EC OpRegion handler must be available immediately >> (like the standard default OpRegion handlers): >> >> Quoting from the ACPI spec version 6.3: "6.5.4 _REG (Region) ... > > (Side note: As of today the revision 6.5 of the ACPI specification is > available) > >> 2. OSPM must make Embedded Controller operation regions, accessed via >> the Embedded Controllers described in ECDT, available before executing >> any control method. These operation regions may become inaccessible >> after OSPM runs _REG(EmbeddedControl, 0)." >> >> 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 . >> >> Generally speaking _REG methods are executed when the ACPI-device they >> are part of has a driver bound to it. Where as _INI methods must be >> executed at table load time (according to the spec). The problem here >> is that the early acpi_install_address_space_handler() call causes >> the _REG handler to run too early. >> >> To allow fixing this the ACPICA code now allows to split the OpRegion >> handler installation and the executing of _REG into 2 separate steps. >> >> This commit uses this ACPICA functionality to fix the EC probe ordering >> by delaying the executing of _REG for ECDT described ECs till the matching >> EC device in the DSDT gets parsed and acpi_ec_add() for it gets called. >> This moves the calling of _REG for the EC on devices with an ECDT to >> the same point in time where it is called on devices without an ECDT table. > > ... > >> + if (call_reg && !test_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags)) { >> + acpi_execute_reg_methods(ec->handle, ACPI_ADR_SPACE_EC); > >> + set_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags); > > Just to be sure: do you need atomic operation here? Does it prevent of any > kind of races? Because if it had been the case, it would have been done via > test_and_set_bit() rather than testing and setting separated. AFAIK we do not need atomic operations here (I did not verify this). Also note that existing code a couple of lines above already uses the same pattern. Regards, Hans
Hi Hans, On Mon, Oct 3, 2022 at 4:42 PM Hans de Goede <hdegoede@redhat.com> wrote: > > Hi All, > > Here is v3 of my series fixing some ECDT EC probe ordering issues which > are causing issues om some laptops: > > https://bugzilla.kernel.org/show_bug.cgi?id=214899 > > This is a RFC because fixing this requires some ACPICA changes which > obviously need to go upstream through the ACPICA project: > https://github.com/acpica/acpica/pull/786 I've just approved your pull request. Also, as soon as it gets merged, you can resubmit the series with a proper ACPICA commit ID and I will be able to apply the patches right away then. > 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): > > Quoting from the ACPI spec version 6.3: "6.5.4 _REG (Region) ... > 2. OSPM must make Embedded Controller operation regions, accessed via > the Embedded Controllers described in ECDT, available before executing > any control method. These operation regions may become inaccessible > after OSPM runs _REG(EmbeddedControl, 0)." > > 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 . > > Generally speaking _REG methods are executed when the ACPI-device they > are part of has a driver bound to it. Where as _INI methods must be > executed at table load time (according to the spec). The problem here > is that the early acpi_install_address_space_handler() call causes > the _REG handler to run too early. > > To allow fixing this the ACPICA code now allows to split the OpRegion > handler installation and the executing of _REG into 2 separate steps. > > This commit uses this ACPICA functionality to fix the EC probe ordering > by delaying the executing of _REG for ECDT described ECs till the matching > EC device in the DSDT gets parsed and acpi_ec_add() for it gets called. > This moves the calling of _REG for the EC on devices with an ECDT to > the same point in time where it is called on devices without an ECDT table. > > Changes in v3: > - Add a prep patch to fix an indentation issue in Linux' acpixf.h to fix > the patch from ACPICA's script not applying > - Add 2 new functions to ACPICA for this instead of a flags argument > 1. acpi_install_address_space_handler_no_reg() > 2. acpi_execute_reg_methods() > - Add a patch to fix EC handler removal in the ECDT case > > From my pov this series is ready for merging once the ACPICA changes > are accepted. I agree, please resubmit as soon as the upstream ACPICA pull request gets merged. Thanks!
Hi, On 10/13/22 18:53, Rafael J. Wysocki wrote: > Hi Hans, > > On Mon, Oct 3, 2022 at 4:42 PM Hans de Goede <hdegoede@redhat.com> wrote: >> >> Hi All, >> >> Here is v3 of my series fixing some ECDT EC probe ordering issues which >> are causing issues om some laptops: >> >> https://bugzilla.kernel.org/show_bug.cgi?id=214899 >> >> This is a RFC because fixing this requires some ACPICA changes which >> obviously need to go upstream through the ACPICA project: >> https://github.com/acpica/acpica/pull/786 > > I've just approved your pull request. Thanks. > Also, as soon as it gets merged, you can resubmit the series with a > proper ACPICA commit ID and I will be able to apply the patches right > away then. Will do. Regards, Hans >> 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): >> >> Quoting from the ACPI spec version 6.3: "6.5.4 _REG (Region) ... >> 2. OSPM must make Embedded Controller operation regions, accessed via >> the Embedded Controllers described in ECDT, available before executing >> any control method. These operation regions may become inaccessible >> after OSPM runs _REG(EmbeddedControl, 0)." >> >> 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 . >> >> Generally speaking _REG methods are executed when the ACPI-device they >> are part of has a driver bound to it. Where as _INI methods must be >> executed at table load time (according to the spec). The problem here >> is that the early acpi_install_address_space_handler() call causes >> the _REG handler to run too early. >> >> To allow fixing this the ACPICA code now allows to split the OpRegion >> handler installation and the executing of _REG into 2 separate steps. >> >> This commit uses this ACPICA functionality to fix the EC probe ordering >> by delaying the executing of _REG for ECDT described ECs till the matching >> EC device in the DSDT gets parsed and acpi_ec_add() for it gets called. >> This moves the calling of _REG for the EC on devices with an ECDT to >> the same point in time where it is called on devices without an ECDT table. >> >> Changes in v3: >> - Add a prep patch to fix an indentation issue in Linux' acpixf.h to fix >> the patch from ACPICA's script not applying >> - Add 2 new functions to ACPICA for this instead of a flags argument >> 1. acpi_install_address_space_handler_no_reg() >> 2. acpi_execute_reg_methods() >> - Add a patch to fix EC handler removal in the ECDT case >> >> From my pov this series is ready for merging once the ACPICA changes >> are accepted. > > I agree, please resubmit as soon as the upstream ACPICA pull request > gets merged. > > Thanks! >