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.

518 lines
23 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: drvsup.hxx
  3. *
  4. * defines the internal structures used in drvsup.cxx
  5. *
  6. * Copyright (c) 1995-1999 Microsoft Corporation
  7. \**************************************************************************/
  8. /******************************Conventions*********************************\
  9. *
  10. * Function Dispatching:
  11. *
  12. * The dispatch table in an ldev consists of an array of function
  13. * pointers. The functions the device does not support have 0's in them.
  14. * The functions it does support contain pointers to the function in the
  15. * device driver dll.
  16. *
  17. * For a surface output call you check if the device has hooked the call.
  18. * (Signaled by the flags passed in EngAssociateSurface) If it has
  19. * dispatch the call via the ldev in so.hldevOwner(). If it has not
  20. * hooked the call, the simulations should be called. This is what is
  21. * done by the macro PFNGET.
  22. *
  23. * For some optional calls like DrvSetPalette, DrvCreateDeviceBitmap
  24. * you must check for 0 in the driver dispatch table. This is what
  25. * the macro PFNVALID does.
  26. *
  27. \**************************************************************************/
  28. #include "ntddvdeo.h"
  29. typedef enum _LDEVTYPE { /* ldt */
  30. LDEV_DEVICE_DISPLAY = 1, /* Display Driver */
  31. LDEV_DEVICE_PRINTER = 2, /* Printer Driver */
  32. LDEV_DEVICE_META = 3, /* Layer Driver (ex. DDML) */
  33. LDEV_DEVICE_MIRROR = 4, /* Mirror Driver (ex. NetMeeting) */
  34. LDEV_IMAGE = 5, /* Image Driver (ex. DirectDraw) */
  35. LDEV_FONT = 6, /* Font Driver */
  36. } LDEVTYPE;
  37. #define INDEX_DdGetDriverInfo 1
  38. #define INDEX_DdContextCreate 2
  39. #define INDEX_DdContextDestroy 3
  40. //
  41. // EnableDirectDraw Generic Callback indexes
  42. //
  43. #define INDEX_DdCanCreateSurface 4
  44. #define INDEX_DdCreateSurface 5
  45. #define INDEX_DdDestroySurface 6
  46. #define INDEX_DdLockSurface 7
  47. #define INDEX_DdUnlockSurface 8
  48. #define INDEX_DdCreatePalette 9
  49. #define INDEX_DdSetColorKey 10
  50. #define INDEX_DdWaitForVerticalBlank 11
  51. #define INDEX_DdGetScanLine 12
  52. #define INDEX_DdMapMemory 13
  53. //
  54. // EnableDirectDraw Surface Callback indexes
  55. //
  56. #define INDEX_DdFlip 14
  57. #define INDEX_DdSetClipList 15
  58. #define INDEX_DdLock 16
  59. #define INDEX_DdUnlock 17
  60. #define INDEX_DdBlt 18
  61. #define INDEX_DdAddAttachedSurface 19
  62. #define INDEX_DdGetBltStatus 20
  63. #define INDEX_DdGetFlipStatus 21
  64. #define INDEX_DdUpdateOverlay 22
  65. #define INDEX_DdSetOverlayPosition 23
  66. #define INDEX_DdSetPalette 24
  67. //
  68. // EnableDirectDraw Palette Callback indexes
  69. //
  70. #define INDEX_DdDestroyPalette 25
  71. #define INDEX_DdSetEntries 26
  72. //
  73. // DrvGetDirectDrawInfo
  74. //
  75. #define INDEX_DdCanCreateD3DBuffer 27
  76. #define INDEX_DdCreateD3DBuffer 28
  77. #define INDEX_DdDestroyD3DBuffer 29
  78. #define INDEX_DdLockD3DBuffer 30
  79. #define INDEX_DdUnlockD3DBuffer 31
  80. //
  81. // GetDirectDrawInfo - Color Control
  82. //
  83. #define INDEX_DdColorControl 32
  84. #define INDEX_DdDrawPrimitives2 33
  85. #define INDEX_DdValidateTextureStageState 34
  86. #define INDEX_DdSyncSurfaceData 35
  87. #define INDEX_DdSyncVideoPortData 36
  88. #define INDEX_DdGetAvailDriverMemory 37
  89. #define INDEX_DdAlphaBlt 38
  90. #define INDEX_DdCreateSurfaceEx 39
  91. #define INDEX_DdGetDriverState 40
  92. #define INDEX_DdDestroyDDLocal 41
  93. #define INDEX_DdFreeDriverMemory 42
  94. #define INDEX_DdSetExclusiveMode 43
  95. #define INDEX_DdFlipToGDISurface 44
  96. #define INDEX_DD_LAST 45
  97. /*********************************Class************************************\
  98. * LDEV structure
  99. *
  100. \**************************************************************************/
  101. typedef struct _LDEV {
  102. //
  103. // The first three elements of the LDEV are used by the watchdog.sys
  104. // driver. Please don't modify the first three fields.
  105. //
  106. struct _LDEV *pldevNext; // link to the next LDEV in list
  107. struct _LDEV *pldevPrev; // link to the previous LDEV in list
  108. PSYSTEM_GDI_DRIVER_INFORMATION pGdiDriverInfo; // Driver module handle.
  109. LDEVTYPE ldevType; // Type of ldev
  110. ULONG cldevRefs; // Count of open PDEVs.
  111. BOOL bArtificialIncrement:1; // Flag to increment refcnt for printer drivers
  112. BOOL bStaticImportLink:1; // Statically linked to win32.sys ?
  113. // which keeps the driver loaded w/o open DCs.
  114. PVOID umpdCookie; // Cookie for the loaded umpd driver
  115. PW32PROCESS pid; // valid only for umpd
  116. //
  117. // DDI version number of the driver.
  118. //
  119. ULONG ulDriverVersion;
  120. //
  121. // Watchdog Dispatch Table - this is a set of entry points which
  122. // mirrors the driver entry points but starts and stops the watchdog.
  123. //
  124. PFN apfn[INDEX_LAST]; // Dispatch table.
  125. //
  126. // Driver Dispatch Table - this is the final entry point into the driver
  127. //
  128. PFN apfnDriver[INDEX_LAST];
  129. //
  130. // Monitor whether a thread got stuck in the driver owned by this
  131. // LDEV.
  132. //
  133. BOOL bThreadStuck;
  134. } LDEV, *PLDEV;
  135. /*********************************Class************************************\
  136. * External Prototypes
  137. *
  138. \**************************************************************************/
  139. PLDEV
  140. ldevLoadImage(
  141. LPWSTR pwszDriver,
  142. BOOL bImage,
  143. PBOOL pbAlreadyLoaded,
  144. BOOL LoadInSessionSpace);
  145. PLDEV
  146. ldevLoadDriver(
  147. LPWSTR pwszDriver,
  148. LDEVTYPE ldt
  149. );
  150. PLDEV
  151. ldevLoadInternal(
  152. PFN pfnFdEnable,
  153. LDEVTYPE ldt
  154. );
  155. VOID
  156. ldevUnloadImage(
  157. PLDEV pldev
  158. );
  159. ULONG
  160. ldevGetDriverModes(
  161. LPWSTR pwszDriver,
  162. HANDLE hDriver,
  163. ULONG cjSize,
  164. DEVMODEW *pdm
  165. );
  166. BOOL
  167. bFillFunctionTable(
  168. PDRVFN pdrvfn,
  169. ULONG cdrvfn,
  170. PFN* ppfnTable
  171. );
  172. VOID
  173. DrvPrepareForEARecovery(
  174. VOID
  175. );
  176. /**************************************************************************\
  177. * Debug trace
  178. *
  179. \**************************************************************************/
  180. #if DBG
  181. #define MDEV_STACK_TRACE_LENGTH 14
  182. typedef enum {
  183. UnusedRecord = 0,
  184. DrvDisableMDEV_HWOff,
  185. DrvEnableMDEV_HWOn,
  186. DrvDisableMDEV_FromGRE,
  187. DrvEnableMDEV_FromGRE,
  188. DrvChangeDisplaySettings_SetMode,
  189. } MDEVAPI;
  190. typedef struct tagMDEVRECORD {
  191. PMDEV pMDEV;
  192. MDEVAPI API;
  193. PFN Trace[MDEV_STACK_TRACE_LENGTH];
  194. } MDEVRECORD, *PMDEVRECORD;
  195. #endif
  196. /**************************************************************************\
  197. * Internal graphics device structure
  198. *
  199. \**************************************************************************/
  200. typedef struct tagDEVMODEMARK {
  201. ULONG bPruned;
  202. PDEVMODEW pDevMode;
  203. } DEVMODEMARK, *PDEVMODEMARK, *LPDEVMODEMARK;
  204. typedef struct tagGRAPHICS_DEVICE *PGRAPHICS_DEVICE;
  205. typedef struct tagGRAPHICS_DEVICE {
  206. WCHAR szNtDeviceName[16]; // NT device name (\\Device\\Videox)
  207. WCHAR szWinDeviceName[16]; // user-mode name (\\DosDevices\\Displayx)
  208. //
  209. PGRAPHICS_DEVICE pNextGraphicsDevice; // Next device in the linked list.
  210. PGRAPHICS_DEVICE pVgaDevice; // If this device is VGA compatible
  211. // and uses another isntance to operate
  212. // in VGA mode
  213. HANDLE pDeviceHandle; // Handle for the device
  214. HANDLE pPhysDeviceHandle; // Physical device handle
  215. PVOID hkClassDriverConfig; // Registry Handle to the driver class key
  216. //
  217. DWORD stateFlags; // Flags describing the state of the
  218. // device
  219. ULONG cbdevmodeInfo; // Size of the devmode information
  220. PDEVMODEW devmodeInfo; // Pointer to the current list of modes
  221. // for the device
  222. ULONG numRawModes; // Number of modes returned from video card
  223. PDEVMODEMARK devmodeMarks; // List of marked devmodes
  224. LPWSTR DisplayDriverNames; // Pointer to MULTI_SZ with DD names.
  225. LPWSTR DeviceDescription; // Pointer to the devices description.
  226. ULONG numMonitorDevice; // number of monitors associate with the device
  227. PVIDEO_MONITOR_DEVICE MonitorDevices; // Monitor devices
  228. HANDLE pFileObject;
  229. USHORT ProtocolType;
  230. } GRAPHICS_DEVICE, *PGRAPHICS_DEVICE;
  231. #define IS_ATTACHED_ACTIVE(flag) ((flag & (DISPLAY_DEVICE_ATTACHED | DISPLAY_DEVICE_ACTIVE)) \
  232. == (DISPLAY_DEVICE_ATTACHED | DISPLAY_DEVICE_ACTIVE))
  233. #ifdef IOCTL_VIDEO_USE_DEVICE_IN_SESSION
  234. BOOL
  235. bSetDeviceSessionUsage(
  236. PGRAPHICS_DEVICE PhysDisp,
  237. BOOL bEnable
  238. );
  239. #else IOCTL_VIDEO_USE_DEVICE_IN_SESSION
  240. #define bSetDeviceSessionUsage(pGraphicsDevice, bEnable) TRUE
  241. #endif IOCTL_VIDEO_USE_DEVICE_IN_SESSION
  242. /**************************************************************************\
  243. * This is for mode pruning based on EDID
  244. *
  245. \**************************************************************************/
  246. #define MAX_MODE_CAPABILITY 36
  247. #define MIN_REFRESH_RATE 56
  248. typedef struct tagModeCap
  249. {
  250. ULONG dmWidth, dmHeight;
  251. ULONG freq;
  252. ULONG MinVFreq, MinHFreq, MaxHFreq;
  253. } MODECAP, *PMODECAP, *LPMODECAP;
  254. typedef struct _FREQUENCY_RAGE
  255. {
  256. ULONG ulMinVerticalRate; // Min vertical rate in Hz
  257. ULONG ulMaxVerticalRate; // Max vertical rate in Hz
  258. ULONG ulMinHorizontalRate; // Min horizontal rate in Hz
  259. ULONG ulMaxHorizontalRate; // Max horizontal rate in Hz
  260. ULONG ulMinPixelClock; // Min supported pixel clock in Hz
  261. ULONG ulMaxPixelClock; // Max supported pixel clock in Hz
  262. } FREQUENCY_RANGE, *PFREQUENCY_RANGE;
  263. /**************************************************************************\
  264. * EDID Version 2 constrains and offsets
  265. *
  266. \**************************************************************************/
  267. #define EDID2_MAX_LUMINANCE_TABLES 1
  268. #define EDID2_MAX_FREQUENCY_RANGES 7
  269. #define EDID2_MAX_DETAIL_TIMING_RANGES 3
  270. #define EDID2_MAX_TIMING_CODES 31
  271. #define EDID2_MAX_DETAIL_TIMINGS 7
  272. #define EDID2_LUMINANCE_TABLE_OFFSET 0x80
  273. /**************************************************************************\
  274. * EDID Version 2 MapOfTiming masks, shifts, and flags
  275. *
  276. \**************************************************************************/
  277. #define EDID2_MOT0_DETAIL_TIMING_RANGE_MASK 0x03
  278. #define EDID2_MOT0_DETAIL_TIMING_RANGE_SHIFT 0x00
  279. #define EDID2_MOT0_FREQUENCY_RANGE_MASK 0x1c
  280. #define EDID2_MOT0_FREQUENCY_RANGE_SHIFT 0x02
  281. #define EDID2_MOT0_LUMINANCE_TABLE_MASK 0x20
  282. #define EDID2_MOT0_LUMINANCE_TABLE_SHIFT 0x05
  283. #define EDID2_MOT0_PREFFERED_MODE_FLAG 0x40
  284. #define EDID2_MOT0_EXTENSION_FLAG 0x80
  285. #define EDID2_MOT1_DETAIL_TIMING_MASK 0x07
  286. #define EDID2_MOT1_DETAIL_TIMING_SHIFT 0x00
  287. #define EDID2_MOT1_TIMING_CODE_MASK 0xf8
  288. #define EDID2_MOT1_TIMING_CODE_SHIFT 0x03
  289. /**************************************************************************\
  290. * EDID Version 2 LuminanceTable masks, shifts, and flags
  291. *
  292. \**************************************************************************/
  293. #define EDID2_LT0_ENTRIES_MASK 0x1f
  294. #define EDID2_LT0_ENTRIES_SHIFT 0x00
  295. #define EDID2_LT0_SUB_CHANNELS_FLAG 0x80
  296. /**************************************************************************\
  297. * EDID Version 2 EDID2_DETAIL_TIMING flags
  298. *
  299. \**************************************************************************/
  300. #define EDID2_DT_INTERLACED 0x80
  301. /**************************************************************************\
  302. * EDID Version 2 EDID2_TIMING_CODE flags
  303. *
  304. \**************************************************************************/
  305. #define EDID2_TC_INTERLACED 0x40
  306. /**************************************************************************\
  307. * EDID Version 2 data structures
  308. *
  309. \**************************************************************************/
  310. #pragma pack(1)
  311. typedef struct _EDID2
  312. {
  313. UCHAR ucEdidVersionRevision; // EDID version / revision
  314. UCHAR ucaVendorProductId[7]; // Vendor / product identification
  315. UCHAR ucaManufacturerProductId[32]; // Manufacturer / product ID string
  316. UCHAR ucaSerialNumber[16]; // Serial number string
  317. UCHAR ucaReserved1[8]; // Unused
  318. UCHAR ucaDisplayInterface[15]; // Display interface parameters
  319. UCHAR ucaDisplayDevice[5]; // Display device description
  320. UCHAR ucaDisplayResponseTime[2]; // Display response time
  321. UCHAR ucaColorLuminance[28]; // Color / luminance description
  322. UCHAR ucaDisplaySpatial[10]; // Display spatial description
  323. UCHAR ucReserved2; // Unused
  324. UCHAR ucGftSupport; // GFT support information
  325. UCHAR ucaMapOfTiming[2]; // Map of timing information
  326. UCHAR ucaLuminanceTableAndTimings[127]; // Luminance table & timing descriptions
  327. UCHAR ucChecksum; // Checksum fill-in
  328. } EDID2, *PEDID2;
  329. typedef struct _EDID2_FREQUENCY_RANGE
  330. {
  331. UCHAR ucMinFrameFieldRateBits9_2; // Bits 9-2 of min frame/field rate in Hz
  332. UCHAR ucMaxFrameFieldRateBits9_2; // Bits 9-2 of max frame/field rate in Hz
  333. UCHAR ucMinLineRateBits9_2; // Bits 9-2 of min line rate in kHz
  334. UCHAR ucMaxLineRateBits9_2; // Bits 9-2 of max line rate in kHz
  335. UCHAR ucFrameFieldLineRatesBits1_0; // Bits 1-0 for above 4 values
  336. // Bits 7-6: lower 2 bits of min frame rate
  337. // Bits 5-4: lower 2 bits of max frame rate
  338. // Bits 3-2: lower 2 bits of min line rate
  339. // Bits 1-0: lower 2 bits of max line rate
  340. UCHAR ucMinPixelRateBits7_0; // Bits 7-0 of min pixel rate in MHz
  341. UCHAR ucMaxPixelRateBits7_0; // Bits 7-0 of max pixel rate in MHz
  342. UCHAR ucPixelRatesBits11_8; // Bits 11-8 of min pixel rate in MHz
  343. } EDID2_FREQUENCY_RANGE, *PEDID2_FREQUENCY_RANGE;
  344. typedef struct _EDID2_DETAIL_TIMING_RANGE
  345. {
  346. USHORT usMinPixelClock; // Min pixel clock in units of 10 kHz
  347. UCHAR ucMinHorizontalBlankLowByte; // Low byte of min horizontal blank (total - active)
  348. UCHAR ucMinVerticalBlankLowByte; // Low byte of min vertical blank (total - active)
  349. UCHAR ucMinBlankHighBits; // High nibbles of above 2 values:
  350. // Upper nibble: upper 4 bits of min horizontal blank
  351. // Lower nibble: upper 4 bits of min vertical blank
  352. UCHAR ucMinHorizontalSyncOffsetLowByte; // Low byte of min horizontal sync offset
  353. UCHAR ucMinHorizontalSyncWidthLowByte; // Low byte of min horizontal sync width
  354. UCHAR ucMinVerticalSyncOffsetAndWidthLowBits; // Low nibbles of above 2 values:
  355. // Upper nibble: lower 4 bits of min vertical sync offset
  356. // Lower nibble: lower 4 bits of min vertical sync width
  357. UCHAR ucMinSyncHighBits; // High bits of sync values:
  358. // Bits 7-6: upper 2 bits of min horizontal sync offset
  359. // Bits 5-4: upper 2 bits of min horizontal sync width
  360. // Bits 3-2: upper 2 bits of min vertical sync offset
  361. // Bits 1-0: upper 2 bits of min vertical sync width
  362. USHORT usMaxPixelClock; // Max pixel clock in units of 10 kHz
  363. UCHAR ucMaxHorizontalBlankLowByte; // Low byte of max horizontal blank (total - active)
  364. UCHAR ucMaxVerticalBlankLowByte; // Low byte of max vertical blank (total - active)
  365. UCHAR ucMaxBlankHighBits; // High nibbles of above 2 values:
  366. // Upper nibble: upper 4 bits of max horizontal blank
  367. // Lower nibble: upper 4 bits of max vertical blank
  368. UCHAR ucMaxHorizontalSyncOffsetLowByte; // Low byte of max horizontal sync offset
  369. UCHAR ucMaxHorizontalSyncWidthLowByte; // Low byte of max horizontal sync width
  370. UCHAR ucMaxVerticalSyncOffsetAndWidthLowBits; // Low nibbles of above 2 values:
  371. // Upper nibble: lower 4 bits of max vertical sync offset
  372. // Lower nibble: lower 4 bits of max vertical sync width
  373. UCHAR ucMaxSyncHighBits; // High bits of sync values:
  374. // Bits 7-6: upper 2 bits of max horizontal sync offset
  375. // Bits 5-4: upper 2 bits of max horizontal sync width
  376. // Bits 3-2: upper 2 bits of max vertical sync offset
  377. // Bits 1-0: upper 2 bits of max vertical sync width
  378. UCHAR ucHorizontalSizeLowByte; // Low byte of horizontal size in mm
  379. UCHAR ucVerticalSizeLowByte; // Low byte of vertical size in mm
  380. UCHAR ucSizeHighBits; // High nibbles of above 2 values:
  381. // Upper nibble: upper 4 bits of horizontal size
  382. // Lower nibble: upper 4 bits of vertical size
  383. UCHAR ucHorizontalActiveLowByte; // Low byte of horizontal active
  384. UCHAR ucVerticalActiveLowByte; // Low byte of vertical active
  385. UCHAR ucActiveHighBits; // High nibbles of above 2 values:
  386. // Upper nibble: upper 4 bits of horizontal active
  387. // Lower nibble: upper 4 bits of vertical active
  388. UCHAR ucHorizontalBorder; // Size of horizontal overscan
  389. UCHAR ucVerticalBorder; // Size of vertical overscan
  390. UCHAR ucFlags; // Interlace, polarities, sync configuration
  391. } EDID2_DETAIL_TIMING_RANGE, *PEDID2_DETAIL_TIMING_RANGE;
  392. typedef struct _EDID2_TIMING_CODE
  393. {
  394. UCHAR ucHorizontalActive; // (Horizontal Active pixels - 256) / 16
  395. UCHAR ucFlags; // Interlace, polarities, ...
  396. UCHAR ucAspectRatio; // Aspect ratio as N:100
  397. UCHAR ucRefreshRate; // Refresh rate in Hz
  398. } EDID2_TIMING_CODE, *PEDID2_TIMING_CODE;
  399. typedef struct _EDID2_DETAIL_TIMING
  400. {
  401. USHORT usPixelClock; // Pixel clock in units of 10 kHz
  402. UCHAR ucHorizontalActiveLowByte; // Low byte of horizontal active
  403. UCHAR ucHorizontalBlankLowByte; // Low byte of horizontal blank (total - active)
  404. UCHAR ucHorizontalHighBits; // High nibbles of above 2 values:
  405. // Upper nibble: upper 4 bits of horizontal active
  406. // Lower nibble: upper 4 bits of horizontal blank
  407. UCHAR ucVerticalActiveLowByte; // Low byte of vertical active
  408. UCHAR ucVerticalBlankLowByte; // Low byte of vertical blank (total - active)
  409. UCHAR ucVerticalHighBits; // High nibbles of above 2 values:
  410. // Upper nibble: upper 4 bits of vertical active
  411. // Lower nibble: upper 4 bits of vertical blank
  412. UCHAR ucHorizontalSyncOffsetLowByte; // Low byte of horizontal sync offset
  413. UCHAR ucHorizontalSyncWidthLowByte; // Low byte of horizontal sync width
  414. UCHAR ucVerticalSyncOffsetAndWidthLowBits; // Low nibbles of above 2 values:
  415. // Upper nibble: lower 4 bits of vertical sync offset
  416. // Lower nibble: lower 4 bits of vertical sync width
  417. UCHAR ucSyncHighBits; // High bits of sync values:
  418. // Bits 7-6: upper 2 bits of horizontal sync offset
  419. // Bits 5-4: upper 2 bits of horizontal sync width
  420. // Bits 3-2: upper 2 bits of vertical sync offset
  421. // Bits 1-0: upper 2 bits of vertical sync width
  422. UCHAR ucHorizontalSizeLowByte; // Low byte of horizontal size in mm
  423. UCHAR ucVerticalSizeLowByte; // Low byte of vertical size in mm
  424. UCHAR ucSizeHighBits; // High nibbles of above 2 values:
  425. // Upper nibble: upper 4 bits of horizontal size
  426. // Lower nibble: upper 4 bits of vertical size
  427. UCHAR ucHorizontalBorder; // Size of horizontal overscan
  428. UCHAR ucVerticalBorder; // Size of vertical overscan
  429. UCHAR ucFlags; // Interlace, polarities, sync configuration
  430. } EDID2_DETAIL_TIMING, *PEDID2_DETAIL_TIMING;
  431. #pragma pack()