Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 1 | /* |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2024, STMicroelectronics - All Rights Reserved |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 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 | /* |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 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 |
Nicolas Le Bayon | 97287cd | 2019-05-20 18:35:02 +0200 | [diff] [blame] | 24 | #define BSEC_TIMEOUT 0xFFFFFFF9U |
| 25 | #define BSEC_RETRY 0xFFFFFFF8U |
| 26 | #define BSEC_NOT_SUPPORTED 0xFFFFFFF7U |
| 27 | #define BSEC_WRITE_LOCKED 0xFFFFFFF6U |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 28 | |
Nicolas Le Bayon | 97287cd | 2019-05-20 18:35:02 +0200 | [diff] [blame] | 29 | /* |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 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 |
Nicolas Le Bayon | 97287cd | 2019-05-20 18:35:02 +0200 | [diff] [blame] | 37 | */ |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 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) |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 42 | |
| 43 | uint32_t bsec_probe(void); |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 44 | |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 45 | uint32_t bsec_read_otp(uint32_t *val, uint32_t otp); |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 46 | uint32_t bsec_shadow_read_otp(uint32_t *val, uint32_t otp); |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 47 | uint32_t bsec_write_otp(uint32_t val, uint32_t otp); |
| 48 | uint32_t bsec_program_otp(uint32_t val, uint32_t otp); |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 49 | |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 50 | uint32_t bsec_read_debug_conf(void); |
Nicolas Le Bayon | 97287cd | 2019-05-20 18:35:02 +0200 | [diff] [blame] | 51 | |
| 52 | void bsec_write_scratch(uint32_t val); |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 53 | |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 54 | /* Sticky lock support */ |
Nicolas Le Bayon | 97287cd | 2019-05-20 18:35:02 +0200 | [diff] [blame] | 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); |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 61 | |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 62 | uint32_t bsec_get_secure_state(void); |
| 63 | static 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); |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 70 | uint32_t bsec_check_nsec_access_rights(uint32_t otp); |
Patrick Delaunay | e720b5b | 2022-12-14 13:45:04 +0100 | [diff] [blame] | 71 | #endif |
Yann Gautier | 36a1e4b | 2019-01-17 14:52:47 +0100 | [diff] [blame] | 72 | |
| 73 | #endif /* BSEC_H */ |