summaryrefslogtreecommitdiff
path: root/sys/dev/pv/hyperv.c
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2021-08-31 15:52:11 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2021-08-31 15:52:11 +0000
commit4d9139667c6f31eb790d7dee4c81d177674d307c (patch)
treeae25ebed3c0234d41507996c93a01217b077ff05 /sys/dev/pv/hyperv.c
parenta6ff55c8c8dd34b44962521dd489c0dcc983bced (diff)
When running on Hyper-V, make use of its timecounter as delay func in case
we're still using the i8254 for that. On Hyper-V Gen 2 VMs there is no i8254 we can trust, so we need some kind of fallback, especially if there is no TSC either. Discussed with the hackroom ok kettenis@
Diffstat (limited to 'sys/dev/pv/hyperv.c')
-rw-r--r--sys/dev/pv/hyperv.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sys/dev/pv/hyperv.c b/sys/dev/pv/hyperv.c
index de753ccbfc9..dcebd3ae681 100644
--- a/sys/dev/pv/hyperv.c
+++ b/sys/dev/pv/hyperv.c
@@ -349,6 +349,18 @@ hv_gettime(struct timecounter *tc)
return (now);
}
+void
+hv_delay(int usecs)
+{
+ uint64_t interval, start;
+
+ /* 10 MHz fixed frequency */
+ interval = (uint64_t)usecs * 10;
+ start = rdmsr(MSR_HV_TIME_REF_COUNT);
+ while (rdmsr(MSR_HV_TIME_REF_COUNT) - start < interval)
+ CPU_BUSY_CYCLE();
+}
+
int
hv_init_hypercall(struct hv_softc *sc)
{