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.

408 lines
15 KiB

  1. /************************************************************************/
  2. /* */
  3. /* ESCAPE.C */
  4. /* */
  5. /* Copyright (c) 1994, 1995 ATI Technologies Incorporated. */
  6. /************************************************************************/
  7. #include "precomp.h"
  8. #if (TARGET_BUILD == 351)
  9. /*
  10. * DCI support requires the use of structures and defined values
  11. * found in a header file that is only present in versions of
  12. * the DDK that support DCI, rather than having these items
  13. * in a DCI section of one of the standard header files. For this
  14. * reason, we can't do conditional compilation based on whether
  15. * the DCI-specific values are defined, because our first indication
  16. * would be an error due to the header file not being found.
  17. *
  18. * Explicit DCI support is only needed when building for NT 3.51,
  19. * since it was added for this version, but for version 4.0 (next
  20. * version) and above it is incorporated into Direct Draw rather
  21. * than being handled separately.
  22. */
  23. #include <dciddi.h>
  24. #include "dci.h"
  25. #endif
  26. /**************************************************************************
  27. *
  28. * ULONG DrvEscape(pso, iEsc, cjIn, pvIn, cjOut, pvOut);
  29. *
  30. * SURFOBJ *pso; Surface that the call is directed to
  31. * ULONG iEsc; Specifies the particular function to be performed.
  32. * Currently, only the following are supported:
  33. * QUERYESCSUPPORT:
  34. * Determine if a function is supported
  35. * ESC_SET_POWER_MANAGEMENT:
  36. * Set the DPMS state
  37. * DCICOMMAND:
  38. * Command to allow apps direct access to video memory
  39. * ULONG cjIn; Size, in bytes, of the buffer pointed to by pvIn
  40. * PVOID pvIn; Input data for the call. Format depends on function
  41. * specified by iEsc
  42. * ULONG cjOut; Size, in bytes, of the buffer pointed to by pvOut
  43. * PVOID pvOut; Output buffer for the call. Format depends on function
  44. * specified by iEsc
  45. *
  46. * DESCRIPTION:
  47. * Entry point for driver-defined functions.
  48. *
  49. * RETURN VALUE:
  50. * ESC_IS_SUPPORTED if successful
  51. * ESC_NOT_IMPLEMENTED if QUERYESCSUPPORT called for unimplemented function
  52. * ESC_NOT_SUPPORTED if unimplemented function requested
  53. *
  54. * GLOBALS CHANGED:
  55. * None
  56. *
  57. * CALLED BY:
  58. * This is an entry point
  59. *
  60. * AUTHOR:
  61. * Robert Wolff
  62. *
  63. * CHANGE HISTORY:
  64. *
  65. * TEST HISTORY:
  66. *
  67. ***************************************************************************/
  68. ULONG DrvEscape (SURFOBJ *pso,
  69. ULONG iEsc,
  70. ULONG cjIn,
  71. PVOID pvIn,
  72. ULONG cjOut,
  73. PVOID pvOut)
  74. {
  75. ULONG RetVal; /* Value to be returned */
  76. PDEV *ppdev; /* Pointer to video PDEV */
  77. DWORD dwRet; /* Output bytes from DeviceIoControl() */
  78. VIDEO_POWER_MANAGEMENT DpmsData; /* Structure used in DeviceIoControl() call */
  79. #if (TARGET_BUILD == 351)
  80. DCICMD *pDciCmd;
  81. #endif
  82. DISPDBG((DEBUG_ENTRY_EXIT, "--> DrvEscape"));
  83. RetVal = ESC_NOT_SUPPORTED;
  84. /*
  85. * Get the PDEV for the video card (used for calling IOCTLs).
  86. */
  87. ppdev = (PDEV *) pso->dhpdev;
  88. /*
  89. * Handle each case depending on which escape function was requested.
  90. */
  91. switch (iEsc)
  92. {
  93. /*
  94. * Check whether a given function is supported.
  95. */
  96. case QUERYESCSUPPORT:
  97. /*
  98. * When querying escape support, the function in question
  99. * is passed in the ULONG passed in pvIn.
  100. */
  101. if(!pvIn)
  102. RetVal = ESC_NOT_IMPLEMENTED;
  103. break;
  104. switch (*(PULONG)pvIn)
  105. {
  106. case QUERYESCSUPPORT:
  107. DISPDBG((DEBUG_DETAIL, "Querying QUERYESCSUPPORT"));
  108. RetVal = ESC_IS_SUPPORTED;
  109. break;
  110. case ESC_SET_POWER_MANAGEMENT:
  111. DISPDBG((DEBUG_DETAIL, "Querying ESC_SET_POWER_MANAGEMENT"));
  112. RetVal = ESC_IS_SUPPORTED;
  113. break;
  114. #if (TARGET_BUILD == 351)
  115. case DCICOMMAND:
  116. DISPDBG((DEBUG_DETAIL, "Querying DCICOMMAND"));
  117. RetVal = ESC_IS_SUPPORTED;
  118. break;
  119. #endif
  120. #if PAL_SUPPORT
  121. case ESC_INIT_PAL_SUPPORT:
  122. {
  123. DWORD value;
  124. // the first time ATIPlayer is calling us
  125. DISPDBG( (DEBUG_ESC,"PAL: ESC_INIT_PAL_SUPPORT " ));
  126. RetVal= DeallocOffscreenMem(ppdev) ;
  127. ppdev->pal_str.Palindrome_flag=FALSE;
  128. //init the VT regs in block 1 (BUS_CNTL)
  129. MemR32(0x28,&value);
  130. value=value|0x08000000;
  131. MemW32(0x28,value);
  132. // initialize some overlay/scaler regs on RAGEIII
  133. if (ppdev->iAsic>=CI_M64_GTC_UMC)
  134. {
  135. WriteVTReg(0x54, 0x101000); //DD_SCALER_COLOUR_CNTL
  136. WriteVTReg(0x55, 0x2000); //DD_SCALER_H_COEFF0
  137. WriteVTReg(0x56, 0x0D06200D); //DD_SCALER_H_COEFF1
  138. WriteVTReg(0x57, 0x0D0A1C0D); //DD_SCALER_H_COEFF2
  139. WriteVTReg(0x58, 0x0C0E1A0C); //DD_SCALER_H_COEFF3
  140. WriteVTReg(0x59, 0x0C14140C); //DD_SCALER_H_COEFF4
  141. }
  142. // problems with ACCESS DEVICE due to inconcistencies in Palindrome (Due to the fact that Palindrome is inconsistent in
  143. // using the same pointer to ACCESSDEVICE struct for QUERY, ALLOC and FREE) :
  144. (ppdev->pal_str.lpOwnerAccessStructConnector)=NULL; // no owner at this time
  145. (ppdev->pal_str.lpOwnerAccessStructOverlay)=NULL; // no owner at this time
  146. if(ppdev->semph_overlay==2) // = 0 resource free; = 1 in use by DDraw; = 2 in use by Palindrome;
  147. {
  148. ppdev->semph_overlay=0;
  149. }
  150. }
  151. break;
  152. //Functions for CWDDE support
  153. //Display mode group
  154. case Control_DisplaymodeIsSupported:
  155. DISPDBG( (DEBUG_ESC,"PAL: Control_DisplaymodeIsSupported " ));
  156. RetVal=1;
  157. break;
  158. case Control_DisplaymodeIsEnabled:
  159. DISPDBG( (DEBUG_ESC,"PAL: Control_DisplaymodeIsEnabled " ));
  160. RetVal=1;
  161. break;
  162. case Control_GetDisplaymode:
  163. DISPDBG( (DEBUG_ESC," PAL: Control_GetDisplaymode" ));
  164. RetVal=GetDisplayMode(ppdev,pvOut) ;
  165. break;
  166. //End display mode group
  167. // DCI control group
  168. case Control_DCIIsSupported:
  169. DISPDBG( (DEBUG_ESC,"PAL: Control_DCIIsSupported " ));
  170. RetVal=1;
  171. break;
  172. case Control_DCIIsEnabled:
  173. DISPDBG( (DEBUG_ESC,"PAL: Control_DCIIsEnabled " ));
  174. if(ppdev->pal_str.Flag_DCIIsEnabled)
  175. RetVal=1;
  176. else
  177. RetVal=0;
  178. break;
  179. case Control_DCIEnable:
  180. DISPDBG( (DEBUG_ESC," PAL: Control_DCIEnable" ));
  181. // this flag will be also used for activation of the mode switch detection code
  182. // this function will be called in the case of mode switch
  183. ppdev->pal_str.CallBackFnct=(PVOID)pvIn;
  184. ppdev->pal_str.pData=(PVOID)pvOut;
  185. ppdev->pal_str.Flag_DCIIsEnabled=TRUE;
  186. ppdev->pal_str.Counter_DCIIsEnabled++;
  187. RetVal=1;
  188. break;
  189. case Control_DCIDisable:
  190. DISPDBG( (DEBUG_ESC," PAL: Control_DCIDisable " ));
  191. if(ppdev->pal_str.Counter_DCIIsEnabled>0)
  192. if(--ppdev->pal_str.Counter_DCIIsEnabled==0)
  193. ppdev->pal_str.Flag_DCIIsEnabled=FALSE;
  194. RetVal=1;
  195. break;
  196. case Control_DCIAccessDevice:
  197. DISPDBG( (DEBUG_ESC,"PAL: Control_DCIAccessDevice " ));
  198. RetVal=AccessDevice(ppdev,pvIn, pvOut);
  199. DISPDBG( (DEBUG_ESC,"PAL: EXIT Control_DCIAccessDevice " ));
  200. break;
  201. case Control_DCIVideoCapture:
  202. DISPDBG( (DEBUG_ESC_2,"PAL: Control_DCIVideoCapture " ));
  203. RetVal=VideoCaptureFnct(ppdev,pvIn, pvOut);
  204. break;
  205. case Control_ConfigIsSupported:
  206. DISPDBG( (DEBUG_ESC,"PAL: Control_ConfigIsSupported" ));
  207. RetVal=1;
  208. break;
  209. case Control_ConfigIsEnabled:
  210. DISPDBG( (DEBUG_ESC,"PAL:Control_ConfigIsEnabled " ));
  211. if(ppdev->pal_str.Flag_Control_ConfigIsEnabled)
  212. RetVal=1;
  213. else
  214. RetVal=0;
  215. break;
  216. //end of DCI feature group
  217. // Configuration Group
  218. case Control_GetConfiguration:
  219. DISPDBG( (DEBUG_ESC,"PAL: Control_GetConfiguration " ));
  220. RetVal=GetConfiguration(ppdev,pvOut);
  221. break; //end GetConfiguration
  222. //Functions for direct palindrome support
  223. case ESC_WRITE_REG:
  224. DISPDBG( (DEBUG_ESC," PAL: ESC_WRITE_REG" ));
  225. RetVal=WriteRegFnct(ppdev,pvIn);
  226. break;
  227. case ESC_READ_REG:
  228. DISPDBG( (DEBUG_ESC,"PAL: ESC_READ_REG " ));
  229. RetVal=ReadRegFnct(ppdev,pvIn, pvOut);
  230. break;
  231. case ESC_I2C_ACCESS:
  232. DISPDBG( (DEBUG_ESC,"PAL:ESC_I2C_ACCESS " ));
  233. I2CAccess_New(ppdev,(LPI2CSTRUCT_NEW)pvIn,(LPI2CSTRUCT_NEW)pvOut);
  234. RetVal=ESC_IS_SUPPORTED;
  235. break;
  236. case ESC_ALLOC_OFFSCREEN:
  237. // this call is palindrome specific and it is seldomly used
  238. if(ppdev->pal_str.Palindrome_flag==FALSE)
  239. {
  240. ppdev->pal_str.Palindrome_flag=TRUE;
  241. ppdev->pal_str.no_lines_allocated=0; // number of lines already allocated by "alloc mem" in offscreen mem
  242. //flags for palindrome
  243. ppdev->pal_str.dos_flag=FALSE;
  244. ppdev->pal_str.Realloc_mem_flag=FALSE;
  245. ppdev->pal_str.Mode_Switch_flag=FALSE;
  246. ppdev->pal_str.No_mem_allocated_flag=FALSE;
  247. ppdev->pal_str.preg=NULL;
  248. }
  249. DISPDBG( (DEBUG_ESC,"PAL:ESC_ALLOC_OFFSCREEN " ));
  250. RetVal=AllocOffscreenMem(ppdev, pvIn, pvOut);
  251. break;
  252. case ESC_DEALLOC_OFFSCREEN:
  253. DISPDBG( (DEBUG_ESC,"PAL: ESC_DEALLOC_OFFSCREEN " ));
  254. RetVal= DeallocOffscreenMem(ppdev) ;
  255. ppdev->pal_str.Palindrome_flag=FALSE;
  256. break;
  257. // end escapes for palindrome support
  258. #endif // PALINDROME_SUPPORT
  259. default:
  260. DISPDBG((DEBUG_ERROR, "Querying unimplemented function"));
  261. RetVal = ESC_NOT_IMPLEMENTED;
  262. break;
  263. }
  264. break;
  265. /*
  266. * Switch into the specified DPMS state.
  267. */
  268. case ESC_SET_POWER_MANAGEMENT:
  269. DISPDBG((DEBUG_DETAIL, "Function ESC_SET_POWER_MANAGEMENT"));
  270. /*
  271. * The desired power management state is passed
  272. * in the ULONG passed in pvIn.
  273. */
  274. if(!pvIn)
  275. RetVal = ESC_NOT_IMPLEMENTED;
  276. break;
  277. switch (*(PULONG)pvIn)
  278. {
  279. case VideoPowerOn:
  280. DISPDBG((DEBUG_DETAIL, "State selected = ON"));
  281. RetVal = ESC_IS_SUPPORTED;
  282. break;
  283. case VideoPowerStandBy:
  284. DISPDBG((DEBUG_DETAIL, "State selected = STAND-BY"));
  285. RetVal = ESC_IS_SUPPORTED;
  286. break;
  287. case VideoPowerSuspend:
  288. DISPDBG((DEBUG_DETAIL, "State selected = SUSPEND"));
  289. RetVal = ESC_IS_SUPPORTED;
  290. break;
  291. case VideoPowerOff:
  292. DISPDBG((DEBUG_DETAIL, "State selected = OFF"));
  293. RetVal = ESC_IS_SUPPORTED;
  294. break;
  295. default:
  296. DISPDBG((DEBUG_ERROR, "Invalid state selected"));
  297. RetVal = ESC_NOT_SUPPORTED;
  298. break;
  299. }
  300. DpmsData.Length = sizeof(struct _VIDEO_POWER_MANAGEMENT);
  301. DpmsData.DPMSVersion = 0; /* Not used for "set" packet */
  302. DpmsData.PowerState = *(PULONG)pvIn;
  303. /*
  304. * Tell the miniport to set the DPMS mode. If the miniport
  305. * either doesn't support this packet, or reports that the
  306. * video card doesn't, tell the calling application that
  307. * we failed.
  308. */
  309. if (AtiDeviceIoControl( ppdev->hDriver,
  310. IOCTL_VIDEO_SET_POWER_MANAGEMENT,
  311. &DpmsData,
  312. sizeof (struct _VIDEO_POWER_MANAGEMENT),
  313. NULL,
  314. 0,
  315. &dwRet) == FALSE)
  316. {
  317. DISPDBG((DEBUG_ERROR, "Unable to set desired state"));
  318. RetVal = ESC_NOT_SUPPORTED;
  319. }
  320. break;
  321. #if (TARGET_BUILD == 351)
  322. case DCICOMMAND:
  323. pDciCmd = (DCICMD*) pvIn;
  324. if ((cjIn < sizeof(DCICMD)) || (pDciCmd->dwVersion != DCI_VERSION))
  325. {
  326. RetVal = (ULONG)DCI_FAIL_UNSUPPORTED;
  327. }
  328. else
  329. {
  330. switch(pDciCmd->dwCommand)
  331. {
  332. case DCICREATEPRIMARYSURFACE:
  333. RetVal = DCICreatePrimarySurface(ppdev, cjIn, pvIn, cjOut, pvOut);
  334. break;
  335. default:
  336. RetVal = (ULONG)DCI_FAIL_UNSUPPORTED;
  337. break;
  338. }
  339. }
  340. break;
  341. #endif
  342. /*
  343. * Unimplemented function requested.
  344. */
  345. default:
  346. DISPDBG((DEBUG_ERROR, "Unimplemented function requested"));
  347. RetVal = ESC_NOT_SUPPORTED;
  348. break;
  349. }
  350. DISPDBG((DEBUG_ENTRY_EXIT, "<-- DrvEscape"));
  351. return RetVal;
  352. } /* DrvEscape() */
  353.