📄 smbbattp.h
字号:
/*++
Copyright (c) 1998 Microsoft Corporation
Module Name:
smbbattp.h
Abstract:
Smart Battery Class Driver Header File
Author:
Ken Reneris
Environment:
Notes:
Revision History:
--*/
#ifndef FAR
#define FAR
#endif
#include <ntddk.h>
#include <wmilib.h>
#include <batclass.h>
#include <acpiioct.h>
#include <smbus.h>
#include <dontuse.h>
//
// Debugging
//
#define DEBUG DBG
#if DEBUG
extern ULONG SMBBattDebug;
#define BattPrint(l,m) if(l & SMBBattDebug) DbgPrint m
#else
#define BattPrint(l,m)
#endif
#define BAT_TRACE 0x00000400
#define BAT_STATE 0x00000200
#define BAT_IRPS 0x00000100
#define BAT_IO 0x00000040
#define BAT_DATA 0x00000020
#define BAT_ALARM 0x00000010
#define BAT_NOTE 0x00000008
#define BAT_WARN 0x00000004
#define BAT_ERROR 0x00000002
#define BAT_BIOS_ERROR 0x00000001
//
// Driver supports the following class driver version
//
#define SMB_BATTERY_MAJOR_VERSION 0x0001
#define SMB_BATTERY_MINOR_VERSION 0x0000
//
// Smart battery device driver tag for memory allocations: "BatS"
//
#define SMB_BATTERY_TAG 'StaB'
//
// Globals
//
extern UNICODE_STRING GlobalRegistryPath;
//
// Remove Lock parameters for checked builds
//
#define REMOVE_LOCK_MAX_LOCKED_MINUTES 1
#define REMOVE_LOCK_HIGH_WATER_MARK 64
//
// Driver Device Names (FDO)
//
#define BatterySubsystemName L"\\Device\\SmartBatterySubsystem"
#define SmbBattDeviceName L"\\Device\\SmartBattery"
//
// Query ID Names
//
#define SubSystemIdentifier L"SMBUS\\SMBBATT"
#define BatteryInstance L"Battery"
#define HidSmartBattery L"SMBBATT\\SMART_BATTERY"
//
// Structure for input from private Ioctls to read from devices on smbus
//
typedef struct {
UCHAR Address;
UCHAR Command;
union {
USHORT Block [2];
ULONG Ulong;
} Data;
} SMBBATT_DATA_STRUCT, *PSMBBATT_DATA_STRUCT;
typedef union {
USHORT Block [2];
ULONG Ulong;
} _SMBBATT_DATA_STRUCT_UNION;
#define SMBBATT_DATA_STRUCT_SIZE sizeof (SMBBATT_DATA_STRUCT) - sizeof (_SMBBATT_DATA_STRUCT_UNION)
//
// Private Ioctls for test engines
//
#define IOCTL_SMBBATT_DATA \
CTL_CODE(FILE_DEVICE_BATTERY, 0x100, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
//
// Definitions for the selector state lookup table
//
typedef struct {
UCHAR BatteryIndex;
BOOLEAN ReverseLogic;
} SELECTOR_STATE_LOOKUP;
extern const SELECTOR_STATE_LOOKUP SelectorBits [];
extern const SELECTOR_STATE_LOOKUP SelectorBits4 [];
//
// Definitions for control method names neede by the smart battery
//
#define SMBATT_SBS_METHOD (ULONG) ('SBS_') // control method "_SBS"
#define SMBATT_GLK_METHOD (ULONG) ('KLG_') // control method "_GLK"
//
// Definitions for some string lengths
//
#define MAX_DEVICE_NAME_LENGTH 100
#define MAX_CHEMISTRY_LENGTH 4
//
// Maximum number of smart batteries supported by this driver
//
#define MAX_SMART_BATTERIES_SUPPORTED 4
//
// Types for the FDOs hnadled by this driver:
// Smart battery subsystem FDO
// Smart Battery FDO
// Smart battery PDO
//
typedef enum {
SmbTypeSubsystem,
SmbTypeBattery,
SmbTypePdo
} SMB_FDO_TYPE;
//
// SMB Host Controller Device object extenstion
//
//
// Cached battery info
//
typedef struct {
ULONG Tag;
UCHAR Valid;
BATTERY_INFORMATION Info;
UCHAR ManufacturerNameLength;
UCHAR ManufacturerName[SMB_MAX_DATA_SIZE];
UCHAR DeviceNameLength;
UCHAR DeviceName[SMB_MAX_DATA_SIZE];
BATTERY_MANUFACTURE_DATE ManufacturerDate;
ULONG SerialNumber;
ULONG PowerState;
ULONG Capacity;
ULONG VoltageScale;
ULONG CurrentScale;
ULONG PowerScale;
} STATIC_BAT_INFO, *PSTATIC_BAT_INFO;
#define VALID_TAG_DATA 0x01 // manufacturer, device, serial #
#define VALID_MODE 0x02
#define VALID_OTHER 0x04
#define VALID_CYCLE_COUNT 0x08
#define VALID_SANITY_CHECK 0x10
#define VALID_TAG 0x80
#define VALID_ALL 0x1F // (does not include tag)
//
// Selector information structure
//
typedef struct _BATTERY_SELECTOR {
//
// Addressing and command information. This can change based whether or
// not the selector is stand alone or part of the charger.
//
UCHAR SelectorAddress;
UCHAR SelectorStateCommand;
UCHAR SelectorPresetsCommand;
UCHAR SelectorInfoCommand;
//
// Mutex to keep only one person talking with the selector at a time
//
FAST_MUTEX Mutex;
//
// Cached information. We will get notifications when these change.
//
ULONG SelectorState;
ULONG SelectorPresets;
ULONG SelectorInfo;
} BATTERY_SELECTOR, *PBATTERY_SELECTOR;
typedef struct {
ULONG Setting;
ULONG Skip;
LONG Delta;
LONG AllowedFudge;
} BAT_ALARM_INFO, *PBAT_ALARM_INFO;
typedef struct {
UCHAR Address;
USHORT Data;
LIST_ENTRY Alarms;
} SMB_ALARM_ENTRY, *PSMB_ALARM_ENTRY;
//
// Non-pagable device extension for smart battery FDO
// (Created by IoCreateDevice SMB_NP_BATT for each battery)
//
typedef struct {
SMB_FDO_TYPE SmbBattFdoType; // Device object type
IO_REMOVE_LOCK RemoveLock;
//
// All elements above this point must be identical in
// SMB_NP_BATT, SMB_BATT_SUBSYSTEM, and SMB_BATT_PDO structures.
//
PDEVICE_OBJECT LowerDevice; // Battery Subsystem PDO
//
// All elements above this point must be identical in
// SMB_NP_BATT and SMB_BATT_SUBSYSTEM structures.
//
FAST_MUTEX Mutex; // lets either battery OR subsystem
// have access to batt
PVOID Class; // Battery Class handle
struct _SMB_BATT *Batt; // Battery pageable extension
WMILIB_CONTEXT WmiLibContext;
} SMB_NP_BATT, *PSMB_NP_BATT;
//
// Pagable device extension for smart battery FDO
// (Allocated Extra Memory for device information)
//
typedef struct _SMB_BATT {
//
//
//
PSMB_NP_BATT NP; // Battery device object extension
PDEVICE_OBJECT DeviceObject; // Battery Fdo
PDEVICE_OBJECT PDO; // Battery Pdo
// SMB host controller
PDEVICE_OBJECT SmbHcFdo; // SM bus Fdo
//
// Selector
//
PBATTERY_SELECTOR Selector; // Selector for battery
//
// For handling multiple batteries
//
BOOLEAN SelectorPresent;
ULONG SelectorBitPosition;
//
// Battery
//
ULONG TagCount; // Tag for next battery
STATIC_BAT_INFO Info;
BAT_ALARM_INFO AlarmLow;
} SMB_BATT, *PSMB_BATT;
//
// Device extension for the smart battery subsystem FDO
// (Created by first AddDevice command from ACPI PDO)
//
typedef struct _SMB_BATT_SUBSYSTEM {
SMB_FDO_TYPE SmbBattFdoType; // Device object type
IO_REMOVE_LOCK RemoveLock;
//
// All elements above this point must be identical in
// SMB_NP_BATT, SMB_BATT_SUBSYSTEM, and SMB_BATT_PDO structures.
//
PDEVICE_OBJECT LowerDevice; // Subsystem PDO
//
// All elements above this point must be identical in
// SMB_NP_BATT and SMB_BATT_SUBSYSTEM structures.
//
PVOID SmbAlarmHandle; // handle for SmbAlarm registration
PDEVICE_OBJECT DeviceObject; // Subsystem FDO
PDEVICE_OBJECT SmbHcFdo; // SMBus Fdo
ULONG NumberOfBatteries; // Number of batteries supported
BOOLEAN SelectorPresent; // Is there a selector present
PBATTERY_SELECTOR Selector; // Selector specific info
//
// Stuff for handling the SMB alarms for the smart battery subsystem
//
LIST_ENTRY AlarmList;
KSPIN_LOCK AlarmListLock;
PIO_WORKITEM WorkerThread; // WORK_QUEUE to get worker thread
ULONG WorkerActive;
//
// Keep a list of the battery PDOs I "discover"
//
PDEVICE_OBJECT BatteryPdoList[MAX_SMART_BATTERIES_SUPPORTED];
} SMB_BATT_SUBSYSTEM, *PSMB_BATT_SUBSYSTEM;
//
// Device extension for the smart battery PDOs
// (Created by IoCreateDevice SMB_BATT_PDO for each battery)
//
typedef struct _SMB_BATT_PDO {
SMB_FDO_TYPE SmbBattFdoType; // Device object type
IO_REMOVE_LOCK RemoveLock;
//
// All elements above this point must be identical in
// SMB_NP_BATT, SMB_BATT_SUBSYSTEM, and SMB_BATT_PDO structures.
//
PDEVICE_OBJECT DeviceObject; // Battery PDO
PDEVICE_OBJECT Fdo; // Battery FDO layered on top of PDO
PDEVICE_OBJECT SubsystemFdo; // Smart Battery subsystem FDO
ULONG BatteryNumber; // Used by subsystem during battery
// FDO init
} SMB_BATT_PDO, *PSMB_BATT_PDO;
//
// SMBus Smart battery addresses and registers
//
#define SMB_HOST_ADDRESS 0x8 // Address on bus (10H)
#define SMB_CHARGER_ADDRESS 0x9 // Address on bus (12H)
#define SMB_SELECTOR_ADDRESS 0xa // Address on bus (14H)
#define SMB_BATTERY_ADDRESS 0xb // Address on bus (16H)
#define SMB_ALERT_ADDRESS 0xc // Address on bus (18H)
//
// Smart Battery command codes
//
#define BAT_REMAINING_CAPACITY_ALARM 0x01 // word
#define BAT_REMAINING_TIME_ALARM 0x02 // word
#define BAT_BATTERY_MODE 0x03 // word
#define BAT_AT_RATE 0x04 // word
#define BAT_RATE_TIME_TO_FULL 0x05 // word
#define BAT_RATE_TIME_TO_EMPTY 0x06 // word
#define BAT_RATE_OK 0x07 // word
#define BAT_TEMPERATURE 0x08 // word
#define BAT_VOLTAGE 0x09 // word
#define BAT_CURRENT 0x0a // word
#define BAT_AVERAGE_CURRENT 0x0b // word
#define BAT_MAX_ERROR 0x0c // word
#define BAT_RELATIVE_STATE_OF_CHARGE 0x0d // word
#define BAT_ABSOLUTE_STATE_OF_CHARGE 0x0e // word
#define BAT_REMAINING_CAPACITY 0x0f // word
#define BAT_FULL_CHARGE_CAPACITY 0x10 // word
#define BAT_RUN_TO_EMPTY 0x11 // word
#define BAT_AVERAGE_TIME_TO_EMPTY 0x12 // word
#define BAT_AVERAGE_TIME_TO_FULL 0x13 // word
#define BAT_STATUS 0x16 // word
#define BAT_CYCLE_COUNT 0x17 // word
#define BAT_DESIGN_CAPACITY 0x18 // word
#define BAT_DESIGN_VOLTAGE 0x19 // word
#define BAT_SPECITICATION_INFO 0x1a // word
#define BAT_MANUFACTURER_DATE 0x1b // word
#define BAT_SERIAL_NUMBER 0x1c // word
#define BAT_MANUFACTURER_NAME 0x20 // block
#define BAT_DEVICE_NAME 0x21 // block
#define BAT_CHEMISTRY 0x22 // block
#define BAT_MANUFACTURER_DATA 0x23 // block
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -