ACPI: Add support for ResourceSource/IRQ domain mapping
Subsystems (2)
ACPI extended IRQ resources may contain a ResourceSource to specify an alternate interrupt controller. Introduce acpi_irq_get and use it to implement ResourceSource/IRQ domain mapping.
The new API is similar to of_irq_get and allows re-initialization of a platform resource from the ACPI extended IRQ resource, and provides proper behavior for probe deferral when the domain is not yet present when called.
---
drivers/acpi/Makefile | 2 +-
drivers/acpi/{gsi.c => irq.c} | 184 ++++++++++++++++++++++++++++++++++++++++++
drivers/base/platform.c | 9 ++-
include/linux/acpi.h | 10 +++
4 files changed, 203 insertions(+), 2 deletions(-)
rename drivers/acpi/{gsi.c => irq.c} (32%)drivers/acpi/Makefile +1 -1
@@ -55,7 +55,7 @@ acpi-$(CONFIG_DEBUG_FS) += debugfs.o acpi-$(CONFIG_ACPI_NUMA) += numa.o acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o acpi-y += acpi_lpat.o -acpi-$(CONFIG_ACPI_GENERIC_GSI) += gsi.o +acpi-$(CONFIG_ACPI_GENERIC_GSI) += irq.o acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o # These are (potentially) separate modules
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +184 -0
190 lines not on this page · raw message
drivers/base/platform.c +8 -1
@@ -102,6 +102,14 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) } r =platform_get_resource (dev,IORESOURCE_IRQ , num); +if (r && r->flags &IORESOURCE_DISABLED &&ACPI_COMPANION (&dev->dev)) { +int ret; + + ret =acpi_irq_get (ACPI_HANDLE (&dev->dev), num, r); +if (ret) +return ret; + } +/* * The resources may pass trigger flags to the irqs that need * to be set up. It so happens that the trigger flags for
@@ -1450,4 +1458,3 @@ void __init early_platform_cleanup(void)memset (&pd->dev.devres_head,0 ,sizeof (pd->dev.devres_head)); } } -
include/linux/acpi.h +10 -0
@@ -1153,4 +1153,14 @@ static inline void acpi_table_upgrade(void) { }static inline int parse_spcr (bool earlycon) {return 0 ; }#endif +#ifdef CONFIG_ACPI_GENERIC_GSI +int acpi_irq_get (acpi_handle handle,unsigned int index,struct resource *res); +#else +static inline int acpi_irq_get (acpi_handle handle,unsigned int index, +struct resource *res) +{ +return -EINVAL ; +} +#endif +#endif /*_LINUX_ACPI_H*/
--
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 8 lines · Agustin Vega-Frias
ACPI extended IRQ resources may contain a ResourceSource to specify an alternate interrupt controller. Introduce
acpi_irq_getand use it to implement ResourceSource/IRQ domain mapping.The new API is similar to
of_irq_getand allows re-initialization of a platform resource from the ACPI extended IRQ resource, and provides proper behavior for probe deferral when the domain is not yet present when called.
Thanks, looks better now.
Quoted 4 lines
/**
+ *acpi_get_irq_source_fwhandle()- Retrieve the fwhandle of the given
+ *acpi_resource_sourcewhich is used
+ * as an IRQ domain id
Please, make short description here and put long one below
Quoted 2 lines
+ * @source:
acpi_resource_sourceto use for the lookup
+ *
* Description:
* ...
*
Quoted 2 lines
+ * Returns: The appropriate IRQ fwhandle domain id
+ * NULL on failure
* Return:
* blablabla
Quoted 12 lines
+ */
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +11
-0+static struct fwnode_handle * +acpi_get_irq_source_fwhandle (const struct acpi_resource_source *source) +{ +struct fwnode_handle *result; +struct acpi_device *device; +acpi_handle handle; +acpi_status status; + +if (!source->string_length) +return acpi_gsi_domain_id; +
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 115
Quoted 10 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +9
-0+ status =acpi_get_handle (NULL , source->string_ptr, &handle); +if (ACPI_FAILURE (status)) { +pr_warn ("Could not find handle for %s\n" , source->string_ptr); +return NULL ; + } + + device =acpi_bus_get_acpi_device (handle); +if (!device) { +pr_warn ("Could not get device for %s\n" , source->string_ptr);
I'm not sure both messages have a value.
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 125
Quoted 4 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +3
-0+return NULL ; + } +/**
You mark as kernel doc, but in fact it's just a comment.
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 136
Quoted 11 lines
+ * Context for the resource walk used to lookup IRQ resources.
+ */drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +9
-0+struct acpi_irq_parse_one_ctx { +int rc; +unsigned int index; +unsigned long *res_flags; +struct irq_fwspec *fwspec; +}; + +/** +* acpi_irq_parse_one_match - Handle a matching IRQ resource
This looks better, but lacks of parameter descriptions.
Quoted 8 lines
+ */
+/**
+ *acpi_irq_parse_one_cb- Handle the given resource
+ * @ares: resource to handle+ * @context: context for the walk, contains the lookup index and references
+ * to the flags and fwspec where the result is returned
Make it shorter, ideally into one line
Quoted 1 line
+ *
* Description:
Quoted 9 lines
+ * This is called by
acpi_walk_resourcespassing each resource returned by
+ * the_CRSmethod. We only inspect IRQ resources. Since IRQ resources
+ * might contain multiple interrupts we check if the index is within this
+ * one's interrupt array, otherwise we subtract the current resource IRQ
+ * count from the lookup index to prepare for the next resource.
+ * Once a match is found we callacpi_irq_parse_one_matchto populate
+ * the result and end the walk by returningAE_CTRL_TERMINATE.
+ *
+ * ReturnAE_OKif the walk should continue,AE_CTRL_TERMINATEif a matching
* Return:
* blablabla
Quoted 16 lines
+ * IRQ resource was found.
+ */+/**
+ *acpi_irq_parse_one- Resolve an interrupt for a device
+ * @handle: the device whose interrupt is to be resolved
+ * @index: index of the interrupt to resolve
+ * @fwspec: structureirq_fwspecfilled by this function
+ * @flags: resource flags filled by this function
+ *
+ * This function resolves an interrupt for a device by walking its CRS resources
+ * to find the appropriate ACPI IRQ resource and populating the given structure
+ * which can be used to retrieve a Linux IRQ number.
+ *
+ * Returns the result stored in ctx.rc by the callback, or-EINVALif the given
+ * index is out of range.
Ditto for Description and Return.
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 229
Quoted 12 lines
+ */
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +10
-0+static int acpi_irq_parse_one (acpi_handle handle,unsigned int index, +struct irq_fwspec *fwspec,unsigned long *flags) +{ +struct acpi_irq_parse_one_ctx ctx = { -EINVAL , index, flags, fwspec }; +acpi_status status; + + status =acpi_walk_resources (handle,METHOD_NAME__CRS , + acpi_irq_parse_one_cb, &ctx); +if (ACPI_FAILURE (status)) +return -EINVAL ;
Shouldn't you have the same in rc? Would be redundant.
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 238
Quoted 9 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +9
-0+return ctx.rc; +} + +/** +* acpi_irq_get - Look for the ACPI IRQ resource with the given index and +* use it to initialize the given Linux IRQ resource. +* @handle ACPI device handle +* @index ACPI IRQ resource index to lookup +* @res Linux IRQ resource to initialize
Ah, you missed colons after field names:
* @field1:
Quoted 2 lines
+ *
+ * Return:
Next line: 0 on success
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 246
Quoted 7 lines
+ *
-EINVALif an error occurs
+ * -EPROBE_DEFER if the IRQ lookup/conversion failed
+ */drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +3
-0+int acpi_irq_get (acpi_handle handle,unsigned int index,struct resource *res) +{ +int rc;
Put this last in the definition block.
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 257
Quoted 11 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +11
-0+struct irq_fwspec fwspec; +struct irq_domain *domain; +unsigned long flags; + + rc =acpi_irq_parse_one (handle, index, &fwspec, &flags); +if (rc) +return rc; + + domain =irq_find_matching_fwnode (fwspec.fwnode,DOMAIN_BUS_ANY ); +if (!domain) +return -EPROBE_DEFER ;
Hmm... Could it be other issues here?
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 265
Quoted 9 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +8
-0+ + rc =irq_create_fwspec_mapping (&fwspec); +if (rc <=0 ) +return -EINVAL ; + + res->start = rc; + res->end = rc; + res->flags = flags;
Perhaps struct resource *r should be a parameter to acpi_irq_parse_one().
Quoted 14 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +6
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_irq_get); + +/** * acpi_set_irq_model - Setup the GSI irqdomain information * @model: the value assigned to acpi_irq_model * @fwnode: the irq_domain identifier for mapping and looking up drivers/base/platform.c +0
-0
drivers/base/platform.c int platform_get_irq(struct platform_device *dev, unsigned int num) · line 105
Quoted 4 lines
drivers/base/platform.c +1
-0@@ -102,6 +102,14 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) } r =platform_get_resource (dev,IORESOURCE_IRQ , num); +if (r && r->flags &IORESOURCE_DISABLED &&ACPI_COMPANION (&dev->dev)) {
has_acpi_companion() ?
drivers/base/platform.c void __init early_platform_cleanup(void) · line 1453
Quoted 12 lines
drivers/base/platform.c +6
-1+int ret; + + ret =acpi_irq_get (ACPI_HANDLE (&dev->dev), num, r); +if (ret) +return ret; + }@@ -1450,4 +1458,3 @@ void __init early_platform_cleanup(void)memset (&pd->dev.devres_head,0 ,sizeof (pd->dev.devres_head)); } } -
It doesn't belong here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
On Wed, Jan 18, 2017 at 09:45:56PM +0200, Andy Shevchenko wrote:
[...]
Quoted 25 lines
Quoted 6 lines
+/**
+ *acpi_irq_get- Look for the ACPI IRQ resource with the given index and
+ * use it to initialize the given Linux IRQ resource.
+ * @handle ACPI device handle
+ * @index ACPI IRQ resource index to lookup
+ * @res Linux IRQ resource to initializeAh, you missed colons after field names:
* @field1:Quoted 2 lines
+ *
+ * Return:Next line: 0 on success
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 246
Quoted 7 lines
+ *
-EINVALif an error occurs
+ * -EPROBE_DEFER if the IRQ lookup/conversion failed
+ */drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +3
-0+int acpi_irq_get (acpi_handle handle,unsigned int index,struct resource *res) +{ +int rc;Put this last in the definition block.
Quoted 13 lines
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 257
Quoted 11 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +11
-0+struct irq_fwspec fwspec; +struct irq_domain *domain; +unsigned long flags; + + rc =acpi_irq_parse_one (handle, index, &fwspec, &flags); +if (rc) +return rc; + + domain =irq_find_matching_fwnode (fwspec.fwnode,DOMAIN_BUS_ANY ); +if (!domain) +return -EPROBE_DEFER ;Hmm... Could it be other issues here?
That's a good point. Here probing should be deferred only if we know a driver capable of handling fwspec.fwnode will have a chance to be probed/initialized eventually right (which basically means it is compiled in the kernel and we hope it will probed successfully) ? I am not sure there is an easy way to detect that in ACPI at the moment, I suspect it is time we added a linker section (or augment the existing one used for irqchip early MADT parsing - IRQCHIP_ACPI_DECLARE) for this purpose I do not see any other option (apart from leaving devices in the deferred probe list if a driver for the irqchip represented by fwspec.fwnode is not present in the kernel, which is a bit sloppy, or resorting to checking Kconfig entries to detect compile time enabled irqchip drivers).
Quoted 11 lines
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 265
Quoted 9 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +8
-0+ + rc =irq_create_fwspec_mapping (&fwspec); +if (rc <=0 ) +return -EINVAL ; + + res->start = rc; + res->end = rc; + res->flags = flags;Perhaps struct resource *r should be a parameter to
acpi_irq_parse_one().
Yeah but then you would end up with flags initialized in acpi_irq_parse_one() and the other resource params (ie start, end) here, I do not think it is nicer.
Thanks,
Lorenzo
Quoted 40 lines
Quoted 15 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +6
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_irq_get); + +/** * acpi_set_irq_model - Setup the GSI irqdomain information * @model: the value assigned to acpi_irq_model * @fwnode: the irq_domain identifier for mapping and looking up drivers/base/platform.c +0
-0drivers/base/platform.c int platform_get_irq(struct platform_device *dev, unsigned int num) · line 105
Quoted 4 lines
drivers/base/platform.c +1
-0@@ -102,6 +102,14 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) } r =platform_get_resource (dev,IORESOURCE_IRQ , num); +if (r && r->flags &IORESOURCE_DISABLED &&ACPI_COMPANION (&dev->dev)) {
has_acpi_companion()?drivers/base/platform.c void __init early_platform_cleanup(void) · line 1453
Quoted 12 lines
drivers/base/platform.c +6
-1+int ret; + + ret =acpi_irq_get (ACPI_HANDLE (&dev->dev), num, r); +if (ret) +return ret; + }@@ -1450,4 +1458,3 @@ void __init early_platform_cleanup(void)memset (&pd->dev.devres_head,0 ,sizeof (pd->dev.devres_head)); } } -It doesn't belong here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 43 lines · Lorenzo Pieralisi
On Wed, Jan 18, 2017 at 09:45:56PM +0200, Andy Shevchenko wrote:
[...]
Quoted 25 lines
Quoted 6 lines
+/**
+ *acpi_irq_get- Look for the ACPI IRQ resource with the given index and
+ * use it to initialize the given Linux IRQ resource.
+ * @handle ACPI device handle
+ * @index ACPI IRQ resource index to lookup
+ * @res Linux IRQ resource to initializeAh, you missed colons after field names:
* @field1:Quoted 2 lines
+ *
+ * Return:Next line: 0 on success
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 246
Quoted 7 lines
+ *
-EINVALif an error occurs
+ * -EPROBE_DEFER if the IRQ lookup/conversion failed
+ */drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +3
-0+int acpi_irq_get (acpi_handle handle,unsigned int index,struct resource *res) +{ +int rc;Put this last in the definition block.
Quoted 13 lines
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 257
Quoted 11 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +11
-0+struct irq_fwspec fwspec; +struct irq_domain *domain; +unsigned long flags; + + rc =acpi_irq_parse_one (handle, index, &fwspec, &flags); +if (rc) +return rc; + + domain =irq_find_matching_fwnode (fwspec.fwnode,DOMAIN_BUS_ANY ); +if (!domain) +return -EPROBE_DEFER ;Hmm... Could it be other issues here?
Quoted 12 lines
That's a good point. Here probing should be deferred only if we know a driver capable of handling fwspec.fwnode will have a chance to be probed/initialized eventually right (which basically means it is compiled in the kernel and we hope it will probed successfully) ? I am not sure there is an easy way to detect that in ACPI at the moment, I suspect it is time we added a linker section (or augment the existing one used for irqchip early MADT parsing -
IRQCHIP_ACPI_DECLARE) for this purpose I do not see any other option (apart from leaving devices in the deferred probe list if a driver for the irqchip represented by fwspec.fwnode is not present in the kernel, which is a bit sloppy, or resorting to checkingKconfigentries to detect compile time enabled irqchip drivers).
I'll add the linker section suggested by Lorenzo for the extra check. We can do that check in acpi_get_irq_source_fwhandle and make the lookup fail if the device is not listed in the table.
That way we can keep this check as-is.
Thoughts?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +8
-0+ + rc =irq_create_fwspec_mapping (&fwspec); +if (rc <=0 ) +return -EINVAL ; + + res->start = rc; + res->end = rc; + res->flags = flags;
Quoted 5 lines
Quoted 1 line
Perhaps struct resource *r should be a parameter to
acpi_irq_parse_one().Yeah but then you would end up with flags initialized in
acpi_irq_parse_one()and the other resource params (ie start, end) here, I do not think it is nicer.
The reason this took this form is that we are trying to get some symmetry with what of_irq_get does.
Thanks,
Agustin
Quoted 9 lines
Thanks,
Lorenzo[...]
Quoted 3 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Hi Andy,
Quoted 32 lines · Andy Shevchenko
On Wed, Jan 18, 2017 at 9:04 PM, Agustin Vega-Frias <[email protected]> wrote:
[...]
Quoted 24 lines
+ */
(quoted diff) +2
-0+static struct fwnode_handle * +acpi_get_irq_source_fwhandle(const struct acpi_resource_source*source)
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +12
-0+{ +struct fwnode_handle *result; +struct acpi_device *device; +acpi_handle handle; +acpi_status status; + +if (!source->string_length) +return acpi_gsi_domain_id; + + status =acpi_get_handle (NULL , source->string_ptr, &handle); +if (ACPI_FAILURE (status)) { + pr_warn("Could not find handle for %s\n",
source->string_ptr);drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +6
-0+return NULL ; + } + + device =acpi_bus_get_acpi_device (handle); +if (!device) { + pr_warn("Could not get device for %s\n",Quoted 1 line
source->string_ptr);
Quoted 1 line
I'm not sure both messages have a value.
I'll probably just drop the explicit pr_warns and just use WARN_ON on the if condition. Is that a reasonable alternative in your view?
Quoted 19 lines
Quoted 3 lines
(quoted diff) +2
-0+ return NULL; + }[...]
Quoted 11 lines
+ */
(quoted diff) +2
-0+static int acpi_irq_parse_one(acpi_handle handle, unsigned int index, + struct irq_fwspec *fwspec, unsigned long*flags)
(quoted diff) +2
-0+{ + struct acpi_irq_parse_one_ctx ctx = { -EINVAL, index, flags,fwspec };
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +4
-0+acpi_status status; + + status =acpi_walk_resources (handle,METHOD_NAME__CRS , + acpi_irq_parse_one_cb, &ctx);
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ACPI_FAILURE(status)) + return -EINVAL;Shouldn't you have the same in rc? Would be redundant.
Good point, since we always return -EINVAL on failure we can skip the check since rc will only be updated on success.
Quoted 6 lines
Quoted 3 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +3
-0+return ctx.rc; +} +[...]
Quoted 6 lines
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 257
Quoted 4 lines
+ domain = irq_find_matching_fwnode(fwspec.fwnode,
DOMAIN_BUS_ANY);drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +2
-0+if (!domain) +return -EPROBE_DEFER ;Hmm... Could it be other issues here?
I'll comment on this on Lorenzo's reply.
Quoted 7 lines
Quoted 6 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +5
-0+ + rc =irq_create_fwspec_mapping (&fwspec); +if (rc <=0 ) +return -EINVAL ; +
Quoted 6 lines
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 265
Quoted 3 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +3
-0+ res->start = rc; + res->end = rc; + res->flags = flags;Perhaps struct resource *r should be a parameter to
acpi_irq_parse_one().
I'll comment on this on Lorenzo's reply.
Quoted 10 lines
drivers/acpi/irq.c void acpi_unregister_gsi(u32 gsi) · line 274
Quoted 10 lines
drivers/acpi/irq.c renamed from drivers/acpi/gsi.c +6
-0+ +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_irq_get); + +/** * acpi_set_irq_model - Setup the GSI irqdomain information * @model: the value assigned to acpi_irq_model * @fwnode: the irq_domain identifier for mapping and looking up
I'll address the other issues on V11.
Thanks for your thorough review,
Agustin
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
Signature · 4 lines
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.