Skip to content

Commit 3fe9e88

Browse files
committed
[COMPBATT][CMBATT][BATTC] Enable debug logging & resuscitate these drivers
1 parent 921cfd8 commit 3fe9e88

File tree

7 files changed

+1323
-150
lines changed

7 files changed

+1323
-150
lines changed

drivers/battery/battc/battc.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ BatteryClassStatusNotify(PVOID ClassData)
8181
PBATTERY_CLASS_DATA BattClass;
8282
PBATTERY_WAIT_STATUS BattWait;
8383
BATTERY_STATUS BattStatus;
84+
ULONG Tag;
8485
NTSTATUS Status;
8586

8687
DPRINT("Received battery status notification from %p\n", ClassData);
@@ -99,7 +100,14 @@ BatteryClassStatusNotify(PVOID ClassData)
99100
{
100101
case EVENT_BATTERY_TAG:
101102
ExReleaseFastMutex(&BattClass->Mutex);
102-
DPRINT1("Waiting for battery is UNIMPLEMENTED!\n");
103+
Status = BattClass->MiniportInfo.QueryTag(BattClass->MiniportInfo.Context,
104+
&Tag);
105+
if (!NT_SUCCESS(Status))
106+
return Status;
107+
108+
ExAcquireFastMutex(&BattClass->Mutex);
109+
KeSetEvent(&BattClass->WaitEvent, IO_NO_INCREMENT, FALSE);
110+
ExReleaseFastMutex(&BattClass->Mutex);
103111
break;
104112

105113
case EVENT_BATTERY_STATUS:
@@ -164,7 +172,7 @@ BatteryClassInitializeDevice(PBATTERY_MINIPORT_INFO MiniportInfo,
164172
&BattClass->InterfaceName);
165173
if (NT_SUCCESS(Status))
166174
{
167-
DPRINT("Initialized battery interface: %wZ\n", &BattClass->InterfaceName);
175+
DPRINT1("Initialized battery interface: %wZ\n", &BattClass->InterfaceName);
168176
Status = IoSetDeviceInterfaceState(&BattClass->InterfaceName, TRUE);
169177
if (Status == STATUS_OBJECT_NAME_EXISTS)
170178
{
@@ -223,7 +231,7 @@ BatteryClassIoctl(PVOID ClassData,
223231

224232
WaitTime = IrpSp->Parameters.DeviceIoControl.InputBufferLength == sizeof(ULONG) ? *(PULONG)Irp->AssociatedIrp.SystemBuffer : 0;
225233

226-
Timeout.QuadPart = Int32x32To64(WaitTime, -1000);
234+
Timeout.QuadPart = Int32x32To64(WaitTime, -10000);
227235

228236
Status = BattClass->MiniportInfo.QueryTag(BattClass->MiniportInfo.Context,
229237
(PULONG)Irp->AssociatedIrp.SystemBuffer);
@@ -272,7 +280,7 @@ BatteryClassIoctl(PVOID ClassData,
272280

273281
BattWait = *(PBATTERY_WAIT_STATUS)Irp->AssociatedIrp.SystemBuffer;
274282

275-
Timeout.QuadPart = Int32x32To64(BattWait.Timeout, -1000);
283+
Timeout.QuadPart = Int32x32To64(BattWait.Timeout, -10000);
276284

277285
BattStatus = Irp->AssociatedIrp.SystemBuffer;
278286
Status = BattClass->MiniportInfo.QueryStatus(BattClass->MiniportInfo.Context,

drivers/bus/acpi/cmbatt/cmbatt.c

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,12 @@ CmBattUnload(IN PDRIVER_OBJECT DriverObject)
275275

276276
NTSTATUS
277277
NTAPI
278-
CmBattVerifyStaticInfo(PCMBATT_DEVICE_EXTENSION DeviceExtension,
279-
ULONG BatteryTag)
278+
CmBattVerifyStaticInfo(
279+
_Inout_ PCMBATT_DEVICE_EXTENSION DeviceExtension,
280+
_In_ ULONG BatteryTag)
280281
{
281282
ACPI_BIF_DATA BifData;
283+
ULONG DesignVoltage;
282284
PBATTERY_INFORMATION Info = &DeviceExtension->BatteryInformation;
283285
NTSTATUS Status;
284286

@@ -292,16 +294,73 @@ CmBattVerifyStaticInfo(PCMBATT_DEVICE_EXTENSION DeviceExtension,
292294
// FIXME: take from _BIX method: Info->CycleCount
293295
DeviceExtension->BifData = BifData;
294296

295-
if (BifData.PowerUnit == 1)
297+
/* Check if the power stats are reported in ampere or watts */
298+
if (BifData.PowerUnit == ACPI_BATT_POWER_UNIT_AMPS)
296299
{
297-
DPRINT1("FIXME: need to convert mAh into mWh\n");
298-
Info->DesignedCapacity = BATTERY_UNKNOWN_CAPACITY;
299-
Info->FullChargedCapacity = BATTERY_UNKNOWN_CAPACITY;
300-
Info->DefaultAlert1 = BATTERY_UNKNOWN_CAPACITY;
301-
Info->DefaultAlert2 = BATTERY_UNKNOWN_CAPACITY;
300+
/*
301+
* We have got power stats in milli-ampere but ReactOS expects the values
302+
* to be reported in milli-watts, so we have to convert them.
303+
* In order to do so we must expect the design voltage of the battery
304+
* is not unknown.
305+
*/
306+
DesignVoltage = DeviceExtension->BifData.DesignVoltage;
307+
if ((DesignVoltage != BATTERY_UNKNOWN_VOLTAGE) && (DesignVoltage))
308+
{
309+
/* Convert the design capacity */
310+
if (BifData.DesignCapacity != BATTERY_UNKNOWN_CAPACITY)
311+
{
312+
Info->DesignedCapacity = CONVERT_MAH_TO_MWH(BifData.DesignCapacity, DesignVoltage);
313+
}
314+
else
315+
{
316+
Info->DesignedCapacity = BATTERY_UNKNOWN_CAPACITY;
317+
}
318+
319+
/* Convert the full charged capacity */
320+
if (BifData.LastFullCapacity != BATTERY_UNKNOWN_CAPACITY)
321+
{
322+
Info->FullChargedCapacity = CONVERT_MAH_TO_MWH(BifData.LastFullCapacity, DesignVoltage);
323+
}
324+
else
325+
{
326+
Info->FullChargedCapacity = BATTERY_UNKNOWN_CAPACITY;
327+
}
328+
329+
/* Convert the low capacity alarm (DefaultAlert1) */
330+
if (BifData.DesignCapacityLow != BATTERY_UNKNOWN_CAPACITY)
331+
{
332+
Info->DefaultAlert1 = CONVERT_MAH_TO_MWH(BifData.DesignCapacityLow, DesignVoltage);
333+
}
334+
else
335+
{
336+
Info->DefaultAlert1 = BATTERY_UNKNOWN_CAPACITY;
337+
}
338+
339+
/* Convert the designed capacity warning alarm (DefaultAlert2) */
340+
if (BifData.DesignCapacityWarning != BATTERY_UNKNOWN_CAPACITY)
341+
{
342+
Info->DefaultAlert2 = CONVERT_MAH_TO_MWH(BifData.DesignCapacityWarning, DesignVoltage);
343+
}
344+
else
345+
{
346+
Info->DefaultAlert2 = BATTERY_UNKNOWN_CAPACITY;
347+
}
348+
}
349+
else
350+
{
351+
/*
352+
* Without knowing the nominal designed voltage of the battery
353+
* we cannot determine the power consumption of this battery.
354+
*/
355+
Info->DesignedCapacity = BATTERY_UNKNOWN_CAPACITY;
356+
Info->FullChargedCapacity = BATTERY_UNKNOWN_CAPACITY;
357+
Info->DefaultAlert1 = BATTERY_UNKNOWN_CAPACITY;
358+
Info->DefaultAlert2 = BATTERY_UNKNOWN_CAPACITY;
359+
}
302360
}
303361
else
304362
{
363+
/* The stats are in milli-watts, use them directly */
305364
Info->DesignedCapacity = BifData.DesignCapacity;
306365
Info->FullChargedCapacity = BifData.LastFullCapacity;
307366
Info->DefaultAlert1 = BifData.DesignCapacityLow;
@@ -582,8 +641,13 @@ CmBattQueryTag(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
582641
Status = CmBattGetStaData(PdoDevice, &StaData);
583642
if (NT_SUCCESS(Status))
584643
{
585-
/* Is a battery present? */
586-
if (StaData & ACPI_STA_BATTERY_PRESENT)
644+
/*
645+
* Check if _STA method has returned us the battery state as being
646+
* present. On some machines the returned _STA element might be 0xF
647+
* which is still valid.
648+
*/
649+
if ((StaData & ACPI_STA_BATTERY_PRESENT) ||
650+
(StaData & ACPI_STA_BATTERY_PRESENT_V2))
587651
{
588652
/* Do we not have a tag yet? */
589653
if (DeviceExtension->Tag == BATTERY_TAG_INVALID)
@@ -939,7 +1003,7 @@ CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
9391003
}
9401004
}
9411005
}
942-
else if ((DesignVoltage != CM_UNKNOWN_VALUE) && (DesignVoltage))
1006+
else if ((DesignVoltage != CM_UNKNOWN_VALUE) && (DesignVoltage)) // Same as doing DeviceExtension->BifData.PowerUnit == ACPI_BATT_POWER_UNIT_AMPS
9431007
{
9441008
/* We have voltage data, what about capacity? */
9451009
if (RemainingCapacity == CM_UNKNOWN_VALUE)

drivers/bus/acpi/cmbatt/cmbatt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef enum _CMBATT_EXTENSION_TYPE
5656
#define ACPI_STA_SHOW_UI 0x04
5757
#define ACPI_STA_FUNCTIONAL 0x08
5858
#define ACPI_STA_BATTERY_PRESENT 0x10
59+
#define ACPI_STA_BATTERY_PRESENT_V2 0xF
5960

6061
#define ACPI_BATT_NOTIFY_STATUS 0x80
6162
#define ACPI_BATT_NOTIFY_INFO 0x81
@@ -78,6 +79,8 @@ typedef struct _ACPI_BST_DATA
7879
#define ACPI_BATT_POWER_UNIT_WATTS 0x0
7980
#define ACPI_BATT_POWER_UNIT_AMPS 0x1
8081

82+
#define CONVERT_MAH_TO_MWH(mA, Volts) ((mA * Volts + 500) / 1000)
83+
8184
typedef struct _ACPI_BIF_DATA
8285
{
8386
ULONG PowerUnit;

0 commit comments

Comments
 (0)