1 | /* $Id: PDMGCDevice.cpp 8155 2008-04-18 15:16:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM - Pluggable Device and Driver Manager, GC Device parts.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP LOG_GROUP_PDM_DEVICE
|
---|
27 | #include "PDMInternal.h"
|
---|
28 | #include <VBox/pdm.h>
|
---|
29 | #include <VBox/pgm.h>
|
---|
30 | #include <VBox/mm.h>
|
---|
31 | #include <VBox/vm.h>
|
---|
32 | #include <VBox/patm.h>
|
---|
33 |
|
---|
34 | #include <VBox/log.h>
|
---|
35 | #include <VBox/err.h>
|
---|
36 | #include <iprt/asm.h>
|
---|
37 | #include <iprt/assert.h>
|
---|
38 | #include <iprt/string.h>
|
---|
39 |
|
---|
40 |
|
---|
41 | /*******************************************************************************
|
---|
42 | * Defined Constants And Macros *
|
---|
43 | *******************************************************************************/
|
---|
44 | /** @def PDMDEV_ASSERT_DEVINS
|
---|
45 | * Asserts the validity of the driver instance.
|
---|
46 | */
|
---|
47 | #ifdef VBOX_STRICT
|
---|
48 | # define PDMDEV_ASSERT_DEVINS(pDevIns) do { Assert(VALID_PTR(pDevIns)); \
|
---|
49 | Assert(pDevIns->u32Version == PDM_DEVINS_VERSION); \
|
---|
50 | Assert(pDevIns->pvInstanceDataGC == (void *)&pDevIns->achInstanceData[0]); \
|
---|
51 | } while (0)
|
---|
52 | #else
|
---|
53 | # define PDMDEV_ASSERT_DEVINS(pDevIns) do { } while (0)
|
---|
54 | #endif
|
---|
55 |
|
---|
56 |
|
---|
57 | /*******************************************************************************
|
---|
58 | * Global Variables *
|
---|
59 | *******************************************************************************/
|
---|
60 | __BEGIN_DECLS
|
---|
61 | extern DECLEXPORT(const PDMDEVHLPGC) g_pdmGCDevHlp;
|
---|
62 | extern DECLEXPORT(const PDMPICHLPGC) g_pdmGCPicHlp;
|
---|
63 | extern DECLEXPORT(const PDMAPICHLPGC) g_pdmGCApicHlp;
|
---|
64 | extern DECLEXPORT(const PDMIOAPICHLPGC) g_pdmGCIoApicHlp;
|
---|
65 | extern DECLEXPORT(const PDMPCIHLPGC) g_pdmGCPciHlp;
|
---|
66 | __END_DECLS
|
---|
67 |
|
---|
68 |
|
---|
69 | /*******************************************************************************
|
---|
70 | * Internal Functions *
|
---|
71 | *******************************************************************************/
|
---|
72 | /** @name GC Device Helpers
|
---|
73 | * @{
|
---|
74 | */
|
---|
75 | static DECLCALLBACK(void) pdmGCDevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
76 | static DECLCALLBACK(void) pdmGCDevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
77 | static DECLCALLBACK(void) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
|
---|
78 | static DECLCALLBACK(void) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
|
---|
79 | static DECLCALLBACK(bool) pdmGCDevHlp_A20IsEnabled(PPDMDEVINS pDevIns);
|
---|
80 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
|
---|
81 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va);
|
---|
82 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...);
|
---|
83 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va);
|
---|
84 | static DECLCALLBACK(int) pdmGCDevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData);
|
---|
85 | /** @} */
|
---|
86 |
|
---|
87 |
|
---|
88 | /** @name PIC GC Helpers
|
---|
89 | * @{
|
---|
90 | */
|
---|
91 | static DECLCALLBACK(void) pdmGCPicHlp_SetInterruptFF(PPDMDEVINS pDevIns);
|
---|
92 | static DECLCALLBACK(void) pdmGCPicHlp_ClearInterruptFF(PPDMDEVINS pDevIns);
|
---|
93 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
94 | static DECLCALLBACK(int) pdmGCPicHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
95 | static DECLCALLBACK(void) pdmGCPicHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
96 | #endif
|
---|
97 | /** @} */
|
---|
98 |
|
---|
99 |
|
---|
100 | /** @name APIC GC Helpers
|
---|
101 | * @{
|
---|
102 | */
|
---|
103 | static DECLCALLBACK(void) pdmGCApicHlp_SetInterruptFF(PPDMDEVINS pDevIns);
|
---|
104 | static DECLCALLBACK(void) pdmGCApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns);
|
---|
105 | static DECLCALLBACK(void) pdmGCApicHlp_ChangeFeature(PPDMDEVINS pDevIns, bool fEnabled);
|
---|
106 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
107 | static DECLCALLBACK(int) pdmGCApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
108 | static DECLCALLBACK(void) pdmGCApicHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
109 | #endif
|
---|
110 | /** @} */
|
---|
111 |
|
---|
112 |
|
---|
113 | /** @name I/O APIC GC Helpers
|
---|
114 | * @{
|
---|
115 | */
|
---|
116 | static DECLCALLBACK(void) pdmGCIoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
|
---|
117 | uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode);
|
---|
118 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
119 | static DECLCALLBACK(int) pdmGCIoApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
120 | static DECLCALLBACK(void) pdmGCIoApicHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
121 | #endif
|
---|
122 | /** @} */
|
---|
123 |
|
---|
124 |
|
---|
125 | /** @name PCI Bus GC Helpers
|
---|
126 | * @{
|
---|
127 | */
|
---|
128 | static DECLCALLBACK(void) pdmGCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
129 | static DECLCALLBACK(void) pdmGCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
130 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
131 | static DECLCALLBACK(int) pdmGCPciHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
132 | static DECLCALLBACK(void) pdmGCPciHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
133 | #endif
|
---|
134 | /** @} */
|
---|
135 |
|
---|
136 |
|
---|
137 | static void pdmGCIsaSetIrq(PVM pVM, int iIrq, int iLevel);
|
---|
138 | static void pdmGCIoApicSetIrq(PVM pVM, int iIrq, int iLevel);
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * The Guest Context Device Helper Callbacks.
|
---|
144 | */
|
---|
145 | extern DECLEXPORT(const PDMDEVHLPGC) g_pdmGCDevHlp =
|
---|
146 | {
|
---|
147 | PDM_DEVHLPGC_VERSION,
|
---|
148 | pdmGCDevHlp_PCISetIrq,
|
---|
149 | pdmGCDevHlp_ISASetIrq,
|
---|
150 | pdmGCDevHlp_PhysRead,
|
---|
151 | pdmGCDevHlp_PhysWrite,
|
---|
152 | pdmGCDevHlp_A20IsEnabled,
|
---|
153 | pdmGCDevHlp_VMSetError,
|
---|
154 | pdmGCDevHlp_VMSetErrorV,
|
---|
155 | pdmGCDevHlp_VMSetRuntimeError,
|
---|
156 | pdmGCDevHlp_VMSetRuntimeErrorV,
|
---|
157 | pdmGCDevHlp_PATMSetMMIOPatchInfo,
|
---|
158 | PDM_DEVHLPGC_VERSION
|
---|
159 | };
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * The Guest Context PIC Helper Callbacks.
|
---|
163 | */
|
---|
164 | extern DECLEXPORT(const PDMPICHLPGC) g_pdmGCPicHlp =
|
---|
165 | {
|
---|
166 | PDM_PICHLPGC_VERSION,
|
---|
167 | pdmGCPicHlp_SetInterruptFF,
|
---|
168 | pdmGCPicHlp_ClearInterruptFF,
|
---|
169 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
170 | pdmGCPicHlp_Lock,
|
---|
171 | pdmGCPicHlp_Unlock,
|
---|
172 | #endif
|
---|
173 | PDM_PICHLPGC_VERSION
|
---|
174 | };
|
---|
175 |
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * The Guest Context APIC Helper Callbacks.
|
---|
179 | */
|
---|
180 | extern DECLEXPORT(const PDMAPICHLPGC) g_pdmGCApicHlp =
|
---|
181 | {
|
---|
182 | PDM_APICHLPGC_VERSION,
|
---|
183 | pdmGCApicHlp_SetInterruptFF,
|
---|
184 | pdmGCApicHlp_ClearInterruptFF,
|
---|
185 | pdmGCApicHlp_ChangeFeature,
|
---|
186 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
187 | pdmGCApicHlp_Lock,
|
---|
188 | pdmGCApicHlp_Unlock,
|
---|
189 | #endif
|
---|
190 | PDM_APICHLPGC_VERSION
|
---|
191 | };
|
---|
192 |
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * The Guest Context I/O APIC Helper Callbacks.
|
---|
196 | */
|
---|
197 | extern DECLEXPORT(const PDMIOAPICHLPGC) g_pdmGCIoApicHlp =
|
---|
198 | {
|
---|
199 | PDM_IOAPICHLPGC_VERSION,
|
---|
200 | pdmGCIoApicHlp_ApicBusDeliver,
|
---|
201 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
202 | pdmGCIoApicHlp_Lock,
|
---|
203 | pdmGCIoApicHlp_Unlock,
|
---|
204 | #endif
|
---|
205 | PDM_IOAPICHLPGC_VERSION
|
---|
206 | };
|
---|
207 |
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * The Guest Context PCI Bus Helper Callbacks.
|
---|
211 | */
|
---|
212 | extern DECLEXPORT(const PDMPCIHLPGC) g_pdmGCPciHlp =
|
---|
213 | {
|
---|
214 | PDM_PCIHLPGC_VERSION,
|
---|
215 | pdmGCPciHlp_IsaSetIrq,
|
---|
216 | pdmGCPciHlp_IoApicSetIrq,
|
---|
217 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
218 | pdmGCPciHlp_Lock,
|
---|
219 | pdmGCPciHlp_Unlock,
|
---|
220 | #endif
|
---|
221 | PDM_PCIHLPGC_VERSION, /* the end */
|
---|
222 | };
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 |
|
---|
227 | /** @copydoc PDMDEVHLPGC::pfnPCISetIrq */
|
---|
228 | static DECLCALLBACK(void) pdmGCDevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
229 | {
|
---|
230 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
231 | LogFlow(("pdmGCDevHlp_PCISetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
|
---|
232 |
|
---|
233 | PVM pVM = pDevIns->Internal.s.pVMGC;
|
---|
234 | PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceGC;
|
---|
235 | PPDMPCIBUS pPciBus = pDevIns->Internal.s.pPciBusGC;
|
---|
236 | if ( pPciDev
|
---|
237 | && pPciBus
|
---|
238 | && pPciBus->pDevInsGC)
|
---|
239 | {
|
---|
240 | pdmLock(pVM);
|
---|
241 | pPciBus->pfnSetIrqGC(pPciBus->pDevInsGC, pPciDev, iIrq, iLevel);
|
---|
242 | pdmUnlock(pVM);
|
---|
243 | }
|
---|
244 | else
|
---|
245 | {
|
---|
246 | /* queue for ring-3 execution. */
|
---|
247 | PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueGC);
|
---|
248 | if (pTask)
|
---|
249 | {
|
---|
250 | pTask->enmOp = PDMDEVHLPTASKOP_PCI_SET_IRQ;
|
---|
251 | pTask->pDevInsHC = MMHyperGC2HC(pVM, pDevIns);
|
---|
252 | pTask->u.SetIRQ.iIrq = iIrq;
|
---|
253 | pTask->u.SetIRQ.iLevel = iLevel;
|
---|
254 |
|
---|
255 | PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueGC, &pTask->Core, 0);
|
---|
256 | }
|
---|
257 | else
|
---|
258 | AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
|
---|
259 | }
|
---|
260 |
|
---|
261 | LogFlow(("pdmGCDevHlp_PCISetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | /** @copydoc PDMDEVHLPGC::pfnPCISetIrq */
|
---|
266 | static DECLCALLBACK(void) pdmGCDevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
267 | {
|
---|
268 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
269 | LogFlow(("pdmGCDevHlp_ISASetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
|
---|
270 |
|
---|
271 | pdmGCIsaSetIrq(pDevIns->Internal.s.pVMGC, iIrq, iLevel);
|
---|
272 |
|
---|
273 | LogFlow(("pdmGCDevHlp_ISASetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | /** @copydoc PDMDEVHLPGC::pfnPhysRead */
|
---|
278 | static DECLCALLBACK(void) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
|
---|
279 | {
|
---|
280 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
281 | LogFlow(("pdmGCDevHlp_PhysRead: caller=%p/%d: GCPhys=%VGp pvBuf=%p cbRead=%#x\n",
|
---|
282 | pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbRead));
|
---|
283 |
|
---|
284 | PGMPhysRead(pDevIns->Internal.s.pVMGC, GCPhys, pvBuf, cbRead);
|
---|
285 |
|
---|
286 | Log(("pdmGCDevHlp_PhysRead: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | /** @copydoc PDMDEVHLPGC::pfnPhysWrite */
|
---|
291 | static DECLCALLBACK(void) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
|
---|
292 | {
|
---|
293 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
294 | LogFlow(("pdmGCDevHlp_PhysWrite: caller=%p/%d: GCPhys=%VGp pvBuf=%p cbWrite=%#x\n",
|
---|
295 | pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbWrite));
|
---|
296 |
|
---|
297 | PGMPhysWrite(pDevIns->Internal.s.pVMGC, GCPhys, pvBuf, cbWrite);
|
---|
298 |
|
---|
299 | Log(("pdmGCDevHlp_PhysWrite: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | /** @copydoc PDMDEVHLPGC::pfnA20IsEnabled */
|
---|
304 | static DECLCALLBACK(bool) pdmGCDevHlp_A20IsEnabled(PPDMDEVINS pDevIns)
|
---|
305 | {
|
---|
306 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
307 | LogFlow(("pdmGCDevHlp_A20IsEnabled: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
|
---|
308 |
|
---|
309 | bool fEnabled = PGMPhysIsA20Enabled(pDevIns->Internal.s.pVMGC);
|
---|
310 |
|
---|
311 | Log(("pdmGCDevHlp_A20IsEnabled: caller=%p/%d: returns %RTbool\n", pDevIns, pDevIns->iInstance, fEnabled));
|
---|
312 | return fEnabled;
|
---|
313 | }
|
---|
314 |
|
---|
315 |
|
---|
316 | /** @copydoc PDMDEVHLPGC::pfnVMSetError */
|
---|
317 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
|
---|
318 | {
|
---|
319 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
320 | va_list args;
|
---|
321 | va_start(args, pszFormat);
|
---|
322 | int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMGC, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
|
---|
323 | va_end(args);
|
---|
324 | return rc;
|
---|
325 | }
|
---|
326 |
|
---|
327 |
|
---|
328 | /** @copydoc PDMDEVHLPGC::pfnVMSetErrorV */
|
---|
329 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
|
---|
330 | {
|
---|
331 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
332 | int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMGC, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
|
---|
333 | return rc;
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | /** @copydoc PDMDEVHLPGC::pfnVMSetRuntimeError */
|
---|
338 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
|
---|
339 | {
|
---|
340 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
341 | va_list args;
|
---|
342 | va_start(args, pszFormat);
|
---|
343 | int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMGC, fFatal, pszErrorID, pszFormat, args);
|
---|
344 | va_end(args);
|
---|
345 | return rc;
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | /** @copydoc PDMDEVHLPGC::pfnVMSetErrorV */
|
---|
350 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va)
|
---|
351 | {
|
---|
352 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
353 | int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMGC, fFatal, pszErrorID, pszFormat, va);
|
---|
354 | return rc;
|
---|
355 | }
|
---|
356 |
|
---|
357 |
|
---|
358 | /** @copydoc PDMDEVHLPGC::pdmGCDevHlp_PATMSetMMIOPatchInfo */
|
---|
359 | static DECLCALLBACK(int) pdmGCDevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData)
|
---|
360 | {
|
---|
361 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
362 | LogFlow(("pdmGCDevHlp_PATMSetMMIOPatchInfo: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
|
---|
363 |
|
---|
364 | return PATMSetMMIOPatchInfo(pDevIns->Internal.s.pVMGC, GCPhys, pCachedData);
|
---|
365 | }
|
---|
366 |
|
---|
367 |
|
---|
368 |
|
---|
369 |
|
---|
370 | /** @copydoc PDMPICHLPGC::pfnSetInterruptFF */
|
---|
371 | static DECLCALLBACK(void) pdmGCPicHlp_SetInterruptFF(PPDMDEVINS pDevIns)
|
---|
372 | {
|
---|
373 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
374 | LogFlow(("pdmGCPicHlp_SetInterruptFF: caller=%p/%d: VM_FF_INTERRUPT_PIC %d -> 1\n",
|
---|
375 | pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_PIC)));
|
---|
376 | VM_FF_SET(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_PIC);
|
---|
377 | }
|
---|
378 |
|
---|
379 |
|
---|
380 | /** @copydoc PDMPICHLPGC::pfnClearInterruptFF */
|
---|
381 | static DECLCALLBACK(void) pdmGCPicHlp_ClearInterruptFF(PPDMDEVINS pDevIns)
|
---|
382 | {
|
---|
383 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
384 | LogFlow(("pdmGCPicHlp_ClearInterruptFF: caller=%p/%d: VM_FF_INTERRUPT_PIC %d -> 0\n",
|
---|
385 | pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_PIC)));
|
---|
386 | VM_FF_CLEAR(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_PIC);
|
---|
387 | }
|
---|
388 |
|
---|
389 |
|
---|
390 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
391 | /** @copydoc PDMPICHLPGC::pfnLock */
|
---|
392 | static DECLCALLBACK(int) pdmGCPicHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
393 | {
|
---|
394 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
395 | return pdmLockEx(pDevIns->Internal.s.pVMGC, rc);
|
---|
396 | }
|
---|
397 |
|
---|
398 |
|
---|
399 | /** @copydoc PDMPICHLPGC::pfnUnlock */
|
---|
400 | static DECLCALLBACK(void) pdmGCPicHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
401 | {
|
---|
402 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
403 | pdmUnlock(pDevIns->Internal.s.pVMGC);
|
---|
404 | }
|
---|
405 | #endif /* VBOX_WITH_PDM_LOCK */
|
---|
406 |
|
---|
407 |
|
---|
408 |
|
---|
409 |
|
---|
410 | /** @copydoc PDMAPICHLPGC::pfnSetInterruptFF */
|
---|
411 | static DECLCALLBACK(void) pdmGCApicHlp_SetInterruptFF(PPDMDEVINS pDevIns)
|
---|
412 | {
|
---|
413 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
414 | LogFlow(("pdmGCApicHlp_SetInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 1\n",
|
---|
415 | pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_APIC)));
|
---|
416 | VM_FF_SET(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_APIC);
|
---|
417 | }
|
---|
418 |
|
---|
419 |
|
---|
420 | /** @copydoc PDMAPICHLPGC::pfnClearInterruptFF */
|
---|
421 | static DECLCALLBACK(void) pdmGCApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns)
|
---|
422 | {
|
---|
423 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
424 | LogFlow(("pdmGCApicHlp_ClearInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 0\n",
|
---|
425 | pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_APIC)));
|
---|
426 | VM_FF_CLEAR(pDevIns->Internal.s.pVMGC, VM_FF_INTERRUPT_APIC);
|
---|
427 | }
|
---|
428 |
|
---|
429 |
|
---|
430 | /** @copydoc PDMAPICHLPGC::pfnChangeFeature */
|
---|
431 | static DECLCALLBACK(void) pdmGCApicHlp_ChangeFeature(PPDMDEVINS pDevIns, bool fEnabled)
|
---|
432 | {
|
---|
433 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
434 | LogFlow(("pdmGCApicHlp_ChangeFeature: caller=%p/%d: fEnabled=%RTbool\n", pDevIns, pDevIns->iInstance, fEnabled));
|
---|
435 | if (fEnabled)
|
---|
436 | CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMGC, CPUMCPUIDFEATURE_APIC);
|
---|
437 | else
|
---|
438 | CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMGC, CPUMCPUIDFEATURE_APIC);
|
---|
439 | }
|
---|
440 |
|
---|
441 |
|
---|
442 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
443 | /** @copydoc PDMAPICHLPGC::pfnLock */
|
---|
444 | static DECLCALLBACK(int) pdmGCApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
445 | {
|
---|
446 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
447 | return pdmLockEx(pDevIns->Internal.s.pVMGC, rc);
|
---|
448 | }
|
---|
449 |
|
---|
450 |
|
---|
451 | /** @copydoc PDMAPICHLPGC::pfnUnlock */
|
---|
452 | static DECLCALLBACK(void) pdmGCApicHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
453 | {
|
---|
454 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
455 | pdmUnlock(pDevIns->Internal.s.pVMGC);
|
---|
456 | }
|
---|
457 | #endif /* VBOX_WITH_PDM_LOCK */
|
---|
458 |
|
---|
459 |
|
---|
460 |
|
---|
461 |
|
---|
462 | /** @copydoc PDMIOAPICHLPGC::pfnApicBusDeliver */
|
---|
463 | static DECLCALLBACK(void) pdmGCIoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
|
---|
464 | uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode)
|
---|
465 | {
|
---|
466 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
467 | PVM pVM = pDevIns->Internal.s.pVMGC;
|
---|
468 | LogFlow(("pdmGCIoApicHlp_ApicBusDeliver: caller=%p/%d: u8Dest=%RX8 u8DestMode=%RX8 u8DeliveryMode=%RX8 iVector=%RX8 u8Polarity=%RX8 u8TriggerMode=%RX8\n",
|
---|
469 | pDevIns, pDevIns->iInstance, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode));
|
---|
470 | if (pVM->pdm.s.Apic.pfnBusDeliverGC)
|
---|
471 | pVM->pdm.s.Apic.pfnBusDeliverGC(pVM->pdm.s.Apic.pDevInsGC, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode);
|
---|
472 | }
|
---|
473 |
|
---|
474 |
|
---|
475 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
476 | /** @copydoc PDMIOAPICHLPGC::pfnLock */
|
---|
477 | static DECLCALLBACK(int) pdmGCIoApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
478 | {
|
---|
479 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
480 | return pdmLockEx(pDevIns->Internal.s.pVMGC, rc);
|
---|
481 | }
|
---|
482 |
|
---|
483 |
|
---|
484 | /** @copydoc PDMIOAPICHLPGC::pfnUnlock */
|
---|
485 | static DECLCALLBACK(void) pdmGCIoApicHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
486 | {
|
---|
487 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
488 | pdmUnlock(pDevIns->Internal.s.pVMGC);
|
---|
489 | }
|
---|
490 | #endif /* VBOX_WITH_PDM_LOCK */
|
---|
491 |
|
---|
492 |
|
---|
493 |
|
---|
494 |
|
---|
495 | /** @copydoc PDMPCIHLPGC::pfnIsaSetIrq */
|
---|
496 | static DECLCALLBACK(void) pdmGCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
497 | {
|
---|
498 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
499 | Log4(("pdmGCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
|
---|
500 | pdmGCIsaSetIrq(pDevIns->Internal.s.pVMGC, iIrq, iLevel);
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 | /** @copydoc PDMPCIHLPGC::pfnIoApicSetIrq */
|
---|
505 | static DECLCALLBACK(void) pdmGCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
506 | {
|
---|
507 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
508 | Log4(("pdmGCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
|
---|
509 | pdmGCIoApicSetIrq(pDevIns->Internal.s.pVMGC, iIrq, iLevel);
|
---|
510 | }
|
---|
511 |
|
---|
512 |
|
---|
513 | #ifdef VBOX_WITH_PDM_LOCK
|
---|
514 | /** @copydoc PDMPCIHLPGC::pfnLock */
|
---|
515 | static DECLCALLBACK(int) pdmGCPciHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
516 | {
|
---|
517 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
518 | return pdmLockEx(pDevIns->Internal.s.pVMGC, rc);
|
---|
519 | }
|
---|
520 |
|
---|
521 |
|
---|
522 | /** @copydoc PDMPCIHLPGC::pfnUnlock */
|
---|
523 | static DECLCALLBACK(void) pdmGCPciHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
524 | {
|
---|
525 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
526 | pdmUnlock(pDevIns->Internal.s.pVMGC);
|
---|
527 | }
|
---|
528 | #endif /* VBOX_WITH_PDM_LOCK */
|
---|
529 |
|
---|
530 |
|
---|
531 |
|
---|
532 |
|
---|
533 | /**
|
---|
534 | * Sets an irq on the I/O APIC.
|
---|
535 | *
|
---|
536 | * @param pVM The VM handle.
|
---|
537 | * @param iIrq The irq.
|
---|
538 | * @param iLevel The new level.
|
---|
539 | */
|
---|
540 | static void pdmGCIsaSetIrq(PVM pVM, int iIrq, int iLevel)
|
---|
541 | {
|
---|
542 | if ( ( pVM->pdm.s.IoApic.pDevInsGC
|
---|
543 | || !pVM->pdm.s.IoApic.pDevInsR3)
|
---|
544 | && ( pVM->pdm.s.Pic.pDevInsGC
|
---|
545 | || !pVM->pdm.s.Pic.pDevInsR3))
|
---|
546 | {
|
---|
547 | pdmLock(pVM);
|
---|
548 | if (pVM->pdm.s.Pic.pDevInsGC)
|
---|
549 | pVM->pdm.s.Pic.pfnSetIrqGC(pVM->pdm.s.Pic.pDevInsGC, iIrq, iLevel);
|
---|
550 | if (pVM->pdm.s.IoApic.pDevInsGC)
|
---|
551 | pVM->pdm.s.IoApic.pfnSetIrqGC(pVM->pdm.s.IoApic.pDevInsGC, iIrq, iLevel);
|
---|
552 | pdmUnlock(pVM);
|
---|
553 | }
|
---|
554 | else
|
---|
555 | {
|
---|
556 | /* queue for ring-3 execution. */
|
---|
557 | PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueGC);
|
---|
558 | if (pTask)
|
---|
559 | {
|
---|
560 | pTask->enmOp = PDMDEVHLPTASKOP_ISA_SET_IRQ;
|
---|
561 | pTask->pDevInsHC = 0; /* not required */
|
---|
562 | pTask->u.SetIRQ.iIrq = iIrq;
|
---|
563 | pTask->u.SetIRQ.iLevel = iLevel;
|
---|
564 |
|
---|
565 | PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueGC, &pTask->Core, 0);
|
---|
566 | }
|
---|
567 | else
|
---|
568 | AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
|
---|
569 | }
|
---|
570 | }
|
---|
571 |
|
---|
572 |
|
---|
573 | /**
|
---|
574 | * Sets an irq on the I/O APIC.
|
---|
575 | *
|
---|
576 | * @param pVM The VM handle.
|
---|
577 | * @param iIrq The irq.
|
---|
578 | * @param iLevel The new level.
|
---|
579 | */
|
---|
580 | static void pdmGCIoApicSetIrq(PVM pVM, int iIrq, int iLevel)
|
---|
581 | {
|
---|
582 | if (pVM->pdm.s.IoApic.pDevInsGC)
|
---|
583 | {
|
---|
584 | pdmLock(pVM);
|
---|
585 | pVM->pdm.s.IoApic.pfnSetIrqGC(pVM->pdm.s.IoApic.pDevInsGC, iIrq, iLevel);
|
---|
586 | pdmUnlock(pVM);
|
---|
587 | }
|
---|
588 | else if (pVM->pdm.s.IoApic.pDevInsR3)
|
---|
589 | {
|
---|
590 | /* queue for ring-3 execution. */
|
---|
591 | PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueGC);
|
---|
592 | if (pTask)
|
---|
593 | {
|
---|
594 | pTask->enmOp = PDMDEVHLPTASKOP_IOAPIC_SET_IRQ;
|
---|
595 | pTask->pDevInsHC = 0; /* not required */
|
---|
596 | pTask->u.SetIRQ.iIrq = iIrq;
|
---|
597 | pTask->u.SetIRQ.iLevel = iLevel;
|
---|
598 |
|
---|
599 | PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueGC, &pTask->Core, 0);
|
---|
600 | }
|
---|
601 | else
|
---|
602 | AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
|
---|
603 | }
|
---|
604 | }
|
---|