From patchwork Tue Jan 20 05:07:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 5663981 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CFD10C058D for ; Tue, 20 Jan 2015 05:12:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CEF48203AE for ; Tue, 20 Jan 2015 05:12:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D26BE202AE for ; Tue, 20 Jan 2015 05:12:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YDR4C-0005dL-0i; Tue, 20 Jan 2015 05:09:28 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YDR44-0005XU-6x for linux-arm-kernel@lists.infradead.org; Tue, 20 Jan 2015 05:09:25 +0000 Received: from 172.24.2.119 (EHLO szxeml428-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CFY82266; Tue, 20 Jan 2015 13:08:28 +0800 (CST) Received: from localhost (10.177.27.142) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.158.1; Tue, 20 Jan 2015 13:08:19 +0800 From: Zhen Lei To: Catalin Marinas , Will Deacon , linux-arm-kernel Subject: [PATCH 1/2] arm64: support new attribute reg-var-mask in cpu node Date: Tue, 20 Jan 2015 13:07:50 +0800 Message-ID: <1421730471-8256-1-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.27.142] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150119_210920_818681_017DBEFD X-CRM114-Status: GOOD ( 14.90 ) X-Spam-Score: -0.7 (/) Cc: Xinwei Hu , Kefeng Wang , Zefan Li , Zhen Lei , Tianhong Ding X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now, a cpu node in dts can only describe one cpu. All the same attribute node's value in each cpu node are the same, except reg attribute. For example: cpu@0 { device_type = "cpu"; compatible = "arm,armv8"; reg = <0x0 0x0>; enable-method = "spin-table"; cpu-release-addr = <0x0 0x8000fff8>; }; cpu@1 { device_type = "cpu"; compatible = "arm,armv8"; reg = <0x0 0x1>; enable-method = "spin-table"; cpu-release-addr = <0x0 0x8000fff8>; }; Wow! Assume a processor have 4 clusters, each cluster contains 8 cores, we should write 32 times. It's too long. But base upon reg-var-mask, we can simply write like below(only one cpu node): cpu@0-31 { device_type = "cpu"; compatible = "arm,armv8"; reg = <0x0 0x0>; reg-var-mask = <0x0 0x307>; enable-method = "spin-table"; cpu-release-addr = <0x0 0x8000fff8>; }; In the above example, reg-var-mask = <0x0 0x307>. The mask of cluster-id field is 3, means cluster-id can be variable from 0 to 3. The mask of core-id field is 7, means core-id can be variable from 0 to 7. Each varible result OR with reg to form the final hwid. like C code: for (cluster-id = 0; cluster-id <= 3; cluster-id++) for (core-id = 0; core-id <= 7; core-id++) hwid = reg | | ; If only run cluster-1, we can slightly modified like below: cpu@8-15 { device_type = "cpu"; compatible = "arm,armv8"; reg = <0x0 0x100>; reg-var-mask = <0x0 0x7>; enable-method = "spin-table"; cpu-release-addr = <0x0 0x8000fff8>; }; reg-var-mask is optional, if omitted or zero value, use the old style. Signed-off-by: Zhen Lei --- arch/arm64/kernel/smp.c | 85 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 80 insertions(+), 5 deletions(-) -- 1.7.1 diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 7ae6ee0..cb1b9d5 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -318,6 +318,56 @@ void __init smp_prepare_boot_cpu(void) set_my_cpu_offset(per_cpu_offset(smp_processor_id())); } +struct hwid_var_ctrl { + struct { + u8 num; + u8 shift; + } fields[BITS_PER_LONG >> 1]; + + u64 var; + int num; +}; + +static void init_var_fields(u64 var_mask, struct hwid_var_ctrl *ctrl) +{ + int i, idx = -1, found_field = 0; + + if (!var_mask) + goto scan_finished; + + for (i = 0; i < BITS_PER_LONG; i++) + if (((u64)1 << i) & var_mask) + if (!found_field) { + found_field = 1; + ctrl->fields[++idx].shift = i; + ctrl->fields[idx].num = 1; + } else { + ctrl->fields[idx].num++; + } + else + found_field = 0; + +scan_finished: + ctrl->var = 0; + ctrl->num = idx + 1; +} + +static u64 fill_var_fields(u64 hwid, struct hwid_var_ctrl *ctrl) +{ + int i; + u64 var, mask; + + var = ctrl->var++; + + for (i = 0; i < ctrl->num; i++) { + mask = ((u64)1 << ctrl->fields[i].num) - 1; + hwid |= (mask & var) << ctrl->fields[i].shift; + var >>= ctrl->fields[i].num; + } + + return hwid; +} + /* * Enumerate the possible CPU set from the device tree and build the * cpu logical map array containing MPIDR values related to logical @@ -332,6 +382,8 @@ void __init smp_init_cpus(void) while ((dn = of_find_node_by_type(dn, "cpu"))) { const u32 *cell; u64 hwid; + u64 hwid_fixed, var_mask; + struct hwid_var_ctrl ctrl; /* * A cpu node with missing "reg" property is @@ -341,18 +393,37 @@ void __init smp_init_cpus(void) cell = of_get_property(dn, "reg", NULL); if (!cell) { pr_err("%s: missing reg property\n", dn->full_name); - goto next; + cpu++; + continue; + } + hwid_fixed = of_read_number(cell, of_n_addr_cells(dn)); + + cell = of_get_property(dn, "reg-var-mask", NULL); + if (!cell) + var_mask = 0; + else + var_mask = of_read_number(cell, of_n_addr_cells(dn)); + + if ((hwid_fixed & var_mask) != 0) { + pr_warn("reg-var-mask 0x%llx is incorrect, ignored\n", + var_mask); + var_mask = 0; } - hwid = of_read_number(cell, of_n_addr_cells(dn)); /* * Non affinity bits must be set to 0 in the DT */ - if (hwid & ~MPIDR_HWID_BITMASK) { + if ((hwid_fixed | var_mask) & ~MPIDR_HWID_BITMASK) { pr_err("%s: invalid reg property\n", dn->full_name); - goto next; + cpu++; + continue; } + init_var_fields(var_mask, &ctrl); + +inc_var_fields: + hwid = fill_var_fields(hwid_fixed, &ctrl); + /* * Duplicate MPIDRs are a recipe for disaster. Scan * all initialized entries and check for @@ -389,7 +460,7 @@ void __init smp_init_cpus(void) * the enable-method so continue without * incrementing cpu. */ - continue; + goto var_check; } if (cpu >= NR_CPUS) @@ -405,6 +476,10 @@ void __init smp_init_cpus(void) cpu_logical_map(cpu) = hwid; next: cpu++; + +var_check: + if ((hwid & var_mask) != var_mask) + goto inc_var_fields; } /* sanity check */