VirtualBox

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

Last change on this file since 44898 was 44898, checked in by vboxsync, 12 years ago

missing x.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 149.9 KB
Line 
1/* $Id: PDMDevHlp.cpp 44898 2013-03-01 22:26:49Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, Device Helpers.
4 */
5
6/*
7 * Copyright (C) 2006-2013 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#include "PDMInternal.h"
24#include <VBox/vmm/pdm.h>
25#include <VBox/vmm/mm.h>
26#include <VBox/vmm/pgm.h>
27#include <VBox/vmm/iom.h>
28#ifdef VBOX_WITH_REM
29# include <VBox/vmm/rem.h>
30#endif
31#include <VBox/vmm/dbgf.h>
32#include <VBox/vmm/vmapi.h>
33#include <VBox/vmm/vm.h>
34#include <VBox/vmm/uvm.h>
35#include <VBox/vmm/vmm.h>
36
37#include <VBox/version.h>
38#include <VBox/log.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
46#include "dtrace/VBoxVMM.h"
47#include "PDMInline.h"
48
49
50/*******************************************************************************
51* Defined Constants And Macros *
52*******************************************************************************/
53/** @def PDM_DEVHLP_DEADLOCK_DETECTION
54 * Define this to enable the deadlock detection when accessing physical memory.
55 */
56#if /*defined(DEBUG_bird) ||*/ defined(DOXYGEN_RUNNING)
57# define PDM_DEVHLP_DEADLOCK_DETECTION /**< @todo enable DevHlp deadlock detection! */
58#endif
59
60
61
62/**
63 * Wrapper around PDMR3LdrGetSymbolRCLazy.
64 */
65DECLINLINE(int) pdmR3DevGetSymbolRCLazy(PPDMDEVINS pDevIns, const char *pszSymbol, PRTRCPTR ppvValue)
66{
67 return PDMR3LdrGetSymbolRCLazy(pDevIns->Internal.s.pVMR3,
68 pDevIns->Internal.s.pDevR3->pReg->szRCMod,
69 pDevIns->Internal.s.pDevR3->pszRCSearchPath,
70 pszSymbol, ppvValue);
71}
72
73
74/**
75 * Wrapper around PDMR3LdrGetSymbolR0Lazy.
76 */
77DECLINLINE(int) pdmR3DevGetSymbolR0Lazy(PPDMDEVINS pDevIns, const char *pszSymbol, PRTR0PTR ppvValue)
78{
79 return PDMR3LdrGetSymbolR0Lazy(pDevIns->Internal.s.pVMR3,
80 pDevIns->Internal.s.pDevR3->pReg->szR0Mod,
81 pDevIns->Internal.s.pDevR3->pszR0SearchPath,
82 pszSymbol, ppvValue);
83}
84
85
86/** @name R3 DevHlp
87 * @{
88 */
89
90
91/** @interface_method_impl{PDMDEVHLPR3,pfnIOPortRegister} */
92static DECLCALLBACK(int) pdmR3DevHlp_IOPortRegister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser, PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
93 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc)
94{
95 PDMDEV_ASSERT_DEVINS(pDevIns);
96 LogFlow(("pdmR3DevHlp_IOPortRegister: caller='%s'/%d: Port=%#x cPorts=%#x pvUser=%p pfnOut=%p pfnIn=%p pfnOutStr=%p pfnInStr=%p p32_tszDesc=%p:{%s}\n", pDevIns->pReg->szName, pDevIns->iInstance,
97 Port, cPorts, pvUser, pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc, pszDesc));
98 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
99
100#if 0 /** @todo needs a real string cache for this */
101 if (pDevIns->iInstance > 0)
102 {
103 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
104 if (pszDesc2)
105 pszDesc = pszDesc2;
106 }
107#endif
108
109 int rc = IOMR3IOPortRegisterR3(pDevIns->Internal.s.pVMR3, pDevIns, Port, cPorts, pvUser,
110 pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc);
111
112 LogFlow(("pdmR3DevHlp_IOPortRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
113 return rc;
114}
115
116
117/** @interface_method_impl{PDMDEVHLPR3,pfnIOPortRegisterRC} */
118static DECLCALLBACK(int) pdmR3DevHlp_IOPortRegisterRC(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
119 const char *pszOut, const char *pszIn,
120 const char *pszOutStr, const char *pszInStr, const char *pszDesc)
121{
122 PDMDEV_ASSERT_DEVINS(pDevIns);
123 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
124 LogFlow(("pdmR3DevHlp_IOPortRegisterRC: caller='%s'/%d: Port=%#x cPorts=%#x pvUser=%p pszOut=%p:{%s} pszIn=%p:{%s} pszOutStr=%p:{%s} pszInStr=%p:{%s} pszDesc=%p:{%s}\n", pDevIns->pReg->szName, pDevIns->iInstance,
125 Port, cPorts, pvUser, pszOut, pszOut, pszIn, pszIn, pszOutStr, pszOutStr, pszInStr, pszInStr, pszDesc, pszDesc));
126
127 /*
128 * Resolve the functions (one of the can be NULL).
129 */
130 int rc = VINF_SUCCESS;
131 if ( pDevIns->pReg->szRCMod[0]
132 && (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC))
133 {
134 RTRCPTR RCPtrIn = NIL_RTRCPTR;
135 if (pszIn)
136 {
137 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pszIn, &RCPtrIn);
138 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszIn)\n", pDevIns->pReg->szRCMod, pszIn));
139 }
140 RTRCPTR RCPtrOut = NIL_RTRCPTR;
141 if (pszOut && RT_SUCCESS(rc))
142 {
143 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pszOut, &RCPtrOut);
144 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszOut)\n", pDevIns->pReg->szRCMod, pszOut));
145 }
146 RTRCPTR RCPtrInStr = NIL_RTRCPTR;
147 if (pszInStr && RT_SUCCESS(rc))
148 {
149 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pszInStr, &RCPtrInStr);
150 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszInStr)\n", pDevIns->pReg->szRCMod, pszInStr));
151 }
152 RTRCPTR RCPtrOutStr = NIL_RTRCPTR;
153 if (pszOutStr && RT_SUCCESS(rc))
154 {
155 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pszOutStr, &RCPtrOutStr);
156 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszOutStr)\n", pDevIns->pReg->szRCMod, pszOutStr));
157 }
158
159 if (RT_SUCCESS(rc))
160 {
161#if 0 /** @todo needs a real string cache for this */
162 if (pDevIns->iInstance > 0)
163 {
164 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
165 if (pszDesc2)
166 pszDesc = pszDesc2;
167 }
168#endif
169
170 rc = IOMR3IOPortRegisterRC(pDevIns->Internal.s.pVMR3, pDevIns, Port, cPorts, pvUser, RCPtrOut, RCPtrIn, RCPtrOutStr, RCPtrInStr, pszDesc);
171 }
172 }
173 else
174 {
175 AssertMsgFailed(("No GC module for this driver!\n"));
176 rc = VERR_INVALID_PARAMETER;
177 }
178
179 LogFlow(("pdmR3DevHlp_IOPortRegisterRC: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
180 return rc;
181}
182
183
184/** @interface_method_impl{PDMDEVHLPR3,pfnIOPortRegisterR0} */
185static DECLCALLBACK(int) pdmR3DevHlp_IOPortRegisterR0(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
186 const char *pszOut, const char *pszIn,
187 const char *pszOutStr, const char *pszInStr, const char *pszDesc)
188{
189 PDMDEV_ASSERT_DEVINS(pDevIns);
190 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
191 LogFlow(("pdmR3DevHlp_IOPortRegisterR0: caller='%s'/%d: Port=%#x cPorts=%#x pvUser=%p pszOut=%p:{%s} pszIn=%p:{%s} pszOutStr=%p:{%s} pszInStr=%p:{%s} pszDesc=%p:{%s}\n", pDevIns->pReg->szName, pDevIns->iInstance,
192 Port, cPorts, pvUser, pszOut, pszOut, pszIn, pszIn, pszOutStr, pszOutStr, pszInStr, pszInStr, pszDesc, pszDesc));
193
194 /*
195 * Resolve the functions (one of the can be NULL).
196 */
197 int rc = VINF_SUCCESS;
198 if ( pDevIns->pReg->szR0Mod[0]
199 && (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0))
200 {
201 R0PTRTYPE(PFNIOMIOPORTIN) pfnR0PtrIn = 0;
202 if (pszIn)
203 {
204 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pszIn, &pfnR0PtrIn);
205 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszIn)\n", pDevIns->pReg->szR0Mod, pszIn));
206 }
207 R0PTRTYPE(PFNIOMIOPORTOUT) pfnR0PtrOut = 0;
208 if (pszOut && RT_SUCCESS(rc))
209 {
210 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pszOut, &pfnR0PtrOut);
211 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszOut)\n", pDevIns->pReg->szR0Mod, pszOut));
212 }
213 R0PTRTYPE(PFNIOMIOPORTINSTRING) pfnR0PtrInStr = 0;
214 if (pszInStr && RT_SUCCESS(rc))
215 {
216 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pszInStr, &pfnR0PtrInStr);
217 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszInStr)\n", pDevIns->pReg->szR0Mod, pszInStr));
218 }
219 R0PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnR0PtrOutStr = 0;
220 if (pszOutStr && RT_SUCCESS(rc))
221 {
222 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pszOutStr, &pfnR0PtrOutStr);
223 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszOutStr)\n", pDevIns->pReg->szR0Mod, pszOutStr));
224 }
225
226 if (RT_SUCCESS(rc))
227 {
228#if 0 /** @todo needs a real string cache for this */
229 if (pDevIns->iInstance > 0)
230 {
231 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
232 if (pszDesc2)
233 pszDesc = pszDesc2;
234 }
235#endif
236
237 rc = IOMR3IOPortRegisterR0(pDevIns->Internal.s.pVMR3, pDevIns, Port, cPorts, pvUser, pfnR0PtrOut, pfnR0PtrIn, pfnR0PtrOutStr, pfnR0PtrInStr, pszDesc);
238 }
239 }
240 else
241 {
242 AssertMsgFailed(("No R0 module for this driver!\n"));
243 rc = VERR_INVALID_PARAMETER;
244 }
245
246 LogFlow(("pdmR3DevHlp_IOPortRegisterR0: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
247 return rc;
248}
249
250
251/** @interface_method_impl{PDMDEVHLPR3,pfnIOPortDeregister} */
252static DECLCALLBACK(int) pdmR3DevHlp_IOPortDeregister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts)
253{
254 PDMDEV_ASSERT_DEVINS(pDevIns);
255 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
256 LogFlow(("pdmR3DevHlp_IOPortDeregister: caller='%s'/%d: Port=%#x cPorts=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance,
257 Port, cPorts));
258
259 int rc = IOMR3IOPortDeregister(pDevIns->Internal.s.pVMR3, pDevIns, Port, cPorts);
260
261 LogFlow(("pdmR3DevHlp_IOPortDeregister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
262 return rc;
263}
264
265
266/** @interface_method_impl{PDMDEVHLPR3,pfnMMIORegister} */
267static DECLCALLBACK(int) pdmR3DevHlp_MMIORegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
268 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
269 uint32_t fFlags, const char *pszDesc)
270{
271 PDMDEV_ASSERT_DEVINS(pDevIns);
272 PVM pVM = pDevIns->Internal.s.pVMR3;
273 VM_ASSERT_EMT(pVM);
274 LogFlow(("pdmR3DevHlp_MMIORegister: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x pvUser=%p pfnWrite=%p pfnRead=%p pfnFill=%p fFlags=%#x pszDesc=%p:{%s}\n",
275 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, pfnFill, pszDesc, fFlags, pszDesc));
276
277 if (pDevIns->iInstance > 0)
278 {
279 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
280 if (pszDesc2)
281 pszDesc = pszDesc2;
282 }
283
284 int rc = IOMR3MmioRegisterR3(pVM, pDevIns, GCPhysStart, cbRange, pvUser,
285 pfnWrite, pfnRead, pfnFill, fFlags, pszDesc);
286
287 LogFlow(("pdmR3DevHlp_MMIORegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
288 return rc;
289}
290
291
292/** @interface_method_impl{PDMDEVHLPR3,pfnMMIORegisterRC} */
293static DECLCALLBACK(int) pdmR3DevHlp_MMIORegisterRC(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTRCPTR pvUser,
294 const char *pszWrite, const char *pszRead, const char *pszFill)
295{
296 PDMDEV_ASSERT_DEVINS(pDevIns);
297 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
298 LogFlow(("pdmR3DevHlp_MMIORegisterRC: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x pvUser=%p pszWrite=%p:{%s} pszRead=%p:{%s} pszFill=%p:{%s}\n",
299 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange, pvUser, pszWrite, pszWrite, pszRead, pszRead, pszFill, pszFill));
300
301
302 /*
303 * Resolve the functions.
304 * Not all function have to present, leave it to IOM to enforce this.
305 */
306 int rc = VINF_SUCCESS;
307 if ( pDevIns->pReg->szRCMod[0]
308 && (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC))
309 {
310 RTRCPTR RCPtrWrite = NIL_RTRCPTR;
311 if (pszWrite)
312 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pszWrite, &RCPtrWrite);
313
314 RTRCPTR RCPtrRead = NIL_RTRCPTR;
315 int rc2 = VINF_SUCCESS;
316 if (pszRead)
317 rc2 = pdmR3DevGetSymbolRCLazy(pDevIns, pszRead, &RCPtrRead);
318
319 RTRCPTR RCPtrFill = NIL_RTRCPTR;
320 int rc3 = VINF_SUCCESS;
321 if (pszFill)
322 rc3 = pdmR3DevGetSymbolRCLazy(pDevIns, pszFill, &RCPtrFill);
323
324 if (RT_SUCCESS(rc) && RT_SUCCESS(rc2) && RT_SUCCESS(rc3))
325 rc = IOMR3MmioRegisterRC(pDevIns->Internal.s.pVMR3, pDevIns, GCPhysStart, cbRange, pvUser, RCPtrWrite, RCPtrRead, RCPtrFill);
326 else
327 {
328 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszWrite)\n", pDevIns->pReg->szRCMod, pszWrite));
329 AssertMsgRC(rc2, ("Failed to resolve %s.%s (pszRead)\n", pDevIns->pReg->szRCMod, pszRead));
330 AssertMsgRC(rc3, ("Failed to resolve %s.%s (pszFill)\n", pDevIns->pReg->szRCMod, pszFill));
331 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
332 rc = rc2;
333 if (RT_FAILURE(rc3) && RT_SUCCESS(rc))
334 rc = rc3;
335 }
336 }
337 else
338 {
339 AssertMsgFailed(("No GC module for this driver!\n"));
340 rc = VERR_INVALID_PARAMETER;
341 }
342
343 LogFlow(("pdmR3DevHlp_MMIORegisterRC: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
344 return rc;
345}
346
347/** @interface_method_impl{PDMDEVHLPR3,pfnMMIORegisterR0} */
348static DECLCALLBACK(int) pdmR3DevHlp_MMIORegisterR0(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
349 const char *pszWrite, const char *pszRead, const char *pszFill)
350{
351 PDMDEV_ASSERT_DEVINS(pDevIns);
352 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
353 LogFlow(("pdmR3DevHlp_MMIORegisterHC: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x pvUser=%p pszWrite=%p:{%s} pszRead=%p:{%s} pszFill=%p:{%s}\n",
354 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange, pvUser, pszWrite, pszWrite, pszRead, pszRead, pszFill, pszFill));
355
356 /*
357 * Resolve the functions.
358 * Not all function have to present, leave it to IOM to enforce this.
359 */
360 int rc = VINF_SUCCESS;
361 if ( pDevIns->pReg->szR0Mod[0]
362 && (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0))
363 {
364 R0PTRTYPE(PFNIOMMMIOWRITE) pfnR0PtrWrite = 0;
365 if (pszWrite)
366 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pszWrite, &pfnR0PtrWrite);
367 R0PTRTYPE(PFNIOMMMIOREAD) pfnR0PtrRead = 0;
368 int rc2 = VINF_SUCCESS;
369 if (pszRead)
370 rc2 = pdmR3DevGetSymbolR0Lazy(pDevIns, pszRead, &pfnR0PtrRead);
371 R0PTRTYPE(PFNIOMMMIOFILL) pfnR0PtrFill = 0;
372 int rc3 = VINF_SUCCESS;
373 if (pszFill)
374 rc3 = pdmR3DevGetSymbolR0Lazy(pDevIns, pszFill, &pfnR0PtrFill);
375 if (RT_SUCCESS(rc) && RT_SUCCESS(rc2) && RT_SUCCESS(rc3))
376 rc = IOMR3MmioRegisterR0(pDevIns->Internal.s.pVMR3, pDevIns, GCPhysStart, cbRange, pvUser, pfnR0PtrWrite, pfnR0PtrRead, pfnR0PtrFill);
377 else
378 {
379 AssertMsgRC(rc, ("Failed to resolve %s.%s (pszWrite)\n", pDevIns->pReg->szR0Mod, pszWrite));
380 AssertMsgRC(rc2, ("Failed to resolve %s.%s (pszRead)\n", pDevIns->pReg->szR0Mod, pszRead));
381 AssertMsgRC(rc3, ("Failed to resolve %s.%s (pszFill)\n", pDevIns->pReg->szR0Mod, pszFill));
382 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
383 rc = rc2;
384 if (RT_FAILURE(rc3) && RT_SUCCESS(rc))
385 rc = rc3;
386 }
387 }
388 else
389 {
390 AssertMsgFailed(("No R0 module for this driver!\n"));
391 rc = VERR_INVALID_PARAMETER;
392 }
393
394 LogFlow(("pdmR3DevHlp_MMIORegisterR0: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
395 return rc;
396}
397
398
399/** @interface_method_impl{PDMDEVHLPR3,pfnMMIODeregister} */
400static DECLCALLBACK(int) pdmR3DevHlp_MMIODeregister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange)
401{
402 PDMDEV_ASSERT_DEVINS(pDevIns);
403 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
404 LogFlow(("pdmR3DevHlp_MMIODeregister: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x\n",
405 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange));
406
407 int rc = IOMR3MmioDeregister(pDevIns->Internal.s.pVMR3, pDevIns, GCPhysStart, cbRange);
408
409 LogFlow(("pdmR3DevHlp_MMIODeregister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
410 return rc;
411}
412
413
414/**
415 * @copydoc PDMDEVHLPR3::pfnMMIO2Register
416 */
417static DECLCALLBACK(int) pdmR3DevHlp_MMIO2Register(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc)
418{
419 PDMDEV_ASSERT_DEVINS(pDevIns);
420 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
421 LogFlow(("pdmR3DevHlp_MMIO2Register: caller='%s'/%d: iRegion=%#x cb=%#RGp fFlags=%RX32 ppv=%p pszDescp=%p:{%s}\n",
422 pDevIns->pReg->szName, pDevIns->iInstance, iRegion, cb, fFlags, ppv, pszDesc, pszDesc));
423
424/** @todo PGMR3PhysMMIO2Register mangles the description, move it here and
425 * use a real string cache. */
426 int rc = PGMR3PhysMMIO2Register(pDevIns->Internal.s.pVMR3, pDevIns, iRegion, cb, fFlags, ppv, pszDesc);
427
428 LogFlow(("pdmR3DevHlp_MMIO2Register: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
429 return rc;
430}
431
432
433/**
434 * @copydoc PDMDEVHLPR3::pfnMMIO2Deregister
435 */
436static DECLCALLBACK(int) pdmR3DevHlp_MMIO2Deregister(PPDMDEVINS pDevIns, uint32_t iRegion)
437{
438 PDMDEV_ASSERT_DEVINS(pDevIns);
439 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
440 LogFlow(("pdmR3DevHlp_MMIO2Deregister: caller='%s'/%d: iRegion=%#x\n",
441 pDevIns->pReg->szName, pDevIns->iInstance, iRegion));
442
443 AssertReturn(iRegion == UINT32_MAX, VERR_INVALID_PARAMETER);
444
445 int rc = PGMR3PhysMMIO2Deregister(pDevIns->Internal.s.pVMR3, pDevIns, iRegion);
446
447 LogFlow(("pdmR3DevHlp_MMIO2Deregister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
448 return rc;
449}
450
451
452/**
453 * @copydoc PDMDEVHLPR3::pfnMMIO2Map
454 */
455static DECLCALLBACK(int) pdmR3DevHlp_MMIO2Map(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
456{
457 PDMDEV_ASSERT_DEVINS(pDevIns);
458 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
459 LogFlow(("pdmR3DevHlp_MMIO2Map: caller='%s'/%d: iRegion=%#x GCPhys=%#RGp\n",
460 pDevIns->pReg->szName, pDevIns->iInstance, iRegion, GCPhys));
461
462 int rc = PGMR3PhysMMIO2Map(pDevIns->Internal.s.pVMR3, pDevIns, iRegion, GCPhys);
463
464 LogFlow(("pdmR3DevHlp_MMIO2Map: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
465 return rc;
466}
467
468
469/**
470 * @copydoc PDMDEVHLPR3::pfnMMIO2Unmap
471 */
472static DECLCALLBACK(int) pdmR3DevHlp_MMIO2Unmap(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
473{
474 PDMDEV_ASSERT_DEVINS(pDevIns);
475 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
476 LogFlow(("pdmR3DevHlp_MMIO2Unmap: caller='%s'/%d: iRegion=%#x GCPhys=%#RGp\n",
477 pDevIns->pReg->szName, pDevIns->iInstance, iRegion, GCPhys));
478
479 int rc = PGMR3PhysMMIO2Unmap(pDevIns->Internal.s.pVMR3, pDevIns, iRegion, GCPhys);
480
481 LogFlow(("pdmR3DevHlp_MMIO2Unmap: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
482 return rc;
483}
484
485
486/**
487 * @copydoc PDMDEVHLPR3::pfnMMHyperMapMMIO2
488 */
489static DECLCALLBACK(int) pdmR3DevHlp_MMHyperMapMMIO2(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
490 const char *pszDesc, PRTRCPTR pRCPtr)
491{
492 PDMDEV_ASSERT_DEVINS(pDevIns);
493 PVM pVM = pDevIns->Internal.s.pVMR3;
494 VM_ASSERT_EMT(pVM);
495 LogFlow(("pdmR3DevHlp_MMHyperMapMMIO2: caller='%s'/%d: iRegion=%#x off=%RGp cb=%RGp pszDesc=%p:{%s} pRCPtr=%p\n",
496 pDevIns->pReg->szName, pDevIns->iInstance, iRegion, off, cb, pszDesc, pszDesc, pRCPtr));
497
498 if (pDevIns->iInstance > 0)
499 {
500 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
501 if (pszDesc2)
502 pszDesc = pszDesc2;
503 }
504
505 int rc = MMR3HyperMapMMIO2(pVM, pDevIns, iRegion, off, cb, pszDesc, pRCPtr);
506
507 LogFlow(("pdmR3DevHlp_MMHyperMapMMIO2: caller='%s'/%d: returns %Rrc *pRCPtr=%RRv\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *pRCPtr));
508 return rc;
509}
510
511
512/**
513 * @copydoc PDMDEVHLPR3::pfnMMIO2MapKernel
514 */
515static DECLCALLBACK(int) pdmR3DevHlp_MMIO2MapKernel(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
516 const char *pszDesc, PRTR0PTR pR0Ptr)
517{
518 PDMDEV_ASSERT_DEVINS(pDevIns);
519 PVM pVM = pDevIns->Internal.s.pVMR3;
520 VM_ASSERT_EMT(pVM);
521 LogFlow(("pdmR3DevHlp_MMIO2MapKernel: caller='%s'/%d: iRegion=%#x off=%RGp cb=%RGp pszDesc=%p:{%s} pR0Ptr=%p\n",
522 pDevIns->pReg->szName, pDevIns->iInstance, iRegion, off, cb, pszDesc, pszDesc, pR0Ptr));
523
524 if (pDevIns->iInstance > 0)
525 {
526 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
527 if (pszDesc2)
528 pszDesc = pszDesc2;
529 }
530
531 int rc = PGMR3PhysMMIO2MapKernel(pVM, pDevIns, iRegion, off, cb, pszDesc, pR0Ptr);
532
533 LogFlow(("pdmR3DevHlp_MMIO2MapKernel: caller='%s'/%d: returns %Rrc *pR0Ptr=%RHv\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *pR0Ptr));
534 return rc;
535}
536
537
538/** @interface_method_impl{PDMDEVHLPR3,pfnROMRegister} */
539static DECLCALLBACK(int) pdmR3DevHlp_ROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
540 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc)
541{
542 PDMDEV_ASSERT_DEVINS(pDevIns);
543 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
544 LogFlow(("pdmR3DevHlp_ROMRegister: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x pvBinary=%p cbBinary=%#x fFlags=%#RX32 pszDesc=%p:{%s}\n",
545 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc, pszDesc));
546
547/** @todo can we mangle pszDesc? */
548 int rc = PGMR3PhysRomRegister(pDevIns->Internal.s.pVMR3, pDevIns, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc);
549
550 LogFlow(("pdmR3DevHlp_ROMRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
551 return rc;
552}
553
554
555/** @interface_method_impl{PDMDEVHLPR3,pfnROMProtectShadow} */
556static DECLCALLBACK(int) pdmR3DevHlp_ROMProtectShadow(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt)
557{
558 PDMDEV_ASSERT_DEVINS(pDevIns);
559 LogFlow(("pdmR3DevHlp_ROMProtectShadow: caller='%s'/%d: GCPhysStart=%RGp cbRange=%#x enmProt=%d\n",
560 pDevIns->pReg->szName, pDevIns->iInstance, GCPhysStart, cbRange, enmProt));
561
562 int rc = PGMR3PhysRomProtect(pDevIns->Internal.s.pVMR3, GCPhysStart, cbRange, enmProt);
563
564 LogFlow(("pdmR3DevHlp_ROMProtectShadow: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
565 return rc;
566}
567
568
569/** @interface_method_impl{PDMDEVHLPR3,pfnSSMRegister} */
570static DECLCALLBACK(int) pdmR3DevHlp_SSMRegister(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
571 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
572 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
573 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
574{
575 PDMDEV_ASSERT_DEVINS(pDevIns);
576 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
577 LogFlow(("pdmR3DevHlp_SSMRegister: caller='%s'/%d: uVersion=#x cbGuess=%#x pszBefore=%p:{%s}\n"
578 " pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoadDone=%p\n",
579 pDevIns->pReg->szName, pDevIns->iInstance, uVersion, cbGuess, pszBefore, pszBefore,
580 pfnLivePrep, pfnLiveExec, pfnLiveVote,
581 pfnSavePrep, pfnSaveExec, pfnSaveDone,
582 pfnLoadPrep, pfnLoadExec, pfnLoadDone));
583
584 int rc = SSMR3RegisterDevice(pDevIns->Internal.s.pVMR3, pDevIns, pDevIns->pReg->szName, pDevIns->iInstance,
585 uVersion, cbGuess, pszBefore,
586 pfnLivePrep, pfnLiveExec, pfnLiveVote,
587 pfnSavePrep, pfnSaveExec, pfnSaveDone,
588 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
589
590 LogFlow(("pdmR3DevHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
591 return rc;
592}
593
594
595/** @interface_method_impl{PDMDEVHLPR3,pfnTMTimerCreate} */
596static DECLCALLBACK(int) pdmR3DevHlp_TMTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
597{
598 PDMDEV_ASSERT_DEVINS(pDevIns);
599 PVM pVM = pDevIns->Internal.s.pVMR3;
600 VM_ASSERT_EMT(pVM);
601 LogFlow(("pdmR3DevHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} ppTimer=%p\n",
602 pDevIns->pReg->szName, pDevIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, ppTimer));
603
604 if (pDevIns->iInstance > 0) /** @todo use a string cache here later. */
605 {
606 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s [%u]", pszDesc, pDevIns->iInstance);
607 if (pszDesc2)
608 pszDesc = pszDesc2;
609 }
610
611 int rc = TMR3TimerCreateDevice(pVM, pDevIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
612
613 LogFlow(("pdmR3DevHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
614 return rc;
615}
616
617
618/** @interface_method_impl{PDMDEVHLPR3,pfnTMUtcNow} */
619static DECLCALLBACK(PRTTIMESPEC) pdmR3DevHlp_TMUtcNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
620{
621 PDMDEV_ASSERT_DEVINS(pDevIns);
622 LogFlow(("pdmR3DevHlp_TMUtcNow: caller='%s'/%d: pTime=%p\n",
623 pDevIns->pReg->szName, pDevIns->iInstance, pTime));
624
625 pTime = TMR3UtcNow(pDevIns->Internal.s.pVMR3, pTime);
626
627 LogFlow(("pdmR3DevHlp_TMUtcNow: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, RTTimeSpecGetNano(pTime)));
628 return pTime;
629}
630
631
632/** @interface_method_impl{PDMDEVHLPR3,pfnTMTimeVirtGet} */
633static DECLCALLBACK(uint64_t) pdmR3DevHlp_TMTimeVirtGet(PPDMDEVINS pDevIns)
634{
635 PDMDEV_ASSERT_DEVINS(pDevIns);
636 LogFlow(("pdmR3DevHlp_TMTimeVirtGet: caller='%s'\n",
637 pDevIns->pReg->szName, pDevIns->iInstance));
638
639 uint64_t u64Time = TMVirtualSyncGet(pDevIns->Internal.s.pVMR3);
640
641 LogFlow(("pdmR3DevHlp_TMTimeVirtGet: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, u64Time));
642 return u64Time;
643}
644
645
646/** @interface_method_impl{PDMDEVHLPR3,pfnTMTimeVirtGetFreq} */
647static DECLCALLBACK(uint64_t) pdmR3DevHlp_TMTimeVirtGetFreq(PPDMDEVINS pDevIns)
648{
649 PDMDEV_ASSERT_DEVINS(pDevIns);
650 LogFlow(("pdmR3DevHlp_TMTimeVirtGetFreq: caller='%s'\n",
651 pDevIns->pReg->szName, pDevIns->iInstance));
652
653 uint64_t u64Freq = TMVirtualGetFreq(pDevIns->Internal.s.pVMR3);
654
655 LogFlow(("pdmR3DevHlp_TMTimeVirtGetFreq: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, u64Freq));
656 return u64Freq;
657}
658
659
660/** @interface_method_impl{PDMDEVHLPR3,pfnTMTimeVirtGetNano} */
661static DECLCALLBACK(uint64_t) pdmR3DevHlp_TMTimeVirtGetNano(PPDMDEVINS pDevIns)
662{
663 PDMDEV_ASSERT_DEVINS(pDevIns);
664 LogFlow(("pdmR3DevHlp_TMTimeVirtGetNano: caller='%s'\n",
665 pDevIns->pReg->szName, pDevIns->iInstance));
666
667 uint64_t u64Time = TMVirtualGet(pDevIns->Internal.s.pVMR3);
668 uint64_t u64Nano = TMVirtualToNano(pDevIns->Internal.s.pVMR3, u64Time);
669
670 LogFlow(("pdmR3DevHlp_TMTimeVirtGetNano: caller='%s'/%d: returns %RU64\n", pDevIns->pReg->szName, pDevIns->iInstance, u64Nano));
671 return u64Nano;
672}
673
674
675/** @interface_method_impl{PDMDEVHLPR3,pfnPhysRead} */
676static DECLCALLBACK(int) pdmR3DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
677{
678 PDMDEV_ASSERT_DEVINS(pDevIns);
679 PVM pVM = pDevIns->Internal.s.pVMR3;
680 LogFlow(("pdmR3DevHlp_PhysRead: caller='%s'/%d: GCPhys=%RGp pvBuf=%p cbRead=%#x\n",
681 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, pvBuf, cbRead));
682
683#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
684 if (!VM_IS_EMT(pVM))
685 {
686 char szNames[128];
687 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
688 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
689 }
690#endif
691
692 int rc;
693 if (VM_IS_EMT(pVM))
694 rc = PGMPhysRead(pVM, GCPhys, pvBuf, cbRead);
695 else
696 rc = PGMR3PhysReadExternal(pVM, GCPhys, pvBuf, cbRead);
697
698 Log(("pdmR3DevHlp_PhysRead: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
699 return rc;
700}
701
702
703/** @interface_method_impl{PDMDEVHLPR3,pfnPhysWrite} */
704static DECLCALLBACK(int) pdmR3DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
705{
706 PDMDEV_ASSERT_DEVINS(pDevIns);
707 PVM pVM = pDevIns->Internal.s.pVMR3;
708 LogFlow(("pdmR3DevHlp_PhysWrite: caller='%s'/%d: GCPhys=%RGp pvBuf=%p cbWrite=%#x\n",
709 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, pvBuf, cbWrite));
710
711#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
712 if (!VM_IS_EMT(pVM))
713 {
714 char szNames[128];
715 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
716 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
717 }
718#endif
719
720 int rc;
721 if (VM_IS_EMT(pVM))
722 rc = PGMPhysWrite(pVM, GCPhys, pvBuf, cbWrite);
723 else
724 rc = PGMR3PhysWriteExternal(pVM, GCPhys, pvBuf, cbWrite, pDevIns->pReg->szName);
725
726 Log(("pdmR3DevHlp_PhysWrite: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
727 return rc;
728}
729
730
731/** @interface_method_impl{PDMDEVHLPR3,pfnPhysGCPhys2CCPtr} */
732static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
733{
734 PDMDEV_ASSERT_DEVINS(pDevIns);
735 PVM pVM = pDevIns->Internal.s.pVMR3;
736 LogFlow(("pdmR3DevHlp_PhysGCPhys2CCPtr: caller='%s'/%d: GCPhys=%RGp fFlags=%#x ppv=%p pLock=%p\n",
737 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, fFlags, ppv, pLock));
738 AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
739
740#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
741 if (!VM_IS_EMT(pVM))
742 {
743 char szNames[128];
744 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
745 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
746 }
747#endif
748
749 int rc = PGMR3PhysGCPhys2CCPtrExternal(pVM, GCPhys, ppv, pLock);
750
751 Log(("pdmR3DevHlp_PhysGCPhys2CCPtr: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
752 return rc;
753}
754
755
756/** @interface_method_impl{PDMDEVHLPR3,pfnPhysGCPhys2CCPtrReadOnly} */
757static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, const void **ppv, PPGMPAGEMAPLOCK pLock)
758{
759 PDMDEV_ASSERT_DEVINS(pDevIns);
760 PVM pVM = pDevIns->Internal.s.pVMR3;
761 LogFlow(("pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly: caller='%s'/%d: GCPhys=%RGp fFlags=%#x ppv=%p pLock=%p\n",
762 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, fFlags, ppv, pLock));
763 AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
764
765#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
766 if (!VM_IS_EMT(pVM))
767 {
768 char szNames[128];
769 uint32_t cLocks = PDMR3CritSectCountOwned(pVM, szNames, sizeof(szNames));
770 AssertMsg(cLocks == 0, ("cLocks=%u %s\n", cLocks, szNames));
771 }
772#endif
773
774 int rc = PGMR3PhysGCPhys2CCPtrReadOnlyExternal(pVM, GCPhys, ppv, pLock);
775
776 Log(("pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
777 return rc;
778}
779
780
781/** @interface_method_impl{PDMDEVHLPR3,pfnPhysReleasePageMappingLock} */
782static DECLCALLBACK(void) pdmR3DevHlp_PhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
783{
784 PDMDEV_ASSERT_DEVINS(pDevIns);
785 PVM pVM = pDevIns->Internal.s.pVMR3;
786 LogFlow(("pdmR3DevHlp_PhysReleasePageMappingLock: caller='%s'/%d: pLock=%p\n",
787 pDevIns->pReg->szName, pDevIns->iInstance, pLock));
788
789 PGMPhysReleasePageMappingLock(pVM, pLock);
790
791 Log(("pdmR3DevHlp_PhysReleasePageMappingLock: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
792}
793
794
795/** @interface_method_impl{PDMDEVHLPR3,pfnPhysReadGCVirt} */
796static DECLCALLBACK(int) pdmR3DevHlp_PhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
797{
798 PDMDEV_ASSERT_DEVINS(pDevIns);
799 PVM pVM = pDevIns->Internal.s.pVMR3;
800 VM_ASSERT_EMT(pVM);
801 LogFlow(("pdmR3DevHlp_PhysReadGCVirt: caller='%s'/%d: pvDst=%p GCVirt=%RGv cb=%#x\n",
802 pDevIns->pReg->szName, pDevIns->iInstance, pvDst, GCVirtSrc, cb));
803
804 PVMCPU pVCpu = VMMGetCpu(pVM);
805 if (!pVCpu)
806 return VERR_ACCESS_DENIED;
807#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
808 /** @todo SMP. */
809#endif
810
811 int rc = PGMPhysSimpleReadGCPtr(pVCpu, pvDst, GCVirtSrc, cb);
812
813 LogFlow(("pdmR3DevHlp_PhysReadGCVirt: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
814
815 return rc;
816}
817
818
819/** @interface_method_impl{PDMDEVHLPR3,pfnPhysWriteGCVirt} */
820static DECLCALLBACK(int) pdmR3DevHlp_PhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
821{
822 PDMDEV_ASSERT_DEVINS(pDevIns);
823 PVM pVM = pDevIns->Internal.s.pVMR3;
824 VM_ASSERT_EMT(pVM);
825 LogFlow(("pdmR3DevHlp_PhysWriteGCVirt: caller='%s'/%d: GCVirtDst=%RGv pvSrc=%p cb=%#x\n",
826 pDevIns->pReg->szName, pDevIns->iInstance, GCVirtDst, pvSrc, cb));
827
828 PVMCPU pVCpu = VMMGetCpu(pVM);
829 if (!pVCpu)
830 return VERR_ACCESS_DENIED;
831#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
832 /** @todo SMP. */
833#endif
834
835 int rc = PGMPhysSimpleWriteGCPtr(pVCpu, GCVirtDst, pvSrc, cb);
836
837 LogFlow(("pdmR3DevHlp_PhysWriteGCVirt: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
838
839 return rc;
840}
841
842
843/** @interface_method_impl{PDMDEVHLPR3,pfnPhysGCPtr2GCPhys} */
844static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPtr2GCPhys(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys)
845{
846 PDMDEV_ASSERT_DEVINS(pDevIns);
847 PVM pVM = pDevIns->Internal.s.pVMR3;
848 VM_ASSERT_EMT(pVM);
849 LogFlow(("pdmR3DevHlp_PhysGCPtr2GCPhys: caller='%s'/%d: GCPtr=%RGv pGCPhys=%p\n",
850 pDevIns->pReg->szName, pDevIns->iInstance, GCPtr, pGCPhys));
851
852 PVMCPU pVCpu = VMMGetCpu(pVM);
853 if (!pVCpu)
854 return VERR_ACCESS_DENIED;
855#if defined(VBOX_STRICT) && defined(PDM_DEVHLP_DEADLOCK_DETECTION)
856 /** @todo SMP. */
857#endif
858
859 int rc = PGMPhysGCPtr2GCPhys(pVCpu, GCPtr, pGCPhys);
860
861 LogFlow(("pdmR3DevHlp_PhysGCPtr2GCPhys: caller='%s'/%d: returns %Rrc *pGCPhys=%RGp\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *pGCPhys));
862
863 return rc;
864}
865
866
867/** @interface_method_impl{PDMDEVHLPR3,pfnMMHeapAlloc} */
868static DECLCALLBACK(void *) pdmR3DevHlp_MMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
869{
870 PDMDEV_ASSERT_DEVINS(pDevIns);
871 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: cb=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cb));
872
873 void *pv = MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE_USER, cb);
874
875 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv));
876 return pv;
877}
878
879
880/** @interface_method_impl{PDMDEVHLPR3,pfnMMHeapAllocZ} */
881static DECLCALLBACK(void *) pdmR3DevHlp_MMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
882{
883 PDMDEV_ASSERT_DEVINS(pDevIns);
884 LogFlow(("pdmR3DevHlp_MMHeapAllocZ: caller='%s'/%d: cb=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cb));
885
886 void *pv = MMR3HeapAllocZ(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE_USER, cb);
887
888 LogFlow(("pdmR3DevHlp_MMHeapAllocZ: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv));
889 return pv;
890}
891
892
893/** @interface_method_impl{PDMDEVHLPR3,pfnMMHeapFree} */
894static DECLCALLBACK(void) pdmR3DevHlp_MMHeapFree(PPDMDEVINS pDevIns, void *pv)
895{
896 PDMDEV_ASSERT_DEVINS(pDevIns);
897 LogFlow(("pdmR3DevHlp_MMHeapFree: caller='%s'/%d: pv=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv));
898
899 MMR3HeapFree(pv);
900
901 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
902}
903
904
905/** @interface_method_impl{PDMDEVHLPR3,pfnVMState} */
906static DECLCALLBACK(VMSTATE) pdmR3DevHlp_VMState(PPDMDEVINS pDevIns)
907{
908 PDMDEV_ASSERT_DEVINS(pDevIns);
909
910 VMSTATE enmVMState = VMR3GetState(pDevIns->Internal.s.pVMR3);
911
912 LogFlow(("pdmR3DevHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDevIns->pReg->szName, pDevIns->iInstance,
913 enmVMState, VMR3GetStateName(enmVMState)));
914 return enmVMState;
915}
916
917
918/** @interface_method_impl{PDMDEVHLPR3,pfnVMTeleportedAndNotFullyResumedYet} */
919static DECLCALLBACK(bool) pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet(PPDMDEVINS pDevIns)
920{
921 PDMDEV_ASSERT_DEVINS(pDevIns);
922
923 bool fRc = VMR3TeleportedAndNotFullyResumedYet(pDevIns->Internal.s.pVMR3);
924
925 LogFlow(("pdmR3DevHlp_VMState: caller='%s'/%d: returns %RTbool\n", pDevIns->pReg->szName, pDevIns->iInstance,
926 fRc));
927 return fRc;
928}
929
930
931/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetError} */
932static DECLCALLBACK(int) pdmR3DevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
933{
934 PDMDEV_ASSERT_DEVINS(pDevIns);
935 va_list args;
936 va_start(args, pszFormat);
937 int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
938 va_end(args);
939 return rc;
940}
941
942
943/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetErrorV} */
944static DECLCALLBACK(int) pdmR3DevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
945{
946 PDMDEV_ASSERT_DEVINS(pDevIns);
947 int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
948 return rc;
949}
950
951
952/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetRuntimeError} */
953static DECLCALLBACK(int) pdmR3DevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
954{
955 PDMDEV_ASSERT_DEVINS(pDevIns);
956 va_list args;
957 va_start(args, pszFormat);
958 int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, args);
959 va_end(args);
960 return rc;
961}
962
963
964/** @interface_method_impl{PDMDEVHLPR3,pfnVMSetRuntimeErrorV} */
965static DECLCALLBACK(int) pdmR3DevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
966{
967 PDMDEV_ASSERT_DEVINS(pDevIns);
968 int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, va);
969 return rc;
970}
971
972
973/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFStopV} */
974static DECLCALLBACK(int) pdmR3DevHlp_DBGFStopV(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list args)
975{
976 PDMDEV_ASSERT_DEVINS(pDevIns);
977#ifdef LOG_ENABLED
978 va_list va2;
979 va_copy(va2, args);
980 LogFlow(("pdmR3DevHlp_DBGFStopV: caller='%s'/%d: pszFile=%p:{%s} iLine=%d pszFunction=%p:{%s} pszFormat=%p:{%s} (%N)\n",
981 pDevIns->pReg->szName, pDevIns->iInstance, pszFile, pszFile, iLine, pszFunction, pszFunction, pszFormat, pszFormat, pszFormat, &va2));
982 va_end(va2);
983#endif
984
985 PVM pVM = pDevIns->Internal.s.pVMR3;
986 VM_ASSERT_EMT(pVM);
987 int rc = DBGFR3EventSrcV(pVM, DBGFEVENT_DEV_STOP, pszFile, iLine, pszFunction, pszFormat, args);
988 if (rc == VERR_DBGF_NOT_ATTACHED)
989 rc = VINF_SUCCESS;
990
991 LogFlow(("pdmR3DevHlp_DBGFStopV: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
992 return rc;
993}
994
995
996/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFInfoRegister} */
997static DECLCALLBACK(int) pdmR3DevHlp_DBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
998{
999 PDMDEV_ASSERT_DEVINS(pDevIns);
1000 LogFlow(("pdmR3DevHlp_DBGFInfoRegister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1001 pDevIns->pReg->szName, pDevIns->iInstance, pszName, pszName, pszDesc, pszDesc, pfnHandler));
1002
1003 PVM pVM = pDevIns->Internal.s.pVMR3;
1004 VM_ASSERT_EMT(pVM);
1005 int rc = DBGFR3InfoRegisterDevice(pVM, pszName, pszDesc, pfnHandler, pDevIns);
1006
1007 LogFlow(("pdmR3DevHlp_DBGFInfoRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1008 return rc;
1009}
1010
1011
1012/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFRegRegister} */
1013static DECLCALLBACK(int) pdmR3DevHlp_DBGFRegRegister(PPDMDEVINS pDevIns, PCDBGFREGDESC paRegisters)
1014{
1015 PDMDEV_ASSERT_DEVINS(pDevIns);
1016 LogFlow(("pdmR3DevHlp_DBGFRegRegister: caller='%s'/%d: paRegisters=%p\n",
1017 pDevIns->pReg->szName, pDevIns->iInstance, paRegisters));
1018
1019 PVM pVM = pDevIns->Internal.s.pVMR3;
1020 VM_ASSERT_EMT(pVM);
1021 int rc = DBGFR3RegRegisterDevice(pVM, paRegisters, pDevIns, pDevIns->pReg->szName, pDevIns->iInstance);
1022
1023 LogFlow(("pdmR3DevHlp_DBGFRegRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1024 return rc;
1025}
1026
1027
1028/** @interface_method_impl{PDMDEVHLPR3,pfnDBGFTraceBuf} */
1029static DECLCALLBACK(RTTRACEBUF) pdmR3DevHlp_DBGFTraceBuf(PPDMDEVINS pDevIns)
1030{
1031 PDMDEV_ASSERT_DEVINS(pDevIns);
1032 RTTRACEBUF hTraceBuf = pDevIns->Internal.s.pVMR3->hTraceBufR3;
1033 LogFlow(("pdmR3DevHlp_DBGFTraceBuf: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, hTraceBuf));
1034 return hTraceBuf;
1035}
1036
1037
1038/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegister} */
1039static DECLCALLBACK(void) pdmR3DevHlp_STAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
1040{
1041 PDMDEV_ASSERT_DEVINS(pDevIns);
1042 PVM pVM = pDevIns->Internal.s.pVMR3;
1043 VM_ASSERT_EMT(pVM);
1044
1045 STAM_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc);
1046 NOREF(pVM);
1047}
1048
1049
1050
1051/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegisterF} */
1052static DECLCALLBACK(void) pdmR3DevHlp_STAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1053 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
1054{
1055 PDMDEV_ASSERT_DEVINS(pDevIns);
1056 PVM pVM = pDevIns->Internal.s.pVMR3;
1057 VM_ASSERT_EMT(pVM);
1058
1059 va_list args;
1060 va_start(args, pszName);
1061 int rc = STAMR3RegisterV(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1062 va_end(args);
1063 AssertRC(rc);
1064
1065 NOREF(pVM);
1066}
1067
1068
1069/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegisterV} */
1070static DECLCALLBACK(void) pdmR3DevHlp_STAMRegisterV(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1071 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
1072{
1073 PDMDEV_ASSERT_DEVINS(pDevIns);
1074 PVM pVM = pDevIns->Internal.s.pVMR3;
1075 VM_ASSERT_EMT(pVM);
1076
1077 int rc = STAMR3RegisterV(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1078 AssertRC(rc);
1079
1080 NOREF(pVM);
1081}
1082
1083
1084/** @interface_method_impl{PDMDEVHLPR3,pfnPCIRegister} */
1085static DECLCALLBACK(int) pdmR3DevHlp_PCIRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev)
1086{
1087 PDMDEV_ASSERT_DEVINS(pDevIns);
1088 PVM pVM = pDevIns->Internal.s.pVMR3;
1089 VM_ASSERT_EMT(pVM);
1090 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: pPciDev=%p:{.config={%#.256Rhxs}\n",
1091 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev->config));
1092
1093 /*
1094 * Validate input.
1095 */
1096 if (!pPciDev)
1097 {
1098 Assert(pPciDev);
1099 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc (pPciDev)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1100 return VERR_INVALID_PARAMETER;
1101 }
1102 if (!pPciDev->config[0] && !pPciDev->config[1])
1103 {
1104 Assert(pPciDev->config[0] || pPciDev->config[1]);
1105 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc (vendor)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1106 return VERR_INVALID_PARAMETER;
1107 }
1108 if (pDevIns->Internal.s.pPciDeviceR3)
1109 {
1110 /** @todo the PCI device vs. PDM device designed is a bit flawed if we have to
1111 * support a PDM device with multiple PCI devices. This might become a problem
1112 * when upgrading the chipset for instance because of multiple functions in some
1113 * devices...
1114 */
1115 AssertMsgFailed(("Only one PCI device per device is currently implemented!\n"));
1116 return VERR_PDM_ONE_PCI_FUNCTION_PER_DEVICE;
1117 }
1118
1119 /*
1120 * Choose the PCI bus for the device.
1121 *
1122 * This is simple. If the device was configured for a particular bus, the PCIBusNo
1123 * configuration value will be set. If not the default bus is 0.
1124 */
1125 int rc;
1126 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3;
1127 if (!pBus)
1128 {
1129 uint8_t u8Bus;
1130 rc = CFGMR3QueryU8Def(pDevIns->Internal.s.pCfgHandle, "PCIBusNo", &u8Bus, 0);
1131 AssertLogRelMsgRCReturn(rc, ("Configuration error: PCIBusNo query failed with rc=%Rrc (%s/%d)\n",
1132 rc, pDevIns->pReg->szName, pDevIns->iInstance), rc);
1133 AssertLogRelMsgReturn(u8Bus < RT_ELEMENTS(pVM->pdm.s.aPciBuses),
1134 ("Configuration error: PCIBusNo=%d, max is %d. (%s/%d)\n", u8Bus,
1135 RT_ELEMENTS(pVM->pdm.s.aPciBuses), pDevIns->pReg->szName, pDevIns->iInstance),
1136 VERR_PDM_NO_PCI_BUS);
1137 pBus = pDevIns->Internal.s.pPciBusR3 = &pVM->pdm.s.aPciBuses[u8Bus];
1138 }
1139 if (pBus->pDevInsR3)
1140 {
1141 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
1142 pDevIns->Internal.s.pPciBusR0 = MMHyperR3ToR0(pVM, pDevIns->Internal.s.pPciBusR3);
1143 else
1144 pDevIns->Internal.s.pPciBusR0 = NIL_RTR0PTR;
1145
1146 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
1147 pDevIns->Internal.s.pPciBusRC = MMHyperR3ToRC(pVM, pDevIns->Internal.s.pPciBusR3);
1148 else
1149 pDevIns->Internal.s.pPciBusRC = NIL_RTRCPTR;
1150
1151 /*
1152 * Check the configuration for PCI device and function assignment.
1153 */
1154 int iDev = -1;
1155 uint8_t u8Device;
1156 rc = CFGMR3QueryU8(pDevIns->Internal.s.pCfgHandle, "PCIDeviceNo", &u8Device);
1157 if (RT_SUCCESS(rc))
1158 {
1159 AssertMsgReturn(u8Device <= 31,
1160 ("Configuration error: PCIDeviceNo=%d, max is 31. (%s/%d)\n",
1161 u8Device, pDevIns->pReg->szName, pDevIns->iInstance),
1162 VERR_PDM_BAD_PCI_CONFIG);
1163
1164 uint8_t u8Function;
1165 rc = CFGMR3QueryU8(pDevIns->Internal.s.pCfgHandle, "PCIFunctionNo", &u8Function);
1166 AssertMsgRCReturn(rc, ("Configuration error: PCIDeviceNo, but PCIFunctionNo query failed with rc=%Rrc (%s/%d)\n",
1167 rc, pDevIns->pReg->szName, pDevIns->iInstance),
1168 rc);
1169 AssertMsgReturn(u8Function <= 7,
1170 ("Configuration error: PCIFunctionNo=%d, max is 7. (%s/%d)\n",
1171 u8Function, pDevIns->pReg->szName, pDevIns->iInstance),
1172 VERR_PDM_BAD_PCI_CONFIG);
1173
1174 iDev = (u8Device << 3) | u8Function;
1175 }
1176 else if (rc != VERR_CFGM_VALUE_NOT_FOUND)
1177 {
1178 AssertMsgFailed(("Configuration error: PCIDeviceNo query failed with rc=%Rrc (%s/%d)\n",
1179 rc, pDevIns->pReg->szName, pDevIns->iInstance));
1180 return rc;
1181 }
1182
1183 /*
1184 * Call the pci bus device to do the actual registration.
1185 */
1186 pdmLock(pVM);
1187 rc = pBus->pfnRegisterR3(pBus->pDevInsR3, pPciDev, pDevIns->pReg->szName, iDev);
1188 pdmUnlock(pVM);
1189 if (RT_SUCCESS(rc))
1190 {
1191 pPciDev->pDevIns = pDevIns;
1192
1193 pDevIns->Internal.s.pPciDeviceR3 = pPciDev;
1194 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
1195 pDevIns->Internal.s.pPciDeviceR0 = MMHyperR3ToR0(pVM, pPciDev);
1196 else
1197 pDevIns->Internal.s.pPciDeviceR0 = NIL_RTR0PTR;
1198
1199 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
1200 pDevIns->Internal.s.pPciDeviceRC = MMHyperR3ToRC(pVM, pPciDev);
1201 else
1202 pDevIns->Internal.s.pPciDeviceRC = NIL_RTRCPTR;
1203
1204 Log(("PDM: Registered device '%s'/%d as PCI device %d on bus %d\n",
1205 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev->devfn, pDevIns->Internal.s.pPciBusR3->iBus));
1206 }
1207 }
1208 else
1209 {
1210 AssertLogRelMsgFailed(("Configuration error: No PCI bus available. This could be related to init order too!\n"));
1211 rc = VERR_PDM_NO_PCI_BUS;
1212 }
1213
1214 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1215 return rc;
1216}
1217
1218
1219/** @interface_method_impl{PDMDEVHLPR3,pfnPCIIORegionRegister} */
1220static DECLCALLBACK(int) pdmR3DevHlp_PCIIORegionRegister(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
1221{
1222 PDMDEV_ASSERT_DEVINS(pDevIns);
1223 PVM pVM = pDevIns->Internal.s.pVMR3;
1224 VM_ASSERT_EMT(pVM);
1225 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: iRegion=%d cbRegion=%#x enmType=%d pfnCallback=%p\n",
1226 pDevIns->pReg->szName, pDevIns->iInstance, iRegion, cbRegion, enmType, pfnCallback));
1227
1228 /*
1229 * Validate input.
1230 */
1231 if (iRegion < 0 || iRegion >= PCI_NUM_REGIONS)
1232 {
1233 Assert(iRegion >= 0 && iRegion < PCI_NUM_REGIONS);
1234 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc (iRegion)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1235 return VERR_INVALID_PARAMETER;
1236 }
1237 switch ((int)enmType)
1238 {
1239 case PCI_ADDRESS_SPACE_IO:
1240 /*
1241 * Sanity check: don't allow to register more than 32K of the PCI I/O space.
1242 */
1243 AssertMsgReturn(cbRegion <= _32K,
1244 ("caller='%s'/%d: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cbRegion),
1245 VERR_INVALID_PARAMETER);
1246 break;
1247
1248 case PCI_ADDRESS_SPACE_MEM:
1249 case PCI_ADDRESS_SPACE_MEM_PREFETCH:
1250 case PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64:
1251 case PCI_ADDRESS_SPACE_MEM_PREFETCH | PCI_ADDRESS_SPACE_BAR64:
1252 /*
1253 * Sanity check: don't allow to register more than 512MB of the PCI MMIO space for
1254 * now. If this limit is increased beyond 2GB, adapt the aligned check below as well!
1255 */
1256 AssertMsgReturn(cbRegion <= 512 * _1M,
1257 ("caller='%s'/%d: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cbRegion),
1258 VERR_INVALID_PARAMETER);
1259 break;
1260 default:
1261 AssertMsgFailed(("enmType=%#x is unknown\n", enmType));
1262 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc (enmType)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1263 return VERR_INVALID_PARAMETER;
1264 }
1265 if (!pfnCallback)
1266 {
1267 Assert(pfnCallback);
1268 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc (callback)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1269 return VERR_INVALID_PARAMETER;
1270 }
1271 AssertRelease(VMR3GetState(pVM) != VMSTATE_RUNNING);
1272
1273 /*
1274 * Must have a PCI device registered!
1275 */
1276 int rc;
1277 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1278 if (pPciDev)
1279 {
1280 /*
1281 * We're currently restricted to page aligned MMIO regions.
1282 */
1283 if ( ((enmType & ~(PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_MEM_PREFETCH)) == PCI_ADDRESS_SPACE_MEM)
1284 && cbRegion != RT_ALIGN_32(cbRegion, PAGE_SIZE))
1285 {
1286 Log(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: aligning cbRegion %#x -> %#x\n",
1287 pDevIns->pReg->szName, pDevIns->iInstance, cbRegion, RT_ALIGN_32(cbRegion, PAGE_SIZE)));
1288 cbRegion = RT_ALIGN_32(cbRegion, PAGE_SIZE);
1289 }
1290
1291 /*
1292 * For registering PCI MMIO memory or PCI I/O memory, the size of the region must be a power of 2!
1293 */
1294 int iLastSet = ASMBitLastSetU32(cbRegion);
1295 Assert(iLastSet > 0);
1296 uint32_t cbRegionAligned = RT_BIT_32(iLastSet - 1);
1297 if (cbRegion > cbRegionAligned)
1298 cbRegion = cbRegionAligned * 2; /* round up */
1299
1300 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3;
1301 Assert(pBus);
1302 pdmLock(pVM);
1303 rc = pBus->pfnIORegionRegisterR3(pBus->pDevInsR3, pPciDev, iRegion, cbRegion, enmType, pfnCallback);
1304 pdmUnlock(pVM);
1305 }
1306 else
1307 {
1308 AssertMsgFailed(("No PCI device registered!\n"));
1309 rc = VERR_PDM_NOT_PCI_DEVICE;
1310 }
1311
1312 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1313 return rc;
1314}
1315
1316
1317/** @interface_method_impl{PDMDEVHLPR3,pfnPCISetConfigCallbacks} */
1318static DECLCALLBACK(void) pdmR3DevHlp_PCISetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
1319 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
1320{
1321 PDMDEV_ASSERT_DEVINS(pDevIns);
1322 PVM pVM = pDevIns->Internal.s.pVMR3;
1323 VM_ASSERT_EMT(pVM);
1324 LogFlow(("pdmR3DevHlp_PCISetConfigCallbacks: caller='%s'/%d: pPciDev=%p pfnRead=%p ppfnReadOld=%p pfnWrite=%p ppfnWriteOld=%p\n",
1325 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pfnRead, ppfnReadOld, pfnWrite, ppfnWriteOld));
1326
1327 /*
1328 * Validate input and resolve defaults.
1329 */
1330 AssertPtr(pfnRead);
1331 AssertPtr(pfnWrite);
1332 AssertPtrNull(ppfnReadOld);
1333 AssertPtrNull(ppfnWriteOld);
1334 AssertPtrNull(pPciDev);
1335
1336 if (!pPciDev)
1337 pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1338 AssertReleaseMsg(pPciDev, ("You must register your device first!\n"));
1339 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3;
1340 AssertRelease(pBus);
1341 AssertRelease(VMR3GetState(pVM) != VMSTATE_RUNNING);
1342
1343 /*
1344 * Do the job.
1345 */
1346 pdmLock(pVM);
1347 pBus->pfnSetConfigCallbacksR3(pBus->pDevInsR3, pPciDev, pfnRead, ppfnReadOld, pfnWrite, ppfnWriteOld);
1348 pdmUnlock(pVM);
1349
1350 LogFlow(("pdmR3DevHlp_PCISetConfigCallbacks: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1351}
1352
1353
1354/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysRead} */
1355static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
1356{
1357 PDMDEV_ASSERT_DEVINS(pDevIns);
1358
1359 /*
1360 * Just check the busmaster setting here and forward the request to the generic read helper.
1361 */
1362 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1363 AssertReleaseMsg(pPciDev, ("No PCI device registered!\n"));
1364
1365 if (!PCIDevIsBusmaster(pPciDev))
1366 {
1367 Log(("pdmR3DevHlp_PCIPhysRead: caller='%s'/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbRead=%#zx\n",
1368 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbRead));
1369 return VERR_PDM_NOT_PCI_BUS_MASTER;
1370 }
1371
1372 return pDevIns->pHlpR3->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
1373}
1374
1375
1376/** @interface_method_impl{PDMDEVHLPR3,pfnPCIPhysRead} */
1377static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
1378{
1379 PDMDEV_ASSERT_DEVINS(pDevIns);
1380
1381 /*
1382 * Just check the busmaster setting here and forward the request to the generic read helper.
1383 */
1384 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1385 AssertReleaseMsg(pPciDev, ("No PCI device registered!\n"));
1386
1387 if (!PCIDevIsBusmaster(pPciDev))
1388 {
1389 Log(("pdmR3DevHlp_PCIPhysWrite: caller='%s'/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbWrite=%#zx\n",
1390 pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbWrite));
1391 return VERR_PDM_NOT_PCI_BUS_MASTER;
1392 }
1393
1394 return pDevIns->pHlpR3->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
1395}
1396
1397
1398/** @interface_method_impl{PDMDEVHLPR3,pfnPCISetIrq} */
1399static DECLCALLBACK(void) pdmR3DevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1400{
1401 PDMDEV_ASSERT_DEVINS(pDevIns);
1402 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: iIrq=%d iLevel=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, iIrq, iLevel));
1403
1404 /*
1405 * Validate input.
1406 */
1407 Assert(iIrq == 0);
1408 Assert((uint32_t)iLevel <= PDM_IRQ_LEVEL_FLIP_FLOP);
1409
1410 /*
1411 * Must have a PCI device registered!
1412 */
1413 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1414 if (pPciDev)
1415 {
1416 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3; /** @todo the bus should be associated with the PCI device not the PDM device. */
1417 Assert(pBus);
1418 PVM pVM = pDevIns->Internal.s.pVMR3;
1419
1420 pdmLock(pVM);
1421 uint32_t uTagSrc;
1422 if (iLevel & PDM_IRQ_LEVEL_HIGH)
1423 {
1424 pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
1425 if (iLevel == PDM_IRQ_LEVEL_HIGH)
1426 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1427 else
1428 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1429 }
1430 else
1431 uTagSrc = pDevIns->Internal.s.uLastIrqTag;
1432
1433 pBus->pfnSetIrqR3(pBus->pDevInsR3, pPciDev, iIrq, iLevel, uTagSrc);
1434
1435 if (iLevel == PDM_IRQ_LEVEL_LOW)
1436 VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1437 pdmUnlock(pVM);
1438 }
1439 else
1440 AssertReleaseMsgFailed(("No PCI device registered!\n"));
1441
1442 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1443}
1444
1445
1446/** @interface_method_impl{PDMDEVHLPR3,pfnPCISetIrqNoWait} */
1447static DECLCALLBACK(void) pdmR3DevHlp_PCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1448{
1449 pdmR3DevHlp_PCISetIrq(pDevIns, iIrq, iLevel);
1450}
1451
1452
1453/** @interface_method_impl{PDMDEVHLPR3,pfnPCIRegisterMsi} */
1454static DECLCALLBACK(int) pdmR3DevHlp_PCIRegisterMsi(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg)
1455{
1456 PDMDEV_ASSERT_DEVINS(pDevIns);
1457 LogFlow(("pdmR3DevHlp_PCIRegisterMsi: caller='%s'/%d: %d MSI vectors %d MSI-X vectors\n", pDevIns->pReg->szName, pDevIns->iInstance, pMsiReg->cMsiVectors,pMsiReg->cMsixVectors ));
1458 int rc = VINF_SUCCESS;
1459
1460 /*
1461 * Must have a PCI device registered!
1462 */
1463 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1464 if (pPciDev)
1465 {
1466 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3; /** @todo the bus should be associated with the PCI device not the PDM device. */
1467 Assert(pBus);
1468
1469 PVM pVM = pDevIns->Internal.s.pVMR3;
1470 pdmLock(pVM);
1471 if (pBus->pfnRegisterMsiR3)
1472 rc = pBus->pfnRegisterMsiR3(pBus->pDevInsR3, pPciDev, pMsiReg);
1473 else
1474 rc = VERR_NOT_IMPLEMENTED;
1475 pdmUnlock(pVM);
1476 }
1477 else
1478 AssertReleaseMsgFailed(("No PCI device registered!\n"));
1479
1480 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1481 return rc;
1482}
1483
1484/** @interface_method_impl{PDMDEVHLPR3,pfnISASetIrq} */
1485static DECLCALLBACK(void) pdmR3DevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1486{
1487 PDMDEV_ASSERT_DEVINS(pDevIns);
1488 LogFlow(("pdmR3DevHlp_ISASetIrq: caller='%s'/%d: iIrq=%d iLevel=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, iIrq, iLevel));
1489
1490 /*
1491 * Validate input.
1492 */
1493 Assert(iIrq < 16);
1494 Assert((uint32_t)iLevel <= PDM_IRQ_LEVEL_FLIP_FLOP);
1495
1496 PVM pVM = pDevIns->Internal.s.pVMR3;
1497
1498 /*
1499 * Do the job.
1500 */
1501 pdmLock(pVM);
1502 uint32_t uTagSrc;
1503 if (iLevel & PDM_IRQ_LEVEL_HIGH)
1504 {
1505 pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
1506 if (iLevel == PDM_IRQ_LEVEL_HIGH)
1507 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1508 else
1509 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1510 }
1511 else
1512 uTagSrc = pDevIns->Internal.s.uLastIrqTag;
1513
1514 PDMIsaSetIrq(pVM, iIrq, iLevel, uTagSrc); /* (The API takes the lock recursively.) */
1515
1516 if (iLevel == PDM_IRQ_LEVEL_LOW)
1517 VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1518 pdmUnlock(pVM);
1519
1520 LogFlow(("pdmR3DevHlp_ISASetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1521}
1522
1523
1524/** @interface_method_impl{PDMDEVHLPR3,pfnISASetIrqNoWait} */
1525static DECLCALLBACK(void) pdmR3DevHlp_ISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1526{
1527 pdmR3DevHlp_ISASetIrq(pDevIns, iIrq, iLevel);
1528}
1529
1530
1531/** @interface_method_impl{PDMDEVHLPR3,pfnDriverAttach} */
1532static DECLCALLBACK(int) pdmR3DevHlp_DriverAttach(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
1533{
1534 PDMDEV_ASSERT_DEVINS(pDevIns);
1535 PVM pVM = pDevIns->Internal.s.pVMR3;
1536 VM_ASSERT_EMT(pVM);
1537 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: iLun=%d pBaseInterface=%p ppBaseInterface=%p pszDesc=%p:{%s}\n",
1538 pDevIns->pReg->szName, pDevIns->iInstance, iLun, pBaseInterface, ppBaseInterface, pszDesc, pszDesc));
1539
1540 /*
1541 * Lookup the LUN, it might already be registered.
1542 */
1543 PPDMLUN pLunPrev = NULL;
1544 PPDMLUN pLun = pDevIns->Internal.s.pLunsR3;
1545 for (; pLun; pLunPrev = pLun, pLun = pLun->pNext)
1546 if (pLun->iLun == iLun)
1547 break;
1548
1549 /*
1550 * Create the LUN if if wasn't found, else check if driver is already attached to it.
1551 */
1552 if (!pLun)
1553 {
1554 if ( !pBaseInterface
1555 || !pszDesc
1556 || !*pszDesc)
1557 {
1558 Assert(pBaseInterface);
1559 Assert(pszDesc || *pszDesc);
1560 return VERR_INVALID_PARAMETER;
1561 }
1562
1563 pLun = (PPDMLUN)MMR3HeapAlloc(pVM, MM_TAG_PDM_LUN, sizeof(*pLun));
1564 if (!pLun)
1565 return VERR_NO_MEMORY;
1566
1567 pLun->iLun = iLun;
1568 pLun->pNext = pLunPrev ? pLunPrev->pNext : NULL;
1569 pLun->pTop = NULL;
1570 pLun->pBottom = NULL;
1571 pLun->pDevIns = pDevIns;
1572 pLun->pUsbIns = NULL;
1573 pLun->pszDesc = pszDesc;
1574 pLun->pBase = pBaseInterface;
1575 if (!pLunPrev)
1576 pDevIns->Internal.s.pLunsR3 = pLun;
1577 else
1578 pLunPrev->pNext = pLun;
1579 Log(("pdmR3DevHlp_DriverAttach: Registered LUN#%d '%s' with device '%s'/%d.\n",
1580 iLun, pszDesc, pDevIns->pReg->szName, pDevIns->iInstance));
1581 }
1582 else if (pLun->pTop)
1583 {
1584 AssertMsgFailed(("Already attached! The device should keep track of such things!\n"));
1585 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_DRIVER_ALREADY_ATTACHED));
1586 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
1587 }
1588 Assert(pLun->pBase == pBaseInterface);
1589
1590
1591 /*
1592 * Get the attached driver configuration.
1593 */
1594 int rc;
1595 PCFGMNODE pNode = CFGMR3GetChildF(pDevIns->Internal.s.pCfgHandle, "LUN#%u", iLun);
1596 if (pNode)
1597 rc = pdmR3DrvInstantiate(pVM, pNode, pBaseInterface, NULL /*pDrvAbove*/, pLun, ppBaseInterface);
1598 else
1599 rc = VERR_PDM_NO_ATTACHED_DRIVER;
1600
1601
1602 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1603 return rc;
1604}
1605
1606
1607/** @interface_method_impl{PDMDEVHLPR3,pfnQueueCreate} */
1608static DECLCALLBACK(int) pdmR3DevHlp_QueueCreate(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
1609 PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, const char *pszName, PPDMQUEUE *ppQueue)
1610{
1611 PDMDEV_ASSERT_DEVINS(pDevIns);
1612 LogFlow(("pdmR3DevHlp_QueueCreate: caller='%s'/%d: cbItem=%#x cItems=%#x cMilliesInterval=%u pfnCallback=%p fGCEnabled=%RTbool pszName=%p:{%s} ppQueue=%p\n",
1613 pDevIns->pReg->szName, pDevIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, fGCEnabled, pszName, pszName, ppQueue));
1614
1615 PVM pVM = pDevIns->Internal.s.pVMR3;
1616 VM_ASSERT_EMT(pVM);
1617
1618 if (pDevIns->iInstance > 0)
1619 {
1620 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s_%u", pszName, pDevIns->iInstance);
1621 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
1622 }
1623
1624 int rc = PDMR3QueueCreateDevice(pVM, pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fGCEnabled, pszName, ppQueue);
1625
1626 LogFlow(("pdmR3DevHlp_QueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *ppQueue));
1627 return rc;
1628}
1629
1630
1631/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectInit} */
1632static DECLCALLBACK(int) pdmR3DevHlp_CritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1633 const char *pszNameFmt, va_list va)
1634{
1635 PDMDEV_ASSERT_DEVINS(pDevIns);
1636 LogFlow(("pdmR3DevHlp_CritSectInit: caller='%s'/%d: pCritSect=%p pszNameFmt=%p:{%s}\n",
1637 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect, pszNameFmt, pszNameFmt));
1638
1639 PVM pVM = pDevIns->Internal.s.pVMR3;
1640 VM_ASSERT_EMT(pVM);
1641 int rc = pdmR3CritSectInitDevice(pVM, pDevIns, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
1642
1643 LogFlow(("pdmR3DevHlp_CritSectInit: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1644 return rc;
1645}
1646
1647
1648/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNop} */
1649static DECLCALLBACK(PPDMCRITSECT) pdmR3DevHlp_CritSectGetNop(PPDMDEVINS pDevIns)
1650{
1651 PDMDEV_ASSERT_DEVINS(pDevIns);
1652 PVM pVM = pDevIns->Internal.s.pVMR3;
1653 VM_ASSERT_EMT(pVM);
1654
1655 PPDMCRITSECT pCritSect = PDMR3CritSectGetNop(pVM);
1656 LogFlow(("pdmR3DevHlp_CritSectGetNop: caller='%s'/%d: return %p\n",
1657 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
1658 return pCritSect;
1659}
1660
1661
1662/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNopR0} */
1663static DECLCALLBACK(R0PTRTYPE(PPDMCRITSECT)) pdmR3DevHlp_CritSectGetNopR0(PPDMDEVINS pDevIns)
1664{
1665 PDMDEV_ASSERT_DEVINS(pDevIns);
1666 PVM pVM = pDevIns->Internal.s.pVMR3;
1667 VM_ASSERT_EMT(pVM);
1668
1669 R0PTRTYPE(PPDMCRITSECT) pCritSect = PDMR3CritSectGetNopR0(pVM);
1670 LogFlow(("pdmR3DevHlp_CritSectGetNopR0: caller='%s'/%d: return %RHv\n",
1671 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
1672 return pCritSect;
1673}
1674
1675
1676/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNopRC} */
1677static DECLCALLBACK(RCPTRTYPE(PPDMCRITSECT)) pdmR3DevHlp_CritSectGetNopRC(PPDMDEVINS pDevIns)
1678{
1679 PDMDEV_ASSERT_DEVINS(pDevIns);
1680 PVM pVM = pDevIns->Internal.s.pVMR3;
1681 VM_ASSERT_EMT(pVM);
1682
1683 RCPTRTYPE(PPDMCRITSECT) pCritSect = PDMR3CritSectGetNopRC(pVM);
1684 LogFlow(("pdmR3DevHlp_CritSectGetNopRC: caller='%s'/%d: return %RRv\n",
1685 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
1686 return pCritSect;
1687}
1688
1689
1690/** @interface_method_impl{PDMDEVHLPR3,pfnSetDeviceCritSect} */
1691static DECLCALLBACK(int) pdmR3DevHlp_SetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
1692{
1693 /*
1694 * Validate input.
1695 *
1696 * Note! We only allow the automatically created default critical section
1697 * to be replaced by this API.
1698 */
1699 PDMDEV_ASSERT_DEVINS(pDevIns);
1700 AssertPtrReturn(pCritSect, VERR_INVALID_POINTER);
1701 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: pCritSect=%p (%s)\n",
1702 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect, pCritSect->s.pszName));
1703 AssertReturn(PDMCritSectIsInitialized(pCritSect), VERR_INVALID_PARAMETER);
1704 PVM pVM = pDevIns->Internal.s.pVMR3;
1705 AssertReturn(pCritSect->s.pVMR3 == pVM, VERR_INVALID_PARAMETER);
1706
1707 VM_ASSERT_EMT(pVM);
1708 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
1709
1710 AssertReturn(pDevIns->pCritSectRoR3, VERR_PDM_DEV_IPE_1);
1711 AssertReturn(pDevIns->pCritSectRoR3->s.fAutomaticDefaultCritsect, VERR_WRONG_ORDER);
1712 AssertReturn(!pDevIns->pCritSectRoR3->s.fUsedByTimerOrSimilar, VERR_WRONG_ORDER);
1713 AssertReturn(pDevIns->pCritSectRoR3 != pCritSect, VERR_INVALID_PARAMETER);
1714
1715 /*
1716 * Replace the critical section and destroy the automatic default section.
1717 */
1718 PPDMCRITSECT pOldCritSect = pDevIns->pCritSectRoR3;
1719 pDevIns->pCritSectRoR3 = pCritSect;
1720 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
1721 pDevIns->pCritSectRoR0 = MMHyperCCToR0(pVM, pDevIns->pCritSectRoR3);
1722 else
1723 Assert(pDevIns->pCritSectRoR0 == NIL_RTRCPTR);
1724
1725 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
1726 pDevIns->pCritSectRoRC = MMHyperCCToRC(pVM, pDevIns->pCritSectRoR3);
1727 else
1728 Assert(pDevIns->pCritSectRoRC == NIL_RTRCPTR);
1729
1730 PDMR3CritSectDelete(pOldCritSect);
1731 if (pDevIns->pReg->fFlags & (PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0))
1732 MMHyperFree(pVM, pOldCritSect);
1733 else
1734 MMR3HeapFree(pOldCritSect);
1735
1736 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
1737 return VINF_SUCCESS;
1738}
1739
1740
1741/** @interface_method_impl{PDMDEVHLPR3,pfnThreadCreate} */
1742static DECLCALLBACK(int) pdmR3DevHlp_ThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
1743 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1744{
1745 PDMDEV_ASSERT_DEVINS(pDevIns);
1746 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
1747 LogFlow(("pdmR3DevHlp_ThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
1748 pDevIns->pReg->szName, pDevIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
1749
1750 int rc = pdmR3ThreadCreateDevice(pDevIns->Internal.s.pVMR3, pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1751
1752 LogFlow(("pdmR3DevHlp_ThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDevIns->pReg->szName, pDevIns->iInstance,
1753 rc, *ppThread));
1754 return rc;
1755}
1756
1757
1758/** @interface_method_impl{PDMDEVHLPR3,pfnSetAsyncNotification} */
1759static DECLCALLBACK(int) pdmR3DevHlp_SetAsyncNotification(PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify)
1760{
1761 PDMDEV_ASSERT_DEVINS(pDevIns);
1762 VM_ASSERT_EMT0(pDevIns->Internal.s.pVMR3);
1763 LogFlow(("pdmR3DevHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pfnAsyncNotify));
1764
1765 int rc = VINF_SUCCESS;
1766 AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
1767 AssertStmt(!pDevIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
1768 AssertStmt(pDevIns->Internal.s.fIntFlags & (PDMDEVINSINT_FLAGS_SUSPENDED | PDMDEVINSINT_FLAGS_RESET), rc = VERR_WRONG_ORDER);
1769 VMSTATE enmVMState = VMR3GetState(pDevIns->Internal.s.pVMR3);
1770 AssertStmt( enmVMState == VMSTATE_SUSPENDING
1771 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1772 || enmVMState == VMSTATE_SUSPENDING_LS
1773 || enmVMState == VMSTATE_RESETTING
1774 || enmVMState == VMSTATE_RESETTING_LS
1775 || enmVMState == VMSTATE_POWERING_OFF
1776 || enmVMState == VMSTATE_POWERING_OFF_LS,
1777 rc = VERR_INVALID_STATE);
1778
1779 if (RT_SUCCESS(rc))
1780 pDevIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
1781
1782 LogFlow(("pdmR3DevHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1783 return rc;
1784}
1785
1786
1787/** @interface_method_impl{PDMDEVHLPR3,pfnAsyncNotificationCompleted} */
1788static DECLCALLBACK(void) pdmR3DevHlp_AsyncNotificationCompleted(PPDMDEVINS pDevIns)
1789{
1790 PDMDEV_ASSERT_DEVINS(pDevIns);
1791 PVM pVM = pDevIns->Internal.s.pVMR3;
1792
1793 VMSTATE enmVMState = VMR3GetState(pVM);
1794 if ( enmVMState == VMSTATE_SUSPENDING
1795 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1796 || enmVMState == VMSTATE_SUSPENDING_LS
1797 || enmVMState == VMSTATE_RESETTING
1798 || enmVMState == VMSTATE_RESETTING_LS
1799 || enmVMState == VMSTATE_POWERING_OFF
1800 || enmVMState == VMSTATE_POWERING_OFF_LS)
1801 {
1802 LogFlow(("pdmR3DevHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
1803 VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
1804 }
1805 else
1806 LogFlow(("pdmR3DevHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, enmVMState));
1807}
1808
1809
1810/** @interface_method_impl{PDMDEVHLPR3,pfnRTCRegister} */
1811static DECLCALLBACK(int) pdmR3DevHlp_RTCRegister(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp)
1812{
1813 PDMDEV_ASSERT_DEVINS(pDevIns);
1814 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
1815 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: pRtcReg=%p:{.u32Version=%#x, .pfnWrite=%p, .pfnRead=%p} ppRtcHlp=%p\n",
1816 pDevIns->pReg->szName, pDevIns->iInstance, pRtcReg, pRtcReg->u32Version, pRtcReg->pfnWrite,
1817 pRtcReg->pfnWrite, ppRtcHlp));
1818
1819 /*
1820 * Validate input.
1821 */
1822 if (pRtcReg->u32Version != PDM_RTCREG_VERSION)
1823 {
1824 AssertMsgFailed(("u32Version=%#x expected %#x\n", pRtcReg->u32Version,
1825 PDM_RTCREG_VERSION));
1826 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (version)\n",
1827 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1828 return VERR_INVALID_PARAMETER;
1829 }
1830 if ( !pRtcReg->pfnWrite
1831 || !pRtcReg->pfnRead)
1832 {
1833 Assert(pRtcReg->pfnWrite);
1834 Assert(pRtcReg->pfnRead);
1835 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (callbacks)\n",
1836 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1837 return VERR_INVALID_PARAMETER;
1838 }
1839
1840 if (!ppRtcHlp)
1841 {
1842 Assert(ppRtcHlp);
1843 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (ppRtcHlp)\n",
1844 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1845 return VERR_INVALID_PARAMETER;
1846 }
1847
1848 /*
1849 * Only one DMA device.
1850 */
1851 PVM pVM = pDevIns->Internal.s.pVMR3;
1852 if (pVM->pdm.s.pRtc)
1853 {
1854 AssertMsgFailed(("Only one RTC device is supported!\n"));
1855 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n",
1856 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1857 return VERR_INVALID_PARAMETER;
1858 }
1859
1860 /*
1861 * Allocate and initialize pci bus structure.
1862 */
1863 int rc = VINF_SUCCESS;
1864 PPDMRTC pRtc = (PPDMRTC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pRtc));
1865 if (pRtc)
1866 {
1867 pRtc->pDevIns = pDevIns;
1868 pRtc->Reg = *pRtcReg;
1869 pVM->pdm.s.pRtc = pRtc;
1870
1871 /* set the helper pointer. */
1872 *ppRtcHlp = &g_pdmR3DevRtcHlp;
1873 Log(("PDM: Registered RTC device '%s'/%d pDevIns=%p\n",
1874 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
1875 }
1876 else
1877 rc = VERR_NO_MEMORY;
1878
1879 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n",
1880 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1881 return rc;
1882}
1883
1884
1885/** @interface_method_impl{PDMDEVHLPR3,pfnDMARegister} */
1886static DECLCALLBACK(int) pdmR3DevHlp_DMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
1887{
1888 PDMDEV_ASSERT_DEVINS(pDevIns);
1889 PVM pVM = pDevIns->Internal.s.pVMR3;
1890 VM_ASSERT_EMT(pVM);
1891 LogFlow(("pdmR3DevHlp_DMARegister: caller='%s'/%d: uChannel=%d pfnTransferHandler=%p pvUser=%p\n",
1892 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pfnTransferHandler, pvUser));
1893 int rc = VINF_SUCCESS;
1894 if (pVM->pdm.s.pDmac)
1895 pVM->pdm.s.pDmac->Reg.pfnRegister(pVM->pdm.s.pDmac->pDevIns, uChannel, pfnTransferHandler, pvUser);
1896 else
1897 {
1898 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1899 rc = VERR_PDM_NO_DMAC_INSTANCE;
1900 }
1901 LogFlow(("pdmR3DevHlp_DMARegister: caller='%s'/%d: returns %Rrc\n",
1902 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1903 return rc;
1904}
1905
1906
1907/** @interface_method_impl{PDMDEVHLPR3,pfnDMAReadMemory} */
1908static DECLCALLBACK(int) pdmR3DevHlp_DMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
1909{
1910 PDMDEV_ASSERT_DEVINS(pDevIns);
1911 PVM pVM = pDevIns->Internal.s.pVMR3;
1912 VM_ASSERT_EMT(pVM);
1913 LogFlow(("pdmR3DevHlp_DMAReadMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbRead=%p\n",
1914 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbRead));
1915 int rc = VINF_SUCCESS;
1916 if (pVM->pdm.s.pDmac)
1917 {
1918 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnReadMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock);
1919 if (pcbRead)
1920 *pcbRead = cb;
1921 }
1922 else
1923 {
1924 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1925 rc = VERR_PDM_NO_DMAC_INSTANCE;
1926 }
1927 LogFlow(("pdmR3DevHlp_DMAReadMemory: caller='%s'/%d: returns %Rrc\n",
1928 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1929 return rc;
1930}
1931
1932
1933/** @interface_method_impl{PDMDEVHLPR3,pfnDMAWriteMemory} */
1934static DECLCALLBACK(int) pdmR3DevHlp_DMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
1935{
1936 PDMDEV_ASSERT_DEVINS(pDevIns);
1937 PVM pVM = pDevIns->Internal.s.pVMR3;
1938 VM_ASSERT_EMT(pVM);
1939 LogFlow(("pdmR3DevHlp_DMAWriteMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbWritten=%p\n",
1940 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbWritten));
1941 int rc = VINF_SUCCESS;
1942 if (pVM->pdm.s.pDmac)
1943 {
1944 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnWriteMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock);
1945 if (pcbWritten)
1946 *pcbWritten = cb;
1947 }
1948 else
1949 {
1950 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1951 rc = VERR_PDM_NO_DMAC_INSTANCE;
1952 }
1953 LogFlow(("pdmR3DevHlp_DMAWriteMemory: caller='%s'/%d: returns %Rrc\n",
1954 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1955 return rc;
1956}
1957
1958
1959/** @interface_method_impl{PDMDEVHLPR3,pfnDMASetDREQ} */
1960static DECLCALLBACK(int) pdmR3DevHlp_DMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
1961{
1962 PDMDEV_ASSERT_DEVINS(pDevIns);
1963 PVM pVM = pDevIns->Internal.s.pVMR3;
1964 VM_ASSERT_EMT(pVM);
1965 LogFlow(("pdmR3DevHlp_DMASetDREQ: caller='%s'/%d: uChannel=%d uLevel=%d\n",
1966 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, uLevel));
1967 int rc = VINF_SUCCESS;
1968 if (pVM->pdm.s.pDmac)
1969 pVM->pdm.s.pDmac->Reg.pfnSetDREQ(pVM->pdm.s.pDmac->pDevIns, uChannel, uLevel);
1970 else
1971 {
1972 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1973 rc = VERR_PDM_NO_DMAC_INSTANCE;
1974 }
1975 LogFlow(("pdmR3DevHlp_DMASetDREQ: caller='%s'/%d: returns %Rrc\n",
1976 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1977 return rc;
1978}
1979
1980/** @interface_method_impl{PDMDEVHLPR3,pfnDMAGetChannelMode} */
1981static DECLCALLBACK(uint8_t) pdmR3DevHlp_DMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
1982{
1983 PDMDEV_ASSERT_DEVINS(pDevIns);
1984 PVM pVM = pDevIns->Internal.s.pVMR3;
1985 VM_ASSERT_EMT(pVM);
1986 LogFlow(("pdmR3DevHlp_DMAGetChannelMode: caller='%s'/%d: uChannel=%d\n",
1987 pDevIns->pReg->szName, pDevIns->iInstance, uChannel));
1988 uint8_t u8Mode;
1989 if (pVM->pdm.s.pDmac)
1990 u8Mode = pVM->pdm.s.pDmac->Reg.pfnGetChannelMode(pVM->pdm.s.pDmac->pDevIns, uChannel);
1991 else
1992 {
1993 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1994 u8Mode = 3 << 2 /* illegal mode type */;
1995 }
1996 LogFlow(("pdmR3DevHlp_DMAGetChannelMode: caller='%s'/%d: returns %#04x\n",
1997 pDevIns->pReg->szName, pDevIns->iInstance, u8Mode));
1998 return u8Mode;
1999}
2000
2001/** @interface_method_impl{PDMDEVHLPR3,pfnDMASchedule} */
2002static DECLCALLBACK(void) pdmR3DevHlp_DMASchedule(PPDMDEVINS pDevIns)
2003{
2004 PDMDEV_ASSERT_DEVINS(pDevIns);
2005 PVM pVM = pDevIns->Internal.s.pVMR3;
2006 VM_ASSERT_EMT(pVM);
2007 LogFlow(("pdmR3DevHlp_DMASchedule: caller='%s'/%d: VM_FF_PDM_DMA %d -> 1\n",
2008 pDevIns->pReg->szName, pDevIns->iInstance, VM_FF_ISSET(pVM, VM_FF_PDM_DMA)));
2009
2010 AssertMsg(pVM->pdm.s.pDmac, ("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
2011 VM_FF_SET(pVM, VM_FF_PDM_DMA);
2012#ifdef VBOX_WITH_REM
2013 REMR3NotifyDmaPending(pVM);
2014#endif
2015 VMR3NotifyGlobalFFU(pVM->pUVM, VMNOTIFYFF_FLAGS_DONE_REM);
2016}
2017
2018
2019/** @interface_method_impl{PDMDEVHLPR3,pfnCMOSWrite} */
2020static DECLCALLBACK(int) pdmR3DevHlp_CMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
2021{
2022 PDMDEV_ASSERT_DEVINS(pDevIns);
2023 PVM pVM = pDevIns->Internal.s.pVMR3;
2024 VM_ASSERT_EMT(pVM);
2025
2026 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: iReg=%#04x u8Value=%#04x\n",
2027 pDevIns->pReg->szName, pDevIns->iInstance, iReg, u8Value));
2028 int rc;
2029 if (pVM->pdm.s.pRtc)
2030 {
2031 PPDMDEVINS pDevInsRtc = pVM->pdm.s.pRtc->pDevIns;
2032 rc = PDMCritSectEnter(pDevInsRtc->pCritSectRoR3, VERR_IGNORED);
2033 if (RT_SUCCESS(rc))
2034 {
2035 rc = pVM->pdm.s.pRtc->Reg.pfnWrite(pDevInsRtc, iReg, u8Value);
2036 PDMCritSectLeave(pDevInsRtc->pCritSectRoR3);
2037 }
2038 }
2039 else
2040 rc = VERR_PDM_NO_RTC_INSTANCE;
2041
2042 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: return %Rrc\n",
2043 pDevIns->pReg->szName, pDevIns->iInstance, rc));
2044 return rc;
2045}
2046
2047
2048/** @interface_method_impl{PDMDEVHLPR3,pfnCMOSRead} */
2049static DECLCALLBACK(int) pdmR3DevHlp_CMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
2050{
2051 PDMDEV_ASSERT_DEVINS(pDevIns);
2052 PVM pVM = pDevIns->Internal.s.pVMR3;
2053 VM_ASSERT_EMT(pVM);
2054
2055 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: iReg=%#04x pu8Value=%p\n",
2056 pDevIns->pReg->szName, pDevIns->iInstance, iReg, pu8Value));
2057 int rc;
2058 if (pVM->pdm.s.pRtc)
2059 {
2060 PPDMDEVINS pDevInsRtc = pVM->pdm.s.pRtc->pDevIns;
2061 rc = PDMCritSectEnter(pDevInsRtc->pCritSectRoR3, VERR_IGNORED);
2062 if (RT_SUCCESS(rc))
2063 {
2064 rc = pVM->pdm.s.pRtc->Reg.pfnRead(pDevInsRtc, iReg, pu8Value);
2065 PDMCritSectLeave(pDevInsRtc->pCritSectRoR3);
2066 }
2067 }
2068 else
2069 rc = VERR_PDM_NO_RTC_INSTANCE;
2070
2071 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: return %Rrc\n",
2072 pDevIns->pReg->szName, pDevIns->iInstance, rc));
2073 return rc;
2074}
2075
2076
2077/** @interface_method_impl{PDMDEVHLPR3,pfnAssertEMT} */
2078static DECLCALLBACK(bool) pdmR3DevHlp_AssertEMT(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction)
2079{
2080 PDMDEV_ASSERT_DEVINS(pDevIns);
2081 if (VM_IS_EMT(pDevIns->Internal.s.pVMR3))
2082 return true;
2083
2084 char szMsg[100];
2085 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance);
2086 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
2087 AssertBreakpoint();
2088 return false;
2089}
2090
2091
2092/** @interface_method_impl{PDMDEVHLPR3,pfnAssertOther} */
2093static DECLCALLBACK(bool) pdmR3DevHlp_AssertOther(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction)
2094{
2095 PDMDEV_ASSERT_DEVINS(pDevIns);
2096 if (!VM_IS_EMT(pDevIns->Internal.s.pVMR3))
2097 return true;
2098
2099 char szMsg[100];
2100 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance);
2101 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
2102 AssertBreakpoint();
2103 return false;
2104}
2105
2106
2107/** @interface_method_impl{PDMDEVHLP,pfnLdrGetRCInterfaceSymbols} */
2108static DECLCALLBACK(int) pdmR3DevHlp_LdrGetRCInterfaceSymbols(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
2109 const char *pszSymPrefix, const char *pszSymList)
2110{
2111 PDMDEV_ASSERT_DEVINS(pDevIns);
2112 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2113 LogFlow(("pdmR3DevHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
2114 pDevIns->pReg->szName, pDevIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
2115
2116 int rc;
2117 if ( strncmp(pszSymPrefix, "dev", 3) == 0
2118 && RTStrIStr(pszSymPrefix + 3, pDevIns->pReg->szName) != NULL)
2119 {
2120 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
2121 rc = PDMR3LdrGetInterfaceSymbols(pDevIns->Internal.s.pVMR3,
2122 pvInterface, cbInterface,
2123 pDevIns->pReg->szRCMod, pDevIns->Internal.s.pDevR3->pszRCSearchPath,
2124 pszSymPrefix, pszSymList,
2125 false /*fRing0OrRC*/);
2126 else
2127 {
2128 AssertMsgFailed(("Not a raw-mode enabled driver\n"));
2129 rc = VERR_PERMISSION_DENIED;
2130 }
2131 }
2132 else
2133 {
2134 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'dev' and contain the driver name!\n",
2135 pszSymPrefix, pDevIns->pReg->szName));
2136 rc = VERR_INVALID_NAME;
2137 }
2138
2139 LogFlow(("pdmR3DevHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
2140 pDevIns->iInstance, rc));
2141 return rc;
2142}
2143
2144
2145/** @interface_method_impl{PDMDEVHLP,pfnLdrGetR0InterfaceSymbols} */
2146static DECLCALLBACK(int) pdmR3DevHlp_LdrGetR0InterfaceSymbols(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
2147 const char *pszSymPrefix, const char *pszSymList)
2148{
2149 PDMDEV_ASSERT_DEVINS(pDevIns);
2150 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2151 LogFlow(("pdmR3DevHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
2152 pDevIns->pReg->szName, pDevIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
2153
2154 int rc;
2155 if ( strncmp(pszSymPrefix, "dev", 3) == 0
2156 && RTStrIStr(pszSymPrefix + 3, pDevIns->pReg->szName) != NULL)
2157 {
2158 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
2159 rc = PDMR3LdrGetInterfaceSymbols(pDevIns->Internal.s.pVMR3,
2160 pvInterface, cbInterface,
2161 pDevIns->pReg->szR0Mod, pDevIns->Internal.s.pDevR3->pszR0SearchPath,
2162 pszSymPrefix, pszSymList,
2163 true /*fRing0OrRC*/);
2164 else
2165 {
2166 AssertMsgFailed(("Not a ring-0 enabled driver\n"));
2167 rc = VERR_PERMISSION_DENIED;
2168 }
2169 }
2170 else
2171 {
2172 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'dev' and contain the driver name!\n",
2173 pszSymPrefix, pDevIns->pReg->szName));
2174 rc = VERR_INVALID_NAME;
2175 }
2176
2177 LogFlow(("pdmR3DevHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
2178 pDevIns->iInstance, rc));
2179 return rc;
2180}
2181
2182
2183/** @interface_method_impl{PDMDEVHLP,pfnCallR0} */
2184static DECLCALLBACK(int) pdmR3DevHlp_CallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
2185{
2186 PDMDEV_ASSERT_DEVINS(pDevIns);
2187 PVM pVM = pDevIns->Internal.s.pVMR3;
2188 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2189 LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: uOperation=%#x u64Arg=%#RX64\n",
2190 pDevIns->pReg->szName, pDevIns->iInstance, uOperation, u64Arg));
2191
2192 /*
2193 * Resolve the ring-0 entry point. There is not need to remember this like
2194 * we do for drivers since this is mainly for construction time hacks and
2195 * other things that aren't performance critical.
2196 */
2197 int rc;
2198 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
2199 {
2200 char szSymbol[ sizeof("devR0") + sizeof(pDevIns->pReg->szName) + sizeof("ReqHandler")];
2201 strcat(strcat(strcpy(szSymbol, "devR0"), pDevIns->pReg->szName), "ReqHandler");
2202 szSymbol[sizeof("devR0") - 1] = RT_C_TO_UPPER(szSymbol[sizeof("devR0") - 1]);
2203
2204 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0;
2205 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, szSymbol, &pfnReqHandlerR0);
2206 if (RT_SUCCESS(rc))
2207 {
2208 /*
2209 * Make the ring-0 call.
2210 */
2211 PDMDEVICECALLREQHANDLERREQ Req;
2212 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
2213 Req.Hdr.cbReq = sizeof(Req);
2214 Req.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2215 Req.pfnReqHandlerR0 = pfnReqHandlerR0;
2216 Req.uOperation = uOperation;
2217 Req.u32Alignment = 0;
2218 Req.u64Arg = u64Arg;
2219 rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER, 0, &Req.Hdr);
2220 }
2221 else
2222 pfnReqHandlerR0 = NIL_RTR0PTR;
2223 }
2224 else
2225 rc = VERR_ACCESS_DENIED;
2226 LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
2227 pDevIns->iInstance, rc));
2228 return rc;
2229}
2230
2231
2232/** @interface_method_impl{PDMDEVHLPR3,pfnGetUVM} */
2233static DECLCALLBACK(PUVM) pdmR3DevHlp_GetUVM(PPDMDEVINS pDevIns)
2234{
2235 PDMDEV_ASSERT_DEVINS(pDevIns);
2236 LogFlow(("pdmR3DevHlp_GetUVM: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns->Internal.s.pVMR3));
2237 return pDevIns->Internal.s.pVMR3->pUVM;
2238}
2239
2240
2241/** @interface_method_impl{PDMDEVHLPR3,pfnGetVM} */
2242static DECLCALLBACK(PVM) pdmR3DevHlp_GetVM(PPDMDEVINS pDevIns)
2243{
2244 PDMDEV_ASSERT_DEVINS(pDevIns);
2245 LogFlow(("pdmR3DevHlp_GetVM: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns->Internal.s.pVMR3));
2246 return pDevIns->Internal.s.pVMR3;
2247}
2248
2249
2250/** @interface_method_impl{PDMDEVHLPR3,pfnGetVMCPU} */
2251static DECLCALLBACK(PVMCPU) pdmR3DevHlp_GetVMCPU(PPDMDEVINS pDevIns)
2252{
2253 PDMDEV_ASSERT_DEVINS(pDevIns);
2254 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2255 LogFlow(("pdmR3DevHlp_GetVMCPU: caller='%s'/%d for CPU %u\n", pDevIns->pReg->szName, pDevIns->iInstance, VMMGetCpuId(pDevIns->Internal.s.pVMR3)));
2256 return VMMGetCpu(pDevIns->Internal.s.pVMR3);
2257}
2258
2259
2260/** @interface_method_impl{PDMDEVHLPR3,pfnPCIBusRegister} */
2261static DECLCALLBACK(int) pdmR3DevHlp_PCIBusRegister(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3)
2262{
2263 PDMDEV_ASSERT_DEVINS(pDevIns);
2264 PVM pVM = pDevIns->Internal.s.pVMR3;
2265 VM_ASSERT_EMT(pVM);
2266 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: pPciBusReg=%p:{.u32Version=%#x, .pfnRegisterR3=%p, .pfnIORegionRegisterR3=%p, "
2267 ".pfnSetIrqR3=%p, .pfnFakePCIBIOSR3=%p, .pszSetIrqRC=%p:{%s}, .pszSetIrqR0=%p:{%s}} ppPciHlpR3=%p\n",
2268 pDevIns->pReg->szName, pDevIns->iInstance, pPciBusReg, pPciBusReg->u32Version, pPciBusReg->pfnRegisterR3,
2269 pPciBusReg->pfnIORegionRegisterR3, pPciBusReg->pfnSetIrqR3, pPciBusReg->pfnFakePCIBIOSR3,
2270 pPciBusReg->pszSetIrqRC, pPciBusReg->pszSetIrqRC, pPciBusReg->pszSetIrqR0, pPciBusReg->pszSetIrqR0, ppPciHlpR3));
2271
2272 /*
2273 * Validate the structure.
2274 */
2275 if (pPciBusReg->u32Version != PDM_PCIBUSREG_VERSION)
2276 {
2277 AssertMsgFailed(("u32Version=%#x expected %#x\n", pPciBusReg->u32Version, PDM_PCIBUSREG_VERSION));
2278 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2279 return VERR_INVALID_PARAMETER;
2280 }
2281 if ( !pPciBusReg->pfnRegisterR3
2282 || !pPciBusReg->pfnIORegionRegisterR3
2283 || !pPciBusReg->pfnSetIrqR3
2284 || (!pPciBusReg->pfnFakePCIBIOSR3 && !pVM->pdm.s.aPciBuses[0].pDevInsR3)) /* Only the first bus needs to do the BIOS work. */
2285 {
2286 Assert(pPciBusReg->pfnRegisterR3);
2287 Assert(pPciBusReg->pfnIORegionRegisterR3);
2288 Assert(pPciBusReg->pfnSetIrqR3);
2289 Assert(pPciBusReg->pfnFakePCIBIOSR3);
2290 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2291 return VERR_INVALID_PARAMETER;
2292 }
2293 if ( pPciBusReg->pszSetIrqRC
2294 && !VALID_PTR(pPciBusReg->pszSetIrqRC))
2295 {
2296 Assert(VALID_PTR(pPciBusReg->pszSetIrqRC));
2297 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2298 return VERR_INVALID_PARAMETER;
2299 }
2300 if ( pPciBusReg->pszSetIrqR0
2301 && !VALID_PTR(pPciBusReg->pszSetIrqR0))
2302 {
2303 Assert(VALID_PTR(pPciBusReg->pszSetIrqR0));
2304 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2305 return VERR_INVALID_PARAMETER;
2306 }
2307 if (!ppPciHlpR3)
2308 {
2309 Assert(ppPciHlpR3);
2310 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (ppPciHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2311 return VERR_INVALID_PARAMETER;
2312 }
2313
2314 /*
2315 * Find free PCI bus entry.
2316 */
2317 unsigned iBus = 0;
2318 for (iBus = 0; iBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses); iBus++)
2319 if (!pVM->pdm.s.aPciBuses[iBus].pDevInsR3)
2320 break;
2321 if (iBus >= RT_ELEMENTS(pVM->pdm.s.aPciBuses))
2322 {
2323 AssertMsgFailed(("Too many PCI buses. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aPciBuses)));
2324 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (pci bus)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2325 return VERR_INVALID_PARAMETER;
2326 }
2327 PPDMPCIBUS pPciBus = &pVM->pdm.s.aPciBuses[iBus];
2328
2329 /*
2330 * Resolve and init the RC bits.
2331 */
2332 if (pPciBusReg->pszSetIrqRC)
2333 {
2334 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pPciBusReg->pszSetIrqRC, &pPciBus->pfnSetIrqRC);
2335 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pPciBusReg->pszSetIrqRC, rc));
2336 if (RT_FAILURE(rc))
2337 {
2338 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2339 return rc;
2340 }
2341 pPciBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2342 }
2343 else
2344 {
2345 pPciBus->pfnSetIrqRC = 0;
2346 pPciBus->pDevInsRC = 0;
2347 }
2348
2349 /*
2350 * Resolve and init the R0 bits.
2351 */
2352 if (pPciBusReg->pszSetIrqR0)
2353 {
2354 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pPciBusReg->pszSetIrqR0, &pPciBus->pfnSetIrqR0);
2355 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pPciBusReg->pszSetIrqR0, rc));
2356 if (RT_FAILURE(rc))
2357 {
2358 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2359 return rc;
2360 }
2361 pPciBus->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2362 }
2363 else
2364 {
2365 pPciBus->pfnSetIrqR0 = 0;
2366 pPciBus->pDevInsR0 = 0;
2367 }
2368
2369 /*
2370 * Init the R3 bits.
2371 */
2372 pPciBus->iBus = iBus;
2373 pPciBus->pDevInsR3 = pDevIns;
2374 pPciBus->pfnRegisterR3 = pPciBusReg->pfnRegisterR3;
2375 pPciBus->pfnRegisterMsiR3 = pPciBusReg->pfnRegisterMsiR3;
2376 pPciBus->pfnIORegionRegisterR3 = pPciBusReg->pfnIORegionRegisterR3;
2377 pPciBus->pfnSetConfigCallbacksR3 = pPciBusReg->pfnSetConfigCallbacksR3;
2378 pPciBus->pfnSetIrqR3 = pPciBusReg->pfnSetIrqR3;
2379 pPciBus->pfnFakePCIBIOSR3 = pPciBusReg->pfnFakePCIBIOSR3;
2380
2381 Log(("PDM: Registered PCI bus device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
2382
2383 /* set the helper pointer and return. */
2384 *ppPciHlpR3 = &g_pdmR3DevPciHlp;
2385 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2386 return VINF_SUCCESS;
2387}
2388
2389
2390/** @interface_method_impl{PDMDEVHLPR3,pfnPICRegister} */
2391static DECLCALLBACK(int) pdmR3DevHlp_PICRegister(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3)
2392{
2393 PDMDEV_ASSERT_DEVINS(pDevIns);
2394 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2395 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: pPicReg=%p:{.u32Version=%#x, .pfnSetIrqR3=%p, .pfnGetInterruptR3=%p, .pszGetIrqRC=%p:{%s}, .pszGetInterruptRC=%p:{%s}, .pszGetIrqR0=%p:{%s}, .pszGetInterruptR0=%p:{%s} } ppPicHlpR3=%p\n",
2396 pDevIns->pReg->szName, pDevIns->iInstance, pPicReg, pPicReg->u32Version, pPicReg->pfnSetIrqR3, pPicReg->pfnGetInterruptR3,
2397 pPicReg->pszSetIrqRC, pPicReg->pszSetIrqRC, pPicReg->pszGetInterruptRC, pPicReg->pszGetInterruptRC,
2398 pPicReg->pszSetIrqR0, pPicReg->pszSetIrqR0, pPicReg->pszGetInterruptR0, pPicReg->pszGetInterruptR0,
2399 ppPicHlpR3));
2400
2401 /*
2402 * Validate input.
2403 */
2404 if (pPicReg->u32Version != PDM_PICREG_VERSION)
2405 {
2406 AssertMsgFailed(("u32Version=%#x expected %#x\n", pPicReg->u32Version, PDM_PICREG_VERSION));
2407 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2408 return VERR_INVALID_PARAMETER;
2409 }
2410 if ( !pPicReg->pfnSetIrqR3
2411 || !pPicReg->pfnGetInterruptR3)
2412 {
2413 Assert(pPicReg->pfnSetIrqR3);
2414 Assert(pPicReg->pfnGetInterruptR3);
2415 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2416 return VERR_INVALID_PARAMETER;
2417 }
2418 if ( ( pPicReg->pszSetIrqRC
2419 || pPicReg->pszGetInterruptRC)
2420 && ( !VALID_PTR(pPicReg->pszSetIrqRC)
2421 || !VALID_PTR(pPicReg->pszGetInterruptRC))
2422 )
2423 {
2424 Assert(VALID_PTR(pPicReg->pszSetIrqRC));
2425 Assert(VALID_PTR(pPicReg->pszGetInterruptRC));
2426 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (RC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2427 return VERR_INVALID_PARAMETER;
2428 }
2429 if ( pPicReg->pszSetIrqRC
2430 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC))
2431 {
2432 Assert(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC);
2433 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (RC flag)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2434 return VERR_INVALID_PARAMETER;
2435 }
2436 if ( pPicReg->pszSetIrqR0
2437 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0))
2438 {
2439 Assert(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0);
2440 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (R0 flag)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2441 return VERR_INVALID_PARAMETER;
2442 }
2443 if (!ppPicHlpR3)
2444 {
2445 Assert(ppPicHlpR3);
2446 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (ppPicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2447 return VERR_INVALID_PARAMETER;
2448 }
2449
2450 /*
2451 * Only one PIC device.
2452 */
2453 PVM pVM = pDevIns->Internal.s.pVMR3;
2454 if (pVM->pdm.s.Pic.pDevInsR3)
2455 {
2456 AssertMsgFailed(("Only one pic device is supported!\n"));
2457 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2458 return VERR_INVALID_PARAMETER;
2459 }
2460
2461 /*
2462 * RC stuff.
2463 */
2464 if (pPicReg->pszSetIrqRC)
2465 {
2466 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pPicReg->pszSetIrqRC, &pVM->pdm.s.Pic.pfnSetIrqRC);
2467 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pPicReg->pszSetIrqRC, rc));
2468 if (RT_SUCCESS(rc))
2469 {
2470 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pPicReg->pszGetInterruptRC, &pVM->pdm.s.Pic.pfnGetInterruptRC);
2471 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pPicReg->pszGetInterruptRC, rc));
2472 }
2473 if (RT_FAILURE(rc))
2474 {
2475 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2476 return rc;
2477 }
2478 pVM->pdm.s.Pic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2479 }
2480 else
2481 {
2482 pVM->pdm.s.Pic.pDevInsRC = 0;
2483 pVM->pdm.s.Pic.pfnSetIrqRC = 0;
2484 pVM->pdm.s.Pic.pfnGetInterruptRC = 0;
2485 }
2486
2487 /*
2488 * R0 stuff.
2489 */
2490 if (pPicReg->pszSetIrqR0)
2491 {
2492 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pPicReg->pszSetIrqR0, &pVM->pdm.s.Pic.pfnSetIrqR0);
2493 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pPicReg->pszSetIrqR0, rc));
2494 if (RT_SUCCESS(rc))
2495 {
2496 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pPicReg->pszGetInterruptR0, &pVM->pdm.s.Pic.pfnGetInterruptR0);
2497 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pPicReg->pszGetInterruptR0, rc));
2498 }
2499 if (RT_FAILURE(rc))
2500 {
2501 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2502 return rc;
2503 }
2504 pVM->pdm.s.Pic.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2505 Assert(pVM->pdm.s.Pic.pDevInsR0);
2506 }
2507 else
2508 {
2509 pVM->pdm.s.Pic.pfnSetIrqR0 = 0;
2510 pVM->pdm.s.Pic.pfnGetInterruptR0 = 0;
2511 pVM->pdm.s.Pic.pDevInsR0 = 0;
2512 }
2513
2514 /*
2515 * R3 stuff.
2516 */
2517 pVM->pdm.s.Pic.pDevInsR3 = pDevIns;
2518 pVM->pdm.s.Pic.pfnSetIrqR3 = pPicReg->pfnSetIrqR3;
2519 pVM->pdm.s.Pic.pfnGetInterruptR3 = pPicReg->pfnGetInterruptR3;
2520 Log(("PDM: Registered PIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
2521
2522 /* set the helper pointer and return. */
2523 *ppPicHlpR3 = &g_pdmR3DevPicHlp;
2524 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2525 return VINF_SUCCESS;
2526}
2527
2528
2529/** @interface_method_impl{PDMDEVHLPR3,pfnAPICRegister} */
2530static DECLCALLBACK(int) pdmR3DevHlp_APICRegister(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3)
2531{
2532 PDMDEV_ASSERT_DEVINS(pDevIns);
2533 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2534 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: pApicReg=%p:{.u32Version=%#x, .pfnGetInterruptR3=%p, .pfnSetBaseR3=%p, .pfnGetBaseR3=%p, "
2535 ".pfnSetTPRR3=%p, .pfnGetTPRR3=%p, .pfnWriteMSR3=%p, .pfnReadMSR3=%p, .pfnBusDeliverR3=%p, .pfnLocalInterruptR3=%p, pszGetInterruptRC=%p:{%s}, pszSetBaseRC=%p:{%s}, pszGetBaseRC=%p:{%s}, "
2536 ".pszSetTPRRC=%p:{%s}, .pszGetTPRRC=%p:{%s}, .pszWriteMSRRC=%p:{%s}, .pszReadMSRRC=%p:{%s}, .pszBusDeliverRC=%p:{%s}, .pszLocalInterruptRC=%p:{%s}} ppApicHlpR3=%p\n",
2537 pDevIns->pReg->szName, pDevIns->iInstance, pApicReg, pApicReg->u32Version, pApicReg->pfnGetInterruptR3, pApicReg->pfnSetBaseR3,
2538 pApicReg->pfnGetBaseR3, pApicReg->pfnSetTPRR3, pApicReg->pfnGetTPRR3, pApicReg->pfnWriteMSRR3, pApicReg->pfnReadMSRR3, pApicReg->pfnBusDeliverR3, pApicReg->pfnLocalInterruptR3, pApicReg->pszGetInterruptRC,
2539 pApicReg->pszGetInterruptRC, pApicReg->pszSetBaseRC, pApicReg->pszSetBaseRC, pApicReg->pszGetBaseRC, pApicReg->pszGetBaseRC,
2540 pApicReg->pszSetTPRRC, pApicReg->pszSetTPRRC, pApicReg->pszGetTPRRC, pApicReg->pszGetTPRRC, pApicReg->pszWriteMSRRC, pApicReg->pszWriteMSRRC, pApicReg->pszReadMSRRC, pApicReg->pszReadMSRRC, pApicReg->pszBusDeliverRC,
2541 pApicReg->pszBusDeliverRC, pApicReg->pszLocalInterruptRC, pApicReg->pszLocalInterruptRC, ppApicHlpR3));
2542
2543 /*
2544 * Validate input.
2545 */
2546 if (pApicReg->u32Version != PDM_APICREG_VERSION)
2547 {
2548 AssertMsgFailed(("u32Version=%#x expected %#x\n", pApicReg->u32Version, PDM_APICREG_VERSION));
2549 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2550 return VERR_INVALID_PARAMETER;
2551 }
2552 if ( !pApicReg->pfnGetInterruptR3
2553 || !pApicReg->pfnHasPendingIrqR3
2554 || !pApicReg->pfnSetBaseR3
2555 || !pApicReg->pfnGetBaseR3
2556 || !pApicReg->pfnSetTPRR3
2557 || !pApicReg->pfnGetTPRR3
2558 || !pApicReg->pfnWriteMSRR3
2559 || !pApicReg->pfnReadMSRR3
2560 || !pApicReg->pfnBusDeliverR3
2561 || !pApicReg->pfnLocalInterruptR3)
2562 {
2563 Assert(pApicReg->pfnGetInterruptR3);
2564 Assert(pApicReg->pfnHasPendingIrqR3);
2565 Assert(pApicReg->pfnSetBaseR3);
2566 Assert(pApicReg->pfnGetBaseR3);
2567 Assert(pApicReg->pfnSetTPRR3);
2568 Assert(pApicReg->pfnGetTPRR3);
2569 Assert(pApicReg->pfnWriteMSRR3);
2570 Assert(pApicReg->pfnReadMSRR3);
2571 Assert(pApicReg->pfnBusDeliverR3);
2572 Assert(pApicReg->pfnLocalInterruptR3);
2573 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2574 return VERR_INVALID_PARAMETER;
2575 }
2576 if ( ( pApicReg->pszGetInterruptRC
2577 || pApicReg->pszHasPendingIrqRC
2578 || pApicReg->pszSetBaseRC
2579 || pApicReg->pszGetBaseRC
2580 || pApicReg->pszSetTPRRC
2581 || pApicReg->pszGetTPRRC
2582 || pApicReg->pszWriteMSRRC
2583 || pApicReg->pszReadMSRRC
2584 || pApicReg->pszBusDeliverRC
2585 || pApicReg->pszLocalInterruptRC)
2586 && ( !VALID_PTR(pApicReg->pszGetInterruptRC)
2587 || !VALID_PTR(pApicReg->pszHasPendingIrqRC)
2588 || !VALID_PTR(pApicReg->pszSetBaseRC)
2589 || !VALID_PTR(pApicReg->pszGetBaseRC)
2590 || !VALID_PTR(pApicReg->pszSetTPRRC)
2591 || !VALID_PTR(pApicReg->pszGetTPRRC)
2592 || !VALID_PTR(pApicReg->pszWriteMSRRC)
2593 || !VALID_PTR(pApicReg->pszReadMSRRC)
2594 || !VALID_PTR(pApicReg->pszBusDeliverRC)
2595 || !VALID_PTR(pApicReg->pszLocalInterruptRC))
2596 )
2597 {
2598 Assert(VALID_PTR(pApicReg->pszGetInterruptRC));
2599 Assert(VALID_PTR(pApicReg->pszHasPendingIrqRC));
2600 Assert(VALID_PTR(pApicReg->pszSetBaseRC));
2601 Assert(VALID_PTR(pApicReg->pszGetBaseRC));
2602 Assert(VALID_PTR(pApicReg->pszSetTPRRC));
2603 Assert(VALID_PTR(pApicReg->pszGetTPRRC));
2604 Assert(VALID_PTR(pApicReg->pszReadMSRRC));
2605 Assert(VALID_PTR(pApicReg->pszWriteMSRRC));
2606 Assert(VALID_PTR(pApicReg->pszBusDeliverRC));
2607 Assert(VALID_PTR(pApicReg->pszLocalInterruptRC));
2608 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (RC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2609 return VERR_INVALID_PARAMETER;
2610 }
2611 if ( ( pApicReg->pszGetInterruptR0
2612 || pApicReg->pszHasPendingIrqR0
2613 || pApicReg->pszSetBaseR0
2614 || pApicReg->pszGetBaseR0
2615 || pApicReg->pszSetTPRR0
2616 || pApicReg->pszGetTPRR0
2617 || pApicReg->pszWriteMSRR0
2618 || pApicReg->pszReadMSRR0
2619 || pApicReg->pszBusDeliverR0
2620 || pApicReg->pszLocalInterruptR0)
2621 && ( !VALID_PTR(pApicReg->pszGetInterruptR0)
2622 || !VALID_PTR(pApicReg->pszHasPendingIrqR0)
2623 || !VALID_PTR(pApicReg->pszSetBaseR0)
2624 || !VALID_PTR(pApicReg->pszGetBaseR0)
2625 || !VALID_PTR(pApicReg->pszSetTPRR0)
2626 || !VALID_PTR(pApicReg->pszGetTPRR0)
2627 || !VALID_PTR(pApicReg->pszReadMSRR0)
2628 || !VALID_PTR(pApicReg->pszWriteMSRR0)
2629 || !VALID_PTR(pApicReg->pszBusDeliverR0)
2630 || !VALID_PTR(pApicReg->pszLocalInterruptR0))
2631 )
2632 {
2633 Assert(VALID_PTR(pApicReg->pszGetInterruptR0));
2634 Assert(VALID_PTR(pApicReg->pszHasPendingIrqR0));
2635 Assert(VALID_PTR(pApicReg->pszSetBaseR0));
2636 Assert(VALID_PTR(pApicReg->pszGetBaseR0));
2637 Assert(VALID_PTR(pApicReg->pszSetTPRR0));
2638 Assert(VALID_PTR(pApicReg->pszGetTPRR0));
2639 Assert(VALID_PTR(pApicReg->pszReadMSRR0));
2640 Assert(VALID_PTR(pApicReg->pszWriteMSRR0));
2641 Assert(VALID_PTR(pApicReg->pszBusDeliverR0));
2642 Assert(VALID_PTR(pApicReg->pszLocalInterruptR0));
2643 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (R0 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2644 return VERR_INVALID_PARAMETER;
2645 }
2646 if (!ppApicHlpR3)
2647 {
2648 Assert(ppApicHlpR3);
2649 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (ppApicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2650 return VERR_INVALID_PARAMETER;
2651 }
2652
2653 /*
2654 * Only one APIC device. On SMP we have single logical device covering all LAPICs,
2655 * as they need to communicate and share state easily.
2656 */
2657 PVM pVM = pDevIns->Internal.s.pVMR3;
2658 if (pVM->pdm.s.Apic.pDevInsR3)
2659 {
2660 AssertMsgFailed(("Only one apic device is supported!\n"));
2661 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2662 return VERR_INVALID_PARAMETER;
2663 }
2664
2665 /*
2666 * Resolve & initialize the RC bits.
2667 */
2668 if (pApicReg->pszGetInterruptRC)
2669 {
2670 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszGetInterruptRC, &pVM->pdm.s.Apic.pfnGetInterruptRC);
2671 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszGetInterruptRC, rc));
2672 if (RT_SUCCESS(rc))
2673 {
2674 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszHasPendingIrqRC, &pVM->pdm.s.Apic.pfnHasPendingIrqRC);
2675 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszHasPendingIrqRC, rc));
2676 }
2677 if (RT_SUCCESS(rc))
2678 {
2679 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszSetBaseRC, &pVM->pdm.s.Apic.pfnSetBaseRC);
2680 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszSetBaseRC, rc));
2681 }
2682 if (RT_SUCCESS(rc))
2683 {
2684 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszGetBaseRC, &pVM->pdm.s.Apic.pfnGetBaseRC);
2685 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszGetBaseRC, rc));
2686 }
2687 if (RT_SUCCESS(rc))
2688 {
2689 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszSetTPRRC, &pVM->pdm.s.Apic.pfnSetTPRRC);
2690 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszSetTPRRC, rc));
2691 }
2692 if (RT_SUCCESS(rc))
2693 {
2694 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszGetTPRRC, &pVM->pdm.s.Apic.pfnGetTPRRC);
2695 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszGetTPRRC, rc));
2696 }
2697 if (RT_SUCCESS(rc))
2698 {
2699 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszWriteMSRRC, &pVM->pdm.s.Apic.pfnWriteMSRRC);
2700 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszWriteMSRRC, rc));
2701 }
2702 if (RT_SUCCESS(rc))
2703 {
2704 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszReadMSRRC, &pVM->pdm.s.Apic.pfnReadMSRRC);
2705 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszReadMSRRC, rc));
2706 }
2707 if (RT_SUCCESS(rc))
2708 {
2709 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszBusDeliverRC, &pVM->pdm.s.Apic.pfnBusDeliverRC);
2710 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszBusDeliverRC, rc));
2711 }
2712 if (RT_SUCCESS(rc))
2713 {
2714 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszLocalInterruptRC, &pVM->pdm.s.Apic.pfnLocalInterruptRC);
2715 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszLocalInterruptRC, rc));
2716 }
2717 if (RT_FAILURE(rc))
2718 {
2719 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2720 return rc;
2721 }
2722 pVM->pdm.s.Apic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2723 }
2724 else
2725 {
2726 pVM->pdm.s.Apic.pDevInsRC = 0;
2727 pVM->pdm.s.Apic.pfnGetInterruptRC = 0;
2728 pVM->pdm.s.Apic.pfnHasPendingIrqRC = 0;
2729 pVM->pdm.s.Apic.pfnSetBaseRC = 0;
2730 pVM->pdm.s.Apic.pfnGetBaseRC = 0;
2731 pVM->pdm.s.Apic.pfnSetTPRRC = 0;
2732 pVM->pdm.s.Apic.pfnGetTPRRC = 0;
2733 pVM->pdm.s.Apic.pfnWriteMSRRC = 0;
2734 pVM->pdm.s.Apic.pfnReadMSRRC = 0;
2735 pVM->pdm.s.Apic.pfnBusDeliverRC = 0;
2736 pVM->pdm.s.Apic.pfnLocalInterruptRC = 0;
2737 }
2738
2739 /*
2740 * Resolve & initialize the R0 bits.
2741 */
2742 if (pApicReg->pszGetInterruptR0)
2743 {
2744 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszGetInterruptR0, &pVM->pdm.s.Apic.pfnGetInterruptR0);
2745 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszGetInterruptR0, rc));
2746 if (RT_SUCCESS(rc))
2747 {
2748 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszHasPendingIrqR0, &pVM->pdm.s.Apic.pfnHasPendingIrqR0);
2749 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszHasPendingIrqR0, rc));
2750 }
2751 if (RT_SUCCESS(rc))
2752 {
2753 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszSetBaseR0, &pVM->pdm.s.Apic.pfnSetBaseR0);
2754 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszSetBaseR0, rc));
2755 }
2756 if (RT_SUCCESS(rc))
2757 {
2758 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszGetBaseR0, &pVM->pdm.s.Apic.pfnGetBaseR0);
2759 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszGetBaseR0, rc));
2760 }
2761 if (RT_SUCCESS(rc))
2762 {
2763 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszSetTPRR0, &pVM->pdm.s.Apic.pfnSetTPRR0);
2764 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszSetTPRR0, rc));
2765 }
2766 if (RT_SUCCESS(rc))
2767 {
2768 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszGetTPRR0, &pVM->pdm.s.Apic.pfnGetTPRR0);
2769 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszGetTPRR0, rc));
2770 }
2771 if (RT_SUCCESS(rc))
2772 {
2773 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszWriteMSRR0, &pVM->pdm.s.Apic.pfnWriteMSRR0);
2774 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszWriteMSRR0, rc));
2775 }
2776 if (RT_SUCCESS(rc))
2777 {
2778 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszReadMSRR0, &pVM->pdm.s.Apic.pfnReadMSRR0);
2779 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszReadMSRR0, rc));
2780 }
2781 if (RT_SUCCESS(rc))
2782 {
2783 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszBusDeliverR0, &pVM->pdm.s.Apic.pfnBusDeliverR0);
2784 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszBusDeliverR0, rc));
2785 }
2786 if (RT_SUCCESS(rc))
2787 {
2788 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszLocalInterruptR0, &pVM->pdm.s.Apic.pfnLocalInterruptR0);
2789 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszLocalInterruptR0, rc));
2790 }
2791 if (RT_FAILURE(rc))
2792 {
2793 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2794 return rc;
2795 }
2796 pVM->pdm.s.Apic.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2797 Assert(pVM->pdm.s.Apic.pDevInsR0);
2798 }
2799 else
2800 {
2801 pVM->pdm.s.Apic.pfnGetInterruptR0 = 0;
2802 pVM->pdm.s.Apic.pfnHasPendingIrqR0 = 0;
2803 pVM->pdm.s.Apic.pfnSetBaseR0 = 0;
2804 pVM->pdm.s.Apic.pfnGetBaseR0 = 0;
2805 pVM->pdm.s.Apic.pfnSetTPRR0 = 0;
2806 pVM->pdm.s.Apic.pfnGetTPRR0 = 0;
2807 pVM->pdm.s.Apic.pfnWriteMSRR0 = 0;
2808 pVM->pdm.s.Apic.pfnReadMSRR0 = 0;
2809 pVM->pdm.s.Apic.pfnBusDeliverR0 = 0;
2810 pVM->pdm.s.Apic.pfnLocalInterruptR0 = 0;
2811 pVM->pdm.s.Apic.pDevInsR0 = 0;
2812 }
2813
2814 /*
2815 * Initialize the HC bits.
2816 */
2817 pVM->pdm.s.Apic.pDevInsR3 = pDevIns;
2818 pVM->pdm.s.Apic.pfnGetInterruptR3 = pApicReg->pfnGetInterruptR3;
2819 pVM->pdm.s.Apic.pfnHasPendingIrqR3 = pApicReg->pfnHasPendingIrqR3;
2820 pVM->pdm.s.Apic.pfnSetBaseR3 = pApicReg->pfnSetBaseR3;
2821 pVM->pdm.s.Apic.pfnGetBaseR3 = pApicReg->pfnGetBaseR3;
2822 pVM->pdm.s.Apic.pfnSetTPRR3 = pApicReg->pfnSetTPRR3;
2823 pVM->pdm.s.Apic.pfnGetTPRR3 = pApicReg->pfnGetTPRR3;
2824 pVM->pdm.s.Apic.pfnWriteMSRR3 = pApicReg->pfnWriteMSRR3;
2825 pVM->pdm.s.Apic.pfnReadMSRR3 = pApicReg->pfnReadMSRR3;
2826 pVM->pdm.s.Apic.pfnBusDeliverR3 = pApicReg->pfnBusDeliverR3;
2827 pVM->pdm.s.Apic.pfnLocalInterruptR3 = pApicReg->pfnLocalInterruptR3;
2828 Log(("PDM: Registered APIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
2829
2830 /* set the helper pointer and return. */
2831 *ppApicHlpR3 = &g_pdmR3DevApicHlp;
2832 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2833 return VINF_SUCCESS;
2834}
2835
2836
2837/** @interface_method_impl{PDMDEVHLPR3,pfnIOAPICRegister} */
2838static DECLCALLBACK(int) pdmR3DevHlp_IOAPICRegister(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3)
2839{
2840 PDMDEV_ASSERT_DEVINS(pDevIns);
2841 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2842 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: pIoApicReg=%p:{.u32Version=%#x, .pfnSetIrqR3=%p, .pszSetIrqRC=%p:{%s}, .pszSetIrqR0=%p:{%s}} ppIoApicHlpR3=%p\n",
2843 pDevIns->pReg->szName, pDevIns->iInstance, pIoApicReg, pIoApicReg->u32Version, pIoApicReg->pfnSetIrqR3,
2844 pIoApicReg->pszSetIrqRC, pIoApicReg->pszSetIrqRC, pIoApicReg->pszSetIrqR0, pIoApicReg->pszSetIrqR0, ppIoApicHlpR3));
2845
2846 /*
2847 * Validate input.
2848 */
2849 if (pIoApicReg->u32Version != PDM_IOAPICREG_VERSION)
2850 {
2851 AssertMsgFailed(("u32Version=%#x expected %#x\n", pIoApicReg->u32Version, PDM_IOAPICREG_VERSION));
2852 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2853 return VERR_INVALID_PARAMETER;
2854 }
2855 if (!pIoApicReg->pfnSetIrqR3 || !pIoApicReg->pfnSendMsiR3)
2856 {
2857 Assert(pIoApicReg->pfnSetIrqR3);
2858 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2859 return VERR_INVALID_PARAMETER;
2860 }
2861 if ( pIoApicReg->pszSetIrqRC
2862 && !VALID_PTR(pIoApicReg->pszSetIrqRC))
2863 {
2864 Assert(VALID_PTR(pIoApicReg->pszSetIrqRC));
2865 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2866 return VERR_INVALID_PARAMETER;
2867 }
2868 if ( pIoApicReg->pszSendMsiRC
2869 && !VALID_PTR(pIoApicReg->pszSendMsiRC))
2870 {
2871 Assert(VALID_PTR(pIoApicReg->pszSendMsiRC));
2872 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2873 return VERR_INVALID_PARAMETER;
2874 }
2875 if ( pIoApicReg->pszSetIrqR0
2876 && !VALID_PTR(pIoApicReg->pszSetIrqR0))
2877 {
2878 Assert(VALID_PTR(pIoApicReg->pszSetIrqR0));
2879 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2880 return VERR_INVALID_PARAMETER;
2881 }
2882 if ( pIoApicReg->pszSendMsiR0
2883 && !VALID_PTR(pIoApicReg->pszSendMsiR0))
2884 {
2885 Assert(VALID_PTR(pIoApicReg->pszSendMsiR0));
2886 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2887 return VERR_INVALID_PARAMETER;
2888 }
2889 if (!ppIoApicHlpR3)
2890 {
2891 Assert(ppIoApicHlpR3);
2892 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (ppApicHlp)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2893 return VERR_INVALID_PARAMETER;
2894 }
2895
2896 /*
2897 * The I/O APIC requires the APIC to be present (hacks++).
2898 * If the I/O APIC does GC stuff so must the APIC.
2899 */
2900 PVM pVM = pDevIns->Internal.s.pVMR3;
2901 if (!pVM->pdm.s.Apic.pDevInsR3)
2902 {
2903 AssertMsgFailed(("Configuration error / Init order error! No APIC!\n"));
2904 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (no APIC)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2905 return VERR_INVALID_PARAMETER;
2906 }
2907 if ( pIoApicReg->pszSetIrqRC
2908 && !pVM->pdm.s.Apic.pDevInsRC)
2909 {
2910 AssertMsgFailed(("Configuration error! APIC doesn't do GC, I/O APIC does!\n"));
2911 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (no GC APIC)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2912 return VERR_INVALID_PARAMETER;
2913 }
2914
2915 /*
2916 * Only one I/O APIC device.
2917 */
2918 if (pVM->pdm.s.IoApic.pDevInsR3)
2919 {
2920 AssertMsgFailed(("Only one ioapic device is supported!\n"));
2921 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (only one)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2922 return VERR_INVALID_PARAMETER;
2923 }
2924
2925 /*
2926 * Resolve & initialize the GC bits.
2927 */
2928 if (pIoApicReg->pszSetIrqRC)
2929 {
2930 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pIoApicReg->pszSetIrqRC, &pVM->pdm.s.IoApic.pfnSetIrqRC);
2931 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pIoApicReg->pszSetIrqRC, rc));
2932 if (RT_FAILURE(rc))
2933 {
2934 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2935 return rc;
2936 }
2937 pVM->pdm.s.IoApic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2938 }
2939 else
2940 {
2941 pVM->pdm.s.IoApic.pDevInsRC = 0;
2942 pVM->pdm.s.IoApic.pfnSetIrqRC = 0;
2943 }
2944
2945 if (pIoApicReg->pszSendMsiRC)
2946 {
2947 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pIoApicReg->pszSetIrqRC, &pVM->pdm.s.IoApic.pfnSendMsiRC);
2948 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pIoApicReg->pszSendMsiRC, rc));
2949 if (RT_FAILURE(rc))
2950 {
2951 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2952 return rc;
2953 }
2954 }
2955 else
2956 {
2957 pVM->pdm.s.IoApic.pfnSendMsiRC = 0;
2958 }
2959
2960 /*
2961 * Resolve & initialize the R0 bits.
2962 */
2963 if (pIoApicReg->pszSetIrqR0)
2964 {
2965 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pIoApicReg->pszSetIrqR0, &pVM->pdm.s.IoApic.pfnSetIrqR0);
2966 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pIoApicReg->pszSetIrqR0, rc));
2967 if (RT_FAILURE(rc))
2968 {
2969 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2970 return rc;
2971 }
2972 pVM->pdm.s.IoApic.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2973 Assert(pVM->pdm.s.IoApic.pDevInsR0);
2974 }
2975 else
2976 {
2977 pVM->pdm.s.IoApic.pfnSetIrqR0 = 0;
2978 pVM->pdm.s.IoApic.pDevInsR0 = 0;
2979 }
2980
2981 if (pIoApicReg->pszSendMsiR0)
2982 {
2983 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pIoApicReg->pszSetIrqR0, &pVM->pdm.s.IoApic.pfnSendMsiR0);
2984 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pIoApicReg->pszSendMsiR0, rc));
2985 if (RT_FAILURE(rc))
2986 {
2987 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2988 return rc;
2989 }
2990 }
2991 else
2992 {
2993 pVM->pdm.s.IoApic.pfnSendMsiR0 = 0;
2994 }
2995
2996
2997 /*
2998 * Initialize the R3 bits.
2999 */
3000 pVM->pdm.s.IoApic.pDevInsR3 = pDevIns;
3001 pVM->pdm.s.IoApic.pfnSetIrqR3 = pIoApicReg->pfnSetIrqR3;
3002 pVM->pdm.s.IoApic.pfnSendMsiR3 = pIoApicReg->pfnSendMsiR3;
3003 Log(("PDM: Registered I/O APIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3004
3005 /* set the helper pointer and return. */
3006 *ppIoApicHlpR3 = &g_pdmR3DevIoApicHlp;
3007 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3008 return VINF_SUCCESS;
3009}
3010
3011
3012/** @interface_method_impl{PDMDEVHLPR3,pfnHPETRegister} */
3013static DECLCALLBACK(int) pdmR3DevHlp_HPETRegister(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3)
3014{
3015 PDMDEV_ASSERT_DEVINS(pDevIns);
3016 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3017 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d:\n"));
3018
3019 /*
3020 * Validate input.
3021 */
3022 if (pHpetReg->u32Version != PDM_HPETREG_VERSION)
3023 {
3024 AssertMsgFailed(("u32Version=%#x expected %#x\n", pHpetReg->u32Version, PDM_HPETREG_VERSION));
3025 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3026 return VERR_INVALID_PARAMETER;
3027 }
3028
3029 if (!ppHpetHlpR3)
3030 {
3031 Assert(ppHpetHlpR3);
3032 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d: returns %Rrc (ppApicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3033 return VERR_INVALID_PARAMETER;
3034 }
3035
3036 /* set the helper pointer and return. */
3037 *ppHpetHlpR3 = &g_pdmR3DevHpetHlp;
3038 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3039 return VINF_SUCCESS;
3040}
3041
3042
3043/** @interface_method_impl{PDMDEVHLPR3,pfnPciRawRegister} */
3044static DECLCALLBACK(int) pdmR3DevHlp_PciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
3045{
3046 PDMDEV_ASSERT_DEVINS(pDevIns);
3047 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3048 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d:\n"));
3049
3050 /*
3051 * Validate input.
3052 */
3053 if (pPciRawReg->u32Version != PDM_PCIRAWREG_VERSION)
3054 {
3055 AssertMsgFailed(("u32Version=%#x expected %#x\n", pPciRawReg->u32Version, PDM_PCIRAWREG_VERSION));
3056 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3057 return VERR_INVALID_PARAMETER;
3058 }
3059
3060 if (!ppPciRawHlpR3)
3061 {
3062 Assert(ppPciRawHlpR3);
3063 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc (ppApicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3064 return VERR_INVALID_PARAMETER;
3065 }
3066
3067 /* set the helper pointer and return. */
3068 *ppPciRawHlpR3 = &g_pdmR3DevPciRawHlp;
3069 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3070 return VINF_SUCCESS;
3071}
3072
3073
3074/** @interface_method_impl{PDMDEVHLPR3,pfnDMACRegister} */
3075static DECLCALLBACK(int) pdmR3DevHlp_DMACRegister(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp)
3076{
3077 PDMDEV_ASSERT_DEVINS(pDevIns);
3078 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3079 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",
3080 pDevIns->pReg->szName, pDevIns->iInstance, pDmacReg, pDmacReg->u32Version, pDmacReg->pfnRun, pDmacReg->pfnRegister,
3081 pDmacReg->pfnReadMemory, pDmacReg->pfnWriteMemory, pDmacReg->pfnSetDREQ, pDmacReg->pfnGetChannelMode, ppDmacHlp));
3082
3083 /*
3084 * Validate input.
3085 */
3086 if (pDmacReg->u32Version != PDM_DMACREG_VERSION)
3087 {
3088 AssertMsgFailed(("u32Version=%#x expected %#x\n", pDmacReg->u32Version,
3089 PDM_DMACREG_VERSION));
3090 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (version)\n",
3091 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3092 return VERR_INVALID_PARAMETER;
3093 }
3094 if ( !pDmacReg->pfnRun
3095 || !pDmacReg->pfnRegister
3096 || !pDmacReg->pfnReadMemory
3097 || !pDmacReg->pfnWriteMemory
3098 || !pDmacReg->pfnSetDREQ
3099 || !pDmacReg->pfnGetChannelMode)
3100 {
3101 Assert(pDmacReg->pfnRun);
3102 Assert(pDmacReg->pfnRegister);
3103 Assert(pDmacReg->pfnReadMemory);
3104 Assert(pDmacReg->pfnWriteMemory);
3105 Assert(pDmacReg->pfnSetDREQ);
3106 Assert(pDmacReg->pfnGetChannelMode);
3107 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (callbacks)\n",
3108 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3109 return VERR_INVALID_PARAMETER;
3110 }
3111
3112 if (!ppDmacHlp)
3113 {
3114 Assert(ppDmacHlp);
3115 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (ppDmacHlp)\n",
3116 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3117 return VERR_INVALID_PARAMETER;
3118 }
3119
3120 /*
3121 * Only one DMA device.
3122 */
3123 PVM pVM = pDevIns->Internal.s.pVMR3;
3124 if (pVM->pdm.s.pDmac)
3125 {
3126 AssertMsgFailed(("Only one DMA device is supported!\n"));
3127 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n",
3128 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3129 return VERR_INVALID_PARAMETER;
3130 }
3131
3132 /*
3133 * Allocate and initialize pci bus structure.
3134 */
3135 int rc = VINF_SUCCESS;
3136 PPDMDMAC pDmac = (PPDMDMAC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pDmac));
3137 if (pDmac)
3138 {
3139 pDmac->pDevIns = pDevIns;
3140 pDmac->Reg = *pDmacReg;
3141 pVM->pdm.s.pDmac = pDmac;
3142
3143 /* set the helper pointer. */
3144 *ppDmacHlp = &g_pdmR3DevDmacHlp;
3145 Log(("PDM: Registered DMAC device '%s'/%d pDevIns=%p\n",
3146 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3147 }
3148 else
3149 rc = VERR_NO_MEMORY;
3150
3151 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n",
3152 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3153 return rc;
3154}
3155
3156
3157/**
3158 * @copydoc PDMDEVHLPR3::pfnRegisterVMMDevHeap
3159 */
3160static DECLCALLBACK(int) pdmR3DevHlp_RegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize)
3161{
3162 PDMDEV_ASSERT_DEVINS(pDevIns);
3163 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3164
3165 int rc = PDMR3VmmDevHeapRegister(pDevIns->Internal.s.pVMR3, GCPhys, pvHeap, cbSize);
3166 return rc;
3167}
3168
3169
3170/**
3171 * @copydoc PDMDEVHLPR3::pfnUnregisterVMMDevHeap
3172 */
3173static DECLCALLBACK(int) pdmR3DevHlp_UnregisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys)
3174{
3175 PDMDEV_ASSERT_DEVINS(pDevIns);
3176 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3177
3178 int rc = PDMR3VmmDevHeapUnregister(pDevIns->Internal.s.pVMR3, GCPhys);
3179 return rc;
3180}
3181
3182
3183/** @interface_method_impl{PDMDEVHLPR3,pfnVMReset} */
3184static DECLCALLBACK(int) pdmR3DevHlp_VMReset(PPDMDEVINS pDevIns)
3185{
3186 PDMDEV_ASSERT_DEVINS(pDevIns);
3187 PVM pVM = pDevIns->Internal.s.pVMR3;
3188 VM_ASSERT_EMT(pVM);
3189 LogFlow(("pdmR3DevHlp_VMReset: caller='%s'/%d: VM_FF_RESET %d -> 1\n",
3190 pDevIns->pReg->szName, pDevIns->iInstance, VM_FF_ISSET(pVM, VM_FF_RESET)));
3191
3192 /*
3193 * We postpone this operation because we're likely to be inside a I/O instruction
3194 * and the EIP will be updated when we return.
3195 * We still return VINF_EM_RESET to break out of any execution loops and force FF evaluation.
3196 */
3197 bool fHaltOnReset;
3198 int rc = CFGMR3QueryBool(CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM"), "HaltOnReset", &fHaltOnReset);
3199 if (RT_SUCCESS(rc) && fHaltOnReset)
3200 {
3201 Log(("pdmR3DevHlp_VMReset: Halt On Reset!\n"));
3202 rc = VINF_EM_HALT;
3203 }
3204 else
3205 {
3206 VM_FF_SET(pVM, VM_FF_RESET);
3207 rc = VINF_EM_RESET;
3208 }
3209
3210 LogFlow(("pdmR3DevHlp_VMReset: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3211 return rc;
3212}
3213
3214
3215/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspend} */
3216static DECLCALLBACK(int) pdmR3DevHlp_VMSuspend(PPDMDEVINS pDevIns)
3217{
3218 int rc;
3219 PDMDEV_ASSERT_DEVINS(pDevIns);
3220 PVM pVM = pDevIns->Internal.s.pVMR3;
3221 VM_ASSERT_EMT(pVM);
3222 LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d:\n",
3223 pDevIns->pReg->szName, pDevIns->iInstance));
3224
3225 /** @todo Always take the SMP path - fewer code paths. */
3226 if (pVM->cCpus > 1)
3227 {
3228 /* We own the IOM lock here and could cause a deadlock by waiting for a VCPU that is blocking on the IOM lock. */
3229 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3Suspend, 1, pVM->pUVM);
3230 AssertRC(rc);
3231 rc = VINF_EM_SUSPEND;
3232 }
3233 else
3234 rc = VMR3Suspend(pVM->pUVM);
3235
3236 LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3237 return rc;
3238}
3239
3240
3241/**
3242 * Worker for pdmR3DevHlp_VMSuspendSaveAndPowerOff that is invoked via a queued
3243 * EMT request to avoid deadlocks.
3244 *
3245 * @returns VBox status code fit for scheduling.
3246 * @param pVM Pointer to the VM.
3247 * @param pDevIns The device that triggered this action.
3248 */
3249static DECLCALLBACK(int) pdmR3DevHlp_VMSuspendSaveAndPowerOffWorker(PVM pVM, PPDMDEVINS pDevIns)
3250{
3251 /*
3252 * Suspend the VM first then do the saving.
3253 */
3254 int rc = VMR3Suspend(pVM->pUVM);
3255 if (RT_SUCCESS(rc))
3256 {
3257 PUVM pUVM = pVM->pUVM;
3258 rc = pUVM->pVmm2UserMethods->pfnSaveState(pVM->pUVM->pVmm2UserMethods, pUVM);
3259
3260 /*
3261 * On success, power off the VM, on failure we'll leave it suspended.
3262 */
3263 if (RT_SUCCESS(rc))
3264 {
3265 rc = VMR3PowerOff(pVM->pUVM);
3266 if (RT_FAILURE(rc))
3267 LogRel(("%s/SSP: VMR3PowerOff failed: %Rrc\n", pDevIns->pReg->szName, rc));
3268 }
3269 else
3270 LogRel(("%s/SSP: pfnSaveState failed: %Rrc\n", pDevIns->pReg->szName, rc));
3271 }
3272 else
3273 LogRel(("%s/SSP: Suspend failed: %Rrc\n", pDevIns->pReg->szName, rc));
3274 return rc;
3275}
3276
3277
3278/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
3279static DECLCALLBACK(int) pdmR3DevHlp_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
3280{
3281 PDMDEV_ASSERT_DEVINS(pDevIns);
3282 PVM pVM = pDevIns->Internal.s.pVMR3;
3283 VM_ASSERT_EMT(pVM);
3284 LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d:\n",
3285 pDevIns->pReg->szName, pDevIns->iInstance));
3286
3287 int rc;
3288 if ( pVM->pUVM->pVmm2UserMethods
3289 && pVM->pUVM->pVmm2UserMethods->pfnSaveState)
3290 {
3291 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)pdmR3DevHlp_VMSuspendSaveAndPowerOffWorker, 2, pVM, pDevIns);
3292 if (RT_SUCCESS(rc))
3293 {
3294 LogRel(("%s: Suspending, Saving and Powering Off the VM\n", pDevIns->pReg->szName));
3295 rc = VINF_EM_SUSPEND;
3296 }
3297 }
3298 else
3299 rc = VERR_NOT_SUPPORTED;
3300
3301 LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3302 return rc;
3303}
3304
3305
3306/** @interface_method_impl{PDMDEVHLPR3,pfnVMPowerOff} */
3307static DECLCALLBACK(int) pdmR3DevHlp_VMPowerOff(PPDMDEVINS pDevIns)
3308{
3309 int rc;
3310 PDMDEV_ASSERT_DEVINS(pDevIns);
3311 PVM pVM = pDevIns->Internal.s.pVMR3;
3312 VM_ASSERT_EMT(pVM);
3313 LogFlow(("pdmR3DevHlp_VMPowerOff: caller='%s'/%d:\n",
3314 pDevIns->pReg->szName, pDevIns->iInstance));
3315
3316 /** @todo Always take the SMP path - fewer code paths. */
3317 if (pVM->cCpus > 1)
3318 {
3319 /* We own the IOM lock here and could cause a deadlock by waiting for a VCPU that is blocking on the IOM lock. */
3320 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3PowerOff, 1, pVM->pUVM);
3321 AssertRC(rc);
3322 /* Set the VCPU state to stopped here as well to make sure no
3323 * inconsistency with the EM state occurs.
3324 */
3325 VMCPU_SET_STATE(VMMGetCpu(pVM), VMCPUSTATE_STOPPED);
3326 rc = VINF_EM_OFF;
3327 }
3328 else
3329 rc = VMR3PowerOff(pVM->pUVM);
3330
3331 LogFlow(("pdmR3DevHlp_VMPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3332 return rc;
3333}
3334
3335
3336/** @interface_method_impl{PDMDEVHLPR3,pfnA20IsEnabled} */
3337static DECLCALLBACK(bool) pdmR3DevHlp_A20IsEnabled(PPDMDEVINS pDevIns)
3338{
3339 PDMDEV_ASSERT_DEVINS(pDevIns);
3340 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3341
3342 bool fRc = PGMPhysIsA20Enabled(VMMGetCpu(pDevIns->Internal.s.pVMR3));
3343
3344 LogFlow(("pdmR3DevHlp_A20IsEnabled: caller='%s'/%d: returns %d\n", pDevIns->pReg->szName, pDevIns->iInstance, fRc));
3345 return fRc;
3346}
3347
3348
3349/** @interface_method_impl{PDMDEVHLPR3,pfnA20Set} */
3350static DECLCALLBACK(void) pdmR3DevHlp_A20Set(PPDMDEVINS pDevIns, bool fEnable)
3351{
3352 PDMDEV_ASSERT_DEVINS(pDevIns);
3353 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3354 LogFlow(("pdmR3DevHlp_A20Set: caller='%s'/%d: fEnable=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, fEnable));
3355 PGMR3PhysSetA20(VMMGetCpu(pDevIns->Internal.s.pVMR3), fEnable);
3356}
3357
3358
3359/** @interface_method_impl{PDMDEVHLPR3,pfnGetCpuId} */
3360static DECLCALLBACK(void) pdmR3DevHlp_GetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf,
3361 uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
3362{
3363 PDMDEV_ASSERT_DEVINS(pDevIns);
3364 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3365
3366 LogFlow(("pdmR3DevHlp_GetCpuId: caller='%s'/%d: iLeaf=%d pEax=%p pEbx=%p pEcx=%p pEdx=%p\n",
3367 pDevIns->pReg->szName, pDevIns->iInstance, iLeaf, pEax, pEbx, pEcx, pEdx));
3368 AssertPtr(pEax); AssertPtr(pEbx); AssertPtr(pEcx); AssertPtr(pEdx);
3369
3370 CPUMGetGuestCpuId(VMMGetCpu(pDevIns->Internal.s.pVMR3), iLeaf, pEax, pEbx, pEcx, pEdx);
3371
3372 LogFlow(("pdmR3DevHlp_GetCpuId: caller='%s'/%d: returns void - *pEax=%#x *pEbx=%#x *pEcx=%#x *pEdx=%#x\n",
3373 pDevIns->pReg->szName, pDevIns->iInstance, *pEax, *pEbx, *pEcx, *pEdx));
3374}
3375
3376
3377/**
3378 * The device helper structure for trusted devices.
3379 */
3380const PDMDEVHLPR3 g_pdmR3DevHlpTrusted =
3381{
3382 PDM_DEVHLPR3_VERSION,
3383 pdmR3DevHlp_IOPortRegister,
3384 pdmR3DevHlp_IOPortRegisterRC,
3385 pdmR3DevHlp_IOPortRegisterR0,
3386 pdmR3DevHlp_IOPortDeregister,
3387 pdmR3DevHlp_MMIORegister,
3388 pdmR3DevHlp_MMIORegisterRC,
3389 pdmR3DevHlp_MMIORegisterR0,
3390 pdmR3DevHlp_MMIODeregister,
3391 pdmR3DevHlp_MMIO2Register,
3392 pdmR3DevHlp_MMIO2Deregister,
3393 pdmR3DevHlp_MMIO2Map,
3394 pdmR3DevHlp_MMIO2Unmap,
3395 pdmR3DevHlp_MMHyperMapMMIO2,
3396 pdmR3DevHlp_MMIO2MapKernel,
3397 pdmR3DevHlp_ROMRegister,
3398 pdmR3DevHlp_ROMProtectShadow,
3399 pdmR3DevHlp_SSMRegister,
3400 pdmR3DevHlp_TMTimerCreate,
3401 pdmR3DevHlp_TMUtcNow,
3402 pdmR3DevHlp_PhysRead,
3403 pdmR3DevHlp_PhysWrite,
3404 pdmR3DevHlp_PhysGCPhys2CCPtr,
3405 pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
3406 pdmR3DevHlp_PhysReleasePageMappingLock,
3407 pdmR3DevHlp_PhysReadGCVirt,
3408 pdmR3DevHlp_PhysWriteGCVirt,
3409 pdmR3DevHlp_PhysGCPtr2GCPhys,
3410 pdmR3DevHlp_MMHeapAlloc,
3411 pdmR3DevHlp_MMHeapAllocZ,
3412 pdmR3DevHlp_MMHeapFree,
3413 pdmR3DevHlp_VMState,
3414 pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet,
3415 pdmR3DevHlp_VMSetError,
3416 pdmR3DevHlp_VMSetErrorV,
3417 pdmR3DevHlp_VMSetRuntimeError,
3418 pdmR3DevHlp_VMSetRuntimeErrorV,
3419 pdmR3DevHlp_DBGFStopV,
3420 pdmR3DevHlp_DBGFInfoRegister,
3421 pdmR3DevHlp_DBGFRegRegister,
3422 pdmR3DevHlp_DBGFTraceBuf,
3423 pdmR3DevHlp_STAMRegister,
3424 pdmR3DevHlp_STAMRegisterF,
3425 pdmR3DevHlp_STAMRegisterV,
3426 pdmR3DevHlp_PCIRegister,
3427 pdmR3DevHlp_PCIRegisterMsi,
3428 pdmR3DevHlp_PCIIORegionRegister,
3429 pdmR3DevHlp_PCISetConfigCallbacks,
3430 pdmR3DevHlp_PCIPhysRead,
3431 pdmR3DevHlp_PCIPhysWrite,
3432 pdmR3DevHlp_PCISetIrq,
3433 pdmR3DevHlp_PCISetIrqNoWait,
3434 pdmR3DevHlp_ISASetIrq,
3435 pdmR3DevHlp_ISASetIrqNoWait,
3436 pdmR3DevHlp_DriverAttach,
3437 pdmR3DevHlp_QueueCreate,
3438 pdmR3DevHlp_CritSectInit,
3439 pdmR3DevHlp_CritSectGetNop,
3440 pdmR3DevHlp_CritSectGetNopR0,
3441 pdmR3DevHlp_CritSectGetNopRC,
3442 pdmR3DevHlp_SetDeviceCritSect,
3443 pdmR3DevHlp_ThreadCreate,
3444 pdmR3DevHlp_SetAsyncNotification,
3445 pdmR3DevHlp_AsyncNotificationCompleted,
3446 pdmR3DevHlp_RTCRegister,
3447 pdmR3DevHlp_PCIBusRegister,
3448 pdmR3DevHlp_PICRegister,
3449 pdmR3DevHlp_APICRegister,
3450 pdmR3DevHlp_IOAPICRegister,
3451 pdmR3DevHlp_HPETRegister,
3452 pdmR3DevHlp_PciRawRegister,
3453 pdmR3DevHlp_DMACRegister,
3454 pdmR3DevHlp_DMARegister,
3455 pdmR3DevHlp_DMAReadMemory,
3456 pdmR3DevHlp_DMAWriteMemory,
3457 pdmR3DevHlp_DMASetDREQ,
3458 pdmR3DevHlp_DMAGetChannelMode,
3459 pdmR3DevHlp_DMASchedule,
3460 pdmR3DevHlp_CMOSWrite,
3461 pdmR3DevHlp_CMOSRead,
3462 pdmR3DevHlp_AssertEMT,
3463 pdmR3DevHlp_AssertOther,
3464 pdmR3DevHlp_LdrGetRCInterfaceSymbols,
3465 pdmR3DevHlp_LdrGetR0InterfaceSymbols,
3466 pdmR3DevHlp_CallR0,
3467 0,
3468 0,
3469 0,
3470 0,
3471 0,
3472 0,
3473 0,
3474 0,
3475 0,
3476 pdmR3DevHlp_GetUVM,
3477 pdmR3DevHlp_GetVM,
3478 pdmR3DevHlp_GetVMCPU,
3479 pdmR3DevHlp_RegisterVMMDevHeap,
3480 pdmR3DevHlp_UnregisterVMMDevHeap,
3481 pdmR3DevHlp_VMReset,
3482 pdmR3DevHlp_VMSuspend,
3483 pdmR3DevHlp_VMSuspendSaveAndPowerOff,
3484 pdmR3DevHlp_VMPowerOff,
3485 pdmR3DevHlp_A20IsEnabled,
3486 pdmR3DevHlp_A20Set,
3487 pdmR3DevHlp_GetCpuId,
3488 pdmR3DevHlp_TMTimeVirtGet,
3489 pdmR3DevHlp_TMTimeVirtGetFreq,
3490 pdmR3DevHlp_TMTimeVirtGetNano,
3491 PDM_DEVHLPR3_VERSION /* the end */
3492};
3493
3494
3495
3496
3497/** @interface_method_impl{PDMDEVHLPR3,pfnGetUVM} */
3498static DECLCALLBACK(PUVM) pdmR3DevHlp_Untrusted_GetUVM(PPDMDEVINS pDevIns)
3499{
3500 PDMDEV_ASSERT_DEVINS(pDevIns);
3501 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3502 return NULL;
3503}
3504
3505
3506/** @interface_method_impl{PDMDEVHLPR3,pfnGetVM} */
3507static DECLCALLBACK(PVM) pdmR3DevHlp_Untrusted_GetVM(PPDMDEVINS pDevIns)
3508{
3509 PDMDEV_ASSERT_DEVINS(pDevIns);
3510 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3511 return NULL;
3512}
3513
3514
3515/** @interface_method_impl{PDMDEVHLPR3,pfnGetVMCPU} */
3516static DECLCALLBACK(PVMCPU) pdmR3DevHlp_Untrusted_GetVMCPU(PPDMDEVINS pDevIns)
3517{
3518 PDMDEV_ASSERT_DEVINS(pDevIns);
3519 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3520 return NULL;
3521}
3522
3523
3524/** @interface_method_impl{PDMDEVHLPR3,pfnRegisterVMMDevHeap} */
3525static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_RegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize)
3526{
3527 PDMDEV_ASSERT_DEVINS(pDevIns);
3528 NOREF(GCPhys); NOREF(pvHeap); NOREF(cbSize);
3529 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3530 return VERR_ACCESS_DENIED;
3531}
3532
3533
3534/** @interface_method_impl{PDMDEVHLPR3,pfnUnregisterVMMDevHeap} */
3535static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_UnregisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys)
3536{
3537 PDMDEV_ASSERT_DEVINS(pDevIns);
3538 NOREF(GCPhys);
3539 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3540 return VERR_ACCESS_DENIED;
3541}
3542
3543
3544/** @interface_method_impl{PDMDEVHLPR3,pfnVMReset} */
3545static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMReset(PPDMDEVINS pDevIns)
3546{
3547 PDMDEV_ASSERT_DEVINS(pDevIns);
3548 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3549 return VERR_ACCESS_DENIED;
3550}
3551
3552
3553/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspend} */
3554static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspend(PPDMDEVINS pDevIns)
3555{
3556 PDMDEV_ASSERT_DEVINS(pDevIns);
3557 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3558 return VERR_ACCESS_DENIED;
3559}
3560
3561
3562/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
3563static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
3564{
3565 PDMDEV_ASSERT_DEVINS(pDevIns);
3566 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3567 return VERR_ACCESS_DENIED;
3568}
3569
3570
3571/** @interface_method_impl{PDMDEVHLPR3,pfnVMPowerOff} */
3572static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMPowerOff(PPDMDEVINS pDevIns)
3573{
3574 PDMDEV_ASSERT_DEVINS(pDevIns);
3575 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3576 return VERR_ACCESS_DENIED;
3577}
3578
3579
3580/** @interface_method_impl{PDMDEVHLPR3,pfnA20IsEnabled} */
3581static DECLCALLBACK(bool) pdmR3DevHlp_Untrusted_A20IsEnabled(PPDMDEVINS pDevIns)
3582{
3583 PDMDEV_ASSERT_DEVINS(pDevIns);
3584 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3585 return false;
3586}
3587
3588
3589/** @interface_method_impl{PDMDEVHLPR3,pfnA20Set} */
3590static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_A20Set(PPDMDEVINS pDevIns, bool fEnable)
3591{
3592 PDMDEV_ASSERT_DEVINS(pDevIns);
3593 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3594 NOREF(fEnable);
3595}
3596
3597
3598/** @interface_method_impl{PDMDEVHLPR3,pfnGetCpuId} */
3599static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_GetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf,
3600 uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
3601{
3602 PDMDEV_ASSERT_DEVINS(pDevIns);
3603 NOREF(iLeaf); NOREF(pEax); NOREF(pEbx); NOREF(pEcx); NOREF(pEdx);
3604 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3605}
3606
3607
3608/**
3609 * The device helper structure for non-trusted devices.
3610 */
3611const PDMDEVHLPR3 g_pdmR3DevHlpUnTrusted =
3612{
3613 PDM_DEVHLPR3_VERSION,
3614 pdmR3DevHlp_IOPortRegister,
3615 pdmR3DevHlp_IOPortRegisterRC,
3616 pdmR3DevHlp_IOPortRegisterR0,
3617 pdmR3DevHlp_IOPortDeregister,
3618 pdmR3DevHlp_MMIORegister,
3619 pdmR3DevHlp_MMIORegisterRC,
3620 pdmR3DevHlp_MMIORegisterR0,
3621 pdmR3DevHlp_MMIODeregister,
3622 pdmR3DevHlp_MMIO2Register,
3623 pdmR3DevHlp_MMIO2Deregister,
3624 pdmR3DevHlp_MMIO2Map,
3625 pdmR3DevHlp_MMIO2Unmap,
3626 pdmR3DevHlp_MMHyperMapMMIO2,
3627 pdmR3DevHlp_MMIO2MapKernel,
3628 pdmR3DevHlp_ROMRegister,
3629 pdmR3DevHlp_ROMProtectShadow,
3630 pdmR3DevHlp_SSMRegister,
3631 pdmR3DevHlp_TMTimerCreate,
3632 pdmR3DevHlp_TMUtcNow,
3633 pdmR3DevHlp_PhysRead,
3634 pdmR3DevHlp_PhysWrite,
3635 pdmR3DevHlp_PhysGCPhys2CCPtr,
3636 pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
3637 pdmR3DevHlp_PhysReleasePageMappingLock,
3638 pdmR3DevHlp_PhysReadGCVirt,
3639 pdmR3DevHlp_PhysWriteGCVirt,
3640 pdmR3DevHlp_PhysGCPtr2GCPhys,
3641 pdmR3DevHlp_MMHeapAlloc,
3642 pdmR3DevHlp_MMHeapAllocZ,
3643 pdmR3DevHlp_MMHeapFree,
3644 pdmR3DevHlp_VMState,
3645 pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet,
3646 pdmR3DevHlp_VMSetError,
3647 pdmR3DevHlp_VMSetErrorV,
3648 pdmR3DevHlp_VMSetRuntimeError,
3649 pdmR3DevHlp_VMSetRuntimeErrorV,
3650 pdmR3DevHlp_DBGFStopV,
3651 pdmR3DevHlp_DBGFInfoRegister,
3652 pdmR3DevHlp_DBGFRegRegister,
3653 pdmR3DevHlp_DBGFTraceBuf,
3654 pdmR3DevHlp_STAMRegister,
3655 pdmR3DevHlp_STAMRegisterF,
3656 pdmR3DevHlp_STAMRegisterV,
3657 pdmR3DevHlp_PCIRegister,
3658 pdmR3DevHlp_PCIRegisterMsi,
3659 pdmR3DevHlp_PCIIORegionRegister,
3660 pdmR3DevHlp_PCISetConfigCallbacks,
3661 pdmR3DevHlp_PCIPhysRead,
3662 pdmR3DevHlp_PCIPhysWrite,
3663 pdmR3DevHlp_PCISetIrq,
3664 pdmR3DevHlp_PCISetIrqNoWait,
3665 pdmR3DevHlp_ISASetIrq,
3666 pdmR3DevHlp_ISASetIrqNoWait,
3667 pdmR3DevHlp_DriverAttach,
3668 pdmR3DevHlp_QueueCreate,
3669 pdmR3DevHlp_CritSectInit,
3670 pdmR3DevHlp_CritSectGetNop,
3671 pdmR3DevHlp_CritSectGetNopR0,
3672 pdmR3DevHlp_CritSectGetNopRC,
3673 pdmR3DevHlp_SetDeviceCritSect,
3674 pdmR3DevHlp_ThreadCreate,
3675 pdmR3DevHlp_SetAsyncNotification,
3676 pdmR3DevHlp_AsyncNotificationCompleted,
3677 pdmR3DevHlp_RTCRegister,
3678 pdmR3DevHlp_PCIBusRegister,
3679 pdmR3DevHlp_PICRegister,
3680 pdmR3DevHlp_APICRegister,
3681 pdmR3DevHlp_IOAPICRegister,
3682 pdmR3DevHlp_HPETRegister,
3683 pdmR3DevHlp_PciRawRegister,
3684 pdmR3DevHlp_DMACRegister,
3685 pdmR3DevHlp_DMARegister,
3686 pdmR3DevHlp_DMAReadMemory,
3687 pdmR3DevHlp_DMAWriteMemory,
3688 pdmR3DevHlp_DMASetDREQ,
3689 pdmR3DevHlp_DMAGetChannelMode,
3690 pdmR3DevHlp_DMASchedule,
3691 pdmR3DevHlp_CMOSWrite,
3692 pdmR3DevHlp_CMOSRead,
3693 pdmR3DevHlp_AssertEMT,
3694 pdmR3DevHlp_AssertOther,
3695 pdmR3DevHlp_LdrGetRCInterfaceSymbols,
3696 pdmR3DevHlp_LdrGetR0InterfaceSymbols,
3697 pdmR3DevHlp_CallR0,
3698 0,
3699 0,
3700 0,
3701 0,
3702 0,
3703 0,
3704 0,
3705 0,
3706 0,
3707 pdmR3DevHlp_Untrusted_GetUVM,
3708 pdmR3DevHlp_Untrusted_GetVM,
3709 pdmR3DevHlp_Untrusted_GetVMCPU,
3710 pdmR3DevHlp_Untrusted_RegisterVMMDevHeap,
3711 pdmR3DevHlp_Untrusted_UnregisterVMMDevHeap,
3712 pdmR3DevHlp_Untrusted_VMReset,
3713 pdmR3DevHlp_Untrusted_VMSuspend,
3714 pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff,
3715 pdmR3DevHlp_Untrusted_VMPowerOff,
3716 pdmR3DevHlp_Untrusted_A20IsEnabled,
3717 pdmR3DevHlp_Untrusted_A20Set,
3718 pdmR3DevHlp_Untrusted_GetCpuId,
3719 pdmR3DevHlp_TMTimeVirtGet,
3720 pdmR3DevHlp_TMTimeVirtGetFreq,
3721 pdmR3DevHlp_TMTimeVirtGetNano,
3722 PDM_DEVHLPR3_VERSION /* the end */
3723};
3724
3725
3726
3727/**
3728 * Queue consumer callback for internal component.
3729 *
3730 * @returns Success indicator.
3731 * If false the item will not be removed and the flushing will stop.
3732 * @param pVM Pointer to the VM.
3733 * @param pItem The item to consume. Upon return this item will be freed.
3734 */
3735DECLCALLBACK(bool) pdmR3DevHlpQueueConsumer(PVM pVM, PPDMQUEUEITEMCORE pItem)
3736{
3737 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)pItem;
3738 LogFlow(("pdmR3DevHlpQueueConsumer: enmOp=%d pDevIns=%p\n", pTask->enmOp, pTask->pDevInsR3));
3739 switch (pTask->enmOp)
3740 {
3741 case PDMDEVHLPTASKOP_ISA_SET_IRQ:
3742 PDMIsaSetIrq(pVM, pTask->u.SetIRQ.iIrq, pTask->u.SetIRQ.iLevel, pTask->u.SetIRQ.uTagSrc);
3743 break;
3744
3745 case PDMDEVHLPTASKOP_PCI_SET_IRQ:
3746 {
3747 /* Same as pdmR3DevHlp_PCISetIrq, except we've got a tag already. */
3748 PPDMDEVINS pDevIns = pTask->pDevInsR3;
3749 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
3750 if (pPciDev)
3751 {
3752 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3; /** @todo the bus should be associated with the PCI device not the PDM device. */
3753 Assert(pBus);
3754
3755 pdmLock(pVM);
3756 pBus->pfnSetIrqR3(pBus->pDevInsR3, pPciDev, pTask->u.SetIRQ.iIrq,
3757 pTask->u.SetIRQ.iLevel, pTask->u.SetIRQ.uTagSrc);
3758 pdmUnlock(pVM);
3759 }
3760 else
3761 AssertReleaseMsgFailed(("No PCI device registered!\n"));
3762 break;
3763 }
3764
3765 case PDMDEVHLPTASKOP_IOAPIC_SET_IRQ:
3766 PDMIoApicSetIrq(pVM, pTask->u.SetIRQ.iIrq, pTask->u.SetIRQ.iLevel, pTask->u.SetIRQ.uTagSrc);
3767 break;
3768
3769 default:
3770 AssertReleaseMsgFailed(("Invalid operation %d\n", pTask->enmOp));
3771 break;
3772 }
3773 return true;
3774}
3775
3776/** @} */
3777
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