Source code of Windows XP (NT5)
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.

1144 lines
42 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: hw.h
  3. *
  4. * All the hardware specific driver file stuff. Parts are mirrored in
  5. * 'hw.inc'.
  6. *
  7. * Copyright (c) 1992-1995 Microsoft Corporation
  8. *
  9. \**************************************************************************/
  10. //////////////////////////////////////////////////////////////////////
  11. // Alpha and PowerPC considerations
  12. //
  13. // Both the Alpha and the PowerPC do not guarantee that I/O to
  14. // separate addresses will be executed in order. The Alpha and
  15. // PowerPC differ, however, in that the PowerPC guarantees that
  16. // output to the same address will be executed in order, while the
  17. // Alpha may cache and 'collapse' consecutive output to become only
  18. // one output.
  19. //
  20. // Consequently, we use the following synchronization macros. They
  21. // are relatively expensive in terms of performance, so we try to avoid
  22. // them whereever possible.
  23. //
  24. // CP_EIEIO() 'Ensure In-order Execution of I/O'
  25. // - Used to flush any pending I/O in situations where we wish to
  26. // avoid out-of-order execution of I/O to separate addresses.
  27. //
  28. // CP_MEMORY_BARRIER()
  29. // - Used to flush any pending I/O in situations where we wish to
  30. // avoid out-of-order execution or 'collapsing' of I/O to
  31. // the same address. On the PowerPC, this will be defined as
  32. // a null operation.
  33. #if defined(_PPC_)
  34. // On PowerPC, CP_MEMORY_BARRIER doesn't do anything.
  35. #define CP_EIEIO() MEMORY_BARRIER()
  36. #define CP_MEMORY_BARRIER()
  37. #else
  38. // On Alpha, CP_EIEIO is the same thing as a CP_MEMORY_BARRIER.
  39. // On other systems, both CP_EIEIO and CP_MEMORY_BARRIER don't do anything.
  40. #define CP_EIEIO() MEMORY_BARRIER()
  41. #define CP_MEMORY_BARRIER() MEMORY_BARRIER()
  42. #endif
  43. ////////////////////////////////////////////////////////////////////////////
  44. // Mach32 Equates
  45. ////////////////////////////////////////////////////////////////////////////
  46. #define NOT_SCREEN 0x00
  47. #define LOGICAL_0 0x01
  48. #define LOGICAL_1 0x02
  49. #define LEAVE_ALONE 0x03
  50. #define NOT_NEW 0x04
  51. #define SCREEN_XOR_NEW 0x05
  52. #define NOT_SCREEN_XOR_NEW 0x06
  53. #define OVERPAINT 0x07
  54. #define NOT_SCREEN_OR_NOT_NEW 0x08
  55. #define SCREEN_OR_NOT_NEW 0x09
  56. #define NOT_SCREEN_OR_NEW 0x0A
  57. #define SCREEN_OR_NEW 0x0B
  58. #define SCREEN_AND_NEW 0x0C
  59. #define NOT_SCREEN_AND_NEW 0x0D
  60. #define SCREEN_AND_NOT_NEW 0x0E
  61. #define NOT_SCREEN_AND_NOT_NEW 0x0F
  62. #define SETUP_ID1 0x0100 // Setup Mode Identification (Byte 1)
  63. #define SETUP_ID2 0x0101 // Setup Mode Identification (Byte 2)
  64. #define SETUP_OPT 0x0102 // Setup Mode Option Select
  65. #define ROM_SETUP 0x0103 //
  66. #define SETUP_1 0x0104 //
  67. #define SETUP_2 0x0105 //
  68. #define DISP_STATUS 0x02E8 // Display Status
  69. #define H_TOTAL 0x02E8 // Horizontal Total
  70. #define DAC_MASK 0x02EA // DAC Mask
  71. #define DAC_R_INDEX 0x02EB // DAC Read Index
  72. #define DAC_W_INDEX 0x02EC // DAC Write Index
  73. #define DAC_DATA 0x02ED // DAC Data
  74. #define OVERSCAN_COLOR_8 0x02EE
  75. #define OVERSCAN_BLUE_24 0x02EF
  76. #define H_DISP 0x06E8 // Horizontal Displayed
  77. #define OVERSCAN_GREEN_24 0x06EE
  78. #define OVERSCAN_RED_24 0x06EF
  79. #define H_SYNC_STRT 0x0AE8 // Horizontal Sync Start
  80. #define CURSOR_OFFSET_LO 0x0AEE
  81. #define H_SYNC_WID 0x0EE8 // Horizontal Sync Width
  82. #define CURSOR_OFFSET_HI 0x0EEE
  83. #define V_TOTAL 0x12E8 // Vertical Total
  84. #define CONFIG_STATUS_1 0x12EE // Read only equivalent to HORZ_CURSOR_POSN
  85. #define HORZ_CURSOR_POSN 0x12EE
  86. #define V_DISP 0x16E8 // Vertical Displayed
  87. #define CONFIG_STATUS_2 0x16EE // Read only equivalent to VERT_CURSOR_POSN
  88. #define VERT_CURSOR_POSN 0x16EE
  89. #define V_SYNC_STRT 0x1AE8 // Vertical Sync Start
  90. #define CURSOR_COLOR_0 0x1AEE
  91. #define FIFO_TEST_DATA 0x1AEE
  92. #define CURSOR_COLOR_1 0x1AEF
  93. #define V_SYNC_WID 0x1EE8 // Vertical Sync Width
  94. #define HORZ_CURSOR_OFFSET 0x1EEE
  95. #define VERT_CURSOR_OFFSET 0x1EEF
  96. #define DISP_CNTL 0x22E8 // Display Control
  97. #define CRT_PITCH 0x26EE
  98. #define CRT_OFFSET_LO 0x2AEE
  99. #define CRT_OFFSET_HI 0x2EEE
  100. #define LOCAL_CONTROL 0x32EE
  101. #define FIFO_OPT 0x36EE
  102. #define MISC_OPTIONS 0x36EE
  103. #define EXT_CURSOR_COLOR_0 0x3AEE
  104. #define FIFO_TEST_TAG 0x3AEE
  105. #define EXT_CURSOR_COLOR_1 0x3EEE
  106. #define SUBSYS_CNTL 0x42E8 // Subsystem Control
  107. #define SUBSYS_STAT 0x42E8 // Subsystem Status
  108. #define MEM_BNDRY 0x42EE
  109. #define SHADOW_CTL 0x46EE
  110. #define ROM_PAGE_SEL 0x46E8 // ROM Page Select (not in manual)
  111. #define ADVFUNC_CNTL 0x4AE8 // Advanced Function Control
  112. #define CLOCK_SEL 0x4AEE
  113. #define SCRATCH_PAD_0 0x52EE
  114. #define SCRATCH_PAD_1 0x56EE
  115. #define SHADOW_SET 0x5AEE
  116. #define MEM_CFG 0x5EEE
  117. #define EXT_GE_STATUS 0x62EE
  118. #define HORZ_OVERSCAN 0x62EE
  119. #define VERT_OVERSCAN 0x66EE
  120. #define MAX_WAITSTATES 0x6AEE
  121. #define GE_OFFSET_LO 0x6EEE
  122. #define BOUNDS_LEFT 0x72EE
  123. #define GE_OFFSET_HI 0x72EE
  124. #define BOUNDS_TOP 0x76EE
  125. #define GE_PITCH 0x76EE
  126. #define BOUNDS_RIGHT 0x7AEE
  127. #define EXT_GE_CONFIG 0x7AEE
  128. #define BOUNDS_BOTTOM 0x7EEE
  129. #define MISC_CNTL 0x7EEE
  130. #define CUR_Y 0x82E8 // Current Y Position
  131. #define PATT_DATA_INDEX 0x82EE
  132. #define CUR_X 0x86E8 // Current X Position
  133. #define M32_SRC_Y 0x8AE8 //
  134. #define DEST_Y 0x8AE8 //
  135. #define AXSTP 0x8AE8 // Destination Y Position
  136. // Axial Step Constant
  137. #define M32_SRC_X 0x8EE8 //
  138. #define DEST_X 0x8EE8 //
  139. #define DIASTP 0x8EE8 // Destination X Position
  140. // Diagonial Step Constant
  141. #define PATT_DATA 0x8EEE
  142. #define R_EXT_GE_CONFIG 0x8EEE
  143. #define ERR_TERM 0x92E8 // Error Term
  144. #define R_MISC_CNTL 0x92EE
  145. #define MAJ_AXIS_PCNT 0x96E8 // Major Axis Pixel Count
  146. #define BRES_COUNT 0x96EE
  147. #define CMD 0x9AE8 // Command
  148. #define GE_STAT 0x9AE8 // Graphics Processor Status
  149. #define EXT_FIFO_STATUS 0x9AEE
  150. #define LINEDRAW_INDEX 0x9AEE
  151. #define SHORT_STROKE 0x9EE8 // Short Stroke Vector Transfer
  152. #define BKGD_COLOR 0xA2E8 // Background Color
  153. #define LINEDRAW_OPT 0xA2EE
  154. #define FRGD_COLOR 0xA6E8 // Foreground Color
  155. #define DEST_X_START 0xA6EE
  156. #define WRT_MASK 0xAAE8 // Write Mask
  157. #define DEST_X_END 0xAAEE
  158. #define RD_MASK 0xAEE8 // Read Mask
  159. #define DEST_Y_END 0xAEEE
  160. #define CMP_COLOR 0xB2E8 // Compare Color
  161. #define R_H_TOTAL 0xB2EE
  162. #define R_H_DISP 0xB2EE
  163. #define M32_SRC_X_START 0xB2EE
  164. #define BKGD_MIX 0xB6E8 // Background Mix
  165. #define ALU_BG_FN 0xB6EE
  166. #define R_H_SYNC_STRT 0xB6EE
  167. #define FRGD_MIX 0xBAE8 // Foreground Mix
  168. #define ALU_FG_FN 0xBAEE
  169. #define R_H_SYNC_WID 0xBAEE
  170. #define MULTIFUNC_CNTL 0xBEE8 // Multi-Function Control (mach 8) !!!!!! Requires MB
  171. #define MIN_AXIS_PCNT 0xBEE8
  172. #define SCISSOR_T 0xBEE8
  173. #define SCISSOR_L 0xBEE8
  174. #define SCISSOR_B 0xBEE8
  175. #define SCISSOR_R 0xBEE8
  176. #define M32_MEM_CNTL 0xBEE8
  177. #define PATTERN_L 0xBEE8
  178. #define PATTERN_H 0xBEE8
  179. #define PIXEL_CNTL 0xBEE8
  180. #define M32_SRC_X_END 0xBEEE
  181. #define SRC_Y_DIR 0xC2EE
  182. #define R_V_TOTAL 0xC2EE
  183. #define EXT_SSV 0xC6EE // (used for MACH 8)
  184. #define EXT_SHORT_STROKE 0xC6EE
  185. #define R_V_DISP 0xC6EE
  186. #define SCAN_X 0xCAEE
  187. #define R_V_SYNC_STRT 0xCAEE
  188. #define DP_CONFIG 0xCEEE
  189. #define VERT_LINE_CNTR 0xCEEE
  190. #define PATT_LENGTH 0xD2EE
  191. #define R_V_SYNC_WID 0xD2EE
  192. #define PATT_INDEX 0xD6EE
  193. #define EXT_SCISSOR_L 0xDAEE // "extended" left scissor (12 bits precision)
  194. #define R_SRC_X 0xDAEE
  195. #define EXT_SCISSOR_T 0xDEEE // "extended" top scissor (12 bits precision)
  196. #define R_SRC_Y 0xDEEE
  197. #define PIX_TRANS 0xE2E8 // Pixel Data Transfer
  198. #define PIX_TRANS_LO 0xE2E8
  199. #define PIX_TRANS_HI 0xE2E9
  200. #define EXT_SCISSOR_R 0xE2EE // "extended" right scissor (12 bits precision)
  201. #define EXT_SCISSOR_B 0xE6EE // "extended" bottom scissor (12 bits precision)
  202. #define SRC_CMP_COLOR 0xEAEE // (used for MACH 8)
  203. #define DEST_CMP_FN 0xEEEE
  204. #define LINEDRAW 0xFEEE // !!!!!! Requires MB
  205. //---------------------------------------------------------
  206. // macros (from 8514.inc)
  207. //
  208. // I/O macros:
  209. //
  210. //mov if port NOT = to DX
  211. //
  212. //mov if port NOT = to DX
  213. //
  214. //
  215. //
  216. //Following are the FIFO checking macros:
  217. //
  218. //
  219. //
  220. //FIFO space check macro:
  221. //
  222. #define ONE_WORD 0x8000
  223. #define TWO_WORDS 0xC000
  224. #define THREE_WORDS 0xE000
  225. #define FOUR_WORDS 0xF000
  226. #define FIVE_WORDS 0xF800
  227. #define SIX_WORDS 0xFC00
  228. #define SEVEN_WORDS 0xFE00
  229. #define EIGHT_WORDS 0xFF00
  230. #define NINE_WORDS 0xFF80
  231. #define TEN_WORDS 0xFFC0
  232. #define ELEVEN_WORDS 0xFFE0
  233. #define TWELVE_WORDS 0xFFF0
  234. #define THIRTEEN_WORDS 0xFFF8
  235. #define FOURTEEN_WORDS 0xFFFC
  236. #define FIFTEEN_WORDS 0xFFFE
  237. #define SIXTEEN_WORDS 0xFFFF
  238. //
  239. //
  240. //
  241. //---------------------------------------
  242. //
  243. //
  244. // Draw Command (DRAW_COMMAND) (from 8514regs.inc)
  245. // note: required by m32poly.asm
  246. //
  247. // opcode field
  248. #define OP_CODE 0xE000
  249. #define SHIFT_op_code 0x000D
  250. #define DRAW_SETUP 0x0000
  251. #define DRAW_LINE 0x2000
  252. #define FILL_RECT_H1H4 0x4000
  253. #define FILL_RECT_V1V2 0x6000
  254. #define FILL_RECT_V1H4 0x8000
  255. #define DRAW_POLY_LINE 0xA000
  256. #define BITBLT_OP 0xC000
  257. #define DRAW_FOREVER 0xE000
  258. // swap field
  259. #define LSB_FIRST 0x1000
  260. // data width field
  261. #define DATA_WIDTH 0x0200
  262. #define BIT16 0x0200
  263. #define BIT8 0x0000
  264. // CPU wait field
  265. #define CPU_WAIT 0x0100
  266. // octant field
  267. #define OCTANT 0x00E0
  268. #define SHIFT_octant 0x0005
  269. #define YPOSITIVE 0x0080
  270. #define YMAJOR 0x0040
  271. #define XPOSITIVE 0x0020
  272. // draw field
  273. #define DRAW 0x0010
  274. // direction field
  275. #define DIR_TYPE 0x0008
  276. #define DEGREE 0x0008
  277. #define XY 0x0000
  278. #define RECT_RIGHT_AND_DOWN 0x00E0 // quadrant 3
  279. #define RECT_LEFT_AND_UP 0x0000 // quadrant 1
  280. // last pel off field
  281. #define SHIFT_last_pel_off 0x0002
  282. #define LAST_PEL_OFF 0x0004
  283. #define LAST_PEL_ON 0x0000
  284. // pixel mode
  285. #define PIXEL_MODE 0x0002
  286. #define MULTI 0x0002
  287. #define SINGLE 0x0000
  288. // read/write
  289. #define RW 0x0001
  290. #define WRITE 0x0001
  291. #define READ 0x0000
  292. //
  293. // ---------------------------------------------------------
  294. // 8514 register definitions (from vga1regs.inc)
  295. //
  296. // Internal registers (read only, for test purposes only)
  297. #define _PAR_FIFO_DATA 0x1AEE
  298. #define _PAR_FIFO_ADDR 0x3AEE
  299. #define _MAJOR_DEST_CNT 0x42EE
  300. #define _MAJOR_SRC_CNT 0x5EEE
  301. #define _MINOR_DEST_CNT 0x66EE
  302. #define _MINOR_SRC_CNT 0x8AEE
  303. #define _HW_TEST 0x32EE
  304. //
  305. // Extended Graphics Engine Status (EXT_GE_STATUS)
  306. // -rn- used in mach32.asm
  307. //
  308. #define POINTS_INSIDE 0x8000
  309. #define EE_DATA_IN 0x4000
  310. #define GE_ACTIVE 0x2000
  311. #define CLIP_ABOVE 0x1000
  312. #define CLIP_BELOW 0x0800
  313. #define CLIP_LEFT 0x0400
  314. #define CLIP_RIGHT 0x0200
  315. #define CLIP_FLAGS 0x1E00
  316. #define CLIP_INSIDE 0x0100
  317. #define EE_CRC_VALID 0x0080
  318. #define CLIP_OVERRUN 0x000F
  319. //
  320. // Datapath Configuration Register (DP_CONFIG)
  321. // note: some of the EQU is needed in m32poly.asm
  322. #define FG_COLOR_SRC 0xE000
  323. #define SHIFT_fg_color_src 0x000D
  324. #define DATA_ORDER 0x1000
  325. #define DATA_WIDTH 0x0200
  326. #define BG_COLOR_SRC 0x0180
  327. #define SHIFT_bg_color_src 0x0007
  328. #define EXT_MONO_SRC 0x0060
  329. #define SHIFT_ext_mono_src 0x0005
  330. #define DRAW 0x0010
  331. #define READ_MODE 0x0004
  332. #define POLY_FILL_MODE 0x0002
  333. #define WRITE 0x0001
  334. #define SRC_SWAP 0x0800
  335. //
  336. #define FG_COLOR_SRC_BG 0x0000 // Background Color Register
  337. #define FG_COLOR_SRC_FG 0x2000 // Foreground Color Register
  338. #define FG_COLOR_SRC_HOST 0x4000 // CPU Data Transfer Reg
  339. #define FG_COLOR_SRC_BLIT 0x6000 // VRAM blit source
  340. #define FG_COLOR_SRC_GS 0x8000 // Grey-scale mono blit
  341. #define FG_COLOR_SRC_PATT 0xA000 // Color Pattern Shift Reg
  342. #define FG_COLOR_SRC_CLUH 0xC000 // Color lookup of Host Data
  343. #define FG_COLOR_SRC_CLUB 0xE000 // Color lookup of blit src
  344. //
  345. #define BG_COLOR_SRC_BG 0x0000 // Background Color Reg
  346. #define BG_COLOR_SRC_FG 0x0080 // Foreground Color Reg
  347. #define BG_COLOR_SRC_HOST 0x0100 // CPU Data Transfer Reg
  348. #define BG_COLOR_SRC_BLIT 0x0180 // VRAM blit source
  349. //
  350. // Note that "EXT_MONO_SRC" and "MONO_SRC" are mutually destructive, but that
  351. // "EXT_MONO_SRC" selects the ATI pattern registers.
  352. //
  353. #define EXT_MONO_SRC_ONE 0x0000 // Always '1'
  354. #define EXT_MONO_SRC_PATT 0x0020 // ATI Mono Pattern Regs
  355. #define EXT_MONO_SRC_HOST 0x0040 // CPU Data Transfer Reg
  356. #define EXT_MONO_SRC_BLIT 0x0060 // VRAM Blit source plane
  357. //
  358. // Linedraw Options Register (LINEDRAW_OPT)
  359. //
  360. // note: some of the EQUS are needed in m32poly.asm
  361. #define CLIP_MODE 0x0600
  362. #define SHIFT_clip_mode 0x0009
  363. #define CLIP_MODE_DIS 0x0000
  364. #define CLIP_MODE_LINE 0x0200
  365. #define CLIP_MODE_PLINE 0x0400
  366. #define CLIP_MODE_PATT 0x0600
  367. #define BOUNDS_RESET 0x0100
  368. #define OCTANT 0x00E0
  369. #define SHIFT_ldo_octant 0x0005
  370. #define YDIR 0x0080
  371. #define XMAJOR 0x0040
  372. #define XDIR 0x0020
  373. #define DIR_TYPE 0x0008
  374. #define DIR_TYPE_DEGREE 0x0008
  375. #define DIR_TYPE_OCTANT 0x0000
  376. #define LAST_PEL_OFF 0x0004
  377. #define POLY_MODE 0x0002
  378. //
  379. #define FOREGROUND_COLOR 0x20
  380. #define DATA_EXTENSION 0xA000
  381. #define ALL_ONES 0x0000
  382. #define CPU_DATA 0x0080
  383. #define DISPLAY_MEMORY 0x00C0
  384. //
  385. // Blt defines
  386. //
  387. #define GE_BUSY 0x0200
  388. #define LOAD_SOURCE_AND_DEST 0
  389. #define LOAD_DEST 1
  390. #define LOAD_SOURCE 2
  391. #define TOP_TO_BOTTOM 1
  392. #define BOTTOM_TO_TOP 0
  393. #define VID_MEM_BLT 0x6211
  394. #define COLOR_FIL_BLT 0x2211
  395. #define MIX_FN_D 3 // page 8-24
  396. #define MIX_FN_S 7 // page 8-24
  397. #define PIXEL_CTRL 0xa000 // page 8-46
  398. #define DEST_NOT_EQ_COLOR_CMP 0x0020
  399. #define DEST_ALWAY_OVERWRITE 0
  400. //
  401. //
  402. // ------------------------------------------------------------
  403. // Mach32 register equates (from m32regs.inc)
  404. //
  405. #define REVISION 0x0000
  406. //HORIZONTAL_OVERSCAN equ 062EEh
  407. //VERTICAL_OVERSCAN equ 066EEh
  408. #define FL_MM_REGS 0x80000000 /* Memory Mapped registers are available */
  409. #define M32_MAX_SCISSOR 2047 /* Maximum scissors value */
  410. ////////////////////////////////////////////////////////////////////////////
  411. // Mach32 Port Access
  412. ////////////////////////////////////////////////////////////////////////////
  413. #if !(defined(ALPHA) || defined(_AXP64_) || defined(AXP64) )
  414. #define M32_IB_DIRECT(pbase,port) \
  415. READ_REGISTER_UCHAR((((port) & 0xFE) == 0xE8) \
  416. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  417. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))))
  418. #define M32_IW_DIRECT(pbase,port) \
  419. READ_REGISTER_USHORT((((port) & 0xFE) == 0xE8) \
  420. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  421. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))))
  422. #define M32_OB_DIRECT(pbase,port,val) \
  423. WRITE_REGISTER_UCHAR((((port) & 0xFE) == 0xE8) \
  424. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  425. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))), \
  426. (UCHAR) (val))
  427. #define M32_OW_DIRECT(pbase,port,val) \
  428. WRITE_REGISTER_USHORT((((port) & 0xFE) == 0xE8) \
  429. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  430. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))), \
  431. (USHORT) (val))
  432. #else
  433. extern BOOL isDense;
  434. #define M32_IB_DIRECT(pbase,port) \
  435. (isDense? \
  436. *((((port) & 0xFE) == 0xE8) \
  437. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  438. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1)))) : \
  439. READ_REGISTER_UCHAR((((port) & 0xFE) == 0xE8) \
  440. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  441. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1)))))
  442. #define M32_IW_DIRECT(pbase,port) \
  443. (isDense? \
  444. *((((port) & 0xFE) == 0xE8) \
  445. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  446. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1)))) : \
  447. READ_REGISTER_USHORT((((port) & 0xFE) == 0xE8) \
  448. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  449. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1)))))
  450. #define M32_OB_DIRECT(pbase,port,val) \
  451. { \
  452. if (isDense) \
  453. *((UCHAR*) ((((port) & 0xFE) == 0xE8) \
  454. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  455. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))))) \
  456. = (UCHAR) (val); \
  457. else { \
  458. WRITE_REGISTER_UCHAR((((port) & 0xFE) == 0xE8) \
  459. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  460. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))), \
  461. (UCHAR) (val)); } \
  462. CP_MEMORY_BARRIER(); \
  463. }
  464. #define M32_OW_DIRECT(pbase,port,val) \
  465. { \
  466. if (isDense) \
  467. *((USHORT*) ((((port) & 0xFE) == 0xE8) \
  468. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  469. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))))) \
  470. = (USHORT) (val); \
  471. else { \
  472. WRITE_REGISTER_USHORT((((port) & 0xFE) == 0xE8) \
  473. ? ((BYTE*) pbase + 0x3FFE00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))) \
  474. : ((BYTE*) pbase + 0x3FFF00 + ((((port) & 0xFC00) >> 8) | ((port) & 0x1))), \
  475. (USHORT) (val)); } \
  476. CP_MEMORY_BARRIER(); \
  477. }
  478. #endif
  479. #if defined(_X86_) || defined(_IA64_)
  480. #define I32_IB_DIRECT(pbase,port) \
  481. READ_PORT_UCHAR((BYTE*)port)
  482. #define I32_IW_DIRECT(pbase,port) \
  483. READ_PORT_USHORT((BYTE*)port)
  484. #define I32_OB_DIRECT(pbase,port,val) \
  485. WRITE_PORT_UCHAR((BYTE*)port, val)
  486. #define I32_OW_DIRECT(pbase,port,val) \
  487. WRITE_PORT_USHORT((BYTE*)port, (USHORT)(val))
  488. #else
  489. #define I32_IB_DIRECT(pbase,port) \
  490. READ_PORT_UCHAR((BYTE*) pbase + (port))
  491. #define I32_IW_DIRECT(pbase,port) \
  492. READ_PORT_USHORT((BYTE*) pbase + (port))
  493. #define I32_OB_DIRECT(pbase,port,val) \
  494. WRITE_PORT_UCHAR((BYTE*) pbase + (port), val)
  495. #define I32_OW_DIRECT(pbase,port,val) \
  496. WRITE_PORT_USHORT((BYTE*) pbase + (port), val)
  497. #endif
  498. /////////////////////////////////////////////////////////////////////////
  499. // Mach32 FIFO access
  500. //
  501. // The following macros should be used for all accesses to FIFO registers.
  502. // On checked builds, they enforce proper FIFO usage protocol; on free
  503. // builds, they incur no overhead.
  504. #define M32_IB(pbase,port) (M32_IB_DIRECT(pbase,port))
  505. #define M32_IW(pbase,port) (M32_IW_DIRECT(pbase,port))
  506. #define M32_OB(pbase,port,val) {CHECK_FIFO_WRITE(); M32_OB_DIRECT(pbase,port,val);}
  507. #define M32_OW(pbase,port,val) {CHECK_FIFO_WRITE(); M32_OW_DIRECT(pbase,port,val);}
  508. #define I32_IB(pbase,port) (I32_IB_DIRECT(pbase,port))
  509. #define I32_IW(pbase,port) (I32_IW_DIRECT(pbase,port))
  510. #define I32_OB(pbase,port,val) {CHECK_FIFO_WRITE(); I32_OB_DIRECT(pbase,port,val);}
  511. #define I32_OW(pbase,port,val) {CHECK_FIFO_WRITE(); I32_OW_DIRECT(pbase,port,val);}
  512. #if DBG
  513. VOID vCheckWriteFifo();
  514. VOID vI32CheckFifoSpace(PDEV*, VOID*, LONG);
  515. VOID vM32CheckFifoSpace(PDEV*, VOID*, LONG);
  516. #define CHECK_FIFO_WRITE() \
  517. vCheckFifoWrite()
  518. #define M32_CHECK_FIFO_SPACE(ppdev, pbase, level) \
  519. vM32CheckFifoSpace(ppdev, pbase, level)
  520. #define I32_CHECK_FIFO_SPACE(ppdev, pbase, level) \
  521. vI32CheckFifoSpace(ppdev, pbase, level)
  522. #else
  523. #define M32_CHECK_FIFO_SPACE(ppdev, pbase, level) \
  524. { \
  525. while (M32_IW(pbase, EXT_FIFO_STATUS) & (0x10000L >> (level))) \
  526. ; \
  527. }
  528. #define I32_CHECK_FIFO_SPACE(ppdev, pbase, level) \
  529. { \
  530. while (I32_IW(pbase, EXT_FIFO_STATUS) & (0x10000L >> (level))) \
  531. ; \
  532. }
  533. #endif
  534. ////////////////////////////////////////////////////////////////////////////
  535. // Mach64 Equates
  536. ////////////////////////////////////////////////////////////////////////////
  537. // CRTC IO Registers
  538. #define ioCRTC_H_TOTAL_DISP 0x02EC
  539. #define ioBASE ioCRTC_H_TOTAL_DISP
  540. #define ioCRTC_H_SYNC_STRT_WID 0x06EC
  541. #define ioCRTC_V_TOTAL_DISP 0x0AEC
  542. #define ioCRTC_V_SYNC_STRT_WID 0x0EEC
  543. #define ioCRTC_CRNT_VLINE 0x12EC
  544. #define ioCRTC_OFF_PITCH 0x16EC
  545. #define ioCRTC_INT_CNTL 0x1AEC
  546. #define ioCRTC_GEN_CNTL 0x1EEC
  547. #define ioOVR_CLR 0x22EC
  548. #define ioOVR_WID_LEFT_RIGHT 0x26EC
  549. #define ioOVR_WID_TOP_BOTTOM 0x2AEC
  550. #define ioCUR_CLR0 0x2EEC
  551. #define ioCUR_CLR1 0x32EC
  552. #define ioCUR_OFFSET 0x36EC
  553. #define ioCUR_HORZ_VERT_POSN 0x3AEC
  554. #define ioCUR_HORZ_VERT_OFF 0x3EEC
  555. #define ioSCRATCH0 0x42EC
  556. #define ioSCRATCH1 0x46EC
  557. #define ioCLOCK_SEL_CNTL 0x4AEC
  558. #define ioBUS_CNTL 0x4EEC
  559. #define ioMEM_CNTL 0x52EC
  560. #define ioMEM_VGA_WP_SEL 0x56EC
  561. #define ioMEM_VGA_RP_SEL 0x5AEC
  562. #define ioDAC_REGS 0x5EEC
  563. #define ioDAC_CNTL 0x62EC
  564. #define ioGEN_TEST_CNTL 0x66EC
  565. #define ioCONFIG_CNTL 0x6AEC
  566. #define ioCONFIG_CHIP_ID 0x6EEC
  567. #define ioCONFIG_STAT 0x72EC
  568. // CRTC MEM Registers
  569. #define CRTC_H_TOTAL_DISP 0x0000
  570. #define CRTC_H_SYNC_STRT_WID 0x0001
  571. #define CRTC_V_TOTAL_DISP 0x0002
  572. #define CRTC_V_SYNC_STRT_WID 0x0003
  573. #define CRTC_CRNT_VLINE 0x0004
  574. #define CRTC_OFF_PITCH 0x0005
  575. #define CRTC_INT_CNTL 0x0006
  576. #define CRTC_GEN_CNTL 0x0007
  577. #define OVR_CLR 0x0010
  578. #define OVR_WID_LEFT_RIGHT 0x0011
  579. #define OVR_WID_TOP_BOTTOM 0x0012
  580. #define CUR_CLR0 0x0018
  581. #define CUR_CLR1 0x0019
  582. #define CUR_OFFSET 0x001A
  583. #define CUR_HORZ_VERT_POSN 0x001B
  584. #define CUR_HORZ_VERT_OFF 0x001C
  585. #define SCRATCH0 0x0020
  586. #define SCRATCH1 0x0021
  587. #define CLOCK_SEL_CNTL 0x0024
  588. #define BUS_CNTL 0x0028
  589. #define BUS_CNTL_FifoErrInt 0x00200000
  590. #define BUS_CNTL_FifoErrAk 0x00200000
  591. #define BUS_CNTL_HostErrInt 0x00800000
  592. #define BUS_CNTL_HostErrAk 0x00800000
  593. #define M64_MEM_CNTL 0x002C
  594. #define MEM_CNTL_MemBndryMsk 0x00070000
  595. #define MEM_CNTL_MemBndryEn 0x00040000
  596. #define MEM_CNTL_MemBndry256k 0x00040000
  597. #define MEM_CNTL_MemBndry512k 0x00050000
  598. #define MEM_CNTL_MemBndry768k 0x00060000
  599. #define MEM_CNTL_MemBndry1Mb 0x00070000
  600. #define MEM_VGA_WP_SEL 0x002D
  601. #define MEM_VGA_RP_SEL 0x002E
  602. #define DAC_REGS 0x0030
  603. #define DAC_CNTL 0x0031
  604. #define GEN_TEST_CNTL 0x0034
  605. #define GEN_TEST_CNTL_CursorEna 0x00000080
  606. #define GEN_TEST_CNTL_GuiEna 0x00000100
  607. #define GEN_TEST_CNTL_TestFifoEna 0x00010000
  608. #define GEN_TEST_CNTL_GuiRegEna 0x00020000
  609. #define GEN_TEST_CNTL_TestMode 0x00700000
  610. #define GEN_TEST_CNTL_TestMode0 0x00000000
  611. #define GEN_TEST_CNTL_TestMode1 0x00100000
  612. #define GEN_TEST_CNTL_TestMode2 0x00200000
  613. #define GEN_TEST_CNTL_TestMode3 0x00300000
  614. #define GEN_TEST_CNTL_TestMode4 0x00400000
  615. #define GEN_TEST_CNTL_MemWR 0x01000000
  616. #define GEN_TEST_CNTL_MemStrobe 0x02000000
  617. #define GEN_TEST_CNTL_DstSSEna 0x04000000
  618. #define GEN_TEST_CNTL_DstSSStrobe 0x08000000
  619. #define GEN_TEST_CNTL_SrcSSEna 0x10000000
  620. #define GEN_TEST_CNTL_SrcSSStrobe 0x20000000
  621. #define CONFIG_CHIP_ID 0x0038
  622. #define CONFIG_STAT 0x0039
  623. #define DST_OFF_PITCH 0x0040
  624. #define DST_X 0x0041
  625. #define DST_Y 0x0042
  626. #define DST_Y_X 0x0043
  627. #define DST_WIDTH 0x0044
  628. #define DST_WIDTH_Disable 0x80000000
  629. #define DST_HEIGHT 0x0045
  630. #define DST_HEIGHT_WIDTH 0x0046
  631. #define DST_X_WIDTH 0x0047
  632. #define DST_BRES_LNTH 0x0048
  633. #define DST_BRES_ERR 0x0049
  634. #define DST_BRES_INC 0x004A
  635. #define DST_BRES_DEC 0x004B
  636. #define DST_CNTL 0x004C
  637. #define DST_CNTL_XDir 0x00000001
  638. #define DST_CNTL_YDir 0x00000002
  639. #define DST_CNTL_YMajor 0x00000004
  640. #define DST_CNTL_XTile 0x00000008
  641. #define DST_CNTL_YTile 0x00000010
  642. #define DST_CNTL_LastPel 0x00000020
  643. #define DST_CNTL_PolyEna 0x00000040
  644. #define DST_CNTL_24_RotEna 0x00000080
  645. #define DST_CNTL_24_Rot 0x00000700
  646. #define SRC_OFF_PITCH 0x0060
  647. #define M64_SRC_X 0x0061
  648. #define M64_SRC_Y 0x0062
  649. #define SRC_Y_X 0x0063
  650. #define SRC_WIDTH1 0x0064
  651. #define SRC_HEIGHT1 0x0065
  652. #define SRC_HEIGHT1_WIDTH1 0x0066
  653. #define M64_SRC_X_START 0x0067
  654. #define SRC_Y_START 0x0068
  655. #define SRC_Y_X_START 0x0069
  656. #define SRC_WIDTH2 0x006A
  657. #define SRC_HEIGHT2 0x006B
  658. #define SRC_HEIGHT2_WIDTH2 0x006C
  659. #define SRC_CNTL 0x006D
  660. #define SRC_CNTL_PatEna 0x0001
  661. #define SRC_CNTL_PatRotEna 0x0002
  662. #define SRC_CNTL_LinearEna 0x0004
  663. #define SRC_CNTL_ByteAlign 0x0008
  664. #define SRC_CNTL_LineXDir 0x0010
  665. #define HOST_DATA0 0x0080
  666. #define HOST_DATA1 0x0081
  667. #define HOST_DATA2 0x0082
  668. #define HOST_DATA3 0x0083
  669. #define HOST_DATA4 0x0084
  670. #define HOST_DATA5 0x0085
  671. #define HOST_DATA6 0x0086
  672. #define HOST_DATA7 0x0087
  673. #define HOST_DATA8 0x0088
  674. #define HOST_DATA9 0x0089
  675. #define HOST_DATAA 0x008A
  676. #define HOST_DATAB 0x008B
  677. #define HOST_DATAC 0x008C
  678. #define HOST_DATAD 0x008D
  679. #define HOST_DATAE 0x008E
  680. #define HOST_DATAF 0x008F
  681. #define HOST_CNTL 0x0090
  682. #define HOST_CNTL_ByteAlign 0x0001
  683. #define PAT_REG0 0x00A0
  684. #define PAT_REG1 0x00A1
  685. #define PAT_CNTL 0x00A2
  686. #define PAT_CNTL_MonoEna 0x0001
  687. #define PAT_CNTL_Clr4x2Ena 0x0002
  688. #define PAT_CNTL_Clr8x1Ena 0x0004
  689. #define SC_LEFT 0x00A8
  690. #define SC_RIGHT 0x00A9
  691. #define SC_LEFT_RIGHT 0x00AA
  692. #define SC_TOP 0x00AB
  693. #define SC_BOTTOM 0x00AC
  694. #define SC_TOP_BOTTOM 0x00AD
  695. #define DP_BKGD_CLR 0x00B0
  696. #define DP_FRGD_CLR 0x00B1
  697. #define DP_WRITE_MASK 0x00B2
  698. #define DP_CHAIN_MASK 0x00B3
  699. #define DP_PIX_WIDTH 0x00B4
  700. #define DP_PIX_WIDTH_Mono 0x00000000
  701. #define DP_PIX_WIDTH_4bpp 0x00000001
  702. #define DP_PIX_WIDTH_8bpp 0x00000002
  703. #define DP_PIX_WIDTH_15bpp 0x00000003
  704. #define DP_PIX_WIDTH_16bpp 0x00000004
  705. #define DP_PIX_WIDTH_32bpp 0x00000006
  706. #define DP_PIX_WIDTH_NibbleSwap 0x01000000
  707. #define DP_MIX 0x00B5
  708. #define DP_SRC 0x00B6
  709. #define DP_SRC_BkgdClr 0x0000
  710. #define DP_SRC_FrgdClr 0x0001
  711. #define DP_SRC_Host 0x0002
  712. #define DP_SRC_Blit 0x0003
  713. #define DP_SRC_Pattern 0x0004
  714. #define DP_SRC_Always1 0x00000000
  715. #define DP_SRC_MonoPattern 0x00010000
  716. #define DP_SRC_MonoHost 0x00020000
  717. #define DP_SRC_MonoBlit 0x00030000
  718. #define CLR_CMP_CLR 0x00C0
  719. #define CLR_CMP_MSK 0x00C1
  720. #define CLR_CMP_CNTL 0x00C2
  721. #define CLR_CMP_CNTL_Source 0x01000000
  722. #define FIFO_STAT 0x00C4
  723. #define CONTEXT_MASK 0x00C8
  724. #define CONTEXT_SAVE_CNTL 0x00CA
  725. #define CONTEXT_LOAD_CNTL 0x00CB
  726. #define CONTEXT_LOAD_Cmd 0x00030000
  727. #define CONTEXT_LOAD_CmdLoad 0x00010000
  728. #define CONTEXT_LOAD_CmdBlt 0x00020000
  729. #define CONTEXT_LOAD_CmdLine 0x00030000
  730. #define CONTEXT_LOAD_Disable 0x80000000
  731. #define GUI_TRAJ_CNTL 0x00CC
  732. #define GUI_STAT 0x00CE
  733. // DDraw MACH 64 stuff
  734. //
  735. // GUI_STAT
  736. #define GUI_ACTIVE 0x00000001L
  737. #define DSTX_LT_SCISSOR_LEFT 0x00000100L
  738. #define DSTX_GT_SCISSOR_RIGHT 0x00000200L
  739. #define DSTY_LT_SCISSOR_TOP 0x00000400L
  740. #define DSTY_GT_SCISSOR_BOTTOM 0x00000800L
  741. // DST Shifts
  742. #define SHIFT_DST_PITCH 22 // DST_OFF_PITCH
  743. #define SHIFT_DST_X 16 // DST_Y_X
  744. #define SHIFT_DST_WIDTH 16 // DST_HEIGHT_WIDTH DST_X_WIDTH
  745. // DST_WIDTH
  746. #define DST_WIDTH_FILL_DIS 0x80000000L
  747. // SC Shifts
  748. #define SHIFT_SC_RIGHT 16
  749. #define SHIFT_SC_BOTTOM 16
  750. // DP_PIX_WIDTH
  751. #define DP_DST_PIX_WIDTH 0x00000007L
  752. #define DP_SRC_PIX_WIDTH 0x00000700L
  753. #define DP_HOST_PIX_WIDTH 0x00070000L
  754. #define DP_BYTE_PIX_ORDER 0x01000000L
  755. #define DP_PIX_WIDTH_MONO 0x00000000L
  756. #define DP_PIX_WIDTH_4BPP 0x00010101L
  757. #define DP_PIX_WIDTH_8BPP 0x00020202L
  758. #define DP_PIX_WIDTH_15BPP 0x00030303L
  759. #define DP_PIX_WIDTH_16BPP 0x00040404L
  760. #define DP_PIX_WIDTH_24BPP 0x00020202L
  761. #define DP_PIX_WIDTH_32BPP 0x00060606L
  762. // DP_MIX
  763. #define DP_BKGD_MIX 0x0000001FL
  764. #define DP_FRGD_MIX 0x001F0000L
  765. #define DP_MIX_Dn 0x00000000L
  766. #define DP_MIX_0 0x00010001L
  767. #define DP_MIX_1 0x00020002L
  768. #define DP_MIX_D 0x00030003L
  769. #define DP_MIX_Sn 0x00040004L
  770. #define DP_MIX_DSx 0x00050005L
  771. #define DP_MIX_DSxn 0x00060006L
  772. #define DP_MIX_S 0x00070007L
  773. #define DP_MIX_DSan 0x00080008L
  774. #define DP_MIX_DSno 0x00090009L
  775. #define DP_MIX_SDno 0x000A000AL
  776. #define DP_MIX_DSo 0x000B000BL
  777. #define DP_MIX_DSa 0x000C000CL
  778. #define DP_MIX_SDna 0x000D000DL
  779. #define DP_MIX_DSna 0x000E000EL
  780. #define DP_MIX_DSon 0x000F000FL
  781. #define DP_MIX_0x17 0x00170017L
  782. // DP_SRC
  783. #define DP_BKGD_SRC 0x00000007L
  784. #define DP_FRGD_SRC 0x00000700L
  785. #define DP_MONO_SRC 0x00030000L
  786. #define DP_SRC_BKGD 0x00000000L
  787. #define DP_SRC_FRGD 0x00000101L
  788. #define DP_SRC_HOST 0x00020202L
  789. #define DP_SRC_VRAM 0x00030303L
  790. #define DP_SRC_PATT 0x00010404L
  791. // CLR_CMP_CNTL
  792. #define CLR_CMP_FCN 0x00000007L
  793. #define CLR_CMP_SRC 0x01000000L
  794. #define CLR_CMP_FCN_FALSE 0x00000000L
  795. #define CLR_CMP_FCN_TRUE 0x00000001L
  796. #define CLR_CMP_FCN_NE 0x00000004L
  797. #define CLR_CMP_FCN_EQ 0x00000005L
  798. // DST_CNTL
  799. #define DST_X_DIR 0x00000001L
  800. #define DST_Y_DIR 0x00000002L
  801. #define DST_Y_MAJOR 0x00000004L
  802. #define DST_X_TILE 0x00000008L
  803. #define DST_Y_TILE 0x00000010L
  804. #define DST_LAST_PEL 0x00000020L
  805. #define DST_POLYGON_EN 0x00000040L
  806. #define DST_24_ROT_EN 0x00000080L
  807. #define DST_24_ROT 0x00000700L
  808. #define DST_BRES_SIGN 0x00000800L
  809. // SRC Shifts
  810. #define SHIFT_SRC_PITCH 22
  811. #define SHIFT_SRC_X 16
  812. #define SHIFT_SRC_WIDTH1 16
  813. #define SHIFT_SRC_X_START 16
  814. #define SHIFT_SRC_WIDTH2 16
  815. // SRC_CNTL
  816. #define SRC_PATT_EN 0x00000001L
  817. #define SRC_PATT_ROT_EN 0x00000002L
  818. #define SRC_LINEAR_EN 0x00000004L
  819. #define SRC_BYTE_ALIGN 0x00000008L
  820. #define ONE_WORD 0x8000
  821. #define TWO_WORDS 0xC000
  822. #define THREE_WORDS 0xE000
  823. #define FOUR_WORDS 0xF000
  824. #define FIVE_WORDS 0xF800
  825. #define SIX_WORDS 0xFC00
  826. #define SEVEN_WORDS 0xFE00
  827. #define EIGHT_WORDS 0xFF00
  828. #define NINE_WORDS 0xFF80
  829. #define TEN_WORDS 0xFFC0
  830. #define ELEVEN_WORDS 0xFFE0
  831. #define TWELVE_WORDS 0xFFF0
  832. #define THIRTEEN_WORDS 0xFFF8
  833. #define FOURTEEN_WORDS 0xFFFC
  834. #define FIFTEEN_WORDS 0xFFFE
  835. #define SIXTEEN_WORDS 0xFFFF
  836. #define REG_W 0 // DAC REGS offset for Write
  837. #define REG_D 1 // DAC REGS offset for Data
  838. #define REG_M 2 // DAC REGS offset for Mask
  839. #define REG_R 3 // DAC REGS offset for Read
  840. #define MAX_NEGX 4096
  841. #define M64_MAX_SCISSOR_R 4095 /* Maximum right scissors value */
  842. #define M64_MAX_SCISSOR_B 16383 /* Maximum bottom scissors value */
  843. #define CRTC_VBLANK 0x00000001L
  844. #define MUL24 3
  845. ////////////////////////////////////////////////////////////////////////////
  846. // Mach64 Port Access
  847. ////////////////////////////////////////////////////////////////////////////
  848. // NOTE: This macro must not be used if 'y' can be negative:
  849. #define PACKXY(x, y) (((x) << 16) | ((y) & 0xffff))
  850. #define PACKXY_FAST(x, y) (((x) << 16) | ((y) & 0xffff))
  851. //#define PACKXY_FAST(x, y) (((x) << 16) | (y))
  852. #define PACKPAIR(a, b) (((b) << 16) | (a))
  853. #if !( defined(ALPHA) || defined(_AXP64_) || defined(AXP64) )
  854. #define M64_ID_DIRECT(pbase,port) \
  855. READ_REGISTER_ULONG((ULONG*) pbase + (port))
  856. #define M64_OD_DIRECT(pbase,port,val) \
  857. WRITE_REGISTER_ULONG((ULONG*) pbase + (port), (val)); \
  858. CP_EIEIO()
  859. #else
  860. extern BOOL isDense;
  861. #define M64_ID_DIRECT(pbase,port) \
  862. (isDense? *((ULONG*) pbase + \
  863. (port)):READ_REGISTER_ULONG((ULONG*) pbase + (port)))
  864. #define M64_OD_DIRECT(pbase,port,val) \
  865. { \
  866. if (isDense) \
  867. *((ULONG*) pbase + (port)) = (ULONG) (val); \
  868. else { \
  869. WRITE_REGISTER_ULONG((ULONG*) pbase + (port), (val)); } \
  870. CP_MEMORY_BARRIER(); \
  871. }
  872. #endif
  873. VOID vM64DataPortOutB(PDEV *ppdev, PBYTE pb, UINT count);
  874. /////////////////////////////////////////////////////////////////////////
  875. // Mach64 FIFO access
  876. //
  877. // The following macros should be used for all accesses to FIFO registers.
  878. // On checked builds, they enforce proper FIFO usage protocol; on free
  879. // builds, they incur no overhead.
  880. #define M64_ID(pbase,port) (M64_ID_DIRECT(pbase,port))
  881. #define M64_OD(pbase,port,val) {CHECK_FIFO_WRITE(); M64_OD_DIRECT(pbase,port,val);}
  882. #if DBG
  883. VOID vCheckFifoWrite();
  884. VOID vM64CheckFifoSpace(PDEV*, VOID*, LONG);
  885. ULONG ulM64FastFifoCheck(PDEV*, VOID*, LONG, ULONG);
  886. #define CHECK_FIFO_WRITE() \
  887. vCheckFifoWrite()
  888. #define M64_CHECK_FIFO_SPACE(ppdev, pbase, level) \
  889. vM64CheckFifoSpace(ppdev, pbase, level)
  890. #define M64_FAST_FIFO_CHECK(ppdev, pbase, level, ulFifo) \
  891. (ulFifo) = ulM64FastFifoCheck(ppdev, pbase, level, ulFifo)
  892. #define I32_FIFO_SPACE_AVAIL(ppdev, pbase, level) \
  893. (I32_IW((pbase), EXT_FIFO_STATUS) & (0x10000L >> (level))) \
  894. #define M32_FIFO_SPACE_AVAIL(ppdev, pbase, level) \
  895. (M32_IW((pbase), EXT_FIFO_STATUS) & (0x10000L >> (level))) \
  896. #define M64_FIFO_SPACE_AVAIL(ppdev, pbase, level) \
  897. (M64_ID((pbase), FIFO_STAT) & (0x10000L >> (level))) \
  898. #else
  899. #define CHECK_FIFO_WRITE()
  900. #define M64_CHECK_FIFO_SPACE(ppdev, pbase, level) \
  901. { \
  902. while (M64_ID((pbase), FIFO_STAT) & (0x10000L >> (level))) \
  903. ; \
  904. }
  905. // This handy little macro is useful for amortizing the read cost of
  906. // the status register:
  907. #define M64_FAST_FIFO_CHECK(ppdev, pbase, level, ulFifo) \
  908. { \
  909. while (!((ulFifo) & (0x10000L >> (level)))) \
  910. { \
  911. (ulFifo) = ~M64_ID((pbase), FIFO_STAT); /* Invert bits */ \
  912. } \
  913. (ulFifo) <<= (level); \
  914. }
  915. #define M64_FIFO_SPACE_AVAIL(ppdev, pbase, level) \
  916. (M64_ID((pbase), FIFO_STAT) & (0x10000L >> (level))) \
  917. #define I32_FIFO_SPACE_AVAIL(ppdev, pbase, level) \
  918. (I32_IW((pbase), EXT_FIFO_STATUS) & (0x10000L >> (level))) \
  919. #define M32_FIFO_SPACE_AVAIL(ppdev, pbase, level) \
  920. (M32_IW((pbase), EXT_FIFO_STATUS) & (0x10000L >> (level))) \
  921. #endif
  922. // Wait for engine idle. These macros are used to work around timing
  923. // problems due to flakey hardware.
  924. #define vM64QuietDown(ppdev,pjBase) \
  925. { \
  926. M64_CHECK_FIFO_SPACE(ppdev, pjBase, 16); \
  927. CP_EIEIO(); \
  928. do {} while (M64_ID(pjBase, GUI_STAT) & 1); \
  929. }
  930. #define vM32QuietDown(ppdev,pjBase) \
  931. { \
  932. M32_CHECK_FIFO_SPACE(ppdev, pjBase, 16); \
  933. do {} while (M32_IW(pjBase, EXT_GE_STATUS) & GE_ACTIVE); \
  934. }
  935. #define vI32QuietDown(ppdev,pjBase) \
  936. { \
  937. I32_CHECK_FIFO_SPACE(ppdev, pjBase, 16); \
  938. do {} while (I32_IW(pjBase, EXT_GE_STATUS) & GE_ACTIVE); \
  939. }
  940. // DDraw macros
  941. #define IN_VBLANK_64( pjMmBase )(M64_ID (pjMmBase, CRTC_INT_CNTL ) & CRTC_VBLANK)
  942. #define CURRENT_VLINE_64( pjMmBase)((WORD)(M64_ID(pjMmBase,CRTC_CRNT_VLINE)>>16))
  943. #define DRAW_ENGINE_BUSY_64( ppdev, pjMmBase) (((M64_FIFO_SPACE_AVAIL(ppdev,pjMmBase, 16 )) || ((M64_ID(pjMmBase, GUI_STAT)) & GUI_ACTIVE)))
  944. // the next define is for overlay support
  945. #define DD_WriteVTReg(port,val) { \
  946. WRITE_REGISTER_ULONG((ULONG*) ppdev->pjMmBase_Ext + (port), (val)); \
  947. CP_MEMORY_BARRIER(); \
  948. }
  949. // Special I/O routines to read DAC regs on the mach64 (for relocatable I/O)
  950. #define rioIB(port) READ_PORT_UCHAR((port))
  951. #define rioOB(port, val) WRITE_PORT_UCHAR((port), (val))
  952. ////////////////////////////////////////////////////////////////////////////////
  953. // Context Stuff
  954. //
  955. // Default context used to initialize the hardware before graphics operations.
  956. // Certain registers, such as DP_WRITE_MASK and CLR_CMP_CNTL, need to be reset
  957. // because they fail to latch properly after a blit operation. Mach64 only.
  958. VOID vSetDefaultContext(PDEV * ppdev);
  959. VOID vEnableContexts(PDEV * ppdev);
  960. // For overlay support
  961. /////////////////////////////////////////////////////////////////////////////
  962. // DirectDraw stuff
  963. #define IS_RGB15_R(flRed) \
  964. (flRed == 0x7c00)
  965. #define IS_RGB15(this) \
  966. (((this)->dwRBitMask == 0x7c00) && \
  967. ((this)->dwGBitMask == 0x03e0) && \
  968. ((this)->dwBBitMask == 0x001f))
  969. #define IS_RGB16(this) \
  970. (((this)->dwRBitMask == 0xf800) && \
  971. ((this)->dwGBitMask == 0x07e0) && \
  972. ((this)->dwBBitMask == 0x001f))
  973. #define IS_RGB24(this) \
  974. (((this)->dwRBitMask == 0x00ff0000) && \
  975. ((this)->dwGBitMask == 0x0000ff00) && \
  976. ((this)->dwBBitMask == 0x000000ff))
  977. #define IS_RGB32(this) \
  978. (((this)->dwRBitMask == 0x00ff0000) && \
  979. ((this)->dwGBitMask == 0x0000ff00) && \
  980. ((this)->dwBBitMask == 0x000000ff))
  981. #define RGB15to32(c) \
  982. (((c & 0x7c00) << 9) | \
  983. ((c & 0x03e0) << 6) | \
  984. ((c & 0x001f) << 3))
  985. #define RGB16to32(c) \
  986. (((c & 0xf800) << 8) | \
  987. ((c & 0x07e0) << 5) | \
  988. ((c & 0x001f) << 3))
  989. // end macros for overlay support