1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (C) 2022, STMicroelectronics - All Rights Reserved
4  */
5 
6 #ifndef __PTA_STM32MP_BSEC_H
7 #define __PTA_STM32MP_BSEC_H
8 
9 #define PTA_BSEC_UUID { 0x94cf71ad, 0x80e6, 0x40b5, \
10 	{ 0xa7, 0xc6, 0x3d, 0xc5, 0x01, 0xeb, 0x28, 0x03 } }
11 
12 /**
13  * Read OTP memory
14  *
15  * [in]		value[0].a		OTP start offset in byte
16  * [in]		value[0].b		Access type, see PTA_BSEC_TYPE_*
17  * [out]	memref[1].buffer	Output buffer to store read values
18  * [out]	memref[1].size		Size of OTP to be read
19  *
20  * Return codes:
21  * TEE_SUCCESS - Invoke command success
22  * TEE_ERROR_BAD_PARAMETERS - Incorrect input param
23  * TEE_ERROR_ACCESS_DENIED - OTP not accessible by caller
24  */
25 #define PTA_BSEC_CMD_READ_OTP		0x0
26 
27 /**
28  * Write OTP memory
29  *
30  * [in]		value[0].a		OTP start offset in byte
31  * [in]		value[0].b		Access type (0 : shadow,
32  *					1 : fuse, 2 : lock)
33  * [in]		memref[1].buffer	Input buffer to read values
34  * [in]		memref[1].size		Size of OTP to be written
35  *
36  * Return codes:
37  * TEE_SUCCESS - Invoke command success
38  * TEE_ERROR_BAD_PARAMETERS - Incorrect input param
39  * TEE_ERROR_ACCESS_DENIED - OTP not accessible by caller
40  */
41 #define PTA_BSEC_CMD_WRITE_OTP		0x1
42 
43 /**
44  * Get BSEC state
45  * Return the chip security level by reading the BSEC state
46  *
47  * [out]	value[0].a		One of PTA_BSEC_STATE_*
48  * Return codes:
49  * TEE_SUCCESS - Invoke command success
50  * TEE_ERROR_BAD_PARAMETERS - Incorrect input param
51  */
52 #define PTA_BSEC_CMD_GET_STATE		0x3
53 
54 enum stm32_bsec_pta_sec_state {
55 	PTA_BSEC_STATE_SEC_OPEN = 0,
56 	PTA_BSEC_STATE_SEC_CLOSE = 1,
57 	PTA_BSEC_STATE_INVALID = 3
58 };
59 
60 /*
61  * Access types identifiers for PTA_BSEC_CMD_READ_OTP and
62  * PTA_BSEC_CMD_WRITE_OTP = value[in].b.
63  *
64  * PTA_BSEC_SHADOW_ACCESS	Access OTP shadow memory
65  * PTA_BSEC_FUSE_ACCESS	Access	OTP fuse memory
66  * PTA_BSEC_LOCKS_ACCESS	Access OTP locks. The locks value read/written
67  *				in memref[1] 32bit words are related to bit flag
68  *				masks PTA_BSEC_LOCK_*.
69  */
70 #define PTA_BSEC_SHADOW_ACCESS		0
71 #define PTA_BSEC_FUSE_ACCESS		1
72 #define PTA_BSEC_LOCKS_ACCESS		2
73 
74 /*
75  * PTA_BSEC_LOCK_* - Bit mask of OTP locks in memref[1]
76  *
77  * PTA_BSEC_LOCK_PERM		Fuse programming permanent lock
78  * PTA_BSEC_LOCK_SHADOW_R	Shadow programming (from fuse) lock
79  * PTA_BSEC_LOCK_SHADOW_W	Shadow memory write lock
80  * PTA_BSEC_LOCK_SHADOW_P	Fuse programming sticky lock
81  * PTA_BSEC_LOCK_ERROR		Flag indicating an error in lock access
82  */
83 #define PTA_BSEC_LOCK_PERM			BIT(30)
84 #define PTA_BSEC_LOCK_SHADOW_R			BIT(29)
85 #define PTA_BSEC_LOCK_SHADOW_W			BIT(28)
86 #define PTA_BSEC_LOCK_SHADOW_P			BIT(27)
87 #define PTA_BSEC_LOCK_ERROR			BIT(26)
88 
89 #endif /* __PTA_STM32MP_BSEC_H */
90