From nobody Thu Jan 11 00:06:31 2024 X-Original-To: dev-commits-src-main@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 4T9Q1z3Ngqz56XW0; Thu, 11 Jan 2024 00:06:31 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T9Q1z2W9wz4Fhm; Thu, 11 Jan 2024 00:06:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704931591; 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=xM01cijgw1g7Mcq7hB7uHn+nsDjNsTdYj4Kst5x9QrE=; b=of58EB6eCwOeYLtBNp7UN7iEVmCYchEOth5tDLD70vlgzaLIA9SEjayyR1EOJ1vAwcE2dZ ZoahYrbBxion4cl3RolQ8kDK7QlwOpiSL4aMtJrU+tWNh38lh3LnONGbdCVZju4eONOlyd SL64JNPgJzi6A0EwLzvSygDUGK1NGz8mftRJ8+JxS1KM4M0H9JOf+RVtD3Pzl2GoQk6q6J pLputHBAl1kTP8E4o08rpPhzcDvHRavENPa2CbAOFXrsciZ6BnaFNJ691m0h0WjqlckWp4 /pXmO5Gw4Gu7ZLxiekSNoxtieKIJbbQaHI4gTdWjCXfJIZCFbYjP3Rg+OQZZiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704931591; 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=xM01cijgw1g7Mcq7hB7uHn+nsDjNsTdYj4Kst5x9QrE=; b=UJRAxEM0DT3nnuQSGRALyEA39Mb3/61pCSPECkTQkZwflJI1eTZlxDBue7JC3kDHQscRN6 0+RW4MIJ4d+hJc2ZX9ezHuES0K1iT5l+guoqjfqjeYRTVjPDvfV5WMx67cl5cFFlxJFFnq CMXnEp7klPMQ3QrysLYbpTMVYhVwUuk2H2sS5hRgw6kZEPcuaLijtSKvI4knO6Fhgo+JTs bKANIFDCb+7MXcJyDWfu9EPe8HFe9FSLhmXPGDdWdEzUDIZLjhxic7236Am8M7iGJzluoO e3cNaWvnHNjEQ1lS33dHx/7iO7Jrr08xMwn6nkJqMpbj8vy6ljCwsyIItsO8qg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704931591; a=rsa-sha256; cv=none; b=rHTpFZ1x2HvNSgb2mCuvBX1gRRItWT+1E2Suk8Xe760Xjkc6zr46uVNAnXTzyaxqWrWhWW 8N1N+VTTONaWJZ6YylEV2WLs1Kmii+wQMLXPcQTaqqvVXkZgbbvElDb122SXU39LhfOjLq FDjPoV+CHopea3HoINOEmPN7m6NyGVqFh8QyqnHK3G5hpP+TQ3Vtf/B+dIv8yfP2wJ2s32 tezmgyMWEtF8eMfGJMUG3OVZTM6KApK1ALakBrAzPmcY1A6OW3xZjXOlfQ8+Q09rdv0xIk GwHz+TfATBmy7R4t+OmQTj0iHZ1gIgepVQhO0CFMYeYAWP4YVWpxh9vusy4AoQ== 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 4T9Q1z1YMLzwxH; Thu, 11 Jan 2024 00:06:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40B06VOU052075; Thu, 11 Jan 2024 00:06:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40B06VAx052072; Thu, 11 Jan 2024 00:06:31 GMT (envelope-from git) Date: Thu, 11 Jan 2024 00:06:31 GMT Message-Id: <202401110006.40B06VAx052072@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 8a3fafc82114 - main - acpi/apm: Improve APM ioctl interface emulation List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 8a3fafc821149e800747cd92afee092fd131c402 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=8a3fafc821149e800747cd92afee092fd131c402 commit 8a3fafc821149e800747cd92afee092fd131c402 Author: Warner Losh AuthorDate: 2024-01-03 23:18:23 +0000 Commit: Warner Losh CommitDate: 2024-01-11 00:05:00 +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 --- 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 ffefcdf733c2..fcc1663b9a84 100644 --- a/sys/x86/acpica/acpi_apm.c +++ b/sys/x86/acpica/acpi_apm.c @@ -141,18 +141,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(); } @@ -186,11 +186,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 */