[50994] | 1 | /* $Id: GIMMinimal.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * GIM - Guest Interface Manager, Minimal implementation.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[76553] | 7 | * Copyright (C) 2014-2019 Oracle Corporation
|
---|
[50994] | 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 |
|
---|
[57358] | 18 |
|
---|
| 19 | /*********************************************************************************************************************************
|
---|
| 20 | * Header Files *
|
---|
| 21 | *********************************************************************************************************************************/
|
---|
[50994] | 22 | #define LOG_GROUP LOG_GROUP_GIM
|
---|
[61632] | 23 | #include <VBox/vmm/gim.h>
|
---|
| 24 | #include <VBox/vmm/cpum.h>
|
---|
| 25 | #include <VBox/vmm/tm.h>
|
---|
[64655] | 26 | #include <VBox/vmm/apic.h>
|
---|
[50994] | 27 | #include "GIMInternal.h"
|
---|
[61632] | 28 | #include <VBox/vmm/vm.h>
|
---|
[50994] | 29 |
|
---|
| 30 | #include <iprt/assert.h>
|
---|
| 31 | #include <iprt/err.h>
|
---|
[51797] | 32 | #include <iprt/asm-amd64-x86.h>
|
---|
[52672] | 33 | #include <iprt/string.h>
|
---|
[50994] | 34 |
|
---|
| 35 |
|
---|
[57358] | 36 | /*********************************************************************************************************************************
|
---|
| 37 | * Defined Constants And Macros *
|
---|
| 38 | *********************************************************************************************************************************/
|
---|
| 39 |
|
---|
[52699] | 40 | /**
|
---|
| 41 | * Initializes the Minimal provider.
|
---|
| 42 | *
|
---|
| 43 | * @returns VBox status code.
|
---|
[58122] | 44 | * @param pVM The cross context VM structure.
|
---|
[52699] | 45 | */
|
---|
[54654] | 46 | VMMR3_INT_DECL(int) gimR3MinimalInit(PVM pVM)
|
---|
[50994] | 47 | {
|
---|
| 48 | AssertReturn(pVM, VERR_INVALID_PARAMETER);
|
---|
[51333] | 49 | AssertReturn(pVM->gim.s.enmProviderId == GIMPROVIDERID_MINIMAL, VERR_INTERNAL_ERROR_5);
|
---|
[50994] | 50 |
|
---|
[51731] | 51 | /*
|
---|
[62591] | 52 | * Expose HVP (Hypervisor Present) bit to the guest.
|
---|
[51731] | 53 | */
|
---|
[61776] | 54 | CPUMR3SetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP);
|
---|
[50994] | 55 |
|
---|
[62591] | 56 | /*
|
---|
| 57 | * Insert the hypervisor leaf range.
|
---|
| 58 | */
|
---|
| 59 | CPUMCPUIDLEAF HyperLeaf;
|
---|
| 60 | RT_ZERO(HyperLeaf);
|
---|
| 61 | HyperLeaf.uLeaf = UINT32_C(0x40000000);
|
---|
| 62 | HyperLeaf.uEax = UINT32_C(0x40000010); /* Maximum leaf we implement. */
|
---|
| 63 | int rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
|
---|
| 64 | if (RT_SUCCESS(rc))
|
---|
| 65 | {
|
---|
| 66 | /*
|
---|
| 67 | * Insert missing zero leaves (you never know what missing leaves are
|
---|
| 68 | * going to return when read).
|
---|
| 69 | */
|
---|
| 70 | RT_ZERO(HyperLeaf);
|
---|
| 71 | for (uint32_t uLeaf = UINT32_C(0x40000001); uLeaf <= UINT32_C(0x40000010); uLeaf++)
|
---|
| 72 | {
|
---|
| 73 | HyperLeaf.uLeaf = uLeaf;
|
---|
| 74 | rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
|
---|
| 75 | AssertLogRelRCReturn(rc, rc);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | else
|
---|
| 79 | LogRel(("GIM: Minimal: Failed to insert hypervisor leaf %#RX32. rc=%Rrc\n", HyperLeaf.uLeaf, rc));
|
---|
| 80 |
|
---|
| 81 | return rc;
|
---|
[52675] | 82 | }
|
---|
| 83 |
|
---|
| 84 |
|
---|
[52699] | 85 | /**
|
---|
| 86 | * Initializes remaining bits of the Minimal provider.
|
---|
| 87 | * This is called after initializing HM and almost all other VMM components.
|
---|
| 88 | *
|
---|
| 89 | * @returns VBox status code.
|
---|
[58122] | 90 | * @param pVM The cross context VM structure.
|
---|
[52699] | 91 | */
|
---|
[54654] | 92 | VMMR3_INT_DECL(int) gimR3MinimalInitCompleted(PVM pVM)
|
---|
[52675] | 93 | {
|
---|
[52672] | 94 | /*
|
---|
[58564] | 95 | * Expose a generic hypervisor-agnostic leaf (originally defined by VMware).
|
---|
[52672] | 96 | * The leaves range from 0x40000010 to 0x400000FF.
|
---|
[52675] | 97 | *
|
---|
[52707] | 98 | * This is done in the init. completed routine as we need PDM to be
|
---|
[64655] | 99 | * initialized (otherwise APICGetTimerFreq() would fail).
|
---|
[52672] | 100 | */
|
---|
| 101 | CPUMCPUIDLEAF HyperLeaf;
|
---|
| 102 | int rc = CPUMR3CpuIdGetLeaf(pVM, &HyperLeaf, 0x40000000, 0 /* uSubLeaf */);
|
---|
| 103 | if (RT_SUCCESS(rc))
|
---|
| 104 | {
|
---|
[62591] | 105 | Assert(HyperLeaf.uEax >= 0x40000010);
|
---|
[52672] | 106 |
|
---|
| 107 | /*
|
---|
| 108 | * Add the timing information hypervisor leaf.
|
---|
| 109 | * MacOS X uses this to determine the TSC, bus frequency. See @bugref{7270}.
|
---|
| 110 | *
|
---|
| 111 | * EAX - TSC frequency in KHz.
|
---|
| 112 | * EBX - APIC frequency in KHz.
|
---|
| 113 | * ECX, EDX - Reserved.
|
---|
| 114 | */
|
---|
| 115 | uint64_t uApicFreq;
|
---|
[64655] | 116 | rc = APICGetTimerFreq(pVM, &uApicFreq);
|
---|
[52672] | 117 | AssertLogRelRCReturn(rc, rc);
|
---|
| 118 |
|
---|
| 119 | RT_ZERO(HyperLeaf);
|
---|
| 120 | HyperLeaf.uLeaf = UINT32_C(0x40000010);
|
---|
| 121 | HyperLeaf.uEax = TMCpuTicksPerSecond(pVM) / UINT64_C(1000);
|
---|
[52676] | 122 | HyperLeaf.uEbx = (uApicFreq + 500) / UINT64_C(1000);
|
---|
[52672] | 123 | rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
|
---|
| 124 | AssertLogRelRCReturn(rc, rc);
|
---|
| 125 | }
|
---|
[52674] | 126 | else
|
---|
[62591] | 127 | LogRel(("GIM: Minimal: failed to get hypervisor leaf 0x40000000. rc=%Rrc\n", rc));
|
---|
[52672] | 128 |
|
---|
[50994] | 129 | return VINF_SUCCESS;
|
---|
| 130 | }
|
---|
| 131 |
|
---|