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.

455 lines
11 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. GAMEENUM.H
  5. Abstract:
  6. This module contains the common private declarations for the game port
  7. enumerator.
  8. @@BEGIN_DDKSPLIT
  9. Author:
  10. Kenneth Ray
  11. @@END_DDKSPLIT
  12. Environment:
  13. kernel mode only
  14. Notes:
  15. Revision History:
  16. --*/
  17. #ifndef GAMEENUM_H
  18. #define GAMEENUM_H
  19. #define GAMEENUM_COMPATIBLE_IDS L"GamePort\\GameDevice\0\0"
  20. #define GAMEENUM_COMPATIBLE_IDS_LENGTH 21 // NB wide characters.
  21. #define GAMEENUM_UNIQUEID_START (-1)
  22. #define GAMEENUM_POOL_TAG (ULONG) 'emaG'
  23. #undef ExAllocatePool
  24. #define ExAllocatePool(type, size) \
  25. ExAllocatePoolWithTag (type, size, GAMEENUM_POOL_TAG)
  26. #pragma warning(error:4100) // Unreferenced formal parameter
  27. #pragma warning(error:4705) // Statement has no effect
  28. //
  29. // Debugging Output Levels
  30. //
  31. #define GAME_DBG_ALWAYS 0x00000000
  32. #define GAME_DBG_STARTUP_SHUTDOWN_MASK 0x0000000F
  33. #define GAME_DBG_SS_NOISE 0x00000001
  34. #define GAME_DBG_SS_TRACE 0x00000002
  35. #define GAME_DBG_SS_INFO 0x00000004
  36. #define GAME_DBG_SS_ERROR 0x00000008
  37. #define GAME_DBG_PNP_MASK 0x000000F0
  38. #define GAME_DBG_PNP_NOISE 0x00000010
  39. #define GAME_DBG_PNP_TRACE 0x00000020
  40. #define GAME_DBG_PNP_INFO 0x00000040
  41. #define GAME_DBG_PNP_ERROR 0x00000080
  42. #define GAME_DBG_IOCTL_MASK 0x00000F00
  43. #define GAME_DBG_IOCTL_NOISE 0x00000100
  44. #define GAME_DBG_IOCTL_TRACE 0x00000200
  45. #define GAME_DBG_IOCTL_INFO 0x00000400
  46. #define GAME_DBG_IOCTL_ERROR 0x00000800
  47. #define GAME_DBG_ACQUIRE_ERROR 0x00001000
  48. #define GAME_DBG_ACQUIRE_NOISE 0x00002000
  49. #define GAME_DBG_RELEASE_ERROR 0x00004000
  50. #define GAME_DBG_RELEASE_NOISE 0x00008000
  51. #if DBG
  52. extern ULONG GameEnumDebugLevel;
  53. #define GAME_DEFAULT_DEBUG_OUTPUT_LEVEL 0x00005888
  54. #define Game_KdPrint(_d_,_l_, _x_) \
  55. if (!(_l_) || (_d_)->DebugLevel & (_l_)) { \
  56. DbgPrint ("GameEnum.SYS: "); \
  57. DbgPrint _x_; \
  58. }
  59. #define Game_KdPrint_Cont(_d_,_l_, _x_) \
  60. if (!(_l_) || (_d_)->DebugLevel & (_l_)) { \
  61. DbgPrint _x_; \
  62. }
  63. #define Game_KdPrint_Def(_l_, _x_) \
  64. if (!(_l_) || GameEnumDebugLevel & (_l_)) { \
  65. DbgPrint ("GameEnum.SYS: "); \
  66. DbgPrint _x_; \
  67. }
  68. #define TRAP() DbgBreakPoint()
  69. #define DbgRaiseIrql(_x_,_y_) KeRaiseIrql(_x_,_y_)
  70. #define DbgLowerIrql(_x_) KeLowerIrql(_x_)
  71. #else
  72. #define GAME_DEFAULT_DEBUG_OUTPUT_LEVEL 0x0
  73. #define Game_KdPrint(_d_, _l_, _x_)
  74. #define Game_KdPrint_Cont(_d_, _l_, _x_)
  75. #define Game_KdPrint_Def(_l_, _x_)
  76. #define TRAP()
  77. #define DbgRaiseIrql(_x_,_y_)
  78. #define DbgLowerIrql(_x_)
  79. #endif
  80. //
  81. // A common header for the device extensions of the PDOs and FDO
  82. //
  83. typedef struct _COMMON_DEVICE_DATA
  84. {
  85. PDEVICE_OBJECT Self;
  86. // A backpointer to the device object for which this is the extension
  87. CHAR Reserved[2];
  88. BOOLEAN SurpriseRemoved;
  89. BOOLEAN IsFDO;
  90. // A boolean to distringuish between PDO and FDO.
  91. ULONG DebugLevel;
  92. GAMEENUM_OEM_DATA OemData;
  93. USHORT UnitID;
  94. USHORT _Unused;
  95. // user supplied data
  96. SYSTEM_POWER_STATE SystemState;
  97. DEVICE_POWER_STATE DeviceState;
  98. } COMMON_DEVICE_DATA, *PCOMMON_DEVICE_DATA;
  99. //
  100. // The device extension for the PDOs.
  101. // That is the game ports of which this bus driver enumerates.
  102. //
  103. typedef struct _PDO_DEVICE_DATA
  104. {
  105. COMMON_DEVICE_DATA;
  106. PDEVICE_OBJECT ParrentFdo;
  107. // A back pointer to the bus
  108. PWCHAR HardwareIDs;
  109. // An array of (zero terminated wide character strings).
  110. // The array itself also null terminated
  111. ULONG UniqueID;
  112. // Globally unique id in the system
  113. BOOLEAN AnalogCompatible;
  114. // TRUE if the device can be supported by the analog joystick driver
  115. BOOLEAN Started;
  116. BOOLEAN Attached;
  117. BOOLEAN Removed;
  118. // When a device (PDO) is found on a bus and presented as a device relation
  119. // to the PlugPlay system, Attached is set to TRUE, and Removed to FALSE.
  120. // When the bus driver determines that this PDO is no longer valid, because
  121. // the device has gone away, it informs the PlugPlay system of the new
  122. // device relastions, but it does not delete the device object at that time.
  123. // The PDO is deleted only when the PlugPlay system has sent a remove IRP,
  124. // and there is no longer a device on the bus.
  125. //
  126. // If the PlugPlay system sends a remove IRP then the Removed field is set
  127. // to true, and all client (non PlugPlay system) accesses are failed.
  128. // If the device is removed from the bus Attached is set to FALSE.
  129. //
  130. // Durring a query relations Irp Minor call, only the PDOs that are
  131. // attached to the bus (and all that are attached to the bus) are returned
  132. // (even if they have been removed).
  133. //
  134. // Durring a remove device Irp Minor call, if and only if, attached is set
  135. // to FALSE, the PDO is deleted.
  136. //
  137. // For legacy joysticks only
  138. USHORT NumberAxis;
  139. USHORT NumberButtons;
  140. GAMEENUM_PORTION Portion;
  141. LIST_ENTRY Link;
  142. // the link point to hold all the PDOs for a single bus together
  143. } PDO_DEVICE_DATA, *PPDO_DEVICE_DATA;
  144. //
  145. // The device extension of the bus itself. From whence the PDO's are born.
  146. //
  147. typedef struct _FDO_DEVICE_DATA
  148. {
  149. COMMON_DEVICE_DATA;
  150. BOOLEAN MappedPorts;
  151. // Were the ports mapped with MmMapIoSpace?
  152. BOOLEAN PowerQueryLock;
  153. // Are we currently in a query power state?
  154. BOOLEAN Started;
  155. // Are we on, have resources, etc?
  156. BOOLEAN Removed;
  157. // Has this device been removed? Should we fail any requests?
  158. PDEVICE_OBJECT UnderlyingPDO;
  159. PDEVICE_OBJECT TopOfStack;
  160. // the underlying bus PDO and the actual device object to which our
  161. // FDO is attached
  162. LIST_ENTRY PDOs;
  163. ULONG NumPDOs;
  164. // The PDOs currently enumerated.
  165. FAST_MUTEX Mutex;
  166. // A syncronization for access to the device extension.
  167. ULONG OutstandingIO;
  168. // the number of IRPs sent from the bus to the underlying device object
  169. // can't use NT RtlRemoveLocks b/c win 9x does not have them
  170. KEVENT RemoveEvent;
  171. // On remove device plugplay request we must wait until all outstanding
  172. // requests have been completed before we can actually delete the device
  173. // object.
  174. UNICODE_STRING DevClassAssocName;
  175. // The name returned from IoRegisterDeviceClass Association,
  176. // which is used as a handle for IoSetDev... and friends.
  177. PHYSICAL_ADDRESS PhysicalAddress;
  178. PGAMEENUM_READPORT ReadPort;
  179. PGAMEENUM_WRITEPORT WritePort;
  180. PVOID GamePortAddress;
  181. ULONG GamePortAddressLength;
  182. //
  183. // If there is a bus lower filter these will be used after sanity checks
  184. //
  185. PVOID LowerPortContext;
  186. PGAMEENUM_ACQUIRE_PORT LowerAcquirePort;
  187. PGAMEENUM_RELEASE_PORT LowerReleasePort;
  188. LONG UniqueIDCount;
  189. KEVENT PoweredDownEvent;
  190. LONG PoweredDownDevices;
  191. LONG Acquired;
  192. } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
  193. #define FDO_FROM_PDO(pdoData) ((PFDO_DEVICE_DATA) (pdoData)->ParrentFdo->DeviceExtension)
  194. //
  195. // Prototypes
  196. //
  197. NTSTATUS
  198. Game_CreateClose (
  199. IN PDEVICE_OBJECT DeviceObject,
  200. IN PIRP Irp
  201. );
  202. NTSTATUS
  203. Game_IoCtl (
  204. IN PDEVICE_OBJECT DeviceObject,
  205. IN PIRP Irp
  206. );
  207. NTSTATUS
  208. Game_InternIoCtl (
  209. IN PDEVICE_OBJECT DeviceObject,
  210. IN PIRP Irp
  211. );
  212. NTSTATUS
  213. Game_SystemControl (
  214. IN PDEVICE_OBJECT DeviceObject,
  215. IN PIRP Irp
  216. );
  217. VOID
  218. Game_DriverUnload (
  219. IN PDRIVER_OBJECT DriverObject
  220. );
  221. NTSTATUS
  222. Game_CompletionRoutine (
  223. IN PDEVICE_OBJECT DeviceObject,
  224. IN PIRP Pirp,
  225. IN PVOID Context
  226. );
  227. NTSTATUS
  228. Game_SendIrpSynchronously (
  229. IN PDEVICE_OBJECT DeviceObject,
  230. IN PIRP Irp,
  231. IN BOOLEAN NotImplementedIsValid,
  232. IN BOOLEAN CopyToNext
  233. );
  234. NTSTATUS
  235. Game_PnP (
  236. IN PDEVICE_OBJECT DeviceObject,
  237. IN PIRP Irp
  238. );
  239. NTSTATUS
  240. Game_Power (
  241. IN PDEVICE_OBJECT DeviceObject,
  242. IN PIRP Irp
  243. );
  244. NTSTATUS
  245. Game_AddDevice(
  246. IN PDRIVER_OBJECT DriverObject,
  247. IN PDEVICE_OBJECT BusDeviceObject
  248. );
  249. VOID
  250. Game_InitializePdo (
  251. PDEVICE_OBJECT Pdo,
  252. PFDO_DEVICE_DATA FdoData
  253. );
  254. NTSTATUS
  255. Game_CheckHardwareIDs (
  256. PWCHAR pwszTestId,
  257. PULONG puLenLimit,
  258. PFDO_DEVICE_DATA FdoData
  259. );
  260. NTSTATUS
  261. Game_Expose (
  262. PGAMEENUM_EXPOSE_HARDWARE Expose,
  263. ULONG ExposeLength,
  264. PFDO_DEVICE_DATA DeviceData
  265. );
  266. NTSTATUS
  267. Game_ExposeSibling (
  268. PGAMEENUM_EXPOSE_SIBLING ExposeSibling,
  269. PPDO_DEVICE_DATA SiblingPdo
  270. );
  271. NTSTATUS
  272. Game_Remove (
  273. PGAMEENUM_REMOVE_HARDWARE Remove,
  274. PFDO_DEVICE_DATA DeviceData
  275. );
  276. NTSTATUS
  277. Game_RemoveSelf (
  278. PPDO_DEVICE_DATA DeviceData
  279. );
  280. NTSTATUS
  281. Game_RemoveEx (
  282. PDEVICE_OBJECT RemoveDO,
  283. PFDO_DEVICE_DATA DeviceData
  284. );
  285. void
  286. Game_RemoveFdo (
  287. PFDO_DEVICE_DATA FdoData
  288. );
  289. NTSTATUS
  290. Game_RemovePdo (
  291. PDEVICE_OBJECT Device,
  292. PPDO_DEVICE_DATA PdoData
  293. );
  294. NTSTATUS
  295. Game_ListPorts (
  296. PGAMEENUM_PORT_DESC Desc,
  297. PFDO_DEVICE_DATA DeviceData
  298. );
  299. NTSTATUS
  300. Game_PortParameters (
  301. PGAMEENUM_PORT_PARAMETERS Parameters,
  302. PPDO_DEVICE_DATA PdoDeviceData
  303. );
  304. NTSTATUS
  305. Game_FDO_PnP (
  306. IN PDEVICE_OBJECT DeviceObject,
  307. IN PIRP Irp,
  308. IN PIO_STACK_LOCATION IrpStack,
  309. IN PFDO_DEVICE_DATA DeviceData
  310. );
  311. NTSTATUS
  312. Game_PDO_PnP (
  313. IN PDEVICE_OBJECT DeviceObject,
  314. IN PIRP Irp,
  315. IN PIO_STACK_LOCATION IrpStack,
  316. IN PPDO_DEVICE_DATA DeviceData
  317. );
  318. NTSTATUS
  319. Game_StartFdo (
  320. IN PFDO_DEVICE_DATA FdoData,
  321. IN PCM_PARTIAL_RESOURCE_LIST partialResourceList,
  322. IN PCM_PARTIAL_RESOURCE_LIST partialResourceListTranslated
  323. );
  324. NTSTATUS
  325. Game_IncIoCount (
  326. PFDO_DEVICE_DATA Data
  327. );
  328. VOID
  329. Game_DecIoCount (
  330. PFDO_DEVICE_DATA Data
  331. );
  332. NTSTATUS
  333. Game_FDO_Power (
  334. PFDO_DEVICE_DATA FdoData,
  335. PIRP Irp
  336. );
  337. NTSTATUS
  338. Game_PDO_Power (
  339. PPDO_DEVICE_DATA PdoData,
  340. PIRP Irp
  341. );
  342. NTSTATUS
  343. Game_AcquirePort (
  344. PFDO_DEVICE_DATA FdoData
  345. );
  346. VOID
  347. Game_ReleasePort (
  348. PFDO_DEVICE_DATA FdoData
  349. );
  350. #endif