From patchwork Tue Mar 19 14:58:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 229088 X-Patchwork-Delegate: trini@ti.com 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 CAA5D2C00B8 for ; Wed, 20 Mar 2013 02:00:11 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BC5E44A03C; Tue, 19 Mar 2013 16:00:08 +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 24ZBsrJCRWry; Tue, 19 Mar 2013 16:00:08 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DBAF64A033; Tue, 19 Mar 2013 16:00:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 536D34A033 for ; Tue, 19 Mar 2013 16:00:01 +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 eGdfE4Q1fTfq for ; Tue, 19 Mar 2013 15:59:58 +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-vb0-f74.google.com (mail-vb0-f74.google.com [209.85.212.74]) by theia.denx.de (Postfix) with ESMTPS id 3C5E64A032 for ; Tue, 19 Mar 2013 15:59:55 +0100 (CET) Received: by mail-vb0-f74.google.com with SMTP id r6so50752vbi.1 for ; Tue, 19 Mar 2013 07:59:50 -0700 (PDT) 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 :x-gm-message-state; bh=cll6rRz46eaHO0axw1PPqilCmZvEqVbJOBHxloSsqns=; b=fKaij8X6US2dj18+meBhtxRMIPFbrz02smj8/gNJDXQCSZOSr30ZVrxU6dZMdXgG4H 8P0PYTzZid05gXCAQnH2RiLyNUHgiqzE47oq5sqA/Ulqd3d4rtEeed7RuUGTm8lz8EQ9 8InSDpabUPD6cx1zyDhyY409OETCMx+YFUliUye6/fnnZnak7WclNra8iKoSLCXY2rG9 5lOjWsiZeaNUsbjJQ5KzXq1awhn2NQVryDNRz5NnPHK/kCLxpWH4Grm1eXo6Y/TuG76G dy+kHOqtCzU/FN1FaEw8TPYQ6yQjvbyah/eLA4NIpxuI92cF4lEaZkgdgSrrB243cfmw QUZQ== X-Received: by 10.224.131.193 with SMTP id y1mr1392031qas.8.1363705190576; Tue, 19 Mar 2013 07:59:50 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id x1si1144125qci.2.2013.03.19.07.59.50 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Tue, 19 Mar 2013 07:59:50 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 4530431C307; Tue, 19 Mar 2013 07:59:50 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id D9A22160623; Tue, 19 Mar 2013 07:59:49 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 19 Mar 2013 07:58:51 -0700 Message-Id: <1363705145-27651-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.1.3 X-Gm-Message-State: ALoCoQkTe1t0zd5SEek+Fbc/X0PbBrjRorseNvQtmt09CMQHvDgrh7j3TjgVOqKox3+MisSokEbo/7oKMbkWF9a8iR5gK0OUIV+pCZsxBUv5DY3XUfEG1V/HFIAoRFBsTJEnfbGrHa9w+/naVLho8/IjyxblHAmUgNb/hE31CVaPL7vYvKbN3VjBrnDNZLX5SABnCDKgjikt Cc: u-boot-review@google.com, Graeme Russ , Jerry Van Baren , Tom Warren Subject: [U-Boot] [PATCH v3 01/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 --- Changes in v3: - Fix new checkpatch check Changes in v2: None include/fdtdec.h | 15 +++++++++++++++ lib/fdtdec.c | 27 +++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/fdtdec.h b/include/fdtdec.h index 2189483..5ca84a0 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) @@ -200,6 +202,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 43f29f5..cffba94 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -68,25 +68,40 @@ 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) || - len == sizeof(fdt_addr_t) * 2)) { + 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); + 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) {