xref: /optee_os/core/include/drivers/stm32_bsec.h (revision ef9888dc73edbd3a3935e432320f5e6644e5cd2a)
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 <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  * Return a TEE_Result compliant return value
72  */
73 TEE_Result stm32_bsec_set_sr_lock(uint32_t otp_id);
74 
75 /*
76  * Read shadow-read lock
77  * @otp_id: OTP number
78  * @locked: (out) true if shadow-read is locked, false if not locked.
79  * Return a TEE_Result compliant return value
80  */
81 TEE_Result stm32_bsec_read_sr_lock(uint32_t otp_id, bool *locked);
82 
83 /*
84  * Write shadow-write lock
85  * @otp_id: OTP number
86  * Return a TEE_Result compliant return value
87  */
88 TEE_Result stm32_bsec_set_sw_lock(uint32_t otp_id);
89 
90 /*
91  * Read shadow-write lock
92  * @otp_id: OTP number
93  * @locked: (out) true if shadow-write is locked, false if not locked.
94  * Return a TEE_Result compliant return value
95  */
96 TEE_Result stm32_bsec_read_sw_lock(uint32_t otp_id, bool *locked);
97 
98 /*
99  * Write shadow-program lock
100  * @otp_id: OTP number
101  * Return a TEE_Result compliant return value
102  */
103 TEE_Result stm32_bsec_set_sp_lock(uint32_t otp_id);
104 
105 /*
106  * Read shadow-program lock
107  * @otp_id: OTP number
108  * @locked: (out) true if shadow-program is locked, false if not locked.
109  * Return a TEE_Result compliant return value
110  */
111 TEE_Result stm32_bsec_read_sp_lock(uint32_t otp_id, bool *locked);
112 
113 /*
114  * Read permanent lock status
115  * @otp_id: OTP number
116  * @locked: (out) true if permanent lock is locked, false if not locked.
117  * Return a TEE_Result compliant return value
118  */
119 TEE_Result stm32_bsec_read_permanent_lock(uint32_t otp_id, bool *locked);
120 
121 /*
122  * Lock Upper OTP or Global programming or debug enable
123  * @service: Service to lock, see header file
124  * Return a TEE_Result compliant return value
125  */
126 TEE_Result stm32_bsec_otp_lock(uint32_t service);
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