8636b2163e4484b2ae270533a50bfa0452cac5bb
[platform/upstream/libva-intel-driver.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_DW_VIDEO_PIPELINE_CACHE_INVALIDATE   (0x1 << 7)
35
36 #define XY_COLOR_BLT_CMD                        (CMD_2D | (0x50 << 22) | 0x04)
37 #define XY_COLOR_BLT_WRITE_ALPHA                (1 << 21)
38 #define XY_COLOR_BLT_WRITE_RGB                  (1 << 20)
39 #define XY_COLOR_BLT_DST_TILED                  (1 << 11)
40
41 #define GEN8_XY_COLOR_BLT_CMD                   (CMD_2D | (0x50 << 22) | 0x05)
42
43 /* BR13 */
44 #define BR13_8                                  (0x0 << 24)
45 #define BR13_565                                (0x1 << 24)
46 #define BR13_1555                               (0x2 << 24)
47 #define BR13_8888                               (0x3 << 24)
48
49 #define CMD_PIPE_CONTROL                        (CMD_3D | (3 << 27) | (2 << 24) | (0 << 16))
50 #define CMD_PIPE_CONTROL_CS_STALL               (1 << 20)
51 #define CMD_PIPE_CONTROL_NOWRITE                (0 << 14)
52 #define CMD_PIPE_CONTROL_WRITE_QWORD            (1 << 14)
53 #define CMD_PIPE_CONTROL_WRITE_DEPTH            (2 << 14)
54 #define CMD_PIPE_CONTROL_WRITE_TIME             (3 << 14)
55 #define CMD_PIPE_CONTROL_DEPTH_STALL            (1 << 13)
56 #define CMD_PIPE_CONTROL_WC_FLUSH               (1 << 12)
57 #define CMD_PIPE_CONTROL_IS_FLUSH               (1 << 11)
58 #define CMD_PIPE_CONTROL_TC_FLUSH               (1 << 10)
59 #define CMD_PIPE_CONTROL_NOTIFY_ENABLE          (1 << 8)
60 #define CMD_PIPE_CONTROL_DC_FLUSH               (1 << 5)
61 #define CMD_PIPE_CONTROL_GLOBAL_GTT             (1 << 2)
62 #define CMD_PIPE_CONTROL_LOCAL_PGTT             (0 << 2)
63 #define CMD_PIPE_CONTROL_STALL_AT_SCOREBOARD    (1 << 1)
64 #define CMD_PIPE_CONTROL_DEPTH_CACHE_FLUSH      (1 << 0)
65
66
67 struct intel_batchbuffer;
68
69 #define ALIGN(i, n)    (((i) + (n) - 1) & ~((n) - 1))
70 #define IS_ALIGNED(i, n) (((i) & ((n)-1)) == 0)
71 #define MIN(a, b) ((a) < (b) ? (a) : (b))
72 #define MAX(a, b) ((a) > (b) ? (a) : (b))
73 #define ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
74
75 #define Bool int
76 #define True 1
77 #define False 0
78
79 #define ASSERT_RET(value, fail_ret) do {    \
80         if (!(value)) {                 \
81             assert(0);                      \
82             return fail_ret;                \
83         }                                   \
84     } while (0)
85
86 #define SET_BLOCKED_SIGSET()   do {     \
87         sigset_t bl_mask;               \
88         sigfillset(&bl_mask);           \
89         sigdelset(&bl_mask, SIGFPE);    \
90         sigdelset(&bl_mask, SIGILL);    \
91         sigdelset(&bl_mask, SIGSEGV);   \
92         sigdelset(&bl_mask, SIGBUS);    \
93         sigdelset(&bl_mask, SIGKILL);   \
94         pthread_sigmask(SIG_SETMASK, &bl_mask, &intel->sa_mask); \
95     } while (0)
96
97 #define RESTORE_BLOCKED_SIGSET() do {    \
98         pthread_sigmask(SIG_SETMASK, &intel->sa_mask, NULL); \
99     } while (0)
100
101 #define PPTHREAD_MUTEX_LOCK() do {             \
102         SET_BLOCKED_SIGSET();                  \
103         pthread_mutex_lock(&intel->ctxmutex);       \
104     } while (0)
105
106 #define PPTHREAD_MUTEX_UNLOCK() do {           \
107         pthread_mutex_unlock(&intel->ctxmutex);     \
108         RESTORE_BLOCKED_SIGSET();              \
109     } while (0)
110
111 #define WARN_ONCE(...) do {                     \
112         static int g_once = 1;                  \
113         if (g_once) {                           \
114             g_once = 0;                         \
115             printf("WARNING: " __VA_ARGS__);    \
116         }                                       \
117     } while (0)
118
119 struct intel_device_info
120 {
121     int gen;
122     int gt;
123
124     unsigned int urb_size;
125     unsigned int max_wm_threads;
126
127     unsigned int is_g4x         : 1; /* gen4 */
128     unsigned int is_ivybridge   : 1; /* gen7 */
129     unsigned int is_baytrail    : 1; /* gen7 */
130     unsigned int is_haswell     : 1; /* gen7 */
131 };
132
133 struct intel_driver_data 
134 {
135     int fd;
136     int device_id;
137     int revision;
138
139     int dri2Enabled;
140
141     sigset_t sa_mask;
142     pthread_mutex_t ctxmutex;
143     int locked;
144
145     dri_bufmgr *bufmgr;
146
147     unsigned int has_exec2  : 1; /* Flag: has execbuffer2? */
148     unsigned int has_bsd    : 1; /* Flag: has bitstream decoder for H.264? */
149     unsigned int has_blt    : 1; /* Flag: has BLT unit? */
150     unsigned int has_vebox  : 1; /* Flag: has VEBOX unit */
151
152     const struct intel_device_info *device_info;
153 };
154
155 bool intel_driver_init(VADriverContextP ctx);
156 void intel_driver_terminate(VADriverContextP ctx);
157
158 static INLINE struct intel_driver_data *
159 intel_driver_data(VADriverContextP ctx)
160 {
161     return (struct intel_driver_data *)ctx->pDriverData;
162 }
163
164 struct intel_region
165 {
166     int x;
167     int y;
168     unsigned int width;
169     unsigned int height;
170     unsigned int cpp;
171     unsigned int pitch;
172     unsigned int tiling;
173     unsigned int swizzle;
174     dri_bo *bo;
175 };
176
177 #define IS_G4X(device_info)             (device_info->is_g4x)
178
179 #define IS_IRONLAKE(device_info)        (device_info->gen == 5)
180
181 #define IS_GEN6(device_info)            (device_info->gen == 6)
182
183 #define IS_HASWELL(device_info)         (device_info->is_haswell)
184 #define IS_GEN7(device_info)            (device_info->gen == 7)
185
186 #define IS_GEN8(device_info)            (device_info->gen == 8)
187
188 #endif /* _INTEL_DRIVER_H_ */