* [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
@ 2021-11-22 22:04 Hans de Goede
2021-11-23 9:36 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Hans de Goede @ 2021-11-22 22:04 UTC (permalink / raw)
To: Mika Westerberg, Andy Shevchenko, Linus Walleij
Cc: Hans de Goede, linux-gpio, linux-acpi
If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really
should not change the type underneath the current owner.
I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay
Trail tablet, when the Boot OS selection in the BIOS is set to Android.
In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and
the _CRS resources for this device include a GpioInt pointing to a GPIO
already in use by an _AEI handler, with a different type then specified
in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get()
call done by the i2c-core-acpi.c code changing the type breaking the
_AEI handler.
Now this clearly is a bug in the DSDT of this tablet (in Android mode),
but in general calling irq_set_irq_type() on an IRQ which already is
in use seems like a bad idea.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/gpio/gpiolib-acpi.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 985e8589c58b..24cd86bf2c4c 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -1056,8 +1056,12 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind
irq_flags = acpi_dev_get_irq_type(info.triggering,
info.polarity);
- /* Set type if specified and different than the current one */
- if (irq_flags != IRQ_TYPE_NONE &&
+ /*
+ * If the IRQ is not already in use then set type
+ * if specified and different than the current one.
+ */
+ if (can_request_irq(irq, irq_flags) &&
+ irq_flags != IRQ_TYPE_NONE &&
irq_flags != irq_get_trigger_type(irq))
irq_set_irq_type(irq, irq_flags);
--
2.33.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
2021-11-22 22:04 [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Hans de Goede
@ 2021-11-23 9:36 ` Andy Shevchenko
2021-11-23 10:59 ` Hans de Goede
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2021-11-23 9:36 UTC (permalink / raw)
To: Hans de Goede
Cc: Mika Westerberg, Andy Shevchenko, Linus Walleij, linux-gpio, linux-acpi
On Mon, Nov 22, 2021 at 11:04:16PM +0100, Hans de Goede wrote:
> If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really
> should not change the type underneath the current owner.
>
> I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay
> Trail tablet, when the Boot OS selection in the BIOS is set to Android.
> In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and
> the _CRS resources for this device include a GpioInt pointing to a GPIO
> already in use by an _AEI handler, with a different type then specified
> in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get()
> call done by the i2c-core-acpi.c code changing the type breaking the
> _AEI handler.
>
> Now this clearly is a bug in the DSDT of this tablet (in Android mode),
> but in general calling irq_set_irq_type() on an IRQ which already is
> in use seems like a bad idea.
I'm fine with the change, one comment below, though.
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/gpio/gpiolib-acpi.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index 985e8589c58b..24cd86bf2c4c 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -1056,8 +1056,12 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind
> irq_flags = acpi_dev_get_irq_type(info.triggering,
> info.polarity);
>
> - /* Set type if specified and different than the current one */
> - if (irq_flags != IRQ_TYPE_NONE &&
> + /*
> + * If the IRQ is not already in use then set type
> + * if specified and different than the current one.
> + */
> + if (can_request_irq(irq, irq_flags) &&
> + irq_flags != IRQ_TYPE_NONE &&
> irq_flags != irq_get_trigger_type(irq))
> irq_set_irq_type(irq, irq_flags);
What about issuing a debug (?) message
if (can_request_irq(irq, irq_flags) {
if (irq_flags != IRQ_TYPE_NONE &&
irq_flags != irq_get_trigger_type(irq))
irq_set_irq_type(irq, irq_flags);
} else {
dev_dbg(..., FW_BUG "IRQ %d already in use\n", irq);
}
?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
2021-11-23 9:36 ` Andy Shevchenko
@ 2021-11-23 10:59 ` Hans de Goede
2021-11-23 11:01 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Hans de Goede @ 2021-11-23 10:59 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Mika Westerberg, Andy Shevchenko, Linus Walleij, linux-gpio, linux-acpi
Hi,
On 11/23/21 10:36, Andy Shevchenko wrote:
> On Mon, Nov 22, 2021 at 11:04:16PM +0100, Hans de Goede wrote:
>> If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really
>> should not change the type underneath the current owner.
>>
>> I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay
>> Trail tablet, when the Boot OS selection in the BIOS is set to Android.
>> In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and
>> the _CRS resources for this device include a GpioInt pointing to a GPIO
>> already in use by an _AEI handler, with a different type then specified
>> in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get()
>> call done by the i2c-core-acpi.c code changing the type breaking the
>> _AEI handler.
>>
>> Now this clearly is a bug in the DSDT of this tablet (in Android mode),
>> but in general calling irq_set_irq_type() on an IRQ which already is
>> in use seems like a bad idea.
>
> I'm fine with the change, one comment below, though.
>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> drivers/gpio/gpiolib-acpi.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
>> index 985e8589c58b..24cd86bf2c4c 100644
>> --- a/drivers/gpio/gpiolib-acpi.c
>> +++ b/drivers/gpio/gpiolib-acpi.c
>> @@ -1056,8 +1056,12 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind
>> irq_flags = acpi_dev_get_irq_type(info.triggering,
>> info.polarity);
>>
>> - /* Set type if specified and different than the current one */
>> - if (irq_flags != IRQ_TYPE_NONE &&
>> + /*
>> + * If the IRQ is not already in use then set type
>> + * if specified and different than the current one.
>> + */
>> + if (can_request_irq(irq, irq_flags) &&
>> + irq_flags != IRQ_TYPE_NONE &&
>> irq_flags != irq_get_trigger_type(irq))
>> irq_set_irq_type(irq, irq_flags);
>
> What about issuing a debug (?) message
>
> if (can_request_irq(irq, irq_flags) {
> if (irq_flags != IRQ_TYPE_NONE &&
> irq_flags != irq_get_trigger_type(irq))
> irq_set_irq_type(irq, irq_flags);
> } else {
> dev_dbg(..., FW_BUG "IRQ %d already in use\n", irq);
> }
>
> ?
That is a good idea, I would even be fine with making it a dev_warn, because it
really is a FW_BUG if we get here. If we turn out to hit this too much we
can always lower the log level later.
Shall I submit a v2 with your suggestion, but then using a dev_warn ?
Regards,
Hans
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
2021-11-23 10:59 ` Hans de Goede
@ 2021-11-23 11:01 ` Andy Shevchenko
2021-11-25 20:35 ` Hans de Goede
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2021-11-23 11:01 UTC (permalink / raw)
To: Hans de Goede
Cc: Andy Shevchenko, Mika Westerberg, Andy Shevchenko, Linus Walleij,
open list:GPIO SUBSYSTEM, ACPI Devel Maling List
On Tue, Nov 23, 2021 at 12:59 PM Hans de Goede <hdegoede@redhat.com> wrote:
> On 11/23/21 10:36, Andy Shevchenko wrote:
> > On Mon, Nov 22, 2021 at 11:04:16PM +0100, Hans de Goede wrote:
> >> If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really
> >> should not change the type underneath the current owner.
> >>
> >> I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay
> >> Trail tablet, when the Boot OS selection in the BIOS is set to Android.
> >> In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and
> >> the _CRS resources for this device include a GpioInt pointing to a GPIO
> >> already in use by an _AEI handler, with a different type then specified
> >> in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get()
> >> call done by the i2c-core-acpi.c code changing the type breaking the
> >> _AEI handler.
> >>
> >> Now this clearly is a bug in the DSDT of this tablet (in Android mode),
> >> but in general calling irq_set_irq_type() on an IRQ which already is
> >> in use seems like a bad idea.
> >
> > I'm fine with the change, one comment below, though.
> >
> >> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> >> ---
> >> drivers/gpio/gpiolib-acpi.c | 8 ++++++--
> >> 1 file changed, 6 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> >> index 985e8589c58b..24cd86bf2c4c 100644
> >> --- a/drivers/gpio/gpiolib-acpi.c
> >> +++ b/drivers/gpio/gpiolib-acpi.c
> >> @@ -1056,8 +1056,12 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind
> >> irq_flags = acpi_dev_get_irq_type(info.triggering,
> >> info.polarity);
> >>
> >> - /* Set type if specified and different than the current one */
> >> - if (irq_flags != IRQ_TYPE_NONE &&
> >> + /*
> >> + * If the IRQ is not already in use then set type
> >> + * if specified and different than the current one.
> >> + */
> >> + if (can_request_irq(irq, irq_flags) &&
> >> + irq_flags != IRQ_TYPE_NONE &&
> >> irq_flags != irq_get_trigger_type(irq))
> >> irq_set_irq_type(irq, irq_flags);
> >
> > What about issuing a debug (?) message
> >
> > if (can_request_irq(irq, irq_flags) {
> > if (irq_flags != IRQ_TYPE_NONE &&
> > irq_flags != irq_get_trigger_type(irq))
> > irq_set_irq_type(irq, irq_flags);
> > } else {
> > dev_dbg(..., FW_BUG "IRQ %d already in use\n", irq);
> > }
> >
> > ?
>
> That is a good idea, I would even be fine with making it a dev_warn, because it
> really is a FW_BUG if we get here. If we turn out to hit this too much we
> can always lower the log level later.
>
> Shall I submit a v2 with your suggestion, but then using a dev_warn ?
Please do, it will be slightly easier for me.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
2021-11-23 11:01 ` Andy Shevchenko
@ 2021-11-25 20:35 ` Hans de Goede
0 siblings, 0 replies; 7+ messages in thread
From: Hans de Goede @ 2021-11-25 20:35 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andy Shevchenko, Mika Westerberg, Andy Shevchenko, Linus Walleij,
open list:GPIO SUBSYSTEM, ACPI Devel Maling List
Hi,
On 11/23/21 12:01, Andy Shevchenko wrote:
> On Tue, Nov 23, 2021 at 12:59 PM Hans de Goede <hdegoede@redhat.com> wrote:
>> On 11/23/21 10:36, Andy Shevchenko wrote:
>>> On Mon, Nov 22, 2021 at 11:04:16PM +0100, Hans de Goede wrote:
>>>> If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really
>>>> should not change the type underneath the current owner.
>>>>
>>>> I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay
>>>> Trail tablet, when the Boot OS selection in the BIOS is set to Android.
>>>> In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and
>>>> the _CRS resources for this device include a GpioInt pointing to a GPIO
>>>> already in use by an _AEI handler, with a different type then specified
>>>> in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get()
>>>> call done by the i2c-core-acpi.c code changing the type breaking the
>>>> _AEI handler.
>>>>
>>>> Now this clearly is a bug in the DSDT of this tablet (in Android mode),
>>>> but in general calling irq_set_irq_type() on an IRQ which already is
>>>> in use seems like a bad idea.
>>>
>>> I'm fine with the change, one comment below, though.
>>>
>>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>>> ---
>>>> drivers/gpio/gpiolib-acpi.c | 8 ++++++--
>>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
>>>> index 985e8589c58b..24cd86bf2c4c 100644
>>>> --- a/drivers/gpio/gpiolib-acpi.c
>>>> +++ b/drivers/gpio/gpiolib-acpi.c
>>>> @@ -1056,8 +1056,12 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind
>>>> irq_flags = acpi_dev_get_irq_type(info.triggering,
>>>> info.polarity);
>>>>
>>>> - /* Set type if specified and different than the current one */
>>>> - if (irq_flags != IRQ_TYPE_NONE &&
>>>> + /*
>>>> + * If the IRQ is not already in use then set type
>>>> + * if specified and different than the current one.
>>>> + */
>>>> + if (can_request_irq(irq, irq_flags) &&
>>>> + irq_flags != IRQ_TYPE_NONE &&
>>>> irq_flags != irq_get_trigger_type(irq))
>>>> irq_set_irq_type(irq, irq_flags);
>>>
>>> What about issuing a debug (?) message
>>>
>>> if (can_request_irq(irq, irq_flags) {
>>> if (irq_flags != IRQ_TYPE_NONE &&
>>> irq_flags != irq_get_trigger_type(irq))
>>> irq_set_irq_type(irq, irq_flags);
>>> } else {
>>> dev_dbg(..., FW_BUG "IRQ %d already in use\n", irq);
>>> }
>>>
>>> ?
>>
>> That is a good idea, I would even be fine with making it a dev_warn, because it
>> really is a FW_BUG if we get here. If we turn out to hit this too much we
>> can always lower the log level later.
>>
>> Shall I submit a v2 with your suggestion, but then using a dev_warn ?
>
> Please do, it will be slightly easier for me.
Ok, I've just send out a v2. Note I forgot to add -v2 to format-patch so
the subject does not say it is v2, sorry.
Regards,
Hans
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
2021-11-25 20:30 Hans de Goede
@ 2021-11-25 21:39 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2021-11-25 21:39 UTC (permalink / raw)
To: Hans de Goede
Cc: Mika Westerberg, Andy Shevchenko, Linus Walleij, linux-gpio, linux-acpi
On Thu, Nov 25, 2021 at 09:30:10PM +0100, Hans de Goede wrote:
> If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really
> should not change the type underneath the current owner.
>
> I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay
> Trail tablet, when the Boot OS selection in the BIOS is set to Android.
> In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and
> the _CRS resources for this device include a GpioInt pointing to a GPIO
> already in use by an _AEI handler, with a different type then specified
> in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get()
> call done by the i2c-core-acpi.c code changing the type breaking the
> _AEI handler.
>
> Now this clearly is a bug in the DSDT of this tablet (in Android mode),
> but in general calling irq_set_irq_type() on an IRQ which already is
> in use seems like a bad idea.
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> - Emit a dev_dbg when the IRQ is already in use. Note while making this
> change I realized that i2c-multi-instantiate.c actually uses
> acpi_dev_gpio_irq_get_by() with shared interrupts, so I decided to
> go with a dev_dbg instead of a dev_warn after all
Okay, this explains drop of FW_BUG macro, I suppose.
Pushed to my review and testing queue, thanks!
> ---
> drivers/gpio/gpiolib-acpi.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index 985e8589c58b..feb8157d2d67 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -1056,10 +1056,17 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind
> irq_flags = acpi_dev_get_irq_type(info.triggering,
> info.polarity);
>
> - /* Set type if specified and different than the current one */
> - if (irq_flags != IRQ_TYPE_NONE &&
> - irq_flags != irq_get_trigger_type(irq))
> - irq_set_irq_type(irq, irq_flags);
> + /*
> + * If the IRQ is not already in use then set type
> + * if specified and different than the current one.
> + */
> + if (can_request_irq(irq, irq_flags)) {
> + if (irq_flags != IRQ_TYPE_NONE &&
> + irq_flags != irq_get_trigger_type(irq))
> + irq_set_irq_type(irq, irq_flags);
> + } else {
> + dev_dbg(&adev->dev, "IRQ %d already in use\n", irq);
> + }
>
> return irq;
> }
> --
> 2.33.1
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
@ 2021-11-25 20:30 Hans de Goede
2021-11-25 21:39 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Hans de Goede @ 2021-11-25 20:30 UTC (permalink / raw)
To: Mika Westerberg, Andy Shevchenko, Linus Walleij
Cc: Hans de Goede, linux-gpio, linux-acpi
If the IRQ is already in use, then acpi_dev_gpio_irq_get_by() really
should not change the type underneath the current owner.
I specifically hit an issue with this an a Chuwi Hi8 Super (CWI509) Bay
Trail tablet, when the Boot OS selection in the BIOS is set to Android.
In this case _STA for a MAX17047 ACPI I2C device wrongly returns 0xf and
the _CRS resources for this device include a GpioInt pointing to a GPIO
already in use by an _AEI handler, with a different type then specified
in the _CRS for the MAX17047 device. Leading to the acpi_dev_gpio_irq_get()
call done by the i2c-core-acpi.c code changing the type breaking the
_AEI handler.
Now this clearly is a bug in the DSDT of this tablet (in Android mode),
but in general calling irq_set_irq_type() on an IRQ which already is
in use seems like a bad idea.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
- Emit a dev_dbg when the IRQ is already in use. Note while making this
change I realized that i2c-multi-instantiate.c actually uses
acpi_dev_gpio_irq_get_by() with shared interrupts, so I decided to
go with a dev_dbg instead of a dev_warn after all
---
drivers/gpio/gpiolib-acpi.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 985e8589c58b..feb8157d2d67 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -1056,10 +1056,17 @@ int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int ind
irq_flags = acpi_dev_get_irq_type(info.triggering,
info.polarity);
- /* Set type if specified and different than the current one */
- if (irq_flags != IRQ_TYPE_NONE &&
- irq_flags != irq_get_trigger_type(irq))
- irq_set_irq_type(irq, irq_flags);
+ /*
+ * If the IRQ is not already in use then set type
+ * if specified and different than the current one.
+ */
+ if (can_request_irq(irq, irq_flags)) {
+ if (irq_flags != IRQ_TYPE_NONE &&
+ irq_flags != irq_get_trigger_type(irq))
+ irq_set_irq_type(irq, irq_flags);
+ } else {
+ dev_dbg(&adev->dev, "IRQ %d already in use\n", irq);
+ }
return irq;
}
--
2.33.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-11-25 21:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 22:04 [PATCH] gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use Hans de Goede
2021-11-23 9:36 ` Andy Shevchenko
2021-11-23 10:59 ` Hans de Goede
2021-11-23 11:01 ` Andy Shevchenko
2021-11-25 20:35 ` Hans de Goede
2021-11-25 20:30 Hans de Goede
2021-11-25 21:39 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.