2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2008-2016 Freescale Semiconductor Inc.
8 * Copyright (c) 2016 NXP.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
41 #ifndef __RTA_MATH_CMD_H__
42 #define __RTA_MATH_CMD_H__
44 extern enum rta_sec_era rta_sec_era;
46 static const uint32_t math_op1[][2] = {
47 /*1*/ { MATH0, MATH_SRC0_REG0 },
48 { MATH1, MATH_SRC0_REG1 },
49 { MATH2, MATH_SRC0_REG2 },
50 { MATH3, MATH_SRC0_REG3 },
51 { SEQINSZ, MATH_SRC0_SEQINLEN },
52 { SEQOUTSZ, MATH_SRC0_SEQOUTLEN },
53 { VSEQINSZ, MATH_SRC0_VARSEQINLEN },
54 { VSEQOUTSZ, MATH_SRC0_VARSEQOUTLEN },
55 { ZERO, MATH_SRC0_ZERO },
56 /*10*/ { NONE, 0 }, /* dummy value */
57 { DPOVRD, MATH_SRC0_DPOVRD },
58 { ONE, MATH_SRC0_ONE }
62 * Allowed MATH op1 sources for each SEC Era.
63 * Values represent the number of entries from math_op1[] that are supported.
65 static const unsigned int math_op1_sz[] = {10, 10, 12, 12, 12, 12, 12, 12};
67 static const uint32_t math_op2[][2] = {
68 /*1*/ { MATH0, MATH_SRC1_REG0 },
69 { MATH1, MATH_SRC1_REG1 },
70 { MATH2, MATH_SRC1_REG2 },
71 { MATH3, MATH_SRC1_REG3 },
72 { ABD, MATH_SRC1_INFIFO },
73 { OFIFO, MATH_SRC1_OUTFIFO },
74 { ONE, MATH_SRC1_ONE },
75 /*8*/ { NONE, 0 }, /* dummy value */
76 { JOBSRC, MATH_SRC1_JOBSOURCE },
77 { DPOVRD, MATH_SRC1_DPOVRD },
78 { VSEQINSZ, MATH_SRC1_VARSEQINLEN },
79 { VSEQOUTSZ, MATH_SRC1_VARSEQOUTLEN },
80 /*13*/ { ZERO, MATH_SRC1_ZERO }
84 * Allowed MATH op2 sources for each SEC Era.
85 * Values represent the number of entries from math_op2[] that are supported.
87 static const unsigned int math_op2_sz[] = {8, 9, 13, 13, 13, 13, 13, 13};
89 static const uint32_t math_result[][2] = {
90 /*1*/ { MATH0, MATH_DEST_REG0 },
91 { MATH1, MATH_DEST_REG1 },
92 { MATH2, MATH_DEST_REG2 },
93 { MATH3, MATH_DEST_REG3 },
94 { SEQINSZ, MATH_DEST_SEQINLEN },
95 { SEQOUTSZ, MATH_DEST_SEQOUTLEN },
96 { VSEQINSZ, MATH_DEST_VARSEQINLEN },
97 { VSEQOUTSZ, MATH_DEST_VARSEQOUTLEN },
98 /*9*/ { NONE, MATH_DEST_NONE },
99 { DPOVRD, MATH_DEST_DPOVRD }
103 * Allowed MATH result destinations for each SEC Era.
104 * Values represent the number of entries from math_result[] that are
107 static const unsigned int math_result_sz[] = {9, 9, 10, 10, 10, 10, 10, 10};
110 rta_math(struct program *program, uint64_t operand1,
111 uint32_t op, uint64_t operand2, uint32_t result,
112 int length, uint32_t options)
114 uint32_t opcode = CMD_MATH;
117 unsigned int start_pc = program->current_pc;
119 if (((op == MATH_FUN_BSWAP) && (rta_sec_era < RTA_SEC_ERA_4)) ||
120 ((op == MATH_FUN_ZBYT) && (rta_sec_era < RTA_SEC_ERA_2))) {
121 pr_err("MATH: operation not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
122 USER_SEC_ERA(rta_sec_era), program->current_pc,
123 program->current_instruction);
128 if (rta_sec_era < RTA_SEC_ERA_7) {
129 pr_err("MATH: operation not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
130 USER_SEC_ERA(rta_sec_era), program->current_pc,
131 program->current_instruction);
135 if ((options & IFB) ||
136 (!(options & IMMED) && !(options & IMMED2)) ||
137 ((options & IMMED) && (options & IMMED2))) {
138 pr_err("MATH: SWP - invalid configuration. SEC PC: %d; Instr: %d\n",
140 program->current_instruction);
146 * SHLD operation is different from others and we
147 * assume that we can have _NONE as first operand
148 * or _SEQINSZ as second operand
150 if ((op != MATH_FUN_SHLD) && ((operand1 == NONE) ||
151 (operand2 == SEQINSZ))) {
152 pr_err("MATH: Invalid operand. SEC PC: %d; Instr: %d\n",
153 program->current_pc, program->current_instruction);
158 * We first check if it is unary operation. In that
159 * case second operand must be _NONE
161 if (((op == MATH_FUN_ZBYT) || (op == MATH_FUN_BSWAP)) &&
162 (operand2 != NONE)) {
163 pr_err("MATH: Invalid operand2. SEC PC: %d; Instr: %d\n",
164 program->current_pc, program->current_instruction);
168 /* Write first operand field */
169 if (options & IMMED) {
170 opcode |= MATH_SRC0_IMM;
172 ret = __rta_map_opcode((uint32_t)operand1, math_op1,
173 math_op1_sz[rta_sec_era], &val);
175 pr_err("MATH: operand1 not supported. SEC PC: %d; Instr: %d\n",
177 program->current_instruction);
183 /* Write second operand field */
184 if (options & IMMED2) {
185 opcode |= MATH_SRC1_IMM;
187 ret = __rta_map_opcode((uint32_t)operand2, math_op2,
188 math_op2_sz[rta_sec_era], &val);
190 pr_err("MATH: operand2 not supported. SEC PC: %d; Instr: %d\n",
192 program->current_instruction);
198 /* Write result field */
199 ret = __rta_map_opcode(result, math_result, math_result_sz[rta_sec_era],
202 pr_err("MATH: result not supported. SEC PC: %d; Instr: %d\n",
203 program->current_pc, program->current_instruction);
209 * as we encode operations with their "real" values, we do not
210 * to translate but we do need to validate the value
213 /*Binary operators */
215 case (MATH_FUN_ADDC):
217 case (MATH_FUN_SUBB):
221 case (MATH_FUN_LSHIFT):
222 case (MATH_FUN_RSHIFT):
223 case (MATH_FUN_SHLD):
224 /* Unary operators */
225 case (MATH_FUN_ZBYT):
226 case (MATH_FUN_BSWAP):
230 pr_err("MATH: operator is not supported. SEC PC: %d; Instr: %d\n",
231 program->current_pc, program->current_instruction);
236 opcode |= (options & ~(IMMED | IMMED2));
241 opcode |= MATH_LEN_1BYTE;
244 opcode |= MATH_LEN_2BYTE;
247 opcode |= MATH_LEN_4BYTE;
250 opcode |= MATH_LEN_8BYTE;
253 pr_err("MATH: length is not supported. SEC PC: %d; Instr: %d\n",
254 program->current_pc, program->current_instruction);
259 __rta_out32(program, opcode);
260 program->current_instruction++;
262 /* Write immediate value */
263 if ((options & IMMED) && !(options & IMMED2)) {
264 __rta_out64(program, (length > 4) && !(options & IFB),
266 } else if ((options & IMMED2) && !(options & IMMED)) {
267 __rta_out64(program, (length > 4) && !(options & IFB),
269 } else if ((options & IMMED) && (options & IMMED2)) {
270 __rta_out32(program, lower_32_bits(operand1));
271 __rta_out32(program, lower_32_bits(operand2));
274 return (int)start_pc;
277 program->first_error_pc = start_pc;
278 program->current_instruction++;
283 rta_mathi(struct program *program, uint64_t operand,
284 uint32_t op, uint8_t imm, uint32_t result,
285 int length, uint32_t options)
287 uint32_t opcode = CMD_MATHI;
290 unsigned int start_pc = program->current_pc;
292 if (rta_sec_era < RTA_SEC_ERA_6) {
293 pr_err("MATHI: Command not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
294 USER_SEC_ERA(rta_sec_era), program->current_pc,
295 program->current_instruction);
299 if (((op == MATH_FUN_FBYT) && (options & SSEL))) {
300 pr_err("MATHI: Illegal combination - FBYT and SSEL. SEC PC: %d; Instr: %d\n",
301 program->current_pc, program->current_instruction);
305 if ((options & SWP) && (rta_sec_era < RTA_SEC_ERA_7)) {
306 pr_err("MATHI: SWP not supported by SEC Era %d. SEC PC: %d; Instr: %d\n",
307 USER_SEC_ERA(rta_sec_era), program->current_pc,
308 program->current_instruction);
312 /* Write first operand field */
313 if (!(options & SSEL))
314 ret = __rta_map_opcode((uint32_t)operand, math_op1,
315 math_op1_sz[rta_sec_era], &val);
317 ret = __rta_map_opcode((uint32_t)operand, math_op2,
318 math_op2_sz[rta_sec_era], &val);
320 pr_err("MATHI: operand not supported. SEC PC: %d; Instr: %d\n",
321 program->current_pc, program->current_instruction);
325 if (!(options & SSEL))
328 opcode |= (val << (MATHI_SRC1_SHIFT - MATH_SRC1_SHIFT));
330 /* Write second operand field */
331 opcode |= (imm << MATHI_IMM_SHIFT);
333 /* Write result field */
334 ret = __rta_map_opcode(result, math_result, math_result_sz[rta_sec_era],
337 pr_err("MATHI: result not supported. SEC PC: %d; Instr: %d\n",
338 program->current_pc, program->current_instruction);
341 opcode |= (val << (MATHI_DEST_SHIFT - MATH_DEST_SHIFT));
344 * as we encode operations with their "real" values, we do not have to
345 * translate but we do need to validate the value
349 case (MATH_FUN_ADDC):
351 case (MATH_FUN_SUBB):
355 case (MATH_FUN_LSHIFT):
356 case (MATH_FUN_RSHIFT):
357 case (MATH_FUN_FBYT):
361 pr_err("MATHI: operator not supported. SEC PC: %d; Instr: %d\n",
362 program->current_pc, program->current_instruction);
372 opcode |= MATH_LEN_1BYTE;
375 opcode |= MATH_LEN_2BYTE;
378 opcode |= MATH_LEN_4BYTE;
381 opcode |= MATH_LEN_8BYTE;
384 pr_err("MATHI: length %d not supported. SEC PC: %d; Instr: %d\n",
385 length, program->current_pc,
386 program->current_instruction);
391 __rta_out32(program, opcode);
392 program->current_instruction++;
394 return (int)start_pc;
397 program->first_error_pc = start_pc;
398 program->current_instruction++;
402 #endif /* __RTA_MATH_CMD_H__ */