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.

339 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. headless.c
  5. Abstract:
  6. This is the miniport driver for the hardware with no graphic adapter.
  7. Should work only with display driver for headless environment.
  8. Environment:
  9. kernel mode only
  10. Notes:
  11. --*/
  12. #include "dderror.h"
  13. #include "devioctl.h"
  14. #include "miniport.h"
  15. #include "ntddvdeo.h"
  16. #include "video.h"
  17. #include "headless.h"
  18. #if defined(ALLOC_PRAGMA)
  19. #pragma alloc_text(PAGE,DriverEntry)
  20. #pragma alloc_text(PAGE,HeadlessFindAdapter)
  21. #pragma alloc_text(PAGE,HeadlessInitialize)
  22. #pragma alloc_text(PAGE,HeadlessStartIO)
  23. #endif
  24. ULONG
  25. DriverEntry(
  26. PVOID Context1,
  27. PVOID Context2
  28. )
  29. /*++
  30. Routine Description:
  31. Installable driver initialization entry point.
  32. This entry point is called directly by the I/O system.
  33. Arguments:
  34. Context1 - First context value passed by the operating system. This is
  35. the value with which the miniport driver calls VideoPortInitialize().
  36. Context2 - Second context value passed by the operating system. This is
  37. the value with which the miniport driver calls VideoPortInitialize().
  38. Return Value:
  39. Status from VideoPortInitialize()
  40. --*/
  41. {
  42. VIDEO_HW_INITIALIZATION_DATA hwInitData;
  43. ULONG initializationStatus;
  44. //
  45. // Zero out structure.
  46. //
  47. VideoPortZeroMemory(&hwInitData, sizeof(VIDEO_HW_INITIALIZATION_DATA));
  48. hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);
  49. //
  50. // Set entry points.
  51. //
  52. hwInitData.HwFindAdapter = HeadlessFindAdapter;
  53. hwInitData.HwInitialize = HeadlessInitialize;
  54. hwInitData.HwStartIO = HeadlessStartIO;
  55. hwInitData.AdapterInterfaceType = PCIBus;
  56. initializationStatus = VideoPortInitialize(Context1,
  57. Context2,
  58. &hwInitData,
  59. NULL);
  60. return initializationStatus;
  61. }
  62. VP_STATUS
  63. HeadlessFindAdapter(
  64. PVOID HwDeviceExtension,
  65. PVOID HwContext,
  66. PWSTR ArgumentString,
  67. PVIDEO_PORT_CONFIG_INFO ConfigInfo,
  68. PUCHAR Again
  69. )
  70. /*++
  71. Routine Description:
  72. This routine is called to determine if the adapter for this driver
  73. is present in the system.
  74. If it is present, the function fills out some information describing
  75. the adapter.
  76. Arguments:
  77. HwDeviceExtension - Supplies the miniport driver's adapter storage. This
  78. storage is initialized to zero before this call.
  79. HwContext - Supplies the context value which was passed to
  80. VideoPortInitialize().
  81. ArgumentString - Supplies a NULL terminated ASCII string. This string
  82. originates from the user.
  83. ConfigInfo - Returns the configuration information structure which is
  84. filled by the miniport driver. This structure is initialized with
  85. any known configuration information (such as SystemIoBusNumber) by
  86. the port driver. Where possible, drivers should have one set of
  87. defaults which do not require any supplied configuration information.
  88. Again - Indicates if the miniport driver wants the port driver to call
  89. its VIDEO_HW_FIND_ADAPTER function again with a new device extension
  90. and the same config info. This is used by the miniport drivers which
  91. can search for several adapters on a bus.
  92. Return Value:
  93. This routine must return:
  94. NO_ERROR - Indicates a host adapter was found and the
  95. configuration information was successfully determined.
  96. ERROR_INVALID_PARAMETER - Indicates an adapter was found but there was an
  97. error obtaining the configuration information. If possible an error
  98. should be logged.
  99. ERROR_DEV_NOT_EXIST - Indicates no host adapter was found for the
  100. supplied configuration information.
  101. --*/
  102. {
  103. VP_STATUS status;
  104. PHYSICAL_ADDRESS Zero = { 0, 0 };
  105. VIDEO_PORT_HEADLESS_INTERFACE HeadlessInterface;
  106. VideoDebugPrint((2, "Headless - FindAdapter\n"));
  107. //
  108. // Make sure the size of the structure is at least as large as what we
  109. // are expecting (check version of the config info structure).
  110. //
  111. if (ConfigInfo->Length < sizeof(VIDEO_PORT_CONFIG_INFO)) {
  112. return ERROR_INVALID_PARAMETER;
  113. }
  114. //
  115. // We only want this driver to load if no other video miniports
  116. // loaded successfully.
  117. //
  118. HeadlessInterface.Size = sizeof(VIDEO_PORT_HEADLESS_INTERFACE);
  119. HeadlessInterface.Version = 1;
  120. status = VideoPortQueryServices(
  121. HwDeviceExtension,
  122. VideoPortServicesHeadless,
  123. (PINTERFACE)&HeadlessInterface);
  124. if (status == NO_ERROR) {
  125. ULONG DisplayDeviceCount;
  126. HeadlessInterface.InterfaceReference(HeadlessInterface.Context);
  127. DisplayDeviceCount =
  128. HeadlessInterface.HeadlessGetDeviceCount(HwDeviceExtension);
  129. HeadlessInterface.InterfaceDereference(HeadlessInterface.Context);
  130. if (DisplayDeviceCount != 0) {
  131. return ERROR_DEV_NOT_EXIST;
  132. }
  133. } else {
  134. return ERROR_INVALID_PARAMETER;
  135. }
  136. ConfigInfo->NumEmulatorAccessEntries = 0;
  137. ConfigInfo->EmulatorAccessEntries = NULL;
  138. ConfigInfo->EmulatorAccessEntriesContext = 0;
  139. ConfigInfo->VdmPhysicalVideoMemoryAddress = Zero;
  140. ConfigInfo->VdmPhysicalVideoMemoryLength = 0;
  141. //
  142. // Minimum size of the buffer required to store the hardware state
  143. // information returned by IOCTL_VIDEO_SAVE_HARDWARE_STATE.
  144. //
  145. ConfigInfo->HardwareStateSize = 0;
  146. //
  147. // Indicate we do not wish to be called again for another initialization.
  148. //
  149. *Again = 0;
  150. return NO_ERROR;
  151. }
  152. BOOLEAN
  153. HeadlessInitialize(
  154. PVOID HwDeviceExtension
  155. )
  156. /*++
  157. Routine Description:
  158. This routine does one time initialization of the device.
  159. Arguments:
  160. HwDeviceExtension - Pointer to the miniport driver's adapter information.
  161. Return Value:
  162. None.
  163. --*/
  164. {
  165. VideoDebugPrint((2, "Headless - Initialize\n"));
  166. return TRUE;
  167. }
  168. BOOLEAN
  169. HeadlessStartIO(
  170. PVOID HwDeviceExtension,
  171. PVIDEO_REQUEST_PACKET RequestPacket
  172. )
  173. /*++
  174. Routine Description:
  175. This routine is the main execution routine for the miniport driver. It
  176. acceptss a Video Request Packet, performs the request, and then returns
  177. with the appropriate status.
  178. Arguments:
  179. HwDeviceExtension - Pointer to the miniport driver's adapter information.
  180. RequestPacket - Pointer to the video request packet. This structure
  181. contains all the parameters passed to the VideoIoControl function.
  182. Return Value:
  183. This routine will return error codes from the various support routines
  184. and will also return ERROR_INSUFFICIENT_BUFFER for incorrectly sized
  185. buffers and ERROR_INVALID_FUNCTION for unsupported functions.
  186. --*/
  187. {
  188. VP_STATUS status;
  189. //
  190. // Switch on the IoContolCode in the RequestPacket. It indicates which
  191. // function must be performed by the driver.
  192. //
  193. switch (RequestPacket->IoControlCode) {
  194. case IOCTL_VIDEO_QUERY_AVAIL_MODES:
  195. VideoDebugPrint((2, "HeadlessStartIO - QueryAvailableModes\n"));
  196. status = HeadlessQueryAvailableModes(
  197. (PVIDEO_MODE_INFORMATION)RequestPacket->OutputBuffer,
  198. RequestPacket->OutputBufferLength,
  199. (PULONG)(&RequestPacket->StatusBlock->Information));
  200. break;
  201. case IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES:
  202. VideoDebugPrint((2, "HeadlessStartIO - QueryNumAvailableModes\n"));
  203. status = HeadlessQueryNumberOfAvailableModes(
  204. (PVIDEO_NUM_MODES) RequestPacket->OutputBuffer,
  205. RequestPacket->OutputBufferLength,
  206. (PULONG)(&RequestPacket->StatusBlock->Information));
  207. break;
  208. case IOCTL_VIDEO_RESET_DEVICE:
  209. VideoDebugPrint((2, "HeadlessStartIO - Got reset, perhaps for dummy device\n"));
  210. status = NO_ERROR;
  211. break;
  212. //
  213. // if we get here, an invalid IoControlCode was specified.
  214. //
  215. default:
  216. VideoDebugPrint((1, "Fell through headless startIO routine - invalid command 0x%08X\n", RequestPacket->IoControlCode));
  217. status = ERROR_INVALID_FUNCTION;
  218. break;
  219. }
  220. RequestPacket->StatusBlock->Status = status;
  221. return TRUE;
  222. }