From patchwork Mon Sep 7 12:23:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7134331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 806A2BEEC1 for ; Mon, 7 Sep 2015 12:26:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9234D2066C for ; Mon, 7 Sep 2015 12:26:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98DBC2066B for ; Mon, 7 Sep 2015 12:26:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZYvTa-000815-QT; Mon, 07 Sep 2015 12:24:46 +0000 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZYvTJ-0007qs-W2 for linux-arm-kernel@lists.infradead.org; Mon, 07 Sep 2015 12:24:30 +0000 Received: by wicfx3 with SMTP id fx3so82221701wic.0 for ; Mon, 07 Sep 2015 05:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=eWdkv13fAnVDx5XmgWaaC6enRRDKG1BGIf6JgbvqTSY=; b=Pu49Ld0F7jUwYoOtBHy4Xo9NuEMUCji/solKwLgVuM2Jo3SHF6U1f3k7RgFm7jmc2y FovStS804v4mkBCKogn4XGSAbNIZd9ECEUnvNkrABBhXTDZul3/+QhQZgMv6QQ8QI2tk ZwR/pYiIPnTP+6eISbaqQf2VdlUNHRvZQJwrSdiESXPPyPFtTowCNoqnnyIj6PI/HUty KaodIROPdeJv5a2rrbM5A8cR3xwDrf5uM4jW9/ArgAuFtlLUO9ivPfwOv/kPWkg1N4NL v3KssHaajsUXRwUVpBFbczZHZHroTAbIKkmYSd5Ydcwm9dAsL552csIausp1foFCPy8/ DFWQ== X-Received: by 10.194.93.3 with SMTP id cq3mr34928126wjb.20.1441628648440; Mon, 07 Sep 2015 05:24:08 -0700 (PDT) Received: from cizrna.lan ([109.72.12.78]) by smtp.gmail.com with ESMTPSA id cm6sm15438wib.22.2015.09.07.05.24.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2015 05:24:07 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v4 01/22] driver core: Add pre_probe callback to bus_type Date: Mon, 7 Sep 2015 14:23:26 +0200 Message-Id: <1441628627-5143-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1441628627-5143-1-git-send-email-tomeu.vizoso@collabora.com> References: <1441628627-5143-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150907_052430_174053_F26B211F X-CRM114-Status: GOOD ( 21.57 ) X-Spam-Score: -2.3 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Greg Kroah-Hartman , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Rob Herring , Javier Martinez Canillas , Mark Brown , Thierry Reding , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some buses (eg. AMBA) need access to some HW resources (it may need a clock to be enabled so a device ID can be read) before a device can be matched to a driver. The pre_probe callback allows the device-driver core to request the bus to perform this initialization and can defer the probe if any of the resources needed are missing. This gives us more flexibility when setting the order in which devices are probed because the resources needed to get the matching information don't need to be available by the time that the bus devices are registered. Signed-off-by: Tomeu Vizoso --- Changes in v4: None Changes in v3: None Changes in v2: None drivers/base/dd.c | 24 ++++++++++++++++++++++++ include/linux/device.h | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index be0eb4639128..faf60bfc46b3 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -544,6 +544,17 @@ static int __device_attach(struct device *dev, bool allow_async) int ret = 0; device_lock(dev); + + if (dev->bus && dev->bus->pre_probe) { + ret = dev->bus->pre_probe(dev); + if (ret) { + if (ret == -EPROBE_DEFER) + driver_deferred_probe_add(dev); + ret = 0; + goto out_unlock; + } + } + if (dev->driver) { if (klist_node_attached(&dev->p->knode_driver)) { ret = 1; @@ -619,6 +630,7 @@ void device_initial_probe(struct device *dev) static int __driver_attach(struct device *dev, void *data) { struct device_driver *drv = data; + int ret; /* * Lock device and try to bind to it. We drop the error @@ -636,8 +648,20 @@ static int __driver_attach(struct device *dev, void *data) if (dev->parent) /* Needed for USB */ device_lock(dev->parent); device_lock(dev); + + if (dev->bus && dev->bus->pre_probe) { + ret = dev->bus->pre_probe(dev); + if (ret) { + if (ret == -EPROBE_DEFER) + driver_deferred_probe_add(dev); + goto out; + } + } + if (!dev->driver) driver_probe_device(drv, dev); + +out: device_unlock(dev); if (dev->parent) device_unlock(dev->parent); diff --git a/include/linux/device.h b/include/linux/device.h index 5d7bc6349930..d8be07bc9c3f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -74,6 +74,9 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * given device can be handled by the given driver. * @uevent: Called when a device is added, removed, or a few other things * that generate uevents to add the environment variables. + * @pre_probe: Called when a new device or driver is added to this bus, to + * perform any initializations that are needed so the device can + * be matched to a driver. * @probe: Called when a new device or driver add to this bus, and callback * the specific driver's probe to initial the matched device. * @remove: Called when a device removed from this bus. @@ -113,6 +116,7 @@ struct bus_type { int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); + int (*pre_probe)(struct device *dev); int (*probe)(struct device *dev); int (*remove)(struct device *dev); void (*shutdown)(struct device *dev);