Yanhong Wang | e28ec34 | 2023-03-29 11:42:08 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2022 StarFive Technology Co., Ltd. |
| 4 | * Author: Yanhong Wang<yanhong.wang@starfivetech.com> |
| 5 | */ |
| 6 | |
| 7 | #include <asm/csr.h> |
| 8 | #include <asm/sections.h> |
| 9 | #include <dm.h> |
| 10 | #include <log.h> |
| 11 | |
| 12 | #define CSR_U74_FEATURE_DISABLE 0x7c1 |
| 13 | #define L2_LIM_MEM_END 0x81FFFFFUL |
| 14 | |
| 15 | int spl_soc_init(void) |
| 16 | { |
| 17 | int ret; |
| 18 | struct udevice *dev; |
| 19 | |
| 20 | /* DDR init */ |
| 21 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 22 | if (ret) { |
| 23 | debug("DRAM init failed: %d\n", ret); |
| 24 | return ret; |
| 25 | } |
| 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | void harts_early_init(void) |
| 31 | { |
| 32 | ulong *ptr; |
| 33 | u8 *tmp; |
| 34 | ulong len, remain; |
| 35 | /* |
| 36 | * Feature Disable CSR |
| 37 | * |
| 38 | * Clear feature disable CSR to '0' to turn on all features for |
| 39 | * each core. This operation must be in M-mode. |
| 40 | */ |
| 41 | if (CONFIG_IS_ENABLED(RISCV_MMODE)) |
| 42 | csr_write(CSR_U74_FEATURE_DISABLE, 0); |
| 43 | |
| 44 | /* clear L2 LIM memory |
| 45 | * set __bss_end to 0x81FFFFF region to zero |
| 46 | * The L2 Cache Controller supports ECC. ECC is applied to SRAM. |
| 47 | * If it is not cleared, the ECC part is invalid, and an ECC error |
| 48 | * will be reported when reading data. |
| 49 | */ |
| 50 | ptr = (ulong *)&__bss_end; |
| 51 | len = L2_LIM_MEM_END - (ulong)&__bss_end; |
| 52 | remain = len % sizeof(ulong); |
| 53 | len /= sizeof(ulong); |
| 54 | |
| 55 | while (len--) |
| 56 | *ptr++ = 0; |
| 57 | |
| 58 | /* clear the remain bytes */ |
| 59 | if (remain) { |
| 60 | tmp = (u8 *)ptr; |
| 61 | while (remain--) |
| 62 | *tmp++ = 0; |
| 63 | } |
| 64 | } |