Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1317139ybp; Fri, 11 Oct 2019 12:17:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFcMYdUiQH2XfpvtN6ozgRhhC8adU7Skclr71hbjubXWBH45wL4dWQdEk+hQ+763sAonnl X-Received: by 2002:a17:906:1e43:: with SMTP id i3mr14825181ejj.77.1570821454804; Fri, 11 Oct 2019 12:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570821454; cv=none; d=google.com; s=arc-20160816; b=DF3HPRH+vfTEdiH6yLfAVqmReqRVmGFj8qybPeFmv2/VT1le22crOFHKHuZmlERd5P gzjmcU6HriwV5qpWk98JooHwrWhgYkUZsq3fa0AWI1qBjeke9Dzl+C53X+CYvxlWxoyI 2cq+X6UFVpAhW8Dn/KJRGTgMMXrebMSf2qVCizjsZx//lkNl3K3wLn9LtL9N0METAWQx 4gB5gkn2+o2hp8rB+vmizfP1/sE2yrblFKzXmxEI3DfohO0+BIk4cqRPrBeV25xR18Fr LjQyAVHWTIm1aka4ugW2ty8QrbNDgOpi0thKIXoNKCQjRICklVMeEWuzAUfArBNtLWTG 2BFw== 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=fuET3qNc4z015mh4xj4NLz17joYOgUCh9UCVZC00VJQ=; b=LPxdSiXUvKiTVhs0lVhQd3V3OrBskxVXADJAToxDHMQTOgHFMfak7Gsfwa0GBkmqMp hQ/GD4m4Lb0s8SQXWLMZ7EJDJjz9Enkzd/ZdWH+vr24mBL8BuVkJ5RB+sAnV17I3ESEW h+XWfMNOY0AMS61lIC63Qi+gtZUQAYW2JqyW62y2bW6FZjkeN175gl4m21vDY0KYtU5c yombEUKlTQu20q61j/UAe1Ete6eFje6PVTMdXj+VDkAOwtZoPMRHTGTWq48ndwk1Fw1W Z+fJRMMaz6ycNAjiqanCMX1mfd65e6lFcQJ7nFSbEfJCZZpa42DCJgZjWszCxccSbZ3C 4Hyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KtQ7RuQA; 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 e22si5725225ejr.19.2019.10.11.12.17.11; Fri, 11 Oct 2019 12:17:34 -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=KtQ7RuQA; 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 S1728997AbfJKTPi (ORCPT + 99 others); Fri, 11 Oct 2019 15:15:38 -0400 Received: from mail-vk1-f202.google.com ([209.85.221.202]:38695 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728865AbfJKTPi (ORCPT ); Fri, 11 Oct 2019 15:15:38 -0400 Received: by mail-vk1-f202.google.com with SMTP id k132so3814747vka.5 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=XltsyHQrA9b1xHILuypABMDwWzJ3ukrkrZXvqLhABK8MVdQXNQFCecw+R656l/dLyt vtCBbSwrgi3ZlGA4Ap0sn+UaG+25shZ4qlqvGgOB6M66wyHxWzLtzUt2wu/NLIwnqY62 1oT3Kfe6oO1HdfpNm7rw+3oywazYlLqhRQQnJr/8WOhW3cQzcTote2DXtEVzE6A2Rxay q84AZK0ihun8cfYCnTkkhOm2QPRQUhcfux7oxqGV6mLrgTfi1zlHwJ6nrYSoGYxD48iA kFkS5oNaLQghjzAvmZMt0YX0ZqvimzJaYY1u/AN7KqMgRQEhVwvjEJQcxQnDnK0a3tLt VNdw== X-Gm-Message-State: APjAAAUf1r4CBNgyRPLuHSwTwylreHk6sS61lD8dMHCMpwIXQeRnhoYY adQ0AlGkVb9y1KXfmgtsen7KcMAwO+OphX8= 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 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 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 -- 2.23.0.700.g56cf767bdb-goog