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.

498 lines
12 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ecp.h
  5. Abstract:
  6. Header file for ACPI EC Driver
  7. Author:
  8. Environment:
  9. NT Kernel Model Driver only
  10. --*/
  11. #include <wdm.h>
  12. #include <ec.h>
  13. #include <devioctl.h>
  14. #include <acpiioct.h>
  15. #include <acpimsft.h>
  16. #include "errlog.h"
  17. //
  18. // Debugging
  19. //
  20. #define DEBUG DBG
  21. #if DEBUG
  22. extern ULONG ECDebug;
  23. #define EcPrint(l,m) if(l & ECDebug) DbgPrint m
  24. #else
  25. #define EcPrint(l,m)
  26. #endif
  27. #define EC_LOW 0x00000010
  28. #define EC_NOTE 0x00000001
  29. #define EC_WARN 0x00000002
  30. #define EC_ERROR 0x00000004
  31. #define EC_ERRORS (EC_ERROR | EC_WARN)
  32. #define EC_HANDLER 0x00000020
  33. #define EC_IO 0x00000040
  34. #define EC_OPREGION 0x00000080
  35. #define EC_QUERY 0x00000200
  36. #define EC_TRACE 0x00000400
  37. #define EC_TRANSACTION 0x00000800
  38. //
  39. // Control methods used by EC
  40. //
  41. #define CM_GPE_METHOD (ULONG) ('EPG_') // control method "_GPE"
  42. //
  43. // Misc
  44. //
  45. extern ACPI_INTERFACE_STANDARD AcpiInterfaces;
  46. #define MAX_QUERY 255
  47. #define BITS_PER_ULONG (sizeof(ULONG)*8)
  48. #define EVTBITS ((MAX_QUERY+1)/BITS_PER_ULONG)
  49. extern LARGE_INTEGER AcpiEcWatchdogTimeout;
  50. //
  51. // Query vector
  52. //
  53. typedef struct {
  54. UCHAR Next;
  55. UCHAR Vector;
  56. PVECTOR_HANDLER Handler;
  57. PVOID Context;
  58. } VECTOR_TABLE, *PVECTOR_TABLE;
  59. //
  60. // EC configuration information structure contains information
  61. // about the embedded controller attached and its configuration.
  62. //
  63. typedef struct _ACPIEC_CONFIGURATION_INFORMATION {
  64. INTERFACE_TYPE InterfaceType;
  65. ULONG BusNumber;
  66. ULONG SlotNumber;
  67. PHYSICAL_ADDRESS PortAddress;
  68. USHORT PortSize;
  69. USHORT UntranslatedPortAddress;
  70. CM_PARTIAL_RESOURCE_DESCRIPTOR Interrupt;
  71. //
  72. // For PCI-based controllers, indicates the pin number which we need
  73. // for programming the controller interrupt
  74. //
  75. UCHAR InterruptPin;
  76. BOOLEAN FloatingSave;
  77. } ACPIEC_CONFIGURATION_INFORMATION, *PACPIEC_CONFIGURATION_INFORMATION;
  78. //
  79. // Definitions for keeping track of the last x actions taken by the EC driver.
  80. //
  81. #define ACPIEC_ACTION_COUNT 0x20
  82. #define ACPIEC_ACTION_COUNT_MASK 0x1f
  83. typedef struct {
  84. UCHAR IoStateAction; // EcData->IoState | EC_ACTION_???? (see definitions below)
  85. UCHAR Data; // Depends on event
  86. USHORT Time; // Delta time of first event of identical events
  87. } ACPIEC_ACTION, *PACPIEC_ACTION;
  88. #define EC_ACTION_MASK 0xf0
  89. #define EC_ACTION_READ_STATUS 0x10
  90. #define EC_ACTION_READ_DATA 0x20
  91. #define EC_ACTION_WRITE_CMD 0x30
  92. #define EC_ACTION_WRITE_DATA 0x40
  93. #define EC_ACTION_INTERRUPT 0x50
  94. #define EC_ACTION_DISABLE_GPE 0x60
  95. #define EC_ACTION_ENABLE_GPE 0x70
  96. #define EC_ACTION_CLEAR_GPE 0x80
  97. #define EC_ACTION_QUEUED_IO 0x90
  98. #define EC_ACTION_REPEATED 0xa0
  99. #define EC_ACTION_MAX 0xb0
  100. //
  101. // ACPI Embedded Control Device object extenstion
  102. //
  103. typedef struct {
  104. PDEVICE_OBJECT DeviceObject;
  105. PDEVICE_OBJECT NextFdo;
  106. PDEVICE_OBJECT Pdo; //Pdo corresponding to this fdo
  107. PDEVICE_OBJECT LowerDeviceObject;
  108. //
  109. // Static device information
  110. //
  111. PUCHAR DataPort; // EC Data port
  112. PUCHAR StatusPort; // EC Status port
  113. PUCHAR CommandPort; // EC Command port
  114. ULONG MaxBurstStall; // Max delay for EC reponse in burst mode
  115. ULONG MaxNonBurstStall; // Max delay for EC otherwise
  116. BOOLEAN IsStarted;
  117. //
  118. // Gpe and Operation Region info
  119. //
  120. PVOID EnableGpe;
  121. PVOID DisableGpe;
  122. PVOID ClearGpeStatus;
  123. PVOID GpeVectorObject; // Object representing attachment to the EC GPE vector
  124. ULONG GpeVector; // GPE vector assigned to the EC device
  125. PVOID OperationRegionObject; // Attachment to the EC operation region
  126. ACPIEC_CONFIGURATION_INFORMATION Configuration;
  127. //
  128. // Lock for device data
  129. //
  130. KSPIN_LOCK Lock; // Lock device data
  131. //
  132. // Device maintenance
  133. //
  134. KEVENT Unload; // Event to wait of for unload
  135. UCHAR DeviceState;
  136. //
  137. // Query/vector operations
  138. //
  139. UCHAR QueryState;
  140. UCHAR VectorState;
  141. ULONG QuerySet[EVTBITS]; // If pending or not
  142. ULONG QueryType[EVTBITS]; // Type of Query or Vector
  143. PIRP QueryRequest; // IRP to execute query methods
  144. UCHAR QueryMap[MAX_QUERY+1]; // Query pending list and vector table map
  145. UCHAR QueryHead; // List of pending queries
  146. UCHAR VectorHead; // List of pending vectors
  147. UCHAR VectorFree; // List of free vectors entries
  148. UCHAR VectorTableSize; // Sizeof vector table
  149. PVECTOR_TABLE VectorTable;
  150. //
  151. // Device's work queue (owned by Lock owner)
  152. //
  153. BOOLEAN InService; // Serialize in service
  154. BOOLEAN InServiceLoop; // Flag when in service needs to loop
  155. BOOLEAN InterruptEnabled; // Masked or not
  156. LIST_ENTRY WorkQueue; // Queued IO IRPs to the device
  157. PIRP MiscRequest; // IRP for start/stop device
  158. //
  159. // Data IO (owned by InService owner)
  160. //
  161. UCHAR IoState; // Io state
  162. UCHAR IoBurstState; // Pushed state for burst enable
  163. UCHAR IoTransferMode; // read or write transfer
  164. UCHAR IoAddress; // Address in EC for transfer
  165. UCHAR IoLength; // Length of transfer
  166. UCHAR IoRemain; // Length remaining of transfer
  167. PUCHAR IoBuffer; // RAM location for transfer
  168. //
  169. // Watchdog Timer to catch hung and/or malfunctioning ECs
  170. //
  171. UCHAR ConsecutiveFailures;// Count how many times watdog fired without making progress.
  172. UCHAR LastAction; // Index into RecentActions array.
  173. LARGE_INTEGER PerformanceFrequency;
  174. KTIMER WatchdogTimer;
  175. KDPC WatchdogDpc;
  176. ACPIEC_ACTION RecentActions [ACPIEC_ACTION_COUNT];
  177. //
  178. // Stats
  179. //
  180. ULONG NonBurstTimeout;
  181. ULONG BurstTimeout;
  182. ULONG BurstComplete;
  183. ULONG BurstAborted;
  184. ULONG TotalBursts;
  185. ULONG Errors;
  186. ULONG MaxServiceLoop;
  187. } ECDATA, *PECDATA;
  188. //
  189. // DeviceState
  190. //
  191. #define EC_DEVICE_WORKING 0
  192. #define EC_DEVICE_UNLOAD_PENDING 1
  193. #define EC_DEVICE_UNLOAD_CANCEL_TIMER 2
  194. #define EC_DEVICE_UNLOAD_COMPLETE 3
  195. //
  196. // QueryState
  197. //
  198. #define EC_QUERY_IDLE 0
  199. #define EC_QUERY_DISPATCH 1
  200. #define EC_QUERY_DISPATCH_WAITING 2
  201. #define EC_QUERY_DISPATCH_COMPLETE 3
  202. //
  203. // Embedded Control read state
  204. //
  205. #define EC_IO_NONE 0 // Idle
  206. #define EC_IO_READ_BYTE 1 // Read byte on OBF
  207. #define EC_IO_READ_QUERY 2 // Query response on OBF
  208. #define EC_IO_BURST_ACK 3 // Brust ACK on OBF
  209. #define EC_IO_WRITE_BYTE 4 // Write byte on IBE
  210. #define EC_IO_NEXT_BYTE 5 // Issue read/write on IBE
  211. #define EC_IO_SEND_ADDRESS 6 // Send transfer address on IBE
  212. #define EC_IO_UNKNOWN 7
  213. //
  214. // Status port definitions
  215. //
  216. #define EC_OUTPUT_FULL 0x01 // Output buffer full (data from EC to Host)
  217. #define EC_INPUT_FULL 0x02 // Input buffer full (data from Host to EC)
  218. #define EC_BURST 0x10 // In burst transfer
  219. #define EC_QEVT_PENDING 0x20 // Query event is pending
  220. #define EC_BUSY 0x80 // Device is busy
  221. //
  222. // Embedded controller commands
  223. //
  224. #define EC_READ_BYTE 0x80
  225. #define EC_WRITE_BYTE 0x81
  226. #define EC_BURST_TRANSFER 0x82
  227. #define EC_CANCEL_BURST 0x83
  228. #define EC_QUERY_EVENT 0x84
  229. //
  230. // Prototypes
  231. //
  232. NTSTATUS
  233. AcpiEcSynchronousRequest (
  234. IN PDEVICE_OBJECT DeviceObject,
  235. IN PIRP Irp,
  236. IN PVOID Context
  237. );
  238. NTSTATUS
  239. AcpiEcNewEc (
  240. IN PDEVICE_OBJECT Fdo
  241. );
  242. NTSTATUS
  243. AcpiEcOpenClose(
  244. IN PDEVICE_OBJECT DeviceObject,
  245. IN PIRP Irp
  246. );
  247. NTSTATUS
  248. AcpiEcReadWrite(
  249. IN PDEVICE_OBJECT DeviceObject,
  250. IN PIRP Irp
  251. );
  252. NTSTATUS
  253. AcpiEcInternalControl(
  254. IN PDEVICE_OBJECT DeviceObject,
  255. IN PIRP Irp
  256. );
  257. NTSTATUS
  258. AcpiEcForwardRequest(
  259. IN PDEVICE_OBJECT DeviceObject,
  260. IN PIRP Irp
  261. );
  262. VOID
  263. AcpiEcUnload(
  264. IN PDRIVER_OBJECT DriverObject
  265. );
  266. BOOLEAN
  267. AcpiEcGpeServiceRoutine (
  268. IN PVOID GpeVectorObject,
  269. IN PVOID ServiceContext
  270. );
  271. VOID
  272. AcpiEcServiceDevice (
  273. IN PECDATA EcData
  274. );
  275. VOID
  276. AcpiEcDispatchQueries (
  277. IN PECDATA EcData
  278. );
  279. VOID
  280. AcpiEcUnloadPending (
  281. IN PECDATA EcData
  282. );
  283. NTSTATUS
  284. AcpiEcConnectHandler (
  285. IN PECDATA EcData,
  286. IN PIRP Irp
  287. );
  288. NTSTATUS
  289. AcpiEcDisconnectHandler (
  290. IN PECDATA EcData,
  291. IN PIRP Irp
  292. );
  293. NTSTATUS
  294. AcpiEcGetPdo (
  295. IN PECDATA EcData,
  296. IN PIRP Irp
  297. );
  298. NTSTATUS EXPORT
  299. AcpiEcOpRegionHandler (
  300. ULONG AccessType,
  301. PVOID OpRegion,
  302. ULONG Address,
  303. ULONG Size,
  304. PULONG Data,
  305. ULONG_PTR Context,
  306. PACPI_OPREGION_CALLBACK CompletionHandler,
  307. PVOID CompletionContext
  308. );
  309. NTSTATUS
  310. AcpiEcGetAcpiInterfaces (
  311. IN PECDATA EcData
  312. );
  313. NTSTATUS
  314. AcpiEcGetGpeVector (
  315. IN PECDATA EcData
  316. );
  317. NTSTATUS
  318. AcpiEcConnectGpeVector (
  319. IN PECDATA EcData
  320. );
  321. NTSTATUS
  322. AcpiEcDisconnectGpeVector (
  323. IN PECDATA EcData
  324. );
  325. NTSTATUS
  326. AcpiEcInstallOpRegionHandler (
  327. IN PECDATA EcData
  328. );
  329. NTSTATUS
  330. AcpiEcRemoveOpRegionHandler (
  331. IN PECDATA EcData
  332. );
  333. NTSTATUS
  334. AcpiEcForwardIrpAndWait (
  335. IN PECDATA EcData,
  336. IN PIRP Irp
  337. );
  338. NTSTATUS
  339. AcpiEcIoCompletion(
  340. IN PDEVICE_OBJECT DeviceObject,
  341. IN PIRP Irp,
  342. IN PKEVENT pdoIoCompletedEvent
  343. );
  344. NTSTATUS
  345. AcpiEcAddDevice(
  346. IN PDRIVER_OBJECT DriverObject,
  347. IN PDEVICE_OBJECT Pdo
  348. );
  349. NTSTATUS
  350. AcpiEcStartDevice(
  351. IN PDEVICE_OBJECT Fdo,
  352. IN PIRP Irp
  353. );
  354. NTSTATUS
  355. AcpiEcStopDevice(
  356. IN PDEVICE_OBJECT Fdo,
  357. IN PIRP Irp
  358. );
  359. NTSTATUS
  360. AcpiEcCreateFdo(
  361. IN PDRIVER_OBJECT DriverObject,
  362. OUT PDEVICE_OBJECT *NewDeviceObject
  363. );
  364. VOID
  365. AcpiEcServiceIoLoop (
  366. IN PECDATA EcData
  367. );
  368. VOID
  369. AcpiEcDispatchQueries (
  370. IN PECDATA EcData
  371. );
  372. VOID
  373. AcpiEcWatchdogDpc(
  374. IN PKDPC Dpc,
  375. IN PECDATA EcData,
  376. IN PVOID SystemArgument1,
  377. IN PVOID SystemArgument2
  378. );
  379. VOID
  380. AcpiEcLogAction (
  381. PECDATA EcData,
  382. UCHAR Action,
  383. UCHAR Data
  384. );
  385. VOID
  386. AcpiEcLogError (
  387. PECDATA EcData,
  388. NTSTATUS ErrCode
  389. );
  390. //
  391. // Io extension macro to just pass on the Irp to a lower driver
  392. //
  393. #define AcpiEcCallLowerDriver(Status, DeviceObject, Irp) { \
  394. IoSkipCurrentIrpStackLocation(Irp); \
  395. Status = IoCallDriver(DeviceObject,Irp); \
  396. }