From patchwork Sun Oct 29 21:20:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10031759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C1D23602D6 for ; Sun, 29 Oct 2017 21:26:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2FE4286F1 for ; Sun, 29 Oct 2017 21:26:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7C8B28714; Sun, 29 Oct 2017 21:26:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 108AC286F1 for ; Sun, 29 Oct 2017 21:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=iyujwxQoRSstAE/KzsOY5K2CqU3hHJLscQYIoeJ+5+M=; b=nAjHtTtpiC5cCm8No3dDlaDsB7 MkfEphe0QBNKXeEkmf9bDo8ENm08qzm6Zt4yo+Ken0kca4bAJL8Yj3x3pAc3OvKJdvXJSL6bEVJxZ CvOLDcRyQhOqbMWs2K9vp/e8ayWs8qh9oMMsbRjrZI3CFBJvpz5gNm239u2z8xRlyD7RPCP94vuXm x2Kf7jImNjUW7fn1qJO4KyVPbxF+4GoQ6Fo0IKoCmHrADmtlNPub5ezldn1DF7W9+Yyec3Wu6vDup NT7562muGilISIriQfVc4m5q2vv6jWAuBeawCrvgfxbLd/PDDpo+FZYqnllmhsssFRbRuhCBFS+D1 iZ8rAsYw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e8v63-0001qx-HP; Sun, 29 Oct 2017 21:26:19 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e8v52-0008DY-Im for linux-arm-kernel@lists.infradead.org; Sun, 29 Oct 2017 21:25:23 +0000 Received: by mail-wm0-x243.google.com with SMTP id s66so12092469wmf.5 for ; Sun, 29 Oct 2017 14:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KzLa/zs4q6J9kwvUFKbHHqCCydwxjQBFc5Bc7Px30MQ=; b=d3VckFBNxB1im1+vFRCq+ddLhgcAXGsqQJi5PL0RLy+phfspm7AlmdLERas1KckJrP 2tkwkNilhv4u8tsFgSpzf+peuzTLZBdtes7u7pHQ3+vhc3e7pEhTAuo+70DfyJRYyt70 LyzDlFOQ43+vPALWGqAY9fUoEYxbSfCo+QIx0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KzLa/zs4q6J9kwvUFKbHHqCCydwxjQBFc5Bc7Px30MQ=; b=KNNIdb/N07/BdHUUDrejd36V+eIg/wdO5DN669gOw4uw3EC6nn6483zvKFpoWSjht0 D/0NiM97rXaLPOWNu7xLFU3P894gr3CsEW1j7zUstgDe+GtFcyCWJYBdx+iWjUStimM4 HZ1YtbDXe64PO8Wn3EqFK1UriBpwidd1e/YkJnxXhitanhuR+5gzHLoP06TGFnbggauC qjjz1vEhVqShM31exzDf2Ze6eD4/tPaPnq7K3jpAJjWeeFhUfXqijDWzW4D/aT1JmMSP PMnks2T2aIZvpq7kQqrqT66YiesuDrKMR0bxUUsJ8geJ4qkRIVSGlgrou2Cmu7mVVZg0 ivDg== X-Gm-Message-State: AMCzsaX92UNgkz5/Z9t+9IbX3VRhS/QVj1Cp/tlaS+A675oqqUq52bmG 2dwIVdzCZjkG7oPHJoDz72KYzg== X-Google-Smtp-Source: ABhQp+RlWFlG/DrsyR3m8+N5cZhELomdLn9e0PEM+bF0XMJj1d3VNcUSrvqNc7yU/ybN2mHbIdY3bg== X-Received: by 10.28.35.67 with SMTP id j64mr1853457wmj.55.1509312294669; Sun, 29 Oct 2017 14:24:54 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:2c92:b7e6:9f71:ab86]) by smtp.gmail.com with ESMTPSA id z20sm10067264wrz.62.2017.10.29.14.24.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 Oct 2017 14:24:54 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de, daniel.lezcano@linaro.org Subject: [PATCH 13/17] clocksource/drivers/arm_arch_timer: Validate CNTFRQ after enabling frame Date: Sun, 29 Oct 2017 22:20:30 +0100 Message-Id: <1509312035-17368-13-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509312035-17368-1-git-send-email-daniel.lezcano@linaro.org> References: <1509312035-17368-1-git-send-email-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171029_142517_006044_B064A551 X-CRM114-Status: GOOD ( 17.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Marc Zyngier , linux-kernel@vger.kernel.org, "moderated list:ARM ARCHITECTED TIMER DRIVER" , Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Daniel Lezcano --- drivers/clocksource/arm_arch_timer.c | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index fd4b7f6..14e2419 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;