From patchwork Fri Oct 11 19:15:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 11186247 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DDBA76 for ; Fri, 11 Oct 2019 19:15:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F61A21A4A for ; Fri, 11 Oct 2019 19:15:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h68zGj5x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728956AbfJKTPa (ORCPT ); Fri, 11 Oct 2019 15:15:30 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:36631 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728955AbfJKTPa (ORCPT ); Fri, 11 Oct 2019 15:15:30 -0400 Received: by mail-qk1-f201.google.com with SMTP id k67so9975489qkc.3 for ; Fri, 11 Oct 2019 12:15:29 -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=b6OPfeDXDNnLoQEW6NHQIyUVbhLZaRHwvYyPaGn7Jx4=; b=h68zGj5xh+JMp5ROxPTII7AfDWeZLe+QFnK3e/ab7881KamtZ+ymQWny9QpnUGSzCN UxQ2QN+2lcZbZ8CCj8y9YuV9DaumY7ELPJstSm4v3Kjxh1B5b3Fs1Y2SrV3s6htG8LdT XWsAoMVEmzi+/gmNTTKOLRoTsUdIhmlRnfQwMqlR0R4scxGxUFD92oqBDBr7PS9z2vUx uFOEBXHpmdyscah3hj1NxTvGqQsT6/1rpVzVYa1GBmFPOlvlWlghrKIOvVVSsOvu/vdT bGhhElYb/2NdC42yhGz5UgOPFxELaCOb+5V3xYGS2lua/fyEZ3mRdetUQBuF26drHJSa 6Z+w== 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=b6OPfeDXDNnLoQEW6NHQIyUVbhLZaRHwvYyPaGn7Jx4=; b=as5E39h4FQj3kuX57gC4SbPHAZXkXVMC8D1XGh/GGiTnUOU0oKpC5wE5/x5ccOPrzs qWyytSvDiF1r9mBL5PrXVTi2/Y6z4EoGJwFQPC7aGtWMTK4frF88K1RFPM4K2UCQWNGT HTEtaSbx0JqSgEneNETI1KcNZkS5s5lAHeJReOKJkKrlOJbCG5zpqO78b9ko6ny1s8bp S80UpqIWCdYy3NivGCPfnIhdZoV764aWYM2xwTxvBEIsjx8n2FlUhlHZDD1AdGR8DB7j wHYf6ak6LKVl5oDwpXsbZ16pzfPlGlM3Q0A+PIFDKDZK6F6KWqNIohiej6ct6BPGBs9x JWlA== X-Gm-Message-State: APjAAAUG6F/8zA5hnGZcwNxVKJbU5DJq15DOJmJpuLXx+t2NrJIn9zNL 8UtMZJeV+KpHbFXiy6lobRSwJgVqNh8iFVs= X-Google-Smtp-Source: APXvYqzrDB1u/6Ws76aANvtFWvjSpE4W7wK5JP6C/Mh29zv9OXM1FQmakJRl8/LsdIt9CkIdWU3Zo67haQv9IXs= X-Received: by 2002:a0c:f9c6:: with SMTP id j6mr17688251qvo.40.1570821329024; Fri, 11 Oct 2019 12:15:29 -0700 (PDT) Date: Fri, 11 Oct 2019 12:15:19 -0700 In-Reply-To: <20191011191521.179614-1-saravanak@google.com> Message-Id: <20191011191521.179614-2-saravanak@google.com> Mime-Version: 1.0 References: <20191011191521.179614-1-saravanak@google.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog Subject: [PATCH v1 1/3] of: property: Minor code formatting/style clean ups From: Saravana Kannan To: Jonathan Corbet , Rob Herring , Frank Rowand , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman Cc: Saravana Kannan , Stephen Boyd , kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Better variable and function names. Remove "," after the sentinel in an array initialization list. Signed-off-by: Saravana Kannan Acked-by: Rob Herring --- drivers/of/property.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/of/property.c b/drivers/of/property.c index 923d6f88a99c..6f6e1d9644cf 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1147,11 +1147,11 @@ struct supplier_bindings { const char *prop_name, int index); }; -static const struct supplier_bindings bindings[] = { +static const struct supplier_bindings of_supplier_bindings[] = { { .parse_prop = parse_clocks, }, { .parse_prop = parse_interconnects, }, { .parse_prop = parse_regulators, }, - {}, + {} }; /** @@ -1177,7 +1177,7 @@ static int of_link_property(struct device *dev, struct device_node *con_np, const char *prop_name) { struct device_node *phandle; - const struct supplier_bindings *s = bindings; + const struct supplier_bindings *s = of_supplier_bindings; unsigned int i = 0; bool matched = false; int ret = 0; @@ -1196,7 +1196,7 @@ static int of_link_property(struct device *dev, struct device_node *con_np, return ret; } -static int __of_link_to_suppliers(struct device *dev, +static int of_link_to_suppliers(struct device *dev, struct device_node *con_np) { struct device_node *child; @@ -1208,7 +1208,7 @@ static int __of_link_to_suppliers(struct device *dev, ret = -EAGAIN; for_each_child_of_node(con_np, child) - if (__of_link_to_suppliers(dev, child)) + if (of_link_to_suppliers(dev, child)) ret = -EAGAIN; return ret; @@ -1226,7 +1226,7 @@ static int of_fwnode_add_links(const struct fwnode_handle *fwnode, if (unlikely(!is_of_node(fwnode))) return 0; - return __of_link_to_suppliers(dev, to_of_node(fwnode)); + return of_link_to_suppliers(dev, to_of_node(fwnode)); } const struct fwnode_operations of_fwnode_ops = { From patchwork Fri Oct 11 19:15:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 11186249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BEB2176 for ; Fri, 11 Oct 2019 19:15:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9ED7D21D71 for ; Fri, 11 Oct 2019 19:15:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SjWuOTsG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728981AbfJKTPe (ORCPT ); Fri, 11 Oct 2019 15:15:34 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:39363 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728851AbfJKTPd (ORCPT ); Fri, 11 Oct 2019 15:15:33 -0400 Received: by mail-pf1-f201.google.com with SMTP id b13so8216413pfp.6 for ; Fri, 11 Oct 2019 12:15:32 -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=wwUIXG8zaTQahpGiWbKYxnh72iiHnCVZCniLVYgkymY=; b=SjWuOTsGX96zO37k1lrS0YGrpMuH9atVN00vNP8ziHSqCn5t4dh1R8CJorCFIjPdkg WEWKUOZPjx8vnNqtI6YQDXKsRyBAVvql3hBRri2FhH+wJ0084Fb4JXe0niwBFfhvnYmx PRw9piDFj/NQVRK8uguTgpNyFy1hd0f2bGlygLYPWJqEI/bfEIsGC7vIwGn4XrC154Cf CFNI4CQ1F5Bg649N5plNnllxLyf1xvpsBPAYffUiDd8QbDT+JZf0MTjcec0yP+Yh1ELW n845mj7mpnjt67qWFGOA8qyslxjBTS35v/vcpCBs0h0+KtkSBPxWDP/L07tiwi84Xc/Z 2r0A== 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=wwUIXG8zaTQahpGiWbKYxnh72iiHnCVZCniLVYgkymY=; b=bfBTF6q4dgVdWczqPp47/sj4Qi8eSENwHJFSD46hGNunLAExpHDrXG9pT+GSx+tLaQ UmhGn6seRRd4i9xIwzk1WP/8YFTWdq0YmD8GjxBAxl3tYlH3qg2ntkOMVnwUjChqj+jA rD1TbiK4vwPix1Q2Oh7yvcgQsqKQqYFcOY38otqXoK0vaavifg+RINyexMIKFaeO9cYZ u+2bBJC1zH8bR31LR2dByXq0r/CwAh1egErrpKT1vqWG2f3O2eYtKJd7D5VzoylHbGG7 Uaxb+H4T9SWjhw32w0/2laYigb6sAomePOzIpYGDUmXop3U2pPNXKQWeomwDOaxcLNLp i6PA== X-Gm-Message-State: APjAAAVDqYSbIQ5NXtWiKfG5n8AFOcxYUI4XcMnutW1+TnJjBvxTc+GM afARpP5a98DsTY0/0P6xvKze0YYFtOs9zME= X-Google-Smtp-Source: APXvYqzaCgjn0N9hABwlUZ7A/oUwETCiJvUmLoZt+RlNeEME8ZHLP4663B/JrOTQqolBHH7K1mL5F5e9EcUtEu0= X-Received: by 2002:a63:6a46:: with SMTP id f67mr17738001pgc.87.1570821332209; Fri, 11 Oct 2019 12:15:32 -0700 (PDT) Date: Fri, 11 Oct 2019 12:15:20 -0700 In-Reply-To: <20191011191521.179614-1-saravanak@google.com> Message-Id: <20191011191521.179614-3-saravanak@google.com> Mime-Version: 1.0 References: <20191011191521.179614-1-saravanak@google.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog Subject: [PATCH v1 2/3] driver: core: Improve documentation for fwnode_operations.add_links() From: Saravana Kannan To: Jonathan Corbet , Rob Herring , Frank Rowand , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman Cc: Saravana Kannan , Stephen Boyd , kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The add_links() ops shouldn't return on the first failed device link add. It needs to continue trying to add device links to other suppliers that are available. The documentation didn't explain WHY this behavior is necessary. So, update the documentation with an example that explains why this is necessary. Signed-off-by: Saravana Kannan --- include/linux/fwnode.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 6ae05b9ce359..97223e2410bd 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -71,8 +71,25 @@ struct fwnode_reference_args { * links to all the suppliers of the device that are available at * the time this function is called. The function must NOT stop * at the first failed device link if other unlinked supplier - * devices are present in the system. If some suppliers are not - * yet available, this function will be called again when other + * devices are present in the system. This is necessary for the + * driver/bus sync_state() callbacks to work correctly. + * + * For example, say Device-C depends on suppliers Device-S1 and + * Device-S2 and the dependency is listed in that order in the + * firmware. Say, S1 gets populated from the firmware after + * late_initcall_sync(). Say S2 is populated and probed way + * before that in device_initcall(). When C is populated, if this + * add_links() function doesn't continue past a "failed linking to + * S1" and continue linking C to S2, then S2 will get a + * sync_state() callback before C is probed. This is because from + * the perspective of S2, C was never a consumer when its + * sync_state() evaluation is done. To avoid this, the add_links() + * function has to go through all available suppliers of the + * device (that corresponds to this fwnode) and link to them + * before returning. + * + * If some suppliers are not yet available (indicated by an error + * return value), this function will be called again when other * devices are added to allow creating device links to any newly * available suppliers. * From patchwork Fri Oct 11 19:15:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 11186251 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3232676 for ; Fri, 11 Oct 2019 19:15:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A4ED2190F for ; Fri, 11 Oct 2019 19:15:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KtQ7RuQA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728865AbfJKTPl (ORCPT ); Fri, 11 Oct 2019 15:15:41 -0400 Received: from mail-vk1-f202.google.com ([209.85.221.202]:45794 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728895AbfJKTPi (ORCPT ); Fri, 11 Oct 2019 15:15:38 -0400 Received: by mail-vk1-f202.google.com with SMTP id q84so3785422vkb.12 for ; Fri, 11 Oct 2019 12:15:36 -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=fuET3qNc4z015mh4xj4NLz17joYOgUCh9UCVZC00VJQ=; b=KtQ7RuQAgEe2d9wcSmFDcLBsRoaaxGnpESOpf/q6dteBQqfkJ6FlI7FsfVyrTIxA5z xwZTZVQZlDQ7S/gzwJjZus5nZx3GJjO6hkhrkgUqORg8jTVxIt+s0y88CkAOFOTUIpRI 0Pzt39RFgrUq2XIP4cHJaFu8U0+NpHeQM7pfJw6eTNiKtASKlEgUMTfTY9F2RVJtnEFn QFT/ef3CgPcb9DsR5oYYhAAL8hYt4W/XFs81+D/zCGDiiNyfGHoL54m7RQCMwlIb7DXR P/W0KYOmCkgg16488maeLjzDGxalw2QDxZWb880tI/rMhZWrR+NypPxIgCWcm2dDL2uj qDPA== 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=fuET3qNc4z015mh4xj4NLz17joYOgUCh9UCVZC00VJQ=; b=fgQGruYGOJROiDKrtMfopSJ2GDqe8ueXN684ysUxZjByBDr2oGlG/AQ/X0JgGhV4rC Y0Wzh2613XI15ZnPJlg41FMhb6nTCbCHX0ZOsTg8Uc0y8t3hW8FqiB4jnIrF3HkTCIs9 vCRDi/s0tAS5rTdmLAVpcFmVhRKsvhQufM8c2WgGXF2CqlsYWEK9g954kJ1+EHhGlUDC 59bMPrKV87C3+33372SkDEBpZlVKKycRYhy12oJyDmBw3/Cwj87dPQC09//f/OH1E8lx LPq7MCyJpu2zIGOJeic4b/jpLQNBb5722/iWZ3ITULvJWlBPj2s9jkWYYzbvDwTGbncW dzdg== X-Gm-Message-State: APjAAAWPTib4IWJ5iSec1bkBDziuQ6yzaWuufsO/hyqCh6Z03wrLt/+p IROy95x8XucHosP5kx6PRz6DqUReN00wNMU= X-Google-Smtp-Source: APXvYqyKbyMInaL/TiLznxFZpaDnmd4A+1ivZ+irQgGm2Xkw+CFqTG49xHbf8Z1vqOMgRdvb2xnG1jQBb3eetEU= X-Received: by 2002:a1f:f445:: with SMTP id s66mr9324346vkh.62.1570821335385; Fri, 11 Oct 2019 12:15:35 -0700 (PDT) Date: Fri, 11 Oct 2019 12:15:21 -0700 In-Reply-To: <20191011191521.179614-1-saravanak@google.com> Message-Id: <20191011191521.179614-4-saravanak@google.com> Mime-Version: 1.0 References: <20191011191521.179614-1-saravanak@google.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog Subject: [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state From: Saravana Kannan To: Jonathan Corbet , Rob Herring , Frank Rowand , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman Cc: Saravana Kannan , Stephen Boyd , kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The sync_state() driver callback was added recently, but the documentation was missing. Adding it now. Signed-off-by: Saravana Kannan --- .../driver-api/driver-model/driver.rst | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Documentation/driver-api/driver-model/driver.rst b/Documentation/driver-api/driver-model/driver.rst index 11d281506a04..baa6a85c8287 100644 --- a/Documentation/driver-api/driver-model/driver.rst +++ b/Documentation/driver-api/driver-model/driver.rst @@ -169,6 +169,49 @@ A driver's probe() may return a negative errno value to indicate that the driver did not bind to this device, in which case it should have released all resources it allocated:: + void (*sync_state)(struct device *dev); + +sync_state is called only once for a device. It's called when all the consumer +devices of the device have successfully probed. The list of consumers of the +device is obtained by looking at the device links connecting that device to its +consumer devices. + +The first attempt to call sync_state() is made during late_initcall_sync() to +give firmware and drivers time to link devices to each other. During the first +attempt at calling sync_state(), if all the consumers of the device at that +point in time have already probed successfully, sync_state() is called right +away. If there are no consumers of the device during the first attempt, that +too is considered as "all consumers of the device have probed" and sync_state() +is called right away. + +If during the first attempt at calling sync_state() for a device, there are +still consumers that haven't probed successfully, the sync_state() call is +postponed and reattempted in the future only when one or more consumers of the +device probe successfully. If during the reattempt, the driver core finds that +there are one or more consumers of the device that haven't probed yet, then +sync_state() call is postponed again. + +A typical use case for sync_state() is to have the kernel cleanly take over +management of devices from the bootloader. For example, if a device is left on +and at a particular hardware configuration by the bootloader, the device's +driver might need to keep the device in the boot configuration until all the +consumers of the device have probed. Once all the consumers of the device have +probed, the device's driver can synchronize the hardware state of the device to +match the aggregated software state requested by all the consumers. Hence the +name sync_state(). + +While obvious examples of resources that can benefit from sync_state() include +resources such as regulator, sync_state() can also be useful for complex +resources like IOMMUs. For example, IOMMUs with multiple consumers (devices +whose addresses are remapped by the IOMMU) might need to keep their mappings +fixed at (or additive to) the boot configuration until all its consumers have +probed. + +While the typical use case for sync_state() is to have the kernel cleanly take +over management of devices from the bootloader, the usage of sync_state() is +not restricted to that. Use it whenever it makes sense to take an action after +all the consumers of a device have probed. + int (*remove) (struct device *dev); remove is called to unbind a driver from a device. This may be