From patchwork Tue May 13 11:48:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 30040 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 04C3B20446 for ; Tue, 13 May 2014 11:48:55 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wo20sf986938obc.7 for ; Tue, 13 May 2014 04:48:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=oX5rS3HxE4NaYKpN/e6Y95T/+sCR3rhdjaFEGnHyoas=; b=D7+4fCWW8UkT9A06DC4IdMF+zuffF3mH8uG7yJi2m1zkaCtm4rNelw/c15ulw3H62Y Ahyb7Saf6/bumf65uxi/GMMMs2ExXfqDxtKxSb6zkP1uHgtXuwNCZ91JIOExP3ciUau4 kbdkCZgwUM8U8fu5NUKyz8AT5fxnn9LSn453NXNjLWSvv8oNXdxzMKDWwDP8d6c5j5is 9jzeXNp2SxObuTIw/b3R8HxMERi9/fTcYCgN6urybMM/5RDxvbUtHOc4g1pom4QE1Vrk +EmMgPJkQqvmtIsvUFIcHJwynP5gATEymdlaWPoHZrhpCVf30xxEkoMDb2A3uxhrj8gH 7rng== X-Gm-Message-State: ALoCoQnDmoCLXttVqtgkWvLDU4qd0WqsNs3Ls1hGcNezHBlyEWt9be11B3zdZNy1y+krdtqph3sf X-Received: by 10.43.45.1 with SMTP id ui1mr15208410icb.1.1399981735317; Tue, 13 May 2014 04:48:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.82.145 with SMTP id h17ls1743913qgd.31.gmail; Tue, 13 May 2014 04:48:55 -0700 (PDT) X-Received: by 10.58.48.201 with SMTP id o9mr28083453ven.5.1399981735208; Tue, 13 May 2014 04:48:55 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id pd4si2594248veb.213.2014.05.13.04.48.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 04:48:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id lc6so259172vcb.16 for ; Tue, 13 May 2014 04:48:55 -0700 (PDT) X-Received: by 10.58.186.207 with SMTP id fm15mr28076161vec.4.1399981735037; Tue, 13 May 2014 04:48:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp144449vcb; Tue, 13 May 2014 04:48:54 -0700 (PDT) X-Received: by 10.66.65.169 with SMTP id y9mr63579920pas.145.1399981733712; Tue, 13 May 2014 04:48:53 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gd2si7869444pbd.162.2014.05.13.04.48.53; Tue, 13 May 2014 04:48:53 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753568AbaEMLsw (ORCPT + 8 others); Tue, 13 May 2014 07:48:52 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:17387 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1760030AbaEMLsv (ORCPT ); Tue, 13 May 2014 07:48:51 -0400 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.45]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 5BB3A13F8B8; Tue, 13 May 2014 06:48:40 -0500 (CDT) From: Pawel Moll To: Grant Likely , Rob Herring , Russell King Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Pawel Moll Subject: [PATCH v3] of: Keep track of populated platform devices Date: Tue, 13 May 2014 12:48:36 +0100 Message-Id: <1399981716-24618-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In "Device Tree powered" systems, platform devices are usually massively populated with of_platform_populate() call, executed at some level of initcalls, either by generic architecture or by platform-specific code. There are situations though where certain devices must be created (and bound with drivers) before all the others. This presents a challenge, as devices created explicitly would be created again by of_platform_populate(). This patch tries to solve that issue in a generic way, adding a "populated" flag for a DT node description. Once set, this device will never be created again via of_* API, so of_platform_populate() will skip such nodes (and its children) in a similar way to the non-available ones. The flag is cleared when a device is being removed and returns the DT node by calling of_device_node_put() (it was missing from the amba device release function, added). Signed-off-by: Pawel Moll Reviewed-by: Rob Herring Acked-by: Grant Likely --- Changes since v2: - the populated flag is now cleared when the device is being removed by platform or amba bus code - added missing of_device_node_put() to amba_device_release() - renamed of_node_check_and_set_flag() to of_node_check_test_and_set_flag() to follow the bitops naming convention - didn't add Rob's ack as the patch changed too much Changes since v1: - added of_node_check_and_set_flag()... (atomic test and set) - ... used it to atomically mark a node... - ... clearing the bit on error path. drivers/amba/bus.c | 2 ++ drivers/of/platform.c | 18 +++++++++++++----- include/linux/of.h | 7 +++++++ include/linux/of_device.h | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 3cf61a1..0f489fb 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -268,6 +269,7 @@ static void amba_device_release(struct device *dev) { struct amba_device *d = to_amba_device(dev); + of_device_node_put(dev); if (d->res.parent) release_resource(&d->res); kfree(d); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index bd47fbc..2d0c8b7 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -206,12 +206,13 @@ static struct platform_device *of_platform_device_create_pdata( { struct platform_device *dev; - if (!of_device_is_available(np)) + if (!of_device_is_available(np) || + of_node_test_and_set_flag(np, OF_POPULATED)) return NULL; dev = of_device_alloc(np, bus_id, parent); if (!dev) - return NULL; + goto err_clear_flag; #if defined(CONFIG_MICROBLAZE) dev->archdata.dma_mask = 0xffffffffUL; @@ -229,10 +230,14 @@ static struct platform_device *of_platform_device_create_pdata( if (of_device_add(dev) != 0) { platform_device_put(dev); - return NULL; + goto err_clear_flag; } return dev; + +err_clear_flag: + of_node_clear_flag(np, OF_POPULATED); + return NULL; } /** @@ -264,14 +269,15 @@ static struct amba_device *of_amba_device_create(struct device_node *node, pr_debug("Creating amba device %s\n", node->full_name); - if (!of_device_is_available(node)) + if (!of_device_is_available(node) || + of_node_test_and_set_flag(node, OF_POPULATED)) return NULL; dev = amba_device_alloc(NULL, 0, 0); if (!dev) { pr_err("%s(): amba_device_alloc() failed for %s\n", __func__, node->full_name); - return NULL; + goto err_clear_flag; } /* setup generic device info */ @@ -311,6 +317,8 @@ static struct amba_device *of_amba_device_create(struct device_node *node, err_free: amba_device_put(dev); +err_clear_flag: + of_node_clear_flag(node, OF_POPULATED); return NULL; } #else /* CONFIG_ARM_AMBA */ diff --git a/include/linux/of.h b/include/linux/of.h index 3bad8d1..3fd6079 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -130,6 +130,12 @@ static inline int of_node_check_flag(struct device_node *n, unsigned long flag) return test_bit(flag, &n->_flags); } +static inline int of_node_test_and_set_flag(struct device_node *n, + unsigned long flag) +{ + return test_and_set_bit(flag, &n->_flags); +} + static inline void of_node_set_flag(struct device_node *n, unsigned long flag) { set_bit(flag, &n->_flags); @@ -197,6 +203,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) /* flag descriptions */ #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ #define OF_DETACHED 2 /* node has been detached from the device tree */ +#define OF_POPULATED 3 /* device already created for the node */ #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) diff --git a/include/linux/of_device.h b/include/linux/of_device.h index ef37021..fd14d46 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -41,6 +41,8 @@ extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env static inline void of_device_node_put(struct device *dev) { + if (dev->of_node) + of_node_clear_flag(dev->of_node, OF_POPULATED); of_node_put(dev->of_node); }