VirtualBox

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

Last change on this file since 33980 was 33799, checked in by vboxsync, 14 years ago

PDM: Added DevHelps to query virtual time without requiring a timer.

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