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