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.

2532 lines
82 KiB

  1. /******************************************************************************\
  2. *
  3. * $Workfile: enable.c $
  4. *
  5. * This module contains the functions that enable and disable the driver, the
  6. * pdev, and the surface.
  7. *
  8. * Copyright (c) 1992-1997 Microsoft Corporation.
  9. * Copyright (c) 1996-1997 Cirrus Logic, Inc.,
  10. *
  11. * $Log: S:/projects/drivers/ntsrc/display/enable.c_v $
  12. *
  13. * Rev 1.21 Apr 03 1997 15:38:50 unknown
  14. *
  15. *
  16. * Rev 1.20 28 Mar 1997 16:08:40 PLCHU
  17. *
  18. *
  19. * Rev 1.12 Jan 15 1997 09:41:32 unknown
  20. * Change to Version 4.0.5
  21. *
  22. * Rev 1.11 Jan 14 1997 18:00:32 unknown
  23. * disable command list due to performance drop.
  24. *
  25. * Rev 1.10 Jan 14 1997 15:14:02 unknown
  26. * Change to version V4.0.4
  27. *
  28. * Rev 1.8 Jan 08 1997 11:22:34 unknown
  29. * Change to V4.0.3
  30. *
  31. * Rev 1.7 18 Dec 1996 13:44:08 PLCHU
  32. *
  33. *
  34. * Rev 1.6 Dec 13 1996 12:15:48 unknown
  35. * update bandwith equation for DDraw.
  36. *
  37. * Rev 1.6 Nov 27 1996 15:07:28 unknown
  38. * turn on second apertue for 5480
  39. *
  40. * Rev 1.5 Nov 07 1996 16:48:00 unknown
  41. *
  42. *
  43. * Rev 1.4 Nov 06 1996 15:55:10 unknown
  44. * Turn off second aperture
  45. *
  46. * Rev 1.3 Nov 05 1996 14:49:00 unknown
  47. * Turn on second aperture feature for 5480
  48. *
  49. * Rev 1.1 Oct 10 1996 15:36:38 unknown
  50. *
  51. *
  52. * Rev 1.9 12 Aug 1996 16:52:42 frido
  53. * Removed unaccessed local variables.
  54. * Added NT 3.5x/4.0 auto detection.
  55. * Renamned vMmPatternBlt into vMmFillPat36.
  56. *
  57. * Rev 1.8 08 Aug 1996 16:20:54 frido
  58. * Added vMmCopyBlt36 routine.
  59. *
  60. * Rev 1.7 01 Aug 1996 00:09:28 frido
  61. * Fixed a type causing havoc in new pitch in 24-bpp.
  62. *
  63. * Rev 1.6 26 Jul 1996 17:46:30 frido
  64. * Added new solid fill routine for 54x6 chips.
  65. *
  66. * Rev 1.5 26 Jul 1996 14:16:40 frido
  67. * Added new pattern blit routine.
  68. *
  69. * Rev 1.4 20 Jul 1996 13:48:12 frido
  70. * Hooked DrvDestroyFont.
  71. *
  72. * Rev 1.3 10 Jul 1996 17:54:50 frido
  73. * Cosmetic change in the flHooks variable.
  74. *
  75. * Rev 1.2 09 Jul 1996 17:58:24 frido
  76. * Added LineTo code.
  77. *
  78. * Rev 1.1 03 Jul 1996 13:38:30 frido
  79. * Added DirectDraw support.
  80. *
  81. * sge01 10-23-96 Add second aperture maping
  82. * sge02 10-29-96 Merge port and register access
  83. * for VGA relocatable and MMIO registers.
  84. * myf0 08-19-96 added 85hz supported
  85. * myf1 08-20-96 supported panning scrolling
  86. * myf2 08-20-96 fixed hardware save/restore state bug for matterhorn
  87. * myf3 09-01-96 Added IOCTL_CIRRUS_PRIVATE_BIOS_CALL for TV supported
  88. * myf4 09-01-96 patch Viking BIOS bug, PDR #4287, begin
  89. * myf5 09-01-96 Fixed PDR #4365 keep all default refresh rate
  90. * myf6 09-17-96 Merged Desktop SRC1001 & MINI102
  91. * myf7 09-19-96 Fixed exclude 60Hz refresh rate selected
  92. * myf8 *09-21-96* May be need change CheckandUpdateDDC2BMonitor --keystring[]
  93. * myf9 09-21-96 8x6 panel in 6x4x256 mode, cursor can't move to bottom scrn
  94. * ms0809 09-25-96 fixed dstn panel icon corrupted
  95. * ms923 09-25-96 merge MS-923 Disp.zip code
  96. * myf10 09-26-96 Fixed DSTN reserved half-frame buffer bug.
  97. * myf11 09-26-96 Fixed 755x CE chip HW bug, access ramdac before disable HW
  98. * icons and cursor
  99. * myf12 10-01-96 Supported Hot Key switch display
  100. * myf13 10-05-96 Fixed /w panning scrolling, vertical expension on bug
  101. * myf14 10-15-96 Fixed PDR#6917, 6x4 panel can't panning scrolling for 754x
  102. * myf15 10-16-96 Fixed disable memory mapped IO for 754x, 755x
  103. * myf16 10-22-96 Fixed PDR #6933,panel type set different demo board setting
  104. * sge01 10-28-96 Map the ports before we use it and free it in bInitializeModeFields
  105. * myf17 11-04-96 Added special escape code must be use 11/5/96 later NTCTRL,
  106. * and added Matterhorn LF Device ID==0x4C
  107. * myf18 11-04-96 Fixed PDR #7075,
  108. * myf19 11-06-96 Fixed Vinking can't work problem, because DEVICEID = 0x30
  109. * is different from data book (CR27=0x2C)
  110. * myf20 11-11-96 Fixed PDR#5501 pop-up icon crash problem
  111. * myf21 11-21-96 Change CAPS_IS_7555 to check ppdev->ulChipID
  112. * chu01 12-16-96 Enable color correction
  113. * chu02 02-07-97 Disable command list for 24 bpp modes
  114. * jl01 02-11-97 Fix 542x VLB banking issue
  115. * myf29 02-12-97 Support Gamma Correction for 755x
  116. * pat04 :12-05-96 : Set default Panel bootup mode = 640x480x256colors if
  117. * current resolution not supported.
  118. * pat08 : : Put in changes that didn't make in 1.11 driver
  119. * myf33 : 03-21-97 Fixed 6x4x256 TV on, font cut bug,
  120. *
  121. \******************************************************************************/
  122. #include "precomp.h"
  123. #define DBG_LVL_CAPS 0
  124. #define CIRRUSVERSION 21
  125. //crus
  126. //myf17 #define PANNING_SCROLL //myf1
  127. BOOL bGetChipIDandRev(BOOL bRetInfo, PPDEV ppdev);
  128. //crus begin
  129. #ifdef PANNING_SCROLL //myf1
  130. VOID
  131. CirrusLaptopViewPoint(
  132. PDEV* ppdev,
  133. PVIDEO_MODE_INFORMATION pVideoModeInfo);
  134. #endif
  135. //crus end
  136. /******************************Public*Structure****************************\
  137. * GDIINFO ggdiDefault
  138. *
  139. * This contains the default GDIINFO fields that are passed back to GDI
  140. * during DrvEnablePDEV.
  141. *
  142. * NOTE: This structure defaults to values for an 8bpp palette device.
  143. * Some fields are overwritten for different colour depths.
  144. \**************************************************************************/
  145. GDIINFO ggdiDefault = {
  146. // GDI_DRIVER_VERSION, // ulVersion
  147. GDI_DRIVER_VERSION+CIRRUSVERSION, // ulVersion, sge01
  148. DT_RASDISPLAY, // ulTechnology
  149. 0, // ulHorzSize (filled in later)
  150. 0, // ulVertSize (filled in later)
  151. 0, // ulHorzRes (filled in later)
  152. 0, // ulVertRes (filled in later)
  153. 0, // cBitsPixel (filled in later)
  154. 0, // cPlanes (filled in later)
  155. 20, // ulNumColors (palette managed)
  156. 0, // flRaster (DDI reserved field)
  157. 0, // ulLogPixelsX (filled in later)
  158. 0, // ulLogPixelsY (filled in later)
  159. TC_RA_ABLE /* | TC_SCROLLBLT */,
  160. // flTextCaps --
  161. // Setting TC_SCROLLBLT tells console to scroll
  162. // by repainting the entire window. Otherwise,
  163. // scrolls are done by calling the driver to
  164. // do screen to screen copies.
  165. 0, // ulDACRed (filled in later)
  166. 0, // ulDACGreen (filled in later)
  167. 0, // ulDACBlue (filled in later)
  168. 0x0024, // ulAspectX
  169. 0x0024, // ulAspectY
  170. 0x0033, // ulAspectXY (one-to-one aspect ratio)
  171. 1, // xStyleStep
  172. 1, // yStyleSte;
  173. 3, // denStyleStep -- Styles have a one-to-one aspect
  174. // ratio, and every 'dot' is 3 pixels long
  175. { 0, 0 }, // ptlPhysOffset
  176. { 0, 0 }, // szlPhysSize
  177. 256, // ulNumPalReg
  178. // These fields are for halftone initialization. The actual values are
  179. // a bit magic, but seem to work well on our display.
  180. { // ciDevice
  181. { 6700, 3300, 0 }, // Red
  182. { 2100, 7100, 0 }, // Green
  183. { 1400, 800, 0 }, // Blue
  184. { 1750, 3950, 0 }, // Cyan
  185. { 4050, 2050, 0 }, // Magenta
  186. { 4400, 5200, 0 }, // Yellow
  187. { 3127, 3290, 0 }, // AlignmentWhite
  188. 20000, // RedGamma
  189. 20000, // GreenGamma
  190. 20000, // BlueGamma
  191. 0, 0, 0, 0, 0, 0 // No dye correction for raster displays
  192. },
  193. 0, // ulDevicePelsDPI (for printers only)
  194. PRIMARY_ORDER_CBA, // ulPrimaryOrder
  195. HT_PATSIZE_4x4_M, // ulHTPatternSize
  196. HT_FORMAT_8BPP, // ulHTOutputFormat
  197. HT_FLAG_ADDITIVE_PRIMS, // flHTFlags
  198. 0, // ulVRefresh (filled in later)
  199. #if (NT_VERSION < 0x0400)
  200. 0, // ulDesktopHorzRes (filled in later)
  201. 0, // ulDesktopVertRes (filled in later)
  202. 0, // ulBltAlignment
  203. #else
  204. 0, // ulBltAlignment
  205. 0, // ulPanningHorzRes (filled in later)
  206. 0, // ulPanningVertRes (filled in later)
  207. #endif
  208. };
  209. /******************************Public*Structure****************************\
  210. * DEVINFO gdevinfoDefault
  211. *
  212. * This contains the default DEVINFO fields that are passed back to GDI
  213. * during DrvEnablePDEV.
  214. *
  215. * NOTE: This structure defaults to values for an 8bpp palette device.
  216. * Some fields are overwritten for different colour depths.
  217. \**************************************************************************/
  218. #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  219. CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
  220. VARIABLE_PITCH | FF_DONTCARE,L"System"}
  221. #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  222. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  223. VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
  224. #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  225. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  226. FIXED_PITCH | FF_DONTCARE, L"Courier"}
  227. DEVINFO gdevinfoDefault = {
  228. (GCAPS_OPAQUERECT
  229. | GCAPS_DITHERONREALIZE
  230. | GCAPS_PALMANAGED
  231. | GCAPS_ALTERNATEFILL
  232. | GCAPS_WINDINGFILL
  233. | GCAPS_MONO_DITHER
  234. | GCAPS_COLOR_DITHER
  235. #if DIRECTDRAW
  236. | GCAPS_DIRECTDRAW
  237. #endif
  238. //crus
  239. #if (NT_VERSION >= 0x0400)
  240. #ifdef PANNING_SCROLL //myf1
  241. | GCAPS_PANNING
  242. #endif
  243. #endif
  244. // This driver can't handle GCAPS_ASYNCMOVE because some of the pointer
  245. // moves, where the pointer image must be rotated at the left edge,
  246. // require the blt hardware to download a new pointer shape.
  247. ),
  248. // NOTE: Only enable GCAPS_ASYNCMOVE if your code
  249. // and hardware can handle DrvMovePointer
  250. // calls at any time, even while another
  251. // thread is in the middle of a drawing
  252. // call such as DrvBitBlt.
  253. // flGraphicsFlags
  254. SYSTM_LOGFONT, // lfDefaultFont
  255. HELVE_LOGFONT, // lfAnsiVarFont
  256. COURI_LOGFONT, // lfAnsiFixFont
  257. 0, // cFonts
  258. BMF_8BPP, // iDitherFormat
  259. 8, // cxDither
  260. 8, // cyDither
  261. 0 // hpalDefault (filled in later)
  262. };
  263. /******************************Public*Structure****************************\
  264. * DFVFN gadrvfn[]
  265. *
  266. * Build the driver function table gadrvfn with function index/address
  267. * pairs. This table tells GDI which DDI calls we support, and their
  268. * location (GDI does an indirect call through this table to call us).
  269. *
  270. * Why haven't we implemented DrvSaveScreenBits? To save code.
  271. *
  272. * When the driver doesn't hook DrvSaveScreenBits, USER simulates on-
  273. * the-fly by creating a temporary device-format-bitmap, and explicitly
  274. * calling DrvCopyBits to save/restore the bits. Since we already hook
  275. * DrvCreateDeviceBitmap, we'll end up using off-screen memory to store
  276. * the bits anyway (which would have been the main reason for implementing
  277. * DrvSaveScreenBits). So we may as well save some working set.
  278. \**************************************************************************/
  279. #if DBG
  280. // On Checked builds, or when we have to synchronize access, thunk
  281. // everything through Dbg calls...
  282. DRVFN gadrvfn[] = {
  283. { INDEX_DrvEnablePDEV, (PFN) DbgEnablePDEV },
  284. { INDEX_DrvCompletePDEV, (PFN) DbgCompletePDEV },
  285. { INDEX_DrvDisablePDEV, (PFN) DbgDisablePDEV },
  286. { INDEX_DrvEnableSurface, (PFN) DbgEnableSurface },
  287. { INDEX_DrvDisableSurface, (PFN) DbgDisableSurface },
  288. { INDEX_DrvAssertMode, (PFN) DbgAssertMode },
  289. { INDEX_DrvCopyBits, (PFN) DbgCopyBits },
  290. { INDEX_DrvBitBlt, (PFN) DbgBitBlt },
  291. { INDEX_DrvTextOut, (PFN) DbgTextOut },
  292. { INDEX_DrvSynchronize, (PFN) DrvSynchronize },
  293. #if 1 // Font cache.
  294. { INDEX_DrvDestroyFont, (PFN) DbgDestroyFont },
  295. #endif
  296. { INDEX_DrvGetModes, (PFN) DbgGetModes },
  297. { INDEX_DrvStrokePath, (PFN) DbgStrokePath },
  298. { INDEX_DrvSetPalette, (PFN) DbgSetPalette },
  299. { INDEX_DrvDitherColor, (PFN) DbgDitherColor },
  300. { INDEX_DrvFillPath, (PFN) DbgFillPath },
  301. #if DIRECTDRAW
  302. { INDEX_DrvGetDirectDrawInfo, (PFN) DbgGetDirectDrawInfo },
  303. { INDEX_DrvEnableDirectDraw, (PFN) DbgEnableDirectDraw },
  304. { INDEX_DrvDisableDirectDraw, (PFN) DbgDisableDirectDraw },
  305. #endif
  306. #if LINETO
  307. { INDEX_DrvLineTo, (PFN) DbgLineTo },
  308. #endif
  309. #if !DRIVER_PUNT_ALL
  310. #if !DRIVER_PUNT_STRETCH
  311. { INDEX_DrvStretchBlt, (PFN) DbgStretchBlt },
  312. #endif
  313. #if !DRIVER_PUNT_PTR
  314. { INDEX_DrvMovePointer, (PFN) DbgMovePointer },
  315. { INDEX_DrvSetPointerShape, (PFN) DbgSetPointerShape },
  316. #endif
  317. { INDEX_DrvCreateDeviceBitmap, (PFN) DbgCreateDeviceBitmap },
  318. { INDEX_DrvDeleteDeviceBitmap, (PFN) DbgDeleteDeviceBitmap },
  319. #if !DRIVER_PUNT_BRUSH
  320. { INDEX_DrvRealizeBrush, (PFN) DbgRealizeBrush },
  321. #endif
  322. #endif
  323. };
  324. #else
  325. // On Free builds, directly call the appropriate functions...
  326. DRVFN gadrvfn[] = {
  327. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  328. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  329. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  330. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  331. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  332. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  333. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  334. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  335. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  336. { INDEX_DrvSynchronize, (PFN) DrvSynchronize },
  337. #if 1 // Font cache.
  338. { INDEX_DrvDestroyFont, (PFN) DrvDestroyFont },
  339. #endif
  340. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  341. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  342. { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
  343. { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
  344. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  345. #if DIRECTDRAW
  346. { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo },
  347. { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw },
  348. { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw },
  349. #endif
  350. #if LINETO
  351. { INDEX_DrvLineTo, (PFN) DrvLineTo },
  352. #endif
  353. #if !DRIVER_PUNT_ALL
  354. #if !DRIVER_PUNT_STRETCH
  355. { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt },
  356. #endif
  357. #if !DRIVER_PUNT_PTR
  358. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  359. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  360. #endif
  361. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  362. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  363. #if !DRIVER_PUNT_BRUSH
  364. { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush },
  365. #endif
  366. #endif
  367. };
  368. #endif
  369. ULONG gcdrvfn = sizeof(gadrvfn) / sizeof(DRVFN);
  370. //
  371. // Merge port and register access for
  372. // VGA relocatable and MMIO registers.
  373. //
  374. // sge02 begin
  375. #if defined(_X86_)
  376. UCHAR CirrusREAD_PORT_UCHAR(PVOID Port);
  377. USHORT CirrusREAD_PORT_USHORT(PVOID Port);
  378. ULONG CirrusREAD_PORT_ULONG(PVOID Port);
  379. VOID CirrusWRITE_PORT_UCHAR(PVOID Port,UCHAR Value);
  380. VOID CirrusWRITE_PORT_USHORT(PVOID Port, USHORT Value);
  381. VOID CirrusWRITE_PORT_ULONG(PVOID Port, ULONG Value);
  382. UCHAR CirrusREAD_REGISTER_UCHAR(PVOID Register);
  383. USHORT CirrusREAD_REGISTER_USHORT(PVOID Register);
  384. ULONG CirrusREAD_REGISTER_ULONG(PVOID Register);
  385. VOID CirrusWRITE_REGISTER_UCHAR(PVOID Register,UCHAR Value);
  386. VOID CirrusWRITE_REGISTER_USHORT(PVOID Register, USHORT Value);
  387. VOID CirrusWRITE_REGISTER_ULONG(PVOID Register, ULONG Value);
  388. UCHAR CirrusREAD_PORT_UCHAR(PVOID Port)
  389. {
  390. return((UCHAR)inp(Port));
  391. }
  392. USHORT CirrusREAD_PORT_USHORT(PVOID Port)
  393. {
  394. return(inpw(Port));
  395. }
  396. ULONG CirrusREAD_PORT_ULONG(PVOID Port)
  397. {
  398. return(inpd(Port));
  399. }
  400. VOID CirrusWRITE_PORT_UCHAR(PVOID Port,UCHAR Value)
  401. {
  402. outp(Port, Value);
  403. }
  404. VOID CirrusWRITE_PORT_USHORT(PVOID Port, USHORT Value)
  405. {
  406. outpw(Port, Value);
  407. }
  408. VOID CirrusWRITE_PORT_ULONG(PVOID Port, ULONG Value)
  409. {
  410. outpd(Port, Value);
  411. }
  412. UCHAR CirrusREAD_REGISTER_UCHAR(PVOID Register)
  413. {
  414. return(*(volatile UCHAR *)(Register));
  415. }
  416. USHORT CirrusREAD_REGISTER_USHORT(PVOID Register)
  417. {
  418. return(*(volatile USHORT *)(Register));
  419. }
  420. ULONG CirrusREAD_REGISTER_ULONG(PVOID Register)
  421. {
  422. return(*(volatile ULONG *)(Register));
  423. }
  424. VOID CirrusWRITE_REGISTER_UCHAR(PVOID Register,UCHAR Value)
  425. {
  426. *(volatile UCHAR *)(Register) = (Value);
  427. }
  428. VOID CirrusWRITE_REGISTER_USHORT(PVOID Register, USHORT Value)
  429. {
  430. *(volatile USHORT *)(Register) = (Value);
  431. }
  432. VOID CirrusWRITE_REGISTER_ULONG(PVOID Register, ULONG Value)
  433. {
  434. *(volatile ULONG *)(Register) = (Value);
  435. }
  436. #endif
  437. //sge02 end
  438. /******************************Public*Routine******************************\
  439. * BOOL DrvEnableDriver
  440. *
  441. * Enables the driver by retrieving the drivers function table and version.
  442. *
  443. \**************************************************************************/
  444. BOOL DrvEnableDriver(
  445. ULONG iEngineVersion,
  446. ULONG cj,
  447. DRVENABLEDATA* pded)
  448. {
  449. DISPDBG((2, "---- DrvEnableDriver"));
  450. // Engine Version is passed down so future drivers can support previous
  451. // engine versions. A next generation driver can support both the old
  452. // and new engine conventions if told what version of engine it is
  453. // working with. For the first version the driver does nothing with it.
  454. // Fill in as much as we can.
  455. if (cj >= sizeof(DRVENABLEDATA))
  456. pded->pdrvfn = gadrvfn;
  457. if (cj >= (sizeof(ULONG) * 2))
  458. pded->c = gcdrvfn;
  459. // DDI version this driver was targeted for is passed back to engine.
  460. // Future graphic's engine may break calls down to old driver format.
  461. if (cj >= sizeof(ULONG))
  462. pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
  463. return(TRUE);
  464. }
  465. /******************************Public*Routine******************************\
  466. * VOID DrvDisableDriver
  467. *
  468. * Tells the driver it is being disabled. Release any resources allocated in
  469. * DrvEnableDriver.
  470. *
  471. \**************************************************************************/
  472. VOID DrvDisableDriver(VOID)
  473. {
  474. return;
  475. }
  476. /******************************Public*Routine******************************\
  477. * DHPDEV DrvEnablePDEV
  478. *
  479. * Initializes a bunch of fields for GDI, based on the mode we've been asked
  480. * to do. This is the first thing called after DrvEnableDriver, when GDI
  481. * wants to get some information about us.
  482. *
  483. * (This function mostly returns back information; DrvEnableSurface is used
  484. * for initializing the hardware and driver components.)
  485. *
  486. \**************************************************************************/
  487. DHPDEV DrvEnablePDEV(
  488. DEVMODEW* pdm, // Contains data pertaining to requested mode
  489. PWSTR pwszLogAddr, // Logical address
  490. ULONG cPat, // Count of standard patterns
  491. HSURF* phsurfPatterns, // Buffer for standard patterns
  492. ULONG cjCaps, // Size of buffer for device caps 'pdevcaps'
  493. ULONG* pdevcaps, // Buffer for device caps, also known as 'gdiinfo'
  494. ULONG cjDevInfo, // Number of bytes in device info 'pdi'
  495. DEVINFO* pdi, // Device information
  496. #if (NT_VERSION < 0x0400)
  497. PWSTR pwszDataFile, // DataFile - not used
  498. #else
  499. HDEV hdev, // HDEV, used for callbacks
  500. #endif
  501. PWSTR pwszDeviceName, // Device name
  502. HANDLE hDriver) // Kernel driver handle
  503. {
  504. PDEV* ppdev;
  505. // Future versions of NT had better supply 'devcaps' and 'devinfo'
  506. // structures that are the same size or larger than the current
  507. // structures:
  508. DISPDBG((2, "---- DrvEnablePDEV"));
  509. if ((cjCaps < sizeof(GDIINFO)) || (cjDevInfo < sizeof(DEVINFO)))
  510. {
  511. DISPDBG((0, "DrvEnablePDEV - Buffer size too small"));
  512. goto ReturnFailure0;
  513. }
  514. // Allocate a physical device structure. Note that we definitely
  515. // rely on the zero initialization:
  516. ppdev = (PDEV*) ALLOC(sizeof(PDEV));
  517. if (ppdev == NULL)
  518. {
  519. DISPDBG((0, "DrvEnablePDEV - Failed EngAllocMem"));
  520. goto ReturnFailure0;
  521. }
  522. ppdev->hDriver = hDriver;
  523. // Get the current screen mode information. Set up device caps and devinfo.
  524. if (!bInitializeModeFields(ppdev, (GDIINFO*) pdevcaps, pdi, pdm))
  525. {
  526. goto ReturnFailure1;
  527. }
  528. // Initialize palette information.
  529. if (!bInitializePalette(ppdev, pdi))
  530. {
  531. DISPDBG((0, "DrvEnablePDEV - Failed bInitializePalette"));
  532. goto ReturnFailure1;
  533. }
  534. return((DHPDEV) ppdev);
  535. ReturnFailure1:
  536. DrvDisablePDEV((DHPDEV) ppdev);
  537. ReturnFailure0:
  538. DISPDBG((0, "Failed DrvEnablePDEV"));
  539. return(0);
  540. }
  541. /******************************Public*Routine******************************\
  542. * DrvDisablePDEV
  543. *
  544. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  545. * enabled DrvDisableSurface will have already been called.
  546. *
  547. * Note that this function will be called when previewing modes in the
  548. * Display Applet, but not at system shutdown. If you need to reset the
  549. * hardware at shutdown, you can do it in the miniport by providing a
  550. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  551. *
  552. * Note: In an error, we may call this before DrvEnablePDEV is done.
  553. *
  554. \**************************************************************************/
  555. VOID DrvDisablePDEV(
  556. DHPDEV dhpdev)
  557. {
  558. PDEV* ppdev;
  559. ppdev = (PDEV*) dhpdev;
  560. vUninitializePalette(ppdev);
  561. FREE(ppdev);
  562. }
  563. /******************************Public*Routine******************************\
  564. * VOID DrvCompletePDEV
  565. *
  566. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  567. *
  568. \**************************************************************************/
  569. VOID DrvCompletePDEV(
  570. DHPDEV dhpdev,
  571. HDEV hdev)
  572. {
  573. ((PDEV*) dhpdev)->hdevEng = hdev;
  574. }
  575. /******************************Public*Routine******************************\
  576. * HSURF DrvEnableSurface
  577. *
  578. * Creates the drawing surface, initializes the hardware, and initializes
  579. * driver components. This function is called after DrvEnablePDEV, and
  580. * performs the final device initialization.
  581. *
  582. \**************************************************************************/
  583. HSURF DrvEnableSurface(
  584. DHPDEV dhpdev)
  585. {
  586. PDEV* ppdev;
  587. HSURF hsurf;
  588. SIZEL sizl;
  589. DSURF* pdsurf;
  590. VOID* pvTmpBuffer;
  591. SURFOBJ* pso;
  592. ppdev = (PDEV*) dhpdev;
  593. DISPDBG((2, "---- DrvEnableSurface"));
  594. /////////////////////////////////////////////////////////////////////
  595. // First, enable all the subcomponents.
  596. //
  597. // Note that the order in which these 'Enable' functions are called
  598. // may be significant in low off-screen memory conditions, because
  599. // the off-screen heap manager may fail some of the later
  600. // allocations...
  601. if (!bEnableHardware(ppdev))
  602. goto ReturnFailure;
  603. if (!bEnableBanking(ppdev))
  604. goto ReturnFailure;
  605. if (!bEnableOffscreenHeap(ppdev))
  606. goto ReturnFailure;
  607. if (!bEnablePointer(ppdev))
  608. goto ReturnFailure;
  609. if (!bEnableText(ppdev))
  610. goto ReturnFailure;
  611. if (!bEnableBrushCache(ppdev))
  612. goto ReturnFailure;
  613. if (!bEnablePalette(ppdev))
  614. goto ReturnFailure;
  615. #if DIRECTDRAW
  616. if (!bEnableDirectDraw(ppdev))
  617. goto ReturnFailure;
  618. #endif
  619. /////////////////////////////////////////////////////////////////////
  620. // Now create our private surface structure.
  621. //
  622. // Whenever we get a call to draw directly to the screen, we'll get
  623. // passed a pointer to a SURFOBJ whose 'dhpdev' field will point
  624. // to our PDEV structure, and whose 'dhsurf' field will point to the
  625. // following DSURF structure.
  626. //
  627. // Every device bitmap we create in DrvCreateDeviceBitmap will also
  628. // have its own unique DSURF structure allocated (but will share the
  629. // same PDEV). To make our code more polymorphic for handling drawing
  630. // to either the screen or an off-screen bitmap, we have the same
  631. // structure for both.
  632. pdsurf = ALLOC(sizeof(DSURF));
  633. if (pdsurf == NULL)
  634. {
  635. DISPDBG((0, "DrvEnableSurface - Failed pdsurf EngAllocMem"));
  636. goto ReturnFailure;
  637. }
  638. ppdev->pdsurfScreen = pdsurf; // Remember it for clean-up
  639. pdsurf->poh = ppdev->pohScreen; // The screen is a surface, too
  640. pdsurf->dt = DT_SCREEN; // Not to be confused with a DIB
  641. pdsurf->sizl.cx = ppdev->cxScreen;
  642. pdsurf->sizl.cy = ppdev->cyScreen;
  643. pdsurf->ppdev = ppdev;
  644. /////////////////////////////////////////////////////////////////////
  645. // Next, have GDI create the actual SURFOBJ.
  646. //
  647. // Our drawing surface is going to be 'device-managed', meaning that
  648. // GDI cannot draw on the framebuffer bits directly, and as such we
  649. // create the surface via EngCreateDeviceSurface. By doing this, we ensure
  650. // that GDI will only ever access the bitmaps bits via the Drv calls
  651. // that we've HOOKed.
  652. //
  653. // If we could map the entire framebuffer linearly into main memory
  654. // (i.e., we didn't have to go through a 64k aperture), it would be
  655. // beneficial to create the surface via EngCreateBitmap, giving GDI a
  656. // pointer to the framebuffer bits. When we pass a call on to GDI
  657. // where it can't directly read/write to the surface bits because the
  658. // surface is device managed, it has to create a temporary bitmap and
  659. // call our DrvCopyBits routine to get/set a copy of the affected bits.
  660. // For example, the OpenGL component prefers to be able to write on the
  661. // framebuffer bits directly.
  662. //
  663. // The check for CAPS_AUTOSTART rules out chipsets (like the 7543) that
  664. // can't be written to directly.
  665. sizl.cx = ppdev->cxScreen;
  666. sizl.cy = ppdev->cyScreen;
  667. if ((ppdev->bLinearMode && DIRECT_ACCESS(ppdev)) && (ppdev->flCaps & CAPS_ENGINEMANAGED))
  668. {
  669. // Engine-managed surface:
  670. hsurf = (HSURF) EngCreateBitmap(sizl,
  671. ppdev->lDelta,
  672. ppdev->iBitmapFormat,
  673. BMF_TOPDOWN,
  674. ppdev->pjScreen);
  675. if (hsurf == 0)
  676. {
  677. DISPDBG((0, "DrvEnableSurface - Failed EngCreateBitmap"));
  678. goto ReturnFailure;
  679. }
  680. pso = EngLockSurface(hsurf);
  681. if (pso == NULL)
  682. {
  683. DISPDBG((0, "DrvEnableSurface - Couldn't lock our surface"));
  684. goto ReturnFailure;
  685. }
  686. pso->dhsurf = (DHSURF) pdsurf;
  687. EngUnlockSurface(pso);
  688. }
  689. else
  690. {
  691. // Device managed surface
  692. hsurf = EngCreateDeviceSurface((DHSURF) pdsurf, sizl, ppdev->iBitmapFormat);
  693. if (hsurf == 0)
  694. {
  695. DISPDBG((0, "DrvEnableSurface - Failed EngCreateDeviceSurface"));
  696. goto ReturnFailure;
  697. }
  698. }
  699. /////////////////////////////////////////////////////////////////////
  700. // Now associate the surface and the PDEV.
  701. //
  702. // We have to associate the surface we just created with our physical
  703. // device so that GDI can get information related to the PDEV when
  704. // it's drawing to the surface (such as, for example, the length of
  705. // styles on the device when simulating styled lines).
  706. //
  707. if (!EngAssociateSurface(hsurf, ppdev->hdevEng, ppdev->flHooks))
  708. {
  709. DISPDBG((0, "DrvEnableSurface - Failed EngAssociateSurface 2"));
  710. goto ReturnFailure;
  711. }
  712. ppdev->hsurfScreen = hsurf; // Remember it for clean-up
  713. ppdev->bEnabled = TRUE; // We'll soon be in graphics mode
  714. // Create our generic temporary buffer, which may be used by any
  715. // component.
  716. pvTmpBuffer = ALLOC(TMP_BUFFER_SIZE);
  717. if (pvTmpBuffer == NULL)
  718. {
  719. DISPDBG((0, "DrvEnableSurface - Failed EngAllocMem"));
  720. goto ReturnFailure;
  721. }
  722. ppdev->pvTmpBuffer = pvTmpBuffer;
  723. DISPDBG((5, "Passed DrvEnableSurface"));
  724. ppdev->hbmTmpMono = EngCreateBitmap(sizl, sizl.cx, BMF_1BPP, 0, ppdev->pvTmpBuffer);
  725. if (ppdev->hbmTmpMono == (HBITMAP) 0)
  726. {
  727. DISPDBG((0, "Couldn't create temporary 1bpp bitmap"));
  728. goto ReturnFailure;
  729. }
  730. ppdev->psoTmpMono = EngLockSurface((HSURF) ppdev->hbmTmpMono);
  731. if (ppdev->psoTmpMono == (SURFOBJ*) NULL)
  732. {
  733. DISPDBG((0,"Couldn't lock temporary 1bpp surface"));
  734. goto ReturnFailure;
  735. }
  736. return(hsurf);
  737. ReturnFailure:
  738. DrvDisableSurface((DHPDEV) ppdev);
  739. DISPDBG((0, "Failed DrvEnableSurface"));
  740. return(0);
  741. }
  742. VOID
  743. DrvSynchronize(
  744. IN DHPDEV dhpdev,
  745. IN RECTL *prcl
  746. )
  747. {
  748. PDEV *ppdev = (PDEV *) dhpdev;
  749. //
  750. // We need to do a wait for blt complete before we
  751. // let the engine party on our frame buffer
  752. //
  753. if (ppdev->flCaps & CAPS_MM_IO)
  754. {
  755. CP_MM_WAIT_FOR_BLT_COMPLETE(ppdev, ppdev->pjBase);
  756. }
  757. else
  758. {
  759. CP_IO_WAIT_FOR_BLT_COMPLETE(ppdev, ppdev->pjPorts);
  760. }
  761. }
  762. /******************************Public*Routine******************************\
  763. * VOID DrvDisableSurface
  764. *
  765. * Free resources allocated by DrvEnableSurface. Release the surface.
  766. *
  767. * Note that this function will be called when previewing modes in th* Display Applet, but not at system shutdown. If you need to reset the
  768. * hardware at shutdown, you can do it in the miniport by providing a
  769. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  770. *
  771. * Note: In an error case, we may call this before DrvEnableSurface is
  772. * completely done.
  773. *
  774. \**************************************************************************/
  775. VOID DrvDisableSurface(
  776. DHPDEV dhpdev)
  777. {
  778. PDEV* ppdev;
  779. ppdev = (PDEV*) dhpdev;
  780. // Note: In an error case, some of the following relies on the
  781. // fact that the PDEV is zero-initialized, so fields like
  782. // 'hsurfScreen' will be zero unless the surface has been
  783. // sucessfully initialized, and makes the assumption that
  784. // EngDeleteSurface can take '0' as a parameter.
  785. #if DIRECTDRAW
  786. vDisableDirectDraw(ppdev);
  787. #endif
  788. vDisablePalette(ppdev);
  789. vDisableBrushCache(ppdev);
  790. vDisableText(ppdev);
  791. vDisablePointer(ppdev);
  792. vDisableOffscreenHeap(ppdev);
  793. vDisableBanking(ppdev);
  794. vDisableHardware(ppdev);
  795. EngUnlockSurface(ppdev->psoTmpMono);
  796. EngDeleteSurface((HSURF) ppdev->hbmTmpMono);
  797. FREE(ppdev->pvTmpBuffer);
  798. EngDeleteSurface(ppdev->hsurfScreen);
  799. FREE(ppdev->pdsurfScreen);
  800. }
  801. /******************************Public*Routine******************************\
  802. * VOID DrvAssertMode
  803. *
  804. * This asks the device to reset itself to the mode of the pdev passed in.
  805. *
  806. \**************************************************************************/
  807. #if (NT_VERSION < 0x0400)
  808. VOID
  809. #else
  810. BOOL
  811. #endif
  812. DrvAssertMode(DHPDEV dhpdev, BOOL bEnable)
  813. {
  814. PDEV* ppdev = (PDEV*) dhpdev;
  815. if (!bEnable)
  816. {
  817. //////////////////////////////////////////////////////////////
  818. // Disable - Switch to full-screen mode
  819. #if DIRECTDRAW
  820. vAssertModeDirectDraw(ppdev, FALSE);
  821. #endif
  822. vAssertModePalette(ppdev, FALSE);
  823. vAssertModeBrushCache(ppdev, FALSE);
  824. vAssertModeText(ppdev, FALSE);
  825. vAssertModePointer(ppdev, FALSE);
  826. if (bAssertModeOffscreenHeap(ppdev, FALSE))
  827. {
  828. vAssertModeBanking(ppdev, FALSE);
  829. if (bAssertModeHardware(ppdev, FALSE))
  830. {
  831. ppdev->bEnabled = FALSE;
  832. #if (NT_VERSION >= 0x0400)
  833. return (TRUE);
  834. #else
  835. return;
  836. #endif
  837. }
  838. //////////////////////////////////////////////////////////
  839. // We failed to switch to full-screen. So undo everything:
  840. vAssertModeBanking(ppdev, TRUE);
  841. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  842. } // return code with TRUE
  843. vAssertModePointer(ppdev, TRUE);
  844. vAssertModeText(ppdev, TRUE);
  845. vAssertModeBrushCache(ppdev, TRUE);
  846. vAssertModePalette(ppdev, TRUE);
  847. }
  848. else
  849. {
  850. //////////////////////////////////////////////////////////////
  851. // Enable - Switch back to graphics mode
  852. // We have to enable every subcomponent in the reverse order
  853. // in which it was disabled:
  854. if (bAssertModeHardware(ppdev, TRUE))
  855. {
  856. vAssertModeBanking(ppdev, TRUE);
  857. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  858. // return code with TRUE
  859. vAssertModePointer(ppdev, TRUE);
  860. vAssertModeText(ppdev, TRUE);
  861. vAssertModeBrushCache(ppdev, TRUE);
  862. vAssertModePalette(ppdev, TRUE);
  863. #if DIRECTDRAW
  864. vAssertModeDirectDraw(ppdev, TRUE);
  865. #endif
  866. //
  867. // chu01 begin
  868. //
  869. #ifdef GAMMACORRECT
  870. {
  871. BYTE ajClutSpace[MAX_CLUT_SIZE];
  872. PVIDEO_CLUT pScreenClut;
  873. PALETTEENTRY* ppalFrom;
  874. PALETTEENTRY* ppalTo;
  875. PALETTEENTRY* ppalEnd;
  876. BOOL status;
  877. ULONG ulReturn;
  878. if (ppdev->flCaps & CAPS_GAMMA_CORRECT)
  879. {
  880. pScreenClut = (PVIDEO_CLUT) ajClutSpace;
  881. pScreenClut->NumEntries = 256;
  882. pScreenClut->FirstEntry = 0;
  883. ppalFrom = ppdev->pPal;
  884. ppalTo = (PALETTEENTRY*) pScreenClut->LookupTable;
  885. ppalEnd = &ppalTo[256];
  886. for (; ppalTo < ppalEnd; ppalFrom++, ppalTo++)
  887. {
  888. ppalTo->peRed = ppalFrom->peRed ;
  889. ppalTo->peGreen = ppalFrom->peGreen ;
  890. ppalTo->peBlue = ppalFrom->peBlue ;
  891. ppalTo->peFlags = 0 ;
  892. }
  893. //myf29 begin
  894. if (ppdev->ulChipID == 0xBC)
  895. status = bEnableGammaCorrect(ppdev) ;
  896. else if ((ppdev->ulChipID == 0x40) || (ppdev->ulChipID ==0x4C))
  897. status = bEnableGamma755x(ppdev) ;
  898. //myf29 end
  899. CalculateGamma( ppdev, pScreenClut, 256 ) ;
  900. // Set palette registers:
  901. if (!IOCONTROL(ppdev->hDriver,
  902. IOCTL_VIDEO_SET_COLOR_REGISTERS,
  903. pScreenClut,
  904. MAX_CLUT_SIZE,
  905. NULL,
  906. 0,
  907. &ulReturn))
  908. {
  909. DISPDBG((0, "Failed bEnablePalette"));
  910. }
  911. }
  912. }
  913. #endif // GAMMACORRECT
  914. //chu01
  915. ppdev->bEnabled = TRUE;
  916. #if (NT_VERSION >= 0x0400)
  917. return(TRUE);
  918. #endif
  919. }
  920. }
  921. #if (NT_VERSION >= 0x0400)
  922. return(FALSE);
  923. #endif
  924. }
  925. /******************************Public*Routine******************************\
  926. * ULONG DrvGetModes
  927. *
  928. * Returns the list of available modes for the device.
  929. *
  930. \**************************************************************************/
  931. ULONG DrvGetModes(
  932. HANDLE hDriver,
  933. ULONG cjSize,
  934. DEVMODEW* pdm)
  935. {
  936. DWORD cModes;
  937. DWORD cbOutputSize;
  938. PVIDEO_MODE_INFORMATION pVideoModeInformation;
  939. PVIDEO_MODE_INFORMATION pVideoTemp;
  940. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  941. DWORD cbModeSize;
  942. cModes = getAvailableModes(hDriver,
  943. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  944. &cbModeSize);
  945. if (cModes == 0)
  946. {
  947. DISPDBG((0, "DrvGetModes failed to get mode information"));
  948. return(0);
  949. }
  950. if (pdm == NULL)
  951. {
  952. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  953. }
  954. else
  955. {
  956. //
  957. // Now copy the information for the supported modes back into the
  958. // output buffer
  959. //
  960. cbOutputSize = 0;
  961. pVideoTemp = pVideoModeInformation;
  962. do
  963. {
  964. if (pVideoTemp->Length != 0)
  965. {
  966. if (cOutputModes == 0)
  967. {
  968. break;
  969. }
  970. //
  971. // Zero the entire structure to start off with.
  972. //
  973. memset(pdm, 0, sizeof(DEVMODEW));
  974. //
  975. // Set the name of the device to the name of the DLL.
  976. //
  977. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  978. pdm->dmSpecVersion = DM_SPECVERSION;
  979. pdm->dmDriverVersion = DM_SPECVERSION;
  980. pdm->dmSize = sizeof(DEVMODEW);
  981. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  982. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  983. pVideoTemp->BitsPerPlane;
  984. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  985. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  986. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  987. pdm->dmDisplayFlags = 0;
  988. pdm->dmFields = DM_BITSPERPEL |
  989. DM_PELSWIDTH |
  990. DM_PELSHEIGHT |
  991. DM_DISPLAYFREQUENCY |
  992. DM_DISPLAYFLAGS ;
  993. #if (NT_VERSION < 0x0400)
  994. if (pVideoTemp->AttributeFlags & VIDEO_MODE_INTERLACED)
  995. {
  996. pdm->dmDisplayFlags |= DM_INTERLACED;
  997. }
  998. #endif
  999. //
  1000. // Go to the next DEVMODE entry in the buffer.
  1001. //
  1002. cOutputModes--;
  1003. pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW) +
  1004. DRIVER_EXTRA_SIZE);
  1005. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  1006. }
  1007. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1008. (((PUCHAR)pVideoTemp) + cbModeSize);
  1009. } while (--cModes);
  1010. }
  1011. FREE(pVideoModeInformation);
  1012. return(cbOutputSize);
  1013. }
  1014. /******************************Public*Routine******************************\
  1015. * BOOL bAssertModeHardware
  1016. *
  1017. * Sets the appropriate hardware state for graphics mode or full-screen.
  1018. *
  1019. \**************************************************************************/
  1020. BOOL bAssertModeHardware(
  1021. PDEV* ppdev,
  1022. BOOL bEnable)
  1023. {
  1024. DWORD ReturnedDataLength;
  1025. ULONG ulReturn;
  1026. VIDEO_MODE_INFORMATION VideoModeInfo;
  1027. LONG cjEndOfFrameBuffer;
  1028. LONG cjPointerOffset;
  1029. LONG lDelta;
  1030. ULONG ulMode;
  1031. ULONG pFirstCL, pSecondCL;
  1032. if (bEnable)
  1033. {
  1034. // Call the miniport via an IOCTL to set the graphics mode.
  1035. ulMode = ppdev->ulMode;
  1036. if (ppdev->bLinearMode)
  1037. {
  1038. ulMode |= VIDEO_MODE_MAP_MEM_LINEAR;
  1039. }
  1040. if (!IOCONTROL(ppdev->hDriver,
  1041. IOCTL_VIDEO_SET_CURRENT_MODE,
  1042. &ulMode, // input buffer
  1043. sizeof(DWORD),
  1044. NULL,
  1045. 0,
  1046. &ReturnedDataLength))
  1047. {
  1048. DISPDBG((0, "bAssertModeHardware - Failed VIDEO_SET_CURRENT_MODE"));
  1049. goto ReturnFalse;
  1050. }
  1051. //
  1052. // This driver requires that extended write modes be enabled.
  1053. // Normally, we would put code like this into the miniport, but
  1054. // unfortunately the VGA drivers do not expect extended write
  1055. // modes to be enabled, and thus we have to put the code here.
  1056. //
  1057. #define ENABLE_EXTENDED_WRITE_MODES 0x4
  1058. {
  1059. BYTE j;
  1060. CP_OUT_BYTE(ppdev->pjPorts, INDEX_REG, 0x0B);
  1061. j = CP_IN_BYTE(ppdev->pjPorts, DATA_REG);
  1062. DISPDBG((3, "Mode extensions register was (%x)", j));
  1063. j &= 0x20;
  1064. j |= ENABLE_EXTENDED_WRITE_MODES;
  1065. CP_OUT_BYTE(ppdev->pjPorts, DATA_REG, j);
  1066. DISPDBG((3, "Mode extensions register now (%x)", j));
  1067. }
  1068. CP_IO_XPAR_COLOR_MASK(ppdev, ppdev->pjPorts, 0);
  1069. if (!IOCONTROL(ppdev->hDriver,
  1070. IOCTL_VIDEO_QUERY_CURRENT_MODE,
  1071. NULL,
  1072. 0,
  1073. &VideoModeInfo,
  1074. sizeof(VideoModeInfo),
  1075. &ReturnedDataLength))
  1076. {
  1077. DISPDBG((0, "bAssertModeHardware - failed VIDEO_QUERY_CURRENT_MODE"));
  1078. goto ReturnFalse;
  1079. }
  1080. //crus
  1081. //myf1, begin
  1082. #ifdef PANNING_SCROLL
  1083. if ((ppdev->ulChipID == 0x38) || (ppdev->ulChipID == 0x2C) ||
  1084. (ppdev->ulChipID == 0x30) || (ppdev->ulChipID == 0x34) || //myf19
  1085. (ppdev->ulChipID == 0x40) || (ppdev->ulChipID == 0x4C)) //myf17
  1086. {
  1087. CirrusLaptopViewPoint(ppdev, &VideoModeInfo);
  1088. }
  1089. #endif
  1090. //myf1, end
  1091. #if DEBUG_HEAP
  1092. VideoModeInfo.VideoMemoryBitmapWidth = VideoModeInfo.VisScreenWidth;
  1093. VideoModeInfo.VideoMemoryBitmapHeight = VideoModeInfo.VisScreenHeight;
  1094. #endif
  1095. // The following variables are determined only after the initial
  1096. // modeset:
  1097. ppdev->lDelta = VideoModeInfo.ScreenStride;
  1098. ppdev->flCaps = VideoModeInfo.DriverSpecificAttributeFlags;
  1099. DISPDBG((1,"ppdev->flCaps = %x",ppdev->flCaps)); //2
  1100. #if 1 // Check for 5446 chip.
  1101. CP_OUT_BYTE(ppdev->pjPorts, CRTC_INDEX, 0x27);
  1102. ppdev->ulChipID = CP_IN_BYTE(ppdev->pjPorts, CRTC_DATA) & 0xFC;
  1103. //
  1104. // add chip flags for 5446BE and 5480
  1105. //
  1106. //sge01 begin
  1107. if ((ppdev->ulChipID == 0xB8) || (ppdev->ulChipID == 0xBC))
  1108. {
  1109. ppdev->flCaps |= CAPS_VIDEO;
  1110. if (ppdev->ulChipID == 0xBC)
  1111. {
  1112. ppdev->flCaps |= CAPS_SECOND_APERTURE;
  1113. }
  1114. else
  1115. {
  1116. // get revision ID
  1117. CP_OUT_BYTE(ppdev->pjPorts, CRTC_INDEX, 0x25);
  1118. ppdev->ulChipNum = CP_IN_BYTE(ppdev->pjPorts, CRTC_DATA);
  1119. if (ppdev->ulChipNum==0x45)
  1120. ppdev->flCaps |= CAPS_SECOND_APERTURE;
  1121. }
  1122. }
  1123. //myf30 begin
  1124. else if ((ppdev->ulChipID == 0x40) || (ppdev->ulChipID == 0x4C))
  1125. {
  1126. #if (_WIN32_WINNT >= 0x0400)
  1127. ppdev->flCaps |= CAPS_VIDEO;
  1128. #endif
  1129. }
  1130. //myf30 end
  1131. #endif
  1132. //sge01 end
  1133. // Set up the shift factor for the banking code.
  1134. if (ppdev->flCaps & CAPS_IS_542x)
  1135. {
  1136. ppdev->ulBankShiftFactor = 12;
  1137. }
  1138. else
  1139. {
  1140. ppdev->ulBankShiftFactor = 10;
  1141. }
  1142. ppdev->cxMemory = VideoModeInfo.VideoMemoryBitmapWidth;
  1143. ppdev->cyMemory = VideoModeInfo.VideoMemoryBitmapHeight;
  1144. //pat04, begin
  1145. //#if 0
  1146. #if (_WIN32_WINNT < 0x0400)
  1147. ppdev->cxScreen = VideoModeInfo.VisScreenWidth;
  1148. ppdev->cyScreen = VideoModeInfo.VisScreenHeight;
  1149. #endif
  1150. //#endif
  1151. //pat04, end
  1152. //crus begin
  1153. //ms0809, begin
  1154. /********************************************************************
  1155. *
  1156. * If we are on a DSTN panel, then the hardware needs 128K for the
  1157. * half frame accelerator.
  1158. *
  1159. ********************************************************************/
  1160. if ((ppdev->flCaps & CAPS_DSTN_PANEL) &&
  1161. ((ppdev->ulChipID == 0x38) || (ppdev->ulChipID == 0x2C) ||
  1162. (ppdev->ulChipID == 0x30) || (ppdev->ulChipID == 0x34) || //myf19
  1163. (ppdev->ulChipID == 0x40) || (ppdev->ulChipID == 0x4C)) ) //myf17
  1164. {
  1165. // figure out how much cyMemory needs to be decremented by
  1166. // to reserve 128K.
  1167. // =====================================================
  1168. // if Matterhorn 2M/4M board needs to be decremented by
  1169. // to reserve 152K+16k(h/w icon)=168K.
  1170. // =====================================================
  1171. // I need to make sure that if there is a remainder that I
  1172. // remove an additional scan. What is the best way to do
  1173. // this? Is this the memory the DSTN is using? Will it ever
  1174. // use more?
  1175. if ((ppdev->ulChipID == 0x38) || (ppdev->ulChipID == 0x2C) ||
  1176. (ppdev->ulChipID == 0x30) || (ppdev->ulChipID == 0x34)) //myf19
  1177. ppdev->cyMemory -= (0x24000 / ppdev->cxMemory); //myf
  1178. else if ((ppdev->ulChipID == 0x40) || (ppdev->ulChipID == 0x4C))//myf17
  1179. ppdev->cyMemory -= (0x2A000 / ppdev->cxMemory); //myf
  1180. }
  1181. // else if (!(ppdev->flCaps & CAPS_DSTN_PANEL) &&
  1182. else if (((ppdev->ulChipID == 0x38) || (ppdev->ulChipID == 0x2C) || //myf20
  1183. (ppdev->ulChipID == 0x30) || (ppdev->ulChipID == 0x34) || //myf19
  1184. (ppdev->ulChipID == 0x40) || (ppdev->ulChipID == 0x4C))) //myf17
  1185. {
  1186. // figure out how much cyMemory needs to be decremented by
  1187. // to reserve 16K for H/W icon & cursor
  1188. // =====================================================
  1189. ppdev->cyMemory -= (0x4000 / ppdev->cxMemory); //myf
  1190. }
  1191. //ms0809, end
  1192. //crus end
  1193. //sge01 begin
  1194. if (!(ppdev->flCaps & CAPS_BLT_SUPPORT))
  1195. {
  1196. DISPDBG((1, "Cirrus chip doesn't support BLT's"));
  1197. goto ReturnFalse;
  1198. }
  1199. //sge01 end
  1200. //
  1201. // Check to see if we have a non-zero value for pjBase. If so, we
  1202. // can support memory mapped IO.
  1203. //
  1204. if (ppdev->pjBase)
  1205. {
  1206. CP_ENABLE_MM_IO(ppdev, ppdev->pjPorts);
  1207. CP_MM_START_REG(ppdev, ppdev->pjBase, BLT_RESET);
  1208. if (ppdev->flCaps & CAPS_AUTOSTART)
  1209. {
  1210. //
  1211. // enable second aperture for 5480 and 5446BE
  1212. //
  1213. // sge01 begin
  1214. if (ppdev->flCaps & CAPS_SECOND_APERTURE)
  1215. {
  1216. CP_MM_START_REG(ppdev, ppdev->pjBase, BLT_AUTO_START | BLT_SECOND_APERTURE);
  1217. }
  1218. else
  1219. //sge01 end
  1220. {
  1221. CP_MM_START_REG(ppdev, ppdev->pjBase, BLT_AUTO_START);
  1222. }
  1223. }
  1224. }
  1225. else
  1226. {
  1227. CP_DISABLE_MM_IO(ppdev, ppdev->pjPorts);
  1228. CP_IO_START_REG(ppdev, ppdev->pjPorts, BLT_RESET);
  1229. if (ppdev->flCaps & CAPS_AUTOSTART)
  1230. {
  1231. //
  1232. // enable second aperture for 5480 and 5446BE
  1233. //
  1234. // sge01 begin
  1235. if (ppdev->flCaps & CAPS_SECOND_APERTURE)
  1236. {
  1237. CP_IO_START_REG(ppdev, ppdev->pjBase, BLT_AUTO_START | BLT_SECOND_APERTURE);
  1238. }
  1239. else
  1240. //sge 01 end
  1241. {
  1242. CP_IO_START_REG(ppdev, ppdev->pjBase, BLT_AUTO_START);
  1243. }
  1244. }
  1245. }
  1246. /********************************************************************
  1247. *
  1248. * If we're using the hardware pointer, reserve the last scan of
  1249. * the frame buffer to store the pointer shape. The pointer MUST be
  1250. * stored in the last 256 bytes of video memory.
  1251. *
  1252. ********************************************************************/
  1253. // #pat08 start
  1254. //#if 0
  1255. #if (_WIN32_WINNT < 0x0400)
  1256. #ifdef PANNING_SCROLL
  1257. // allocate without test
  1258. // if ((ppdev->ulChipID != CL7541_ID) && (ppdev->ulChipID != CL7543_ID) &&
  1259. // (ppdev->ulChipID != CL7542_ID) && (ppdev->ulChipID != CL7548_ID) &&
  1260. // (ppdev->ulChipID != CL7555_ID) && (ppdev->ulChipID != CL7556_ID))
  1261. // if (!(ppdev->flCaps & (CAPS_SW_POINTER)))
  1262. // else
  1263. // ;
  1264. #else
  1265. if (!(ppdev->flCaps & (CAPS_SW_POINTER)))
  1266. #endif
  1267. #else // NT 4.0 code
  1268. if (!(ppdev->flCaps & (CAPS_SW_POINTER)))
  1269. #endif
  1270. //#endif //0,pat08
  1271. // #pat08 end
  1272. //pat08 if (!(ppdev->flCaps & (CAPS_SW_POINTER)))
  1273. {
  1274. // We'll reserve the end of off-screen memory for the hardware
  1275. // pointer shape.
  1276. cjPointerOffset = (ppdev->ulMemSize - SPRITE_BUFFER_SIZE);
  1277. // Figure out the coordinate where the pointer shape starts:
  1278. lDelta = ppdev->lDelta;
  1279. ppdev->cjPointerOffset = cjPointerOffset;
  1280. ppdev->yPointerShape = (cjPointerOffset / lDelta);
  1281. ppdev->xPointerShape = (cjPointerOffset % lDelta) / ppdev->cBpp;
  1282. if (ppdev->yPointerShape >= ppdev->cyScreen)
  1283. {
  1284. // There's enough room for the pointer shape at the
  1285. // bottom of off-screen memory; reserve its room by
  1286. // lying about how much off-screen memory there is:
  1287. ppdev->cyMemory = min(ppdev->yPointerShape, ppdev->cyMemory);
  1288. }
  1289. else
  1290. {
  1291. // There's not enough room for the pointer shape in
  1292. // off-screen memory; we'll have to simulate:
  1293. DISPDBG((2,"Not enough room for HW pointer...\n"
  1294. "\tppdev->yPointerShape(%d)\n"
  1295. "\tppdev->cyScreen(%d)\n"
  1296. "\tcjPointerOffset(%d)",
  1297. ppdev->yPointerShape, ppdev->cyScreen,cjPointerOffset));
  1298. ppdev->flCaps |= CAPS_SW_POINTER;
  1299. }
  1300. }
  1301. // !!! No room for a transfer buffer, as in the 1280x1024 case on
  1302. // a 2 MB card. This case should go away when the miniport
  1303. // is fixed to return non-power-of-2 screen strides.
  1304. if ((ppdev->cyMemory == ppdev->cyScreen) ||
  1305. (ppdev->flCaps & CAPS_NO_HOST_XFER))
  1306. {
  1307. //
  1308. // disable host xfer buffer
  1309. //
  1310. ppdev->lXferBank = 0;
  1311. ppdev->pulXfer = NULL;
  1312. DISPDBG((2,"Host transfers disabled"));
  1313. }
  1314. else
  1315. {
  1316. //
  1317. // for chips do not have second aperture
  1318. //
  1319. // sge01 begin
  1320. if (!(ppdev->flCaps & CAPS_SECOND_APERTURE))
  1321. {
  1322. if (ppdev->flCaps & CAPS_AUTOSTART)
  1323. {
  1324. (BYTE*)ppdev->pulXfer = ppdev->pjScreen;
  1325. }
  1326. else
  1327. {
  1328. //
  1329. // enable host xfer buffer
  1330. //
  1331. ASSERTDD(ppdev->cyMemory > ppdev->cyScreen, "No scans left for blt xfer buffer");
  1332. ppdev->cyMemory--;
  1333. cjEndOfFrameBuffer = ppdev->cyMemory * ppdev->lDelta;
  1334. ppdev->lXferBank = cjEndOfFrameBuffer / ppdev->cjBank;
  1335. (BYTE*)ppdev->pulXfer = ppdev->pjScreen + (cjEndOfFrameBuffer % ppdev->cjBank);
  1336. DISPDBG((2, "ppdev->cyMemory = %x", ppdev->cyMemory)) ;
  1337. DISPDBG((2, "ppdev->lDelta = %x", ppdev->lDelta)) ;
  1338. DISPDBG((2, "cjBank: %lx", ppdev->cjBank)) ;
  1339. DISPDBG((2, "pulXfer = %x", ppdev->pulXfer)) ;
  1340. DISPDBG((2, "Host transfers enabled")) ;
  1341. }
  1342. }
  1343. #if 0 // D5480
  1344. //
  1345. // allocate command list buffer
  1346. //
  1347. if ((ppdev->flCaps & CAPS_COMMAND_LIST) && FALSE)
  1348. {
  1349. ppdev->cyMemory -= (COMMAND_BUFFER_SIZE + COMMAND_BUFFER_ALIGN + ppdev->lDelta / 2 ) / ppdev->lDelta;
  1350. cjEndOfFrameBuffer = ppdev->cyMemory * ppdev->lDelta;
  1351. pFirstCL = (ULONG)(((ULONG_PTR)ppdev->pjScreen + cjEndOfFrameBuffer + COMMAND_BUFFER_ALIGN) & ~COMMAND_BUFFER_ALIGN);
  1352. pSecondCL = pFirstCL + (COMMAND_BUFFER_SIZE >> 1);
  1353. ppdev->pCLFirst = (ULONG_PTR*) pFirstCL;
  1354. ppdev->pCLSecond = (ULONG_PTR*) pSecondCL;
  1355. ppdev->pCommandList = ppdev->pCLFirst;
  1356. }
  1357. #endif // endif D5480
  1358. //
  1359. // Make sure we don't try to use command lists.
  1360. //
  1361. ppdev->pCommandList = NULL;
  1362. }
  1363. DISPDBG((2, "ppdev->cxMemory = %x", ppdev->cxMemory)) ;
  1364. DISPDBG((2, "ppdev->cyMemory = %x", ppdev->cyMemory)) ;
  1365. DISPDBG((2, "ppdev->cxScreen = %x", ppdev->cxScreen)) ;
  1366. DISPDBG((2, "ppdev->cyScreen = %x", ppdev->cyScreen)) ;
  1367. DISPDBG((2, "ppdev->lDelta = %x", ppdev->lDelta)) ;
  1368. DISPDBG((2, "cjBank: %lx", ppdev->cjBank)) ;
  1369. DISPDBG((2,"pulXfer = %x", ppdev->pulXfer)) ;
  1370. // Do some paramater checking on the values that the miniport
  1371. // returned to us:
  1372. ASSERTDD(ppdev->cxMemory >= ppdev->cxScreen, "Invalid cxMemory");
  1373. ASSERTDD(ppdev->cyMemory >= ppdev->cyScreen, "Invalid cyMemory");
  1374. }
  1375. else
  1376. {
  1377. CP_DISABLE_MM_IO(ppdev, ppdev->pjPorts);
  1378. // Call the kernel driver to reset the device to a known state.
  1379. // NTVDM will take things from there:
  1380. if (!IOCONTROL(ppdev->hDriver,
  1381. IOCTL_VIDEO_RESET_DEVICE,
  1382. NULL,
  1383. 0,
  1384. NULL,
  1385. 0,
  1386. &ulReturn))
  1387. {
  1388. DISPDBG((0, "bAssertModeHardware - Failed reset IOCTL"));
  1389. return FALSE;
  1390. }
  1391. }
  1392. DISPDBG((5, "Passed bAssertModeHardware"));
  1393. return(TRUE);
  1394. ReturnFalse:
  1395. DISPDBG((0, "Failed bAssertModeHardware"));
  1396. return(FALSE);
  1397. }
  1398. /******************************Public*Routine******************************\
  1399. * BOOL bEnableHardware
  1400. *
  1401. * Puts the hardware in the requested mode and initializes it.
  1402. *
  1403. * Note: Should be called before any access is done to the hardware from
  1404. * the display driver.
  1405. *
  1406. \**************************************************************************/
  1407. BOOL bEnableHardware(
  1408. PDEV* ppdev)
  1409. {
  1410. VIDEO_PUBLIC_ACCESS_RANGES VideoAccessRange[2];
  1411. VIDEO_MEMORY VideoMemory;
  1412. //sge01 VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
  1413. VIDEO_MEMORY_INFORMATION VideoMemoryInfo[2]; // sge01
  1414. DWORD ReturnedDataLength;
  1415. BYTE* pjPorts = ppdev->pjPorts;
  1416. ULONG ulMode;
  1417. BOOL bRet;
  1418. //
  1419. // Check the last field in the PDEV to make sure that the compiler
  1420. // didn't generate unaligned fields following BYTE fields.
  1421. //
  1422. ASSERTDD(!(((ULONG_PTR)(&ppdev->ulLastField)) & 3),
  1423. "PDEV alignment screwed up... BYTE fields mishandled?");
  1424. // Map the ports.
  1425. bRet = IOCONTROL(ppdev->hDriver,
  1426. IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES,
  1427. NULL, // input buffer
  1428. 0,
  1429. (PVOID) &VideoAccessRange, // output buffer
  1430. sizeof (VideoAccessRange),
  1431. &ReturnedDataLength);
  1432. if (bRet == FALSE)
  1433. {
  1434. DISPDBG((0, "bEnableHardware - Error mapping ports"));
  1435. goto ReturnFalse;
  1436. }
  1437. // Set a convienent pointer to the registers in the pdev.
  1438. ppdev->pjPorts = VideoAccessRange[0].VirtualAddress;
  1439. ppdev->pjBase = VideoAccessRange[1].VirtualAddress;
  1440. //
  1441. // Merge port and register access for
  1442. // VGA relocatable and MMIO registers.
  1443. //
  1444. // sge02 begin
  1445. #if defined(_X86_)
  1446. if (VideoAccessRange[0].InIoSpace)
  1447. {
  1448. ppdev->pfnREAD_PORT_UCHAR = CirrusREAD_PORT_UCHAR;
  1449. ppdev->pfnREAD_PORT_USHORT = CirrusREAD_PORT_USHORT;
  1450. ppdev->pfnREAD_PORT_ULONG = CirrusREAD_PORT_ULONG;
  1451. ppdev->pfnWRITE_PORT_UCHAR = CirrusWRITE_PORT_UCHAR;
  1452. ppdev->pfnWRITE_PORT_USHORT = CirrusWRITE_PORT_USHORT;
  1453. ppdev->pfnWRITE_PORT_ULONG = CirrusWRITE_PORT_ULONG;
  1454. }
  1455. else
  1456. {
  1457. ppdev->pfnREAD_PORT_UCHAR = CirrusREAD_REGISTER_UCHAR;
  1458. ppdev->pfnREAD_PORT_USHORT = CirrusREAD_REGISTER_USHORT;
  1459. ppdev->pfnREAD_PORT_ULONG = CirrusREAD_REGISTER_ULONG;
  1460. ppdev->pfnWRITE_PORT_UCHAR = CirrusWRITE_REGISTER_UCHAR;
  1461. ppdev->pfnWRITE_PORT_USHORT = CirrusWRITE_REGISTER_USHORT;
  1462. ppdev->pfnWRITE_PORT_ULONG = CirrusWRITE_REGISTER_ULONG;
  1463. }
  1464. #elif defined(_ALPHA_)
  1465. if (VideoAccessRange[0].InIoSpace)
  1466. {
  1467. ppdev->pfnREAD_PORT_UCHAR = READ_PORT_UCHAR;
  1468. ppdev->pfnREAD_PORT_USHORT = READ_PORT_USHORT;
  1469. ppdev->pfnREAD_PORT_ULONG = READ_PORT_ULONG;
  1470. ppdev->pfnWRITE_PORT_UCHAR = WRITE_PORT_UCHAR;
  1471. ppdev->pfnWRITE_PORT_USHORT = WRITE_PORT_USHORT;
  1472. ppdev->pfnWRITE_PORT_ULONG = WRITE_PORT_ULONG;
  1473. }
  1474. else
  1475. {
  1476. ppdev->pfnREAD_PORT_UCHAR = READ_REGISTER_UCHAR;
  1477. ppdev->pfnREAD_PORT_USHORT = READ_REGISTER_USHORT;
  1478. ppdev->pfnREAD_PORT_ULONG = READ_REGISTER_ULONG;
  1479. ppdev->pfnWRITE_PORT_UCHAR = (FnWRITE_PORT_UCHAR)WRITE_REGISTER_UCHAR;
  1480. ppdev->pfnWRITE_PORT_USHORT = (FnWRITE_PORT_USHORT)WRITE_REGISTER_USHORT;
  1481. ppdev->pfnWRITE_PORT_ULONG = (FnWRITE_PORT_ULONG)WRITE_REGISTER_ULONG;
  1482. }
  1483. #endif
  1484. //sge02 end
  1485. //
  1486. // Try to get the miniport to give us a mode with a linear frame buffer.
  1487. //
  1488. ulMode = ppdev->ulMode | VIDEO_MODE_MAP_MEM_LINEAR;
  1489. if (!IOCONTROL(ppdev->hDriver,
  1490. IOCTL_VIDEO_SET_CURRENT_MODE,
  1491. &ulMode, // input buffer
  1492. sizeof(DWORD),
  1493. NULL,
  1494. 0,
  1495. &ReturnedDataLength))
  1496. {
  1497. //
  1498. // We could not set this mode with a linear frame buffer, so lets try
  1499. // again banked.
  1500. //
  1501. ulMode &= ~VIDEO_MODE_MAP_MEM_LINEAR;
  1502. if (!IOCONTROL(ppdev->hDriver,
  1503. IOCTL_VIDEO_SET_CURRENT_MODE,
  1504. &ulMode, // input buffer
  1505. sizeof(DWORD),
  1506. NULL,
  1507. 0,
  1508. &ReturnedDataLength))
  1509. {
  1510. DISPDBG((0, "bEnableHardware - Failed VIDEO_SET_CURRENT_MODE"));
  1511. goto ReturnFalse;
  1512. }
  1513. }
  1514. ppdev->bLinearMode = (ulMode & VIDEO_MODE_MAP_MEM_LINEAR) ? TRUE : FALSE;
  1515. // Get the linear memory address range.
  1516. VideoMemory.RequestedVirtualAddress = NULL;
  1517. if (!IOCONTROL(ppdev->hDriver,
  1518. IOCTL_VIDEO_MAP_VIDEO_MEMORY,
  1519. &VideoMemory, // input buffer
  1520. sizeof(VIDEO_MEMORY),
  1521. &VideoMemoryInfo, // output buffer
  1522. sizeof(VideoMemoryInfo),
  1523. &ReturnedDataLength))
  1524. {
  1525. DISPDBG((0, "bEnableHardware - Error mapping video buffer"));
  1526. goto ReturnFalse;
  1527. }
  1528. //myfr, 2
  1529. DISPDBG((2, "FrameBufferBase(ie. pjScreen) %lx",
  1530. VideoMemoryInfo[0].FrameBufferBase));
  1531. DISPDBG((2, "FrameBufferLength %d",
  1532. VideoMemoryInfo[0].FrameBufferLength));
  1533. DISPDBG((2, "VideoRamLength(ie. ulMemSize) %d",
  1534. VideoMemoryInfo[0].VideoRamLength));
  1535. // Record the Frame Buffer Linear Address.
  1536. //sge01
  1537. ppdev->pjScreen = (BYTE*) VideoMemoryInfo[0].FrameBufferBase;
  1538. ppdev->cjBank = VideoMemoryInfo[0].FrameBufferLength;
  1539. ppdev->ulMemSize = VideoMemoryInfo[0].VideoRamLength;
  1540. // Now we can set the mode and unlock the accelerator.
  1541. if (!bAssertModeHardware(ppdev, TRUE))
  1542. {
  1543. goto ReturnFalse;
  1544. }
  1545. //sge01 begin
  1546. if ((ppdev->flCaps & CAPS_SECOND_APERTURE) &&
  1547. !(ppdev->flCaps & CAPS_NO_HOST_XFER))
  1548. {
  1549. ppdev->pulXfer = VideoMemoryInfo[1].VideoRamBase;
  1550. }
  1551. //sge01 end
  1552. if (ppdev->flCaps & CAPS_MM_IO)
  1553. {
  1554. DISPDBG((1,"Memory mapped IO enabled"));
  1555. #if 1 // D5480
  1556. if ((ppdev->flCaps & CAPS_COMMAND_LIST) &&
  1557. (ppdev->pCommandList != NULL))
  1558. {
  1559. //
  1560. // Bitmap functions
  1561. //
  1562. ppdev->pfnXfer1bpp = vMmXfer1bpp80;
  1563. ppdev->pfnXfer4bpp = vMmXfer4bpp;
  1564. ppdev->pfnXferNative = vMmXferNative80;
  1565. //
  1566. // Pattern functions
  1567. //
  1568. //
  1569. // chu02 : This is due to hardware error for 24bpp,
  1570. // GR2f[4..0] != 0, non-color expandsion and 8x8 pattern
  1571. // copy.
  1572. //
  1573. ppdev->pfnFillPat = (ppdev->cBpp == 3) ?
  1574. vMmFillPat36 : vMmFillPat80;
  1575. ppdev->pfnFillSolid = vMmFillSolid80;
  1576. ppdev->pfnCopyBlt = vMmCopyBlt80;
  1577. //
  1578. // Text functions
  1579. //
  1580. ppdev->pfnGlyphOut = vMmGlyphOut80;
  1581. ppdev->pfnGlyphOutClip = vMmGlyphOutClip80;
  1582. }
  1583. else if(ppdev->flCaps & CAPS_AUTOSTART)
  1584. {
  1585. // bitmap functions
  1586. ppdev->pfnXfer1bpp = vMmXfer1bpp;
  1587. ppdev->pfnXfer4bpp = vMmXfer4bpp;
  1588. ppdev->pfnXferNative = vMmXferNative;
  1589. // Pattern functions
  1590. ppdev->pfnFillPat = vMmFillPat36;
  1591. ppdev->pfnFillSolid = vMmFillSolid36;
  1592. ppdev->pfnCopyBlt = vMmCopyBlt36;
  1593. // Text functions
  1594. ppdev->pfnGlyphOut = vMmGlyphOut;
  1595. ppdev->pfnGlyphOutClip = vMmGlyphOutClip;
  1596. }
  1597. else
  1598. {
  1599. // bitmap functions
  1600. ppdev->pfnXfer1bpp = vMmXfer1bpp;
  1601. ppdev->pfnXfer4bpp = vMmXfer4bpp;
  1602. ppdev->pfnXferNative = vMmXferNative;
  1603. // Pattern functions
  1604. ppdev->pfnFillPat = vMmFillPat;
  1605. ppdev->pfnFillSolid = vMmFillSolid;
  1606. ppdev->pfnCopyBlt = vMmCopyBlt;
  1607. // Text functions
  1608. ppdev->pfnGlyphOut = vMmGlyphOut;
  1609. ppdev->pfnGlyphOutClip = vMmGlyphOutClip;
  1610. }
  1611. ppdev->pfnFastPatRealize = vMmFastPatRealize;
  1612. #if LINETO
  1613. ppdev->pfnLineTo = bMmLineTo;
  1614. #endif
  1615. #endif // endif D5480
  1616. }
  1617. else
  1618. {
  1619. DISPDBG((1,"Memory mapped IO disabled"));
  1620. ppdev->pfnXfer1bpp = vIoXfer1bpp;
  1621. ppdev->pfnXfer4bpp = vIoXfer4bpp;
  1622. ppdev->pfnXferNative = vIoXferNative;
  1623. ppdev->pfnFillSolid = vIoFillSolid;
  1624. ppdev->pfnFillPat = vIoFillPat;
  1625. ppdev->pfnCopyBlt = vIoCopyBlt;
  1626. ppdev->pfnFastPatRealize = vIoFastPatRealize;
  1627. #if LINETO
  1628. ppdev->pfnLineTo = bIoLineTo;
  1629. #endif
  1630. }
  1631. /////////////////////////////////////////////////////////////
  1632. // Fill in pfns specific to linear vs banked frame buffer
  1633. if (ppdev->bLinearMode)
  1634. {
  1635. ppdev->pfnGetBits = vGetBitsLinear;
  1636. ppdev->pfnPutBits = vPutBitsLinear;
  1637. }
  1638. else
  1639. {
  1640. ppdev->pfnGetBits = vGetBits;
  1641. ppdev->pfnPutBits = vPutBits;
  1642. }
  1643. DISPDBG((5, "Passed bEnableHardware"));
  1644. return(TRUE);
  1645. ReturnFalse:
  1646. DISPDBG((0, "Failed bEnableHardware"));
  1647. return(FALSE);
  1648. }
  1649. /******************************Public*Routine******************************\
  1650. * VOID vDisableHardware
  1651. *
  1652. * Undoes anything done in bEnableHardware.
  1653. *
  1654. * Note: In an error case, we may call this before bEnableHardware is
  1655. * completely done.
  1656. *
  1657. \**************************************************************************/
  1658. VOID vDisableHardware(
  1659. PDEV* ppdev)
  1660. {
  1661. //
  1662. // It is possible that we reached this point without
  1663. // actually mapping memory. (i.e. if the SET_CURRENT_MODE
  1664. // failed which occurs before we map memory)
  1665. //
  1666. // If this is the case, we should not try to free the
  1667. // memory, because it hasn't been mapped!
  1668. //
  1669. if (ppdev->pjScreen)
  1670. {
  1671. DWORD ReturnedDataLength;
  1672. VIDEO_MEMORY VideoMemory;
  1673. VideoMemory.RequestedVirtualAddress = ppdev->pjScreen;
  1674. if (!IOCONTROL(ppdev->hDriver,
  1675. IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
  1676. &VideoMemory,
  1677. sizeof(VIDEO_MEMORY),
  1678. NULL,
  1679. 0,
  1680. &ReturnedDataLength))
  1681. {
  1682. DISPDBG((0, "vDisableHardware failed IOCTL_VIDEO_UNMAP_VIDEO"));
  1683. }
  1684. }
  1685. }
  1686. /******************************Public*Routine******************************\
  1687. * BOOL bInitializeModeFields
  1688. *
  1689. * Initializes a bunch of fields in the pdev, devcaps (aka gdiinfo), and
  1690. * devinfo based on the requested mode.
  1691. *
  1692. \**************************************************************************/
  1693. BOOL bInitializeModeFields(
  1694. PDEV* ppdev,
  1695. GDIINFO* pgdi,
  1696. DEVINFO* pdi,
  1697. DEVMODEW* pdm)
  1698. {
  1699. ULONG cModes;
  1700. PVIDEO_MODE_INFORMATION pVideoBuffer;
  1701. PVIDEO_MODE_INFORMATION pVideoModeSelected;
  1702. PVIDEO_MODE_INFORMATION pVideoTemp;
  1703. BOOL bSelectDefault;
  1704. VIDEO_MODE_INFORMATION VideoModeInformation;
  1705. ULONG cbModeSize;
  1706. // crus
  1707. VIDEO_PUBLIC_ACCESS_RANGES VideoAccessRange[2];
  1708. VIDEO_MEMORY VideoMemory;
  1709. DWORD ReturnedDataLength;
  1710. BOOL bRet;
  1711. DISPDBG((2, "bInitializeModeFields"));
  1712. // crus
  1713. bRet = IOCONTROL(ppdev->hDriver,
  1714. IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES,
  1715. NULL, // input buffer
  1716. 0,
  1717. (PVOID) &VideoAccessRange, // output buffer
  1718. sizeof (VideoAccessRange),
  1719. &ReturnedDataLength);
  1720. if (bRet == FALSE)
  1721. {
  1722. DISPDBG((0, "bInitializeModeFields - Error mapping ports"));
  1723. goto ReturnFalse;
  1724. }
  1725. // Set a convienent pointer to the registers in the pdev.
  1726. ppdev->pjPorts = VideoAccessRange[0].VirtualAddress;
  1727. ppdev->pjBase = VideoAccessRange[1].VirtualAddress;
  1728. //sge01 end
  1729. //
  1730. // Merge port and register access for
  1731. // VGA relocatable and MMIO registers.
  1732. //
  1733. // crus
  1734. #if defined(_X86_)
  1735. if (VideoAccessRange[0].InIoSpace)
  1736. {
  1737. ppdev->pfnREAD_PORT_UCHAR = CirrusREAD_PORT_UCHAR;
  1738. ppdev->pfnREAD_PORT_USHORT = CirrusREAD_PORT_USHORT;
  1739. ppdev->pfnREAD_PORT_ULONG = CirrusREAD_PORT_ULONG;
  1740. ppdev->pfnWRITE_PORT_UCHAR = CirrusWRITE_PORT_UCHAR;
  1741. ppdev->pfnWRITE_PORT_USHORT = CirrusWRITE_PORT_USHORT;
  1742. ppdev->pfnWRITE_PORT_ULONG = CirrusWRITE_PORT_ULONG;
  1743. }
  1744. else
  1745. {
  1746. ppdev->pfnREAD_PORT_UCHAR = CirrusREAD_REGISTER_UCHAR;
  1747. ppdev->pfnREAD_PORT_USHORT = CirrusREAD_REGISTER_USHORT;
  1748. ppdev->pfnREAD_PORT_ULONG = CirrusREAD_REGISTER_ULONG;
  1749. ppdev->pfnWRITE_PORT_UCHAR = CirrusWRITE_REGISTER_UCHAR;
  1750. ppdev->pfnWRITE_PORT_USHORT = CirrusWRITE_REGISTER_USHORT;
  1751. ppdev->pfnWRITE_PORT_ULONG = CirrusWRITE_REGISTER_ULONG;
  1752. }
  1753. #elif defined(_ALPHA_)
  1754. if (VideoAccessRange[0].InIoSpace)
  1755. {
  1756. ppdev->pfnREAD_PORT_UCHAR = READ_PORT_UCHAR;
  1757. ppdev->pfnREAD_PORT_USHORT = READ_PORT_USHORT;
  1758. ppdev->pfnREAD_PORT_ULONG = READ_PORT_ULONG;
  1759. ppdev->pfnWRITE_PORT_UCHAR = WRITE_PORT_UCHAR;
  1760. ppdev->pfnWRITE_PORT_USHORT = WRITE_PORT_USHORT;
  1761. ppdev->pfnWRITE_PORT_ULONG = WRITE_PORT_ULONG;
  1762. }
  1763. else
  1764. {
  1765. ppdev->pfnREAD_PORT_UCHAR = READ_REGISTER_UCHAR;
  1766. ppdev->pfnREAD_PORT_USHORT = READ_REGISTER_USHORT;
  1767. ppdev->pfnREAD_PORT_ULONG = READ_REGISTER_ULONG;
  1768. ppdev->pfnWRITE_PORT_UCHAR = (FnWRITE_PORT_UCHAR)WRITE_REGISTER_UCHAR;
  1769. ppdev->pfnWRITE_PORT_USHORT = (FnWRITE_PORT_USHORT)WRITE_REGISTER_USHORT;
  1770. ppdev->pfnWRITE_PORT_ULONG = (FnWRITE_PORT_ULONG)WRITE_REGISTER_ULONG;
  1771. }
  1772. #endif
  1773. //crus
  1774. CP_OUT_BYTE(ppdev->pjPorts, CRTC_INDEX, 0x27);
  1775. ppdev->ulChipID = CP_IN_BYTE(ppdev->pjPorts, CRTC_DATA) & 0xFC;
  1776. // Call the miniport to get mode information
  1777. cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
  1778. if (cModes == 0)
  1779. {
  1780. DISPDBG((2, "getAvailableModes returned 0"));
  1781. goto ReturnFalse;
  1782. }
  1783. // Now see if the requested mode has a match in that table.
  1784. pVideoModeSelected = NULL;
  1785. pVideoTemp = pVideoBuffer;
  1786. if ((pdm->dmPelsWidth == 0) &&
  1787. (pdm->dmPelsHeight == 0) &&
  1788. (pdm->dmBitsPerPel == 0) &&
  1789. (pdm->dmDisplayFrequency == 0))
  1790. {
  1791. DISPDBG((2, "Default mode requested"));
  1792. bSelectDefault = TRUE;
  1793. }
  1794. else
  1795. {
  1796. DISPDBG((2, "Requested mode..."));
  1797. DISPDBG((2, " Screen width -- %li", pdm->dmPelsWidth));
  1798. DISPDBG((2, " Screen height -- %li", pdm->dmPelsHeight));
  1799. DISPDBG((2, " Bits per pel -- %li", pdm->dmBitsPerPel));
  1800. DISPDBG((2, " Frequency -- %li", pdm->dmDisplayFrequency));
  1801. bSelectDefault = FALSE;
  1802. }
  1803. while (cModes--)
  1804. {
  1805. if (pVideoTemp->Length != 0)
  1806. {
  1807. //myfr, 2->0
  1808. DISPDBG((2, "Checking against miniport mode:"));
  1809. DISPDBG((2, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  1810. DISPDBG((2, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  1811. DISPDBG((2, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  1812. pVideoTemp->NumberOfPlanes));
  1813. DISPDBG((2, " Frequency -- %li", pVideoTemp->Frequency));
  1814. //pat04, begin
  1815. //#if 0
  1816. #if (_WIN32_WINNT < 0x0400)
  1817. if ((ppdev->ulChipID == CL7541_ID) || (ppdev->ulChipID == CL7543_ID) ||
  1818. (ppdev->ulChipID == CL7542_ID) || (ppdev->ulChipID == CL7548_ID) ||
  1819. (ppdev->ulChipID == CL7555_ID) || (ppdev->ulChipID == CL7556_ID))
  1820. {
  1821. if ((pVideoTemp->VisScreenWidth == 640) &&
  1822. (pVideoTemp->VisScreenHeight == 480) &&
  1823. (pVideoTemp->BitsPerPlane *
  1824. pVideoTemp->NumberOfPlanes == 8) &&
  1825. (pVideoTemp->Frequency == 60))
  1826. {
  1827. pVideoModeSelected = pVideoTemp;
  1828. } // default mode = 640x480x256 ! //#pat4
  1829. }
  1830. #endif
  1831. //#endif //0, pat04
  1832. //pat04, end
  1833. if (bSelectDefault ||
  1834. ((pVideoTemp->VisScreenWidth == pdm->dmPelsWidth) &&
  1835. (pVideoTemp->VisScreenHeight == pdm->dmPelsHeight) &&
  1836. (pVideoTemp->BitsPerPlane *
  1837. pVideoTemp->NumberOfPlanes == pdm->dmBitsPerPel) &&
  1838. (pVideoTemp->Frequency == pdm->dmDisplayFrequency)))
  1839. {
  1840. pVideoModeSelected = pVideoTemp;
  1841. DISPDBG((2, "...Found a mode match!"));
  1842. break;
  1843. }
  1844. }
  1845. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1846. (((PUCHAR)pVideoTemp) + cbModeSize);
  1847. }
  1848. // If no mode has been found, return an error
  1849. if (pVideoModeSelected == NULL)
  1850. {
  1851. DISPDBG((2, "...Couldn't find a mode match!"));
  1852. FREE(pVideoBuffer); //ms923
  1853. goto ReturnFalse;
  1854. }
  1855. // We have chosen the one we want. Save it in a stack buffer and
  1856. // get rid of allocated memory before we forget to free it.
  1857. VideoModeInformation = *pVideoModeSelected;
  1858. FREE(pVideoBuffer);
  1859. #if DEBUG_HEAP
  1860. VideoModeInformation.VisScreenWidth = 640;
  1861. VideoModeInformation.VisScreenHeight = 480;
  1862. #endif
  1863. // Set up screen information from the mini-port:
  1864. ppdev->ulMode = VideoModeInformation.ModeIndex;
  1865. ppdev->cxScreen = VideoModeInformation.VisScreenWidth;
  1866. ppdev->cyScreen = VideoModeInformation.VisScreenHeight;
  1867. DISPDBG((2, "ScreenStride: %lx", VideoModeInformation.ScreenStride));
  1868. //crus
  1869. #ifdef PANNING_SCROLL
  1870. if ((ppdev->ulChipID == 0x38) || (ppdev->ulChipID == 0x2C) ||
  1871. (ppdev->ulChipID == 0x30) || (ppdev->ulChipID == 0x34) || //myf19
  1872. (ppdev->ulChipID == 0x40) || (ppdev->ulChipID == 0x4C)) //myf17
  1873. {
  1874. CirrusLaptopViewPoint(ppdev, &VideoModeInformation);
  1875. }
  1876. #endif
  1877. // Setting the SYNCHRONIZEACCESS flag tells GDI that we
  1878. // want all drawing to the bitmaps to be synchronized (GDI
  1879. // is multi-threaded and by default does not synchronize
  1880. // device bitmap drawing -- it would be a Bad Thing for us
  1881. // to have multiple threads using the accelerator at the
  1882. // same time):
  1883. ppdev->flHooks = HOOK_SYNCHRONIZEACCESS
  1884. | HOOK_FILLPATH
  1885. | HOOK_BITBLT
  1886. | HOOK_TEXTOUT
  1887. | HOOK_COPYBITS
  1888. | HOOK_STROKEPATH
  1889. | HOOK_SYNCHRONIZE
  1890. #if LINETO
  1891. | HOOK_LINETO
  1892. #endif
  1893. #if !DRIVER_PUNT_ALL
  1894. #if !DRIVER_PUNT_STRETCH
  1895. | HOOK_STRETCHBLT
  1896. #endif
  1897. #endif
  1898. ;
  1899. // Fill in the GDIINFO data structure with the default 8bpp values:
  1900. *pgdi = ggdiDefault;
  1901. // Now overwrite the defaults with the relevant information returned
  1902. // from the kernel driver:
  1903. pgdi->ulHorzSize = VideoModeInformation.XMillimeter;
  1904. pgdi->ulVertSize = VideoModeInformation.YMillimeter;
  1905. pgdi->ulHorzRes = VideoModeInformation.VisScreenWidth;
  1906. pgdi->ulVertRes = VideoModeInformation.VisScreenHeight;
  1907. #if (NT_VERSION < 0x0400)
  1908. pgdi->ulDesktopHorzRes = VideoModeInformation.VisScreenWidth;
  1909. pgdi->ulDesktopVertRes = VideoModeInformation.VisScreenHeight;
  1910. #else
  1911. pgdi->ulPanningHorzRes = VideoModeInformation.VisScreenWidth;
  1912. pgdi->ulPanningVertRes = VideoModeInformation.VisScreenHeight;
  1913. #endif
  1914. pgdi->cBitsPixel = VideoModeInformation.BitsPerPlane;
  1915. pgdi->cPlanes = VideoModeInformation.NumberOfPlanes;
  1916. pgdi->ulVRefresh = VideoModeInformation.Frequency;
  1917. pgdi->ulDACRed = VideoModeInformation.NumberRedBits;
  1918. pgdi->ulDACGreen = VideoModeInformation.NumberGreenBits;
  1919. pgdi->ulDACBlue = VideoModeInformation.NumberBlueBits;
  1920. pgdi->ulLogPixelsX = pdm->dmLogPixels;
  1921. pgdi->ulLogPixelsY = pdm->dmLogPixels;
  1922. // Fill in the devinfo structure with the default 8bpp values:
  1923. *pdi = gdevinfoDefault;
  1924. // Several MIPS machines are broken in that 64 bit accesses to the
  1925. // framebuffer don't work.
  1926. #ifdef GCAPS_NO64BITMEMACCESS
  1927. if (VideoModeInformation.AttributeFlags & VIDEO_MODE_NO_64_BIT_ACCESS)
  1928. {
  1929. DISPDBG((2, "Disable 64 bit access on this device !\n"));
  1930. pdi->flGraphicsCaps |= GCAPS_NO64BITMEMACCESS;
  1931. }
  1932. #endif
  1933. if (VideoModeInformation.BitsPerPlane == 8)
  1934. {
  1935. ppdev->cBpp = 1;
  1936. ppdev->cBitsPerPixel = 8;
  1937. ppdev->iBitmapFormat = BMF_8BPP;
  1938. ppdev->jModeColor = 0;
  1939. ppdev->ulWhite = 0xff;
  1940. }
  1941. else if ((VideoModeInformation.BitsPerPlane == 16) ||
  1942. (VideoModeInformation.BitsPerPlane == 15))
  1943. {
  1944. ppdev->cBpp = 2;
  1945. ppdev->cBitsPerPixel = 16;
  1946. ppdev->iBitmapFormat = BMF_16BPP;
  1947. ppdev->jModeColor = SET_16BPP_COLOR;
  1948. ppdev->ulWhite = 0xffff;
  1949. ppdev->flRed = VideoModeInformation.RedMask;
  1950. ppdev->flGreen = VideoModeInformation.GreenMask;
  1951. ppdev->flBlue = VideoModeInformation.BlueMask;
  1952. pgdi->ulNumColors = (ULONG) -1;
  1953. pgdi->ulNumPalReg = 0;
  1954. pgdi->ulHTOutputFormat = HT_FORMAT_16BPP;
  1955. pdi->iDitherFormat = BMF_16BPP;
  1956. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1957. }
  1958. else if (VideoModeInformation.BitsPerPlane == 24)
  1959. {
  1960. ppdev->cBpp = 3;
  1961. ppdev->cBitsPerPixel = 24;
  1962. ppdev->iBitmapFormat = BMF_24BPP;
  1963. ppdev->jModeColor = SET_24BPP_COLOR;
  1964. ppdev->ulWhite = 0xffffff;
  1965. ppdev->flRed = VideoModeInformation.RedMask;
  1966. ppdev->flGreen = VideoModeInformation.GreenMask;
  1967. ppdev->flBlue = VideoModeInformation.BlueMask;
  1968. pgdi->ulNumColors = (ULONG) -1;
  1969. pgdi->ulNumPalReg = 0;
  1970. pgdi->ulHTOutputFormat = HT_FORMAT_24BPP;
  1971. pdi->iDitherFormat = BMF_24BPP;
  1972. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1973. }
  1974. else
  1975. {
  1976. ASSERTDD(VideoModeInformation.BitsPerPlane == 32,
  1977. "This driver supports only 8, 16, 24 and 32bpp");
  1978. ppdev->cBpp = 4;
  1979. ppdev->cBitsPerPixel = 32;
  1980. ppdev->iBitmapFormat = BMF_32BPP;
  1981. ppdev->jModeColor = SET_32BPP_COLOR;
  1982. ppdev->ulWhite = 0xffffffff;
  1983. ppdev->flRed = VideoModeInformation.RedMask;
  1984. ppdev->flGreen = VideoModeInformation.GreenMask;
  1985. ppdev->flBlue = VideoModeInformation.BlueMask;
  1986. pgdi->ulNumColors = (ULONG) -1;
  1987. pgdi->ulNumPalReg = 0;
  1988. pgdi->ulHTOutputFormat = HT_FORMAT_32BPP;
  1989. pdi->iDitherFormat = BMF_32BPP;
  1990. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1991. }
  1992. DISPDBG((5, "Passed bInitializeModeFields"));
  1993. return(TRUE);
  1994. ReturnFalse:
  1995. DISPDBG((0, "Failed bInitializeModeFields"));
  1996. return(FALSE);
  1997. }
  1998. /******************************Public*Routine******************************\
  1999. * DWORD getAvailableModes
  2000. *
  2001. * Calls the miniport to get the list of modes supported by the kernel driver,
  2002. * and returns the list of modes supported by the diplay driver among those
  2003. *
  2004. * returns the number of entries in the videomode buffer.
  2005. * 0 means no modes are supported by the miniport or that an error occured.
  2006. *
  2007. * NOTE: the buffer must be freed up by the caller.
  2008. *
  2009. \**************************************************************************/
  2010. DWORD getAvailableModes(
  2011. HANDLE hDriver,
  2012. PVIDEO_MODE_INFORMATION* modeInformation,
  2013. DWORD* cbModeSize)
  2014. {
  2015. ULONG ulTemp;
  2016. VIDEO_NUM_MODES modes;
  2017. PVIDEO_MODE_INFORMATION pVideoTemp;
  2018. //
  2019. // Get the number of modes supported by the mini-port
  2020. //
  2021. if (!IOCONTROL(hDriver,
  2022. IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
  2023. NULL,
  2024. 0,
  2025. &modes,
  2026. sizeof(VIDEO_NUM_MODES),
  2027. &ulTemp))
  2028. {
  2029. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_NUM_AVAIL_MODES"));
  2030. return(0);
  2031. }
  2032. *cbModeSize = modes.ModeInformationLength;
  2033. //
  2034. // Allocate the buffer for the mini-port to write the modes in.
  2035. //
  2036. *modeInformation = (PVIDEO_MODE_INFORMATION)
  2037. ALLOC(modes.NumModes * modes.ModeInformationLength);
  2038. if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
  2039. {
  2040. DISPDBG((0, "getAvailableModes - Failed EngAllocMem"));
  2041. return 0;
  2042. }
  2043. //
  2044. // Ask the mini-port to fill in the available modes.
  2045. //
  2046. if (!IOCONTROL(hDriver,
  2047. IOCTL_VIDEO_QUERY_AVAIL_MODES,
  2048. NULL,
  2049. 0,
  2050. *modeInformation,
  2051. modes.NumModes * modes.ModeInformationLength,
  2052. &ulTemp))
  2053. {
  2054. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_AVAIL_MODES"));
  2055. FREE(*modeInformation);
  2056. *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
  2057. return(0);
  2058. }
  2059. //
  2060. // Now see which of these modes are supported by the display driver.
  2061. // As an internal mechanism, set the length to 0 for the modes we
  2062. // DO NOT support.
  2063. //
  2064. ulTemp = modes.NumModes;
  2065. pVideoTemp = *modeInformation;
  2066. //
  2067. // Mode is rejected if it is not one plane, or not graphics, or is not
  2068. // one of 8, 15, 16, 24 or 32 bits per pel.
  2069. //
  2070. while (ulTemp--)
  2071. {
  2072. if ((pVideoTemp->NumberOfPlanes != 1 ) ||
  2073. !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
  2074. //ms923 added
  2075. !(pVideoTemp->DriverSpecificAttributeFlags & CAPS_BLT_SUPPORT)||
  2076. ((pVideoTemp->BitsPerPlane != 8) &&
  2077. (pVideoTemp->BitsPerPlane != 15) &&
  2078. (pVideoTemp->BitsPerPlane != 16) &&
  2079. (pVideoTemp->BitsPerPlane != 24) &&
  2080. (pVideoTemp->BitsPerPlane != 32)))
  2081. {
  2082. DISPDBG((2, "Rejecting miniport mode:"));
  2083. pVideoTemp->Length = 0;
  2084. }
  2085. else
  2086. {
  2087. DISPDBG((2, "Accepting miniport mode:"));
  2088. }
  2089. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  2090. (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
  2091. }
  2092. return(modes.NumModes);
  2093. }
  2094. //crus begin
  2095. //myf1, begin
  2096. #ifdef PANNING_SCROLL
  2097. VOID
  2098. CirrusLaptopViewPoint(
  2099. PDEV* ppdev,
  2100. PVIDEO_MODE_INFORMATION pVideoModeInfo)
  2101. {
  2102. UCHAR ChipID;
  2103. UCHAR savSEQidx, Panel_Type, LCD;
  2104. // Panning Scrolling Supported for TI
  2105. //myf16 savSEQidx = CP_IN_BYTE(ppdev->pjPorts, SR_INDEX);
  2106. //myf16 CP_OUT_BYTE(ppdev->pjPorts, SR_INDEX, 0x09);
  2107. //myf16 Panel_Type = (CP_IN_BYTE(ppdev->pjPorts, SR_DATA) & 0x70) >> 4;
  2108. //myf16 CP_OUT_BYTE(ppdev->pjPorts, SR_INDEX, savSEQidx);
  2109. savSEQidx = CP_IN_BYTE(ppdev->pjPorts, CRTC_INDEX);
  2110. CP_OUT_BYTE(ppdev->pjPorts, CRTC_INDEX, 0x27);
  2111. ChipID = (CP_IN_BYTE(ppdev->pjPorts, CRTC_DATA) & 0xFC) >> 2;
  2112. if ((ChipID == 0x0E) || (ChipID == 0x0B) || (ChipID == 0x0C))
  2113. //7548/7543/7541
  2114. {
  2115. CP_OUT_BYTE(ppdev->pjPorts, CRTC_INDEX, 0x20);
  2116. LCD = CP_IN_BYTE(ppdev->pjPorts, CRTC_DATA) & 0x20;
  2117. }
  2118. else if ((ChipID == 0x10) || (ChipID == 0x13)) //myf17
  2119. {
  2120. CP_OUT_BYTE(ppdev->pjPorts, CRTC_INDEX, 0x80);
  2121. LCD = CP_IN_BYTE(ppdev->pjPorts, CRTC_DATA) & 0x01;
  2122. }
  2123. CP_OUT_BYTE(ppdev->pjPorts, CRTC_INDEX, savSEQidx);
  2124. if ((ChipID == 0x0E) || (ChipID == 0x0B) || (ChipID == 0x0C) ||
  2125. (ChipID == 0x10) || (ChipID == 0x13)) //myf17
  2126. {
  2127. if ((LCD) && //myf33
  2128. !(pVideoModeInfo->DriverSpecificAttributeFlags & CAPS_TV_ON) &&
  2129. (pVideoModeInfo->DriverSpecificAttributeFlags & CAPS_SVGA_PANEL))
  2130. {
  2131. ppdev->Hres = 800;
  2132. ppdev->Vres = 600;
  2133. }
  2134. else if ((LCD) && //myf33
  2135. !(pVideoModeInfo->DriverSpecificAttributeFlags & CAPS_TV_ON) &&
  2136. (pVideoModeInfo->DriverSpecificAttributeFlags & CAPS_VGA_PANEL))
  2137. {
  2138. ppdev->Hres = 640;
  2139. ppdev->Vres = 480;
  2140. }
  2141. else if ((LCD) && //myf33
  2142. !(pVideoModeInfo->DriverSpecificAttributeFlags & CAPS_TV_ON) &&
  2143. (pVideoModeInfo->DriverSpecificAttributeFlags & CAPS_XGA_PANEL))
  2144. {
  2145. ppdev->Hres = 1024;
  2146. ppdev->Vres = 768;
  2147. }
  2148. else
  2149. {
  2150. ppdev->Hres = pVideoModeInfo->VisScreenWidth;
  2151. ppdev->Vres = pVideoModeInfo->VisScreenHeight;
  2152. }
  2153. ppdev->min_Xscreen = 0;
  2154. ppdev->max_Xscreen = ppdev->Hres - 1;
  2155. ppdev->min_Yscreen = 0;
  2156. ppdev->max_Yscreen = ppdev->Vres - 1;
  2157. DISPDBG((2,"INIT- PANNING SCROLLING : %x\t:%x, %x, \n %x, %x, %x, %x\n",
  2158. ppdev->ulMode,ppdev->Hres, ppdev->Vres, ppdev->min_Xscreen, ppdev->max_Xscreen,
  2159. ppdev->min_Yscreen, ppdev->max_Yscreen));
  2160. }
  2161. ppdev->flCaps = pVideoModeInfo->DriverSpecificAttributeFlags; //myf33
  2162. }
  2163. #endif
  2164. //myf1, end
  2165. //crus end