xref: /reactos/drivers/bus/acpi/cmbatt/cmbatt.h (revision a97fcf19)
1 /*
2  * PROJECT:         ReactOS ACPI-Compliant Control Method Battery
3  * LICENSE:         BSD - See COPYING.ARM in the top level directory
4  * FILE:            boot/drivers/bus/acpi/cmbatt/cmbatt.h
5  * PURPOSE:         Main Header File
6  * PROGRAMMERS:     ReactOS Portable Systems Group
7  */
8 
9 #ifndef _CMBATT_PCH_
10 #define _CMBATT_PCH_
11 
12 #include <wdm.h>
13 #include <batclass.h>
14 #include <wmilib.h>
15 #include <wdmguid.h>
16 
17 #define IOCTL_BATTERY_QUERY_UNIQUE_ID  \
18     CTL_CODE(FILE_DEVICE_BATTERY, 0x101, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294404
19 
20 #define IOCTL_BATTERY_QUERY_STA  \
21     CTL_CODE(FILE_DEVICE_BATTERY, 0x102, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294408
22 
23 #define IOCTL_BATTERY_QUERY_PSR  \
24     CTL_CODE(FILE_DEVICE_BATTERY, 0x103, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x29440C
25 
26 #define IOCTL_BATTERY_SET_TRIP_POINT \
27     CTL_CODE(FILE_DEVICE_BATTERY, 0x104, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294410
28 
29 #define IOCTL_BATTERY_QUERY_BIF_BIX \
30     CTL_CODE(FILE_DEVICE_BATTERY, 0x105, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294414
31 
32 #define IOCTL_BATTERY_QUERY_BST \
33     CTL_CODE(FILE_DEVICE_BATTERY, 0x106, METHOD_BUFFERED, FILE_READ_ACCESS) // 0x294418
34 
35 #define CMBATT_GENERIC_STATUS   0x01
36 #define CMBATT_GENERIC_INFO     0x02
37 #define CMBATT_GENERIC_WARNING  0x04
38 #define CMBATT_ACPI_WARNING     0x08
39 #define CMBATT_POWER_INFO       0x10
40 #define CMBATT_PNP_INFO         0x20
41 #define CMBATT_ACPI_ENTRY_EXIT  0x40
42 #define CMBATT_PNP_ENTRY_EXIT   0x200
43 #define CMBATT_ACPI_ASSERT      0x400
44 
45 //
46 // Constant used to determine if the battery was discharging
47 // for over 15 seconds since last time the AC adapter got unplugged.
48 //
49 #define CMBATT_DISCHARGE_TIME   150000000
50 
51 //
52 // Bogus constant used to determine if the remaining battery capacity
53 // overflows which is returned by the hardware.
54 //
55 #define CMBATT_CAPACITY_BOGUS   0x100000
56 
57 typedef enum _CMBATT_EXTENSION_TYPE
58 {
59     CmBattAcAdapter,
60     CmBattBattery
61 } CMBATT_EXTENSION_TYPE;
62 
63 #define ACPI_BUS_CHECK              0x00
64 #define ACPI_DEVICE_CHECK           0x01
65 
66 #define ACPI_STA_PRESENT            0x01
67 #define ACPI_STA_ENABLED            0x02
68 #define ACPI_STA_SHOW_UI            0x04
69 #define ACPI_STA_FUNCTIONAL         0x08
70 #define ACPI_STA_BATTERY_PRESENT    0x10
71 
72 #define ACPI_BATT_NOTIFY_STATUS     0x80
73 #define ACPI_BATT_NOTIFY_INFO       0x81
74 
75 #define ACPI_BATT_STAT_DISCHARG		0x0001
76 #define ACPI_BATT_STAT_CHARGING		0x0002
77 #define ACPI_BATT_STAT_CRITICAL		0x0004
78 
79 #define CM_MAX_VALUE                0x7FFFFFFF
80 #define CM_UNKNOWN_VALUE            0xFFFFFFFF
81 
82 #define CONVERT_MAH_TO_MWH(mA, Volts) (((mA) * (Volts) + 500) / 1000)
83 
84 #define CONVERT_BATT_INFO(Capacity, DesignVoltage) \
85     (((Capacity) != BATTERY_UNKNOWN_CAPACITY) \
86         ? CONVERT_MAH_TO_MWH((Capacity), (DesignVoltage)) \
87         : BATTERY_UNKNOWN_CAPACITY)
88 
89 typedef struct _ACPI_BST_DATA
90 {
91     ULONG State;
92     ULONG PresentRate;
93     ULONG RemainingCapacity;
94     ULONG PresentVoltage;
95 } ACPI_BST_DATA, *PACPI_BST_DATA;
96 
97 #define ACPI_BATT_POWER_UNIT_WATTS  0x0
98 #define ACPI_BATT_POWER_UNIT_AMPS   0x1
99 
100 #define ASCIIZ_MAX_LENGTH   256
101 
102 typedef struct _ACPI_BIF_DATA
103 {
104     ULONG PowerUnit;
105     ULONG DesignCapacity;
106     ULONG LastFullCapacity;
107     ULONG BatteryTechnology;
108     ULONG DesignVoltage;
109     ULONG DesignCapacityWarning;
110     ULONG DesignCapacityLow;
111     ULONG BatteryCapacityGranularity1;
112     ULONG BatteryCapacityGranularity2;
113     CHAR ModelNumber[ASCIIZ_MAX_LENGTH];
114     CHAR SerialNumber[ASCIIZ_MAX_LENGTH];
115     CHAR BatteryType[ASCIIZ_MAX_LENGTH];
116     CHAR OemInfo[ASCIIZ_MAX_LENGTH];
117 } ACPI_BIF_DATA, *PACPI_BIF_DATA;
118 
119 typedef struct _ACPI_BIX_DATA
120 {
121     ULONG Revision;
122     ULONG PowerUnit;
123     ULONG DesignCapacity;
124     ULONG LastFullCapacity;
125     ULONG BatteryTechnology;
126     ULONG DesignVoltage;
127     ULONG DesignCapacityWarning;
128     ULONG DesignCapacityLow;
129     ULONG CycleCount;
130     ULONG Accuracy;
131     ULONG MaxSampleTime;
132     ULONG MinSampleTime;
133     ULONG MaxAverageInterval;
134     ULONG MinAverageInterval;
135     ULONG BatteryCapacityGranularity1;
136     ULONG BatteryCapacityGranularity2;
137     CHAR ModelNumber[ASCIIZ_MAX_LENGTH];
138     CHAR SerialNumber[ASCIIZ_MAX_LENGTH];
139     CHAR BatteryType[ASCIIZ_MAX_LENGTH];
140     CHAR OemInfo[ASCIIZ_MAX_LENGTH];
141     ULONG SwapCapability;
142 } ACPI_BIX_DATA, *PACPI_BIX_DATA;
143 
144 typedef struct _ACPI_BATT_STATIC_INFO
145 {
146     ACPI_BIF_DATA BifData;
147     ACPI_BIX_DATA BixData;
148     BOOLEAN ExtendedData;
149 } ACPI_BATT_STATIC_INFO, *PACPI_BATT_STATIC_INFO;
150 
151 #define CMBATT_BATT_STATIC_INFO_TAG     'nItS'
152 
153 #define CMBATT_AR_NOTIFY            0x01
154 #define CMBATT_AR_INSERT            0x02
155 #define CMBATT_AR_REMOVE            0x04
156 
157 typedef struct _CMBATT_DEVICE_EXTENSION
158 {
159     CMBATT_EXTENSION_TYPE FdoType;
160     PDEVICE_OBJECT DeviceObject;
161     PDEVICE_OBJECT FdoDeviceObject;
162     PDEVICE_OBJECT PdoDeviceObject;
163     PDEVICE_OBJECT AttachedDevice;
164     FAST_MUTEX FastMutex;
165     ULONG HandleCount;
166     PIRP PowerIrp;
167     POWER_STATE PowerState;
168     WMILIB_CONTEXT WmiLibInfo;
169     BOOLEAN WaitWakeEnable;
170     IO_REMOVE_LOCK RemoveLock;
171     ULONG DeviceId;
172     PUNICODE_STRING DeviceName;
173     ACPI_INTERFACE_STANDARD AcpiInterface;
174     BOOLEAN DelayNotification;
175     BOOLEAN ArFlag;
176     PVOID ClassData;
177     BOOLEAN Started;
178     BOOLEAN NotifySent;
179     LONG ArLockValue;
180     ULONG TagData;
181     ULONG Tag;
182     ACPI_BST_DATA BstData;
183     ACPI_BATT_STATIC_INFO BattInfo;
184     ULONG Id;
185     ULONG State;
186     ULONG RemainingCapacity;
187     ULONG PresentVoltage;
188     ULONG Rate;
189     BATTERY_INFORMATION BatteryInformation;
190     ULONG BatteryCapacityGranularity1;
191     ULONG BatteryCapacityGranularity2;
192     BOOLEAN TripPointSet;
193     ULONG TripPointValue;
194     ULONG TripPointOld;
195     ULONGLONG InterruptTime;
196 } CMBATT_DEVICE_EXTENSION, *PCMBATT_DEVICE_EXTENSION;
197 
198 NTSTATUS
199 NTAPI
200 CmBattPowerDispatch(
201     PDEVICE_OBJECT DeviceObject,
202     PIRP Irp
203 );
204 
205 NTSTATUS
206 NTAPI
207 CmBattPnpDispatch(
208     PDEVICE_OBJECT DeviceObject,
209     PIRP Irp
210 );
211 
212 NTSTATUS
213 NTAPI
214 CmBattAddDevice(
215     PDRIVER_OBJECT DriverObject,
216     PDEVICE_OBJECT DeviceObject
217 );
218 
219 NTSTATUS
220 NTAPI
221 CmBattSystemControl(
222     PDEVICE_OBJECT DeviceObject,
223     PIRP Irp
224 );
225 
226 NTSTATUS
227 NTAPI
228 CmBattGetBstData(
229     PCMBATT_DEVICE_EXTENSION DeviceExtension,
230     PACPI_BST_DATA BstData
231 );
232 
233 NTSTATUS
234 NTAPI
235 CmBattGetPsrData(
236     PDEVICE_OBJECT DeviceObject,
237     PULONG PsrData
238 );
239 
240 NTSTATUS
241 NTAPI
242 CmBattGetStaData(
243     PDEVICE_OBJECT DeviceObject,
244     PULONG StaData
245 );
246 
247 NTSTATUS
248 NTAPI
249 CmBattGetBifData(
250     PCMBATT_DEVICE_EXTENSION DeviceExtension,
251     PACPI_BIF_DATA BifData
252 );
253 
254 NTSTATUS
255 NTAPI
256 CmBattGetBixData(
257     _In_ PCMBATT_DEVICE_EXTENSION DeviceExtension,
258     _Out_ PACPI_BIX_DATA BixData
259 );
260 
261 NTSTATUS
262 NTAPI
263 CmBattSetTripPpoint(
264     PCMBATT_DEVICE_EXTENSION DeviceExtension,
265     ULONG AlarmValue
266 );
267 
268 VOID
269 NTAPI
270 CmBattNotifyHandler(
271     IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
272     IN ULONG NotifyValue
273 );
274 
275 NTSTATUS
276 NTAPI
277 CmBattWmiDeRegistration(
278     PCMBATT_DEVICE_EXTENSION DeviceExtension
279 );
280 
281 NTSTATUS
282 NTAPI
283 CmBattWmiRegistration(
284     PCMBATT_DEVICE_EXTENSION DeviceExtension
285 );
286 
287 NTSTATUS
288 NTAPI
289 CmBattGetUniqueId(
290     PDEVICE_OBJECT DeviceObject,
291     PULONG UniqueId
292 );
293 
294 NTSTATUS
295 NTAPI
296 CmBattQueryInformation(
297     IN PCMBATT_DEVICE_EXTENSION FdoExtension,
298     IN ULONG Tag,
299     IN BATTERY_QUERY_INFORMATION_LEVEL InfoLevel,
300     IN OPTIONAL LONG AtRate,
301     IN PVOID Buffer,
302     IN ULONG BufferLength,
303     OUT PULONG ReturnedLength
304 );
305 
306 NTSTATUS
307 NTAPI
308 CmBattQueryStatus(
309     IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
310     IN ULONG Tag,
311     IN PBATTERY_STATUS BatteryStatus
312 );
313 
314 NTSTATUS
315 NTAPI
316 CmBattSetStatusNotify(
317     IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
318     IN ULONG BatteryTag,
319     IN PBATTERY_NOTIFY BatteryNotify
320 );
321 
322 NTSTATUS
323 NTAPI
324 CmBattDisableStatusNotify(
325     IN PCMBATT_DEVICE_EXTENSION DeviceExtension
326 );
327 
328 NTSTATUS
329 NTAPI
330 CmBattQueryTag(
331     IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
332     OUT PULONG Tag
333 );
334 
335 extern PDEVICE_OBJECT AcAdapterPdo;
336 extern ULONG CmBattDebug;
337 
338 #endif /* _CMBATT_PCH_ */
339