Stefan Roese | 65da15e | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2018 Stefan Roese <sr@denx.de> |
| 4 | */ |
| 5 | |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 6 | #include <event.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 8 | #include <malloc.h> |
developer | af2c754 | 2020-11-12 16:35:33 +0800 | [diff] [blame] | 9 | #include <asm/addrspace.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 11 | #include <linux/bitops.h> |
Stefan Roese | 65da15e | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 12 | #include <linux/io.h> |
| 13 | #include <linux/sizes.h> |
Stefan Roese | 65da15e | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 14 | |
developer | 29b37c5 | 2020-04-21 09:28:34 +0200 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
Stefan Roese | 65da15e | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 16 | |
| 17 | int dram_init(void) |
| 18 | { |
developer | 2fddd72 | 2022-05-20 11:22:21 +0800 | [diff] [blame] | 19 | gd->ram_size = get_ram_size((void *)KSEG1, CONFIG_MAX_MEM_SIZE << 20); |
Stefan Roese | 65da15e | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 20 | |
| 21 | return 0; |
| 22 | } |
Stefan Roese | 17679e4 | 2019-05-28 08:11:37 +0200 | [diff] [blame] | 23 | |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 24 | #ifndef CONFIG_SPL_BUILD |
| 25 | static int last_stage_init(void) |
Stefan Roese | 17679e4 | 2019-05-28 08:11:37 +0200 | [diff] [blame] | 26 | { |
| 27 | void *src, *dst; |
| 28 | |
| 29 | src = malloc(SZ_64K); |
| 30 | dst = malloc(SZ_64K); |
| 31 | if (!src || !dst) { |
| 32 | printf("Can't allocate buffer for cache cleanup copy!\n"); |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | /* |
| 37 | * It has been noticed, that sometimes the d-cache is not in a |
| 38 | * "clean-state" when U-Boot is running on MT7688. This was |
| 39 | * detected when using the ethernet driver (which uses d-cache) |
| 40 | * and a TFTP command does not complete. Copying an area of 64KiB |
| 41 | * in DDR at a very late bootup time in U-Boot, directly before |
| 42 | * calling into the prompt, seems to fix this issue. |
| 43 | */ |
| 44 | memcpy(dst, src, SZ_64K); |
| 45 | free(src); |
| 46 | free(dst); |
| 47 | |
| 48 | return 0; |
| 49 | } |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 50 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |
| 51 | #endif |