170eacc45SMarouene Boubakri /* SPDX-License-Identifier: BSD-2-Clause */ 270eacc45SMarouene Boubakri /* 370eacc45SMarouene Boubakri * Copyright (c) 2015-2020, Linaro Limited 4809fa817SBalint Dobszay * Copyright (c) 2021-2023, Arm Limited 570eacc45SMarouene Boubakri */ 670eacc45SMarouene Boubakri #ifndef __KERNEL_BOOT_H 770eacc45SMarouene Boubakri #define __KERNEL_BOOT_H 870eacc45SMarouene Boubakri 970eacc45SMarouene Boubakri #include <initcall.h> 10910441c3SYu Chien Peter Lin #include <kernel/dt.h> 1170eacc45SMarouene Boubakri #include <types_ext.h> 1270eacc45SMarouene Boubakri 1370eacc45SMarouene Boubakri /* 1470eacc45SMarouene Boubakri * struct boot_embdata - Embedded boot data 1570eacc45SMarouene Boubakri * @total_len: Total length of the embedded boot data 1670eacc45SMarouene Boubakri * @num_blobs: Number of blobs in the embedded boot data, always 2 even if 1770eacc45SMarouene Boubakri * one blob is empty 1870eacc45SMarouene Boubakri * @hashes_offset: Offset of hashes from start of this struct 1970eacc45SMarouene Boubakri * @hashes_len: Length of hashes 2070eacc45SMarouene Boubakri * @reloc_offset: Offset of reloc from start of this struct 2170eacc45SMarouene Boubakri * @reloc_len: Length of reloc 2270eacc45SMarouene Boubakri * 2370eacc45SMarouene Boubakri * This struct is initialized by scripts/gen_tee_bin.py and must be kept 2470eacc45SMarouene Boubakri * in sync with that script. The struct and the following data is loaded 2570eacc45SMarouene Boubakri * at different addresses at boot depending on CFG_WITH_PAGER. 2670eacc45SMarouene Boubakri * 2770eacc45SMarouene Boubakri * If configured with CFG_WITH_PAGER=y the struct with data is following 2870eacc45SMarouene Boubakri * init part, this is together with the init part moved by the primary CPU 2970eacc45SMarouene Boubakri * so it ends up at __init_end. Whatever need to be saved for later need to 3070eacc45SMarouene Boubakri * be copied to a safe location in init_runtime(). 3170eacc45SMarouene Boubakri * 3270eacc45SMarouene Boubakri * If configured with CFG_WITH_PAGER=n following the struct with data is 3370eacc45SMarouene Boubakri * __data_end, this is moved by the primary CPU so it ends up at __end. 3470eacc45SMarouene Boubakri */ 3570eacc45SMarouene Boubakri struct boot_embdata { 3670eacc45SMarouene Boubakri uint32_t total_len; 3770eacc45SMarouene Boubakri uint32_t num_blobs; 3870eacc45SMarouene Boubakri uint32_t hashes_offset; 3970eacc45SMarouene Boubakri uint32_t hashes_len; 4070eacc45SMarouene Boubakri uint32_t reloc_offset; 4170eacc45SMarouene Boubakri uint32_t reloc_len; 4270eacc45SMarouene Boubakri }; 4370eacc45SMarouene Boubakri 4470eacc45SMarouene Boubakri extern const struct core_mmu_config boot_mmu_config; 4570eacc45SMarouene Boubakri 469c5eac75SJens Wiklander void boot_init_primary_early(void); 47330e04efSJens Wiklander void boot_init_primary_late(unsigned long fdt, unsigned long manifest); 48b0da0d59SJens Wiklander void boot_init_primary_runtime(void); 49faf09045SJens Wiklander void boot_init_primary_final(void); 50a0e8ffe9SJens Wiklander void boot_init_memtag(void); 51b2f99d20SOlivier Deprez void boot_clear_memtag(void); 52f332e77cSJens Wiklander void boot_save_args(unsigned long a0, unsigned long a1, unsigned long a2, 53f332e77cSJens Wiklander unsigned long a3, unsigned long a4); 5470eacc45SMarouene Boubakri 5570eacc45SMarouene Boubakri void __panic_at_smc_return(void) __noreturn; 5670eacc45SMarouene Boubakri 5770eacc45SMarouene Boubakri #if defined(CFG_WITH_ARM_TRUSTED_FW) 5870eacc45SMarouene Boubakri unsigned long cpu_on_handler(unsigned long a0, unsigned long a1); 5970eacc45SMarouene Boubakri unsigned long boot_cpu_on_handler(unsigned long a0, unsigned long a1); 6070eacc45SMarouene Boubakri #else 6170eacc45SMarouene Boubakri void boot_init_secondary(unsigned long nsec_entry); 6270eacc45SMarouene Boubakri #endif 6370eacc45SMarouene Boubakri 64df913c6dSAlvin Chang void boot_primary_init_intc(void); 65*2e27ec6cSYu-Chien Peter Lin void boot_primary_init_core_ids(void); 668aae4669SAlvin Chang void boot_secondary_init_intc(void); 6770eacc45SMarouene Boubakri 6870eacc45SMarouene Boubakri void init_sec_mon(unsigned long nsec_entry); 6970eacc45SMarouene Boubakri void init_tee_runtime(void); 7070eacc45SMarouene Boubakri 7170eacc45SMarouene Boubakri /* weak routines eventually overridden by platform */ 7270eacc45SMarouene Boubakri void plat_cpu_reset_early(void); 7370eacc45SMarouene Boubakri void plat_primary_init_early(void); 7470eacc45SMarouene Boubakri unsigned long plat_get_aslr_seed(void); 7570eacc45SMarouene Boubakri unsigned long plat_get_freq(void); 76b89b3da2SVincent Chuang #if defined(_CFG_CORE_STACK_PROTECTOR) || defined(CFG_WITH_STACK_CANARIES) 77b89b3da2SVincent Chuang /* 78b89b3da2SVincent Chuang * plat_get_random_stack_canaries() - Get random values for stack canaries. 79b89b3da2SVincent Chuang * @buf: Pointer to the buffer where to store canaries 80b89b3da2SVincent Chuang * @ncan: The number of canaries to generate. 81b89b3da2SVincent Chuang * @size: The size (in bytes) of each canary. 82b89b3da2SVincent Chuang * 83b89b3da2SVincent Chuang * This function has a __weak default implementation. 84b89b3da2SVincent Chuang */ 85b89b3da2SVincent Chuang void plat_get_random_stack_canaries(void *buf, size_t ncan, size_t size); 8645507d10SKhoa Hoang #endif 8770eacc45SMarouene Boubakri void arm_cl2_config(vaddr_t pl310); 8870eacc45SMarouene Boubakri void arm_cl2_enable(vaddr_t pl310); 8970eacc45SMarouene Boubakri 9070eacc45SMarouene Boubakri #if defined(CFG_BOOT_SECONDARY_REQUEST) 9170eacc45SMarouene Boubakri void boot_set_core_ns_entry(size_t core_idx, uintptr_t entry, 9270eacc45SMarouene Boubakri uintptr_t context_id); 9370eacc45SMarouene Boubakri 9470eacc45SMarouene Boubakri int boot_core_release(size_t core_idx, paddr_t entry); 9570eacc45SMarouene Boubakri struct ns_entry_context *boot_core_hpen(void); 9670eacc45SMarouene Boubakri #endif 9770eacc45SMarouene Boubakri 98839dadc2SJens Wiklander /* 99839dadc2SJens Wiklander * get_aslr_seed() - return a random seed for core ASLR 100839dadc2SJens Wiklander * 101839dadc2SJens Wiklander * This function has a __weak default implementation. 102839dadc2SJens Wiklander */ 103720e8800SJens Wiklander unsigned long get_aslr_seed(void); 10470eacc45SMarouene Boubakri 105910441c3SYu Chien Peter Lin /* Identify non-secure memory regions for dynamic shared memory */ 106910441c3SYu Chien Peter Lin void discover_nsec_memory(void); 107910441c3SYu Chien Peter Lin /* Add reserved memory for static shared memory in the device-tree */ 108910441c3SYu Chien Peter Lin int mark_static_shm_as_reserved(struct dt_descriptor *dt); 109910441c3SYu Chien Peter Lin 110fe85eae5SJens Wiklander /* 111fe85eae5SJens Wiklander * Stack-like memory allocations during boot before a heap has been 112fe85eae5SJens Wiklander * configured. boot_mem_relocate() performs relocation of the boot memory 113fe85eae5SJens Wiklander * and address cells registered with boot_mem_add_reloc() during virtual 114fe85eae5SJens Wiklander * memory initialization. Unused memory is unmapped and released to pool of 115fe85eae5SJens Wiklander * free physical memory once MMU is initialized. 116fe85eae5SJens Wiklander */ 117fe85eae5SJens Wiklander void boot_mem_init(vaddr_t start, vaddr_t end, vaddr_t orig_end); 118c62a7972SJens Wiklander void boot_mem_foreach_padding(bool (*func)(vaddr_t va, size_t len, void *ptr), 119c62a7972SJens Wiklander void *ptr); 120fe85eae5SJens Wiklander void boot_mem_add_reloc(void *ptr); 121fe85eae5SJens Wiklander void boot_mem_relocate(size_t offs); 122fe85eae5SJens Wiklander void *boot_mem_alloc(size_t len, size_t align); 123fe85eae5SJens Wiklander void *boot_mem_alloc_tmp(size_t len, size_t align); 124fe85eae5SJens Wiklander vaddr_t boot_mem_release_unused(void); 125fe85eae5SJens Wiklander void boot_mem_release_tmp_alloc(void); 126fe85eae5SJens Wiklander 12770eacc45SMarouene Boubakri #endif /* __KERNEL_BOOT_H */ 128