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