diff options
-rw-r--r-- | sys/arch/amd64/amd64/identcpu.c | 12 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/mainbus.c | 20 | ||||
-rw-r--r-- | sys/arch/amd64/conf/GENERIC | 6 | ||||
-rw-r--r-- | sys/arch/amd64/conf/files.amd64 | 8 | ||||
-rw-r--r-- | sys/arch/i386/conf/GENERIC | 6 | ||||
-rw-r--r-- | sys/arch/i386/conf/files.i386 | 8 | ||||
-rw-r--r-- | sys/arch/i386/i386/machdep.c | 12 | ||||
-rw-r--r-- | sys/arch/i386/i386/mainbus.c | 20 | ||||
-rw-r--r-- | sys/conf/files | 6 | ||||
-rw-r--r-- | sys/dev/pv/files.pv | 14 | ||||
-rw-r--r-- | sys/dev/pv/pvbus.c | 193 | ||||
-rw-r--r-- | sys/dev/pv/pvreg.h | 45 | ||||
-rw-r--r-- | sys/dev/pv/pvvar.h (renamed from sys/dev/vmtvar.h) | 33 | ||||
-rw-r--r-- | sys/dev/vmt.c | 7 |
14 files changed, 353 insertions, 37 deletions
diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index ed7dbd336d7..e074300642b 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identcpu.c,v 1.62 2015/05/28 20:10:58 guenther Exp $ */ +/* $OpenBSD: identcpu.c,v 1.63 2015/07/21 03:38:22 reyk Exp $ */ /* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */ /* @@ -56,6 +56,11 @@ int amd64_has_aesni; #endif int has_rdrand; +#include "pvbus.h" +#if NPVBUS > 0 +#include <dev/pv/pvvar.h> +#endif + const struct { u_int32_t bit; char str[12]; @@ -561,6 +566,11 @@ identifycpu(struct cpu_info *ci) if (cpu_ecxfeature & CPUIDECX_RDRAND) has_rdrand = 1; +#if NPVBUS > 0 + if (cpu_ecxfeature & CPUIDECX_HV) + has_hv_cpuid = 1; +#endif + if (ci->ci_feature_sefflags & SEFF0EBX_SMAP) replacesmap(); } diff --git a/sys/arch/amd64/amd64/mainbus.c b/sys/arch/amd64/amd64/mainbus.c index b0dc4c04da4..4bfb0601f4d 100644 --- a/sys/arch/amd64/amd64/mainbus.c +++ b/sys/arch/amd64/amd64/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.28 2015/03/14 03:38:46 jsg Exp $ */ +/* $OpenBSD: mainbus.c,v 1.29 2015/07/21 03:38:22 reyk Exp $ */ /* $NetBSD: mainbus.c,v 1.1 2003/04/26 18:39:29 fvdl Exp $ */ /* @@ -48,7 +48,7 @@ #include "ipmi.h" #include "bios.h" #include "mpbios.h" -#include "vmt.h" +#include "pvbus.h" #include <machine/cpuvar.h> #include <machine/i82093var.h> @@ -59,8 +59,8 @@ #include <dev/ipmivar.h> #endif -#if NVMT > 0 -#include <dev/vmtvar.h> +#if NPVBUS > 0 +#include <dev/pv/pvvar.h> #endif #if NBIOS > 0 @@ -92,6 +92,9 @@ union mainbus_attach_args { #if NBIOS > 0 struct bios_attach_args mba_bios; #endif +#if NPVBUS > 0 + struct pvbus_attach_args mba_pvba; +#endif }; /* @@ -170,10 +173,11 @@ mainbus_attach(struct device *parent, struct device *self, void *aux) } #endif -#if NVMT > 0 - if (vmt_probe()) { - mba.mba_busname = "vmt"; - config_found(self, &mba.mba_busname, mainbus_print); +#if NPVBUS > 0 + /* Probe first to hide the "not configured" message */ + if (pvbus_probe()) { + mba.mba_pvba.pvba_busname = "pvbus"; + config_found(self, &mba.mba_pvba.pvba_busname, mainbus_print); } #endif diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC index cb96cf9aa6d..33e8361c22d 100644 --- a/sys/arch/amd64/conf/GENERIC +++ b/sys/arch/amd64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.390 2015/07/19 18:17:06 bmercer Exp $ +# $OpenBSD: GENERIC,v 1.391 2015/07/21 03:38:22 reyk Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -38,6 +38,7 @@ isa0 at pcib? isa0 at amdpcib? isa0 at tcpcib? pci* at mainbus0 +pvbus0 at mainbus0 acpi0 at bios0 acpitimer* at acpi? @@ -64,7 +65,8 @@ aibs* at acpi? mpbios0 at bios0 ipmi0 at mainbus? disable # IPMI -vmt0 at mainbus? # VMware Tools + +vmt0 at pvbus? # VMware Tools option PCIVERBOSE option USBVERBOSE diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index 270dffd2cb7..57942f9410c 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.amd64,v 1.78 2015/07/17 22:52:28 tedu Exp $ +# $OpenBSD: files.amd64,v 1.79 2015/07/21 03:38:22 reyk Exp $ maxpartitions 16 maxusers 2 16 128 @@ -234,8 +234,10 @@ include "dev/onewire/files.onewire" # attach ipmi at mainbus -# VMware Tools -attach vmt at mainbus +# +# Paravirtual device bus +# +include "dev/pv/files.pv" # # device major numbers diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC index 13767a85c8f..a2378e6fc4d 100644 --- a/sys/arch/i386/conf/GENERIC +++ b/sys/arch/i386/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.800 2015/07/19 18:17:06 bmercer Exp $ +# $OpenBSD: GENERIC,v 1.801 2015/07/21 03:38:22 reyk Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -42,10 +42,12 @@ acpi0 at bios? mpbios0 at bios0 pcibios0 at bios0 flags 0x0000 # use 0x30 for a total verbose ipmi0 at mainbus? disable # IPMI -vmt0 at mainbus? # VMware Tools esm0 at mainbus? # Dell Embedded Server Management amdmsr0 at mainbus? # MSR access for AMD Geode LX CPUs with GP +pvbus0 at mainbus0 # Paravirtual device bus +vmt0 at pvbus? # VMware Tools + acpitimer* at acpi? acpihpet* at acpi? acpiac* at acpi? diff --git a/sys/arch/i386/conf/files.i386 b/sys/arch/i386/conf/files.i386 index a1b2c3b8b1c..25e96b1cbfe 100644 --- a/sys/arch/i386/conf/files.i386 +++ b/sys/arch/i386/conf/files.i386 @@ -1,4 +1,4 @@ -# $OpenBSD: files.i386,v 1.224 2015/07/17 22:52:28 tedu Exp $ +# $OpenBSD: files.i386,v 1.225 2015/07/21 03:38:22 reyk Exp $ # # new style config file for i386 architecture # @@ -392,8 +392,10 @@ file arch/i386/i386/acpi_wakecode.S acpi & !small_kernel # attach ipmi at mainbus -# VMware Tools -attach vmt at mainbus +# +# Paravirtual device bus +# +include "dev/pv/files.pv" # Dell Embedded Systems Management device esm diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 959832f4dc0..1dc4a2637fc 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.573 2015/07/16 23:03:40 sf Exp $ */ +/* $OpenBSD: machdep.c,v 1.574 2015/07/21 03:38:22 reyk Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -316,6 +316,11 @@ int allowaperture = 0; int has_rdrand; +#include "pvbus.h" +#if NPVBUS > 0 +#include <dev/pv/pvvar.h> +#endif + void winchip_cpu_setup(struct cpu_info *); void amd_family5_setperf_setup(struct cpu_info *); void amd_family5_setup(struct cpu_info *); @@ -2011,6 +2016,11 @@ identifycpu(struct cpu_info *ci) if (ci->ci_feature_sefflags & SEFF0EBX_SMAP) replacesmap(); #endif + +#if NPVBUS > 0 + if (cpu_ecxfeature & CPUIDECX_HV) + has_hv_cpuid = 1; +#endif } #ifndef SMALL_KERNEL diff --git a/sys/arch/i386/i386/mainbus.c b/sys/arch/i386/i386/mainbus.c index 1af1664aa48..9a471600571 100644 --- a/sys/arch/i386/i386/mainbus.c +++ b/sys/arch/i386/i386/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.50 2012/10/04 08:32:20 ehrhardt Exp $ */ +/* $OpenBSD: mainbus.c,v 1.51 2015/07/21 03:38:22 reyk Exp $ */ /* $NetBSD: mainbus.c,v 1.21 1997/06/06 23:14:20 thorpej Exp $ */ /* @@ -52,9 +52,9 @@ #include "acpi.h" #include "ipmi.h" #include "esm.h" -#include "vmt.h" #include "vesabios.h" #include "amdmsr.h" +#include "pvbus.h" #include <machine/cpuvar.h> #include <machine/i82093var.h> @@ -69,8 +69,8 @@ #include <dev/ipmivar.h> #endif -#if NVMT > 0 -#include <dev/vmtvar.h> +#if NPVBUS > 0 +#include <dev/pv/pvvar.h> #endif #if NAMDMSR > 0 @@ -115,6 +115,9 @@ union mainbus_attach_args { #if NESM > 0 struct esm_attach_args mba_eaa; #endif +#if NPVBUS > 0 + struct pvbus_attach_args mba_pvba; +#endif }; /* @@ -164,10 +167,11 @@ mainbus_attach(struct device *parent, struct device *self, void *aux) } #endif -#if NVMT > 0 - if (vmt_probe()) { - mba.mba_busname = "vmt"; - config_found(self, &mba.mba_busname, mainbus_print); +#if NPVBUS > 0 + /* Probe first to hide the "not configured" message */ + if (pvbus_probe()) { + mba.mba_pvba.pvba_busname = "pvbus"; + config_found(self, &mba.mba_pvba.pvba_busname, mainbus_print); } #endif diff --git a/sys/conf/files b/sys/conf/files index b1ae3a5a8df..82972b6e122 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.598 2015/07/20 22:16:41 rzalamena Exp $ +# $OpenBSD: files,v 1.599 2015/07/21 03:38:22 reyk Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -486,10 +486,6 @@ file dev/radio.c radio needs-flag device ipmi file dev/ipmi.c ipmi needs-flag -# VMware Tools -device vmt -file dev/vmt.c vmt needs-flag - # Virtual SCSI device vscsi: scsi attach vscsi at root diff --git a/sys/dev/pv/files.pv b/sys/dev/pv/files.pv new file mode 100644 index 00000000000..d0834032390 --- /dev/null +++ b/sys/dev/pv/files.pv @@ -0,0 +1,14 @@ +# $OpenBSD: files.pv,v 1.1 2015/07/21 03:38:22 reyk Exp $ +# +# Config file and device description for paravirtual devices. +# Included by ports that need it. + +define pvbus {} +device pvbus +attach pvbus at mainbus +file dev/pv/pvbus.c pvbus needs-flag + +# VMware Tools +device vmt +attach vmt at pvbus +file dev/vmt.c vmt needs-flag diff --git a/sys/dev/pv/pvbus.c b/sys/dev/pv/pvbus.c new file mode 100644 index 00000000000..bc886f0814f --- /dev/null +++ b/sys/dev/pv/pvbus.c @@ -0,0 +1,193 @@ +/* $OpenBSD: pvbus.c,v 1.1 2015/07/21 03:38:22 reyk Exp $ */ + +/* + * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#if !defined(__i386__) && !defined(__amd64__) +#error pvbus(4) is currently only supported on i386 and amd64 +#endif + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/timeout.h> +#include <sys/signalvar.h> +#include <sys/syslog.h> +#include <sys/proc.h> +#include <sys/socket.h> + +#include <machine/specialreg.h> + +#include <dev/rndvar.h> + +#include <dev/pv/pvvar.h> +#include <dev/pv/pvreg.h> + +#include "vmt.h" + +int has_hv_cpuid = 0; + +extern void rdrand(void *); + +int pvbus_activate(struct device *, int); +int pvbus_match(struct device *, void *, void *); +void pvbus_attach(struct device *, struct device *, void *); +int pvbus_print(void *, const char *); + +struct cfattach pvbus_ca = { + sizeof(struct pvbus_softc), + pvbus_match, + pvbus_attach, + NULL, + pvbus_activate +}; + +struct cfdriver pvbus_cd = { + NULL, + "pvbus", + DV_DULL +}; + +struct pvbus_type { + const char *signature; + const char *name; + unsigned int type; +} pvbus_types[] = { + { "KVMKVMKVM\0\0\0", "KVM", PVBUS_KVM }, + { "Microsoft Hv", "Hyper-V", PVBUS_HYPERV }, + { "VMwareVMware", "VMware", PVBUS_VMWARE }, + { "XenVMMXenVMM", "Xen", PVBUS_XEN }, + { NULL } +}; + +struct pv_attach_args pvbus_devices[] = { +#if NVMT > 0 + { "vmt", PVBUS_VMWARE }, +#endif + { NULL } +}; + +int +pvbus_probe(void) +{ + /* Must be set in identcpu */ + if (!has_hv_cpuid) + return (0); + return (1); +} + +int +pvbus_match(struct device *parent, void *match, void *aux) +{ + const char **busname = (const char **)aux; + return (strcmp(*busname, pvbus_cd.cd_name) == 0); +} + +void +pvbus_attach(struct device *parent, struct device *self, void *aux) +{ + struct pvbus_softc *sc = (struct pvbus_softc *)self; + struct pv_attach_args *pva; + uint32_t reg0, base; + union { + uint32_t regs[3]; + char str[CPUID_HV_SIGNATURE_STRLEN]; + } r; + int i; + + printf(":"); + + for (base = CPUID_HV_SIGNATURE_START; + base < CPUID_HV_SIGNATURE_END; + base += CPUID_HV_SIGNATURE_STEP) { + CPUID(base, reg0, r.regs[0], r.regs[1], r.regs[2]); + for (i = 0; i < 4; i++) { + /* + * Check if first 4 chars are printable ASCII as + * minimal validity check + */ + if (r.str[i] < 32 || r.str[i] > 126) + goto out; + } + + for (i = 0; pvbus_types[i].signature != NULL; i++) { + if (memcmp(pvbus_types[i].signature, r.str, + CPUID_HV_SIGNATURE_STRLEN) != 0) + continue; + sc->pvbus_types |= pvbus_types[i].type; + + printf(" %s", pvbus_types[i].name); + } + } + + out: + printf("\n"); + +#ifdef notyet + /* XXX get hypervisor-specific features */ + if (sc->pvbus_types & PVBUS_KVM) { + kvm_cpuid_base = base; + CPUID(base + CPUID_OFFSET_KVM_FEATURES, + reg0, r.regs[0], r.regs[1], r.regs[2]); + kvm_features = reg0; + } + if (sc->pvbus_types & PVBUS_HYPERV) { + /* XXX */ + } +#endif + + /* Attach drivers */ + for (i = 0; pvbus_devices[i].pva_busname != NULL; i++) { + pva = &pvbus_devices[i]; + pva->pva_types = sc->pvbus_types; + if (sc->pvbus_types & pva->pva_type) + config_found(self, &pva->pva_busname, + pvbus_print); + } +} + +int +pvbus_activate(struct device *self, int act) +{ + int rv = 0; + + switch (act) { + case DVACT_SUSPEND: + rv = config_activate_children(self, act); + break; + case DVACT_RESUME: + rv = config_activate_children(self, act); + break; + case DVACT_POWERDOWN: + rv = config_activate_children(self, act); + break; + default: + rv = config_activate_children(self, act); + break; + } + + return (rv); +} + +int +pvbus_print(void *aux, const char *pnp) +{ + struct pv_attach_args *pva = aux; + if (pnp) + printf("%s at %s", pva->pva_busname, pnp); + return (UNCONF); +} diff --git a/sys/dev/pv/pvreg.h b/sys/dev/pv/pvreg.h new file mode 100644 index 00000000000..1fa19dee558 --- /dev/null +++ b/sys/dev/pv/pvreg.h @@ -0,0 +1,45 @@ +/* $OpenBSD: pvreg.h,v 1.1 2015/07/21 03:38:22 reyk Exp $ */ + +/* + * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> + * Copyright (c) 2015 Stefan Fritsch <sf@sfritsch.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _DEV_PV_PVBUS_H_ +#define _DEV_PV_PVBUS_H_ + +#define CPUID_HV_SIGNATURE_START 0x40000000 +#define CPUID_HV_SIGNATURE_END 0x40010000 +#define CPUID_HV_SIGNATURE_STEP 0x100 +#define CPUID_HV_SIGNATURE_STRLEN 12 + +/* KVM */ +#define CPUID_OFFSET_KVM_FEATURES 0x1 + +#define KVM_FEATURE_CLOCKSOURCE 0 /* deprecated */ +#define KVM_FEATURE_NOP_IO_DELAY 1 +#define KVM_FEATURE_MMU_OP 2 /* deprecated */ +#define KVM_FEATURE_CLOCKSOURCE2 3 +#define KVM_FEATURE_ASYNC_PF 4 +#define KVM_FEATURE_STEAL_TIME 5 +#define KVM_FEATURE_PV_EOI 6 +#define KVM_FEATURE_PV_UNHALT 7 +#define KVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24 + +#define MSR_KVM_EOI_EN 0x4b564d04 + +#define KVM_PV_EOI_BIT 0 + +#endif /* _DEV_PV_PVBUS_H_ */ diff --git a/sys/dev/vmtvar.h b/sys/dev/pv/pvvar.h index 5029d5e6085..06161c7d51a 100644 --- a/sys/dev/vmtvar.h +++ b/sys/dev/pv/pvvar.h @@ -1,7 +1,7 @@ -/* $OpenBSD: vmtvar.h,v 1.1 2008/07/08 05:22:00 dlg Exp $ */ +/* $OpenBSD: pvvar.h,v 1.1 2015/07/21 03:38:22 reyk Exp $ */ /* - * Copyright (c) 2008 David Gwynne <dlg@openbsd.org> + * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,4 +16,31 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -int vmt_probe(void); +#ifndef _DEV_PV_PVVAR_H_ +#define _DEV_PV_PVVAR_H_ + +struct pvbus_softc { + struct device pvbus_dev; + uint8_t pvbus_types; +}; + +struct pvbus_attach_args { + const char *pvba_busname; +}; + +struct pv_attach_args { + const char *pva_busname; + uint8_t pva_type; /* required hv type */ + uint8_t pva_types; /* detected hv types */ +}; + +extern int has_hv_cpuid; + +#define PVBUS_KVM 0x01 +#define PVBUS_HYPERV 0x02 +#define PVBUS_VMWARE 0x04 +#define PVBUS_XEN 0x08 + +int pvbus_probe(void); + +#endif /* _DEV_PV_PVBUS_H_ */ diff --git a/sys/dev/vmt.c b/sys/dev/vmt.c index d21ec59e96d..b1b02c457bf 100644 --- a/sys/dev/vmt.c +++ b/sys/dev/vmt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmt.c,v 1.29 2015/03/14 03:38:46 jsg Exp $ */ +/* $OpenBSD: vmt.c,v 1.30 2015/07/21 03:38:22 reyk Exp $ */ /* * Copyright (c) 2007 David Crawshaw <david@zentus.com> @@ -226,6 +226,8 @@ void vmt_tclo_resume(struct vmt_softc *); void vmt_tclo_capreg(struct vmt_softc *); void vmt_tclo_broadcastip(struct vmt_softc *); +int vmt_probe(void); + struct vmt_tclo_rpc { const char *name; void (*cb)(struct vmt_softc *); @@ -317,6 +319,9 @@ vmt_match(struct device *parent, void *match, void *aux) { const char **busname = (const char **)aux; + if (!vmt_probe()) + return (0); + return (strcmp(*busname, vmt_cd.cd_name) == 0); } |