From owner-svn-src-stable-12@freebsd.org Mon Mar 2 09:09:18 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A85FC25FAA7; Mon, 2 Mar 2020 09:09:18 +0000 (UTC) (envelope-from hselasky@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48WDq161NBz3NRX; Mon, 2 Mar 2020 09:09:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1E74D1A0A8; Mon, 2 Mar 2020 09:09:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02299G68048014; Mon, 2 Mar 2020 09:09:16 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02299G0S048013; Mon, 2 Mar 2020 09:09:16 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202003020909.02299G0S048013@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 2 Mar 2020 09:09:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r358534 - stable/12/sys/dev/acpica X-SVN-Group: stable-12 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/12/sys/dev/acpica X-SVN-Commit-Revision: 358534 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Mar 2020 09:09:18 -0000 Author: hselasky Date: Mon Mar 2 09:09:16 2020 New Revision: 358534 URL: https://svnweb.freebsd.org/changeset/base/358534 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 Sponsored by: Mellanox Technologies Modified: stable/12/sys/dev/acpica/acpi_lid.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/acpica/acpi_lid.c ============================================================================== --- stable/12/sys/dev/acpica/acpi_lid.c Mon Mar 2 08:44:58 2020 (r358533) +++ stable/12/sys/dev/acpica/acpi_lid.c Mon Mar 2 09:09:16 2020 (r358534) @@ -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)