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.

511 lines
15 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ospower.h
  5. Abstract:
  6. This contains the OS-shared power structures. These varify depending
  7. on the OS that is being used
  8. Author:
  9. Stephane Plante (splante)
  10. Environment:
  11. NT Kernel Model Driver only
  12. --*/
  13. #ifndef _OSPOWER_H_
  14. #define _OSPOWER_H_
  15. //
  16. // Makesure that the _DEVICE_EXTENSION structure is defined
  17. //
  18. struct _DEVICE_EXTENSION;
  19. //
  20. // These are the flags that can used with the Power Device Node
  21. //
  22. #define DEVICE_NODE_PRESENT 0x0001
  23. #define DEVICE_NODE_INITIALIZED 0x0002
  24. #define DEVICE_NODE_STA_UNKNOWN 0x0004
  25. #define DEVICE_NODE_ON 0x0010
  26. #define DEVICE_NODE_OVERRIDE_ON 0x0020
  27. #define DEVICE_NODE_OVERRIDE_OFF 0x0040
  28. #define DEVICE_NODE_ALWAYS_ON 0x0200
  29. #define DEVICE_NODE_ALWAYS_OFF 0x0400
  30. //
  31. // These are fast macros
  32. //
  33. #define DEVICE_NODE_TURN_ON (DEVICE_NODE_OVERRIDE_ON | DEVICE_NODE_ALWAYS_ON)
  34. #define DEVICE_NODE_TURN_OFF (DEVICE_NODE_OVERRIDE_OFF | DEVICE_NODE_ALWAYS_OFF)
  35. //
  36. // These flags are more for status of the device node. Note that the
  37. // Hibernate Path flags requires special handling
  38. //
  39. #define DEVICE_NODE_FAIL 0x10000
  40. #define DEVICE_NODE_HIBERNATE_PATH 0x20000
  41. //
  42. // These are the various request flags for device requests
  43. //
  44. #define DEVICE_REQUEST_DELAYED 0x00000001
  45. #define DEVICE_REQUEST_NO_QUEUE 0x00000002
  46. #define DEVICE_REQUEST_LOCK_DEVICE 0x00000004
  47. #define DEVICE_REQUEST_UNLOCK_DEVICE 0x00000008
  48. #define DEVICE_REQUEST_LOCK_HIBER 0x00000010
  49. #define DEVICE_REQUEST_UNLOCK_HIBER 0x00000020
  50. #define DEVICE_REQUEST_HAS_CANCEL 0x00000040
  51. #define DEVICE_REQUEST_UPDATE_HW_PROFILE 0x00000080
  52. #define DEVICE_REQUEST_TO_SYNC_QUEUE 0x00000100
  53. //
  54. // These values are used with WorkDone variables and InterlockedXXX
  55. // functions to synchronize the various phases of DevicePowerManagement
  56. //
  57. typedef enum _WORK_DONE {
  58. WORK_DONE_COMPLETE = 0,
  59. WORK_DONE_PENDING,
  60. WORK_DONE_FAILURE,
  61. WORK_DONE_STEP_0,
  62. WORK_DONE_STEP_1,
  63. WORK_DONE_STEP_2,
  64. WORK_DONE_STEP_3,
  65. WORK_DONE_STEP_4,
  66. WORK_DONE_STEP_5,
  67. WORK_DONE_STEP_6,
  68. WORK_DONE_STEP_7,
  69. WORK_DONE_STEP_8,
  70. WORK_DONE_STEP_9,
  71. WORK_DONE_STEP_10,
  72. WORK_DONE_STEP_11,
  73. WORK_DONE_STEP_12,
  74. WORK_DONE_STEP_13,
  75. WORK_DONE_STEP_14,
  76. WORK_DONE_STEP_15,
  77. WORK_DONE_STEP_16,
  78. WORK_DONE_STEP_17,
  79. WORK_DONE_STEP_18,
  80. WORK_DONE_STEP_19,
  81. WORK_DONE_STEP_20,
  82. WORK_DONE_STEP_21,
  83. WORK_DONE_STEP_22,
  84. WORK_DONE_STEP_23,
  85. WORK_DONE_STEP_24,
  86. WORK_DONE_STEP_25,
  87. WORK_DONE_STEP_26,
  88. } WORK_DONE;
  89. //
  90. // This describes a single power device node
  91. //
  92. // This used to be called a POWERDEVICEDEPENCIES
  93. // but that was to hard to type out
  94. //
  95. typedef struct _ACPI_POWER_DEVICE_NODE {
  96. //
  97. // Keeps the things in order
  98. //
  99. LIST_ENTRY ListEntry;
  100. //
  101. // This define the current device state and flags
  102. //
  103. union{
  104. ULONGLONG Flags;
  105. struct {
  106. ULONGLONG Present:1;
  107. ULONGLONG Initialized:1;
  108. ULONGLONG StatusUnknown:1;
  109. ULONGLONG On:1;
  110. ULONGLONG OverrideOn:1;
  111. ULONGLONG OverrideOff:1;
  112. ULONGLONG AlwaysOn:1;
  113. ULONGLONG AlwaysOff:1;
  114. ULONGLONG Reserved1:5;
  115. ULONGLONG Failed:1;
  116. ULONGLONG HibernatePath:1;
  117. ULONGLONG Reserved2:49;
  118. } UFlags;
  119. };
  120. //
  121. // How many references there are to the node
  122. //
  123. ULONG UseCounts;
  124. //
  125. // The name space object associated with the power node
  126. //
  127. PNSOBJ PowerObject;
  128. //
  129. // The resource order
  130. //
  131. UCHAR ResourceOrder;
  132. //
  133. // The supported system level
  134. //
  135. SYSTEM_POWER_STATE SystemLevel;
  136. //
  137. // This is the head of a list of DPNs that are associated with this
  138. // PDN
  139. //
  140. LIST_ENTRY DevicePowerListHead;
  141. //
  142. // This reflects the amount of work that has been done on the
  143. // DeviceNode
  144. //
  145. ULONG WorkDone;
  146. //
  147. // This is a pointer to the on function
  148. //
  149. PNSOBJ PowerOnObject;
  150. //
  151. // This is a pointer to the off function
  152. //
  153. PNSOBJ PowerOffObject;
  154. //
  155. // This is a pointer to the sta function
  156. //
  157. PNSOBJ PowerStaObject;
  158. } ACPI_POWER_DEVICE_NODE, *PACPI_POWER_DEVICE_NODE;
  159. //
  160. // This describes a single power node for a devices list of power reqs
  161. //
  162. // This was known as a POWER_RES_LIST_NODE. Again that was a pain
  163. // to type and it didn't quite do what I need it to do
  164. //
  165. typedef struct _ACPI_DEVICE_POWER_NODE {
  166. //
  167. // Contains pointer to next element
  168. //
  169. struct _ACPI_DEVICE_POWER_NODE *Next;
  170. //
  171. // Pointer to actual power resource
  172. //
  173. PACPI_POWER_DEVICE_NODE PowerNode;
  174. //
  175. // This is the system level that is supported for this node
  176. //
  177. SYSTEM_POWER_STATE SystemState;
  178. //
  179. // This is the device power level of the device that this node
  180. // is associated with
  181. //
  182. DEVICE_POWER_STATE AssociatedDeviceState;
  183. //
  184. // This determines if the Device Power Node is on the wake path
  185. // or not
  186. //
  187. BOOLEAN WakePowerResource;
  188. //
  189. // This is a pointer back to the DeviceExtension
  190. //
  191. struct _DEVICE_EXTENSION *DeviceExtension;
  192. //
  193. // This is the list that is used to link all of the DPN attached
  194. // to a single PDN.
  195. //
  196. LIST_ENTRY DevicePowerListEntry;
  197. } ACPI_DEVICE_POWER_NODE, *PACPI_DEVICE_POWER_NODE;
  198. //
  199. // This callback is used for handling power requests which must be
  200. // processed through the main power DPC. Win9x does not use this
  201. // approach to power managament
  202. //
  203. typedef VOID ( *PACPI_POWER_CALLBACK )(PDEVICE_EXTENSION, PVOID, NTSTATUS);
  204. typedef enum {
  205. AcpiPowerRequestDevice = 0,
  206. AcpiPowerRequestSystem,
  207. AcpiPowerRequestWaitWake,
  208. AcpiPowerRequestWarmEject,
  209. AcpiPowerRequestSynchronize,
  210. AcpiPowerRequestMaximum
  211. } ACPI_POWER_REQUEST_TYPE;
  212. //
  213. // This is how we describe the power requests that we have outstanding
  214. // on a single device extension
  215. //
  216. typedef struct _ACPI_POWER_REQUEST {
  217. //
  218. // This is the ListEntry used to chain all the PowerRequests on
  219. // the same queue
  220. //
  221. LIST_ENTRY ListEntry;
  222. //
  223. // This is the ListEntry used to chain all the PowerRequests on the
  224. // same device/irp. These requests are processed in serial
  225. //
  226. LIST_ENTRY SerialListEntry;
  227. //
  228. // This is the signature block --- if this is not the value we expect,
  229. // then we assume the request is garbage
  230. //
  231. ULONG Signature;
  232. //
  233. // This is a pointer to the associated DeviceExtension
  234. //
  235. struct _DEVICE_EXTENSION *DeviceExtension;
  236. //
  237. // This is the type of request
  238. //
  239. ACPI_POWER_REQUEST_TYPE RequestType;
  240. //
  241. // Has this request failed already?
  242. //
  243. BOOLEAN FailedOnce;
  244. //
  245. // Holds information about what we need to do for the various
  246. // requests
  247. //
  248. union {
  249. //
  250. // This is the Information required by a DevicePower request
  251. //
  252. struct {
  253. ULONG Flags;
  254. DEVICE_POWER_STATE DevicePowerState;
  255. } DevicePowerRequest;
  256. //
  257. // This is the Information required by a SystemPower request
  258. //
  259. struct {
  260. SYSTEM_POWER_STATE SystemPowerState;
  261. POWER_ACTION SystemPowerAction;
  262. } SystemPowerRequest;
  263. //
  264. // This is the Information required by a WaitWake request
  265. //
  266. struct {
  267. ULONG Flags;
  268. SYSTEM_POWER_STATE SystemPowerState;
  269. } WaitWakeRequest;
  270. //
  271. // This is the information required by the WarmEject request
  272. //
  273. struct {
  274. ULONG Flags;
  275. SYSTEM_POWER_STATE EjectPowerState;
  276. } EjectPowerRequest;
  277. //
  278. // This is the information required by the Synchronize request
  279. //
  280. struct {
  281. ULONG Flags;
  282. } SynchronizePowerRequest;
  283. //
  284. // Make the flags easy to access...
  285. //
  286. struct {
  287. ULONG Delayed:1;
  288. ULONG NoQueue:1;
  289. ULONG LockDevice:1;
  290. ULONG UnlockDevice:1;
  291. ULONG LockHiber:1;
  292. ULONG UnlockHiber:1;
  293. ULONG HasCancel:1;
  294. ULONG UpdateProfile:1;
  295. ULONG SyncQueue:1;
  296. ULONG Reserved:23;
  297. } UFlags;
  298. } u;
  299. //
  300. // This is the routine that will get called when the request is
  301. // done
  302. //
  303. PACPI_POWER_CALLBACK CallBack;
  304. //
  305. // This is the context that will be passed to the completion routine
  306. //
  307. PVOID Context;
  308. //
  309. // This defines the amount of work that has been done on the
  310. // request. This can only be touched with an InterlockedXXX call
  311. //
  312. ULONG WorkDone;
  313. //
  314. // This is the next value for WorkDone, if we have been successfull
  315. //
  316. ULONG NextWorkDone;
  317. //
  318. // Since we sometimes need to get data back from the interpreter,
  319. // we need some place to store that data
  320. //
  321. OBJDATA ResultData;
  322. //
  323. // This is the result of the request
  324. //
  325. NTSTATUS Status;
  326. } ACPI_POWER_REQUEST, *PACPI_POWER_REQUEST;
  327. //
  328. // Define the power information
  329. //
  330. // This was known as a DEVICEPOWERDEPENDENCIES. But that
  331. // was incredibly confusing and not quite suited to my needs
  332. //
  333. typedef struct _ACPI_POWER_INFO {
  334. //
  335. // Context is the OS object we are associated with, either a
  336. // device node or a device extension
  337. //
  338. PVOID Context;
  339. //
  340. // Current State of the device
  341. //
  342. DEVICE_POWER_STATE PowerState;
  343. //
  344. // This is the notify callback (and context) for the current device
  345. //
  346. PDEVICE_NOTIFY_CALLBACK DeviceNotifyHandler;
  347. PVOID HandlerContext;
  348. //
  349. // This is an array of powerNodes, which point to Wake, D0, D1, and D2,
  350. // respectively
  351. //
  352. PACPI_DEVICE_POWER_NODE PowerNode[PowerDeviceD2+1];
  353. //
  354. // This is an array of PowerObjects, which represent _PS0 to _PS3
  355. // and _PRW
  356. //
  357. PNSOBJ PowerObject[PowerDeviceD3+1];
  358. //
  359. // This is the Enable bit for the GPE mask for Wake support
  360. //
  361. ULONG WakeBit;
  362. //
  363. // We want to remember the devices capabilities so that we can dump
  364. // it out at some later point in time.
  365. //
  366. DEVICE_POWER_STATE DevicePowerMatrix[PowerSystemMaximum];
  367. //
  368. // This is the deepest sleep level that can used and at the same
  369. // time, have the device wake the system
  370. //
  371. SYSTEM_POWER_STATE SystemWakeLevel;
  372. //
  373. // This is the deepest power level that the device can be in and
  374. // still wake up the system
  375. //
  376. DEVICE_POWER_STATE DeviceWakeLevel;
  377. //
  378. // This is the current desired state of the device
  379. //
  380. DEVICE_POWER_STATE DesiredPowerState;
  381. //
  382. // This keeps track of the number of times the device has
  383. // been enabled for Wake Support. On a 0-1 transition, we
  384. // must run _PSW(1). On a 1-0 transition, we must run _PSW(0).
  385. //
  386. ULONG WakeSupportCount;
  387. //
  388. // This is the list of pending _PSW calls
  389. //
  390. LIST_ENTRY WakeSupportList;
  391. //
  392. // This is a pointer associated with the current PowerRequest
  393. //
  394. PACPI_POWER_REQUEST CurrentPowerRequest;
  395. //
  396. // This is the queue that is used to link the PowerRequests associated
  397. // with this device. Note: that this list is *only* for DevicePower
  398. // requests with no associated Irps
  399. //
  400. LIST_ENTRY PowerRequestListEntry;
  401. //
  402. // Remember what we support so that we can answer the QueryCapibilities
  403. //
  404. ULONG SupportDeviceD1 : 1;
  405. ULONG SupportDeviceD2 : 1;
  406. ULONG SupportWakeFromD0 : 1;
  407. ULONG SupportWakeFromD1 : 1;
  408. ULONG SupportWakeFromD2 : 1;
  409. ULONG SupportWakeFromD3 : 1;
  410. ULONG Reserved :26;
  411. } ACPI_POWER_INFO, *PACPI_POWER_INFO;
  412. //
  413. // Find the power information for the given node
  414. //
  415. PACPI_POWER_INFO
  416. OSPowerFindPowerInfo(
  417. PNSOBJ AcpiObject
  418. );
  419. PACPI_POWER_INFO
  420. OSPowerFindPowerInfoByContext(
  421. PVOID Context
  422. );
  423. PACPI_POWER_DEVICE_NODE
  424. OSPowerFindPowerNode(
  425. PNSOBJ PowerObject
  426. );
  427. #endif