From patchwork Thu Jul 16 03:23:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1329961 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=pN4iGvtA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B6fjW0d9Pz9sRN for ; Thu, 16 Jul 2020 13:23:40 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 078CB81BA3; Thu, 16 Jul 2020 05:23:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pN4iGvtA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ED7FE81B7D; Thu, 16 Jul 2020 05:23:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5BA6D81B7D for ; Thu, 16 Jul 2020 05:23:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bmeng.cn@gmail.com Received: by mail-ej1-x641.google.com with SMTP id br7so4931966ejb.5 for ; Wed, 15 Jul 2020 20:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rX+mLDQ3rwTLg684tjM7YJR0RNEygdZJWr70x+s0j/0=; b=pN4iGvtAKZUy8aTZWMLNvyC4/S6+YaRORIMkAU0iV4hsj4Pd5nHRCAsU1Zxo33JdPC g/lcLCIN4Vc+zSxC08lhSwcs7lyppefY0Q9hiHD1B9yUGM8c1zYQ3jMp0S0j/aMm1lRs 317sjkqny3hJkCT00HfnVXWSgfmsd90kIjHWZL07JGmJmDxeJgVqVDYk+Xv86lXToQEJ 9LcahigvBBFrbwdgFUWBW0w2fIq57NHEtBBJ+f3H6xJFVjYGuGLcwX5MUgRWgqk/XJgC hE63L3pgNfn2+NRFjXoVD7V2pL4lnaTFITRc4KMsUAQTwa8cpvPycKZ9f+hXODBIlSG6 6b6Q== 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; bh=rX+mLDQ3rwTLg684tjM7YJR0RNEygdZJWr70x+s0j/0=; b=SA2RBvLCku6JkNsm2EnHLXch+BmwwZaM+2H7cfLin/Jh2kOjLHUawrMYhPr0DZxKQc tccvLc82AJQoGW4vwBp1kSh19nIE31PTs5IeQP8qtnLDCRHCt3GwIC17Nvf2zCBx4jiZ QNwtQlpdHHKoiNmdRbLfXKKc8FwgCqdArRXb9yMhvXe/EugWNFqpXbD8xaZVEc3Ww+P6 FQFOfnimDe8DXLiN7MoGfNzTMN84lxmDfUJAEXH1Ex9k8NpfphSF2BgTHbvKB+mGCT3d PokFjUZ+MhbDj9bjo0bujSVAYENT2sTKXeCThq30nlrSIJfHMln28+uswBn5NFvBPY1c PC+Q== X-Gm-Message-State: AOAM530JnZv+IMnKzBkr3tnIrF6JLdVDIHPlnckE/Fm9lefcUw96EYDF JpZ963XTPxISYcHvJ+xcIXU= X-Google-Smtp-Source: ABdhPJy92SXK4ne4yKloWzQRGChMspx11tJWxqA48RaCJs7BwA1Qg+hNRQUgRPuBZHPaOF6OvImFvw== X-Received: by 2002:a17:906:3282:: with SMTP id 2mr693570ejw.11.1594869799982; Wed, 15 Jul 2020 20:23:19 -0700 (PDT) Received: from localhost.localdomain (unknown-224-80.windriver.com. [147.11.224.80]) by smtp.gmail.com with ESMTPSA id h10sm3886710eds.0.2020.07.15.20.23.18 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 15 Jul 2020 20:23:19 -0700 (PDT) From: Bin Meng To: Rick Chen , Pragnesh Patel , Sagar Kadam , U-Boot Mailing List Cc: Bin Meng Subject: [PATCH 1/4] fdtdec: Add fdtdec_get_mem_size_base() Date: Wed, 15 Jul 2020 20:23:00 -0700 Message-Id: <1594869783-20189-1-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Bin Meng This adds a new API fdtdec_get_mem_size_base() that does similar thing to fdtdec_setup_mem_size_base_fdt(), but without assigning gd->ram_size and gd->ram_base. Signed-off-by: Bin Meng --- include/fdtdec.h | 22 ++++++++++++++++++++++ lib/fdtdec.c | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/fdtdec.h b/include/fdtdec.h index abd6d42..460d57a 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -909,6 +909,28 @@ int fdtdec_decode_display_timing(const void *blob, int node, int index, struct display_timing *config); /** + * fdtdec_get_mem_size_base() - decode FDT to get ram size and base + * + * Decode the /memory 'reg' property to determine the size and start of the + * first memory bank, populate the global data with the size and start 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 and start + * address instead of hard coding the value in the case where the memory size + * and start address cannot be detected automatically. + * + * @param blob FDT blob + * @param ram_size buffer to hold the ram size to set + * @param ram_base buffer to hold the ram base to set + * + * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or + * invalid + */ +int fdtdec_get_mem_size_base(const void *blob, + phys_size_t *ram_size, unsigned long *ram_base); + +/** * fdtdec_setup_mem_size_base_fdt() - decode and setup gd->ram_size and * gd->ram_start * diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 0dd7ff1..078ff7a 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1030,6 +1030,30 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index, return ret; } +int fdtdec_get_mem_size_base(const void *blob, + phys_size_t *ram_size, unsigned long *ram_base) +{ + int ret, mem; + struct fdt_resource res; + + mem = fdt_path_offset(blob, "/memory"); + if (mem < 0) { + debug("%s: Missing /memory node\n", __func__); + return -EINVAL; + } + + ret = fdt_get_resource(blob, mem, "reg", 0, &res); + if (ret != 0) { + debug("%s: Unable to decode first memory bank\n", __func__); + return -EINVAL; + } + + *ram_size = (phys_size_t)(res.end - res.start + 1); + *ram_base = (unsigned long)res.start; + + return 0; +} + int fdtdec_setup_mem_size_base_fdt(const void *blob) { int ret, mem;