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.

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