File: /usr/src/linux/drivers/video/riva/riva_hw.h
1 /***************************************************************************\
2 |* *|
3 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
4 |* *|
5 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
6 |* international laws. Users and possessors of this source code are *|
7 |* hereby granted a nonexclusive, royalty-free copyright license to *|
8 |* use this code in individual and commercial software. *|
9 |* *|
10 |* Any use of this source code must include, in the user documenta- *|
11 |* tion and internal comments to the code, notices to the end user *|
12 |* as follows: *|
13 |* *|
14 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
15 |* *|
16 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
17 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
18 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
19 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
20 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
21 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
22 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
23 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
24 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
25 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
26 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
27 |* *|
28 |* U.S. Government End Users. This source code is a "commercial *|
29 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
30 |* consisting of "commercial computer software" and "commercial *|
31 |* computer software documentation," as such terms are used in *|
32 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
33 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
34 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
35 |* all U.S. Government End Users acquire the source code with only *|
36 |* those rights set forth herein. *|
37 |* *|
38 \***************************************************************************/
39
40 /*
41 * GPL licensing note -- nVidia is allowing a liberal interpretation of
42 * the documentation restriction above, to merely say that this nVidia's
43 * copyright and disclaimer should be included with all code derived
44 * from this source. -- Jeff Garzik <jgarzik@mandrakesoft.com>, 01/Nov/99
45 */
46
47 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_hw.h,v 1.6 2000/02/08 17:19:12 dawes Exp $ */
48 #ifndef __RIVA_HW_H__
49 #define __RIVA_HW_H__
50 #define RIVA_SW_VERSION 0x00010003
51
52 /*
53 * Typedefs to force certain sized values.
54 */
55 typedef unsigned char U008;
56 typedef unsigned short U016;
57 typedef unsigned int U032;
58
59 /*
60 * HW access macros.
61 */
62 #define NV_WR08(p,i,d) (((U008 *)(p))[i]=(d))
63 #define NV_RD08(p,i) (((U008 *)(p))[i])
64 #define NV_WR16(p,i,d) (((U016 *)(p))[(i)/2]=(d))
65 #define NV_RD16(p,i) (((U016 *)(p))[(i)/2])
66 #define NV_WR32(p,i,d) (((U032 *)(p))[(i)/4]=(d))
67 #define NV_RD32(p,i) (((U032 *)(p))[(i)/4])
68 #define VGA_WR08(p,i,d) NV_WR08(p,i,d)
69 #define VGA_RD08(p,i) NV_RD08(p,i)
70
71 /*
72 * Define supported architectures.
73 */
74 #define NV_ARCH_03 0x03
75 #define NV_ARCH_04 0x04
76 #define NV_ARCH_10 0x10
77 /***************************************************************************\
78 * *
79 * FIFO registers. *
80 * *
81 \***************************************************************************/
82
83 /*
84 * Raster OPeration. Windows style ROP3.
85 */
86 typedef volatile struct
87 {
88 U032 reserved00[4];
89 U016 FifoFree;
90 U016 Nop;
91 U032 reserved01[0x0BB];
92 U032 Rop3;
93 } RivaRop;
94 /*
95 * 8X8 Monochrome pattern.
96 */
97 typedef volatile struct
98 {
99 U032 reserved00[4];
100 U016 FifoFree;
101 U016 Nop;
102 U032 reserved01[0x0BD];
103 U032 Shape;
104 U032 reserved03[0x001];
105 U032 Color0;
106 U032 Color1;
107 U032 Monochrome[2];
108 } RivaPattern;
109 /*
110 * Scissor clip rectangle.
111 */
112 typedef volatile struct
113 {
114 U032 reserved00[4];
115 U016 FifoFree;
116 U016 Nop;
117 U032 reserved01[0x0BB];
118 U032 TopLeft;
119 U032 WidthHeight;
120 } RivaClip;
121 /*
122 * 2D filled rectangle.
123 */
124 typedef volatile struct
125 {
126 U032 reserved00[4];
127 U016 FifoFree;
128 U016 Nop[1];
129 U032 reserved01[0x0BC];
130 U032 Color;
131 U032 reserved03[0x03E];
132 U032 TopLeft;
133 U032 WidthHeight;
134 } RivaRectangle;
135 /*
136 * 2D screen-screen BLT.
137 */
138 typedef volatile struct
139 {
140 U032 reserved00[4];
141 U016 FifoFree;
142 U016 Nop;
143 U032 reserved01[0x0BB];
144 U032 TopLeftSrc;
145 U032 TopLeftDst;
146 U032 WidthHeight;
147 } RivaScreenBlt;
148 /*
149 * 2D pixel BLT.
150 */
151 typedef volatile struct
152 {
153 U032 reserved00[4];
154 U016 FifoFree;
155 U016 Nop[1];
156 U032 reserved01[0x0BC];
157 U032 TopLeft;
158 U032 WidthHeight;
159 U032 WidthHeightIn;
160 U032 reserved02[0x03C];
161 U032 Pixels;
162 } RivaPixmap;
163 /*
164 * Filled rectangle combined with monochrome expand. Useful for glyphs.
165 */
166 typedef volatile struct
167 {
168 U032 reserved00[4];
169 U016 FifoFree;
170 U016 Nop;
171 U032 reserved01[0x0BB];
172 U032 reserved03[(0x040)-1];
173 U032 Color1A;
174 struct
175 {
176 U032 TopLeft;
177 U032 WidthHeight;
178 } UnclippedRectangle[64];
179 U032 reserved04[(0x080)-3];
180 struct
181 {
182 U032 TopLeft;
183 U032 BottomRight;
184 } ClipB;
185 U032 Color1B;
186 struct
187 {
188 U032 TopLeft;
189 U032 BottomRight;
190 } ClippedRectangle[64];
191 U032 reserved05[(0x080)-5];
192 struct
193 {
194 U032 TopLeft;
195 U032 BottomRight;
196 } ClipC;
197 U032 Color1C;
198 U032 WidthHeightC;
199 U032 PointC;
200 U032 MonochromeData1C;
201 U032 reserved06[(0x080)+121];
202 struct
203 {
204 U032 TopLeft;
205 U032 BottomRight;
206 } ClipD;
207 U032 Color1D;
208 U032 WidthHeightInD;
209 U032 WidthHeightOutD;
210 U032 PointD;
211 U032 MonochromeData1D;
212 U032 reserved07[(0x080)+120];
213 struct
214 {
215 U032 TopLeft;
216 U032 BottomRight;
217 } ClipE;
218 U032 Color0E;
219 U032 Color1E;
220 U032 WidthHeightInE;
221 U032 WidthHeightOutE;
222 U032 PointE;
223 U032 MonochromeData01E;
224 } RivaBitmap;
225 /*
226 * 3D textured, Z buffered triangle.
227 */
228 typedef volatile struct
229 {
230 U032 reserved00[4];
231 U016 FifoFree;
232 U016 Nop;
233 U032 reserved01[0x0BC];
234 U032 TextureOffset;
235 U032 TextureFormat;
236 U032 TextureFilter;
237 U032 FogColor;
238 /* This is a problem on LynxOS */
239 #ifdef Control
240 #undef Control
241 #endif
242 U032 Control;
243 U032 AlphaTest;
244 U032 reserved02[0x339];
245 U032 FogAndIndex;
246 U032 Color;
247 float ScreenX;
248 float ScreenY;
249 float ScreenZ;
250 float EyeM;
251 float TextureS;
252 float TextureT;
253 } RivaTexturedTriangle03;
254 typedef volatile struct
255 {
256 U032 reserved00[4];
257 U016 FifoFree;
258 U016 Nop;
259 U032 reserved01[0x0BB];
260 U032 ColorKey;
261 U032 TextureOffset;
262 U032 TextureFormat;
263 U032 TextureFilter;
264 U032 Blend;
265 /* This is a problem on LynxOS */
266 #ifdef Control
267 #undef Control
268 #endif
269 U032 Control;
270 U032 FogColor;
271 U032 reserved02[0x39];
272 struct
273 {
274 float ScreenX;
275 float ScreenY;
276 float ScreenZ;
277 float EyeM;
278 U032 Color;
279 U032 Specular;
280 float TextureS;
281 float TextureT;
282 } Vertex[16];
283 U032 DrawTriangle3D;
284 } RivaTexturedTriangle05;
285 /*
286 * 2D line.
287 */
288 typedef volatile struct
289 {
290 U032 reserved00[4];
291 U016 FifoFree;
292 U016 Nop[1];
293 U032 reserved01[0x0BC];
294 U032 Color; /* source color 0304-0307*/
295 U032 Reserved02[0x03e];
296 struct { /* start aliased methods in array 0400- */
297 U032 point0; /* y_x S16_S16 in pixels 0- 3*/
298 U032 point1; /* y_x S16_S16 in pixels 4- 7*/
299 } Lin[16]; /* end of aliased methods in array -047f*/
300 struct { /* start aliased methods in array 0480- */
301 U032 point0X; /* in pixels, 0 at left 0- 3*/
302 U032 point0Y; /* in pixels, 0 at top 4- 7*/
303 U032 point1X; /* in pixels, 0 at left 8- b*/
304 U032 point1Y; /* in pixels, 0 at top c- f*/
305 } Lin32[8]; /* end of aliased methods in array -04ff*/
306 U032 PolyLin[32]; /* y_x S16_S16 in pixels 0500-057f*/
307 struct { /* start aliased methods in array 0580- */
308 U032 x; /* in pixels, 0 at left 0- 3*/
309 U032 y; /* in pixels, 0 at top 4- 7*/
310 } PolyLin32[16]; /* end of aliased methods in array -05ff*/
311 struct { /* start aliased methods in array 0600- */
312 U032 color; /* source color 0- 3*/
313 U032 point; /* y_x S16_S16 in pixels 4- 7*/
314 } ColorPolyLin[16]; /* end of aliased methods in array -067f*/
315 } RivaLine;
316 /*
317 * 2D/3D surfaces
318 */
319 typedef volatile struct
320 {
321 U032 reserved00[4];
322 U016 FifoFree;
323 U016 Nop;
324 U032 reserved01[0x0BE];
325 U032 Offset;
326 } RivaSurface;
327 typedef volatile struct
328 {
329 U032 reserved00[4];
330 U016 FifoFree;
331 U016 Nop;
332 U032 reserved01[0x0BD];
333 U032 Pitch;
334 U032 RenderBufferOffset;
335 U032 ZBufferOffset;
336 } RivaSurface3D;
337
338 /***************************************************************************\
339 * *
340 * Virtualized RIVA H/W interface. *
341 * *
342 \***************************************************************************/
343
344 struct _riva_hw_inst;
345 struct _riva_hw_state;
346 /*
347 * Virtialized chip interface. Makes RIVA 128 and TNT look alike.
348 */
349 typedef struct _riva_hw_inst
350 {
351 /*
352 * Chip specific settings.
353 */
354 U032 Architecture;
355 U032 Version;
356 U032 CrystalFreqKHz;
357 U032 RamAmountKBytes;
358 U032 MaxVClockFreqKHz;
359 U032 RamBandwidthKBytesPerSec;
360 U032 EnableIRQ;
361 U032 IO;
362 U032 VBlankBit;
363 U032 FifoFreeCount;
364 U032 FifoEmptyCount;
365 /*
366 * Non-FIFO registers.
367 */
368 volatile U032 *PCRTC;
369 volatile U032 *PRAMDAC;
370 volatile U032 *PFB;
371 volatile U032 *PFIFO;
372 volatile U032 *PGRAPH;
373 volatile U032 *PEXTDEV;
374 volatile U032 *PTIMER;
375 volatile U032 *PMC;
376 volatile U032 *PRAMIN;
377 volatile U032 *FIFO;
378 volatile U032 *CURSOR;
379 volatile U032 *CURSORPOS;
380 volatile U032 *VBLANKENABLE;
381 volatile U032 *VBLANK;
382 volatile U008 *PCIO;
383 volatile U008 *PVIO;
384 volatile U008 *PDIO;
385 /*
386 * Common chip functions.
387 */
388 int (*Busy)(struct _riva_hw_inst *);
389 void (*CalcStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *,int,int,int,int,int,int,int,int,int,int,int,int,int);
390 void (*LoadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
391 void (*UnloadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
392 void (*SetStartAddress)(struct _riva_hw_inst *,U032);
393 void (*SetSurfaces2D)(struct _riva_hw_inst *,U032,U032);
394 void (*SetSurfaces3D)(struct _riva_hw_inst *,U032,U032);
395 int (*ShowHideCursor)(struct _riva_hw_inst *,int);
396 void (*LockUnlock)(struct _riva_hw_inst *, int);
397 /*
398 * Current extended mode settings.
399 */
400 struct _riva_hw_state *CurrentState;
401 /*
402 * FIFO registers.
403 */
404 RivaRop *Rop;
405 RivaPattern *Patt;
406 RivaClip *Clip;
407 RivaPixmap *Pixmap;
408 RivaScreenBlt *Blt;
409 RivaBitmap *Bitmap;
410 RivaLine *Line;
411 RivaTexturedTriangle03 *Tri03;
412 RivaTexturedTriangle05 *Tri05;
413 } RIVA_HW_INST;
414 /*
415 * Extended mode state information.
416 */
417 typedef struct _riva_hw_state
418 {
419 U032 bpp;
420 U032 width;
421 U032 height;
422 U032 repaint0;
423 U032 repaint1;
424 U032 screen;
425 U032 pixel;
426 U032 horiz;
427 U032 arbitration0;
428 U032 arbitration1;
429 U032 vpll;
430 U032 pllsel;
431 U032 general;
432 U032 config;
433 U032 cursor0;
434 U032 cursor1;
435 U032 cursor2;
436 U032 offset0;
437 U032 offset1;
438 U032 offset2;
439 U032 offset3;
440 U032 pitch0;
441 U032 pitch1;
442 U032 pitch2;
443 U032 pitch3;
444 } RIVA_HW_STATE;
445 /*
446 * External routines.
447 */
448 int RivaGetConfig(RIVA_HW_INST *);
449 /*
450 * FIFO Free Count. Should attempt to yield processor if RIVA is busy.
451 */
452
453 #define RIVA_FIFO_FREE(hwinst,hwptr,cnt) \
454 { \
455 while ((hwinst).FifoFreeCount < (cnt)) \
456 (hwinst).FifoFreeCount = (hwinst).hwptr->FifoFree >> 2; \
457 (hwinst).FifoFreeCount -= (cnt); \
458 }
459 #endif /* __RIVA_HW_H__ */
460
461