Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2482987pxb; Mon, 18 Jan 2021 20:44:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1VdFD/Y+KMrIAZQLR3uhGxmbZCKhYPsV0PBCJOWGM9zq+4eMyn+Z1AYIQp8H92NsZ3cE/ X-Received: by 2002:a17:906:c793:: with SMTP id cw19mr1759987ejb.246.1611031487225; Mon, 18 Jan 2021 20:44:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611031487; cv=none; d=google.com; s=arc-20160816; b=oYKcmsxlqArDsAeWwmjg77TKJRBIO1/UGR5y73vyimtbU4O8GFKHGbNs8J9vFy+QaX dYxlJoHUrLo7FqC5pe5bwFvNrNO+AFO7CtFG5qSCAqYwfZIB6HvA+YDMb53KW6Kt/jS1 XuiZL8L0SO7SCUQd8q5l9gEv+t+RwxC59gsfDbPaf2rEAXfQbL+KuvHtvzEKRq1QnJhS +MOpbXKE7yoRew/2cT4a2uekjV/jk07IuVn+LUjuyGu65HtOqON0jkrpPTLTqbmW+DVU eS04PdNVeUlNJYWEql0cAP7QlnZZulQhI2mdaA4rj3RfKT0/z0OnTgpDr3BfBQWunq9W enqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=kytasFWKgvc5nOgZfApzBHs9Vw3bTByXjqhFQofMSYo=; b=qH96o65fbjFIruaABIde8KSdcrqIH7M6dgWflDt4N/iyRyBGawWnnsllBY8oy+SUS8 w8bNiZ+Kr72gj4iU/Uy9IawVDBqbbxip5Sp7WdwUUu37NivPnSX9M9iEPSKHeMn3l/Pw KJ5EZog8joAXQhvLll407E3w04VWVXjar75XdXanWW1YtEwHmCVLgFFvY3I1+hTxXOea +dUyWedGDhJRLtkXPIWlRJbMRQCXjKn4w6Kzkzy2ekHvak6krwbJIrWVflYFxOVCkNzx zDO6A/h11MlVW7iI9b0Np4o8NKNEBDlVsFTOAxmgp6hYYrHDx+J7v9da0GzHPmwksLna +1Wg== 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 w4si1803926ejb.499.2021.01.18.20.44.24; Mon, 18 Jan 2021 20:44:47 -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 S2406500AbhARQP0 (ORCPT + 99 others); Mon, 18 Jan 2021 11:15:26 -0500 Received: from mail-oi1-f179.google.com ([209.85.167.179]:43302 "EHLO mail-oi1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406484AbhARQPJ (ORCPT ); Mon, 18 Jan 2021 11:15:09 -0500 Received: by mail-oi1-f179.google.com with SMTP id q25so18165410oij.10; Mon, 18 Jan 2021 08:14:54 -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; bh=kytasFWKgvc5nOgZfApzBHs9Vw3bTByXjqhFQofMSYo=; b=RGI6HfMoHdxn5lyZ+SlMsj2bSwT8qKwQpbYmgsWhn9OFG0Am9NViYAZ91tMMjFU+eP ui5lE3XjrbdqeDAgQOJslQSGsIZaNG1j+vJ6sE8Y1NqnyekEk3ctLRV8qhTzDKQAWRmO wDBMGIyOQyA7uTQA1gXM4vCc5gSEZ8tb0b6Z8USchHFg9FrBHVPStUccznOAIkvJbPEy MoMyJqkthuipkg/el6xyY7nPRHr4a+4riyJgIZVz7KRN6erEoym+M0LjYz/WVL3C8sJ7 Nf+JwwHlDFt+/cTbXXuR1bgKzsiDxVLeZjzkTGHY6dN1g2oGooJwGOTgWMve7OYY+jTR NwBw== X-Gm-Message-State: AOAM530zBHSQpZSaF4htpm3zwggfKKNGwxATFtskCm7oCM1jvKb6SWzW cSIQZzxl3m/BXC2UzMFk1DIulYx7m+OQoFFdtxI= X-Received: by 2002:aca:5c05:: with SMTP id q5mr47953oib.157.1610986468728; Mon, 18 Jan 2021 08:14:28 -0800 (PST) MIME-Version: 1.0 References: <20210118003428.568892-1-djrscally@gmail.com> <20210118003428.568892-3-djrscally@gmail.com> In-Reply-To: <20210118003428.568892-3-djrscally@gmail.com> From: "Rafael J. Wysocki" Date: Mon, 18 Jan 2021 17:14:17 +0100 Message-ID: Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices To: Daniel Scally Cc: Linux Kernel Mailing List , ACPI Devel Maling List , linux-gpio@vger.kernel.org, linux-i2c , Platform Driver , "open list:ACPI COMPONENT ARCHITECTURE (ACPICA)" , "Rafael J. Wysocki" , Len Brown , andy@kernel.org, Mika Westerberg , Linus Walleij , Bartosz Golaszewski , Wolfram Sang , Lee Jones , Hans de Goede , Mark Gross , Robert Moore , Erik Kaneda , Sakari Ailus , Andy Shevchenko , Laurent Pinchart , Kieran Bingham Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally wrote: > > In some ACPI tables we encounter, devices use the _DEP method to assert > a dependence on other ACPI devices as opposed to the OpRegions that the > specification intends. We need to be able to find those devices "from" > the dependee, so add a function to parse all ACPI Devices and check if > the include the handle of the dependee device in their _DEP buffer. What exactly do you need this for? Would it be practical to look up the suppliers in acpi_dep_list instead? Note that supplier drivers may remove entries from there, but does that matter for your use case? > Signed-off-by: Daniel Scally > --- > Changes in v2: > - Used acpi_lpss_dep() as Andy suggested. > > drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++ > include/acpi/acpi_bus.h | 2 ++ > 2 files changed, 36 insertions(+) > > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c > index 78b38775f18b..ec6a2406a886 100644 > --- a/drivers/acpi/utils.c > +++ b/drivers/acpi/utils.c > @@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle) > return false; > } > > +static int acpi_dev_match_by_dep(struct device *dev, const void *data) > +{ > + struct acpi_device *adev = to_acpi_device(dev); > + const struct acpi_device *dependee = data; > + acpi_handle handle = dependee->handle; > + > + if (acpi_lpss_dep(adev, handle)) > + return 1; > + > + return 0; > +} > + > /** > * acpi_dev_present - Detect that a given ACPI device is present > * @hid: Hardware ID of the device. > @@ -866,6 +878,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) > } > EXPORT_SYMBOL(acpi_dev_present); > > +/** > + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev > + * @adev: Pointer to the dependee device > + * @prev: Pointer to the previous dependent device (or NULL for first match) > + * > + * Return the next ACPI device which declares itself dependent on @adev in > + * the _DEP buffer. > + * > + * The caller is responsible to call put_device() on the returned device. > + */ > +struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev, > + struct acpi_device *prev) > +{ > + struct device *start = prev ? &prev->dev : NULL; > + struct device *dev; > + > + dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep); > + > + return dev ? to_acpi_device(dev) : NULL; > +} > +EXPORT_SYMBOL(acpi_dev_get_next_dep_dev); > + > /** > * acpi_dev_get_next_match_dev - Return the next match of ACPI device > * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv > diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h > index 02a716a0af5d..33deb22294f2 100644 > --- a/include/acpi/acpi_bus.h > +++ b/include/acpi/acpi_bus.h > @@ -683,6 +683,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev) > > bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2); > > +struct acpi_device * > +acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev); > struct acpi_device * > acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv); > struct acpi_device * > -- > 2.25.1 >