From patchwork Mon Dec 12 07:14:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Rossi X-Patchwork-Id: 704936 X-Patchwork-Delegate: monstr@monstr.eu 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 3tcYyL5pszz9t6g for ; Mon, 12 Dec 2016 18:15:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nathanrossi.com header.i=@nathanrossi.com header.b="TC6Dqi+M"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4B025A75CC; Mon, 12 Dec 2016 08:15:21 +0100 (CET) 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 b_oshyXDSnwV; Mon, 12 Dec 2016 08:15:21 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CB41FA75B4; Mon, 12 Dec 2016 08:15:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2C5C5A75B4 for ; Mon, 12 Dec 2016 08:15:16 +0100 (CET) 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 SnOuw_03Mucx for ; Mon, 12 Dec 2016 08:15:16 +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-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by theia.denx.de (Postfix) with ESMTPS id 06790A75E6 for ; Mon, 12 Dec 2016 08:15:10 +0100 (CET) Received: by mail-pg0-f67.google.com with SMTP id 3so112356pgd.0 for ; Sun, 11 Dec 2016 23:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nathanrossi.com; s=google; h=from:mime-version:content-transfer-encoding:date:subject:message-id :in-reply-to:references:to:cc; bh=RF3zfYlhcZ+QqTXRCp0QY+MkowpoTOC3HoWjh4PIAuw=; b=TC6Dqi+MutxDmSvfDhEcVGnU+anF28821uH+evB5v4ysdVt+E7PNWT3yEOXSnt+QbT 3javJH/e9SzpzdbzY1pmm3NRK7WDg+RFFiWx9039cJvYdpd69W0ci6hg2FeQHyya1bhQ 1ajK9P+Fcq9UySi1yJjIBbPXLaqyHNktz2yBOpdfyO7Tutk9nukoinUrDbrr/0GVWAHt ab7oNNs8zWS9imV/W+tslXd9ItsBzpQoqB9IeVu+b+xCyXnHzww8MAVonzyVsqw/909+ i4M33jWm79r7RmHPJSFGtaqp03zGTLDhe8/IQABW480QCsH8w0qO6Rple5yi2WVd4uTS mk9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:mime-version:content-transfer-encoding:date :subject:message-id:in-reply-to:references:to:cc; bh=RF3zfYlhcZ+QqTXRCp0QY+MkowpoTOC3HoWjh4PIAuw=; b=TtPBPCxCpmRmB2cUReUasP0B7pzLnUsEc9Oo9aHysESnWir6a2xG736Ix7lM+d6Qa7 zXWhDPDBpt4pp97ACDNChz6gP68BN7R0zItGsGOmZXn8Xr6kbDrFqQg9CIr5Q4JhxzEl MYEYXYiUg+yBXwDlrTWXC6L/gFlBY/zG/obSO/gGd0FMmOKICVxf/9Wc8cKzaTyLpKX8 J2XWaa1hQIXa/A1dQb2cBEZkdz5Uj1xyy0kucT+/3cWwqhYySdwNIND+WYSbXuH1BSda 6wbrN44OJ+jY9rd9JQAzljrvl6IW4TSf5xoMWYcrRoWLHAdNmnjDN3XimbpiZAMKQg+Y Ww3w== X-Gm-Message-State: AKaTC03zY0g8H2ybTKELTI/nlojuWfiYxV/hNGPw+2Nvtp/WxWMwdjbup1T6Wpr1htofNg== X-Received: by 10.84.215.142 with SMTP id l14mr180022104pli.99.1481526908924; Sun, 11 Dec 2016 23:15:08 -0800 (PST) Received: from [127.0.1.1] (CPE-1-121-152-133.qwl9.woo.bigpond.net.au. [1.121.152.133]) by smtp.gmail.com with ESMTPSA id q20sm74298270pgn.39.2016.12.11.23.15.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Dec 2016 23:15:08 -0800 (PST) From: Nathan Rossi MIME-Version: 1.0 Date: Mon, 12 Dec 2016 17:14:54 +1000 Message-Id: <20161212071454.16659-1-nathan@nathanrossi.com> In-Reply-To: <20161212071454.16659-0-nathan@nathanrossi.com> References: <20161212071454.16659-0-nathan@nathanrossi.com> To: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 1/3] fdt: add memory bank decoding functions for board setup X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add two functions for use by board implementations to decode the memory banks of the /memory node so as to populate the global data with ram_size and board info for memory banks. The fdtdec_setup_memory_size() function decodes the first memory bank and sets up the gd->ram_size with the size of the memory bank. This function should be called from the boards dram_init(). The fdtdec_setup_memory_banksize() function decode the memory banks (up to the CONFIG_NR_DRAM_BANKS) and populates the base address and size into the gd->bd->bi_dram array of banks. This function should be called from the boards dram_init_banksize(). Signed-off-by: Nathan Rossi Cc: Simon Glass Cc: Michal Simek Reviewed-by: Simon Glass --- v2: * Make fdtdec_setup_memory_banksize() return value consistent * Add more detail into the function documentation This implementation of decoding has been tested on zynq and zynqmp boards with address/size cells of (1, 1), (1, 2), (2, 1), (2, 2) and up to 2 memory banks. --- include/fdtdec.h | 34 ++++++++++++++++++++++++++++++++++ lib/fdtdec.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/include/fdtdec.h b/include/fdtdec.h index 27887c8c21..d074478f14 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -976,6 +976,40 @@ struct display_timing { */ int fdtdec_decode_display_timing(const void *blob, int node, int index, struct display_timing *config); + +/** + * fdtdec_setup_memory_size() - decode and setup gd->ram_size + * + * Decode the /memory 'reg' property to determine the size of the first memory + * bank, populate the global data with the size of the first bank of memory. + * + * This function should be called from a boards dram_init(). This helper + * function allows for boards to query the device tree for DRAM size instead of + * hard coding the value in the case where the memory size cannot be detected + * automatically. + * + * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or + * invalid + */ +int fdtdec_setup_memory_size(void); + +/** + * fdtdec_setup_memory_banksize() - decode and populate gd->bd->bi_dram + * + * Decode the /memory 'reg' property to determine the address and size of the + * memory banks. Use this data to populate the global data board info with the + * phys address and size of memory banks. + * + * This function should be called from a boards dram_init_banksize(). This + * helper function allows for boards to query the device tree for memory bank + * information instead of hard coding the information in cases where it cannot + * be detected automatically. + * + * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or + * invalid + */ +int fdtdec_setup_memory_banksize(void); + /** * Set up the device tree ready for use */ diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 4e619c49a2..3bf9ff84f4 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1174,6 +1174,60 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index, return ret; } +int fdtdec_setup_memory_size(void) +{ + int ret, mem; + struct fdt_resource res; + + mem = fdt_path_offset(gd->fdt_blob, "/memory"); + if (mem < 0) { + debug("%s: Missing /memory node\n", __func__); + return -EINVAL; + } + + ret = fdt_get_resource(gd->fdt_blob, mem, "reg", 0, &res); + if (ret != 0) { + debug("%s: Unable to decode first memory bank\n", __func__); + return -EINVAL; + } + + gd->ram_size = (phys_size_t)(res.end - res.start + 1); + debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size); + + return 0; +} + +int fdtdec_setup_memory_banksize(void) +{ + int bank, ret, mem; + struct fdt_resource res; + + mem = fdt_path_offset(gd->fdt_blob, "/memory"); + if (mem < 0) { + debug("%s: Missing /memory node\n", __func__); + return -EINVAL; + } + + for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { + ret = fdt_get_resource(gd->fdt_blob, mem, "reg", bank, &res); + if (ret == -FDT_ERR_NOTFOUND) + break; + if (ret != 0) + return -EINVAL; + + gd->bd->bi_dram[bank].start = (phys_addr_t)res.start; + gd->bd->bi_dram[bank].size = + (phys_size_t)(res.end - res.start + 1); + + debug("%s: DRAM Bank #%d: start = 0x%llx, size = 0x%llx\n", + __func__, bank, + (unsigned long long)gd->bd->bi_dram[bank].start, + (unsigned long long)gd->bd->bi_dram[bank].size); + } + + return 0; +} + int fdtdec_setup(void) { #if CONFIG_IS_ENABLED(OF_CONTROL)