xref: /optee_os/core/include/kernel/boot.h (revision f332e77c4b7c133f03148d58cc6109f8adaeddd1)
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);
48330e04efSJens Wiklander void boot_init_primary_late(unsigned long fdt, unsigned long manifest);
49a0e8ffe9SJens Wiklander void boot_init_memtag(void);
50*f332e77cSJens Wiklander void boot_save_args(unsigned long a0, unsigned long a1, unsigned long a2,
51*f332e77cSJens Wiklander 		    unsigned long a3, unsigned long a4);
5270eacc45SMarouene Boubakri 
5370eacc45SMarouene Boubakri void __panic_at_smc_return(void) __noreturn;
5470eacc45SMarouene Boubakri 
5570eacc45SMarouene Boubakri #if defined(CFG_WITH_ARM_TRUSTED_FW)
5670eacc45SMarouene Boubakri unsigned long cpu_on_handler(unsigned long a0, unsigned long a1);
5770eacc45SMarouene Boubakri unsigned long boot_cpu_on_handler(unsigned long a0, unsigned long a1);
5870eacc45SMarouene Boubakri #else
5970eacc45SMarouene Boubakri void boot_init_secondary(unsigned long nsec_entry);
6070eacc45SMarouene Boubakri #endif
6170eacc45SMarouene Boubakri 
62df913c6dSAlvin Chang void boot_primary_init_intc(void);
638aae4669SAlvin Chang void boot_secondary_init_intc(void);
6470eacc45SMarouene Boubakri 
6570eacc45SMarouene Boubakri void init_sec_mon(unsigned long nsec_entry);
6670eacc45SMarouene Boubakri void init_tee_runtime(void);
6770eacc45SMarouene Boubakri 
6870eacc45SMarouene Boubakri /* weak routines eventually overridden by platform */
6970eacc45SMarouene Boubakri void plat_cpu_reset_early(void);
7070eacc45SMarouene Boubakri void plat_primary_init_early(void);
7170eacc45SMarouene Boubakri unsigned long plat_get_aslr_seed(void);
7270eacc45SMarouene Boubakri unsigned long plat_get_freq(void);
73b89b3da2SVincent Chuang #if defined(_CFG_CORE_STACK_PROTECTOR) || defined(CFG_WITH_STACK_CANARIES)
74b89b3da2SVincent Chuang /*
75b89b3da2SVincent Chuang  * plat_get_random_stack_canaries() - Get random values for stack canaries.
76b89b3da2SVincent Chuang  * @buf:	Pointer to the buffer where to store canaries
77b89b3da2SVincent Chuang  * @ncan:	The number of canaries to generate.
78b89b3da2SVincent Chuang  * @size:	The size (in bytes) of each canary.
79b89b3da2SVincent Chuang  *
80b89b3da2SVincent Chuang  * This function has a __weak default implementation.
81b89b3da2SVincent Chuang  */
82b89b3da2SVincent Chuang void plat_get_random_stack_canaries(void *buf, size_t ncan, size_t size);
8345507d10SKhoa Hoang #endif
8470eacc45SMarouene Boubakri void arm_cl2_config(vaddr_t pl310);
8570eacc45SMarouene Boubakri void arm_cl2_enable(vaddr_t pl310);
8670eacc45SMarouene Boubakri 
8770eacc45SMarouene Boubakri #if defined(CFG_BOOT_SECONDARY_REQUEST)
8870eacc45SMarouene Boubakri void boot_set_core_ns_entry(size_t core_idx, uintptr_t entry,
8970eacc45SMarouene Boubakri 			    uintptr_t context_id);
9070eacc45SMarouene Boubakri 
9170eacc45SMarouene Boubakri int boot_core_release(size_t core_idx, paddr_t entry);
9270eacc45SMarouene Boubakri struct ns_entry_context *boot_core_hpen(void);
9370eacc45SMarouene Boubakri #endif
9470eacc45SMarouene Boubakri 
95330e04efSJens Wiklander /* Returns TOS_FW_CONFIG DTB or SP manifest DTB if present, otherwise NULL */
96330e04efSJens Wiklander void *get_manifest_dt(void);
97809fa817SBalint Dobszay 
98839dadc2SJens Wiklander /*
99839dadc2SJens Wiklander  * get_aslr_seed() - return a random seed for core ASLR
100839dadc2SJens Wiklander  * @fdt:	Pointer to a device tree if CFG_DT_ADDR=y
101839dadc2SJens Wiklander  *
102839dadc2SJens Wiklander  * This function has a __weak default implementation.
103839dadc2SJens Wiklander  */
10470eacc45SMarouene Boubakri unsigned long get_aslr_seed(void *fdt);
10570eacc45SMarouene Boubakri 
10670eacc45SMarouene Boubakri #endif /* __KERNEL_BOOT_H */
107