From: Hans de Goede <hdegoede@redhat.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH] ACPI: EC: Make evaluate acpi_ec_add() _REG for EC operation regions
Date: Wed, 6 Jul 2022 22:26:23 +0200 [thread overview]
Message-ID: <be219334-456f-c2f1-7102-4a3b01e8cd59@redhat.com> (raw)
In-Reply-To: <5592689.DvuYhMxLoT@kreacher>
Hi,
On 7/6/22 14:37, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> acpi_ec_ecdt_probe() is called between acpi_load_tables() and
> acpi_enable_subsystem(). It passes ACPI_ROOT_OBJECT as ec->handle
> to acpi_ec_setup() and so ACPI_ROOT_OBJECT is passed to
> acpi_install_address_space_handler() via ec_install_handlers().
>
> Next, acpi_ns_validate_handle() converts it to acpi_gbl_root_node
> which is passed to acpi_ev_install_space_handler() and the handler is
> installed for acpi_gbl_root_node.
>
> Now, acpi_gbl_root_node is passed to acpi_ev_execute_reg_methods() which
> evaluates _REG for any ACPI_ADR_SPACE_EC regions it can find in the
> namespace which should not be necessary, because the OS is expected to
> make the ECDT operation regions available before evaluating any AML, so
> in particular AML is not expected to check the evaluation of _REG before
> it accesses these operation regions (see ACPI 6.4, Section 6.5.4,
> exception 2 [1]). Doing that is also problematic, because the _REG
> methods for the ACPI_ADR_SPACE_EC regions may depend on various _INI, so
> they should be be evaluated before running acpi_initialize_objects() [2].
>
> Address this problem by modifying acpi_install_address_space_handler()
> to avoid evaluating _REG for ACPI_ADR_SPACE_EC regions when the handler
> is installed for acpi_gbl_root_node which indicates the ECDT case.
>
> However, this needs to be accompanied by an EC driver change to
> actually trigger the evaluation of _REG for the ACPI_ADR_SPACE_EC
> regions when it finds the EC object in the namespace.
>
> Link: https://uefi.org/specs/ACPI/6.4/06_Device_Configuration/Device_Configuration.html#reg-region # [1]
> Link: https://github.com/acpica/acpica/pull/786 # [2]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>
> Note: This change doesn't make any practical difference on any of the systems
> in my office.
>
> ---
> drivers/acpi/acpica/evxfregn.c | 12 ++++++++++++
> drivers/acpi/ec.c | 7 +++++++
> 2 files changed, 19 insertions(+)
>
> Index: linux-pm/drivers/acpi/ec.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/ec.c
> +++ linux-pm/drivers/acpi/ec.c
> @@ -1632,6 +1632,13 @@ static int acpi_ec_add(struct acpi_devic
> acpi_handle_debug(ec->handle, "duplicated.\n");
> acpi_ec_free(ec);
> ec = boot_ec;
> + /*
> + * Uninstall the EC address space handler and let
> + * acpi_ec_setup() install it again along with
> + * evaluating _REG methogs associated with
> + * ACPI_ADR_SPACE_EC operation regions.
> + */
> + ec_remove_handlers(ec);
This will call the _REG method to get called with ACPI_REG_DISCONNECT (0)
as second argument which may lead to unexpected consequences so I'm not
in favor of doing things this way.
IMHO it would be much better to instead have flags; or if flags are
disliked a separate function to only call _REG later on.
> }
> }
>
> Index: linux-pm/drivers/acpi/acpica/evxfregn.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/acpica/evxfregn.c
> +++ linux-pm/drivers/acpi/acpica/evxfregn.c
> @@ -78,6 +78,18 @@ acpi_install_address_space_handler(acpi_
> goto unlock_and_exit;
> }
>
> + /*
> + * Avoid evaluating _REG methods if an EC address space handler is
> + * installed for acpi_gbl_root_node, because this is done in order to
> + * make Embedded Controller operation regions, accessed via the Embedded
> + * Controllers described in ECDT, available early (see ACPI 6.4, Section
> + * 6.5.4, exception 2).
> + */
> +
> + if (node == acpi_gbl_root_node || space_id == ACPI_ADR_SPACE_EC) {
> + goto unlock_and_exit;
> + }
> +
Hmm, I like this in that it is KISS. But OTOH this does mean that
acpi_install_address_space_handler() now behaves differently depending on its
parameters in a possibly surprising way. So IMHO this feels a bit too clever
for our own good, since it may surprise the callers of this function.
My biggest problem is, that as indicated above I believe that instead
of uninstalling + re-installing the handler we really need to have a way
to just call _REG later; and that in turn requires the caller to know if
_REG has run or not.
I've posted a new RFC patch series which adds flags to
acpi_install_address_space_handler() to not run / only run _REG :
https://lore.kernel.org/linux-acpi/20220706201410.88244-1-hdegoede@redhat.com/
this then gets used in the drivers/acpi/ec.c patch to defer calling _REG when
registering the handler based on the ECDT until the DSDT EC entry is parsed.
I personally like how this turns out and IMHO this is cleaner (less hackish)
then the proposed solution with calling ec_remove_handlers(ec) :
https://lore.kernel.org/linux-acpi/20220706201410.88244-3-hdegoede@redhat.com/
Regards,
Hans
> /* Run all _REG methods for this address space */
>
> acpi_ev_execute_reg_methods(node, space_id, ACPI_REG_CONNECT);
>
>
>
next prev parent reply other threads:[~2022-07-06 20:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-06 12:37 [RFC][PATCH] ACPI: EC: Make evaluate acpi_ec_add() _REG for EC operation regions Rafael J. Wysocki
2022-07-06 20:26 ` Hans de Goede [this message]
2022-07-07 19:31 ` Rafael J. Wysocki
2022-08-04 11:57 ` Hans de Goede
2022-08-04 13:51 ` Rafael J. Wysocki
2022-08-04 13:57 ` Hans de Goede
2022-08-04 14:08 ` Rafael J. Wysocki
2022-08-04 14:11 ` Rafael J. Wysocki
2022-08-04 15:10 ` Hans de Goede
2022-08-04 15:19 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be219334-456f-c2f1-7102-4a3b01e8cd59@redhat.com \
--to=hdegoede@redhat.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox