Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3751836rwe; Mon, 17 Apr 2023 03:04:50 -0700 (PDT) X-Google-Smtp-Source: AKy350ZSuiZik3KQuZ49KyFySm/k0e2hwPx1VC6sRttz5mNDGUOL/cfT+wkz6S7xxAgX2g9MQr6L X-Received: by 2002:a05:6a00:80d:b0:637:d692:fbda with SMTP id m13-20020a056a00080d00b00637d692fbdamr20894512pfk.6.1681725890365; Mon, 17 Apr 2023 03:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681725890; cv=none; d=google.com; s=arc-20160816; b=JzqFBFskq9oLSSf4chAp8HS6klnv/lJD+iIk56usuii4g/ard/N2Hh0Csw5cTLdQ5Q Sg5CPWsPHDAErRMizf+oqEFdpo1jHsUlsdvRqJ6qLw9BQtkgrLhSyCTBv4lkEywCIQxq P9bSO3/hiPiUCdpAtzvcEQQnEoMupPWMP+zbTgwW/K/vsPqzKVI3Y8rHcHm9HLodcu4N KSjnDJGEsLjFRmEjYysj9SORL4emFQV5EGEh4Eb0czNkdQ5FKCJwMA4mG1XmOVqwloAw 7uwJ1q1mNnD8w3RdS5KoCAo54jRh9YEczh0oq1F7N/u6ipQWdxDzy9BTgkT062zXKlu2 PWbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=OK6P58x0m7vLvplwz340XhE9IhH6CK4jlCcZUmcdwjg=; b=0Iqk6vDT5f9TL1y1ZgZhswAzb90f1YqFo/QFBuCYYldpmkyALrQxdsru+z2QrI7qd1 pJBsw/ByWe5Lg6JzzKlPk3ZlIVHIboZ31OnVfz8kx1v64MBhddbgMPRtX6EFg2+OYo8n cA3aHph39ukzAYUpmvBBqM3BE3Bs80MLjp+TPxpX/sZTxP5IxTKbDnGax32NtwzsjmCh USjQD9pnUJqTOtsPCsea5CboMt+Q41faB5BU3Xq+xBnNZ9D2TPrccWF0JOlIcqXAQJf6 mLceyQEYUNX7pGyORH++rs8kgfp/ilpX2RlI1hrlIy7Rv/rXK8T0ZcRNDAA1yue7Hyuv n99Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="I9U/Xvg6"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r204-20020a632bd5000000b0050f64740c13si11995792pgr.622.2023.04.17.03.04.38; Mon, 17 Apr 2023 03:04:50 -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=@collabora.com header.s=mail header.b="I9U/Xvg6"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231161AbjDQKEZ (ORCPT + 99 others); Mon, 17 Apr 2023 06:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbjDQKD0 (ORCPT ); Mon, 17 Apr 2023 06:03:26 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B39A69759; Mon, 17 Apr 2023 03:02:32 -0700 (PDT) Received: from [IPV6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2] (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 007E26603050; Mon, 17 Apr 2023 11:01:17 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1681725679; bh=B0H7Xc8pFJmEgctk+ZRRF3aNKm7rElFH0bnnlDlQbD4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=I9U/Xvg6M9NzMGqGFPDKP+SNzfidPj4xuKy5l3xAe+xzrJsSasPjxW/UmVJ9HYX5O fJf0X6VoV3NLH8YmOWvrl+bE/JIr9G4QDsIo1Ze5VRKj1Ka9NM/rQIRBFiN4Mb3U0h K8Wqv6nPJsbJBPNEfSHcX0DIpvxU4vJ4vjeZjiT+dkwOKAmC7QfiYQwvJtcOiiqv+c S/yj8Mkc/X5lhArSCPu8t7C+AKLEVvJDr1N1bojF0MSH9Hsob5L43gcVpgpUmqAOZf OyygQWO6S1yOMWd3pueGDa9965KjEM89yYvG4CGktP5UdcjZRYKlvltI60jDb5yQR8 AtHuQrS1OGfAg== Message-ID: Date: Mon, 17 Apr 2023 12:01:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH] clocksource/drivers/arm_arch_timer: Add workaround for MediaTek MMIO timer Content-Language: en-US To: walter.chang@mediatek.com, Catalin Marinas , Will Deacon , Jonathan Corbet , Daniel Lezcano , Thomas Gleixner , Mark Rutland , Marc Zyngier , Matthias Brugger Cc: wsd_upstream@mediatek.com, stanley.chu@mediatek.com, Chun-hung.Wu@mediatek.com, Freddy.Hsin@mediatek.com, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org References: <20230417090635.13202-1-walter.chang@mediatek.com> From: AngeloGioacchino Del Regno In-Reply-To: <20230417090635.13202-1-walter.chang@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 Il 17/04/23 11:06, walter.chang@mediatek.com ha scritto: > From: Walter Chang > > The MT69XX series SoCs have the incomplete implementation issue in the > mmio timer. Specifically, the hardware only implements the TVAL > functionality, but not the CVAL functionality. This hardware limitation > will cause set_next_event_mem() fail to set the actual expiration time > when writing a value to the CVAL. On these platforms, the mmio timer's > internal expiration time will still be judged as 0 (the value of TVAL), > resulting in the mmio timer not functioning as intended. > > The workaround is to use TVAL in addition to CVAL for these affected > platforms. > > Signed-off-by: Walter Chang > --- > Documentation/arm64/silicon-errata.rst | 4 ++++ > drivers/clocksource/Kconfig | 9 ++++++++ > drivers/clocksource/arm_arch_timer.c | 29 ++++++++++++++++++++++++++ > 3 files changed, 42 insertions(+) > > diff --git a/Documentation/arm64/silicon-errata.rst b/Documentation/arm64/silicon-errata.rst > index ec5f889d7681..ca1893713a4c 100644 > --- a/Documentation/arm64/silicon-errata.rst > +++ b/Documentation/arm64/silicon-errata.rst > @@ -209,3 +209,7 @@ stable kernels. > +----------------+-----------------+-----------------+-----------------------------+ > | Fujitsu | A64FX | E#010001 | FUJITSU_ERRATUM_010001 | > +----------------+-----------------+-----------------+-----------------------------+ > + > ++----------------+-----------------+-----------------+-----------------------------+ > +| MediaTek | MT69XX series | #690001 | MEDIATEK_ERRATUM_690001 | > ++----------------+-----------------+-----------------+-----------------------------+ > diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig > index 5fc8f0e7fb38..475356b8dbdc 100644 > --- a/drivers/clocksource/Kconfig > +++ b/drivers/clocksource/Kconfig > @@ -368,6 +368,15 @@ config SUN50I_ERRATUM_UNKNOWN1 > the Allwinner A64 SoC. The workaround will only be active if the > allwinner,erratum-unknown1 property is found in the timer node. > > +config MEDIATEK_ERRATUM_690001 > + bool "Workaround for MediaTek MT69XX erratum 690001" > + depends on ARM_ARCH_TIMER && ARM64 > + help > + This option enables a workaround for incomplete implementation > + in the MMIO timer on the MediaTek MT69XX SoCs. The workaround > + will only be active if mediatek,erratum-690001 property is > + found in the timer node. > + > config ARM_GLOBAL_TIMER > bool "Support for the ARM global timer" if COMPILE_TEST > select TIMER_OF if OF > diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c > index e09d4427f604..920570d57fc0 100644 > --- a/drivers/clocksource/arm_arch_timer.c > +++ b/drivers/clocksource/arm_arch_timer.c > @@ -389,6 +389,10 @@ static u64 notrace sun50i_a64_read_cntvct_el0(void) > } > #endif > > +#ifdef CONFIG_MEDIATEK_ERRATUM_690001 > +static bool arch_timer_mem_sne_use_tval __ro_after_init; What about reusing part of the CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND logic and adding something like CONFIG_ARM_ARCH_TIMER_MEM_WORKAROUND? That would make you able to reuse the already existing infrastructure to parse the device-tree and possibly more. Regards, Angelo > +#endif > + > #ifdef CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND > DEFINE_PER_CPU(const struct arch_timer_erratum_workaround *, timer_unstable_counter_workaround); > EXPORT_SYMBOL_GPL(timer_unstable_counter_workaround); > @@ -783,6 +787,19 @@ static __always_inline void set_next_event_mem(const int access, unsigned long e > cnt = arch_counter_get_cnt_mem(timer, CNTPCT_LO); > > arch_timer_reg_write(access, ARCH_TIMER_REG_CVAL, evt + cnt, clk); > +#ifdef CONFIG_MEDIATEK_ERRATUM_690001 > + if (arch_timer_mem_sne_use_tval) { > + /* Due to the incomplete implementation of mmio timer on > + * specific MediaTek platforms, CVAL has not been implemented. > + * Therefore, the workaround is to use TVAL in addition to > + * CVAL. > + */ > + if (access == ARCH_TIMER_MEM_VIRT_ACCESS) > + writel_relaxed(evt, timer->base + 0x38); > + else > + writel_relaxed(evt, timer->base + 0x28); > + } > +#endif > arch_timer_reg_write(access, ARCH_TIMER_REG_CTRL, ctrl, clk); > } > > @@ -878,7 +895,16 @@ static void __arch_timer_setup(unsigned type, > arch_timer_set_next_event_phys_mem; > } > > +#ifdef CONFIG_MEDIATEK_ERRATUM_690001 > + if (arch_timer_mem_sne_use_tval) { > + pr_info("Enabling mediatek,erratum-690001 for mmio timer\n"); > + max_delta = CLOCKSOURCE_MASK(31); > + } else { > + max_delta = CLOCKSOURCE_MASK(56); > + } > +#else > max_delta = CLOCKSOURCE_MASK(56); > +#endif > } > > clk->set_state_shutdown(clk); > @@ -1591,6 +1617,9 @@ static int __init arch_timer_mem_of_init(struct device_node *np) > frame->valid = true; > } > > +#ifdef CONFIG_MEDIATEK_ERRATUM_690001 > + arch_timer_mem_sne_use_tval = of_property_read_bool(np, "mediatek,erratum-690001"); > +#endif > frame = arch_timer_mem_find_best_frame(timer_mem); > if (!frame) { > pr_err("Unable to find a suitable frame in timer @ %pa\n",