VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp@ 88639

Last change on this file since 88639 was 88639, checked in by vboxsync, 4 years ago

Intel IOMMU: bugref:9967 PDM: Enable more interfaces for Intel IOMMU and comment nit.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 208.5 KB
Line 
1/* $Id: PDMDevHlp.cpp 88639 2021-04-22 05:52:42Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, Device Helpers.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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_PDM_DEVICE
23#define PDMPCIDEV_INCLUDE_PRIVATE /* Hack to get pdmpcidevint.h included at the right point. */
24#include "PDMInternal.h"
25#include <VBox/vmm/pdm.h>
26#include <VBox/vmm/mm.h>
27#include <VBox/vmm/hm.h>
28#include <VBox/vmm/pgm.h>
29#include <VBox/vmm/iom.h>
30#include <VBox/vmm/dbgf.h>
31#include <VBox/vmm/ssm.h>
32#include <VBox/vmm/vmapi.h>
33#include <VBox/vmm/vmm.h>
34#include <VBox/vmm/vmcc.h>
35
36#include <VBox/version.h>
37#include <VBox/log.h>
38#include <VBox/pci.h>
39#include <VBox/err.h>
40#include <iprt/asm.h>
41#include <iprt/assert.h>
42#include <iprt/ctype.h>
43#include <iprt/string.h>
44#include <iprt/thread.h>
45#include <iprt/mem.h>
46
47#include "dtrace/VBoxVMM.h"
48#include "PDMInline.h"
49
50
51/*********************************************************************************************************************************
52* Defined Constants And Macros *
53*********************************************************************************************************************************/
54/** @def PDM_DEVHLP_DEADLOCK_DETECTION
55 * Define this to enable the deadlock detection when accessing physical memory.
56 */
57#if /*defined(DEBUG_bird) ||*/ defined(DOXYGEN_RUNNING)
58# define PDM_DEVHLP_DEADLOCK_DETECTION /**< @todo enable DevHlp deadlock detection! */
59#endif
60
61
62
63/** @name R3 DevHlp
64 * @{
65 */
66
67
68/** @interface_method_impl{PDMDEVHLPR3,pfnIoPortCreateEx} */
69static DECLCALLBACK(int) pdmR3DevHlp_IoPortCreateEx(PPDMDEVINS pDevIns, RTIOPORT cPorts, uint32_t fFlags, PPDMPCIDEV pPciDev,
70 uint32_t iPciRegion, PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
71 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr, RTR3PTR pvUser,
72 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
73{
74 PDMDEV_ASSERT_DEVINS(pDevIns);
75 LogFlow(("pdmR3DevHlp_IoPortCreateEx: caller='%s'/%d: cPorts=%#x fFlags=%#x pPciDev=%p iPciRegion=%#x pfnOut=%p pfnIn=%p pfnOutStr=%p pfnInStr=%p pvUser=%p pszDesc=%p:{%s} paExtDescs=%p phIoPorts=%p\n",
76 pDevIns->pReg->szName, pDevIns->iInstance, cPorts, fFlags, pPciDev, iPciRegion, pfnOut, pfnIn, pfnOutStr, pfnInStr,
77 pvUser, pszDesc, pszDesc, paExtDescs, phIoPorts));
78 PVM pVM = pDevIns->Internal.s.pVMR3;
79 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
80 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_VM_INVALID_VM_STATE);
81
82 int rc = IOMR3IoPortCreate(pVM, pDevIns, cPorts, fFlags, pPciDev, iPciRegion,
83 pfnOut, pfnIn, pfnOutStr, pfnInStr, pvUser, pszDesc, paExtDescs, phIoPorts);
84
85 LogFlow(("pdmR3DevHlp_IoPortCreateEx: caller='%s'/%d: returns %Rrc (*phIoPorts=%#x)\n",
86 pDevIns->pReg->szName, pDevIns->iInstance, rc, *phIoPorts));
87 return rc;
88}
89
90
91/** @interface_method_impl{PDMDEVHLPR3,pfnIoPortMap} */
92static DECLCALLBACK(int) pdmR3DevHlp_IoPortMap(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts, RTIOPORT Port)
93{
94 PDMDEV_ASSERT_DEVINS(pDevIns);
95 LogFlow(("pdmR3DevHlp_IoPortMap: caller='%s'/%d: hIoPorts=%#x Port=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, hIoPorts, Port));
96 PVM pVM = pDevIns->Internal.s.pVMR3;
97 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
98
99 int rc = IOMR3IoPortMap(pVM, pDevIns, hIoPorts, Port);
100
101 LogFlow(("pdmR3DevHlp_IoPortMap: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
102 return rc;
103}
104
105
106/** @interface_method_impl{PDMDEVHLPR3,pfnIoPortUnmap} */
107static DECLCALLBACK(int) pdmR3DevHlp_IoPortUnmap(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts)
108{
109 PDMDEV_ASSERT_DEVINS(pDevIns);
110 LogFlow(("pdmR3DevHlp_IoPortMap: caller='%s'/%d: hIoPorts=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, hIoPorts));
111 PVM pVM = pDevIns->Internal.s.pVMR3;
112 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
113
114 int rc = IOMR3IoPortUnmap(pVM, pDevIns, hIoPorts);
115
116 LogFlow(("pdmR3DevHlp_IoPortMap: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
117 return rc;
118}
119
120
121/** @interface_method_impl{PDMDEVHLPR3,pfnIoPortGetMappingAddress} */
122static DECLCALLBACK(uint32_t) pdmR3DevHlp_IoPortGetMappingAddress(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts)
123{
124 PDMDEV_ASSERT_DEVINS(pDevIns);
125 LogFlow(("pdmR3DevHlp_IoPortGetMappingAddress: caller='%s'/%d: hIoPorts=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, hIoPorts));
126
127 uint32_t uAddress = IOMR3IoPortGetMappingAddress(pDevIns->Internal.s.pVMR3, pDevIns, hIoPorts);
128
129 LogFlow(("pdmR3DevHlp_IoPortGetMappingAddress: caller='%s'/%d: returns %#RX32\n", pDevIns->pReg->szName, pDevIns->iInstance, uAddress));
130 return uAddress;
131}
132
133
134/** @interface_method_impl{PDMDEVHLPR3,pfnMmioCreateEx} */
135static DECLCALLBACK(int) pdmR3DevHlp_MmioCreateEx(PPDMDEVINS pDevIns, RTGCPHYS cbRegion,
136 uint32_t fFlags, PPDMPCIDEV pPciDev, uint32_t iPciRegion,
137 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill,
138 void *pvUser, const char *pszDesc, PIOMMMIOHANDLE phRegion)
139{
140 PDMDEV_ASSERT_DEVINS(pDevIns);
141 LogFlow(("pdmR3DevHlp_MmioCreateEx: caller='%s'/%d: cbRegion=%#RGp fFlags=%#x pPciDev=%p iPciRegion=%#x pfnWrite=%p pfnRead=%p pfnFill=%p pvUser=%p pszDesc=%p:{%s} phRegion=%p\n",
142 pDevIns->pReg->szName, pDevIns->iInstance, cbRegion, fFlags, pPciDev, iPciRegion, pfnWrite, pfnRead, pfnFill, pvUser, pszDesc, pszDesc, phRegion));
143 PVM pVM = pDevIns->Internal.s.pVMR3;
144 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
145 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_VM_INVALID_VM_STATE);
146
147 if (pDevIns->iInstance > 0)
148 {
149 pszDesc = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
150 AssertReturn(pszDesc, VERR_NO_STR_MEMORY);
151 }
152
153 /* HACK ALERT! Round the size up to page size. The PCI bus should do something similar before mapping it. */
154 /** @todo It's possible we need to do dummy MMIO fill-in of the PCI bus or
155 * guest adds more alignment to an region. */
156 cbRegion = RT_ALIGN_T(cbRegion, PAGE_SIZE, RTGCPHYS);
157
158 int rc = IOMR3MmioCreate(pVM, pDevIns, cbRegion, fFlags, pPciDev, iPciRegion,
159 pfnWrite, pfnRead, pfnFill, pvUser, pszDesc, phRegion);
160
161 LogFlow(("pdmR3DevHlp_MmioCreateEx: caller='%s'/%d: returns %Rrc (*phRegion=%#x)\n",
162 pDevIns->pReg->szName, pDevIns->iInstance, rc, *phRegion));
163 return rc;
164}
165
166
167/** @interface_method_impl{PDMDEVHLPR3,pfnMmioMap} */
168static DECLCALLBACK(int) pdmR3DevHlp_MmioMap(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, RTGCPHYS GCPhys)
169{
170 PDMDEV_ASSERT_DEVINS(pDevIns);
171 LogFlow(("pdmR3DevHlp_MmioMap: caller='%s'/%d: hRegion=%#x GCPhys=%#RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion, GCPhys));
172 PVM pVM = pDevIns->Internal.s.pVMR3;
173 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
174
175 int rc = IOMR3MmioMap(pVM, pDevIns, hRegion, GCPhys);
176
177 LogFlow(("pdmR3DevHlp_MmioMap: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
178 return rc;
179}
180
181
182/** @interface_method_impl{PDMDEVHLPR3,pfnMmioUnmap} */
183static DECLCALLBACK(int) pdmR3DevHlp_MmioUnmap(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion)
184{
185 PDMDEV_ASSERT_DEVINS(pDevIns);
186 LogFlow(("pdmR3DevHlp_MmioUnmap: caller='%s'/%d: hRegion=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion));
187 PVM pVM = pDevIns->Internal.s.pVMR3;
188 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
189
190 int rc = IOMR3MmioUnmap(pVM, pDevIns, hRegion);
191
192 LogFlow(("pdmR3DevHlp_MmioUnmap: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
193 return rc;
194}
195
196
197/** @interface_method_impl{PDMDEVHLPR3,pfnMmioReduce} */
198static DECLCALLBACK(int) pdmR3DevHlp_MmioReduce(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, RTGCPHYS cbRegion)
199{
200 PDMDEV_ASSERT_DEVINS(pDevIns);
201 LogFlow(("pdmR3DevHlp_MmioReduce: caller='%s'/%d: hRegion=%#x cbRegion=%#RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion, cbRegion));
202 PVM pVM = pDevIns->Internal.s.pVMR3;
203 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
204 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_LOADING, VERR_VM_INVALID_VM_STATE);
205
206 int rc = IOMR3MmioReduce(pVM, pDevIns, hRegion, cbRegion);
207
208 LogFlow(("pdmR3DevHlp_MmioReduce: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
209 return rc;
210}
211
212
213/** @interface_method_impl{PDMDEVHLPR3,pfnMmioGetMappingAddress} */
214static DECLCALLBACK(RTGCPHYS) pdmR3DevHlp_MmioGetMappingAddress(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion)
215{
216 PDMDEV_ASSERT_DEVINS(pDevIns);
217 LogFlow(("pdmR3DevHlp_MmioGetMappingAddress: caller='%s'/%d: hRegion=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion));
218
219 RTGCPHYS GCPhys = IOMR3MmioGetMappingAddress(pDevIns->Internal.s.pVMR3, pDevIns, hRegion);
220
221 LogFlow(("pdmR3DevHlp_MmioGetMappingAddress: caller='%s'/%d: returns %RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, GCPhys));
222 return GCPhys;
223}
224
225
226/** @interface_method_impl{PDMDEVHLPR3,pfnMmio2Create} */
227static DECLCALLBACK(int) pdmR3DevHlp_Mmio2Create(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iPciRegion, RTGCPHYS cbRegion,
228 uint32_t fFlags, const char *pszDesc, void **ppvMapping, PPGMMMIO2HANDLE phRegion)
229{
230 PDMDEV_ASSERT_DEVINS(pDevIns);
231 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
232 LogFlow(("pdmR3DevHlp_Mmio2Create: caller='%s'/%d: pPciDev=%p (%#x) iPciRegion=%#x cbRegion=%#RGp fFlags=%RX32 pszDesc=%p:{%s} ppvMapping=%p phRegion=%p\n",
233 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev ? pPciDev->uDevFn : UINT32_MAX, iPciRegion, cbRegion,
234 fFlags, pszDesc, pszDesc, ppvMapping, phRegion));
235 *ppvMapping = NULL;
236 *phRegion = NIL_PGMMMIO2HANDLE;
237 AssertReturn(!pPciDev || pPciDev->Int.s.pDevInsR3 == pDevIns, VERR_INVALID_PARAMETER);
238
239 PVM pVM = pDevIns->Internal.s.pVMR3;
240 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
241 AssertMsgReturn( pVM->enmVMState == VMSTATE_CREATING
242 || pVM->enmVMState == VMSTATE_LOADING,
243 ("state %s, expected CREATING or LOADING\n", VMGetStateName(pVM->enmVMState)), VERR_VM_INVALID_VM_STATE);
244
245 AssertReturn(!(iPciRegion & UINT16_MAX), VERR_INVALID_PARAMETER); /* not implemented. */
246
247 /** @todo PGMR3PhysMmio2Register mangles the description, move it here and
248 * use a real string cache. */
249 int rc = PGMR3PhysMmio2Register(pVM, pDevIns, pPciDev ? pPciDev->Int.s.idxDevCfg : 254, iPciRegion >> 16,
250 cbRegion, fFlags, pszDesc, ppvMapping, phRegion);
251
252 LogFlow(("pdmR3DevHlp_Mmio2Create: caller='%s'/%d: returns %Rrc *ppvMapping=%p phRegion=%#RX64\n",
253 pDevIns->pReg->szName, pDevIns->iInstance, rc, *ppvMapping, *phRegion));
254 return rc;
255}
256
257
258/** @interface_method_impl{PDMDEVHLPR3,pfnMmio2Destroy} */
259static DECLCALLBACK(int) pdmR3DevHlp_Mmio2Destroy(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion)
260{
261 PDMDEV_ASSERT_DEVINS(pDevIns);
262 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
263 LogFlow(("pdmR3DevHlp_Mmio2Destroy: caller='%s'/%d: hRegion=%#RX64\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion));
264
265 PVM pVM = pDevIns->Internal.s.pVMR3;
266 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
267 AssertMsgReturn( pVM->enmVMState == VMSTATE_DESTROYING
268 || pVM->enmVMState == VMSTATE_LOADING,
269 ("state %s, expected DESTROYING or LOADING\n", VMGetStateName(pVM->enmVMState)), VERR_VM_INVALID_VM_STATE);
270
271 int rc = PGMR3PhysMmio2Deregister(pDevIns->Internal.s.pVMR3, pDevIns, hRegion);
272
273 LogFlow(("pdmR3DevHlp_Mmio2Destroy: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
274 return rc;
275}
276
277
278/** @interface_method_impl{PDMDEVHLPR3,pfnMmio2Map} */
279static DECLCALLBACK(int) pdmR3DevHlp_Mmio2Map(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, RTGCPHYS GCPhys)
280{
281 PDMDEV_ASSERT_DEVINS(pDevIns);
282 LogFlow(("pdmR3DevHlp_Mmio2Map: caller='%s'/%d: hRegion=%#RX64 GCPhys=%RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion, GCPhys));
283
284 PVM pVM = pDevIns->Internal.s.pVMR3;
285 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
286
287 int rc = PGMR3PhysMmio2Map(pDevIns->Internal.s.pVMR3, pDevIns, hRegion, GCPhys);
288
289 LogFlow(("pdmR3DevHlp_Mmio2Map: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
290 return rc;
291}
292
293
294/** @interface_method_impl{PDMDEVHLPR3,pfnMmio2Unmap} */
295static DECLCALLBACK(int) pdmR3DevHlp_Mmio2Unmap(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion)
296{
297 PDMDEV_ASSERT_DEVINS(pDevIns);
298 LogFlow(("pdmR3DevHlp_Mmio2Unmap: caller='%s'/%d: hRegion=%#RX64\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion));
299
300 PVM pVM = pDevIns->Internal.s.pVMR3;
301 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
302
303 int rc = PGMR3PhysMmio2Unmap(pDevIns->Internal.s.pVMR3, pDevIns, hRegion, NIL_RTGCPHYS);
304
305 LogFlow(("pdmR3DevHlp_Mmio2Unmap: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
306 return rc;
307}
308
309
310/** @interface_method_impl{PDMDEVHLPR3,pfnMmio2Reduce} */
311static DECLCALLBACK(int) pdmR3DevHlp_Mmio2Reduce(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, RTGCPHYS cbRegion)
312{
313 PDMDEV_ASSERT_DEVINS(pDevIns);
314 LogFlow(("pdmR3DevHlp_Mmio2Reduce: caller='%s'/%d: hRegion=%#RX64 cbRegion=%RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion, cbRegion));
315 PVM pVM = pDevIns->Internal.s.pVMR3;
316 VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
317 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_LOADING, VERR_VM_INVALID_VM_STATE);
318
319 int rc = PGMR3PhysMmio2Reduce(pDevIns->Internal.s.pVMR3, pDevIns, hRegion, cbRegion);
320
321 LogFlow(("pdmR3DevHlp_Mmio2Reduce: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
322 return rc;
323}
324
325
326/** @interface_method_impl{PDMDEVHLPR3,pfnMmio2GetMappingAddress} */
327static DECLCALLBACK(RTGCPHYS) pdmR3DevHlp_Mmio2GetMappingAddress(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion)
328{
329 PDMDEV_ASSERT_DEVINS(pDevIns);
330 PVM pVM = pDevIns->Internal.s.pVMR3;
331 LogFlow(("pdmR3DevHlp_Mmio2GetMappingAddress: caller='%s'/%d: hRegion=%#RX6r\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion));
332 VM_ASSERT_EMT0_RETURN(pVM, NIL_RTGCPHYS);
333
334 RTGCPHYS GCPhys = PGMR3PhysMmio2GetMappingAddress(pVM, pDevIns, hRegion);
335
336 LogFlow(("pdmR3DevHlp_Mmio2GetMappingAddress: caller='%s'/%d: returns %RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, GCPhys));
337 return GCPhys;
338}
339
340/**
341 * @copydoc PDMDEVHLPR3::pfnMmio2ChangeRegionNo
342 */
343static DECLCALLBACK(int) pdmR3DevHlp_Mmio2ChangeRegionNo(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, uint32_t iNewRegion)
344{
345 PDMDEV_ASSERT_DEVINS(pDevIns);
346 PVM pVM = pDevIns->Internal.s.pVMR3;
347 LogFlow(("pdmR3DevHlp_Mmio2ChangeRegionNo: caller='%s'/%d: hRegion=%#RX6r iNewRegion=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, hRegion, iNewRegion));
348 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
349
350 int rc = PGMR3PhysMmio2ChangeRegionNo(pVM, pDevIns, hRegion, iNewRegion);
351
352 LogFlow(("pdmR3DevHlp_Mmio2ChangeRegionNo: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
353 return rc;
354}
355
356
357/** @interface_method_impl{PDMDEVHLPR3,pfnROMRegister} */
358static DECLCALLBACK(int) pdmR3DevHlp_ROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
359 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc)
360{
361 PDMDEV_ASSERT_DEVINS(pDevIns);
362 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
363 LogFlow(("pdmR3DevHlp_ROMRegister: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x pvBinary=%p cbBinary=%#x fFlags=%#RX32 pszDesc=%p:{%s}\n",
364 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc, pszDesc));
365
366/** @todo can we mangle pszDesc? */
367 int rc = PGMR3PhysRomRegister(pDevIns->Internal.s.pVMR3, pDevIns, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc);
368
369 LogFlow(("pdmR3DevHlp_ROMRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
370 return rc;
371}
372
373
374/** @interface_method_impl{PDMDEVHLPR3,pfnROMProtectShadow} */
375static DECLCALLBACK(int) pdmR3DevHlp_ROMProtectShadow(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt)
376{
377 PDMDEV_ASSERT_DEVINS(pDevIns);
378 LogFlow(("pdmR3DevHlp_ROMProtectShadow: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x enmProt=%d\n",
379 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange, enmProt));
380
381 int rc = PGMR3PhysRomProtect(pDevIns->Internal.s.pVMR3, GCPhysStart, cbRange, enmProt);
382
383 LogFlow(("pdmR3DevHlp_ROMProtectShadow: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
384 return rc;
385}
386
387
388/** @interface_method_impl{PDMDEVHLPR3,pfnSSMRegister} */
389static DECLCALLBACK(int) pdmR3DevHlp_SSMRegister(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
390 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
391 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
392 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
393{
394 PDMDEV_ASSERT_DEVINS(pDevIns);
395 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
396 LogFlow(("pdmR3DevHlp_SSMRegister: caller='%s'/%d: uVersion=%#x cbGuess=%#x pszBefore=%p:{%s}\n"
397 " pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoadDone=%p\n",
398 pDevIns->pReg->szName, pDevIns->iInstance, uVersion, cbGuess, pszBefore, pszBefore,
399 pfnLivePrep, pfnLiveExec, pfnLiveVote,
400 pfnSavePrep, pfnSaveExec, pfnSaveDone,
401 pfnLoadPrep, pfnLoadExec, pfnLoadDone));
402
403 int rc = SSMR3RegisterDevice(pDevIns->Internal.s.pVMR3, pDevIns, pDevIns->pReg->szName, pDevIns->iInstance,
404 uVersion, cbGuess, pszBefore,
405 pfnLivePrep, pfnLiveExec, pfnLiveVote,
406 pfnSavePrep, pfnSaveExec, pfnSaveDone,
407 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
408
409 LogFlow(("pdmR3DevHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
410 return rc;
411}
412
413
414/** @interface_method_impl{PDMDEVHLPR3,pfnTimerCreate} */
415static DECLCALLBACK(int) pdmR3DevHlp_TimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback,
416 void *pvUser, uint32_t fFlags, const char *pszDesc, PTMTIMERHANDLE phTimer)
417{
418 PDMDEV_ASSERT_DEVINS(pDevIns);
419 PVM pVM = pDevIns->Internal.s.pVMR3;
420 VM_ASSERT_EMT(pVM);
421 LogFlow(("pdmR3DevHlp_TimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} phTimer=%p\n",
422 pDevIns->pReg->szName, pDevIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, phTimer));
423
424 /* Mangle the timer name if there are more than one instance of this device. */
425 char szName[32];
426 AssertReturn(strlen(pszDesc) < sizeof(szName) - 3, VERR_INVALID_NAME);
427 if (pDevIns->iInstance > 0)
428 {
429 RTStrPrintf(szName, sizeof(szName), "%s[%u]", pszDesc, pDevIns->iInstance);
430 pszDesc = szName;
431 }
432
433 /* Clear the ring-0 flag if the device isn't configured for ring-0. */
434 if (fFlags & TMTIMER_FLAGS_RING0)
435 {
436 Assert(pDevIns->Internal.s.pDevR3->pReg->fFlags & PDM_DEVREG_FLAGS_R0);
437 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_R0_ENABLED))
438 fFlags &= ~TMTIMER_FLAGS_RING0;
439 }
440 else
441 Assert(fFlags & TMTIMER_FLAGS_NO_RING0 /* just to make sure all devices has been considered */);
442
443 int rc = TMR3TimerCreateDevice(pVM, pDevIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, phTimer);
444
445 LogFlow(("pdmR3DevHlp_TimerCreate: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
446 return rc;
447}
448
449
450/** @interface_method_impl{PDMDEVHLPR3,pfnTimerFromMicro} */
451static DECLCALLBACK(uint64_t) pdmR3DevHlp_TimerFromMicro(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicroSecs)
452{
453 PDMDEV_ASSERT_DEVINS(pDevIns);
454 return TMTimerFromMicro(pDevIns->Internal.s.pVMR3, hTimer, cMicroSecs);
455}
456
457
458/** @interface_method_impl{PDMDEVHLPR3,pfnTimerFromMilli} */
459static DECLCALLBACK(uint64_t) pdmR3DevHlp_TimerFromMilli(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliSecs)
460{
461 PDMDEV_ASSERT_DEVINS(pDevIns);
462 return TMTimerFromMilli(pDevIns->Internal.s.pVMR3, hTimer, cMilliSecs);
463}
464
465
466/** @interface_method_impl{PDMDEVHLPR3,pfnTimerFromNano} */
467static DECLCALLBACK(uint64_t) pdmR3DevHlp_TimerFromNano(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanoSecs)
468{
469 PDMDEV_ASSERT_DEVINS(pDevIns);
470 return TMTimerFromNano(pDevIns->Internal.s.pVMR3, hTimer, cNanoSecs);
471}
472
473/** @interface_method_impl{PDMDEVHLPR3,pfnTimerGet} */
474static DECLCALLBACK(uint64_t) pdmR3DevHlp_TimerGet(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
475{
476 PDMDEV_ASSERT_DEVINS(pDevIns);
477 return TMTimerGet(pDevIns->Internal.s.pVMR3, hTimer);
478}
479
480
481/** @interface_method_impl{PDMDEVHLPR3,pfnTimerGetFreq} */
482static DECLCALLBACK(uint64_t) pdmR3DevHlp_TimerGetFreq(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
483{
484 PDMDEV_ASSERT_DEVINS(pDevIns);
485 return TMTimerGetFreq(pDevIns->Internal.s.pVMR3, hTimer);
486}
487
488
489/** @interface_method_impl{PDMDEVHLPR3,pfnTimerGetNano} */
490static DECLCALLBACK(uint64_t) pdmR3DevHlp_TimerGetNano(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
491{
492 PDMDEV_ASSERT_DEVINS(pDevIns);
493 return TMTimerGetNano(pDevIns->Internal.s.pVMR3, hTimer);
494}
495
496
497/** @interface_method_impl{PDMDEVHLPR3,pfnTimerIsActive} */
498static DECLCALLBACK(bool) pdmR3DevHlp_TimerIsActive(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
499{
500 PDMDEV_ASSERT_DEVINS(pDevIns);
501 return TMTimerIsActive(pDevIns->Internal.s.pVMR3, hTimer);
502}
503
504
505/** @interface_method_impl{PDMDEVHLPR3,pfnTimerIsLockOwner} */
506static DECLCALLBACK(bool) pdmR3DevHlp_TimerIsLockOwner(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
507{
508 PDMDEV_ASSERT_DEVINS(pDevIns);
509 return TMTimerIsLockOwner(pDevIns->Internal.s.pVMR3, hTimer);
510}
511
512
513/** @interface_method_impl{PDMDEVHLPR3,pfnTimerLockClock} */
514static DECLCALLBACK(VBOXSTRICTRC) pdmR3DevHlp_TimerLockClock(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, int rcBusy)
515{
516 PDMDEV_ASSERT_DEVINS(pDevIns);
517 return TMTimerLock(pDevIns->Internal.s.pVMR3, hTimer, rcBusy);
518}
519
520
521/** @interface_method_impl{PDMDEVHLPR3,pfnTimerLockClock2} */
522static DECLCALLBACK(VBOXSTRICTRC) pdmR3DevHlp_TimerLockClock2(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer,
523 PPDMCRITSECT pCritSect, int rcBusy)
524{
525 PDMDEV_ASSERT_DEVINS(pDevIns);
526 VBOXSTRICTRC rc = TMTimerLock(pDevIns->Internal.s.pVMR3, hTimer, rcBusy);
527 if (rc == VINF_SUCCESS)
528 {
529 rc = PDMCritSectEnter(pCritSect, rcBusy);
530 if (rc == VINF_SUCCESS)
531 return rc;
532 AssertRC(VBOXSTRICTRC_VAL(rc));
533 TMTimerUnlock(pDevIns->Internal.s.pVMR3, hTimer);
534 }
535 else
536 AssertRC(VBOXSTRICTRC_VAL(rc));
537 return rc;
538}
539
540
541/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSet} */
542static DECLCALLBACK(int) pdmR3DevHlp_TimerSet(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t uExpire)
543{
544 PDMDEV_ASSERT_DEVINS(pDevIns);
545 return TMTimerSet(pDevIns->Internal.s.pVMR3, hTimer, uExpire);
546}
547
548
549/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSetFrequencyHint} */
550static DECLCALLBACK(int) pdmR3DevHlp_TimerSetFrequencyHint(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint32_t uHz)
551{
552 PDMDEV_ASSERT_DEVINS(pDevIns);
553 return TMTimerSetFrequencyHint(pDevIns->Internal.s.pVMR3, hTimer, uHz);
554}
555
556
557/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSetMicro} */
558static DECLCALLBACK(int) pdmR3DevHlp_TimerSetMicro(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext)
559{
560 PDMDEV_ASSERT_DEVINS(pDevIns);
561 return TMTimerSetMicro(pDevIns->Internal.s.pVMR3, hTimer, cMicrosToNext);
562}
563
564
565/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSetMillies} */
566static DECLCALLBACK(int) pdmR3DevHlp_TimerSetMillies(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliesToNext)
567{
568 PDMDEV_ASSERT_DEVINS(pDevIns);
569 return TMTimerSetMillies(pDevIns->Internal.s.pVMR3, hTimer, cMilliesToNext);
570}
571
572
573/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSetNano} */
574static DECLCALLBACK(int) pdmR3DevHlp_TimerSetNano(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanosToNext)
575{
576 PDMDEV_ASSERT_DEVINS(pDevIns);
577 return TMTimerSetNano(pDevIns->Internal.s.pVMR3, hTimer, cNanosToNext);
578}
579
580
581/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSetRelative} */
582static DECLCALLBACK(int) pdmR3DevHlp_TimerSetRelative(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now)
583{
584 PDMDEV_ASSERT_DEVINS(pDevIns);
585 return TMTimerSetRelative(pDevIns->Internal.s.pVMR3, hTimer, cTicksToNext, pu64Now);
586}
587
588
589/** @interface_method_impl{PDMDEVHLPR3,pfnTimerStop} */
590static DECLCALLBACK(int) pdmR3DevHlp_TimerStop(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
591{
592 PDMDEV_ASSERT_DEVINS(pDevIns);
593 return TMTimerStop(pDevIns->Internal.s.pVMR3, hTimer);
594}
595
596
597/** @interface_method_impl{PDMDEVHLPR3,pfnTimerUnlockClock} */
598static DECLCALLBACK(void) pdmR3DevHlp_TimerUnlockClock(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
599{
600 PDMDEV_ASSERT_DEVINS(pDevIns);
601 TMTimerUnlock(pDevIns->Internal.s.pVMR3, hTimer);
602}
603
604
605/** @interface_method_impl{PDMDEVHLPR3,pfnTimerUnlockClock2} */
606static DECLCALLBACK(void) pdmR3DevHlp_TimerUnlockClock2(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect)
607{
608 PDMDEV_ASSERT_DEVINS(pDevIns);
609 TMTimerUnlock(pDevIns->Internal.s.pVMR3, hTimer);
610 int rc = PDMCritSectLeave(pCritSect);
611 AssertRC(rc);
612}
613
614
615/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSetCritSect} */
616static DECLCALLBACK(int) pdmR3DevHlp_TimerSetCritSect(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect)
617{
618 PDMDEV_ASSERT_DEVINS(pDevIns);
619 return TMR3TimerSetCritSect(pDevIns->Internal.s.pVMR3, hTimer, pCritSect);
620}
621
622
623/** @interface_method_impl{PDMDEVHLPR3,pfnTimerSave} */
624static DECLCALLBACK(int) pdmR3DevHlp_TimerSave(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM)
625{
626 PDMDEV_ASSERT_DEVINS(pDevIns);
627 return TMR3TimerSave(pDevIns->Internal.s.pVMR3, hTimer, pSSM);
628}
629
630
631/** @interface_method_impl{PDMDEVHLPR3,pfnTimerLoad} */
632static DECLCALLBACK(int) pdmR3DevHlp_TimerLoad(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM)
633{
634 PDMDEV_ASSERT_DEVINS(pDevIns);
635 return TMR3TimerLoad(pDevIns->Internal.s.pVMR3, hTimer, pSSM);
636}
637
638
639/** @interface_method_impl{PDMDEVHLPR3,pfnTimerDestroy} */
640static DECLCALLBACK(int) pdmR3DevHlp_TimerDestroy(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
641{
642 PDMDEV_ASSERT_DEVINS(pDevIns);
643 return TMR3TimerDestroy(pDevIns->Internal.s.pVMR3, hTimer);
644}
645
646
647/** @interface_method_impl{PDMDEVHLPR3,pfnTMUtcNow} */
648static DECLCALLBACK(PRTTIMESPEC) pdmR3DevHlp_TMUtcNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
649{
650 PDMDEV_ASSERT_DEVINS(pDevIns);
651 LogFlow(("pdmR3DevHlp_TMUtcNow: caller='%s'/%d: pTime=%p\n",
652 pDevIns->pReg->szName, pDevIns->iInstance, pTime));
653
654 pTime = TMR3UtcNow(pDevIns->Internal.s.pVMR3, pTime);
655
656 LogFlow(("pdmR3DevHlp_TMUtcNow: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, RTTimeSpecGetNano(pTime)));
657 return pTime;
658}
659
660
661/** @interface_method_impl{PDMDEVHLPR3,pfnTMTimeVirtGet} */
662static DECLCALLBACK(uint64_t) pdmR3DevHlp_TMTimeVirtGet(PPDMDEVINS pDevIns)
663{
664 PDMDEV_ASSERT_DEVINS(pDevIns);
665 LogFlow(("pdmR3DevHlp_TMTimeVirtGet: caller='%s'/%d\n",
666 pDevIns->pReg->szName, pDevIns->iInstance));
667
668 uint64_t u64Time = TMVirtualSyncGet(pDevIns->Internal.s.pVMR3);
669
670 LogFlow(("pdmR3DevHlp_TMTimeVirtGet: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, u64Time));
671 return u64Time;
672}
673
674
675/** @interface_method_impl{PDMDEVHLPR3,pfnTMTimeVirtGetFreq} */
676static DECLCALLBACK(uint64_t) pdmR3DevHlp_TMTimeVirtGetFreq(PPDMDEVINS pDevIns)
677{
678 PDMDEV_ASSERT_DEVINS(pDevIns);
679 LogFlow(("pdmR3DevHlp_TMTimeVirtGetFreq: caller='%s'/%d\n",
680 pDevIns->pReg->szName, pDevIns->iInstance));
681
682 uint64_t u64Freq = TMVirtualGetFreq(pDevIns->Internal.s.pVMR3);
683
684 LogFlow(("pdmR3DevHlp_TMTimeVirtGetFreq: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, u64Freq));
685 return u64Freq;
686}
687
688
689/** @interface_method_impl{PDMDEVHLPR3,pfnTMTimeVirtGetNano} */
690static DECLCALLBACK(uint64_t) pdmR3DevHlp_TMTimeVirtGetNano(PPDMDEVINS pDevIns)
691{
692 PDMDEV_ASSERT_DEVINS(pDevIns);
693 LogFlow(("pdmR3DevHlp_TMTimeVirtGetNano: caller='%s'/%d\n",
694 pDevIns->pReg->szName, pDevIns->iInstance));
695
696 uint64_t u64Time = TMVirtualGet(pDevIns->Internal.s.pVMR3);
697 uint64_t u64Nano = TMVirtualToNano(pDevIns->Internal.s.pVMR3, u64Time);
698
699 LogFlow(("pdmR3DevHlp_TMTimeVirtGetNano: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, u64Nano));
700 return u64Nano;
701}
702
703
704/** @interface_method_impl{PDMDEVHLPR3,pfnGetSupDrvSession} */
705static DECLCALLBACK(PSUPDRVSESSION) pdmR3DevHlp_GetSupDrvSession(PPDMDEVINS pDevIns)
706{
707 PDMDEV_ASSERT_DEVINS(pDevIns);
708 LogFlow(("pdmR3DevHlp_GetSupDrvSession: caller='%s'/%d\n",
709 pDevIns->pReg->szName, pDevIns->iInstance));
710
711 PSUPDRVSESSION pSession = pDevIns->Internal.s.pVMR3->pSession;
712
713 LogFlow(("pdmR3DevHlp_GetSupDrvSession: caller='%s'/%d: returns %#p\n", pDevIns->pReg->szName, pDevIns->iInstance, pSession));
714 return pSession;
715}
716
717
718/** @interface_method_impl{PDMDEVHLPR3,pfnQueryGenericUserObject} */
719static DECLCALLBACK(void *) pdmR3DevHlp_QueryGenericUserObject(PPDMDEVINS pDevIns, PCRTUUID pUuid)
720{
721 PDMDEV_ASSERT_DEVINS(pDevIns);
722 LogFlow(("pdmR3DevHlp_QueryGenericUserObject: caller='%s'/%d: pUuid=%p:%RTuuid\n",
723 pDevIns->pReg->szName, pDevIns->iInstance, pUuid, pUuid));
724
725#if defined(DEBUG_bird) || defined(DEBUG_ramshankar) || defined(DEBUG_sunlover) || defined(DEBUG_michael) || defined(DEBUG_andy)
726 AssertMsgFailed(("'%s' wants %RTuuid - external only interface!\n", pDevIns->pReg->szName, pUuid));
727#endif
728
729 void *pvRet;
730 PUVM pUVM = pDevIns->Internal.s.pVMR3->pUVM;
731 if (pUVM->pVmm2UserMethods->pfnQueryGenericObject)
732 pvRet = pUVM->pVmm2UserMethods->pfnQueryGenericObject(pUVM->pVmm2UserMethods, pUVM, pUuid);
733 else
734 pvRet = NULL;
735
736 LogRel(("pdmR3DevHlp_QueryGenericUserObject: caller='%s'/%d: returns %#p for %RTuuid\n",
737 pDevIns->pReg->szName, pDevIns->iInstance, pvRet, pUuid));
738 return pvRet;
739}
740
741
742/** @interface_method_impl{PDMDEVHLPR3,pfnPGMHandlerPhysicalTypeRegister} */
743static DECLCALLBACK(int) pdmR3DevHlp_PGMHandlerPhysicalTypeRegister(PPDMDEVINS pDevIns, PGMPHYSHANDLERKIND enmKind,
744 R3PTRTYPE(PFNPGMPHYSHANDLER) pfnHandlerR3,
745 const char *pszHandlerR0, const char *pszPfHandlerR0,
746 const char *pszHandlerRC, const char *pszPfHandlerRC,
747 const char *pszDesc, PPGMPHYSHANDLERTYPE phType)
748{
749 PDMDEV_ASSERT_DEVINS(pDevIns);
750 PVM pVM = pDevIns->Internal.s.pVMR3;
751 LogFlow(("pdmR3DevHlp_PGMHandlerPhysicalTypeRegister: caller='%s'/%d: enmKind=%d pfnHandlerR3=%p pszHandlerR0=%p:{%s} pszPfHandlerR0=%p:{%s} pszHandlerRC=%p:{%s} pszPfHandlerRC=%p:{%s} pszDesc=%p:{%s} phType=%p\n",
752 pDevIns->pReg->szName, pDevIns->iInstance, enmKind, pfnHandlerR3,
753 pszHandlerR0, pszHandlerR0, pszPfHandlerR0, pszPfHandlerR0,
754 pszHandlerRC, pszHandlerRC, pszPfHandlerRC, pszPfHandlerRC,
755 pszDesc, pszDesc, phType));
756
757 int rc = PGMR3HandlerPhysicalTypeRegister(pVM, enmKind, pfnHandlerR3,
758 pDevIns->pReg->pszR0Mod, pszHandlerR0, pszPfHandlerR0,
759 pDevIns->pReg->pszRCMod, pszHandlerRC, pszPfHandlerRC,
760 pszDesc, phType);
761
762 Log(("pdmR3DevHlp_PGMHandlerPhysicalTypeRegister: caller='%s'/%d: returns %Rrc\n",
763 pDevIns->pReg->szName, pDevIns->iInstance, rc));
764 return rc;
765}
766
767
768/** @interface_method_impl{PDMDEVHLPR3,pfnPhysRead} */
769static DECLCALLBACK(int) pdmR3DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags)
770{
771 RT_NOREF(fFlags);
772
773 PDMDEV_ASSERT_DEVINS(pDevIns);
774 PVM pVM = pDevIns->Internal.s.pVMR3;
775 LogFlow(("pdmR3DevHlp_PhysRead: caller='%s'/%d: GCPhys=%RGp pvBuf=%p cbRead=%#x\n",
776 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, pvBuf, cbRead));
777
778#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
779 if (!VM_IS_EMT(pVM))
780 {
781 char szNames[128];
782 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
783 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
784 }
785#endif
786
787 VBOXSTRICTRC rcStrict;
788 if (VM_IS_EMT(pVM))
789 rcStrict = PGMPhysRead(pVM, GCPhys, pvBuf, cbRead, PGMACCESSORIGIN_DEVICE);
790 else
791 rcStrict = PGMR3PhysReadExternal(pVM, GCPhys, pvBuf, cbRead, PGMACCESSORIGIN_DEVICE);
792 AssertMsg(rcStrict == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict))); /** @todo track down the users for this bugger. */
793
794 Log(("pdmR3DevHlp_PhysRead: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VBOXSTRICTRC_VAL(rcStrict) ));
795 return VBOXSTRICTRC_VAL(rcStrict);
796}
797
798
799/** @interface_method_impl{PDMDEVHLPR3,pfnPhysWrite} */
800static DECLCALLBACK(int) pdmR3DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags)
801{
802 RT_NOREF(fFlags);
803
804 PDMDEV_ASSERT_DEVINS(pDevIns);
805 PVM pVM = pDevIns->Internal.s.pVMR3;
806 LogFlow(("pdmR3DevHlp_PhysWrite: caller='%s'/%d: GCPhys=%RGp pvBuf=%p cbWrite=%#x\n",
807 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, pvBuf, cbWrite));
808
809#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
810 if (!VM_IS_EMT(pVM))
811 {
812 char szNames[128];
813 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
814 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
815 }
816#endif
817
818 VBOXSTRICTRC rcStrict;
819 if (VM_IS_EMT(pVM))
820 rcStrict = PGMPhysWrite(pVM, GCPhys, pvBuf, cbWrite, PGMACCESSORIGIN_DEVICE);
821 else
822 rcStrict = PGMR3PhysWriteExternal(pVM, GCPhys, pvBuf, cbWrite, PGMACCESSORIGIN_DEVICE);
823 AssertMsg(rcStrict == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict))); /** @todo track down the users for this bugger. */
824
825 Log(("pdmR3DevHlp_PhysWrite: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VBOXSTRICTRC_VAL(rcStrict) ));
826 return VBOXSTRICTRC_VAL(rcStrict);
827}
828
829
830/** @interface_method_impl{PDMDEVHLPR3,pfnPhysGCPhys2CCPtr} */
831static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
832{
833 PDMDEV_ASSERT_DEVINS(pDevIns);
834 PVM pVM = pDevIns->Internal.s.pVMR3;
835 LogFlow(("pdmR3DevHlp_PhysGCPhys2CCPtr: caller='%s'/%d: GCPhys=%RGp fFlags=%#x ppv=%p pLock=%p\n",
836 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, fFlags, ppv, pLock));
837 AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
838
839#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
840 if (!VM_IS_EMT(pVM))
841 {
842 char szNames[128];
843 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
844 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
845 }
846#endif
847
848 int rc = PGMR3PhysGCPhys2CCPtrExternal(pVM, GCPhys, ppv, pLock);
849
850 Log(("pdmR3DevHlp_PhysGCPhys2CCPtr: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
851 return rc;
852}
853
854
855/** @interface_method_impl{PDMDEVHLPR3,pfnPhysGCPhys2CCPtrReadOnly} */
856static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, const void **ppv, PPGMPAGEMAPLOCK pLock)
857{
858 PDMDEV_ASSERT_DEVINS(pDevIns);
859 PVM pVM = pDevIns->Internal.s.pVMR3;
860 LogFlow(("pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly: caller='%s'/%d: GCPhys=%RGp fFlags=%#x ppv=%p pLock=%p\n",
861 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, fFlags, ppv, pLock));
862 AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
863
864#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
865 if (!VM_IS_EMT(pVM))
866 {
867 char szNames[128];
868 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
869 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
870 }
871#endif
872
873 int rc = PGMR3PhysGCPhys2CCPtrReadOnlyExternal(pVM, GCPhys, ppv, pLock);
874
875 Log(("pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
876 return rc;
877}
878
879
880/** @interface_method_impl{PDMDEVHLPR3,pfnPhysReleasePageMappingLock} */
881static DECLCALLBACK(void) pdmR3DevHlp_PhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
882{
883 PDMDEV_ASSERT_DEVINS(pDevIns);
884 PVM pVM = pDevIns->Internal.s.pVMR3;
885 LogFlow(("pdmR3DevHlp_PhysReleasePageMappingLock: caller='%s'/%d: pLock=%p\n",
886 pDevIns->pReg->szName, pDevIns->iInstance, pLock));
887
888 PGMPhysReleasePageMappingLock(pVM, pLock);
889
890 Log(("pdmR3DevHlp_PhysReleasePageMappingLock: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
891}
892
893
894/** @interface_method_impl{PDMDEVHLPR3,pfnPhysBulkGCPhys2CCPtr} */
895static DECLCALLBACK(int) pdmR3DevHlp_PhysBulkGCPhys2CCPtr(PPDMDEVINS pDevIns, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
896 uint32_t fFlags, void **papvPages, PPGMPAGEMAPLOCK paLocks)
897{
898 PDMDEV_ASSERT_DEVINS(pDevIns);
899 PVM pVM = pDevIns->Internal.s.pVMR3;
900 LogFlow(("pdmR3DevHlp_PhysBulkGCPhys2CCPtr: caller='%s'/%d: cPages=%#x paGCPhysPages=%p (%RGp,..) fFlags=%#x papvPages=%p paLocks=%p\n",
901 pDevIns->pReg->szName, pDevIns->iInstance, cPages, paGCPhysPages, paGCPhysPages[0], fFlags, papvPages, paLocks));
902 AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
903 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER);
904
905#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
906 if (!VM_IS_EMT(pVM))
907 {
908 char szNames[128];
909 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
910 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
911 }
912#endif
913
914 int rc = PGMR3PhysBulkGCPhys2CCPtrExternal(pVM, cPages, paGCPhysPages, papvPages, paLocks);
915
916 Log(("pdmR3DevHlp_PhysBulkGCPhys2CCPtr: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
917 return rc;
918}
919
920
921/** @interface_method_impl{PDMDEVHLPR3,pfnPhysBulkGCPhys2CCPtrReadOnly} */
922static DECLCALLBACK(int) pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
923 uint32_t fFlags, const void **papvPages, PPGMPAGEMAPLOCK paLocks)
924{
925 PDMDEV_ASSERT_DEVINS(pDevIns);
926 PVM pVM = pDevIns->Internal.s.pVMR3;
927 LogFlow(("pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly: caller='%s'/%d: cPages=%#x paGCPhysPages=%p (%RGp,...) fFlags=%#x papvPages=%p paLocks=%p\n",
928 pDevIns->pReg->szName, pDevIns->iInstance, cPages, paGCPhysPages, paGCPhysPages[0], fFlags, papvPages, paLocks));
929 AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
930 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER);
931
932#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
933 if (!VM_IS_EMT(pVM))
934 {
935 char szNames[128];
936 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
937 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
938 }
939#endif
940
941 int rc = PGMR3PhysBulkGCPhys2CCPtrReadOnlyExternal(pVM, cPages, paGCPhysPages, papvPages, paLocks);
942
943 Log(("pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
944 return rc;
945}
946
947
948/** @interface_method_impl{PDMDEVHLPR3,pfnPhysBulkReleasePageMappingLocks} */
949static DECLCALLBACK(void) pdmR3DevHlp_PhysBulkReleasePageMappingLocks(PPDMDEVINS pDevIns, uint32_t cPages, PPGMPAGEMAPLOCK paLocks)
950{
951 PDMDEV_ASSERT_DEVINS(pDevIns);
952 PVM pVM = pDevIns->Internal.s.pVMR3;
953 LogFlow(("pdmR3DevHlp_PhysBulkReleasePageMappingLocks: caller='%s'/%d: cPages=%#x paLocks=%p\n",
954 pDevIns->pReg->szName, pDevIns->iInstance, cPages, paLocks));
955 Assert(cPages > 0);
956
957 PGMPhysBulkReleasePageMappingLocks(pVM, cPages, paLocks);
958
959 Log(("pdmR3DevHlp_PhysBulkReleasePageMappingLocks: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
960}
961
962
963/** @interface_method_impl{PDMDEVHLPR3,pfnCpuGetGuestMicroarch} */
964static DECLCALLBACK(CPUMMICROARCH) pdmR3DevHlp_CpuGetGuestMicroarch(PPDMDEVINS pDevIns)
965{
966 PDMDEV_ASSERT_DEVINS(pDevIns);
967 PVM pVM = pDevIns->Internal.s.pVMR3;
968 LogFlow(("pdmR3DevHlp_CpuGetGuestMicroarch: caller='%s'/%d\n",
969 pDevIns->pReg->szName, pDevIns->iInstance));
970
971 CPUMMICROARCH enmMicroarch = CPUMGetGuestMicroarch(pVM);
972
973 Log(("pdmR3DevHlp_CpuGetGuestMicroarch: caller='%s'/%d: returns %u\n", pDevIns->pReg->szName, pDevIns->iInstance, enmMicroarch));
974 return enmMicroarch;
975}
976
977
978/** @interface_method_impl{PDMDEVHLPR3,pfnCpuGetGuestAddrWidths} */
979static DECLCALLBACK(void) pdmR3DevHlp_CpuGetGuestAddrWidths(PPDMDEVINS pDevIns, uint8_t *pcPhysAddrWidth,
980 uint8_t *pcLinearAddrWidth)
981{
982 PDMDEV_ASSERT_DEVINS(pDevIns);
983 PVM pVM = pDevIns->Internal.s.pVMR3;
984 LogFlow(("pdmR3DevHlp_CpuGetGuestAddrWidths: caller='%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
985 AssertPtrReturnVoid(pcPhysAddrWidth);
986 AssertPtrReturnVoid(pcLinearAddrWidth);
987
988 CPUMGetGuestAddrWidths(pVM, pcPhysAddrWidth, pcLinearAddrWidth);
989
990 Log(("pdmR3DevHlp_CpuGetGuestAddrWidths: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
991}
992
993
994/** @interface_method_impl{PDMDEVHLPR3,pfnPhysReadGCVirt} */
995static DECLCALLBACK(int) pdmR3DevHlp_PhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
996{
997 PDMDEV_ASSERT_DEVINS(pDevIns);
998 PVM pVM = pDevIns->Internal.s.pVMR3;
999 VM_ASSERT_EMT(pVM);
1000 LogFlow(("pdmR3DevHlp_PhysReadGCVirt: caller='%s'/%d: pvDst=%p GCVirt=%RGv cb=%#x\n",
1001 pDevIns->pReg->szName, pDevIns->iInstance, pvDst, GCVirtSrc, cb));
1002
1003 PVMCPU pVCpu = VMMGetCpu(pVM);
1004 if (!pVCpu)
1005 return VERR_ACCESS_DENIED;
1006#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
1007 /** @todo SMP. */
1008#endif
1009
1010 int rc = PGMPhysSimpleReadGCPtr(pVCpu, pvDst, GCVirtSrc, cb);
1011
1012 LogFlow(("pdmR3DevHlp_PhysReadGCVirt: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1013
1014 return rc;
1015}
1016
1017
1018/** @interface_method_impl{PDMDEVHLPR3,pfnPhysWriteGCVirt} */
1019static DECLCALLBACK(int) pdmR3DevHlp_PhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
1020{
1021 PDMDEV_ASSERT_DEVINS(pDevIns);
1022 PVM pVM = pDevIns->Internal.s.pVMR3;
1023 VM_ASSERT_EMT(pVM);
1024 LogFlow(("pdmR3DevHlp_PhysWriteGCVirt: caller='%s'/%d: GCVirtDst=%RGv pvSrc=%p cb=%#x\n",
1025 pDevIns->pReg->szName, pDevIns->iInstance, GCVirtDst, pvSrc, cb));
1026
1027 PVMCPU pVCpu = VMMGetCpu(pVM);
1028 if (!pVCpu)
1029 return VERR_ACCESS_DENIED;
1030#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
1031 /** @todo SMP. */
1032#endif
1033
1034 int rc = PGMPhysSimpleWriteGCPtr(pVCpu, GCVirtDst, pvSrc, cb);
1035
1036 LogFlow(("pdmR3DevHlp_PhysWriteGCVirt: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1037
1038 return rc;
1039}
1040
1041
1042/** @interface_method_impl{PDMDEVHLPR3,pfnPhysGCPtr2GCPhys} */
1043static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPtr2GCPhys(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys)
1044{
1045 PDMDEV_ASSERT_DEVINS(pDevIns);
1046 PVM pVM = pDevIns->Internal.s.pVMR3;
1047 VM_ASSERT_EMT(pVM);
1048 LogFlow(("pdmR3DevHlp_PhysGCPtr2GCPhys: caller='%s'/%d: GCPtr=%RGv pGCPhys=%p\n",
1049 pDevIns->pReg->szName, pDevIns->iInstance, GCPtr, pGCPhys));
1050
1051 PVMCPU pVCpu = VMMGetCpu(pVM);
1052 if (!pVCpu)
1053 return VERR_ACCESS_DENIED;
1054#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
1055 /** @todo SMP. */
1056#endif
1057
1058 int rc = PGMPhysGCPtr2GCPhys(pVCpu, GCPtr, pGCPhys);
1059
1060 LogFlow(("pdmR3DevHlp_PhysGCPtr2GCPhys: caller='%s'/%d: returns %Rrc *pGCPhys=%RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *pGCPhys));
1061
1062 return rc;
1063}
1064
1065
1066/** @interface_method_impl{PDMDEVHLPR3,pfnMMHeapAlloc} */
1067static DECLCALLBACK(void *) pdmR3DevHlp_MMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
1068{
1069 PDMDEV_ASSERT_DEVINS(pDevIns);
1070 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: cb=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cb));
1071
1072 void *pv = MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE_USER, cb);
1073
1074 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv));
1075 return pv;
1076}
1077
1078
1079/** @interface_method_impl{PDMDEVHLPR3,pfnMMHeapAllocZ} */
1080static DECLCALLBACK(void *) pdmR3DevHlp_MMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
1081{
1082 PDMDEV_ASSERT_DEVINS(pDevIns);
1083 LogFlow(("pdmR3DevHlp_MMHeapAllocZ: caller='%s'/%d: cb=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cb));
1084
1085 void *pv = MMR3HeapAllocZ(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE_USER, cb);
1086
1087 LogFlow(("pdmR3DevHlp_MMHeapAllocZ: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv));
1088 return pv;
1089}
1090
1091
1092/** @interface_method_impl{PDMDEVHLPR3,pfnMMHeapFree} */
1093static DECLCALLBACK(void) pdmR3DevHlp_MMHeapFree(PPDMDEVINS pDevIns, void *pv)
1094{
1095 PDMDEV_ASSERT_DEVINS(pDevIns); RT_NOREF_PV(pDevIns);
1096 LogFlow(("pdmR3DevHlp_MMHeapFree: caller='%s'/%d: pv=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv));
1097
1098 MMR3HeapFree(pv);
1099
1100 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1101}
1102
1103
1104/** @interface_method_impl{PDMDEVHLPR3,pfnVMState} */
1105static DECLCALLBACK(VMSTATE) pdmR3DevHlp_VMState(PPDMDEVINS pDevIns)
1106{
1107 PDMDEV_ASSERT_DEVINS(pDevIns);
1108
1109 VMSTATE enmVMState = VMR3GetState(pDevIns->Internal.s.pVMR3);
1110
1111 LogFlow(("pdmR3DevHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDevIns->pReg->szName, pDevIns->iInstance,
1112 enmVMState, VMR3GetStateName(enmVMState)));
1113 return enmVMState;
1114}
1115
1116
1117/** @interface_method_impl{PDMDEVHLPR3,pfnVMTeleportedAndNotFullyResumedYet} */
1118static DECLCALLBACK(bool) pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet(PPDMDEVINS pDevIns)
1119{
1120 PDMDEV_ASSERT_DEVINS(pDevIns);
1121
1122 bool fRc = VMR3TeleportedAndNotFullyResumedYet(pDevIns->Internal.s.pVMR3);
1123
1124 LogFlow(("pdmR3DevHlp_VMState: caller='%s'/%d: returns %RTbool\n", pDevIns->pReg->szName, pDevIns->iInstance,
1125 fRc));
1126 return fRc;
1127}
1128
1129
1130/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetError} */
1131static DECLCALLBACK(int) pdmR3DevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
1132{
1133 PDMDEV_ASSERT_DEVINS(pDevIns);
1134 va_list args;
1135 va_start(args, pszFormat);
1136 int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
1137 va_end(args);
1138 return rc;
1139}
1140
1141
1142/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetErrorV} */
1143static DECLCALLBACK(int) pdmR3DevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
1144{
1145 PDMDEV_ASSERT_DEVINS(pDevIns);
1146 int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
1147 return rc;
1148}
1149
1150
1151/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetRuntimeError} */
1152static DECLCALLBACK(int) pdmR3DevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
1153{
1154 PDMDEV_ASSERT_DEVINS(pDevIns);
1155 va_list args;
1156 va_start(args, pszFormat);
1157 int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, args);
1158 va_end(args);
1159 return rc;
1160}
1161
1162
1163/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetRuntimeErrorV} */
1164static DECLCALLBACK(int) pdmR3DevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
1165{
1166 PDMDEV_ASSERT_DEVINS(pDevIns);
1167 int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, va);
1168 return rc;
1169}
1170
1171
1172/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFStopV} */
1173static DECLCALLBACK(int) pdmR3DevHlp_DBGFStopV(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list args)
1174{
1175 PDMDEV_ASSERT_DEVINS(pDevIns);
1176#ifdef LOG_ENABLED
1177 va_list va2;
1178 va_copy(va2, args);
1179 LogFlow(("pdmR3DevHlp_DBGFStopV: caller='%s'/%d: pszFile=%p:{%s} iLine=%d pszFunction=%p:{%s} pszFormat=%p:{%s} (%N)\n",
1180 pDevIns->pReg->szName, pDevIns->iInstance, pszFile, pszFile, iLine, pszFunction, pszFunction, pszFormat, pszFormat, pszFormat, &va2));
1181 va_end(va2);
1182#endif
1183
1184 PVM pVM = pDevIns->Internal.s.pVMR3;
1185 VM_ASSERT_EMT(pVM);
1186 int rc = DBGFR3EventSrcV(pVM, DBGFEVENT_DEV_STOP, pszFile, iLine, pszFunction, pszFormat, args);
1187 if (rc == VERR_DBGF_NOT_ATTACHED)
1188 rc = VINF_SUCCESS;
1189
1190 LogFlow(("pdmR3DevHlp_DBGFStopV: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1191 return rc;
1192}
1193
1194
1195/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFInfoRegister} */
1196static DECLCALLBACK(int) pdmR3DevHlp_DBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
1197{
1198 PDMDEV_ASSERT_DEVINS(pDevIns);
1199 LogFlow(("pdmR3DevHlp_DBGFInfoRegister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1200 pDevIns->pReg->szName, pDevIns->iInstance, pszName, pszName, pszDesc, pszDesc, pfnHandler));
1201
1202 PVM pVM = pDevIns->Internal.s.pVMR3;
1203 VM_ASSERT_EMT(pVM);
1204 int rc = DBGFR3InfoRegisterDevice(pVM, pszName, pszDesc, pfnHandler, pDevIns);
1205
1206 LogFlow(("pdmR3DevHlp_DBGFInfoRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1207 return rc;
1208}
1209
1210
1211/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFInfoRegisterArgv} */
1212static DECLCALLBACK(int) pdmR3DevHlp_DBGFInfoRegisterArgv(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDEV pfnHandler)
1213{
1214 PDMDEV_ASSERT_DEVINS(pDevIns);
1215 LogFlow(("pdmR3DevHlp_DBGFInfoRegisterArgv: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1216 pDevIns->pReg->szName, pDevIns->iInstance, pszName, pszName, pszDesc, pszDesc, pfnHandler));
1217
1218 PVM pVM = pDevIns->Internal.s.pVMR3;
1219 VM_ASSERT_EMT(pVM);
1220 int rc = DBGFR3InfoRegisterDeviceArgv(pVM, pszName, pszDesc, pfnHandler, pDevIns);
1221
1222 LogFlow(("pdmR3DevHlp_DBGFInfoRegisterArgv: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1223 return rc;
1224}
1225
1226
1227/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFRegRegister} */
1228static DECLCALLBACK(int) pdmR3DevHlp_DBGFRegRegister(PPDMDEVINS pDevIns, PCDBGFREGDESC paRegisters)
1229{
1230 PDMDEV_ASSERT_DEVINS(pDevIns);
1231 LogFlow(("pdmR3DevHlp_DBGFRegRegister: caller='%s'/%d: paRegisters=%p\n",
1232 pDevIns->pReg->szName, pDevIns->iInstance, paRegisters));
1233
1234 PVM pVM = pDevIns->Internal.s.pVMR3;
1235 VM_ASSERT_EMT(pVM);
1236 int rc = DBGFR3RegRegisterDevice(pVM, paRegisters, pDevIns, pDevIns->pReg->szName, pDevIns->iInstance);
1237
1238 LogFlow(("pdmR3DevHlp_DBGFRegRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1239 return rc;
1240}
1241
1242
1243/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFTraceBuf} */
1244static DECLCALLBACK(RTTRACEBUF) pdmR3DevHlp_DBGFTraceBuf(PPDMDEVINS pDevIns)
1245{
1246 PDMDEV_ASSERT_DEVINS(pDevIns);
1247 RTTRACEBUF hTraceBuf = pDevIns->Internal.s.pVMR3->hTraceBufR3;
1248 LogFlow(("pdmR3DevHlp_DBGFTraceBuf: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, hTraceBuf));
1249 return hTraceBuf;
1250}
1251
1252
1253/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegister} */
1254static DECLCALLBACK(void) pdmR3DevHlp_STAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName,
1255 STAMUNIT enmUnit, const char *pszDesc)
1256{
1257 PDMDEV_ASSERT_DEVINS(pDevIns);
1258 PVM pVM = pDevIns->Internal.s.pVMR3;
1259 VM_ASSERT_EMT(pVM);
1260
1261 int rc;
1262 if (*pszName == '/')
1263 rc = STAMR3Register(pVM, pvSample, enmType, STAMVISIBILITY_ALWAYS, pszName, enmUnit, pszDesc);
1264 /* Provide default device statistics prefix: */
1265 else if (pDevIns->pReg->cMaxInstances == 1)
1266 rc = STAMR3RegisterF(pVM, pvSample, enmType, STAMVISIBILITY_ALWAYS, enmUnit, pszDesc,
1267 "/Devices/%s/%s", pDevIns->pReg->szName, pszName);
1268 else
1269 rc = STAMR3RegisterF(pVM, pvSample, enmType, STAMVISIBILITY_ALWAYS, enmUnit, pszDesc,
1270 "/Devices/%s#%u/%s", pDevIns->pReg->szName, pDevIns->iInstance, pszName);
1271 AssertRC(rc);
1272}
1273
1274
1275/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegisterV} */
1276static DECLCALLBACK(void) pdmR3DevHlp_STAMRegisterV(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1277 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
1278{
1279 PDMDEV_ASSERT_DEVINS(pDevIns);
1280 PVM pVM = pDevIns->Internal.s.pVMR3;
1281 VM_ASSERT_EMT(pVM);
1282
1283 int rc;
1284 if (*pszName == '/')
1285 rc = STAMR3RegisterV(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1286 else
1287 {
1288 /* Provide default device statistics prefix: */
1289 va_list vaCopy;
1290 va_copy(vaCopy, args);
1291 if (pDevIns->pReg->cMaxInstances == 1)
1292 rc = STAMR3RegisterF(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc,
1293 "/Devices/%s/%N", pDevIns->pReg->szName, pszName, &vaCopy);
1294 else
1295 rc = STAMR3RegisterF(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc,
1296 "/Devices/%s#%u/%N", pDevIns->pReg->szName, pDevIns->iInstance, pszName, &vaCopy);
1297 va_end(vaCopy);
1298 }
1299 AssertRC(rc);
1300}
1301
1302
1303/**
1304 * @interface_method_impl{PDMDEVHLPR3,pfnSTAMDeregisterByPrefix}
1305 */
1306static DECLCALLBACK(int) pdmR3DevHlp_STAMDeregisterByPrefix(PPDMDEVINS pDevIns, const char *pszPrefix)
1307{
1308 PDMDEV_ASSERT_DEVINS(pDevIns);
1309 PVM pVM = pDevIns->Internal.s.pVMR3;
1310 VM_ASSERT_EMT(pVM);
1311
1312 int rc;
1313 if (*pszPrefix == '/')
1314 rc = STAMR3DeregisterByPrefix(pVM->pUVM, pszPrefix);
1315 else
1316 {
1317 char szQualifiedPrefix[1024];
1318 ssize_t cch;
1319 if (pDevIns->pReg->cMaxInstances == 1)
1320 cch = RTStrPrintf2(szQualifiedPrefix, sizeof(szQualifiedPrefix), "/Devices/%s/%s", pDevIns->pReg->szName, pszPrefix);
1321 else
1322 cch = RTStrPrintf2(szQualifiedPrefix, sizeof(szQualifiedPrefix), "/Devices/%s#%u/%s",
1323 pDevIns->pReg->szName, pDevIns->iInstance, pszPrefix);
1324 AssertReturn(cch > 0, VERR_OUT_OF_RANGE);
1325 rc = STAMR3DeregisterByPrefix(pVM->pUVM, szQualifiedPrefix);
1326 }
1327 AssertRC(rc);
1328 return rc;
1329}
1330
1331
1332/**
1333 * @interface_method_impl{PDMDEVHLPR3,pfnPCIRegister}
1334 */
1335static DECLCALLBACK(int) pdmR3DevHlp_PCIRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
1336 uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName)
1337{
1338 PDMDEV_ASSERT_DEVINS(pDevIns);
1339 PVM pVM = pDevIns->Internal.s.pVMR3;
1340 VM_ASSERT_EMT(pVM);
1341 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: pPciDev=%p:{.config={%#.256Rhxs} fFlags=%#x uPciDevNo=%#x uPciFunNo=%#x pszName=%p:{%s}\n",
1342 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev->abConfig, fFlags, uPciDevNo, uPciFunNo, pszName, pszName ? pszName : ""));
1343
1344 /*
1345 * Validate input.
1346 */
1347 AssertLogRelMsgReturn(pDevIns->pReg->cMaxPciDevices > 0,
1348 ("'%s'/%d: cMaxPciDevices is 0\n", pDevIns->pReg->szName, pDevIns->iInstance),
1349 VERR_WRONG_ORDER);
1350 AssertLogRelMsgReturn(RT_VALID_PTR(pPciDev),
1351 ("'%s'/%d: Invalid pPciDev value: %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pPciDev),
1352 VERR_INVALID_POINTER);
1353 AssertLogRelMsgReturn(PDMPciDevGetVendorId(pPciDev),
1354 ("'%s'/%d: Vendor ID is not set!\n", pDevIns->pReg->szName, pDevIns->iInstance),
1355 VERR_INVALID_POINTER);
1356 AssertLogRelMsgReturn( uPciDevNo < 32
1357 || uPciDevNo == PDMPCIDEVREG_DEV_NO_FIRST_UNUSED
1358 || uPciDevNo == PDMPCIDEVREG_DEV_NO_SAME_AS_PREV,
1359 ("'%s'/%d: Invalid PCI device number: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, uPciDevNo),
1360 VERR_INVALID_PARAMETER);
1361 AssertLogRelMsgReturn( uPciFunNo < 8
1362 || uPciFunNo == PDMPCIDEVREG_FUN_NO_FIRST_UNUSED,
1363 ("'%s'/%d: Invalid PCI funcion number: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, uPciFunNo),
1364 VERR_INVALID_PARAMETER);
1365 AssertLogRelMsgReturn(!(fFlags & ~PDMPCIDEVREG_F_VALID_MASK),
1366 ("'%s'/%d: Invalid flags: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, fFlags),
1367 VERR_INVALID_FLAGS);
1368 if (!pszName)
1369 pszName = pDevIns->pReg->szName;
1370 AssertLogRelReturn(RT_VALID_PTR(pszName), VERR_INVALID_POINTER);
1371 AssertLogRelReturn(!pPciDev->Int.s.fRegistered, VERR_PDM_NOT_PCI_DEVICE);
1372 AssertLogRelReturn(pPciDev == PDMDEV_GET_PPCIDEV(pDevIns, pPciDev->Int.s.idxSubDev), VERR_PDM_NOT_PCI_DEVICE);
1373 AssertLogRelReturn(pPciDev == PDMDEV_CALC_PPCIDEV(pDevIns, pPciDev->Int.s.idxSubDev), VERR_PDM_NOT_PCI_DEVICE);
1374 AssertMsgReturn(pPciDev->u32Magic == PDMPCIDEV_MAGIC, ("%#x\n", pPciDev->u32Magic), VERR_PDM_NOT_PCI_DEVICE);
1375
1376 /*
1377 * Check the registration order - must be following PDMDEVINSR3::apPciDevs.
1378 */
1379 PPDMPCIDEV const pPrevPciDev = pPciDev->Int.s.idxSubDev == 0 ? NULL
1380 : PDMDEV_GET_PPCIDEV(pDevIns, pPciDev->Int.s.idxSubDev - 1);
1381 if (pPrevPciDev)
1382 {
1383 AssertLogRelReturn(pPrevPciDev->u32Magic == PDMPCIDEV_MAGIC, VERR_INVALID_MAGIC);
1384 AssertLogRelReturn(pPrevPciDev->Int.s.fRegistered, VERR_WRONG_ORDER);
1385 }
1386
1387 /*
1388 * Resolve the PCI configuration node for the device. The default (zero'th)
1389 * is the same as the PDM device, the rest are "PciCfg1..255" CFGM sub-nodes.
1390 */
1391 PCFGMNODE pCfg = pDevIns->Internal.s.pCfgHandle;
1392 if (pPciDev->Int.s.idxSubDev > 0)
1393 pCfg = CFGMR3GetChildF(pDevIns->Internal.s.pCfgHandle, "PciCfg%u", pPciDev->Int.s.idxSubDev);
1394
1395 /*
1396 * We resolve PDMPCIDEVREG_DEV_NO_SAME_AS_PREV, the PCI bus handles
1397 * PDMPCIDEVREG_DEV_NO_FIRST_UNUSED and PDMPCIDEVREG_FUN_NO_FIRST_UNUSED.
1398 */
1399 uint8_t const uPciDevNoRaw = uPciDevNo;
1400 uint32_t uDefPciBusNo = 0;
1401 if (uPciDevNo == PDMPCIDEVREG_DEV_NO_SAME_AS_PREV)
1402 {
1403 if (pPrevPciDev)
1404 {
1405 uPciDevNo = pPrevPciDev->uDevFn >> 3;
1406 uDefPciBusNo = pPrevPciDev->Int.s.idxPdmBus;
1407 }
1408 else
1409 {
1410 /* Look for PCI device registered with an earlier device instance so we can more
1411 easily have multiple functions spanning multiple PDM device instances. */
1412 PPDMDEVINS pPrevIns = pDevIns->Internal.s.pDevR3->pInstances;
1413 for (;;)
1414 {
1415 AssertLogRelMsgReturn(pPrevIns && pPrevIns != pDevIns,
1416 ("'%s'/%d: Can't use PDMPCIDEVREG_DEV_NO_SAME_AS_PREV without a previously registered PCI device by the same or earlier PDM device instance!\n",
1417 pDevIns->pReg->szName, pDevIns->iInstance), VERR_WRONG_ORDER);
1418 if (pPrevIns->Internal.s.pNextR3 == pDevIns)
1419 break;
1420 pPrevIns = pPrevIns->Internal.s.pNextR3;
1421 }
1422
1423 PPDMPCIDEV pOtherPciDev = PDMDEV_GET_PPCIDEV(pPrevIns, 0);
1424 AssertLogRelMsgReturn(pOtherPciDev && pOtherPciDev->Int.s.fRegistered,
1425 ("'%s'/%d: Can't use PDMPCIDEVREG_DEV_NO_SAME_AS_PREV without a previously registered PCI device by the same or earlier PDM device instance!\n",
1426 pDevIns->pReg->szName, pDevIns->iInstance),
1427 VERR_WRONG_ORDER);
1428 for (uint32_t iPrevPciDev = 1; iPrevPciDev < pDevIns->cPciDevs; iPrevPciDev++)
1429 {
1430 PPDMPCIDEV pCur = PDMDEV_GET_PPCIDEV(pPrevIns, iPrevPciDev);
1431 AssertBreak(pCur);
1432 if (!pCur->Int.s.fRegistered)
1433 break;
1434 pOtherPciDev = pCur;
1435 }
1436
1437 uPciDevNo = pOtherPciDev->uDevFn >> 3;
1438 uDefPciBusNo = pOtherPciDev->Int.s.idxPdmBus;
1439 }
1440 }
1441
1442 /*
1443 * Choose the PCI bus for the device.
1444 *
1445 * This is simple. If the device was configured for a particular bus, the PCIBusNo
1446 * configuration value will be set. If not the default bus is 0.
1447 */
1448 /** @cfgm{/Devices/NAME/XX/[PciCfgYY/]PCIBusNo, uint8_t, 0, 7, 0}
1449 * Selects the PCI bus number of a device. The default value isn't necessarily
1450 * zero if the device is registered using PDMPCIDEVREG_DEV_NO_SAME_AS_PREV, it
1451 * will then also inherit the bus number from the previously registered device.
1452 */
1453 uint8_t u8Bus;
1454 int rc = CFGMR3QueryU8Def(pCfg, "PCIBusNo", &u8Bus, (uint8_t)uDefPciBusNo);
1455 AssertLogRelMsgRCReturn(rc, ("Configuration error: PCIBusNo query failed with rc=%Rrc (%s/%d)\n",
1456 rc, pDevIns->pReg->szName, pDevIns->iInstance), rc);
1457 AssertLogRelMsgReturn(u8Bus < RT_ELEMENTS(pVM->pdm.s.aPciBuses),
1458 ("Configuration error: PCIBusNo=%d, max is %d. (%s/%d)\n", u8Bus,
1459 RT_ELEMENTS(pVM->pdm.s.aPciBuses), pDevIns->pReg->szName, pDevIns->iInstance),
1460 VERR_PDM_NO_PCI_BUS);
1461 pPciDev->Int.s.idxPdmBus = u8Bus;
1462 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[u8Bus];
1463 if (pBus->pDevInsR3)
1464 {
1465 /*
1466 * Check the configuration for PCI device and function assignment.
1467 */
1468 /** @cfgm{/Devices/NAME/XX/[PciCfgYY/]PCIDeviceNo, uint8_t, 0, 31}
1469 * Overrides the default PCI device number of a device.
1470 */
1471 uint8_t uCfgDevice;
1472 rc = CFGMR3QueryU8(pCfg, "PCIDeviceNo", &uCfgDevice);
1473 if (RT_SUCCESS(rc))
1474 {
1475 AssertMsgReturn(uCfgDevice <= 31,
1476 ("Configuration error: PCIDeviceNo=%d, max is 31. (%s/%d/%d)\n",
1477 uCfgDevice, pDevIns->pReg->szName, pDevIns->iInstance, pPciDev->Int.s.idxSubDev),
1478 VERR_PDM_BAD_PCI_CONFIG);
1479 uPciDevNo = uCfgDevice;
1480 }
1481 else
1482 AssertMsgReturn(rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT,
1483 ("Configuration error: PCIDeviceNo query failed with rc=%Rrc (%s/%d/%d)\n",
1484 rc, pDevIns->pReg->szName, pDevIns->iInstance, pPciDev->Int.s.idxSubDev),
1485 rc);
1486
1487 /** @cfgm{/Devices/NAME/XX/[PciCfgYY/]PCIFunctionNo, uint8_t, 0, 7}
1488 * Overrides the default PCI function number of a device.
1489 */
1490 uint8_t uCfgFunction;
1491 rc = CFGMR3QueryU8(pCfg, "PCIFunctionNo", &uCfgFunction);
1492 if (RT_SUCCESS(rc))
1493 {
1494 AssertMsgReturn(uCfgFunction <= 7,
1495 ("Configuration error: PCIFunctionNo=%#x, max is 7. (%s/%d/%d)\n",
1496 uCfgFunction, pDevIns->pReg->szName, pDevIns->iInstance, pPciDev->Int.s.idxSubDev),
1497 VERR_PDM_BAD_PCI_CONFIG);
1498 uPciFunNo = uCfgFunction;
1499 }
1500 else
1501 AssertMsgReturn(rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT,
1502 ("Configuration error: PCIFunctionNo query failed with rc=%Rrc (%s/%d/%d)\n",
1503 rc, pDevIns->pReg->szName, pDevIns->iInstance, pPciDev->Int.s.idxSubDev),
1504 rc);
1505
1506#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
1507 PPDMIOMMUR3 pIommu = &pVM->pdm.s.aIommus[0];
1508 PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
1509 if (pDevInsIommu)
1510 {
1511 /*
1512 * If the PCI device/function number has been explicitly specified via CFGM,
1513 * ensure it's not the BDF reserved for the southbridge I/O APIC expected
1514 * by linux guests when using an AMD IOMMU, see @bugref{9654#c23}.
1515 *
1516 * In the Intel IOMMU case, we re-use the same I/O APIC address to reserve a
1517 * PCI slot so the same check below is sufficient, see @bugref{9967#c13}.
1518 */
1519 uint16_t const uDevFn = VBOX_PCI_DEVFN_MAKE(uPciDevNo, uPciFunNo);
1520 uint16_t const uBusDevFn = PCIBDF_MAKE(u8Bus, uDevFn);
1521 if (uBusDevFn == VBOX_PCI_BDF_SB_IOAPIC)
1522 {
1523 LogRel(("Configuration error: PCI BDF (%u:%u:%u) conflicts with SB I/O APIC (%s/%d/%d)\n", u8Bus,
1524 uCfgDevice, uCfgFunction, pDevIns->pReg->szName, pDevIns->iInstance, pPciDev->Int.s.idxSubDev));
1525 return VERR_NOT_AVAILABLE;
1526 }
1527 }
1528#endif
1529
1530 /*
1531 * Initialize the internal data. We only do the wipe and the members
1532 * owned by PDM, the PCI bus does the rest in the registration call.
1533 */
1534 RT_ZERO(pPciDev->Int);
1535
1536 pPciDev->Int.s.idxDevCfg = pPciDev->Int.s.idxSubDev;
1537 pPciDev->Int.s.fReassignableDevNo = uPciDevNoRaw >= VBOX_PCI_MAX_DEVICES;
1538 pPciDev->Int.s.fReassignableFunNo = uPciFunNo >= VBOX_PCI_MAX_FUNCTIONS;
1539 pPciDev->Int.s.pDevInsR3 = pDevIns;
1540 pPciDev->Int.s.idxPdmBus = u8Bus;
1541 pPciDev->Int.s.fRegistered = true;
1542
1543 /* Set some of the public members too. */
1544 pPciDev->pszNameR3 = pszName;
1545
1546 /*
1547 * Call the pci bus device to do the actual registration.
1548 */
1549 pdmLock(pVM);
1550 rc = pBus->pfnRegister(pBus->pDevInsR3, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName);
1551 pdmUnlock(pVM);
1552 if (RT_SUCCESS(rc))
1553 Log(("PDM: Registered device '%s'/%d as PCI device %d on bus %d\n",
1554 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev->uDevFn, pBus->iBus));
1555 else
1556 pPciDev->Int.s.fRegistered = false;
1557 }
1558 else
1559 {
1560 AssertLogRelMsgFailed(("Configuration error: No PCI bus available. This could be related to init order too!\n"));
1561 rc = VERR_PDM_NO_PCI_BUS;
1562 }
1563
1564 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1565 return rc;
1566}
1567
1568
1569/** @interface_method_impl{PDMDEVHLPR3,pfnPCIRegisterMsi} */
1570static DECLCALLBACK(int) pdmR3DevHlp_PCIRegisterMsi(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, PPDMMSIREG pMsiReg)
1571{
1572 PDMDEV_ASSERT_DEVINS(pDevIns);
1573 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1574 pPciDev = pDevIns->apPciDevs[0];
1575 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1576 LogFlow(("pdmR3DevHlp_PCIRegisterMsi: caller='%s'/%d: pPciDev=%p:{%#x} pMsgReg=%p:{cMsiVectors=%d, cMsixVectors=%d}\n",
1577 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev->uDevFn, pMsiReg, pMsiReg->cMsiVectors, pMsiReg->cMsixVectors));
1578 PDMPCIDEV_ASSERT_VALID_RET(pDevIns, pPciDev);
1579
1580 AssertLogRelMsgReturn(pDevIns->pReg->cMaxPciDevices > 0,
1581 ("'%s'/%d: cMaxPciDevices is 0\n", pDevIns->pReg->szName, pDevIns->iInstance),
1582 VERR_WRONG_ORDER);
1583 AssertLogRelMsgReturn(pMsiReg->cMsixVectors <= pDevIns->pReg->cMaxMsixVectors,
1584 ("'%s'/%d: cMsixVectors=%u cMaxMsixVectors=%u\n",
1585 pDevIns->pReg->szName, pDevIns->iInstance, pMsiReg->cMsixVectors, pDevIns->pReg->cMaxMsixVectors),
1586 VERR_INVALID_FLAGS);
1587
1588 PVM pVM = pDevIns->Internal.s.pVMR3;
1589 size_t const idxBus = pPciDev->Int.s.idxPdmBus;
1590 AssertReturn(idxBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses), VERR_WRONG_ORDER);
1591 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[idxBus];
1592
1593 pdmLock(pVM);
1594 int rc;
1595 if (pBus->pfnRegisterMsi)
1596 rc = pBus->pfnRegisterMsi(pBus->pDevInsR3, pPciDev, pMsiReg);
1597 else
1598 rc = VERR_NOT_IMPLEMENTED;
1599 pdmUnlock(pVM);
1600
1601 LogFlow(("pdmR3DevHlp_PCIRegisterMsi: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1602 return rc;
1603}
1604
1605
1606/** @interface_method_impl{PDMDEVHLPR3,pfnPCIIORegionRegister} */
1607static DECLCALLBACK(int) pdmR3DevHlp_PCIIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
1608 RTGCPHYS cbRegion, PCIADDRESSSPACE enmType, uint32_t fFlags,
1609 uint64_t hHandle, PFNPCIIOREGIONMAP pfnMapUnmap)
1610{
1611 PDMDEV_ASSERT_DEVINS(pDevIns);
1612 PVM pVM = pDevIns->Internal.s.pVMR3;
1613 VM_ASSERT_EMT(pVM);
1614 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1615 pPciDev = pDevIns->apPciDevs[0];
1616 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1617 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: pPciDev=%p:{%#x} iRegion=%d cbRegion=%RGp enmType=%d fFlags=%#x, hHandle=%#RX64 pfnMapUnmap=%p\n",
1618 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev->uDevFn, iRegion, cbRegion, enmType, fFlags, hHandle, pfnMapUnmap));
1619 PDMPCIDEV_ASSERT_VALID_RET(pDevIns, pPciDev);
1620
1621 /*
1622 * Validate input.
1623 */
1624 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
1625 AssertLogRelMsgReturn(VMR3GetState(pVM) == VMSTATE_CREATING,
1626 ("caller='%s'/%d: %s\n", pDevIns->pReg->szName, pDevIns->iInstance, VMR3GetStateName(VMR3GetState(pVM))),
1627 VERR_WRONG_ORDER);
1628
1629 if (iRegion >= VBOX_PCI_NUM_REGIONS)
1630 {
1631 Assert(iRegion < VBOX_PCI_NUM_REGIONS);
1632 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc (iRegion)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1633 return VERR_INVALID_PARAMETER;
1634 }
1635
1636 switch ((int)enmType)
1637 {
1638 case PCI_ADDRESS_SPACE_IO:
1639 /*
1640 * Sanity check: don't allow to register more than 32K of the PCI I/O space.
1641 */
1642 AssertLogRelMsgReturn(cbRegion <= _32K,
1643 ("caller='%s'/%d: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cbRegion),
1644 VERR_INVALID_PARAMETER);
1645 break;
1646
1647 case PCI_ADDRESS_SPACE_MEM:
1648 case PCI_ADDRESS_SPACE_MEM_PREFETCH:
1649 /*
1650 * Sanity check: Don't allow to register more than 2GB of the PCI MMIO space.
1651 */
1652 AssertLogRelMsgReturn(cbRegion <= MM_MMIO_32_MAX,
1653 ("caller='%s'/%d: %RGp (max %RGp)\n",
1654 pDevIns->pReg->szName, pDevIns->iInstance, cbRegion, (RTGCPHYS)MM_MMIO_32_MAX),
1655 VERR_OUT_OF_RANGE);
1656 break;
1657
1658 case PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_MEM:
1659 case PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_MEM_PREFETCH:
1660 /*
1661 * Sanity check: Don't allow to register more than 64GB of the 64-bit PCI MMIO space.
1662 */
1663 AssertLogRelMsgReturn(cbRegion <= MM_MMIO_64_MAX,
1664 ("caller='%s'/%d: %RGp (max %RGp)\n",
1665 pDevIns->pReg->szName, pDevIns->iInstance, cbRegion, MM_MMIO_64_MAX),
1666 VERR_OUT_OF_RANGE);
1667 break;
1668
1669 default:
1670 AssertMsgFailed(("enmType=%#x is unknown\n", enmType));
1671 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc (enmType)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1672 return VERR_INVALID_PARAMETER;
1673 }
1674
1675 AssertMsgReturn( pfnMapUnmap
1676 || ( hHandle != UINT64_MAX
1677 && (fFlags & PDMPCIDEV_IORGN_F_HANDLE_MASK) != PDMPCIDEV_IORGN_F_NO_HANDLE),
1678 ("caller='%s'/%d: fFlags=%#x hHandle=%#RX64\n", pDevIns->pReg->szName, pDevIns->iInstance, fFlags, hHandle),
1679 VERR_INVALID_PARAMETER);
1680
1681 AssertMsgReturn(!(fFlags & ~PDMPCIDEV_IORGN_F_VALID_MASK), ("fFlags=%#x\n", fFlags), VERR_INVALID_FLAGS);
1682 int rc;
1683 switch (fFlags & PDMPCIDEV_IORGN_F_HANDLE_MASK)
1684 {
1685 case PDMPCIDEV_IORGN_F_NO_HANDLE:
1686 break;
1687 case PDMPCIDEV_IORGN_F_IOPORT_HANDLE:
1688 AssertReturn(enmType == PCI_ADDRESS_SPACE_IO, VERR_INVALID_FLAGS);
1689 rc = IOMR3IoPortValidateHandle(pVM, pDevIns, (IOMIOPORTHANDLE)hHandle);
1690 AssertRCReturn(rc, rc);
1691 break;
1692 case PDMPCIDEV_IORGN_F_MMIO_HANDLE:
1693 AssertReturn( (enmType & ~PCI_ADDRESS_SPACE_BAR64) == PCI_ADDRESS_SPACE_MEM
1694 || (enmType & ~PCI_ADDRESS_SPACE_BAR64) == PCI_ADDRESS_SPACE_MEM_PREFETCH,
1695 VERR_INVALID_FLAGS);
1696 rc = IOMR3MmioValidateHandle(pVM, pDevIns, (IOMMMIOHANDLE)hHandle);
1697 AssertRCReturn(rc, rc);
1698 break;
1699 case PDMPCIDEV_IORGN_F_MMIO2_HANDLE:
1700 AssertReturn( (enmType & ~PCI_ADDRESS_SPACE_BAR64) == PCI_ADDRESS_SPACE_MEM
1701 || (enmType & ~PCI_ADDRESS_SPACE_BAR64) == PCI_ADDRESS_SPACE_MEM_PREFETCH,
1702 VERR_INVALID_FLAGS);
1703 rc = PGMR3PhysMmio2ValidateHandle(pVM, pDevIns, (PGMMMIO2HANDLE)hHandle);
1704 AssertRCReturn(rc, rc);
1705 break;
1706 default:
1707 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
1708 break;
1709 }
1710
1711 /* This flag is required now. */
1712 AssertLogRelMsgReturn(fFlags & PDMPCIDEV_IORGN_F_NEW_STYLE,
1713 ("'%s'/%d: Invalid flags: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, fFlags),
1714 VERR_INVALID_FLAGS);
1715
1716 /*
1717 * We're currently restricted to page aligned MMIO regions.
1718 */
1719 if ( ((enmType & ~(PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_MEM_PREFETCH)) == PCI_ADDRESS_SPACE_MEM)
1720 && cbRegion != RT_ALIGN_64(cbRegion, PAGE_SIZE))
1721 {
1722 Log(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: aligning cbRegion %RGp -> %RGp\n",
1723 pDevIns->pReg->szName, pDevIns->iInstance, cbRegion, RT_ALIGN_64(cbRegion, PAGE_SIZE)));
1724 cbRegion = RT_ALIGN_64(cbRegion, PAGE_SIZE);
1725 }
1726
1727 /*
1728 * For registering PCI MMIO memory or PCI I/O memory, the size of the region must be a power of 2!
1729 */
1730 int iLastSet = ASMBitLastSetU64(cbRegion);
1731 Assert(iLastSet > 0);
1732 uint64_t cbRegionAligned = RT_BIT_64(iLastSet - 1);
1733 if (cbRegion > cbRegionAligned)
1734 cbRegion = cbRegionAligned * 2; /* round up */
1735
1736 size_t const idxBus = pPciDev->Int.s.idxPdmBus;
1737 AssertReturn(idxBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses), VERR_WRONG_ORDER);
1738 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[idxBus];
1739
1740 pdmLock(pVM);
1741 rc = pBus->pfnIORegionRegister(pBus->pDevInsR3, pPciDev, iRegion, cbRegion, enmType, fFlags, hHandle, pfnMapUnmap);
1742 pdmUnlock(pVM);
1743
1744 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1745 return rc;
1746}
1747
1748
1749/** @interface_method_impl{PDMDEVHLPR3,pfnPCIInterceptConfigAccesses} */
1750static DECLCALLBACK(int) pdmR3DevHlp_PCIInterceptConfigAccesses(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
1751 PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite)
1752{
1753 PDMDEV_ASSERT_DEVINS(pDevIns);
1754 PVM pVM = pDevIns->Internal.s.pVMR3;
1755 VM_ASSERT_EMT(pVM);
1756 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1757 pPciDev = pDevIns->apPciDevs[0];
1758 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1759 LogFlow(("pdmR3DevHlp_PCIInterceptConfigAccesses: caller='%s'/%d: pPciDev=%p pfnRead=%p pfnWrite=%p\n",
1760 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pfnRead, pfnWrite));
1761 PDMPCIDEV_ASSERT_VALID_RET(pDevIns, pPciDev);
1762
1763 /*
1764 * Validate input.
1765 */
1766 AssertPtr(pfnRead);
1767 AssertPtr(pfnWrite);
1768 AssertPtr(pPciDev);
1769
1770 size_t const idxBus = pPciDev->Int.s.idxPdmBus;
1771 AssertReturn(idxBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses), VERR_INTERNAL_ERROR_2);
1772 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[idxBus];
1773 AssertRelease(VMR3GetState(pVM) != VMSTATE_RUNNING);
1774
1775 /*
1776 * Do the job.
1777 */
1778 pdmLock(pVM);
1779 pBus->pfnInterceptConfigAccesses(pBus->pDevInsR3, pPciDev, pfnRead, pfnWrite);
1780 pdmUnlock(pVM);
1781
1782 LogFlow(("pdmR3DevHlp_PCIInterceptConfigAccesses: caller='%s'/%d: returns VINF_SUCCESS\n",
1783 pDevIns->pReg->szName, pDevIns->iInstance));
1784 return VINF_SUCCESS;
1785}
1786
1787
1788/** @interface_method_impl{PDMDEVHLPR3,pfnPCIConfigWrite} */
1789static DECLCALLBACK(VBOXSTRICTRC)
1790pdmR3DevHlp_PCIConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb, uint32_t u32Value)
1791{
1792 PDMDEV_ASSERT_DEVINS(pDevIns);
1793 PVM pVM = pDevIns->Internal.s.pVMR3;
1794 AssertPtrReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1795 LogFlow(("pdmR3DevHlp_PCIConfigWrite: caller='%s'/%d: pPciDev=%p uAddress=%#x cd=%d u32Value=%#x\n",
1796 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, uAddress, cb, u32Value));
1797
1798 /*
1799 * Resolve the bus.
1800 */
1801 size_t const idxBus = pPciDev->Int.s.idxPdmBus;
1802 AssertReturn(idxBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses), VERR_INTERNAL_ERROR_2);
1803 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[idxBus];
1804
1805 /*
1806 * Do the job.
1807 */
1808 VBOXSTRICTRC rcStrict = pBus->pfnConfigWrite(pBus->pDevInsR3, pPciDev, uAddress, cb, u32Value);
1809
1810 LogFlow(("pdmR3DevHlp_PCIConfigWrite: caller='%s'/%d: returns %Rrc\n",
1811 pDevIns->pReg->szName, pDevIns->iInstance, VBOXSTRICTRC_VAL(rcStrict)));
1812 return rcStrict;
1813}
1814
1815
1816/** @interface_method_impl{PDMDEVHLPR3,pfnPCIConfigRead} */
1817static DECLCALLBACK(VBOXSTRICTRC)
1818pdmR3DevHlp_PCIConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb, uint32_t *pu32Value)
1819{
1820 PDMDEV_ASSERT_DEVINS(pDevIns);
1821 PVM pVM = pDevIns->Internal.s.pVMR3;
1822 AssertPtrReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1823 LogFlow(("pdmR3DevHlp_PCIConfigRead: caller='%s'/%d: pPciDev=%p uAddress=%#x cd=%d pu32Value=%p:{%#x}\n",
1824 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, uAddress, cb, pu32Value, *pu32Value));
1825
1826 /*
1827 * Resolve the bus.
1828 */
1829 size_t const idxBus = pPciDev->Int.s.idxPdmBus;
1830 AssertReturn(idxBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses), VERR_INTERNAL_ERROR_2);
1831 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[idxBus];
1832
1833 /*
1834 * Do the job.
1835 */
1836 VBOXSTRICTRC rcStrict = pBus->pfnConfigRead(pBus->pDevInsR3, pPciDev, uAddress, cb, pu32Value);
1837
1838 LogFlow(("pdmR3DevHlp_PCIConfigRead: caller='%s'/%d: returns %Rrc (*pu32Value=%#x)\n",
1839 pDevIns->pReg->szName, pDevIns->iInstance, VBOXSTRICTRC_VAL(rcStrict), *pu32Value));
1840 return rcStrict;
1841}
1842
1843
1844/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysRead} */
1845static DECLCALLBACK(int)
1846pdmR3DevHlp_PCIPhysRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags)
1847{
1848 PDMDEV_ASSERT_DEVINS(pDevIns);
1849 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1850 pPciDev = pDevIns->apPciDevs[0];
1851 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1852 PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
1853
1854#ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
1855 /*
1856 * Just check the busmaster setting here and forward the request to the generic read helper.
1857 */
1858 if (PCIDevIsBusmaster(pPciDev))
1859 { /* likely */ }
1860 else
1861 {
1862 Log(("pdmR3DevHlp_PCIPhysRead: caller='%s'/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbRead=%#zx\n",
1863 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbRead));
1864 memset(pvBuf, 0xff, cbRead);
1865 return VERR_PDM_NOT_PCI_BUS_MASTER;
1866 }
1867#endif
1868
1869#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
1870 int rc = pdmIommuMemAccessRead(pDevIns, pPciDev, GCPhys, pvBuf, cbRead, fFlags);
1871 if ( rc == VERR_IOMMU_NOT_PRESENT
1872 || rc == VERR_IOMMU_CANNOT_CALL_SELF)
1873 { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
1874 else
1875 return rc;
1876#endif
1877
1878 return pDevIns->pHlpR3->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead, fFlags);
1879}
1880
1881
1882/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysWrite} */
1883static DECLCALLBACK(int)
1884pdmR3DevHlp_PCIPhysWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags)
1885{
1886 PDMDEV_ASSERT_DEVINS(pDevIns);
1887 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1888 pPciDev = pDevIns->apPciDevs[0];
1889 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1890 PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
1891
1892#ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
1893 /*
1894 * Just check the busmaster setting here and forward the request to the generic read helper.
1895 */
1896 if (PCIDevIsBusmaster(pPciDev))
1897 { /* likely */ }
1898 else
1899 {
1900 Log(("pdmR3DevHlp_PCIPhysWrite: caller='%s'/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbWrite=%#zx\n",
1901 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbWrite));
1902 return VERR_PDM_NOT_PCI_BUS_MASTER;
1903 }
1904#endif
1905
1906#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
1907 int rc = pdmIommuMemAccessWrite(pDevIns, pPciDev, GCPhys, pvBuf, cbWrite, fFlags);
1908 if ( rc == VERR_IOMMU_NOT_PRESENT
1909 || rc == VERR_IOMMU_CANNOT_CALL_SELF)
1910 { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
1911 else
1912 return rc;
1913#endif
1914
1915 return pDevIns->pHlpR3->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite, fFlags);
1916}
1917
1918
1919/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysGCPhys2CCPtr} */
1920static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysGCPhys2CCPtr(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys,
1921 uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
1922{
1923 PDMDEV_ASSERT_DEVINS(pDevIns);
1924 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1925 pPciDev = pDevIns->apPciDevs[0];
1926 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1927 PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
1928
1929#ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
1930 if (PCIDevIsBusmaster(pPciDev))
1931 { /* likely */ }
1932 else
1933 {
1934 LogFunc(("caller='%s'/%d: returns %Rrc - Not bus master! GCPhys=%RGp fFlags=%#RX32\n",
1935 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, fFlags));
1936 return VERR_PDM_NOT_PCI_BUS_MASTER;
1937 }
1938#endif
1939
1940#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
1941 int rc = pdmR3IommuMemAccessWriteCCPtr(pDevIns, pPciDev, GCPhys, fFlags, ppv, pLock);
1942 if ( rc == VERR_IOMMU_NOT_PRESENT
1943 || rc == VERR_IOMMU_CANNOT_CALL_SELF)
1944 { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
1945 else
1946 return rc;
1947#endif
1948
1949 return pDevIns->pHlpR3->pfnPhysGCPhys2CCPtr(pDevIns, GCPhys, fFlags, ppv, pLock);
1950}
1951
1952
1953/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysGCPhys2CCPtrReadOnly} */
1954static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys,
1955 uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock)
1956{
1957 PDMDEV_ASSERT_DEVINS(pDevIns);
1958 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1959 pPciDev = pDevIns->apPciDevs[0];
1960 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1961 PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
1962
1963#ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
1964 if (PCIDevIsBusmaster(pPciDev))
1965 { /* likely */ }
1966 else
1967 {
1968 LogFunc(("caller='%s'/%d: returns %Rrc - Not bus master! GCPhys=%RGp fFlags=%#RX32\n",
1969 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, fFlags));
1970 return VERR_PDM_NOT_PCI_BUS_MASTER;
1971 }
1972#endif
1973
1974#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
1975 int rc = pdmR3IommuMemAccessReadCCPtr(pDevIns, pPciDev, GCPhys, fFlags, ppv, pLock);
1976 if ( rc == VERR_IOMMU_NOT_PRESENT
1977 || rc == VERR_IOMMU_CANNOT_CALL_SELF)
1978 { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
1979 else
1980 return rc;
1981#endif
1982
1983 return pDevIns->pHlpR3->pfnPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhys, fFlags, ppv, pLock);
1984}
1985
1986
1987/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysBulkGCPhys2CCPtr} */
1988static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtr(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t cPages,
1989 PCRTGCPHYS paGCPhysPages, uint32_t fFlags, void **papvPages,
1990 PPGMPAGEMAPLOCK paLocks)
1991{
1992 PDMDEV_ASSERT_DEVINS(pDevIns);
1993 if (!pPciDev) /* NULL is an alias for the default PCI device. */
1994 pPciDev = pDevIns->apPciDevs[0];
1995 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
1996 PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
1997
1998#ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
1999 if (PCIDevIsBusmaster(pPciDev))
2000 { /* likely */ }
2001 else
2002 {
2003 LogFunc(("caller='%s'/%d: returns %Rrc - Not bus master! cPages=%zu fFlags=%#RX32\n",
2004 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, cPages, fFlags));
2005 return VERR_PDM_NOT_PCI_BUS_MASTER;
2006 }
2007#endif
2008
2009#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
2010 int rc = pdmR3IommuMemAccessBulkWriteCCPtr(pDevIns, pPciDev, cPages, paGCPhysPages, fFlags, papvPages, paLocks);
2011 if ( rc == VERR_IOMMU_NOT_PRESENT
2012 || rc == VERR_IOMMU_CANNOT_CALL_SELF)
2013 { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
2014 else
2015 return rc;
2016#endif
2017
2018 return pDevIns->pHlpR3->pfnPhysBulkGCPhys2CCPtr(pDevIns, cPages, paGCPhysPages, fFlags, papvPages, paLocks);
2019}
2020
2021
2022/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysBulkGCPhys2CCPtrReadOnly} */
2023static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t cPages,
2024 PCRTGCPHYS paGCPhysPages, uint32_t fFlags,
2025 const void **papvPages, PPGMPAGEMAPLOCK paLocks)
2026{
2027 PDMDEV_ASSERT_DEVINS(pDevIns);
2028 if (!pPciDev) /* NULL is an alias for the default PCI device. */
2029 pPciDev = pDevIns->apPciDevs[0];
2030 AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
2031 PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
2032
2033#ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
2034 if (PCIDevIsBusmaster(pPciDev))
2035 { /* likely */ }
2036 else
2037 {
2038 LogFunc(("caller='%s'/%d: returns %Rrc - Not bus master! cPages=%zu fFlags=%#RX32\n",
2039 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, cPages, fFlags));
2040 return VERR_PDM_NOT_PCI_BUS_MASTER;
2041 }
2042#endif
2043
2044#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
2045 int rc = pdmR3IommuMemAccessBulkReadCCPtr(pDevIns, pPciDev, cPages, paGCPhysPages, fFlags, papvPages, paLocks);
2046 if ( rc == VERR_IOMMU_NOT_PRESENT
2047 || rc == VERR_IOMMU_CANNOT_CALL_SELF)
2048 { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
2049 else
2050 return rc;
2051#endif
2052
2053 return pDevIns->pHlpR3->pfnPhysBulkGCPhys2CCPtrReadOnly(pDevIns, cPages, paGCPhysPages, fFlags, papvPages, paLocks);
2054}
2055
2056
2057/** @interface_method_impl{PDMDEVHLPR3,pfnPCISetIrq} */
2058static DECLCALLBACK(void) pdmR3DevHlp_PCISetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel)
2059{
2060 PDMDEV_ASSERT_DEVINS(pDevIns);
2061 if (!pPciDev) /* NULL is an alias for the default PCI device. */
2062 pPciDev = pDevIns->apPciDevs[0];
2063 AssertReturnVoid(pPciDev);
2064 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: pPciDev=%p:{%#x} iIrq=%d iLevel=%d\n",
2065 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev->uDevFn, iIrq, iLevel));
2066 PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
2067
2068 /*
2069 * Validate input.
2070 */
2071 Assert(iIrq == 0);
2072 Assert((uint32_t)iLevel <= PDM_IRQ_LEVEL_FLIP_FLOP);
2073
2074 /*
2075 * Must have a PCI device registered!
2076 */
2077 PVM pVM = pDevIns->Internal.s.pVMR3;
2078 size_t const idxBus = pPciDev->Int.s.idxPdmBus;
2079 AssertReturnVoid(idxBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses));
2080 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[idxBus];
2081
2082 pdmLock(pVM);
2083 uint32_t uTagSrc;
2084 if (iLevel & PDM_IRQ_LEVEL_HIGH)
2085 {
2086 pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
2087 if (iLevel == PDM_IRQ_LEVEL_HIGH)
2088 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
2089 else
2090 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
2091 }
2092 else
2093 uTagSrc = pDevIns->Internal.s.uLastIrqTag;
2094
2095 pBus->pfnSetIrqR3(pBus->pDevInsR3, pPciDev, iIrq, iLevel, uTagSrc);
2096
2097 if (iLevel == PDM_IRQ_LEVEL_LOW)
2098 VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
2099 pdmUnlock(pVM);
2100
2101 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
2102}
2103
2104
2105/** @interface_method_impl{PDMDEVHLPR3,pfnPCISetIrqNoWait} */
2106static DECLCALLBACK(void) pdmR3DevHlp_PCISetIrqNoWait(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel)
2107{
2108 pdmR3DevHlp_PCISetIrq(pDevIns, pPciDev, iIrq, iLevel);
2109}
2110
2111
2112/** @interface_method_impl{PDMDEVHLPR3,pfnISASetIrq} */
2113static DECLCALLBACK(void) pdmR3DevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
2114{
2115 PDMDEV_ASSERT_DEVINS(pDevIns);
2116 LogFlow(("pdmR3DevHlp_ISASetIrq: caller='%s'/%d: iIrq=%d iLevel=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, iIrq, iLevel));
2117
2118 /*
2119 * Validate input.
2120 */
2121 Assert(iIrq < 16);
2122 Assert((uint32_t)iLevel <= PDM_IRQ_LEVEL_FLIP_FLOP);
2123
2124 PVM pVM = pDevIns->Internal.s.pVMR3;
2125
2126 /*
2127 * Do the job.
2128 */
2129 pdmLock(pVM);
2130 uint32_t uTagSrc;
2131 if (iLevel & PDM_IRQ_LEVEL_HIGH)
2132 {
2133 pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
2134 if (iLevel == PDM_IRQ_LEVEL_HIGH)
2135 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
2136 else
2137 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
2138 }
2139 else
2140 uTagSrc = pDevIns->Internal.s.uLastIrqTag;
2141
2142 PDMIsaSetIrq(pVM, iIrq, iLevel, uTagSrc); /* (The API takes the lock recursively.) */
2143
2144 if (iLevel == PDM_IRQ_LEVEL_LOW)
2145 VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
2146 pdmUnlock(pVM);
2147
2148 LogFlow(("pdmR3DevHlp_ISASetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
2149}
2150
2151
2152/** @interface_method_impl{PDMDEVHLPR3,pfnISASetIrqNoWait} */
2153static DECLCALLBACK(void) pdmR3DevHlp_ISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
2154{
2155 pdmR3DevHlp_ISASetIrq(pDevIns, iIrq, iLevel);
2156}
2157
2158
2159/** @interface_method_impl{PDMDEVHLPR3,pfnDriverAttach} */
2160static DECLCALLBACK(int) pdmR3DevHlp_DriverAttach(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
2161{
2162 PDMDEV_ASSERT_DEVINS(pDevIns);
2163 PVM pVM = pDevIns->Internal.s.pVMR3;
2164 VM_ASSERT_EMT(pVM);
2165 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: iLun=%d pBaseInterface=%p ppBaseInterface=%p pszDesc=%p:{%s}\n",
2166 pDevIns->pReg->szName, pDevIns->iInstance, iLun, pBaseInterface, ppBaseInterface, pszDesc, pszDesc));
2167
2168 /*
2169 * Lookup the LUN, it might already be registered.
2170 */
2171 PPDMLUN pLunPrev = NULL;
2172 PPDMLUN pLun = pDevIns->Internal.s.pLunsR3;
2173 for (; pLun; pLunPrev = pLun, pLun = pLun->pNext)
2174 if (pLun->iLun == iLun)
2175 break;
2176
2177 /*
2178 * Create the LUN if if wasn't found, else check if driver is already attached to it.
2179 */
2180 if (!pLun)
2181 {
2182 if ( !pBaseInterface
2183 || !pszDesc
2184 || !*pszDesc)
2185 {
2186 Assert(pBaseInterface);
2187 Assert(pszDesc || *pszDesc);
2188 return VERR_INVALID_PARAMETER;
2189 }
2190
2191 pLun = (PPDMLUN)MMR3HeapAlloc(pVM, MM_TAG_PDM_LUN, sizeof(*pLun));
2192 if (!pLun)
2193 return VERR_NO_MEMORY;
2194
2195 pLun->iLun = iLun;
2196 pLun->pNext = pLunPrev ? pLunPrev->pNext : NULL;
2197 pLun->pTop = NULL;
2198 pLun->pBottom = NULL;
2199 pLun->pDevIns = pDevIns;
2200 pLun->pUsbIns = NULL;
2201 pLun->pszDesc = pszDesc;
2202 pLun->pBase = pBaseInterface;
2203 if (!pLunPrev)
2204 pDevIns->Internal.s.pLunsR3 = pLun;
2205 else
2206 pLunPrev->pNext = pLun;
2207 Log(("pdmR3DevHlp_DriverAttach: Registered LUN#%d '%s' with device '%s'/%d.\n",
2208 iLun, pszDesc, pDevIns->pReg->szName, pDevIns->iInstance));
2209 }
2210 else if (pLun->pTop)
2211 {
2212 AssertMsgFailed(("Already attached! The device should keep track of such things!\n"));
2213 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_DRIVER_ALREADY_ATTACHED));
2214 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
2215 }
2216 Assert(pLun->pBase == pBaseInterface);
2217
2218
2219 /*
2220 * Get the attached driver configuration.
2221 */
2222 int rc;
2223 PCFGMNODE pNode = CFGMR3GetChildF(pDevIns->Internal.s.pCfgHandle, "LUN#%u", iLun);
2224 if (pNode)
2225 rc = pdmR3DrvInstantiate(pVM, pNode, pBaseInterface, NULL /*pDrvAbove*/, pLun, ppBaseInterface);
2226 else
2227 rc = VERR_PDM_NO_ATTACHED_DRIVER;
2228
2229 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2230 return rc;
2231}
2232
2233
2234/** @interface_method_impl{PDMDEVHLPR3,pfnDriverDetach} */
2235static DECLCALLBACK(int) pdmR3DevHlp_DriverDetach(PPDMDEVINS pDevIns, PPDMDRVINS pDrvIns, uint32_t fFlags)
2236{
2237 PDMDEV_ASSERT_DEVINS(pDevIns); RT_NOREF_PV(pDevIns);
2238 LogFlow(("pdmR3DevHlp_DriverDetach: caller='%s'/%d: pDrvIns=%p\n",
2239 pDevIns->pReg->szName, pDevIns->iInstance, pDrvIns));
2240
2241#ifdef VBOX_STRICT
2242 PVM pVM = pDevIns->Internal.s.pVMR3;
2243 VM_ASSERT_EMT(pVM);
2244#endif
2245
2246 int rc = pdmR3DrvDetach(pDrvIns, fFlags);
2247
2248 LogFlow(("pdmR3DevHlp_DriverDetach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2249 return rc;
2250}
2251
2252
2253/** @interface_method_impl{PDMDEVHLPR3,pfnDriverReconfigure} */
2254static DECLCALLBACK(int) pdmR3DevHlp_DriverReconfigure(PPDMDEVINS pDevIns, uint32_t iLun, uint32_t cDepth,
2255 const char * const *papszDrivers, PCFGMNODE *papConfigs, uint32_t fFlags)
2256{
2257 PDMDEV_ASSERT_DEVINS(pDevIns);
2258 PVM pVM = pDevIns->Internal.s.pVMR3;
2259 VM_ASSERT_EMT(pVM);
2260 LogFlow(("pdmR3DevHlp_DriverReconfigure: caller='%s'/%d: iLun=%u cDepth=%u fFlags=%#x\n",
2261 pDevIns->pReg->szName, pDevIns->iInstance, iLun, cDepth, fFlags));
2262
2263 /*
2264 * Validate input.
2265 */
2266 AssertReturn(cDepth <= 8, VERR_INVALID_PARAMETER);
2267 AssertPtrReturn(papszDrivers, VERR_INVALID_POINTER);
2268 AssertPtrNullReturn(papConfigs, VERR_INVALID_POINTER);
2269 for (uint32_t i = 0; i < cDepth; i++)
2270 {
2271 AssertPtrReturn(papszDrivers[i], VERR_INVALID_POINTER);
2272 size_t cchDriver = strlen(papszDrivers[i]);
2273 AssertReturn(cchDriver > 0 && cchDriver < RT_SIZEOFMEMB(PDMDRVREG, szName), VERR_OUT_OF_RANGE);
2274
2275 if (papConfigs)
2276 AssertPtrNullReturn(papConfigs[i], VERR_INVALID_POINTER);
2277 }
2278 AssertReturn(fFlags == 0, VERR_INVALID_FLAGS);
2279
2280 /*
2281 * Do we have to detach an existing driver first?
2282 */
2283 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext)
2284 if (pLun->iLun == iLun)
2285 {
2286 if (pLun->pTop)
2287 {
2288 int rc = pdmR3DrvDetach(pLun->pTop, 0);
2289 AssertRCReturn(rc, rc);
2290 }
2291 break;
2292 }
2293
2294 /*
2295 * Remove the old tree.
2296 */
2297 PCFGMNODE pCfgDev = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/", pDevIns->pReg->szName, pDevIns->iInstance);
2298 AssertReturn(pCfgDev, VERR_INTERNAL_ERROR_2);
2299 PCFGMNODE pCfgLun = CFGMR3GetChildF(pCfgDev, "LUN#%u", iLun);
2300 if (pCfgLun)
2301 CFGMR3RemoveNode(pCfgLun);
2302
2303 /*
2304 * Construct a new tree.
2305 */
2306 int rc = CFGMR3InsertNodeF(pCfgDev, &pCfgLun, "LUN#%u", iLun);
2307 AssertRCReturn(rc, rc);
2308 PCFGMNODE pCfgDrv = pCfgLun;
2309 for (uint32_t i = 0; i < cDepth; i++)
2310 {
2311 rc = CFGMR3InsertString(pCfgDrv, "Driver", papszDrivers[i]);
2312 AssertRCReturn(rc, rc);
2313 if (papConfigs && papConfigs[i])
2314 {
2315 rc = CFGMR3InsertSubTree(pCfgDrv, "Config", papConfigs[i], NULL);
2316 AssertRCReturn(rc, rc);
2317 papConfigs[i] = NULL;
2318 }
2319 else
2320 {
2321 rc = CFGMR3InsertNode(pCfgDrv, "Config", NULL);
2322 AssertRCReturn(rc, rc);
2323 }
2324
2325 if (i + 1 >= cDepth)
2326 break;
2327 rc = CFGMR3InsertNode(pCfgDrv, "AttachedDriver", &pCfgDrv);
2328 AssertRCReturn(rc, rc);
2329 }
2330
2331 LogFlow(("pdmR3DevHlp_DriverReconfigure: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2332 return rc;
2333}
2334
2335
2336/** @interface_method_impl{PDMDEVHLPR3,pfnQueueCreatePtr} */
2337static DECLCALLBACK(int) pdmR3DevHlp_QueueCreatePtr(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
2338 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PPDMQUEUE *ppQueue)
2339{
2340 PDMDEV_ASSERT_DEVINS(pDevIns);
2341 LogFlow(("pdmR3DevHlp_QueueCreatePtr: caller='%s'/%d: cbItem=%#x cItems=%#x cMilliesInterval=%u pfnCallback=%p fRZEnabled=%RTbool pszName=%p:{%s} ppQueue=%p\n",
2342 pDevIns->pReg->szName, pDevIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, pszName, ppQueue));
2343
2344 PVM pVM = pDevIns->Internal.s.pVMR3;
2345 VM_ASSERT_EMT(pVM);
2346
2347 if (pDevIns->iInstance > 0)
2348 {
2349 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s_%u", pszName, pDevIns->iInstance);
2350 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
2351 }
2352
2353 int rc = PDMR3QueueCreateDevice(pVM, pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, ppQueue);
2354
2355 LogFlow(("pdmR3DevHlp_QueueCreatePtr: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *ppQueue));
2356 return rc;
2357}
2358
2359
2360/** @interface_method_impl{PDMDEVHLPR3,pfnQueueCreate} */
2361static DECLCALLBACK(int) pdmR3DevHlp_QueueCreate(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
2362 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName,
2363 PDMQUEUEHANDLE *phQueue)
2364{
2365 PDMDEV_ASSERT_DEVINS(pDevIns);
2366 LogFlow(("pdmR3DevHlp_QueueCreate: caller='%s'/%d: cbItem=%#x cItems=%#x cMilliesInterval=%u pfnCallback=%p fRZEnabled=%RTbool pszName=%p:{%s} phQueue=%p\n",
2367 pDevIns->pReg->szName, pDevIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, pszName, phQueue));
2368
2369 PVM pVM = pDevIns->Internal.s.pVMR3;
2370 VM_ASSERT_EMT(pVM);
2371
2372 if (pDevIns->iInstance > 0)
2373 {
2374 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s_%u", pszName, pDevIns->iInstance);
2375 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
2376 }
2377
2378 PPDMQUEUE pQueue = NULL;
2379 int rc = PDMR3QueueCreateDevice(pVM, pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, &pQueue);
2380 *phQueue = (uintptr_t)pQueue;
2381
2382 LogFlow(("pdmR3DevHlp_QueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *phQueue));
2383 return rc;
2384}
2385
2386
2387/** @interface_method_impl{PDMDEVHLPR3,pfnQueueToPtr} */
2388static DECLCALLBACK(PPDMQUEUE) pdmR3DevHlp_QueueToPtr(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue)
2389{
2390 PDMDEV_ASSERT_DEVINS(pDevIns);
2391 RT_NOREF(pDevIns);
2392 return (PPDMQUEUE)hQueue;
2393}
2394
2395
2396/** @interface_method_impl{PDMDEVHLPR3,pfnQueueAlloc} */
2397static DECLCALLBACK(PPDMQUEUEITEMCORE) pdmR3DevHlp_QueueAlloc(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue)
2398{
2399 return PDMQueueAlloc(pdmR3DevHlp_QueueToPtr(pDevIns, hQueue));
2400}
2401
2402
2403/** @interface_method_impl{PDMDEVHLPR3,pfnQueueInsert} */
2404static DECLCALLBACK(void) pdmR3DevHlp_QueueInsert(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem)
2405{
2406 return PDMQueueInsert(pdmR3DevHlp_QueueToPtr(pDevIns, hQueue), pItem);
2407}
2408
2409
2410/** @interface_method_impl{PDMDEVHLPR3,pfnQueueInsertEx} */
2411static DECLCALLBACK(void) pdmR3DevHlp_QueueInsertEx(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem,
2412 uint64_t cNanoMaxDelay)
2413{
2414 return PDMQueueInsertEx(pdmR3DevHlp_QueueToPtr(pDevIns, hQueue), pItem, cNanoMaxDelay);
2415}
2416
2417
2418/** @interface_method_impl{PDMDEVHLPR3,pfnQueueFlushIfNecessary} */
2419static DECLCALLBACK(bool) pdmR3DevHlp_QueueFlushIfNecessary(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue)
2420{
2421 return PDMQueueFlushIfNecessary(pdmR3DevHlp_QueueToPtr(pDevIns, hQueue));
2422}
2423
2424
2425/** @interface_method_impl{PDMDEVHLPR3,pfnTaskCreate} */
2426static DECLCALLBACK(int) pdmR3DevHlp_TaskCreate(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszName,
2427 PFNPDMTASKDEV pfnCallback, void *pvUser, PDMTASKHANDLE *phTask)
2428{
2429 PDMDEV_ASSERT_DEVINS(pDevIns);
2430 LogFlow(("pdmR3DevHlp_TaskTrigger: caller='%s'/%d: pfnCallback=%p fFlags=%#x pszName=%p:{%s} phTask=%p\n",
2431 pDevIns->pReg->szName, pDevIns->iInstance, pfnCallback, fFlags, pszName, pszName, phTask));
2432 PVM pVM = pDevIns->Internal.s.pVMR3;
2433 VM_ASSERT_EMT(pVM);
2434
2435 int rc = PDMR3TaskCreate(pVM, fFlags, pszName, PDMTASKTYPE_DEV, pDevIns, (PFNRT)pfnCallback, pvUser, phTask);
2436
2437 LogFlow(("pdmR3DevHlp_TaskTrigger: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2438 return rc;
2439}
2440
2441
2442/** @interface_method_impl{PDMDEVHLPR3,pfnTaskTrigger} */
2443static DECLCALLBACK(int) pdmR3DevHlp_TaskTrigger(PPDMDEVINS pDevIns, PDMTASKHANDLE hTask)
2444{
2445 PDMDEV_ASSERT_DEVINS(pDevIns);
2446 LogFlow(("pdmR3DevHlp_TaskTrigger: caller='%s'/%d: hTask=%RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, hTask));
2447
2448 int rc = PDMTaskTrigger(pDevIns->Internal.s.pVMR3, PDMTASKTYPE_DEV, pDevIns, hTask);
2449
2450 LogFlow(("pdmR3DevHlp_TaskTrigger: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2451 return rc;
2452}
2453
2454
2455/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventCreate} */
2456static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventCreate(PPDMDEVINS pDevIns, PSUPSEMEVENT phEvent)
2457{
2458 PDMDEV_ASSERT_DEVINS(pDevIns);
2459 LogFlow(("pdmR3DevHlp_SUPSemEventCreate: caller='%s'/%d: phEvent=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, phEvent));
2460 PVM pVM = pDevIns->Internal.s.pVMR3;
2461 VM_ASSERT_EMT(pVM);
2462
2463 int rc = SUPSemEventCreate(pVM->pSession, phEvent);
2464
2465 LogFlow(("pdmR3DevHlp_SUPSemEventCreate: caller='%s'/%d: returns %Rrc *phEvent=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *phEvent));
2466 return rc;
2467}
2468
2469
2470/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventClose} */
2471static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventClose(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent)
2472{
2473 PDMDEV_ASSERT_DEVINS(pDevIns);
2474 LogFlow(("pdmR3DevHlp_SUPSemEventClose: caller='%s'/%d: hEvent=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, hEvent));
2475
2476 int rc = SUPSemEventClose(pDevIns->Internal.s.pVMR3->pSession, hEvent);
2477
2478 LogFlow(("pdmR3DevHlp_SUPSemEventClose: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2479 return rc;
2480}
2481
2482
2483/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventSignal} */
2484static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventSignal(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent)
2485{
2486 PDMDEV_ASSERT_DEVINS(pDevIns);
2487 LogFlow(("pdmR3DevHlp_SUPSemEventSignal: caller='%s'/%d: hEvent=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, hEvent));
2488
2489 int rc = SUPSemEventSignal(pDevIns->Internal.s.pVMR3->pSession, hEvent);
2490
2491 LogFlow(("pdmR3DevHlp_SUPSemEventSignal: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2492 return rc;
2493}
2494
2495
2496/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventWaitNoResume} */
2497static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventWaitNoResume(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint32_t cMillies)
2498{
2499 PDMDEV_ASSERT_DEVINS(pDevIns);
2500 LogFlow(("pdmR3DevHlp_SUPSemEventWaitNoResume: caller='%s'/%d: hEvent=%p cNsTimeout=%RU32\n",
2501 pDevIns->pReg->szName, pDevIns->iInstance, hEvent, cMillies));
2502
2503 int rc = SUPSemEventWaitNoResume(pDevIns->Internal.s.pVMR3->pSession, hEvent, cMillies);
2504
2505 LogFlow(("pdmR3DevHlp_SUPSemEventWaitNoResume: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2506 return rc;
2507}
2508
2509
2510/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventWaitNsAbsIntr} */
2511static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventWaitNsAbsIntr(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t uNsTimeout)
2512{
2513 PDMDEV_ASSERT_DEVINS(pDevIns);
2514 LogFlow(("pdmR3DevHlp_SUPSemEventWaitNsAbsIntr: caller='%s'/%d: hEvent=%p uNsTimeout=%RU64\n",
2515 pDevIns->pReg->szName, pDevIns->iInstance, hEvent, uNsTimeout));
2516
2517 int rc = SUPSemEventWaitNsAbsIntr(pDevIns->Internal.s.pVMR3->pSession, hEvent, uNsTimeout);
2518
2519 LogFlow(("pdmR3DevHlp_SUPSemEventWaitNsAbsIntr: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2520 return rc;
2521}
2522
2523
2524/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventWaitNsRelIntr} */
2525static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventWaitNsRelIntr(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t cNsTimeout)
2526{
2527 PDMDEV_ASSERT_DEVINS(pDevIns);
2528 LogFlow(("pdmR3DevHlp_SUPSemEventWaitNsRelIntr: caller='%s'/%d: hEvent=%p cNsTimeout=%RU64\n",
2529 pDevIns->pReg->szName, pDevIns->iInstance, hEvent, cNsTimeout));
2530
2531 int rc = SUPSemEventWaitNsRelIntr(pDevIns->Internal.s.pVMR3->pSession, hEvent, cNsTimeout);
2532
2533 LogFlow(("pdmR3DevHlp_SUPSemEventWaitNsRelIntr: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2534 return rc;
2535}
2536
2537
2538/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventGetResolution} */
2539static DECLCALLBACK(uint32_t) pdmR3DevHlp_SUPSemEventGetResolution(PPDMDEVINS pDevIns)
2540{
2541 PDMDEV_ASSERT_DEVINS(pDevIns);
2542 LogFlow(("pdmR3DevHlp_SUPSemEventGetResolution: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
2543
2544 uint32_t cNsResolution = SUPSemEventGetResolution(pDevIns->Internal.s.pVMR3->pSession);
2545
2546 LogFlow(("pdmR3DevHlp_SUPSemEventGetResolution: caller='%s'/%d: returns %u\n", pDevIns->pReg->szName, pDevIns->iInstance, cNsResolution));
2547 return cNsResolution;
2548}
2549
2550
2551/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiCreate} */
2552static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventMultiCreate(PPDMDEVINS pDevIns, PSUPSEMEVENTMULTI phEventMulti)
2553{
2554 PDMDEV_ASSERT_DEVINS(pDevIns);
2555 LogFlow(("pdmR3DevHlp_SUPSemEventMultiCreate: caller='%s'/%d: phEventMulti=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, phEventMulti));
2556 PVM pVM = pDevIns->Internal.s.pVMR3;
2557 VM_ASSERT_EMT(pVM);
2558
2559 int rc = SUPSemEventMultiCreate(pVM->pSession, phEventMulti);
2560
2561 LogFlow(("pdmR3DevHlp_SUPSemEventMultiCreate: caller='%s'/%d: returns %Rrc *phEventMulti=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *phEventMulti));
2562 return rc;
2563}
2564
2565
2566/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiClose} */
2567static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventMultiClose(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti)
2568{
2569 PDMDEV_ASSERT_DEVINS(pDevIns);
2570 LogFlow(("pdmR3DevHlp_SUPSemEventMultiClose: caller='%s'/%d: hEventMulti=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, hEventMulti));
2571
2572 int rc = SUPSemEventMultiClose(pDevIns->Internal.s.pVMR3->pSession, hEventMulti);
2573
2574 LogFlow(("pdmR3DevHlp_SUPSemEventMultiClose: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2575 return rc;
2576}
2577
2578
2579/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiSignal} */
2580static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventMultiSignal(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti)
2581{
2582 PDMDEV_ASSERT_DEVINS(pDevIns);
2583 LogFlow(("pdmR3DevHlp_SUPSemEventMultiSignal: caller='%s'/%d: hEventMulti=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, hEventMulti));
2584
2585 int rc = SUPSemEventMultiSignal(pDevIns->Internal.s.pVMR3->pSession, hEventMulti);
2586
2587 LogFlow(("pdmR3DevHlp_SUPSemEventMultiSignal: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2588 return rc;
2589}
2590
2591
2592/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiReset} */
2593static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventMultiReset(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti)
2594{
2595 PDMDEV_ASSERT_DEVINS(pDevIns);
2596 LogFlow(("pdmR3DevHlp_SUPSemEventMultiReset: caller='%s'/%d: hEventMulti=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, hEventMulti));
2597
2598 int rc = SUPSemEventMultiReset(pDevIns->Internal.s.pVMR3->pSession, hEventMulti);
2599
2600 LogFlow(("pdmR3DevHlp_SUPSemEventMultiReset: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2601 return rc;
2602}
2603
2604
2605/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiWaitNoResume} */
2606static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventMultiWaitNoResume(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti,
2607 uint32_t cMillies)
2608{
2609 PDMDEV_ASSERT_DEVINS(pDevIns);
2610 LogFlow(("pdmR3DevHlp_SUPSemEventMultiWaitNoResume: caller='%s'/%d: hEventMulti=%p cMillies=%RU32\n",
2611 pDevIns->pReg->szName, pDevIns->iInstance, hEventMulti, cMillies));
2612
2613 int rc = SUPSemEventMultiWaitNoResume(pDevIns->Internal.s.pVMR3->pSession, hEventMulti, cMillies);
2614
2615 LogFlow(("pdmR3DevHlp_SUPSemEventMultiWaitNoResume: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2616 return rc;
2617}
2618
2619
2620/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiWaitNsAbsIntr} */
2621static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventMultiWaitNsAbsIntr(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti,
2622 uint64_t uNsTimeout)
2623{
2624 PDMDEV_ASSERT_DEVINS(pDevIns);
2625 LogFlow(("pdmR3DevHlp_SUPSemEventMultiWaitNsAbsIntr: caller='%s'/%d: hEventMulti=%p uNsTimeout=%RU64\n",
2626 pDevIns->pReg->szName, pDevIns->iInstance, hEventMulti, uNsTimeout));
2627
2628 int rc = SUPSemEventMultiWaitNsAbsIntr(pDevIns->Internal.s.pVMR3->pSession, hEventMulti, uNsTimeout);
2629
2630 LogFlow(("pdmR3DevHlp_SUPSemEventMultiWaitNsAbsIntr: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2631 return rc;
2632}
2633
2634
2635/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiWaitNsRelIntr} */
2636static DECLCALLBACK(int) pdmR3DevHlp_SUPSemEventMultiWaitNsRelIntr(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti,
2637 uint64_t cNsTimeout)
2638{
2639 PDMDEV_ASSERT_DEVINS(pDevIns);
2640 LogFlow(("pdmR3DevHlp_SUPSemEventMultiWaitNsRelIntr: caller='%s'/%d: hEventMulti=%p cNsTimeout=%RU64\n",
2641 pDevIns->pReg->szName, pDevIns->iInstance, hEventMulti, cNsTimeout));
2642
2643 int rc = SUPSemEventMultiWaitNsRelIntr(pDevIns->Internal.s.pVMR3->pSession, hEventMulti, cNsTimeout);
2644
2645 LogFlow(("pdmR3DevHlp_SUPSemEventMultiWaitNsRelIntr: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2646 return rc;
2647}
2648
2649
2650/** @interface_method_impl{PDMDEVHLPR3,pfnSUPSemEventMultiGetResolution} */
2651static DECLCALLBACK(uint32_t) pdmR3DevHlp_SUPSemEventMultiGetResolution(PPDMDEVINS pDevIns)
2652{
2653 PDMDEV_ASSERT_DEVINS(pDevIns);
2654 LogFlow(("pdmR3DevHlp_SUPSemEventMultiGetResolution: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
2655
2656 uint32_t cNsResolution = SUPSemEventMultiGetResolution(pDevIns->Internal.s.pVMR3->pSession);
2657
2658 LogFlow(("pdmR3DevHlp_SUPSemEventMultiGetResolution: caller='%s'/%d: returns %u\n", pDevIns->pReg->szName, pDevIns->iInstance, cNsResolution));
2659 return cNsResolution;
2660}
2661
2662
2663/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectInit} */
2664static DECLCALLBACK(int) pdmR3DevHlp_CritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
2665 const char *pszNameFmt, va_list va)
2666{
2667 PDMDEV_ASSERT_DEVINS(pDevIns);
2668 LogFlow(("pdmR3DevHlp_CritSectInit: caller='%s'/%d: pCritSect=%p pszNameFmt=%p:{%s}\n",
2669 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect, pszNameFmt, pszNameFmt));
2670
2671 PVM pVM = pDevIns->Internal.s.pVMR3;
2672 VM_ASSERT_EMT(pVM);
2673 int rc = pdmR3CritSectInitDevice(pVM, pDevIns, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
2674
2675 LogFlow(("pdmR3DevHlp_CritSectInit: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2676 return rc;
2677}
2678
2679
2680/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNop} */
2681static DECLCALLBACK(PPDMCRITSECT) pdmR3DevHlp_CritSectGetNop(PPDMDEVINS pDevIns)
2682{
2683 PDMDEV_ASSERT_DEVINS(pDevIns);
2684 PVM pVM = pDevIns->Internal.s.pVMR3;
2685 VM_ASSERT_EMT(pVM);
2686
2687 PPDMCRITSECT pCritSect = PDMR3CritSectGetNop(pVM);
2688 LogFlow(("pdmR3DevHlp_CritSectGetNop: caller='%s'/%d: return %p\n",
2689 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
2690 return pCritSect;
2691}
2692
2693
2694/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNopR0} */
2695static DECLCALLBACK(R0PTRTYPE(PPDMCRITSECT)) pdmR3DevHlp_CritSectGetNopR0(PPDMDEVINS pDevIns)
2696{
2697 PDMDEV_ASSERT_DEVINS(pDevIns);
2698 PVM pVM = pDevIns->Internal.s.pVMR3;
2699 VM_ASSERT_EMT(pVM);
2700
2701 R0PTRTYPE(PPDMCRITSECT) pCritSect = PDMR3CritSectGetNopR0(pVM);
2702 LogFlow(("pdmR3DevHlp_CritSectGetNopR0: caller='%s'/%d: return %RHv\n",
2703 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
2704 return pCritSect;
2705}
2706
2707
2708/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNopRC} */
2709static DECLCALLBACK(RCPTRTYPE(PPDMCRITSECT)) pdmR3DevHlp_CritSectGetNopRC(PPDMDEVINS pDevIns)
2710{
2711 PDMDEV_ASSERT_DEVINS(pDevIns);
2712 PVM pVM = pDevIns->Internal.s.pVMR3;
2713 VM_ASSERT_EMT(pVM);
2714
2715 RCPTRTYPE(PPDMCRITSECT) pCritSect = PDMR3CritSectGetNopRC(pVM);
2716 LogFlow(("pdmR3DevHlp_CritSectGetNopRC: caller='%s'/%d: return %RRv\n",
2717 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
2718 return pCritSect;
2719}
2720
2721
2722/** @interface_method_impl{PDMDEVHLPR3,pfnSetDeviceCritSect} */
2723static DECLCALLBACK(int) pdmR3DevHlp_SetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
2724{
2725 /*
2726 * Validate input.
2727 *
2728 * Note! We only allow the automatically created default critical section
2729 * to be replaced by this API.
2730 */
2731 PDMDEV_ASSERT_DEVINS(pDevIns);
2732 AssertPtrReturn(pCritSect, VERR_INVALID_POINTER);
2733 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: pCritSect=%p (%s)\n",
2734 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect, pCritSect->s.pszName));
2735 AssertReturn(PDMCritSectIsInitialized(pCritSect), VERR_INVALID_PARAMETER);
2736 PVM pVM = pDevIns->Internal.s.pVMR3;
2737 AssertReturn(pCritSect->s.pVMR3 == pVM, VERR_INVALID_PARAMETER);
2738
2739 VM_ASSERT_EMT(pVM);
2740 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
2741
2742 AssertReturn(pDevIns->pCritSectRoR3, VERR_PDM_DEV_IPE_1);
2743 AssertReturn(pDevIns->pCritSectRoR3->s.fAutomaticDefaultCritsect, VERR_WRONG_ORDER);
2744 AssertReturn(!pDevIns->pCritSectRoR3->s.fUsedByTimerOrSimilar, VERR_WRONG_ORDER);
2745 AssertReturn(pDevIns->pCritSectRoR3 != pCritSect, VERR_INVALID_PARAMETER);
2746
2747 /*
2748 * Replace the critical section and destroy the automatic default section.
2749 */
2750 PPDMCRITSECT pOldCritSect = pDevIns->pCritSectRoR3;
2751 pDevIns->pCritSectRoR3 = pCritSect;
2752 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_CHANGED_CRITSECT;
2753
2754 Assert(RT_BOOL(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_R0_ENABLED) == pDevIns->fR0Enabled);
2755 if ( (pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_R0_ENABLED)
2756 && !(pDevIns->Internal.s.pDevR3->pReg->fFlags & PDM_DEVREG_FLAGS_NEW_STYLE))
2757 {
2758 PDMDEVICECOMPATSETCRITSECTREQ Req;
2759 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
2760 Req.Hdr.cbReq = sizeof(Req);
2761 Req.idxR0Device = pDevIns->Internal.s.idxR0Device;
2762 Req.pDevInsR3 = pDevIns;
2763 Req.pCritSectR3 = pCritSect;
2764 int rc = VMMR3CallR0(pVM, VMMR0_DO_PDM_DEVICE_COMPAT_SET_CRITSECT, 0, &Req.Hdr);
2765 AssertLogRelRCReturn(rc, rc);
2766 }
2767
2768 PDMR3CritSectDelete(pOldCritSect);
2769 Assert((uintptr_t)pOldCritSect - (uintptr_t)pDevIns < pDevIns->cbRing3);
2770
2771 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2772 return VINF_SUCCESS;
2773}
2774
2775
2776/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectYield} */
2777static DECLCALLBACK(bool) pdmR3DevHlp_CritSectYield(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
2778{
2779 PDMDEV_ASSERT_DEVINS(pDevIns);
2780 return PDMR3CritSectYield(pDevIns->Internal.s.pVMR3, pCritSect);
2781}
2782
2783
2784/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectEnter} */
2785static DECLCALLBACK(int) pdmR3DevHlp_CritSectEnter(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy)
2786{
2787 PDMDEV_ASSERT_DEVINS(pDevIns);
2788 RT_NOREF(pDevIns); /** @todo pass pDevIns->Internal.s.pVMR3 to the crit sect code. */
2789 return PDMCritSectEnter(pCritSect, rcBusy);
2790}
2791
2792
2793/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectEnterDebug} */
2794static DECLCALLBACK(int) pdmR3DevHlp_CritSectEnterDebug(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy, RTHCUINTPTR uId, RT_SRC_POS_DECL)
2795{
2796 PDMDEV_ASSERT_DEVINS(pDevIns);
2797 RT_NOREF(pDevIns); /** @todo pass pDevIns->Internal.s.pVMR3 to the crit sect code. */
2798 return PDMCritSectEnterDebug(pCritSect, rcBusy, uId, RT_SRC_POS_ARGS);
2799}
2800
2801
2802/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectTryEnter} */
2803static DECLCALLBACK(int) pdmR3DevHlp_CritSectTryEnter(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
2804{
2805 PDMDEV_ASSERT_DEVINS(pDevIns);
2806 RT_NOREF(pDevIns); /** @todo pass pDevIns->Internal.s.pVMR3 to the crit sect code. */
2807 return PDMCritSectTryEnter(pCritSect);
2808}
2809
2810
2811/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectTryEnterDebug} */
2812static DECLCALLBACK(int) pdmR3DevHlp_CritSectTryEnterDebug(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RTHCUINTPTR uId, RT_SRC_POS_DECL)
2813{
2814 PDMDEV_ASSERT_DEVINS(pDevIns);
2815 RT_NOREF(pDevIns); /** @todo pass pDevIns->Internal.s.pVMR3 to the crit sect code. */
2816 return PDMCritSectTryEnterDebug(pCritSect, uId, RT_SRC_POS_ARGS);
2817}
2818
2819
2820/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectLeave} */
2821static DECLCALLBACK(int) pdmR3DevHlp_CritSectLeave(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
2822{
2823 PDMDEV_ASSERT_DEVINS(pDevIns);
2824 RT_NOREF(pDevIns); /** @todo pass pDevIns->Internal.s.pVMR3 to the crit sect code. */
2825 return PDMCritSectLeave(pCritSect);
2826}
2827
2828
2829/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectIsOwner} */
2830static DECLCALLBACK(bool) pdmR3DevHlp_CritSectIsOwner(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
2831{
2832 PDMDEV_ASSERT_DEVINS(pDevIns);
2833 RT_NOREF(pDevIns); /** @todo pass pDevIns->Internal.s.pVMR3 to the crit sect code. */
2834 return PDMCritSectIsOwner(pCritSect);
2835}
2836
2837
2838/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectIsInitialized} */
2839static DECLCALLBACK(bool) pdmR3DevHlp_CritSectIsInitialized(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
2840{
2841 PDMDEV_ASSERT_DEVINS(pDevIns);
2842 RT_NOREF(pDevIns);
2843 return PDMCritSectIsInitialized(pCritSect);
2844}
2845
2846
2847/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectHasWaiters} */
2848static DECLCALLBACK(bool) pdmR3DevHlp_CritSectHasWaiters(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
2849{
2850 PDMDEV_ASSERT_DEVINS(pDevIns);
2851 RT_NOREF(pDevIns);
2852 return PDMCritSectHasWaiters(pCritSect);
2853}
2854
2855
2856/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetRecursion} */
2857static DECLCALLBACK(uint32_t) pdmR3DevHlp_CritSectGetRecursion(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
2858{
2859 PDMDEV_ASSERT_DEVINS(pDevIns);
2860 RT_NOREF(pDevIns);
2861 return PDMCritSectGetRecursion(pCritSect);
2862}
2863
2864
2865/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectScheduleExitEvent} */
2866static DECLCALLBACK(int) pdmR3DevHlp_CritSectScheduleExitEvent(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect,
2867 SUPSEMEVENT hEventToSignal)
2868{
2869 PDMDEV_ASSERT_DEVINS(pDevIns);
2870 RT_NOREF(pDevIns);
2871 return PDMHCCritSectScheduleExitEvent(pCritSect, hEventToSignal);
2872}
2873
2874
2875/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectDelete} */
2876static DECLCALLBACK(int) pdmR3DevHlp_CritSectDelete(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
2877{
2878 PDMDEV_ASSERT_DEVINS(pDevIns);
2879 RT_NOREF(pDevIns);
2880 return PDMR3CritSectDelete(pCritSect);
2881}
2882
2883
2884/** @interface_method_impl{PDMDEVHLPR3,pfnThreadCreate} */
2885static DECLCALLBACK(int) pdmR3DevHlp_ThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
2886 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
2887{
2888 PDMDEV_ASSERT_DEVINS(pDevIns);
2889 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2890 LogFlow(("pdmR3DevHlp_ThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
2891 pDevIns->pReg->szName, pDevIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
2892
2893 int rc = pdmR3ThreadCreateDevice(pDevIns->Internal.s.pVMR3, pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
2894
2895 LogFlow(("pdmR3DevHlp_ThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDevIns->pReg->szName, pDevIns->iInstance,
2896 rc, *ppThread));
2897 return rc;
2898}
2899
2900
2901/** @interface_method_impl{PDMDEVHLPR3,pfnSetAsyncNotification} */
2902static DECLCALLBACK(int) pdmR3DevHlp_SetAsyncNotification(PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify)
2903{
2904 PDMDEV_ASSERT_DEVINS(pDevIns);
2905 VM_ASSERT_EMT0(pDevIns->Internal.s.pVMR3);
2906 LogFlow(("pdmR3DevHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pfnAsyncNotify));
2907
2908 int rc = VINF_SUCCESS;
2909 AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
2910 AssertStmt(!pDevIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
2911 AssertStmt(pDevIns->Internal.s.fIntFlags & (PDMDEVINSINT_FLAGS_SUSPENDED | PDMDEVINSINT_FLAGS_RESET), rc = VERR_WRONG_ORDER);
2912 VMSTATE enmVMState = VMR3GetState(pDevIns->Internal.s.pVMR3);
2913 AssertStmt( enmVMState == VMSTATE_SUSPENDING
2914 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
2915 || enmVMState == VMSTATE_SUSPENDING_LS
2916 || enmVMState == VMSTATE_RESETTING
2917 || enmVMState == VMSTATE_RESETTING_LS
2918 || enmVMState == VMSTATE_POWERING_OFF
2919 || enmVMState == VMSTATE_POWERING_OFF_LS,
2920 rc = VERR_INVALID_STATE);
2921
2922 if (RT_SUCCESS(rc))
2923 pDevIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
2924
2925 LogFlow(("pdmR3DevHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2926 return rc;
2927}
2928
2929
2930/** @interface_method_impl{PDMDEVHLPR3,pfnAsyncNotificationCompleted} */
2931static DECLCALLBACK(void) pdmR3DevHlp_AsyncNotificationCompleted(PPDMDEVINS pDevIns)
2932{
2933 PDMDEV_ASSERT_DEVINS(pDevIns);
2934 PVM pVM = pDevIns->Internal.s.pVMR3;
2935
2936 VMSTATE enmVMState = VMR3GetState(pVM);
2937 if ( enmVMState == VMSTATE_SUSPENDING
2938 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
2939 || enmVMState == VMSTATE_SUSPENDING_LS
2940 || enmVMState == VMSTATE_RESETTING
2941 || enmVMState == VMSTATE_RESETTING_LS
2942 || enmVMState == VMSTATE_POWERING_OFF
2943 || enmVMState == VMSTATE_POWERING_OFF_LS)
2944 {
2945 LogFlow(("pdmR3DevHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
2946 VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
2947 }
2948 else
2949 LogFlow(("pdmR3DevHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, enmVMState));
2950}
2951
2952
2953/** @interface_method_impl{PDMDEVHLPR3,pfnRTCRegister} */
2954static DECLCALLBACK(int) pdmR3DevHlp_RTCRegister(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp)
2955{
2956 PDMDEV_ASSERT_DEVINS(pDevIns);
2957 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2958 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: pRtcReg=%p:{.u32Version=%#x, .pfnWrite=%p, .pfnRead=%p} ppRtcHlp=%p\n",
2959 pDevIns->pReg->szName, pDevIns->iInstance, pRtcReg, pRtcReg->u32Version, pRtcReg->pfnWrite,
2960 pRtcReg->pfnWrite, ppRtcHlp));
2961
2962 /*
2963 * Validate input.
2964 */
2965 if (pRtcReg->u32Version != PDM_RTCREG_VERSION)
2966 {
2967 AssertMsgFailed(("u32Version=%#x expected %#x\n", pRtcReg->u32Version,
2968 PDM_RTCREG_VERSION));
2969 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (version)\n",
2970 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2971 return VERR_INVALID_PARAMETER;
2972 }
2973 if ( !pRtcReg->pfnWrite
2974 || !pRtcReg->pfnRead)
2975 {
2976 Assert(pRtcReg->pfnWrite);
2977 Assert(pRtcReg->pfnRead);
2978 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (callbacks)\n",
2979 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2980 return VERR_INVALID_PARAMETER;
2981 }
2982
2983 if (!ppRtcHlp)
2984 {
2985 Assert(ppRtcHlp);
2986 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (ppRtcHlp)\n",
2987 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2988 return VERR_INVALID_PARAMETER;
2989 }
2990
2991 /*
2992 * Only one DMA device.
2993 */
2994 PVM pVM = pDevIns->Internal.s.pVMR3;
2995 if (pVM->pdm.s.pRtc)
2996 {
2997 AssertMsgFailed(("Only one RTC device is supported!\n"));
2998 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n",
2999 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3000 return VERR_INVALID_PARAMETER;
3001 }
3002
3003 /*
3004 * Allocate and initialize pci bus structure.
3005 */
3006 int rc = VINF_SUCCESS;
3007 PPDMRTC pRtc = (PPDMRTC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pRtc));
3008 if (pRtc)
3009 {
3010 pRtc->pDevIns = pDevIns;
3011 pRtc->Reg = *pRtcReg;
3012 pVM->pdm.s.pRtc = pRtc;
3013
3014 /* set the helper pointer. */
3015 *ppRtcHlp = &g_pdmR3DevRtcHlp;
3016 Log(("PDM: Registered RTC device '%s'/%d pDevIns=%p\n",
3017 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3018 }
3019 else
3020 rc = VERR_NO_MEMORY;
3021
3022 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n",
3023 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3024 return rc;
3025}
3026
3027
3028/** @interface_method_impl{PDMDEVHLPR3,pfnDMARegister} */
3029static DECLCALLBACK(int) pdmR3DevHlp_DMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
3030{
3031 PDMDEV_ASSERT_DEVINS(pDevIns);
3032 PVM pVM = pDevIns->Internal.s.pVMR3;
3033 VM_ASSERT_EMT(pVM);
3034 LogFlow(("pdmR3DevHlp_DMARegister: caller='%s'/%d: uChannel=%d pfnTransferHandler=%p pvUser=%p\n",
3035 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pfnTransferHandler, pvUser));
3036 int rc = VINF_SUCCESS;
3037 if (pVM->pdm.s.pDmac)
3038 pVM->pdm.s.pDmac->Reg.pfnRegister(pVM->pdm.s.pDmac->pDevIns, uChannel, pDevIns, pfnTransferHandler, pvUser);
3039 else
3040 {
3041 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
3042 rc = VERR_PDM_NO_DMAC_INSTANCE;
3043 }
3044 LogFlow(("pdmR3DevHlp_DMARegister: caller='%s'/%d: returns %Rrc\n",
3045 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3046 return rc;
3047}
3048
3049
3050/** @interface_method_impl{PDMDEVHLPR3,pfnDMAReadMemory} */
3051static DECLCALLBACK(int) pdmR3DevHlp_DMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
3052{
3053 PDMDEV_ASSERT_DEVINS(pDevIns);
3054 PVM pVM = pDevIns->Internal.s.pVMR3;
3055 VM_ASSERT_EMT(pVM);
3056 LogFlow(("pdmR3DevHlp_DMAReadMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbRead=%p\n",
3057 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbRead));
3058 int rc = VINF_SUCCESS;
3059 if (pVM->pdm.s.pDmac)
3060 {
3061 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnReadMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock);
3062 if (pcbRead)
3063 *pcbRead = cb;
3064 }
3065 else
3066 {
3067 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
3068 rc = VERR_PDM_NO_DMAC_INSTANCE;
3069 }
3070 LogFlow(("pdmR3DevHlp_DMAReadMemory: caller='%s'/%d: returns %Rrc\n",
3071 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3072 return rc;
3073}
3074
3075
3076/** @interface_method_impl{PDMDEVHLPR3,pfnDMAWriteMemory} */
3077static DECLCALLBACK(int) pdmR3DevHlp_DMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
3078{
3079 PDMDEV_ASSERT_DEVINS(pDevIns);
3080 PVM pVM = pDevIns->Internal.s.pVMR3;
3081 VM_ASSERT_EMT(pVM);
3082 LogFlow(("pdmR3DevHlp_DMAWriteMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbWritten=%p\n",
3083 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbWritten));
3084 int rc = VINF_SUCCESS;
3085 if (pVM->pdm.s.pDmac)
3086 {
3087 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnWriteMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock);
3088 if (pcbWritten)
3089 *pcbWritten = cb;
3090 }
3091 else
3092 {
3093 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
3094 rc = VERR_PDM_NO_DMAC_INSTANCE;
3095 }
3096 LogFlow(("pdmR3DevHlp_DMAWriteMemory: caller='%s'/%d: returns %Rrc\n",
3097 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3098 return rc;
3099}
3100
3101
3102/** @interface_method_impl{PDMDEVHLPR3,pfnDMASetDREQ} */
3103static DECLCALLBACK(int) pdmR3DevHlp_DMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
3104{
3105 PDMDEV_ASSERT_DEVINS(pDevIns);
3106 PVM pVM = pDevIns->Internal.s.pVMR3;
3107 VM_ASSERT_EMT(pVM);
3108 LogFlow(("pdmR3DevHlp_DMASetDREQ: caller='%s'/%d: uChannel=%d uLevel=%d\n",
3109 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, uLevel));
3110 int rc = VINF_SUCCESS;
3111 if (pVM->pdm.s.pDmac)
3112 pVM->pdm.s.pDmac->Reg.pfnSetDREQ(pVM->pdm.s.pDmac->pDevIns, uChannel, uLevel);
3113 else
3114 {
3115 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
3116 rc = VERR_PDM_NO_DMAC_INSTANCE;
3117 }
3118 LogFlow(("pdmR3DevHlp_DMASetDREQ: caller='%s'/%d: returns %Rrc\n",
3119 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3120 return rc;
3121}
3122
3123/** @interface_method_impl{PDMDEVHLPR3,pfnDMAGetChannelMode} */
3124static DECLCALLBACK(uint8_t) pdmR3DevHlp_DMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
3125{
3126 PDMDEV_ASSERT_DEVINS(pDevIns);
3127 PVM pVM = pDevIns->Internal.s.pVMR3;
3128 VM_ASSERT_EMT(pVM);
3129 LogFlow(("pdmR3DevHlp_DMAGetChannelMode: caller='%s'/%d: uChannel=%d\n",
3130 pDevIns->pReg->szName, pDevIns->iInstance, uChannel));
3131 uint8_t u8Mode;
3132 if (pVM->pdm.s.pDmac)
3133 u8Mode = pVM->pdm.s.pDmac->Reg.pfnGetChannelMode(pVM->pdm.s.pDmac->pDevIns, uChannel);
3134 else
3135 {
3136 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
3137 u8Mode = 3 << 2 /* illegal mode type */;
3138 }
3139 LogFlow(("pdmR3DevHlp_DMAGetChannelMode: caller='%s'/%d: returns %#04x\n",
3140 pDevIns->pReg->szName, pDevIns->iInstance, u8Mode));
3141 return u8Mode;
3142}
3143
3144/** @interface_method_impl{PDMDEVHLPR3,pfnDMASchedule} */
3145static DECLCALLBACK(void) pdmR3DevHlp_DMASchedule(PPDMDEVINS pDevIns)
3146{
3147 PDMDEV_ASSERT_DEVINS(pDevIns);
3148 PVM pVM = pDevIns->Internal.s.pVMR3;
3149 VM_ASSERT_EMT(pVM);
3150 LogFlow(("pdmR3DevHlp_DMASchedule: caller='%s'/%d: VM_FF_PDM_DMA %d -> 1\n",
3151 pDevIns->pReg->szName, pDevIns->iInstance, VM_FF_IS_SET(pVM, VM_FF_PDM_DMA)));
3152
3153 AssertMsg(pVM->pdm.s.pDmac, ("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
3154 VM_FF_SET(pVM, VM_FF_PDM_DMA);
3155 VMR3NotifyGlobalFFU(pVM->pUVM, VMNOTIFYFF_FLAGS_DONE_REM);
3156}
3157
3158
3159/** @interface_method_impl{PDMDEVHLPR3,pfnCMOSWrite} */
3160static DECLCALLBACK(int) pdmR3DevHlp_CMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
3161{
3162 PDMDEV_ASSERT_DEVINS(pDevIns);
3163 PVM pVM = pDevIns->Internal.s.pVMR3;
3164 VM_ASSERT_EMT(pVM);
3165
3166 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: iReg=%#04x u8Value=%#04x\n",
3167 pDevIns->pReg->szName, pDevIns->iInstance, iReg, u8Value));
3168 int rc;
3169 if (pVM->pdm.s.pRtc)
3170 {
3171 PPDMDEVINS pDevInsRtc = pVM->pdm.s.pRtc->pDevIns;
3172 rc = PDMCritSectEnter(pDevInsRtc->pCritSectRoR3, VERR_IGNORED);
3173 if (RT_SUCCESS(rc))
3174 {
3175 rc = pVM->pdm.s.pRtc->Reg.pfnWrite(pDevInsRtc, iReg, u8Value);
3176 PDMCritSectLeave(pDevInsRtc->pCritSectRoR3);
3177 }
3178 }
3179 else
3180 rc = VERR_PDM_NO_RTC_INSTANCE;
3181
3182 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: return %Rrc\n",
3183 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3184 return rc;
3185}
3186
3187
3188/** @interface_method_impl{PDMDEVHLPR3,pfnCMOSRead} */
3189static DECLCALLBACK(int) pdmR3DevHlp_CMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
3190{
3191 PDMDEV_ASSERT_DEVINS(pDevIns);
3192 PVM pVM = pDevIns->Internal.s.pVMR3;
3193 VM_ASSERT_EMT(pVM);
3194
3195 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: iReg=%#04x pu8Value=%p\n",
3196 pDevIns->pReg->szName, pDevIns->iInstance, iReg, pu8Value));
3197 int rc;
3198 if (pVM->pdm.s.pRtc)
3199 {
3200 PPDMDEVINS pDevInsRtc = pVM->pdm.s.pRtc->pDevIns;
3201 rc = PDMCritSectEnter(pDevInsRtc->pCritSectRoR3, VERR_IGNORED);
3202 if (RT_SUCCESS(rc))
3203 {
3204 rc = pVM->pdm.s.pRtc->Reg.pfnRead(pDevInsRtc, iReg, pu8Value);
3205 PDMCritSectLeave(pDevInsRtc->pCritSectRoR3);
3206 }
3207 }
3208 else
3209 rc = VERR_PDM_NO_RTC_INSTANCE;
3210
3211 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: return %Rrc\n",
3212 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3213 return rc;
3214}
3215
3216
3217/** @interface_method_impl{PDMDEVHLPR3,pfnAssertEMT} */
3218static DECLCALLBACK(bool) pdmR3DevHlp_AssertEMT(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction)
3219{
3220 PDMDEV_ASSERT_DEVINS(pDevIns);
3221 if (VM_IS_EMT(pDevIns->Internal.s.pVMR3))
3222 return true;
3223
3224 char szMsg[100];
3225 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance);
3226 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
3227 AssertBreakpoint();
3228 return false;
3229}
3230
3231
3232/** @interface_method_impl{PDMDEVHLPR3,pfnAssertOther} */
3233static DECLCALLBACK(bool) pdmR3DevHlp_AssertOther(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction)
3234{
3235 PDMDEV_ASSERT_DEVINS(pDevIns);
3236 if (!VM_IS_EMT(pDevIns->Internal.s.pVMR3))
3237 return true;
3238
3239 char szMsg[100];
3240 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance);
3241 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
3242 AssertBreakpoint();
3243 return false;
3244}
3245
3246
3247/** @interface_method_impl{PDMDEVHLPR3,pfnLdrGetRCInterfaceSymbols} */
3248static DECLCALLBACK(int) pdmR3DevHlp_LdrGetRCInterfaceSymbols(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3249 const char *pszSymPrefix, const char *pszSymList)
3250{
3251 PDMDEV_ASSERT_DEVINS(pDevIns);
3252 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3253 LogFlow(("pdmR3DevHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
3254 pDevIns->pReg->szName, pDevIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
3255
3256 int rc;
3257 if ( strncmp(pszSymPrefix, "dev", 3) == 0
3258 && RTStrIStr(pszSymPrefix + 3, pDevIns->pReg->szName) != NULL)
3259 {
3260 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
3261 rc = PDMR3LdrGetInterfaceSymbols(pDevIns->Internal.s.pVMR3,
3262 pvInterface, cbInterface,
3263 pDevIns->pReg->pszRCMod, pDevIns->Internal.s.pDevR3->pszRCSearchPath,
3264 pszSymPrefix, pszSymList,
3265 false /*fRing0OrRC*/);
3266 else
3267 {
3268 AssertMsgFailed(("Not a raw-mode enabled driver\n"));
3269 rc = VERR_PERMISSION_DENIED;
3270 }
3271 }
3272 else
3273 {
3274 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'dev' and contain the driver name!\n",
3275 pszSymPrefix, pDevIns->pReg->szName));
3276 rc = VERR_INVALID_NAME;
3277 }
3278
3279 LogFlow(("pdmR3DevHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
3280 pDevIns->iInstance, rc));
3281 return rc;
3282}
3283
3284
3285/** @interface_method_impl{PDMDEVHLPR3,pfnLdrGetR0InterfaceSymbols} */
3286static DECLCALLBACK(int) pdmR3DevHlp_LdrGetR0InterfaceSymbols(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3287 const char *pszSymPrefix, const char *pszSymList)
3288{
3289 PDMDEV_ASSERT_DEVINS(pDevIns);
3290 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3291 LogFlow(("pdmR3DevHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
3292 pDevIns->pReg->szName, pDevIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
3293
3294 int rc;
3295 if ( strncmp(pszSymPrefix, "dev", 3) == 0
3296 && RTStrIStr(pszSymPrefix + 3, pDevIns->pReg->szName) != NULL)
3297 {
3298 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
3299 rc = PDMR3LdrGetInterfaceSymbols(pDevIns->Internal.s.pVMR3,
3300 pvInterface, cbInterface,
3301 pDevIns->pReg->pszR0Mod, pDevIns->Internal.s.pDevR3->pszR0SearchPath,
3302 pszSymPrefix, pszSymList,
3303 true /*fRing0OrRC*/);
3304 else
3305 {
3306 AssertMsgFailed(("Not a ring-0 enabled driver\n"));
3307 rc = VERR_PERMISSION_DENIED;
3308 }
3309 }
3310 else
3311 {
3312 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'dev' and contain the driver name!\n",
3313 pszSymPrefix, pDevIns->pReg->szName));
3314 rc = VERR_INVALID_NAME;
3315 }
3316
3317 LogFlow(("pdmR3DevHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
3318 pDevIns->iInstance, rc));
3319 return rc;
3320}
3321
3322
3323/** @interface_method_impl{PDMDEVHLPR3,pfnCallR0} */
3324static DECLCALLBACK(int) pdmR3DevHlp_CallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
3325{
3326 PDMDEV_ASSERT_DEVINS(pDevIns);
3327 PVM pVM = pDevIns->Internal.s.pVMR3;
3328 PVMCPU pVCpu = VMMGetCpu(pVM);
3329 AssertReturn(pVCpu, VERR_VM_THREAD_IS_EMT);
3330 LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: uOperation=%#x u64Arg=%#RX64\n",
3331 pDevIns->pReg->szName, pDevIns->iInstance, uOperation, u64Arg));
3332
3333 /*
3334 * Resolve the ring-0 entry point. There is not need to remember this like
3335 * we do for drivers since this is mainly for construction time hacks and
3336 * other things that aren't performance critical.
3337 */
3338 int rc;
3339 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
3340 {
3341 /*
3342 * Make the ring-0 call.
3343 */
3344 PDMDEVICEGENCALLREQ Req;
3345 RT_ZERO(Req.Params);
3346 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
3347 Req.Hdr.cbReq = sizeof(Req);
3348 Req.pDevInsR3 = pDevIns;
3349 Req.idxR0Device = pDevIns->Internal.s.idxR0Device;
3350 Req.enmCall = PDMDEVICEGENCALL_REQUEST;
3351 Req.Params.Req.uReq = uOperation;
3352 Req.Params.Req.uArg = u64Arg;
3353 rc = VMMR3CallR0Emt(pVM, pVCpu, VMMR0_DO_PDM_DEVICE_GEN_CALL, 0, &Req.Hdr);
3354 }
3355 else
3356 rc = VERR_ACCESS_DENIED;
3357 LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
3358 pDevIns->iInstance, rc));
3359 return rc;
3360}
3361
3362
3363/** @interface_method_impl{PDMDEVHLPR3,pfnVMGetSuspendReason} */
3364static DECLCALLBACK(VMSUSPENDREASON) pdmR3DevHlp_VMGetSuspendReason(PPDMDEVINS pDevIns)
3365{
3366 PDMDEV_ASSERT_DEVINS(pDevIns);
3367 PVM pVM = pDevIns->Internal.s.pVMR3;
3368 VM_ASSERT_EMT(pVM);
3369 VMSUSPENDREASON enmReason = VMR3GetSuspendReason(pVM->pUVM);
3370 LogFlow(("pdmR3DevHlp_VMGetSuspendReason: caller='%s'/%d: returns %d\n",
3371 pDevIns->pReg->szName, pDevIns->iInstance, enmReason));
3372 return enmReason;
3373}
3374
3375
3376/** @interface_method_impl{PDMDEVHLPR3,pfnVMGetResumeReason} */
3377static DECLCALLBACK(VMRESUMEREASON) pdmR3DevHlp_VMGetResumeReason(PPDMDEVINS pDevIns)
3378{
3379 PDMDEV_ASSERT_DEVINS(pDevIns);
3380 PVM pVM = pDevIns->Internal.s.pVMR3;
3381 VM_ASSERT_EMT(pVM);
3382 VMRESUMEREASON enmReason = VMR3GetResumeReason(pVM->pUVM);
3383 LogFlow(("pdmR3DevHlp_VMGetResumeReason: caller='%s'/%d: returns %d\n",
3384 pDevIns->pReg->szName, pDevIns->iInstance, enmReason));
3385 return enmReason;
3386}
3387
3388
3389/** @interface_method_impl{PDMDEVHLPR3,pfnGetUVM} */
3390static DECLCALLBACK(PUVM) pdmR3DevHlp_GetUVM(PPDMDEVINS pDevIns)
3391{
3392 PDMDEV_ASSERT_DEVINS(pDevIns);
3393 LogFlow(("pdmR3DevHlp_GetUVM: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns->Internal.s.pVMR3));
3394 return pDevIns->Internal.s.pVMR3->pUVM;
3395}
3396
3397
3398/** @interface_method_impl{PDMDEVHLPR3,pfnGetVM} */
3399static DECLCALLBACK(PVM) pdmR3DevHlp_GetVM(PPDMDEVINS pDevIns)
3400{
3401 PDMDEV_ASSERT_DEVINS(pDevIns);
3402 LogFlow(("pdmR3DevHlp_GetVM: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns->Internal.s.pVMR3));
3403 return pDevIns->Internal.s.pVMR3;
3404}
3405
3406
3407/** @interface_method_impl{PDMDEVHLPR3,pfnGetVMCPU} */
3408static DECLCALLBACK(PVMCPU) pdmR3DevHlp_GetVMCPU(PPDMDEVINS pDevIns)
3409{
3410 PDMDEV_ASSERT_DEVINS(pDevIns);
3411 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3412 LogFlow(("pdmR3DevHlp_GetVMCPU: caller='%s'/%d for CPU %u\n", pDevIns->pReg->szName, pDevIns->iInstance, VMMGetCpuId(pDevIns->Internal.s.pVMR3)));
3413 return VMMGetCpu(pDevIns->Internal.s.pVMR3);
3414}
3415
3416
3417/** @interface_method_impl{PDMDEVHLPR3,pfnGetCurrentCpuId} */
3418static DECLCALLBACK(VMCPUID) pdmR3DevHlp_GetCurrentCpuId(PPDMDEVINS pDevIns)
3419{
3420 PDMDEV_ASSERT_DEVINS(pDevIns);
3421 VMCPUID idCpu = VMMGetCpuId(pDevIns->Internal.s.pVMR3);
3422 LogFlow(("pdmR3DevHlp_GetCurrentCpuId: caller='%s'/%d for CPU %u\n", pDevIns->pReg->szName, pDevIns->iInstance, idCpu));
3423 return idCpu;
3424}
3425
3426
3427/** @interface_method_impl{PDMDEVHLPR3,pfnPCIBusRegister} */
3428static DECLCALLBACK(int) pdmR3DevHlp_PCIBusRegister(PPDMDEVINS pDevIns, PPDMPCIBUSREGR3 pPciBusReg,
3429 PCPDMPCIHLPR3 *ppPciHlp, uint32_t *piBus)
3430{
3431 PDMDEV_ASSERT_DEVINS(pDevIns);
3432 PVM pVM = pDevIns->Internal.s.pVMR3;
3433 VM_ASSERT_EMT(pVM);
3434 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: pPciBusReg=%p:{.u32Version=%#x, .pfnRegisterR3=%p, .pfnIORegionRegisterR3=%p, "
3435 ".pfnInterceptConfigAccesses=%p, pfnConfigRead=%p, pfnConfigWrite=%p, .pfnSetIrqR3=%p, .u32EndVersion=%#x} ppPciHlpR3=%p piBus=%p\n",
3436 pDevIns->pReg->szName, pDevIns->iInstance, pPciBusReg, pPciBusReg->u32Version, pPciBusReg->pfnRegisterR3,
3437 pPciBusReg->pfnIORegionRegisterR3, pPciBusReg->pfnInterceptConfigAccesses, pPciBusReg->pfnConfigRead,
3438 pPciBusReg->pfnConfigWrite, pPciBusReg->pfnSetIrqR3, pPciBusReg->u32EndVersion, ppPciHlp, piBus));
3439
3440 /*
3441 * Validate the structure and output parameters.
3442 */
3443 AssertLogRelMsgReturn(pPciBusReg->u32Version == PDM_PCIBUSREGR3_VERSION,
3444 ("u32Version=%#x expected %#x\n", pPciBusReg->u32Version, PDM_PCIBUSREGR3_VERSION),
3445 VERR_INVALID_PARAMETER);
3446 AssertPtrReturn(pPciBusReg->pfnRegisterR3, VERR_INVALID_PARAMETER);
3447 AssertPtrNullReturn(pPciBusReg->pfnRegisterMsiR3, VERR_INVALID_POINTER);
3448 AssertPtrReturn(pPciBusReg->pfnIORegionRegisterR3, VERR_INVALID_POINTER);
3449 AssertPtrReturn(pPciBusReg->pfnInterceptConfigAccesses, VERR_INVALID_POINTER);
3450 AssertPtrReturn(pPciBusReg->pfnConfigWrite, VERR_INVALID_POINTER);
3451 AssertPtrReturn(pPciBusReg->pfnConfigRead, VERR_INVALID_POINTER);
3452 AssertPtrReturn(pPciBusReg->pfnSetIrqR3, VERR_INVALID_POINTER);
3453 AssertLogRelMsgReturn(pPciBusReg->u32EndVersion == PDM_PCIBUSREGR3_VERSION,
3454 ("u32Version=%#x expected %#x\n", pPciBusReg->u32Version, PDM_PCIBUSREGR3_VERSION),
3455 VERR_INVALID_PARAMETER);
3456 AssertPtrReturn(ppPciHlp, VERR_INVALID_POINTER);
3457 AssertPtrNullReturn(piBus, VERR_INVALID_POINTER);
3458 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
3459
3460 /*
3461 * Find free PCI bus entry.
3462 */
3463 unsigned iBus = 0;
3464 for (iBus = 0; iBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses); iBus++)
3465 if (!pVM->pdm.s.aPciBuses[iBus].pDevInsR3)
3466 break;
3467 AssertLogRelMsgReturn(iBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses),
3468 ("Too many PCI buses. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aPciBuses)),
3469 VERR_OUT_OF_RESOURCES);
3470 PPDMPCIBUS pPciBus = &pVM->pdm.s.aPciBuses[iBus];
3471
3472 /*
3473 * Init the R3 bits.
3474 */
3475 pPciBus->iBus = iBus;
3476 pPciBus->pDevInsR3 = pDevIns;
3477 pPciBus->pfnRegister = pPciBusReg->pfnRegisterR3;
3478 pPciBus->pfnRegisterMsi = pPciBusReg->pfnRegisterMsiR3;
3479 pPciBus->pfnIORegionRegister = pPciBusReg->pfnIORegionRegisterR3;
3480 pPciBus->pfnInterceptConfigAccesses = pPciBusReg->pfnInterceptConfigAccesses;
3481 pPciBus->pfnConfigRead = pPciBusReg->pfnConfigRead;
3482 pPciBus->pfnConfigWrite = pPciBusReg->pfnConfigWrite;
3483 pPciBus->pfnSetIrqR3 = pPciBusReg->pfnSetIrqR3;
3484
3485 Log(("PDM: Registered PCI bus device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3486
3487 /* set the helper pointer and return. */
3488 *ppPciHlp = &g_pdmR3DevPciHlp;
3489 if (piBus)
3490 *piBus = iBus;
3491 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc *piBus=%u\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS, iBus));
3492 return VINF_SUCCESS;
3493}
3494
3495
3496/** @interface_method_impl{PDMDEVHLPR3,pfnIommuRegister} */
3497static DECLCALLBACK(int) pdmR3DevHlp_IommuRegister(PPDMDEVINS pDevIns, PPDMIOMMUREGR3 pIommuReg, PCPDMIOMMUHLPR3 *ppIommuHlp,
3498 uint32_t *pidxIommu)
3499{
3500 PDMDEV_ASSERT_DEVINS(pDevIns);
3501 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3502 LogFlow(("pdmR3DevHlp_IommuRegister: caller='%s'/%d: pIommuReg=%p:{.u32Version=%#x, .u32TheEnd=%#x } ppIommuHlp=%p\n",
3503 pDevIns->pReg->szName, pDevIns->iInstance, pIommuReg, pIommuReg->u32Version, pIommuReg->u32TheEnd, ppIommuHlp));
3504 PVM pVM = pDevIns->Internal.s.pVMR3;
3505
3506 /*
3507 * Validate input.
3508 */
3509 AssertMsgReturn(pIommuReg->u32Version == PDM_IOMMUREGR3_VERSION,
3510 ("%s/%d: u32Version=%#x expected %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, pIommuReg->u32Version, PDM_IOMMUREGR3_VERSION),
3511 VERR_INVALID_PARAMETER);
3512 AssertPtrReturn(pIommuReg->pfnMemAccess, VERR_INVALID_POINTER);
3513 AssertPtrReturn(pIommuReg->pfnMemBulkAccess, VERR_INVALID_POINTER);
3514 AssertPtrReturn(pIommuReg->pfnMsiRemap, VERR_INVALID_POINTER);
3515 AssertMsgReturn(pIommuReg->u32TheEnd == PDM_IOMMUREGR3_VERSION,
3516 ("%s/%d: u32TheEnd=%#x expected %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, pIommuReg->u32TheEnd, PDM_IOMMUREGR3_VERSION),
3517 VERR_INVALID_PARAMETER);
3518 AssertPtrReturn(ppIommuHlp, VERR_INVALID_POINTER);
3519
3520 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
3521 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
3522
3523 /*
3524 * Find free IOMMU slot.
3525 * The IOMMU at the root complex is the one at 0.
3526 */
3527 unsigned idxIommu = 0;
3528#if 0
3529 for (idxIommu = 0; idxIommu < RT_ELEMENTS(pVM->pdm.s.aIommus); idxIommu++)
3530 if (!pVM->pdm.s.aIommus[idxIommu].pDevInsR3)
3531 break;
3532 AssertLogRelMsgReturn(idxIommu < RT_ELEMENTS(pVM->pdm.s.aIommus),
3533 ("Too many IOMMUs. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aIommus)),
3534 VERR_OUT_OF_RESOURCES);
3535#else
3536 /* Currently we support only a single IOMMU. */
3537 AssertMsgReturn(!pVM->pdm.s.aIommus[0].pDevInsR3,
3538 ("%s/%u: Only one IOMMU device is supported!\n", pDevIns->pReg->szName, pDevIns->iInstance),
3539 VERR_ALREADY_EXISTS);
3540#endif
3541 PPDMIOMMUR3 pIommu = &pVM->pdm.s.aIommus[idxIommu];
3542
3543 /*
3544 * Init the R3 bits.
3545 */
3546 pIommu->idxIommu = idxIommu;
3547 pIommu->pDevInsR3 = pDevIns;
3548 pIommu->pfnMemAccess = pIommuReg->pfnMemAccess;
3549 pIommu->pfnMemBulkAccess = pIommuReg->pfnMemBulkAccess;
3550 pIommu->pfnMsiRemap = pIommuReg->pfnMsiRemap;
3551 Log(("PDM: Registered IOMMU device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3552
3553 /* Set the helper pointer and return. */
3554 *ppIommuHlp = &g_pdmR3DevIommuHlp;
3555 if (pidxIommu)
3556 *pidxIommu = idxIommu;
3557 LogFlow(("pdmR3DevHlp_IommuRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3558 return VINF_SUCCESS;
3559}
3560
3561
3562
3563/** @interface_method_impl{PDMDEVHLPR3,pfnPICRegister} */
3564static DECLCALLBACK(int) pdmR3DevHlp_PICRegister(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLP *ppPicHlp)
3565{
3566 PDMDEV_ASSERT_DEVINS(pDevIns);
3567 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3568 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: pPicReg=%p:{.u32Version=%#x, .pfnSetIrq=%p, .pfnGetInterrupt=%p, .u32TheEnd=%#x } ppPicHlp=%p\n",
3569 pDevIns->pReg->szName, pDevIns->iInstance, pPicReg, pPicReg->u32Version, pPicReg->pfnSetIrq, pPicReg->pfnGetInterrupt, pPicReg->u32TheEnd, ppPicHlp));
3570 PVM pVM = pDevIns->Internal.s.pVMR3;
3571
3572 /*
3573 * Validate input.
3574 */
3575 AssertMsgReturn(pPicReg->u32Version == PDM_PICREG_VERSION,
3576 ("%s/%d: u32Version=%#x expected %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, pPicReg->u32Version, PDM_PICREG_VERSION),
3577 VERR_INVALID_PARAMETER);
3578 AssertPtrReturn(pPicReg->pfnSetIrq, VERR_INVALID_POINTER);
3579 AssertPtrReturn(pPicReg->pfnGetInterrupt, VERR_INVALID_POINTER);
3580 AssertMsgReturn(pPicReg->u32TheEnd == PDM_PICREG_VERSION,
3581 ("%s/%d: u32TheEnd=%#x expected %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, pPicReg->u32TheEnd, PDM_PICREG_VERSION),
3582 VERR_INVALID_PARAMETER);
3583 AssertPtrReturn(ppPicHlp, VERR_INVALID_POINTER);
3584
3585 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
3586 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
3587
3588 /*
3589 * Only one PIC device.
3590 */
3591 AssertMsgReturn(pVM->pdm.s.Pic.pDevInsR3 == NULL, ("%s/%d: Only one PIC!\n", pDevIns->pReg->szName, pDevIns->iInstance),
3592 VERR_ALREADY_EXISTS);
3593
3594 /*
3595 * Take down the callbacks and instance.
3596 */
3597 pVM->pdm.s.Pic.pDevInsR3 = pDevIns;
3598 pVM->pdm.s.Pic.pfnSetIrqR3 = pPicReg->pfnSetIrq;
3599 pVM->pdm.s.Pic.pfnGetInterruptR3 = pPicReg->pfnGetInterrupt;
3600 Log(("PDM: Registered PIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3601
3602 /* set the helper pointer and return. */
3603 *ppPicHlp = &g_pdmR3DevPicHlp;
3604 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3605 return VINF_SUCCESS;
3606}
3607
3608
3609/** @interface_method_impl{PDMDEVHLPR3,pfnApicRegister} */
3610static DECLCALLBACK(int) pdmR3DevHlp_ApicRegister(PPDMDEVINS pDevIns)
3611{
3612 PDMDEV_ASSERT_DEVINS(pDevIns);
3613
3614 /*
3615 * Validate caller context.
3616 */
3617 PVM pVM = pDevIns->Internal.s.pVMR3;
3618 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
3619 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
3620
3621 /*
3622 * Only one APIC device. On SMP we have single logical device covering all LAPICs,
3623 * as they need to communicate and share state easily.
3624 */
3625 AssertMsgReturn(pVM->pdm.s.Apic.pDevInsR3 == NULL,
3626 ("%s/%u: Only one APIC device is supported!\n", pDevIns->pReg->szName, pDevIns->iInstance),
3627 VERR_ALREADY_EXISTS);
3628
3629 /*
3630 * Set the ring-3 and raw-mode bits, leave the ring-0 to ring-0 setup.
3631 */
3632 pVM->pdm.s.Apic.pDevInsR3 = pDevIns;
3633 pVM->pdm.s.Apic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
3634 Assert(pVM->pdm.s.Apic.pDevInsRC || !VM_IS_RAW_MODE_ENABLED(pVM));
3635
3636 LogFlow(("pdmR3DevHlp_ApicRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3637 return VINF_SUCCESS;
3638}
3639
3640
3641/** @interface_method_impl{PDMDEVHLPR3,pfnIoApicRegister} */
3642static DECLCALLBACK(int) pdmR3DevHlp_IoApicRegister(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLP *ppIoApicHlp)
3643{
3644 PDMDEV_ASSERT_DEVINS(pDevIns);
3645 LogFlow(("pdmR3DevHlp_IoApicRegister: caller='%s'/%d: pIoApicReg=%p:{.u32Version=%#x, .pfnSetIrq=%p, .pfnSendMsi=%p, .pfnSetEoi=%p, .u32TheEnd=%#x } ppIoApicHlp=%p\n",
3646 pDevIns->pReg->szName, pDevIns->iInstance, pIoApicReg, pIoApicReg->u32Version, pIoApicReg->pfnSetIrq, pIoApicReg->pfnSendMsi, pIoApicReg->pfnSetEoi, pIoApicReg->u32TheEnd, ppIoApicHlp));
3647 PVM pVM = pDevIns->Internal.s.pVMR3;
3648
3649 /*
3650 * Validate input.
3651 */
3652 AssertMsgReturn(pIoApicReg->u32Version == PDM_IOAPICREG_VERSION,
3653 ("%s/%d: u32Version=%#x expected %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, pIoApicReg->u32Version, PDM_IOAPICREG_VERSION),
3654 VERR_VERSION_MISMATCH);
3655 AssertPtrReturn(pIoApicReg->pfnSetIrq, VERR_INVALID_POINTER);
3656 AssertPtrReturn(pIoApicReg->pfnSendMsi, VERR_INVALID_POINTER);
3657 AssertPtrReturn(pIoApicReg->pfnSetEoi, VERR_INVALID_POINTER);
3658 AssertMsgReturn(pIoApicReg->u32TheEnd == PDM_IOAPICREG_VERSION,
3659 ("%s/%d: u32TheEnd=%#x expected %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, pIoApicReg->u32TheEnd, PDM_IOAPICREG_VERSION),
3660 VERR_VERSION_MISMATCH);
3661 AssertPtrReturn(ppIoApicHlp, VERR_INVALID_POINTER);
3662 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
3663 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
3664
3665 /*
3666 * The I/O APIC requires the APIC to be present (hacks++).
3667 * If the I/O APIC does GC stuff so must the APIC.
3668 */
3669 AssertMsgReturn(pVM->pdm.s.Apic.pDevInsR3 != NULL, ("Configuration error / Init order error! No APIC!\n"), VERR_WRONG_ORDER);
3670
3671 /*
3672 * Only one I/O APIC device.
3673 */
3674 AssertMsgReturn(pVM->pdm.s.IoApic.pDevInsR3 == NULL,
3675 ("Only one IOAPIC device is supported! (caller %s/%d)\n", pDevIns->pReg->szName, pDevIns->iInstance),
3676 VERR_ALREADY_EXISTS);
3677
3678 /*
3679 * Initialize the R3 bits.
3680 */
3681 pVM->pdm.s.IoApic.pDevInsR3 = pDevIns;
3682 pVM->pdm.s.IoApic.pfnSetIrqR3 = pIoApicReg->pfnSetIrq;
3683 pVM->pdm.s.IoApic.pfnSendMsiR3 = pIoApicReg->pfnSendMsi;
3684 pVM->pdm.s.IoApic.pfnSetEoiR3 = pIoApicReg->pfnSetEoi;
3685 Log(("PDM: Registered I/O APIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3686
3687 /* set the helper pointer and return. */
3688 *ppIoApicHlp = &g_pdmR3DevIoApicHlp;
3689 LogFlow(("pdmR3DevHlp_IoApicRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3690 return VINF_SUCCESS;
3691}
3692
3693
3694/** @interface_method_impl{PDMDEVHLPR3,pfnHpetRegister} */
3695static DECLCALLBACK(int) pdmR3DevHlp_HpetRegister(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3)
3696{
3697 PDMDEV_ASSERT_DEVINS(pDevIns);
3698 LogFlow(("pdmR3DevHlp_HpetRegister: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
3699 PVM pVM = pDevIns->Internal.s.pVMR3;
3700
3701 /*
3702 * Validate input.
3703 */
3704 AssertMsgReturn(pHpetReg->u32Version == PDM_HPETREG_VERSION,
3705 ("%s/%u: u32Version=%#x expected %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, pHpetReg->u32Version, PDM_HPETREG_VERSION),
3706 VERR_VERSION_MISMATCH);
3707 AssertPtrReturn(ppHpetHlpR3, VERR_INVALID_POINTER);
3708 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
3709 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
3710
3711 /*
3712 * Only one HPET device.
3713 */
3714 AssertMsgReturn(pVM->pdm.s.pHpet == NULL,
3715 ("Only one HPET device is supported! (caller %s/%d)\n", pDevIns->pReg->szName, pDevIns->iInstance),
3716 VERR_ALREADY_EXISTS);
3717
3718 /*
3719 * Do the job (what there is of it).
3720 */
3721 pVM->pdm.s.pHpet = pDevIns;
3722 *ppHpetHlpR3 = &g_pdmR3DevHpetHlp;
3723
3724 LogFlow(("pdmR3DevHlp_HpetRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3725 return VINF_SUCCESS;
3726}
3727
3728
3729/** @interface_method_impl{PDMDEVHLPR3,pfnPciRawRegister} */
3730static DECLCALLBACK(int) pdmR3DevHlp_PciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
3731{
3732 PDMDEV_ASSERT_DEVINS(pDevIns); RT_NOREF_PV(pDevIns);
3733 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3734 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
3735
3736 /*
3737 * Validate input.
3738 */
3739 if (pPciRawReg->u32Version != PDM_PCIRAWREG_VERSION)
3740 {
3741 AssertMsgFailed(("u32Version=%#x expected %#x\n", pPciRawReg->u32Version, PDM_PCIRAWREG_VERSION));
3742 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3743 return VERR_INVALID_PARAMETER;
3744 }
3745
3746 if (!ppPciRawHlpR3)
3747 {
3748 Assert(ppPciRawHlpR3);
3749 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc (ppPciRawHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3750 return VERR_INVALID_PARAMETER;
3751 }
3752
3753 /* set the helper pointer and return. */
3754 *ppPciRawHlpR3 = &g_pdmR3DevPciRawHlp;
3755 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3756 return VINF_SUCCESS;
3757}
3758
3759
3760/** @interface_method_impl{PDMDEVHLPR3,pfnDMACRegister} */
3761static DECLCALLBACK(int) pdmR3DevHlp_DMACRegister(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp)
3762{
3763 PDMDEV_ASSERT_DEVINS(pDevIns);
3764 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3765 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: pDmacReg=%p:{.u32Version=%#x, .pfnRun=%p, .pfnRegister=%p, .pfnReadMemory=%p, .pfnWriteMemory=%p, .pfnSetDREQ=%p, .pfnGetChannelMode=%p} ppDmacHlp=%p\n",
3766 pDevIns->pReg->szName, pDevIns->iInstance, pDmacReg, pDmacReg->u32Version, pDmacReg->pfnRun, pDmacReg->pfnRegister,
3767 pDmacReg->pfnReadMemory, pDmacReg->pfnWriteMemory, pDmacReg->pfnSetDREQ, pDmacReg->pfnGetChannelMode, ppDmacHlp));
3768
3769 /*
3770 * Validate input.
3771 */
3772 if (pDmacReg->u32Version != PDM_DMACREG_VERSION)
3773 {
3774 AssertMsgFailed(("u32Version=%#x expected %#x\n", pDmacReg->u32Version,
3775 PDM_DMACREG_VERSION));
3776 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (version)\n",
3777 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3778 return VERR_INVALID_PARAMETER;
3779 }
3780 if ( !pDmacReg->pfnRun
3781 || !pDmacReg->pfnRegister
3782 || !pDmacReg->pfnReadMemory
3783 || !pDmacReg->pfnWriteMemory
3784 || !pDmacReg->pfnSetDREQ
3785 || !pDmacReg->pfnGetChannelMode)
3786 {
3787 Assert(pDmacReg->pfnRun);
3788 Assert(pDmacReg->pfnRegister);
3789 Assert(pDmacReg->pfnReadMemory);
3790 Assert(pDmacReg->pfnWriteMemory);
3791 Assert(pDmacReg->pfnSetDREQ);
3792 Assert(pDmacReg->pfnGetChannelMode);
3793 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (callbacks)\n",
3794 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3795 return VERR_INVALID_PARAMETER;
3796 }
3797
3798 if (!ppDmacHlp)
3799 {
3800 Assert(ppDmacHlp);
3801 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (ppDmacHlp)\n",
3802 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3803 return VERR_INVALID_PARAMETER;
3804 }
3805
3806 /*
3807 * Only one DMA device.
3808 */
3809 PVM pVM = pDevIns->Internal.s.pVMR3;
3810 if (pVM->pdm.s.pDmac)
3811 {
3812 AssertMsgFailed(("Only one DMA device is supported!\n"));
3813 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n",
3814 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3815 return VERR_INVALID_PARAMETER;
3816 }
3817
3818 /*
3819 * Allocate and initialize pci bus structure.
3820 */
3821 int rc = VINF_SUCCESS;
3822 PPDMDMAC pDmac = (PPDMDMAC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pDmac));
3823 if (pDmac)
3824 {
3825 pDmac->pDevIns = pDevIns;
3826 pDmac->Reg = *pDmacReg;
3827 pVM->pdm.s.pDmac = pDmac;
3828
3829 /* set the helper pointer. */
3830 *ppDmacHlp = &g_pdmR3DevDmacHlp;
3831 Log(("PDM: Registered DMAC device '%s'/%d pDevIns=%p\n",
3832 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3833 }
3834 else
3835 rc = VERR_NO_MEMORY;
3836
3837 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n",
3838 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3839 return rc;
3840}
3841
3842
3843/**
3844 * @copydoc PDMDEVHLPR3::pfnRegisterVMMDevHeap
3845 */
3846static DECLCALLBACK(int) pdmR3DevHlp_RegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbHeap)
3847{
3848 PDMDEV_ASSERT_DEVINS(pDevIns);
3849 PVM pVM = pDevIns->Internal.s.pVMR3;
3850 VM_ASSERT_EMT(pVM);
3851 LogFlow(("pdmR3DevHlp_RegisterVMMDevHeap: caller='%s'/%d: GCPhys=%RGp pvHeap=%p cbHeap=%#x\n",
3852 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, pvHeap, cbHeap));
3853
3854 if (pVM->pdm.s.pvVMMDevHeap == NULL)
3855 {
3856 pVM->pdm.s.pvVMMDevHeap = pvHeap;
3857 pVM->pdm.s.GCPhysVMMDevHeap = GCPhys;
3858 pVM->pdm.s.cbVMMDevHeap = cbHeap;
3859 pVM->pdm.s.cbVMMDevHeapLeft = cbHeap;
3860 }
3861 else
3862 {
3863 Assert(pVM->pdm.s.pvVMMDevHeap == pvHeap);
3864 Assert(pVM->pdm.s.cbVMMDevHeap == cbHeap);
3865 Assert(pVM->pdm.s.GCPhysVMMDevHeap != GCPhys || GCPhys == NIL_RTGCPHYS);
3866 if (pVM->pdm.s.GCPhysVMMDevHeap != GCPhys)
3867 {
3868 pVM->pdm.s.GCPhysVMMDevHeap = GCPhys;
3869 if (pVM->pdm.s.pfnVMMDevHeapNotify)
3870 pVM->pdm.s.pfnVMMDevHeapNotify(pVM, pvHeap, GCPhys);
3871 }
3872 }
3873
3874 LogFlow(("pdmR3DevHlp_RegisterVMMDevHeap: caller='%s'/%d: returns %Rrc\n",
3875 pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3876 return VINF_SUCCESS;
3877}
3878
3879
3880/**
3881 * @interface_method_impl{PDMDEVHLPR3,pfnFirmwareRegister}
3882 */
3883static DECLCALLBACK(int) pdmR3DevHlp_FirmwareRegister(PPDMDEVINS pDevIns, PCPDMFWREG pFwReg, PCPDMFWHLPR3 *ppFwHlp)
3884{
3885 PDMDEV_ASSERT_DEVINS(pDevIns);
3886 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3887 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: pFWReg=%p:{.u32Version=%#x, .pfnIsHardReset=%p, .u32TheEnd=%#x} ppFwHlp=%p\n",
3888 pDevIns->pReg->szName, pDevIns->iInstance, pFwReg, pFwReg->u32Version, pFwReg->pfnIsHardReset, pFwReg->u32TheEnd, ppFwHlp));
3889
3890 /*
3891 * Validate input.
3892 */
3893 if (pFwReg->u32Version != PDM_FWREG_VERSION)
3894 {
3895 AssertMsgFailed(("u32Version=%#x expected %#x\n", pFwReg->u32Version, PDM_FWREG_VERSION));
3896 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: returns %Rrc (version)\n",
3897 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3898 return VERR_INVALID_PARAMETER;
3899 }
3900 if (!pFwReg->pfnIsHardReset)
3901 {
3902 Assert(pFwReg->pfnIsHardReset);
3903 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: returns %Rrc (callbacks)\n",
3904 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3905 return VERR_INVALID_PARAMETER;
3906 }
3907
3908 if (!ppFwHlp)
3909 {
3910 Assert(ppFwHlp);
3911 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: returns %Rrc (ppFwHlp)\n",
3912 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3913 return VERR_INVALID_PARAMETER;
3914 }
3915
3916 /*
3917 * Only one DMA device.
3918 */
3919 PVM pVM = pDevIns->Internal.s.pVMR3;
3920 if (pVM->pdm.s.pFirmware)
3921 {
3922 AssertMsgFailed(("Only one firmware device is supported!\n"));
3923 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: returns %Rrc\n",
3924 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3925 return VERR_INVALID_PARAMETER;
3926 }
3927
3928 /*
3929 * Allocate and initialize pci bus structure.
3930 */
3931 int rc = VINF_SUCCESS;
3932 PPDMFW pFirmware = (PPDMFW)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pFirmware));
3933 if (pFirmware)
3934 {
3935 pFirmware->pDevIns = pDevIns;
3936 pFirmware->Reg = *pFwReg;
3937 pVM->pdm.s.pFirmware = pFirmware;
3938
3939 /* set the helper pointer. */
3940 *ppFwHlp = &g_pdmR3DevFirmwareHlp;
3941 Log(("PDM: Registered firmware device '%s'/%d pDevIns=%p\n",
3942 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3943 }
3944 else
3945 rc = VERR_NO_MEMORY;
3946
3947 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: returns %Rrc\n",
3948 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3949 return rc;
3950}
3951
3952
3953/** @interface_method_impl{PDMDEVHLPR3,pfnVMReset} */
3954static DECLCALLBACK(int) pdmR3DevHlp_VMReset(PPDMDEVINS pDevIns, uint32_t fFlags)
3955{
3956 PDMDEV_ASSERT_DEVINS(pDevIns);
3957 PVM pVM = pDevIns->Internal.s.pVMR3;
3958 VM_ASSERT_EMT(pVM);
3959 LogFlow(("pdmR3DevHlp_VMReset: caller='%s'/%d: fFlags=%#x VM_FF_RESET %d -> 1\n",
3960 pDevIns->pReg->szName, pDevIns->iInstance, fFlags, VM_FF_IS_SET(pVM, VM_FF_RESET)));
3961
3962 /*
3963 * We postpone this operation because we're likely to be inside a I/O instruction
3964 * and the EIP will be updated when we return.
3965 * We still return VINF_EM_RESET to break out of any execution loops and force FF evaluation.
3966 */
3967 bool fHaltOnReset;
3968 int rc = CFGMR3QueryBool(CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM"), "HaltOnReset", &fHaltOnReset);
3969 if (RT_SUCCESS(rc) && fHaltOnReset)
3970 {
3971 Log(("pdmR3DevHlp_VMReset: Halt On Reset!\n"));
3972 rc = VINF_EM_HALT;
3973 }
3974 else
3975 {
3976 pVM->pdm.s.fResetFlags = fFlags;
3977 VM_FF_SET(pVM, VM_FF_RESET);
3978 rc = VINF_EM_RESET;
3979 }
3980
3981 LogFlow(("pdmR3DevHlp_VMReset: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3982 return rc;
3983}
3984
3985
3986/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspend} */
3987static DECLCALLBACK(int) pdmR3DevHlp_VMSuspend(PPDMDEVINS pDevIns)
3988{
3989 int rc;
3990 PDMDEV_ASSERT_DEVINS(pDevIns);
3991 PVM pVM = pDevIns->Internal.s.pVMR3;
3992 VM_ASSERT_EMT(pVM);
3993 LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d:\n",
3994 pDevIns->pReg->szName, pDevIns->iInstance));
3995
3996 /** @todo Always take the SMP path - fewer code paths. */
3997 if (pVM->cCpus > 1)
3998 {
3999 /* We own the IOM lock here and could cause a deadlock by waiting for a VCPU that is blocking on the IOM lock. */
4000 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3Suspend, 2, pVM->pUVM, VMSUSPENDREASON_VM);
4001 AssertRC(rc);
4002 rc = VINF_EM_SUSPEND;
4003 }
4004 else
4005 rc = VMR3Suspend(pVM->pUVM, VMSUSPENDREASON_VM);
4006
4007 LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
4008 return rc;
4009}
4010
4011
4012/**
4013 * Worker for pdmR3DevHlp_VMSuspendSaveAndPowerOff that is invoked via a queued
4014 * EMT request to avoid deadlocks.
4015 *
4016 * @returns VBox status code fit for scheduling.
4017 * @param pVM The cross context VM structure.
4018 * @param pDevIns The device that triggered this action.
4019 */
4020static DECLCALLBACK(int) pdmR3DevHlp_VMSuspendSaveAndPowerOffWorker(PVM pVM, PPDMDEVINS pDevIns)
4021{
4022 /*
4023 * Suspend the VM first then do the saving.
4024 */
4025 int rc = VMR3Suspend(pVM->pUVM, VMSUSPENDREASON_VM);
4026 if (RT_SUCCESS(rc))
4027 {
4028 PUVM pUVM = pVM->pUVM;
4029 rc = pUVM->pVmm2UserMethods->pfnSaveState(pVM->pUVM->pVmm2UserMethods, pUVM);
4030
4031 /*
4032 * On success, power off the VM, on failure we'll leave it suspended.
4033 */
4034 if (RT_SUCCESS(rc))
4035 {
4036 rc = VMR3PowerOff(pVM->pUVM);
4037 if (RT_FAILURE(rc))
4038 LogRel(("%s/SSP: VMR3PowerOff failed: %Rrc\n", pDevIns->pReg->szName, rc));
4039 }
4040 else
4041 LogRel(("%s/SSP: pfnSaveState failed: %Rrc\n", pDevIns->pReg->szName, rc));
4042 }
4043 else
4044 LogRel(("%s/SSP: Suspend failed: %Rrc\n", pDevIns->pReg->szName, rc));
4045 return rc;
4046}
4047
4048
4049/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
4050static DECLCALLBACK(int) pdmR3DevHlp_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
4051{
4052 PDMDEV_ASSERT_DEVINS(pDevIns);
4053 PVM pVM = pDevIns->Internal.s.pVMR3;
4054 VM_ASSERT_EMT(pVM);
4055 LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d:\n",
4056 pDevIns->pReg->szName, pDevIns->iInstance));
4057
4058 int rc;
4059 if ( pVM->pUVM->pVmm2UserMethods
4060 && pVM->pUVM->pVmm2UserMethods->pfnSaveState)
4061 {
4062 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)pdmR3DevHlp_VMSuspendSaveAndPowerOffWorker, 2, pVM, pDevIns);
4063 if (RT_SUCCESS(rc))
4064 {
4065 LogRel(("%s: Suspending, Saving and Powering Off the VM\n", pDevIns->pReg->szName));
4066 rc = VINF_EM_SUSPEND;
4067 }
4068 }
4069 else
4070 rc = VERR_NOT_SUPPORTED;
4071
4072 LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
4073 return rc;
4074}
4075
4076
4077/** @interface_method_impl{PDMDEVHLPR3,pfnVMPowerOff} */
4078static DECLCALLBACK(int) pdmR3DevHlp_VMPowerOff(PPDMDEVINS pDevIns)
4079{
4080 int rc;
4081 PDMDEV_ASSERT_DEVINS(pDevIns);
4082 PVM pVM = pDevIns->Internal.s.pVMR3;
4083 VM_ASSERT_EMT(pVM);
4084 LogFlow(("pdmR3DevHlp_VMPowerOff: caller='%s'/%d:\n",
4085 pDevIns->pReg->szName, pDevIns->iInstance));
4086
4087 /** @todo Always take the SMP path - fewer code paths. */
4088 if (pVM->cCpus > 1)
4089 {
4090 /* We might be holding locks here and could cause a deadlock since
4091 VMR3PowerOff rendezvous with the other CPUs. */
4092 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3PowerOff, 1, pVM->pUVM);
4093 AssertRC(rc);
4094 /* Set the VCPU state to stopped here as well to make sure no
4095 inconsistency with the EM state occurs. */
4096 VMCPU_SET_STATE(VMMGetCpu(pVM), VMCPUSTATE_STOPPED);
4097 rc = VINF_EM_OFF;
4098 }
4099 else
4100 rc = VMR3PowerOff(pVM->pUVM);
4101
4102 LogFlow(("pdmR3DevHlp_VMPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
4103 return rc;
4104}
4105
4106
4107/** @interface_method_impl{PDMDEVHLPR3,pfnA20IsEnabled} */
4108static DECLCALLBACK(bool) pdmR3DevHlp_A20IsEnabled(PPDMDEVINS pDevIns)
4109{
4110 PDMDEV_ASSERT_DEVINS(pDevIns);
4111 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
4112
4113 bool fRc = PGMPhysIsA20Enabled(VMMGetCpu(pDevIns->Internal.s.pVMR3));
4114
4115 LogFlow(("pdmR3DevHlp_A20IsEnabled: caller='%s'/%d: returns %d\n", pDevIns->pReg->szName, pDevIns->iInstance, fRc));
4116 return fRc;
4117}
4118
4119
4120/** @interface_method_impl{PDMDEVHLPR3,pfnA20Set} */
4121static DECLCALLBACK(void) pdmR3DevHlp_A20Set(PPDMDEVINS pDevIns, bool fEnable)
4122{
4123 PDMDEV_ASSERT_DEVINS(pDevIns);
4124 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
4125 LogFlow(("pdmR3DevHlp_A20Set: caller='%s'/%d: fEnable=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, fEnable));
4126 PGMR3PhysSetA20(VMMGetCpu(pDevIns->Internal.s.pVMR3), fEnable);
4127}
4128
4129
4130/** @interface_method_impl{PDMDEVHLPR3,pfnGetCpuId} */
4131static DECLCALLBACK(void) pdmR3DevHlp_GetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf,
4132 uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
4133{
4134 PDMDEV_ASSERT_DEVINS(pDevIns);
4135 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
4136
4137 LogFlow(("pdmR3DevHlp_GetCpuId: caller='%s'/%d: iLeaf=%d pEax=%p pEbx=%p pEcx=%p pEdx=%p\n",
4138 pDevIns->pReg->szName, pDevIns->iInstance, iLeaf, pEax, pEbx, pEcx, pEdx));
4139 AssertPtr(pEax); AssertPtr(pEbx); AssertPtr(pEcx); AssertPtr(pEdx);
4140
4141 CPUMGetGuestCpuId(VMMGetCpu(pDevIns->Internal.s.pVMR3), iLeaf, 0 /*iSubLeaf*/, pEax, pEbx, pEcx, pEdx);
4142
4143 LogFlow(("pdmR3DevHlp_GetCpuId: caller='%s'/%d: returns void - *pEax=%#x *pEbx=%#x *pEcx=%#x *pEdx=%#x\n",
4144 pDevIns->pReg->szName, pDevIns->iInstance, *pEax, *pEbx, *pEcx, *pEdx));
4145}
4146
4147
4148/**
4149 * The device helper structure for trusted devices.
4150 */
4151const PDMDEVHLPR3 g_pdmR3DevHlpTrusted =
4152{
4153 PDM_DEVHLPR3_VERSION,
4154 pdmR3DevHlp_IoPortCreateEx,
4155 pdmR3DevHlp_IoPortMap,
4156 pdmR3DevHlp_IoPortUnmap,
4157 pdmR3DevHlp_IoPortGetMappingAddress,
4158 pdmR3DevHlp_MmioCreateEx,
4159 pdmR3DevHlp_MmioMap,
4160 pdmR3DevHlp_MmioUnmap,
4161 pdmR3DevHlp_MmioReduce,
4162 pdmR3DevHlp_MmioGetMappingAddress,
4163 pdmR3DevHlp_Mmio2Create,
4164 pdmR3DevHlp_Mmio2Destroy,
4165 pdmR3DevHlp_Mmio2Map,
4166 pdmR3DevHlp_Mmio2Unmap,
4167 pdmR3DevHlp_Mmio2Reduce,
4168 pdmR3DevHlp_Mmio2GetMappingAddress,
4169 pdmR3DevHlp_Mmio2ChangeRegionNo,
4170 pdmR3DevHlp_ROMRegister,
4171 pdmR3DevHlp_ROMProtectShadow,
4172 pdmR3DevHlp_SSMRegister,
4173 SSMR3PutStruct,
4174 SSMR3PutStructEx,
4175 SSMR3PutBool,
4176 SSMR3PutU8,
4177 SSMR3PutS8,
4178 SSMR3PutU16,
4179 SSMR3PutS16,
4180 SSMR3PutU32,
4181 SSMR3PutS32,
4182 SSMR3PutU64,
4183 SSMR3PutS64,
4184 SSMR3PutU128,
4185 SSMR3PutS128,
4186 SSMR3PutUInt,
4187 SSMR3PutSInt,
4188 SSMR3PutGCUInt,
4189 SSMR3PutGCUIntReg,
4190 SSMR3PutGCPhys32,
4191 SSMR3PutGCPhys64,
4192 SSMR3PutGCPhys,
4193 SSMR3PutGCPtr,
4194 SSMR3PutGCUIntPtr,
4195 SSMR3PutRCPtr,
4196 SSMR3PutIOPort,
4197 SSMR3PutSel,
4198 SSMR3PutMem,
4199 SSMR3PutStrZ,
4200 SSMR3GetStruct,
4201 SSMR3GetStructEx,
4202 SSMR3GetBool,
4203 SSMR3GetBoolV,
4204 SSMR3GetU8,
4205 SSMR3GetU8V,
4206 SSMR3GetS8,
4207 SSMR3GetS8V,
4208 SSMR3GetU16,
4209 SSMR3GetU16V,
4210 SSMR3GetS16,
4211 SSMR3GetS16V,
4212 SSMR3GetU32,
4213 SSMR3GetU32V,
4214 SSMR3GetS32,
4215 SSMR3GetS32V,
4216 SSMR3GetU64,
4217 SSMR3GetU64V,
4218 SSMR3GetS64,
4219 SSMR3GetS64V,
4220 SSMR3GetU128,
4221 SSMR3GetU128V,
4222 SSMR3GetS128,
4223 SSMR3GetS128V,
4224 SSMR3GetGCPhys32,
4225 SSMR3GetGCPhys32V,
4226 SSMR3GetGCPhys64,
4227 SSMR3GetGCPhys64V,
4228 SSMR3GetGCPhys,
4229 SSMR3GetGCPhysV,
4230 SSMR3GetUInt,
4231 SSMR3GetSInt,
4232 SSMR3GetGCUInt,
4233 SSMR3GetGCUIntReg,
4234 SSMR3GetGCPtr,
4235 SSMR3GetGCUIntPtr,
4236 SSMR3GetRCPtr,
4237 SSMR3GetIOPort,
4238 SSMR3GetSel,
4239 SSMR3GetMem,
4240 SSMR3GetStrZ,
4241 SSMR3GetStrZEx,
4242 SSMR3Skip,
4243 SSMR3SkipToEndOfUnit,
4244 SSMR3SetLoadError,
4245 SSMR3SetLoadErrorV,
4246 SSMR3SetCfgError,
4247 SSMR3SetCfgErrorV,
4248 SSMR3HandleGetStatus,
4249 SSMR3HandleGetAfter,
4250 SSMR3HandleIsLiveSave,
4251 SSMR3HandleMaxDowntime,
4252 SSMR3HandleHostBits,
4253 SSMR3HandleRevision,
4254 SSMR3HandleVersion,
4255 SSMR3HandleHostOSAndArch,
4256 pdmR3DevHlp_TimerCreate,
4257 pdmR3DevHlp_TimerFromMicro,
4258 pdmR3DevHlp_TimerFromMilli,
4259 pdmR3DevHlp_TimerFromNano,
4260 pdmR3DevHlp_TimerGet,
4261 pdmR3DevHlp_TimerGetFreq,
4262 pdmR3DevHlp_TimerGetNano,
4263 pdmR3DevHlp_TimerIsActive,
4264 pdmR3DevHlp_TimerIsLockOwner,
4265 pdmR3DevHlp_TimerLockClock,
4266 pdmR3DevHlp_TimerLockClock2,
4267 pdmR3DevHlp_TimerSet,
4268 pdmR3DevHlp_TimerSetFrequencyHint,
4269 pdmR3DevHlp_TimerSetMicro,
4270 pdmR3DevHlp_TimerSetMillies,
4271 pdmR3DevHlp_TimerSetNano,
4272 pdmR3DevHlp_TimerSetRelative,
4273 pdmR3DevHlp_TimerStop,
4274 pdmR3DevHlp_TimerUnlockClock,
4275 pdmR3DevHlp_TimerUnlockClock2,
4276 pdmR3DevHlp_TimerSetCritSect,
4277 pdmR3DevHlp_TimerSave,
4278 pdmR3DevHlp_TimerLoad,
4279 pdmR3DevHlp_TimerDestroy,
4280 TMR3TimerSkip,
4281 pdmR3DevHlp_TMUtcNow,
4282 CFGMR3Exists,
4283 CFGMR3QueryType,
4284 CFGMR3QuerySize,
4285 CFGMR3QueryInteger,
4286 CFGMR3QueryIntegerDef,
4287 CFGMR3QueryString,
4288 CFGMR3QueryStringDef,
4289 CFGMR3QueryBytes,
4290 CFGMR3QueryU64,
4291 CFGMR3QueryU64Def,
4292 CFGMR3QueryS64,
4293 CFGMR3QueryS64Def,
4294 CFGMR3QueryU32,
4295 CFGMR3QueryU32Def,
4296 CFGMR3QueryS32,
4297 CFGMR3QueryS32Def,
4298 CFGMR3QueryU16,
4299 CFGMR3QueryU16Def,
4300 CFGMR3QueryS16,
4301 CFGMR3QueryS16Def,
4302 CFGMR3QueryU8,
4303 CFGMR3QueryU8Def,
4304 CFGMR3QueryS8,
4305 CFGMR3QueryS8Def,
4306 CFGMR3QueryBool,
4307 CFGMR3QueryBoolDef,
4308 CFGMR3QueryPort,
4309 CFGMR3QueryPortDef,
4310 CFGMR3QueryUInt,
4311 CFGMR3QueryUIntDef,
4312 CFGMR3QuerySInt,
4313 CFGMR3QuerySIntDef,
4314 CFGMR3QueryPtr,
4315 CFGMR3QueryPtrDef,
4316 CFGMR3QueryGCPtr,
4317 CFGMR3QueryGCPtrDef,
4318 CFGMR3QueryGCPtrU,
4319 CFGMR3QueryGCPtrUDef,
4320 CFGMR3QueryGCPtrS,
4321 CFGMR3QueryGCPtrSDef,
4322 CFGMR3QueryStringAlloc,
4323 CFGMR3QueryStringAllocDef,
4324 CFGMR3GetParent,
4325 CFGMR3GetChild,
4326 CFGMR3GetChildF,
4327 CFGMR3GetChildFV,
4328 CFGMR3GetFirstChild,
4329 CFGMR3GetNextChild,
4330 CFGMR3GetName,
4331 CFGMR3GetNameLen,
4332 CFGMR3AreChildrenValid,
4333 CFGMR3GetFirstValue,
4334 CFGMR3GetNextValue,
4335 CFGMR3GetValueName,
4336 CFGMR3GetValueNameLen,
4337 CFGMR3GetValueType,
4338 CFGMR3AreValuesValid,
4339 CFGMR3ValidateConfig,
4340 pdmR3DevHlp_PhysRead,
4341 pdmR3DevHlp_PhysWrite,
4342 pdmR3DevHlp_PhysGCPhys2CCPtr,
4343 pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
4344 pdmR3DevHlp_PhysReleasePageMappingLock,
4345 pdmR3DevHlp_PhysReadGCVirt,
4346 pdmR3DevHlp_PhysWriteGCVirt,
4347 pdmR3DevHlp_PhysGCPtr2GCPhys,
4348 pdmR3DevHlp_MMHeapAlloc,
4349 pdmR3DevHlp_MMHeapAllocZ,
4350 pdmR3DevHlp_MMHeapFree,
4351 pdmR3DevHlp_VMState,
4352 pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet,
4353 pdmR3DevHlp_VMSetError,
4354 pdmR3DevHlp_VMSetErrorV,
4355 pdmR3DevHlp_VMSetRuntimeError,
4356 pdmR3DevHlp_VMSetRuntimeErrorV,
4357 pdmR3DevHlp_DBGFStopV,
4358 pdmR3DevHlp_DBGFInfoRegister,
4359 pdmR3DevHlp_DBGFInfoRegisterArgv,
4360 pdmR3DevHlp_DBGFRegRegister,
4361 pdmR3DevHlp_DBGFTraceBuf,
4362 pdmR3DevHlp_STAMRegister,
4363 pdmR3DevHlp_STAMRegisterV,
4364 pdmR3DevHlp_PCIRegister,
4365 pdmR3DevHlp_PCIRegisterMsi,
4366 pdmR3DevHlp_PCIIORegionRegister,
4367 pdmR3DevHlp_PCIInterceptConfigAccesses,
4368 pdmR3DevHlp_PCIConfigWrite,
4369 pdmR3DevHlp_PCIConfigRead,
4370 pdmR3DevHlp_PCIPhysRead,
4371 pdmR3DevHlp_PCIPhysWrite,
4372 pdmR3DevHlp_PCIPhysGCPhys2CCPtr,
4373 pdmR3DevHlp_PCIPhysGCPhys2CCPtrReadOnly,
4374 pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtr,
4375 pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtrReadOnly,
4376 pdmR3DevHlp_PCISetIrq,
4377 pdmR3DevHlp_PCISetIrqNoWait,
4378 pdmR3DevHlp_ISASetIrq,
4379 pdmR3DevHlp_ISASetIrqNoWait,
4380 pdmR3DevHlp_DriverAttach,
4381 pdmR3DevHlp_DriverDetach,
4382 pdmR3DevHlp_DriverReconfigure,
4383 pdmR3DevHlp_QueueCreatePtr,
4384 pdmR3DevHlp_QueueCreate,
4385 pdmR3DevHlp_QueueToPtr,
4386 pdmR3DevHlp_QueueAlloc,
4387 pdmR3DevHlp_QueueInsert,
4388 pdmR3DevHlp_QueueInsertEx,
4389 pdmR3DevHlp_QueueFlushIfNecessary,
4390 pdmR3DevHlp_TaskCreate,
4391 pdmR3DevHlp_TaskTrigger,
4392 pdmR3DevHlp_SUPSemEventCreate,
4393 pdmR3DevHlp_SUPSemEventClose,
4394 pdmR3DevHlp_SUPSemEventSignal,
4395 pdmR3DevHlp_SUPSemEventWaitNoResume,
4396 pdmR3DevHlp_SUPSemEventWaitNsAbsIntr,
4397 pdmR3DevHlp_SUPSemEventWaitNsRelIntr,
4398 pdmR3DevHlp_SUPSemEventGetResolution,
4399 pdmR3DevHlp_SUPSemEventMultiCreate,
4400 pdmR3DevHlp_SUPSemEventMultiClose,
4401 pdmR3DevHlp_SUPSemEventMultiSignal,
4402 pdmR3DevHlp_SUPSemEventMultiReset,
4403 pdmR3DevHlp_SUPSemEventMultiWaitNoResume,
4404 pdmR3DevHlp_SUPSemEventMultiWaitNsAbsIntr,
4405 pdmR3DevHlp_SUPSemEventMultiWaitNsRelIntr,
4406 pdmR3DevHlp_SUPSemEventMultiGetResolution,
4407 pdmR3DevHlp_CritSectInit,
4408 pdmR3DevHlp_CritSectGetNop,
4409 pdmR3DevHlp_CritSectGetNopR0,
4410 pdmR3DevHlp_CritSectGetNopRC,
4411 pdmR3DevHlp_SetDeviceCritSect,
4412 pdmR3DevHlp_CritSectYield,
4413 pdmR3DevHlp_CritSectEnter,
4414 pdmR3DevHlp_CritSectEnterDebug,
4415 pdmR3DevHlp_CritSectTryEnter,
4416 pdmR3DevHlp_CritSectTryEnterDebug,
4417 pdmR3DevHlp_CritSectLeave,
4418 pdmR3DevHlp_CritSectIsOwner,
4419 pdmR3DevHlp_CritSectIsInitialized,
4420 pdmR3DevHlp_CritSectHasWaiters,
4421 pdmR3DevHlp_CritSectGetRecursion,
4422 pdmR3DevHlp_CritSectScheduleExitEvent,
4423 pdmR3DevHlp_CritSectDelete,
4424 pdmR3DevHlp_ThreadCreate,
4425 PDMR3ThreadDestroy,
4426 PDMR3ThreadIAmSuspending,
4427 PDMR3ThreadIAmRunning,
4428 PDMR3ThreadSleep,
4429 PDMR3ThreadSuspend,
4430 PDMR3ThreadResume,
4431 pdmR3DevHlp_SetAsyncNotification,
4432 pdmR3DevHlp_AsyncNotificationCompleted,
4433 pdmR3DevHlp_RTCRegister,
4434 pdmR3DevHlp_PCIBusRegister,
4435 pdmR3DevHlp_IommuRegister,
4436 pdmR3DevHlp_PICRegister,
4437 pdmR3DevHlp_ApicRegister,
4438 pdmR3DevHlp_IoApicRegister,
4439 pdmR3DevHlp_HpetRegister,
4440 pdmR3DevHlp_PciRawRegister,
4441 pdmR3DevHlp_DMACRegister,
4442 pdmR3DevHlp_DMARegister,
4443 pdmR3DevHlp_DMAReadMemory,
4444 pdmR3DevHlp_DMAWriteMemory,
4445 pdmR3DevHlp_DMASetDREQ,
4446 pdmR3DevHlp_DMAGetChannelMode,
4447 pdmR3DevHlp_DMASchedule,
4448 pdmR3DevHlp_CMOSWrite,
4449 pdmR3DevHlp_CMOSRead,
4450 pdmR3DevHlp_AssertEMT,
4451 pdmR3DevHlp_AssertOther,
4452 pdmR3DevHlp_LdrGetRCInterfaceSymbols,
4453 pdmR3DevHlp_LdrGetR0InterfaceSymbols,
4454 pdmR3DevHlp_CallR0,
4455 pdmR3DevHlp_VMGetSuspendReason,
4456 pdmR3DevHlp_VMGetResumeReason,
4457 pdmR3DevHlp_PhysBulkGCPhys2CCPtr,
4458 pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly,
4459 pdmR3DevHlp_PhysBulkReleasePageMappingLocks,
4460 pdmR3DevHlp_CpuGetGuestMicroarch,
4461 pdmR3DevHlp_CpuGetGuestAddrWidths,
4462 pdmR3DevHlp_STAMDeregisterByPrefix,
4463 0,
4464 0,
4465 0,
4466 0,
4467 0,
4468 0,
4469 0,
4470 0,
4471 0,
4472 pdmR3DevHlp_GetUVM,
4473 pdmR3DevHlp_GetVM,
4474 pdmR3DevHlp_GetVMCPU,
4475 pdmR3DevHlp_GetCurrentCpuId,
4476 pdmR3DevHlp_RegisterVMMDevHeap,
4477 pdmR3DevHlp_FirmwareRegister,
4478 pdmR3DevHlp_VMReset,
4479 pdmR3DevHlp_VMSuspend,
4480 pdmR3DevHlp_VMSuspendSaveAndPowerOff,
4481 pdmR3DevHlp_VMPowerOff,
4482 pdmR3DevHlp_A20IsEnabled,
4483 pdmR3DevHlp_A20Set,
4484 pdmR3DevHlp_GetCpuId,
4485 pdmR3DevHlp_TMTimeVirtGet,
4486 pdmR3DevHlp_TMTimeVirtGetFreq,
4487 pdmR3DevHlp_TMTimeVirtGetNano,
4488 pdmR3DevHlp_GetSupDrvSession,
4489 pdmR3DevHlp_QueryGenericUserObject,
4490 pdmR3DevHlp_PGMHandlerPhysicalTypeRegister,
4491 PDM_DEVHLPR3_VERSION /* the end */
4492};
4493
4494
4495#ifdef VBOX_WITH_DBGF_TRACING
4496/**
4497 * The device helper structure for trusted devices - tracing variant.
4498 */
4499const PDMDEVHLPR3 g_pdmR3DevHlpTracing =
4500{
4501 PDM_DEVHLPR3_VERSION,
4502 pdmR3DevHlpTracing_IoPortCreateEx,
4503 pdmR3DevHlpTracing_IoPortMap,
4504 pdmR3DevHlpTracing_IoPortUnmap,
4505 pdmR3DevHlp_IoPortGetMappingAddress,
4506 pdmR3DevHlpTracing_MmioCreateEx,
4507 pdmR3DevHlpTracing_MmioMap,
4508 pdmR3DevHlpTracing_MmioUnmap,
4509 pdmR3DevHlp_MmioReduce,
4510 pdmR3DevHlp_MmioGetMappingAddress,
4511 pdmR3DevHlp_Mmio2Create,
4512 pdmR3DevHlp_Mmio2Destroy,
4513 pdmR3DevHlp_Mmio2Map,
4514 pdmR3DevHlp_Mmio2Unmap,
4515 pdmR3DevHlp_Mmio2Reduce,
4516 pdmR3DevHlp_Mmio2GetMappingAddress,
4517 pdmR3DevHlp_Mmio2ChangeRegionNo,
4518 pdmR3DevHlp_ROMRegister,
4519 pdmR3DevHlp_ROMProtectShadow,
4520 pdmR3DevHlp_SSMRegister,
4521 SSMR3PutStruct,
4522 SSMR3PutStructEx,
4523 SSMR3PutBool,
4524 SSMR3PutU8,
4525 SSMR3PutS8,
4526 SSMR3PutU16,
4527 SSMR3PutS16,
4528 SSMR3PutU32,
4529 SSMR3PutS32,
4530 SSMR3PutU64,
4531 SSMR3PutS64,
4532 SSMR3PutU128,
4533 SSMR3PutS128,
4534 SSMR3PutUInt,
4535 SSMR3PutSInt,
4536 SSMR3PutGCUInt,
4537 SSMR3PutGCUIntReg,
4538 SSMR3PutGCPhys32,
4539 SSMR3PutGCPhys64,
4540 SSMR3PutGCPhys,
4541 SSMR3PutGCPtr,
4542 SSMR3PutGCUIntPtr,
4543 SSMR3PutRCPtr,
4544 SSMR3PutIOPort,
4545 SSMR3PutSel,
4546 SSMR3PutMem,
4547 SSMR3PutStrZ,
4548 SSMR3GetStruct,
4549 SSMR3GetStructEx,
4550 SSMR3GetBool,
4551 SSMR3GetBoolV,
4552 SSMR3GetU8,
4553 SSMR3GetU8V,
4554 SSMR3GetS8,
4555 SSMR3GetS8V,
4556 SSMR3GetU16,
4557 SSMR3GetU16V,
4558 SSMR3GetS16,
4559 SSMR3GetS16V,
4560 SSMR3GetU32,
4561 SSMR3GetU32V,
4562 SSMR3GetS32,
4563 SSMR3GetS32V,
4564 SSMR3GetU64,
4565 SSMR3GetU64V,
4566 SSMR3GetS64,
4567 SSMR3GetS64V,
4568 SSMR3GetU128,
4569 SSMR3GetU128V,
4570 SSMR3GetS128,
4571 SSMR3GetS128V,
4572 SSMR3GetGCPhys32,
4573 SSMR3GetGCPhys32V,
4574 SSMR3GetGCPhys64,
4575 SSMR3GetGCPhys64V,
4576 SSMR3GetGCPhys,
4577 SSMR3GetGCPhysV,
4578 SSMR3GetUInt,
4579 SSMR3GetSInt,
4580 SSMR3GetGCUInt,
4581 SSMR3GetGCUIntReg,
4582 SSMR3GetGCPtr,
4583 SSMR3GetGCUIntPtr,
4584 SSMR3GetRCPtr,
4585 SSMR3GetIOPort,
4586 SSMR3GetSel,
4587 SSMR3GetMem,
4588 SSMR3GetStrZ,
4589 SSMR3GetStrZEx,
4590 SSMR3Skip,
4591 SSMR3SkipToEndOfUnit,
4592 SSMR3SetLoadError,
4593 SSMR3SetLoadErrorV,
4594 SSMR3SetCfgError,
4595 SSMR3SetCfgErrorV,
4596 SSMR3HandleGetStatus,
4597 SSMR3HandleGetAfter,
4598 SSMR3HandleIsLiveSave,
4599 SSMR3HandleMaxDowntime,
4600 SSMR3HandleHostBits,
4601 SSMR3HandleRevision,
4602 SSMR3HandleVersion,
4603 SSMR3HandleHostOSAndArch,
4604 pdmR3DevHlp_TimerCreate,
4605 pdmR3DevHlp_TimerFromMicro,
4606 pdmR3DevHlp_TimerFromMilli,
4607 pdmR3DevHlp_TimerFromNano,
4608 pdmR3DevHlp_TimerGet,
4609 pdmR3DevHlp_TimerGetFreq,
4610 pdmR3DevHlp_TimerGetNano,
4611 pdmR3DevHlp_TimerIsActive,
4612 pdmR3DevHlp_TimerIsLockOwner,
4613 pdmR3DevHlp_TimerLockClock,
4614 pdmR3DevHlp_TimerLockClock2,
4615 pdmR3DevHlp_TimerSet,
4616 pdmR3DevHlp_TimerSetFrequencyHint,
4617 pdmR3DevHlp_TimerSetMicro,
4618 pdmR3DevHlp_TimerSetMillies,
4619 pdmR3DevHlp_TimerSetNano,
4620 pdmR3DevHlp_TimerSetRelative,
4621 pdmR3DevHlp_TimerStop,
4622 pdmR3DevHlp_TimerUnlockClock,
4623 pdmR3DevHlp_TimerUnlockClock2,
4624 pdmR3DevHlp_TimerSetCritSect,
4625 pdmR3DevHlp_TimerSave,
4626 pdmR3DevHlp_TimerLoad,
4627 pdmR3DevHlp_TimerDestroy,
4628 TMR3TimerSkip,
4629 pdmR3DevHlp_TMUtcNow,
4630 CFGMR3Exists,
4631 CFGMR3QueryType,
4632 CFGMR3QuerySize,
4633 CFGMR3QueryInteger,
4634 CFGMR3QueryIntegerDef,
4635 CFGMR3QueryString,
4636 CFGMR3QueryStringDef,
4637 CFGMR3QueryBytes,
4638 CFGMR3QueryU64,
4639 CFGMR3QueryU64Def,
4640 CFGMR3QueryS64,
4641 CFGMR3QueryS64Def,
4642 CFGMR3QueryU32,
4643 CFGMR3QueryU32Def,
4644 CFGMR3QueryS32,
4645 CFGMR3QueryS32Def,
4646 CFGMR3QueryU16,
4647 CFGMR3QueryU16Def,
4648 CFGMR3QueryS16,
4649 CFGMR3QueryS16Def,
4650 CFGMR3QueryU8,
4651 CFGMR3QueryU8Def,
4652 CFGMR3QueryS8,
4653 CFGMR3QueryS8Def,
4654 CFGMR3QueryBool,
4655 CFGMR3QueryBoolDef,
4656 CFGMR3QueryPort,
4657 CFGMR3QueryPortDef,
4658 CFGMR3QueryUInt,
4659 CFGMR3QueryUIntDef,
4660 CFGMR3QuerySInt,
4661 CFGMR3QuerySIntDef,
4662 CFGMR3QueryPtr,
4663 CFGMR3QueryPtrDef,
4664 CFGMR3QueryGCPtr,
4665 CFGMR3QueryGCPtrDef,
4666 CFGMR3QueryGCPtrU,
4667 CFGMR3QueryGCPtrUDef,
4668 CFGMR3QueryGCPtrS,
4669 CFGMR3QueryGCPtrSDef,
4670 CFGMR3QueryStringAlloc,
4671 CFGMR3QueryStringAllocDef,
4672 CFGMR3GetParent,
4673 CFGMR3GetChild,
4674 CFGMR3GetChildF,
4675 CFGMR3GetChildFV,
4676 CFGMR3GetFirstChild,
4677 CFGMR3GetNextChild,
4678 CFGMR3GetName,
4679 CFGMR3GetNameLen,
4680 CFGMR3AreChildrenValid,
4681 CFGMR3GetFirstValue,
4682 CFGMR3GetNextValue,
4683 CFGMR3GetValueName,
4684 CFGMR3GetValueNameLen,
4685 CFGMR3GetValueType,
4686 CFGMR3AreValuesValid,
4687 CFGMR3ValidateConfig,
4688 pdmR3DevHlpTracing_PhysRead,
4689 pdmR3DevHlpTracing_PhysWrite,
4690 pdmR3DevHlp_PhysGCPhys2CCPtr,
4691 pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
4692 pdmR3DevHlp_PhysReleasePageMappingLock,
4693 pdmR3DevHlp_PhysReadGCVirt,
4694 pdmR3DevHlp_PhysWriteGCVirt,
4695 pdmR3DevHlp_PhysGCPtr2GCPhys,
4696 pdmR3DevHlp_MMHeapAlloc,
4697 pdmR3DevHlp_MMHeapAllocZ,
4698 pdmR3DevHlp_MMHeapFree,
4699 pdmR3DevHlp_VMState,
4700 pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet,
4701 pdmR3DevHlp_VMSetError,
4702 pdmR3DevHlp_VMSetErrorV,
4703 pdmR3DevHlp_VMSetRuntimeError,
4704 pdmR3DevHlp_VMSetRuntimeErrorV,
4705 pdmR3DevHlp_DBGFStopV,
4706 pdmR3DevHlp_DBGFInfoRegister,
4707 pdmR3DevHlp_DBGFInfoRegisterArgv,
4708 pdmR3DevHlp_DBGFRegRegister,
4709 pdmR3DevHlp_DBGFTraceBuf,
4710 pdmR3DevHlp_STAMRegister,
4711 pdmR3DevHlp_STAMRegisterV,
4712 pdmR3DevHlp_PCIRegister,
4713 pdmR3DevHlp_PCIRegisterMsi,
4714 pdmR3DevHlp_PCIIORegionRegister,
4715 pdmR3DevHlp_PCIInterceptConfigAccesses,
4716 pdmR3DevHlp_PCIConfigWrite,
4717 pdmR3DevHlp_PCIConfigRead,
4718 pdmR3DevHlpTracing_PCIPhysRead,
4719 pdmR3DevHlpTracing_PCIPhysWrite,
4720 pdmR3DevHlp_PCIPhysGCPhys2CCPtr,
4721 pdmR3DevHlp_PCIPhysGCPhys2CCPtrReadOnly,
4722 pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtr,
4723 pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtrReadOnly,
4724 pdmR3DevHlpTracing_PCISetIrq,
4725 pdmR3DevHlpTracing_PCISetIrqNoWait,
4726 pdmR3DevHlpTracing_ISASetIrq,
4727 pdmR3DevHlpTracing_ISASetIrqNoWait,
4728 pdmR3DevHlp_DriverAttach,
4729 pdmR3DevHlp_DriverDetach,
4730 pdmR3DevHlp_DriverReconfigure,
4731 pdmR3DevHlp_QueueCreatePtr,
4732 pdmR3DevHlp_QueueCreate,
4733 pdmR3DevHlp_QueueToPtr,
4734 pdmR3DevHlp_QueueAlloc,
4735 pdmR3DevHlp_QueueInsert,
4736 pdmR3DevHlp_QueueInsertEx,
4737 pdmR3DevHlp_QueueFlushIfNecessary,
4738 pdmR3DevHlp_TaskCreate,
4739 pdmR3DevHlp_TaskTrigger,
4740 pdmR3DevHlp_SUPSemEventCreate,
4741 pdmR3DevHlp_SUPSemEventClose,
4742 pdmR3DevHlp_SUPSemEventSignal,
4743 pdmR3DevHlp_SUPSemEventWaitNoResume,
4744 pdmR3DevHlp_SUPSemEventWaitNsAbsIntr,
4745 pdmR3DevHlp_SUPSemEventWaitNsRelIntr,
4746 pdmR3DevHlp_SUPSemEventGetResolution,
4747 pdmR3DevHlp_SUPSemEventMultiCreate,
4748 pdmR3DevHlp_SUPSemEventMultiClose,
4749 pdmR3DevHlp_SUPSemEventMultiSignal,
4750 pdmR3DevHlp_SUPSemEventMultiReset,
4751 pdmR3DevHlp_SUPSemEventMultiWaitNoResume,
4752 pdmR3DevHlp_SUPSemEventMultiWaitNsAbsIntr,
4753 pdmR3DevHlp_SUPSemEventMultiWaitNsRelIntr,
4754 pdmR3DevHlp_SUPSemEventMultiGetResolution,
4755 pdmR3DevHlp_CritSectInit,
4756 pdmR3DevHlp_CritSectGetNop,
4757 pdmR3DevHlp_CritSectGetNopR0,
4758 pdmR3DevHlp_CritSectGetNopRC,
4759 pdmR3DevHlp_SetDeviceCritSect,
4760 pdmR3DevHlp_CritSectYield,
4761 pdmR3DevHlp_CritSectEnter,
4762 pdmR3DevHlp_CritSectEnterDebug,
4763 pdmR3DevHlp_CritSectTryEnter,
4764 pdmR3DevHlp_CritSectTryEnterDebug,
4765 pdmR3DevHlp_CritSectLeave,
4766 pdmR3DevHlp_CritSectIsOwner,
4767 pdmR3DevHlp_CritSectIsInitialized,
4768 pdmR3DevHlp_CritSectHasWaiters,
4769 pdmR3DevHlp_CritSectGetRecursion,
4770 pdmR3DevHlp_CritSectScheduleExitEvent,
4771 pdmR3DevHlp_CritSectDelete,
4772 pdmR3DevHlp_ThreadCreate,
4773 PDMR3ThreadDestroy,
4774 PDMR3ThreadIAmSuspending,
4775 PDMR3ThreadIAmRunning,
4776 PDMR3ThreadSleep,
4777 PDMR3ThreadSuspend,
4778 PDMR3ThreadResume,
4779 pdmR3DevHlp_SetAsyncNotification,
4780 pdmR3DevHlp_AsyncNotificationCompleted,
4781 pdmR3DevHlp_RTCRegister,
4782 pdmR3DevHlp_PCIBusRegister,
4783 pdmR3DevHlp_IommuRegister,
4784 pdmR3DevHlp_PICRegister,
4785 pdmR3DevHlp_ApicRegister,
4786 pdmR3DevHlp_IoApicRegister,
4787 pdmR3DevHlp_HpetRegister,
4788 pdmR3DevHlp_PciRawRegister,
4789 pdmR3DevHlp_DMACRegister,
4790 pdmR3DevHlp_DMARegister,
4791 pdmR3DevHlp_DMAReadMemory,
4792 pdmR3DevHlp_DMAWriteMemory,
4793 pdmR3DevHlp_DMASetDREQ,
4794 pdmR3DevHlp_DMAGetChannelMode,
4795 pdmR3DevHlp_DMASchedule,
4796 pdmR3DevHlp_CMOSWrite,
4797 pdmR3DevHlp_CMOSRead,
4798 pdmR3DevHlp_AssertEMT,
4799 pdmR3DevHlp_AssertOther,
4800 pdmR3DevHlp_LdrGetRCInterfaceSymbols,
4801 pdmR3DevHlp_LdrGetR0InterfaceSymbols,
4802 pdmR3DevHlp_CallR0,
4803 pdmR3DevHlp_VMGetSuspendReason,
4804 pdmR3DevHlp_VMGetResumeReason,
4805 pdmR3DevHlp_PhysBulkGCPhys2CCPtr,
4806 pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly,
4807 pdmR3DevHlp_PhysBulkReleasePageMappingLocks,
4808 pdmR3DevHlp_CpuGetGuestMicroarch,
4809 pdmR3DevHlp_CpuGetGuestAddrWidths,
4810 pdmR3DevHlp_STAMDeregisterByPrefix,
4811 0,
4812 0,
4813 0,
4814 0,
4815 0,
4816 0,
4817 0,
4818 0,
4819 0,
4820 pdmR3DevHlp_GetUVM,
4821 pdmR3DevHlp_GetVM,
4822 pdmR3DevHlp_GetVMCPU,
4823 pdmR3DevHlp_GetCurrentCpuId,
4824 pdmR3DevHlp_RegisterVMMDevHeap,
4825 pdmR3DevHlp_FirmwareRegister,
4826 pdmR3DevHlp_VMReset,
4827 pdmR3DevHlp_VMSuspend,
4828 pdmR3DevHlp_VMSuspendSaveAndPowerOff,
4829 pdmR3DevHlp_VMPowerOff,
4830 pdmR3DevHlp_A20IsEnabled,
4831 pdmR3DevHlp_A20Set,
4832 pdmR3DevHlp_GetCpuId,
4833 pdmR3DevHlp_TMTimeVirtGet,
4834 pdmR3DevHlp_TMTimeVirtGetFreq,
4835 pdmR3DevHlp_TMTimeVirtGetNano,
4836 pdmR3DevHlp_GetSupDrvSession,
4837 pdmR3DevHlp_QueryGenericUserObject,
4838 pdmR3DevHlp_PGMHandlerPhysicalTypeRegister,
4839 PDM_DEVHLPR3_VERSION /* the end */
4840};
4841#endif /* VBOX_WITH_DBGF_TRACING */
4842
4843
4844
4845
4846/** @interface_method_impl{PDMDEVHLPR3,pfnGetUVM} */
4847static DECLCALLBACK(PUVM) pdmR3DevHlp_Untrusted_GetUVM(PPDMDEVINS pDevIns)
4848{
4849 PDMDEV_ASSERT_DEVINS(pDevIns);
4850 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4851 return NULL;
4852}
4853
4854
4855/** @interface_method_impl{PDMDEVHLPR3,pfnGetVM} */
4856static DECLCALLBACK(PVM) pdmR3DevHlp_Untrusted_GetVM(PPDMDEVINS pDevIns)
4857{
4858 PDMDEV_ASSERT_DEVINS(pDevIns);
4859 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4860 return NULL;
4861}
4862
4863
4864/** @interface_method_impl{PDMDEVHLPR3,pfnGetVMCPU} */
4865static DECLCALLBACK(PVMCPU) pdmR3DevHlp_Untrusted_GetVMCPU(PPDMDEVINS pDevIns)
4866{
4867 PDMDEV_ASSERT_DEVINS(pDevIns);
4868 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4869 return NULL;
4870}
4871
4872
4873/** @interface_method_impl{PDMDEVHLPR3,pfnGetCurrentCpuId} */
4874static DECLCALLBACK(VMCPUID) pdmR3DevHlp_Untrusted_GetCurrentCpuId(PPDMDEVINS pDevIns)
4875{
4876 PDMDEV_ASSERT_DEVINS(pDevIns);
4877 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4878 return NIL_VMCPUID;
4879}
4880
4881
4882/** @interface_method_impl{PDMDEVHLPR3,pfnRegisterVMMDevHeap} */
4883static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_RegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys,
4884 RTR3PTR pvHeap, unsigned cbHeap)
4885{
4886 PDMDEV_ASSERT_DEVINS(pDevIns);
4887 NOREF(GCPhys); NOREF(pvHeap); NOREF(cbHeap);
4888 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4889 return VERR_ACCESS_DENIED;
4890}
4891
4892
4893/** @interface_method_impl{PDMDEVHLPR3,pfnFirmwareRegister} */
4894static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_FirmwareRegister(PPDMDEVINS pDevIns, PCPDMFWREG pFwReg, PCPDMFWHLPR3 *ppFwHlp)
4895{
4896 PDMDEV_ASSERT_DEVINS(pDevIns);
4897 NOREF(pFwReg); NOREF(ppFwHlp);
4898 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4899 return VERR_ACCESS_DENIED;
4900}
4901
4902
4903/** @interface_method_impl{PDMDEVHLPR3,pfnVMReset} */
4904static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMReset(PPDMDEVINS pDevIns, uint32_t fFlags)
4905{
4906 PDMDEV_ASSERT_DEVINS(pDevIns); NOREF(fFlags);
4907 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4908 return VERR_ACCESS_DENIED;
4909}
4910
4911
4912/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspend} */
4913static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspend(PPDMDEVINS pDevIns)
4914{
4915 PDMDEV_ASSERT_DEVINS(pDevIns);
4916 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4917 return VERR_ACCESS_DENIED;
4918}
4919
4920
4921/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
4922static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
4923{
4924 PDMDEV_ASSERT_DEVINS(pDevIns);
4925 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4926 return VERR_ACCESS_DENIED;
4927}
4928
4929
4930/** @interface_method_impl{PDMDEVHLPR3,pfnVMPowerOff} */
4931static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMPowerOff(PPDMDEVINS pDevIns)
4932{
4933 PDMDEV_ASSERT_DEVINS(pDevIns);
4934 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4935 return VERR_ACCESS_DENIED;
4936}
4937
4938
4939/** @interface_method_impl{PDMDEVHLPR3,pfnA20IsEnabled} */
4940static DECLCALLBACK(bool) pdmR3DevHlp_Untrusted_A20IsEnabled(PPDMDEVINS pDevIns)
4941{
4942 PDMDEV_ASSERT_DEVINS(pDevIns);
4943 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4944 return false;
4945}
4946
4947
4948/** @interface_method_impl{PDMDEVHLPR3,pfnA20Set} */
4949static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_A20Set(PPDMDEVINS pDevIns, bool fEnable)
4950{
4951 PDMDEV_ASSERT_DEVINS(pDevIns);
4952 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4953 NOREF(fEnable);
4954}
4955
4956
4957/** @interface_method_impl{PDMDEVHLPR3,pfnGetCpuId} */
4958static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_GetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf,
4959 uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
4960{
4961 PDMDEV_ASSERT_DEVINS(pDevIns);
4962 NOREF(iLeaf); NOREF(pEax); NOREF(pEbx); NOREF(pEcx); NOREF(pEdx);
4963 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4964}
4965
4966
4967/** @interface_method_impl{PDMDEVHLPR3,pfnGetSupDrvSession} */
4968static DECLCALLBACK(PSUPDRVSESSION) pdmR3DevHlp_Untrusted_GetSupDrvSession(PPDMDEVINS pDevIns)
4969{
4970 PDMDEV_ASSERT_DEVINS(pDevIns);
4971 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
4972 return (PSUPDRVSESSION)0;
4973}
4974
4975
4976/** @interface_method_impl{PDMDEVHLPR3,pfnQueryGenericUserObject} */
4977static DECLCALLBACK(void *) pdmR3DevHlp_Untrusted_QueryGenericUserObject(PPDMDEVINS pDevIns, PCRTUUID pUuid)
4978{
4979 PDMDEV_ASSERT_DEVINS(pDevIns);
4980 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d %RTuuid\n",
4981 pDevIns->pReg->szName, pDevIns->iInstance, pUuid));
4982 return NULL;
4983}
4984
4985
4986/** @interface_method_impl{PDMDEVHLPR3,pfnPGMHandlerPhysicalTypeRegister} */
4987static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_PGMHandlerPhysicalTypeRegister(PPDMDEVINS pDevIns, PGMPHYSHANDLERKIND enmKind,
4988 R3PTRTYPE(PFNPGMPHYSHANDLER) pfnHandlerR3,
4989 const char *pszHandlerR0, const char *pszPfHandlerR0,
4990 const char *pszHandlerRC, const char *pszPfHandlerRC,
4991 const char *pszDesc, PPGMPHYSHANDLERTYPE phType)
4992{
4993 PDMDEV_ASSERT_DEVINS(pDevIns);
4994 RT_NOREF(enmKind, pfnHandlerR3, pszHandlerR0, pszPfHandlerR0, pszHandlerRC, pszPfHandlerRC, pszDesc, phType);
4995 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n",
4996 pDevIns->pReg->szName, pDevIns->iInstance));
4997 return VERR_ACCESS_DENIED;
4998}
4999
5000
5001/**
5002 * The device helper structure for non-trusted devices.
5003 */
5004const PDMDEVHLPR3 g_pdmR3DevHlpUnTrusted =
5005{
5006 PDM_DEVHLPR3_VERSION,
5007 pdmR3DevHlp_IoPortCreateEx,
5008 pdmR3DevHlp_IoPortMap,
5009 pdmR3DevHlp_IoPortUnmap,
5010 pdmR3DevHlp_IoPortGetMappingAddress,
5011 pdmR3DevHlp_MmioCreateEx,
5012 pdmR3DevHlp_MmioMap,
5013 pdmR3DevHlp_MmioUnmap,
5014 pdmR3DevHlp_MmioReduce,
5015 pdmR3DevHlp_MmioGetMappingAddress,
5016 pdmR3DevHlp_Mmio2Create,
5017 pdmR3DevHlp_Mmio2Destroy,
5018 pdmR3DevHlp_Mmio2Map,
5019 pdmR3DevHlp_Mmio2Unmap,
5020 pdmR3DevHlp_Mmio2Reduce,
5021 pdmR3DevHlp_Mmio2GetMappingAddress,
5022 pdmR3DevHlp_Mmio2ChangeRegionNo,
5023 pdmR3DevHlp_ROMRegister,
5024 pdmR3DevHlp_ROMProtectShadow,
5025 pdmR3DevHlp_SSMRegister,
5026 SSMR3PutStruct,
5027 SSMR3PutStructEx,
5028 SSMR3PutBool,
5029 SSMR3PutU8,
5030 SSMR3PutS8,
5031 SSMR3PutU16,
5032 SSMR3PutS16,
5033 SSMR3PutU32,
5034 SSMR3PutS32,
5035 SSMR3PutU64,
5036 SSMR3PutS64,
5037 SSMR3PutU128,
5038 SSMR3PutS128,
5039 SSMR3PutUInt,
5040 SSMR3PutSInt,
5041 SSMR3PutGCUInt,
5042 SSMR3PutGCUIntReg,
5043 SSMR3PutGCPhys32,
5044 SSMR3PutGCPhys64,
5045 SSMR3PutGCPhys,
5046 SSMR3PutGCPtr,
5047 SSMR3PutGCUIntPtr,
5048 SSMR3PutRCPtr,
5049 SSMR3PutIOPort,
5050 SSMR3PutSel,
5051 SSMR3PutMem,
5052 SSMR3PutStrZ,
5053 SSMR3GetStruct,
5054 SSMR3GetStructEx,
5055 SSMR3GetBool,
5056 SSMR3GetBoolV,
5057 SSMR3GetU8,
5058 SSMR3GetU8V,
5059 SSMR3GetS8,
5060 SSMR3GetS8V,
5061 SSMR3GetU16,
5062 SSMR3GetU16V,
5063 SSMR3GetS16,
5064 SSMR3GetS16V,
5065 SSMR3GetU32,
5066 SSMR3GetU32V,
5067 SSMR3GetS32,
5068 SSMR3GetS32V,
5069 SSMR3GetU64,
5070 SSMR3GetU64V,
5071 SSMR3GetS64,
5072 SSMR3GetS64V,
5073 SSMR3GetU128,
5074 SSMR3GetU128V,
5075 SSMR3GetS128,
5076 SSMR3GetS128V,
5077 SSMR3GetGCPhys32,
5078 SSMR3GetGCPhys32V,
5079 SSMR3GetGCPhys64,
5080 SSMR3GetGCPhys64V,
5081 SSMR3GetGCPhys,
5082 SSMR3GetGCPhysV,
5083 SSMR3GetUInt,
5084 SSMR3GetSInt,
5085 SSMR3GetGCUInt,
5086 SSMR3GetGCUIntReg,
5087 SSMR3GetGCPtr,
5088 SSMR3GetGCUIntPtr,
5089 SSMR3GetRCPtr,
5090 SSMR3GetIOPort,
5091 SSMR3GetSel,
5092 SSMR3GetMem,
5093 SSMR3GetStrZ,
5094 SSMR3GetStrZEx,
5095 SSMR3Skip,
5096 SSMR3SkipToEndOfUnit,
5097 SSMR3SetLoadError,
5098 SSMR3SetLoadErrorV,
5099 SSMR3SetCfgError,
5100 SSMR3SetCfgErrorV,
5101 SSMR3HandleGetStatus,
5102 SSMR3HandleGetAfter,
5103 SSMR3HandleIsLiveSave,
5104 SSMR3HandleMaxDowntime,
5105 SSMR3HandleHostBits,
5106 SSMR3HandleRevision,
5107 SSMR3HandleVersion,
5108 SSMR3HandleHostOSAndArch,
5109 pdmR3DevHlp_TimerCreate,
5110 pdmR3DevHlp_TimerFromMicro,
5111 pdmR3DevHlp_TimerFromMilli,
5112 pdmR3DevHlp_TimerFromNano,
5113 pdmR3DevHlp_TimerGet,
5114 pdmR3DevHlp_TimerGetFreq,
5115 pdmR3DevHlp_TimerGetNano,
5116 pdmR3DevHlp_TimerIsActive,
5117 pdmR3DevHlp_TimerIsLockOwner,
5118 pdmR3DevHlp_TimerLockClock,
5119 pdmR3DevHlp_TimerLockClock2,
5120 pdmR3DevHlp_TimerSet,
5121 pdmR3DevHlp_TimerSetFrequencyHint,
5122 pdmR3DevHlp_TimerSetMicro,
5123 pdmR3DevHlp_TimerSetMillies,
5124 pdmR3DevHlp_TimerSetNano,
5125 pdmR3DevHlp_TimerSetRelative,
5126 pdmR3DevHlp_TimerStop,
5127 pdmR3DevHlp_TimerUnlockClock,
5128 pdmR3DevHlp_TimerUnlockClock2,
5129 pdmR3DevHlp_TimerSetCritSect,
5130 pdmR3DevHlp_TimerSave,
5131 pdmR3DevHlp_TimerLoad,
5132 pdmR3DevHlp_TimerDestroy,
5133 TMR3TimerSkip,
5134 pdmR3DevHlp_TMUtcNow,
5135 CFGMR3Exists,
5136 CFGMR3QueryType,
5137 CFGMR3QuerySize,
5138 CFGMR3QueryInteger,
5139 CFGMR3QueryIntegerDef,
5140 CFGMR3QueryString,
5141 CFGMR3QueryStringDef,
5142 CFGMR3QueryBytes,
5143 CFGMR3QueryU64,
5144 CFGMR3QueryU64Def,
5145 CFGMR3QueryS64,
5146 CFGMR3QueryS64Def,
5147 CFGMR3QueryU32,
5148 CFGMR3QueryU32Def,
5149 CFGMR3QueryS32,
5150 CFGMR3QueryS32Def,
5151 CFGMR3QueryU16,
5152 CFGMR3QueryU16Def,
5153 CFGMR3QueryS16,
5154 CFGMR3QueryS16Def,
5155 CFGMR3QueryU8,
5156 CFGMR3QueryU8Def,
5157 CFGMR3QueryS8,
5158 CFGMR3QueryS8Def,
5159 CFGMR3QueryBool,
5160 CFGMR3QueryBoolDef,
5161 CFGMR3QueryPort,
5162 CFGMR3QueryPortDef,
5163 CFGMR3QueryUInt,
5164 CFGMR3QueryUIntDef,
5165 CFGMR3QuerySInt,
5166 CFGMR3QuerySIntDef,
5167 CFGMR3QueryPtr,
5168 CFGMR3QueryPtrDef,
5169 CFGMR3QueryGCPtr,
5170 CFGMR3QueryGCPtrDef,
5171 CFGMR3QueryGCPtrU,
5172 CFGMR3QueryGCPtrUDef,
5173 CFGMR3QueryGCPtrS,
5174 CFGMR3QueryGCPtrSDef,
5175 CFGMR3QueryStringAlloc,
5176 CFGMR3QueryStringAllocDef,
5177 CFGMR3GetParent,
5178 CFGMR3GetChild,
5179 CFGMR3GetChildF,
5180 CFGMR3GetChildFV,
5181 CFGMR3GetFirstChild,
5182 CFGMR3GetNextChild,
5183 CFGMR3GetName,
5184 CFGMR3GetNameLen,
5185 CFGMR3AreChildrenValid,
5186 CFGMR3GetFirstValue,
5187 CFGMR3GetNextValue,
5188 CFGMR3GetValueName,
5189 CFGMR3GetValueNameLen,
5190 CFGMR3GetValueType,
5191 CFGMR3AreValuesValid,
5192 CFGMR3ValidateConfig,
5193 pdmR3DevHlp_PhysRead,
5194 pdmR3DevHlp_PhysWrite,
5195 pdmR3DevHlp_PhysGCPhys2CCPtr,
5196 pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
5197 pdmR3DevHlp_PhysReleasePageMappingLock,
5198 pdmR3DevHlp_PhysReadGCVirt,
5199 pdmR3DevHlp_PhysWriteGCVirt,
5200 pdmR3DevHlp_PhysGCPtr2GCPhys,
5201 pdmR3DevHlp_MMHeapAlloc,
5202 pdmR3DevHlp_MMHeapAllocZ,
5203 pdmR3DevHlp_MMHeapFree,
5204 pdmR3DevHlp_VMState,
5205 pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet,
5206 pdmR3DevHlp_VMSetError,
5207 pdmR3DevHlp_VMSetErrorV,
5208 pdmR3DevHlp_VMSetRuntimeError,
5209 pdmR3DevHlp_VMSetRuntimeErrorV,
5210 pdmR3DevHlp_DBGFStopV,
5211 pdmR3DevHlp_DBGFInfoRegister,
5212 pdmR3DevHlp_DBGFInfoRegisterArgv,
5213 pdmR3DevHlp_DBGFRegRegister,
5214 pdmR3DevHlp_DBGFTraceBuf,
5215 pdmR3DevHlp_STAMRegister,
5216 pdmR3DevHlp_STAMRegisterV,
5217 pdmR3DevHlp_PCIRegister,
5218 pdmR3DevHlp_PCIRegisterMsi,
5219 pdmR3DevHlp_PCIIORegionRegister,
5220 pdmR3DevHlp_PCIInterceptConfigAccesses,
5221 pdmR3DevHlp_PCIConfigWrite,
5222 pdmR3DevHlp_PCIConfigRead,
5223 pdmR3DevHlp_PCIPhysRead,
5224 pdmR3DevHlp_PCIPhysWrite,
5225 pdmR3DevHlp_PCIPhysGCPhys2CCPtr,
5226 pdmR3DevHlp_PCIPhysGCPhys2CCPtrReadOnly,
5227 pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtr,
5228 pdmR3DevHlp_PCIPhysBulkGCPhys2CCPtrReadOnly,
5229 pdmR3DevHlp_PCISetIrq,
5230 pdmR3DevHlp_PCISetIrqNoWait,
5231 pdmR3DevHlp_ISASetIrq,
5232 pdmR3DevHlp_ISASetIrqNoWait,
5233 pdmR3DevHlp_DriverAttach,
5234 pdmR3DevHlp_DriverDetach,
5235 pdmR3DevHlp_DriverReconfigure,
5236 pdmR3DevHlp_QueueCreatePtr,
5237 pdmR3DevHlp_QueueCreate,
5238 pdmR3DevHlp_QueueToPtr,
5239 pdmR3DevHlp_QueueAlloc,
5240 pdmR3DevHlp_QueueInsert,
5241 pdmR3DevHlp_QueueInsertEx,
5242 pdmR3DevHlp_QueueFlushIfNecessary,
5243 pdmR3DevHlp_TaskCreate,
5244 pdmR3DevHlp_TaskTrigger,
5245 pdmR3DevHlp_SUPSemEventCreate,
5246 pdmR3DevHlp_SUPSemEventClose,
5247 pdmR3DevHlp_SUPSemEventSignal,
5248 pdmR3DevHlp_SUPSemEventWaitNoResume,
5249 pdmR3DevHlp_SUPSemEventWaitNsAbsIntr,
5250 pdmR3DevHlp_SUPSemEventWaitNsRelIntr,
5251 pdmR3DevHlp_SUPSemEventGetResolution,
5252 pdmR3DevHlp_SUPSemEventMultiCreate,
5253 pdmR3DevHlp_SUPSemEventMultiClose,
5254 pdmR3DevHlp_SUPSemEventMultiSignal,
5255 pdmR3DevHlp_SUPSemEventMultiReset,
5256 pdmR3DevHlp_SUPSemEventMultiWaitNoResume,
5257 pdmR3DevHlp_SUPSemEventMultiWaitNsAbsIntr,
5258 pdmR3DevHlp_SUPSemEventMultiWaitNsRelIntr,
5259 pdmR3DevHlp_SUPSemEventMultiGetResolution,
5260 pdmR3DevHlp_CritSectInit,
5261 pdmR3DevHlp_CritSectGetNop,
5262 pdmR3DevHlp_CritSectGetNopR0,
5263 pdmR3DevHlp_CritSectGetNopRC,
5264 pdmR3DevHlp_SetDeviceCritSect,
5265 pdmR3DevHlp_CritSectYield,
5266 pdmR3DevHlp_CritSectEnter,
5267 pdmR3DevHlp_CritSectEnterDebug,
5268 pdmR3DevHlp_CritSectTryEnter,
5269 pdmR3DevHlp_CritSectTryEnterDebug,
5270 pdmR3DevHlp_CritSectLeave,
5271 pdmR3DevHlp_CritSectIsOwner,
5272 pdmR3DevHlp_CritSectIsInitialized,
5273 pdmR3DevHlp_CritSectHasWaiters,
5274 pdmR3DevHlp_CritSectGetRecursion,
5275 pdmR3DevHlp_CritSectScheduleExitEvent,
5276 pdmR3DevHlp_CritSectDelete,
5277 pdmR3DevHlp_ThreadCreate,
5278 PDMR3ThreadDestroy,
5279 PDMR3ThreadIAmSuspending,
5280 PDMR3ThreadIAmRunning,
5281 PDMR3ThreadSleep,
5282 PDMR3ThreadSuspend,
5283 PDMR3ThreadResume,
5284 pdmR3DevHlp_SetAsyncNotification,
5285 pdmR3DevHlp_AsyncNotificationCompleted,
5286 pdmR3DevHlp_RTCRegister,
5287 pdmR3DevHlp_PCIBusRegister,
5288 pdmR3DevHlp_IommuRegister,
5289 pdmR3DevHlp_PICRegister,
5290 pdmR3DevHlp_ApicRegister,
5291 pdmR3DevHlp_IoApicRegister,
5292 pdmR3DevHlp_HpetRegister,
5293 pdmR3DevHlp_PciRawRegister,
5294 pdmR3DevHlp_DMACRegister,
5295 pdmR3DevHlp_DMARegister,
5296 pdmR3DevHlp_DMAReadMemory,
5297 pdmR3DevHlp_DMAWriteMemory,
5298 pdmR3DevHlp_DMASetDREQ,
5299 pdmR3DevHlp_DMAGetChannelMode,
5300 pdmR3DevHlp_DMASchedule,
5301 pdmR3DevHlp_CMOSWrite,
5302 pdmR3DevHlp_CMOSRead,
5303 pdmR3DevHlp_AssertEMT,
5304 pdmR3DevHlp_AssertOther,
5305 pdmR3DevHlp_LdrGetRCInterfaceSymbols,
5306 pdmR3DevHlp_LdrGetR0InterfaceSymbols,
5307 pdmR3DevHlp_CallR0,
5308 pdmR3DevHlp_VMGetSuspendReason,
5309 pdmR3DevHlp_VMGetResumeReason,
5310 pdmR3DevHlp_PhysBulkGCPhys2CCPtr,
5311 pdmR3DevHlp_PhysBulkGCPhys2CCPtrReadOnly,
5312 pdmR3DevHlp_PhysBulkReleasePageMappingLocks,
5313 pdmR3DevHlp_CpuGetGuestMicroarch,
5314 pdmR3DevHlp_CpuGetGuestAddrWidths,
5315 pdmR3DevHlp_STAMDeregisterByPrefix,
5316 0,
5317 0,
5318 0,
5319 0,
5320 0,
5321 0,
5322 0,
5323 0,
5324 0,
5325 pdmR3DevHlp_Untrusted_GetUVM,
5326 pdmR3DevHlp_Untrusted_GetVM,
5327 pdmR3DevHlp_Untrusted_GetVMCPU,
5328 pdmR3DevHlp_Untrusted_GetCurrentCpuId,
5329 pdmR3DevHlp_Untrusted_RegisterVMMDevHeap,
5330 pdmR3DevHlp_Untrusted_FirmwareRegister,
5331 pdmR3DevHlp_Untrusted_VMReset,
5332 pdmR3DevHlp_Untrusted_VMSuspend,
5333 pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff,
5334 pdmR3DevHlp_Untrusted_VMPowerOff,
5335 pdmR3DevHlp_Untrusted_A20IsEnabled,
5336 pdmR3DevHlp_Untrusted_A20Set,
5337 pdmR3DevHlp_Untrusted_GetCpuId,
5338 pdmR3DevHlp_TMTimeVirtGet,
5339 pdmR3DevHlp_TMTimeVirtGetFreq,
5340 pdmR3DevHlp_TMTimeVirtGetNano,
5341 pdmR3DevHlp_Untrusted_GetSupDrvSession,
5342 pdmR3DevHlp_Untrusted_QueryGenericUserObject,
5343 pdmR3DevHlp_Untrusted_PGMHandlerPhysicalTypeRegister,
5344 PDM_DEVHLPR3_VERSION /* the end */
5345};
5346
5347
5348
5349/**
5350 * Queue consumer callback for internal component.
5351 *
5352 * @returns Success indicator.
5353 * If false the item will not be removed and the flushing will stop.
5354 * @param pVM The cross context VM structure.
5355 * @param pItem The item to consume. Upon return this item will be freed.
5356 */
5357DECLCALLBACK(bool) pdmR3DevHlpQueueConsumer(PVM pVM, PPDMQUEUEITEMCORE pItem)
5358{
5359 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)pItem;
5360 LogFlow(("pdmR3DevHlpQueueConsumer: enmOp=%d pDevIns=%p\n", pTask->enmOp, pTask->pDevInsR3));
5361 switch (pTask->enmOp)
5362 {
5363 case PDMDEVHLPTASKOP_ISA_SET_IRQ:
5364 PDMIsaSetIrq(pVM, pTask->u.IsaSetIRQ.iIrq, pTask->u.IsaSetIRQ.iLevel, pTask->u.IsaSetIRQ.uTagSrc);
5365 break;
5366
5367 case PDMDEVHLPTASKOP_PCI_SET_IRQ:
5368 {
5369 /* Same as pdmR3DevHlp_PCISetIrq, except we've got a tag already. */
5370 PPDMPCIDEV pPciDev = pTask->u.PciSetIRQ.pPciDevR3;
5371 if (pPciDev)
5372 {
5373 size_t const idxBus = pPciDev->Int.s.idxPdmBus;
5374 AssertBreak(idxBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses));
5375 PPDMPCIBUS pBus = &pVM->pdm.s.aPciBuses[idxBus];
5376
5377 pdmLock(pVM);
5378 pBus->pfnSetIrqR3(pBus->pDevInsR3, pPciDev, pTask->u.PciSetIRQ.iIrq,
5379 pTask->u.PciSetIRQ.iLevel, pTask->u.PciSetIRQ.uTagSrc);
5380 pdmUnlock(pVM);
5381 }
5382 else
5383 AssertReleaseMsgFailed(("No PCI device registered!\n"));
5384 break;
5385 }
5386
5387 case PDMDEVHLPTASKOP_IOAPIC_SET_IRQ:
5388 {
5389 PDMIoApicSetIrq(pVM, pTask->u.IoApicSetIRQ.uBusDevFn, pTask->u.IoApicSetIRQ.iIrq, pTask->u.IoApicSetIRQ.iLevel,
5390 pTask->u.IoApicSetIRQ.uTagSrc);
5391 break;
5392 }
5393
5394 default:
5395 AssertReleaseMsgFailed(("Invalid operation %d\n", pTask->enmOp));
5396 break;
5397 }
5398 return true;
5399}
5400
5401/** @} */
5402
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