Clear target surface with specified color
[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
8 #include <drm.h>
9 #include <i915_drm.h>
10 #include <intel_bufmgr.h>
11
12 #include <va/va_backend.h>
13
14 #include "intel_compiler.h"
15
16 #define BATCH_SIZE      0x80000
17 #define BATCH_RESERVED  0x10
18
19 #define CMD_MI                                  (0x0 << 29)
20 #define CMD_2D                                  (0x2 << 29)
21 #define CMD_3D                                  (0x3 << 29)
22
23 #define MI_NOOP                                 (CMD_MI | 0)
24
25 #define MI_BATCH_BUFFER_END                     (CMD_MI | (0xA << 23))
26 #define MI_BATCH_BUFFER_START                   (CMD_MI | (0x31 << 23))
27
28 #define MI_FLUSH                                (CMD_MI | (0x4 << 23))
29 #define   MI_FLUSH_STATE_INSTRUCTION_CACHE_INVALIDATE   (0x1 << 0)
30
31 #define MI_FLUSH_DW                             (CMD_MI | (0x26 << 23) | 0x2)
32 #define   MI_FLUSH_DW_VIDEO_PIPELINE_CACHE_INVALIDATE   (0x1 << 7)
33
34 #define XY_COLOR_BLT_CMD                        (CMD_2D | (0x50 << 22) | 0x04)
35 #define XY_COLOR_BLT_WRITE_ALPHA                (1 << 21)
36 #define XY_COLOR_BLT_WRITE_RGB                  (1 << 20)
37 #define XY_COLOR_BLT_DST_TILED                  (1 << 11)
38
39 /* BR13 */
40 #define BR13_8                                  (0x0 << 24)
41 #define BR13_565                                (0x1 << 24)
42 #define BR13_1555                               (0x2 << 24)
43 #define BR13_8888                               (0x3 << 24)
44
45 #define CMD_PIPE_CONTROL                        (CMD_3D | (3 << 27) | (2 << 24) | (0 << 16))
46 #define CMD_PIPE_CONTROL_NOWRITE                (0 << 14)
47 #define CMD_PIPE_CONTROL_WRITE_QWORD            (1 << 14)
48 #define CMD_PIPE_CONTROL_WRITE_DEPTH            (2 << 14)
49 #define CMD_PIPE_CONTROL_WRITE_TIME             (3 << 14)
50 #define CMD_PIPE_CONTROL_DEPTH_STALL            (1 << 13)
51 #define CMD_PIPE_CONTROL_WC_FLUSH               (1 << 12)
52 #define CMD_PIPE_CONTROL_IS_FLUSH               (1 << 11)
53 #define CMD_PIPE_CONTROL_TC_FLUSH               (1 << 10)
54 #define CMD_PIPE_CONTROL_NOTIFY_ENABLE          (1 << 8)
55 #define CMD_PIPE_CONTROL_DC_FLUSH               (1 << 5)
56 #define CMD_PIPE_CONTROL_GLOBAL_GTT             (1 << 2)
57 #define CMD_PIPE_CONTROL_LOCAL_PGTT             (0 << 2)
58 #define CMD_PIPE_CONTROL_DEPTH_CACHE_FLUSH      (1 << 0)
59
60
61 struct intel_batchbuffer;
62
63 #define ALIGN(i, n)    (((i) + (n) - 1) & ~((n) - 1))
64 #define MIN(a, b) ((a) < (b) ? (a) : (b))
65 #define MAX(a, b) ((a) > (b) ? (a) : (b))
66 #define ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
67
68 #define Bool int
69 #define True 1
70 #define False 0
71
72 #define SET_BLOCKED_SIGSET()   do {     \
73         sigset_t bl_mask;               \
74         sigfillset(&bl_mask);           \
75         sigdelset(&bl_mask, SIGFPE);    \
76         sigdelset(&bl_mask, SIGILL);    \
77         sigdelset(&bl_mask, SIGSEGV);   \
78         sigdelset(&bl_mask, SIGBUS);    \
79         sigdelset(&bl_mask, SIGKILL);   \
80         pthread_sigmask(SIG_SETMASK, &bl_mask, &intel->sa_mask); \
81     } while (0)
82
83 #define RESTORE_BLOCKED_SIGSET() do {    \
84         pthread_sigmask(SIG_SETMASK, &intel->sa_mask, NULL); \
85     } while (0)
86
87 #define PPTHREAD_MUTEX_LOCK() do {             \
88         SET_BLOCKED_SIGSET();                  \
89         pthread_mutex_lock(&intel->ctxmutex);       \
90     } while (0)
91
92 #define PPTHREAD_MUTEX_UNLOCK() do {           \
93         pthread_mutex_unlock(&intel->ctxmutex);     \
94         RESTORE_BLOCKED_SIGSET();              \
95     } while (0)
96
97 struct intel_driver_data 
98 {
99     int fd;
100     int device_id;
101
102     int dri2Enabled;
103
104     sigset_t sa_mask;
105     pthread_mutex_t ctxmutex;
106     int locked;
107
108     dri_bufmgr *bufmgr;
109
110     unsigned int has_exec2  : 1; /* Flag: has execbuffer2? */
111     unsigned int has_bsd    : 1; /* Flag: has bitstream decoder for H.264? */
112     unsigned int has_blt    : 1; /* Flag: has BLT unit? */
113 };
114
115 Bool intel_driver_init(VADriverContextP ctx);
116 Bool intel_driver_terminate(VADriverContextP ctx);
117
118 static INLINE struct intel_driver_data *
119 intel_driver_data(VADriverContextP ctx)
120 {
121     return (struct intel_driver_data *)ctx->pDriverData;
122 }
123
124 struct intel_region
125 {
126     int x;
127     int y;
128     unsigned int width;
129     unsigned int height;
130     unsigned int cpp;
131     unsigned int pitch;
132     unsigned int tiling;
133     unsigned int swizzle;
134     dri_bo *bo;
135 };
136
137 #define PCI_CHIP_GM45_GM                0x2A42
138 #define PCI_CHIP_IGD_E_G                0x2E02
139 #define PCI_CHIP_Q45_G                  0x2E12
140 #define PCI_CHIP_G45_G                  0x2E22
141 #define PCI_CHIP_G41_G                  0x2E32
142 #define PCI_CHIP_B43_G                  0x2E42
143 #define PCI_CHIP_B43_G1                 0x2E92
144
145 #define PCI_CHIP_IRONLAKE_D_G           0x0042
146 #define PCI_CHIP_IRONLAKE_M_G           0x0046
147
148 #ifndef PCI_CHIP_SANDYBRIDGE_GT1
149 #define PCI_CHIP_SANDYBRIDGE_GT1        0x0102  /* Desktop */
150 #define PCI_CHIP_SANDYBRIDGE_GT2        0x0112
151 #define PCI_CHIP_SANDYBRIDGE_GT2_PLUS   0x0122
152 #define PCI_CHIP_SANDYBRIDGE_M_GT1      0x0106  /* Mobile */
153 #define PCI_CHIP_SANDYBRIDGE_M_GT2      0x0116
154 #define PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS 0x0126
155 #define PCI_CHIP_SANDYBRIDGE_S_GT       0x010A  /* Server */
156 #endif
157
158 #define PCI_CHIP_IVYBRIDGE_GT1          0x0152  /* Desktop */
159 #define PCI_CHIP_IVYBRIDGE_GT2          0x0162
160 #define PCI_CHIP_IVYBRIDGE_M_GT1        0x0156  /* Mobile */
161 #define PCI_CHIP_IVYBRIDGE_M_GT2        0x0166
162 #define PCI_CHIP_IVYBRIDGE_S_GT1        0x015a  /* Server */
163
164 #define IS_G45(devid)           (devid == PCI_CHIP_IGD_E_G ||   \
165                                  devid == PCI_CHIP_Q45_G ||     \
166                                  devid == PCI_CHIP_G45_G ||     \
167                                  devid == PCI_CHIP_G41_G ||     \
168                                  devid == PCI_CHIP_B43_G ||     \
169                                  devid == PCI_CHIP_B43_G1)
170  
171 #define IS_GM45(devid)          (devid == PCI_CHIP_GM45_GM)
172 #define IS_G4X(devid)           (IS_G45(devid) || IS_GM45(devid))
173
174 #define IS_IRONLAKE_D(devid)    (devid == PCI_CHIP_IRONLAKE_D_G)
175 #define IS_IRONLAKE_M(devid)    (devid == PCI_CHIP_IRONLAKE_M_G)
176 #define IS_IRONLAKE(devid)      (IS_IRONLAKE_D(devid) || IS_IRONLAKE_M(devid))
177
178 #define IS_GEN6(devid)          (devid == PCI_CHIP_SANDYBRIDGE_GT1 || \
179                                  devid == PCI_CHIP_SANDYBRIDGE_GT2 || \
180                                  devid == PCI_CHIP_SANDYBRIDGE_GT2_PLUS ||\
181                                  devid == PCI_CHIP_SANDYBRIDGE_M_GT1 || \
182                                  devid == PCI_CHIP_SANDYBRIDGE_M_GT2 || \
183                                  devid == PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS || \
184                                  devid == PCI_CHIP_SANDYBRIDGE_S_GT)
185
186 #define IS_GEN7(devid)          (devid == PCI_CHIP_IVYBRIDGE_GT1 ||     \
187                                  devid == PCI_CHIP_IVYBRIDGE_GT2 ||     \
188                                  devid == PCI_CHIP_IVYBRIDGE_M_GT1 ||   \
189                                  devid == PCI_CHIP_IVYBRIDGE_M_GT2 ||   \
190                                  devid == PCI_CHIP_IVYBRIDGE_S_GT1)
191
192 #endif /* _INTEL_DRIVER_H_ */