1 /* 2 * Copyright (c) 2017-2024, STMicroelectronics - All Rights Reserved 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef BSEC_H 8 #define BSEC_H 9 10 #include <stdbool.h> 11 #include <stdint.h> 12 13 #include <lib/utils_def.h> 14 15 /* 16 * Return status 17 */ 18 #define BSEC_OK 0U 19 #define BSEC_ERROR 0xFFFFFFFFU 20 #define BSEC_DISTURBED 0xFFFFFFFEU 21 #define BSEC_INVALID_PARAM 0xFFFFFFFCU 22 #define BSEC_PROG_FAIL 0xFFFFFFFBU 23 #define BSEC_LOCK_FAIL 0xFFFFFFFAU 24 #define BSEC_TIMEOUT 0xFFFFFFF9U 25 #define BSEC_RETRY 0xFFFFFFF8U 26 #define BSEC_NOT_SUPPORTED 0xFFFFFFF7U 27 #define BSEC_WRITE_LOCKED 0xFFFFFFF6U 28 29 /* 30 * get BSEC global state: result for bsec_get_secure_state() 31 * @state: global state 32 * [1:0] BSEC state 33 * 00b: Sec Open 34 * 01b: Sec Closed 35 * 11b: Invalid 36 * [8]: Hardware Key set = 1b 37 */ 38 #define BSEC_STATE_SEC_OPEN U(0x0) 39 #define BSEC_STATE_SEC_CLOSED U(0x1) 40 #define BSEC_STATE_INVALID U(0x3) 41 #define BSEC_STATE_MASK GENMASK_32(1, 0) 42 43 uint32_t bsec_probe(void); 44 45 uint32_t bsec_read_otp(uint32_t *val, uint32_t otp); 46 uint32_t bsec_shadow_read_otp(uint32_t *val, uint32_t otp); 47 uint32_t bsec_write_otp(uint32_t val, uint32_t otp); 48 uint32_t bsec_program_otp(uint32_t val, uint32_t otp); 49 50 uint32_t bsec_read_debug_conf(void); 51 52 void bsec_write_scratch(uint32_t val); 53 54 /* Sticky lock support */ 55 uint32_t bsec_set_sr_lock(uint32_t otp); 56 uint32_t bsec_read_sr_lock(uint32_t otp, bool *value); 57 uint32_t bsec_set_sw_lock(uint32_t otp); 58 uint32_t bsec_read_sw_lock(uint32_t otp, bool *value); 59 uint32_t bsec_set_sp_lock(uint32_t otp); 60 uint32_t bsec_read_sp_lock(uint32_t otp, bool *value); 61 62 uint32_t bsec_get_secure_state(void); bsec_mode_is_closed_device(void)63static inline bool bsec_mode_is_closed_device(void) 64 { 65 return (bsec_get_secure_state() & BSEC_STATE_MASK) == BSEC_STATE_SEC_CLOSED; 66 } 67 68 #if defined(IMAGE_BL32) 69 uint32_t bsec_permanent_lock_otp(uint32_t otp); 70 uint32_t bsec_check_nsec_access_rights(uint32_t otp); 71 #endif 72 73 #endif /* BSEC_H */ 74