2 * Copyright 2008-2016 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: BSD-3-Clause or GPL-2.0+
7 #ifndef __RTA_MATH_CMD_H__
8 #define __RTA_MATH_CMD_H__
10 extern enum rta_sec_era rta_sec_era;
12 static const uint32_t math_op1[][2] = {
13 /*1*/ { MATH0, MATH_SRC0_REG0 },
14 { MATH1, MATH_SRC0_REG1 },
15 { MATH2, MATH_SRC0_REG2 },
16 { MATH3, MATH_SRC0_REG3 },
17 { SEQINSZ, MATH_SRC0_SEQINLEN },
18 { SEQOUTSZ, MATH_SRC0_SEQOUTLEN },
19 { VSEQINSZ, MATH_SRC0_VARSEQINLEN },
20 { VSEQOUTSZ, MATH_SRC0_VARSEQOUTLEN },
21 { ZERO, MATH_SRC0_ZERO },
22 /*10*/ { NONE, 0 }, /* dummy value */
23 { DPOVRD, MATH_SRC0_DPOVRD },
24 { ONE, MATH_SRC0_ONE }
28 * Allowed MATH op1 sources for each SEC Era.
29 * Values represent the number of entries from math_op1[] that are supported.
31 static const unsigned int math_op1_sz[] = {10, 10, 12, 12, 12, 12, 12, 12};
33 static const uint32_t math_op2[][2] = {
34 /*1*/ { MATH0, MATH_SRC1_REG0 },
35 { MATH1, MATH_SRC1_REG1 },
36 { MATH2, MATH_SRC1_REG2 },
37 { MATH3, MATH_SRC1_REG3 },
38 { ABD, MATH_SRC1_INFIFO },
39 { OFIFO, MATH_SRC1_OUTFIFO },
40 { ONE, MATH_SRC1_ONE },
41 /*8*/ { NONE, 0 }, /* dummy value */
42 { JOBSRC, MATH_SRC1_JOBSOURCE },
43 { DPOVRD, MATH_SRC1_DPOVRD },
44 { VSEQINSZ, MATH_SRC1_VARSEQINLEN },
45 { VSEQOUTSZ, MATH_SRC1_VARSEQOUTLEN },
46 /*13*/ { ZERO, MATH_SRC1_ZERO }
50 * Allowed MATH op2 sources for each SEC Era.
51 * Values represent the number of entries from math_op2[] that are supported.
53 static const unsigned int math_op2_sz[] = {8, 9, 13, 13, 13, 13, 13, 13};
55 static const uint32_t math_result[][2] = {
56 /*1*/ { MATH0, MATH_DEST_REG0 },
57 { MATH1, MATH_DEST_REG1 },
58 { MATH2, MATH_DEST_REG2 },
59 { MATH3, MATH_DEST_REG3 },
60 { SEQINSZ, MATH_DEST_SEQINLEN },
61 { SEQOUTSZ, MATH_DEST_SEQOUTLEN },
62 { VSEQINSZ, MATH_DEST_VARSEQINLEN },
63 { VSEQOUTSZ, MATH_DEST_VARSEQOUTLEN },
64 /*9*/ { NONE, MATH_DEST_NONE },
65 { DPOVRD, MATH_DEST_DPOVRD }
69 * Allowed MATH result destinations for each SEC Era.
70 * Values represent the number of entries from math_result[] that are
73 static const unsigned int math_result_sz[] = {9, 9, 10, 10, 10, 10, 10, 10};
76 rta_math(struct program *program, uint64_t operand1,
77 uint32_t op, uint64_t operand2, uint32_t result,
78 int length, uint32_t options)
80 uint32_t opcode = CMD_MATH;
83 unsigned int start_pc = program->current_pc;
85 if (((op == MATH_FUN_BSWAP) && (rta_sec_era < RTA_SEC_ERA_4)) ||
86 ((op == MATH_FUN_ZBYT) && (rta_sec_era < RTA_SEC_ERA_2))) {
87 pr_err("MATH: operation not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
88 USER_SEC_ERA(rta_sec_era), program->current_pc,
89 program->current_instruction);
94 if (rta_sec_era < RTA_SEC_ERA_7) {
95 pr_err("MATH: operation not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
96 USER_SEC_ERA(rta_sec_era), program->current_pc,
97 program->current_instruction);
101 if ((options & IFB) ||
102 (!(options & IMMED) && !(options & IMMED2)) ||
103 ((options & IMMED) && (options & IMMED2))) {
104 pr_err("MATH: SWP - invalid configuration. SEC PC: %d; Instr: %d\n",
106 program->current_instruction);
112 * SHLD operation is different from others and we
113 * assume that we can have _NONE as first operand
114 * or _SEQINSZ as second operand
116 if ((op != MATH_FUN_SHLD) && ((operand1 == NONE) ||
117 (operand2 == SEQINSZ))) {
118 pr_err("MATH: Invalid operand. SEC PC: %d; Instr: %d\n",
119 program->current_pc, program->current_instruction);
124 * We first check if it is unary operation. In that
125 * case second operand must be _NONE
127 if (((op == MATH_FUN_ZBYT) || (op == MATH_FUN_BSWAP)) &&
128 (operand2 != NONE)) {
129 pr_err("MATH: Invalid operand2. SEC PC: %d; Instr: %d\n",
130 program->current_pc, program->current_instruction);
134 /* Write first operand field */
135 if (options & IMMED) {
136 opcode |= MATH_SRC0_IMM;
138 ret = __rta_map_opcode((uint32_t)operand1, math_op1,
139 math_op1_sz[rta_sec_era], &val);
141 pr_err("MATH: operand1 not supported. SEC PC: %d; Instr: %d\n",
143 program->current_instruction);
149 /* Write second operand field */
150 if (options & IMMED2) {
151 opcode |= MATH_SRC1_IMM;
153 ret = __rta_map_opcode((uint32_t)operand2, math_op2,
154 math_op2_sz[rta_sec_era], &val);
156 pr_err("MATH: operand2 not supported. SEC PC: %d; Instr: %d\n",
158 program->current_instruction);
164 /* Write result field */
165 ret = __rta_map_opcode(result, math_result, math_result_sz[rta_sec_era],
168 pr_err("MATH: result not supported. SEC PC: %d; Instr: %d\n",
169 program->current_pc, program->current_instruction);
175 * as we encode operations with their "real" values, we do not
176 * to translate but we do need to validate the value
179 /*Binary operators */
181 case (MATH_FUN_ADDC):
183 case (MATH_FUN_SUBB):
187 case (MATH_FUN_LSHIFT):
188 case (MATH_FUN_RSHIFT):
189 case (MATH_FUN_SHLD):
190 /* Unary operators */
191 case (MATH_FUN_ZBYT):
192 case (MATH_FUN_BSWAP):
196 pr_err("MATH: operator is not supported. SEC PC: %d; Instr: %d\n",
197 program->current_pc, program->current_instruction);
202 opcode |= (options & ~(IMMED | IMMED2));
207 opcode |= MATH_LEN_1BYTE;
210 opcode |= MATH_LEN_2BYTE;
213 opcode |= MATH_LEN_4BYTE;
216 opcode |= MATH_LEN_8BYTE;
219 pr_err("MATH: length is not supported. SEC PC: %d; Instr: %d\n",
220 program->current_pc, program->current_instruction);
225 __rta_out32(program, opcode);
226 program->current_instruction++;
228 /* Write immediate value */
229 if ((options & IMMED) && !(options & IMMED2)) {
230 __rta_out64(program, (length > 4) && !(options & IFB),
232 } else if ((options & IMMED2) && !(options & IMMED)) {
233 __rta_out64(program, (length > 4) && !(options & IFB),
235 } else if ((options & IMMED) && (options & IMMED2)) {
236 __rta_out32(program, lower_32_bits(operand1));
237 __rta_out32(program, lower_32_bits(operand2));
240 return (int)start_pc;
243 program->first_error_pc = start_pc;
244 program->current_instruction++;
249 rta_mathi(struct program *program, uint64_t operand,
250 uint32_t op, uint8_t imm, uint32_t result,
251 int length, uint32_t options)
253 uint32_t opcode = CMD_MATHI;
256 unsigned int start_pc = program->current_pc;
258 if (rta_sec_era < RTA_SEC_ERA_6) {
259 pr_err("MATHI: Command not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
260 USER_SEC_ERA(rta_sec_era), program->current_pc,
261 program->current_instruction);
265 if (((op == MATH_FUN_FBYT) && (options & SSEL))) {
266 pr_err("MATHI: Illegal combination - FBYT and SSEL. SEC PC: %d; Instr: %d\n",
267 program->current_pc, program->current_instruction);
271 if ((options & SWP) && (rta_sec_era < RTA_SEC_ERA_7)) {
272 pr_err("MATHI: SWP not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
273 USER_SEC_ERA(rta_sec_era), program->current_pc,
274 program->current_instruction);
278 /* Write first operand field */
279 if (!(options & SSEL))
280 ret = __rta_map_opcode((uint32_t)operand, math_op1,
281 math_op1_sz[rta_sec_era], &val);
283 ret = __rta_map_opcode((uint32_t)operand, math_op2,
284 math_op2_sz[rta_sec_era], &val);
286 pr_err("MATHI: operand not supported. SEC PC: %d; Instr: %d\n",
287 program->current_pc, program->current_instruction);
291 if (!(options & SSEL))
294 opcode |= (val << (MATHI_SRC1_SHIFT - MATH_SRC1_SHIFT));
296 /* Write second operand field */
297 opcode |= (imm << MATHI_IMM_SHIFT);
299 /* Write result field */
300 ret = __rta_map_opcode(result, math_result, math_result_sz[rta_sec_era],
303 pr_err("MATHI: result not supported. SEC PC: %d; Instr: %d\n",
304 program->current_pc, program->current_instruction);
307 opcode |= (val << (MATHI_DEST_SHIFT - MATH_DEST_SHIFT));
310 * as we encode operations with their "real" values, we do not have to
311 * translate but we do need to validate the value
315 case (MATH_FUN_ADDC):
317 case (MATH_FUN_SUBB):
321 case (MATH_FUN_LSHIFT):
322 case (MATH_FUN_RSHIFT):
323 case (MATH_FUN_FBYT):
327 pr_err("MATHI: operator not supported. SEC PC: %d; Instr: %d\n",
328 program->current_pc, program->current_instruction);
338 opcode |= MATH_LEN_1BYTE;
341 opcode |= MATH_LEN_2BYTE;
344 opcode |= MATH_LEN_4BYTE;
347 opcode |= MATH_LEN_8BYTE;
350 pr_err("MATHI: length %d not supported. SEC PC: %d; Instr: %d\n",
351 length, program->current_pc,
352 program->current_instruction);
357 __rta_out32(program, opcode);
358 program->current_instruction++;
360 return (int)start_pc;
363 program->first_error_pc = start_pc;
364 program->current_instruction++;
368 #endif /* __RTA_MATH_CMD_H__ */