1
2
3
4
5
6
7
8
9#ifndef __FSL_SEC_H
10#define __FSL_SEC_H
11
12#include <common.h>
13#include <asm/io.h>
14
15#ifdef CONFIG_SYS_FSL_SEC_LE
16#define sec_in32(a) in_le32(a)
17#define sec_out32(a, v) out_le32(a, v)
18#define sec_in16(a) in_le16(a)
19#define sec_clrbits32 clrbits_le32
20#define sec_setbits32 setbits_le32
21#elif defined(CONFIG_SYS_FSL_SEC_BE)
22#define sec_in32(a) in_be32(a)
23#define sec_out32(a, v) out_be32(a, v)
24#define sec_in16(a) in_be16(a)
25#define sec_clrbits32 clrbits_be32
26#define sec_setbits32 setbits_be32
27#elif defined(CONFIG_SYS_FSL_HAS_SEC)
28#error Neither CONFIG_SYS_FSL_SEC_LE nor CONFIG_SYS_FSL_SEC_BE is defined
29#endif
30
31
32#if CONFIG_SYS_FSL_SEC_COMPAT >= 4
33
34struct rng4tst {
35#define RTMCTL_PRGM 0x00010000
36#define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_SC 0
37
38
39#define RTMCTL_SAMP_MODE_RAW_ES_SC 1
40
41
42#define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_RAW_SC 2
43
44
45#define RTMCTL_SAMP_MODE_INVALID 3
46 u32 rtmctl;
47 u32 rtscmisc;
48 u32 rtpkrrng;
49#define RTSDCTL_ENT_DLY_MIN 3200
50#define RTSDCTL_ENT_DLY_MAX 12800
51 union {
52 u32 rtpkrmax;
53 u32 rtpkrsq;
54 };
55#define RTSDCTL_ENT_DLY_SHIFT 16
56#define RTSDCTL_ENT_DLY_MASK (0xffff << RTSDCTL_ENT_DLY_SHIFT)
57 u32 rtsdctl;
58 union {
59 u32 rtsblim;
60 u32 rttotsam;
61 };
62 u32 rtfreqmin;
63#define RTFRQMAX_DISABLE (1 << 20)
64 union {
65 u32 rtfreqmax;
66 u32 rtfreqcnt;
67 };
68 u32 rsvd1[40];
69#define RNG_STATE0_HANDLE_INSTANTIATED 0x00000001
70 u32 rdsta;
71 u32 rsvd2[15];
72};
73
74typedef struct ccsr_sec {
75 u32 res0;
76 u32 mcfgr;
77 u8 res1[0x4];
78 u32 scfgr;
79 struct {
80 u32 ms;
81 u32 ls;
82 } jrliodnr[4];
83 u8 res2[0x2c];
84 u32 jrstartr;
85 struct {
86 u32 ms;
87 u32 ls;
88 } rticliodnr[4];
89 u8 res3[0x1c];
90 u32 decorr;
91 struct {
92 u32 ms;
93 u32 ls;
94 } decoliodnr[8];
95 u8 res4[0x40];
96 u32 dar;
97 u32 drr;
98 u8 res5[0x4d8];
99 struct rng4tst rng;
100 u8 res6[0x8a0];
101 u32 crnr_ms;
102 u32 crnr_ls;
103 u32 ctpr_ms;
104 u32 ctpr_ls;
105 u8 res7[0x10];
106 u32 far_ms;
107 u32 far_ls;
108 u32 falr;
109 u32 fadr;
110 u8 res8[0x4];
111 u32 csta;
112 u32 smpart;
113 u32 smvid;
114 u32 rvid;
115 u32 ccbvid;
116 u32 chavid_ms;
117 u32 chavid_ls;
118 u32 chanum_ms;
119 u32 chanum_ls;
120 u32 secvid_ms;
121 u32 secvid_ls;
122 u8 res9[0x6020];
123 u32 qilcr_ms;
124 u32 qilcr_ls;
125 u8 res10[0x8fd8];
126} ccsr_sec_t;
127
128#define SEC_CTPR_MS_AXI_LIODN 0x08000000
129#define SEC_CTPR_MS_QI 0x02000000
130#define SEC_CTPR_MS_VIRT_EN_INCL 0x00000001
131#define SEC_CTPR_MS_VIRT_EN_POR 0x00000002
132#define SEC_RVID_MA 0x0f000000
133#define SEC_CHANUM_MS_JRNUM_MASK 0xf0000000
134#define SEC_CHANUM_MS_JRNUM_SHIFT 28
135#define SEC_CHANUM_MS_DECONUM_MASK 0x0f000000
136#define SEC_CHANUM_MS_DECONUM_SHIFT 24
137#define SEC_SECVID_MS_IPID_MASK 0xffff0000
138#define SEC_SECVID_MS_IPID_SHIFT 16
139#define SEC_SECVID_MS_MAJ_REV_MASK 0x0000ff00
140#define SEC_SECVID_MS_MAJ_REV_SHIFT 8
141#define SEC_CCBVID_ERA_MASK 0xff000000
142#define SEC_CCBVID_ERA_SHIFT 24
143#define SEC_SCFGR_RDBENABLE 0x00000400
144#define SEC_SCFGR_VIRT_EN 0x00008000
145#define SEC_CHAVID_LS_RNG_SHIFT 16
146#define SEC_CHAVID_RNG_LS_MASK 0x000f0000
147
148#define CONFIG_JRSTARTR_JR0 0x00000001
149
150struct jr_regs {
151#if defined(CONFIG_SYS_FSL_SEC_LE) && \
152 !(defined(CONFIG_MX6) || defined(CONFIG_MX7))
153 u32 irba_l;
154 u32 irba_h;
155#else
156 u32 irba_h;
157 u32 irba_l;
158#endif
159 u32 rsvd1;
160 u32 irs;
161 u32 rsvd2;
162 u32 irsa;
163 u32 rsvd3;
164 u32 irja;
165#if defined(CONFIG_SYS_FSL_SEC_LE) && \
166 !(defined(CONFIG_MX6) || defined(CONFIG_MX7))
167 u32 orba_l;
168 u32 orba_h;
169#else
170 u32 orba_h;
171 u32 orba_l;
172#endif
173 u32 rsvd4;
174 u32 ors;
175 u32 rsvd5;
176 u32 orjr;
177 u32 rsvd6;
178 u32 orsf;
179 u32 rsvd7;
180 u32 jrsta;
181 u32 rsvd8;
182 u32 jrint;
183 u32 jrcfg0;
184 u32 jrcfg1;
185 u32 rsvd9;
186 u32 irri;
187 u32 rsvd10;
188 u32 orwi;
189 u32 rsvd11;
190 u32 jrcr;
191};
192
193
194
195
196
197struct sg_entry {
198#if defined(CONFIG_SYS_FSL_SEC_LE) && \
199 !(defined(CONFIG_MX6) || defined(CONFIG_MX7))
200 uint32_t addr_lo;
201 uint32_t addr_hi;
202#else
203 uint32_t addr_hi;
204 uint32_t addr_lo;
205#endif
206
207 uint32_t len_flag;
208#define SG_ENTRY_LENGTH_MASK 0x3FFFFFFF
209#define SG_ENTRY_EXTENSION_BIT 0x80000000
210#define SG_ENTRY_FINAL_BIT 0x40000000
211 uint32_t bpid_offset;
212#define SG_ENTRY_BPID_MASK 0x00FF0000
213#define SG_ENTRY_BPID_SHIFT 16
214#define SG_ENTRY_OFFSET_MASK 0x00001FFF
215#define SG_ENTRY_OFFSET_SHIFT 0
216};
217
218#if defined(CONFIG_MX6) || defined(CONFIG_MX7)
219
220#define JR_BASE_ADDR(x) (CONFIG_SYS_FSL_SEC_ADDR + 0x1000 * (x + 1))
221
222#define SM_V1_OFFSET 0x0f4
223#define SM_V2_OFFSET 0xa00
224
225#define SMVID_V2 0x20105
226#define SM_VERSION(x) (x < SMVID_V2 ? 1 : 2)
227#define SM_OFFSET(x) (x == 1 ? SM_V1_OFFSET : SM_V2_OFFSET)
228
229
230#define SMCSJR_PO (3 << 6)
231
232#define SMCSJR_AERR (3 << 12)
233
234#define CAAM_SMPO_0 (CONFIG_SYS_FSL_SEC_ADDR + 0x1FBC)
235
236#define CAAM_SMCJR(v, jr) (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_CMD(v))
237
238#define CAAM_SMCSJR(v, jr) (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_STATUS(v))
239
240#define CAAM_SMAPJR(v, jr, y) \
241 (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_PERM(v) + y * 16)
242
243#define CAAM_SMAG2JR(v, jr, y) \
244 (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_GROUP2(v) + y * 16)
245
246#define CAAM_SMAG1JR(v, jr, y) \
247 (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_GROUP1(v) + y * 16)
248
249
250#define SM_CMD(v) (v == 1 ? 0x0 : 0x1E4)
251#define SM_STATUS(v) (v == 1 ? 0x8 : 0x1EC)
252#define SM_PERM(v) (v == 1 ? 0x10 : 0x4)
253#define SM_GROUP2(v) (v == 1 ? 0x14 : 0x8)
254#define SM_GROUP1(v) (v == 1 ? 0x18 : 0xC)
255#define CMD_PAGE_ALLOC 0x1
256#define CMD_PAGE_DEALLOC 0x2
257#define CMD_PART_DEALLOC 0x3
258#define CMD_INQUIRY 0x5
259#define CMD_COMPLETE (3 << 14)
260#define PAGE_AVAILABLE 0
261#define PAGE_OWNED (3 << 6)
262#define PAGE(x) (x << 16)
263#define PARTITION(x) (x << 8)
264#define PARTITION_OWNER(x) (0x3 << (x*2))
265
266
267#define SEC_MEM_PAGE0 CAAM_ARB_BASE_ADDR
268#define SEC_MEM_PAGE1 (CAAM_ARB_BASE_ADDR + 0x1000)
269#define SEC_MEM_PAGE2 (CAAM_ARB_BASE_ADDR + 0x2000)
270#define SEC_MEM_PAGE3 (CAAM_ARB_BASE_ADDR + 0x3000)
271
272#define JR_MID 2
273#define KS_G1 (1 << JR_MID)
274#define PERM 0x0000B008
275
276
277#define BLOB_SIZE(x) (x + 32 + 16)
278
279
280#define WRP_HDR_SIZE 0x08
281#define HDR_TAG 0x81
282#define HDR_PAR 0x41
283
284#define HAB_MOD 0x66
285#define HAB_ALG 0x55
286#define HAB_FLG 0x00
287
288
289#define PARTITION_1 1
290#define PAGE_1 1
291
292#define ERROR_IN_PAGE_ALLOC 1
293#define ECONSTRJDESC -1
294
295#endif
296
297
298
299
300
301
302
303
304int blob_dek(const u8 *src, u8 *dst, u8 len);
305
306#if defined(CONFIG_ARCH_C29X)
307int sec_init_idx(uint8_t);
308#endif
309int sec_init(void);
310#endif
311
312#endif
313