46 DbgPrint(
"CmBattPowerCallBack: Calling CmBattWakeDpc after 10 seconds.\n");
49 DbgPrint(
"CmBattPowerCallBack: timerCanceled = %d.\n", Cancelled);
55 DbgPrint(
"CmBattPowerCallBack: Delaying Notifications\n");
62 DeviceExtension->DelayNotification =
TRUE;
68 DbgPrint(
"CmBattPowerCallBack: unknown argument2 = %08x\n",
Value);
89 CurrentObject = CurrentObject->NextDevice)
103 DeviceExtension->
ArFlag = 0;
105 DbgPrint(
"CmBattWakeDpc: AC adapter notified\n");
113 CurrentObject = CurrentObject->NextDevice)
120 ArFlag = DeviceExtension->
ArFlag;
122 DbgPrint(
"CmBattWakeDpc: Performing delayed ARs: %01x\n", ArFlag);
150 DbgPrint(
"CmBattNotifyHandler: CmBatt 0x%08x Type %d Number %d Notify Value: %x\n",
152 DeviceExtension->FdoType,
153 DeviceExtension->DeviceId,
164 if ((DeviceExtension->Tag) &&
166 DbgPrint(
"CmBattNotifyHandler: Received battery #%x insertion, but tag was not invalid.\n",
167 DeviceExtension->DeviceId);
190 DbgPrint(
"CmBattNotifyHandler: Unknown Notify Value: %x\n", NotifyValue);
194 if (DeviceExtension->DelayNotification)
198 DbgPrint(
"CmBattNotifyHandler: Notification delayed: ARs = %01x\n",
199 DeviceExtension->ArFlag);
205 DbgPrint(
"CmBattNotifyHandler: Performing ARs: %01x\n", DeviceExtension->ArFlag);
214 ArFlag = DeviceExtension->ArFlag;
226 DeviceExtension->NotifySent =
TRUE;
233 for (
DeviceObject = DeviceExtension->FdoDeviceObject->DriverObject->DeviceObject;
249 DeviceExtension->ArFlag = 0;
272 DbgPrint(
"Unload called before all devices removed.\n");
293 DeviceExtension->
BifData = BifData;
297 DPRINT1(
"FIXME: need to convert mAh into mWh\n");
334 if (
Count == 0xFFFFFFFF)
340 DbgPrint(
"CmBattOpenClose: Failed (UID = %x)(device being removed).\n",
341 DeviceExtension->
Tag);
355 DbgPrint(
"CmBattOpenClose: Open (DeviceNumber = %x)(count = %x).\n",
365 DbgPrint(
"CmBattOpenClose: Close (DeviceNumber = %x)(count = %x).\n",
432 Irp->AssociatedIrp.SystemBuffer);
449 Irp->AssociatedIrp.SystemBuffer);
469 Irp->AssociatedIrp.SystemBuffer);
492 *(
PULONG)
Irp->AssociatedIrp.SystemBuffer);
493 Irp->IoStatus.Information = 0;
509 Irp->AssociatedIrp.SystemBuffer);
526 Irp->AssociatedIrp.SystemBuffer);
575 DbgPrint(
"CmBattQueryTag - Tag (%d), Battery %x, Device %d\n",
576 *
Tag, DeviceExtension, DeviceExtension->DeviceId);
579 PdoDevice = DeviceExtension->PdoDeviceObject;
580 DeviceExtension->NotifySent = 0;
590 if (!DeviceExtension->Tag)
593 NewTag = DeviceExtension->TagData;
594 if (DeviceExtension->TagData++ == 0xFFFFFFFF) NewTag = 1;
595 DeviceExtension->Tag = NewTag;
597 DbgPrint(
"CmBattQueryTag - New Tag: (%d)\n", DeviceExtension->Tag);
600 DeviceExtension->TripPointOld = 0;
611 DeviceExtension->Tag = 0;
617 *
Tag = DeviceExtension->Tag;
632 if (DeviceExtension->TripPointSet)
635 if (DeviceExtension->TripPointValue)
638 DeviceExtension->TripPointValue = 0;
645 DbgPrint(
"CmBattDisableStatusNotify: SetTripPoint failed - %x\n",
Status);
672 ULONG Capacity, NewTripPoint, TripPoint, DesignVoltage;
676 DbgPrint(
"CmBattSetStatusNotify: Tag (%d) Target(0x%x)\n",
692 DbgPrint(
"CmBattSetStatusNotify: Failing request because of BATTERY_UNKNOWN_CAPACITY.\n");
715 DesignVoltage = DeviceExtension->BifData.DesignVoltage;
719 TripPoint = 1000 * NewTripPoint;
723 NewTripPoint = (TripPoint + 500) / DesignVoltage + ((TripPoint + 500) % DesignVoltage != 0);
728 NewTripPoint = (TripPoint - 500) / DesignVoltage - ((TripPoint - 500) % DesignVoltage == 0);
736 DbgPrint(
"CmBattSetStatusNotify: Can't calculate BTP, DesignVoltage = 0x%08x\n",
745 else if (NewTripPoint > 0)
752 if (NewTripPoint == DeviceExtension->TripPointValue)
756 DbgPrint(
"CmBattSetStatusNotify: Keeping original setting: %X\n", DeviceExtension->TripPointValue);
761 DeviceExtension->TripPointValue = NewTripPoint;
769 DbgPrint(
"CmBattSetStatusNotify: SetTripPoint failed - %x\n",
Status);
785 DbgPrint(
"CmBattSetStatusNotify: Trip point already crossed (1): TP = %08x, remaining capacity = %08x\n",
793 DbgPrint(
"CmBattSetStatusNotify: Trip point already crossed (1): TP = %08x, remaining capacity = %08x\n",
800 DbgPrint(
"CmBattSetStatusNotify: Want %X CurrentCap %X\n",
801 Capacity, DeviceExtension->RemainingCapacity);
803 DbgPrint(
"CmBattSetStatusNotify: Set to: [%#08lx][%#08lx][%#08lx] Status %lx\n",
819 ULONG DesignVoltage, PresentRate, RemainingCapacity;
822 DbgPrint(
"CmBattGetBatteryStatus - CmBatt (%08x) Tag (%d)\n", DeviceExtension,
Tag);
829 if (DeviceExtension->DelayNotification)
846 DeviceExtension->State = 0;
847 DeviceExtension->RemainingCapacity = 0;
848 DeviceExtension->PresentVoltage = 0;
849 DeviceExtension->Rate = 0;
852 BstState = DeviceExtension->BstData.State;
857 DbgPrint(
"************************ ACPI BIOS BUG ********************\n* "
858 "CmBattGetBatteryStatus: Invalid state: _BST method returned 0x%08x for Battery State.\n"
859 "* One battery cannot be charging and discharging at the same time.\n",
883 DeviceExtension->PresentVoltage = DeviceExtension->BstData.PresentVoltage;
912 DbgPrint(
"CmBattGetBatteryStatus: AC adapter is connected\n");
916 DbgPrint(
"CmBattGetBatteryStatus: AC adapter is NOT connected\n");
920 DesignVoltage = DeviceExtension->BifData.DesignVoltage;
921 PresentRate = DeviceExtension->BstData.PresentRate;
922 RemainingCapacity = DeviceExtension->BstData.RemainingCapacity;
928 DeviceExtension->RemainingCapacity = RemainingCapacity;
929 DeviceExtension->Rate = PresentRate;
938 DbgPrint(
"CmBattGetBatteryStatus - Rate is greater than CM_MAX_VALUE\n");
939 DbgPrint(
"---------------------- PresentRate = 0x%08x\n", PresentRate);
952 DbgPrint(
"CmBattGetBatteryStatus - Can't calculate RemainingCapacity \n");
953 DbgPrint(
"---------------------- RemainingCapacity = CM_UNKNOWN_VALUE\n");
959 DeviceExtension->RemainingCapacity = (DesignVoltage * RemainingCapacity + 500) / 1000;
966 if (PresentRate > (-500 / DesignVoltage))
972 DbgPrint(
"CmBattGetBatteryStatus - Can't calculate Rate \n");
973 DbgPrint(
"---------------------- Overflow: PresentRate = 0x%08x\n", PresentRate);
978 DeviceExtension->Rate = (PresentRate * DesignVoltage + 500) / 1000;
986 DbgPrint(
"CmBattGetBatteryStatus - Can't calculate Rate \n");
987 DbgPrint(
"---------------------- Present Rate = CM_UNKNOWN_VALUE\n");
998 DbgPrint(
"CmBattGetBatteryStatus - Can't calculate RemainingCapacity and Rate \n");
999 DbgPrint(
"---------------------- DesignVoltage = 0x%08x\n", DesignVoltage);
1009 DbgPrint(
"CmBattGetBatteryStatus: battery rate is unknown when battery is not charging!\n");
1014 DeviceExtension->Rate = -(
LONG)DeviceExtension->Rate;
1016 else if (!(DeviceExtension->State &
BATTERY_CHARGING) && (DeviceExtension->Rate))
1020 DbgPrint(
"CmBattGetBatteryStatus: battery is not charging or discharging, but rate = %x\n",
1021 DeviceExtension->Rate);
1022 DeviceExtension->Rate = 0;
1041 ULONG QueryLength = 0;
1042 ULONG RemainingTime = 0;
1045 WCHAR InfoBuffer[256];
1046 WCHAR TempBuffer[256];
1048 ULONG RemainingCapacity;
1053 DbgPrint(
"CmBattQueryInformation - Tag (%d) Device %d, Informationlevel %d\n",
1078 QueryData = BatteryReportingScale;
1107 DbgPrint(
"CmBattQueryInformation: Can't calculate EstimatedTime.\n");
1116 DbgPrint(
"---------------------- PresentRate = BATTERY_UNKNOWN_RATE\n");
1125 DbgPrint(
"---------------------- RemainingCapacity = BATTERY_UNKNOWN_CAPACITY\n");
1131 if (RemainingCapacity > 0x123456)
1135 DbgPrint(
"CmBattQueryInformation: Data Overflow in calculating Remaining Capacity.\n");
1140 RemainingTime = (RemainingCapacity * 3600) / -Rate;
1146 QueryData = &RemainingTime;
1147 QueryLength =
sizeof(
ULONG);
1156 InfoString.
Buffer = InfoBuffer;
1161 QueryData = InfoString.
Buffer;
1162 QueryLength = InfoString.
Length;
1178 InfoString.
Buffer = InfoBuffer;
1183 QueryData = InfoString.
Buffer;
1184 QueryLength = InfoString.
Length;
1193 InfoString.
Buffer = InfoBuffer;
1198 TempString2.
Buffer = TempBuffer;
1220 QueryData = InfoString.
Buffer;
1221 QueryLength = InfoString.
Length;
1251 DbgPrint(
"CmBattQueryStatus - Tag (%d) Device %x\n",
Tag, DeviceExtension->DeviceId);
1265 DbgPrint(
"CmBattQueryStatus: Returning [%#08lx][%#08lx][%#08lx][%#08lx]\n",
1293 DbgPrint(
"CmBatt: Couldn't allocate pool for registry path.");
1300 DbgPrint(
"CmBatt DriverEntry - Obj (%08x) Path \"%wZ\"\n",
1332 DbgPrint(
"CmBattRegisterPowerCallBack: failed status=0x%08x\n",
Status);
1350 DbgPrint(
"CmBattRegisterPowerCallBack: ExRegisterCallback failed.\n");
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define ACPI_STA_BATTERY_PRESENT
#define InterlockedExchange
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
#define BATTERY_SYSTEM_BATTERY
_In_ ULONG _In_ PBATTERY_NOTIFY BatteryNotify
#define BATTERY_UNKNOWN_CAPACITY
_In_ ULONG _Out_ PBATTERY_STATUS BatteryStatus
#define BATTERY_UNKNOWN_VOLTAGE
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG AtRate
#define BATTERY_POWER_ON_LINE
#define BATTERY_DISCHARGING
struct _BATTERY_INFORMATION BATTERY_INFORMATION
@ BatteryGranularityInformation
#define BATTERY_UNKNOWN_RATE
enum _BATTERY_QUERY_INFORMATION_LEVEL BATTERY_QUERY_INFORMATION_LEVEL
BCLASSAPI NTSTATUS NTAPI BatteryClassStatusNotify(PVOID ClassData)
BCLASSAPI NTSTATUS NTAPI BatteryClassIoctl(PVOID ClassData, PIRP Irp)
PDEVICE_OBJECT AcAdapterPdo
NTSTATUS NTAPI CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag)
VOID NTAPI CmBattUnload(IN PDRIVER_OBJECT DriverObject)
KTIMER CmBattWakeDpcTimerObject
NTSTATUS NTAPI CmBattOpenClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
NTSTATUS NTAPI CmBattIoctl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
PCALLBACK_OBJECT CmBattPowerCallBackObject
PVOID CmBattPowerCallBackRegistration
NTSTATUS NTAPI CmBattDisableStatusNotify(IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
LARGE_INTEGER CmBattWakeDpcDelay
VOID NTAPI CmBattWakeDpc(IN PKDPC Dpc, IN PCMBATT_DEVICE_EXTENSION FdoExtension, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
NTSTATUS NTAPI CmBattQueryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag, IN PBATTERY_STATUS BatteryStatus)
NTSTATUS NTAPI CmBattQueryInformation(IN PCMBATT_DEVICE_EXTENSION FdoExtension, IN ULONG Tag, IN BATTERY_QUERY_INFORMATION_LEVEL InfoLevel, IN OPTIONAL LONG AtRate, IN PVOID Buffer, IN ULONG BufferLength, OUT PULONG ReturnedLength)
VOID NTAPI CmBattNotifyHandler(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG NotifyValue)
UNICODE_STRING GlobalRegistryPath
NTSTATUS NTAPI CmBattVerifyStaticInfo(PCMBATT_DEVICE_EXTENSION DeviceExtension, ULONG BatteryTag)
VOID NTAPI CmBattPowerCallBack(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Action, IN ULONG Value)
NTSTATUS NTAPI CmBattQueryTag(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, OUT PULONG Tag)
NTSTATUS NTAPI CmBattSetStatusNotify(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG BatteryTag, IN PBATTERY_NOTIFY BatteryNotify)
NTSTATUS NTAPI CmBattSetTripPpoint(PCMBATT_DEVICE_EXTENSION DeviceExtension, ULONG AlarmValue)
#define CMBATT_GENERIC_INFO
#define CMBATT_ACPI_WARNING
#define CMBATT_GENERIC_STATUS
NTSTATUS NTAPI CmBattGetStaData(PDEVICE_OBJECT DeviceObject, PULONG StaData)
NTSTATUS NTAPI CmBattGetPsrData(PDEVICE_OBJECT DeviceObject, PULONG PsrData)
#define CMBATT_ACPI_ASSERT
#define ACPI_BATT_NOTIFY_INFO
#define IOCTL_BATTERY_QUERY_STA
struct _ACPI_BIF_DATA ACPI_BIF_DATA
#define ACPI_BATT_POWER_UNIT_WATTS
#define IOCTL_BATTERY_QUERY_BST
NTSTATUS NTAPI CmBattGetUniqueId(PDEVICE_OBJECT DeviceObject, PULONG UniqueId)
#define ACPI_BATT_STAT_CRITICAL
#define IOCTL_BATTERY_SET_TRIP_POINT
#define ACPI_DEVICE_CHECK
NTSTATUS NTAPI CmBattPowerDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
#define CMBATT_GENERIC_WARNING
NTSTATUS NTAPI CmBattGetBifData(PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BIF_DATA BifData)
#define ACPI_BATT_STAT_DISCHARG
NTSTATUS NTAPI CmBattGetBstData(PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BST_DATA BstData)
#define IOCTL_BATTERY_QUERY_PSR
#define IOCTL_BATTERY_QUERY_UNIQUE_ID
NTSTATUS NTAPI CmBattPnpDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
struct _ACPI_BST_DATA ACPI_BST_DATA
#define ACPI_BATT_STAT_CHARGING
#define IOCTL_BATTERY_QUERY_BIF
#define ACPI_BATT_NOTIFY_STATUS
NTSTATUS NTAPI CmBattAddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject)
NTSTATUS NTAPI CmBattSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
#define ACPI_BATT_POWER_UNIT_AMPS
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
DRIVER_INITIALIZE DriverEntry
#define ExAllocatePoolWithTag(hernya, size, tag)
pRequest Complete(RequestStatus)
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
#define OBJ_KERNEL_HANDLE
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define IoSkipCurrentIrpStackLocation(Irp)
VOID NTAPI ExUnregisterCallback(IN PVOID CallbackRegistrationHandle)
PVOID NTAPI ExRegisterCallback(IN PCALLBACK_OBJECT CallbackObject, IN PCALLBACK_FUNCTION CallbackFunction, IN PVOID CallbackContext)
NTSTATUS NTAPI ExCreateCallback(OUT PCALLBACK_OBJECT *CallbackObject, IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN Create, IN BOOLEAN AllowMultipleCallbacks)
#define IoCompleteRequest
#define STATUS_INVALID_BUFFER_SIZE
#define STATUS_NOT_SUPPORTED
#define STATUS_DEVICE_REMOVED
PPCI_DRIVER_EXTENSION DriverExtension
#define IRP_MJ_DEVICE_CONTROL
#define KeQueryInterruptTime()
#define STATUS_BUFFER_TOO_SMALL
PULONG MinorVersion OPTIONAL
ULONG DesignCapacityWarning
CMBATT_EXTENSION_TYPE FdoType
PDEVICE_OBJECT PdoDeviceObject
BOOLEAN DelayNotification
PDEVICE_OBJECT AttachedDevice
IO_REMOVE_LOCK RemoveLock
BATTERY_INFORMATION BatteryInformation
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define STATUS_INVALID_DEVICE_REQUEST
#define STATUS_INVALID_PARAMETER
#define STATUS_NO_SUCH_DEVICE
#define STATUS_INSUFFICIENT_RESOURCES
#define STATUS_OBJECT_NAME_NOT_FOUND
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
_In_ PDEVICE_OBJECT DeviceObject
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
_In_ WDFREQUEST _In_ size_t OutputBufferLength
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
#define IRP_MJ_SYSTEM_CONTROL
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
#define ObDereferenceObject
#define PO_CB_SYSTEM_STATE_LOCK