Debian Codegraph @

src/intel_driver.h

raw
1 #ifndef _INTEL_DRIVER_H_
2 #define _INTEL_DRIVER_H_
3
4 #include <stddef.h>
5 #include <pthread.h>
6 #include <signal.h>
7 #include <stdbool.h>
8
9 #include <drm.h>
10 #include <i915_drm.h>
11 #include <intel_bufmgr.h>
12
13 #include <va/va_backend.h>
14 #include "va_backend_compat.h"
15
16 #include "intel_compiler.h"
17
18 #define BATCH_SIZE 0x80000
19 #define BATCH_RESERVED 0x10
20
21 #define CMD_MI (0x0 << 29)
22 #define CMD_2D (0x2 << 29)
23 #define CMD_3D (0x3 << 29)
24
25 #define MI_NOOP (CMD_MI | 0)
26
27 #define MI_BATCH_BUFFER_END (CMD_MI | (0xA << 23))
28 #define MI_BATCH_BUFFER_START (CMD_MI | (0x31 << 23))
29
30 #define MI_FLUSH (CMD_MI | (0x4 << 23))
31 #define MI_FLUSH_STATE_INSTRUCTION_CACHE_INVALIDATE (0x1 << 0)
32
33 #define MI_FLUSH_DW (CMD_MI | (0x26 << 23) | 0x2)
34 #define MI_FLUSH_DW2 (CMD_MI | (0x26 << 23) | 0x3)
35 #define MI_FLUSH_DW_VIDEO_PIPELINE_CACHE_INVALIDATE (0x1 << 7)
36 #define MI_FLUSH_DW_NOWRITE (0 << 14)
37 #define MI_FLUSH_DW_WRITE_QWORD (1 << 14)
38 #define MI_FLUSH_DW_WRITE_TIME (3 << 14)
39
40 #define MI_STORE_DATA_IMM (CMD_MI | (0x20 << 23))
41
42 #define MI_STORE_REGISTER_MEM (CMD_MI | (0x24 << 23))
43
44 #define MI_LOAD_REGISTER_IMM (CMD_MI | (0x22 << 23))
45
46 #define MI_LOAD_REGISTER_MEM (CMD_MI | (0x29 << 23))
47
48 #define MI_LOAD_REGISTER_REG (CMD_MI | (0x2A << 23))
49
50 #define MI_MATH (CMD_MI | (0x1A << 23))
51
52 #define MI_CONDITIONAL_BATCH_BUFFER_END (CMD_MI | (0x36 << 23))
53 #define MI_COMPARE_MASK_MODE_ENANBLED (1 << 19)
54
55 #define MI_COPY_MEM_MEM (CMD_MI | (0x2E << 23))
56
57 #define XY_COLOR_BLT_CMD (CMD_2D | (0x50 << 22) | 0x04)
58 #define XY_COLOR_BLT_WRITE_ALPHA (1 << 21)
59 #define XY_COLOR_BLT_WRITE_RGB (1 << 20)
60 #define XY_COLOR_BLT_DST_TILED (1 << 11)
61
62 #define GEN8_XY_COLOR_BLT_CMD (CMD_2D | (0x50 << 22) | 0x05)
63
64 /* BR13 */
65 #define BR13_8 (0x0 << 24)
66 #define BR13_565 (0x1 << 24)
67 #define BR13_1555 (0x2 << 24)
68 #define BR13_8888 (0x3 << 24)
69
70 #define CMD_PIPE_CONTROL (CMD_3D | (3 << 27) | (2 << 24) | (0 << 16))
71 #define CMD_PIPE_CONTROL_CS_STALL (1 << 20)
72 #define CMD_PIPE_CONTROL_NOWRITE (0 << 14)
73 #define CMD_PIPE_CONTROL_WRITE_QWORD (1 << 14)
74 #define CMD_PIPE_CONTROL_WRITE_DEPTH (2 << 14)
75 #define CMD_PIPE_CONTROL_WRITE_TIME (3 << 14)
76 #define CMD_PIPE_CONTROL_DEPTH_STALL (1 << 13)
77 #define CMD_PIPE_CONTROL_WC_FLUSH (1 << 12)
78 #define CMD_PIPE_CONTROL_IS_FLUSH (1 << 11)
79 #define CMD_PIPE_CONTROL_TC_FLUSH (1 << 10)
80 #define CMD_PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
81 #define CMD_PIPE_CONTROL_FLUSH_ENABLE (1 << 7)
82 #define CMD_PIPE_CONTROL_DC_FLUSH (1 << 5)
83 #define CMD_PIPE_CONTROL_GLOBAL_GTT (1 << 2)
84 #define CMD_PIPE_CONTROL_LOCAL_PGTT (0 << 2)
85 #define CMD_PIPE_CONTROL_STALL_AT_SCOREBOARD (1 << 1)
86 #define CMD_PIPE_CONTROL_DEPTH_CACHE_FLUSH (1 << 0)
87
88 #define CMD_PIPE_CONTROL_GLOBAL_GTT_GEN8 (1 << 24)
89 #define CMD_PIPE_CONTROL_LOCAL_PGTT_GEN8 (0 << 24)
90 #define CMD_PIPE_CONTROL_VFC_INVALIDATION_GEN8 (1 << 4)
91 #define CMD_PIPE_CONTROL_CC_INVALIDATION_GEN8 (1 << 3)
92 #define CMD_PIPE_CONTROL_SC_INVALIDATION_GEN8 (1 << 2)
93
94 struct intel_batchbuffer;
95
96 #define ALIGN(i, n) (((i) + (n) - 1) & ~((n) - 1))
97 #define IS_ALIGNED(i, n) (((i) & ((n)-1)) == 0)
98 #define MIN(a, b) ((a) < (b) ? (a) : (b))
99 #define MAX(a, b) ((a) > (b) ? (a) : (b))
100 #define ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
101 #define CLAMP(min, max, a) ((a) < (min) ? (min) : ((a) > (max) ? (max) : (a)))
102
103 #define ALIGN_FLOOR(i, n) ((i) & ~((n) - 1))
104
105 #define Bool int
106 #define True 1
107 #define False 0
108
109 extern uint32_t g_intel_debug_option_flags;
110 #define VA_INTEL_DEBUG_OPTION_ASSERT (1 << 0)
111 #define VA_INTEL_DEBUG_OPTION_BENCH (1 << 1)
112 #define VA_INTEL_DEBUG_OPTION_DUMP_AUB (1 << 2)
113
114 #define ASSERT_RET(value, fail_ret) do { \
115 if (!(value)) { \
116 if (g_intel_debug_option_flags & VA_INTEL_DEBUG_OPTION_ASSERT) \
117 assert(value); \
118 return fail_ret; \
119 } \
120 } while (0)
121
122 #define SET_BLOCKED_SIGSET() do { \
123 sigset_t bl_mask; \
124 sigfillset(&bl_mask); \
125 sigdelset(&bl_mask, SIGFPE); \
126 sigdelset(&bl_mask, SIGILL); \
127 sigdelset(&bl_mask, SIGSEGV); \
128 sigdelset(&bl_mask, SIGBUS); \
129 sigdelset(&bl_mask, SIGKILL); \
130 pthread_sigmask(SIG_SETMASK, &bl_mask, &intel->sa_mask); \
131 } while (0)
132
133 #define RESTORE_BLOCKED_SIGSET() do { \
134 pthread_sigmask(SIG_SETMASK, &intel->sa_mask, NULL); \
135 } while (0)
136
137 #define PPTHREAD_MUTEX_LOCK() do { \
138 SET_BLOCKED_SIGSET(); \
139 pthread_mutex_lock(&intel->ctxmutex); \
140 } while (0)
141
142 #define PPTHREAD_MUTEX_UNLOCK() do { \
143 pthread_mutex_unlock(&intel->ctxmutex); \
144 RESTORE_BLOCKED_SIGSET(); \
145 } while (0)
146
147 #define WARN_ONCE(...) do { \
148 static int g_once = 1; \
149 if (g_once) { \
150 g_once = 0; \
151 fprintf(stderr, "WARNING: " __VA_ARGS__); \
152 } \
153 } while (0)
154
155 struct intel_device_info {
156 int gen;
157 int gt;
158
159 unsigned int urb_size;
160 unsigned int max_wm_threads;
161
162 unsigned int is_g4x : 1; /* gen4 */
163 unsigned int is_ivybridge : 1; /* gen7 */
164 unsigned int is_baytrail : 1; /* gen7 */
165 unsigned int is_haswell : 1; /* gen7 */
166 unsigned int is_cherryview : 1; /* gen8 */
167 unsigned int is_skylake : 1; /* gen9 */
168 unsigned int is_broxton : 1; /* gen9 */
169 unsigned int is_kabylake : 1; /* gen9p5 */
170 unsigned int is_glklake : 1; /* gen9p5 lp*/
171 unsigned int is_cfllake : 1;
172 };
173
174 struct intel_driver_data {
175 int fd;
176 int device_id;
177 int revision;
178
179 int dri2Enabled;
180
181 sigset_t sa_mask;
182 pthread_mutex_t ctxmutex;
183 int locked;
184
185 dri_bufmgr *bufmgr;
186
187 unsigned int has_exec2 : 1; /* Flag: has execbuffer2? */
188 unsigned int has_bsd : 1; /* Flag: has bitstream decoder for H.264? */
189 unsigned int has_blt : 1; /* Flag: has BLT unit? */
190 unsigned int has_vebox : 1; /* Flag: has VEBOX unit */
191 unsigned int has_bsd2 : 1; /* Flag: has the second BSD video ring unit */
192 unsigned int has_huc : 1; /* Flag: has a fully loaded HuC firmware? */
193
194 int eu_total;
195
196 const struct intel_device_info *device_info;
197 unsigned int mocs_state;
198 };
199
200 bool intel_driver_init(VADriverContextP ctx);
201 void intel_driver_terminate(VADriverContextP ctx);
202
203 static INLINE struct intel_driver_data *
204 intel_driver_data(VADriverContextP ctx)
205 {
206 return (struct intel_driver_data *)ctx->pDriverData;
207 }
208
209 struct intel_region {
210 int x;
211 int y;
212 unsigned int width;
213 unsigned int height;
214 unsigned int cpp;
215 unsigned int pitch;
216 unsigned int tiling;
217 unsigned int swizzle;
218 dri_bo *bo;
219 };
220
221 #define IS_G4X(device_info) (device_info->is_g4x)
222
223 #define IS_IRONLAKE(device_info) (device_info->gen == 5)
224
225 #define IS_GEN6(device_info) (device_info->gen == 6)
226
227 #define IS_HASWELL(device_info) (device_info->is_haswell)
228 #define IS_GEN7(device_info) (device_info->gen == 7)
229
230 #define IS_CHERRYVIEW(device_info) (device_info->is_cherryview)
231 #define IS_GEN8(device_info) (device_info->gen == 8)
232
233 #define IS_GEN9(device_info) (device_info->gen == 9)
234
235 #define IS_SKL(device_info) (device_info->is_skylake)
236
237 #define IS_BXT(device_info) (device_info->is_broxton)
238
239 #define IS_KBL(device_info) (device_info->is_kabylake ||\
240 device_info->is_cfllake)
241
242 #define IS_GLK(device_info) (device_info->is_glklake)
243
244 #define IS_GEN10(device_info) (device_info->gen == 10)
245
246 #endif /* _INTEL_DRIVER_H_ */