1*e9b148a3SSimon J. Gerraty /*-
2*e9b148a3SSimon J. Gerraty * Copyright (c) 2013-2019 Juniper Networks, Inc.
3*e9b148a3SSimon J. Gerraty * All rights reserved.
4*e9b148a3SSimon J. Gerraty *
5*e9b148a3SSimon J. Gerraty * Redistribution and use in source and binary forms, with or without
6*e9b148a3SSimon J. Gerraty * modification, are permitted provided that the following conditions
7*e9b148a3SSimon J. Gerraty * are met:
8*e9b148a3SSimon J. Gerraty * 1. Redistributions of source code must retain the above copyright
9*e9b148a3SSimon J. Gerraty * notice, this list of conditions and the following disclaimer.
10*e9b148a3SSimon J. Gerraty * 2. Redistributions in binary form must reproduce the above copyright
11*e9b148a3SSimon J. Gerraty * notice, this list of conditions and the following disclaimer in the
12*e9b148a3SSimon J. Gerraty * documentation and/or other materials provided with the distribution.
13*e9b148a3SSimon J. Gerraty *
14*e9b148a3SSimon J. Gerraty * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*e9b148a3SSimon J. Gerraty * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*e9b148a3SSimon J. Gerraty * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*e9b148a3SSimon J. Gerraty * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*e9b148a3SSimon J. Gerraty * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*e9b148a3SSimon J. Gerraty * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*e9b148a3SSimon J. Gerraty * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*e9b148a3SSimon J. Gerraty * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*e9b148a3SSimon J. Gerraty * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*e9b148a3SSimon J. Gerraty * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*e9b148a3SSimon J. Gerraty * SUCH DAMAGE.
25*e9b148a3SSimon J. Gerraty */
26*e9b148a3SSimon J. Gerraty
27*e9b148a3SSimon J. Gerraty #include <stand.h>
28*e9b148a3SSimon J. Gerraty #include <machine/cpufunc.h>
29*e9b148a3SSimon J. Gerraty #include <machine/specialreg.h>
30*e9b148a3SSimon J. Gerraty
31*e9b148a3SSimon J. Gerraty const char *
x86_hypervisor(void)32*e9b148a3SSimon J. Gerraty x86_hypervisor(void)
33*e9b148a3SSimon J. Gerraty {
34*e9b148a3SSimon J. Gerraty static union {
35*e9b148a3SSimon J. Gerraty struct {
36*e9b148a3SSimon J. Gerraty u_int high;
37*e9b148a3SSimon J. Gerraty char name[13];
38*e9b148a3SSimon J. Gerraty } hv;
39*e9b148a3SSimon J. Gerraty u_int regs[4];
40*e9b148a3SSimon J. Gerraty } u;
41*e9b148a3SSimon J. Gerraty
42*e9b148a3SSimon J. Gerraty /* Return NULL when no hypervisor is present. */
43*e9b148a3SSimon J. Gerraty do_cpuid(1, u.regs);
44*e9b148a3SSimon J. Gerraty if ((u.regs[2] & CPUID2_HV) == 0)
45*e9b148a3SSimon J. Gerraty return (NULL);
46*e9b148a3SSimon J. Gerraty /* Return the hypervisor's identification. */
47*e9b148a3SSimon J. Gerraty do_cpuid(0x40000000, u.regs);
48*e9b148a3SSimon J. Gerraty return (u.hv.name);
49*e9b148a3SSimon J. Gerraty }
50