VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/PDMR0Driver.cpp@ 103131

Last change on this file since 103131 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* $Id: PDMR0Driver.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, R0 Driver parts.
4 */
5
6/*
7 * Copyright (C) 2010-2023 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_DRIVER
33#include "PDMInternal.h"
34#include <VBox/vmm/pdm.h>
35#include <VBox/vmm/vmcc.h>
36#include <VBox/vmm/gvmm.h>
37
38#include <VBox/log.h>
39#include <iprt/errcore.h>
40#include <iprt/assert.h>
41
42
43/*********************************************************************************************************************************
44* Global Variables *
45*********************************************************************************************************************************/
46RT_C_DECLS_BEGIN
47extern DECLEXPORT(const PDMDRVHLPR0) g_pdmR0DrvHlp;
48RT_C_DECLS_END
49
50
51/** @name Ring-0 Context Driver Helpers
52 * @{
53 */
54
55/** @interface_method_impl{PDMDRVHLPR0,pfnAssertEMT} */
56static DECLCALLBACK(bool) pdmR0DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
57{
58 PDMDRV_ASSERT_DRVINS(pDrvIns);
59 if (VM_IS_EMT(pDrvIns->Internal.s.pVMR0))
60 return true;
61
62 RTAssertMsg1Weak("AssertEMT", iLine, pszFile, pszFunction);
63 RTAssertPanic();
64 return false;
65}
66
67
68/** @interface_method_impl{PDMDRVHLPR0,pfnAssertOther} */
69static DECLCALLBACK(bool) pdmR0DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
70{
71 PDMDRV_ASSERT_DRVINS(pDrvIns);
72 if (!VM_IS_EMT(pDrvIns->Internal.s.pVMR0))
73 return true;
74
75 RTAssertMsg1Weak("AssertOther", iLine, pszFile, pszFunction);
76 RTAssertPanic();
77 return false;
78}
79
80
81/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectEnter} */
82static DECLCALLBACK(int) pdmR0DrvHlp_CritSectEnter(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect, int rcBusy)
83{
84 PDMDRV_ASSERT_DRVINS(pDrvIns);
85 return PDMCritSectEnter(pDrvIns->Internal.s.pVMR0, pCritSect, rcBusy);
86}
87
88
89/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectEnterDebug} */
90static DECLCALLBACK(int) pdmR0DrvHlp_CritSectEnterDebug(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect, int rcBusy,
91 RTHCUINTPTR uId, RT_SRC_POS_DECL)
92{
93 PDMDRV_ASSERT_DRVINS(pDrvIns);
94 return PDMCritSectEnterDebug(pDrvIns->Internal.s.pVMR0, pCritSect, rcBusy, uId, RT_SRC_POS_ARGS);
95}
96
97
98/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectTryEnter} */
99static DECLCALLBACK(int) pdmR0DrvHlp_CritSectTryEnter(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect)
100{
101 PDMDRV_ASSERT_DRVINS(pDrvIns);
102 return PDMCritSectTryEnter(pDrvIns->Internal.s.pVMR0, pCritSect);
103}
104
105
106/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectTryEnterDebug} */
107static DECLCALLBACK(int) pdmR0DrvHlp_CritSectTryEnterDebug(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect,
108 RTHCUINTPTR uId, RT_SRC_POS_DECL)
109{
110 PDMDRV_ASSERT_DRVINS(pDrvIns);
111 return PDMCritSectTryEnterDebug(pDrvIns->Internal.s.pVMR0, pCritSect, uId, RT_SRC_POS_ARGS);
112}
113
114
115/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectLeave} */
116static DECLCALLBACK(int) pdmR0DrvHlp_CritSectLeave(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect)
117{
118 PDMDRV_ASSERT_DRVINS(pDrvIns);
119 return PDMCritSectLeave(pDrvIns->Internal.s.pVMR0, pCritSect);
120}
121
122
123/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectIsOwner} */
124static DECLCALLBACK(bool) pdmR0DrvHlp_CritSectIsOwner(PPDMDRVINS pDrvIns, PCPDMCRITSECT pCritSect)
125{
126 PDMDRV_ASSERT_DRVINS(pDrvIns);
127 return PDMCritSectIsOwner(pDrvIns->Internal.s.pVMR0, pCritSect);
128}
129
130
131/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectIsInitialized} */
132static DECLCALLBACK(bool) pdmR0DrvHlp_CritSectIsInitialized(PPDMDRVINS pDrvIns, PCPDMCRITSECT pCritSect)
133{
134 PDMDRV_ASSERT_DRVINS(pDrvIns);
135 NOREF(pDrvIns);
136 return PDMCritSectIsInitialized(pCritSect);
137}
138
139
140/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectHasWaiters} */
141static DECLCALLBACK(bool) pdmR0DrvHlp_CritSectHasWaiters(PPDMDRVINS pDrvIns, PCPDMCRITSECT pCritSect)
142{
143 PDMDRV_ASSERT_DRVINS(pDrvIns);
144 return PDMCritSectHasWaiters(pDrvIns->Internal.s.pVMR0, pCritSect);
145}
146
147
148/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectGetRecursion} */
149static DECLCALLBACK(uint32_t) pdmR0DrvHlp_CritSectGetRecursion(PPDMDRVINS pDrvIns, PCPDMCRITSECT pCritSect)
150{
151 PDMDRV_ASSERT_DRVINS(pDrvIns);
152 NOREF(pDrvIns);
153 return PDMCritSectGetRecursion(pCritSect);
154}
155
156
157/** @interface_method_impl{PDMDRVHLPR0,pfnCritSectScheduleExitEvent} */
158static DECLCALLBACK(int) pdmR0DrvHlp_CritSectScheduleExitEvent(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect,
159 SUPSEMEVENT hEventToSignal)
160{
161 PDMDRV_ASSERT_DRVINS(pDrvIns);
162 NOREF(pDrvIns);
163 return PDMHCCritSectScheduleExitEvent(pCritSect, hEventToSignal);
164}
165
166
167/** @interface_method_impl{PDMDRVHLPR0,pfnNetShaperAllocateBandwidth} */
168static DECLCALLBACK(bool) pdmR0DrvHlp_NetShaperAllocateBandwidth(PPDMDRVINS pDrvIns, PPDMNSFILTER pFilter, size_t cbTransfer)
169{
170#ifdef VBOX_WITH_NETSHAPER
171 PDMDRV_ASSERT_DRVINS(pDrvIns);
172 LogFlow(("pdmR0DrvHlp_NetShaperDetach: caller='%s'/%d: pFilter=%p cbTransfer=%#zx\n",
173 pDrvIns->pReg->szName, pDrvIns->iInstance, pFilter, cbTransfer));
174
175 bool const fRc = PDMNetShaperAllocateBandwidth(pDrvIns->Internal.s.pVMR0, pFilter, cbTransfer);
176
177 LogFlow(("pdmR0DrvHlp_NetShaperDetach: caller='%s'/%d: returns %RTbool\n", pDrvIns->pReg->szName, pDrvIns->iInstance, fRc));
178 return fRc;
179#else
180 RT_NOREF(pDrvIns, pFilter, cbTransfer);
181 return true;
182#endif
183}
184
185
186/**
187 * The Ring-0 Context Driver Helper Callbacks.
188 */
189extern DECLEXPORT(const PDMDRVHLPR0) g_pdmR0DrvHlp =
190{
191 PDM_DRVHLPRC_VERSION,
192 pdmR0DrvHlp_AssertEMT,
193 pdmR0DrvHlp_AssertOther,
194 pdmR0DrvHlp_CritSectEnter,
195 pdmR0DrvHlp_CritSectEnterDebug,
196 pdmR0DrvHlp_CritSectTryEnter,
197 pdmR0DrvHlp_CritSectTryEnterDebug,
198 pdmR0DrvHlp_CritSectLeave,
199 pdmR0DrvHlp_CritSectIsOwner,
200 pdmR0DrvHlp_CritSectIsInitialized,
201 pdmR0DrvHlp_CritSectHasWaiters,
202 pdmR0DrvHlp_CritSectGetRecursion,
203 pdmR0DrvHlp_CritSectScheduleExitEvent,
204 pdmR0DrvHlp_NetShaperAllocateBandwidth,
205 PDM_DRVHLPRC_VERSION
206};
207
208/** @} */
209
210
211
212/**
213 * PDMDrvHlpCallR0 helper.
214 *
215 * @returns See PFNPDMDRVREQHANDLERR0.
216 * @param pGVM The global (ring-0) VM structure. (For validation.)
217 * @param pReq Pointer to the request buffer.
218 */
219VMMR0_INT_DECL(int) PDMR0DriverCallReqHandler(PGVM pGVM, PPDMDRIVERCALLREQHANDLERREQ pReq)
220{
221 /*
222 * Validate input and make the call.
223 */
224 int rc = GVMMR0ValidateGVM(pGVM);
225 if (RT_SUCCESS(rc))
226 {
227 AssertPtrReturn(pReq, VERR_INVALID_POINTER);
228 AssertMsgReturn(pReq->Hdr.cbReq == sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER);
229
230 PPDMDRVINS pDrvIns = pReq->pDrvInsR0;
231 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
232 AssertReturn(pDrvIns->Internal.s.pVMR0 == pGVM, VERR_INVALID_PARAMETER);
233
234 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0 = pDrvIns->Internal.s.pfnReqHandlerR0;
235 AssertPtrReturn(pfnReqHandlerR0, VERR_INVALID_POINTER);
236
237 rc = pfnReqHandlerR0(pDrvIns, pReq->uOperation, pReq->u64Arg);
238 }
239 return rc;
240}
241
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