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