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