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 | |
Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 70 | int arch_misc_init(void) |
| 71 | { |
Patrice Chotard | 539fec3 | 2024-01-15 15:05:50 +0100 | [diff] [blame^] | 72 | setup_serial_number(); |
| 73 | |
Patrice Chotard | d29531c | 2023-10-27 16:43:04 +0200 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Force data-section, as .bss will not be valid |
| 79 | * when save_boot_params is invoked. |
| 80 | */ |
| 81 | static uintptr_t nt_fw_dtb __section(".data"); |
| 82 | |
| 83 | uintptr_t get_stm32mp_bl2_dtb(void) |
| 84 | { |
| 85 | return nt_fw_dtb; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Save the FDT address provided by TF-A in r2 at boot time |
| 90 | * This function is called from start.S |
| 91 | */ |
| 92 | void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2, |
| 93 | unsigned long r3) |
| 94 | { |
| 95 | nt_fw_dtb = r2; |
| 96 | |
| 97 | save_boot_params_ret(); |
| 98 | } |