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