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.

425 lines
12 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: debug.c
  8. *
  9. * Content: Debug helper routines.
  10. *
  11. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-2003 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #include "glint.h"
  16. #if DBG
  17. //@@BEGIN_DDKSPLIT
  18. #if 0
  19. LONG gcFifo = 0; // Number of currently free FIFO entries
  20. BOOL gbCrtcCriticalSection = FALSE;
  21. // Have we acquired the CRTC register
  22. // critical section?
  23. // single-shot list output (checked in DebugPrint)
  24. BOOL bPrintList = FALSE;
  25. // single-shot memory viewer (checked in DebugPrint)
  26. int bSetViewableScanline = 0;
  27. int nViewableScanline = 0;
  28. #define LARGE_LOOP_COUNT 10000000
  29. /******************************Public*Routine******************************\
  30. * VOID vCheckDataComplete
  31. \**************************************************************************/
  32. VOID vCheckDataReady(
  33. PDEV* ppdev)
  34. {
  35. ASSERTDD((IO_GP_STAT(ppdev) & HARDWARE_BUSY),
  36. "Not ready for data transfer.");
  37. }
  38. /******************************Public*Routine******************************\
  39. * VOID vCheckDataComplete
  40. \**************************************************************************/
  41. VOID vCheckDataComplete(
  42. PDEV* ppdev)
  43. {
  44. LONG i;
  45. // We loop because it may take a while for the hardware to finish
  46. // digesting all the data we transferred:
  47. for (i = LARGE_LOOP_COUNT; i > 0; i--)
  48. {
  49. if (!(IO_GP_STAT(ppdev) & HARDWARE_BUSY))
  50. return;
  51. }
  52. RIP("Data transfer not complete.");
  53. }
  54. /******************************Public*Routine******************************\
  55. * VOID vOutFifoW
  56. \**************************************************************************/
  57. VOID vOutFifoW(
  58. VOID* p,
  59. ULONG v)
  60. {
  61. gcFifo--;
  62. if (gcFifo < 0)
  63. {
  64. gcFifo = 0;
  65. RIP("Incorrect FIFO wait count");
  66. }
  67. WRITE_PORT_USHORT(p, v);
  68. }
  69. /******************************Public*Routine******************************\
  70. * VOID vOutFifoPseudoD
  71. \**************************************************************************/
  72. VOID vOutFifoPseudoD(
  73. PDEV* ppdev,
  74. VOID* p,
  75. ULONG v)
  76. {
  77. ULONG ulMiscState;
  78. ASSERTDD(!(ppdev->flCaps & CAPS_MM_IO),
  79. "No pseudo 32-bit writes when using memory-mapped I/O");
  80. ASSERTDD(ppdev->iBitmapFormat == BMF_32BPP,
  81. "We're trying to do 32bpp output while not in 32bpp mode");
  82. IO_GP_WAIT(ppdev); // Wait so we don't interfere with any
  83. // pending commands waiting on the
  84. // FIFO
  85. IO_READ_SEL(ppdev, 6); // We'll be reading index 0xE
  86. IO_GP_WAIT(ppdev); // Wait until that's processed
  87. IO_RD_REG_DT(ppdev, ulMiscState); // Read ulMiscState
  88. ASSERTDD((ulMiscState & 0x10) == 0,
  89. "Register select flag is out of sync");
  90. gcFifo -= 2;
  91. if (gcFifo < 0)
  92. {
  93. gcFifo = 0;
  94. RIP("Incorrect FIFO wait count");
  95. }
  96. OUT_PSEUDO_DWORD(p, v);
  97. }
  98. /******************************Public*Routine******************************\
  99. * VOID vWriteFifoW
  100. \**************************************************************************/
  101. VOID vWriteFifoW(
  102. VOID* p,
  103. ULONG v)
  104. {
  105. gcFifo--;
  106. if (gcFifo < 0)
  107. {
  108. gcFifo = 0;
  109. RIP("Incorrect FIFO wait count");
  110. }
  111. WRITE_REGISTER_USHORT(p, (USHORT) v);
  112. }
  113. /******************************Public*Routine******************************\
  114. * VOID vWriteFifoD
  115. \**************************************************************************/
  116. VOID vWriteFifoD(
  117. VOID* p,
  118. ULONG v)
  119. {
  120. gcFifo--;
  121. if (gcFifo < 0)
  122. {
  123. gcFifo = 0;
  124. RIP("Incorrect FIFO wait count");
  125. }
  126. WRITE_REGISTER_ULONG(p, v);
  127. }
  128. /******************************Public*Routine******************************\
  129. * VOID vIoFifoWait
  130. \**************************************************************************/
  131. VOID vIoFifoWait(
  132. PDEV* ppdev,
  133. LONG level)
  134. {
  135. LONG i;
  136. ASSERTDD((level > 0) && (level <= 8), "Illegal wait level");
  137. gcFifo = level;
  138. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  139. {
  140. #ifdef _PPC_
  141. if( level == 8 )
  142. if( IO_GP_STAT(ppdev) & GP_ALL_EMPTY )
  143. return; // all fifo slots are empty
  144. else;
  145. else
  146. if( !(IO_GP_STAT(ppdev) & (FIFO_1_EMPTY >> (level))) )
  147. return; // There are 'level + 1' entries free
  148. #else
  149. if (!(IO_GP_STAT(ppdev) & ((FIFO_1_EMPTY << 1) >> (level))))
  150. return; // There are 'level' entries free
  151. #endif
  152. }
  153. RIP("vIoFifoWait timeout -- The hardware is in a funky state.");
  154. }
  155. /******************************Public*Routine******************************\
  156. * VOID vNwFifoWait
  157. \**************************************************************************/
  158. VOID vNwFifoWait(
  159. PDEV* ppdev,
  160. BYTE* pjMmBase,
  161. LONG level)
  162. {
  163. LONG i;
  164. ASSERTDD((level > 0) && (level <= 13), "Illegal wait level");
  165. gcFifo = level;
  166. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  167. {
  168. if (level <= 8)
  169. {
  170. if (!(READ_REGISTER_USHORT(pjMmBase + CMD)
  171. & (0x0080 >> (level - 1))))
  172. return;
  173. }
  174. else
  175. {
  176. if (!(READ_REGISTER_USHORT(pjMmBase + CMD)
  177. & (0x8000 >> (level - 9))))
  178. return;
  179. }
  180. }
  181. RIP("vNwFifoWait timeout -- The hardware is in a funky state.");
  182. }
  183. /******************************Public*Routine******************************\
  184. * VOID vDbgFakeWait
  185. \**************************************************************************/
  186. VOID vDbgFakeWait(
  187. PDEV* ppdev,
  188. BYTE* pjMmBase,
  189. LONG level)
  190. {
  191. gcFifo = level;
  192. }
  193. /******************************Public*Routine******************************\
  194. * VOID vIoGpWait
  195. \**************************************************************************/
  196. VOID vIoGpWait(
  197. PDEV* ppdev)
  198. {
  199. LONG i;
  200. gcFifo = (ppdev->flCaps & CAPS_16_ENTRY_FIFO) ? 16 : 8;
  201. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  202. {
  203. if (!(IO_GP_STAT(ppdev) & HARDWARE_BUSY))
  204. return; // It isn't busy
  205. }
  206. RIP("vIoGpWait timeout -- The hardware is in a funky state.");
  207. }
  208. /******************************Public*Routine******************************\
  209. * VOID vNwGpWait
  210. \**************************************************************************/
  211. VOID vNwGpWait(
  212. PDEV* ppdev,
  213. BYTE* pjMmBase)
  214. {
  215. LONG i;
  216. gcFifo = 16;
  217. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  218. {
  219. if (!(READ_REGISTER_USHORT(pjMmBase + CMD) & HARDWARE_BUSY))
  220. return; // It isn't busy
  221. }
  222. RIP("vNwGpWait timeout -- The hardware is in a funky state.");
  223. }
  224. /******************************Public*Routine******************************\
  225. * VOID vIoAllEmpty
  226. \**************************************************************************/
  227. VOID vIoAllEmpty(
  228. PDEV* ppdev)
  229. {
  230. LONG i;
  231. ASSERTDD(ppdev->flCaps & CAPS_16_ENTRY_FIFO,
  232. "Can't call ALL_EMPTY on chips with 8-deep FIFOs");
  233. gcFifo = 16;
  234. for (i = LARGE_LOOP_COUNT; i != 0; i--)
  235. {
  236. if (IO_GP_STAT(ppdev) & GP_ALL_EMPTY) // Not implemented on 911/924s
  237. return;
  238. }
  239. RIP("ALL_EMPTY timeout -- The hardware is in a funky state.");
  240. }
  241. /******************************Public*Routines*****************************\
  242. * UCHAR jInp() - INP()
  243. * USHORT wInpW() - INPW()
  244. * VOID vOutp() - OUTP()
  245. * VOID vOutpW() - OUTPW()
  246. *
  247. * Debug thunks for general I/O routines. This is used primarily to verify
  248. * that any code accessing the CRTC register has grabbed the CRTC critical
  249. * section (necessary because with GCAPS_ASYNCMOVE, DrvMovePointer calls
  250. * may happen at any time, and they need to access the CRTC register).
  251. *
  252. \**************************************************************************/
  253. UCHAR jInp(BYTE* pjIoBase, ULONG p)
  254. {
  255. if (((p == CRTC_INDEX) || (p == CRTC_DATA)) &&
  256. (!gbCrtcCriticalSection))
  257. {
  258. RIP("Must have acquired CRTC critical section to access CRTC register");
  259. }
  260. CP_EIEIO();
  261. return(READ_PORT_UCHAR(pjIoBase + (p)));
  262. }
  263. USHORT wInpW(BYTE* pjIoBase, ULONG p)
  264. {
  265. if (((p == CRTC_INDEX) || (p == CRTC_DATA)) &&
  266. (!gbCrtcCriticalSection))
  267. {
  268. RIP("Must have acquired CRTC critical section to access CRTC register");
  269. }
  270. CP_EIEIO();
  271. return(READ_PORT_USHORT(pjIoBase + (p)));
  272. }
  273. VOID vOutp(BYTE* pjIoBase, ULONG p, ULONG v)
  274. {
  275. if (((p == CRTC_INDEX) || (p == CRTC_DATA)) &&
  276. (!gbCrtcCriticalSection))
  277. {
  278. RIP("Must have acquired CRTC critical section to access CRTC register");
  279. }
  280. CP_EIEIO();
  281. WRITE_PORT_UCHAR(pjIoBase + (p), (v));
  282. CP_EIEIO();
  283. }
  284. VOID vOutpW(BYTE* pjIoBase, ULONG p, ULONG v)
  285. {
  286. if (((p == CRTC_INDEX) || (p == CRTC_DATA)) &&
  287. (!gbCrtcCriticalSection))
  288. {
  289. RIP("Must have acquired CRTC critical section to access CRTC register");
  290. }
  291. CP_EIEIO();
  292. WRITE_PORT_USHORT(pjIoBase + (p), (v));
  293. CP_EIEIO();
  294. }
  295. /******************************Public*Routine******************************\
  296. * VOID vAcquireCrtc()
  297. * VOID vReleaseCrtc()
  298. *
  299. * Debug thunks for grabbing the CRTC register critical section.
  300. *
  301. \**************************************************************************/
  302. VOID vAcquireCrtc(PDEV* ppdev)
  303. {
  304. EngAcquireSemaphore(ppdev->csCrtc);
  305. if (gbCrtcCriticalSection)
  306. RIP("Had already acquired Critical Section");
  307. gbCrtcCriticalSection = TRUE;
  308. }
  309. VOID vReleaseCrtc(PDEV* ppdev)
  310. {
  311. // 80x/805i/928 and 928PCI chips have a bug where if I/O registers
  312. // are left unlocked after accessing them, writes to memory with
  313. // similar addresses can cause writes to I/O registers. The problem
  314. // registers are 0x40, 0x58, 0x59 and 0x5c. We will simply always
  315. // leave the index set to an innocuous register (namely, the text
  316. // mode cursor start scan line):
  317. OUTP(ppdev->pjIoBase, CRTC_INDEX, 0xa);
  318. if (!gbCrtcCriticalSection)
  319. RIP("Hadn't yet acquired Critical Section");
  320. gbCrtcCriticalSection = FALSE;
  321. EngReleaseSemaphore(ppdev->csCrtc);
  322. }
  323. #if VERIFY_CHECKFLAGS
  324. void __CheckFlags(PDEV *ppdev, ULONG x)
  325. {
  326. ULONG lop, fbr, cFlags = ppdev->cFlags;
  327. GLINT_DECL;
  328. SYNC_WITH_GLINT;
  329. READ_GLINT_FIFO_REG (__GlintTagLogicalOpMode, lop);
  330. READ_GLINT_FIFO_REG (__GlintTagFBReadMode, fbr);
  331. READ_GLINT_FIFO_REG (__GlintTagLogicalOpMode, lop);
  332. ASSERTDD ((cFlags & cFlagFBReadDefault) == 0 || ((cFlags & cFlagFBReadDefault) && fbr == glintInfo->FBReadMode), "SCF: Bad check fbread cache flag");
  333. ASSERTDD ((cFlags & cFlagLogicalOpDisabled) == 0 || ((cFlags & cFlagLogicalOpDisabled) && (lop & 0x1) == 0x0), "SCF: Bad check logicop cache flag");
  334. ASSERTDD ((cFlags & cFlagConstantFBWrite) == 0 || ((cFlags & cFlagConstantFBWrite) && (lop & (1<<5))), "SCF: Bad check const fbwrite cache flag");
  335. }
  336. #endif //VERIFY_CHECKFLAGS
  337. #endif // if 0
  338. //@@END_DDKSPLIT
  339. ////////////////////////////////////////////////////////////////////////////
  340. #endif // DBG