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.

1114 lines
30 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * Module Name: enable.c
  4. *
  5. * This module contains the functions that enable and disable the
  6. * driver, the pdev, and the surface.
  7. *
  8. * Copyright (c) 1995,1996 Cirrus Logic, Inc.
  9. *
  10. * $Log: X:/log/laguna/nt35/displays/cl546x/ENABLE.C $
  11. *
  12. * Rev 1.46 Jan 20 1998 11:44:38 frido
  13. * The fDataStreaming flag has changed its value from 1 into 0x80000000.
  14. *
  15. * Rev 1.45 Nov 04 1997 10:12:24 frido
  16. * Added IOCtl call to Miniport to get the AGPDataStreaming value.
  17. *
  18. * Rev 1.44 Nov 03 1997 15:21:46 frido
  19. * Added REQUIRE macros.
  20. *
  21. * Rev 1.43 16 Oct 1997 09:55:04 bennyn
  22. *
  23. * Added bPrevModeDDOutOfVideoMem to DrvResetPDEV
  24. *
  25. * Rev 1.42 08 Aug 1997 17:24:00 FRIDO
  26. * Added support for new memory manager.
  27. *
  28. * Rev 1.41 02 Jul 1997 15:56:00 noelv
  29. * Added LgMatchDriverToChip() function. Moved driver/chip match from bin
  30. * from binitSurface to DrvEnablePdev()
  31. *
  32. * Rev 1.40 29 Apr 1997 16:28:40 noelv
  33. *
  34. * Merged in new SWAT code.
  35. * SWAT:
  36. * SWAT: Rev 1.3 24 Apr 1997 11:37:28 frido
  37. * SWAT: NT140b09 merge.
  38. * SWAT:
  39. * SWAT: Rev 1.2 18 Apr 1997 00:15:02 frido
  40. * SWAT: NT140b07 merge.
  41. * SWAT:
  42. * SWAT: Rev 1.1 09 Apr 1997 17:32:34 frido
  43. * SWAT: Called vAssertModeText in DrvAssertMode.
  44. *
  45. * Rev 1.39 09 Apr 1997 10:50:40 SueS
  46. * Changed sw_test_flag to pointer_switch.
  47. *
  48. * Rev 1.38 09 Apr 1997 07:52:38 noelv
  49. * Disabled the MCD code for NT 3.51
  50. *
  51. * Rev 1.37 08 Apr 1997 12:21:24 einkauf
  52. *
  53. * new hooks for MCD when reset; add SYNC/IDLE for MCD/2D coordination
  54. *
  55. * Rev 1.36 21 Mar 1997 10:59:12 noelv
  56. *
  57. * Combined the loggong flags into one ENABLE_LOGFILE flag.
  58. * Removed PROFILE_DRIVER flag
  59. * Added code to initialize QfreeData
  60. *
  61. * Rev 1.35 26 Feb 1997 13:19:42 noelv
  62. *
  63. * Disable MCD code for NT 3.5x
  64. *
  65. * Rev 1.34 26 Feb 1997 09:22:10 noelv
  66. *
  67. * Changed initial debugging message for 5465
  68. * Added init code for MCD
  69. *
  70. * Rev 1.33 19 Feb 1997 13:15:32 noelv
  71. *
  72. * Added translation table cache
  73. *
  74. * Rev 1.32 28 Jan 1997 16:18:42 bennyn
  75. * Commented out "DrvEnableSurface failed bInitSurf" message
  76. *
  77. * Rev 1.31 06 Jan 1997 11:04:28 SueS
  78. * Enabled DrvLineTo, since it's been fixed.
  79. *
  80. * Rev 1.30 18 Dec 1996 11:38:22 noelv
  81. *
  82. * Unhooked DrvLineTo, 'cause it's broken.
  83. *
  84. * Rev 1.29 17 Dec 1996 16:53:24 SueS
  85. * Added test for writing to log file based on cursor at (0,0).
  86. *
  87. * Rev 1.28 27 Nov 1996 11:32:44 noelv
  88. * Disabled Magic Bitmap. Yeah!!!
  89. *
  90. * Rev 1.27 26 Nov 1996 10:16:58 SueS
  91. * Changed WriteLogFile parameters for buffering.
  92. *
  93. * Rev 1.26 13 Nov 1996 16:58:14 SueS
  94. * Changed WriteFile calls to WriteLogFile.
  95. *
  96. * Rev 1.25 13 Nov 1996 08:17:18 noelv
  97. *
  98. * Disabled test blt.
  99. *
  100. * Rev 1.24 07 Nov 1996 16:11:54 bennyn
  101. *
  102. * Restore lost version (add drvresetPDEV support)
  103. *
  104. * Rev 1.23 31 Oct 1996 11:15:40 noelv
  105. *
  106. * Split common buffer into two buffers.
  107. *
  108. * Rev 1.22 24 Oct 1996 14:40:38 noelv
  109. * Demo bus master capabilities of 5464
  110. *
  111. * Rev 1.20 06 Sep 1996 08:55:02 noelv
  112. * Hooked DrvStrokeAndFillPath and DrvStretchBlt when doinng analysis.
  113. *
  114. * Rev 1.19 20 Aug 1996 11:03:24 noelv
  115. * Bugfix release from Frido 8-19-96
  116. *
  117. * Rev 1.3 18 Aug 1996 22:48:36 frido
  118. * #lineto - Added DrvLineTo.
  119. *
  120. * Rev 1.2 15 Aug 1996 12:09:34 frido
  121. * Fixed NT 3.51/4.0 in DrvEnablePDEV.
  122. *
  123. * Rev 1.1 15 Aug 1996 11:42:40 frido
  124. * Added precompiled header.
  125. *
  126. * Rev 1.0 14 Aug 1996 17:16:20 frido
  127. * Initial revision.
  128. *
  129. * Rev 1.18 07 Aug 1996 09:34:04 noelv
  130. *
  131. * re-hooked textout
  132. *
  133. * Rev 1.17 25 Jul 1996 15:57:44 bennyn
  134. *
  135. * Modified for DirectDraw
  136. *
  137. * Rev 1.16 12 Jul 1996 09:38:22 bennyn
  138. * Added getdisplayduration call for DirectDraw
  139. *
  140. * Rev 1.15 11 Jul 1996 15:53:50 bennyn
  141. *
  142. * Added DirectDraw support
  143. *
  144. * Rev 1.14 17 May 1996 12:55:34 bennyn
  145. * Fixed the problem NT40 allocate 400x90 twice
  146. *
  147. * Rev 1.13 16 May 1996 14:54:22 noelv
  148. * Added logging code.
  149. *
  150. * Rev 1.12 01 May 1996 12:06:44 bennyn
  151. *
  152. * Fixed resolution change bug for NT 4.0
  153. *
  154. * Rev 1.11 01 May 1996 10:59:10 bennyn
  155. *
  156. * Modified for NT4.0
  157. *
  158. * Rev 1.10 25 Apr 1996 22:39:50 noelv
  159. * Cleaned up data logging.
  160. *
  161. * Rev 1.9 04 Apr 1996 13:20:14 noelv
  162. * Frido release 26
  163. *
  164. * Rev 1.13 02 Apr 1996 09:08:36 frido
  165. * Bellevue lg102b04 release.
  166. *
  167. * Rev 1.12 28 Mar 1996 20:02:18 frido
  168. * Added new comments.
  169. *
  170. * Rev 1.11 28 Mar 1996 20:01:00 frido
  171. * Fixed bouncing screeen when cursor is disabled.
  172. *
  173. * Rev 1.10 25 Mar 1996 12:05:34 frido
  174. * Changed #ifdef LOG_CALLS into #if LOG_CALLS.
  175. * Removed warning message.
  176. *
  177. * Rev 1.9 25 Mar 1996 11:52:46 frido
  178. * Bellevue 102B03.
  179. *
  180. * Rev 1.5 12 Mar 1996 15:45:28 noelv
  181. * Added support for data logging and stroke and fill.
  182. *
  183. * Rev 1.8 12 Mar 1996 16:50:14 frido
  184. * Added stroke and fill stuff.
  185. *
  186. * Rev 1.7 29 Feb 1996 20:23:24 frido
  187. * Added bEnable flag in PPDEV.
  188. *
  189. * Rev 1.6 29 Feb 1996 19:25:08 frido
  190. * Turned HOOK_TEXTOUT flags back on for 16-bpp modes and higher.
  191. *
  192. * Rev 1.5 27 Feb 1996 16:38:10 frido
  193. * Added device bitmap store/restore.
  194. *
  195. * Rev 1.4 24 Feb 1996 01:24:18 frido
  196. * Added device bitmaps.
  197. *
  198. * Rev 1.3 03 Feb 1996 13:40:24 frido
  199. * Use the compile switch "-Dfrido=0" to disable my extensions.
  200. *
  201. * Rev 1.2 23 Jan 1996 15:14:26 frido
  202. * Added call to DrvDestroyFont.
  203. *
  204. \**************************************************************************/
  205. #include "precomp.h"
  206. #include "SWAT.h"
  207. #include "CLIOCtl.h"
  208. // The driver function table with all function index/address pairs
  209. static DRVFN gadrvfn[] =
  210. {
  211. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  212. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  213. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  214. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  215. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  216. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  217. { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
  218. { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
  219. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  220. //
  221. // Laguna Functions:
  222. //
  223. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  224. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  225. { INDEX_DrvSynchronize, (PFN) DrvSynchronize },
  226. { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt },
  227. { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits },
  228. { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush },
  229. { INDEX_DrvPaint, (PFN) DrvPaint },
  230. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  231. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  232. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  233. { INDEX_DrvDestroyFont, (PFN) DrvDestroyFont },
  234. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  235. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  236. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  237. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  238. #ifdef WINNT_VER40
  239. { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo },
  240. { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw },
  241. { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw },
  242. { INDEX_DrvLineTo, (PFN) DrvLineTo },
  243. { INDEX_DrvResetPDEV, (PFN) DrvResetPDEV },
  244. #define LGHOOK_LINETO HOOK_LINETO
  245. #else
  246. #define LGHOOK_LINETO 0
  247. #endif
  248. //
  249. // We don't accelerate DrvStrokeAndFillPath or DrvStrethcBlt.
  250. // But we do want to hook them if we're doing driver analysis.
  251. //
  252. #if NULL_STROKEFILL
  253. { INDEX_DrvStrokeAndFillPath, (PFN) DrvStrokeAndFillPath },
  254. #define LGHOOK_STROKEANDFILLPATH HOOK_STROKEANDFILLPATH
  255. #else
  256. #define LGHOOK_STROKEANDFILLPATH 0
  257. #endif
  258. #if NULL_STRETCH
  259. { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt },
  260. #define LGHOOK_STRETCHBLT HOOK_STRETCHBLT
  261. #else
  262. #define LGHOOK_STRETCHBLT 0
  263. #endif
  264. { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }
  265. };
  266. //
  267. // Define the functions you want to hook for 8/16/24/32 pel formats
  268. // We do not need to set HOOK_SYNCHRONIZEACCESS because we only support a
  269. // single surface at the moment. GDI only permits one thread to draw to
  270. // a surface at a time.
  271. // When we impliment device bitmaps, we may need to set this.
  272. //
  273. #define HOOKS_BMF8BPP (HOOK_BITBLT | HOOK_PAINT | HOOK_COPYBITS | HOOK_TEXTOUT \
  274. | HOOK_STROKEPATH | LGHOOK_LINETO | HOOK_FILLPATH \
  275. | LGHOOK_STROKEANDFILLPATH | LGHOOK_STRETCHBLT \
  276. | HOOK_SYNCHRONIZE | HOOK_SYNCHRONIZEACCESS )
  277. #define HOOKS_BMF16BPP HOOKS_BMF8BPP
  278. #define HOOKS_BMF24BPP HOOKS_BMF8BPP
  279. #define HOOKS_BMF32BPP HOOKS_BMF8BPP
  280. #if DRIVER_5465
  281. #define _DISP_ "CL5465.DLL"
  282. #else
  283. #define _DISP_ "CL546x.DLL"
  284. #endif
  285. /******************************Public*Routine******************************\
  286. * DrvEnableDriver
  287. *
  288. * Enables the driver by retrieving the drivers function table and version.
  289. *
  290. \**************************************************************************/
  291. BOOL DrvEnableDriver(
  292. ULONG iEngineVersion,
  293. ULONG cj,
  294. PDRVENABLEDATA pded)
  295. {
  296. // Engine Version is passed down so future drivers can support previous
  297. // engine versions. A next generation driver can support both the old
  298. // and new engine conventions if told what version of engine it is
  299. // working with. For the first version the driver does nothing with it.
  300. iEngineVersion;
  301. // Fill in as much as we can.
  302. #ifdef WINNT_VER40
  303. #if DRIVER_5465
  304. DISPDBG((1, " ==> Cirrus Logic 5465 DISPLAY DRIVER for NT 4.0.\n"));
  305. #else // if DRIVER_5465
  306. DISPDBG((1, " ==> Cirrus Logic 546x DISPLAY DRIVER for NT 4.0.\n"));
  307. #endif // if DRIVER_5465
  308. #else
  309. #if DRIVER_5465
  310. DISPDBG((1, " ==> Cirrus Logic 5465 DISPLAY DRIVER for NT 3.5x.\n"));
  311. #else // if DRIVER_5465
  312. DISPDBG((1, " ==> Cirrus Logic 546x DISPLAY DRIVER for NT 3.5x.\n"));
  313. #endif // if DRIVER_5465
  314. #endif
  315. if (cj >= sizeof(DRVENABLEDATA))
  316. pded->pdrvfn = gadrvfn;
  317. if (cj >= (sizeof(ULONG) * 2))
  318. pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
  319. // DDI version this driver was targeted for is passed back to engine.
  320. // Future graphic's engine may break calls down to old driver format.
  321. if (cj >= sizeof(ULONG))
  322. pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
  323. return(TRUE);
  324. }
  325. /******************************Public*Routine******************************\
  326. * DrvDisableDriver
  327. *
  328. * Tells the driver it is being disabled. Release any resources allocated in
  329. * DrvEnableDriver.
  330. *
  331. \**************************************************************************/
  332. VOID DrvDisableDriver(VOID)
  333. {
  334. DISPDBG((1, _DISP_ " DrvDisableDriver\n"));
  335. return;
  336. }
  337. /******************************Public*Routine******************************\
  338. * DrvEnablePDEV
  339. *
  340. * DDI function, Enables the Physical Device.
  341. *
  342. * Return Value: device handle to pdev.
  343. *
  344. \**************************************************************************/
  345. DHPDEV DrvEnablePDEV(
  346. DEVMODEW *pDevmode, // Pointer to DEVMODE
  347. PWSTR pwszLogAddress, // Logical address
  348. ULONG cPatterns, // number of patterns
  349. HSURF *ahsurfPatterns, // return standard patterns
  350. ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
  351. ULONG *pGdiInfo, // Pointer to GdiInfo structure
  352. ULONG cjDevInfo, // Length of following PDEVINFO structure
  353. DEVINFO *pDevInfo, // physical device information structure
  354. #ifdef WINNT_VER40
  355. HDEV hdev,
  356. #else
  357. PWSTR pwszDataFile, // DataFile - not used
  358. #endif
  359. PWSTR pwszDeviceName, // DeviceName - not used
  360. HANDLE hDriver) // Handle to base driver
  361. {
  362. GDIINFO GdiInfo;
  363. DEVINFO DevInfo;
  364. PPDEV ppdev = (PPDEV) NULL;
  365. DISPDBG((1, _DISP_ " DrvEnablePDEV: Entry.\n"));
  366. // Allocate a physical device structure.
  367. #ifdef WINNT_VER40
  368. ppdev = (PPDEV) MEM_ALLOC(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
  369. #else
  370. ppdev = (PPDEV) MEM_ALLOC(LMEM_FIXED | LMEM_ZEROINIT, sizeof(PDEV));
  371. #endif
  372. if (ppdev == (PPDEV) NULL)
  373. {
  374. RIP(_DISP_ " DrvEnablePDEV failed MEM_ALLOC\n");
  375. return((DHPDEV) 0);
  376. }
  377. // Save the screen handle in the PDEV.
  378. ppdev->hDriver = hDriver;
  379. ppdev->pjScreen = 0;
  380. //
  381. // Verify the driver matches the chip.
  382. //
  383. if (!LgMatchDriverToChip(ppdev))
  384. {
  385. #if DRIVER_5465
  386. DISPDBG((1," Chip doesn't match CL5465 driver. Failing.\n"));
  387. #else
  388. DISPDBG((1," Chip doesn't match CL546x driver. Failing.\n"));
  389. #endif
  390. goto error_free;
  391. }
  392. // Init MCD.
  393. #ifndef WINNT_VER35
  394. ppdev->hMCD = NULL;
  395. ppdev->NumMCDContexts = 0;
  396. #endif
  397. // Initialize the offscreen manager initial flag to FALSE
  398. ppdev->OFM_init = FALSE;
  399. // Initialize the color translation caches to NULL
  400. ppdev->XlateCache = NULL;
  401. // Initialize the pofmMagic to NULL
  402. #if WINBENCH96
  403. ppdev->pofmMagic = NULL;
  404. #endif
  405. #if DATASTREAMING
  406. {
  407. ULONG ulReturn;
  408. BOOL fDataStreaming = FALSE;
  409. if (! DEVICE_IO_CTRL(ppdev->hDriver,
  410. IOCTL_GET_AGPDATASTREAMING,
  411. NULL,
  412. 0,
  413. (PVOID) &fDataStreaming,
  414. sizeof(fDataStreaming),
  415. &ulReturn,
  416. NULL) )
  417. {
  418. DISPDBG( (1, _DISP_ " DrvEnablePDEV: failed to get "
  419. "AGPDataStreaming flag\n") );
  420. fDataStreaming = FALSE; // default to OFF
  421. }
  422. ppdev->dwDataStreaming = fDataStreaming ? 0x80000000 : 0;
  423. }
  424. #endif
  425. // Get the current screen mode information. Set up device caps and devinfo.
  426. if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
  427. {
  428. DISPDBG((1,_DISP_ " DrvEnablePDEV: bInitPDEV failed\n"));
  429. goto error_free;
  430. }
  431. // Initialize palette information.
  432. if (!bInitPaletteInfo(ppdev, &DevInfo))
  433. {
  434. RIP(_DISP_ " DrvEnablePDEV: failed bInitPalette\n");
  435. goto error_free;
  436. }
  437. // Initialize device standard patterns.
  438. if (!bInitPatterns(ppdev, min(cPatterns, HS_DDI_MAX)))
  439. {
  440. RIP(_DISP_ " DrvEnablePDEV: failed bInitPatterns\n");
  441. vDisablePatterns(ppdev);
  442. vDisablePalette(ppdev);
  443. goto error_free;
  444. }
  445. // Copy the devinfo into the engine buffer.
  446. memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
  447. // Set the ahsurfPatterns array to handles each of the standard
  448. // patterns that were just created.
  449. memcpy((PVOID)ahsurfPatterns, ppdev->ahbmPat, ppdev->cPatterns*sizeof(HBITMAP));
  450. // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
  451. // pdev.
  452. memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
  453. #if ENABLE_LOG_FILE
  454. {
  455. char buf[256];
  456. int i1;
  457. #if ENABLE_LOG_SWITCH
  458. if (pointer_switch == 1)
  459. #endif
  460. {
  461. DISPDBG((1, _DISP_ " Creating log file.\n"));
  462. CreateLogFile(ppdev->hDriver, &ppdev->TxtBuffIndex);
  463. ppdev->pmfile = ppdev->hDriver; // handle to the miniport
  464. if (ppdev->pmfile == (HANDLE)-1) // INVALID_HANDLE_VALUE
  465. RIP( _DISP_ " Couldn't create log file!\n");
  466. i1 = sprintf(buf, _DISP_ " Log file opened.\r\n");
  467. WriteLogFile(ppdev->pmfile, buf, i1, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  468. }
  469. }
  470. #endif
  471. #if LOG_QFREE
  472. {
  473. int i;
  474. for (i=0; i<32; ++i)
  475. QfreeData[i] = 0;
  476. }
  477. #endif
  478. DISPDBG((1, _DISP_ " DrvEnablePDEV: Succeeded.\n"));
  479. return((DHPDEV) ppdev);
  480. // Error case for failure.
  481. error_free:
  482. MEMORY_FREE(ppdev);
  483. DISPDBG((1, _DISP_ " DrvEnablePDEV: Failed.\n"));
  484. return((DHPDEV) 0);
  485. }
  486. /******************************Public*Routine******************************\
  487. * DrvCompletePDEV
  488. *
  489. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  490. *
  491. \**************************************************************************/
  492. VOID DrvCompletePDEV(
  493. DHPDEV dhpdev,
  494. HDEV hdev)
  495. {
  496. DISPDBG((1, _DISP_ " DrvCompletePDEV\n"));
  497. ((PPDEV) dhpdev)->hdevEng = hdev;
  498. }
  499. /******************************Public*Routine******************************\
  500. * DrvDisablePDEV
  501. *
  502. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  503. * enabled DrvDisableSurface will have already been called.
  504. *
  505. \**************************************************************************/
  506. VOID DrvDisablePDEV(
  507. DHPDEV dhpdev)
  508. {
  509. PPDEV ppdev;
  510. DISPDBG((1, _DISP_ " DrvDisablePDEV\n"));
  511. ppdev = (PPDEV) dhpdev;
  512. vDisablePalette((PPDEV) dhpdev);
  513. vDisablePatterns((PPDEV) dhpdev);
  514. MEMORY_FREE(dhpdev);
  515. }
  516. /******************************Public*Routine******************************\
  517. * DrvEnableSurface
  518. *
  519. * Enable the surface for the device. Hook the calls this driver supports.
  520. *
  521. * Return: Handle to the surface if successful, 0 for failure.
  522. *
  523. \**************************************************************************/
  524. HSURF DrvEnableSurface(
  525. DHPDEV dhpdev)
  526. {
  527. PPDEV ppdev;
  528. HSURF hsurf;
  529. SIZEL sizl;
  530. ULONG ulBitmapType;
  531. FLONG flHooks;
  532. DISPDBG((1, _DISP_ " DrvEnableSurface Entry.\n"));
  533. // Create engine bitmap around frame buffer.
  534. ppdev = (PPDEV) dhpdev;
  535. if (!bInitSURF(ppdev, TRUE))
  536. {
  537. // Comments out this message because new two drivers model will break
  538. // here every time from power-up.
  539. // RIP(_DISP_ " DrvEnableSurface failed bInitSURF\n");
  540. goto ReturnFailure;
  541. }
  542. #ifdef WINNT_VER40
  543. ppdev->pvTmpBuffer = MEM_ALLOC(0, TMP_BUFFER_SIZE, ALLOC_TAG);
  544. #else
  545. ppdev->pvTmpBuffer = VirtualAlloc(NULL, TMP_BUFFER_SIZE, MEM_RESERVE |
  546. MEM_COMMIT, PAGE_READWRITE);
  547. #endif
  548. if (ppdev->pvTmpBuffer == NULL)
  549. {
  550. DISPDBG((1, _DISP_ " DrvEnableSurface - Failed VirtualAlloc"));
  551. goto ReturnFailure;
  552. }
  553. sizl.cx = ppdev->cxScreen;
  554. sizl.cy = ppdev->cyScreen;
  555. if (ppdev->ulBitCount == 8)
  556. {
  557. if (!bInit256ColorPalette(ppdev)) {
  558. RIP(_DISP_ " DrvEnableSurface failed to init the 8bpp palette\n");
  559. goto ReturnFailure;
  560. }
  561. ulBitmapType = BMF_8BPP;
  562. flHooks = HOOKS_BMF8BPP;
  563. }
  564. else if (ppdev->ulBitCount == 16)
  565. {
  566. ulBitmapType = BMF_16BPP;
  567. flHooks = HOOKS_BMF16BPP;
  568. }
  569. else if (ppdev->ulBitCount == 24)
  570. {
  571. ulBitmapType = BMF_24BPP;
  572. flHooks = HOOKS_BMF24BPP;
  573. }
  574. else
  575. {
  576. ulBitmapType = BMF_32BPP;
  577. flHooks = HOOKS_BMF32BPP;
  578. }
  579. hsurf = (HSURF) EngCreateBitmap(sizl,
  580. ppdev->lDeltaScreen,
  581. ulBitmapType,
  582. (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
  583. (PVOID) (ppdev->pjScreen));
  584. if (hsurf == (HSURF) 0)
  585. {
  586. RIP(_DISP_ " DrvEnableSurface failed EngCreateBitmap\n");
  587. goto ReturnFailure;
  588. }
  589. ppdev->bEnable = TRUE;
  590. if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
  591. {
  592. RIP(_DISP_ " DrvEnableSurface failed EngAssociateSurface\n");
  593. EngDeleteSurface(hsurf);
  594. goto ReturnFailure;
  595. }
  596. ppdev->hsurfEng = hsurf;
  597. ppdev->iBitmapFormat = ulBitmapType;
  598. if (!bEnableText(ppdev))
  599. goto ReturnFailure;
  600. #ifdef WINNT_VER40
  601. // Accurately measure the refresh rate for DirectDraw use
  602. vGetDisplayDuration(&ppdev->flipRecord);
  603. #endif
  604. //
  605. // Demo HostToScreen BLT
  606. //
  607. #if BUS_MASTER
  608. if (ppdev->BufLength)
  609. {
  610. unsigned long i;
  611. unsigned long temp;
  612. DWORD *bufD = (DWORD *)ppdev->Buf1VirtAddr;
  613. //
  614. // init the buffer.
  615. //
  616. for (i=0; i<ppdev->BufLength/4; ++i)
  617. bufD[i] = 0x87654321;
  618. DISPDBG((1, _DISP_ " bInitSurf: \n\n **** TestBLT **** \n"));
  619. // Enable the HOST XY unit.
  620. LL32(grHXY_HOST_CRTL_3D, 1);
  621. // Write host address.
  622. LL32(grHXY_BASE1_ADDRESS_PTR_3D, ppdev->Buf1PhysAddr);
  623. // Offset into host buffer is 0
  624. LL32(grHXY_BASE1_OFFSET0_3D, 0);
  625. LL32(grHXY_BASE1_OFFSET1_3D, 0);
  626. // Setup 2D engine.
  627. REQUIRE(8);
  628. LL16 (grBLTDEF, 0x1020); // OP1 is host, RES is screen
  629. LL16 (grDRAWDEF, 0xCC); // SRCCPY
  630. // Source and destination XY address.
  631. LL16 (grOP1_opRDRAM.pt.X, 0); // source phase
  632. LL16 (grOP0_opRDRAM.pt.X, 0); // Destination x = 0;
  633. LL16 (grOP0_opRDRAM.pt.Y, 0); // Destination y = 0;
  634. // Size of destination rectangle.
  635. // This starts the 2D engine.
  636. LL16 (grMBLTEXT_EX.pt.X, 128); // Width
  637. LL16 (grBLTEXT_EX.pt.Y, 16); // Height
  638. // Write the length of the host data (in bytes)
  639. // This starts the Host XY unit.
  640. LL32(grHXY_BASE1_LENGTH_3D, ppdev->BufLength);
  641. //
  642. // Wait until HOST XY unit goes idle.
  643. //
  644. do {
  645. temp = LLDR_SZ (grPF_STATUS_3D);
  646. } while (temp & 0x80);
  647. DISPDBG((1, _DISP_ " PF_STATUS: 0x%08X\n", temp));
  648. }
  649. #endif
  650. DISPDBG((1, _DISP_ " DrvEnableSurface Exit.\n"));
  651. return(hsurf);
  652. ReturnFailure:
  653. DrvDisableSurface((DHPDEV) ppdev);
  654. DISPDBG((1, _DISP_ " Failed DrvEnableSurface"));
  655. return(0);
  656. }
  657. /******************************Public*Routine******************************\
  658. * DrvDisableSurface
  659. *
  660. * Free resources allocated by DrvEnableSurface. Release the surface.
  661. *
  662. \**************************************************************************/
  663. VOID DrvDisableSurface(
  664. DHPDEV dhpdev)
  665. {
  666. PPDEV ppdev;
  667. DISPDBG((1, _DISP_ " DrvDisableSurface Entry.\n"));
  668. ppdev = (PPDEV) dhpdev;
  669. ENSURE_3D_IDLE(ppdev);
  670. if (((PPDEV) dhpdev)->pvTmpBuffer)
  671. #ifdef WINNT_VER40
  672. MEMORY_FREE(((PPDEV) dhpdev)->pvTmpBuffer);
  673. #else
  674. VirtualFree(((PPDEV) dhpdev)->pvTmpBuffer, 0, MEM_RELEASE);
  675. #endif
  676. // Close the offscreen manager
  677. CloseOffScnMem((PPDEV) dhpdev);
  678. #ifdef WINNT_VER40
  679. if (ppdev->CShsem != NULL)
  680. EngDeleteSemaphore(ppdev->CShsem);
  681. #else
  682. DeleteCriticalSection(&ppdev->PtrCritSec);
  683. #endif
  684. if (((PPDEV) dhpdev)->hsurfEng)
  685. EngDeleteSurface(((PPDEV) dhpdev)->hsurfEng);
  686. vDisableSURF((PPDEV) dhpdev);
  687. ((PPDEV) dhpdev)->hsurfEng = (HSURF) 0;
  688. }
  689. /******************************Public*Routine******************************\
  690. * DrvAssertMode
  691. *
  692. * This asks the device to reset itself to the mode of the pdev passed in.
  693. *
  694. \**************************************************************************/
  695. #ifdef WINNT_VER40
  696. BOOL APIENTRY DrvAssertMode(
  697. #else
  698. VOID DrvAssertMode(
  699. #endif
  700. DHPDEV dhpdev,
  701. BOOL bEnable)
  702. {
  703. PPDEV ppdev = (PPDEV) dhpdev;
  704. ULONG ulReturn;
  705. DISPDBG((1, _DISP_ " DrvAssertMode, en=%d\n",bEnable));
  706. ENSURE_3D_IDLE(ppdev);
  707. #ifndef WINNT_VER35
  708. if (ppdev->hMCD)
  709. {
  710. ppdev->pAssertModeMCD(ppdev,bEnable);
  711. }
  712. #endif
  713. ppdev->bEnable = bEnable;
  714. if (bEnable)
  715. {
  716. // The screen must be reenabled, reinitialize the device to clean state.
  717. bInitSURF(ppdev, FALSE);
  718. #if SWAT3
  719. // Enable font cache.
  720. vAssertModeText(ppdev, TRUE);
  721. #endif
  722. }
  723. else
  724. {
  725. POFMHDL pofm, pofmNext;
  726. #if (HW_PRESET_BUG)
  727. //
  728. // Disable the HW cursor for real, since we are leaving graphics mode.
  729. //
  730. ULONG ultmp = LLDR_SZ (grCursor_Control);
  731. ultmp &= 0xFFFE;
  732. LL16 (grCursor_Control, ultmp);
  733. #endif
  734. #if 1 // SWAT3 - font cache removal is now in vAssertMoveText.
  735. // Disable font cache.
  736. vAssertModeText(ppdev, FALSE);
  737. #endif
  738. #if MEMMGR
  739. {
  740. // Hostify all device bitmaps.
  741. extern void HostifyAllBitmaps(PPDEV ppdev);
  742. HostifyAllBitmaps(ppdev);
  743. }
  744. #else
  745. // We have to move all off-screen device bitmaps to memory.
  746. for (pofm = ppdev->OFM_UsedQ; pofm; pofm = pofmNext)
  747. {
  748. pofmNext = pofm->nexthdl;
  749. if ( (pofm->pdsurf) && (pofm->pdsurf->pofm) )
  750. {
  751. if (!bCreateDibFromScreen(ppdev, pofm->pdsurf))
  752. {
  753. RIP("Error moving off-screen bitmap to DIB");
  754. break;
  755. }
  756. }
  757. }
  758. #endif
  759. // We must give up the display.
  760. // Call the kernel driver to reset the device to a known state.
  761. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  762. IOCTL_VIDEO_RESET_DEVICE,
  763. NULL,
  764. 0,
  765. NULL,
  766. 0,
  767. &ulReturn,
  768. NULL))
  769. {
  770. RIP(_DISP_ " DrvAssertMode failed IOCTL");
  771. }
  772. }
  773. #ifdef WINNT_VER40
  774. return TRUE;
  775. #else
  776. return;
  777. #endif
  778. }
  779. /******************************Public*Routine******************************\
  780. * DrvGetModes
  781. *
  782. * Returns the list of available modes for the device.
  783. *
  784. \**************************************************************************/
  785. ULONG DrvGetModes(
  786. HANDLE hDriver,
  787. ULONG cjSize,
  788. DEVMODEW *pdm)
  789. {
  790. DWORD cModes;
  791. DWORD cbOutputSize;
  792. PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
  793. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  794. DWORD cbModeSize;
  795. DISPDBG((1, _DISP_ " DrvGetModes: Entry.\n"));
  796. cModes = getAvailableModes(hDriver,
  797. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  798. &cbModeSize);
  799. if (cModes == 0)
  800. {
  801. DISPDBG((1, _DISP_ " DrvGetModes failed to get mode information"));
  802. return 0;
  803. }
  804. if (pdm == NULL)
  805. {
  806. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  807. }
  808. else
  809. {
  810. //
  811. // Now copy the information for the supported modes back into the output
  812. // buffer
  813. //
  814. cbOutputSize = 0;
  815. pVideoTemp = pVideoModeInformation;
  816. do
  817. {
  818. if (pVideoTemp->Length != 0)
  819. {
  820. if (cOutputModes == 0)
  821. {
  822. break;
  823. }
  824. //
  825. // Zero the entire structure to start off with.
  826. //
  827. memset(pdm, 0, sizeof(DEVMODEW));
  828. //
  829. // Set the name of the device to the name of the DLL.
  830. //
  831. memcpy(&(pdm->dmDeviceName), L"cl546x", sizeof(L"cl546x"));
  832. pdm->dmSpecVersion = DM_SPECVERSION;
  833. pdm->dmDriverVersion = DM_SPECVERSION;
  834. //
  835. // We currently do not support Extra information in the driver
  836. //
  837. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  838. pdm->dmSize = sizeof(DEVMODEW);
  839. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  840. pVideoTemp->BitsPerPlane;
  841. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  842. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  843. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  844. #ifdef WINNT_VER40
  845. pdm->dmDisplayFlags = 0;
  846. pdm->dmFields = DM_BITSPERPEL |
  847. DM_PELSWIDTH |
  848. DM_PELSHEIGHT |
  849. DM_DISPLAYFREQUENCY |
  850. DM_DISPLAYFLAGS ;
  851. #else
  852. if (pVideoTemp->AttributeFlags & VIDEO_MODE_INTERLACED)
  853. {
  854. pdm->dmDisplayFlags |= DM_INTERLACED;
  855. }
  856. #endif
  857. //
  858. // Go to the next DEVMODE entry in the buffer.
  859. //
  860. cOutputModes--;
  861. pdm = (LPDEVMODEW) ( ((ULONG)pdm) + sizeof(DEVMODEW) +
  862. DRIVER_EXTRA_SIZE);
  863. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  864. }
  865. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  866. (((PUCHAR)pVideoTemp) + cbModeSize);
  867. } while (--cModes);
  868. }
  869. MEMORY_FREE(pVideoModeInformation);
  870. DISPDBG((1, _DISP_ " DrvGetModes: Exit.\n"));
  871. return cbOutputSize;
  872. }
  873. /**************************************************************************\
  874. * DrvResetPDEV
  875. *
  876. \**************************************************************************/
  877. BOOL DrvResetPDEV(DHPDEV dhpdevOld, DHPDEV dhpdevNew)
  878. {
  879. PPDEV ppdevOld, ppdevNew;
  880. DISPDBG((1, _DISP_ " DrvResetPDEV:\n"));
  881. ppdevOld = (PPDEV) dhpdevOld;
  882. ppdevNew = (PPDEV) dhpdevNew;
  883. #ifndef WINNT_VER35
  884. ENSURE_3D_IDLE(ppdevOld);
  885. ppdevNew->iUniqueness = ppdevOld->iUniqueness + 1;
  886. ppdevNew->pAllocOffScnMem = AllocOffScnMem;
  887. ppdevNew->pFreeOffScnMem = FreeOffScnMem;
  888. ppdevNew->bPrevModeDDOutOfVideoMem = ppdevOld->bPrevModeDDOutOfVideoMem;
  889. #endif // ndef WINNT_VER35
  890. return (TRUE);
  891. };
  892. /* ===========================================================================
  893. * LgMatchDriverToChip()
  894. *
  895. * This driver code base compiles into several different DLLs, based on
  896. * what C Preprocessor symbols are defined at compile time. This allows us
  897. * to build several different chip specific drivers from a single code base.
  898. *
  899. * This function checks the Laguna chip ID and returns TRUE if the chip is
  900. * one supported by this DLL.
  901. *
  902. * ========================================================================== */
  903. BOOL LgMatchDriverToChip(
  904. PPDEV ppdev
  905. )
  906. {
  907. DWORD returnedDataLength;
  908. WORD DeviceID;
  909. VIDEO_PUBLIC_ACCESS_RANGES VideoAccessRanges[2];
  910. BYTE *pLgREGS_PCI_ID;
  911. // Get a pointer to the HW registers.
  912. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  913. IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES,
  914. NULL, // input buffer
  915. 0,
  916. (PVOID) VideoAccessRanges, // output buffer
  917. sizeof (VideoAccessRanges),
  918. &returnedDataLength,
  919. NULL))
  920. {
  921. RIP(_DISP_ "LgMatchDriverToChip - QUERY_PUBLIC_ACCESS_RANGES ioctl failed!\n");
  922. return (FALSE);
  923. }
  924. pLgREGS_PCI_ID = ((BYTE *)VideoAccessRanges[0].VirtualAddress) + 0x302;
  925. //Get the chip id.
  926. DeviceID = *(WORD *)pLgREGS_PCI_ID;
  927. DISPDBG((1,_DISP_ " MatchDriverToChip: Chip ID is 0x%08X.\n",DeviceID));
  928. // Does this driver instance support this chip?
  929. #if DRIVER_5465
  930. // This is the 5465 driver. Fail if not a 5465 or later.
  931. if (DeviceID < CL_GD5465)
  932. {
  933. return FALSE;
  934. }
  935. #else
  936. // This is the 546x driver. Fail if a 5465 or later.
  937. if (DeviceID >= CL_GD5465)
  938. {
  939. return FALSE;
  940. }
  941. #endif
  942. return TRUE;
  943. }
  944.