Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2567384ybl; Thu, 29 Aug 2019 09:52:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNMQIQUvkVa4BHleKW/K6V6fTXR/SBhOnWsCoJu7fxSJK/HVRe7bSAVfgfv4aS/dGGuW66 X-Received: by 2002:a17:902:2ea2:: with SMTP id r31mr11172167plb.200.1567097549922; Thu, 29 Aug 2019 09:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567097549; cv=none; d=google.com; s=arc-20160816; b=n0gZGSOFCKKwzrzpxkVp4FNcfIRR6d7Mb6MRShwEVBepW6Mo+exY4pZhoulPnwbVHa BrCGo4M3cMyRGVteULJWxFKyvuYtQ95ijEgsMO1wkhWH9UKHMJMDdpCJ/A88+MfWEyjV 4yG8KtXIe7juP6hLSRTp2wnXF9z0xrtlKGQmZ8IDshZ3T5ozAO96bdpFV57xetZrIVAD 8gXd0GABMlpd6m9ZojZsvDcJagr+LpzB1cR/wsGAgJtqlJGysSLcCCrqckxRYz0mw/4O suRsiaqa2rm90WNTJXNFoSO0bi5yWWOQMo5bCe7LPeogpHZgfCW/ZQbxXmawxOwHUZwF hhNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=WXkmY9dKDZOaUdG/SQpzdL0Fp/MnkopnRwdDQ6IEl2w=; b=saHHy01nwgX4bOvcsZUz7QTvmeN2PCwnYDa3R8l+1BPlV0No5+2MppGta7qcrF537z 0r3dODhEERJpnmxrH0/e/WBl+AqF3xuMdz/q/29EfaXLq9cP+hShl4exO28kCuvftzfV lDDZ8tdhgoeMQtzO3l6ozF17irBLYA7rmz15F55hevEq6PkB/eskGGrz98pqjV4SiIWb g291CIkXhHgPvnEedZW4VLFpieytc4A3JxzaAjP3msnpRdz4igD5Vy/FKBwMaqysli6+ ndpg2ckYuvQEJSy6+43+Wdc/fnL70+nQhDjnhDBg/mP3lu1rzXuhabPK3eArKVFrXtTk OvPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="o6/1mtIq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b30si2423573pla.299.2019.08.29.09.52.15; Thu, 29 Aug 2019 09:52:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="o6/1mtIq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727929AbfH2QvP (ORCPT + 99 others); Thu, 29 Aug 2019 12:51:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:51460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbfH2QvP (ORCPT ); Thu, 29 Aug 2019 12:51:15 -0400 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C399D23404; Thu, 29 Aug 2019 16:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567097473; bh=pq0GhKU46RrXmGHvJIz30TT4pz3IJZ1TJm+ViEdFWA0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=o6/1mtIqrrR6T7me9poL5iZetsESqc4Cbf6otJ0M/FH05hzqbNryL3rqW1SDMUu/U PmoXbLr0xiHT3i8hqyYZo3GtC1NXe4LJNBXBonfjgJyxzFG2Pdgkv2s0i2otFDvFd7 FkpyVzxayL5cOiyg57xqutd8+dWy3DP6oarqEEyQ= Received: by mail-qt1-f178.google.com with SMTP id u34so4445387qte.2; Thu, 29 Aug 2019 09:51:13 -0700 (PDT) X-Gm-Message-State: APjAAAXkkakvyiy3nuSP3c534mO7cBnskrW9WDFIxLAzO5FaepO5lWjP 9Nfb/kvIyi6WRnPjVklazeqelbKTyVhrcYysHA== X-Received: by 2002:ac8:368a:: with SMTP id a10mr10808259qtc.143.1567097472930; Thu, 29 Aug 2019 09:51:12 -0700 (PDT) MIME-Version: 1.0 References: <20190829074603.70424-1-saravanak@google.com> <20190829074603.70424-3-saravanak@google.com> In-Reply-To: <20190829074603.70424-3-saravanak@google.com> From: Rob Herring Date: Thu, 29 Aug 2019 11:51:02 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v10 2/7] of: property: Add functional dependency link from DT bindings To: Saravana Kannan Cc: Mark Rutland , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , Jonathan Corbet , Len Brown , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , Linux Doc Mailing List , linux-acpi@vger.kernel.org, clang-built-linux , David Collins , Android Kernel Team , kbuild test robot Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 29, 2019 at 2:46 AM Saravana Kannan wrote: > > Add device links after the devices are created (but before they are > probed) by looking at common DT bindings like clocks and > interconnects. > > Automatically adding device links for functional dependencies at the > framework level provides the following benefits: > > - Optimizes device probe order and avoids the useless work of > attempting probes of devices that will not probe successfully > (because their suppliers aren't present or haven't probed yet). > > For example, in a commonly available mobile SoC, registering just > one consumer device's driver at an initcall level earlier than the > supplier device's driver causes 11 failed probe attempts before the > consumer device probes successfully. This was with a kernel with all > the drivers statically compiled in. This problem gets a lot worse if > all the drivers are loaded as modules without direct symbol > dependencies. > > - Supplier devices like clock providers, interconnect providers, etc > need to keep the resources they provide active and at a particular > state(s) during boot up even if their current set of consumers don't > request the resource to be active. This is because the rest of the > consumers might not have probed yet and turning off the resource > before all the consumers have probed could lead to a hang or > undesired user experience. > > Some frameworks (Eg: regulator) handle this today by turning off > "unused" resources at late_initcall_sync and hoping all the devices > have probed by then. This is not a valid assumption for systems with > loadable modules. Other frameworks (Eg: clock) just don't handle > this due to the lack of a clear signal for when they can turn off > resources. This leads to downstream hacks to handle cases like this > that can easily be solved in the upstream kernel. > > By linking devices before they are probed, we give suppliers a clear > count of the number of dependent consumers. Once all of the > consumers are active, the suppliers can turn off the unused > resources without making assumptions about the number of consumers. > > By default we just add device-links to track "driver presence" (probe > succeeded) of the supplier device. If any other functionality provided > by device-links are needed, it is left to the consumer/supplier > devices to change the link when they probe. > > kbuild test robot reported clang error about missing const > Reported-by: kbuild test robot > Signed-off-by: Saravana Kannan > --- > .../admin-guide/kernel-parameters.rst | 1 + > .../admin-guide/kernel-parameters.txt | 6 + > drivers/of/property.c | 241 ++++++++++++++++++ > 3 files changed, 248 insertions(+) > +static int of_link_to_phandle(struct device *dev, struct device_node *sup_np) > +{ > + struct platform_device *sup_dev; > + u32 dl_flags = DL_FLAG_AUTOPROBE_CONSUMER; > + int ret = 0; > + struct device_node *tmp_np = sup_np; > + > + of_node_get(sup_np); > + /* > + * Find the device node that contains the supplier phandle. It may be > + * @sup_np or it may be an ancestor of @sup_np. > + */ > + while (sup_np && !of_find_property(sup_np, "compatible", NULL)) > + sup_np = of_get_next_parent(sup_np); > + if (!sup_np) { > + dev_dbg(dev, "Not linking to %pOFP - No device\n", tmp_np); > + return -ENODEV; > + } > + > + /* > + * Don't allow linking a device node as a consumer of one of its > + * descendant nodes. By definition, a child node can't be a functional > + * dependency for the parent node. > + */ > + if (!of_is_ancestor_of(dev->of_node, sup_np)) { > + dev_dbg(dev, "Not linking to %pOFP - is descendant\n", sup_np); > + of_node_put(sup_np); > + return -EINVAL; > + } > + sup_dev = of_find_device_by_node(sup_np); What if the supplier isn't a platform_device? A regulator supply is quite likely not. Rob