VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/PDMR0Device.cpp@ 3294

Last change on this file since 3294 was 3112, checked in by vboxsync, 18 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: PDMR0Device.cpp 3112 2007-06-14 18:23:38Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, R0 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->pvInstanceDataR0 == (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 PDMDEVHLPR0) g_pdmR0DevHlp;
62extern DECLEXPORT(const PDMPICHLPR0) g_pdmR0PicHlp;
63extern DECLEXPORT(const PDMAPICHLPR0) g_pdmR0ApicHlp;
64extern DECLEXPORT(const PDMIOAPICHLPR0) g_pdmR0IoApicHlp;
65extern DECLEXPORT(const PDMPCIHLPR0) g_pdmR0PciHlp;
66__END_DECLS
67
68
69/*******************************************************************************
70* Internal Functions *
71*******************************************************************************/
72/** @name GC Device Helpers
73 * @{
74 */
75static DECLCALLBACK(void) pdmR0DevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
76static DECLCALLBACK(void) pdmR0DevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
77static DECLCALLBACK(void) pdmR0DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
78static DECLCALLBACK(void) pdmR0DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
79static DECLCALLBACK(bool) pdmR0DevHlp_A20IsEnabled(PPDMDEVINS pDevIns);
80static DECLCALLBACK(int) pdmR0DevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
81static DECLCALLBACK(int) pdmR0DevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va);
82static DECLCALLBACK(int) pdmR0DevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...);
83static DECLCALLBACK(int) pdmR0DevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va);
84static DECLCALLBACK(int) pdmR0DevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData);
85/** @} */
86
87
88/** @name PIC GC Helpers
89 * @{
90 */
91static DECLCALLBACK(void) pdmR0PicHlp_SetInterruptFF(PPDMDEVINS pDevIns);
92static DECLCALLBACK(void) pdmR0PicHlp_ClearInterruptFF(PPDMDEVINS pDevIns);
93#ifdef VBOX_WITH_PDM_LOCK
94static DECLCALLBACK(int) pdmR0PicHlp_Lock(PPDMDEVINS pDevIns, int rc);
95static DECLCALLBACK(void) pdmR0PicHlp_Unlock(PPDMDEVINS pDevIns);
96#endif
97/** @} */
98
99
100/** @name APIC GC Helpers
101 * @{
102 */
103static DECLCALLBACK(void) pdmR0ApicHlp_SetInterruptFF(PPDMDEVINS pDevIns);
104static DECLCALLBACK(void) pdmR0ApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns);
105static DECLCALLBACK(void) pdmR0ApicHlp_ChangeFeature(PPDMDEVINS pDevIns, bool fEnabled);
106#ifdef VBOX_WITH_PDM_LOCK
107static DECLCALLBACK(int) pdmR0ApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
108static DECLCALLBACK(void) pdmR0ApicHlp_Unlock(PPDMDEVINS pDevIns);
109#endif
110/** @} */
111
112
113/** @name I/O APIC GC Helpers
114 * @{
115 */
116static DECLCALLBACK(void) pdmR0IoApicHlp_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) pdmR0IoApicHlp_Lock(PPDMDEVINS pDevIns, int rc);
120static DECLCALLBACK(void) pdmR0IoApicHlp_Unlock(PPDMDEVINS pDevIns);
121#endif
122/** @} */
123
124
125/** @name PCI Bus GC Helpers
126 * @{
127 */
128static DECLCALLBACK(void) pdmR0PciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
129static DECLCALLBACK(void) pdmR0PciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
130#ifdef VBOX_WITH_PDM_LOCK
131static DECLCALLBACK(int) pdmR0PciHlp_Lock(PPDMDEVINS pDevIns, int rc);
132static DECLCALLBACK(void) pdmR0PciHlp_Unlock(PPDMDEVINS pDevIns);
133#endif
134/** @} */
135
136
137static void pdmR0IsaSetIrq(PVM pVM, int iIrq, int iLevel);
138static void pdmR0IoApicSetIrq(PVM pVM, int iIrq, int iLevel);
139
140
141
142/**
143 * The Guest Context Device Helper Callbacks.
144 */
145extern DECLEXPORT(const PDMDEVHLPR0) g_pdmR0DevHlp =
146{
147 PDM_DEVHLPR0_VERSION,
148 pdmR0DevHlp_PCISetIrq,
149 pdmR0DevHlp_ISASetIrq,
150 pdmR0DevHlp_PhysRead,
151 pdmR0DevHlp_PhysWrite,
152 pdmR0DevHlp_A20IsEnabled,
153 pdmR0DevHlp_VMSetError,
154 pdmR0DevHlp_VMSetErrorV,
155 pdmR0DevHlp_VMSetRuntimeError,
156 pdmR0DevHlp_VMSetRuntimeErrorV,
157 pdmR0DevHlp_PATMSetMMIOPatchInfo,
158 PDM_DEVHLPR0_VERSION
159};
160
161/**
162 * The Guest Context PIC Helper Callbacks.
163 */
164extern DECLEXPORT(const PDMPICHLPR0) g_pdmR0PicHlp =
165{
166 PDM_PICHLPR0_VERSION,
167 pdmR0PicHlp_SetInterruptFF,
168 pdmR0PicHlp_ClearInterruptFF,
169#ifdef VBOX_WITH_PDM_LOCK
170 pdmR0PicHlp_Lock,
171 pdmR0PicHlp_Unlock,
172#endif
173 PDM_PICHLPR0_VERSION
174};
175
176
177/**
178 * The Guest Context APIC Helper Callbacks.
179 */
180extern DECLEXPORT(const PDMAPICHLPR0) g_pdmR0ApicHlp =
181{
182 PDM_APICHLPR0_VERSION,
183 pdmR0ApicHlp_SetInterruptFF,
184 pdmR0ApicHlp_ClearInterruptFF,
185 pdmR0ApicHlp_ChangeFeature,
186#ifdef VBOX_WITH_PDM_LOCK
187 pdmR0ApicHlp_Lock,
188 pdmR0ApicHlp_Unlock,
189#endif
190 PDM_APICHLPR0_VERSION
191};
192
193
194/**
195 * The Guest Context I/O APIC Helper Callbacks.
196 */
197extern DECLEXPORT(const PDMIOAPICHLPR0) g_pdmR0IoApicHlp =
198{
199 PDM_IOAPICHLPR0_VERSION,
200 pdmR0IoApicHlp_ApicBusDeliver,
201#ifdef VBOX_WITH_PDM_LOCK
202 pdmR0IoApicHlp_Lock,
203 pdmR0IoApicHlp_Unlock,
204#endif
205 PDM_IOAPICHLPR0_VERSION
206};
207
208
209/**
210 * The Guest Context PCI Bus Helper Callbacks.
211 */
212extern DECLEXPORT(const PDMPCIHLPR0) g_pdmR0PciHlp =
213{
214 PDM_PCIHLPR0_VERSION,
215 pdmR0PciHlp_IsaSetIrq,
216 pdmR0PciHlp_IoApicSetIrq,
217#ifdef VBOX_WITH_PDM_LOCK
218 pdmR0PciHlp_Lock,
219 pdmR0PciHlp_Unlock,
220#endif
221 PDM_PCIHLPR0_VERSION, /* the end */
222};
223
224
225
226
227/** @copydoc PDMDEVHLPR0::pfnPCISetIrq */
228static DECLCALLBACK(void) pdmR0DevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
229{
230 PDMDEV_ASSERT_DEVINS(pDevIns);
231 LogFlow(("pdmR0DevHlp_PCISetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
232
233 PVM pVM = pDevIns->Internal.s.pVMHC;
234 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceHC;
235 PPDMPCIBUS pPciBus = pDevIns->Internal.s.pPciBusHC;
236 if ( pPciDev
237 && pPciBus
238 && pPciBus->pDevInsR0)
239 {
240 pdmLock(pVM);
241 pPciBus->pfnSetIrqR0(pPciBus->pDevInsR0, pPciDev, iIrq, iLevel);
242 pdmUnlock(pVM);
243 }
244 else
245 {
246 /* queue for ring-3 execution. */
247 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueHC);
248 if (pTask)
249 {
250 pTask->enmOp = PDMDEVHLPTASKOP_PCI_SET_IRQ;
251 pTask->pDevInsHC = pDevIns;
252 pTask->u.SetIRQ.iIrq = iIrq;
253 pTask->u.SetIRQ.iLevel = iLevel;
254
255 PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueHC, &pTask->Core, 0);
256 }
257 else
258 AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
259 }
260
261 LogFlow(("pdmR0DevHlp_PCISetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
262}
263
264
265/** @copydoc PDMDEVHLPR0::pfnPCISetIrq */
266static DECLCALLBACK(void) pdmR0DevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
267{
268 PDMDEV_ASSERT_DEVINS(pDevIns);
269 LogFlow(("pdmR0DevHlp_ISASetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
270
271 pdmR0IsaSetIrq(pDevIns->Internal.s.pVMHC, iIrq, iLevel);
272
273 LogFlow(("pdmR0DevHlp_ISASetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
274}
275
276
277/** @copydoc PDMDEVHLPR0::pfnPhysRead */
278static DECLCALLBACK(void) pdmR0DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
279{
280 PDMDEV_ASSERT_DEVINS(pDevIns);
281 LogFlow(("pdmR0DevHlp_PhysRead: caller=%p/%d: GCPhys=%VGp pvBuf=%p cbRead=%#x\n",
282 pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbRead));
283
284 PGMPhysRead(pDevIns->Internal.s.pVMHC, GCPhys, pvBuf, cbRead);
285
286 Log(("pdmR0DevHlp_PhysRead: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
287}
288
289
290/** @copydoc PDMDEVHLPR0::pfnPhysWrite */
291static DECLCALLBACK(void) pdmR0DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
292{
293 PDMDEV_ASSERT_DEVINS(pDevIns);
294 LogFlow(("pdmR0DevHlp_PhysWrite: caller=%p/%d: GCPhys=%VGp pvBuf=%p cbWrite=%#x\n",
295 pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbWrite));
296
297 PGMPhysWrite(pDevIns->Internal.s.pVMHC, GCPhys, pvBuf, cbWrite);
298
299 Log(("pdmR0DevHlp_PhysWrite: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
300}
301
302
303/** @copydoc PDMDEVHLPR0::pfnA20IsEnabled */
304static DECLCALLBACK(bool) pdmR0DevHlp_A20IsEnabled(PPDMDEVINS pDevIns)
305{
306 PDMDEV_ASSERT_DEVINS(pDevIns);
307 LogFlow(("pdmR0DevHlp_A20IsEnabled: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
308
309 bool fEnabled = PGMPhysIsA20Enabled(pDevIns->Internal.s.pVMHC);
310
311 Log(("pdmR0DevHlp_A20IsEnabled: caller=%p/%d: returns %RTbool\n", pDevIns, pDevIns->iInstance, fEnabled));
312 return fEnabled;
313}
314
315
316/** @copydoc PDMDEVHLPR0::pfnVMSetError */
317static DECLCALLBACK(int) pdmR0DevHlp_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.pVMHC, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
323 va_end(args);
324 return rc;
325}
326
327
328/** @copydoc PDMDEVHLPR0::pfnVMSetErrorV */
329static DECLCALLBACK(int) pdmR0DevHlp_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.pVMHC, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
333 return rc;
334}
335
336
337/** @copydoc PDMDEVHLPR0::pfnVMSetRuntimeError */
338static DECLCALLBACK(int) pdmR0DevHlp_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.pVMHC, fFatal, pszErrorID, pszFormat, args);
344 va_end(args);
345 return rc;
346}
347
348
349/** @copydoc PDMDEVHLPR0::pfnVMSetRuntimeErrorV */
350static DECLCALLBACK(int) pdmR0DevHlp_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.pVMHC, fFatal, pszErrorID, pszFormat, va);
354 return rc;
355}
356
357
358/** @copydoc PDMDEVHLPR0::pdmR0DevHlp_PATMSetMMIOPatchInfo*/
359static DECLCALLBACK(int) pdmR0DevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData)
360{
361 PDMDEV_ASSERT_DEVINS(pDevIns);
362 LogFlow(("pdmR0DevHlp_PATMSetMMIOPatchInfo: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
363
364 return PATMSetMMIOPatchInfo(pDevIns->Internal.s.pVMHC, GCPhys, pCachedData);
365}
366
367
368
369
370
371/** @copydoc PDMPICHLPGC::pfnSetInterruptFF */
372static DECLCALLBACK(void) pdmR0PicHlp_SetInterruptFF(PPDMDEVINS pDevIns)
373{
374 PDMDEV_ASSERT_DEVINS(pDevIns);
375 LogFlow(("pdmR0PicHlp_SetInterruptFF: caller=%p/%d: VM_FF_INTERRUPT_PIC %d -> 1\n",
376 pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_PIC)));
377 VM_FF_SET(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_PIC);
378}
379
380
381/** @copydoc PDMPICHLPGC::pfnClearInterruptFF */
382static DECLCALLBACK(void) pdmR0PicHlp_ClearInterruptFF(PPDMDEVINS pDevIns)
383{
384 PDMDEV_ASSERT_DEVINS(pDevIns);
385 LogFlow(("pdmR0PicHlp_ClearInterruptFF: caller=%p/%d: VM_FF_INTERRUPT_PIC %d -> 0\n",
386 pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_PIC)));
387 VM_FF_CLEAR(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_PIC);
388}
389
390
391#ifdef VBOX_WITH_PDM_LOCK
392/** @copydoc PDMPICHLPR0::pfnLock */
393static DECLCALLBACK(int) pdmR0PicHlp_Lock(PPDMDEVINS pDevIns, int rc)
394{
395 PDMDEV_ASSERT_DEVINS(pDevIns);
396 return pdmLockEx(pDevIns->Internal.s.pVMHC, rc);
397}
398
399
400/** @copydoc PDMPICHLPR0::pfnUnlock */
401static DECLCALLBACK(void) pdmR0PicHlp_Unlock(PPDMDEVINS pDevIns)
402{
403 PDMDEV_ASSERT_DEVINS(pDevIns);
404 pdmUnlock(pDevIns->Internal.s.pVMHC);
405}
406#endif /* VBOX_WITH_PDM_LOCK */
407
408
409
410
411/** @copydoc PDMAPICHLPGC::pfnSetInterruptFF */
412static DECLCALLBACK(void) pdmR0ApicHlp_SetInterruptFF(PPDMDEVINS pDevIns)
413{
414 PDMDEV_ASSERT_DEVINS(pDevIns);
415 LogFlow(("pdmR0ApicHlp_SetInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 1\n",
416 pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_APIC)));
417 VM_FF_SET(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_APIC);
418}
419
420
421/** @copydoc PDMAPICHLPGC::pfnClearInterruptFF */
422static DECLCALLBACK(void) pdmR0ApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns)
423{
424 PDMDEV_ASSERT_DEVINS(pDevIns);
425 LogFlow(("pdmR0ApicHlp_ClearInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 0\n",
426 pDevIns, pDevIns->iInstance, VM_FF_ISSET(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_APIC)));
427 VM_FF_CLEAR(pDevIns->Internal.s.pVMHC, VM_FF_INTERRUPT_APIC);
428}
429
430
431/** @copydoc PDMAPICHLPGC::pfnChangeFeature */
432static DECLCALLBACK(void) pdmR0ApicHlp_ChangeFeature(PPDMDEVINS pDevIns, bool fEnabled)
433{
434 PDMDEV_ASSERT_DEVINS(pDevIns);
435 LogFlow(("pdmR0ApicHlp_ChangeFeature: caller=%p/%d: fEnabled=%RTbool\n", pDevIns, pDevIns->iInstance, fEnabled));
436 if (fEnabled)
437 CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMHC, CPUMCPUIDFEATURE_APIC);
438 else
439 CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMHC, CPUMCPUIDFEATURE_APIC);
440}
441
442
443#ifdef VBOX_WITH_PDM_LOCK
444/** @copydoc PDMAPICHLPR0::pfnLock */
445static DECLCALLBACK(int) pdmR0ApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
446{
447 PDMDEV_ASSERT_DEVINS(pDevIns);
448 return pdmLockEx(pDevIns->Internal.s.pVMHC, rc);
449}
450
451
452/** @copydoc PDMAPICHLPR0::pfnUnlock */
453static DECLCALLBACK(void) pdmR0ApicHlp_Unlock(PPDMDEVINS pDevIns)
454{
455 PDMDEV_ASSERT_DEVINS(pDevIns);
456 pdmUnlock(pDevIns->Internal.s.pVMHC);
457}
458#endif /* VBOX_WITH_PDM_LOCK */
459
460
461
462
463/** @copydoc PDMIOAPICHLPR0::pfnApicBusDeliver */
464static DECLCALLBACK(void) pdmR0IoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
465 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode)
466{
467 PDMDEV_ASSERT_DEVINS(pDevIns);
468 PVM pVM = pDevIns->Internal.s.pVMHC;
469 LogFlow(("pdmR0IoApicHlp_ApicBusDeliver: caller=%p/%d: u8Dest=%RX8 u8DestMode=%RX8 u8DeliveryMode=%RX8 iVector=%RX8 u8Polarity=%RX8 u8TriggerMode=%RX8\n",
470 pDevIns, pDevIns->iInstance, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode));
471 Assert(pVM->pdm.s.Apic.pDevInsR0);
472 if (pVM->pdm.s.Apic.pfnBusDeliverR0)
473 pVM->pdm.s.Apic.pfnBusDeliverR0(pVM->pdm.s.Apic.pDevInsR0, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode);
474}
475
476
477#ifdef VBOX_WITH_PDM_LOCK
478/** @copydoc PDMIOAPICHLPR0::pfnLock */
479static DECLCALLBACK(int) pdmR0IoApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
480{
481 PDMDEV_ASSERT_DEVINS(pDevIns);
482 return pdmLockEx(pDevIns->Internal.s.pVMHC, rc);
483}
484
485
486/** @copydoc PDMIOAPICHLPR0::pfnUnlock */
487static DECLCALLBACK(void) pdmR0IoApicHlp_Unlock(PPDMDEVINS pDevIns)
488{
489 PDMDEV_ASSERT_DEVINS(pDevIns);
490 pdmUnlock(pDevIns->Internal.s.pVMHC);
491}
492#endif /* VBOX_WITH_PDM_LOCK */
493
494
495
496
497
498/** @copydoc PDMPCIHLPR0::pfnIsaSetIrq */
499static DECLCALLBACK(void) pdmR0PciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
500{
501 PDMDEV_ASSERT_DEVINS(pDevIns);
502 Log4(("pdmR0PciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
503 pdmR0IsaSetIrq(pDevIns->Internal.s.pVMHC, iIrq, iLevel);
504}
505
506
507/** @copydoc PDMPCIHLPR0::pfnIoApicSetIrq */
508static DECLCALLBACK(void) pdmR0PciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
509{
510 PDMDEV_ASSERT_DEVINS(pDevIns);
511 Log4(("pdmR0PciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
512 pdmR0IoApicSetIrq(pDevIns->Internal.s.pVMHC, iIrq, iLevel);
513}
514
515
516#ifdef VBOX_WITH_PDM_LOCK
517/** @copydoc PDMPCIHLPR0::pfnLock */
518static DECLCALLBACK(int) pdmR0PciHlp_Lock(PPDMDEVINS pDevIns, int rc)
519{
520 PDMDEV_ASSERT_DEVINS(pDevIns);
521 return pdmLockEx(pDevIns->Internal.s.pVMHC, rc);
522}
523
524
525/** @copydoc PDMPCIHLPR0::pfnUnlock */
526static DECLCALLBACK(void) pdmR0PciHlp_Unlock(PPDMDEVINS pDevIns)
527{
528 PDMDEV_ASSERT_DEVINS(pDevIns);
529 pdmUnlock(pDevIns->Internal.s.pVMHC);
530}
531#endif /* VBOX_WITH_PDM_LOCK */
532
533
534
535
536/**
537 * Sets an irq on the I/O APIC.
538 *
539 * @param pVM The VM handle.
540 * @param iIrq The irq.
541 * @param iLevel The new level.
542 */
543static void pdmR0IsaSetIrq(PVM pVM, int iIrq, int iLevel)
544{
545 if ( ( pVM->pdm.s.IoApic.pDevInsR0
546 || !pVM->pdm.s.IoApic.pDevInsR3)
547 && ( pVM->pdm.s.Pic.pDevInsR0
548 || !pVM->pdm.s.Pic.pDevInsR3))
549 {
550 pdmLock(pVM);
551 if (pVM->pdm.s.Pic.pDevInsR0)
552 pVM->pdm.s.Pic.pfnSetIrqR0(pVM->pdm.s.Pic.pDevInsR0, iIrq, iLevel);
553 if (pVM->pdm.s.IoApic.pDevInsR0)
554 pVM->pdm.s.IoApic.pfnSetIrqR0(pVM->pdm.s.IoApic.pDevInsR0, iIrq, iLevel);
555 pdmUnlock(pVM);
556 }
557 else
558 {
559 /* queue for ring-3 execution. */
560 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueHC);
561 if (pTask)
562 {
563 pTask->enmOp = PDMDEVHLPTASKOP_ISA_SET_IRQ;
564 pTask->pDevInsHC = 0; /* not required */
565 pTask->u.SetIRQ.iIrq = iIrq;
566 pTask->u.SetIRQ.iLevel = iLevel;
567
568 PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueHC, &pTask->Core, 0);
569 }
570 else
571 AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
572 }
573}
574
575
576/**
577 * Sets an irq on the I/O APIC.
578 *
579 * @param pVM The VM handle.
580 * @param iIrq The irq.
581 * @param iLevel The new level.
582 */
583static void pdmR0IoApicSetIrq(PVM pVM, int iIrq, int iLevel)
584{
585 if (pVM->pdm.s.IoApic.pDevInsR0)
586 {
587 pdmLock(pVM);
588 pVM->pdm.s.IoApic.pfnSetIrqR0(pVM->pdm.s.IoApic.pDevInsR0, iIrq, iLevel);
589 pdmUnlock(pVM);
590 }
591 else if (pVM->pdm.s.IoApic.pDevInsR3)
592 {
593 /* queue for ring-3 execution. */
594 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueHC);
595 if (pTask)
596 {
597 pTask->enmOp = PDMDEVHLPTASKOP_IOAPIC_SET_IRQ;
598 pTask->pDevInsHC = 0; /* not required */
599 pTask->u.SetIRQ.iIrq = iIrq;
600 pTask->u.SetIRQ.iLevel = iLevel;
601
602 PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueHC, &pTask->Core, 0);
603 }
604 else
605 AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
606 }
607}
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