Date: Mon, 2 Mar 2020 09:16:48 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r358536 - stable/11/sys/dev/acpica Message-ID: <202003020916.0229Gmka054518@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Mon Mar 2 09:16:48 2020 New Revision: 358536 URL: https://svnweb.freebsd.org/changeset/base/358536 Log: MFC r358219 and r358270: Make sure the ACPI lid state is updated during boot and after resume. While at it update the sysctl(9) description for the lid state. Always check return value from acpi_GetInteger(). If a failure happens reading the lid state, assume the lid is opened. Differential Revision: https://reviews.freebsd.org/D23724 PR: 240881 Submitted by: Yuri Pankov <yuripv@yuripv.me> Sponsored by: Mellanox Technologies Modified: stable/11/sys/dev/acpica/acpi_lid.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/acpica/acpi_lid.c ============================================================================== --- stable/11/sys/dev/acpica/acpi_lid.c Mon Mar 2 09:13:26 2020 (r358535) +++ stable/11/sys/dev/acpica/acpi_lid.c Mon Mar 2 09:16:48 2020 (r358536) @@ -84,6 +84,27 @@ static devclass_t acpi_lid_devclass; DRIVER_MODULE(acpi_lid, acpi, acpi_lid_driver, acpi_lid_devclass, 0, 0); MODULE_DEPEND(acpi_lid, acpi, 1, 1, 1); +static void +acpi_lid_status_update(struct acpi_lid_softc *sc) +{ + ACPI_STATUS status; + int lid_status; + + ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); + + /* + * Evaluate _LID and check the return value, update lid status. + * Zero: The lid is closed + * Non-zero: The lid is open + */ + status = acpi_GetInteger(sc->lid_handle, "_LID", &lid_status); + if (ACPI_FAILURE(status)) + lid_status = 1; /* assume lid is opened */ + + /* range check value */ + sc->lid_status = lid_status ? 1 : 0; +} + static int acpi_lid_probe(device_t dev) { @@ -122,13 +143,16 @@ acpi_lid_attach(device_t dev) if (acpi_parse_prw(sc->lid_handle, &prw) == 0) AcpiEnableGpe(prw.gpe_handle, prw.gpe_bit); + /* Get the initial lid status */ + acpi_lid_status_update(sc); + /* * Export the lid status */ SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "state", CTLFLAG_RD, &sc->lid_status, 0, - "Device set to wake the system"); + "Device state (0 = closed, 1 = open)"); return (0); } @@ -142,6 +166,13 @@ acpi_lid_suspend(device_t dev) static int acpi_lid_resume(device_t dev) { + struct acpi_lid_softc *sc; + + sc = device_get_softc(dev); + + /* Update lid status, if any */ + acpi_lid_status_update(sc); + return (0); } @@ -150,21 +181,14 @@ acpi_lid_notify_status_changed(void *arg) { struct acpi_lid_softc *sc; struct acpi_softc *acpi_sc; - ACPI_STATUS status; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = (struct acpi_lid_softc *)arg; ACPI_SERIAL_BEGIN(lid); - /* - * Evaluate _LID and check the return value, update lid status. - * Zero: The lid is closed - * Non-zero: The lid is open - */ - status = acpi_GetInteger(sc->lid_handle, "_LID", &sc->lid_status); - if (ACPI_FAILURE(status)) - goto out; + /* Update lid status, if any */ + acpi_lid_status_update(sc); acpi_sc = acpi_device_get_parent_softc(sc->lid_dev); if (acpi_sc == NULL)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202003020916.0229Gmka054518>