From patchwork Mon Aug 5 06:53:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 18763 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f69.google.com (mail-qe0-f69.google.com [209.85.128.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 65B6325E7B for ; Mon, 5 Aug 2013 06:54:41 +0000 (UTC) Received: by mail-qe0-f69.google.com with SMTP id 1sf4169712qec.8 for ; Sun, 04 Aug 2013 23:54:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-beenthere:x-forwarded-to:x-forwarded-for:delivered-to:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-gm-message-state:x-removed-original-auth:x-original-sender :x-original-authentication-results:mailing-list:x-google-group-id :content-type:content-transfer-encoding; bh=pzwrWEJ0hAKV09pVl+Uf4nFsK9E1YqWYTRr1243gNC4=; b=QOQtwsYd4nYzKr+0ZfEEnjubak9Kq3L/3uXwxc1ZRw8kC5m7LI4yi9GvYuwCMiNTou YEO45abyXk2HiFZkGSq2jksfceRzxzCYuL49Ij9Z11mLfCGiFTchyHTU2SLgKekXeIhT jn1n91OqY9WmeVp3QEWPjaoQBbW1IF3in68M6C12rtz/3LV8NR5+ziBCxZkLe0ago9sX Sw6moMx0FNGxn9Bzzk6n/NLz5zSRXpj9MG2T7xCP1Dpeuyvq/IiW6Cz3/ojz9gRpb/yw QMClmBmfFZ0W55ym5JxREYma8sab4LKGQw3yHmTZ8udTK93ItdaMrcAVHQa0y7jUheLi GRow== X-Received: by 10.236.78.198 with SMTP id g46mr7858148yhe.56.1375685681155; Sun, 04 Aug 2013 23:54:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.110.40 with SMTP id hx8ls960338qeb.83.gmail; Sun, 04 Aug 2013 23:54:41 -0700 (PDT) X-Received: by 10.220.76.69 with SMTP id b5mr4423756vck.85.1375685681059; Sun, 04 Aug 2013 23:54:41 -0700 (PDT) Received: from mail-vb0-f44.google.com (mail-vb0-f44.google.com [209.85.212.44]) by mx.google.com with ESMTPS id rd13si178812vcb.51.2013.08.04.23.54.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 04 Aug 2013 23:54:41 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.44 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.44; Received: by mail-vb0-f44.google.com with SMTP id e13so2456951vbg.31 for ; Sun, 04 Aug 2013 23:54:41 -0700 (PDT) X-Received: by 10.221.43.70 with SMTP id ub6mr5193963vcb.86.1375685680924; Sun, 04 Aug 2013 23:54:40 -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.221.11.8 with SMTP id pc8csp72233vcb; Sun, 4 Aug 2013 23:54:40 -0700 (PDT) X-Received: by 10.14.212.6 with SMTP id x6mr4028129eeo.67.1375685679845; Sun, 04 Aug 2013 23:54:39 -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 w4si15117157eex.207.2013.08.04.23.54.39 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 04 Aug 2013 23:54:39 -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 1V6EgT-0001n3-7Y; Mon, 05 Aug 2013 06:54:25 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1V6EgQ-0001mN-UJ for linaro-mm-sig@lists.linaro.org; Mon, 05 Aug 2013 06:54:23 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MR100JAPPURLNB0@mailout2.samsung.com> for linaro-mm-sig@lists.linaro.org; Mon, 05 Aug 2013 15:54:28 +0900 (KST) X-AuditID: cbfee61b-b7efe6d000007b11-55-51ff4c2374eb Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 8B.3E.31505.32C4FF15; Mon, 05 Aug 2013 15:54:27 +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 <0MR1001JGPTNTLG1@mmp1.samsung.com>; Mon, 05 Aug 2013 15:54:27 +0900 (KST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, devicetree@vger.kernel.org Date: Mon, 05 Aug 2013 08:53:42 +0200 Message-id: <1375685624-12103-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1375685624-12103-1-git-send-email-m.szyprowski@samsung.com> References: <1375685624-12103-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsVy+t9jAV1ln/+BBkfPmln8nXSM3WL+kXOs Fq/ObGSzONv0ht1ie+cMdosvVx4yWWx6fI3VYu2Ru+wWG14eZLJYcLyF1eLPdDmLU9c/s1l8 //aNzeLv9k0sFofftLNarJ/xmsVBwOP3r0mMHpf7epk8ds66y+6xeUm9x+1/j5k9rpxoYvVY 9+cVk0f/XwOPvi2rGD1+vtTx+LxJLoA7issmJTUnsyy1SN8ugSvjz7N29oIzshWfti9iamC8 IN7FyMEhIWAiMe+WahcjJ5ApJnHh3nq2LkYuDiGBRYwSm458Zodw2pkkfmw4yw5SxSZgKNH1 tosNxBYRSJOYsWoDC4jNLNDGIvECwhYWCJZYfOYUWD2LgKrEj8OtYDavgIfEla9bWCAWK0jM mWQDYnIKeErcfJYJUiEEVLGg/yTbBEbeBYwMqxhFUwuSC4qT0nON9IoTc4tL89L1kvNzNzGC w/uZ9A7GVQ0WhxgFOBiVeHgV2P8HCrEmlhVX5h5ilOBgVhLhZe//GyjEm5JYWZValB9fVJqT WnyIUZqDRUmc92CrdaCQQHpiSWp2ampBahFMlomDU6qBcZ2acIzioztTJ3zuPWkedC+Y160m 1+bFkuSzAssmP77wQr34h2p6256TzPqmTBXGIYfk2Iwu9Zx+9Nle6Jkqn4e8zhaFIN/48gXL u/LK1YU47iRN7VZ+dHVqGpvrr0fvFO6sZZfJ+vReze3sA631G8sYXh1QKnG/YdEls9sk+tGW lbzpNQ8fKbEUZyQaajEXFScCAJHkYEBrAgAA Cc: Arnd Bergmann , Tomasz Figa , Michal Nazarewicz , Grant Likely , Kyungmin Park , Rob Herring , Sylwester Nawrocki , Olof Johansson , Sascha Hauer Subject: [Linaro-mm-sig] [PATCH v4 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-Gm-Message-State: ALoCoQnTqfFx1wP2NJ1ii69TtMnASI4p0dXEfPFVXH83DCNN3iCx30cqiX2vkv1FO0oeu6ZC02YP 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.212.44 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 ealy boot before we can unflatten the tree. Signed-off-by: Marek Szyprowski Acked-by: Kyungmin Park --- 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);