From patchwork Wed Dec 26 22:28:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 208227 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 7DC412C008A for ; Thu, 27 Dec 2012 09:29:43 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 44A2E4A0FE; Wed, 26 Dec 2012 23:29:42 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xA9VBmvkX8gS; Wed, 26 Dec 2012 23:29:41 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 41C944A0BB; Wed, 26 Dec 2012 23:29:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 02D254A0AF for ; Wed, 26 Dec 2012 23:29:05 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z7UYLB5KmHbd for ; Wed, 26 Dec 2012 23:29:04 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ye0-f202.google.com (mail-ye0-f202.google.com [209.85.213.202]) by theia.denx.de (Postfix) with ESMTPS id 10B244A058 for ; Wed, 26 Dec 2012 23:29:00 +0100 (CET) Received: by mail-ye0-f202.google.com with SMTP id r9so98183yen.5 for ; Wed, 26 Dec 2012 14:28:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=cvUC5n+hdkVcELYUQ6tguxV6FfY4CLVH9WUOZKbgms8=; b=EMw01UlPKbT8aXWwfgRvpngnLPRnTo9aBlIxcqD0ecDCujBmD5j8R2459tABabes7d 2XMh2amp52p5CXTaQ5PmfnIiIbd82esVFYx3BqnOXW4MIyByb1niDPHg71SVvqJE2vG2 LjA9RtsZmsjqapdEAGY9V1FgJvEFVgEfzOFc0zY1B64kfYgRbS4GJd7tUD8UtIE7bZcZ Hi8m8EJ6Xdi4O0QQ01ZOqHcYAsFNJrBVUA7Qi8QO1a9fcxram4OekjxdfNa5RK9J/t1R Yt1dnLy4f0wFacxBv6z45yFV5nqkR5KGSHD7PJ71Edc+Ek5TlPGw8dgFG0PcYecwnJ82 WfLw== X-Received: by 10.236.124.102 with SMTP id w66mr13289986yhh.38.1356560938053; Wed, 26 Dec 2012 14:28:58 -0800 (PST) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id i63si2381649yhk.5.2012.12.26.14.28.58 (version=TLSv1/SSLv3 cipher=AES128-SHA); Wed, 26 Dec 2012 14:28:58 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id 87E7D100047; Wed, 26 Dec 2012 14:28:57 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 466F9160C72; Wed, 26 Dec 2012 14:28:57 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Wed, 26 Dec 2012 14:28:20 -0800 Message-Id: <1356560913-2205-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1356560913-2205-1-git-send-email-sjg@chromium.org> References: <1356560913-2205-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQmJWbyT4obTQHRQ2p/m5Lq0BCtOTjUS3/5g8tCHMaqr2EqkY3FOMA8PjGcss4iTfiOUzRT8Wy1Y6kzxNQ54Q8qHUbklsFFbMDOTVYeR6saoVztkIKABg2cuT8s3jXbONfoXISSYJqU9T688wrQ1MOr4fyahVhvftUEHmVYa6m+JjVJX0eAcZJo2POhFlpZRzk4ceMh4 Cc: Graeme Russ , Tom Warren , Jerry Van Baren Subject: [U-Boot] [PATCH 02/15] fdt: Add fdtdec_get_addr_size() to read reg properties X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de It is common to have a "reg =
" property in the FDT. Add a function to handle this, similar to the existing fdtdec_get_addr(); Signed-off-by: Simon Glass --- include/fdtdec.h | 15 +++++++++++++++ lib/fdtdec.c | 26 +++++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/include/fdtdec.h b/include/fdtdec.h index 70d0e97..570d3ac 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -38,11 +38,13 @@ */ #ifdef CONFIG_PHYS_64BIT typedef u64 fdt_addr_t; +typedef u64 fdt_size_t; #define FDT_ADDR_T_NONE (-1ULL) #define fdt_addr_to_cpu(reg) be64_to_cpu(reg) #define fdt_size_to_cpu(reg) be64_to_cpu(reg) #else typedef u32 fdt_addr_t; +typedef u32 fdt_size_t; #define FDT_ADDR_T_NONE (-1U) #define fdt_addr_to_cpu(reg) be32_to_cpu(reg) #define fdt_size_to_cpu(reg) be32_to_cpu(reg) @@ -186,6 +188,19 @@ fdt_addr_t fdtdec_get_addr(const void *blob, int node, const char *prop_name); /** + * Look up an address property in a node and return it as an address. + * The property must hold one address with a length. This is only tested + * on 32-bit machines. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @return address, if found, or FDT_ADDR_T_NONE if not + */ +fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, + const char *prop_name, fdt_size_t *sizep); + +/** * Look up a 32-bit integer property in a node and return it. The property * must have at least 4 bytes of data. The value of the first cell is * returned. diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 6dba438..d0bc848 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -54,25 +54,41 @@ const char *fdtdec_get_compatible(enum fdt_compat_id id) return compat_names[id]; } -fdt_addr_t fdtdec_get_addr(const void *blob, int node, - const char *prop_name) +fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, + const char *prop_name, fdt_size_t *sizep) { const fdt_addr_t *cell; int len; debug("%s: %s: ", __func__, prop_name); cell = fdt_getprop(blob, node, prop_name, &len); - if (cell && (len == sizeof(fdt_addr_t) || + if (cell && ((!sizep && len == sizeof(fdt_addr_t)) || len == sizeof(fdt_addr_t) * 2)) { - fdt_addr_t addr = fdt_addr_to_cpu(*cell); - debug("%p\n", (void *)addr); + fdt_addr_t addr = fdt_addr_to_cpu(*cell); + if (sizep) { + const fdt_size_t *size; + + size = (fdt_size_t *)((char *)cell + + sizeof(fdt_addr_t)); + *sizep = fdt_size_to_cpu(*size); + debug("addr=%p, size=%p\n", (void *)addr, + (void *)*sizep); + } else { + debug("%p\n", (void *)addr); + } return addr; } debug("(not found)\n"); return FDT_ADDR_T_NONE; } +fdt_addr_t fdtdec_get_addr(const void *blob, int node, + const char *prop_name) +{ + return fdtdec_get_addr_size(blob, node, prop_name, NULL); +} + s32 fdtdec_get_int(const void *blob, int node, const char *prop_name, s32 default_val) {