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 2008 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 drm_file_t *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 drm_dma_handle_t *status_page_dmah; 106 void *hw_status_page; 107 dma_addr_t dma_status_page; 108 uint32_t counter; 109 110 unsigned int cpp; 111 int back_offset; 112 int front_offset; 113 int current_page; 114 int page_flipping; 115 int use_mi_batchbuffer_start; 116 117 wait_queue_head_t irq_queue; 118 atomic_t irq_received; 119 atomic_t irq_emitted; 120 121 int tex_lru_log_granularity; 122 int allow_batchbuffer; 123 struct mem_block *agp_heap; 124 unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds; 125 int vblank_pipe; 126 spinlock_t user_irq_lock; 127 int user_irq_refcount; 128 int fence_irq_on; 129 uint32_t irq_enable_reg; 130 int irq_enabled; 131 132 #ifdef I915_HAVE_FENCE 133 uint32_t flush_sequence; 134 uint32_t flush_flags; 135 uint32_t flush_pending; 136 uint32_t saved_flush_status; 137 #endif 138 #ifdef I915_HAVE_BUFFER 139 void *agp_iomap; 140 #endif 141 spinlock_t swaps_lock; 142 drm_i915_vbl_swap_t vbl_swaps; 143 unsigned int swaps_pending; 144 } drm_i915_private_t; 145 146 enum intel_chip_family { 147 CHIP_I8XX = 0x01, 148 CHIP_I9XX = 0x02, 149 CHIP_I915 = 0x04, 150 CHIP_I965 = 0x08, 151 }; 152 153 extern drm_ioctl_desc_t i915_ioctls[]; 154 extern int i915_max_ioctl; 155 156 /* i915_dma.c */ 157 extern void i915_kernel_lost_context(drm_device_t * dev); 158 extern int i915_driver_load(struct drm_device *, unsigned long flags); 159 extern void i915_driver_lastclose(drm_device_t * dev); 160 extern void i915_driver_preclose(drm_device_t * dev, drm_file_t *filp); 161 extern int i915_driver_device_is_agp(drm_device_t * dev); 162 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd, 163 unsigned long arg); 164 extern int i915_emit_mi_flush(drm_device_t *dev, uint32_t flush); 165 166 167 /* i915_irq.c */ 168 extern int i915_irq_emit(DRM_IOCTL_ARGS); 169 extern int i915_irq_wait(DRM_IOCTL_ARGS); 170 171 extern int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence); 172 extern int i915_driver_vblank_wait2(drm_device_t *dev, unsigned int *sequence); 173 extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS); 174 extern void i915_driver_irq_preinstall(drm_device_t * dev); 175 extern void i915_driver_irq_postinstall(drm_device_t * dev); 176 extern void i915_driver_irq_uninstall(drm_device_t * dev); 177 extern int i915_emit_irq(drm_device_t * dev); 178 extern void i915_user_irq_on(drm_i915_private_t *dev_priv); 179 extern void i915_user_irq_off(drm_i915_private_t *dev_priv); 180 181 /* i915_mem.c */ 182 extern int i915_mem_alloc(DRM_IOCTL_ARGS); 183 extern int i915_mem_free(DRM_IOCTL_ARGS); 184 extern int i915_mem_init_heap(DRM_IOCTL_ARGS); 185 extern int i915_mem_destroy_heap(DRM_IOCTL_ARGS); 186 extern void i915_mem_takedown(struct mem_block **heap); 187 extern void i915_mem_release(drm_device_t * dev, 188 drm_file_t *filp, struct mem_block *heap); 189 extern struct mem_block **get_heap(drm_i915_private_t *, int); 190 extern struct mem_block *find_block_by_proc(struct mem_block *, drm_file_t *); 191 extern void mark_block(drm_device_t *, struct mem_block *, int); 192 extern void free_block(struct mem_block *); 193 194 #ifdef I915_HAVE_FENCE 195 /* i915_fence.c */ 196 197 198 extern void i915_fence_handler(drm_device_t *dev); 199 extern int i915_fence_emit_sequence(drm_device_t *dev, uint32_t class, 200 uint32_t flags, 201 uint32_t *sequence, 202 uint32_t *native_type); 203 extern void i915_poke_flush(drm_device_t *dev, uint32_t class); 204 extern int i915_fence_has_irq(drm_device_t *dev, uint32_t class, uint32_t flags); 205 #endif 206 207 #ifdef I915_HAVE_BUFFER 208 /* i915_buffer.c */ 209 extern drm_ttm_backend_t *i915_create_ttm_backend_entry(drm_device_t *dev); 210 extern int i915_fence_types(drm_buffer_object_t *bo, uint32_t *class, uint32_t *type); 211 extern int i915_invalidate_caches(drm_device_t *dev, uint32_t buffer_flags); 212 extern int i915_init_mem_type(drm_device_t *dev, uint32_t type, 213 drm_mem_type_manager_t *man); 214 extern uint32_t i915_evict_mask(drm_buffer_object_t *bo); 215 extern int i915_move(drm_buffer_object_t *bo, int evict, 216 int no_wait, drm_bo_mem_reg_t *new_mem); 217 218 #endif 219 220 #define I915_READ(reg) DRM_READ32(dev_priv->mmio_map, (reg)) 221 #define I915_WRITE(reg,val) DRM_WRITE32(dev_priv->mmio_map, (reg), (val)) 222 #define I915_READ16(reg) DRM_READ16(dev_priv->mmio_map, (reg)) 223 #define I915_WRITE16(reg,val) DRM_WRITE16(dev_priv->mmio_map, (reg), (val)) 224 225 #define RING_LOCALS unsigned int outring, ringmask, outcount; \ 226 volatile unsigned char *virt; 227 228 #define BEGIN_LP_RING(n) do { \ 229 if (dev_priv->ring.space < (n)*4) \ 230 (void) i915_wait_ring(dev, (n)*4, __FUNCTION__); \ 231 outcount = 0; \ 232 outring = dev_priv->ring.tail; \ 233 ringmask = dev_priv->ring.tail_mask; \ 234 virt = dev_priv->ring.virtual_start; \ 235 } while (*"\0") 236 237 #define OUT_RING(n) do { \ 238 *(volatile unsigned int *)(virt + outring) = (n); \ 239 outcount++; \ 240 outring += 4; \ 241 outring &= ringmask; \ 242 } while (*"\0") 243 244 #define ADVANCE_LP_RING() do { \ 245 dev_priv->ring.tail = outring; \ 246 dev_priv->ring.space -= outcount * 4; \ 247 I915_WRITE(LP_RING + RING_TAIL, outring); \ 248 } while (*"\0") 249 250 extern int i915_wait_ring(drm_device_t * dev, int n, const char *caller); 251 252 #define GFX_OP_USER_INTERRUPT ((0<<29)|(2<<23)) 253 #define GFX_OP_BREAKPOINT_INTERRUPT ((0<<29)|(1<<23)) 254 #define CMD_REPORT_HEAD (7<<23) 255 #define CMD_STORE_DWORD_IDX ((0x21<<23) | 0x1) 256 #define CMD_OP_BATCH_BUFFER ((0x0<<29)|(0x30<<23)|0x1) 257 258 #define INST_PARSER_CLIENT 0x00000000 259 #define INST_OP_FLUSH 0x02000000 260 #define INST_FLUSH_MAP_CACHE 0x00000001 261 262 #define CMD_MI_FLUSH (0x04 << 23) 263 #define MI_NO_WRITE_FLUSH (1 << 2) 264 #define MI_READ_FLUSH (1 << 0) 265 #define MI_EXE_FLUSH (1 << 1) 266 267 #define BB1_START_ADDR_MASK (~0x7) 268 #define BB1_PROTECTED (1<<0) 269 #define BB1_UNPROTECTED (0<<0) 270 #define BB2_END_ADDR_MASK (~0x7) 271 272 #define I915REG_HWSTAM 0x02098 273 #define I915REG_INT_IDENTITY_R 0x020a4 274 #define I915REG_INT_MASK_R 0x020a8 275 #define I915REG_INT_ENABLE_R 0x020a0 276 #define I915REG_INSTPM 0x020c0 277 278 #define I915REG_PIPEASTAT 0x70024 279 #define I915REG_PIPEBSTAT 0x71024 280 281 #define I915_VBLANK_INTERRUPT_ENABLE (1UL<<17) 282 #define I915_VBLANK_CLEAR (1UL<<1) 283 284 #define SRX_INDEX 0x3c4 285 #define SRX_DATA 0x3c5 286 #define SR01 1 287 #define SR01_SCREEN_OFF (1<<5) 288 289 #define PPCR 0x61204 290 #define PPCR_ON (1<<0) 291 292 #define DVOB 0x61140 293 #define DVOB_ON (1<<31) 294 #define DVOC 0x61160 295 #define DVOC_ON (1<<31) 296 #define LVDS 0x61180 297 #define LVDS_ON (1<<31) 298 299 #define ADPA 0x61100 300 #define ADPA_DPMS_MASK (~(3<<10)) 301 #define ADPA_DPMS_ON (0<<10) 302 #define ADPA_DPMS_SUSPEND (1<<10) 303 #define ADPA_DPMS_STANDBY (2<<10) 304 #define ADPA_DPMS_OFF (3<<10) 305 306 #ifdef NOPID 307 #undef NOPID 308 #endif 309 #define NOPID 0x2094 310 #define LP_RING 0x2030 311 #define HP_RING 0x2040 312 #define RING_TAIL 0x00 313 #define TAIL_ADDR 0x001FFFF8 314 #define RING_HEAD 0x04 315 #define HEAD_WRAP_COUNT 0xFFE00000 316 #define HEAD_WRAP_ONE 0x00200000 317 #define HEAD_ADDR 0x001FFFFC 318 #define RING_START 0x08 319 #define START_ADDR 0x0xFFFFF000 320 #define RING_LEN 0x0C 321 #define RING_NR_PAGES 0x001FF000 322 #define RING_REPORT_MASK 0x00000006 323 #define RING_REPORT_64K 0x00000002 324 #define RING_REPORT_128K 0x00000004 325 #define RING_NO_REPORT 0x00000000 326 #define RING_VALID_MASK 0x00000001 327 #define RING_VALID 0x00000001 328 #define RING_INVALID 0x00000000 329 330 #define GFX_OP_SCISSOR ((0x3<<29)|(0x1c<<24)|(0x10<<19)) 331 #define SC_UPDATE_SCISSOR (0x1<<1) 332 #define SC_ENABLE_MASK (0x1<<0) 333 #define SC_ENABLE (0x1<<0) 334 335 #define GFX_OP_SCISSOR_INFO ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1)) 336 #define SCI_YMIN_MASK (0xffff<<16) 337 #define SCI_XMIN_MASK (0xffff<<0) 338 #define SCI_YMAX_MASK (0xffff<<16) 339 #define SCI_XMAX_MASK (0xffff<<0) 340 341 #define GFX_OP_SCISSOR_ENABLE ((0x3<<29)|(0x1c<<24)|(0x10<<19)) 342 #define GFX_OP_SCISSOR_RECT ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1) 343 #define GFX_OP_COLOR_FACTOR ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0) 344 #define GFX_OP_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16)) 345 #define GFX_OP_MAP_INFO ((0x3<<29)|(0x1d<<24)|0x4) 346 #define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0) 347 #define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3)) 348 349 #define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2) 350 351 #define SRC_COPY_BLT_CMD ((2<<29)|(0x43<<22)|4) 352 #define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6) 353 #define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21) 354 #define XY_SRC_COPY_BLT_WRITE_RGB (1<<20) 355 356 #define MI_BATCH_BUFFER ((0x30<<23)|1) 357 #define MI_BATCH_BUFFER_START (0x31<<23) 358 #define MI_BATCH_BUFFER_END (0xA<<23) 359 #define MI_BATCH_NON_SECURE (1) 360 361 #define MI_WAIT_FOR_EVENT ((0x3<<23)) 362 #define MI_WAIT_FOR_PLANE_A_FLIP (1<<2) 363 #define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1) 364 365 #define MI_LOAD_SCAN_LINES_INCL ((0x12<<23)) 366 367 #define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2) 368 #define ASYNC_FLIP (1<<22) 369 370 #define CMD_OP_DESTBUFFER_INFO ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1) 371 372 #define READ_BREADCRUMB(dev_priv) (((volatile u32*)(dev_priv->hw_status_page))[5]) 373 #define READ_HWSP(dev_priv, reg) (((volatile u32*)(dev_priv->hw_status_page))[reg]) 374 375 #endif /* _I915_DRV_H */ 376