]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
arm: mediatek: mt8188: fix gd->ram_top limit
authorDavid Lechner <dlechner@baylibre.com>
Thu, 19 Mar 2026 20:00:11 +0000 (15:00 -0500)
committerDavid Lechner <dlechner@baylibre.com>
Mon, 6 Apr 2026 23:39:10 +0000 (18:39 -0500)
Fix the implementation of the gd->ram_top limit for mt8188.

The intention of the comment about MMC/DMA is correct, but the
implementation was wrong. gd->mon_len is set to the code size of U-Boot,
so trying to set it to limit gd->ram_top does not make sense.

Instead, there is already a get_effective_memsize() weak function that
we can override to implement the required limit on the usable memory
size. This is used to set gd->ram_top in setup_dest_addr().

The comment about the extra SZ_1M needing to be reserved is not correct
as U-Boot already takes care of this (with the actual size of U-Boot) in
the various board_f functions, so it is removed.

This fixes DMA not working on MMC on mt8188.

Reviewed-by: Julien Stephan <jstephan@baylibre.com>
Tested-by: Julien Stephan <jstephan@baylibre.com>
Link: https://patch.msgid.link/20260319-mtk-init-fix-dram-v1-8-6171ec141f40@baylibre.com
Signed-off-by: David Lechner <dlechner@baylibre.com>
arch/arm/mach-mediatek/mt8188/init.c

index fc80bc92bd8a7855ba2591c3d642528cafca8fa6..a48a41f3b97493e7188f06dc6dea32b87ff926a3 100644 (file)
@@ -9,6 +9,7 @@
 #include <asm/global_data.h>
 #include <asm/system.h>
 #include <dm/uclass.h>
+#include <linux/kernel.h>
 #include <linux/sizes.h>
 #include <wdt.h>
 
@@ -16,23 +17,16 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init(void)
 {
-       int ret;
-
-       ret = fdtdec_setup_mem_size_base();
-       if (ret)
-               return ret;
+       return fdtdec_setup_mem_size_base();
+}
 
+phys_size_t get_effective_memsize(void)
+{
        /*
-        * Limit gd->ram_top not exceeding SZ_4G.  Some periphals like mmc
-        * requires DMA buffer allocated below SZ_4G.
-        *
-        * Note: SZ_1M is for adjusting gd->relocaddr, the reserved memory for
-        * u-boot itself.
+        * Limit gd->ram_top not exceeding SZ_4G. Because some peripherals like
+        * MMC requires DMA buffer allocated below SZ_4G.
         */
-       if (gd->ram_base + gd->ram_size >= SZ_4G)
-               gd->mon_len = (gd->ram_base + gd->ram_size + SZ_1M) - SZ_4G;
-
-       return 0;
+       return min(SZ_4G - gd->ram_base, gd->ram_size);
 }
 
 void reset_cpu(void)