xref: /optee_os/core/include/kernel/boot.h (revision 941a58d78c99c4754fbd4ec3079ec9e1d596af8f)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015-2025, Linaro Limited
4  * Copyright (c) 2021-2023, Arm Limited
5  */
6 #ifndef __KERNEL_BOOT_H
7 #define __KERNEL_BOOT_H
8 
9 #include <initcall.h>
10 #include <kernel/dt.h>
11 #include <types_ext.h>
12 
13 /*
14  * struct boot_embdata - Embedded boot data
15  * @total_len: Total length of the embedded boot data
16  * @num_blobs: Number of blobs in the embedded boot data, always 2 even if
17  *	       one blob is empty
18  * @hashes_offset: Offset of hashes from start of this struct
19  * @hashes_len: Length of hashes
20  * @reloc_offset: Offset of reloc from start of this struct
21  * @reloc_len: Length of reloc
22  *
23  * This struct is initialized by scripts/gen_tee_bin.py and must be kept
24  * in sync with that script. The struct and the following data is loaded
25  * at different addresses at boot depending on CFG_WITH_PAGER.
26  *
27  * If configured with CFG_WITH_PAGER=y the struct with data is following
28  * init part, this is together with the init part moved by the primary CPU
29  * so it ends up at __init_end. Whatever need to be saved for later need to
30  * be copied to a safe location in init_runtime().
31  *
32  * If configured with CFG_WITH_PAGER=n following the struct with data is
33  * __data_end, this is moved by the primary CPU so it ends up at __end.
34  */
35 struct boot_embdata {
36 	uint32_t total_len;
37 	uint32_t num_blobs;
38 	uint32_t hashes_offset;
39 	uint32_t hashes_len;
40 	uint32_t reloc_offset;
41 	uint32_t reloc_len;
42 };
43 
44 extern const struct core_mmu_config boot_mmu_config;
45 
46 void boot_init_primary_early(void);
47 void boot_init_primary_late(unsigned long fdt, unsigned long manifest);
48 void boot_init_primary_runtime(void);
49 void boot_init_primary_final(void);
50 void boot_init_memtag(void);
51 void boot_clear_memtag(void);
52 void boot_save_args(unsigned long a0, unsigned long a1, unsigned long a2,
53 		    unsigned long a3, unsigned long a4);
54 
55 void __panic_at_smc_return(void) __noreturn;
56 
57 #if defined(CFG_WITH_ARM_TRUSTED_FW)
58 unsigned long cpu_on_handler(unsigned long a0, unsigned long a1);
59 unsigned long boot_cpu_on_handler(unsigned long a0, unsigned long a1);
60 #else
61 void boot_init_secondary(unsigned long nsec_entry);
62 #endif
63 
64 void boot_primary_init_intc(void);
65 void boot_primary_init_core_ids(void);
66 void boot_secondary_init_intc(void);
67 
68 void init_sec_mon(unsigned long nsec_entry);
69 void init_tee_runtime(void);
70 
71 /* weak routines eventually overridden by platform */
72 void plat_cpu_reset_early(void);
73 void plat_primary_init_early(void);
74 unsigned long plat_get_aslr_seed(void);
75 unsigned long plat_get_freq(void);
76 #if defined(_CFG_CORE_STACK_PROTECTOR) || defined(CFG_WITH_STACK_CANARIES)
77 /*
78  * plat_get_random_stack_canaries() - Get random values for stack canaries.
79  * @buf:	Pointer to the buffer where to store canaries
80  * @ncan:	The number of canaries to generate.
81  * @size:	The size (in bytes) of each canary.
82  *
83  * This function has a __weak default implementation.
84  */
85 void plat_get_random_stack_canaries(void *buf, size_t ncan, size_t size);
86 #endif
87 void arm_cl2_config(vaddr_t pl310);
88 void arm_cl2_enable(vaddr_t pl310);
89 
90 #if defined(CFG_BOOT_SECONDARY_REQUEST)
91 void boot_set_core_ns_entry(size_t core_idx, uintptr_t entry,
92 			    uintptr_t context_id);
93 
94 int boot_core_release(size_t core_idx, paddr_t entry);
95 struct ns_entry_context *boot_core_hpen(void);
96 #endif
97 
98 /*
99  * get_aslr_seed() - return a random seed for core ASLR
100  *
101  * This function has a __weak default implementation.
102  */
103 unsigned long get_aslr_seed(void);
104 
105 /* Identify non-secure memory regions for dynamic shared memory */
106 void discover_nsec_memory(void);
107 /* Add reserved memory for static shared memory in the device-tree */
108 int mark_static_shm_as_reserved(struct dt_descriptor *dt);
109 
110 /*
111  * Stack-like memory allocations during boot before a heap has been
112  * configured. boot_mem_relocate() performs relocation of the boot memory
113  * and address cells registered with boot_mem_add_reloc() during virtual
114  * memory initialization. Unused memory is unmapped and released to pool of
115  * free physical memory once MMU is initialized.
116  */
117 void boot_mem_init(vaddr_t start, vaddr_t end, vaddr_t orig_end);
118 void boot_mem_init_asan(void);
119 void boot_mem_foreach_padding(bool (*func)(vaddr_t va, size_t len, void *ptr),
120 			      void *ptr);
121 void boot_mem_add_reloc(void *ptr);
122 void boot_mem_relocate(size_t offs);
123 void *boot_mem_alloc(size_t len, size_t align);
124 void *boot_mem_alloc_tmp(size_t len, size_t align);
125 vaddr_t boot_mem_release_unused(void);
126 void boot_mem_release_tmp_alloc(void);
127 
128 #endif /* __KERNEL_BOOT_H */
129