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