pinctrl: cherryview: Ensure _REG(ACPI_ADR_SPACE_GPIO, 1) gets called
Subsystems (6)
PATCH v2 1/1 pinctrl: cherryview: Ensure _REG(ACPI_ADR_SPACE_GPIO, 1) gets called
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.
---
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(+)
drivers/pinctrl/intel/pinctrl-cherryview.c +18 -0
@@ -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 ;
Signature · 1 line
2.26.0
Mika Westerberg
maintainer+Rafael and ACPICA folks.
Quoted 15 lines · Hans de Goede
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
_REGhas been called for the OpRegion which the ACPI code wants to use.The ACPICA core does not call
_REGon 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.
Quoted 8 lines
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
_REGbeen 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?
Quoted 5 lines
This issue leads to the
intel_vbtndriver
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.
Quoted 7 lines
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
_REGalways getting called for the GeneralPurposeIo OpRegion are met.
I would like to understand the issue bit better before we do this.
Quoted 48 lines
Signed-off-by Hans de Goede <[email protected]>---
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(+)drivers/pinctrl/intel/pinctrl-cherryview.c +18
-0@@ -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 ;Signature · 1 line
2.26.0
Hi,
Quoted 23 lines · Mika Westerberg
+Rafael and ACPICA folks.
Quoted 20 lines · Hans de Goede
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
_REGhas been called for the OpRegion which the ACPI code wants to use.The ACPICA core does not call
_REGon 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.
Quoted 7 lines
Quoted 3 lines
But it uses a has
_REGbeen 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
_REGin 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.
Quoted 1 line
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
Quoted 64 lines
Quoted 5 lines
This issue leads to the
intel_vbtndriver
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.Quoted 7 lines
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
_REGalways getting called for the GeneralPurposeIo OpRegion are met.I would like to understand the issue bit better before we do this.
Quoted 48 lines
Signed-off-by Hans de Goede <[email protected]>---
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(+)drivers/pinctrl/intel/pinctrl-cherryview.c +18
-0@@ -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 ;Signature · 1 line
2.26.0
Mika Westerberg
maintainerQuoted 41 lines · Hans de Goede
Hi,
Quoted 23 lines · Mika Westerberg
+Rafael and ACPICA folks.
Quoted 20 lines · Hans de Goede
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
_REGhas been called for the OpRegion which the ACPI code wants to use.The ACPICA core does not call
_REGon 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.
Quoted 7 lines
Quoted 3 lines
But it uses a has
_REGbeen 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
_REGin 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);
Quoted 6 lines
Call from
drivers/gpio/gpiolib-acpi.cindeed always calls_REGon the handle without checking that there is an actual OpRegion with a space-id
ofACPI_ADR_SPACE_GPIOdefined, 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_REGcall at the end ofacpi_install_address_space_handler(), potentially calling_REGtwice 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?
Quoted 14 lines
We could move the manual
_REGcall I'm adding topinctrl-cherry-view.cbut that has the same issue of calling_REGtwice in many cases.Most (all?)
_REGimplementations are fine with that, as they just set a variable to 1 (to the Arg1 value). Still calling_REGtwice is something which we might want to avoid.As a compromise I've chosen to add the extra unconditional
_REGcall topinctrl-cherryview.cbecause:1. The problem in the DSDT in question stems from there being 2 different OpRegions for accessing GPIOs which AFAIK is unique to cherryview
Quoted 7 lines
2. I've seen many many cherryview DSDT-s and as such I'm confident that calling
_REGtwice is not an issue on cherryview.Quoted 1 line
Are the ACPI tables from this system available somewhere?
Here you go:
https://fedorapeople.org/~jwrdegoede/medion-e1239t-dsdt.dsl
Thanks for sharing!
Quoted 10 lines
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
_REGfor the GPO2 device checkes for a space-id of 8 (ACPI_ADR_SPACE_GPIO) to set AVBLBut the only OpRegion defined for the GPO2 device, and the OpRegion to which GPO2.DCDT is mapped is the cherryview UserDefined
0x93GPIO access OpRegion, see line 17760. Since there is no OpRegion for theACPI_ADR_SPACE_GPIOspace-id, ACPICA never calls_REGwith Arg0 == 8.
Indeed, I see the issue now. I guess calling _REG always when there is handler installed would solve this as well?
Quoted 71 lines
So as already mentioned the problem stems from the confusion of there being 2 different OpRegions for accessing GPIOs on cherryview.
Regards,
Hans
Quoted 61 lines
Quoted 5 lines
This issue leads to the
intel_vbtndriver
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.Quoted 7 lines
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
_REGalways getting called for the GeneralPurposeIo OpRegion are met.I would like to understand the issue bit better before we do this.
Quoted 45 lines
Signed-off-by Hans de Goede <[email protected]>---
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(+)drivers/pinctrl/intel/pinctrl-cherryview.c +18
-0@@ -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 ;Signature · 1 line
2.26.0
Hi,
Quoted 92 lines · Mika Westerberg
Quoted 41 lines · Hans de Goede
Hi,
Quoted 23 lines · Mika Westerberg
+Rafael and ACPICA folks.
Quoted 20 lines · Hans de Goede
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
_REGhas been called for the OpRegion which the ACPI code wants to use.The ACPICA core does not call
_REGon 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.
Quoted 7 lines
Quoted 3 lines
But it uses a has
_REGbeen 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
_REGin 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);Quoted 6 lines
Call from
drivers/gpio/gpiolib-acpi.cindeed always calls_REGon the handle without checking that there is an actual OpRegion with a space-id
ofACPI_ADR_SPACE_GPIOdefined, 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_REGcall at the end ofacpi_install_address_space_handler(), potentially calling_REGtwice in many cases.I actually think this is the correct solution. Reading ACPI spec it say this:
Once
_REGhas been executed for a particular operation region, indicating that the operation region handler is ready, a control method can access fields in the operation regionYou can interpret it so that
_REGgets 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?
Quoted 14 lines
We could move the manual
_REGcall I'm adding topinctrl-cherry-view.cbut that has the same issue of calling_REGtwice in many cases.Most (all?)
_REGimplementations are fine with that, as they just set a variable to 1 (to the Arg1 value). Still calling_REGtwice is something which we might want to avoid.As a compromise I've chosen to add the extra unconditional
_REGcall topinctrl-cherryview.cbecause:1. The problem in the DSDT in question stems from there being 2 different OpRegions for accessing GPIOs which AFAIK is unique to cherryview
Quoted 7 lines
2. I've seen many many cherryview DSDT-s and as such I'm confident that calling
_REGtwice is not an issue on cherryview.Quoted 1 line
Are the ACPI tables from this system available somewhere?
Here you go:
https://fedorapeople.org/~jwrdegoede/medion-e1239t-dsdt.dslThanks for sharing!
Quoted 5 lines
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
_REGfor the GPO2 device checkes for a space-id of 8 (ACPI_ADR_SPACE_GPIO) to set AVBL
Quoted 8 lines
Quoted 5 lines
But the only OpRegion defined for the GPO2 device, and the OpRegion to which GPO2.DCDT is mapped is the cherryview UserDefined
0x93GPIO access OpRegion, see line 17760. Since there is no OpRegion for theACPI_ADR_SPACE_GPIOspace-id, ACPICA never calls_REGwith Arg0 == 8.Indeed, I see the issue now. I guess calling
_REGalways 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
Quoted 62 lines
Quoted 61 lines
Quoted 61 lines
Quoted 5 lines
This issue leads to the
intel_vbtndriver
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.Quoted 7 lines
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
_REGalways getting called for the GeneralPurposeIo OpRegion are met.I would like to understand the issue bit better before we do this.
Quoted 45 lines
Signed-off-by Hans de Goede <[email protected]>---
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(+)drivers/pinctrl/intel/pinctrl-cherryview.c +18
-0@@ -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 ;Signature · 1 line
2.26.0
Quoted 3 lines · Hans de Goede
Quoted 2 lines · Mika Westerberg
Quoted 1 line · Hans de Goede
On 5/6/20 8:40 AM, Mika Westerberg wrote:
+Rafael and ACPICA folks.
...
Quoted 49 lines
Quoted 49 lines
I actually think this is the correct solution. Reading ACPI spec it say this:
Once
_REGhas been executed for a particular operation region, indicating that the operation region handler is ready, a control method can access fields in the operation regionYou can interpret it so that
_REGgets 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?
Quoted 14 lines
We could move the manual
_REGcall I'm adding topinctrl-cherry-view.cbut that has the same issue of calling_REGtwice in many cases.Most (all?)
_REGimplementations are fine with that, as they just set a variable to 1 (to the Arg1 value). Still calling_REGtwice is something which we might want to avoid.As a compromise I've chosen to add the extra unconditional
_REGcall topinctrl-cherryview.cbecause:1. The problem in the DSDT in question stems from there being 2 different OpRegions for accessing GPIOs which AFAIK is unique to cherryview
Quoted 7 lines
2. I've seen many many cherryview DSDT-s and as such I'm confident that calling
_REGtwice is not an issue on cherryview.Quoted 1 line
Are the ACPI tables from this system available somewhere?
Here you go:
https://fedorapeople.org/~jwrdegoede/medion-e1239t-dsdt.dslThanks for sharing!
Quoted 10 lines
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
_REGfor the GPO2 device checkes for a space-id of 8 (ACPI_ADR_SPACE_GPIO) to set AVBLBut the only OpRegion defined for the GPO2 device, and the OpRegion to which GPO2.DCDT is mapped is the cherryview UserDefined
0x93GPIO access OpRegion, see line 17760. Since there is no OpRegion for theACPI_ADR_SPACE_GPIOspace-id, ACPICA never calls_REGwith Arg0 == 8.
Quoted 6 lines
Quoted 2 lines
Indeed, I see the issue now. I guess calling
_REGalways 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.ccase.
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 56 lines · Mika Westerberg
Quoted 41 lines · Hans de Goede
Hi,
Quoted 23 lines · Mika Westerberg
+Rafael and ACPICA folks.
Quoted 20 lines · Hans de Goede
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
_REGhas been called for the OpRegion which the ACPI code wants to use.The ACPICA core does not call
_REGon 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.
Quoted 7 lines
Quoted 3 lines
But it uses a has
_REGbeen 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
_REGin 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);Quoted 6 lines
Call from
drivers/gpio/gpiolib-acpi.cindeed always calls_REGon the handle without checking that there is an actual OpRegion with a space-id
ofACPI_ADR_SPACE_GPIOdefined, 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_REGcall at the end ofacpi_install_address_space_handler(), potentially calling_REGtwice in many cases.I actually think this is the correct solution. Reading ACPI spec it say this:
Once
_REGhas 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
Quoted 6 lines
You can interpret it so that
_REGgets 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?
I realize that this thread has gone a bit stale (sorry about that) but I have been working on an ACPICA solution on that, and this works nicely. It turns out that ACPICA already had code to run the _REG method unconditionally in some cases, so I've simply extended that to also apply to GpioOpRegions.
One thing which is open for discussion is if we want to extend this to more then just GpioOpRegions. For now I've chosen to just extend the current special handling for EC OpRegions to also apply to GpioOpRegions which fixes the issue at hand.
I've attached a patch directly against the Linux kernel acpica copy which fixes this.
Mika (or anyone else reading along who wants to help), I know that ACPICA patches go upstream through the ACPICA repo, but I'm not really familiar with there workflow and I'm a bit swamped with work atm. So I was wondering if you could perhaps convert this patch to an upstream ACPICA patch and submit it there for me ?
Regards,
Hans
From a2729247cb69707c0244e84cfa4316cffc63b35f Mon Sep 17 00:00:00 2001
From: Hans de Goede <[email protected]>
Date: Wed, 22 Jul 2020 22:22:13 +0200
Subject: [PATCH] ACPICA: Also handle "orphan" _REG methods for GPIO OpRegions
Before this commit acpi_ev_execute_reg_methods() had special handling to handle "orphan" (no matching OpRegion declared) _REG methods for EC nodes.
On Intel 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.
Except for the "orphan" EC handling, 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.
This commit fixes this by extending the "orphan" _REG method handling to also apply to GPIO address-space handlers.
Note it seems that Windows always calls "orphan" _REG methods so me may want to consider dropping the space-id check and always do "orphan" _REG method handling.
--- drivers/acpi/acpica/evregion.c | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/acpi/acpica/evregion.c +27 -27
@@ -21,7 +21,8 @@ extern u8 acpi_gbl_default_address_spaces[];/* Local prototypes */ static void -acpi_ev_orphan_ec_reg_method (struct acpi_namespace_node *ec_device_node); +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, +acpi_adr_space_type space_id); static acpi_status acpi_ev_reg_run(acpi_handle obj_handle,
@@ -684,10 +685,12 @@ acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,ACPI_NS_WALK_UNLOCK , acpi_ev_reg_run,NULL , &info, NULL); -/* Special case for EC: handle "orphan" _REG methods with no region */ - -if (space_id ==ACPI_ADR_SPACE_EC ) { -acpi_ev_orphan_ec_reg_method (node); +/* +* Special case for EC and GPIO: handle "orphan" _REG methods with +* no region. +*/ +if (space_id ==ACPI_ADR_SPACE_EC || space_id ==ACPI_ADR_SPACE_GPIO ) { +acpi_ev_execute_orphan_reg_method (node, space_id); } ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
@@ -760,31 +763,28 @@ acpi_ev_reg_run(acpi_handle obj_handle,/******************************************************************************* * -* FUNCTION: acpi_ev_orphan_ec_reg_method +* FUNCTION: acpi_ev_execute_orphan_reg_method * -* PARAMETERS: ec_device_node - Namespace node for an EC device +* PARAMETERS: device_node - Namespace node for an ACPI device +* space_id - The address space ID * * RETURN: None * -* DESCRIPTION: Execute an "orphan" _REG method that appears under the EC +* DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI * device. This is a _REG method that has no corresponding region -* within the EC device scope. The orphan _REG method appears to -* have been enabled by the description of the ECDT in the ACPI -* specification: "The availability of the region space can be -* detected by providing a _REG method object underneath the -* Embedded Controller device." -* -* To quickly access the EC device, we use the ec_device_node used -* during EC handler installation. Otherwise, we would need to -* perform a time consuming namespace walk, executing _HID -* methods to find the EC device. +* within the device's scope. ACPI tables depending on these +* "orphan" _REG methods have been seen for both EC and GPIO +* Operation Regions. Presumably the Windows ACPI implementation +* always calls the _REG method independent of the presence of +* an actual Operation Region with the correct address space ID. * * MUTEX: Assumes the namespace is locked * ******************************************************************************/ static void -acpi_ev_orphan_ec_reg_method (struct acpi_namespace_node *ec_device_node) +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, +acpi_adr_space_type space_id) {acpi_handle reg_method;struct acpi_namespace_node *next_node;
@@ -792,9 +792,9 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)struct acpi_object_list args;union acpi_object objects[2 ]; -ACPI_FUNCTION_TRACE (ev_orphan_ec_reg_method); +ACPI_FUNCTION_TRACE (ev_execute_orphan_reg_method); -if (!ec_device_node) { +if (!device_node) { return_VOID; }
@@ -804,7 +804,7 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)/* Get a handle to a _REG method immediately under the EC device */ - status =acpi_get_handle (ec_device_node,METHOD_NAME__REG , ®_method); + status =acpi_get_handle (device_node,METHOD_NAME__REG , ®_method);if (ACPI_FAILURE (status)) { goto exit;/* There is no _REG method present */ }
@@ -816,23 +816,23 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)* with other space IDs to be present; but the code below will then * execute the _REG method with the embedded_control space_ID argument. */ - next_node =acpi_ns_get_next_node (ec_device_node,NULL ); + next_node =acpi_ns_get_next_node (device_node,NULL );while (next_node) {if ((next_node->type ==ACPI_TYPE_REGION ) && (next_node->object) && - (next_node->object->region.space_id ==ACPI_ADR_SPACE_EC )) { + (next_node->object->region.space_id == space_id)) { goto exit;/* Do not execute the _REG */ } - next_node =acpi_ns_get_next_node (ec_device_node, next_node); + next_node =acpi_ns_get_next_node (device_node, next_node); } -/* Evaluate the _REG(embedded_control,Connect) method */ +/* Evaluate the _REG(space_id, Connect) method */ args.count =2 ; args.pointer = objects; objects[0 ].type =ACPI_TYPE_INTEGER ; - objects[0 ].integer.value =ACPI_ADR_SPACE_EC ; + objects[0 ].integer.value = space_id; objects[1 ].type =ACPI_TYPE_INTEGER ; objects[1 ].integer.value =ACPI_REG_CONNECT ;
Signature · 1 line
2.28.0
Mika Westerberg
maintainerHi,
Quoted 77 lines · Hans de Goede
Hi,
Quoted 56 lines · Mika Westerberg
Quoted 41 lines · Hans de Goede
Hi,
Quoted 23 lines · Mika Westerberg
+Rafael and ACPICA folks.
Quoted 20 lines · Hans de Goede
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
_REGhas been called for the OpRegion which the ACPI code wants to use.The ACPICA core does not call
_REGon 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.
Quoted 7 lines
Quoted 3 lines
But it uses a has
_REGbeen 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
_REGin 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);Quoted 6 lines
Call from
drivers/gpio/gpiolib-acpi.cindeed always calls_REGon the handle without checking that there is an actual OpRegion with a space-id
ofACPI_ADR_SPACE_GPIOdefined, 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_REGcall at the end ofacpi_install_address_space_handler(), potentially calling_REGtwice in many cases.I actually think this is the correct solution. Reading ACPI spec it say this:
Once
_REGhas been executed for a particular operation region, indicating that the operation region handler is ready, a control method can access fields in the operation regionQuoted 6 lines
You can interpret it so that
_REGgets 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?
I realize that this thread has gone a bit stale (sorry about that) but I have been working on an ACPICA solution on that, and this works nicely. It turns out that ACPICA already had code to run the
_REGmethod unconditionally in some cases, so I've simply extended that to also apply to GpioOpRegions.One thing which is open for discussion is if we want to extend this to more then just GpioOpRegions. For now I've chosen to just extend the current special handling for EC OpRegions to also apply to GpioOpRegions which fixes the issue at hand.
Quoted 8 lines
I've attached a patch directly against the Linux kernel acpica copy which fixes this.
Mika (or anyone else reading along who wants to help), I know that ACPICA patches go upstream through the ACPICA repo, but I'm not really familiar with there workflow and I'm a bit swamped with work atm. So I was wondering if you could perhaps convert this patch to an upstream ACPICA patch and submit it there for me ?
IIRC we sometimes take the ACPICA related patches first to Linux and then it gets picked up by the ACPICA maintainers. I think Erik Kaneda (who is Cc'd on this thread) has been doing some of that work.
Erik, Rafael, can you help us out here? What is the best way for Hans to get the below patch to the upstream ACPICA?
Quoted 182 lines
Regards,
Hans
Quoted 1 line
From
a2729247cb69707c0244e84cfa4316cffc63b35fMon Sep 17 00:00:00 2001From: Hans de Goede <[email protected]>
Date: Wed, 22 Jul 2020 22:22:13 +0200
Subject: [PATCH] ACPICA: Also handle "orphan"_REGmethods for GPIO OpRegionsBefore this commit
acpi_ev_execute_reg_methods()had special handling to handle "orphan" (no matching OpRegion declared)_REGmethods for EC nodes.On Intel 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
_REGhas been called for the OpRegion which the ACPI code wants to use.Except for the "orphan" EC handling, ACPICA core does not call
_REGon 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
_REGbeen 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 theintel_vbtndriver 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.This commit fixes this by extending the "orphan"
_REGmethod handling to also apply to GPIO address-space handlers.Note it seems that Windows always calls "orphan"
_REGmethods so me may want to consider dropping the space-id check and always do "orphan"_REGmethod handling.Signed-off-by Hans de Goede <[email protected]>--- drivers/acpi/acpica/evregion.c | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-)drivers/acpi/acpica/evregion.c +27
-27@@ -21,7 +21,8 @@ extern u8 acpi_gbl_default_address_spaces[];/* Local prototypes */ static void -acpi_ev_orphan_ec_reg_method (struct acpi_namespace_node *ec_device_node); +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, +acpi_adr_space_type space_id); static acpi_status acpi_ev_reg_run(acpi_handle obj_handle,@@ -684,10 +685,12 @@ acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,ACPI_NS_WALK_UNLOCK , acpi_ev_reg_run,NULL , &info, NULL); -/* Special case for EC: handle "orphan" _REG methods with no region */ - -if (space_id ==ACPI_ADR_SPACE_EC ) { -acpi_ev_orphan_ec_reg_method (node); +/* +* Special case for EC and GPIO: handle "orphan" _REG methods with +* no region. +*/ +if (space_id ==ACPI_ADR_SPACE_EC || space_id ==ACPI_ADR_SPACE_GPIO ) { +acpi_ev_execute_orphan_reg_method (node, space_id); } ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,@@ -760,31 +763,28 @@ acpi_ev_reg_run(acpi_handle obj_handle,/******************************************************************************* * -* FUNCTION: acpi_ev_orphan_ec_reg_method +* FUNCTION: acpi_ev_execute_orphan_reg_method * -* PARAMETERS: ec_device_node - Namespace node for an EC device +* PARAMETERS: device_node - Namespace node for an ACPI device +* space_id - The address space ID * * RETURN: None * -* DESCRIPTION: Execute an "orphan" _REG method that appears under the EC +* DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI * device. This is a _REG method that has no corresponding region -* within the EC device scope. The orphan _REG method appears to -* have been enabled by the description of the ECDT in the ACPI -* specification: "The availability of the region space can be -* detected by providing a _REG method object underneath the -* Embedded Controller device." -* -* To quickly access the EC device, we use the ec_device_node used -* during EC handler installation. Otherwise, we would need to -* perform a time consuming namespace walk, executing _HID -* methods to find the EC device. +* within the device's scope. ACPI tables depending on these +* "orphan" _REG methods have been seen for both EC and GPIO +* Operation Regions. Presumably the Windows ACPI implementation +* always calls the _REG method independent of the presence of +* an actual Operation Region with the correct address space ID. * * MUTEX: Assumes the namespace is locked * ******************************************************************************/ static void -acpi_ev_orphan_ec_reg_method (struct acpi_namespace_node *ec_device_node) +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, +acpi_adr_space_type space_id) {acpi_handle reg_method;struct acpi_namespace_node *next_node;@@ -792,9 +792,9 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)struct acpi_object_list args;union acpi_object objects[2 ]; -ACPI_FUNCTION_TRACE (ev_orphan_ec_reg_method); +ACPI_FUNCTION_TRACE (ev_execute_orphan_reg_method); -if (!ec_device_node) { +if (!device_node) { return_VOID; }@@ -804,7 +804,7 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)/* Get a handle to a _REG method immediately under the EC device */ - status =acpi_get_handle (ec_device_node,METHOD_NAME__REG , ®_method); + status =acpi_get_handle (device_node,METHOD_NAME__REG , ®_method);if (ACPI_FAILURE (status)) { goto exit;/* There is no _REG method present */ }@@ -816,23 +816,23 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)* with other space IDs to be present; but the code below will then * execute the _REG method with the embedded_control space_ID argument. */ - next_node =acpi_ns_get_next_node (ec_device_node,NULL ); + next_node =acpi_ns_get_next_node (device_node,NULL );while (next_node) {if ((next_node->type ==ACPI_TYPE_REGION ) && (next_node->object) && - (next_node->object->region.space_id ==ACPI_ADR_SPACE_EC )) { + (next_node->object->region.space_id == space_id)) { goto exit;/* Do not execute the _REG */ } - next_node =acpi_ns_get_next_node (ec_device_node, next_node); + next_node =acpi_ns_get_next_node (device_node, next_node); } -/* Evaluate the _REG(embedded_control,Connect) method */ +/* Evaluate the _REG(space_id, Connect) method */ args.count =2 ; args.pointer = objects; objects[0 ].type =ACPI_TYPE_INTEGER ; - objects[0 ].integer.value =ACPI_ADR_SPACE_EC ; + objects[0 ].integer.value = space_id; objects[1 ].type =ACPI_TYPE_INTEGER ; objects[1 ].integer.value =ACPI_REG_CONNECT ;Signature · 1 line
2.28.0
Hi,
Quoted 89 lines · Mika Westerberg
Hi,
Quoted 77 lines · Hans de Goede
Hi,
Quoted 56 lines · Mika Westerberg
Quoted 41 lines · Hans de Goede
Hi,
Quoted 23 lines · Mika Westerberg
+Rafael and ACPICA folks.
Quoted 20 lines · Hans de Goede
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
_REGhas been called for the OpRegion which the ACPI code wants to use.The ACPICA core does not call
_REGon 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.
Quoted 7 lines
Quoted 3 lines
But it uses a has
_REGbeen 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
_REGin 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);Quoted 6 lines
Call from
drivers/gpio/gpiolib-acpi.cindeed always calls_REGon the handle without checking that there is an actual OpRegion with a space-id
ofACPI_ADR_SPACE_GPIOdefined, 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_REGcall at the end ofacpi_install_address_space_handler(), potentially calling_REGtwice in many cases.I actually think this is the correct solution. Reading ACPI spec it say this:
Once
_REGhas been executed for a particular operation region, indicating that the operation region handler is ready, a control method can access fields in the operation regionQuoted 6 lines
You can interpret it so that
_REGgets 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?
I realize that this thread has gone a bit stale (sorry about that) but I have been working on an ACPICA solution on that, and this works nicely. It turns out that ACPICA already had code to run the
_REGmethod unconditionally in some cases, so I've simply extended that to also apply to GpioOpRegions.One thing which is open for discussion is if we want to extend this to more then just GpioOpRegions. For now I've chosen to just extend the current special handling for EC OpRegions to also apply to GpioOpRegions which fixes the issue at hand.
Quoted 8 lines
I've attached a patch directly against the Linux kernel acpica copy which fixes this.
Mika (or anyone else reading along who wants to help), I know that ACPICA patches go upstream through the ACPICA repo, but I'm not really familiar with there workflow and I'm a bit swamped with work atm. So I was wondering if you could perhaps convert this patch to an upstream ACPICA patch and submit it there for me ?
Quoted 6 lines
IIRC we sometimes take the ACPICA related patches first to Linux and then it gets picked up by the ACPICA maintainers. I think Erik Kaneda (who is Cc'd on this thread) has been doing some of that work.
Erik, Rafael, can you help us out here? What is the best way for Hans to get the below patch to the upstream ACPICA?
Thanks Mika, I did not know that getting it into Linux directly was an option.
Mika, do you have input wrt always calling _REG for just the GpioIoOpRegion type (on top of the existing EC exception) vs just simply always calling it for all all/more OpRegion types ?
Regards,
Hans
Quoted 176 lines
Quoted 175 lines
Quoted 1 line
From
a2729247cb69707c0244e84cfa4316cffc63b35fMon Sep 17 00:00:00 2001From: Hans de Goede <[email protected]>
Date: Wed, 22 Jul 2020 22:22:13 +0200
Subject: [PATCH] ACPICA: Also handle "orphan"_REGmethods for GPIO OpRegionsBefore this commit
acpi_ev_execute_reg_methods()had special handling to handle "orphan" (no matching OpRegion declared)_REGmethods for EC nodes.On Intel 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
_REGhas been called for the OpRegion which the ACPI code wants to use.Except for the "orphan" EC handling, ACPICA core does not call
_REGon 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
_REGbeen 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 theintel_vbtndriver 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.This commit fixes this by extending the "orphan"
_REGmethod handling to also apply to GPIO address-space handlers.Note it seems that Windows always calls "orphan"
_REGmethods so me may want to consider dropping the space-id check and always do "orphan"_REGmethod handling.Signed-off-by Hans de Goede <[email protected]>--- drivers/acpi/acpica/evregion.c | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-)drivers/acpi/acpica/evregion.c +27
-27@@ -21,7 +21,8 @@ extern u8 acpi_gbl_default_address_spaces[];/* Local prototypes */ static void -acpi_ev_orphan_ec_reg_method (struct acpi_namespace_node *ec_device_node); +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, +acpi_adr_space_type space_id); static acpi_status acpi_ev_reg_run(acpi_handle obj_handle,@@ -684,10 +685,12 @@ acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,ACPI_NS_WALK_UNLOCK , acpi_ev_reg_run,NULL , &info, NULL); -/* Special case for EC: handle "orphan" _REG methods with no region */ - -if (space_id ==ACPI_ADR_SPACE_EC ) { -acpi_ev_orphan_ec_reg_method (node); +/* +* Special case for EC and GPIO: handle "orphan" _REG methods with +* no region. +*/ +if (space_id ==ACPI_ADR_SPACE_EC || space_id ==ACPI_ADR_SPACE_GPIO ) { +acpi_ev_execute_orphan_reg_method (node, space_id); } ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,@@ -760,31 +763,28 @@ acpi_ev_reg_run(acpi_handle obj_handle,/******************************************************************************* * -* FUNCTION: acpi_ev_orphan_ec_reg_method +* FUNCTION: acpi_ev_execute_orphan_reg_method * -* PARAMETERS: ec_device_node - Namespace node for an EC device +* PARAMETERS: device_node - Namespace node for an ACPI device +* space_id - The address space ID * * RETURN: None * -* DESCRIPTION: Execute an "orphan" _REG method that appears under the EC +* DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI * device. This is a _REG method that has no corresponding region -* within the EC device scope. The orphan _REG method appears to -* have been enabled by the description of the ECDT in the ACPI -* specification: "The availability of the region space can be -* detected by providing a _REG method object underneath the -* Embedded Controller device." -* -* To quickly access the EC device, we use the ec_device_node used -* during EC handler installation. Otherwise, we would need to -* perform a time consuming namespace walk, executing _HID -* methods to find the EC device. +* within the device's scope. ACPI tables depending on these +* "orphan" _REG methods have been seen for both EC and GPIO +* Operation Regions. Presumably the Windows ACPI implementation +* always calls the _REG method independent of the presence of +* an actual Operation Region with the correct address space ID. * * MUTEX: Assumes the namespace is locked * ******************************************************************************/ static void -acpi_ev_orphan_ec_reg_method (struct acpi_namespace_node *ec_device_node) +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, +acpi_adr_space_type space_id) {acpi_handle reg_method;struct acpi_namespace_node *next_node;@@ -792,9 +792,9 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)struct acpi_object_list args;union acpi_object objects[2 ]; -ACPI_FUNCTION_TRACE (ev_orphan_ec_reg_method); +ACPI_FUNCTION_TRACE (ev_execute_orphan_reg_method); -if (!ec_device_node) { +if (!device_node) { return_VOID; }@@ -804,7 +804,7 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)/* Get a handle to a _REG method immediately under the EC device */ - status =acpi_get_handle (ec_device_node,METHOD_NAME__REG , ®_method); + status =acpi_get_handle (device_node,METHOD_NAME__REG , ®_method);if (ACPI_FAILURE (status)) { goto exit;/* There is no _REG method present */ }@@ -816,23 +816,23 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)* with other space IDs to be present; but the code below will then * execute the _REG method with the embedded_control space_ID argument. */ - next_node =acpi_ns_get_next_node (ec_device_node,NULL ); + next_node =acpi_ns_get_next_node (device_node,NULL );while (next_node) {if ((next_node->type ==ACPI_TYPE_REGION ) && (next_node->object) && - (next_node->object->region.space_id ==ACPI_ADR_SPACE_EC )) { + (next_node->object->region.space_id == space_id)) { goto exit;/* Do not execute the _REG */ } - next_node =acpi_ns_get_next_node (ec_device_node, next_node); + next_node =acpi_ns_get_next_node (device_node, next_node); } -/* Evaluate the _REG(embedded_control,Connect) method */ +/* Evaluate the _REG(space_id, Connect) method */ args.count =2 ; args.pointer = objects; objects[0 ].type =ACPI_TYPE_INTEGER ; - objects[0 ].integer.value =ACPI_ADR_SPACE_EC ; + objects[0 ].integer.value = space_id; objects[1 ].type =ACPI_TYPE_INTEGER ; objects[1 ].integer.value =ACPI_REG_CONNECT ;Signature · 1 line
2.28.0
Mika Westerberg
maintainerQuoted 3 lines · Hans de Goede
Mika, do you have input wrt always calling
_REGfor just the GpioIoOpRegion type (on top of the existing EC exception) vs just simply always calling it for all all/more OpRegion types ?
IMO it is safer to call it only for GPIO (GpioIoOpRegion) now.
Hi,
Quoted 6 lines · Mika Westerberg
Quoted 3 lines · Hans de Goede
Mika, do you have input wrt always calling
_REGfor just the GpioIoOpRegion type (on top of the existing EC exception) vs just simply always calling it for all all/more OpRegion types ?IMO it is safer to call it only for GPIO (GpioIoOpRegion) now.
That was my thought too, and is what my current patch does. Thank you for your input on this.
Regards,
Hans
Sasha Levin
maintainerHi
[This is an automated email]
This commit has been processed because it contains a -stable tag. The stable tag indicates that it's relevant for the following trees: all
The bot has tested the following trees: v5.6.10, v5.4.38, v4.19.120, v4.14.178, v4.9.221, v4.4.221.
v5.6.10: Build OK!
v5.4.38: Build OK!
v4.19.120: Build OK!
v4.14.178: Build OK!
v4.9.221: Failed to apply! Possible dependencies:
a0b028597d59 ("pinctrl: cherryview: Add support for GMMR GPIO opregion")
v4.4.221: Build OK!
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Signature · 2 lines
Thanks Sasha