1 1.1 riastrad /* $NetBSD: i810_drm.h,v 1.2 2021/12/18 23:45:46 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 4 1.1 riastrad #ifndef _I810_DRM_H_ 5 1.1 riastrad #define _I810_DRM_H_ 6 1.1 riastrad 7 1.1 riastrad #include "drm.h" 8 1.1 riastrad 9 1.1 riastrad #if defined(__cplusplus) 10 1.1 riastrad extern "C" { 11 1.1 riastrad #endif 12 1.1 riastrad 13 1.1 riastrad /* WARNING: These defines must be the same as what the Xserver uses. 14 1.1 riastrad * if you change them, you must change the defines in the Xserver. 15 1.1 riastrad */ 16 1.1 riastrad 17 1.1 riastrad #ifndef _I810_DEFINES_ 18 1.1 riastrad #define _I810_DEFINES_ 19 1.1 riastrad 20 1.1 riastrad #define I810_DMA_BUF_ORDER 12 21 1.1 riastrad #define I810_DMA_BUF_SZ (1<<I810_DMA_BUF_ORDER) 22 1.1 riastrad #define I810_DMA_BUF_NR 256 23 1.1 riastrad #define I810_NR_SAREA_CLIPRECTS 8 24 1.1 riastrad 25 1.1 riastrad /* Each region is a minimum of 64k, and there are at most 64 of them. 26 1.1 riastrad */ 27 1.1 riastrad #define I810_NR_TEX_REGIONS 64 28 1.1 riastrad #define I810_LOG_MIN_TEX_REGION_SIZE 16 29 1.1 riastrad #endif 30 1.1 riastrad 31 1.1 riastrad #define I810_UPLOAD_TEX0IMAGE 0x1 /* handled clientside */ 32 1.1 riastrad #define I810_UPLOAD_TEX1IMAGE 0x2 /* handled clientside */ 33 1.1 riastrad #define I810_UPLOAD_CTX 0x4 34 1.1 riastrad #define I810_UPLOAD_BUFFERS 0x8 35 1.1 riastrad #define I810_UPLOAD_TEX0 0x10 36 1.1 riastrad #define I810_UPLOAD_TEX1 0x20 37 1.1 riastrad #define I810_UPLOAD_CLIPRECTS 0x40 38 1.1 riastrad 39 1.1 riastrad /* Indices into buf.Setup where various bits of state are mirrored per 40 1.1 riastrad * context and per buffer. These can be fired at the card as a unit, 41 1.1 riastrad * or in a piecewise fashion as required. 42 1.1 riastrad */ 43 1.1 riastrad 44 1.1 riastrad /* Destbuffer state 45 1.1 riastrad * - backbuffer linear offset and pitch -- invarient in the current dri 46 1.1 riastrad * - zbuffer linear offset and pitch -- also invarient 47 1.1 riastrad * - drawing origin in back and depth buffers. 48 1.1 riastrad * 49 1.1 riastrad * Keep the depth/back buffer state here to accommodate private buffers 50 1.1 riastrad * in the future. 51 1.1 riastrad */ 52 1.1 riastrad #define I810_DESTREG_DI0 0 /* CMD_OP_DESTBUFFER_INFO (2 dwords) */ 53 1.1 riastrad #define I810_DESTREG_DI1 1 54 1.1 riastrad #define I810_DESTREG_DV0 2 /* GFX_OP_DESTBUFFER_VARS (2 dwords) */ 55 1.1 riastrad #define I810_DESTREG_DV1 3 56 1.1 riastrad #define I810_DESTREG_DR0 4 /* GFX_OP_DRAWRECT_INFO (4 dwords) */ 57 1.1 riastrad #define I810_DESTREG_DR1 5 58 1.1 riastrad #define I810_DESTREG_DR2 6 59 1.1 riastrad #define I810_DESTREG_DR3 7 60 1.1 riastrad #define I810_DESTREG_DR4 8 61 1.1 riastrad #define I810_DEST_SETUP_SIZE 10 62 1.1 riastrad 63 1.1 riastrad /* Context state 64 1.1 riastrad */ 65 1.1 riastrad #define I810_CTXREG_CF0 0 /* GFX_OP_COLOR_FACTOR */ 66 1.1 riastrad #define I810_CTXREG_CF1 1 67 1.1 riastrad #define I810_CTXREG_ST0 2 /* GFX_OP_STIPPLE */ 68 1.1 riastrad #define I810_CTXREG_ST1 3 69 1.1 riastrad #define I810_CTXREG_VF 4 /* GFX_OP_VERTEX_FMT */ 70 1.1 riastrad #define I810_CTXREG_MT 5 /* GFX_OP_MAP_TEXELS */ 71 1.1 riastrad #define I810_CTXREG_MC0 6 /* GFX_OP_MAP_COLOR_STAGES - stage 0 */ 72 1.1 riastrad #define I810_CTXREG_MC1 7 /* GFX_OP_MAP_COLOR_STAGES - stage 1 */ 73 1.1 riastrad #define I810_CTXREG_MC2 8 /* GFX_OP_MAP_COLOR_STAGES - stage 2 */ 74 1.1 riastrad #define I810_CTXREG_MA0 9 /* GFX_OP_MAP_ALPHA_STAGES - stage 0 */ 75 1.1 riastrad #define I810_CTXREG_MA1 10 /* GFX_OP_MAP_ALPHA_STAGES - stage 1 */ 76 1.1 riastrad #define I810_CTXREG_MA2 11 /* GFX_OP_MAP_ALPHA_STAGES - stage 2 */ 77 1.1 riastrad #define I810_CTXREG_SDM 12 /* GFX_OP_SRC_DEST_MONO */ 78 1.1 riastrad #define I810_CTXREG_FOG 13 /* GFX_OP_FOG_COLOR */ 79 1.1 riastrad #define I810_CTXREG_B1 14 /* GFX_OP_BOOL_1 */ 80 1.1 riastrad #define I810_CTXREG_B2 15 /* GFX_OP_BOOL_2 */ 81 1.1 riastrad #define I810_CTXREG_LCS 16 /* GFX_OP_LINEWIDTH_CULL_SHADE_MODE */ 82 1.1 riastrad #define I810_CTXREG_PV 17 /* GFX_OP_PV_RULE -- Invarient! */ 83 1.1 riastrad #define I810_CTXREG_ZA 18 /* GFX_OP_ZBIAS_ALPHAFUNC */ 84 1.1 riastrad #define I810_CTXREG_AA 19 /* GFX_OP_ANTIALIAS */ 85 1.1 riastrad #define I810_CTX_SETUP_SIZE 20 86 1.1 riastrad 87 1.1 riastrad /* Texture state (per tex unit) 88 1.1 riastrad */ 89 1.1 riastrad #define I810_TEXREG_MI0 0 /* GFX_OP_MAP_INFO (4 dwords) */ 90 1.1 riastrad #define I810_TEXREG_MI1 1 91 1.1 riastrad #define I810_TEXREG_MI2 2 92 1.1 riastrad #define I810_TEXREG_MI3 3 93 1.1 riastrad #define I810_TEXREG_MF 4 /* GFX_OP_MAP_FILTER */ 94 1.1 riastrad #define I810_TEXREG_MLC 5 /* GFX_OP_MAP_LOD_CTL */ 95 1.1 riastrad #define I810_TEXREG_MLL 6 /* GFX_OP_MAP_LOD_LIMITS */ 96 1.1 riastrad #define I810_TEXREG_MCS 7 /* GFX_OP_MAP_COORD_SETS ??? */ 97 1.1 riastrad #define I810_TEX_SETUP_SIZE 8 98 1.1 riastrad 99 1.1 riastrad /* Flags for clear ioctl 100 1.1 riastrad */ 101 1.1 riastrad #define I810_FRONT 0x1 102 1.1 riastrad #define I810_BACK 0x2 103 1.1 riastrad #define I810_DEPTH 0x4 104 1.1 riastrad 105 1.1 riastrad typedef enum _drm_i810_init_func { 106 1.1 riastrad I810_INIT_DMA = 0x01, 107 1.1 riastrad I810_CLEANUP_DMA = 0x02, 108 1.1 riastrad I810_INIT_DMA_1_4 = 0x03 109 1.1 riastrad } drm_i810_init_func_t; 110 1.1 riastrad 111 1.1 riastrad /* This is the init structure after v1.2 */ 112 1.1 riastrad typedef struct _drm_i810_init { 113 1.1 riastrad drm_i810_init_func_t func; 114 1.1 riastrad unsigned int mmio_offset; 115 1.1 riastrad unsigned int buffers_offset; 116 1.1 riastrad int sarea_priv_offset; 117 1.1 riastrad unsigned int ring_start; 118 1.1 riastrad unsigned int ring_end; 119 1.1 riastrad unsigned int ring_size; 120 1.1 riastrad unsigned int front_offset; 121 1.1 riastrad unsigned int back_offset; 122 1.1 riastrad unsigned int depth_offset; 123 1.1 riastrad unsigned int overlay_offset; 124 1.1 riastrad unsigned int overlay_physical; 125 1.1 riastrad unsigned int w; 126 1.1 riastrad unsigned int h; 127 1.1 riastrad unsigned int pitch; 128 1.1 riastrad unsigned int pitch_bits; 129 1.1 riastrad } drm_i810_init_t; 130 1.1 riastrad 131 1.1 riastrad /* This is the init structure prior to v1.2 */ 132 1.1 riastrad typedef struct _drm_i810_pre12_init { 133 1.1 riastrad drm_i810_init_func_t func; 134 1.1 riastrad unsigned int mmio_offset; 135 1.1 riastrad unsigned int buffers_offset; 136 1.1 riastrad int sarea_priv_offset; 137 1.1 riastrad unsigned int ring_start; 138 1.1 riastrad unsigned int ring_end; 139 1.1 riastrad unsigned int ring_size; 140 1.1 riastrad unsigned int front_offset; 141 1.1 riastrad unsigned int back_offset; 142 1.1 riastrad unsigned int depth_offset; 143 1.1 riastrad unsigned int w; 144 1.1 riastrad unsigned int h; 145 1.1 riastrad unsigned int pitch; 146 1.1 riastrad unsigned int pitch_bits; 147 1.1 riastrad } drm_i810_pre12_init_t; 148 1.1 riastrad 149 1.1 riastrad /* Warning: If you change the SAREA structure you must change the Xserver 150 1.1 riastrad * structure as well */ 151 1.1 riastrad 152 1.1 riastrad typedef struct _drm_i810_tex_region { 153 1.1 riastrad unsigned char next, prev; /* indices to form a circular LRU */ 154 1.1 riastrad unsigned char in_use; /* owned by a client, or free? */ 155 1.1 riastrad int age; /* tracked by clients to update local LRU's */ 156 1.1 riastrad } drm_i810_tex_region_t; 157 1.1 riastrad 158 1.1 riastrad typedef struct _drm_i810_sarea { 159 1.1 riastrad unsigned int ContextState[I810_CTX_SETUP_SIZE]; 160 1.1 riastrad unsigned int BufferState[I810_DEST_SETUP_SIZE]; 161 1.1 riastrad unsigned int TexState[2][I810_TEX_SETUP_SIZE]; 162 1.1 riastrad unsigned int dirty; 163 1.1 riastrad 164 1.1 riastrad unsigned int nbox; 165 1.1 riastrad struct drm_clip_rect boxes[I810_NR_SAREA_CLIPRECTS]; 166 1.1 riastrad 167 1.1 riastrad /* Maintain an LRU of contiguous regions of texture space. If 168 1.1 riastrad * you think you own a region of texture memory, and it has an 169 1.1 riastrad * age different to the one you set, then you are mistaken and 170 1.1 riastrad * it has been stolen by another client. If global texAge 171 1.1 riastrad * hasn't changed, there is no need to walk the list. 172 1.1 riastrad * 173 1.1 riastrad * These regions can be used as a proxy for the fine-grained 174 1.1 riastrad * texture information of other clients - by maintaining them 175 1.1 riastrad * in the same lru which is used to age their own textures, 176 1.1 riastrad * clients have an approximate lru for the whole of global 177 1.1 riastrad * texture space, and can make informed decisions as to which 178 1.1 riastrad * areas to kick out. There is no need to choose whether to 179 1.1 riastrad * kick out your own texture or someone else's - simply eject 180 1.1 riastrad * them all in LRU order. 181 1.1 riastrad */ 182 1.1 riastrad 183 1.1 riastrad drm_i810_tex_region_t texList[I810_NR_TEX_REGIONS + 1]; 184 1.1 riastrad /* Last elt is sentinal */ 185 1.1 riastrad int texAge; /* last time texture was uploaded */ 186 1.1 riastrad int last_enqueue; /* last time a buffer was enqueued */ 187 1.1 riastrad int last_dispatch; /* age of the most recently dispatched buffer */ 188 1.1 riastrad int last_quiescent; /* */ 189 1.1 riastrad int ctxOwner; /* last context to upload state */ 190 1.1 riastrad 191 1.1 riastrad int vertex_prim; 192 1.1 riastrad 193 1.1 riastrad int pf_enabled; /* is pageflipping allowed? */ 194 1.1 riastrad int pf_active; 195 1.1 riastrad int pf_current_page; /* which buffer is being displayed? */ 196 1.1 riastrad } drm_i810_sarea_t; 197 1.1 riastrad 198 1.1 riastrad /* WARNING: If you change any of these defines, make sure to change the 199 1.1 riastrad * defines in the Xserver file (xf86drmMga.h) 200 1.1 riastrad */ 201 1.1 riastrad 202 1.1 riastrad /* i810 specific ioctls 203 1.1 riastrad * The device specific ioctl range is 0x40 to 0x79. 204 1.1 riastrad */ 205 1.1 riastrad #define DRM_I810_INIT 0x00 206 1.1 riastrad #define DRM_I810_VERTEX 0x01 207 1.1 riastrad #define DRM_I810_CLEAR 0x02 208 1.1 riastrad #define DRM_I810_FLUSH 0x03 209 1.1 riastrad #define DRM_I810_GETAGE 0x04 210 1.1 riastrad #define DRM_I810_GETBUF 0x05 211 1.1 riastrad #define DRM_I810_SWAP 0x06 212 1.1 riastrad #define DRM_I810_COPY 0x07 213 1.1 riastrad #define DRM_I810_DOCOPY 0x08 214 1.1 riastrad #define DRM_I810_OV0INFO 0x09 215 1.1 riastrad #define DRM_I810_FSTATUS 0x0a 216 1.1 riastrad #define DRM_I810_OV0FLIP 0x0b 217 1.1 riastrad #define DRM_I810_MC 0x0c 218 1.1 riastrad #define DRM_I810_RSTATUS 0x0d 219 1.1 riastrad #define DRM_I810_FLIP 0x0e 220 1.1 riastrad 221 1.1 riastrad #define DRM_IOCTL_I810_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I810_INIT, drm_i810_init_t) 222 1.1 riastrad #define DRM_IOCTL_I810_VERTEX DRM_IOW( DRM_COMMAND_BASE + DRM_I810_VERTEX, drm_i810_vertex_t) 223 1.1 riastrad #define DRM_IOCTL_I810_CLEAR DRM_IOW( DRM_COMMAND_BASE + DRM_I810_CLEAR, drm_i810_clear_t) 224 1.1 riastrad #define DRM_IOCTL_I810_FLUSH DRM_IO( DRM_COMMAND_BASE + DRM_I810_FLUSH) 225 1.1 riastrad #define DRM_IOCTL_I810_GETAGE DRM_IO( DRM_COMMAND_BASE + DRM_I810_GETAGE) 226 1.1 riastrad #define DRM_IOCTL_I810_GETBUF DRM_IOWR(DRM_COMMAND_BASE + DRM_I810_GETBUF, drm_i810_dma_t) 227 1.1 riastrad #define DRM_IOCTL_I810_SWAP DRM_IO( DRM_COMMAND_BASE + DRM_I810_SWAP) 228 1.1 riastrad #define DRM_IOCTL_I810_COPY DRM_IOW( DRM_COMMAND_BASE + DRM_I810_COPY, drm_i810_copy_t) 229 1.1 riastrad #define DRM_IOCTL_I810_DOCOPY DRM_IO( DRM_COMMAND_BASE + DRM_I810_DOCOPY) 230 1.1 riastrad #define DRM_IOCTL_I810_OV0INFO DRM_IOR( DRM_COMMAND_BASE + DRM_I810_OV0INFO, drm_i810_overlay_t) 231 1.1 riastrad #define DRM_IOCTL_I810_FSTATUS DRM_IO ( DRM_COMMAND_BASE + DRM_I810_FSTATUS) 232 1.1 riastrad #define DRM_IOCTL_I810_OV0FLIP DRM_IO ( DRM_COMMAND_BASE + DRM_I810_OV0FLIP) 233 1.1 riastrad #define DRM_IOCTL_I810_MC DRM_IOW( DRM_COMMAND_BASE + DRM_I810_MC, drm_i810_mc_t) 234 1.1 riastrad #define DRM_IOCTL_I810_RSTATUS DRM_IO ( DRM_COMMAND_BASE + DRM_I810_RSTATUS) 235 1.1 riastrad #define DRM_IOCTL_I810_FLIP DRM_IO ( DRM_COMMAND_BASE + DRM_I810_FLIP) 236 1.1 riastrad 237 1.1 riastrad typedef struct _drm_i810_clear { 238 1.1 riastrad int clear_color; 239 1.1 riastrad int clear_depth; 240 1.1 riastrad int flags; 241 1.1 riastrad } drm_i810_clear_t; 242 1.1 riastrad 243 1.1 riastrad /* These may be placeholders if we have more cliprects than 244 1.1 riastrad * I810_NR_SAREA_CLIPRECTS. In that case, the client sets discard to 245 1.1 riastrad * false, indicating that the buffer will be dispatched again with a 246 1.1 riastrad * new set of cliprects. 247 1.1 riastrad */ 248 1.1 riastrad typedef struct _drm_i810_vertex { 249 1.1 riastrad int idx; /* buffer index */ 250 1.1 riastrad int used; /* nr bytes in use */ 251 1.1 riastrad int discard; /* client is finished with the buffer? */ 252 1.1 riastrad } drm_i810_vertex_t; 253 1.1 riastrad 254 1.1 riastrad typedef struct _drm_i810_copy_t { 255 1.1 riastrad int idx; /* buffer index */ 256 1.1 riastrad int used; /* nr bytes in use */ 257 1.1 riastrad void *address; /* Address to copy from */ 258 1.1 riastrad } drm_i810_copy_t; 259 1.1 riastrad 260 1.1 riastrad #define PR_TRIANGLES (0x0<<18) 261 1.1 riastrad #define PR_TRISTRIP_0 (0x1<<18) 262 1.1 riastrad #define PR_TRISTRIP_1 (0x2<<18) 263 1.1 riastrad #define PR_TRIFAN (0x3<<18) 264 1.1 riastrad #define PR_POLYGON (0x4<<18) 265 1.1 riastrad #define PR_LINES (0x5<<18) 266 1.1 riastrad #define PR_LINESTRIP (0x6<<18) 267 1.1 riastrad #define PR_RECTS (0x7<<18) 268 1.1 riastrad #define PR_MASK (0x7<<18) 269 1.1 riastrad 270 1.1 riastrad typedef struct drm_i810_dma { 271 1.1 riastrad void *virtual; 272 1.1 riastrad int request_idx; 273 1.1 riastrad int request_size; 274 1.1 riastrad int granted; 275 1.1 riastrad } drm_i810_dma_t; 276 1.1 riastrad 277 1.1 riastrad typedef struct _drm_i810_overlay_t { 278 1.1 riastrad unsigned int offset; /* Address of the Overlay Regs */ 279 1.1 riastrad unsigned int physical; 280 1.1 riastrad } drm_i810_overlay_t; 281 1.1 riastrad 282 1.1 riastrad typedef struct _drm_i810_mc { 283 1.1 riastrad int idx; /* buffer index */ 284 1.1 riastrad int used; /* nr bytes in use */ 285 1.1 riastrad int num_blocks; /* number of GFXBlocks */ 286 1.1 riastrad int *length; /* List of lengths for GFXBlocks (FUTURE) */ 287 1.1 riastrad unsigned int last_render; /* Last Render Request */ 288 1.1 riastrad } drm_i810_mc_t; 289 1.1 riastrad 290 1.1 riastrad #if defined(__cplusplus) 291 1.1 riastrad } 292 1.1 riastrad #endif 293 1.1 riastrad 294 1.1 riastrad #endif /* _I810_DRM_H_ */ 295