From 8d8f7df74bf36ed66fd363459746aa0fa47ef861 Mon Sep 17 00:00:00 2001 From: jmatthew Date: Thu, 22 Jun 2017 06:21:12 +0000 Subject: [PATCH] Add a hypervisor-specific function pointer in pvbus(4) that gets called during cpu_hatch() on each cpu, allowing initialization of per-cpu features on each cpu as it starts up. input from reyk@ and mikeb@ ok mikeb@ --- sys/arch/amd64/amd64/cpu.c | 10 +++++++++- sys/arch/i386/i386/cpu.c | 10 +++++++++- sys/dev/pv/pvbus.c | 15 ++++++++++++++- sys/dev/pv/pvvar.h | 4 +++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index b76d0908b53..3b530d3a887 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.105 2017/05/30 15:11:32 deraadt Exp $ */ +/* $OpenBSD: cpu.c,v 1.106 2017/06/22 06:21:12 jmatthew Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -67,6 +67,7 @@ #include "lapic.h" #include "ioapic.h" #include "vmm.h" +#include "pvbus.h" #include #include @@ -103,6 +104,10 @@ #include #endif +#if NPVBUS > 0 +#include +#endif + #include #include #include @@ -728,6 +733,9 @@ cpu_hatch(void *v) lldt(0); cpu_init(ci); +#if NPVBUS > 0 + pvbus_init_cpu(); +#endif /* Re-initialise memory range handling on AP */ if (mem_range_softc.mr_op != NULL) diff --git a/sys/arch/i386/i386/cpu.c b/sys/arch/i386/i386/cpu.c index e56f8b45b3d..c87c3ec3b3e 100644 --- a/sys/arch/i386/i386/cpu.c +++ b/sys/arch/i386/i386/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.84 2017/05/30 15:11:32 deraadt Exp $ */ +/* $OpenBSD: cpu.c,v 1.85 2017/06/22 06:21:12 jmatthew Exp $ */ /* $NetBSD: cpu.c,v 1.1.2.7 2000/06/26 02:04:05 sommerfeld Exp $ */ /*- @@ -67,6 +67,7 @@ #include "lapic.h" #include "ioapic.h" #include "vmm.h" +#include "pvbus.h" #include #include @@ -104,6 +105,10 @@ #include #endif +#if NPVBUS > 0 +#include +#endif + #include #include #include @@ -626,6 +631,9 @@ cpu_hatch(void *v) ci->ci_curpmap = pmap_kernel(); cpu_init(ci); +#if NPVBUS > 0 + pvbus_init_cpu(); +#endif /* Re-initialise memory range handling on AP */ if (mem_range_softc.mr_op != NULL) diff --git a/sys/dev/pv/pvbus.c b/sys/dev/pv/pvbus.c index ecc60b3c6b3..902221ec6f5 100644 --- a/sys/dev/pv/pvbus.c +++ b/sys/dev/pv/pvbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pvbus.c,v 1.16 2017/01/10 17:16:39 reyk Exp $ */ +/* $OpenBSD: pvbus.c,v 1.17 2017/06/22 06:21:12 jmatthew Exp $ */ /* * Copyright (c) 2015 Reyk Floeter @@ -210,6 +210,19 @@ pvbus_identify(void) has_hv_cpuid = 1; } +void +pvbus_init_cpu(void) +{ + int i; + + for (i = 0; i < PVBUS_MAX; i++) { + if (pvbus_hv[i].hv_base == 0) + continue; + if (pvbus_hv[i].hv_init_cpu != NULL) + (pvbus_hv[i].hv_init_cpu)(&pvbus_hv[i]); + } +} + int pvbus_activate(struct device *self, int act) { diff --git a/sys/dev/pv/pvvar.h b/sys/dev/pv/pvvar.h index b4dbf32929a..4e23ae52bd5 100644 --- a/sys/dev/pv/pvvar.h +++ b/sys/dev/pv/pvvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pvvar.h,v 1.9 2017/01/10 17:16:39 reyk Exp $ */ +/* $OpenBSD: pvvar.h,v 1.10 2017/06/22 06:21:12 jmatthew Exp $ */ /* * Copyright (c) 2015 Reyk Floeter @@ -56,6 +56,7 @@ struct pvbus_hv { void *hv_arg; int (*hv_kvop)(void *, int, char *, char *, size_t); + void (*hv_init_cpu)(struct pvbus_hv *); }; struct pvbus_softc { @@ -77,6 +78,7 @@ struct pv_attach_args { void pvbus_identify(void); int pvbus_probe(void); +void pvbus_init_cpu(void); void pvbus_reboot(struct device *); void pvbus_shutdown(struct device *); -- 2.20.1