VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/PMUAll.cpp@ 106477

Last change on this file since 106477 was 106477, checked in by vboxsync, 7 months ago

VMMArm: Skeleton of the PMU device emulation enough to make Windows/ARM boot as a guest and have it out of the NEM darwin backend, bugref:10778 [release build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/* $Id: PMUAll.cpp 106477 2024-10-18 13:15:51Z vboxsync $ */
2/** @file
3 * PMU - Performance Monitoring Unit. - All Contexts.
4 */
5
6/*
7 * Copyright (C) 2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DEV_PMU
33#include "PMUInternal.h"
34#include <VBox/vmm/pmu.h>
35#include <VBox/vmm/pdmdev.h>
36#include <VBox/vmm/vmcc.h>
37#include <VBox/vmm/vmm.h>
38#include <VBox/vmm/vmcpuset.h>
39#ifdef IN_RING0
40# include <VBox/vmm/gvmm.h>
41#endif
42
43#include <iprt/asm-arm.h>
44
45
46/*********************************************************************************************************************************
47* Internal Functions *
48*********************************************************************************************************************************/
49
50
51/*********************************************************************************************************************************
52* Global Variables *
53*********************************************************************************************************************************/
54
55/**
56 * Reads a PMU system register.
57 *
58 * @returns Strict VBox status code.
59 * @param pVCpu The cross context virtual CPU structure.
60 * @param u32Reg The system register being read.
61 * @param pu64Value Where to store the read value.
62 */
63VMM_INT_DECL(VBOXSTRICTRC) PMUReadSysReg(PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t *pu64Value)
64{
65 /*
66 * Validate.
67 */
68 VMCPU_ASSERT_EMT(pVCpu);
69 Assert(pu64Value);
70
71 *pu64Value = 0;
72
73#if 0
74 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, pDevIns->pCritSectRoR3, VERR_IGNORED);
75 PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, pDevIns->pCritSectRoR3, rcLock);
76#endif
77
78 switch (u32Reg)
79 {
80 case ARMV8_AARCH64_SYSREG_PMCCNTR_EL0:
81 *pu64Value = ASMReadTSC() * 100;
82 break;
83 case ARMV8_AARCH64_SYSREG_PMCR_EL0:
84 case ARMV8_AARCH64_SYSREG_PMCNTENCLR_EL0:
85 case ARMV8_AARCH64_SYSREG_PMUSERENR_EL0:
86 break;
87 default:
88 AssertReleaseFailed();
89 break;
90 }
91
92 //PDMDevHlpCritSectLeave(pDevIns, pDevIns->pCritSectRoR3);
93
94 LogFlowFunc(("pVCpu=%p u32Reg=%#x pu64Value=%RX64\n", pVCpu, u32Reg, *pu64Value));
95 return VINF_SUCCESS;
96}
97
98
99/**
100 * Writes an PMU system register.
101 *
102 * @returns Strict VBox status code.
103 * @param pVCpu The cross context virtual CPU structure.
104 * @param u32Reg The system register being written (IPRT system register identifier).
105 * @param u64Value The value to write.
106 */
107VMM_INT_DECL(VBOXSTRICTRC) PMUWriteSysReg(PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t u64Value)
108{
109 /*
110 * Validate.
111 */
112 VMCPU_ASSERT_EMT(pVCpu);
113 LogFlowFunc(("pVCpu=%p u32Reg=%#x u64Value=%RX64\n", pVCpu, u32Reg, u64Value));
114
115#if 0
116 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, pDevIns->pCritSectRoR3, VERR_IGNORED);
117 PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, pDevIns->pCritSectRoR3, rcLock);
118#endif
119
120 switch (u32Reg)
121 {
122 case ARMV8_AARCH64_SYSREG_PMCNTENCLR_EL0:
123 case ARMV8_AARCH64_SYSREG_PMOVSCLR_EL0:
124 case ARMV8_AARCH64_SYSREG_PMINTENCLR_EL1:
125 case ARMV8_AARCH64_SYSREG_PMCR_EL0:
126 case ARMV8_AARCH64_SYSREG_PMCCFILTR_EL0:
127 case ARMV8_AARCH64_SYSREG_PMCNTENSET_EL0:
128 case ARMV8_AARCH64_SYSREG_PMUSERENR_EL0:
129 case ARMV8_AARCH64_SYSREG_PMCCNTR_EL0:
130 RT_NOREF(u64Value);
131 break;
132 default:
133 AssertReleaseFailed();
134 break;
135 }
136
137 //PDMDevHlpCritSectLeave(pDevIns, pDevIns->pCritSectRoR3);
138 return VINF_SUCCESS;
139}
140
141
142#ifndef IN_RING3
143
144/**
145 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
146 */
147static DECLCALLBACK(int) pmuRZConstruct(PPDMDEVINS pDevIns)
148{
149 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
150 AssertReleaseFailed();
151 return VINF_SUCCESS;
152}
153#endif /* !IN_RING3 */
154
155/**
156 * PMU device registration structure.
157 */
158const PDMDEVREG g_DevicePMU =
159{
160 /* .u32Version = */ PDM_DEVREG_VERSION,
161 /* .uReserved0 = */ 0,
162 /* .szName = */ "pmu",
163 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
164 /* .fClass = */ PDM_DEVREG_CLASS_ARCH,
165 /* .cMaxInstances = */ 1,
166 /* .uSharedVersion = */ 42,
167 /* .cbInstanceShared = */ sizeof(PMUDEV),
168 /* .cbInstanceCC = */ 0,
169 /* .cbInstanceRC = */ 0,
170 /* .cMaxPciDevices = */ 0,
171 /* .cMaxMsixVectors = */ 0,
172 /* .pszDescription = */ "Performance Monitoring Unit",
173#if defined(IN_RING3)
174 /* .szRCMod = */ "VMMRC.rc",
175 /* .szR0Mod = */ "VMMR0.r0",
176 /* .pfnConstruct = */ pmuR3Construct,
177 /* .pfnDestruct = */ pmuR3Destruct,
178 /* .pfnRelocate = */ pmuR3Relocate,
179 /* .pfnMemSetup = */ NULL,
180 /* .pfnPowerOn = */ NULL,
181 /* .pfnReset = */ pmuR3Reset,
182 /* .pfnSuspend = */ NULL,
183 /* .pfnResume = */ NULL,
184 /* .pfnAttach = */ NULL,
185 /* .pfnDetach = */ NULL,
186 /* .pfnQueryInterface = */ NULL,
187 /* .pfnInitComplete = */ NULL,
188 /* .pfnPowerOff = */ NULL,
189 /* .pfnSoftReset = */ NULL,
190 /* .pfnReserved0 = */ NULL,
191 /* .pfnReserved1 = */ NULL,
192 /* .pfnReserved2 = */ NULL,
193 /* .pfnReserved3 = */ NULL,
194 /* .pfnReserved4 = */ NULL,
195 /* .pfnReserved5 = */ NULL,
196 /* .pfnReserved6 = */ NULL,
197 /* .pfnReserved7 = */ NULL,
198#elif defined(IN_RING0)
199 /* .pfnEarlyConstruct = */ NULL,
200 /* .pfnConstruct = */ pmuRZConstruct,
201 /* .pfnDestruct = */ NULL,
202 /* .pfnFinalDestruct = */ NULL,
203 /* .pfnRequest = */ NULL,
204 /* .pfnReserved0 = */ NULL,
205 /* .pfnReserved1 = */ NULL,
206 /* .pfnReserved2 = */ NULL,
207 /* .pfnReserved3 = */ NULL,
208 /* .pfnReserved4 = */ NULL,
209 /* .pfnReserved5 = */ NULL,
210 /* .pfnReserved6 = */ NULL,
211 /* .pfnReserved7 = */ NULL,
212#elif defined(IN_RC)
213 /* .pfnConstruct = */ pmuRZConstruct,
214 /* .pfnReserved0 = */ NULL,
215 /* .pfnReserved1 = */ NULL,
216 /* .pfnReserved2 = */ NULL,
217 /* .pfnReserved3 = */ NULL,
218 /* .pfnReserved4 = */ NULL,
219 /* .pfnReserved5 = */ NULL,
220 /* .pfnReserved6 = */ NULL,
221 /* .pfnReserved7 = */ NULL,
222#else
223# error "Not in IN_RING3, IN_RING0 or IN_RC!"
224#endif
225 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
226};
Note: See TracBrowser for help on using the repository browser.

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