ReactOS 0.4.16-dev-752-g47bae01
compbatt.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Composite Battery Driver
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Composite battery main header file
5 * COPYRIGHT: Copyright 2010 ReactOS Portable Systems Group <ros.arm@reactos.org>
6 * Copyright 2024 George Bișoc <george.bisoc@reactos.org>
7 */
8
9/* INCLUDES *******************************************************************/
10
11#ifndef _COMPBATT_PCH_
12#define _COMPBATT_PCH_
13
14#include <wdm.h>
15#include <batclass.h>
16
17/* DEFINES ********************************************************************/
18
19//
20// I/O remove lock allocate tag
21//
22#define COMPBATT_TAG 'aBoC'
23
24//
25// Composite battery flags
26//
27#define COMPBATT_BATTERY_INFORMATION_PRESENT 0x04
28#define COMPBATT_STATUS_NOTIFY_SET 0x10
29#define COMPBATT_TAG_ASSIGNED 0x80
30
31//
32// IRP complete worker mode states
33//
34#define COMPBATT_QUERY_TAG 1
35#define COMPBATT_READ_STATUS 2
36
37//
38// Low/High capacity wait constants
39//
40#define COMPBATT_WAIT_MIN_LOW_CAPACITY 0
41#define COMPBATT_WAIT_MAX_HIGH_CAPACITY 0x7FFFFFFF
42
43//
44// One hour in seconds, used to calculate the total rate of each battery for time estimation
45//
46#define COMPBATT_ATRATE_HOUR_IN_SECS 3600
47
48//
49// Time constant of which the battery status data is considered fresh (50000000 * 100ns == 5s)
50//
51#define COMPBATT_FRESH_STATUS_TIME 50000000
52
53//
54// Macro that calculates the delta of a battery's capacity
55//
56#define COMPUTE_BATT_CAP_DELTA(LowDiff, Batt, TotalRate) \
57 ((ULONG)(((LONGLONG)LowDiff * (Batt)->BatteryStatus.Rate) / TotalRate))
58
59//
60// Macro that calculates the "At Rate" time drain of the battery
61//
62#define COMPUTE_ATRATE_DRAIN(Batt, Time) \
63 ((LONG)((Batt)->BatteryStatus.Capacity) * COMPBATT_ATRATE_HOUR_IN_SECS / Time)
64
65//
66// Composite battery debug levels
67//
68#define COMPBATT_DEBUG_INFO 0x1
69#define COMPBATT_DEBUG_TRACE 0x2
70#define COMPBATT_DEBUG_WARN 0x4
71#define COMPBATT_DEBUG_ERR 0x10
72#define COMPBATT_DEBUG_ALL_LEVELS (COMPBATT_DEBUG_INFO | COMPBATT_DEBUG_TRACE | COMPBATT_DEBUG_WARN | COMPBATT_DEBUG_ERR)
73
74/* STRUCTURES *****************************************************************/
75
76//
77// Individual ACPI battery data
78//
80{
81 /* The linked battery with the Composite Battery */
83
84 /* I/O remove lock which protects the battery from being removed */
86
87 /*
88 * The associated device object (usually CMBATT) and the I/O battery packet
89 * which is used to transport and gather battery data.
90 */
93
94 /*
95 * The Executive work item, which serves as a worker item for the
96 * IRP battery monitor worker.
97 */
99
100 /*
101 * Execution state mode of the individual battery. Only two modes are valid:
102 *
103 * COMPBATT_QUERY_TAG - The battery is currently waiting for a tag to get assigned;
104 * COMPBATT_READ_STATUS - The battery is querying battery status.
105 */
107
108 /*
109 * The battery wait configuration settings, set up by the SetStatusNotify method.
110 * These values are used to instruct CMBATT when the battery status should be retrieved.
111 */
113
114 /*
115 * A union that serves as the buffer which holds battery monitor IRP data, specifically
116 * managed by CompBattMonitorIrpCompleteWorker, to avoid allocating separate memory pools.
117 */
118 union
119 {
124
125 /* The ID of the battery that associates the identification of this battery */
127
128 /*
129 * The battery flags that govern the behavior of the battery. The valid flags are:
130 *
131 * COMPBATT_BATTERY_INFORMATION_PRESENT - The static battery information ha been
132 * queried. Re-querying such information is not needed.
133 *
134 * COMPBATT_STATUS_NOTIFY_SET - The current notification wait settings are valid.
135 *
136 * COMPBATT_TAG_ASSIGNED - The battery has a tag assigned and it can be read.
137 */
139
140 /* The static battery information and battery status */
143
144 /* The interrupt time of which the battery status was last read */
146
147 /* A uniquely given name of the battery that associates it */
150
151//
152// Composite battery device extension data
153//
155{
156 /*
157 * The class data initialized and used by Battery Class. It contains information
158 * such as miniport data used for registration and communication between the
159 * Composite Battery and Battery Class, wait and context events, etc.
160 */
162
163 /*
164 * The successor computed tag. This field is used when there are more upcoming
165 * batteries to be connected with the Composite Battery, of which the tag is
166 * incremented by 1 by each new battery that is connected.
167 */
169
170 /* A list of linked batteries connected with the Composite Battery */
172
173 /* A mutex lock which ensures proper synchronization of Composite Battery operations */
175
176 /* The ID of the Composite Battery */
178
179 /*
180 * The battery flags that govern the behavior of the battery. The valid flags are:
181 *
182 * COMPBATT_BATTERY_INFORMATION_PRESENT - The static battery information has been
183 * queried. Re-querying such information is not needed.
184 *
185 * COMPBATT_STATUS_NOTIFY_SET - The current notification wait settings are valid.
186 *
187 * COMPBATT_TAG_ASSIGNED - The battery has a tag assigned and it can be read.
188 */
190
191 /*
192 * The Composite Battery static information, status and wait status settings.
193 * Note that both the battery information and status are combined, based upon
194 * the individual information and status of each linked battery.
195 */
199
200 /* The interrupt time of which the battery status was last read */
202
203 /*
204 * The physical device object that associates the Composite Battery and
205 * the attached device, typically the ACPI driver.
206 */
209
210 /* The notification entry that identifies the registered I/O PnP notification */
213
214/* PROTOTYPES *****************************************************************/
215
217NTAPI
221);
222
224NTAPI
228);
229
231NTAPI
235);
236
238NTAPI
241 _In_ ULONG Tag,
247);
248
250NTAPI
252 _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension,
253 _In_ ULONG Tag,
255);
256
258NTAPI
261 _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension
262);
263
265NTAPI
267 _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension,
270);
271
273NTAPI
275 _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension
276);
277
279NTAPI
281 _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension,
283);
284
286NTAPI
289 _In_ PIRP Irp,
291);
292
293VOID
294NTAPI
296 _In_ PCOMPBATT_BATTERY_DATA BatteryData
297);
298
300NTAPI
306);
307
309NTAPI
318);
319
321NTAPI
323 _In_ PUNICODE_STRING BatteryName,
324 _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension
325);
326
327extern ULONG CompBattDebug;
328
329#endif /* _COMPBATT_PCH_ */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
_In_ ULONG _In_ PBATTERY_NOTIFY BatteryNotify
Definition: batclass.h:216
_Out_ PULONG BatteryTag
Definition: batclass.h:173
_In_ ULONG _Out_ PBATTERY_STATUS BatteryStatus
Definition: batclass.h:199
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG AtRate
Definition: batclass.h:185
enum _BATTERY_QUERY_INFORMATION_LEVEL BATTERY_QUERY_INFORMATION_LEVEL
Definition: bufpool.h:45
NTSTATUS NTAPI CompBattMonitorIrpComplete(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID Context)
Queues a work item thread worker which is bound to the individual CM (Control Method) ACPI battery to...
Definition: compbatt.c:92
NTSTATUS NTAPI CompBattPnpDispatch(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: comppnp.c:412
NTSTATUS NTAPI CompBattQueryStatus(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension, _In_ ULONG Tag, _Out_ PBATTERY_STATUS BatteryStatus)
Queries the battery status of each individiual connected battery with the composite battery and combi...
Definition: compbatt.c:932
NTSTATUS NTAPI CompBattRemoveBattery(_In_ PUNICODE_STRING BatteryName, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: comppnp.c:226
ULONG CompBattDebug
Definition: compbatt.c:17
NTSTATUS NTAPI CompBattQueryTag(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension, _Out_ PULONG Tag)
Definition: compbatt.c:453
NTSTATUS NTAPI CompBattQueryInformation(_In_ PCOMPBATT_DEVICE_EXTENSION FdoExtension, _In_ ULONG Tag, _In_ BATTERY_QUERY_INFORMATION_LEVEL InfoLevel, _In_opt_ LONG AtRate, _In_ PVOID Buffer, _In_ ULONG BufferLength, _Out_ PULONG ReturnedLength)
Definition: compbatt.c:1656
NTSTATUS NTAPI CompBattSetStatusNotify(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension, _In_ ULONG BatteryTag, _In_ PBATTERY_NOTIFY BatteryNotify)
Sets a new configuration battery wait status settings of each battery. The purpose of this is so that...
Definition: compbatt.c:676
struct _COMPBATT_BATTERY_DATA COMPBATT_BATTERY_DATA
struct _COMPBATT_BATTERY_DATA * PCOMPBATT_BATTERY_DATA
VOID NTAPI CompBattMonitorIrpCompleteWorker(_In_ PCOMPBATT_BATTERY_DATA BatteryData)
The brains of the battery IRP worker. It monitors the state of the IRP as well as sends the IRP down ...
Definition: compbatt.c:125
struct _COMPBATT_DEVICE_EXTENSION COMPBATT_DEVICE_EXTENSION
NTSTATUS NTAPI CompBattDisableStatusNotify(_In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Definition: compbatt.c:489
NTSTATUS NTAPI BatteryIoctl(_In_ ULONG IoControlCode, _In_ PDEVICE_OBJECT DeviceObject, _In_ PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_ PVOID OutputBuffer, _Inout_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl)
Definition: compmisc.c:16
NTSTATUS NTAPI CompBattPowerDispatch(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: comppnp.c:18
NTSTATUS NTAPI CompBattAddDevice(_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT PdoDeviceObject)
Definition: comppnp.c:328
NTSTATUS NTAPI CompBattGetEstimatedTime(_Out_ PULONG Time, _In_ PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
Retrieves the estimated time of the composite battery based on the power drain rate of all the batter...
Definition: compbatt.c:1500
struct _COMPBATT_DEVICE_EXTENSION * PCOMPBATT_DEVICE_EXTENSION
NTSTATUS NTAPI CompBattGetDeviceObjectPointer(_In_ PUNICODE_STRING DeviceName, _In_ ACCESS_MASK DesiredAccess, _Out_ PFILE_OBJECT *FileObject, _Out_ PDEVICE_OBJECT *DeviceObject)
Definition: compmisc.c:74
_In_ PIRP Irp
Definition: csq.h:116
@ FdoExtension
Definition: precomp.h:48
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT _In_ PUSB_PORT_PATH _Out_ PUSB_CD_ERROR_INFORMATION _In_ USHORT _In_ PDEVICE_OBJECT PdoDeviceObject
Definition: hubbusif.h:95
static PLARGE_INTEGER Time
Definition: time.c:105
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
ULONG ACCESS_MASK
Definition: nt_native.h:40
long LONG
Definition: pedump.c:60
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:91
BATTERY_WAIT_STATUS WorkerWaitStatus
Definition: compbatt.h:120
LIST_ENTRY BatteryLink
Definition: compbatt.h:82
BATTERY_STATUS WorkerStatus
Definition: compbatt.h:121
BATTERY_INFORMATION BatteryInformation
Definition: compbatt.h:141
BATTERY_WAIT_STATUS WaitStatus
Definition: compbatt.h:112
BATTERY_STATUS BatteryStatus
Definition: compbatt.h:142
UNICODE_STRING BatteryName
Definition: compbatt.h:148
WORK_QUEUE_ITEM WorkItem
Definition: compbatt.h:98
IO_REMOVE_LOCK RemoveLock
Definition: compbatt.h:85
ULONGLONG InterruptTime
Definition: compbatt.h:145
union _COMPBATT_BATTERY_DATA::@619 WorkerBuffer
BATTERY_WAIT_STATUS WaitNotifyStatus
Definition: compbatt.h:198
PDEVICE_OBJECT DeviceObject
Definition: compbatt.h:208
PDEVICE_OBJECT AttachedDevice
Definition: compbatt.h:207
BATTERY_INFORMATION BatteryInformation
Definition: compbatt.h:196
BATTERY_STATUS BatteryStatus
Definition: compbatt.h:197
Definition: typedefs.h:120
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
FAST_MUTEX
Definition: extypes.h:17
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID _In_ ULONG _In_ BOOLEAN InternalDeviceIoControl
Definition: iofuncs.h:720
* PFILE_OBJECT
Definition: iotypes.h:1998
unsigned char UCHAR
Definition: xmlstorage.h:181