Skip to content

Commit 98e720f

Browse files
FlyGoatchenhuacai
authored andcommitted
LoongArch: Derive timer max_delta from PRCFG1's timer_bits
As per arch spec, maximum timer bits is configurable and should not be hardcoded in any way. Probe timer bits from PRCFG1 and use that to determine the clockevent's max_delta to be conformance. Signed-off-by: Jiaxun Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 341cf99 commit 98e720f

File tree

4 files changed

+3
-2
lines changed

4 files changed

+3
-2
lines changed

arch/loongarch/include/asm/cpu-info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct cpuinfo_loongarch {
5757
int global_id; /* physical global thread number */
5858
int vabits; /* Virtual Address size in bits */
5959
int pabits; /* Physical Address size in bits */
60+
int timerbits; /* Width of arch timer in bits */
6061
unsigned int ksave_mask; /* Usable KSave mask. */
6162
unsigned int watch_dreg_count; /* Number data breakpoints */
6263
unsigned int watch_ireg_count; /* Number instruction breakpoints */

arch/loongarch/include/asm/loongarch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@
466466

467467
#define LOONGARCH_CSR_TCFG 0x41 /* Timer config */
468468
#define CSR_TCFG_VAL_SHIFT 2
469-
#define CSR_TCFG_VAL_WIDTH 48
470469
#define CSR_TCFG_VAL (_ULCAST_(0x3fffffffffff) << CSR_TCFG_VAL_SHIFT)
471470
#define CSR_TCFG_PERIOD_SHIFT 1
472471
#define CSR_TCFG_PERIOD (_ULCAST_(0x1) << CSR_TCFG_PERIOD_SHIFT)

arch/loongarch/kernel/cpu-probe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static void cpu_probe_common(struct cpuinfo_loongarch *c)
190190
set_cpu_asid_mask(c, asid_mask);
191191

192192
config = read_csr_prcfg1();
193+
c->timerbits = (config & CSR_CONF1_TMRBITS) >> CSR_CONF1_TMRBITS_SHIFT;
193194
c->ksave_mask = GENMASK((config & CSR_CONF1_KSNUM) - 1, 0);
194195
c->ksave_mask &= ~(EXC_KSAVE_MASK | PERCPU_KSAVE_MASK | KVM_KSAVE_MASK);
195196

arch/loongarch/kernel/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int constant_clockevent_init(void)
132132
#else
133133
unsigned long min_delta = 1000;
134134
#endif
135-
unsigned long max_delta = (1UL << 48) - 1;
135+
unsigned long max_delta = GENMASK_ULL(boot_cpu_data.timerbits, 0);
136136
struct clock_event_device *cd;
137137
static int irq = 0, timer_irq_installed = 0;
138138

0 commit comments

Comments
 (0)