From: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
To: Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: dave.martin-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH 2/3] of/irq: introduce of_irq_init
Date: Wed, 21 Sep 2011 11:01:10 +0100 [thread overview]
Message-ID: <20110921100110.GE18931@pulham.picochip.com> (raw)
In-Reply-To: <1316550244-3655-3-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Hi Rob,
On Tue, Sep 20, 2011 at 03:24:03PM -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.
>
> Signed-off-by: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> ---
> drivers/of/irq.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/of_irq.h | 1 +
> 2 files changed, 115 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> index 6a5b5e7..1d51bc7 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,115 @@ 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;
> +};
> +
> +typedef int (*irq_init_cb_t)(struct device_node *, struct device_node *);
> +
> +/**
> + * of_irq_init - Scan the device tree for matching interrupt controllers and
> + * call their initialization functions in order with parents first.
> + * @matches: 0 terminated array of nodes to match and initialization function
> + * to call on match
> + */
> +void __init of_irq_init(const struct of_device_id *matches)
> +{
> + struct device_node *np;
> + struct intc_desc *desc;
> + struct intc_desc *temp_desc;
> + struct intc_desc *parent_desc = NULL;
> + struct list_head intc_desc_list;
> + struct list_head 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 (!desc) {
> + WARN_ON(1);
> + goto err;
> + }
> + desc->dev = np;
> + desc->interrupt_parent = of_irq_find_parent(np);
> + list_add(&desc->list, &intc_desc_list);
> + }
> + if (list_empty(&intc_desc_list))
> + return;
> +
> + /*
> + * 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;
> + irq_init_cb_t irq_init_cb;
> +
> + if (parent_desc &&
> + (desc->interrupt_parent != parent_desc->dev))
> + continue;
> +
> + list_del(&desc->list);
> + match = of_match_node(matches, desc->dev);
> + if (!match || !match->data)
> + continue;
Doesn't this case need to kfree(desc)?
> +
> + 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)
> + continue;
and here?
> +
> + /*
> + * 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);
> + }
> + /*
> + * All the direct children for the current parent are
> + * processed, so free the parent now.
> + */
> + if (parent_desc)
> + kfree(parent_desc);
> +
> + /* Get the next pending parent that might have children */
> + parent_desc = list_first_entry(&intc_parent_list,
> + typeof(*parent_desc), list);
> + if (list_empty(&intc_parent_list) || !parent_desc) {
> + pr_debug("of_irq_init: children remain, but no parents\n");
> + goto err;
> + }
> +
> + list_del(&parent_desc->list);
> + }
> + return;
> +
> +err:
> + list_for_each_entry_safe(desc, temp_desc, &intc_parent_list, list) {
> + list_del(&desc->list);
> + kfree(desc);
> + }
> + 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..032d76c 100644
> --- a/include/linux/of_irq.h
> +++ b/include/linux/of_irq.h
> @@ -73,6 +73,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
>
next prev parent reply other threads:[~2011-09-21 10:01 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 [this message]
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
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=20110921100110.GE18931@pulham.picochip.com \
--to=jamie-wmlquqddiekakbo8gow8eq@public.gmane.org \
--cc=dave.martin-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
--cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
--cc=robherring2-Re5JQEeQqe8AvxtiuMwx3w@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).