PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/src/xgi.h

#
C Header | 1038 lines | 736 code | 153 blank | 149 comment | 7 complexity | f813e9e1dc1d5fca5525938d99153898 MD5 | raw file
Possible License(s): MIT
  1. /*
  2. * Main global data and definitions
  3. *
  4. * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1) Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2) Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3) The name of the author may not be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * Authors: Thomas Winischhofer <thomas@winischhofer.net>
  29. * others (old code base)
  30. *
  31. */
  32. #ifndef _XGI_H_
  33. #define _XGI_H_
  34. #define DEBUG
  35. #define DEBUG1
  36. #define DEBUG2
  37. #define DEBUG3
  38. #define DEBUG4
  39. #define DEBUG5
  40. /***************
  41. #define DEBUG
  42. #define DEBUG1
  43. #define DEBUG2
  44. #define DEBUG3
  45. #define DEBUG4
  46. #define DEBUG5
  47. #define DEBUGI2C
  48. *****************/
  49. #ifndef XGI_VIDEO_HW /* avoid compile error in xgi_videohw.c; weird! */
  50. /* Jong 07/27/2009; use run-time debug instead except for HW acceleration routines */
  51. extern BOOL g_bRunTimeDebug;
  52. #define RUNTIMEDEBUG(p) if(g_bRunTimeDebug)p;
  53. /* Jong@08052009 */
  54. #ifdef DEBUGI2C
  55. #define PDEBUGI2C(p) p
  56. #else
  57. #define PDEBUGI2C(p)
  58. #endif
  59. #ifdef DEBUG
  60. #define PDEBUG(p) RUNTIMEDEBUG(p)
  61. #else
  62. #define PDEBUG(p)
  63. #endif
  64. #ifdef DEBUG1
  65. #define PDEBUG1(p) RUNTIMEDEBUG(p)
  66. #else
  67. #define PDEBUG1(p)
  68. #endif
  69. #ifdef DEBUG2
  70. #define PDEBUG2(p) RUNTIMEDEBUG(p)
  71. #else
  72. #define PDEBUG2(p)
  73. #endif
  74. #ifdef DEBUG3
  75. #define PDEBUG3(p) RUNTIMEDEBUG(p)
  76. #else
  77. #define PDEBUG3(p)
  78. #endif
  79. #ifdef DEBUG4
  80. #define PDEBUG4(p) RUNTIMEDEBUG(p)
  81. #else
  82. #define PDEBUG4(p)
  83. #endif
  84. #ifdef DEBUG5
  85. #define PDEBUG5(p) RUNTIMEDEBUG(p)
  86. #else
  87. #define PDEBUG5(p)
  88. #endif
  89. #ifdef CDEBUG
  90. #define CPDEBUG(p) p
  91. #else
  92. #define CPDEBUG(p)
  93. #endif
  94. #ifdef CDEBUG1
  95. #define CPDEBUG1(p) p
  96. #else
  97. #define CPDEBUG1(p)
  98. #endif
  99. #ifdef CDEBUG2
  100. #define CPDEBUG2(p) p
  101. #else
  102. #define CPDEBUG2(p)
  103. #endif
  104. #ifdef CDEBUG3
  105. #define CPDEBUG3(p) p
  106. #else
  107. #define CPDEBUG3(p)
  108. #endif
  109. #ifdef CDEBUG4
  110. #define CPDEBUG4(p) p
  111. #else
  112. #define CPDEBUG4(p)
  113. #endif
  114. #ifdef CDEBUG5
  115. #define CPDEBUG5(p) p
  116. #else
  117. #define CPDEBUG5(p)
  118. #endif
  119. #ifdef ACCELDEBUG
  120. #define PACCELDEBUG(p) p
  121. #else
  122. #define PACCELDEBUG(p)
  123. #endif
  124. #endif
  125. /* Always unlock the registers (should be set!) */
  126. #define UNLOCK_ALWAYS
  127. #undef XGI_CP
  128. #ifdef XSERVER_LIBPCIACCESS
  129. #include <pciaccess.h>
  130. #else
  131. #include "xf86Pci.h"
  132. #endif
  133. #include "xf86Cursor.h"
  134. #include "xf86xv.h"
  135. #include "compiler.h"
  136. #ifdef XORG_VERSION_CURRENT
  137. #include "xorgVersion.h"
  138. /* #if XORG_VERSION_CURRENT > XORG_VERSION_NUMERIC(7,0,0,0,0) */
  139. #if ((XORG_VERSION_CURRENT > XORG_VERSION_NUMERIC(7,0,0,0,0)) || (XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(2,0,0,0,0)) )
  140. #define XGIISXORGPOST70
  141. #endif
  142. #if (XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(6,9,0,0,0) )
  143. #define XGI_USE_EXA
  144. #endif
  145. #endif
  146. /* Jong 01/13/2009; support EXA */
  147. #define XGI_USE_XAA
  148. /* #define XGI_USE_EXA */
  149. #ifdef XGI_USE_XAA
  150. #include "xaa.h"
  151. #endif
  152. #ifdef XGI_USE_EXA
  153. #include "exa.h"
  154. #endif
  155. #include "vgaHW.h"
  156. #include "vbe.h"
  157. /*
  158. #ifdef XORG_VERSION_CURRENT
  159. #include "xorgVersion.h"
  160. #endif */
  161. /* #define XGIISXORGPOST70 */
  162. #include "xgi_pci.h"
  163. #include "osdef.h"
  164. #include "vgatypes.h"
  165. #include "vb_struct.h"
  166. #ifdef XF86DRI
  167. #define XGINEWDRI
  168. #undef XGINEWDRI2
  169. #ifdef XF86_VERSION_CURRENT
  170. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,4,99,99,0) /* Adapt this when the time has come */
  171. #define XGINEWDRI2
  172. #endif
  173. #endif /* XF86_VERSION_CURRENT */
  174. #include "xf86drm.h"
  175. #include "sarea.h"
  176. #define _XF86DRI_SERVER_
  177. /* Jong@09032009 */
  178. #ifdef XORG_VERSION_CURRENT
  179. #if ( (XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(6,9,0,0,0)) || (XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(2,0,0,0,0)) )
  180. #include "X11/dri/xf86dri.h"
  181. #else
  182. #include "xf86dri.h"
  183. #endif
  184. #endif
  185. #include "dri.h"
  186. #include "GL/glxint.h"
  187. #include "xgi_dri.h"
  188. #endif
  189. #ifdef XSERVER_LIBPCIACCESS
  190. #define VENDOR_ID(p) (p)->vendor_id
  191. #define DEVICE_ID(p) (p)->device_id
  192. #define SUBSYS_ID(p) (p)->subdevice_id
  193. #define CHIP_REVISION(p) (p)->revision
  194. #else
  195. #define VENDOR_ID(p) (p)->vendor
  196. #define DEVICE_ID(p) (p)->chipType
  197. #define SUBSYS_ID(p) (p)->subsysCard
  198. #define CHIP_REVISION(p) (p)->chipRev
  199. #endif
  200. #if 1
  201. #define XGIDUALHEAD /* Include Dual Head code */
  202. #endif
  203. #if 1
  204. #define XGIMERGED /* Include Merged-FB mode */
  205. #endif
  206. #ifdef XGIMERGED
  207. #if 1
  208. #define XGIXINERAMA /* Include Pseudo-Xinerama for MergedFB mode */
  209. #define XGI_XINERAMA_MAJOR_VERSION 1
  210. #define XGI_XINERAMA_MINOR_VERSION 1
  211. #endif
  212. #endif
  213. #if 1
  214. #define XGIGAMMA /* Include code for gamma correction */
  215. #endif
  216. /* Jong 09/28/2007; disable this because it causes cursor drawing incorrectly */
  217. #if 0 /* Include code for color hardware cursors */
  218. #define XGI_ARGB_CURSOR
  219. #endif
  220. #if 0 /* Include YPbPr support on VB */
  221. #define ENABLE_YPBPR
  222. #endif
  223. #ifdef XGIMERGED
  224. #ifdef XGIXINERAMA
  225. #define EXTENSION_PROC_ARGS void *
  226. #include "extnsionst.h" /* required */
  227. #include <X11/extensions/panoramiXproto.h> /* required */
  228. #endif
  229. #endif
  230. #if 1
  231. #define XGIVRAMQ /* Use VRAM queue mode on 315 series */
  232. #endif
  233. #undef XGI315DRI /* define this if dri is adapted for 315/330 series */
  234. #ifndef PCI_VENDOR_XGI
  235. #define PCI_VENDOR_XGI 0x18CA
  236. #endif
  237. #ifndef PCI_CHIP_XGIXG40
  238. #define PCI_CHIP_XGIXG40 0x0040
  239. #endif
  240. #ifndef PCI_CHIP_XGIXG20
  241. #define PCI_CHIP_XGIXG20 0x0020
  242. #endif
  243. /* Jong 09/18/2007; patch to GIT */
  244. #ifndef PCI_CHIP_XGIXG27
  245. #define PCI_CHIP_XGIXG27 0x0027
  246. #endif
  247. /* Jong 01/07/2008; support New XG21 */
  248. #ifndef PCI_CHIP_XGIXG21
  249. #define PCI_CHIP_XGIXG21 0x0021
  250. #endif
  251. #define CONFIG_DRM_XGI
  252. #define XGI_NAME "XGI"
  253. #define XGI_DRIVER_NAME "xgi"
  254. #define XGI_CURRENT_VERSION ((PACKAGE_VERSION_MAJOR << 16) | \
  255. (PACKAGE_VERSION_MINOR << 8) | \
  256. PACKAGE_VERSION_PATCHLEVEL)
  257. /* pXGI->Flags (old series only) */
  258. #define SYNCDRAM 0x00000001
  259. #define RAMFLAG 0x00000002
  260. #define ESS137xPRESENT 0x00000004
  261. #define SECRETFLAG 0x00000008
  262. #define A6326REVAB 0x00000010
  263. #define MMIOMODE 0x00010000
  264. #define LFBQMODE 0x00020000
  265. #define AGPQMODE 0x00040000
  266. #define UMA 0x80000000
  267. #define BIOS_BASE 0xC0000
  268. #define BIOS_SIZE 0x10000
  269. #define SR_BUFFER_SIZE 5
  270. #define CR_BUFFER_SIZE 5
  271. #define XGI_VBFlagsVersion 1
  272. /* VBFlags - if anything is changed here, increase VBFlagsVersion! */
  273. #define CRT2_DEFAULT 0x00000001
  274. #define CRT2_LCD 0x00000002 /* Never change the order of the CRT2_XXX entries */
  275. #define CRT2_TV 0x00000004
  276. #define CRT2_VGA 0x00000008
  277. #define TV_NTSC 0x00000010
  278. #define TV_PAL 0x00000020
  279. #define TV_HIVISION 0x00000040
  280. #define TV_YPBPR 0x00000080
  281. #define TV_AVIDEO 0x00000100
  282. #define TV_SVIDEO 0x00000200
  283. #define TV_SCART 0x00000400
  284. #define VB_CONEXANT 0x00000800 /* 661 series only */
  285. #define VB_TRUMPION VB_CONEXANT /* 300 series only */
  286. #define TV_PALM 0x00001000
  287. #define TV_PALN 0x00002000
  288. #define TV_NTSCJ 0x00001000
  289. #define VB_302ELV 0x00004000
  290. #define TV_CHSCART 0x00008000
  291. #define TV_CHYPBPR525I 0x00010000
  292. #define CRT1_VGA 0x00000000
  293. #define CRT1_LCDA 0x00020000
  294. #define VGA2_CONNECTED 0x00040000
  295. #define DISPTYPE_CRT1 0x00080000 /* CRT1 connected and used */
  296. #define SINGLE_MODE 0x20000000 /* CRT1 or CRT2; determined by DISPTYPE_CRTx */
  297. #define MIRROR_MODE 0x40000000 /* CRT1 + CRT2 identical (mirror mode) */
  298. #define DUALVIEW_MODE 0x80000000 /* CRT1 + CRT2 independent (dual head mode) */
  299. /* Aliases: */
  300. #define CRT2_ENABLE (CRT2_LCD | CRT2_TV | CRT2_VGA)
  301. #define TV_STANDARD (TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ)
  302. #define TV_INTERFACE (TV_AVIDEO|TV_SVIDEO|TV_SCART|TV_HIVISION|TV_YPBPR)
  303. /* Only if TV_YPBPR is set: */
  304. #define TV_YPBPR525I TV_NTSC
  305. #define TV_YPBPR525P TV_PAL
  306. #define TV_YPBPR750P TV_PALM
  307. #define TV_YPBPR1080I TV_PALN
  308. #define TV_YPBPRALL (TV_YPBPR525I | TV_YPBPR525P | TV_YPBPR750P | TV_YPBPR1080I)
  309. #define TV_YPBPR43LB TV_CHSCART
  310. #define TV_YPBPR43 TV_CHYPBPR525I
  311. #define TV_YPBPR169 (TV_CHSCART | TV_CHYPBPR525I)
  312. #define TV_YPBPRAR (TV_CHSCART | TV_CHYPBPR525I)
  313. #define DISPTYPE_DISP2 CRT2_ENABLE
  314. #define DISPTYPE_DISP1 DISPTYPE_CRT1
  315. #define VB_DISPMODE_SINGLE SINGLE_MODE /* alias */
  316. #define VB_DISPMODE_MIRROR MIRROR_MODE /* alias */
  317. #define VB_DISPMODE_DUAL DUALVIEW_MODE /* alias */
  318. #define DISPLAY_MODE (SINGLE_MODE | MIRROR_MODE | DUALVIEW_MODE)
  319. /* PresetMode argument */
  320. #define XGI_MODE_SIMU 0
  321. #define XGI_MODE_CRT1 1
  322. #define XGI_MODE_CRT2 2
  323. /* pXGI->MiscFlags */
  324. #define MISC_CRT1OVERLAY 0x00000001 /* Current display mode supports overlay */
  325. #define MISC_PANELLINKSCALER 0x00000002 /* Panel link is currently scaling */
  326. #define MISC_CRT1OVERLAYGAMMA 0x00000004 /* Current display mode supports overlay gamma corr on CRT1 */
  327. #define MISC_TVNTSC1024 0x00000008 /* Current display mode is TV NTSC/PALM/YPBPR525I 1024x768 */
  328. #define HW_DEVICE_EXTENSION XGI_HW_DEVICE_INFO
  329. #define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
  330. #define GENMASK(mask) BITMASK(1?mask,0?mask)
  331. typedef unsigned long ULong;
  332. typedef unsigned short UShort;
  333. typedef unsigned char UChar;
  334. /* ChipFlags */
  335. /* Use only lower 16 bit for chip id! (xgictrl) */
  336. #define XGICF_LARGEOVERLAY 0x00000001
  337. #define XGICF_Is651 0x00000002
  338. #define XGICF_IsM650 0x00000004
  339. #define XGICF_IsM652 0x00000008
  340. #define XGICF_IsM653 0x00000010
  341. #define XGICF_Is652 0x00000020
  342. #define XGICF_Is65x (XGICF_Is651|XGICF_IsM650|XGICF_IsM652|XGICF_IsM653|XGICF_Is652)
  343. #define XGICF_IsM661 0x00000100 /* M661FX */
  344. #define XGICF_IsM741 0x00000200
  345. #define XGICF_IsM760 0x00000400
  346. #define XGICF_IsM661M 0x00000800 /* M661MX */
  347. #define XGICF_IsM66x (XGICF_IsM661 | XGICF_IsM741 | XGICF_IsM760 | XGICF_IsM661M)
  348. #define XGICF_315Core 0x00010000 /* 3D: Real 315 */
  349. #define XGICF_Real256ECore 0x00020000 /* 3D: Similar to 315 core, no T&L? (65x, 661, 740, 741) */
  350. #define XGICF_XabreCore 0x00040000 /* 3D: Real Xabre */
  351. #define XGICF_Ultra256Core 0x00080000 /* 3D: Similar to Xabre, no T&L?, no P:Shader? (660, 760) */
  352. #define XGICF_UseLCDA 0x01000000
  353. #define XGICF_760UMA 0x10000000 /* 760: UMA active */
  354. #define XGICF_CRT2HWCKaputt 0x20000000 /* CRT2 Mono HWCursor engine buggy */
  355. #define XGICF_Glamour3 0x40000000
  356. #define XGICF_Integrated 0x80000000
  357. /* Direct Xv-API */
  358. #define XGI_SD_IS300SERIES 0x00000001
  359. #define XGI_SD_IS315SERIES 0x00000002
  360. #define XGI_SD_IS330SERIES 0x00000004
  361. #define XGI_SD_SUPPORTPALMN 0x00000008 /* tv chip supports pal-m, pal-n */
  362. #define XGI_SD_SUPPORT2OVL 0x00000010 /* set = 2 overlays, clear = support SWITCHCRT xv prop */
  363. #define XGI_SD_SUPPORTTVPOS 0x00000020 /* supports changing tv position */
  364. #define XGI_SD_ISDUALHEAD 0x00000040 /* Driver is in dual head mode */
  365. #define XGI_SD_ISMERGEDFB 0x00000080 /* Driver is in merged fb mode */
  366. #define XGI_SD_ISDHSECONDHEAD 0x00000100 /* Dual head: This is CRT1 (=second head) */
  367. #define XGI_SD_ISDHXINERAMA 0x00000200 /* Dual head: We are running Xinerama */
  368. #define XGI_SD_VBHASSCART 0x00000400 /* videobridge has SCART instead of VGA2 */
  369. #define XGI_SD_ISDEPTH8 0x00000800 /* Depth is 8, no independent gamma correction */
  370. #define XGI_SD_ENABLED 0x00002000 /* xgictrl is enabled (by option) */
  371. #define XGI_SD_PSEUDOXINERAMA 0x00004000 /* pseudo xinerama is active */
  372. #define XGI_SD_SUPPORTLCDA 0x00008000 /* Support LCD Channel A */
  373. #define XGI_SD_SUPPORTNTSCJ 0x00010000 /* tv chip supports ntsc-j */
  374. #define XGI_SD_ADDLSUPFLAG 0x00020000 /* 1 = the following flags are valid */
  375. #define XGI_SD_SUPPORTVGA2 0x00040000 /* CRT2=VGA supported */
  376. #define XGI_SD_SUPPORTSCART 0x00080000 /* CRT2=SCART supported */
  377. #define XGI_SD_SUPPORTOVERSCAN 0x00100000 /* Overscan flag supported */
  378. #define XGI_SD_SUPPORTXVGAMMA1 0x00200000 /* Xv Gamma correction for CRT1 supported */
  379. #define XGI_SD_SUPPORTTV 0x00400000 /* CRT2=TV supported */
  380. #define XGI_SD_SUPPORTYPBPR 0x00800000 /* CRT2=YPbPr (525i, 525p, 750p, 1080i) is supported */
  381. #define XGI_SD_SUPPORTHIVISION 0x01000000 /* CRT2=HiVision is supported */
  382. #define XGI_SD_SUPPORTYPBPRAR 0x02000000 /* YPbPr aspect ratio is supported */
  383. #define XGI_SD_SUPPORTSCALE 0x04000000 /* Scaling of LCD panel supported */
  384. #define XGI_SD_SUPPORTCENTER 0x08000000 /* If scaling supported: Centering of screen [NOT] supported (TMDS only) */
  385. #define XGI_DIRECTKEY 0x03145792
  386. /* XGICtrl: Check mode for CRT2 */
  387. #define XGI_CF2_LCD 0x01
  388. #define XGI_CF2_TV 0x02
  389. #define XGI_CF2_VGA2 0x04
  390. #define XGI_CF2_TVPAL 0x08
  391. #define XGI_CF2_TVNTSC 0x10 /* + NTSC-J */
  392. #define XGI_CF2_TVPALM 0x20
  393. #define XGI_CF2_TVPALN 0x40
  394. #define XGI_CF2_CRT1LCDA 0x80
  395. #define XGI_CF2_TYPEMASK (XGI_CF2_LCD | XGI_CF2_TV | XGI_CF2_VGA2 | XGI_CF2_CRT1LCDA)
  396. #define XGI_CF2_TVSPECIAL (XGI_CF2_LCD | XGI_CF2_TV)
  397. #define XGI_CF2_TVSPECMASK (XGI_CF2_TVPAL | XGI_CF2_TVNTSC | XGI_CF2_TVPALM | XGI_CF2_TVPALN)
  398. #define XGI_CF2_TVHIVISION XGI_CF2_TVPAL
  399. #define XGI_CF2_TVYPBPR525I XGI_CF2_TVNTSC
  400. #define XGI_CF2_TVYPBPR525P (XGI_CF2_TVPAL | XGI_CF2_TVNTSC)
  401. #define XGI_CF2_TVYPBPR750P XGI_CF2_TVPALM
  402. #define XGI_CF2_TVYPBPR1080I (XGI_CF2_TVPALM | XGI_CF2_TVPAL)
  403. /* AGP stuff for DRI */
  404. #define AGP_PAGE_SIZE 4096
  405. #define AGP_PAGES 2048 /* Default: 2048 pages @ 4096 = 8MB */
  406. /* 300 */
  407. #define AGP_CMDBUF_PAGES 256
  408. #define AGP_CMDBUF_SIZE (AGP_PAGE_SIZE * AGP_CMDBUF_PAGES)
  409. /* 315/330 */
  410. #define AGP_VTXBUF_PAGES 512
  411. #define AGP_VTXBUF_SIZE (AGP_PAGE_SIZE * AGP_VTXBUF_PAGES)
  412. #define VOLARI_CQSIZE (1024*1024)
  413. #define VOLARI_CQSIZEXG20 (128*1024)
  414. #define VOLARI_CURSOR_SHAPE_SIZE (64*64*4)
  415. /* For backup of register contents */
  416. typedef struct {
  417. unsigned char xgiRegs3C4[0x50];
  418. unsigned char xgiRegs3D4[0x90];
  419. unsigned char xgiRegs3C2;
  420. unsigned char xgiCapt[0x60];
  421. unsigned char xgiVid[0x50];
  422. unsigned char VBPart1[0x50];
  423. unsigned char VBPart2[0x100];
  424. unsigned char VBPart3[0x50];
  425. unsigned char VBPart4[0x50];
  426. unsigned short ch70xx[64];
  427. unsigned long xgiMMIO85C0;
  428. unsigned char xgi6326tv[0x46];
  429. unsigned long xgiRegsPCI50, xgiRegsPCIA0;
  430. } XGIRegRec, *XGIRegPtr;
  431. /* XGIFBLayout is mainly there because of DGA. It holds the
  432. * current layout parameters needed for acceleration and other
  433. * stuff. When switching mode using DGA, these are set up
  434. * accordingly and not necessarily match pScrn's. Therefore,
  435. * driver modules should read these values instead of pScrn's.
  436. */
  437. typedef struct {
  438. int bitsPerPixel; /* = pScrn->bitsPerPixel */
  439. int depth; /* = pScrn->depth */
  440. int displayWidth; /* = pScrn->displayWidth */
  441. DisplayModePtr mode; /* = pScrn->currentMode */
  442. } XGIFBLayout;
  443. /* Dual head private entity structure */
  444. typedef struct {
  445. ScrnInfoPtr pScrn_1;
  446. ScrnInfoPtr pScrn_2;
  447. unsigned char * BIOS;
  448. VB_DEVICE_INFO *XGI_Pr;
  449. int CRT2ModeNo; /* Current display mode for CRT2 */
  450. Bool CRT2ModeSet; /* CRT2 mode has been set */
  451. unsigned char CRT2CR30, CRT2CR31, CRT2CR35, CRT2CR38;
  452. int refCount;
  453. /**
  454. * Number of entities
  455. *
  456. * \bug
  457. * This field is tested in one place, but it doesn't appear to ever be
  458. * set or modified.
  459. */
  460. int lastInstance;
  461. Bool DisableDual; /* Emergency flag */
  462. Bool ErrorAfterFirst; /* Emergency flag: Error after first init -> Abort second */
  463. int maxUsedClock; /* Max used pixelclock on master head */
  464. /**
  465. * Framebuffer addresses and sizes
  466. *
  467. * \bug
  468. * These 4 fields are set, but the stored values don't appear to be used.
  469. */
  470. unsigned long masterFbAddress;
  471. unsigned long masterFbSize;
  472. unsigned long slaveFbAddress;
  473. unsigned long slaveFbSize;
  474. unsigned char * FbBase; /* VRAM linear address */
  475. unsigned char * IOBase; /* MMIO linear address */
  476. /**
  477. * Map / unmap queue counter.
  478. *
  479. * \bug
  480. * These vales are tested, set to zero, or decremented. However, I don't
  481. * see anywhere in the code where they are incremented.
  482. */
  483. unsigned short MapCountIOBase;
  484. unsigned short MapCountFbBase;
  485. Bool forceUnmapIOBase; /* ignore counter and unmap */
  486. Bool forceUnmapFbBase; /* ignore counter and unmap */
  487. #ifdef __alpha__
  488. unsigned char * IOBaseDense; /* MMIO for Alpha platform */
  489. unsigned short MapCountIOBaseDense;
  490. Bool forceUnmapIOBaseDense; /* ignore counter and unmap */
  491. #endif
  492. BOOLEAN CRT1gamma;
  493. /**
  494. * \bug This field is tested and set to \c NULL but never used.
  495. */
  496. unsigned char *RenderAccelArray;
  497. unsigned char * FbBase1;
  498. unsigned long OnScreenSize1;
  499. #ifdef XGI_CP
  500. XGI_CP_H_ENT
  501. #endif
  502. } XGIEntRec, *XGIEntPtr;
  503. #define XGIPTR(p) ((XGIPtr)((p)->driverPrivate))
  504. #define XAAPTR(p) ((XAAInfoRecPtr)(XGIPTR(p)->AccelInfoPtr))
  505. #define ExtRegSize 0x40
  506. /* Relative merge position */
  507. typedef enum {
  508. xgiLeftOf,
  509. xgiRightOf,
  510. xgiAbove,
  511. xgiBelow,
  512. xgiClone
  513. } XGIScrn2Rel;
  514. typedef struct MonitorRange {
  515. float loH,hiH,loV,hiV ;
  516. }MonitorRangeRec,*MonitorRangePtr ;
  517. typedef struct {
  518. ScrnInfoPtr pScrn; /* -------------- DON'T INSERT ANYTHING HERE --------------- */
  519. #ifdef XSERVER_LIBPCIACCESS
  520. struct pci_device * PciInfo;
  521. #else
  522. pciVideoPtr PciInfo; /* -------- OTHERWISE xgi_dri.so MUST BE RECOMPILED -------- */
  523. PCITAG PciTag;
  524. #endif
  525. EntityInfoPtr pEnt;
  526. int Chipset;
  527. int ChipRev;
  528. VB_DEVICE_INFO *XGI_Pr; /* For new mode switching code */
  529. unsigned long FbAddress; /* VRAM physical address (in DHM: for each Fb!) */
  530. unsigned long realFbAddress; /* For DHM/PCI mem mapping: store global FBAddress */
  531. unsigned char * FbBase; /* VRAM virtual linear address */
  532. CARD32 IOAddress; /* MMIO physical address */
  533. unsigned char * IOBase; /* MMIO linear address */
  534. unsigned long IODBase; /* Base of PIO memory area */
  535. #ifdef __alpha__
  536. unsigned char * IOBaseDense; /* MMIO for Alpha platform */
  537. #endif
  538. XGIIOADDRESS RelIO; /* Relocated IO Ports baseaddress */
  539. unsigned char * BIOS;
  540. int MemClock;
  541. int BusWidth;
  542. int MinClock;
  543. int MaxClock;
  544. int Flags; /* HW config flags */
  545. long FbMapSize; /* Used for Mem Mapping - DON'T CHANGE THIS */
  546. long availMem; /* Really available Fb mem (minus TQ, HWCursor) */
  547. unsigned long maxxfbmem; /* limit fb memory X is to use to this (KB) */
  548. unsigned long xgifbMem; /* heapstart of xgifb (if running) */
  549. unsigned long dhmOffset; /* Offset to memory for each head (0 or ..) */
  550. DGAModePtr DGAModes;
  551. int numDGAModes;
  552. Bool DGAactive;
  553. Bool NoAccel;
  554. Bool useEXA; /* Jong 01/13/2009; support EXA */
  555. Bool NoXvideo;
  556. Bool TurboQueue;
  557. int ForceCRT1Type;
  558. int ForceCRT2Type;
  559. int OptROMUsage;
  560. Bool ValidWidth;
  561. unsigned char myCR63;
  562. unsigned long VBFlags; /* Video bridge configuration */
  563. unsigned long VBFlags_backup; /* Backup for SlaveMode-modes */
  564. short scrnOffset; /* Screen pitch (data) */
  565. short scrnPitch; /* Screen pitch (display; regarding interlace) */
  566. unsigned long DstColor;
  567. int xcurrent; /* for temp use in accel */
  568. int ycurrent; /* for temp use in accel */
  569. int CommandReg;
  570. Bool HWCursor;
  571. CARD16 CursorSize; /* Size of HWCursor area (bytes) */
  572. xf86CursorInfoPtr CursorInfoPtr;
  573. unsigned CursorOffset;
  574. /**
  575. * \bug This field is set to \c FALSE but never used.
  576. */
  577. Bool DoColorExpand;
  578. XGIRegRec SavedReg;
  579. XGIRegRec ModeReg;
  580. #ifdef XGI_USE_XAA
  581. XAAInfoRecPtr AccelInfoPtr;
  582. #endif
  583. #ifdef XGI_USE_EXA /* Jong 01/13/2009; support EXA */
  584. ExaDriverPtr EXADriverPtr;
  585. int fillPitch, fillBpp;
  586. CARD32 fillDstBase;
  587. int copyBpp;
  588. int copySPitch, copyDPitch;
  589. CARD32 copySrcBase, copyDstBase;
  590. int copyXdir, copyYdir;
  591. ExaOffscreenArea* exa_scratch;
  592. unsigned int exa_scratch_next;
  593. #endif
  594. CloseScreenProcPtr CloseScreen;
  595. Bool (*ModeInit)(ScrnInfoPtr pScrn, DisplayModePtr mode);
  596. void (*XGISave)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
  597. void (*XGISave2)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
  598. void (*XGISave3)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
  599. void (*XGIRestore)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
  600. void (*XGIRestore2)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
  601. void (*XGIRestore3)(ScrnInfoPtr pScrn, XGIRegPtr xgireg);
  602. void (*LoadCRT2Palette)(ScrnInfoPtr pScrn, int numColors,
  603. int *indicies, LOCO *colors, VisualPtr pVisual);
  604. int cmdQueueLen; /* Current cmdQueueLength (for 2D and 3D) */
  605. unsigned long cmdQueueLenMax;
  606. unsigned long cmdQueueLenMin;
  607. unsigned char *cmdQueueBase;
  608. int *cmdQueueLenPtr; /* Ptr to variable holding the current queue length */
  609. unsigned int cmdQueueOffset;
  610. unsigned int cmdQueueSize;
  611. unsigned long cmdQueueSizeMask;
  612. /**
  613. * \bug This field is set but never used.
  614. */
  615. unsigned int agpWantedPages;
  616. #ifdef XF86DRI
  617. unsigned long agpHandle;
  618. unsigned long agpAddr;
  619. unsigned char *agpBase;
  620. unsigned int agpSize;
  621. unsigned long agpVtxBufAddr; /* 315 series */
  622. unsigned char *agpVtxBufBase;
  623. unsigned int agpVtxBufSize;
  624. unsigned int agpVtxBufFree;
  625. xgiRegion agp;
  626. Bool irqEnabled;
  627. int irq;
  628. #endif
  629. unsigned long DRIheapstart, DRIheapend;
  630. void (*RenderCallback)(ScrnInfoPtr);
  631. /**
  632. * \bug This field is tested and set to \c NULL but never used.
  633. */
  634. unsigned char *RenderAccelArray;
  635. /**
  636. * \bug This field is to \c TRUE but never used.
  637. */
  638. Bool doRender;
  639. int PerColorExpandBufferSize;
  640. int ColorExpandBufferNumber;
  641. unsigned char *ColorExpandBufferAddr[32];
  642. int ColorExpandBufferScreenOffset[32];
  643. /**
  644. * \bug This field is read but never initialized.
  645. */
  646. int ImageWriteBufferSize;
  647. unsigned char *ImageWriteBufferAddr;
  648. int Rotate;
  649. BOOLEAN HaveCustomModes; /* Jong 07/27/2009; support customer modes */
  650. /* ShadowFB support */
  651. Bool ShadowFB;
  652. unsigned char *ShadowPtr;
  653. int ShadowPitch;
  654. /**
  655. * \bug This field is set but never used.
  656. */
  657. Bool loadDRI;
  658. #ifdef XF86DRI
  659. Bool directRenderingEnabled;
  660. DRIInfoPtr pDRIInfo;
  661. int drmSubFD;
  662. int numVisualConfigs;
  663. __GLXvisualConfig* pVisualConfigs;
  664. XGIConfigPrivPtr pVisualConfigsPriv;
  665. #endif
  666. HW_DEVICE_EXTENSION xgi_HwDevExt; /* For new mode switching code */
  667. XF86VideoAdaptorPtr adaptor;
  668. ScreenBlockHandlerProcPtr BlockHandler;
  669. /**
  670. * \bug This field is tested and used but never set.
  671. */
  672. void (*VideoTimerCallback)(ScrnInfoPtr, Time);
  673. void (*ResetXv)(ScrnInfoPtr);
  674. void (*ResetXvGamma)(ScrnInfoPtr);
  675. OptionInfoPtr Options;
  676. /**
  677. * \bug This field is used but never initialized.
  678. */
  679. unsigned char LCDon;
  680. Bool Blank;
  681. int CRT1off; /* 1=CRT1 off, 0=CRT1 on */
  682. CARD16 LCDheight; /* Vertical resolution of LCD panel */
  683. CARD16 LCDwidth; /* Horizontal resolution of LCD panel */
  684. vbeInfoPtr pVbe; /* For VESA mode switching */
  685. UCHAR ScratchSet[16];
  686. MonitorRangeRec CRT1Range,CRT2Range;
  687. #ifdef XGIDUALHEAD
  688. BOOL DualHeadMode; /* TRUE if we use dual head mode */
  689. BOOL SecondHead; /* TRUE is this is the second head */
  690. XGIEntPtr entityPrivate; /* Ptr to private entity (see above) */
  691. #endif
  692. XGIFBLayout CurrentLayout; /* Current framebuffer layout */
  693. BOOL Primary; /* Display adapter is primary */
  694. xf86Int10InfoPtr pInt; /* Our int10 */
  695. /**
  696. * Use our own default modes?
  697. *
  698. * \bug This field is set but never used.
  699. */
  700. Bool noInternalModes;
  701. int ForceTVType, SenseYPbPr;
  702. int NonDefaultPAL, NonDefaultNTSC;
  703. unsigned long ForceYPbPrType, ForceYPbPrAR;
  704. unsigned long lockcalls; /* Count unlock calls for debug */
  705. Atom xvBrightness, xvContrast, xvColorKey, xvHue, xvSaturation;
  706. Atom xvAutopaintColorKey, xvSetDefaults, xvSwitchCRT;
  707. Atom xvDisableGfx, xvDisableGfxLR, xvTVXPosition, xvTVYPosition;
  708. Atom xvDisableColorkey, xvUseChromakey, xvChromaMin, xvChromaMax;
  709. Atom xvInsideChromakey, xvYUVChromakey;
  710. Atom xvGammaRed, xvGammaGreen, xvGammaBlue;
  711. #ifdef XGI_CP
  712. XGI_CP_H
  713. #endif
  714. unsigned long ChipFlags;
  715. unsigned long XGI_SD_Flags;
  716. BOOLEAN UseHWARGBCursor;
  717. BOOLEAN HWARGBCursor;
  718. int vb;
  719. BOOLEAN restorebyset;
  720. BOOLEAN nocrt2ddcdetection;
  721. BOOLEAN forcecrt2redetection;
  722. BOOLEAN CRT1gamma, CRT1gammaGiven, CRT2gamma, XvGamma, XvGammaGiven;
  723. int XvDefCon, XvDefBri, XvDefHue, XvDefSat;
  724. BOOLEAN XvDefDisableGfx, XvDefDisableGfxLR;
  725. BOOLEAN XvUseMemcpy;
  726. int XvGammaRed, XvGammaGreen, XvGammaBlue;
  727. CARD8 XvGammaRampRed[256], XvGammaRampGreen[256], XvGammaRampBlue[256];
  728. BOOLEAN disablecolorkeycurrent;
  729. CARD32 colorKey;
  730. CARD32 MiscFlags;
  731. #ifdef XGI_USE_XAA
  732. FBLinearPtr AccelLinearScratch;
  733. #endif
  734. float zClearVal;
  735. unsigned long bClrColor, dwColor;
  736. int AllowHotkey;
  737. BOOLEAN enablexgictrl;
  738. short Video_MaxWidth, Video_MaxHeight;
  739. short scrnPitch2;
  740. int CurXPreset ;
  741. int CurYPreset ;
  742. unsigned long mmioSize;
  743. #ifdef XGIMERGED
  744. Bool MergedFB, MergedFBAuto;
  745. XGIScrn2Rel CRT2Position;
  746. char * CRT2HSync;
  747. char * CRT2VRefresh;
  748. char * MetaModes;
  749. ScrnInfoPtr CRT2pScrn;
  750. DisplayModePtr CRT1Modes;
  751. DisplayModePtr CRT1CurrentMode;
  752. int CRT1frameX0;
  753. int CRT1frameY0;
  754. int CRT1frameX1;
  755. int CRT1frameY1;
  756. Bool CheckForCRT2;
  757. int MergedFBXDPI, MergedFBYDPI;
  758. #ifdef XGIXINERAMA
  759. Bool UsexgiXinerama;
  760. Bool CRT2IsScrn0;
  761. ExtensionEntry *XineramaExtEntry;
  762. int xgiXineramaVX, xgiXineramaVY;
  763. Bool AtLeastOneNonClone;
  764. #endif
  765. #endif
  766. /* Added for 3D */
  767. unsigned long cmdQueue_shareWP_only2D;
  768. unsigned long *pCQ_shareWritePort;
  769. void (*SetThreshold)(ScrnInfoPtr pScrn, DisplayModePtr mode,
  770. unsigned short *Low, unsigned short *High);
  771. XGI_DSReg SRList[ExtRegSize] ;
  772. XGI_DSReg CRList[ExtRegSize] ;
  773. /**
  774. * Total number of iterations to wait in \c Volari_Idle.
  775. */
  776. unsigned int idle_wait_count;
  777. //:::: for capture
  778. Bool v4l_videoin;
  779. int v4l_devnum; /* v4l device number, 0,1,2....*/
  780. //~::::
  781. int TargetRefreshRate;
  782. Bool IgnoreDDC;
  783. Bool Non_DDC_DefaultMode;
  784. int Non_DDC_DefaultResolutionX ;
  785. int Non_DDC_DefaultResolutionY ;
  786. int Non_DDC_DefaultRefreshRate ;
  787. } XGIRec, *XGIPtr;
  788. #ifdef XGIDUALHEAD
  789. # define IS_DUAL_HEAD(x) ((x)->DualHeadMode)
  790. # define IS_SECOND_HEAD(x) ((x)->SecondHead)
  791. # define ENTITY_PRIVATE(x) ((x)->entityPrivate)
  792. #else
  793. # define IS_DUAL_HEAD(x) FALSE
  794. # define IS_SECOND_HEAD(x) FALSE
  795. # define ENTITY_PRIVATE(x) NULL
  796. #endif
  797. #define SEQ_ADDRESS_PORT 0x0014
  798. #define MISC_OUTPUT_REG_WRITE_PORT 0x0012
  799. #define MISC_OUTPUT_REG_READ_PORT 0x001C
  800. #define GRAPH_ADDRESS_PORT 0x001E
  801. #define VIDEO_SUBSYSTEM_ENABLE_PORT 0x0013
  802. #define CRTC_ADDRESS_PORT_COLOR 0x0024
  803. #define PCI_COMMAND 0x04
  804. #define SDMPTR(x) ((XGIMergedDisplayModePtr)(x->currentMode->Private))
  805. #define CDMPTR ((XGIMergedDisplayModePtr)(pXGI->CurrentLayout.mode->Private))
  806. #define BOUND(test,low,hi) { \
  807. if(test < low) test = low; \
  808. if(test > hi) test = hi; }
  809. #define REBOUND(low,hi,test) { \
  810. if(test < low) { \
  811. hi += test-low; \
  812. low = test; } \
  813. if(test > hi) { \
  814. low += test-hi; \
  815. hi = test; } }
  816. typedef struct _MergedDisplayModeRec {
  817. DisplayModePtr CRT1;
  818. DisplayModePtr CRT2;
  819. XGIScrn2Rel CRT2Position;
  820. } XGIMergedDisplayModeRec, *XGIMergedDisplayModePtr;
  821. typedef struct _region {
  822. int x0,x1,y0,y1;
  823. } region;
  824. extern void xgiOptions(ScrnInfoPtr pScrn);
  825. extern const OptionInfoRec * XGIAvailableOptions(int chipid, int busid);
  826. extern void XGISetup(ScrnInfoPtr pScrn);
  827. extern void XGIVGAPreInit(ScrnInfoPtr pScrn);
  828. extern Bool XGIAccelInit(ScreenPtr pScreen);
  829. extern Bool XGIHWCursorInit(ScreenPtr pScreen);
  830. extern Bool XGIDGAInit(ScreenPtr pScreen);
  831. extern void XGIInitVideo(ScreenPtr pScreen);
  832. extern int XGI_GetCHTVlumabandwidthcvbs(ScrnInfoPtr pScrn);
  833. int XG40Mclk(XGIPtr pXGI);
  834. void XGINew_InitVBIOSData(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo) ;
  835. int compute_vclk(int Clock, int *out_n, int *out_dn, int *out_div,
  836. int *out_sbit, int *out_scale);
  837. void XGI_WaitBeginRetrace(XGIIOADDRESS RelIO);
  838. void XGI_WaitEndRetrace(XGIIOADDRESS RelIO);
  839. #include <unistd.h>
  840. /* 2005/11/21 added by jjtseng */
  841. #define DelayS(sec) usleep((sec)*1000000)
  842. #define DelayMS(millisec) usleep((millisec)*1000)
  843. #define DelayUS(microsec) usleep((microsec))
  844. /*~jjtseng 2005/11/21 */
  845. Bool Volari_AccelInit(ScreenPtr pScreen) ;
  846. /* void XGI_UnLockCRT2(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
  847. /* void XGI_LockCRT2(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
  848. /* void XGI_DisableBridge(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
  849. /* void XGI_EnableBridge(PXGI_HW_DEVICE_INFO,USHORT BaseAddr); */
  850. #endif
  851. extern USHORT XGI_GetModeID(ULONG VBFlags, int HDisplay, int VDisplay,
  852. int Depth, int LCDwith, int LCDheight);
  853. extern BOOLEAN XGI_SearchModeID(const XGI_StStruct *SModeIDTable,
  854. const XGI_ExtStruct *EModeIDTable, unsigned char VGAINFO,
  855. USHORT *ModeNo, USHORT *ModeIdIndex);
  856. extern UCHAR XGI_GetModePtr(const XGI_StStruct *SModeIDTable,
  857. unsigned ModeType, USHORT ModeNo, USHORT ModeIdIndex);
  858. extern void XGI_SetReg(XGIIOADDRESS port, USHORT index, USHORT data);
  859. extern void XGI_SetRegByte(XGIIOADDRESS port, USHORT data);
  860. extern void XGI_SetRegShort(XGIIOADDRESS port, USHORT data);
  861. extern void XGI_SetRegLong(XGIIOADDRESS port, ULONG data);
  862. extern UCHAR XGI_GetReg(XGIIOADDRESS port, USHORT index);
  863. extern UCHAR XGI_GetRegByte(XGIIOADDRESS port);
  864. extern USHORT XGI_GetRegShort(XGIIOADDRESS port);
  865. extern ULONG XGI_GetRegLong(XGIIOADDRESS port);
  866. extern void XGI_SetRegANDOR(XGIIOADDRESS Port, USHORT Index, USHORT DataAND,
  867. USHORT DataOR);
  868. extern void XGI_SetRegAND(XGIIOADDRESS Port, USHORT Index, USHORT DataAND);
  869. extern void XGI_SetRegOR(XGIIOADDRESS Port, USHORT Index, USHORT DataOR);
  870. #define uint8_t CARD8
  871. extern void XGI_WriteDAC(XGIIOADDRESS dac_data, unsigned shift,
  872. unsigned ordering, uint8_t red, uint8_t green, uint8_t blue);
  873. #ifdef DEBUG
  874. void XGIDumpRegs(ScrnInfoPtr pScrn);
  875. /**
  876. * Write value to the PC's 0x80 debug port.
  877. *
  878. * \bug
  879. * I'm pretty sure the debug 0x80 only exists on PCs. Should this routine
  880. * be a no-op on non-x86 and non-x86-64 architectures?
  881. */
  882. #define Newdebugcode(dbg_code) outb(0x80, dbg_code)
  883. #else
  884. #define Newdebugcode(dbg_code)
  885. #endif