xref: /optee_os/core/include/kernel/boot.h (revision bc12b0e95e3c63f46850c1e69c79cd6879c68543)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015-2020, 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 <types_ext.h>
11 
12 /*
13  * struct boot_embdata - Embedded boot data
14  * @total_len: Total length of the embedded boot data
15  * @num_blobs: Number of blobs in the embedded boot data, always 2 even if
16  *	       one blob is empty
17  * @hashes_offset: Offset of hashes from start of this struct
18  * @hashes_len: Length of hashes
19  * @reloc_offset: Offset of reloc from start of this struct
20  * @reloc_len: Length of reloc
21  *
22  * This struct is initialized by scripts/gen_tee_bin.py and must be kept
23  * in sync with that script. The struct and the following data is loaded
24  * at different addresses at boot depending on CFG_WITH_PAGER.
25  *
26  * If configured with CFG_WITH_PAGER=y the struct with data is following
27  * init part, this is together with the init part moved by the primary CPU
28  * so it ends up at __init_end. Whatever need to be saved for later need to
29  * be copied to a safe location in init_runtime().
30  *
31  * If configured with CFG_WITH_PAGER=n following the struct with data is
32  * __data_end, this is moved by the primary CPU so it ends up at __end.
33  */
34 struct boot_embdata {
35 	uint32_t total_len;
36 	uint32_t num_blobs;
37 	uint32_t hashes_offset;
38 	uint32_t hashes_len;
39 	uint32_t reloc_offset;
40 	uint32_t reloc_len;
41 };
42 
43 extern uint8_t embedded_secure_dtb[];
44 extern const struct core_mmu_config boot_mmu_config;
45 
46 /* @nsec_entry is unused if using CFG_WITH_ARM_TRUSTED_FW */
47 void boot_init_primary_early(unsigned long pageable_part,
48 			     unsigned long nsec_entry);
49 void boot_init_primary_late(unsigned long fdt, unsigned long tos_fw_config);
50 void boot_init_memtag(void);
51 void boot_save_boot_info(void *boot_info);
52 
53 void __panic_at_smc_return(void) __noreturn;
54 
55 #if defined(CFG_WITH_ARM_TRUSTED_FW)
56 unsigned long cpu_on_handler(unsigned long a0, unsigned long a1);
57 unsigned long boot_cpu_on_handler(unsigned long a0, unsigned long a1);
58 #else
59 void boot_init_secondary(unsigned long nsec_entry);
60 #endif
61 
62 void main_init_gic(void);
63 void main_secondary_init_gic(void);
64 
65 void init_sec_mon(unsigned long nsec_entry);
66 void init_tee_runtime(void);
67 
68 /* weak routines eventually overridden by platform */
69 void plat_cpu_reset_early(void);
70 void plat_primary_init_early(void);
71 unsigned long plat_get_aslr_seed(void);
72 unsigned long plat_get_freq(void);
73 #if defined(_CFG_CORE_STACK_PROTECTOR) || defined(CFG_WITH_STACK_CANARIES)
74 /*
75  * plat_get_random_stack_canaries() - Get random values for stack canaries.
76  * @buf:	Pointer to the buffer where to store canaries
77  * @ncan:	The number of canaries to generate.
78  * @size:	The size (in bytes) of each canary.
79  *
80  * This function has a __weak default implementation.
81  */
82 void plat_get_random_stack_canaries(void *buf, size_t ncan, size_t size);
83 #endif
84 void arm_cl2_config(vaddr_t pl310);
85 void arm_cl2_enable(vaddr_t pl310);
86 
87 #if defined(CFG_BOOT_SECONDARY_REQUEST)
88 void boot_set_core_ns_entry(size_t core_idx, uintptr_t entry,
89 			    uintptr_t context_id);
90 
91 int boot_core_release(size_t core_idx, paddr_t entry);
92 struct ns_entry_context *boot_core_hpen(void);
93 #endif
94 
95 /* Returns embedded DTB if present, then external DTB if found, then NULL */
96 void *get_dt(void);
97 
98 /*
99  * get_secure_dt() - returns secure DTB for drivers
100  *
101  * Returns device tree that is considered secure for drivers to use.
102  *
103  * 1. Returns embedded DTB if available,
104  * 2. Secure external DTB if available,
105  * 3. If neither then NULL
106  */
107 void *get_secure_dt(void);
108 
109 /* Returns embedded DTB location if present, otherwise NULL */
110 void *get_embedded_dt(void);
111 
112 /* Returns external DTB if present, otherwise NULL */
113 void *get_external_dt(void);
114 
115 /* Returns TOS_FW_CONFIG DTB if present, otherwise NULL */
116 void *get_tos_fw_config_dt(void);
117 
118 /*
119  * get_aslr_seed() - return a random seed for core ASLR
120  * @fdt:	Pointer to a device tree if CFG_DT_ADDR=y
121  *
122  * This function has a __weak default implementation.
123  */
124 unsigned long get_aslr_seed(void *fdt);
125 
126 /* Returns true if passed DTB is same as Embedded DTB, otherwise false */
127 static inline bool is_embedded_dt(void *fdt)
128 {
129 	return fdt && fdt == get_embedded_dt();
130 }
131 
132 #endif /* __KERNEL_BOOT_H */
133