VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMGC/PDMGCDevice.cpp@ 4041

Last change on this file since 4041 was 3112, checked in by vboxsync, 17 years ago

Added full set of runtime error functions to PDM device/driver
interface.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 20.0 KB
Line 
1/* $Id: PDMGCDevice.cpp 3112 2007-06-14 18:23:38Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, GC Device parts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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
61extern DECLEXPORT(const PDMDEVHLPGC) g_pdmGCDevHlp;
62extern DECLEXPORT(const PDMPICHLPGC) g_pdmGCPicHlp;
63extern DECLEXPORT(const PDMAPICHLPGC) g_pdmGCApicHlp;
64extern DECLEXPORT(const PDMIOAPICHLPGC) g_pdmGCIoApicHlp;
65extern DECLEXPORT(const PDMPCIHLPGC) g_pdmGCPciHlp;
66__END_DECLS
67
68
69/*******************************************************************************
70* Internal Functions *
71*******************************************************************************/
72/** @name GC Device Helpers
73 * @{
74 */
75static DECLCALLBACK(void) pdmGCDevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
76static DECLCALLBACK(void) pdmGCDevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
77static DECLCALLBACK(void) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
78static DECLCALLBACK(void) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
79static DECLCALLBACK(bool) pdmGCDevHlp_A20IsEnabled(PPDMDEVINS pDevIns);
80static DECLCALLBACK(int) pdmGCDevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
81static DECLCALLBACK(int) pdmGCDevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va);
82static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...);
83static DECLCALLBACK(int) pdmGCDevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va);
84static DECLCALLBACK(int) pdmGCDevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData);
85/** @} */
86
87
88/** @name PIC GC Helpers
89 * @{
90 */
91static DECLCALLBACK(void) pdmGCPicHlp_SetInterruptFF(PPDMDEVINS pDevIns);
92static DECLCALLBACK(void) pdmGCPicHlp_ClearInterruptFF(PPDMDEVINS pDevIns);
93#ifdef VBOX_WITH_PDM_LOCK
94static DECLCALLBACK(int) pdmGCPicHlp_Lock(PPDMDEVINS pDevIns, int rc);
95static DECLCALLBACK(void) pdmGCPicHlp_Unlock(PPDMDEVINS pDevIns);
96#endif
97/** @} */
98
99
100/** @name APIC GC Helpers
101 * @{
102 */
103static DECLCALLBACK(void) pdmGCApicHlp_SetInterruptFF(PPDMDEVINS pDevIns);
104static DECLCALLBACK(void) pdmGCApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns);
105static DECLCALLBACK(void) pdmGCApicHlp_ChangeFeature(PPDMDEVINS pDevIns, bool fEnabled);
106#ifdef VBOX_WITH_PDM_LOCK
107static DECLCALLBACK(int) pdmGCApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
108static DECLCALLBACK(void) pdmGCApicHlp_Unlock(PPDMDEVINS pDevIns);
109#endif
110/** @} */
111
112
113/** @name I/O APIC GC Helpers
114 * @{
115 */
116static 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
119static DECLCALLBACK(int) pdmGCIoApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
120static DECLCALLBACK(void) pdmGCIoApicHlp_Unlock(PPDMDEVINS pDevIns);
121#endif
122/** @} */
123
124
125/** @name PCI Bus GC Helpers
126 * @{
127 */
128static DECLCALLBACK(void) pdmGCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
129static DECLCALLBACK(void) pdmGCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
130#ifdef VBOX_WITH_PDM_LOCK
131static DECLCALLBACK(int) pdmGCPciHlp_Lock(PPDMDEVINS pDevIns, int rc);
132static DECLCALLBACK(void) pdmGCPciHlp_Unlock(PPDMDEVINS pDevIns);
133#endif
134/** @} */
135
136
137static void pdmGCIsaSetIrq(PVM pVM, int iIrq, int iLevel);
138static void pdmGCIoApicSetIrq(PVM pVM, int iIrq, int iLevel);
139
140
141
142/**
143 * The Guest Context Device Helper Callbacks.
144 */
145extern 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 */
164extern 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 */
180extern 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 */
197extern 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 */
212extern 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 */
228static 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 */
266static 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 */
278static 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 */
291static 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 */
304static 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 */
317static 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 */
329static 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 */
338static 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 */
350static 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 */
359static 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 */
371static 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 */
381static 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 */
392static 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 */
400static 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 */
411static 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 */
421static 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 */
431static 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 */
444static 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 */
452static 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 */
463static 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 */
477static 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 */
485static 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 */
496static 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 */
505static 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 */
515static 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 */
523static 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 */
540static 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 */
580static 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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette