xref: /optee_os/core/include/kernel/boot.h (revision a25cf4cf468d19f71f0679979aef4748ffeb4338)
170eacc45SMarouene Boubakri /* SPDX-License-Identifier: BSD-2-Clause */
270eacc45SMarouene Boubakri /*
3bd8bea6fSJens Wiklander  * Copyright (c) 2015-2025, 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 
44*a25cf4cfSAlistair Higgins extern unsigned long boot_arg_nsec_entry;
45*a25cf4cfSAlistair Higgins 
4670eacc45SMarouene Boubakri extern const struct core_mmu_config boot_mmu_config;
4770eacc45SMarouene Boubakri 
489c5eac75SJens Wiklander void boot_init_primary_early(void);
49330e04efSJens Wiklander void boot_init_primary_late(unsigned long fdt, unsigned long manifest);
50b0da0d59SJens Wiklander void boot_init_primary_runtime(void);
51faf09045SJens Wiklander void boot_init_primary_final(void);
52a0e8ffe9SJens Wiklander void boot_init_memtag(void);
53b2f99d20SOlivier Deprez void boot_clear_memtag(void);
54f332e77cSJens Wiklander void boot_save_args(unsigned long a0, unsigned long a1, unsigned long a2,
55f332e77cSJens Wiklander 		    unsigned long a3, unsigned long a4);
5670eacc45SMarouene Boubakri 
5770eacc45SMarouene Boubakri void __panic_at_smc_return(void) __noreturn;
5870eacc45SMarouene Boubakri 
5970eacc45SMarouene Boubakri #if defined(CFG_WITH_ARM_TRUSTED_FW)
6070eacc45SMarouene Boubakri unsigned long cpu_on_handler(unsigned long a0, unsigned long a1);
6170eacc45SMarouene Boubakri unsigned long boot_cpu_on_handler(unsigned long a0, unsigned long a1);
6270eacc45SMarouene Boubakri #else
6370eacc45SMarouene Boubakri void boot_init_secondary(unsigned long nsec_entry);
6470eacc45SMarouene Boubakri #endif
6570eacc45SMarouene Boubakri 
66df913c6dSAlvin Chang void boot_primary_init_intc(void);
672e27ec6cSYu-Chien Peter Lin void boot_primary_init_core_ids(void);
688aae4669SAlvin Chang void boot_secondary_init_intc(void);
6970eacc45SMarouene Boubakri 
7070eacc45SMarouene Boubakri void init_sec_mon(unsigned long nsec_entry);
7170eacc45SMarouene Boubakri void init_tee_runtime(void);
7270eacc45SMarouene Boubakri 
7370eacc45SMarouene Boubakri /* weak routines eventually overridden by platform */
7470eacc45SMarouene Boubakri void plat_cpu_reset_early(void);
7570eacc45SMarouene Boubakri void plat_primary_init_early(void);
7670eacc45SMarouene Boubakri unsigned long plat_get_aslr_seed(void);
7770eacc45SMarouene Boubakri unsigned long plat_get_freq(void);
78b89b3da2SVincent Chuang #if defined(_CFG_CORE_STACK_PROTECTOR) || defined(CFG_WITH_STACK_CANARIES)
79b89b3da2SVincent Chuang /*
80b89b3da2SVincent Chuang  * plat_get_random_stack_canaries() - Get random values for stack canaries.
81b89b3da2SVincent Chuang  * @buf:	Pointer to the buffer where to store canaries
82b89b3da2SVincent Chuang  * @ncan:	The number of canaries to generate.
83b89b3da2SVincent Chuang  * @size:	The size (in bytes) of each canary.
84b89b3da2SVincent Chuang  *
85b89b3da2SVincent Chuang  * This function has a __weak default implementation.
86b89b3da2SVincent Chuang  */
87b89b3da2SVincent Chuang void plat_get_random_stack_canaries(void *buf, size_t ncan, size_t size);
8845507d10SKhoa Hoang #endif
8970eacc45SMarouene Boubakri void arm_cl2_config(vaddr_t pl310);
9070eacc45SMarouene Boubakri void arm_cl2_enable(vaddr_t pl310);
9170eacc45SMarouene Boubakri 
9270eacc45SMarouene Boubakri #if defined(CFG_BOOT_SECONDARY_REQUEST)
9370eacc45SMarouene Boubakri void boot_set_core_ns_entry(size_t core_idx, uintptr_t entry,
9470eacc45SMarouene Boubakri 			    uintptr_t context_id);
9570eacc45SMarouene Boubakri 
9670eacc45SMarouene Boubakri int boot_core_release(size_t core_idx, paddr_t entry);
9770eacc45SMarouene Boubakri struct ns_entry_context *boot_core_hpen(void);
9870eacc45SMarouene Boubakri #endif
9970eacc45SMarouene Boubakri 
100839dadc2SJens Wiklander /*
101839dadc2SJens Wiklander  * get_aslr_seed() - return a random seed for core ASLR
102839dadc2SJens Wiklander  *
103839dadc2SJens Wiklander  * This function has a __weak default implementation.
104839dadc2SJens Wiklander  */
105720e8800SJens Wiklander unsigned long get_aslr_seed(void);
10670eacc45SMarouene Boubakri 
107910441c3SYu Chien Peter Lin /* Identify non-secure memory regions for dynamic shared memory */
108910441c3SYu Chien Peter Lin void discover_nsec_memory(void);
109910441c3SYu Chien Peter Lin /* Add reserved memory for static shared memory in the device-tree */
110910441c3SYu Chien Peter Lin int mark_static_shm_as_reserved(struct dt_descriptor *dt);
111910441c3SYu Chien Peter Lin 
112fe85eae5SJens Wiklander /*
113fe85eae5SJens Wiklander  * Stack-like memory allocations during boot before a heap has been
114fe85eae5SJens Wiklander  * configured. boot_mem_relocate() performs relocation of the boot memory
115fe85eae5SJens Wiklander  * and address cells registered with boot_mem_add_reloc() during virtual
116fe85eae5SJens Wiklander  * memory initialization. Unused memory is unmapped and released to pool of
117fe85eae5SJens Wiklander  * free physical memory once MMU is initialized.
118fe85eae5SJens Wiklander  */
119fe85eae5SJens Wiklander void boot_mem_init(vaddr_t start, vaddr_t end, vaddr_t orig_end);
120bd8bea6fSJens Wiklander void boot_mem_init_asan(void);
121c62a7972SJens Wiklander void boot_mem_foreach_padding(bool (*func)(vaddr_t va, size_t len, void *ptr),
122c62a7972SJens Wiklander 			      void *ptr);
123fe85eae5SJens Wiklander void boot_mem_add_reloc(void *ptr);
124fe85eae5SJens Wiklander void boot_mem_relocate(size_t offs);
125fe85eae5SJens Wiklander void *boot_mem_alloc(size_t len, size_t align);
126fe85eae5SJens Wiklander void *boot_mem_alloc_tmp(size_t len, size_t align);
127fe85eae5SJens Wiklander vaddr_t boot_mem_release_unused(void);
128fe85eae5SJens Wiklander void boot_mem_release_tmp_alloc(void);
129fe85eae5SJens Wiklander 
13070eacc45SMarouene Boubakri #endif /* __KERNEL_BOOT_H */
131