1 | /* $Id: PDMR0DevHlpTracing.cpp 93609 2022-02-05 19:03:08Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM - Pluggable Device and Driver Manager, Device Helper variants when tracing is enabled.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-2022 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 | #define PDMPCIDEV_INCLUDE_PRIVATE /* Hack to get pdmpcidevint.h included at the right point. */
|
---|
24 | #include "PDMInternal.h"
|
---|
25 | #include <VBox/vmm/pdm.h>
|
---|
26 | #include <VBox/vmm/mm.h>
|
---|
27 | #include <VBox/vmm/hm.h>
|
---|
28 | #include <VBox/vmm/pgm.h>
|
---|
29 | #include <VBox/vmm/iom.h>
|
---|
30 | #include <VBox/vmm/dbgf.h>
|
---|
31 | #include <VBox/vmm/ssm.h>
|
---|
32 | #include <VBox/vmm/vmapi.h>
|
---|
33 | #include <VBox/vmm/vmm.h>
|
---|
34 | #include <VBox/vmm/vmcc.h>
|
---|
35 |
|
---|
36 | #include <VBox/version.h>
|
---|
37 | #include <VBox/log.h>
|
---|
38 | #include <VBox/err.h>
|
---|
39 | #include <iprt/asm.h>
|
---|
40 | #include <iprt/assert.h>
|
---|
41 | #include <iprt/ctype.h>
|
---|
42 | #include <iprt/string.h>
|
---|
43 | #include <iprt/thread.h>
|
---|
44 |
|
---|
45 | #include "dtrace/VBoxVMM.h"
|
---|
46 | #include "PDMInline.h"
|
---|
47 |
|
---|
48 |
|
---|
49 | /*********************************************************************************************************************************
|
---|
50 | * Defined Constants And Macros *
|
---|
51 | *********************************************************************************************************************************/
|
---|
52 | /** @name Ring-0 Device Helpers
|
---|
53 | * @{
|
---|
54 | */
|
---|
55 |
|
---|
56 |
|
---|
57 | static DECLCALLBACK(VBOXSTRICTRC) pdmR0DevHlpTracing_IoPortNewIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
|
---|
58 | {
|
---|
59 | PCPDMDEVINSDBGFTRACK pTrack = (PCPDMDEVINSDBGFTRACK)pvUser;
|
---|
60 |
|
---|
61 | Assert(!pTrack->fMmio);
|
---|
62 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
63 | VBOXSTRICTRC rcStrict = pTrack->u.IoPort.pfnIn(pDevIns, pTrack->pvUser, offPort, pu32, cb);
|
---|
64 | if (RT_SUCCESS(rcStrict))
|
---|
65 | DBGFTracerEvtIoPortRead(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, pTrack->u.IoPort.hIoPorts, offPort, pu32, cb);
|
---|
66 |
|
---|
67 | return rcStrict;
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | static DECLCALLBACK(VBOXSTRICTRC) pdmR0DevHlpTracing_IoPortNewInStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint8_t *pbDst,
|
---|
72 | uint32_t *pcTransfers, unsigned cb)
|
---|
73 | {
|
---|
74 | PCPDMDEVINSDBGFTRACK pTrack = (PCPDMDEVINSDBGFTRACK)pvUser;
|
---|
75 |
|
---|
76 | Assert(!pTrack->fMmio);
|
---|
77 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
78 | uint32_t cTransfersReq = *pcTransfers;
|
---|
79 | VBOXSTRICTRC rcStrict = pTrack->u.IoPort.pfnInStr(pDevIns, pTrack->pvUser, offPort, pbDst, pcTransfers, cb);
|
---|
80 | if (RT_SUCCESS(rcStrict))
|
---|
81 | DBGFTracerEvtIoPortReadStr(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, pTrack->u.IoPort.hIoPorts, offPort, pbDst, cb,
|
---|
82 | cTransfersReq, cTransfersReq - *pcTransfers);
|
---|
83 |
|
---|
84 | return rcStrict;
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | static DECLCALLBACK(VBOXSTRICTRC) pdmR0DevHlpTracing_IoPortNewOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
|
---|
89 | {
|
---|
90 | PCPDMDEVINSDBGFTRACK pTrack = (PCPDMDEVINSDBGFTRACK)pvUser;
|
---|
91 |
|
---|
92 | Assert(!pTrack->fMmio);
|
---|
93 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
94 | VBOXSTRICTRC rcStrict = pTrack->u.IoPort.pfnOut(pDevIns, pTrack->pvUser, offPort, u32, cb);
|
---|
95 | if (RT_SUCCESS(rcStrict))
|
---|
96 | DBGFTracerEvtIoPortWrite(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, pTrack->u.IoPort.hIoPorts, offPort, &u32, cb);
|
---|
97 |
|
---|
98 | return rcStrict;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | static DECLCALLBACK(VBOXSTRICTRC) pdmR0DevHlpTracing_IoPortNewOutStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, const uint8_t *pbSrc,
|
---|
103 | uint32_t *pcTransfers, unsigned cb)
|
---|
104 | {
|
---|
105 | PCPDMDEVINSDBGFTRACK pTrack = (PCPDMDEVINSDBGFTRACK)pvUser;
|
---|
106 |
|
---|
107 | Assert(!pTrack->fMmio);
|
---|
108 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
109 | uint32_t cTransfersReq = *pcTransfers;
|
---|
110 | VBOXSTRICTRC rcStrict = pTrack->u.IoPort.pfnOutStr(pDevIns, pTrack->pvUser, offPort, pbSrc, pcTransfers, cb);
|
---|
111 | if (RT_SUCCESS(rcStrict))
|
---|
112 | DBGFTracerEvtIoPortWriteStr(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, pTrack->u.IoPort.hIoPorts, offPort, pbSrc, cb,
|
---|
113 | cTransfersReq, cTransfersReq - *pcTransfers);
|
---|
114 |
|
---|
115 | return rcStrict;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | static DECLCALLBACK(VBOXSTRICTRC) pdmR0DevHlpTracing_MmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, uint32_t cb)
|
---|
120 | {
|
---|
121 | PCPDMDEVINSDBGFTRACK pTrack = (PCPDMDEVINSDBGFTRACK)pvUser;
|
---|
122 |
|
---|
123 | Assert(pTrack->fMmio);
|
---|
124 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
125 | VBOXSTRICTRC rcStrict = pTrack->u.Mmio.pfnRead(pDevIns, pTrack->pvUser, off, pv, cb);
|
---|
126 | if (RT_SUCCESS(rcStrict))
|
---|
127 | DBGFTracerEvtMmioRead(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, pTrack->u.Mmio.hMmioRegion, off, pv, cb);
|
---|
128 |
|
---|
129 | return rcStrict;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | static DECLCALLBACK(VBOXSTRICTRC) pdmR0DevHlpTracing_MmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, uint32_t cb)
|
---|
134 | {
|
---|
135 | PCPDMDEVINSDBGFTRACK pTrack = (PCPDMDEVINSDBGFTRACK)pvUser;
|
---|
136 |
|
---|
137 | Assert(pTrack->fMmio);
|
---|
138 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
139 | VBOXSTRICTRC rcStrict = pTrack->u.Mmio.pfnWrite(pDevIns, pTrack->pvUser, off, pv, cb);
|
---|
140 | if (RT_SUCCESS(rcStrict))
|
---|
141 | DBGFTracerEvtMmioWrite(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, pTrack->u.Mmio.hMmioRegion, off, pv, cb);
|
---|
142 |
|
---|
143 | return rcStrict;
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | static DECLCALLBACK(VBOXSTRICTRC) pdmR0DevHlpTracing_MmioFill(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off,
|
---|
148 | uint32_t u32Item, uint32_t cbItem, uint32_t cItems)
|
---|
149 | {
|
---|
150 | PCPDMDEVINSDBGFTRACK pTrack = (PCPDMDEVINSDBGFTRACK)pvUser;
|
---|
151 |
|
---|
152 | Assert(pTrack->fMmio);
|
---|
153 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
154 | VBOXSTRICTRC rcStrict = pTrack->u.Mmio.pfnFill(pDevIns, pTrack->pvUser, off, u32Item, cbItem, cItems);
|
---|
155 | if (RT_SUCCESS(rcStrict))
|
---|
156 | DBGFTracerEvtMmioFill(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, pTrack->u.Mmio.hMmioRegion, off,
|
---|
157 | u32Item, cbItem, cItems);
|
---|
158 |
|
---|
159 | return rcStrict;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | /** @interface_method_impl{PDMDEVHLPR0,pfnIoPortSetUpContextEx} */
|
---|
164 | DECL_HIDDEN_CALLBACK(int)
|
---|
165 | pdmR0DevHlpTracing_IoPortSetUpContextEx(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts,
|
---|
166 | PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
|
---|
167 | PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr, void *pvUser)
|
---|
168 | {
|
---|
169 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
170 | LogFlow(("pdmR0DevHlp_IoPortSetUpContextEx: caller='%s'/%d: hIoPorts=%#x pfnOut=%p pfnIn=%p pfnOutStr=%p pfnInStr=%p pvUser=%p\n",
|
---|
171 | pDevIns->pReg->szName, pDevIns->iInstance, hIoPorts, pfnOut, pfnIn, pfnOutStr, pfnInStr, pvUser));
|
---|
172 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
173 | VM_ASSERT_EMT0_RETURN(pGVM, VERR_VM_THREAD_NOT_EMT);
|
---|
174 | VM_ASSERT_STATE_RETURN(pGVM, VMSTATE_CREATING, VERR_VM_INVALID_VM_STATE);
|
---|
175 |
|
---|
176 | int rc = VINF_SUCCESS;
|
---|
177 | if (pDevIns->Internal.s.idxDbgfTraceTrackNext < pDevIns->Internal.s.cDbgfTraceTrackMax)
|
---|
178 | {
|
---|
179 | PPDMDEVINSDBGFTRACK pTrack = &pDevIns->Internal.s.paDbgfTraceTrack[pDevIns->Internal.s.idxDbgfTraceTrackNext];
|
---|
180 | rc = IOMR0IoPortSetUpContext(pGVM, pDevIns, hIoPorts,
|
---|
181 | pfnOut ? pdmR0DevHlpTracing_IoPortNewOut : NULL,
|
---|
182 | pfnIn ? pdmR0DevHlpTracing_IoPortNewIn : NULL,
|
---|
183 | pfnOutStr ? pdmR0DevHlpTracing_IoPortNewOutStr : NULL,
|
---|
184 | pfnInStr ? pdmR0DevHlpTracing_IoPortNewInStr : NULL,
|
---|
185 | pTrack);
|
---|
186 | if (RT_SUCCESS(rc))
|
---|
187 | {
|
---|
188 | pTrack->fMmio = false;
|
---|
189 | pTrack->pvUser = pvUser;
|
---|
190 | pTrack->u.IoPort.hIoPorts = hIoPorts;
|
---|
191 | pTrack->u.IoPort.pfnOut = pfnOut;
|
---|
192 | pTrack->u.IoPort.pfnIn = pfnIn;
|
---|
193 | pTrack->u.IoPort.pfnOutStr = pfnOutStr;
|
---|
194 | pTrack->u.IoPort.pfnInStr = pfnInStr;
|
---|
195 | pDevIns->Internal.s.idxDbgfTraceTrackNext++;
|
---|
196 | }
|
---|
197 | }
|
---|
198 | else
|
---|
199 | rc = VERR_OUT_OF_RESOURCES;
|
---|
200 |
|
---|
201 | LogFlow(("pdmR0DevHlp_IoPortSetUpContextEx: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
|
---|
202 | return rc;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | /** @interface_method_impl{PDMDEVHLPR0,pfnMmioSetUpContextEx} */
|
---|
207 | DECL_HIDDEN_CALLBACK(int)
|
---|
208 | pdmR0DevHlpTracing_MmioSetUpContextEx(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, PFNIOMMMIONEWWRITE pfnWrite,
|
---|
209 | PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill, void *pvUser)
|
---|
210 | {
|
---|
211 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
212 | LogFlow(("pdmR0DevHlp_MmioSetUpContextEx: caller='%s'/%d: hRegion=%#x pfnWrite=%p pfnRead=%p pfnFill=%p pvUser=%p\n",
|
---|
213 | pDevIns->pReg->szName, pDevIns->iInstance, hRegion, pfnWrite, pfnRead, pfnFill, pvUser));
|
---|
214 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
215 | VM_ASSERT_EMT0_RETURN(pGVM, VERR_VM_THREAD_NOT_EMT);
|
---|
216 | VM_ASSERT_STATE_RETURN(pGVM, VMSTATE_CREATING, VERR_VM_INVALID_VM_STATE);
|
---|
217 |
|
---|
218 | int rc = VINF_SUCCESS;
|
---|
219 | if (pDevIns->Internal.s.idxDbgfTraceTrackNext < pDevIns->Internal.s.cDbgfTraceTrackMax)
|
---|
220 | {
|
---|
221 | PPDMDEVINSDBGFTRACK pTrack = &pDevIns->Internal.s.paDbgfTraceTrack[pDevIns->Internal.s.idxDbgfTraceTrackNext];
|
---|
222 |
|
---|
223 | rc = IOMR0MmioSetUpContext(pGVM, pDevIns, hRegion,
|
---|
224 | pfnWrite ? pdmR0DevHlpTracing_MmioWrite : NULL,
|
---|
225 | pfnRead ? pdmR0DevHlpTracing_MmioRead : NULL,
|
---|
226 | pfnFill ? pdmR0DevHlpTracing_MmioFill : NULL,
|
---|
227 | pTrack);
|
---|
228 | if (RT_SUCCESS(rc))
|
---|
229 | {
|
---|
230 | pTrack->fMmio = true;
|
---|
231 | pTrack->pvUser = pvUser;
|
---|
232 | pTrack->u.Mmio.hMmioRegion = hRegion;
|
---|
233 | pTrack->u.Mmio.pfnWrite = pfnWrite;
|
---|
234 | pTrack->u.Mmio.pfnRead = pfnRead;
|
---|
235 | pTrack->u.Mmio.pfnFill = pfnFill;
|
---|
236 | pDevIns->Internal.s.idxDbgfTraceTrackNext++;
|
---|
237 | }
|
---|
238 | }
|
---|
239 | else
|
---|
240 | rc = VERR_OUT_OF_RESOURCES;
|
---|
241 |
|
---|
242 | LogFlow(("pdmR0DevHlp_MmioSetUpContextEx: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
|
---|
243 | return rc;
|
---|
244 | }
|
---|
245 |
|
---|
246 |
|
---|
247 | /** @interface_method_impl{PDMDEVHLPR0,pfnPhysRead} */
|
---|
248 | DECL_HIDDEN_CALLBACK(int)
|
---|
249 | pdmR0DevHlpTracing_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags)
|
---|
250 | {
|
---|
251 | RT_NOREF(fFlags);
|
---|
252 |
|
---|
253 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
254 | LogFlow(("pdmR0DevHlp_PhysRead: caller=%p/%d: GCPhys=%RGp pvBuf=%p cbRead=%#x\n",
|
---|
255 | pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbRead));
|
---|
256 |
|
---|
257 | VBOXSTRICTRC rcStrict = PGMPhysRead(pDevIns->Internal.s.pGVM, GCPhys, pvBuf, cbRead, PGMACCESSORIGIN_DEVICE);
|
---|
258 | AssertMsg(rcStrict == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict))); /** @todo track down the users for this bugger. */
|
---|
259 |
|
---|
260 | if (!(fFlags & PDM_DEVHLP_PHYS_RW_F_DATA_USER))
|
---|
261 | DBGFTracerEvtGCPhysRead(pDevIns->Internal.s.pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, GCPhys, pvBuf, cbRead);
|
---|
262 |
|
---|
263 | Log(("pdmR0DevHlp_PhysRead: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, VBOXSTRICTRC_VAL(rcStrict) ));
|
---|
264 | return VBOXSTRICTRC_VAL(rcStrict);
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | /** @interface_method_impl{PDMDEVHLPR0,pfnPhysWrite} */
|
---|
269 | DECL_HIDDEN_CALLBACK(int)
|
---|
270 | pdmR0DevHlpTracing_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags)
|
---|
271 | {
|
---|
272 | RT_NOREF(fFlags);
|
---|
273 |
|
---|
274 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
275 | LogFlow(("pdmR0DevHlp_PhysWrite: caller=%p/%d: GCPhys=%RGp pvBuf=%p cbWrite=%#x\n",
|
---|
276 | pDevIns, pDevIns->iInstance, GCPhys, pvBuf, cbWrite));
|
---|
277 |
|
---|
278 | VBOXSTRICTRC rcStrict = PGMPhysWrite(pDevIns->Internal.s.pGVM, GCPhys, pvBuf, cbWrite, PGMACCESSORIGIN_DEVICE);
|
---|
279 | AssertMsg(rcStrict == VINF_SUCCESS, ("%Rrc\n", VBOXSTRICTRC_VAL(rcStrict))); /** @todo track down the users for this bugger. */
|
---|
280 |
|
---|
281 | if (!(fFlags & PDM_DEVHLP_PHYS_RW_F_DATA_USER))
|
---|
282 | DBGFTracerEvtGCPhysWrite(pDevIns->Internal.s.pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, GCPhys, pvBuf, cbWrite);
|
---|
283 |
|
---|
284 | Log(("pdmR0DevHlp_PhysWrite: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, VBOXSTRICTRC_VAL(rcStrict) ));
|
---|
285 | return VBOXSTRICTRC_VAL(rcStrict);
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|
289 | /** @interface_method_impl{PDMDEVHLPR0,pfnPCIPhysRead} */
|
---|
290 | DECL_HIDDEN_CALLBACK(int)
|
---|
291 | pdmR0DevHlpTracing_PCIPhysRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags)
|
---|
292 | {
|
---|
293 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
294 | if (!pPciDev) /* NULL is an alias for the default PCI device. */
|
---|
295 | pPciDev = pDevIns->apPciDevs[0];
|
---|
296 | AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
|
---|
297 | PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
|
---|
298 |
|
---|
299 | #ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
|
---|
300 | /*
|
---|
301 | * Just check the busmaster setting here and forward the request to the generic read helper.
|
---|
302 | */
|
---|
303 | if (PCIDevIsBusmaster(pPciDev))
|
---|
304 | { /* likely */ }
|
---|
305 | else
|
---|
306 | {
|
---|
307 | Log(("pdmRCDevHlp_PCIPhysRead: caller=%p/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbRead=%#zx\n",
|
---|
308 | pDevIns, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbRead));
|
---|
309 | memset(pvBuf, 0xff, cbRead);
|
---|
310 | return VERR_PDM_NOT_PCI_BUS_MASTER;
|
---|
311 | }
|
---|
312 | #endif
|
---|
313 |
|
---|
314 | #if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
|
---|
315 | int rc = pdmIommuMemAccessRead(pDevIns, pPciDev, GCPhys, pvBuf, cbRead, fFlags);
|
---|
316 | if ( rc == VERR_IOMMU_NOT_PRESENT
|
---|
317 | || rc == VERR_IOMMU_CANNOT_CALL_SELF)
|
---|
318 | { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
|
---|
319 | else
|
---|
320 | return rc;
|
---|
321 | #endif
|
---|
322 |
|
---|
323 | return pDevIns->pHlpR0->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead, fFlags);
|
---|
324 | }
|
---|
325 |
|
---|
326 |
|
---|
327 | /** @interface_method_impl{PDMDEVHLPR0,pfnPCIPhysWrite} */
|
---|
328 | DECL_HIDDEN_CALLBACK(int)
|
---|
329 | pdmR0DevHlpTracing_PCIPhysWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags)
|
---|
330 | {
|
---|
331 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
332 | if (!pPciDev) /* NULL is an alias for the default PCI device. */
|
---|
333 | pPciDev = pDevIns->apPciDevs[0];
|
---|
334 | AssertReturn(pPciDev, VERR_PDM_NOT_PCI_DEVICE);
|
---|
335 | PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
|
---|
336 |
|
---|
337 | #ifndef PDM_DO_NOT_RESPECT_PCI_BM_BIT
|
---|
338 | /*
|
---|
339 | * Just check the busmaster setting here and forward the request to the generic read helper.
|
---|
340 | */
|
---|
341 | if (PCIDevIsBusmaster(pPciDev))
|
---|
342 | { /* likely */ }
|
---|
343 | else
|
---|
344 | {
|
---|
345 | LogFunc(("caller=%p/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbWrite=%#zx\n", pDevIns, pDevIns->iInstance,
|
---|
346 | VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbWrite));
|
---|
347 | return VERR_PDM_NOT_PCI_BUS_MASTER;
|
---|
348 | }
|
---|
349 | #endif
|
---|
350 |
|
---|
351 | #if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
|
---|
352 | int rc = pdmIommuMemAccessWrite(pDevIns, pPciDev, GCPhys, pvBuf, cbWrite, fFlags);
|
---|
353 | if ( rc == VERR_IOMMU_NOT_PRESENT
|
---|
354 | || rc == VERR_IOMMU_CANNOT_CALL_SELF)
|
---|
355 | { /* likely - ASSUMING most VMs won't be configured with an IOMMU. */ }
|
---|
356 | else
|
---|
357 | return rc;
|
---|
358 | #endif
|
---|
359 |
|
---|
360 | return pDevIns->pHlpR0->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite, fFlags);
|
---|
361 | }
|
---|
362 |
|
---|
363 |
|
---|
364 | /** @interface_method_impl{PDMDEVHLPR0,pfnPCISetIrq} */
|
---|
365 | DECL_HIDDEN_CALLBACK(void) pdmR0DevHlpTracing_PCISetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel)
|
---|
366 | {
|
---|
367 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
368 | if (!pPciDev) /* NULL is an alias for the default PCI device. */
|
---|
369 | pPciDev = pDevIns->apPciDevs[0];
|
---|
370 | AssertReturnVoid(pPciDev);
|
---|
371 | LogFlow(("pdmR0DevHlpTracing_PCISetIrq: caller=%p/%d: pPciDev=%p:{%#x} iIrq=%d iLevel=%d\n",
|
---|
372 | pDevIns, pDevIns->iInstance, pPciDev, pPciDev->uDevFn, iIrq, iLevel));
|
---|
373 | PDMPCIDEV_ASSERT_VALID_AND_REGISTERED(pDevIns, pPciDev);
|
---|
374 |
|
---|
375 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
376 | size_t const idxBus = pPciDev->Int.s.idxPdmBus;
|
---|
377 | AssertReturnVoid(idxBus < RT_ELEMENTS(pGVM->pdmr0.s.aPciBuses));
|
---|
378 | PPDMPCIBUSR0 pPciBusR0 = &pGVM->pdmr0.s.aPciBuses[idxBus];
|
---|
379 |
|
---|
380 | DBGFTracerEvtIrq(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, iIrq, iLevel);
|
---|
381 |
|
---|
382 | pdmLock(pGVM);
|
---|
383 |
|
---|
384 | uint32_t uTagSrc;
|
---|
385 | if (iLevel & PDM_IRQ_LEVEL_HIGH)
|
---|
386 | {
|
---|
387 | pDevIns->Internal.s.pIntR3R0->uLastIrqTag = uTagSrc = pdmCalcIrqTag(pGVM, pDevIns->Internal.s.pInsR3R0->idTracing);
|
---|
388 | if (iLevel == PDM_IRQ_LEVEL_HIGH)
|
---|
389 | VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pGVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
|
---|
390 | else
|
---|
391 | VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pGVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
|
---|
392 | }
|
---|
393 | else
|
---|
394 | uTagSrc = pDevIns->Internal.s.pIntR3R0->uLastIrqTag;
|
---|
395 |
|
---|
396 | if (pPciBusR0->pDevInsR0)
|
---|
397 | {
|
---|
398 | pPciBusR0->pfnSetIrqR0(pPciBusR0->pDevInsR0, pPciDev, iIrq, iLevel, uTagSrc);
|
---|
399 |
|
---|
400 | pdmUnlock(pGVM);
|
---|
401 |
|
---|
402 | if (iLevel == PDM_IRQ_LEVEL_LOW)
|
---|
403 | VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pGVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
|
---|
404 | }
|
---|
405 | else
|
---|
406 | {
|
---|
407 | pdmUnlock(pGVM);
|
---|
408 |
|
---|
409 | /* queue for ring-3 execution. */
|
---|
410 | PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pGVM, pGVM->pdm.s.hDevHlpQueue, pGVM);
|
---|
411 | AssertReturnVoid(pTask);
|
---|
412 |
|
---|
413 | pTask->enmOp = PDMDEVHLPTASKOP_PCI_SET_IRQ;
|
---|
414 | pTask->pDevInsR3 = PDMDEVINS_2_R3PTR(pDevIns);
|
---|
415 | pTask->u.PciSetIrq.iIrq = iIrq;
|
---|
416 | pTask->u.PciSetIrq.iLevel = iLevel;
|
---|
417 | pTask->u.PciSetIrq.uTagSrc = uTagSrc;
|
---|
418 | pTask->u.PciSetIrq.idxPciDev = pPciDev->Int.s.idxSubDev;
|
---|
419 |
|
---|
420 | PDMQueueInsert(pGVM, pGVM->pdm.s.hDevHlpQueue, pGVM, &pTask->Core);
|
---|
421 | }
|
---|
422 |
|
---|
423 | LogFlow(("pdmR0DevHlpTracing_PCISetIrq: caller=%p/%d: returns void; uTagSrc=%#x\n", pDevIns, pDevIns->iInstance, uTagSrc));
|
---|
424 | }
|
---|
425 |
|
---|
426 |
|
---|
427 | /** @interface_method_impl{PDMDEVHLPR0,pfnISASetIrq} */
|
---|
428 | DECL_HIDDEN_CALLBACK(void) pdmR0DevHlpTracing_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
|
---|
429 | {
|
---|
430 | PDMDEV_ASSERT_DEVINS(pDevIns);
|
---|
431 | LogFlow(("pdmR0DevHlpTracing_ISASetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
|
---|
432 | PGVM pGVM = pDevIns->Internal.s.pGVM;
|
---|
433 |
|
---|
434 | DBGFTracerEvtIrq(pGVM, pDevIns->Internal.s.hDbgfTraceEvtSrc, iIrq, iLevel);
|
---|
435 |
|
---|
436 | pdmLock(pGVM);
|
---|
437 | uint32_t uTagSrc;
|
---|
438 | if (iLevel & PDM_IRQ_LEVEL_HIGH)
|
---|
439 | {
|
---|
440 | pDevIns->Internal.s.pIntR3R0->uLastIrqTag = uTagSrc = pdmCalcIrqTag(pGVM, pDevIns->Internal.s.pInsR3R0->idTracing);
|
---|
441 | if (iLevel == PDM_IRQ_LEVEL_HIGH)
|
---|
442 | VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pGVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
|
---|
443 | else
|
---|
444 | VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pGVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
|
---|
445 | }
|
---|
446 | else
|
---|
447 | uTagSrc = pDevIns->Internal.s.pIntR3R0->uLastIrqTag;
|
---|
448 |
|
---|
449 | bool fRc = pdmR0IsaSetIrq(pGVM, iIrq, iLevel, uTagSrc);
|
---|
450 |
|
---|
451 | if (iLevel == PDM_IRQ_LEVEL_LOW && fRc)
|
---|
452 | VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pGVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
|
---|
453 | pdmUnlock(pGVM);
|
---|
454 | LogFlow(("pdmR0DevHlpTracing_ISASetIrq: caller=%p/%d: returns void; uTagSrc=%#x\n", pDevIns, pDevIns->iInstance, uTagSrc));
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | /** @} */
|
---|
459 |
|
---|