From patchwork Fri Jul 12 23:52:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131535 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="jn0odGG/"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqVw1dlmz9sNk for ; Sat, 13 Jul 2019 09:53:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728551AbfGLXw5 (ORCPT ); Fri, 12 Jul 2019 19:52:57 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:37033 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727708AbfGLXw4 (ORCPT ); Fri, 12 Jul 2019 19:52:56 -0400 Received: by mail-pf1-f201.google.com with SMTP id x18so6455228pfj.4 for ; Fri, 12 Jul 2019 16:52:56 -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=eaQJVzKVYitsX+nBcXNXCgca4tYNoR3mi+s/+unfQdQ=; b=jn0odGG/oFt0js4DkYxZzkmmn6cZzljmylWA0Mx4zBCxeTFHUyc0WyKdJjFGAQ5q+G vr7sEMJJnVEK0J0cRgr+HDfLDKIGLg/C4Ve5+RY76PBISpPI/PEUE94cwuWBNwDCg4bf 7dqQq6QfLYzuoFW1POXgFCuqwLBUiCkcLgf4fCZD0fOwhJx86tHh6Fjegunp+aIgERgF v869pQE2pDVdGwMXCqrXw0+BKE3KT3numFnjyH9wtQzzPHP8/5KQ8pnD4FatNjPRkqIq 1/JqhH9Qs0ms0eeLTMxfhaoJUuKUZFhimZ7I5g6SjvrjLMB1vT7LSE0TwLLmITxQzXrm GwDQ== 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=eaQJVzKVYitsX+nBcXNXCgca4tYNoR3mi+s/+unfQdQ=; b=MDITsb4v6fyVKQfVPcDz/XvGeqUZ/IZtI7r1rLUQrQlOaDGZZYJe/WUs4TwL7Mt8UA rou+OvZsfs1AIVT+qzY7RQOiY0N8avmHWWyUXw/osT8XqKsGNLbNOOZxP285u+lWlASm Dxrinia6j5f2l6hAiImZVu5IjC1MNUvpb8cDwtVAhGUk2P1QLjbKwt2Oq71wOsyJKZmR iAWanZXaTvg+o7gfOcZaFS7O2eJucAhRaBjRvP/HGbejxKnPU/tKp2xE7uJ9cdqqc7q+ kAan9yhRuSxtU2O0L3MxwevX13NgicrMrBo7WZfwHXTqZSW/urO9b/RiRCUnRwbWhit1 GN4Q== X-Gm-Message-State: APjAAAWFFPONx1ayD0KtKr2XW17CMiMGe2OOlfHPl3k9OtP8TpIRAMpl S/vF6MXaCrQqYzr6i5yLqoipztVW0gm7jJM= X-Google-Smtp-Source: APXvYqzcXhm6MzlfeEhmVbdJbUNlik4cYgtPgDKR9xS8FKJtjyANKiCJSi1hR/+Yc/CQmA+WYZUOX2t9DTqHx3Q= X-Received: by 2002:a63:1e0b:: with SMTP id e11mr13111041pge.402.1562975575788; Fri, 12 Jul 2019 16:52:55 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:35 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-3-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 02/11] of/platform: Add functional dependency link from DT bindings From: Saravana Kannan To: Rob Herring , Mark Rutland , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , Jonathan Corbet Cc: Saravana Kannan , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, David Collins , kernel-team@android.com, linux-doc@vger.kernel.org Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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. Signed-off-by: Saravana Kannan --- .../admin-guide/kernel-parameters.txt | 5 ++ drivers/of/platform.c | 57 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 138f6664b2e2..109b4310844f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3141,6 +3141,11 @@ This can be set from sysctl after boot. See Documentation/sysctl/vm.txt for details. + of_devlink [KNL] Make device links from common DT bindings. Useful + for optimizing probe order and making sure resources + aren't turned off before the consumer devices have + probed. + ohci1394_dma=early [HW] enable debugging via the ohci1394 driver. See Documentation/debugging-via-ohci1394.txt for more info. diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 04ad312fd85b..0930f9f89571 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -509,6 +509,62 @@ int of_platform_default_populate(struct device_node *root, } EXPORT_SYMBOL_GPL(of_platform_default_populate); +static int of_link_binding(struct device *dev, + const char *binding, const char *cell) +{ + struct of_phandle_args sup_args; + struct platform_device *sup_dev; + unsigned int i = 0, links = 0; + u32 dl_flags = DL_FLAG_AUTOPROBE_CONSUMER; + + while (!of_parse_phandle_with_args(dev->of_node, binding, cell, i, + &sup_args)) { + i++; + sup_dev = of_find_device_by_node(sup_args.np); + of_node_put(sup_args.np); + if (!sup_dev) + continue; + if (device_link_add(dev, &sup_dev->dev, dl_flags)) + links++; + put_device(&sup_dev->dev); + } + if (links < i) + return -ENODEV; + return 0; +} + +static bool of_devlink; +core_param(of_devlink, of_devlink, bool, 0); + +/* + * List of bindings and their cell names (use NULL if no cell names) from which + * device links need to be created. + */ +static const char * const link_bindings[] = { + "clocks", "#clock-cells", + "interconnects", "#interconnect-cells", +}; + +static int of_link_to_suppliers(struct device *dev) +{ + unsigned int i = 0; + bool done = true; + + if (!of_devlink) + return 0; + if (unlikely(!dev->of_node)) + return 0; + + for (i = 0; i < ARRAY_SIZE(link_bindings) / 2; i++) + if (of_link_binding(dev, link_bindings[i * 2], + link_bindings[i * 2 + 1])) + done = false; + + if (!done) + return -ENODEV; + return 0; +} + #ifndef CONFIG_PPC static const struct of_device_id reserved_mem_matches[] = { { .compatible = "qcom,rmtfs-mem" }, @@ -524,6 +580,7 @@ static int __init of_platform_default_populate_init(void) if (!of_have_populated_dt()) return -ENODEV; + platform_bus_type.add_links = of_link_to_suppliers; /* * Handle certain compatibles explicitly, since we don't want to create * platform_devices for every node in /reserved-memory with a From patchwork Fri Jul 12 23:52:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131536 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="NZCr2g6j"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqVw5bnMz9sNq for ; Sat, 13 Jul 2019 09:53:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728549AbfGLXxA (ORCPT ); Fri, 12 Jul 2019 19:53:00 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:45240 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728569AbfGLXw7 (ORCPT ); Fri, 12 Jul 2019 19:52:59 -0400 Received: by mail-pg1-f202.google.com with SMTP id n7so6613928pgr.12 for ; Fri, 12 Jul 2019 16:52:59 -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=1hfAR7BJm0sl3XPWVF757MMKVHLS5GkBR3sqRxDFXmo=; b=NZCr2g6j2XTVkDM8sddBX9CA+DZ+f7VYb+AfIh7DRGhfxple/RYPVAvjuZaD9ct75F +/nD5txyHUGrW6AH7QzN0Yd5ZRYeOEbPWMQ2q79jGdyIHcFgmC482AI7pTVC/gJmh+AL Xyu4rt5d1voQ6EmaVCdGLJrca/EUrKX/naRxLX1fw90dUnZQdR3s0YBzpbHOdyZT/ShG JPyrQHtvyAEHYHrqn2SusHz8TuwVS7ZBrgzAiB7fUv4lDOaW9EpLvx/B1rulgpqZw9kw XSwxzsEvOh2AJf4CvEEdp3GECtkOn+mK80Pamo4lug5whKHoFCXRv1we+cxURpsN4Hdk fXWw== 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=1hfAR7BJm0sl3XPWVF757MMKVHLS5GkBR3sqRxDFXmo=; b=ud54m6XWFQgQNsIvJmXLyMxf/DNE+IZduLIruI0GiSQH9aOEVuLX2/h0ppfxX1yz0G oB2heZNhbJ4ZK8uRFHKSarMabaKhx8P0m07cGB2NeNtSkRx2Km+MttsNxOmmb0atDU27 V/jv2EHtSuFWjFjUIONXDlNS+GjTF6puqKDuRZPv91Mo0osyzfWSIZIbC8JRk47hkalu zPtidSgwd1l6+6OMOoQNWQtESeFyDsxPdzTC3sAFww++lmCBO4v4KcXq6cjnEDqtvaI7 iUW9JOnbQm8THdcrVz5i2snK7nlcx1GPs8CLbv3+eqLngEPSzH4za0Fyv27/kV5pL6we 0Tgw== X-Gm-Message-State: APjAAAW/ZNPqN+p9myhdW1CLosFNzkI+mQM5kyffPXO1AMyjZEUUzmnk Dz1cR2yGNQalz8kSTRb7FiglT7ZXVs0BdL4= X-Google-Smtp-Source: APXvYqyn05EQCLzIXw17cC7j+//sPfbdO/T5uCdhNZS/3v31ukGZAoMdQAI2fvB/ZGSY0BPYyNyCugk1o+yR52I= X-Received: by 2002:a63:d950:: with SMTP id e16mr14668466pgj.271.1562975578822; Fri, 12 Jul 2019 16:52:58 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:36 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-4-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 03/11] driver core: Add sync_state driver/bus callback 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This sync_state driver/bus callback is called once all the consumers of a supplier have probed successfully. This allows the supplier device's driver/bus to sync the supplier device's state to the software state with the guarantee that all the consumers are actively managing the resources provided by the supplier device. To maintain backwards compatibility and ease transition from existing frameworks and resource cleanup schemes, late_initcall_sync is the earliest when the sync_state callback might be called. There is no upper bound on the time by which the sync_state callback has to be called. This is because if a consumer device never probes, the supplier has to maintain its resources in the state left by the bootloader. For example, if the bootloader leaves the display backlight at a fixed voltage and the backlight driver is never probed, you don't want the backlight to ever be turned off after boot up. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 39 +++++++++++++++++++++++++++++++++++++++ drivers/of/platform.c | 9 +++++++++ include/linux/device.h | 19 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 0705926d362f..8b8b812d26f1 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -46,6 +46,7 @@ early_param("sysfs.deprecated", sysfs_deprecated_setup); /* Device links support. */ static LIST_HEAD(wait_for_suppliers); static DEFINE_MUTEX(wfs_lock); +static bool supplier_sync_state_enabled; #ifdef CONFIG_SRCU static DEFINE_MUTEX(device_links_lock); @@ -614,6 +615,41 @@ int device_links_check_suppliers(struct device *dev) return ret; } +static void __device_links_supplier_sync_state(struct device *dev) +{ + struct device_link *link; + + if (dev->state_synced) + return; + + list_for_each_entry(link, &dev->links.consumers, s_node) { + if (link->flags & DL_FLAG_STATELESS) + continue; + if (link->status != DL_STATE_ACTIVE) + return; + } + + if (dev->bus->sync_state) + dev->bus->sync_state(dev); + else if (dev->driver && dev->driver->sync_state) + dev->driver->sync_state(dev); + + dev->state_synced = true; +} + +int device_links_supplier_sync_state(struct device *dev, void *data) +{ + device_links_write_lock(); + __device_links_supplier_sync_state(dev); + device_links_write_unlock(); + return 0; +} + +void device_links_supplier_sync_state_enable(void) +{ + supplier_sync_state_enabled = true; +} + /** * device_links_driver_bound - Update device links after probing its driver. * @dev: Device to update the links for. @@ -658,6 +694,9 @@ void device_links_driver_bound(struct device *dev) WARN_ON(link->status != DL_STATE_CONSUMER_PROBE); WRITE_ONCE(link->status, DL_STATE_ACTIVE); + + if (supplier_sync_state_enabled) + __device_links_supplier_sync_state(link->supplier); } dev->links.status = DL_DEV_DRIVER_BOUND; diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 0930f9f89571..4d12d6658999 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -601,6 +601,15 @@ static int __init of_platform_default_populate_init(void) return 0; } arch_initcall_sync(of_platform_default_populate_init); + +static int __init of_platform_sync_state_init(void) +{ + device_links_supplier_sync_state_enable(); + bus_for_each_dev(&platform_bus_type, NULL, NULL, + device_links_supplier_sync_state); + return 0; +} +late_initcall_sync(of_platform_sync_state_init); #endif int of_platform_device_destroy(struct device *dev, void *data) diff --git a/include/linux/device.h b/include/linux/device.h index 7f8ae7e5fc6b..4a0db34ae650 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -84,6 +84,13 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * in the future. * @probe: Called when a new device or driver add to this bus, and callback * the specific driver's probe to initial the matched device. + * @sync_state: Called to sync device state to software state after all the + * state tracking consumers linked to this device (present at + * the time of late_initcall) have successfully bound to a + * driver. If the device has no consumers, this function will + * be called at late_initcall_sync level. If the device has + * consumers that are never bound to a driver, this function + * will never get called until they do. * @remove: Called when a device removed from this bus. * @shutdown: Called at shut-down time to quiesce the device. * @@ -128,6 +135,7 @@ struct bus_type { int (*uevent)(struct device *dev, struct kobj_uevent_env *env); int (*add_links)(struct device *dev); int (*probe)(struct device *dev); + void (*sync_state)(struct device *dev); int (*remove)(struct device *dev); void (*shutdown)(struct device *dev); @@ -257,6 +265,13 @@ enum probe_type { * @probe: Called to query the existence of a specific device, * whether this driver can work with it, and bind the driver * to a specific device. + * @sync_state: Called to sync device state to software state after all the + * state tracking consumers linked to this device (present at + * the time of late_initcall) have successfully bound to a + * driver. If the device has no consumers, this function will + * be called at late_initcall_sync level. If the device has + * consumers that are never bound to a driver, this function + * will never get called until they do. * @remove: Called when the device is removed from the system to * unbind a device from this driver. * @shutdown: Called at shut-down time to quiesce the device. @@ -294,6 +309,7 @@ struct device_driver { const struct acpi_device_id *acpi_match_table; int (*probe) (struct device *dev); + void (*sync_state)(struct device *dev); int (*remove) (struct device *dev); void (*shutdown) (struct device *dev); int (*suspend) (struct device *dev, pm_message_t state); @@ -1065,6 +1081,7 @@ struct device { bool offline_disabled:1; bool offline:1; bool of_node_reused:1; + bool state_synced:1; #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) @@ -1404,6 +1421,8 @@ struct device_link *device_link_add(struct device *consumer, struct device *supplier, u32 flags); void device_link_del(struct device_link *link); void device_link_remove(void *consumer, struct device *supplier); +int device_links_supplier_sync_state(struct device *dev, void *data); +void device_links_supplier_sync_state_enable(void); #ifndef dev_fmt #define dev_fmt(fmt) fmt From patchwork Fri Jul 12 23:52:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131543 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="tXcvXIe2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqWY1lLrz9s8m for ; Sat, 13 Jul 2019 09:53:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728618AbfGLXxG (ORCPT ); Fri, 12 Jul 2019 19:53:06 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:51740 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbfGLXxG (ORCPT ); Fri, 12 Jul 2019 19:53:06 -0400 Received: by mail-pl1-f202.google.com with SMTP id d2so6001663pla.18 for ; Fri, 12 Jul 2019 16:53:06 -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=ZEVp2FCp1m5Avn1zvXLMIQboGrgTrI7qvc1ZsTzxPVA=; b=tXcvXIe2kvoVcWyV5vJrUI4NMxZlZITLOAHkR4m+X9tLPBSzepy2Aq5Q8ocCI7fFlf BzKkEyLxc4iQCMI4yCAFnxW4hcjXoyF13oiKC0o0TRiCpRRz02ZH49phlN5qe6/hd4N5 KFcoLLue5fa+qjsOhJplb8wGSthDc13X3r4sPHb+Z4I79Tthi7KDw5GQPewK95komqvF 5cH6Yaxt4i8m4xXrHoZNP0okWhLR5J0EVRhdSeIGWLLMNDZPaURTa30cTfIVFD4aDGGH CaPOrWn6sqmgmCnYOniac8jrO2BQ+H0dwMEukI+RaPOvjBXTL3hfFagsUa9yH3gJHV1P tMYw== 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=ZEVp2FCp1m5Avn1zvXLMIQboGrgTrI7qvc1ZsTzxPVA=; b=czg7V14gpgHx+XIHCKwrVtBF8W0VIO2A0oCct1AbU1QBZL/Uko0/2/NoXKv4wVM6gG dfSbsFrFTfVtMmpg7Cc1BvrFOOzYb0EJZBbuEdkUbTUE1h/m0bAMGcoXR5OxFcpPsBPB sVZZXWjEtQCvDOyYdrV7F1n7tLXQHp7+JuZdPtxFQg3tpG1JZxGLRuEYaBQ71tmArhTb Buqikt99J11q6qKGrNRxv3Gz1+ioMLf0V/KsBp+AwbpunHUSLhZLBq5I5KYXOMUg/fmD 1bumF4h6QaWNUchZBBdX7JHPQGem5MQA5zqnXp1kJ2C88HhnWDYpAX6+uWO/8kjuWGQl ihfg== X-Gm-Message-State: APjAAAU4+fBAg3Y8MjO1EGQ0FwhN2jdPtVeYzYCFbAmqS8iT/O45Fcmq AnOCLYhXNsyoHTRohPRKUjJdPwAfTD+MnEM= X-Google-Smtp-Source: APXvYqwE93haDcWZIlE2uV9aKH/dihxMkEOtWldOKrJoEgGLHZA+61FZ6MoYEiiGgPqIAnMgMdh/D+ehB20Y96o= X-Received: by 2002:a63:4612:: with SMTP id t18mr5009360pga.85.1562975585221; Fri, 12 Jul 2019 16:53:05 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:38 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-6-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 05/11] driver core: Add APIs to pause/resume sync state callbacks 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org When multiple devices are added after kernel init, some suppliers could be added before their consumer devices get added. In these instances, the supplier devices could get their sync_state callback called right after they probe because the consumers haven't had a chance to create device links to the suppliers. This change adds APIs to pause/resume sync state callbacks so that when multiple devices are added, their sync_state callback evaluation can be postponed to happen after all of them are added. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 40 +++++++++++++++++++++++++++++++++------- drivers/of/platform.c | 5 ++--- include/linux/device.h | 6 ++++-- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index dce97b5f3536..b03e679faea4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -46,7 +46,8 @@ early_param("sysfs.deprecated", sysfs_deprecated_setup); /* Device links support. */ static LIST_HEAD(wait_for_suppliers); static DEFINE_MUTEX(wfs_lock); -static bool supplier_sync_state_enabled; +static LIST_HEAD(deferred_sync); +static unsigned int supplier_sync_state_disabled; #ifdef CONFIG_SRCU static DEFINE_MUTEX(device_links_lock); @@ -657,17 +658,38 @@ static void __device_links_supplier_sync_state(struct device *dev) dev->state_synced = true; } -int device_links_supplier_sync_state(struct device *dev, void *data) +void device_links_supplier_sync_state_pause(void) { device_links_write_lock(); - __device_links_supplier_sync_state(dev); + supplier_sync_state_disabled++; device_links_write_unlock(); - return 0; } -void device_links_supplier_sync_state_enable(void) +void device_links_supplier_sync_state_resume(void) { - supplier_sync_state_enabled = true; + struct device *dev, *tmp; + + device_links_write_lock(); + if (!supplier_sync_state_disabled) { + WARN(true, "Unmatched sync_state pause/resume!"); + goto out; + } + supplier_sync_state_disabled--; + if (supplier_sync_state_disabled) + goto out; + + list_for_each_entry_safe(dev, tmp, &deferred_sync, links.defer_sync) { + __device_links_supplier_sync_state(dev); + list_del_init(&dev->links.defer_sync); + } +out: + device_links_write_unlock(); +} + +static void __device_links_supplier_defer_sync(struct device *sup) +{ + if (list_empty(&sup->links.defer_sync)) + list_add_tail(&sup->links.defer_sync, &deferred_sync); } /** @@ -715,7 +737,9 @@ void device_links_driver_bound(struct device *dev) WARN_ON(link->status != DL_STATE_CONSUMER_PROBE); WRITE_ONCE(link->status, DL_STATE_ACTIVE); - if (supplier_sync_state_enabled) + if (supplier_sync_state_disabled) + __device_links_supplier_defer_sync(link->supplier); + else __device_links_supplier_sync_state(link->supplier); } @@ -826,6 +850,7 @@ void device_links_driver_cleanup(struct device *dev) WRITE_ONCE(link->status, DL_STATE_DORMANT); } + list_del_init(&dev->links.defer_sync); __device_links_no_driver(dev); device_links_write_unlock(); @@ -1797,6 +1822,7 @@ void device_initialize(struct device *dev) INIT_LIST_HEAD(&dev->links.consumers); INIT_LIST_HEAD(&dev->links.suppliers); INIT_LIST_HEAD(&dev->links.needs_suppliers); + INIT_LIST_HEAD(&dev->links.defer_sync); dev->links.status = DL_DEV_NO_DRIVER; } EXPORT_SYMBOL_GPL(device_initialize); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 4d12d6658999..56b718f09929 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -581,6 +581,7 @@ static int __init of_platform_default_populate_init(void) return -ENODEV; platform_bus_type.add_links = of_link_to_suppliers; + device_links_supplier_sync_state_pause(); /* * Handle certain compatibles explicitly, since we don't want to create * platform_devices for every node in /reserved-memory with a @@ -604,9 +605,7 @@ arch_initcall_sync(of_platform_default_populate_init); static int __init of_platform_sync_state_init(void) { - device_links_supplier_sync_state_enable(); - bus_for_each_dev(&platform_bus_type, NULL, NULL, - device_links_supplier_sync_state); + device_links_supplier_sync_state_resume(); return 0; } late_initcall_sync(of_platform_sync_state_init); diff --git a/include/linux/device.h b/include/linux/device.h index d3c9e70052d8..0ea28cb8c77e 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -926,12 +926,14 @@ enum dl_dev_state { * @suppliers: List of links to supplier devices. * @consumers: List of links to consumer devices. * @needs_suppliers: Hook to global list of devices waiting for suppliers. + * @defer_sync: Hook to global list of devices that have deferred sync_state. * @status: Driver status information. */ struct dev_links_info { struct list_head suppliers; struct list_head consumers; struct list_head needs_suppliers; + struct list_head defer_sync; enum dl_dev_state status; }; @@ -1438,8 +1440,8 @@ struct device_link *device_link_add(struct device *consumer, struct device *supplier, u32 flags); void device_link_del(struct device_link *link); void device_link_remove(void *consumer, struct device *supplier); -int device_links_supplier_sync_state(struct device *dev, void *data); -void device_links_supplier_sync_state_enable(void); +void device_links_supplier_sync_state_pause(void); +void device_links_supplier_sync_state_resume(void); void device_link_remove_from_wfs(struct device *consumer); #ifndef dev_fmt From patchwork Fri Jul 12 23:52:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131537 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="vBSRrli9"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqVx2m5Rz9sNk for ; Sat, 13 Jul 2019 09:53:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728639AbfGLXxK (ORCPT ); Fri, 12 Jul 2019 19:53:10 -0400 Received: from mail-vk1-f202.google.com ([209.85.221.202]:53575 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728631AbfGLXxJ (ORCPT ); Fri, 12 Jul 2019 19:53:09 -0400 Received: by mail-vk1-f202.google.com with SMTP id v126so4675505vkv.20 for ; Fri, 12 Jul 2019 16:53:09 -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=CAlHJy5+PE+GUC+yGE/HoGyC126T/YkJLT0emjsVwvg=; b=vBSRrli97XKmYjaFIGkTrcpCdCNGuE+h8IhFrSjimPFbqLeAsD6MGB4jNFhsSO9U16 aO7Hsb3DRlpZOw7nW7ieuCskwIYYeq4G9U9Dc4U6kCs6M4zxBv4owXK9H/L870Onwxyf Eb1rfA+W2CsEK33teA2bvZH4zYIXX4TxdFtbSRVakoxy1siyL2ZEMCCh4Dj5ajB3Z1DW Knm77sDEisIgodbyts3qx9jkiRdo4T2aotiJnFF5XbFfJnCtGYjsLoJh5/v4zTZFQZIf 4qDSWvdPfYiUQj6h9dF5/U8AA1a8iBbFTjoB0iGNbPtwSHYVIVJNarpjiaR8y3iHb3t2 IOWQ== 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=CAlHJy5+PE+GUC+yGE/HoGyC126T/YkJLT0emjsVwvg=; b=j1IDyennnbjcfWxqkE+zNc7etsNnlC3gebB6CPWGrBtGF/ZN6xQHDPckmBAGCHQDrZ CaZ6hjMjPBQ7UGQN7qC9u055/bq++oU3Sc1k2m8+0JPfetAxHG/klcRNAziGLJBLCkc7 QVfMc2p29ebt6oSPiWtVoTUaJ/zwm4TVeBaLWOAip1+tBQvDBQlsSMsXFGWFehdeInlK rb8YB87mzBH08NeNVWhTHw26ebygvrfo8YCsh+lRLCM8J1NYqn53kkhCGUHz00uhu7LZ Mr1GrkWFKAeADGXm9OnSz0qRPfa5pyRSoAANL2aq83BWgCeyjaiuD27FXTF4L7ehVd7W K0SQ== X-Gm-Message-State: APjAAAW3OlQC/43sz6VRgVR7i7cZi4aoZKb+vpIyyYXoJF9evcWMn41y j2Wm0jrEHrxy0JQ/7geJMmdh4mA/BF8HS3I= X-Google-Smtp-Source: APXvYqzwP48zLLPRZS7QmxTr3oncKEyLjcgCl8Hybw1d/cNDtpOqX9dKb2Tc4NdPmWjX/kIB8o1avR2Bs7ubFXg= X-Received: by 2002:ab0:2556:: with SMTP id l22mr10397175uan.46.1562975588442; Fri, 12 Jul 2019 16:53:08 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:39 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-7-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 06/11] of/platform: Pause/resume sync state in of_platform_populate() 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org When multiple child devices are populated using of_platform_populate() after kernel init, there could be supplier-consumer dependencies between the child devices. Wait for all the devices to be added and linked before calling sync_state() on all the suppliers. Signed-off-by: Saravana Kannan --- drivers/of/platform.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 56b718f09929..dba962a0ee50 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -486,6 +486,7 @@ int of_platform_populate(struct device_node *root, pr_debug("%s()\n", __func__); pr_debug(" starting at: %pOF\n", root); + device_links_supplier_sync_state_pause(); for_each_child_of_node(root, child) { rc = of_platform_bus_create(child, matches, lookup, parent, true); if (rc) { @@ -493,6 +494,8 @@ int of_platform_populate(struct device_node *root, break; } } + device_links_supplier_sync_state_resume(); + of_node_set_flag(root, OF_POPULATED_BUS); of_node_put(root); From patchwork Fri Jul 12 23:52:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131542 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="NuFa6cXO"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqWV5YkQz9sNm for ; Sat, 13 Jul 2019 09:53:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727226AbfGLXxh (ORCPT ); Fri, 12 Jul 2019 19:53:37 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:41839 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728650AbfGLXxM (ORCPT ); Fri, 12 Jul 2019 19:53:12 -0400 Received: by mail-pl1-f202.google.com with SMTP id i3so6011452plb.8 for ; Fri, 12 Jul 2019 16:53:11 -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=u0aCbzfqst+D0QpebqfgPDDHqeCzNETI6rpepbYOqAg=; b=NuFa6cXOZ03xsdBH/ZfK+iY9xs3bPy/PkCnlYauhFuo7hp8ItcNakBHm6+e4a6FW2/ Qy9eIPHN9QVYImgGz3vPgOgEL1Rh9APmS9LNzfVQyfr6nhAZXkcaPKv770hkuZ4I7FQo mPmItCpQQAy5CB2VrS/cMO2g4JsLM8S1emnd+9zU3+Xe0k044I2r6InPphZxx4momvaj 7uKzqvPnB8g0uXab+/biy4Ex+MSTlHVndbwTeKi+rsrxW1L6kkIj29IQXCIfhS160bMb o/0MTn6NSnijj7JgBcEIScY75jodS+cD0NP6BucvNliohtB+o9sS3ZOoYnFmDXIwDtgE sliw== 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=u0aCbzfqst+D0QpebqfgPDDHqeCzNETI6rpepbYOqAg=; b=grmDoGJFqIwSUFHI7t5iShVmuPMpTWOeop/OjGibQ2gvlA/bsidqraWcs4r0pZQiOS EZs8CfQmjYqAiT13ssgxPqEjSDIr/VgMt+FHXeI63umt/c98sHwoQvbBu5mrsRSdGMe+ 6EdhjZPyqoGV1O47+T+V/MREEz/lw/j6aphXCM5U7liahc3dxByMlcUO9POVoRhIpZCk UgDzumdUihz+AVz94RYXSGUdiU+RZbnxfDQOMMVIUKfhyKBhbP5XnpmVnkY1IMmeS7c5 4lT9pkZRa0qhYIbA4MINPfIdqbrEpUnfk1voCazzMfgr4B/55cJJWPDSTIibOxXdez6n 8ACA== X-Gm-Message-State: APjAAAXq2YxQYjBWRI3YuGfD81N3r7FxYV5w+CVL9HSdU/00jki87wE0 usljOBedNBC1Rgy5r77EvBadWBvT5ix4XH8= X-Google-Smtp-Source: APXvYqyWvabAfyxvg6UIJqiHNYu3Re+Ps/dXojaoKmsWOUDI0X+STCObr0nnDdxk3G7ga5ZyPciHY8ModRXmB94= X-Received: by 2002:a63:e90b:: with SMTP id i11mr14217259pgh.351.1562975591373; Fri, 12 Jul 2019 16:53:11 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:40 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-8-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 07/11] of/platform: Sanity check DT bindings before creating device links 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org If a common DT binding is pointing to a child DT node of a particular parent DT node, don't add device links for such DT references. This is because, by definition, a child node can't be a functional dependency for the parent node. Signed-off-by: Saravana Kannan --- drivers/of/platform.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index dba962a0ee50..98414ba53b1f 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -512,6 +512,19 @@ int of_platform_default_populate(struct device_node *root, } EXPORT_SYMBOL_GPL(of_platform_default_populate); +bool of_link_is_valid(struct device_node *con, struct device_node *sup) +{ + of_node_get(sup); + while (sup) { + if (sup == con) { + of_node_put(sup); + return false; + } + sup = of_get_next_parent(sup); + } + return true; +} + static int of_link_binding(struct device *dev, const char *binding, const char *cell) { @@ -522,6 +535,10 @@ static int of_link_binding(struct device *dev, while (!of_parse_phandle_with_args(dev->of_node, binding, cell, i, &sup_args)) { + if (!of_link_is_valid(dev->of_node, sup_args.np)) { + of_node_put(sup_args.np); + continue; + } i++; sup_dev = of_find_device_by_node(sup_args.np); of_node_put(sup_args.np); From patchwork Fri Jul 12 23:52:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131541 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="wLKRVzok"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqWN2J6Tz9sNx for ; Sat, 13 Jul 2019 09:53:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728671AbfGLXxP (ORCPT ); Fri, 12 Jul 2019 19:53:15 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:45108 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728666AbfGLXxP (ORCPT ); Fri, 12 Jul 2019 19:53:15 -0400 Received: by mail-pf1-f202.google.com with SMTP id i27so6461373pfk.12 for ; Fri, 12 Jul 2019 16:53:15 -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=tt/DTeQs0nvo9WoetVmfSZpmCFMdgz1aG+kJun8yGvM=; b=wLKRVzokAdZ+sOZ0EVqWDmF2WSFfl0Zd8n3dg5gXkMxXk/VYBMY8xoip1vQBsOqGK1 L3tmmFkecXTHq2Cj/pVkI19ndx+Bm3ubtU6NNRwx0F/GMZhL2N41YsAXN7ZKdLJwRO1D frvCfjf0kwJzgFMVwxW8/7IeeBlYXuvPdavLaEooB2dcPkg3UJqNc/T8rrimZncvq48r Rd+wBiVcfOQGrmjhOZkYjXnDgZxH1OnUOiUkm+bLKE8ts4ANN8bIkYfW/N4mmvzdh1p3 OikGbOms/olMsbXXw6IURWCCqsY3Ycth21WtvF+YGiZ7aV56f9f2tj11s7FJf3gFMxaz gDWA== 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=tt/DTeQs0nvo9WoetVmfSZpmCFMdgz1aG+kJun8yGvM=; b=O46/v8mklbqaKZyzBM/Dtk0M1i/NDfHbHIChTvN3d4tbxix8QmjATYjr0VQcAVS4DO iKEmSWBMgXbolENfzruefydrTfeQw5+zexH96e++tgHG4PSNVCz2wZhr0x7X8VEIiemL Hj+F+zsTYn5/BqR65hEzki6j3rfNxCV2X94L2Ay0+GEEA73LhMEUsfLKsqCCtlbQQoXq KBA3SHvD3i0BA7NxeKnSEEw9qW2B7RdPQMCfPf5uYOOzz03w2nbc3E9fwRCRtw+GZd7B IbKnZW5pEPPqtRpnMm8VXdoj6HfBWGec3hu80b6RqjXY72QcC+yWHAu0/WZsZNM2J145 KLmA== X-Gm-Message-State: APjAAAUXNRc9OiJ2KrspHOLfoyGcHTPdyCqDGxUuTk0YPIbabOR8xYSa NwiDVkcblN4YbWEG0AqoNXJh7Zc9xdR6uIU= X-Google-Smtp-Source: APXvYqw00/nq1o/MSeTmkRBVcKK4DJpRz0GCa3SIEHTE3wNs9/3sBfq4wk1F7KycCoDZgeiaLwfs3cKq1BglehE= X-Received: by 2002:a63:1658:: with SMTP id 24mr14469351pgw.167.1562975594316; Fri, 12 Jul 2019 16:53:14 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:41 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-9-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 08/11] of/platform: Make sure supplier DT node is device when creating device links 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org While most phandle references in common bindings point to the supplier device node, there are also common bindings where the phandle can pointing to a child node of the supplier device node. Therefore, when trying to find the supplier device that corresponds to a supplier phandle, we need to make sure we are using the supplier's device node. Otherwise, we'll never find the supplier device. Signed-off-by: Saravana Kannan --- drivers/of/platform.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 98414ba53b1f..cf8625abe30c 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -529,19 +529,33 @@ static int of_link_binding(struct device *dev, const char *binding, const char *cell) { struct of_phandle_args sup_args; + struct device_node *sup_np; struct platform_device *sup_dev; unsigned int i = 0, links = 0; u32 dl_flags = DL_FLAG_AUTOPROBE_CONSUMER; while (!of_parse_phandle_with_args(dev->of_node, binding, cell, i, &sup_args)) { - if (!of_link_is_valid(dev->of_node, sup_args.np)) { - of_node_put(sup_args.np); + sup_np = sup_args.np; + /* + * Since we are trying to create device links, we need to find + * the actual device node that owns this supplier phandle. + * Often times it's the same node, but sometimes it can be one + * of the parents. So walk up the parent till you find a + * device. + */ + while (sup_np && !of_find_property(sup_np, "compatible", NULL)) + sup_np = of_get_next_parent(sup_np); + if (!sup_np) + continue; + + if (!of_link_is_valid(dev->of_node, sup_np)) { + of_node_put(sup_np); continue; } i++; - sup_dev = of_find_device_by_node(sup_args.np); - of_node_put(sup_args.np); + sup_dev = of_find_device_by_node(sup_np); + of_node_put(sup_np); if (!sup_dev) continue; if (device_link_add(dev, &sup_dev->dev, dl_flags)) From patchwork Fri Jul 12 23:52:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131540 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="SmTIoga6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqWM3Tygz9sNF for ; Sat, 13 Jul 2019 09:53:35 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728692AbfGLXxU (ORCPT ); Fri, 12 Jul 2019 19:53:20 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:42093 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728686AbfGLXxS (ORCPT ); Fri, 12 Jul 2019 19:53:18 -0400 Received: by mail-qt1-f201.google.com with SMTP id x1so8542989qts.9 for ; Fri, 12 Jul 2019 16:53:18 -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=aNfyFMFZafWi71b+o8VurVJ/Moxv/9An2Vz0MQSpw2E=; b=SmTIoga6HOIwTIw08mAMeozQrZPePiLyKswn4zNjz2IPFPycWu6caDt6xVt2AFzVx6 pRqcSLKYRs6KGvzn+l8I0Tx5kMSe6Q22foMB1DRJnqLcM4QYCwXzTmwjkrIlKV7uvZWD 7nqtMqvQo1P/qkz/KWX0Of4toJREidB5YJB40WKmm/cGbLXVgbeEBz6jnF3slzWnNuRA T0Ga2wZ05IJMko75q61JwavKkOX53+rAa7w+4pxthG/DiuKwnusJcZk1GO8uryDncRwS WACxjkLMsEDf3yiGuouoIVNhGXbwfJoLn6Z3Q28q1Es1Xl4Ba8dj5UQrwJcyvSxRBX0s Z0Uw== 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=aNfyFMFZafWi71b+o8VurVJ/Moxv/9An2Vz0MQSpw2E=; b=XA6fmlCV7V00fuxspTxp0qoNzUS4oo6qP+6OTCi8c89hTgAp6pWprhS4m4TsWxpfum LUiEgUMHwoYR0se1oq8uEnuHPRZ47cIORlPDQZo5/YM6vc1hz5FuD8bgYL998PJt2dOg 5U4d64j3uK4acP5KRUgzoelUyKyxMdaSqvi1snBvUeVrd34uY/KfOX3hHUxZQmyQHc1M ShJtYc+lGlGY9bOYQmb/bi/qzLByNCGNWAc3goh3F7OAPqlXVC1On+TajrTcCBNg1N3m WKM9VvJeoiOEU0JzNN7ebQF7mCopRjtgCsNksiI/oDwbojTYRMNvPerfqZEhVxOFMeFR 5kBQ== X-Gm-Message-State: APjAAAWGku5h6ucsKGhDCGqLDNMQaSmugOEKJwIPHGymFA04yzkHrpPE 1PaazABAp+IFPwgE+JtDWgaN1np3152u4LE= X-Google-Smtp-Source: APXvYqyyIBmeECglDcsfHezEruplDPEH4/v5Nq5NAhyh+EhK+LjnFi7lONixaTVz6xmPPJp4ZzV0Vr5/ngo9sAI= X-Received: by 2002:a0c:99e6:: with SMTP id y38mr9095787qve.42.1562975597621; Fri, 12 Jul 2019 16:53:17 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:42 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-10-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 09/11] 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index cf8625abe30c..6523d07ef2d7 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -525,7 +525,7 @@ bool of_link_is_valid(struct device_node *con, struct device_node *sup) return true; } -static int of_link_binding(struct device *dev, +static int of_link_binding(struct device *dev, struct device_node *con_np, const char *binding, const char *cell) { struct of_phandle_args sup_args; @@ -534,7 +534,7 @@ static int of_link_binding(struct device *dev, unsigned int i = 0, links = 0; u32 dl_flags = DL_FLAG_AUTOPROBE_CONSUMER; - while (!of_parse_phandle_with_args(dev->of_node, binding, cell, i, + while (!of_parse_phandle_with_args(con_np, binding, cell, i, &sup_args)) { sup_np = sup_args.np; /* @@ -579,26 +579,37 @@ static const char * const link_bindings[] = { "interconnects", "#interconnect-cells", }; -static int of_link_to_suppliers(struct device *dev) +static int __of_link_to_suppliers(struct device *dev, + struct device_node *con_np) { unsigned int i = 0; bool done = true; - - if (!of_devlink) - return 0; - if (unlikely(!dev->of_node)) - return 0; + struct device_node *child; for (i = 0; i < ARRAY_SIZE(link_bindings) / 2; i++) - if (of_link_binding(dev, link_bindings[i * 2], + if (of_link_binding(dev, con_np, link_bindings[i * 2], link_bindings[i * 2 + 1])) done = false; + for_each_child_of_node(con_np, child) + if (__of_link_to_suppliers(dev, child)) + done = false; + if (!done) return -ENODEV; return 0; } +static int of_link_to_suppliers(struct device *dev) +{ + if (!of_devlink) + return 0; + if (unlikely(!dev->of_node)) + return 0; + + return __of_link_to_suppliers(dev, dev->of_node); +} + #ifndef CONFIG_PPC static const struct of_device_id reserved_mem_matches[] = { { .compatible = "qcom,rmtfs-mem" }, From patchwork Fri Jul 12 23:52:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131538 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="iWVWNVmG"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqWB59wrz9sNk for ; Sat, 13 Jul 2019 09:53:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727431AbfGLXxZ (ORCPT ); Fri, 12 Jul 2019 19:53:25 -0400 Received: from mail-yw1-f73.google.com ([209.85.161.73]:39971 "EHLO mail-yw1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728701AbfGLXxW (ORCPT ); Fri, 12 Jul 2019 19:53:22 -0400 Received: by mail-yw1-f73.google.com with SMTP id r67so8978196ywg.7 for ; Fri, 12 Jul 2019 16:53:21 -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=QW+zU+QNcjXCm1XYmfzCA7KbcESNkERoyOnm4EH5sTg=; b=iWVWNVmGIYOFOC2EfUg0jOTE4wOOeyFoogk3TsEl3yexL33cERuEvCn12OgGpVGh/M OtGuJMxBEMZlSnKf5FKH2pHfK/cKlC0cPi7DfFMYPXJf2yzxCIeq6XDuVcYAIB52RMUE sQCLSp7AV9oM8CfGVUKXuOnQQEGwZsKT8oqLwfyNnzKtKfMUYVl+LcZFJ6obQYgrJKaY 1wZIOeEPIZ+d6h8cfkaSpG5mQ4so3XPUKFj5VV7qTtGb5LNApKngj/I4AntTthPzT6jK rZQU5ZGWoTZmJxCaejE0tyBR1mgYCpmddN209JDQWcZNOPM8rlBclnqvoGaPAdreRY+c SeEg== 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=QW+zU+QNcjXCm1XYmfzCA7KbcESNkERoyOnm4EH5sTg=; b=ohuo7vAiqM0z5HdYHiMQ37NbJx/7eyjClCc6Q8e8w91CLJxUdUsg5/gELxc9okZXuy ECVKNhYD/i4sBmIXz2n4/tVDPkTjj7cmJ/weXeDx5Zo0GomS49BU7PubFpAgHT/owezQ msP7mA1Y1j5Dmu7y8BwkLqQ1ZHcIYkjGtsZQVqm620Pv7GB6z/Jj+Ku+GDQomeiXRMr5 PpysZEZO7+gf+VPiZ2rYZGxzlLP+dDXQlNUPcGxPV+/CUs0TVZGiUfft7G7hipyd6xfi 6fWiOQkami2m8M542xguCHdoytUNfYj4eCAtevX9xJb0x/gyBSiSwNj7vp4MF3XuRkYN Ihbg== X-Gm-Message-State: APjAAAWmnTHQSnuH9mc6SdAIC0Hx9x0wjpY+heg2p/dVPBi7YO1qL0og XvMvBxjFohEhkvQatWdvYwn+P3veVRwYnsg= X-Google-Smtp-Source: APXvYqx7VbQ88nJ8oFqEGVqdvtIAtzH6D/4k0+SgF5oYk4u33PLfWUs4+rkdopyVpvfPqMy6v3uCdYVY04dxJk4= X-Received: by 2002:a81:3bd4:: with SMTP id i203mr7979284ywa.116.1562975600624; Fri, 12 Jul 2019 16:53:20 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:43 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-11-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 10/11] of/platform: Add functional dependency link from DT regulator bindings 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Similar to creating functional dependency links from clock and interconnect DT bindings, also create functional dependency links from regulator DT bindings. Signed-off-by: Saravana Kannan --- drivers/of/platform.c | 83 ++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 6523d07ef2d7..9f3b7e1801bc 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -525,46 +525,50 @@ bool of_link_is_valid(struct device_node *con, struct device_node *sup) return true; } -static int of_link_binding(struct device *dev, struct device_node *con_np, - const char *binding, const char *cell) +static int of_link_to_phandle(struct device *dev, struct device_node *sup_np) { - struct of_phandle_args sup_args; - struct device_node *sup_np; struct platform_device *sup_dev; - unsigned int i = 0, links = 0; u32 dl_flags = DL_FLAG_AUTOPROBE_CONSUMER; + int ret = 0; - while (!of_parse_phandle_with_args(con_np, binding, cell, i, - &sup_args)) { - sup_np = sup_args.np; - /* - * Since we are trying to create device links, we need to find - * the actual device node that owns this supplier phandle. - * Often times it's the same node, but sometimes it can be one - * of the parents. So walk up the parent till you find a - * device. - */ - while (sup_np && !of_find_property(sup_np, "compatible", NULL)) - sup_np = of_get_next_parent(sup_np); - if (!sup_np) - continue; + /* + * Since we are trying to create device links, we need to find + * the actual device node that owns this supplier phandle. + * Often times it's the same node, but sometimes it can be one + * of the parents. So walk up the parent till you find a + * device. + */ + while (sup_np && !of_find_property(sup_np, "compatible", NULL)) + sup_np = of_get_next_parent(sup_np); + if (!sup_np) + return 0; - if (!of_link_is_valid(dev->of_node, sup_np)) { - of_node_put(sup_np); - continue; - } - i++; - sup_dev = of_find_device_by_node(sup_np); + if (!of_link_is_valid(dev->of_node, sup_np)) { of_node_put(sup_np); - if (!sup_dev) - continue; - if (device_link_add(dev, &sup_dev->dev, dl_flags)) - links++; - put_device(&sup_dev->dev); + return 0; } - if (links < i) + sup_dev = of_find_device_by_node(sup_np); + of_node_put(sup_np); + if (!sup_dev) return -ENODEV; - return 0; + if (!device_link_add(dev, &sup_dev->dev, dl_flags)) + ret = -ENODEV; + put_device(&sup_dev->dev); + return ret; +} + +static int of_link_binding(struct device *dev, struct device_node *con_np, + const char *binding, const char *cell) +{ + struct of_phandle_args sup_args; + unsigned int i = 0; + bool done = true; + + while (!of_parse_phandle_with_args(con_np, binding, cell, i++, + &sup_args)) + if (of_link_to_phandle(dev, sup_args.np)) + done = false; + return done ? 0 : -ENODEV; } static bool of_devlink; @@ -579,18 +583,33 @@ static const char * const link_bindings[] = { "interconnects", "#interconnect-cells", }; +#define REG_SUFFIX "-supply" static int __of_link_to_suppliers(struct device *dev, struct device_node *con_np) { unsigned int i = 0; bool done = true; struct device_node *child; + struct property *p; + unsigned int len, reg_len; for (i = 0; i < ARRAY_SIZE(link_bindings) / 2; i++) if (of_link_binding(dev, con_np, link_bindings[i * 2], link_bindings[i * 2 + 1])) done = false; + reg_len = strlen(REG_SUFFIX); + for_each_property_of_node(con_np, p) { + len = strlen(p->name); + if (len <= reg_len) + continue; + if (strcmp(p->name + len - reg_len, REG_SUFFIX)) + continue; + if (of_link_to_phandle(dev, + of_parse_phandle(con_np, p->name, 0))) + done = false; + } + for_each_child_of_node(con_np, child) if (__of_link_to_suppliers(dev, child)) done = false; From patchwork Fri Jul 12 23:52:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 1131539 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="MnUPYPMp"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45lqWH0y36z9sNF for ; Sat, 13 Jul 2019 09:53:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727417AbfGLXx0 (ORCPT ); Fri, 12 Jul 2019 19:53:26 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:56547 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728687AbfGLXxY (ORCPT ); Fri, 12 Jul 2019 19:53:24 -0400 Received: by mail-pl1-f202.google.com with SMTP id o6so5995502plk.23 for ; Fri, 12 Jul 2019 16:53:24 -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=CFxxqGnefOXorhrwYqF3mwAy1+jiw4VOCKpjKBDoyT8=; b=MnUPYPMpXRNJhnxIEOQkopnSiqM4LwT2KaAFhMGRiiQq8POudN9dt0VG4XPUeGz8ao nmHisWeLgIwP+2I/ubn8KZSf+D8q7CVvWz7iqwv1T4Qw2D0qDYwiKc0yMnqdjd3p5Yg8 KLh8mRQ2Bd5E21GecWU9+bQ+p83bSYgh8W+1zJxQH5PM+NaikhlYF0spos9UT22/GD21 opWt+BWMDrRY8FmbN/kBOAYR9JnWDPi/cCefm7Oeo60EF5cDG7A7YR2JyQ+2S/1JlARM Al2ilX4+kFDDQcvXTMQB1BuLNmh6oAZ2cY2FKNm15cK4Skj7hfX40d5iJEZ6HpjnRAdN Nizw== 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=CFxxqGnefOXorhrwYqF3mwAy1+jiw4VOCKpjKBDoyT8=; b=KmoFSVe11r3f37OpGMSXgz7/3VnIhqi3b2+XT1YNivshvjg81RCYOnXUs9eRnpbg9m PQW4FqUJLlSzfEsp8LtNnF160bMNTThifv6EqP9aKcSAqhXyENLE5WDbLsT4/OAc5bNE ez8a7p9zymVxt0QL48DB3gvmj6+92WIbnOYr5uldTs1KE4V6yzRipdX6e8WDSHAMZxHe Kicg1nvQtgEwEPpo6oUmRFTPGRNDOGdzEO2C/L9iz/XDdPXx9dijD1BbjalQeSU+Qey+ gLAWejNFc3/JUcksTg9YxXZeLJyxaZg3hQhG+SABhrMlZJbv8qhzcy/JUjLw/fcin3Xm THow== X-Gm-Message-State: APjAAAVD1w8SIchWNw2J5On8H332Aln1BotPFXdGpSx3DXpDgjTAsM9m LGIuX48FRLEq6DG8UUuMliViAN/BTwUs5vQ= X-Google-Smtp-Source: APXvYqw0E6zYGebktTFqUus6/97NONkNo8swfiCbKYdrUTLEfjPBQAFkvFlxtjmj0xrbWbFHkzYe9KU4nWk7qtQ= X-Received: by 2002:a63:1658:: with SMTP id 24mr14469922pgw.167.1562975603646; Fri, 12 Jul 2019 16:53:23 -0700 (PDT) Date: Fri, 12 Jul 2019 16:52:44 -0700 In-Reply-To: <20190712235245.202558-1-saravanak@google.com> Message-Id: <20190712235245.202558-12-saravanak@google.com> Mime-Version: 1.0 References: <20190712235245.202558-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v5 11/11] of/platform: Don't create device links default busses 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 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Default busses also have devices created for them. But there's no point in creating device links for them. It's especially wasteful as it'll cause the traversal of the entire device tree and also spend a lot of time checking and figuring out that creating those links isn't allowed. So check for default busses and skip trying to create device links for them. Signed-off-by: Saravana Kannan --- drivers/of/platform.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 9f3b7e1801bc..b02dbaa01bfe 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -593,6 +593,9 @@ static int __of_link_to_suppliers(struct device *dev, struct property *p; unsigned int len, reg_len; + if (of_match_node(of_default_bus_match_table, con_np)) + return 0; + for (i = 0; i < ARRAY_SIZE(link_bindings) / 2; i++) if (of_link_binding(dev, con_np, link_bindings[i * 2], link_bindings[i * 2 + 1]))