From patchwork Mon Aug 26 14:39:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 19535 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9E6112469A for ; Mon, 26 Aug 2013 14:40:10 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id oz10sf3746638veb.11 for ; Mon, 26 Aug 2013 07:40:10 -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=O+zfbe5OjjuYrLWSRnHjPZWU8JC8wZb0GQuFHKzOv90=; b=A5dOeKbgYHvNMyI02bFqr5LniEaTuYEBC9HsKSDUJtJVuGsgcb0adB7t3J2uppdRGI WzIEOAF6yRwIjzzV6CXdVOYFe95wm23P+Mw4puWmIFWFpksOw+z36SCVX4dKhK4yFtBF J1qhlea0UD0XRSvOyDkAo8pg8Sr6WN7u89eJ9zM78aW9/hk6kVkrCx56FX1FiV/T79AT h60X865L8orP48Q7+ukzoIxaAi45SEhkMADc8WmRO3a6O3vm4GimGgQ+N8w4Kmy9DHul hvjv9S7Xxgd/fp6JB5urvl2CSjX6LUsBG/15ppjbuExmRg91HParmmnDWwSTiuHFPBFK yRcg== X-Received: by 10.236.45.102 with SMTP id o66mr5335677yhb.47.1377528010272; Mon, 26 Aug 2013 07:40:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.41 with SMTP id h9ls2394155qeh.79.gmail; Mon, 26 Aug 2013 07:40:10 -0700 (PDT) X-Received: by 10.58.215.15 with SMTP id oe15mr1122639vec.25.1377528010189; Mon, 26 Aug 2013 07:40:10 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id o4si3654536vcx.58.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 26 Aug 2013 07:40:10 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id db10so2246243veb.28 for ; Mon, 26 Aug 2013 07:40:09 -0700 (PDT) X-Gm-Message-State: ALoCoQk7sfXWK1+z3eZ30/WfHKIbVhQyEwGNGN3mnaqhqFU5X6Yj4iRlk8p9Va4NnoEIaqKs71e9 X-Received: by 10.58.201.227 with SMTP id kd3mr15733751vec.14.1377528009848; Mon, 26 Aug 2013 07:40:09 -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 u4csp238959vcz; Mon, 26 Aug 2013 07:40:09 -0700 (PDT) X-Received: by 10.194.85.198 with SMTP id j6mr1490117wjz.51.1377528008373; Mon, 26 Aug 2013 07:40:08 -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 gs3si4207471wib.82.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 26 Aug 2013 07:40:08 -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 1VDxwu-0003PE-PI; Mon, 26 Aug 2013 14:39:20 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1VDxwt-0003Op-Kj for linaro-mm-sig@lists.linaro.org; Mon, 26 Aug 2013 14:39:19 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MS5008YP7EKD410@mailout1.samsung.com> for linaro-mm-sig@lists.linaro.org; Mon, 26 Aug 2013 23:39:56 +0900 (KST) X-AuditID: cbfee61a-b7f7a6d00000235f-fe-521b68bcfe01 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 68.C4.09055.CB86B125; Mon, 26 Aug 2013 23:39:56 +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 <0MS50074S7DMCL50@mmp2.samsung.com>; Mon, 26 Aug 2013 23:39:56 +0900 (KST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, devicetree@vger.kernel.org Date: Mon, 26 Aug 2013 16:39:17 +0200 Message-id: <1377527959-5080-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1377527959-5080-1-git-send-email-m.szyprowski@samsung.com> References: <1377527959-5080-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeLIzCtJLcpLzFFi42I5/e+xoO6eDOkgg+WX5Sz+TjrGbjH/yDlW i/43C1ktXp3ZyGbxpreDxeJs0xt2i+2dM9gtvlx5yGSx6fE1Vou1R+6yW2x4eZDJYun1i0wW C463sFr8mS5ncer6ZzaLCdPXslh8//aNzeLv9k0sFofftAONO9jGYrF+xmsWi1W7/jA6iHms mbeG0eP3r0mMHq8nT2D0uNzXy+Sxc9Zddo/NS+o9bv97zOxx5UQTq8e6P6+YPPr/Gnj0bVnF 6PHzpY7H501yHhvnhgbwRXHZpKTmZJalFunbJXBl9Oy+wFawXq7iwKQLrA2MyyS6GDk4JARM JD7eteli5AQyxSQu3FvP1sXIxSEkMJ1R4vChGawQTjuTxNpjs9lBqtgEDCW63naxgdgiAmkS M1ZtYAEpYhZ4wyqx4lIPO8hUYYFgiU33M0BqWARUJY7+aAWr5xVwlzj5+zErxGIFiTmTwBZz CnhI3Dk2gxEkLARU0tqqOYGRdwEjwypG0dSC5ILipPRcQ73ixNzi0rx0veT83E2M4Lh5JrWD cWWDxSFGAQ5GJR7ewAKpICHWxLLiytxDjBIczEoivByp0kFCvCmJlVWpRfnxRaU5qcWHGKU5 WJTEeQ+0WgcKCaQnlqRmp6YWpBbBZJk4OKUaGBcdElYzWML/KHTD6+a/P7miF1k+T/5+j+Pn P/2rHY9kg/xk+Kv/6UbFqyZlaBcq971wTnC+v5/nYj33xbSzkUzX598/6HTxwKXq1qLpJmxn +pNW6kwrPLFi2bJEzwxBp0qW+Zu5PGN1qtyfhl10nL9L4NstKwbum53HozO/eAQUSrgLdqx9 osRSnJFoqMVcVJwIAGuIHBuXAgAA 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 v7 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.128.169 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 Reviewed-by: Rob Herring Acked-by: Grant Likely --- 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 b10ba00..4fb06f3 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -545,6 +545,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..19f26f8 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);