From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4138C54EE9 for ; Sun, 18 Sep 2022 11:23:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DC062848A1; Sun, 18 Sep 2022 13:23:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="LdWIMuhf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5E43849CD; Sun, 18 Sep 2022 13:23:52 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 771ED8456E for ; Sun, 18 Sep 2022 13:23:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6A543612A4; Sun, 18 Sep 2022 11:23:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB795C433D6; Sun, 18 Sep 2022 11:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663500227; bh=OLcGLkWsNBzvJVgWbEPxAA5UcJA7db8yFpu1YASaiw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LdWIMuhfcUwTlWfN7ez8GUY+7Zq9tFiEHPprxALlTAT9GKbX3s9GgbY80Pkn5LMkA /OCDqUhiDmek+8SBSuLh90eZJJAOfN7GWuxGINF7r5KNXHBwwZMwSVKRGaGxX9Vj2D y6LgxZUEfxWT4PqH07jnHl+NjivPM8IO4ar/ok4OeE3IKPZMDzETFI60aOrfypPL38 SGudwML/nyu/3fzxEj5SmCmin+qlpfr1hpNhBQMPXNAzq8afVOhSYbZngGk4dWGScD 4mxZjJBdRbrd/sFeRH6tXr4wdbdeTi96kTLciK+g9R8O+wLlS5sO6Dnz7YhQw6DB8x d/ab3fomEqUUg== Received: by pali.im (Postfix) id A007ECD5; Sun, 18 Sep 2022 13:23:44 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Simon Glass , Sean Anderson Cc: u-boot@lists.denx.de Subject: [PATCH v2] board_f: show_dram_config: Print also real DRAM size Date: Sun, 18 Sep 2022 13:23:27 +0200 Message-Id: <20220918112328.4570-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220911093942.9570-1-pali@kernel.org> References: <20220911093942.9570-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean 32-bit U-Boot builds cannot use more than around 2 GB of DDR memory. But on some platforms/boards it is possible to connect also 4 GB SODIMM DDR memory. U-Boot currently prints only effective size of RAM which can use, which may be misleading as somebody would expect that this line prints total size of connected DDR modules. So change show_dram_config code to prints both real and effective DRAM size if they are different. If they are same then print just one number like before. It is possible that effective size is just few bytes smaller than the real size, so print both numbers only in case function print_size() prints formats them differently. Signed-off-by: Pali Rohár --- Changes in v2: * Move calculation code into separate macro and add description of it --- common/board_f.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/common/board_f.c b/common/board_f.c index 9e34fbee147e..88a6dfff03fc 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -54,6 +54,7 @@ #include #include #include +#include /* * Pointer to initial global data area @@ -213,6 +214,36 @@ static int announce_dram_init(void) return 0; } +/* + * From input size calculate its nearest rounded unit scale (multiply of 2^10) + * and value in calculated unit scale multiplied by 10 (as fractional fixed + * point number with one decimal digit), which is human natural format, + * same what uses print_size() function for displaying. Mathematically it is: + * round_nearest(val * 2^scale) = size * 10; where: 10 <= val < 10240. + * + * For example for size=87654321 we calculate scale=20 and val=836 which means + * that input has natural human format 83.6 M (mega = 2^20). + */ +#define compute_size_scale_val(size, scale, val) do { \ + scale = ilog2(size) / 10 * 10; \ + val = (10 * size + ((1ULL << scale) >> 1)) >> scale; \ + if (val == 10240) { val = 10; scale += 10; } \ +} while (0) + +/* + * Check if the sizes in their natural units written in decimal format with + * one fraction number are same. + */ +static int sizes_near(unsigned long long size1, unsigned long long size2) +{ + unsigned int size1_scale, size1_val, size2_scale, size2_val; + + compute_size_scale_val(size1, size1_scale, size1_val); + compute_size_scale_val(size2, size2_scale, size2_val); + + return size1_scale == size2_scale && size1_val == size2_val; +} + static int show_dram_config(void) { unsigned long long size; @@ -229,7 +260,11 @@ static int show_dram_config(void) } debug("\nDRAM: "); - print_size(size, ""); + print_size(gd->ram_size, ""); + if (!sizes_near(gd->ram_size, size)) { + printf(" (effective "); + print_size(size, ")"); + } board_add_ram_info(0); putc('\n'); -- 2.20.1