1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2008-2016 Freescale Semiconductor Inc.
8 #ifndef __RTA_MATH_CMD_H__
9 #define __RTA_MATH_CMD_H__
11 extern enum rta_sec_era rta_sec_era;
13 static const uint32_t math_op1[][2] = {
14 /*1*/ { MATH0, MATH_SRC0_REG0 },
15 { MATH1, MATH_SRC0_REG1 },
16 { MATH2, MATH_SRC0_REG2 },
17 { MATH3, MATH_SRC0_REG3 },
18 { SEQINSZ, MATH_SRC0_SEQINLEN },
19 { SEQOUTSZ, MATH_SRC0_SEQOUTLEN },
20 { VSEQINSZ, MATH_SRC0_VARSEQINLEN },
21 { VSEQOUTSZ, MATH_SRC0_VARSEQOUTLEN },
22 { ZERO, MATH_SRC0_ZERO },
23 /*10*/ { NONE, 0 }, /* dummy value */
24 { DPOVRD, MATH_SRC0_DPOVRD },
25 { ONE, MATH_SRC0_ONE }
29 * Allowed MATH op1 sources for each SEC Era.
30 * Values represent the number of entries from math_op1[] that are supported.
32 static const unsigned int math_op1_sz[] = {10, 10, 12, 12, 12, 12, 12, 12};
34 static const uint32_t math_op2[][2] = {
35 /*1*/ { MATH0, MATH_SRC1_REG0 },
36 { MATH1, MATH_SRC1_REG1 },
37 { MATH2, MATH_SRC1_REG2 },
38 { MATH3, MATH_SRC1_REG3 },
39 { ABD, MATH_SRC1_INFIFO },
40 { OFIFO, MATH_SRC1_OUTFIFO },
41 { ONE, MATH_SRC1_ONE },
42 /*8*/ { NONE, 0 }, /* dummy value */
43 { JOBSRC, MATH_SRC1_JOBSOURCE },
44 { DPOVRD, MATH_SRC1_DPOVRD },
45 { VSEQINSZ, MATH_SRC1_VARSEQINLEN },
46 { VSEQOUTSZ, MATH_SRC1_VARSEQOUTLEN },
47 /*13*/ { ZERO, MATH_SRC1_ZERO }
51 * Allowed MATH op2 sources for each SEC Era.
52 * Values represent the number of entries from math_op2[] that are supported.
54 static const unsigned int math_op2_sz[] = {8, 9, 13, 13, 13, 13, 13, 13};
56 static const uint32_t math_result[][2] = {
57 /*1*/ { MATH0, MATH_DEST_REG0 },
58 { MATH1, MATH_DEST_REG1 },
59 { MATH2, MATH_DEST_REG2 },
60 { MATH3, MATH_DEST_REG3 },
61 { SEQINSZ, MATH_DEST_SEQINLEN },
62 { SEQOUTSZ, MATH_DEST_SEQOUTLEN },
63 { VSEQINSZ, MATH_DEST_VARSEQINLEN },
64 { VSEQOUTSZ, MATH_DEST_VARSEQOUTLEN },
65 /*9*/ { NONE, MATH_DEST_NONE },
66 { DPOVRD, MATH_DEST_DPOVRD }
70 * Allowed MATH result destinations for each SEC Era.
71 * Values represent the number of entries from math_result[] that are
74 static const unsigned int math_result_sz[] = {9, 9, 10, 10, 10, 10, 10, 10};
77 rta_math(struct program *program, uint64_t operand1,
78 uint32_t op, uint64_t operand2, uint32_t result,
79 int length, uint32_t options)
81 uint32_t opcode = CMD_MATH;
84 unsigned int start_pc = program->current_pc;
86 if (((op == MATH_FUN_BSWAP) && (rta_sec_era < RTA_SEC_ERA_4)) ||
87 ((op == MATH_FUN_ZBYT) && (rta_sec_era < RTA_SEC_ERA_2))) {
88 pr_err("MATH: operation not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
89 USER_SEC_ERA(rta_sec_era), program->current_pc,
90 program->current_instruction);
95 if (rta_sec_era < RTA_SEC_ERA_7) {
96 pr_err("MATH: operation not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
97 USER_SEC_ERA(rta_sec_era), program->current_pc,
98 program->current_instruction);
102 if ((options & IFB) ||
103 (!(options & IMMED) && !(options & IMMED2)) ||
104 ((options & IMMED) && (options & IMMED2))) {
105 pr_err("MATH: SWP - invalid configuration. SEC PC: %d; Instr: %d\n",
107 program->current_instruction);
113 * SHLD operation is different from others and we
114 * assume that we can have _NONE as first operand
115 * or _SEQINSZ as second operand
117 if ((op != MATH_FUN_SHLD) && ((operand1 == NONE) ||
118 (operand2 == SEQINSZ))) {
119 pr_err("MATH: Invalid operand. SEC PC: %d; Instr: %d\n",
120 program->current_pc, program->current_instruction);
125 * We first check if it is unary operation. In that
126 * case second operand must be _NONE
128 if (((op == MATH_FUN_ZBYT) || (op == MATH_FUN_BSWAP)) &&
129 (operand2 != NONE)) {
130 pr_err("MATH: Invalid operand2. SEC PC: %d; Instr: %d\n",
131 program->current_pc, program->current_instruction);
135 /* Write first operand field */
136 if (options & IMMED) {
137 opcode |= MATH_SRC0_IMM;
139 ret = __rta_map_opcode((uint32_t)operand1, math_op1,
140 math_op1_sz[rta_sec_era], &val);
142 pr_err("MATH: operand1 not supported. SEC PC: %d; Instr: %d\n",
144 program->current_instruction);
150 /* Write second operand field */
151 if (options & IMMED2) {
152 opcode |= MATH_SRC1_IMM;
154 ret = __rta_map_opcode((uint32_t)operand2, math_op2,
155 math_op2_sz[rta_sec_era], &val);
157 pr_err("MATH: operand2 not supported. SEC PC: %d; Instr: %d\n",
159 program->current_instruction);
165 /* Write result field */
166 ret = __rta_map_opcode(result, math_result, math_result_sz[rta_sec_era],
169 pr_err("MATH: result not supported. SEC PC: %d; Instr: %d\n",
170 program->current_pc, program->current_instruction);
176 * as we encode operations with their "real" values, we do not
177 * to translate but we do need to validate the value
180 /*Binary operators */
182 case (MATH_FUN_ADDC):
184 case (MATH_FUN_SUBB):
188 case (MATH_FUN_LSHIFT):
189 case (MATH_FUN_RSHIFT):
190 case (MATH_FUN_SHLD):
191 /* Unary operators */
192 case (MATH_FUN_ZBYT):
193 case (MATH_FUN_BSWAP):
197 pr_err("MATH: operator is not supported. SEC PC: %d; Instr: %d\n",
198 program->current_pc, program->current_instruction);
203 opcode |= (options & ~(IMMED | IMMED2));
208 opcode |= MATH_LEN_1BYTE;
211 opcode |= MATH_LEN_2BYTE;
214 opcode |= MATH_LEN_4BYTE;
217 opcode |= MATH_LEN_8BYTE;
220 pr_err("MATH: length is not supported. SEC PC: %d; Instr: %d\n",
221 program->current_pc, program->current_instruction);
226 __rta_out32(program, opcode);
227 program->current_instruction++;
229 /* Write immediate value */
230 if ((options & IMMED) && !(options & IMMED2)) {
231 __rta_out64(program, (length > 4) && !(options & IFB),
233 } else if ((options & IMMED2) && !(options & IMMED)) {
234 __rta_out64(program, (length > 4) && !(options & IFB),
236 } else if ((options & IMMED) && (options & IMMED2)) {
237 __rta_out32(program, lower_32_bits(operand1));
238 __rta_out32(program, lower_32_bits(operand2));
241 return (int)start_pc;
244 program->first_error_pc = start_pc;
245 program->current_instruction++;
250 rta_mathi(struct program *program, uint64_t operand,
251 uint32_t op, uint8_t imm, uint32_t result,
252 int length, uint32_t options)
254 uint32_t opcode = CMD_MATHI;
257 unsigned int start_pc = program->current_pc;
259 if (rta_sec_era < RTA_SEC_ERA_6) {
260 pr_err("MATHI: Command not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
261 USER_SEC_ERA(rta_sec_era), program->current_pc,
262 program->current_instruction);
266 if (((op == MATH_FUN_FBYT) && (options & SSEL))) {
267 pr_err("MATHI: Illegal combination - FBYT and SSEL. SEC PC: %d; Instr: %d\n",
268 program->current_pc, program->current_instruction);
272 if ((options & SWP) && (rta_sec_era < RTA_SEC_ERA_7)) {
273 pr_err("MATHI: SWP not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
274 USER_SEC_ERA(rta_sec_era), program->current_pc,
275 program->current_instruction);
279 /* Write first operand field */
280 if (!(options & SSEL))
281 ret = __rta_map_opcode((uint32_t)operand, math_op1,
282 math_op1_sz[rta_sec_era], &val);
284 ret = __rta_map_opcode((uint32_t)operand, math_op2,
285 math_op2_sz[rta_sec_era], &val);
287 pr_err("MATHI: operand not supported. SEC PC: %d; Instr: %d\n",
288 program->current_pc, program->current_instruction);
292 if (!(options & SSEL))
295 opcode |= (val << (MATHI_SRC1_SHIFT - MATH_SRC1_SHIFT));
297 /* Write second operand field */
298 opcode |= (imm << MATHI_IMM_SHIFT);
300 /* Write result field */
301 ret = __rta_map_opcode(result, math_result, math_result_sz[rta_sec_era],
304 pr_err("MATHI: result not supported. SEC PC: %d; Instr: %d\n",
305 program->current_pc, program->current_instruction);
308 opcode |= (val << (MATHI_DEST_SHIFT - MATH_DEST_SHIFT));
311 * as we encode operations with their "real" values, we do not have to
312 * translate but we do need to validate the value
316 case (MATH_FUN_ADDC):
318 case (MATH_FUN_SUBB):
322 case (MATH_FUN_LSHIFT):
323 case (MATH_FUN_RSHIFT):
324 case (MATH_FUN_FBYT):
328 pr_err("MATHI: operator not supported. SEC PC: %d; Instr: %d\n",
329 program->current_pc, program->current_instruction);
339 opcode |= MATH_LEN_1BYTE;
342 opcode |= MATH_LEN_2BYTE;
345 opcode |= MATH_LEN_4BYTE;
348 opcode |= MATH_LEN_8BYTE;
351 pr_err("MATHI: length %d not supported. SEC PC: %d; Instr: %d\n",
352 length, program->current_pc,
353 program->current_instruction);
358 __rta_out32(program, opcode);
359 program->current_instruction++;
361 return (int)start_pc;
364 program->first_error_pc = start_pc;
365 program->current_instruction++;
369 #endif /* __RTA_MATH_CMD_H__ */