From patchwork Mon Aug 19 15:04:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 19324 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f69.google.com (mail-vb0-f69.google.com [209.85.212.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 03192246F8 for ; Mon, 19 Aug 2013 15:05:23 +0000 (UTC) Received: by mail-vb0-f69.google.com with SMTP id e13sf5601300vbg.4 for ; Mon, 19 Aug 2013 08:05:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=lgt39SSFcE+TIZs4V7SPebunqJB5mRCHicPKaRwyUuQ=; b=Cx75gTnSVLzMNlVdG9O8KKRb4wfCf3Bfud6tUx3mxNuveLnRnhWnNK0BDwDTRGvpQ7 TJEz1LHPvYMofBA5y5Os7+C/3cYXw0NSXo/SsoQo7JH+5QIHRD9TB+DWR24ctp3Ka+io 2+MKHlTTFiJdZkZk+BYaCo6GNPddDzC4sk2CzqlPz2CQ1eCFmaDUlrURDcxLTxb7E+PS n7of4kmpWD7inzlI9BeEa0LdnZg3CSbvHRBNI9XWZUvYYsYQDw13EZrO3VmvMc68dBP5 GVVM5nGcDDNRIae8kBTU9ratT5smhznmXZV+OS7u+4tuUf3187laas1xZ4qCCOlsWNbD 5GpQ== X-Received: by 10.59.11.2 with SMTP id ee2mr864969ved.11.1376924723864; Mon, 19 Aug 2013 08:05:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.49.196 with SMTP id w4ls1720913qen.71.gmail; Mon, 19 Aug 2013 08:05:23 -0700 (PDT) X-Received: by 10.52.165.111 with SMTP id yx15mr719907vdb.33.1376924723245; Mon, 19 Aug 2013 08:05:23 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id rx10si2443205vdc.99.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Aug 2013 08:05:23 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ia10so3036318vcb.6 for ; Mon, 19 Aug 2013 08:05:23 -0700 (PDT) X-Gm-Message-State: ALoCoQm4gnVvPg2H7HLHShEcEBouH6di1iJC2wxC9MZZMJSjkScKBAMBR9QFOAgxz8cX9ymBa2CF X-Received: by 10.220.164.70 with SMTP id d6mr6352825vcy.19.1376924723146; Mon, 19 Aug 2013 08:05:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp101193vcz; Mon, 19 Aug 2013 08:05:22 -0700 (PDT) X-Received: by 10.15.68.198 with SMTP id w46mr31181eex.77.1376924720414; Mon, 19 Aug 2013 08:05:20 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id l45si10057105eep.34.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 19 Aug 2013 08:05:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1VBR0Z-0002Of-AG; Mon, 19 Aug 2013 15:04:39 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1VBR0X-0002O1-Oz for linaro-mm-sig@lists.linaro.org; Mon, 19 Aug 2013 15:04:37 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MRS007AP9WGR1A0@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 20 Aug 2013 00:05:04 +0900 (KST) X-AuditID: cbfee61a-b7f196d000007dfa-ae-521234200856 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id C5.B2.32250.02432125; Tue, 20 Aug 2013 00:05:04 +0900 (KST) Received: from localhost.localdomain ([106.116.147.30]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MRS004QS9VPKP20@mmp2.samsung.com>; Tue, 20 Aug 2013 00:05:04 +0900 (KST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, devicetree@vger.kernel.org Date: Mon, 19 Aug 2013 17:04:27 +0200 Message-id: <1376924669-28873-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1376924669-28873-1-git-send-email-m.szyprowski@samsung.com> References: <1376924669-28873-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeLIzCtJLcpLzFFi42I5/e+xoK6CiVCQwYEmNYu/k46xW8w/co7V ov/NQlaLV2c2slm86e1gsTjb9IbdYnvnDHaLL1ceMllsenyN1WLtkbvsFhteHmSyWHr9IpPF guMtrBZ/pstZnLr+mc1iwvS1LBbfv31js/i7fROLxeE37UDjDraxWKyf8ZrFYtWuP4wOYh5r 5q1h9Pj9axKjx+vJExg9Lvf1MnnsnHWX3WPzknqP2/8eM3tcOdHE6rHuzysmj/6/Bh59W1Yx evx8qePxeZOcx8a5oQF8UVw2Kak5mWWpRfp2CVwZG36/ZSz4LVtxufMVcwPjd/EuRk4OCQET iXffNjNC2GISF+6tZwOxhQSmM0pc+KXXxcgFZLczSVy6+QYswSZgKNH1tgvMFhFIk5ixagML SBGzwBtWiRWXethBEsICwRJ3/vwCSnBwsAioSszcagZi8gp4SExsEwcxJQQUJOZMsgEp5hTw lNjWeZQJYq2HxL6nXxknMPIuYGRYxSiaWpBcUJyUnmuoV5yYW1yal66XnJ+7iREcN8+kdjCu bLA4xCjAwajEw9upJBQkxJpYVlyZe4hRgoNZSYT3KztQiDclsbIqtSg/vqg0J7X4EKM0B4uS OO+BVutAIYH0xJLU7NTUgtQimCwTB6dUA+NU5d2mwXNe+k7vYLvt6rmg5PGJePctDumKJn0H TWdur16e8Xztg+Xa27JdVpXHC8463Hp0Q3SpxiuV6u3+hv3hM9dPXBbp7bZkX/azWIe0Hdee l6YvOHyDsUdcWfnAotn6BW/sM/6r35hS/tKCf5Xcsf06uqvrVfmvVd+ddVesL17Jb0VxTrgS S3FGoqEWc1FxIgD57OO4lwIAAA== Cc: Mark Rutland , Pawel Moll , Arnd Bergmann , Stephen Warren , Tomasz Figa , Tomasz Figa , Michal Nazarewicz , Grant Likely , Kyungmin Park , Rob Herring , Sylwester Nawrocki , Kumar Gala , Olof Johansson , Ian Campbell , Sascha Hauer Subject: [Linaro-mm-sig] [PATCH v6 2/4] drivers: of: add function to scan fdt nodes given by path X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 early boot before we can unflatten the tree. Signed-off-by: Marek Szyprowski Acked-by: Michal Nazarewicz Acked-by: Tomasz Figa --- 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..585b1a6 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 && + 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; + st->name = next; + st->namelen = strcspn(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) + return -ENOENT; + else if (ret == -ENXIO) /* scan has been completed */ + return 0; + else + return ret; +} + #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 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);