linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Agustin Vega-Frias <agustinv@codeaurora.org>
To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, rjw@rjwysocki.net,
	lenb@kernel.org, tglx@linutronix.de, jason@lakedaemon.net,
	marc.zyngier@arm.com
Cc: timur@codeaurora.org, cov@codeaurora.org, agross@codeaurora.org,
	harba@codeaurora.org, jcm@redhat.com, msalter@redhat.com,
	mlangsdo@redhat.com, ahs3@redhat.com, astone@redhat.com,
	graeme.gregory@linaro.org, guohanjun@huawei.com,
	charles.garcia-tobin@arm.com,
	Agustin Vega-Frias <agustinv@codeaurora.org>
Subject: [PATCH V7 1/3] ACPI: Retry IRQ conversion if it failed previously
Date: Sun, 13 Nov 2016 16:59:33 -0500	[thread overview]
Message-ID: <1479074375-2629-2-git-send-email-agustinv@codeaurora.org> (raw)
In-Reply-To: <1479074375-2629-1-git-send-email-agustinv@codeaurora.org>

This allows probe deferral to work properly when a dependent device
fails to get a valid IRQ because the IRQ domain was not registered
at the time the resources were added to the platform_device.

Signed-off-by: Agustin Vega-Frias <agustinv@codeaurora.org>
---
 drivers/acpi/resource.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/base/platform.c |  9 +++++++-
 include/linux/acpi.h    |  7 ++++++
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 56241eb..4beda15 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -664,3 +664,62 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
 	return (type & types) ? 0 : 1;
 }
 EXPORT_SYMBOL_GPL(acpi_dev_filter_resource_type);
+
+struct acpi_irq_get_ctx {
+	unsigned int index;
+	struct resource *res;
+};
+
+static acpi_status acpi_irq_get_cb(struct acpi_resource *ares, void *context)
+{
+	struct acpi_irq_get_ctx *ctx = context;
+	struct acpi_resource_irq *irq;
+	struct acpi_resource_extended_irq *ext_irq;
+
+	switch (ares->type) {
+	case ACPI_RESOURCE_TYPE_IRQ:
+		irq = &ares->data.irq;
+		if (ctx->index < irq->interrupt_count) {
+			acpi_dev_resource_interrupt(ares, ctx->index, ctx->res);
+			return AE_CTRL_TERMINATE;
+		}
+		ctx->index -= irq->interrupt_count;
+		break;
+	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
+		ext_irq = &ares->data.extended_irq;
+		if (ctx->index < ext_irq->interrupt_count) {
+			acpi_dev_resource_interrupt(ares, ctx->index, ctx->res);
+			return AE_CTRL_TERMINATE;
+		}
+		ctx->index -= ext_irq->interrupt_count;
+		break;
+	}
+
+	return AE_OK;
+}
+
+/**
+ * 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
+ *
+ * Return: 0 on success
+ *         -EINVAL if an error occurs
+ *         -EPROBE_DEFER if the IRQ lookup/conversion failed
+ */
+int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res)
+{
+	struct acpi_irq_get_ctx ctx = { index, res };
+	acpi_status status;
+
+	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
+				     acpi_irq_get_cb, &ctx);
+	if (ACPI_FAILURE(status))
+		return -EINVAL;
+	if (res->flags & IORESOURCE_DISABLED)
+		return -EPROBE_DEFER;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(acpi_irq_get);
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index c4af003..61423d2 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -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));
 	}
 }
-
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 689a8b9..325bdb9 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -406,6 +406,7 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares,
 unsigned int acpi_dev_get_irq_type(int triggering, int polarity);
 bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,
 				 struct resource *res);
+int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res);
 
 void acpi_dev_free_resource_list(struct list_head *list);
 int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
@@ -763,6 +764,12 @@ static inline int acpi_reconfig_notifier_unregister(struct notifier_block *nb)
 	return -EINVAL;
 }
 
+static inline int acpi_irq_get(acpi_handle handle, unsigned int index,
+			       struct resource *res)
+{
+	return -EINVAL;
+}
+
 #endif	/* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
-- 
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.

  reply	other threads:[~2016-11-13 21:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-13 21:59 [PATCH V7 0/3] irqchip: qcom: Add IRQ combiner driver Agustin Vega-Frias
2016-11-13 21:59 ` Agustin Vega-Frias [this message]
2016-11-15 15:48   ` [PATCH V7 1/3] ACPI: Retry IRQ conversion if it failed previously Lorenzo Pieralisi
2016-11-15 17:43     ` Agustin Vega-Frias
2016-11-16 17:18       ` Lorenzo Pieralisi
2016-11-16 18:29         ` Agustin Vega-Frias
2016-11-28 10:52   ` majun (Euler7)
2016-11-13 21:59 ` [PATCH V7 2/3] ACPI: Add support for ResourceSource/IRQ domain mapping Agustin Vega-Frias
2016-11-24 16:15   ` Lorenzo Pieralisi
2016-11-25 11:40     ` Lorenzo Pieralisi
2016-11-28 22:40       ` Agustin Vega-Frias
2016-11-29 12:11         ` Lorenzo Pieralisi
2016-11-29 12:43           ` Rafael J. Wysocki
2016-11-29 15:20             ` Agustin Vega-Frias
2016-11-29 16:26               ` Rafael J. Wysocki
2016-11-30  2:07                 ` Hanjun Guo
2016-11-29 15:18           ` Agustin Vega-Frias
2016-11-13 21:59 ` [PATCH V7 3/3] irqchip: qcom: Add IRQ combiner driver Agustin Vega-Frias
2016-11-29 11:31 ` [PATCH V7 0/3] " Hanjun Guo
2016-11-29 15:14   ` Agustin Vega-Frias

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479074375-2629-2-git-send-email-agustinv@codeaurora.org \
    --to=agustinv@codeaurora.org \
    --cc=agross@codeaurora.org \
    --cc=ahs3@redhat.com \
    --cc=astone@redhat.com \
    --cc=charles.garcia-tobin@arm.com \
    --cc=cov@codeaurora.org \
    --cc=graeme.gregory@linaro.org \
    --cc=guohanjun@huawei.com \
    --cc=harba@codeaurora.org \
    --cc=jason@lakedaemon.net \
    --cc=jcm@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mlangsdo@redhat.com \
    --cc=msalter@redhat.com \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=timur@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).