xref: /optee_os/core/include/kernel/boot.h (revision df913c6d8a6d9fc4b0cb5146603b50d26c8f08ed)
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>
1070eacc45SMarouene Boubakri #include <types_ext.h>
1170eacc45SMarouene Boubakri 
1270eacc45SMarouene Boubakri /*
1370eacc45SMarouene Boubakri  * struct boot_embdata - Embedded boot data
1470eacc45SMarouene Boubakri  * @total_len: Total length of the embedded boot data
1570eacc45SMarouene Boubakri  * @num_blobs: Number of blobs in the embedded boot data, always 2 even if
1670eacc45SMarouene Boubakri  *	       one blob is empty
1770eacc45SMarouene Boubakri  * @hashes_offset: Offset of hashes from start of this struct
1870eacc45SMarouene Boubakri  * @hashes_len: Length of hashes
1970eacc45SMarouene Boubakri  * @reloc_offset: Offset of reloc from start of this struct
2070eacc45SMarouene Boubakri  * @reloc_len: Length of reloc
2170eacc45SMarouene Boubakri  *
2270eacc45SMarouene Boubakri  * This struct is initialized by scripts/gen_tee_bin.py and must be kept
2370eacc45SMarouene Boubakri  * in sync with that script. The struct and the following data is loaded
2470eacc45SMarouene Boubakri  * at different addresses at boot depending on CFG_WITH_PAGER.
2570eacc45SMarouene Boubakri  *
2670eacc45SMarouene Boubakri  * If configured with CFG_WITH_PAGER=y the struct with data is following
2770eacc45SMarouene Boubakri  * init part, this is together with the init part moved by the primary CPU
2870eacc45SMarouene Boubakri  * so it ends up at __init_end. Whatever need to be saved for later need to
2970eacc45SMarouene Boubakri  * be copied to a safe location in init_runtime().
3070eacc45SMarouene Boubakri  *
3170eacc45SMarouene Boubakri  * If configured with CFG_WITH_PAGER=n following the struct with data is
3270eacc45SMarouene Boubakri  * __data_end, this is moved by the primary CPU so it ends up at __end.
3370eacc45SMarouene Boubakri  */
3470eacc45SMarouene Boubakri struct boot_embdata {
3570eacc45SMarouene Boubakri 	uint32_t total_len;
3670eacc45SMarouene Boubakri 	uint32_t num_blobs;
3770eacc45SMarouene Boubakri 	uint32_t hashes_offset;
3870eacc45SMarouene Boubakri 	uint32_t hashes_len;
3970eacc45SMarouene Boubakri 	uint32_t reloc_offset;
4070eacc45SMarouene Boubakri 	uint32_t reloc_len;
4170eacc45SMarouene Boubakri };
4270eacc45SMarouene Boubakri 
4370eacc45SMarouene Boubakri extern const struct core_mmu_config boot_mmu_config;
4470eacc45SMarouene Boubakri 
4570eacc45SMarouene Boubakri /* @nsec_entry is unused if using CFG_WITH_ARM_TRUSTED_FW */
4670eacc45SMarouene Boubakri void boot_init_primary_early(unsigned long pageable_part,
4770eacc45SMarouene Boubakri 			     unsigned long nsec_entry);
48809fa817SBalint Dobszay void boot_init_primary_late(unsigned long fdt, unsigned long tos_fw_config);
49a0e8ffe9SJens Wiklander void boot_init_memtag(void);
50e1602654SJens Wiklander void boot_save_boot_info(void *boot_info);
5170eacc45SMarouene Boubakri 
5270eacc45SMarouene Boubakri void __panic_at_smc_return(void) __noreturn;
5370eacc45SMarouene Boubakri 
5470eacc45SMarouene Boubakri #if defined(CFG_WITH_ARM_TRUSTED_FW)
5570eacc45SMarouene Boubakri unsigned long cpu_on_handler(unsigned long a0, unsigned long a1);
5670eacc45SMarouene Boubakri unsigned long boot_cpu_on_handler(unsigned long a0, unsigned long a1);
5770eacc45SMarouene Boubakri #else
5870eacc45SMarouene Boubakri void boot_init_secondary(unsigned long nsec_entry);
5970eacc45SMarouene Boubakri #endif
6070eacc45SMarouene Boubakri 
61*df913c6dSAlvin Chang void boot_primary_init_intc(void);
628aae4669SAlvin Chang void boot_secondary_init_intc(void);
6370eacc45SMarouene Boubakri 
6470eacc45SMarouene Boubakri void init_sec_mon(unsigned long nsec_entry);
6570eacc45SMarouene Boubakri void init_tee_runtime(void);
6670eacc45SMarouene Boubakri 
6770eacc45SMarouene Boubakri /* weak routines eventually overridden by platform */
6870eacc45SMarouene Boubakri void plat_cpu_reset_early(void);
6970eacc45SMarouene Boubakri void plat_primary_init_early(void);
7070eacc45SMarouene Boubakri unsigned long plat_get_aslr_seed(void);
7170eacc45SMarouene Boubakri unsigned long plat_get_freq(void);
72b89b3da2SVincent Chuang #if defined(_CFG_CORE_STACK_PROTECTOR) || defined(CFG_WITH_STACK_CANARIES)
73b89b3da2SVincent Chuang /*
74b89b3da2SVincent Chuang  * plat_get_random_stack_canaries() - Get random values for stack canaries.
75b89b3da2SVincent Chuang  * @buf:	Pointer to the buffer where to store canaries
76b89b3da2SVincent Chuang  * @ncan:	The number of canaries to generate.
77b89b3da2SVincent Chuang  * @size:	The size (in bytes) of each canary.
78b89b3da2SVincent Chuang  *
79b89b3da2SVincent Chuang  * This function has a __weak default implementation.
80b89b3da2SVincent Chuang  */
81b89b3da2SVincent Chuang void plat_get_random_stack_canaries(void *buf, size_t ncan, size_t size);
8245507d10SKhoa Hoang #endif
8370eacc45SMarouene Boubakri void arm_cl2_config(vaddr_t pl310);
8470eacc45SMarouene Boubakri void arm_cl2_enable(vaddr_t pl310);
8570eacc45SMarouene Boubakri 
8670eacc45SMarouene Boubakri #if defined(CFG_BOOT_SECONDARY_REQUEST)
8770eacc45SMarouene Boubakri void boot_set_core_ns_entry(size_t core_idx, uintptr_t entry,
8870eacc45SMarouene Boubakri 			    uintptr_t context_id);
8970eacc45SMarouene Boubakri 
9070eacc45SMarouene Boubakri int boot_core_release(size_t core_idx, paddr_t entry);
9170eacc45SMarouene Boubakri struct ns_entry_context *boot_core_hpen(void);
9270eacc45SMarouene Boubakri #endif
9370eacc45SMarouene Boubakri 
94809fa817SBalint Dobszay /* Returns TOS_FW_CONFIG DTB if present, otherwise NULL */
95809fa817SBalint Dobszay void *get_tos_fw_config_dt(void);
96809fa817SBalint Dobszay 
97839dadc2SJens Wiklander /*
98839dadc2SJens Wiklander  * get_aslr_seed() - return a random seed for core ASLR
99839dadc2SJens Wiklander  * @fdt:	Pointer to a device tree if CFG_DT_ADDR=y
100839dadc2SJens Wiklander  *
101839dadc2SJens Wiklander  * This function has a __weak default implementation.
102839dadc2SJens Wiklander  */
10370eacc45SMarouene Boubakri unsigned long get_aslr_seed(void *fdt);
10470eacc45SMarouene Boubakri 
10570eacc45SMarouene Boubakri #endif /* __KERNEL_BOOT_H */
106