From patchwork Fri Aug 10 12:54:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 956242 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AMVhLG/I"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41n4qS1dJCz9s4Z for ; Fri, 10 Aug 2018 22:55:48 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id BA1F2C21DF9; Fri, 10 Aug 2018 12:55:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EFBBBC21DB6; Fri, 10 Aug 2018 12:54:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 504CEC21C27; Fri, 10 Aug 2018 12:54:42 +0000 (UTC) Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by lists.denx.de (Postfix) with ESMTPS id DA34CC21C27 for ; Fri, 10 Aug 2018 12:54:41 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id f18-v6so6528598lfc.2 for ; Fri, 10 Aug 2018 05:54:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WB0r/QnU5Maqf0pqVTMNOqHxmR20pieSek+3MYJad+w=; b=AMVhLG/IR2LUmJcPulFW5RksUFT988PBtjAZ2LYWbe6ujrI+N35YaX6k/CpJeTcpoY sl/m6saSGCHf3uiE9l3W5ya9uzu4dT46BEEf+rIphei4MhrGUMDVPhKgIHIjHpUIGamk PNNzM+YEK8ncb3r59q7kSHffE6ScR9TpTA7PE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WB0r/QnU5Maqf0pqVTMNOqHxmR20pieSek+3MYJad+w=; b=SUtOrhFuUlrUcMzkvwt/B9gCFdKYwObETqQc872UMjVHoIeP6VENp0f7ezKE/5x6Q+ 2Zuu6e9DjBF/nnyjmJtzbIPE3ktDlZHmp3rVpHb0c6ZZ/tvPuVpRpE7ajVBAPKWcdy35 96pz23NVApsayj7lMe7pAjdlrfCSxPSnqlB9eK7EVrOkUe3awsXn3Feg+305I2NNdGHB lNt8QbZTwHYewKZtTUVUxIkAebT/YMaJIxvA+Lx5v3Lre6MpGZJOQxE5KsUv/54tjBmJ mmNMrq/0ACrNHJKG3ul38KjkrthM2B1bq6ml6CVBYjjVGMdJqzNIDeu6p6GTzT/801cw gWsg== X-Gm-Message-State: AOUpUlHZDlM7U6jnY+tErKK+8ABsDFtvAom9mp54sLm7oA8l0xK1uQWa 5/w9PCqcB5KsO4/uBISD1XAasu1sT1E= X-Google-Smtp-Source: AA+uWPxw3xLQpWMCNnz+g4+pAktrAokJeyU7+pqoXj+UhnQnlVihw07gZaeCs/eVQbMOn+aDfaMvGw== X-Received: by 2002:a19:9e8c:: with SMTP id h134-v6mr4380520lfe.63.1533905680990; Fri, 10 Aug 2018 05:54:40 -0700 (PDT) Received: from jax.urgonet (h-84-105.A175.priv.bahnhof.se. [79.136.84.105]) by smtp.gmail.com with ESMTPSA id v10-v6sm1574518ljg.12.2018.08.10.05.54.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 05:54:40 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Date: Fri, 10 Aug 2018 14:54:09 +0200 Message-Id: <20180810125410.19393-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180810125410.19393-1-jens.wiklander@linaro.org> References: <20180810125410.19393-1-jens.wiklander@linaro.org> Subject: [U-Boot] [PATCH 1/2] ofnode: add ofnode_by_prop_value() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Adds ofnode_by_prop_value() to search for nodes with a given property and value, an ofnode version of fdt_node_offset_by_prop_value(). Signed-off-by: Jens Wiklander --- drivers/core/of_access.c | 27 +++++++++++++++++++++++++++ drivers/core/ofnode.c | 14 ++++++++++++++ include/dm/of_access.h | 16 ++++++++++++++++ include/dm/ofnode.h | 14 ++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 0729dfcdb3b8..14c020a687b7 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -376,6 +376,33 @@ struct device_node *of_find_compatible_node(struct device_node *from, return np; } +static int of_device_has_prop_value(const struct device_node *device, + const char *propname, const void *propval, + int proplen) +{ + struct property *prop = of_find_property(device, propname, NULL); + + if (!prop || !prop->value || prop->length != proplen) + return 0; + return !memcmp(prop->value, propval, proplen); +} + +struct device_node *of_find_node_by_prop_value(struct device_node *from, + const char *propname, + const void *propval, int proplen) +{ + struct device_node *np; + + for_each_of_allnodes_from(from, np) { + if (of_device_has_prop_value(np, propname, propval, proplen) && + of_node_get(np)) + break; + } + of_node_put(from); + + return np; +} + struct device_node *of_find_node_by_phandle(phandle handle) { struct device_node *np; diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 0cfb0fbabb00..a7e192772324 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -777,3 +777,17 @@ ofnode ofnode_by_compatible(ofnode from, const char *compat) gd->fdt_blob, ofnode_to_offset(from), compat)); } } + +ofnode ofnode_by_prop_value(ofnode from, const char *propname, + const void *propval, int proplen) +{ + if (of_live_active()) { + return np_to_ofnode(of_find_node_by_prop_value( + (struct device_node *)ofnode_to_np(from), propname, + propval, proplen)); + } else { + return offset_to_ofnode(fdt_node_offset_by_prop_value( + gd->fdt_blob, ofnode_to_offset(from), + propname, propval, proplen)); + } +} diff --git a/include/dm/of_access.h b/include/dm/of_access.h index dd1abb8e97b4..5ed1a0cdb427 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -193,6 +193,22 @@ static inline struct device_node *of_find_node_by_path(const char *path) struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compatible); +/** + * of_find_node_by_prop_value() - find a node with a given property value + * + * Find a node based on a property value. + * @from: Node to start searching from or NULL. the node you pass will not be + * searched, only the next one will; typically, you pass what the previous + * call returned. + * @propname: property name to check + * @propval: property value to search for + * @proplen: length of the value in propval + * @return node pointer or NULL if not found + */ +struct device_node *of_find_node_by_prop_value(struct device_node *from, + const char *propname, + const void *propval, + int proplen); /** * of_find_node_by_phandle() - Find a node given a phandle * diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ab36b74c4ca4..c06d77849c73 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -702,6 +702,20 @@ int ofnode_read_resource_byname(ofnode node, const char *name, */ ofnode ofnode_by_compatible(ofnode from, const char *compat); +/** + * ofnode_by_prop_value() - Find the next node with given property value + * + * Find the next node after @from that has a @propname with a value + * @propval and a length @proplen. + * + * @from: ofnode to start from (use ofnode_null() to start at the + * beginning) @propname: property name to check @propval: property value to + * search for @proplen: length of the value in propval @return ofnode + * found, or ofnode_null() if none + */ +ofnode ofnode_by_prop_value(ofnode from, const char *propname, + const void *propval, int proplen); + /** * ofnode_for_each_subnode() - iterate over all subnodes of a parent * From patchwork Fri Aug 10 12:54:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 956243 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AlVf1LJx"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41n4qm20bXz9s4Z for ; Fri, 10 Aug 2018 22:56:04 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E16C5C21CB1; Fri, 10 Aug 2018 12:55:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0D22CC21D72; Fri, 10 Aug 2018 12:54:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 33C65C21DFF; Fri, 10 Aug 2018 12:54:46 +0000 (UTC) Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by lists.denx.de (Postfix) with ESMTPS id 455EAC21D8E for ; Fri, 10 Aug 2018 12:54:43 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id v22-v6so6497575lfe.8 for ; Fri, 10 Aug 2018 05:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/AQX6NrEhAw1DMugwgFqidqugiyEqYYJjecffR6I1No=; b=AlVf1LJxBh4KROGfjcdX5kFHWOdO2yayxQFhgiZSDQobtIpXED6agyZYOEUg1GG4Nk POjIy3lKkTZOGf5uXx9+ayvYbuO/XnUO0eF3WBZ6ee81qi9Hn70NjU754rQo4D9G8570 rJTUIyrF4LrdczwVGwLo7XTacQoNo6k/Ly/AE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/AQX6NrEhAw1DMugwgFqidqugiyEqYYJjecffR6I1No=; b=douu5mzyJTuwIugx+KcrW2yOyRTaIwxeWd66laS5mBKZoJy+PCthR6qe9qbIR3tdm1 3y+Int5a1Be+exDLBx2lcj2tGuIIVml/KtTryCgYw7mNCT7yd8a9Zvhb3oUhY0UjEHzn brUmCDpMzIIo6ga7+3Jf4BJEcdlmoC98VdNkjAsFmZRILtSEVg3WU6WGvU3GwsctUGMt h8bD5jyAEpm6+kDIji4J+bAgYgk2N0tP0M9yyM6vCl8eTlrewXrckpZfPyTqLfNUIhYI SkFeDbwqhT9q5r5rX6+FSm77ie3WZBxfn/wQrtfIRngeLp84jgd6fnCIUU8Etf1oRs/e ZlWQ== X-Gm-Message-State: AOUpUlHRJoDYSaKtHuvhx+HU4L/upDHYTPETZdYxA8FE1iRn73GScRjF zqF46wIfB6iO2RxMSD2uO6y6cqWgpao= X-Google-Smtp-Source: AA+uWPzhZ9wo8pB8zxOh0pln6lYUrLwv+GiwS6GF6eZnmaupKfunXGNSAqN9Kw8eZH4WZRpr6hdSsA== X-Received: by 2002:a19:4c57:: with SMTP id z84-v6mr4356519lfa.67.1533905682496; Fri, 10 Aug 2018 05:54:42 -0700 (PDT) Received: from jax.urgonet (h-84-105.A175.priv.bahnhof.se. [79.136.84.105]) by smtp.gmail.com with ESMTPSA id v10-v6sm1574518ljg.12.2018.08.10.05.54.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 05:54:41 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Date: Fri, 10 Aug 2018 14:54:10 +0200 Message-Id: <20180810125410.19393-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180810125410.19393-1-jens.wiklander@linaro.org> References: <20180810125410.19393-1-jens.wiklander@linaro.org> Subject: [U-Boot] [PATCH 2/2] fdt: fdtdec_setup_memory_banksize() use livetree X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Converts fdtdec_setup_memory_banksize() to use ofnode functions instead. Signed-off-by: Jens Wiklander Reviewed-by: Simon Glass --- lib/fdtdec.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index a208589c48ae..fef2f88f9d10 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -16,6 +16,7 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -1182,43 +1183,34 @@ int fdtdec_setup_mem_size_base(void) #if defined(CONFIG_NR_DRAM_BANKS) -static int get_next_memory_node(const void *blob, int startoffset) +static ofnode get_next_memory_node(ofnode mem) { - int mem = -1; - do { - mem = fdt_node_offset_by_prop_value(gd->fdt_blob, mem, - "device_type", "memory", 7); - } while (!fdtdec_get_is_enabled(blob, mem)); + mem = ofnode_by_prop_value(mem, "device_type", "memory", 7); + } while (ofnode_valid(mem) && !ofnode_is_available(mem)); return mem; } int fdtdec_setup_memory_banksize(void) { - int bank, ret, mem, reg = 0; - struct fdt_resource res; + int bank, reg = 0; + struct resource res; + ofnode mem; - mem = get_next_memory_node(gd->fdt_blob, -1); - if (mem < 0) { - debug("%s: Missing /memory node\n", __func__); - return -EINVAL; - } + mem = get_next_memory_node(ofnode_null()); + if (!ofnode_valid(mem)) + goto missing_node; for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); - if (ret == -FDT_ERR_NOTFOUND) { + while (ofnode_read_resource(mem, reg++, &res)) { reg = 0; - mem = get_next_memory_node(gd->fdt_blob, mem); - if (mem == -FDT_ERR_NOTFOUND) - break; - - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); - if (ret == -FDT_ERR_NOTFOUND) - break; - } - if (ret != 0) { - return -EINVAL; + mem = get_next_memory_node(mem); + if (!ofnode_valid(mem)) { + if (bank) + return 0; + goto missing_node; + } } gd->bd->bi_dram[bank].start = (phys_addr_t)res.start; @@ -1232,6 +1224,10 @@ int fdtdec_setup_memory_banksize(void) } return 0; + +missing_node: + debug("%s: Missing /memory node\n", __func__); + return -EINVAL; } #endif