VirtualBox

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

Last change on this file since 29655 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 24.0 KB
Line 
1/* $Id: PDMGCDevice.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, RC Device parts.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_PDM_DEVICE
23#include "PDMInternal.h"
24#include <VBox/pdm.h>
25#include <VBox/pgm.h>
26#include <VBox/mm.h>
27#include <VBox/vm.h>
28#include <VBox/vmm.h>
29#include <VBox/patm.h>
30
31#include <VBox/log.h>
32#include <VBox/err.h>
33#include <iprt/asm.h>
34#include <iprt/assert.h>
35#include <iprt/string.h>
36
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41RT_C_DECLS_BEGIN
42extern DECLEXPORT(const PDMDEVHLPRC) g_pdmRCDevHlp;
43extern DECLEXPORT(const PDMPICHLPRC) g_pdmRCPicHlp;
44extern DECLEXPORT(const PDMAPICHLPRC) g_pdmRCApicHlp;
45extern DECLEXPORT(const PDMIOAPICHLPRC) g_pdmRCIoApicHlp;
46extern DECLEXPORT(const PDMPCIHLPRC) g_pdmRCPciHlp;
47extern DECLEXPORT(const PDMHPETHLPRC) g_pdmRCHpetHlp;
48extern DECLEXPORT(const PDMDRVHLPRC) g_pdmRCDrvHlp;
49RT_C_DECLS_END
50
51
52/*******************************************************************************
53* Internal Functions *
54*******************************************************************************/
55static void pdmRCIsaSetIrq(PVM pVM, int iIrq, int iLevel);
56static void pdmRCIoApicSetIrq(PVM pVM, int iIrq, int iLevel);
57
58
59
60
61/** @name Raw-Mode Context Device Helpers
62 * @{
63 */
64
65/** @interface_method_impl{PDMDEVHLPRC,pfnPCISetIrq} */
66static DECLCALLBACK(void) pdmRCDevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
67{
68 PDMDEV_ASSERT_DEVINS(pDevIns);
69 LogFlow(("pdmRCDevHlp_PCISetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
70
71 PVM pVM = pDevIns->Internal.s.pVMRC;
72 PPCIDEVICE pPciDev = pDevIns->Internal.s.pPciDeviceRC;
73 PPDMPCIBUS pPciBus = pDevIns->Internal.s.pPciBusRC;
74 if ( pPciDev
75 && pPciBus
76 && pPciBus->pDevInsRC)
77 {
78 pdmLock(pVM);
79 pPciBus->pfnSetIrqRC(pPciBus->pDevInsRC, pPciDev, iIrq, iLevel);
80 pdmUnlock(pVM);
81 }
82 else
83 {
84 /* queue for ring-3 execution. */
85 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
86 if (pTask)
87 {
88 pTask->enmOp = PDMDEVHLPTASKOP_PCI_SET_IRQ;
89 pTask->pDevInsR3 = PDMDEVINS_2_R3PTR(pDevIns);
90 pTask->u.SetIRQ.iIrq = iIrq;
91 pTask->u.SetIRQ.iLevel = iLevel;
92
93 PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
94 }
95 else
96 AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
97 }
98
99 LogFlow(("pdmRCDevHlp_PCISetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
100}
101
102
103/** @interface_method_impl{PDMDRVHLPRC,pfnPCISetIrq} */
104static DECLCALLBACK(void) pdmRCDevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
105{
106 PDMDEV_ASSERT_DEVINS(pDevIns);
107 LogFlow(("pdmRCDevHlp_ISASetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
108
109 pdmRCIsaSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
110
111 LogFlow(("pdmRCDevHlp_ISASetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
112}
113
114
115/** @interface_method_impl{PDMDEVHLPRC,pfnPhysRead} */
116static DECLCALLBACK(int) pdmRCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
117{
118 PDMDEV_ASSERT_DEVINS(pDevIns);
119 LogFlow(("pdmRCDevHlp_PhysRead: caller=%p/%d: GCPhys=%RGp pvBuf=%p cbRead=%#x\n",
120 pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbRead));
121
122 int rc = PGMPhysRead(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbRead);
123 AssertRC(rc); /** @todo track down the users for this bugger. */
124
125 Log(("pdmRCDevHlp_PhysRead: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
126 return rc;
127}
128
129
130/** @interface_method_impl{PDMDEVHLPRC,pfnPhysWrite} */
131static DECLCALLBACK(int) pdmRCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
132{
133 PDMDEV_ASSERT_DEVINS(pDevIns);
134 LogFlow(("pdmRCDevHlp_PhysWrite: caller=%p/%d: GCPhys=%RGp pvBuf=%p cbWrite=%#x\n",
135 pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbWrite));
136
137 int rc = PGMPhysWrite(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbWrite);
138 AssertRC(rc); /** @todo track down the users for this bugger. */
139
140 Log(("pdmRCDevHlp_PhysWrite: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
141 return rc;
142}
143
144
145/** @interface_method_impl{PDMDEVHLPRC,pfnA20IsEnabled} */
146static DECLCALLBACK(bool) pdmRCDevHlp_A20IsEnabled(PPDMDEVINS pDevIns)
147{
148 PDMDEV_ASSERT_DEVINS(pDevIns);
149 LogFlow(("pdmRCDevHlp_A20IsEnabled: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
150
151 bool fEnabled = PGMPhysIsA20Enabled(VMMGetCpu0(pDevIns->Internal.s.pVMRC));
152
153 Log(("pdmRCDevHlp_A20IsEnabled: caller=%p/%d: returns %RTbool\n", pDevIns, pDevIns->iInstance, fEnabled));
154 return fEnabled;
155}
156
157
158/** @interface_method_impl{PDMDEVHLPRC,pfnVMState} */
159static DECLCALLBACK(VMSTATE) pdmRCDevHlp_VMState(PPDMDEVINS pDevIns)
160{
161 PDMDEV_ASSERT_DEVINS(pDevIns);
162
163 VMSTATE enmVMState = pDevIns->Internal.s.pVMRC->enmVMState;
164
165 LogFlow(("pdmRCDevHlp_VMState: caller=%p/%d: returns %d\n", pDevIns, pDevIns->iInstance, enmVMState));
166 return enmVMState;
167}
168
169
170/** @interface_method_impl{PDMDEVHLPRC,pfnVMSetError} */
171static DECLCALLBACK(int) pdmRCDevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
172{
173 PDMDEV_ASSERT_DEVINS(pDevIns);
174 va_list args;
175 va_start(args, pszFormat);
176 int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMRC, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
177 va_end(args);
178 return rc;
179}
180
181
182/** @interface_method_impl{PDMDEVHLPRC,pfnVMSetErrorV} */
183static DECLCALLBACK(int) pdmRCDevHlp_VMSetErrorV(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
184{
185 PDMDEV_ASSERT_DEVINS(pDevIns);
186 int rc2 = VMSetErrorV(pDevIns->Internal.s.pVMRC, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
187 return rc;
188}
189
190
191/** @interface_method_impl{PDMDEVHLPRC,pfnVMSetRuntimeError} */
192static DECLCALLBACK(int) pdmRCDevHlp_VMSetRuntimeError(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
193{
194 PDMDEV_ASSERT_DEVINS(pDevIns);
195 va_list va;
196 va_start(va, pszFormat);
197 int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMRC, fFlags, pszErrorId, pszFormat, va);
198 va_end(va);
199 return rc;
200}
201
202
203/** @interface_method_impl{PDMDEVHLPRC,pfnVMSetErrorV} */
204static DECLCALLBACK(int) pdmRCDevHlp_VMSetRuntimeErrorV(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
205{
206 PDMDEV_ASSERT_DEVINS(pDevIns);
207 int rc = VMSetRuntimeErrorV(pDevIns->Internal.s.pVMRC, fFlags, pszErrorId, pszFormat, va);
208 return rc;
209}
210
211
212/** @interface_method_impl{PDMDEVHLPRC,pfnPATMSetMMIOPatchInfo} */
213static DECLCALLBACK(int) pdmRCDevHlp_PATMSetMMIOPatchInfo(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData)
214{
215 PDMDEV_ASSERT_DEVINS(pDevIns);
216 LogFlow(("pdmRCDevHlp_PATMSetMMIOPatchInfo: caller=%p/%d:\n", pDevIns, pDevIns->iInstance));
217
218 return PATMSetMMIOPatchInfo(pDevIns->Internal.s.pVMRC, GCPhys, (RTRCPTR)(uintptr_t)pCachedData);
219}
220
221
222/** @interface_method_impl{PDMDEVHLPRC,pfnGetVM} */
223static DECLCALLBACK(PVM) pdmRCDevHlp_GetVM(PPDMDEVINS pDevIns)
224{
225 PDMDEV_ASSERT_DEVINS(pDevIns);
226 LogFlow(("pdmRCDevHlp_GetVM: caller='%p'/%d\n", pDevIns, pDevIns->iInstance));
227 return pDevIns->Internal.s.pVMRC;
228}
229
230
231/** @interface_method_impl{PDMDEVHLPRC,pfnGetVMCPU} */
232static DECLCALLBACK(PVMCPU) pdmRCDevHlp_GetVMCPU(PPDMDEVINS pDevIns)
233{
234 PDMDEV_ASSERT_DEVINS(pDevIns);
235 LogFlow(("pdmRCDevHlp_GetVMCPU: caller='%p'/%d\n", pDevIns, pDevIns->iInstance));
236 return VMMGetCpu(pDevIns->Internal.s.pVMRC);
237}
238
239
240/**
241 * The Raw-Mode Context Device Helper Callbacks.
242 */
243extern DECLEXPORT(const PDMDEVHLPRC) g_pdmRCDevHlp =
244{
245 PDM_DEVHLPRC_VERSION,
246 pdmRCDevHlp_PCISetIrq,
247 pdmRCDevHlp_ISASetIrq,
248 pdmRCDevHlp_PhysRead,
249 pdmRCDevHlp_PhysWrite,
250 pdmRCDevHlp_A20IsEnabled,
251 pdmRCDevHlp_VMState,
252 pdmRCDevHlp_VMSetError,
253 pdmRCDevHlp_VMSetErrorV,
254 pdmRCDevHlp_VMSetRuntimeError,
255 pdmRCDevHlp_VMSetRuntimeErrorV,
256 pdmRCDevHlp_PATMSetMMIOPatchInfo,
257 pdmRCDevHlp_GetVM,
258 pdmRCDevHlp_GetVMCPU,
259 PDM_DEVHLPRC_VERSION
260};
261
262/** @} */
263
264
265
266
267/** @name PIC RC Helpers
268 * @{
269 */
270
271/** @interface_method_impl{PDMPICHLPGC,pfnSetInterruptFF} */
272static DECLCALLBACK(void) pdmRCPicHlp_SetInterruptFF(PPDMDEVINS pDevIns)
273{
274 PDMDEV_ASSERT_DEVINS(pDevIns);
275 PVM pVM = pDevIns->Internal.s.pVMRC;
276
277 if (pVM->pdm.s.Apic.pfnLocalInterruptRC)
278 {
279 LogFlow(("pdmRCPicHlp_SetInterruptFF: caller='%p'/%d: Setting local interrupt on LAPIC\n",
280 pDevIns, pDevIns->iInstance));
281 /* Raise the LAPIC's LINT0 line instead of signaling the CPU directly. */
282 pVM->pdm.s.Apic.pfnLocalInterruptRC(pVM->pdm.s.Apic.pDevInsRC, 0, 1);
283 return;
284 }
285
286 PVMCPU pVCpu = &pVM->aCpus[0]; /* for PIC we always deliver to CPU 0, MP use APIC */
287
288 LogFlow(("pdmRCPicHlp_SetInterruptFF: caller=%p/%d: VMMCPU_FF_INTERRUPT_PIC %d -> 1\n",
289 pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC)));
290
291 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
292}
293
294
295/** @interface_method_impl{PDMPICHLPGC,pfnClearInterruptFF} */
296static DECLCALLBACK(void) pdmRCPicHlp_ClearInterruptFF(PPDMDEVINS pDevIns)
297{
298 PDMDEV_ASSERT_DEVINS(pDevIns);
299 PVM pVM = pDevIns->Internal.s.CTX_SUFF(pVM);
300
301 if (pVM->pdm.s.Apic.pfnLocalInterruptRC)
302 {
303 /* Raise the LAPIC's LINT0 line instead of signaling the CPU directly. */
304 LogFlow(("pdmRCPicHlp_ClearInterruptFF: caller='%s'/%d: Clearing local interrupt on LAPIC\n",
305 pDevIns, pDevIns->iInstance));
306 /* Lower the LAPIC's LINT0 line instead of signaling the CPU directly. */
307 pVM->pdm.s.Apic.pfnLocalInterruptRC(pVM->pdm.s.Apic.pDevInsRC, 0, 0);
308 return;
309 }
310
311 PVMCPU pVCpu = &pVM->aCpus[0]; /* for PIC we always deliver to CPU 0, MP use APIC */
312
313 LogFlow(("pdmRCPicHlp_ClearInterruptFF: caller=%p/%d: VMCPU_FF_INTERRUPT_PIC %d -> 0\n",
314 pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_PIC)));
315
316 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
317}
318
319
320/** @interface_method_impl{PDMPICHLPGC,pfnLock} */
321static DECLCALLBACK(int) pdmRCPicHlp_Lock(PPDMDEVINS pDevIns, int rc)
322{
323 PDMDEV_ASSERT_DEVINS(pDevIns);
324 return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
325}
326
327
328/** @interface_method_impl{PDMPICHLPGC,pfnUnlock} */
329static DECLCALLBACK(void) pdmRCPicHlp_Unlock(PPDMDEVINS pDevIns)
330{
331 PDMDEV_ASSERT_DEVINS(pDevIns);
332 pdmUnlock(pDevIns->Internal.s.pVMRC);
333}
334
335
336/**
337 * The Raw-Mode Context PIC Helper Callbacks.
338 */
339extern DECLEXPORT(const PDMPICHLPRC) g_pdmRCPicHlp =
340{
341 PDM_PICHLPRC_VERSION,
342 pdmRCPicHlp_SetInterruptFF,
343 pdmRCPicHlp_ClearInterruptFF,
344 pdmRCPicHlp_Lock,
345 pdmRCPicHlp_Unlock,
346 PDM_PICHLPRC_VERSION
347};
348
349/** @} */
350
351
352
353
354/** @name APIC RC Helpers
355 * @{
356 */
357
358/** @interface_method_impl{PDMAPICHLPRC,pfnSetInterruptFF} */
359static DECLCALLBACK(void) pdmRCApicHlp_SetInterruptFF(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu)
360{
361 PDMDEV_ASSERT_DEVINS(pDevIns);
362 PVM pVM = pDevIns->Internal.s.pVMRC;
363 PVMCPU pVCpu = &pVM->aCpus[idCpu];
364
365 AssertReturnVoid(idCpu < pVM->cCpus);
366
367 LogFlow(("pdmRCApicHlp_SetInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 1\n",
368 pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC)));
369 switch (enmType)
370 {
371 case PDMAPICIRQ_HARDWARE:
372 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC);
373 break;
374 case PDMAPICIRQ_NMI:
375 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI);
376 break;
377 case PDMAPICIRQ_SMI:
378 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI);
379 break;
380 case PDMAPICIRQ_EXTINT:
381 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
382 break;
383 default:
384 AssertMsgFailed(("enmType=%d\n", enmType));
385 break;
386 }
387}
388
389
390/** @interface_method_impl{PDMAPICHLPRC,pfnClearInterruptFF} */
391static DECLCALLBACK(void) pdmRCApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu)
392{
393 PDMDEV_ASSERT_DEVINS(pDevIns);
394 PVM pVM = pDevIns->Internal.s.pVMRC;
395 PVMCPU pVCpu = &pVM->aCpus[idCpu];
396
397 AssertReturnVoid(idCpu < pVM->cCpus);
398
399 LogFlow(("pdmRCApicHlp_ClearInterruptFF: caller=%p/%d: VM_FF_INTERRUPT %d -> 0\n",
400 pDevIns, pDevIns->iInstance, VMCPU_FF_ISSET(pVCpu, VMCPU_FF_INTERRUPT_APIC)));
401
402 /* Note: NMI/SMI can't be cleared. */
403 switch (enmType)
404 {
405 case PDMAPICIRQ_HARDWARE:
406 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
407 break;
408 case PDMAPICIRQ_EXTINT:
409 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
410 break;
411 default:
412 AssertMsgFailed(("enmType=%d\n", enmType));
413 break;
414 }
415}
416
417
418/** @interface_method_impl{PDMAPICHLPRC,pfnChangeFeature} */
419static DECLCALLBACK(void) pdmRCApicHlp_ChangeFeature(PPDMDEVINS pDevIns, PDMAPICVERSION enmVersion)
420{
421 PDMDEV_ASSERT_DEVINS(pDevIns);
422 LogFlow(("pdmRCApicHlp_ChangeFeature: caller=%p/%d: version=%d\n", pDevIns, pDevIns->iInstance, (int)enmVersion));
423 switch (enmVersion)
424 {
425 case PDMAPICVERSION_NONE:
426 CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_APIC);
427 CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_X2APIC);
428 break;
429 case PDMAPICVERSION_APIC:
430 CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_APIC);
431 CPUMClearGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_X2APIC);
432 break;
433 case PDMAPICVERSION_X2APIC:
434 CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_X2APIC);
435 CPUMSetGuestCpuIdFeature(pDevIns->Internal.s.pVMRC, CPUMCPUIDFEATURE_APIC);
436 break;
437 default:
438 AssertMsgFailed(("Unknown APIC version: %d\n", (int)enmVersion));
439 }
440}
441
442
443/** @interface_method_impl{PDMAPICHLPRC,pfnLock} */
444static DECLCALLBACK(int) pdmRCApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
445{
446 PDMDEV_ASSERT_DEVINS(pDevIns);
447 return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
448}
449
450
451/** @interface_method_impl{PDMAPICHLPRC,pfnUnlock} */
452static DECLCALLBACK(void) pdmRCApicHlp_Unlock(PPDMDEVINS pDevIns)
453{
454 PDMDEV_ASSERT_DEVINS(pDevIns);
455 pdmUnlock(pDevIns->Internal.s.pVMRC);
456}
457
458
459/** @interface_method_impl{PDMAPICHLPRC,pfnGetCpuId} */
460static DECLCALLBACK(VMCPUID) pdmRCApicHlp_GetCpuId(PPDMDEVINS pDevIns)
461{
462 PDMDEV_ASSERT_DEVINS(pDevIns);
463 return VMMGetCpuId(pDevIns->Internal.s.pVMRC);
464}
465
466
467/**
468 * The Raw-Mode Context APIC Helper Callbacks.
469 */
470extern DECLEXPORT(const PDMAPICHLPRC) g_pdmRCApicHlp =
471{
472 PDM_APICHLPRC_VERSION,
473 pdmRCApicHlp_SetInterruptFF,
474 pdmRCApicHlp_ClearInterruptFF,
475 pdmRCApicHlp_ChangeFeature,
476 pdmRCApicHlp_Lock,
477 pdmRCApicHlp_Unlock,
478 pdmRCApicHlp_GetCpuId,
479 PDM_APICHLPRC_VERSION
480};
481
482/** @} */
483
484
485
486
487/** @name I/O APIC RC Helpers
488 * @{
489 */
490
491/** @interface_method_impl{PDMIOAPICHLPRC,pfnApicBusDeliver} */
492static DECLCALLBACK(int) pdmRCIoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
493 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode)
494{
495 PDMDEV_ASSERT_DEVINS(pDevIns);
496 PVM pVM = pDevIns->Internal.s.pVMRC;
497 LogFlow(("pdmRCIoApicHlp_ApicBusDeliver: caller=%p/%d: u8Dest=%RX8 u8DestMode=%RX8 u8DeliveryMode=%RX8 iVector=%RX8 u8Polarity=%RX8 u8TriggerMode=%RX8\n",
498 pDevIns, pDevIns->iInstance, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode));
499 if (pVM->pdm.s.Apic.pfnBusDeliverRC)
500 return pVM->pdm.s.Apic.pfnBusDeliverRC(pVM->pdm.s.Apic.pDevInsRC, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode);
501 return VINF_SUCCESS;
502}
503
504
505/** @interface_method_impl{PDMIOAPICHLPRC,pfnLock} */
506static DECLCALLBACK(int) pdmRCIoApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
507{
508 PDMDEV_ASSERT_DEVINS(pDevIns);
509 return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
510}
511
512
513/** @interface_method_impl{PDMIOAPICHLPRC,pfnUnlock} */
514static DECLCALLBACK(void) pdmRCIoApicHlp_Unlock(PPDMDEVINS pDevIns)
515{
516 PDMDEV_ASSERT_DEVINS(pDevIns);
517 pdmUnlock(pDevIns->Internal.s.pVMRC);
518}
519
520
521/**
522 * The Raw-Mode Context I/O APIC Helper Callbacks.
523 */
524extern DECLEXPORT(const PDMIOAPICHLPRC) g_pdmRCIoApicHlp =
525{
526 PDM_IOAPICHLPRC_VERSION,
527 pdmRCIoApicHlp_ApicBusDeliver,
528 pdmRCIoApicHlp_Lock,
529 pdmRCIoApicHlp_Unlock,
530 PDM_IOAPICHLPRC_VERSION
531};
532
533/** @} */
534
535
536
537
538/** @name PCI Bus RC Helpers
539 * @{
540 */
541
542/** @interface_method_impl{PDMPCIHLPRC,pfnIsaSetIrq} */
543static DECLCALLBACK(void) pdmRCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
544{
545 PDMDEV_ASSERT_DEVINS(pDevIns);
546 Log4(("pdmRCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
547 pdmRCIsaSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
548}
549
550
551/** @interface_method_impl{PDMPCIHLPRC,pfnIoApicSetIrq} */
552static DECLCALLBACK(void) pdmRCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
553{
554 PDMDEV_ASSERT_DEVINS(pDevIns);
555 Log4(("pdmRCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
556 pdmRCIoApicSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
557}
558
559
560/** @interface_method_impl{PDMPCIHLPRC,pfnLock} */
561static DECLCALLBACK(int) pdmRCPciHlp_Lock(PPDMDEVINS pDevIns, int rc)
562{
563 PDMDEV_ASSERT_DEVINS(pDevIns);
564 return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
565}
566
567
568/** @interface_method_impl{PDMPCIHLPRC,pfnUnlock} */
569static DECLCALLBACK(void) pdmRCPciHlp_Unlock(PPDMDEVINS pDevIns)
570{
571 PDMDEV_ASSERT_DEVINS(pDevIns);
572 pdmUnlock(pDevIns->Internal.s.pVMRC);
573}
574
575
576/**
577 * The Raw-Mode Context PCI Bus Helper Callbacks.
578 */
579extern DECLEXPORT(const PDMPCIHLPRC) g_pdmRCPciHlp =
580{
581 PDM_PCIHLPRC_VERSION,
582 pdmRCPciHlp_IsaSetIrq,
583 pdmRCPciHlp_IoApicSetIrq,
584 pdmRCPciHlp_Lock,
585 pdmRCPciHlp_Unlock,
586 PDM_PCIHLPRC_VERSION, /* the end */
587};
588
589/** @} */
590
591
592
593
594/** @name HPET RC Helpers
595 * @{
596 */
597
598
599/**
600 * The Raw-Mode Context HPET Helper Callbacks.
601 */
602extern DECLEXPORT(const PDMHPETHLPRC) g_pdmRCHpetHlp =
603{
604 PDM_HPETHLPRC_VERSION,
605 PDM_HPETHLPRC_VERSION, /* the end */
606};
607
608/** @} */
609
610
611
612
613/** @name Raw-Mode Context Driver Helpers
614 * @{
615 */
616
617/** @interface_method_impl{PDMDRVHLPRC,pfnVMSetError} */
618static DECLCALLBACK(int) pdmRCDrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
619{
620 PDMDRV_ASSERT_DRVINS(pDrvIns);
621 va_list args;
622 va_start(args, pszFormat);
623 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMRC, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
624 va_end(args);
625 return rc;
626}
627
628
629/** @interface_method_impl{PDMDRVHLPRC,pfnVMSetErrorV} */
630static DECLCALLBACK(int) pdmRCDrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
631{
632 PDMDRV_ASSERT_DRVINS(pDrvIns);
633 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMRC, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
634 return rc;
635}
636
637
638/** @interface_method_impl{PDMDRVHLPRC,pfnVMSetRuntimeError} */
639static DECLCALLBACK(int) pdmRCDrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
640{
641 PDMDRV_ASSERT_DRVINS(pDrvIns);
642 va_list va;
643 va_start(va, pszFormat);
644 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMRC, fFlags, pszErrorId, pszFormat, va);
645 va_end(va);
646 return rc;
647}
648
649
650/** @interface_method_impl{PDMDRVHLPRC,pfnVMSetErrorV} */
651static DECLCALLBACK(int) pdmRCDrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
652{
653 PDMDRV_ASSERT_DRVINS(pDrvIns);
654 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMRC, fFlags, pszErrorId, pszFormat, va);
655 return rc;
656}
657
658
659/** @interface_method_impl{PDMDRVHLPRC,pfnAssertEMT} */
660static DECLCALLBACK(bool) pdmRCDrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
661{
662 PDMDRV_ASSERT_DRVINS(pDrvIns);
663 if (VM_IS_EMT(pDrvIns->Internal.s.pVMRC))
664 return true;
665
666 RTAssertMsg1Weak("AssertEMT", iLine, pszFile, pszFunction);
667 RTAssertPanic();
668 return false;
669}
670
671
672/** @interface_method_impl{PDMDRVHLPRC,pfnAssertOther} */
673static DECLCALLBACK(bool) pdmRCDrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
674{
675 PDMDRV_ASSERT_DRVINS(pDrvIns);
676 if (!VM_IS_EMT(pDrvIns->Internal.s.pVMRC))
677 return true;
678
679 /* Note: While we don't have any other threads but EMT(0) in RC, might
680 still have drive code compiled in which it shouldn't execute. */
681 RTAssertMsg1Weak("AssertOther", iLine, pszFile, pszFunction);
682 RTAssertPanic();
683 return false;
684}
685
686
687/**
688 * The Raw-Mode Context Driver Helper Callbacks.
689 */
690extern DECLEXPORT(const PDMDRVHLPRC) g_pdmRCDrvHlp =
691{
692 PDM_DRVHLPRC_VERSION,
693 pdmRCDrvHlp_VMSetError,
694 pdmRCDrvHlp_VMSetErrorV,
695 pdmRCDrvHlp_VMSetRuntimeError,
696 pdmRCDrvHlp_VMSetRuntimeErrorV,
697 pdmRCDrvHlp_AssertEMT,
698 pdmRCDrvHlp_AssertOther,
699 PDM_DRVHLPRC_VERSION
700};
701
702/** @} */
703
704
705
706
707/**
708 * Sets an irq on the I/O APIC.
709 *
710 * @param pVM The VM handle.
711 * @param iIrq The irq.
712 * @param iLevel The new level.
713 */
714static void pdmRCIsaSetIrq(PVM pVM, int iIrq, int iLevel)
715{
716 if ( ( pVM->pdm.s.IoApic.pDevInsRC
717 || !pVM->pdm.s.IoApic.pDevInsR3)
718 && ( pVM->pdm.s.Pic.pDevInsRC
719 || !pVM->pdm.s.Pic.pDevInsR3))
720 {
721 pdmLock(pVM);
722 if (pVM->pdm.s.Pic.pDevInsRC)
723 pVM->pdm.s.Pic.pfnSetIrqRC(pVM->pdm.s.Pic.pDevInsRC, iIrq, iLevel);
724 if (pVM->pdm.s.IoApic.pDevInsRC)
725 pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel);
726 pdmUnlock(pVM);
727 }
728 else
729 {
730 /* queue for ring-3 execution. */
731 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
732 if (pTask)
733 {
734 pTask->enmOp = PDMDEVHLPTASKOP_ISA_SET_IRQ;
735 pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
736 pTask->u.SetIRQ.iIrq = iIrq;
737 pTask->u.SetIRQ.iLevel = iLevel;
738
739 PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
740 }
741 else
742 AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
743 }
744}
745
746
747/**
748 * Sets an irq on the I/O APIC.
749 *
750 * @param pVM The VM handle.
751 * @param iIrq The irq.
752 * @param iLevel The new level.
753 */
754static void pdmRCIoApicSetIrq(PVM pVM, int iIrq, int iLevel)
755{
756 if (pVM->pdm.s.IoApic.pDevInsRC)
757 {
758 pdmLock(pVM);
759 pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel);
760 pdmUnlock(pVM);
761 }
762 else if (pVM->pdm.s.IoApic.pDevInsR3)
763 {
764 /* queue for ring-3 execution. */
765 PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
766 if (pTask)
767 {
768 pTask->enmOp = PDMDEVHLPTASKOP_IOAPIC_SET_IRQ;
769 pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
770 pTask->u.SetIRQ.iIrq = iIrq;
771 pTask->u.SetIRQ.iLevel = iLevel;
772
773 PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
774 }
775 else
776 AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
777 }
778}
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