From patchwork Mon Oct 16 15:28:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115924 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3813436qgn; Mon, 16 Oct 2017 08:28:56 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TSXOmUQErTuAcLm4kUIE36nR5PZNmuBYaaWSJxWwG6OtVwKVfTYbgQ8bzMHwhqo7GDc+mC X-Received: by 10.99.94.198 with SMTP id s189mr6261735pgb.32.1508167736591; Mon, 16 Oct 2017 08:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508167736; cv=none; d=google.com; s=arc-20160816; b=OjmYIXpT8Q53PsnMZmm6lqDo8B06cgucEFDE+IQNMP8VJM90ttGG7JH5IDiO+p6qV4 T2Mjyr6XmZ1xWGx6GDV6p/8GSaaQtxp5K7MpcLwlcYhWB8k7+IEri7slSFBbOEpS1VaO ygYRGfuPsmHyDEC7wg3aNxaUtW4w3rCq86/mb99d3aCTbBylhQ6PFg5JYEW8YSiTG/sK NMYS/JEDLlgbzsgLidzVNpYcqTW7frr8TUJOlXJsL1kIp6hzkzLNzlXnR/BCxVtQSecH Ky4bkXwQvHdpOV5FVxTRooJ4oJOZpc5kjZVhJFnMGQBAjPcg0lLhFxsp7w4YCUKTQiAs fNZg== 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:arc-authentication-results; bh=9ZoLs53fCIPfiaYUbtdl9T1eD4tBoiL113nCgt4tCMM=; b=MTI7XHJ/ZgOglhW+0yAFclmUvb5RAN/7YtelBPcsCo7Q+RoeuAWF75Jy0/CQxqlfAW KTkLffFHlnZmkJYdzl0JqEFtgsLa6T/HaBEx70TfHD+bOLMVZ2wgeyV69LQTcfuzTUkn 8B3rkl2wkL6Sx05/r/RGQA97gZ4AsHzCMNB0z37oEB7RjorxdrG1zWUpFr5A+0To+fZi +rcKvRTBwVLxf3qfK/Tpa1NQvA97ZaU3smlqlDCOsMgU+HReDDVgOHj5Kf1et3T0QNvB YJjZtHfUwWdb7kOKPjyfYQRiPX5MIgNQFqFwd7JZTkZzS4m29Vlisp/LT/jv/rSaZWGF P5GA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si3244889pge.370.2017.10.16.08.28.56; Mon, 16 Oct 2017 08:28:56 -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; Authentication-Results: mx.google.com; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754056AbdJPP2w (ORCPT + 27 others); Mon, 16 Oct 2017 11:28:52 -0400 Received: from foss.arm.com ([217.140.101.70]:58572 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753693AbdJPP2u (ORCPT ); Mon, 16 Oct 2017 11:28:50 -0400 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 A493315A2; Mon, 16 Oct 2017 08:28:50 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4EFE23F483; Mon, 16 Oct 2017 08:28:49 -0700 (PDT) From: Mark Rutland To: daniel.lezcano@linaro.org Cc: marc.zyngier@arm.com, tglx@linutronix.de, ard.biesheuvel@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Rutland Subject: [PATCH 1/2] clocksource: arm_arch_timer: validate CNTFRQ after enabling frame Date: Mon, 16 Oct 2017 16:28:38 +0100 Message-Id: <20171016152839.14964-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171016152839.14964-1-mark.rutland@arm.com> References: <20171016152839.14964-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel The ACPI GTDT code validates the CNTFRQ field of each MMIO timer frame against the CNTFRQ system register of the current CPU, to ensure that they are equal, which is mandated by the architecture. However, reading the CNTFRQ field of a frame is not possible until the RFRQ bit in the frame's CNTACRn register is set, and doing so before that willl produce the following error: arch_timer: [Firmware Bug]: CNTFRQ mismatch: frame @ 0x00000000e0be0000: (0x00000000), CPU: (0x0ee6b280) arch_timer: Disabling MMIO timers due to CNTFRQ mismatch arch_timer: Failed to initialize memory-mapped timer. The reason is that the CNTFRQ field is RES0 if access is not enabled. So move the validation of CNTFRQ into the loop that iterates over the timers to find the best frame, but defer it until after we have selected the best frame, which should also have enabled the RFRQ bit. Signed-off-by: Ard Biesheuvel Signed-off-by: Mark Rutland --- drivers/clocksource/arm_arch_timer.c | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) -- 2.11.0 diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index fd4b7f684bd0..14e2419063e9 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -1268,10 +1268,6 @@ arch_timer_mem_find_best_frame(struct arch_timer_mem *timer_mem) iounmap(cntctlbase); - if (!best_frame) - pr_err("Unable to find a suitable frame in timer @ %pa\n", - &timer_mem->cntctlbase); - return best_frame; } @@ -1372,6 +1368,8 @@ static int __init arch_timer_mem_of_init(struct device_node *np) frame = arch_timer_mem_find_best_frame(timer_mem); if (!frame) { + pr_err("Unable to find a suitable frame in timer @ %pa\n", + &timer_mem->cntctlbase); ret = -EINVAL; goto out; } @@ -1420,7 +1418,7 @@ arch_timer_mem_verify_cntfrq(struct arch_timer_mem *timer_mem) static int __init arch_timer_mem_acpi_init(int platform_timer_count) { struct arch_timer_mem *timers, *timer; - struct arch_timer_mem_frame *frame; + struct arch_timer_mem_frame *frame, *best_frame = NULL; int timer_count, i, ret = 0; timers = kcalloc(platform_timer_count, sizeof(*timers), @@ -1432,14 +1430,6 @@ static int __init arch_timer_mem_acpi_init(int platform_timer_count) if (ret || !timer_count) goto out; - for (i = 0; i < timer_count; i++) { - ret = arch_timer_mem_verify_cntfrq(&timers[i]); - if (ret) { - pr_err("Disabling MMIO timers due to CNTFRQ mismatch\n"); - goto out; - } - } - /* * While unlikely, it's theoretically possible that none of the frames * in a timer expose the combination of feature we want. @@ -1448,12 +1438,26 @@ static int __init arch_timer_mem_acpi_init(int platform_timer_count) timer = &timers[i]; frame = arch_timer_mem_find_best_frame(timer); - if (frame) - break; + if (!best_frame) + best_frame = frame; + + ret = arch_timer_mem_verify_cntfrq(timer); + if (ret) { + pr_err("Disabling MMIO timers due to CNTFRQ mismatch\n"); + goto out; + } + + if (!best_frame) /* implies !frame */ + /* + * Only complain about missing suitable frames if we + * haven't already found one in a previous iteration. + */ + pr_err("Unable to find a suitable frame in timer @ %pa\n", + &timer->cntctlbase); } - if (frame) - ret = arch_timer_mem_frame_register(frame); + if (best_frame) + ret = arch_timer_mem_frame_register(best_frame); out: kfree(timers); return ret;