From patchwork Fri Oct 26 02:31:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 194347 X-Patchwork-Delegate: vanbaren@cideas.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 6051E2C008E for ; Fri, 26 Oct 2012 13:35:13 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 36E5A4A6A8; Fri, 26 Oct 2012 04:34:08 +0200 (CEST) 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 0-lMJOWPM4QH; Fri, 26 Oct 2012 04:34:07 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C361B4A530; Fri, 26 Oct 2012 04:32:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 01DF34A479 for ; Fri, 26 Oct 2012 04:31:39 +0200 (CEST) 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 qKzQOTlQ52Qv for ; Fri, 26 Oct 2012 04:31:37 +0200 (CEST) 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-we0-f202.google.com (mail-we0-f202.google.com [74.125.82.202]) by theia.denx.de (Postfix) with ESMTPS id 77ACD4A45E for ; Fri, 26 Oct 2012 04:31:25 +0200 (CEST) Received: by mail-we0-f202.google.com with SMTP id x43so146526wey.3 for ; Thu, 25 Oct 2012 19:31:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=WCZo33EMHSeXlTyHlwtQv3qkN1LQaoZrZcsvYFxc9No=; b=giqxurzo0dL0C8p8pXrtbA1z1Q+U4Lphnq6gu7P6vn6it1tUtO6qReJrkq8mJfqKz9 wXxxIQ6AFaVuwcsKQJzGADvFGUjTJngjFXpxcP64DpTbo7u7QLxWmylo02n/+cEcKCgy ZqqAdx+LqGETjSsT451GIGcnbgxcC36+kwqaDVl4yfE91OvKZiH6IjNTVC8nAc/czczq 2tlc+baRkfh2QoA0g+1Brj1y3g9Ecm9Ac9RZXOTo1p7H3w6XKhUOuTzgqfKQfy+lfeZi ccgcmwetXuwCmVwU0tuaohFL3D2xjn3eR2spgc0IiPENEL0RqjyP9Zr6BewZ3WiwTv0N 9NGQ== Received: by 10.216.193.131 with SMTP id k3mr1272188wen.4.1351218682543; Thu, 25 Oct 2012 19:31:22 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id z7si708171wiw.1.2012.10.25.19.31.22 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 25 Oct 2012 19:31:22 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id 275C920004E; Thu, 25 Oct 2012 19:31:22 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 7C83616159F; Thu, 25 Oct 2012 19:31:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 25 Oct 2012 19:31:00 -0700 Message-Id: <1351218671-15228-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1351218671-15228-1-git-send-email-sjg@chromium.org> References: <1351218671-15228-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlLYletOAhZp2H0LcRxDJ5vPul3D3JGc3yQC2anb5HmTYOkln8xcRp5gC+++taXs+XrhL1qeP6cvdgyDbJjWSyq54YPGQPWCvFLCNtcdCUjA5kE0nyIA8c76T6nwg55qHFUapwNGppsipIUfg1ncq0fSoFoUt8xaGJzHJpUdO/L/QNIXZflgkA57a7GuGjnE9PMP2m3 Cc: Tom Rini , Jerry Van Baren , Devicetree Discuss Subject: [U-Boot] [PATCH 03/14] fdt: Add fdtdec_decode_region() to decode memory region 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 A memory region has a start and a size and is often specified in a node by a 'reg' property. Add a function to decode this information from the fdt. Signed-off-by: Simon Glass --- include/fdtdec.h | 19 +++++++++++++++++++ lib/fdtdec.c | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/include/fdtdec.h b/include/fdtdec.h index e828662..341e6a1 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -40,10 +40,12 @@ typedef u64 fdt_addr_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; #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) #endif /* Information obtained about memory from the FDT */ @@ -408,4 +410,21 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, */ const u8 *fdtdec_locate_byte_array(const void *blob, int node, const char *prop_name, int count); + +/** + * Look up a property in a node which contains a memory region address and + * size. Then return a pointer to this 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 + * @param ptrp returns pointer to region, or NULL if no address + * @param size returns size of region + * @return 0 if ok, -1 on error (propery not found) + */ +int fdtdec_decode_region(const void *blob, int node, + const char *prop_name, void **ptrp, size_t *size); #endif diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 2d60c8a..5570972 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -542,3 +542,20 @@ char *fdtdec_get_config_string(const void *blob, const char *prop_name) return (char *)nodep; } + +int fdtdec_decode_region(const void *blob, int node, + const char *prop_name, void **ptrp, size_t *size) +{ + const fdt_addr_t *cell; + int len; + + debug("%s: %s\n", __func__, prop_name); + cell = fdt_getprop(blob, node, prop_name, &len); + if (!cell || (len != sizeof(fdt_addr_t) * 2)) + return -1; + + *ptrp = (void *)fdt_addr_to_cpu(*cell); + *size = fdt_size_to_cpu(cell[1]); + debug("%s: size=%zx\n", __func__, *size); + return 0; +}