Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1431765imu; Thu, 13 Dec 2018 15:16:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/UPkfKCU17uzvwafKmfssHcHD/dJtuNH4JDnrTOhRulK4fgvS4g6CBzvL/Ag/z3TAjP0DiW X-Received: by 2002:a62:a99:: with SMTP id 25mr606895pfk.121.1544742985944; Thu, 13 Dec 2018 15:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544742985; cv=none; d=google.com; s=arc-20160816; b=QB2Cc3PsVMQgUUVn3doavN9WmwlUe2zZy495lcaNpjwrq/W8Xo1ZPDAjw02xMJGX9O OeCdyb9oR59v9ZCRhbgV0qIcaFdl/JaGoXSRS+CBTkvvj0RSdMkJOXcnGIVdjJGz5oAI k1WGueUACVfgoKCRQBIDGFBnqysiBHcAK5yS0wY9p6XyfvEjbUNX6xy06djcwPPZ2kIa fLSDG485pWFf3u9Nj6piIrXQXJay3Z26GJdP1xmv5SKG6SiiqZ830ddI2In1VftgWCiY gJqXUWxwvsNfmZFQArrukMpQ029i8i65PQs6FdtflY3uPc/S6eyHntzZFV8IsT80yE1d 1VRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=8z8MvLYwpvf/340/0Nm+8GAkrGF7+92kwodXMBVez4w=; b=A7gmYzehaland2tL1lkrvqAq86BPl296Z6eD7UlKCNUbCy4vn3LZTTHOzjmhjIuvpn +zEizulduVaDVKLSNUkPJDdJXb+5CVMrksME2ByJfnRU730IktD+hMWPjzX/TWBbK5ti cVsqFGOSupD/L112EVlHY30qTixQqyl5gixuDTpSjm5NsNa0nSk6rg4dqwkrS1/gyF8W QtMmltbEQ19IC9IKW+DkeRttiS6f7K/RpNcDGxGedcnfHzISVKll1XUPdY83cUTum018 YFh55pImXJy7IyYofc2bjRvDvkI2KGDSdYy8st7NjmI6Egrt3FqDlkMvJpL7XY4umlQj fKrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=dNEOJ0Hp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si2648794pgo.11.2018.12.13.15.16.11; Thu, 13 Dec 2018 15:16:25 -0800 (PST) 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; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=dNEOJ0Hp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728802AbeLMXPE (ORCPT + 99 others); Thu, 13 Dec 2018 18:15:04 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:15460 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbeLMXOx (ORCPT ); Thu, 13 Dec 2018 18:14:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1544742896; x=1576278896; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=dxBtfF9Jex9DE2/3vLUN+wWRwkF14HDcarpu+1RMLOM=; b=dNEOJ0Hp/SkuxZrKChfCUS9ZJ49qDkpNoLU7U1WBYXiHdHyM8O79foRb gQr17SRHBfxyWxV/du60U6G7o6aGn1E7I/2C/d2OC2IDx52ilym7KthqD XhL8/1FYI5HYerQBT8vwWKmRt8h7Ll7y+Mo6js1uD/++A95ThmckhaXoC OCdZ8eqXQ9NwmjDK4sSlsl2fNvpwGs4V+aC/EW0ZYCG6gjVELrQTCX7r+ 6dQcY+ix4Fm6fE/1HCpt1h0WuIvyjPsgyt6wAUgakQrg9gmXl42lisu3m Nsu5H82wYJTIWxxcxhYd59jppfsuH4RAVPJDDfbw4b0A/5roYBCarUYkG g==; X-IronPort-AV: E=Sophos;i="5.56,350,1539619200"; d="scan'208";a="194445537" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 14 Dec 2018 07:14:55 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 13 Dec 2018 14:57:20 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2018 15:14:53 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Daniel Lezcano , devicetree@vger.kernel.org, Dmitriy Cherkasov , linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Rob Herring , Thomas Gleixner , Anup Patel , Damien Le Moal , Christoph Hellwig Subject: [PATCH v2 2/4] RISC-V: Support per-hart timebase-frequency Date: Thu, 13 Dec 2018 15:14:27 -0800 Message-Id: <1544742869-19980-3-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544742869-19980-1-git-send-email-atish.patra@wdc.com> References: <1544742869-19980-1-git-send-email-atish.patra@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Follow the updated DT specs and read the timebase-frequency from the boot cpu. Keep the old DT reading as well for backward compatibility. This patch is rework of old patch from Palmer. Signed-off-by: Atish Patra --- arch/riscv/kernel/time.c | 9 +-------- drivers/clocksource/riscv_timer.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kernel/time.c b/arch/riscv/kernel/time.c index 1911c8f6..225fe743 100644 --- a/arch/riscv/kernel/time.c +++ b/arch/riscv/kernel/time.c @@ -20,14 +20,7 @@ unsigned long riscv_timebase; void __init time_init(void) { - struct device_node *cpu; - u32 prop; - - cpu = of_find_node_by_path("/cpus"); - if (!cpu || of_property_read_u32(cpu, "timebase-frequency", &prop)) - panic(KERN_WARNING "RISC-V system with no 'timebase-frequency' in DTS\n"); - riscv_timebase = prop; + timer_probe(); lpj_fine = riscv_timebase / HZ; - timer_probe(); } diff --git a/drivers/clocksource/riscv_timer.c b/drivers/clocksource/riscv_timer.c index 084e97dc..75262409 100644 --- a/drivers/clocksource/riscv_timer.c +++ b/drivers/clocksource/riscv_timer.c @@ -83,6 +83,35 @@ void riscv_timer_interrupt(void) evdev->event_handler(evdev); } +static void __init riscv_timebase_frequency(struct device_node *node, + int hartid) +{ + u32 timebase; + + if (!of_property_read_u32(node, "timebase-frequency", &timebase)) + goto check; + + /* + * As per the DT specification, timebase-frequency should be present + * under individual cpu node. Unfortunately, there are already available + * HiFive Unleashed devices where the timebase-frequency entry is under + * CPUs. check under parent "cpus" node to cover those devices. + */ + if (!of_property_read_u32(node->parent, "timebase-frequency", + &timebase)) + goto check; + + panic("RISC-V system with no timebase-frequency in DTS for hart [%d]\n", + hartid); + +check: + /* RISC-V ISA specification mandates that every cpu has a timer */ + if (!riscv_timebase) + riscv_timebase = timebase; + else if (riscv_timebase && riscv_timebase != timebase) + pr_warn("RISC-V system with different timebase-frequency\n"); +} + static int __init riscv_timer_init_dt(struct device_node *n) { int cpuid, hartid, error; @@ -90,10 +119,12 @@ static int __init riscv_timer_init_dt(struct device_node *n) hartid = riscv_of_processor_hartid(n); cpuid = riscv_hartid_to_cpuid(hartid); + riscv_timebase_frequency(n, hartid); if (cpuid != smp_processor_id()) return 0; + /* This should be called only for boot cpu */ cs = per_cpu_ptr(&riscv_clocksource, cpuid); clocksource_register_hz(cs, riscv_timebase); -- 2.7.4