[PATCH 02/25] ACPI: irq: Add IRQ affinity reporting interface

Marc Zyngier posted 25 patches 1 day, 9 hours ago
[PATCH 02/25] ACPI: irq: Add IRQ affinity reporting interface
Posted by Marc Zyngier 1 day, 9 hours ago
Plug the irq_populate_fwspec_info() helper into the ACPI layer
to offer an IRQ affinity reporting function. This is currently
only supported for the CONFIG_ACPI_GENERIC_GSI configurations,
but could later be extended to legacy architectures if necessary.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/acpi/irq.c   | 15 +++++++++++++++
 include/linux/acpi.h |  7 +++++++
 2 files changed, 22 insertions(+)

diff --git a/drivers/acpi/irq.c b/drivers/acpi/irq.c
index 76a856c32c4d0..22f93fe23ddce 100644
--- a/drivers/acpi/irq.c
+++ b/drivers/acpi/irq.c
@@ -300,6 +300,21 @@ int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res)
 }
 EXPORT_SYMBOL_GPL(acpi_irq_get);
 
+const struct cpumask *acpi_irq_get_affinity(acpi_handle handle,
+					    unsigned int index)
+{
+	struct irq_fwspec_info info;
+	unsigned long flags;
+
+	if (!acpi_irq_parse_one(handle, index, &info.fwspec, &flags)) {
+		if (!irq_populate_fwspec_info(&info) &&
+		    info.flags & IRQ_FWSPEC_INFO_AFFINITY_VALID)
+			return info.affinity;
+	}
+
+	return NULL;
+}
+
 /**
  * acpi_set_irq_model - Setup the GSI irqdomain information
  * @model: the value assigned to acpi_irq_model
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 1c5bb1e887cd1..c506ae4bacc86 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1509,12 +1509,19 @@ static inline int acpi_parse_spcr(bool enable_earlycon, bool enable_console)
 
 #if IS_ENABLED(CONFIG_ACPI_GENERIC_GSI)
 int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res);
+const struct cpumask *acpi_irq_get_affinity(acpi_handle handle,
+					    unsigned int index);
 #else
 static inline
 int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res)
 {
 	return -EINVAL;
 }
+static inline const struct cpumask *acpi_irq_get_affinity(acpi_handle handle,
+							  unsigned int index)
+{
+	return NULL;
+}
 #endif
 
 #ifdef CONFIG_ACPI_LPIT
-- 
2.39.2
Re: [PATCH 02/25] ACPI: irq: Add IRQ affinity reporting interface
Posted by Rafael J. Wysocki 1 day, 8 hours ago
On Mon, Sep 8, 2025 at 6:31 PM Marc Zyngier <maz@kernel.org> wrote:
>
> Plug the irq_populate_fwspec_info() helper into the ACPI layer
> to offer an IRQ affinity reporting function. This is currently
> only supported for the CONFIG_ACPI_GENERIC_GSI configurations,
> but could later be extended to legacy architectures if necessary.
>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  drivers/acpi/irq.c   | 15 +++++++++++++++
>  include/linux/acpi.h |  7 +++++++
>  2 files changed, 22 insertions(+)
>
> diff --git a/drivers/acpi/irq.c b/drivers/acpi/irq.c
> index 76a856c32c4d0..22f93fe23ddce 100644
> --- a/drivers/acpi/irq.c
> +++ b/drivers/acpi/irq.c
> @@ -300,6 +300,21 @@ int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res)
>  }
>  EXPORT_SYMBOL_GPL(acpi_irq_get);
>
> +const struct cpumask *acpi_irq_get_affinity(acpi_handle handle,
> +                                           unsigned int index)
> +{
> +       struct irq_fwspec_info info;
> +       unsigned long flags;
> +
> +       if (!acpi_irq_parse_one(handle, index, &info.fwspec, &flags)) {
> +               if (!irq_populate_fwspec_info(&info) &&
> +                   info.flags & IRQ_FWSPEC_INFO_AFFINITY_VALID)
> +                       return info.affinity;
> +       }

I would prefer fewer logical negations to be used in this, for instance:

if (acpi_irq_parse_one(handle, index, &info.fwspec, &flags))
      return NULL;

if (irq_populate_fwspec_info(&info))
       return NULL;

if (info.flags & IRQ_FWSPEC_INFO_AFFINITY_VALID)
       return info.affinity;

return NULL;

> +
> +       return NULL;
> +}
> +
>  /**
>   * acpi_set_irq_model - Setup the GSI irqdomain information
>   * @model: the value assigned to acpi_irq_model
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 1c5bb1e887cd1..c506ae4bacc86 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -1509,12 +1509,19 @@ static inline int acpi_parse_spcr(bool enable_earlycon, bool enable_console)
>
>  #if IS_ENABLED(CONFIG_ACPI_GENERIC_GSI)
>  int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res);
> +const struct cpumask *acpi_irq_get_affinity(acpi_handle handle,
> +                                           unsigned int index);
>  #else
>  static inline
>  int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res)
>  {
>         return -EINVAL;
>  }
> +static inline const struct cpumask *acpi_irq_get_affinity(acpi_handle handle,
> +                                                         unsigned int index)
> +{
> +       return NULL;
> +}
>  #endif
>
>  #ifdef CONFIG_ACPI_LPIT
> --