xref: /optee_os/core/arch/arm/plat-stm32mp1/stm32_util.h (revision faaa17350a63b639d82b80b08c5512e87a80f33c)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Copyright (c) 2018-2022, STMicroelectronics
4  */
5 
6 #ifndef __STM32_UTIL_H__
7 #define __STM32_UTIL_H__
8 
9 #include <assert.h>
10 #include <drivers/clk.h>
11 #include <kernel/panic.h>
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <tee_api_types.h>
15 #include <types_ext.h>
16 
17 /* SoC versioning and device ID */
18 TEE_Result stm32mp1_dbgmcu_get_chip_dev_id(uint32_t *chip_dev_id);
19 
20 /* Crypto HW support */
21 bool stm32mp_supports_hw_cryp(void);
22 
23 /*  Second core support */
24 bool stm32mp_supports_second_core(void);
25 
26 /* Get device ID from SYSCFG registers */
27 uint32_t stm32mp_syscfg_get_chip_dev_id(void);
28 
29 /*
30  * OPP service support per hardware constraints
31  * @opp_id: OPP support identifier read from DT property opp-hw-support
32  * Return true if hardware supports the OPP, return false otherwise
33  */
34 bool stm32mp_supports_cpu_opp(uint32_t opp_id);
35 
36 /* Backup registers and RAM utils */
37 vaddr_t stm32mp_bkpreg(unsigned int idx);
38 
39 /* Platform util for the RCC drivers */
40 vaddr_t stm32_rcc_base(void);
41 
42 /* Erase ESRAM3 */
43 TEE_Result stm32mp_syscfg_erase_sram3(void);
44 
45 /* Platform util for the GIC */
46 vaddr_t get_gicd_base(void);
47 
48 /* Platform util for PMIC support */
49 bool stm32mp_with_pmic(void);
50 
51 /* Power management service */
52 #ifdef CFG_PSCI_ARM32
53 void stm32mp_register_online_cpu(void);
54 #else
stm32mp_register_online_cpu(void)55 static inline void stm32mp_register_online_cpu(void)
56 {
57 }
58 #endif
59 
60 /*
61  * Generic spinlock function that bypass spinlock if MMU is disabled or
62  * lock is NULL.
63  */
64 uint32_t may_spin_lock(unsigned int *lock);
65 void may_spin_unlock(unsigned int *lock, uint32_t exceptions);
66 
67 /* Helper from platform RCC clock driver */
68 struct clk *stm32mp_rcc_clock_id_to_clk(unsigned long clock_id);
69 
70 extern const struct clk_ops stm32mp1_clk_ops;
71 
72 /* Return rstctrl instance related to RCC reset controller DT binding ID */
73 struct rstctrl *stm32mp_rcc_reset_id_to_rstctrl(unsigned int binding_id);
74 
75 /*
76  * Structure and API function for BSEC driver to get some platform data.
77  *
78  * @base: BSEC interface registers physical base address
79  * @upper_start: Base ID for the BSEC upper words in the platform
80  * @max_id: Max value for BSEC word ID for the platform
81  */
82 struct stm32_bsec_static_cfg {
83 	paddr_t base;
84 	unsigned int upper_start;
85 	unsigned int max_id;
86 };
87 
88 void stm32mp_get_bsec_static_cfg(struct stm32_bsec_static_cfg *cfg);
89 
90 bool stm32mp_allow_probe_shared_device(const void *fdt, int node);
91 
92 #if defined(CFG_STM32MP15) && defined(CFG_WITH_PAGER)
93 /*
94  * Return the SRAM alias physical address related to @pa when applicable or
95  * @pa if it does not relate to an SRAMx non-aliased memory address.
96  */
97 paddr_t stm32mp1_pa_or_sram_alias_pa(paddr_t pa);
98 
99 /* Return whether or not the physical address range intersec pager secure RAM */
100 bool stm32mp1_ram_intersect_pager_ram(paddr_t base, size_t size);
101 #else
stm32mp1_pa_or_sram_alias_pa(paddr_t pa)102 static inline paddr_t stm32mp1_pa_or_sram_alias_pa(paddr_t pa)
103 {
104 	return pa;
105 }
106 
stm32mp1_ram_intersect_pager_ram(paddr_t base __unused,size_t size __unused)107 static inline bool stm32mp1_ram_intersect_pager_ram(paddr_t base __unused,
108 						    size_t size __unused)
109 {
110 	return false;
111 }
112 #endif /*CFG_STM32MP15 && CFG_WITH_PAGER*/
113 
114 /* Print a message and reset the system */
115 void __noreturn do_reset(const char *str);
116 
117 #endif /*__STM32_UTIL_H__*/
118