1/* i810_common.h -- common header definitions for I810 2D/3D/DRM suite 2 * 3 * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 * DEALINGS IN THE SOFTWARE. 24 * 25 * Converted to common header format: 26 * Jens Owen <jens@tungstengraphics.com> 27 * 28 * 29 */ 30 31/* WARNING: If you change any of these defines, make sure to change 32 * the kernel include file as well (i810_drm.h) 33 */ 34 35#ifndef _I810_COMMON_H_ 36#define _I810_COMMON_H_ 37 38/* Provide substitutes for gcc's __FUNCTION__ on other compilers */ 39#if !defined(__GNUC__) && !defined(__FUNCTION__) 40# if defined(__STDC__) && (__STDC_VERSION__>=199901L) /* C99 */ 41# define __FUNCTION__ __func__ 42# else 43# define __FUNCTION__ "" 44# endif 45#endif 46 47#define PFX __FILE__,__LINE__,__FUNCTION__ 48#define FUNCTION_NAME __FUNCTION__ 49 50#define KB(x) ((x) * 1024) 51#define MB(x) ((x) * KB(1024)) 52 53#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1)) 54 55/* Using usleep() makes things noticably slow. */ 56#if 0 57#define DELAY(x) usleep(x) 58#else 59#define DELAY(x) do {;} while (0) 60#endif 61 62#define PrintErrorState I810PrintErrorState 63#define WaitRingFunc I810WaitLpRing 64#define RecPtr pI810 65 66static inline void memset_volatile(volatile void *b, int c, size_t len) 67{ 68 unsigned i; 69 70 for (i = 0; i < len; i++) 71 ((volatile char *)b)[i] = c; 72} 73 74static inline void memcpy_volatile(volatile void *dst, const void *src, 75 size_t len) 76{ 77 unsigned i; 78 79 for (i = 0; i < len; i++) 80 ((volatile char *)dst)[i] = ((const volatile char *)src)[i]; 81} 82 83/* Memory mapped register access macros */ 84#define INREG8(addr) *(volatile uint8_t *)(RecPtr->MMIOBase + (addr)) 85#define INREG16(addr) *(volatile uint16_t *)(RecPtr->MMIOBase + (addr)) 86#define INREG(addr) *(volatile uint32_t *)(RecPtr->MMIOBase + (addr)) 87#define INGTT(addr) *(volatile uint32_t *)(RecPtr->GTTBase + (addr)) 88#define POSTING_READ(addr) (void)INREG(addr) 89 90#define OUTREG8(addr, val) do { \ 91 *(volatile uint8_t *)(RecPtr->MMIOBase + (addr)) = (val); \ 92 if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) { \ 93 ErrorF("OUTREG8(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr), \ 94 (unsigned long)(val), FUNCTION_NAME); \ 95 } \ 96} while (0) 97 98#define OUTREG16(addr, val) do { \ 99 *(volatile uint16_t *)(RecPtr->MMIOBase + (addr)) = (val); \ 100 if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) { \ 101 ErrorF("OUTREG16(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr), \ 102 (unsigned long)(val), FUNCTION_NAME); \ 103 } \ 104} while (0) 105 106#define OUTREG(addr, val) do { \ 107 *(volatile uint32_t *)(RecPtr->MMIOBase + (addr)) = (val); \ 108 if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) { \ 109 ErrorF("OUTREG(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr), \ 110 (unsigned long)(val), FUNCTION_NAME); \ 111 } \ 112} while (0) 113 114/* To remove all debugging, make sure I810_DEBUG is defined as a 115 * preprocessor symbol, and equal to zero. 116 */ 117#if 1 118#define I810_DEBUG 0 119#endif 120#ifndef I810_DEBUG 121#warning "Debugging enabled - expect reduced performance" 122extern int I810_DEBUG; 123#endif 124 125#define DEBUG_VERBOSE_ACCEL 0x1 126#define DEBUG_VERBOSE_SYNC 0x2 127#define DEBUG_VERBOSE_VGA 0x4 128#define DEBUG_VERBOSE_RING 0x8 129#define DEBUG_VERBOSE_OUTREG 0x10 130#define DEBUG_VERBOSE_MEMORY 0x20 131#define DEBUG_VERBOSE_CURSOR 0x40 132#define DEBUG_ALWAYS_SYNC 0x80 133#define DEBUG_VERBOSE_DRI 0x100 134#define DEBUG_VERBOSE_BIOS 0x200 135 136/* Size of the mmio region. 137 */ 138#define I810_REG_SIZE 0x80000 139 140#define GTT_PAGE_SIZE KB(4) 141#define PRIMARY_RINGBUFFER_SIZE KB(128) 142#define MIN_SCRATCH_BUFFER_SIZE KB(16) 143#define MAX_SCRATCH_BUFFER_SIZE KB(64) 144#define HWCURSOR_SIZE GTT_PAGE_SIZE 145#define HWCURSOR_SIZE_ARGB GTT_PAGE_SIZE * 4 146 147/* Use a 64x64 HW cursor */ 148#define I810_CURSOR_X 64 149#define I810_CURSOR_Y I810_CURSOR_X 150 151#define PIPE_NAME(n) ('A' + (n)) 152 153extern struct pci_device * 154intel_host_bridge (void); 155 156/** 157 * Hints to CreatePixmap to tell the driver how the pixmap is going to be 158 * used. 159 * 160 * Compare to CREATE_PIXMAP_USAGE_* in the server. 161 */ 162enum { 163 INTEL_CREATE_PIXMAP_TILING_X = 0x10000000, 164 INTEL_CREATE_PIXMAP_TILING_Y, 165 INTEL_CREATE_PIXMAP_TILING_NONE, 166}; 167 168#ifndef _I810_DEFINES_ 169#define _I810_DEFINES_ 170#define I810_USE_BATCH 1 171 172#define I810_DMA_BUF_ORDER 12 173#define I810_DMA_BUF_SZ (1<<I810_DMA_BUF_ORDER) 174#define I810_DMA_BUF_NR 256 175 176#define I810_NR_SAREA_CLIPRECTS 8 177 178/* Each region is a minimum of 64k, and there are at most 64 of them. 179 */ 180#define I810_NR_TEX_REGIONS 64 181#define I810_LOG_MIN_TEX_REGION_SIZE 16 182 183/* Destbuffer state 184 * - backbuffer linear offset and pitch -- invarient in the current dri 185 * - zbuffer linear offset and pitch -- also invarient 186 * - drawing origin in back and depth buffers. 187 * 188 * Keep the depth/back buffer state here to acommodate private buffers 189 * in the future. 190 */ 191#define I810_DESTREG_DI0 0 /* CMD_OP_DESTBUFFER_INFO (2 dwords) */ 192#define I810_DESTREG_DI1 1 193#define I810_DESTREG_DV0 2 /* GFX_OP_DESTBUFFER_VARS (2 dwords) */ 194#define I810_DESTREG_DV1 3 195#define I810_DESTREG_DR0 4 /* GFX_OP_DRAWRECT_INFO (4 dwords) */ 196#define I810_DESTREG_DR1 5 197#define I810_DESTREG_DR2 6 198#define I810_DESTREG_DR3 7 199#define I810_DESTREG_DR4 8 200#define I810_DEST_SETUP_SIZE 10 201 202/* Context state 203 */ 204#define I810_CTXREG_CF0 0 /* GFX_OP_COLOR_FACTOR */ 205#define I810_CTXREG_CF1 1 206#define I810_CTXREG_ST0 2 /* GFX_OP_STIPPLE */ 207#define I810_CTXREG_ST1 3 208#define I810_CTXREG_VF 4 /* GFX_OP_VERTEX_FMT */ 209#define I810_CTXREG_MT 5 /* GFX_OP_MAP_TEXELS */ 210#define I810_CTXREG_MC0 6 /* GFX_OP_MAP_COLOR_STAGES - stage 0 */ 211#define I810_CTXREG_MC1 7 /* GFX_OP_MAP_COLOR_STAGES - stage 1 */ 212#define I810_CTXREG_MC2 8 /* GFX_OP_MAP_COLOR_STAGES - stage 2 */ 213#define I810_CTXREG_MA0 9 /* GFX_OP_MAP_ALPHA_STAGES - stage 0 */ 214#define I810_CTXREG_MA1 10 /* GFX_OP_MAP_ALPHA_STAGES - stage 1 */ 215#define I810_CTXREG_MA2 11 /* GFX_OP_MAP_ALPHA_STAGES - stage 2 */ 216#define I810_CTXREG_SDM 12 /* GFX_OP_SRC_DEST_MONO */ 217#define I810_CTXREG_FOG 13 /* GFX_OP_FOG_COLOR */ 218#define I810_CTXREG_B1 14 /* GFX_OP_BOOL_1 */ 219#define I810_CTXREG_B2 15 /* GFX_OP_BOOL_2 */ 220#define I810_CTXREG_LCS 16 /* GFX_OP_LINEWIDTH_CULL_SHADE_MODE */ 221#define I810_CTXREG_PV 17 /* GFX_OP_PV_RULE -- Invarient! */ 222#define I810_CTXREG_ZA 18 /* GFX_OP_ZBIAS_ALPHAFUNC */ 223#define I810_CTXREG_AA 19 /* GFX_OP_ANTIALIAS */ 224#define I810_CTX_SETUP_SIZE 20 225 226/* Texture state (per tex unit) 227 */ 228#define I810_TEXREG_MI0 0 /* GFX_OP_MAP_INFO (4 dwords) */ 229#define I810_TEXREG_MI1 1 230#define I810_TEXREG_MI2 2 231#define I810_TEXREG_MI3 3 232#define I810_TEXREG_MF 4 /* GFX_OP_MAP_FILTER */ 233#define I810_TEXREG_MLC 5 /* GFX_OP_MAP_LOD_CTL */ 234#define I810_TEXREG_MLL 6 /* GFX_OP_MAP_LOD_LIMITS */ 235#define I810_TEXREG_MCS 7 /* GFX_OP_MAP_COORD_SETS ??? */ 236#define I810_TEX_SETUP_SIZE 8 237 238/* Driver specific DRM command indices 239 * NOTE: these are not OS specific, but they are driver specific 240 */ 241#define DRM_I810_INIT 0x00 242#define DRM_I810_VERTEX 0x01 243#define DRM_I810_CLEAR 0x02 244#define DRM_I810_FLUSH 0x03 245#define DRM_I810_GETAGE 0x04 246#define DRM_I810_GETBUF 0x05 247#define DRM_I810_SWAP 0x06 248#define DRM_I810_COPY 0x07 249#define DRM_I810_DOCOPY 0x08 250#define DRM_I810_OV0INFO 0x09 251#define DRM_I810_FSTATUS 0x0a 252#define DRM_I810_OV0FLIP 0x0b 253#define DRM_I810_MC 0x0c 254#define DRM_I810_RSTATUS 0x0d 255#define DRM_I810_FLIP 0x0e 256 257#endif 258 259typedef enum _drmI810Initfunc { 260 I810_INIT_DMA = 0x01, 261 I810_CLEANUP_DMA = 0x02, 262 I810_INIT_DMA_1_4 = 0x03 263} drmI810Initfunc; 264 265typedef struct { 266 drmI810Initfunc func; 267 unsigned int mmio_offset; 268 unsigned int buffers_offset; 269 int sarea_priv_offset; 270 unsigned int ring_start; 271 unsigned int ring_end; 272 unsigned int ring_size; 273 unsigned int front_offset; 274 unsigned int back_offset; 275 unsigned int depth_offset; 276 unsigned int overlay_offset; 277 unsigned int overlay_physical; 278 unsigned int w; 279 unsigned int h; 280 unsigned int pitch; 281 unsigned int pitch_bits; 282} drmI810Init; 283 284typedef struct { 285 void *virtual; 286 int request_idx; 287 int request_size; 288 int granted; 289} drmI810DMA; 290 291/* Flags for clear ioctl 292 */ 293#define I810_FRONT 0x1 294#define I810_BACK 0x2 295#define I810_DEPTH 0x4 296 297typedef struct { 298 int clear_color; 299 int clear_depth; 300 int flags; 301} drmI810Clear; 302 303typedef struct { 304 int idx; /* buffer index */ 305 int used; /* nr bytes in use */ 306 int discard; /* client is finished with the buffer? */ 307} drmI810Vertex; 308 309/* Flags for vertex ioctl 310 */ 311#define PR_TRIANGLES (0x0<<18) 312#define PR_TRISTRIP_0 (0x1<<18) 313#define PR_TRISTRIP_1 (0x2<<18) 314#define PR_TRIFAN (0x3<<18) 315#define PR_POLYGON (0x4<<18) 316#define PR_LINES (0x5<<18) 317#define PR_LINESTRIP (0x6<<18) 318#define PR_RECTS (0x7<<18) 319#define PR_MASK (0x7<<18) 320 321#endif 322