1*2fee8756SJohn-Mark Gurney /*- 2*2fee8756SJohn-Mark Gurney * Copyright 2014 John Baldwin 3*2fee8756SJohn-Mark Gurney * Copyright 2019 Stephen J. Kiernan 4*2fee8756SJohn-Mark Gurney * All rights reserved. 5*2fee8756SJohn-Mark Gurney * 6*2fee8756SJohn-Mark Gurney * Redistribution and use in source and binary forms, with or without 7*2fee8756SJohn-Mark Gurney * modification, are permitted provided that the following conditions 8*2fee8756SJohn-Mark Gurney * are met: 9*2fee8756SJohn-Mark Gurney * 1. Redistributions of source code must retain the above copyright 10*2fee8756SJohn-Mark Gurney * notice, this list of conditions and the following disclaimer. 11*2fee8756SJohn-Mark Gurney * 2. Redistributions in binary form must reproduce the above copyright 12*2fee8756SJohn-Mark Gurney * notice, this list of conditions and the following disclaimer in the 13*2fee8756SJohn-Mark Gurney * documentation and/or other materials provided with the distribution. 14*2fee8756SJohn-Mark Gurney * 3. All advertising materials mentioning features or use of this software 15*2fee8756SJohn-Mark Gurney * must display the following acknowledgement: 16*2fee8756SJohn-Mark Gurney * This product includes software developed by the University of 17*2fee8756SJohn-Mark Gurney * California, Berkeley and its contributors. 18*2fee8756SJohn-Mark Gurney * 4. Neither the name of the University nor the names of its contributors 19*2fee8756SJohn-Mark Gurney * may be used to endorse or promote products derived from this software 20*2fee8756SJohn-Mark Gurney * without specific prior written permission. 21*2fee8756SJohn-Mark Gurney * 22*2fee8756SJohn-Mark Gurney * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*2fee8756SJohn-Mark Gurney * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*2fee8756SJohn-Mark Gurney * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*2fee8756SJohn-Mark Gurney * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*2fee8756SJohn-Mark Gurney * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*2fee8756SJohn-Mark Gurney * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*2fee8756SJohn-Mark Gurney * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*2fee8756SJohn-Mark Gurney * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*2fee8756SJohn-Mark Gurney * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*2fee8756SJohn-Mark Gurney * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*2fee8756SJohn-Mark Gurney * SUCH DAMAGE. 33*2fee8756SJohn-Mark Gurney * 34*2fee8756SJohn-Mark Gurney * from: Id: machdep.c,v 1.193 1996/06/18 01:22:04 bde Exp 35*2fee8756SJohn-Mark Gurney */ 36*2fee8756SJohn-Mark Gurney 37*2fee8756SJohn-Mark Gurney #include <sys/param.h> 38*2fee8756SJohn-Mark Gurney #include <sys/systm.h> 39*2fee8756SJohn-Mark Gurney 40*2fee8756SJohn-Mark Gurney #include <dev/smbios/smbios.h> 41*2fee8756SJohn-Mark Gurney 42*2fee8756SJohn-Mark Gurney static const struct { 43*2fee8756SJohn-Mark Gurney const char *vm_bname; 44*2fee8756SJohn-Mark Gurney int vm_guest; 45*2fee8756SJohn-Mark Gurney } vm_bnames[] = { 46*2fee8756SJohn-Mark Gurney { "QEMU", VM_GUEST_VM }, /* QEMU */ 47*2fee8756SJohn-Mark Gurney { "Plex86", VM_GUEST_VM }, /* Plex86 */ 48*2fee8756SJohn-Mark Gurney { "Bochs", VM_GUEST_VM }, /* Bochs */ 49*2fee8756SJohn-Mark Gurney { "Xen", VM_GUEST_XEN }, /* Xen */ 50*2fee8756SJohn-Mark Gurney { "BHYVE", VM_GUEST_BHYVE }, /* bhyve */ 51*2fee8756SJohn-Mark Gurney { "Seabios", VM_GUEST_KVM }, /* KVM */ 52*2fee8756SJohn-Mark Gurney }; 53*2fee8756SJohn-Mark Gurney 54*2fee8756SJohn-Mark Gurney static const struct { 55*2fee8756SJohn-Mark Gurney const char *vm_pname; 56*2fee8756SJohn-Mark Gurney int vm_guest; 57*2fee8756SJohn-Mark Gurney } vm_pnames[] = { 58*2fee8756SJohn-Mark Gurney { "VMware Virtual Platform", VM_GUEST_VMWARE }, 59*2fee8756SJohn-Mark Gurney { "Virtual Machine", VM_GUEST_VM }, /* Microsoft VirtualPC */ 60*2fee8756SJohn-Mark Gurney { "QEMU Virtual Machine", VM_GUEST_VM }, 61*2fee8756SJohn-Mark Gurney { "VirtualBox", VM_GUEST_VBOX }, 62*2fee8756SJohn-Mark Gurney { "Parallels Virtual Platform", VM_GUEST_PARALLELS }, 63*2fee8756SJohn-Mark Gurney { "KVM", VM_GUEST_KVM }, 64*2fee8756SJohn-Mark Gurney }; 65*2fee8756SJohn-Mark Gurney 66*2fee8756SJohn-Mark Gurney void 67*2fee8756SJohn-Mark Gurney identify_hypervisor_smbios(void) 68*2fee8756SJohn-Mark Gurney { 69*2fee8756SJohn-Mark Gurney char *p; 70*2fee8756SJohn-Mark Gurney int i; 71*2fee8756SJohn-Mark Gurney 72*2fee8756SJohn-Mark Gurney /* 73*2fee8756SJohn-Mark Gurney * XXX: Some of these entries may not be needed since they were 74*2fee8756SJohn-Mark Gurney * added to FreeBSD before the checks above. 75*2fee8756SJohn-Mark Gurney */ 76*2fee8756SJohn-Mark Gurney p = kern_getenv("smbios.bios.vendor"); 77*2fee8756SJohn-Mark Gurney if (p != NULL) { 78*2fee8756SJohn-Mark Gurney for (i = 0; i < nitems(vm_bnames); i++) 79*2fee8756SJohn-Mark Gurney if (strcmp(p, vm_bnames[i].vm_bname) == 0) { 80*2fee8756SJohn-Mark Gurney vm_guest = vm_bnames[i].vm_guest; 81*2fee8756SJohn-Mark Gurney /* If we have a specific match, return */ 82*2fee8756SJohn-Mark Gurney if (vm_guest != VM_GUEST_VM) { 83*2fee8756SJohn-Mark Gurney freeenv(p); 84*2fee8756SJohn-Mark Gurney return; 85*2fee8756SJohn-Mark Gurney } 86*2fee8756SJohn-Mark Gurney /* 87*2fee8756SJohn-Mark Gurney * We are done with bnames, but there might be 88*2fee8756SJohn-Mark Gurney * a more specific match in the pnames 89*2fee8756SJohn-Mark Gurney */ 90*2fee8756SJohn-Mark Gurney break; 91*2fee8756SJohn-Mark Gurney } 92*2fee8756SJohn-Mark Gurney freeenv(p); 93*2fee8756SJohn-Mark Gurney } 94*2fee8756SJohn-Mark Gurney p = kern_getenv("smbios.system.product"); 95*2fee8756SJohn-Mark Gurney if (p != NULL) { 96*2fee8756SJohn-Mark Gurney for (i = 0; i < nitems(vm_pnames); i++) 97*2fee8756SJohn-Mark Gurney if (strcmp(p, vm_pnames[i].vm_pname) == 0) { 98*2fee8756SJohn-Mark Gurney vm_guest = vm_pnames[i].vm_guest; 99*2fee8756SJohn-Mark Gurney freeenv(p); 100*2fee8756SJohn-Mark Gurney return; 101*2fee8756SJohn-Mark Gurney } 102*2fee8756SJohn-Mark Gurney freeenv(p); 103*2fee8756SJohn-Mark Gurney } 104*2fee8756SJohn-Mark Gurney } 105