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.

255 lines
8.1 KiB

  1. /****************************************************************************************
  2. * *
  3. * Header: SPX_MISC.H *
  4. * *
  5. * Creation: 15th October 1998 *
  6. * *
  7. * Author: Paul Smith *
  8. * *
  9. * Version: 1.0.0 *
  10. * *
  11. * Contains: All Macros and function prototypes for the common PnP and power code. *
  12. * *
  13. ****************************************************************************************/
  14. #if !defined(SPX_MISC_H)
  15. #define SPX_MISC_H
  16. // Prototypes for common PnP code.
  17. NTSTATUS
  18. Spx_AddDevice(IN PDRIVER_OBJECT pDriverObject, IN PDEVICE_OBJECT pPDO);
  19. NTSTATUS
  20. Spx_DispatchPnp(IN PDEVICE_OBJECT pDevObject, IN PIRP pIrp);
  21. NTSTATUS
  22. Spx_DispatchPower(IN PDEVICE_OBJECT pDevObject, IN PIRP pIrp);
  23. NTSTATUS
  24. Spx_DispatchPnpPowerComplete(IN PDEVICE_OBJECT pDevObject, IN PIRP pIrp, IN PVOID Context);
  25. NTSTATUS
  26. Spx_SerialInternalIoControl(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp);
  27. NTSTATUS
  28. Spx_InitMultiString(BOOLEAN multi, PUNICODE_STRING MultiString, ...);
  29. NTSTATUS
  30. Spx_GetRegistryKeyValue(
  31. IN HANDLE Handle,
  32. IN PWCHAR KeyNameString,
  33. IN ULONG KeyNameStringLength,
  34. IN PVOID Data,
  35. IN ULONG DataLength
  36. );
  37. NTSTATUS
  38. Spx_PutRegistryKeyValue(
  39. IN HANDLE Handle,
  40. IN PWCHAR PKeyNameString,
  41. IN ULONG KeyNameStringLength,
  42. IN ULONG Dtype,
  43. IN PVOID PData,
  44. IN ULONG DataLength
  45. );
  46. VOID
  47. Spx_LogMessage(
  48. IN ULONG MessageSeverity,
  49. IN PDRIVER_OBJECT DriverObject,
  50. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  51. IN PHYSICAL_ADDRESS P1,
  52. IN PHYSICAL_ADDRESS P2,
  53. IN ULONG SequenceNumber,
  54. IN UCHAR MajorFunctionCode,
  55. IN UCHAR RetryCount,
  56. IN ULONG UniqueErrorValue,
  57. IN NTSTATUS FinalStatus,
  58. IN PCHAR szTemp);
  59. VOID
  60. Spx_LogError(
  61. IN PDRIVER_OBJECT DriverObject,
  62. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  63. IN PHYSICAL_ADDRESS P1,
  64. IN PHYSICAL_ADDRESS P2,
  65. IN ULONG SequenceNumber,
  66. IN UCHAR MajorFunctionCode,
  67. IN UCHAR RetryCount,
  68. IN ULONG UniqueErrorValue,
  69. IN NTSTATUS FinalStatus,
  70. IN NTSTATUS SpecificIOStatus,
  71. IN ULONG LengthOfInsert1,
  72. IN PWCHAR Insert1,
  73. IN ULONG LengthOfInsert2,
  74. IN PWCHAR Insert2
  75. );
  76. ULONG SpxGetNtCardType(PDEVICE_OBJECT pNtDevObj);
  77. NTSTATUS Spx_CreatePortInstanceID(IN PPORT_DEVICE_EXTENSION pPort);
  78. SPX_MEM_COMPARES Spx_MemCompare(IN PHYSICAL_ADDRESS A, IN ULONG SpanOfA, IN PHYSICAL_ADDRESS B, IN ULONG SpanOfB);
  79. NTSTATUS PLX_9050_CNTRL_REG_FIX(IN PCARD_DEVICE_EXTENSION pCard);
  80. VOID SpxSetOrClearPnpPowerFlags(IN PCOMMON_OBJECT_DATA pDevExt, IN ULONG Value, IN BOOLEAN Set);
  81. VOID SpxSetOrClearUnstallingFlag(IN PCOMMON_OBJECT_DATA pDevExt, IN BOOLEAN Set);
  82. BOOLEAN
  83. SpxCheckPnpPowerFlags(IN PCOMMON_OBJECT_DATA pDevExt, IN ULONG ulSetFlags, IN ULONG ulClearedFlags, IN BOOLEAN bAll);
  84. PVOID SpxAllocateMem(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes);
  85. PVOID SpxAllocateMemWithQuota(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes);
  86. #ifndef BUILD_SPXMINIPORT
  87. void SpxFreeMem(PVOID pMem);
  88. #endif
  89. VOID SpxIRPCounter(IN PPORT_DEVICE_EXTENSION pPort, IN PIRP pIrp, IN ULONG IrpCondition);
  90. BOOLEAN SpxClearAllPortStats(IN PPORT_DEVICE_EXTENSION pPort);
  91. // Filtered dispatch entry points...
  92. NTSTATUS Spx_Flush(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  93. NTSTATUS Spx_Write(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  94. NTSTATUS Spx_Read(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  95. NTSTATUS Spx_IoControl(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  96. NTSTATUS Spx_InternalIoControl(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  97. NTSTATUS Spx_CreateOpen(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  98. NTSTATUS Spx_Close(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  99. NTSTATUS Spx_Cleanup(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  100. NTSTATUS Spx_QueryInformationFile(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  101. NTSTATUS Spx_SetInformationFile(IN PDEVICE_OBJECT pDevObject,IN PIRP pIrp); // SPX_DISP.C
  102. VOID Spx_UnstallIrps(IN PPORT_DEVICE_EXTENSION pPort); // SPX_DISP.C
  103. VOID Spx_KillStalledIRPs(IN PDEVICE_OBJECT pDevObj); // SPX_DISP.C
  104. // End of prototypes for common PnP code.
  105. #ifdef WMI_SUPPORT
  106. NTSTATUS Spx_DispatchSystemControl(IN PDEVICE_OBJECT pDevObject, IN PIRP pIrp);
  107. NTSTATUS SpxPort_WmiInitializeWmilibContext(IN PWMILIB_CONTEXT WmilibContext);
  108. #define UPDATE_WMI_LINE_CONTROL(WmiCommData, LineControl) \
  109. do \
  110. { \
  111. \
  112. WmiCommData.BitsPerByte = (LineControl & SERIAL_DATA_MASK) + 5; \
  113. WmiCommData.ParityCheckEnable = (LineControl & 0x08) ? TRUE : FALSE; \
  114. \
  115. switch(LineControl & SERIAL_PARITY_MASK) \
  116. { \
  117. case SERIAL_ODD_PARITY: \
  118. WmiCommData.Parity = SERIAL_WMI_PARITY_ODD; \
  119. break; \
  120. \
  121. case SERIAL_EVEN_PARITY: \
  122. WmiCommData.Parity = SERIAL_WMI_PARITY_EVEN; \
  123. break; \
  124. \
  125. case SERIAL_MARK_PARITY: \
  126. WmiCommData.Parity = SERIAL_WMI_PARITY_MARK; \
  127. break; \
  128. \
  129. case SERIAL_SPACE_PARITY: \
  130. WmiCommData.Parity = SERIAL_WMI_PARITY_SPACE; \
  131. break; \
  132. \
  133. case SERIAL_NONE_PARITY: \
  134. default: \
  135. WmiCommData.Parity = SERIAL_WMI_PARITY_NONE; \
  136. break; \
  137. } \
  138. \
  139. \
  140. if(LineControl & SERIAL_STOP_MASK) \
  141. { \
  142. if((LineControl & SERIAL_DATA_MASK) == SERIAL_5_DATA) \
  143. WmiCommData.StopBits = SERIAL_WMI_STOP_1_5; \
  144. else \
  145. WmiCommData.StopBits = SERIAL_WMI_STOP_2; \
  146. } \
  147. else \
  148. WmiCommData.StopBits = SERIAL_WMI_STOP_1; \
  149. \
  150. } while (0)
  151. #define UPDATE_WMI_XON_XOFF_CHARS(WmiCommData, SpecialChars) \
  152. do \
  153. { \
  154. WmiCommData.XoffCharacter = SpecialChars.XoffChar; \
  155. WmiCommData.XonCharacter = SpecialChars.XonChar; \
  156. \
  157. } while (0)
  158. #define UPDATE_WMI_XMIT_THRESHOLDS(WmiCommData, HandFlow) \
  159. do \
  160. { \
  161. WmiCommData.XoffXmitThreshold = HandFlow.XoffLimit; \
  162. WmiCommData.XonXmitThreshold = HandFlow.XonLimit; \
  163. \
  164. } while (0)
  165. #endif
  166. // Macros
  167. // Debug Messages
  168. #if DBG
  169. #define SPX_TRACE_CALLS ((ULONG)0x00000001)
  170. #define SPX_TRACE_PNP_IRPS ((ULONG)0x00000002)
  171. #define SPX_ERRORS ((ULONG)0x00000004)
  172. #define SPX_MISC_DBG ((ULONG)0x00000008)
  173. #define SPX_TRACE_POWER_IRPS ((ULONG)0x00000010)
  174. #define SPX_TRACE_IRP_PATH ((ULONG)0x00000020)
  175. #define SPX_TRACE_FILTER_IRPS ((ULONG)0x00000040)
  176. //#define SERFLOW ((ULONG)0x00000080)
  177. //#define SERERRORS ((ULONG)0x00000100)
  178. //#define SERBUGCHECK ((ULONG)0x00000200)
  179. extern ULONG SpxDebugLevel; // Global Debug Level
  180. #define SpxDbgMsg(LEVEL, STRING) \
  181. do{ \
  182. if(SpxDebugLevel & (LEVEL)) \
  183. { \
  184. DbgPrint STRING; \
  185. } \
  186. if((LEVEL) == SERBUGCHECK) \
  187. { \
  188. ASSERT(FALSE); \
  189. } \
  190. }while (0)
  191. #else
  192. #define SpxDbgMsg(LEVEL, STRING) do {NOTHING;} while (0)
  193. #endif
  194. #define SetPnpPowerFlags(pDevExt,Value) \
  195. SpxSetOrClearPnpPowerFlags( (PCOMMON_OBJECT_DATA)(pDevExt), (Value), TRUE);
  196. #define ClearPnpPowerFlags(pDevExt,Value) \
  197. SpxSetOrClearPnpPowerFlags( (PCOMMON_OBJECT_DATA)(pDevExt), (Value), FALSE);
  198. #define SPX_SUCCESS(Status) ((NTSTATUS)(Status) == 0)
  199. #define SetUnstallingFlag(pDevExt) \
  200. SpxSetOrClearUnstallingFlag( (PCOMMON_OBJECT_DATA)(pDevExt), TRUE);
  201. #define ClearUnstallingFlag(pDevExt) \
  202. SpxSetOrClearUnstallingFlag( (PCOMMON_OBJECT_DATA)(pDevExt), FALSE);
  203. // End of macros.
  204. #endif // End of SPX_MISC_H