From nobody Sat Dec 28 18:54:55 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YLBPX11Hnz5j3BS; Sat, 28 Dec 2024 18:54:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YLBPX0S0wz506Z; Sat, 28 Dec 2024 18:54:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735412096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4St5x/HLokMDszpB4WaXgvHvxgBPSk68k1Xt9LDNvVs=; b=xSlL4+/5DBJecDbJBQePkrTKcMOxiP3NCA7LMi3U5gylMgv57viiEa8RU6QgZSon/ALajE NebDJVjikRyjpddW0bnl01yEF5dTUHxCNBDONZY+9i3aSOj/LMgiIk21VXnpylS1jE8BcE lCWdWWcECgg2zY5ivdSY2ma00lWTEv9ywoZGc8hrb40qfTQornPGMKV8mz99/UUNQtal9U Lq+gE5mgil7lsuI/1YsPGCnkQ/Hku5e0STqEyiJcSGPuV9IVnImZencvDb0P9Ur+LYz7gi VIAarjG7Mljh1cs3K8zIVSXP+lfz295zE2X+Mq0yr9m0L+vaiRUQKb0M9UxKQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735412096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4St5x/HLokMDszpB4WaXgvHvxgBPSk68k1Xt9LDNvVs=; b=wly/njxW0z5VoQmgRPrRFWNOIcfmzYMN3lRFrq4I++j9BaWPDdcy5qD5ljkT1/34kjSQ6d XRtczIXjrlJuVRTz5cMzxj4ODYQS5Kqw5EmOY0ihysleY6Jnukw15nylbf5nGiMQ1sabPC l3pfB+arl84SS+BQG9hs/sMNh3yTVNwU/0sAEu/4buSlaL6KqSuTnKbFguFdGWH+OZhujh 5eq0WeK1JvM17gf9wjtLno+WADCGf2Kt+qbmYEEWELt9+4bfiISP0vctnmUwjMnv1T+eDm 8b6Cy7rCGEFW0no4R70ZyRuStllodEuBQ/wc6580jeVvIswg5BKEQ6PgB15hPQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735412096; a=rsa-sha256; cv=none; b=lvgUb74jkj4bj8t/9aEriKFNBYNjrq+np8NcT9vLP58qz4RkYu47qc0V0qCmtOXGqTqI96 dM/WuQAiNrEco+caiGaslHnfBAiyTFcig9xdpDEqPQgRAR1nSsXwKW0+4IzVJ7fHgyvK3i p9utZzupEr7pbMLXilrS8T7VJ22u1dl5qFDfo7jRsYVChYFMVP+lRH2eGa6SJv5ByQtbhd ps/dZTuK9V/oBE9k6yJ1Ls/S8IgLNq6ZK9UrCpjdy8w59XSF16V/Vgzd6hwKCf0uxjzaDJ AhISxruAt6MZB6MAKGgphqFly7ZuTMh0l9p5wKIDJ/dGgG6jUh9D53V5TvowFw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YLBPX03szzc0y; Sat, 28 Dec 2024 18:54:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BSIstdh037416; Sat, 28 Dec 2024 18:54:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BSIstqh037413; Sat, 28 Dec 2024 18:54:55 GMT (envelope-from git) Date: Sat, 28 Dec 2024 18:54:55 GMT Message-Id: <202412281854.4BSIstqh037413@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 9863280ff77c - stable/13 - acpi/apm: Improve APM ioctl interface emulation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9863280ff77c23c00dfe7f5052bc3814bbc4b733 Auto-Submitted: auto-generated The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=9863280ff77c23c00dfe7f5052bc3814bbc4b733 commit 9863280ff77c23c00dfe7f5052bc3814bbc4b733 Author: Warner Losh AuthorDate: 2024-01-03 23:18:23 +0000 Commit: Warner Losh CommitDate: 2024-12-28 18:11:18 +0000 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 (cherry picked from commit 8a3fafc821149e800747cd92afee092fd131c402) --- sys/x86/acpica/acpi_apm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/x86/acpica/acpi_apm.c b/sys/x86/acpica/acpi_apm.c index 4e880c3e5411..66fe25b0448a 100644 --- a/sys/x86/acpica/acpi_apm.c +++ b/sys/x86/acpica/acpi_apm.c @@ -142,18 +142,18 @@ acpi_capm_get_info(apm_info_t aip) aip->ai_capabilities= 0xff00; /* unknown */ if (acpi_acad_get_acline(&acline)) - aip->ai_acline = APM_UNKNOWN; /* unknown */ + aip->ai_acline = 1; /* no info -- on-line best guess */ else aip->ai_acline = acline; /* on/off */ if (acpi_battery_get_battinfo(NULL, &batt) != 0) { - aip->ai_batt_stat = APM_UNKNOWN; - aip->ai_batt_life = APM_UNKNOWN; - aip->ai_batt_time = -1; /* unknown */ - aip->ai_batteries = ~0U; /* unknown */ + aip->ai_batt_stat = 0; /* "high" old I/F has no unknown state */ + aip->ai_batt_life = 255; /* N/A, not -1 */ + aip->ai_batt_time = -1; /* unknown */ + aip->ai_batteries = ~0U; /* unknown */ } else { aip->ai_batt_stat = acpi_capm_convert_battstate(&batt); - aip->ai_batt_life = batt.cap; + aip->ai_batt_life = (batt.cap == -1) ? 255 : batt.cap; aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60; aip->ai_batteries = acpi_battery_get_units(); } @@ -187,11 +187,11 @@ acpi_capm_get_pwstatus(apm_pwstatus_t app) app->ap_batt_stat = acpi_capm_convert_battstate(&batt); app->ap_batt_flag = acpi_capm_convert_battflags(&batt); - app->ap_batt_life = batt.cap; + app->ap_batt_life = (batt.cap == -1) ? 255 : batt.cap; app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60; if (acpi_acad_get_acline(&acline)) - app->ap_acline = APM_UNKNOWN; + app->ap_acline = 1; /* no info -- on-line best guess */ else app->ap_acline = acline; /* on/off */