From patchwork Fri May 17 15:21:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 2583731 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id CD80C40079 for ; Fri, 17 May 2013 16:21:01 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UdMWV-0008T5-0K; Fri, 17 May 2013 15:24:49 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UdMVD-0008Cq-48; Fri, 17 May 2013 15:23:27 +0000 Received: from service87.mimecast.com ([91.220.42.44]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UdMTq-00081K-JH for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2013 15:22:06 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Fri, 17 May 2013 16:21:41 +0100 Received: from e102568-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 17 May 2013 16:21:39 +0100 From: Lorenzo Pieralisi To: linux-arm-kernel@lists.infradead.org, devicetree-discuss@lists.ozlabs.org Subject: [RFC PATCH v4 18/18] ARM: DT: kernel: DT cpus/cpu node bindings update Date: Fri, 17 May 2013 16:21:01 +0100 Message-Id: <1368804061-4421-19-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: <1368804061-4421-1-git-send-email-lorenzo.pieralisi@arm.com> References: <1368804061-4421-1-git-send-email-lorenzo.pieralisi@arm.com> X-OriginalArrivalTime: 17 May 2013 15:21:39.0998 (UTC) FILETIME=[3AB80BE0:01CE5312] X-MC-Unique: 113051716214109901 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130517_112203_110396_7E8B4471 X-CRM114-Status: GOOD ( 18.69 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [91.220.42.44 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Nicolas Pitre , Jon Medhurst , Dave Martin , Andrew Lunn , Tony Lindgren , Benjamin Herrenschmidt , Linus Walleij , Will Deacon , Viresh Kumar , Kukjin Kim , Mark Rutland , Lennert Buytenhek , Lorenzo Pieralisi , Russell King , Magnus Damm , Catalin Marinas , Grant Likely , David Brown , Jean-Christophe Plagniol-Villard , Dinh Nguyen , Arnd Bergmann , Stephen Warren , Sekhar Nori , Rob Herring , Simon Horman , Barry Song , Vincent Guittot , Vinayak Kale , Amit Kucheria , Nicolas Ferre , Olof Johansson , Maxime Ripard , Shawn Guo X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DT cpu map parsing code must be made compliant with the latest cpus/cpu nodes bindings updates, hence this patch updates the arm_dt_init_cpu_maps() function with checks and additional parsing rules. Uniprocessor systems predating v7 do not parse the cpus node at all since the reg property is meaningless on those systems. Device trees for 64-bit systems can be taken as device tree input also for 64-bit CPUs running in 32-bit mode. The code checks that the reg entries are zeroed as required in the respective fields and detects automatically the cpus node #address-cells value so that device tree written for 64-bit ARM platforms (that can have cpus node #address-cells == 2) can still be taken as input. The correct device tree entries are to be set up by the boot loader, kernel code just checks that device tree entries in the cpus node are as expected for a 32-bit CPU (reg[63:24] == 0). cpu node entries with invalid reg property or containing duplicates are ignored and the device tree parsing is not stopped anymore when such entries are encountered, the device tree cpu node entry is just skipped. A device tree with cpu nodes missing the boot CPU MPIDR is considered an error and the kernel flags this up as such to trigger firmware updates. Signed-off-by: Lorenzo Pieralisi Acked-by: Nicolas Pitre --- arch/arm/kernel/devtree.c | 146 ++++++++++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 58 deletions(-) diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c index 0905502..80d6cf24 100644 --- a/arch/arm/kernel/devtree.c +++ b/arch/arm/kernel/devtree.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -72,100 +73,129 @@ void __init arm_dt_memblock_reserve(void) */ void __init arm_dt_init_cpu_maps(void) { - /* - * Temp logical map is initialized with UINT_MAX values that are - * considered invalid logical map entries since the logical map must - * contain a list of MPIDR[23:0] values where MPIDR[31:24] must - * read as 0. - */ struct device_node *cpu, *cpus; - u32 i, j, cpuidx = 1; + u32 i, ac, cpuidx = 1; + int len; u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0; - u32 tmp_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID }; bool bootcpu_valid = false; cpus = of_find_node_by_path("/cpus"); - if (!cpus) + if (!cpus || ((cpu_architecture() < CPU_ARCH_ARMv7) && !is_smp())) return; + if (of_property_read_u32(cpus, "#address-cells", &ac)) { + pr_warn("%s invalid #address-cells\n", cpus->full_name); + ac = of_n_addr_cells(cpus); + } + /* + * The boot CPU knows its MPIDR and initialize it + * to allow DT boot CPU detection. + */ + cpu_logical_map(0) = mpidr; + for_each_child_of_node(cpus, cpu) { - u32 hwid; + u64 hwid64; + u32 hwid32; + const __be32 *prop; if (of_node_cmp(cpu->type, "cpu")) continue; pr_debug(" * %s...\n", cpu->full_name); /* - * A device tree containing CPU nodes with missing "reg" - * properties is considered invalid to build the - * cpu_logical_map. + * A CPU node with missing or wrong "reg" property is + * considered invalid to build a cpu_logical_map entry. */ - if (of_property_read_u32(cpu, "reg", &hwid)) { - pr_debug(" * %s missing reg property\n", - cpu->full_name); - return; + prop = of_get_property(cpu, "reg", &len); + if (!prop || len < (ac * sizeof(*prop))) { + pr_warn(" * %s node missing/wrong reg property, skipped\n", + cpu->full_name); + goto next; } /* - * 8 MSBs must be set to 0 in the DT since the reg property - * defines the MPIDR[23:0]. + * Always read reg as u64 value. + * For dts with #address-cells == 1 hwid64[63:32] + * will be set to 0 by of_read_number. + * Toss away the top 32 bits and store value in hwid32. */ - if (hwid & ~MPIDR_HWID_BITMASK) - return; - + hwid32 = hwid64 = of_read_number(prop, ac); + /* + * hwid64[63:24] must be always be 0 since the reg + * property defines the MPIDR[23:0] bits regardless + * of the cpus node #address-cells value. + */ + if (hwid64 & ~MPIDR_HWID_BITMASK) { + pr_warn(" * %s node reg[63:24] must be 0 on 32-bit dts, got %#016llx, skipped\n", + cpu->full_name, hwid64); + goto next; + } /* * Duplicate MPIDRs are a recipe for disaster. * Scan all initialized entries and check for - * duplicates. If any is found just bail out. - * temp values were initialized to UINT_MAX - * to avoid matching valid MPIDR[23:0] values. + * duplicates. If any is found just ignore the CPU. + * Boot CPU at logical index 0 is not checked to + * allow self contained boot CPU detection logic. */ - for (j = 0; j < cpuidx; j++) - if (WARN(tmp_map[j] == hwid, "Duplicate /cpu reg " - "properties in the DT\n")) - return; + for (i = 1; i < cpuidx; i++) + if (cpu_logical_map(i) == hwid32) { + pr_warn(" * %s node duplicate cpu reg property, skipped\n", + cpu->full_name); + goto next; + } /* - * Build a stashed array of MPIDR values. Numbering scheme - * requires that if detected the boot CPU must be assigned - * logical id 0. Other CPUs get sequential indexes starting - * from 1. If a CPU node with a reg property matching the - * boot CPU MPIDR is detected, this is recorded so that the - * logical map built from DT is validated and can be used - * to override the map created in smp_setup_processor_id(). + * If a CPU node with a reg property matching the + * cpu_logical_map(0) is detected, this is recorded so + * that the bootcpu_valid condition can be checked when + * DT scanning is completed. Duplicate boot cpu entries + * are flagged up if detected. */ - if (hwid == mpidr) { - i = 0; - bootcpu_valid = true; - } else { - i = cpuidx++; + if (hwid32 == cpu_logical_map(0)) { + if (bootcpu_valid) { + pr_warn(" * %s node duplicate boot cpu reg property, skipped\n", + cpu->full_name); + } else { + bootcpu_valid = true; + } + goto next; } + /* + * Build cpu_logical_map array. Numbering scheme + * requires that boot CPU is assigned logical id 0. + * Other CPUs get sequential indexes starting from 1. + */ + i = cpuidx++; - if (WARN(cpuidx > nr_cpu_ids, "DT /cpu %u nodes greater than " - "max cores %u, capping them\n", - cpuidx, nr_cpu_ids)) { + if (cpuidx > nr_cpu_ids) { + pr_warn_once("DT cpu %u nodes greater than max cores %u, capping them\n", + cpuidx, nr_cpu_ids); cpuidx = nr_cpu_ids; - break; + goto next; } - tmp_map[i] = hwid; + cpu_logical_map(i) = hwid32; + set_cpu_possible(i, true); + pr_debug("cpu_logical_map(%u) 0x%x\n", i, cpu_logical_map(i)); +next: ; } - - if (WARN(!bootcpu_valid, "DT missing boot CPU MPIDR[23:0], " - "fall back to default cpu_logical_map\n")) - return; + /* + * A DT missing the boot CPU MPIDR is a really bad omen + * Flag it up as such. + */ + if (!bootcpu_valid) + pr_warn("DT missing boot cpu node\n"); /* - * Since the boot CPU node contains proper data, and all nodes have - * a reg property, the DT CPU list can be considered valid and the - * logical map created in smp_setup_processor_id() can be overridden + * Since the DT might contain fewer entries than NR_CPUS, + * cpu_logical_map entries initialized in smp_setup_processor_id() + * but not found in the DT must be overriden with MPIDR_INVALID + * values to make sure the cpu_logical_map does not contain stale + * MPIDR values. */ - for (i = 0; i < cpuidx; i++) { - set_cpu_possible(i, true); - cpu_logical_map(i) = tmp_map[i]; - pr_debug("cpu logical map 0x%x\n", cpu_logical_map(i)); - } + for (i = cpuidx; i < nr_cpu_ids; i++) + cpu_logical_map(i) = MPIDR_INVALID; } /**