2019-02-07 18:59:49

by Enrico Granata

[permalink] [raw]
Subject: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

From: Enrico Granata <[email protected]>

ACPI 5 added support for GpioInt resources as a way to provide
information about interrupts mediated via a GPIO controller.

Several device buses (e.g. SPI, I2C) have support for retrieving
an IRQ specified via this type of resource, and providing it
directly to the driver as an IRQ number.
This is not currently done for the platform drivers, as platform_get_irq()
does not try to parse GpioInt() resources.

This commit adds that functionality.

Signed-off-by: Enrico Granata <[email protected]>
---
drivers/base/platform.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 1c958eb33ef4d..c50c4f9033aef 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -127,7 +127,17 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
}

- return r ? r->start : -ENXIO;
+ if (r)
+ return r->start;
+
+ /*
+ * If no IRQ was found, try to parse ACPI GpioInt resources
+ * as a last resort.
+ */
+ if (has_acpi_companion(&dev->dev))
+ return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
+
+ return -ENXIO;
#endif
}
EXPORT_SYMBOL_GPL(platform_get_irq);
--
2.20.1.611.gfbb209baf1-goog



2019-02-07 19:03:19

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

+Mika Westerberg
+Andy Shevchenko
+Hans de Goede

On Thu, Feb 7, 2019 at 7:59 PM <[email protected]> wrote:
>
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources.
>
> This commit adds that functionality.
>
> Signed-off-by: Enrico Granata <[email protected]>
> ---
> drivers/base/platform.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..c50c4f9033aef 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,17 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * If no IRQ was found, try to parse ACPI GpioInt resources
> + * as a last resort.
> + */
> + if (has_acpi_companion(&dev->dev))
> + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
> --
> 2.20.1.611.gfbb209baf1-goog
>

2019-02-07 19:41:28

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

On Thu, Feb 7, 2019 at 9:04 PM Rafael J. Wysocki <[email protected]> wrote:
>
> +Mika Westerberg
> +Andy Shevchenko
> +Hans de Goede

Thanks, Rafael.
My comments below.

> On Thu, Feb 7, 2019 at 7:59 PM <[email protected]> wrote:
> >
> > From: Enrico Granata <[email protected]>
> >
> > ACPI 5 added support for GpioInt resources as a way to provide
> > information about interrupts mediated via a GPIO controller.
> >
> > Several device buses (e.g. SPI, I2C) have support for retrieving
> > an IRQ specified via this type of resource, and providing it
> > directly to the driver as an IRQ number.

> > This is not currently done for the platform drivers, as platform_get_irq()
> > does not try to parse GpioInt() resources.

And why is this a problem?

> > This commit adds that functionality.

How that can override the configuration / BIOS flavour when driver
needs to register an interrupt out of GpioIo() resource?

P.S. Have you looked at drivers/platform/x86/i2c-multi-instantiate.c
and intel_cht_int33fe.c?
They are the only drivers which needs something like this for now and
I would rather say it's a bad BIOS decision to write a table like
that.

--
With Best Regards,
Andy Shevchenko

2019-02-07 19:46:25

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

On Thu, Feb 7, 2019 at 9:39 PM Andy Shevchenko
<[email protected]> wrote:
> On Thu, Feb 7, 2019 at 9:04 PM Rafael J. Wysocki <[email protected]> wrote:

> > > This commit adds that functionality.
>
> How that can override the configuration / BIOS flavour when driver
> needs to register an interrupt out of GpioIo() resource?

One more missed example,

Two variants of the IRQ resources in the table for the _same_ device
but on different platforms.

--Variant1--
Device(XYZ)
_CRS1() {
Interrupt()
GpioInt()
Interrupt()
}

--Variant2--
Device(XYZ)
_CRS2() {
GpioInt()
Interrupt()
Interrupt()
}

How to always get second resource?

--
With Best Regards,
Andy Shevchenko

2019-02-07 19:56:01

by Enrico Granata

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

Resending as plain text; comments inlined.

On Thu, Feb 7, 2019 at 11:39 AM Andy Shevchenko
<[email protected]> wrote:
>
> On Thu, Feb 7, 2019 at 9:04 PM Rafael J. Wysocki <[email protected]> wrote:
> >
> > +Mika Westerberg
> > +Andy Shevchenko
> > +Hans de Goede
>
> Thanks, Rafael.
> My comments below.
>
> > On Thu, Feb 7, 2019 at 7:59 PM <[email protected]> wrote:
> > >
> > > From: Enrico Granata <[email protected]>
> > >
> > > ACPI 5 added support for GpioInt resources as a way to provide
> > > information about interrupts mediated via a GPIO controller.
> > >
> > > Several device buses (e.g. SPI, I2C) have support for retrieving
> > > an IRQ specified via this type of resource, and providing it
> > > directly to the driver as an IRQ number.
>
> > > This is not currently done for the platform drivers, as platform_get_irq()
> > > does not try to parse GpioInt() resources.
>
> And why is this a problem?

In ChromeOS, we have a driver (cros_ec_lpc) which can run either on
systems that directly expose the interrupt,
or systems where the interrupt goes through a GPIO controller. On the
former, firmware provides an Interrupt resource
and platform_get_irq() finds it. On the latter, firmware provides a
GpioInt resource and platform_get_irq does not
find it. We could work around this in the driver by probing both
paths, but since other subsystems seem to directly
look for GpioInt resources, it seemed to us to make more sense to
extend platform_get_irq() instead.

> > > This commit adds that functionality.
>
> How that can override the configuration / BIOS flavour when driver
> needs to register an interrupt out of GpioIo() resource?
>
> P.S. Have you looked at drivers/platform/x86/i2c-multi-instantiate.c
> and intel_cht_int33fe.c?

Those drivers seem to only ever expect a GpioInt(). Our case is one
where both are possible,
depending on the system we're running on. We are trying not to put
ad-hoc logic in the driver,
but if you think that doing so would be our best course of action,
please do let us know.

> They are the only drivers which needs something like this for now and
> I would rather say it's a bad BIOS decision to write a table like
> that.

Do you have any suggestions to write proper firmware tables to avoid this issue?

>
> --
> With Best Regards,
> Andy Shevchenko

2019-02-07 20:19:55

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

On Thu, Feb 7, 2019 at 9:45 PM Enrico Granata <[email protected]> wrote:
> On Thu, Feb 7, 2019 at 11:39 AM Andy Shevchenko <[email protected]> wrote:
>> On Thu, Feb 7, 2019 at 9:04 PM Rafael J. Wysocki <[email protected]> wrote:

>> > > This is not currently done for the platform drivers, as platform_get_irq()
>> > > does not try to parse GpioInt() resources.
>>
>> And why is this a problem?

> In ChromeOS, we have a driver (cros_ec_lpc) which can run either on systems that directly expose the interrupt,
> or systems where the interrupt goes through a GPIO controller. On the former, firmware provides an Interrupt resource
> and platform_get_irq() finds it. On the latter, firmware provides a GpioInt resource and platform_get_irq does not
> find it. We could work around this in the driver by probing both paths, but since other subsystems seem to directly
> look for GpioInt resources, it seemed to us to make more sense to extend platform_get_irq() instead.

Looking briefly into the driver I found third scenario — no resource at all.
So, you already have a quirk for that. Now it's the question either
you go for global quirk (trying to find an IRQ via iterating over
GpioInt() resources like in this patch, but in the driver), or use DMI
table for more stricter rules.

Either way you choose, I don't see a necessity to put this to the
driver core for now since it would be the only (let's assume properly
written ACPI tables) driver needs such.

> Do you have a suggestion as to how to write ACPI tables to avoid the issue?

1. Allocate new ID and use it (perhaps not the best path).
2. Use GPE(s).

--
With Best Regards,
Andy Shevchenko

2019-02-07 20:30:39

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

On Thu, Feb 7, 2019 at 12:18 PM Andy Shevchenko
<[email protected]> wrote:
>
> On Thu, Feb 7, 2019 at 9:45 PM Enrico Granata <[email protected]> wrote:
> > On Thu, Feb 7, 2019 at 11:39 AM Andy Shevchenko <[email protected]> wrote:
> >> On Thu, Feb 7, 2019 at 9:04 PM Rafael J. Wysocki <[email protected]> wrote:
>
> >> > > This is not currently done for the platform drivers, as platform_get_irq()
> >> > > does not try to parse GpioInt() resources.
> >>
> >> And why is this a problem?
>
> > In ChromeOS, we have a driver (cros_ec_lpc) which can run either on systems that directly expose the interrupt,
> > or systems where the interrupt goes through a GPIO controller. On the former, firmware provides an Interrupt resource
> > and platform_get_irq() finds it. On the latter, firmware provides a GpioInt resource and platform_get_irq does not
> > find it. We could work around this in the driver by probing both paths, but since other subsystems seem to directly
> > look for GpioInt resources, it seemed to us to make more sense to extend platform_get_irq() instead.
>
> Looking briefly into the driver I found third scenario — no resource at all.
> So, you already have a quirk for that. Now it's the question either
> you go for global quirk (trying to find an IRQ via iterating over
> GpioInt() resources like in this patch, but in the driver), or use DMI
> table for more stricter rules.

No, no DMI rules please, they are more pain than anything.

>
> Either way you choose, I don't see a necessity to put this to the
> driver core for now since it would be the only (let's assume properly
> written ACPI tables) driver needs such.

This is simply kicking the can down the road.

>
> > Do you have a suggestion as to how to write ACPI tables to avoid the issue?
>
> 1. Allocate new ID and use it (perhaps not the best path).
> 2. Use GPE(s).
>

Or just solve the issue of intermixing Interrupt() with GpioInt(). We
have similar issue with i2c and spi, but we sidestep that there as we
only parse the first interrupt and do not give option of fetching 2nd,
3rd, etc. Maybe we should only GpioInt parsing for the first interrupt
in platform_get_irq() as well for the first iteration and then see if
we need to improve it if we see devices with multiple interrupts.

Thanks,
Dmitry

2019-02-11 10:31:52

by Mika Westerberg

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

Hi,

On Thu, Feb 07, 2019 at 12:29:17PM -0800, Dmitry Torokhov wrote:
> >
> > > Do you have a suggestion as to how to write ACPI tables to avoid the issue?
> >
> > 1. Allocate new ID and use it (perhaps not the best path).
> > 2. Use GPE(s).
> >
>
> Or just solve the issue of intermixing Interrupt() with GpioInt(). We
> have similar issue with i2c and spi, but we sidestep that there as we
> only parse the first interrupt and do not give option of fetching 2nd,
> 3rd, etc. Maybe we should only GpioInt parsing for the first interrupt
> in platform_get_irq() as well for the first iteration and then see if
> we need to improve it if we see devices with multiple interrupts.

I think it should be fine to intermix them or do what you suggest and
start supporting index 0 for now and then maybe extend it in the future
to cover more.

2019-02-11 15:45:20

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH] driver: platform: Add support for GpioInt() ACPI to platform_get_irq()

Hi,

On 11-02-19 11:30, Mika Westerberg wrote:
> Hi,
>
> On Thu, Feb 07, 2019 at 12:29:17PM -0800, Dmitry Torokhov wrote:
>>>
>>>> Do you have a suggestion as to how to write ACPI tables to avoid the issue?
>>>
>>> 1. Allocate new ID and use it (perhaps not the best path).
>>> 2. Use GPE(s).
>>>
>>
>> Or just solve the issue of intermixing Interrupt() with GpioInt(). We
>> have similar issue with i2c and spi, but we sidestep that there as we
>> only parse the first interrupt and do not give option of fetching 2nd,
>> 3rd, etc. Maybe we should only GpioInt parsing for the first interrupt
>> in platform_get_irq() as well for the first iteration and then see if
>> we need to improve it if we see devices with multiple interrupts.
>
> I think it should be fine to intermix them or do what you suggest and
> start supporting index 0 for now and then maybe extend it in the future
> to cover more.

I think only support fallback to GpioInt for index 0 for now is probably
the best solution. A device could have both Interrupt and GpioInt resources,
as soon as that is the case then the meaning of index becomes ambiguous.

We are already seeing something similar with mixed use of GpioInt + Gpio
resources on some devices, where we need the GpioInt for the IRQ and
the Gpio resource to toggle something else and the ACPI tables on
different devices have them in a different order, see:
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git/commit/?id=4d1f7a6eabd45639d9de22a8a004f3c208d13c1a

I suspect that on Windows device drivers specifically specify if they want a
Gpio or a GpioInt; or in this case if they want an Interrupt or a GpioInt.

Regards,

Hans

2019-02-11 20:41:16

by egranata

[permalink] [raw]
Subject: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

From: Enrico Granata <[email protected]>

ACPI 5 added support for GpioInt resources as a way to provide
information about interrupts mediated via a GPIO controller.

Several device buses (e.g. SPI, I2C) have support for retrieving
an IRQ specified via this type of resource, and providing it
directly to the driver as an IRQ number.

This is not currently done for the platform drivers, as platform_get_irq()
does not try to parse GpioInt() resources. This requires drivers to
either have to support only one possible IRQ resource, or to have code
in place to try both as a failsafe.

While there is a possibility of ambiguity for devices that exposes
multiple IRQs, it is easy and feasible to support the common case
of devices that only expose one IRQ which would be of either type
depending on the underlying system's architecture.

This commit adds support for parsing a GpioInt resource in order
to fulfill a request for the index 0 IRQ for a platform device.

Signed-off-by: Enrico Granata <[email protected]>
---
Changes in v2:
- only support IRQ index 0

drivers/base/platform.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 1c958eb33ef4d..0d3611cd1b3bc 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
}

- return r ? r->start : -ENXIO;
+ if (r)
+ return r->start;
+
+ /*
+ * For the index 0 interrupt, allow falling back to GpioInt
+ * resources. While a device could have both Interrupt and GpioInt
+ * resources, making this fallback ambiguous, in many common cases
+ * the device will only expose one IRQ, and this fallback
+ * allows a common code path across either kind of resource.
+ */
+ if (num == 0 && has_acpi_companion(&dev->dev))
+ return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
+
+ return -ENXIO;
#endif
}
EXPORT_SYMBOL_GPL(platform_get_irq);
--
2.20.1.791.gb4d0f1c61a-goog


2019-02-11 20:42:05

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

On Mon, Feb 11, 2019 at 11:01 AM <[email protected]> wrote:
>
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>
> Signed-off-by: Enrico Granata <[email protected]>

Yeah, this looks good to me.

Reviewed-by: Dmitry Torokhov <[email protected]>

> ---
> Changes in v2:
> - only support IRQ index 0
>
> drivers/base/platform.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..0d3611cd1b3bc 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * For the index 0 interrupt, allow falling back to GpioInt
> + * resources. While a device could have both Interrupt and GpioInt
> + * resources, making this fallback ambiguous, in many common cases
> + * the device will only expose one IRQ, and this fallback
> + * allows a common code path across either kind of resource.
> + */
> + if (num == 0 && has_acpi_companion(&dev->dev))
> + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
> --
> 2.20.1.791.gb4d0f1c61a-goog
>

2019-02-12 07:30:29

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

Hi,

On 11-02-19 20:01, [email protected] wrote:
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>
> Signed-off-by: Enrico Granata <[email protected]>

Looks good to me:

Acked-by: Hans de Goede <[email protected]>

Regards,

Hans


> ---
> Changes in v2:
> - only support IRQ index 0
>
> drivers/base/platform.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..0d3611cd1b3bc 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * For the index 0 interrupt, allow falling back to GpioInt
> + * resources. While a device could have both Interrupt and GpioInt
> + * resources, making this fallback ambiguous, in many common cases
> + * the device will only expose one IRQ, and this fallback
> + * allows a common code path across either kind of resource.
> + */
> + if (num == 0 && has_acpi_companion(&dev->dev))
> + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
>

2019-02-12 09:09:34

by Mika Westerberg

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

On Mon, Feb 11, 2019 at 11:01:12AM -0800, [email protected] wrote:
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>
> Signed-off-by: Enrico Granata <[email protected]>

Reviewed-by: Mika Westerberg <[email protected]>

2019-02-12 09:19:56

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

On Mon, Feb 11, 2019 at 8:01 PM <[email protected]> wrote:
>
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>
> Signed-off-by: Enrico Granata <[email protected]>

Reviewed-by: Rafael J. Wysocki <[email protected]>

> ---
> Changes in v2:
> - only support IRQ index 0
>
> drivers/base/platform.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..0d3611cd1b3bc 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * For the index 0 interrupt, allow falling back to GpioInt
> + * resources. While a device could have both Interrupt and GpioInt
> + * resources, making this fallback ambiguous, in many common cases
> + * the device will only expose one IRQ, and this fallback
> + * allows a common code path across either kind of resource.
> + */
> + if (num == 0 && has_acpi_companion(&dev->dev))
> + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
> --
> 2.20.1.791.gb4d0f1c61a-goog
>

2019-02-12 12:58:36

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

On Mon, Feb 11, 2019 at 11:01:12AM -0800, [email protected] wrote:
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>

Yes, let's go this way as a compromise to get major of the cases working.
Reviewed-by: Andy Shevchenko <[email protected]>

> Signed-off-by: Enrico Granata <[email protected]>
> ---
> Changes in v2:
> - only support IRQ index 0
>
> drivers/base/platform.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..0d3611cd1b3bc 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * For the index 0 interrupt, allow falling back to GpioInt
> + * resources. While a device could have both Interrupt and GpioInt
> + * resources, making this fallback ambiguous, in many common cases
> + * the device will only expose one IRQ, and this fallback
> + * allows a common code path across either kind of resource.
> + */
> + if (num == 0 && has_acpi_companion(&dev->dev))
> + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
> --
> 2.20.1.791.gb4d0f1c61a-goog
>

--
With Best Regards,
Andy Shevchenko



2019-02-20 18:07:02

by Brian Norris

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

Hi,

On Mon, Feb 11, 2019 at 11:01:12AM -0800, [email protected] wrote:
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>
> Signed-off-by: Enrico Granata <[email protected]>
> ---
> Changes in v2:
> - only support IRQ index 0
>
> drivers/base/platform.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..0d3611cd1b3bc 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * For the index 0 interrupt, allow falling back to GpioInt
> + * resources. While a device could have both Interrupt and GpioInt
> + * resources, making this fallback ambiguous, in many common cases
> + * the device will only expose one IRQ, and this fallback
> + * allows a common code path across either kind of resource.
> + */
> + if (num == 0 && has_acpi_companion(&dev->dev))
> + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);

For ACPI devices, this changes the return code for a missing interrupt
0 from ENXIO to ENOENT, because acpi_dev_gpio_irq_get() uses ENOENT
instead of ENXIO. While ENXIO isn't exactly documented as the *specific*
error code for a missing interrupt in platform_get_irq(), there are
definitely drivers out there that are looking specifically for ENXIO
(grepping the tree finds several Rockchip platform drivers and a few
ethernet drivers at a minimum). And it also incidentally broke some
usage of the very driver you were trying to support
(drivers/platform/chrome/cros_ec_lpc.c).

I suspect a good strategy here would be to check
acpi_dev_gpio_irq_get()'s return codes here with something like:

if (ret > 0 || ret == -EPROBE_DEFER)
return ret;
return -ENXIO;

Although, the gpiolib functions embedded in there also can return EIO,
so maybe something like this is better?

if (ret == -ENOENT || ret == 0)
return -ENXIO;
return ret;

I'm kinda unsure what to do with error codes besides PROBE_DEFER or
"missing", since most users don't really have it in their mind that
platform_get_irq() can fail with EIO or similar.

Brian

> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
> --
> 2.20.1.791.gb4d0f1c61a-goog
>

2019-02-21 18:59:37

by Enrico Granata

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

Thanks for catching that and sorry for the delayed response, I was on vacation.

I think your analysis makes sense. I would personally lean towards the
former suggestion (keeping the change localized to the return value of
platform_get_irq() which is the function that apparently has an
informal contract about returning -ENXIO specifically).

I am happy to post a PATCH v3 to that effect if this seems amenable.

Thanks

Enrico Granata | [email protected] | ChromeOS | MTV1600


On Wed, Feb 20, 2019 at 10:05 AM Brian Norris <[email protected]> wrote:
>
> Hi,
>
> On Mon, Feb 11, 2019 at 11:01:12AM -0800, [email protected] wrote:
> > From: Enrico Granata <[email protected]>
> >
> > ACPI 5 added support for GpioInt resources as a way to provide
> > information about interrupts mediated via a GPIO controller.
> >
> > Several device buses (e.g. SPI, I2C) have support for retrieving
> > an IRQ specified via this type of resource, and providing it
> > directly to the driver as an IRQ number.
> >
> > This is not currently done for the platform drivers, as platform_get_irq()
> > does not try to parse GpioInt() resources. This requires drivers to
> > either have to support only one possible IRQ resource, or to have code
> > in place to try both as a failsafe.
> >
> > While there is a possibility of ambiguity for devices that exposes
> > multiple IRQs, it is easy and feasible to support the common case
> > of devices that only expose one IRQ which would be of either type
> > depending on the underlying system's architecture.
> >
> > This commit adds support for parsing a GpioInt resource in order
> > to fulfill a request for the index 0 IRQ for a platform device.
> >
> > Signed-off-by: Enrico Granata <[email protected]>
> > ---
> > Changes in v2:
> > - only support IRQ index 0
> >
> > drivers/base/platform.c | 15 ++++++++++++++-
> > 1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index 1c958eb33ef4d..0d3611cd1b3bc 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> > irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> > }
> >
> > - return r ? r->start : -ENXIO;
> > + if (r)
> > + return r->start;
> > +
> > + /*
> > + * For the index 0 interrupt, allow falling back to GpioInt
> > + * resources. While a device could have both Interrupt and GpioInt
> > + * resources, making this fallback ambiguous, in many common cases
> > + * the device will only expose one IRQ, and this fallback
> > + * allows a common code path across either kind of resource.
> > + */
> > + if (num == 0 && has_acpi_companion(&dev->dev))
> > + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
>
> For ACPI devices, this changes the return code for a missing interrupt
> 0 from ENXIO to ENOENT, because acpi_dev_gpio_irq_get() uses ENOENT
> instead of ENXIO. While ENXIO isn't exactly documented as the *specific*
> error code for a missing interrupt in platform_get_irq(), there are
> definitely drivers out there that are looking specifically for ENXIO
> (grepping the tree finds several Rockchip platform drivers and a few
> ethernet drivers at a minimum). And it also incidentally broke some
> usage of the very driver you were trying to support
> (drivers/platform/chrome/cros_ec_lpc.c).
>
> I suspect a good strategy here would be to check
> acpi_dev_gpio_irq_get()'s return codes here with something like:
>
> if (ret > 0 || ret == -EPROBE_DEFER)
> return ret;
> return -ENXIO;
>
> Although, the gpiolib functions embedded in there also can return EIO,
> so maybe something like this is better?
>
> if (ret == -ENOENT || ret == 0)
> return -ENXIO;
> return ret;
>
> I'm kinda unsure what to do with error codes besides PROBE_DEFER or
> "missing", since most users don't really have it in their mind that
> platform_get_irq() can fail with EIO or similar.
>
> Brian
>
> > +
> > + return -ENXIO;
> > #endif
> > }
> > EXPORT_SYMBOL_GPL(platform_get_irq);
> > --
> > 2.20.1.791.gb4d0f1c61a-goog
> >

2019-02-21 19:35:29

by egranata

[permalink] [raw]
Subject: [PATCH v3] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

From: Enrico Granata <[email protected]>

ACPI 5 added support for GpioInt resources as a way to provide
information about interrupts mediated via a GPIO controller.

Several device buses (e.g. SPI, I2C) have support for retrieving
an IRQ specified via this type of resource, and providing it
directly to the driver as an IRQ number.

This is not currently done for the platform drivers, as platform_get_irq()
does not try to parse GpioInt() resources. This requires drivers to
either have to support only one possible IRQ resource, or to have code
in place to try both as a failsafe.

While there is a possibility of ambiguity for devices that exposes
multiple IRQs, it is easy and feasible to support the common case
of devices that only expose one IRQ which would be of either type
depending on the underlying system's architecture.

This commit adds support for parsing a GpioInt resource in order
to fulfill a request for the index 0 IRQ for a platform device.

Signed-off-by: Enrico Granata <[email protected]>
---
Changes in v3:
- ensured that -ENOENT return from acpi_dev_gpio_irq_get is not propagated
upwards, as some drivers expect platform_get_irq to return either a valid
IRQ or -ENXIO and will break otherwise

drivers/base/platform.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 1c958eb33ef4d..afd8b916303e4 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -127,7 +127,24 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
}

- return r ? r->start : -ENXIO;
+ if (r)
+ return r->start;
+
+ /*
+ * For the index 0 interrupt, allow falling back to GpioInt
+ * resources. While a device could have both Interrupt and GpioInt
+ * resources, making this fallback ambiguous, in many common cases
+ * the device will only expose one IRQ, and this fallback
+ * allows a common code path across either kind of resource.
+ */
+ if (num == 0 && has_acpi_companion(&dev->dev)) {
+ int ret = acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
+
+ if (ret > 0 || ret == -EPROBE_DEFER)
+ return ret;
+ }
+
+ return -ENXIO;
#endif
}
EXPORT_SYMBOL_GPL(platform_get_irq);
--
2.21.0.rc0.258.g878e2cd30e-goog


2019-02-22 09:04:11

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v3] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

On Thu, Feb 21, 2019 at 8:34 PM <[email protected]> wrote:
>
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>
> Signed-off-by: Enrico Granata <[email protected]>
> ---
> Changes in v3:
> - ensured that -ENOENT return from acpi_dev_gpio_irq_get is not propagated
> upwards, as some drivers expect platform_get_irq to return either a valid
> IRQ or -ENXIO and will break otherwise
>
> drivers/base/platform.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..afd8b916303e4 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,24 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * For the index 0 interrupt, allow falling back to GpioInt
> + * resources. While a device could have both Interrupt and GpioInt
> + * resources, making this fallback ambiguous, in many common cases
> + * the device will only expose one IRQ, and this fallback
> + * allows a common code path across either kind of resource.
> + */
> + if (num == 0 && has_acpi_companion(&dev->dev)) {
> + int ret = acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> +
> + if (ret > 0 || ret == -EPROBE_DEFER)

Can't 0 be a valid GPIO IRQ?

> + return ret;
> + }
> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
> --

2019-02-22 17:08:56

by Brian Norris

[permalink] [raw]
Subject: Re: [PATCH v3] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

On Fri, Feb 22, 2019 at 1:03 AM Rafael J. Wysocki <[email protected]> wrote:
>
> On Thu, Feb 21, 2019 at 8:34 PM <[email protected]> wrote:
> >
> > From: Enrico Granata <[email protected]>
> >
> > ACPI 5 added support for GpioInt resources as a way to provide
> > information about interrupts mediated via a GPIO controller.
> >
> > Several device buses (e.g. SPI, I2C) have support for retrieving
> > an IRQ specified via this type of resource, and providing it
> > directly to the driver as an IRQ number.
> >
> > This is not currently done for the platform drivers, as platform_get_irq()
> > does not try to parse GpioInt() resources. This requires drivers to
> > either have to support only one possible IRQ resource, or to have code
> > in place to try both as a failsafe.
> >
> > While there is a possibility of ambiguity for devices that exposes
> > multiple IRQs, it is easy and feasible to support the common case
> > of devices that only expose one IRQ which would be of either type
> > depending on the underlying system's architecture.
> >
> > This commit adds support for parsing a GpioInt resource in order
> > to fulfill a request for the index 0 IRQ for a platform device.
> >
> > Signed-off-by: Enrico Granata <[email protected]>
> > ---
> > Changes in v3:
> > - ensured that -ENOENT return from acpi_dev_gpio_irq_get is not propagated
> > upwards, as some drivers expect platform_get_irq to return either a valid
> > IRQ or -ENXIO and will break otherwise

I hope there are no other lurking ways in which this might break things...

Reviewed-by: Brian Norris <[email protected]>

> > drivers/base/platform.c | 19 ++++++++++++++++++-
> > 1 file changed, 18 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index 1c958eb33ef4d..afd8b916303e4 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -127,7 +127,24 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> > irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> > }
> >
> > - return r ? r->start : -ENXIO;
> > + if (r)
> > + return r->start;
> > +
> > + /*
> > + * For the index 0 interrupt, allow falling back to GpioInt
> > + * resources. While a device could have both Interrupt and GpioInt
> > + * resources, making this fallback ambiguous, in many common cases
> > + * the device will only expose one IRQ, and this fallback
> > + * allows a common code path across either kind of resource.
> > + */
> > + if (num == 0 && has_acpi_companion(&dev->dev)) {
> > + int ret = acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> > +
> > + if (ret > 0 || ret == -EPROBE_DEFER)
>
> Can't 0 be a valid GPIO IRQ?

acpi_dev_gpio_irq_get() claims:

* Return: Linux IRQ number (> %0) on success, negative errno on failure.

Should I trust the documentation? It seems like yes, I should:

int gpiod_to_irq(const struct gpio_desc *desc)
{
...
/* Zero means NO_IRQ */
if (!retirq)
return -ENXIO;


Brian

> > + return ret;
> > + }
> > +
> > + return -ENXIO;
> > #endif
> > }
> > EXPORT_SYMBOL_GPL(platform_get_irq);
> > --

2019-02-24 19:36:19

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2] driver: platform: Support parsing GpioInt 0 in platform_get_irq()

On Mon, Feb 11, 2019 at 8:01 PM <[email protected]> wrote:
>
> From: Enrico Granata <[email protected]>
>
> ACPI 5 added support for GpioInt resources as a way to provide
> information about interrupts mediated via a GPIO controller.
>
> Several device buses (e.g. SPI, I2C) have support for retrieving
> an IRQ specified via this type of resource, and providing it
> directly to the driver as an IRQ number.
>
> This is not currently done for the platform drivers, as platform_get_irq()
> does not try to parse GpioInt() resources. This requires drivers to
> either have to support only one possible IRQ resource, or to have code
> in place to try both as a failsafe.
>
> While there is a possibility of ambiguity for devices that exposes
> multiple IRQs, it is easy and feasible to support the common case
> of devices that only expose one IRQ which would be of either type
> depending on the underlying system's architecture.
>
> This commit adds support for parsing a GpioInt resource in order
> to fulfill a request for the index 0 IRQ for a platform device.
>
> Signed-off-by: Enrico Granata <[email protected]>

Reviewed-by: Rafael J. Wysocki <[email protected]>

> ---
> Changes in v2:
> - only support IRQ index 0
>
> drivers/base/platform.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 1c958eb33ef4d..0d3611cd1b3bc 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -127,7 +127,20 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
> irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
> }
>
> - return r ? r->start : -ENXIO;
> + if (r)
> + return r->start;
> +
> + /*
> + * For the index 0 interrupt, allow falling back to GpioInt
> + * resources. While a device could have both Interrupt and GpioInt
> + * resources, making this fallback ambiguous, in many common cases
> + * the device will only expose one IRQ, and this fallback
> + * allows a common code path across either kind of resource.
> + */
> + if (num == 0 && has_acpi_companion(&dev->dev))
> + return acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
> +
> + return -ENXIO;
> #endif
> }
> EXPORT_SYMBOL_GPL(platform_get_irq);
> --
> 2.20.1.791.gb4d0f1c61a-goog
>