freedreno/afuc: Handle setsecure opcode
[mesa.git] / src / freedreno / afuc / afuc.h
1 /*
2 * Copyright (c) 2017 Rob Clark <robdclark@gmail.com>
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef _AFUC_H_
25 #define _AFUC_H_
26
27 /*
28 TODO kernel debugfs to inject packet into rb for easier experimentation. It
29 should trigger reloading pfp/me and resetting gpu..
30
31 Actually maybe it should be flag on submit ioctl to be able to deal w/ relocs,
32 should be restricted to CAP_ADMIN and probably compile option too (default=n).
33 if flag set, copy cmdstream bo contents into RB instead of IB'ing to it from
34 RB.
35 */
36
37 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
38 #define PACKED __attribute__((__packed__))
39
40 /* The opcode is encoded variable length. Opcodes less than 0x30
41 * are encoded as 5 bits followed by (rep) flag. Opcodes >= 0x30
42 * (ie. top two bits are '11' are encoded as 6 bits. See get_opc()
43 */
44 typedef enum {
45 OPC_NOP = 0x00,
46
47 OPC_ADD = 0x01, /* add immediate */
48 OPC_ADDHI = 0x02, /* add immediate (hi 32b of 64b) */
49 OPC_SUB = 0x03, /* subtract immediate */
50 OPC_SUBHI = 0x04, /* subtract immediate (hi 32b of 64b) */
51 OPC_AND = 0x05, /* AND immediate */
52 OPC_OR = 0x06, /* OR immediate */
53 OPC_XOR = 0x07, /* XOR immediate */
54 OPC_NOT = 0x08, /* bitwise not of immed (src1 ignored) */
55 OPC_SHL = 0x09, /* shift-left immediate */
56 OPC_USHR = 0x0a, /* unsigned shift right by immediate */
57 OPC_ISHR = 0x0b, /* signed shift right by immediate */
58 OPC_ROT = 0x0c, /* rotate left (left shift with wrap-around) */
59 OPC_MUL8 = 0x0d, /* 8bit multiply by immediate */
60 OPC_MIN = 0x0e,
61 OPC_MAX = 0x0f,
62 OPC_CMP = 0x10, /* compare src to immed */
63 OPC_MOVI = 0x11, /* move immediate */
64
65 /* Return the most-significant bit of src2, or 0 if src2 == 0 (the
66 * same as if src2 == 1). src1 is ignored. Note that this overlaps
67 * with STORE6, so it can only be used with the two-source encoding.
68 */
69 OPC_MSB = 0x14,
70
71
72 OPC_ALU = 0x13, /* ALU instruction with two src registers */
73
74 /* These seem something to do with setting some external state..
75 * doesn't seem to map *directly* to registers, but I guess that
76 * is where things end up. For example, this sequence in the
77 * CP_INDIRECT_BUFFER handler:
78 *
79 * mov $02, $data ; low 32b of IB target address
80 * mov $03, $data ; high 32b of IB target
81 * mov $04, $data ; IB size in dwords
82 * breq $04, 0x0, #l23 (#69, 04a2)
83 * and $05, $18, 0x0003
84 * shl $05, $05, 0x0002
85 * cwrite $02, [$05 + 0x0b0], 0x8
86 * cwrite $03, [$05 + 0x0b1], 0x8
87 * cwrite $04, [$05 + 0x0b2], 0x8
88 *
89 * Note that CP_IB1/2_BASE_LO/HI/BUFSZ in 0x0b1f->0xb21 (IB1) and
90 * 0x0b22->0x0b24 (IB2). Presumably $05 ends up w/ different value
91 * for RB->IB1 vs IB1->IB2.
92 */
93 OPC_CWRITE5 = 0x15,
94 OPC_CREAD5 = 0x16,
95
96 /* A6xx shuffled around the cwrite/cread opcodes and added new opcodes
97 * that let you read/write directly to memory (and bypass the IOMMU?).
98 */
99 OPC_STORE6 = 0x14,
100 OPC_CWRITE6 = 0x15,
101 OPC_LOAD6 = 0x16,
102 OPC_CREAD6 = 0x17,
103
104 OPC_BRNEI = 0x30, /* relative branch (if $src != immed) */
105 OPC_BREQI = 0x31, /* relative branch (if $src == immed) */
106 OPC_BRNEB = 0x32, /* relative branch (if bit not set) */
107 OPC_BREQB = 0x33, /* relative branch (if bit is set) */
108 OPC_RET = 0x34, /* return */
109 OPC_CALL = 0x35, /* "function" call */
110 OPC_WIN = 0x36, /* wait for input (ie. wait for WPTR to advance) */
111 OPC_PREEMPTLEAVE6 = 0x38, /* try to leave preemption */
112 OPC_SETSECURE = 0x3b, /* switch secure mode on/off */
113 } afuc_opc;
114
115
116 typedef union PACKED {
117 /* addi, subi, andi, ori, xori, etc: */
118 struct PACKED {
119 uint32_t uimm : 16;
120 uint32_t dst : 5;
121 uint32_t src : 5;
122 uint32_t hdr : 6;
123 } alui;
124 struct PACKED {
125 uint32_t uimm : 16;
126 uint32_t dst : 5;
127 uint32_t shift : 5;
128 uint32_t hdr : 6;
129 } movi;
130 struct PACKED {
131 uint32_t alu : 5;
132 uint32_t pad : 6;
133 uint32_t dst : 5;
134 uint32_t src2 : 5;
135 uint32_t src1 : 5;
136 uint32_t hdr : 6;
137 } alu;
138 struct PACKED {
139 uint32_t uimm : 12;
140 uint32_t flags : 4;
141 uint32_t src1 : 5; /* dst (cread) or src (cwrite) register */
142 uint32_t src2 : 5; /* read or write address is src2+uimm */
143 uint32_t hdr : 6;
144 } control;
145 struct PACKED {
146 int32_t ioff : 16; /* relative offset */
147 uint32_t bit_or_imm : 5;
148 uint32_t src : 5;
149 uint32_t hdr : 6;
150 } br;
151 struct PACKED {
152 uint32_t uoff : 26; /* absolute (unsigned) offset */
153 uint32_t hdr : 6;
154 } call;
155 struct PACKED {
156 uint32_t pad : 26;
157 uint32_t hdr : 6;
158 } waitin;
159 struct PACKED {
160 uint32_t pad : 26;
161 uint32_t opc_r : 6;
162 };
163
164 } afuc_instr;
165
166 static inline void
167 afuc_get_opc(afuc_instr *ai, afuc_opc *opc, bool *rep)
168 {
169 if (ai->opc_r < 0x30) {
170 *opc = ai->opc_r >> 1;
171 *rep = ai->opc_r & 0x1;
172 } else {
173 *opc = ai->opc_r;
174 *rep = false;
175 }
176 }
177
178 static inline void
179 afuc_set_opc(afuc_instr *ai, afuc_opc opc, bool rep)
180 {
181 if (opc < 0x30) {
182 ai->opc_r = opc << 1;
183 ai->opc_r |= !!rep;
184 } else {
185 ai->opc_r = opc;
186 }
187 }
188
189 #endif /* _AFUC_H_ */