VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/GIMMinimal.cpp@ 96335

Last change on this file since 96335 was 93725, checked in by vboxsync, 3 years ago

VMM: More arm64 adjustments. bugref:9898

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette