2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 #ifndef SAVAGE_3D_REG_H
27 #define SAVAGE_3D_REG_H
29 #define VIDEO_MEM_ADR 0x02
30 #define SYSTEM_MEM_ADR 0x01
31 #define AGP_MEM_ADR 0x03
33 /***********************************************************
35 ----------- 3D ENGINE UNIT Registers -------------
37 *********************************************************/
43 unsigned reserved
: 4;
47 } savageRegZPixelOffset
;
49 /* This reg exists only on Savage4. */
55 unsigned stencilEn
: 1;
56 unsigned readMask
: 8;
57 unsigned writeMask
: 8;
59 unsigned passZfailOp
: 3;
60 unsigned passZpassOp
: 3;
61 unsigned reserved
: 3;
64 } savageRegStencilCtrl
;
66 /**************************
68 **************************/
69 /* The layout of this reg differs between Savage4 and Savage3D. */
74 unsigned tex0Width
: 4;
75 unsigned tex0Height
: 4;
77 unsigned tex1Width
: 4;
78 unsigned tex1Height
: 4;
80 unsigned texBLoopEn
: 1;
83 unsigned orthProjEn
: 1;
84 unsigned reserved
: 1;
89 } savageRegTexDescr_s4
;
94 unsigned texWidth
: 4;
95 unsigned reserved1
: 4;
96 unsigned texHeight
: 4;
97 unsigned reserved2
: 4;
98 /* Savage3D supports only the first 8 texture formats defined in
99 enum TexFmt in savge_bci.h. */
101 unsigned palSize
: 2;
102 unsigned reserved3
: 10;
106 } savageRegTexDescr_s3d
;
108 /* The layout of this reg is the same on Savage4 and Savage3D,
109 but the Savage4 has two of them, Savage3D has only one. */
114 unsigned inSysTex
: 1;
115 unsigned inAGPTex
: 1;
116 unsigned reserved
: 1;
122 /* The layout of this reg is the same on Savage4 and Savage3D. */
127 unsigned reserved
: 3;
131 } savageRegTexPalAddr
;
133 /* The layout of this reg on Savage4 and Savage3D are very similar. */
138 unsigned xprClr0
: 16;
139 unsigned xprClr1
: 16; /* this is reserved on Savage3D */
142 } savageRegTexXprClr
; /* transparency color in RGB565 format*/
144 /* The layout of this reg differs between Savage4 and Savage3D.
145 * Savage4 has two of them, Savage3D has only one. */
150 unsigned filterMode
: 2;
151 unsigned mipmapEnable
: 1;
156 unsigned useDFraction
: 1;
157 unsigned texXprEn
: 1;
158 unsigned clrBlendAlphaSel
: 2;
159 unsigned clrArg1CopyAlpha
: 1;
160 unsigned clrArg2CopyAlpha
: 1;
161 unsigned clrArg1Invert
: 1;
162 unsigned clrArg2Invert
: 1;
163 unsigned alphaBlendAlphaSel
: 2;
164 unsigned alphaArg1Invert
: 1;
165 unsigned alphaArg2Invert
: 1;
168 } savageRegTexCtrl_s4
;
173 unsigned filterMode
: 2;
174 unsigned mipmapDisable
: 1;
176 unsigned uWrapEn
: 1;
177 unsigned vWrapEn
: 1;
178 unsigned wrapMode
: 2;
180 unsigned useDFraction
: 1;
181 unsigned reserved1
: 1;
182 /* Color Compare Alpha Blend Control
183 0 - reduce dest alpha to 0 or 1
184 1 - blend with destination
185 The Utah-Driver doesn't know how to use it and sets it to 0. */
187 unsigned texXprEn
: 1;
188 unsigned reserved2
: 11;
191 } savageRegTexCtrl_s3d
;
193 /* This reg exists only on Savage4. */
198 unsigned colorArg1Sel
: 2;
199 unsigned colorArg2Sel
: 3;
200 unsigned colorInvAlphaEn
: 1;
201 unsigned colorInvArg2En
: 1;
202 unsigned colorPremodSel
: 1;
203 unsigned colorMod1Sel
: 1;
204 unsigned colorMod2Sel
: 2;
205 unsigned colorAddSel
: 2;
206 unsigned colorDoBlend
: 1;
207 unsigned colorDo2sCompl
: 1;
208 unsigned colorAddBiasEn
: 1;
209 unsigned alphaArg1Sel
: 2;
210 unsigned alphaArg2Sel
: 3;
211 unsigned alphaMod1Sel
: 1;
212 unsigned alphaMod2Sel
: 2;
213 unsigned alphaAdd0Sel
: 1;
214 unsigned alphaDoBlend
: 1;
215 unsigned alphaDo2sCompl
: 1;
216 unsigned colorStageClamp
: 1;
217 unsigned alphaStageClamp
: 1;
218 unsigned colorDoDiffMul
: 1;
219 unsigned LeftShiftVal
: 2;
222 } savageRegTexBlendCtrl
;
224 /* This reg exists only on Savage4. */
235 } savageRegTexBlendColor
;
237 /********************************
238 Tiled Surface Registers
239 **********************************/
245 unsigned frmBufOffset
: 13;
246 unsigned reserved
: 12;
247 unsigned widthInTile
: 6;
248 unsigned bitPerPixel
: 1;
251 } savageRegTiledSurface
;
253 /********************************
254 Draw/Shading Control Registers
255 **********************************/
257 /* This reg exists only on Savage4. */
262 unsigned scissorXStart
: 11;
263 unsigned dPerfAccelEn
: 1;
264 unsigned scissorYStart
: 12;
265 unsigned alphaRefVal
: 8;
268 } savageRegDrawCtrl0
;
270 /* This reg exists only on Savage4. */
275 unsigned scissorXEnd
: 11;
276 unsigned xyOffsetEn
: 1;
277 unsigned scissorYEnd
: 12;
278 unsigned ditherEn
: 1;
279 unsigned nonNormTexCoord
: 1;
280 unsigned cullMode
: 2;
281 unsigned alphaTestCmpFunc
: 3;
282 unsigned alphaTestEn
: 1;
285 } savageRegDrawCtrl1
;
287 /* This reg exists only on Savage4. */
292 unsigned dstAlphaMode
: 3;
293 unsigned dstMinusSrc
: 1;
294 unsigned srcAlphaMode
: 3;
295 unsigned binaryFinalAlpha
: 1;
296 unsigned dstAlphaModeHighBit
: 1;
297 unsigned srcAlphaModeHighBit
: 1;
298 unsigned reserved1
: 15;
299 unsigned wrZafterAlphaTst
: 1;
300 unsigned drawUpdateEn
: 1;
301 unsigned zUpdateEn
: 1;
302 unsigned flatShadeEn
: 1;
303 unsigned specShadeEn
: 1;
304 unsigned flushPdDestWrites
: 1;
305 unsigned flushPdZbufWrites
: 1;
308 } savageRegDrawLocalCtrl
;
310 /* This reg exists only on Savage3D. */
315 unsigned ditherEn
: 1;
316 unsigned xyOffsetEn
: 1;
317 unsigned cullMode
: 2;
318 unsigned vertexCountReset
: 1;
319 unsigned flatShadeEn
: 1;
320 unsigned specShadeEn
: 1;
321 unsigned dstAlphaMode
: 3;
322 unsigned srcAlphaMode
: 3;
323 unsigned reserved1
: 1;
324 unsigned alphaTestCmpFunc
: 3;
325 unsigned alphaTestEn
: 1;
326 unsigned alphaRefVal
: 8;
327 unsigned texBlendCtrl
: 3;
328 unsigned flushPdDestWrites
: 1;
329 unsigned flushPdZbufWrites
: 1;
330 /* havn't found an equivalent for Savage4. Utah-driver sets it to 0. */
331 unsigned interpMode
: 1;
336 #define SAVAGETBC_DECAL_S3D 0
337 #define SAVAGETBC_MODULATE_S3D 1
338 #define SAVAGETBC_DECALALPHA_S3D 2
339 #define SAVAGETBC_MODULATEALPHA_S3D 3
340 #define SAVAGETBC_4_S3D 4
341 #define SAVAGETBC_5_S3D 5
342 #define SAVAGETBC_COPY_S3D 6
343 #define SAVAGETBC_7_S3D 7
345 /* This reg exists only on Savage3D. */
350 unsigned scissorXStart
: 11;
351 unsigned reserved1
: 5;
352 unsigned scissorYStart
: 11;
353 unsigned reserved2
: 5;
356 } savageRegScissorsStart
;
358 /* This reg exists only on Savage3D. */
363 unsigned scissorXEnd
: 11;
364 unsigned reserved1
: 5;
365 unsigned scissorYEnd
: 11;
366 unsigned reserved2
: 5;
369 } savageRegScissorsEnd
;
371 /********************************
373 **********************************/
375 /* I havn't found a Savage3D equivalent of this reg in the Utah-driver.
376 * But Tim Roberts claims that the Savage3D supports DMA vertex and
377 * command buffers. */
384 unsigned reserved
: 1;
385 unsigned addr
: 29; /*quad word aligned*/
388 } savageRegVertBufAddr
;
390 /* I havn't found a Savage3D equivalent of this reg in the Utah-driver.
391 * But Tim Roberts claims that the Savage3D supports DMA vertex and
392 * command buffers. */
399 unsigned reserved
: 1;
400 unsigned addr
: 29; /*4-quad word aligned*/
403 } savageRegDMABufAddr
;
405 /********************************
407 **********************************/
408 /* The layout of this reg is the same on Savage4 and Savage3D. */
423 unsigned cullOrient
: 1;
424 unsigned loadNewTex
: 1;
425 unsigned loadNewPal
: 1;
426 unsigned doDSetup
: 1;
427 unsigned reserved
: 17;
428 unsigned kickOff
: 1;
433 /********************************
434 Z Buffer Registers -- Global
435 **********************************/
437 /* The layout of this reg differs between Savage4 and Savage3D. */
442 unsigned zCmpFunc
: 3;
443 unsigned reserved1
: 2;
445 unsigned reserved2
: 1;
446 unsigned zExpOffset
: 8;
447 unsigned reserved3
: 1;
448 unsigned stencilRefVal
: 8;
449 unsigned autoZEnable
: 1;
450 unsigned frameID
: 1;
451 unsigned reserved4
: 4;
452 unsigned floatZEn
: 1;
456 } savageRegZBufCtrl_s4
;
460 unsigned zCmpFunc
: 3;
461 unsigned drawUpdateEn
: 1;
462 unsigned zUpdateEn
: 1;
466 * We suspect that, in conjunction with
467 * \c savageRegZBufOffset::zDepthSelect, these 2 bits are actually
468 * \c stencilUpdateEn and \c stencilBufEn. If not, then some of
469 * the bits in \c reserved2 may fulfill that purpose.
471 unsigned reserved1
: 2;
473 unsigned zExpOffset
: 8;
474 unsigned wrZafterAlphaTst
: 1;
475 unsigned reserved2
: 15;
478 } savageRegZBufCtrl_s3d
;
480 /* The layout of this reg on Savage4 and Savage3D is very similar. */
485 /* In the Utah-Driver the offset is defined as 13-bit, 2k-aligned. */
486 unsigned offset
: 14;
487 unsigned reserved
: 11; /* 12-bits in Utah-driver */
488 unsigned zBufWidthInTiles
: 6;
491 * 0 selects 16-bit depth buffer. On Savage4 hardware, 1 selects
492 * 24-bit depth buffer (with 8-bits for stencil). Though it has never
493 * been tried, we suspect that on Savage3D hardware, 1 selects 15-bit
494 * depth buffer (with 1-bit for stencil).
496 unsigned zDepthSelect
: 1;
499 } savageRegZBufOffset
;
501 /* The layout of this reg is the same on Savage4 and Savage3D. */
507 unsigned reserved1
: 2;
509 unsigned reserved2
: 2;
511 unsigned reserved3
: 2;
513 unsigned reserved4
: 2;
516 } savageRegZWatermarks
;
518 /********************************
519 Fog Registers -- Global
520 **********************************/
521 /* The layout of this reg is the same on Savage4 and Savage3D. */
526 unsigned fogClr
: 24;
527 unsigned expShift
: 3;
528 unsigned reserved
: 1;
530 unsigned fogMode
: 1;
531 unsigned fogEndShift
: 2;
536 /*not in spec, but tempo for pp and driver*/
541 unsigned fogDensity
: 16;
542 unsigned fogStart
: 16;
547 /**************************************
548 Destination Buffer Registers -- Global
549 ***************************************/
551 /* The layout of this reg on Savage4 and Savage3D are very similar. */
556 unsigned dstWidthInTile
: 7;
557 unsigned reserved
: 1;
558 /* In the Utah-Driver the offset is defined as 13-bit, 2k-aligned. */
559 unsigned offset
: 14;
560 unsigned reserved1
: 7;
561 /* antiAliasMode does not exist in the Utah-driver. But it includes the
562 * high bit of this in the destPixFmt. However, only values 0 and 2
563 * are used as dstPixFmt, so antiAliasMode is effectively always 0
564 * in the Utah-driver. In other words, treat as reserved on Savage3D.*/
565 unsigned antiAliasMode
: 2;
566 unsigned dstPixFmt
: 1;
571 /* The layout of this reg on Savage4 and Savage3D are very similar. */
576 unsigned destReadLow
: 6;
577 unsigned destReadHigh
: 6;
578 unsigned destWriteLow
: 6;
579 unsigned destWriteHigh
: 6;
580 unsigned texRead
: 4;
581 unsigned reserved4
: 2;
582 /* The Utah-driver calls this pixel FIFO length:
583 * 00 - 240, 01 - 180, 10 - 120, 11 - 60
584 * However, it is not used in either driver. */
585 unsigned destFlush
: 2;
588 } savageRegDestTexWatermarks
;
590 /* Savage4/Twister/ProSavage register BCI addresses */
591 #define SAVAGE_DRAWLOCALCTRL_S4 0x1e
592 #define SAVAGE_TEXPALADDR_S4 0x1f
593 #define SAVAGE_TEXCTRL0_S4 0x20
594 #define SAVAGE_TEXCTRL1_S4 0x21
595 #define SAVAGE_TEXADDR0_S4 0x22
596 #define SAVAGE_TEXADDR1_S4 0x23
597 #define SAVAGE_TEXBLEND0_S4 0x24
598 #define SAVAGE_TEXBLEND1_S4 0x25
599 #define SAVAGE_TEXXPRCLR_S4 0x26 /* never used */
600 #define SAVAGE_TEXDESCR_S4 0x27
601 #define SAVAGE_FOGTABLE_S4 0x28
602 #define SAVAGE_FOGCTRL_S4 0x30
603 #define SAVAGE_STENCILCTRL_S4 0x31
604 #define SAVAGE_ZBUFCTRL_S4 0x32
605 #define SAVAGE_ZBUFOFF_S4 0x33
606 #define SAVAGE_DESTCTRL_S4 0x34
607 #define SAVAGE_DRAWCTRLGLOBAL0_S4 0x35
608 #define SAVAGE_DRAWCTRLGLOBAL1_S4 0x36
609 #define SAVAGE_ZWATERMARK_S4 0x37
610 #define SAVAGE_DESTTEXRWWATERMARK_S4 0x38
611 #define SAVAGE_TEXBLENDCOLOR_S4 0x39
612 /* Savage3D/MX/IC register BCI addresses */
613 #define SAVAGE_TEXPALADDR_S3D 0x18
614 #define SAVAGE_TEXXPRCLR_S3D 0x19 /* never used */
615 #define SAVAGE_TEXADDR_S3D 0x1A
616 #define SAVAGE_TEXDESCR_S3D 0x1B
617 #define SAVAGE_TEXCTRL_S3D 0x1C
618 #define SAVAGE_FOGTABLE_S3D 0x20
619 #define SAVAGE_FOGCTRL_S3D 0x30
620 #define SAVAGE_DRAWCTRL_S3D 0x31
621 #define SAVAGE_ZBUFCTRL_S3D 0x32
622 #define SAVAGE_ZBUFOFF_S3D 0x33
623 #define SAVAGE_DESTCTRL_S3D 0x34
624 #define SAVAGE_SCSTART_S3D 0x35
625 #define SAVAGE_SCEND_S3D 0x36
626 #define SAVAGE_ZWATERMARK_S3D 0x37
627 #define SAVAGE_DESTTEXRWWATERMARK_S3D 0x38
629 #define SAVAGE_FIRST_REG 0x18
630 #define SAVAGE_NR_REGS 34
631 typedef struct savage_registers_s4_t
{
632 uint32_t unused1
[6]; /* 0x18-0x1d */
633 savageRegDrawLocalCtrl drawLocalCtrl
; /* 0x1e */
634 savageRegTexPalAddr texPalAddr
; /* 0x1f */
635 savageRegTexCtrl_s4 texCtrl
[2]; /* 0x20, 0x21 */
636 savageRegTexAddr texAddr
[2]; /* 0x22, 0x23 */
637 savageRegTexBlendCtrl texBlendCtrl
[2]; /* 0x24, 0x25 */
638 savageRegTexXprClr texXprClr
; /* 0x26 */
639 savageRegTexDescr_s4 texDescr
; /* 0x27 */
640 uint8_t fogTable
[32]; /* 0x28-0x2f (8dwords) */
641 savageRegFogCtrl fogCtrl
; /* 0x30 */
642 savageRegStencilCtrl stencilCtrl
; /* 0x31 */
643 savageRegZBufCtrl_s4 zBufCtrl
; /* 0x32 */
644 savageRegZBufOffset zBufOffset
; /* 0x33 */
645 savageRegDestCtrl destCtrl
; /* 0x34 */
646 savageRegDrawCtrl0 drawCtrl0
; /* 0x35 */
647 savageRegDrawCtrl1 drawCtrl1
; /* 0x36 */
648 savageRegZWatermarks zWatermarks
; /* 0x37 */
649 savageRegDestTexWatermarks destTexWatermarks
; /* 0x38 */
650 savageRegTexBlendColor texBlendColor
; /* 0x39 */
652 typedef struct savage_registers_s3d_t
{
653 savageRegTexPalAddr texPalAddr
; /* 0x18 */
654 savageRegTexXprClr texXprClr
; /* 0x19 */
655 savageRegTexAddr texAddr
; /* 0x1a */
656 savageRegTexDescr_s3d texDescr
; /* 0x1b */
657 savageRegTexCtrl_s3d texCtrl
; /* 0x1c */
658 uint32_t unused1
[3]; /* 0x1d-0x1f */
659 uint8_t fogTable
[64]; /* 0x20-0x2f (16dwords) */
660 savageRegFogCtrl fogCtrl
; /* 0x30 */
661 savageRegDrawCtrl drawCtrl
; /* 0x31 */
662 savageRegZBufCtrl_s3d zBufCtrl
; /* 0x32 */
663 savageRegZBufOffset zBufOffset
; /* 0x33 */
664 savageRegDestCtrl destCtrl
; /* 0x34 */
665 savageRegScissorsStart scissorsStart
; /* 0x35 */
666 savageRegScissorsEnd scissorsEnd
; /* 0x36 */
667 savageRegZWatermarks zWatermarks
; /* 0x37 */
668 savageRegDestTexWatermarks destTexWatermarks
; /* 0x38 */
669 uint32_t unused2
; /* 0x39 */
670 } savageRegistersS3D
;
671 typedef union savage_registers_t
{
672 savageRegistersS4 s4
;
673 savageRegistersS3D s3d
;
674 uint32_t ui
[SAVAGE_NR_REGS
];
678 #define DV_PF_555 (0x1<<8)
679 #define DV_PF_565 (0x2<<8)
680 #define DV_PF_8888 (0x4<<8)
682 #define SAVAGEPACKCOLORA4L4(l,a) \
683 ((l >> 4) | (a & 0xf0))
685 #define SAVAGEPACKCOLOR4444(r,g,b,a) \
686 ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4))
688 #define SAVAGEPACKCOLOR1555(r,g,b,a) \
689 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
692 #define SAVAGEPACKCOLOR8888(r,g,b,a) \
693 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
695 #define SAVAGEPACKCOLOR565(r,g,b) \
696 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))