diff --git a/sys/arch/arm/arm32/cortex_pmc.c b/sys/arch/arm/arm32/cortex_pmc.c index 3c8c401..f314f9a 100644 --- a/sys/arch/arm/arm32/cortex_pmc.c +++ b/sys/arch/arm/arm32/cortex_pmc.c @@ -75,6 +75,7 @@ cortex_pmc_ccnt_init(void) * NOTE: at 400MHz we are restricted to (uint32_t)~0 "counts" * if this is a problem, accumulate counts in LL vars */ +#ifndef ARM_KVM_GUEST void delay(u_int arg) { @@ -112,3 +113,22 @@ delay(u_int arg) } } } +#else /* ARM_KVM_GUEST */ +void +delay(u_int arg) +{ + uint64_t start; + uint64_t target; + const uint32_t counts_per_usec = COUNTS_PER_USEC; + const uint32_t delay_arg_limit = ~0UL / counts_per_usec; /* about 10 sec */ + + if (arg > delay_arg_limit) + panic("%s: arg %u overflow, limit is %u usec\n", + __func__, arg, delay_arg_limit); + + target = arg * counts_per_usec; + start = armreg_cntv_ct_read(); + while ((armreg_cntv_ct_read() - start) < target) + cpu_cpwait(); +} +#endif