From: Grant Likely <grant.likely@secretlab.ca>
To: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Cc: Rob Herring <rob.herring@calxeda.com>
Subject: [RFC 1/2] irq_domain: Create common xlate functions that device drivers can use
Date: Tue, 24 Jan 2012 17:18:38 -0700 [thread overview]
Message-ID: <1327450719-25590-1-git-send-email-grant.likely@secretlab.ca> (raw)
Rather than having each interrupt controller driver creating its own barely
unique .xlate function for irq_domain, create a library of translators which
any driver can use directly.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
This builds on top of my irq_domain series and will be included with it when
I post v3. Rob, does this serve your needs for generic irq controller DT
support?
g.
include/linux/irqdomain.h | 15 ++++++++++
kernel/irq/irqdomain.c | 69 +++++++++++++++++++++++++++++++++++++++-----
2 files changed, 76 insertions(+), 8 deletions(-)
diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index e7379a3..5e497a0 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -110,6 +110,9 @@ struct irq_domain {
void *host_data;
irq_hw_number_t inval_irq;
+ /* Data for common irq xlate functions */
+ unsigned int xlate_type;
+
/* Optional device node pointer */
struct device_node *of_node;
};
@@ -163,6 +166,18 @@ extern unsigned int irq_linear_revmap(struct irq_domain *host,
irq_hw_number_t hwirq);
extern struct irq_domain_ops irq_domain_simple_ops;
+
+/* stock xlate functions */
+int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ irq_hw_number_t *out_hwirq, unsigned int *out_type);
+int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ irq_hw_number_t *out_hwirq, unsigned int *out_type);
+int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ irq_hw_number_t *out_hwirq, unsigned int *out_type);
+
#if defined(CONFIG_OF_IRQ)
extern void irq_domain_generate_simple(const struct of_device_id *match,
u64 phys_base, unsigned int irq_start);
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index def8e7b..df80205 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -53,6 +53,7 @@ static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
domain->ops = ops;
domain->host_data = host_data;
domain->of_node = of_node_get(of_node);
+ domain->xlate_type = IRQ_TYPE_NONE;
if (domain->ops->match == NULL)
domain->ops->match = default_irq_domain_match;
@@ -690,25 +691,77 @@ int irq_domain_simple_map(struct irq_domain *d, unsigned int irq,
return 0;
}
-int irq_domain_simple_xlate(struct irq_domain *d,
- struct device_node *controller,
- const u32 *intspec, unsigned int intsize,
- unsigned long *out_hwirq, unsigned int *out_type)
+/**
+ * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
+ *
+ * Device Tree IRQ specifier translation function which works with one cell
+ * bindings where the cell value maps directly to the hwirq number.
+ */
+int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ unsigned long *out_hwirq, unsigned int *out_type)
+{
+ if (WARN(intsize < 1, "Bad intspec for %s: intsize=%i < 1\n",
+ ctrlr->full_name, intsize))
+ return -EINVAL;
+ *out_hwirq = intspec[0];
+ *out_type = d->xlate_type;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
+
+/**
+ * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
+ *
+ * Device Tree IRQ specifier translation function which works with two cell
+ * bindings where the cell values map directly to the hwirq number
+ * and linux irq flags.
+ */
+int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ irq_hw_number_t *out_hwirq, unsigned int *out_type)
{
- if (d->of_node != controller)
+ if (WARN(intsize < 2, "Bad intspec for %s: intsize=%i < 2\n",
+ ctrlr->full_name, intsize))
+ return -EINVAL;
+ if (intsize < 2)
return -EINVAL;
- if (intsize < 1)
+ *out_hwirq = intspec[0];
+ *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
+
+/**
+ * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
+ *
+ * Device Tree IRQ specifier translation function which works with either one
+ * or two cell bindings where the cell values map directly to the hwirq number
+ * and linux irq flags.
+ *
+ * Note: don't use this function unless your interrupt controller explicitly
+ * supports both one and two cell bindings. For the majority of controllers
+ * the _onecell() or _twocell() variants above should be used.
+ */
+int irq_domain_xlate_onetwocell(struct irq_domain *d,
+ struct device_node *ctrlr,
+ const u32 *intspec, unsigned int intsize,
+ unsigned long *out_hwirq, unsigned int *out_type)
+{
+ if (WARN(intsize < 1, "Bad intspec for %s: intsize=%i < 1\n",
+ ctrlr->full_name, intsize))
return -EINVAL;
*out_hwirq = intspec[0];
- *out_type = IRQ_TYPE_NONE;
+ *out_type = d->xlate_type;
if (intsize > 1)
*out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
return 0;
}
+EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
struct irq_domain_ops irq_domain_simple_ops = {
.map = irq_domain_simple_map,
- .xlate = irq_domain_simple_xlate,
+ .xlate = irq_domain_xlate_onetwocell,
};
EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
--
1.7.5.4
next reply other threads:[~2012-01-25 0:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-25 0:18 Grant Likely [this message]
2012-01-25 0:18 ` [RFC 2/2] irqdomain/powerpc: Replace custom xlate functions with library functions Grant Likely
2012-01-25 1:50 ` [RFC 1/2] irq_domain: Create common xlate functions that device drivers can use Rob Herring
2012-01-25 5:35 ` Grant Likely
2012-01-25 17:59 ` Grant Likely
2012-01-26 14:50 ` Rob Herring
2012-01-26 18:15 ` Grant Likely
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=1327450719-25590-1-git-send-email-grant.likely@secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=rob.herring@calxeda.com \
/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).