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.

526 lines
12 KiB

  1. /*++
  2. Module Name:
  3. mxenum.h
  4. Abstract:
  5. This module contains the common private declarations for the serial port
  6. enumerator.
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. Revision History:
  11. --*/
  12. #ifndef MXENUM_H
  13. #define MXENUM_H
  14. #define REGISTRY_CLASS L"\\REGISTRY\\Machine\\System\\CurrentControlSet\\Control\\Class\\"
  15. #define REGISTRY_PARAMETER L"Parameters\\"
  16. #define MAXPORT_PER_CARD 32
  17. #define MAX_BOARD 4
  18. #define MXENUM_PDO_COMPATIBLE_ID "Mxport"
  19. #define MXENUM_PDO_HARDWARE_ID "Mxport000"
  20. #define MXENUM_PDO_DEVICE_ID "Mxcard\\MxcardB00P000"
  21. #define MXENUM_PDO_NT_NAME L"MxcardB00P000"
  22. #define MXENUM_PDO_NAME_BASE L"\\Mxcard\\MxcardEnumB00P000"
  23. #define MXENUM_PDO_DEVICE_TEXT L"MOXA communication port"
  24. #define MXENUM_INSTANCE_IDS L"0000"
  25. #define MXENUM_INSTANCE_IDS_LENGTH 5
  26. #define C218ISA 1
  27. #define C218PCI 2
  28. #define C320ISA 3
  29. #define C320PCI 4
  30. #define CP204J 5
  31. #define MOXA_MAX_BOARD_TYPE 5
  32. // Error code for download firmware
  33. #define Fail_FirmwareCode 1
  34. #define Fail_FindBoard 2
  35. #define Fail_FindCpumodule 3
  36. #define Fail_Download 4
  37. #define Fail_Checksum 5
  38. #define Fail_Cpumodule 6
  39. #define Fail_Uartmodule 7
  40. #define MXENUM_POOL_TAG (ULONG)'eixM'
  41. #undef ExAllocatePool
  42. #define ExAllocatePool(type, size) \
  43. ExAllocatePoolWithTag(type, size, MXENUM_POOL_TAG)
  44. #pragma warning(error:4100) // Unreferenced formal parameter
  45. #pragma warning(error:4705) // Statement has no effect
  46. //
  47. // Debugging Output Levels
  48. //
  49. #define MXENUM_DBG_MASK 0x0000000F
  50. #define MXENUM_DBG_NOISE 0x00000001
  51. #define MXENUM_DBG_TRACE 0x00000002
  52. #define MXENUM_DBG_INFO 0x00000004
  53. #define MXENUM_DBG_ERROR 0x00000008
  54. #define MXENUM_DEFAULT_DEBUG_OUTPUT_LEVEL MXENUM_DBG_MASK
  55. #if DBG
  56. #define MxenumKdPrint(_l_, _x_) \
  57. if (MXENUM_DEFAULT_DEBUG_OUTPUT_LEVEL & (_l_)) { \
  58. DbgPrint ("Mxcard.SYS: "); \
  59. DbgPrint _x_; \
  60. }
  61. #define TRAP() DbgBreakPoint()
  62. #define DbgRaiseIrql(_x_,_y_) KeRaiseIrql(_x_,_y_)
  63. #define DbgLowerIrql(_x_) KeLowerIrql(_x_)
  64. #else
  65. #define MxenumKdPrint(_l_, _x_)
  66. #define TRAP()
  67. #define DbgRaiseIrql(_x_,_y_)
  68. #define DbgLowerIrql(_x_)
  69. #endif
  70. #if !defined(MIN)
  71. #define MIN(_A_,_B_) (((_A_) < (_B_)) ? (_A_) : (_B_))
  72. #endif
  73. #define MOXA_IOCTL 0x800
  74. #define IOCTL_MOXA_INTERNAL_BASIC_SETTINGS CTL_CODE(FILE_DEVICE_SERIAL_PORT,MOXA_IOCTL+30, METHOD_BUFFERED, FILE_ANY_ACCESS)
  75. #define IOCTL_MOXA_INTERNAL_BOARD_READY CTL_CODE(FILE_DEVICE_SERIAL_PORT,MOXA_IOCTL+31, METHOD_BUFFERED, FILE_ANY_ACCESS)
  76. typedef enum _MXENUM__MEM_COMPARES {
  77. AddressesAreEqual,
  78. AddressesOverlap,
  79. AddressesAreDisjoint
  80. } MXENUM_MEM_COMPARES,*PMXENUM_MEM_COMPARES;
  81. //
  82. // A common header for the device extensions of the PDOs and FDO
  83. //
  84. typedef struct _COMMON_DEVICE_DATA
  85. {
  86. PDEVICE_OBJECT Self;
  87. // A backpointer to the device object for which this is the extension
  88. CHAR Reserved[2];
  89. BOOLEAN IsFDO;
  90. BOOLEAN PowerQueryLock;
  91. // Are we currently in a query power state?
  92. // A boolean to distringuish between PDO and FDO.
  93. SYSTEM_POWER_STATE SystemState;
  94. DEVICE_POWER_STATE DeviceState;
  95. } COMMON_DEVICE_DATA, *PCOMMON_DEVICE_DATA;
  96. //
  97. // The device extension for the PDOs.
  98. // That is the serial ports of which this bus driver enumerates.
  99. // (IE there is a PDO for the 201 serial port).
  100. //
  101. typedef struct _PDO_DEVICE_DATA
  102. {
  103. COMMON_DEVICE_DATA;
  104. PDEVICE_OBJECT ParentFdo;
  105. // A back pointer to the bus
  106. PDEVICE_OBJECT Next;
  107. UNICODE_STRING HardwareIDs;
  108. UNICODE_STRING CompIDs;
  109. // compatible ids to the hardware id
  110. UNICODE_STRING DeviceIDs;
  111. // Format: bus\device
  112. //
  113. // Text describing device
  114. //
  115. UNICODE_STRING DevDesc;
  116. BOOLEAN Started;
  117. BOOLEAN Attached;
  118. BOOLEAN Removed;
  119. // When a device (PDO) is found on a bus and presented as a device relation
  120. // to the PlugPlay system, Attached is set to TRUE, and Removed to FALSE.
  121. // When the bus driver determines that this PDO is no longer valid, because
  122. // the device has gone away, it informs the PlugPlay system of the new
  123. // device relastions, but it does not delete the device object at that time.
  124. // The PDO is deleted only when the PlugPlay system has sent a remove IRP,
  125. // and there is no longer a device on the bus.
  126. //
  127. // If the PlugPlay system sends a remove IRP then the Removed field is set
  128. // to true, and all client (non PlugPlay system) accesses are failed.
  129. // If the device is removed from the bus Attached is set to FALSE.
  130. //
  131. // During a query relations Irp Minor call, only the PDOs that are
  132. // attached to the bus (and all that are attached to the bus) are returned
  133. // (even if they have been removed).
  134. //
  135. // During a remove device Irp Minor call, if and only if, attached is set
  136. // to FALSE, the PDO is deleted.
  137. //
  138. LIST_ENTRY Link;
  139. // the link point to hold all the PDOs for a single bus together
  140. ULONG PortIndex;
  141. } PDO_DEVICE_DATA, *PPDO_DEVICE_DATA;
  142. //
  143. // The device extension of the bus itself. From whence the PDO's are born.
  144. //
  145. typedef struct _FDO_DEVICE_DATA
  146. {
  147. COMMON_DEVICE_DATA;
  148. ULONG PollingPeriod;
  149. // The amount of time to wait between polling the serial port for detecting
  150. // pnp device attachment and removal.
  151. FAST_MUTEX Mutex;
  152. // A syncronization for access to the device extension.
  153. UCHAR NumPDOs;
  154. // A number to keep track of the Pdo we're allocating.
  155. // Increment every time we create a new PDO. It's ok that it wraps.
  156. BOOLEAN Started;
  157. // Are we on, have resources, etc?
  158. BOOLEAN Removed;
  159. // Has this device been removed? Should we fail any requests?
  160. BOOLEAN PDOWasExposed;
  161. // Was the current pdo exposed to us using the expose IOCTL?
  162. // If so, on a query device relations, don't enumerate.
  163. BOOLEAN PDOForcedRemove;
  164. // Was the last PDO removed by force using the internal ioctl?
  165. // If so, when the next Query Device Relations is called, return only the
  166. // currently enumerated pdos
  167. PDEVICE_OBJECT AttachedPDO;
  168. // The last power state of the pdo set by me
  169. DEVICE_POWER_STATE LastSetPowerState;
  170. PDEVICE_OBJECT UnderlyingPDO;
  171. PDEVICE_OBJECT TopOfStack;
  172. // the underlying bus PDO and the actual device object to which our
  173. // FDO is attached
  174. KEVENT CallEvent;
  175. // An event on which to wait for IRPs sent to the lower device objects
  176. // to complete.
  177. ULONG OutstandingIO;
  178. // the number of IRPs sent from the bus to the underlying device object
  179. KEVENT RemoveEvent;
  180. // On remove device plugplay request we must wait until all outstanding
  181. // requests have been completed before we can actually delete the device
  182. // object.
  183. UNICODE_STRING DevClassAssocName;
  184. // The name returned from IoRegisterDeviceClass Association,
  185. // which is used as a handle for IoSetDev... and friends.
  186. ULONG BoardIndex;
  187. ULONG BoardType;
  188. ULONG UsablePortMask;
  189. ULONG NumPorts;
  190. ULONG ClockRate;
  191. INTERFACE_TYPE InterfaceType;
  192. ULONG BusNumber;
  193. PHYSICAL_ADDRESS OriginalBaseAddress;
  194. PHYSICAL_ADDRESS OriginalAckPort;
  195. PUCHAR BaseAddress;
  196. PUCHAR AckPort;
  197. BOOLEAN AddressMapped;
  198. struct {
  199. ULONG Level;
  200. ULONG Vector;
  201. ULONG Affinity;
  202. } Interrupt;
  203. } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
  204. typedef struct _DEVICE_SETTINGS
  205. {
  206. ULONG BoardIndex;
  207. ULONG PortIndex;
  208. ULONG BoardType;
  209. ULONG NumPorts;
  210. INTERFACE_TYPE InterfaceType;
  211. ULONG BusNumber;
  212. PHYSICAL_ADDRESS OriginalBaseAddress;
  213. PHYSICAL_ADDRESS OriginalAckPort;
  214. PUCHAR BaseAddress;
  215. PUCHAR AckPort;
  216. struct {
  217. ULONG Level;
  218. ULONG Vector;
  219. ULONG Affinity;
  220. } Interrupt;
  221. } DEVICE_SETTINGS, *PDEVICE_SETTINGS;
  222. extern PWSTR BoardDesc[5];
  223. extern PWSTR DownloadErrMsg[7];
  224. extern ULONG NumBoardInstalled;
  225. //
  226. // Prototypes
  227. //
  228. NTSTATUS
  229. MxenumInternIoCtl (
  230. IN PDEVICE_OBJECT DeviceObject,
  231. IN PIRP Irp
  232. );
  233. VOID
  234. MxenumDriverUnload (
  235. IN PDRIVER_OBJECT DriverObject
  236. );
  237. NTSTATUS
  238. MxenumPnPDispatch (
  239. IN PDEVICE_OBJECT DeviceObject,
  240. IN PIRP Irp
  241. );
  242. NTSTATUS
  243. MxenumPowerDispatch (
  244. IN PDEVICE_OBJECT DeviceObject,
  245. IN PIRP Irp
  246. );
  247. NTSTATUS
  248. MxenumRemove (
  249. PFDO_DEVICE_DATA FdoData,
  250. PFDO_DEVICE_DATA PdoData
  251. );
  252. NTSTATUS
  253. MxenumPnPRemovePDOs (
  254. PDEVICE_OBJECT PFDdo
  255. );
  256. NTSTATUS
  257. MxenumPnPRemovePDO (
  258. PDEVICE_OBJECT PPdo
  259. );
  260. NTSTATUS
  261. MxenumAddDevice (
  262. IN PDRIVER_OBJECT DriverObject,
  263. IN PDEVICE_OBJECT BusDeviceObject
  264. );
  265. NTSTATUS
  266. MxenumFdoPnP (
  267. IN PDEVICE_OBJECT DeviceObject,
  268. IN PIRP Irp,
  269. IN PIO_STACK_LOCATION IrpStack,
  270. IN PFDO_DEVICE_DATA DeviceData
  271. );
  272. NTSTATUS
  273. MxenumPdoPnP (
  274. IN PDEVICE_OBJECT DeviceObject,
  275. IN PIRP Irp,
  276. IN PIO_STACK_LOCATION IrpStack,
  277. IN PPDO_DEVICE_DATA DeviceData
  278. );
  279. NTSTATUS
  280. MxenumIncIoCount (
  281. PFDO_DEVICE_DATA Data
  282. );
  283. VOID
  284. MxenumDecIoCount (
  285. PFDO_DEVICE_DATA Data
  286. );
  287. NTSTATUS
  288. MxenumFdoPowerDispatch (
  289. PFDO_DEVICE_DATA FdoData,
  290. PIRP Irp
  291. );
  292. NTSTATUS
  293. MxenumPdoPowerDispatch (
  294. PPDO_DEVICE_DATA FdoData,
  295. PIRP Irp
  296. );
  297. NTSTATUS
  298. MxenumDispatchPassThrough(
  299. IN PDEVICE_OBJECT DeviceObject,
  300. IN PIRP Irp
  301. );
  302. NTSTATUS
  303. MxenumEnumComplete (
  304. IN PDEVICE_OBJECT DeviceObject,
  305. IN PIRP Irp,
  306. IN PVOID Context
  307. );
  308. NTSTATUS
  309. MxenumInitMultiString(PUNICODE_STRING MultiString,
  310. ...);
  311. NTSTATUS
  312. MxenumCreatePDO(
  313. IN PFDO_DEVICE_DATA FdoData
  314. );
  315. NTSTATUS
  316. MxenumGetRegistryKeyValue (
  317. IN HANDLE Handle,
  318. IN PWCHAR KeyNameString,
  319. IN ULONG KeyNameStringLength,
  320. IN PVOID Data,
  321. IN ULONG DataLength,
  322. OUT PULONG ActualLength);
  323. NTSTATUS
  324. MxenumPutRegistryKeyValue(
  325. IN HANDLE Handle,
  326. IN PWCHAR PKeyNameString,
  327. IN ULONG KeyNameStringLength,
  328. IN ULONG Dtype,
  329. IN PVOID PData,
  330. IN ULONG DataLength);
  331. void
  332. MxenumInitPDO (
  333. PDEVICE_OBJECT pdoData,
  334. PFDO_DEVICE_DATA fdoData);
  335. NTSTATUS
  336. MxenumGetBoardType(
  337. IN PDEVICE_OBJECT devObject,
  338. OUT PULONG boardType
  339. );
  340. VOID
  341. MxenumLogError(
  342. IN PDRIVER_OBJECT DriverObject,
  343. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  344. IN PHYSICAL_ADDRESS P1,
  345. IN PHYSICAL_ADDRESS P2,
  346. IN ULONG SequenceNumber,
  347. IN UCHAR MajorFunctionCode,
  348. IN UCHAR RetryCount,
  349. IN ULONG UniqueErrorValue,
  350. IN NTSTATUS FinalStatus,
  351. IN NTSTATUS SpecificIOStatus,
  352. IN ULONG LengthOfInsert1,
  353. IN PWCHAR Insert1,
  354. IN ULONG LengthOfInsert2,
  355. IN PWCHAR Insert2
  356. );
  357. VOID
  358. MxenumHexToString(
  359. IN PWSTR buffer,
  360. IN int port
  361. );
  362. VOID
  363. MxenumDelay(IN ULONG);
  364. ULONG
  365. MxenumGetClockRate( IN ULONG iobase);
  366. // Portable file I/O routines
  367. NTSTATUS
  368. MxenumOpenFile(PWCHAR filename,
  369. BOOLEAN read,
  370. PHANDLE phandle
  371. );
  372. NTSTATUS
  373. MxenumCloseFile(HANDLE handle);
  374. unsigned __int64
  375. MxenumGetFileSize(HANDLE handle);
  376. NTSTATUS
  377. MxenumReadFile(HANDLE handle,
  378. PVOID buffer,
  379. ULONG nbytes,
  380. PULONG pnumread
  381. );
  382. NTSTATUS
  383. MxenumWriteFile(HANDLE handle,
  384. PVOID buffer,
  385. ULONG nbytes,
  386. PULONG pnumread
  387. );
  388. MxenumMemCompare(
  389. IN PHYSICAL_ADDRESS A,
  390. IN ULONG SpanOfA,
  391. IN PHYSICAL_ADDRESS B,
  392. IN ULONG SpanOfB
  393. );
  394. int
  395. MxenumDownloadFirmware(PFDO_DEVICE_DATA deviceData,BOOLEAN NumPortDefined);
  396. #endif // ndef SERENUM_H