From patchwork Wed Jul 31 12:51:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 2836223 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4B4AC9F4D4 for ; Wed, 31 Jul 2013 12:53:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 15E36202C7 for ; Wed, 31 Jul 2013 12:53:38 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 226C7202BE for ; Wed, 31 Jul 2013 12:53:33 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V4Vu1-0007xM-2E; Wed, 31 Jul 2013 12:53:17 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V4Vtu-0005xG-MY; Wed, 31 Jul 2013 12:53:10 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V4VtS-0005sk-Kk for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2013 12:52:44 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MQS00GABX3472V0@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2013 21:52:23 +0900 (KST) X-AuditID: cbfee61b-b7efe6d000007b11-11-51f90887056c Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 13.0A.31505.78809F15; Wed, 31 Jul 2013 21:52:23 +0900 (KST) Received: from localhost.localdomain ([106.116.147.30]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MQS004JJX2O1G70@mmp1.samsung.com>; Wed, 31 Jul 2013 21:52:22 +0900 (KST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, devicetree-discuss@lists.ozlabs.org Subject: [PATCH v4 2/4] drivers: of: add function to scan fdt nodes given by path Date: Wed, 31 Jul 2013 14:51:57 +0200 Message-id: <1375275119-12787-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1375275119-12787-1-git-send-email-m.szyprowski@samsung.com> References: <1375275119-12787-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFLMWRmVeSWpSXmKPExsVy+t9jAd12jp+BBtObeSz+TjrGbnFg9kNW i1dnNrJZnG16w26xvXMGu8WXKw+ZLDY9vsZqsfbIXXaLDS8PMlksON7CavFnupzFqeuf2Sy+ f/vGZvF3+yYWi8Nv2lkt1s94zeIg4PH71yRGj8t9vUweO2fdZffYvKTe4/a/x8we52csZPS4 cqKJ1WPdn1dMHv1/DTz6tqxi9Pj5UieAO4rLJiU1J7MstUjfLoEr48+zdvaCM7IVn7YvYmpg vCDexcjJISFgIrHtygo2CFtM4sK99UA2F4eQwCJGidlPnjNDOO1MEiuvbGAEqWITMJToetsF VMXBISKQL7F6Fi9ImFmgjUXixQYWEFtYIFhi8ZlT7CA2i4CqxO5pM5hBbF4BD4k/fVOYQFol BBQk5kyyAQlzCnhKHPy5B+wGIaCSY3Mnsk1g5F3AyLCKUTS1ILmgOCk910ivODG3uDQvXS85 P3cTIzjEn0nvYFzVYHGIUYCDUYmHd8al74FCrIllxZW5hxglOJiVRHj3sP4MFOJNSaysSi3K jy8qzUktPsQozcGiJM57sNU6UEggPbEkNTs1tSC1CCbLxMEp1cBYMruraiOzf6EBz7qkGRte ie3xet9wREItlPMct2Sd608JXR1ehoqLLqVCondd9c7MOLPI62fuq3OK7D75nQ89FjXbSl0+ xpxxvoKba0Lebbn3d+a/DZ6fPneqV2L8EwGGq3w2P1axBZjI1nBetvPab3et7OstwWVGkzdk vXdSuV+3eGbu5RVKLMUZiYZazEXFiQApARe6bQIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130731_085242_959482_0D29E27F X-CRM114-Status: GOOD ( 15.40 ) X-Spam-Score: -8.4 (--------) Cc: Laura Abbott , Arnd Bergmann , Tomasz Figa , Nishanth Peethambaran , Michal Nazarewicz , Grant Likely , Marc , Kyungmin Park , Sylwester Nawrocki , Olof Johansson , Sascha Hauer , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 tree. Signed-off-by: Marek Szyprowski Acked-by: Kyungmin Park Acked-by: Michal Nazarewicz --- drivers/of/fdt.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_fdt.h | 3 ++ 2 files changed, 79 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 6bb7cf2..8d6e7e8 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -543,6 +543,82 @@ int __init of_flat_dt_match(unsigned long node, const char *const *compat) return of_fdt_match(initial_boot_params, node, compat); } +struct fdt_scan_status { + const char *name; + int namelen; + int depth; + int found; + int (*iterator)(unsigned long node, const char *uname, int depth, void *data); + void *data; +}; + +/** + * fdt_scan_node_by_path - iterator for of_scan_flat_dt_by_path function + */ +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) { + 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; + } + 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; +} + #ifdef CONFIG_BLK_DEV_INITRD /** * early_init_dt_check_for_initrd - Decode initrd location from flat tree diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index ed136ad..1151a7f 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -90,6 +90,9 @@ extern void *of_get_flat_dt_prop(unsigned long node, const char *name, extern int of_flat_dt_is_compatible(unsigned long node, const char *name); extern int of_flat_dt_match(unsigned long node, const char *const *matches); extern unsigned long of_get_flat_dt_root(void); +extern 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); extern int early_init_dt_scan_chosen(unsigned long node, const char *uname, int depth, void *data);