xref: /optee_os/core/include/kernel/boot.h (revision faf09045e38c5eb698ae3d2749a2ddaef8ce1b4d)
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);
48*faf09045SJens Wiklander void boot_init_primary_final(void);
49a0e8ffe9SJens Wiklander void boot_init_memtag(void);
50b2f99d20SOlivier Deprez void boot_clear_memtag(void);
51f332e77cSJens Wiklander void boot_save_args(unsigned long a0, unsigned long a1, unsigned long a2,
52f332e77cSJens Wiklander 		    unsigned long a3, unsigned long a4);
5370eacc45SMarouene Boubakri 
5470eacc45SMarouene Boubakri void __panic_at_smc_return(void) __noreturn;
5570eacc45SMarouene Boubakri 
5670eacc45SMarouene Boubakri #if defined(CFG_WITH_ARM_TRUSTED_FW)
5770eacc45SMarouene Boubakri unsigned long cpu_on_handler(unsigned long a0, unsigned long a1);
5870eacc45SMarouene Boubakri unsigned long boot_cpu_on_handler(unsigned long a0, unsigned long a1);
5970eacc45SMarouene Boubakri #else
6070eacc45SMarouene Boubakri void boot_init_secondary(unsigned long nsec_entry);
6170eacc45SMarouene Boubakri #endif
6270eacc45SMarouene Boubakri 
63df913c6dSAlvin Chang void boot_primary_init_intc(void);
648aae4669SAlvin Chang void boot_secondary_init_intc(void);
6570eacc45SMarouene Boubakri 
6670eacc45SMarouene Boubakri void init_sec_mon(unsigned long nsec_entry);
6770eacc45SMarouene Boubakri void init_tee_runtime(void);
6870eacc45SMarouene Boubakri 
6970eacc45SMarouene Boubakri /* weak routines eventually overridden by platform */
7070eacc45SMarouene Boubakri void plat_cpu_reset_early(void);
7170eacc45SMarouene Boubakri void plat_primary_init_early(void);
7270eacc45SMarouene Boubakri unsigned long plat_get_aslr_seed(void);
7370eacc45SMarouene Boubakri unsigned long plat_get_freq(void);
74b89b3da2SVincent Chuang #if defined(_CFG_CORE_STACK_PROTECTOR) || defined(CFG_WITH_STACK_CANARIES)
75b89b3da2SVincent Chuang /*
76b89b3da2SVincent Chuang  * plat_get_random_stack_canaries() - Get random values for stack canaries.
77b89b3da2SVincent Chuang  * @buf:	Pointer to the buffer where to store canaries
78b89b3da2SVincent Chuang  * @ncan:	The number of canaries to generate.
79b89b3da2SVincent Chuang  * @size:	The size (in bytes) of each canary.
80b89b3da2SVincent Chuang  *
81b89b3da2SVincent Chuang  * This function has a __weak default implementation.
82b89b3da2SVincent Chuang  */
83b89b3da2SVincent Chuang void plat_get_random_stack_canaries(void *buf, size_t ncan, size_t size);
8445507d10SKhoa Hoang #endif
8570eacc45SMarouene Boubakri void arm_cl2_config(vaddr_t pl310);
8670eacc45SMarouene Boubakri void arm_cl2_enable(vaddr_t pl310);
8770eacc45SMarouene Boubakri 
8870eacc45SMarouene Boubakri #if defined(CFG_BOOT_SECONDARY_REQUEST)
8970eacc45SMarouene Boubakri void boot_set_core_ns_entry(size_t core_idx, uintptr_t entry,
9070eacc45SMarouene Boubakri 			    uintptr_t context_id);
9170eacc45SMarouene Boubakri 
9270eacc45SMarouene Boubakri int boot_core_release(size_t core_idx, paddr_t entry);
9370eacc45SMarouene Boubakri struct ns_entry_context *boot_core_hpen(void);
9470eacc45SMarouene Boubakri #endif
9570eacc45SMarouene Boubakri 
96839dadc2SJens Wiklander /*
97839dadc2SJens Wiklander  * get_aslr_seed() - return a random seed for core ASLR
98839dadc2SJens Wiklander  *
99839dadc2SJens Wiklander  * This function has a __weak default implementation.
100839dadc2SJens Wiklander  */
101720e8800SJens Wiklander unsigned long get_aslr_seed(void);
10270eacc45SMarouene Boubakri 
103910441c3SYu Chien Peter Lin /* Identify non-secure memory regions for dynamic shared memory */
104910441c3SYu Chien Peter Lin void discover_nsec_memory(void);
105910441c3SYu Chien Peter Lin /* Add reserved memory for static shared memory in the device-tree */
106910441c3SYu Chien Peter Lin int mark_static_shm_as_reserved(struct dt_descriptor *dt);
107910441c3SYu Chien Peter Lin 
10870eacc45SMarouene Boubakri #endif /* __KERNEL_BOOT_H */
109