VirtualBox

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

最後變更 在這個檔案從80281是 80191,由 vboxsync 提交於 6 年 前

VMM/r3: Refactored VMCPU enumeration in preparation that aCpus will be replaced with a pointer array. Removed two raw-mode offset members from the CPUM and CPUMCPU sub-structures. bugref:9217 bugref:9517

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

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