VirtualBox

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

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

PDM,++: Change APIs used by Main from PVM to PUVM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 148.1 KB
Line 
1/* $Id: PDMDevHlp.cpp 44351 2013-01-24 12:04:39Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, Device Helpers.
4 */
5
6/*
7 * Copyright (C) 2006-2011 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,pfnDBGFTraceBuf} */
1013static DECLCALLBACK(RTTRACEBUF) pdmR3DevHlp_DBGFTraceBuf(PPDMDEVINS pDevIns)
1014{
1015 PDMDEV_ASSERT_DEVINS(pDevIns);
1016 RTTRACEBUF hTraceBuf = pDevIns->Internal.s.pVMR3->hTraceBufR3;
1017 LogFlow(("pdmR3DevHlp_DBGFTraceBuf: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, hTraceBuf));
1018 return hTraceBuf;
1019}
1020
1021
1022/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegister} */
1023static DECLCALLBACK(void) pdmR3DevHlp_STAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
1024{
1025 PDMDEV_ASSERT_DEVINS(pDevIns);
1026 PVM pVM = pDevIns->Internal.s.pVMR3;
1027 VM_ASSERT_EMT(pVM);
1028
1029 STAM_REG(pVM, pvSample, enmType, pszName, enmUnit, pszDesc);
1030 NOREF(pVM);
1031}
1032
1033
1034
1035/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegisterF} */
1036static DECLCALLBACK(void) pdmR3DevHlp_STAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1037 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
1038{
1039 PDMDEV_ASSERT_DEVINS(pDevIns);
1040 PVM pVM = pDevIns->Internal.s.pVMR3;
1041 VM_ASSERT_EMT(pVM);
1042
1043 va_list args;
1044 va_start(args, pszName);
1045 int rc = STAMR3RegisterV(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1046 va_end(args);
1047 AssertRC(rc);
1048
1049 NOREF(pVM);
1050}
1051
1052
1053/** @interface_method_impl{PDMDEVHLPR3,pfnSTAMRegisterV} */
1054static DECLCALLBACK(void) pdmR3DevHlp_STAMRegisterV(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1055 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
1056{
1057 PDMDEV_ASSERT_DEVINS(pDevIns);
1058 PVM pVM = pDevIns->Internal.s.pVMR3;
1059 VM_ASSERT_EMT(pVM);
1060
1061 int rc = STAMR3RegisterV(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1062 AssertRC(rc);
1063
1064 NOREF(pVM);
1065}
1066
1067
1068/** @interface_method_impl{PDMDEVHLPR3,pfnPCIDevPhysRead} */
1069static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
1070{
1071 PDMDEV_ASSERT_DEVINS(pDevIns);
1072 return PDMDevHlpPCIDevPhysRead(pDevIns->Internal.s.pPciDeviceR3, GCPhys, pvBuf, cbRead);
1073}
1074
1075
1076/** @interface_method_impl{PDMDEVHLPR3,pfnPCIDevPhysWrite} */
1077static DECLCALLBACK(int) pdmR3DevHlp_PCIPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
1078{
1079 PDMDEV_ASSERT_DEVINS(pDevIns);
1080 return PDMDevHlpPCIDevPhysWrite(pDevIns->Internal.s.pPciDeviceR3, GCPhys, pvBuf, cbWrite);
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,pfnPCISetIrq} */
1355static DECLCALLBACK(void) pdmR3DevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1356{
1357 PDMDEV_ASSERT_DEVINS(pDevIns);
1358 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: iIrq=%d iLevel=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, iIrq, iLevel));
1359
1360 /*
1361 * Validate input.
1362 */
1363 Assert(iIrq == 0);
1364 Assert((uint32_t)iLevel <= PDM_IRQ_LEVEL_FLIP_FLOP);
1365
1366 /*
1367 * Must have a PCI device registered!
1368 */
1369 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1370 if (pPciDev)
1371 {
1372 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3; /** @todo the bus should be associated with the PCI device not the PDM device. */
1373 Assert(pBus);
1374 PVM pVM = pDevIns->Internal.s.pVMR3;
1375
1376 pdmLock(pVM);
1377 uint32_t uTagSrc;
1378 if (iLevel & PDM_IRQ_LEVEL_HIGH)
1379 {
1380 pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
1381 if (iLevel == PDM_IRQ_LEVEL_HIGH)
1382 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1383 else
1384 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1385 }
1386 else
1387 uTagSrc = pDevIns->Internal.s.uLastIrqTag;
1388
1389 pBus->pfnSetIrqR3(pBus->pDevInsR3, pPciDev, iIrq, iLevel, uTagSrc);
1390
1391 if (iLevel == PDM_IRQ_LEVEL_LOW)
1392 VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1393 pdmUnlock(pVM);
1394 }
1395 else
1396 AssertReleaseMsgFailed(("No PCI device registered!\n"));
1397
1398 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1399}
1400
1401
1402/** @interface_method_impl{PDMDEVHLPR3,pfnPCISetIrqNoWait} */
1403static DECLCALLBACK(void) pdmR3DevHlp_PCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1404{
1405 pdmR3DevHlp_PCISetIrq(pDevIns, iIrq, iLevel);
1406}
1407
1408
1409/** @interface_method_impl{PDMDEVHLPR3,pfnPCIRegisterMsi} */
1410static DECLCALLBACK(int) pdmR3DevHlp_PCIRegisterMsi(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg)
1411{
1412 PDMDEV_ASSERT_DEVINS(pDevIns);
1413 LogFlow(("pdmR3DevHlp_PCIRegisterMsi: caller='%s'/%d: %d MSI vectors %d MSI-X vectors\n", pDevIns->pReg->szName, pDevIns->iInstance, pMsiReg->cMsiVectors,pMsiReg->cMsixVectors ));
1414 int rc = VINF_SUCCESS;
1415
1416 /*
1417 * Must have a PCI device registered!
1418 */
1419 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
1420 if (pPciDev)
1421 {
1422 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3; /** @todo the bus should be associated with the PCI device not the PDM device. */
1423 Assert(pBus);
1424
1425 PVM pVM = pDevIns->Internal.s.pVMR3;
1426 pdmLock(pVM);
1427 if (!pBus->pfnRegisterMsiR3)
1428 rc = VERR_NOT_IMPLEMENTED;
1429 else
1430 rc = pBus->pfnRegisterMsiR3(pBus->pDevInsR3, pPciDev, pMsiReg);
1431 pdmUnlock(pVM);
1432 }
1433 else
1434 AssertReleaseMsgFailed(("No PCI device registered!\n"));
1435
1436 LogFlow(("pdmR3DevHlp_PCISetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1437 return rc;
1438}
1439
1440/** @interface_method_impl{PDMDEVHLPR3,pfnISASetIrq} */
1441static DECLCALLBACK(void) pdmR3DevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1442{
1443 PDMDEV_ASSERT_DEVINS(pDevIns);
1444 LogFlow(("pdmR3DevHlp_ISASetIrq: caller='%s'/%d: iIrq=%d iLevel=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, iIrq, iLevel));
1445
1446 /*
1447 * Validate input.
1448 */
1449 Assert(iIrq < 16);
1450 Assert((uint32_t)iLevel <= PDM_IRQ_LEVEL_FLIP_FLOP);
1451
1452 PVM pVM = pDevIns->Internal.s.pVMR3;
1453
1454 /*
1455 * Do the job.
1456 */
1457 pdmLock(pVM);
1458 uint32_t uTagSrc;
1459 if (iLevel & PDM_IRQ_LEVEL_HIGH)
1460 {
1461 pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
1462 if (iLevel == PDM_IRQ_LEVEL_HIGH)
1463 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1464 else
1465 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1466 }
1467 else
1468 uTagSrc = pDevIns->Internal.s.uLastIrqTag;
1469
1470 PDMIsaSetIrq(pVM, iIrq, iLevel, uTagSrc); /* (The API takes the lock recursively.) */
1471
1472 if (iLevel == PDM_IRQ_LEVEL_LOW)
1473 VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
1474 pdmUnlock(pVM);
1475
1476 LogFlow(("pdmR3DevHlp_ISASetIrq: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance));
1477}
1478
1479
1480/** @interface_method_impl{PDMDEVHLPR3,pfnISASetIrqNoWait} */
1481static DECLCALLBACK(void) pdmR3DevHlp_ISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
1482{
1483 pdmR3DevHlp_ISASetIrq(pDevIns, iIrq, iLevel);
1484}
1485
1486
1487/** @interface_method_impl{PDMDEVHLPR3,pfnDriverAttach} */
1488static DECLCALLBACK(int) pdmR3DevHlp_DriverAttach(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
1489{
1490 PDMDEV_ASSERT_DEVINS(pDevIns);
1491 PVM pVM = pDevIns->Internal.s.pVMR3;
1492 VM_ASSERT_EMT(pVM);
1493 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: iLun=%d pBaseInterface=%p ppBaseInterface=%p pszDesc=%p:{%s}\n",
1494 pDevIns->pReg->szName, pDevIns->iInstance, iLun, pBaseInterface, ppBaseInterface, pszDesc, pszDesc));
1495
1496 /*
1497 * Lookup the LUN, it might already be registered.
1498 */
1499 PPDMLUN pLunPrev = NULL;
1500 PPDMLUN pLun = pDevIns->Internal.s.pLunsR3;
1501 for (; pLun; pLunPrev = pLun, pLun = pLun->pNext)
1502 if (pLun->iLun == iLun)
1503 break;
1504
1505 /*
1506 * Create the LUN if if wasn't found, else check if driver is already attached to it.
1507 */
1508 if (!pLun)
1509 {
1510 if ( !pBaseInterface
1511 || !pszDesc
1512 || !*pszDesc)
1513 {
1514 Assert(pBaseInterface);
1515 Assert(pszDesc || *pszDesc);
1516 return VERR_INVALID_PARAMETER;
1517 }
1518
1519 pLun = (PPDMLUN)MMR3HeapAlloc(pVM, MM_TAG_PDM_LUN, sizeof(*pLun));
1520 if (!pLun)
1521 return VERR_NO_MEMORY;
1522
1523 pLun->iLun = iLun;
1524 pLun->pNext = pLunPrev ? pLunPrev->pNext : NULL;
1525 pLun->pTop = NULL;
1526 pLun->pBottom = NULL;
1527 pLun->pDevIns = pDevIns;
1528 pLun->pUsbIns = NULL;
1529 pLun->pszDesc = pszDesc;
1530 pLun->pBase = pBaseInterface;
1531 if (!pLunPrev)
1532 pDevIns->Internal.s.pLunsR3 = pLun;
1533 else
1534 pLunPrev->pNext = pLun;
1535 Log(("pdmR3DevHlp_DriverAttach: Registered LUN#%d '%s' with device '%s'/%d.\n",
1536 iLun, pszDesc, pDevIns->pReg->szName, pDevIns->iInstance));
1537 }
1538 else if (pLun->pTop)
1539 {
1540 AssertMsgFailed(("Already attached! The device should keep track of such things!\n"));
1541 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_DRIVER_ALREADY_ATTACHED));
1542 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
1543 }
1544 Assert(pLun->pBase == pBaseInterface);
1545
1546
1547 /*
1548 * Get the attached driver configuration.
1549 */
1550 int rc;
1551 PCFGMNODE pNode = CFGMR3GetChildF(pDevIns->Internal.s.pCfgHandle, "LUN#%u", iLun);
1552 if (pNode)
1553 rc = pdmR3DrvInstantiate(pVM, pNode, pBaseInterface, NULL /*pDrvAbove*/, pLun, ppBaseInterface);
1554 else
1555 rc = VERR_PDM_NO_ATTACHED_DRIVER;
1556
1557
1558 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1559 return rc;
1560}
1561
1562
1563/** @interface_method_impl{PDMDEVHLPR3,pfnQueueCreate} */
1564static DECLCALLBACK(int) pdmR3DevHlp_QueueCreate(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
1565 PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, const char *pszName, PPDMQUEUE *ppQueue)
1566{
1567 PDMDEV_ASSERT_DEVINS(pDevIns);
1568 LogFlow(("pdmR3DevHlp_QueueCreate: caller='%s'/%d: cbItem=%#x cItems=%#x cMilliesInterval=%u pfnCallback=%p fGCEnabled=%RTbool pszName=%p:{%s} ppQueue=%p\n",
1569 pDevIns->pReg->szName, pDevIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, fGCEnabled, pszName, pszName, ppQueue));
1570
1571 PVM pVM = pDevIns->Internal.s.pVMR3;
1572 VM_ASSERT_EMT(pVM);
1573
1574 if (pDevIns->iInstance > 0)
1575 {
1576 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s_%u", pszName, pDevIns->iInstance);
1577 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
1578 }
1579
1580 int rc = PDMR3QueueCreateDevice(pVM, pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fGCEnabled, pszName, ppQueue);
1581
1582 LogFlow(("pdmR3DevHlp_QueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, rc, *ppQueue));
1583 return rc;
1584}
1585
1586
1587/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectInit} */
1588static DECLCALLBACK(int) pdmR3DevHlp_CritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1589 const char *pszNameFmt, va_list va)
1590{
1591 PDMDEV_ASSERT_DEVINS(pDevIns);
1592 LogFlow(("pdmR3DevHlp_CritSectInit: caller='%s'/%d: pCritSect=%p pszNameFmt=%p:{%s}\n",
1593 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect, pszNameFmt, pszNameFmt));
1594
1595 PVM pVM = pDevIns->Internal.s.pVMR3;
1596 VM_ASSERT_EMT(pVM);
1597 int rc = pdmR3CritSectInitDevice(pVM, pDevIns, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
1598
1599 LogFlow(("pdmR3DevHlp_CritSectInit: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1600 return rc;
1601}
1602
1603
1604/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNop} */
1605static DECLCALLBACK(PPDMCRITSECT) pdmR3DevHlp_CritSectGetNop(PPDMDEVINS pDevIns)
1606{
1607 PDMDEV_ASSERT_DEVINS(pDevIns);
1608 PVM pVM = pDevIns->Internal.s.pVMR3;
1609 VM_ASSERT_EMT(pVM);
1610
1611 PPDMCRITSECT pCritSect = PDMR3CritSectGetNop(pVM);
1612 LogFlow(("pdmR3DevHlp_CritSectGetNop: caller='%s'/%d: return %p\n",
1613 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
1614 return pCritSect;
1615}
1616
1617
1618/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNopR0} */
1619static DECLCALLBACK(R0PTRTYPE(PPDMCRITSECT)) pdmR3DevHlp_CritSectGetNopR0(PPDMDEVINS pDevIns)
1620{
1621 PDMDEV_ASSERT_DEVINS(pDevIns);
1622 PVM pVM = pDevIns->Internal.s.pVMR3;
1623 VM_ASSERT_EMT(pVM);
1624
1625 R0PTRTYPE(PPDMCRITSECT) pCritSect = PDMR3CritSectGetNopR0(pVM);
1626 LogFlow(("pdmR3DevHlp_CritSectGetNopR0: caller='%s'/%d: return %RHv\n",
1627 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
1628 return pCritSect;
1629}
1630
1631
1632/** @interface_method_impl{PDMDEVHLPR3,pfnCritSectGetNopRC} */
1633static DECLCALLBACK(RCPTRTYPE(PPDMCRITSECT)) pdmR3DevHlp_CritSectGetNopRC(PPDMDEVINS pDevIns)
1634{
1635 PDMDEV_ASSERT_DEVINS(pDevIns);
1636 PVM pVM = pDevIns->Internal.s.pVMR3;
1637 VM_ASSERT_EMT(pVM);
1638
1639 RCPTRTYPE(PPDMCRITSECT) pCritSect = PDMR3CritSectGetNopRC(pVM);
1640 LogFlow(("pdmR3DevHlp_CritSectGetNopRC: caller='%s'/%d: return %RRv\n",
1641 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect));
1642 return pCritSect;
1643}
1644
1645
1646/** @interface_method_impl{PDMDEVHLPR3,pfnSetDeviceCritSect} */
1647static DECLCALLBACK(int) pdmR3DevHlp_SetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
1648{
1649 /*
1650 * Validate input.
1651 *
1652 * Note! We only allow the automatically created default critical section
1653 * to be replaced by this API.
1654 */
1655 PDMDEV_ASSERT_DEVINS(pDevIns);
1656 AssertPtrReturn(pCritSect, VERR_INVALID_POINTER);
1657 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: pCritSect=%p (%s)\n",
1658 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect, pCritSect->s.pszName));
1659 AssertReturn(PDMCritSectIsInitialized(pCritSect), VERR_INVALID_PARAMETER);
1660 PVM pVM = pDevIns->Internal.s.pVMR3;
1661 AssertReturn(pCritSect->s.pVMR3 == pVM, VERR_INVALID_PARAMETER);
1662
1663 VM_ASSERT_EMT(pVM);
1664 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER);
1665
1666 AssertReturn(pDevIns->pCritSectRoR3, VERR_PDM_DEV_IPE_1);
1667 AssertReturn(pDevIns->pCritSectRoR3->s.fAutomaticDefaultCritsect, VERR_WRONG_ORDER);
1668 AssertReturn(!pDevIns->pCritSectRoR3->s.fUsedByTimerOrSimilar, VERR_WRONG_ORDER);
1669 AssertReturn(pDevIns->pCritSectRoR3 != pCritSect, VERR_INVALID_PARAMETER);
1670
1671 /*
1672 * Replace the critical section and destroy the automatic default section.
1673 */
1674 PPDMCRITSECT pOldCritSect = pDevIns->pCritSectRoR3;
1675 pDevIns->pCritSectRoR3 = pCritSect;
1676 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
1677 pDevIns->pCritSectRoR0 = MMHyperCCToR0(pVM, pDevIns->pCritSectRoR3);
1678 else
1679 Assert(pDevIns->pCritSectRoR0 == NIL_RTRCPTR);
1680
1681 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
1682 pDevIns->pCritSectRoRC = MMHyperCCToRC(pVM, pDevIns->pCritSectRoR3);
1683 else
1684 Assert(pDevIns->pCritSectRoRC == NIL_RTRCPTR);
1685
1686 PDMR3CritSectDelete(pOldCritSect);
1687 if (pDevIns->pReg->fFlags & (PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0))
1688 MMHyperFree(pVM, pOldCritSect);
1689 else
1690 MMR3HeapFree(pOldCritSect);
1691
1692 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
1693 return VINF_SUCCESS;
1694}
1695
1696
1697/** @interface_method_impl{PDMDEVHLPR3,pfnThreadCreate} */
1698static DECLCALLBACK(int) pdmR3DevHlp_ThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
1699 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1700{
1701 PDMDEV_ASSERT_DEVINS(pDevIns);
1702 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
1703 LogFlow(("pdmR3DevHlp_ThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
1704 pDevIns->pReg->szName, pDevIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
1705
1706 int rc = pdmR3ThreadCreateDevice(pDevIns->Internal.s.pVMR3, pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1707
1708 LogFlow(("pdmR3DevHlp_ThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDevIns->pReg->szName, pDevIns->iInstance,
1709 rc, *ppThread));
1710 return rc;
1711}
1712
1713
1714/** @interface_method_impl{PDMDEVHLPR3,pfnSetAsyncNotification} */
1715static DECLCALLBACK(int) pdmR3DevHlp_SetAsyncNotification(PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify)
1716{
1717 PDMDEV_ASSERT_DEVINS(pDevIns);
1718 VM_ASSERT_EMT0(pDevIns->Internal.s.pVMR3);
1719 LogFlow(("pdmR3DevHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pfnAsyncNotify));
1720
1721 int rc = VINF_SUCCESS;
1722 AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
1723 AssertStmt(!pDevIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
1724 AssertStmt(pDevIns->Internal.s.fIntFlags & (PDMDEVINSINT_FLAGS_SUSPENDED | PDMDEVINSINT_FLAGS_RESET), rc = VERR_WRONG_ORDER);
1725 VMSTATE enmVMState = VMR3GetState(pDevIns->Internal.s.pVMR3);
1726 AssertStmt( enmVMState == VMSTATE_SUSPENDING
1727 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1728 || enmVMState == VMSTATE_SUSPENDING_LS
1729 || enmVMState == VMSTATE_RESETTING
1730 || enmVMState == VMSTATE_RESETTING_LS
1731 || enmVMState == VMSTATE_POWERING_OFF
1732 || enmVMState == VMSTATE_POWERING_OFF_LS,
1733 rc = VERR_INVALID_STATE);
1734
1735 if (RT_SUCCESS(rc))
1736 pDevIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
1737
1738 LogFlow(("pdmR3DevHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
1739 return rc;
1740}
1741
1742
1743/** @interface_method_impl{PDMDEVHLPR3,pfnAsyncNotificationCompleted} */
1744static DECLCALLBACK(void) pdmR3DevHlp_AsyncNotificationCompleted(PPDMDEVINS pDevIns)
1745{
1746 PDMDEV_ASSERT_DEVINS(pDevIns);
1747 PVM pVM = pDevIns->Internal.s.pVMR3;
1748
1749 VMSTATE enmVMState = VMR3GetState(pVM);
1750 if ( enmVMState == VMSTATE_SUSPENDING
1751 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1752 || enmVMState == VMSTATE_SUSPENDING_LS
1753 || enmVMState == VMSTATE_RESETTING
1754 || enmVMState == VMSTATE_RESETTING_LS
1755 || enmVMState == VMSTATE_POWERING_OFF
1756 || enmVMState == VMSTATE_POWERING_OFF_LS)
1757 {
1758 LogFlow(("pdmR3DevHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
1759 VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
1760 }
1761 else
1762 LogFlow(("pdmR3DevHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, enmVMState));
1763}
1764
1765
1766/** @interface_method_impl{PDMDEVHLPR3,pfnRTCRegister} */
1767static DECLCALLBACK(int) pdmR3DevHlp_RTCRegister(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp)
1768{
1769 PDMDEV_ASSERT_DEVINS(pDevIns);
1770 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
1771 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: pRtcReg=%p:{.u32Version=%#x, .pfnWrite=%p, .pfnRead=%p} ppRtcHlp=%p\n",
1772 pDevIns->pReg->szName, pDevIns->iInstance, pRtcReg, pRtcReg->u32Version, pRtcReg->pfnWrite,
1773 pRtcReg->pfnWrite, ppRtcHlp));
1774
1775 /*
1776 * Validate input.
1777 */
1778 if (pRtcReg->u32Version != PDM_RTCREG_VERSION)
1779 {
1780 AssertMsgFailed(("u32Version=%#x expected %#x\n", pRtcReg->u32Version,
1781 PDM_RTCREG_VERSION));
1782 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (version)\n",
1783 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1784 return VERR_INVALID_PARAMETER;
1785 }
1786 if ( !pRtcReg->pfnWrite
1787 || !pRtcReg->pfnRead)
1788 {
1789 Assert(pRtcReg->pfnWrite);
1790 Assert(pRtcReg->pfnRead);
1791 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (callbacks)\n",
1792 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1793 return VERR_INVALID_PARAMETER;
1794 }
1795
1796 if (!ppRtcHlp)
1797 {
1798 Assert(ppRtcHlp);
1799 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc (ppRtcHlp)\n",
1800 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1801 return VERR_INVALID_PARAMETER;
1802 }
1803
1804 /*
1805 * Only one DMA device.
1806 */
1807 PVM pVM = pDevIns->Internal.s.pVMR3;
1808 if (pVM->pdm.s.pRtc)
1809 {
1810 AssertMsgFailed(("Only one RTC device is supported!\n"));
1811 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n",
1812 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
1813 return VERR_INVALID_PARAMETER;
1814 }
1815
1816 /*
1817 * Allocate and initialize pci bus structure.
1818 */
1819 int rc = VINF_SUCCESS;
1820 PPDMRTC pRtc = (PPDMRTC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pRtc));
1821 if (pRtc)
1822 {
1823 pRtc->pDevIns = pDevIns;
1824 pRtc->Reg = *pRtcReg;
1825 pVM->pdm.s.pRtc = pRtc;
1826
1827 /* set the helper pointer. */
1828 *ppRtcHlp = &g_pdmR3DevRtcHlp;
1829 Log(("PDM: Registered RTC device '%s'/%d pDevIns=%p\n",
1830 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
1831 }
1832 else
1833 rc = VERR_NO_MEMORY;
1834
1835 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n",
1836 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1837 return rc;
1838}
1839
1840
1841/** @interface_method_impl{PDMDEVHLPR3,pfnDMARegister} */
1842static DECLCALLBACK(int) pdmR3DevHlp_DMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
1843{
1844 PDMDEV_ASSERT_DEVINS(pDevIns);
1845 PVM pVM = pDevIns->Internal.s.pVMR3;
1846 VM_ASSERT_EMT(pVM);
1847 LogFlow(("pdmR3DevHlp_DMARegister: caller='%s'/%d: uChannel=%d pfnTransferHandler=%p pvUser=%p\n",
1848 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pfnTransferHandler, pvUser));
1849 int rc = VINF_SUCCESS;
1850 if (pVM->pdm.s.pDmac)
1851 pVM->pdm.s.pDmac->Reg.pfnRegister(pVM->pdm.s.pDmac->pDevIns, uChannel, pfnTransferHandler, pvUser);
1852 else
1853 {
1854 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1855 rc = VERR_PDM_NO_DMAC_INSTANCE;
1856 }
1857 LogFlow(("pdmR3DevHlp_DMARegister: caller='%s'/%d: returns %Rrc\n",
1858 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1859 return rc;
1860}
1861
1862
1863/** @interface_method_impl{PDMDEVHLPR3,pfnDMAReadMemory} */
1864static DECLCALLBACK(int) pdmR3DevHlp_DMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
1865{
1866 PDMDEV_ASSERT_DEVINS(pDevIns);
1867 PVM pVM = pDevIns->Internal.s.pVMR3;
1868 VM_ASSERT_EMT(pVM);
1869 LogFlow(("pdmR3DevHlp_DMAReadMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbRead=%p\n",
1870 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbRead));
1871 int rc = VINF_SUCCESS;
1872 if (pVM->pdm.s.pDmac)
1873 {
1874 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnReadMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock);
1875 if (pcbRead)
1876 *pcbRead = cb;
1877 }
1878 else
1879 {
1880 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1881 rc = VERR_PDM_NO_DMAC_INSTANCE;
1882 }
1883 LogFlow(("pdmR3DevHlp_DMAReadMemory: caller='%s'/%d: returns %Rrc\n",
1884 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1885 return rc;
1886}
1887
1888
1889/** @interface_method_impl{PDMDEVHLPR3,pfnDMAWriteMemory} */
1890static DECLCALLBACK(int) pdmR3DevHlp_DMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
1891{
1892 PDMDEV_ASSERT_DEVINS(pDevIns);
1893 PVM pVM = pDevIns->Internal.s.pVMR3;
1894 VM_ASSERT_EMT(pVM);
1895 LogFlow(("pdmR3DevHlp_DMAWriteMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbWritten=%p\n",
1896 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbWritten));
1897 int rc = VINF_SUCCESS;
1898 if (pVM->pdm.s.pDmac)
1899 {
1900 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnWriteMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock);
1901 if (pcbWritten)
1902 *pcbWritten = cb;
1903 }
1904 else
1905 {
1906 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1907 rc = VERR_PDM_NO_DMAC_INSTANCE;
1908 }
1909 LogFlow(("pdmR3DevHlp_DMAWriteMemory: caller='%s'/%d: returns %Rrc\n",
1910 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1911 return rc;
1912}
1913
1914
1915/** @interface_method_impl{PDMDEVHLPR3,pfnDMASetDREQ} */
1916static DECLCALLBACK(int) pdmR3DevHlp_DMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
1917{
1918 PDMDEV_ASSERT_DEVINS(pDevIns);
1919 PVM pVM = pDevIns->Internal.s.pVMR3;
1920 VM_ASSERT_EMT(pVM);
1921 LogFlow(("pdmR3DevHlp_DMASetDREQ: caller='%s'/%d: uChannel=%d uLevel=%d\n",
1922 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, uLevel));
1923 int rc = VINF_SUCCESS;
1924 if (pVM->pdm.s.pDmac)
1925 pVM->pdm.s.pDmac->Reg.pfnSetDREQ(pVM->pdm.s.pDmac->pDevIns, uChannel, uLevel);
1926 else
1927 {
1928 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1929 rc = VERR_PDM_NO_DMAC_INSTANCE;
1930 }
1931 LogFlow(("pdmR3DevHlp_DMASetDREQ: caller='%s'/%d: returns %Rrc\n",
1932 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1933 return rc;
1934}
1935
1936/** @interface_method_impl{PDMDEVHLPR3,pfnDMAGetChannelMode} */
1937static DECLCALLBACK(uint8_t) pdmR3DevHlp_DMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
1938{
1939 PDMDEV_ASSERT_DEVINS(pDevIns);
1940 PVM pVM = pDevIns->Internal.s.pVMR3;
1941 VM_ASSERT_EMT(pVM);
1942 LogFlow(("pdmR3DevHlp_DMAGetChannelMode: caller='%s'/%d: uChannel=%d\n",
1943 pDevIns->pReg->szName, pDevIns->iInstance, uChannel));
1944 uint8_t u8Mode;
1945 if (pVM->pdm.s.pDmac)
1946 u8Mode = pVM->pdm.s.pDmac->Reg.pfnGetChannelMode(pVM->pdm.s.pDmac->pDevIns, uChannel);
1947 else
1948 {
1949 AssertMsgFailed(("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1950 u8Mode = 3 << 2 /* illegal mode type */;
1951 }
1952 LogFlow(("pdmR3DevHlp_DMAGetChannelMode: caller='%s'/%d: returns %#04x\n",
1953 pDevIns->pReg->szName, pDevIns->iInstance, u8Mode));
1954 return u8Mode;
1955}
1956
1957/** @interface_method_impl{PDMDEVHLPR3,pfnDMASchedule} */
1958static DECLCALLBACK(void) pdmR3DevHlp_DMASchedule(PPDMDEVINS pDevIns)
1959{
1960 PDMDEV_ASSERT_DEVINS(pDevIns);
1961 PVM pVM = pDevIns->Internal.s.pVMR3;
1962 VM_ASSERT_EMT(pVM);
1963 LogFlow(("pdmR3DevHlp_DMASchedule: caller='%s'/%d: VM_FF_PDM_DMA %d -> 1\n",
1964 pDevIns->pReg->szName, pDevIns->iInstance, VM_FF_ISSET(pVM, VM_FF_PDM_DMA)));
1965
1966 AssertMsg(pVM->pdm.s.pDmac, ("Configuration error: No DMAC controller available. This could be related to init order too!\n"));
1967 VM_FF_SET(pVM, VM_FF_PDM_DMA);
1968#ifdef VBOX_WITH_REM
1969 REMR3NotifyDmaPending(pVM);
1970#endif
1971 VMR3NotifyGlobalFFU(pVM->pUVM, VMNOTIFYFF_FLAGS_DONE_REM);
1972}
1973
1974
1975/** @interface_method_impl{PDMDEVHLPR3,pfnCMOSWrite} */
1976static DECLCALLBACK(int) pdmR3DevHlp_CMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
1977{
1978 PDMDEV_ASSERT_DEVINS(pDevIns);
1979 PVM pVM = pDevIns->Internal.s.pVMR3;
1980 VM_ASSERT_EMT(pVM);
1981
1982 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: iReg=%#04x u8Value=%#04x\n",
1983 pDevIns->pReg->szName, pDevIns->iInstance, iReg, u8Value));
1984 int rc;
1985 if (pVM->pdm.s.pRtc)
1986 rc = pVM->pdm.s.pRtc->Reg.pfnWrite(pVM->pdm.s.pRtc->pDevIns, iReg, u8Value);
1987 else
1988 rc = VERR_PDM_NO_RTC_INSTANCE;
1989
1990 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: return %Rrc\n",
1991 pDevIns->pReg->szName, pDevIns->iInstance, rc));
1992 return rc;
1993}
1994
1995
1996/** @interface_method_impl{PDMDEVHLPR3,pfnCMOSRead} */
1997static DECLCALLBACK(int) pdmR3DevHlp_CMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
1998{
1999 PDMDEV_ASSERT_DEVINS(pDevIns);
2000 PVM pVM = pDevIns->Internal.s.pVMR3;
2001 VM_ASSERT_EMT(pVM);
2002
2003 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: iReg=%#04x pu8Value=%p\n",
2004 pDevIns->pReg->szName, pDevIns->iInstance, iReg, pu8Value));
2005 int rc;
2006 if (pVM->pdm.s.pRtc)
2007 rc = pVM->pdm.s.pRtc->Reg.pfnRead(pVM->pdm.s.pRtc->pDevIns, iReg, pu8Value);
2008 else
2009 rc = VERR_PDM_NO_RTC_INSTANCE;
2010
2011 LogFlow(("pdmR3DevHlp_CMOSWrite: caller='%s'/%d: return %Rrc\n",
2012 pDevIns->pReg->szName, pDevIns->iInstance, rc));
2013 return rc;
2014}
2015
2016
2017/** @interface_method_impl{PDMDEVHLPR3,pfnAssertEMT} */
2018static DECLCALLBACK(bool) pdmR3DevHlp_AssertEMT(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction)
2019{
2020 PDMDEV_ASSERT_DEVINS(pDevIns);
2021 if (VM_IS_EMT(pDevIns->Internal.s.pVMR3))
2022 return true;
2023
2024 char szMsg[100];
2025 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance);
2026 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
2027 AssertBreakpoint();
2028 return false;
2029}
2030
2031
2032/** @interface_method_impl{PDMDEVHLPR3,pfnAssertOther} */
2033static DECLCALLBACK(bool) pdmR3DevHlp_AssertOther(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction)
2034{
2035 PDMDEV_ASSERT_DEVINS(pDevIns);
2036 if (!VM_IS_EMT(pDevIns->Internal.s.pVMR3))
2037 return true;
2038
2039 char szMsg[100];
2040 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance);
2041 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
2042 AssertBreakpoint();
2043 return false;
2044}
2045
2046
2047/** @interface_method_impl{PDMDEVHLP,pfnLdrGetRCInterfaceSymbols} */
2048static DECLCALLBACK(int) pdmR3DevHlp_LdrGetRCInterfaceSymbols(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
2049 const char *pszSymPrefix, const char *pszSymList)
2050{
2051 PDMDEV_ASSERT_DEVINS(pDevIns);
2052 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2053 LogFlow(("pdmR3DevHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
2054 pDevIns->pReg->szName, pDevIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
2055
2056 int rc;
2057 if ( strncmp(pszSymPrefix, "dev", 3) == 0
2058 && RTStrIStr(pszSymPrefix + 3, pDevIns->pReg->szName) != NULL)
2059 {
2060 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)
2061 rc = PDMR3LdrGetInterfaceSymbols(pDevIns->Internal.s.pVMR3,
2062 pvInterface, cbInterface,
2063 pDevIns->pReg->szRCMod, pDevIns->Internal.s.pDevR3->pszRCSearchPath,
2064 pszSymPrefix, pszSymList,
2065 false /*fRing0OrRC*/);
2066 else
2067 {
2068 AssertMsgFailed(("Not a raw-mode enabled driver\n"));
2069 rc = VERR_PERMISSION_DENIED;
2070 }
2071 }
2072 else
2073 {
2074 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'dev' and contain the driver name!\n",
2075 pszSymPrefix, pDevIns->pReg->szName));
2076 rc = VERR_INVALID_NAME;
2077 }
2078
2079 LogFlow(("pdmR3DevHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
2080 pDevIns->iInstance, rc));
2081 return rc;
2082}
2083
2084
2085/** @interface_method_impl{PDMDEVHLP,pfnLdrGetR0InterfaceSymbols} */
2086static DECLCALLBACK(int) pdmR3DevHlp_LdrGetR0InterfaceSymbols(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
2087 const char *pszSymPrefix, const char *pszSymList)
2088{
2089 PDMDEV_ASSERT_DEVINS(pDevIns);
2090 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2091 LogFlow(("pdmR3DevHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
2092 pDevIns->pReg->szName, pDevIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
2093
2094 int rc;
2095 if ( strncmp(pszSymPrefix, "dev", 3) == 0
2096 && RTStrIStr(pszSymPrefix + 3, pDevIns->pReg->szName) != NULL)
2097 {
2098 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
2099 rc = PDMR3LdrGetInterfaceSymbols(pDevIns->Internal.s.pVMR3,
2100 pvInterface, cbInterface,
2101 pDevIns->pReg->szR0Mod, pDevIns->Internal.s.pDevR3->pszR0SearchPath,
2102 pszSymPrefix, pszSymList,
2103 true /*fRing0OrRC*/);
2104 else
2105 {
2106 AssertMsgFailed(("Not a ring-0 enabled driver\n"));
2107 rc = VERR_PERMISSION_DENIED;
2108 }
2109 }
2110 else
2111 {
2112 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'dev' and contain the driver name!\n",
2113 pszSymPrefix, pDevIns->pReg->szName));
2114 rc = VERR_INVALID_NAME;
2115 }
2116
2117 LogFlow(("pdmR3DevHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
2118 pDevIns->iInstance, rc));
2119 return rc;
2120}
2121
2122
2123/** @interface_method_impl{PDMDEVHLP,pfnCallR0} */
2124static DECLCALLBACK(int) pdmR3DevHlp_CallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
2125{
2126 PDMDEV_ASSERT_DEVINS(pDevIns);
2127 PVM pVM = pDevIns->Internal.s.pVMR3;
2128 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2129 LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: uOperation=%#x u64Arg=%#RX64\n",
2130 pDevIns->pReg->szName, pDevIns->iInstance, uOperation, u64Arg));
2131
2132 /*
2133 * Resolve the ring-0 entry point. There is not need to remember this like
2134 * we do for drivers since this is mainly for construction time hacks and
2135 * other things that aren't performance critical.
2136 */
2137 int rc;
2138 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
2139 {
2140 char szSymbol[ sizeof("devR0") + sizeof(pDevIns->pReg->szName) + sizeof("ReqHandler")];
2141 strcat(strcat(strcpy(szSymbol, "devR0"), pDevIns->pReg->szName), "ReqHandler");
2142 szSymbol[sizeof("devR0") - 1] = RT_C_TO_UPPER(szSymbol[sizeof("devR0") - 1]);
2143
2144 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0;
2145 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, szSymbol, &pfnReqHandlerR0);
2146 if (RT_SUCCESS(rc))
2147 {
2148 /*
2149 * Make the ring-0 call.
2150 */
2151 PDMDEVICECALLREQHANDLERREQ Req;
2152 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
2153 Req.Hdr.cbReq = sizeof(Req);
2154 Req.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2155 Req.pfnReqHandlerR0 = pfnReqHandlerR0;
2156 Req.uOperation = uOperation;
2157 Req.u32Alignment = 0;
2158 Req.u64Arg = u64Arg;
2159 rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER, 0, &Req.Hdr);
2160 }
2161 else
2162 pfnReqHandlerR0 = NIL_RTR0PTR;
2163 }
2164 else
2165 rc = VERR_ACCESS_DENIED;
2166 LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
2167 pDevIns->iInstance, rc));
2168 return rc;
2169}
2170
2171
2172/** @interface_method_impl{PDMDEVHLPR3,pfnGetUVM} */
2173static DECLCALLBACK(PUVM) pdmR3DevHlp_GetUVM(PPDMDEVINS pDevIns)
2174{
2175 PDMDEV_ASSERT_DEVINS(pDevIns);
2176 LogFlow(("pdmR3DevHlp_GetUVM: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns->Internal.s.pVMR3));
2177 return pDevIns->Internal.s.pVMR3->pUVM;
2178}
2179
2180
2181/** @interface_method_impl{PDMDEVHLPR3,pfnGetVM} */
2182static DECLCALLBACK(PVM) pdmR3DevHlp_GetVM(PPDMDEVINS pDevIns)
2183{
2184 PDMDEV_ASSERT_DEVINS(pDevIns);
2185 LogFlow(("pdmR3DevHlp_GetVM: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns->Internal.s.pVMR3));
2186 return pDevIns->Internal.s.pVMR3;
2187}
2188
2189
2190/** @interface_method_impl{PDMDEVHLPR3,pfnGetVMCPU} */
2191static DECLCALLBACK(PVMCPU) pdmR3DevHlp_GetVMCPU(PPDMDEVINS pDevIns)
2192{
2193 PDMDEV_ASSERT_DEVINS(pDevIns);
2194 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2195 LogFlow(("pdmR3DevHlp_GetVMCPU: caller='%s'/%d for CPU %u\n", pDevIns->pReg->szName, pDevIns->iInstance, VMMGetCpuId(pDevIns->Internal.s.pVMR3)));
2196 return VMMGetCpu(pDevIns->Internal.s.pVMR3);
2197}
2198
2199
2200/** @interface_method_impl{PDMDEVHLPR3,pfnPCIBusRegister} */
2201static DECLCALLBACK(int) pdmR3DevHlp_PCIBusRegister(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3)
2202{
2203 PDMDEV_ASSERT_DEVINS(pDevIns);
2204 PVM pVM = pDevIns->Internal.s.pVMR3;
2205 VM_ASSERT_EMT(pVM);
2206 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: pPciBusReg=%p:{.u32Version=%#x, .pfnRegisterR3=%p, .pfnIORegionRegisterR3=%p, .pfnSetIrqR3=%p, "
2207 ".pfnSaveExecR3=%p, .pfnLoadExecR3=%p, .pfnFakePCIBIOSR3=%p, .pszSetIrqRC=%p:{%s}, .pszSetIrqR0=%p:{%s}} ppPciHlpR3=%p\n",
2208 pDevIns->pReg->szName, pDevIns->iInstance, pPciBusReg, pPciBusReg->u32Version, pPciBusReg->pfnRegisterR3,
2209 pPciBusReg->pfnIORegionRegisterR3, pPciBusReg->pfnSetIrqR3, pPciBusReg->pfnSaveExecR3, pPciBusReg->pfnLoadExecR3,
2210 pPciBusReg->pfnFakePCIBIOSR3, pPciBusReg->pszSetIrqRC, pPciBusReg->pszSetIrqRC, pPciBusReg->pszSetIrqR0, pPciBusReg->pszSetIrqR0, ppPciHlpR3));
2211
2212 /*
2213 * Validate the structure.
2214 */
2215 if (pPciBusReg->u32Version != PDM_PCIBUSREG_VERSION)
2216 {
2217 AssertMsgFailed(("u32Version=%#x expected %#x\n", pPciBusReg->u32Version, PDM_PCIBUSREG_VERSION));
2218 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2219 return VERR_INVALID_PARAMETER;
2220 }
2221 if ( !pPciBusReg->pfnRegisterR3
2222 || !pPciBusReg->pfnIORegionRegisterR3
2223 || !pPciBusReg->pfnSetIrqR3
2224 || !pPciBusReg->pfnSaveExecR3
2225 || !pPciBusReg->pfnLoadExecR3
2226 || (!pPciBusReg->pfnFakePCIBIOSR3 && !pVM->pdm.s.aPciBuses[0].pDevInsR3)) /* Only the first bus needs to do the BIOS work. */
2227 {
2228 Assert(pPciBusReg->pfnRegisterR3);
2229 Assert(pPciBusReg->pfnIORegionRegisterR3);
2230 Assert(pPciBusReg->pfnSetIrqR3);
2231 Assert(pPciBusReg->pfnSaveExecR3);
2232 Assert(pPciBusReg->pfnLoadExecR3);
2233 Assert(pPciBusReg->pfnFakePCIBIOSR3);
2234 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2235 return VERR_INVALID_PARAMETER;
2236 }
2237 if ( pPciBusReg->pszSetIrqRC
2238 && !VALID_PTR(pPciBusReg->pszSetIrqRC))
2239 {
2240 Assert(VALID_PTR(pPciBusReg->pszSetIrqRC));
2241 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2242 return VERR_INVALID_PARAMETER;
2243 }
2244 if ( pPciBusReg->pszSetIrqR0
2245 && !VALID_PTR(pPciBusReg->pszSetIrqR0))
2246 {
2247 Assert(VALID_PTR(pPciBusReg->pszSetIrqR0));
2248 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2249 return VERR_INVALID_PARAMETER;
2250 }
2251 if (!ppPciHlpR3)
2252 {
2253 Assert(ppPciHlpR3);
2254 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (ppPciHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2255 return VERR_INVALID_PARAMETER;
2256 }
2257
2258 /*
2259 * Find free PCI bus entry.
2260 */
2261 unsigned iBus = 0;
2262 for (iBus = 0; iBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses); iBus++)
2263 if (!pVM->pdm.s.aPciBuses[iBus].pDevInsR3)
2264 break;
2265 if (iBus >= RT_ELEMENTS(pVM->pdm.s.aPciBuses))
2266 {
2267 AssertMsgFailed(("Too many PCI buses. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aPciBuses)));
2268 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc (pci bus)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2269 return VERR_INVALID_PARAMETER;
2270 }
2271 PPDMPCIBUS pPciBus = &pVM->pdm.s.aPciBuses[iBus];
2272
2273 /*
2274 * Resolve and init the RC bits.
2275 */
2276 if (pPciBusReg->pszSetIrqRC)
2277 {
2278 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pPciBusReg->pszSetIrqRC, &pPciBus->pfnSetIrqRC);
2279 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pPciBusReg->pszSetIrqRC, rc));
2280 if (RT_FAILURE(rc))
2281 {
2282 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2283 return rc;
2284 }
2285 pPciBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2286 }
2287 else
2288 {
2289 pPciBus->pfnSetIrqRC = 0;
2290 pPciBus->pDevInsRC = 0;
2291 }
2292
2293 /*
2294 * Resolve and init the R0 bits.
2295 */
2296 if (pPciBusReg->pszSetIrqR0)
2297 {
2298 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pPciBusReg->pszSetIrqR0, &pPciBus->pfnSetIrqR0);
2299 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pPciBusReg->pszSetIrqR0, rc));
2300 if (RT_FAILURE(rc))
2301 {
2302 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2303 return rc;
2304 }
2305 pPciBus->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2306 }
2307 else
2308 {
2309 pPciBus->pfnSetIrqR0 = 0;
2310 pPciBus->pDevInsR0 = 0;
2311 }
2312
2313 /*
2314 * Init the R3 bits.
2315 */
2316 pPciBus->iBus = iBus;
2317 pPciBus->pDevInsR3 = pDevIns;
2318 pPciBus->pfnRegisterR3 = pPciBusReg->pfnRegisterR3;
2319 pPciBus->pfnRegisterMsiR3 = pPciBusReg->pfnRegisterMsiR3;
2320 pPciBus->pfnIORegionRegisterR3 = pPciBusReg->pfnIORegionRegisterR3;
2321 pPciBus->pfnSetConfigCallbacksR3 = pPciBusReg->pfnSetConfigCallbacksR3;
2322 pPciBus->pfnSetIrqR3 = pPciBusReg->pfnSetIrqR3;
2323 pPciBus->pfnSaveExecR3 = pPciBusReg->pfnSaveExecR3;
2324 pPciBus->pfnLoadExecR3 = pPciBusReg->pfnLoadExecR3;
2325 pPciBus->pfnFakePCIBIOSR3 = pPciBusReg->pfnFakePCIBIOSR3;
2326
2327 Log(("PDM: Registered PCI bus device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
2328
2329 /* set the helper pointer and return. */
2330 *ppPciHlpR3 = &g_pdmR3DevPciHlp;
2331 LogFlow(("pdmR3DevHlp_PCIBusRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2332 return VINF_SUCCESS;
2333}
2334
2335
2336/** @interface_method_impl{PDMDEVHLPR3,pfnPICRegister} */
2337static DECLCALLBACK(int) pdmR3DevHlp_PICRegister(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3)
2338{
2339 PDMDEV_ASSERT_DEVINS(pDevIns);
2340 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2341 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",
2342 pDevIns->pReg->szName, pDevIns->iInstance, pPicReg, pPicReg->u32Version, pPicReg->pfnSetIrqR3, pPicReg->pfnGetInterruptR3,
2343 pPicReg->pszSetIrqRC, pPicReg->pszSetIrqRC, pPicReg->pszGetInterruptRC, pPicReg->pszGetInterruptRC,
2344 pPicReg->pszSetIrqR0, pPicReg->pszSetIrqR0, pPicReg->pszGetInterruptR0, pPicReg->pszGetInterruptR0,
2345 ppPicHlpR3));
2346
2347 /*
2348 * Validate input.
2349 */
2350 if (pPicReg->u32Version != PDM_PICREG_VERSION)
2351 {
2352 AssertMsgFailed(("u32Version=%#x expected %#x\n", pPicReg->u32Version, PDM_PICREG_VERSION));
2353 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2354 return VERR_INVALID_PARAMETER;
2355 }
2356 if ( !pPicReg->pfnSetIrqR3
2357 || !pPicReg->pfnGetInterruptR3)
2358 {
2359 Assert(pPicReg->pfnSetIrqR3);
2360 Assert(pPicReg->pfnGetInterruptR3);
2361 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2362 return VERR_INVALID_PARAMETER;
2363 }
2364 if ( ( pPicReg->pszSetIrqRC
2365 || pPicReg->pszGetInterruptRC)
2366 && ( !VALID_PTR(pPicReg->pszSetIrqRC)
2367 || !VALID_PTR(pPicReg->pszGetInterruptRC))
2368 )
2369 {
2370 Assert(VALID_PTR(pPicReg->pszSetIrqRC));
2371 Assert(VALID_PTR(pPicReg->pszGetInterruptRC));
2372 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (RC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2373 return VERR_INVALID_PARAMETER;
2374 }
2375 if ( pPicReg->pszSetIrqRC
2376 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC))
2377 {
2378 Assert(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC);
2379 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (RC flag)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2380 return VERR_INVALID_PARAMETER;
2381 }
2382 if ( pPicReg->pszSetIrqR0
2383 && !(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0))
2384 {
2385 Assert(pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0);
2386 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (R0 flag)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2387 return VERR_INVALID_PARAMETER;
2388 }
2389 if (!ppPicHlpR3)
2390 {
2391 Assert(ppPicHlpR3);
2392 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc (ppPicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2393 return VERR_INVALID_PARAMETER;
2394 }
2395
2396 /*
2397 * Only one PIC device.
2398 */
2399 PVM pVM = pDevIns->Internal.s.pVMR3;
2400 if (pVM->pdm.s.Pic.pDevInsR3)
2401 {
2402 AssertMsgFailed(("Only one pic device is supported!\n"));
2403 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2404 return VERR_INVALID_PARAMETER;
2405 }
2406
2407 /*
2408 * RC stuff.
2409 */
2410 if (pPicReg->pszSetIrqRC)
2411 {
2412 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pPicReg->pszSetIrqRC, &pVM->pdm.s.Pic.pfnSetIrqRC);
2413 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pPicReg->pszSetIrqRC, rc));
2414 if (RT_SUCCESS(rc))
2415 {
2416 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pPicReg->pszGetInterruptRC, &pVM->pdm.s.Pic.pfnGetInterruptRC);
2417 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pPicReg->pszGetInterruptRC, rc));
2418 }
2419 if (RT_FAILURE(rc))
2420 {
2421 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2422 return rc;
2423 }
2424 pVM->pdm.s.Pic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2425 }
2426 else
2427 {
2428 pVM->pdm.s.Pic.pDevInsRC = 0;
2429 pVM->pdm.s.Pic.pfnSetIrqRC = 0;
2430 pVM->pdm.s.Pic.pfnGetInterruptRC = 0;
2431 }
2432
2433 /*
2434 * R0 stuff.
2435 */
2436 if (pPicReg->pszSetIrqR0)
2437 {
2438 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pPicReg->pszSetIrqR0, &pVM->pdm.s.Pic.pfnSetIrqR0);
2439 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pPicReg->pszSetIrqR0, rc));
2440 if (RT_SUCCESS(rc))
2441 {
2442 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pPicReg->pszGetInterruptR0, &pVM->pdm.s.Pic.pfnGetInterruptR0);
2443 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pPicReg->pszGetInterruptR0, rc));
2444 }
2445 if (RT_FAILURE(rc))
2446 {
2447 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2448 return rc;
2449 }
2450 pVM->pdm.s.Pic.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2451 Assert(pVM->pdm.s.Pic.pDevInsR0);
2452 }
2453 else
2454 {
2455 pVM->pdm.s.Pic.pfnSetIrqR0 = 0;
2456 pVM->pdm.s.Pic.pfnGetInterruptR0 = 0;
2457 pVM->pdm.s.Pic.pDevInsR0 = 0;
2458 }
2459
2460 /*
2461 * R3 stuff.
2462 */
2463 pVM->pdm.s.Pic.pDevInsR3 = pDevIns;
2464 pVM->pdm.s.Pic.pfnSetIrqR3 = pPicReg->pfnSetIrqR3;
2465 pVM->pdm.s.Pic.pfnGetInterruptR3 = pPicReg->pfnGetInterruptR3;
2466 Log(("PDM: Registered PIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
2467
2468 /* set the helper pointer and return. */
2469 *ppPicHlpR3 = &g_pdmR3DevPicHlp;
2470 LogFlow(("pdmR3DevHlp_PICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2471 return VINF_SUCCESS;
2472}
2473
2474
2475/** @interface_method_impl{PDMDEVHLPR3,pfnAPICRegister} */
2476static DECLCALLBACK(int) pdmR3DevHlp_APICRegister(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3)
2477{
2478 PDMDEV_ASSERT_DEVINS(pDevIns);
2479 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2480 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: pApicReg=%p:{.u32Version=%#x, .pfnGetInterruptR3=%p, .pfnSetBaseR3=%p, .pfnGetBaseR3=%p, "
2481 ".pfnSetTPRR3=%p, .pfnGetTPRR3=%p, .pfnWriteMSR3=%p, .pfnReadMSR3=%p, .pfnBusDeliverR3=%p, .pfnLocalInterruptR3=%p, pszGetInterruptRC=%p:{%s}, pszSetBaseRC=%p:{%s}, pszGetBaseRC=%p:{%s}, "
2482 ".pszSetTPRRC=%p:{%s}, .pszGetTPRRC=%p:{%s}, .pszWriteMSRRC=%p:{%s}, .pszReadMSRRC=%p:{%s}, .pszBusDeliverRC=%p:{%s}, .pszLocalInterruptRC=%p:{%s}} ppApicHlpR3=%p\n",
2483 pDevIns->pReg->szName, pDevIns->iInstance, pApicReg, pApicReg->u32Version, pApicReg->pfnGetInterruptR3, pApicReg->pfnSetBaseR3,
2484 pApicReg->pfnGetBaseR3, pApicReg->pfnSetTPRR3, pApicReg->pfnGetTPRR3, pApicReg->pfnWriteMSRR3, pApicReg->pfnReadMSRR3, pApicReg->pfnBusDeliverR3, pApicReg->pfnLocalInterruptR3, pApicReg->pszGetInterruptRC,
2485 pApicReg->pszGetInterruptRC, pApicReg->pszSetBaseRC, pApicReg->pszSetBaseRC, pApicReg->pszGetBaseRC, pApicReg->pszGetBaseRC,
2486 pApicReg->pszSetTPRRC, pApicReg->pszSetTPRRC, pApicReg->pszGetTPRRC, pApicReg->pszGetTPRRC, pApicReg->pszWriteMSRRC, pApicReg->pszWriteMSRRC, pApicReg->pszReadMSRRC, pApicReg->pszReadMSRRC, pApicReg->pszBusDeliverRC,
2487 pApicReg->pszBusDeliverRC, pApicReg->pszLocalInterruptRC, pApicReg->pszLocalInterruptRC, ppApicHlpR3));
2488
2489 /*
2490 * Validate input.
2491 */
2492 if (pApicReg->u32Version != PDM_APICREG_VERSION)
2493 {
2494 AssertMsgFailed(("u32Version=%#x expected %#x\n", pApicReg->u32Version, PDM_APICREG_VERSION));
2495 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2496 return VERR_INVALID_PARAMETER;
2497 }
2498 if ( !pApicReg->pfnGetInterruptR3
2499 || !pApicReg->pfnHasPendingIrqR3
2500 || !pApicReg->pfnSetBaseR3
2501 || !pApicReg->pfnGetBaseR3
2502 || !pApicReg->pfnSetTPRR3
2503 || !pApicReg->pfnGetTPRR3
2504 || !pApicReg->pfnWriteMSRR3
2505 || !pApicReg->pfnReadMSRR3
2506 || !pApicReg->pfnBusDeliverR3
2507 || !pApicReg->pfnLocalInterruptR3)
2508 {
2509 Assert(pApicReg->pfnGetInterruptR3);
2510 Assert(pApicReg->pfnHasPendingIrqR3);
2511 Assert(pApicReg->pfnSetBaseR3);
2512 Assert(pApicReg->pfnGetBaseR3);
2513 Assert(pApicReg->pfnSetTPRR3);
2514 Assert(pApicReg->pfnGetTPRR3);
2515 Assert(pApicReg->pfnWriteMSRR3);
2516 Assert(pApicReg->pfnReadMSRR3);
2517 Assert(pApicReg->pfnBusDeliverR3);
2518 Assert(pApicReg->pfnLocalInterruptR3);
2519 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2520 return VERR_INVALID_PARAMETER;
2521 }
2522 if ( ( pApicReg->pszGetInterruptRC
2523 || pApicReg->pszHasPendingIrqRC
2524 || pApicReg->pszSetBaseRC
2525 || pApicReg->pszGetBaseRC
2526 || pApicReg->pszSetTPRRC
2527 || pApicReg->pszGetTPRRC
2528 || pApicReg->pszWriteMSRRC
2529 || pApicReg->pszReadMSRRC
2530 || pApicReg->pszBusDeliverRC
2531 || pApicReg->pszLocalInterruptRC)
2532 && ( !VALID_PTR(pApicReg->pszGetInterruptRC)
2533 || !VALID_PTR(pApicReg->pszHasPendingIrqRC)
2534 || !VALID_PTR(pApicReg->pszSetBaseRC)
2535 || !VALID_PTR(pApicReg->pszGetBaseRC)
2536 || !VALID_PTR(pApicReg->pszSetTPRRC)
2537 || !VALID_PTR(pApicReg->pszGetTPRRC)
2538 || !VALID_PTR(pApicReg->pszWriteMSRRC)
2539 || !VALID_PTR(pApicReg->pszReadMSRRC)
2540 || !VALID_PTR(pApicReg->pszBusDeliverRC)
2541 || !VALID_PTR(pApicReg->pszLocalInterruptRC))
2542 )
2543 {
2544 Assert(VALID_PTR(pApicReg->pszGetInterruptRC));
2545 Assert(VALID_PTR(pApicReg->pszHasPendingIrqRC));
2546 Assert(VALID_PTR(pApicReg->pszSetBaseRC));
2547 Assert(VALID_PTR(pApicReg->pszGetBaseRC));
2548 Assert(VALID_PTR(pApicReg->pszSetTPRRC));
2549 Assert(VALID_PTR(pApicReg->pszGetTPRRC));
2550 Assert(VALID_PTR(pApicReg->pszReadMSRRC));
2551 Assert(VALID_PTR(pApicReg->pszWriteMSRRC));
2552 Assert(VALID_PTR(pApicReg->pszBusDeliverRC));
2553 Assert(VALID_PTR(pApicReg->pszLocalInterruptRC));
2554 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (RC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2555 return VERR_INVALID_PARAMETER;
2556 }
2557 if ( ( pApicReg->pszGetInterruptR0
2558 || pApicReg->pszHasPendingIrqR0
2559 || pApicReg->pszSetBaseR0
2560 || pApicReg->pszGetBaseR0
2561 || pApicReg->pszSetTPRR0
2562 || pApicReg->pszGetTPRR0
2563 || pApicReg->pszWriteMSRR0
2564 || pApicReg->pszReadMSRR0
2565 || pApicReg->pszBusDeliverR0
2566 || pApicReg->pszLocalInterruptR0)
2567 && ( !VALID_PTR(pApicReg->pszGetInterruptR0)
2568 || !VALID_PTR(pApicReg->pszHasPendingIrqR0)
2569 || !VALID_PTR(pApicReg->pszSetBaseR0)
2570 || !VALID_PTR(pApicReg->pszGetBaseR0)
2571 || !VALID_PTR(pApicReg->pszSetTPRR0)
2572 || !VALID_PTR(pApicReg->pszGetTPRR0)
2573 || !VALID_PTR(pApicReg->pszReadMSRR0)
2574 || !VALID_PTR(pApicReg->pszWriteMSRR0)
2575 || !VALID_PTR(pApicReg->pszBusDeliverR0)
2576 || !VALID_PTR(pApicReg->pszLocalInterruptR0))
2577 )
2578 {
2579 Assert(VALID_PTR(pApicReg->pszGetInterruptR0));
2580 Assert(VALID_PTR(pApicReg->pszHasPendingIrqR0));
2581 Assert(VALID_PTR(pApicReg->pszSetBaseR0));
2582 Assert(VALID_PTR(pApicReg->pszGetBaseR0));
2583 Assert(VALID_PTR(pApicReg->pszSetTPRR0));
2584 Assert(VALID_PTR(pApicReg->pszGetTPRR0));
2585 Assert(VALID_PTR(pApicReg->pszReadMSRR0));
2586 Assert(VALID_PTR(pApicReg->pszWriteMSRR0));
2587 Assert(VALID_PTR(pApicReg->pszBusDeliverR0));
2588 Assert(VALID_PTR(pApicReg->pszLocalInterruptR0));
2589 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (R0 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2590 return VERR_INVALID_PARAMETER;
2591 }
2592 if (!ppApicHlpR3)
2593 {
2594 Assert(ppApicHlpR3);
2595 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc (ppApicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2596 return VERR_INVALID_PARAMETER;
2597 }
2598
2599 /*
2600 * Only one APIC device. On SMP we have single logical device covering all LAPICs,
2601 * as they need to communicate and share state easily.
2602 */
2603 PVM pVM = pDevIns->Internal.s.pVMR3;
2604 if (pVM->pdm.s.Apic.pDevInsR3)
2605 {
2606 AssertMsgFailed(("Only one apic device is supported!\n"));
2607 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2608 return VERR_INVALID_PARAMETER;
2609 }
2610
2611 /*
2612 * Resolve & initialize the RC bits.
2613 */
2614 if (pApicReg->pszGetInterruptRC)
2615 {
2616 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszGetInterruptRC, &pVM->pdm.s.Apic.pfnGetInterruptRC);
2617 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszGetInterruptRC, rc));
2618 if (RT_SUCCESS(rc))
2619 {
2620 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszHasPendingIrqRC, &pVM->pdm.s.Apic.pfnHasPendingIrqRC);
2621 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszHasPendingIrqRC, rc));
2622 }
2623 if (RT_SUCCESS(rc))
2624 {
2625 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszSetBaseRC, &pVM->pdm.s.Apic.pfnSetBaseRC);
2626 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszSetBaseRC, rc));
2627 }
2628 if (RT_SUCCESS(rc))
2629 {
2630 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszGetBaseRC, &pVM->pdm.s.Apic.pfnGetBaseRC);
2631 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszGetBaseRC, rc));
2632 }
2633 if (RT_SUCCESS(rc))
2634 {
2635 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszSetTPRRC, &pVM->pdm.s.Apic.pfnSetTPRRC);
2636 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszSetTPRRC, rc));
2637 }
2638 if (RT_SUCCESS(rc))
2639 {
2640 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszGetTPRRC, &pVM->pdm.s.Apic.pfnGetTPRRC);
2641 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszGetTPRRC, rc));
2642 }
2643 if (RT_SUCCESS(rc))
2644 {
2645 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszWriteMSRRC, &pVM->pdm.s.Apic.pfnWriteMSRRC);
2646 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszWriteMSRRC, rc));
2647 }
2648 if (RT_SUCCESS(rc))
2649 {
2650 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszReadMSRRC, &pVM->pdm.s.Apic.pfnReadMSRRC);
2651 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszReadMSRRC, rc));
2652 }
2653 if (RT_SUCCESS(rc))
2654 {
2655 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszBusDeliverRC, &pVM->pdm.s.Apic.pfnBusDeliverRC);
2656 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszBusDeliverRC, rc));
2657 }
2658 if (RT_SUCCESS(rc))
2659 {
2660 rc = pdmR3DevGetSymbolRCLazy(pDevIns, pApicReg->pszLocalInterruptRC, &pVM->pdm.s.Apic.pfnLocalInterruptRC);
2661 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pApicReg->pszLocalInterruptRC, rc));
2662 }
2663 if (RT_FAILURE(rc))
2664 {
2665 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2666 return rc;
2667 }
2668 pVM->pdm.s.Apic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2669 }
2670 else
2671 {
2672 pVM->pdm.s.Apic.pDevInsRC = 0;
2673 pVM->pdm.s.Apic.pfnGetInterruptRC = 0;
2674 pVM->pdm.s.Apic.pfnHasPendingIrqRC = 0;
2675 pVM->pdm.s.Apic.pfnSetBaseRC = 0;
2676 pVM->pdm.s.Apic.pfnGetBaseRC = 0;
2677 pVM->pdm.s.Apic.pfnSetTPRRC = 0;
2678 pVM->pdm.s.Apic.pfnGetTPRRC = 0;
2679 pVM->pdm.s.Apic.pfnWriteMSRRC = 0;
2680 pVM->pdm.s.Apic.pfnReadMSRRC = 0;
2681 pVM->pdm.s.Apic.pfnBusDeliverRC = 0;
2682 pVM->pdm.s.Apic.pfnLocalInterruptRC = 0;
2683 }
2684
2685 /*
2686 * Resolve & initialize the R0 bits.
2687 */
2688 if (pApicReg->pszGetInterruptR0)
2689 {
2690 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszGetInterruptR0, &pVM->pdm.s.Apic.pfnGetInterruptR0);
2691 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszGetInterruptR0, rc));
2692 if (RT_SUCCESS(rc))
2693 {
2694 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszHasPendingIrqR0, &pVM->pdm.s.Apic.pfnHasPendingIrqR0);
2695 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszHasPendingIrqR0, rc));
2696 }
2697 if (RT_SUCCESS(rc))
2698 {
2699 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszSetBaseR0, &pVM->pdm.s.Apic.pfnSetBaseR0);
2700 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszSetBaseR0, rc));
2701 }
2702 if (RT_SUCCESS(rc))
2703 {
2704 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszGetBaseR0, &pVM->pdm.s.Apic.pfnGetBaseR0);
2705 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszGetBaseR0, rc));
2706 }
2707 if (RT_SUCCESS(rc))
2708 {
2709 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszSetTPRR0, &pVM->pdm.s.Apic.pfnSetTPRR0);
2710 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszSetTPRR0, rc));
2711 }
2712 if (RT_SUCCESS(rc))
2713 {
2714 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszGetTPRR0, &pVM->pdm.s.Apic.pfnGetTPRR0);
2715 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszGetTPRR0, rc));
2716 }
2717 if (RT_SUCCESS(rc))
2718 {
2719 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszWriteMSRR0, &pVM->pdm.s.Apic.pfnWriteMSRR0);
2720 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszWriteMSRR0, rc));
2721 }
2722 if (RT_SUCCESS(rc))
2723 {
2724 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszReadMSRR0, &pVM->pdm.s.Apic.pfnReadMSRR0);
2725 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszReadMSRR0, rc));
2726 }
2727 if (RT_SUCCESS(rc))
2728 {
2729 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszBusDeliverR0, &pVM->pdm.s.Apic.pfnBusDeliverR0);
2730 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszBusDeliverR0, rc));
2731 }
2732 if (RT_SUCCESS(rc))
2733 {
2734 rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pApicReg->pszLocalInterruptR0, &pVM->pdm.s.Apic.pfnLocalInterruptR0);
2735 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pApicReg->pszLocalInterruptR0, rc));
2736 }
2737 if (RT_FAILURE(rc))
2738 {
2739 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2740 return rc;
2741 }
2742 pVM->pdm.s.Apic.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2743 Assert(pVM->pdm.s.Apic.pDevInsR0);
2744 }
2745 else
2746 {
2747 pVM->pdm.s.Apic.pfnGetInterruptR0 = 0;
2748 pVM->pdm.s.Apic.pfnHasPendingIrqR0 = 0;
2749 pVM->pdm.s.Apic.pfnSetBaseR0 = 0;
2750 pVM->pdm.s.Apic.pfnGetBaseR0 = 0;
2751 pVM->pdm.s.Apic.pfnSetTPRR0 = 0;
2752 pVM->pdm.s.Apic.pfnGetTPRR0 = 0;
2753 pVM->pdm.s.Apic.pfnWriteMSRR0 = 0;
2754 pVM->pdm.s.Apic.pfnReadMSRR0 = 0;
2755 pVM->pdm.s.Apic.pfnBusDeliverR0 = 0;
2756 pVM->pdm.s.Apic.pfnLocalInterruptR0 = 0;
2757 pVM->pdm.s.Apic.pDevInsR0 = 0;
2758 }
2759
2760 /*
2761 * Initialize the HC bits.
2762 */
2763 pVM->pdm.s.Apic.pDevInsR3 = pDevIns;
2764 pVM->pdm.s.Apic.pfnGetInterruptR3 = pApicReg->pfnGetInterruptR3;
2765 pVM->pdm.s.Apic.pfnHasPendingIrqR3 = pApicReg->pfnHasPendingIrqR3;
2766 pVM->pdm.s.Apic.pfnSetBaseR3 = pApicReg->pfnSetBaseR3;
2767 pVM->pdm.s.Apic.pfnGetBaseR3 = pApicReg->pfnGetBaseR3;
2768 pVM->pdm.s.Apic.pfnSetTPRR3 = pApicReg->pfnSetTPRR3;
2769 pVM->pdm.s.Apic.pfnGetTPRR3 = pApicReg->pfnGetTPRR3;
2770 pVM->pdm.s.Apic.pfnWriteMSRR3 = pApicReg->pfnWriteMSRR3;
2771 pVM->pdm.s.Apic.pfnReadMSRR3 = pApicReg->pfnReadMSRR3;
2772 pVM->pdm.s.Apic.pfnBusDeliverR3 = pApicReg->pfnBusDeliverR3;
2773 pVM->pdm.s.Apic.pfnLocalInterruptR3 = pApicReg->pfnLocalInterruptR3;
2774 Log(("PDM: Registered APIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
2775
2776 /* set the helper pointer and return. */
2777 *ppApicHlpR3 = &g_pdmR3DevApicHlp;
2778 LogFlow(("pdmR3DevHlp_APICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2779 return VINF_SUCCESS;
2780}
2781
2782
2783/** @interface_method_impl{PDMDEVHLPR3,pfnIOAPICRegister} */
2784static DECLCALLBACK(int) pdmR3DevHlp_IOAPICRegister(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3)
2785{
2786 PDMDEV_ASSERT_DEVINS(pDevIns);
2787 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2788 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: pIoApicReg=%p:{.u32Version=%#x, .pfnSetIrqR3=%p, .pszSetIrqRC=%p:{%s}, .pszSetIrqR0=%p:{%s}} ppIoApicHlpR3=%p\n",
2789 pDevIns->pReg->szName, pDevIns->iInstance, pIoApicReg, pIoApicReg->u32Version, pIoApicReg->pfnSetIrqR3,
2790 pIoApicReg->pszSetIrqRC, pIoApicReg->pszSetIrqRC, pIoApicReg->pszSetIrqR0, pIoApicReg->pszSetIrqR0, ppIoApicHlpR3));
2791
2792 /*
2793 * Validate input.
2794 */
2795 if (pIoApicReg->u32Version != PDM_IOAPICREG_VERSION)
2796 {
2797 AssertMsgFailed(("u32Version=%#x expected %#x\n", pIoApicReg->u32Version, PDM_IOAPICREG_VERSION));
2798 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2799 return VERR_INVALID_PARAMETER;
2800 }
2801 if (!pIoApicReg->pfnSetIrqR3 || !pIoApicReg->pfnSendMsiR3)
2802 {
2803 Assert(pIoApicReg->pfnSetIrqR3);
2804 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (R3 callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2805 return VERR_INVALID_PARAMETER;
2806 }
2807 if ( pIoApicReg->pszSetIrqRC
2808 && !VALID_PTR(pIoApicReg->pszSetIrqRC))
2809 {
2810 Assert(VALID_PTR(pIoApicReg->pszSetIrqRC));
2811 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2812 return VERR_INVALID_PARAMETER;
2813 }
2814 if ( pIoApicReg->pszSendMsiRC
2815 && !VALID_PTR(pIoApicReg->pszSendMsiRC))
2816 {
2817 Assert(VALID_PTR(pIoApicReg->pszSendMsiRC));
2818 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2819 return VERR_INVALID_PARAMETER;
2820 }
2821 if ( pIoApicReg->pszSetIrqR0
2822 && !VALID_PTR(pIoApicReg->pszSetIrqR0))
2823 {
2824 Assert(VALID_PTR(pIoApicReg->pszSetIrqR0));
2825 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2826 return VERR_INVALID_PARAMETER;
2827 }
2828 if ( pIoApicReg->pszSendMsiR0
2829 && !VALID_PTR(pIoApicReg->pszSendMsiR0))
2830 {
2831 Assert(VALID_PTR(pIoApicReg->pszSendMsiR0));
2832 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (GC callbacks)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2833 return VERR_INVALID_PARAMETER;
2834 }
2835 if (!ppIoApicHlpR3)
2836 {
2837 Assert(ppIoApicHlpR3);
2838 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (ppApicHlp)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2839 return VERR_INVALID_PARAMETER;
2840 }
2841
2842 /*
2843 * The I/O APIC requires the APIC to be present (hacks++).
2844 * If the I/O APIC does GC stuff so must the APIC.
2845 */
2846 PVM pVM = pDevIns->Internal.s.pVMR3;
2847 if (!pVM->pdm.s.Apic.pDevInsR3)
2848 {
2849 AssertMsgFailed(("Configuration error / Init order error! No APIC!\n"));
2850 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (no APIC)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2851 return VERR_INVALID_PARAMETER;
2852 }
2853 if ( pIoApicReg->pszSetIrqRC
2854 && !pVM->pdm.s.Apic.pDevInsRC)
2855 {
2856 AssertMsgFailed(("Configuration error! APIC doesn't do GC, I/O APIC does!\n"));
2857 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (no GC APIC)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2858 return VERR_INVALID_PARAMETER;
2859 }
2860
2861 /*
2862 * Only one I/O APIC device.
2863 */
2864 if (pVM->pdm.s.IoApic.pDevInsR3)
2865 {
2866 AssertMsgFailed(("Only one ioapic device is supported!\n"));
2867 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc (only one)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2868 return VERR_INVALID_PARAMETER;
2869 }
2870
2871 /*
2872 * Resolve & initialize the GC bits.
2873 */
2874 if (pIoApicReg->pszSetIrqRC)
2875 {
2876 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pIoApicReg->pszSetIrqRC, &pVM->pdm.s.IoApic.pfnSetIrqRC);
2877 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pIoApicReg->pszSetIrqRC, rc));
2878 if (RT_FAILURE(rc))
2879 {
2880 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2881 return rc;
2882 }
2883 pVM->pdm.s.IoApic.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2884 }
2885 else
2886 {
2887 pVM->pdm.s.IoApic.pDevInsRC = 0;
2888 pVM->pdm.s.IoApic.pfnSetIrqRC = 0;
2889 }
2890
2891 if (pIoApicReg->pszSendMsiRC)
2892 {
2893 int rc = pdmR3DevGetSymbolRCLazy(pDevIns, pIoApicReg->pszSetIrqRC, &pVM->pdm.s.IoApic.pfnSendMsiRC);
2894 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szRCMod, pIoApicReg->pszSendMsiRC, rc));
2895 if (RT_FAILURE(rc))
2896 {
2897 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2898 return rc;
2899 }
2900 }
2901 else
2902 {
2903 pVM->pdm.s.IoApic.pfnSendMsiRC = 0;
2904 }
2905
2906 /*
2907 * Resolve & initialize the R0 bits.
2908 */
2909 if (pIoApicReg->pszSetIrqR0)
2910 {
2911 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pIoApicReg->pszSetIrqR0, &pVM->pdm.s.IoApic.pfnSetIrqR0);
2912 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pIoApicReg->pszSetIrqR0, rc));
2913 if (RT_FAILURE(rc))
2914 {
2915 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2916 return rc;
2917 }
2918 pVM->pdm.s.IoApic.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2919 Assert(pVM->pdm.s.IoApic.pDevInsR0);
2920 }
2921 else
2922 {
2923 pVM->pdm.s.IoApic.pfnSetIrqR0 = 0;
2924 pVM->pdm.s.IoApic.pDevInsR0 = 0;
2925 }
2926
2927 if (pIoApicReg->pszSendMsiR0)
2928 {
2929 int rc = pdmR3DevGetSymbolR0Lazy(pDevIns, pIoApicReg->pszSetIrqR0, &pVM->pdm.s.IoApic.pfnSendMsiR0);
2930 AssertMsgRC(rc, ("%s::%s rc=%Rrc\n", pDevIns->pReg->szR0Mod, pIoApicReg->pszSendMsiR0, rc));
2931 if (RT_FAILURE(rc))
2932 {
2933 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
2934 return rc;
2935 }
2936 }
2937 else
2938 {
2939 pVM->pdm.s.IoApic.pfnSendMsiR0 = 0;
2940 }
2941
2942
2943 /*
2944 * Initialize the R3 bits.
2945 */
2946 pVM->pdm.s.IoApic.pDevInsR3 = pDevIns;
2947 pVM->pdm.s.IoApic.pfnSetIrqR3 = pIoApicReg->pfnSetIrqR3;
2948 pVM->pdm.s.IoApic.pfnSendMsiR3 = pIoApicReg->pfnSendMsiR3;
2949 Log(("PDM: Registered I/O APIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
2950
2951 /* set the helper pointer and return. */
2952 *ppIoApicHlpR3 = &g_pdmR3DevIoApicHlp;
2953 LogFlow(("pdmR3DevHlp_IOAPICRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2954 return VINF_SUCCESS;
2955}
2956
2957
2958/** @interface_method_impl{PDMDEVHLPR3,pfnHPETRegister} */
2959static DECLCALLBACK(int) pdmR3DevHlp_HPETRegister(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3)
2960{
2961 PDMDEV_ASSERT_DEVINS(pDevIns);
2962 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2963 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d:\n"));
2964
2965 /*
2966 * Validate input.
2967 */
2968 if (pHpetReg->u32Version != PDM_HPETREG_VERSION)
2969 {
2970 AssertMsgFailed(("u32Version=%#x expected %#x\n", pHpetReg->u32Version, PDM_HPETREG_VERSION));
2971 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2972 return VERR_INVALID_PARAMETER;
2973 }
2974
2975 if (!ppHpetHlpR3)
2976 {
2977 Assert(ppHpetHlpR3);
2978 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d: returns %Rrc (ppApicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
2979 return VERR_INVALID_PARAMETER;
2980 }
2981
2982 /* set the helper pointer and return. */
2983 *ppHpetHlpR3 = &g_pdmR3DevHpetHlp;
2984 LogFlow(("pdmR3DevHlp_HPETRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
2985 return VINF_SUCCESS;
2986}
2987
2988
2989/** @interface_method_impl{PDMDEVHLPR3,pfnPciRawRegister} */
2990static DECLCALLBACK(int) pdmR3DevHlp_PciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
2991{
2992 PDMDEV_ASSERT_DEVINS(pDevIns);
2993 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
2994 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d:\n"));
2995
2996 /*
2997 * Validate input.
2998 */
2999 if (pPciRawReg->u32Version != PDM_PCIRAWREG_VERSION)
3000 {
3001 AssertMsgFailed(("u32Version=%#x expected %#x\n", pPciRawReg->u32Version, PDM_PCIRAWREG_VERSION));
3002 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc (version)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3003 return VERR_INVALID_PARAMETER;
3004 }
3005
3006 if (!ppPciRawHlpR3)
3007 {
3008 Assert(ppPciRawHlpR3);
3009 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc (ppApicHlpR3)\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3010 return VERR_INVALID_PARAMETER;
3011 }
3012
3013 /* set the helper pointer and return. */
3014 *ppPciRawHlpR3 = &g_pdmR3DevPciRawHlp;
3015 LogFlow(("pdmR3DevHlp_PciRawRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS));
3016 return VINF_SUCCESS;
3017}
3018
3019
3020/** @interface_method_impl{PDMDEVHLPR3,pfnDMACRegister} */
3021static DECLCALLBACK(int) pdmR3DevHlp_DMACRegister(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp)
3022{
3023 PDMDEV_ASSERT_DEVINS(pDevIns);
3024 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3025 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",
3026 pDevIns->pReg->szName, pDevIns->iInstance, pDmacReg, pDmacReg->u32Version, pDmacReg->pfnRun, pDmacReg->pfnRegister,
3027 pDmacReg->pfnReadMemory, pDmacReg->pfnWriteMemory, pDmacReg->pfnSetDREQ, pDmacReg->pfnGetChannelMode, ppDmacHlp));
3028
3029 /*
3030 * Validate input.
3031 */
3032 if (pDmacReg->u32Version != PDM_DMACREG_VERSION)
3033 {
3034 AssertMsgFailed(("u32Version=%#x expected %#x\n", pDmacReg->u32Version,
3035 PDM_DMACREG_VERSION));
3036 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (version)\n",
3037 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3038 return VERR_INVALID_PARAMETER;
3039 }
3040 if ( !pDmacReg->pfnRun
3041 || !pDmacReg->pfnRegister
3042 || !pDmacReg->pfnReadMemory
3043 || !pDmacReg->pfnWriteMemory
3044 || !pDmacReg->pfnSetDREQ
3045 || !pDmacReg->pfnGetChannelMode)
3046 {
3047 Assert(pDmacReg->pfnRun);
3048 Assert(pDmacReg->pfnRegister);
3049 Assert(pDmacReg->pfnReadMemory);
3050 Assert(pDmacReg->pfnWriteMemory);
3051 Assert(pDmacReg->pfnSetDREQ);
3052 Assert(pDmacReg->pfnGetChannelMode);
3053 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (callbacks)\n",
3054 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3055 return VERR_INVALID_PARAMETER;
3056 }
3057
3058 if (!ppDmacHlp)
3059 {
3060 Assert(ppDmacHlp);
3061 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc (ppDmacHlp)\n",
3062 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3063 return VERR_INVALID_PARAMETER;
3064 }
3065
3066 /*
3067 * Only one DMA device.
3068 */
3069 PVM pVM = pDevIns->Internal.s.pVMR3;
3070 if (pVM->pdm.s.pDmac)
3071 {
3072 AssertMsgFailed(("Only one DMA device is supported!\n"));
3073 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n",
3074 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER));
3075 return VERR_INVALID_PARAMETER;
3076 }
3077
3078 /*
3079 * Allocate and initialize pci bus structure.
3080 */
3081 int rc = VINF_SUCCESS;
3082 PPDMDMAC pDmac = (PPDMDMAC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pDmac));
3083 if (pDmac)
3084 {
3085 pDmac->pDevIns = pDevIns;
3086 pDmac->Reg = *pDmacReg;
3087 pVM->pdm.s.pDmac = pDmac;
3088
3089 /* set the helper pointer. */
3090 *ppDmacHlp = &g_pdmR3DevDmacHlp;
3091 Log(("PDM: Registered DMAC device '%s'/%d pDevIns=%p\n",
3092 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns));
3093 }
3094 else
3095 rc = VERR_NO_MEMORY;
3096
3097 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n",
3098 pDevIns->pReg->szName, pDevIns->iInstance, rc));
3099 return rc;
3100}
3101
3102
3103/**
3104 * @copydoc PDMDEVHLPR3::pfnRegisterVMMDevHeap
3105 */
3106static DECLCALLBACK(int) pdmR3DevHlp_RegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize)
3107{
3108 PDMDEV_ASSERT_DEVINS(pDevIns);
3109 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3110
3111 int rc = PDMR3VmmDevHeapRegister(pDevIns->Internal.s.pVMR3, GCPhys, pvHeap, cbSize);
3112 return rc;
3113}
3114
3115
3116/**
3117 * @copydoc PDMDEVHLPR3::pfnUnregisterVMMDevHeap
3118 */
3119static DECLCALLBACK(int) pdmR3DevHlp_UnregisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys)
3120{
3121 PDMDEV_ASSERT_DEVINS(pDevIns);
3122 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3123
3124 int rc = PDMR3VmmDevHeapUnregister(pDevIns->Internal.s.pVMR3, GCPhys);
3125 return rc;
3126}
3127
3128
3129/** @interface_method_impl{PDMDEVHLPR3,pfnVMReset} */
3130static DECLCALLBACK(int) pdmR3DevHlp_VMReset(PPDMDEVINS pDevIns)
3131{
3132 PDMDEV_ASSERT_DEVINS(pDevIns);
3133 PVM pVM = pDevIns->Internal.s.pVMR3;
3134 VM_ASSERT_EMT(pVM);
3135 LogFlow(("pdmR3DevHlp_VMReset: caller='%s'/%d: VM_FF_RESET %d -> 1\n",
3136 pDevIns->pReg->szName, pDevIns->iInstance, VM_FF_ISSET(pVM, VM_FF_RESET)));
3137
3138 /*
3139 * We postpone this operation because we're likely to be inside a I/O instruction
3140 * and the EIP will be updated when we return.
3141 * We still return VINF_EM_RESET to break out of any execution loops and force FF evaluation.
3142 */
3143 bool fHaltOnReset;
3144 int rc = CFGMR3QueryBool(CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM"), "HaltOnReset", &fHaltOnReset);
3145 if (RT_SUCCESS(rc) && fHaltOnReset)
3146 {
3147 Log(("pdmR3DevHlp_VMReset: Halt On Reset!\n"));
3148 rc = VINF_EM_HALT;
3149 }
3150 else
3151 {
3152 VM_FF_SET(pVM, VM_FF_RESET);
3153 rc = VINF_EM_RESET;
3154 }
3155
3156 LogFlow(("pdmR3DevHlp_VMReset: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3157 return rc;
3158}
3159
3160
3161/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspend} */
3162static DECLCALLBACK(int) pdmR3DevHlp_VMSuspend(PPDMDEVINS pDevIns)
3163{
3164 int rc;
3165 PDMDEV_ASSERT_DEVINS(pDevIns);
3166 PVM pVM = pDevIns->Internal.s.pVMR3;
3167 VM_ASSERT_EMT(pVM);
3168 LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d:\n",
3169 pDevIns->pReg->szName, pDevIns->iInstance));
3170
3171 /** @todo Always take the SMP path - fewer code paths. */
3172 if (pVM->cCpus > 1)
3173 {
3174 /* We own the IOM lock here and could cause a deadlock by waiting for a VCPU that is blocking on the IOM lock. */
3175 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3Suspend, 1, pVM->pUVM);
3176 AssertRC(rc);
3177 rc = VINF_EM_SUSPEND;
3178 }
3179 else
3180 rc = VMR3Suspend(pVM->pUVM);
3181
3182 LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3183 return rc;
3184}
3185
3186
3187/**
3188 * Worker for pdmR3DevHlp_VMSuspendSaveAndPowerOff that is invoked via a queued
3189 * EMT request to avoid deadlocks.
3190 *
3191 * @returns VBox status code fit for scheduling.
3192 * @param pVM Pointer to the VM.
3193 * @param pDevIns The device that triggered this action.
3194 */
3195static DECLCALLBACK(int) pdmR3DevHlp_VMSuspendSaveAndPowerOffWorker(PVM pVM, PPDMDEVINS pDevIns)
3196{
3197 /*
3198 * Suspend the VM first then do the saving.
3199 */
3200 int rc = VMR3Suspend(pVM->pUVM);
3201 if (RT_SUCCESS(rc))
3202 {
3203 PUVM pUVM = pVM->pUVM;
3204 rc = pUVM->pVmm2UserMethods->pfnSaveState(pVM->pUVM->pVmm2UserMethods, pUVM);
3205
3206 /*
3207 * On success, power off the VM, on failure we'll leave it suspended.
3208 */
3209 if (RT_SUCCESS(rc))
3210 {
3211 rc = VMR3PowerOff(pVM->pUVM);
3212 if (RT_FAILURE(rc))
3213 LogRel(("%s/SSP: VMR3PowerOff failed: %Rrc\n", pDevIns->pReg->szName, rc));
3214 }
3215 else
3216 LogRel(("%s/SSP: pfnSaveState failed: %Rrc\n", pDevIns->pReg->szName, rc));
3217 }
3218 else
3219 LogRel(("%s/SSP: Suspend failed: %Rrc\n", pDevIns->pReg->szName, rc));
3220 return rc;
3221}
3222
3223
3224/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
3225static DECLCALLBACK(int) pdmR3DevHlp_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
3226{
3227 PDMDEV_ASSERT_DEVINS(pDevIns);
3228 PVM pVM = pDevIns->Internal.s.pVMR3;
3229 VM_ASSERT_EMT(pVM);
3230 LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d:\n",
3231 pDevIns->pReg->szName, pDevIns->iInstance));
3232
3233 int rc;
3234 if ( pVM->pUVM->pVmm2UserMethods
3235 && pVM->pUVM->pVmm2UserMethods->pfnSaveState)
3236 {
3237 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)pdmR3DevHlp_VMSuspendSaveAndPowerOffWorker, 2, pVM, pDevIns);
3238 if (RT_SUCCESS(rc))
3239 {
3240 LogRel(("%s: Suspending, Saving and Powering Off the VM\n", pDevIns->pReg->szName));
3241 rc = VINF_EM_SUSPEND;
3242 }
3243 }
3244 else
3245 rc = VERR_NOT_SUPPORTED;
3246
3247 LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3248 return rc;
3249}
3250
3251
3252/** @interface_method_impl{PDMDEVHLPR3,pfnVMPowerOff} */
3253static DECLCALLBACK(int) pdmR3DevHlp_VMPowerOff(PPDMDEVINS pDevIns)
3254{
3255 int rc;
3256 PDMDEV_ASSERT_DEVINS(pDevIns);
3257 PVM pVM = pDevIns->Internal.s.pVMR3;
3258 VM_ASSERT_EMT(pVM);
3259 LogFlow(("pdmR3DevHlp_VMPowerOff: caller='%s'/%d:\n",
3260 pDevIns->pReg->szName, pDevIns->iInstance));
3261
3262 /** @todo Always take the SMP path - fewer code paths. */
3263 if (pVM->cCpus > 1)
3264 {
3265 /* We own the IOM lock here and could cause a deadlock by waiting for a VCPU that is blocking on the IOM lock. */
3266 rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3PowerOff, 1, pVM->pUVM);
3267 AssertRC(rc);
3268 /* Set the VCPU state to stopped here as well to make sure no
3269 * inconsistency with the EM state occurs.
3270 */
3271 VMCPU_SET_STATE(VMMGetCpu(pVM), VMCPUSTATE_STOPPED);
3272 rc = VINF_EM_OFF;
3273 }
3274 else
3275 rc = VMR3PowerOff(pVM->pUVM);
3276
3277 LogFlow(("pdmR3DevHlp_VMPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
3278 return rc;
3279}
3280
3281
3282/** @interface_method_impl{PDMDEVHLPR3,pfnA20IsEnabled} */
3283static DECLCALLBACK(bool) pdmR3DevHlp_A20IsEnabled(PPDMDEVINS pDevIns)
3284{
3285 PDMDEV_ASSERT_DEVINS(pDevIns);
3286 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3287
3288 bool fRc = PGMPhysIsA20Enabled(VMMGetCpu(pDevIns->Internal.s.pVMR3));
3289
3290 LogFlow(("pdmR3DevHlp_A20IsEnabled: caller='%s'/%d: returns %d\n", pDevIns->pReg->szName, pDevIns->iInstance, fRc));
3291 return fRc;
3292}
3293
3294
3295/** @interface_method_impl{PDMDEVHLPR3,pfnA20Set} */
3296static DECLCALLBACK(void) pdmR3DevHlp_A20Set(PPDMDEVINS pDevIns, bool fEnable)
3297{
3298 PDMDEV_ASSERT_DEVINS(pDevIns);
3299 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3300 LogFlow(("pdmR3DevHlp_A20Set: caller='%s'/%d: fEnable=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, fEnable));
3301 PGMR3PhysSetA20(VMMGetCpu(pDevIns->Internal.s.pVMR3), fEnable);
3302}
3303
3304
3305/** @interface_method_impl{PDMDEVHLPR3,pfnGetCpuId} */
3306static DECLCALLBACK(void) pdmR3DevHlp_GetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf,
3307 uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
3308{
3309 PDMDEV_ASSERT_DEVINS(pDevIns);
3310 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
3311
3312 LogFlow(("pdmR3DevHlp_GetCpuId: caller='%s'/%d: iLeaf=%d pEax=%p pEbx=%p pEcx=%p pEdx=%p\n",
3313 pDevIns->pReg->szName, pDevIns->iInstance, iLeaf, pEax, pEbx, pEcx, pEdx));
3314 AssertPtr(pEax); AssertPtr(pEbx); AssertPtr(pEcx); AssertPtr(pEdx);
3315
3316 CPUMGetGuestCpuId(VMMGetCpu(pDevIns->Internal.s.pVMR3), iLeaf, pEax, pEbx, pEcx, pEdx);
3317
3318 LogFlow(("pdmR3DevHlp_GetCpuId: caller='%s'/%d: returns void - *pEax=%#x *pEbx=%#x *pEcx=%#x *pEdx=%#x\n",
3319 pDevIns->pReg->szName, pDevIns->iInstance, *pEax, *pEbx, *pEcx, *pEdx));
3320}
3321
3322
3323/**
3324 * The device helper structure for trusted devices.
3325 */
3326const PDMDEVHLPR3 g_pdmR3DevHlpTrusted =
3327{
3328 PDM_DEVHLPR3_VERSION,
3329 pdmR3DevHlp_IOPortRegister,
3330 pdmR3DevHlp_IOPortRegisterRC,
3331 pdmR3DevHlp_IOPortRegisterR0,
3332 pdmR3DevHlp_IOPortDeregister,
3333 pdmR3DevHlp_MMIORegister,
3334 pdmR3DevHlp_MMIORegisterRC,
3335 pdmR3DevHlp_MMIORegisterR0,
3336 pdmR3DevHlp_MMIODeregister,
3337 pdmR3DevHlp_MMIO2Register,
3338 pdmR3DevHlp_MMIO2Deregister,
3339 pdmR3DevHlp_MMIO2Map,
3340 pdmR3DevHlp_MMIO2Unmap,
3341 pdmR3DevHlp_MMHyperMapMMIO2,
3342 pdmR3DevHlp_MMIO2MapKernel,
3343 pdmR3DevHlp_ROMRegister,
3344 pdmR3DevHlp_ROMProtectShadow,
3345 pdmR3DevHlp_SSMRegister,
3346 pdmR3DevHlp_TMTimerCreate,
3347 pdmR3DevHlp_TMUtcNow,
3348 pdmR3DevHlp_PhysRead,
3349 pdmR3DevHlp_PhysWrite,
3350 pdmR3DevHlp_PhysGCPhys2CCPtr,
3351 pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
3352 pdmR3DevHlp_PhysReleasePageMappingLock,
3353 pdmR3DevHlp_PhysReadGCVirt,
3354 pdmR3DevHlp_PhysWriteGCVirt,
3355 pdmR3DevHlp_PhysGCPtr2GCPhys,
3356 pdmR3DevHlp_MMHeapAlloc,
3357 pdmR3DevHlp_MMHeapAllocZ,
3358 pdmR3DevHlp_MMHeapFree,
3359 pdmR3DevHlp_VMState,
3360 pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet,
3361 pdmR3DevHlp_VMSetError,
3362 pdmR3DevHlp_VMSetErrorV,
3363 pdmR3DevHlp_VMSetRuntimeError,
3364 pdmR3DevHlp_VMSetRuntimeErrorV,
3365 pdmR3DevHlp_DBGFStopV,
3366 pdmR3DevHlp_DBGFInfoRegister,
3367 pdmR3DevHlp_DBGFTraceBuf,
3368 pdmR3DevHlp_STAMRegister,
3369 pdmR3DevHlp_STAMRegisterF,
3370 pdmR3DevHlp_STAMRegisterV,
3371 pdmR3DevHlp_PCIPhysRead,
3372 pdmR3DevHlp_PCIPhysWrite,
3373 pdmR3DevHlp_PCIRegister,
3374 pdmR3DevHlp_PCIRegisterMsi,
3375 pdmR3DevHlp_PCIIORegionRegister,
3376 pdmR3DevHlp_PCISetConfigCallbacks,
3377 pdmR3DevHlp_PCISetIrq,
3378 pdmR3DevHlp_PCISetIrqNoWait,
3379 pdmR3DevHlp_ISASetIrq,
3380 pdmR3DevHlp_ISASetIrqNoWait,
3381 pdmR3DevHlp_DriverAttach,
3382 pdmR3DevHlp_QueueCreate,
3383 pdmR3DevHlp_CritSectInit,
3384 pdmR3DevHlp_CritSectGetNop,
3385 pdmR3DevHlp_CritSectGetNopR0,
3386 pdmR3DevHlp_CritSectGetNopRC,
3387 pdmR3DevHlp_SetDeviceCritSect,
3388 pdmR3DevHlp_ThreadCreate,
3389 pdmR3DevHlp_SetAsyncNotification,
3390 pdmR3DevHlp_AsyncNotificationCompleted,
3391 pdmR3DevHlp_RTCRegister,
3392 pdmR3DevHlp_PCIBusRegister,
3393 pdmR3DevHlp_PICRegister,
3394 pdmR3DevHlp_APICRegister,
3395 pdmR3DevHlp_IOAPICRegister,
3396 pdmR3DevHlp_HPETRegister,
3397 pdmR3DevHlp_PciRawRegister,
3398 pdmR3DevHlp_DMACRegister,
3399 pdmR3DevHlp_DMARegister,
3400 pdmR3DevHlp_DMAReadMemory,
3401 pdmR3DevHlp_DMAWriteMemory,
3402 pdmR3DevHlp_DMASetDREQ,
3403 pdmR3DevHlp_DMAGetChannelMode,
3404 pdmR3DevHlp_DMASchedule,
3405 pdmR3DevHlp_CMOSWrite,
3406 pdmR3DevHlp_CMOSRead,
3407 pdmR3DevHlp_AssertEMT,
3408 pdmR3DevHlp_AssertOther,
3409 pdmR3DevHlp_LdrGetRCInterfaceSymbols,
3410 pdmR3DevHlp_LdrGetR0InterfaceSymbols,
3411 pdmR3DevHlp_CallR0,
3412 0,
3413 0,
3414 0,
3415 0,
3416 0,
3417 0,
3418 0,
3419 0,
3420 0,
3421 pdmR3DevHlp_GetUVM,
3422 pdmR3DevHlp_GetVM,
3423 pdmR3DevHlp_GetVMCPU,
3424 pdmR3DevHlp_RegisterVMMDevHeap,
3425 pdmR3DevHlp_UnregisterVMMDevHeap,
3426 pdmR3DevHlp_VMReset,
3427 pdmR3DevHlp_VMSuspend,
3428 pdmR3DevHlp_VMSuspendSaveAndPowerOff,
3429 pdmR3DevHlp_VMPowerOff,
3430 pdmR3DevHlp_A20IsEnabled,
3431 pdmR3DevHlp_A20Set,
3432 pdmR3DevHlp_GetCpuId,
3433 pdmR3DevHlp_TMTimeVirtGet,
3434 pdmR3DevHlp_TMTimeVirtGetFreq,
3435 pdmR3DevHlp_TMTimeVirtGetNano,
3436 PDM_DEVHLPR3_VERSION /* the end */
3437};
3438
3439
3440
3441
3442/** @interface_method_impl{PDMDEVHLPR3,pfnGetUVM} */
3443static DECLCALLBACK(PUVM) pdmR3DevHlp_Untrusted_GetUVM(PPDMDEVINS pDevIns)
3444{
3445 PDMDEV_ASSERT_DEVINS(pDevIns);
3446 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3447 return NULL;
3448}
3449
3450
3451/** @interface_method_impl{PDMDEVHLPR3,pfnGetVM} */
3452static DECLCALLBACK(PVM) pdmR3DevHlp_Untrusted_GetVM(PPDMDEVINS pDevIns)
3453{
3454 PDMDEV_ASSERT_DEVINS(pDevIns);
3455 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3456 return NULL;
3457}
3458
3459
3460/** @interface_method_impl{PDMDEVHLPR3,pfnGetVMCPU} */
3461static DECLCALLBACK(PVMCPU) pdmR3DevHlp_Untrusted_GetVMCPU(PPDMDEVINS pDevIns)
3462{
3463 PDMDEV_ASSERT_DEVINS(pDevIns);
3464 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3465 return NULL;
3466}
3467
3468
3469/** @interface_method_impl{PDMDEVHLPR3,pfnRegisterVMMDevHeap} */
3470static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_RegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize)
3471{
3472 PDMDEV_ASSERT_DEVINS(pDevIns);
3473 NOREF(GCPhys); NOREF(pvHeap); NOREF(cbSize);
3474 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3475 return VERR_ACCESS_DENIED;
3476}
3477
3478
3479/** @interface_method_impl{PDMDEVHLPR3,pfnUnregisterVMMDevHeap} */
3480static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_UnregisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys)
3481{
3482 PDMDEV_ASSERT_DEVINS(pDevIns);
3483 NOREF(GCPhys);
3484 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3485 return VERR_ACCESS_DENIED;
3486}
3487
3488
3489/** @interface_method_impl{PDMDEVHLPR3,pfnVMReset} */
3490static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMReset(PPDMDEVINS pDevIns)
3491{
3492 PDMDEV_ASSERT_DEVINS(pDevIns);
3493 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3494 return VERR_ACCESS_DENIED;
3495}
3496
3497
3498/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspend} */
3499static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspend(PPDMDEVINS pDevIns)
3500{
3501 PDMDEV_ASSERT_DEVINS(pDevIns);
3502 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3503 return VERR_ACCESS_DENIED;
3504}
3505
3506
3507/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
3508static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
3509{
3510 PDMDEV_ASSERT_DEVINS(pDevIns);
3511 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3512 return VERR_ACCESS_DENIED;
3513}
3514
3515
3516/** @interface_method_impl{PDMDEVHLPR3,pfnVMPowerOff} */
3517static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMPowerOff(PPDMDEVINS pDevIns)
3518{
3519 PDMDEV_ASSERT_DEVINS(pDevIns);
3520 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3521 return VERR_ACCESS_DENIED;
3522}
3523
3524
3525/** @interface_method_impl{PDMDEVHLPR3,pfnA20IsEnabled} */
3526static DECLCALLBACK(bool) pdmR3DevHlp_Untrusted_A20IsEnabled(PPDMDEVINS pDevIns)
3527{
3528 PDMDEV_ASSERT_DEVINS(pDevIns);
3529 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3530 return false;
3531}
3532
3533
3534/** @interface_method_impl{PDMDEVHLPR3,pfnA20Set} */
3535static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_A20Set(PPDMDEVINS pDevIns, bool fEnable)
3536{
3537 PDMDEV_ASSERT_DEVINS(pDevIns);
3538 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3539 NOREF(fEnable);
3540}
3541
3542
3543/** @interface_method_impl{PDMDEVHLPR3,pfnGetCpuId} */
3544static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_GetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf,
3545 uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
3546{
3547 PDMDEV_ASSERT_DEVINS(pDevIns);
3548 NOREF(iLeaf); NOREF(pEax); NOREF(pEbx); NOREF(pEcx); NOREF(pEdx);
3549 AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
3550}
3551
3552
3553/**
3554 * The device helper structure for non-trusted devices.
3555 */
3556const PDMDEVHLPR3 g_pdmR3DevHlpUnTrusted =
3557{
3558 PDM_DEVHLPR3_VERSION,
3559 pdmR3DevHlp_IOPortRegister,
3560 pdmR3DevHlp_IOPortRegisterRC,
3561 pdmR3DevHlp_IOPortRegisterR0,
3562 pdmR3DevHlp_IOPortDeregister,
3563 pdmR3DevHlp_MMIORegister,
3564 pdmR3DevHlp_MMIORegisterRC,
3565 pdmR3DevHlp_MMIORegisterR0,
3566 pdmR3DevHlp_MMIODeregister,
3567 pdmR3DevHlp_MMIO2Register,
3568 pdmR3DevHlp_MMIO2Deregister,
3569 pdmR3DevHlp_MMIO2Map,
3570 pdmR3DevHlp_MMIO2Unmap,
3571 pdmR3DevHlp_MMHyperMapMMIO2,
3572 pdmR3DevHlp_MMIO2MapKernel,
3573 pdmR3DevHlp_ROMRegister,
3574 pdmR3DevHlp_ROMProtectShadow,
3575 pdmR3DevHlp_SSMRegister,
3576 pdmR3DevHlp_TMTimerCreate,
3577 pdmR3DevHlp_TMUtcNow,
3578 pdmR3DevHlp_PhysRead,
3579 pdmR3DevHlp_PhysWrite,
3580 pdmR3DevHlp_PhysGCPhys2CCPtr,
3581 pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
3582 pdmR3DevHlp_PhysReleasePageMappingLock,
3583 pdmR3DevHlp_PhysReadGCVirt,
3584 pdmR3DevHlp_PhysWriteGCVirt,
3585 pdmR3DevHlp_PhysGCPtr2GCPhys,
3586 pdmR3DevHlp_MMHeapAlloc,
3587 pdmR3DevHlp_MMHeapAllocZ,
3588 pdmR3DevHlp_MMHeapFree,
3589 pdmR3DevHlp_VMState,
3590 pdmR3DevHlp_VMTeleportedAndNotFullyResumedYet,
3591 pdmR3DevHlp_VMSetError,
3592 pdmR3DevHlp_VMSetErrorV,
3593 pdmR3DevHlp_VMSetRuntimeError,
3594 pdmR3DevHlp_VMSetRuntimeErrorV,
3595 pdmR3DevHlp_DBGFStopV,
3596 pdmR3DevHlp_DBGFInfoRegister,
3597 pdmR3DevHlp_DBGFTraceBuf,
3598 pdmR3DevHlp_STAMRegister,
3599 pdmR3DevHlp_STAMRegisterF,
3600 pdmR3DevHlp_STAMRegisterV,
3601 pdmR3DevHlp_PCIPhysRead,
3602 pdmR3DevHlp_PCIPhysWrite,
3603 pdmR3DevHlp_PCIRegister,
3604 pdmR3DevHlp_PCIRegisterMsi,
3605 pdmR3DevHlp_PCIIORegionRegister,
3606 pdmR3DevHlp_PCISetConfigCallbacks,
3607 pdmR3DevHlp_PCISetIrq,
3608 pdmR3DevHlp_PCISetIrqNoWait,
3609 pdmR3DevHlp_ISASetIrq,
3610 pdmR3DevHlp_ISASetIrqNoWait,
3611 pdmR3DevHlp_DriverAttach,
3612 pdmR3DevHlp_QueueCreate,
3613 pdmR3DevHlp_CritSectInit,
3614 pdmR3DevHlp_CritSectGetNop,
3615 pdmR3DevHlp_CritSectGetNopR0,
3616 pdmR3DevHlp_CritSectGetNopRC,
3617 pdmR3DevHlp_SetDeviceCritSect,
3618 pdmR3DevHlp_ThreadCreate,
3619 pdmR3DevHlp_SetAsyncNotification,
3620 pdmR3DevHlp_AsyncNotificationCompleted,
3621 pdmR3DevHlp_RTCRegister,
3622 pdmR3DevHlp_PCIBusRegister,
3623 pdmR3DevHlp_PICRegister,
3624 pdmR3DevHlp_APICRegister,
3625 pdmR3DevHlp_IOAPICRegister,
3626 pdmR3DevHlp_HPETRegister,
3627 pdmR3DevHlp_PciRawRegister,
3628 pdmR3DevHlp_DMACRegister,
3629 pdmR3DevHlp_DMARegister,
3630 pdmR3DevHlp_DMAReadMemory,
3631 pdmR3DevHlp_DMAWriteMemory,
3632 pdmR3DevHlp_DMASetDREQ,
3633 pdmR3DevHlp_DMAGetChannelMode,
3634 pdmR3DevHlp_DMASchedule,
3635 pdmR3DevHlp_CMOSWrite,
3636 pdmR3DevHlp_CMOSRead,
3637 pdmR3DevHlp_AssertEMT,
3638 pdmR3DevHlp_AssertOther,
3639 pdmR3DevHlp_LdrGetRCInterfaceSymbols,
3640 pdmR3DevHlp_LdrGetR0InterfaceSymbols,
3641 pdmR3DevHlp_CallR0,
3642 0,
3643 0,
3644 0,
3645 0,
3646 0,
3647 0,
3648 0,
3649 0,
3650 0,
3651 pdmR3DevHlp_Untrusted_GetUVM,
3652 pdmR3DevHlp_Untrusted_GetVM,
3653 pdmR3DevHlp_Untrusted_GetVMCPU,
3654 pdmR3DevHlp_Untrusted_RegisterVMMDevHeap,
3655 pdmR3DevHlp_Untrusted_UnregisterVMMDevHeap,
3656 pdmR3DevHlp_Untrusted_VMReset,
3657 pdmR3DevHlp_Untrusted_VMSuspend,
3658 pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff,
3659 pdmR3DevHlp_Untrusted_VMPowerOff,
3660 pdmR3DevHlp_Untrusted_A20IsEnabled,
3661 pdmR3DevHlp_Untrusted_A20Set,
3662 pdmR3DevHlp_Untrusted_GetCpuId,
3663 pdmR3DevHlp_TMTimeVirtGet,
3664 pdmR3DevHlp_TMTimeVirtGetFreq,
3665 pdmR3DevHlp_TMTimeVirtGetNano,
3666 PDM_DEVHLPR3_VERSION /* the end */
3667};
3668
3669
3670
3671/**
3672 * Queue consumer callback for internal component.
3673 *
3674 * @returns Success indicator.
3675 * If false the item will not be removed and the flushing will stop.
3676 * @param pVM Pointer to the VM.
3677 * @param pItem The item to consume. Upon return this item will be freed.
3678 */
3679DECLCALLBACK(bool) pdmR3DevHlpQueueConsumer(PVM pVM, PPDMQUEUEITEMCORE pItem)
3680{
3681 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)pItem;
3682 LogFlow(("pdmR3DevHlpQueueConsumer: enmOp=%d pDevIns=%p\n", pTask->enmOp, pTask->pDevInsR3));
3683 switch (pTask->enmOp)
3684 {
3685 case PDMDEVHLPTASKOP_ISA_SET_IRQ:
3686 PDMIsaSetIrq(pVM, pTask->u.SetIRQ.iIrq, pTask->u.SetIRQ.iLevel, pTask->u.SetIRQ.uTagSrc);
3687 break;
3688
3689 case PDMDEVHLPTASKOP_PCI_SET_IRQ:
3690 {
3691 /* Same as pdmR3DevHlp_PCISetIrq, except we've got a tag already. */
3692 PPDMDEVINS pDevIns = pTask->pDevInsR3;
3693 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceR3;
3694 if (pPciDev)
3695 {
3696 PPDMPCIBUS pBus = pDevIns->Internal.s.pPciBusR3; /** @todo the bus should be associated with the PCI device not the PDM device. */
3697 Assert(pBus);
3698
3699 pdmLock(pVM);
3700 pBus->pfnSetIrqR3(pBus->pDevInsR3, pPciDev, pTask->u.SetIRQ.iIrq,
3701 pTask->u.SetIRQ.iLevel, pTask->u.SetIRQ.uTagSrc);
3702 pdmUnlock(pVM);
3703 }
3704 else
3705 AssertReleaseMsgFailed(("No PCI device registered!\n"));
3706 break;
3707 }
3708
3709 case PDMDEVHLPTASKOP_IOAPIC_SET_IRQ:
3710 PDMIoApicSetIrq(pVM, pTask->u.SetIRQ.iIrq, pTask->u.SetIRQ.iLevel, pTask->u.SetIRQ.uTagSrc);
3711 break;
3712
3713 default:
3714 AssertReleaseMsgFailed(("Invalid operation %d\n", pTask->enmOp));
3715 break;
3716 }
3717 return true;
3718}
3719
3720/** @} */
3721
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