From patchwork Fri May 19 04:25:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 9735783 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2BFCD601C2 for ; Fri, 19 May 2017 04:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 147B72866A for ; Fri, 19 May 2017 04:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 076AC288A9; Fri, 19 May 2017 04:27:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 521092866A for ; Fri, 19 May 2017 04:27:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755033AbdESE1a (ORCPT ); Fri, 19 May 2017 00:27:30 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:35784 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755015AbdESE12 (ORCPT ); Fri, 19 May 2017 00:27:28 -0400 Received: by mail-pg0-f43.google.com with SMTP id q125so32324815pgq.2 for ; Thu, 18 May 2017 21:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AUa/r/owcEkLREAOhERJKHIL8sY1rKzDXiQd4uezk7o=; b=SSPh+zCW3PP8rwQjQx8KC/xv+COW81PDzn5EtEUjVQY6+BD763oZJNXKNcMKQhLN8b j9a4PYuU76FF5XMH+QNNIpUh0h0fJUZuxcKOTesHWfNQL+Wa5++R1l/1/RQWZ6yHkr4r 63+AG6VV5/Mcr+/tFamwSX2xwfUb5IBJVGoeg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AUa/r/owcEkLREAOhERJKHIL8sY1rKzDXiQd4uezk7o=; b=sLpEt4jxtFf/X2YcksXxFb+EIZ6fSXsgT6Hf0M5SHlyXsA0f9OqTDMyr46/NRD0v7g uy4/IZ/zOgb/3tSiUO5SVnXhCHloCpexlXt/KRvL3STwgnQ4BZW+Pfy2PkzFScMXQs3K HHLkC4zLOzjO3a2topqpoxss+D9qNq9QcL47dCeLdtnTYwYAmHYMa6b1KQ7a7v+PEl1C DPJBMqSJ3XT2Dzjo+8/Q3xbSeaKi4Ez626Vmh+A6256O7OFJZAdX1I5fSs0loc1cCUxl HbSujVPCnBWT8lhszLkpAkKz34M3h2C3CwBcHIRAewSY0WWqXP86jvIjKvKAtglw3Avp thJw== X-Gm-Message-State: AODbwcAIrGgmofWaZG0KCpoG1RLP5Ko4aCYUYy42FbYYvanzhMT0l/Vf BufNZ+CMM4y5xRiU X-Received: by 10.98.78.193 with SMTP id c184mr7963661pfb.85.1495168033233; Thu, 18 May 2017 21:27:13 -0700 (PDT) Received: from localhost.localdomain (li637-108.members.linode.com. [106.186.117.108]) by smtp.gmail.com with ESMTPSA id c29sm5823259pfj.101.2017.05.18.21.27.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 May 2017 21:27:11 -0700 (PDT) From: Leo Yan To: Jonathan Corbet , Mathieu Poirier , Rob Herring , Mark Rutland , Liviu Dudau , Sudeep Holla , Lorenzo Pieralisi , Catalin Marinas , Will Deacon , Wei Xu , Andy Gross , David Brown , Greg Kroah-Hartman , Suzuki K Poulose , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Stephen Boyd , Mike Leach Cc: Leo Yan Subject: [PATCH v10 06/10] coresight: refactor with function of_coresight_get_cpu Date: Fri, 19 May 2017 12:25:53 +0800 Message-Id: <1495167957-14923-7-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495167957-14923-1-git-send-email-leo.yan@linaro.org> References: <1495167957-14923-1-git-send-email-leo.yan@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is refactor to add function of_coresight_get_cpu(), so it's used to retrieve CPU id for coresight component. Finally can use it as a common function for multiple places. Suggested-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/of_coresight.c | 43 +++++++++++++++++++----------- include/linux/coresight.h | 3 +++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/drivers/hwtracing/coresight/of_coresight.c b/drivers/hwtracing/coresight/of_coresight.c index 225b2dd..a187941 100644 --- a/drivers/hwtracing/coresight/of_coresight.c +++ b/drivers/hwtracing/coresight/of_coresight.c @@ -101,16 +101,40 @@ static int of_coresight_alloc_memory(struct device *dev, return 0; } +int of_coresight_get_cpu(const struct device_node *node) +{ + int cpu; + bool found; + struct device_node *dn, *np; + + dn = of_parse_phandle(node, "cpu", 0); + + /* Affinity defaults to CPU0 */ + if (!dn) + return 0; + + for_each_possible_cpu(cpu) { + np = of_cpu_device_node_get(cpu); + found = (dn == np); + of_node_put(np); + if (found) + break; + } + of_node_put(dn); + + /* Affinity to CPU0 if no cpu nodes are found */ + return found ? cpu : 0; +} +EXPORT_SYMBOL_GPL(of_coresight_get_cpu); + struct coresight_platform_data * of_get_coresight_platform_data(struct device *dev, const struct device_node *node) { - int i = 0, ret = 0, cpu; + int i = 0, ret = 0; struct coresight_platform_data *pdata; struct of_endpoint endpoint, rendpoint; struct device *rdev; - bool found; - struct device_node *dn, *np; struct device_node *ep = NULL; struct device_node *rparent = NULL; struct device_node *rport = NULL; @@ -177,18 +201,7 @@ of_get_coresight_platform_data(struct device *dev, } while (ep); } - dn = of_parse_phandle(node, "cpu", 0); - for_each_possible_cpu(cpu) { - np = of_cpu_device_node_get(cpu); - found = (dn == np); - of_node_put(np); - if (found) - break; - } - of_node_put(dn); - - /* Affinity to CPU0 if no cpu nodes are found */ - pdata->cpu = found ? cpu : 0; + pdata->cpu = of_coresight_get_cpu(node); return pdata; } diff --git a/include/linux/coresight.h b/include/linux/coresight.h index bf0aa50..d950dad 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -263,10 +263,13 @@ static inline int coresight_timeout(void __iomem *addr, u32 offset, #endif #ifdef CONFIG_OF +extern int of_coresight_get_cpu(const struct device_node *node); extern struct coresight_platform_data * of_get_coresight_platform_data(struct device *dev, const struct device_node *node); #else +static inline int of_coresight_get_cpu(const struct device_node *node) +{ return 0; } static inline struct coresight_platform_data *of_get_coresight_platform_data( struct device *dev, const struct device_node *node) { return NULL; } #endif