diff mbox series

[v2] pinctrl: cherryview: Ensure _REG(ACPI_ADR_SPACE_GPIO, 1) gets called

Message ID 20200504145957.480418-1-hdegoede@redhat.com
State New
Headers show
Series [v2] pinctrl: cherryview: Ensure _REG(ACPI_ADR_SPACE_GPIO, 1) gets called | expand

Commit Message

Hans de Goede May 4, 2020, 2:59 p.m. UTC
On Cherry Trail devices there are 2 possible ACPI OpRegions for
accessing GPIOs. The standard GeneralPurposeIo OpRegion and the Cherry
Trail specific UserDefined 0x9X OpRegions.

Having 2 different types of OpRegions leads to potential issues with
checks for OpRegion availability, or in other words checks if _REG has
been called for the OpRegion which the ACPI code wants to use.

The ACPICA core does not call _REG on an ACPI node which does not
define an OpRegion matching the type being registered; and the reference
design DSDT, from which most Cherry Trail DSDTs are derived, does not
define GeneralPurposeIo, nor UserDefined(0x93) OpRegions for the GPO2
(UID 3) device, because no pins were assigned ACPI controlled functions
in the reference design.

Together this leads to the perfect storm, at least on the Cherry Trail
based Medion Akayo E1239T. This design does use a GPO2 pin from its ACPI
code and has added the Cherry Trail specific UserDefined(0x93) opregion
to its GPO2 ACPI node to access this pin.

But it uses a has _REG been called availability check for the standard
GeneralPurposeIo OpRegion. This clearly is a bug in the DSDT, but this
does work under Windows. This issue leads to the intel_vbtn driver
reporting the device always being in tablet-mode at boot, even if it
is in laptop mode. Which in turn causes userspace to ignore touchpad
events. So iow this issues causes the touchpad to not work at boot.

Since the bug in the DSDT stems from the confusion of having 2 different
OpRegion types for accessing GPIOs on Cherry Trail devices, I believe
that this is best fixed inside the Cherryview pinctrl driver.

This commit adds a workaround to the Cherryview pinctrl driver so
that the DSDT's expectations of _REG always getting called for the
GeneralPurposeIo OpRegion are met.

Cc: stable@vger.kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
- Drop unnecessary if (acpi_has_method(adev->handle, "_REG")) check
- Fix Cherryview spelling in the commit message
---
 drivers/pinctrl/intel/pinctrl-cherryview.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Mika Westerberg May 6, 2020, 6:40 a.m. UTC | #1
+Rafael and ACPICA folks.

On Mon, May 04, 2020 at 04:59:57PM +0200, Hans de Goede wrote:
> On Cherry Trail devices there are 2 possible ACPI OpRegions for
> accessing GPIOs. The standard GeneralPurposeIo OpRegion and the Cherry
> Trail specific UserDefined 0x9X OpRegions.
> 
> Having 2 different types of OpRegions leads to potential issues with
> checks for OpRegion availability, or in other words checks if _REG has
> been called for the OpRegion which the ACPI code wants to use.
> 
> The ACPICA core does not call _REG on an ACPI node which does not
> define an OpRegion matching the type being registered; and the reference
> design DSDT, from which most Cherry Trail DSDTs are derived, does not
> define GeneralPurposeIo, nor UserDefined(0x93) OpRegions for the GPO2
> (UID 3) device, because no pins were assigned ACPI controlled functions
> in the reference design.
> 
> Together this leads to the perfect storm, at least on the Cherry Trail
> based Medion Akayo E1239T. This design does use a GPO2 pin from its ACPI
> code and has added the Cherry Trail specific UserDefined(0x93) opregion
> to its GPO2 ACPI node to access this pin.
> 
> But it uses a has _REG been called availability check for the standard
> GeneralPurposeIo OpRegion. This clearly is a bug in the DSDT, but this
> does work under Windows.

Do we know why this works under Windows? I mean if possible we should do
the same and I kind of suspect that they forcibly call _REG in their
GPIO driver.

Are the ACPI tables from this system available somewhere?

> This issue leads to the intel_vbtn driver
> reporting the device always being in tablet-mode at boot, even if it
> is in laptop mode. Which in turn causes userspace to ignore touchpad
> events. So iow this issues causes the touchpad to not work at boot.
> 
> Since the bug in the DSDT stems from the confusion of having 2 different
> OpRegion types for accessing GPIOs on Cherry Trail devices, I believe
> that this is best fixed inside the Cherryview pinctrl driver.
> 
> This commit adds a workaround to the Cherryview pinctrl driver so
> that the DSDT's expectations of _REG always getting called for the
> GeneralPurposeIo OpRegion are met.

I would like to understand the issue bit better before we do this.

> Cc: stable@vger.kernel.org
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> - Drop unnecessary if (acpi_has_method(adev->handle, "_REG")) check
> - Fix Cherryview spelling in the commit message
> ---
>  drivers/pinctrl/intel/pinctrl-cherryview.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
> index 4c74fdde576d..4817aec114d6 100644
> --- a/drivers/pinctrl/intel/pinctrl-cherryview.c
> +++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
> @@ -1693,6 +1693,8 @@ static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
>  
>  static int chv_pinctrl_probe(struct platform_device *pdev)
>  {
> +	struct acpi_object_list input;
> +	union acpi_object params[2];
>  	struct chv_pinctrl *pctrl;
>  	struct acpi_device *adev;
>  	acpi_status status;
> @@ -1755,6 +1757,22 @@ static int chv_pinctrl_probe(struct platform_device *pdev)
>  	if (ACPI_FAILURE(status))
>  		dev_err(&pdev->dev, "failed to install ACPI addr space handler\n");
>  
> +	/*
> +	 * Some DSDT-s use the chv_pinctrl_mmio_access_handler while checking
> +	 * for the regular GeneralPurposeIo OpRegion availability, mixed with
> +	 * the DSDT not defining a GeneralPurposeIo OpRegion at all. In this
> +	 * case the ACPICA code will not call _REG to signal availability of
> +	 * the GeneralPurposeIo OpRegion. Manually call _REG here so that
> +	 * the DSDT-s GeneralPurposeIo availability checks will succeed.
> +	 */
> +	params[0].type = ACPI_TYPE_INTEGER;
> +	params[0].integer.value = ACPI_ADR_SPACE_GPIO;
> +	params[1].type = ACPI_TYPE_INTEGER;
> +	params[1].integer.value = 1;
> +	input.count = 2;
> +	input.pointer = params;
> +	acpi_evaluate_object(adev->handle, "_REG", &input, NULL);
> +
>  	platform_set_drvdata(pdev, pctrl);
>  
>  	return 0;
> -- 
> 2.26.0
Hans de Goede May 7, 2020, 10:15 a.m. UTC | #2
Hi,

On 5/6/20 8:40 AM, Mika Westerberg wrote:
> +Rafael and ACPICA folks.
> 
> On Mon, May 04, 2020 at 04:59:57PM +0200, Hans de Goede wrote:
>> On Cherry Trail devices there are 2 possible ACPI OpRegions for
>> accessing GPIOs. The standard GeneralPurposeIo OpRegion and the Cherry
>> Trail specific UserDefined 0x9X OpRegions.
>>
>> Having 2 different types of OpRegions leads to potential issues with
>> checks for OpRegion availability, or in other words checks if _REG has
>> been called for the OpRegion which the ACPI code wants to use.
>>
>> The ACPICA core does not call _REG on an ACPI node which does not
>> define an OpRegion matching the type being registered; and the reference
>> design DSDT, from which most Cherry Trail DSDTs are derived, does not
>> define GeneralPurposeIo, nor UserDefined(0x93) OpRegions for the GPO2
>> (UID 3) device, because no pins were assigned ACPI controlled functions
>> in the reference design.
>>
>> Together this leads to the perfect storm, at least on the Cherry Trail
>> based Medion Akayo E1239T. This design does use a GPO2 pin from its ACPI
>> code and has added the Cherry Trail specific UserDefined(0x93) opregion
>> to its GPO2 ACPI node to access this pin.
>>
>> But it uses a has _REG been called availability check for the standard
>> GeneralPurposeIo OpRegion. This clearly is a bug in the DSDT, but this
>> does work under Windows.
> 
> Do we know why this works under Windows? I mean if possible we should do
> the same and I kind of suspect that they forcibly call _REG in their
> GPIO driver.

Windows has its own ACPI implementation, so it could also be that their
equivalent of the:

         status = acpi_install_address_space_handler(handle, ACPI_ADR_SPACE_GPIO,
                                                     acpi_gpio_adr_space_handler,
                                                     NULL, achip);

Call from drivers/gpio/gpiolib-acpi.c indeed always calls _REG on the handle
without checking that there is an actual OpRegion with a space-id
of ACPI_ADR_SPACE_GPIO defined, as the ACPICA code does.  Note that the
current ACPICA code would require significant rework to allow this, or
it would need to add a _REG call at the end of acpi_install_address_space_handler(),
potentially calling _REG twice in many cases.

We could move the manual _REG call I'm adding to pinctrl-cherry-view.c
but that has the same issue of calling _REG twice in many cases.

Most (all?) _REG implementations are fine with that, as they just set a
variable to 1 (to the Arg1 value). Still calling _REG twice is something
which we might want to avoid.

As a compromise I've chosen to add the extra unconditional _REG call
to pinctrl-cherryview.c because:

1. The problem in the DSDT in question stems from there being 2
different OpRegions for accessing GPIOs which AFAIK is unique to
cherryview

2. I've seen many many cherryview DSDT-s and as such I'm confident
that calling _REG twice is not an issue on cherryview.

> Are the ACPI tables from this system available somewhere?

Here you go:
https://fedorapeople.org/~jwrdegoede/medion-e1239t-dsdt.dsl

The problem is that on line 12624 there is a GPO2.AVBL == One
check, before GPO2.DCDT is used. If you then look at line
17688 you see that _REG for the GPO2 device checkes for a
space-id of 8 (ACPI_ADR_SPACE_GPIO) to set AVBL

But the only OpRegion defined for the GPO2 device, and the
OpRegion to which GPO2.DCDT is mapped is the cherryview
UserDefined 0x93 GPIO access OpRegion, see line 17760.
Since there is no OpRegion for the ACPI_ADR_SPACE_GPIO
space-id, ACPICA never calls _REG with Arg0 == 8.

So as already mentioned the problem stems from the confusion
of there being 2 different OpRegions for accessing GPIOs
on cherryview.

Regards,

Hans



>> This issue leads to the intel_vbtn driver
>> reporting the device always being in tablet-mode at boot, even if it
>> is in laptop mode. Which in turn causes userspace to ignore touchpad
>> events. So iow this issues causes the touchpad to not work at boot.
>>
>> Since the bug in the DSDT stems from the confusion of having 2 different
>> OpRegion types for accessing GPIOs on Cherry Trail devices, I believe
>> that this is best fixed inside the Cherryview pinctrl driver.
>>
>> This commit adds a workaround to the Cherryview pinctrl driver so
>> that the DSDT's expectations of _REG always getting called for the
>> GeneralPurposeIo OpRegion are met.
> 
> I would like to understand the issue bit better before we do this.
> 
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> Changes in v2:
>> - Drop unnecessary if (acpi_has_method(adev->handle, "_REG")) check
>> - Fix Cherryview spelling in the commit message
>> ---
>>   drivers/pinctrl/intel/pinctrl-cherryview.c | 18 ++++++++++++++++++
>>   1 file changed, 18 insertions(+)
>>
>> diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
>> index 4c74fdde576d..4817aec114d6 100644
>> --- a/drivers/pinctrl/intel/pinctrl-cherryview.c
>> +++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
>> @@ -1693,6 +1693,8 @@ static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
>>   
>>   static int chv_pinctrl_probe(struct platform_device *pdev)
>>   {
>> +	struct acpi_object_list input;
>> +	union acpi_object params[2];
>>   	struct chv_pinctrl *pctrl;
>>   	struct acpi_device *adev;
>>   	acpi_status status;
>> @@ -1755,6 +1757,22 @@ static int chv_pinctrl_probe(struct platform_device *pdev)
>>   	if (ACPI_FAILURE(status))
>>   		dev_err(&pdev->dev, "failed to install ACPI addr space handler\n");
>>   
>> +	/*
>> +	 * Some DSDT-s use the chv_pinctrl_mmio_access_handler while checking
>> +	 * for the regular GeneralPurposeIo OpRegion availability, mixed with
>> +	 * the DSDT not defining a GeneralPurposeIo OpRegion at all. In this
>> +	 * case the ACPICA code will not call _REG to signal availability of
>> +	 * the GeneralPurposeIo OpRegion. Manually call _REG here so that
>> +	 * the DSDT-s GeneralPurposeIo availability checks will succeed.
>> +	 */
>> +	params[0].type = ACPI_TYPE_INTEGER;
>> +	params[0].integer.value = ACPI_ADR_SPACE_GPIO;
>> +	params[1].type = ACPI_TYPE_INTEGER;
>> +	params[1].integer.value = 1;
>> +	input.count = 2;
>> +	input.pointer = params;
>> +	acpi_evaluate_object(adev->handle, "_REG", &input, NULL);
>> +
>>   	platform_set_drvdata(pdev, pctrl);
>>   
>>   	return 0;
>> -- 
>> 2.26.0
>
Mika Westerberg May 7, 2020, 12:30 p.m. UTC | #3
On Thu, May 07, 2020 at 12:15:09PM +0200, Hans de Goede wrote:
> Hi,
> 
> On 5/6/20 8:40 AM, Mika Westerberg wrote:
> > +Rafael and ACPICA folks.
> > 
> > On Mon, May 04, 2020 at 04:59:57PM +0200, Hans de Goede wrote:
> > > On Cherry Trail devices there are 2 possible ACPI OpRegions for
> > > accessing GPIOs. The standard GeneralPurposeIo OpRegion and the Cherry
> > > Trail specific UserDefined 0x9X OpRegions.
> > > 
> > > Having 2 different types of OpRegions leads to potential issues with
> > > checks for OpRegion availability, or in other words checks if _REG has
> > > been called for the OpRegion which the ACPI code wants to use.
> > > 
> > > The ACPICA core does not call _REG on an ACPI node which does not
> > > define an OpRegion matching the type being registered; and the reference
> > > design DSDT, from which most Cherry Trail DSDTs are derived, does not
> > > define GeneralPurposeIo, nor UserDefined(0x93) OpRegions for the GPO2
> > > (UID 3) device, because no pins were assigned ACPI controlled functions
> > > in the reference design.
> > > 
> > > Together this leads to the perfect storm, at least on the Cherry Trail
> > > based Medion Akayo E1239T. This design does use a GPO2 pin from its ACPI
> > > code and has added the Cherry Trail specific UserDefined(0x93) opregion
> > > to its GPO2 ACPI node to access this pin.
> > > 
> > > But it uses a has _REG been called availability check for the standard
> > > GeneralPurposeIo OpRegion. This clearly is a bug in the DSDT, but this
> > > does work under Windows.
> > 
> > Do we know why this works under Windows? I mean if possible we should do
> > the same and I kind of suspect that they forcibly call _REG in their
> > GPIO driver.
> 
> Windows has its own ACPI implementation, so it could also be that their
> equivalent of the:
> 
>         status = acpi_install_address_space_handler(handle, ACPI_ADR_SPACE_GPIO,
>                                                     acpi_gpio_adr_space_handler,
>                                                     NULL, achip);
> 
> Call from drivers/gpio/gpiolib-acpi.c indeed always calls _REG on the handle
> without checking that there is an actual OpRegion with a space-id
> of ACPI_ADR_SPACE_GPIO defined, as the ACPICA code does.  Note that the
> current ACPICA code would require significant rework to allow this, or
> it would need to add a _REG call at the end of acpi_install_address_space_handler(),
> potentially calling _REG twice in many cases.

I actually think this is the correct solution. Reading ACPI spec it say
this:

  Once _REG has been executed for a particular operation region,
  indicating that the operation region handler is ready, a control
  method can access fields in the operation region

You can interpret it so that _REG gets called when operation region
handler is ready. It does not say that there needs to be an actual
operation region even though the examples following all have operation
region.

I wonder what our ACPICA gurus think about this? Rafael, Bob, Erik?

> We could move the manual _REG call I'm adding to pinctrl-cherry-view.c
> but that has the same issue of calling _REG twice in many cases.
> 
> Most (all?) _REG implementations are fine with that, as they just set a
> variable to 1 (to the Arg1 value). Still calling _REG twice is something
> which we might want to avoid.
> 
> As a compromise I've chosen to add the extra unconditional _REG call
> to pinctrl-cherryview.c because:
> 
> 1. The problem in the DSDT in question stems from there being 2
> different OpRegions for accessing GPIOs which AFAIK is unique to
> cherryview
> 
> 2. I've seen many many cherryview DSDT-s and as such I'm confident
> that calling _REG twice is not an issue on cherryview.
> 
> > Are the ACPI tables from this system available somewhere?
> 
> Here you go:
> https://fedorapeople.org/~jwrdegoede/medion-e1239t-dsdt.dsl

Thanks for sharing!

> The problem is that on line 12624 there is a GPO2.AVBL == One
> check, before GPO2.DCDT is used. If you then look at line
> 17688 you see that _REG for the GPO2 device checkes for a
> space-id of 8 (ACPI_ADR_SPACE_GPIO) to set AVBL
> 
> But the only OpRegion defined for the GPO2 device, and the
> OpRegion to which GPO2.DCDT is mapped is the cherryview
> UserDefined 0x93 GPIO access OpRegion, see line 17760.
> Since there is no OpRegion for the ACPI_ADR_SPACE_GPIO
> space-id, ACPICA never calls _REG with Arg0 == 8.

Indeed, I see the issue now. I guess calling _REG always when there is
handler installed would solve this as well?

> So as already mentioned the problem stems from the confusion
> of there being 2 different OpRegions for accessing GPIOs
> on cherryview.
> 
> Regards,
> 
> Hans
> 
> 
> 
> > > This issue leads to the intel_vbtn driver
> > > reporting the device always being in tablet-mode at boot, even if it
> > > is in laptop mode. Which in turn causes userspace to ignore touchpad
> > > events. So iow this issues causes the touchpad to not work at boot.
> > > 
> > > Since the bug in the DSDT stems from the confusion of having 2 different
> > > OpRegion types for accessing GPIOs on Cherry Trail devices, I believe
> > > that this is best fixed inside the Cherryview pinctrl driver.
> > > 
> > > This commit adds a workaround to the Cherryview pinctrl driver so
> > > that the DSDT's expectations of _REG always getting called for the
> > > GeneralPurposeIo OpRegion are met.
> > 
> > I would like to understand the issue bit better before we do this.
> > 
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> > > ---
> > > Changes in v2:
> > > - Drop unnecessary if (acpi_has_method(adev->handle, "_REG")) check
> > > - Fix Cherryview spelling in the commit message
> > > ---
> > >   drivers/pinctrl/intel/pinctrl-cherryview.c | 18 ++++++++++++++++++
> > >   1 file changed, 18 insertions(+)
> > > 
> > > diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
> > > index 4c74fdde576d..4817aec114d6 100644
> > > --- a/drivers/pinctrl/intel/pinctrl-cherryview.c
> > > +++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
> > > @@ -1693,6 +1693,8 @@ static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
> > >   static int chv_pinctrl_probe(struct platform_device *pdev)
> > >   {
> > > +	struct acpi_object_list input;
> > > +	union acpi_object params[2];
> > >   	struct chv_pinctrl *pctrl;
> > >   	struct acpi_device *adev;
> > >   	acpi_status status;
> > > @@ -1755,6 +1757,22 @@ static int chv_pinctrl_probe(struct platform_device *pdev)
> > >   	if (ACPI_FAILURE(status))
> > >   		dev_err(&pdev->dev, "failed to install ACPI addr space handler\n");
> > > +	/*
> > > +	 * Some DSDT-s use the chv_pinctrl_mmio_access_handler while checking
> > > +	 * for the regular GeneralPurposeIo OpRegion availability, mixed with
> > > +	 * the DSDT not defining a GeneralPurposeIo OpRegion at all. In this
> > > +	 * case the ACPICA code will not call _REG to signal availability of
> > > +	 * the GeneralPurposeIo OpRegion. Manually call _REG here so that
> > > +	 * the DSDT-s GeneralPurposeIo availability checks will succeed.
> > > +	 */
> > > +	params[0].type = ACPI_TYPE_INTEGER;
> > > +	params[0].integer.value = ACPI_ADR_SPACE_GPIO;
> > > +	params[1].type = ACPI_TYPE_INTEGER;
> > > +	params[1].integer.value = 1;
> > > +	input.count = 2;
> > > +	input.pointer = params;
> > > +	acpi_evaluate_object(adev->handle, "_REG", &input, NULL);
> > > +
> > >   	platform_set_drvdata(pdev, pctrl);
> > >   	return 0;
> > > -- 
> > > 2.26.0
> >
Hans de Goede May 7, 2020, 12:39 p.m. UTC | #4
Hi,

On 5/7/20 2:30 PM, Mika Westerberg wrote:
> On Thu, May 07, 2020 at 12:15:09PM +0200, Hans de Goede wrote:
>> Hi,
>>
>> On 5/6/20 8:40 AM, Mika Westerberg wrote:
>>> +Rafael and ACPICA folks.
>>>
>>> On Mon, May 04, 2020 at 04:59:57PM +0200, Hans de Goede wrote:
>>>> On Cherry Trail devices there are 2 possible ACPI OpRegions for
>>>> accessing GPIOs. The standard GeneralPurposeIo OpRegion and the Cherry
>>>> Trail specific UserDefined 0x9X OpRegions.
>>>>
>>>> Having 2 different types of OpRegions leads to potential issues with
>>>> checks for OpRegion availability, or in other words checks if _REG has
>>>> been called for the OpRegion which the ACPI code wants to use.
>>>>
>>>> The ACPICA core does not call _REG on an ACPI node which does not
>>>> define an OpRegion matching the type being registered; and the reference
>>>> design DSDT, from which most Cherry Trail DSDTs are derived, does not
>>>> define GeneralPurposeIo, nor UserDefined(0x93) OpRegions for the GPO2
>>>> (UID 3) device, because no pins were assigned ACPI controlled functions
>>>> in the reference design.
>>>>
>>>> Together this leads to the perfect storm, at least on the Cherry Trail
>>>> based Medion Akayo E1239T. This design does use a GPO2 pin from its ACPI
>>>> code and has added the Cherry Trail specific UserDefined(0x93) opregion
>>>> to its GPO2 ACPI node to access this pin.
>>>>
>>>> But it uses a has _REG been called availability check for the standard
>>>> GeneralPurposeIo OpRegion. This clearly is a bug in the DSDT, but this
>>>> does work under Windows.
>>>
>>> Do we know why this works under Windows? I mean if possible we should do
>>> the same and I kind of suspect that they forcibly call _REG in their
>>> GPIO driver.
>>
>> Windows has its own ACPI implementation, so it could also be that their
>> equivalent of the:
>>
>>          status = acpi_install_address_space_handler(handle, ACPI_ADR_SPACE_GPIO,
>>                                                      acpi_gpio_adr_space_handler,
>>                                                      NULL, achip);
>>
>> Call from drivers/gpio/gpiolib-acpi.c indeed always calls _REG on the handle
>> without checking that there is an actual OpRegion with a space-id
>> of ACPI_ADR_SPACE_GPIO defined, as the ACPICA code does.  Note that the
>> current ACPICA code would require significant rework to allow this, or
>> it would need to add a _REG call at the end of acpi_install_address_space_handler(),
>> potentially calling _REG twice in many cases.
> 
> I actually think this is the correct solution. Reading ACPI spec it say
> this:
> 
>    Once _REG has been executed for a particular operation region,
>    indicating that the operation region handler is ready, a control
>    method can access fields in the operation region
> 
> You can interpret it so that _REG gets called when operation region
> handler is ready. It does not say that there needs to be an actual
> operation region even though the examples following all have operation
> region.
> 
> I wonder what our ACPICA gurus think about this? Rafael, Bob, Erik?
> 
>> We could move the manual _REG call I'm adding to pinctrl-cherry-view.c
>> but that has the same issue of calling _REG twice in many cases.
>>
>> Most (all?) _REG implementations are fine with that, as they just set a
>> variable to 1 (to the Arg1 value). Still calling _REG twice is something
>> which we might want to avoid.
>>
>> As a compromise I've chosen to add the extra unconditional _REG call
>> to pinctrl-cherryview.c because:
>>
>> 1. The problem in the DSDT in question stems from there being 2
>> different OpRegions for accessing GPIOs which AFAIK is unique to
>> cherryview
>>
>> 2. I've seen many many cherryview DSDT-s and as such I'm confident
>> that calling _REG twice is not an issue on cherryview.
>>
>>> Are the ACPI tables from this system available somewhere?
>>
>> Here you go:
>> https://fedorapeople.org/~jwrdegoede/medion-e1239t-dsdt.dsl
> 
> Thanks for sharing!
> 
>> The problem is that on line 12624 there is a GPO2.AVBL == One
>> check, before GPO2.DCDT is used. If you then look at line
>> 17688 you see that _REG for the GPO2 device checkes for a
>> space-id of 8 (ACPI_ADR_SPACE_GPIO) to set AVBL
>>
>> But the only OpRegion defined for the GPO2 device, and the
>> OpRegion to which GPO2.DCDT is mapped is the cherryview
>> UserDefined 0x93 GPIO access OpRegion, see line 17760.
>> Since there is no OpRegion for the ACPI_ADR_SPACE_GPIO
>> space-id, ACPICA never calls _REG with Arg0 == 8.
> 
> Indeed, I see the issue now. I guess calling _REG always when there is
> handler installed would solve this as well?

Yes that should solve the issue, that is actualy more or less
what my patch does, but my patch only does it for the
pinctrl-cherryview.c case.

Regards,

Hans









>>>> This issue leads to the intel_vbtn driver
>>>> reporting the device always being in tablet-mode at boot, even if it
>>>> is in laptop mode. Which in turn causes userspace to ignore touchpad
>>>> events. So iow this issues causes the touchpad to not work at boot.
>>>>
>>>> Since the bug in the DSDT stems from the confusion of having 2 different
>>>> OpRegion types for accessing GPIOs on Cherry Trail devices, I believe
>>>> that this is best fixed inside the Cherryview pinctrl driver.
>>>>
>>>> This commit adds a workaround to the Cherryview pinctrl driver so
>>>> that the DSDT's expectations of _REG always getting called for the
>>>> GeneralPurposeIo OpRegion are met.
>>>
>>> I would like to understand the issue bit better before we do this.
>>>
>>>> Cc: stable@vger.kernel.org
>>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>>> ---
>>>> Changes in v2:
>>>> - Drop unnecessary if (acpi_has_method(adev->handle, "_REG")) check
>>>> - Fix Cherryview spelling in the commit message
>>>> ---
>>>>    drivers/pinctrl/intel/pinctrl-cherryview.c | 18 ++++++++++++++++++
>>>>    1 file changed, 18 insertions(+)
>>>>
>>>> diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
>>>> index 4c74fdde576d..4817aec114d6 100644
>>>> --- a/drivers/pinctrl/intel/pinctrl-cherryview.c
>>>> +++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
>>>> @@ -1693,6 +1693,8 @@ static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
>>>>    static int chv_pinctrl_probe(struct platform_device *pdev)
>>>>    {
>>>> +	struct acpi_object_list input;
>>>> +	union acpi_object params[2];
>>>>    	struct chv_pinctrl *pctrl;
>>>>    	struct acpi_device *adev;
>>>>    	acpi_status status;
>>>> @@ -1755,6 +1757,22 @@ static int chv_pinctrl_probe(struct platform_device *pdev)
>>>>    	if (ACPI_FAILURE(status))
>>>>    		dev_err(&pdev->dev, "failed to install ACPI addr space handler\n");
>>>> +	/*
>>>> +	 * Some DSDT-s use the chv_pinctrl_mmio_access_handler while checking
>>>> +	 * for the regular GeneralPurposeIo OpRegion availability, mixed with
>>>> +	 * the DSDT not defining a GeneralPurposeIo OpRegion at all. In this
>>>> +	 * case the ACPICA code will not call _REG to signal availability of
>>>> +	 * the GeneralPurposeIo OpRegion. Manually call _REG here so that
>>>> +	 * the DSDT-s GeneralPurposeIo availability checks will succeed.
>>>> +	 */
>>>> +	params[0].type = ACPI_TYPE_INTEGER;
>>>> +	params[0].integer.value = ACPI_ADR_SPACE_GPIO;
>>>> +	params[1].type = ACPI_TYPE_INTEGER;
>>>> +	params[1].integer.value = 1;
>>>> +	input.count = 2;
>>>> +	input.pointer = params;
>>>> +	acpi_evaluate_object(adev->handle, "_REG", &input, NULL);
>>>> +
>>>>    	platform_set_drvdata(pdev, pctrl);
>>>>    	return 0;
>>>> -- 
>>>> 2.26.0
>>>
>
Andy Shevchenko May 7, 2020, 1:39 p.m. UTC | #5
On Thu, May 07, 2020 at 02:39:21PM +0200, Hans de Goede wrote:
> On 5/7/20 2:30 PM, Mika Westerberg wrote:
> > On Thu, May 07, 2020 at 12:15:09PM +0200, Hans de Goede wrote:
> > > On 5/6/20 8:40 AM, Mika Westerberg wrote:

+Rafael and ACPICA folks.

...

> > I actually think this is the correct solution. Reading ACPI spec it say
> > this:
> > 
> >    Once _REG has been executed for a particular operation region,
> >    indicating that the operation region handler is ready, a control
> >    method can access fields in the operation region
> > 
> > You can interpret it so that _REG gets called when operation region
> > handler is ready. It does not say that there needs to be an actual
> > operation region even though the examples following all have operation
> > region.
> > 
> > I wonder what our ACPICA gurus think about this? Rafael, Bob, Erik?
> > 
> > > We could move the manual _REG call I'm adding to pinctrl-cherry-view.c
> > > but that has the same issue of calling _REG twice in many cases.
> > > 
> > > Most (all?) _REG implementations are fine with that, as they just set a
> > > variable to 1 (to the Arg1 value). Still calling _REG twice is something
> > > which we might want to avoid.
> > > 
> > > As a compromise I've chosen to add the extra unconditional _REG call
> > > to pinctrl-cherryview.c because:
> > > 
> > > 1. The problem in the DSDT in question stems from there being 2
> > > different OpRegions for accessing GPIOs which AFAIK is unique to
> > > cherryview
> > > 
> > > 2. I've seen many many cherryview DSDT-s and as such I'm confident
> > > that calling _REG twice is not an issue on cherryview.
> > > 
> > > > Are the ACPI tables from this system available somewhere?
> > > 
> > > Here you go:
> > > https://fedorapeople.org/~jwrdegoede/medion-e1239t-dsdt.dsl
> > 
> > Thanks for sharing!
> > 
> > > The problem is that on line 12624 there is a GPO2.AVBL == One
> > > check, before GPO2.DCDT is used. If you then look at line
> > > 17688 you see that _REG for the GPO2 device checkes for a
> > > space-id of 8 (ACPI_ADR_SPACE_GPIO) to set AVBL
> > > 
> > > But the only OpRegion defined for the GPO2 device, and the
> > > OpRegion to which GPO2.DCDT is mapped is the cherryview
> > > UserDefined 0x93 GPIO access OpRegion, see line 17760.
> > > Since there is no OpRegion for the ACPI_ADR_SPACE_GPIO
> > > space-id, ACPICA never calls _REG with Arg0 == 8.
> > 
> > Indeed, I see the issue now. I guess calling _REG always when there is
> > handler installed would solve this as well?
> 
> Yes that should solve the issue, that is actualy more or less
> what my patch does, but my patch only does it for the
> pinctrl-cherryview.c case.

And ACPICA guys, in case of thinking about generic solution there, can also
have a look into ACPI hotplug code. Something tells me that there may be the
very same root cause.
diff mbox series

Patch

diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
index 4c74fdde576d..4817aec114d6 100644
--- a/drivers/pinctrl/intel/pinctrl-cherryview.c
+++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
@@ -1693,6 +1693,8 @@  static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
 
 static int chv_pinctrl_probe(struct platform_device *pdev)
 {
+	struct acpi_object_list input;
+	union acpi_object params[2];
 	struct chv_pinctrl *pctrl;
 	struct acpi_device *adev;
 	acpi_status status;
@@ -1755,6 +1757,22 @@  static int chv_pinctrl_probe(struct platform_device *pdev)
 	if (ACPI_FAILURE(status))
 		dev_err(&pdev->dev, "failed to install ACPI addr space handler\n");
 
+	/*
+	 * Some DSDT-s use the chv_pinctrl_mmio_access_handler while checking
+	 * for the regular GeneralPurposeIo OpRegion availability, mixed with
+	 * the DSDT not defining a GeneralPurposeIo OpRegion at all. In this
+	 * case the ACPICA code will not call _REG to signal availability of
+	 * the GeneralPurposeIo OpRegion. Manually call _REG here so that
+	 * the DSDT-s GeneralPurposeIo availability checks will succeed.
+	 */
+	params[0].type = ACPI_TYPE_INTEGER;
+	params[0].integer.value = ACPI_ADR_SPACE_GPIO;
+	params[1].type = ACPI_TYPE_INTEGER;
+	params[1].integer.value = 1;
+	input.count = 2;
+	input.pointer = params;
+	acpi_evaluate_object(adev->handle, "_REG", &input, NULL);
+
 	platform_set_drvdata(pdev, pctrl);
 
 	return 0;