OSDN Git Service

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