1b01c2033SNeel Natu /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3c49761ddSPedro F. Giffuni *
4b01c2033SNeel Natu * Copyright (c) 2012 NetApp, Inc.
5b01c2033SNeel Natu * All rights reserved.
6b01c2033SNeel Natu *
7b01c2033SNeel Natu * Redistribution and use in source and binary forms, with or without
8b01c2033SNeel Natu * modification, are permitted provided that the following conditions
9b01c2033SNeel Natu * are met:
10b01c2033SNeel Natu * 1. Redistributions of source code must retain the above copyright
11b01c2033SNeel Natu * notice, this list of conditions and the following disclaimer.
12b01c2033SNeel Natu * 2. Redistributions in binary form must reproduce the above copyright
13b01c2033SNeel Natu * notice, this list of conditions and the following disclaimer in the
14b01c2033SNeel Natu * documentation and/or other materials provided with the distribution.
15b01c2033SNeel Natu *
16b01c2033SNeel Natu * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17b01c2033SNeel Natu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b01c2033SNeel Natu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b01c2033SNeel Natu * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20b01c2033SNeel Natu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b01c2033SNeel Natu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b01c2033SNeel Natu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b01c2033SNeel Natu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b01c2033SNeel Natu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b01c2033SNeel Natu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b01c2033SNeel Natu * SUCH DAMAGE.
27b01c2033SNeel Natu */
28b01c2033SNeel Natu
29b01c2033SNeel Natu #ifndef _VMM_HOST_H_
30b01c2033SNeel Natu #define _VMM_HOST_H_
31b01c2033SNeel Natu
32b01c2033SNeel Natu #ifndef _KERNEL
331d64db52SConrad Meyer #error "no user-serviceable parts inside"
34b01c2033SNeel Natu #endif
35b01c2033SNeel Natu
36abb023fbSJohn Baldwin struct xsave_limits {
37abb023fbSJohn Baldwin int xsave_enabled;
38abb023fbSJohn Baldwin uint64_t xcr0_allowed;
39abb023fbSJohn Baldwin uint32_t xsave_max_size;
40abb023fbSJohn Baldwin };
41abb023fbSJohn Baldwin
42b01c2033SNeel Natu void vmm_host_state_init(void);
43b01c2033SNeel Natu
44b01c2033SNeel Natu uint64_t vmm_get_host_pat(void);
45b01c2033SNeel Natu uint64_t vmm_get_host_efer(void);
46b01c2033SNeel Natu uint64_t vmm_get_host_cr0(void);
47b01c2033SNeel Natu uint64_t vmm_get_host_cr4(void);
48abb023fbSJohn Baldwin uint64_t vmm_get_host_xcr0(void);
49b01c2033SNeel Natu uint64_t vmm_get_host_datasel(void);
50b01c2033SNeel Natu uint64_t vmm_get_host_codesel(void);
51b01c2033SNeel Natu uint64_t vmm_get_host_tsssel(void);
52b01c2033SNeel Natu uint64_t vmm_get_host_fsbase(void);
53b01c2033SNeel Natu uint64_t vmm_get_host_idtrbase(void);
54abb023fbSJohn Baldwin const struct xsave_limits *vmm_get_xsave_limits(void);
55b01c2033SNeel Natu
56b01c2033SNeel Natu /*
57b01c2033SNeel Natu * Inline access to host state that is used on every VM entry
58b01c2033SNeel Natu */
59b01c2033SNeel Natu static __inline uint64_t
vmm_get_host_trbase(void)60b01c2033SNeel Natu vmm_get_host_trbase(void)
61b01c2033SNeel Natu {
62b01c2033SNeel Natu
63b01c2033SNeel Natu return ((uint64_t)PCPU_GET(tssp));
64b01c2033SNeel Natu }
65b01c2033SNeel Natu
66b01c2033SNeel Natu static __inline uint64_t
vmm_get_host_gdtrbase(void)67b01c2033SNeel Natu vmm_get_host_gdtrbase(void)
68b01c2033SNeel Natu {
69b01c2033SNeel Natu
70a7af4a3eSKonstantin Belousov return ((uint64_t)*PCPU_PTR(gdt));
71b01c2033SNeel Natu }
72b01c2033SNeel Natu
73b01c2033SNeel Natu static __inline uint64_t
vmm_get_host_gsbase(void)74b01c2033SNeel Natu vmm_get_host_gsbase(void)
75b01c2033SNeel Natu {
76b01c2033SNeel Natu
77e08087eeSJohn Baldwin return ((uint64_t)get_pcpu());
78b01c2033SNeel Natu }
79b01c2033SNeel Natu
80b01c2033SNeel Natu #endif
81