History log of /freebsd-11-stable/sys/dev/acpica/acpi_battery.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 359076 18-Mar-2020 hrs

MFC of r355574, r358095, and r358395:

Add ACPI battery subsystem man page.

Add _BIX (Battery Information Extended) object support.

ACPI Control Method Batteries have a _BIF and/or _BIX object which
provide static properties of the battery. FreeBSD acpi_cmbat module
supported _BIF object only, which was deprecated as of ACPI 4.0.
_BIX is an extended version of _BIF defined in ACPI 4.0 or later.

As of writing, _BIX has two revisions. One is in ACPI 4.0 (rev.0) and
another is in ACPI 6.0 (rev.1). It seems that hardware vendors still
stick to _BIF only or _BIX rev.0 + _BIF for the maximum compatibility.
Microsoft requires _BIX rev.0 for Windows machines, so there are some
laptop machines with _BIX rev.0 only. In this case, FreeBSD does not
recognize the battery information.

After this change, the acpi_cmbat module gets battery information from
_BIX or _BIF object and internally uses _BIX rev.1 data structure as
the primary information store in the kernel. ACPIIO_BATT_GET_BI[FX]
returns an acpi_bi[fx] structure built by using information obtained
from a _BIF or a _BIX object found on the system. The revision number
field can be used to check which field is available. The acpiconf(8)
utility will show additional information if _BIX is available.

Although ABIs of ACPIIO_BATT_* were changed, the existing APIs for
userland utilities are not changed and the backward-compatible ABIs
are provided. This means that older versions of acpiconf(8) can also
work with the new kernel. The (union acpi_battery_ioctl_arg) was
padded to 256 byte long to avoid another ABI change in the future.
A _BIX object with its revision number >1 will be treated as
compatible with the rev.1 _BIX format.

Add workaround for models which do not follow the ACPI specification strictly.
Extra objects are now simply ignored instead of rejecting everything.

Differential Revision: https://reviews.freebsd.org/D22556
Differential Revision: https://reviews.freebsd.org/D23728


# 348726 06-Jun-2019 allanjude

MFC r348065:

Correct the way remaining battery life is calculated

Previously, if a system had multiple batteries, the remaining life
percentage was calculated as the average of each battery's percent
remaining. This results in rather incorrect values when you consider the
case of the Thinkpad X270 that has a small 3 cell internally battery, and
a hot-swappable 9 cell battery that is used first. Battery 0 is at 100%,
but battery 1 is at 10%, you do not infact have 55% of your capacity
remaining.

The new method calculates the percentage based on remaining capacity
out of total capacity, giving a much more accurate reading.

PR: 229818
Submitted by: Keegan Drake H.P. <kd-dev@pm.me>
Sponsored by: Klara Systems
Event: Waterloo Hackathon 2019
Approved by: re (gjb)


# 342712 03-Jan-2019 jhb

MFC 339899: Make battery emptying rate available as sysctl variable.

Curiously, the in-kernel routines always use the design voltage to
convert from mA to mW, but acpiconf in userland uses the current
voltage. As a result, this can report a different mW rate than
acpiconf.


# 302408 07-Jul-2016 gjb

Copy head@r302406 to stable/11 as part of the 11.0-RELEASE cycle.
Prune svn:mergeinfo from the new branch, as nothing has been merged
here.

Additional commits post-branch will follow.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


/freebsd-11-stable/MAINTAINERS
/freebsd-11-stable/cddl
/freebsd-11-stable/cddl/contrib/opensolaris
/freebsd-11-stable/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/print
/freebsd-11-stable/cddl/contrib/opensolaris/cmd/zfs
/freebsd-11-stable/cddl/contrib/opensolaris/lib/libzfs
/freebsd-11-stable/contrib/amd
/freebsd-11-stable/contrib/apr
/freebsd-11-stable/contrib/apr-util
/freebsd-11-stable/contrib/atf
/freebsd-11-stable/contrib/binutils
/freebsd-11-stable/contrib/bmake
/freebsd-11-stable/contrib/byacc
/freebsd-11-stable/contrib/bzip2
/freebsd-11-stable/contrib/com_err
/freebsd-11-stable/contrib/compiler-rt
/freebsd-11-stable/contrib/dialog
/freebsd-11-stable/contrib/dma
/freebsd-11-stable/contrib/dtc
/freebsd-11-stable/contrib/ee
/freebsd-11-stable/contrib/elftoolchain
/freebsd-11-stable/contrib/elftoolchain/ar
/freebsd-11-stable/contrib/elftoolchain/brandelf
/freebsd-11-stable/contrib/elftoolchain/elfdump
/freebsd-11-stable/contrib/expat
/freebsd-11-stable/contrib/file
/freebsd-11-stable/contrib/gcc
/freebsd-11-stable/contrib/gcclibs/libgomp
/freebsd-11-stable/contrib/gdb
/freebsd-11-stable/contrib/gdtoa
/freebsd-11-stable/contrib/groff
/freebsd-11-stable/contrib/ipfilter
/freebsd-11-stable/contrib/ldns
/freebsd-11-stable/contrib/ldns-host
/freebsd-11-stable/contrib/less
/freebsd-11-stable/contrib/libarchive
/freebsd-11-stable/contrib/libarchive/cpio
/freebsd-11-stable/contrib/libarchive/libarchive
/freebsd-11-stable/contrib/libarchive/libarchive_fe
/freebsd-11-stable/contrib/libarchive/tar
/freebsd-11-stable/contrib/libc++
/freebsd-11-stable/contrib/libc-vis
/freebsd-11-stable/contrib/libcxxrt
/freebsd-11-stable/contrib/libexecinfo
/freebsd-11-stable/contrib/libpcap
/freebsd-11-stable/contrib/libstdc++
/freebsd-11-stable/contrib/libucl
/freebsd-11-stable/contrib/libxo
/freebsd-11-stable/contrib/llvm
/freebsd-11-stable/contrib/llvm/projects/libunwind
/freebsd-11-stable/contrib/llvm/tools/clang
/freebsd-11-stable/contrib/llvm/tools/lldb
/freebsd-11-stable/contrib/llvm/tools/llvm-dwarfdump
/freebsd-11-stable/contrib/llvm/tools/llvm-lto
/freebsd-11-stable/contrib/mdocml
/freebsd-11-stable/contrib/mtree
/freebsd-11-stable/contrib/ncurses
/freebsd-11-stable/contrib/netcat
/freebsd-11-stable/contrib/ntp
/freebsd-11-stable/contrib/nvi
/freebsd-11-stable/contrib/one-true-awk
/freebsd-11-stable/contrib/openbsm
/freebsd-11-stable/contrib/openpam
/freebsd-11-stable/contrib/openresolv
/freebsd-11-stable/contrib/pf
/freebsd-11-stable/contrib/sendmail
/freebsd-11-stable/contrib/serf
/freebsd-11-stable/contrib/sqlite3
/freebsd-11-stable/contrib/subversion
/freebsd-11-stable/contrib/tcpdump
/freebsd-11-stable/contrib/tcsh
/freebsd-11-stable/contrib/tnftp
/freebsd-11-stable/contrib/top
/freebsd-11-stable/contrib/top/install-sh
/freebsd-11-stable/contrib/tzcode/stdtime
/freebsd-11-stable/contrib/tzcode/zic
/freebsd-11-stable/contrib/tzdata
/freebsd-11-stable/contrib/unbound
/freebsd-11-stable/contrib/vis
/freebsd-11-stable/contrib/wpa
/freebsd-11-stable/contrib/xz
/freebsd-11-stable/crypto/heimdal
/freebsd-11-stable/crypto/openssh
/freebsd-11-stable/crypto/openssl
/freebsd-11-stable/gnu/lib
/freebsd-11-stable/gnu/usr.bin/binutils
/freebsd-11-stable/gnu/usr.bin/cc/cc_tools
/freebsd-11-stable/gnu/usr.bin/gdb
/freebsd-11-stable/lib/libc/locale/ascii.c
/freebsd-11-stable/sys/cddl/contrib/opensolaris
/freebsd-11-stable/sys/contrib/dev/acpica
/freebsd-11-stable/sys/contrib/ipfilter
/freebsd-11-stable/sys/contrib/libfdt
/freebsd-11-stable/sys/contrib/octeon-sdk
/freebsd-11-stable/sys/contrib/x86emu
/freebsd-11-stable/sys/contrib/xz-embedded
/freebsd-11-stable/usr.sbin/bhyve/atkbdc.h
/freebsd-11-stable/usr.sbin/bhyve/bhyvegc.c
/freebsd-11-stable/usr.sbin/bhyve/bhyvegc.h
/freebsd-11-stable/usr.sbin/bhyve/console.c
/freebsd-11-stable/usr.sbin/bhyve/console.h
/freebsd-11-stable/usr.sbin/bhyve/pci_fbuf.c
/freebsd-11-stable/usr.sbin/bhyve/pci_xhci.c
/freebsd-11-stable/usr.sbin/bhyve/pci_xhci.h
/freebsd-11-stable/usr.sbin/bhyve/ps2kbd.c
/freebsd-11-stable/usr.sbin/bhyve/ps2kbd.h
/freebsd-11-stable/usr.sbin/bhyve/ps2mouse.c
/freebsd-11-stable/usr.sbin/bhyve/ps2mouse.h
/freebsd-11-stable/usr.sbin/bhyve/rfb.c
/freebsd-11-stable/usr.sbin/bhyve/rfb.h
/freebsd-11-stable/usr.sbin/bhyve/sockstream.c
/freebsd-11-stable/usr.sbin/bhyve/sockstream.h
/freebsd-11-stable/usr.sbin/bhyve/usb_emul.c
/freebsd-11-stable/usr.sbin/bhyve/usb_emul.h
/freebsd-11-stable/usr.sbin/bhyve/usb_mouse.c
/freebsd-11-stable/usr.sbin/bhyve/vga.c
/freebsd-11-stable/usr.sbin/bhyve/vga.h
# 227992 26-Nov-2011 dumbbell

Prevent a division by zero with some broken batteries

This problem was seen on a laptop with a dead battery.


# 216503 17-Dec-2010 avg

small cleanup of acpi battery status setting and checking

This is based on the patch submitted by Yuri Skripachov.
Overview of the changes:
- clarify double-use of some ACPI_BATT_STAT_* definitions
- clean up undefined/extended status bits returned by _BST
- warn about charging+discharging bits being set at the same time

PR: kern/124744
Submitted by: Yuri Skripachov <y.skripachov@gmail.com>
Tested by: Yuri Skripachov <y.skripachov@gmail.com>
MFC after: 2 weeks


# 196403 20-Aug-2009 jhb

Temporarily revert the new-bus locking for 8.0 release. It will be
reintroduced after HEAD is reopened for commits by re@.

Approved by: re (kib), attilio


# 196037 02-Aug-2009 attilio

Make the newbus subsystem Giant free by adding the new newbus sxlock.
The newbus lock is responsible for protecting newbus internIal structures,
device states and devclass flags. It is necessary to hold it when all
such datas are accessed. For the other operations, softc locking should
ensure enough protection to avoid races.

Newbus lock is automatically held when virtual operations on the device
and bus are invoked when loading the driver or when the suspend/resume
take place. For other 'spourious' operations trying to access/modify
the newbus topology, newbus lock needs to be automatically acquired and
dropped.

For the moment Giant is also acquired in some key point (modules subsystem)
in order to avoid problems before the 8.0 release as module handlers could
make assumptions about it. This Giant locking should go just after
the release happens.

Please keep in mind that the public interface can be expanded in order
to provide more support, if there are really necessities at some point
and also some bugs could arise as long as the patch needs a bit of
further testing.

Bump __FreeBSD_version in order to reflect the newbus lock introduction.

Reviewed by: ed, hps, jhb, imp, mav, scottl
No answer by: ariff, thompsa, yongari
Tested by: pho,
G. Trematerra <giovanni dot trematerra at gmail dot com>,
Brandon Gooch <jamesbrandongooch at gmail dot com>
Sponsored by: Yahoo! Incorporated
Approved by: re (ksmith)


# 193530 05-Jun-2009 jkim

Import ACPICA 20090521.


# 187368 17-Jan-2009 mav

Convert battery capacity/rate from mA to mW only when summary is requested.
Unconditional conversion causes incorrect rate units reported by acpiconf.

MFC after: 2 weeks


# 173782 20-Nov-2007 jkim

Check battery presence first before trying to get battery information.

PR: kern/117591
Tested by: Jessica Mahoney (root at varusonline dot com)


# 172490 09-Oct-2007 njl

When the EC times out (common with Compaqs), it may report a design
voltage of 0. This can result in a divide by zero trap. Add a guard
for this case. The value of lfcap is checked in acpi_battery_bif_valid()
just before this, so it is safe.

Reportd by: sam
Approved by: re
MFC after: 3 days


# 165457 21-Dec-2006 imp

ACPIIO_BATT_GET_UNITS would always return ENXIO. However, it should never
return an error since it returns a count of battery devices in the system.
Set it to 0 explicitly, since it is the only switch branch that doesn't set
it.

# I guess no one uses it.


# 159476 10-Jun-2006 njl

Minor sysctl cleanup. The RW flag means read|write and so it is redundant
to add the RD flag. Also, the debug node does not need to be writable.


# 152703 22-Nov-2005 njl

Simplify checks for valid battery info via DeMorgan's Rule. No
functional change.


# 151591 23-Oct-2005 njl

Add prototype to be consistent.


# 151563 22-Oct-2005 njl

Cleanups and support code for importing smart battery support.

* Use ACPI_BATT_UNKNOWN instead of constants
* Use maxunit instead of a count of devices since we may have sparse
battery devices in the future. Only userland should be using unit
numbers anyway, so provide a translation function. (Kernel use of
batteries should be restricted to looking up a device_t and calling
methods directly.
* Don't check acpi_BatteryIsPresent() in acpi_battery. Leave it up to
the hardware-specific driver (i.e. cmbat) since smart batteries seem
to not report the "battery present" flag.
* Convert mA to mW if the battery uses those units. CM-batteries only
used mW so this deficiency went unnoticed.
* Clean strings reported in the battery info from any control chars.
* Only dereference the unit from ioctl_arg if the full struct is present.
Unit wouldn't have been used later if it wasn't present but this is
cleaner. Translate the unit if it's not ACPI_BATTERY_ALL_UNITS.
* bzero structs before returning them to usermode for future compat.

Most of this work was submitted by Hans Petter Selasky and then majorly
reworked by myself.

Submitted by: Hans Petter Selasky <hselasky / c2i.net>


# 150003 11-Sep-2005 obrien

Canonize the include of acpi.h.


# 148968 11-Aug-2005 njl

Modify the fix in rev 1.16 slightly. Instead of setting the cap to zero,
just skip summing it if it's unknown.

MFC after: 1 day


# 148742 05-Aug-2005 njl

When summing capacities, skip info from batteries that weren't present.
Previously, we used all info (including -1 or "not present") which would
keep the system from reaching 100% when charging.

Reported by: Eric Anderson
MFC after: 2 days


# 148492 28-Jul-2005 njl

Add descriptions for the sysctls.

MFC after: 1 day


# 148489 28-Jul-2005 njl

Zero the _BST, _BIF, and battinfo allocations. This is needed since we
later sum capacities for all batteries, even those that weren't actually
present. We only need to do this for _BST but do it for all of them.

Reported by: Eric Anderson
MFC after: 1 day


# 148400 25-Jul-2005 njl

Correct minor output bug. When the battery being queried is charging or
the overall discharge rate is 0, mark the battery remaining time as
"unknown", not 0.

Reported by: Eric Kjeldergaard
MFC after: 4 days


# 148352 23-Jul-2005 njl

Rewrite the acpi_battery interface to allow for other battery types
(i.e., smart battery) and fix various bugs found during the cleanup.

API changes:
* kernel access:
Access to individual batteries is now via devclass_find("battery").
Introduce new methods ACPI_BATT_GET_STATUS (for _BST-formatted data) and
ACPI_BATT_GET_INFO (for _BIF-formatted data). The helper function
acpi_battery_get_battinfo() now takes a device_t instead of a unit #
argument. If dev is NULL, this signifies all batteries.

* ioctl access:
The ACPIIO_BATT_GET_TYPE and ACPIIO_BATT_GET_BATTDESC ioctls have been
removed. Since there is now no need for a mapping between "virtual" unit
and physical unit, usermode programs can just specify the unit directly and
skip the old translation steps. In fact, acpiconf(8) was actually already
doing this and virtual unit was the same as physical unit in all cases
since there was previously only one battery type (acpi_cmbat). Additionally,
we now map the ACPIIO_BATT_GET_BIF and ACPIIO_BATT_GET_BST ioctls for all
batteries, if they provide the associated methods.

* apm compatibility device/ioctls: no change
* sysctl: no change

Since most third-party applications use the apm(4) compat interface, there
should be very few affected applications (if any).

Reviewed by: bruno
MFC after: 5 days


# 143771 17-Mar-2005 njl

Introduce a general name for the previously cmbat-only ioctls. It has the
same value as the previous ioctls so no binary change. Also, make a few
style changes to reduce diffs to my tree.

Loosely based on code from: Hans Petter Selasky


# 143002 02-Mar-2005 obrien

Fix SCM ID's.


# 133614 13-Aug-2004 njl

MPSAFE locking

* Serialize acpi_battery_get_battdesc(), acpi_battery_register(), and
acpi_battery_remove().
* Assert that the sx lock is held in acpi_batteries_init().
* Remove check for device_get_softc() returning NULL.


# 132049 12-Jul-2004 njl

Add the ability to detach a battery. Now batteries that are detached are
also removed from the battery list.


# 118783 11-Aug-2003 njl

Style cleanups to match the rest of this directory. For acpi_battery.c,
remove unused includes.


# 110894 14-Feb-2003 takawata

Allow non-privilaged user to retrive battery or AC line information.

Reviewed by: rwatson


# 105282 16-Oct-2002 jhb

Catch up to changes in acpivar.h to add support for using ACPI on
4-stable systems.

Sponsored by: The Weather Channel


# 89054 08-Jan-2002 msmith

Staticise devclasses and some unnecessarily global variables.


# 85729 30-Oct-2001 iwasaki

Some improvements of control method battery driver.
- Add a new MIB for battery info expire time in order to make it changeable.
Battery info expire time can be specified by
hw.acpi.battery.info_expire in sec.
- Add own MALLOC type and fix some potential memory leakages.
- Change some frequent printings to verbose printing.
- Stop timeout during acpi_cmbat_get_bst() too. This should reduce
the races with BIF evaluation.
- Remove acpi_cmbat_get_bif() invocation from acpi_cmbat_attach().
This was redundant because this should be called from
acpi_cmbat_timeout() now.


# 85556 26-Oct-2001 iwasaki

Add APM compatibility feature to ACPI.
This emulates APM device node interface APIs (mainly ioctl) and
provides APM services for the applications. The goal is to support
most of APM applications without any changes.
Implemented ioctls in this commit are:
- APMIO_SUSPEND (mapped ACPI S3 as default but changable by sysctl)
- APMIO_STANDBY (mapped ACPI S1 as default but changable by sysctl)
- APMIO_GETINFO and APMIO_GETINFO_OLD
- APMIO_GETPWSTATUS

With above, many APM applications which get batteries, ac-line
info. and transition the system into suspend/standby mode (such as
wmapm, xbatt) should work with ACPI enabled kernel (if ACPI works well :-)

Reviewed by: arch@, audit@ and some guys


# 82372 26-Aug-2001 msmith

Updates to match the ACPI CA 20010816 import:

- New debug macro (ACPI_DEBUG_PRINT), reducing debug-case code size.
- New debug level/subsystem codes.


# 79282 05-Jul-2001 msmith

Add a new helper function for finding resources in resource buffers.

Move the ACPI generic battery code into a new file.