Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp267266pxb; Thu, 21 Jan 2021 06:43:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgPr+zcqxWCiXkFx5t0YJyxrW+ySiep8YnkW8WsyPlx2N2d21KK/moNI3lSgTQMTW+Co3w X-Received: by 2002:a17:906:40d2:: with SMTP id a18mr9517807ejk.315.1611240231084; Thu, 21 Jan 2021 06:43:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611240231; cv=none; d=google.com; s=arc-20160816; b=OjIYZrdHqppqmHx5zpLwochXXzEOXzndPX8+CKnfAuBgl2rHRCkB0z9iF7twzdz7mF 7ZZsfxdRoNQFkrfOjYlBG6hDKFdm9r8Axpxgb5CgB8Rf/7Emi5Fy6pJ5Sm4H8sshjoSY qlQv5RyBFmuIhwjVu6H2KelQLlLzD/sWCEQpLPO3YM7A9CaWO3pf8acRZd7oD5tO/+v4 dPl7QExBtonZMbwnUMY3N0SGY5ERM1LsNBwcJUh+S/Q5DFm2r8A0xvFh/BEIBXZK1ImN aNe66UnpeNTemvmg/zp54FKFIuIZC7pOe5Wn2+IMMqKVe5LILw2knioCnfz1wfpYrCjH QpBA== 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=e2wC/gqTSVsEHUIwD9i+N/18O78gZ5uCZkeTAoDdvWM=; b=SwWqXCEIRMpN5uvBKxr7Y4ZuuTAnuiv0BepR3E1ixCz1DS6QtrcY3Q7Ix8LCR8beJD pqgXH3ujlDanR9+JTDW+Idg4/uZBHhrso1NA0PjVu3V2khMH4orK6bJOpKhmRtzhquKN fqBSEXcAJJeh7hFV+qVJ1nrcePqvK5GMpit6ncBFy/lKcWZM/RWa5jJ5BwmPKpZuapbz zfMYEErUAPWZ60RRIvKKTDjSjGVWGryHUTuPBnVu5Flubhi1T3+sTJZr4ZX5kWdF6HyE OXxutZYfOinFh8C4Z8T/T1hIo5d3XjGVsofXmyF/BJWyJCUhyRe+XzPmQ51to6EiMNu/ 22qQ== 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 b2si1837691ejc.551.2021.01.21.06.43.27; Thu, 21 Jan 2021 06:43:51 -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 S1731961AbhAUOlY (ORCPT + 99 others); Thu, 21 Jan 2021 09:41:24 -0500 Received: from mail-ot1-f53.google.com ([209.85.210.53]:45994 "EHLO mail-ot1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731621AbhAUOk5 (ORCPT ); Thu, 21 Jan 2021 09:40:57 -0500 Received: by mail-ot1-f53.google.com with SMTP id n42so1754160ota.12; Thu, 21 Jan 2021 06:40:33 -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=e2wC/gqTSVsEHUIwD9i+N/18O78gZ5uCZkeTAoDdvWM=; b=N/Dm8JP1SX8I81Iak5zh5Lc1eM6okSBElw7EryE1P35cBxz2Z7gktT6Rfu/D8CwG5a 7+pzRGeQtoUELB7LOHVRQLONWOAI2H4A5FL+k3tglrNexAuxL4Qhbrb6zKAXPRb0tMLe 9+m2DYlpHwwtDkiFsu6gJVXSFaLopRHi9hmU0IWUOA8hL7onSWrDOD7Vba2Wv0UuizlM a7KhgAWIo4eIUsb1k3E49stKjzCfnEPzUMlfrD4jfUCSQbPPvW/JbjikFRW2X5uDPjjh kgOLcoSN3Wk9aMD+ZdTsa84SjFe/r7pKAoNRsyZHk44/XzRI8eHzTl45sDlCDN8RXntq smZg== X-Gm-Message-State: AOAM531+sL7HuYayhPMFJQtH+pHe21FVVco7Yt5j2EltybfUH5t332B6 6QrAMxW5VIuIC5KJx5w8hzJ/nj8KYuyM1gopmRA= X-Received: by 2002:a9d:1710:: with SMTP id i16mr10445162ota.260.1611240007526; Thu, 21 Jan 2021 06:40:07 -0800 (PST) MIME-Version: 1.0 References: <20210118003428.568892-1-djrscally@gmail.com> <20210118003428.568892-3-djrscally@gmail.com> <85ccf00d-7c04-b1da-a4bc-82c805df69c9@gmail.com> In-Reply-To: <85ccf00d-7c04-b1da-a4bc-82c805df69c9@gmail.com> From: "Rafael J. Wysocki" Date: Thu, 21 Jan 2021 15:39:55 +0100 Message-ID: Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices To: Daniel Scally Cc: "Rafael J. Wysocki" , 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 Thu, Jan 21, 2021 at 1:04 PM Daniel Scally wrote: > > > On 21/01/2021 11:58, Rafael J. Wysocki wrote: > > On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally wrote: > >> Hi Rafael > >> > >> On 19/01/2021 13:15, Rafael J. Wysocki wrote: > >>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally wrote: > >>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote: > >>>>> 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? > >>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which > >>>> refer to those INT3472's in their _DEP method. The driver binds to the > >>>> INT3472 device, we need to find the sensors dependent on them. > >>>> > >>> Well, this is an interesting concept. :-) > >>> > >>> Why does _DEP need to be used for that? Isn't there any other way to > >>> look up the dependent sensors? > >>> > >>>>> 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? > >>>> Ah - that may work, yes. Thank you, let me test that. > >>> Even if that doesn't work right away, but it can be made work, I would > >>> very much prefer that to the driver parsing _DEP for every device in > >>> the namespace by itself. > >> > >> This does work; do you prefer it in scan.c, or in utils.c (in which case > >> with acpi_dep_list declared as external var in internal.h)? > > Let's put it in scan.c for now, because there is the lock protecting > > the list in there too. > > > > How do you want to implement this? Something like "walk the list and > > run a callback for the matching entries" or do you have something else > > in mind? > > > Something like this (though with a mutex_lock()). It could be simplified > by dropping the prev stuff, but we have seen INT3472 devices with > multiple sensors declaring themselves dependent on the same device > > > struct acpi_device * > acpi_dev_get_next_dependent_dev(struct acpi_device *supplier, > struct acpi_device *prev) > { > struct acpi_dep_data *dep; > struct acpi_device *adev; > int ret; > > if (!supplier) > return ERR_PTR(-EINVAL); > > if (prev) { > /* > * We need to find the previous device in the list, so we know > * where to start iterating from. > */ > list_for_each_entry(dep, &acpi_dep_list, node) > if (dep->consumer == prev->handle && > dep->supplier == supplier->handle) > break; > > dep = list_next_entry(dep, node); > } else { > dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data, > node); > } > > > list_for_each_entry_from(dep, &acpi_dep_list, node) { > if (dep->supplier == supplier->handle) { > ret = acpi_bus_get_device(dep->consumer, &adev); > if (ret) > return ERR_PTR(ret); > > return adev; > } > } > > return NULL; > } That would work I think, but would it be practical to modify acpi_walk_dep_device_list() so that it runs a callback for every consumer found instead of or in addition to the "delete from the list and free the entry" operation?