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.

1734 lines
60 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: enable.c
  3. *
  4. * This module contains the functions that enable and disable the
  5. * driver, the pdev, and the surface.
  6. *
  7. * Copyright (c) 1992-1995 Microsoft Corporation
  8. \**************************************************************************/
  9. #include "precomp.h"
  10. #if defined(ALPHA)
  11. /**************************************************************************\
  12. * BOOL isDense
  13. *
  14. * This global is used to distinguish dense space from sparse space on the
  15. * DEC Alpha in order to use the appropriate method of register access.
  16. *
  17. \**************************************************************************/
  18. BOOL isDense = TRUE;
  19. #endif
  20. /******************************Public*Structure****************************\
  21. * GDIINFO ggdiDefault
  22. *
  23. * This contains the default GDIINFO fields that are passed back to GDI
  24. * during DrvEnablePDEV.
  25. *
  26. * NOTE: This structure defaults to values for an 8bpp palette device.
  27. * Some fields are overwritten for different colour depths.
  28. \**************************************************************************/
  29. GDIINFO ggdiDefault = {
  30. GDI_DRIVER_VERSION, // ulVersion
  31. DT_RASDISPLAY, // ulTechnology
  32. 0, // ulHorzSize (filled in later)
  33. 0, // ulVertSize (filled in later)
  34. 0, // ulHorzRes (filled in later)
  35. 0, // ulVertRes (filled in later)
  36. 0, // cBitsPixel (filled in later)
  37. 0, // cPlanes (filled in later)
  38. 20, // ulNumColors (palette managed)
  39. 0, // flRaster (DDI reserved field)
  40. 0, // ulLogPixelsX (filled in later)
  41. 0, // ulLogPixelsY (filled in later)
  42. TC_RA_ABLE, // flTextCaps -- If we had wanted console windows
  43. // to scroll by repainting the entire window,
  44. // instead of doing a screen-to-screen blt, we
  45. // would have set TC_SCROLLBLT (yes, the flag is
  46. // bass-ackwards).
  47. 0, // ulDACRed (filled in later)
  48. 0, // ulDACGreen (filled in later)
  49. 0, // ulDACBlue (filled in later)
  50. 0x0024, // ulAspectX
  51. 0x0024, // ulAspectY
  52. 0x0033, // ulAspectXY (one-to-one aspect ratio)
  53. 1, // xStyleStep
  54. 1, // yStyleSte;
  55. 3, // denStyleStep -- Styles have a one-to-one aspect
  56. // ratio, and every 'dot' is 3 pixels long
  57. { 0, 0 }, // ptlPhysOffset
  58. { 0, 0 }, // szlPhysSize
  59. 256, // ulNumPalReg
  60. // These fields are for halftone initialization. The actual values are
  61. // a bit magic, but seem to work well on our display.
  62. { // ciDevice
  63. { 6700, 3300, 0 }, // Red
  64. { 2100, 7100, 0 }, // Green
  65. { 1400, 800, 0 }, // Blue
  66. { 1750, 3950, 0 }, // Cyan
  67. { 4050, 2050, 0 }, // Magenta
  68. { 4400, 5200, 0 }, // Yellow
  69. { 3127, 3290, 0 }, // AlignmentWhite
  70. 20000, // RedGamma
  71. 20000, // GreenGamma
  72. 20000, // BlueGamma
  73. 0, 0, 0, 0, 0, 0 // No dye correction for raster displays
  74. },
  75. 0, // ulDevicePelsDPI (for printers only)
  76. PRIMARY_ORDER_CBA, // ulPrimaryOrder
  77. HT_PATSIZE_4x4_M, // ulHTPatternSize
  78. HT_FORMAT_8BPP, // ulHTOutputFormat
  79. HT_FLAG_ADDITIVE_PRIMS, // flHTFlags
  80. 0, // ulVRefresh
  81. 0, // ulPanningHorzRes
  82. 0, // ulPanningVertRes
  83. 0, // ulBltAlignment
  84. };
  85. /******************************Public*Structure****************************\
  86. * DEVINFO gdevinfoDefault
  87. *
  88. * This contains the default DEVINFO fields that are passed back to GDI
  89. * during DrvEnablePDEV.
  90. *
  91. * NOTE: This structure defaults to values for an 8bpp palette device.
  92. * Some fields are overwritten for different colour depths.
  93. \**************************************************************************/
  94. #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  95. CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
  96. VARIABLE_PITCH | FF_DONTCARE,L"System"}
  97. #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  98. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  99. VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
  100. #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  101. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  102. FIXED_PITCH | FF_DONTCARE, L"Courier"}
  103. DEVINFO gdevinfoDefault = {
  104. (GCAPS_OPAQUERECT |
  105. GCAPS_DITHERONREALIZE |
  106. GCAPS_PALMANAGED |
  107. GCAPS_ALTERNATEFILL |
  108. GCAPS_WINDINGFILL |
  109. #if TARGET_BUILD > 351
  110. GCAPS_DIRECTDRAW |
  111. #endif
  112. GCAPS_MONO_DITHER |
  113. GCAPS_COLOR_DITHER |
  114. GCAPS_ASYNCMOVE), // NOTE: Only enable ASYNCMOVE if your code
  115. // and hardware can handle DrvMovePointer
  116. // calls at any time, even while another
  117. // thread is in the middle of a drawing
  118. // call such as DrvBitBlt.
  119. // flGraphicsFlags
  120. SYSTM_LOGFONT, // lfDefaultFont
  121. HELVE_LOGFONT, // lfAnsiVarFont
  122. COURI_LOGFONT, // lfAnsiFixFont
  123. 0, // cFonts
  124. BMF_8BPP, // iDitherFormat
  125. 8, // cxDither
  126. 8, // cyDither
  127. 0 // hpalDefault (filled in later)
  128. };
  129. /******************************Public*Structure****************************\
  130. * DFVFN gadrvfn[]
  131. *
  132. * Build the driver function table gadrvfn with function index/address
  133. * pairs. This table tells GDI which DDI calls we support, and their
  134. * location (GDI does an indirect call through this table to call us).
  135. *
  136. * Why haven't we implemented DrvSaveScreenBits? To save code.
  137. *
  138. * When the driver doesn't hook DrvSaveScreenBits, USER simulates on-
  139. * the-fly by creating a temporary device-format-bitmap, and explicitly
  140. * calling DrvCopyBits to save/restore the bits. Since we already hook
  141. * DrvCreateDeviceBitmap, we'll end up using off-screen memory to store
  142. * the bits anyway (which would have been the main reason for implementing
  143. * DrvSaveScreenBits). So we may as well save some working set.
  144. \**************************************************************************/
  145. #if MULTI_BOARDS
  146. // Multi-board support has its own thunks...
  147. DRVFN gadrvfn[] = {
  148. { INDEX_DrvEnablePDEV, (PFN) MulEnablePDEV },
  149. { INDEX_DrvCompletePDEV, (PFN) MulCompletePDEV },
  150. { INDEX_DrvDisablePDEV, (PFN) MulDisablePDEV },
  151. { INDEX_DrvEnableSurface, (PFN) MulEnableSurface },
  152. { INDEX_DrvDisableSurface, (PFN) MulDisableSurface },
  153. { INDEX_DrvAssertMode, (PFN) MulAssertMode },
  154. { INDEX_DrvMovePointer, (PFN) MulMovePointer },
  155. { INDEX_DrvSetPointerShape, (PFN) MulSetPointerShape },
  156. { INDEX_DrvDitherColor, (PFN) MulDitherColor },
  157. { INDEX_DrvSetPalette, (PFN) MulSetPalette },
  158. { INDEX_DrvCopyBits, (PFN) MulCopyBits },
  159. { INDEX_DrvBitBlt, (PFN) MulBitBlt },
  160. { INDEX_DrvTextOut, (PFN) MulTextOut },
  161. { INDEX_DrvGetModes, (PFN) MulGetModes },
  162. { INDEX_DrvStrokePath, (PFN) MulStrokePath },
  163. { INDEX_DrvFillPath, (PFN) MulFillPath },
  164. { INDEX_DrvPaint, (PFN) MulPaint },
  165. { INDEX_DrvRealizeBrush, (PFN) MulRealizeBrush },
  166. { INDEX_DrvDestroyFont, (PFN) MulDestroyFont },
  167. #if TARGET_BUILD > 351
  168. { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo },
  169. { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw },
  170. { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw },
  171. #endif
  172. { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }
  173. // Note that we don't support DrvCreateDeviceBitmap for multi-boards
  174. // Note that we don't support DrvDeleteDeviceBitmap for multi-boards
  175. // Note that we don't support DrvStretchBlt for multi-boards
  176. // Note that we don't support DrvLineTo for multi-boards
  177. // Note that we don't support DrvEscape for multi-boards
  178. };
  179. #elif DBG
  180. // On Checked builds, thunk everything through Dbg calls...
  181. DRVFN gadrvfn[] = {
  182. { INDEX_DrvEnablePDEV, (PFN) DbgEnablePDEV },
  183. { INDEX_DrvCompletePDEV, (PFN) DbgCompletePDEV },
  184. { INDEX_DrvDisablePDEV, (PFN) DbgDisablePDEV },
  185. { INDEX_DrvEnableSurface, (PFN) DbgEnableSurface },
  186. { INDEX_DrvDisableSurface, (PFN) DbgDisableSurface },
  187. { INDEX_DrvAssertMode, (PFN) DbgAssertMode },
  188. { INDEX_DrvMovePointer, (PFN) DbgMovePointer },
  189. { INDEX_DrvSetPointerShape, (PFN) DbgSetPointerShape },
  190. { INDEX_DrvDitherColor, (PFN) DbgDitherColor },
  191. { INDEX_DrvSetPalette, (PFN) DbgSetPalette },
  192. { INDEX_DrvCopyBits, (PFN) DbgCopyBits },
  193. { INDEX_DrvBitBlt, (PFN) DbgBitBlt },
  194. { INDEX_DrvTextOut, (PFN) DbgTextOut },
  195. { INDEX_DrvGetModes, (PFN) DbgGetModes },
  196. { INDEX_DrvStrokePath, (PFN) DbgStrokePath },
  197. #if TARGET_BUILD > 351
  198. { INDEX_DrvLineTo, (PFN) DbgLineTo },
  199. #endif
  200. { INDEX_DrvFillPath, (PFN) DbgFillPath },
  201. { INDEX_DrvPaint, (PFN) DbgPaint },
  202. { INDEX_DrvStretchBlt, (PFN) DbgStretchBlt },
  203. { INDEX_DrvRealizeBrush, (PFN) DbgRealizeBrush },
  204. { INDEX_DrvCreateDeviceBitmap, (PFN) DbgCreateDeviceBitmap },
  205. { INDEX_DrvDeleteDeviceBitmap, (PFN) DbgDeleteDeviceBitmap },
  206. { INDEX_DrvDestroyFont, (PFN) DbgDestroyFont },
  207. #if TARGET_BUILD > 351
  208. { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo },
  209. { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw },
  210. { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw },
  211. #endif
  212. { INDEX_DrvDisableDriver, (PFN) DbgDisableDriver }
  213. };
  214. #else
  215. // On Free builds, directly call the appropriate functions...
  216. DRVFN gadrvfn[] = {
  217. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  218. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  219. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  220. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  221. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  222. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  223. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  224. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  225. { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
  226. { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
  227. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  228. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  229. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  230. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  231. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  232. #if TARGET_BUILD > 351
  233. { INDEX_DrvLineTo, (PFN) DrvLineTo },
  234. #endif
  235. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  236. { INDEX_DrvPaint, (PFN) DrvPaint },
  237. { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt },
  238. { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush },
  239. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  240. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  241. { INDEX_DrvDestroyFont, (PFN) DrvDestroyFont },
  242. #if TARGET_BUILD > 351
  243. { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo },
  244. { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw },
  245. { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw },
  246. #endif
  247. { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }
  248. };
  249. #endif
  250. ULONG gcdrvfn = sizeof(gadrvfn) / sizeof(DRVFN);
  251. /******************************Public*Routine******************************\
  252. * BOOL DrvEnableDriver
  253. *
  254. * Enables the driver by retrieving the drivers function table and version.
  255. *
  256. \**************************************************************************/
  257. BOOL DrvEnableDriver(
  258. ULONG iEngineVersion,
  259. ULONG cj,
  260. DRVENABLEDATA* pded)
  261. {
  262. // Engine Version is passed down so future drivers can support previous
  263. // engine versions. A next generation driver can support both the old
  264. // and new engine conventions if told what version of engine it is
  265. // working with. For the first version the driver does nothing with it.
  266. // Fill in as much as we can.
  267. if (cj >= sizeof(DRVENABLEDATA))
  268. pded->pdrvfn = gadrvfn;
  269. if (cj >= (sizeof(ULONG) * 2))
  270. pded->c = gcdrvfn;
  271. // DDI version this driver was targeted for is passed back to engine.
  272. // Future graphic's engine may break calls down to old driver format.
  273. if (cj >= sizeof(ULONG))
  274. pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
  275. return(TRUE);
  276. }
  277. /******************************Public*Routine******************************\
  278. * VOID DrvDisableDriver
  279. *
  280. * Tells the driver it is being disabled. Release any resources allocated in
  281. * DrvEnableDriver.
  282. *
  283. \**************************************************************************/
  284. VOID DrvDisableDriver(VOID)
  285. {
  286. return;
  287. }
  288. /******************************Public*Routine******************************\
  289. * BOOL bInitializeATI
  290. *
  291. * Initializes some private ATI info.
  292. *
  293. \**************************************************************************/
  294. BOOL bInitializeATI(PDEV* ppdev)
  295. {
  296. ENH_VERSION_NT info;
  297. ULONG ReturnedDataLength;
  298. info.FeatureFlags = 0;
  299. info.StructureVersion = 0;
  300. info.InterfaceVersion = 0; // Miniport needs these to be zero
  301. // Get some adapter information via a private IOCTL call:
  302. if (!AtiDeviceIoControl(ppdev->hDriver,
  303. IOCTL_VIDEO_ATI_GET_VERSION,
  304. &info,
  305. sizeof(ENH_VERSION_NT),
  306. &info,
  307. sizeof(ENH_VERSION_NT),
  308. &ReturnedDataLength))
  309. {
  310. DISPDBG((0, "bInitializeATI - Failed ATI_GET_VERSION"));
  311. goto ReturnFalse;
  312. }
  313. ppdev->FeatureFlags = info.FeatureFlags;
  314. ppdev->iAsic = info.ChipIndex;
  315. ppdev->iAperture = info.ApertureType;
  316. #if defined(ALPHA)
  317. if (!(ppdev->FeatureFlags & EVN_DENSE_CAPABLE))
  318. {
  319. // Can't use a sparse linear aperture.
  320. // Banked aperture is always sparse.
  321. // In either case, we execute no-aperture code...
  322. ppdev->iAperture = APERTURE_NONE;
  323. isDense = FALSE;
  324. }
  325. #endif
  326. if (info.ChipIndex == ASIC_88800GX)
  327. {
  328. ppdev->iMachType = MACH_MM_64;
  329. }
  330. else if (info.BusFlag & FL_MM_REGS)
  331. {
  332. ppdev->iMachType = MACH_MM_32;
  333. }
  334. else
  335. {
  336. ppdev->iMachType = MACH_IO_32;
  337. }
  338. return(TRUE);
  339. ReturnFalse:
  340. return(FALSE);
  341. }
  342. /******************************Public*Routine******************************\
  343. * DHPDEV DrvEnablePDEV
  344. *
  345. * Initializes a bunch of fields for GDI, based on the mode we've been asked
  346. * to do. This is the first thing called after DrvEnableDriver, when GDI
  347. * wants to get some information about us.
  348. *
  349. * (This function mostly returns back information; DrvEnableSurface is used
  350. * for initializing the hardware and driver components.)
  351. *
  352. \**************************************************************************/
  353. DHPDEV DrvEnablePDEV(
  354. DEVMODEW* pdm, // Contains data pertaining to requested mode
  355. PWSTR pwszLogAddr, // Logical address
  356. ULONG cPat, // Count of standard patterns
  357. HSURF* phsurfPatterns, // Buffer for standard patterns
  358. ULONG cjCaps, // Size of buffer for device caps 'pdevcaps'
  359. ULONG* pdevcaps, // Buffer for device caps, also known as 'gdiinfo'
  360. ULONG cjDevInfo, // Number of bytes in device info 'pdi'
  361. DEVINFO* pdi, // Device information
  362. #if TARGET_BUILD > 351
  363. HDEV hdev, // Used for callbacks
  364. #else
  365. PWSTR pwszDataFile,
  366. #endif
  367. PWSTR pwszDeviceName, // Device name
  368. HANDLE hDriver) // Kernel driver handle
  369. {
  370. PDEV* ppdev;
  371. // Future versions of NT had better supply 'devcaps' and 'devinfo'
  372. // structures that are the same size or larger than the current
  373. // structures:
  374. if ((cjCaps < sizeof(GDIINFO)) || (cjDevInfo < sizeof(DEVINFO)))
  375. {
  376. DISPDBG((0, "DrvEnablePDEV - Buffer size too small"));
  377. goto ReturnFailure0;
  378. }
  379. // Allocate a physical device structure. Note that we definitely
  380. // rely on the zero initialization:
  381. ppdev = AtiAllocMem(LPTR, FL_ZERO_MEMORY, sizeof(PDEV));
  382. if (ppdev == NULL)
  383. {
  384. DISPDBG((0, "DrvEnablePDEV - Failed AtiAllocMem"));
  385. goto ReturnFailure0;
  386. }
  387. ppdev->hDriver = hDriver;
  388. // Do some private ATI-specific initialization:
  389. if (!bInitializeATI(ppdev))
  390. {
  391. DISPDBG((0, "DrvEnablePDEV - Failed bInitializeATI"));
  392. goto ReturnFailure1;
  393. }
  394. // Get the current screen mode information. Set up device caps and
  395. // devinfo:
  396. if (!bInitializeModeFields(ppdev, (GDIINFO*) pdevcaps, pdi, pdm))
  397. {
  398. DISPDBG((0, "DrvEnablePDEV - Failed bInitializeModeFields"));
  399. goto ReturnFailure1;
  400. }
  401. // Initialize palette information.
  402. if (!bInitializePalette(ppdev, pdi))
  403. {
  404. DISPDBG((0, "DrvEnablePDEV - Failed bInitializePalette"));
  405. goto ReturnFailure1;
  406. }
  407. return((DHPDEV) ppdev);
  408. ReturnFailure1:
  409. DrvDisablePDEV((DHPDEV) ppdev);
  410. ReturnFailure0:
  411. DISPDBG((0, "Failed DrvEnablePDEV"));
  412. return(0);
  413. }
  414. /******************************Public*Routine******************************\
  415. * DrvDisablePDEV
  416. *
  417. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  418. * enabled DrvDisableSurface will have already been called.
  419. *
  420. * Note that this function will be called when previewing modes in the
  421. * Display Applet, but not at system shutdown. If you need to reset the
  422. * hardware at shutdown, you can do it in the miniport by providing a
  423. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  424. *
  425. * Note: In an error, we may call this before DrvEnablePDEV is done.
  426. *
  427. \**************************************************************************/
  428. VOID DrvDisablePDEV(
  429. DHPDEV dhpdev)
  430. {
  431. PDEV* ppdev;
  432. ppdev = (PDEV*) dhpdev;
  433. vUninitializePalette(ppdev);
  434. AtiFreeMem(ppdev);
  435. }
  436. /******************************Public*Routine******************************\
  437. * VOID DrvCompletePDEV
  438. *
  439. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  440. *
  441. \**************************************************************************/
  442. VOID DrvCompletePDEV(
  443. DHPDEV dhpdev,
  444. HDEV hdev)
  445. {
  446. ((PDEV*) dhpdev)->hdevEng = hdev;
  447. }
  448. /******************************Public*Routine******************************\
  449. * HSURF DrvEnableSurface
  450. *
  451. * Creates the drawing surface, initializes the hardware, and initializes
  452. * driver components. This function is called after DrvEnablePDEV, and
  453. * performs the final device initialization.
  454. *
  455. \**************************************************************************/
  456. HSURF DrvEnableSurface(
  457. DHPDEV dhpdev)
  458. {
  459. PDEV* ppdev;
  460. HSURF hsurf;
  461. SIZEL sizl;
  462. DSURF* pdsurf;
  463. VOID* pvTmpBuffer;
  464. ppdev = (PDEV*) dhpdev;
  465. /////////////////////////////////////////////////////////////////////
  466. // First enable all the subcomponents.
  467. //
  468. // Note that the order in which these 'Enable' functions are called
  469. // may be significant in low off-screen memory conditions, because
  470. // the off-screen heap manager may fail some of the later
  471. // allocations...
  472. if (!bEnableHardware(ppdev))
  473. goto ReturnFailure;
  474. if (!bEnableBanking(ppdev))
  475. goto ReturnFailure;
  476. if (!bEnableOffscreenHeap(ppdev))
  477. goto ReturnFailure;
  478. if (!bEnablePointer(ppdev))
  479. goto ReturnFailure;
  480. if (!bEnableText(ppdev))
  481. goto ReturnFailure;
  482. if (!bEnableBrushCache(ppdev))
  483. goto ReturnFailure;
  484. if (!bEnablePalette(ppdev))
  485. goto ReturnFailure;
  486. if (!bEnableDirectDraw(ppdev))
  487. goto ReturnFailure;
  488. /////////////////////////////////////////////////////////////////////
  489. // Now create our private surface structure.
  490. //
  491. // Whenever we get a call to draw directly to the screen, we'll get
  492. // passed a pointer to a SURFOBJ whose 'dhpdev' field will point
  493. // to our PDEV structure, and whose 'dhsurf' field will point to the
  494. // following DSURF structure.
  495. //
  496. // Every device bitmap we create in DrvCreateDeviceBitmap will also
  497. // have its own unique DSURF structure allocated (but will share the
  498. // same PDEV). To make our code more polymorphic for handling drawing
  499. // to either the screen or an off-screen bitmap, we have the same
  500. // structure for both.
  501. pdsurf = AtiAllocMem(LPTR, FL_ZERO_MEMORY, sizeof(DSURF));
  502. if (pdsurf == NULL)
  503. {
  504. DISPDBG((0, "DrvEnableSurface - Failed pdsurf AtiAllocMem"));
  505. goto ReturnFailure;
  506. }
  507. ppdev->pdsurfScreen = pdsurf; // Remember it for clean-up
  508. pdsurf->poh = ppdev->pohScreen; // The screen is a surface, too
  509. pdsurf->dt = DT_SCREEN; // Not to be confused with a DIB
  510. pdsurf->sizl.cx = ppdev->cxScreen;
  511. pdsurf->sizl.cy = ppdev->cyScreen;
  512. pdsurf->ppdev = ppdev;
  513. /////////////////////////////////////////////////////////////////////
  514. // Next, have GDI create the actual SURFOBJ.
  515. //
  516. // Our drawing surface is going to be 'device-managed', meaning that
  517. // GDI cannot draw on the framebuffer bits directly, and as such we
  518. // create the surface via EngCreateDeviceSurface. By doing this, we ensure
  519. // that GDI will only ever access the bitmaps bits via the Drv calls
  520. // that we've HOOKed.
  521. //
  522. // If we could map the entire framebuffer linearly into main memory
  523. // (i.e., we didn't have to go through a 64k aperture), it would be
  524. // beneficial to create the surface via EngCreateBitmap, giving GDI a
  525. // pointer to the framebuffer bits. When we pass a call on to GDI
  526. // where it can't directly read/write to the surface bits because the
  527. // surface is device managed, it has to create a temporary bitmap and
  528. // call our DrvCopyBits routine to get/set a copy of the affected bits.
  529. // Fer example, the OpenGL component prefers to be able to write on the
  530. // framebuffer bits directly.
  531. sizl.cx = ppdev->cxScreen;
  532. sizl.cy = ppdev->cyScreen;
  533. // Let GDI manage 24bpp mach32 with linear aperture.
  534. if (ppdev->iBitmapFormat == BMF_24BPP &&
  535. ppdev->iAsic != ASIC_88800GX && ppdev->iAperture == APERTURE_FULL)
  536. {
  537. hsurf= ppdev->hsurfPunt;
  538. //
  539. // Also tell GDI that we don't want to be called back.
  540. //
  541. if (!EngAssociateSurface(hsurf, ppdev->hdevEng, 0))
  542. {
  543. DISPDBG((0, "DrvEnableSurface - Failed EngAssociateSurface"));
  544. goto ReturnFailure;
  545. }
  546. }
  547. else
  548. {
  549. hsurf = EngCreateDeviceSurface((DHSURF) pdsurf, sizl, ppdev->iBitmapFormat);
  550. if (hsurf == 0)
  551. {
  552. DISPDBG((0, "DrvEnableSurface - Failed EngCreateDeviceSurface"));
  553. goto ReturnFailure;
  554. }
  555. ppdev->hsurfScreen = hsurf; // Remember it for clean-up
  556. ppdev->bEnabled = TRUE; // We'll soon be in graphics mode
  557. /////////////////////////////////////////////////////////////////////
  558. // Now associate the surface and the PDEV.
  559. //
  560. // We have to associate the surface we just created with our physical
  561. // device so that GDI can get information related to the PDEV when
  562. // it's drawing to the surface (such as, for example, the length of
  563. // styles on the device when simulating styled lines).
  564. //
  565. if (!EngAssociateSurface(hsurf, ppdev->hdevEng, ppdev->flHooks))
  566. {
  567. DISPDBG((0, "DrvEnableSurface - Failed EngAssociateSurface"));
  568. goto ReturnFailure;
  569. }
  570. }
  571. // Create our generic temporary buffer, which may be used by any
  572. // component.
  573. pvTmpBuffer = AtiAllocMem(LMEM_FIXED, 0, TMP_BUFFER_SIZE);
  574. if (pvTmpBuffer == NULL)
  575. {
  576. DISPDBG((0, "DrvEnableSurface - Failed VirtualAlloc"));
  577. goto ReturnFailure;
  578. }
  579. ppdev->pvTmpBuffer = pvTmpBuffer;
  580. DISPDBG((5, "Passed DrvEnableSurface"));
  581. return(hsurf);
  582. ReturnFailure:
  583. DrvDisableSurface((DHPDEV) ppdev);
  584. DISPDBG((0, "Failed DrvEnableSurface"));
  585. return(0);
  586. }
  587. /******************************Public*Routine******************************\
  588. * VOID DrvDisableSurface
  589. *
  590. * Free resources allocated by DrvEnableSurface. Release the surface.
  591. *
  592. * Note that this function will be called when previewing modes in the
  593. * Display Applet, but not at system shutdown. If you need to reset the
  594. * hardware at shutdown, you can do it in the miniport by providing a
  595. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  596. *
  597. * Note: In an error case, we may call this before DrvEnableSurface is
  598. * completely done.
  599. *
  600. \**************************************************************************/
  601. VOID DrvDisableSurface(
  602. DHPDEV dhpdev)
  603. {
  604. PDEV* ppdev;
  605. ppdev = (PDEV*) dhpdev;
  606. // Note: In an error case, some of the following relies on the
  607. // fact that the PDEV is zero-initialized, so fields like
  608. // 'hsurfScreen' will be zero unless the surface has been
  609. // sucessfully initialized, and makes the assumption that
  610. // EngDeleteSurface can take '0' as a parameter.
  611. vDisableDirectDraw(ppdev);
  612. vDisablePalette(ppdev);
  613. vDisableBrushCache(ppdev);
  614. vDisableText(ppdev);
  615. vDisablePointer(ppdev);
  616. vDisableOffscreenHeap(ppdev);
  617. vDisableBanking(ppdev);
  618. vDisableHardware(ppdev);
  619. AtiFreeMem(ppdev->pvTmpBuffer);
  620. EngDeleteSurface(ppdev->hsurfScreen);
  621. AtiFreeMem(ppdev->pdsurfScreen);
  622. }
  623. /******************************Public*Routine******************************\
  624. * VOID DrvAssertMode
  625. *
  626. * This asks the device to reset itself to the mode of the pdev passed in.
  627. *
  628. \**************************************************************************/
  629. #if TARGET_BUILD > 351
  630. BOOL DrvAssertMode(
  631. #else
  632. VOID DrvAssertMode(
  633. #endif
  634. DHPDEV dhpdev,
  635. BOOL bEnable)
  636. {
  637. PDEV* ppdev;
  638. ppdev = (PDEV*) dhpdev;
  639. if (!bEnable)
  640. {
  641. //////////////////////////////////////////////////////////////
  642. // Disable - Switch to full-screen mode
  643. vAssertModeDirectDraw(ppdev, FALSE);
  644. vAssertModePalette(ppdev, FALSE);
  645. vAssertModeBrushCache(ppdev, FALSE);
  646. vAssertModeText(ppdev, FALSE);
  647. vAssertModePointer(ppdev, FALSE);
  648. if (bAssertModeOffscreenHeap(ppdev, FALSE))
  649. {
  650. vAssertModeBanking(ppdev, FALSE);
  651. if (bAssertModeHardware(ppdev, FALSE))
  652. {
  653. ppdev->bEnabled = FALSE;
  654. #if TARGET_BUILD > 351
  655. return(TRUE);
  656. #else
  657. return;
  658. #endif
  659. }
  660. //////////////////////////////////////////////////////////
  661. // We failed to switch to full-screen. So undo everything:
  662. vAssertModeBanking(ppdev, TRUE);
  663. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  664. } // return code with TRUE
  665. vAssertModePointer(ppdev, TRUE);
  666. vAssertModeText(ppdev, TRUE);
  667. vAssertModeBrushCache(ppdev, TRUE);
  668. vAssertModePalette(ppdev, TRUE);
  669. vAssertModeDirectDraw(ppdev, TRUE);
  670. }
  671. else
  672. {
  673. //////////////////////////////////////////////////////////////
  674. // Enable - Switch back to graphics mode
  675. // We have to enable every subcomponent in the reverse order
  676. // in which it was disabled:
  677. #if TARGET_BUILD > 351
  678. if (!bAssertModeHardware(ppdev, TRUE))
  679. {
  680. return FALSE;
  681. }
  682. #else
  683. bAssertModeHardware(ppdev, TRUE);
  684. #endif
  685. vAssertModeBanking(ppdev, TRUE);
  686. bAssertModeOffscreenHeap(ppdev, TRUE); // don't need the return
  687. vAssertModePointer(ppdev, TRUE);
  688. vAssertModeText(ppdev, TRUE);
  689. vAssertModeBrushCache(ppdev, TRUE);
  690. vAssertModePalette(ppdev, TRUE);
  691. vAssertModeDirectDraw(ppdev, TRUE);
  692. ppdev->bEnabled = TRUE;
  693. #if TARGET_BUILD > 351
  694. return TRUE;
  695. #endif
  696. }
  697. #if TARGET_BUILD > 351
  698. return FALSE; // If we get here, we've failed!
  699. #endif
  700. }
  701. /******************************Public*Routine******************************\
  702. * ULONG DrvGetModes
  703. *
  704. * Returns the list of available modes for the device.
  705. *
  706. \**************************************************************************/
  707. ULONG DrvGetModes(
  708. HANDLE hDriver,
  709. ULONG cjSize,
  710. DEVMODEW* pdm)
  711. {
  712. DWORD cModes;
  713. DWORD cbOutputSize;
  714. PVIDEO_MODE_INFORMATION pVideoModeInformation;
  715. PVIDEO_MODE_INFORMATION pVideoTemp;
  716. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  717. DWORD cbModeSize;
  718. cModes = getAvailableModes(hDriver,
  719. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  720. &cbModeSize);
  721. if (cModes == 0)
  722. {
  723. DISPDBG((0, "DrvGetModes failed to get mode information"));
  724. return(0);
  725. }
  726. if (pdm == NULL)
  727. {
  728. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  729. }
  730. else
  731. {
  732. //
  733. // Now copy the information for the supported modes back into the
  734. // output buffer
  735. //
  736. cbOutputSize = 0;
  737. pVideoTemp = pVideoModeInformation;
  738. do
  739. {
  740. if (pVideoTemp->Length != 0)
  741. {
  742. if (cOutputModes == 0)
  743. {
  744. break;
  745. }
  746. //
  747. // Zero the entire structure to start off with.
  748. //
  749. memset(pdm, 0, sizeof(DEVMODEW));
  750. //
  751. // Set the name of the device to the name of the DLL.
  752. //
  753. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  754. pdm->dmSpecVersion = DM_SPECVERSION;
  755. pdm->dmDriverVersion = DM_SPECVERSION;
  756. //
  757. // We currently do not support Extra information in the driver
  758. //
  759. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  760. pdm->dmSize = sizeof(DEVMODEW);
  761. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  762. pVideoTemp->BitsPerPlane;
  763. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  764. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  765. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  766. #if TARGET_BUILD > 351
  767. pdm->dmDisplayFlags = 0;
  768. pdm->dmFields = DM_BITSPERPEL |
  769. DM_PELSWIDTH |
  770. DM_PELSHEIGHT |
  771. DM_DISPLAYFREQUENCY |
  772. DM_DISPLAYFLAGS ;
  773. #else
  774. if (pVideoTemp->AttributeFlags & VIDEO_MODE_INTERLACED)
  775. {
  776. pdm->dmDisplayFlags |= DM_INTERLACED;
  777. }
  778. #endif
  779. //DISPDBG((0, "pdm: %4li bpp, %4li x %4li, %4li Hz",
  780. //pdm->dmBitsPerPel, pdm->dmPelsWidth, pdm->dmPelsHeight, pdm->dmDisplayFrequency ));
  781. //
  782. // Go to the next DEVMODE entry in the buffer.
  783. //
  784. cOutputModes--;
  785. pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW) +
  786. DRIVER_EXTRA_SIZE);
  787. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  788. }
  789. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  790. (((PUCHAR)pVideoTemp) + cbModeSize);
  791. } while (--cModes);
  792. }
  793. AtiFreeMem(pVideoModeInformation);
  794. return(cbOutputSize);
  795. }
  796. /******************************Public*Routine******************************\
  797. * BOOL bAssertModeHardware
  798. *
  799. * Sets the appropriate hardware state for graphics mode or full-screen.
  800. *
  801. \**************************************************************************/
  802. BOOL bAssertModeHardware(
  803. PDEV* ppdev,
  804. BOOL bEnable)
  805. {
  806. DWORD ReturnedDataLength;
  807. ULONG ulReturn;
  808. if (bEnable)
  809. {
  810. // Call the miniport via an IOCTL to set the graphics mode.
  811. if (!AtiDeviceIoControl(ppdev->hDriver,
  812. IOCTL_VIDEO_SET_CURRENT_MODE,
  813. &ppdev->ulMode, // input buffer
  814. sizeof(DWORD),
  815. NULL,
  816. 0,
  817. &ReturnedDataLength))
  818. {
  819. DISPDBG((0, "bAssertModeHardware - Failed set IOCTL"));
  820. return(FALSE);
  821. }
  822. vResetClipping(ppdev);
  823. // Set some Mach64 defaults:
  824. if (ppdev->iMachType == MACH_MM_64)
  825. {
  826. BYTE* pjMmBase;
  827. pjMmBase = ppdev->pjMmBase;
  828. M64_CHECK_FIFO_SPACE(ppdev, pjMmBase, 1);
  829. M64_OD(pjMmBase, DP_PIX_WIDTH, ppdev->ulMonoPixelWidth);
  830. vSetDefaultContext(ppdev);
  831. }
  832. }
  833. else
  834. {
  835. // Call the kernel driver to reset the device to a known state.
  836. // NTVDM will take things from there:
  837. if (!AtiDeviceIoControl(ppdev->hDriver,
  838. IOCTL_VIDEO_RESET_DEVICE,
  839. NULL,
  840. 0,
  841. NULL,
  842. 0,
  843. &ulReturn))
  844. {
  845. DISPDBG((0, "bAssertModeHardware - Failed reset IOCTL"));
  846. return(FALSE);
  847. }
  848. }
  849. DISPDBG((5, "Passed bAssertModeHardware"));
  850. return(TRUE);
  851. }
  852. /******************************Public*Routine******************************\
  853. * BOOL bEnableHardware
  854. *
  855. * Puts the hardware in the requested mode and initializes it.
  856. *
  857. * Note: Should be called before any access is done to the hardware from
  858. * the display driver.
  859. *
  860. \**************************************************************************/
  861. BOOL bEnableHardware(
  862. PDEV* ppdev)
  863. {
  864. BYTE* pjIoBase;
  865. VIDEO_PUBLIC_ACCESS_RANGES VideoAccessRange[2];
  866. VIDEO_MEMORY VideoMemory;
  867. VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
  868. DWORD ReturnedDataLength;
  869. ppdev->pjIoBase = NULL;
  870. ppdev->pjMmBase = NULL;
  871. // Map io ports into virtual memory:
  872. if (!AtiDeviceIoControl(ppdev->hDriver,
  873. IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES,
  874. NULL, // input buffer
  875. 0,
  876. VideoAccessRange, // output buffer
  877. sizeof(VideoAccessRange),
  878. &ReturnedDataLength))
  879. {
  880. DISPDBG((0, "bEnableHardware - Initialization error mapping IO port base"));
  881. goto ReturnFalse;
  882. }
  883. ppdev->pjIoBase = (UCHAR*) VideoAccessRange[0].VirtualAddress;
  884. ppdev->pjMmBase_Ext = (BYTE*) VideoAccessRange[1].VirtualAddress;
  885. // ------------------------- ATI-specific ----------------------------
  886. // Call the miniport via an IOCTL to set the graphics mode.
  887. // Because of a hardware quirk, 4 BPP causes the mach64 to alter its
  888. // video memory size when you do a SET_CURRENT_MODE, so we do it here
  889. // first so that MAP_VIDEO_MEMORY maps the correct amount of memory.
  890. if (!AtiDeviceIoControl(ppdev->hDriver,
  891. IOCTL_VIDEO_SET_CURRENT_MODE,
  892. &ppdev->ulMode, // input buffer
  893. sizeof(DWORD),
  894. NULL,
  895. 0,
  896. &ReturnedDataLength))
  897. {
  898. DISPDBG((0, "bEnableHardware - Failed set IOCTL"));
  899. goto ReturnFalse;
  900. }
  901. ppdev->pModeInfo = AtiAllocMem( LPTR, FL_ZERO_MEMORY, sizeof (ATI_MODE_INFO) );
  902. if( ppdev->pModeInfo == NULL )
  903. {
  904. DISPDBG((0, "bEnableHardware - Failed memory allocation" ));
  905. goto ReturnFalse;
  906. }
  907. if( !AtiDeviceIoControl( ppdev->hDriver,
  908. IOCTL_VIDEO_ATI_GET_MODE_INFORMATION,
  909. ppdev->pModeInfo,
  910. sizeof (ATI_MODE_INFO),
  911. ppdev->pModeInfo,
  912. sizeof (ATI_MODE_INFO),
  913. &ReturnedDataLength
  914. ) )
  915. {
  916. DISPDBG((0, "bEnableHardware - Failed to get ATI-specific mode information" ));
  917. goto ReturnFalse;
  918. }
  919. // Get the linear memory address range.
  920. VideoMemory.RequestedVirtualAddress = NULL;
  921. if (!AtiDeviceIoControl(ppdev->hDriver,
  922. IOCTL_VIDEO_MAP_VIDEO_MEMORY,
  923. &VideoMemory, // input buffer
  924. sizeof(VIDEO_MEMORY),
  925. &VideoMemoryInfo, // output buffer
  926. sizeof(VideoMemoryInfo),
  927. &ReturnedDataLength))
  928. {
  929. DISPDBG((0, "bEnableHardware - Error mapping buffer address"));
  930. goto ReturnFalse;
  931. }
  932. // Record the Frame Buffer Linear Address.
  933. ppdev->cjBank = VideoMemoryInfo.FrameBufferLength;
  934. // 128K VGA Aperture?
  935. if (ppdev->cjBank == 0x20000)
  936. {
  937. ppdev->cjBank = 0x10000; // true banksize is 64K
  938. }
  939. ppdev->pjScreen = (BYTE*) VideoMemoryInfo.FrameBufferBase;
  940. // So we can free it later in vDisableHardware...
  941. ppdev->VideoRamBase = (BYTE*) VideoMemoryInfo.VideoRamBase;
  942. if (ppdev->iMachType == MACH_MM_64)
  943. {
  944. ppdev->pjMmBase = (BYTE*) VideoMemoryInfo.VideoRamBase
  945. + VideoMemoryInfo.FrameBufferLength
  946. - 0x400;
  947. }
  948. else
  949. {
  950. ppdev->pjMmBase = (BYTE*) VideoMemoryInfo.FrameBufferBase;
  951. }
  952. pjIoBase = ppdev->pjIoBase;
  953. // We finally have enough information to calculate the dimensions
  954. // of on-screen and off-screen memory:
  955. ppdev->cxMemory = ppdev->lDelta / ppdev->cjPelSize;
  956. ppdev->cyMemory = VideoMemoryInfo.VideoRamLength / ppdev->lDelta;
  957. if (VideoMemoryInfo.VideoRamLength <= VideoMemoryInfo.FrameBufferLength)
  958. {
  959. ppdev->flCaps |= CAPS_LINEAR_FRAMEBUFFER;
  960. }
  961. ppdev->ulTearOffset = (ULONG)(ppdev->pjScreen - ppdev->VideoRamBase);
  962. ppdev->ulVramOffset = ppdev->ulTearOffset/8;
  963. if (ppdev->iBitmapFormat != BMF_24BPP)
  964. ppdev->ulScreenOffsetAndPitch = PACKPAIR(ppdev->ulVramOffset,
  965. ppdev->cxMemory * 8);
  966. else
  967. ppdev->ulScreenOffsetAndPitch = PACKPAIR(ppdev->ulVramOffset,
  968. (ppdev->cxMemory * 3) * 8);
  969. // The default pixel width is setup to have monochrome as the
  970. // host data path pixel width:
  971. switch (ppdev->iBitmapFormat)
  972. {
  973. case BMF_4BPP: ppdev->ulMonoPixelWidth = 0x00000101; break;
  974. case BMF_8BPP: ppdev->ulMonoPixelWidth = 0x00000202; break;
  975. case BMF_16BPP: ppdev->ulMonoPixelWidth = 0x00000404; break;
  976. case BMF_24BPP: ppdev->ulMonoPixelWidth = 0x01000202; break;
  977. case BMF_32BPP: ppdev->ulMonoPixelWidth = 0x00000606; break;
  978. }
  979. DISPDBG((1, "RamLength = %lxH, lDelta = %li",
  980. VideoMemoryInfo.VideoRamLength,
  981. ppdev->lDelta));
  982. if ((ppdev->iMachType == MACH_IO_32) || (ppdev->iMachType == MACH_MM_32))
  983. {
  984. // The Mach32 and Mach8 can't handle coordinates larger than 1535:
  985. ppdev->cyMemory = min(ppdev->cyMemory, 1535);
  986. }
  987. if (ppdev->iMachType == MACH_MM_32)
  988. {
  989. // Can do memory-mapped IO:
  990. ppdev->pfnFillSolid = vM32FillSolid;
  991. ppdev->pfnFillPatColor = vM32FillPatColor;
  992. ppdev->pfnFillPatMonochrome = vM32FillPatMonochrome;
  993. ppdev->pfnXfer1bpp = vM32Xfer1bpp;
  994. ppdev->pfnXfer4bpp = vM32Xfer4bpp;
  995. ppdev->pfnXfer8bpp = vM32Xfer8bpp;
  996. ppdev->pfnXferNative = vM32XferNative;
  997. ppdev->pfnCopyBlt = vM32CopyBlt;
  998. ppdev->pfnLineToTrivial = vM32LineToTrivial;
  999. if (ppdev->iAsic == ASIC_68800AX) // Timing problem.
  1000. ppdev->pfnTextOut = bI32TextOut;
  1001. else
  1002. ppdev->pfnTextOut = bM32TextOut;
  1003. ppdev->pfnStretchDIB = bM32StretchDIB;
  1004. }
  1005. else if (ppdev->iMachType == MACH_IO_32)
  1006. {
  1007. ppdev->pfnFillSolid = vI32FillSolid;
  1008. ppdev->pfnFillPatColor = vI32FillPatColor;
  1009. ppdev->pfnFillPatMonochrome = vI32FillPatMonochrome;
  1010. ppdev->pfnXfer1bpp = vI32Xfer1bpp;
  1011. ppdev->pfnXfer4bpp = vI32Xfer4bpp;
  1012. ppdev->pfnXfer8bpp = vI32Xfer8bpp;
  1013. ppdev->pfnXferNative = vI32XferNative;
  1014. ppdev->pfnCopyBlt = vI32CopyBlt;
  1015. ppdev->pfnLineToTrivial = vI32LineToTrivial;
  1016. ppdev->pfnTextOut = bI32TextOut;
  1017. ppdev->pfnStretchDIB = bI32StretchDIB;
  1018. }
  1019. else
  1020. {
  1021. // ppdev->iMachType == MACH_MM_64
  1022. ppdev->pfnFillSolid = vM64FillSolid;
  1023. ppdev->pfnFillPatColor = vM64FillPatColor;
  1024. ppdev->pfnFillPatMonochrome = vM64FillPatMonochrome;
  1025. ppdev->pfnXfer1bpp = vM64Xfer1bpp;
  1026. ppdev->pfnXfer4bpp = vM64Xfer4bpp;
  1027. ppdev->pfnXfer8bpp = vM64Xfer8bpp;
  1028. ppdev->pfnXferNative = vM64XferNative;
  1029. if (!(ppdev->FeatureFlags & EVN_SDRAM_1M))
  1030. {
  1031. ppdev->pfnCopyBlt = vM64CopyBlt;
  1032. }
  1033. else
  1034. {
  1035. // Special version to fix screen source FIFO bug in VT-A4
  1036. // with 1 MB of SDRAM.
  1037. ppdev->pfnCopyBlt = vM64CopyBlt_VTA4;
  1038. }
  1039. ppdev->pfnLineToTrivial = vM64LineToTrivial;
  1040. ppdev->pfnTextOut = bM64TextOut;
  1041. ppdev->pfnStretchDIB = bM64StretchDIB;
  1042. if (ppdev->iBitmapFormat == BMF_24BPP)
  1043. {
  1044. ppdev->pfnFillSolid = vM64FillSolid24;
  1045. ppdev->pfnFillPatColor = vM64FillPatColor24;
  1046. ppdev->pfnFillPatMonochrome = vM64FillPatMonochrome24;
  1047. ppdev->pfnXferNative = vM64XferNative24;
  1048. if (!(ppdev->FeatureFlags & EVN_SDRAM_1M))
  1049. {
  1050. ppdev->pfnCopyBlt = vM64CopyBlt24;
  1051. }
  1052. else
  1053. {
  1054. // Special version to fix screen source FIFO bug in VT-A4
  1055. // with 1 MB of SDRAM.
  1056. ppdev->pfnCopyBlt = vM64CopyBlt24_VTA4;
  1057. }
  1058. ppdev->pfnLineToTrivial = vM64LineToTrivial24;
  1059. ppdev->pfnTextOut = bM64TextOut24;
  1060. }
  1061. vEnableContexts(ppdev);
  1062. }
  1063. if ((ppdev->iAsic != ASIC_38800_1) &&
  1064. ((ppdev->iAperture != APERTURE_NONE)||(ppdev->iMachType == MACH_MM_64)))
  1065. {
  1066. ppdev->pfnGetBits = vGetBits;
  1067. ppdev->pfnPutBits = vPutBits;
  1068. }
  1069. else
  1070. {
  1071. ppdev->pfnGetBits = vI32GetBits;
  1072. ppdev->pfnPutBits = vI32PutBits;
  1073. }
  1074. // Now we can set the mode, unlock the accelerator, and reset the
  1075. // clipping:
  1076. if (!bAssertModeHardware(ppdev, TRUE))
  1077. goto ReturnFalse;
  1078. DISPDBG((0, "%li bpp, %li x %li, pjScreen = %lx, cjBank = %lxH, pjMmBase = %lx",
  1079. ppdev->cBitsPerPel, ppdev->cxMemory, ppdev->cyMemory, ppdev->pjScreen, ppdev->cjBank, ppdev->pjMmBase));
  1080. DISPDBG((5, "Passed bEnableHardware"));
  1081. return(TRUE);
  1082. ReturnFalse:
  1083. DISPDBG((0, "Failed bEnableHardware"));
  1084. return(FALSE);
  1085. }
  1086. /******************************Public*Routine******************************\
  1087. * VOID vDisableHardware
  1088. *
  1089. * Undoes anything done in bEnableHardware.
  1090. *
  1091. * Note: In an error case, we may call this before bEnableHardware is
  1092. * completely done.
  1093. *
  1094. \**************************************************************************/
  1095. VOID vDisableHardware(
  1096. PDEV* ppdev)
  1097. {
  1098. DWORD ReturnedDataLength;
  1099. VIDEO_MEMORY VideoMemory[2];
  1100. VideoMemory[0].RequestedVirtualAddress = ppdev->VideoRamBase;
  1101. if (!AtiDeviceIoControl(ppdev->hDriver,
  1102. IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
  1103. VideoMemory,
  1104. sizeof(VIDEO_MEMORY),
  1105. NULL,
  1106. 0,
  1107. &ReturnedDataLength))
  1108. {
  1109. DISPDBG((0, "vDisableHardware failed IOCTL_VIDEO_UNMAP_VIDEO"));
  1110. }
  1111. VideoMemory[0].RequestedVirtualAddress = ppdev->pjIoBase;
  1112. VideoMemory[1].RequestedVirtualAddress = ppdev->VideoRamBase;
  1113. if (!AtiDeviceIoControl(ppdev->hDriver,
  1114. IOCTL_VIDEO_FREE_PUBLIC_ACCESS_RANGES,
  1115. VideoMemory,
  1116. sizeof(VideoMemory),
  1117. NULL,
  1118. 0,
  1119. &ReturnedDataLength))
  1120. {
  1121. DISPDBG((0, "vDisableHardware failed IOCTL_VIDEO_FREE_PUBLIC_ACCESS"));
  1122. }
  1123. }
  1124. /******************************Public*Routine******************************\
  1125. * BOOL bInitializeModeFields
  1126. *
  1127. * Initializes a bunch of fields in the pdev, devcaps (aka gdiinfo), and
  1128. * devinfo based on the requested mode.
  1129. *
  1130. \**************************************************************************/
  1131. BOOL bInitializeModeFields(
  1132. PDEV* ppdev,
  1133. GDIINFO* pgdi,
  1134. DEVINFO* pdi,
  1135. DEVMODEW* pdm)
  1136. {
  1137. ULONG cModes;
  1138. PVIDEO_MODE_INFORMATION pVideoBuffer;
  1139. PVIDEO_MODE_INFORMATION pVideoModeSelected;
  1140. PVIDEO_MODE_INFORMATION pVideoTemp;
  1141. BOOL bSelectDefault;
  1142. VIDEO_MODE_INFORMATION VideoModeInformation;
  1143. ULONG cbModeSize;
  1144. // Call the miniport to get mode information
  1145. cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
  1146. if (cModes == 0)
  1147. goto ReturnFalse;
  1148. // Now see if the requested mode has a match in that table.
  1149. pVideoModeSelected = NULL;
  1150. pVideoTemp = pVideoBuffer;
  1151. if ((pdm->dmPelsWidth == 0) &&
  1152. (pdm->dmPelsHeight == 0) &&
  1153. (pdm->dmBitsPerPel == 0) &&
  1154. (pdm->dmDisplayFrequency == 0))
  1155. {
  1156. DISPDBG((1, "Default mode requested"));
  1157. bSelectDefault = TRUE;
  1158. }
  1159. else
  1160. {
  1161. DISPDBG((1, "Requested mode..."));
  1162. DISPDBG((1, " Screen width -- %li", pdm->dmPelsWidth));
  1163. DISPDBG((1, " Screen height -- %li", pdm->dmPelsHeight));
  1164. DISPDBG((1, " Bits per pel -- %li", pdm->dmBitsPerPel));
  1165. DISPDBG((1, " Frequency -- %li", pdm->dmDisplayFrequency));
  1166. bSelectDefault = FALSE;
  1167. }
  1168. while (cModes--)
  1169. {
  1170. if (pVideoTemp->Length != 0)
  1171. {
  1172. DISPDBG((8, " Checking against miniport mode:"));
  1173. DISPDBG((8, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  1174. DISPDBG((8, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  1175. DISPDBG((8, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  1176. pVideoTemp->NumberOfPlanes));
  1177. DISPDBG((8, " Frequency -- %li", pVideoTemp->Frequency));
  1178. if (bSelectDefault ||
  1179. ((pVideoTemp->VisScreenWidth == pdm->dmPelsWidth) &&
  1180. (pVideoTemp->VisScreenHeight == pdm->dmPelsHeight) &&
  1181. (pVideoTemp->BitsPerPlane *
  1182. pVideoTemp->NumberOfPlanes == pdm->dmBitsPerPel) &&
  1183. (pVideoTemp->Frequency == pdm->dmDisplayFrequency)))
  1184. {
  1185. pVideoModeSelected = pVideoTemp;
  1186. DISPDBG((1, "...Found a mode match!"));
  1187. break;
  1188. }
  1189. }
  1190. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1191. (((PUCHAR)pVideoTemp) + cbModeSize);
  1192. }
  1193. // If no mode has been found, return an error
  1194. if (pVideoModeSelected == NULL)
  1195. {
  1196. DISPDBG((1, "...Couldn't find a mode match!"));
  1197. AtiFreeMem(pVideoBuffer);
  1198. goto ReturnFalse;
  1199. }
  1200. // Punt all rev 3 VLB cards in 8bpp to the 8514/A driver.
  1201. // Timing problems on "MIO" cards are impossible to deal with.
  1202. // They only show up on 5% of all mach32 cards.
  1203. if ((ppdev->FeatureFlags & EVN_MIO_BUG) && pVideoModeSelected->BitsPerPlane == 8)
  1204. {
  1205. AtiFreeMem(pVideoBuffer);
  1206. goto ReturnFalse;
  1207. }
  1208. // We won't support 24bpp without a linear frame buffer.
  1209. if (pVideoModeSelected->BitsPerPlane == 24 && ppdev->iAperture != APERTURE_FULL)
  1210. {
  1211. AtiFreeMem(pVideoBuffer);
  1212. goto ReturnFalse;
  1213. }
  1214. // We have chosen the one we want. Save it in a stack buffer and
  1215. // get rid of allocated memory before we forget to free it.
  1216. VideoModeInformation = *pVideoModeSelected;
  1217. AtiFreeMem(pVideoBuffer);
  1218. #if DEBUG_HEAP
  1219. VideoModeInformation.VisScreenWidth = 640;
  1220. VideoModeInformation.VisScreenHeight = 480;
  1221. #endif
  1222. // Set up screen information from the mini-port:
  1223. ppdev->ulMode = VideoModeInformation.ModeIndex;
  1224. ppdev->cxScreen = VideoModeInformation.VisScreenWidth;
  1225. ppdev->cyScreen = VideoModeInformation.VisScreenHeight;
  1226. ppdev->lDelta = VideoModeInformation.ScreenStride;
  1227. ppdev->cBitsPerPel = VideoModeInformation.BitsPerPlane;
  1228. DISPDBG((1, "ScreenStride: %lx", VideoModeInformation.ScreenStride));
  1229. ppdev->flHooks = (HOOK_BITBLT |
  1230. HOOK_TEXTOUT |
  1231. HOOK_FILLPATH |
  1232. HOOK_COPYBITS |
  1233. HOOK_STROKEPATH |
  1234. HOOK_STRETCHBLT |
  1235. #if TARGET_BUILD > 351
  1236. HOOK_LINETO |
  1237. #endif
  1238. HOOK_PAINT);
  1239. // Fill in the GDIINFO data structure with the default 8bpp values:
  1240. *pgdi = ggdiDefault;
  1241. // Now overwrite the defaults with the relevant information returned
  1242. // from the kernel driver:
  1243. pgdi->ulHorzSize = VideoModeInformation.XMillimeter;
  1244. pgdi->ulVertSize = VideoModeInformation.YMillimeter;
  1245. pgdi->ulHorzRes = VideoModeInformation.VisScreenWidth;
  1246. pgdi->ulVertRes = VideoModeInformation.VisScreenHeight;
  1247. #if TARGET_BUILD > 351
  1248. pgdi->ulPanningHorzRes = VideoModeInformation.VisScreenWidth;
  1249. pgdi->ulPanningVertRes = VideoModeInformation.VisScreenHeight;
  1250. #else
  1251. pgdi->ulDesktopHorzRes = VideoModeInformation.VisScreenWidth;
  1252. pgdi->ulDesktopVertRes = VideoModeInformation.VisScreenHeight;
  1253. #endif
  1254. pgdi->cBitsPixel = VideoModeInformation.BitsPerPlane;
  1255. pgdi->cPlanes = VideoModeInformation.NumberOfPlanes;
  1256. pgdi->ulVRefresh = VideoModeInformation.Frequency;
  1257. pgdi->ulDACRed = VideoModeInformation.NumberRedBits;
  1258. pgdi->ulDACGreen = VideoModeInformation.NumberGreenBits;
  1259. pgdi->ulDACBlue = VideoModeInformation.NumberBlueBits;
  1260. pgdi->ulLogPixelsX = pdm->dmLogPixels;
  1261. pgdi->ulLogPixelsY = pdm->dmLogPixels;
  1262. // Fill in the devinfo structure with the default 8bpp values:
  1263. *pdi = gdevinfoDefault;
  1264. if (VideoModeInformation.BitsPerPlane == 8)
  1265. {
  1266. ppdev->cPelSize = 0;
  1267. ppdev->cjPelSize = 1;
  1268. ppdev->iBitmapFormat = BMF_8BPP;
  1269. ppdev->ulWhite = 0xff;
  1270. // Assuming palette is orthogonal - all colors are same size.
  1271. ppdev->cPaletteShift = 8 - pgdi->ulDACRed;
  1272. DISPDBG((3, "palette shift = %d\n", ppdev->cPaletteShift));
  1273. }
  1274. else if ((VideoModeInformation.BitsPerPlane == 16) ||
  1275. (VideoModeInformation.BitsPerPlane == 15))
  1276. {
  1277. ppdev->cPelSize = 1;
  1278. ppdev->cjPelSize = 2;
  1279. ppdev->iBitmapFormat = BMF_16BPP;
  1280. ppdev->ulWhite = 0xffff;
  1281. ppdev->flRed = VideoModeInformation.RedMask;
  1282. ppdev->flGreen = VideoModeInformation.GreenMask;
  1283. ppdev->flBlue = VideoModeInformation.BlueMask;
  1284. pgdi->ulNumColors = (ULONG) -1;
  1285. pgdi->ulNumPalReg = 0;
  1286. pgdi->ulHTOutputFormat = HT_FORMAT_16BPP;
  1287. pdi->iDitherFormat = BMF_16BPP;
  1288. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1289. }
  1290. else if (VideoModeInformation.BitsPerPlane == 24)
  1291. {
  1292. ppdev->cPelSize = 0; // not used?!
  1293. ppdev->cjPelSize = 3;
  1294. ppdev->iBitmapFormat = BMF_24BPP;
  1295. ppdev->ulWhite = 0xffffff;
  1296. ppdev->flRed = VideoModeInformation.RedMask;
  1297. ppdev->flGreen = VideoModeInformation.GreenMask;
  1298. ppdev->flBlue = VideoModeInformation.BlueMask;
  1299. pgdi->ulNumColors = (ULONG) -1;
  1300. pgdi->ulNumPalReg = 0;
  1301. pgdi->ulHTOutputFormat = HT_FORMAT_24BPP;
  1302. pdi->iDitherFormat = BMF_24BPP;
  1303. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1304. }
  1305. else
  1306. {
  1307. ASSERTDD(VideoModeInformation.BitsPerPlane == 32,
  1308. "This driver supports only 8, 16, 24 and 32bpp");
  1309. ppdev->cPelSize = 2;
  1310. ppdev->cjPelSize = 4;
  1311. ppdev->iBitmapFormat = BMF_32BPP;
  1312. ppdev->ulWhite = 0xffffffff;
  1313. ppdev->flRed = VideoModeInformation.RedMask;
  1314. ppdev->flGreen = VideoModeInformation.GreenMask;
  1315. ppdev->flBlue = VideoModeInformation.BlueMask;
  1316. pgdi->ulNumColors = (ULONG) -1;
  1317. pgdi->ulNumPalReg = 0;
  1318. pgdi->ulHTOutputFormat = HT_FORMAT_32BPP;
  1319. pdi->iDitherFormat = BMF_32BPP;
  1320. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1321. }
  1322. DISPDBG((5, "Passed bInitializeModeFields"));
  1323. return(TRUE);
  1324. ReturnFalse:
  1325. DISPDBG((0, "Failed bInitializeModeFields"));
  1326. return(FALSE);
  1327. }
  1328. /******************************Public*Routine******************************\
  1329. * DWORD getAvailableModes
  1330. *
  1331. * Calls the miniport to get the list of modes supported by the kernel driver,
  1332. * and returns the list of modes supported by the diplay driver among those
  1333. *
  1334. * returns the number of entries in the videomode buffer.
  1335. * 0 means no modes are supported by the miniport or that an error occured.
  1336. *
  1337. * NOTE: the buffer must be freed up by the caller.
  1338. *
  1339. \**************************************************************************/
  1340. DWORD getAvailableModes(
  1341. HANDLE hDriver,
  1342. PVIDEO_MODE_INFORMATION* modeInformation, // Must be freed by caller
  1343. DWORD* cbModeSize)
  1344. {
  1345. ULONG ulTemp;
  1346. VIDEO_NUM_MODES modes;
  1347. PVIDEO_MODE_INFORMATION pVideoTemp;
  1348. //
  1349. // Get the number of modes supported by the mini-port
  1350. //
  1351. if (!AtiDeviceIoControl(hDriver,
  1352. IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
  1353. NULL,
  1354. 0,
  1355. &modes,
  1356. sizeof(VIDEO_NUM_MODES),
  1357. &ulTemp))
  1358. {
  1359. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_NUM_AVAIL_MODES"));
  1360. return(0);
  1361. }
  1362. *cbModeSize = modes.ModeInformationLength;
  1363. //
  1364. // Allocate the buffer for the mini-port to write the modes in.
  1365. //
  1366. *modeInformation = AtiAllocMem(LPTR, FL_ZERO_MEMORY,
  1367. modes.NumModes * modes.ModeInformationLength
  1368. );
  1369. if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
  1370. {
  1371. DISPDBG((0, "getAvailableModes - Failed AtiAllocMem"));
  1372. return 0;
  1373. }
  1374. //
  1375. // Ask the mini-port to fill in the available modes.
  1376. //
  1377. if (!AtiDeviceIoControl(hDriver,
  1378. IOCTL_VIDEO_QUERY_AVAIL_MODES,
  1379. NULL,
  1380. 0,
  1381. *modeInformation,
  1382. modes.NumModes * modes.ModeInformationLength,
  1383. &ulTemp))
  1384. {
  1385. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_AVAIL_MODES"));
  1386. AtiFreeMem(*modeInformation);
  1387. *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
  1388. return(0);
  1389. }
  1390. //
  1391. // Now see which of these modes are supported by the display driver.
  1392. // As an internal mechanism, set the length to 0 for the modes we
  1393. // DO NOT support.
  1394. //
  1395. ulTemp = modes.NumModes;
  1396. pVideoTemp = *modeInformation;
  1397. //
  1398. // Mode is rejected if it is not one plane, or not graphics, or is not
  1399. // one of 8, 15, 16, 24 or 32 bits per pel.
  1400. //
  1401. while (ulTemp--)
  1402. {
  1403. //DISPDBG((0, "pVideoTemp: %4li bpp, %4li x %4li, %4li Hz",
  1404. //pVideoTemp->BitsPerPlane * pVideoTemp->NumberOfPlanes,
  1405. //pVideoTemp->VisScreenWidth, pVideoTemp->VisScreenHeight,
  1406. //pVideoTemp->Frequency ));
  1407. if ((pVideoTemp->NumberOfPlanes != 1 ) ||
  1408. !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
  1409. ((pVideoTemp->BitsPerPlane != 8) &&
  1410. (pVideoTemp->BitsPerPlane != 15) &&
  1411. (pVideoTemp->BitsPerPlane != 16) &&
  1412. (pVideoTemp->BitsPerPlane != 24) &&
  1413. (pVideoTemp->BitsPerPlane != 32)))
  1414. {
  1415. DISPDBG((2, "Rejecting miniport mode:"));
  1416. DISPDBG((2, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  1417. DISPDBG((2, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  1418. DISPDBG((2, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  1419. pVideoTemp->NumberOfPlanes));
  1420. DISPDBG((2, " Frequency -- %li", pVideoTemp->Frequency));
  1421. pVideoTemp->Length = 0;
  1422. }
  1423. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1424. (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
  1425. }
  1426. return(modes.NumModes);
  1427. }