From patchwork Wed Apr 23 01:40:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Shen Lim X-Patchwork-Id: 28841 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D36E2203AC for ; Wed, 23 Apr 2014 01:41:05 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id to1sf1769481ieb.9 for ; Tue, 22 Apr 2014 18:41:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=6jbp79QDJphM018DUYSD/aAl9WUFWXoAqsJT+b/I8Hk=; b=hWBnZybqY6i8eCUL9hTgm1DF9VMIaFxscFCy5IbS8Vx+q5KCZz+6QdYKJ5z8vFLB7N OdFJ621qCv65dyT4P7+dLxq56ZPxAKzIkI7HHsnZHef40EmmpTU9QcGfgF9EOdTq8NuO EQ47oIF6ytqSaM6mGs9TAP/VRTDmzkbYomzd2FKcQVH1bSV04+g7TBUe8YKN7vS9qaQ+ Cy14111mfEYcWfRYDD3usKEiFT5nLMcT10ernI81kFlpoCnxRjRWLeiRBxAgwP/EC1Ly UzUHyeKoE/1xYx2O1gB4PI0+fz66mIA4oM2YKD4THbFi1JkkSN1UCYolitJR0miJYSW9 N39w== X-Gm-Message-State: ALoCoQk5KWHgZr/X2nswHbvYMOR3MKZEOolnoVsTYkB5ud7s4YBig5VeDce2zHbhTypiy/4YjTf6 X-Received: by 10.42.30.71 with SMTP id u7mr1544698icc.15.1398217265291; Tue, 22 Apr 2014 18:41:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.29.130 with SMTP id b2ls37032qgb.99.gmail; Tue, 22 Apr 2014 18:41:05 -0700 (PDT) X-Received: by 10.52.191.100 with SMTP id gx4mr33777043vdc.4.1398217265133; Tue, 22 Apr 2014 18:41:05 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id v2si7179594vet.142.2014.04.22.18.41.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Apr 2014 18:41:05 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id ld13so333722vcb.5 for ; Tue, 22 Apr 2014 18:41:05 -0700 (PDT) X-Received: by 10.221.20.199 with SMTP id qp7mr10668321vcb.24.1398217264976; Tue, 22 Apr 2014 18:41:04 -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 ib8csp67958vcb; Tue, 22 Apr 2014 18:41:04 -0700 (PDT) X-Received: by 10.68.91.194 with SMTP id cg2mr4758510pbb.30.1398217263954; Tue, 22 Apr 2014 18:41:03 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zm10si22918202pbc.275.2014.04.22.18.41.02; Tue, 22 Apr 2014 18:41:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754113AbaDWBkw (ORCPT + 27 others); Tue, 22 Apr 2014 21:40:52 -0400 Received: from mail-gw2-out.broadcom.com ([216.31.210.63]:21916 "EHLO mail-gw2-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753033AbaDWBk3 (ORCPT ); Tue, 22 Apr 2014 21:40:29 -0400 X-IronPort-AV: E=Sophos;i="4.97,908,1389772800"; d="scan'208";a="25836718" Received: from irvexchcas06.broadcom.com (HELO IRVEXCHCAS06.corp.ad.broadcom.com) ([10.9.208.53]) by mail-gw2-out.broadcom.com with ESMTP; 22 Apr 2014 19:04:37 -0700 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) by IRVEXCHCAS06.corp.ad.broadcom.com (10.9.208.53) with Microsoft SMTP Server (TLS) id 14.3.174.1; Tue, 22 Apr 2014 18:40:29 -0700 Received: from mail-sj1-12.sj.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.3.174.1; Tue, 22 Apr 2014 18:40:29 -0700 Received: from lc-sj1-5012.broadcom.com (lc-sj1-5012.sj.broadcom.com [10.66.65.230]) by mail-sj1-12.sj.broadcom.com (Postfix) with ESMTP id BD5D027A81; Tue, 22 Apr 2014 18:40:28 -0700 (PDT) Received: by lc-sj1-5012.broadcom.com (Postfix, from userid 28931) id B7EB7E01ECB; Tue, 22 Apr 2014 18:40:28 -0700 (PDT) From: Zi Shen Lim To: Catalin Marinas , Lorenzo Pieralisi , Mark Brown , Mark Rutland , Will Deacon CC: , , Zi Shen Lim Subject: [PATCH 2/2] arm64: topology: add MPIDR-based detection Date: Tue, 22 Apr 2014 18:40:14 -0700 Message-ID: <1398217214-12204-3-git-send-email-zlim@broadcom.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1398217214-12204-1-git-send-email-zlim@broadcom.com> References: <1398217214-12204-1-git-send-email-zlim@broadcom.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zlim@broadcom.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , Create cpu topology based on MPIDR. When hardware sets MPIDR to sane values, this method will always work. Therefore it should also work well as the fallback method. [1] [1] http://www.spinics.net/lists/arm-kernel/msg317445.html Signed-off-by: Zi Shen Lim --- arch/arm64/include/asm/cputype.h | 2 ++ arch/arm64/kernel/topology.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h index c404fb0..7639e8b 100644 --- a/arch/arm64/include/asm/cputype.h +++ b/arch/arm64/include/asm/cputype.h @@ -18,6 +18,8 @@ #define INVALID_HWID ULONG_MAX +#define MPIDR_UP_BITMASK (0x1 << 30) +#define MPIDR_MT_BITMASK (0x1 << 24) #define MPIDR_HWID_BITMASK 0xff00ffffff #define MPIDR_LEVEL_BITS_SHIFT 3 diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 3e06b0b..ef3bb7e 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -19,6 +19,7 @@ #include #include +#include #include /* @@ -71,6 +72,36 @@ static void update_siblings_masks(unsigned int cpuid) void store_cpu_topology(unsigned int cpuid) { + struct cpu_topology *cpuid_topo = &cpu_topology[cpuid]; + u64 mpidr; + + mpidr = read_cpuid_mpidr(); + + /* Create cpu topology mapping based on MPIDR. */ + if (mpidr & MPIDR_UP_BITMASK) { + /* Uniprocessor system */ + cpuid_topo->thread_id = -1; + cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); + cpuid_topo->cluster_id = -1; + } else { + /* Multiprocessor system */ + if (mpidr & MPIDR_MT_BITMASK) { + /* Multi-threads per core */ + cpuid_topo->thread_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); + cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 1); + cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 2); + } else { + /* Single-thread per core */ + cpuid_topo->thread_id = -1; + cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); + cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 1); + } + } + + pr_info("CPU%u: cluster %d core %d thread %d mpidr %llx\n", + cpuid, cpuid_topo->cluster_id, cpuid_topo->core_id, + cpuid_topo->thread_id, mpidr); + update_siblings_masks(cpuid); }