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.

204 lines
4.5 KiB

  1. #define SMBCLASS 1
  2. #include <wdm.h>
  3. #include <smbus.h>
  4. #include <devioctl.h>
  5. #include <acpiioct.h>
  6. #include <acpimsft.h>
  7. #define _INC_NSOBJ_ONLY
  8. #include <amli.h>
  9. #include <aml.h>
  10. #if DBG
  11. #define DEBUG 1
  12. #else
  13. #define DEBUG 0
  14. #endif
  15. //
  16. // Debug
  17. //
  18. extern ULONG SMBCDebug;
  19. #if DEBUG
  20. #define SmbPrint(l,m) if(l & SMBCDebug) DbgPrint m
  21. #define ASSERT_DEVICE_LOCKED(a) ASSERT(a->SpinLockAcquired);
  22. #else
  23. #define SmbPrint(l,m)
  24. #define ASSERT_DEVICE_LOCKED(a)
  25. #endif
  26. #define SMB_LOW 0x00000010
  27. #define SMB_STATE 0x00000020
  28. #define SMB_HANDLER 0x00000040
  29. #define SMB_ALARMS 0x00000080
  30. #define SMB_NOTE 0x00000001
  31. #define SMB_WARN 0x00000002
  32. #define SMB_ERROR 0x00000004
  33. #define SMB_ERRORS (SMB_ERROR | SMB_WARN)
  34. #define SMB_TRANSACTION 0x00000100
  35. //
  36. // Internal SMB class data
  37. //
  38. #define MAX_RETRIES 5
  39. #define RETRY_TIME -800000 // Delay 80ms
  40. //typedef
  41. //VOID
  42. //(*SMB_ALARM_NOTIFY)(
  43. // IN PVOID Context,
  44. // IN USHORT AlarmData
  45. // );
  46. typedef struct {
  47. LIST_ENTRY Link; // List of all alarm notifies
  48. UCHAR Flag;
  49. UCHAR Reference;
  50. UCHAR MinAddress; // Min address on bus
  51. UCHAR MaxAddress; // Max address
  52. SMB_ALARM_NOTIFY NotifyFunction;
  53. PVOID NotifyContext;
  54. } SMB_ALARM, *PSMB_ALARM;
  55. #define SMBC_ALARM_DELETE_PENDING 0x01
  56. typedef struct {
  57. SMB_CLASS Class; // Shared Class/Miniport data
  58. KSPIN_LOCK SpinLock; // Lock device data
  59. KIRQL SpinLockIrql; // Irql spinlock acquired at
  60. BOOLEAN SpinLockAcquired; // Debug only
  61. //
  62. // Alarm notifies
  63. //
  64. LIST_ENTRY Alarms; // List of all Alarm notifies
  65. KEVENT AlarmEvent; // Used to delete alarms
  66. //
  67. // IO
  68. //
  69. LIST_ENTRY WorkQueue; // Queued IO IRPs to the device
  70. BOOLEAN InService; // Irp
  71. UCHAR IoState;
  72. //
  73. // Current IO request
  74. //
  75. UCHAR RetryCount;
  76. KTIMER RetryTimer;
  77. KDPC RetryDpc;
  78. //
  79. // Operation Region
  80. //
  81. PVOID RawOperationRegionObject;
  82. } SMBDATA, *PSMBDATA;
  83. //
  84. // IoState
  85. //
  86. #define SMBC_IDLE 0
  87. #define SMBC_START_REQUEST 1
  88. #define SMBC_WAITING_FOR_REQUEST 2
  89. #define SMBC_COMPLETE_REQUEST 3
  90. #define SMBC_COMPLETING_REQUEST 4
  91. #define SMBC_WAITING_FOR_RETRY 5
  92. //
  93. // ACPI SMBus opregion details
  94. //
  95. typedef struct {
  96. UCHAR Status;
  97. UCHAR Length;
  98. UCHAR Data [32];
  99. } BUFFERACC_BUFFER, *PBUFFERACC_BUFFER;
  100. #define SMB_QUICK 0x02
  101. #define SMB_SEND_RECEIVE 0x04
  102. #define SMB_BYTE 0x06
  103. #define SMB_WORD 0x08
  104. #define SMB_BLOCK 0x0a
  105. #define SMB_PROCESS 0x0c
  106. #define SMB_BLOCK_PROCESS 0x0d
  107. //
  108. // Prototypes
  109. //
  110. VOID
  111. SmbClassStartIo (
  112. IN PSMBDATA Smb
  113. );
  114. VOID
  115. SmbCRetry (
  116. IN struct _KDPC *Dpc,
  117. IN PVOID DeferredContext,
  118. IN PVOID SystemArgument1,
  119. IN PVOID SystemArgument2
  120. );
  121. NTSTATUS
  122. SmbCRegisterAlarm (
  123. PSMBDATA Smb,
  124. PIRP Irp
  125. );
  126. NTSTATUS
  127. SmbCDeregisterAlarm (
  128. PSMBDATA Smb,
  129. PIRP Irp
  130. );
  131. NTSTATUS EXPORT
  132. SmbCRawOpRegionHandler (
  133. ULONG AccessType,
  134. PFIELDUNITOBJ FieldUnit,
  135. POBJDATA Data,
  136. ULONG_PTR Context,
  137. PACPI_OPREGION_CALLBACK CompletionHandler,
  138. PVOID CompletionContext
  139. );
  140. NTSTATUS
  141. SmbCRawOpRegionCompletion (
  142. IN PDEVICE_OBJECT DeviceObject,
  143. IN PIRP Irp,
  144. IN PVOID Context
  145. );
  146. NTSTATUS
  147. SmbCSynchronousRequest (
  148. IN PDEVICE_OBJECT DeviceObject,
  149. IN PIRP Irp,
  150. IN PKEVENT IoCompletionEvent
  151. );
  152. //
  153. // Io extension macro to just pass on the Irp to a lower driver
  154. //
  155. #define SmbCallLowerDriver(Status, DeviceObject, Irp) { \
  156. IoSkipCurrentIrpStackLocation(Irp); \
  157. Status = IoCallDriver(DeviceObject,Irp); \
  158. }