e8f1879842724a82f3fada82f278d03dbc8ad5a4
[profile/ivi/libdrm.git] / shared-core / i915_drv.h
1 /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
2  */
3 /*
4  * 
5  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6  * All Rights Reserved.
7  * 
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sub license, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  * 
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  * 
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  * 
28  */
29
30 #ifndef _I915_DRV_H_
31 #define _I915_DRV_H_
32
33 /* General customization:
34  */
35
36 #define DRIVER_AUTHOR           "Tungsten Graphics, Inc."
37
38 #define DRIVER_NAME             "i915"
39 #define DRIVER_DESC             "Intel Graphics"
40 #define DRIVER_DATE             "20070209"
41
42 #if defined(__linux__)
43 #define I915_HAVE_FENCE
44 #define I915_HAVE_BUFFER
45 #endif
46
47 /* Interface history:
48  *
49  * 1.1: Original.
50  * 1.2: Add Power Management
51  * 1.3: Add vblank support
52  * 1.4: Fix cmdbuffer path, add heap destroy
53  * 1.5: Add vblank pipe configuration
54  * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
55  *      - Support vertical blank on secondary display pipe
56  * 1.8: New ioctl for ARB_Occlusion_Query
57  * 1.9: Usable page flipping and triple buffering
58  * 1.10: Plane/pipe disentangling
59  * 1.11: TTM superioctl
60  */
61 #define DRIVER_MAJOR            1
62 #if defined(I915_HAVE_FENCE) && defined(I915_HAVE_BUFFER)
63 #define DRIVER_MINOR            11
64 #else
65 #define DRIVER_MINOR            6
66 #endif
67 #define DRIVER_PATCHLEVEL       0
68
69 #ifdef I915_HAVE_BUFFER
70 #define I915_MAX_VALIDATE_BUFFERS 4096
71 #endif
72
73 typedef struct _drm_i915_ring_buffer {
74         int tail_mask;
75         unsigned long Start;
76         unsigned long End;
77         unsigned long Size;
78         u8 *virtual_start;
79         int head;
80         int tail;
81         int space;
82         drm_local_map_t map;
83 } drm_i915_ring_buffer_t;
84
85 struct mem_block {
86         struct mem_block *next;
87         struct mem_block *prev;
88         int start;
89         int size;
90         struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
91 };
92
93 typedef struct _drm_i915_vbl_swap {
94         struct list_head head;
95         drm_drawable_t drw_id;
96         unsigned int plane;
97         unsigned int sequence;
98         int flip;
99 } drm_i915_vbl_swap_t;
100
101 typedef struct drm_i915_private {
102         drm_local_map_t *sarea;
103         drm_local_map_t *mmio_map;
104
105         drm_i915_sarea_t *sarea_priv;
106         drm_i915_ring_buffer_t ring;
107
108         drm_dma_handle_t *status_page_dmah;
109         void *hw_status_page;
110         dma_addr_t dma_status_page;
111         uint32_t counter;
112         unsigned int status_gfx_addr;
113         drm_local_map_t hws_map;
114
115         unsigned int cpp;
116         int use_mi_batchbuffer_start;
117
118         wait_queue_head_t irq_queue;
119         atomic_t irq_received;
120         atomic_t irq_emitted;
121
122         int tex_lru_log_granularity;
123         int allow_batchbuffer;
124         struct mem_block *agp_heap;
125         unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
126         int vblank_pipe;
127         DRM_SPINTYPE user_irq_lock;
128         int user_irq_refcount;
129         int fence_irq_on;
130         uint32_t irq_enable_reg;
131         int irq_enabled;
132
133 #ifdef I915_HAVE_FENCE
134         uint32_t flush_sequence;
135         uint32_t flush_flags;
136         uint32_t flush_pending;
137         uint32_t saved_flush_status;
138 #endif
139 #ifdef I915_HAVE_BUFFER
140         void *agp_iomap;
141         unsigned int max_validate_buffers;
142 #endif
143
144         DRM_SPINTYPE swaps_lock;
145         drm_i915_vbl_swap_t vbl_swaps;
146         unsigned int swaps_pending;
147
148 } drm_i915_private_t;
149
150 enum intel_chip_family {
151         CHIP_I8XX = 0x01,
152         CHIP_I9XX = 0x02,
153         CHIP_I915 = 0x04,
154         CHIP_I965 = 0x08,
155 };
156
157 extern struct drm_ioctl_desc i915_ioctls[];
158 extern int i915_max_ioctl;
159
160                                 /* i915_dma.c */
161 extern void i915_kernel_lost_context(struct drm_device * dev);
162 extern int i915_driver_load(struct drm_device *, unsigned long flags);
163 extern void i915_driver_lastclose(struct drm_device * dev);
164 extern void i915_driver_preclose(struct drm_device *dev,
165                                  struct drm_file *file_priv);
166 extern int i915_driver_device_is_agp(struct drm_device * dev);
167 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
168                               unsigned long arg);
169 extern void i915_emit_breadcrumb(struct drm_device *dev);
170 extern void i915_dispatch_flip(struct drm_device * dev, int pipes, int sync);
171 extern int i915_emit_mi_flush(struct drm_device *dev, uint32_t flush);
172 extern int i915_driver_firstopen(struct drm_device *dev);
173
174 /* i915_irq.c */
175 extern int i915_irq_emit(struct drm_device *dev, void *data,
176                          struct drm_file *file_priv);
177 extern int i915_irq_wait(struct drm_device *dev, void *data,
178                          struct drm_file *file_priv);
179
180 extern int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence);
181 extern int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
182 extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
183 extern void i915_driver_irq_preinstall(struct drm_device * dev);
184 extern void i915_driver_irq_postinstall(struct drm_device * dev);
185 extern void i915_driver_irq_uninstall(struct drm_device * dev);
186 extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
187                                 struct drm_file *file_priv);
188 extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
189                                 struct drm_file *file_priv);
190 extern int i915_emit_irq(struct drm_device * dev);
191 extern void i915_user_irq_on(drm_i915_private_t *dev_priv);
192 extern void i915_user_irq_off(drm_i915_private_t *dev_priv);
193 extern int i915_vblank_swap(struct drm_device *dev, void *data,
194                             struct drm_file *file_priv);
195
196 /* i915_mem.c */
197 extern int i915_mem_alloc(struct drm_device *dev, void *data,
198                           struct drm_file *file_priv);
199 extern int i915_mem_free(struct drm_device *dev, void *data,
200                          struct drm_file *file_priv);
201 extern int i915_mem_init_heap(struct drm_device *dev, void *data,
202                               struct drm_file *file_priv);
203 extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
204                                  struct drm_file *file_priv);
205 extern void i915_mem_takedown(struct mem_block **heap);
206 extern void i915_mem_release(struct drm_device * dev,
207                              struct drm_file *file_priv,
208                              struct mem_block *heap);
209 #ifdef I915_HAVE_FENCE
210 /* i915_fence.c */
211
212
213 extern void i915_fence_handler(struct drm_device *dev);
214 extern int i915_fence_emit_sequence(struct drm_device *dev, uint32_t class,
215                                     uint32_t flags,
216                                     uint32_t *sequence, 
217                                     uint32_t *native_type);
218 extern void i915_poke_flush(struct drm_device *dev, uint32_t class);
219 extern int i915_fence_has_irq(struct drm_device *dev, uint32_t class, uint32_t flags);
220 #endif
221
222 #ifdef I915_HAVE_BUFFER
223 /* i915_buffer.c */
224 extern struct drm_ttm_backend *i915_create_ttm_backend_entry(struct drm_device *dev);
225 extern int i915_fence_types(struct drm_buffer_object *bo, uint32_t *fclass,
226                             uint32_t *type);
227 extern int i915_invalidate_caches(struct drm_device *dev, uint64_t buffer_flags);
228 extern int i915_init_mem_type(struct drm_device *dev, uint32_t type,
229                                struct drm_mem_type_manager *man);
230 extern uint32_t i915_evict_mask(struct drm_buffer_object *bo);
231 extern int i915_move(struct drm_buffer_object *bo, int evict,
232                 int no_wait, struct drm_bo_mem_reg *new_mem);
233
234 #endif
235
236 #define I915_READ(reg)          DRM_READ32(dev_priv->mmio_map, (reg))
237 #define I915_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, (reg), (val))
238 #define I915_READ16(reg)        DRM_READ16(dev_priv->mmio_map, (reg))
239 #define I915_WRITE16(reg,val)   DRM_WRITE16(dev_priv->mmio_map, (reg), (val))
240
241 #define I915_VERBOSE 0
242
243 #define RING_LOCALS     unsigned int outring, ringmask, outcount; \
244                         volatile char *virt;
245
246 #define BEGIN_LP_RING(n) do {                           \
247         if (I915_VERBOSE)                               \
248                 DRM_DEBUG("BEGIN_LP_RING(%d) in %s\n",  \
249                                  (n), __FUNCTION__);           \
250         if (dev_priv->ring.space < (n)*4)                      \
251                 i915_wait_ring(dev, (n)*4, __FUNCTION__);      \
252         outcount = 0;                                   \
253         outring = dev_priv->ring.tail;                  \
254         ringmask = dev_priv->ring.tail_mask;            \
255         virt = dev_priv->ring.virtual_start;            \
256 } while (0)
257
258 #define OUT_RING(n) do {                                        \
259         if (I915_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
260         *(volatile unsigned int *)(virt + outring) = (n);               \
261         outcount++;                                             \
262         outring += 4;                                           \
263         outring &= ringmask;                                    \
264 } while (0)
265
266 #define ADVANCE_LP_RING() do {                                          \
267         if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring);   \
268         dev_priv->ring.tail = outring;                                  \
269         dev_priv->ring.space -= outcount * 4;                           \
270         I915_WRITE(LP_RING + RING_TAIL, outring);                       \
271 } while(0)
272
273 extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
274
275 #define GFX_OP_USER_INTERRUPT           ((0<<29)|(2<<23))
276 #define GFX_OP_BREAKPOINT_INTERRUPT     ((0<<29)|(1<<23))
277 #define CMD_REPORT_HEAD                 (7<<23)
278 #define CMD_STORE_DWORD_IDX             ((0x21<<23) | 0x1)
279 #define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
280
281 #define CMD_MI_FLUSH         (0x04 << 23)
282 #define MI_NO_WRITE_FLUSH    (1 << 2)
283 #define MI_READ_FLUSH        (1 << 0)
284 #define MI_EXE_FLUSH         (1 << 1)
285 #define MI_END_SCENE         (1 << 4) /* flush binner and incr scene count */
286 #define MI_SCENE_COUNT       (1 << 3) /* just increment scene count */
287
288 /* Packet to load a register value from the ring/batch command stream:
289  */
290 #define CMD_MI_LOAD_REGISTER_IMM        ((0x22 << 23)|0x1)
291
292 #define BB1_START_ADDR_MASK   (~0x7)
293 #define BB1_PROTECTED         (1<<0)
294 #define BB1_UNPROTECTED       (0<<0)
295 #define BB2_END_ADDR_MASK     (~0x7)
296
297 /* Interrupt bits:
298  */
299 #define USER_INT_FLAG    (1<<1)
300 #define VSYNC_PIPEB_FLAG (1<<5)
301 #define VSYNC_PIPEA_FLAG (1<<7)
302 #define HWB_OOM_FLAG     (1<<13) /* binner out of memory */
303
304 #define I915REG_HWSTAM          0x02098
305 #define I915REG_INT_IDENTITY_R  0x020a4
306 #define I915REG_INT_MASK_R      0x020a8
307 #define I915REG_INT_ENABLE_R    0x020a0
308 #define I915REG_INSTPM          0x020c0
309
310 #define I915REG_PIPEASTAT       0x70024
311 #define I915REG_PIPEBSTAT       0x71024
312
313 #define I915_VBLANK_INTERRUPT_ENABLE    (1UL<<17)
314 #define I915_VBLANK_CLEAR               (1UL<<1)
315
316 #define SRX_INDEX               0x3c4
317 #define SRX_DATA                0x3c5
318 #define SR01                    1
319 #define SR01_SCREEN_OFF         (1<<5)
320
321 #define PPCR                    0x61204
322 #define PPCR_ON                 (1<<0)
323
324 #define DVOB                    0x61140
325 #define DVOB_ON                 (1<<31)
326 #define DVOC                    0x61160
327 #define DVOC_ON                 (1<<31)
328 #define LVDS                    0x61180
329 #define LVDS_ON                 (1<<31)
330
331 #define ADPA                    0x61100
332 #define ADPA_DPMS_MASK          (~(3<<10))
333 #define ADPA_DPMS_ON            (0<<10)
334 #define ADPA_DPMS_SUSPEND       (1<<10)
335 #define ADPA_DPMS_STANDBY       (2<<10)
336 #define ADPA_DPMS_OFF           (3<<10)
337
338 #define NOPID                   0x2094
339 #define LP_RING                 0x2030
340 #define HP_RING                 0x2040
341 /* The binner has its own ring buffer:
342  */
343 #define HWB_RING                0x2400
344
345 #define RING_TAIL               0x00
346 #define TAIL_ADDR               0x001FFFF8
347 #define RING_HEAD               0x04
348 #define HEAD_WRAP_COUNT         0xFFE00000
349 #define HEAD_WRAP_ONE           0x00200000
350 #define HEAD_ADDR               0x001FFFFC
351 #define RING_START              0x08
352 #define START_ADDR              0x0xFFFFF000
353 #define RING_LEN                0x0C
354 #define RING_NR_PAGES           0x001FF000
355 #define RING_REPORT_MASK        0x00000006
356 #define RING_REPORT_64K         0x00000002
357 #define RING_REPORT_128K        0x00000004
358 #define RING_NO_REPORT          0x00000000
359 #define RING_VALID_MASK         0x00000001
360 #define RING_VALID              0x00000001
361 #define RING_INVALID            0x00000000
362
363 /* Instruction parser error reg:
364  */
365 #define IPEIR                   0x2088
366
367 /* Scratch pad debug 0 reg:
368  */
369 #define SCPD0                   0x209c
370
371 /* Error status reg:
372  */
373 #define ESR                     0x20b8
374
375 /* Secondary DMA fetch address debug reg:
376  */
377 #define DMA_FADD_S              0x20d4
378
379 /* Cache mode 0 reg.  
380  *  - Manipulating render cache behaviour is central
381  *    to the concept of zone rendering, tuning this reg can help avoid
382  *    unnecessary render cache reads and even writes (for z/stencil)
383  *    at beginning and end of scene.
384  *
385  * - To change a bit, write to this reg with a mask bit set and the
386  * bit of interest either set or cleared.  EG: (BIT<<16) | BIT to set.
387  */
388 #define Cache_Mode_0            0x2120
389 #define CM0_MASK_SHIFT          16
390 #define CM0_IZ_OPT_DISABLE      (1<<6)
391 #define CM0_ZR_OPT_DISABLE      (1<<5)
392 #define CM0_DEPTH_EVICT_DISABLE (1<<4)
393 #define CM0_COLOR_EVICT_DISABLE (1<<3)
394 #define CM0_DEPTH_WRITE_DISABLE (1<<1)
395 #define CM0_RC_OP_FLUSH_DISABLE (1<<0)
396
397
398 /* Graphics flush control.  A CPU write flushes the GWB of all writes.
399  * The data is discarded.
400  */
401 #define GFX_FLSH_CNTL           0x2170
402
403 /* Binner control.  Defines the location of the bin pointer list:
404  */
405 #define BINCTL                  0x2420
406 #define BC_MASK                 (1 << 9)
407
408 /* Binned scene info.  
409  */
410 #define BINSCENE                0x2428
411 #define BS_OP_LOAD              (1 << 8)
412 #define BS_MASK                 (1 << 22)
413
414 /* Bin command parser debug reg:
415  */
416 #define BCPD                    0x2480
417
418 /* Bin memory control debug reg:
419  */
420 #define BMCD                    0x2484
421
422 /* Bin data cache debug reg:
423  */
424 #define BDCD                    0x2488
425
426 /* Binner pointer cache debug reg: 
427  */
428 #define BPCD                    0x248c
429
430 /* Binner scratch pad debug reg:
431  */
432 #define BINSKPD                 0x24f0
433
434 /* HWB scratch pad debug reg:
435  */
436 #define HWBSKPD                 0x24f4
437
438 /* Binner memory pool reg:
439  */
440 #define BMP_BUFFER              0x2430
441 #define BMP_PAGE_SIZE_4K        (0 << 10)
442 #define BMP_BUFFER_SIZE_SHIFT   1
443 #define BMP_ENABLE              (1 << 0)
444
445 /* Get/put memory from the binner memory pool:
446  */
447 #define BMP_GET                 0x2438
448 #define BMP_PUT                 0x2440
449 #define BMP_OFFSET_SHIFT        5
450
451 /* 3D state packets:
452  */
453 #define GFX_OP_RASTER_RULES    ((0x3<<29)|(0x7<<24))
454
455 #define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
456 #define SC_UPDATE_SCISSOR       (0x1<<1)
457 #define SC_ENABLE_MASK          (0x1<<0)
458 #define SC_ENABLE               (0x1<<0)
459
460 #define GFX_OP_LOAD_INDIRECT   ((0x3<<29)|(0x1d<<24)|(0x7<<16))
461
462 #define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
463 #define SCI_YMIN_MASK      (0xffff<<16)
464 #define SCI_XMIN_MASK      (0xffff<<0)
465 #define SCI_YMAX_MASK      (0xffff<<16)
466 #define SCI_XMAX_MASK      (0xffff<<0)
467
468 #define GFX_OP_SCISSOR_ENABLE    ((0x3<<29)|(0x1c<<24)|(0x10<<19))
469 #define GFX_OP_SCISSOR_RECT      ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
470 #define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
471 #define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
472 #define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x4)
473 #define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
474 #define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
475
476 #define GFX_OP_DRAWRECT_INFO_I965  ((0x7900<<16)|0x2)
477
478 #define SRC_COPY_BLT_CMD                ((2<<29)|(0x43<<22)|4)
479 #define XY_SRC_COPY_BLT_CMD             ((2<<29)|(0x53<<22)|6)
480 #define XY_SRC_COPY_BLT_WRITE_ALPHA     (1<<21)
481 #define XY_SRC_COPY_BLT_WRITE_RGB       (1<<20)
482
483 #define MI_BATCH_BUFFER         ((0x30<<23)|1)
484 #define MI_BATCH_BUFFER_START   (0x31<<23)
485 #define MI_BATCH_BUFFER_END     (0xA<<23)
486 #define MI_BATCH_NON_SECURE     (1)
487
488 #define MI_BATCH_NON_SECURE_I965 (1<<8)
489
490 #define MI_WAIT_FOR_EVENT       ((0x3<<23))
491 #define MI_WAIT_FOR_PLANE_B_FLIP      (1<<6)
492 #define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
493 #define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
494
495 #define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
496
497 #define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
498 #define ASYNC_FLIP                (1<<22)
499 #define DISPLAY_PLANE_A           (0<<20)
500 #define DISPLAY_PLANE_B           (1<<20)
501
502 /* Display regs */
503 #define DSPACNTR                0x70180
504 #define DSPBCNTR                0x71180
505 #define DISPPLANE_SEL_PIPE_MASK                 (1<<24)
506
507 /* Define the region of interest for the binner:
508  */
509 #define CMD_OP_BIN_CONTROL       ((0x3<<29)|(0x1d<<24)|(0x84<<16)|4)
510
511 #define CMD_OP_DESTBUFFER_INFO   ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
512
513 #define BREADCRUMB_BITS 31
514 #define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
515
516 #define READ_BREADCRUMB(dev_priv)  (((volatile u32*)(dev_priv->hw_status_page))[5])
517 #define READ_HWSP(dev_priv, reg)  (((volatile u32*)(dev_priv->hw_status_page))[reg])
518 #endif