From: mina86@mina86.com (Michal Nazarewicz)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 2/4] drivers: of: add function to scan fdt nodes given by path
Date: Mon, 05 Aug 2013 16:30:56 +0200 [thread overview]
Message-ID: <xa1ttxj4us4f.fsf@mina86.com> (raw)
In-Reply-To: <1375275119-12787-3-git-send-email-m.szyprowski@samsung.com>
On Wed, Jul 31 2013, Marek Szyprowski wrote:
> Add a function to scan the flattened device-tree starting from the
> node given by the path. It is used to extract information (like reserved
> memory), which is required on ealy boot before we can unflatten the
^^^^ early
> tree.
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Some minor comments inline.
> +static int __init fdt_scan_node_by_path(unsigned long node, const char *uname,
> + int depth, void *data)
> +{
> + struct fdt_scan_status *st = data;
> +
> + /*
> + * if scan at the requested fdt node has been completed,
> + * return -ENXIO to abort further scanning
> + */
> + if (depth <= st->depth)
> + return -ENXIO;
> +
> + /* requested fdt node has been found, so call iterator function */
> + if (st->found)
> + return st->iterator(node, uname, depth, st->data);
> +
> + /* check if scanning automata is entering next level of fdt nodes */
> + if (depth == st->depth + 1 &&
> + strncmp(st->name, uname, st->namelen) == 0) {
+ strncmp(st->name, uname, st->namelen) == 0 &&
+ uname[st->namelen] == 0) {
> + st->depth += 1;
> + if (st->name[st->namelen] == 0) {
> + st->found = 1;
> + } else {
> + const char *next = st->name + st->namelen + 1;
> + const char *p = next;
> + while (*p != '/' && *p != 0)
> + p++;
> + st->name = next;
> + st->namelen = p - next;
+ st->namelen = strcspn(next, "/");
except this might be slightly slower since the second argument is looped
over, but something to consider I guess since it get rid of few of the
lines of code.
> + }
> + return 0;
> + }
> +
> + /* scan next fdt node */
> + return 0;
> +}
> +
> +/**
> + * of_scan_flat_dt_by_path - scan flattened tree blob and call callback on each
> + * child of the given path.
> + * @path: path to start searching for children
> + * @it: callback function
> + * @data: context data pointer
> + *
> + * This function is used to scan the flattened device-tree starting from the
> + * node given by path. It is used to extract information (like reserved
> + * memory), which is required on ealy boot before we can unflatten the tree.
> + */
> +int __init of_scan_flat_dt_by_path(const char *path,
> + int (*it)(unsigned long node, const char *name, int depth, void *data),
> + void *data)
> +{
> + struct fdt_scan_status st = {path, 0, -1, 0, it, data};
> + int ret = 0;
> +
> + if (initial_boot_params)
> + ret = of_scan_flat_dt(fdt_scan_node_by_path, &st);
> +
> + if (st.found && ret == -ENXIO) /* scan has been completed */
> + return 0;
> + else
> + return -ENOENT;
Perhaps propagate ret:
+ if (!st.found)
+ return -ENOENT;
+ else if (ret == -ENXIO)
+ return 0;
+ else
+ return ret;
> +}
> +
> #ifdef CONFIG_BLK_DEV_INITRD
> /**
> * early_init_dt_check_for_initrd - Decode initrd location from flat tree
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Micha? ?mina86? Nazarewicz (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130805/6cec4a65/attachment.sig>
WARNING: multiple messages have this Message-ID (diff)
From: Michal Nazarewicz <mina86@mina86.com>
To: linux-arm-kernel@lists.infradead.org,
linaro-mm-sig@lists.linaro.org,
devicetree-discuss@lists.ozlabs.org
Cc: Laura Abbott <lauraa@codeaurora.org>,
Arnd Bergmann <arnd@arndb.de>, Tomasz Figa <t.figa@samsung.com>,
Nishanth Peethambaran <nishanth.p@gmail.com>,
Grant Likely <grant.likely@secretlab.ca>,
Marc <marc.ceeeee@gmail.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Sylwester Nawrocki <s.nawrocki@samsung.com>,
Olof Johansson <olof@lixom.net>,
Sascha Hauer <s.hauer@pengutronix.de>,
Marek Szyprowski <m.szyprowski@samsung.com>
Subject: Re: [PATCH v4 2/4] drivers: of: add function to scan fdt nodes given by path
Date: Mon, 05 Aug 2013 16:30:56 +0200 [thread overview]
Message-ID: <xa1ttxj4us4f.fsf@mina86.com> (raw)
In-Reply-To: <1375275119-12787-3-git-send-email-m.szyprowski@samsung.com>
[-- Attachment #1: Type: text/plain, Size: 3340 bytes --]
On Wed, Jul 31 2013, Marek Szyprowski wrote:
> Add a function to scan the flattened device-tree starting from the
> node given by the path. It is used to extract information (like reserved
> memory), which is required on ealy boot before we can unflatten the
^^^^ early
> tree.
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Some minor comments inline.
> +static int __init fdt_scan_node_by_path(unsigned long node, const char *uname,
> + int depth, void *data)
> +{
> + struct fdt_scan_status *st = data;
> +
> + /*
> + * if scan at the requested fdt node has been completed,
> + * return -ENXIO to abort further scanning
> + */
> + if (depth <= st->depth)
> + return -ENXIO;
> +
> + /* requested fdt node has been found, so call iterator function */
> + if (st->found)
> + return st->iterator(node, uname, depth, st->data);
> +
> + /* check if scanning automata is entering next level of fdt nodes */
> + if (depth == st->depth + 1 &&
> + strncmp(st->name, uname, st->namelen) == 0) {
+ strncmp(st->name, uname, st->namelen) == 0 &&
+ uname[st->namelen] == 0) {
> + st->depth += 1;
> + if (st->name[st->namelen] == 0) {
> + st->found = 1;
> + } else {
> + const char *next = st->name + st->namelen + 1;
> + const char *p = next;
> + while (*p != '/' && *p != 0)
> + p++;
> + st->name = next;
> + st->namelen = p - next;
+ st->namelen = strcspn(next, "/");
except this might be slightly slower since the second argument is looped
over, but something to consider I guess since it get rid of few of the
lines of code.
> + }
> + return 0;
> + }
> +
> + /* scan next fdt node */
> + return 0;
> +}
> +
> +/**
> + * of_scan_flat_dt_by_path - scan flattened tree blob and call callback on each
> + * child of the given path.
> + * @path: path to start searching for children
> + * @it: callback function
> + * @data: context data pointer
> + *
> + * This function is used to scan the flattened device-tree starting from the
> + * node given by path. It is used to extract information (like reserved
> + * memory), which is required on ealy boot before we can unflatten the tree.
> + */
> +int __init of_scan_flat_dt_by_path(const char *path,
> + int (*it)(unsigned long node, const char *name, int depth, void *data),
> + void *data)
> +{
> + struct fdt_scan_status st = {path, 0, -1, 0, it, data};
> + int ret = 0;
> +
> + if (initial_boot_params)
> + ret = of_scan_flat_dt(fdt_scan_node_by_path, &st);
> +
> + if (st.found && ret == -ENXIO) /* scan has been completed */
> + return 0;
> + else
> + return -ENOENT;
Perhaps propagate ret:
+ if (!st.found)
+ return -ENOENT;
+ else if (ret == -ENXIO)
+ return 0;
+ else
+ return ret;
> +}
> +
> #ifdef CONFIG_BLK_DEV_INITRD
> /**
> * early_init_dt_check_for_initrd - Decode initrd location from flat tree
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--
[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]
[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]
[-- Attachment #3: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2013-08-05 14:30 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-31 12:51 [PATCH v4 0/4] Device Tree support for CMA (Contiguous Memory Allocator) Marek Szyprowski
2013-07-31 12:51 ` Marek Szyprowski
2013-07-31 12:51 ` [PATCH v4 1/4] drivers: dma-contiguous: clean source code and prepare for device tree Marek Szyprowski
2013-07-31 12:51 ` Marek Szyprowski
2013-08-05 14:06 ` Michal Nazarewicz
2013-08-05 14:06 ` Michal Nazarewicz
2013-07-31 12:51 ` [PATCH v4 2/4] drivers: of: add function to scan fdt nodes given by path Marek Szyprowski
2013-07-31 12:51 ` Marek Szyprowski
2013-08-05 14:30 ` Michal Nazarewicz [this message]
2013-08-05 14:30 ` Michal Nazarewicz
2013-07-31 12:51 ` [PATCH v4 3/4] drivers: of: add initialization code for dma reserved memory Marek Szyprowski
2013-07-31 12:51 ` Marek Szyprowski
2013-08-05 18:59 ` Michal Nazarewicz
2013-08-05 18:59 ` Michal Nazarewicz
2013-08-06 13:30 ` Rob Herring
2013-08-06 13:30 ` Rob Herring
2013-08-06 15:07 ` Michal Nazarewicz
2013-08-06 15:07 ` Michal Nazarewicz
2013-08-06 15:33 ` Sylwester Nawrocki
2013-08-06 15:33 ` Sylwester Nawrocki
2013-08-07 12:38 ` Michal Nazarewicz
2013-08-07 12:38 ` Michal Nazarewicz
2013-08-07 13:08 ` Rob Herring
2013-08-07 13:08 ` Rob Herring
2013-08-07 15:07 ` Kumar Gala
2013-08-07 15:07 ` Kumar Gala
2013-07-31 12:51 ` [PATCH v4 4/4] ARM: init: add support for reserved memory defined by device tree Marek Szyprowski
2013-07-31 12:51 ` Marek Szyprowski
2013-08-05 14:31 ` Michal Nazarewicz
2013-08-05 14:31 ` Michal Nazarewicz
-- strict thread matches above, loose matches on Subject: below --
2013-08-05 6:53 [PATCH v4 0/4] [RESEND] Device Tree support for CMA (Contiguous Memory Allocator) Marek Szyprowski
2013-08-05 6:53 ` [PATCH v4 2/4] drivers: of: add function to scan fdt nodes given by path Marek Szyprowski
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=xa1ttxj4us4f.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.