VirtualBox

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

Last change on this file since 58600 was 58126, checked in by vboxsync, 9 years ago

VMM: Fixed almost all the Doxygen warnings.

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