Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1299591pxb; Wed, 6 Apr 2022 14:12:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1vbBgRvYX+/ZqxgfOLElgEaYICaKga/XOhH9GyQi1zgSU0l11qHG+zUxVYoqlDN50ZiAl X-Received: by 2002:a17:903:110c:b0:14a:f110:84e1 with SMTP id n12-20020a170903110c00b0014af11084e1mr10586703plh.7.1649279540376; Wed, 06 Apr 2022 14:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649279540; cv=none; d=google.com; s=arc-20160816; b=d6bawytiwzyi+b9BnQq96TGCwq/S9jRSEb8mvqkMiAa1H74yl5E5bZuqB9YnXjjRkJ 1yfA0+C/1q9qrQC8j28QFQtjpjI7YjL7RHYHHzRV0X84Z/qA8mWbWwveAq6jpi4zj/Ht 9WlGETGalYfbSSyhqtufbNpNzcIKLwKJaDGb94JhsJPJl0r1aFDQy61PeEmN5p91Kelp c5qP+PP/56ZisyBxnnmQFYJrmc92sOYtzaGfJWqafKHdBZX6Gfmh89m0Fx45NJHtdJIC ZxhPVq010Ps2q6PqxSqrp6WmUi0aKgvvRzmIT9f6cWcXPmeSrDY0KAovmAgR2YwGQWrY 8TbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pHmCPJDzipqAkTU8EflDAIp2YUaIb/RNX2FugWMeGv8=; b=cZib00jrNKUqDJMBk0bUQjD9+h0xq0P87WK3NMcV4h6Mkn5ai3+IKzoOvVzYF8bk1t GvXRSGEv+S0kPWlKhst1NOr5nhU339keiKyJ0FMH5qRs7M94+SiyVC8HQMT/fL5rlnmI +tjByn/XcDmDRh38VyiSq23e/h7ORvr2+5Q+ue8Iya57EFozoZaLyf6ilJDfya1C4p/J VrxQOfArW5lklrYcoilkymRRCbSkDEOsHpW18aecAHJRoJMB7mtx1DB9Rp0TMrg0BLy2 QBvtotq2JWLYbJ59ZsQF+SJSGVTAtzTBBLfW9DN6001TtF3Ba2S8ucagGsctCrYtjcmQ Ja1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oaw8xf87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf6-20020a656d06000000b003816043eed3si17393343pgb.200.2022.04.06.14.12.01; Wed, 06 Apr 2022 14:12:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oaw8xf87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231977AbiDFUK1 (ORCPT + 99 others); Wed, 6 Apr 2022 16:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233698AbiDFUKQ (ORCPT ); Wed, 6 Apr 2022 16:10:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46FB7CF4B3; Wed, 6 Apr 2022 11:27:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EBF7EB824E1; Wed, 6 Apr 2022 18:27:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F23CC385A3; Wed, 6 Apr 2022 18:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649269634; bh=T0hUhy+ZEHBPKg8ig2zcn/mvi2SifcsVfTmk4w6GxtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oaw8xf875UaT0VQxcuA/kQ3b7gN4z7SfO+5nKQGfFptaozx7OjQh3vpreNSxVerQ2 RyNFd4TfsT/ZtRcTF4J6ATLdgLwSpRU43GeFKUZS1ehyg2PCV7GM1aSW26/xJb3alK eigwSgnTvmpy95VZ5cXcPSVaroZOqCNalIDOAjxc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Hanjun Guo , Marc Zyngier , James Morse Subject: [PATCH 4.9 14/43] arm64: arch_timer: Add infrastructure for multiple erratum detection methods Date: Wed, 6 Apr 2022 20:26:23 +0200 Message-Id: <20220406182437.099454875@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406182436.675069715@linuxfoundation.org> References: <20220406182436.675069715@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit 651bb2e9dca6e6dbad3fba5f6e6086a23575b8b5 upstream. We're currently stuck with DT when it comes to handling errata, which is pretty restrictive. In order to make things more flexible, let's introduce an infrastructure that could support alternative discovery methods. No change in functionality. Acked-by: Thomas Gleixner Reviewed-by: Hanjun Guo Signed-off-by: Marc Zyngier [ morse: Removed the changes to HiSilicon erratum 161010101, which isn't present in v4.9 ] Signed-off-by: James Morse Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/arch_timer.h | 7 ++- drivers/clocksource/arm_arch_timer.c | 81 ++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 12 deletions(-) --- a/arch/arm64/include/asm/arch_timer.h +++ b/arch/arm64/include/asm/arch_timer.h @@ -37,9 +37,14 @@ extern struct static_key_false arch_time #define needs_unstable_timer_counter_workaround() false #endif +enum arch_timer_erratum_match_type { + ate_match_dt, +}; struct arch_timer_erratum_workaround { - const char *id; /* Indicate the Erratum ID */ + enum arch_timer_erratum_match_type match_type; + const void *id; + const char *desc; u32 (*read_cntp_tval_el0)(void); u32 (*read_cntv_tval_el0)(void); u64 (*read_cntvct_el0)(void); --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -140,13 +140,81 @@ EXPORT_SYMBOL_GPL(arch_timer_read_ool_en static const struct arch_timer_erratum_workaround ool_workarounds[] = { #ifdef CONFIG_FSL_ERRATUM_A008585 { + .match_type = ate_match_dt, .id = "fsl,erratum-a008585", + .desc = "Freescale erratum a005858", .read_cntp_tval_el0 = fsl_a008585_read_cntp_tval_el0, .read_cntv_tval_el0 = fsl_a008585_read_cntv_tval_el0, .read_cntvct_el0 = fsl_a008585_read_cntvct_el0, }, #endif }; + +typedef bool (*ate_match_fn_t)(const struct arch_timer_erratum_workaround *, + const void *); + +static +bool arch_timer_check_dt_erratum(const struct arch_timer_erratum_workaround *wa, + const void *arg) +{ + const struct device_node *np = arg; + + return of_property_read_bool(np, wa->id); +} + +static const struct arch_timer_erratum_workaround * +arch_timer_iterate_errata(enum arch_timer_erratum_match_type type, + ate_match_fn_t match_fn, + void *arg) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ool_workarounds); i++) { + if (ool_workarounds[i].match_type != type) + continue; + + if (match_fn(&ool_workarounds[i], arg)) + return &ool_workarounds[i]; + } + + return NULL; +} + +static +void arch_timer_enable_workaround(const struct arch_timer_erratum_workaround *wa) +{ + timer_unstable_counter_workaround = wa; + static_branch_enable(&arch_timer_read_ool_enabled); +} + +static void arch_timer_check_ool_workaround(enum arch_timer_erratum_match_type type, + void *arg) +{ + const struct arch_timer_erratum_workaround *wa; + ate_match_fn_t match_fn = NULL; + + if (static_branch_unlikely(&arch_timer_read_ool_enabled)) + return; + + switch (type) { + case ate_match_dt: + match_fn = arch_timer_check_dt_erratum; + break; + default: + WARN_ON(1); + return; + } + + wa = arch_timer_iterate_errata(type, match_fn, arg); + if (!wa) + return; + + arch_timer_enable_workaround(wa); + pr_info("Enabling global workaround for %s\n", wa->desc); +} + +#else +#define arch_timer_check_ool_workaround(t,a) do { } while(0) #endif /* CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND */ static __always_inline @@ -919,17 +987,8 @@ static int __init arch_timer_of_init(str arch_timer_c3stop = !of_property_read_bool(np, "always-on"); -#ifdef CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND - for (i = 0; i < ARRAY_SIZE(ool_workarounds); i++) { - if (of_property_read_bool(np, ool_workarounds[i].id)) { - timer_unstable_counter_workaround = &ool_workarounds[i]; - static_branch_enable(&arch_timer_read_ool_enabled); - pr_info("arch_timer: Enabling workaround for %s\n", - timer_unstable_counter_workaround->id); - break; - } - } -#endif + /* Check for globally applicable workarounds */ + arch_timer_check_ool_workaround(ate_match_dt, np); /* * If we cannot rely on firmware initializing the timer registers then