From owner-freebsd-acpi@FreeBSD.ORG Sun Dec 7 07:55:44 2014 Return-Path: Delivered-To: freebsd-acpi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0E8C2FEE for ; Sun, 7 Dec 2014 07:55:44 +0000 (UTC) Received: from o1.l99.sendgrid.net (o1.l99.sendgrid.net [198.37.153.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C3200FBF for ; Sun, 7 Dec 2014 07:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.info; h=from:mime-version:to:subject:content-type; s=smtpapi; bh=5eqQXVj2mbFj+qX8rwQk19c25zk=; b=SHOb11i9RGe4Pw9Oa+M4Gtow3Ui7v cTleYhTsqPgk6S2u7Rvaf85r78bz75T2VUUd12G4YM/EH1CaSAgjzygV5zRa4xOh CxB38n+cpDFtkMEQvBpivPVaWuFkhDx/2gPBo++KnOGrry3HpK9LkTsddqfGyQZY AhG1/8C2yww10o= Received: by filter0177p1mdw1.sendgrid.net with SMTP id filter0177p1mdw1.2692.548407EBF 2014-12-07 07:55:24.701091829 +0000 UTC Received: from mail.tarsnap.com (unknown [10.100.60.108]) by ismtpd-004 (SG) with ESMTP id 14a23bef439.8c2.3a2d2c for ; Sun, 07 Dec 2014 07:55:24 +0000 (UTC) Received: (qmail 55738 invoked from network); 7 Dec 2014 07:55:24 -0000 Received: from unknown (HELO clamshell.daemonology.net) (127.0.0.1) by ec2-107-20-205-189.compute-1.amazonaws.com with ESMTP; 7 Dec 2014 07:55:24 -0000 Received: (qmail 61821 invoked from network); 7 Dec 2014 07:53:37 -0000 Received: from unknown (HELO clamshell.daemonology.net) (127.0.0.1) by clamshell.daemonology.net with SMTP; 7 Dec 2014 07:53:37 -0000 Message-ID: <54840781.70603@freebsd.org> Date: Sat, 06 Dec 2014 23:53:37 -0800 From: Colin Percival User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: freebsd-acpi@freebsd.org Subject: ENXIOing non-present battery Content-Type: multipart/mixed; boundary="------------010302010806090809050207" X-SG-EID: t2fXfoZHCw6vGsGKHqKxJ9qWwHSlQfPdDS+3+p6rOCudNMbltcytpX5LGgkrH7G7qDL1+9O9E/odd4 /A+6jdXVgucrkTI02EX0XtotnXYy5E0dXu1oTtDrjHLg8EfAm2a4omWtHN/whOH7BZlweKg3+DjN6Q jNFE6IW9rvVbmcM= X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Dec 2014 07:55:44 -0000 This is a multi-part message in MIME format. --------------010302010806090809050207 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hi ACPI people, On my Dell Latitude E7440 laptop, the ACPI reports two batteries: First the battery which exists; and second, a "Not Present" battery with zeroed statistics. FreeBSD, not realizing that this second battery is a complete myth -- the E7440 only has one battery, and there is nowhere to add another -- faithfully reports the data from ACPI to userland. Unfortunately it causes some problems there; in particular, KDE interprets it as meaning that the system should have two batteries, and when it sees that the "second" battery has 0% power remaining it kicks off the "battery is low, turn the laptop off" code. If that code is disabled, it still displays the wrong battery-charge-remaining status icons. For dealing with such broken ACPIs, it seems like not attaching a non-present battery would be a good idea. This shouldn't be the default behaviour, since there are plenty of systems where a non-present battery might be inserted at a later time; but I see nothing wrong with adding an option. The attached patch adds a acpi.cmbat.hide_not_present loader tunable which, as the name suggests, hides non-present batteries; this is done in the probe code by returning ENXIO if the tunable is set to a nonzero value and acpi_BatteryIsPresent returns zero. With this patch and the tunable set my laptop behaves appropriately; and (aside from wasting a few bytes of memory) there should be no effect on systems where the tunable is not set. Any objections to me committing this? -- Colin Percival Security Officer Emeritus, FreeBSD | The power to serve Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid --------------010302010806090809050207 Content-Type: text/x-patch; name="hide_not_present.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="hide_not_present.patch" Index: sys/dev/acpica/acpi_cmbat.c =================================================================== --- sys/dev/acpica/acpi_cmbat.c (revision 274932) +++ sys/dev/acpica/acpi_cmbat.c (working copy) @@ -112,13 +112,17 @@ DRIVER_MODULE(acpi_cmbat, acpi, acpi_cmbat_driver, acpi_cmbat_devclass, 0, 0); MODULE_DEPEND(acpi_cmbat, acpi, 1, 1, 1); +static unsigned long hide_not_present = 0; +TUNABLE_ULONG("acpi.cmbat.hide_not_present", &hide_not_present); + static int acpi_cmbat_probe(device_t dev) { static char *cmbat_ids[] = { "PNP0C0A", NULL }; if (acpi_disabled("cmbat") || - ACPI_ID_PROBE(device_get_parent(dev), dev, cmbat_ids) == NULL) + ACPI_ID_PROBE(device_get_parent(dev), dev, cmbat_ids) == NULL || + (hide_not_present && !acpi_BatteryIsPresent(dev))) return (ENXIO); device_set_desc(dev, "ACPI Control Method Battery"); --------------010302010806090809050207--