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.

561 lines
15 KiB

  1. /*--------------------------------------------------------------------------
  2. *
  3. * Copyright (C) Cyclades Corporation, 1999-2001.
  4. * All rights reserved.
  5. *
  6. * Cyclom-Y Enumerator Driver
  7. *
  8. * This file: cyclom-y.h
  9. *
  10. * Description: This module contains the common private declarations
  11. * for the cyyport 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 CYCLOMY_H
  30. #define CYCLOMY_H
  31. #include "cyyhw.h"
  32. #define DEVICE_OBJECT_NAME_LENGTH 128 // Copied from serial.h
  33. #define CYY_PDO_NAME_BASE L"\\Cyy\\"
  34. #define CYCLOMY_POOL_TAG (ULONG)'YcyC'
  35. #undef ExAllocatePool
  36. #define ExAllocatePool(type, size) \
  37. ExAllocatePoolWithTag(type, size, CYCLOMY_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 Cyclomy_KdPrint(_d_,_l_, _x_) \
  61. if ((_d_)->DebugLevel & (_l_)) { \
  62. DbgPrint ("Cyclom-y: "); \
  63. DbgPrint _x_; \
  64. }
  65. #define Cyclomy_KdPrint_Cont(_d_,_l_, _x_) \
  66. if ((_d_)->DebugLevel & (_l_)) { \
  67. DbgPrint _x_; \
  68. }
  69. #define Cyclomy_KdPrint_Def(_l_, _x_) \
  70. if (SER_DEFAULT_DEBUG_OUTPUT_LEVEL & (_l_)) { \
  71. DbgPrint ("Cyclom-y: "); \
  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 Cyclomy_KdPrint(_d_, _l_, _x_)
  79. #define Cyclomy_KdPrint_Cont(_d_, _l_, _x_)
  80. #define Cyclomy_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. //
  89. // These are the states a PDO or FDO transition upon
  90. // receiving a specific PnP Irp. Refer to the PnP Device States
  91. // diagram in DDK documentation for better understanding.
  92. //
  93. typedef enum _DEVICE_PNP_STATE {
  94. NotStarted = 0, // Not started yet
  95. Started, // Device has received the START_DEVICE IRP
  96. StopPending, // Device has received the QUERY_STOP IRP
  97. Stopped, // Device has received the STOP_DEVICE IRP
  98. RemovePending, // Device has received the QUERY_REMOVE IRP
  99. SurpriseRemovePending, // Device has received the SURPRISE_REMOVE IRP
  100. Deleted, // Device has received the REMOVE_DEVICE IRP
  101. UnKnown // Unknown state
  102. } DEVICE_PNP_STATE;
  103. //
  104. // A common header for the device extensions of the PDOs and FDO
  105. //
  106. typedef struct _COMMON_DEVICE_DATA
  107. {
  108. PDEVICE_OBJECT Self;
  109. // A backpointer to the device object for which this is the extension
  110. BOOLEAN IsFDO;
  111. // BOOLEAN Removed; // Added in build 2072
  112. // Has this device been removed? Should we fail any requests?
  113. // We track the state of the device with every PnP Irp
  114. // that affects the device through these two variables.
  115. DEVICE_PNP_STATE DevicePnPState;
  116. DEVICE_PNP_STATE PreviousPnPState;
  117. ULONG DebugLevel;
  118. SYSTEM_POWER_STATE SystemState;
  119. DEVICE_POWER_STATE DeviceState;
  120. } COMMON_DEVICE_DATA, *PCOMMON_DEVICE_DATA;
  121. //
  122. // The device extension for the PDOs.
  123. // That is the serial ports of which this bus driver enumerates.
  124. // (IE there is a PDO for the 201 serial port).
  125. //
  126. typedef struct _PDO_DEVICE_DATA
  127. {
  128. COMMON_DEVICE_DATA;
  129. PDEVICE_OBJECT ParentFdo;
  130. // A back pointer to the bus
  131. UNICODE_STRING HardwareIDs;
  132. // Either in the form of bus\device
  133. // or *PNPXXXX - meaning root enumerated
  134. UNICODE_STRING CompIDs;
  135. // compatible ids to the hardware id
  136. UNICODE_STRING DeviceIDs;
  137. // Format: bus\device
  138. UNICODE_STRING InstanceIDs;
  139. //
  140. // Text describing device
  141. //
  142. UNICODE_STRING DevDesc;
  143. BOOLEAN Attached;
  144. // BOOLEAN Removed; -> Removed in build 2072
  145. // When a device (PDO) is found on a bus and presented as a device relation
  146. // to the PlugPlay system, Attached is set to TRUE, and Removed to FALSE.
  147. // When the bus driver determines that this PDO is no longer valid, because
  148. // the device has gone away, it informs the PlugPlay system of the new
  149. // device relastions, but it does not delete the device object at that time.
  150. // The PDO is deleted only when the PlugPlay system has sent a remove IRP,
  151. // and there is no longer a device on the bus.
  152. //
  153. // If the PlugPlay system sends a remove IRP then the Removed field is set
  154. // to true, and all client (non PlugPlay system) accesses are failed.
  155. // If the device is removed from the bus Attached is set to FALSE.
  156. //
  157. // During a query relations Irp Minor call, only the PDOs that are
  158. // attached to the bus (and all that are attached to the bus) are returned
  159. // (even if they have been removed).
  160. //
  161. // During a remove device Irp Minor call, if and only if, attached is set
  162. // to FALSE, the PDO is deleted.
  163. //
  164. // The child devices will have to know which PortIndex they are.
  165. ULONG PortIndex;
  166. } PDO_DEVICE_DATA, *PPDO_DEVICE_DATA;
  167. //
  168. // The device extension of the bus itself. From whence the PDO's are born.
  169. //
  170. typedef struct _FDO_DEVICE_DATA
  171. {
  172. COMMON_DEVICE_DATA;
  173. PDRIVER_OBJECT DriverObject;
  174. UCHAR PdoIndex;
  175. // A number to keep track of the Pdo we're allocating.
  176. // Increment every time we create a new PDO. It's ok that it wraps.
  177. ULONG NumPDOs;
  178. // The PDOs currently enumerated.
  179. PDEVICE_OBJECT AttachedPDO[CYY_MAX_PORTS];
  180. PPDO_DEVICE_DATA PdoData[CYY_MAX_PORTS];
  181. PDEVICE_OBJECT UnderlyingPDO;
  182. PDEVICE_OBJECT TopOfStack;
  183. // the underlying bus PDO and the actual device object to which our
  184. // FDO is attached
  185. ULONG OutstandingIO;
  186. // the number of IRPs sent from the bus to the underlying device object
  187. KEVENT RemoveEvent;
  188. // On remove device plugplay request we must wait until all outstanding
  189. // requests have been completed before we can actually delete the device
  190. // object.
  191. UNICODE_STRING DevClassAssocName;
  192. // The name returned from IoRegisterDeviceClass Association,
  193. // which is used as a handle for IoSetDev... and friends.
  194. SYSTEM_POWER_STATE SystemWake;
  195. DEVICE_POWER_STATE DeviceWake;
  196. //
  197. // We keep the following values around so that we can connect
  198. // to the interrupt and report resources after the configuration
  199. // record is gone.
  200. //
  201. //
  202. // Translated vector
  203. //
  204. ULONG Vector;
  205. //
  206. // Translated Irql
  207. //
  208. KIRQL Irql;
  209. //
  210. // Untranslated vector
  211. //
  212. ULONG OriginalVector;
  213. //
  214. // Untranslated irql
  215. //
  216. ULONG OriginalIrql;
  217. //
  218. // Bus number
  219. //
  220. ULONG BusNumber;
  221. //
  222. // Interface type
  223. //
  224. INTERFACE_TYPE InterfaceType;
  225. //
  226. // Cyclom-Y hardware
  227. //
  228. PHYSICAL_ADDRESS PhysicalRuntime;
  229. PHYSICAL_ADDRESS TranslatedRuntime;
  230. ULONG RuntimeLength;
  231. PHYSICAL_ADDRESS PhysicalBoardMemory;
  232. PHYSICAL_ADDRESS TranslatedBoardMemory;
  233. ULONG BoardMemoryLength;
  234. PUCHAR Runtime;
  235. PUCHAR BoardMemory;
  236. ULONG IsPci;
  237. PUCHAR Cd1400Base[CYY_MAX_CHIPS];
  238. // We are passing the resources privatly to our children so that Device Manager will not
  239. // complain about resource conflict between children.
  240. PIO_RESOURCE_REQUIREMENTS_LIST PChildRequiredList;
  241. PCM_RESOURCE_LIST PChildResourceList;
  242. ULONG PChildResourceListSize;
  243. PCM_RESOURCE_LIST PChildResourceListTr;
  244. ULONG PChildResourceListSizeTr;
  245. ULONG UINumber;
  246. } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
  247. //
  248. // Macros
  249. //
  250. #define INITIALIZE_PNP_STATE(_Data_) \
  251. (_Data_)->DevicePnPState = NotStarted;\
  252. (_Data_)->PreviousPnPState = NotStarted;
  253. #define SET_NEW_PNP_STATE(_Data_, _state_) \
  254. (_Data_)->PreviousPnPState = (_Data_)->DevicePnPState;\
  255. (_Data_)->DevicePnPState = (_state_);
  256. #define RESTORE_PREVIOUS_PNP_STATE(_Data_) \
  257. (_Data_)->DevicePnPState = (_Data_)->PreviousPnPState;\
  258. //
  259. // Free the buffer associated with a Unicode string
  260. // and re-init it to NULL
  261. //
  262. #define CyclomyFreeUnicodeString(PStr) \
  263. { \
  264. if ((PStr)->Buffer != NULL) { \
  265. ExFreePool((PStr)->Buffer); \
  266. } \
  267. RtlInitUnicodeString((PStr), NULL); \
  268. }
  269. //
  270. // Prototypes
  271. //
  272. NTSTATUS
  273. Cyclomy_CreateClose (
  274. IN PDEVICE_OBJECT DeviceObject,
  275. IN PIRP Irp
  276. );
  277. NTSTATUS
  278. Cyclomy_IoCtl (
  279. IN PDEVICE_OBJECT DeviceObject,
  280. IN PIRP Irp
  281. );
  282. NTSTATUS
  283. Cyclomy_InternIoCtl (
  284. IN PDEVICE_OBJECT DeviceObject,
  285. IN PIRP Irp
  286. );
  287. VOID
  288. Cyclomy_DriverUnload (
  289. IN PDRIVER_OBJECT DriverObject
  290. );
  291. NTSTATUS
  292. Cyclomy_PnP (
  293. IN PDEVICE_OBJECT DeviceObject,
  294. IN PIRP Irp
  295. );
  296. NTSTATUS
  297. Cyclomy_Power (
  298. IN PDEVICE_OBJECT DeviceObject,
  299. IN PIRP Irp
  300. );
  301. NTSTATUS
  302. Cyclomy_AddDevice(
  303. IN PDRIVER_OBJECT DriverObject,
  304. IN PDEVICE_OBJECT BusDeviceObject
  305. );
  306. NTSTATUS
  307. Cyclomy_PnPRemove (
  308. PDEVICE_OBJECT Device,
  309. PPDO_DEVICE_DATA PdoData
  310. );
  311. NTSTATUS
  312. Cyclomy_FDO_PnP (
  313. IN PDEVICE_OBJECT DeviceObject,
  314. IN PIRP Irp,
  315. IN PIO_STACK_LOCATION IrpStack,
  316. IN PFDO_DEVICE_DATA DeviceData
  317. );
  318. NTSTATUS
  319. Cyclomy_PDO_PnP (
  320. IN PDEVICE_OBJECT DeviceObject,
  321. IN PIRP Irp,
  322. IN PIO_STACK_LOCATION IrpStack,
  323. IN PPDO_DEVICE_DATA DeviceData
  324. );
  325. NTSTATUS
  326. Cyclomy_IncIoCount (
  327. PFDO_DEVICE_DATA Data
  328. );
  329. VOID
  330. Cyclomy_DecIoCount (
  331. PFDO_DEVICE_DATA Data
  332. );
  333. NTSTATUS
  334. Cyclomy_DispatchPassThrough(
  335. IN PDEVICE_OBJECT DeviceObject,
  336. IN PIRP Irp
  337. );
  338. NTSTATUS
  339. Cyclomy_ReenumerateDevices(
  340. IN PIRP Irp,
  341. IN PFDO_DEVICE_DATA DeviceData
  342. );
  343. NTSTATUS
  344. Cyclomy_InitMultiString(PFDO_DEVICE_DATA FdoData, PUNICODE_STRING MultiString,
  345. ...);
  346. void
  347. Cyclomy_PDO_EnumMarkMissing(
  348. PFDO_DEVICE_DATA FdoData,
  349. PPDO_DEVICE_DATA PdoData);
  350. NTSTATUS
  351. Cyclomy_GetRegistryKeyValue (
  352. IN HANDLE Handle,
  353. IN PWCHAR KeyNameString,
  354. IN ULONG KeyNameStringLength,
  355. IN PVOID Data,
  356. IN ULONG DataLength,
  357. OUT PULONG ActualLength);
  358. void
  359. Cyclomy_InitPDO (
  360. ULONG index,
  361. PDEVICE_OBJECT pdoData,
  362. PFDO_DEVICE_DATA fdoData
  363. );
  364. NTSTATUS
  365. CyclomySyncCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
  366. IN PKEVENT CyclomySyncEvent);
  367. NTSTATUS
  368. Cyclomy_GetResourceInfo(IN PDEVICE_OBJECT PDevObj,
  369. IN PCM_RESOURCE_LIST PResList,
  370. IN PCM_RESOURCE_LIST PTrResList);
  371. VOID
  372. Cyclomy_ReleaseResources(IN PFDO_DEVICE_DATA PDevExt);
  373. NTSTATUS
  374. Cyclomy_GotoPowerState(IN PDEVICE_OBJECT PDevObj,
  375. IN PFDO_DEVICE_DATA PDevExt,
  376. IN DEVICE_POWER_STATE DevPowerState);
  377. NTSTATUS
  378. Cyclomy_SystemPowerCompletion(IN PDEVICE_OBJECT PDevObj, UCHAR MinorFunction,
  379. IN POWER_STATE PowerState, IN PVOID Context,
  380. PIO_STATUS_BLOCK IoStatus);
  381. NTSTATUS
  382. Cyclomy_ItemCallBack(
  383. IN PVOID Context,
  384. IN PUNICODE_STRING PathName,
  385. IN INTERFACE_TYPE BusType,
  386. IN ULONG BusNumber,
  387. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  388. IN CONFIGURATION_TYPE ControllerType,
  389. IN ULONG ControllerNumber,
  390. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  391. IN CONFIGURATION_TYPE PeripheralType,
  392. IN ULONG PeripheralNumber,
  393. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  394. );
  395. NTSTATUS
  396. Cyclomy_BuildRequirementsList(
  397. OUT PIO_RESOURCE_REQUIREMENTS_LIST *PChildRequiredList_Pointer,
  398. IN PCM_RESOURCE_LIST PResourceList, IN ULONG NumberOfResources
  399. );
  400. NTSTATUS
  401. Cyclomy_BuildResourceList(
  402. OUT PCM_RESOURCE_LIST *POutList_Pointer,
  403. OUT ULONG *ListSize_Pointer,
  404. IN PCM_RESOURCE_LIST PInList,
  405. IN ULONG NumberOfResources
  406. );
  407. ULONG
  408. Cyclomy_DoesBoardExist(
  409. IN PFDO_DEVICE_DATA Extension
  410. );
  411. ULONG
  412. Cyclomy_DoesBoardExist(
  413. IN PFDO_DEVICE_DATA Extension
  414. );
  415. VOID
  416. Cyclomy_EnableInterruptInPLX(
  417. IN PFDO_DEVICE_DATA PDevExt
  418. );
  419. VOID
  420. CyyLogError(
  421. IN PDRIVER_OBJECT DriverObject,
  422. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  423. IN PHYSICAL_ADDRESS P1,
  424. IN PHYSICAL_ADDRESS P2,
  425. IN ULONG SequenceNumber,
  426. IN UCHAR MajorFunctionCode,
  427. IN UCHAR RetryCount,
  428. IN ULONG UniqueErrorValue,
  429. IN NTSTATUS FinalStatus,
  430. IN NTSTATUS SpecificIOStatus,
  431. IN ULONG LengthOfInsert1,
  432. IN PWCHAR Insert1,
  433. IN ULONG LengthOfInsert2,
  434. IN PWCHAR Insert2
  435. );
  436. PCHAR
  437. PnPMinorFunctionString (
  438. UCHAR MinorFunction
  439. );
  440. #endif // endef CYCLOMY_H