From patchwork Tue May 9 02:49:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 9716951 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 A767960236 for ; Tue, 9 May 2017 02:51:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B784206AC for ; Tue, 9 May 2017 02:51:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EA02269DA; Tue, 9 May 2017 02:51:23 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 CE1E22074F for ; Tue, 9 May 2017 02:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752513AbdEICvU (ORCPT ); Mon, 8 May 2017 22:51:20 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:34554 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753015AbdEICvR (ORCPT ); Mon, 8 May 2017 22:51:17 -0400 Received: by mail-pg0-f41.google.com with SMTP id u28so32692605pgn.1 for ; Mon, 08 May 2017 19:51:17 -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=krQGLJjYgID56xxBcZTFi9iN++6uSS1k9c/Bj8OUKXPPTWQkxnqlmhnNqbsPho7CWj N4w7nfg0fZ5/MKPZKABef1uN1SI4FcTP5Qzl8BC5GVqhWN7K+nB4bSLI1gMhOdfozWBG UFly4yrg8q7LOx3jnkxVPT/L2h93mQNz4dfbo= 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=SpQ8LlBIqcECgnUccnjh/Ye4Q08D84XbF63Q/UW6ZrKNgWqGqhf+AFo98imrgmxh/z zLaU+OKVrKVkwRJb26ug+oNZ5OfdxIQ6JxVpxSblAQ3lPeFj4pEf/HZTUMvmNjZblFIv BaQAEl/iuC+4JwHcqxTzitmT1IaT78qimmHdobMhJREDtmdlryHI2sN1YBTvZVQAGg8/ ZZxxp11gSrZE8COuDf547atIyN50cSP8n+aHp7QyJ/RQOCXSs0DQvI0QAcuP/HJkAJ1u hoeq/qlXfxkHzlPleN5hb8TgtBZtOkCpSRSGAuhZp+6RL74Jesm3TLKfkWjijOP3e4rg WXow== X-Gm-Message-State: AODbwcB1BTczHnVjNBy6lB1KN7ui2Mo0ZSIDq7LRefy6npGOO8LzzTEb aPIK7As+x2YHaUVd X-Received: by 10.99.151.10 with SMTP id n10mr5810552pge.199.1494298276964; Mon, 08 May 2017 19:51:16 -0700 (PDT) Received: from localhost.localdomain (li1627-128.members.linode.com. [172.104.47.128]) by smtp.gmail.com with ESMTPSA id 20sm35326370pfq.42.2017.05.08.19.51.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 19:51:15 -0700 (PDT) From: Leo Yan To: Jonathan Corbet , Mathieu Poirier , Rob Herring , Mark Rutland , Wei Xu , Catalin Marinas , Will Deacon , Andy Gross , David Brown , Greg Kroah-Hartman , Suzuki K Poulose , Stephen Boyd , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Mike Leach , Sudeep Holla Cc: Leo Yan Subject: [PATCH v9 6/9] coresight: refactor with function of_coresight_get_cpu Date: Tue, 9 May 2017 10:49:59 +0800 Message-Id: <1494298202-6739-7-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494298202-6739-1-git-send-email-leo.yan@linaro.org> References: <1494298202-6739-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