Branch data Line data Source code
1 : : /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 : : *
3 : : * Copyright 2008-2016 Freescale Semiconductor Inc.
4 : : * Copyright 2016,2019 NXP
5 : : */
6 : :
7 : : #ifndef __RTA_HEADER_CMD_H__
8 : : #define __RTA_HEADER_CMD_H__
9 : :
10 : : extern enum rta_sec_era rta_sec_era;
11 : :
12 : : /* Allowed job header flags for each SEC Era. */
13 : : static const uint32_t job_header_flags[] = {
14 : : DNR | TD | MTD | SHR | REO,
15 : : DNR | TD | MTD | SHR | REO | RSMS,
16 : : DNR | TD | MTD | SHR | REO | RSMS,
17 : : DNR | TD | MTD | SHR | REO | RSMS,
18 : : DNR | TD | MTD | SHR | REO | RSMS | EXT,
19 : : DNR | TD | MTD | SHR | REO | RSMS | EXT,
20 : : DNR | TD | MTD | SHR | REO | RSMS | EXT,
21 : : DNR | TD | MTD | SHR | REO | EXT,
22 : : DNR | TD | MTD | SHR | REO | EXT,
23 : : DNR | TD | MTD | SHR | REO | EXT
24 : : };
25 : :
26 : : /* Allowed shared header flags for each SEC Era. */
27 : : static const uint32_t shr_header_flags[] = {
28 : : DNR | SC | PD,
29 : : DNR | SC | PD | CIF,
30 : : DNR | SC | PD | CIF,
31 : : DNR | SC | PD | CIF | RIF,
32 : : DNR | SC | PD | CIF | RIF,
33 : : DNR | SC | PD | CIF | RIF,
34 : : DNR | SC | PD | CIF | RIF,
35 : : DNR | SC | PD | CIF | RIF,
36 : : DNR | SC | PD | CIF | RIF,
37 : : DNR | SC | PD | CIF | RIF
38 : : };
39 : :
40 : : static inline int
41 : 0 : rta_shr_header(struct program *program,
42 : : enum rta_share_type share,
43 : : unsigned int start_idx,
44 : : uint32_t flags)
45 : : {
46 : : uint32_t opcode = CMD_SHARED_DESC_HDR;
47 : 0 : unsigned int start_pc = program->current_pc;
48 : :
49 [ # # ]: 0 : if (flags & ~shr_header_flags[rta_sec_era]) {
50 : 0 : pr_err("SHR_DESC: Flag(s) not supported by SEC Era %d\n",
51 : : USER_SEC_ERA(rta_sec_era));
52 : 0 : goto err;
53 : : }
54 : :
55 : : switch (share) {
56 : : case SHR_ALWAYS:
57 : : opcode |= HDR_SHARE_ALWAYS;
58 : : break;
59 : : case SHR_SERIAL:
60 : : opcode |= HDR_SHARE_SERIAL;
61 : : break;
62 : : case SHR_NEVER:
63 : : /*
64 : : * opcode |= HDR_SHARE_NEVER;
65 : : * HDR_SHARE_NEVER is 0
66 : : */
67 : : break;
68 : : case SHR_WAIT:
69 : : opcode |= HDR_SHARE_WAIT;
70 : : break;
71 : 0 : default:
72 : 0 : pr_err("SHR_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
73 : : program->current_pc);
74 : 0 : goto err;
75 : : }
76 : :
77 : 0 : opcode |= HDR_ONE;
78 [ # # ]: 0 : if (rta_sec_era >= RTA_SEC_ERA_10)
79 : 0 : opcode |= (start_idx << HDR_START_IDX_SHIFT) &
80 : : HDR_START_IDX_MASK_ERA10;
81 : : else
82 : 0 : opcode |= (start_idx << HDR_START_IDX_SHIFT) &
83 : : HDR_START_IDX_MASK;
84 : :
85 [ # # ]: 0 : if (flags & DNR)
86 : 0 : opcode |= HDR_DNR;
87 [ # # ]: 0 : if (flags & CIF)
88 : 0 : opcode |= HDR_CLEAR_IFIFO;
89 [ # # ]: 0 : if (flags & SC)
90 : 0 : opcode |= HDR_SAVECTX;
91 [ # # ]: 0 : if (flags & PD)
92 : 0 : opcode |= HDR_PROP_DNR;
93 [ # # ]: 0 : if (flags & RIF)
94 : 0 : opcode |= HDR_RIF;
95 : :
96 : 0 : __rta_out32(program, opcode);
97 : 0 : program->current_instruction++;
98 : :
99 [ # # ]: 0 : if (program->current_instruction == 1)
100 : 0 : program->shrhdr = program->buffer;
101 : :
102 : 0 : return (int)start_pc;
103 : :
104 : 0 : err:
105 : 0 : program->first_error_pc = start_pc;
106 : 0 : program->current_instruction++;
107 : 0 : return -EINVAL;
108 : : }
109 : :
110 : : static inline int
111 : : rta_job_header(struct program *program,
112 : : enum rta_share_type share,
113 : : unsigned int start_idx,
114 : : uint64_t shr_desc, uint32_t flags,
115 : : uint32_t ext_flags)
116 : : {
117 : : uint32_t opcode = CMD_DESC_HDR;
118 : : uint32_t hdr_ext = 0;
119 : : unsigned int start_pc = program->current_pc;
120 : :
121 : : if (flags & ~job_header_flags[rta_sec_era]) {
122 : : pr_err("JOB_DESC: Flag(s) not supported by SEC Era %d\n",
123 : : USER_SEC_ERA(rta_sec_era));
124 : : goto err;
125 : : }
126 : :
127 : : switch (share) {
128 : : case SHR_ALWAYS:
129 : : opcode |= HDR_SHARE_ALWAYS;
130 : : break;
131 : : case SHR_SERIAL:
132 : : opcode |= HDR_SHARE_SERIAL;
133 : : break;
134 : : case SHR_NEVER:
135 : : /*
136 : : * opcode |= HDR_SHARE_NEVER;
137 : : * HDR_SHARE_NEVER is 0
138 : : */
139 : : break;
140 : : case SHR_WAIT:
141 : : opcode |= HDR_SHARE_WAIT;
142 : : break;
143 : : case SHR_DEFER:
144 : : opcode |= HDR_SHARE_DEFER;
145 : : break;
146 : : default:
147 : : pr_err("JOB_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
148 : : program->current_pc);
149 : : goto err;
150 : : }
151 : :
152 : : if ((flags & TD) && (flags & REO)) {
153 : : pr_err("JOB_DESC: REO flag not supported for trusted descriptors. SEC Program Line: %d\n",
154 : : program->current_pc);
155 : : goto err;
156 : : }
157 : :
158 : : if ((flags & EXT) && !(flags & SHR) && (start_idx < 2)) {
159 : : pr_err("JOB_DESC: Start index must be >= 2 in case of no SHR and EXT. SEC Program Line: %d\n",
160 : : program->current_pc);
161 : : goto err;
162 : : }
163 : :
164 : : opcode |= HDR_ONE;
165 : : if (rta_sec_era >= RTA_SEC_ERA_10)
166 : : opcode |= (start_idx << HDR_START_IDX_SHIFT) &
167 : : HDR_START_IDX_MASK_ERA10;
168 : : else
169 : : opcode |= (start_idx << HDR_START_IDX_SHIFT) &
170 : : HDR_START_IDX_MASK;
171 : :
172 : : if (flags & EXT) {
173 : : opcode |= HDR_EXT;
174 : :
175 : : if (ext_flags & DSV) {
176 : : hdr_ext |= HDR_EXT_DSEL_VALID;
177 : : hdr_ext |= ext_flags & DSEL_MASK;
178 : : }
179 : :
180 : : if (ext_flags & FTD)
181 : : hdr_ext |= HDR_EXT_FTD;
182 : : }
183 : : if (flags & RSMS)
184 : : opcode |= HDR_RSLS;
185 : : if (flags & DNR)
186 : : opcode |= HDR_DNR;
187 : : if (flags & TD)
188 : : opcode |= HDR_TRUSTED;
189 : : if (flags & MTD)
190 : : opcode |= HDR_MAKE_TRUSTED;
191 : : if (flags & REO)
192 : : opcode |= HDR_REVERSE;
193 : : if (flags & SHR)
194 : : opcode |= HDR_SHARED;
195 : :
196 : : __rta_out32(program, opcode);
197 : : program->current_instruction++;
198 : :
199 : : if (program->current_instruction == 1) {
200 : : program->jobhdr = program->buffer;
201 : :
202 : : if (opcode & HDR_SHARED)
203 : : __rta_out64(program, program->ps, shr_desc);
204 : : }
205 : :
206 : : if (flags & EXT)
207 : : __rta_out32(program, hdr_ext);
208 : :
209 : : /* Note: descriptor length is set in program_finalize routine */
210 : : return (int)start_pc;
211 : :
212 : : err:
213 : : program->first_error_pc = start_pc;
214 : : program->current_instruction++;
215 : : return -EINVAL;
216 : : }
217 : :
218 : : #endif /* __RTA_HEADER_CMD_H__ */
|