1 /* BEGIN CSTYLED */ 2 3 /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*- 4 */ 5 /* 6 * 7 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 8 * All Rights Reserved. 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining a 11 * copy of this software and associated documentation files (the 12 * "Software"), to deal in the Software without restriction, including 13 * without limitation the rights to use, copy, modify, merge, publish, 14 * distribute, sub license, and/or sell copies of the Software, and to 15 * permit persons to whom the Software is furnished to do so, subject to 16 * the following conditions: 17 * 18 * The above copyright notice and this permission notice (including the 19 * next paragraph) shall be included in all copies or substantial portions 20 * of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 25 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 26 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 * 30 */ 31 32 /* 33 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 34 * Use is subject to license terms. 35 */ 36 37 #ifndef _I915_DRV_H 38 #define _I915_DRV_H 39 40 #pragma ident "%Z%%M% %I% %E% SMI" 41 42 /* General customization: 43 */ 44 45 #define DRIVER_AUTHOR "Tungsten Graphics, Inc." 46 47 #define DRIVER_NAME "i915" 48 #define DRIVER_DESC "Intel Graphics" 49 #define DRIVER_DATE "20060929" 50 51 #if defined(__SVR4) && defined(__sun) 52 #define spinlock_t kmutex_t 53 #endif 54 55 /* Interface history: 56 * 57 * 1.1: Original. 58 * 1.2: Add Power Management 59 * 1.3: Add vblank support 60 * 1.4: Fix cmdbuffer path, add heap destroy 61 */ 62 #define DRIVER_MAJOR 1 63 #define DRIVER_MINOR 4 64 #define DRIVER_PATCHLEVEL 0 65 66 #if defined(__linux__) 67 #define I915_HAVE_FENCE 68 #define I915_HAVE_BUFFER 69 #endif 70 71 typedef struct _drm_i915_ring_buffer { 72 int tail_mask; 73 unsigned long Start; 74 unsigned long End; 75 unsigned long Size; 76 u8 *virtual_start; 77 int head; 78 int tail; 79 int space; 80 drm_local_map_t map; 81 } drm_i915_ring_buffer_t; 82 83 struct mem_block { 84 struct mem_block *next; 85 struct mem_block *prev; 86 int start; 87 int size; 88 DRMFILE filp; /* 0: free, -1: heap, other: real files */ 89 }; 90 91 typedef struct _drm_i915_vbl_swap { 92 struct list_head head; 93 drm_drawable_t drw_id; 94 unsigned int pipe; 95 unsigned int sequence; 96 } drm_i915_vbl_swap_t; 97 98 typedef struct drm_i915_private { 99 drm_local_map_t *sarea; 100 drm_local_map_t *mmio_map; 101 102 drm_i915_sarea_t *sarea_priv; 103 drm_i915_ring_buffer_t ring; 104 105 #if !defined(__SOLARIS__) && !defined(sun) 106 drm_dma_handle_t *status_page_dmah; 107 #endif 108 void *hw_status_page; 109 dma_addr_t dma_status_page; 110 uint32_t counter; 111 112 unsigned int cpp; 113 int back_offset; 114 int front_offset; 115 int current_page; 116 int page_flipping; 117 int use_mi_batchbuffer_start; 118 119 wait_queue_head_t irq_queue; 120 atomic_t irq_received; 121 atomic_t irq_emitted; 122 123 int tex_lru_log_granularity; 124 int allow_batchbuffer; 125 struct mem_block *agp_heap; 126 unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds; 127 int vblank_pipe; 128 spinlock_t user_irq_lock; 129 int user_irq_refcount; 130 int fence_irq_on; 131 uint32_t irq_enable_reg; 132 int irq_enabled; 133 134 #ifdef I915_HAVE_FENCE 135 uint32_t flush_sequence; 136 uint32_t flush_flags; 137 uint32_t flush_pending; 138 uint32_t saved_flush_status; 139 #endif 140 #ifdef I915_HAVE_BUFFER 141 void *agp_iomap; 142 #endif 143 spinlock_t swaps_lock; 144 drm_i915_vbl_swap_t vbl_swaps; 145 unsigned int swaps_pending; 146 } drm_i915_private_t; 147 148 enum intel_chip_family { 149 CHIP_I8XX = 0x01, 150 CHIP_I9XX = 0x02, 151 CHIP_I915 = 0x04, 152 CHIP_I965 = 0x08, 153 }; 154 155 extern drm_ioctl_desc_t i915_ioctls[]; 156 extern int i915_max_ioctl; 157 158 /* i915_dma.c */ 159 extern void i915_kernel_lost_context(drm_device_t * dev); 160 extern int i915_driver_load(struct drm_device *, unsigned long flags); 161 extern void i915_driver_lastclose(drm_device_t * dev); 162 extern void i915_driver_preclose(drm_device_t * dev, DRMFILE filp); 163 extern int i915_driver_device_is_agp(drm_device_t * dev); 164 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd, 165 unsigned long arg); 166 extern int i915_emit_mi_flush(drm_device_t *dev, uint32_t flush); 167 168 169 /* i915_irq.c */ 170 extern int i915_irq_emit(DRM_IOCTL_ARGS); 171 extern int i915_irq_wait(DRM_IOCTL_ARGS); 172 173 extern int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence); 174 extern int i915_driver_vblank_wait2(drm_device_t *dev, unsigned int *sequence); 175 extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS); 176 extern void i915_driver_irq_preinstall(drm_device_t * dev); 177 extern void i915_driver_irq_postinstall(drm_device_t * dev); 178 extern void i915_driver_irq_uninstall(drm_device_t * dev); 179 extern int i915_emit_irq(drm_device_t * dev); 180 extern void i915_user_irq_on(drm_i915_private_t *dev_priv); 181 extern void i915_user_irq_off(drm_i915_private_t *dev_priv); 182 183 /* i915_mem.c */ 184 extern int i915_mem_alloc(DRM_IOCTL_ARGS); 185 extern int i915_mem_free(DRM_IOCTL_ARGS); 186 extern int i915_mem_init_heap(DRM_IOCTL_ARGS); 187 extern int i915_mem_destroy_heap(DRM_IOCTL_ARGS); 188 extern void i915_mem_takedown(struct mem_block **heap); 189 extern void i915_mem_release(drm_device_t * dev, 190 DRMFILE filp, struct mem_block *heap); 191 extern struct mem_block **get_heap(drm_i915_private_t *, int); 192 extern struct mem_block *find_block_by_proc(struct mem_block *, DRMFILE); 193 extern void mark_block(drm_device_t *, struct mem_block *, int); 194 extern void free_block(struct mem_block *); 195 196 #ifdef I915_HAVE_FENCE 197 /* i915_fence.c */ 198 199 200 extern void i915_fence_handler(drm_device_t *dev); 201 extern int i915_fence_emit_sequence(drm_device_t *dev, uint32_t class, 202 uint32_t flags, 203 uint32_t *sequence, 204 uint32_t *native_type); 205 extern void i915_poke_flush(drm_device_t *dev, uint32_t class); 206 extern int i915_fence_has_irq(drm_device_t *dev, uint32_t class, uint32_t flags); 207 #endif 208 209 #ifdef I915_HAVE_BUFFER 210 /* i915_buffer.c */ 211 extern drm_ttm_backend_t *i915_create_ttm_backend_entry(drm_device_t *dev); 212 extern int i915_fence_types(drm_buffer_object_t *bo, uint32_t *class, uint32_t *type); 213 extern int i915_invalidate_caches(drm_device_t *dev, uint32_t buffer_flags); 214 extern int i915_init_mem_type(drm_device_t *dev, uint32_t type, 215 drm_mem_type_manager_t *man); 216 extern uint32_t i915_evict_mask(drm_buffer_object_t *bo); 217 extern int i915_move(drm_buffer_object_t *bo, int evict, 218 int no_wait, drm_bo_mem_reg_t *new_mem); 219 220 #endif 221 222 #define I915_READ(reg) DRM_READ32(dev_priv->mmio_map, (reg)) 223 #define I915_WRITE(reg,val) DRM_WRITE32(dev_priv->mmio_map, (reg), (val)) 224 #define I915_READ16(reg) DRM_READ16(dev_priv->mmio_map, (reg)) 225 #define I915_WRITE16(reg,val) DRM_WRITE16(dev_priv->mmio_map, (reg), (val)) 226 227 #define RING_LOCALS unsigned int outring, ringmask, outcount; \ 228 volatile unsigned char *virt; 229 230 #define BEGIN_LP_RING(n) do { \ 231 if (dev_priv->ring.space < (n)*4) \ 232 (void) i915_wait_ring(dev, (n)*4, __FUNCTION__); \ 233 outcount = 0; \ 234 outring = dev_priv->ring.tail; \ 235 ringmask = dev_priv->ring.tail_mask; \ 236 virt = dev_priv->ring.virtual_start; \ 237 } while (*"\0") 238 239 #define OUT_RING(n) do { \ 240 *(volatile unsigned int *)(virt + outring) = (n); \ 241 outcount++; \ 242 outring += 4; \ 243 outring &= ringmask; \ 244 } while (*"\0") 245 246 #define ADVANCE_LP_RING() do { \ 247 dev_priv->ring.tail = outring; \ 248 dev_priv->ring.space -= outcount * 4; \ 249 I915_WRITE(LP_RING + RING_TAIL, outring); \ 250 } while (*"\0") 251 252 extern int i915_wait_ring(drm_device_t * dev, int n, const char *caller); 253 254 #define GFX_OP_USER_INTERRUPT ((0<<29)|(2<<23)) 255 #define GFX_OP_BREAKPOINT_INTERRUPT ((0<<29)|(1<<23)) 256 #define CMD_REPORT_HEAD (7<<23) 257 #define CMD_STORE_DWORD_IDX ((0x21<<23) | 0x1) 258 #define CMD_OP_BATCH_BUFFER ((0x0<<29)|(0x30<<23)|0x1) 259 260 #define INST_PARSER_CLIENT 0x00000000 261 #define INST_OP_FLUSH 0x02000000 262 #define INST_FLUSH_MAP_CACHE 0x00000001 263 264 #define CMD_MI_FLUSH (0x04 << 23) 265 #define MI_NO_WRITE_FLUSH (1 << 2) 266 #define MI_READ_FLUSH (1 << 0) 267 #define MI_EXE_FLUSH (1 << 1) 268 269 #define BB1_START_ADDR_MASK (~0x7) 270 #define BB1_PROTECTED (1<<0) 271 #define BB1_UNPROTECTED (0<<0) 272 #define BB2_END_ADDR_MASK (~0x7) 273 274 #define I915REG_HWSTAM 0x02098 275 #define I915REG_INT_IDENTITY_R 0x020a4 276 #define I915REG_INT_MASK_R 0x020a8 277 #define I915REG_INT_ENABLE_R 0x020a0 278 #define I915REG_INSTPM 0x020c0 279 280 #define I915REG_PIPEASTAT 0x70024 281 #define I915REG_PIPEBSTAT 0x71024 282 283 #define I915_VBLANK_INTERRUPT_ENABLE (1UL<<17) 284 #define I915_VBLANK_CLEAR (1UL<<1) 285 286 #define SRX_INDEX 0x3c4 287 #define SRX_DATA 0x3c5 288 #define SR01 1 289 #define SR01_SCREEN_OFF (1<<5) 290 291 #define PPCR 0x61204 292 #define PPCR_ON (1<<0) 293 294 #define DVOB 0x61140 295 #define DVOB_ON (1<<31) 296 #define DVOC 0x61160 297 #define DVOC_ON (1<<31) 298 #define LVDS 0x61180 299 #define LVDS_ON (1<<31) 300 301 #define ADPA 0x61100 302 #define ADPA_DPMS_MASK (~(3<<10)) 303 #define ADPA_DPMS_ON (0<<10) 304 #define ADPA_DPMS_SUSPEND (1<<10) 305 #define ADPA_DPMS_STANDBY (2<<10) 306 #define ADPA_DPMS_OFF (3<<10) 307 308 #define NOPID 0x2094 309 #define LP_RING 0x2030 310 #define HP_RING 0x2040 311 #define RING_TAIL 0x00 312 #define TAIL_ADDR 0x001FFFF8 313 #define RING_HEAD 0x04 314 #define HEAD_WRAP_COUNT 0xFFE00000 315 #define HEAD_WRAP_ONE 0x00200000 316 #define HEAD_ADDR 0x001FFFFC 317 #define RING_START 0x08 318 #define START_ADDR 0x0xFFFFF000 319 #define RING_LEN 0x0C 320 #define RING_NR_PAGES 0x001FF000 321 #define RING_REPORT_MASK 0x00000006 322 #define RING_REPORT_64K 0x00000002 323 #define RING_REPORT_128K 0x00000004 324 #define RING_NO_REPORT 0x00000000 325 #define RING_VALID_MASK 0x00000001 326 #define RING_VALID 0x00000001 327 #define RING_INVALID 0x00000000 328 329 #define GFX_OP_SCISSOR ((0x3<<29)|(0x1c<<24)|(0x10<<19)) 330 #define SC_UPDATE_SCISSOR (0x1<<1) 331 #define SC_ENABLE_MASK (0x1<<0) 332 #define SC_ENABLE (0x1<<0) 333 334 #define GFX_OP_SCISSOR_INFO ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1)) 335 #define SCI_YMIN_MASK (0xffff<<16) 336 #define SCI_XMIN_MASK (0xffff<<0) 337 #define SCI_YMAX_MASK (0xffff<<16) 338 #define SCI_XMAX_MASK (0xffff<<0) 339 340 #define GFX_OP_SCISSOR_ENABLE ((0x3<<29)|(0x1c<<24)|(0x10<<19)) 341 #define GFX_OP_SCISSOR_RECT ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1) 342 #define GFX_OP_COLOR_FACTOR ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0) 343 #define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16)) 344 #define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x4) 345 #define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0) 346 #define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3)) 347 348 #define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2) 349 350 #define SRC_COPY_BLT_CMD ((2<<29)|(0x43<<22)|4) 351 #define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6) 352 #define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21) 353 #define XY_SRC_COPY_BLT_WRITE_RGB (1<<20) 354 355 #define MI_BATCH_BUFFER ((0x30<<23)|1) 356 #define MI_BATCH_BUFFER_START (0x31<<23) 357 #define MI_BATCH_BUFFER_END (0xA<<23) 358 #define MI_BATCH_NON_SECURE (1) 359 360 #define MI_WAIT_FOR_EVENT ((0x3<<23)) 361 #define MI_WAIT_FOR_PLANE_A_FLIP (1<<2) 362 #define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1) 363 364 #define MI_LOAD_SCAN_LINES_INCL ((0x12<<23)) 365 366 #define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2) 367 #define ASYNC_FLIP (1<<22) 368 369 #define CMD_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1) 370 371 #define READ_BREADCRUMB(dev_priv) (((volatile u32*)(dev_priv->hw_status_page))[5]) 372 #define READ_HWSP(dev_priv, reg) (((volatile u32*)(dev_priv->hw_status_page))[reg]) 373 374 #endif /* _I915_DRV_H */ 375