Stefan Roese | 4c835a6 | 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 | |
| 6 | #include <common.h> |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 7 | #include <event.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Weijie Gao | 9bf72ba | 2020-11-12 16:35:33 +0800 | [diff] [blame] | 10 | #include <asm/addrspace.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Stefan Roese | 4c835a6 | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 13 | #include <linux/io.h> |
| 14 | #include <linux/sizes.h> |
Stefan Roese | 4c835a6 | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 15 | |
Weijie Gao | 02cd449 | 2020-04-21 09:28:34 +0200 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
Stefan Roese | 4c835a6 | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 17 | |
| 18 | int dram_init(void) |
| 19 | { |
Weijie Gao | 4bc0104 | 2022-05-20 11:22:21 +0800 | [diff] [blame] | 20 | gd->ram_size = get_ram_size((void *)KSEG1, CONFIG_MAX_MEM_SIZE << 20); |
Stefan Roese | 4c835a6 | 2018-09-05 15:12:35 +0200 | [diff] [blame] | 21 | |
| 22 | return 0; |
| 23 | } |
Stefan Roese | 9814fb2 | 2019-05-28 08:11:37 +0200 | [diff] [blame] | 24 | |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 25 | #ifndef CONFIG_SPL_BUILD |
| 26 | static int last_stage_init(void) |
Stefan Roese | 9814fb2 | 2019-05-28 08:11:37 +0200 | [diff] [blame] | 27 | { |
| 28 | void *src, *dst; |
| 29 | |
| 30 | src = malloc(SZ_64K); |
| 31 | dst = malloc(SZ_64K); |
| 32 | if (!src || !dst) { |
| 33 | printf("Can't allocate buffer for cache cleanup copy!\n"); |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * It has been noticed, that sometimes the d-cache is not in a |
| 39 | * "clean-state" when U-Boot is running on MT7688. This was |
| 40 | * detected when using the ethernet driver (which uses d-cache) |
| 41 | * and a TFTP command does not complete. Copying an area of 64KiB |
| 42 | * in DDR at a very late bootup time in U-Boot, directly before |
| 43 | * calling into the prompt, seems to fix this issue. |
| 44 | */ |
| 45 | memcpy(dst, src, SZ_64K); |
| 46 | free(src); |
| 47 | free(dst); |
| 48 | |
| 49 | return 0; |
| 50 | } |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 51 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |
| 52 | #endif |