From patchwork Mon Aug 21 17:55:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 9913439 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 380B2600C8 for ; Mon, 21 Aug 2017 17:58:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E7C828614 for ; Mon, 21 Aug 2017 17:58:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 235C5286EF; Mon, 21 Aug 2017 17:58:26 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA83028614 for ; Mon, 21 Aug 2017 17:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=upe8S1Gh8+bFtywAKMl/KGVsTrW3UfORgYzYJTuYHM0=; b=ZisS3DpViJBIepaVlHVCmOnn+/ azlsakzq6Gi6YJP4YRh4triEYOdMZxO1XdyuyWzb2X1gNXV9R2vaozth4VaIKRaPckw7Asje9cDHg PmlStZELtZ/eGze0ZdI77KNA0Q1rq0uG4NelmD1vxTniwC2tir3rrN+UodgwkKllrwUEceN3i4z1m KuE9cZz2aIXYxUQ8YN7cZTUQwAfNc3dCbH/mDJB8I/XWgPoFEE0dSLDNW+NprUtCTKpe4vBNR3NlQ 0767JCgdZB14e6Cl5MiyaZy6uyvZRDTm1Ljv4+wlMAB4f/MrnKAEMdSLuFHaFe8K/JDOoSvMSncYZ 9gNL4NPg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1djqxx-000307-IV; Mon, 21 Aug 2017 17:58:21 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1djqw6-0001fM-EP for linux-arm-kernel@lists.infradead.org; Mon, 21 Aug 2017 17:56:29 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2581615A2; Mon, 21 Aug 2017 10:56:10 -0700 (PDT) Received: from e107814-lin.cambridge.arm.com (e107814-lin.cambridge.arm.com [10.1.206.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E395C3F540; Mon, 21 Aug 2017 10:56:07 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 2/6] of: Add helper for mapping device node to logical CPU number Date: Mon, 21 Aug 2017 18:55:05 +0100 Message-Id: <1503338109-32540-3-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1503338109-32540-1-git-send-email-suzuki.poulose@arm.com> References: <1503338109-32540-1-git-send-email-suzuki.poulose@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170821_105626_549929_1206E9E2 X-CRM114-Status: GOOD ( 12.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, robh@kernel.org, Sudeep Holla , mathieu.poirier@linaro.org, devicetree@vger.kernel.org, marc.zyngier@arm.com, Suzuki K Poulose , will.deacon@arm.com, linux-kernel@vger.kernel.org, peterz@infradead.org, Jonathan.Cameron@huawei.com, frowand.list@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a helper to map a device node to a logical CPU number to avoid duplication. Currently this is open coded in different places (e.g gic-v3, coresight). The helper tries to map device node to a "possible" logical CPU id, which may not be online yet. It is the responsibility of the user to make sure that the CPU is online. The helper uses of_get_cpu_node() which uses arch specific backends to match the phyiscal ids. Cc: devicetree@vger.kernel.org Cc: Frank Rowand Cc: Mark Rutland Cc: Sudeep Holla Reviewed-by: Marc Zyngier Reviewed-by: Rob Herring Signed-off-by: Suzuki K Poulose --- Changes since V3: - Renamed the helper to of_cpu_node_to_id(), suggested by Rob - Return -ENODEV on failure than nr_cpus_id --- drivers/of/base.c | 26 ++++++++++++++++++++++++++ include/linux/of.h | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 686628d..e8625ff 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -420,6 +420,32 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) EXPORT_SYMBOL(of_get_cpu_node); /** + * of_cpu_node_to_id: Get the logical CPU number for a given device_node + * + * @cpu_node: Pointer to the device_node for CPU. + * + * Returns the logical CPU number of the given CPU device_node. + * Returns -ENODEV if the CPU is not found. + */ +int of_cpu_node_to_id(struct device_node *cpu_node) +{ + int cpu; + bool found = false; + struct device_node *np; + + for_each_possible_cpu(cpu) { + np = of_get_cpu_node(cpu, NULL); + found = (cpu_node == np); + of_node_put(np); + if (found) + return cpu; + } + + return -ENODEV; +} +EXPORT_SYMBOL(of_cpu_node_to_id); + +/** * __of_device_is_compatible() - Check if the node matches given constraints * @device: pointer to node * @compat: required compatible string, NULL or "" for any match diff --git a/include/linux/of.h b/include/linux/of.h index 4a8a709..23cf02d 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -539,6 +539,8 @@ const char *of_prop_next_string(struct property *prop, const char *cur); bool of_console_check(struct device_node *dn, char *name, int index); +extern int of_cpu_node_to_id(struct device_node *np); + #else /* CONFIG_OF */ static inline void of_core_init(void) @@ -863,6 +865,11 @@ static inline void of_property_clear_flag(struct property *p, unsigned long flag { } +static inline int of_cpu_node_to_id(struct device_node *np) +{ + return -ENODEV; +} + #define of_match_ptr(_ptr) NULL #define of_match_node(_matches, _node) NULL #endif /* CONFIG_OF */