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 05FD4C433EF for ; Tue, 22 Feb 2022 01:34:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3926883CA1; Tue, 22 Feb 2022 02:33:25 +0100 (CET) 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="L7A/HuL3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB0C68382C; Tue, 22 Feb 2022 02:32:12 +0100 (CET) Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) (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 DF8DA83C84 for ; Tue, 22 Feb 2022 02:31:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pgwipeout@gmail.com Received: by mail-qv1-xf31.google.com with SMTP id n6so36927569qvk.13 for ; Mon, 21 Feb 2022 17:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F6glGblESVUZGtDqXuUuE7RA1PWIfeROpue7mg9WW5o=; b=L7A/HuL3AwdDY2iLuMkXdiCvhcJ1okjW/GRvkyCiwHp0vInqvTQ40r4VRe/5u48b6g e6HwVYYryiCsBMLm9GlGl2AxS5530RAG1YaAM86hkzGf1/B7xxHhkWIgxvIqCON8kUC0 sGmaCitoqeFnO07N+FiVs5rdZfAiWpvRG3HJW1pjoSduldx40i5cIKTYx+TVJW45L6zb rJjV59uGBptmPWsNuqflOS5DwnXRA4i21IXxPZvxWs4rUQL+jUxAyFaPuevgOiuqDLNi 5TKiEuibn3+O2NEdKdp3Y/PXFQK03Wyy7MmHJnAZBlBoX6R5ZxzgIP7itZvUTlAsoyPO 6Eiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F6glGblESVUZGtDqXuUuE7RA1PWIfeROpue7mg9WW5o=; b=eakgWpEicfpEwJExsjzBHpQVH2lqiuWUsxquG6jSLx6o7E5Vtb5pY1k6BIr3O9bh6e n8QTOAfOvNLa9nf+8MELcyPp73b3CstBoqdTrkkm1GLloKEqxOYRBNqo/u3FdSKQkQFs SDGQ1mSXL9Wby8+lBZ3jUMVVruQ/ff5dqtUILNMwW3+5Awl8VYfMEkPrjkYVDK+feL6S C3x4KzyOe75WWFCO/ohYrDDGfhGH6b7L+se6cUyB26vChn0eUzB5O1S5sQztSGO10MXu Byp151Lwacb6IM7+joTTadMRpJMAPojNiQaDi6q158u5keVrflwaVBLwYUlfVOffq1Iq keyA== X-Gm-Message-State: AOAM533Wngm6Q6hy7wZU406lAWS7Rxwr3LLltMTcx4mjU7HuC2LSNoZy w6IqBphxOYQ7+sPWHIn2ULQ= X-Google-Smtp-Source: ABdhPJxbivKqTXenHHf+nLQ4lZscH1wexEBnkCWvBDQJcVODZrFLXCP/2+EkoH1G+W+VEkO3OioFRA== X-Received: by 2002:a05:622a:138b:b0:2de:29bf:7a09 with SMTP id o11-20020a05622a138b00b002de29bf7a09mr6819230qtk.479.1645493502591; Mon, 21 Feb 2022 17:31:42 -0800 (PST) Received: from master-x64.sparksnet (c-98-233-193-225.hsd1.dc.comcast.net. [98.233.193.225]) by smtp.gmail.com with ESMTPSA id q12sm31597841qtx.51.2022.02.21.17.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 17:31:42 -0800 (PST) From: Peter Geis To: Simon Glass , Philipp Tomsich , Kever Yang Cc: Peter Geis , u-boot@lists.denx.de Subject: [PATCH v1 11/11] [RFC] rockchip: rk356x: attempt to fix ram detection Date: Mon, 21 Feb 2022 20:31:30 -0500 Message-Id: <20220222013131.3114990-12-pgwipeout@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220222013131.3114990-1-pgwipeout@gmail.com> References: <20220222013131.3114990-1-pgwipeout@gmail.com> MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean This patch attempts to fix ram detection on rk3568. Prior to this, the rk3568 incorrectly detected 8gb ram as 2gb. On top of this, the board panics when u-boot accesses ram above 4gb. Fix this by correcting ram detection in hopefully a backwards compatable way, and extend board_f.c to enforce an upper limit on the ram u-boot uses. This allows us to limit the ram u-boot accesses, while passing the correctly detected size to follow on software (eg linux). This has been tested on rk3566 2gb, 4gb, and 8gb configurations, as well as rk3399 4gb configurations. I do not have other configurations available, and I do not have the insights into rockchip ram handling to tell if this is the correct way to go about this. Signed-off-by: Peter Geis --- arch/arm/mach-rockchip/Kconfig | 1 + arch/arm/mach-rockchip/rk3568/rk3568.c | 29 ++++++++++++++++++++++++++ arch/arm/mach-rockchip/sdram.c | 19 +++++++++++------ common/board_f.c | 7 +++++++ include/configs/rk3568_common.h | 5 +++++ 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index 92f35309e4a6..58393cc623f8 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -264,6 +264,7 @@ config ROCKCHIP_RK3568 select SYSCON select BOARD_LATE_INIT imply ROCKCHIP_COMMON_BOARD + imply OF_SYSTEM_SETUP help The Rockchip RK3568 is a ARM-based SoC with quad-core Cortex-A55, including NEON and GPU, 512K L3 cache, Mali-G52 based graphics, diff --git a/arch/arm/mach-rockchip/rk3568/rk3568.c b/arch/arm/mach-rockchip/rk3568/rk3568.c index ef6bc67a88b0..8d2a59bc649d 100644 --- a/arch/arm/mach-rockchip/rk3568/rk3568.c +++ b/arch/arm/mach-rockchip/rk3568/rk3568.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -187,3 +188,31 @@ int board_usb_init(int index, enum usb_init_type init) #endif /* CONFIG_USB_DWC3_GADGET */ #endif /* CONFIG_USB_GADGET */ + +#ifdef CONFIG_OF_SYSTEM_SETUP +int ft_system_setup(void *blob, struct bd_info *bd) +{ + int ret; + int areas = 1; + u64 start[2], size[2]; + + /* Reserve the io address space. */ + if (gd->ram_top > SDRAM_UPPER_ADDR_MIN) { + start[0] = gd->bd->bi_dram[0].start; + size[0] = SDRAM_LOWER_ADDR_MAX - gd->bd->bi_dram[0].start; + + /* Add the upper 4GB address space */ + start[1] = SDRAM_UPPER_ADDR_MIN; + size[1] = gd->ram_top - SDRAM_UPPER_ADDR_MIN; + areas = 2; + + ret = fdt_set_usable_memory(blob, start, size, areas); + if (ret) { + printf("Cannot set usable memory\n"); + return ret; + } + } + + return 0; +}; +#endif diff --git a/arch/arm/mach-rockchip/sdram.c b/arch/arm/mach-rockchip/sdram.c index 705ec7ba6450..52974e6dc333 100644 --- a/arch/arm/mach-rockchip/sdram.c +++ b/arch/arm/mach-rockchip/sdram.c @@ -3,6 +3,8 @@ * Copyright (C) 2017 Rockchip Electronics Co., Ltd. */ +#define DEBUG + #include #include #include @@ -98,8 +100,7 @@ size_t rockchip_sdram_size(phys_addr_t reg) SYS_REG_COL_MASK); cs1_col = cs0_col; bk = 3 - ((sys_reg2 >> SYS_REG_BK_SHIFT(ch)) & SYS_REG_BK_MASK); - if ((sys_reg3 >> SYS_REG_VERSION_SHIFT & - SYS_REG_VERSION_MASK) == 0x2) { + if ((sys_reg3 >> SYS_REG_VERSION_SHIFT & SYS_REG_VERSION_MASK) >= 0x2) { cs1_col = 9 + (sys_reg3 >> SYS_REG_CS1_COL_SHIFT(ch) & SYS_REG_CS1_COL_MASK); if (((sys_reg3 >> SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) & @@ -136,7 +137,7 @@ size_t rockchip_sdram_size(phys_addr_t reg) SYS_REG_BW_MASK)); row_3_4 = sys_reg2 >> SYS_REG_ROW_3_4_SHIFT(ch) & SYS_REG_ROW_3_4_MASK; - if (dram_type == DDR4) { + if ((dram_type == DDR4) && (sys_reg3 >> SYS_REG_VERSION_SHIFT & SYS_REG_VERSION_MASK) != 0x3){ dbw = (sys_reg2 >> SYS_REG_DBW_SHIFT(ch)) & SYS_REG_DBW_MASK; bg = (dbw == 2) ? 2 : 1; @@ -176,9 +177,11 @@ size_t rockchip_sdram_size(phys_addr_t reg) * 2. update board_get_usable_ram_top() and dram_init_banksize() * to reserve memory for peripheral space after previous update. */ + +#ifndef __aarch64__ if (size_mb > (SDRAM_MAX_SIZE >> 20)) size_mb = (SDRAM_MAX_SIZE >> 20); - +#endif return (size_t)size_mb << 20; } @@ -208,6 +211,10 @@ int dram_init(void) ulong board_get_usable_ram_top(ulong total_size) { unsigned long top = CONFIG_SYS_SDRAM_BASE + SDRAM_MAX_SIZE; - - return (gd->ram_top > top) ? top : gd->ram_top; +#ifdef SDRAM_UPPER_ADDR_MIN + if (gd->ram_top > SDRAM_UPPER_ADDR_MIN) + return gd->ram_top; + else +#endif + return (gd->ram_top > top) ? top : gd->ram_top; } diff --git a/common/board_f.c b/common/board_f.c index a68760092ac1..933ba7aedac0 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -344,7 +344,14 @@ static int setup_dest_addr(void) #endif gd->ram_top = gd->ram_base + get_effective_memsize(); gd->ram_top = board_get_usable_ram_top(gd->mon_len); +#ifdef SDRAM_LOWER_ADDR_MAX + if (gd->ram_top > SDRAM_LOWER_ADDR_MAX) + gd->relocaddr = SDRAM_LOWER_ADDR_MAX; + else + gd->relocaddr = gd->ram_top; +#else gd->relocaddr = gd->ram_top; +#endif debug("Ram top: %08lX\n", (ulong)gd->ram_top); #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) /* diff --git a/include/configs/rk3568_common.h b/include/configs/rk3568_common.h index 25d7c5cc8fff..8dd1b033017b 100644 --- a/include/configs/rk3568_common.h +++ b/include/configs/rk3568_common.h @@ -27,6 +27,11 @@ #define CONFIG_SYS_SDRAM_BASE 0 #define SDRAM_MAX_SIZE 0xf0000000 +#ifdef CONFIG_OF_SYSTEM_SETUP +#define SDRAM_LOWER_ADDR_MAX 0xf0000000 +#define SDRAM_UPPER_ADDR_MIN 0x100000000 +#endif + #ifndef CONFIG_SPL_BUILD #define ENV_MEM_LAYOUT_SETTINGS \ "scriptaddr=0x00c00000\0" \ -- 2.25.1