Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2023, STMicroelectronics - All Rights Reserved |
| 4 | */ |
| 5 | |
| 6 | #define LOG_CATEGORY LOGC_ARCH |
| 7 | |
Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 8 | #include <clk.h> |
| 9 | #include <cpu_func.h> |
| 10 | #include <debug_uart.h> |
| 11 | #include <env_internal.h> |
| 12 | #include <init.h> |
| 13 | #include <misc.h> |
| 14 | #include <wdt.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/stm32.h> |
| 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/system.h> |
| 19 | #include <dm/device.h> |
| 20 | #include <dm/lists.h> |
| 21 | #include <dm/uclass.h> |
| 22 | |
| 23 | /* |
| 24 | * early TLB into the .data section so that it not get cleared |
| 25 | * with 16kB alignment |
| 26 | */ |
| 27 | #define EARLY_TLB_SIZE 0xA000 |
| 28 | u8 early_tlb[EARLY_TLB_SIZE] __section(".data") __aligned(0x4000); |
| 29 | |
| 30 | /* |
| 31 | * initialize the MMU and activate cache in U-Boot pre-reloc stage |
| 32 | * MMU/TLB is updated in enable_caches() for U-Boot after relocation |
| 33 | */ |
| 34 | static void early_enable_caches(void) |
| 35 | { |
| 36 | if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) |
| 37 | return; |
| 38 | |
| 39 | if (!(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))) { |
| 40 | gd->arch.tlb_size = EARLY_TLB_SIZE; |
| 41 | gd->arch.tlb_addr = (unsigned long)&early_tlb; |
| 42 | } |
| 43 | /* enable MMU (default configuration) */ |
| 44 | dcache_enable(); |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * Early system init |
| 49 | */ |
| 50 | int arch_cpu_init(void) |
| 51 | { |
| 52 | icache_enable(); |
| 53 | early_enable_caches(); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | void enable_caches(void) |
| 59 | { |
| 60 | /* deactivate the data cache, early enabled in arch_cpu_init() */ |
| 61 | dcache_disable(); |
| 62 | /* |
| 63 | * Force the call of setup_all_pgtables() in mmu_setup() by clearing tlb_fillptr |
| 64 | * to update the TLB location udpated in board_f.c::reserve_mmu |
| 65 | */ |
| 66 | gd->arch.tlb_fillptr = 0; |
| 67 | dcache_enable(); |
| 68 | } |
| 69 | |
| 70 | /* used when CONFIG_DISPLAY_CPUINFO is activated */ |
| 71 | int print_cpuinfo(void) |
| 72 | { |
| 73 | char name[SOC_NAME_SIZE]; |
| 74 | |
| 75 | get_soc_name(name); |
| 76 | printf("CPU: %s\n", name); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int arch_misc_init(void) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Force data-section, as .bss will not be valid |
| 88 | * when save_boot_params is invoked. |
| 89 | */ |
| 90 | static uintptr_t nt_fw_dtb __section(".data"); |
| 91 | |
| 92 | uintptr_t get_stm32mp_bl2_dtb(void) |
| 93 | { |
| 94 | return nt_fw_dtb; |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Save the FDT address provided by TF-A in r2 at boot time |
| 99 | * This function is called from start.S |
| 100 | */ |
| 101 | void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2, |
| 102 | unsigned long r3) |
| 103 | { |
| 104 | nt_fw_dtb = r2; |
| 105 | |
| 106 | save_boot_params_ret(); |
| 107 | } |