blob: 4a1517af36a65ff00d2f75a13c805ba969187a8c [file] [log] [blame]
Yann Gautier36a1e4b2019-01-17 14:52:47 +01001/*
Patrick Delaunaye720b5b2022-12-14 13:45:04 +01002 * Copyright (c) 2017-2024, STMicroelectronics - All Rights Reserved
Yann Gautier36a1e4b2019-01-17 14:52:47 +01003 *
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 Gautier36a1e4b2019-01-17 14:52:47 +010016 * 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 Bayon97287cd2019-05-20 18:35:02 +020024#define BSEC_TIMEOUT 0xFFFFFFF9U
25#define BSEC_RETRY 0xFFFFFFF8U
26#define BSEC_NOT_SUPPORTED 0xFFFFFFF7U
27#define BSEC_WRITE_LOCKED 0xFFFFFFF6U
Yann Gautier36a1e4b2019-01-17 14:52:47 +010028
Nicolas Le Bayon97287cd2019-05-20 18:35:02 +020029/*
Patrick Delaunaye720b5b2022-12-14 13:45:04 +010030 * 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 Bayon97287cd2019-05-20 18:35:02 +020037 */
Patrick Delaunaye720b5b2022-12-14 13:45:04 +010038#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 Gautier36a1e4b2019-01-17 14:52:47 +010042
43uint32_t bsec_probe(void);
Yann Gautier36a1e4b2019-01-17 14:52:47 +010044
Yann Gautier36a1e4b2019-01-17 14:52:47 +010045uint32_t bsec_read_otp(uint32_t *val, uint32_t otp);
Patrick Delaunaye720b5b2022-12-14 13:45:04 +010046uint32_t bsec_shadow_read_otp(uint32_t *val, uint32_t otp);
Yann Gautier36a1e4b2019-01-17 14:52:47 +010047uint32_t bsec_write_otp(uint32_t val, uint32_t otp);
48uint32_t bsec_program_otp(uint32_t val, uint32_t otp);
Yann Gautier36a1e4b2019-01-17 14:52:47 +010049
Yann Gautier36a1e4b2019-01-17 14:52:47 +010050uint32_t bsec_read_debug_conf(void);
Nicolas Le Bayon97287cd2019-05-20 18:35:02 +020051
52void bsec_write_scratch(uint32_t val);
Yann Gautier36a1e4b2019-01-17 14:52:47 +010053
Patrick Delaunaye720b5b2022-12-14 13:45:04 +010054/* Sticky lock support */
Nicolas Le Bayon97287cd2019-05-20 18:35:02 +020055uint32_t bsec_set_sr_lock(uint32_t otp);
56uint32_t bsec_read_sr_lock(uint32_t otp, bool *value);
57uint32_t bsec_set_sw_lock(uint32_t otp);
58uint32_t bsec_read_sw_lock(uint32_t otp, bool *value);
59uint32_t bsec_set_sp_lock(uint32_t otp);
60uint32_t bsec_read_sp_lock(uint32_t otp, bool *value);
Yann Gautier36a1e4b2019-01-17 14:52:47 +010061
Patrick Delaunaye720b5b2022-12-14 13:45:04 +010062uint32_t bsec_get_secure_state(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)
69uint32_t bsec_permanent_lock_otp(uint32_t otp);
Yann Gautier36a1e4b2019-01-17 14:52:47 +010070uint32_t bsec_check_nsec_access_rights(uint32_t otp);
Patrick Delaunaye720b5b2022-12-14 13:45:04 +010071#endif
Yann Gautier36a1e4b2019-01-17 14:52:47 +010072
73#endif /* BSEC_H */