From owner-svn-src-all@FreeBSD.ORG Fri Oct 18 23:19:29 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2F2B9349; Fri, 18 Oct 2013 23:19:29 +0000 (UTC) (envelope-from gibbs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0C8222590; Fri, 18 Oct 2013 23:19:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9INJSUL085736; Fri, 18 Oct 2013 23:19:28 GMT (envelope-from gibbs@svn.freebsd.org) Received: (from gibbs@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9INJSdH085731; Fri, 18 Oct 2013 23:19:28 GMT (envelope-from gibbs@svn.freebsd.org) Message-Id: <201310182319.r9INJSdH085731@svn.freebsd.org> From: "Justin T. Gibbs" Date: Fri, 18 Oct 2013 23:19:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r256758 - in stable/10/sys: dev/hyperv/stordisengage dev/hyperv/vmbus sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 23:19:29 -0000 Author: gibbs Date: Fri Oct 18 23:19:27 2013 New Revision: 256758 URL: http://svnweb.freebsd.org/changeset/base/256758 Log: MFC r256425: Centralize the detection logic for the Hyper-V hypervisor. Submitted by: Roger Pau MonnĂ© Sponsored by: Citrix Systems R&D Reviewed by: gibbs, grehan Approved by: re (gjb) sys/sys/systm.h: * Add a new VM_GUEST type, VM_GUEST_HV (HyperV guest). sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c: sys/dev/hyperv/vmbus/hv_hv.c: sys/dev/hyperv/stordisengage/hv_ata_pci_disengage.c: * Set vm_guest to VM_GUEST_HV and use that on other HyperV related devices instead of cloning the cpuid hypervisor check. * Cleanup the vmbus_identify function. ------------------------------------------------------------------------ Modified: stable/10/sys/dev/hyperv/stordisengage/hv_ata_pci_disengage.c stable/10/sys/dev/hyperv/vmbus/hv_hv.c stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c stable/10/sys/sys/systm.h Directory Properties: stable/10/sys/ (props changed) stable/10/sys/dev/hyperv/ (props changed) Modified: stable/10/sys/dev/hyperv/stordisengage/hv_ata_pci_disengage.c ============================================================================== --- stable/10/sys/dev/hyperv/stordisengage/hv_ata_pci_disengage.c Fri Oct 18 22:48:38 2013 (r256757) +++ stable/10/sys/dev/hyperv/stordisengage/hv_ata_pci_disengage.c Fri Oct 18 23:19:27 2013 (r256758) @@ -75,17 +75,11 @@ __FBSDID("$FreeBSD$"); #include #include -#define HV_X64_MSR_GUEST_OS_ID 0x40000000 -#define HV_X64_CPUID_MIN 0x40000005 -#define HV_X64_CPUID_MAX 0x4000ffff - /* prototypes */ static int hv_ata_pci_probe(device_t dev); static int hv_ata_pci_attach(device_t dev); static int hv_ata_pci_detach(device_t dev); -static int hv_check_for_hyper_v(void); - /* * generic PCI ATA device probe */ @@ -100,7 +94,7 @@ hv_ata_pci_probe(device_t dev) /* * Don't probe if not running in a Hyper-V environment */ - if (!hv_check_for_hyper_v()) + if (vm_guest != VM_GUEST_HV) return (ENXIO); if (device_get_unit(parent) != 0 || device_get_ivars(dev) != 0) @@ -139,33 +133,6 @@ hv_ata_pci_detach(device_t dev) return (0); } -/** -* Detect Hyper-V and enable fast IDE -* via enlighted storage driver -*/ -static int -hv_check_for_hyper_v(void) -{ - u_int regs[4]; - int hyper_v_detected; - - hyper_v_detected = 0; - do_cpuid(1, regs); - if (regs[2] & 0x80000000) { - /* - * if(a hypervisor is detected) - * make sure this really is Hyper-V - */ - do_cpuid(HV_X64_MSR_GUEST_OS_ID, regs); - hyper_v_detected = - regs[0] >= HV_X64_CPUID_MIN && - regs[0] <= HV_X64_CPUID_MAX && - !memcmp("Microsoft Hv", ®s[1], 12); - } - - return (hyper_v_detected); -} - static device_method_t hv_ata_pci_methods[] = { /* device interface */ DEVMETHOD(device_probe, hv_ata_pci_probe), Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_hv.c Fri Oct 18 22:48:38 2013 (r256757) +++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c Fri Oct 18 23:19:27 2013 (r256758) @@ -218,7 +218,7 @@ hv_vmbus_init(void) 0, sizeof(hv_vmbus_handle) * MAXCPU); - if (!hv_vmbus_query_hypervisor_presence()) + if (vm_guest != VM_GUEST_HV) goto cleanup; max_leaf = hv_vmbus_get_hypervisor_version(); Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Fri Oct 18 22:48:38 2013 (r256757) +++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c Fri Oct 18 23:19:27 2013 (r256758) @@ -295,11 +295,15 @@ hv_vmbus_child_device_unregister(struct return(ret); } -static void vmbus_identify(driver_t *driver, device_t parent) { +static void +vmbus_identify(driver_t *driver, device_t parent) +{ + if (!hv_vmbus_query_hypervisor_presence()) + return; + + vm_guest = VM_GUEST_HV; + BUS_ADD_CHILD(parent, 0, "vmbus", 0); - if (device_find_child(parent, "vmbus", 0) == NULL) { - BUS_ADD_CHILD(parent, 0, "vmbus", 0); - } } static int @@ -307,9 +311,6 @@ vmbus_probe(device_t dev) { if(bootverbose) device_printf(dev, "VMBUS: probe\n"); - if (!hv_vmbus_query_hypervisor_presence()) - return (ENXIO); - device_set_desc(dev, "Vmbus Devices"); return (0); @@ -491,10 +492,13 @@ vmbus_attach(device_t dev) static void vmbus_init(void) { + if (vm_guest != VM_GUEST_HV) + return; + /* * If the system has already booted and thread - * scheduling is possible indicated by the global - * cold set to zero, we just call the driver + * scheduling is possible, as indicated by the + * global cold set to zero, we just call the driver * initialization directly. */ if (!cold) Modified: stable/10/sys/sys/systm.h ============================================================================== --- stable/10/sys/sys/systm.h Fri Oct 18 22:48:38 2013 (r256757) +++ stable/10/sys/sys/systm.h Fri Oct 18 23:19:27 2013 (r256758) @@ -71,7 +71,7 @@ extern int vm_guest; /* Running as virt * and/or add to the VM_GUEST_VM type if specific VM functionality is * ever implemented (e.g. vendor-specific paravirtualization features). */ -enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN }; +enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN, VM_GUEST_HV }; #if defined(WITNESS) || defined(INVARIANTS) void kassert_panic(const char *fmt, ...) __printflike(1, 2);