Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

406 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. /*
  84. * Get the PDEV for the video card (used for calling IOCTLs).
  85. */
  86. ppdev = (PDEV *) pso->dhpdev;
  87. /*
  88. * Handle each case depending on which escape function was requested.
  89. */
  90. switch (iEsc)
  91. {
  92. /*
  93. * Check whether a given function is supported.
  94. */
  95. case QUERYESCSUPPORT:
  96. /*
  97. * When querying escape support, the function in question
  98. * is passed in the ULONG passed in pvIn.
  99. */
  100. if(!pvIn)
  101. RetVal = ESC_NOT_IMPLEMENTED;
  102. break;
  103. switch (*(PULONG)pvIn)
  104. {
  105. case QUERYESCSUPPORT:
  106. DISPDBG((DEBUG_DETAIL, "Querying QUERYESCSUPPORT"));
  107. RetVal = ESC_IS_SUPPORTED;
  108. break;
  109. case ESC_SET_POWER_MANAGEMENT:
  110. DISPDBG((DEBUG_DETAIL, "Querying ESC_SET_POWER_MANAGEMENT"));
  111. RetVal = ESC_IS_SUPPORTED;
  112. break;
  113. #if (TARGET_BUILD == 351)
  114. case DCICOMMAND:
  115. DISPDBG((DEBUG_DETAIL, "Querying DCICOMMAND"));
  116. RetVal = ESC_IS_SUPPORTED;
  117. break;
  118. #endif
  119. #if PAL_SUPPORT
  120. case ESC_INIT_PAL_SUPPORT:
  121. {
  122. DWORD value;
  123. // the first time ATIPlayer is calling us
  124. DISPDBG( (DEBUG_ESC,"PAL: ESC_INIT_PAL_SUPPORT " ));
  125. RetVal= DeallocOffscreenMem(ppdev) ;
  126. ppdev->pal_str.Palindrome_flag=FALSE;
  127. //init the VT regs in block 1 (BUS_CNTL)
  128. MemR32(0x28,&value);
  129. value=value|0x08000000;
  130. MemW32(0x28,value);
  131. // initialize some overlay/scaler regs on RAGEIII
  132. if (ppdev->iAsic>=CI_M64_GTC_UMC)
  133. {
  134. WriteVTReg(0x54, 0x101000); //DD_SCALER_COLOUR_CNTL
  135. WriteVTReg(0x55, 0x2000); //DD_SCALER_H_COEFF0
  136. WriteVTReg(0x56, 0x0D06200D); //DD_SCALER_H_COEFF1
  137. WriteVTReg(0x57, 0x0D0A1C0D); //DD_SCALER_H_COEFF2
  138. WriteVTReg(0x58, 0x0C0E1A0C); //DD_SCALER_H_COEFF3
  139. WriteVTReg(0x59, 0x0C14140C); //DD_SCALER_H_COEFF4
  140. }
  141. // problems with ACCESS DEVICE due to inconcistencies in Palindrome (Due to the fact that Palindrome is inconsistent in
  142. // using the same pointer to ACCESSDEVICE struct for QUERY, ALLOC and FREE) :
  143. (ppdev->pal_str.lpOwnerAccessStructConnector)=NULL; // no owner at this time
  144. (ppdev->pal_str.lpOwnerAccessStructOverlay)=NULL; // no owner at this time
  145. if(ppdev->semph_overlay==2) // = 0 resource free; = 1 in use by DDraw; = 2 in use by Palindrome;
  146. {
  147. ppdev->semph_overlay=0;
  148. }
  149. }
  150. break;
  151. //Functions for CWDDE support
  152. //Display mode group
  153. case Control_DisplaymodeIsSupported:
  154. DISPDBG( (DEBUG_ESC,"PAL: Control_DisplaymodeIsSupported " ));
  155. RetVal=1;
  156. break;
  157. case Control_DisplaymodeIsEnabled:
  158. DISPDBG( (DEBUG_ESC,"PAL: Control_DisplaymodeIsEnabled " ));
  159. RetVal=1;
  160. break;
  161. case Control_GetDisplaymode:
  162. DISPDBG( (DEBUG_ESC," PAL: Control_GetDisplaymode" ));
  163. RetVal=GetDisplayMode(ppdev,pvOut) ;
  164. break;
  165. //End display mode group
  166. // DCI control group
  167. case Control_DCIIsSupported:
  168. DISPDBG( (DEBUG_ESC,"PAL: Control_DCIIsSupported " ));
  169. RetVal=1;
  170. break;
  171. case Control_DCIIsEnabled:
  172. DISPDBG( (DEBUG_ESC,"PAL: Control_DCIIsEnabled " ));
  173. if(ppdev->pal_str.Flag_DCIIsEnabled)
  174. RetVal=1;
  175. else
  176. RetVal=0;
  177. break;
  178. case Control_DCIEnable:
  179. DISPDBG( (DEBUG_ESC," PAL: Control_DCIEnable" ));
  180. // this flag will be also used for activation of the mode switch detection code
  181. // this function will be called in the case of mode switch
  182. ppdev->pal_str.CallBackFnct=(PVOID)pvIn;
  183. ppdev->pal_str.pData=(PVOID)pvOut;
  184. ppdev->pal_str.Flag_DCIIsEnabled=TRUE;
  185. ppdev->pal_str.Counter_DCIIsEnabled++;
  186. RetVal=1;
  187. break;
  188. case Control_DCIDisable:
  189. DISPDBG( (DEBUG_ESC," PAL: Control_DCIDisable " ));
  190. if(ppdev->pal_str.Counter_DCIIsEnabled>0)
  191. if(--ppdev->pal_str.Counter_DCIIsEnabled==0)
  192. ppdev->pal_str.Flag_DCIIsEnabled=FALSE;
  193. RetVal=1;
  194. break;
  195. case Control_DCIAccessDevice:
  196. DISPDBG( (DEBUG_ESC,"PAL: Control_DCIAccessDevice " ));
  197. RetVal=AccessDevice(ppdev,pvIn, pvOut);
  198. DISPDBG( (DEBUG_ESC,"PAL: EXIT Control_DCIAccessDevice " ));
  199. break;
  200. case Control_DCIVideoCapture:
  201. DISPDBG( (DEBUG_ESC_2,"PAL: Control_DCIVideoCapture " ));
  202. RetVal=VideoCaptureFnct(ppdev,pvIn, pvOut);
  203. break;
  204. case Control_ConfigIsSupported:
  205. DISPDBG( (DEBUG_ESC,"PAL: Control_ConfigIsSupported" ));
  206. RetVal=1;
  207. break;
  208. case Control_ConfigIsEnabled:
  209. DISPDBG( (DEBUG_ESC,"PAL:Control_ConfigIsEnabled " ));
  210. if(ppdev->pal_str.Flag_Control_ConfigIsEnabled)
  211. RetVal=1;
  212. else
  213. RetVal=0;
  214. break;
  215. //end of DCI feature group
  216. // Configuration Group
  217. case Control_GetConfiguration:
  218. DISPDBG( (DEBUG_ESC,"PAL: Control_GetConfiguration " ));
  219. RetVal=GetConfiguration(ppdev,pvOut);
  220. break; //end GetConfiguration
  221. //Functions for direct palindrome support
  222. case ESC_WRITE_REG:
  223. DISPDBG( (DEBUG_ESC," PAL: ESC_WRITE_REG" ));
  224. RetVal=WriteRegFnct(ppdev,pvIn);
  225. break;
  226. case ESC_READ_REG:
  227. DISPDBG( (DEBUG_ESC,"PAL: ESC_READ_REG " ));
  228. RetVal=ReadRegFnct(ppdev,pvIn, pvOut);
  229. break;
  230. case ESC_I2C_ACCESS:
  231. DISPDBG( (DEBUG_ESC,"PAL:ESC_I2C_ACCESS " ));
  232. I2CAccess_New(ppdev,(LPI2CSTRUCT_NEW)pvIn,(LPI2CSTRUCT_NEW)pvOut);
  233. RetVal=ESC_IS_SUPPORTED;
  234. break;
  235. case ESC_ALLOC_OFFSCREEN:
  236. // this call is palindrome specific and it is seldomly used
  237. if(ppdev->pal_str.Palindrome_flag==FALSE)
  238. {
  239. ppdev->pal_str.Palindrome_flag=TRUE;
  240. ppdev->pal_str.no_lines_allocated=0; // number of lines already allocated by "alloc mem" in offscreen mem
  241. //flags for palindrome
  242. ppdev->pal_str.dos_flag=FALSE;
  243. ppdev->pal_str.Realloc_mem_flag=FALSE;
  244. ppdev->pal_str.Mode_Switch_flag=FALSE;
  245. ppdev->pal_str.No_mem_allocated_flag=FALSE;
  246. ppdev->pal_str.preg=NULL;
  247. }
  248. DISPDBG( (DEBUG_ESC,"PAL:ESC_ALLOC_OFFSCREEN " ));
  249. RetVal=AllocOffscreenMem(ppdev, pvIn, pvOut);
  250. break;
  251. case ESC_DEALLOC_OFFSCREEN:
  252. DISPDBG( (DEBUG_ESC,"PAL: ESC_DEALLOC_OFFSCREEN " ));
  253. RetVal= DeallocOffscreenMem(ppdev) ;
  254. ppdev->pal_str.Palindrome_flag=FALSE;
  255. break;
  256. // end escapes for palindrome support
  257. #endif // PALINDROME_SUPPORT
  258. default:
  259. DISPDBG((DEBUG_ERROR, "Querying unimplemented function"));
  260. RetVal = ESC_NOT_IMPLEMENTED;
  261. break;
  262. }
  263. break;
  264. /*
  265. * Switch into the specified DPMS state.
  266. */
  267. case ESC_SET_POWER_MANAGEMENT:
  268. DISPDBG((DEBUG_DETAIL, "Function ESC_SET_POWER_MANAGEMENT"));
  269. /*
  270. * The desired power management state is passed
  271. * in the ULONG passed in pvIn.
  272. */
  273. if(!pvIn)
  274. RetVal = ESC_NOT_IMPLEMENTED;
  275. break;
  276. switch (*(PULONG)pvIn)
  277. {
  278. case VideoPowerOn:
  279. DISPDBG((DEBUG_DETAIL, "State selected = ON"));
  280. RetVal = ESC_IS_SUPPORTED;
  281. break;
  282. case VideoPowerStandBy:
  283. DISPDBG((DEBUG_DETAIL, "State selected = STAND-BY"));
  284. RetVal = ESC_IS_SUPPORTED;
  285. break;
  286. case VideoPowerSuspend:
  287. DISPDBG((DEBUG_DETAIL, "State selected = SUSPEND"));
  288. RetVal = ESC_IS_SUPPORTED;
  289. break;
  290. case VideoPowerOff:
  291. DISPDBG((DEBUG_DETAIL, "State selected = OFF"));
  292. RetVal = ESC_IS_SUPPORTED;
  293. break;
  294. default:
  295. DISPDBG((DEBUG_ERROR, "Invalid state selected"));
  296. RetVal = ESC_NOT_SUPPORTED;
  297. break;
  298. }
  299. DpmsData.Length = sizeof(struct _VIDEO_POWER_MANAGEMENT);
  300. DpmsData.DPMSVersion = 0; /* Not used for "set" packet */
  301. DpmsData.PowerState = *(PULONG)pvIn;
  302. /*
  303. * Tell the miniport to set the DPMS mode. If the miniport
  304. * either doesn't support this packet, or reports that the
  305. * video card doesn't, tell the calling application that
  306. * we failed.
  307. */
  308. if (AtiDeviceIoControl( ppdev->hDriver,
  309. IOCTL_VIDEO_SET_POWER_MANAGEMENT,
  310. &DpmsData,
  311. sizeof (struct _VIDEO_POWER_MANAGEMENT),
  312. NULL,
  313. 0,
  314. &dwRet) == FALSE)
  315. {
  316. DISPDBG((DEBUG_ERROR, "Unable to set desired state"));
  317. RetVal = ESC_NOT_SUPPORTED;
  318. }
  319. break;
  320. #if (TARGET_BUILD == 351)
  321. case DCICOMMAND:
  322. pDciCmd = (DCICMD*) pvIn;
  323. if ((cjIn < sizeof(DCICMD)) || (pDciCmd->dwVersion != DCI_VERSION))
  324. {
  325. RetVal = (ULONG)DCI_FAIL_UNSUPPORTED;
  326. }
  327. else
  328. {
  329. switch(pDciCmd->dwCommand)
  330. {
  331. case DCICREATEPRIMARYSURFACE:
  332. RetVal = DCICreatePrimarySurface(ppdev, cjIn, pvIn, cjOut, pvOut);
  333. break;
  334. default:
  335. RetVal = (ULONG)DCI_FAIL_UNSUPPORTED;
  336. break;
  337. }
  338. }
  339. break;
  340. #endif
  341. /*
  342. * Unimplemented function requested.
  343. */
  344. default:
  345. DISPDBG((DEBUG_ERROR, "Unimplemented function requested"));
  346. RetVal = ESC_NOT_SUPPORTED;
  347. break;
  348. }
  349. DISPDBG((DEBUG_ENTRY_EXIT, "<-- DrvEscape"));
  350. return RetVal;
  351. } /* DrvEscape() */
  352.