ReactOS 0.4.16-dev-555-g690643f
cmbatt.h File Reference
#include <wdm.h>
#include <batclass.h>
#include <wmilib.h>
#include <wdmguid.h>
Include dependency graph for cmbatt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ACPI_BST_DATA
 
struct  _ACPI_BIF_DATA
 
struct  _ACPI_BIX_DATA
 
struct  _ACPI_BATT_STATIC_INFO
 
struct  _CMBATT_DEVICE_EXTENSION
 

Macros

#define IOCTL_BATTERY_QUERY_UNIQUE_ID    CTL_CODE(FILE_DEVICE_BATTERY, 0x101, METHOD_BUFFERED, FILE_READ_ACCESS)
 
#define IOCTL_BATTERY_QUERY_STA    CTL_CODE(FILE_DEVICE_BATTERY, 0x102, METHOD_BUFFERED, FILE_READ_ACCESS)
 
#define IOCTL_BATTERY_QUERY_PSR    CTL_CODE(FILE_DEVICE_BATTERY, 0x103, METHOD_BUFFERED, FILE_READ_ACCESS)
 
#define IOCTL_BATTERY_SET_TRIP_POINT    CTL_CODE(FILE_DEVICE_BATTERY, 0x104, METHOD_BUFFERED, FILE_READ_ACCESS)
 
#define IOCTL_BATTERY_QUERY_BIF_BIX    CTL_CODE(FILE_DEVICE_BATTERY, 0x105, METHOD_BUFFERED, FILE_READ_ACCESS)
 
#define IOCTL_BATTERY_QUERY_BST    CTL_CODE(FILE_DEVICE_BATTERY, 0x106, METHOD_BUFFERED, FILE_READ_ACCESS)
 
#define CMBATT_GENERIC_STATUS   0x01
 
#define CMBATT_GENERIC_INFO   0x02
 
#define CMBATT_GENERIC_WARNING   0x04
 
#define CMBATT_ACPI_WARNING   0x08
 
#define CMBATT_POWER_INFO   0x10
 
#define CMBATT_PNP_INFO   0x20
 
#define CMBATT_ACPI_ENTRY_EXIT   0x40
 
#define CMBATT_PNP_ENTRY_EXIT   0x200
 
#define CMBATT_ACPI_ASSERT   0x400
 
#define CMBATT_DISCHARGE_TIME   150000000
 
#define CMBATT_CAPACITY_BOGUS   0x100000
 
#define ACPI_BUS_CHECK   0x00
 
#define ACPI_DEVICE_CHECK   0x01
 
#define ACPI_STA_PRESENT   0x01
 
#define ACPI_STA_ENABLED   0x02
 
#define ACPI_STA_SHOW_UI   0x04
 
#define ACPI_STA_FUNCTIONAL   0x08
 
#define ACPI_STA_BATTERY_PRESENT   0x10
 
#define ACPI_BATT_NOTIFY_STATUS   0x80
 
#define ACPI_BATT_NOTIFY_INFO   0x81
 
#define ACPI_BATT_STAT_DISCHARG   0x0001
 
#define ACPI_BATT_STAT_CHARGING   0x0002
 
#define ACPI_BATT_STAT_CRITICAL   0x0004
 
#define CM_MAX_VALUE   0x7FFFFFFF
 
#define CM_UNKNOWN_VALUE   0xFFFFFFFF
 
#define CONVERT_MAH_TO_MWH(mA, Volts)   (((mA) * (Volts) + 500) / 1000)
 
#define CONVERT_BATT_INFO(Capacity, DesignVoltage)
 
#define ACPI_BATT_POWER_UNIT_WATTS   0x0
 
#define ACPI_BATT_POWER_UNIT_AMPS   0x1
 
#define ASCIIZ_MAX_LENGTH   256
 
#define CMBATT_BATT_STATIC_INFO_TAG   'nItS'
 
#define CMBATT_AR_NOTIFY   0x01
 
#define CMBATT_AR_INSERT   0x02
 
#define CMBATT_AR_REMOVE   0x04
 

Typedefs

typedef enum _CMBATT_EXTENSION_TYPE CMBATT_EXTENSION_TYPE
 
typedef struct _ACPI_BST_DATA ACPI_BST_DATA
 
typedef struct _ACPI_BST_DATAPACPI_BST_DATA
 
typedef struct _ACPI_BIF_DATA ACPI_BIF_DATA
 
typedef struct _ACPI_BIF_DATAPACPI_BIF_DATA
 
typedef struct _ACPI_BIX_DATA ACPI_BIX_DATA
 
typedef struct _ACPI_BIX_DATAPACPI_BIX_DATA
 
typedef struct _ACPI_BATT_STATIC_INFO ACPI_BATT_STATIC_INFO
 
typedef struct _ACPI_BATT_STATIC_INFOPACPI_BATT_STATIC_INFO
 
typedef struct _CMBATT_DEVICE_EXTENSION CMBATT_DEVICE_EXTENSION
 
typedef struct _CMBATT_DEVICE_EXTENSIONPCMBATT_DEVICE_EXTENSION
 

Enumerations

enum  _CMBATT_EXTENSION_TYPE { CmBattAcAdapter , CmBattBattery }
 

Functions

NTSTATUS NTAPI CmBattPowerDispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI CmBattPnpDispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI CmBattAddDevice (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI CmBattSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI CmBattGetBstData (PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BST_DATA BstData)
 
NTSTATUS NTAPI CmBattGetPsrData (PDEVICE_OBJECT DeviceObject, PULONG PsrData)
 
NTSTATUS NTAPI CmBattGetStaData (PDEVICE_OBJECT DeviceObject, PULONG StaData)
 
NTSTATUS NTAPI CmBattGetBifData (PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BIF_DATA BifData)
 
NTSTATUS NTAPI CmBattGetBixData (_In_ PCMBATT_DEVICE_EXTENSION DeviceExtension, _Out_ PACPI_BIX_DATA BixData)
 Retrieves the eXtended static battery information from the ACPI _BIX method.
 
NTSTATUS NTAPI CmBattSetTripPpoint (PCMBATT_DEVICE_EXTENSION DeviceExtension, ULONG AlarmValue)
 
VOID NTAPI CmBattNotifyHandler (IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG NotifyValue)
 
NTSTATUS NTAPI CmBattWmiDeRegistration (PCMBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CmBattWmiRegistration (PCMBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CmBattGetUniqueId (PDEVICE_OBJECT DeviceObject, PULONG UniqueId)
 
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)
 
NTSTATUS NTAPI CmBattQueryStatus (IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag, IN PBATTERY_STATUS BatteryStatus)
 
NTSTATUS NTAPI CmBattSetStatusNotify (IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG BatteryTag, IN PBATTERY_NOTIFY BatteryNotify)
 
NTSTATUS NTAPI CmBattDisableStatusNotify (IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI CmBattQueryTag (IN PCMBATT_DEVICE_EXTENSION DeviceExtension, OUT PULONG Tag)
 

Variables

PDEVICE_OBJECT AcAdapterPdo
 
ULONG CmBattDebug
 

Macro Definition Documentation

◆ ACPI_BATT_NOTIFY_INFO

#define ACPI_BATT_NOTIFY_INFO   0x81

Definition at line 73 of file cmbatt.h.

◆ ACPI_BATT_NOTIFY_STATUS

#define ACPI_BATT_NOTIFY_STATUS   0x80

Definition at line 72 of file cmbatt.h.

◆ ACPI_BATT_POWER_UNIT_AMPS

#define ACPI_BATT_POWER_UNIT_AMPS   0x1

Definition at line 98 of file cmbatt.h.

◆ ACPI_BATT_POWER_UNIT_WATTS

#define ACPI_BATT_POWER_UNIT_WATTS   0x0

Definition at line 97 of file cmbatt.h.

◆ ACPI_BATT_STAT_CHARGING

#define ACPI_BATT_STAT_CHARGING   0x0002

Definition at line 76 of file cmbatt.h.

◆ ACPI_BATT_STAT_CRITICAL

#define ACPI_BATT_STAT_CRITICAL   0x0004

Definition at line 77 of file cmbatt.h.

◆ ACPI_BATT_STAT_DISCHARG

#define ACPI_BATT_STAT_DISCHARG   0x0001

Definition at line 75 of file cmbatt.h.

◆ ACPI_BUS_CHECK

#define ACPI_BUS_CHECK   0x00

Definition at line 63 of file cmbatt.h.

◆ ACPI_DEVICE_CHECK

#define ACPI_DEVICE_CHECK   0x01

Definition at line 64 of file cmbatt.h.

◆ ACPI_STA_BATTERY_PRESENT

#define ACPI_STA_BATTERY_PRESENT   0x10

Definition at line 70 of file cmbatt.h.

◆ ACPI_STA_ENABLED

#define ACPI_STA_ENABLED   0x02

Definition at line 67 of file cmbatt.h.

◆ ACPI_STA_FUNCTIONAL

#define ACPI_STA_FUNCTIONAL   0x08

Definition at line 69 of file cmbatt.h.

◆ ACPI_STA_PRESENT

#define ACPI_STA_PRESENT   0x01

Definition at line 66 of file cmbatt.h.

◆ ACPI_STA_SHOW_UI

#define ACPI_STA_SHOW_UI   0x04

Definition at line 68 of file cmbatt.h.

◆ ASCIIZ_MAX_LENGTH

#define ASCIIZ_MAX_LENGTH   256

Definition at line 100 of file cmbatt.h.

◆ CM_MAX_VALUE

#define CM_MAX_VALUE   0x7FFFFFFF

Definition at line 79 of file cmbatt.h.

◆ CM_UNKNOWN_VALUE

#define CM_UNKNOWN_VALUE   0xFFFFFFFF

Definition at line 80 of file cmbatt.h.

◆ CMBATT_ACPI_ASSERT

#define CMBATT_ACPI_ASSERT   0x400

Definition at line 43 of file cmbatt.h.

◆ CMBATT_ACPI_ENTRY_EXIT

#define CMBATT_ACPI_ENTRY_EXIT   0x40

Definition at line 41 of file cmbatt.h.

◆ CMBATT_ACPI_WARNING

#define CMBATT_ACPI_WARNING   0x08

Definition at line 38 of file cmbatt.h.

◆ CMBATT_AR_INSERT

#define CMBATT_AR_INSERT   0x02

Definition at line 154 of file cmbatt.h.

◆ CMBATT_AR_NOTIFY

#define CMBATT_AR_NOTIFY   0x01

Definition at line 153 of file cmbatt.h.

◆ CMBATT_AR_REMOVE

#define CMBATT_AR_REMOVE   0x04

Definition at line 155 of file cmbatt.h.

◆ CMBATT_BATT_STATIC_INFO_TAG

#define CMBATT_BATT_STATIC_INFO_TAG   'nItS'

Definition at line 151 of file cmbatt.h.

◆ CMBATT_CAPACITY_BOGUS

#define CMBATT_CAPACITY_BOGUS   0x100000

Definition at line 55 of file cmbatt.h.

◆ CMBATT_DISCHARGE_TIME

#define CMBATT_DISCHARGE_TIME   150000000

Definition at line 49 of file cmbatt.h.

◆ CMBATT_GENERIC_INFO

#define CMBATT_GENERIC_INFO   0x02

Definition at line 36 of file cmbatt.h.

◆ CMBATT_GENERIC_STATUS

#define CMBATT_GENERIC_STATUS   0x01

Definition at line 35 of file cmbatt.h.

◆ CMBATT_GENERIC_WARNING

#define CMBATT_GENERIC_WARNING   0x04

Definition at line 37 of file cmbatt.h.

◆ CMBATT_PNP_ENTRY_EXIT

#define CMBATT_PNP_ENTRY_EXIT   0x200

Definition at line 42 of file cmbatt.h.

◆ CMBATT_PNP_INFO

#define CMBATT_PNP_INFO   0x20

Definition at line 40 of file cmbatt.h.

◆ CMBATT_POWER_INFO

#define CMBATT_POWER_INFO   0x10

Definition at line 39 of file cmbatt.h.

◆ CONVERT_BATT_INFO

#define CONVERT_BATT_INFO (   Capacity,
  DesignVoltage 
)
Value:
(((Capacity) != BATTERY_UNKNOWN_CAPACITY) \
? CONVERT_MAH_TO_MWH((Capacity), (DesignVoltage)) \
#define BATTERY_UNKNOWN_CAPACITY
Definition: batclass.h:65
#define CONVERT_MAH_TO_MWH(mA, Volts)
Definition: cmbatt.h:82

Definition at line 84 of file cmbatt.h.

◆ CONVERT_MAH_TO_MWH

#define CONVERT_MAH_TO_MWH (   mA,
  Volts 
)    (((mA) * (Volts) + 500) / 1000)

Definition at line 82 of file cmbatt.h.

◆ IOCTL_BATTERY_QUERY_BIF_BIX

#define IOCTL_BATTERY_QUERY_BIF_BIX    CTL_CODE(FILE_DEVICE_BATTERY, 0x105, METHOD_BUFFERED, FILE_READ_ACCESS)

Definition at line 29 of file cmbatt.h.

◆ IOCTL_BATTERY_QUERY_BST

#define IOCTL_BATTERY_QUERY_BST    CTL_CODE(FILE_DEVICE_BATTERY, 0x106, METHOD_BUFFERED, FILE_READ_ACCESS)

Definition at line 32 of file cmbatt.h.

◆ IOCTL_BATTERY_QUERY_PSR

#define IOCTL_BATTERY_QUERY_PSR    CTL_CODE(FILE_DEVICE_BATTERY, 0x103, METHOD_BUFFERED, FILE_READ_ACCESS)

Definition at line 23 of file cmbatt.h.

◆ IOCTL_BATTERY_QUERY_STA

#define IOCTL_BATTERY_QUERY_STA    CTL_CODE(FILE_DEVICE_BATTERY, 0x102, METHOD_BUFFERED, FILE_READ_ACCESS)

Definition at line 20 of file cmbatt.h.

◆ IOCTL_BATTERY_QUERY_UNIQUE_ID

#define IOCTL_BATTERY_QUERY_UNIQUE_ID    CTL_CODE(FILE_DEVICE_BATTERY, 0x101, METHOD_BUFFERED, FILE_READ_ACCESS)

Definition at line 17 of file cmbatt.h.

◆ IOCTL_BATTERY_SET_TRIP_POINT

#define IOCTL_BATTERY_SET_TRIP_POINT    CTL_CODE(FILE_DEVICE_BATTERY, 0x104, METHOD_BUFFERED, FILE_READ_ACCESS)

Definition at line 26 of file cmbatt.h.

Typedef Documentation

◆ ACPI_BATT_STATIC_INFO

◆ ACPI_BIF_DATA

◆ ACPI_BIX_DATA

◆ ACPI_BST_DATA

◆ CMBATT_DEVICE_EXTENSION

◆ CMBATT_EXTENSION_TYPE

◆ PACPI_BATT_STATIC_INFO

◆ PACPI_BIF_DATA

◆ PACPI_BIX_DATA

◆ PACPI_BST_DATA

◆ PCMBATT_DEVICE_EXTENSION

Enumeration Type Documentation

◆ _CMBATT_EXTENSION_TYPE

Enumerator
CmBattAcAdapter 
CmBattBattery 

Definition at line 57 of file cmbatt.h.

58{
enum _CMBATT_EXTENSION_TYPE CMBATT_EXTENSION_TYPE
@ CmBattAcAdapter
Definition: cmbatt.h:59
@ CmBattBattery
Definition: cmbatt.h:60

Function Documentation

◆ CmBattAddDevice()

NTSTATUS NTAPI CmBattAddDevice ( PDRIVER_OBJECT  DriverObject,
PDEVICE_OBJECT  DeviceObject 
)

Referenced by DriverEntry().

◆ CmBattDisableStatusNotify()

NTSTATUS NTAPI CmBattDisableStatusNotify ( IN PCMBATT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 884 of file cmbatt.c.

885{
887 PAGED_CODE();
888 if (CmBattDebug & 0xA) DbgPrint("CmBattDisableStatusNotify\n");
889
890 /* Do we have a trip point */
891 if (DeviceExtension->TripPointSet)
892 {
893 /* Is there a current value set? */
894 if (DeviceExtension->TripPointValue)
895 {
896 /* Reset it back to 0 */
897 DeviceExtension->TripPointValue = 0;
898 Status = CmBattSetTripPpoint(DeviceExtension, 0);
899 if (!NT_SUCCESS(Status))
900 {
901 /* If it failed, set unknown/invalid value */
902 DeviceExtension->TripPointValue = BATTERY_UNKNOWN_CAPACITY;
903 if (CmBattDebug & 8)
904 DbgPrint("CmBattDisableStatusNotify: SetTripPoint failed - %x\n", Status);
905 }
906 }
907 else
908 {
909 /* No trip point set, so this is a successful no-op */
911 }
912 }
913 else
914 {
915 /* Nothing we can do */
917 }
918
919 /* Return status */
920 return Status;
921}
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
ULONG CmBattDebug
Definition: cmbatt.c:17
NTSTATUS NTAPI CmBattSetTripPpoint(PCMBATT_DEVICE_EXTENSION DeviceExtension, ULONG AlarmValue)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by CmBattAddBattery().

◆ CmBattGetBifData()

NTSTATUS NTAPI CmBattGetBifData ( PCMBATT_DEVICE_EXTENSION  DeviceExtension,
PACPI_BIF_DATA  BifData 
)

Definition at line 412 of file cmexec.c.

414{
415 ACPI_PACKAGE_FIELD BifFields[] = {
416 { "PowerUnit", FALSE, &BifData->PowerUnit },
417 { "DesignCapacity", FALSE, &BifData->DesignCapacity },
418 { "LastFullCapacity", FALSE, &BifData->LastFullCapacity },
419 { "BatteryTechnology", FALSE, &BifData->BatteryTechnology },
420 { "DesignVoltage", FALSE, &BifData->DesignVoltage },
421 { "DesignCapacityWarning", FALSE, &BifData->DesignCapacityWarning },
422 { "DesignCapacityLow", FALSE, &BifData->DesignCapacityLow },
423 { "BatteryCapacityGranularity1", FALSE, &BifData->BatteryCapacityGranularity1 },
424 { "BatteryCapacityGranularity2", FALSE, &BifData->BatteryCapacityGranularity2 },
425 { "ModelNumber", TRUE, &BifData->ModelNumber },
426 { "SerialNumber", TRUE, &BifData->SerialNumber },
427 { "BatteryType", TRUE, &BifData->BatteryType },
428 { "OemInfo", TRUE, &BifData->OemInfo },
429 };
430 PAGED_CODE();
431
433 DbgPrint("CmBattGetBifData: Buffer (0x%x) Device %x Tid %x\n",
434 BifData, DeviceExtension->DeviceId, KeGetCurrentThread());
435
436 /* Request the _BIF method */
437 /* Note that _BIF method is deprecated since ACPI 4.0, and replaced by _BIX method.
438 * However, VirtualBox 7.0 only support _BIF method.
439 */
440 return CmBattCallAcpiPackage("CmBattGetBifData",
441 DeviceExtension,
442 'FIB_',
443 512,
444 BifFields,
445 RTL_NUMBER_OF(BifFields));
446}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define CMBATT_ACPI_ENTRY_EXIT
Definition: cmbatt.h:41
static NTSTATUS CmBattCallAcpiPackage(_In_ LPCSTR FunctionName, _In_ PCMBATT_DEVICE_EXTENSION DeviceExtension, _In_ ULONG PackageName, _In_ ULONG OutputBufferSize, _In_ PACPI_PACKAGE_FIELD PackageFields, _In_ ULONG PackageFieldCount)
Definition: cmexec.c:163
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define KeGetCurrentThread
Definition: hal.h:55
ULONG DesignCapacityLow
Definition: cmbatt.h:110
ULONG DesignVoltage
Definition: cmbatt.h:108
ULONG LastFullCapacity
Definition: cmbatt.h:106
ULONG DesignCapacity
Definition: cmbatt.h:105
CHAR SerialNumber[ASCIIZ_MAX_LENGTH]
Definition: cmbatt.h:114
ULONG BatteryTechnology
Definition: cmbatt.h:107
CHAR BatteryType[ASCIIZ_MAX_LENGTH]
Definition: cmbatt.h:115
ULONG BatteryCapacityGranularity1
Definition: cmbatt.h:111
CHAR OemInfo[ASCIIZ_MAX_LENGTH]
Definition: cmbatt.h:116
ULONG DesignCapacityWarning
Definition: cmbatt.h:109
ULONG BatteryCapacityGranularity2
Definition: cmbatt.h:112
CHAR ModelNumber[ASCIIZ_MAX_LENGTH]
Definition: cmbatt.h:113
ULONG PowerUnit
Definition: cmbatt.h:104

Referenced by CmBattGetBattStaticInfo(), and CmBattIoctl().

◆ CmBattGetBixData()

NTSTATUS NTAPI CmBattGetBixData ( _In_ PCMBATT_DEVICE_EXTENSION  DeviceExtension,
_Out_ PACPI_BIX_DATA  BixData 
)

Retrieves the eXtended static battery information from the ACPI _BIX method.

Parameters
[in]DeviceExtensionA pointer to a Control Method (CM) battery device extension. It is used to send the ACPI method evaluation operation to the ACPI driver of which it is attached to this CM battery.
[out]BixDataA pointer to a structure that contains the _BIX data fields, returned to caller.
Returns
Returns STATUS_SUCCESS if the operation has succeeded successfully, otherwise a failure NTSTATUS code is returned.

Definition at line 468 of file cmexec.c.

471{
472 ACPI_PACKAGE_FIELD BixFields[] = {
473 { "Revision", FALSE, &BixData->Revision },
474 { "PowerUnit", FALSE, &BixData->PowerUnit },
475 { "DesignCapacity", FALSE, &BixData->DesignCapacity },
476 { "LastFullCapacity", FALSE, &BixData->LastFullCapacity },
477 { "BatteryTechnology", FALSE, &BixData->BatteryTechnology },
478 { "DesignVoltage", FALSE, &BixData->DesignVoltage },
479 { "DesignCapacityWarning", FALSE, &BixData->DesignCapacityWarning },
480 { "DesignCapacityLow", FALSE, &BixData->DesignCapacityLow },
481 { "CycleCount", FALSE, &BixData->CycleCount },
482 { "Accuracy", FALSE, &BixData->Accuracy },
483 { "MaxSampleTime", FALSE, &BixData->MaxSampleTime },
484 { "MinSampleTime", FALSE, &BixData->MinSampleTime },
485 { "MaxAverageInterval", FALSE, &BixData->MaxAverageInterval },
486 { "MinAverageInterval", FALSE, &BixData->MinAverageInterval },
487 { "BatteryCapacityGranularity1", FALSE, &BixData->BatteryCapacityGranularity1 },
488 { "BatteryCapacityGranularity2", FALSE, &BixData->BatteryCapacityGranularity2 },
489 { "ModelNumber", TRUE, &BixData->ModelNumber },
490 { "SerialNumber", TRUE, &BixData->SerialNumber },
491 { "BatteryType", TRUE, &BixData->BatteryType },
492 { "OemInfo", TRUE, &BixData->OemInfo },
493 { "SwapCapability", FALSE, &BixData->SwapCapability },
494 };
495 PAGED_CODE();
496
498 {
499 DbgPrint("CmBattGetBixData: Buffer (0x%x) Device %x Tid %x\n",
500 BixData, DeviceExtension->DeviceId, KeGetCurrentThread());
501 }
502
503 /* Request the ACPI driver to get the _BIX data for us */
504 return CmBattCallAcpiPackage("CmBattGetBifData",
505 DeviceExtension,
506 'XIB_',
507 512,
508 BixFields,
509 RTL_NUMBER_OF(BixFields));
510}

Referenced by CmBattGetBattStaticInfo(), and CmBattIoctl().

◆ CmBattGetBstData()

NTSTATUS NTAPI CmBattGetBstData ( PCMBATT_DEVICE_EXTENSION  DeviceExtension,
PACPI_BST_DATA  BstData 
)

Definition at line 514 of file cmexec.c.

516{
517 ACPI_PACKAGE_FIELD BstFields[] = {
518 { "State", FALSE, &BstData->State },
519 { "PresentRate", FALSE, &BstData->PresentRate },
520 { "RemainingCapacity", FALSE, &BstData->RemainingCapacity },
521 { "PresentVoltage", FALSE, &BstData->PresentVoltage },
522 };
523 PAGED_CODE();
524
526 DbgPrint("CmBattGetBstData: Buffer (0x%x) Device %x Tid %x\n",
527 BstData, DeviceExtension->DeviceId, KeGetCurrentThread());
528
529
530 return CmBattCallAcpiPackage("CmBattGetBstData",
531 DeviceExtension,
532 'TSB_',
533 512,
534 BstFields,
535 RTL_NUMBER_OF(BstFields));
536}
ULONG PresentRate
Definition: cmbatt.h:92
ULONG RemainingCapacity
Definition: cmbatt.h:93
ULONG PresentVoltage
Definition: cmbatt.h:94
ULONG State
Definition: cmbatt.h:91

Referenced by CmBattGetBatteryStatus(), CmBattIoctl(), and CmBattSetStatusNotify().

◆ CmBattGetPsrData()

NTSTATUS NTAPI CmBattGetPsrData ( PDEVICE_OBJECT  DeviceObject,
PULONG  PsrData 
)

◆ CmBattGetStaData()

NTSTATUS NTAPI CmBattGetStaData ( PDEVICE_OBJECT  DeviceObject,
PULONG  StaData 
)

Referenced by CmBattIoctl(), and CmBattQueryTag().

◆ CmBattGetUniqueId()

NTSTATUS NTAPI CmBattGetUniqueId ( PDEVICE_OBJECT  DeviceObject,
PULONG  UniqueId 
)

Referenced by CmBattCreateFdo(), and CmBattIoctl().

◆ CmBattNotifyHandler()

VOID NTAPI CmBattNotifyHandler ( IN PCMBATT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  NotifyValue 
)

Definition at line 142 of file cmbatt.c.

144{
145 ULONG ArFlag;
148
150 DbgPrint("CmBattNotifyHandler: CmBatt 0x%08x Type %d Number %d Notify Value: %x\n",
151 DeviceExtension,
152 DeviceExtension->FdoType,
153 DeviceExtension->DeviceId,
154 NotifyValue);
155
156 /* Check what kind of notification was received */
157 switch (NotifyValue)
158 {
159 /* ACPI Specification says is sends a "Bus Check" when power source changes */
160 case ACPI_BUS_CHECK:
161
162 /* We treat it as possible physical change */
163 DeviceExtension->ArFlag |= (CMBATT_AR_NOTIFY | CMBATT_AR_INSERT);
164 if ((DeviceExtension->Tag) &&
166 DbgPrint("CmBattNotifyHandler: Received battery #%x insertion, but tag was not invalid.\n",
167 DeviceExtension->DeviceId);
168 break;
169
170 /* Status of the battery has changed */
172
173 /* All we'll do is notify the class driver */
174 DeviceExtension->ArFlag |= CMBATT_AR_NOTIFY;
175 break;
176
177 /* Information on the battery has changed, such as physical presence */
180
181 /* Reset all state and let the class driver re-evaluate it all */
182 DeviceExtension->ArFlag |= (CMBATT_AR_NOTIFY |
185 break;
186
187 default:
188
190 DbgPrint("CmBattNotifyHandler: Unknown Notify Value: %x\n", NotifyValue);
191 }
192
193 /* Check if we're supposed to delay the notification till later */
194 if (DeviceExtension->DelayNotification)
195 {
196 /* We'll handle this when we get a status query later on */
198 DbgPrint("CmBattNotifyHandler: Notification delayed: ARs = %01x\n",
199 DeviceExtension->ArFlag);
200 return;
201 }
202
203 /* We're going to handle this now */
205 DbgPrint("CmBattNotifyHandler: Performing ARs: %01x\n", DeviceExtension->ArFlag);
206
207 /* Check if this is a battery or AC adapter notification */
208 if (DeviceExtension->FdoType == CmBattBattery)
209 {
210 /* Reset the current trip point */
211 DeviceExtension->TripPointValue = BATTERY_UNKNOWN_CAPACITY;
212
213 /* Check what ARs have to be done */
214 ArFlag = DeviceExtension->ArFlag;
215
216 /* New battery inserted, reset lock value */
217 if (ArFlag & CMBATT_AR_INSERT) InterlockedExchange(&DeviceExtension->ArLockValue, 0);
218
219 /* Check if the battery may have been removed */
220 if (ArFlag & CMBATT_AR_REMOVE) DeviceExtension->Tag = 0;
221
222 /* Check if there's been any sort of change to the battery */
223 if (ArFlag & CMBATT_AR_NOTIFY)
224 {
225 /* We'll probably end up re-evaluating _BIF and _BST */
226 DeviceExtension->NotifySent = TRUE;
227 BatteryClassStatusNotify(DeviceExtension->ClassData);
228 }
229 }
230 else if (DeviceExtension->ArFlag & CMBATT_AR_NOTIFY)
231 {
232 /* The only known notification is AC/DC change. Loop device objects. */
233 for (DeviceObject = DeviceExtension->FdoDeviceObject->DriverObject->DeviceObject;
235 DeviceObject = DeviceObject->NextDevice)
236 {
237 /* Is this a battery? */
238 FdoExtension = DeviceObject->DeviceExtension;
239 if (FdoExtension->FdoType == CmBattBattery)
240 {
241 /* Send a notification to the class driver */
242 FdoExtension->NotifySent = TRUE;
244 }
245 }
246 }
247
248 /* ARs have been processed */
249 DeviceExtension->ArFlag = 0;
250}
#define InterlockedExchange
Definition: armddk.h:54
BCLASSAPI NTSTATUS NTAPI BatteryClassStatusNotify(_In_ PVOID ClassData)
Definition: battc.c:79
#define ACPI_BUS_CHECK
Definition: cmbatt.h:63
#define CMBATT_ACPI_WARNING
Definition: cmbatt.h:38
#define CMBATT_ACPI_ASSERT
Definition: cmbatt.h:43
#define ACPI_BATT_NOTIFY_INFO
Definition: cmbatt.h:73
#define CMBATT_AR_INSERT
Definition: cmbatt.h:154
#define CMBATT_AR_REMOVE
Definition: cmbatt.h:155
#define ACPI_DEVICE_CHECK
Definition: cmbatt.h:64
#define CMBATT_GENERIC_WARNING
Definition: cmbatt.h:37
#define CMBATT_PNP_INFO
Definition: cmbatt.h:40
#define CMBATT_AR_NOTIFY
Definition: cmbatt.h:153
#define ACPI_BATT_NOTIFY_STATUS
Definition: cmbatt.h:72
@ FdoExtension
Definition: precomp.h:48
uint32_t ULONG
Definition: typedefs.h:59
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by CmBattAddAcAdapter(), CmBattAddBattery(), CmBattGetBatteryStatus(), CmBattRemoveDevice(), and CmBattSetStatusNotify().

◆ CmBattPnpDispatch()

NTSTATUS NTAPI CmBattPnpDispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Referenced by DriverEntry().

◆ CmBattPowerDispatch()

NTSTATUS NTAPI CmBattPowerDispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Referenced by DriverEntry().

◆ CmBattQueryInformation()

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 
)

Definition at line 1317 of file cmbatt.c.

1324{
1326 PVOID QueryData = NULL;
1327 ULONG QueryLength = 0;
1328 ULONG RemainingTime = 0;
1329 ANSI_STRING TempString;
1330 UNICODE_STRING TempString2;
1331 WCHAR InfoBuffer[256];
1332 WCHAR TempBuffer[256];
1333 UNICODE_STRING InfoString;
1334 ULONG RemainingCapacity;
1335 BATTERY_REPORTING_SCALE BatteryReportingScale[2];
1336 LONG Rate;
1337 PAGED_CODE();
1339 DbgPrint("CmBattQueryInformation - Tag (%d) Device %d, Informationlevel %d\n",
1340 Tag,
1341 FdoExtension->DeviceId,
1342 InfoLevel);
1343
1344 /* Check ACPI Data */
1346 if (!NT_SUCCESS(Status)) return Status;
1347
1348 /* Check what caller wants */
1349 switch (InfoLevel)
1350 {
1351 case BatteryInformation:
1352 /* Just return our static information */
1353 QueryData = &FdoExtension->BatteryInformation;
1354 QueryLength = sizeof(BATTERY_INFORMATION);
1355 break;
1356
1358
1359 /* Return our static information, we have two scales */
1360 BatteryReportingScale[0].Granularity = FdoExtension->BatteryCapacityGranularity1;
1361 BatteryReportingScale[0].Capacity = FdoExtension->BatteryInformation.DefaultAlert1;
1362 BatteryReportingScale[1].Granularity = FdoExtension->BatteryCapacityGranularity2;
1363 BatteryReportingScale[1].Capacity = FdoExtension->BatteryInformation.DesignedCapacity;
1364 QueryData = BatteryReportingScale;
1365 QueryLength = sizeof(BATTERY_REPORTING_SCALE) * 2;
1366 break;
1367
1369
1370 /* Check if it's been more than 15 seconds since the last change */
1371 if (KeQueryInterruptTime() > (FdoExtension->InterruptTime + CMBATT_DISCHARGE_TIME))
1372 {
1373 /* Get new battery status */
1375
1376 /* If the caller didn't specify a rate, use our static one */
1377 Rate = AtRate;
1378 if (!Rate) Rate = FdoExtension->Rate;
1379
1380 /* If we don't have a valid negative rate, use unknown value */
1381 if (Rate >= 0) Rate = BATTERY_UNKNOWN_RATE;
1382
1383 /* Grab the remaining capacity */
1384 RemainingCapacity = FdoExtension->RemainingCapacity;
1385
1386 /* Default time to unknown if we fail the request later */
1387 RemainingTime = BATTERY_UNKNOWN_TIME;
1388
1389 /* See if we don't know one or the other */
1390 if ((Rate == BATTERY_UNKNOWN_RATE) ||
1391 (RemainingCapacity == BATTERY_UNKNOWN_CAPACITY))
1392 {
1393 /* If the battery is discharging, we can't give out a time */
1394 if ((FdoExtension->BstData.State & ACPI_BATT_STAT_DISCHARG) &&
1396 DbgPrint("CmBattQueryInformation: Can't calculate EstimatedTime.\n");
1397
1398 /* Check if we don't have a rate and capacity is going down */
1399 if ((FdoExtension->Rate == BATTERY_UNKNOWN_RATE) &&
1400 (FdoExtension->BstData.State & ACPI_BATT_STAT_DISCHARG))
1401 {
1402 /* We have to fail, since we lack data */
1405 DbgPrint("---------------------- PresentRate = BATTERY_UNKNOWN_RATE\n");
1406 }
1407
1408 /* If we don't have capacity, the rate is useless */
1409 if (RemainingCapacity == BATTERY_UNKNOWN_CAPACITY)
1410 {
1411 /* We have to fail the request */
1414 DbgPrint("---------------------- RemainingCapacity = BATTERY_UNKNOWN_CAPACITY\n");
1415 }
1416 }
1417 else
1418 {
1419 /* We have data, but is it valid? */
1420 if (RemainingCapacity > CMBATT_CAPACITY_BOGUS)
1421 {
1422 /* The capacity seems bogus, so don't use it */
1424 DbgPrint("CmBattQueryInformation: Data Overflow in calculating Remaining Capacity.\n");
1425 }
1426 else
1427 {
1428 /* Compute the remaining time in seconds, based on rate */
1429 RemainingTime = (RemainingCapacity * 3600) / -Rate;
1430 }
1431 }
1432 }
1433 else
1434 {
1435 RemainingTime = BATTERY_UNKNOWN_TIME;
1436 }
1437
1438 /* Return the remaining time */
1439 QueryData = &RemainingTime;
1440 QueryLength = sizeof(ULONG);
1441 break;
1442
1443 case BatteryDeviceName:
1444
1445 /* Build the model number string */
1446 if (FdoExtension->BattInfo.ExtendedData)
1447 {
1448 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BixData.ModelNumber);
1449 }
1450 else
1451 {
1452 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BifData.ModelNumber);
1453 }
1454
1455 /* Convert it to Unicode */
1456 InfoString.Buffer = InfoBuffer;
1457 InfoString.MaximumLength = sizeof(InfoBuffer);
1458 Status = RtlAnsiStringToUnicodeString(&InfoString, &TempString, 0);
1459
1460 /* Return the unicode buffer */
1461 QueryData = InfoString.Buffer;
1462 QueryLength = InfoString.Length;
1463 break;
1464
1465 case BatteryTemperature:
1467
1468 /* We don't support these */
1470 break;
1471
1473
1474 /* Build the OEM info string */
1475 if (FdoExtension->BattInfo.ExtendedData)
1476 {
1477 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BixData.OemInfo);
1478 }
1479 else
1480 {
1481 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BifData.OemInfo);
1482 }
1483
1484 /* Convert it to Unicode */
1485 InfoString.Buffer = InfoBuffer;
1486 InfoString.MaximumLength = sizeof(InfoBuffer);
1487 Status = RtlAnsiStringToUnicodeString(&InfoString, &TempString, 0);
1488
1489 /* Return the unicode buffer */
1490 QueryData = InfoString.Buffer;
1491 QueryLength = InfoString.Length;
1492 break;
1493
1494 case BatteryUniqueID:
1495
1496 /* Build the serial number string */
1497 if (FdoExtension->BattInfo.ExtendedData)
1498 {
1499 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BixData.SerialNumber);
1500 }
1501 else
1502 {
1503 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BifData.SerialNumber);
1504 }
1505
1506 /* Convert it to Unicode */
1507 InfoString.Buffer = InfoBuffer;
1508 InfoString.MaximumLength = sizeof(InfoBuffer);
1509 RtlAnsiStringToUnicodeString(&InfoString, &TempString, 0);
1510
1511 /* Setup a temporary string for concatenation */
1512 TempString2.Buffer = TempBuffer;
1513 TempString2.MaximumLength = sizeof(TempBuffer);
1514
1515 /* Check if there's an OEM string */
1516 if ((FdoExtension->BattInfo.ExtendedData && FdoExtension->BattInfo.BixData.OemInfo[0]) ||
1517 FdoExtension->BattInfo.BifData.OemInfo[0])
1518 {
1519 /* Build the OEM info string */
1520 if (FdoExtension->BattInfo.ExtendedData)
1521 {
1522 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BixData.OemInfo);
1523 }
1524 else
1525 {
1526 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BifData.OemInfo);
1527 }
1528
1529 /* Convert it to Unicode and append it */
1530 RtlAnsiStringToUnicodeString(&TempString2, &TempString, 0);
1531 RtlAppendUnicodeStringToString(&InfoString, &TempString2);
1532 }
1533
1534 /* Build the model number string */
1535 if (FdoExtension->BattInfo.ExtendedData)
1536 {
1537 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BixData.ModelNumber);
1538 }
1539 else
1540 {
1541 RtlInitAnsiString(&TempString, FdoExtension->BattInfo.BifData.ModelNumber);
1542 }
1543
1544 /* Convert it to Unicode and append it */
1545 RtlAnsiStringToUnicodeString(&TempString2, &TempString, 0);
1546 RtlAppendUnicodeStringToString(&InfoString, &TempString2);
1547
1548 /* Return the final appended string */
1549 QueryData = InfoString.Buffer;
1550 QueryLength = InfoString.Length;
1551 break;
1552
1553 default:
1554
1555 /* Everything else is unknown */
1557 break;
1558 }
1559
1560 /* Return the required length and check if the caller supplied enough */
1561 *ReturnedLength = QueryLength;
1562 if (BufferLength < QueryLength) Status = STATUS_BUFFER_TOO_SMALL;
1563
1564 /* Copy the data if there's enough space and it exists */
1565 if ((NT_SUCCESS(Status)) && (QueryData)) RtlCopyMemory(Buffer, QueryData, QueryLength);
1566
1567 /* Return function result */
1568 return Status;
1569}
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG AtRate
Definition: batclass.h:185
struct _BATTERY_INFORMATION BATTERY_INFORMATION
@ BatteryInformation
Definition: batclass.h:97
@ BatteryManufactureName
Definition: batclass.h:103
@ BatteryGranularityInformation
Definition: batclass.h:98
@ BatteryUniqueID
Definition: batclass.h:104
@ BatteryEstimatedTime
Definition: batclass.h:100
@ BatteryDeviceName
Definition: batclass.h:101
@ BatteryTemperature
Definition: batclass.h:99
@ BatteryManufactureDate
Definition: batclass.h:102
#define BATTERY_UNKNOWN_RATE
Definition: batclass.h:82
#define BATTERY_UNKNOWN_TIME
Definition: batclass.h:68
Definition: bufpool.h:45
NTSTATUS NTAPI CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG Tag)
Definition: cmbatt.c:1083
NTSTATUS NTAPI CmBattVerifyStaticInfo(_Inout_ PCMBATT_DEVICE_EXTENSION DeviceExtension, _In_ ULONG BatteryTag)
Definition: cmbatt.c:511
#define CMBATT_GENERIC_INFO
Definition: cmbatt.h:36
#define CMBATT_CAPACITY_BOGUS
Definition: cmbatt.h:55
#define CMBATT_DISCHARGE_TIME
Definition: cmbatt.h:49
#define ACPI_BATT_STAT_DISCHARG
Definition: cmbatt.h:75
#define NULL
Definition: types.h:112
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 RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
long LONG
Definition: pedump.c:60
#define KeQueryInterruptTime()
Definition: ke.h:37
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CmBattAddBattery().

◆ CmBattQueryStatus()

NTSTATUS NTAPI CmBattQueryStatus ( IN PCMBATT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  Tag,
IN PBATTERY_STATUS  BatteryStatus 
)

Definition at line 1573 of file cmbatt.c.

1576{
1578 PAGED_CODE();
1580 DbgPrint("CmBattQueryStatus - Tag (%d) Device %x\n", Tag, DeviceExtension->DeviceId);
1581
1582 /* Query ACPI information */
1583 Status = CmBattGetBatteryStatus(DeviceExtension, Tag);
1584 if (NT_SUCCESS(Status))
1585 {
1586 BatteryStatus->PowerState = DeviceExtension->State;
1587 BatteryStatus->Capacity = DeviceExtension->RemainingCapacity;
1588 BatteryStatus->Voltage = DeviceExtension->PresentVoltage;
1589 BatteryStatus->Rate = DeviceExtension->Rate;
1590 }
1591
1592 /* Return status */
1594 DbgPrint("CmBattQueryStatus: Returning [%#08lx][%#08lx][%#08lx][%#08lx]\n",
1599 return Status;
1600}
_In_ ULONG _Out_ PBATTERY_STATUS BatteryStatus
Definition: batclass.h:199
ULONG PowerState
Definition: batclass.h:154
ULONG Capacity
Definition: batclass.h:155

Referenced by CmBattAddBattery().

◆ CmBattQueryTag()

NTSTATUS NTAPI CmBattQueryTag ( IN PCMBATT_DEVICE_EXTENSION  DeviceExtension,
OUT PULONG  Tag 
)

Definition at line 826 of file cmbatt.c.

828{
829 PDEVICE_OBJECT PdoDevice;
830 ULONG StaData;
832 PAGED_CODE();
834 DbgPrint("CmBattQueryTag - Tag (%d), Battery %x, Device %d\n",
835 *Tag, DeviceExtension, DeviceExtension->DeviceId);
836
837 /* Get PDO and clear notification flag */
838 PdoDevice = DeviceExtension->PdoDeviceObject;
839 DeviceExtension->NotifySent = 0;
840
841 /* Get _STA from PDO (we need the machine status, not the battery status) */
842 Status = CmBattGetStaData(PdoDevice, &StaData);
843 if (NT_SUCCESS(Status))
844 {
845 /* Is a battery present? */
846 if (StaData & ACPI_STA_BATTERY_PRESENT)
847 {
848 /* Do we not have a tag yet? */
849 if (DeviceExtension->Tag == BATTERY_TAG_INVALID)
850 {
851 /* Set the new tag value, reset tags if we reached the maximum */
852 if (++DeviceExtension->TagData == BATTERY_TAG_INVALID)
853 DeviceExtension->TagData = 1;
854 DeviceExtension->Tag = DeviceExtension->TagData;
856 DbgPrint("CmBattQueryTag - New Tag: (%d)\n", DeviceExtension->Tag);
857
858 /* Reset trip point data */
859 DeviceExtension->TripPointOld = 0;
860 DeviceExtension->TripPointValue = BATTERY_UNKNOWN_CAPACITY;
861
862 /* Clear AR lock and set new interrupt time */
863 InterlockedExchange(&DeviceExtension->ArLockValue, 0);
864 DeviceExtension->InterruptTime = KeQueryInterruptTime();
865 }
866 }
867 else
868 {
869 /* No battery, so no tag */
870 DeviceExtension->Tag = BATTERY_TAG_INVALID;
872 }
873 }
874
875 /* Return the tag and status result */
876 *Tag = DeviceExtension->Tag;
878 DbgPrint("CmBattQueryTag: Returning Tag: 0x%x, status 0x%x\n", *Tag, Status);
879 return Status;
880}
#define ACPI_STA_BATTERY_PRESENT
Definition: actypes.h:1344
#define BATTERY_TAG_INVALID
Definition: batclass.h:94
NTSTATUS NTAPI CmBattGetStaData(PDEVICE_OBJECT DeviceObject, PULONG StaData)
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136

Referenced by CmBattAddBattery().

◆ CmBattSetStatusNotify()

NTSTATUS NTAPI CmBattSetStatusNotify ( IN PCMBATT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  BatteryTag,
IN PBATTERY_NOTIFY  BatteryNotify 
)

Definition at line 925 of file cmbatt.c.

928{
930 ACPI_BST_DATA BstData;
931 ULONG PowerUnit, Capacity, NewTripPoint, TripPoint, DesignVoltage;
932 BOOLEAN Charging;
933 PAGED_CODE();
935 DbgPrint("CmBattSetStatusNotify: Tag (%d) Target(0x%x)\n",
937
938 /* Update any ACPI evaluations */
939 Status = CmBattVerifyStaticInfo(DeviceExtension, BatteryTag);
940 if (!NT_SUCCESS(Status)) return Status;
941
942 /* Trip point not supported, fail */
943 if (!DeviceExtension->TripPointSet) return STATUS_OBJECT_NAME_NOT_FOUND;
944
945 /* Are both capacities known? */
948 {
949 /* We can't set trip points without these */
951 DbgPrint("CmBattSetStatusNotify: Failing request because of BATTERY_UNKNOWN_CAPACITY.\n");
953 }
954
955 /* Is the battery charging? */
956 Charging = DeviceExtension->BstData.State & ACPI_BATT_STAT_CHARGING;
957 if (Charging)
958 {
959 /* Then the trip point is when we hit the cap */
960 Capacity = BatteryNotify->HighCapacity;
961 NewTripPoint = BatteryNotify->HighCapacity;
962 }
963 else
964 {
965 /* Otherwise it's when we discharge to the bottom */
966 Capacity = BatteryNotify->LowCapacity;
967 NewTripPoint = BatteryNotify->LowCapacity;
968 }
969
970 /* Is this machine supporting _BIX or _BIF? */
971 if (DeviceExtension->BattInfo.ExtendedData)
972 {
973 PowerUnit = DeviceExtension->BattInfo.BixData.PowerUnit;
974 DesignVoltage = DeviceExtension->BattInfo.BixData.DesignVoltage;
975 }
976 else
977 {
978 PowerUnit = DeviceExtension->BattInfo.BifData.PowerUnit;
979 DesignVoltage = DeviceExtension->BattInfo.BifData.DesignVoltage;
980 }
981
982 /* Do we have data in Amps or Watts? */
983 if (PowerUnit == ACPI_BATT_POWER_UNIT_AMPS)
984 {
985 /* We need the voltage to do the conversion */
986 if ((DesignVoltage != BATTERY_UNKNOWN_VOLTAGE) && (DesignVoltage))
987 {
988 /* Convert from mAh into Ah */
989 TripPoint = 1000 * NewTripPoint;
990 if (Charging)
991 {
992 /* Scale the high trip point */
993 NewTripPoint = (TripPoint + 500) / DesignVoltage + ((TripPoint + 500) % DesignVoltage != 0);
994 }
995 else
996 {
997 /* Scale the low trip point */
998 NewTripPoint = (TripPoint - 500) / DesignVoltage - ((TripPoint - 500) % DesignVoltage == 0);
999 }
1000 }
1001 else
1002 {
1003 /* Without knowing the voltage, Amps are not enough data on consumption */
1006 DbgPrint("CmBattSetStatusNotify: Can't calculate BTP, DesignVoltage = 0x%08x\n",
1007 DesignVoltage);
1008 }
1009 }
1010 else if (Charging)
1011 {
1012 /* Make it trip just one past the charge cap */
1013 ++NewTripPoint;
1014 }
1015 else if (NewTripPoint > 0)
1016 {
1017 /* Make it trip just one below the drain cap */
1018 --NewTripPoint;
1019 }
1020
1021 /* Do we actually have a new trip point? */
1022 if (NewTripPoint == DeviceExtension->TripPointValue)
1023 {
1024 /* No, so there is no work to be done */
1026 DbgPrint("CmBattSetStatusNotify: Keeping original setting: %X\n", DeviceExtension->TripPointValue);
1027 return STATUS_SUCCESS;
1028 }
1029
1030 /* Set the trip point with ACPI and check for success */
1031 DeviceExtension->TripPointValue = NewTripPoint;
1032 Status = CmBattSetTripPpoint(DeviceExtension, NewTripPoint);
1033 if (!(NewTripPoint) && (Capacity)) Status = STATUS_NOT_SUPPORTED;
1034 if (!NT_SUCCESS(Status))
1035 {
1036 /* We failed to set the trip point, or there wasn't one settable */
1037 DeviceExtension->TripPointValue = BATTERY_UNKNOWN_CAPACITY;
1039 DbgPrint("CmBattSetStatusNotify: SetTripPoint failed - %x\n", Status);
1040 return Status;
1041 }
1042
1043 /* Read the new BST data to see the latest state */
1044 Status = CmBattGetBstData(DeviceExtension, &BstData);
1045 if (!NT_SUCCESS(Status))
1046 {
1047 /* We'll return failure to the caller */
1049 DbgPrint("CmBattSetStatusNotify: GetBstData - %x\n", Status);
1050 }
1051 else if ((Charging) && (BstData.RemainingCapacity >= NewTripPoint))
1052 {
1053 /* We are charging and our capacity is past the trip point, so trip now */
1055 DbgPrint("CmBattSetStatusNotify: Trip point already crossed (1): TP = %08x, remaining capacity = %08x\n",
1056 NewTripPoint, BstData.RemainingCapacity);
1058 }
1059 else if ((BstData.RemainingCapacity) && (Capacity))
1060 {
1061 /* We are discharging, and our capacity is below the trip point, trip now */
1063 DbgPrint("CmBattSetStatusNotify: Trip point already crossed (1): TP = %08x, remaining capacity = %08x\n",
1064 NewTripPoint, BstData.RemainingCapacity);
1066 }
1067
1068 /* All should've went well if we got here, unless BST failed... return! */
1070 DbgPrint("CmBattSetStatusNotify: Want %X CurrentCap %X\n",
1071 Capacity, DeviceExtension->RemainingCapacity);
1073 DbgPrint("CmBattSetStatusNotify: Set to: [%#08lx][%#08lx][%#08lx] Status %lx\n",
1077 Status);
1078 return Status;
1079}
unsigned char BOOLEAN
_In_ ULONG _In_ PBATTERY_NOTIFY BatteryNotify
Definition: batclass.h:216
_Out_ PULONG BatteryTag
Definition: batclass.h:173
#define BATTERY_UNKNOWN_VOLTAGE
Definition: batclass.h:79
VOID NTAPI CmBattNotifyHandler(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG NotifyValue)
Definition: cmbatt.c:142
#define CMBATT_GENERIC_STATUS
Definition: cmbatt.h:35
NTSTATUS NTAPI CmBattGetBstData(PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BST_DATA BstData)
Definition: cmexec.c:514
#define ACPI_BATT_STAT_CHARGING
Definition: cmbatt.h:76
#define ACPI_BATT_POWER_UNIT_AMPS
Definition: cmbatt.h:98
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
ULONG LowCapacity
Definition: batclass.h:204
ULONG HighCapacity
Definition: batclass.h:205
ULONG PowerState
Definition: batclass.h:203

Referenced by CmBattAddBattery().

◆ CmBattSetTripPpoint()

NTSTATUS NTAPI CmBattSetTripPpoint ( PCMBATT_DEVICE_EXTENSION  DeviceExtension,
ULONG  AlarmValue 
)

◆ CmBattSystemControl()

NTSTATUS NTAPI CmBattSystemControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Referenced by DriverEntry().

◆ CmBattWmiDeRegistration()

NTSTATUS NTAPI CmBattWmiDeRegistration ( PCMBATT_DEVICE_EXTENSION  DeviceExtension)

◆ CmBattWmiRegistration()

NTSTATUS NTAPI CmBattWmiRegistration ( PCMBATT_DEVICE_EXTENSION  DeviceExtension)

Variable Documentation

◆ AcAdapterPdo

PDEVICE_OBJECT AcAdapterPdo
extern

◆ CmBattDebug