VirtualBox

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

Last change on this file since 63495 was 63239, checked in by vboxsync, 8 years ago

Main: warnings

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