OSDN Git Service

f60374c964da9a27f4633419cd6fd4effea8d5b3
[android-x86/hardware-intel-common-vaapi.git] / src / intel_driver.h
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 XY_COLOR_BLT_CMD                        (CMD_2D | (0x50 << 22) | 0x04)
56 #define XY_COLOR_BLT_WRITE_ALPHA                (1 << 21)
57 #define XY_COLOR_BLT_WRITE_RGB                  (1 << 20)
58 #define XY_COLOR_BLT_DST_TILED                  (1 << 11)
59
60 #define GEN8_XY_COLOR_BLT_CMD                   (CMD_2D | (0x50 << 22) | 0x05)
61
62 /* BR13 */
63 #define BR13_8                                  (0x0 << 24)
64 #define BR13_565                                (0x1 << 24)
65 #define BR13_1555                               (0x2 << 24)
66 #define BR13_8888                               (0x3 << 24)
67
68 #define CMD_PIPE_CONTROL                        (CMD_3D | (3 << 27) | (2 << 24) | (0 << 16))
69 #define CMD_PIPE_CONTROL_CS_STALL               (1 << 20)
70 #define CMD_PIPE_CONTROL_NOWRITE                (0 << 14)
71 #define CMD_PIPE_CONTROL_WRITE_QWORD            (1 << 14)
72 #define CMD_PIPE_CONTROL_WRITE_DEPTH            (2 << 14)
73 #define CMD_PIPE_CONTROL_WRITE_TIME             (3 << 14)
74 #define CMD_PIPE_CONTROL_DEPTH_STALL            (1 << 13)
75 #define CMD_PIPE_CONTROL_WC_FLUSH               (1 << 12)
76 #define CMD_PIPE_CONTROL_IS_FLUSH               (1 << 11)
77 #define CMD_PIPE_CONTROL_TC_FLUSH               (1 << 10)
78 #define CMD_PIPE_CONTROL_NOTIFY_ENABLE          (1 << 8)
79 #define CMD_PIPE_CONTROL_DC_FLUSH               (1 << 5)
80 #define CMD_PIPE_CONTROL_GLOBAL_GTT             (1 << 2)
81 #define CMD_PIPE_CONTROL_LOCAL_PGTT             (0 << 2)
82 #define CMD_PIPE_CONTROL_STALL_AT_SCOREBOARD    (1 << 1)
83 #define CMD_PIPE_CONTROL_DEPTH_CACHE_FLUSH      (1 << 0)
84
85
86 struct intel_batchbuffer;
87
88 #define ALIGN(i, n)    (((i) + (n) - 1) & ~((n) - 1))
89 #define IS_ALIGNED(i, n) (((i) & ((n)-1)) == 0)
90 #define MIN(a, b) ((a) < (b) ? (a) : (b))
91 #define MAX(a, b) ((a) > (b) ? (a) : (b))
92 #define ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
93 #define CLAMP(min, max, a) ((a) < (min) ? (min) : ((a) > (max) ? (max) : (a)))
94
95 #define Bool int
96 #define True 1
97 #define False 0
98
99 extern uint32_t g_intel_debug_option_flags;
100 #define VA_INTEL_DEBUG_OPTION_ASSERT    (1 << 0)
101 #define VA_INTEL_DEBUG_OPTION_BENCH     (1 << 1)
102 #define VA_INTEL_DEBUG_OPTION_DUMP_AUB  (1 << 2)
103
104 #define ASSERT_RET(value, fail_ret) do {    \
105         if (!(value)) {                     \
106             if (g_intel_debug_option_flags & VA_INTEL_DEBUG_OPTION_ASSERT)       \
107                 assert(value);              \
108             return fail_ret;                \
109         }                                   \
110     } while (0)
111
112 #define SET_BLOCKED_SIGSET()   do {     \
113         sigset_t bl_mask;               \
114         sigfillset(&bl_mask);           \
115         sigdelset(&bl_mask, SIGFPE);    \
116         sigdelset(&bl_mask, SIGILL);    \
117         sigdelset(&bl_mask, SIGSEGV);   \
118         sigdelset(&bl_mask, SIGBUS);    \
119         sigdelset(&bl_mask, SIGKILL);   \
120         pthread_sigmask(SIG_SETMASK, &bl_mask, &intel->sa_mask); \
121     } while (0)
122
123 #define RESTORE_BLOCKED_SIGSET() do {    \
124         pthread_sigmask(SIG_SETMASK, &intel->sa_mask, NULL); \
125     } while (0)
126
127 #define PPTHREAD_MUTEX_LOCK() do {             \
128         SET_BLOCKED_SIGSET();                  \
129         pthread_mutex_lock(&intel->ctxmutex);       \
130     } while (0)
131
132 #define PPTHREAD_MUTEX_UNLOCK() do {           \
133         pthread_mutex_unlock(&intel->ctxmutex);     \
134         RESTORE_BLOCKED_SIGSET();              \
135     } while (0)
136
137 #define WARN_ONCE(...) do {                     \
138         static int g_once = 1;                  \
139         if (g_once) {                           \
140             g_once = 0;                         \
141             fprintf(stderr, "WARNING: " __VA_ARGS__);    \
142         }                                       \
143     } while (0)
144
145 struct intel_device_info
146 {
147     int gen;
148     int gt;
149
150     unsigned int urb_size;
151     unsigned int max_wm_threads;
152
153     unsigned int is_g4x         : 1; /* gen4 */
154     unsigned int is_ivybridge   : 1; /* gen7 */
155     unsigned int is_baytrail    : 1; /* gen7 */
156     unsigned int is_haswell     : 1; /* gen7 */
157     unsigned int is_cherryview  : 1; /* gen8 */
158     unsigned int is_skylake     : 1; /* gen9 */
159     unsigned int is_broxton     : 1; /* gen9 */
160     unsigned int is_kabylake    : 1; /* gen9p5 */
161 };
162
163 struct intel_driver_data 
164 {
165     int fd;
166     int device_id;
167     int revision;
168
169     int dri2Enabled;
170
171     sigset_t sa_mask;
172     pthread_mutex_t ctxmutex;
173     int locked;
174
175     dri_bufmgr *bufmgr;
176
177     unsigned int has_exec2  : 1; /* Flag: has execbuffer2? */
178     unsigned int has_bsd    : 1; /* Flag: has bitstream decoder for H.264? */
179     unsigned int has_blt    : 1; /* Flag: has BLT unit? */
180     unsigned int has_vebox  : 1; /* Flag: has VEBOX unit */
181     unsigned int has_bsd2   : 1; /* Flag: has the second BSD video ring unit */
182
183     const struct intel_device_info *device_info;
184 };
185
186 bool intel_driver_init(VADriverContextP ctx);
187 void intel_driver_terminate(VADriverContextP ctx);
188
189 static INLINE struct intel_driver_data *
190 intel_driver_data(VADriverContextP ctx)
191 {
192     return (struct intel_driver_data *)ctx->pDriverData;
193 }
194
195 struct intel_region
196 {
197     int x;
198     int y;
199     unsigned int width;
200     unsigned int height;
201     unsigned int cpp;
202     unsigned int pitch;
203     unsigned int tiling;
204     unsigned int swizzle;
205     dri_bo *bo;
206 };
207
208 #define IS_G4X(device_info)             (device_info->is_g4x)
209
210 #define IS_IRONLAKE(device_info)        (device_info->gen == 5)
211
212 #define IS_GEN6(device_info)            (device_info->gen == 6)
213
214 #define IS_HASWELL(device_info)         (device_info->is_haswell)
215 #define IS_GEN7(device_info)            (device_info->gen == 7)
216
217 #define IS_CHERRYVIEW(device_info)      (device_info->is_cherryview)
218 #define IS_GEN8(device_info)            (device_info->gen == 8)
219
220 #define IS_GEN9(device_info)            (device_info->gen == 9)
221
222 #define IS_SKL(device_info)             (device_info->is_skylake)
223
224 #define IS_BXT(device_info)             (device_info->is_broxton)
225
226 #define IS_KBL(device_info)             (device_info->is_kabylake)
227
228 #endif /* _INTEL_DRIVER_H_ */