VPP: Fix Coverity alert on unitialized vpp_kernels
[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 extern uint32_t g_intel_debug_option_flags;
80 #define VA_INTEL_DEBUG_OPTION_ASSERT    (1 << 0)
81 #define VA_INTEL_DEBUG_OPTION_BENCH     (1 << 1)
82
83 #define ASSERT_RET(value, fail_ret) do {    \
84         if (!(value)) {                     \
85             if (g_intel_debug_option_flags & VA_INTEL_DEBUG_OPTION_ASSERT)       \
86                 assert(value);              \
87             return fail_ret;                \
88         }                                   \
89     } while (0)
90
91 #define SET_BLOCKED_SIGSET()   do {     \
92         sigset_t bl_mask;               \
93         sigfillset(&bl_mask);           \
94         sigdelset(&bl_mask, SIGFPE);    \
95         sigdelset(&bl_mask, SIGILL);    \
96         sigdelset(&bl_mask, SIGSEGV);   \
97         sigdelset(&bl_mask, SIGBUS);    \
98         sigdelset(&bl_mask, SIGKILL);   \
99         pthread_sigmask(SIG_SETMASK, &bl_mask, &intel->sa_mask); \
100     } while (0)
101
102 #define RESTORE_BLOCKED_SIGSET() do {    \
103         pthread_sigmask(SIG_SETMASK, &intel->sa_mask, NULL); \
104     } while (0)
105
106 #define PPTHREAD_MUTEX_LOCK() do {             \
107         SET_BLOCKED_SIGSET();                  \
108         pthread_mutex_lock(&intel->ctxmutex);       \
109     } while (0)
110
111 #define PPTHREAD_MUTEX_UNLOCK() do {           \
112         pthread_mutex_unlock(&intel->ctxmutex);     \
113         RESTORE_BLOCKED_SIGSET();              \
114     } while (0)
115
116 #define WARN_ONCE(...) do {                     \
117         static int g_once = 1;                  \
118         if (g_once) {                           \
119             g_once = 0;                         \
120             printf("WARNING: " __VA_ARGS__);    \
121         }                                       \
122     } while (0)
123
124 struct intel_device_info
125 {
126     int gen;
127     int gt;
128
129     unsigned int urb_size;
130     unsigned int max_wm_threads;
131
132     unsigned int is_g4x         : 1; /* gen4 */
133     unsigned int is_ivybridge   : 1; /* gen7 */
134     unsigned int is_baytrail    : 1; /* gen7 */
135     unsigned int is_haswell     : 1; /* gen7 */
136     unsigned int is_cherryview  : 1; /* gen8 */
137 };
138
139 struct intel_driver_data 
140 {
141     int fd;
142     int device_id;
143     int revision;
144
145     int dri2Enabled;
146
147     sigset_t sa_mask;
148     pthread_mutex_t ctxmutex;
149     int locked;
150
151     dri_bufmgr *bufmgr;
152
153     unsigned int has_exec2  : 1; /* Flag: has execbuffer2? */
154     unsigned int has_bsd    : 1; /* Flag: has bitstream decoder for H.264? */
155     unsigned int has_blt    : 1; /* Flag: has BLT unit? */
156     unsigned int has_vebox  : 1; /* Flag: has VEBOX unit */
157
158     const struct intel_device_info *device_info;
159 };
160
161 bool intel_driver_init(VADriverContextP ctx);
162 void intel_driver_terminate(VADriverContextP ctx);
163
164 static INLINE struct intel_driver_data *
165 intel_driver_data(VADriverContextP ctx)
166 {
167     return (struct intel_driver_data *)ctx->pDriverData;
168 }
169
170 struct intel_region
171 {
172     int x;
173     int y;
174     unsigned int width;
175     unsigned int height;
176     unsigned int cpp;
177     unsigned int pitch;
178     unsigned int tiling;
179     unsigned int swizzle;
180     dri_bo *bo;
181 };
182
183 #define IS_G4X(device_info)             (device_info->is_g4x)
184
185 #define IS_IRONLAKE(device_info)        (device_info->gen == 5)
186
187 #define IS_GEN6(device_info)            (device_info->gen == 6)
188
189 #define IS_HASWELL(device_info)         (device_info->is_haswell)
190 #define IS_GEN7(device_info)            (device_info->gen == 7)
191
192 #define IS_CHERRYVIEW(device_info)      (device_info->is_cherryview)
193 #define IS_GEN8(device_info)            (device_info->gen == 8)
194
195 #endif /* _INTEL_DRIVER_H_ */