eg_asm.c revision 89dc31a28d8e5607989ec11cfd29310c1c97f6ac
1/*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <stdio.h>
24#include <errno.h>
25#include "util/u_memory.h"
26#include "r600_pipe.h"
27#include "r600_asm.h"
28#include "eg_sq.h"
29#include "r600_opcodes.h"
30#include "evergreend.h"
31
32int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf)
33{
34	unsigned id = cf->id;
35
36	switch (cf->inst) {
37	case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3):
38	case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER << 3):
39	case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER << 3):
40	case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3):
41		bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) |
42			S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache[0].mode) |
43			S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf->kcache[0].bank) |
44			S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf->kcache[1].bank);
45		bc->bytecode[id++] = S_SQ_CF_ALU_WORD1_CF_INST(cf->inst >> 3) |
46			S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf->kcache[1].mode) |
47			S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf->kcache[0].addr) |
48			S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf->kcache[1].addr) |
49					S_SQ_CF_ALU_WORD1_BARRIER(1) |
50					S_SQ_CF_ALU_WORD1_COUNT((cf->ndw / 2) - 1);
51		break;
52	case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX:
53	case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX:
54		bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->addr >> 1);
55		bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
56					S_SQ_CF_WORD1_BARRIER(1) |
57					S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1);
58		break;
59	case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
60	case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
61		bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) |
62			S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) |
63			S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) |
64			S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type);
65		bc->bytecode[id] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf->output.burst_count - 1) |
66			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf->output.swizzle_x) |
67			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf->output.swizzle_y) |
68			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf->output.swizzle_z) |
69			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf->output.swizzle_w) |
70			S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->output.barrier) |
71			S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf->output.inst);
72		if (bc->chip_class == EVERGREEN) /* no EOP on cayman */
73			bc->bytecode[id] |= S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->output.end_of_program);
74		id++;
75
76		break;
77	case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP:
78	case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE:
79	case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP:
80	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL:
81	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END:
82	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE:
83	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK:
84	case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS:
85	case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN:
86	case CM_V_SQ_CF_WORD1_SQ_CF_INST_END:
87		bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->cf_addr >> 1);
88		bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
89					S_SQ_CF_WORD1_BARRIER(1) |
90					S_SQ_CF_WORD1_COND(cf->cond) |
91					S_SQ_CF_WORD1_POP_COUNT(cf->pop_count);
92
93		break;
94	default:
95		R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst);
96		return -EINVAL;
97	}
98	return 0;
99}
100