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.

473 lines
17 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4. * !! !!
  5. * !! WARNING: NOT DDK SAMPLE CODE !!
  6. * !! !!
  7. * !! This source code is provided for completeness only and should not be !!
  8. * !! used as sample code for display driver development. Only those sources !!
  9. * !! marked as sample code for a given driver component should be used for !!
  10. * !! development purposes. !!
  11. * !! !!
  12. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  13. *
  14. * Module Name: rgb640.h
  15. *
  16. * Content: This module contains the definitions for the IBM RGB640 RAMDAC.
  17. *
  18. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  19. * Copyright (c) 1995-2003 Microsoft Corporation. All rights reserved.
  20. \*****************************************************************************/
  21. //
  22. // IBM RGB640 RAMDAC definitions
  23. // This set of registers resides at &(pCtrlRegs->ExternalVideo)
  24. //
  25. typedef struct _rgb640_regs {
  26. RAMDAC_REG palAddrWr; // loads internal register for palette writes
  27. RAMDAC_REG palData; // read/write to get/set palette data
  28. RAMDAC_REG pixelMask; // mask to AND with input pixel data
  29. RAMDAC_REG palAddrRd; // loads internal register for palette reads
  30. RAMDAC_REG indexLow; // low byte of internal control/cursor register
  31. RAMDAC_REG indexHigh; // high byte of internal control/cursor register
  32. RAMDAC_REG indexData; // read/write to get/set control/cursor data
  33. RAMDAC_REG Reserved;
  34. } RGB640RAMDAC, *pRGB640RAMDAC;
  35. // structure containing the mapped addresses for each of the RGB640 registers.
  36. // We need this since some chips like the Alpha cannot be accessed by simply
  37. // writing to the memory mapped register. So instead we set up the following
  38. // struct of memory addresses at init time and use these instead. All these
  39. // addresses must be passed to WRITE/READ_FAST_ULONG.
  40. // We also keep software copies of various registers in here so we can turn
  41. // on and off individual bits more easily.
  42. //
  43. typedef struct _rgb640_data {
  44. // register addresses
  45. ULONG * palAddrWr; // loads internal register for palette writes
  46. ULONG * palData; // read/write to get/set palette data
  47. ULONG * pixelMask; // mask to AND with input pixel data
  48. ULONG * palAddrRd; // loads internal register for palette reads
  49. ULONG * indexLow; // low byte of internal control/cursor register
  50. ULONG * indexHigh; // high byte of internal control/cursor register
  51. ULONG * indexData; // read/write to get/set control/cursor data
  52. ULONG * indexCtl; // controls auto-increment of internal addresses
  53. // register copies
  54. ULONG cursorControl; // controls enable/disable
  55. } RGB640Data, *pRGB640Data;
  56. // use the following macros as the address to pass to the
  57. // VideoPortWriteRegisterUlong function
  58. //
  59. #define RGB640_PAL_WR_ADDR pRGB640info->palAddrWr
  60. #define RGB640_PAL_RD_ADDR pRGB640info->palAddrRd
  61. #define RGB640_PAL_DATA pRGB640info->palData
  62. #define RGB640_PIXEL_MASK pRGB640info->pixelMask
  63. #define RGB640_INDEX_ADDR_LO pRGB640info->indexLow
  64. #define RGB640_INDEX_ADDR_HI pRGB640info->indexHigh
  65. #define RGB640_INDEX_DATA pRGB640info->indexData
  66. #define RGB640_INDEX_CONTROL pRGB640info->indexCtl
  67. //
  68. // generic read/write routines for 640 registers
  69. //
  70. #define WRITE_640REG_ULONG(r, d) \
  71. { \
  72. WRITE_FAST_ULONG(r, (ULONG)(d)); \
  73. MEMORY_BARRIER(); \
  74. }
  75. #define READ_640REG_ULONG(r) READ_FAST_ULONG(r)
  76. // We have to have a delay between all accesses to the RGB640. A simple
  77. // for loop delay is not good enough since writes to GLINT are posted
  78. // and may still get batched together. The only sure way is to do a read
  79. // from bypass space. Arbitrarily, we choose the FBModeSel register since
  80. // we already have a macro to read it. PPC needs 2 reads to give us enough
  81. // time.
  82. //
  83. #define RGB640_DELAY \
  84. { \
  85. volatile ULONG __junk; \
  86. GLINT_GET_PACKING_MODE(__junk); \
  87. GLINT_GET_PACKING_MODE(__junk); \
  88. }
  89. // macro to load a given data value into an internal RGB640 register. The
  90. // second macro loads an internal index register assuming that we have
  91. // already zeroed the high address register.
  92. //
  93. #define RGB640_INDEX_INCREMENT(n) \
  94. { \
  95. /*WRITE_640REG_ULONG (RGB640_INDEX_CONTROL, (ULONG)(n)); */\
  96. RGB640_DELAY; \
  97. }
  98. // macro to load a given data value into an internal RGB640 register. The
  99. // second macro loads an internal index register assuming that we have
  100. // already zeroed the high address register.
  101. //
  102. #define RGB640_INDEX_REG(index) \
  103. { \
  104. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_LO, (ULONG)((index) & 0xff)); \
  105. RGB640_DELAY; \
  106. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_HI, (ULONG)((index) >> 8)); \
  107. RGB640_DELAY; \
  108. }
  109. #define RGB640_LOAD_DATA(data) \
  110. { \
  111. WRITE_640REG_ULONG(RGB640_INDEX_DATA, (ULONG)((data) & 0xff)); \
  112. RGB640_DELAY; \
  113. }
  114. #define RGB640_LOAD_INDEX_REG(index, data) \
  115. { \
  116. RGB640_INDEX_REG(index); \
  117. WRITE_640REG_ULONG(RGB640_INDEX_DATA, (ULONG)((data) & 0xff)); \
  118. RGB640_DELAY; \
  119. }
  120. #define RGB640_READ_INDEX_REG(index, data) \
  121. { \
  122. RGB640_INDEX_REG(index); \
  123. data = (UCHAR) (READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff); \
  124. RGB640_DELAY; \
  125. }
  126. #define RGB640_LOAD_INDEX_REG_LO(index, data) \
  127. { \
  128. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_LO, (ULONG)(index)); \
  129. RGB640_DELAY; \
  130. WRITE_640REG_ULONG(RGB640_INDEX_DATA, (ULONG)(data)); \
  131. RGB640_DELAY; \
  132. }
  133. // macros to load a given RGB triple into the RGB640 palette. Send the starting
  134. // index and then send RGB triples. Auto-increment is turned on.
  135. // Use RGB640_PALETTE_START and multiple RGB640_LOAD_PALETTE calls to load
  136. // a contiguous set of entries. Use RGB640_LOAD_PALETTE_INDEX to load a set
  137. // of sparse entries.
  138. //
  139. #define RGB640_PALETTE_START_WR(index) \
  140. RGB640_INDEX_REG((index) + 0x4000)
  141. #define RGB640_PALETTE_START_RD(index) \
  142. RGB640_INDEX_REG((index) + 0x8000)
  143. #define RGB640_LOAD_PALETTE(red, green, blue) \
  144. { \
  145. RGB640_LOAD_DATA(red); \
  146. RGB640_LOAD_DATA(green); \
  147. RGB640_LOAD_DATA(blue); \
  148. }
  149. #define RGB640_LOAD_PALETTE_INDEX(index, red, green, blue) \
  150. { \
  151. RGB640_PALETTE_START_WR(index); \
  152. RGB640_LOAD_PALETTE(red, green, blue); \
  153. }
  154. // macro to read back a given RGB triple from the RGB640 palette. Use after
  155. // a call to RGB640_PALETTE_START_RD
  156. //
  157. #define RGB640_READ_PALETTE(red, green, blue) \
  158. { \
  159. red = (UCHAR)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff); \
  160. RGB640_DELAY; \
  161. green = (UCHAR)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff); \
  162. RGB640_DELAY; \
  163. blue = (UCHAR)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff); \
  164. RGB640_DELAY; \
  165. }
  166. // Accesses to 1024x30 palette using four accesses
  167. #define RGB640_LOAD_PALETTE10(red, green, blue) \
  168. { \
  169. RGB640_LOAD_DATA ((red) >> 2); \
  170. RGB640_LOAD_DATA ((green) >> 2); \
  171. RGB640_LOAD_DATA ((blue) >> 2); \
  172. RGB640_LOAD_DATA ((((red) & 3) << 4) | \
  173. (((green) & 3) << 2) | \
  174. (((blue) & 3) )); \
  175. }
  176. #define RGB640_LOAD_PALETTE10_INDEX(index, red, green, blue) \
  177. { \
  178. RGB640_PALETTE_START_WR(index); \
  179. RGB640_LOAD_PALETTE10(red, green, blue); \
  180. }
  181. // macro to read back a given RGB triple from the RGB640 palette. Use after
  182. // a call to RGB640_PALETTE_START_RD
  183. //
  184. #define RGB640_READ_PALETTE10(red, green, blue) \
  185. { \
  186. USHORT temp; \
  187. red = (USHORT)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff) << 2; \
  188. RGB640_DELAY; \
  189. green = (USHORT)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff) << 2; \
  190. RGB640_DELAY; \
  191. blue = (USHORT)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff) << 2; \
  192. RGB640_DELAY; \
  193. temp = (USHORT)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff); \
  194. RGB640_DELAY; \
  195. red |= (temp >> 4) & 0x3; \
  196. green |= (temp >> 2) & 0x3; \
  197. blue |= temp & 0x3; \
  198. }
  199. // macros to set/get the pixel read mask. The mask is 8 bits wide and gets
  200. // replicated across all bytes that make up a pixel.
  201. //
  202. #define RGB640_SET_PIXEL_READMASK(mask) \
  203. { \
  204. WRITE_640REG_ULONG(RGB640_PIXEL_MASK, (ULONG)(mask)); \
  205. RGB640_DELAY; \
  206. }
  207. #define RGB640_READ_PIXEL_READMASK(mask) \
  208. { \
  209. mask = (UCHAR)(READ_640REG_ULONG (RGB640_PIXEL_MASK) & 0xff); \
  210. RGB640_DELAY; \
  211. }
  212. // macros to load values into the cursor array
  213. //
  214. #define RGB640_CURSOR_ARRAY_START_WR(offset) \
  215. { \
  216. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_LO, (ULONG)(((offset)+0x1000) & 0xff)); \
  217. RGB640_DELAY; \
  218. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_HI, (ULONG)(((offset)+0x1000) >> 8)); \
  219. RGB640_DELAY; \
  220. }
  221. #define RGB640_CURSOR_ARRAY_START_RD(offset) \
  222. { \
  223. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_LO, (ULONG)(((offset)+0x2000) & 0xff)); \
  224. RGB640_DELAY; \
  225. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_HI, (ULONG)(((offset)+0x2000) >> 8)); \
  226. RGB640_DELAY; \
  227. }
  228. #define RGB640_LOAD_CURSOR_ARRAY(data) \
  229. { \
  230. WRITE_640REG_ULONG(RGB640_INDEX_DATA, (ULONG)(data)); \
  231. RGB640_DELAY; \
  232. }
  233. #define RGB640_READ_CURSOR_ARRAY(data) \
  234. { \
  235. data = (UCHAR)(READ_640REG_ULONG (RGB640_INDEX_DATA) & 0xff); \
  236. RGB640_DELAY; \
  237. }
  238. // macro to move the cursor
  239. //
  240. #define RGB640_MOVE_CURSOR(x, y) \
  241. { \
  242. RGB640_INDEX_REG (RGB640_CURSOR_X_LOW); \
  243. RGB640_LOAD_DATA ((ULONG)((x) & 0xff)); \
  244. RGB640_LOAD_DATA ((ULONG)((x) >> 8)); \
  245. RGB640_LOAD_DATA ((ULONG)((y) & 0xff)); \
  246. RGB640_LOAD_DATA ((ULONG)((y) >> 8)); \
  247. }
  248. // macro to change the cursor hotspot
  249. //
  250. #define RGB640_CURSOR_HOTSPOT(x, y) \
  251. { \
  252. RGB640_INDEX_REG (RGB640_CURSOR_X_HOT_SPOT); \
  253. RGB640_LOAD_DATA ((ULONG)(x)); \
  254. RGB640_LOAD_DATA ((ULONG)(y)); \
  255. }
  256. // macro to change the cursor color
  257. //
  258. #define RGB640_CURSOR_COLOR(red, green, blue) \
  259. { \
  260. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_HI, (ULONG)(0x4800 >> 8)); \
  261. RGB640_DELAY; \
  262. WRITE_640REG_ULONG(RGB640_INDEX_ADDR_LO, (ULONG)(0x4800 & 0xff)); \
  263. RGB640_DELAY; \
  264. WRITE_640REG_ULONG(RGB640_INDEX_DATA, (ULONG)(red)); \
  265. RGB640_DELAY; \
  266. WRITE_640REG_ULONG(RGB640_INDEX_DATA, (ULONG)(data)); \
  267. RGB640_DELAY; \
  268. WRITE_640REG_ULONG(RGB640_INDEX_DATA, (ULONG)(green)); \
  269. RGB640_DELAY; \
  270. }
  271. //
  272. // RGB640 internal register indexes
  273. //
  274. //
  275. // These are the same as for the 525 so we use 525 definitions when getting
  276. // RGBxxx Dac ids.
  277. //
  278. //#define RGB640_REVISION_LEVEL 0x0000
  279. //#define RGB640_ID 0x0001
  280. #define RGB640_SERIALIZER_PIXEL_07_00 0x0002
  281. #define RGB640_SERIALIZER_PIXEL_15_08 0x0003
  282. #define RGB640_SERIALIZER_PIXEL_23_16 0x0004
  283. #define RGB640_SERIALIZER_PIXEL_31_24 0x0005
  284. #define RGB640_SERIALIZER_WID_03_00 0x0006
  285. #define RGB640_SERIALIZER_WID_07_04 0x0007
  286. #define RGB640_SERIALIZER_MODE 0x0008
  287. #define RGB640_PIXEL_INTERLEAVE 0x0009
  288. #define RGB640_MISC_CONFIG 0x000A
  289. #define RGB640_VGA_CONTROL 0x000B
  290. #define RGB640_DAC_COMPARE_MONITOR_ID 0x000C
  291. #define RGB640_DAC_CONTROL 0x000D
  292. #define RGB640_UPDATE_CONTROL 0x000E
  293. #define RGB640_SYNC_CONTROL 0x000F
  294. #define RGB640_VIDEO_PLL_REF_DIV 0x0010
  295. #define RGB640_VIDEO_PLL_MULT 0x0011
  296. #define RGB640_VIDEO_PLL_OUTPUT_DIV 0x0012
  297. #define RGB640_VIDEO_PLL_CONTROL 0x0013
  298. #define RGB640_VIDEO_AUX_REF_DIV 0x0014
  299. #define RGB640_VIDEO_AUX_MULT 0x0015
  300. #define RGB640_VIDEO_AUX_OUTPUT_DIV 0x0016
  301. #define RGB640_VIDEO_AUX_CONTROL 0x0017
  302. #define RGB640_CHROMA_KEY_0 0x0020
  303. #define RGB640_CHROMA_KEY_MASK_0 0x0021
  304. #define RGB640_CHROMA_KEY_1 0x0022
  305. #define RGB640_CHROMA_KEY_MASK_1 0x0023
  306. #define RGB640_CHROMA_KEY_0 0x0020
  307. #define RGB640_CHROMA_KEY_0 0x0020
  308. // RGB640 Internal Cursor Registers
  309. #define RGB640_CURSOR_XHAIR_CONTROL 0x0030
  310. #define RGB640_CURSOR_BLINK_RATE 0x0031
  311. #define RGB640_CURSOR_BLINK_DUTY_CYCLE 0x0032
  312. #define RGB640_CURSOR_X_LOW 0x0040
  313. #define RGB640_CURSOR_X_HIGH 0x0041
  314. #define RGB640_CURSOR_Y_LOW 0x0042
  315. #define RGB640_CURSOR_Y_HIGH 0x0043
  316. #define RGB640_CURSOR_X_HOT_SPOT 0x0044
  317. #define RGB640_CURSOR_Y_HOT_SPOT 0x0045
  318. #define RGB640_ADV_CURSOR_COLOR_0 0x0046
  319. #define RGB640_ADV_CURSOR_COLOR_1 0x0047
  320. #define RGB640_ADV_CURSOR_COLOR_2 0x0048
  321. #define RGB640_ADV_CURSOR_COLOR_3 0x0049
  322. #define RGB640_ADV_CURSOR_ATTR_TABLE 0x004A
  323. #define RGB640_CURSOR_CONTROL 0x004B
  324. #define RGB640_XHAIR_X_LOW 0x0050
  325. #define RGB640_XHAIR_X_HIGH 0x0051
  326. #define RGB640_XHAIR_Y_LOW 0x0052
  327. #define RGB640_XHAIR_Y_HIGH 0x0053
  328. #define RGB640_XHAIR_PATTERN_COLOR 0x0054
  329. #define RGB640_XHAIR_HORZ_PATTERN 0x0055
  330. #define RGB640_XHAIR_VERT_PATTERN 0x0056
  331. #define RGB640_XHAIR_CONTROL_1 0x0057
  332. #define RGB640_XHAIR_CONTROL_2 0x0058
  333. #define RGB640_YUV_COEFFICIENT_K1 0x0070
  334. #define RGB640_YUV_COEFFICIENT_K2 0x0071
  335. #define RGB640_YUV_COEFFICIENT_K3 0x0072
  336. #define RGB640_YUV_COEFFICIENT_K4 0x0073
  337. #define RGB640_VRAM_MASK_REG_0 0x00F0
  338. #define RGB640_VRAM_MASK_REG_1 0x00F1
  339. #define RGB640_VRAM_MASK_REG_2 0x00F2
  340. #define RGB640_DIAGNOSTICS 0x00FA
  341. #define RGB640_MISR_CONTOL_STATUS 0x00FB
  342. #define RGB640_MISR_SIGNATURE_0 0x00FC
  343. #define RGB640_MISR_SIGNATURE_1 0x00FD
  344. #define RGB640_MISR_SIGNATURE_2 0x00FE
  345. #define RGB640_MISR_SIGNATURE_3 0x00FF
  346. #define RGB640_FRAMEBUFFER_WAT(n) (0x0100 + (n))
  347. #define RGB640_OVERLAY_WAT(n) (0x0200 + (n))
  348. #define RGB640_CURSOR_PIXEL_MAP_WR(n) (0x1000 + (n))
  349. #define RGB640_CURSOR_PIXEL_MAP_RD(n) (0x2000 + (n))
  350. #define RGB640_MAIN_COLOR_PAL_WR(n) (0x4000 + (n))
  351. #define RGB640_CURSOR_COLOR_0_WR 0x4800
  352. #define RGB640_CURSOR_COLOR_1_WR 0x4801
  353. #define RGB640_CURSOR_COLOR_2_WR 0x4802
  354. #define RGB640_CURSOR_COLOR_3_WR 0x4803
  355. #define RGB640_ALT_CURSOR_COLOR_0_WR 0x4804
  356. #define RGB640_ALT_CURSOR_COLOR_1_WR 0x4805
  357. #define RGB640_ALT_CURSOR_COLOR_2_WR 0x4806
  358. #define RGB640_ALT_CURSOR_COLOR_3_WR 0x4807
  359. #define RGB640_XHAIR_COLOR_0_WR 0x4808
  360. #define RGB640_XHAIR_COLOR_1_WR 0x4809
  361. #define RGB640_XHAIR_COLOR_2_WR 0x480A
  362. #define RGB640_XHAIR_COLOR_3_WR 0x480B
  363. #define RGB640_ALT_XHAIR_COLOR_0_WR 0x480C
  364. #define RGB640_ALT_XHAIR_COLOR_1_WR 0x480D
  365. #define RGB640_ALT_XHAIR_COLOR_2_WR 0x480E
  366. #define RGB640_ALT_XHAIR_COLOR_3_WR 0x480F
  367. #define RGB640_MAIN_COLOR_PAL_RD(n) (0x8000 + (n))
  368. #define RGB640_CURSOR_COLOR_0_RD 0x8800
  369. #define RGB640_CURSOR_COLOR_1_RD 0x8801
  370. #define RGB640_CURSOR_COLOR_2_RD 0x8802
  371. #define RGB640_CURSOR_COLOR_3_RD 0x8803
  372. #define RGB640_ALT_CURSOR_COLOR_0_RD 0x8804
  373. #define RGB640_ALT_CURSOR_COLOR_1_RD 0x8805
  374. #define RGB640_ALT_CURSOR_COLOR_2_RD 0x8806
  375. #define RGB640_ALT_CURSOR_COLOR_3_RD 0x8807
  376. #define RGB640_XHAIR_COLOR_0_RD 0x8808
  377. #define RGB640_XHAIR_COLOR_1_RD 0x8809
  378. #define RGB640_XHAIR_COLOR_2_RD 0x880A
  379. #define RGB640_XHAIR_COLOR_3_RD 0x880B
  380. #define RGB640_ALT_XHAIR_COLOR_0_RD 0x880C
  381. #define RGB640_ALT_XHAIR_COLOR_1_RD 0x880D
  382. #define RGB640_ALT_XHAIR_COLOR_2_RD 0x880E
  383. #define RGB640_ALT_XHAIR_COLOR_3_RD 0x880F
  384. //
  385. // Bit definitions for individual internal RGB640 registers
  386. //
  387. // RGB640_REVISION_LEVEL
  388. #define RGB640_IDENTIFICATION_CODE 0x1c
  389. // RGB640_ID
  390. #define RGB640_ID_REVISION_LEVEL (0x02 | (0x01 << 4))
  391. // Cursor definitions
  392. //
  393. #define RGB640_CURSOR_PARTITION_0 0
  394. #define RGB640_CURSOR_PARTITION_1 (1 << 6)
  395. #define RGB640_CURSOR_PARTITION_2 (2 << 6)
  396. #define RGB640_CURSOR_PARTITION_3 (3 << 6)
  397. #define RGB640_CURSOR_SIZE_32 0x0
  398. #define RGB640_CURSOR_SIZE_64 (1 << 3)
  399. #define RGB640_CURSOR_BLINK_OFF 0
  400. #define RGB640_CURSOR_BLINK_ON (1 << 5)
  401. #define RGB640_CURSOR_MODE_OFF 0
  402. #define RGB640_CURSOR_MODE_0 1
  403. #define RGB640_CURSOR_MODE_1 2
  404. #define RGB640_CURSOR_MODE_2 3
  405. #define RGB640_CURSOR_MODE_ADVANCED 4
  406. // we only ever use a two color cursor so define registers and enable bits.
  407. // for each 2 bit pixel that defines the cursor shape, bit 0x2 defines the
  408. // foreground and bit 0x1 defines the background.
  409. // NB: the transparent cursor pixel value depends on the cursor mode chosen.
  410. //
  411. #define RGB640_CURSOR_MODE_ON RGB640_CURSOR_MODE_1
  412. #define RGB640_CURSOR_TRANSPARENT_PEL 0xAA