Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4950786ybi; Sat, 20 Jul 2019 09:30:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzErUJOwVLUCDlbmjtZObi0AaZYBsaGDuCy4MSsVS9KYf1bHPsZm5ZoDiXDjyKBpmYtc4WR X-Received: by 2002:a63:6110:: with SMTP id v16mr14916067pgb.81.1563640254715; Sat, 20 Jul 2019 09:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563640254; cv=none; d=google.com; s=arc-20160816; b=Udq+KQngNlIX93CW2VGnrPRIPQ25BoRpHipuYH64s8uhI92WP5aJbLShIQtviOIy+a tLMhMC4HclN2nV8zaICLDJ+sxMSLlVuDDC5N41NwrMTdACC5UEUzcR/0l4fltVhDhIJW vB1qI5H2Zhrfnounqb2QcGGKEIZor1dk05528aaU9hVo74aT0W+c3vrp9gg3p4ucIOSu KNhpyh+BQVvFHiFYnaN1EhaWww23Bp3hqvSL1bn9hL8rh2cfkCAskEfbfiCioa3eOMwN q/FjspmMzBWaW6OqjCHNyaWUmImEytSpnMFBZsUoV+cXpLfdvODXMZY9B6pDNNQ6/JOj vWbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=czN7OgNyihOa9VdIP6ZEMSedIRrbUsmUmhpHuJJjXTo=; b=fqFhYuG+tc/jxeREqpblpys14CYXfd8SAfzEufcQro7Z29Z2I8LF+jGzNG2rMENqS6 beqZ/J/+IYnF4mNqtDZIdBOukXHnw9ARf12OvlzgnyDAiMLVK3CxES6GgnFaIClyGbqV sgaN8FVGuxHeUKCVIEIBLwD3wJz0Ew3u0+gwEqTGW26dH80T1ay8b6K3Ki+dRnbTa2DJ rKue4C6UyjKfsO7IuAMV7LcHsjfcTXh2AYMa4CV/OfTur5Ta/kd1WtUyPbzwdKWTlu3U 4zwwr764jbHY8HDhmc9cWpCKecGzXFKAxgFFezPuPbqctEVm3EC8t5S+Je8AUS60Y8rz FF7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JjeSiWUW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q18si3856736pll.79.2019.07.20.09.30.38; Sat, 20 Jul 2019 09:30:54 -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=@google.com header.s=20161025 header.b=JjeSiWUW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726442AbfGTGRR (ORCPT + 99 others); Sat, 20 Jul 2019 02:17:17 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:43452 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbfGTGRO (ORCPT ); Sat, 20 Jul 2019 02:17:14 -0400 Received: by mail-qk1-f202.google.com with SMTP id v4so28242926qkj.10 for ; Fri, 19 Jul 2019 23:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=czN7OgNyihOa9VdIP6ZEMSedIRrbUsmUmhpHuJJjXTo=; b=JjeSiWUWj0/rue13YU+ELAHX6hLfpI4PJnFZ3Q3aZh5PTfek/rlsbRkh9vntEdz3pc RVJXwy8Z/Eq5iaSAz00CO7t/AzU/8PBLyovCjFnjha9Q3UbeEUv8jNIVllc5UZDvQbu6 iz5YOIH9wo86uj6dUCcIKZv9wTyW4SpxKEYiPy34pOz7dy3/Aax9RQLXEFYjhITigF2y eVurdpmIiZe3KXQMcoyvXqVq8XJ9iVAm7XR4T+aZ1r/sN4eIAhud6GkZvhQFh7732JAZ DKrXi6HKEMhxT1OhGFzJq1scn0ol5E0tdLDkd88gWhZ9U0UH1LCxNybbbYW0T3oWHtCq MTJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=czN7OgNyihOa9VdIP6ZEMSedIRrbUsmUmhpHuJJjXTo=; b=ZRfGEIUFV4eU/cNeyTePZjUzDgrJOxYnVlqsEvNvxRoc1HSFaXNO7Fc9ahXgnepKz8 5YXjbPXArnLfueifJ6TmJXSrYmiCtaINO7B0Jbyn9j1P6gZatz9U5DqXpdFXo+uqBgMH 5jJmYeeELAQBy90K66XufFAnai62CnS98DjEmC+a5A4jVscCo4Osf/JUt41ZQRhm9gdm vD6JIu6xl81/IeApBwUaTGtdqIlITQWEYJm9pNVUFn7vUSRYG11uyhMBkZUabFeu5CI2 iBEXt6Xcg7omGyko9ptr93pm37+Cwohq6YEEPikbc0QGuHFAyg+s5RVQFsaWvroAvVQp iM+g== X-Gm-Message-State: APjAAAXulADW1MOeKsyKSVCYmUyDjhoNubhpiCHF06525Z0LIbEtSdTO 36QuJFc/A42BlyzvHR++j5jtrD9S5THwXV4= X-Received: by 2002:a37:7ec1:: with SMTP id z184mr38505880qkc.491.1563603433832; Fri, 19 Jul 2019 23:17:13 -0700 (PDT) Date: Fri, 19 Jul 2019 23:16:45 -0700 In-Reply-To: <20190720061647.234852-1-saravanak@google.com> Message-Id: <20190720061647.234852-7-saravanak@google.com> Mime-Version: 1.0 References: <20190720061647.234852-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH v6 6/7] of/platform: Create device links for all child-supplier depencencies From: Saravana Kannan To: Rob Herring , Mark Rutland , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand Cc: Saravana Kannan , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Collins , kernel-team@android.com 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 A parent device can have child devices that it adds when it probes. But this probing of the parent device can happen way after kernel init is done -- for example, when the parent device's driver is loaded as a module. In such cases, if the child devices depend on a supplier in the system, we need to make sure the supplier gets the sync_state() callback only after these child devices are added and probed. To achieve this, when creating device links for a device by looking at its DT node, don't just look at DT references at the top node level. Look at DT references in all the descendant nodes too and create device links from the ancestor device to all these supplier devices. This way, when the parent device probes and adds child devices, the child devices can then create their own device links to the suppliers and further delay the supplier's sync_state() callback to after the child devices are probed. Example: In this illustration, -> denotes DT references and indentation represents child status. Device node A Device node B -> D Device node C -> B, D Device node D Assume all these devices have their drivers loaded as modules. Without this patch, this is the sequence of events: 1. D is added. 2. A is added. 3. Device D probes. 4. Device D gets its sync_state() callback. 5. Device B and C might malfunction because their resources got altered/turned off before they can make active requests for them. With this patch, this is the sequence of events: 1. D is added. 2. A is added and creates device links to D. 3. Device link from A to B is not added because A is a parent of B. 4. Device D probes. 5. Device D does not get it's sync_state() callback because consumer A hasn't probed yet. 5. Device A probes. 5. a. Devices B and C are added. 5. b. Device links from B and C to D are added. 5. c. Device A's probe completes. 6. Device D does not get it's sync_state() callback because consumer A has probed but consumers B and C haven't probed yet. 7. Device B and C probe. 8. Device D gets it's sync_state() callback because all its consumers have probed. 9. None of the devices malfunction. Signed-off-by: Saravana Kannan --- drivers/of/platform.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index d0c2f6443247..c1a116f7a087 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -649,24 +649,35 @@ static bool of_link_property(struct device *dev, struct device_node *con_np, return done ? 0 : -ENODEV; } +static int __of_link_to_suppliers(struct device *dev, + struct device_node *con_np) +{ + struct device_node *child; + struct property *p; + bool done = true; + + for_each_property_of_node(con_np, p) + if (of_link_property(dev, con_np, p->name)) + done = false; + + for_each_child_of_node(con_np, child) + if (__of_link_to_suppliers(dev, child)) + done = false; + + return done ? 0 : -ENODEV; +} + static bool of_devlink; core_param(of_devlink, of_devlink, bool, 0); static int of_link_to_suppliers(struct device *dev) { - struct property *p; - bool done = true; - if (!of_devlink) return 0; if (unlikely(!dev->of_node)) return 0; - for_each_property_of_node(dev->of_node, p) - if (of_link_property(dev, dev->of_node, p->name)) - done = false; - - return done ? 0 : -ENODEV; + return __of_link_to_suppliers(dev, dev->of_node); } #ifndef CONFIG_PPC -- 2.22.0.657.g960e92d24f-goog