Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3748843pxb; Mon, 1 Feb 2021 03:49:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYQmiZNtMJ+hB8cOPaNpEIBor4FgPaXUGKaG2Y8KZtwrOseclh8pvg5iWD6uA/n16qTheS X-Received: by 2002:a17:906:ce5b:: with SMTP id se27mr17074367ejb.57.1612180151086; Mon, 01 Feb 2021 03:49:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612180151; cv=none; d=google.com; s=arc-20160816; b=s3YaxDGDW9+VmHzRMpyy2CVe4usN7RCkdfHuK6hEMJYIT3rj7o8AQ2eA/zhY8mdZPh 135j7H5BvqAbuD2yg44GQjfDbjmD9gc/TKw5LLnCHCRMahZ6bGPE0BoFtCyOG2PoSKQH B1WqZ++nXhe8BO1l7DwiwmfN9fpiTY81UCrVK4eHDpXU30C6KyWKfUuoT3JpgXMqNA22 x2vBIXKcppU5Bk/lvPJN0VSBwuruaYnX3LJo5RQr945QvLrOIpnnUR2IbG7yQvCsVIr7 6gwBZm+ESffscqH0z+VGKS9hBBTJnDD0OxrUcbR/5bQN3RD2GYIrCnvY+hP4w+Bc51ZU zz4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=ZECPl9vWLqX80qTTkcPpSaoTS5g7uLclA6b2TpcCjTo=; b=zLSwzffdgmu5sZxfeSM5X4VILIArRqhBQrn1eijTk8QwzpBTiu87tBkUGwWGxZwLcd 64ONOmfRE5GIsQdjOF7yceNF0xcE0gpjiMPxwcDPnffHrsfiiddwUiYDrKFT++CiBzSs LfQLfsEEwH/R4W+TWUaWJqUNWGBFRlctY9OF7p2nIAY2/vHef1hcxdJW+60c05SHWxj2 /BKpSYjKYLkFVea6EMdsz381pjKKbkte71O9SXkhT3NYxVW0TeDRAiopxQG6kJlWXk0h TVoVwbHnTP7gP53CFgnskSWwWxKlDFB9/sQWE3sKY5ZMh+1ZWdZUxuW6nXJFRKjaSUEC MEiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fx4si10618388ejb.157.2021.02.01.03.48.45; Mon, 01 Feb 2021 03:49:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbhBALpo convert rfc822-to-8bit (ORCPT + 99 others); Mon, 1 Feb 2021 06:45:44 -0500 Received: from mail-oi1-f169.google.com ([209.85.167.169]:33276 "EHLO mail-oi1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbhBALpm (ORCPT ); Mon, 1 Feb 2021 06:45:42 -0500 Received: by mail-oi1-f169.google.com with SMTP id j25so18502402oii.0; Mon, 01 Feb 2021 03:45:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=F3brwljMK0uhzeGRjZ/IuBQwp5XiEQw0EzVWxL9yxHk=; b=nOiQxrcJLo1158TBeGPNaNURf699znMIIMT/o+af0IUdw2dnZfcB+RWs9GVw6cn/Nw y+0zC4Dp9ReQMc3InO/AKCmp0mWY/o3nk0TLFfyRurzdZbcpvLxqk2K3Msy4NDzk9LAH AwhG+dmKFkUWI3wYK7FgkFP+oF12REvh2fekpHuyP/qTUy+wu6HUzKQJPOP+z71JCJn+ 58+60bZ83SIym6kaWNqroxKTaUHxx2T8HaQD8UBdBb+Fy5QJDJmTKLoshprNNoylGmOL zoAMl8PK+dc0DJseoP1YkRhwmAo0lTq9iEOB5tuSSgpKuySKEGanl5pUpp0PUfBfbtRv Jvuw== X-Gm-Message-State: AOAM532og5wZ4CkJ2PYywbNrAG+imBfbakm8VPpiLlMK5bYO3FqDOAYA LTKpe3/MkGLgPk3ZYeAHhKoI3/MxAtS2JH2M+ok= X-Received: by 2002:aca:308a:: with SMTP id w132mr10054609oiw.69.1612179901283; Mon, 01 Feb 2021 03:45:01 -0800 (PST) MIME-Version: 1.0 References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> <20210128232729.16064-1-sakari.ailus@linux.intel.com> <20210129164522.GJ32460@paasikivi.fi.intel.com> <20210129212211.GK32460@paasikivi.fi.intel.com> In-Reply-To: <20210129212211.GK32460@paasikivi.fi.intel.com> From: "Rafael J. Wysocki" Date: Mon, 1 Feb 2021 12:44:46 +0100 Message-ID: Subject: Re: [PATCH v9 1/7] ACPI: scan: Obtain device's desired enumeration power state To: Sakari Ailus Cc: "Rafael J. Wysocki" , linux-i2c , Wolfram Sang , ACPI Devel Maling List , Linux Kernel Mailing List , Greg Kroah-Hartman , "Mani, Rajmohan" , Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , Linux Media Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 29, 2021 at 10:22 PM Sakari Ailus wrote: > > On Fri, Jan 29, 2021 at 05:57:17PM +0100, Rafael J. Wysocki wrote: > > On Fri, Jan 29, 2021 at 5:45 PM Sakari Ailus > > wrote: > > > > > > Hi Rafael, > > > > > > Thanks for the comments. > > > > > > On Fri, Jan 29, 2021 at 03:07:57PM +0100, Rafael J. Wysocki wrote: > > > > On Fri, Jan 29, 2021 at 12:27 AM Sakari Ailus > > > > wrote: > > > > > > > > > > Store a device's desired enumeration power state in struct > > > > > acpi_device_power_flags during acpi_device object's initialisation. > > > > > > > > > > Signed-off-by: Sakari Ailus > > > > > --- > > > > > drivers/acpi/scan.c | 6 ++++++ > > > > > include/acpi/acpi_bus.h | 3 ++- > > > > > 2 files changed, 8 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > > > > > index 1d7a02ee45e05..b077c645c9845 100644 > > > > > --- a/drivers/acpi/scan.c > > > > > +++ b/drivers/acpi/scan.c > > > > > @@ -987,6 +987,8 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state) > > > > > > > > > > static void acpi_bus_get_power_flags(struct acpi_device *device) > > > > > { > > > > > + unsigned long long pre; > > > > > + acpi_status status; > > > > > u32 i; > > > > > > > > > > /* Presence of _PS0|_PR0 indicates 'power manageable' */ > > > > > @@ -1008,6 +1010,10 @@ static void acpi_bus_get_power_flags(struct acpi_device *device) > > > > > if (acpi_has_method(device->handle, "_DSW")) > > > > > device->power.flags.dsw_present = 1; > > > > > > > > > > + status = acpi_evaluate_integer(device->handle, "_PRE", NULL, &pre); > > > > > + if (ACPI_SUCCESS(status) && !pre) > > > > > + device->power.flags.allow_low_power_probe = 1; > > > > > > > > While this is what has been discussed and thanks for taking it into > > > > account, I'm now thinking that it may be cleaner to introduce a new > > > > object to return the deepest power state of the device in which it can > > > > be enumerated, say _DSE (Device State for Enumeration) such that 4 > > > > means D3cold, 3 - D3hot and so on, so the above check can be replaced > > > > with something like > > > > > > > > status = acpi_evaluate_integer(device->handle, "_PRE", NULL, &dse); > > > > > > s/_PRE/_DSE/ > > > > > > ? > > > > Yes, sorry. > > > > > > > > > if (ACPI_FAILURE(status)) > > > > > > ACPI_SUCCESS? > > > > Yup. > > > > > > device->power.state_for_enumeratin = dse; > > > > > > > > And then, it is a matter of comparing ->power.state_for_enumeratin > > > > with ->power.state and putting the device into D0 if the former is > > > > shallower than the latter. > > > > > > > > What do you think? > > > > > > Sounds good. How about calling the function e.g. > > > acpi_device_resume_for_probe(), so runtime PM could be used to resume the > > > device if the function returns true? > > > > I'd rather try to power it up before enabling runtime PM, because in > > order to do the latter properly, you need to know if the device is > > active or suspended to start with. > > > > So you need something like (pseudo-code) > > > > if (this_device_needs_to_be_on(ACPI_COMPANION(dev))) { > > acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D0); > > pm_runtime_set_active(dev); > > } else { > > pm_runtime_set_suspended(dev); > > I guess the else branch isn't needed? The device remains suspended if its > state hasn't been changed. Assuming that the initial status is always "suspended", the else branch is not needed. > > } > > > > and then you can enable PM-runtime. > > Yes, agreed, this is what drivers should do. The I涎 framework would use > the function and conditionally power the device on before enabling runtime > PM. > > This is how it's implemented by the set already but I think the change in > semantics requires a little more still. Agreed.