VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/PCIRawDevImpl.cpp@ 102493

Last change on this file since 102493 was 98274, checked in by vboxsync, 23 months ago

Main/PCIRawDevImpl.cpp: rc -> hrc/vrc. bugref:10223

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: PCIRawDevImpl.cpp 98274 2023-01-24 11:19:16Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to raw PCI device.
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#define LOG_GROUP LOG_GROUP_DEV_PCI_RAW
29#include "LoggingNew.h"
30
31#include "PCIRawDevImpl.h"
32#include "PCIDeviceAttachmentImpl.h"
33#include "ConsoleImpl.h"
34
35// generated header for events
36#include "VBoxEvents.h"
37
38#include <VBox/err.h>
39
40
41/**
42 * PCI raw driver instance data.
43 */
44typedef struct DRVMAINPCIRAWDEV
45{
46 /** Pointer to the real PCI raw object. */
47 PCIRawDev *pPCIRawDev;
48 /** Pointer to the driver instance structure. */
49 PPDMDRVINS pDrvIns;
50 /** Our PCI device connector interface. */
51 PDMIPCIRAWCONNECTOR IConnector;
52
53} DRVMAINPCIRAWDEV, *PDRVMAINPCIRAWDEV;
54
55//
56// constructor / destructor
57//
58PCIRawDev::PCIRawDev(Console *console)
59 : mParent(console),
60 mpDrv(NULL)
61{
62}
63
64PCIRawDev::~PCIRawDev()
65{
66}
67
68/**
69 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
70 */
71DECLCALLBACK(void *) PCIRawDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
72{
73 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
74 PDRVMAINPCIRAWDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINPCIRAWDEV);
75
76 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
77 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIPCIRAWCONNECTOR, &pThis->IConnector);
78
79 return NULL;
80}
81
82
83/**
84 * @interface_method_impl{PDMIPCIRAWCONNECTOR,pfnDeviceConstructComplete}
85 */
86DECLCALLBACK(int) PCIRawDev::drvDeviceConstructComplete(PPDMIPCIRAWCONNECTOR pInterface, const char *pcszName,
87 uint32_t uHostPCIAddress, uint32_t uGuestPCIAddress,
88 int vrc)
89{
90 PDRVMAINPCIRAWDEV pThis = RT_FROM_CPP_MEMBER(pInterface, DRVMAINPCIRAWDEV, IConnector);
91 Console *pConsole = pThis->pPCIRawDev->getParent();
92 const ComPtr<IMachine>& machine = pConsole->i_machine();
93 ComPtr<IVirtualBox> vbox;
94
95 HRESULT hrc = machine->COMGETTER(Parent)(vbox.asOutParam());
96 Assert(SUCCEEDED(hrc)); NOREF(hrc);
97
98 ComPtr<IEventSource> es;
99 hrc = vbox->COMGETTER(EventSource)(es.asOutParam());
100 Assert(SUCCEEDED(hrc));
101
102 Bstr bstrId;
103 hrc = machine->COMGETTER(Id)(bstrId.asOutParam());
104 Assert(SUCCEEDED(hrc));
105
106 ComObjPtr<PCIDeviceAttachment> pda;
107 BstrFmt bstrName(pcszName);
108 pda.createObject();
109 pda->init(machine, bstrName, uHostPCIAddress, uGuestPCIAddress, TRUE);
110
111 Bstr msg("");
112 if (RT_FAILURE(vrc))
113 msg.printf("runtime error %Rrc", vrc);
114
115 ::FireHostPCIDevicePlugEvent(es, bstrId.raw(), true /* plugged */, RT_SUCCESS_NP(vrc) /* success */, pda, msg.raw());
116
117 return VINF_SUCCESS;
118}
119
120
121/**
122 * @interface_method_impl{PDMDRVREG,pfnReset}
123 */
124DECLCALLBACK(void) PCIRawDev::drvDestruct(PPDMDRVINS pDrvIns)
125{
126 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
127 PDRVMAINPCIRAWDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINPCIRAWDEV);
128
129 if (pThis->pPCIRawDev)
130 pThis->pPCIRawDev->mpDrv = NULL;
131}
132
133
134/**
135 * @interface_method_impl{PDMDRVREG,pfnConstruct}
136 */
137DECLCALLBACK(int) PCIRawDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
138{
139 RT_NOREF(fFlags);
140 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
141 PDRVMAINPCIRAWDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINPCIRAWDEV);
142
143 /*
144 * Validate configuration.
145 */
146 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
147 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
148
149 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
150 ("Configuration error: Not possible to attach anything to this driver!\n"),
151 VERR_PDM_DRVINS_NO_ATTACH);
152
153 /*
154 * IBase.
155 */
156 pDrvIns->IBase.pfnQueryInterface = PCIRawDev::drvQueryInterface;
157
158 /*
159 * IConnector.
160 */
161 pThis->IConnector.pfnDeviceConstructComplete = PCIRawDev::drvDeviceConstructComplete;
162
163 /*
164 * Get the object pointer and update the mpDrv member.
165 */
166 void *pv;
167 int vrc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
168 if (RT_FAILURE(vrc))
169 {
170 AssertMsgFailed(("Configuration error: No \"Object\" value! vrc=%Rrc\n", vrc));
171 return vrc;
172 }
173
174 pThis->pPCIRawDev = (PCIRawDev *)pv;
175 pThis->pPCIRawDev->mpDrv = pThis;
176
177 return VINF_SUCCESS;
178}
179
180/**
181 * Main raw PCI driver registration record.
182 */
183const PDMDRVREG PCIRawDev::DrvReg =
184{
185 /* u32Version */
186 PDM_DRVREG_VERSION,
187 /* szName */
188 "MainPciRaw",
189 /* szRCMod */
190 "",
191 /* szR0Mod */
192 "",
193 /* pszDescription */
194 "Main PCI raw driver (Main as in the API).",
195 /* fFlags */
196 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
197 /* fClass. */
198 PDM_DRVREG_CLASS_PCIRAW,
199 /* cMaxInstances */
200 ~0U,
201 /* cbInstance */
202 sizeof(DRVMAINPCIRAWDEV),
203 /* pfnConstruct */
204 PCIRawDev::drvConstruct,
205 /* pfnDestruct */
206 PCIRawDev::drvDestruct,
207 /* pfnRelocate */
208 NULL,
209 /* pfnIOCtl */
210 NULL,
211 /* pfnPowerOn */
212 NULL,
213 /* pfnReset */
214 NULL,
215 /* pfnSuspend */
216 NULL,
217 /* pfnResume */
218 NULL,
219 /* pfnAttach */
220 NULL,
221 /* pfnDetach */
222 NULL,
223 /* pfnPowerOff */
224 NULL,
225 /* pfnSoftReset */
226 NULL,
227 /* u32EndVersion */
228 PDM_DRVREG_VERSION
229};
230
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