linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root
@ 2024-05-10 14:01 Rafael J. Wysocki
  2024-05-10 14:03 ` [PATCH v1 1/2] ACPI: EC: Install " Rafael J. Wysocki
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-10 14:01 UTC (permalink / raw)
  To: Linux ACPI
  Cc: LKML, Andy Shevchenko, Hans de Goede, Mario Limonciello,
	Armin Wolf, Heikki Krogerus

Hi Everyone,

This is a follow up for the discussion in:

https://lore.kernel.org/linux-acpi/CAJZ5v0hiXdv08PRcop7oSYqgr_g5rwzRTj7HgdNCCGjXeV44zA@mail.gmail.com/T/#t

Patch [1/2] is a resend of the patch posted in the thread above and patch [2/2]
removes the custom EC address space handler from the WMI driver as it should
not be necessary any more.

Thanks!




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 14:01 [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Rafael J. Wysocki
@ 2024-05-10 14:03 ` Rafael J. Wysocki
  2024-05-10 16:10   ` Armin Wolf
  2024-05-10 14:04 ` [PATCH v1 2/2] platform/x86: wmi: Remove custom EC address space handler Rafael J. Wysocki
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-10 14:03 UTC (permalink / raw)
  To: Linux ACPI
  Cc: LKML, Andy Shevchenko, Hans de Goede, Mario Limonciello,
	Armin Wolf, Heikki Krogerus

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
IdeaPad Pro 5 due to a missing address space handler for the EC address
space:

 ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)

This happens because the EC driver only registers the EC address space
handler for operation regions defined in the EC device scope of the
ACPI namespace while the operation region being accessed by the _DSM
in question is located beyond that scope.

To address this, modify the ACPI EC driver to install the EC address
space handler at the root of the ACPI namespace.

Note that this change is consistent with some examples in the ACPI
specification in which EC operation regions located outside the EC
device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
so the current behavior of the EC driver is arguably questionable.

Reported-by: webcaptcha <webcapcha@gmail.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218789
Link: https://uefi.org/specs/ACPI/6.5/09_ACPI_Defined_Devices_and_Device_Specific_Objects.html#example-asl-code
Link: https://lore.kernel.org/linux-acpi/Zi+0whTvDbAdveHq@kuha.fi.intel.com
Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/ec.c       |   10 +++++-----
 drivers/acpi/internal.h |    1 -
 2 files changed, 5 insertions(+), 6 deletions(-)

Index: linux-pm/drivers/acpi/ec.c
===================================================================
--- linux-pm.orig/drivers/acpi/ec.c
+++ linux-pm/drivers/acpi/ec.c
@@ -1488,7 +1488,7 @@ static int ec_install_handlers(struct ac
 
 	if (!test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) {
 		acpi_ec_enter_noirq(ec);
-		status = acpi_install_address_space_handler_no_reg(ec->handle,
+		status = acpi_install_address_space_handler_no_reg(ACPI_ROOT_OBJECT,
 								   ACPI_ADR_SPACE_EC,
 								   &acpi_ec_space_handler,
 								   NULL, ec);
@@ -1497,11 +1497,10 @@ static int ec_install_handlers(struct ac
 			return -ENODEV;
 		}
 		set_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags);
-		ec->address_space_handler_holder = ec->handle;
 	}
 
 	if (call_reg && !test_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags)) {
-		acpi_execute_reg_methods(ec->handle, ACPI_ADR_SPACE_EC);
+		acpi_execute_reg_methods(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_EC);
 		set_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags);
 	}
 
@@ -1555,8 +1554,9 @@ static void ec_remove_handlers(struct ac
 {
 	if (test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) {
 		if (ACPI_FAILURE(acpi_remove_address_space_handler(
-					ec->address_space_handler_holder,
-					ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
+						ACPI_ROOT_OBJECT,
+						ACPI_ADR_SPACE_EC,
+						&acpi_ec_space_handler)))
 			pr_err("failed to remove space handler\n");
 		clear_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags);
 	}
Index: linux-pm/drivers/acpi/internal.h
===================================================================
--- linux-pm.orig/drivers/acpi/internal.h
+++ linux-pm/drivers/acpi/internal.h
@@ -186,7 +186,6 @@ enum acpi_ec_event_state {
 
 struct acpi_ec {
 	acpi_handle handle;
-	acpi_handle address_space_handler_holder;
 	int gpe;
 	int irq;
 	unsigned long command_addr;




^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v1 2/2] platform/x86: wmi: Remove custom EC address space handler
  2024-05-10 14:01 [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Rafael J. Wysocki
  2024-05-10 14:03 ` [PATCH v1 1/2] ACPI: EC: Install " Rafael J. Wysocki
@ 2024-05-10 14:04 ` Rafael J. Wysocki
  2024-05-10 17:40   ` Armin Wolf
  2024-05-10 14:15 ` [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Mario Limonciello
  2024-05-13  8:10 ` Heikki Krogerus
  3 siblings, 1 reply; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-10 14:04 UTC (permalink / raw)
  To: Linux ACPI
  Cc: LKML, Andy Shevchenko, Hans de Goede, Mario Limonciello,
	Armin Wolf, Heikki Krogerus

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The custom EC address space handler in the WMI driver was only needed
because the EC driver did not install its address space handler for
EC operation regions beyond the EC device scope in the ACPI namespace.

That has just changed, so the custom EC address handler is not needed
any more and it can be removed.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/platform/x86/wmi.c |   62 ---------------------------------------------
 1 file changed, 62 deletions(-)

Index: linux-pm/drivers/platform/x86/wmi.c
===================================================================
--- linux-pm.orig/drivers/platform/x86/wmi.c
+++ linux-pm/drivers/platform/x86/wmi.c
@@ -1153,47 +1153,6 @@ static int parse_wdg(struct device *wmi_
 	return 0;
 }
 
-/*
- * WMI can have EmbeddedControl access regions. In which case, we just want to
- * hand these off to the EC driver.
- */
-static acpi_status
-acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
-			  u32 bits, u64 *value,
-			  void *handler_context, void *region_context)
-{
-	int result = 0;
-	u8 temp = 0;
-
-	if ((address > 0xFF) || !value)
-		return AE_BAD_PARAMETER;
-
-	if (function != ACPI_READ && function != ACPI_WRITE)
-		return AE_BAD_PARAMETER;
-
-	if (bits != 8)
-		return AE_BAD_PARAMETER;
-
-	if (function == ACPI_READ) {
-		result = ec_read(address, &temp);
-		*value = temp;
-	} else {
-		temp = 0xff & *value;
-		result = ec_write(address, temp);
-	}
-
-	switch (result) {
-	case -EINVAL:
-		return AE_BAD_PARAMETER;
-	case -ENODEV:
-		return AE_NOT_FOUND;
-	case -ETIME:
-		return AE_TIME;
-	default:
-		return AE_OK;
-	}
-}
-
 static int wmi_get_notify_data(struct wmi_block *wblock, union acpi_object **obj)
 {
 	struct acpi_buffer data = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -1308,14 +1267,6 @@ static void acpi_wmi_remove_notify_handl
 	acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, acpi_wmi_notify_handler);
 }
 
-static void acpi_wmi_remove_address_space_handler(void *data)
-{
-	struct acpi_device *acpi_device = data;
-
-	acpi_remove_address_space_handler(acpi_device->handle, ACPI_ADR_SPACE_EC,
-					  &acpi_wmi_ec_space_handler);
-}
-
 static void acpi_wmi_remove_bus_device(void *data)
 {
 	struct device *wmi_bus_dev = data;
@@ -1347,19 +1298,6 @@ static int acpi_wmi_probe(struct platfor
 
 	dev_set_drvdata(&device->dev, wmi_bus_dev);
 
-	status = acpi_install_address_space_handler(acpi_device->handle,
-						    ACPI_ADR_SPACE_EC,
-						    &acpi_wmi_ec_space_handler,
-						    NULL, NULL);
-	if (ACPI_FAILURE(status)) {
-		dev_err(&device->dev, "Error installing EC region handler\n");
-		return -ENODEV;
-	}
-	error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_address_space_handler,
-					 acpi_device);
-	if (error < 0)
-		return error;
-
 	status = acpi_install_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY,
 					     acpi_wmi_notify_handler, wmi_bus_dev);
 	if (ACPI_FAILURE(status)) {




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root
  2024-05-10 14:01 [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Rafael J. Wysocki
  2024-05-10 14:03 ` [PATCH v1 1/2] ACPI: EC: Install " Rafael J. Wysocki
  2024-05-10 14:04 ` [PATCH v1 2/2] platform/x86: wmi: Remove custom EC address space handler Rafael J. Wysocki
@ 2024-05-10 14:15 ` Mario Limonciello
  2024-05-13  8:10 ` Heikki Krogerus
  3 siblings, 0 replies; 22+ messages in thread
From: Mario Limonciello @ 2024-05-10 14:15 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linux ACPI
  Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf, Heikki Krogerus

On 5/10/2024 09:01, Rafael J. Wysocki wrote:
> Hi Everyone,
> 
> This is a follow up for the discussion in:
> 
> https://lore.kernel.org/linux-acpi/CAJZ5v0hiXdv08PRcop7oSYqgr_g5rwzRTj7HgdNCCGjXeV44zA@mail.gmail.com/T/#t
> 
> Patch [1/2] is a resend of the patch posted in the thread above and patch [2/2]
> removes the custom EC address space handler from the WMI driver as it should
> not be necessary any more.
> 
> Thanks!
> 
> 
> 

For the series:

Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 14:03 ` [PATCH v1 1/2] ACPI: EC: Install " Rafael J. Wysocki
@ 2024-05-10 16:10   ` Armin Wolf
  2024-05-10 16:41     ` Rafael J. Wysocki
  0 siblings, 1 reply; 22+ messages in thread
From: Armin Wolf @ 2024-05-10 16:10 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linux ACPI
  Cc: LKML, Andy Shevchenko, Hans de Goede, Mario Limonciello, Heikki Krogerus

Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:

> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> IdeaPad Pro 5 due to a missing address space handler for the EC address
> space:
>
>   ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
>
> This happens because the EC driver only registers the EC address space
> handler for operation regions defined in the EC device scope of the
> ACPI namespace while the operation region being accessed by the _DSM
> in question is located beyond that scope.
>
> To address this, modify the ACPI EC driver to install the EC address
> space handler at the root of the ACPI namespace.
>
> Note that this change is consistent with some examples in the ACPI
> specification in which EC operation regions located outside the EC
> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> so the current behavior of the EC driver is arguably questionable.

Hi,

the patch itself looks good to me, but i wonder what happens if multiple
ACPI EC devices are present. How would we handle such a situation?

Thanks,
Armin Wolf

> Reported-by: webcaptcha <webcapcha@gmail.com>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=218789
> Link: https://uefi.org/specs/ACPI/6.5/09_ACPI_Defined_Devices_and_Device_Specific_Objects.html#example-asl-code
> Link: https://lore.kernel.org/linux-acpi/Zi+0whTvDbAdveHq@kuha.fi.intel.com
> Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/acpi/ec.c       |   10 +++++-----
>   drivers/acpi/internal.h |    1 -
>   2 files changed, 5 insertions(+), 6 deletions(-)
>
> Index: linux-pm/drivers/acpi/ec.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/ec.c
> +++ linux-pm/drivers/acpi/ec.c
> @@ -1488,7 +1488,7 @@ static int ec_install_handlers(struct ac
>
>   	if (!test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) {
>   		acpi_ec_enter_noirq(ec);
> -		status = acpi_install_address_space_handler_no_reg(ec->handle,
> +		status = acpi_install_address_space_handler_no_reg(ACPI_ROOT_OBJECT,
>   								   ACPI_ADR_SPACE_EC,
>   								   &acpi_ec_space_handler,
>   								   NULL, ec);
> @@ -1497,11 +1497,10 @@ static int ec_install_handlers(struct ac
>   			return -ENODEV;
>   		}
>   		set_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags);
> -		ec->address_space_handler_holder = ec->handle;
>   	}
>
>   	if (call_reg && !test_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags)) {
> -		acpi_execute_reg_methods(ec->handle, ACPI_ADR_SPACE_EC);
> +		acpi_execute_reg_methods(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_EC);
>   		set_bit(EC_FLAGS_EC_REG_CALLED, &ec->flags);
>   	}
>
> @@ -1555,8 +1554,9 @@ static void ec_remove_handlers(struct ac
>   {
>   	if (test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) {
>   		if (ACPI_FAILURE(acpi_remove_address_space_handler(
> -					ec->address_space_handler_holder,
> -					ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
> +						ACPI_ROOT_OBJECT,
> +						ACPI_ADR_SPACE_EC,
> +						&acpi_ec_space_handler)))
>   			pr_err("failed to remove space handler\n");
>   		clear_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags);
>   	}
> Index: linux-pm/drivers/acpi/internal.h
> ===================================================================
> --- linux-pm.orig/drivers/acpi/internal.h
> +++ linux-pm/drivers/acpi/internal.h
> @@ -186,7 +186,6 @@ enum acpi_ec_event_state {
>
>   struct acpi_ec {
>   	acpi_handle handle;
> -	acpi_handle address_space_handler_holder;
>   	int gpe;
>   	int irq;
>   	unsigned long command_addr;
>
>
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 16:10   ` Armin Wolf
@ 2024-05-10 16:41     ` Rafael J. Wysocki
  2024-05-10 16:52       ` Armin Wolf
  0 siblings, 1 reply; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-10 16:41 UTC (permalink / raw)
  To: Armin Wolf
  Cc: Rafael J. Wysocki, Linux ACPI, LKML, Andy Shevchenko,
	Hans de Goede, Mario Limonciello, Heikki Krogerus

On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
>
> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
>
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> > IdeaPad Pro 5 due to a missing address space handler for the EC address
> > space:
> >
> >   ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> >
> > This happens because the EC driver only registers the EC address space
> > handler for operation regions defined in the EC device scope of the
> > ACPI namespace while the operation region being accessed by the _DSM
> > in question is located beyond that scope.
> >
> > To address this, modify the ACPI EC driver to install the EC address
> > space handler at the root of the ACPI namespace.
> >
> > Note that this change is consistent with some examples in the ACPI
> > specification in which EC operation regions located outside the EC
> > device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> > so the current behavior of the EC driver is arguably questionable.
>
> Hi,
>
> the patch itself looks good to me, but i wonder what happens if multiple
> ACPI EC devices are present. How would we handle such a situation?

I'm wondering if this is a theoretical question or do you have any
existing or planned systems in mind?

ec_read(), ec_write() and ec_transaction() use only the first EC that
has been found anyway.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 16:41     ` Rafael J. Wysocki
@ 2024-05-10 16:52       ` Armin Wolf
  2024-05-10 17:29         ` Andy Shevchenko
  2024-05-10 17:56         ` Rafael J. Wysocki
  0 siblings, 2 replies; 22+ messages in thread
From: Armin Wolf @ 2024-05-10 16:52 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael J. Wysocki, Linux ACPI, LKML, Andy Shevchenko,
	Hans de Goede, Mario Limonciello, Heikki Krogerus

Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:

> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
>>
>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>
>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
>>> IdeaPad Pro 5 due to a missing address space handler for the EC address
>>> space:
>>>
>>>    ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
>>>
>>> This happens because the EC driver only registers the EC address space
>>> handler for operation regions defined in the EC device scope of the
>>> ACPI namespace while the operation region being accessed by the _DSM
>>> in question is located beyond that scope.
>>>
>>> To address this, modify the ACPI EC driver to install the EC address
>>> space handler at the root of the ACPI namespace.
>>>
>>> Note that this change is consistent with some examples in the ACPI
>>> specification in which EC operation regions located outside the EC
>>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
>>> so the current behavior of the EC driver is arguably questionable.
>> Hi,
>>
>> the patch itself looks good to me, but i wonder what happens if multiple
>> ACPI EC devices are present. How would we handle such a situation?
> I'm wondering if this is a theoretical question or do you have any
> existing or planned systems in mind?
>
> ec_read(), ec_write() and ec_transaction() use only the first EC that
> has been found anyway.

Its a theoretical question, i do not know of any systems which have more than
one ACPI EC device.

This patch would prevent any ACPI ECs other than the first one from probing,
since they would fail to register their address space handler.
I am just curious if/how we want to handle such situations.

Thanks,
Armin Wolf


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 16:52       ` Armin Wolf
@ 2024-05-10 17:29         ` Andy Shevchenko
  2024-05-10 17:38           ` Armin Wolf
  2024-05-10 17:40           ` Mario Limonciello
  2024-05-10 17:56         ` Rafael J. Wysocki
  1 sibling, 2 replies; 22+ messages in thread
From: Andy Shevchenko @ 2024-05-10 17:29 UTC (permalink / raw)
  To: Armin Wolf
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux ACPI, LKML,
	Hans de Goede, Mario Limonciello, Heikki Krogerus

On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
> > On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> > > Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> > > 
> > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > > 
> > > > It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> > > > IdeaPad Pro 5 due to a missing address space handler for the EC address
> > > > space:
> > > > 
> > > >    ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> > > > 
> > > > This happens because the EC driver only registers the EC address space
> > > > handler for operation regions defined in the EC device scope of the
> > > > ACPI namespace while the operation region being accessed by the _DSM
> > > > in question is located beyond that scope.
> > > > 
> > > > To address this, modify the ACPI EC driver to install the EC address
> > > > space handler at the root of the ACPI namespace.
> > > > 
> > > > Note that this change is consistent with some examples in the ACPI
> > > > specification in which EC operation regions located outside the EC
> > > > device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> > > > so the current behavior of the EC driver is arguably questionable.
> > > Hi,
> > > 
> > > the patch itself looks good to me, but i wonder what happens if multiple
> > > ACPI EC devices are present. How would we handle such a situation?
> > I'm wondering if this is a theoretical question or do you have any
> > existing or planned systems in mind?
> > 
> > ec_read(), ec_write() and ec_transaction() use only the first EC that
> > has been found anyway.
> 
> Its a theoretical question, i do not know of any systems which have more than
> one ACPI EC device.

The specification is clear about this case in the "ACPI Embedded Controller
Interface Specification":

 "The ACPI standard supports multiple embedded controllers in a system,
  each with its own resources. Each embedded controller has a flat
  byte-addressable I/O space, currently defined as 256 bytes."

However, I haven't checked deeper, so it might be a leftover in the documentation.

The OperationRegion() has no reference to the EC (or in general, device) which
we need to speak to. The only possibility to declare OpRegion() for the second+
EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
supports 2+ ECs, it doesn't support OpRegion():s for them under the same
RegionSpace.

That said, the commit message might be extended to summarize this, but at
the same time I see no way how this series can break anything even in 2+ ECs
environments.

> This patch would prevent any ACPI ECs other than the first one from probing,
> since they would fail to register their address space handler.
> I am just curious if/how we want to handle such situations.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 17:29         ` Andy Shevchenko
@ 2024-05-10 17:38           ` Armin Wolf
  2024-05-10 18:00             ` Rafael J. Wysocki
  2024-05-10 17:40           ` Mario Limonciello
  1 sibling, 1 reply; 22+ messages in thread
From: Armin Wolf @ 2024-05-10 17:38 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux ACPI, LKML,
	Hans de Goede, Mario Limonciello, Heikki Krogerus

Am 10.05.24 um 19:29 schrieb Andy Shevchenko:

> On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
>> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
>>> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
>>>>
>>>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>>>
>>>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
>>>>> IdeaPad Pro 5 due to a missing address space handler for the EC address
>>>>> space:
>>>>>
>>>>>     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
>>>>>
>>>>> This happens because the EC driver only registers the EC address space
>>>>> handler for operation regions defined in the EC device scope of the
>>>>> ACPI namespace while the operation region being accessed by the _DSM
>>>>> in question is located beyond that scope.
>>>>>
>>>>> To address this, modify the ACPI EC driver to install the EC address
>>>>> space handler at the root of the ACPI namespace.
>>>>>
>>>>> Note that this change is consistent with some examples in the ACPI
>>>>> specification in which EC operation regions located outside the EC
>>>>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
>>>>> so the current behavior of the EC driver is arguably questionable.
>>>> Hi,
>>>>
>>>> the patch itself looks good to me, but i wonder what happens if multiple
>>>> ACPI EC devices are present. How would we handle such a situation?
>>> I'm wondering if this is a theoretical question or do you have any
>>> existing or planned systems in mind?
>>>
>>> ec_read(), ec_write() and ec_transaction() use only the first EC that
>>> has been found anyway.
>> Its a theoretical question, i do not know of any systems which have more than
>> one ACPI EC device.
> The specification is clear about this case in the "ACPI Embedded Controller
> Interface Specification":
>
>   "The ACPI standard supports multiple embedded controllers in a system,
>    each with its own resources. Each embedded controller has a flat
>    byte-addressable I/O space, currently defined as 256 bytes."
>
> However, I haven't checked deeper, so it might be a leftover in the documentation.
>
> The OperationRegion() has no reference to the EC (or in general, device) which
> we need to speak to. The only possibility to declare OpRegion() for the second+
> EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> RegionSpace.
>
> That said, the commit message might be extended to summarize this, but at
> the same time I see no way how this series can break anything even in 2+ ECs
> environments.

Consider the following execution flow when the second EC probes:

1. acpi_install_address_space_handler_no_reg() fails with AE_ALREADY_EXISTS since the first EC
has already installed a handler at ACPI_ROOT_OBJECT.

2. ec_install_handlers() fails with -ENODEV.

3. acpi_ec_setup() fails with -ENODEV.

4. acpi_ec_add() fails with -ENODEV.

5. Probe of seconds EC fails with -ENODEV.

This might cause problems if the second EC is supposed to for example handle EC query events.
Of course if we only support a single EC, then this situation cannot happen.

>> This patch would prevent any ACPI ECs other than the first one from probing,
>> since they would fail to register their address space handler.
>> I am just curious if/how we want to handle such situations.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 17:29         ` Andy Shevchenko
  2024-05-10 17:38           ` Armin Wolf
@ 2024-05-10 17:40           ` Mario Limonciello
  2024-05-10 17:47             ` Armin Wolf
  2024-05-10 17:50             ` Andy Shevchenko
  1 sibling, 2 replies; 22+ messages in thread
From: Mario Limonciello @ 2024-05-10 17:40 UTC (permalink / raw)
  To: Andy Shevchenko, Armin Wolf
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux ACPI, LKML,
	Hans de Goede, Heikki Krogerus

On 5/10/2024 12:29, Andy Shevchenko wrote:
> On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
>> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
>>> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
>>>>
>>>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>>>
>>>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
>>>>> IdeaPad Pro 5 due to a missing address space handler for the EC address
>>>>> space:
>>>>>
>>>>>     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
>>>>>
>>>>> This happens because the EC driver only registers the EC address space
>>>>> handler for operation regions defined in the EC device scope of the
>>>>> ACPI namespace while the operation region being accessed by the _DSM
>>>>> in question is located beyond that scope.
>>>>>
>>>>> To address this, modify the ACPI EC driver to install the EC address
>>>>> space handler at the root of the ACPI namespace.
>>>>>
>>>>> Note that this change is consistent with some examples in the ACPI
>>>>> specification in which EC operation regions located outside the EC
>>>>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
>>>>> so the current behavior of the EC driver is arguably questionable.
>>>> Hi,
>>>>
>>>> the patch itself looks good to me, but i wonder what happens if multiple
>>>> ACPI EC devices are present. How would we handle such a situation?
>>> I'm wondering if this is a theoretical question or do you have any
>>> existing or planned systems in mind?
>>>
>>> ec_read(), ec_write() and ec_transaction() use only the first EC that
>>> has been found anyway.
>>
>> Its a theoretical question, i do not know of any systems which have more than
>> one ACPI EC device.
> 
> The specification is clear about this case in the "ACPI Embedded Controller
> Interface Specification":
> 
>   "The ACPI standard supports multiple embedded controllers in a system,
>    each with its own resources. Each embedded controller has a flat
>    byte-addressable I/O space, currently defined as 256 bytes."
> 
> However, I haven't checked deeper, so it might be a leftover in the documentation.
> 
> The OperationRegion() has no reference to the EC (or in general, device) which
> we need to speak to. The only possibility to declare OpRegion() for the second+
> EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> RegionSpace.
> 
> That said, the commit message might be extended to summarize this, but at
> the same time I see no way how this series can break anything even in 2+ ECs
> environments.

It's deviating from the patch, but in practice /why/ would you even want 
to have a design with two ECs?  In general that is going to mean a much 
more complex state machine with synchronizing the interaction between 
both of them and the host.

Understanding the benefit of such a design might make it easier to 
hypothesize impacts.

> 
>> This patch would prevent any ACPI ECs other than the first one from probing,
>> since they would fail to register their address space handler.
>> I am just curious if/how we want to handle such situations.
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 2/2] platform/x86: wmi: Remove custom EC address space handler
  2024-05-10 14:04 ` [PATCH v1 2/2] platform/x86: wmi: Remove custom EC address space handler Rafael J. Wysocki
@ 2024-05-10 17:40   ` Armin Wolf
  0 siblings, 0 replies; 22+ messages in thread
From: Armin Wolf @ 2024-05-10 17:40 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linux ACPI
  Cc: LKML, Andy Shevchenko, Hans de Goede, Mario Limonciello, Heikki Krogerus

Am 10.05.24 um 16:04 schrieb Rafael J. Wysocki:

> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> The custom EC address space handler in the WMI driver was only needed
> because the EC driver did not install its address space handler for
> EC operation regions beyond the EC device scope in the ACPI namespace.
>
> That has just changed, so the custom EC address handler is not needed
> any more and it can be removed.

The patch seems ok to me, but it might conflict with pdx86/for-next.

Other than that:
Reviewed-by: Armin Wolf <W_Armin@gmx.de>

> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/platform/x86/wmi.c |   62 ---------------------------------------------
>   1 file changed, 62 deletions(-)
>
> Index: linux-pm/drivers/platform/x86/wmi.c
> ===================================================================
> --- linux-pm.orig/drivers/platform/x86/wmi.c
> +++ linux-pm/drivers/platform/x86/wmi.c
> @@ -1153,47 +1153,6 @@ static int parse_wdg(struct device *wmi_
>   	return 0;
>   }
>
> -/*
> - * WMI can have EmbeddedControl access regions. In which case, we just want to
> - * hand these off to the EC driver.
> - */
> -static acpi_status
> -acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
> -			  u32 bits, u64 *value,
> -			  void *handler_context, void *region_context)
> -{
> -	int result = 0;
> -	u8 temp = 0;
> -
> -	if ((address > 0xFF) || !value)
> -		return AE_BAD_PARAMETER;
> -
> -	if (function != ACPI_READ && function != ACPI_WRITE)
> -		return AE_BAD_PARAMETER;
> -
> -	if (bits != 8)
> -		return AE_BAD_PARAMETER;
> -
> -	if (function == ACPI_READ) {
> -		result = ec_read(address, &temp);
> -		*value = temp;
> -	} else {
> -		temp = 0xff & *value;
> -		result = ec_write(address, temp);
> -	}
> -
> -	switch (result) {
> -	case -EINVAL:
> -		return AE_BAD_PARAMETER;
> -	case -ENODEV:
> -		return AE_NOT_FOUND;
> -	case -ETIME:
> -		return AE_TIME;
> -	default:
> -		return AE_OK;
> -	}
> -}
> -
>   static int wmi_get_notify_data(struct wmi_block *wblock, union acpi_object **obj)
>   {
>   	struct acpi_buffer data = { ACPI_ALLOCATE_BUFFER, NULL };
> @@ -1308,14 +1267,6 @@ static void acpi_wmi_remove_notify_handl
>   	acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, acpi_wmi_notify_handler);
>   }
>
> -static void acpi_wmi_remove_address_space_handler(void *data)
> -{
> -	struct acpi_device *acpi_device = data;
> -
> -	acpi_remove_address_space_handler(acpi_device->handle, ACPI_ADR_SPACE_EC,
> -					  &acpi_wmi_ec_space_handler);
> -}
> -
>   static void acpi_wmi_remove_bus_device(void *data)
>   {
>   	struct device *wmi_bus_dev = data;
> @@ -1347,19 +1298,6 @@ static int acpi_wmi_probe(struct platfor
>
>   	dev_set_drvdata(&device->dev, wmi_bus_dev);
>
> -	status = acpi_install_address_space_handler(acpi_device->handle,
> -						    ACPI_ADR_SPACE_EC,
> -						    &acpi_wmi_ec_space_handler,
> -						    NULL, NULL);
> -	if (ACPI_FAILURE(status)) {
> -		dev_err(&device->dev, "Error installing EC region handler\n");
> -		return -ENODEV;
> -	}
> -	error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_address_space_handler,
> -					 acpi_device);
> -	if (error < 0)
> -		return error;
> -
>   	status = acpi_install_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY,
>   					     acpi_wmi_notify_handler, wmi_bus_dev);
>   	if (ACPI_FAILURE(status)) {
>
>
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 17:40           ` Mario Limonciello
@ 2024-05-10 17:47             ` Armin Wolf
  2024-05-10 17:50             ` Andy Shevchenko
  1 sibling, 0 replies; 22+ messages in thread
From: Armin Wolf @ 2024-05-10 17:47 UTC (permalink / raw)
  To: Mario Limonciello, Andy Shevchenko
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux ACPI, LKML,
	Hans de Goede, Heikki Krogerus

Am 10.05.24 um 19:40 schrieb Mario Limonciello:

> On 5/10/2024 12:29, Andy Shevchenko wrote:
>> On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
>>> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
>>>> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>>>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
>>>>>
>>>>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>>>>
>>>>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on
>>>>>> Lenovo
>>>>>> IdeaPad Pro 5 due to a missing address space handler for the EC
>>>>>> address
>>>>>> space:
>>>>>>
>>>>>>     ACPI Error: No handler for Region [ECSI] (000000007b8176ee)
>>>>>> [EmbeddedControl] (20230628/evregion-130)
>>>>>>
>>>>>> This happens because the EC driver only registers the EC address
>>>>>> space
>>>>>> handler for operation regions defined in the EC device scope of the
>>>>>> ACPI namespace while the operation region being accessed by the _DSM
>>>>>> in question is located beyond that scope.
>>>>>>
>>>>>> To address this, modify the ACPI EC driver to install the EC address
>>>>>> space handler at the root of the ACPI namespace.
>>>>>>
>>>>>> Note that this change is consistent with some examples in the ACPI
>>>>>> specification in which EC operation regions located outside the EC
>>>>>> device scope are used (for example, see Section 9.17.15 in ACPI
>>>>>> 6.5),
>>>>>> so the current behavior of the EC driver is arguably questionable.
>>>>> Hi,
>>>>>
>>>>> the patch itself looks good to me, but i wonder what happens if
>>>>> multiple
>>>>> ACPI EC devices are present. How would we handle such a situation?
>>>> I'm wondering if this is a theoretical question or do you have any
>>>> existing or planned systems in mind?
>>>>
>>>> ec_read(), ec_write() and ec_transaction() use only the first EC that
>>>> has been found anyway.
>>>
>>> Its a theoretical question, i do not know of any systems which have
>>> more than
>>> one ACPI EC device.
>>
>> The specification is clear about this case in the "ACPI Embedded
>> Controller
>> Interface Specification":
>>
>>   "The ACPI standard supports multiple embedded controllers in a system,
>>    each with its own resources. Each embedded controller has a flat
>>    byte-addressable I/O space, currently defined as 256 bytes."
>>
>> However, I haven't checked deeper, so it might be a leftover in the
>> documentation.
>>
>> The OperationRegion() has no reference to the EC (or in general,
>> device) which
>> we need to speak to. The only possibility to declare OpRegion() for
>> the second+
>> EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI
>> specification
>> supports 2+ ECs, it doesn't support OpRegion():s for them under the same
>> RegionSpace.
>>
>> That said, the commit message might be extended to summarize this,
>> but at
>> the same time I see no way how this series can break anything even in
>> 2+ ECs
>> environments.
>
> It's deviating from the patch, but in practice /why/ would you even
> want to have a design with two ECs?  In general that is going to mean
> a much more complex state machine with synchronizing the interaction
> between both of them and the host.
>
> Understanding the benefit of such a design might make it easier to
> hypothesize impacts.
>
I am not saying that such designs would make sense, it was a theoretical question only.

Maybe we can just add a small note to the Linux ACPI documentation saying that we only
support a single EC device?

Thanks,
Armin Wolf

>>
>>> This patch would prevent any ACPI ECs other than the first one from
>>> probing,
>>> since they would fail to register their address space handler.
>>> I am just curious if/how we want to handle such situations.
>>
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 17:40           ` Mario Limonciello
  2024-05-10 17:47             ` Armin Wolf
@ 2024-05-10 17:50             ` Andy Shevchenko
  2024-05-10 17:54               ` Andy Shevchenko
  2024-05-10 18:06               ` Rafael J. Wysocki
  1 sibling, 2 replies; 22+ messages in thread
From: Andy Shevchenko @ 2024-05-10 17:50 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Armin Wolf, Rafael J. Wysocki, Rafael J. Wysocki, Linux ACPI,
	LKML, Hans de Goede, Heikki Krogerus

On Fri, May 10, 2024 at 12:40:05PM -0500, Mario Limonciello wrote:
> On 5/10/2024 12:29, Andy Shevchenko wrote:
> > On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
> > > Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
> > > > On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> > > > > Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> > > > > 
> > > > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > > > > 
> > > > > > It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> > > > > > IdeaPad Pro 5 due to a missing address space handler for the EC address
> > > > > > space:
> > > > > > 
> > > > > >     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> > > > > > 
> > > > > > This happens because the EC driver only registers the EC address space
> > > > > > handler for operation regions defined in the EC device scope of the
> > > > > > ACPI namespace while the operation region being accessed by the _DSM
> > > > > > in question is located beyond that scope.
> > > > > > 
> > > > > > To address this, modify the ACPI EC driver to install the EC address
> > > > > > space handler at the root of the ACPI namespace.
> > > > > > 
> > > > > > Note that this change is consistent with some examples in the ACPI
> > > > > > specification in which EC operation regions located outside the EC
> > > > > > device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> > > > > > so the current behavior of the EC driver is arguably questionable.
> > > > > Hi,
> > > > > 
> > > > > the patch itself looks good to me, but i wonder what happens if multiple
> > > > > ACPI EC devices are present. How would we handle such a situation?
> > > > I'm wondering if this is a theoretical question or do you have any
> > > > existing or planned systems in mind?
> > > > 
> > > > ec_read(), ec_write() and ec_transaction() use only the first EC that
> > > > has been found anyway.
> > > 
> > > Its a theoretical question, i do not know of any systems which have more than
> > > one ACPI EC device.
> > 
> > The specification is clear about this case in the "ACPI Embedded Controller
> > Interface Specification":
> > 
> >   "The ACPI standard supports multiple embedded controllers in a system,
> >    each with its own resources. Each embedded controller has a flat
> >    byte-addressable I/O space, currently defined as 256 bytes."
> > 
> > However, I haven't checked deeper, so it might be a leftover in the documentation.
> > 
> > The OperationRegion() has no reference to the EC (or in general, device) which
> > we need to speak to. The only possibility to declare OpRegion() for the second+
> > EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> > supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> > RegionSpace.
> > 
> > That said, the commit message might be extended to summarize this, but at
> > the same time I see no way how this series can break anything even in 2+ ECs
> > environments.
> 
> It's deviating from the patch, but in practice /why/ would you even want to
> have a design with two ECs?  In general that is going to mean a much more
> complex state machine with synchronizing the interaction between both of
> them and the host.
> 
> Understanding the benefit of such a design might make it easier to
> hypothesize impacts.

First that comes to my mind (but hypothetical), is the separate CPU/EC add-on
cards. If the main firmware somehow supports all of these add-on platforms,
it might need to handle 2+ ECs.

Again, it might be ACPI specification issue. For instance, the cited piece
doesn't tell about 16-bit EC accesses.

> > > This patch would prevent any ACPI ECs other than the first one from probing,
> > > since they would fail to register their address space handler.
> > > I am just curious if/how we want to handle such situations.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 17:50             ` Andy Shevchenko
@ 2024-05-10 17:54               ` Andy Shevchenko
  2024-05-10 18:06               ` Rafael J. Wysocki
  1 sibling, 0 replies; 22+ messages in thread
From: Andy Shevchenko @ 2024-05-10 17:54 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Armin Wolf, Rafael J. Wysocki, Rafael J. Wysocki, Linux ACPI,
	LKML, Hans de Goede, Heikki Krogerus

On Fri, May 10, 2024 at 08:50:29PM +0300, Andy Shevchenko wrote:
> On Fri, May 10, 2024 at 12:40:05PM -0500, Mario Limonciello wrote:
> > On 5/10/2024 12:29, Andy Shevchenko wrote:
> > > On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
> > > > Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
> > > > > On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> > > > > > Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> > > > > > 
> > > > > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > > > > > 
> > > > > > > It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> > > > > > > IdeaPad Pro 5 due to a missing address space handler for the EC address
> > > > > > > space:
> > > > > > > 
> > > > > > >     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> > > > > > > 
> > > > > > > This happens because the EC driver only registers the EC address space
> > > > > > > handler for operation regions defined in the EC device scope of the
> > > > > > > ACPI namespace while the operation region being accessed by the _DSM
> > > > > > > in question is located beyond that scope.
> > > > > > > 
> > > > > > > To address this, modify the ACPI EC driver to install the EC address
> > > > > > > space handler at the root of the ACPI namespace.
> > > > > > > 
> > > > > > > Note that this change is consistent with some examples in the ACPI
> > > > > > > specification in which EC operation regions located outside the EC
> > > > > > > device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> > > > > > > so the current behavior of the EC driver is arguably questionable.
> > > > > > Hi,
> > > > > > 
> > > > > > the patch itself looks good to me, but i wonder what happens if multiple
> > > > > > ACPI EC devices are present. How would we handle such a situation?
> > > > > I'm wondering if this is a theoretical question or do you have any
> > > > > existing or planned systems in mind?
> > > > > 
> > > > > ec_read(), ec_write() and ec_transaction() use only the first EC that
> > > > > has been found anyway.
> > > > 
> > > > Its a theoretical question, i do not know of any systems which have more than
> > > > one ACPI EC device.
> > > 
> > > The specification is clear about this case in the "ACPI Embedded Controller
> > > Interface Specification":
> > > 
> > >   "The ACPI standard supports multiple embedded controllers in a system,
> > >    each with its own resources. Each embedded controller has a flat
> > >    byte-addressable I/O space, currently defined as 256 bytes."
> > > 
> > > However, I haven't checked deeper, so it might be a leftover in the documentation.
> > > 
> > > The OperationRegion() has no reference to the EC (or in general, device) which
> > > we need to speak to. The only possibility to declare OpRegion() for the second+
> > > EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> > > supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> > > RegionSpace.
> > > 
> > > That said, the commit message might be extended to summarize this, but at
> > > the same time I see no way how this series can break anything even in 2+ ECs
> > > environments.
> > 
> > It's deviating from the patch, but in practice /why/ would you even want to
> > have a design with two ECs?  In general that is going to mean a much more
> > complex state machine with synchronizing the interaction between both of
> > them and the host.
> > 
> > Understanding the benefit of such a design might make it easier to
> > hypothesize impacts.
> 
> First that comes to my mind (but hypothetical), is the separate CPU/EC add-on
> cards. If the main firmware somehow supports all of these add-on platforms,
> it might need to handle 2+ ECs.
> 
> Again, it might be ACPI specification issue. For instance, the cited piece
> doesn't tell about 16-bit EC accesses.

Chapter "4.8.4.2.2 Embedded Controller" among other says:

  "Additionally the embedded controller can support up to 255 generic events
   per embedded controller, referred to as query events."

So, if specification needs an update, it should be very carefully proof-read.

> > > > This patch would prevent any ACPI ECs other than the first one from probing,
> > > > since they would fail to register their address space handler.
> > > > I am just curious if/how we want to handle such situations.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 16:52       ` Armin Wolf
  2024-05-10 17:29         ` Andy Shevchenko
@ 2024-05-10 17:56         ` Rafael J. Wysocki
  1 sibling, 0 replies; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-10 17:56 UTC (permalink / raw)
  To: Armin Wolf
  Cc: Rafael J. Wysocki, Rafael J. Wysocki, Linux ACPI, LKML,
	Andy Shevchenko, Hans de Goede, Mario Limonciello,
	Heikki Krogerus

On Fri, May 10, 2024 at 6:52 PM Armin Wolf <W_Armin@gmx.de> wrote:
>
> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
>
> > On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> >> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> >>
> >>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >>>
> >>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> >>> IdeaPad Pro 5 due to a missing address space handler for the EC address
> >>> space:
> >>>
> >>>    ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> >>>
> >>> This happens because the EC driver only registers the EC address space
> >>> handler for operation regions defined in the EC device scope of the
> >>> ACPI namespace while the operation region being accessed by the _DSM
> >>> in question is located beyond that scope.
> >>>
> >>> To address this, modify the ACPI EC driver to install the EC address
> >>> space handler at the root of the ACPI namespace.
> >>>
> >>> Note that this change is consistent with some examples in the ACPI
> >>> specification in which EC operation regions located outside the EC
> >>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> >>> so the current behavior of the EC driver is arguably questionable.
> >> Hi,
> >>
> >> the patch itself looks good to me, but i wonder what happens if multiple
> >> ACPI EC devices are present. How would we handle such a situation?
> > I'm wondering if this is a theoretical question or do you have any
> > existing or planned systems in mind?
> >
> > ec_read(), ec_write() and ec_transaction() use only the first EC that
> > has been found anyway.
>
> Its a theoretical question, i do not know of any systems which have more than
> one ACPI EC device.
>
> This patch would prevent any ACPI ECs other than the first one from probing,
> since they would fail to register their address space handler.
> I am just curious if/how we want to handle such situations.

I'm not worried until I see a system where that is a problem.

That said, it can be addressed by adding a first_ec check around the
address space handler registration/unregistration.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 17:38           ` Armin Wolf
@ 2024-05-10 18:00             ` Rafael J. Wysocki
  2024-05-11 14:22               ` Hans de Goede
  0 siblings, 1 reply; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-10 18:00 UTC (permalink / raw)
  To: Armin Wolf
  Cc: Andy Shevchenko, Rafael J. Wysocki, Rafael J. Wysocki,
	Linux ACPI, LKML, Hans de Goede, Mario Limonciello,
	Heikki Krogerus

On Fri, May 10, 2024 at 7:39 PM Armin Wolf <W_Armin@gmx.de> wrote:
>
> Am 10.05.24 um 19:29 schrieb Andy Shevchenko:
>
> > On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
> >> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
> >>> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> >>>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> >>>>
> >>>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >>>>>
> >>>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> >>>>> IdeaPad Pro 5 due to a missing address space handler for the EC address
> >>>>> space:
> >>>>>
> >>>>>     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> >>>>>
> >>>>> This happens because the EC driver only registers the EC address space
> >>>>> handler for operation regions defined in the EC device scope of the
> >>>>> ACPI namespace while the operation region being accessed by the _DSM
> >>>>> in question is located beyond that scope.
> >>>>>
> >>>>> To address this, modify the ACPI EC driver to install the EC address
> >>>>> space handler at the root of the ACPI namespace.
> >>>>>
> >>>>> Note that this change is consistent with some examples in the ACPI
> >>>>> specification in which EC operation regions located outside the EC
> >>>>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> >>>>> so the current behavior of the EC driver is arguably questionable.
> >>>> Hi,
> >>>>
> >>>> the patch itself looks good to me, but i wonder what happens if multiple
> >>>> ACPI EC devices are present. How would we handle such a situation?
> >>> I'm wondering if this is a theoretical question or do you have any
> >>> existing or planned systems in mind?
> >>>
> >>> ec_read(), ec_write() and ec_transaction() use only the first EC that
> >>> has been found anyway.
> >> Its a theoretical question, i do not know of any systems which have more than
> >> one ACPI EC device.
> > The specification is clear about this case in the "ACPI Embedded Controller
> > Interface Specification":
> >
> >   "The ACPI standard supports multiple embedded controllers in a system,
> >    each with its own resources. Each embedded controller has a flat
> >    byte-addressable I/O space, currently defined as 256 bytes."
> >
> > However, I haven't checked deeper, so it might be a leftover in the documentation.
> >
> > The OperationRegion() has no reference to the EC (or in general, device) which
> > we need to speak to. The only possibility to declare OpRegion() for the second+
> > EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> > supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> > RegionSpace.
> >
> > That said, the commit message might be extended to summarize this, but at
> > the same time I see no way how this series can break anything even in 2+ ECs
> > environments.
>
> Consider the following execution flow when the second EC probes:
>
> 1. acpi_install_address_space_handler_no_reg() fails with AE_ALREADY_EXISTS since the first EC
> has already installed a handler at ACPI_ROOT_OBJECT.
>
> 2. ec_install_handlers() fails with -ENODEV.
>
> 3. acpi_ec_setup() fails with -ENODEV.
>
> 4. acpi_ec_add() fails with -ENODEV.
>
> 5. Probe of seconds EC fails with -ENODEV.
>
> This might cause problems if the second EC is supposed to for example handle EC query events.
> Of course if we only support a single EC, then this situation cannot happen.

This is kind of moot though until a system with 2 ECs is available.
It is hard to say whether or not it is supported until it can be
tested.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 17:50             ` Andy Shevchenko
  2024-05-10 17:54               ` Andy Shevchenko
@ 2024-05-10 18:06               ` Rafael J. Wysocki
  2024-05-10 18:17                 ` Andy Shevchenko
  1 sibling, 1 reply; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-10 18:06 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Mario Limonciello, Armin Wolf, Rafael J. Wysocki,
	Rafael J. Wysocki, Linux ACPI, LKML, Hans de Goede,
	Heikki Krogerus

On Fri, May 10, 2024 at 7:50 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Fri, May 10, 2024 at 12:40:05PM -0500, Mario Limonciello wrote:
> > On 5/10/2024 12:29, Andy Shevchenko wrote:
> > > On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
> > > > Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
> > > > > On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> > > > > > Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> > > > > >
> > > > > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > > > > >
> > > > > > > It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> > > > > > > IdeaPad Pro 5 due to a missing address space handler for the EC address
> > > > > > > space:
> > > > > > >
> > > > > > >     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> > > > > > >
> > > > > > > This happens because the EC driver only registers the EC address space
> > > > > > > handler for operation regions defined in the EC device scope of the
> > > > > > > ACPI namespace while the operation region being accessed by the _DSM
> > > > > > > in question is located beyond that scope.
> > > > > > >
> > > > > > > To address this, modify the ACPI EC driver to install the EC address
> > > > > > > space handler at the root of the ACPI namespace.
> > > > > > >
> > > > > > > Note that this change is consistent with some examples in the ACPI
> > > > > > > specification in which EC operation regions located outside the EC
> > > > > > > device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> > > > > > > so the current behavior of the EC driver is arguably questionable.
> > > > > > Hi,
> > > > > >
> > > > > > the patch itself looks good to me, but i wonder what happens if multiple
> > > > > > ACPI EC devices are present. How would we handle such a situation?
> > > > > I'm wondering if this is a theoretical question or do you have any
> > > > > existing or planned systems in mind?
> > > > >
> > > > > ec_read(), ec_write() and ec_transaction() use only the first EC that
> > > > > has been found anyway.
> > > >
> > > > Its a theoretical question, i do not know of any systems which have more than
> > > > one ACPI EC device.
> > >
> > > The specification is clear about this case in the "ACPI Embedded Controller
> > > Interface Specification":
> > >
> > >   "The ACPI standard supports multiple embedded controllers in a system,
> > >    each with its own resources. Each embedded controller has a flat
> > >    byte-addressable I/O space, currently defined as 256 bytes."
> > >
> > > However, I haven't checked deeper, so it might be a leftover in the documentation.
> > >
> > > The OperationRegion() has no reference to the EC (or in general, device) which
> > > we need to speak to. The only possibility to declare OpRegion() for the second+
> > > EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> > > supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> > > RegionSpace.
> > >
> > > That said, the commit message might be extended to summarize this, but at
> > > the same time I see no way how this series can break anything even in 2+ ECs
> > > environments.
> >
> > It's deviating from the patch, but in practice /why/ would you even want to
> > have a design with two ECs?  In general that is going to mean a much more
> > complex state machine with synchronizing the interaction between both of
> > them and the host.
> >
> > Understanding the benefit of such a design might make it easier to
> > hypothesize impacts.
>
> First that comes to my mind (but hypothetical), is the separate CPU/EC add-on
> cards. If the main firmware somehow supports all of these add-on platforms,
> it might need to handle 2+ ECs.
>
> Again, it might be ACPI specification issue. For instance, the cited piece
> doesn't tell about 16-bit EC accesses.

IMV this is a matter of what is testable.

We can only seriously say that we support 1 EC in the system, because
that's what we can test.

Now, the specification allows (theoretically) multiple ECs to be
supported which does not mean that it will ever be done in practice
and it also does not mean that this is a good idea.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 18:06               ` Rafael J. Wysocki
@ 2024-05-10 18:17                 ` Andy Shevchenko
  0 siblings, 0 replies; 22+ messages in thread
From: Andy Shevchenko @ 2024-05-10 18:17 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mario Limonciello, Armin Wolf, Rafael J. Wysocki, Linux ACPI,
	LKML, Hans de Goede, Heikki Krogerus

On Fri, May 10, 2024 at 08:06:11PM +0200, Rafael J. Wysocki wrote:
> On Fri, May 10, 2024 at 7:50 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Fri, May 10, 2024 at 12:40:05PM -0500, Mario Limonciello wrote:
> > > On 5/10/2024 12:29, Andy Shevchenko wrote:
> > > > On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
> > > > > Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
> > > > > > On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> > > > > > > Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> > > > > > >
> > > > > > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > > > > > >
> > > > > > > > It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> > > > > > > > IdeaPad Pro 5 due to a missing address space handler for the EC address
> > > > > > > > space:
> > > > > > > >
> > > > > > > >     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> > > > > > > >
> > > > > > > > This happens because the EC driver only registers the EC address space
> > > > > > > > handler for operation regions defined in the EC device scope of the
> > > > > > > > ACPI namespace while the operation region being accessed by the _DSM
> > > > > > > > in question is located beyond that scope.
> > > > > > > >
> > > > > > > > To address this, modify the ACPI EC driver to install the EC address
> > > > > > > > space handler at the root of the ACPI namespace.
> > > > > > > >
> > > > > > > > Note that this change is consistent with some examples in the ACPI
> > > > > > > > specification in which EC operation regions located outside the EC
> > > > > > > > device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> > > > > > > > so the current behavior of the EC driver is arguably questionable.
> > > > > > > Hi,
> > > > > > >
> > > > > > > the patch itself looks good to me, but i wonder what happens if multiple
> > > > > > > ACPI EC devices are present. How would we handle such a situation?
> > > > > > I'm wondering if this is a theoretical question or do you have any
> > > > > > existing or planned systems in mind?
> > > > > >
> > > > > > ec_read(), ec_write() and ec_transaction() use only the first EC that
> > > > > > has been found anyway.
> > > > >
> > > > > Its a theoretical question, i do not know of any systems which have more than
> > > > > one ACPI EC device.
> > > >
> > > > The specification is clear about this case in the "ACPI Embedded Controller
> > > > Interface Specification":
> > > >
> > > >   "The ACPI standard supports multiple embedded controllers in a system,
> > > >    each with its own resources. Each embedded controller has a flat
> > > >    byte-addressable I/O space, currently defined as 256 bytes."
> > > >
> > > > However, I haven't checked deeper, so it might be a leftover in the documentation.
> > > >
> > > > The OperationRegion() has no reference to the EC (or in general, device) which
> > > > we need to speak to. The only possibility to declare OpRegion() for the second+
> > > > EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> > > > supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> > > > RegionSpace.
> > > >
> > > > That said, the commit message might be extended to summarize this, but at
> > > > the same time I see no way how this series can break anything even in 2+ ECs
> > > > environments.
> > >
> > > It's deviating from the patch, but in practice /why/ would you even want to
> > > have a design with two ECs?  In general that is going to mean a much more
> > > complex state machine with synchronizing the interaction between both of
> > > them and the host.
> > >
> > > Understanding the benefit of such a design might make it easier to
> > > hypothesize impacts.
> >
> > First that comes to my mind (but hypothetical), is the separate CPU/EC add-on
> > cards. If the main firmware somehow supports all of these add-on platforms,
> > it might need to handle 2+ ECs.
> >
> > Again, it might be ACPI specification issue. For instance, the cited piece
> > doesn't tell about 16-bit EC accesses.
> 
> IMV this is a matter of what is testable.
> 
> We can only seriously say that we support 1 EC in the system, because
> that's what we can test.
> 
> Now, the specification allows (theoretically) multiple ECs to be
> supported which does not mean that it will ever be done in practice
> and it also does not mean that this is a good idea.

I briefly read the all mentions of the "Embedded Controller" in the
specification and like 98% implies that the only one is per system. I believe
the specification may be corrected to remove ambiguous plural forms in a couple
(or a few) places. In any case it's a question to ASWG.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-10 18:00             ` Rafael J. Wysocki
@ 2024-05-11 14:22               ` Hans de Goede
  2024-05-14 19:40                 ` Rafael J. Wysocki
  0 siblings, 1 reply; 22+ messages in thread
From: Hans de Goede @ 2024-05-11 14:22 UTC (permalink / raw)
  To: Rafael J. Wysocki, Armin Wolf
  Cc: Andy Shevchenko, Rafael J. Wysocki, Linux ACPI, LKML,
	Mario Limonciello, Heikki Krogerus

Hi Rafael, Armin, et. al.,

On 5/10/24 8:00 PM, Rafael J. Wysocki wrote:
> On Fri, May 10, 2024 at 7:39 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>
>> Am 10.05.24 um 19:29 schrieb Andy Shevchenko:
>>
>>> On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
>>>> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
>>>>> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>>>>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
>>>>>>
>>>>>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>>>>>
>>>>>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
>>>>>>> IdeaPad Pro 5 due to a missing address space handler for the EC address
>>>>>>> space:
>>>>>>>
>>>>>>>     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
>>>>>>>
>>>>>>> This happens because the EC driver only registers the EC address space
>>>>>>> handler for operation regions defined in the EC device scope of the
>>>>>>> ACPI namespace while the operation region being accessed by the _DSM
>>>>>>> in question is located beyond that scope.
>>>>>>>
>>>>>>> To address this, modify the ACPI EC driver to install the EC address
>>>>>>> space handler at the root of the ACPI namespace.
>>>>>>>
>>>>>>> Note that this change is consistent with some examples in the ACPI
>>>>>>> specification in which EC operation regions located outside the EC
>>>>>>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
>>>>>>> so the current behavior of the EC driver is arguably questionable.
>>>>>> Hi,
>>>>>>
>>>>>> the patch itself looks good to me, but i wonder what happens if multiple
>>>>>> ACPI EC devices are present. How would we handle such a situation?
>>>>> I'm wondering if this is a theoretical question or do you have any
>>>>> existing or planned systems in mind?
>>>>>
>>>>> ec_read(), ec_write() and ec_transaction() use only the first EC that
>>>>> has been found anyway.
>>>> Its a theoretical question, i do not know of any systems which have more than
>>>> one ACPI EC device.
>>> The specification is clear about this case in the "ACPI Embedded Controller
>>> Interface Specification":
>>>
>>>   "The ACPI standard supports multiple embedded controllers in a system,
>>>    each with its own resources. Each embedded controller has a flat
>>>    byte-addressable I/O space, currently defined as 256 bytes."
>>>
>>> However, I haven't checked deeper, so it might be a leftover in the documentation.
>>>
>>> The OperationRegion() has no reference to the EC (or in general, device) which
>>> we need to speak to. The only possibility to declare OpRegion() for the second+
>>> EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
>>> supports 2+ ECs, it doesn't support OpRegion():s for them under the same
>>> RegionSpace.
>>>
>>> That said, the commit message might be extended to summarize this, but at
>>> the same time I see no way how this series can break anything even in 2+ ECs
>>> environments.
>>
>> Consider the following execution flow when the second EC probes:
>>
>> 1. acpi_install_address_space_handler_no_reg() fails with AE_ALREADY_EXISTS since the first EC
>> has already installed a handler at ACPI_ROOT_OBJECT.
>>
>> 2. ec_install_handlers() fails with -ENODEV.
>>
>> 3. acpi_ec_setup() fails with -ENODEV.
>>
>> 4. acpi_ec_add() fails with -ENODEV.
>>
>> 5. Probe of seconds EC fails with -ENODEV.
>>
>> This might cause problems if the second EC is supposed to for example handle EC query events.
>> Of course if we only support a single EC, then this situation cannot happen.
> 
> This is kind of moot though until a system with 2 ECs is available.
> It is hard to say whether or not it is supported until it can be
> tested.

I do not believe that this is as theoretical as it sounds though.
If the ECDT and the DSDT disagree on the EC-s command_addr or
data_addr, then the check to re-use the boot_ec acpi_ec object
(struct acpi_ec *boot_ec) in acpi_ec_add() around line 1644:

                if (boot_ec && ec->command_addr == boot_ec->command_addr &&
                    ec->data_addr == boot_ec->data_addr) {

will fail and the separately allocated acpi_ec which "ec" points to at this
point will be kept around (rather then free-ed and replaced with the boot_ec).

And then when the below line runs on the newly allocated ec:

        ret = acpi_ec_setup(ec, device, true);

the newly allocated ec obj does not have EC_FLAGS_EC_HANDLER_INSTALLED set in
ec->flags so this acpi_ec_setup() call will call

               status = acpi_install_address_space_handler_no_reg(ec->handle,
                                                                  ACPI_ADR_SPACE_EC,
                                                                  &acpi_ec_space_handler,
                                                                  NULL, ec);

A second time. Now the above is from the old code and if we currently hit this
then the boot_ec acpi_install_address_space_handler_no_reg() call will have been
done with:

	ec->handle = ACPI_ROOT_OBJECT

and the second call for the not boot_ec matching DSDT EC will use the handle from
the DSDT EC.

Given how much quirks we have to deal with ECDT vs DSDT EC mismatches I'm pretty sure
that there is hw out there were we hit this path and atm we essentially treat that
as 2 ECs routing any OpRegion calls outside of the scope of the DSDT EC handle
to the boot_ec object and OpRegion calls any under the scope of the DSDT EC handle
to the regular "ec" object allocated in acpi_ec_add()

For such buggy hardware the old behavior can be preserved by passing which handle
to use for the acpi_install_address_space_handler_no_reg() call to acpi_ec_setup()
and pass ec->handle, rather then ACPI_ROOT_OBJECT when not re-using
the boot_ec in acpi_ec_add().

I think preserving the old behavior when we hit such buggy hw is the best thing
to do here. While at it we should probably also start logging a warning when
we hit this code path.

This does mean that we also need to keep acpi_ec.address_space_handler_holder
around for when unregistering the opregion handler.

Regards,

Hans



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root
  2024-05-10 14:01 [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Rafael J. Wysocki
                   ` (2 preceding siblings ...)
  2024-05-10 14:15 ` [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Mario Limonciello
@ 2024-05-13  8:10 ` Heikki Krogerus
  3 siblings, 0 replies; 22+ messages in thread
From: Heikki Krogerus @ 2024-05-13  8:10 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux ACPI, LKML, Andy Shevchenko, Hans de Goede,
	Mario Limonciello, Armin Wolf

On Fri, May 10, 2024 at 04:01:41PM +0200, Rafael J. Wysocki wrote:
> Hi Everyone,
> 
> This is a follow up for the discussion in:
> 
> https://lore.kernel.org/linux-acpi/CAJZ5v0hiXdv08PRcop7oSYqgr_g5rwzRTj7HgdNCCGjXeV44zA@mail.gmail.com/T/#t
> 
> Patch [1/2] is a resend of the patch posted in the thread above and patch [2/2]
> removes the custom EC address space handler from the WMI driver as it should
> not be necessary any more.

For the series:

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks Rafael!

-- 
heikki

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-11 14:22               ` Hans de Goede
@ 2024-05-14 19:40                 ` Rafael J. Wysocki
  2024-05-15 10:05                   ` Hans de Goede
  0 siblings, 1 reply; 22+ messages in thread
From: Rafael J. Wysocki @ 2024-05-14 19:40 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Rafael J. Wysocki, Armin Wolf, Andy Shevchenko,
	Rafael J. Wysocki, Linux ACPI, LKML, Mario Limonciello,
	Heikki Krogerus

Hi Hans,

On Sat, May 11, 2024 at 4:22 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Hi Rafael, Armin, et. al.,
>
> On 5/10/24 8:00 PM, Rafael J. Wysocki wrote:
> > On Fri, May 10, 2024 at 7:39 PM Armin Wolf <W_Armin@gmx.de> wrote:
> >>
> >> Am 10.05.24 um 19:29 schrieb Andy Shevchenko:
> >>
> >>> On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
> >>>> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
> >>>>> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
> >>>>>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
> >>>>>>
> >>>>>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >>>>>>>
> >>>>>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
> >>>>>>> IdeaPad Pro 5 due to a missing address space handler for the EC address
> >>>>>>> space:
> >>>>>>>
> >>>>>>>     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
> >>>>>>>
> >>>>>>> This happens because the EC driver only registers the EC address space
> >>>>>>> handler for operation regions defined in the EC device scope of the
> >>>>>>> ACPI namespace while the operation region being accessed by the _DSM
> >>>>>>> in question is located beyond that scope.
> >>>>>>>
> >>>>>>> To address this, modify the ACPI EC driver to install the EC address
> >>>>>>> space handler at the root of the ACPI namespace.
> >>>>>>>
> >>>>>>> Note that this change is consistent with some examples in the ACPI
> >>>>>>> specification in which EC operation regions located outside the EC
> >>>>>>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
> >>>>>>> so the current behavior of the EC driver is arguably questionable.
> >>>>>> Hi,
> >>>>>>
> >>>>>> the patch itself looks good to me, but i wonder what happens if multiple
> >>>>>> ACPI EC devices are present. How would we handle such a situation?
> >>>>> I'm wondering if this is a theoretical question or do you have any
> >>>>> existing or planned systems in mind?
> >>>>>
> >>>>> ec_read(), ec_write() and ec_transaction() use only the first EC that
> >>>>> has been found anyway.
> >>>> Its a theoretical question, i do not know of any systems which have more than
> >>>> one ACPI EC device.
> >>> The specification is clear about this case in the "ACPI Embedded Controller
> >>> Interface Specification":
> >>>
> >>>   "The ACPI standard supports multiple embedded controllers in a system,
> >>>    each with its own resources. Each embedded controller has a flat
> >>>    byte-addressable I/O space, currently defined as 256 bytes."
> >>>
> >>> However, I haven't checked deeper, so it might be a leftover in the documentation.
> >>>
> >>> The OperationRegion() has no reference to the EC (or in general, device) which
> >>> we need to speak to. The only possibility to declare OpRegion() for the second+
> >>> EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
> >>> supports 2+ ECs, it doesn't support OpRegion():s for them under the same
> >>> RegionSpace.
> >>>
> >>> That said, the commit message might be extended to summarize this, but at
> >>> the same time I see no way how this series can break anything even in 2+ ECs
> >>> environments.
> >>
> >> Consider the following execution flow when the second EC probes:
> >>
> >> 1. acpi_install_address_space_handler_no_reg() fails with AE_ALREADY_EXISTS since the first EC
> >> has already installed a handler at ACPI_ROOT_OBJECT.
> >>
> >> 2. ec_install_handlers() fails with -ENODEV.
> >>
> >> 3. acpi_ec_setup() fails with -ENODEV.
> >>
> >> 4. acpi_ec_add() fails with -ENODEV.
> >>
> >> 5. Probe of seconds EC fails with -ENODEV.
> >>
> >> This might cause problems if the second EC is supposed to for example handle EC query events.
> >> Of course if we only support a single EC, then this situation cannot happen.
> >
> > This is kind of moot though until a system with 2 ECs is available.
> > It is hard to say whether or not it is supported until it can be
> > tested.
>
> I do not believe that this is as theoretical as it sounds though.
> If the ECDT and the DSDT disagree on the EC-s command_addr or
> data_addr, then the check to re-use the boot_ec acpi_ec object
> (struct acpi_ec *boot_ec) in acpi_ec_add() around line 1644:
>
>                 if (boot_ec && ec->command_addr == boot_ec->command_addr &&
>                     ec->data_addr == boot_ec->data_addr) {
>
> will fail and the separately allocated acpi_ec which "ec" points to at this
> point will be kept around (rather then free-ed and replaced with the boot_ec).

Good point.

> And then when the below line runs on the newly allocated ec:
>
>         ret = acpi_ec_setup(ec, device, true);
>
> the newly allocated ec obj does not have EC_FLAGS_EC_HANDLER_INSTALLED set in
> ec->flags so this acpi_ec_setup() call will call
>
>                status = acpi_install_address_space_handler_no_reg(ec->handle,
>                                                                   ACPI_ADR_SPACE_EC,
>                                                                   &acpi_ec_space_handler,
>                                                                   NULL, ec);
>
> A second time. Now the above is from the old code and if we currently hit this
> then the boot_ec acpi_install_address_space_handler_no_reg() call will have been
> done with:
>
>         ec->handle = ACPI_ROOT_OBJECT
>
> and the second call for the not boot_ec matching DSDT EC will use the handle from
> the DSDT EC.

If I'm not mistaken, this can be addressed by using ACPI_ROOT_OBJECT
to install the EC address space handler for first_ec only and
ec->handler for the other EC devices found in the ACPI namespace.

This actually is the case when ECDT is present and so (for consistency
and to address the issue leading to the $subject patch) it can be done
when there's no ECDT either.

Note that first_ec is only set once and never cleared (it would be
cleared during the EC driver removal if it were not equal to boot_ec,
but the latter is always the case AFAICS), so there can be only one ec
object with the address equal to first_ec.

> Given how much quirks we have to deal with ECDT vs DSDT EC mismatches I'm pretty sure
> that there is hw out there were we hit this path and atm we essentially treat that
> as 2 ECs routing any OpRegion calls outside of the scope of the DSDT EC handle
> to the boot_ec object and OpRegion calls any under the scope of the DSDT EC handle
> to the regular "ec" object allocated in acpi_ec_add()
>
> For such buggy hardware the old behavior can be preserved by passing which handle
> to use for the acpi_install_address_space_handler_no_reg() call to acpi_ec_setup()
> and pass ec->handle, rather then ACPI_ROOT_OBJECT when not re-using
> the boot_ec in acpi_ec_add().
>
> I think preserving the old behavior when we hit such buggy hw is the best thing
> to do here. While at it we should probably also start logging a warning when
> we hit this code path.

Yes, that would be useful IMV.

> This does mean that we also need to keep acpi_ec.address_space_handler_holder
> around for when unregistering the opregion handler.

Well, see above.

Thanks!

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v1 1/2] ACPI: EC: Install address space handler at the namespace root
  2024-05-14 19:40                 ` Rafael J. Wysocki
@ 2024-05-15 10:05                   ` Hans de Goede
  0 siblings, 0 replies; 22+ messages in thread
From: Hans de Goede @ 2024-05-15 10:05 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Armin Wolf, Andy Shevchenko, Rafael J. Wysocki, Linux ACPI, LKML,
	Mario Limonciello, Heikki Krogerus

Hi Rafael,

On 5/14/24 9:40 PM, Rafael J. Wysocki wrote:
> Hi Hans,
> 
> On Sat, May 11, 2024 at 4:22 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Hi Rafael, Armin, et. al.,
>>
>> On 5/10/24 8:00 PM, Rafael J. Wysocki wrote:
>>> On Fri, May 10, 2024 at 7:39 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>>>
>>>> Am 10.05.24 um 19:29 schrieb Andy Shevchenko:
>>>>
>>>>> On Fri, May 10, 2024 at 06:52:41PM +0200, Armin Wolf wrote:
>>>>>> Am 10.05.24 um 18:41 schrieb Rafael J. Wysocki:
>>>>>>> On Fri, May 10, 2024 at 6:10 PM Armin Wolf <W_Armin@gmx.de> wrote:
>>>>>>>> Am 10.05.24 um 16:03 schrieb Rafael J. Wysocki:
>>>>>>>>
>>>>>>>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>>>>>>>
>>>>>>>>> It is reported that _DSM evaluation fails in ucsi_acpi_dsm() on Lenovo
>>>>>>>>> IdeaPad Pro 5 due to a missing address space handler for the EC address
>>>>>>>>> space:
>>>>>>>>>
>>>>>>>>>     ACPI Error: No handler for Region [ECSI] (000000007b8176ee) [EmbeddedControl] (20230628/evregion-130)
>>>>>>>>>
>>>>>>>>> This happens because the EC driver only registers the EC address space
>>>>>>>>> handler for operation regions defined in the EC device scope of the
>>>>>>>>> ACPI namespace while the operation region being accessed by the _DSM
>>>>>>>>> in question is located beyond that scope.
>>>>>>>>>
>>>>>>>>> To address this, modify the ACPI EC driver to install the EC address
>>>>>>>>> space handler at the root of the ACPI namespace.
>>>>>>>>>
>>>>>>>>> Note that this change is consistent with some examples in the ACPI
>>>>>>>>> specification in which EC operation regions located outside the EC
>>>>>>>>> device scope are used (for example, see Section 9.17.15 in ACPI 6.5),
>>>>>>>>> so the current behavior of the EC driver is arguably questionable.
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> the patch itself looks good to me, but i wonder what happens if multiple
>>>>>>>> ACPI EC devices are present. How would we handle such a situation?
>>>>>>> I'm wondering if this is a theoretical question or do you have any
>>>>>>> existing or planned systems in mind?
>>>>>>>
>>>>>>> ec_read(), ec_write() and ec_transaction() use only the first EC that
>>>>>>> has been found anyway.
>>>>>> Its a theoretical question, i do not know of any systems which have more than
>>>>>> one ACPI EC device.
>>>>> The specification is clear about this case in the "ACPI Embedded Controller
>>>>> Interface Specification":
>>>>>
>>>>>   "The ACPI standard supports multiple embedded controllers in a system,
>>>>>    each with its own resources. Each embedded controller has a flat
>>>>>    byte-addressable I/O space, currently defined as 256 bytes."
>>>>>
>>>>> However, I haven't checked deeper, so it might be a leftover in the documentation.
>>>>>
>>>>> The OperationRegion() has no reference to the EC (or in general, device) which
>>>>> we need to speak to. The only possibility to declare OpRegion() for the second+
>>>>> EC is to use vendor specific RegionSpace, AFAIU. So, even if ACPI specification
>>>>> supports 2+ ECs, it doesn't support OpRegion():s for them under the same
>>>>> RegionSpace.
>>>>>
>>>>> That said, the commit message might be extended to summarize this, but at
>>>>> the same time I see no way how this series can break anything even in 2+ ECs
>>>>> environments.
>>>>
>>>> Consider the following execution flow when the second EC probes:
>>>>
>>>> 1. acpi_install_address_space_handler_no_reg() fails with AE_ALREADY_EXISTS since the first EC
>>>> has already installed a handler at ACPI_ROOT_OBJECT.
>>>>
>>>> 2. ec_install_handlers() fails with -ENODEV.
>>>>
>>>> 3. acpi_ec_setup() fails with -ENODEV.
>>>>
>>>> 4. acpi_ec_add() fails with -ENODEV.
>>>>
>>>> 5. Probe of seconds EC fails with -ENODEV.
>>>>
>>>> This might cause problems if the second EC is supposed to for example handle EC query events.
>>>> Of course if we only support a single EC, then this situation cannot happen.
>>>
>>> This is kind of moot though until a system with 2 ECs is available.
>>> It is hard to say whether or not it is supported until it can be
>>> tested.
>>
>> I do not believe that this is as theoretical as it sounds though.
>> If the ECDT and the DSDT disagree on the EC-s command_addr or
>> data_addr, then the check to re-use the boot_ec acpi_ec object
>> (struct acpi_ec *boot_ec) in acpi_ec_add() around line 1644:
>>
>>                 if (boot_ec && ec->command_addr == boot_ec->command_addr &&
>>                     ec->data_addr == boot_ec->data_addr) {
>>
>> will fail and the separately allocated acpi_ec which "ec" points to at this
>> point will be kept around (rather then free-ed and replaced with the boot_ec).
> 
> Good point.
> 
>> And then when the below line runs on the newly allocated ec:
>>
>>         ret = acpi_ec_setup(ec, device, true);
>>
>> the newly allocated ec obj does not have EC_FLAGS_EC_HANDLER_INSTALLED set in
>> ec->flags so this acpi_ec_setup() call will call
>>
>>                status = acpi_install_address_space_handler_no_reg(ec->handle,
>>                                                                   ACPI_ADR_SPACE_EC,
>>                                                                   &acpi_ec_space_handler,
>>                                                                   NULL, ec);
>>
>> A second time. Now the above is from the old code and if we currently hit this
>> then the boot_ec acpi_install_address_space_handler_no_reg() call will have been
>> done with:
>>
>>         ec->handle = ACPI_ROOT_OBJECT
>>
>> and the second call for the not boot_ec matching DSDT EC will use the handle from
>> the DSDT EC.
> 
> If I'm not mistaken, this can be addressed by using ACPI_ROOT_OBJECT
> to install the EC address space handler for first_ec only and
> ec->handler for the other EC devices found in the ACPI namespace.

Yes that should work and is a nice solution, that would require
moving the setting of first_ec to above the ec_install_handlers()
call in acpi_ec_setup(), with that small change we could do:

                status = acpi_install_address_space_handler_no_reg(
					(ec == first_ec) ? ACPI_ROOT_OBJECT : ec->handle,
                                        ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, NULL, ec);

in ec_install_handlers() and mirror that in ec_remove_handlers().

> 
> This actually is the case when ECDT is present and so (for consistency
> and to address the issue leading to the $subject patch) it can be done
> when there's no ECDT either.
> 
> Note that first_ec is only set once and never cleared (it would be
> cleared during the EC driver removal if it were not equal to boot_ec,
> but the latter is always the case AFAICS), so there can be only one ec
> object with the address equal to first_ec.

Right I was wondering the same, wondering why we have boot boot_ec and
first_ec.

I guess when there is no ECDT we could somehow not find the DSDT defined
EC during acpi_ec_dsdt_probe() due to some weirdness in the DSDT (e.g.
dynamically set _HID) but then find it later, then we would hit a case
where boot_ec is left at NULL and only first_ec is set.

In that case in the theoretical case of acpi_ec_remove() getting called
(which should never happen) then we would clear first_ec. But that clearing
is done by acpi_ec_free() which gets called *after* ec_remove_handlers()
so even then we can still mirror the (ec == first_ec) check in
ec_remove_handlers() and it will do the right thing.

The other way around however, when there is a boot_ec then that will
indeed always be the same as first_ec and first_ec will never get
cleared and this will be the common case.


>> Given how much quirks we have to deal with ECDT vs DSDT EC mismatches I'm pretty sure
>> that there is hw out there were we hit this path and atm we essentially treat that
>> as 2 ECs routing any OpRegion calls outside of the scope of the DSDT EC handle
>> to the boot_ec object and OpRegion calls any under the scope of the DSDT EC handle
>> to the regular "ec" object allocated in acpi_ec_add()
>>
>> For such buggy hardware the old behavior can be preserved by passing which handle
>> to use for the acpi_install_address_space_handler_no_reg() call to acpi_ec_setup()
>> and pass ec->handle, rather then ACPI_ROOT_OBJECT when not re-using
>> the boot_ec in acpi_ec_add().
>>
>> I think preserving the old behavior when we hit such buggy hw is the best thing
>> to do here. While at it we should probably also start logging a warning when
>> we hit this code path.
> 
> Yes, that would be useful IMV.
> 
>> This does mean that we also need to keep acpi_ec.address_space_handler_holder
>> around for when unregistering the opregion handler.
> 
> Well, see above.

Ack.

TL;DR: I like your suggestion of doing something like:

                status = acpi_install_address_space_handler_no_reg(
					(ec == first_ec) ? ACPI_ROOT_OBJECT : ec->handle,
                                        ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, NULL, ec);

And drop acpi_ec.address_space_handler_holder, so lets go with that.

Regards,

Hans



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-05-15 10:05 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-10 14:01 [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Rafael J. Wysocki
2024-05-10 14:03 ` [PATCH v1 1/2] ACPI: EC: Install " Rafael J. Wysocki
2024-05-10 16:10   ` Armin Wolf
2024-05-10 16:41     ` Rafael J. Wysocki
2024-05-10 16:52       ` Armin Wolf
2024-05-10 17:29         ` Andy Shevchenko
2024-05-10 17:38           ` Armin Wolf
2024-05-10 18:00             ` Rafael J. Wysocki
2024-05-11 14:22               ` Hans de Goede
2024-05-14 19:40                 ` Rafael J. Wysocki
2024-05-15 10:05                   ` Hans de Goede
2024-05-10 17:40           ` Mario Limonciello
2024-05-10 17:47             ` Armin Wolf
2024-05-10 17:50             ` Andy Shevchenko
2024-05-10 17:54               ` Andy Shevchenko
2024-05-10 18:06               ` Rafael J. Wysocki
2024-05-10 18:17                 ` Andy Shevchenko
2024-05-10 17:56         ` Rafael J. Wysocki
2024-05-10 14:04 ` [PATCH v1 2/2] platform/x86: wmi: Remove custom EC address space handler Rafael J. Wysocki
2024-05-10 17:40   ` Armin Wolf
2024-05-10 14:15 ` [PATCH v1 0/2] ACPI: EC: Install EC address space handler at the namespace root Mario Limonciello
2024-05-13  8:10 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).