Commit Graph

94 Commits

Author SHA1 Message Date
jruoho dfc3a8d66a Fix the previous commit properly: we need to set all sensor-flags during the
initialization of sysmon_envsys(9), otherwise, if _STA does not return true
during the attachment of the driver, it is possible that a flag is never
set. This flaw has always been present, but it only got exposed after the
conversion to use the sysmon-limits.
2010-03-22 15:08:35 +00:00
jruoho 72763cb4e7 Set the capacity flags already in the acpibat_get_info(),
instead of acpibat_get_status().
2010-03-22 09:31:24 +00:00
pooka f3beefdb45 Convert acpibat to use ioconf instead of homerolled config glue.
Note, config whines about things like:
files.acpi:30: attaching undefined device `apm'

I intentionally was a lazy boy and didn't include a ton of dirt to
keep the hot napalm and riot blasts in the config thread rolling ;)

tested by jruoho (thanks!)
2010-03-21 07:09:56 +00:00
jruoho ef2b6dd20b Print also the so-called "granularity" values when the _BIF is evaluated.
These refer to the smallest increment in capacity that the battery is
capable of measuring.
2010-03-17 11:07:59 +00:00
jruoho dce0020d0c Remove the technology "sensor" (a fixed constant). Report this information
in an improved output when the battery information changes (i.e. device
attachment or battery removal/insertion).
2010-03-17 09:21:50 +00:00
jruoho febc76c6be Remove the timer-based check in the sensor refresh routine. We henceforth
trust that the sysmon_envsys(9)'s polling is functioning properly. Discussed
with drochner@, jmcneill@, and pgoyette@.
2010-03-17 08:07:27 +00:00
jruoho 88e4bfe590 Fix the testing of temporarily unknown values. 2010-03-17 07:48:18 +00:00
jruoho 73b3b3d393 Move the low and warning capacity sensors to the limits framework provided
by sysmon_envsys(9).
2010-03-17 07:40:34 +00:00
pgoyette 89bf6ebb9f Remove setting of edata->monitor since that member no longer exists. 2010-03-14 18:05:07 +00:00
jruoho aa4b9b510c Use the predefined ACPI_STA_BATTERY_PRESENT instead of defining a local one. 2010-03-08 11:45:45 +00:00
jruoho 5a425210a3 Remove <dev/acpi/acpica.h> from all files. It is included from
<dev/acpi/acpivar.h>. Ditto for <dev/sysmon/sysmonvar.h>, <sys/bus.h>,
<dev/pci/pcivar.h>, and <dev/isa/isavar.h>.

Also nuke a lot of unused and invalid headers. Some of these are audibly
provided by standard headers (namely <sys/param.h> and <sys/device.h>), some
have nothing to do with ACPI devices (e.g. <sys/syslog.h>), and some are
nonexistent local includes (e.g. "mpu_ym.h"). Moreoever, try to group the
includes into their respective blocks.

Tested with GENERIC and ALL (i386). No functional change.
2010-03-05 14:00:16 +00:00
jruoho 86c3014958 Introduce support for ACPI kernel modules.
Tested on couple of laptops.
2010-02-28 17:22:41 +00:00
dyoung c1b390d493 A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
2010-02-24 22:37:54 +00:00
jruoho baf97f9356 Allocate the sensor structures dynamically. 2010-01-31 06:45:09 +00:00
jruoho 1aca5372db Add detachment routines. 2010-01-31 06:10:53 +00:00
drochner 30d27f4f07 the "Battery Present Rate" is only required to be valid if the battery
is discharging; it might make sense when charging, but it doesn't
make sense if neither is the case -- remove a wrong assertion and
arrange the code to make this obvious
(actually, the ACPI spec says that the requirement is only for
rechargeable batteries)
2010-01-27 22:17:28 +00:00
jruoho e6056a8df3 * Reintroduce a state variable. From njoly@.
* Always mark the charge state sensor as valid.
2010-01-24 11:32:13 +00:00
jruoho 3f1f18b1bd Cleanup:
* Remove ACPI_BAT_DEBUG.
  * Reduce the amount of error reporting.
  * Remove the internal bookkeeping flags.
  * Remove the debugging functions used to print status and information
    changes. This information is fully conveyed in the output of envstat(8).
  * Always evaluate _STA. If it fails or the battery is not present, mark
    all remaining sensors as invalid. This will eliminate the convoluted
    update routine.
  * Semantics.

Over 200 LOC was eliminated, but functional change should again be minimal.

ok jmcneill@, pgoyette@
2010-01-23 15:06:47 +00:00
jruoho 791571cbd1 In preparation for upcoming changes:
* Provide proper definitions and use these.
  * Clarify the evaluation of _STA.
  * Mark the state of a sensor according to the return value from _STA.
  * Share the basic object evaluation in _BIF and _BST.
  * Verify the object types before using the objects.
  * Be aware of bogus values from _BIF and _BST, as noted in the
    specification.

Despite of the list, functional change should be minimal. Ok pgoyette@.
2010-01-21 08:57:17 +00:00
dyoung cd6e1fbf91 Expand PMF_FN_* macros. 2010-01-08 19:53:10 +00:00
jmcneill 5be9fd621d If the driver thinks a battery is not present, poll for present status.
Workaround for firmware that doesn't report battery present status
immediately at boot and doesn't issue a subsequent notify when the
information becomes available.
2009-09-29 21:41:38 +00:00
mlelstv 23ab96a36b Allow for 'options ACPI_DEBUG' by providing module declarations
and using memory allocation macros instead of calling AcpiOs* stubs
directly.
2009-09-16 10:47:54 +00:00
jmcneill 80adfeb08d PR# kern/41179: Incorrect return values from AcpiOsExecute()
ACPICA functions return ACPI_STATUS instead of int, so use it for
consistency.
2009-08-25 10:34:08 +00:00
cegger 93dfc06da9 struct device * -> device_t, no functional changes intended. 2009-05-12 09:50:28 +00:00
cegger e5339e11d4 struct cfdata * -> cfdata_t, no functional changes intended. 2009-05-12 09:29:46 +00:00
jmcneill fc993c6a36 Reintroduce acpibat_refresh, only have it refresh battery status (not info,
we will get notified for changes there). Use SME_POLL_ONLY so applications
that use GTREDATA don't cause trouble, and don't use SME_INIT_REFRESH as it
appears to be completely broken.
2008-06-03 15:02:31 +00:00
jmcneill edd4ea5b7d Refresh battery info/status on resume. 2008-06-03 12:16:34 +00:00
jmcneill daaa85a781 Simplify SME usage within acpibat:
* No need for sme_refresh callback; GPE handler will tell us when the
    device status changed (otherwise we can refresh data up to once a second,
    and that can take time!)
  * Since sme_refresh callback is gone, mutex is no longer required to
    synchronize GPE handlers and refresh thread, so nuke it.
  * Don't do any more work in GPE handler than required; use AcpiOsExecute
    to clear battery status/information in the sysmon_task_queue along with
    the refresh.

With these changes running GNOME's battstat-applet-2 no longer causes
my mouse to stutter once a second, and significantly reduces its CPU usage.
2008-06-03 01:11:18 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
xtraeme 6e9673dcb2 Use the SME_INIT_REFRESH flag to fetch sensor data once in the
autoconf(9) process.
2008-03-23 16:12:45 +00:00
jmcneill 4c1d81b2b5 Merge jmcneill-pm branch. 2007-12-09 20:27:42 +00:00
ad 598ab03ad0 Match the docs: MUTEX_DRIVER/SPIN are now only for porting code written
for Solaris.
2007-12-05 07:06:50 +00:00
xtraeme 31962fc6e5 Extend the envsys2 API (one more time, sorry) as defined in:
http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
2007-11-16 08:00:11 +00:00
xtraeme 4e10a84855 - Rename ENVSYS_BATTERY_STATE units to ENVSYS_BATTERY_CAPACITY and
introduce ENVSYS_BATTERY_CHARGE, which is the same than an Indicator and
  it's used to know if the battery is currently charging or discharging.

- Require two sensors at least for SME_CLASS_BATTERY to make the low-power
  condition work: a ENVSYS_BATTERY_CAPACITY plus ENVSYS_BATTERY_CHARGE.

- Simplify sme_event_check_lowpower() and make it check the required
  sensors in the SME_CLASS_ACADAPTER and SME_CLASS_BATTERY classes.
  If the acadapter is not ready, trust the state returned by the battery
  device.

Based on suggestion from joerg@.
2007-11-03 23:05:21 +00:00
plunky 812fa1c5a1 do not embed acpi device names in the sensor names
fake it in the compat code for the old envsys API
2007-11-02 19:21:29 +00:00
joerg 649a2156ea Convert to device_t/softc split. Use aprint API. 2007-10-18 23:54:54 +00:00
joerg 8302c6904b Separate softc and device_t. Convert to aprint API and make the driver
less verbose by default.
2007-10-17 23:30:58 +00:00
xtraeme 7ade6d03ad Fix the problems described in:
http://mail-index.netbsd.org/current-users/2007/07/16/0012.html

- Introduce sme_class into the sysmon_envsys struct to specify a
  class; currently there are two classes: SME_CLASS_ACADAPTER and
  SME_CLASS_BATTERY.

- Add a new envsys event: PENVSYS_EVENT_LOW_POWER that is reached when
  all SME_CLASS_BATTERY devices are in CRITICAL/LOW state and there's not
  any SME_CLASS_ACADAPTER connected.

- Add the 'low-power' event into the sensor_battery script that will
  shutdown the system gracefully via 'shutdown -p'. If powerd(8) is
  not running, cpu_reboot(9) with RB_POWERDOWN is used.

- Make acpiacad(4) a SME_CLASS_ACADAPTER device and acpibat(4) a
  SME_CLASS_BATTERY device.

Update the documentation accordingly to these changes.
2007-10-10 23:25:39 +00:00
xtraeme debeab5278 - Use a ENVSYS_BATTERY_STATE sensor rather than ENVSYS_GSTRING.
- Use ENVSYS_FMONSTCHANGED on the ENVSYS_BATTERY_STATE sensor to monitor
  state changes.
2007-09-04 16:56:30 +00:00
xtraeme cba98bab30 Add a new sensor of type ENVSYS_GSTRING. This is useful to print
the current battery charge state.

$ envstat -dacpibat0 -s"acpibat0 charge state"
  acpibat0 charge state:     NORMAL
$

It will show WARNING, CRITICAL, LOW or NORMAL depending on the
state it is.
2007-09-02 19:38:32 +00:00
xtraeme 9d55226ba9 Set ENVSYS_FMONNOTSUPP in the last two missing sensors, forgot in previous. 2007-08-26 20:52:15 +00:00
xtraeme a8995b3790 Only assing the monitoring flags once in acpibat_init_envsys() before
registering the driver.
2007-08-26 20:47:42 +00:00
cube 5f5f6cdbad Fix a few minor envsys2 bugs/oddities in acpi_bat(4).
- mark (DIS)CHARGERATE as invalid when (DIS)CHARGING so that envstat
   doesn't print some weird stats where the system appears to be doing
   both
 - handle the case when it's doing neither by marking *RATE as invalid
   and setting CHARGING to OFF (because we're not charging, even though
   we're not discharging)
 - fix print_stats to print correct values in those cases, and a real
   percentage (i.e., computed against LFCCAPACITY)
2007-08-08 08:36:41 +00:00
xtraeme 912541575c Disable monitoring in the ACPIBAT_TECHNOLOGY sensor, which is just
informative.
2007-07-16 17:54:46 +00:00
xtraeme 65811978f4 Final round, after more comments from yamt and cube:
For indicators, if sensor is valid but it should report that it is
in disabled state (OFF), just set value_cur to 0 without changing its
state.
2007-07-05 13:47:46 +00:00
xtraeme 615572e484 acpibat_print_stat(): in the 'charging' indicator sensor, check its state
to select the correct string rather than using value_cur.
2007-07-05 12:14:18 +00:00
xtraeme 194be74536 Use only one Indicator sensor when the battery is connected/disconnected
and another one only for charging/discharging.
2007-07-05 12:08:45 +00:00
xtraeme 937ef5eeb2 Rather than using two AcpiInstallNotifyHandler() with ACPI_DEVICE_NOTIFY
and ACPI_SYSTEM_NOTIFY, use ACPI_ALL_NOTIFY and remove a redundant
call.
2007-07-03 07:44:05 +00:00
xtraeme da3f163bd2 Imported envsys 2, a brief description of the new features:
(Part 2: drivers)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
  and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
  sysmon_power(9) and powerd(8), that means there is no 32 bytes event
  size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 07:37:12 +00:00
christos 168cd830d2 __unused removal on arguments; approved by core. 2006-11-16 01:32:37 +00:00