1 | /* $Id: GIMR0.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Guest Interface Manager (GIM) - Host Context Ring-0.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_GIM
|
---|
23 | #include <VBox/vmm/gim.h>
|
---|
24 | #include "GIMInternal.h"
|
---|
25 | #include "GIMHvInternal.h"
|
---|
26 | #include <VBox/vmm/vm.h>
|
---|
27 |
|
---|
28 | #include <VBox/err.h>
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Does ring-0 per-VM GIM initialization.
|
---|
33 | *
|
---|
34 | * @returns VBox status code.
|
---|
35 | * @param pVM The cross context VM structure.
|
---|
36 | */
|
---|
37 | VMMR0_INT_DECL(int) GIMR0InitVM(PVM pVM)
|
---|
38 | {
|
---|
39 | if (!GIMIsEnabled(pVM))
|
---|
40 | return VINF_SUCCESS;
|
---|
41 |
|
---|
42 | switch (pVM->gim.s.enmProviderId)
|
---|
43 | {
|
---|
44 | case GIMPROVIDERID_HYPERV:
|
---|
45 | return gimR0HvInitVM(pVM);
|
---|
46 |
|
---|
47 | case GIMPROVIDERID_KVM:
|
---|
48 | return gimR0KvmInitVM(pVM);
|
---|
49 |
|
---|
50 | default:
|
---|
51 | break;
|
---|
52 | }
|
---|
53 | return VINF_SUCCESS;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Does ring-0 per-VM GIM termination.
|
---|
59 | *
|
---|
60 | * @returns VBox status code.
|
---|
61 | * @param pVM The cross context VM structure.
|
---|
62 | */
|
---|
63 | VMMR0_INT_DECL(int) GIMR0TermVM(PVM pVM)
|
---|
64 | {
|
---|
65 | if (!GIMIsEnabled(pVM))
|
---|
66 | return VINF_SUCCESS;
|
---|
67 |
|
---|
68 | switch (pVM->gim.s.enmProviderId)
|
---|
69 | {
|
---|
70 | case GIMPROVIDERID_HYPERV:
|
---|
71 | return gimR0HvTermVM(pVM);
|
---|
72 |
|
---|
73 | case GIMPROVIDERID_KVM:
|
---|
74 | return gimR0KvmTermVM(pVM);
|
---|
75 |
|
---|
76 | default:
|
---|
77 | break;
|
---|
78 | }
|
---|
79 | return VINF_SUCCESS;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Updates the paravirtualized TSC supported by the GIM provider.
|
---|
85 | *
|
---|
86 | * @returns VBox status code.
|
---|
87 | * @retval VINF_SUCCESS if the paravirt. TSC is setup and in use.
|
---|
88 | * @retval VERR_GIM_NOT_ENABLED if no GIM provider is configured for this VM.
|
---|
89 | * @retval VERR_GIM_PVTSC_NOT_AVAILABLE if the GIM provider does not support any
|
---|
90 | * paravirt. TSC.
|
---|
91 | * @retval VERR_GIM_PVTSC_NOT_IN_USE if the GIM provider supports paravirt. TSC
|
---|
92 | * but the guest isn't currently using it.
|
---|
93 | *
|
---|
94 | * @param pVM The cross context VM structure.
|
---|
95 | * @param u64Offset The computed TSC offset.
|
---|
96 | *
|
---|
97 | * @thread EMT(pVCpu)
|
---|
98 | */
|
---|
99 | VMMR0_INT_DECL(int) GIMR0UpdateParavirtTsc(PVM pVM, uint64_t u64Offset)
|
---|
100 | {
|
---|
101 | switch (pVM->gim.s.enmProviderId)
|
---|
102 | {
|
---|
103 | case GIMPROVIDERID_HYPERV:
|
---|
104 | return gimR0HvUpdateParavirtTsc(pVM, u64Offset);
|
---|
105 |
|
---|
106 | case GIMPROVIDERID_KVM:
|
---|
107 | return VINF_SUCCESS;
|
---|
108 |
|
---|
109 | case GIMPROVIDERID_NONE:
|
---|
110 | return VERR_GIM_NOT_ENABLED;
|
---|
111 |
|
---|
112 | default:
|
---|
113 | break;
|
---|
114 | }
|
---|
115 | return VERR_GIM_PVTSC_NOT_AVAILABLE;
|
---|
116 | }
|
---|
117 |
|
---|