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.

570 lines
15 KiB

  1. /*--------------------------------------------------------------------------
  2. *
  3. * Copyright (C) Cyclades Corporation, 2000-2001.
  4. * All rights reserved.
  5. *
  6. * Cyclades-Z Enumerator Driver
  7. *
  8. * This file: cyclad-z.h
  9. *
  10. * Description: This module contains the common private declarations
  11. * for the cyzport enumerator.
  12. *
  13. * Notes: This code supports Windows 2000 and Windows XP,
  14. * x86 and ia64 processors.
  15. *
  16. * Complies with Cyclades SW Coding Standard rev 1.3.
  17. *
  18. *--------------------------------------------------------------------------
  19. */
  20. /*-------------------------------------------------------------------------
  21. *
  22. * Change History
  23. *
  24. *--------------------------------------------------------------------------
  25. * Initial implementation based on Microsoft sample code.
  26. *
  27. *--------------------------------------------------------------------------
  28. */
  29. #ifndef CYCLADZ_H
  30. #define CYCLADZ_H
  31. #include "cyzhw.h"
  32. #define DEVICE_OBJECT_NAME_LENGTH 128 // Copied from serial.h
  33. #define CYZ_PDO_NAME_BASE L"\\Cyz\\"
  34. #define CYCLADZ_POOL_TAG (ULONG)'ZcyC'
  35. #undef ExAllocatePool
  36. #define ExAllocatePool(type, size) \
  37. ExAllocatePoolWithTag(type, size, CYCLADZ_POOL_TAG)
  38. #pragma warning(error:4100) // Unreferenced formal parameter
  39. #pragma warning(error:4705) // Statement has no effect
  40. //
  41. // Debugging Output Levels
  42. //
  43. #define SER_DBG_STARTUP_SHUTDOWN_MASK 0x0000000F
  44. #define SER_DBG_SS_NOISE 0x00000001
  45. #define SER_DBG_SS_TRACE 0x00000002
  46. #define SER_DBG_SS_INFO 0x00000004
  47. #define SER_DBG_SS_ERROR 0x00000008
  48. #define SER_DBG_PNP_MASK 0x000000F0
  49. #define SER_DBG_PNP_NOISE 0x00000010
  50. #define SER_DBG_PNP_TRACE 0x00000020
  51. #define SER_DBG_PNP_INFO 0x00000040
  52. #define SER_DBG_PNP_ERROR 0x00000080
  53. #define SER_DBG_PNP_DUMP_PACKET 0x00000100
  54. #define SER_DBG_IOCTL_TRACE 0x00000200
  55. #define SER_DBG_POWER_TRACE 0x00000400
  56. #define SER_DBG_CYCLADES 0x00000800
  57. #define SER_DEFAULT_DEBUG_OUTPUT_LEVEL 0x00000000
  58. //#define SER_DEFAULT_DEBUG_OUTPUT_LEVEL 0xFFFFFFFF
  59. #if DBG
  60. #define Cycladz_KdPrint(_d_,_l_, _x_) \
  61. if ((_d_)->DebugLevel & (_l_)) { \
  62. DbgPrint ("Cyclad-z: "); \
  63. DbgPrint _x_; \
  64. }
  65. #define Cycladz_KdPrint_Cont(_d_,_l_, _x_) \
  66. if ((_d_)->DebugLevel & (_l_)) { \
  67. DbgPrint _x_; \
  68. }
  69. #define Cycladz_KdPrint_Def(_l_, _x_) \
  70. if (SER_DEFAULT_DEBUG_OUTPUT_LEVEL & (_l_)) { \
  71. DbgPrint ("Cyclad-z: "); \
  72. DbgPrint _x_; \
  73. }
  74. #define TRAP() DbgBreakPoint()
  75. #define DbgRaiseIrql(_x_,_y_) KeRaiseIrql(_x_,_y_)
  76. #define DbgLowerIrql(_x_) KeLowerIrql(_x_)
  77. #else
  78. #define Cycladz_KdPrint(_d_, _l_, _x_)
  79. #define Cycladz_KdPrint_Cont(_d_, _l_, _x_)
  80. #define Cycladz_KdPrint_Def(_l_, _x_)
  81. #define TRAP()
  82. #define DbgRaiseIrql(_x_,_y_)
  83. #define DbgLowerIrql(_x_)
  84. #endif
  85. #if !defined(MIN)
  86. #define MIN(_A_,_B_) (((_A_) < (_B_)) ? (_A_) : (_B_))
  87. #endif
  88. typedef struct _WORKER_THREAD_CONTEXT
  89. {
  90. PDEVICE_OBJECT DeviceObject;
  91. PIRP Irp;
  92. PIO_WORKITEM WorkItem;
  93. POWER_STATE PowerState;
  94. POWER_STATE_TYPE PowerType;
  95. } WORKER_THREAD_CONTEXT, *PWORKER_THREAD_CONTEXT;
  96. //
  97. // These are the states a PDO or FDO transition upon
  98. // receiving a specific PnP Irp. Refer to the PnP Device States
  99. // diagram in DDK documentation for better understanding.
  100. //
  101. typedef enum _DEVICE_PNP_STATE {
  102. NotStarted = 0, // Not started yet
  103. Started, // Device has received the START_DEVICE IRP
  104. StopPending, // Device has received the QUERY_STOP IRP
  105. Stopped, // Device has received the STOP_DEVICE IRP
  106. RemovePending, // Device has received the QUERY_REMOVE IRP
  107. SurpriseRemovePending, // Device has received the SURPRISE_REMOVE IRP
  108. Deleted, // Device has received the REMOVE_DEVICE IRP
  109. UnKnown // Unknown state
  110. } DEVICE_PNP_STATE;
  111. //
  112. // A common header for the device extensions of the PDOs and FDO
  113. //
  114. typedef struct _COMMON_DEVICE_DATA
  115. {
  116. PDEVICE_OBJECT Self;
  117. // A backpointer to the device object for which this is the extension
  118. BOOLEAN IsFDO;
  119. // BOOLEAN Removed; // Added in build 2072
  120. // Has this device been removed? Should we fail any requests?
  121. // We track the state of the device with every PnP Irp
  122. // that affects the device through these two variables.
  123. DEVICE_PNP_STATE DevicePnPState;
  124. DEVICE_PNP_STATE PreviousPnPState;
  125. ULONG DebugLevel;
  126. SYSTEM_POWER_STATE SystemState;
  127. DEVICE_POWER_STATE DeviceState;
  128. } COMMON_DEVICE_DATA, *PCOMMON_DEVICE_DATA;
  129. //
  130. // The device extension for the PDOs.
  131. // That is the serial ports of which this bus driver enumerates.
  132. // (IE there is a PDO for the 201 serial port).
  133. //
  134. typedef struct _PDO_DEVICE_DATA
  135. {
  136. COMMON_DEVICE_DATA;
  137. PDEVICE_OBJECT ParentFdo;
  138. // A back pointer to the bus
  139. UNICODE_STRING HardwareIDs;
  140. // Either in the form of bus\device
  141. // or *PNPXXXX - meaning root enumerated
  142. UNICODE_STRING CompIDs;
  143. // compatible ids to the hardware id
  144. UNICODE_STRING DeviceIDs;
  145. // Format: bus\device
  146. UNICODE_STRING InstanceIDs;
  147. //
  148. // Text describing device
  149. //
  150. UNICODE_STRING DevDesc;
  151. BOOLEAN Attached;
  152. // BOOLEAN Removed; -> Removed in build 2072
  153. // When a device (PDO) is found on a bus and presented as a device relation
  154. // to the PlugPlay system, Attached is set to TRUE, and Removed to FALSE.
  155. // When the bus driver determines that this PDO is no longer valid, because
  156. // the device has gone away, it informs the PlugPlay system of the new
  157. // device relastions, but it does not delete the device object at that time.
  158. // The PDO is deleted only when the PlugPlay system has sent a remove IRP,
  159. // and there is no longer a device on the bus.
  160. //
  161. // If the PlugPlay system sends a remove IRP then the Removed field is set
  162. // to true, and all client (non PlugPlay system) accesses are failed.
  163. // If the device is removed from the bus Attached is set to FALSE.
  164. //
  165. // During a query relations Irp Minor call, only the PDOs that are
  166. // attached to the bus (and all that are attached to the bus) are returned
  167. // (even if they have been removed).
  168. //
  169. // During a remove device Irp Minor call, if and only if, attached is set
  170. // to FALSE, the PDO is deleted.
  171. //
  172. // The child devices will have to know which PortIndex they are.
  173. ULONG PortIndex;
  174. } PDO_DEVICE_DATA, *PPDO_DEVICE_DATA;
  175. //
  176. // The device extension of the bus itself. From whence the PDO's are born.
  177. //
  178. typedef struct _FDO_DEVICE_DATA
  179. {
  180. COMMON_DEVICE_DATA;
  181. PDRIVER_OBJECT DriverObject;
  182. UCHAR PdoIndex;
  183. // A number to keep track of the Pdo we're allocating.
  184. // Increment every time we create a new PDO. It's ok that it wraps.
  185. ULONG NumPDOs;
  186. // The PDOs currently enumerated.
  187. PDEVICE_OBJECT AttachedPDO[CYZ_MAX_PORTS];
  188. PPDO_DEVICE_DATA PdoData[CYZ_MAX_PORTS];
  189. PDEVICE_OBJECT UnderlyingPDO;
  190. PDEVICE_OBJECT TopOfStack;
  191. // the underlying bus PDO and the actual device object to which our
  192. // FDO is attached
  193. ULONG OutstandingIO;
  194. // the number of IRPs sent from the bus to the underlying device object
  195. KEVENT RemoveEvent;
  196. // On remove device plugplay request we must wait until all outstanding
  197. // requests have been completed before we can actually delete the device
  198. // object.
  199. UNICODE_STRING DevClassAssocName;
  200. // The name returned from IoRegisterDeviceClass Association,
  201. // which is used as a handle for IoSetDev... and friends.
  202. SYSTEM_POWER_STATE SystemWake;
  203. DEVICE_POWER_STATE DeviceWake;
  204. #ifndef POLL
  205. //
  206. // We keep the following values around so that we can connect
  207. // to the interrupt and report resources after the configuration
  208. // record is gone.
  209. //
  210. //
  211. // Translated vector
  212. //
  213. ULONG Vector;
  214. //
  215. // Translated Irql
  216. //
  217. KIRQL Irql;
  218. //
  219. // Untranslated vector
  220. //
  221. ULONG OriginalVector;
  222. //
  223. // Untranslated irql
  224. //
  225. ULONG OriginalIrql;
  226. #endif
  227. //
  228. // Bus number
  229. //
  230. ULONG BusNumber;
  231. //
  232. // Interface type
  233. //
  234. INTERFACE_TYPE InterfaceType;
  235. //
  236. // Cycladez-Z hardware
  237. //
  238. PHYSICAL_ADDRESS PhysicalRuntime;
  239. PHYSICAL_ADDRESS TranslatedRuntime;
  240. ULONG RuntimeLength;
  241. PHYSICAL_ADDRESS PhysicalBoardMemory;
  242. PHYSICAL_ADDRESS TranslatedBoardMemory;
  243. ULONG BoardMemoryLength;
  244. PUCHAR BoardMemory;
  245. struct RUNTIME_9060 *Runtime;
  246. ULONG IsPci;
  247. ULONG NumPorts;
  248. ULONG FirmwareVersion;
  249. // We are passing the resources privatly to our children so that Device Manager will not
  250. // complain about resource conflict between children.
  251. PIO_RESOURCE_REQUIREMENTS_LIST PChildRequiredList;
  252. PCM_RESOURCE_LIST PChildResourceList;
  253. ULONG PChildResourceListSize;
  254. PCM_RESOURCE_LIST PChildResourceListTr;
  255. ULONG PChildResourceListSizeTr;
  256. ULONG UINumber;
  257. } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
  258. //
  259. // Macros
  260. //
  261. #define INITIALIZE_PNP_STATE(_Data_) \
  262. (_Data_)->DevicePnPState = NotStarted;\
  263. (_Data_)->PreviousPnPState = NotStarted;
  264. #define SET_NEW_PNP_STATE(_Data_, _state_) \
  265. (_Data_)->PreviousPnPState = (_Data_)->DevicePnPState;\
  266. (_Data_)->DevicePnPState = (_state_);
  267. #define RESTORE_PREVIOUS_PNP_STATE(_Data_) \
  268. (_Data_)->DevicePnPState = (_Data_)->PreviousPnPState;\
  269. //
  270. // Free the buffer associated with a Unicode string
  271. // and re-init it to NULL
  272. //
  273. #define CycladzFreeUnicodeString(PStr) \
  274. { \
  275. if ((PStr)->Buffer != NULL) { \
  276. ExFreePool((PStr)->Buffer); \
  277. } \
  278. RtlInitUnicodeString((PStr), NULL); \
  279. }
  280. //
  281. // Prototypes
  282. //
  283. NTSTATUS
  284. Cycladz_CreateClose (
  285. IN PDEVICE_OBJECT DeviceObject,
  286. IN PIRP Irp
  287. );
  288. NTSTATUS
  289. Cycladz_IoCtl (
  290. IN PDEVICE_OBJECT DeviceObject,
  291. IN PIRP Irp
  292. );
  293. NTSTATUS
  294. Cycladz_InternIoCtl (
  295. IN PDEVICE_OBJECT DeviceObject,
  296. IN PIRP Irp
  297. );
  298. VOID
  299. Cycladz_DriverUnload (
  300. IN PDRIVER_OBJECT DriverObject
  301. );
  302. NTSTATUS
  303. Cycladz_PnP (
  304. IN PDEVICE_OBJECT DeviceObject,
  305. IN PIRP Irp
  306. );
  307. NTSTATUS
  308. Cycladz_Power (
  309. IN PDEVICE_OBJECT DeviceObject,
  310. IN PIRP Irp
  311. );
  312. NTSTATUS
  313. Cycladz_AddDevice(
  314. IN PDRIVER_OBJECT DriverObject,
  315. IN PDEVICE_OBJECT BusDeviceObject
  316. );
  317. NTSTATUS
  318. Cycladz_PnPRemove (
  319. PDEVICE_OBJECT Device,
  320. PPDO_DEVICE_DATA PdoData
  321. );
  322. NTSTATUS
  323. Cycladz_FDO_PnP (
  324. IN PDEVICE_OBJECT DeviceObject,
  325. IN PIRP Irp,
  326. IN PIO_STACK_LOCATION IrpStack,
  327. IN PFDO_DEVICE_DATA DeviceData
  328. );
  329. NTSTATUS
  330. Cycladz_PDO_PnP (
  331. IN PDEVICE_OBJECT DeviceObject,
  332. IN PIRP Irp,
  333. IN PIO_STACK_LOCATION IrpStack,
  334. IN PPDO_DEVICE_DATA DeviceData
  335. );
  336. NTSTATUS
  337. Cycladz_IncIoCount (
  338. PFDO_DEVICE_DATA Data
  339. );
  340. VOID
  341. Cycladz_DecIoCount (
  342. PFDO_DEVICE_DATA Data
  343. );
  344. NTSTATUS
  345. Cycladz_DispatchPassThrough(
  346. IN PDEVICE_OBJECT DeviceObject,
  347. IN PIRP Irp
  348. );
  349. NTSTATUS
  350. Cycladz_ReenumerateDevices(
  351. IN PIRP Irp,
  352. IN PFDO_DEVICE_DATA DeviceData
  353. );
  354. NTSTATUS
  355. Cycladz_InitMultiString(PFDO_DEVICE_DATA FdoData, PUNICODE_STRING MultiString,
  356. ...);
  357. void
  358. Cycladz_PDO_EnumMarkMissing(
  359. PFDO_DEVICE_DATA FdoData,
  360. PPDO_DEVICE_DATA PdoData);
  361. NTSTATUS
  362. Cycladz_GetRegistryKeyValue (
  363. IN HANDLE Handle,
  364. IN PWCHAR KeyNameString,
  365. IN ULONG KeyNameStringLength,
  366. IN PVOID Data,
  367. IN ULONG DataLength,
  368. OUT PULONG ActualLength);
  369. void
  370. Cycladz_InitPDO (
  371. ULONG index,
  372. PDEVICE_OBJECT pdoData,
  373. PFDO_DEVICE_DATA fdoData
  374. );
  375. NTSTATUS
  376. CycladzSyncCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
  377. IN PKEVENT CycladzSyncEvent);
  378. NTSTATUS
  379. Cycladz_GetResourceInfo(IN PDEVICE_OBJECT PDevObj,
  380. IN PCM_RESOURCE_LIST PResList,
  381. IN PCM_RESOURCE_LIST PTrResList);
  382. VOID
  383. Cycladz_ReleaseResources(IN PFDO_DEVICE_DATA PDevExt);
  384. NTSTATUS
  385. Cycladz_GotoPowerState(IN PDEVICE_OBJECT PDevObj,
  386. IN PFDO_DEVICE_DATA PDevExt,
  387. IN DEVICE_POWER_STATE DevPowerState);
  388. NTSTATUS
  389. Cycladz_SystemPowerCompletion(IN PDEVICE_OBJECT PDevObj, UCHAR MinorFunction,
  390. IN POWER_STATE PowerState, IN PVOID Context,
  391. PIO_STATUS_BLOCK IoStatus);
  392. NTSTATUS
  393. Cycladz_ItemCallBack(
  394. IN PVOID Context,
  395. IN PUNICODE_STRING PathName,
  396. IN INTERFACE_TYPE BusType,
  397. IN ULONG BusNumber,
  398. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  399. IN CONFIGURATION_TYPE ControllerType,
  400. IN ULONG ControllerNumber,
  401. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  402. IN CONFIGURATION_TYPE PeripheralType,
  403. IN ULONG PeripheralNumber,
  404. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  405. );
  406. NTSTATUS
  407. Cycladz_BuildRequirementsList(
  408. OUT PIO_RESOURCE_REQUIREMENTS_LIST *PChildRequiredList_Pointer,
  409. IN PCM_RESOURCE_LIST PResourceList, IN ULONG NumberOfResources
  410. );
  411. NTSTATUS
  412. Cycladz_BuildResourceList(
  413. OUT PCM_RESOURCE_LIST *POutList_Pointer,
  414. OUT ULONG *ListSize_Pointer,
  415. IN PCM_RESOURCE_LIST PInList,
  416. IN ULONG NumberOfResources
  417. );
  418. VOID
  419. Cycladz_Delay(
  420. ULONG NumberOfMilliseconds
  421. );
  422. ULONG
  423. Cycladz_DoesBoardExist(
  424. IN PFDO_DEVICE_DATA Extension
  425. );
  426. VOID
  427. CyzLogError(
  428. IN PDRIVER_OBJECT DriverObject,
  429. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  430. IN PHYSICAL_ADDRESS P1,
  431. IN PHYSICAL_ADDRESS P2,
  432. IN ULONG SequenceNumber,
  433. IN UCHAR MajorFunctionCode,
  434. IN UCHAR RetryCount,
  435. IN ULONG UniqueErrorValue,
  436. IN NTSTATUS FinalStatus,
  437. IN NTSTATUS SpecificIOStatus,
  438. IN ULONG LengthOfInsert1,
  439. IN PWCHAR Insert1,
  440. IN ULONG LengthOfInsert2,
  441. IN PWCHAR Insert2
  442. );
  443. PCHAR
  444. PnPMinorFunctionString (
  445. UCHAR MinorFunction
  446. );
  447. #endif // endef CYCLADZ_H