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