riva_hw.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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. * GPL licensing note -- nVidia is allowing a liberal interpretation of
  41. * the documentation restriction above, to merely say that this nVidia's
  42. * copyright and disclaimer should be included with all code derived
  43. * from this source. -- Jeff Garzik <jgarzik@pobox.com>, 01/Nov/99
  44. */
  45. /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_hw.h,v 1.21 2002/10/14 18:22:46 mvojkovi Exp $ */
  46. #ifndef __RIVA_HW_H__
  47. #define __RIVA_HW_H__
  48. #define RIVA_SW_VERSION 0x00010003
  49. #ifndef Bool
  50. typedef int Bool;
  51. #endif
  52. #ifndef TRUE
  53. #define TRUE 1
  54. #endif
  55. #ifndef FALSE
  56. #define FALSE 0
  57. #endif
  58. #ifndef NULL
  59. #define NULL 0
  60. #endif
  61. /*
  62. * Typedefs to force certain sized values.
  63. */
  64. typedef unsigned char U008;
  65. typedef unsigned short U016;
  66. typedef unsigned int U032;
  67. /*
  68. * HW access macros.
  69. */
  70. #include <asm/io.h>
  71. #define NV_WR08(p,i,d) (__raw_writeb((d), (void __iomem *)(p) + (i)))
  72. #define NV_RD08(p,i) (__raw_readb((void __iomem *)(p) + (i)))
  73. #define NV_WR16(p,i,d) (__raw_writew((d), (void __iomem *)(p) + (i)))
  74. #define NV_RD16(p,i) (__raw_readw((void __iomem *)(p) + (i)))
  75. #define NV_WR32(p,i,d) (__raw_writel((d), (void __iomem *)(p) + (i)))
  76. #define NV_RD32(p,i) (__raw_readl((void __iomem *)(p) + (i)))
  77. #define VGA_WR08(p,i,d) (writeb((d), (void __iomem *)(p) + (i)))
  78. #define VGA_RD08(p,i) (readb((void __iomem *)(p) + (i)))
  79. /*
  80. * Define different architectures.
  81. */
  82. #define NV_ARCH_03 0x03
  83. #define NV_ARCH_04 0x04
  84. #define NV_ARCH_10 0x10
  85. #define NV_ARCH_20 0x20
  86. #define NV_ARCH_30 0x30
  87. #define NV_ARCH_40 0x40
  88. /***************************************************************************\
  89. * *
  90. * FIFO registers. *
  91. * *
  92. \***************************************************************************/
  93. /*
  94. * Raster OPeration. Windows style ROP3.
  95. */
  96. typedef volatile struct
  97. {
  98. U032 reserved00[4];
  99. #ifdef __BIG_ENDIAN
  100. U032 FifoFree;
  101. #else
  102. U016 FifoFree;
  103. U016 Nop;
  104. #endif
  105. U032 reserved01[0x0BB];
  106. U032 Rop3;
  107. } RivaRop;
  108. /*
  109. * 8X8 Monochrome pattern.
  110. */
  111. typedef volatile struct
  112. {
  113. U032 reserved00[4];
  114. #ifdef __BIG_ENDIAN
  115. U032 FifoFree;
  116. #else
  117. U016 FifoFree;
  118. U016 Nop;
  119. #endif
  120. U032 reserved01[0x0BD];
  121. U032 Shape;
  122. U032 reserved03[0x001];
  123. U032 Color0;
  124. U032 Color1;
  125. U032 Monochrome[2];
  126. } RivaPattern;
  127. /*
  128. * Scissor clip rectangle.
  129. */
  130. typedef volatile struct
  131. {
  132. U032 reserved00[4];
  133. #ifdef __BIG_ENDIAN
  134. U032 FifoFree;
  135. #else
  136. U016 FifoFree;
  137. U016 Nop;
  138. #endif
  139. U032 reserved01[0x0BB];
  140. U032 TopLeft;
  141. U032 WidthHeight;
  142. } RivaClip;
  143. /*
  144. * 2D filled rectangle.
  145. */
  146. typedef volatile struct
  147. {
  148. U032 reserved00[4];
  149. #ifdef __BIG_ENDIAN
  150. U032 FifoFree;
  151. #else
  152. U016 FifoFree;
  153. U016 Nop[1];
  154. #endif
  155. U032 reserved01[0x0BC];
  156. U032 Color;
  157. U032 reserved03[0x03E];
  158. U032 TopLeft;
  159. U032 WidthHeight;
  160. } RivaRectangle;
  161. /*
  162. * 2D screen-screen BLT.
  163. */
  164. typedef volatile struct
  165. {
  166. U032 reserved00[4];
  167. #ifdef __BIG_ENDIAN
  168. U032 FifoFree;
  169. #else
  170. U016 FifoFree;
  171. U016 Nop;
  172. #endif
  173. U032 reserved01[0x0BB];
  174. U032 TopLeftSrc;
  175. U032 TopLeftDst;
  176. U032 WidthHeight;
  177. } RivaScreenBlt;
  178. /*
  179. * 2D pixel BLT.
  180. */
  181. typedef volatile struct
  182. {
  183. U032 reserved00[4];
  184. #ifdef __BIG_ENDIAN
  185. U032 FifoFree;
  186. #else
  187. U016 FifoFree;
  188. U016 Nop[1];
  189. #endif
  190. U032 reserved01[0x0BC];
  191. U032 TopLeft;
  192. U032 WidthHeight;
  193. U032 WidthHeightIn;
  194. U032 reserved02[0x03C];
  195. U032 Pixels;
  196. } RivaPixmap;
  197. /*
  198. * Filled rectangle combined with monochrome expand. Useful for glyphs.
  199. */
  200. typedef volatile struct
  201. {
  202. U032 reserved00[4];
  203. #ifdef __BIG_ENDIAN
  204. U032 FifoFree;
  205. #else
  206. U016 FifoFree;
  207. U016 Nop;
  208. #endif
  209. U032 reserved01[0x0BB];
  210. U032 reserved03[(0x040)-1];
  211. U032 Color1A;
  212. struct
  213. {
  214. U032 TopLeft;
  215. U032 WidthHeight;
  216. } UnclippedRectangle[64];
  217. U032 reserved04[(0x080)-3];
  218. struct
  219. {
  220. U032 TopLeft;
  221. U032 BottomRight;
  222. } ClipB;
  223. U032 Color1B;
  224. struct
  225. {
  226. U032 TopLeft;
  227. U032 BottomRight;
  228. } ClippedRectangle[64];
  229. U032 reserved05[(0x080)-5];
  230. struct
  231. {
  232. U032 TopLeft;
  233. U032 BottomRight;
  234. } ClipC;
  235. U032 Color1C;
  236. U032 WidthHeightC;
  237. U032 PointC;
  238. U032 MonochromeData1C;
  239. U032 reserved06[(0x080)+121];
  240. struct
  241. {
  242. U032 TopLeft;
  243. U032 BottomRight;
  244. } ClipD;
  245. U032 Color1D;
  246. U032 WidthHeightInD;
  247. U032 WidthHeightOutD;
  248. U032 PointD;
  249. U032 MonochromeData1D;
  250. U032 reserved07[(0x080)+120];
  251. struct
  252. {
  253. U032 TopLeft;
  254. U032 BottomRight;
  255. } ClipE;
  256. U032 Color0E;
  257. U032 Color1E;
  258. U032 WidthHeightInE;
  259. U032 WidthHeightOutE;
  260. U032 PointE;
  261. U032 MonochromeData01E;
  262. } RivaBitmap;
  263. /*
  264. * 3D textured, Z buffered triangle.
  265. */
  266. typedef volatile struct
  267. {
  268. U032 reserved00[4];
  269. #ifdef __BIG_ENDIAN
  270. U032 FifoFree;
  271. #else
  272. U016 FifoFree;
  273. U016 Nop;
  274. #endif
  275. U032 reserved01[0x0BC];
  276. U032 TextureOffset;
  277. U032 TextureFormat;
  278. U032 TextureFilter;
  279. U032 FogColor;
  280. /* This is a problem on LynxOS */
  281. #ifdef Control
  282. #undef Control
  283. #endif
  284. U032 Control;
  285. U032 AlphaTest;
  286. U032 reserved02[0x339];
  287. U032 FogAndIndex;
  288. U032 Color;
  289. float ScreenX;
  290. float ScreenY;
  291. float ScreenZ;
  292. float EyeM;
  293. float TextureS;
  294. float TextureT;
  295. } RivaTexturedTriangle03;
  296. typedef volatile struct
  297. {
  298. U032 reserved00[4];
  299. #ifdef __BIG_ENDIAN
  300. U032 FifoFree;
  301. #else
  302. U016 FifoFree;
  303. U016 Nop;
  304. #endif
  305. U032 reserved01[0x0BB];
  306. U032 ColorKey;
  307. U032 TextureOffset;
  308. U032 TextureFormat;
  309. U032 TextureFilter;
  310. U032 Blend;
  311. /* This is a problem on LynxOS */
  312. #ifdef Control
  313. #undef Control
  314. #endif
  315. U032 Control;
  316. U032 FogColor;
  317. U032 reserved02[0x39];
  318. struct
  319. {
  320. float ScreenX;
  321. float ScreenY;
  322. float ScreenZ;
  323. float EyeM;
  324. U032 Color;
  325. U032 Specular;
  326. float TextureS;
  327. float TextureT;
  328. } Vertex[16];
  329. U032 DrawTriangle3D;
  330. } RivaTexturedTriangle05;
  331. /*
  332. * 2D line.
  333. */
  334. typedef volatile struct
  335. {
  336. U032 reserved00[4];
  337. #ifdef __BIG_ENDIAN
  338. U032 FifoFree;
  339. #else
  340. U016 FifoFree;
  341. U016 Nop[1];
  342. #endif
  343. U032 reserved01[0x0BC];
  344. U032 Color; /* source color 0304-0307*/
  345. U032 Reserved02[0x03e];
  346. struct { /* start aliased methods in array 0400- */
  347. U032 point0; /* y_x S16_S16 in pixels 0- 3*/
  348. U032 point1; /* y_x S16_S16 in pixels 4- 7*/
  349. } Lin[16]; /* end of aliased methods in array -047f*/
  350. struct { /* start aliased methods in array 0480- */
  351. U032 point0X; /* in pixels, 0 at left 0- 3*/
  352. U032 point0Y; /* in pixels, 0 at top 4- 7*/
  353. U032 point1X; /* in pixels, 0 at left 8- b*/
  354. U032 point1Y; /* in pixels, 0 at top c- f*/
  355. } Lin32[8]; /* end of aliased methods in array -04ff*/
  356. U032 PolyLin[32]; /* y_x S16_S16 in pixels 0500-057f*/
  357. struct { /* start aliased methods in array 0580- */
  358. U032 x; /* in pixels, 0 at left 0- 3*/
  359. U032 y; /* in pixels, 0 at top 4- 7*/
  360. } PolyLin32[16]; /* end of aliased methods in array -05ff*/
  361. struct { /* start aliased methods in array 0600- */
  362. U032 color; /* source color 0- 3*/
  363. U032 point; /* y_x S16_S16 in pixels 4- 7*/
  364. } ColorPolyLin[16]; /* end of aliased methods in array -067f*/
  365. } RivaLine;
  366. /*
  367. * 2D/3D surfaces
  368. */
  369. typedef volatile struct
  370. {
  371. U032 reserved00[4];
  372. #ifdef __BIG_ENDIAN
  373. U032 FifoFree;
  374. #else
  375. U016 FifoFree;
  376. U016 Nop;
  377. #endif
  378. U032 reserved01[0x0BE];
  379. U032 Offset;
  380. } RivaSurface;
  381. typedef volatile struct
  382. {
  383. U032 reserved00[4];
  384. #ifdef __BIG_ENDIAN
  385. U032 FifoFree;
  386. #else
  387. U016 FifoFree;
  388. U016 Nop;
  389. #endif
  390. U032 reserved01[0x0BD];
  391. U032 Pitch;
  392. U032 RenderBufferOffset;
  393. U032 ZBufferOffset;
  394. } RivaSurface3D;
  395. /***************************************************************************\
  396. * *
  397. * Virtualized RIVA H/W interface. *
  398. * *
  399. \***************************************************************************/
  400. #define FP_ENABLE 1
  401. #define FP_DITHER 2
  402. struct _riva_hw_inst;
  403. struct _riva_hw_state;
  404. /*
  405. * Virtialized chip interface. Makes RIVA 128 and TNT look alike.
  406. */
  407. typedef struct _riva_hw_inst
  408. {
  409. /*
  410. * Chip specific settings.
  411. */
  412. U032 Architecture;
  413. U032 Version;
  414. U032 Chipset;
  415. U032 CrystalFreqKHz;
  416. U032 RamAmountKBytes;
  417. U032 MaxVClockFreqKHz;
  418. U032 RamBandwidthKBytesPerSec;
  419. U032 EnableIRQ;
  420. U032 IO;
  421. U032 VBlankBit;
  422. U032 FifoFreeCount;
  423. U032 FifoEmptyCount;
  424. U032 CursorStart;
  425. U032 flatPanel;
  426. Bool twoHeads;
  427. /*
  428. * Non-FIFO registers.
  429. */
  430. volatile U032 __iomem *PCRTC0;
  431. volatile U032 __iomem *PCRTC;
  432. volatile U032 __iomem *PRAMDAC0;
  433. volatile U032 __iomem *PFB;
  434. volatile U032 __iomem *PFIFO;
  435. volatile U032 __iomem *PGRAPH;
  436. volatile U032 __iomem *PEXTDEV;
  437. volatile U032 __iomem *PTIMER;
  438. volatile U032 __iomem *PMC;
  439. volatile U032 __iomem *PRAMIN;
  440. volatile U032 __iomem *FIFO;
  441. volatile U032 __iomem *CURSOR;
  442. volatile U008 __iomem *PCIO0;
  443. volatile U008 __iomem *PCIO;
  444. volatile U008 __iomem *PVIO;
  445. volatile U008 __iomem *PDIO0;
  446. volatile U008 __iomem *PDIO;
  447. volatile U032 __iomem *PRAMDAC;
  448. /*
  449. * Common chip functions.
  450. */
  451. int (*Busy)(struct _riva_hw_inst *);
  452. void (*LoadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
  453. void (*UnloadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
  454. void (*SetStartAddress)(struct _riva_hw_inst *,U032);
  455. void (*SetSurfaces2D)(struct _riva_hw_inst *,U032,U032);
  456. void (*SetSurfaces3D)(struct _riva_hw_inst *,U032,U032);
  457. int (*ShowHideCursor)(struct _riva_hw_inst *,int);
  458. void (*LockUnlock)(struct _riva_hw_inst *, int);
  459. /*
  460. * Current extended mode settings.
  461. */
  462. struct _riva_hw_state *CurrentState;
  463. /*
  464. * FIFO registers.
  465. */
  466. RivaRop __iomem *Rop;
  467. RivaPattern __iomem *Patt;
  468. RivaClip __iomem *Clip;
  469. RivaPixmap __iomem *Pixmap;
  470. RivaScreenBlt __iomem *Blt;
  471. RivaBitmap __iomem *Bitmap;
  472. RivaLine __iomem *Line;
  473. RivaTexturedTriangle03 __iomem *Tri03;
  474. RivaTexturedTriangle05 __iomem *Tri05;
  475. } RIVA_HW_INST;
  476. /*
  477. * Extended mode state information.
  478. */
  479. typedef struct _riva_hw_state
  480. {
  481. U032 bpp;
  482. U032 width;
  483. U032 height;
  484. U032 interlace;
  485. U032 repaint0;
  486. U032 repaint1;
  487. U032 screen;
  488. U032 scale;
  489. U032 dither;
  490. U032 extra;
  491. U032 pixel;
  492. U032 horiz;
  493. U032 arbitration0;
  494. U032 arbitration1;
  495. U032 vpll;
  496. U032 vpll2;
  497. U032 pllsel;
  498. U032 general;
  499. U032 crtcOwner;
  500. U032 head;
  501. U032 head2;
  502. U032 config;
  503. U032 cursorConfig;
  504. U032 cursor0;
  505. U032 cursor1;
  506. U032 cursor2;
  507. U032 offset0;
  508. U032 offset1;
  509. U032 offset2;
  510. U032 offset3;
  511. U032 pitch0;
  512. U032 pitch1;
  513. U032 pitch2;
  514. U032 pitch3;
  515. } RIVA_HW_STATE;
  516. /*
  517. * function prototypes
  518. */
  519. extern int CalcStateExt
  520. (
  521. RIVA_HW_INST *chip,
  522. RIVA_HW_STATE *state,
  523. int bpp,
  524. int width,
  525. int hDisplaySize,
  526. int height,
  527. int dotClock
  528. );
  529. /*
  530. * External routines.
  531. */
  532. int RivaGetConfig(RIVA_HW_INST *, unsigned int);
  533. /*
  534. * FIFO Free Count. Should attempt to yield processor if RIVA is busy.
  535. */
  536. #define RIVA_FIFO_FREE(hwinst,hwptr,cnt) \
  537. { \
  538. while ((hwinst).FifoFreeCount < (cnt)) { \
  539. mb();mb(); \
  540. (hwinst).FifoFreeCount = NV_RD32(&(hwinst).hwptr->FifoFree, 0) >> 2; \
  541. } \
  542. (hwinst).FifoFreeCount -= (cnt); \
  543. }
  544. #endif /* __RIVA_HW_H__ */