From patchwork Wed Apr 30 14:05:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 29426 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f197.google.com (mail-yk0-f197.google.com [209.85.160.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DC296202FE for ; Wed, 30 Apr 2014 14:05:41 +0000 (UTC) Received: by mail-yk0-f197.google.com with SMTP id 142sf3675085ykq.4 for ; Wed, 30 Apr 2014 07:05:41 -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=4Fd/XBYn8ug2O2TSKgMw40eyWKmxv/NcY7dyRWj4sI0=; b=W+8gbU9C+ZSFhERgwMzLnRPi+hzyLmPCZjd9Z2j6dY6FqJ95O3kuMn0cEWBr9OIazQ GApxa6JPK8TXAITNmTFcH27zXF9RXwoivf//NBzJt7LsSLFxDT29U8Bqco+1JIVK0uYN k/dRWHyu0IakPHqcqN6IiQbXZm77Ln8jbPwDiPU45LPBjRwOUXgFcRAlUslv0gsKEqVT b9W0Vfo9+y69gKFVU1DhGCh627rVCG22fre0DjZ2b9DdRxsUjd8mZCKhmIpSrNm08GTc RfkNVfCGK0qhYyJ4WyCgx4RqKx8mUKvZynMSMdpxcKrPp6OncND1CDY40apiPmZDta0P dHTA== X-Gm-Message-State: ALoCoQl7SHC/LiOPQfxnUFE2TdCXGcLmyzCU9c/QoqdpPbvLIGuIKgKqS4AAce2CiE82LdkLGkbd X-Received: by 10.236.66.169 with SMTP id h29mr2233795yhd.34.1398866741397; Wed, 30 Apr 2014 07:05:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.85.40 with SMTP id m37ls569640qgd.18.gmail; Wed, 30 Apr 2014 07:05:41 -0700 (PDT) X-Received: by 10.58.39.129 with SMTP id p1mr170583vek.69.1398866741143; Wed, 30 Apr 2014 07:05:41 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id sl10si2504789vdc.147.2014.04.30.07.05.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 07:05:41 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id db12so2163096veb.38 for ; Wed, 30 Apr 2014 07:05:41 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr4095661vcb.0.1398866741064; Wed, 30 Apr 2014 07:05:41 -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 ib8csp281799vcb; Wed, 30 Apr 2014 07:05:40 -0700 (PDT) X-Received: by 10.66.164.70 with SMTP id yo6mr8762639pab.85.1398866740219; Wed, 30 Apr 2014 07:05:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lk4si10574749pab.268.2014.04.30.07.05.39; Wed, 30 Apr 2014 07:05:39 -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 S1759108AbaD3OFe (ORCPT + 9 others); Wed, 30 Apr 2014 10:05:34 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:30859 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759007AbaD3OFc (ORCPT ); Wed, 30 Apr 2014 10:05:32 -0400 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.45]) by collaborate-mta1.arm.com (Postfix) with ESMTP id BAD0413F7E9; Wed, 30 Apr 2014 09:05:24 -0500 (CDT) From: Pawel Moll To: Grant Likely , Rob Herring Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Pawel Moll Subject: [PATCH v2] of: Keep track of populated platform devices Date: Wed, 30 Apr 2014 15:05:17 +0100 Message-Id: <1398866717-20268-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1398858529.24255.3.camel@hornet> References: <1398858529.24255.3.camel@hornet> 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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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. Signed-off-by: Pawel Moll Acked-by: Rob Herring --- 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/of/platform.c | 18 +++++++++++++----- include/linux/of.h | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 404d1da..b33927a 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -204,12 +204,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_check_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; @@ -227,10 +228,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; } /** @@ -262,14 +267,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_check_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 */ @@ -309,6 +315,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..534cab8 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_check_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)