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