Skip to content

Commit 012f188

Browse files
Marc Zyngierdlezcano
authored andcommitted
clocksource/drivers/arm_arch_timer: Work around broken CVAL implementations
The Applied Micro XGene-1 SoC has a busted implementation of the CVAL register: it looks like it is based on TVAL instead of the other way around. The net effect of this implementation blunder is that the maximum deadline you can program in the timer is 32bit wide. Use a MIDR check to notice the broken CPU, and reduce the width of the timer to 32bit. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent 30aa08d commit 012f188

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

drivers/clocksource/arm_arch_timer.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,32 @@ static int arch_timer_set_next_event_phys_mem(unsigned long evt,
780780
return 0;
781781
}
782782

783+
static u64 __arch_timer_check_delta(void)
784+
{
785+
#ifdef CONFIG_ARM64
786+
const struct midr_range broken_cval_midrs[] = {
787+
/*
788+
* XGene-1 implements CVAL in terms of TVAL, meaning
789+
* that the maximum timer range is 32bit. Shame on them.
790+
*/
791+
MIDR_ALL_VERSIONS(MIDR_CPU_MODEL(ARM_CPU_IMP_APM,
792+
APM_CPU_PART_POTENZA)),
793+
{},
794+
};
795+
796+
if (is_midr_in_range_list(read_cpuid_id(), broken_cval_midrs)) {
797+
pr_warn_once("Broken CNTx_CVAL_EL1, limiting width to 32bits");
798+
return CLOCKSOURCE_MASK(32);
799+
}
800+
#endif
801+
return CLOCKSOURCE_MASK(56);
802+
}
803+
783804
static void __arch_timer_setup(unsigned type,
784805
struct clock_event_device *clk)
785806
{
807+
u64 max_delta;
808+
786809
clk->features = CLOCK_EVT_FEAT_ONESHOT;
787810

788811
if (type == ARCH_TIMER_TYPE_CP15) {
@@ -814,6 +837,7 @@ static void __arch_timer_setup(unsigned type,
814837
}
815838

816839
clk->set_next_event = sne;
840+
max_delta = __arch_timer_check_delta();
817841
} else {
818842
clk->features |= CLOCK_EVT_FEAT_DYNIRQ;
819843
clk->name = "arch_mem_timer";
@@ -830,11 +854,13 @@ static void __arch_timer_setup(unsigned type,
830854
clk->set_next_event =
831855
arch_timer_set_next_event_phys_mem;
832856
}
857+
858+
max_delta = CLOCKSOURCE_MASK(56);
833859
}
834860

835861
clk->set_state_shutdown(clk);
836862

837-
clockevents_config_and_register(clk, arch_timer_rate, 0xf, CLOCKSOURCE_MASK(56));
863+
clockevents_config_and_register(clk, arch_timer_rate, 0xf, max_delta);
838864
}
839865

840866
static void arch_timer_evtstrm_enable(int divider)

0 commit comments

Comments
 (0)