devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH v4] of/irq: introduce of_irq_init
Date: Tue, 27 Sep 2011 08:03:51 -0500	[thread overview]
Message-ID: <4E81C9B7.9000004@gmail.com> (raw)
In-Reply-To: <20110927015305.GD20588-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>

Grant,

On 09/26/2011 08:53 PM, Grant Likely wrote:
> On Mon, Sep 26, 2011 at 02:24:43PM -0500, Rob Herring wrote:
>> From: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
>>
>> of_irq_init will scan the devicetree for matching interrupt controller
>> nodes. Then it calls an initialization function for each found controller
>> in the proper order with parent nodes initialized before child nodes.
>>
>> Based on initial pseudo code from Grant Likely.
>>
>> Changes in v4:
>> - Drop unnecessary empty list check
>> - Be more verbose on errors
>> - Simplify "if (!desc) WARN_ON(1)" to "if (WARN_ON(!desc))"
>>
>> Changes in v3:
>> - add missing kfree's found by Jamie
>> - Implement Grant's comments to simplify the init loop
>> - fix function comments
>>
>> Changes in v2:
>> - Complete re-write of list searching code from Grant Likely
>>
>> Signed-off-by: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
>> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> 
> Looks good to me.  Merged.
> 

I'm dependent on this and things in rmk's tree for initial highbank
support, so should this series go in thru arm-soc tree? Several others
are dependent on this as well.

Rob

> g.
> 
>> ---
>>  drivers/of/irq.c       |  107 ++++++++++++++++++++++++++++++++++++++++++++++++
>>  include/linux/of_irq.h |    3 +
>>  2 files changed, 110 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
>> index 6a5b5e7..6d3dd39 100644
>> --- a/drivers/of/irq.c
>> +++ b/drivers/of/irq.c
>> @@ -19,10 +19,12 @@
>>   */
>>  
>>  #include <linux/errno.h>
>> +#include <linux/list.h>
>>  #include <linux/module.h>
>>  #include <linux/of.h>
>>  #include <linux/of_irq.h>
>>  #include <linux/string.h>
>> +#include <linux/slab.h>
>>  
>>  /* For archs that don't support NO_IRQ (such as x86), provide a dummy value */
>>  #ifndef NO_IRQ
>> @@ -386,3 +388,108 @@ int of_irq_to_resource_table(struct device_node *dev, struct resource *res,
>>  
>>  	return i;
>>  }
>> +
>> +struct intc_desc {
>> +	struct list_head	list;
>> +	struct device_node	*dev;
>> +	struct device_node	*interrupt_parent;
>> +};
>> +
>> +/**
>> + * of_irq_init - Scan and init matching interrupt controllers in DT
>> + * @matches: 0 terminated array of nodes to match and init function to call
>> + *
>> + * This function scans the device tree for matching interrupt controller nodes,
>> + * and calls their initialization functions in order with parents first.
>> + */
>> +void __init of_irq_init(const struct of_device_id *matches)
>> +{
>> +	struct device_node *np, *parent = NULL;
>> +	struct intc_desc *desc, *temp_desc;
>> +	struct list_head intc_desc_list, intc_parent_list;
>> +
>> +	INIT_LIST_HEAD(&intc_desc_list);
>> +	INIT_LIST_HEAD(&intc_parent_list);
>> +
>> +	for_each_matching_node(np, matches) {
>> +		if (!of_find_property(np, "interrupt-controller", NULL))
>> +			continue;
>> +		/*
>> +		 * Here, we allocate and populate an intc_desc with the node
>> +		 * pointer, interrupt-parent device_node etc.
>> +		 */
>> +		desc = kzalloc(sizeof(*desc), GFP_KERNEL);
>> +		if (WARN_ON(!desc))
>> +			goto err;
>> +
>> +		desc->dev = np;
>> +		desc->interrupt_parent = of_irq_find_parent(np);
>> +		list_add_tail(&desc->list, &intc_desc_list);
>> +	}
>> +
>> +	/*
>> +	 * The root irq controller is the one without an interrupt-parent.
>> +	 * That one goes first, followed by the controllers that reference it,
>> +	 * followed by the ones that reference the 2nd level controllers, etc.
>> +	 */
>> +	while (!list_empty(&intc_desc_list)) {
>> +		/*
>> +		 * Process all controllers with the current 'parent'.
>> +		 * First pass will be looking for NULL as the parent.
>> +		 * The assumption is that NULL parent means a root controller.
>> +		 */
>> +		list_for_each_entry_safe(desc, temp_desc, &intc_desc_list, list) {
>> +			const struct of_device_id *match;
>> +			int ret;
>> +			of_irq_init_cb_t irq_init_cb;
>> +
>> +			if (desc->interrupt_parent != parent)
>> +				continue;
>> +
>> +			list_del(&desc->list);
>> +			match = of_match_node(matches, desc->dev);
>> +			if (WARN(!match->data,
>> +			    "of_irq_init: no init function for %s\n",
>> +			    match->compatible)) {
>> +				kfree(desc);
>> +				continue;
>> +			}
>> +
>> +			pr_debug("of_irq_init: init %s @ %p, parent %p\n",
>> +				 match->compatible,
>> +				 desc->dev, desc->interrupt_parent);
>> +			irq_init_cb = match->data;
>> +			ret = irq_init_cb(desc->dev, desc->interrupt_parent);
>> +			if (ret) {
>> +				kfree(desc);
>> +				continue;
>> +			}
>> +
>> +			/*
>> +			 * This one is now set up; add it to the parent list so
>> +			 * its children can get processed in a subsequent pass.
>> +			 */
>> +			list_add_tail(&desc->list, &intc_parent_list);
>> +		}
>> +
>> +		/* Get the next pending parent that might have children */
>> +		desc = list_first_entry(&intc_parent_list, typeof(*desc), list);
>> +		if (list_empty(&intc_parent_list) || !desc) {
>> +			pr_err("of_irq_init: children remain, but no parents\n");
>> +			break;
>> +		}
>> +		list_del(&desc->list);
>> +		parent = desc->dev;
>> +		kfree(desc);
>> +	}
>> +
>> +	list_for_each_entry_safe(desc, temp_desc, &intc_parent_list, list) {
>> +		list_del(&desc->list);
>> +		kfree(desc);
>> +	}
>> +err:
>> +	list_for_each_entry_safe(desc, temp_desc, &intc_desc_list, list) {
>> +		list_del(&desc->list);
>> +		kfree(desc);
>> +	}
>> +}
>> diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
>> index cd2e61c..d0307ee 100644
>> --- a/include/linux/of_irq.h
>> +++ b/include/linux/of_irq.h
>> @@ -33,6 +33,8 @@ struct of_irq {
>>  	u32 specifier[OF_MAX_IRQ_SPEC]; /* Specifier copy */
>>  };
>>  
>> +typedef int (*of_irq_init_cb_t)(struct device_node *, struct device_node *);
>> +
>>  /*
>>   * Workarounds only applied to 32bit powermac machines
>>   */
>> @@ -73,6 +75,7 @@ extern int of_irq_to_resource_table(struct device_node *dev,
>>  		struct resource *res, int nr_irqs);
>>  extern struct device_node *of_irq_find_parent(struct device_node *child);
>>  
>> +extern void of_irq_init(const struct of_device_id *matches);
>>  
>>  #endif /* CONFIG_OF_IRQ */
>>  #endif /* CONFIG_OF */
>> -- 
>> 1.7.5.4
>>

  parent reply	other threads:[~2011-09-27 13:03 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20 20:24 [PATCH 0/3] GIC OF bindings Rob Herring
     [not found] ` <1316550244-3655-1-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-20 20:24   ` [PATCH 1/3] of/irq: of_irq_find_parent: check for parent equal to child Rob Herring
     [not found]     ` <1316550244-3655-2-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-20 21:01       ` Grant Likely
2011-09-20 20:24   ` [PATCH 2/3] of/irq: introduce of_irq_init Rob Herring
2011-09-20 23:00     ` Grant Likely
     [not found]     ` <1316550244-3655-3-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-21 10:01       ` Jamie Iles
2011-09-23  2:21       ` [PATCH v3] " Rob Herring
     [not found]         ` <1316744473-13158-1-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-23  5:14           ` Grant Likely
2011-09-26 19:24           ` [PATCH v4] " Rob Herring
     [not found]             ` <1317065083-23573-1-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-27  1:53               ` Grant Likely
     [not found]                 ` <20110927015305.GD20588-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2011-09-27 13:03                   ` Rob Herring [this message]
2011-09-27 21:24                     ` Grant Likely
2011-09-20 20:24   ` [PATCH 3/3] ARM: gic: add OF based initialization Rob Herring
     [not found]     ` <1316550244-3655-4-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-20 23:08       ` Grant Likely
     [not found]         ` <20110920230800.GS7781-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2011-09-21  1:54           ` Rob Herring
2011-09-21 17:15       ` Cousson, Benoit
     [not found]         ` <4E7A1BCA.1090006-l0cyMroinI0@public.gmane.org>
2011-09-21 17:55           ` Rob Herring
     [not found]             ` <4E7A252F.2000402-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-21 19:28               ` Cousson, Benoit
     [not found]                 ` <4E7A3AF0.1020809-l0cyMroinI0@public.gmane.org>
2011-09-21 20:27                   ` Cousson, Benoit
2011-09-26 19:57       ` Jamie Iles
2011-09-26 20:49         ` Rob Herring
     [not found]           ` <4E80E547.2080004-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-26 21:11             ` Jamie Iles
2011-09-26 21:32               ` Rob Herring
2011-09-26 22:00                 ` Jamie Iles
2011-09-26 22:29       ` Jamie Iles
2011-09-21  9:43   ` [PATCH 0/3] GIC OF bindings Shawn Guo
2011-09-21  2:49 ` David Miller
2011-09-21  4:14   ` Grant Likely
     [not found]     ` <CACxGe6t7Mdr+w+aGFPM2-FEAQaYHuG8Za9dybLgMo-5-whLyNQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-21  4:58       ` Mitch Bradley
2011-09-21  5:21         ` David Miller
     [not found]           ` <20110921.012158.2252182592946972727.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-09-21  7:11             ` Mitch Bradley
     [not found]   ` <20110920.224910.1996429830782124690.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-09-21  5:16     ` Segher Boessenkool

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=4E81C9B7.9000004@gmail.com \
    --to=robherring2-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.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).