1 /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
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.
33 /* General customization:
36 #define DRIVER_AUTHOR "Tungsten Graphics, Inc."
38 #define DRIVER_NAME "i915"
39 #define DRIVER_DESC "Intel Graphics"
40 #define DRIVER_DATE "20070209"
42 #if defined(__linux__)
43 #define I915_HAVE_FENCE
44 #define I915_HAVE_BUFFER
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
61 #define DRIVER_MAJOR 1
62 #if defined(I915_HAVE_FENCE) && defined(I915_HAVE_BUFFER)
63 #define DRIVER_MINOR 11
65 #define DRIVER_MINOR 6
67 #define DRIVER_PATCHLEVEL 0
69 #ifdef I915_HAVE_BUFFER
70 #define I915_MAX_VALIDATE_BUFFERS 4096
73 typedef struct _drm_i915_ring_buffer {
83 } drm_i915_ring_buffer_t;
86 struct mem_block *next;
87 struct mem_block *prev;
90 struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
93 typedef struct _drm_i915_vbl_swap {
94 struct list_head head;
95 drm_drawable_t drw_id;
97 unsigned int sequence;
99 } drm_i915_vbl_swap_t;
101 typedef struct drm_i915_private {
102 drm_local_map_t *sarea;
103 drm_local_map_t *mmio_map;
105 drm_i915_sarea_t *sarea_priv;
106 drm_i915_ring_buffer_t ring;
108 drm_dma_handle_t *status_page_dmah;
109 void *hw_status_page;
110 dma_addr_t dma_status_page;
112 unsigned int status_gfx_addr;
113 drm_local_map_t hws_map;
116 int use_mi_batchbuffer_start;
118 wait_queue_head_t irq_queue;
119 atomic_t irq_received;
120 atomic_t irq_emitted;
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;
127 DRM_SPINTYPE user_irq_lock;
128 int user_irq_refcount;
130 uint32_t irq_enable_reg;
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;
139 #ifdef I915_HAVE_BUFFER
141 unsigned int max_validate_buffers;
144 DRM_SPINTYPE swaps_lock;
145 drm_i915_vbl_swap_t vbl_swaps;
146 unsigned int swaps_pending;
148 } drm_i915_private_t;
150 enum intel_chip_family {
157 extern struct drm_ioctl_desc i915_ioctls[];
158 extern int i915_max_ioctl;
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,
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);
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);
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);
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
213 extern void i915_fence_handler(struct drm_device *dev);
214 extern int i915_fence_emit_sequence(struct drm_device *dev, uint32_t class,
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);
222 #ifdef I915_HAVE_BUFFER
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,
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);
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))
241 #define I915_VERBOSE 0
243 #define RING_LOCALS unsigned int outring, ringmask, outcount; \
246 #define BEGIN_LP_RING(n) do { \
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__); \
253 outring = dev_priv->ring.tail; \
254 ringmask = dev_priv->ring.tail_mask; \
255 virt = dev_priv->ring.virtual_start; \
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); \
263 outring &= ringmask; \
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); \
273 extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
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)
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 */
288 /* Packet to load a register value from the ring/batch command stream:
290 #define CMD_MI_LOAD_REGISTER_IMM ((0x22 << 23)|0x1)
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)
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 */
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
310 #define I915REG_PIPEASTAT 0x70024
311 #define I915REG_PIPEBSTAT 0x71024
313 #define I915_VBLANK_INTERRUPT_ENABLE (1UL<<17)
314 #define I915_VBLANK_CLEAR (1UL<<1)
316 #define SRX_INDEX 0x3c4
317 #define SRX_DATA 0x3c5
319 #define SR01_SCREEN_OFF (1<<5)
322 #define PPCR_ON (1<<0)
325 #define DVOB_ON (1<<31)
327 #define DVOC_ON (1<<31)
329 #define LVDS_ON (1<<31)
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)
339 #define LP_RING 0x2030
340 #define HP_RING 0x2040
341 /* The binner has its own ring buffer:
343 #define HWB_RING 0x2400
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
363 /* Instruction parser error reg:
367 /* Scratch pad debug 0 reg:
375 /* Secondary DMA fetch address debug reg:
377 #define DMA_FADD_S 0x20d4
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.
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.
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)
398 /* Graphics flush control. A CPU write flushes the GWB of all writes.
399 * The data is discarded.
401 #define GFX_FLSH_CNTL 0x2170
403 /* Binner control. Defines the location of the bin pointer list:
405 #define BINCTL 0x2420
406 #define BC_MASK (1 << 9)
408 /* Binned scene info.
410 #define BINSCENE 0x2428
411 #define BS_OP_LOAD (1 << 8)
412 #define BS_MASK (1 << 22)
414 /* Bin command parser debug reg:
418 /* Bin memory control debug reg:
422 /* Bin data cache debug reg:
426 /* Binner pointer cache debug reg:
430 /* Binner scratch pad debug reg:
432 #define BINSKPD 0x24f0
434 /* HWB scratch pad debug reg:
436 #define HWBSKPD 0x24f4
438 /* Binner memory pool reg:
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)
445 /* Get/put memory from the binner memory pool:
447 #define BMP_GET 0x2438
448 #define BMP_PUT 0x2440
449 #define BMP_OFFSET_SHIFT 5
453 #define GFX_OP_RASTER_RULES ((0x3<<29)|(0x7<<24))
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)
460 #define GFX_OP_LOAD_INDIRECT ((0x3<<29)|(0x1d<<24)|(0x7<<16))
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)
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))
476 #define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
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)
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)
488 #define MI_BATCH_NON_SECURE_I965 (1<<8)
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)
495 #define MI_LOAD_SCAN_LINES_INCL ((0x12<<23))
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)
503 #define DSPACNTR 0x70180
504 #define DSPBCNTR 0x71180
505 #define DISPPLANE_SEL_PIPE_MASK (1<<24)
507 /* Define the region of interest for the binner:
509 #define CMD_OP_BIN_CONTROL ((0x3<<29)|(0x1d<<24)|(0x84<<16)|4)
511 #define CMD_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
513 #define BREADCRUMB_BITS 31
514 #define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
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])