acpi/apm: Improve APM ioctl interface emulation
authorWarner Losh <imp@FreeBSD.org>
Wed, 3 Jan 2024 23:18:23 +0000 (16:18 -0700)
committerWarner Losh <imp@FreeBSD.org>
Thu, 11 Jan 2024 00:05:00 +0000 (17:05 -0700)
commit8a3fafc821149e800747cd92afee092fd131c402
tree99dd6ee81f832e0cc8d699e876ea863f17cebd8b
parenta61d2c7fbd3c87126db93dfe83b9f96fea3156f8
acpi/apm: Improve APM ioctl interface emulation

The apm(8) program documents certain states, but doesn't document the
'unknown' state. It reports things correctly for systems with a battery,
but incorrectly for systems without one. Emulate the old interface a
little better by saying ac power is online if we have no status (instead
of unknown), the battery has a high charge of 255% if there's no battery
(instead of -1). Programs, like emacs, expect to see only the documented
values and misbehave when they see something else.

This is closer to what would happen on old-school APM machines. Sadly
(or not) I have no access to old-school APM machines to 100% confirm
this, but reading the spec, old code and testing with emacs' mode line
with battery suggests these values are more correct. emacs has never
been converted to acpi_conf due to permissions issues with acpi devices.

Fixing the kernel is preferable to hacking apm(8) for these special
cases because other programs that use these interfaces will also be more
correct. The kernel also has more data with which to decide what to
return.

Sponsored by: Netflix
MFC After: 1 week
sys/x86/acpica/acpi_apm.c