Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Sep 2025 16:03:50 GMT
From:      Aymeric Wibo <obiwac@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 9e1e29bd5ec6 - main - acpi: Add back `hw.acpi.suspend_state` sysctl
Message-ID:  <202509261603.58QG3oPf069252@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by obiwac:

URL: https://cgit.FreeBSD.org/src/commit/?id=9e1e29bd5ec61bba1bb3366ff4c069b0c8f75954

commit 9e1e29bd5ec61bba1bb3366ff4c069b0c8f75954
Author:     Aymeric Wibo <obiwac@FreeBSD.org>
AuthorDate: 2025-09-26 15:49:28 +0000
Commit:     Aymeric Wibo <obiwac@FreeBSD.org>
CommitDate: 2025-09-26 16:03:05 +0000

    acpi: Add back `hw.acpi.suspend_state` sysctl
    
    When writing an ACPI S-state to it it will set kern.power.suspend to the
    appropriate sleep type, and when reading from it it will return the
    corresponding ACPI S-state to the sleep type in kern.power.suspend.
    
    This is deprecated and kern.power.suspend should be used directly
    instead, but add this back because zzz(1) makes use of this and we can't
    easily rewrite it just now.
    
    PR:             289634
    Reviewed by:    cy, markj
    Approved by:    cy, markj
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D52600
    Event:          EuroBSDcon 2025 Devsummit
---
 sys/dev/acpica/acpi.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c
index f9003a951d45..6994f46eba10 100644
--- a/sys/dev/acpica/acpi.c
+++ b/sys/dev/acpica/acpi.c
@@ -195,6 +195,7 @@ static void	acpi_system_eventhandler_wakeup(void *arg,
 static enum power_stype	acpi_sstate_to_stype(int sstate);
 static int	acpi_sname_to_sstate(const char *sname);
 static const char	*acpi_sstate_to_sname(int sstate);
+static int	acpi_suspend_state_sysctl(SYSCTL_HANDLER_ARGS);
 static int	acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS);
 static int	acpi_stype_sysctl(SYSCTL_HANDLER_ARGS);
 static int	acpi_debug_objects_sysctl(SYSCTL_HANDLER_ARGS);
@@ -616,6 +617,11 @@ acpi_attach(device_t dev)
 	&sc->acpi_lid_switch_stype, 0, acpi_stype_sysctl, "A",
 	"Lid ACPI sleep state. Set to s2idle or s2mem if you want to suspend "
 	"your laptop when close the lid.");
+    SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
+	OID_AUTO, "suspend_state", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
+	NULL, 0, acpi_suspend_state_sysctl, "A",
+	"Current ACPI suspend state. This sysctl is deprecated; you probably "
+	"want to use kern.power.suspend instead.");
     SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
 	OID_AUTO, "standby_state",
 	CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
@@ -4352,6 +4358,32 @@ acpi_supported_sleep_state_sysctl(SYSCTL_HANDLER_ARGS)
     return (error);
 }
 
+static int
+acpi_suspend_state_sysctl(SYSCTL_HANDLER_ARGS)
+{
+    char name[10];
+    int err;
+    struct acpi_softc *sc = oidp->oid_arg1;
+    enum power_stype new_stype;
+    enum power_stype old_stype = power_suspend_stype;
+    int old_sstate = acpi_stype_to_sstate(sc, old_stype);
+    int new_sstate;
+
+    strlcpy(name, acpi_sstate_to_sname(old_sstate), sizeof(name));
+    err = sysctl_handle_string(oidp, name, sizeof(name), req);
+    if (err != 0 || req->newptr == NULL)
+	return (err);
+
+    new_sstate = acpi_sname_to_sstate(name);
+    if (new_sstate < 0)
+	return (EINVAL);
+    new_stype = acpi_sstate_to_stype(new_sstate);
+    if (acpi_supported_stypes[new_stype] == false)
+	return (EOPNOTSUPP);
+    if (new_stype != old_stype)
+	power_suspend_stype = new_stype;
+    return (err);
+}
 
 static int
 acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509261603.58QG3oPf069252>