1 /* savage_drv.h -- Private header for the savage driver
3 * Copyright 2004 Felix Kuehling
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, sub license,
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef __SAVAGE_DRV_H__
27 #define __SAVAGE_DRV_H__
29 #define DRIVER_AUTHOR "Felix Kuehling"
31 #define DRIVER_NAME "savage"
32 #define DRIVER_DESC "Savage3D/MX/IX, Savage4, SuperSavage, Twister, ProSavage[DDR]"
33 #define DRIVER_DATE "20050110"
35 #define DRIVER_MAJOR 2
36 #define DRIVER_MINOR 1
37 #define DRIVER_PATCHLEVEL 2
40 * 1.x The DRM driver from the VIA/S3 code drop, basically a dummy
41 * 2.0 The first real DRM
42 * 2.1 Scissors registers managed by the DRM, 3D operations clipped by
43 * cliprects of the cmdbuf ioctl
46 typedef struct drm_savage_age {
51 typedef struct drm_savage_buf_priv {
52 struct drm_savage_buf_priv *next;
53 struct drm_savage_buf_priv *prev;
56 } drm_savage_buf_priv_t;
58 /* interesting bits of hardware state that are saved in dev_priv */
60 struct drm_savage_common_state {
64 unsigned char pad[sizeof(struct drm_savage_common_state)];
65 uint32_t texctrl, texaddr;
66 uint32_t scstart, new_scstart;
67 uint32_t scend, new_scend;
70 unsigned char pad[sizeof(struct drm_savage_common_state)];
71 uint32_t texdescr, texaddr0, texaddr1;
72 uint32_t drawctrl0, new_drawctrl0;
73 uint32_t drawctrl1, new_drawctrl1;
77 /* these chip tags should match the ones in the 2D driver in savage_regs.h. */
91 #define S3_SAVAGE3D_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
93 #define S3_SAVAGE4_SERIES(chip) ((chip==S3_SAVAGE4) \
94 || (chip==S3_PROSAVAGE) \
95 || (chip==S3_TWISTER) \
96 || (chip==S3_PROSAVAGEDDR))
98 #define S3_SAVAGE_MOBILE_SERIES(chip) ((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
100 #define S3_SAVAGE_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
102 #define S3_MOBILE_TWISTER_SERIES(chip) ((chip==S3_TWISTER) \
103 ||(chip==S3_PROSAVAGEDDR))
106 #define SAVAGE_IS_AGP 1
108 typedef struct drm_savage_private {
109 drm_savage_sarea_t *sarea_priv;
111 drm_savage_buf_priv_t head, tail;
114 enum savage_family chipset;
116 unsigned int cob_size;
117 unsigned int bci_threshold_lo, bci_threshold_hi;
118 unsigned int dma_type;
120 /* frame buffer layout */
122 unsigned int front_offset, front_pitch;
123 unsigned int back_offset, back_pitch;
124 unsigned int depth_bpp;
125 unsigned int depth_offset, depth_pitch;
127 /* bitmap descriptors for swap and clear */
128 unsigned int front_bd, back_bd, depth_bd;
131 unsigned int texture_offset;
132 unsigned int texture_size;
134 /* memory regions in physical memory */
135 drm_local_map_t *sarea;
136 drm_local_map_t *mmio;
138 drm_local_map_t *aperture;
139 drm_local_map_t *status;
140 drm_local_map_t *agp_textures;
141 drm_local_map_t *cmd_dma;
145 unsigned long base, size;
148 /* BCI and status-related stuff */
149 volatile uint32_t *status_ptr, *bci_ptr;
150 uint32_t status_used_mask;
151 uint16_t event_counter;
152 unsigned int event_wrap;
154 /* saved hw state for global/local check on S3D */
155 uint32_t hw_draw_ctrl, hw_zbuf_ctrl;
156 /* and for scissors (global, so don't emit if not changed) */
157 uint32_t hw_scissors_start, hw_scissors_end;
159 drm_savage_state_t state;
161 /* after emitting a wait cmd Savage3D needs 63 nops before next DMA */
162 unsigned int waiting;
164 /* config/hardware-dependent function pointers */
165 int (*wait_fifo)(struct drm_savage_private *dev_priv, unsigned int n);
166 int (*wait_evnt)(struct drm_savage_private *dev_priv, uint16_t e);
167 /* Err, there is a macro wait_event in include/linux/wait.h.
168 * Avoid unwanted macro expansion. */
169 void (*emit_clip_rect)(struct drm_savage_private *dev_priv,
170 drm_clip_rect_t *pbox);
171 } drm_savage_private_t;
174 extern int savage_bci_init(DRM_IOCTL_ARGS);
175 extern int savage_bci_cmdbuf(DRM_IOCTL_ARGS);
176 extern int savage_bci_event_emit(DRM_IOCTL_ARGS);
177 extern int savage_bci_event_wait(DRM_IOCTL_ARGS);
178 extern int savage_bci_buffers(DRM_IOCTL_ARGS);
181 extern uint16_t savage_bci_emit_event(drm_savage_private_t *dev_priv,
183 extern void savage_freelist_put(drm_device_t *dev, drm_buf_t *buf);
184 extern int savage_preinit(drm_device_t *dev, unsigned long chipset);
185 extern int savage_postcleanup(drm_device_t *dev);
186 extern int savage_do_cleanup_bci(drm_device_t *dev);
187 extern void savage_reclaim_buffers(drm_device_t *dev, DRMFILE filp);
189 /* state functions */
190 extern void savage_emit_clip_rect_s3d(drm_savage_private_t *dev_priv,
191 drm_clip_rect_t *pbox);
192 extern void savage_emit_clip_rect_s4(drm_savage_private_t *dev_priv,
193 drm_clip_rect_t *pbox);
195 #define SAVAGE_FB_SIZE_S3 0x01000000 /* 16MB */
196 #define SAVAGE_FB_SIZE_S4 0x02000000 /* 32MB */
197 #define SAVAGE_MMIO_SIZE 0x00080000 /* 512kB */
198 #define SAVAGE_APERTURE_OFFSET 0x02000000 /* 32MB */
199 #define SAVAGE_APERTURE_SIZE 0x05000000 /* 5 tiled surfaces, 16MB each */
201 #define SAVAGE_BCI_OFFSET 0x00010000 /* offset of the BCI region
202 * inside the MMIO region */
203 #define SAVAGE_BCI_FIFO_SIZE 32 /* number of entries in on-chip
209 #define SAVAGE_STATUS_WORD0 0x48C00
210 #define SAVAGE_STATUS_WORD1 0x48C04
211 #define SAVAGE_ALT_STATUS_WORD0 0x48C60
213 #define SAVAGE_FIFO_USED_MASK_S3D 0x0001ffff
214 #define SAVAGE_FIFO_USED_MASK_S4 0x001fffff
216 /* Copied from savage_bci.h in the 2D driver with some renaming. */
218 /* Bitmap descriptors */
219 #define SAVAGE_BD_STRIDE_SHIFT 0
220 #define SAVAGE_BD_BPP_SHIFT 16
221 #define SAVAGE_BD_TILE_SHIFT 24
222 #define SAVAGE_BD_BW_DISABLE (1<<28)
224 #define SAVAGE_BD_TILE_LINEAR 0
225 /* savage4, MX, IX, 3D */
226 #define SAVAGE_BD_TILE_16BPP 2
227 #define SAVAGE_BD_TILE_32BPP 3
228 /* twister, prosavage, DDR, supersavage, 2000 */
229 #define SAVAGE_BD_TILE_DEST 1
230 #define SAVAGE_BD_TILE_TEXTURE 2
231 /* GBD - BCI enable */
232 /* savage4, MX, IX, 3D */
233 #define SAVAGE_GBD_BCI_ENABLE 8
234 /* twister, prosavage, DDR, supersavage, 2000 */
235 #define SAVAGE_GBD_BCI_ENABLE_TWISTER 0
237 #define SAVAGE_GBD_BIG_ENDIAN 4
238 #define SAVAGE_GBD_LITTLE_ENDIAN 0
239 #define SAVAGE_GBD_64 1
241 /* Global Bitmap Descriptor */
242 #define SAVAGE_BCI_GLB_BD_LOW 0x8168
243 #define SAVAGE_BCI_GLB_BD_HIGH 0x816C
248 /* Savage4/Twister/ProSavage 3D registers */
249 #define SAVAGE_DRAWLOCALCTRL_S4 0x1e
250 #define SAVAGE_TEXPALADDR_S4 0x1f
251 #define SAVAGE_TEXCTRL0_S4 0x20
252 #define SAVAGE_TEXCTRL1_S4 0x21
253 #define SAVAGE_TEXADDR0_S4 0x22
254 #define SAVAGE_TEXADDR1_S4 0x23
255 #define SAVAGE_TEXBLEND0_S4 0x24
256 #define SAVAGE_TEXBLEND1_S4 0x25
257 #define SAVAGE_TEXXPRCLR_S4 0x26 /* never used */
258 #define SAVAGE_TEXDESCR_S4 0x27
259 #define SAVAGE_FOGTABLE_S4 0x28
260 #define SAVAGE_FOGCTRL_S4 0x30
261 #define SAVAGE_STENCILCTRL_S4 0x31
262 #define SAVAGE_ZBUFCTRL_S4 0x32
263 #define SAVAGE_ZBUFOFF_S4 0x33
264 #define SAVAGE_DESTCTRL_S4 0x34
265 #define SAVAGE_DRAWCTRL0_S4 0x35
266 #define SAVAGE_DRAWCTRL1_S4 0x36
267 #define SAVAGE_ZWATERMARK_S4 0x37
268 #define SAVAGE_DESTTEXRWWATERMARK_S4 0x38
269 #define SAVAGE_TEXBLENDCOLOR_S4 0x39
270 /* Savage3D/MX/IX 3D registers */
271 #define SAVAGE_TEXPALADDR_S3D 0x18
272 #define SAVAGE_TEXXPRCLR_S3D 0x19 /* never used */
273 #define SAVAGE_TEXADDR_S3D 0x1A
274 #define SAVAGE_TEXDESCR_S3D 0x1B
275 #define SAVAGE_TEXCTRL_S3D 0x1C
276 #define SAVAGE_FOGTABLE_S3D 0x20
277 #define SAVAGE_FOGCTRL_S3D 0x30
278 #define SAVAGE_DRAWCTRL_S3D 0x31
279 #define SAVAGE_ZBUFCTRL_S3D 0x32
280 #define SAVAGE_ZBUFOFF_S3D 0x33
281 #define SAVAGE_DESTCTRL_S3D 0x34
282 #define SAVAGE_SCSTART_S3D 0x35
283 #define SAVAGE_SCEND_S3D 0x36
284 #define SAVAGE_ZWATERMARK_S3D 0x37
285 #define SAVAGE_DESTTEXRWWATERMARK_S3D 0x38
287 #define SAVAGE_VERTBUFADDR 0x3e
288 #define SAVAGE_BITPLANEWTMASK 0xd7
290 /* texture enable bits (needed for tex addr checking) */
291 #define SAVAGE_TEXCTRL_TEXEN_MASK 0x00010000 /* S3D */
292 #define SAVAGE_TEXDESCR_TEX0EN_MASK 0x02000000 /* S4 */
293 #define SAVAGE_TEXDESCR_TEX1EN_MASK 0x04000000 /* S4 */
295 /* Global fields in Savage4/Twister/ProSavage 3D registers:
297 * All texture registers and DrawLocalCtrl are local. All other
298 * registers are global. */
300 /* Global fields in Savage3D/MX/IX 3D registers:
302 * All texture registers are local. DrawCtrl and ZBufCtrl are
303 * partially local. All other registers are global.
305 * DrawCtrl global fields: cullMode, alphaTestCmpFunc, alphaTestEn, alphaRefVal
306 * ZBufCtrl global fields: zCmpFunc, zBufEn
308 #define SAVAGE_DRAWCTRL_S3D_GLOBAL 0x03f3c00c
309 #define SAVAGE_ZBUFCTRL_S3D_GLOBAL 0x00000027
311 /* Masks for scissor bits (drawCtrl[01] on s4, scissorStart/End on s3d)
313 #define SAVAGE_SCISSOR_MASK_S4 0x00fff7ff
314 #define SAVAGE_SCISSOR_MASK_S3D 0x07ff07ff
319 #define BCI_CMD_NOP 0x40000000
320 #define BCI_CMD_RECT 0x48000000
321 #define BCI_CMD_RECT_XP 0x01000000
322 #define BCI_CMD_RECT_YP 0x02000000
323 #define BCI_CMD_SCANLINE 0x50000000
324 #define BCI_CMD_LINE 0x5C000000
325 #define BCI_CMD_LINE_LAST_PIXEL 0x58000000
326 #define BCI_CMD_BYTE_TEXT 0x63000000
327 #define BCI_CMD_NT_BYTE_TEXT 0x67000000
328 #define BCI_CMD_BIT_TEXT 0x6C000000
329 #define BCI_CMD_GET_ROP(cmd) (((cmd) >> 16) & 0xFF)
330 #define BCI_CMD_SET_ROP(cmd, rop) ((cmd) |= ((rop & 0xFF) << 16))
331 #define BCI_CMD_SEND_COLOR 0x00008000
333 #define BCI_CMD_CLIP_NONE 0x00000000
334 #define BCI_CMD_CLIP_CURRENT 0x00002000
335 #define BCI_CMD_CLIP_LR 0x00004000
336 #define BCI_CMD_CLIP_NEW 0x00006000
338 #define BCI_CMD_DEST_GBD 0x00000000
339 #define BCI_CMD_DEST_PBD 0x00000800
340 #define BCI_CMD_DEST_PBD_NEW 0x00000C00
341 #define BCI_CMD_DEST_SBD 0x00001000
342 #define BCI_CMD_DEST_SBD_NEW 0x00001400
344 #define BCI_CMD_SRC_TRANSPARENT 0x00000200
345 #define BCI_CMD_SRC_SOLID 0x00000000
346 #define BCI_CMD_SRC_GBD 0x00000020
347 #define BCI_CMD_SRC_COLOR 0x00000040
348 #define BCI_CMD_SRC_MONO 0x00000060
349 #define BCI_CMD_SRC_PBD_COLOR 0x00000080
350 #define BCI_CMD_SRC_PBD_MONO 0x000000A0
351 #define BCI_CMD_SRC_PBD_COLOR_NEW 0x000000C0
352 #define BCI_CMD_SRC_PBD_MONO_NEW 0x000000E0
353 #define BCI_CMD_SRC_SBD_COLOR 0x00000100
354 #define BCI_CMD_SRC_SBD_MONO 0x00000120
355 #define BCI_CMD_SRC_SBD_COLOR_NEW 0x00000140
356 #define BCI_CMD_SRC_SBD_MONO_NEW 0x00000160
358 #define BCI_CMD_PAT_TRANSPARENT 0x00000010
359 #define BCI_CMD_PAT_NONE 0x00000000
360 #define BCI_CMD_PAT_COLOR 0x00000002
361 #define BCI_CMD_PAT_MONO 0x00000003
362 #define BCI_CMD_PAT_PBD_COLOR 0x00000004
363 #define BCI_CMD_PAT_PBD_MONO 0x00000005
364 #define BCI_CMD_PAT_PBD_COLOR_NEW 0x00000006
365 #define BCI_CMD_PAT_PBD_MONO_NEW 0x00000007
366 #define BCI_CMD_PAT_SBD_COLOR 0x00000008
367 #define BCI_CMD_PAT_SBD_MONO 0x00000009
368 #define BCI_CMD_PAT_SBD_COLOR_NEW 0x0000000A
369 #define BCI_CMD_PAT_SBD_MONO_NEW 0x0000000B
371 #define BCI_BD_BW_DISABLE 0x10000000
372 #define BCI_BD_TILE_MASK 0x03000000
373 #define BCI_BD_TILE_NONE 0x00000000
374 #define BCI_BD_TILE_16 0x02000000
375 #define BCI_BD_TILE_32 0x03000000
376 #define BCI_BD_GET_BPP(bd) (((bd) >> 16) & 0xFF)
377 #define BCI_BD_SET_BPP(bd, bpp) ((bd) |= (((bpp) & 0xFF) << 16))
378 #define BCI_BD_GET_STRIDE(bd) ((bd) & 0xFFFF)
379 #define BCI_BD_SET_STRIDE(bd, st) ((bd) |= ((st) & 0xFFFF))
381 #define BCI_CMD_SET_REGISTER 0x96000000
383 #define BCI_CMD_WAIT 0xC0000000
384 #define BCI_CMD_WAIT_3D 0x00010000
385 #define BCI_CMD_WAIT_2D 0x00020000
387 #define BCI_CMD_UPDATE_EVENT_TAG 0x98000000
389 #define BCI_CMD_DRAW_PRIM 0x80000000
390 #define BCI_CMD_DRAW_INDEXED_PRIM 0x88000000
391 #define BCI_CMD_DRAW_CONT 0x01000000
392 #define BCI_CMD_DRAW_TRILIST 0x00000000
393 #define BCI_CMD_DRAW_TRISTRIP 0x02000000
394 #define BCI_CMD_DRAW_TRIFAN 0x04000000
395 #define BCI_CMD_DRAW_SKIPFLAGS 0x000000ff
396 #define BCI_CMD_DRAW_NO_Z 0x00000001
397 #define BCI_CMD_DRAW_NO_W 0x00000002
398 #define BCI_CMD_DRAW_NO_CD 0x00000004
399 #define BCI_CMD_DRAW_NO_CS 0x00000008
400 #define BCI_CMD_DRAW_NO_U0 0x00000010
401 #define BCI_CMD_DRAW_NO_V0 0x00000020
402 #define BCI_CMD_DRAW_NO_UV0 0x00000030
403 #define BCI_CMD_DRAW_NO_U1 0x00000040
404 #define BCI_CMD_DRAW_NO_V1 0x00000080
405 #define BCI_CMD_DRAW_NO_UV1 0x000000c0
407 #define BCI_W_H(w, h) ((((h) << 16) | (w)) & 0x0FFF0FFF)
408 #define BCI_X_Y(x, y) ((((y) << 16) | (x)) & 0x0FFF0FFF)
409 #define BCI_X_W(x, y) ((((w) << 16) | (x)) & 0x0FFF0FFF)
410 #define BCI_CLIP_LR(l, r) ((((r) << 16) | (l)) & 0x0FFF0FFF)
411 #define BCI_CLIP_TL(t, l) ((((t) << 16) | (l)) & 0x0FFF0FFF)
412 #define BCI_CLIP_BR(b, r) ((((b) << 16) | (r)) & 0x0FFF0FFF)
414 #define BCI_LINE_X_Y(x, y) (((y) << 16) | ((x) & 0xFFFF))
415 #define BCI_LINE_STEPS(diag, axi) (((axi) << 16) | ((diag) & 0xFFFF))
416 #define BCI_LINE_MISC(maj, ym, xp, yp, err) \
417 (((maj) & 0x1FFF) | \
418 ((ym) ? 1<<13 : 0) | \
419 ((xp) ? 1<<14 : 0) | \
420 ((yp) ? 1<<15 : 0) | \
426 #define BCI_SET_REGISTERS( first, n ) \
427 BCI_WRITE(BCI_CMD_SET_REGISTER | \
428 ((uint32_t)(n) & 0xff) << 16 | \
429 ((uint32_t)(first) & 0xffff))
431 #define BCI_DRAW_PRIMITIVE(n, type, skip) \
432 BCI_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
435 #define BCI_DRAW_INDICES_S3D(n, type, i0) \
436 BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) | \
439 #define BCI_DRAW_INDICES_S4(n, type, skip) \
440 BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) | \
441 (skip) | ((n) << 16))
446 #define SAVAGE_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
447 #define SAVAGE_WRITE(reg) DRM_WRITE32( dev_priv->mmio, (reg) )
450 * access to the burst command interface (BCI)
452 #define SAVAGE_BCI_DEBUG 1
454 #define BCI_LOCALS volatile uint32_t *bci_ptr;
456 #define BEGIN_BCI( n ) do { \
457 dev_priv->wait_fifo(dev_priv, (n)); \
458 bci_ptr = dev_priv->bci_ptr; \
461 #define BCI_WRITE( val ) *bci_ptr++ = (uint32_t)(val)
463 #define BCI_COPY_FROM_USER(src,n) do { \
465 for (i = 0; i < n; ++i) { \
467 DRM_GET_USER_UNCHECKED(val, &((uint32_t*)(src))[i]); \
472 /* Buffer aging via event tag
475 #define UPDATE_EVENT_COUNTER( ) do { \
476 if (dev_priv->status_ptr) { \
478 /* coordinate with Xserver */ \
479 count = dev_priv->status_ptr[1023]; \
480 if (count < dev_priv->event_counter) \
481 dev_priv->event_wrap++; \
482 dev_priv->event_counter = count; \
486 #define SET_AGE( age, e, w ) do { \
491 #define TEST_AGE( age, e, w ) \
492 ( (age)->wrap+1 < (w) || \
493 ( (age)->wrap+1 == (w) && (e) <= dev_priv->event_counter ) || \
494 (age)->event <= (e) )
496 #endif /* __SAVAGE_DRV_H__ */