1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (C) 2022 Foundries.io Ltd
4  * Jorge Ramirez-Ortiz <jorge@foundries.io>
5  */
6 
7 #ifndef __DRIVERS_VERSAL_PUF_H
8 #define __DRIVERS_VERSAL_PUF_H
9 
10 #include <platform_config.h>
11 #include <tee_api_types.h>
12 #include <types_ext.h>
13 #include <util.h>
14 
15 #define VERSAL_PUF_REGISTRATION			0x0
16 #define VERSAL_PUF_REGEN_ON_DEMAND		0x1
17 #define VERSAL_PUF_REGEN_ID_ONLY		0x2
18 #define VERSAL_PUF_SHUTTER_VALUE		0x81000100
19 #define VERSAL_PUF_SYNDROME_MODE_4K		0x0
20 #define VERSAL_PUF_GLBL_VAR_FLTR_OPTION		1
21 #define VERSAL_PUF_READ_FROM_RAM		0
22 #define VERSAL_PUF_READ_FROM_EFUSE_CACHE	1
23 #define VERSAL_PUF_4K_PUF_SYN_LEN_IN_WORDS	140
24 
25 #define VERSAL_PUF_EFUSE_SYN_WORDS		127
26 #define VERSAL_PUF_SYNDROME_WORDS		350
27 #define VERSAL_PUF_ID_WORDS			8
28 #define VERSAL_PUF_HASH_LEN			4
29 #define VERSAL_PUF_AUX_LEN			4
30 
31 struct versal_puf_data {
32 	uint32_t syndrome_data[VERSAL_PUF_SYNDROME_WORDS];
33 	uint32_t chash;
34 	uint32_t aux;
35 	uint32_t puf_id[VERSAL_PUF_ID_WORDS];
36 	uint32_t efuse_syn_data[VERSAL_PUF_EFUSE_SYN_WORDS];
37 };
38 
39 struct versal_puf_cfg {
40 	uint8_t reg_mode;
41 	uint8_t puf_operation;
42 	uint8_t global_var_filter;
43 	uint8_t read_option;
44 	uint32_t shutter_value;
45 };
46 
47 struct versal_puf_data_req {
48 	uint8_t reg_mode;
49 	uint8_t puf_operation;
50 	uint8_t global_var_filter;
51 	uint8_t read_option;
52 	uint32_t shutter_value;
53 	uint64_t syndrome_data_addr;
54 	uint64_t hash_addr;
55 	uint64_t aux_addr;
56 	uint64_t puf_id_addr;
57 	uint64_t syndrome_addr;
58 	uint64_t efuse_syn_data_addr;
59 	uint8_t pad[8];
60 };
61 
62 enum versal_puf_api {
63 	VERSAL_PUF_API_FEATURES = 0U,
64 	VERSAL_PUF_REGISTER,
65 	VERSAL_PUF_REGENERATE,
66 	VERSAL_PUF_CLEAR_ID,
67 };
68 
69 #define __aligned_puf	__aligned(CACHELINE_LEN)
70 
71 TEE_Result versal_puf_regenerate(struct versal_puf_data *buf,
72 				 struct versal_puf_cfg *cfg);
73 TEE_Result versal_puf_register(struct versal_puf_data *buf,
74 			       struct versal_puf_cfg *cfg);
75 TEE_Result versal_puf_check_api(enum versal_puf_api id);
76 TEE_Result versal_puf_clear_id(void);
77 
78 #endif /* __DRIVERS_VERSAL_PUF_H */
79