VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/PDMDevMiscHlp.cpp@ 62596

Last change on this file since 62596 was 62478, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 28.0 KB
Line 
1/* $Id: PDMDevMiscHlp.cpp 62478 2016-07-22 18:29:06Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, Misc. Device Helpers.
4 */
5
6/*
7 * Copyright (C) 2006-2016 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/vmm/pdm.h>
25#include <VBox/vmm/pgm.h>
26#include <VBox/vmm/hm.h>
27#ifdef VBOX_WITH_REM
28# include <VBox/vmm/rem.h>
29#endif
30#include <VBox/vmm/vm.h>
31#include <VBox/vmm/vmm.h>
32
33#include <VBox/log.h>
34#include <VBox/err.h>
35#include <iprt/asm.h>
36#include <iprt/assert.h>
37#include <iprt/thread.h>
38
39
40#include "PDMInline.h"
41#include "dtrace/VBoxVMM.h"
42
43
44
45/** @name Ring-3 PIC Helpers
46 * @{
47 */
48
49/** @interface_method_impl{PDMPICHLPR3,pfnSetInterruptFF} */
50static DECLCALLBACK(void) pdmR3PicHlp_SetInterruptFF(PPDMDEVINS pDevIns)
51{
52 PDMDEV_ASSERT_DEVINS(pDevIns);
53 PVM pVM = pDevIns->Internal.s.pVMR3;
54 PVMCPU pVCpu = &pVM->aCpus[0]; /* for PIC we always deliver to CPU 0, MP use APIC */
55
56 if (pVM->pdm.s.Apic.pfnLocalInterruptR3)
57 {
58 LogFlow(("pdmR3PicHlp_SetInterruptFF: caller='%s'/%d: Setting local interrupt on LAPIC\n",
59 pDevIns->pReg->szName, pDevIns->iInstance));
60
61 /* Raise the LAPIC's LINT0 line instead of signaling the CPU directly. */
62 /** @todo 'rcRZ' propagation to pfnLocalInterrupt from caller. */
63 pVM->pdm.s.Apic.pfnLocalInterruptR3(pVM->pdm.s.Apic.pDevInsR3, pVCpu, 0 /* u8Pin */, 1 /* u8Level */,
64 VINF_SUCCESS /* rcRZ */);
65 return;
66 }
67
68 LogFlow(("pdmR3PicHlp_SetInterruptFF: caller='%s'/%d: VMCPU_FF_INTERRUPT_PIC %d -> 1\n",
69 pDevIns->pReg->szName, pDevIns->iInstance, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC)));
70
71 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
72#ifdef VBOX_WITH_REM
73 REMR3NotifyInterruptSet(pVM, pVCpu);
74#endif
75 VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM | VMNOTIFYFF_FLAGS_POKE);
76}
77
78
79/** @interface_method_impl{PDMPICHLPR3,pfnClearInterruptFF} */
80static DECLCALLBACK(void) pdmR3PicHlp_ClearInterruptFF(PPDMDEVINS pDevIns)
81{
82 PDMDEV_ASSERT_DEVINS(pDevIns);
83 PVM pVM = pDevIns->Internal.s.pVMR3;
84 PVMCPU pVCpu = &pVM->aCpus[0]; /* for PIC we always deliver to CPU 0, MP use APIC */
85
86 if (pVM->pdm.s.Apic.pfnLocalInterruptR3)
87 {
88 /* Raise the LAPIC's LINT0 line instead of signaling the CPU directly. */
89 LogFlow(("pdmR3PicHlp_ClearInterruptFF: caller='%s'/%d: Clearing local interrupt on LAPIC\n",
90 pDevIns->pReg->szName, pDevIns->iInstance));
91
92 /* Lower the LAPIC's LINT0 line instead of signaling the CPU directly. */
93 /** @todo 'rcRZ' propagation to pfnLocalInterrupt from caller. */
94 pVM->pdm.s.Apic.pfnLocalInterruptR3(pVM->pdm.s.Apic.pDevInsR3, pVCpu, 0 /* u8Pin */, 0 /* u8Level */,
95 VINF_SUCCESS /* rcRZ */);
96 return;
97 }
98
99 LogFlow(("pdmR3PicHlp_ClearInterruptFF: caller='%s'/%d: VMCPU_FF_INTERRUPT_PIC %d -> 0\n",
100 pDevIns->pReg->szName, pDevIns->iInstance, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC)));
101
102 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
103#ifdef VBOX_WITH_REM
104 REMR3NotifyInterruptClear(pVM, pVCpu);
105#endif
106}
107
108
109/** @interface_method_impl{PDMPICHLPR3,pfnLock} */
110static DECLCALLBACK(int) pdmR3PicHlp_Lock(PPDMDEVINS pDevIns, int rc)
111{
112 PDMDEV_ASSERT_DEVINS(pDevIns);
113 return pdmLockEx(pDevIns->Internal.s.pVMR3, rc);
114}
115
116
117/** @interface_method_impl{PDMPICHLPR3,pfnUnlock} */
118static DECLCALLBACK(void) pdmR3PicHlp_Unlock(PPDMDEVINS pDevIns)
119{
120 PDMDEV_ASSERT_DEVINS(pDevIns);
121 pdmUnlock(pDevIns->Internal.s.pVMR3);
122}
123
124
125/** @interface_method_impl{PDMPICHLPR3,pfnGetRCHelpers} */
126static DECLCALLBACK(PCPDMPICHLPRC) pdmR3PicHlp_GetRCHelpers(PPDMDEVINS pDevIns)
127{
128 PDMDEV_ASSERT_DEVINS(pDevIns);
129 PVM pVM = pDevIns->Internal.s.pVMR3;
130 VM_ASSERT_EMT(pVM);
131
132 RTRCPTR pRCHelpers = NIL_RTRCPTR;
133 if (!HMIsEnabled(pVM))
134 {
135 int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCPicHlp", &pRCHelpers);
136 AssertReleaseRC(rc);
137 AssertRelease(pRCHelpers);
138 }
139
140 LogFlow(("pdmR3PicHlp_GetRCHelpers: caller='%s'/%d: returns %RRv\n",
141 pDevIns->pReg->szName, pDevIns->iInstance, pRCHelpers));
142 return pRCHelpers;
143}
144
145
146/** @interface_method_impl{PDMPICHLPR3,pfnGetR0Helpers} */
147static DECLCALLBACK(PCPDMPICHLPR0) pdmR3PicHlp_GetR0Helpers(PPDMDEVINS pDevIns)
148{
149 PDMDEV_ASSERT_DEVINS(pDevIns);
150 PVM pVM = pDevIns->Internal.s.pVMR3;
151 VM_ASSERT_EMT(pVM);
152 PCPDMPICHLPR0 pR0Helpers = 0;
153 int rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0PicHlp", &pR0Helpers);
154 AssertReleaseRC(rc);
155 AssertRelease(pR0Helpers);
156 LogFlow(("pdmR3PicHlp_GetR0Helpers: caller='%s'/%d: returns %RHv\n",
157 pDevIns->pReg->szName, pDevIns->iInstance, pR0Helpers));
158 return pR0Helpers;
159}
160
161
162/**
163 * PIC Device Helpers.
164 */
165const PDMPICHLPR3 g_pdmR3DevPicHlp =
166{
167 PDM_PICHLPR3_VERSION,
168 pdmR3PicHlp_SetInterruptFF,
169 pdmR3PicHlp_ClearInterruptFF,
170 pdmR3PicHlp_Lock,
171 pdmR3PicHlp_Unlock,
172 pdmR3PicHlp_GetRCHelpers,
173 pdmR3PicHlp_GetR0Helpers,
174 PDM_PICHLPR3_VERSION /* the end */
175};
176
177/** @} */
178
179
180
181
182/** @name R3 APIC Helpers
183 * @{
184 */
185
186/** @interface_method_impl{PDMAPICHLPR3,pfnSetInterruptFF} */
187static DECLCALLBACK(void) pdmR3ApicHlp_SetInterruptFF(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu)
188{
189 PDMDEV_ASSERT_DEVINS(pDevIns);
190 PVM pVM = pDevIns->Internal.s.pVMR3;
191 PVMCPU pVCpu = &pVM->aCpus[idCpu];
192
193 AssertReturnVoid(idCpu < pVM->cCpus);
194
195 LogFlow(("pdmR3ApicHlp_SetInterruptFF: caller='%s'/%d: VMCPU_FF_INTERRUPT_APIC(%d) %d -> 1\n",
196 pDevIns->pReg->szName, pDevIns->iInstance, idCpu, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC)));
197
198 switch (enmType)
199 {
200 case PDMAPICIRQ_UPDATE_PENDING:
201 VMCPU_FF_SET(pVCpu, VMCPU_FF_UPDATE_APIC);
202 break;
203 case PDMAPICIRQ_HARDWARE:
204#ifdef VBOX_WITH_NEW_APIC
205 VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu);
206#endif
207 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC);
208 break;
209 case PDMAPICIRQ_NMI:
210 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_NMI);
211 break;
212 case PDMAPICIRQ_SMI:
213 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_SMI);
214 break;
215 case PDMAPICIRQ_EXTINT:
216 VMCPU_FF_SET(pVCpu, VMCPU_FF_INTERRUPT_PIC);
217 break;
218 default:
219 AssertMsgFailed(("enmType=%d\n", enmType));
220 break;
221 }
222#ifdef VBOX_WITH_REM
223 REMR3NotifyInterruptSet(pVM, pVCpu);
224#endif
225
226#ifdef VBOX_WITH_NEW_APIC
227 if (enmType != PDMAPICIRQ_HARDWARE)
228 VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM | VMNOTIFYFF_FLAGS_POKE);
229#else
230 VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM | VMNOTIFYFF_FLAGS_POKE);
231#endif
232}
233
234
235/** @interface_method_impl{PDMAPICHLPR3,pfnClearInterruptFF} */
236static DECLCALLBACK(void) pdmR3ApicHlp_ClearInterruptFF(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu)
237{
238 PDMDEV_ASSERT_DEVINS(pDevIns);
239 PVM pVM = pDevIns->Internal.s.pVMR3;
240 PVMCPU pVCpu = &pVM->aCpus[idCpu];
241
242 AssertReturnVoid(idCpu < pVM->cCpus);
243
244 LogFlow(("pdmR3ApicHlp_ClearInterruptFF: caller='%s'/%d: VMCPU_FF_INTERRUPT_APIC(%d) %d -> 0\n",
245 pDevIns->pReg->szName, pDevIns->iInstance, idCpu, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INTERRUPT_APIC)));
246
247 /* Note: NMI/SMI can't be cleared. */
248 switch (enmType)
249 {
250 case PDMAPICIRQ_HARDWARE:
251 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
252 break;
253 case PDMAPICIRQ_EXTINT:
254 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
255 break;
256 case PDMAPICIRQ_UPDATE_PENDING:
257 VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu);
258 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_UPDATE_APIC);
259 break;
260 default:
261 AssertMsgFailed(("enmType=%d\n", enmType));
262 break;
263 }
264#ifdef VBOX_WITH_REM
265 REMR3NotifyInterruptClear(pVM, pVCpu);
266#endif
267}
268
269
270/** @interface_method_impl{PDMAPICHLPR3,pfnBusBroadcastEoi} */
271static DECLCALLBACK(int) pdmR3ApicHlp_BusBroadcastEoi(PPDMDEVINS pDevIns, uint8_t u8Vector)
272{
273 /* pfnSetEoi will be NULL in the old IOAPIC code as it's not implemented. */
274#ifdef VBOX_WITH_NEW_IOAPIC
275 PDMDEV_ASSERT_DEVINS(pDevIns);
276 PVM pVM = pDevIns->Internal.s.CTX_SUFF(pVM);
277
278 /* At present, we support only a maximum of one I/O APIC per-VM. If we ever implement having
279 multiple I/O APICs per-VM, we'll have to broadcast this EOI to all of the I/O APICs. */
280 if (pVM->pdm.s.IoApic.CTX_SUFF(pDevIns))
281 {
282 Assert(pVM->pdm.s.IoApic.CTX_SUFF(pfnSetEoi));
283 return pVM->pdm.s.IoApic.CTX_SUFF(pfnSetEoi)(pVM->pdm.s.IoApic.CTX_SUFF(pDevIns), u8Vector);
284 }
285#endif
286 return VINF_SUCCESS;
287}
288
289
290/** @interface_method_impl{PDMAPICHLPR3,pfnCalcIrqTag} */
291static DECLCALLBACK(uint32_t) pdmR3ApicHlp_CalcIrqTag(PPDMDEVINS pDevIns, uint8_t u8Level)
292{
293 PDMDEV_ASSERT_DEVINS(pDevIns);
294 PVM pVM = pDevIns->Internal.s.pVMR3;
295 Assert(u8Level == PDM_IRQ_LEVEL_HIGH || u8Level == PDM_IRQ_LEVEL_FLIP_FLOP);
296
297 pdmLock(pVM);
298
299 uint32_t uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
300 if (u8Level == PDM_IRQ_LEVEL_HIGH)
301 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
302 else
303 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
304
305
306 pdmUnlock(pVM);
307 LogFlow(("pdmR3ApicHlp_CalcIrqTag: caller='%s'/%d: returns %#x (u8Level=%d)\n",
308 pDevIns->pReg->szName, pDevIns->iInstance, uTagSrc, u8Level));
309 return uTagSrc;
310}
311
312
313/** @interface_method_impl{PDMAPICHLPR3,pfnSetFeatureLevel} */
314static DECLCALLBACK(void) pdmR3ApicHlp_SetFeatureLevel(PPDMDEVINS pDevIns, PDMAPICMODE enmMode)
315{
316 PDMDEV_ASSERT_DEVINS(pDevIns);
317 LogFlow(("pdmR3ApicHlp_SetFeatureLevel: caller='%s'/%d: mode=%d\n",
318 pDevIns->pReg->szName, pDevIns->iInstance, (int)enmMode));
319 switch (enmMode)
320 {
321 case PDMAPICMODE_NONE:
322 CPUMR3ClearGuestCpuIdFeature(pDevIns->Internal.s.pVMR3, CPUMCPUIDFEATURE_X2APIC);
323 CPUMR3ClearGuestCpuIdFeature(pDevIns->Internal.s.pVMR3, CPUMCPUIDFEATURE_APIC);
324 break;
325 case PDMAPICMODE_APIC:
326 CPUMR3ClearGuestCpuIdFeature(pDevIns->Internal.s.pVMR3, CPUMCPUIDFEATURE_X2APIC);
327 CPUMR3SetGuestCpuIdFeature(pDevIns->Internal.s.pVMR3, CPUMCPUIDFEATURE_APIC);
328 break;
329 case PDMAPICMODE_X2APIC:
330 CPUMR3SetGuestCpuIdFeature(pDevIns->Internal.s.pVMR3, CPUMCPUIDFEATURE_APIC);
331 CPUMR3SetGuestCpuIdFeature(pDevIns->Internal.s.pVMR3, CPUMCPUIDFEATURE_X2APIC);
332 break;
333 default:
334 AssertMsgFailed(("Unknown APIC mode: %d\n", (int)enmMode));
335 }
336}
337
338/** @interface_method_impl{PDMAPICHLPR3,pfnGetCpuId} */
339static DECLCALLBACK(VMCPUID) pdmR3ApicHlp_GetCpuId(PPDMDEVINS pDevIns)
340{
341 PDMDEV_ASSERT_DEVINS(pDevIns);
342 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
343 return VMMGetCpuId(pDevIns->Internal.s.pVMR3);
344}
345
346
347/** @interface_method_impl{PDMAPICHLPR3,pfnSendStartupIpi} */
348static DECLCALLBACK(void) pdmR3ApicHlp_SendStartupIpi(PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t uVector)
349{
350 PDMDEV_ASSERT_DEVINS(pDevIns);
351 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
352 VMMR3SendStartupIpi(pDevIns->Internal.s.pVMR3, idCpu, uVector);
353}
354
355
356/** @interface_method_impl{PDMAPICHLPR3,pfnSendInitIpi} */
357static DECLCALLBACK(void) pdmR3ApicHlp_SendInitIpi(PPDMDEVINS pDevIns, VMCPUID idCpu)
358{
359 PDMDEV_ASSERT_DEVINS(pDevIns);
360 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
361 VMMR3SendInitIpi(pDevIns->Internal.s.pVMR3, idCpu);
362}
363
364
365/** @interface_method_impl{PDMAPICHLPR3,pfnGetRCHelpers} */
366static DECLCALLBACK(PCPDMAPICHLPRC) pdmR3ApicHlp_GetRCHelpers(PPDMDEVINS pDevIns)
367{
368 PDMDEV_ASSERT_DEVINS(pDevIns);
369 PVM pVM = pDevIns->Internal.s.pVMR3;
370 VM_ASSERT_EMT(pVM);
371
372 RTRCPTR pRCHelpers = NIL_RTRCPTR;
373 if (!HMIsEnabled(pVM))
374 {
375 int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCApicHlp", &pRCHelpers);
376 AssertReleaseRC(rc);
377 AssertRelease(pRCHelpers);
378 }
379
380 LogFlow(("pdmR3ApicHlp_GetRCHelpers: caller='%s'/%d: returns %RRv\n",
381 pDevIns->pReg->szName, pDevIns->iInstance, pRCHelpers));
382 return pRCHelpers;
383}
384
385
386/** @interface_method_impl{PDMAPICHLPR3,pfnGetR0Helpers} */
387static DECLCALLBACK(PCPDMAPICHLPR0) pdmR3ApicHlp_GetR0Helpers(PPDMDEVINS pDevIns)
388{
389 PDMDEV_ASSERT_DEVINS(pDevIns);
390 PVM pVM = pDevIns->Internal.s.pVMR3;
391 VM_ASSERT_EMT(pVM);
392 PCPDMAPICHLPR0 pR0Helpers = 0;
393 int rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0ApicHlp", &pR0Helpers);
394 AssertReleaseRC(rc);
395 AssertRelease(pR0Helpers);
396 LogFlow(("pdmR3ApicHlp_GetR0Helpers: caller='%s'/%d: returns %RHv\n",
397 pDevIns->pReg->szName, pDevIns->iInstance, pR0Helpers));
398 return pR0Helpers;
399}
400
401
402/** @interface_method_impl{PDMAPICHLPR3,pfnGetR3CritSect} */
403static DECLCALLBACK(R3PTRTYPE(PPDMCRITSECT)) pdmR3ApicHlp_GetR3CritSect(PPDMDEVINS pDevIns)
404{
405 PDMDEV_ASSERT_DEVINS(pDevIns);
406 LogFlow(("pdmR3ApicHlp_Lock: caller='%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
407 return &pDevIns->Internal.s.pVMR3->pdm.s.CritSect;
408}
409
410
411/** @interface_method_impl{PDMAPICHLPR3,pfnGetRCCritSect} */
412static DECLCALLBACK(RCPTRTYPE(PPDMCRITSECT)) pdmR3ApicHlp_GetRCCritSect(PPDMDEVINS pDevIns)
413{
414 PDMDEV_ASSERT_DEVINS(pDevIns);
415 PVM pVM = pDevIns->Internal.s.pVMR3;
416 RTRCPTR RCPtr = MMHyperCCToRC(pVM, &pVM->pdm.s.CritSect);
417 LogFlow(("pdmR3ApicHlp_GetR0CritSect: caller='%s'/%d: return %RRv\n", pDevIns->pReg->szName, pDevIns->iInstance, RCPtr));
418 return RCPtr;
419}
420
421
422/** @interface_method_impl{PDMAPICHLPR3,pfnGetR3CritSect} */
423static DECLCALLBACK(R0PTRTYPE(PPDMCRITSECT)) pdmR3ApicHlp_GetR0CritSect(PPDMDEVINS pDevIns)
424{
425 PDMDEV_ASSERT_DEVINS(pDevIns);
426 PVM pVM = pDevIns->Internal.s.pVMR3;
427 RTR0PTR R0Ptr = MMHyperCCToR0(pVM, &pVM->pdm.s.CritSect);
428 LogFlow(("pdmR3ApicHlp_GetR0CritSect: caller='%s'/%d: return %RHv\n", pDevIns->pReg->szName, pDevIns->iInstance, R0Ptr));
429 return R0Ptr;
430}
431
432
433
434/**
435 * APIC Device Helpers.
436 */
437const PDMAPICHLPR3 g_pdmR3DevApicHlp =
438{
439 PDM_APICHLPR3_VERSION,
440 pdmR3ApicHlp_SetInterruptFF,
441 pdmR3ApicHlp_ClearInterruptFF,
442 pdmR3ApicHlp_BusBroadcastEoi,
443 pdmR3ApicHlp_CalcIrqTag,
444 pdmR3ApicHlp_SetFeatureLevel,
445 pdmR3ApicHlp_GetCpuId,
446 pdmR3ApicHlp_SendStartupIpi,
447 pdmR3ApicHlp_SendInitIpi,
448 pdmR3ApicHlp_GetRCHelpers,
449 pdmR3ApicHlp_GetR0Helpers,
450 pdmR3ApicHlp_GetR3CritSect,
451 pdmR3ApicHlp_GetRCCritSect,
452 pdmR3ApicHlp_GetR0CritSect,
453 PDM_APICHLPR3_VERSION /* the end */
454};
455
456/** @} */
457
458
459
460
461/** @name Ring-3 I/O APIC Helpers
462 * @{
463 */
464
465/** @interface_method_impl{PDMIOAPICHLPR3,pfnApicBusDeliver} */
466static DECLCALLBACK(int) pdmR3IoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
467 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc)
468{
469 PDMDEV_ASSERT_DEVINS(pDevIns);
470 PVM pVM = pDevIns->Internal.s.pVMR3;
471 LogFlow(("pdmR3IoApicHlp_ApicBusDeliver: caller='%s'/%d: u8Dest=%RX8 u8DestMode=%RX8 u8DeliveryMode=%RX8 iVector=%RX8 u8Polarity=%RX8 u8TriggerMode=%RX8 uTagSrc=%#x\n",
472 pDevIns->pReg->szName, pDevIns->iInstance, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode, uTagSrc));
473 if (pVM->pdm.s.Apic.pfnBusDeliverR3)
474 return pVM->pdm.s.Apic.pfnBusDeliverR3(pVM->pdm.s.Apic.pDevInsR3, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode, uTagSrc);
475 return VINF_SUCCESS;
476}
477
478
479/** @interface_method_impl{PDMIOAPICHLPR3,pfnLock} */
480static DECLCALLBACK(int) pdmR3IoApicHlp_Lock(PPDMDEVINS pDevIns, int rc)
481{
482 PDMDEV_ASSERT_DEVINS(pDevIns);
483 LogFlow(("pdmR3IoApicHlp_Lock: caller='%s'/%d: rc=%Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
484 return pdmLockEx(pDevIns->Internal.s.pVMR3, rc);
485}
486
487
488/** @interface_method_impl{PDMIOAPICHLPR3,pfnUnlock} */
489static DECLCALLBACK(void) pdmR3IoApicHlp_Unlock(PPDMDEVINS pDevIns)
490{
491 PDMDEV_ASSERT_DEVINS(pDevIns);
492 LogFlow(("pdmR3IoApicHlp_Unlock: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
493 pdmUnlock(pDevIns->Internal.s.pVMR3);
494}
495
496
497/** @interface_method_impl{PDMIOAPICHLPR3,pfnGetRCHelpers} */
498static DECLCALLBACK(PCPDMIOAPICHLPRC) pdmR3IoApicHlp_GetRCHelpers(PPDMDEVINS pDevIns)
499{
500 PDMDEV_ASSERT_DEVINS(pDevIns);
501 PVM pVM = pDevIns->Internal.s.pVMR3;
502 VM_ASSERT_EMT(pVM);
503
504 RTRCPTR pRCHelpers = NIL_RTRCPTR;
505 if (!HMIsEnabled(pVM))
506 {
507 int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCIoApicHlp", &pRCHelpers);
508 AssertReleaseRC(rc);
509 AssertRelease(pRCHelpers);
510 }
511
512 LogFlow(("pdmR3IoApicHlp_GetRCHelpers: caller='%s'/%d: returns %RRv\n",
513 pDevIns->pReg->szName, pDevIns->iInstance, pRCHelpers));
514 return pRCHelpers;
515}
516
517
518/** @interface_method_impl{PDMIOAPICHLPR3,pfnGetR0Helpers} */
519static DECLCALLBACK(PCPDMIOAPICHLPR0) pdmR3IoApicHlp_GetR0Helpers(PPDMDEVINS pDevIns)
520{
521 PDMDEV_ASSERT_DEVINS(pDevIns);
522 PVM pVM = pDevIns->Internal.s.pVMR3;
523 VM_ASSERT_EMT(pVM);
524 PCPDMIOAPICHLPR0 pR0Helpers = 0;
525 int rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0IoApicHlp", &pR0Helpers);
526 AssertReleaseRC(rc);
527 AssertRelease(pR0Helpers);
528 LogFlow(("pdmR3IoApicHlp_GetR0Helpers: caller='%s'/%d: returns %RHv\n",
529 pDevIns->pReg->szName, pDevIns->iInstance, pR0Helpers));
530 return pR0Helpers;
531}
532
533
534/**
535 * I/O APIC Device Helpers.
536 */
537const PDMIOAPICHLPR3 g_pdmR3DevIoApicHlp =
538{
539 PDM_IOAPICHLPR3_VERSION,
540 pdmR3IoApicHlp_ApicBusDeliver,
541 pdmR3IoApicHlp_Lock,
542 pdmR3IoApicHlp_Unlock,
543 pdmR3IoApicHlp_GetRCHelpers,
544 pdmR3IoApicHlp_GetR0Helpers,
545 PDM_IOAPICHLPR3_VERSION /* the end */
546};
547
548/** @} */
549
550
551
552
553/** @name Ring-3 PCI Bus Helpers
554 * @{
555 */
556
557/** @interface_method_impl{PDMPCIHLPR3,pfnIsaSetIrq} */
558static DECLCALLBACK(void) pdmR3PciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc)
559{
560 PDMDEV_ASSERT_DEVINS(pDevIns);
561 Log4(("pdmR3PciHlp_IsaSetIrq: iIrq=%d iLevel=%d uTagSrc=%#x\n", iIrq, iLevel, uTagSrc));
562 PVM pVM = pDevIns->Internal.s.pVMR3;
563 PDMIsaSetIrq(pDevIns->Internal.s.pVMR3, iIrq, iLevel, uTagSrc);
564}
565
566/** @interface_method_impl{PDMPCIHLPR3,pfnIoApicSetIrq} */
567static DECLCALLBACK(void) pdmR3PciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc)
568{
569 PDMDEV_ASSERT_DEVINS(pDevIns);
570 Log4(("pdmR3PciHlp_IoApicSetIrq: iIrq=%d iLevel=%d uTagSrc=%#x\n", iIrq, iLevel, uTagSrc));
571 PDMIoApicSetIrq(pDevIns->Internal.s.pVMR3, iIrq, iLevel, uTagSrc);
572}
573
574/** @interface_method_impl{PDMPCIHLPR3,pfnIoApicSendMsi} */
575static DECLCALLBACK(void) pdmR3PciHlp_IoApicSendMsi(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc)
576{
577 PDMDEV_ASSERT_DEVINS(pDevIns);
578 Log4(("pdmR3PciHlp_IoApicSendMsi: address=%p value=%x uTagSrc=%#x\n", GCPhys, uValue, uTagSrc));
579 PDMIoApicSendMsi(pDevIns->Internal.s.pVMR3, GCPhys, uValue, uTagSrc);
580}
581
582/** @interface_method_impl{PDMPCIHLPR3,pfnIsMMIO2Base} */
583static DECLCALLBACK(bool) pdmR3PciHlp_IsMMIO2Base(PPDMDEVINS pDevIns, PPDMDEVINS pOwner, RTGCPHYS GCPhys)
584{
585 PDMDEV_ASSERT_DEVINS(pDevIns);
586 VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
587 bool fRc = PGMR3PhysMMIO2IsBase(pDevIns->Internal.s.pVMR3, pOwner, GCPhys);
588 Log4(("pdmR3PciHlp_IsMMIO2Base: pOwner=%p GCPhys=%RGp -> %RTbool\n", pOwner, GCPhys, fRc));
589 return fRc;
590}
591
592
593/** @interface_method_impl{PDMPCIHLPR3,pfnLock} */
594static DECLCALLBACK(int) pdmR3PciHlp_Lock(PPDMDEVINS pDevIns, int rc)
595{
596 PDMDEV_ASSERT_DEVINS(pDevIns);
597 LogFlow(("pdmR3PciHlp_Lock: caller='%s'/%d: rc=%Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
598 return pdmLockEx(pDevIns->Internal.s.pVMR3, rc);
599}
600
601
602/** @interface_method_impl{PDMPCIHLPR3,pfnUnlock} */
603static DECLCALLBACK(void) pdmR3PciHlp_Unlock(PPDMDEVINS pDevIns)
604{
605 PDMDEV_ASSERT_DEVINS(pDevIns);
606 LogFlow(("pdmR3PciHlp_Unlock: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
607 pdmUnlock(pDevIns->Internal.s.pVMR3);
608}
609
610
611/** @interface_method_impl{PDMPCIHLPR3,pfnGetRCHelpers} */
612static DECLCALLBACK(PCPDMPCIHLPRC) pdmR3PciHlp_GetRCHelpers(PPDMDEVINS pDevIns)
613{
614 PDMDEV_ASSERT_DEVINS(pDevIns);
615 PVM pVM = pDevIns->Internal.s.pVMR3;
616 VM_ASSERT_EMT(pVM);
617
618 RTRCPTR pRCHelpers = NIL_RTRCPTR;
619 if (!HMIsEnabled(pVM))
620 {
621 int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCPciHlp", &pRCHelpers);
622 AssertReleaseRC(rc);
623 AssertRelease(pRCHelpers);
624 }
625
626 LogFlow(("pdmR3PciHlp_GetRCHelpers: caller='%s'/%d: returns %RRv\n",
627 pDevIns->pReg->szName, pDevIns->iInstance, pRCHelpers));
628 return pRCHelpers;
629}
630
631
632/** @interface_method_impl{PDMPCIHLPR3,pfnGetR0Helpers} */
633static DECLCALLBACK(PCPDMPCIHLPR0) pdmR3PciHlp_GetR0Helpers(PPDMDEVINS pDevIns)
634{
635 PDMDEV_ASSERT_DEVINS(pDevIns);
636 PVM pVM = pDevIns->Internal.s.pVMR3;
637 VM_ASSERT_EMT(pVM);
638 PCPDMPCIHLPR0 pR0Helpers = 0;
639 int rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0PciHlp", &pR0Helpers);
640 AssertReleaseRC(rc);
641 AssertRelease(pR0Helpers);
642 LogFlow(("pdmR3PciHlp_GetR0Helpers: caller='%s'/%d: returns %RHv\n",
643 pDevIns->pReg->szName, pDevIns->iInstance, pR0Helpers));
644 return pR0Helpers;
645}
646
647
648/**
649 * PCI Bus Device Helpers.
650 */
651const PDMPCIHLPR3 g_pdmR3DevPciHlp =
652{
653 PDM_PCIHLPR3_VERSION,
654 pdmR3PciHlp_IsaSetIrq,
655 pdmR3PciHlp_IoApicSetIrq,
656 pdmR3PciHlp_IoApicSendMsi,
657 pdmR3PciHlp_IsMMIO2Base,
658 pdmR3PciHlp_GetRCHelpers,
659 pdmR3PciHlp_GetR0Helpers,
660 pdmR3PciHlp_Lock,
661 pdmR3PciHlp_Unlock,
662 PDM_PCIHLPR3_VERSION, /* the end */
663};
664
665/** @} */
666
667
668
669
670/** @name Ring-3 HPET Helpers
671 * {@
672 */
673
674/** @interface_method_impl{PDMHPETHLPR3,pfnSetLegacyMode} */
675static DECLCALLBACK(int) pdmR3HpetHlp_SetLegacyMode(PPDMDEVINS pDevIns, bool fActivated)
676{
677 PDMDEV_ASSERT_DEVINS(pDevIns);
678 LogFlow(("pdmR3HpetHlp_SetLegacyMode: caller='%s'/%d: fActivated=%RTbool\n", pDevIns->pReg->szName, pDevIns->iInstance, fActivated));
679
680 size_t i;
681 int rc = VINF_SUCCESS;
682 static const char * const s_apszDevsToNotify[] =
683 {
684 "i8254",
685 "mc146818"
686 };
687 for (i = 0; i < RT_ELEMENTS(s_apszDevsToNotify); i++)
688 {
689 PPDMIBASE pBase;
690 rc = PDMR3QueryDevice(pDevIns->Internal.s.pVMR3->pUVM, "i8254", 0, &pBase);
691 if (RT_SUCCESS(rc))
692 {
693 PPDMIHPETLEGACYNOTIFY pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIHPETLEGACYNOTIFY);
694 AssertLogRelMsgBreakStmt(pPort, ("%s\n", s_apszDevsToNotify[i]), rc = VERR_PDM_HPET_LEGACY_NOTIFY_MISSING);
695 pPort->pfnModeChanged(pPort, fActivated);
696 }
697 else if ( rc == VERR_PDM_DEVICE_NOT_FOUND
698 || rc == VERR_PDM_DEVICE_INSTANCE_NOT_FOUND)
699 rc = VINF_SUCCESS; /* the device isn't configured, ignore. */
700 else
701 AssertLogRelMsgFailedBreak(("%s -> %Rrc\n", s_apszDevsToNotify[i], rc));
702 }
703
704 /* Don't bother cleaning up, any failure here will cause a guru meditation. */
705
706 LogFlow(("pdmR3HpetHlp_SetLegacyMode: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
707 return rc;
708}
709
710
711/** @interface_method_impl{PDMHPETHLPR3,pfnSetIrq} */
712static DECLCALLBACK(int) pdmR3HpetHlp_SetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
713{
714 PDMDEV_ASSERT_DEVINS(pDevIns);
715 LogFlow(("pdmR3HpetHlp_SetIrq: caller='%s'/%d: iIrq=%d iLevel=%d\n", pDevIns->pReg->szName, pDevIns->iInstance, iIrq, iLevel));
716 PVM pVM = pDevIns->Internal.s.pVMR3;
717
718 pdmLock(pVM);
719 uint32_t uTagSrc;
720 if (iLevel & PDM_IRQ_LEVEL_HIGH)
721 {
722 pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
723 if (iLevel == PDM_IRQ_LEVEL_HIGH)
724 VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
725 else
726 VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
727 }
728 else
729 uTagSrc = pDevIns->Internal.s.uLastIrqTag;
730
731 PDMIsaSetIrq(pVM, iIrq, iLevel, uTagSrc); /* (The API takes the lock recursively.) */
732
733 if (iLevel == PDM_IRQ_LEVEL_LOW)
734 VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
735 pdmUnlock(pVM);
736 return 0;
737}
738
739
740/** @interface_method_impl{PDMHPETHLPR3,pfnGetRCHelpers} */
741static DECLCALLBACK(PCPDMHPETHLPRC) pdmR3HpetHlp_GetRCHelpers(PPDMDEVINS pDevIns)
742{
743 PDMDEV_ASSERT_DEVINS(pDevIns);
744 PVM pVM = pDevIns->Internal.s.pVMR3;
745 VM_ASSERT_EMT(pVM);
746
747 RTRCPTR pRCHelpers = NIL_RTRCPTR;
748 if (!HMIsEnabled(pVM))
749 {
750 int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCHpetHlp", &pRCHelpers);
751 AssertReleaseRC(rc);
752 AssertRelease(pRCHelpers);
753 }
754
755 LogFlow(("pdmR3HpetHlp_GetGCHelpers: caller='%s'/%d: returns %RRv\n",
756 pDevIns->pReg->szName, pDevIns->iInstance, pRCHelpers));
757 return pRCHelpers;
758}
759
760
761/** @interface_method_impl{PDMHPETHLPR3,pfnGetR0Helpers} */
762static DECLCALLBACK(PCPDMHPETHLPR0) pdmR3HpetHlp_GetR0Helpers(PPDMDEVINS pDevIns)
763{
764 PDMDEV_ASSERT_DEVINS(pDevIns);
765 PVM pVM = pDevIns->Internal.s.pVMR3;
766 VM_ASSERT_EMT(pVM);
767 PCPDMHPETHLPR0 pR0Helpers = 0;
768 int rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0HpetHlp", &pR0Helpers);
769 AssertReleaseRC(rc);
770 AssertRelease(pR0Helpers);
771 LogFlow(("pdmR3HpetHlp_GetR0Helpers: caller='%s'/%d: returns %RHv\n",
772 pDevIns->pReg->szName, pDevIns->iInstance, pR0Helpers));
773 return pR0Helpers;
774}
775
776
777/**
778 * HPET Device Helpers.
779 */
780const PDMHPETHLPR3 g_pdmR3DevHpetHlp =
781{
782 PDM_HPETHLPR3_VERSION,
783 pdmR3HpetHlp_GetRCHelpers,
784 pdmR3HpetHlp_GetR0Helpers,
785 pdmR3HpetHlp_SetLegacyMode,
786 pdmR3HpetHlp_SetIrq,
787 PDM_HPETHLPR3_VERSION, /* the end */
788};
789
790/** @} */
791
792
793/** @name Ring-3 Raw PCI Device Helpers
794 * {@
795 */
796
797/** @interface_method_impl{PDMPCIRAWHLPR3,pfnGetRCHelpers} */
798static DECLCALLBACK(PCPDMPCIRAWHLPRC) pdmR3PciRawHlp_GetRCHelpers(PPDMDEVINS pDevIns)
799{
800 PDMDEV_ASSERT_DEVINS(pDevIns);
801 PVM pVM = pDevIns->Internal.s.pVMR3;
802 VM_ASSERT_EMT(pVM);
803
804 RTRCPTR pRCHelpers = NIL_RTRCPTR;
805 if (!HMIsEnabled(pVM))
806 {
807 int rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCPciRawHlp", &pRCHelpers);
808 AssertReleaseRC(rc);
809 AssertRelease(pRCHelpers);
810 }
811
812 LogFlow(("pdmR3PciRawHlp_GetGCHelpers: caller='%s'/%d: returns %RRv\n",
813 pDevIns->pReg->szName, pDevIns->iInstance, pRCHelpers));
814 return pRCHelpers;
815}
816
817
818/** @interface_method_impl{PDMPCIRAWHLPR3,pfnGetR0Helpers} */
819static DECLCALLBACK(PCPDMPCIRAWHLPR0) pdmR3PciRawHlp_GetR0Helpers(PPDMDEVINS pDevIns)
820{
821 PDMDEV_ASSERT_DEVINS(pDevIns);
822 PVM pVM = pDevIns->Internal.s.pVMR3;
823 VM_ASSERT_EMT(pVM);
824 PCPDMHPETHLPR0 pR0Helpers = NIL_RTR0PTR;
825 int rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0PciRawHlp", &pR0Helpers);
826 AssertReleaseRC(rc);
827 AssertRelease(pR0Helpers);
828 LogFlow(("pdmR3PciRawHlp_GetR0Helpers: caller='%s'/%d: returns %RHv\n",
829 pDevIns->pReg->szName, pDevIns->iInstance, pR0Helpers));
830 return pR0Helpers;
831}
832
833
834/**
835 * Raw PCI Device Helpers.
836 */
837const PDMPCIRAWHLPR3 g_pdmR3DevPciRawHlp =
838{
839 PDM_PCIRAWHLPR3_VERSION,
840 pdmR3PciRawHlp_GetRCHelpers,
841 pdmR3PciRawHlp_GetR0Helpers,
842 PDM_PCIRAWHLPR3_VERSION, /* the end */
843};
844
845/** @} */
846
847
848/* none yet */
849
850/**
851 * Firmware Device Helpers.
852 */
853const PDMFWHLPR3 g_pdmR3DevFirmwareHlp =
854{
855 PDM_FWHLPR3_VERSION,
856 PDM_FWHLPR3_VERSION
857};
858
859/**
860 * DMAC Device Helpers.
861 */
862const PDMDMACHLP g_pdmR3DevDmacHlp =
863{
864 PDM_DMACHLP_VERSION
865};
866
867
868
869
870/* none yet */
871
872/**
873 * RTC Device Helpers.
874 */
875const PDMRTCHLP g_pdmR3DevRtcHlp =
876{
877 PDM_RTCHLP_VERSION
878};
879
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