Blame view

include/fsl_sec.h 10.6 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  /* SPDX-License-Identifier: GPL-2.0+ */
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
2
3
4
5
  /*
   * Common internal memory map for some Freescale SoCs
   *
   * Copyright 2014 Freescale Semiconductor, Inc.
bab55225e   Aymen Sghaier   MLK-18044-1: cryp...
6
   * Copyright 2018 NXP
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
7
8
9
10
11
12
13
   */
  
  #ifndef __FSL_SEC_H
  #define __FSL_SEC_H
  
  #include <common.h>
  #include <asm/io.h>
028dbb8db   Ruchika Gupta   fsl_sec : Change ...
14
  #ifdef CONFIG_SYS_FSL_SEC_LE
6fc09fa61   Utkarsh Gupta   MLK-20893: imx: i...
15
16
  #define sec_in32(a)       in_le32((ulong *)(ulong)(a))
  #define sec_out32(a, v)   out_le32((ulong *)(ulong)(a), v)
028dbb8db   Ruchika Gupta   fsl_sec : Change ...
17
18
19
20
21
22
23
24
25
  #define sec_in16(a)       in_le16(a)
  #define sec_clrbits32     clrbits_le32
  #define sec_setbits32     setbits_le32
  #elif defined(CONFIG_SYS_FSL_SEC_BE)
  #define sec_in32(a)       in_be32(a)
  #define sec_out32(a, v)   out_be32(a, v)
  #define sec_in16(a)       in_be16(a)
  #define sec_clrbits32     clrbits_be32
  #define sec_setbits32     setbits_be32
90b80386f   York Sun   crypto: Move CONF...
26
  #elif defined(CONFIG_SYS_FSL_HAS_SEC)
028dbb8db   Ruchika Gupta   fsl_sec : Change ...
27
28
  #error Neither CONFIG_SYS_FSL_SEC_LE nor CONFIG_SYS_FSL_SEC_BE is defined
  #endif
cbc0a6698   Clement Faure   TEE-346 Add DEK b...
29
  #define BLOB_SIZE(x)		((x) + 32 + 16) /* Blob buffer size */
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
30
31
  /* Security Engine Block (MS = Most Sig., LS = Least Sig.) */
  #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
c5de15cbc   Ruchika Gupta   crypto/fsl: Add c...
32
33
34
  /* RNG4 TRNG test registers */
  struct rng4tst {
  #define RTMCTL_PRGM 0x00010000	/* 1 -> program mode, 0 -> run mode */
c40655173   Alex Porosanu   drivers/crypto/fs...
35
36
37
38
39
40
41
42
43
44
  #define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_SC     0 /* use von Neumann data in
  						    both entropy shifter and
  						    statistical checker */
  #define RTMCTL_SAMP_MODE_RAW_ES_SC             1 /* use raw data in both
  						    entropy shifter and
  						    statistical checker */
  #define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_RAW_SC 2 /* use von Neumann data in
  						    entropy shifter, raw data
  						    in statistical checker */
  #define RTMCTL_SAMP_MODE_INVALID               3 /* invalid combination */
c5de15cbc   Ruchika Gupta   crypto/fsl: Add c...
45
46
47
  	u32 rtmctl;		/* misc. control register */
  	u32 rtscmisc;		/* statistical check misc. register */
  	u32 rtpkrrng;		/* poker range register */
17649e1b9   Alex Porosanu   drivers/crypto/fs...
48
  #define RTSDCTL_ENT_DLY_MIN	3200
c5de15cbc   Ruchika Gupta   crypto/fsl: Add c...
49
50
51
52
53
54
55
56
57
58
59
60
61
  #define RTSDCTL_ENT_DLY_MAX	12800
  	union {
  		u32 rtpkrmax;	/* PRGM=1: poker max. limit register */
  		u32 rtpkrsq;	/* PRGM=0: poker square calc. result register */
  	};
  #define RTSDCTL_ENT_DLY_SHIFT 16
  #define RTSDCTL_ENT_DLY_MASK (0xffff << RTSDCTL_ENT_DLY_SHIFT)
  	u32 rtsdctl;		/* seed control register */
  	union {
  		u32 rtsblim;	/* PRGM=1: sparse bit limit register */
  		u32 rttotsam;	/* PRGM=0: total samples register */
  	};
  	u32 rtfreqmin;		/* frequency count min. limit register */
026a3f1b7   Alex Porosanu   drivers/crypto/fs...
62
  #define RTFRQMAX_DISABLE       (1 << 20)
c5de15cbc   Ruchika Gupta   crypto/fsl: Add c...
63
64
65
66
67
68
  	union {
  		u32 rtfreqmax;	/* PRGM=1: freq. count max. limit register */
  		u32 rtfreqcnt;	/* PRGM=0: freq. count register */
  	};
  	u32 rsvd1[40];
  #define RNG_STATE0_HANDLE_INSTANTIATED	0x00000001
dfaec7602   Lukas Auer   crypto/fsl: insta...
69
70
71
  #define RNG_STATE1_HANDLE_INSTANTIATED	0x00000002
  #define RNG_STATE_HANDLE_MASK	\
  	(RNG_STATE0_HANDLE_INSTANTIATED | RNG_STATE1_HANDLE_INSTANTIATED)
c5de15cbc   Ruchika Gupta   crypto/fsl: Add c...
72
73
74
  	u32 rdsta;		/*RNG DRNG Status Register*/
  	u32 rsvd2[15];
  };
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  typedef struct ccsr_sec {
  	u32	res0;
  	u32	mcfgr;		/* Master CFG Register */
  	u8	res1[0x4];
  	u32	scfgr;
  	struct {
  		u32	ms;	/* Job Ring LIODN Register, MS */
  		u32	ls;	/* Job Ring LIODN Register, LS */
  	} jrliodnr[4];
  	u8	res2[0x2c];
  	u32	jrstartr;	/* Job Ring Start Register */
  	struct {
  		u32	ms;	/* RTIC LIODN Register, MS */
  		u32	ls;	/* RTIC LIODN Register, LS */
  	} rticliodnr[4];
  	u8	res3[0x1c];
  	u32	decorr;		/* DECO Request Register */
  	struct {
  		u32	ms;	/* DECO LIODN Register, MS */
  		u32	ls;	/* DECO LIODN Register, LS */
30449aea5   Laurentiu Tudor   armv8: lx2160a: a...
95
  	} decoliodnr[16];
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
96
97
  	u32	dar;		/* DECO Avail Register */
  	u32	drr;		/* DECO Reset Register */
c5de15cbc   Ruchika Gupta   crypto/fsl: Add c...
98
99
  	u8	res5[0x4d8];
  	struct rng4tst rng;	/* RNG Registers */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
100
  	u8	res6[0x8a0];
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
101
102
103
104
  	u32	crnr_ms;	/* CHA Revision Number Register, MS */
  	u32	crnr_ls;	/* CHA Revision Number Register, LS */
  	u32	ctpr_ms;	/* Compile Time Parameters Register, MS */
  	u32	ctpr_ls;	/* Compile Time Parameters Register, LS */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
105
  	u8	res7[0x10];
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
106
107
108
109
  	u32	far_ms;		/* Fault Address Register, MS */
  	u32	far_ls;		/* Fault Address Register, LS */
  	u32	falr;		/* Fault Address LIODN Register */
  	u32	fadr;		/* Fault Address Detail Register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
110
  	u8	res8[0x4];
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
111
  	u32	csta;		/* CAAM Status Register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
112
113
  	u32	smpart;		/* Secure Memory Partition Parameters */
  	u32	smvid;		/* Secure Memory Version ID */
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
114
115
116
117
118
119
120
121
  	u32	rvid;		/* Run Time Integrity Checking Version ID Reg.*/
  	u32	ccbvid;		/* CHA Cluster Block Version ID Register */
  	u32	chavid_ms;	/* CHA Version ID Register, MS */
  	u32	chavid_ls;	/* CHA Version ID Register, LS */
  	u32	chanum_ms;	/* CHA Number Register, MS */
  	u32	chanum_ls;	/* CHA Number Register, LS */
  	u32	secvid_ms;	/* SEC Version ID Register, MS */
  	u32	secvid_ls;	/* SEC Version ID Register, LS */
d8d5fdb7b   Laurentiu Tudor   fsl_sec: fix regi...
122
123
124
  #if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3)
  	u8	res9[0x6f020];
  #else
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
125
  	u8	res9[0x6020];
d8d5fdb7b   Laurentiu Tudor   fsl_sec: fix regi...
126
  #endif
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
127
128
  	u32	qilcr_ms;	/* Queue Interface LIODN CFG Register, MS */
  	u32	qilcr_ls;	/* Queue Interface LIODN CFG Register, LS */
d8d5fdb7b   Laurentiu Tudor   fsl_sec: fix regi...
129
130
131
  #if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3)
  	u8	res10[0x8ffd8];
  #else
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
132
  	u8	res10[0x8fd8];
d8d5fdb7b   Laurentiu Tudor   fsl_sec: fix regi...
133
  #endif
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  } ccsr_sec_t;
  
  #define SEC_CTPR_MS_AXI_LIODN		0x08000000
  #define SEC_CTPR_MS_QI			0x02000000
  #define SEC_CTPR_MS_VIRT_EN_INCL	0x00000001
  #define SEC_CTPR_MS_VIRT_EN_POR		0x00000002
  #define SEC_RVID_MA			0x0f000000
  #define SEC_CHANUM_MS_JRNUM_MASK	0xf0000000
  #define SEC_CHANUM_MS_JRNUM_SHIFT	28
  #define SEC_CHANUM_MS_DECONUM_MASK	0x0f000000
  #define SEC_CHANUM_MS_DECONUM_SHIFT	24
  #define SEC_SECVID_MS_IPID_MASK	0xffff0000
  #define SEC_SECVID_MS_IPID_SHIFT	16
  #define SEC_SECVID_MS_MAJ_REV_MASK	0x0000ff00
  #define SEC_SECVID_MS_MAJ_REV_SHIFT	8
  #define SEC_CCBVID_ERA_MASK		0xff000000
  #define SEC_CCBVID_ERA_SHIFT		24
  #define SEC_SCFGR_RDBENABLE		0x00000400
  #define SEC_SCFGR_VIRT_EN		0x00008000
  #define SEC_CHAVID_LS_RNG_SHIFT		16
  #define SEC_CHAVID_RNG_LS_MASK		0x000f0000
b9eebfade   Ruchika Gupta   fsl_sec: Add hard...
155
156
157
158
  
  #define CONFIG_JRSTARTR_JR0		0x00000001
  
  struct jr_regs {
f91e65a74   Ulises Cardenas   imx: Refactoring ...
159
  #if defined(CONFIG_SYS_FSL_SEC_LE) && \
bab55225e   Aymen Sghaier   MLK-18044-1: cryp...
160
161
  	!(defined(CONFIG_MX6) || defined(CONFIG_MX7) || \
  	  defined(CONFIG_MX7ULP) || defined(CONFIG_IMX8M))
b9eebfade   Ruchika Gupta   fsl_sec: Add hard...
162
163
164
165
166
167
168
169
170
171
172
173
  	u32 irba_l;
  	u32 irba_h;
  #else
  	u32 irba_h;
  	u32 irba_l;
  #endif
  	u32 rsvd1;
  	u32 irs;
  	u32 rsvd2;
  	u32 irsa;
  	u32 rsvd3;
  	u32 irja;
f91e65a74   Ulises Cardenas   imx: Refactoring ...
174
  #if defined(CONFIG_SYS_FSL_SEC_LE) && \
bab55225e   Aymen Sghaier   MLK-18044-1: cryp...
175
176
  	!(defined(CONFIG_MX6) || defined(CONFIG_MX7) || \
  	  defined(CONFIG_MX7ULP) || defined(CONFIG_IMX8M))
b9eebfade   Ruchika Gupta   fsl_sec: Add hard...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  	u32 orba_l;
  	u32 orba_h;
  #else
  	u32 orba_h;
  	u32 orba_l;
  #endif
  	u32 rsvd4;
  	u32 ors;
  	u32 rsvd5;
  	u32 orjr;
  	u32 rsvd6;
  	u32 orsf;
  	u32 rsvd7;
  	u32 jrsta;
  	u32 rsvd8;
  	u32 jrint;
  	u32 jrcfg0;
  	u32 jrcfg1;
  	u32 rsvd9;
  	u32 irri;
  	u32 rsvd10;
  	u32 orwi;
  	u32 rsvd11;
  	u32 jrcr;
  };
94e3c8c4f   gaurav rana   crypto/fsl - Add ...
202
203
204
205
206
  /*
   * Scatter Gather Entry - Specifies the the Scatter Gather Format
   * related information
   */
  struct sg_entry {
f91e65a74   Ulises Cardenas   imx: Refactoring ...
207
  #if defined(CONFIG_SYS_FSL_SEC_LE) && \
bab55225e   Aymen Sghaier   MLK-18044-1: cryp...
208
209
  	!(defined(CONFIG_MX6) || defined(CONFIG_MX7) || \
  	  defined(CONFIG_MX7ULP) || defined(CONFIG_IMX8M))
94e3c8c4f   gaurav rana   crypto/fsl - Add ...
210
  	uint32_t addr_lo;	/* Memory Address - lo */
f59e69cbd   Aneesh Bansal   crypto/fsl: SEC d...
211
  	uint32_t addr_hi;	/* Memory Address of start of buffer - hi */
94e3c8c4f   gaurav rana   crypto/fsl - Add ...
212
  #else
f59e69cbd   Aneesh Bansal   crypto/fsl: SEC d...
213
  	uint32_t addr_hi;	/* Memory Address of start of buffer - hi */
94e3c8c4f   gaurav rana   crypto/fsl - Add ...
214
215
216
217
218
219
220
221
222
223
224
225
226
  	uint32_t addr_lo;	/* Memory Address - lo */
  #endif
  
  	uint32_t len_flag;	/* Length of the data in the frame */
  #define SG_ENTRY_LENGTH_MASK	0x3FFFFFFF
  #define SG_ENTRY_EXTENSION_BIT	0x80000000
  #define SG_ENTRY_FINAL_BIT	0x40000000
  	uint32_t bpid_offset;
  #define SG_ENTRY_BPID_MASK	0x00FF0000
  #define SG_ENTRY_BPID_SHIFT	16
  #define SG_ENTRY_OFFSET_MASK	0x00001FFF
  #define SG_ENTRY_OFFSET_SHIFT	0
  };
bab55225e   Aymen Sghaier   MLK-18044-1: cryp...
227
228
  #if defined(CONFIG_MX6) || defined(CONFIG_MX7) || \
  	defined(CONFIG_MX7ULP) || defined(CONFIG_IMX8M)
f91e65a74   Ulises Cardenas   imx: Refactoring ...
229
230
231
232
233
234
235
  /* Job Ring Base Address */
  #define JR_BASE_ADDR(x) (CONFIG_SYS_FSL_SEC_ADDR + 0x1000 * (x + 1))
  /* Secure Memory Offset varies accross versions */
  #define SM_V1_OFFSET 0x0f4
  #define SM_V2_OFFSET 0xa00
  /*Secure Memory Versioning */
  #define SMVID_V2 0x20105
94690dc8b   Aymen Sghaier   MLK-18044-5: cryp...
236
237
  #define SM_VERSION(x)  ({typeof(x) _x = x; \
  		_x < SMVID_V2 ? 1 : (_x < 0x20300 ? 2 : 3); })
f91e65a74   Ulises Cardenas   imx: Refactoring ...
238
  #define SM_OFFSET(x)  (x == 1 ? SM_V1_OFFSET : SM_V2_OFFSET)
0200020bc   Raul Cardenas   imx6: Added DEK b...
239
240
241
242
243
244
  /* CAAM Job Ring 0 Registers */
  /* Secure Memory Partition Owner register */
  #define SMCSJR_PO		(3 << 6)
  /* JR Allocation Error */
  #define SMCSJR_AERR		(3 << 12)
  /* Secure memory partition 0 page 0 owner register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
245
  #define CAAM_SMPO_0	    (CONFIG_SYS_FSL_SEC_ADDR + 0x1FBC)
0200020bc   Raul Cardenas   imx6: Added DEK b...
246
  /* Secure memory command register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
247
  #define CAAM_SMCJR(v, jr)   (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_CMD(v))
0200020bc   Raul Cardenas   imx6: Added DEK b...
248
  /* Secure memory command status register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
249
  #define CAAM_SMCSJR(v, jr)  (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_STATUS(v))
0200020bc   Raul Cardenas   imx6: Added DEK b...
250
  /* Secure memory access permissions register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
251
252
  #define CAAM_SMAPJR(v, jr, y) \
  	(JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_PERM(v) + y * 16)
0200020bc   Raul Cardenas   imx6: Added DEK b...
253
  /* Secure memory access group 2 register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
254
255
  #define CAAM_SMAG2JR(v, jr, y) \
  	(JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_GROUP2(v) + y * 16)
0200020bc   Raul Cardenas   imx6: Added DEK b...
256
  /* Secure memory access group 1 register */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
257
258
  #define CAAM_SMAG1JR(v, jr, y)  \
  	(JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_GROUP1(v) + y * 16)
0200020bc   Raul Cardenas   imx6: Added DEK b...
259
260
  
  /* Commands and macros for secure memory */
f91e65a74   Ulises Cardenas   imx: Refactoring ...
261
262
263
  #define SM_CMD(v)		(v == 1 ? 0x0 : 0x1E4)
  #define SM_STATUS(v)		(v == 1 ? 0x8 : 0x1EC)
  #define SM_PERM(v)		(v == 1 ?  0x10 : 0x4)
94690dc8b   Aymen Sghaier   MLK-18044-5: cryp...
264
265
266
267
  #define SM_GROUP2(v)		({typeof(v) _v = v; \
  		_v == 1 ? 0x14 : (_v == 2 ? 0x8 : 0xC); })
  #define SM_GROUP1(v)		({typeof(v) _v = v; \
  		_v == 1 ? 0x18 : (_v == 2 ? 0xC : 0x8); })
0200020bc   Raul Cardenas   imx6: Added DEK b...
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
  #define CMD_PAGE_ALLOC		0x1
  #define CMD_PAGE_DEALLOC	0x2
  #define CMD_PART_DEALLOC	0x3
  #define CMD_INQUIRY		0x5
  #define CMD_COMPLETE		(3 << 14)
  #define PAGE_AVAILABLE		0
  #define PAGE_OWNED		(3 << 6)
  #define PAGE(x)			(x << 16)
  #define PARTITION(x)		(x << 8)
  #define PARTITION_OWNER(x)	(0x3 << (x*2))
  
  /* Address of secure 4kbyte pages */
  #define SEC_MEM_PAGE0		CAAM_ARB_BASE_ADDR
  #define SEC_MEM_PAGE1		(CAAM_ARB_BASE_ADDR + 0x1000)
  #define SEC_MEM_PAGE2		(CAAM_ARB_BASE_ADDR + 0x2000)
  #define SEC_MEM_PAGE3		(CAAM_ARB_BASE_ADDR + 0x3000)
94690dc8b   Aymen Sghaier   MLK-18044-5: cryp...
284
285
286
287
288
289
290
291
292
  #ifdef CONFIG_IMX8M
  #define JR_MID    (1)         /* Matches ATF configuration */
  #define KS_G1     (0x10000 << JR_MID) /* CAAM only */
  #define PERM      (0xB080)    /* CSP, SMAP_LCK, SMAG_LCK, G1_BLOB */
  #else
  #define JR_MID    (2)         /* Matches ROM configuration */
  #define KS_G1     BIT(JR_MID) /* CAAM only */
  #define PERM      (0xB008)    /* CSP, SMAP_LCK, SMAG_LCK, G1_BLOB */
  #endif /* CONFIG_IMX8M */
0200020bc   Raul Cardenas   imx6: Added DEK b...
293

0200020bc   Raul Cardenas   imx6: Added DEK b...
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
  /* HAB WRAPPED KEY header */
  #define WRP_HDR_SIZE		0x08
  #define HDR_TAG			0x81
  #define HDR_PAR			0x41
  /* HAB WRAPPED KEY Data */
  #define HAB_MOD			0x66
  #define HAB_ALG			0x55
  #define HAB_FLG			0x00
  
  /* Partition and Page IDs */
  #define PARTITION_1	1
  #define PAGE_1			1
  
  #define ERROR_IN_PAGE_ALLOC	1
  #define ECONSTRJDESC   -1
  
  #endif
d82c850a5   Breno Lima   MLK-18169 imx: im...
311
312
313
  #define FSL_CAAM_MP_PUBK_BYTES		    64
  #define FSL_CAAM_MP_PRVK_BYTES		    32
  #define FSL_CAAM_MP_MES_DGST_BYTES	    32
864316b3b   Breno Lima   MLK-17915: cmd: b...
314
315
  #define FSL_CAAM_ORSR_JRa_OFFSET	0x102c
  #define FSL_CAAM_MAX_JR_SIZE		4
0200020bc   Raul Cardenas   imx6: Added DEK b...
316
317
318
319
320
321
322
323
  /* blob_dek:
   * Encapsulates the src in a secure blob and stores it dst
   * @src: reference to the plaintext
   * @dst: reference to the output adrress
   * @len: size in bytes of src
   * @return: 0 on success, error otherwise
   */
  int blob_dek(const u8 *src, u8 *dst, u8 len);
d82c850a5   Breno Lima   MLK-18169 imx: im...
324
325
326
  int gen_mppubk(u8 *dst);
  
  int sign_mppubk(const u8 *m, int data_size, u8 *dgst, u8 *c, u8 *d);
4fd64746b   York Sun   powerpc: C29X: Mo...
327
  #if defined(CONFIG_ARCH_C29X)
76394c9c9   Alex Porosanu   crypto/fsl: add s...
328
329
330
  int sec_init_idx(uint8_t);
  #endif
  int sec_init(void);
48ef0d2a1   Ruchika Gupta   fsl_sec : Move SE...
331
332
333
  #endif
  
  #endif /* __FSL_SEC_H */