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 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 28u8 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 */ 34static 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 */ 50int arch_cpu_init(void) 51{ 52 icache_enable(); 53 early_enable_caches(); 54 55 return 0; 56} 57 58void 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 70int arch_misc_init(void) 71{ 72 setup_serial_number(); 73 setup_mac_address(); 74 75 return 0; 76} 77 78/* 79 * Force data-section, as .bss will not be valid 80 * when save_boot_params is invoked. 81 */ 82static uintptr_t nt_fw_dtb __section(".data"); 83 84uintptr_t get_stm32mp_bl2_dtb(void) 85{ 86 return nt_fw_dtb; 87} 88 89/* 90 * Save the FDT address provided by TF-A in r2 at boot time 91 * This function is called from start.S 92 */ 93void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2, 94 unsigned long r3) 95{ 96 nt_fw_dtb = r2; 97 98 save_boot_params_ret(); 99} 100