Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

421 lines
15 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: p3rd.h
  8. *
  9. * Content: This module contains the definitions for the P2ST internal RAMDAC.
  10. *
  11. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-2003 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #define VideoDebugPrint
  15. //
  16. // 3Dlabs P3RD RAMDAC definitions
  17. // This set of registers resides at &(pCtrlRegs->ExternalVideo)
  18. //
  19. typedef struct _p3rd_regs
  20. {
  21. RAMDAC_REG RDPaletteWriteAddress;
  22. RAMDAC_REG RDPaletteData;
  23. RAMDAC_REG RDPixelMask;
  24. RAMDAC_REG RDPaletteAddressRead;
  25. RAMDAC_REG RDIndexLow;
  26. RAMDAC_REG RDIndexHigh;
  27. RAMDAC_REG RDIndexedData;
  28. RAMDAC_REG RDIndexControl;
  29. } P3RDRAMDAC, *pP3RDRAMDAC;
  30. // structure containing the mapped addresses for each of the P3RD registers.
  31. // We need this since some chips like the Alpha cannot be accessed by simply
  32. // writing to the memory mapped register. So instead we set up the following
  33. // struct of memory addresses at init time and use these instead. All these
  34. // addresses must be passed to WRITE/READ_FAST_ULONG.
  35. // We also keep software copies of various registers in here so we can turn
  36. // on and off individual bits more easily.
  37. //
  38. typedef struct _p3rd_data {
  39. // register addresses
  40. ULONG * RDPaletteWriteAddress;
  41. ULONG * RDPaletteData;
  42. ULONG * RDPixelMask;
  43. ULONG * RDPaletteAddressRead;
  44. ULONG * RDIndexLow;
  45. ULONG * RDIndexHigh;
  46. ULONG * RDIndexedData;
  47. ULONG * RDIndexControl;
  48. // RAMDAC state info
  49. ULONG cursorModeOff; // cursor disabled
  50. ULONG cursorModeCurrent; // disabled 32/64 mode cursor
  51. ULONG cursorControl; // x & y zoom, etc.
  52. ULONG cursorSize; // see P3RD_CURSOR_SIZE_*
  53. ULONG x, y;
  54. } P3RDData, *pP3RDData;
  55. // macro declared by any function wishing to use the P2ST internal RAMDAC . MUST be declared
  56. // after GLINT_DECL.
  57. //
  58. #define P3RD_DECL_VARS pP3RDData pP3RDinfo
  59. #define P3RD_DECL_INIT pP3RDinfo = (pP3RDData)(ppdev->pvPointerData = &ppdev->ajPointerData[0])
  60. #define P3RD_DECL \
  61. P3RD_DECL_VARS; \
  62. P3RD_DECL_INIT
  63. // use the following macros as the address to pass to the
  64. // WRITE_P3RDREG_ULONG function
  65. //
  66. // Palette Access
  67. #define P3RD_PAL_WR_ADDR (pP3RDinfo->RDPaletteWriteAddress)
  68. #define P3RD_PAL_RD_ADDR (pP3RDinfo->RDPaletteAddressRead)
  69. #define P3RD_PAL_DATA (pP3RDinfo->RDPaletteData)
  70. // Pixel mask
  71. #define P3RD_PIXEL_MASK (pP3RDinfo->RDPixelMask)
  72. // Access to the indexed registers
  73. #define P3RD_INDEX_ADDR_LO (pP3RDinfo->RDIndexLow)
  74. #define P3RD_INDEX_ADDR_HI (pP3RDinfo->RDIndexHigh)
  75. #define P3RD_INDEX_DATA (pP3RDinfo->RDIndexedData)
  76. #define P3RD_INDEX_CONTROL (pP3RDinfo->RDIndexControl)
  77. // bit field definitions for the direct access registers
  78. #define P3RD_IDX_CTL_AUTOINCREMENT_ENABLED 0x01
  79. // indexed register definitions accessed via P3RD_LOAD_INDEX_REG() and P3RD_READ_INDEX_REG()
  80. #define P3RD_MISC_CONTROL 0x0000
  81. #define P3RD_SYNC_CONTROL 0x0001
  82. #define P3RD_DAC_CONTROL 0x0002
  83. #define P3RD_PIXEL_SIZE 0x0003
  84. #define P3RD_COLOR_FORMAT 0x0004
  85. #define P3RD_CURSOR_MODE 0x0005
  86. #define P3RD_CURSOR_CONTROL 0x0006
  87. #define P3RD_CURSOR_X_LOW 0x0007
  88. #define P3RD_CURSOR_X_HIGH 0x0008
  89. #define P3RD_CURSOR_Y_LOW 0x0009
  90. #define P3RD_CURSOR_Y_HIGH 0x000a
  91. #define P3RD_CURSOR_HOTSPOT_X 0x000b
  92. #define P3RD_CURSOR_HOTSPOT_Y 0x000c
  93. #define P3RD_OVERLAY_KEY 0x000d
  94. #define P3RD_PAN 0x000e
  95. #define P3RD_SENSE 0x000f
  96. #define P3RD_CHECK_CONTROL 0x0018
  97. #define P3RD_CHECK_PIXEL_RED 0x0019
  98. #define P3RD_CHECK_PIXEL_GREEN 0x001a
  99. #define P3RD_CHECK_PIXEL_BLUE 0x001b
  100. #define P3RD_CHECK_LUT_RED 0x001c
  101. #define P3RD_CHECK_LUT_GREEN 0x001d
  102. #define P3RD_CHECK_LUT_BLUE 0x001e
  103. #define P3RD_DCLK_SETUP_1 0x01f0
  104. #define P3RD_DCLK_SETUP_2 0x01f1
  105. #define P3RD_MCLK_SETUP_1 0x01f2
  106. #define P3RD_MCLK_SETUP_2 0x01f3
  107. #define P3RD_DCLK_CONTROL 0x0200
  108. #define P3RD_DCLK0_PRE_SCALE 0x0201
  109. #define P3RD_DCLK0_FEEDBACK_SCALE 0x0202
  110. #define P3RD_DCLK0_POST_SCALE 0x0203
  111. #define P3RD_DCLK1_PRE_SCALE 0x0204
  112. #define P3RD_DCLK1_FEEDBACK_SCALE 0x0205
  113. #define P3RD_DCLK1_POST_SCALE 0x0206
  114. #define P3RD_DCLK2_PRE_SCALE 0x0207
  115. #define P3RD_DCLK2_FEEDBACK_SCALE 0x0208
  116. #define P3RD_DCLK2_POST_SCALE 0x0209
  117. #define P3RD_DCLK3_PRE_SCALE 0x020a
  118. #define P3RD_DCLK3_FEEDBACK_SCALE 0x020b
  119. #define P3RD_DCLK3_POST_SCALE 0x020c
  120. #define P3RD_MCLK_CONTROL 0x020d
  121. #define P3RD_MCLK_PRE_SCALE 0x020e
  122. #define P3RD_MCLK_FEEDBACK_SCALE 0x020f
  123. #define P3RD_MCLK_POST_SCALE 0x0210
  124. #define P3RD_CURSOR_PALETTE_START 0x0303 // 303..32f
  125. #define P3RD_CURSOR_PATTERN_START 0x0400 // 400..7ff
  126. // bit field definitions for the indexed registers
  127. #define P3RD_MISC_CONTROL_OVERLAYS_ENABLED 0x10
  128. #define P3RD_MISC_CONTROL_DIRECT_COLOR_ENABLED 0x08
  129. #define P3RD_MISC_CONTROL_HIGHCOLORRES 0x01
  130. #define P3RD_SYNC_CONTROL_VSYNC_ACTIVE_LOW 0x00
  131. #define P3RD_SYNC_CONTROL_HSYNC_ACTIVE_LOW 0x00
  132. #define P3RD_DAC_CONTROL_BLANK_PEDESTAL_ENABLED 0x80
  133. #define P3RD_PIXEL_SIZE_8BPP 0x00
  134. #define P3RD_PIXEL_SIZE_16BPP 0x01
  135. #define P3RD_PIXEL_SIZE_24_BPP 0x04
  136. #define P3RD_PIXEL_SIZE_32BPP 0x02
  137. #define P3RD_COLOR_FORMAT_CI8 0x0e
  138. #define P3RD_COLOR_FORMAT_8BPP 0x05
  139. #define P3RD_COLOR_FORMAT_15BPP 0x01
  140. #define P3RD_COLOR_FORMAT_16BPP 0x10
  141. #define P3RD_COLOR_FORMAT_32BPP 0x00
  142. #define P3RD_COLOR_FORMAT_LINEAR_EXT 0x40
  143. #define P3RD_CURSOR_MODE_REVERSE 0x40
  144. #define P3RD_CURSOR_MODE_WINDOWS 0x00
  145. #define P3RD_CURSOR_MODE_X 0x10
  146. #define P3RD_CURSOR_MODE_3COLOR 0x20
  147. #define P3RD_CURSOR_MODE_15COLOR 0x30
  148. #define P3RD_CURSOR_MODE_64x64 0x00
  149. #define P3RD_CURSOR_MODE_P0_32x32x2 0x02
  150. #define P3RD_CURSOR_MODE_P1_32x32x2 0x04
  151. #define P3RD_CURSOR_MODE_P2_32x32x2 0x06
  152. #define P3RD_CURSOR_MODE_P3_32x32x2 0x08
  153. #define P3RD_CURSOR_MODE_P01_32x32x4 0x0a
  154. #define P3RD_CURSOR_MODE_P23_32x32x4 0x0c
  155. #define P3RD_CURSOR_MODE_ENABLED 0x01
  156. #define P3RD_CURSOR_CONTROL_RPOS_ENABLED 0x04
  157. #define P3RD_CURSOR_CONTROL_DOUBLE_Y 0x02
  158. #define P3RD_CURSOR_CONTROL_DOUBLE_X 0x01
  159. #define P3RD_DCLK_CONTROL_LOCKED 0x02 // read-only
  160. #define P3RD_DCLK_CONTROL_ENABLED 0x01
  161. #define P3RD_MCLK_CONTROL_LOCKED 0x02 // read-only
  162. #define P3RD_MCLK_CONTROL_ENABLED 0x01
  163. #define P3RD_CURSOR_PALETTE_CURSOR_RGB(RGBIndex, Red, Green, Blue) \
  164. { \
  165. P3RD_LOAD_INDEX_REG(P3RD_CURSOR_PALETTE_START+3*(int)RGBIndex+0, Red); \
  166. P3RD_LOAD_INDEX_REG(P3RD_CURSOR_PALETTE_START+3*(int)RGBIndex+1, Green); \
  167. P3RD_LOAD_INDEX_REG(P3RD_CURSOR_PALETTE_START+3*(int)RGBIndex+2, Blue); \
  168. }
  169. #define P3RD_SYNC_WITH_GLINT
  170. //
  171. // generic read/write routines for P3RD registers
  172. //
  173. #define WRITE_P3RDREG_ULONG(r, d) \
  174. { \
  175. WRITE_FAST_ULONG(r, d); \
  176. MEMORY_BARRIER(); \
  177. }
  178. #define READ_P3RDREG_ULONG(r) READ_FAST_ULONG(r)
  179. #if 0
  180. // need a delay between each write to the P3RD. The only way to guarantee
  181. // that the write has completed is to read from a GLINT control register.
  182. // Reading forces any posted writes to be flushed out. PPC needs 2 reads
  183. // to give us enough time.
  184. #define P3RD_DELAY \
  185. { \
  186. volatile LONG __junk; \
  187. GLINT_GET_PACKING_MODE(__junk); \
  188. GLINT_GET_PACKING_MODE(__junk); \
  189. }
  190. #else
  191. #define P3RD_DELAY
  192. #endif
  193. // macro to load a given data value into an internal P3RD register. The
  194. // second macro loads an internal index register assuming that we have
  195. // already zeroed the high address register.
  196. //
  197. #define P3RD_INDEX_REG(index) \
  198. { \
  199. VideoDebugPrint(("*(0x%x) <-- 0x%x\n", P3RD_INDEX_ADDR_LO, (index) & 0xff)); \
  200. WRITE_P3RDREG_ULONG(P3RD_INDEX_ADDR_LO, (ULONG)((index) & 0xff)); \
  201. P3RD_DELAY; \
  202. VideoDebugPrint(("*(0x%x) <-- 0x%x\n", P3RD_INDEX_ADDR_HI, (index) >> 8)); \
  203. WRITE_P3RDREG_ULONG(P3RD_INDEX_ADDR_HI, (ULONG)((index) >> 8)); \
  204. P3RD_DELAY; \
  205. }
  206. #define P3RD_LOAD_DATA(data) \
  207. { \
  208. WRITE_P3RDREG_ULONG(P3RD_INDEX_DATA, (ULONG)((data) & 0xff)); \
  209. P3RD_DELAY; \
  210. }
  211. #define P3RD_LOAD_INDEX_REG(index, data) \
  212. { \
  213. P3RD_INDEX_REG(index); \
  214. VideoDebugPrint(("*(0x%x) <-- 0x%x\n", P3RD_INDEX_DATA, (data) & 0xff)); \
  215. WRITE_P3RDREG_ULONG(P3RD_INDEX_DATA, (ULONG)((data) & 0xff)); \
  216. P3RD_DELAY; \
  217. }
  218. #define P3RD_READ_INDEX_REG(index, data) \
  219. { \
  220. P3RD_INDEX_REG(index); \
  221. data = READ_P3RDREG_ULONG(P3RD_INDEX_DATA) & 0xff; \
  222. P3RD_DELAY; \
  223. VideoDebugPrint(("0x%x <-- *(0x%x)\n", data, P3RD_INDEX_DATA)); \
  224. }
  225. #define P3RD_LOAD_INDEX_REG_LO(index, data) \
  226. { \
  227. WRITE_P3RDREG_ULONG(P3RD_INDEX_ADDR_LO, (ULONG)(index)); \
  228. P3RD_DELAY; \
  229. WRITE_P3RDREG_ULONG(P3RD_INDEX_DATA, (ULONG)(data)); \
  230. P3RD_DELAY; \
  231. }
  232. // macros to load a given RGB triple into the P3RD palette. Send the starting
  233. // index and then send RGB triples. Auto-increment is turned on.
  234. // Use P3RD_PALETTE_START and multiple P3RD_LOAD_PALETTE calls to load
  235. // a contiguous set of entries. Use P3RD_LOAD_PALETTE_INDEX to load a set
  236. // of sparse entries.
  237. //
  238. #define P3RD_PALETTE_START_WR(index) \
  239. { \
  240. WRITE_P3RDREG_ULONG(P3RD_PAL_WR_ADDR, (ULONG)(index)); \
  241. P3RD_DELAY; \
  242. }
  243. #define P3RD_PALETTE_START_RD(index) \
  244. { \
  245. WRITE_P3RDREG_ULONG(P3RD_PAL_RD_ADDR, (ULONG)(index)); \
  246. P3RD_DELAY; \
  247. }
  248. #define P3RD_LOAD_PALETTE(red, green, blue) \
  249. { \
  250. WRITE_P3RDREG_ULONG(P3RD_PAL_DATA, (ULONG)(red)); \
  251. P3RD_DELAY; \
  252. WRITE_P3RDREG_ULONG(P3RD_PAL_DATA, (ULONG)(green)); \
  253. P3RD_DELAY; \
  254. WRITE_P3RDREG_ULONG(P3RD_PAL_DATA, (ULONG)(blue)); \
  255. P3RD_DELAY; \
  256. }
  257. #define P3RD_LOAD_PALETTE_INDEX(index, red, green, blue) \
  258. { \
  259. WRITE_P3RDREG_ULONG(P3RD_PAL_WR_ADDR, (ULONG)(index)); \
  260. P3RD_DELAY; \
  261. WRITE_P3RDREG_ULONG(P3RD_PAL_DATA, (ULONG)(red)); \
  262. P3RD_DELAY; \
  263. WRITE_P3RDREG_ULONG(P3RD_PAL_DATA, (ULONG)(green)); \
  264. P3RD_DELAY; \
  265. WRITE_P3RDREG_ULONG(P3RD_PAL_DATA, (ULONG)(blue)); \
  266. P3RD_DELAY; \
  267. }
  268. // macro to read back a given RGB triple from the P3RD palette. Use after
  269. // a call to P3RD_PALETTE_START_RD
  270. //
  271. #define P3RD_READ_PALETTE(red, green, blue) \
  272. { \
  273. red = (UCHAR)(READ_P3RDREG_ULONG(P3RD_PAL_DATA) & 0xff); \
  274. P3RD_DELAY; \
  275. green = (UCHAR)(READ_P3RDREG_ULONG(P3RD_PAL_DATA) & 0xff); \
  276. P3RD_DELAY; \
  277. blue = (UCHAR)(READ_P3RDREG_ULONG(P3RD_PAL_DATA) & 0xff); \
  278. P3RD_DELAY; \
  279. }
  280. // macros to set/get the pixel read mask. The mask is 8 bits wide and gets
  281. // replicated across all bytes that make up a pixel.
  282. //
  283. #define P3RD_SET_PIXEL_READMASK(mask) \
  284. { \
  285. WRITE_P3RDREG_ULONG(P3RD_PIXEL_MASK, (ULONG)(mask)); \
  286. P3RD_DELAY; \
  287. }
  288. #define P3RD_READ_PIXEL_READMASK(mask) \
  289. { \
  290. mask = READ_P3RDREG_ULONG(P3RD_PIXEL_MASK) & 0xff; \
  291. }
  292. // Windows format byte-packed cursor data: each byte represents 4 consecutive pixels
  293. #define P3RD_CURSOR_2_COLOR_BLACK 0x00
  294. #define P3RD_CURSOR_2_COLOR_WHITE 0x55
  295. #define P3RD_CURSOR_2_COLOR_TRANSPARENT 0xAA
  296. #define P3RD_CURSOR_2_COLOR_HIGHLIGHT 0xFF
  297. #define P3RD_CURSOR_3_COLOR_TRANSPARENT 0x00
  298. #define P3RD_CURSOR_15_COLOR_TRANSPARENT 0x00
  299. // macros to load values into the cursor array usage is P3RD_CURSOR_ARRAR_START() followed by
  300. // n iterations of P3RD_LOAD_CURSOR_ARRAY() or P3RD_READ_CURSOR_ARRAY()
  301. //
  302. #define P3RD_CURSOR_ARRAY_START(offset) \
  303. { \
  304. WRITE_P3RDREG_ULONG(P3RD_INDEX_ADDR_LO, (ULONG)(((offset)+P3RD_CURSOR_PATTERN_START) & 0xff)); \
  305. P3RD_DELAY; \
  306. WRITE_P3RDREG_ULONG(P3RD_INDEX_ADDR_HI, (ULONG)(((offset)+P3RD_CURSOR_PATTERN_START) >> 8)); \
  307. P3RD_DELAY; \
  308. }
  309. #define P3RD_LOAD_CURSOR_ARRAY(data) \
  310. { \
  311. WRITE_P3RDREG_ULONG(P3RD_INDEX_DATA, (ULONG)(data)); \
  312. P3RD_DELAY; \
  313. }
  314. #define P3RD_READ_CURSOR_ARRAY(data) \
  315. { \
  316. data = READ_P3RDREG_ULONG(P3RD_INDEX_DATA) & 0xff; \
  317. P3RD_DELAY; \
  318. }
  319. // macro to move the cursor
  320. //
  321. #define P3RD_MOVE_CURSOR(x, y) \
  322. { \
  323. WRITE_P3RDREG_ULONG(P3RD_INDEX_ADDR_HI, (ULONG)0); \
  324. P3RD_DELAY; \
  325. P3RD_LOAD_INDEX_REG_LO(P3RD_CURSOR_X_LOW, (ULONG)((x) & 0xff)); \
  326. P3RD_LOAD_INDEX_REG_LO(P3RD_CURSOR_X_HIGH, (ULONG)((x) >> 8)); \
  327. P3RD_LOAD_INDEX_REG_LO(P3RD_CURSOR_Y_LOW, (ULONG)((y) & 0xff)); \
  328. P3RD_LOAD_INDEX_REG_LO(P3RD_CURSOR_Y_HIGH, (ULONG)((y) >> 8)); \
  329. }
  330. // macro to change the cursor hotspot
  331. //
  332. #define P3RD_CURSOR_HOTSPOT(x, y) \
  333. { \
  334. WRITE_P3RDREG_ULONG(P3RD_INDEX_ADDR_HI, (ULONG)(0)); \
  335. P3RD_DELAY; \
  336. P3RD_LOAD_INDEX_REG_LO(P3RD_CURSOR_HOTSPOT_X, (ULONG)(x)); \
  337. P3RD_LOAD_INDEX_REG_LO(P3RD_CURSOR_HOTSPOT_Y, (ULONG)(y)); \
  338. }
  339. // Cursor sizes
  340. #define P3RD_CURSOR_SIZE_64_MONO 0
  341. #define P3RD_CURSOR_SIZE_32_MONO 1
  342. #define P3RD_CURSOR_SIZE_64_3COLOR 0
  343. #define P3RD_CURSOR_SIZE_32_3COLOR 1
  344. #define P3RD_CURSOR_SIZE_32_15COLOR 5
  345. #define P3RD_CURSOR_SEL(cursorSize, cursorIndex) \
  346. (((cursorSize + cursorIndex) & 7) << 1)
  347. //
  348. // Warning the P3 has an upside down cursor LUT, which means that
  349. // items read from LUT entry 0 are actually read from entry 14.
  350. // Therefore we have some macros to calculate the right value.
  351. //
  352. // Permedia4 behaves more naturally.
  353. //
  354. #define P3RD_CALCULATE_LUT_INDEX(x) \
  355. (glintInfo->deviceInfo.DeviceId == PERMEDIA4_ID ? (x) : (14-(x)))
  356. // Exported functions from P3RD.c
  357. PTRENABLE vEnablePointerP3RD;
  358. PTRDISABLE vDisablePointerP3RD;
  359. PTRSETSHAPE bSetPointerShapeP3RD;
  360. PTRMOVE vMovePointerP3RD;
  361. PTRSHOW vShowPointerP3RD;
  362. //@@BEGIN_DDKSPLIT
  363. //DACSETUPOVERLAY vSetOverlayModeP3RD;
  364. //PTRSETPIXMSK vP3RDSetPixelMask;
  365. //PTRSWPCSBUF bP3RDSwapCSBuffers;
  366. //PTRCHKCSBUF bP3RDCheckCSBuffering;
  367. //@@END_DDKSPLIT