History log of /openbsd-current/sys/dev/acpi/acpibat.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.71 24-Jun-2024 mglocker

Some machines send AC change notifications to acpibat(4). Forward this
notification to acpiac(4), so that the AC status can be reflected correctly
to programs like apm(8).

This for example fixes the AC status on the Microsoft Surface Go 4.

Help from kettenis@

ok deraadt@, kettenis@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.70 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_7_1_BASE
# 1.69 09-Feb-2022 dv

add Surface Go 3 hid to acpibat(4)

Microsoft decided to break with basic ACPI standards with the Go 3.
In this case, they don't expose the battery in a standard way, so
acpibat(4) needs to look for the special Microsoft hid.

From mlarkin@, ok kettenis@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.68 10-Jun-2020 jca

Give userland a consistent battery and A/C state after resume

Previously we refreshed the state of acpiac(4) and acpibat(4)/acpisbs(4)
by queueing fake ACPI events to be processed by the acpi thread.
acpibat(4) using ACPIDEV_POLL meant that its status could be refreshed
first, resulting in an APM_POWER_CHANGE event sent to userland before
the state of acpiac(4) was up to date. Because of this, apmd(8) could
see A/C unplugged when it was in fact plugged, possibly leading to
a wrong decision.

Instead of using fake ACPI events, refresh the status of acpiac(4) and
acpibat(4)/acpisbs(4) right away at DVACT_WAKEUP time. To reuse the
existing refresh code of those drivers, make their ACPI *_notify()
handlers responsible for sending APM_POWER_CHANGE events instead. Also
queue an APM_POWER_CHANGE event right after resume to retain existing
behavior.

This fixes the consistency of data shown to userland, and makes those
drivers less special.

Initially discussed last year (!) with mpi@ at Miod's place.
Feedback and ok jcs@, deraadt@ agrees with the use of DVACT_WAKEUP here.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.67 01-Jul-2018 mlarkin

acpi: clean up some inconsistent style in the hid matching arrays

ok millert, kettenis, jcs, phessler, deraadt, mpi


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.66 04-Sep-2017 jcs

Don't require exactly 20 elements in the _BIX package if at least 20
are returned since extras may be OEM-specific values we end up
ignoring anyway, such as on the Lenovo X1C 5th Gen which returns 21
elements.

ok mpi


# 1.65 25-Jul-2017 jcs

fallback on _BIF properly when _BIX exists and returns a package
successfully but has an unexpected length, as on the X1C gen 5

tested by naddy


# 1.64 22-Jul-2017 jcs

acpibat: look for _BIX first before falling back on _BIF

ACPI 4.0 deprecated _BIF for battery status so some newer machines
are exporting _BIX which extends _BIF's package with a few extra
fields. When using _BIX, export the new discharge cycle count as a
sensor.

feedback from kettenis and anton
ok deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.63 12-Mar-2017 jcs

try to attach acpisbs first and if successful, don't attach acpibat


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.62 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.61 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.60 23-May-2014 landry

Expose bif_capacity as the 'design capacity' through an acpibat sensor,
giving you the original capacity of the battery:

hw.sensors.acpibat0.watthour0=64.07 Wh (last full capacity)
hw.sensors.acpibat0.watthour4=84.24 Wh (design capacity)

hw.sensors.acpibat0.amphour0=2.03 Ah (last full capacity)
hw.sensors.acpibat0.amphour4=4.40 Ah (design capacity)

Diff from Fabian Raetz on tech@, thanks!

ok mlarkin@ zhuk@ armani@ kettenis@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.59 16-Oct-2011 kettenis

Provide battery charge/discharge rate in proper units.

Based on a diff from Vladimir Kirrillov.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.58 10-Nov-2010 kettenis

The acpibat(4) notify function should not unconditionally call both _BIF
and _BST. Some machines (like the Toshiba Satellite Pro U550 18F mentioned
in PR 6508) have AML that does a Notify(0x81) from the _BST method, which leads
to infinite recursion. Instead call _BIF when the argument is 0x81 and call
_BST when the argument is 0x80 or 0x00 (the latter indicates we're polling).
Simplify the battery detection logic while there.

ok mikeb@, marco@


Revision tags: OPENBSD_4_8_BASE
# 1.57 07-Aug-2010 canacar

Generate power change events for APM. Makes powerup and powerdown scripts
work with ACPI.
ok deraadt@, phessler@, feedback kettenis@


# 1.56 21-Jul-2010 deraadt

spacing and indents that are driving me crazy


Revision tags: OPENBSD_4_7_BASE
# 1.55 24-Nov-2009 deraadt

Reporting battery insert/removal was debug code. dmesg is not
a place to spam informational messages about unimportant events.
That is what the sensor framework is for (and that is already
done)
ok kettenis


Revision tags: OPENBSD_4_6_BASE
# 1.54 11-Mar-2009 jordan

More aml_evalinteger fixup
ok marco@


Revision tags: OPENBSD_4_5_BASE
# 1.53 06-Nov-2008 marco

Collapse all sanity checks of hids into one function.

Originaly from jordan


# 1.52 14-Aug-2008 robert

add missing semicolon; ok mbalmer@, marco@


Revision tags: OPENBSD_4_4_BASE
# 1.51 05-Aug-2008 marco

Fix spurious 0 values on batteries seen on laptopts that have an embedded
controller.

Found, diagnosed and patch from Stefan Sperling <stsp@stsp.name>
Minor KNF changes while here.

Tested by many on a variaty of IBM laptops and others with and without
acpiec.

ok deraadt


# 1.50 13-Jun-2008 jordan

Properly handle battery insertion/removal
ok @marco


# 1.49 01-Jun-2008 marco

Re-enable new parser. Lots of testing by various folks. Fits all media
now too.

ok kettenis deraadt


# 1.48 16-May-2008 dlg

back out jordans new parser.

it didnt have enough oks from the right people, it did break machines
that were previously working, and it bloated the RAMDISKS and install
media beyond the constraints of the media.

requested by deraadt@


# 1.47 14-May-2008 jordan

Adding new ACPI Parser code
Old guts of code still exists, needs to be torn out next
ok marco@
ok brad@


Revision tags: OPENBSD_4_3_BASE
# 1.46 16-Nov-2007 deraadt

quotes around model name too


# 1.45 12-Nov-2007 deraadt

spacing


# 1.44 12-Nov-2007 deraadt

spacing


# 1.43 12-Nov-2007 deraadt

only print bif info that is complete


# 1.42 08-Nov-2007 canacar

convert the value to a string instead of using aml_val2str()
which returns invalid pointers if the value is not a string, causing
acpibat to panic, as reported by mbalmer@ and Alexey Suslikov.
tested by Alexey Suslikov, ok marco@


# 1.41 03-Nov-2007 deraadt

repair attach messages; ok gwk canacar


Revision tags: OPENBSD_4_2_BASE
# 1.40 20-Mar-2007 mk

Use aml_val2int() instead of accessing v_integer directly.

`sort of ok' marco (before lock)


Revision tags: OPENBSD_4_1_BASE
# 1.39 17-Feb-2007 deanna

Since a full battery can still have state BST_CHARGE ("charging"),
fullness needs to be checked first. Otherwise, full batteries are
always described as "charging."

ok marco


# 1.38 25-Jan-2007 marco

Do the sensor magic correctly. Found by Constantine Murenin.
help from mickey


# 1.37 26-Dec-2006 marco

Add polling to devices that require it such as acpibat and acpitz.
Use the same tsleep/wakeup mechanism as the interrupt code to keep it non-
concurrent.


# 1.36 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.35 21-Dec-2006 deraadt

even more knf love


# 1.34 21-Dec-2006 marco

Tweak to report full battery.


# 1.33 21-Dec-2006 deraadt

more minor knf


# 1.32 21-Dec-2006 marco

Fix silly logic errors.


# 1.31 21-Dec-2006 marco

Silence acpibat significantly and shave off about 1k. Also add some smarts
for battery removal and insertion.


# 1.30 29-Nov-2006 marco

After a long debate at the hackathon it was decided that the acpi implementation
is not concurrent if the sensors thread goes away. This makes acpi completly
lockless.

help and ok dlg


# 1.29 19-Oct-2006 marco

Reduce the scope of the locks.


# 1.28 19-Oct-2006 marco

KNF and some cleanup


# 1.27 19-Oct-2006 marco

Replace ACPI ioctls with APM ioctls. This makes ACPI talk the same protocol
as APM therefore userspace can now retrieve power information in the same
fashion as all other apm arches (zaurus, macppc, i386 etc).

To use force the use of acpi device like so: apmd -f /dev/acpi

ok jordan@


# 1.26 19-Oct-2006 marco

Fix capacity calculations. Tested on Dell C610, D810, Lenovo X60s.

ok jordan


# 1.25 12-Oct-2006 jordan

Massive ACPI changes
Fixed ACPI leaks
new ACPI API
ok marco@


# 1.24 19-Sep-2006 mk

Typo fixes.

ok marco


Revision tags: OPENBSD_4_0_BASE
# 1.23 06-Jun-2006 jolan

fix a bad strlcpy, from ben lovett


# 1.22 19-May-2006 canacar

Use rwlock instead of lockmgr locks.
ok marco@


# 1.21 30-Apr-2006 marco

rv not set. Sloppy but didn't matter.
pointed out by joris@


# 1.20 05-Mar-2006 marco

KNF nit.


Revision tags: OPENBSD_3_9_BASE
# 1.19 22-Feb-2006 marco

Rework notify handler.
Use jordan's new notify register function.
ok jordan@


# 1.18 22-Feb-2006 marco

Add insertion and removal events for batteries.
Some cleanup & KNF.


# 1.17 21-Feb-2006 marco

KNF


# 1.16 21-Feb-2006 marco

Adjust debugging levels to something more reasonable.


# 1.15 17-Feb-2006 marco

Better comments.


# 1.14 17-Feb-2006 marco

Propogate some values through the sysctl hw.sesnsors interface for debug
purposes. This will be removed later and replaced with something better.


# 1.13 17-Feb-2006 marco

Detect if battery slot is available but without a battery in it.

ok jordan


# 1.12 16-Feb-2006 marco

Print useful information during boot about the battery and power supply.

ok jordan.


# 1.11 16-Feb-2006 marco

Adjust debug levels to something sane.


# 1.10 03-Feb-2006 jordan

Rewrote aml parser yet again...
Fixed bus_space_map for i386/amd64
Added _BST and _BIF to acpibat to get status/info
ok marco@


# 1.9 17-Jan-2006 jordan

Major overhaul of the aml parser. Evaluater temporarily disabled.

ok marco@


# 1.8 06-Jan-2006 grange

Sudden newline


# 1.7 30-Dec-2005 tedu

make ACPI_DEBUG compile


# 1.6 28-Dec-2005 marco

oops enabled a method that doesnt work yet so disabled getbif for now.
ok jordan@


# 1.5 28-Dec-2005 marco

Add some return values to getbst and getbif.
ok jordan@


# 1.4 28-Dec-2005 marco

Add 2 methods (Battery Info and Battery Status)
ok jordan@


# 1.3 16-Dec-2005 marco

Use new unified header.


# 1.2 13-Dec-2005 marco

Use shiny new acpibat.h


# 1.1 13-Dec-2005 marco

Add battery device.


# 1.70 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_7_1_BASE
# 1.69 09-Feb-2022 dv

add Surface Go 3 hid to acpibat(4)

Microsoft decided to break with basic ACPI standards with the Go 3.
In this case, they don't expose the battery in a standard way, so
acpibat(4) needs to look for the special Microsoft hid.

From mlarkin@, ok kettenis@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.68 10-Jun-2020 jca

Give userland a consistent battery and A/C state after resume

Previously we refreshed the state of acpiac(4) and acpibat(4)/acpisbs(4)
by queueing fake ACPI events to be processed by the acpi thread.
acpibat(4) using ACPIDEV_POLL meant that its status could be refreshed
first, resulting in an APM_POWER_CHANGE event sent to userland before
the state of acpiac(4) was up to date. Because of this, apmd(8) could
see A/C unplugged when it was in fact plugged, possibly leading to
a wrong decision.

Instead of using fake ACPI events, refresh the status of acpiac(4) and
acpibat(4)/acpisbs(4) right away at DVACT_WAKEUP time. To reuse the
existing refresh code of those drivers, make their ACPI *_notify()
handlers responsible for sending APM_POWER_CHANGE events instead. Also
queue an APM_POWER_CHANGE event right after resume to retain existing
behavior.

This fixes the consistency of data shown to userland, and makes those
drivers less special.

Initially discussed last year (!) with mpi@ at Miod's place.
Feedback and ok jcs@, deraadt@ agrees with the use of DVACT_WAKEUP here.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.67 01-Jul-2018 mlarkin

acpi: clean up some inconsistent style in the hid matching arrays

ok millert, kettenis, jcs, phessler, deraadt, mpi


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.66 04-Sep-2017 jcs

Don't require exactly 20 elements in the _BIX package if at least 20
are returned since extras may be OEM-specific values we end up
ignoring anyway, such as on the Lenovo X1C 5th Gen which returns 21
elements.

ok mpi


# 1.65 25-Jul-2017 jcs

fallback on _BIF properly when _BIX exists and returns a package
successfully but has an unexpected length, as on the X1C gen 5

tested by naddy


# 1.64 22-Jul-2017 jcs

acpibat: look for _BIX first before falling back on _BIF

ACPI 4.0 deprecated _BIF for battery status so some newer machines
are exporting _BIX which extends _BIF's package with a few extra
fields. When using _BIX, export the new discharge cycle count as a
sensor.

feedback from kettenis and anton
ok deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.63 12-Mar-2017 jcs

try to attach acpisbs first and if successful, don't attach acpibat


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.62 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.61 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.60 23-May-2014 landry

Expose bif_capacity as the 'design capacity' through an acpibat sensor,
giving you the original capacity of the battery:

hw.sensors.acpibat0.watthour0=64.07 Wh (last full capacity)
hw.sensors.acpibat0.watthour4=84.24 Wh (design capacity)

hw.sensors.acpibat0.amphour0=2.03 Ah (last full capacity)
hw.sensors.acpibat0.amphour4=4.40 Ah (design capacity)

Diff from Fabian Raetz on tech@, thanks!

ok mlarkin@ zhuk@ armani@ kettenis@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.59 16-Oct-2011 kettenis

Provide battery charge/discharge rate in proper units.

Based on a diff from Vladimir Kirrillov.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.58 10-Nov-2010 kettenis

The acpibat(4) notify function should not unconditionally call both _BIF
and _BST. Some machines (like the Toshiba Satellite Pro U550 18F mentioned
in PR 6508) have AML that does a Notify(0x81) from the _BST method, which leads
to infinite recursion. Instead call _BIF when the argument is 0x81 and call
_BST when the argument is 0x80 or 0x00 (the latter indicates we're polling).
Simplify the battery detection logic while there.

ok mikeb@, marco@


Revision tags: OPENBSD_4_8_BASE
# 1.57 07-Aug-2010 canacar

Generate power change events for APM. Makes powerup and powerdown scripts
work with ACPI.
ok deraadt@, phessler@, feedback kettenis@


# 1.56 21-Jul-2010 deraadt

spacing and indents that are driving me crazy


Revision tags: OPENBSD_4_7_BASE
# 1.55 24-Nov-2009 deraadt

Reporting battery insert/removal was debug code. dmesg is not
a place to spam informational messages about unimportant events.
That is what the sensor framework is for (and that is already
done)
ok kettenis


Revision tags: OPENBSD_4_6_BASE
# 1.54 11-Mar-2009 jordan

More aml_evalinteger fixup
ok marco@


Revision tags: OPENBSD_4_5_BASE
# 1.53 06-Nov-2008 marco

Collapse all sanity checks of hids into one function.

Originaly from jordan


# 1.52 14-Aug-2008 robert

add missing semicolon; ok mbalmer@, marco@


Revision tags: OPENBSD_4_4_BASE
# 1.51 05-Aug-2008 marco

Fix spurious 0 values on batteries seen on laptopts that have an embedded
controller.

Found, diagnosed and patch from Stefan Sperling <stsp@stsp.name>
Minor KNF changes while here.

Tested by many on a variaty of IBM laptops and others with and without
acpiec.

ok deraadt


# 1.50 13-Jun-2008 jordan

Properly handle battery insertion/removal
ok @marco


# 1.49 01-Jun-2008 marco

Re-enable new parser. Lots of testing by various folks. Fits all media
now too.

ok kettenis deraadt


# 1.48 16-May-2008 dlg

back out jordans new parser.

it didnt have enough oks from the right people, it did break machines
that were previously working, and it bloated the RAMDISKS and install
media beyond the constraints of the media.

requested by deraadt@


# 1.47 14-May-2008 jordan

Adding new ACPI Parser code
Old guts of code still exists, needs to be torn out next
ok marco@
ok brad@


Revision tags: OPENBSD_4_3_BASE
# 1.46 16-Nov-2007 deraadt

quotes around model name too


# 1.45 12-Nov-2007 deraadt

spacing


# 1.44 12-Nov-2007 deraadt

spacing


# 1.43 12-Nov-2007 deraadt

only print bif info that is complete


# 1.42 08-Nov-2007 canacar

convert the value to a string instead of using aml_val2str()
which returns invalid pointers if the value is not a string, causing
acpibat to panic, as reported by mbalmer@ and Alexey Suslikov.
tested by Alexey Suslikov, ok marco@


# 1.41 03-Nov-2007 deraadt

repair attach messages; ok gwk canacar


Revision tags: OPENBSD_4_2_BASE
# 1.40 20-Mar-2007 mk

Use aml_val2int() instead of accessing v_integer directly.

`sort of ok' marco (before lock)


Revision tags: OPENBSD_4_1_BASE
# 1.39 17-Feb-2007 deanna

Since a full battery can still have state BST_CHARGE ("charging"),
fullness needs to be checked first. Otherwise, full batteries are
always described as "charging."

ok marco


# 1.38 25-Jan-2007 marco

Do the sensor magic correctly. Found by Constantine Murenin.
help from mickey


# 1.37 26-Dec-2006 marco

Add polling to devices that require it such as acpibat and acpitz.
Use the same tsleep/wakeup mechanism as the interrupt code to keep it non-
concurrent.


# 1.36 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.35 21-Dec-2006 deraadt

even more knf love


# 1.34 21-Dec-2006 marco

Tweak to report full battery.


# 1.33 21-Dec-2006 deraadt

more minor knf


# 1.32 21-Dec-2006 marco

Fix silly logic errors.


# 1.31 21-Dec-2006 marco

Silence acpibat significantly and shave off about 1k. Also add some smarts
for battery removal and insertion.


# 1.30 29-Nov-2006 marco

After a long debate at the hackathon it was decided that the acpi implementation
is not concurrent if the sensors thread goes away. This makes acpi completly
lockless.

help and ok dlg


# 1.29 19-Oct-2006 marco

Reduce the scope of the locks.


# 1.28 19-Oct-2006 marco

KNF and some cleanup


# 1.27 19-Oct-2006 marco

Replace ACPI ioctls with APM ioctls. This makes ACPI talk the same protocol
as APM therefore userspace can now retrieve power information in the same
fashion as all other apm arches (zaurus, macppc, i386 etc).

To use force the use of acpi device like so: apmd -f /dev/acpi

ok jordan@


# 1.26 19-Oct-2006 marco

Fix capacity calculations. Tested on Dell C610, D810, Lenovo X60s.

ok jordan


# 1.25 12-Oct-2006 jordan

Massive ACPI changes
Fixed ACPI leaks
new ACPI API
ok marco@


# 1.24 19-Sep-2006 mk

Typo fixes.

ok marco


Revision tags: OPENBSD_4_0_BASE
# 1.23 06-Jun-2006 jolan

fix a bad strlcpy, from ben lovett


# 1.22 19-May-2006 canacar

Use rwlock instead of lockmgr locks.
ok marco@


# 1.21 30-Apr-2006 marco

rv not set. Sloppy but didn't matter.
pointed out by joris@


# 1.20 05-Mar-2006 marco

KNF nit.


Revision tags: OPENBSD_3_9_BASE
# 1.19 22-Feb-2006 marco

Rework notify handler.
Use jordan's new notify register function.
ok jordan@


# 1.18 22-Feb-2006 marco

Add insertion and removal events for batteries.
Some cleanup & KNF.


# 1.17 21-Feb-2006 marco

KNF


# 1.16 21-Feb-2006 marco

Adjust debugging levels to something more reasonable.


# 1.15 17-Feb-2006 marco

Better comments.


# 1.14 17-Feb-2006 marco

Propogate some values through the sysctl hw.sesnsors interface for debug
purposes. This will be removed later and replaced with something better.


# 1.13 17-Feb-2006 marco

Detect if battery slot is available but without a battery in it.

ok jordan


# 1.12 16-Feb-2006 marco

Print useful information during boot about the battery and power supply.

ok jordan.


# 1.11 16-Feb-2006 marco

Adjust debug levels to something sane.


# 1.10 03-Feb-2006 jordan

Rewrote aml parser yet again...
Fixed bus_space_map for i386/amd64
Added _BST and _BIF to acpibat to get status/info
ok marco@


# 1.9 17-Jan-2006 jordan

Major overhaul of the aml parser. Evaluater temporarily disabled.

ok marco@


# 1.8 06-Jan-2006 grange

Sudden newline


# 1.7 30-Dec-2005 tedu

make ACPI_DEBUG compile


# 1.6 28-Dec-2005 marco

oops enabled a method that doesnt work yet so disabled getbif for now.
ok jordan@


# 1.5 28-Dec-2005 marco

Add some return values to getbst and getbif.
ok jordan@


# 1.4 28-Dec-2005 marco

Add 2 methods (Battery Info and Battery Status)
ok jordan@


# 1.3 16-Dec-2005 marco

Use new unified header.


# 1.2 13-Dec-2005 marco

Use shiny new acpibat.h


# 1.1 13-Dec-2005 marco

Add battery device.


# 1.69 09-Feb-2022 dv

add Surface Go 3 hid to acpibat(4)

Microsoft decided to break with basic ACPI standards with the Go 3.
In this case, they don't expose the battery in a standard way, so
acpibat(4) needs to look for the special Microsoft hid.

From mlarkin@, ok kettenis@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.68 10-Jun-2020 jca

Give userland a consistent battery and A/C state after resume

Previously we refreshed the state of acpiac(4) and acpibat(4)/acpisbs(4)
by queueing fake ACPI events to be processed by the acpi thread.
acpibat(4) using ACPIDEV_POLL meant that its status could be refreshed
first, resulting in an APM_POWER_CHANGE event sent to userland before
the state of acpiac(4) was up to date. Because of this, apmd(8) could
see A/C unplugged when it was in fact plugged, possibly leading to
a wrong decision.

Instead of using fake ACPI events, refresh the status of acpiac(4) and
acpibat(4)/acpisbs(4) right away at DVACT_WAKEUP time. To reuse the
existing refresh code of those drivers, make their ACPI *_notify()
handlers responsible for sending APM_POWER_CHANGE events instead. Also
queue an APM_POWER_CHANGE event right after resume to retain existing
behavior.

This fixes the consistency of data shown to userland, and makes those
drivers less special.

Initially discussed last year (!) with mpi@ at Miod's place.
Feedback and ok jcs@, deraadt@ agrees with the use of DVACT_WAKEUP here.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.67 01-Jul-2018 mlarkin

acpi: clean up some inconsistent style in the hid matching arrays

ok millert, kettenis, jcs, phessler, deraadt, mpi


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.66 04-Sep-2017 jcs

Don't require exactly 20 elements in the _BIX package if at least 20
are returned since extras may be OEM-specific values we end up
ignoring anyway, such as on the Lenovo X1C 5th Gen which returns 21
elements.

ok mpi


# 1.65 25-Jul-2017 jcs

fallback on _BIF properly when _BIX exists and returns a package
successfully but has an unexpected length, as on the X1C gen 5

tested by naddy


# 1.64 22-Jul-2017 jcs

acpibat: look for _BIX first before falling back on _BIF

ACPI 4.0 deprecated _BIF for battery status so some newer machines
are exporting _BIX which extends _BIF's package with a few extra
fields. When using _BIX, export the new discharge cycle count as a
sensor.

feedback from kettenis and anton
ok deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.63 12-Mar-2017 jcs

try to attach acpisbs first and if successful, don't attach acpibat


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.62 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.61 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.60 23-May-2014 landry

Expose bif_capacity as the 'design capacity' through an acpibat sensor,
giving you the original capacity of the battery:

hw.sensors.acpibat0.watthour0=64.07 Wh (last full capacity)
hw.sensors.acpibat0.watthour4=84.24 Wh (design capacity)

hw.sensors.acpibat0.amphour0=2.03 Ah (last full capacity)
hw.sensors.acpibat0.amphour4=4.40 Ah (design capacity)

Diff from Fabian Raetz on tech@, thanks!

ok mlarkin@ zhuk@ armani@ kettenis@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.59 16-Oct-2011 kettenis

Provide battery charge/discharge rate in proper units.

Based on a diff from Vladimir Kirrillov.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.58 10-Nov-2010 kettenis

The acpibat(4) notify function should not unconditionally call both _BIF
and _BST. Some machines (like the Toshiba Satellite Pro U550 18F mentioned
in PR 6508) have AML that does a Notify(0x81) from the _BST method, which leads
to infinite recursion. Instead call _BIF when the argument is 0x81 and call
_BST when the argument is 0x80 or 0x00 (the latter indicates we're polling).
Simplify the battery detection logic while there.

ok mikeb@, marco@


Revision tags: OPENBSD_4_8_BASE
# 1.57 07-Aug-2010 canacar

Generate power change events for APM. Makes powerup and powerdown scripts
work with ACPI.
ok deraadt@, phessler@, feedback kettenis@


# 1.56 21-Jul-2010 deraadt

spacing and indents that are driving me crazy


Revision tags: OPENBSD_4_7_BASE
# 1.55 24-Nov-2009 deraadt

Reporting battery insert/removal was debug code. dmesg is not
a place to spam informational messages about unimportant events.
That is what the sensor framework is for (and that is already
done)
ok kettenis


Revision tags: OPENBSD_4_6_BASE
# 1.54 11-Mar-2009 jordan

More aml_evalinteger fixup
ok marco@


Revision tags: OPENBSD_4_5_BASE
# 1.53 06-Nov-2008 marco

Collapse all sanity checks of hids into one function.

Originaly from jordan


# 1.52 14-Aug-2008 robert

add missing semicolon; ok mbalmer@, marco@


Revision tags: OPENBSD_4_4_BASE
# 1.51 05-Aug-2008 marco

Fix spurious 0 values on batteries seen on laptopts that have an embedded
controller.

Found, diagnosed and patch from Stefan Sperling <stsp@stsp.name>
Minor KNF changes while here.

Tested by many on a variaty of IBM laptops and others with and without
acpiec.

ok deraadt


# 1.50 13-Jun-2008 jordan

Properly handle battery insertion/removal
ok @marco


# 1.49 01-Jun-2008 marco

Re-enable new parser. Lots of testing by various folks. Fits all media
now too.

ok kettenis deraadt


# 1.48 16-May-2008 dlg

back out jordans new parser.

it didnt have enough oks from the right people, it did break machines
that were previously working, and it bloated the RAMDISKS and install
media beyond the constraints of the media.

requested by deraadt@


# 1.47 14-May-2008 jordan

Adding new ACPI Parser code
Old guts of code still exists, needs to be torn out next
ok marco@
ok brad@


Revision tags: OPENBSD_4_3_BASE
# 1.46 16-Nov-2007 deraadt

quotes around model name too


# 1.45 12-Nov-2007 deraadt

spacing


# 1.44 12-Nov-2007 deraadt

spacing


# 1.43 12-Nov-2007 deraadt

only print bif info that is complete


# 1.42 08-Nov-2007 canacar

convert the value to a string instead of using aml_val2str()
which returns invalid pointers if the value is not a string, causing
acpibat to panic, as reported by mbalmer@ and Alexey Suslikov.
tested by Alexey Suslikov, ok marco@


# 1.41 03-Nov-2007 deraadt

repair attach messages; ok gwk canacar


Revision tags: OPENBSD_4_2_BASE
# 1.40 20-Mar-2007 mk

Use aml_val2int() instead of accessing v_integer directly.

`sort of ok' marco (before lock)


Revision tags: OPENBSD_4_1_BASE
# 1.39 17-Feb-2007 deanna

Since a full battery can still have state BST_CHARGE ("charging"),
fullness needs to be checked first. Otherwise, full batteries are
always described as "charging."

ok marco


# 1.38 25-Jan-2007 marco

Do the sensor magic correctly. Found by Constantine Murenin.
help from mickey


# 1.37 26-Dec-2006 marco

Add polling to devices that require it such as acpibat and acpitz.
Use the same tsleep/wakeup mechanism as the interrupt code to keep it non-
concurrent.


# 1.36 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.35 21-Dec-2006 deraadt

even more knf love


# 1.34 21-Dec-2006 marco

Tweak to report full battery.


# 1.33 21-Dec-2006 deraadt

more minor knf


# 1.32 21-Dec-2006 marco

Fix silly logic errors.


# 1.31 21-Dec-2006 marco

Silence acpibat significantly and shave off about 1k. Also add some smarts
for battery removal and insertion.


# 1.30 29-Nov-2006 marco

After a long debate at the hackathon it was decided that the acpi implementation
is not concurrent if the sensors thread goes away. This makes acpi completly
lockless.

help and ok dlg


# 1.29 19-Oct-2006 marco

Reduce the scope of the locks.


# 1.28 19-Oct-2006 marco

KNF and some cleanup


# 1.27 19-Oct-2006 marco

Replace ACPI ioctls with APM ioctls. This makes ACPI talk the same protocol
as APM therefore userspace can now retrieve power information in the same
fashion as all other apm arches (zaurus, macppc, i386 etc).

To use force the use of acpi device like so: apmd -f /dev/acpi

ok jordan@


# 1.26 19-Oct-2006 marco

Fix capacity calculations. Tested on Dell C610, D810, Lenovo X60s.

ok jordan


# 1.25 12-Oct-2006 jordan

Massive ACPI changes
Fixed ACPI leaks
new ACPI API
ok marco@


# 1.24 19-Sep-2006 mk

Typo fixes.

ok marco


Revision tags: OPENBSD_4_0_BASE
# 1.23 06-Jun-2006 jolan

fix a bad strlcpy, from ben lovett


# 1.22 19-May-2006 canacar

Use rwlock instead of lockmgr locks.
ok marco@


# 1.21 30-Apr-2006 marco

rv not set. Sloppy but didn't matter.
pointed out by joris@


# 1.20 05-Mar-2006 marco

KNF nit.


Revision tags: OPENBSD_3_9_BASE
# 1.19 22-Feb-2006 marco

Rework notify handler.
Use jordan's new notify register function.
ok jordan@


# 1.18 22-Feb-2006 marco

Add insertion and removal events for batteries.
Some cleanup & KNF.


# 1.17 21-Feb-2006 marco

KNF


# 1.16 21-Feb-2006 marco

Adjust debugging levels to something more reasonable.


# 1.15 17-Feb-2006 marco

Better comments.


# 1.14 17-Feb-2006 marco

Propogate some values through the sysctl hw.sesnsors interface for debug
purposes. This will be removed later and replaced with something better.


# 1.13 17-Feb-2006 marco

Detect if battery slot is available but without a battery in it.

ok jordan


# 1.12 16-Feb-2006 marco

Print useful information during boot about the battery and power supply.

ok jordan.


# 1.11 16-Feb-2006 marco

Adjust debug levels to something sane.


# 1.10 03-Feb-2006 jordan

Rewrote aml parser yet again...
Fixed bus_space_map for i386/amd64
Added _BST and _BIF to acpibat to get status/info
ok marco@


# 1.9 17-Jan-2006 jordan

Major overhaul of the aml parser. Evaluater temporarily disabled.

ok marco@


# 1.8 06-Jan-2006 grange

Sudden newline


# 1.7 30-Dec-2005 tedu

make ACPI_DEBUG compile


# 1.6 28-Dec-2005 marco

oops enabled a method that doesnt work yet so disabled getbif for now.
ok jordan@


# 1.5 28-Dec-2005 marco

Add some return values to getbst and getbif.
ok jordan@


# 1.4 28-Dec-2005 marco

Add 2 methods (Battery Info and Battery Status)
ok jordan@


# 1.3 16-Dec-2005 marco

Use new unified header.


# 1.2 13-Dec-2005 marco

Use shiny new acpibat.h


# 1.1 13-Dec-2005 marco

Add battery device.


# 1.68 10-Jun-2020 jca

Give userland a consistent battery and A/C state after resume

Previously we refreshed the state of acpiac(4) and acpibat(4)/acpisbs(4)
by queueing fake ACPI events to be processed by the acpi thread.
acpibat(4) using ACPIDEV_POLL meant that its status could be refreshed
first, resulting in an APM_POWER_CHANGE event sent to userland before
the state of acpiac(4) was up to date. Because of this, apmd(8) could
see A/C unplugged when it was in fact plugged, possibly leading to
a wrong decision.

Instead of using fake ACPI events, refresh the status of acpiac(4) and
acpibat(4)/acpisbs(4) right away at DVACT_WAKEUP time. To reuse the
existing refresh code of those drivers, make their ACPI *_notify()
handlers responsible for sending APM_POWER_CHANGE events instead. Also
queue an APM_POWER_CHANGE event right after resume to retain existing
behavior.

This fixes the consistency of data shown to userland, and makes those
drivers less special.

Initially discussed last year (!) with mpi@ at Miod's place.
Feedback and ok jcs@, deraadt@ agrees with the use of DVACT_WAKEUP here.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.67 01-Jul-2018 mlarkin

acpi: clean up some inconsistent style in the hid matching arrays

ok millert, kettenis, jcs, phessler, deraadt, mpi


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.66 04-Sep-2017 jcs

Don't require exactly 20 elements in the _BIX package if at least 20
are returned since extras may be OEM-specific values we end up
ignoring anyway, such as on the Lenovo X1C 5th Gen which returns 21
elements.

ok mpi


# 1.65 25-Jul-2017 jcs

fallback on _BIF properly when _BIX exists and returns a package
successfully but has an unexpected length, as on the X1C gen 5

tested by naddy


# 1.64 22-Jul-2017 jcs

acpibat: look for _BIX first before falling back on _BIF

ACPI 4.0 deprecated _BIF for battery status so some newer machines
are exporting _BIX which extends _BIF's package with a few extra
fields. When using _BIX, export the new discharge cycle count as a
sensor.

feedback from kettenis and anton
ok deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.63 12-Mar-2017 jcs

try to attach acpisbs first and if successful, don't attach acpibat


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.62 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.61 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.60 23-May-2014 landry

Expose bif_capacity as the 'design capacity' through an acpibat sensor,
giving you the original capacity of the battery:

hw.sensors.acpibat0.watthour0=64.07 Wh (last full capacity)
hw.sensors.acpibat0.watthour4=84.24 Wh (design capacity)

hw.sensors.acpibat0.amphour0=2.03 Ah (last full capacity)
hw.sensors.acpibat0.amphour4=4.40 Ah (design capacity)

Diff from Fabian Raetz on tech@, thanks!

ok mlarkin@ zhuk@ armani@ kettenis@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.59 16-Oct-2011 kettenis

Provide battery charge/discharge rate in proper units.

Based on a diff from Vladimir Kirrillov.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.58 10-Nov-2010 kettenis

The acpibat(4) notify function should not unconditionally call both _BIF
and _BST. Some machines (like the Toshiba Satellite Pro U550 18F mentioned
in PR 6508) have AML that does a Notify(0x81) from the _BST method, which leads
to infinite recursion. Instead call _BIF when the argument is 0x81 and call
_BST when the argument is 0x80 or 0x00 (the latter indicates we're polling).
Simplify the battery detection logic while there.

ok mikeb@, marco@


Revision tags: OPENBSD_4_8_BASE
# 1.57 07-Aug-2010 canacar

Generate power change events for APM. Makes powerup and powerdown scripts
work with ACPI.
ok deraadt@, phessler@, feedback kettenis@


# 1.56 21-Jul-2010 deraadt

spacing and indents that are driving me crazy


Revision tags: OPENBSD_4_7_BASE
# 1.55 24-Nov-2009 deraadt

Reporting battery insert/removal was debug code. dmesg is not
a place to spam informational messages about unimportant events.
That is what the sensor framework is for (and that is already
done)
ok kettenis


Revision tags: OPENBSD_4_6_BASE
# 1.54 11-Mar-2009 jordan

More aml_evalinteger fixup
ok marco@


Revision tags: OPENBSD_4_5_BASE
# 1.53 06-Nov-2008 marco

Collapse all sanity checks of hids into one function.

Originaly from jordan


# 1.52 14-Aug-2008 robert

add missing semicolon; ok mbalmer@, marco@


Revision tags: OPENBSD_4_4_BASE
# 1.51 05-Aug-2008 marco

Fix spurious 0 values on batteries seen on laptopts that have an embedded
controller.

Found, diagnosed and patch from Stefan Sperling <stsp@stsp.name>
Minor KNF changes while here.

Tested by many on a variaty of IBM laptops and others with and without
acpiec.

ok deraadt


# 1.50 13-Jun-2008 jordan

Properly handle battery insertion/removal
ok @marco


# 1.49 01-Jun-2008 marco

Re-enable new parser. Lots of testing by various folks. Fits all media
now too.

ok kettenis deraadt


# 1.48 16-May-2008 dlg

back out jordans new parser.

it didnt have enough oks from the right people, it did break machines
that were previously working, and it bloated the RAMDISKS and install
media beyond the constraints of the media.

requested by deraadt@


# 1.47 14-May-2008 jordan

Adding new ACPI Parser code
Old guts of code still exists, needs to be torn out next
ok marco@
ok brad@


Revision tags: OPENBSD_4_3_BASE
# 1.46 16-Nov-2007 deraadt

quotes around model name too


# 1.45 12-Nov-2007 deraadt

spacing


# 1.44 12-Nov-2007 deraadt

spacing


# 1.43 12-Nov-2007 deraadt

only print bif info that is complete


# 1.42 08-Nov-2007 canacar

convert the value to a string instead of using aml_val2str()
which returns invalid pointers if the value is not a string, causing
acpibat to panic, as reported by mbalmer@ and Alexey Suslikov.
tested by Alexey Suslikov, ok marco@


# 1.41 03-Nov-2007 deraadt

repair attach messages; ok gwk canacar


Revision tags: OPENBSD_4_2_BASE
# 1.40 20-Mar-2007 mk

Use aml_val2int() instead of accessing v_integer directly.

`sort of ok' marco (before lock)


Revision tags: OPENBSD_4_1_BASE
# 1.39 17-Feb-2007 deanna

Since a full battery can still have state BST_CHARGE ("charging"),
fullness needs to be checked first. Otherwise, full batteries are
always described as "charging."

ok marco


# 1.38 25-Jan-2007 marco

Do the sensor magic correctly. Found by Constantine Murenin.
help from mickey


# 1.37 26-Dec-2006 marco

Add polling to devices that require it such as acpibat and acpitz.
Use the same tsleep/wakeup mechanism as the interrupt code to keep it non-
concurrent.


# 1.36 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.35 21-Dec-2006 deraadt

even more knf love


# 1.34 21-Dec-2006 marco

Tweak to report full battery.


# 1.33 21-Dec-2006 deraadt

more minor knf


# 1.32 21-Dec-2006 marco

Fix silly logic errors.


# 1.31 21-Dec-2006 marco

Silence acpibat significantly and shave off about 1k. Also add some smarts
for battery removal and insertion.


# 1.30 29-Nov-2006 marco

After a long debate at the hackathon it was decided that the acpi implementation
is not concurrent if the sensors thread goes away. This makes acpi completly
lockless.

help and ok dlg


# 1.29 19-Oct-2006 marco

Reduce the scope of the locks.


# 1.28 19-Oct-2006 marco

KNF and some cleanup


# 1.27 19-Oct-2006 marco

Replace ACPI ioctls with APM ioctls. This makes ACPI talk the same protocol
as APM therefore userspace can now retrieve power information in the same
fashion as all other apm arches (zaurus, macppc, i386 etc).

To use force the use of acpi device like so: apmd -f /dev/acpi

ok jordan@


# 1.26 19-Oct-2006 marco

Fix capacity calculations. Tested on Dell C610, D810, Lenovo X60s.

ok jordan


# 1.25 12-Oct-2006 jordan

Massive ACPI changes
Fixed ACPI leaks
new ACPI API
ok marco@


# 1.24 19-Sep-2006 mk

Typo fixes.

ok marco


Revision tags: OPENBSD_4_0_BASE
# 1.23 06-Jun-2006 jolan

fix a bad strlcpy, from ben lovett


# 1.22 19-May-2006 canacar

Use rwlock instead of lockmgr locks.
ok marco@


# 1.21 30-Apr-2006 marco

rv not set. Sloppy but didn't matter.
pointed out by joris@


# 1.20 05-Mar-2006 marco

KNF nit.


Revision tags: OPENBSD_3_9_BASE
# 1.19 22-Feb-2006 marco

Rework notify handler.
Use jordan's new notify register function.
ok jordan@


# 1.18 22-Feb-2006 marco

Add insertion and removal events for batteries.
Some cleanup & KNF.


# 1.17 21-Feb-2006 marco

KNF


# 1.16 21-Feb-2006 marco

Adjust debugging levels to something more reasonable.


# 1.15 17-Feb-2006 marco

Better comments.


# 1.14 17-Feb-2006 marco

Propogate some values through the sysctl hw.sesnsors interface for debug
purposes. This will be removed later and replaced with something better.


# 1.13 17-Feb-2006 marco

Detect if battery slot is available but without a battery in it.

ok jordan


# 1.12 16-Feb-2006 marco

Print useful information during boot about the battery and power supply.

ok jordan.


# 1.11 16-Feb-2006 marco

Adjust debug levels to something sane.


# 1.10 03-Feb-2006 jordan

Rewrote aml parser yet again...
Fixed bus_space_map for i386/amd64
Added _BST and _BIF to acpibat to get status/info
ok marco@


# 1.9 17-Jan-2006 jordan

Major overhaul of the aml parser. Evaluater temporarily disabled.

ok marco@


# 1.8 06-Jan-2006 grange

Sudden newline


# 1.7 30-Dec-2005 tedu

make ACPI_DEBUG compile


# 1.6 28-Dec-2005 marco

oops enabled a method that doesnt work yet so disabled getbif for now.
ok jordan@


# 1.5 28-Dec-2005 marco

Add some return values to getbst and getbif.
ok jordan@


# 1.4 28-Dec-2005 marco

Add 2 methods (Battery Info and Battery Status)
ok jordan@


# 1.3 16-Dec-2005 marco

Use new unified header.


# 1.2 13-Dec-2005 marco

Use shiny new acpibat.h


# 1.1 13-Dec-2005 marco

Add battery device.


# 1.67 01-Jul-2018 mlarkin

acpi: clean up some inconsistent style in the hid matching arrays

ok millert, kettenis, jcs, phessler, deraadt, mpi


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.66 04-Sep-2017 jcs

Don't require exactly 20 elements in the _BIX package if at least 20
are returned since extras may be OEM-specific values we end up
ignoring anyway, such as on the Lenovo X1C 5th Gen which returns 21
elements.

ok mpi


# 1.65 25-Jul-2017 jcs

fallback on _BIF properly when _BIX exists and returns a package
successfully but has an unexpected length, as on the X1C gen 5

tested by naddy


# 1.64 22-Jul-2017 jcs

acpibat: look for _BIX first before falling back on _BIF

ACPI 4.0 deprecated _BIF for battery status so some newer machines
are exporting _BIX which extends _BIF's package with a few extra
fields. When using _BIX, export the new discharge cycle count as a
sensor.

feedback from kettenis and anton
ok deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.63 12-Mar-2017 jcs

try to attach acpisbs first and if successful, don't attach acpibat


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.62 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.61 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.60 23-May-2014 landry

Expose bif_capacity as the 'design capacity' through an acpibat sensor,
giving you the original capacity of the battery:

hw.sensors.acpibat0.watthour0=64.07 Wh (last full capacity)
hw.sensors.acpibat0.watthour4=84.24 Wh (design capacity)

hw.sensors.acpibat0.amphour0=2.03 Ah (last full capacity)
hw.sensors.acpibat0.amphour4=4.40 Ah (design capacity)

Diff from Fabian Raetz on tech@, thanks!

ok mlarkin@ zhuk@ armani@ kettenis@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.59 16-Oct-2011 kettenis

Provide battery charge/discharge rate in proper units.

Based on a diff from Vladimir Kirrillov.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.58 10-Nov-2010 kettenis

The acpibat(4) notify function should not unconditionally call both _BIF
and _BST. Some machines (like the Toshiba Satellite Pro U550 18F mentioned
in PR 6508) have AML that does a Notify(0x81) from the _BST method, which leads
to infinite recursion. Instead call _BIF when the argument is 0x81 and call
_BST when the argument is 0x80 or 0x00 (the latter indicates we're polling).
Simplify the battery detection logic while there.

ok mikeb@, marco@


Revision tags: OPENBSD_4_8_BASE
# 1.57 07-Aug-2010 canacar

Generate power change events for APM. Makes powerup and powerdown scripts
work with ACPI.
ok deraadt@, phessler@, feedback kettenis@


# 1.56 21-Jul-2010 deraadt

spacing and indents that are driving me crazy


Revision tags: OPENBSD_4_7_BASE
# 1.55 24-Nov-2009 deraadt

Reporting battery insert/removal was debug code. dmesg is not
a place to spam informational messages about unimportant events.
That is what the sensor framework is for (and that is already
done)
ok kettenis


Revision tags: OPENBSD_4_6_BASE
# 1.54 11-Mar-2009 jordan

More aml_evalinteger fixup
ok marco@


Revision tags: OPENBSD_4_5_BASE
# 1.53 06-Nov-2008 marco

Collapse all sanity checks of hids into one function.

Originaly from jordan


# 1.52 14-Aug-2008 robert

add missing semicolon; ok mbalmer@, marco@


Revision tags: OPENBSD_4_4_BASE
# 1.51 05-Aug-2008 marco

Fix spurious 0 values on batteries seen on laptopts that have an embedded
controller.

Found, diagnosed and patch from Stefan Sperling <stsp@stsp.name>
Minor KNF changes while here.

Tested by many on a variaty of IBM laptops and others with and without
acpiec.

ok deraadt


# 1.50 13-Jun-2008 jordan

Properly handle battery insertion/removal
ok @marco


# 1.49 01-Jun-2008 marco

Re-enable new parser. Lots of testing by various folks. Fits all media
now too.

ok kettenis deraadt


# 1.48 16-May-2008 dlg

back out jordans new parser.

it didnt have enough oks from the right people, it did break machines
that were previously working, and it bloated the RAMDISKS and install
media beyond the constraints of the media.

requested by deraadt@


# 1.47 14-May-2008 jordan

Adding new ACPI Parser code
Old guts of code still exists, needs to be torn out next
ok marco@
ok brad@


Revision tags: OPENBSD_4_3_BASE
# 1.46 16-Nov-2007 deraadt

quotes around model name too


# 1.45 12-Nov-2007 deraadt

spacing


# 1.44 12-Nov-2007 deraadt

spacing


# 1.43 12-Nov-2007 deraadt

only print bif info that is complete


# 1.42 08-Nov-2007 canacar

convert the value to a string instead of using aml_val2str()
which returns invalid pointers if the value is not a string, causing
acpibat to panic, as reported by mbalmer@ and Alexey Suslikov.
tested by Alexey Suslikov, ok marco@


# 1.41 03-Nov-2007 deraadt

repair attach messages; ok gwk canacar


Revision tags: OPENBSD_4_2_BASE
# 1.40 20-Mar-2007 mk

Use aml_val2int() instead of accessing v_integer directly.

`sort of ok' marco (before lock)


Revision tags: OPENBSD_4_1_BASE
# 1.39 17-Feb-2007 deanna

Since a full battery can still have state BST_CHARGE ("charging"),
fullness needs to be checked first. Otherwise, full batteries are
always described as "charging."

ok marco


# 1.38 25-Jan-2007 marco

Do the sensor magic correctly. Found by Constantine Murenin.
help from mickey


# 1.37 26-Dec-2006 marco

Add polling to devices that require it such as acpibat and acpitz.
Use the same tsleep/wakeup mechanism as the interrupt code to keep it non-
concurrent.


# 1.36 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.35 21-Dec-2006 deraadt

even more knf love


# 1.34 21-Dec-2006 marco

Tweak to report full battery.


# 1.33 21-Dec-2006 deraadt

more minor knf


# 1.32 21-Dec-2006 marco

Fix silly logic errors.


# 1.31 21-Dec-2006 marco

Silence acpibat significantly and shave off about 1k. Also add some smarts
for battery removal and insertion.


# 1.30 29-Nov-2006 marco

After a long debate at the hackathon it was decided that the acpi implementation
is not concurrent if the sensors thread goes away. This makes acpi completly
lockless.

help and ok dlg


# 1.29 19-Oct-2006 marco

Reduce the scope of the locks.


# 1.28 19-Oct-2006 marco

KNF and some cleanup


# 1.27 19-Oct-2006 marco

Replace ACPI ioctls with APM ioctls. This makes ACPI talk the same protocol
as APM therefore userspace can now retrieve power information in the same
fashion as all other apm arches (zaurus, macppc, i386 etc).

To use force the use of acpi device like so: apmd -f /dev/acpi

ok jordan@


# 1.26 19-Oct-2006 marco

Fix capacity calculations. Tested on Dell C610, D810, Lenovo X60s.

ok jordan


# 1.25 12-Oct-2006 jordan

Massive ACPI changes
Fixed ACPI leaks
new ACPI API
ok marco@


# 1.24 19-Sep-2006 mk

Typo fixes.

ok marco


Revision tags: OPENBSD_4_0_BASE
# 1.23 06-Jun-2006 jolan

fix a bad strlcpy, from ben lovett


# 1.22 19-May-2006 canacar

Use rwlock instead of lockmgr locks.
ok marco@


# 1.21 30-Apr-2006 marco

rv not set. Sloppy but didn't matter.
pointed out by joris@


# 1.20 05-Mar-2006 marco

KNF nit.


Revision tags: OPENBSD_3_9_BASE
# 1.19 22-Feb-2006 marco

Rework notify handler.
Use jordan's new notify register function.
ok jordan@


# 1.18 22-Feb-2006 marco

Add insertion and removal events for batteries.
Some cleanup & KNF.


# 1.17 21-Feb-2006 marco

KNF


# 1.16 21-Feb-2006 marco

Adjust debugging levels to something more reasonable.


# 1.15 17-Feb-2006 marco

Better comments.


# 1.14 17-Feb-2006 marco

Propogate some values through the sysctl hw.sesnsors interface for debug
purposes. This will be removed later and replaced with something better.


# 1.13 17-Feb-2006 marco

Detect if battery slot is available but without a battery in it.

ok jordan


# 1.12 16-Feb-2006 marco

Print useful information during boot about the battery and power supply.

ok jordan.


# 1.11 16-Feb-2006 marco

Adjust debug levels to something sane.


# 1.10 03-Feb-2006 jordan

Rewrote aml parser yet again...
Fixed bus_space_map for i386/amd64
Added _BST and _BIF to acpibat to get status/info
ok marco@


# 1.9 17-Jan-2006 jordan

Major overhaul of the aml parser. Evaluater temporarily disabled.

ok marco@


# 1.8 06-Jan-2006 grange

Sudden newline


# 1.7 30-Dec-2005 tedu

make ACPI_DEBUG compile


# 1.6 28-Dec-2005 marco

oops enabled a method that doesnt work yet so disabled getbif for now.
ok jordan@


# 1.5 28-Dec-2005 marco

Add some return values to getbst and getbif.
ok jordan@


# 1.4 28-Dec-2005 marco

Add 2 methods (Battery Info and Battery Status)
ok jordan@


# 1.3 16-Dec-2005 marco

Use new unified header.


# 1.2 13-Dec-2005 marco

Use shiny new acpibat.h


# 1.1 13-Dec-2005 marco

Add battery device.


Revision tags: OPENBSD_6_2_BASE
# 1.66 04-Sep-2017 jcs

Don't require exactly 20 elements in the _BIX package if at least 20
are returned since extras may be OEM-specific values we end up
ignoring anyway, such as on the Lenovo X1C 5th Gen which returns 21
elements.

ok mpi


# 1.65 25-Jul-2017 jcs

fallback on _BIF properly when _BIX exists and returns a package
successfully but has an unexpected length, as on the X1C gen 5

tested by naddy


# 1.64 22-Jul-2017 jcs

acpibat: look for _BIX first before falling back on _BIF

ACPI 4.0 deprecated _BIF for battery status so some newer machines
are exporting _BIX which extends _BIF's package with a few extra
fields. When using _BIX, export the new discharge cycle count as a
sensor.

feedback from kettenis and anton
ok deraadt


Revision tags: OPENBSD_6_1_BASE
# 1.63 12-Mar-2017 jcs

try to attach acpisbs first and if successful, don't attach acpibat


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.62 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.61 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.60 23-May-2014 landry

Expose bif_capacity as the 'design capacity' through an acpibat sensor,
giving you the original capacity of the battery:

hw.sensors.acpibat0.watthour0=64.07 Wh (last full capacity)
hw.sensors.acpibat0.watthour4=84.24 Wh (design capacity)

hw.sensors.acpibat0.amphour0=2.03 Ah (last full capacity)
hw.sensors.acpibat0.amphour4=4.40 Ah (design capacity)

Diff from Fabian Raetz on tech@, thanks!

ok mlarkin@ zhuk@ armani@ kettenis@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.59 16-Oct-2011 kettenis

Provide battery charge/discharge rate in proper units.

Based on a diff from Vladimir Kirrillov.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.58 10-Nov-2010 kettenis

The acpibat(4) notify function should not unconditionally call both _BIF
and _BST. Some machines (like the Toshiba Satellite Pro U550 18F mentioned
in PR 6508) have AML that does a Notify(0x81) from the _BST method, which leads
to infinite recursion. Instead call _BIF when the argument is 0x81 and call
_BST when the argument is 0x80 or 0x00 (the latter indicates we're polling).
Simplify the battery detection logic while there.

ok mikeb@, marco@


Revision tags: OPENBSD_4_8_BASE
# 1.57 07-Aug-2010 canacar

Generate power change events for APM. Makes powerup and powerdown scripts
work with ACPI.
ok deraadt@, phessler@, feedback kettenis@


# 1.56 21-Jul-2010 deraadt

spacing and indents that are driving me crazy


Revision tags: OPENBSD_4_7_BASE
# 1.55 24-Nov-2009 deraadt

Reporting battery insert/removal was debug code. dmesg is not
a place to spam informational messages about unimportant events.
That is what the sensor framework is for (and that is already
done)
ok kettenis


Revision tags: OPENBSD_4_6_BASE
# 1.54 11-Mar-2009 jordan

More aml_evalinteger fixup
ok marco@


Revision tags: OPENBSD_4_5_BASE
# 1.53 06-Nov-2008 marco

Collapse all sanity checks of hids into one function.

Originaly from jordan


# 1.52 14-Aug-2008 robert

add missing semicolon; ok mbalmer@, marco@


Revision tags: OPENBSD_4_4_BASE
# 1.51 05-Aug-2008 marco

Fix spurious 0 values on batteries seen on laptopts that have an embedded
controller.

Found, diagnosed and patch from Stefan Sperling <stsp@stsp.name>
Minor KNF changes while here.

Tested by many on a variaty of IBM laptops and others with and without
acpiec.

ok deraadt


# 1.50 13-Jun-2008 jordan

Properly handle battery insertion/removal
ok @marco


# 1.49 01-Jun-2008 marco

Re-enable new parser. Lots of testing by various folks. Fits all media
now too.

ok kettenis deraadt


# 1.48 16-May-2008 dlg

back out jordans new parser.

it didnt have enough oks from the right people, it did break machines
that were previously working, and it bloated the RAMDISKS and install
media beyond the constraints of the media.

requested by deraadt@


# 1.47 14-May-2008 jordan

Adding new ACPI Parser code
Old guts of code still exists, needs to be torn out next
ok marco@
ok brad@


Revision tags: OPENBSD_4_3_BASE
# 1.46 16-Nov-2007 deraadt

quotes around model name too


# 1.45 12-Nov-2007 deraadt

spacing


# 1.44 12-Nov-2007 deraadt

spacing


# 1.43 12-Nov-2007 deraadt

only print bif info that is complete


# 1.42 08-Nov-2007 canacar

convert the value to a string instead of using aml_val2str()
which returns invalid pointers if the value is not a string, causing
acpibat to panic, as reported by mbalmer@ and Alexey Suslikov.
tested by Alexey Suslikov, ok marco@


# 1.41 03-Nov-2007 deraadt

repair attach messages; ok gwk canacar


Revision tags: OPENBSD_4_2_BASE
# 1.40 20-Mar-2007 mk

Use aml_val2int() instead of accessing v_integer directly.

`sort of ok' marco (before lock)


Revision tags: OPENBSD_4_1_BASE
# 1.39 17-Feb-2007 deanna

Since a full battery can still have state BST_CHARGE ("charging"),
fullness needs to be checked first. Otherwise, full batteries are
always described as "charging."

ok marco


# 1.38 25-Jan-2007 marco

Do the sensor magic correctly. Found by Constantine Murenin.
help from mickey


# 1.37 26-Dec-2006 marco

Add polling to devices that require it such as acpibat and acpitz.
Use the same tsleep/wakeup mechanism as the interrupt code to keep it non-
concurrent.


# 1.36 23-Dec-2006 deraadt

adapt to new two-level sensor api; Constantine A. Murenin


# 1.35 21-Dec-2006 deraadt

even more knf love


# 1.34 21-Dec-2006 marco

Tweak to report full battery.


# 1.33 21-Dec-2006 deraadt

more minor knf


# 1.32 21-Dec-2006 marco

Fix silly logic errors.


# 1.31 21-Dec-2006 marco

Silence acpibat significantly and shave off about 1k. Also add some smarts
for battery removal and insertion.


# 1.30 29-Nov-2006 marco

After a long debate at the hackathon it was decided that the acpi implementation
is not concurrent if the sensors thread goes away. This makes acpi completly
lockless.

help and ok dlg


# 1.29 19-Oct-2006 marco

Reduce the scope of the locks.


# 1.28 19-Oct-2006 marco

KNF and some cleanup


# 1.27 19-Oct-2006 marco

Replace ACPI ioctls with APM ioctls. This makes ACPI talk the same protocol
as APM therefore userspace can now retrieve power information in the same
fashion as all other apm arches (zaurus, macppc, i386 etc).

To use force the use of acpi device like so: apmd -f /dev/acpi

ok jordan@


# 1.26 19-Oct-2006 marco

Fix capacity calculations. Tested on Dell C610, D810, Lenovo X60s.

ok jordan


# 1.25 12-Oct-2006 jordan

Massive ACPI changes
Fixed ACPI leaks
new ACPI API
ok marco@


# 1.24 19-Sep-2006 mk

Typo fixes.

ok marco


Revision tags: OPENBSD_4_0_BASE
# 1.23 06-Jun-2006 jolan

fix a bad strlcpy, from ben lovett


# 1.22 19-May-2006 canacar

Use rwlock instead of lockmgr locks.
ok marco@


# 1.21 30-Apr-2006 marco

rv not set. Sloppy but didn't matter.
pointed out by joris@


# 1.20 05-Mar-2006 marco

KNF nit.


Revision tags: OPENBSD_3_9_BASE
# 1.19 22-Feb-2006 marco

Rework notify handler.
Use jordan's new notify register function.
ok jordan@


# 1.18 22-Feb-2006 marco

Add insertion and removal events for batteries.
Some cleanup & KNF.


# 1.17 21-Feb-2006 marco

KNF


# 1.16 21-Feb-2006 marco

Adjust debugging levels to something more reasonable.


# 1.15 17-Feb-2006 marco

Better comments.


# 1.14 17-Feb-2006 marco

Propogate some values through the sysctl hw.sesnsors interface for debug
purposes. This will be removed later and replaced with something better.


# 1.13 17-Feb-2006 marco

Detect if battery slot is available but without a battery in it.

ok jordan


# 1.12 16-Feb-2006 marco

Print useful information during boot about the battery and power supply.

ok jordan.


# 1.11 16-Feb-2006 marco

Adjust debug levels to something sane.


# 1.10 03-Feb-2006 jordan

Rewrote aml parser yet again...
Fixed bus_space_map for i386/amd64
Added _BST and _BIF to acpibat to get status/info
ok marco@


# 1.9 17-Jan-2006 jordan

Major overhaul of the aml parser. Evaluater temporarily disabled.

ok marco@


# 1.8 06-Jan-2006 grange

Sudden newline


# 1.7 30-Dec-2005 tedu

make ACPI_DEBUG compile


# 1.6 28-Dec-2005 marco

oops enabled a method that doesnt work yet so disabled getbif for now.
ok jordan@


# 1.5 28-Dec-2005 marco

Add some return values to getbst and getbif.
ok jordan@


# 1.4 28-Dec-2005 marco

Add 2 methods (Battery Info and Battery Status)
ok jordan@


# 1.3 16-Dec-2005 marco

Use new unified header.


# 1.2 13-Dec-2005 marco

Use shiny new acpibat.h


# 1.1 13-Dec-2005 marco

Add battery device.