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.

195 lines
5.8 KiB

  1. //
  2. // Module: DPMS.C
  3. // Date: Aug 08, 1997
  4. //
  5. // Copyright (c) 1997 by ATI Technologies Inc.
  6. //
  7. /********************** PolyTron RCS Utilities
  8. $Revision: 1.1 $
  9. $Date: 21 Aug 1997 15:01:36 $
  10. $Author: MACIESOW $
  11. $Log: V:\source\wnt\ms11\miniport\archive\dpms.c_v $
  12. *
  13. * Rev 1.1 21 Aug 1997 15:01:36 MACIESOW
  14. * Initial revision.
  15. End of PolyTron RCS section *****************/
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "dderror.h"
  19. #include "miniport.h"
  20. #include "ntddvdeo.h"
  21. #include "video.h"
  22. #include "stdtyp.h"
  23. #include "amach1.h"
  24. #include "amachcx.h"
  25. #include "atimp.h"
  26. #include "atint.h"
  27. #include "dpms.h"
  28. #include "init_m.h"
  29. #include "init_cx.h"
  30. //
  31. // Allow miniport to be swapped out when not needed.
  32. //
  33. #if defined (ALLOC_PRAGMA)
  34. #pragma alloc_text (PAGE_COM, SetMonitorPowerState)
  35. #pragma alloc_text (PAGE_COM, GetMonitorPowerState)
  36. #endif
  37. VP_STATUS
  38. SetMonitorPowerState(
  39. PHW_DEVICE_EXTENSION phwDeviceExtension,
  40. VIDEO_POWER_STATE VideoPowerState
  41. )
  42. //
  43. // DESCRIPTION:
  44. // Set the CRT output to the desired DPMS state under.
  45. //
  46. // PARAMETERS:
  47. // phwDeviceExtension Points to hardware device extension structure.
  48. // VideoPowerState Desired DPMS state.
  49. //
  50. // RETURN VALUE:
  51. // Status code, NO_ERROR = OK.
  52. //
  53. {
  54. ASSERT(phwDeviceExtension != NULL);
  55. VideoDebugPrint((DEBUG_DETAIL, "ATI.SYS SetMonitorPowerState: Setting power state to %lu\n", VideoPowerState));
  56. if ((VideoPowerState != VideoPowerOn) &&
  57. (VideoPowerState != VideoPowerStandBy) &&
  58. (VideoPowerState != VideoPowerSuspend) &&
  59. (VideoPowerState != VideoPowerOff))
  60. {
  61. VideoDebugPrint((DEBUG_DETAIL, "ATI.SYS SetMonitorPowerState: Invalid VideoPowerState\n"));
  62. return ERROR_INVALID_PARAMETER;
  63. }
  64. //
  65. // Different card families need different routines to set the power management state.
  66. //
  67. if (phwDeviceExtension->ModelNumber == MACH64_ULTRA)
  68. {
  69. VIDEO_X86_BIOS_ARGUMENTS Registers;
  70. //
  71. // Invoke the BIOS call to set the desired DPMS state. The BIOS call
  72. // enumeration of DPMS states is in the same order as that in
  73. // VIDEO_POWER_STATE, but it is zero-based instead of one-based.
  74. //
  75. VideoPortZeroMemory(&Registers, sizeof(VIDEO_X86_BIOS_ARGUMENTS));
  76. Registers.Eax = BIOS_SET_DPMS;
  77. Registers.Ecx = VideoPowerState - 1;
  78. VideoPortInt10(phwDeviceExtension, &Registers);
  79. return NO_ERROR;
  80. }
  81. else if((phwDeviceExtension->ModelNumber == _8514_ULTRA) ||
  82. (phwDeviceExtension->ModelNumber == GRAPHICS_ULTRA) ||
  83. (phwDeviceExtension->ModelNumber == MACH32_ULTRA))
  84. {
  85. struct query_structure * pQuery =
  86. (struct query_structure *) phwDeviceExtension->CardInfo;
  87. return SetPowerManagement_m(pQuery, VideoPowerState);
  88. }
  89. else
  90. {
  91. VideoDebugPrint((DEBUG_ERROR, "ATI.SYS SetMonitorPowerState: Invalid adapter type\n"));
  92. ASSERT(FALSE);
  93. return ERROR_INVALID_PARAMETER;
  94. }
  95. } // SetMonitorPowerState()
  96. VP_STATUS
  97. GetMonitorPowerState(
  98. PHW_DEVICE_EXTENSION phwDeviceExtension,
  99. PVIDEO_POWER_STATE pVideoPowerState
  100. )
  101. //
  102. // DESCRIPTION:
  103. // Retrieve the current CRT power state.
  104. //
  105. // PARAMETERS:
  106. // phwDeviceExtension Points to hardware device extension structure.
  107. // pVideoPowerStats Points to
  108. //
  109. // RETURN VALUE:
  110. // Error code on error.
  111. // NO_ERROR = OK, current power management state in pVideoPowerState.
  112. //
  113. // NOTE:
  114. // The enumerations VIDEO_DEVICE_POWER_MANAGEMENT (used by GetMonitorPowerState()) and VIDEO_POWER_MANAGEMENT
  115. // (used by this IOCTL) have opposite orderings (VIDEO_POWER_MANAGEMENT values increase as power consumption
  116. // decreases, while VIDEO_DEVICE_POWER_MANAGEMENT values increase as power consumption increases, and has
  117. // a reserved value for "state unknown"), so we can't simply add a constant to translate between them.
  118. //
  119. {
  120. VP_STATUS vpStatus;
  121. ASSERT(phwDeviceExtension != NULL && pVideoPowerState != NULL);
  122. //
  123. // Different card families need different routines to retrieve the power management state.
  124. //
  125. if (phwDeviceExtension->ModelNumber == MACH64_ULTRA)
  126. *pVideoPowerState = GetPowerManagement_cx(phwDeviceExtension);
  127. else
  128. *pVideoPowerState = GetPowerManagement_m(phwDeviceExtension);
  129. //
  130. // VIDEO_POWER_STATE has 5 possible states and a
  131. // reserved value to report that we can't read the state.
  132. // Our cards support 3 levels of monitor power-down in
  133. // addition to normal operation. Since the number of
  134. // values which can be reported exceeds the number
  135. // of states our cards can be in, we will never report
  136. // one of the possible states (VPPowerDeviceD3).
  137. //
  138. switch (*pVideoPowerState)
  139. {
  140. case VideoPowerOn:
  141. VideoDebugPrint((DEBUG_DETAIL, "ATI.SYS GetMonitorPowerState: Currently set to DPMS ON\n"));
  142. vpStatus = NO_ERROR;
  143. break;
  144. case VideoPowerStandBy:
  145. VideoDebugPrint((DEBUG_DETAIL, "ATI.SYS GetMonitorPowerState: Currently set to DPMS STAND-BY\n"));
  146. vpStatus = NO_ERROR;
  147. break;
  148. case VideoPowerSuspend:
  149. VideoDebugPrint((DEBUG_DETAIL, "ATI.SYS GetMonitorPowerState: Currently set to DPMS SUSPEND\n"));
  150. vpStatus = NO_ERROR;
  151. break;
  152. case VideoPowerOff:
  153. VideoDebugPrint((DEBUG_DETAIL, "ATI.SYS GetMonitorPowerState: Currently set to DPMS OFF\n"));
  154. vpStatus = NO_ERROR;
  155. break;
  156. default:
  157. VideoDebugPrint((DEBUG_ERROR, "ATI.SYS GetMonitorPowerState: Currently set to invalid DPMS state\n"));
  158. *pVideoPowerState = VideoPowerOn;
  159. vpStatus = ERROR_INVALID_PARAMETER;
  160. break;
  161. }
  162. return vpStatus;
  163. } // GetMonitorPowerState()