xref: /optee_os/core/include/drivers/stm32_bsec.h (revision 5a913ee74d3c71af2a2860ce8a4e7aeab2916f9b)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Copyright (c) 2017-2019, STMicroelectronics
4  */
5 
6 #ifndef __STM32_BSEC_H
7 #define __STM32_BSEC_H
8 
9 #include <stdint.h>
10 #include <tee_api.h>
11 
12 /*
13  * Load OTP from SAFMEM and provide its value
14  * @value: Output read value
15  * @otp_id: OTP number
16  * Return a TEE_Result compliant return value
17  */
18 TEE_Result stm32_bsec_shadow_read_otp(uint32_t *value, uint32_t otp_id);
19 
20 /*
21  * Copy SAFMEM OTP to BSEC data.
22  * @otp_id: OTP number.
23  * Return a TEE_Result compliant return value
24  */
25 TEE_Result stm32_bsec_shadow_register(uint32_t otp_id);
26 
27 /*
28  * Read an OTP data value
29  * @value: Output read value
30  * @otp_id: OTP number
31  * Return a TEE_Result compliant return value
32  */
33 TEE_Result stm32_bsec_read_otp(uint32_t *value, uint32_t otp_id);
34 
35 /*
36  * Write value in BSEC data register
37  * @value: Value to write
38  * @otp_id: OTP number
39  * Return a TEE_Result compliant return value
40  */
41 TEE_Result stm32_bsec_write_otp(uint32_t value, uint32_t otp_id);
42 
43 /*
44  * Program a bit in SAFMEM without BSEC data refresh
45  * @value: Value to program.
46  * @otp_id: OTP number.
47  * Return a TEE_Result compliant return value
48  */
49 TEE_Result stm32_bsec_program_otp(uint32_t value, uint32_t otp_id);
50 
51 /*
52  * Permanent lock of OTP in SAFMEM
53  * @otp_id: OTP number
54  * Return a TEE_Result compliant return value
55  */
56 TEE_Result stm32_bsec_permanent_lock_otp(uint32_t otp_id);
57 
58 /*
59  * Enable/disable debug service
60  * @value: Value to write
61  * Return a TEE_Result compliant return value
62  */
63 TEE_Result stm32_bsec_write_debug_conf(uint32_t value);
64 
65 /* Return debug configuration read from BSEC */
66 uint32_t stm32_bsec_read_debug_conf(void);
67 
68 /*
69  * Write shadow-read lock
70  * @otp_id: OTP number
71  * @value: Value to write in the register, must be non null
72  * Return true if OTP is locked, else false
73  */
74 bool stm32_bsec_write_sr_lock(uint32_t otp_id, uint32_t value);
75 
76 /*
77  * Read shadow-read lock
78  * @otp_id: OTP number
79  * Return true if OTP is locked, else false
80  */
81 bool stm32_bsec_read_sr_lock(uint32_t otp_id);
82 
83 /*
84  * Write shadow-write lock
85  * @otp_id: OTP number
86  * @value: Value to write in the register, must be non null
87  * Return true if OTP is locked, else false
88  */
89 bool stm32_bsec_write_sw_lock(uint32_t otp_id, uint32_t value);
90 
91 /*
92  * Read shadow-write lock
93  * @otp_id: OTP number
94  * Return true if OTP is locked, else false
95  */
96 bool stm32_bsec_read_sw_lock(uint32_t otp_id);
97 
98 /*
99  * Write shadow-program lock
100  * @otp_id: OTP number
101  * @value: Value to write in the register, must be non null
102  * Return true if OTP is locked, else false
103  */
104 bool stm32_bsec_write_sp_lock(uint32_t otp_id, uint32_t value);
105 
106 /*
107  * Read shadow-program lock
108  * @otp_id: OTP number
109  * Return true if OTP is locked, else false
110  */
111 bool stm32_bsec_read_sp_lock(uint32_t otp_id);
112 
113 /*
114  * Read permanent lock status
115  * @otp_id: OTP number
116  * Return true if OTP is locked, else false
117  */
118 bool stm32_bsec_wr_lock(uint32_t otp_id);
119 
120 /*
121  * Lock Upper OTP or Global programming or debug enable
122  * @service: Service to lock, see header file
123  * @value: Value to write must always set to 1 (only use for debug purpose)
124  * Return a TEE_Result compliant return value
125  */
126 TEE_Result stm32_bsec_otp_lock(uint32_t service, uint32_t value);
127 
128 /*
129  * Return true if non-secure world is allowed to read the target OTP
130  * @otp_id: OTP number
131  */
132 bool stm32_bsec_nsec_can_access_otp(uint32_t otp_id);
133 
134 #endif /*__STM32_BSEC_H*/
135