linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Mundt <lethal@linux-sh.org>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org,
	Paul Mundt <lethal@linux-sh.org>
Subject: [PATCH 1/2] irqdomain: Fix up linear revmap for non-zero hwirq displacement.
Date: Wed, 13 Jun 2012 07:34:00 +0000	[thread overview]
Message-ID: <1339572841-26175-1-git-send-email-lethal@linux-sh.org> (raw)

Presently the linear revmap code assumes that all hwirqs start at 0,
using the hwirq directly as an index value for the lookup. In the case of
legacy revmaps this isn't necessarily the case, as the first_hwirq value
passed in can be non-zero, causing those types of users to silently have
their IRQs placed in the radix tree instead.

With this change, hwirq displacement is factored in at association time
directly. This also makes it possible for non-legacy users to use linear
revmaps regardless of hwirq base position. This could potentially lead to
a bug if there's an attempt to associate multiple times in to the linear
map in a nonsensical and non-linear order, but at that point being
silently punted to the radix tree is likely to be the least of your
concerns (in such a case it's fairly trivial to simply extend
irq_domain_add_linear() to take a hwirq base and move the linear base
assignment there).

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
---
 include/linux/irqdomain.h |    1 +
 kernel/irq/irqdomain.c    |   18 +++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index 775765d..58defd5 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -97,6 +97,7 @@ struct irq_domain {
 	/* Reverse mapping data */
 	unsigned int nomap_max_irq;
 	struct radix_tree_root radix_tree;
+	unsigned int linear_start;
 	unsigned int linear_size;
 	unsigned int linear_revmap[];
 };
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 906307b..8591cb6 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -55,6 +55,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->linear_start = 0;
 	domain->linear_size = size;
 
 	return domain;
@@ -268,8 +269,8 @@ static void irq_domain_disassociate_many(struct irq_domain *domain,
 		irq_data->hwirq = 0;
 
 		/* Clear reverse map */
-		if (hwirq < domain->linear_size)
-			domain->linear_revmap[hwirq] = 0;
+		if (hwirq - domain->linear_start < domain->linear_size)
+			domain->linear_revmap[hwirq - domain->linear_start] = 0;
 		else {
 			mutex_lock(&revmap_trees_mutex);
 			radix_tree_delete(&domain->radix_tree, hwirq);
@@ -288,6 +289,13 @@ int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
 	pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
 		of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
 
+	/*
+	 * The linear revmap may not begin at 0, factor in the hwirq
+	 * displacement here.
+	 */
+	if (domain->linear_size)
+		domain->linear_start = hwirq_base;
+
 	for (i = 0; i < count; i++) {
 		struct irq_data *irq_data = irq_get_irq_data(virq + i);
 
@@ -311,8 +319,8 @@ int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
 			goto err_unmap;
 		}
 
-		if (hwirq < domain->linear_size)
-			domain->linear_revmap[hwirq] = virq;
+		if (hwirq - domain->linear_start < domain->linear_size)
+			domain->linear_revmap[hwirq - domain->linear_start] = virq;
 		else {
 			mutex_lock(&revmap_trees_mutex);
 			radix_tree_insert(&domain->radix_tree, hwirq, irq_data);
@@ -585,7 +593,7 @@ unsigned int irq_linear_revmap(struct irq_domain *domain,
 	BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
 
 	/* Check revmap bounds; complain if exceeded */
-	if (hwirq >= domain->linear_size) {
+	if (hwirq - domain->linear_start >= domain->linear_size) {
 		rcu_read_lock();
 		data = radix_tree_lookup(&domain->radix_tree, hwirq);
 		rcu_read_unlock();
-- 
1.7.9.rc0.28.g0e1cf


             reply	other threads:[~2012-06-13  7:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-13  7:34 Paul Mundt [this message]
2012-06-13  7:34 ` [PATCH 2/2] irqdomain: Support one-shot tear down of domain mappings Paul Mundt
2012-06-15 18:35   ` Grant Likely
2012-06-15 22:34     ` Paul Mundt
2012-06-17 23:48       ` Grant Likely
2012-06-15 18:25 ` [PATCH 1/2] irqdomain: Fix up linear revmap for non-zero hwirq displacement Grant Likely
2012-06-15 23:14   ` Paul Mundt
2012-06-21  1:19     ` Paul Mundt
2012-07-11 15:22       ` 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=1339572841-26175-1-git-send-email-lethal@linux-sh.org \
    --to=lethal@linux-sh.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.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).