a1c97c4922b6f3cc2db91f145d73062ea785a717
[platform/upstream/libva.git] / i965_drv_video / intel_driver.h
1 #ifndef _INTEL_DRIVER_H_
2 #define _INTEL_DRIVER_H_
3
4 #include <pthread.h>
5 #include <signal.h>
6
7 #include <xf86drm.h>
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_565                                (0x1 << 24)
41 #define BR13_8888                               (0x3 << 24)
42
43 #define CMD_PIPE_CONTROL                        (CMD_3D | (3 << 27) | (2 << 24) | (0 << 16))
44 #define CMD_PIPE_CONTROL_NOWRITE                (0 << 14)
45 #define CMD_PIPE_CONTROL_WRITE_QWORD            (1 << 14)
46 #define CMD_PIPE_CONTROL_WRITE_DEPTH            (2 << 14)
47 #define CMD_PIPE_CONTROL_WRITE_TIME             (3 << 14)
48 #define CMD_PIPE_CONTROL_DEPTH_STALL            (1 << 13)
49 #define CMD_PIPE_CONTROL_WC_FLUSH               (1 << 12)
50 #define CMD_PIPE_CONTROL_IS_FLUSH               (1 << 11)
51 #define CMD_PIPE_CONTROL_TC_FLUSH               (1 << 10)
52 #define CMD_PIPE_CONTROL_NOTIFY_ENABLE          (1 << 8)
53 #define CMD_PIPE_CONTROL_GLOBAL_GTT             (1 << 2)
54 #define CMD_PIPE_CONTROL_LOCAL_PGTT             (0 << 2)
55 #define CMD_PIPE_CONTROL_DEPTH_CACHE_FLUSH      (1 << 0)
56
57
58 struct intel_batchbuffer;
59
60 #define ALIGN(i, n)    (((i) + (n) - 1) & ~((n) - 1))
61 #define MIN(a, b) ((a) < (b) ? (a) : (b))
62 #define MAX(a, b) ((a) > (b) ? (a) : (b))
63 #define ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
64
65 #define SET_BLOCKED_SIGSET()   do {     \
66         sigset_t bl_mask;               \
67         sigfillset(&bl_mask);           \
68         sigdelset(&bl_mask, SIGFPE);    \
69         sigdelset(&bl_mask, SIGILL);    \
70         sigdelset(&bl_mask, SIGSEGV);   \
71         sigdelset(&bl_mask, SIGBUS);    \
72         sigdelset(&bl_mask, SIGKILL);   \
73         pthread_sigmask(SIG_SETMASK, &bl_mask, &intel->sa_mask); \
74     } while (0)
75
76 #define RESTORE_BLOCKED_SIGSET() do {    \
77         pthread_sigmask(SIG_SETMASK, &intel->sa_mask, NULL); \
78     } while (0)
79
80 #define PPTHREAD_MUTEX_LOCK() do {             \
81         SET_BLOCKED_SIGSET();                  \
82         pthread_mutex_lock(&intel->ctxmutex);       \
83     } while (0)
84
85 #define PPTHREAD_MUTEX_UNLOCK() do {           \
86         pthread_mutex_unlock(&intel->ctxmutex);     \
87         RESTORE_BLOCKED_SIGSET();              \
88     } while (0)
89
90 struct intel_driver_data 
91 {
92     int fd;
93     int device_id;
94
95     int dri2Enabled;
96     drm_context_t hHWContext;
97     drm_i915_sarea_t *pPrivSarea;
98     drmLock *driHwLock;
99
100     sigset_t sa_mask;
101     pthread_mutex_t ctxmutex;
102     int locked;
103
104     dri_bufmgr *bufmgr;
105
106     unsigned int has_exec2  : 1; /* Flag: has execbuffer2? */
107     unsigned int has_bsd    : 1; /* Flag: has bitstream decoder for H.264? */
108     unsigned int has_blt    : 1; /* Flag: has BLT unit? */
109 };
110
111 Bool intel_driver_init(VADriverContextP ctx);
112 Bool intel_driver_terminate(VADriverContextP ctx);
113 void intel_lock_hardware(VADriverContextP ctx);
114 void intel_unlock_hardware(VADriverContextP ctx);
115
116 static INLINE struct intel_driver_data *
117 intel_driver_data(VADriverContextP ctx)
118 {
119     return (struct intel_driver_data *)ctx->pDriverData;
120 }
121
122 struct intel_region
123 {
124     int x;
125     int y;
126     unsigned int width;
127     unsigned int height;
128     unsigned int cpp;
129     unsigned int pitch;
130     unsigned int tiling;
131     unsigned int swizzle;
132     dri_bo *bo;
133 };
134
135 #define PCI_CHIP_GM45_GM                0x2A42
136 #define PCI_CHIP_IGD_E_G                0x2E02
137 #define PCI_CHIP_Q45_G                  0x2E12
138 #define PCI_CHIP_G45_G                  0x2E22
139 #define PCI_CHIP_G41_G                  0x2E32
140
141 #define PCI_CHIP_IRONLAKE_D_G           0x0042
142 #define PCI_CHIP_IRONLAKE_M_G           0x0046
143
144 #ifndef PCI_CHIP_SANDYBRIDGE_GT1
145 #define PCI_CHIP_SANDYBRIDGE_GT1        0x0102  /* Desktop */
146 #define PCI_CHIP_SANDYBRIDGE_GT2        0x0112
147 #define PCI_CHIP_SANDYBRIDGE_GT2_PLUS   0x0122
148 #define PCI_CHIP_SANDYBRIDGE_M_GT1      0x0106  /* Mobile */
149 #define PCI_CHIP_SANDYBRIDGE_M_GT2      0x0116
150 #define PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS 0x0126
151 #define PCI_CHIP_SANDYBRIDGE_S_GT       0x010A  /* Server */
152 #endif
153
154
155 #define IS_G45(devid)           (devid == PCI_CHIP_IGD_E_G ||   \
156                                  devid == PCI_CHIP_Q45_G ||     \
157                                  devid == PCI_CHIP_G45_G ||     \
158                                  devid == PCI_CHIP_G41_G)
159 #define IS_GM45(devid)          (devid == PCI_CHIP_GM45_GM)
160 #define IS_G4X(devid)           (IS_G45(devid) || IS_GM45(devid))
161
162 #define IS_IRONLAKE_D(devid)    (devid == PCI_CHIP_IRONLAKE_D_G)
163 #define IS_IRONLAKE_M(devid)    (devid == PCI_CHIP_IRONLAKE_M_G)
164 #define IS_IRONLAKE(devid)      (IS_IRONLAKE_D(devid) || IS_IRONLAKE_M(devid))
165
166 #define IS_GEN6(devid)          (devid == PCI_CHIP_SANDYBRIDGE_GT1 || \
167                                  devid == PCI_CHIP_SANDYBRIDGE_GT2 || \
168                                  devid == PCI_CHIP_SANDYBRIDGE_GT2_PLUS ||\
169                                  devid == PCI_CHIP_SANDYBRIDGE_M_GT1 || \
170                                  devid == PCI_CHIP_SANDYBRIDGE_M_GT2 || \
171                                  devid == PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS || \
172                                  devid == PCI_CHIP_SANDYBRIDGE_S_GT)
173
174 #endif /* _INTEL_DRIVER_H_ */