From nobody Sat Dec 28 18:56:47 2024 X-Original-To: dev-commits-src-all@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 4YLBRg6lhzz5j2qJ; Sat, 28 Dec 2024 18:56:47 +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 4YLBRg6BD7z538V; Sat, 28 Dec 2024 18:56:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735412207; 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=uLuuw/mHcNqY/RSA37EMlrGupaWAGlLymMUmTvy+YzI=; b=pEhso+abbe51ClagBWMBFHpZyEQLg5SueFxQvDodlxIY4+B7eKPdkqKgGULXtp4fbgCmwG pU9ugLAU5YBH0GTytcsam0DEydWWwJNgfhjn35STa5e9P39sa5ZODHxCShQ9ebYTSr8cWF 86g03MDDnEJAncpfGcGhUqPVuk7SFiuGAxR5RGa7TL/UXolsNAL1Xby1pQgAT+whUigKeR 66P7nKln4j7xP3Ln0dJq8+9fN97w5U75dzEdqiGNvziiy1Lr8LVMdh8YA44kdsGCNcPYDd 3ddPsj0XJYLbUDpBJFWAbjuiUhIEaUnPUstvChe7sQKCVngB7yx+R3xFyR+0AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735412207; 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=uLuuw/mHcNqY/RSA37EMlrGupaWAGlLymMUmTvy+YzI=; b=DeMljielfl7BD1Rf8HiTK7MDuox/w4yH/7N0xk4Mit7FJesvs8qGsqjGoQrkYAUWAahzJH dqntwjzlXqMPF5w9I3TnA86x09QiFrzN4XnQ1nQ/LLt3xcfNe9egRXFfuRX5m1eEYyStrI 6j+U+f3919pVCghUVp+b+9Kw1vsb1TXzo3DyHymvgjrrHhxSJrTLLWdv4MtQA7LsUHCjcD zR7ffaZHmJFu6mYIxGOfD3eW1fK5zn7FG4zmbBNsFG1qhBOGtk5xuDBtKkj1bGfRTc17iq oc2qZWkNj/BdA/fEdsG6zo7tUepmf19cwA1T2An6Yh5IKPIDy/xTSTC3S3E4Iw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735412207; a=rsa-sha256; cv=none; b=jZtuvqTarSIE1IZtJ6v3JY5yFaEJtbD9djGB9Sy1C0dkAP3FnSCiX7xVGK8l8/ktsBKUlW fsz5Dss7MmGE0e14heTe3VbwzjCWGDmX8hG1JvwPaNJrTvlLXlfzRrec/rvKeWExqOrNZN TG+5OOccfl5anqTmVKs0PjgEghpgqTThsCzDT963hR7/RQeqTun6Y5lo4Hqb9d5bmm2bZb kQi0K2GJvUdAq71i0//sweKguoJs3GWV5M2mqCLBHTDqulcL5c6jhzDtTuPnwzNEcTg2GZ ABOaIlzfVSLlzHEuTBBH3H0Wq1yUCrDiKQDuiTdK4Mv0P1IGHAjHDcmNeXonyA== 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 4YLBRg5n0CzcjH; Sat, 28 Dec 2024 18:56:47 +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 4BSIulCP038713; Sat, 28 Dec 2024 18:56:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BSIulbw038710; Sat, 28 Dec 2024 18:56:47 GMT (envelope-from git) Date: Sat, 28 Dec 2024 18:56:47 GMT Message-Id: <202412281856.4BSIulbw038710@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: 9be96a2158bb - stable/14 - acpi/apm: Improve APM ioctl interface emulation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/14 X-Git-Reftype: branch X-Git-Commit: 9be96a2158bbaa1af65ef88b1f4e9c57ec5296e4 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=9be96a2158bbaa1af65ef88b1f4e9c57ec5296e4 commit 9be96a2158bbaa1af65ef88b1f4e9c57ec5296e4 Author: Warner Losh AuthorDate: 2024-01-03 23:18:23 +0000 Commit: Warner Losh CommitDate: 2024-12-28 18:11:09 +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 e7e4b0f1a546..b602047d7bca 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 */