VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMRC/PDMRCDevice.cpp@ 35335

Last change on this file since 35335 was 35335, checked in by vboxsync, 14 years ago

VMM source reorg: VMMGC -> VMMRC.

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