Source code of Windows XP (NT5)
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.

282 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. smbali.c
  5. Abstract:
  6. SMB Host Controller Driver for ALI chipset
  7. Author:
  8. Michael Hills
  9. Environment:
  10. Notes:
  11. Revision History:
  12. --*/
  13. #include <wdm.h>
  14. #include <smbus.h>
  15. #include <devioctl.h>
  16. #include <acpiioct.h>
  17. #include <initguid.h>
  18. #include <wdmguid.h>
  19. //
  20. // Debuging
  21. //
  22. #if DBG
  23. extern ULONG SmbAliDebug;
  24. #define SmbPrint(l,m) if(l & SmbAliDebug) DbgPrint m
  25. #else
  26. #define SmbPrint(l,m)
  27. #endif
  28. #define SMB_IO_RESULT 0x00002000
  29. #define SMB_STATS 0x00001000
  30. #define SMB_ALARM 0x00000800
  31. #define SMB_IO_REQUEST 0x00000400
  32. #define SMB_DATA 0x00000200
  33. #define SMB_IO 0x00000100
  34. #define SMB_TRACE 0x00000010
  35. #define SMB_BUS_ERROR 0x00000002
  36. #define SMB_ERROR 0x00000001
  37. //#define USE_IO_DELAY
  38. #ifdef USE_IO_DELAY
  39. VOID SmbDelay(VOID);
  40. #define SMBDELAY SmbDelay ()
  41. #else
  42. #define SMBDELAY
  43. #endif
  44. // The follow constants are based on 10,000,000 / sec <OR> 100ns time units.
  45. #define MICROSECONDS (10)
  46. #define MILLISECONDS (1000*MICROSECONDS)
  47. #define SECONDS (1000*MILLISECONDS)
  48. #define SMB_ALI_MAJOR_VERSION 1
  49. #define SMB_ALI_MINOR_VERSION 1
  50. extern LARGE_INTEGER SmbIoPollRate;
  51. extern ULONG SmbIoInitTimeOut;
  52. extern ULONG SmbIoCompleteTimeOut;
  53. extern LARGE_INTEGER SmbAlertPollRate;
  54. typedef enum {
  55. SmbIoIdle,
  56. SmbIoComplete
  57. } SMB_ALI_IO_STATE;
  58. #define SMB_ALI_IO_RESOURCE_LENGTH 0x40
  59. typedef struct {
  60. UCHAR Address;
  61. UCHAR Command;
  62. UCHAR Protocol;
  63. BOOLEAN ValidData;
  64. USHORT LastData;
  65. } SMB_ALI_POLL_ENTRY, *PSMB_ALI_POL_ENTRY;
  66. typedef struct {
  67. PUCHAR SmbBaseIo; // Base IoAddress
  68. SMB_ALI_IO_STATE IoState;
  69. ACPI_INTERFACE_STANDARD AcpiInterfaces;
  70. PIO_WORKITEM WorkItem;
  71. PIO_WORKITEM InitWorker;
  72. KDPC InitDpc;
  73. KTIMER InitTimer;
  74. ULONG InitTimeOut;
  75. PIO_WORKITEM CompleteWorker;
  76. KDPC CompleteDpc;
  77. KTIMER CompleteTimer;
  78. ULONG CompleteTimeOut;
  79. PIO_WORKITEM PollWorker;
  80. KEVENT PollWorkerActive;
  81. KDPC PollDpc;
  82. KTIMER PollTimer;
  83. PSMB_ALI_POL_ENTRY PollList;
  84. ULONG PollListCount;
  85. ULONG InternalRetries;
  86. } SMB_ALI_DATA, *PSMB_ALI_DATA;
  87. //
  88. // ALI SMBus control registers and bits
  89. //
  90. #define SMB_STS_REG (AliData->SmbBaseIo + 0)
  91. #define SMB_STS_ALERT_STS 0x01 //(1 << 0)
  92. #define SMB_STS_IDLE_STS 0x04 //(1 << 2) // Bus is idle
  93. #define SMB_STS_SMB_IDX_CLR 0x04 //(1 << 2) // Write SMB Index clear.
  94. #define SMB_STS_HOST_BSY 0x08 //(1 << 3) // Bus is busy - do not issue another bus cycle if this is set
  95. #define SMB_STS_SCI_I_STS 0x10 //(1 << 4) // command completed
  96. #define SMB_STS_DRV_ERR 0x20 //(1<<5)
  97. #define SMB_STS_BUS_ERR 0x40 //(1<<6)
  98. #define SMB_STS_FAILED 0x80 //(1<<7)
  99. #define SMB_STS_CLEAR 0xf1
  100. #define SMB_STS_ERRORS 0xe0
  101. #define SMB_STS_LAST_CMD_COMPLETED 0x14
  102. #define SMB_STS_CLEAR_DONE 0x11
  103. #define SMB_TYP_REG (AliData->SmbBaseIo + 1)
  104. #define SMB_TYP_MASK 0x70
  105. #define SMB_TYP_QUICK 0x00
  106. #define SMB_TYP_SEND 0x10
  107. #define SMB_TYP_BYTE 0x20
  108. #define SMB_TYP_WORD 0x30
  109. #define SMB_TYP_BLOCK 0x40
  110. #define SMB_TYP_PROCESS 0x50
  111. #define SMB_TYP_I2C 0x60
  112. #define SMB_TYP_KILL (1<<2)
  113. #define SMB_TYP_T_OUT_CMD (1<<3)
  114. #define STR_PORT_REG (AliData->SmbBaseIo + 2)
  115. #define STR_PORT_START 0xff
  116. #define DEV_ADDR_REG (AliData->SmbBaseIo + 3)
  117. #define DEV_DATA0_REG (AliData->SmbBaseIo + 4)
  118. #define DEV_DATA1_REG (AliData->SmbBaseIo + 5)
  119. #define BLK_DATA_REG (AliData->SmbBaseIo + 6)
  120. #define SMB_CMD_REG (AliData->SmbBaseIo + 7)
  121. NTSTATUS
  122. DriverEntry (
  123. IN PDRIVER_OBJECT DriverObject,
  124. IN PUNICODE_STRING RegistryPath
  125. );
  126. NTSTATUS
  127. SmbAliInitializeMiniport (
  128. IN PSMB_CLASS SmbClass,
  129. IN PVOID MiniportExtension,
  130. IN PVOID MiniportContext
  131. );
  132. NTSTATUS
  133. SmbAliAddDevice (
  134. IN PDRIVER_OBJECT DriverObject,
  135. IN PDEVICE_OBJECT Pdo
  136. );
  137. NTSTATUS
  138. SmbAliResetDevice (
  139. IN struct _SMB_CLASS* SmbClass,
  140. IN PVOID SmbMiniport
  141. );
  142. VOID
  143. SmbAliStartIo (
  144. IN struct _SMB_CLASS* SmbClass,
  145. IN PSMB_ALI_DATA AliData
  146. );
  147. VOID
  148. SmbAliInitTransactionDpc (
  149. IN struct _KDPC *Dpc,
  150. IN struct _SMB_CLASS* SmbClass,
  151. IN PVOID SystemArgument1,
  152. IN PVOID SystemArgument2
  153. );
  154. VOID
  155. SmbAliInitTransactionWorker (
  156. IN PDEVICE_OBJECT DeviceObject,
  157. IN struct _SMB_CLASS* SmbClass
  158. );
  159. VOID
  160. SmbAliCompleteTransactionDpc (
  161. IN struct _KDPC *Dpc,
  162. IN struct _SMB_CLASS* SmbClass,
  163. IN PVOID SystemArgument1,
  164. IN PVOID SystemArgument2
  165. );
  166. VOID
  167. SmbAliCompleteTransactionWorker (
  168. IN PDEVICE_OBJECT DeviceObject,
  169. IN struct _SMB_CLASS* SmbClass
  170. );
  171. NTSTATUS
  172. SmbAliStopDevice (
  173. IN struct _SMB_CLASS* SmbClass,
  174. IN PSMB_ALI_DATA AliData
  175. );
  176. VOID
  177. SmbAliNotifyHandler (
  178. IN PVOID Context,
  179. IN ULONG NotifyValue
  180. );
  181. VOID
  182. SmbAliWorkerThread (
  183. IN PDEVICE_OBJECT DeviceObject,
  184. IN PVOID Context
  185. );
  186. NTSTATUS
  187. SmbAliSyncronousIrpCompletion (
  188. IN PDEVICE_OBJECT DeviceObject,
  189. IN PIRP Irp,
  190. IN PVOID Context
  191. );
  192. BOOLEAN
  193. SmbAliTransactionComplete (
  194. PSMB_ALI_DATA AliData,
  195. PUCHAR SmbStatus
  196. );
  197. BOOLEAN
  198. SmbAliHostBusy (
  199. PSMB_ALI_DATA AliData
  200. );
  201. VOID
  202. SmbAliHandleAlert (
  203. PSMB_ALI_DATA AliData
  204. );
  205. VOID
  206. SmbAliResetBus (
  207. PSMB_ALI_DATA AliData
  208. );
  209. VOID
  210. SmbAliResetHost (
  211. PSMB_ALI_DATA AliData
  212. );
  213. VOID
  214. SmbAliStartDevicePolling (
  215. IN struct _SMB_CLASS* SmbClass
  216. );
  217. VOID
  218. SmbAliStopDevicePolling (
  219. IN struct _SMB_CLASS* SmbClass
  220. );