1 | /* $Id: PDMGCDevice.cpp 18101 2009-03-19 22:39:06Z 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 | * Global Variables *
|
---|
43 | *******************************************************************************/
|
---|
44 | __BEGIN_DECLS
|
---|
45 | extern DECLEXPORT(const PDMDEVHLPRC) g_pdmRCDevHlp;
|
---|
46 | extern DECLEXPORT(const PDMPICHLPRC) g_pdmRCPicHlp;
|
---|
47 | extern DECLEXPORT(const PDMAPICHLPRC) g_pdmRCApicHlp;
|
---|
48 | extern DECLEXPORT(const PDMIOAPICHLPRC) g_pdmRCIoApicHlp;
|
---|
49 | extern DECLEXPORT(const PDMPCIHLPRC) g_pdmRCPciHlp;
|
---|
50 | __END_DECLS
|
---|
51 |
|
---|
52 |
|
---|
53 | /*******************************************************************************
|
---|
54 | * Internal Functions *
|
---|
55 | *******************************************************************************/
|
---|
56 | /** @name GC Device Helpers
|
---|
57 | * @{
|
---|
58 | */
|
---|
59 | static DECLCALLBACK(void) pdmGCDevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
60 | static DECLCALLBACK(void) pdmGCDevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
61 | static DECLCALLBACK(int) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
|
---|
62 | static DECLCALLBACK(int) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
|
---|
63 | static DECLCALLBACK(bool) pdmGCDevHlp_A20IsEnabled(PPDMDEVINS pDevIns);
|
---|
64 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
|
---|
65 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va);
|
---|
66 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...);
|
---|
67 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va);
|
---|
68 | static DECLCALLBACK(int) pdmGCDevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData);
|
---|
69 | static DECLCALLBACK(PVM) pdmGCDevHlp_GetVM(PPDMDEVINS pDevIns);
|
---|
70 | /** @} */
|
---|
71 |
|
---|
72 |
|
---|
73 | /** @name PIC GC Helpers
|
---|
74 | * @{
|
---|
75 | */
|
---|
76 | static DECLCALLBACK(void) pdmRCPicHlp_SetInterruptFF(PPDMDEVINS pDevIns);
|
---|
77 | static DECLCALLBACK(void) pdmRCPicHlp_ClearInterruptFF(PPDMDEVINS pDevIns);
|
---|
78 | static DECLCALLBACK(int) pdmRCPicHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
79 | static DECLCALLBACK(void) pdmRCPicHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
80 | /** @} */
|
---|
81 |
|
---|
82 |
|
---|
83 | /** @name APIC RC Helpers
|
---|
84 | * @{
|
---|
85 | */
|
---|
86 | static DECLCALLBACK(void) pdmRCApicHlp_SetInterruptFF(PPDMDEVINS pDevIns, VMCPUID idCpu);
|
---|
87 | static DECLCALLBACK(void) pdmRCApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns, VMCPUID idCpu);
|
---|
88 | static DECLCALLBACK(void) pdmRCApicHlp_ChangeFeature(PPDMDEVINS pDevIns, PDMAPICVERSION enmVersion);
|
---|
89 | static DECLCALLBACK(int) pdmRCApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
90 | static DECLCALLBACK(void) pdmRCApicHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
91 | static DECLCALLBACK(VMCPUID) pdmRCApicHlp_GetCpuId(PPDMDEVINS pDevIns);
|
---|
92 | /** @} */
|
---|
93 |
|
---|
94 |
|
---|
95 | /** @name I/O APIC RC Helpers
|
---|
96 | * @{
|
---|
97 | */
|
---|
98 | static DECLCALLBACK(void) pdmRCIoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
|
---|
99 | uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode);
|
---|
100 | static DECLCALLBACK(int) pdmRCIoApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
101 | static DECLCALLBACK(void) pdmRCIoApicHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
102 | /** @} */
|
---|
103 |
|
---|
104 |
|
---|
105 | /** @name PCI Bus RC Helpers
|
---|
106 | * @{
|
---|
107 | */
|
---|
108 | static DECLCALLBACK(void) pdmRCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
109 | static DECLCALLBACK(void) pdmRCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
|
---|
110 | static DECLCALLBACK(int) pdmRCPciHlp_Lock(PPDMDEVINS pDevIns, int rc);
|
---|
111 | static DECLCALLBACK(void) pdmRCPciHlp_Unlock(PPDMDEVINS pDevIns);
|
---|
112 | /** @} */
|
---|
113 |
|
---|
114 |
|
---|
115 | static void pdmGCIsaSetIrq(PVM pVM, int iIrq, int iLevel);
|
---|
116 | static void pdmGCIoApicSetIrq(PVM pVM, int iIrq, int iLevel);
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * The Guest Context Device Helper Callbacks.
|
---|
122 | */
|
---|
123 | extern DECLEXPORT(const PDMDEVHLPRC) g_pdmRCDevHlp =
|
---|
124 | {
|
---|
125 | PDM_DEVHLPRC_VERSION,
|
---|
126 | pdmGCDevHlp_PCISetIrq,
|
---|
127 | pdmGCDevHlp_ISASetIrq,
|
---|
128 | pdmGCDevHlp_PhysRead,
|
---|
129 | pdmGCDevHlp_PhysWrite,
|
---|
130 | pdmGCDevHlp_A20IsEnabled,
|
---|
131 | pdmGCDevHlp_VMSetError,
|
---|
132 | pdmGCDevHlp_VMSetErrorV,
|
---|
133 | pdmGCDevHlp_VMSetRuntimeError,
|
---|
134 | pdmGCDevHlp_VMSetRuntimeErrorV,
|
---|
135 | pdmGCDevHlp_PATMSetMMIOPatchInfo,
|
---|
136 | pdmGCDevHlp_GetVM,
|
---|
137 | PDM_DEVHLPRC_VERSION
|
---|
138 | };
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * The Raw-Mode Context PIC Helper Callbacks.
|
---|
142 | */
|
---|
143 | extern DECLEXPORT(const PDMPICHLPRC) g_pdmRCPicHlp =
|
---|
144 | {
|
---|
145 | PDM_PICHLPRC_VERSION,
|
---|
146 | pdmRCPicHlp_SetInterruptFF,
|
---|
147 | pdmRCPicHlp_ClearInterruptFF,
|
---|
148 | pdmRCPicHlp_Lock,
|
---|
149 | pdmRCPicHlp_Unlock,
|
---|
150 | PDM_PICHLPRC_VERSION
|
---|
151 | };
|
---|
152 |
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * The Raw-Mode Context APIC Helper Callbacks.
|
---|
156 | */
|
---|
157 | extern DECLEXPORT(const PDMAPICHLPRC) g_pdmRCApicHlp =
|
---|
158 | {
|
---|
159 | PDM_APICHLPRC_VERSION,
|
---|
160 | pdmRCApicHlp_SetInterruptFF,
|
---|
161 | pdmRCApicHlp_ClearInterruptFF,
|
---|
162 | pdmRCApicHlp_ChangeFeature,
|
---|
163 | pdmRCApicHlp_Lock,
|
---|
164 | pdmRCApicHlp_Unlock,
|
---|
165 | pdmRCApicHlp_GetCpuId,
|
---|
166 | PDM_APICHLPRC_VERSION
|
---|
167 | };
|
---|
168 |
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * The Raw-Mode Context I/O APIC Helper Callbacks.
|
---|
172 | */
|
---|
173 | extern DECLEXPORT(const PDMIOAPICHLPRC) g_pdmRCIoApicHlp =
|
---|
174 | {
|
---|
175 | PDM_IOAPICHLPRC_VERSION,
|
---|
176 | pdmRCIoApicHlp_ApicBusDeliver,
|
---|
177 | pdmRCIoApicHlp_Lock,
|
---|
178 | pdmRCIoApicHlp_Unlock,
|
---|
179 | PDM_IOAPICHLPRC_VERSION
|
---|
180 | };
|
---|
181 |
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * The Raw-Mode Context PCI Bus Helper Callbacks.
|
---|
185 | */
|
---|
186 | extern DECLEXPORT(const PDMPCIHLPRC) g_pdmRCPciHlp =
|
---|
187 | {
|
---|
188 | PDM_PCIHLPRC_VERSION,
|
---|
189 | pdmRCPciHlp_IsaSetIrq,
|
---|
190 | pdmRCPciHlp_IoApicSetIrq,
|
---|
191 | pdmRCPciHlp_Lock,
|
---|
192 | pdmRCPciHlp_Unlock,
|
---|
193 | PDM_PCIHLPRC_VERSION, /* the end */
|
---|
194 | };
|
---|
195 |
|
---|
196 |
|
---|
197 |
|
---|
198 |
|
---|
199 | /** @copydoc PDMDEVHLPRC::pfnPCISetIrq */
|
---|
200 | static DECLCALLBACK(void) pdmGCDevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
201 | {
|
---|
202 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
203 | LogFlow(("pdmGCDevHlp_PCISetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
|
---|
204 |
|
---|
205 | PVM pVM = pDevIns->Internal.s.pVMRC;
|
---|
206 | PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceRC;
|
---|
207 | PPDMPCIBUS pPciBus = pDevIns->Internal.s.pPciBusRC;
|
---|
208 | if ( pPciDev
|
---|
209 | && pPciBus
|
---|
210 | && pPciBus->pDevInsRC)
|
---|
211 | {
|
---|
212 | pdmLock(pVM);
|
---|
213 | pPciBus->pfnSetIrqRC(pPciBus->pDevInsRC, pPciDev, iIrq, iLevel);
|
---|
214 | pdmUnlock(pVM);
|
---|
215 | }
|
---|
216 | else
|
---|
217 | {
|
---|
218 | /* queue for ring-3 execution. */
|
---|
219 | PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
|
---|
220 | if (pTask)
|
---|
221 | {
|
---|
222 | pTask->enmOp = PDMDEVHLPTASKOP_PCI_SET_IRQ;
|
---|
223 | pTask->pDevInsR3 = PDMDEVINS_2_R3PTR(pDevIns);
|
---|
224 | pTask->u.SetIRQ.iIrq = iIrq;
|
---|
225 | pTask->u.SetIRQ.iLevel = iLevel;
|
---|
226 |
|
---|
227 | PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
|
---|
228 | }
|
---|
229 | else
|
---|
230 | AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
|
---|
231 | }
|
---|
232 |
|
---|
233 | LogFlow(("pdmGCDevHlp_PCISetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | /** @copydoc PDMDEVHLPRC::pfnPCISetIrq */
|
---|
238 | static DECLCALLBACK(void) pdmGCDevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
239 | {
|
---|
240 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
241 | LogFlow(("pdmGCDevHlp_ISASetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
|
---|
242 |
|
---|
243 | pdmGCIsaSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
|
---|
244 |
|
---|
245 | LogFlow(("pdmGCDevHlp_ISASetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 | /** @copydoc PDMDEVHLPRC::pfnPhysRead */
|
---|
250 | static DECLCALLBACK(int) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
|
---|
251 | {
|
---|
252 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
253 | LogFlow(("pdmGCDevHlp_PhysRead: caller=%p/%d: GCPhys=%RGp pvBuf=%p cbRead=%#x\n",
|
---|
254 | pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbRead));
|
---|
255 |
|
---|
256 | #ifdef VBOX_WITH_NEW_PHYS_CODE
|
---|
257 | int rc = PGMPhysRead(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbRead);
|
---|
258 | AssertRC(rc); /** @todo track down the users for this bugger. */
|
---|
259 | #else
|
---|
260 | PGMPhysRead(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbRead);
|
---|
261 | int rc = VINF_SUCCESS;
|
---|
262 | #endif
|
---|
263 |
|
---|
264 | Log(("pdmGCDevHlp_PhysRead: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
|
---|
265 | return rc;
|
---|
266 | }
|
---|
267 |
|
---|
268 |
|
---|
269 | /** @copydoc PDMDEVHLPRC::pfnPhysWrite */
|
---|
270 | static DECLCALLBACK(int) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
|
---|
271 | {
|
---|
272 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
273 | LogFlow(("pdmGCDevHlp_PhysWrite: caller=%p/%d: GCPhys=%RGp pvBuf=%p cbWrite=%#x\n",
|
---|
274 | pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbWrite));
|
---|
275 |
|
---|
276 | #ifdef VBOX_WITH_NEW_PHYS_CODE
|
---|
277 | int rc = PGMPhysWrite(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbWrite);
|
---|
278 | AssertRC(rc); /** @todo track down the users for this bugger. */
|
---|
279 | #else
|
---|
280 | PGMPhysWrite(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbWrite);
|
---|
281 | int rc = VINF_SUCCESS;
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | Log(("pdmGCDevHlp_PhysWrite: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
|
---|
285 | return rc;
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|
289 | /** @copydoc PDMDEVHLPRC::pfnA20IsEnabled */
|
---|
290 | static DECLCALLBACK(bool) pdmGCDevHlp_A20IsEnabled(PPDMDEVINS pDevIns)
|
---|
291 | {
|
---|
292 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
293 | LogFlow(("pdmGCDevHlp_A20IsEnabled: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
|
---|
294 |
|
---|
295 | bool fEnabled = PGMPhysIsA20Enabled(pDevIns->Internal.s.pVMRC);
|
---|
296 |
|
---|
297 | Log(("pdmGCDevHlp_A20IsEnabled: caller=%p/%d: returns %RTbool\n", pDevIns, pDevIns->iInstance, fEnabled));
|
---|
298 | return fEnabled;
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | /** @copydoc PDMDEVHLPRC::pfnVMSetError */
|
---|
303 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
|
---|
304 | {
|
---|
305 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
306 | va_list args;
|
---|
307 | va_start(args, pszFormat);
|
---|
308 | int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMRC, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
|
---|
309 | va_end(args);
|
---|
310 | return rc;
|
---|
311 | }
|
---|
312 |
|
---|
313 |
|
---|
314 | /** @copydoc PDMDEVHLPRC::pfnVMSetErrorV */
|
---|
315 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
|
---|
316 | {
|
---|
317 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
318 | int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMRC, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
|
---|
319 | return rc;
|
---|
320 | }
|
---|
321 |
|
---|
322 |
|
---|
323 | /** @copydoc PDMDEVHLPRC::pfnVMSetRuntimeError */
|
---|
324 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
|
---|
325 | {
|
---|
326 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
327 | va_list args;
|
---|
328 | va_start(args, pszFormat);
|
---|
329 | int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMRC, fFatal, pszErrorID, pszFormat, args);
|
---|
330 | va_end(args);
|
---|
331 | return rc;
|
---|
332 | }
|
---|
333 |
|
---|
334 |
|
---|
335 | /** @copydoc PDMDEVHLPRC::pfnVMSetErrorV */
|
---|
336 | static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va)
|
---|
337 | {
|
---|
338 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
339 | int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMRC, fFatal, pszErrorID, pszFormat, va);
|
---|
340 | return rc;
|
---|
341 | }
|
---|
342 |
|
---|
343 |
|
---|
344 | /** @copydoc PDMDEVHLPRC::pfnPATMSetMMIOPatchInfo */
|
---|
345 | static DECLCALLBACK(int) pdmGCDevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData)
|
---|
346 | {
|
---|
347 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
348 | LogFlow(("pdmGCDevHlp_PATMSetMMIOPatchInfo: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
|
---|
349 |
|
---|
350 | return PATMSetMMIOPatchInfo(pDevIns->Internal.s.pVMRC, GCPhys, (RTRCPTR)pCachedData);
|
---|
351 | }
|
---|
352 |
|
---|
353 |
|
---|
354 | /** @copydoc PDMDEVHLPRC::pfnGetVM */
|
---|
355 | static DECLCALLBACK(PVM) pdmGCDevHlp_GetVM(PPDMDEVINS pDevIns)
|
---|
356 | {
|
---|
357 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
358 | LogFlow(("pdmGCDevHlp_GetVM: caller='%p'/%d\n", pDevIns, pDevIns->iInstance));
|
---|
359 | return pDevIns->Internal.s.pVMRC;
|
---|
360 | }
|
---|
361 |
|
---|
362 |
|
---|
363 |
|
---|
364 |
|
---|
365 | /** @copydoc PDMPICHLPGC::pfnSetInterruptFF */
|
---|
366 | static DECLCALLBACK(void) pdmRCPicHlp_SetInterruptFF(PPDMDEVINS pDevIns)
|
---|
367 | {
|
---|
368 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
369 | LogFlow(("pdmRCPicHlp_SetInterruptFF: caller=%p/%d: VM_FF_INTERRUPT_PIC %d -> 1\n",
|
---|
370 | pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pDevIns->Internal.s.pVMRC, 0, VM_FF_INTERRUPT_PIC)));
|
---|
371 | /* for PIC we always deliver to CPU 0, MP use APIC */
|
---|
372 | VMCPU_FF_SET(pDevIns->Internal.s.pVMRC, 0, VM_FF_INTERRUPT_PIC);
|
---|
373 | }
|
---|
374 |
|
---|
375 |
|
---|
376 | /** @copydoc PDMPICHLPGC::pfnClearInterruptFF */
|
---|
377 | static DECLCALLBACK(void) pdmRCPicHlp_ClearInterruptFF(PPDMDEVINS pDevIns)
|
---|
378 | {
|
---|
379 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
380 | LogFlow(("pdmRCPicHlp_ClearInterruptFF: caller=%p/%d: VM_FF_INTERRUPT_PIC %d -> 0\n",
|
---|
381 | pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pDevIns->Internal.s.pVMRC, 0, VM_FF_INTERRUPT_PIC)));
|
---|
382 | /* for PIC we always deliver to CPU 0, MP use APIC */
|
---|
383 | VMCPU_FF_CLEAR(pDevIns->Internal.s.pVMRC, 0, VM_FF_INTERRUPT_PIC);
|
---|
384 | }
|
---|
385 |
|
---|
386 |
|
---|
387 | /** @copydoc PDMPICHLPGC::pfnLock */
|
---|
388 | static DECLCALLBACK(int) pdmRCPicHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
389 | {
|
---|
390 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
391 | return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
|
---|
392 | }
|
---|
393 |
|
---|
394 |
|
---|
395 | /** @copydoc PDMPICHLPGC::pfnUnlock */
|
---|
396 | static DECLCALLBACK(void) pdmRCPicHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
397 | {
|
---|
398 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
399 | pdmUnlock(pDevIns->Internal.s.pVMRC);
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 |
|
---|
404 |
|
---|
405 | /** @copydoc PDMAPICHLPRC::pfnSetInterruptFF */
|
---|
406 | static DECLCALLBACK(void) pdmRCApicHlp_SetInterruptFF(PPDMDEVINS pDevIns, VMCPUID idCpu)
|
---|
407 | {
|
---|
408 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
409 | LogFlow(("pdmRCApicHlp_SetInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 1\n",
|
---|
410 | pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pDevIns->Internal.s.pVMRC, idCpu, VM_FF_INTERRUPT_APIC)));
|
---|
411 | VMCPU_FF_SET(pDevIns->Internal.s.pVMRC, idCpu, VM_FF_INTERRUPT_APIC);
|
---|
412 | }
|
---|
413 |
|
---|
414 |
|
---|
415 | /** @copydoc PDMAPICHLPRC::pfnClearInterruptFF */
|
---|
416 | static DECLCALLBACK(void) pdmRCApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns, VMCPUID idCpu)
|
---|
417 | {
|
---|
418 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
419 | LogFlow(("pdmRCApicHlp_ClearInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 0\n",
|
---|
420 | pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pDevIns->Internal.s.pVMRC, idCpu, VM_FF_INTERRUPT_APIC)));
|
---|
421 | VMCPU_FF_CLEAR(pDevIns->Internal.s.pVMRC, idCpu, VM_FF_INTERRUPT_APIC);
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | /** @copydoc PDMAPICHLPRC::pfnChangeFeature */
|
---|
426 | static DECLCALLBACK(void) pdmRCApicHlp_ChangeFeature(PPDMDEVINS pDevIns, PDMAPICVERSION enmVersion)
|
---|
427 | {
|
---|
428 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
429 | LogFlow(("pdmRCApicHlp_ChangeFeature: caller=%p/%d: version=%d\n", pDevIns, pDevIns->iInstance, (int)enmVersion));
|
---|
430 | switch (enmVersion)
|
---|
431 | {
|
---|
432 | case PDMAPICVERSION_NONE:
|
---|
433 | CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_APIC);
|
---|
434 | CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_X2APIC);
|
---|
435 | break;
|
---|
436 | case PDMAPICVERSION_APIC:
|
---|
437 | CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_APIC);
|
---|
438 | CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_X2APIC);
|
---|
439 | break;
|
---|
440 | case PDMAPICVERSION_X2APIC:
|
---|
441 | CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_X2APIC);
|
---|
442 | CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_APIC);
|
---|
443 | break;
|
---|
444 | default:
|
---|
445 | AssertMsgFailed(("Unknown APIC version: %d\n", (int)enmVersion));
|
---|
446 | }
|
---|
447 | }
|
---|
448 |
|
---|
449 |
|
---|
450 | /** @copydoc PDMAPICHLPRC::pfnLock */
|
---|
451 | static DECLCALLBACK(int) pdmRCApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
452 | {
|
---|
453 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
454 | return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | /** @copydoc PDMAPICHLPRC::pfnUnlock */
|
---|
459 | static DECLCALLBACK(void) pdmRCApicHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
460 | {
|
---|
461 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
462 | pdmUnlock(pDevIns->Internal.s.pVMRC);
|
---|
463 | }
|
---|
464 |
|
---|
465 |
|
---|
466 | /** @copydoc PDMAPICHLPRC::pfnGetCpuId */
|
---|
467 | static DECLCALLBACK(VMCPUID) pdmRCApicHlp_GetCpuId(PPDMDEVINS pDevIns)
|
---|
468 | {
|
---|
469 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
470 | return VMMGetCpuId(pDevIns->Internal.s.pVMRC);
|
---|
471 | }
|
---|
472 |
|
---|
473 | /** @copydoc PDMIOAPICHLPRC::pfnApicBusDeliver */
|
---|
474 | static DECLCALLBACK(void) pdmRCIoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
|
---|
475 | uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode)
|
---|
476 | {
|
---|
477 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
478 | PVM pVM = pDevIns->Internal.s.pVMRC;
|
---|
479 | LogFlow(("pdmRCIoApicHlp_ApicBusDeliver: caller=%p/%d: u8Dest=%RX8 u8DestMode=%RX8 u8DeliveryMode=%RX8 iVector=%RX8 u8Polarity=%RX8 u8TriggerMode=%RX8\n",
|
---|
480 | pDevIns, pDevIns->iInstance, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode));
|
---|
481 | if (pVM->pdm.s.Apic.pfnBusDeliverRC)
|
---|
482 | pVM->pdm.s.Apic.pfnBusDeliverRC(pVM->pdm.s.Apic.pDevInsRC, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode);
|
---|
483 | }
|
---|
484 |
|
---|
485 |
|
---|
486 | /** @copydoc PDMIOAPICHLPRC::pfnLock */
|
---|
487 | static DECLCALLBACK(int) pdmRCIoApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
488 | {
|
---|
489 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
490 | return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
|
---|
491 | }
|
---|
492 |
|
---|
493 |
|
---|
494 | /** @copydoc PDMIOAPICHLPRC::pfnUnlock */
|
---|
495 | static DECLCALLBACK(void) pdmRCIoApicHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
496 | {
|
---|
497 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
498 | pdmUnlock(pDevIns->Internal.s.pVMRC);
|
---|
499 | }
|
---|
500 |
|
---|
501 |
|
---|
502 |
|
---|
503 |
|
---|
504 | /** @copydoc PDMPCIHLPRC::pfnIsaSetIrq */
|
---|
505 | static DECLCALLBACK(void) pdmRCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
506 | {
|
---|
507 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
508 | Log4(("pdmRCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
|
---|
509 | pdmGCIsaSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
|
---|
510 | }
|
---|
511 |
|
---|
512 |
|
---|
513 | /** @copydoc PDMPCIHLPRC::pfnIoApicSetIrq */
|
---|
514 | static DECLCALLBACK(void) pdmRCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
515 | {
|
---|
516 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
517 | Log4(("pdmRCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
|
---|
518 | pdmGCIoApicSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
|
---|
519 | }
|
---|
520 |
|
---|
521 |
|
---|
522 | /** @copydoc PDMPCIHLPRC::pfnLock */
|
---|
523 | static DECLCALLBACK(int) pdmRCPciHlp_Lock(PPDMDEVINS pDevIns, int rc)
|
---|
524 | {
|
---|
525 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
526 | return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
|
---|
527 | }
|
---|
528 |
|
---|
529 |
|
---|
530 | /** @copydoc PDMPCIHLPRC::pfnUnlock */
|
---|
531 | static DECLCALLBACK(void) pdmRCPciHlp_Unlock(PPDMDEVINS pDevIns)
|
---|
532 | {
|
---|
533 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
534 | pdmUnlock(pDevIns->Internal.s.pVMRC);
|
---|
535 | }
|
---|
536 |
|
---|
537 |
|
---|
538 |
|
---|
539 |
|
---|
540 | /**
|
---|
541 | * Sets an irq on the I/O APIC.
|
---|
542 | *
|
---|
543 | * @param pVM The VM handle.
|
---|
544 | * @param iIrq The irq.
|
---|
545 | * @param iLevel The new level.
|
---|
546 | */
|
---|
547 | static void pdmGCIsaSetIrq(PVM pVM, int iIrq, int iLevel)
|
---|
548 | {
|
---|
549 | if ( ( pVM->pdm.s.IoApic.pDevInsRC
|
---|
550 | || !pVM->pdm.s.IoApic.pDevInsR3)
|
---|
551 | && ( pVM->pdm.s.Pic.pDevInsRC
|
---|
552 | || !pVM->pdm.s.Pic.pDevInsR3))
|
---|
553 | {
|
---|
554 | pdmLock(pVM);
|
---|
555 | if (pVM->pdm.s.Pic.pDevInsRC)
|
---|
556 | pVM->pdm.s.Pic.pfnSetIrqRC(pVM->pdm.s.Pic.pDevInsRC, iIrq, iLevel);
|
---|
557 | if (pVM->pdm.s.IoApic.pDevInsRC)
|
---|
558 | pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel);
|
---|
559 | pdmUnlock(pVM);
|
---|
560 | }
|
---|
561 | else
|
---|
562 | {
|
---|
563 | /* queue for ring-3 execution. */
|
---|
564 | PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
|
---|
565 | if (pTask)
|
---|
566 | {
|
---|
567 | pTask->enmOp = PDMDEVHLPTASKOP_ISA_SET_IRQ;
|
---|
568 | pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
|
---|
569 | pTask->u.SetIRQ.iIrq = iIrq;
|
---|
570 | pTask->u.SetIRQ.iLevel = iLevel;
|
---|
571 |
|
---|
572 | PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
|
---|
573 | }
|
---|
574 | else
|
---|
575 | AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
|
---|
576 | }
|
---|
577 | }
|
---|
578 |
|
---|
579 |
|
---|
580 | /**
|
---|
581 | * Sets an irq on the I/O APIC.
|
---|
582 | *
|
---|
583 | * @param pVM The VM handle.
|
---|
584 | * @param iIrq The irq.
|
---|
585 | * @param iLevel The new level.
|
---|
586 | */
|
---|
587 | static void pdmGCIoApicSetIrq(PVM pVM, int iIrq, int iLevel)
|
---|
588 | {
|
---|
589 | if (pVM->pdm.s.IoApic.pDevInsRC)
|
---|
590 | {
|
---|
591 | pdmLock(pVM);
|
---|
592 | pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel);
|
---|
593 | pdmUnlock(pVM);
|
---|
594 | }
|
---|
595 | else if (pVM->pdm.s.IoApic.pDevInsR3)
|
---|
596 | {
|
---|
597 | /* queue for ring-3 execution. */
|
---|
598 | PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
|
---|
599 | if (pTask)
|
---|
600 | {
|
---|
601 | pTask->enmOp = PDMDEVHLPTASKOP_IOAPIC_SET_IRQ;
|
---|
602 | pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
|
---|
603 | pTask->u.SetIRQ.iIrq = iIrq;
|
---|
604 | pTask->u.SetIRQ.iLevel = iLevel;
|
---|
605 |
|
---|
606 | PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
|
---|
607 | }
|
---|
608 | else
|
---|
609 | AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
|
---|
610 | }
|
---|
611 | }
|
---|